enforce-rules
Turn a proposed or existing project rule into the cheapest automated check that enforces it, measure and fix current violations, and promote or demote rules…
от agentty-xyz★ 46 звёзд на GitHub
Установить enforce-rules в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Enforce Rules
Use this skill when someone proposes a convention, a review keeps repeating the same
comment, a fixed bug class could come back, or an AGENTS.md line could be checked
mechanically. It decides where a rule lives and how it gets there.
Levels and Exceptions
docs/site/content/docs/contributing/rule-enforcement.md is the contributor-facing
explanation of the levels, the hooks that report each one, and the exception policy.
Read it first; the steps below use its level numbers:
- Level 1: rustc and Clippy lints and formatter configuration.
- Level 2: ast-grep rules,
ag-xtaskchecks, and contract tests. - Level 3: the nearest
AGENTS.md.
Write an ag-xtask task only when the rule needs more than one file's syntax. Put every
exception in the check's configuration as that page describes, never at the call site.
Placing a Rule
- Write the rule as a predicate: the paths it covers, the construct it forbids or requires, the allowed exceptions, and the fix. If you cannot state the predicate without judgement words such as "focused" or "when clearer", keep it at level 3.
- Pick the lowest level that can evaluate the predicate.
- Measure current violations before changing anything:
- Clippy: run
cargo clippy --workspace --all-targets --all-features --message-format=short -- -W clippy::<lint>and count the distinct sites. Restriction lints that report thousands of existing sites usually belong at level 3. - ast-grep: add the draft rule to its directory under
lint/rules/(see below) and runprek run ast-grep --all-files; it lists every match. ag-xtaskor contract test: implement the check first and let it list violations.
- Clippy: run
- Decide what to do with the existing violations:
- A handful: fix them in the same change.
- Many but mechanical: fix them in the same change, or in a preceding one when the fix touches unrelated code.
- Many that each need judgement: narrow the scope until the remaining sites are fixable, or keep the rule at level 3.
- Implement the check (see below) and make its failure message name the fix.
- Delete the
AGENTS.mdtext the check now enforces, or shrink it to the judgement that remains. The root guide forbids restating enforced rules. - Update
docs/site/content/docs/contributing/rule-enforcement.mdwhen the change adds a level, a reporting hook, or an exception mechanism, or changes the exception policy. A new rule at an existing level needs no page change. - Validate through
skills/validate-changes/SKILL.md, adding the check's own hooks.
Writing ast-grep Rules
- Name the file after the rule
id, in kebab-case, and prefix rules scoped to one crate with that crate, such asagentty-layer-host-access. - Put a rule in
lint/rules/shared/when it names no crate or path of this workspace and itsfilesandignoresglobs start with a pattern such as**/src/**/*.rs;standards.tomlexports these rules to downstream workspaces, andcheck-standardsrejects shared rules that break either condition. Put every other rule inlint/rules/workspace/. - Use
severity: error. Writemessageas one sentence saying what to do, andnoteas the fix plus the owning document. - Scope with
filesandignores, relative to the repository root. Production-only rules ignore"**/*_test.rs"and"**/*_test/**". - Match tree-sitter node kinds (
kind,has,inside,follows) and useregexonly on the matched node's text. Inspect node kinds with ast-grep'srun --debug-query=cst -l rust -p '<snippet>'mode, using theast-grep-cliversion that.pre-commit-config.yamlpins. - Add
<id>-test.ymlto the matchinglint/rule-tests/shared/orlint/rule-tests/workspace/directory with at least onevalidand oneinvalidcase covering each branch of the rule;prek run ast-grep-test --all-filesruns them. Rule tests ignorefilesandignores, so keep path scoping simple.
Writing ag-xtask Checks
Follow crates/ag-xtask/AGENTS.md: one module per check, a mockable boundary for
filesystem, process, and Git access, 100% coverage, and registration in
.pre-commit-config.yaml with a files filter that fires when any input changes.
Extend an existing check when the rule shares its inputs, as dependency rules do with
check-execution-boundary.
Moving a Rule Later
- Up to level 1: when Clippy or rustc gains a lint that covers an ast-grep rule or
ag-xtaskcheck, enable the lint and delete the custom rule in the same change. - Within level 2: move an ast-grep rule to
ag-xtaskwhen it starts needing facts outside one file, such as whether a sibling directory exists. - Down to level 3: when a rule keeps needing exceptions that its configuration cannot express, delete it and restore a short instruction stating the judgement. Record the reason in the change description.
Handoff
Report the rule, its level and hom
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл enforce-rules?
Turn a proposed or existing project rule into the cheapest automated check that enforces it, measure and fix current violations, and promote or demote rules between Clippy lints, ast-grep rules, ag-xtask checks, contract tests, and AGENTS.md instructions.
Как установить скилл enforce-rules?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл enforce-rules запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
AnthropicToolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
access
AnthropicManage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
configure
AnthropicSet up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
access
AnthropicManage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…