@linzumi/cli 1.0.109 → 1.0.110
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/README.md +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/scripts/build-harness-claude-parity-oracle.mjs +308 -0
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -1473,7 +1473,7 @@ To kick the agent off:
|
|
|
1473
1473
|
`,L=Buffer.byteLength(P,"utf8");if(L>s)return l("runner_diagnostics.spool_entry_dropped",{reason:"entry_too_large",entry_bytes:L,max_entry_bytes:s}),!1;jSe(n,{recursive:!0}),m(u)+L>i&&f(),_(L);let D=w()?`
|
|
1474
1474
|
`:"";return $Se(u,`${D}${P}`,"utf8"),!0}catch(R){return l("runner_diagnostics.spool_failed",{error:R instanceof Error?R.message:String(R)}),!1}},v=k=>{let R=[],P=zSe(k,"utf8");for(let L of P.split(`
|
|
1475
1475
|
`))if(L.trim()!=="")try{let D=JSON.parse(L);D!==null&&typeof D=="object"&&R.push({parsed:D,raw:L})}catch{}return R};return{append:S,drain:async k=>{if(c)return{uploadedBatches:0,uploadedEntries:0,remainingBatches:p().length,skipped:!0};c=!0;let R=0,P=0;try{f(),_(0);let L=a()-o;for(let D of p()){let j;try{j=v(D)}catch(Z){l("runner_diagnostics.spool_batch_unreadable",{file:D,error:Z instanceof Error?Z.message:String(Z)}),y(D,"unreadable");continue}let z=j.filter(Z=>{let me=tke(Z.parsed);return me===void 0||me>=L});if(z.length===0){y(D,"empty_or_expired");continue}let E=hP(D,".jsonl"),B=z.map(Z=>Z.raw).join(`
|
|
1476
|
-
`),q=z.map(Z=>Z.parsed.spooled_at).filter(Z=>typeof Z=="string"),W={bundle_name:"runner-diagnostics-spool",exported_at:new Date(a()).toISOString(),idempotency_key:E,diagnostics:{kind:"runner_diagnostic_log",spool_batch:!0,idempotency_key:E,entry_count:z.length,...q.length===0?{}:{first_spooled_at:q[0],last_spooled_at:q[q.length-1]}},telemetry_ndjson:B};try{await k(W)}catch(Z){l("runner_diagnostics.spool_upload_failed",{file:D,remaining_batches:p().length,error:Z instanceof Error?Z.message:String(Z)});break}R+=1,P+=z.length;try{F9(D)}catch(Z){l("runner_diagnostics.spool_delete_failed",{file:D,error:Z instanceof Error?Z.message:String(Z)})}}}catch(L){l("runner_diagnostics.spool_drain_failed",{error:L instanceof Error?L.message:String(L)})}finally{c=!1}return{uploadedBatches:R,uploadedEntries:P,remainingBatches:p().length,skipped:!1}},pendingBatchFiles:p}}var KSe,VSe,WSe,HSe,GSe,z9,QSe,XSe,N9=F(()=>{"use strict";ax();KSe=32*1024*1024,VSe=10080*60*1e3,WSe=4*1024*1024,HSe=1024*1024,GSe="spool.jsonl",z9=/^batch-(\d{1,16})-[0-9a-f-]+\.jsonl$/;QSe=/\b([A-Z][A-Z0-9_]{1,})=("[^"\n]*"|'[^'\n]*'|[^\s"'`;,)\]}]+)/g,XSe=/(?:\/(?:[A-Za-z0-9._@~+-]|%[0-9A-Fa-f]{2})+){2,}/g});var qt,yP,ta=F(()=>{"use strict";qt="1.0.
|
|
1476
|
+
`),q=z.map(Z=>Z.parsed.spooled_at).filter(Z=>typeof Z=="string"),W={bundle_name:"runner-diagnostics-spool",exported_at:new Date(a()).toISOString(),idempotency_key:E,diagnostics:{kind:"runner_diagnostic_log",spool_batch:!0,idempotency_key:E,entry_count:z.length,...q.length===0?{}:{first_spooled_at:q[0],last_spooled_at:q[q.length-1]}},telemetry_ndjson:B};try{await k(W)}catch(Z){l("runner_diagnostics.spool_upload_failed",{file:D,remaining_batches:p().length,error:Z instanceof Error?Z.message:String(Z)});break}R+=1,P+=z.length;try{F9(D)}catch(Z){l("runner_diagnostics.spool_delete_failed",{file:D,error:Z instanceof Error?Z.message:String(Z)})}}}catch(L){l("runner_diagnostics.spool_drain_failed",{error:L instanceof Error?L.message:String(L)})}finally{c=!1}return{uploadedBatches:R,uploadedEntries:P,remainingBatches:p().length,skipped:!1}},pendingBatchFiles:p}}var KSe,VSe,WSe,HSe,GSe,z9,QSe,XSe,N9=F(()=>{"use strict";ax();KSe=32*1024*1024,VSe=10080*60*1e3,WSe=4*1024*1024,HSe=1024*1024,GSe="spool.jsonl",z9=/^batch-(\d{1,16})-[0-9a-f-]+\.jsonl$/;QSe=/\b([A-Z][A-Z0-9_]{1,})=("[^"\n]*"|'[^'\n]*'|[^\s"'`;,)\]}]+)/g,XSe=/(?:\/(?:[A-Za-z0-9._@~+-]|%[0-9A-Fa-f]{2})+){2,}/g});var qt,yP,ta=F(()=>{"use strict";qt="1.0.110",yP=`linzumi ${qt}`});import{closeSync as B9,existsSync as _P,mkdirSync as rke,openSync as J9,readFileSync as K9,renameSync as oke,unlinkSync as _d,writeFileSync as ike,writeSync as V9}from"node:fs";import{dirname as W9,join as ske}from"node:path";function bP(e){return e instanceof ys||e instanceof Error&&e.name===G9&&"lockPath"in e&&"heldBy"in e}function wP(e,n=Wn(),t){let r=t===void 0?encodeURIComponent(e):ld(t);return ske(W9(n),"runners",`${r}.lock`)}function x_(e){let n=wP(e.machineId,e.configPath,e.linzumiUrl),t=e.isPidAlive??t3,r=e.now??(()=>new Date),o=e.killPid??_ke,i=r().toISOString(),s={version:1,machineId:e.machineId,runnerId:e.runnerId,pid:e.pid??process.pid,cwd:e.cwd,workspace:e.workspace,...e.linzumiUrl===void 0?{}:{linzumiUrl:zn(e.linzumiUrl)},...e.launchSource===void 0?{}:{launchSource:e.launchSource},startedAt:i,heartbeatAt:i,cliVersion:e.cliVersion??qt,...e.gracefulUpdateDrain===!0?{gracefulUpdateDrain:!0}:{}};cke(e.machineId,e.configPath,e.linzumiUrl,t,r,o,e.onTakeover),lke(n,s,t,r,o,e.onTakeover,e.beforeReadExistingLock,e.beforeReplaceStaleLock);let a=()=>Z9(n,s,r),d=setInterval(a,H9);return d.unref(),{path:n,record:s,heartbeat:a,release:()=>{clearInterval(d),e3(n,s)}}}function Z9(e,n,t){try{let r=b_(e);if(r===void 0||r.machineId!==n.machineId||r.runnerId!==n.runnerId||r.pid!==n.pid||r.startedAt!==n.startedAt)return;let o={...r,heartbeatAt:t().toISOString()},i=`${e}.tmp`;ike(i,`${JSON.stringify(o,null,2)}
|
|
1477
1477
|
`,"utf8"),oke(i,e)}catch{}}function bd(e,n,t){if(!n(e.pid))return{state:"dead"};let r=e.heartbeatAt??e.startedAt,o=Date.parse(r);return Number.isNaN(o)||t().getTime()-o>ake?{state:"wedged",reason:e.heartbeatAt===void 0?"missing_heartbeat":"stale_heartbeat"}:{state:"live"}}function Q9(e,n,t,r){return t!==__||e.launchSource!==__?!1:r.state!=="live"?!0:dke(n,e.cliVersion)>0}function dke(e,n){let t=U9(e),r=U9(n);for(let o=0;o<3;o++){let i=t.core[o],s=r.core[o];if(i===void 0||s===void 0)throw new Error(`compareCliVersions: unexpected undefined at core index ${o}`);if(i!==s)return i>s?1:-1}return t.prerelease.length===0&&r.prerelease.length===0?0:t.prerelease.length===0?1:r.prerelease.length===0?-1:uke(t.prerelease,r.prerelease)}function U9(e){let n=e.trim().replace(/^v/i,"").split("+",1)[0]??"",t=n.indexOf("-"),r=t===-1?n:n.slice(0,t),o=t===-1?"":n.slice(t+1),i=r.split("."),s=[xP(i[0]),xP(i[1]),xP(i[2])],a=o===""?[]:o.split(".").filter(d=>d!=="");return{core:s,prerelease:a}}function xP(e){let n=Number.parseInt(e??"",10);return Number.isInteger(n)&&n>=0?n:0}function uke(e,n){let t=Math.max(e.length,n.length);for(let r=0;r<t;r++){let o=e[r],i=n[r];if(o===void 0)return-1;if(i===void 0)return 1;let s=Number.parseInt(o,10),a=Number.parseInt(i,10),d=s.toString()===o,u=a.toString()===i;if(d&&u){if(s!==a)return s>a?1:-1}else{if(d!==u)return d?-1:1;if(o!==i)return o>i?1:-1}}return 0}function X9(e,n,t,r,o){try{r(n.pid)}catch(i){let s=i!==null&&typeof i=="object"&&"code"in i?i.code:void 0;if(s!=="ESRCH")throw s==="EPERM"||s==="EACCES"?new Error(`Cannot take over the runner lock at ${e}: its holder process (pid ${n.pid}) is owned by another user and cannot be stopped. Stop that process, or remove the lock file, then retry.`):i}o?.({lockPath:e,holderPid:n.pid,holderRunnerId:n.runnerId,reason:t})}function cke(e,n,t,r,o,i,s){if(t===void 0||yr(t)!==yr(Jt))return;let a=wP(e,n),d=b_(a);if(d!==void 0){if(bd(d,r,o).state==="live")throw new ys(a,d);Y9(a,r,()=>{let u=_P(a)?vP(a):void 0;if(u===void 0)return;let c=bd(u,r,o);if(c.state==="live")throw new ys(a,u);c.state==="wedged"&&X9(a,u,c.reason,i,s),_d(a)})}}function lke(e,n,t,r,o,i,s,a){if(y_(e,n))return;s?.();let d=b_(e);if(d===void 0){if(y_(e,n))return;throw new Error(`another Linzumi runner lock appeared while starting: ${e}`)}if(bd(d,t,r).state==="live")throw new ys(e,d);a?.(),Y9(e,t,()=>{let u=_P(e)?vP(e):void 0;if(u!==void 0){let c=bd(u,t,r);if(c.state==="live")throw new ys(e,u);c.state==="wedged"&&X9(e,u,c.reason,o,i),_d(e)}if(!y_(e,n))throw new Error(`another Linzumi runner lock appeared while starting: ${e}`)})}function y_(e,n){rke(W9(e),{recursive:!0});try{let t=J9(e,"wx");try{V9(t,`${JSON.stringify(n,null,2)}
|
|
1478
1478
|
`)}finally{B9(t)}return!0}catch(t){if(Vc(t,"EEXIST"))return!1;throw t}}function Y9(e,n,t){let r=`${e}.replace`;for(;;)try{let o=J9(r,"wx");try{V9(o,`${process.pid}
|
|
1479
1479
|
`),t()}finally{B9(o),_d(r)}return}catch(o){if(Vc(o,"EEXIST")){let i=pke(r);if(i===void 0)continue;if(n(i))throw new Error(["another Linzumi runner is already replacing a stale runner lock",`lock: ${e}`,"Wait for that startup to finish, then retry."].join(`
|
package/package.json
CHANGED
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
// Spec: kandan/plans/2026-07-10-compute-nodes-rescript-commander-zero-ts-program.md
|
|
2
|
+
// (M3 cluster 8, harness-claude-adapter / workstream H.3).
|
|
3
|
+
// Relationship: Builds the TS-side PARITY ORACLE for the claude-adapter
|
|
4
|
+
// cluster of the ReScript commander port, the sibling of
|
|
5
|
+
// build-harness-codex-parity-oracle.mjs (cluster 7). The oracle runs the
|
|
6
|
+
// REAL TS claude session driver (startClaudeCodeSession + the resume
|
|
7
|
+
// validation + the canUseTool bridge) with '@anthropic-ai/claude-agent-sdk'
|
|
8
|
+
// ALIASED to the M2.3 scripted stub
|
|
9
|
+
// (packages/commander-harness/src/scripted/ScriptedClaudeAgentSdk.res.mjs)
|
|
10
|
+
// - the exact import-seam substitution the stub was built for - and prints
|
|
11
|
+
// the stub recorder's transcript for one named scenario. The dual-impl
|
|
12
|
+
// differential in @linzumi/commander-harness
|
|
13
|
+
// (HarnessClaudeDifferentialConformance) runs the same scenario through
|
|
14
|
+
// the ReScript adapter in-process and requires the two double transcripts
|
|
15
|
+
// byte-identical.
|
|
16
|
+
//
|
|
17
|
+
// Determinism: the scenarios are scripted data, the driver's only waits
|
|
18
|
+
// are milestone polls over the in-process transcript, and the recorder
|
|
19
|
+
// rows carry no wall-clock values.
|
|
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 } 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 stubModulePath = join(
|
|
31
|
+
packageRoot,
|
|
32
|
+
'..',
|
|
33
|
+
'commander-harness',
|
|
34
|
+
'src',
|
|
35
|
+
'scripted',
|
|
36
|
+
'ScriptedClaudeAgentSdk.res.mjs'
|
|
37
|
+
);
|
|
38
|
+
const scriptModulePath = join(
|
|
39
|
+
packageRoot,
|
|
40
|
+
'..',
|
|
41
|
+
'commander-harness',
|
|
42
|
+
'src',
|
|
43
|
+
'scripted',
|
|
44
|
+
'ScriptedClaudeAgentSdkScript.res.mjs'
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const driverSource = `
|
|
48
|
+
import {
|
|
49
|
+
startClaudeCodeSession,
|
|
50
|
+
validateClaudeCodeResumeSession,
|
|
51
|
+
} from './src/claudeCodeSession';
|
|
52
|
+
import type { ClaudeCodeTranscriptEvent } from './src/claudeCodeSession';
|
|
53
|
+
// The scenario side-channel of the SAME stub instance the alias bundles in
|
|
54
|
+
// (esbuild dedupes by resolved path, so install/recorder observe the
|
|
55
|
+
// aliased SDK the session driver consumes).
|
|
56
|
+
import { install, recorder } from '${scriptModulePath.replace(/\\\\/g, '/')}';
|
|
57
|
+
|
|
58
|
+
const cwd = '/scripted/workspace';
|
|
59
|
+
const model = 'scripted-model-alpha';
|
|
60
|
+
|
|
61
|
+
// The recorded API-provenance error text (must stay byte-identical to the
|
|
62
|
+
// ReScript differential leg's scenario data).
|
|
63
|
+
const apiErrorText =
|
|
64
|
+
'API Error: 401 {"type":"error","error":{"type":"authentication_error","message":"invalid x-api-key"},"request_id":"req_scripted42"}';
|
|
65
|
+
|
|
66
|
+
const scenarios: Record<string, unknown> = {
|
|
67
|
+
'clean-turn': {
|
|
68
|
+
queries: [{ TAG: 'CleanText', assistantText: 'scripted claude answer' }],
|
|
69
|
+
startupBehavior: 'StartupOk',
|
|
70
|
+
sessionInfo: 'SessionFound',
|
|
71
|
+
sessionFirstPrompts: [],
|
|
72
|
+
},
|
|
73
|
+
'approval-accept': {
|
|
74
|
+
queries: [
|
|
75
|
+
{
|
|
76
|
+
TAG: 'ToolUseWithPermission',
|
|
77
|
+
toolName: 'Bash',
|
|
78
|
+
toolInputJson: '{"command":"curl https://api.example.test/v1/voices"}',
|
|
79
|
+
assistantText: 'voice roster fetched',
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
startupBehavior: 'StartupOk',
|
|
83
|
+
sessionInfo: 'SessionFound',
|
|
84
|
+
sessionFirstPrompts: [],
|
|
85
|
+
},
|
|
86
|
+
'approval-decline': {
|
|
87
|
+
queries: [
|
|
88
|
+
{
|
|
89
|
+
TAG: 'ToolUseWithPermission',
|
|
90
|
+
toolName: 'Bash',
|
|
91
|
+
toolInputJson: '{"command":"curl https://api.example.test/v1/voices"}',
|
|
92
|
+
assistantText: 'voice roster fetched',
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
startupBehavior: 'StartupOk',
|
|
96
|
+
sessionInfo: 'SessionFound',
|
|
97
|
+
sessionFirstPrompts: [],
|
|
98
|
+
},
|
|
99
|
+
error: {
|
|
100
|
+
queries: [{ TAG: 'ResultApiError', errorText: apiErrorText }],
|
|
101
|
+
startupBehavior: 'StartupOk',
|
|
102
|
+
sessionInfo: 'SessionFound',
|
|
103
|
+
sessionFirstPrompts: [],
|
|
104
|
+
},
|
|
105
|
+
interrupt: {
|
|
106
|
+
queries: [{ TAG: 'MidTurnPark', assistantText: 'partial answer, then' }],
|
|
107
|
+
startupBehavior: 'StartupOk',
|
|
108
|
+
sessionInfo: 'SessionFound',
|
|
109
|
+
sessionFirstPrompts: [],
|
|
110
|
+
interruptBehavior: 'YieldInterruptResult',
|
|
111
|
+
},
|
|
112
|
+
'resume-attach': {
|
|
113
|
+
queries: [{ TAG: 'CleanText', assistantText: 'resumed answer' }],
|
|
114
|
+
startupBehavior: 'StartupOk',
|
|
115
|
+
sessionInfo: 'SessionFound',
|
|
116
|
+
sessionFirstPrompts: [],
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// The runner-shaped streaming input queue (the live multi-turn channel:
|
|
121
|
+
// only the owner closes it).
|
|
122
|
+
function createInputQueue() {
|
|
123
|
+
const pending: unknown[] = [];
|
|
124
|
+
const waiters: Array<(step: { done: boolean; value: unknown }) => void> = [];
|
|
125
|
+
let closed = false;
|
|
126
|
+
return {
|
|
127
|
+
messages: {
|
|
128
|
+
[Symbol.asyncIterator]() {
|
|
129
|
+
return {
|
|
130
|
+
next(): Promise<{ done: boolean; value: unknown }> {
|
|
131
|
+
if (pending.length > 0) {
|
|
132
|
+
return Promise.resolve({ done: false, value: pending.shift() });
|
|
133
|
+
}
|
|
134
|
+
if (closed) {
|
|
135
|
+
return Promise.resolve({ done: true, value: undefined });
|
|
136
|
+
}
|
|
137
|
+
return new Promise((resolve) => waiters.push(resolve));
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
push(message: unknown) {
|
|
143
|
+
const waiter = waiters.shift();
|
|
144
|
+
if (waiter !== undefined) {
|
|
145
|
+
waiter({ done: false, value: message });
|
|
146
|
+
} else {
|
|
147
|
+
pending.push(message);
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
close() {
|
|
151
|
+
closed = true;
|
|
152
|
+
while (waiters.length > 0) {
|
|
153
|
+
waiters.shift()!({ done: true, value: undefined });
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function userMessage(text: string) {
|
|
160
|
+
return {
|
|
161
|
+
type: 'user' as const,
|
|
162
|
+
message: { role: 'user' as const, content: text },
|
|
163
|
+
parent_tool_use_id: null,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
168
|
+
|
|
169
|
+
async function waitFor(predicate: () => boolean): Promise<void> {
|
|
170
|
+
while (!predicate()) {
|
|
171
|
+
await sleep(5);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function transcript(): string[] {
|
|
176
|
+
return (recorder as { events: Array<{ label: string; detail: string }> }).events.map(
|
|
177
|
+
(event) => event.label + '|' + event.detail
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
async function run(): Promise<void> {
|
|
182
|
+
const scenarioName = process.argv[2];
|
|
183
|
+
const scenario = scenarios[scenarioName ?? ''];
|
|
184
|
+
if (scenario === undefined) {
|
|
185
|
+
throw new Error('unknown scenario: ' + String(scenarioName));
|
|
186
|
+
}
|
|
187
|
+
install(scenario);
|
|
188
|
+
|
|
189
|
+
const events: ClaudeCodeTranscriptEvent[] = [];
|
|
190
|
+
const has = (type: string) => events.some((event) => event.type === type);
|
|
191
|
+
let controls:
|
|
192
|
+
| { interrupt: () => Promise<void> }
|
|
193
|
+
| undefined;
|
|
194
|
+
const queue = createInputQueue();
|
|
195
|
+
|
|
196
|
+
if (scenarioName === 'resume-attach') {
|
|
197
|
+
await validateClaudeCodeResumeSession({
|
|
198
|
+
cwd,
|
|
199
|
+
sessionId: 'scripted-claude-session-resumed-7',
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const sessionPromise = startClaudeCodeSession({
|
|
204
|
+
cwd,
|
|
205
|
+
prompt: '',
|
|
206
|
+
streamingInput: queue,
|
|
207
|
+
developerInstructions: undefined,
|
|
208
|
+
model,
|
|
209
|
+
permissionMode: 'default',
|
|
210
|
+
...(scenarioName === 'resume-attach'
|
|
211
|
+
? { resumeSessionId: 'scripted-claude-session-resumed-7' }
|
|
212
|
+
: {}),
|
|
213
|
+
canUseTool: async () =>
|
|
214
|
+
scenarioName === 'approval-decline'
|
|
215
|
+
? { type: 'deny' as const, message: 'not on this machine' }
|
|
216
|
+
: { type: 'allow' as const },
|
|
217
|
+
onSessionControls: (liveControls) => {
|
|
218
|
+
controls = liveControls;
|
|
219
|
+
},
|
|
220
|
+
onTranscriptEvent: (event) => {
|
|
221
|
+
events.push(event);
|
|
222
|
+
},
|
|
223
|
+
});
|
|
224
|
+
// The session settles by scenario design; failures are the error leg's
|
|
225
|
+
// expected outcome and are re-checked below.
|
|
226
|
+
const settled = sessionPromise.then(
|
|
227
|
+
() => undefined,
|
|
228
|
+
(error: unknown) => (error instanceof Error ? error.message : String(error))
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
queue.push(userMessage('do the thing'));
|
|
232
|
+
|
|
233
|
+
switch (scenarioName) {
|
|
234
|
+
case 'error': {
|
|
235
|
+
// The TS session driver THROWS on the result error after emitting
|
|
236
|
+
// session_failed; the transcript snapshot is taken AT the terminal
|
|
237
|
+
// (the abandoned generator never closes the stub query - the
|
|
238
|
+
// documented TS lifecycle - so the close rows are not part of this
|
|
239
|
+
// scenario's comparison surface).
|
|
240
|
+
await waitFor(() => has('session_failed'));
|
|
241
|
+
const failure = await settled;
|
|
242
|
+
if (failure === undefined) {
|
|
243
|
+
throw new Error('the error scenario must fail the session');
|
|
244
|
+
}
|
|
245
|
+
process.stdout.write(JSON.stringify(transcript()) + '\\n');
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
case 'interrupt': {
|
|
249
|
+
await waitFor(() => has('assistant_message'));
|
|
250
|
+
await controls!.interrupt();
|
|
251
|
+
await waitFor(() => has('turn_interrupted'));
|
|
252
|
+
queue.close();
|
|
253
|
+
// An interrupted single-turn session settles as the documented
|
|
254
|
+
// no-text-response failure; the transcript is the comparison
|
|
255
|
+
// surface.
|
|
256
|
+
await settled;
|
|
257
|
+
process.stdout.write(JSON.stringify(transcript()) + '\\n');
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
default: {
|
|
261
|
+
await waitFor(() => has('turn_completed'));
|
|
262
|
+
queue.close();
|
|
263
|
+
const failure = await settled;
|
|
264
|
+
if (failure !== undefined) {
|
|
265
|
+
throw new Error('scenario ' + scenarioName + ' must complete: ' + failure);
|
|
266
|
+
}
|
|
267
|
+
process.stdout.write(JSON.stringify(transcript()) + '\\n');
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
run().then(
|
|
273
|
+
() => process.exit(0),
|
|
274
|
+
(error) => {
|
|
275
|
+
process.stderr.write(String(error && error.stack ? error.stack : error) + '\\n');
|
|
276
|
+
process.exit(1);
|
|
277
|
+
}
|
|
278
|
+
);
|
|
279
|
+
`;
|
|
280
|
+
|
|
281
|
+
const outDir = join(packageRoot, '.differential');
|
|
282
|
+
const outPath = join(outDir, 'harness-claude-parity-oracle.mjs');
|
|
283
|
+
|
|
284
|
+
await mkdir(outDir, { recursive: true });
|
|
285
|
+
|
|
286
|
+
await build({
|
|
287
|
+
stdin: {
|
|
288
|
+
contents: driverSource,
|
|
289
|
+
resolveDir: packageRoot,
|
|
290
|
+
sourcefile: 'harness-claude-parity-driver.ts',
|
|
291
|
+
loader: 'ts',
|
|
292
|
+
},
|
|
293
|
+
bundle: true,
|
|
294
|
+
platform: 'node',
|
|
295
|
+
target: 'node20',
|
|
296
|
+
format: 'esm',
|
|
297
|
+
outfile: outPath,
|
|
298
|
+
minify: false,
|
|
299
|
+
sourcemap: false,
|
|
300
|
+
legalComments: 'none',
|
|
301
|
+
logLevel: 'silent',
|
|
302
|
+
external: ['ws', 'undici', 'blessed'],
|
|
303
|
+
alias: {
|
|
304
|
+
'@anthropic-ai/claude-agent-sdk': stubModulePath,
|
|
305
|
+
},
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
process.stdout.write(outPath + '\n');
|