DocsGuides
Code guidelines
Set a project's code style and rules once; every edit is checked against them, next to code health.
Code guidelines are a project's own style and rules, kept in the repository. Agents read them before editing a file. Every edit is checked against them, and a run cannot finish while its change breaks an error-level rule.
The folder
.rusty/guidelines/
├── rules.json the rules the host checks
└── style.md prose guidance, given to the model
Commit the folder with the project. Without it, only code health applies. The folder must be spelled guidelines; any other name is not read.
Rusty writes .rusty/.gitignore so Git keeps only the shared parts of .rusty (guidelines, specs, skills, workflows, profiles, canvas) and leaves chats, runs, goals, metrics and traces on your machine. .rusty/README.md lists what each part holds. If your repository's own .gitignore has a /.rusty line, remove it to share the guidelines.
rules.json
{
"version": 1,
"limits": { "max_file_lines": 400, "max_function_lines": 60, "max_complexity": 10, "max_params": 5 },
"detectors": { "large_method": { "threshold": 50 }, "disabled": ["ownership_risk"] },
"rules": [
{ "id": "no-unwrap", "kind": "pattern", "lang": "rust",
"query": "(call_expression function: (field_expression field: (field_identifier) @m (#eq? @m \"unwrap\"))) @violation",
"exclude": ["**/tests/**"], "message": "Return an error instead of unwrap()" },
{ "id": "no-console", "kind": "pattern", "regex": "console\\.log\\(", "applies": ["src/**/*.ts"], "severity": "warn" },
{ "id": "ui-not-core", "kind": "boundary", "applies": ["src/components/**"], "must_not_import": ["src/harness/core/**"] },
{ "id": "small-ui", "kind": "metric", "applies": ["src/components/**"], "max_file_lines": 250 },
{ "id": "naming", "kind": "prose", "text": "Name functions after what they return or do." }
]
}
The JSON schema is published as schema/guidelines-v1.schema.json in rusty-core. Mistakes in the file are all reported at once, and the rules are not checked until it is fixed.
| Field | Meaning |
|---|---|
limits |
Size and complexity limits for every source file: lines in the file; lines of code, cyclomatic complexity, nesting depth and parameters per function. Test code is not held to the function limits. |
detectors |
Code health thresholds for this project, over the defaults. The Code Health page and goals measure with them. |
rules[].kind |
pattern (a regex per line, or a tree-sitter query for lang; a capture named violation marks the lines), metric (limits for the files the rule applies to), boundary (files that must not import files matching must_not_import, from the repository index), prose (guidance in words, given to the model and never checked by the host). |
applies, exclude |
Globs relative to the repository root (*, **, ?, {a,b}; a glob without / matches the file name anywhere). |
severity |
error (blocks finishing; the default), warn (reported), info (only shown to the model). |
message, fix |
What a violation says, and how to fix it. |
disabled |
Switches a rule off without deleting it. |
style.md
Plain Markdown. Text before the first glob heading applies to every file. A ## heading whose whole text is a glob in backticks starts a section for those files:
Prefer small modules split by responsibility.
## `src/components/**/*.tsx`
One component per file. Hooks start with `use`.
How edits are checked
- On the first edit to a file in a run, the edit result ends with what applies to it: its rules (severity, id, message) and the outline of the style guide. Each set is shown once per run, so the agent sees the guidelines without having to ask. For the full text of a rule or style section it calls
code_guidelineswith moderules. - The system prompt of every agent that can edit says the project may have guidelines, that the first edit shows them, and that guideline errors must be fixed before finishing.
- After every edit, the
edit_file/write_fileresult ends with a short notice when the edit introduced a violation. Only the rules the host checks run, and only for what the edit introduced. - Before finishing, the completion gate of the single agent and of the Build, Refactor and Optimize profiles runs the check over the files the run changed. Error-level violations the change introduced send the agent back with the list. After the gate's last continuation it lets the run finish.
- Only what a change introduced counts. That means violations on lines changed since the last commit, a function that spans a changed line, and a file-size limit only when the file is new or grew. An untidy repository does not block every edit.
- Goals can require "no guideline errors" in their scope.
The tool
code_guidelines is read-only and every model has it, in every mode and workflow step.
| Call | Answer |
|---|---|
{"mode": "rules", "targets": ["path"]} |
The rules, limits and style sections that apply to those files. Without targets: every rule and section. |
{"mode": "check", "targets": ["path"], "changed_only": true} |
Violations by line with how to fix them. Without changed_only, everything in the files. |
Status not_configured means the project has no guidelines; invalid lists the mistakes in the rules file.