add-guardrail
Block repeated mistakes with types, lint, CI, hooks, or permission rules, with AGENTS.md last. Use after a correction recurs or to mine past sessions with droid search; not for opening /hooks or editing permissionRules by hand.
Cynnamoroll · 已有静态检查记录
安装与使用
运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。
npx skills add Cynnamoroll/factory-stack --skill add-guardrail技能说明
name: add-guardrail description: "Block repeated mistakes with types, lint, CI, hooks, or permission rules, with AGENTS.md last. Use after a correction recurs or to mine past sessions with droid search; not for opening /hooks or editing permissionRules by hand." license: MIT compatibility: droid disable-model-invocation: true
Add guardrail
Make the mistake impossible to repeat. Assume contributors see only opened files, copy the nearest example, and take the shortest path that compiles.
1. Find the mistake classes
Gather the corrections from one of these sources:
- this session
- past sessions:
droid search "<phrase>" --kind message_text --json, then read the matching turns - recent commits, reverts, review comments, and
AGENTS.md
Group corrections into classes with at least two occurrences. Show each class's evidence.
2. Pick the highest rung that works
- Architecture. One owner per piece of state and one supported way per task. Hide internals so the wrong import fails. Replace hand-synced lists with one source. Delete the old way an agent would copy.
- Types, lint, or CI. Make the bad state fail to compile. If it still compiles, add a lint rule or CI check whose error names the right file, type, or function. If the pattern is already common, fail only when a change adds more.
- Hook or permission rule. For agent actions code cannot catch:
- a
PreToolUsehook in.factory/hooks.jsonthat exits2with the reason on stderr, matched onExecute,Edit,Create, orApplyPatch, with the script under.factory/hooks/and called through"$FACTORY_PROJECT_DIR" - a
permissionRulesentry in.factory/settings.jsonwithblockoraskandtests.match/tests.noMatchcases, for shell commands only
- a
AGENTS.md, last. Only for judgment calls nothing can check. A personal habit goes in~/.factory/AGENTS.md. A repo rule goes in the projectAGENTS.md.
Pick the highest effective rung. Explain why higher rungs failed.
Changes to a skill go through /create-skill, not a hand edit here.
3. Prove each guardrail fails
Show each new check failing on a real past instance of the mistake, then passing on the corrected code:
- type, lint, or CI: run the same command locally that CI runs
- hook: pipe a sample payload into the script and check the exit code, for example
echo '{"tool_name":"Edit","tool_input":{"file_path":"gen/x.ts"}}' | .factory/hooks/protect.sh; echo $? - permission rule:
droid rules check --command '<bad command>'reports the decision, anddroid rules checkpasses its self-tests
If a check does not fail on the real mistake, fix the check, not the example. Hooks load at session start, so tell the user to review the new hook in /hooks and start a new session.
4. Record it
Keep a table in AGENTS.md that pairs each rule with what enforces it. Drop a rule once its mistake cannot happen.
Done when
Each class has its evidence, the rung chosen, why higher rungs failed, and a pasted run showing the guardrail fail then pass. One commit per class.