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.
- package/dist/auto-compact-adapter.d.ts.map +1 -1
- package/dist/auto-compact-adapter.js +1 -1
- package/dist/dispatch.d.ts.map +1 -1
- package/dist/dispatch.js +25 -8
- package/dist/guards/json-object.d.ts +25 -0
- package/dist/guards/json-object.d.ts.map +1 -0
- package/dist/guards/json-object.js +26 -0
- package/dist/guards/resource-budget.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/process-supervisor.js +2 -2
- package/dist/prompt-builder.js +3 -3
- package/dist/status-protocol.d.ts +39 -2
- package/dist/status-protocol.d.ts.map +1 -1
- package/dist/status-protocol.js +60 -9
- package/dist/vendor/claude-adapter.d.ts +1 -0
- package/dist/vendor/claude-adapter.d.ts.map +1 -1
- package/dist/vendor/claude-adapter.js +4 -19
- package/dist/vendor/codex-adapter.d.ts +1 -0
- package/dist/vendor/codex-adapter.d.ts.map +1 -1
- package/dist/vendor/codex-adapter.js +3 -9
- package/dist/vendor/copilot-adapter.d.ts +1 -0
- package/dist/vendor/copilot-adapter.d.ts.map +1 -1
- package/dist/vendor/copilot-adapter.js +6 -10
- package/dist/vendor/detect-binary.d.ts.map +1 -1
- package/dist/vendor/progress-line.d.ts +31 -0
- package/dist/vendor/progress-line.d.ts.map +1 -0
- package/dist/vendor/progress-line.js +85 -0
- package/dist/vendor/registry.d.ts.map +1 -1
- package/dist/vendor/registry.js +9 -3
- package/package.json +2 -2
- package/src/auto-compact-adapter.ts +13 -5
- package/src/dispatch.ts +49 -21
- package/src/guards/json-object.ts +26 -0
- package/src/guards/resource-budget.ts +11 -4
- package/src/index.ts +2 -2
- package/src/lifecycle.ts +11 -5
- package/src/process-supervisor.ts +4 -4
- package/src/prompt-builder.ts +4 -4
- package/src/status-protocol.ts +113 -14
- package/src/types.ts +1 -1
- package/src/vendor/adapter.ts +1 -1
- package/src/vendor/claude-adapter.ts +5 -16
- package/src/vendor/codex-adapter.ts +4 -6
- package/src/vendor/copilot-adapter.ts +7 -7
- package/src/vendor/detect-binary.ts +8 -3
- package/src/vendor/progress-line.ts +86 -0
- 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;
|
|
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) {
|
package/dist/dispatch.d.ts.map
CHANGED
|
@@ -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;
|
|
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([
|
|
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,
|
|
28
|
-
|
|
29
|
-
|
|
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,
|
|
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
|
|
56
|
-
|
|
69
|
+
...(spawnError
|
|
70
|
+
? { spawnError: { code: spawnError.code, message: spawnError.message } }
|
|
71
|
+
: {}),
|
|
72
|
+
heartbeats: [],
|
|
73
|
+
at: Date.now()
|
|
57
74
|
}, null, 2));
|
|
58
|
-
return
|
|
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;
|
|
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.
|
|
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';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,eAAe,
|
|
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.
|
|
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
|
package/dist/lifecycle.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../src/lifecycle.ts"],"names":[],"mappings":"
|
|
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
|
}
|
package/dist/prompt-builder.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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;
|
|
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"}
|
package/dist/status-protocol.js
CHANGED
|
@@ -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
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
|
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;
|
|
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
|
-
|
|
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;
|
|
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
|
-
|
|
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;
|
|
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) {
|
|
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
|
-
|
|
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,
|
|
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;
|
|
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"}
|