mirror of
https://github.com/fabro-sh/fabro.git
synced 2026-12-01 00:27:17 +00:00
## Summary
Adds the `rust-style-guide` Agent Skill under
`.fabro/skills/rust-style-guide/` so Fabro workflow agent stages can
apply the project's Rust conventions when writing or reviewing Rust
code.
Skills are discovered by convention from
`{git_root}/.fabro/skills/*/SKILL.md` at agent-session startup — there's
no manifest wiring or per-workflow declaration. Once present, every
agent stage lists the skill in its system prompt and registers the
`use_skill` tool, so an agent can load it (or a node prompt can
reference `/rust-style-guide`). Committing it here (rather than relying
on a local `~/.fabro/skills` copy) is what makes it available to
**remote, clone-based runs** (Docker/Daytona), which only see committed
+ pushed files.
## Contents (44 files)
- `SKILL.md` — entry point (with a short note pointing the agent at the
in-repo location of the supporting files, since Fabro hands the agent
the `SKILL.md` body and it reads the rest itself)
- `guidelines.md` + `guidelines/` — 38 Rust style policy pages
- `workflows/` — 4 procedure pages (new project, library release,
performance investigation, code review/refactor)
## Source / attribution
Vendored from https://github.com/brynary/rust-style-guide (commit
`8fd2a4f`), trimmed to the runtime skill payload; the upstream repo's
mdBook site and authoring scaffolding are omitted. Note: the upstream
repo has **no LICENSE file** — flagging for a call on
attribution/licensing before merge.
## Notes
- No behavior/code change — this is skill content only; nothing is
compiled or bundled.
- No `{{user_input}}` placeholder was added; agents reference the skill
in prose or via `use_skill`. (If we later want deterministic
`/rust-style-guide <task>` slash expansion in node prompts, add the
placeholder to `SKILL.md` then.)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
4.6 KiB
4.6 KiB
Control Flow
Rule
Use clarity-first branching: prefer ?, let else, if let, and match to make branches and exits explicit, and keep mutation in small, validated scopes.
Why
Control flow carries invariants, error paths, and state transitions. Explicit branches and small mutable scopes are easier for agents to modify safely than clever expression chains, hidden exits, or partially updated state.
Do
- Use
?when the local code only needs to propagate a fallible result. - Use early returns for invalid inputs, missing prerequisites, and permission checks.
- Use
let elsewhen a required pattern must be present and the fallback exits the current scope. - Use
if letwhen only one pattern needs special handling. - Use
while letfor loops that repeatedly consume optional or result-like values. - Use
matchwhen multiple variants matter, exhaustiveness matters, or each branch has distinct behavior. - Keep
matcharms small; extract a helper when a branch grows past the local decision. - Prefer naming meaningful enum variants over
_when future variants should force a revisit. - Use match guards only when the guard is short and directly tied to the arm.
- Keep the main path linear after validation and setup.
- Use
let mutfor local accumulators, builders, counters, and staged values; keep mutable scopes small and return to immutable locals once setup is complete. - Validate fallible inputs before mutating long-lived state; prefer computing a new value locally and assigning it once when that avoids partial updates.
- Use
std::mem::takeorstd::mem::replacewhen moving a field out while leaving the struct valid. - Treat Clippy as authoritative for local control-flow idioms; refactor instead of adding local bypasses (rustc and Clippy lints).
Avoid
- Do not write combinator chains that hide branching or side effects; Option and Result idioms owns the combinator-vs-branching line.
- Do not use
matchonbool; useifwith a named condition. - Do not use
_to ignore meaningful domain states. - Do not deeply nest
iformatchblocks when guard clauses would make exits clearer. - Do not use
let elsewhen the fallback contains substantial recovery logic; usematch. - Do not replace explicit error handling with
unwraporexpect. - Do not force a functional style when a small mutable local is clearer.
- Do not mutate object state before fallible validation unless the partial state is intentional and documented.
Example
Prefer visible exits and exhaustive domain handling:
pub fn plan_action(request: Request) -> Result<Action, Error> {
let Some(user_id) = request.user_id() else {
return Err(Error::MissingUserId);
};
let command = Command::parse(request.command())?;
if !request.permissions().can_run(&user_id, &command) {
return Err(Error::Forbidden { user_id });
}
let action = match command {
Command::Start { target } => {
let target = Target::try_new(target)?;
Action::Start { target }
}
Command::Stop { target } => Action::Stop { target },
Command::Status => Action::Status,
};
Ok(action)
}
Validate first, then mutate the owned state in a small block:
pub struct UserAccount {
email: EmailAddress,
labels: Vec<String>,
active: bool,
}
impl UserAccount {
pub fn update(&mut self, update: UserUpdate) -> Result<(), Error> {
let email = match update.email() {
Some(value) => Some(EmailAddress::try_new(value)?),
None => None,
};
let mut labels = Vec::new();
for label in update.labels() {
labels.push(Label::try_new(label)?.into_string());
}
if let Some(email) = email {
self.email = email;
}
self.labels = labels;
if update.deactivate() {
self.active = false;
}
Ok(())
}
}
Use combinators for simple local transformations:
impl User {
pub fn display_name(&self) -> String {
self.nickname()
.filter(|name| !name.is_empty())
.unwrap_or_else(|| self.username())
.to_owned()
}
}
Exceptions
- Use combinators when the transformation is short, linear, and side-effect free.
- Use
_for intentionally ignored variants in tests, logging, metrics, or external#[non_exhaustive]enums. - Use a
matcheven for two cases when it documents a domain state machine or prepares for likely new variants. - Mutate as you go when each step is independently valid and there is no meaningful rollback requirement.