@tank/rule-creator
1.0.0Skill
Description
Author Tank rule atoms -- declarative validation constraints that block, allow, or warn on agent behavior. Covers rule atom schema, policy design, event binding, composition in bundles, and worked examples.
Triggered by
create ruletank rule atomblock policywarn policysafety ruleenforce rule
Download
Verified
tank install @tank/rule-creatorRule Creator
Author declarative rule atoms that enforce constraints on agent behavior without writing code. Rules are data, not logic -- the runtime evaluates them.
Core Philosophy
- Rules are data, hooks are code -- A rule declares "block X when Y" as a JSON object. A hook executes arbitrary TypeScript. Prefer rules for anything expressible as a match-and-act pair. Reach for hooks only when rules lack the expressiveness.
- Block is a last resort -- Blocking halts the agent. Use
warnfor guidance,allowfor explicit permission,blockonly for genuinely dangerous operations. Over-blocking creates a useless agent. - Reason is not optional -- Every rule must include a
reasonfield explaining why the constraint exists. The agent reads reasons to adjust behavior before hitting the wall. - Compose, don't monolith -- Ship rule sets as arrays inside a bundle's
atoms. Each rule targets one concern. Ten focused rules beat one mega-rule with complex match logic. - Test by triggering -- Verify a rule works by deliberately triggering its condition. A rule you have never seen fire is a rule you cannot trust.
Quick-Start: Common Problems
"Block a dangerous shell command"
- Create a multi-atom bundle under
bundles/ - Add a
kind: "rule"atom withevent: "pre-command" - Set
policy: "block", addmatchandreason-> Seereferences/rule-atom-anatomy.mdfor field schema -> Seereferences/worked-examples.mdforrm -rfexample
"Warn when agent writes bad patterns"
- Add a
kind: "rule"atom withevent: "post-file-write" - Set
policy: "warn", match against the pattern (e.g.,as any) - Pair with an instruction atom explaining the preferred alternative
-> See
references/policy-design.mdfor warn vs block guidance -> Seereferences/worked-examples.mdforas anyexample
"Restrict which tools the agent can use"
- Add a
kind: "rule"atom withevent: "pre-tool-use" - Set
policy: "allow"with amatchon the approved tool list - Add a second rule with
policy: "block"as a catch-all deny -> Seereferences/worked-examples.mdfor allow-list example
"Ship a complete policy set"
- Create a
bundles/{name}/directory - Add an
atomsarray with multiple rule atoms + an instruction atom - The instruction explains the rationale; rules enforce it
-> See
references/policy-design.mdfor composition patterns -> Seereferences/worked-examples.mdfor combined bundle example
Decision Trees
Policy Selection
| Signal | Policy | Rationale |
|---|---|---|
| Data loss, credential leak, system damage | block | Irreversible harm, stop immediately |
| Code smell, style violation, minor risk | warn | Educate without halting |
| Known-safe operation in a restricted set | allow | Explicit permission overrides defaults |
Event Selection
| Constraint target | Event | Category |
|---|---|---|
| Shell command content | pre-command | Shell |
| Tool invocation | pre-tool-use | Tool |
| File content after save | post-file-write | File |
| File content before save | pre-file-write | File |
| MCP tool call | pre-mcp-tool-use | MCP |
| Agent finishing work | pre-stop | Stop |
| Agent response | post-response | Convo |
Rule vs Hook
| Need | Use |
|---|---|
| Match string/pattern, act with fixed policy | Rule |
| Conditional logic, external API calls | Hook |
| Multiple rules composing a policy set | Rules |
| Dynamic rewriting of commands/content | Hook |
| Simple block/warn/allow on a known pattern | Rule |
Atom Schema Quick Reference
{
"kind": "rule",
"event": "pre-command",
"policy": "block",
"match": "rm -rf",
"reason": "Destructive file deletion is not permitted",
"extensions": {}
}
Required: kind, event, policy. Strongly recommended: reason.
Optional: match, name, extensions.
-> See references/rule-atom-anatomy.md for complete field reference.
Reference Index
| File | Contents |
|---|---|
references/rule-atom-anatomy.md | Full rule atom schema, fields, types, events |
references/policy-design.md | Policy strategy, composition, precedence, safety |
references/worked-examples.md | 4+ complete rule examples with tank.json context |