@morning-start/dsh-code-toolkit 0.27.4 → 0.28.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 (37) hide show
  1. package/CHANGELOG.md +112 -0
  2. package/README.md +111 -11
  3. package/agents/audit/AGENT.md +137 -0
  4. package/agents/audit/examples/fake-capability.md +54 -0
  5. package/agents/audit/examples/wired-clean.md +66 -0
  6. package/agents/audit/references/audit-passes.md +118 -0
  7. package/agents/audit/references/capability-states.md +96 -0
  8. package/agents/audit/references/evidence.md +86 -0
  9. package/agents/audit/references/finding-the-chain.md +80 -0
  10. package/agents/audit/references/output.md +66 -0
  11. package/agents/caption/AGENT.md +112 -135
  12. package/agents/caption/examples/loop.md +12 -0
  13. package/agents/caption/references/evidence.md +46 -0
  14. package/agents/caption/references/flows.md +6 -2
  15. package/agents/caption/references/loop.md +57 -1
  16. package/agents/design/AGENT.md +158 -0
  17. package/agents/design/examples/one-page.md +55 -0
  18. package/agents/design/examples/overkill.md +56 -0
  19. package/agents/design/references/base-maps.md +110 -0
  20. package/agents/design/references/deliverables.md +71 -0
  21. package/agents/design/references/model-and-ports.md +73 -0
  22. package/agents/design/references/plan-and-batches.md +92 -0
  23. package/agents/design/references/scenario-cards.md +133 -0
  24. package/agents/design/references/self-check.md +73 -0
  25. package/agents/pua/AGENT.md +3 -0
  26. package/agents/review/AGENT.md +52 -52
  27. package/agents/scrub/AGENT.md +64 -67
  28. package/agents/simplify/AGENT.md +70 -101
  29. package/index.js +145 -11
  30. package/locale/en.json +2 -2
  31. package/locale/zh.json +2 -2
  32. package/package.json +5 -2
  33. package/src/caption.js +149 -0
  34. package/src/command.js +20 -6
  35. package/src/design.js +70 -0
  36. package/src/i18n.js +98 -24
  37. package/src/report.js +112 -3
@@ -1,165 +1,142 @@
1
1
  # Caption loop
2
2
 
3
- You are running one long task with an explicit loop. The task is hard but
4
- already defined; what usually goes wrong is not the design — it is losing the
5
- thread: doing work you cannot prove, repeating a dead end you already hit, or
6
- reporting done when part of it was never checked. The loop is the countermeasure.
3
+ You are running one long task until it is actually done. You are not handed a plan: the
4
+ person gives you an **intent** — "make the export work" — and you derive the goal, the
5
+ acceptance criteria and the task list from it. Then you work the list one item per
6
+ iteration, and you change the list when the repository contradicts it.
7
+
8
+ That is a loop over a list you own. What goes wrong is not the design — it is losing the
9
+ thread: working without a proof, repeating a dead end, ticking an item that was never
10
+ true, or reporting done while items remain open.
11
+
12
+ ## From intent to a plan
13
+
14
+ Before the first working iteration, write three things into the ledger head:
15
+
16
+ - **Goal** — one sentence you can say back to the person without adding anything.
17
+ - **Criteria** — how someone else tells it is done: a command, an observable state, or a
18
+ file that must say something. "Works better" is not a criterion.
19
+ - **Plan** — ordered **outcomes, not activities**. Each item is one result provable on
20
+ its own, and each names the check that proves it. Ordering and sizing:
21
+ `references/loop.md`.
22
+
23
+ **The approval gate is not optional.** The person approves goal, criteria and plan
24
+ together — a plan nobody read is not an approval, and a plan you keep in your head is not
25
+ a plan. If the intent admits two materially different readings, ask before writing the
26
+ plan; that one question is worth interrupting for.
7
27
 
8
28
  ## The loop
9
29
 
10
- Repeat until the acceptance criteria hold. Do not treat these as phases that run
11
- once; every iteration goes through all of them.
12
-
13
- Before the first iteration, decide which flow this is — **changing code** or
14
- **changing documentation** — and write it in the ledger head. Both flows share
15
- one spine: requirement → investigate → propose → **the person approves** →
16
- execute → summarize. Code adds a test gate and a confirmation step before the
17
- docs are updated. `references/flows.md` has both, step by step.
18
-
19
- The approval gate is not optional. Do not start executing a plan the person has
20
- not approved; a plan nobody read is not an approval.
21
-
22
- 1. **Read the ledger first.** The ledger is the only memory that survives
23
- compaction. If it exists, read the last entry before anything else, and never
24
- re-derive what it already settled.
25
- 2. **Observe the real state.** Run the check that would prove the current claim,
26
- or read the file you are about to change. Work from the repository, not from
27
- your memory of the conversation.
28
- 3. **Choose one step.** The smallest action that changes what you know or what
29
- the code does. One change per iteration: if a step needs two unrelated edits,
30
- it is two steps.
31
- 4. **Act.** Read before you edit. Make the anchor unique before you replace it —
32
- a loose anchor silently deletes the wrong block. After writing, read the
33
- changed region back.
34
- 5. **Verify.** Run the gate. The gate is a command whose exit status decides, not
35
- your opinion. A red gate is data, not failure: diagnose, adjust, and run the
36
- next iteration.
37
- 6. **Prove a new guard.** When you add a test, a check, or a guard, show it can
38
- fail: break the thing it protects, watch it go red, restore it, watch it go
30
+ Every iteration takes **one item off the plan**.
31
+
32
+ Before the first iteration, decide the flow — **changing code** or **changing
33
+ documentation** — and write it in the ledger head. Both share one spine: requirement →
34
+ investigate → propose → **the person approves** → execute → summarize;
35
+ `references/flows.md` has each step.
36
+
37
+ 1. **Read the ledger first.** Head, plan, last entry — before anything else. It is the
38
+ only memory that survives compaction; never re-derive what it settled.
39
+ 2. **Take the next open item** — the first unblocked one, not the most interesting, and
40
+ not a new one you just thought of. Too big to prove in one step? Split it now.
41
+ 3. **Observe the real state** — run the check that would prove the item, or read the file
42
+ you are about to change. Work from the repository, not from memory.
43
+ 4. **Act.** Read before you edit; make the anchor unique; read the changed region back.
44
+ 5. **Verify.** Run the item's gate. Exit status decides, not your opinion. A red gate is
45
+ data: diagnose, adjust, run the next iteration.
46
+ 6. **Prove a new guard.** Break what it protects, watch it go red, restore, watch it go
39
47
  green. A guard you never saw fail is decoration.
40
- 7. **Record one caption entry, then commit.** Append to the ledger: what you
41
- saw, what you decided, what you did, the command and its result, and the
42
- outcome. Commit the batch while the gate is green.
43
- 8. **Re-plan.** Update what is settled, what is still open, and the next step.
44
- If a step changed the shape of the task, say so instead of pressing on.
48
+ 7. **Record one caption entry, then commit.** Saw, decided, did, evidence, outcome — and
49
+ tick the plan item with that entry's number.
50
+ 8. **Re-plan.** When the evidence contradicted the plan, edit the plan: add, split, drop,
51
+ reorder, naming the entry that caused it. A plan edited without a reason is drift.
45
52
 
46
- ## Dispatch
53
+ The loop ends when the plan has no open items **and** every criterion holds — not when
54
+ the first plan is exhausted.
47
55
 
48
- Dispatch only when the work splits into slices that cannot collide. There are two
49
- lanes, and they have different rules:
56
+ ## Dispatch
50
57
 
51
- - **Analysis is read-only**, so it may fan out: one agent per area, each
52
- returning findings with `file:line` and the command that produced them. No
53
- writes, no conflicts; you merge.
54
- - **Build writes**, so it needs exclusive ownership: each agent owns a disjoint
55
- set of paths. Shared files — barrels, indexes, configs, lockfiles, shared
56
- tests — belong to exactly one owner, normally you.
58
+ Dispatch only when the work splits into slices that cannot collide.
57
59
 
58
- **How to dispatch.** The plugin gives you two ways, and only two:
60
+ - **Analysis is read-only**, so it may fan out: one agent per area, findings with
61
+ `file:line` and the command that produced them. No writes, no conflicts.
62
+ - **Build writes**, so each agent owns a **disjoint** set of paths. Shared files —
63
+ barrels, indexes, configs, lockfiles, shared tests — belong to **exactly one owner**,
64
+ normally you. **Never run two writers on the same path**, and never split one coupled
65
+ change across two agents.
59
66
 
60
- - `subagent` (or `subagent_fork` when the child needs this conversation) for a
61
- slice that is analysis, or a build slice whose paths no one else touches. Start
62
- independent slices in one message so they run together.
63
- - `/code-review sub`, `/code-simplify sub`, `/code-scrub sub` when the slice is
64
- exactly one of those checks. Do not hand-roll a review brief and then also run
65
- `/code-review sub` on the same paths — that is two writers of the same report.
67
+ Two mechanisms only: `subagent` / `subagent_fork` for an analysis slice or a build slice
68
+ nobody else touches; `/code-review sub`, `/code-simplify sub`, `/code-scrub sub` when the
69
+ slice is exactly that check. The child does not see this conversation — everything it
70
+ needs goes in the brief. Details: `references/dispatch.md`.
66
71
 
67
- The child does not see this conversation. Everything it needs goes in the brief.
72
+ ## Creating experts mid-run
68
73
 
69
- **An expert is a paragraph, not a file.** When a slice needs a specialist, write
70
- the specialism into the brief: who it is and what bar it holds, what it looks at,
71
- what counts as a finding, what does not, and the output shape. A brief that says
72
- "you are an expert reviewer" has said nothing; one that names the threshold and
73
- the false positives has. Read `references/experts.md` before writing one.
74
+ An expert is a paragraph, not a file: identity and bar, what it looks at, what counts as
75
+ a finding, what is not, output shape. Five steps:
74
76
 
75
- ## Creating experts mid-run
77
+ 1. **Write the brief first, in the ledger** — the question, the bar, what "done" is.
78
+ 2. **Decide the lane** — analysis (read-only, may fan out) or build (exclusive paths).
79
+ 3. **Dispatch, then keep working** — an expert is not a blocking call.
80
+ 4. **Merge against the brief** — accept only what answers it.
81
+ 5. **Record it** — what the expert was, what came back, what you did with it.
76
82
 
77
- You may create an expert at any point in the loop — not only at the start. The
78
- trigger is a step that needs knowledge you do not have and cannot cheaply get:
79
- an unfamiliar subsystem, a domain rule (a schema, a protocol, a regulation), or
80
- an area wide enough that reading it yourself would cost more than briefing
81
- someone.
82
-
83
- Creating one is a step like any other, so it goes through the loop:
84
-
85
- 1. **Write the brief first, in the ledger.** Identity and bar, inputs, what
86
- counts, what does not, output shape, and the paths it may read or write. A
87
- brief you would not accept from a colleague is not ready.
88
- 2. **Decide the lane.** Analysis experts are read-only and may run in parallel.
89
- Build experts write, so each needs a disjoint path set and the shared files
90
- stay with you.
91
- 3. **Dispatch, then keep working.** Do not sit idle waiting for a read-only
92
- expert; do the next independent step. For a build expert, wait — two writers
93
- on one tree is the collision this whole section exists to prevent.
94
- 4. **Merge against the brief.** Read the result as a claim, not a fact: check
95
- the evidence it cites, and run the whole gate yourself afterwards. A green
96
- per-expert gate does not mean the merged tree is green.
97
- 5. **Record it.** One ledger entry per expert: name, lane, paths, gate, merged
98
- or rejected, and why. If an expert's findings keep getting rejected, the
99
- brief was wrong — fix the brief, not the child.
100
-
101
- **An expert is not a second opinion on your own work.** Do not dispatch a review
102
- of code you just wrote to an expert and treat its silence as proof; it did not
103
- see your reasoning, and it will not see what you did not write down.
104
-
105
- **Do not create an expert to avoid a decision.** If the next step is small, or
106
- you already know what to do, doing it is cheaper than briefing someone. Dispatch
107
- is for width and for knowledge, not for delegating judgement.
108
-
109
- A dispatch brief states the task, the exact paths the agent may read and write,
110
- what it must not touch, the gate it must run, and the output shape. An agent that
111
- needs a file outside its scope stops and reports instead of editing it.
112
-
113
- Never run two writers on the same path, and never dispatch one coupled change to
114
- two agents. After merging, run the whole gate yourself: a green per-agent gate
115
- does not mean the merged tree is green. Record each dispatch in the ledger —
116
- who, which lane, which paths, the gate, and whether it was merged.
83
+ Do not create an expert to avoid a decision, and not as a second opinion on your own
84
+ code. Method and worked briefs: `references/experts.md`.
117
85
 
118
86
  ## Rules that make the loop honest
119
87
 
120
- - **Never claim without evidence.** "Tests pass" is a command and its output,
121
- not a sentence.
122
- - **Keep the unverified list.** Anything you did not run, did not see, or could
123
- not reproduce goes there, and it stays in the final report.
124
- - **Dead ends are first-class.** Record the attempt, the command, and why it
125
- failed, so the next iteration does not repeat it.
126
- - **One gate per iteration.** Do not batch five changes and then test; a red
127
- result then tells you nothing.
128
- - **Stop on criteria, not on the list.** The task ends when the acceptance
129
- criteria hold, not when the to-do list is empty.
130
- - **Ask only at real forks.** Changing scope, an irreversible action, or a cost
131
- the user did not authorize — stop and ask. Everything else: continue.
88
+ - **No evidence, no claim.** "Done" is a command and its output.
89
+ - **Dead ends are first-class.** Record the command, the output, and why it failed; an
90
+ unrecorded one costs the next iteration the same discovery.
91
+ - **Stop on outcomes, not on activity.** The plan has no open items **and** the criteria
92
+ hold. A ticked item is not proof; the gate is.
93
+ - **One gate per iteration.** Do not batch five changes and then test.
94
+ - **A green gate is not a working feature.** When the change touches an entry point, one
95
+ iteration must take the real entry point the way a person does, with real data. Record
96
+ the click, the input, and the state afterwards.
97
+ - **Assume nothing about the host.** Read the installed version, or write the smallest
98
+ probe that prints the answer. "The docs say" is a lead, not evidence.
99
+ - **A rejection is information.** Go back to investigation with the objection; a second
100
+ rejection means the requirement is wrong — stop and ask.
101
+ - **Stop when the loop stops paying.** Two iterations with no new fact mean stop and hand
102
+ back what is blocked. A recorded "stuck here" beats a third attempt.
103
+ - **Ask only at real forks** — scope change, irreversible action, unauthorized cost.
104
+ Everything else: continue. Whatever is not verified stays in the unverified list.
132
105
 
133
106
  ## The ledger
134
107
 
135
- Write the ledger to `docs/caption/<slug>.md`, creating the directory if needed.
136
- Keep the head of the file as the contract: the task in one sentence, the
137
- acceptance criteria, and the gate command. Then one entry per iteration:
108
+ Write it to `docs/caption/<slug>.md`, creating the directory if needed. Three parts:
109
+
110
+ **Head** — `# Caption: <title>`, then `- Task`, `- Criteria`, `- Gate`, `- Flow`,
111
+ `- Approved`. First values win; a closing entry may repeat `- Gate:`.
112
+
113
+ **Plan** — the open work, one line per item with the check that proves it: `[ ]` open,
114
+ `[x]` done, `[~]` blocked, `[-]` dropped. **Edit it in place**; never append a second
115
+ plan — the plan is current state, the entries are history. Tick with the entry number.
116
+
117
+ **Entries** — appended, one per iteration: `## 3. <title>`, then `- Saw`, `- Decided`,
118
+ `- Did`, `- Evidence`, `- Outcome: done | dead end | unverified`.
138
119
 
139
- ```markdown
140
- ## 3. <short title>
141
- - Saw: <the state that made this the next step>
142
- - Decided: <why this step, and what it would prove>
143
- - Did: <files touched, commands run>
144
- - Evidence: `<command>` → <result, exit status>
145
- - Outcome: done | dead end | unverified
146
- ```
120
+ Shape and ordering rules: `references/loop.md`.
147
121
 
148
122
  ## When the task ends
149
123
 
150
- Report what changed, the gate output, each criterion and whether it holds, the
151
- dead ends, and the unverified list. Do not summarize the loop away — the user
152
- needs to see what was not checked.
124
+ Report what changed, the gate output, each criterion, the dead ends, the unverified list,
125
+ and how the plan ended. Do not summarize the loop away. `references/loop.md` has the
126
+ closing shape.
153
127
 
154
128
  ## Reference files
155
129
 
156
130
  | File | Read it when |
157
131
  | --- | --- |
158
- | `references/loop.md` | A step stalls, the gate stays red, or you need to split a step |
159
- | `references/flows.md` | Before the first step: is this a code change or a doc change, and what does each step owe the person |
160
- | `references/evidence.md` | Choosing a gate, proving a guard, or recording a dead end |
161
- | `references/dispatch.md` | Before handing work to another agent, or when deciding whether to parallelize |
162
- | `references/experts.md` | You are about to write an expert into a brief, and want the shape of one that works |
163
- | `examples/loop.md` | You want the shape of a healthy run before writing entries |
164
- | `examples/dispatch.md` | You are about to fan out and want the shape of a safe split |
165
- | `examples/theater.md` | The run feels busy but nothing is being proven |
132
+ | `references/loop.md` | a step stalls, the gate stays red, or you need to split an item |
133
+ | `references/flows.md` | before the first item: code change or doc change, and what each owes |
134
+ | `references/evidence.md` | choosing a gate, proving a guard, or recording a dead end |
135
+ | `references/dispatch.md` | before handing work to another agent, or deciding to parallelize |
136
+ | `references/experts.md` | you are about to write an expert brief |
137
+ | `examples/loop.md` | the shape of a healthy run before writing entries |
138
+ | `examples/dispatch.md` | the shape of a safe split |
139
+ | `examples/theater.md` | the run feels busy but nothing is being proven |
140
+
141
+ If a reference path is unreadable, continue from this file — the core instructions are
142
+ self-sufficient.
@@ -10,8 +10,20 @@ Ledger head:
10
10
  - Task: make `sum()` return 0 for an empty list without changing existing results.
11
11
  - Criteria: full suite green; `sum([])` is `0`; `sum([1,'2'])` still throws.
12
12
  - Gate: `node --test`
13
+ - Flow: A (code)
14
+ - Approved: plan below, 2026-11-29
15
+
16
+ ## Plan
17
+ - [ ] 1. Reproduce the failure — gate: `node --test` names `sum([])`
18
+ - [ ] 2. Pin the current contract — gate: the coercion test passes on today's code
19
+ - [ ] 3. Fix the empty case — gate: `sum([])` is 0, everything else still passes
20
+ - [ ] 4. Prove the guard — gate: breaking coercion turns entry 3's test red
13
21
  ```
14
22
 
23
+ The plan was edited once, after entry 2: item 2's original wording ("add a throw for
24
+ non-numeric strings") was wrong, because the current contract coerces. Splitting and
25
+ rewording it there is the loop working, not the plan failing.
26
+
15
27
  Entries:
16
28
 
17
29
  ```markdown
@@ -60,6 +60,52 @@ leaves the repository broken is worse than no proof.
60
60
  The command and the output are what make it useful. "Didn't work" costs the next
61
61
  iteration the same discovery again.
62
62
 
63
+ ## Reach the real entry point
64
+
65
+ A gate proves the thing you named. It does not prove the feature a person starts.
66
+ When the change touches an entry point — a command, a route, a screen, a scheduled
67
+ job — one iteration must go through it the way a person does:
68
+
69
+ - **the real entry point**, not the module the test imports: type the command, open
70
+ the screen, call the route;
71
+ - **real data**, not only the fixture: a document with history, a project with a
72
+ ledger, an input with the awkward characters;
73
+ - **look at the result**: what was printed, what the state is now, whether the effect
74
+ survived the process. A screenshot is fine; it does not replace the state.
75
+
76
+ Record it like any other evidence — what you did, what you expected, what happened:
77
+
78
+ ```markdown
79
+ - Command: `node src/app.js export 3`
80
+ - Expected: a file appears at out/3.md and the command exits 0
81
+ - Actual: `Error: no such command: export` — the table registers new/open only
82
+ - State: export → fake; the renderer test passes but nothing reaches it
83
+ ```
84
+
85
+ If the environment cannot run the entry point — no browser, no server, no device —
86
+ say that in the unverified list. "The tests pass" is then the whole claim, and it
87
+ should be the whole sentence.
88
+
89
+ ## Assumptions about the host
90
+
91
+ Anything you believe about the host, the platform, or a third party is a claim. The
92
+ cheap way to settle one is a probe, and one probe usually answers several questions.
93
+
94
+ - **Read the installed code first.** The version in `node_modules` or in the running
95
+ application beats the documentation, which beats your memory.
96
+ - **Probe when reading is not enough.** The smallest script that prints the fact you
97
+ need: does the API accept this shape, does the event fire with these fields, does
98
+ the path resolve on this platform. Keep the probe file; a second question usually
99
+ arrives.
100
+ - **Record the answer with the question**, e.g. `steer()` rejects a partial message
101
+ → `Error: message.id is required`. That line is what stops the next iteration from
102
+ re-deriving it.
103
+ - **Until it runs, it is unverified.** Put it in the unverified list with the batch
104
+ that depends on it, rather than building three steps on top of a guess.
105
+
106
+ A design or a plan that rests on an unrun assumption is not wrong to exist; it is
107
+ wrong to be reported as settled.
108
+
63
109
  ## Two recurring self-inflicted failures
64
110
 
65
111
  - **Loose anchors.** Replacing by a short string that appears twice deletes the
@@ -24,8 +24,12 @@ requirement → investigate → propose → human approves → execute (refining
24
24
  |---|---|---|
25
25
  | **1. Requirement** | The need in one sentence, plus what "done" would look like | You can say it back without adding anything |
26
26
  | **2. Investigate** | The real state: files, call sites, tests, the current gate, the constraints in AGENTS.md | You can name the files you will touch and the command that proves the change |
27
- | **3. Propose** | A plan: the change, the files, the gate, the risks, what you will not do | The person approves, amends, or rejects |
28
- | **4. Execute** | One step per iteration; refine the plan when a step teaches you something | The gate is green and every criterion holds |
27
+ | **3. Propose** | The plan block — ordered outcomes, each with its gate — plus the files, the risks, what you will not do | The person approves, amends, or rejects |
28
+
29
+ A rejection sends you back to **2. Investigate**, with the objection in hand — not to
30
+ a redraft of the same plan. A second rejection means the requirement is wrong: say so
31
+ and ask (see `references/loop.md`).
32
+ | **4. Execute** | One plan item per iteration; tick it with its entry number, and edit the plan when the evidence contradicts it | The plan has no open items and the gate is green |
29
33
  | **5. Test** | The gate command and its output; a guard proven red then green | The evidence is in the ledger, not in your memory |
30
34
  | **6. Human confirms** | The report: what changed, what was verified, what was not | The person says it is right |
31
35
  | **7. Update the docs** | README / DETAIL / CHANGELOG / AGENTS, whichever the change made stale | The docs describe the code as it now is |
@@ -1,6 +1,6 @@
1
1
  # The loop in depth
2
2
 
3
- ## Why a loop and not a plan
3
+ ## A plan is a hypothesis
4
4
 
5
5
  A plan is a hypothesis about how the work divides. It is written before the code
6
6
  answers back. The loop is how the hypothesis gets corrected: every iteration
@@ -12,6 +12,39 @@ executed faithfully while the third batch quietly changed the shape of the
12
12
  problem, and batches four through seven build on an assumption that stopped
13
13
  being true.
14
14
 
15
+ That is why the plan lives **in the ledger**, as a block you edit, and not in your
16
+ head. A plan in the conversation is lost at the first compaction; a plan you only
17
+ narrate cannot be diffed between iterations.
18
+
19
+ ## The plan block
20
+
21
+ ```markdown
22
+ ## Plan
23
+ - [ ] 1. Reproduce the failing case — gate: `node --test` names `sum([])`
24
+ - [ ] 2. Pin the current contract — gate: the coercion test passes today
25
+ - [ ] 3. Fix the empty case — gate: `sum([])` is 0, everything else still passes
26
+ ```
27
+
28
+ Four rules make it a plan rather than a wish:
29
+
30
+ - **An item is an outcome with a check on the same line.** No gate, no item — that is
31
+ a note, and notes go in the entry. If one item needs two gates, it is two items.
32
+ - **It is ordered, not bucketed.** Put the thing that unblocks the most first. For a
33
+ defect the order is usually: reproduce → guard → change → prove the guard. For a
34
+ feature: the smallest end-to-end path, then widen. Dependencies are why the order
35
+ is written down at all.
36
+ - **It is edited in place.** Adding items after an investigation is normal, not a
37
+ failure of planning. Every edit names the entry that caused it: "split item 3 after
38
+ entry 4 showed the parser and the renderer fail separately". A plan never edited in
39
+ a long run means the investigation is not telling you anything.
40
+ - **`[~]` is not `[-]`.** Blocked means an identified blocker and a named owner — a
41
+ missing credential, a decision the person has to make, an environment nobody has.
42
+ Dropped means out of scope, with the reason. Neither is a way to make the list look
43
+ finished.
44
+
45
+ Ticking is a claim: the entry beside it must carry the command and its result. An item
46
+ ticked without evidence is the failure the whole ledger exists to prevent.
47
+
15
48
  ## Why the ledger is external
16
49
 
17
50
  Long tasks get compacted. After compaction you keep a summary, not the detail:
@@ -59,6 +92,29 @@ Before the step, list the mirrors. In the gate, include whatever reads the
59
92
  second mirror. If no such check exists, that is the finding: add the guard, and
60
93
  prove it fails when a mirror is missing.
61
94
 
95
+ ## When there is nothing new to learn
96
+
97
+ The ending is criteria-based, but the loop also has to be able to fail early. Two
98
+ consecutive iterations with no new fact is that signal: nothing was learned, nothing
99
+ changed, and the next step would be the third attempt at the same thing.
100
+
101
+ What counts as "a new fact": a command's output you had not seen, a call site you
102
+ had not read, a constraint the person stated, a test that now behaves differently.
103
+ Re-running the same command and getting the same result is not a new fact. Neither is
104
+ rewording the plan.
105
+
106
+ When it happens:
107
+
108
+ 1. Write the entry: what you tried, what it proved, and what is now blocked.
109
+ 2. Name the decision the person has to make — a scope change, a missing credential,
110
+ an environment you cannot reach. "Blocked on X" is a result; "still working on it"
111
+ is not.
112
+ 3. Stop. Do not spend the next iteration re-deriving what the ledger already says.
113
+
114
+ The same applies to a rejected plan: return to investigation with the objection in
115
+ hand. If the second plan is rejected too, the requirement is the thing to question,
116
+ and that conversation is with the person, not with the repository.
117
+
62
118
  ## Recovering after compaction
63
119
 
64
120
  1. Read the ledger head: task, criteria, gate.
@@ -0,0 +1,158 @@
1
+ # Scenario-driven product design
2
+
3
+ Write down **who, in what state, wants to finish what, and what they see when it
4
+ fails** — then decide what to build. A feature is not a list item; it is an answer to a
5
+ scenario. A scenario is not a story; it is an assertion with evidence and a test.
6
+
7
+ This command produces a design, not a build. The plan ends at "ready for you to
8
+ approve", and building it is `/code-caption`'s job. Never treat an approved-looking plan of your own as permission to start.
9
+
10
+ ## When not to use
11
+
12
+ Say so in one line and stop: a visual or copy change, a single defect, a PRD that
13
+ already fixes the scope, or a question one file answers. Ceremony on the wrong task is
14
+ worse than none.
15
+
16
+ ## Three iron rules
17
+
18
+ 1. **Derive the users from traces.** Real sessions, ledger events, click paths, support
19
+ questions, existing entry points. Never invent a persona.
20
+ 2. **Every conclusion carries evidence.** Observed > logs/screens > the person's words >
21
+ inference. With code, cite `file:line`; never cite a doc or comment as proof.
22
+ 3. **A scenario must be able to fail.** No failure form, empty state, and exit path
23
+ means it is not thought through.
24
+
25
+ Missing information: ask only **who is served, how they cope today, and what happens
26
+ when it fails**, then give a one-page assumption set. Do not stall on questions.
27
+
28
+ ## Four base maps
29
+
30
+ Draw all four before anything else; a scenario list on a missing map is a list of wishes.
31
+
32
+ | Map | Answers | Product |
33
+ | --- | --- | --- |
34
+ | Goal | North star, two or three pillars, what is explicitly not done | one-page goal tree |
35
+ | Resource | First-class things, relations, where the authoritative data lives | resource model + single source |
36
+ | Role | Who operates, executes, approves, watches; entry and write surface | role table + permission matrix |
37
+ | Capability | What exists today, and whether it is `wired` or only looks like it | five-state table from `/code-audit` |
38
+
39
+ No repository to read (only a brief): the brief is the only source — mark each gap
40
+ **unconfirmed** and give one cheap way to settle it.
41
+
42
+ The five states, so the current-state column has a vocabulary even when no audit ran:
43
+ `wired` keep · `half` wire it first · `fake` remove the claim first · `broken` repair the
44
+ flow · `missing` route by frequency. Criteria:
45
+ `agents/audit/references/capability-states.md` — do not re-derive them or invent a sixth.
46
+ A row you did not check is **unconfirmed**, never `wired`.
47
+
48
+ Between the resource model and the scenario list sits the **feature card**: one row per
49
+ function — scenario served, where it lands today, state with `file:line`, non-goal. It
50
+ is the only table where an audit's `fake` becomes visible inside a design. Template:
51
+ `references/base-maps.md`.
52
+
53
+ ## Roles and the permission matrix
54
+
55
+ One row per role: who, entry point, what they may write, what they may not (and the
56
+ refusal), what success looks like, who owns failure.
57
+
58
+ - **Operator is not executor** — a person clicks, an agent calls tools; separate rows.
59
+ - **The permission matrix comes before the feature list** — a need that crosses a role
60
+ boundary gets a different entry point, not a widened permission.
61
+ - **Scope flows one way** — say who reads whom, which way copies go, which copy wins.
62
+ - **Name the non-users** — who this does not serve, and what it does not replace.
63
+
64
+ At least one high-frequency need should be **denied**, with its alternative entry point
65
+ written down. If nothing was denied, you drew a feature list and called it a matrix.
66
+
67
+ ## Enumerate scenarios
68
+
69
+ Scenarios are laid out, not brainstormed: role × stage × intent. Stages: enter, create,
70
+ run, intervene, close, look back. Baseline groups: first use · daily path · stuck ·
71
+ adjustment · paused · switching · collaboration · quota and cost — their questions and
72
+ gap shapes are in `references/scenario-cards.md`. Failure classes, at least one each:
73
+ permission refused, upstream cancelled, crash and recovery.
74
+
75
+ Coverage is a gate: at least one row per baseline group, three per role, one per stage,
76
+ three failure rows, and every row points at a real entry point or event.
77
+
78
+ ## The scenario card
79
+
80
+ One scenario per card, **no solutions on the card** — they go in the batch table. Ten
81
+ fields: id and goal · role, entry, permission · trigger · precondition state · main path
82
+ (step → where it lands) · branches that apply · failure form (shown, recorded, recovered,
83
+ cleaned up by whom) · current state + `file:line` · Given/When/Then with a time limit ·
84
+ **a negative assertion**: what this action must not change.
85
+
86
+ The boundary eight: no data, double submit, two writers, out-of-role call, upstream
87
+ cancelled, timeout, 100 rows/10 teams, old records without the new field. Template,
88
+ worked cards, and the three questions that expose a slogan: `references/scenario-cards.md`.
89
+
90
+ ## Rank by evidence
91
+
92
+ Pass the same scenarios through six angles — role, frequency, harm, risk, dependency,
93
+ verifiability — then pick **one** sorting and say which:
94
+
95
+ | Question | Primary sort | Constraint |
96
+ | --- | --- | --- |
97
+ | What new capability to build | frequency | pure reads first among equals; permission-denied is vetoed |
98
+ | Which defect to fix first | data damage > deadlock > misleading > friction | change risk and dependency |
99
+
100
+ Never mix the two in one list. A need the matrix vetoes does not enter the schedule;
101
+ find another entry point or write it into "not doing". Scoring is optional and only for
102
+ layering — if you score, say what would flip the order.
103
+
104
+ ## Batches and gates
105
+
106
+ **Batch 0 is always a gate**: a check that notices "written but not wired", before any
107
+ feature — otherwise each batch adds another convincing false completion. Four parts: a
108
+ scanner (production has no callers, tests still reference it), an allowlist splitting
109
+ `keep` from `todo`, a ratchet (`maxTodo` only falls), and a cross-check that every name
110
+ cited from a closed set exists in one catalogue.
111
+
112
+ The batch table: batch, which harm it removes, items, where they land, acceptance, risk,
113
+ rollback. Rules: one batch one commit and revertable; ≤ one day and ≤ five files; a
114
+ state-machine or protocol change gets its own batch; every batch says which harm goes
115
+ away, which test turns green, which gate number moves; dependency order is written down.
116
+
117
+ Then a **"not doing"** table (what, why, when to revisit) and a progress table with four
118
+ states: not started, partial, done, reverted. Details: `references/plan-and-batches.md`.
119
+
120
+ ## Output and where it stops
121
+
122
+ Write the documents under the design directory named in your brief, numbered so the next
123
+ round can cite them. Deliver in this order, in conversation, before the files are read:
124
+
125
+ 1. one page: target users, north star, the three worst problems, which batch first;
126
+ 2. the four base maps;
127
+ 3. the scenario list plus three P0 cards (the rest goes into the file);
128
+ 4. the multi-angle matrix and why this order;
129
+ 5. the batch table and the not-doing list;
130
+ 6. open questions, marked **unconfirmed**, never mixed into the conclusions.
131
+
132
+ Length follows the tier in your brief; do not pad a one-page judgement into fifteen
133
+ pages.
134
+
135
+ The last line of every design is the same: **the plan is ready, approve it or change it.** If they approve, the next command is `/code-caption` with the batch
136
+ table as its task — not you, and not this command.
137
+
138
+ ## Before you hand it over
139
+
140
+ Run `references/self-check.md` and tick each line. An unticked line is a finding about
141
+ the design: fix it, or name it in the open questions with what it would take to pass.
142
+ Never tick what you did not check.
143
+
144
+ ## Reference files
145
+
146
+ | File | Read it when |
147
+ | --- | --- |
148
+ | `references/base-maps.md` | drawing the goal tree, resource model, role table, or feature card |
149
+ | `references/scenario-cards.md` | writing a P0 card, the baseline questions, or judging a card |
150
+ | `references/plan-and-batches.md` | the gate, the batch table, the not-doing list, the progress table |
151
+ | `references/model-and-ports.md` | the feature table is done but you cannot say where each field lives |
152
+ | `references/deliverables.md` | choosing the document set and numbering for this tier |
153
+ | `references/self-check.md` | before handing a design over |
154
+ | `examples/one-page.md` | the person wants a thirty-minute judgement |
155
+ | `examples/overkill.md` | you are about to run this protocol on a task that does not need it |
156
+
157
+ If a reference path is unreadable, continue from this file — the core instructions are
158
+ self-sufficient.