@linzumi/cli 1.0.272 → 1.0.273

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 (43) hide show
  1. package/README.md +1 -1
  2. package/dist/impl-res/cloud-supervisor.mjs +69 -69
  3. package/dist/impl-res/index.js +353 -312
  4. package/dist/impl-res/mcp-server.mjs +34 -34
  5. package/dist/impl-ts/cloud-supervisor.mjs +69 -69
  6. package/dist/impl-ts/index.js +488 -488
  7. package/dist/impl-ts/mcp-server.mjs +1 -1
  8. package/dist/mcp-server.mjs +1 -1
  9. package/package.json +3 -2
  10. package/scripts/build-auth-parity-oracle.mjs +0 -709
  11. package/scripts/build-canonical-codex-transpiler-oracle.mjs +0 -93
  12. package/scripts/build-config-identity-parity-oracle.mjs +0 -526
  13. package/scripts/build-core-commander-seams-parity-oracle.mjs +0 -799
  14. package/scripts/build-core-daemon-parity-oracle.mjs +0 -573
  15. package/scripts/build-core-dispatch-input-queue-parity-oracle.mjs +0 -225
  16. package/scripts/build-core-fate-ladder-parity-oracle.mjs +0 -350
  17. package/scripts/build-core-generation-overlap-parity-oracle.mjs +0 -292
  18. package/scripts/build-core-integration-parity-oracle.mjs +0 -453
  19. package/scripts/build-core-lifecycle-guards-parity-oracle.mjs +0 -443
  20. package/scripts/build-core-lock-parity-oracle.mjs +0 -462
  21. package/scripts/build-core-reconnect-resume-parity-oracle.mjs +0 -365
  22. package/scripts/build-core-startup-resume-scan-parity-oracle.mjs +0 -296
  23. package/scripts/build-core-supervisor-parity-oracle.mjs +0 -781
  24. package/scripts/build-cross-harness-failover-oracle.mjs +0 -349
  25. package/scripts/build-editor-parity-oracle.mjs +0 -1525
  26. package/scripts/build-forwarding-parity-oracle.mjs +0 -1390
  27. package/scripts/build-harness-claude-parity-oracle.mjs +0 -407
  28. package/scripts/build-harness-codex-parity-oracle.mjs +0 -479
  29. package/scripts/build-mcp-parity-oracle.mjs +0 -412
  30. package/scripts/build-mcp-selector-parity-oracle.mjs +0 -65
  31. package/scripts/build-onboarding-discovery-parity-oracle.mjs +0 -388
  32. package/scripts/build-onboarding-flow-parity-oracle.mjs +0 -562
  33. package/scripts/build-onboarding-gateway-parity-oracle.mjs +0 -313
  34. package/scripts/build-onboarding-support-parity-oracle.mjs +0 -519
  35. package/scripts/build-pipeline-parity-oracle.mjs +0 -614
  36. package/scripts/build-protocol-parity-oracle.mjs +0 -398
  37. package/scripts/build-queue-parity-oracle.mjs +0 -1012
  38. package/scripts/build-session-registry-parity-oracle.mjs +0 -582
  39. package/scripts/build-transport-parity-oracle.mjs +0 -694
  40. package/scripts/build-tui-parity-oracle.mjs +0 -577
  41. package/scripts/build-vm-sandbox-parity-oracle.mjs +0 -1281
  42. package/scripts/build-worker-entry-parity-oracle.mjs +0 -424
  43. package/scripts/build-worker-spawn-parity-oracle.mjs +0 -823
@@ -1,225 +0,0 @@
1
- // Spec: kandan/plans/2026-07-10-compute-nodes-rescript-commander-zero-ts-program.md
2
- // (M3 cluster 10, commander core / dispatch input queue).
3
- // Relationship: Builds the TS-side PARITY ORACLE for the per-session
4
- // dispatch input queue of the ReScript commander port, the sibling of
5
- // build-pipeline-parity-oracle.mjs (cluster 9, which owns the two recovery
6
- // watchdog primitives this queue's predicates feed). The oracle bundles the
7
- // REAL runner.ts exports - createClaudeCodeInputQueue (the streaming-input
8
- // FIFO with the single-live-turn park/release discipline, the #2589 honest
9
- // enqueue disposition, the #2590 steer-application tracking, and the
10
- // BLOCKER A dispatch-confirm watermark seam), claudeCodeTurnStallThresholdMs
11
- // (the LINZUMI_CLAUDE_TURN_STALL_MS env resolution), and
12
- // claudeCodeDispatchTerminalFailureReason (the kill-respawn-retry ladder's
13
- // byte-frozen terminal copy) - behind the cluster 1/2 one-shot BATCH driver
14
- // (a JSON array of cases on stdin, a JSON array of results on stdout).
15
- //
16
- // Byte parity: every trace event (dispatches with their payload bytes,
17
- // predicate refusals, park positions, watermark commits, steer outcomes and
18
- // applied resolutions, closed-input errors) is normalized by THIS driver
19
- // with pinned key order, and delivered message payloads ride the TS message
20
- // objects VERBATIM (their own key insertion order), so the ReScript side
21
- // must reproduce field presence AND insertion order exactly.
22
- //
23
- // Determinism: the queue owns no timers and no clock - its only
24
- // nondeterminism is promise scheduling, which the driver serializes by
25
- // draining the microtask queue after every op (pull resolutions and steer
26
- // `applied` resolutions land in trace order deterministically). Scripted
27
- // deps: the isLiveSteerAllowed predicate is a mutable flag flipped via ops;
28
- // the delivery/wait/watermark callbacks append trace events.
29
- //
30
- // Import-time side effects: runner.ts transitively reads
31
- // src/assets/linzumi-logo.svg relative to the bundle at import time
32
- // (helloLinzumiProject.ts), so the asset is copied next to the bundle -
33
- // the build-harness-codex-parity-oracle.mjs convention. Externals match
34
- // the existing oracles (ws/undici/blessed/claude-agent-sdk stay external;
35
- // none of them is touched at import time on this driver's paths).
36
- //
37
- // SECRETS: the oracle only ever sees the conformance suite's synthetic
38
- // payloads. The output is a local test artifact (.differential/ is
39
- // gitignored, never published) and stays unminified for debuggability.
40
- import { copyFile, mkdir } from 'node:fs/promises';
41
- import { dirname, join } from 'node:path';
42
- import { fileURLToPath } from 'node:url';
43
- import { build } from 'esbuild';
44
-
45
- const packageRoot = dirname(dirname(fileURLToPath(import.meta.url)));
46
-
47
- const driverSource = `
48
- import {
49
- claudeCodeDispatchTerminalFailureReason,
50
- claudeCodeTurnStallThresholdMs,
51
- createClaudeCodeInputQueue,
52
- } from './src/runner';
53
-
54
- // Deterministic promise settlement: every queue-internal resolution is
55
- // synchronous, so a bounded microtask drain after each op flushes every
56
- // pending .then into the trace in resolution order.
57
- async function drainMicrotasks() {
58
- for (let tick = 0; tick < 8; tick += 1) {
59
- await Promise.resolve();
60
- }
61
- }
62
-
63
- async function runInputQueueCase(caseInput) {
64
- const trace = [];
65
- let liveSteerAllowed = true;
66
- let steerCount = 0;
67
- let pullCount = 0;
68
- const queue = createClaudeCodeInputQueue({
69
- content: caseInput.content,
70
- sourceSeq: caseInput.sourceSeq ?? undefined,
71
- onInputDelivered: () => trace.push({ t: 'inputDelivered' }),
72
- isLiveSteerAllowed:
73
- caseInput.liveSteerMode === 'scripted' ? () => liveSteerAllowed : undefined,
74
- onInputWait: (currentSourceSeq) =>
75
- trace.push({ t: 'inputWait', seq: currentSourceSeq ?? null }),
76
- onSourceSeqDelivered: (sourceSeq) => trace.push({ t: 'watermark', seq: sourceSeq }),
77
- });
78
- const iterator = queue.messages[Symbol.asyncIterator]();
79
- for (const op of caseInput.ops ?? []) {
80
- if (op.op === 'enqueue') {
81
- try {
82
- const disposition = queue.enqueue({
83
- content: op.content,
84
- sourceSeq: op.sourceSeq ?? undefined,
85
- });
86
- trace.push({
87
- t: 'enqueue',
88
- result:
89
- disposition.disposition === 'parked'
90
- ? { disposition: 'parked', queuePosition: disposition.queuePosition }
91
- : { disposition: 'delivered' },
92
- });
93
- } catch (error) {
94
- trace.push({
95
- t: 'enqueue',
96
- error: error instanceof Error ? error.message : String(error),
97
- });
98
- }
99
- } else if (op.op === 'enqueueSteer') {
100
- steerCount += 1;
101
- const steerId = steerCount;
102
- try {
103
- const outcome = queue.enqueueSteer(op.content);
104
- trace.push({ t: 'steer', steerId, steered: outcome.steered });
105
- void outcome.applied.then((applied) =>
106
- trace.push({ t: 'steerApplied', steerId, applied })
107
- );
108
- } catch (error) {
109
- trace.push({
110
- t: 'steer',
111
- steerId,
112
- error: error instanceof Error ? error.message : String(error),
113
- });
114
- }
115
- } else if (op.op === 'next') {
116
- pullCount += 1;
117
- const pullId = pullCount;
118
- trace.push({ t: 'pullStart', pullId });
119
- void iterator.next().then((result) =>
120
- trace.push(
121
- result.done === true
122
- ? { t: 'pulled', pullId, done: true }
123
- : { t: 'pulled', pullId, done: false, message: result.value }
124
- )
125
- );
126
- } else if (op.op === 'completeTurn') {
127
- trace.push({ t: 'completeTurn', completed: queue.completeTurn() ?? null });
128
- } else if (op.op === 'currentSourceSeq') {
129
- trace.push({ t: 'currentSourceSeq', seq: queue.currentSourceSeq() ?? null });
130
- } else if (op.op === 'close') {
131
- queue.close();
132
- trace.push({ t: 'closed' });
133
- } else if (op.op === 'drainUndelivered') {
134
- trace.push({
135
- t: 'drained',
136
- followUps: queue.drainUndeliveredFollowUps().map((followUp) => ({
137
- message: followUp.message,
138
- sourceSeq: followUp.sourceSeq ?? null,
139
- })),
140
- });
141
- } else if (op.op === 'setLiveSteerAllowed') {
142
- liveSteerAllowed = op.value === true;
143
- }
144
- await drainMicrotasks();
145
- }
146
- await drainMicrotasks();
147
- return { trace };
148
- }
149
-
150
- async function runCase(input) {
151
- switch (input.kind) {
152
- case 'constants':
153
- return {
154
- claudeCodeDispatchTerminalFailureReason,
155
- };
156
- case 'turnStallThresholdMs':
157
- return claudeCodeTurnStallThresholdMs(input.env ?? {});
158
- case 'inputQueueRun':
159
- return runInputQueueCase(input);
160
- default:
161
- return { error: 'unknown case kind ' + String(input.kind) };
162
- }
163
- }
164
-
165
- async function runBatch() {
166
- const chunks = [];
167
- for await (const chunk of process.stdin) chunks.push(chunk);
168
- const cases = JSON.parse(Buffer.concat(chunks).toString('utf8'));
169
- const results = [];
170
- for (const testCase of cases) {
171
- results.push(await runCase(testCase));
172
- }
173
- process.stdout.write(JSON.stringify(results), () => {
174
- process.exit(0);
175
- });
176
- }
177
-
178
- runBatch().then(
179
- () => {},
180
- (error) => {
181
- process.stderr.write(String(error && error.stack ? error.stack : error) + '\\n');
182
- process.exit(1);
183
- }
184
- );
185
- `;
186
-
187
- const outDir = join(packageRoot, '.differential');
188
- const outPath = join(outDir, 'core-dispatch-input-queue-parity-oracle.mjs');
189
-
190
- await mkdir(outDir, { recursive: true });
191
- // runner.ts transitively reads this asset relative to the bundle at import
192
- // time (helloLinzumiProject.ts readFileSync), so it must exist next to the
193
- // oracle bundle.
194
- await mkdir(join(outDir, 'assets'), { recursive: true });
195
- await copyFile(
196
- join(packageRoot, 'src/assets/linzumi-logo.svg'),
197
- join(outDir, 'assets/linzumi-logo.svg')
198
- );
199
-
200
- await build({
201
- stdin: {
202
- contents: driverSource,
203
- resolveDir: packageRoot,
204
- sourcefile: 'core-dispatch-input-queue-parity-driver.ts',
205
- loader: 'ts',
206
- },
207
- bundle: true,
208
- // Spec: plans/2026-09-09-ts-native-account-continuation.md. Match the
209
- // production/auth-oracle ESM bridge for reachable CJS runtime dependencies;
210
- // the distinct banner binding cannot collide with bundled createRequire.
211
- banner: {
212
- js: "import { createRequire as __coreDispatchInputQueueOracleCreateRequire } from 'node:module';\nconst require = __coreDispatchInputQueueOracleCreateRequire(import.meta.url);",
213
- },
214
- platform: 'node',
215
- target: 'node20',
216
- format: 'esm',
217
- outfile: outPath,
218
- minify: false,
219
- sourcemap: false,
220
- legalComments: 'none',
221
- logLevel: 'silent',
222
- external: ['ws', 'undici', 'blessed', '@anthropic-ai/claude-agent-sdk'],
223
- });
224
-
225
- process.stdout.write(outPath + '\n');
@@ -1,350 +0,0 @@
1
- // Spec: kandan/plans/2026-07-10-compute-nodes-rescript-commander-zero-ts-program.md
2
- // (M3 cluster 10, commander core).
3
- // Relationship: Builds the TS-side PARITY ORACLE for the fate-ladder policy
4
- // engine of the ReScript commander port, the sibling of
5
- // build-pipeline-parity-oracle.mjs (cluster 9). The oracle bundles the REAL
6
- // TS module (src/fateLadder.ts - the F2/D51/D53 policy engine: the policy
7
- // table, the budget env resolution, the run/history record, the one
8
- // decision entry point, the hold-dispatch commit, the visible-reason
9
- // strings, the F4 wire receipts, and the rate-limit reset capture) behind
10
- // the cluster 1/2 one-shot BATCH driver (a JSON array of cases on stdin, a
11
- // JSON array of results on stdout).
12
- //
13
- // Byte parity: fateLadderWireHistory receipts are returned PRE-STRINGIFIED
14
- // (the TS object's own key insertion order rides JSON.stringify), and every
15
- // decision/run is serialized through one canonical shape both sides
16
- // reproduce field-for-field. Determinism: clocks and budgets are injected
17
- // per case op, the breaker gate is scripted per decide op (its calls are
18
- // traced so the consult discipline is pinned too) - nothing here reads wall
19
- // time or process.env except through case inputs.
20
- //
21
- // SECRETS: the oracle only ever sees the conformance suite's synthetic
22
- // payloads. The output is a local test artifact (.differential/ is
23
- // gitignored, never published) and stays unminified for debuggability.
24
- import { mkdir, readFile, writeFile } from 'node:fs/promises';
25
- import { dirname, join } from 'node:path';
26
- import { fileURLToPath } from 'node:url';
27
- import { build } from 'esbuild';
28
-
29
- const packageRoot = dirname(dirname(fileURLToPath(import.meta.url)));
30
- const providerSlasPath = join(
31
- packageRoot,
32
- 'src',
33
- 'fateLadderProviderSlas.json'
34
- );
35
- const generatedProviderSlasPath = join(
36
- packageRoot,
37
- '..',
38
- 'linzumi-cli-rescript',
39
- 'src',
40
- 'generated',
41
- 'CommanderFateLadderProviderSlas.res'
42
- );
43
-
44
- function positiveFiniteNumber(value, label) {
45
- if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0) {
46
- throw new Error(`invalid provider fate SLA ${label}: ${String(value)}`);
47
- }
48
- return value;
49
- }
50
-
51
- const providerSlas = JSON.parse(await readFile(providerSlasPath, 'utf8'));
52
- const defaultMaxLadderMs = positiveFiniteNumber(
53
- providerSlas?.default?.maxLadderMs,
54
- 'default.maxLadderMs'
55
- );
56
- const waferMaxLadderMs = positiveFiniteNumber(
57
- providerSlas?.wafer?.maxLadderMs,
58
- 'wafer.maxLadderMs'
59
- );
60
- const generatedProviderSlas = `// GENERATED from packages/linzumi-cli/src/fateLadderProviderSlas.json by
61
- // packages/linzumi-cli/scripts/build-core-fate-ladder-parity-oracle.mjs.
62
- // Do not edit this file by hand.
63
- // Spec: plans/2026-08-07-wafer-provider-aware-fate-budget.spec.md
64
-
65
- let defaultMaxLadderMs = ${defaultMaxLadderMs}.
66
- let waferMaxLadderMs = ${waferMaxLadderMs}.
67
-
68
- let maxLadderMsForModelProvider = (modelProvider: option<string>): float =>
69
- switch modelProvider {
70
- | Some("wafer") => waferMaxLadderMs
71
- | Some(_) | None => defaultMaxLadderMs
72
- }
73
- `;
74
-
75
- if (process.argv.includes('--write-provider-slas')) {
76
- await writeFile(generatedProviderSlasPath, generatedProviderSlas, 'utf8');
77
- } else {
78
- const trackedProviderSlas = await readFile(generatedProviderSlasPath, 'utf8');
79
- if (trackedProviderSlas !== generatedProviderSlas) {
80
- throw new Error(
81
- 'generated CommanderFateLadderProviderSlas.res is stale; run build-core-fate-ladder-parity-oracle.mjs --write-provider-slas'
82
- );
83
- }
84
- }
85
-
86
- if (process.argv.includes('--check-provider-slas-only')) {
87
- process.stdout.write(generatedProviderSlasPath + '\n');
88
- process.exit(0);
89
- }
90
-
91
- // PARITY SCOPE (owner ruling 2026-07-18, failover becomes a user-decision
92
- // capability): the compared surface is the SHARED F2 recovery engine only.
93
- // The TS-only frozen failover rung (flag-OFF forever, superseded) is
94
- // excluded: no failover constants, no failover flag case, no failover
95
- // decide input/grant, no commitFailover op, no per-entry failover
96
- // sub-object, and the rung vocabulary is filtered to the shared members -
97
- // the ReScript commander has no automatic failover surface to compare.
98
- const driverSource = `
99
- import {
100
- appendFateLadderEntry,
101
- commitFateLadderHoldDispatch,
102
- commitRouteOutageHoldOutcome,
103
- createFateLadderRun,
104
- decideFateLadderStep,
105
- defaultFateLadderBudgets,
106
- fateLadderBudgets,
107
- fateLadderPolicies,
108
- fateLadderRungs,
109
- fateLadderWireHistory,
110
- freshSessionResumeReason,
111
- inPlaceResumeMaxAttempts,
112
- maxFateLadderHistoryEntries,
113
- rateLimitHoldReason,
114
- rateLimitHoldReasonPrefix,
115
- rateLimitResetAtMsFromNotification,
116
- redispatchAfterLocalFailureReason,
117
- workerRebuildRetryReason,
118
- } from './src/fateLadder';
119
-
120
- // Canonical run/decision serialization shared (by construction) with the
121
- // ReScript conformance: fixed key order, option fields as null.
122
- function runJson(run) {
123
- return {
124
- fate: run.fate,
125
- startedAtMs: run.startedAtMs,
126
- rungCursor: run.rungCursor,
127
- cursorAttempts: run.cursorAttempts,
128
- recoveryRungsAttempted: run.recoveryRungsAttempted,
129
- holdCommitted: run.holdCommitted,
130
- holdDispatched: run.holdDispatched,
131
- historyTruncated: run.historyTruncated,
132
- entries: run.entries.map((entry) => ({
133
- rung: entry.rung,
134
- outcome: entry.outcome,
135
- atMs: entry.atMs,
136
- detail: entry.detail === undefined ? null : entry.detail,
137
- resetAtMs: entry.resetAtMs === undefined ? null : entry.resetAtMs,
138
- })),
139
- };
140
- }
141
-
142
- function decisionJson(decision) {
143
- switch (decision.kind) {
144
- case 'stand':
145
- return { kind: 'stand', cause: decision.cause };
146
- case 'execute_rung':
147
- return { kind: 'execute_rung', rung: decision.rung, run: runJson(decision.run) };
148
- case 'hold_until_reset':
149
- return {
150
- kind: 'hold_until_reset',
151
- resetAtMs: decision.resetAtMs,
152
- run: runJson(decision.run),
153
- };
154
- case 'route_outage_hold':
155
- return {
156
- kind: 'route_outage_hold',
157
- deadlineAtMs: decision.deadlineAtMs,
158
- run: runJson(decision.run),
159
- };
160
- case 'breaker_hold':
161
- return { kind: 'breaker_hold', reason: decision.reason, run: runJson(decision.run) };
162
- case 'red':
163
- return { kind: 'red', cause: decision.cause, run: runJson(decision.run) };
164
- default:
165
- return { kind: 'unknown' };
166
- }
167
- }
168
-
169
- function budgetsOf(raw) {
170
- return raw === undefined
171
- ? defaultFateLadderBudgets
172
- : {
173
- maxRecoveryRungs: raw.maxRecoveryRungs,
174
- maxLadderMs: raw.maxLadderMs,
175
- maxRateLimitHoldMs: raw.maxRateLimitHoldMs,
176
- };
177
- }
178
-
179
- // One scripted per-turn schedule: ops drive the pure engine exactly the way
180
- // the session layer would (decide -> store returned run -> dispatch), with
181
- // the breaker verdict scripted per decide op and every gate call traced.
182
- function runScheduleCase(caseInput) {
183
- let current = undefined;
184
- const steps = [];
185
- for (const op of caseInput.ops ?? []) {
186
- if (op.op === 'decide') {
187
- const breakerCalls = [];
188
- const scripted = op.breaker ?? { action: 'proceed' };
189
- const gate = (fate, nowMs) => {
190
- breakerCalls.push({ fate, nowMs });
191
- if (scripted.action === 'hold') {
192
- return { action: 'hold', reason: scripted.reason ?? 'scripted_hold' };
193
- }
194
- if (scripted.action === 'canary') {
195
- return { action: 'canary' };
196
- }
197
- return { action: 'proceed' };
198
- };
199
- const decision = decideFateLadderStep({
200
- fate: op.fate ?? undefined,
201
- run: current,
202
- nowMs: op.nowMs,
203
- budgets: budgetsOf(op.budgets),
204
- breaker: gate,
205
- grants: {
206
- inPlaceResume: op.grants?.inPlaceResume === true,
207
- redispatch: op.grants?.redispatch === true,
208
- workerRebuild: op.grants?.workerRebuild === true,
209
- },
210
- rateLimitResetAtMs: op.resetAtMs ?? undefined,
211
- // route_outage (2026-07-24 duration form): the server-owned hold
212
- // ceiling DURATION the schedule may script; absent = pre-hold
213
- // server / valve off (the honest red).
214
- routeOutageHoldCeilingMs: op.routeOutageCeilingMs ?? undefined,
215
- });
216
- if (decision.kind !== 'stand') {
217
- current = decision.run;
218
- }
219
- steps.push({ decision: decisionJson(decision), breakerCalls });
220
- } else if (op.op === 'commitHoldDispatch') {
221
- if (current === undefined) {
222
- steps.push({ skipped: true });
223
- } else {
224
- current = commitFateLadderHoldDispatch(current, op.nowMs);
225
- steps.push({ run: runJson(current) });
226
- }
227
- } else if (op.op === 'commitRouteOutageHoldOutcome') {
228
- // Route-outage hold outcome commit (2026-07-23): the session-layer
229
- // twin op (dispatch on the route-recovered snapshot / ceiling
230
- // exhaustion).
231
- if (current === undefined) {
232
- steps.push({ skipped: true });
233
- } else {
234
- current = commitRouteOutageHoldOutcome(current, {
235
- outcome: op.outcome,
236
- atMs: op.nowMs,
237
- detail: op.detail ?? undefined,
238
- });
239
- steps.push({ run: runJson(current) });
240
- }
241
- } else if (op.op === 'append') {
242
- if (current === undefined) {
243
- steps.push({ skipped: true });
244
- } else {
245
- current = appendFateLadderEntry(current, {
246
- rung: op.entry.rung,
247
- outcome: op.entry.outcome,
248
- atMs: op.entry.atMs,
249
- detail: op.entry.detail ?? undefined,
250
- resetAtMs: op.entry.resetAtMs ?? undefined,
251
- });
252
- steps.push({ run: runJson(current) });
253
- }
254
- } else if (op.op === 'seed') {
255
- current = createFateLadderRun(op.fate, op.nowMs);
256
- steps.push({ run: runJson(current) });
257
- } else if (op.op === 'wire') {
258
- steps.push({
259
- wire: JSON.stringify(fateLadderWireHistory(current, op.fate, budgetsOf(op.budgets))),
260
- });
261
- } else if (op.op === 'reset') {
262
- current = undefined;
263
- steps.push({ reset: true });
264
- } else {
265
- steps.push({ error: 'unknown op ' + String(op.op) });
266
- }
267
- }
268
- return { steps };
269
- }
270
-
271
- function runCase(input) {
272
- switch (input.kind) {
273
- case 'constants':
274
- return {
275
- // The shared recovery vocabulary only: the TS-only frozen
276
- // cross_harness_failover member is excluded by name (2026-07-18
277
- // ruling) - the ReScript engine's fateLadderRungs is the filtered
278
- // array by construction.
279
- fateLadderRungs: fateLadderRungs.filter(
280
- (rung) => rung !== 'cross_harness_failover'
281
- ),
282
- inPlaceResumeMaxAttempts,
283
- fateLadderPolicies,
284
- defaultFateLadderBudgets,
285
- maxFateLadderHistoryEntries,
286
- redispatchAfterLocalFailureReason,
287
- workerRebuildRetryReason,
288
- freshSessionResumeReason,
289
- rateLimitHoldReasonPrefix,
290
- };
291
- case 'budgets':
292
- return fateLadderBudgets(input.env ?? {}, input.modelProvider);
293
- case 'holdReason':
294
- return rateLimitHoldReason(input.resetAtMs);
295
- case 'resetFromNotification':
296
- return rateLimitResetAtMsFromNotification(input.params) ?? null;
297
- case 'scheduleRun':
298
- return runScheduleCase(input);
299
- default:
300
- return { error: 'unknown case kind ' + String(input.kind) };
301
- }
302
- }
303
-
304
- async function runBatch() {
305
- const chunks = [];
306
- for await (const chunk of process.stdin) chunks.push(chunk);
307
- const cases = JSON.parse(Buffer.concat(chunks).toString('utf8'));
308
- const results = [];
309
- for (const testCase of cases) {
310
- results.push(runCase(testCase));
311
- }
312
- process.stdout.write(JSON.stringify(results), () => {
313
- process.exit(0);
314
- });
315
- }
316
-
317
- runBatch().then(
318
- () => {},
319
- (error) => {
320
- process.stderr.write(String(error && error.stack ? error.stack : error) + '\\n');
321
- process.exit(1);
322
- }
323
- );
324
- `;
325
-
326
- const outDir = join(packageRoot, '.differential');
327
- const outPath = join(outDir, 'core-fate-ladder-parity-oracle.mjs');
328
-
329
- await mkdir(outDir, { recursive: true });
330
-
331
- await build({
332
- stdin: {
333
- contents: driverSource,
334
- resolveDir: packageRoot,
335
- sourcefile: 'core-fate-ladder-parity-driver.ts',
336
- loader: 'ts',
337
- },
338
- bundle: true,
339
- platform: 'node',
340
- target: 'node20',
341
- format: 'esm',
342
- outfile: outPath,
343
- minify: false,
344
- sourcemap: false,
345
- legalComments: 'none',
346
- logLevel: 'silent',
347
- external: ['ws', 'undici', 'blessed', '@anthropic-ai/claude-agent-sdk'],
348
- });
349
-
350
- process.stdout.write(outPath + '\n');