@morning-start/dsh-code-toolkit 0.28.1 → 0.30.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,17 +1,17 @@
1
1
  # The two flows
2
2
 
3
- Most work in a repository is one of two shapes: **change code** or **change
4
- documentation**. They share the same spine — ask, investigate, propose, get
5
- approval, execute, summarize — and differ in what "done" means. Code is done when
6
- a gate proves it and a person confirms it. Documentation is done when the summary
7
- says what changed and why.
3
+ Most repository work is one of two shapes: **change code** or **change documentation**. Both share
4
+ the spine — ask, investigate, propose, get approval, execute, summarize — and differ in what "done"
5
+ means. Code is done when a gate proves it and a person confirms; documentation is done when the
6
+ summary says what changed and why.
8
7
 
9
8
  Two rules apply to both:
10
9
 
11
- - **The approval gate is real.** Do not start executing before the person has
12
- approved the plan. A plan that was never read is not an approval.
13
- - **Investigate before proposing.** A proposal that could have been written
14
- without opening the repository is a guess with formatting.
10
+ - **The approval gate is real.** Do not execute before the person approved the plan. A plan that
11
+ was never read is not an approval. Ask with `ask_user_question`, three options — approve, amend,
12
+ reject — so the answer is a decision and not a paragraph.
13
+ - **Investigate before proposing.** A proposal that could have been written without opening the
14
+ repository is a guess with formatting.
15
15
 
16
16
  ## Flow A — changing code
17
17
 
@@ -22,32 +22,34 @@ requirement → investigate → propose → human approves → execute (refining
22
22
 
23
23
  | Step | What you produce | What ends it |
24
24
  |---|---|---|
25
- | **1. Requirement** | The need in one sentence, plus what "done" would look like | You can say it back without adding anything |
25
+ | **1. Requirement** | The need in one sentence, plus what "done" looks 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** | 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 |
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 |
27
+ | **3. Propose** | The plan block — ordered outcomes, each with its gate — plus files, risks, what you will not do | The person approves, amends, or rejects |
28
+ | **4. Execute** | One plan item per iteration; tick it with its entry number, edit the plan when evidence contradicts it | The plan has no open items and the gate is green |
29
+ | **5. Test** | The gate command and its output; a guard proven red then green | The evidence is in the ledger, not your memory |
34
30
  | **6. Human confirms** | The report: what changed, what was verified, what was not | The person says it is right |
35
31
  | **7. Update the docs** | README / DETAIL / CHANGELOG / AGENTS, whichever the change made stale | The docs describe the code as it now is |
36
32
 
33
+ A rejection sends you back to **2. Investigate** with the objection in hand — not to a redraft of the
34
+ same plan. A second rejection means the requirement is wrong: say so and ask (see
35
+ `references/loop.md`).
36
+
37
+ Between the approval and execution: set the **goal** (stage 2, only when the person asked for the
38
+ work to finish without them), then turn the approved proposal into the **plan block** (stage 3) with
39
+ a check on every line.
40
+
37
41
  Rules that keep this flow honest:
38
42
 
39
- - **Investigation is read-only.** Do not edit while investigating; a plan written
40
- after half the edits is a rationalization.
41
- - **The proposal names the gate.** If you cannot name the command that will prove
42
- the change, you are not ready to propose.
43
- - **Refine in the open.** When step 4 contradicts the plan, say so in the ledger
44
- and adjust the plan — do not silently do something else.
45
- - **Testing is not "it looks right".** A command and its exit status, or it did
46
- not happen.
47
- - **Docs come last, and they are part of done.** A change whose README still
48
- describes the old behavior is not finished; it is a trap for the next person.
49
- - **Stop at the confirmation gate.** Do not push, publish or rewrite history
50
- before the person confirms.
43
+ - **Investigation is read-only.** A plan written after half the edits is a rationalization.
44
+ - **The proposal names the gate.** If you cannot name the command that proves the change, you are
45
+ not ready to propose.
46
+ - **Refine in the open.** When step 4 contradicts the plan, say so in the ledger and adjust — never
47
+ silently do something else.
48
+ - **Testing is not "it looks right".** A command and its exit status, or it did not happen.
49
+ - **Docs come last and are part of done.** A change whose README still describes the old behavior is
50
+ a trap for the next person.
51
+ - **Stop at the confirmation gate.** Do not push, publish or rewrite history before the person
52
+ confirms.
51
53
 
52
54
  ## Flow B — changing documentation
53
55
 
@@ -61,41 +63,37 @@ requirement → investigate → propose → human approves → execute (refining
61
63
  | **1. Requirement** | Which document, for whom, and what is wrong with it now | You can name the reader whose behavior should change |
62
64
  | **2. Investigate** | The current text, the code it describes, and where the two disagree | You can list the claims that are stale or missing |
63
65
  | **3. Propose** | The outline: sections to add, rewrite, delete; what stays | The person approves the outline |
64
- | **4. Execute** | Write section by section; check each claim against the code as you go | Every claim is either verified or marked as unverified |
65
- | **5. Summary** | What changed, section by section, and what you could not verify | The person can see the diff's intent without reading the diff |
66
+ | **4. Execute** | Write section by section, checking each claim against the code | Every claim is verified or marked unverified |
67
+ | **5. Summary** | What changed, section by section, and what you could not verify | The person sees the diff's intent without reading the diff |
66
68
 
67
69
  Rules that keep this flow honest:
68
70
 
69
- - **Documentation is a claim about code.** Every factual sentence should be
70
- checkable against a file or a command. If you cannot check it, mark it.
71
- - **Investigate the code, not only the doc.** The most common defect in a doc
72
- change is a confident sentence about behavior that changed last week.
73
- - **Propose an outline, not a rewrite.** "I will rewrite the README" is not a
74
- proposal; "I will replace sections 3 and 5 and delete 7" is.
75
- - **Delete before you add.** A doc that grows every time it is edited becomes
76
- unreadable. If a section is wrong, removing it is a valid change.
77
- - **The summary is not a changelog of your keystrokes.** It says what a reader
78
- will now find that they did not find before.
71
+ - **Documentation is a claim about code.** Every factual sentence is checkable against a file or a
72
+ command; if you cannot check it, mark it.
73
+ - **Investigate the code, not only the doc.** The commonest defect is a confident sentence about
74
+ behavior that changed last week.
75
+ - **Propose an outline, not a rewrite.** "I will rewrite the README" is not a proposal; "I will
76
+ replace 3 and 5 and delete 7" is.
77
+ - **Delete before you add.** A doc that grows every time it is edited becomes unreadable; removing a
78
+ wrong section is a valid change.
79
+ - **The summary is not a keystroke log.** It says what a reader now finds that they did not before.
79
80
 
80
81
  ## Choosing the flow
81
82
 
82
- - The change alters behavior → **Flow A**, even if it also touches docs.
83
- - The change alters only what people read → **Flow B**.
84
- - Both → run **A**, and treat the doc update as its last step. Do not run two
85
- flows over the same subject; the second one will contradict the first.
83
+ - Alters behavior → **Flow A**, even if it also touches docs.
84
+ - Alters only what people read → **Flow B**.
85
+ - Both → run **A** and treat the doc update as its last step. Never run two flows over one subject;
86
+ the second contradicts the first.
86
87
 
87
88
  ## Where the loop fits
88
89
 
89
- This protocol is the loop from `AGENT.md`. Steps 1–3 are iterations too: reading
90
- the code, finding the gate, and writing the plan each end with a ledger entry.
91
- The approval gate is the one place the loop stops and waits for a person — the
92
- only other stops are a real fork in the task (scope change, irreversible action,
93
- unauthorized cost).
90
+ This is the loop from `AGENT.md`. Steps 1–3 are iterations too — reading the code, finding the gate
91
+ and writing the plan each end with an entry. The approval gate is the one place the loop stops for a
92
+ person; the only other stops are a real fork (scope change, irreversible action, unauthorized cost).
94
93
 
95
- Record the flow in the ledger head, so a later reader knows which contract this
96
- run was under:
94
+ Record the flow in the ledger head, so a later reader knows which contract this run was under:
97
95
 
98
96
  ```markdown
99
97
  - Flow: A (code) | B (docs)
100
98
  - Approved: <what the person approved, and when>
101
- ```
99
+ ```
@@ -2,130 +2,151 @@
2
2
 
3
3
  ## A plan is a hypothesis
4
4
 
5
- A plan is a hypothesis about how the work divides. It is written before the code
6
- answers back. The loop is how the hypothesis gets corrected: every iteration
7
- ends with evidence, and evidence is allowed to contradict the plan. When it
8
- does, update the plan — do not protect it.
5
+ A plan is a guess about how the work divides, written before the code answers back. Every
6
+ iteration ends with evidence, and evidence may contradict the plan — then the plan changes. It is
7
+ not defended. The failure this prevents: seven batches executed faithfully while batch three
8
+ quietly changed the shape of the problem, and four through seven built on a dead assumption.
9
9
 
10
- The failure mode this prevents is the one where a plan of seven batches is
11
- executed faithfully while the third batch quietly changed the shape of the
12
- problem, and batches four through seven build on an assumption that stopped
13
- being true.
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.
10
+ The plan lives **in the ledger**, as a block you edit: a plan in the conversation is lost at the
11
+ first compaction, and a plan you only narrate cannot be diffed against what the code says.
18
12
 
19
13
  ## The plan block
20
14
 
21
15
  ```markdown
22
16
  ## 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
17
+ - [x] 1. Reproduce the failing case — gate: `node --test` names `sum([])` (entry 1)
18
+ - [ ] 2. Pin the current contract — gate: the coercion test passes today | deps: 1
19
+ - [ ] 3. Fix the empty case — gate: `sum([])` is 0, everything else still passes | deps: 2
20
+ - [ ] 4. Fix the export path — gate: one real export | deps: 2 | owner: agent-import
26
21
  ```
27
22
 
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.
23
+ Five rules make it a plan rather than a wish:
24
+
25
+ - **An outcome with its check on the same line.** No gate, no item — that is a note, and notes go
26
+ in the entry. One item needing two gates is two items.
27
+ - **`deps` and `owner` are the scheduler.** Ready means every dep is `[x]` and no one owns it.
28
+ `owner` is written when a child is dispatched, cleared when its result is recorded — that is
29
+ what stops a resumed run from dispatching the same slice twice.
30
+ - **Ordered, not bucketed.** First what unblocks the most. Defect: reproduce → guard → change →
31
+ prove the guard. Feature: the smallest end-to-end path, then widen.
32
+ - **Edited in place.** Adding items after an investigation is normal; every edit names the entry
33
+ that caused it ("split 3: parser and renderer fail separately"). A plan never edited in a long
34
+ run means the investigation is telling you nothing.
35
+ - **`[~]` is not `[-]`.** Blocked means an identified blocker and a named owner; dropped means out
36
+ of scope, with the reason. Neither is a way to make the list look finished.
37
+
38
+ Ticking is a claim: the entry beside it carries the command and its result. A tick without
39
+ evidence is the failure the ledger exists to prevent.
40
+
41
+ ## The goal and the task list
42
+
43
+ | Artifact | Lifetime | Answers |
44
+ | --- | --- | --- |
45
+ | `create_goal` / `update_goal` | this session's continuation rounds | should this keep running without the person? |
46
+ | `todo_write` | this session, display only | what is happening now, that they can see? |
47
+ | the ledger's `## Plan` | the repository | what is left, and what proves each item? |
48
+
49
+ **The goal.** Open it after the plan is approved, from the shape of the work rather than from the
50
+ person's wording: three or more items, or criteria no single iteration can prove, is a run that
51
+ needs more than one turn. A one-turn task gets no goal. The objective is the approved sentence
52
+ plus the criteria plus where the ledger is; a resumed run reads the ledger, not your memory of why
53
+ the goal exists. Updating is not symmetric — `update_goal` needs `goal_id` and `revision`, so call
54
+ `get_goal` first; a remembered `revision` conflicts.
55
+
56
+ - `complete` — no open items and every criterion holds. Not "it feels done".
57
+ - `blocked` — needs a `blocked_reason` naming the concrete condition, and is rejected until that
58
+ condition has persisted for three goal rounds. Being unsure is not blocked.
59
+ - `pause` / `resume` / `edit` need a direct request from the person. A run that pauses its own goal
60
+ has quit without saying so.
61
+
62
+ **The task list.** `todo_write` replaces the whole list, so rewrite it from the plan rather than
63
+ appending; its order is the person's window into what is next. When the two disagree the ledger
64
+ wins and the list is rewritten — never the other way round, or the run starts working toward a
65
+ plan nobody approved.
66
+
67
+ Neither tool exists in every host: a spawned child may have no goal tools, an older host may have
68
+ neither. Say so in the entry and run on the ledger alone.
69
+
70
+ ## Continuing a long run
71
+
72
+ The engine is the host's: `create_goal` keeps the session working across continuation rounds, and
73
+ the six stages are what happens inside one round.
74
+
75
+ | State | What the first iteration does |
76
+ | --- | --- |
77
+ | Same session, goal live | Read the ledger, take the first item whose deps are green |
78
+ | Session resumed, goal disarmed | `update_goal resume` — the person just asked to continue — then read the ledger |
79
+ | Unattended, nobody typing | `schedule_create` is the official mechanism; its guarantees are weaker than a loop needs, so the person owns it |
80
+
81
+ The third row is a documented limit, not a preference (installed
82
+ `docs/user/guide/schedule.md`): a delivery proves the message reached the conversation inbox, **not
83
+ that the model did the work**; exactly-once is not guaranteed; closing the Host discards a message
84
+ still waiting in an inbox; deliveries are a minute apart; a child is refused by the schedule tools.
85
+ So a run is scheduled only when the person asks, with a bounded rule and a line in the ledger
86
+ naming who created it and when it ends.
87
+
88
+ On resume the replay is short: head, plan, the last two entries, the `## Dispatch` table. An item
89
+ that still has an `owner` gets collected before anything is dispatched, or two children end up on
90
+ one path.
47
91
 
48
92
  ## Why the ledger is external
49
93
 
50
- Long tasks get compacted. After compaction you keep a summary, not the detail:
51
- which command was run, what it printed, which attempt already failed. A summary
52
- will happily lose exactly that. The ledger is the part you can re-read.
53
-
54
- Two rules follow:
55
-
56
- - Read the ledger at the start of every iteration, not once at the start.
57
- - Write the entry at the end of every iteration, even when the iteration failed —
58
- especially then.
94
+ Compaction keeps a summary, not the detail: which command ran, what it printed, which attempt
95
+ already failed. Two rules: read the ledger at the start of every iteration, and write the entry at
96
+ the end of every iteration — especially when it failed.
59
97
 
60
98
  ## Sizing a step
61
99
 
62
- A step is well sized when its outcome is one of: a claim proven, a claim
63
- refuted, or one behavior changed. If you cannot state the gate for a step before
64
- doing it, the step is too big or too vague.
65
-
66
- Split when:
67
-
68
- - two files change for unrelated reasons;
69
- - the gate would need to be run twice to know which half broke it;
70
- - you catch yourself writing "and also" in the step description.
100
+ Well sized when the outcome is a claim proven, a claim refuted, or one behavior changed — and you
101
+ can state its gate beforehand. Split when two files change for unrelated reasons, when the gate
102
+ would need two runs to say which half broke, or when you catch yourself writing "and also".
71
103
 
72
104
  ## When the gate stays red
73
105
 
74
- Three iterations on the same red gate is a signal, not a grind. In order:
106
+ Three iterations on one red gate is a signal, not a grind:
75
107
 
76
- 1. Re-read the failure output, not the summary of it.
77
- 2. Check whether the gate itself is wrong (a stale expectation, a test that
78
- locks the old behavior). If the behavior changed on purpose, update the
79
- assertion — and say so in the ledger.
80
- 3. Shrink the step until the red is reproducible in isolation.
81
- 4. If it is still red, record it as a dead end with the exact command and
82
- output, and pick a different route. A recorded dead end is progress; an
83
- unrecorded one is a future repeat.
108
+ 1. Re-read the failure output, not your summary of it.
109
+ 2. Check the gate itself — a stale expectation, a test locking the old behavior. If the behavior
110
+ changed on purpose, update the assertion and say so in the entry.
111
+ 3. Shrink the step until the red reproduces in isolation.
112
+ 4. Still red: record the dead end with the exact command and output, then take another route. A
113
+ recorded dead end is progress; an unrecorded one is a future repeat.
84
114
 
85
115
  ## When a change has more than one mirror
86
116
 
87
- Some changes must land in several places that are maintained by hand: an enum
88
- and its runtime list, a type and its validator, a command and its documentation.
89
- A change that updates one mirror looks green until the second reader runs.
90
-
91
- Before the step, list the mirrors. In the gate, include whatever reads the
92
- second mirror. If no such check exists, that is the finding: add the guard, and
93
- prove it fails when a mirror is missing.
117
+ An enum and its runtime list, a type and its validator, a command and its docs: updating one mirror
118
+ looks green until the second reader runs. List the mirrors before the step and put whatever reads
119
+ the second one in the gate. If no such check exists, that is the finding — add the guard, and prove
120
+ it fails when a mirror is missing.
94
121
 
95
122
  ## When there is nothing new to learn
96
123
 
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.
124
+ The ending is criteria-based, but the loop must also fail early. Two consecutive iterations with no
125
+ new fact is the signal: nothing learned, nothing changed, and the next step is a third attempt at
126
+ the same thing.
105
127
 
106
- When it happens:
128
+ A new fact is a command output you had not seen, a call site you had not read, a constraint the
129
+ person stated, a test that now behaves differently. Re-running the same command for the same result
130
+ is not one; nor is rewording the plan.
107
131
 
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.
132
+ 1. Write the entry: what you tried, what it proved, what is now blocked.
133
+ 2. Name the decision the person has to make. "Blocked on X" is a result; "still working on it" is
134
+ not.
112
135
  3. Stop. Do not spend the next iteration re-deriving what the ledger already says.
113
136
 
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.
137
+ A rejected plan takes the same route — back to investigation with the objection in hand. If the
138
+ second plan is rejected too, the requirement is what to question, and that is a conversation with
139
+ the person.
117
140
 
118
141
  ## Recovering after compaction
119
142
 
120
- 1. Read the ledger head: task, criteria, gate.
121
- 2. Read the last two entries: what was settled, what was open.
122
- 3. Run the gate once. The result tells you whether the last entry's claim still
123
- holds.
124
- 4. Continue from the open item, not from the beginning.
143
+ 1. Head: task, criteria, gate.
144
+ 2. The last two entries: what was settled, what is open.
145
+ 3. Run the gate once — it says whether the last entry's claim still holds.
146
+ 4. Continue from the open item, not the beginning.
125
147
 
126
148
  ## Ending
127
149
 
128
- The loop ends when the criteria hold. Then write the closing entry: gate output,
129
- criteria status, dead ends, unverified list. If a criterion cannot be checked in
130
- this environment, it stays unverified and is reported as such — a task is not
131
- "done" because the remaining work is invisible.
150
+ When the criteria hold, write the closing entry: gate output, criteria status, dead ends, unverified
151
+ list. A criterion that cannot be checked here stays unverified and is reported as such — a task is
152
+ not done because the remaining work is invisible.
@@ -23,7 +23,8 @@ worse than none.
23
23
  means it is not thought through.
24
24
 
25
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.
26
+ when it fails** — one `ask_user_question` call carrying the three, with the options you
27
+ believe are real — then give a one-page assumption set. Do not stall on questions.
27
28
 
28
29
  ## Four base maps
29
30
 
@@ -9,8 +9,11 @@ The task tells you which mode you are in.
9
9
 
10
10
  - **dry-run** — report only. Change no files; the report is the product.
11
11
  - **apply** — report **and** fix. Review first, then fix the findings you are sure of,
12
- one at a time, re-running the gate after each. A finding you cannot prove stays a
13
- finding; a fix that turns the gate red is reverted and reported as unfixed.
12
+ one at a time, re-running the gate after each.
13
+
14
+ **Every fix has a written finding behind it** — an edit with no finding is an unreviewed
15
+ change, however obvious it looks. A finding you cannot prove stays a finding; a fix that
16
+ turns the gate red is reverted and reported as unfixed.
14
17
 
15
18
  In apply mode the report still comes first: the person reads what you found before what
16
19
  you changed. Fixes go under `fixed`, everything you left alone stays under `findings`.
@@ -103,9 +103,11 @@ reads oddly for a scrub, but the renderer only shows the verdict and the finding
103
103
  **In-session** (the brief says so): write the same rows as a Markdown table instead —
104
104
  masked value, `path:line`, priority, one-line reason. Do not send both.
105
105
 
106
- **Apply** — produce the dry-run JSON first, make the redactions described in
107
- `references/redaction.md`, then return a Markdown report: what was redacted (was →
108
- now → verified by), the verification command and result, and what was not handled.
106
+ **Apply** — the plan first: the dry-run JSON and the redaction list it implies, with each
107
+ masked value. Then make them (`references/redaction.md`), and return a Markdown report:
108
+ what was redacted (was → masked → verified by), the verification command and result, and
109
+ what was not handled. While you work, `todo_write` mirrors the redaction list — one entry per
110
+ secret, `in_progress` for the one you are on — when the session has that tool.
109
111
 
110
112
  Rotating a leaked credential is not something you can do from here. Say so in every
111
113
  report that contains one: redaction fixes the working tree, not the history and not the
@@ -73,11 +73,14 @@ The task tells you which mode you are in.
73
73
 
74
74
  - **dry-run** — change no files. Produce the plan and the argument that behaviour is
75
75
  unchanged.
76
- - **apply** — establish the gate **before the first edit**: the project's tests, or a
77
- characterization baseline when there are none (`references/verification.md`). Apply
78
- one item or file group at a time, re-run the gate after each, revert that batch if it
79
- fails. If no gate can be established, **do not apply** — return the plan and say
80
- exactly what is missing.
76
+ - **apply** — **the plan comes first and in writing**: for each item, what it is now, what
77
+ it becomes, and the argument that behaviour is unchanged. Then establish the gate (the
78
+ project's tests, or a characterization baseline when there are none —
79
+ `references/verification.md`), and only then edit. Apply one item or file group at a
80
+ time, re-run the gate after each, revert that batch if it fails. If no gate can be
81
+ established, **do not apply** — return the plan and say exactly what is missing. Keep the
82
+ person's list current while you work: `todo_write` from the plan, one item `in_progress`, when
83
+ the session has that tool.
81
84
 
82
85
  ## Editing
83
86
 
@@ -103,8 +106,9 @@ Follow the structure the examples use; the fields below are the contract.
103
106
  - **Plan (dry-run)**: scope, **`Files read in full`** and `searched only` counts, a gate
104
107
  or "none available", then one entry per point — `type`, `now`, `change to`, `why
105
108
  behaviour is unchanged`, `risk`. A file you only grepped is never "read in full".
106
- - **Apply**: one entry per change — `type`, `change`, `verified by` — then the gate and
107
- its result.
109
+ - **Apply**: the plan you executed — one entry per item with `now`, `change to`, and why
110
+ behaviour is unchanged — then what was actually done (`change`, `verified by`), then the
111
+ gate and its result. A change with no plan entry above it is drift.
108
112
  - **Not handled** (both): `defect`, **`behaviour-risk`**, `too-big`, `intentional`, each
109
113
  with its file:line and why it is not this task.
110
114
 
package/index.js CHANGED
@@ -55,6 +55,13 @@ export function apply(ctx, config = {}) {
55
55
  if (config.designDirectory !== undefined && !String(config.designDirectory).trim()) {
56
56
  throw new Error(translate(fallbackLocale, 'error.designDirectory'))
57
57
  }
58
+ // 0 means "do not open a goal"; anything else is the continuation-round cap.
59
+ if (config.goalRounds !== undefined) {
60
+ const rounds = Number(config.goalRounds)
61
+ if (!Number.isInteger(rounds) || rounds < 0) {
62
+ throw new Error(translate(fallbackLocale, 'error.goalRounds'))
63
+ }
64
+ }
58
65
 
59
66
  const journal = new Journal(config.reportDirectory ?? Journal.defaultDirectory())
60
67
  const personas = {
@@ -97,13 +104,14 @@ export function apply(ctx, config = {}) {
97
104
 
98
105
  /** One ledger as a list line: what it is, how far the plan got, whether it closed. */
99
106
  const describeLedger = (ledger, t) => {
100
- const plan = ledger.plan ?? { total: 0, done: 0, blocked: 0 }
107
+ const plan = ledger.plan ?? { total: 0, done: 0, blocked: 0, inFlight: 0 }
101
108
  const progress = plan.total
102
109
  ? t('caption.planProgress').replace('{done}', String(plan.done)).replace('{total}', String(plan.total))
103
110
  : `${ledger.entries.length}${t('caption.steps')}`
111
+ const flying = plan.inFlight ? t('caption.planInFlight').replace('{count}', String(plan.inFlight)) : ''
104
112
  const blocked = plan.blocked ? t('caption.planBlocked').replace('{count}', String(plan.blocked)) : ''
105
113
  const name = ledger.title ? `${ledger.slug} — ${ledger.title}` : ledger.slug
106
- return `${name} · ${progress}${blocked}${ledger.closed ? t('caption.closed') : ''}`
114
+ return `${name} · ${progress}${flying}${blocked}${ledger.closed ? t('caption.closed') : ''}`
107
115
  }
108
116
 
109
117
  /** The ledger tail a status answer appends after an injected protocol. */
@@ -121,6 +129,16 @@ export function apply(ctx, config = {}) {
121
129
  running,
122
130
  runTimeoutMs: minutesToMs(config.runTimeoutMinutes, 30, 'error.runTimeout'),
123
131
  planMaxAgeMs: minutesToMs(config.planMaxAgeMinutes, 60, 'error.planMaxAge'),
132
+ /**
133
+ * `ctx.goals` opened rather than required. The goal *tool* refuses a call that did not
134
+ * come from a human turn (`hasDirectHumanInput`), and a plugin-delivered message carries
135
+ * this plugin's own source kind — so caption can never open a goal by asking the model to.
136
+ * The service has no such guard, and the authority here is the person's own `/code-caption`
137
+ * keystroke: the command acts for them. Declaring `goals` in `inject` would make an older
138
+ * host that lacks it refuse to load the plugin, so it is read optionally.
139
+ */
140
+ goals: typeof ctx.get === 'function' ? ctx.get('goals') : undefined,
141
+ goalRounds: config.goalRounds === undefined ? 8 : Number(config.goalRounds),
124
142
  localeNow,
125
143
  ledgerDirectory,
126
144
  designDirectory,
@@ -196,6 +214,31 @@ export function apply(ctx, config = {}) {
196
214
  descriptionKey: 'cmd.caption',
197
215
  hintKey: 'hint.caption',
198
216
  persona: personas.caption,
217
+ // The two decisions a caption run makes about itself go into a system section as well as
218
+ // the steered message: a long session compacts the message away, and losing these two
219
+ // rules looks exactly like "it never opens a goal and never splits the work".
220
+ systemNote: () => [
221
+ '## Code toolkit: caption run',
222
+ '',
223
+ 'A caption loop is installed in this session. Two decisions in it are yours, and you take',
224
+ "them from the plan rather than from the person's wording:",
225
+ '',
226
+ '- **The goal.** When the plan has three or more items, or criteria no single iteration can',
227
+ ' prove, open one with `create_goal` before the first item — the objective, the criteria,',
228
+ ' and where the ledger is.',
229
+ '- **The wave.** When two or more ready items touch disjoint paths, each with its own gate',
230
+ ' and more than a one-line edit, dispatch them together with `subagent` in one message.',
231
+ '',
232
+ 'The ledger under `docs/caption/` is authoritative: read it before each step, tick an item',
233
+ 'only with the entry that proves it, and keep `todo_write` mirroring it.',
234
+ ].join('\n'),
235
+ // The objective is the person's own task line. The command already carries the human
236
+ // authority a goal needs; the ledger path is where the plan and criteria land.
237
+ goalObjective: ({ rawInput }) => {
238
+ const task = String(rawInput ?? '').trim()
239
+ if (!task) return null
240
+ return `${task}\n\nWork through the caption loop: the plan, the criteria and every proof go in the ledger under docs/caption/.`
241
+ },
199
242
  // A project accumulates ledgers, and "continue the current task" stops
200
243
  // meaning anything once there are five of them. `list` and `resume <name>`
201
244
  // read the ledger directory before anything is injected.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@morning-start/dsh-code-toolkit",
3
- "version": "0.28.1",
3
+ "version": "0.30.1",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public",
package/src/caption.js CHANGED
@@ -25,7 +25,7 @@ const PLAN_ITEM = /^\s*-\s*\[([ xX~-])\]\s*(.+)$/
25
25
  */
26
26
  export function parsePlan(lines) {
27
27
  const start = lines.findIndex((line) => PLAN_HEADING.test(line))
28
- if (start === -1) return { total: 0, done: 0, open: 0, blocked: 0, dropped: 0, items: [] }
28
+ if (start === -1) return { total: 0, done: 0, open: 0, blocked: 0, dropped: 0, inFlight: 0, ready: 0, items: [] }
29
29
 
30
30
  const items = []
31
31
  for (let index = start + 1; index < lines.length; index += 1) {
@@ -33,19 +33,34 @@ export function parsePlan(lines) {
33
33
  const match = PLAN_ITEM.exec(lines[index])
34
34
  if (!match) continue
35
35
  const mark = match[1].toLowerCase()
36
+ const body = match[2].trim()
37
+ // `deps` and `owner` are what make the plan a graph instead of a wish list: ready
38
+ // items are derived from them, not guessed. Both are optional, so old ledgers parse.
39
+ const deps = /(?:^|\|)\s*deps\s*:\s*([\d,\s]+)/i.exec(body)
40
+ const owner = /(?:^|\|)\s*owner\s*:\s*([^|]+)/i.exec(body)
41
+ const number = /^(\d+)\./.exec(body)
36
42
  items.push({
37
43
  status: mark === 'x' ? 'done' : mark === '~' ? 'blocked' : mark === '-' ? 'dropped' : 'open',
38
- text: match[2].trim(),
44
+ number: number ? Number(number[1]) : items.length + 1,
45
+ deps: deps ? deps[1].split(',').map((part) => Number(part.trim())).filter(Number.isFinite) : [],
46
+ owner: owner ? owner[1].trim() : '',
47
+ text: body,
39
48
  })
40
49
  }
41
50
 
42
51
  const count = (status) => items.filter((item) => item.status === status).length
52
+ const done = new Set(items.filter((item) => item.status === 'done').map((item) => item.number))
53
+ const open = items.filter((item) => item.status === 'open')
43
54
  return {
44
55
  total: items.length,
45
56
  done: count('done'),
46
- open: count('open'),
57
+ open: open.length,
47
58
  blocked: count('blocked'),
48
59
  dropped: count('dropped'),
60
+ /** Open items already handed to a child — a resumed run must collect, not re-dispatch. */
61
+ inFlight: open.filter((item) => item.owner).length,
62
+ /** Open items nothing blocks: the next wave, computed rather than felt. */
63
+ ready: open.filter((item) => !item.owner && item.deps.every((dep) => done.has(dep))).length,
49
64
  items,
50
65
  }
51
66
  }