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
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { ChildStatus, VendorId } from '../types.js';
|
|
2
|
+
import { isJsonObject } from '../guards/json-object.js';
|
|
3
|
+
|
|
4
|
+
/** The states `ChildStatus.state` allows — the set the reader below checks. */
|
|
5
|
+
const CHILD_STATES: readonly ChildStatus['state'][] = [
|
|
6
|
+
'running',
|
|
7
|
+
'stale',
|
|
8
|
+
'crashed',
|
|
9
|
+
'oom-killed',
|
|
10
|
+
'done',
|
|
11
|
+
'spawn-failed'
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
function isChildState(value: unknown): value is ChildStatus['state'] {
|
|
15
|
+
if (typeof value !== 'string') return false;
|
|
16
|
+
return CHILD_STATES.some((state) => state === value);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The old `String(x ?? '')` for the JSON scalars a status line carries, and `''`
|
|
21
|
+
* for everything else. A non-scalar used to stringify to `'[object Object]'`
|
|
22
|
+
* (or throw on a symbol) — `no-base-to-string` rejects that, and no caller
|
|
23
|
+
* wants it. Scalars keep the exact old result, so a line that parsed before
|
|
24
|
+
* still yields the same `rid` / `note`.
|
|
25
|
+
*/
|
|
26
|
+
function asText(value: unknown): string {
|
|
27
|
+
if (value === null || value === undefined) return '';
|
|
28
|
+
if (typeof value === 'string') return value;
|
|
29
|
+
if (typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint') {
|
|
30
|
+
return String(value);
|
|
31
|
+
}
|
|
32
|
+
return '';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Parse one progress line from a vendor's `--output-format json` stream into a
|
|
37
|
+
* `ChildStatus`, or `null` when the text is not one.
|
|
38
|
+
*
|
|
39
|
+
* WHY THIS EXISTS (batch B2). The three vendor adapters carried this body
|
|
40
|
+
* verbatim, and every field of it went straight from `JSON.parse`'s `any` into
|
|
41
|
+
* a `ChildStatus` — `state` included, which is a six-member union the old code
|
|
42
|
+
* assigned to without checking anything:
|
|
43
|
+
*
|
|
44
|
+
* const o = JSON.parse(stdout); // any
|
|
45
|
+
* state: o.state, // any -> 'running' | 'stale' | …
|
|
46
|
+
*
|
|
47
|
+
* That reads as typed and validates nothing, and because `JSON.parse` returns
|
|
48
|
+
* `any`, no compiler complaint was possible. Here each field is checked, and a
|
|
49
|
+
* line that fails is `null` — the outcome the adapters already produced for
|
|
50
|
+
* unparseable text or a missing numeric `progress`.
|
|
51
|
+
*
|
|
52
|
+
* ONE BEHAVIOUR CHANGE, STATED PLAINLY: a line whose `state` is not one of the
|
|
53
|
+
* six now reads as `null` instead of as a `ChildStatus` whose `state` violates
|
|
54
|
+
* its own type. There is no honest default to substitute — inventing one (say
|
|
55
|
+
* `'running'`) would keep the lie and make it harder to see. Nothing in `src/`
|
|
56
|
+
* or `src/cli/` calls `parseStatusLine`; the only readers are each adapter's own
|
|
57
|
+
* unit test, and all three use `state: 'running'`.
|
|
58
|
+
*
|
|
59
|
+
* The `rid` / `note` / `ts` fallbacks preserve the old coercions exactly
|
|
60
|
+
* (`String(x ?? '')`, `Number(x ?? Date.now())`), so a line that used to parse
|
|
61
|
+
* still yields the same record.
|
|
62
|
+
*/
|
|
63
|
+
export function parseProgressLine(stdout: string, vendor: VendorId): ChildStatus | null {
|
|
64
|
+
let parsed: unknown;
|
|
65
|
+
try {
|
|
66
|
+
parsed = JSON.parse(stdout);
|
|
67
|
+
} catch {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
if (!isJsonObject(parsed)) return null;
|
|
71
|
+
|
|
72
|
+
const progress = parsed['progress'];
|
|
73
|
+
if (typeof progress !== 'number') return null;
|
|
74
|
+
|
|
75
|
+
const state = parsed['state'];
|
|
76
|
+
if (!isChildState(state)) return null;
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
rid: asText(parsed['rid']),
|
|
80
|
+
vendor,
|
|
81
|
+
progress,
|
|
82
|
+
state,
|
|
83
|
+
note: asText(parsed['note']),
|
|
84
|
+
ts: Number(parsed['ts'] ?? Date.now())
|
|
85
|
+
};
|
|
86
|
+
}
|
package/src/vendor/registry.ts
CHANGED
|
@@ -8,9 +8,16 @@ export class VendorAdapterRegistry {
|
|
|
8
8
|
constructor(initial: VendorAdapter[] = []) {
|
|
9
9
|
for (const a of initial) this.map.set(a.id, a);
|
|
10
10
|
}
|
|
11
|
-
register(a: VendorAdapter): void {
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
register(a: VendorAdapter): void {
|
|
12
|
+
this.map.set(a.id, a);
|
|
13
|
+
}
|
|
14
|
+
get(id: string): VendorAdapter | undefined {
|
|
15
|
+
return this.map.get(id);
|
|
16
|
+
}
|
|
17
|
+
list(): VendorAdapter[] {
|
|
18
|
+
return [...this.map.values()];
|
|
19
|
+
}
|
|
14
20
|
}
|
|
15
21
|
|
|
16
|
-
export const defaultRegistry = () =>
|
|
22
|
+
export const defaultRegistry = () =>
|
|
23
|
+
new VendorAdapterRegistry([new ClaudeAdapter(), new CodexAdapter(), new CopilotAdapter()]);
|