agentleFS
89jobrien89jobrien/godmode/skills/crs-hook-testing/SKILL.md

godmode:crs-hook-testing

Skill1 starsChanged 56 days agoMITView on GitHub

Coursers rule lifecycle pipeline. Walk a course-correct rule (or candidate rule) through the full lifecycle: author → validate → probe → fire (pre/post) → observe → refine/retire. Use when adding a new crs/coursers rule, auditing an existing one, or diagnosing a rule that is misfiring or dead.

  • Installs packages

The file

We split this skill into the rules it gives an agent

7 rules. About 0 are common, 3 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Check that all rules are well-formed, patterns compile, and alternative tools are on PATH:

    line 77
  2. Distinctive:

    After the rule has been live for a session or more, check its activity:

    line 140
  3. Very specific:

    Add more entries to exceptions

    line 174
  4. Very specific:

    Verify the pattern actually matches the commands you care about via crs probe

    line 180
  5. Distinctive:

    Check if an exception is over-broad and eating all matches

    line 181
  6. Very specific:

    Remove the rule from the JSON file.

    line 185
  7. Very specific:

    After editing crates/core or crates/coursers, the live crs/coursers binaries are NOT updated automatically.

    line 220

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

CRS Hook Testing — Coursers Rule Lifecycle

A structured pipeline for managing the lifecycle of a course-correct rule in ~/.config/coursers/course-correct-rules.json.

Each stage maps to one or more crs / coursers subcommands. Walk through stages in order for a new rule. Jump to the relevant stage when debugging or refining an existing rule.


Stage 0: Discover (optional — new rules only)

Surface Bash commands that coursers is not yet handling:

crs discover

Output: commands seen in Claude Code session logs that have no matching rule. Pick candidates for a new rule from this list.

Also useful:

crs suggest

Output: heuristically proposed new rules based on unhandled command frequency.


Stage 1: Author

Edit ~/.config/coursers/course-correct-rules.json (or the path in $COURSERS_RULES).

Each rule has:

{
  "id": "no-raw-grep",
  "description": "Use ripgrep (rg) instead of grep",
  "pattern": "\\bgrep\\b",
  "message": "Use `rg` instead of `grep` — faster and respects .gitignore",
  "exceptions": [
    "git (commit|log|tag|stash)",
    "git -C .* (commit|log|tag|stash)"
  ],
  "alternative": "rg",
  "failure_threshold": null
}

Key fields:

  • pattern — regex matched against the full Bash command string (not per-segment)
  • exceptions — list of regexes; if any match, the rule does not fire
  • alternative — tool name used in the block message and checked by validate
  • failure_threshold — optional: block a command after this many consecutive failures

Stage 2: Validate

Check that all rules are well-formed, patterns compile, and alternative tools are on PATH:

crs validate

Fix any errors before continuing. Common failures:

  • Invalid regex in pattern or exceptions
  • Alternative tool not on PATH (install it or remove the alternative field)

Stage 3: Probe

Interactively test a rule against a specific command string before wiring into the live hook:

# Pass a raw command string:
echo "grep -r foo ." | crs probe

# Pass a PreToolUse JSON payload (matches real hook input):
echo '{"tool":"Bash","input":{"command":"grep -r foo ."}}' | crs probe

crs probe prints per-rule verdicts — which rules matched, which exceptions fired, and the final block/allow decision.

Note: probe matches the whole command string. The live crs pre hook additionally splits pipeline commands on ; / && / || before matching. If a rule behaves differently in production than in probe, test via crs pre with the full JSON payload.

echo '{"tool":"Bash","input":{"command":"grep -r foo . && echo done"}}' | crs pre

Stage 4: Fire (pre/post)

Exercise the rule through the real hook chain:

Pre-tool (blocking):

echo '{"tool":"Bash","input":{"command":"<command-to-test>"}}' | coursers pre

Exit 0 = allowed. Exit 2 = blocked (rule fired). The response JSON is printed.

Post-tool (failure learning):

echo '{"tool":"Bash","input":{"command":"<cmd>"},"output":{"exit_code":1}}' | coursers post

Records the failure to the rolling state log. After failure_threshold hits, crs pre will block the command even without a pattern match.


Stage 5: Observe

After the rule has been live for a session or more, check its activity:

# Count by rule (all time):
crs stats

# Heatmap — visual frequency chart:
crs heat

# Recent blocked commands:
crs history

# Full hook execution log (last N entries):
crs log --limit 50

# Filter to a specific rule:
crs log --limit 200 | rg "<rule-id>"

Also export a full snapshot for offline analysis:

crs export > /tmp/crs-snapshot-$(date +%Y%m%d).json

Stage 6: Refine or Retire

Based on Stage 5 observations:

Rule fires too broadly (false positives)

  • Narrow pattern regex, or
  • Add more entries to exceptions

Then re-run Stage 2 (validate) and Stage 3 (probe) before deploying.

Rule never fires

  • Verify the pattern actually matches the commands you care about via crs probe
  • Check if an exception is over-broad and eating all matches

Rule is obsolete

Remove the rule from the JSON file. Run crs validate to confirm the file is still clean.

Tracking rule health across sessions

crs insights    # session facets with git context
crs replay      # replay past session Bash commands through the current ruleset

replay is especially useful after narrowing a pattern — it shows how the change would have affected past sessions.


Quick Reference

StageCommand(s)
Discovercrs discover, crs suggest
AuthorEdit ~/.config/coursers/course-correct-rules.json
Validatecrs validate
Probeecho '<cmd>' | crs probe
Fire (pre)echo '<json>' | coursers pre
Fire (post)echo '<json>' | coursers post
Observecrs stats, crs heat, crs history, crs log
Exportcrs export
RefineEdit rules → validate → probe → observe
Replaycrs replay, crs insights

Common Pitfalls

  • probe vs pre divergence: probe matches the whole command string; pre splits on shell operators first. Always test with crs pre before trusting crs probe alone.
  • After editing crates/core or crates/coursers, the live crs/coursers binaries are NOT updated automatically. Run cargo install --path crates/coursers to deploy.
  • The no-find-use-glob rule matches find .ctx in commit messages. Exceptions for git (commit|log|tag|stash) (including git -C form) suppress this.
  • State files: global at ~/.config/coursers/course-correct-state.json; project-local at .ctx/course-correct-state.json (wins over global).

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.