dsh-coding 0.1.1-rc1 → 0.1.1-rc2
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/AGENTS.md +80 -0
- package/LICENSE +21 -21
- package/README.md +96 -37
- package/cordis.patch.yml +51 -8
- package/docs/CHANGELOG.md +47 -0
- package/docs/DETAIL.md +143 -54
- package/icon.svg +6 -6
- package/lib/client/card.js +92 -4
- package/lib/client/locales.js +14 -0
- package/lib/client/styles.js +240 -240
- package/lib/client.js +114 -3
- package/lib/config.js +14 -0
- package/lib/contract.js +20 -6
- package/lib/handoff.js +37 -2
- package/lib/index.js +3 -2
- package/lib/memory.js +336 -0
- package/lib/preset.js +75 -11
- package/lib/stages.js +45 -7
- package/lib/state.js +40 -5
- package/lib/types/client/card.d.ts +5 -1
- package/lib/types/client/locales.d.ts +1 -1
- package/lib/types/config.d.ts +15 -0
- package/lib/types/handoff.d.ts +20 -0
- package/lib/types/index.d.ts +8 -2
- package/lib/types/memory.d.ts +71 -0
- package/lib/types/stages.d.ts +29 -0
- package/lib/types/state.d.ts +14 -2
- package/locale/en.json +2 -2
- package/locale/zh.json +2 -2
- package/package.json +3 -2
- package/docs/DEVELOPMENT.md +0 -189
package/lib/client.js
CHANGED
|
@@ -73,15 +73,18 @@ function asHandoff(value) {
|
|
|
73
73
|
const raw = value;
|
|
74
74
|
if (raw["version"] !== HANDOFF_VERSION) return void 0;
|
|
75
75
|
const goal = boundedText(raw["goal"], HANDOFF_TEXT_LIMIT);
|
|
76
|
+
const delivered = boundedText(raw["delivered"], HANDOFF_TEXT_LIMIT);
|
|
76
77
|
const updatedAt = raw["updatedAt"];
|
|
77
78
|
return {
|
|
78
79
|
version: HANDOFF_VERSION,
|
|
79
80
|
...goal === "" ? {} : { goal },
|
|
81
|
+
...delivered === "" ? {} : { delivered },
|
|
80
82
|
constraints: mergeItems([], listOf(raw["constraints"])),
|
|
81
83
|
acceptance: mergeItems([], listOf(raw["acceptance"])),
|
|
82
84
|
findings: mergeItems([], listOf(raw["findings"])),
|
|
83
85
|
decisions: mergeItems([], listOf(raw["decisions"])),
|
|
84
86
|
open: mergeItems([], listOf(raw["open"])),
|
|
87
|
+
followUps: mergeItems([], listOf(raw["followUps"])),
|
|
85
88
|
tasks: boundedTasks(listOf(raw["tasks"])),
|
|
86
89
|
changes: mergeChanges([], listOf(raw["changes"])),
|
|
87
90
|
updatedAt: typeof updatedAt === "number" && Number.isFinite(updatedAt) ? updatedAt : Date.now()
|
|
@@ -170,6 +173,8 @@ var IMPLEMENT_TABLE = [
|
|
|
170
173
|
TOOL.implement,
|
|
171
174
|
TOOL.handoff,
|
|
172
175
|
"todo_write",
|
|
176
|
+
"bash",
|
|
177
|
+
"pwsh",
|
|
173
178
|
TOOL.stage,
|
|
174
179
|
TOOL.mode,
|
|
175
180
|
TOOL.reasoning
|
|
@@ -201,6 +206,9 @@ function asCheckpoint(value) {
|
|
|
201
206
|
const blockedValue = v["verifyBlocked"];
|
|
202
207
|
const verifyBlocked = asVerifyBlocked(blockedValue);
|
|
203
208
|
if (blockedValue !== void 0 && verifyBlocked === void 0) return void 0;
|
|
209
|
+
const plannerValue = v["planner"];
|
|
210
|
+
const planner = asPlanner(plannerValue);
|
|
211
|
+
if (plannerValue !== void 0 && planner === void 0) return void 0;
|
|
204
212
|
return {
|
|
205
213
|
v: CHECKPOINT_VERSION,
|
|
206
214
|
runId: v["runId"],
|
|
@@ -218,6 +226,7 @@ function asCheckpoint(value) {
|
|
|
218
226
|
...verifyAttempts === void 0 ? {} : { verifyAttempts },
|
|
219
227
|
...verifyBlocked === void 0 ? {} : { verifyBlocked },
|
|
220
228
|
...worker === void 0 ? {} : { worker },
|
|
229
|
+
...planner === void 0 ? {} : { planner },
|
|
221
230
|
...refusal === void 0 ? {} : { refusal },
|
|
222
231
|
...failure === void 0 ? {} : { failure },
|
|
223
232
|
updatedAt: v["updatedAt"]
|
|
@@ -274,6 +283,14 @@ function asWorker(value) {
|
|
|
274
283
|
...isFiniteNumber(v["finishedAt"]) ? { finishedAt: v["finishedAt"] } : {}
|
|
275
284
|
};
|
|
276
285
|
}
|
|
286
|
+
function asPlanner(value) {
|
|
287
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
288
|
+
const v = value;
|
|
289
|
+
if (typeof v["route"] !== "string" || v["route"] === "") return void 0;
|
|
290
|
+
if (v["outcome"] !== "completed" && v["outcome"] !== "failed") return void 0;
|
|
291
|
+
if (!isFiniteNumber(v["at"])) return void 0;
|
|
292
|
+
return { route: v["route"], outcome: v["outcome"], at: v["at"] };
|
|
293
|
+
}
|
|
277
294
|
function asRefusal(value) {
|
|
278
295
|
if (typeof value !== "object" || value === null) return void 0;
|
|
279
296
|
const v = value;
|
|
@@ -585,11 +602,23 @@ function cardState(view, turn) {
|
|
|
585
602
|
const stage = live ? view.stage : frozen?.stage ?? view.stage;
|
|
586
603
|
const verification = (live ? view.verification : frozen?.verification ?? view.verification) ?? null;
|
|
587
604
|
const numbers = live || frozen === void 0 ? { planItems: view.planItems, openPlanItems: view.openPlanItems, edits: view.edits } : { planItems: frozen.planItems, openPlanItems: frozen.openPlanItems, edits: frozen.edits };
|
|
588
|
-
|
|
605
|
+
const canMemory = live && mode === "codex" && stage === "deliver" && verification?.passed === true;
|
|
606
|
+
return {
|
|
607
|
+
live,
|
|
608
|
+
mode,
|
|
609
|
+
stage,
|
|
610
|
+
verification,
|
|
611
|
+
allowed: STAGES_BY_MODE[mode] ?? STAGES_BY_MODE.codex,
|
|
612
|
+
...numbers,
|
|
613
|
+
canMemory
|
|
614
|
+
};
|
|
589
615
|
}
|
|
590
616
|
function commandFor(mode) {
|
|
591
617
|
return `/coding set ${mode}`;
|
|
592
618
|
}
|
|
619
|
+
function memoryCommand() {
|
|
620
|
+
return "/coding memory";
|
|
621
|
+
}
|
|
593
622
|
function turnOf(value) {
|
|
594
623
|
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
595
624
|
const turn = value?.turn;
|
|
@@ -646,9 +675,11 @@ var CodingTurnCard = (0, import_react3.memo)(function CodingTurnCard2(props) {
|
|
|
646
675
|
const view = raw === null || typeof raw !== "object" ? void 0 : raw;
|
|
647
676
|
const [busy, setBusy] = (0, import_react3.useState)(null);
|
|
648
677
|
const [error, setError] = (0, import_react3.useState)(null);
|
|
678
|
+
const [memory, setMemory] = (0, import_react3.useState)("idle");
|
|
679
|
+
const [memoryError, setMemoryError] = (0, import_react3.useState)(null);
|
|
649
680
|
if (view === void 0 || view.active !== true) return null;
|
|
650
681
|
const turn = turnOf(props.turn);
|
|
651
|
-
const { live, mode, stage, verification, allowed, ...numbers } = cardState(view, turn);
|
|
682
|
+
const { live, mode, stage, verification, allowed, canMemory, ...numbers } = cardState(view, turn);
|
|
652
683
|
const reasoningState = reasoningRaw === null || typeof reasoningRaw !== "object" ? void 0 : reasoningRaw;
|
|
653
684
|
const reasoning = reasoningDisplay(reasoningState, turn, props.settings?.());
|
|
654
685
|
const stageIndex = allowed.indexOf(stage);
|
|
@@ -657,6 +688,7 @@ var CodingTurnCard = (0, import_react3.memo)(function CodingTurnCard2(props) {
|
|
|
657
688
|
const openPlanItems = number(numbers.openPlanItems);
|
|
658
689
|
const state = verificationText(verification, t);
|
|
659
690
|
const enabled = live && busy === null;
|
|
691
|
+
const failure = error ?? memoryError;
|
|
660
692
|
async function choose(next) {
|
|
661
693
|
if (next === mode || busy !== null || !live) return;
|
|
662
694
|
setBusy(next);
|
|
@@ -670,6 +702,70 @@ var CodingTurnCard = (0, import_react3.memo)(function CodingTurnCard2(props) {
|
|
|
670
702
|
setBusy(null);
|
|
671
703
|
}
|
|
672
704
|
}
|
|
705
|
+
async function writeMemory() {
|
|
706
|
+
if (memory === "busy") return;
|
|
707
|
+
setMemory("busy");
|
|
708
|
+
setMemoryError(null);
|
|
709
|
+
try {
|
|
710
|
+
const result = await props.execute?.(memoryCommand());
|
|
711
|
+
if (result === void 0 || commandRejected(result)) {
|
|
712
|
+
setMemory("idle");
|
|
713
|
+
setMemoryError(t("card.memoryFailed"));
|
|
714
|
+
} else {
|
|
715
|
+
setMemory("done");
|
|
716
|
+
}
|
|
717
|
+
} catch {
|
|
718
|
+
setMemory("idle");
|
|
719
|
+
setMemoryError(t("card.memoryFailed"));
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
function memoryRow() {
|
|
723
|
+
if (!canMemory) return null;
|
|
724
|
+
let content;
|
|
725
|
+
if (memory === "idle") {
|
|
726
|
+
content = [(0, import_react3.createElement)("button", {
|
|
727
|
+
key: "memory-idle",
|
|
728
|
+
type: "button",
|
|
729
|
+
className: "dsh-coding-button",
|
|
730
|
+
onClick: () => setMemory("confirm")
|
|
731
|
+
}, t("card.memory"))];
|
|
732
|
+
} else if (memory === "confirm") {
|
|
733
|
+
content = [
|
|
734
|
+
(0, import_react3.createElement)("span", { key: "memory-hint", className: "dsh-coding-hint" }, t("card.memoryHint")),
|
|
735
|
+
(0, import_react3.createElement)("button", {
|
|
736
|
+
key: "memory-confirm",
|
|
737
|
+
type: "button",
|
|
738
|
+
className: "dsh-coding-button",
|
|
739
|
+
onClick: () => {
|
|
740
|
+
void writeMemory();
|
|
741
|
+
}
|
|
742
|
+
}, t("card.memoryConfirm")),
|
|
743
|
+
(0, import_react3.createElement)("button", {
|
|
744
|
+
key: "memory-cancel",
|
|
745
|
+
type: "button",
|
|
746
|
+
className: "dsh-coding-button",
|
|
747
|
+
onClick: () => {
|
|
748
|
+
setMemory("idle");
|
|
749
|
+
setMemoryError(null);
|
|
750
|
+
}
|
|
751
|
+
}, t("card.memoryCancel"))
|
|
752
|
+
];
|
|
753
|
+
} else if (memory === "busy") {
|
|
754
|
+
content = [(0, import_react3.createElement)("button", {
|
|
755
|
+
key: "memory-busy",
|
|
756
|
+
type: "button",
|
|
757
|
+
className: "dsh-coding-button",
|
|
758
|
+
disabled: true
|
|
759
|
+
}, t("card.memoryBusy"))];
|
|
760
|
+
} else {
|
|
761
|
+
content = [(0, import_react3.createElement)("span", { key: "memory-done", className: "dsh-coding-success" }, t("card.memoryDone"))];
|
|
762
|
+
}
|
|
763
|
+
return (0, import_react3.createElement)(
|
|
764
|
+
"div",
|
|
765
|
+
{ className: "dsh-coding-row", "data-dsh-coding-memory": "true" },
|
|
766
|
+
...content
|
|
767
|
+
);
|
|
768
|
+
}
|
|
673
769
|
return (0, import_react3.createElement)(
|
|
674
770
|
"div",
|
|
675
771
|
{
|
|
@@ -749,7 +845,8 @@ var CodingTurnCard = (0, import_react3.memo)(function CodingTurnCard2(props) {
|
|
|
749
845
|
(0, import_react3.createElement)("span", { className: "dsh-coding-value" }, t("files").replace("{count}", String(number(numbers.edits)))),
|
|
750
846
|
view.pending === null ? null : (0, import_react3.createElement)("span", { className: "dsh-coding-value" }, t("pending").replace("{tool}", view.pending.tool))
|
|
751
847
|
),
|
|
752
|
-
|
|
848
|
+
memoryRow(),
|
|
849
|
+
failure === null ? null : (0, import_react3.createElement)("p", { className: "dsh-coding-error" }, failure)
|
|
753
850
|
);
|
|
754
851
|
});
|
|
755
852
|
|
|
@@ -1496,6 +1593,13 @@ var en = {
|
|
|
1496
1593
|
"card.verify": "Verification",
|
|
1497
1594
|
"card.stageHint": "Edit with /coding stage <stage>",
|
|
1498
1595
|
"card.switchFailed": "The mode was not changed. Try /coding <mode>.",
|
|
1596
|
+
"card.memory": "End task & write handoff",
|
|
1597
|
+
"card.memoryHint": "Writes one Markdown handoff document under .agents/memory in the project root.",
|
|
1598
|
+
"card.memoryConfirm": "Generate",
|
|
1599
|
+
"card.memoryCancel": "Cancel",
|
|
1600
|
+
"card.memoryBusy": "Writing\u2026",
|
|
1601
|
+
"card.memoryDone": "Handoff document written",
|
|
1602
|
+
"card.memoryFailed": "Could not write the handoff document. Retry or run /coding memory.",
|
|
1499
1603
|
"card.stale": "history",
|
|
1500
1604
|
"card.reasoning": "Reasoning",
|
|
1501
1605
|
"reasoning.pending": "pending",
|
|
@@ -1570,6 +1674,13 @@ var zh = {
|
|
|
1570
1674
|
"card.verify": "\u9A8C\u8BC1",
|
|
1571
1675
|
"card.stageHint": "\u7528 /coding stage <\u9636\u6BB5> \u8C03\u6574",
|
|
1572
1676
|
"card.switchFailed": "\u6A21\u5F0F\u672A\u5207\u6362\u6210\u529F\uFF0C\u8BF7\u91CD\u8BD5\u6216\u76F4\u63A5\u6267\u884C /coding <\u6A21\u5F0F>\u3002",
|
|
1677
|
+
"card.memory": "\u7ED3\u675F\u4EFB\u52A1\u5E76\u751F\u6210\u4EA4\u63A5\u6587\u6863",
|
|
1678
|
+
"card.memoryHint": "\u5C06\u5728\u9879\u76EE\u6839 .agents/memory \u4E0B\u5199\u4E00\u7BC7\u672C\u8F6E\u4EA4\u63A5\u6587\u6863\u3002",
|
|
1679
|
+
"card.memoryConfirm": "\u786E\u8BA4\u751F\u6210",
|
|
1680
|
+
"card.memoryCancel": "\u53D6\u6D88",
|
|
1681
|
+
"card.memoryBusy": "\u6B63\u5728\u5199\u5165\u2026",
|
|
1682
|
+
"card.memoryDone": "\u5DF2\u751F\u6210\u4EA4\u63A5\u6587\u6863",
|
|
1683
|
+
"card.memoryFailed": "\u672A\u80FD\u751F\u6210\u4EA4\u63A5\u6587\u6863\uFF0C\u8BF7\u91CD\u8BD5\u6216\u6267\u884C /coding memory\u3002",
|
|
1573
1684
|
"card.stale": "\u5386\u53F2",
|
|
1574
1685
|
"card.reasoning": "\u63A8\u7406",
|
|
1575
1686
|
"reasoning.pending": "\u5F85\u786E\u5B9A",
|
package/lib/config.js
CHANGED
|
@@ -18,6 +18,8 @@ import { volatileValue } from './volatile.js';
|
|
|
18
18
|
export { volatileValue };
|
|
19
19
|
/** Reasoning-level policies the plugin accepts. */
|
|
20
20
|
export const REASONING_MODES = ['auto', 'low', 'high', 'max'];
|
|
21
|
+
/** planner 门禁策略:`complex` 对复杂 codex 任务强制 planner,`off` 关闭该门禁。 */
|
|
22
|
+
export const PLANNER_GATE_MODES = ['complex', 'off'];
|
|
21
23
|
/** Schemastery schema the Loader validates the bundle row's `config` with. */
|
|
22
24
|
export const Config = z.object({
|
|
23
25
|
// Volatile: the plugin manager page edits these in place, and the runtime
|
|
@@ -26,6 +28,8 @@ export const Config = z.object({
|
|
|
26
28
|
implementWorkerModel: z.string().required().volatile(),
|
|
27
29
|
verifyWorkerModel: z.string().required().volatile(),
|
|
28
30
|
plannerWorkerModel: z.string().required().volatile(),
|
|
31
|
+
// planner 门禁:不可在插件页修改,改动写入 bundle 的 patch config。
|
|
32
|
+
requirePlanner: z.union(PLANNER_GATE_MODES).default('complex'),
|
|
29
33
|
// Volatile: the plugin page switches the conversation language in place, and
|
|
30
34
|
// the prompt reads the live value at assembly time.
|
|
31
35
|
language: z.union(LANGUAGE_MODES).default('auto').volatile(),
|
|
@@ -71,6 +75,12 @@ export const configJsonSchema = {
|
|
|
71
75
|
pattern: '^[^/\\s]+/[^/\\s]+$',
|
|
72
76
|
description: 'provider/model route for the planner worker (pro model); never inherited from the lead.',
|
|
73
77
|
},
|
|
78
|
+
requirePlanner: {
|
|
79
|
+
type: 'string',
|
|
80
|
+
enum: [...PLANNER_GATE_MODES],
|
|
81
|
+
default: 'complex',
|
|
82
|
+
description: 'Require the planner worker for a complex codex run; complex or off.',
|
|
83
|
+
},
|
|
74
84
|
language: {
|
|
75
85
|
type: 'string',
|
|
76
86
|
enum: [...LANGUAGE_MODES],
|
|
@@ -158,6 +168,7 @@ export function normalizeConfig(raw) {
|
|
|
158
168
|
const implementWorkerModel = volatileValue(raw?.implementWorkerModel);
|
|
159
169
|
const verifyWorkerModel = volatileValue(raw?.verifyWorkerModel);
|
|
160
170
|
const plannerWorkerModel = volatileValue(raw?.plannerWorkerModel);
|
|
171
|
+
const requirePlanner = volatileValue(raw?.requirePlanner);
|
|
161
172
|
const language = volatileValue(raw?.language);
|
|
162
173
|
const reasoning = volatileValue(raw?.reasoning);
|
|
163
174
|
// Parse eagerly so a malformed route fails activation, not the first dispatch.
|
|
@@ -169,6 +180,9 @@ export function normalizeConfig(raw) {
|
|
|
169
180
|
implementWorkerModel: String(implementWorkerModel).trim(),
|
|
170
181
|
verifyWorkerModel: String(verifyWorkerModel).trim(),
|
|
171
182
|
plannerWorkerModel: String(plannerWorkerModel).trim(),
|
|
183
|
+
requirePlanner: PLANNER_GATE_MODES.includes(requirePlanner)
|
|
184
|
+
? requirePlanner
|
|
185
|
+
: 'complex',
|
|
172
186
|
language: normalizeLanguageMode(language),
|
|
173
187
|
reasoning: REASONING_MODES.includes(reasoning)
|
|
174
188
|
? reasoning
|
package/lib/contract.js
CHANGED
|
@@ -45,23 +45,32 @@ export const STAGE_CONTRACT = {
|
|
|
45
45
|
].join('\n'),
|
|
46
46
|
plan: [
|
|
47
47
|
'### plan — define done',
|
|
48
|
+
'- A `Delivered` section in the handoff means this is a follow-up round: start from that record and its '
|
|
49
|
+
+ 'follow-ups; do not re-derive or redo the earlier change.',
|
|
48
50
|
'- Record what requirements established in the handoff: what the user asked for (goal, deliverable, '
|
|
49
51
|
+ 'constraints) and what the project actually looks like (entry points, patterns, checks). If either is '
|
|
50
52
|
+ 'missing, inspect now instead of guessing; a fact that stays in the conversation never reaches a worker.',
|
|
51
|
-
'- Call `delegate_plan`
|
|
52
|
-
+ 'single-purpose sub-tasks.
|
|
53
|
-
+ '
|
|
53
|
+
'- Call `delegate_plan` for every multi-file or cross-module change in codex: it explores read-only and '
|
|
54
|
+
+ 'returns single-purpose sub-tasks. A task list that would exceed three items makes it mandatory — the '
|
|
55
|
+
+ 'runtime refuses `implement` until a `delegate_plan` dispatch is recorded (a dispatch that fails counts '
|
|
56
|
+
+ 'too), and skips that gate when the lead itself runs the planner route. For each task settle the '
|
|
57
|
+
+ 'boundary and handoff first: goal, files in scope, acceptance check, and what it must not touch. Order '
|
|
58
|
+
+ 'tasks so each depends only on earlier ones.',
|
|
54
59
|
'- Every todo item and every planner task must name an observable acceptance check; record the definition '
|
|
55
60
|
+ 'of done with `coding_handoff({ acceptance: [...] })`. codex cannot enter verify without it.',
|
|
56
|
-
'- Call `todo_write` with one verifiable item per task (3
|
|
57
|
-
+ 'implement brief self-contained so the
|
|
61
|
+
'- Call `todo_write` with one verifiable item per task (1-3 for a small single-file change, 4-6 for a '
|
|
62
|
+
+ 'multi-file one) and exactly one `in_progress`. Keep each implement brief self-contained so the '
|
|
63
|
+
+ 'worker\'s context and tokens stay bounded.',
|
|
58
64
|
'- Choose the smallest approach: reuse existing functions, types, and patterns. Add no abstraction, '
|
|
59
65
|
+ 'dependency, or drive-by refactor the task does not need.',
|
|
60
|
-
'- `coding_stage` refuses `implement` until the list is written
|
|
66
|
+
'- `coding_stage` refuses `implement` until the list is written, and a list over three items also needs a '
|
|
67
|
+
+ '`delegate_plan` dispatch first.',
|
|
61
68
|
].join('\n'),
|
|
62
69
|
implement: [
|
|
63
70
|
'### implement — delegate the edit',
|
|
64
71
|
'- You cannot edit files in this stage: `apply_patch`, `edit`, and `write` are not in your tool table.',
|
|
72
|
+
'- You do run shell commands yourself (`bash` on POSIX, `pwsh` on Windows) for installs, git, and '
|
|
73
|
+
+ 'one-off inspection the worker cannot do; editing files is still the worker\'s job.',
|
|
65
74
|
'- Call `delegate_implement` with a self-contained task: goal, acceptance criteria, exact files, and '
|
|
66
75
|
+ 'the excerpts the worker needs. The worker has a fresh context and only the editing tools.',
|
|
67
76
|
'- Pass the handoff\'s goal, constraints, and the current task\'s acceptance into the brief; do not make '
|
|
@@ -74,6 +83,8 @@ export const STAGE_CONTRACT = {
|
|
|
74
83
|
'### verify — prove it',
|
|
75
84
|
'- Run the narrowest check first: `run_verification` with `scope:"targeted"`, then `package`, then '
|
|
76
85
|
+ '`full` when the change reaches across packages.',
|
|
86
|
+
'- Ad-hoc shell commands are available here for reproducing a failure; project checks still go through '
|
|
87
|
+
+ '`run_verification` so the outcome is recorded as evidence.',
|
|
77
88
|
'- A behavior change needs a test that would have failed before it. `delegate_verify` investigates a '
|
|
78
89
|
+ 'failure without editing.',
|
|
79
90
|
'- A task without an acceptance check cannot enter verify; record it with `coding_handoff` first.',
|
|
@@ -88,6 +99,9 @@ export const STAGE_CONTRACT = {
|
|
|
88
99
|
'### deliver — report compactly',
|
|
89
100
|
'- Close the task list first: mark the finished items completed with `todo_write`, so no step stays '
|
|
90
101
|
+ 'in_progress after delivery.',
|
|
102
|
+
'- Record the delivery in the handoff before you finish: `coding_handoff({ delivered, followUps })` — one '
|
|
103
|
+
+ 'line naming what changed, the files touched, and the check that proved it. The next turn and a '
|
|
104
|
+
+ 'resumed session read this record, not this conversation.',
|
|
91
105
|
'- Lead with the outcome: what changed and why. Then the files touched as backticked paths, the '
|
|
92
106
|
+ 'verification evidence (command and result), and residual risk.',
|
|
93
107
|
'- If the last check failed and the retry budget is exhausted, this is a BLOCKED delivery: state the '
|
package/lib/handoff.js
CHANGED
|
@@ -10,6 +10,11 @@
|
|
|
10
10
|
* than the timestamp default. The Host runtime, the worker presets, and the Web
|
|
11
11
|
* client can therefore import it directly.
|
|
12
12
|
*
|
|
13
|
+
* 交付段的写入约定:`delivered` / `followUps` 只由 deliver 阶段经 coding_handoff 写入,
|
|
14
|
+
* 记录本轮交付了什么与对应证据;它们随 checkpoint 的 handoff 持久化,由下一轮的 plan /
|
|
15
|
+
* implement worker 读取(verify 分片不渲染该段以控制提示词体积),因此重开会话也能直接
|
|
16
|
+
* 看到上一轮的交付结果,而不必回头翻对话正文。
|
|
17
|
+
*
|
|
13
18
|
* @module dsh-coding/handoff
|
|
14
19
|
*/
|
|
15
20
|
/** Version of the persisted {@link CodingHandoff} shape. */
|
|
@@ -30,10 +35,14 @@ export const HANDOFF_WORKER_LIMIT = 2000;
|
|
|
30
35
|
* Sections each role receives, in order. The planner needs the problem, the
|
|
31
36
|
* implementer needs the decisions and the task list, and the verifier needs the
|
|
32
37
|
* definition of done plus what already changed.
|
|
38
|
+
*
|
|
39
|
+
* 交付段只给 plan / implement:这两个角色需要知道上一轮交付了什么,才能接着规划与实现。
|
|
40
|
+
* verify 只核对本次改动(goal / done / changes / decisions / findings),不读上一轮交付
|
|
41
|
+
* 记录,以控制提示词体积。
|
|
33
42
|
*/
|
|
34
43
|
const WORKER_SECTIONS = {
|
|
35
|
-
plan: ['goal', 'constraints', 'done', 'findings', 'open'],
|
|
36
|
-
implement: ['goal', 'constraints', 'done', 'decisions', 'findings', 'tasks', 'open'],
|
|
44
|
+
plan: ['goal', 'delivered', 'constraints', 'done', 'findings', 'open'],
|
|
45
|
+
implement: ['goal', 'delivered', 'constraints', 'done', 'decisions', 'findings', 'tasks', 'open'],
|
|
37
46
|
verify: ['goal', 'done', 'changes', 'decisions', 'findings'],
|
|
38
47
|
};
|
|
39
48
|
/** An empty handoff stamped at `at`, defaulting to now. */
|
|
@@ -45,6 +54,7 @@ export function emptyHandoff(at) {
|
|
|
45
54
|
findings: [],
|
|
46
55
|
decisions: [],
|
|
47
56
|
open: [],
|
|
57
|
+
followUps: [],
|
|
48
58
|
tasks: [],
|
|
49
59
|
changes: [],
|
|
50
60
|
updatedAt: at ?? Date.now(),
|
|
@@ -54,6 +64,9 @@ export function emptyHandoff(at) {
|
|
|
54
64
|
* Merge one patch into a handoff. A list patch appends (dropping exact
|
|
55
65
|
* duplicates, keeping the newest {@link HANDOFF_ITEMS_LIMIT} entries); a task
|
|
56
66
|
* patch replaces the list; a change patch refines entries by `file`.
|
|
67
|
+
*
|
|
68
|
+
* `delivered` 与 goal 同语义:给值即覆盖,空串清除;`followUps` 与其余列表字段
|
|
69
|
+
* 同语义:追加、去重,并保留最新的 {@link HANDOFF_ITEMS_LIMIT} 条。
|
|
57
70
|
* @param base - the record being updated, or undefined to start empty.
|
|
58
71
|
* @param patch - the sections this stage contributes.
|
|
59
72
|
* @param at - timestamp to stamp, defaults to now.
|
|
@@ -62,14 +75,18 @@ export function emptyHandoff(at) {
|
|
|
62
75
|
export function mergeHandoff(base, patch, at) {
|
|
63
76
|
const previous = base ?? emptyHandoff(at);
|
|
64
77
|
const goal = boundedText(patch.goal === undefined ? previous.goal : patch.goal, HANDOFF_TEXT_LIMIT);
|
|
78
|
+
const delivered = boundedText(patch.delivered === undefined ? previous.delivered : patch.delivered, HANDOFF_TEXT_LIMIT);
|
|
65
79
|
return {
|
|
66
80
|
version: HANDOFF_VERSION,
|
|
67
81
|
...goal === '' ? {} : { goal },
|
|
82
|
+
...delivered === '' ? {} : { delivered },
|
|
68
83
|
constraints: mergeItems(previous.constraints, listOf(patch.constraints)),
|
|
69
84
|
acceptance: mergeItems(previous.acceptance, listOf(patch.acceptance)),
|
|
70
85
|
findings: mergeItems(previous.findings, listOf(patch.findings)),
|
|
71
86
|
decisions: mergeItems(previous.decisions, listOf(patch.decisions)),
|
|
72
87
|
open: mergeItems(previous.open, listOf(patch.open)),
|
|
88
|
+
// 旧数据与测试手工构造的记录可能没有 followUps,先兜底成空列表再合并。
|
|
89
|
+
followUps: mergeItems(previous.followUps ?? [], listOf(patch.followUps)),
|
|
73
90
|
tasks: patch.tasks === undefined ? cleanTasks(previous.tasks) : boundedTasks(listOf(patch.tasks)),
|
|
74
91
|
changes: patch.changes === undefined ? cleanChanges(previous.changes) : mergeChanges(previous.changes, listOf(patch.changes)),
|
|
75
92
|
updatedAt: at ?? Date.now(),
|
|
@@ -79,6 +96,9 @@ export function mergeHandoff(base, patch, at) {
|
|
|
79
96
|
* Validate one untyped value as a {@link CodingHandoff}. The record is persisted
|
|
80
97
|
* in checkpoints and restored from durable JSON, so every field is re-checked
|
|
81
98
|
* here rather than trusted from the writer's build.
|
|
99
|
+
*
|
|
100
|
+
* 旧 checkpoint 可能没有 `delivered` / `followUps`(与 `files` 字段先例一致,不 bump
|
|
101
|
+
* {@link HANDOFF_VERSION}):缺字段按空值处理,损坏值被丢弃,返回的记录始终可用。
|
|
82
102
|
* @param value - decoded JSON or any other untyped value.
|
|
83
103
|
* @returns the normalized record, or undefined when it is not version 1.
|
|
84
104
|
*/
|
|
@@ -89,15 +109,18 @@ export function asHandoff(value) {
|
|
|
89
109
|
if (raw['version'] !== HANDOFF_VERSION)
|
|
90
110
|
return undefined;
|
|
91
111
|
const goal = boundedText(raw['goal'], HANDOFF_TEXT_LIMIT);
|
|
112
|
+
const delivered = boundedText(raw['delivered'], HANDOFF_TEXT_LIMIT);
|
|
92
113
|
const updatedAt = raw['updatedAt'];
|
|
93
114
|
return {
|
|
94
115
|
version: HANDOFF_VERSION,
|
|
95
116
|
...goal === '' ? {} : { goal },
|
|
117
|
+
...delivered === '' ? {} : { delivered },
|
|
96
118
|
constraints: mergeItems([], listOf(raw['constraints'])),
|
|
97
119
|
acceptance: mergeItems([], listOf(raw['acceptance'])),
|
|
98
120
|
findings: mergeItems([], listOf(raw['findings'])),
|
|
99
121
|
decisions: mergeItems([], listOf(raw['decisions'])),
|
|
100
122
|
open: mergeItems([], listOf(raw['open'])),
|
|
123
|
+
followUps: mergeItems([], listOf(raw['followUps'])),
|
|
101
124
|
tasks: boundedTasks(listOf(raw['tasks'])),
|
|
102
125
|
changes: mergeChanges([], listOf(raw['changes'])),
|
|
103
126
|
updatedAt: typeof updatedAt === 'number' && Number.isFinite(updatedAt) ? updatedAt : Date.now(),
|
|
@@ -117,11 +140,15 @@ export function handoffDigest(handoff, limit = HANDOFF_DIGEST_LIMIT) {
|
|
|
117
140
|
const goal = boundedText(handoff.goal, HANDOFF_TEXT_LIMIT);
|
|
118
141
|
if (goal !== '')
|
|
119
142
|
lines.push(`goal: ${goal}`);
|
|
143
|
+
const delivered = boundedText(handoff.delivered, HANDOFF_TEXT_LIMIT);
|
|
144
|
+
if (delivered !== '')
|
|
145
|
+
lines.push(`delivered: ${delivered}`);
|
|
120
146
|
pushItems(lines, 'constraints', handoff.constraints);
|
|
121
147
|
pushItems(lines, 'done', handoff.acceptance);
|
|
122
148
|
pushItems(lines, 'decisions', handoff.decisions);
|
|
123
149
|
pushItems(lines, 'findings', handoff.findings);
|
|
124
150
|
pushItems(lines, 'open', handoff.open);
|
|
151
|
+
pushItems(lines, 'follow-ups', handoff.followUps);
|
|
125
152
|
const tasks = cleanTasks(handoff.tasks);
|
|
126
153
|
if (tasks.length > 0) {
|
|
127
154
|
lines.push('tasks:');
|
|
@@ -139,6 +166,7 @@ export function handoffDigest(handoff, limit = HANDOFF_DIGEST_LIMIT) {
|
|
|
139
166
|
}
|
|
140
167
|
/**
|
|
141
168
|
* Render the sections one worker role receives, as a prompt fragment.
|
|
169
|
+
* 只有 plan / implement 分片包含 `Delivered:` 段,见 {@link WORKER_SECTIONS}。
|
|
142
170
|
* @param handoff - record to render, or undefined.
|
|
143
171
|
* @param role - worker about to run.
|
|
144
172
|
* @returns the fragment, or '' when nothing applies to this role.
|
|
@@ -148,11 +176,13 @@ export function handoffForWorker(handoff, role) {
|
|
|
148
176
|
return '';
|
|
149
177
|
const sections = {
|
|
150
178
|
goal: goalSection(handoff.goal),
|
|
179
|
+
delivered: deliveredSection(handoff.delivered),
|
|
151
180
|
constraints: bulletSection('Constraints:', cleanItems(handoff.constraints)),
|
|
152
181
|
done: bulletSection('Definition of done:', cleanItems(handoff.acceptance)),
|
|
153
182
|
decisions: bulletSection('Decisions:', cleanItems(handoff.decisions)),
|
|
154
183
|
findings: bulletSection('Findings:', cleanItems(handoff.findings)),
|
|
155
184
|
open: bulletSection('Open questions:', cleanItems(handoff.open)),
|
|
185
|
+
followUps: bulletSection('Follow-ups:', cleanItems(handoff.followUps)),
|
|
156
186
|
tasks: taskSection(cleanTasks(handoff.tasks)),
|
|
157
187
|
changes: changeSection(cleanChanges(handoff.changes)),
|
|
158
188
|
};
|
|
@@ -284,6 +314,11 @@ function goalSection(goal) {
|
|
|
284
314
|
const text = boundedText(goal, HANDOFF_TEXT_LIMIT);
|
|
285
315
|
return text === '' ? undefined : `Goal:\n${text}`;
|
|
286
316
|
}
|
|
317
|
+
/** The `Delivered:` fragment(上一轮交付了什么 + 证据),or nothing when absent. */
|
|
318
|
+
function deliveredSection(value) {
|
|
319
|
+
const text = boundedText(value, HANDOFF_TEXT_LIMIT);
|
|
320
|
+
return text === '' ? undefined : `Delivered:\n${text}`;
|
|
321
|
+
}
|
|
287
322
|
/** A titled list, one `- item` per line, or nothing when the list is empty. */
|
|
288
323
|
function bulletSection(title, values) {
|
|
289
324
|
if (values.length === 0)
|
package/lib/index.js
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
* Host-side settings service of the `dsh-coding` bundle.
|
|
3
3
|
*
|
|
4
4
|
* This row is the bundle's only Host contribution: it owns the verified
|
|
5
|
-
* configuration the Coding preset and its
|
|
5
|
+
* configuration the Coding preset and its four worker presets read, and it
|
|
6
6
|
* performs no agent work by itself. Installing the bundle therefore changes no
|
|
7
7
|
* existing session; only a session that selects the Coding preset runs the
|
|
8
8
|
* enforced runtime.
|
|
9
9
|
*
|
|
10
|
-
* It also filters this bundle's
|
|
10
|
+
* It also filters this bundle's four internal worker presets out of the exported
|
|
11
11
|
* preset roster: no client offers them, while the Host roster keeps resolving
|
|
12
12
|
* the compositions `delegate_implement` and `delegate_verify` dispatch to.
|
|
13
13
|
*
|
|
@@ -33,6 +33,7 @@ const WORKER_PRESET_IDS = [
|
|
|
33
33
|
WORKER_PRESETS.planner,
|
|
34
34
|
WORKER_PRESETS.implement,
|
|
35
35
|
WORKER_PRESETS.verify,
|
|
36
|
+
WORKER_PRESETS.verifyWithInstructions,
|
|
36
37
|
];
|
|
37
38
|
/**
|
|
38
39
|
* The client-facing roster without this bundle's worker presets. The Host
|