@morning-start/dsh-code-toolkit 0.29.0 → 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.
- package/CHANGELOG.md +88 -0
- package/README.md +55 -0
- package/agents/caption/AGENT.md +49 -46
- package/agents/caption/references/dispatch.md +103 -93
- package/agents/caption/references/evidence.md +48 -64
- package/agents/caption/references/experts.md +51 -78
- package/agents/caption/references/flows.md +51 -57
- package/agents/caption/references/loop.md +106 -123
- package/agents/design/AGENT.md +2 -1
- package/agents/scrub/AGENT.md +2 -1
- package/agents/simplify/AGENT.md +3 -1
- package/index.js +45 -2
- package/package.json +1 -1
- package/src/caption.js +18 -3
- package/src/command.js +71 -1
- package/src/i18n.js +8 -0
|
@@ -2,168 +2,151 @@
|
|
|
2
2
|
|
|
3
3
|
## A plan is a hypothesis
|
|
4
4
|
|
|
5
|
-
A plan is a
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
11
|
-
|
|
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
|
-
- [
|
|
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
|
-
|
|
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:
|
|
47
24
|
|
|
48
|
-
|
|
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.
|
|
49
37
|
|
|
50
|
-
|
|
51
|
-
|
|
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
|
|
52
42
|
|
|
53
43
|
| Artifact | Lifetime | Answers |
|
|
54
44
|
| --- | --- | --- |
|
|
55
45
|
| `create_goal` / `update_goal` | this session's continuation rounds | should this keep running without the person? |
|
|
56
|
-
| `todo_write` | this session, display only | what is happening
|
|
46
|
+
| `todo_write` | this session, display only | what is happening now, that they can see? |
|
|
57
47
|
| the ledger's `## Plan` | the repository | what is left, and what proves each item? |
|
|
58
48
|
|
|
59
|
-
**The goal.**
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
your memory of why
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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.
|
|
85
91
|
|
|
86
92
|
## Why the ledger is external
|
|
87
93
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
Two rules follow:
|
|
93
|
-
|
|
94
|
-
- Read the ledger at the start of every iteration, not once at the start.
|
|
95
|
-
- Write the entry at the end of every iteration, even when the iteration failed —
|
|
96
|
-
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.
|
|
97
97
|
|
|
98
98
|
## Sizing a step
|
|
99
99
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
Split when:
|
|
105
|
-
|
|
106
|
-
- two files change for unrelated reasons;
|
|
107
|
-
- the gate would need to be run twice to know which half broke it;
|
|
108
|
-
- 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".
|
|
109
103
|
|
|
110
104
|
## When the gate stays red
|
|
111
105
|
|
|
112
|
-
Three iterations on
|
|
106
|
+
Three iterations on one red gate is a signal, not a grind:
|
|
113
107
|
|
|
114
|
-
1. Re-read the failure output, not
|
|
115
|
-
2. Check
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
output, and pick a different route. A recorded dead end is progress; an
|
|
121
|
-
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.
|
|
122
114
|
|
|
123
115
|
## When a change has more than one mirror
|
|
124
116
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
Before the step, list the mirrors. In the gate, include whatever reads the
|
|
130
|
-
second mirror. If no such check exists, that is the finding: add the guard, and
|
|
131
|
-
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.
|
|
132
121
|
|
|
133
122
|
## When there is nothing new to learn
|
|
134
123
|
|
|
135
|
-
The ending is criteria-based, but the loop also
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
What counts as "a new fact": a command's output you had not seen, a call site you
|
|
140
|
-
had not read, a constraint the person stated, a test that now behaves differently.
|
|
141
|
-
Re-running the same command and getting the same result is not a new fact. Neither is
|
|
142
|
-
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.
|
|
143
127
|
|
|
144
|
-
|
|
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.
|
|
145
131
|
|
|
146
|
-
1. Write the entry: what you tried, what it proved,
|
|
147
|
-
2. Name the decision the person has to make
|
|
148
|
-
|
|
149
|
-
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.
|
|
150
135
|
3. Stop. Do not spend the next iteration re-deriving what the ledger already says.
|
|
151
136
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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.
|
|
155
140
|
|
|
156
141
|
## Recovering after compaction
|
|
157
142
|
|
|
158
|
-
1.
|
|
159
|
-
2.
|
|
160
|
-
3. Run the gate once
|
|
161
|
-
|
|
162
|
-
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.
|
|
163
147
|
|
|
164
148
|
## Ending
|
|
165
149
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
"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.
|
package/agents/design/AGENT.md
CHANGED
|
@@ -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
|
|
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
|
|
package/agents/scrub/AGENT.md
CHANGED
|
@@ -106,7 +106,8 @@ masked value, `path:line`, priority, one-line reason. Do not send both.
|
|
|
106
106
|
**Apply** — the plan first: the dry-run JSON and the redaction list it implies, with each
|
|
107
107
|
masked value. Then make them (`references/redaction.md`), and return a Markdown report:
|
|
108
108
|
what was redacted (was → masked → verified by), the verification command and result, and
|
|
109
|
-
what was not handled.
|
|
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.
|
|
110
111
|
|
|
111
112
|
Rotating a leaked credential is not something you can do from here. Say so in every
|
|
112
113
|
report that contains one: redaction fixes the working tree, not the history and not the
|
package/agents/simplify/AGENT.md
CHANGED
|
@@ -78,7 +78,9 @@ The task tells you which mode you are in.
|
|
|
78
78
|
project's tests, or a characterization baseline when there are none —
|
|
79
79
|
`references/verification.md`), and only then edit. Apply one item or file group at a
|
|
80
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.
|
|
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.
|
|
82
84
|
|
|
83
85
|
## Editing
|
|
84
86
|
|
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
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
|
-
|
|
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:
|
|
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
|
}
|
package/src/command.js
CHANGED
|
@@ -3,6 +3,20 @@ import { failureMessage, reportMessage, userMessage, SOURCE_KIND } from './deliv
|
|
|
3
3
|
import { outputLanguage } from './i18n.js'
|
|
4
4
|
import { sessionKey } from './identity.js'
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* System-prompt section that carries an injected run's decision rules.
|
|
8
|
+
*
|
|
9
|
+
* A child agent gets its persona as a system section (see `src/runtime.js`). An injected run
|
|
10
|
+
* used to get the protocol only as a steered user message, which competes with everything else
|
|
11
|
+
* in a long session and can be summarized away by a compaction. The rules that must not drift —
|
|
12
|
+
* when to open a goal, when to split into a wave — go here; the full protocol stays in the
|
|
13
|
+
* message, where it is readable and auditable.
|
|
14
|
+
*/
|
|
15
|
+
const PROTOCOL_SECTION = 'CODE_TOOLKIT_PROTOCOL'
|
|
16
|
+
|
|
17
|
+
/** One section per agent; a second run replaces its own instead of stacking a copy. */
|
|
18
|
+
const PROTOCOL_DISPOSERS = new WeakMap()
|
|
19
|
+
|
|
6
20
|
/**
|
|
7
21
|
* The receipt names where the task went and what it will do: the current
|
|
8
22
|
* session or an isolated agent, a plan or an edit. A bare "submitted" leaves the
|
|
@@ -85,6 +99,9 @@ export class SessionCommand {
|
|
|
85
99
|
// the next load. Build it the same way every other delivery does.
|
|
86
100
|
await agent.steer(userMessage(spec.buildText({ rawInput, agent, locale, host, installed })))
|
|
87
101
|
|
|
102
|
+
const noteInstalled = this.installSystemNote(agent, { installed })
|
|
103
|
+
const goalOpened = this.armGoal(agent, { rawInput })
|
|
104
|
+
|
|
88
105
|
if (sessionId) {
|
|
89
106
|
await host.journal
|
|
90
107
|
.write(sessionId, {
|
|
@@ -95,12 +112,65 @@ export class SessionCommand {
|
|
|
95
112
|
.catch(() => undefined)
|
|
96
113
|
}
|
|
97
114
|
|
|
115
|
+
// The suffix is the only way the person can see which carrier the session actually got:
|
|
116
|
+
// a host without the service falls back to the message alone, silently otherwise.
|
|
117
|
+
const carrier = noteInstalled ? t('cmd.systemNoteOn') : ''
|
|
118
|
+
const goal = goalOpened ? t('cmd.goalOpened').replace('{rounds}', String(host.goalRounds)) : ''
|
|
98
119
|
return {
|
|
99
120
|
kind: 'success',
|
|
100
|
-
text: installed ? spec.receipt(rawInput, t, true, agent) : spec.receipt(rawInput, t, false, agent),
|
|
121
|
+
text: (installed ? spec.receipt(rawInput, t, true, agent) : spec.receipt(rawInput, t, false, agent)) + carrier + goal,
|
|
101
122
|
}
|
|
102
123
|
}
|
|
103
124
|
|
|
125
|
+
/**
|
|
126
|
+
* Open the run's goal through `ctx.goals`.
|
|
127
|
+
*
|
|
128
|
+
* The goal *tool* is unusable here: it requires a `user/message` whose `source.kind` is
|
|
129
|
+
* `user`, and this plugin's deliveries carry the plugin's own kind. The service has no such
|
|
130
|
+
* guard, and the authority is the person's command — the same authority that lets this shell
|
|
131
|
+
* register the command at all. A failure is not fatal: the ledger still carries the run.
|
|
132
|
+
*/
|
|
133
|
+
armGoal(agent, { rawInput }) {
|
|
134
|
+
const { spec, host } = this
|
|
135
|
+
if (typeof spec.goalObjective !== 'function' || !host.goalRounds) return false
|
|
136
|
+
const goals = host.goals
|
|
137
|
+
if (typeof goals?.create !== 'function') return false
|
|
138
|
+
try {
|
|
139
|
+
// One goal per session: the service throws on a second one, and an existing goal is a
|
|
140
|
+
// reason to continue it, not to replace it.
|
|
141
|
+
if (goals.get?.(agent)) return false
|
|
142
|
+
const objective = spec.goalObjective({ rawInput, agent })
|
|
143
|
+
if (!objective) return false
|
|
144
|
+
goals.create(agent, { objective, maxGoalRounds: host.goalRounds })
|
|
145
|
+
return true
|
|
146
|
+
} catch {
|
|
147
|
+
return false
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Put the run's decision rules where they cannot decay: a system section, the same carrier
|
|
153
|
+
* an isolated child gets. A host without the service, or an agent without a context, is left
|
|
154
|
+
* alone — the steered protocol is still there, just weaker.
|
|
155
|
+
*/
|
|
156
|
+
installSystemNote(agent, { installed }) {
|
|
157
|
+
const { spec } = this
|
|
158
|
+
if (typeof spec.systemNote !== 'function') return false
|
|
159
|
+
const prompts = agent?.ctx?.systemPrompt
|
|
160
|
+
if (typeof prompts?.section !== 'function') return false
|
|
161
|
+
const text = spec.systemNote({ installed })
|
|
162
|
+
if (!text) return false
|
|
163
|
+
// Replace, never stack: two copies of the same rules is a reason to disagree with itself.
|
|
164
|
+
PROTOCOL_DISPOSERS.get(agent)?.()
|
|
165
|
+
const dispose = prompts.section({
|
|
166
|
+
name: PROTOCOL_SECTION,
|
|
167
|
+
order: prompts.getSectionOrder?.(PROTOCOL_SECTION) ?? 0,
|
|
168
|
+
text,
|
|
169
|
+
})
|
|
170
|
+
PROTOCOL_DISPOSERS.set(agent, typeof dispose === 'function' ? dispose : () => {})
|
|
171
|
+
return true
|
|
172
|
+
}
|
|
173
|
+
|
|
104
174
|
/** Scope-based task: inline by default, isolated with `sub`. */
|
|
105
175
|
task(agent, rawInput, signal, locale, t) {
|
|
106
176
|
const { sub, report, rest } = splitFlags(rawInput)
|
package/src/i18n.js
CHANGED
|
@@ -31,6 +31,7 @@ const MESSAGES = {
|
|
|
31
31
|
'caption.steps': ' 步',
|
|
32
32
|
'caption.planProgress': '计划 {done}/{total}',
|
|
33
33
|
'caption.planBlocked': ' · {count} 项受阻',
|
|
34
|
+
'caption.planInFlight': ' · {count} 项在飞',
|
|
34
35
|
'caption.closed': ' · 已收口',
|
|
35
36
|
'caption.listHead': '台账目录:{dir}',
|
|
36
37
|
'caption.listHint': '用 /code-caption resume <序号|名字> 继续一份。',
|
|
@@ -54,6 +55,9 @@ const MESSAGES = {
|
|
|
54
55
|
'cmd.queuedSub': '已交给独立子 agent,范围:{scope};完成后结果会作为一条消息发回。',
|
|
55
56
|
'cmd.queuedPlan': '已请它先出方案,范围:{scope},不改任何文件;方案回来后你确认,再执行。',
|
|
56
57
|
'cmd.queuedPlanSub': '已请独立子 agent 先出方案,范围:{scope},不改任何文件;方案回来后你确认,再执行。',
|
|
58
|
+
'cmd.systemNoteOn': ' · 两条决策规则已装进系统提示(不随压缩丢失)',
|
|
59
|
+
'cmd.goalOpened': ' · 已替你在本会话开目标(最多 {rounds} 轮自动续跑,`update_goal complete` 收口)',
|
|
60
|
+
'error.goalRounds': 'goalRounds 必须是 0 或正整数(0 表示不自动开目标)。',
|
|
57
61
|
'cmd.pua': '装上「不许敷衍」的协议',
|
|
58
62
|
'hint.pua': '留空用默认风味;list 查看全部',
|
|
59
63
|
'pua.installed': '已装上 PUA 协议({flavor}):同类尝试失败两次就换方法,说完成必须给出命令和输出。',
|
|
@@ -123,6 +127,7 @@ const MESSAGES = {
|
|
|
123
127
|
'caption.steps': ' steps',
|
|
124
128
|
'caption.planProgress': 'plan {done}/{total}',
|
|
125
129
|
'caption.planBlocked': ' · {count} blocked',
|
|
130
|
+
'caption.planInFlight': ' · {count} in flight',
|
|
126
131
|
'caption.closed': ' · closed',
|
|
127
132
|
'caption.listHead': 'Ledger directory: {dir}',
|
|
128
133
|
'caption.listHint': 'Continue one with /code-caption resume <number|name>.',
|
|
@@ -146,6 +151,9 @@ const MESSAGES = {
|
|
|
146
151
|
'cmd.queuedSub': 'Handed to an isolated agent; scope: {scope}. The result arrives as a message when the run finishes.',
|
|
147
152
|
'cmd.queuedPlan': 'Asked for a plan first; scope: {scope}, no files will change. Confirm it when it arrives, then run the command again to execute.',
|
|
148
153
|
'cmd.queuedPlanSub': 'Asked the isolated agent for a plan first; scope: {scope}, no files will change. Confirm it when it arrives, then run the command again to execute.',
|
|
154
|
+
'cmd.systemNoteOn': ' · both decision rules are now a system section, so a compaction cannot drop them',
|
|
155
|
+
'cmd.goalOpened': ' · goal opened for this session (up to {rounds} continuation rounds; `update_goal complete` ends it)',
|
|
156
|
+
'error.goalRounds': 'goalRounds must be 0 or a positive integer (0 disables opening a goal).',
|
|
149
157
|
'cmd.pua': 'Install the no-shrugging protocol',
|
|
150
158
|
'hint.pua': 'Empty uses the default flavor; list shows them all',
|
|
151
159
|
'pua.installed': 'PUA protocol installed ({flavor}): two failures of the same kind mean change the method, and "done" needs a command and its output.',
|