بنقرة واحدة
implement-rule
Implement checks, patterns, and fixtures for an existing rule skeleton
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Implement checks, patterns, and fixtures for an existing rule skeleton
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Add a changelog entry to UNRELEASED.md
Load project context — backbone, registry, and constraints — before any work
Run rules against pass/fail fixtures using the local CLI test harness
Create, update, and validate agent configurations
Generate a rule skeleton with proper schema and directory structure
Validate rules against schema and contracts
| name | implement-rule |
| description | Implement checks, patterns, and fixtures for an existing rule skeleton |
Implement checks, regex patterns, and test fixtures for an existing rule that has a skeleton but empty checks: [].
/implement-rule <coordinate> [--agent <name>] [--dry-run]
<coordinate>: Rule coordinate (e.g., CORE:C:0001, CLAUDE:S:0001)--agent <name>: Agent for template var resolution (default: claude)--dry-run: Show what would be generated without writing files/implement-rule CORE:S:0002
/implement-rule CORE:M:0003 --agent codex
/implement-rule CLAUDE:S:0001 --dry-run
Follow: @.shared/workflows/rule-implementation.md
Resolve rule directory from coordinate:
registry/coordinate-map.yml (backbone key: registry.coordinate_map){categories.{category}}/{slug}/{agent_rules.{agent}}/{slug}/Parse rule.md frontmatter and body:
id, type, level, targets, question, criteria, Pass/Fail examples from bodychecks: is already non-empty — rule is already implementedThis is the critical step. The goal is to design a check that catches the class of violation, not a regex that discriminates between two fixture files.
| Field | Design role |
|---|---|
title | Names the concern — what property should instruction files have? |
question | Defines the evaluation question — what are we asking about the file? |
criteria | Lists observable properties of a PASSING file — invert each to get violation indicators |
| Pass example | ONE illustration of a good file — extract the structural pattern that makes it good |
| Fail example | ONE illustration of a bad file — extract the structural pattern that makes it bad |
Think in terms of violation structure, not fixture discrimination.
file_exists, directory_exists, directory_contains, git_tracked, frontmatter_key, file_count, line_count, byte_size, path_resolves, extract_importsargs from rule description (e.g., max: 300 for line_count)Design a pattern that matches the structural signature of the violation:
criteria (if present). Each criterion describes a PASSING property. Invert: what does a file look like when it LACKS this property?Two violation types:
| Type | Approach | Example |
|---|---|---|
| Presence of bad content | Pattern matches the violation directly | Secrets: (?i)(api[_-]?key|secret)\s*[=:]\s*['"]?[A-Za-z0-9]{8,} |
| Absence of good content | Pattern matches the structural gap left by the missing content | Missing description: ^#\s+[^\n]+\n\s*\n## (title followed immediately by section heading, no prose between) |
NEVER use presence-then-negate as the primary strategy. A pattern with negate: true that looks for "does good content exist?" is fragile — any incidental keyword match satisfies it. Instead, find the structural shape of the violation itself.
negate: true is acceptable ONLY when:
For core rules: use {{instruction_files}} in paths (not **/*.md).
Semantic rules have two phases: deterministic pre-check → semantic evaluation.
Pre-check purpose: Find text that EXHIBITS the violation pattern — content that needs human/LLM judgment to determine if it's actually a violation.
Pre-check design:
question field. What kind of content needs to be EVALUATED?criteria field. What observable text patterns MIGHT indicate a violation but need context to confirm?Example: Rule "no-linter-enforceable-style"
(?i)(style|format|indent) — matches the rule's topic, not violation indicators(?i)(indent|tab|space|bracket|semicolon|line.length|80.char|120.char) — matches specific linter-enforceable patternsTerminal semantic check uses prompt derived from rule's question/criteria fields.
Write checks: array in rule.md frontmatter:
{NAMESPACE}.{CATEGORY}.{SLOT}.{descriptive-name} format (e.g., CORE.S.0005.file-exists)mechanical rule → only mechanical checksdeterministic rule → mechanical + deterministic checkssemantic rule → any types, semantic must be lastcritical for L1, high/medium for L2+For deterministic/semantic rules, write regex patterns in rule.yml:
id matches the check ID from frontmatterlanguages: [generic] for markdown targetspaths.include uses template vars ({{instruction_files}})For mechanical-only rules: leave rule.yml as rules: [].
Fixtures simulate REAL instruction files, not minimal test content.
Pass fixture (tests/pass/):
CLAUDE.md for claude agent)Fail fixture (tests/fail/):
Fixture quality check: After generating fixtures, re-read them and ask:
Remove .gitkeep from directories that now have real fixture content.
Run the test harness (/test-rules):
docker compose -f runtime/docker-compose.yml -f runtime/docker-compose.dev.yml run --rm test --rule <coordinate> --verbose
schemas/rule.schema.yml — check field definitions, mechanical check names, severity enumdocs/pattern-guide.md — pattern syntax, generic mode, combining patternsruntime/ — test runner, fixture format, mechanical check implementationsagents/{agent}/config.yml — template var values per agent.shared/knowledge/backbone-resolution.md| Rule type | Modifies rule.md | Modifies rule.yml | Fixture content |
|---|---|---|---|
| mechanical | checks with check + args | No change (rules: []) | Files/dirs matching check function expectations |
| deterministic | checks with pattern + message | Regex patterns | Content triggering/not triggering pattern |
| semantic | pre-checks + terminal prompt | Regex patterns for pre-checks | Content producing/not producing candidates |
| rule.md severity | rule.yml severity |
|---|---|
| critical | ERROR |
| high | WARNING |
| medium | WARNING |
| low | WARNING |
Rule: "has-project-description" — file must open with a project description.
Violation structure: Title exists, but next non-blank line is a section heading (no description prose between).
pattern-regex: "^#\\s+[^\\n]+\\n\\s*\\n##"
message: "Title followed immediately by section heading — no project description"
This catches the SHAPE of the problem: # Title\n\n## Section with nothing between.
Same rule, but designed to discriminate fixtures:
pattern-regex: "\\A## "
message: "File opens with H2 instead of project description"
This only catches files starting with ## — misses the primary failure mode (title present, description absent).
Rule: "has-commands" — file must document executable commands.
Violation structure: File has sections but none contain backtick-wrapped commands.
# Combined pattern: file has 2+ sections but zero backtick commands
patterns:
- pattern-regex: "^## "
- pattern-not-regex: "`[a-z]+ .+`"
This requires both conditions: structured file (has sections) AND no commands. A file with no structure at all fails a different rule.
Same rule, but as a negated presence check:
pattern-regex: "`[a-z]+ .+`"
negate: true # fragile — any backtick content satisfies this
A file containing `see above` or `my-var` passes this check despite having no actual commands.
| Mistake | Fix |
|---|---|
| Pattern discriminates fixtures instead of catching violation class | Re-analyze: what is the STRUCTURAL SHAPE of the violation? |
Using negate: true as primary strategy | Find the structural gap pattern. Negate is last resort only. |
| Pre-check matches rule topic instead of violation indicators | Pre-check should find text that NEEDS judgment, not text about the topic |
| Fixture is minimal synthetic content | Write realistic 30-80 line instruction files |
| Fail fixture is broken in multiple ways | One specific violation in an otherwise reasonable file |
| Pattern matches desired state | Invert: pattern must match the violation |
Using **/*.md in paths | Use {{instruction_files}} template var |
Missing cross_file: true | Add when pattern operates across target set |
| Semantic rule without pre-checks | Always add deterministic pre-check before semantic |
| Fixture file named wrong | Must match resolved template var (e.g., CLAUDE.md) |
Leaving .gitkeep alongside real fixtures | Remove .gitkeep when adding content |