@morning-start/dsh-code-toolkit 0.28.0 → 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.
@@ -1,177 +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
- - **A green gate is not a working feature.** When the change is something a person
129
- uses — a command, a screen, a flow — one iteration must reach it the way they do:
130
- the real entry point, real data, and then look at what happened. A passing unit
131
- test says the unit is right; it does not say the capability exists. Record the
132
- click, the input, and the state afterwards the same way you record a command.
133
- - **Assume nothing about the host.** A statement about the host or a third party is
134
- a claim like any other. Read the installed version, or write the smallest probe
135
- that prints the answer. "The docs say it supports it" is a lead, not evidence; until
136
- the probe runs, the assumption goes in the unverified list and stays there.
137
- - **Stop on criteria, not on the list.** The task ends when the acceptance
138
- criteria hold, not when the to-do list is empty.
139
- - **Ask only at real forks.** Changing scope, an irreversible action, or a cost
140
- 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.
141
105
 
142
106
  ## The ledger
143
107
 
144
- Write the ledger to `docs/caption/<slug>.md`, creating the directory if needed.
145
- Keep the head of the file as the contract: the task in one sentence, the
146
- 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`.
147
119
 
148
- ```markdown
149
- ## 3. <short title>
150
- - Saw: <the state that made this the next step>
151
- - Decided: <why this step, and what it would prove>
152
- - Did: <files touched, commands run>
153
- - Evidence: `<command>` → <result, exit status>
154
- - Outcome: done | dead end | unverified
155
- ```
120
+ Shape and ordering rules: `references/loop.md`.
156
121
 
157
122
  ## When the task ends
158
123
 
159
- Report what changed, the gate output, each criterion and whether it holds, the
160
- dead ends, and the unverified list. Do not summarize the loop away — the user
161
- 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.
162
127
 
163
128
  ## Reference files
164
129
 
165
130
  | File | Read it when |
166
131
  | --- | --- |
167
- | `references/loop.md` | A step stalls, the gate stays red, or you need to split a step |
168
- | `references/flows.md` | Before the first step: is this a code change or a doc change, and what does each step owe the person |
169
- | `references/evidence.md` | Choosing a gate, proving a guard, or recording a dead end |
170
- | `references/dispatch.md` | Before handing work to another agent, or when deciding whether to parallelize |
171
- | `references/experts.md` | You are about to write an expert into a brief, and want the shape of one that works |
172
- | `examples/loop.md` | You want the shape of a healthy run before writing entries |
173
- | `examples/dispatch.md` | You are about to fan out and want the shape of a safe split |
174
- | `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 |
175
140
 
176
141
  If a reference path is unreadable, continue from this file — the core instructions are
177
- self-sufficient.
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
@@ -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.