peaks-loop-internal-runtime 0.0.39 → 0.0.41

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 (50) hide show
  1. package/dist/auto-compact-adapter.d.ts.map +1 -1
  2. package/dist/auto-compact-adapter.js +1 -1
  3. package/dist/dispatch.d.ts.map +1 -1
  4. package/dist/dispatch.js +25 -8
  5. package/dist/guards/json-object.d.ts +25 -0
  6. package/dist/guards/json-object.d.ts.map +1 -0
  7. package/dist/guards/json-object.js +26 -0
  8. package/dist/guards/resource-budget.d.ts.map +1 -1
  9. package/dist/index.d.ts +1 -1
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +1 -1
  12. package/dist/lifecycle.d.ts.map +1 -1
  13. package/dist/process-supervisor.js +2 -2
  14. package/dist/prompt-builder.js +3 -3
  15. package/dist/status-protocol.d.ts +39 -2
  16. package/dist/status-protocol.d.ts.map +1 -1
  17. package/dist/status-protocol.js +60 -9
  18. package/dist/vendor/claude-adapter.d.ts +1 -0
  19. package/dist/vendor/claude-adapter.d.ts.map +1 -1
  20. package/dist/vendor/claude-adapter.js +4 -19
  21. package/dist/vendor/codex-adapter.d.ts +1 -0
  22. package/dist/vendor/codex-adapter.d.ts.map +1 -1
  23. package/dist/vendor/codex-adapter.js +3 -9
  24. package/dist/vendor/copilot-adapter.d.ts +1 -0
  25. package/dist/vendor/copilot-adapter.d.ts.map +1 -1
  26. package/dist/vendor/copilot-adapter.js +6 -10
  27. package/dist/vendor/detect-binary.d.ts.map +1 -1
  28. package/dist/vendor/progress-line.d.ts +31 -0
  29. package/dist/vendor/progress-line.d.ts.map +1 -0
  30. package/dist/vendor/progress-line.js +85 -0
  31. package/dist/vendor/registry.d.ts.map +1 -1
  32. package/dist/vendor/registry.js +9 -3
  33. package/package.json +2 -2
  34. package/src/auto-compact-adapter.ts +13 -5
  35. package/src/dispatch.ts +49 -21
  36. package/src/guards/json-object.ts +26 -0
  37. package/src/guards/resource-budget.ts +11 -4
  38. package/src/index.ts +2 -2
  39. package/src/lifecycle.ts +11 -5
  40. package/src/process-supervisor.ts +4 -4
  41. package/src/prompt-builder.ts +4 -4
  42. package/src/status-protocol.ts +113 -14
  43. package/src/types.ts +1 -1
  44. package/src/vendor/adapter.ts +1 -1
  45. package/src/vendor/claude-adapter.ts +5 -16
  46. package/src/vendor/codex-adapter.ts +4 -6
  47. package/src/vendor/copilot-adapter.ts +7 -7
  48. package/src/vendor/detect-binary.ts +8 -3
  49. package/src/vendor/progress-line.ts +86 -0
  50. package/src/vendor/registry.ts +11 -4
@@ -1 +1 @@
1
- {"version":3,"file":"auto-compact-adapter.d.ts","sourceRoot":"","sources":["../src/auto-compact-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D;;;;;;;;;GASG;AACH,MAAM,WAAW,UAAU;IAAG,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAC;CAAE;AAChF,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IACzC,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CACvD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBAAa,kBAAkB;IAC7B,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM;IAuBhC,gBAAgB,CAAC,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAG/D"}
1
+ {"version":3,"file":"auto-compact-adapter.d.ts","sourceRoot":"","sources":["../src/auto-compact-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D;;;;;;;;;GASG;AACH,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AACD,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBAAa,kBAAkB;IAC7B,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM;IAwBhC,gBAAgB,CAAC,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAG/D"}
@@ -47,7 +47,7 @@ export class AutoCompactAdapter {
47
47
  `- 这些文件由你自己维护:不要等 peaks 主进程来催,它不会替你写。`,
48
48
  `- token 费用:peaks-loop 不设费用上限、也不因费用中断你(没有费用闸门)。`,
49
49
  ` 这不对应任何 flag —— 它是 peaks-loop 没有做的事,不是一条你能引用的授权。`,
50
- `</peaks-auto-compact>`,
50
+ `</peaks-auto-compact>`
51
51
  ].join('\n');
52
52
  }
53
53
  parseScratchFile(p) {
@@ -1 +1 @@
1
- {"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../src/dispatch.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAYvD,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,IAAI,GAAC,IAAI,GAAC,IAAI,GAAC,KAAK,GAAC,iBAAiB,CAAC;IACvE,MAAM,EAAE,QAAQ,GAAC,OAAO,GAAC,SAAS,CAAC;IACnC,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAC;IAClD,UAAU,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IACzC,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B;AACD,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,kBAAkB,EAAE,MAAM,CAAC;IAC3B,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB;;;;;OAKG;IACH,UAAU,EAAE,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC;CAC1C;AAED,wBAAsB,gBAAgB,CAAC,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC,CAqDhF"}
1
+ {"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../src/dispatch.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAUvD,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,KAAK,GAAG,iBAAiB,CAAC;IACrD,MAAM,EAAE,QAAQ,GAAG,OAAO,GAAG,SAAS,CAAC;IACvC,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B;AACD,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,kBAAkB,EAAE,MAAM,CAAC;IAC3B,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB;;;;;OAKG;IACH,UAAU,EAAE,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC;CAC1C;AAED,wBAAsB,gBAAgB,CAAC,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC,CAmDhF"}
package/dist/dispatch.js CHANGED
@@ -9,7 +9,11 @@ import { CopilotAdapter } from './vendor/copilot-adapter.js';
9
9
  import { PromptBuilder } from './prompt-builder.js';
10
10
  import { AutoCompactAdapter } from './auto-compact-adapter.js';
11
11
  export async function dispatchDetached(i) {
12
- const registry = new VendorAdapterRegistry([new ClaudeAdapter(), new CodexAdapter(), new CopilotAdapter()]);
12
+ const registry = new VendorAdapterRegistry([
13
+ new ClaudeAdapter(),
14
+ new CodexAdapter(),
15
+ new CopilotAdapter()
16
+ ]);
13
17
  const adapter = registry.get(i.vendor);
14
18
  if (!adapter)
15
19
  throw new Error(`vendor adapter not registered: ${i.vendor}`);
@@ -24,9 +28,13 @@ export async function dispatchDetached(i) {
24
28
  // than invented.
25
29
  const marker = ac.marker({ rid: i.rid, sid: i.sid });
26
30
  const prompt = pb.assemble({
27
- rid: i.rid, role: i.role, vendor: i.vendor,
28
- files: i.files, refs: i.refs, userTask: i.userTask,
29
- verbatimBlocks: [marker, ...(i.verbatimBlocks ?? [])],
31
+ rid: i.rid,
32
+ role: i.role,
33
+ vendor: i.vendor,
34
+ files: i.files,
35
+ refs: i.refs,
36
+ userTask: i.userTask,
37
+ verbatimBlocks: [marker, ...(i.verbatimBlocks ?? [])]
30
38
  });
31
39
  const args = adapter.headlessArgs(prompt, { autoCompactMarker: marker });
32
40
  const dir = join(i.runtimeDir, i.rid);
@@ -44,16 +52,25 @@ export async function dispatchDetached(i) {
44
52
  // an exception thrown from outside this function's promise chain.
45
53
  const spawnError = (await handle.settled) ?? null;
46
54
  lo.register(handle.pid, i.rid, i.sid);
55
+ const recPath = writeDispatchRecord(i, spawnError);
56
+ return { pid: handle.pid, dispatchRecordPath: recPath, child: handle.child, spawnError };
57
+ }
58
+ function writeDispatchRecord(i, spawnError) {
47
59
  // Write dispatch record (placeholder — final shape per Task 8 schema)
48
60
  const recPath = join(i.subAgentsDir, `dispatch-${i.rid}-${Date.now()}.json`);
49
61
  mkdirSync(i.subAgentsDir, { recursive: true });
50
62
  writeFileSync(recPath, JSON.stringify({
51
- rid: i.rid, mode: 'detached', vendor: i.vendor,
63
+ rid: i.rid,
64
+ mode: 'detached',
65
+ vendor: i.vendor,
52
66
  // The record must not claim a child is running when the launch failed —
53
67
  // that is the on-disk form of "looks green, checked nothing".
54
68
  status: spawnError ? 'failed' : 'running',
55
- ...(spawnError ? { spawnError: { code: spawnError.code, message: spawnError.message } } : {}),
56
- heartbeats: [], at: Date.now(),
69
+ ...(spawnError
70
+ ? { spawnError: { code: spawnError.code, message: spawnError.message } }
71
+ : {}),
72
+ heartbeats: [],
73
+ at: Date.now()
57
74
  }, null, 2));
58
- return { pid: handle.pid, dispatchRecordPath: recPath, child: handle.child, spawnError };
75
+ return recPath;
59
76
  }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * "This unknown value is a plain JSON object" — the one narrowing this package
3
+ * uses to open a value that came out of `JSON.parse`.
4
+ *
5
+ * WHY IT LIVES HERE RATHER THAN IN EACH READER (batch B2). Two readers in this
6
+ * package need to open a parsed value before they can check its fields:
7
+ * `src/status-protocol.ts` (a status record) and `src/vendor/progress-line.ts`
8
+ * (a progress line). The alternative to this function is not "no function" — it
9
+ * is `const rec: Record<string, unknown> = JSON.parse(raw)`, which is a CAST:
10
+ * it asserts the shape instead of checking it, and because `JSON.parse` returns
11
+ * `any` the assertion is invisible to the TS lint ratchet. So the check is
12
+ * written out once, at the boundary, and both readers call it.
13
+ *
14
+ * The three clauses are each load-bearing:
15
+ * - `typeof value === 'object'` rejects strings, numbers, booleans, bigints,
16
+ * symbols, undefined and functions in one go;
17
+ * - `value !== null` — `typeof null` is the famous `'object'`;
18
+ * - `!Array.isArray(value)` — an array IS a JSON value, and this predicate is
19
+ * a named narrowing (NOT the repo's non-narrowing `src/shared/array-guards.ts`
20
+ * `isArray`, which this package cannot import and whose job is the opposite
21
+ * one). An array has no named fields, so treating one as an object would
22
+ * hand every field read `undefined`.
23
+ */
24
+ export declare function isJsonObject(value: unknown): value is Record<string, unknown>;
25
+ //# sourceMappingURL=json-object.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-object.d.ts","sourceRoot":"","sources":["../../src/guards/json-object.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAE7E"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * "This unknown value is a plain JSON object" — the one narrowing this package
3
+ * uses to open a value that came out of `JSON.parse`.
4
+ *
5
+ * WHY IT LIVES HERE RATHER THAN IN EACH READER (batch B2). Two readers in this
6
+ * package need to open a parsed value before they can check its fields:
7
+ * `src/status-protocol.ts` (a status record) and `src/vendor/progress-line.ts`
8
+ * (a progress line). The alternative to this function is not "no function" — it
9
+ * is `const rec: Record<string, unknown> = JSON.parse(raw)`, which is a CAST:
10
+ * it asserts the shape instead of checking it, and because `JSON.parse` returns
11
+ * `any` the assertion is invisible to the TS lint ratchet. So the check is
12
+ * written out once, at the boundary, and both readers call it.
13
+ *
14
+ * The three clauses are each load-bearing:
15
+ * - `typeof value === 'object'` rejects strings, numbers, booleans, bigints,
16
+ * symbols, undefined and functions in one go;
17
+ * - `value !== null` — `typeof null` is the famous `'object'`;
18
+ * - `!Array.isArray(value)` — an array IS a JSON value, and this predicate is
19
+ * a named narrowing (NOT the repo's non-narrowing `src/shared/array-guards.ts`
20
+ * `isArray`, which this package cannot import and whose job is the opposite
21
+ * one). An array has no named fields, so treating one as an object would
22
+ * hand every field read `undefined`.
23
+ */
24
+ export function isJsonObject(value) {
25
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
26
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"resource-budget.d.ts","sourceRoot":"","sources":["../../src/guards/resource-budget.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,MAAM;IAAG,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;CAAE;AAC1D,MAAM,WAAW,YAAY;IAAG,MAAM,EAAE,MAAM,CAAC;CAAE;AACjD,MAAM,WAAW,WAAW;IAAG,aAAa,EAAE,MAAM,CAAC;CAAE;AAEvD,qBAAa,mBAAmB;IAClB,OAAO,CAAC,QAAQ,CAAC,GAAG;gBAAH,GAAG,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE;IAEzE,MAAM,IAAI,MAAM;IAQhB,OAAO,CAAC,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,WAAW,GAAG;QAAE,QAAQ,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE;CAIxF"}
1
+ {"version":3,"file":"resource-budget.d.ts","sourceRoot":"","sources":["../../src/guards/resource-budget.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AACD,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;CAChB;AACD,MAAM,WAAW,WAAW;IAC1B,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,qBAAa,mBAAmB;IAClB,OAAO,CAAC,QAAQ,CAAC,GAAG;gBAAH,GAAG,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE;IAEzE,MAAM,IAAI,MAAM;IAQhB,OAAO,CAAC,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,WAAW,GAAG;QAAE,QAAQ,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE;CAIxF"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const RUNTIME_VERSION = "4.0.54";
1
+ export declare const RUNTIME_VERSION = "4.1.1";
2
2
  export declare const RUNTIME_NPM_VERSION = "0.0.21";
3
3
  export { ClaudeAdapter } from './vendor/claude-adapter.js';
4
4
  export { CodexAdapter } from './vendor/codex-adapter.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,eAAe,WAAW,CAAC;AAMxC,eAAO,MAAM,mBAAmB,WAAW,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC9E,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,YAAY,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,eAAe,UAAU,CAAC;AAMvC,eAAO,MAAM,mBAAmB,WAAW,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC9E,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,YAAY,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC"}
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // API contract: RUNTIME_VERSION tracks peaks-loop root version (4.0.x).
2
2
  // This is what consumers (sub-agents dispatched by peaks-code) check at
3
3
  // runtime to verify protocol compatibility.
4
- export const RUNTIME_VERSION = '4.0.54';
4
+ export const RUNTIME_VERSION = '4.1.1';
5
5
  // npm version: independent 0.0.x SemVer. Runtime is its own package
6
6
  // (peaks-loop-internal-runtime@NPM_VERSION) on the registry; bumps
7
7
  // per peaks release notes when its public surface actually changes
@@ -1 +1 @@
1
- {"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../src/lifecycle.ts"],"names":[],"mappings":"AAKA,qBAAa,cAAc;IAGb,OAAO,CAAC,QAAQ,CAAC,UAAU;IAFvC,OAAO,CAAC,MAAM,CAAmC;gBAEpB,UAAU,EAAE,MAAM;IAE/C,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI;IAIxD,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBnE,IAAI,CAAC,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAOxD"}
1
+ {"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../src/lifecycle.ts"],"names":[],"mappings":"AASA,qBAAa,cAAc;IAGb,OAAO,CAAC,QAAQ,CAAC,UAAU;IAFvC,OAAO,CAAC,MAAM,CAAmC;gBAEpB,UAAU,EAAE,MAAM;IAE/C,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI;IAIxD,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAoBnE,IAAI,CAAC,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAOxD"}
@@ -17,7 +17,7 @@ export class ProcessSupervisor {
17
17
  // pipes for capture + lifecycle control.
18
18
  const spawnOpts = {
19
19
  detached: false,
20
- stdio: opts.stdio ?? 'pipe',
20
+ stdio: opts.stdio ?? 'pipe'
21
21
  };
22
22
  if (isWin) {
23
23
  // Suppress the popup console window on Windows without changing
@@ -64,7 +64,7 @@ export class ProcessSupervisor {
64
64
  pid: child.pid ?? -1,
65
65
  child,
66
66
  kill: (signal = 'SIGTERM') => child.kill(signal),
67
- settled,
67
+ settled
68
68
  };
69
69
  }
70
70
  }
@@ -12,12 +12,12 @@ export class PromptBuilder {
12
12
  i.userTask,
13
13
  ``,
14
14
  `## Files (read-only)`,
15
- ...i.files.map(f => `- ${f}`),
15
+ ...i.files.map((f) => `- ${f}`),
16
16
  ``,
17
17
  `## References`,
18
- ...i.refs.map(r => `- ${r}`),
18
+ ...i.refs.map((r) => `- ${r}`),
19
19
  ``,
20
- ...(i.verbatimBlocks ?? []),
20
+ ...(i.verbatimBlocks ?? [])
21
21
  ];
22
22
  const out = parts.join('\n');
23
23
  if (out.includes(FORBIDDEN))
@@ -11,9 +11,46 @@ export interface AutoCompactEvent {
11
11
  tokensAfter: number;
12
12
  scratchFile?: string;
13
13
  }
14
+ /**
15
+ * A status record as it comes off disk: an OPEN JSON object.
16
+ *
17
+ * WHY NOT `heartbeats?: HeartbeatEntry[]` — the honest reason, because the two
18
+ * look equivalent and are not. The record arrives from `JSON.parse`, which
19
+ * hands back `any`; nothing between the disk and this class has checked that
20
+ * `heartbeats` is an array, or that its elements are heartbeat entries. Writing
21
+ * `heartbeats?: HeartbeatEntry[]` on the interface would therefore be a CLAIM
22
+ * about a shape nobody verified — the same offence as `as`, only harder to
23
+ * see, because it reads as a type rather than a cast.
24
+ *
25
+ * So the record is declared as what it really is (an object with unknown
26
+ * values) and the two arrays this class appends to are READ through
27
+ * `readHeartbeats` / `readCompactEvents`, which check and drop. That is why
28
+ * those readers return the concrete types below rather than the field being
29
+ * declared pre-typed.
30
+ */
31
+ export interface StatusRecord {
32
+ [key: string]: unknown;
33
+ }
34
+ /** What `merge` returns: the record it was given, plus the fields it wrote. */
35
+ export type MergedStatusRecord = StatusRecord & {
36
+ heartbeats: HeartbeatEntry[];
37
+ /** Written only when the 100-entry cap actually fired (see `merge`). */
38
+ heartbeatsTruncated?: boolean;
39
+ status: string;
40
+ };
41
+ /** What `appendCompactEvent` returns: the record, plus the event it appended. */
42
+ export type CompactedStatusRecord = StatusRecord & {
43
+ autoCompactEvents: AutoCompactEvent[];
44
+ };
14
45
  export declare class StatusProtocol {
15
- merge(rec: any, s: ChildStatus): any;
46
+ /**
47
+ * Append one heartbeat and refresh `status`. Every other key the record
48
+ * carried is preserved; `heartbeats` is capped at the last 100 and
49
+ * `heartbeatsTruncated` is written only when that cap fired.
50
+ */
51
+ merge(rec: StatusRecord, s: ChildStatus): MergedStatusRecord;
16
52
  isStale(lastBeatAt: number, thresholdSec?: number): boolean;
17
- appendCompactEvent(rec: any, ev: AutoCompactEvent): any;
53
+ /** Append one compact event, preserving every other key on the record. */
54
+ appendCompactEvent(rec: StatusRecord, ev: AutoCompactEvent): CompactedStatusRecord;
18
55
  }
19
56
  //# sourceMappingURL=status-protocol.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"status-protocol.d.ts","sourceRoot":"","sources":["../src/status-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,WAAW,cAAc;IAAG,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;CAAE;AAC/E,MAAM,WAAW,gBAAgB;IAAG,EAAE,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAAE;AAE9I,qBAAa,cAAc;IACzB,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,WAAW,GAAG,GAAG;IAUpC,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,YAAY,SAAM,GAAG,OAAO;IAGxD,kBAAkB,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,gBAAgB,GAAG,GAAG;CAGxD"}
1
+ {"version":3,"file":"status-protocol.d.ts","sourceRoot":"","sources":["../src/status-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAG9C,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;CACZ;AACD,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,YAAY;IAC3B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,+EAA+E;AAC/E,MAAM,MAAM,kBAAkB,GAAG,YAAY,GAAG;IAC9C,UAAU,EAAE,cAAc,EAAE,CAAC;IAC7B,wEAAwE;IACxE,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,iFAAiF;AACjF,MAAM,MAAM,qBAAqB,GAAG,YAAY,GAAG;IACjD,iBAAiB,EAAE,gBAAgB,EAAE,CAAC;CACvC,CAAC;AAkDF,qBAAa,cAAc;IACzB;;;;OAIG;IACH,KAAK,CAAC,GAAG,EAAE,YAAY,EAAE,CAAC,EAAE,WAAW,GAAG,kBAAkB;IAU5D,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,YAAY,SAAM,GAAG,OAAO;IAGxD,0EAA0E;IAC1E,kBAAkB,CAAC,GAAG,EAAE,YAAY,EAAE,EAAE,EAAE,gBAAgB,GAAG,qBAAqB;CAGnF"}
@@ -1,18 +1,69 @@
1
+ import { isJsonObject } from './guards/json-object.js';
2
+ function isHeartbeatEntry(value) {
3
+ return (isJsonObject(value) &&
4
+ typeof value['progress'] === 'number' &&
5
+ typeof value['note'] === 'string' &&
6
+ typeof value['ts'] === 'number');
7
+ }
8
+ function isCompactEvent(value) {
9
+ return (isJsonObject(value) &&
10
+ typeof value['at'] === 'number' &&
11
+ (value['threshold'] === '0.85' || value['threshold'] === '0.95') &&
12
+ typeof value['tokensBefore'] === 'number' &&
13
+ typeof value['tokensAfter'] === 'number' &&
14
+ (value['scratchFile'] === undefined || typeof value['scratchFile'] === 'string'));
15
+ }
16
+ /**
17
+ * The heartbeat entries carried by `rec`, in order, with anything that is not a
18
+ * heartbeat entry dropped. `rec.heartbeats` being absent, a non-array, or an
19
+ * array of junk all read as "no heartbeats yet" — the same outcome the old
20
+ * `rec.heartbeats ?? []` produced for the absent case, extended to the cases it
21
+ * silently spread into a malformed array.
22
+ */
23
+ function readHeartbeats(rec) {
24
+ const raw = rec['heartbeats'];
25
+ if (!Array.isArray(raw))
26
+ return [];
27
+ const out = [];
28
+ for (const item of raw) {
29
+ if (isHeartbeatEntry(item))
30
+ out.push(item);
31
+ }
32
+ return out;
33
+ }
34
+ /** The compact events carried by `rec`. Same contract as `readHeartbeats`. */
35
+ function readCompactEvents(rec) {
36
+ const raw = rec['autoCompactEvents'];
37
+ if (!Array.isArray(raw))
38
+ return [];
39
+ const out = [];
40
+ for (const item of raw) {
41
+ if (isCompactEvent(item))
42
+ out.push(item);
43
+ }
44
+ return out;
45
+ }
1
46
  export class StatusProtocol {
47
+ /**
48
+ * Append one heartbeat and refresh `status`. Every other key the record
49
+ * carried is preserved; `heartbeats` is capped at the last 100 and
50
+ * `heartbeatsTruncated` is written only when that cap fired.
51
+ */
2
52
  merge(rec, s) {
3
- const next = { ...rec };
4
- next.heartbeats = [...(rec.heartbeats ?? []), { progress: s.progress, note: s.note, ts: s.ts }];
5
- if (next.heartbeats.length > 100) {
6
- next.heartbeats = next.heartbeats.slice(-100);
7
- next.heartbeatsTruncated = true;
8
- }
9
- next.status = s.state === 'running' ? 'running' : s.state;
10
- return next;
53
+ const appended = [...readHeartbeats(rec), { progress: s.progress, note: s.note, ts: s.ts }];
54
+ const truncated = appended.length > 100;
55
+ return {
56
+ ...rec,
57
+ heartbeats: truncated ? appended.slice(-100) : appended,
58
+ ...(truncated ? { heartbeatsTruncated: true } : {}),
59
+ status: s.state === 'running' ? 'running' : s.state
60
+ };
11
61
  }
12
62
  isStale(lastBeatAt, thresholdSec = 300) {
13
63
  return Date.now() - lastBeatAt > thresholdSec * 1000;
14
64
  }
65
+ /** Append one compact event, preserving every other key on the record. */
15
66
  appendCompactEvent(rec, ev) {
16
- return { ...rec, autoCompactEvents: [...(rec.autoCompactEvents ?? []), ev] };
67
+ return { ...rec, autoCompactEvents: [...readCompactEvents(rec), ev] };
17
68
  }
18
69
  }
@@ -7,6 +7,7 @@ export declare class ClaudeAdapter implements VendorAdapter {
7
7
  headlessArgs(prompt: string, opts?: {
8
8
  autoCompactMarker?: string;
9
9
  }): string[];
10
+ /** The line format is shared with the other two vendors — see `progress-line.ts`. */
10
11
  parseStatusLine(stdout: string): ChildStatus | null;
11
12
  detectInstalled(): Promise<boolean>;
12
13
  }
@@ -1 +1 @@
1
- {"version":3,"file":"claude-adapter.d.ts","sourceRoot":"","sources":["../../src/vendor/claude-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C,qBAAa,aAAc,YAAW,aAAa;IACjD,QAAQ,CAAC,EAAE,EAAG,QAAQ,CAAU;IAChC,QAAQ,CAAC,MAAM,YAAY;IAC3B,QAAQ,CAAC,cAAc,SAAY;IAEnC,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,iBAAiB,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,EAAE;IAO7E,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI;IAe7C,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC;CAG1C"}
1
+ {"version":3,"file":"claude-adapter.d.ts","sourceRoot":"","sources":["../../src/vendor/claude-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAI/C,qBAAa,aAAc,YAAW,aAAa;IACjD,QAAQ,CAAC,EAAE,EAAG,QAAQ,CAAU;IAChC,QAAQ,CAAC,MAAM,YAAY;IAC3B,QAAQ,CAAC,cAAc,SAAY;IAEnC,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,iBAAiB,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,EAAE;IAK7E,qFAAqF;IACrF,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI;IAI7C,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC;CAG1C"}
@@ -1,31 +1,16 @@
1
1
  import { detectBinaryInstalled } from './detect-binary.js';
2
+ import { parseProgressLine } from './progress-line.js';
2
3
  export class ClaudeAdapter {
3
4
  id = 'claude';
4
5
  binary = 'claude';
5
6
  maxPromptBytes = 8 * 1024;
6
7
  headlessArgs(prompt, opts) {
7
- const injected = opts?.autoCompactMarker
8
- ? `${opts.autoCompactMarker}\n\n${prompt}`
9
- : prompt;
8
+ const injected = opts?.autoCompactMarker ? `${opts.autoCompactMarker}\n\n${prompt}` : prompt;
10
9
  return ['-p', injected, '--output-format', 'json', '--include-partial-messages'];
11
10
  }
11
+ /** The line format is shared with the other two vendors — see `progress-line.ts`. */
12
12
  parseStatusLine(stdout) {
13
- try {
14
- const obj = JSON.parse(stdout);
15
- if (typeof obj.progress !== 'number')
16
- return null;
17
- return {
18
- rid: String(obj.rid ?? ''),
19
- vendor: 'claude',
20
- progress: obj.progress,
21
- state: obj.state,
22
- note: String(obj.note ?? ''),
23
- ts: Number(obj.ts ?? Date.now()),
24
- };
25
- }
26
- catch {
27
- return null;
28
- }
13
+ return parseProgressLine(stdout, 'claude');
29
14
  }
30
15
  async detectInstalled() {
31
16
  return detectBinaryInstalled(this.binary);
@@ -5,6 +5,7 @@ export declare class CodexAdapter implements VendorAdapter {
5
5
  readonly binary = "codex";
6
6
  readonly maxPromptBytes: number;
7
7
  headlessArgs(prompt: string): string[];
8
+ /** The line format is shared with the other two vendors — see `progress-line.ts`. */
8
9
  parseStatusLine(stdout: string): ChildStatus | null;
9
10
  detectInstalled(): Promise<boolean>;
10
11
  }
@@ -1 +1 @@
1
- {"version":3,"file":"codex-adapter.d.ts","sourceRoot":"","sources":["../../src/vendor/codex-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C,qBAAa,YAAa,YAAW,aAAa;IAChD,QAAQ,CAAC,EAAE,EAAG,OAAO,CAAU;IAC/B,QAAQ,CAAC,MAAM,WAAW;IAC1B,QAAQ,CAAC,cAAc,SAAY;IACnC,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE;IAGtC,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI;IAO7C,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC;CAG1C"}
1
+ {"version":3,"file":"codex-adapter.d.ts","sourceRoot":"","sources":["../../src/vendor/codex-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAI/C,qBAAa,YAAa,YAAW,aAAa;IAChD,QAAQ,CAAC,EAAE,EAAG,OAAO,CAAU;IAC/B,QAAQ,CAAC,MAAM,WAAW;IAC1B,QAAQ,CAAC,cAAc,SAAY;IACnC,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE;IAGtC,qFAAqF;IACrF,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI;IAG7C,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC;CAG1C"}
@@ -1,4 +1,5 @@
1
1
  import { detectBinaryInstalled } from './detect-binary.js';
2
+ import { parseProgressLine } from './progress-line.js';
2
3
  export class CodexAdapter {
3
4
  id = 'codex';
4
5
  binary = 'codex';
@@ -6,16 +7,9 @@ export class CodexAdapter {
6
7
  headlessArgs(prompt) {
7
8
  return ['exec', '--json', prompt];
8
9
  }
10
+ /** The line format is shared with the other two vendors — see `progress-line.ts`. */
9
11
  parseStatusLine(stdout) {
10
- try {
11
- const o = JSON.parse(stdout);
12
- if (typeof o.progress !== 'number')
13
- return null;
14
- return { rid: String(o.rid ?? ''), vendor: 'codex', progress: o.progress, state: o.state, note: String(o.note ?? ''), ts: Number(o.ts ?? Date.now()) };
15
- }
16
- catch {
17
- return null;
18
- }
12
+ return parseProgressLine(stdout, 'codex');
19
13
  }
20
14
  async detectInstalled() {
21
15
  return detectBinaryInstalled(this.binary);
@@ -5,6 +5,7 @@ export declare class CopilotAdapter implements VendorAdapter {
5
5
  readonly binary = "copilot";
6
6
  readonly maxPromptBytes: number;
7
7
  headlessArgs(prompt: string): string[];
8
+ /** The line format is shared with the other two vendors — see `progress-line.ts`. */
8
9
  parseStatusLine(stdout: string): ChildStatus | null;
9
10
  detectInstalled(): Promise<boolean>;
10
11
  }
@@ -1 +1 @@
1
- {"version":3,"file":"copilot-adapter.d.ts","sourceRoot":"","sources":["../../src/vendor/copilot-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C,qBAAa,cAAe,YAAW,aAAa;IAClD,QAAQ,CAAC,EAAE,EAAG,SAAS,CAAU;IACjC,QAAQ,CAAC,MAAM,aAAa;IAC5B,QAAQ,CAAC,cAAc,SAAY;IACnC,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE;IACtC,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI;IAO7C,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC;CAG1C"}
1
+ {"version":3,"file":"copilot-adapter.d.ts","sourceRoot":"","sources":["../../src/vendor/copilot-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAI/C,qBAAa,cAAe,YAAW,aAAa;IAClD,QAAQ,CAAC,EAAE,EAAG,SAAS,CAAU;IACjC,QAAQ,CAAC,MAAM,aAAa;IAC5B,QAAQ,CAAC,cAAc,SAAY;IACnC,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE;IAGtC,qFAAqF;IACrF,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI;IAG7C,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC;CAG1C"}
@@ -1,19 +1,15 @@
1
1
  import { detectBinaryInstalled } from './detect-binary.js';
2
+ import { parseProgressLine } from './progress-line.js';
2
3
  export class CopilotAdapter {
3
4
  id = 'copilot';
4
5
  binary = 'copilot';
5
6
  maxPromptBytes = 6 * 1024;
6
- headlessArgs(prompt) { return ['-p', prompt, '--output-format', 'json']; }
7
+ headlessArgs(prompt) {
8
+ return ['-p', prompt, '--output-format', 'json'];
9
+ }
10
+ /** The line format is shared with the other two vendors — see `progress-line.ts`. */
7
11
  parseStatusLine(stdout) {
8
- try {
9
- const o = JSON.parse(stdout);
10
- if (typeof o.progress !== 'number')
11
- return null;
12
- return { rid: String(o.rid ?? ''), vendor: 'copilot', progress: o.progress, state: o.state, note: String(o.note ?? ''), ts: Number(o.ts ?? Date.now()) };
13
- }
14
- catch {
15
- return null;
16
- }
12
+ return parseProgressLine(stdout, 'copilot');
17
13
  }
18
14
  async detectInstalled() {
19
15
  return detectBinaryInstalled(this.binary);
@@ -1 +1 @@
1
- {"version":3,"file":"detect-binary.d.ts","sourceRoot":"","sources":["../../src/vendor/detect-binary.ts"],"names":[],"mappings":"AAIA,oFAAoF;AACpF,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAQtE"}
1
+ {"version":3,"file":"detect-binary.d.ts","sourceRoot":"","sources":["../../src/vendor/detect-binary.ts"],"names":[],"mappings":"AAIA,oFAAoF;AACpF,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAatE"}
@@ -0,0 +1,31 @@
1
+ import type { ChildStatus, VendorId } from '../types.js';
2
+ /**
3
+ * Parse one progress line from a vendor's `--output-format json` stream into a
4
+ * `ChildStatus`, or `null` when the text is not one.
5
+ *
6
+ * WHY THIS EXISTS (batch B2). The three vendor adapters carried this body
7
+ * verbatim, and every field of it went straight from `JSON.parse`'s `any` into
8
+ * a `ChildStatus` — `state` included, which is a six-member union the old code
9
+ * assigned to without checking anything:
10
+ *
11
+ * const o = JSON.parse(stdout); // any
12
+ * state: o.state, // any -> 'running' | 'stale' | …
13
+ *
14
+ * That reads as typed and validates nothing, and because `JSON.parse` returns
15
+ * `any`, no compiler complaint was possible. Here each field is checked, and a
16
+ * line that fails is `null` — the outcome the adapters already produced for
17
+ * unparseable text or a missing numeric `progress`.
18
+ *
19
+ * ONE BEHAVIOUR CHANGE, STATED PLAINLY: a line whose `state` is not one of the
20
+ * six now reads as `null` instead of as a `ChildStatus` whose `state` violates
21
+ * its own type. There is no honest default to substitute — inventing one (say
22
+ * `'running'`) would keep the lie and make it harder to see. Nothing in `src/`
23
+ * or `src/cli/` calls `parseStatusLine`; the only readers are each adapter's own
24
+ * unit test, and all three use `state: 'running'`.
25
+ *
26
+ * The `rid` / `note` / `ts` fallbacks preserve the old coercions exactly
27
+ * (`String(x ?? '')`, `Number(x ?? Date.now())`), so a line that used to parse
28
+ * still yields the same record.
29
+ */
30
+ export declare function parseProgressLine(stdout: string, vendor: VendorId): ChildStatus | null;
31
+ //# sourceMappingURL=progress-line.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"progress-line.d.ts","sourceRoot":"","sources":["../../src/vendor/progress-line.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAkCzD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,GAAG,WAAW,GAAG,IAAI,CAuBtF"}
@@ -0,0 +1,85 @@
1
+ import { isJsonObject } from '../guards/json-object.js';
2
+ /** The states `ChildStatus.state` allows — the set the reader below checks. */
3
+ const CHILD_STATES = [
4
+ 'running',
5
+ 'stale',
6
+ 'crashed',
7
+ 'oom-killed',
8
+ 'done',
9
+ 'spawn-failed'
10
+ ];
11
+ function isChildState(value) {
12
+ if (typeof value !== 'string')
13
+ return false;
14
+ return CHILD_STATES.some((state) => state === value);
15
+ }
16
+ /**
17
+ * The old `String(x ?? '')` for the JSON scalars a status line carries, and `''`
18
+ * for everything else. A non-scalar used to stringify to `'[object Object]'`
19
+ * (or throw on a symbol) — `no-base-to-string` rejects that, and no caller
20
+ * wants it. Scalars keep the exact old result, so a line that parsed before
21
+ * still yields the same `rid` / `note`.
22
+ */
23
+ function asText(value) {
24
+ if (value === null || value === undefined)
25
+ return '';
26
+ if (typeof value === 'string')
27
+ return value;
28
+ if (typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint') {
29
+ return String(value);
30
+ }
31
+ return '';
32
+ }
33
+ /**
34
+ * Parse one progress line from a vendor's `--output-format json` stream into a
35
+ * `ChildStatus`, or `null` when the text is not one.
36
+ *
37
+ * WHY THIS EXISTS (batch B2). The three vendor adapters carried this body
38
+ * verbatim, and every field of it went straight from `JSON.parse`'s `any` into
39
+ * a `ChildStatus` — `state` included, which is a six-member union the old code
40
+ * assigned to without checking anything:
41
+ *
42
+ * const o = JSON.parse(stdout); // any
43
+ * state: o.state, // any -> 'running' | 'stale' | …
44
+ *
45
+ * That reads as typed and validates nothing, and because `JSON.parse` returns
46
+ * `any`, no compiler complaint was possible. Here each field is checked, and a
47
+ * line that fails is `null` — the outcome the adapters already produced for
48
+ * unparseable text or a missing numeric `progress`.
49
+ *
50
+ * ONE BEHAVIOUR CHANGE, STATED PLAINLY: a line whose `state` is not one of the
51
+ * six now reads as `null` instead of as a `ChildStatus` whose `state` violates
52
+ * its own type. There is no honest default to substitute — inventing one (say
53
+ * `'running'`) would keep the lie and make it harder to see. Nothing in `src/`
54
+ * or `src/cli/` calls `parseStatusLine`; the only readers are each adapter's own
55
+ * unit test, and all three use `state: 'running'`.
56
+ *
57
+ * The `rid` / `note` / `ts` fallbacks preserve the old coercions exactly
58
+ * (`String(x ?? '')`, `Number(x ?? Date.now())`), so a line that used to parse
59
+ * still yields the same record.
60
+ */
61
+ export function parseProgressLine(stdout, vendor) {
62
+ let parsed;
63
+ try {
64
+ parsed = JSON.parse(stdout);
65
+ }
66
+ catch {
67
+ return null;
68
+ }
69
+ if (!isJsonObject(parsed))
70
+ return null;
71
+ const progress = parsed['progress'];
72
+ if (typeof progress !== 'number')
73
+ return null;
74
+ const state = parsed['state'];
75
+ if (!isChildState(state))
76
+ return null;
77
+ return {
78
+ rid: asText(parsed['rid']),
79
+ vendor,
80
+ progress,
81
+ state,
82
+ note: asText(parsed['note']),
83
+ ts: Number(parsed['ts'] ?? Date.now())
84
+ };
85
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/vendor/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAKlD,qBAAa,qBAAqB;IAChC,OAAO,CAAC,GAAG,CAAoC;gBACnC,OAAO,GAAE,aAAa,EAAO;IAGzC,QAAQ,CAAC,CAAC,EAAE,aAAa,GAAG,IAAI;IAChC,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS;IAC1C,IAAI,IAAI,aAAa,EAAE;CACxB;AAED,eAAO,MAAM,eAAe,6BAAmG,CAAC"}
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/vendor/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAKlD,qBAAa,qBAAqB;IAChC,OAAO,CAAC,GAAG,CAAoC;gBACnC,OAAO,GAAE,aAAa,EAAO;IAGzC,QAAQ,CAAC,CAAC,EAAE,aAAa,GAAG,IAAI;IAGhC,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS;IAG1C,IAAI,IAAI,aAAa,EAAE;CAGxB;AAED,eAAO,MAAM,eAAe,6BACgE,CAAC"}