@zalom/plastic 1.14.1 → 2.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (189) hide show
  1. package/PLASTIC.md +101 -294
  2. package/README.md +5 -6
  3. package/agents/plastic-advisor.md +18 -17
  4. package/agents/plastic-enforcer.md +57 -69
  5. package/agents/plastic-executor.md +34 -20
  6. package/agents/plastic-faux-advisor.md +18 -18
  7. package/config_asks.yml +38 -0
  8. package/hooks/capture +4 -0
  9. package/hooks/close +5 -0
  10. package/hooks/hooks.json +9 -49
  11. package/hooks/record +4 -0
  12. package/package.json +3 -2
  13. package/scripts/agent-report +8 -9
  14. package/scripts/append-ledger +195 -0
  15. package/scripts/codex-hook +78 -90
  16. package/scripts/dashboard.rb +4 -4
  17. package/scripts/doctor.rb +106 -43
  18. package/scripts/end-intent +77 -76
  19. package/scripts/exec-worktree +11 -20
  20. package/scripts/file-session-intent +61 -0
  21. package/scripts/hook-capture +242 -0
  22. package/scripts/hook-close +34 -0
  23. package/scripts/hook-record +149 -0
  24. package/scripts/hook-session-start +95 -12
  25. package/scripts/install.rb +8 -6
  26. package/scripts/lib/agent_models.rb +1 -7
  27. package/scripts/lib/arm.rb +283 -0
  28. package/scripts/lib/backfill_intent.rb +316 -0
  29. package/scripts/lib/bridge.rb +24 -1597
  30. package/scripts/lib/doctor_core.rb +17 -88
  31. package/scripts/lib/doctor_session_ledger.rb +106 -0
  32. package/scripts/lib/exec_worktree.rb +14 -60
  33. package/scripts/lib/harness_text.rb +5 -4
  34. package/scripts/lib/hook_registry.rb +44 -107
  35. package/scripts/lib/insights.rb +3 -4
  36. package/scripts/lib/installer_core.rb +19 -30
  37. package/scripts/lib/lock.rb +6 -26
  38. package/scripts/lib/outcome_guard.rb +7 -5
  39. package/scripts/lib/project_validator.rb +30 -1
  40. package/scripts/lib/roadmap_queue.rb +3 -3
  41. package/scripts/lib/roadmap_savepoint.rb +1 -1
  42. package/scripts/lib/rule_catalog.rb +6 -3
  43. package/scripts/lib/savepoint.rb +320 -0
  44. package/scripts/lib/scaffold_intent.rb +13 -179
  45. package/scripts/lib/session_backfill.rb +184 -0
  46. package/scripts/lib/session_close.rb +84 -0
  47. package/scripts/lib/session_git.rb +469 -0
  48. package/scripts/lib/session_ledger.rb +497 -0
  49. package/scripts/lib/store_discovery.rb +1 -1
  50. package/scripts/lib/store_provisioning.rb +1 -1
  51. package/scripts/maintenance-run +7 -7
  52. package/scripts/new-intent +63 -4
  53. package/scripts/plastic-lock +94 -41
  54. package/scripts/promote-session-item +150 -0
  55. package/scripts/rebuild-graph +1 -1
  56. package/scripts/roadmap-next +2 -2
  57. package/scripts/rollback.rb +42 -3
  58. package/scripts/scaffold-intent +37 -63
  59. package/scripts/session-commit +116 -0
  60. package/scripts/spawn-preamble +5 -5
  61. package/scripts/update.rb +7 -3
  62. package/skills/agent-advisor/SKILL.md +3 -3
  63. package/skills/agent-advisor/references/advisor-protocol.md +20 -20
  64. package/skills/auto/SKILL.md +218 -317
  65. package/skills/auto/evals/evals.json +10 -10
  66. package/skills/auto/references/agent-architecture.md +102 -90
  67. package/skills/auto/references/agent-report-contract.md +4 -21
  68. package/skills/auto/references/end-tail.md +47 -53
  69. package/skills/auto/references/human-report-contract.md +8 -8
  70. package/skills/conventions/SKILL.md +1 -3
  71. package/skills/conventions/references/lifecycle-and-savepoints.md +35 -1
  72. package/skills/conventions/references/locks-and-worktrees.md +47 -55
  73. package/skills/conventions/references/maintenance-and-revisions.md +12 -12
  74. package/skills/dashboard/SKILL.md +1 -1
  75. package/skills/direct/SKILL.md +66 -0
  76. package/skills/direct/references/request-signals.md +59 -0
  77. package/skills/doctor/SKILL.md +58 -11
  78. package/skills/doctor/report.md +3 -1
  79. package/skills/install/SKILL.md +11 -9
  80. package/skills/intent-continuing/SKILL.md +131 -89
  81. package/skills/intent-continuing/references/boarding-matrix.md +34 -0
  82. package/skills/intent-continuing/references/context-management.md +2 -2
  83. package/skills/intent-creating/SKILL.md +2 -2
  84. package/skills/intent-creating/references/lifecycle.md +1 -1
  85. package/skills/intent-ending/SKILL.md +28 -37
  86. package/skills/intent-ending/evals/evals.json +4 -4
  87. package/skills/intent-executing/SKILL.md +12 -49
  88. package/skills/intent-executing/plan-reviewer-prompt.md +39 -0
  89. package/skills/intent-speccing/SKILL.md +108 -51
  90. package/skills/intent-speccing/evals/evals.json +5 -5
  91. package/skills/intent-speccing/references/per-section-fill-rules.md +4 -4
  92. package/skills/intent-speccing/references/self-verify-checklist.md +1 -2
  93. package/skills/project-creating/SKILL.md +1 -1
  94. package/skills/releasing/SKILL.md +7 -8
  95. package/skills/tutorial/SKILL.md +2 -2
  96. package/skills/tutorial/references/track-1-guided.md +16 -18
  97. package/skills/tutorial/references/track-2-auto.md +12 -13
  98. package/skills/tutorial/references/track-3-projects-and-roadmaps.md +2 -2
  99. package/templates/agents.md +4 -7
  100. package/templates/project.yml +7 -0
  101. package/templates/roadmap.md +1 -1
  102. package/templates/savepoint.md +2 -2
  103. package/templates/session-intent.md +29 -0
  104. package/agents/plastic-brainstorming.md +0 -48
  105. package/agents/plastic-future-intent-researcher.md +0 -35
  106. package/agents/plastic-intent-curator.md +0 -47
  107. package/agents/plastic-intent-discovery.md +0 -43
  108. package/agents/plastic-planner.md +0 -56
  109. package/agents/plastic-spec-specialist.md +0 -53
  110. package/hooks/auto-arm +0 -5
  111. package/hooks/bash-gate +0 -3
  112. package/hooks/continue +0 -31
  113. package/hooks/edit-gates +0 -3
  114. package/hooks/future-intent-check +0 -25
  115. package/hooks/gate-check +0 -12
  116. package/hooks/power-tools +0 -8
  117. package/scripts/hook-auto-arm +0 -51
  118. package/scripts/hook-bash-gate +0 -78
  119. package/scripts/hook-code-gate +0 -38
  120. package/scripts/hook-continue +0 -48
  121. package/scripts/hook-create-gate +0 -51
  122. package/scripts/hook-edit-gates +0 -58
  123. package/scripts/hook-future-intent-check +0 -90
  124. package/scripts/hook-gate-check +0 -169
  125. package/scripts/hook-links-gate +0 -54
  126. package/scripts/hook-lock-gate +0 -47
  127. package/scripts/hook-power-tools +0 -38
  128. package/scripts/hook-savepoint-pre +0 -32
  129. package/scripts/lib/codex_edit_gates.rb +0 -138
  130. package/scripts/lib/edit_gates.rb +0 -398
  131. package/scripts/lib/links_gate.rb +0 -140
  132. package/scripts/lib/qmd_hook.rb +0 -41
  133. package/scripts/lib/spec_header.rb +0 -83
  134. package/scripts/lib/start_intent.rb +0 -296
  135. package/scripts/start-intent +0 -89
  136. package/skills/_active-intent-gate.md +0 -26
  137. package/skills/auto/references/tiers.md +0 -100
  138. package/skills/continuing/SKILL.md +0 -34
  139. package/skills/continuing/evals/evals.json +0 -91
  140. package/skills/conventions/references/gates-and-enforcement.md +0 -53
  141. package/skills/conventions/references/tiers-and-dispatch.md +0 -135
  142. package/skills/doctor/references/gates-stuck-detection.md +0 -43
  143. package/skills/intent-brainstorming/SKILL.md +0 -118
  144. package/skills/intent-brainstorming/evals/evals.json +0 -67
  145. package/skills/intent-continuing/evals/evals.json +0 -145
  146. package/skills/intent-discovering/SKILL.md +0 -56
  147. package/skills/intent-grilling/SKILL.md +0 -108
  148. package/skills/intent-linking/SKILL.md +0 -128
  149. package/skills/intent-linking/evals/evals.json +0 -22
  150. package/skills/intent-linking/references/zettelkasten.md +0 -45
  151. package/skills/intent-locking/SKILL.md +0 -64
  152. package/skills/intent-planning/SKILL.md +0 -145
  153. package/skills/intent-planning/evals/evals.json +0 -81
  154. package/skills/intent-planning/references/plan-format.md +0 -130
  155. package/skills/intent-researching/SKILL.md +0 -123
  156. package/skills/intent-researching/evals/evals.json +0 -22
  157. package/skills/intent-savepoint/SKILL.md +0 -83
  158. package/skills/intent-savepoint/references/context-management.md +0 -32
  159. package/skills/intent-starting/SKILL.md +0 -151
  160. package/skills/intent-starting/evals/evals.json +0 -117
  161. package/skills/intent-starting/references/boarding-matrix.md +0 -35
  162. package/skills/project-continuing/SKILL.md +0 -119
  163. package/skills/project-continuing/evals/evals.json +0 -100
  164. package/skills/roadmap-continuing/SKILL.md +0 -89
  165. package/skills/roadmap-continuing/evals/evals.json +0 -82
  166. package/skills/skill-creating/SKILL.md +0 -75
  167. package/skills/skill-creating/evals/evals.json +0 -108
  168. package/skills/skill-creating/references/agents.md +0 -168
  169. package/skills/skill-creating/references/defaults-first.md +0 -23
  170. package/skills/skill-creating/references/evals.md +0 -41
  171. package/skills/skill-creating/references/hooks.md +0 -251
  172. package/skills/skill-creating/references/progressive-disclosure.md +0 -176
  173. package/skills/skill-creating/references/scripts.md +0 -166
  174. package/skills/skill-creating/references/skills.md +0 -169
  175. package/skills/skill-creating/scripts/scaffold.rb +0 -313
  176. package/skills/skill-evaluating/SKILL.md +0 -141
  177. package/skills/skill-evaluating/assets/eval-template.json +0 -12
  178. package/skills/skill-evaluating/evals/evals.json +0 -75
  179. package/skills/skill-evaluating/references/convention-checks.md +0 -76
  180. package/skills/skill-evaluating/references/eval-methodology.md +0 -154
  181. package/skills/store-curating/SKILL.md +0 -64
  182. package/skills/store-curating/evals/evals.json +0 -38
  183. package/skills/store-indexing/SKILL.md +0 -93
  184. package/skills/store-indexing/evals/evals.json +0 -22
  185. package/skills/store-indexing/references/zettelkasten-linking.md +0 -32
  186. package/skills/store-provisioning/SKILL.md +0 -55
  187. /package/skills/{project-continuing → intent-continuing}/references/board-fill.md +0 -0
  188. /package/skills/{roadmap-continuing → intent-continuing}/references/liveness-ranking.md +0 -0
  189. /package/skills/{intent-brainstorming → intent-speccing}/references/design-principles.md +0 -0
@@ -1,168 +0,0 @@
1
- # Authoring an Agent (subagent)
2
-
3
- How to write a subagent / Agent role file: scope, tools, description, the reviewer pattern,
4
- collector discipline, and the skill-vs-agent decision. Rules cite section D of the
5
- best-practices standard (D1 through D6).
6
-
7
- ## Contents
8
-
9
- - [When a skill suffices vs escalate to an agent](#when-a-skill-suffices-vs-escalate-to-an-agent)
10
- - [The agent definition fields](#the-agent-definition-fields)
11
- - [One focused task per agent](#one-focused-task-per-agent)
12
- - [Tight tool set](#tight-tool-set)
13
- - [Description: embedded when-to-use examples](#description-embedded-when-to-use-examples)
14
- - [Collectors, not implementers](#collectors-not-implementers)
15
- - [Reviewer / devil's-advocate agents](#reviewer--devils-advocate-agents)
16
- - [Composing skills and agents](#composing-skills-and-agents)
17
- - [Self-checks](#self-checks)
18
-
19
- For load levels, the three-bucket model, and description-as-trigger rules, open
20
- `progressive-disclosure.md` and `skills.md`. Do not re-derive them here (C7).
21
-
22
- ## When a skill suffices vs escalate to an agent
23
-
24
- Decide before authoring an agent at all. A full agent carries its own context window and tool
25
- grant, so it is too heavyweight for quick work [D5].
26
-
27
- | Situation | Build | Why |
28
- | --- | --- | --- |
29
- | Light read-only check, single-file validation, scaffold one file | Skill | A skill loads on trigger and runs in the current context, no spin-up cost [D5] |
30
- | Deep multi-file audit, parallel investigation, isolated noisy work | Agent | The isolated context keeps search and log noise off the main thread [D2][D5] |
31
- | Same task repeated with deterministic steps | Script (see `scripts.md`) | Executed, not loaded; token-free and variance-free |
32
-
33
- Default to a skill. Escalate to an agent only when the work needs an isolated context budget or
34
- its own restricted tool grant.
35
-
36
- ## The agent definition fields
37
-
38
- An agent file is frontmatter plus a system-prompt body. Set each field for one reason.
39
-
40
- | Field | When it matters | Set it to |
41
- | --- | --- | --- |
42
- | `name` | Always. The orchestrator and `SendMessage` address the agent by it | Lowercase-hyphen, one capability (`spec-reviewer`, `dependency-auditor`) |
43
- | `description` | Always. The orchestrator delegates purely on this text [D3] | Trigger conditions plus embedded when-to-use example pairs (see below) |
44
- | `tools` | Always. Omitting it grants every tool, which over-arms the agent [D1] | Only the tools the one task needs |
45
- | `model` | When the task is cheap (Haiku) or hard (Opus) | The cheapest tier that holds quality |
46
- | `proactive` marker | When the agent should auto-fire without an explicit ask [D3] | Include "use proactively" inside the description |
47
-
48
- Keep the body in imperative voice. State the agent's single job, its numbered process, and its
49
- output contract. Push reference detail into files the agent reads on demand, same as a skill body.
50
-
51
- ## One focused task per agent
52
-
53
- Give each agent exactly one task. Focused scope plus a tight tool set is what makes delegation
54
- decidable and cheap [D1].
55
-
56
- 1. Name the single responsibility in one phrase. If the name needs "and", split into two agents.
57
- 2. Start with one agent. Add a specialist only when it materially improves isolation or tool
58
- scoping [D1]. More agents widen the discovery surface and the orchestrator's choice space.
59
- 3. Write the body around that one task. An agent that "reviews and also fixes and also reports" has
60
- three jobs and no clear output contract.
61
-
62
- ## Tight tool set
63
-
64
- Grant only the tools the one task requires [D1].
65
-
66
- | Agent kind | Typical tools | Excluded |
67
- | --- | --- | --- |
68
- | Reviewer / auditor | Read, Grep, Glob | Edit, Write, Bash (read-only by design) [D4] |
69
- | Collector / researcher | Read, Grep, Glob, WebFetch | Edit, Write (returns a summary, does not change code) [D2] |
70
- | Implementer | Read, Edit, Write, Bash | Only the surface its task touches |
71
-
72
- A reviewer with Edit can rewrite the code it judges. A collector with Write can leak its noisy
73
- context back into the tree. The tool list is the guardrail; keep it narrow.
74
-
75
- ## Description: embedded when-to-use examples
76
-
77
- The orchestrator never reads the body at delegation time. It routes on the description alone, so
78
- the description must teach the boundary by example [D3].
79
-
80
- Write the description with:
81
-
82
- 1. A trigger clause in third person ("Use when reviewing a spec before the plan stage").
83
- 2. One or more `<example>` pairs showing a matching prompt, the assistant's choice to delegate, and
84
- a one-line `<commentary>` on why. Example pairs teach the boundary a keyword list cannot [D3].
85
- 3. "use proactively" when the agent should auto-fire without the user naming it [D3].
86
-
87
- Concrete shape:
88
-
89
- ```
90
- description: >
91
- Use when a spec is complete and needs an adversarial review before planning.
92
- Use proactively after the spec-specialist writes spec.md.
93
- <example>
94
- Context: spec.md just landed for the active intent.
95
- user: "Is this spec ready to plan?"
96
- assistant: "I'll use the spec-reviewer agent to challenge the spec before planning."
97
- <commentary>Adversarial review runs at the Why-to-How boundary.</commentary>
98
- </example>
99
- ```
100
-
101
- A description that summarizes the agent's workflow instead of its trigger makes the orchestrator
102
- act on the summary and skip the body. State when to fire, not how the agent works.
103
-
104
- ## Collectors, not implementers
105
-
106
- Use a subagent as an information collector that returns a short summary, not as an implementer [D2].
107
-
108
- | Do | Avoid |
109
- | --- | --- |
110
- | Return a tight summary: findings, file paths, a verdict | Stuffing raw search output or full file dumps back into the main thread |
111
- | Write a plan or summary markdown file as shared memory; have the main thread read it [D2] | Passing large results inline, which defeats the isolation |
112
- | Keep search, log, and crawl noise inside the agent's own context [D2] | Re-emitting that noise to the orchestrator |
113
-
114
- The reason a subagent has an isolated context is to absorb noise. The filesystem (a plan or summary
115
- file) is the shared memory between agents; the agent's return value is the headline, not the
116
- transcript [D2].
117
-
118
- ## Reviewer / devil's-advocate agents
119
-
120
- A reviewer agent needs four things, or it produces unscoped, unverifiable results [D4].
121
-
122
- 1. Read-only tools: Read, Grep, Glob, and nothing that edits [D4]. A reviewer that can edit stops
123
- being a reviewer.
124
- 2. A numbered review process in the body, so every run covers the same checks in the same order.
125
- 3. Explicit anti-scope: a "do not use for" clause that names what the agent must not do (implement
126
- fixes, refactor, approve its own changes) [D4].
127
- 4. A fixed, severity-bucketed output format, so findings are comparable across runs [D4].
128
-
129
- Fixed output contract:
130
-
131
- ```
132
- ## Critical
133
- - <finding> (file:line) -> <why it blocks>
134
-
135
- ## Major
136
- - <finding> (file:line) -> <impact>
137
-
138
- ## Minor
139
- - <finding> (file:line) -> <suggestion>
140
-
141
- ## Verdict
142
- PASS | BLOCK, with one-line reason.
143
- ```
144
-
145
- The severity buckets and the verdict are mandatory. Empty buckets stay in, marked "none", so a
146
- reader can tell the agent checked.
147
-
148
- ## Composing skills and agents
149
-
150
- Two mechanisms load content into an agent's context. Choose by what budget the isolated agent
151
- should carry [D6].
152
-
153
- | Mechanism | Effect | Use when |
154
- | --- | --- | --- |
155
- | Subagent `skills:` | Preloads the full skill content into the agent at spawn [D6] | The agent must always have that skill's rules in hand |
156
- | Skill `context: fork` | Runs the skill body as a task prompt inside a chosen agent type [D6] | A skill should execute as an isolated agent, not inline |
157
-
158
- Pick deliberately. `skills:` spends the agent's budget up front for guaranteed availability;
159
- `context: fork` hands the body to a fresh agent so the work runs isolated [D6].
160
-
161
- ## Self-checks
162
-
163
- - Could this be a skill instead? If the work is light or single-file, build a skill [D5].
164
- - Does the agent have exactly one job, named without "and"? [D1]
165
- - Is the tool list the minimum the job needs, and read-only for a reviewer? [D1][D4]
166
- - Does the description carry at least one `<example>` pair and "use proactively" if it auto-fires? [D3]
167
- - Does the agent return a summary and use a file as shared memory, not dump its context? [D2]
168
- - Does a reviewer have a numbered process, an anti-scope clause, and a severity-bucketed output? [D4]
@@ -1,23 +0,0 @@
1
- # Defaults First
2
-
3
- This chapter holds the Plastic-first, delegate-by-exception rule for naming an external skill as a default.
4
-
5
- ### Defaults-First
6
-
7
- Plastic stands on its own. Skills and agents use Plastic's own defaults; an
8
- external skill (for example `superpowers:*`) is opt-in, never load-bearing.
9
-
10
- - **Default to Plastic, delegate by exception.** Name the Plastic-native path as
11
- the default. Delegate to an external skill only when (a) it is available in the
12
- harness, or (b) the user explicitly asks for it. A user without that plugin must
13
- still get the core behavior.
14
- - **Phrase external skills as enhancements.** Write "use Plastic's native X by
15
- default; if `superpowers:<skill>` is available, or the user prefers it, delegate
16
- to it" never "delegate to `superpowers:<skill>`" as the only path.
17
- - **Optional dependencies detect then degrade.** `qmd` is the reference shape:
18
- `scripts/lib/qmd_sync.rb` detects the binary first and every verb no-ops cleanly
19
- when it is absent (see `scripts/qmd-sync`). Optional CLIs and MCP servers follow
20
- the same detect-then-skip pattern, so a missing tool never crashes a session.
21
- - **Legitimate hard dependencies are exempt.** Ruby, Node, git, and POSIX tools are
22
- the cost of running Plastic, not silent coupling. The principle targets accidental
23
- dependence on external skills doing work Plastic should do itself.
@@ -1,41 +0,0 @@
1
- # Evals (author-time gate)
2
-
3
- This is the gate, not the method. It states the eval decisions an author makes while building a
4
- skill, then hands the full procedure to one place. Do not duplicate that procedure here.
5
-
6
- ## Build evals before docs
7
-
8
- Build at least three evals before writing extensive documentation. A skill without an eval is an
9
- assertion, not a capability, so the eval forces the skill to close a real observed gap instead of an
10
- imagined one. [F1]
11
-
12
- Build RED-GREEN-REFACTOR. Run the scenario without the skill and record the verbatim failure (RED),
13
- write the minimal instructions that fix exactly that failure (GREEN), then close the loopholes the
14
- failure exposed (REFACTOR). Only instructions that move a failing eval earn their tokens. [F2]
15
-
16
- ## What each eval must cover
17
-
18
- - Description triggering. Pair should-trigger queries with near-miss negatives: prompts that share
19
- keywords with the skill but need a different skill entirely. Near-miss negatives catch
20
- over-triggering, the most common description failure. State the trigger set here; do not size the
21
- query count or split here. [F3]
22
- - Output quality. Write assertions only after observing real output. Make them specific, verifiable,
23
- and countable, with no benefit of the doubt and no brittle exact-phrase matching. Assertions
24
- written before observation encode hopes, not behavior, so include at least one output-quality case
25
- graded this way. [F4]
26
- - Discipline under pressure. For a skill whose job is restraint, stack pressures (time, sunk cost,
27
- authority, exhaustion) with forced options and run the case via a subagent. Reciting the rule is
28
- not complying with it. [F5]
29
-
30
- ## Grading and reliability decisions
31
-
32
- Grade with the cheapest sufficient tier, and track capability (pass@k) separately from reliability
33
- (pass^k) with k at least three. The evaluating-skills skill owns the grader taxonomy, judge
34
- calibration, clean-context execution, and cross-model testing. [F6, F7, F8]
35
-
36
- ## Run them with the methodology skill
37
-
38
- Use the evaluating-skills skill to author and run the evals. It owns the full method: eval scope
39
- selection, the query-count and train/validation protocol, the grader taxonomy and judge calibration,
40
- the iteration loop, and graduation of stable capability evals into regression. It is the source of
41
- truth for those steps; this file states the author-time gate and stops there. [F6, F7, F8]
@@ -1,251 +0,0 @@
1
- # Authoring a Lifecycle Hook
2
-
3
- A hook is a harness: deterministic code the Claude Code runtime fires at a lifecycle
4
- event. Author one when a probabilistic skill keeps dropping a behavior and that behavior
5
- must hold every time.
6
-
7
- For body voice, budgets, and reference rules, see `progressive-disclosure.md` and `skills.md`.
8
- For deciding script versus prose and writing the handler logic, read `scripts.md` when the
9
- handler grows past a few lines. This file covers only hook authoring.
10
-
11
- ## Contents
12
-
13
- - When to reach for a hook (E1)
14
- - The event to matcher to handler model (E2)
15
- - Which event for which job (E2)
16
- - Path rules and executability (E3)
17
- - No-op by default, opt-in (E4)
18
- - Exit codes and output channels (E5)
19
- - Verify the harness engaged (E6)
20
- - Token levers: global hooks that shrink context (E7)
21
- - Propose-only self-improving loop (E8)
22
- - Authoring checklist
23
-
24
- ## When to reach for a hook (E1)
25
-
26
- Reach for a hook only after a skill has lost the behavior. The documented order is: first
27
- strengthen the skill description and instructions so the model keeps preferring the skill;
28
- if it still drops the step, enforce it deterministically with a hook. [E1]
29
-
30
- Test: ask "does this behavior have to hold even when the model forgets the skill?" If yes
31
- (a gate before a destructive tool, a savepoint before compaction, a format pass after every
32
- edit), the runtime must enforce it, not the prompt. If no, leave it in the skill body and
33
- spend no hook tokens on it. [E1]
34
-
35
- A hook is code on the critical path of an event. It is not loaded into context, so it costs
36
- no tokens at trigger time, but a mistuned hook blocks real work. Make it earn the
37
- intervention. [E1]
38
-
39
- ## The event to matcher to handler model (E2)
40
-
41
- Hooks are configured in three nested levels: event, then matcher group, then handler list.
42
- [E2]
43
-
44
- - Event: the lifecycle moment (for example PreToolUse, SessionStart, PreCompact).
45
- - Matcher: which instances of that event fire the handler. For tool events the matcher is a
46
- tool-name pattern (`Bash`, `Edit|Write`, `mcp__memory__.*`). For SessionStart the matcher
47
- is a source (`startup`, `resume`, `clear`, `compact`). For PreCompact it is `manual` or
48
- `auto`.
49
- - Handler: what runs. Handler types include `command` (a script, JSON arrives on stdin),
50
- `http`, `mcp_tool`, `prompt` (an LLM yes/no), and `agent`. Author `command` handlers as
51
- scripts unless a non-script handler is clearly required. [E2]
52
-
53
- Each event exposes different inputs and a different blocking power, so the wrong event cannot
54
- do the job no matter how the handler is written. Select the event first, then the matcher,
55
- then the handler. [E2]
56
-
57
- ## Which event for which job (E2)
58
-
59
- | Job | Event | Matcher example | Can block | Key inputs |
60
- | --- | --- | --- | --- | --- |
61
- | Gate or validate before a tool runs | PreToolUse | `Edit\|Write`, `Bash` | yes (exit 2 or `permissionDecision: deny`) | `tool_name`, `tool_input` |
62
- | Format, lint, or remind after a tool succeeds | PostToolUse | `Edit\|Write` | block before next model call only | `tool_name`, `tool_input`, `tool_output` |
63
- | Boot or inject context at session start | SessionStart | `startup`, `resume`, `clear`, `compact` | no | `source` |
64
- | Savepoint before compaction | PreCompact | `manual`, `auto` | no (savepoint; exits 0) | compaction trigger |
65
- | Erase or augment a prompt before processing | UserPromptSubmit | (none) | yes (exit 2) | `prompt`, `permission_mode` |
66
-
67
- Notes that change the choice of event: [E2]
68
-
69
- - PreToolUse fires before the tool runs and can stop it. Use it for gates and pre-act
70
- validation (block an edit to project code before the plan exists, block a destructive
71
- Bash command).
72
- - PostToolUse fires after the tool has already run. It cannot undo the tool. Use it to format
73
- the result, lint it, or surface a reminder, and to block the next model call when the
74
- output is unacceptable.
75
- - SessionStart cannot block. Use it to inject boot context, not to enforce anything. Its
76
- stdout on exit 0 becomes conversation context (see exit codes).
77
- - PreCompact fires before the runtime compacts the conversation. Use it to write a savepoint
78
- while the full context still exists.
79
-
80
- Plastic ships working instances of each: `hooks/edit-gates` -> `scripts/hook-edit-gates`
81
- (PreToolUse, the merged dispatcher that runs code-gate, lock-gate, savepoint-pre, links-gate,
82
- and create-gate in one process; each gate's own logic lives in `scripts/lib/edit_gates.rb`
83
- and is also reachable through the standalone `scripts/hook-code-gate` CLI wrapper),
84
- `scripts/hook-session-start` (SessionStart boot and inject), `scripts/hook-savepoint-pre`
85
- (PreCompact savepoint). Read one before authoring a new hook of the same shape.
86
-
87
- ## Path rules and executability (E3)
88
-
89
- Two failures here are silent: the hook never fires and nothing reports why. [E3]
90
-
91
- - Reference the handler script through the exported placeholders: `${CLAUDE_PLUGIN_ROOT}` for
92
- a script shipped inside a plugin, `${CLAUDE_PROJECT_DIR}` for a script that lives in the
93
- project. A relative path resolves against an unpredictable working directory; a hard-coded
94
- absolute path works in development and breaks on another machine. [E3]
95
- - Make the script executable: `chmod +x` the handler file and commit that bit. A
96
- non-executable `command` handler fails silently. [E3]
97
- - Give the script a shebang (`#!/usr/bin/env ruby` for Plastic hooks; any shell must run under
98
- macOS /bin/bash 3.2). [E3]
99
-
100
- Other placeholders the runtime exports: `${CLAUDE_PLUGIN_DATA}`. [E3]
101
-
102
- ## No-op by default, opt-in (E4)
103
-
104
- Make a hook a no-op by default and enable it only through explicit config. Exit 0 (allow,
105
- emit nothing) unless the user has opted in. A reminder or validation hook that fires for users
106
- who never enabled it blocks or noises work that was never asked for. [E4]
107
-
108
- Concrete shape of an opt-in, no-op-by-default handler:
109
-
110
- ```ruby
111
- #!/usr/bin/env ruby
112
- # PostToolUse reminder. No-op unless explicitly enabled.
113
- require "json"
114
- config = ENV["CLAUDE_PROJECT_DIR"] ? File.join(ENV["CLAUDE_PROJECT_DIR"], ".myhook.yml") : nil
115
- exit 0 unless config && File.exist?(config) # opt-in gate: silent allow when not enabled
116
- payload = JSON.parse($stdin.read) rescue {}
117
- # ... emit reminder only past this point ...
118
- exit 0
119
- ```
120
-
121
- The early `exit 0` is the opt-in gate. Place the enable check before any side effect. [E4]
122
- Plastic gate hooks follow the same fail-open discipline: no bridge resolved means exit 0
123
- (allow), seen in `scripts/hook-code-gate`.
124
-
125
- ## Exit codes and output channels (E5)
126
-
127
- The exit code, not the script's intent, decides what the runtime does with the output. [E5]
128
-
129
- | Exit code | Meaning | Where output goes |
130
- | --- | --- | --- |
131
- | 0 | success | stdout shown; for UserPromptSubmit and SessionStart, stdout becomes conversation context |
132
- | 2 | blocking error | stdout and JSON ignored; stderr fed back to Claude; blocks the action on events that support blocking |
133
- | other non-zero | non-blocking error | first stderr line in transcript, full text in debug log; action proceeds |
134
-
135
- Rules that follow from the table: [E5]
136
-
137
- - To inject context (SessionStart boot banner, UserPromptSubmit augmentation), exit 0 and
138
- write the context to stdout. On those two events stdout is consumed as context, not just
139
- displayed.
140
- - To block (a gate that refuses an edit, a validator that rejects a command), exit 2 and write
141
- the reason to stderr. The agent reads stderr and can act on it. Plastic gates do exactly
142
- this: `$stderr.puts "PLASTIC GATE - <reason>"; exit 2`.
143
- - For PreToolUse, prefer the structured decision over a bare exit. Emit
144
- `hookSpecificOutput.permissionDecision` with value `allow`, `deny`, `ask`, or `defer`, plus
145
- `permissionDecisionReason`. Do not use the deprecated top-level `decision` field. [E5]
146
- - Blocking with exit 2 works only on events that support it. PreToolUse is the clear gate
147
- event; UserPromptSubmit, Stop, SubagentStop, and a few task events also support exit-2
148
- blocking. SessionStart and SessionEnd cannot block; exit 2 there does not stop anything.
149
- PreCompact runs a savepoint, not a gate (see the job table). [E5]
150
-
151
- PreToolUse JSON shape:
152
-
153
- ```json
154
- {
155
- "hookSpecificOutput": {
156
- "hookEventName": "PreToolUse",
157
- "permissionDecision": "deny",
158
- "permissionDecisionReason": "Plan not yet written; edits to project code are gated."
159
- }
160
- }
161
- ```
162
-
163
- `hookSpecificOutput` requires `hookEventName`. [E5]
164
-
165
- ## Verify the harness engaged (E6)
166
-
167
- A hook that is configured is not a hook that ran. Verify engagement before relying on a hook
168
- to hold a behavior. [E6]
169
-
170
- The known failure: in background sessions the session-id environment variable can be unset, so
171
- hooks that resolve their state through the session (Plastic gates and savepoints resolve a
172
- per-session bridge) silently no-op. The work proceeds ungated and nothing reports it. [E6]
173
- This claim is grounded mainly in Plastic's own operation rather than independent reports; treat
174
- it as Plastic-specific until confirmed elsewhere (LOW-EVIDENCE per E6).
175
-
176
- Verify by observation, not assumption: [E6]
177
-
178
- - Trigger the event and confirm the side effect (the gate blocked, the savepoint file appeared,
179
- the boot context showed). Absence of an error is not proof the hook ran.
180
- - Check the session-id environment variable is set in the context where the hook must fire;
181
- if it is unset, session-scoped hooks no-op.
182
- - For a gate, attempt the action the gate should block and confirm it is refused. A gate that
183
- never refuses in testing is a gate that is not engaged.
184
-
185
- ## Token levers: global hooks that shrink context (E7)
186
-
187
- Progressive disclosure trims what a skill loads. Two GLOBAL hooks trim what tool traffic
188
- costs at runtime, independent of any skill body. Both are token-reduction levers. Reach for
189
- them when prompts or tool output blow the context budget. [E7]
190
-
191
- - PostToolUse output preprocessing. Register a GLOBAL PostToolUse hook that trims noisy tool
192
- output before it enters context: collapse repeated lines, cut a thousand-line log to its
193
- head and tail, strip ANSI control codes, drop progress chatter. The model never sees the
194
- noise, so it never pays tokens for it. Scope the hook with a matcher over the loud tools
195
- (for example `Bash`), keep it lossless on signal (trim volume, never the line that carries
196
- the answer), and make it no-op by default per E4. This is one GLOBAL hook, not a per-skill
197
- or frontmatter hook. [E7]
198
- - Programmatic Tool Calling. When a tool runs in a loop and only the final result matters,
199
- keep the intermediate results in code and return just the answer, instead of letting every
200
- call land in context. Reach for it when a skill drives a tool in a loop and the per-call
201
- output is throwaway. Pointer only: this is a Claude Code runtime feature, not a hook you
202
- author here. [E7]
203
-
204
- The first lever trims output already produced; the second avoids producing the context at
205
- all. Pair either with sub-agent isolation (see `agents.md`) when a whole noisy sub-task can
206
- run off to the side and return only its conclusion. [E7]
207
-
208
- Both levers cut the CONTEXT axis (the input the model reads). The model's own OUTPUT tokens
209
- (what it writes) are a separate axis with no hook: cut them with terse instructions, tool
210
- responses that offer a concise mode, and sub-agent offloading that returns a short summary
211
- instead of the full trace. [E7]
212
-
213
- ## Propose-only self-improving loop (E8)
214
-
215
- A skill can learn from its own real runs without ever editing itself unattended. Reach for
216
- this shape when a skill should improve from what actually happened in its runs. [E8]
217
-
218
- Wire a GLOBAL Stop or SubagentStop hook that, once an effort threshold is met, reads the
219
- just-finished transcript, drafts proposed edits to the skill, and stops. A human reviews the
220
- proposal, approves it, and the approved change lands in git. The hook never writes the skill
221
- directly. [E8]
222
-
223
- The guardrails that make this safe: [E8]
224
-
225
- - Propose only. The hook emits a diff or a suggestion, never an applied edit. Approval is a
226
- human step, so a bad proposal costs a review, not a regression.
227
- - Effort-gated. Run the analysis only past a threshold (a long enough transcript, a real
228
- failure observed), so cheap runs spend nothing.
229
- - Git-landed. The approved edit goes through the normal commit path, so every
230
- self-improvement is reviewable and revertible.
231
- - Global, not scoped. This is one GLOBAL Stop or SubagentStop hook, not a per-skill
232
- frontmatter hook.
233
-
234
- Pointer only. The real self-improving skill is the future `improving-skills` skill; this
235
- section records the safe shape so a skill author knows the loop exists and keeps it
236
- propose-only. [E8]
237
-
238
- ## Authoring checklist
239
-
240
- - [ ] Behavior must hold deterministically; a stronger skill description was tried first (E1).
241
- - [ ] Event chosen for its inputs and blocking power; matcher scopes it; handler is a script
242
- unless another handler type is required (E2).
243
- - [ ] Script referenced through `${CLAUDE_PLUGIN_ROOT}` or `${CLAUDE_PROJECT_DIR}`, has a
244
- shebang, and is `chmod +x` (E3).
245
- - [ ] No-op by default; the opt-in check runs before any side effect; exits 0 when not enabled
246
- (E4).
247
- - [ ] Exit codes deliberate: 0 to allow or inject context, 2 to block with the reason on
248
- stderr; PreToolUse uses `hookSpecificOutput.permissionDecision`, not top-level `decision`
249
- (E5).
250
- - [ ] Engagement verified by triggering the event and observing the side effect, including the
251
- unset-session-id no-op case (E6).
@@ -1,176 +0,0 @@
1
- # Progressive Disclosure
2
-
3
- The canonical load-level model for Plastic skills, agents, and hooks. Every other
4
- reference and the SKILL.md body point here for this model and must not restate it (C7).
5
- Read it before authoring any skill body, before splitting content into `references/`,
6
- and before deciding where a file goes (scripts, references, or assets).
7
-
8
- ## Contents
9
-
10
- - [The three load levels](#the-three-load-levels)
11
- - [When to split the body into references](#when-to-split-the-body-into-references)
12
- - [Bucket selection: scripts vs references vs assets](#bucket-selection-scripts-vs-references-vs-assets)
13
- - [Reference-link discipline (C4)](#reference-link-discipline-c4)
14
- - [One level deep, with a table of contents (C5, C6)](#one-level-deep-with-a-table-of-contents-c5-c6)
15
- - [Store each fact once (C7)](#store-each-fact-once-c7)
16
- - [Cross-reference other skills by name (C8)](#cross-reference-other-skills-by-name-c8)
17
- - [Ship only what does the job (C9)](#ship-only-what-does-the-job-c9)
18
- - [The thin-router pattern (C10)](#the-thin-router-pattern-c10)
19
- - [Quarantine worked examples (C11)](#quarantine-worked-examples-c11)
20
-
21
- ## The three load levels
22
-
23
- Treat each level as a hard design target, not a guideline. The agent platform loads
24
- each level at a different moment, so a fact in the wrong level either burns context that
25
- is always present or never arrives when needed. [C1]
26
-
27
- | Level | What lives here | Budget | When it loads |
28
- |-------|-----------------|--------|---------------|
29
- | Metadata | `name` + `description` frontmatter | ~100 tokens | Always, for every skill in the catalog |
30
- | Body | `SKILL.md` after the frontmatter | under 5000 tokens / under 500 lines | On trigger (description matches the request) |
31
- | Resources | files in `references/`, `scripts/`, `assets/` | unbounded | On demand (the body points to them, or the agent runs them) |
32
-
33
- Consequences that drive every other rule in this file:
34
-
35
- 1. Metadata is paid for on every request, so the description earns its ~100 tokens by
36
- triggering correctly and nothing more. Authoring rules for the description live in
37
- `skills.md`.
38
- 2. Body tokens are paid for only when the skill fires, but then they are paid in full.
39
- Keep the body to the non-skippable rules plus routing. Push how-to down to resources.
40
- 3. Resource tokens are paid for only when the agent reaches the file. This is where
41
- depth, variants, and worked examples belong.
42
-
43
- ## When to split the body into references
44
-
45
- Split when the body approaches the budget or carries material the agent does not need on
46
- every run. Move out first, in this order: advanced cases, variant paths, long worked
47
- examples, deep domain background. Keep inline only the core workflow plus the selection
48
- guidance that tells the agent which path or reference to take. [C2]
49
-
50
- Move to `references/`:
51
-
52
- - Detailed procedures the agent needs only for one task shape.
53
- - Advanced or edge-case handling most runs never hit.
54
- - Variant flows (one file per variant) so the common path stays short.
55
- - Long examples and tables that document rather than instruct.
56
-
57
- Keep in the body:
58
-
59
- - The non-skippable rules (the ones an agent must not get wrong even if it never opens a
60
- reference).
61
- - The routing table that maps a request shape to the right reference.
62
- - Selection guidance: how to choose between the references and paths on offer.
63
-
64
- ## Bucket selection: scripts vs references vs assets
65
-
66
- Choose the bucket by how the file touches the context window, not by file type. [C3]
67
-
68
- | Bucket | Relationship to context | Use for |
69
- |--------|-------------------------|---------|
70
- | `scripts/` | Executed, not read. Output enters context, the source does not. | Deterministic logic the agent would otherwise re-derive each run: validators, generators, formatters. See `scripts.md`. |
71
- | `references/` | Read only when the body points the agent to it. | Depth, procedures, variants, examples that instruct. |
72
- | `assets/` | Copied into output, never read into context. | Templates, boilerplate, fixtures the agent emits or copies verbatim. |
73
-
74
- Decision rule: if the content is logic that runs, put it in `scripts/` and document the
75
- interface (`--help`, exit codes) rather than the implementation. If it is knowledge the
76
- agent reads to decide or act, put it in `references/`. If it is bytes the agent copies
77
- into its output without reading, put it in `assets/`.
78
-
79
- ## Reference-link discipline (C4)
80
-
81
- Bind every reference link to an observable trigger: a condition the agent can check
82
- against the request or the run state. Never ship a bare "see references/ for more". A
83
- bare pointer makes loading a judgment call, so the agent either loads everything (burning
84
- the budget the split was meant to save) or loads nothing (and acts blind). [C4]
85
-
86
- | Form | Verdict |
87
- |------|---------|
88
- | `Read references/hooks.md when authoring a lifecycle hook.` | Good. Trigger is the task shape. |
89
- | `Read references/errors.md when the API returns a non-200 status.` | Good. Trigger is observable run state. |
90
- | `See references/ for more detail.` | Bad. No trigger; loading is a guess. |
91
- | `Refer to the references as needed.` | Bad. "As needed" is not a condition. |
92
-
93
- Write the trigger as the request shape the agent can match ("when authoring an agent",
94
- "when the user names a hook event") or a run-state signal it can read ("when the test
95
- suite reports a failure", "when the frontmatter validator exits non-zero").
96
-
97
- ## One level deep, with a table of contents (C5, C6)
98
-
99
- Keep every reference exactly one level deep from `SKILL.md`: the body links to
100
- `references/x.md`, and `references/x.md` does not link onward to a further file the agent
101
- must chase. Nested references get head-previewed by the platform, so the agent acts on a
102
- partial read and misses content below the preview window. Flatten instead: if a reference
103
- grows a second level, split it into sibling files the body routes to directly. [C5]
104
-
105
- Add a table of contents to the top of any reference over 100 lines so the agent can jump
106
- to the relevant section instead of reading linearly. For very large files, put grep
107
- patterns in the body so the agent can locate a section without loading the whole file.
108
- [C6]
109
-
110
- ## Store each fact once (C7)
111
-
112
- Keep each fact in exactly one place. Do not restate a rule across the body and a
113
- reference, across two references, or across two skills. Duplicated doctrine drifts: one
114
- copy gets updated, the other goes stale, and the agent cannot tell which is current. When
115
- two files need the same fact, one owns it and the other points to the owner.
116
-
117
- This file owns the load-level model. The body and the other references point here for it
118
- and do not repeat the table or the budgets. [C7]
119
-
120
- ## Cross-reference other skills by name (C8)
121
-
122
- Name a required companion skill with a requirement marker, not a path. Use a line the
123
- agent reads as a dependency it loads on its own terms. [C8]
124
-
125
- | Form | Effect |
126
- |------|--------|
127
- | `REQUIRED BACKGROUND: superpowers:test-driven-development` | Good. Names the dependency; the agent loads it when relevant. |
128
- | `For eval depth, use plastic-skill-evaluating.` | Good. Names the skill, leaves loading to the agent. |
129
- | `@skills/skill-evaluating/SKILL.md` | Bad. `@`-path syntax force-loads the file immediately, defeating disclosure. |
130
-
131
- The `@`-path form pulls the target into context the moment the line is read, so it spends
132
- the budget the level split was built to protect. Name the skill and let the trigger
133
- decide when it loads.
134
-
135
- ## Ship only what does the job (C9)
136
-
137
- Ship the SKILL.md, the references the body routes to, the scripts it runs, and the assets
138
- it copies. Nothing else. No README, CHANGELOG, or QUICK_REFERENCE inside a skill: the
139
- description is the skill's front door, and a second front door duplicates it (C7) and adds
140
- files the agent must skip past. No orphan files (a file no link points to and no script
141
- runs). If nothing reaches a file, delete it. [C9]
142
-
143
- ## The thin-router pattern (C10)
144
-
145
- For a knowledge-heavy domain (one with many distinct request shapes, each needing
146
- different depth), make the body a thin router: a short header of non-skippable rules plus
147
- a table that maps a request shape to the one reference that handles it. The body inlines
148
- no how-to. It decides which reference to load and stops. [C10]
149
-
150
- Router body shape:
151
-
152
- ```
153
- # skill-name
154
-
155
- <non-skippable rules: the few facts an agent must not get wrong>
156
-
157
- ## Routing
158
-
159
- | When the task is... | Read |
160
- |---------------------|------|
161
- | authoring an Agent Skill | references/skills.md |
162
- | authoring a subagent | references/agents.md |
163
- | authoring a lifecycle hook | references/hooks.md |
164
- ```
165
-
166
- The router keeps the always-paid body cost flat as the domain grows: adding a new request
167
- shape adds one reference and one table row, not more body. Each reference stays focused on
168
- its one shape.
169
-
170
- ## Quarantine worked examples (C11)
171
-
172
- Keep the maxim in context, keep the example out of it. State the rule in the body or the
173
- reference; move long worked examples to a file the agent loads only when it needs to see
174
- the rule applied. An example is illustration, not instruction: it is paid for on every run
175
- if it sits in the body, but it is needed only when the rule alone is not enough. Put the
176
- short rule where it triggers, and route to the example with a trigger condition (C4). [C11]