@cstart/coldstart 2.2.14 → 2.2.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/init.d.ts +16 -3
  2. package/dist/init.d.ts.map +1 -1
  3. package/dist/init.js +49 -7
  4. package/dist/init.js.map +1 -1
  5. package/dist/kb/cli.d.ts.map +1 -1
  6. package/dist/kb/cli.js +72 -49
  7. package/dist/kb/cli.js.map +1 -1
  8. package/dist/kb/durable-worklist.d.ts +20 -0
  9. package/dist/kb/durable-worklist.d.ts.map +1 -0
  10. package/dist/kb/durable-worklist.js +175 -0
  11. package/dist/kb/durable-worklist.js.map +1 -0
  12. package/dist/kb/store.d.ts.map +1 -1
  13. package/dist/kb/store.js +24 -3
  14. package/dist/kb/store.js.map +1 -1
  15. package/dist/kb/write-batch.d.ts +21 -0
  16. package/dist/kb/write-batch.d.ts.map +1 -0
  17. package/dist/kb/write-batch.js +77 -0
  18. package/dist/kb/write-batch.js.map +1 -0
  19. package/dist/kb/write-guide.d.ts.map +1 -1
  20. package/dist/kb/write-guide.js +23 -13
  21. package/dist/kb/write-guide.js.map +1 -1
  22. package/dist/kb/write.d.ts +4 -0
  23. package/dist/kb/write.d.ts.map +1 -1
  24. package/dist/kb/write.js +10 -1
  25. package/dist/kb/write.js.map +1 -1
  26. package/dist/server/mcp.d.ts +12 -1
  27. package/dist/server/mcp.d.ts.map +1 -1
  28. package/dist/server/mcp.js +53 -35
  29. package/dist/server/mcp.js.map +1 -1
  30. package/hooks/capture-payload.mjs +229 -85
  31. package/hooks/capture-sentinel.d.mts +4 -0
  32. package/hooks/capture-sentinel.mjs +10 -0
  33. package/hooks/codex-kb-elicit.mjs +6 -2
  34. package/hooks/codex-kb-recall.mjs +54 -5
  35. package/hooks/cursor-kb-elicit.mjs +8 -4
  36. package/hooks/cursor-kb-recall.mjs +34 -1
  37. package/hooks/kb-elicit.mjs +81 -34
  38. package/package.json +1 -1
  39. package/dist/kb/session-worklist.d.ts +0 -10
  40. package/dist/kb/session-worklist.d.ts.map +0 -1
  41. package/dist/kb/session-worklist.js +0 -92
  42. package/dist/kb/session-worklist.js.map +0 -1
@@ -77,7 +77,14 @@ export declare const TOOL_DEFINITIONS: readonly [{
77
77
  readonly properties: {
78
78
  readonly spec: {
79
79
  readonly type: "object";
80
- readonly description: `The note spec (JSON object). Fields: type, title, summary, identityAliases (stable \u2014 unions forever), incidentAliases (this write's symptom words \u2014 replaced by the next write that changes summary/body, omit if this write isn't about an incident), anchors:[{path,symbols?}], and type-specific fields (facets/character for file; steps/verified for flow; kind/scope/body for lesson). ${string} Omit \`id\` on a new flow/lesson to trigger the reuse gate.`;
80
+ readonly description: `A single note spec (JSON object). Fields: type, title, summary, identityAliases (stable \u2014 unions forever), incidentAliases (this write's symptom words \u2014 replaced by the next write that changes summary/body, omit if this write isn't about an incident), anchors:[{path,symbols?}], and type-specific fields (facets/character for file; steps/verified for flow; kind/scope/body for lesson). ${string} Omit \`id\` on a new flow/lesson to trigger the reuse gate. Use \`specs\` instead to write several notes at once.`;
81
+ };
82
+ readonly specs: {
83
+ readonly type: "array";
84
+ readonly items: {
85
+ readonly type: "object";
86
+ };
87
+ readonly description: "The capture path: an ARRAY of note specs (each the same shape as `spec`), written in ONE call. Order flows before the file notes that reference them. Well-formed notes are written; malformed ones are reported together (not atomic — a bad note never silences a good one); the result ends with a coverage line naming any worked file still without a note. Prefer this over many single-`spec` calls.";
81
88
  };
82
89
  readonly into: {
83
90
  readonly type: "string";
@@ -91,6 +98,10 @@ export declare const TOOL_DEFINITIONS: readonly [{
91
98
  readonly type: "string";
92
99
  readonly description: "Optional session id (given in a capture prompt). Enables the flow-evidence check: a flow whose step files this session never actually read gets a warning.";
93
100
  };
101
+ readonly agent: {
102
+ readonly type: "string";
103
+ readonly description: "Optional agent id (given in a capture prompt, alongside session). Selects THIS agent stream's durable worklist for the coverage line so a subagent does not clear the main agent's list. Defaults to \"main\".";
104
+ };
94
105
  };
95
106
  readonly required: readonly [];
96
107
  };
@@ -1 +1 @@
1
- {"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/server/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAWnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAUxD,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsKnB,CAAC;AAKX,MAAM,WAAW,gBAAgB;IAC/B;uEACmE;IACnE,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,OAAO,CAAC,YAAY,CAAC,EACvC,IAAI,GAAE,gBAAqB,GAC1B,IAAI,CAmMN;AAOD,eAAO,MAAM,mBAAmB,QAIpB,CAAC;AAKb,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,OAAO,CAAC,YAAY,CAAC,EAAE,IAAI,GAAE,gBAAqB,GAAG,MAAM,CAiB5G;AAKD,wBAAsB,cAAc,CAClC,OAAO,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,EACjD,UAAU,EAAE,MAAM,OAAO,CAAC,YAAY,CAAC,EACvC,IAAI,GAAE,gBAAqB,GAC1B,OAAO,CAAC,IAAI,CAAC,CAuCf"}
1
+ {"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/server/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAWnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAUxD,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+KnB,CAAC;AAKX,MAAM,WAAW,gBAAgB;IAC/B;uEACmE;IACnE,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,OAAO,CAAC,YAAY,CAAC,EACvC,IAAI,GAAE,gBAAqB,GAC1B,IAAI,CAmMN;AAOD,eAAO,MAAM,mBAAmB,QAIpB,CAAC;AAKb,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,OAAO,CAAC,YAAY,CAAC,EAAE,IAAI,GAAE,gBAAqB,GAAG,MAAM,CAiB5G;AAKD,wBAAsB,cAAc,CAClC,OAAO,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,EACjD,UAAU,EAAE,MAAM,OAAO,CAAC,YAAY,CAAC,EACvC,IAAI,GAAE,gBAAqB,GAC1B,OAAO,CAAC,IAAI,CAAC,CAuCf"}
@@ -100,7 +100,7 @@ export const TOOL_DEFINITIONS = [
100
100
  },
101
101
  {
102
102
  name: 'kb_write',
103
- description: 'Save or correct a NOTEBOOK note after finishing real work here — you have the files in context, so no future agent is better placed to record what you learned. Write a file note (what a file is for), a flow note (how a task spans files), or an absence lesson (a confirmed "there is no X"). Also the tool to FIX or RETRACT a note you used that proved wrong (`op: "put"` replaces, `op: "retract"` removes).\n\n' +
103
+ description: 'Save or correct NOTEBOOK notes after finishing real work here — you have the files in context, so no future agent is better placed to record what you learned. Write a file note (what a file is for), a flow note (how a task spans files), or an absence lesson (a confirmed "there is no X"). Pass `specs` (an ARRAY of specs) to write ALL your notes in ONE call — malformed notes are reported together instead of one hiding the rest, and the result ends with a coverage line naming any worked files still without a note; pass `spec` (a single object) for a one-off. Also the tool to FIX or RETRACT a note you used that proved wrong: `op: "put"` replaces; `op: "retract"` with `target: {kind: "note"}` removes the whole note (or `target: {kind: "anchor"|"alias"|"facet"|"invariant"|"behavior"|"feature", key: "<value>"}` removes one part).\n\n' +
104
104
  'TWO-PHASE reuse gate: a flow/lesson `spec` sent WITHOUT an `id` first searches the notebook for the same concept. If plausible matches exist, kb_write returns `{status:"candidates", candidates:[...]}` INSTEAD of writing — re-call with `into: "<id>"` to merge into an existing note, or `is_new: true` to declare a genuinely new one. This makes note identity reliable (matching, not guessing an exact title). File notes skip the gate (id derives from the path).\n\n' +
105
105
  'The `spec` shape: `type` ("file"|"flow"|"lesson", or sugar "file-hub"/"file-single"), `title`, `summary`, `anchors` ([{path, symbols?}] — the addresses the note is about, which drive freshness), plus type-specific fields (file: facets/character; flow: steps/verified; lesson: kind:"absence"/scope/body). Call with NO arguments to get the full spec guide.\n\n' +
106
106
  // Rendered, not restated. This description going years without ever
@@ -113,7 +113,12 @@ export const TOOL_DEFINITIONS = [
113
113
  properties: {
114
114
  spec: {
115
115
  type: 'object',
116
- description: `The note spec (JSON object). Fields: type, title, summary, identityAliases (stable — unions forever), incidentAliases (this write's symptom words — replaced by the next write that changes summary/body, omit if this write isn't about an incident), anchors:[{path,symbols?}], and type-specific fields (facets/character for file; steps/verified for flow; kind/scope/body for lesson). ${requiredFieldsLine()} Omit \`id\` on a new flow/lesson to trigger the reuse gate.`,
116
+ description: `A single note spec (JSON object). Fields: type, title, summary, identityAliases (stable — unions forever), incidentAliases (this write's symptom words — replaced by the next write that changes summary/body, omit if this write isn't about an incident), anchors:[{path,symbols?}], and type-specific fields (facets/character for file; steps/verified for flow; kind/scope/body for lesson). ${requiredFieldsLine()} Omit \`id\` on a new flow/lesson to trigger the reuse gate. Use \`specs\` instead to write several notes at once.`,
117
+ },
118
+ specs: {
119
+ type: 'array',
120
+ items: { type: 'object' },
121
+ description: 'The capture path: an ARRAY of note specs (each the same shape as `spec`), written in ONE call. Order flows before the file notes that reference them. Well-formed notes are written; malformed ones are reported together (not atomic — a bad note never silences a good one); the result ends with a coverage line naming any worked file still without a note. Prefer this over many single-`spec` calls.',
117
122
  },
118
123
  into: {
119
124
  type: 'string',
@@ -127,6 +132,10 @@ export const TOOL_DEFINITIONS = [
127
132
  type: 'string',
128
133
  description: 'Optional session id (given in a capture prompt). Enables the flow-evidence check: a flow whose step files this session never actually read gets a warning.',
129
134
  },
135
+ agent: {
136
+ type: 'string',
137
+ description: 'Optional agent id (given in a capture prompt, alongside session). Selects THIS agent stream\'s durable worklist for the coverage line so a subagent does not clear the main agent\'s list. Defaults to "main".',
138
+ },
130
139
  },
131
140
  required: [],
132
141
  },
@@ -230,51 +239,60 @@ export function registerToolHandlers(server, getContext, opts = {}) {
230
239
  break;
231
240
  }
232
241
  case 'kb_write': {
233
- const { kbWrite } = await import('../kb/write.js');
234
242
  const { initSkeleton } = await import('../kb/store.js');
235
- const { writeGuideMcp, flowEvidenceWarning, flowStepsWarning, missingFieldsWarning } = await import('../kb/write-guide.js');
236
- const spec = params['spec'];
237
- if (!spec || typeof spec !== 'object' || Array.isArray(spec)) {
238
- // Parity with `kb write` (no spec): return the full guide, not an error.
243
+ const { writeGuideMcp } = await import('../kb/write-guide.js');
244
+ const { kbWriteBatch } = await import('../kb/write-batch.js');
245
+ // `specs` (array) is the capture path all notes in one call, errors
246
+ // reported together, coverage finalized once. `spec` (object) stays a
247
+ // batch of one for a single/manual write. Neither → the full guide.
248
+ const rawSpecs = params['specs'] ?? params['spec'];
249
+ const isBatch = Array.isArray(rawSpecs);
250
+ if (rawSpecs === undefined || rawSpecs === null
251
+ || (!isBatch && (typeof rawSpecs !== 'object'))) {
252
+ result = { __rawText: writeGuideMcp() };
253
+ break;
254
+ }
255
+ const specs = (isBatch ? rawSpecs : [rawSpecs]);
256
+ if (!specs.length) {
239
257
  result = { __rawText: writeGuideMcp() };
240
258
  break;
241
259
  }
242
260
  initSkeleton(index.rootDir); // first write creates the notebook
243
- const wres = await kbWrite(index.rootDir, spec, {
261
+ const batch = await kbWriteBatch(index.rootDir, specs, {
244
262
  into: params['into'] ? String(params['into']) : undefined,
245
263
  isNew: Boolean(params['is_new']),
264
+ session: params['session'] ? String(params['session']) : undefined,
265
+ agent: params['agent'] ? String(params['agent']) : undefined,
246
266
  });
247
- if (wres.status === 'error') {
248
- result = { error: wres.message };
267
+ if (!isBatch) {
268
+ // Single-spec result stays shape-compatible with the pre-batch tool.
269
+ const o = batch.outcomes[0];
270
+ if (o.status === 'error')
271
+ result = { error: o.message };
272
+ else if (o.status === 'candidates') {
273
+ result = {
274
+ status: 'candidates',
275
+ candidates: o.candidates,
276
+ message: `${o.message} Re-call kb_write with the same spec plus \`into: "<id>"\` to merge into one of these, or \`is_new: true\` to create a new note.`,
277
+ };
278
+ }
279
+ else {
280
+ result = {
281
+ status: 'written', op: o.op, id: o.id, warnings: o.warnings ?? [],
282
+ ...(batch.coverage ? { coverage: batch.coverage } : {}),
283
+ };
284
+ }
249
285
  }
250
- else if (wres.status === 'candidates') {
286
+ else {
251
287
  result = {
252
- status: 'candidates',
253
- candidates: wres.candidates,
254
- message: `${wres.message} Re-call kb_write with the same spec plus \`into: "<id>"\` to merge into one of these, or \`is_new: true\` to create a new note.`,
288
+ status: 'batch',
289
+ written: batch.written,
290
+ errors: batch.errors,
291
+ candidates: batch.candidates,
292
+ results: batch.outcomes,
293
+ ...(batch.coverage ? { coverage: batch.coverage } : {}),
255
294
  };
256
295
  }
257
- else {
258
- const warnings = [...(wres.warnings ?? [])];
259
- // Stepless-flow WARN — parity with `kb write`; needs no session.
260
- const { loadNote } = await import('../kb/store.js');
261
- const after = loadNote(index.rootDir, wres.id).note;
262
- const stepsWarn = flowStepsWarning(spec, after);
263
- if (stepsWarn)
264
- warnings.push(stepsWarn);
265
- // Flow-evidence WARN (never a rejection) — parity with `kb write --session`.
266
- const flowWarn = flowEvidenceWarning(spec, params['session'] ? String(params['session']) : undefined);
267
- if (flowWarn)
268
- warnings.push(flowWarn);
269
- // Findability fields — parity with `kb write`; never a rejection.
270
- const missingWarn = missingFieldsWarning(spec, wres.id, after);
271
- if (missingWarn)
272
- warnings.push(missingWarn);
273
- // Capture coverage — parity with `kb write --session`.
274
- const { noteCoverage } = await import('../kb/session-worklist.js');
275
- const coverage = noteCoverage(params['session'] ? String(params['session']) : undefined, spec);
276
- result = { status: 'written', op: wres.op, id: wres.id, warnings, ...(coverage ? { coverage } : {}) };
277
- }
278
296
  break;
279
297
  }
280
298
  // Parity with `coldstart kb repair`: same detection, same worklist text
@@ -1 +1 @@
1
- {"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../src/server/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,qBAAqB,EACrB,0BAA0B,EAC1B,kCAAkC,EAClC,wBAAwB,GACzB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAEhE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EACL,UAAU,EACV,kBAAkB,GACnB,MAAM,YAAY,CAAC;AAEpB,8EAA8E;AAC9E,8EAA8E;AAC9E,8EAA8E;AAC9E,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B;QACE,IAAI,EAAE,MAAM;QACZ,WAAW,EACT,kWAAkW;YAClW,wWAAwW;YACxW,sfAAsf;YACtf,4MAA4M;YAC5M,qBAAqB;YACrB,sFAAsF;YACtF,+HAA+H;YAC/H,2NAA2N;QAC7N,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,KAAK,EAAE;oBACL,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,4MAA4M;iBAC1N;aACF;Y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AE,CAAC;YACtD,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QACpD,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,4EAA4E;IAC9E,CAAC;IAED,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC;AAC7B,CAAC"}
@@ -16,8 +16,7 @@
16
16
  * (the coordinator only sees the final message — #61).
17
17
  */
18
18
 
19
- import { readFileSync, writeFileSync } from "node:fs";
20
- import { tmpdir } from "node:os";
19
+ import { readFileSync, writeFileSync, mkdirSync, readdirSync, statSync, unlinkSync } from "node:fs";
21
20
  import { join } from "node:path";
22
21
  // The spec shapes are NOT written here any more. They come from the one table
23
22
  // the write guide, the MCP tool description and `kb repair` also render from —
@@ -25,25 +24,102 @@ import { join } from "node:path";
25
24
  import { shapesBlock } from "./note-shape.mjs";
26
25
 
27
26
  /**
28
- * Session worklist manifest — the DENOMINATOR for capture coverage.
27
+ * Durable capture worklist — the checklist the agent can re-Read at any point.
29
28
  *
30
- * The checklist can only ASK the agent to walk the whole worklist (rule 3a);
31
- * nothing downstream could tell it that it wrote 8 notes for 30 worked files,
32
- * because `kb write` sees one spec at a time and never saw the worklist. So the
33
- * worklist is dropped here, at the one point every host passes through, and
34
- * `kb write --session <sid>` reads it back to print "N of M".
29
+ * The old design dropped the worklist in tmpdir (keyed by session id) and let
30
+ * `kb write --session` print a running "N of M". Two failures: the manifest was
31
+ * scratch that no agent ever read directly, and the whole capture PAYLOAD (this
32
+ * checklist + the write contract) was delivered one-shot and lost to compaction
33
+ * the agent had to re-derive the note shape from memory 80 tool-calls later.
35
34
  *
36
- * CONTRACT TWIN: src/kb/session-worklist.ts same filename, same shape. Keyed
37
- * by session id in tmpdir like the pending-capture file (elicit-core.pendingPath);
38
- * never in the repo, so it cannot be committed and needs no ignore rule.
39
- * Best-effort: capture must never fail because this could not be written.
35
+ * So the pair now lives in the repo notebook and holds BOTH:
36
+ * .worklist-<sid>-<aid>.json structured scope (the coverage source of truth)
37
+ * .worklist-<sid>-<aid>.md today's worklist + a pointer (see below)
38
+ * The agent re-Reads the .md whenever this scrolls away; `kb write` credits and
39
+ * trims/clears the pair (src/kb/durable-worklist.ts) so a stale snapshot never
40
+ * lingers, and the next capture fire regenerates it against live freshness.
41
+ *
42
+ * The .md used to hold the FULL rendered payload — the ~150 lines of static
43
+ * DECIDE-FIRST/per-note/FLOWS/WRITE rules, byte-identical every session,
44
+ * duplicated onto disk every single fire. Since 2026-08-06 that static text
45
+ * lives once in a PERMANENT file, `.capture-instructions.md` (also gitignored,
46
+ * but never deleted/regenerated per fire — only rewritten if its version tag is
47
+ * stale, see INSTRUCTIONS_VERSION below); the per-session .md now holds only
48
+ * the worklist + a pointer to it. The payload delivered to the agent THIS turn
49
+ * (buildCapturePayload's return value) is unaffected — it still inlines the
50
+ * full instructions text so nothing changes for the current fire, only what's
51
+ * persisted for a later re-Read.
52
+ *
53
+ * KEYED BY <sid>-<aid>, the SAME identity as the tmpdir evidence marker — NOT by
54
+ * root, and NOT by sid alone. A subagent shares its parent's session id, so a
55
+ * sid-only (or root-only) key would let a subagent's capture clobber the main
56
+ * agent's worklist. Each agent stream owns its own pair; the printed `kb write`
57
+ * carries `--session <sid> --agent <aid>` so finalize trims the right one.
58
+ *
59
+ * CONTRACT TWIN: src/kb/durable-worklist.ts — keep the paths and the .json shape
60
+ * (ts, sid, aid, files:[{path,tier,needsNote}], wrote:[]) in step. Both gitignored
61
+ * (src/kb/store.ts initSkeleton). Best-effort: capture must never fail because
62
+ * these could not be written.
40
63
  */
41
- export function worklistManifestPath(sid) {
42
- return join(tmpdir(), `coldstart-kb-worklist-${sid}.json`);
64
+ export function worklistJsonPath(root, sid, aid) {
65
+ const k = worklistKey(sid, aid);
66
+ return join(root, ".coldstart", "notebook", k ? `.worklist-${k}.json` : ".worklist.json");
67
+ }
68
+ export function worklistMdPath(root, sid, aid) {
69
+ const k = worklistKey(sid, aid);
70
+ return join(root, ".coldstart", "notebook", k ? `.worklist-${k}.md` : ".worklist.md");
71
+ }
72
+ function worklistKey(sid, aid) {
73
+ const s = String(sid ?? "").replace(/[^A-Za-z0-9_-]/g, "");
74
+ return s ? `${s}-${String(aid ?? "").replace(/[^A-Za-z0-9_-]/g, "") || "main"}` : "";
43
75
  }
44
76
 
45
- function recordWorklistManifest(sid, entries) {
46
- if (!sid || !entries?.length) return;
77
+ // Abandoned sessions' worklist pairs would otherwise accrue forever (a session
78
+ // that fires once then never captures again leaves its pair behind). Prune any
79
+ // sibling worklist file whose json is older than this on each fire — long enough
80
+ // that a still-live session is never touched, short enough to stay tidy.
81
+ const STALE_WORKLIST_MS = 3 * 24 * 60 * 60 * 1000;
82
+ function pruneStaleWorklists(dir, keepKey) {
83
+ try {
84
+ for (const n of readdirSync(dir)) {
85
+ const m = /^\.worklist-([A-Za-z0-9_-]+)\.json$/.exec(n);
86
+ if (!m || m[1] === keepKey) continue;
87
+ // Age by the json's own ts; fall back to file mtime when ts is absent or
88
+ // unreadable, NEVER to 0 — a ts-less-but-recent file must not read as 1970
89
+ // and get deleted out from under a live session.
90
+ let ts = 0;
91
+ try { ts = JSON.parse(readFileSync(join(dir, n), "utf8"))?.ts || statMtime(join(dir, n)); } catch { ts = statMtime(join(dir, n)); }
92
+ if (Date.now() - ts < STALE_WORKLIST_MS) continue;
93
+ for (const p of [join(dir, n), join(dir, n.replace(/\.json$/, ".md"))]) {
94
+ try { unlinkSync(p); } catch { /* best-effort */ }
95
+ }
96
+ }
97
+ } catch { /* best-effort */ }
98
+ }
99
+ function statMtime(p) { try { return statSync(p).mtimeMs; } catch { return 0; } }
100
+
101
+ /**
102
+ * The .md half of the durable pair used to hold the FULL rendered payload
103
+ * (instructions + worklist) — meaning the ~150-line static instructions were
104
+ * duplicated onto disk once per session, every session, forever. Since
105
+ * 2026-08-06 that static text lives once in the permanent
106
+ * .capture-instructions.md (below); the per-session .md only needs to point at
107
+ * it plus carry the part that's actually per-session, the worklist.
108
+ */
109
+ function renderDurableMd(sid, aid, entries) {
110
+ return `**Notebook capture point.** Full instructions: \`.coldstart/notebook/.capture-instructions.md\` \
111
+ (stable — re-Read it once; it does not change per session). This file holds only today's worklist.
112
+
113
+ WORKLIST — files you actually read this session, most-worked first:
114
+
115
+ ${worklistLines(entries)}
116
+
117
+ Write command: node <cli> kb write /tmp/notes.json --root <root> --session ${sid} --agent ${aid} --force
118
+ `;
119
+ }
120
+
121
+ function writeDurableWorklist(root, sid, aid, entries) {
122
+ if (!root || !entries?.length) return;
47
123
  try {
48
124
  // needsNote: no note yet, or the note it has is stale. A file whose note is
49
125
  // already fresh is NOT an outstanding item — counting it would make full
@@ -53,14 +129,18 @@ function recordWorklistManifest(sid, entries) {
53
129
  tier: e.tier,
54
130
  needsNote: !e.notes?.length || e.notes.some((n) => n.state === "changed" || n.state === "missing"),
55
131
  }));
56
- writeFileSync(worklistManifestPath(sid), JSON.stringify({ ts: Date.now(), files, wrote: [] }));
132
+ const dir = join(root, ".coldstart", "notebook");
133
+ mkdirSync(dir, { recursive: true });
134
+ writeFileSync(worklistJsonPath(root, sid, aid), JSON.stringify({ ts: Date.now(), sid, aid: aid || "main", files, wrote: [] }));
135
+ writeFileSync(worklistMdPath(root, sid, aid), renderDurableMd(sid, aid || "main", entries));
136
+ pruneStaleWorklists(dir, worklistKey(sid, aid));
57
137
  } catch { /* best-effort */ }
58
138
  }
59
139
 
60
140
  /**
61
141
  * SPIKE (experimental, undocumented): a repo can replace the shipped checklist
62
142
  * with its own `.coldstart/checklist.md`. Placeholders {{WORKLIST}}, {{CLI}},
63
- * {{ROOT}}, {{SID}} are substituted. The worklist is LOAD-BEARING (it is the
143
+ * {{ROOT}}, {{SID}}, {{AID}} are substituted. The worklist is LOAD-BEARING (it is the
64
144
  * scope rule) — an override that omits {{WORKLIST}} gets it appended anyway.
65
145
  * Trigger mechanics stay in code; only the prompt text is overridable. Merge
66
146
  * semantics when the shipped default evolves = none (the override wins
@@ -74,65 +154,31 @@ function loadChecklistOverride(root) {
74
154
  }
75
155
 
76
156
  /**
77
- * worklist entry: { path, tier, retouches, notes: [{id, type, state}], noConsumers }
78
- * tier: "edited ×N" | "read" | "skimmed"
157
+ * The shipped instructions (DECIDE-FIRST rules, per-note rules, FLOWS, WRITE
158
+ * mechanics) are identical every fire, every session — only the worklist and a
159
+ * handful of interpolated values change. Since 2026-08-06 this static text is
160
+ * generated ONCE into a permanent file (`.capture-instructions.md`, gitignored
161
+ * like the rest of the durable-worklist pair, but never deleted/regenerated per
162
+ * fire) instead of being duplicated onto disk in every session's .md — same
163
+ * placeholder mechanism as the user-authored checklist override above, so both
164
+ * paths share one substitution pass in renderCapturePayload.
165
+ *
166
+ * VERSIONED so an upgrade that changes the shipped text self-heals an existing
167
+ * repo's stale copy instead of silently drifting; bump when the template below
168
+ * changes.
79
169
  */
80
- function worklistLines(entries) {
81
- const lines = [];
82
- for (const e of entries) {
83
- const ann = [];
84
- ann.push(`[${e.tier}]`);
85
- if (!e.notes?.length) {
86
- ann.push("no note yet");
87
- } else {
88
- for (const n of e.notes) {
89
- if (n.state === "fresh") {
90
- ann.push(`note ${n.id} (fresh) → update ONLY if this session taught something the note lacks (.coldstart/notebook/notes/${n.id}.md)`);
91
- } else if (n.state === "changed" || n.state === "missing") {
92
- ann.push(`note ${n.id} (STALE) → fix or re-stamp; list the path in "verified" (.coldstart/notebook/notes/${n.id}.md)`);
93
- } else {
94
- ann.push(`note ${n.id} → read it first, update by its "id" (.coldstart/notebook/notes/${n.id}.md)`);
95
- }
96
- }
97
- }
98
- if (e.noConsumers) ann.push("no consumers in import graph");
99
- lines.push(`- ${e.path} ${ann.join(" · ")}`);
100
- }
101
- return lines.join("\n");
102
- }
103
-
104
- export function buildCapturePayload({ root, cli, sid, entries, envelope }) {
105
- recordWorklistManifest(sid, entries);
106
- const opening = envelope === "block"
107
- ? "Handle capture now, then stop."
108
- : envelope === "manual"
109
- ? "You invoked this capture yourself (/capture-notes) — handle it now, then carry on."
110
- : "Handle capture first, then continue with the user's request.";
111
-
112
- const tail = envelope === "subagent"
113
- ? `\nOnce you have handled the notebook — whether you wrote notes or decided none were \
114
- needed — remember you were spawned as a subagent. The coordinator that spawned you receives \
115
- ONLY your final message, so your last message must repeat, in full, the result you produced \
116
- for it — your findings, not the notebook decision.`
117
- : "";
170
+ const INSTRUCTIONS_VERSION = 1;
171
+ const INSTRUCTIONS_VERSION_TAG = `<!-- coldstart:capture-instructions:v${INSTRUCTIONS_VERSION} -->`;
118
172
 
119
- const override = loadChecklistOverride(root);
120
- if (override) {
121
- const worklist = worklistLines(entries);
122
- let body = override
123
- .replaceAll("{{CLI}}", String(cli))
124
- .replaceAll("{{ROOT}}", String(root))
125
- .replaceAll("{{SID}}", String(sid));
126
- body = body.includes("{{WORKLIST}}")
127
- ? body.replaceAll("{{WORKLIST}}", worklist)
128
- : `${body.trimEnd()}\n\nWORKLIST — files you actually read this session, most-worked first \
129
- (your scope; if you edited or deep-read a file that isn't listed, you can note it too):\n\n${worklist}`;
130
- return `**Notebook capture point.** ${opening}\n\n${body.trimEnd()}${tail}`;
131
- }
173
+ function captureInstructionsPath(root) {
174
+ return join(root, ".coldstart", "notebook", ".capture-instructions.md");
175
+ }
132
176
 
133
- return `**Notebook capture point.** You have completed work and gathered knowledge as part \
134
- of it — knowledge a future agent could use. This repo keeps that knowledge in a notebook: \
135
- notes are searched and served to future cold agents when their task matches. ${opening}
177
+ function shippedInstructionsTemplate() {
178
+ return `${INSTRUCTIONS_VERSION_TAG}
179
+ You have completed work and gathered knowledge as part of it knowledge a future agent \
180
+ could use. This repo keeps that knowledge in a notebook: notes are searched and served to \
181
+ future cold agents when their task matches.
136
182
 
137
183
  DECIDE FIRST — as the agent who worked on this task, you know its exact intent:
138
184
  1. So you, not any rule, are best suited to judge whether this work was about the code in \
@@ -150,13 +196,15 @@ changed and what you had to understand to change it, and that is precisely the k
150
196
  cold agent lacks. The default for an edited file is a note. Walk the worklist top to bottom \
151
197
  and decide each one explicitly; do not stop at the first two or three. If you end up writing \
152
198
  notes for well under half the [edited] files, you have under-captured — say which files you \
153
- skipped and why, so the decision is visible instead of silent. Each \`kb write\` prints the \
154
- running count ("N of M worklist files noted") and lists what is still unwritten — read that \
155
- line back before you finish; it is the only place your own coverage is visible to you.
199
+ skipped and why, so the decision is visible instead of silent. These instructions are \
200
+ permanent at \`.coldstart/notebook/.capture-instructions.md\`; today's worklist is at \
201
+ \`.coldstart/notebook/.worklist-{{SID}}-{{AID}}.md\` re-Read whichever scrolls out of context \
202
+ this session. Your \`kb write\` call ends with a coverage line naming any worked file still \
203
+ without a note; read it back before you finish.
156
204
 
157
205
  WORKLIST — files you actually read this session, most-worked first:
158
206
 
159
- ${worklistLines(entries)}
207
+ {{WORKLIST}}
160
208
 
161
209
  FOR EACH NOTE:
162
210
  4. Say only what you verified in THIS file, this session. A confident whole-file claim from \
@@ -210,7 +258,11 @@ missing fact is a NEW flow, even in the same subsystem, even across the same fil
210
258
  an unrelated fact into a nearby flow buries it: nobody searching for your fact will find that \
211
259
  title.
212
260
 
213
- WRITE — one Bash block total: specs as heredocs, writes chained with &&.
261
+ WRITE — ONE call: put EVERY note as an object in a JSON array and write the array \
262
+ in a single \`kb write\`. Order flows before the file notes that reference them. Malformed \
263
+ notes are reported together (a bad note never silences a good one), and the call ends with \
264
+ the coverage line. Forming an array is fewer tokens than chaining, not more — same JSON, \
265
+ without the per-note heredoc and && glue.
214
266
  ${shapesBlock({ compact: true })}
215
267
  "identityAliases" and "symbols" are what make a note FINDABLE and both go missing by \
216
268
  default: a note without identityAliases is reachable only by its exact title, and agents \
@@ -227,15 +279,107 @@ however carefully you described it. Never write a flow using the file-note shape
227
279
  with several of its symbols. file-hub is ONLY for grab-bag files that have no single purpose \
228
280
  (models.py, utils, helpers) — there, knowledge lives per symbol. Touching many symbols does \
229
281
  not make a file a hub; having no one purpose does.
230
- Update = the same spec plus "id":"<id from the worklist>".
231
- node ${cli} kb write /tmp/spec1.json --root ${root} --session ${sid} --force
232
- Flow/lesson shapes: run \`node ${cli} kb write --root ${root}\` with no spec — it prints the full guide.
282
+ Update = the same spec plus "id":"<id from the worklist>". Retract a note you \
283
+ found wrong: {"op":"retract","id":"<id>","target":{"kind":"note"}} (as one array element).
284
+ cat > /tmp/notes.json <<'JSON'
285
+ [ {…note 1…}, {…note 2…} ]
286
+ JSON
287
+ node {{CLI}} kb write /tmp/notes.json --root {{ROOT}} --session {{SID}} --agent {{AID}} --force
288
+ Full shapes: run \`node {{CLI}} kb write --root {{ROOT}}\` with no spec — it prints the guide.
289
+ (Keep --session/--agent exactly as written — they point coverage at THIS agent's worklist.)
233
290
 
234
291
  FLOW DECISION — record what you decided about FLOWS (created a new one, folded into an \
235
- existing one, or none) so the flow gate can be measured. Ride it on your LAST kb write — it \
292
+ existing one, or none) so the flow gate can be measured. Ride it on the SAME batch write — it \
236
293
  is a flag, not a second command:
237
- node ${cli} kb write /tmp/specN.json --root ${root} --session ${sid} --force \\
294
+ node {{CLI}} kb write /tmp/notes.json --root {{ROOT}} --session {{SID}} --agent {{AID}} --force \\
238
295
  --decision <none|new|update> [--id <flow id>] --why "<one clause>"
239
296
  Only when you wrote NO notes at all is there no write to carry it, and then run it alone:
240
- node ${cli} kb flow-decision --decision none --why "<one clause>" --root ${root} --session ${sid}${tail}`;
297
+ node {{CLI}} kb flow-decision --decision none --why "<one clause>" --root {{ROOT}} --session {{SID}}`;
298
+ }
299
+
300
+ /** Ensure the permanent instructions file exists and is current; return its
301
+ * body (without the version-tag line). Best-effort — a write failure still
302
+ * returns the shipped text so THIS fire's payload is unaffected; only the
303
+ * on-disk persistence for later re-Reads is at risk. */
304
+ function ensureCaptureInstructions(root) {
305
+ const p = captureInstructionsPath(root);
306
+ try {
307
+ const existing = readFileSync(p, "utf8");
308
+ if (existing.startsWith(INSTRUCTIONS_VERSION_TAG)) {
309
+ return existing.slice(existing.indexOf("\n") + 1);
310
+ }
311
+ } catch { /* missing — write below */ }
312
+ const text = shippedInstructionsTemplate();
313
+ try {
314
+ mkdirSync(join(root, ".coldstart", "notebook"), { recursive: true });
315
+ writeFileSync(p, text);
316
+ } catch { /* best-effort; still usable in-memory this fire */ }
317
+ return text.slice(text.indexOf("\n") + 1);
318
+ }
319
+
320
+ /**
321
+ * worklist entry: { path, tier, retouches, notes: [{id, type, state}], noConsumers }
322
+ * tier: "edited ×N" | "read" | "skimmed"
323
+ */
324
+ function worklistLines(entries) {
325
+ const lines = [];
326
+ for (const e of entries) {
327
+ const ann = [];
328
+ ann.push(`[${e.tier}]`);
329
+ if (!e.notes?.length) {
330
+ ann.push("no note yet");
331
+ } else {
332
+ for (const n of e.notes) {
333
+ if (n.state === "fresh") {
334
+ ann.push(`note ${n.id} (fresh) → update ONLY if this session taught something the note lacks (.coldstart/notebook/notes/${n.id}.md)`);
335
+ } else if (n.state === "changed" || n.state === "missing") {
336
+ ann.push(`note ${n.id} (STALE) → fix or re-stamp; list the path in "verified" (.coldstart/notebook/notes/${n.id}.md)`);
337
+ } else {
338
+ ann.push(`note ${n.id} → read it first, update by its "id" (.coldstart/notebook/notes/${n.id}.md)`);
339
+ }
340
+ }
341
+ }
342
+ if (e.noConsumers) ann.push("no consumers in import graph");
343
+ lines.push(`- ${e.path} ${ann.join(" · ")}`);
344
+ }
345
+ return lines.join("\n");
346
+ }
347
+
348
+ export function buildCapturePayload(args) {
349
+ const payload = renderCapturePayload(args);
350
+ // Persist the structured scope (+ a small pointer .md — the static
351
+ // instructions live in the permanent .capture-instructions.md, not
352
+ // duplicated per session) so the agent can re-Read it later and `kb write`
353
+ // has coverage to check against. Best-effort; never blocks capture.
354
+ writeDurableWorklist(args.root, args.sid, args.aid, args.entries);
355
+ return payload;
356
+ }
357
+
358
+ function renderCapturePayload({ root, cli, sid, aid, entries, envelope }) {
359
+ aid = String(aid ?? "main").replace(/[^A-Za-z0-9_-]/g, "") || "main";
360
+ const opening = envelope === "block"
361
+ ? "Handle capture now, then stop."
362
+ : envelope === "manual"
363
+ ? "You invoked this capture yourself (/capture-notes) — handle it now, then carry on."
364
+ : "Handle capture first, then continue with the user's request.";
365
+
366
+ const tail = envelope === "subagent"
367
+ ? `\nOnce you have handled the notebook — whether you wrote notes or decided none were \
368
+ needed — remember you were spawned as a subagent. The coordinator that spawned you receives \
369
+ ONLY your final message, so your last message must repeat, in full, the result you produced \
370
+ for it — your findings, not the notebook decision.`
371
+ : "";
372
+
373
+ const worklist = worklistLines(entries);
374
+ const source = loadChecklistOverride(root) ?? ensureCaptureInstructions(root);
375
+ let body = source
376
+ .replaceAll("{{CLI}}", String(cli))
377
+ .replaceAll("{{ROOT}}", String(root))
378
+ .replaceAll("{{SID}}", String(sid))
379
+ .replaceAll("{{AID}}", String(aid));
380
+ body = body.includes("{{WORKLIST}}")
381
+ ? body.replaceAll("{{WORKLIST}}", worklist)
382
+ : `${body.trimEnd()}\n\nWORKLIST — files you actually read this session, most-worked first \
383
+ (your scope; if you edited or deep-read a file that isn't listed, you can note it too):\n\n${worklist}`;
384
+ return `**Notebook capture point.** ${opening}\n\n${body.trimEnd()}${tail}`;
241
385
  }
@@ -0,0 +1,4 @@
1
+ /** Types for capture-sentinel.mjs — plain ESM so the capture hooks can import
2
+ * it without a build step; this declaration is what lets the TypeScript side
3
+ * (src/init.ts) import the same file instead of copying the string. */
4
+ export declare const CAPTURE_SENTINEL: string;