@linzumi/cli 1.0.93 → 1.0.95
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 +428 -428
- package/package.json +1 -1
- package/scripts/build-protocol-parity-oracle.mjs +192 -0
package/package.json
CHANGED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
// Spec: kandan/plans/2026-07-10-compute-nodes-rescript-commander-zero-ts-program.md
|
|
2
|
+
// (M3 cluster 1, protocol-types).
|
|
3
|
+
// Relationship: Builds the TS-side PARITY ORACLE for the protocol/type
|
|
4
|
+
// cluster of the ReScript commander port. The oracle bundles the REAL TS
|
|
5
|
+
// protocol modules (protocol.ts, json.ts, localCodexMessageState.ts,
|
|
6
|
+
// terminalFailureRetry.ts, localConfig.ts) behind a one-shot batch driver:
|
|
7
|
+
// it reads a JSON array of cases on stdin and writes a JSON array of
|
|
8
|
+
// results on stdout. The ReScript package's parity conformance
|
|
9
|
+
// (packages/linzumi-cli-rescript/src/parity/ProtocolParityConformance.res)
|
|
10
|
+
// drives the SAME inputs through the sury schemas/functions and asserts
|
|
11
|
+
// accept/reject/normalized-output equivalence - so the two protocol layers
|
|
12
|
+
// cannot drift silently.
|
|
13
|
+
//
|
|
14
|
+
// Like build-differential-entry.mjs, the output is a local test artifact
|
|
15
|
+
// (.differential/ is gitignored, never published) and stays unminified for
|
|
16
|
+
// debuggability.
|
|
17
|
+
import { mkdir } from 'node:fs/promises';
|
|
18
|
+
import { dirname, join } from 'node:path';
|
|
19
|
+
import { fileURLToPath } from 'node:url';
|
|
20
|
+
import { build } from 'esbuild';
|
|
21
|
+
|
|
22
|
+
const packageRoot = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
23
|
+
|
|
24
|
+
const driverSource = `
|
|
25
|
+
import { mkdtempSync, writeFileSync } from 'node:fs';
|
|
26
|
+
import { tmpdir } from 'node:os';
|
|
27
|
+
import { join } from 'node:path';
|
|
28
|
+
import {
|
|
29
|
+
isJsonObject,
|
|
30
|
+
parseJsonObject,
|
|
31
|
+
requireString,
|
|
32
|
+
requirePositiveInteger,
|
|
33
|
+
extractCodexIds,
|
|
34
|
+
} from './src/protocol';
|
|
35
|
+
import {
|
|
36
|
+
objectValue,
|
|
37
|
+
arrayValue,
|
|
38
|
+
stringValue,
|
|
39
|
+
integerValue,
|
|
40
|
+
stringListValue,
|
|
41
|
+
parseJsonObjectOrUndefined,
|
|
42
|
+
} from './src/json';
|
|
43
|
+
import {
|
|
44
|
+
approvalRequestKey,
|
|
45
|
+
codexApprovalMessageState,
|
|
46
|
+
fleetBreakerHoldReason,
|
|
47
|
+
parkedAsOwnTurnQueuedReason,
|
|
48
|
+
parkedAsOwnTurnReasonDetail,
|
|
49
|
+
processingReasonForCodexNotification,
|
|
50
|
+
queuedBehindEarlierMessagesReason,
|
|
51
|
+
queuedBehindRunningTurnReason,
|
|
52
|
+
queuedBehindReasonPrefix,
|
|
53
|
+
queuedBehindRunningTurnReasonPrefix,
|
|
54
|
+
resumingAfterStreamStallReason,
|
|
55
|
+
steeredIntoRunningTurnReason,
|
|
56
|
+
} from './src/localCodexMessageState';
|
|
57
|
+
import { parseFleetBreakerPayload } from './src/fleetBreaker';
|
|
58
|
+
import {
|
|
59
|
+
fateRetryable,
|
|
60
|
+
isTerminalFailureFate,
|
|
61
|
+
terminalFailureClasses,
|
|
62
|
+
terminalFailureFate,
|
|
63
|
+
terminalFailureFates,
|
|
64
|
+
terminalFailureRetryableStamp,
|
|
65
|
+
} from './src/terminalFailureRetry';
|
|
66
|
+
import { readLocalConfig, readLocalSignupAuth } from './src/localConfig';
|
|
67
|
+
|
|
68
|
+
const jsonHelpers = {
|
|
69
|
+
isJsonObject,
|
|
70
|
+
parseJsonObject,
|
|
71
|
+
requireString,
|
|
72
|
+
requirePositiveInteger,
|
|
73
|
+
extractCodexIds,
|
|
74
|
+
objectValue,
|
|
75
|
+
arrayValue,
|
|
76
|
+
stringValue,
|
|
77
|
+
integerValue,
|
|
78
|
+
stringListValue,
|
|
79
|
+
parseJsonObjectOrUndefined,
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const messageStateFns = {
|
|
83
|
+
approvalRequestKey,
|
|
84
|
+
codexApprovalMessageState,
|
|
85
|
+
parkedAsOwnTurnQueuedReason,
|
|
86
|
+
parkedAsOwnTurnReasonDetail,
|
|
87
|
+
processingReasonForCodexNotification,
|
|
88
|
+
queuedBehindEarlierMessagesReason,
|
|
89
|
+
queuedBehindRunningTurnReason,
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// Encode a call outcome so undefined stays distinguishable from null after
|
|
93
|
+
// JSON serialization.
|
|
94
|
+
function outcome(run) {
|
|
95
|
+
try {
|
|
96
|
+
const value = run();
|
|
97
|
+
return value === undefined ? { defined: false } : { defined: true, value };
|
|
98
|
+
} catch (error) {
|
|
99
|
+
return { threw: true, message: error instanceof Error ? error.message : String(error) };
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function handle(testCase) {
|
|
104
|
+
switch (testCase.op) {
|
|
105
|
+
case 'jsonHelper': {
|
|
106
|
+
const fn = jsonHelpers[testCase.fn];
|
|
107
|
+
if (fn === undefined) {
|
|
108
|
+
return { threw: true, message: 'unknown jsonHelper ' + testCase.fn };
|
|
109
|
+
}
|
|
110
|
+
return outcome(() => fn(...testCase.args));
|
|
111
|
+
}
|
|
112
|
+
case 'messageState': {
|
|
113
|
+
const fn = messageStateFns[testCase.fn];
|
|
114
|
+
if (fn === undefined) {
|
|
115
|
+
return { threw: true, message: 'unknown messageState fn ' + testCase.fn };
|
|
116
|
+
}
|
|
117
|
+
return outcome(() => fn(...testCase.args));
|
|
118
|
+
}
|
|
119
|
+
case 'constants':
|
|
120
|
+
return {
|
|
121
|
+
resumingAfterStreamStallReason,
|
|
122
|
+
steeredIntoRunningTurnReason,
|
|
123
|
+
queuedBehindReasonPrefix,
|
|
124
|
+
queuedBehindRunningTurnReasonPrefix,
|
|
125
|
+
fleetBreakerHoldReason,
|
|
126
|
+
};
|
|
127
|
+
case 'fleetBreakerParse':
|
|
128
|
+
return outcome(() => parseFleetBreakerPayload(testCase.value));
|
|
129
|
+
case 'fateTables': {
|
|
130
|
+
const retryableByFate = {};
|
|
131
|
+
for (const fate of terminalFailureFates) {
|
|
132
|
+
retryableByFate[fate] = fateRetryable(fate);
|
|
133
|
+
}
|
|
134
|
+
const fateByClass = {};
|
|
135
|
+
const stampByClass = {};
|
|
136
|
+
for (const failureClass of terminalFailureClasses) {
|
|
137
|
+
fateByClass[failureClass] = terminalFailureFate(failureClass);
|
|
138
|
+
stampByClass[failureClass] = terminalFailureRetryableStamp(failureClass);
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
fates: [...terminalFailureFates],
|
|
142
|
+
retryableByFate,
|
|
143
|
+
classes: [...terminalFailureClasses],
|
|
144
|
+
fateByClass,
|
|
145
|
+
stampByClass,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
case 'isFate':
|
|
149
|
+
return outcome(() => isTerminalFailureFate(testCase.value));
|
|
150
|
+
case 'localConfig': {
|
|
151
|
+
const dir = mkdtempSync(join(tmpdir(), 'linzumi-protocol-parity-'));
|
|
152
|
+
const path = join(dir, 'config.json');
|
|
153
|
+
writeFileSync(path, testCase.contents, 'utf8');
|
|
154
|
+
const config = outcome(() => readLocalConfig(path));
|
|
155
|
+
const signupAuth = outcome(() => readLocalSignupAuth(path));
|
|
156
|
+
return { config, signupAuth };
|
|
157
|
+
}
|
|
158
|
+
default:
|
|
159
|
+
return { threw: true, message: 'unknown op ' + String(testCase.op) };
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
let stdin = '';
|
|
164
|
+
process.stdin.setEncoding('utf8');
|
|
165
|
+
for await (const chunk of process.stdin) {
|
|
166
|
+
stdin += chunk;
|
|
167
|
+
}
|
|
168
|
+
const cases = JSON.parse(stdin);
|
|
169
|
+
process.stdout.write(JSON.stringify(cases.map(handle)));
|
|
170
|
+
`;
|
|
171
|
+
|
|
172
|
+
await mkdir(join(packageRoot, '.differential'), { recursive: true });
|
|
173
|
+
|
|
174
|
+
await build({
|
|
175
|
+
stdin: {
|
|
176
|
+
contents: driverSource,
|
|
177
|
+
resolveDir: packageRoot,
|
|
178
|
+
sourcefile: 'protocol-parity-driver.ts',
|
|
179
|
+
loader: 'ts',
|
|
180
|
+
},
|
|
181
|
+
bundle: true,
|
|
182
|
+
platform: 'node',
|
|
183
|
+
target: 'node20',
|
|
184
|
+
format: 'esm',
|
|
185
|
+
outfile: join(packageRoot, '.differential/protocol-parity-oracle.mjs'),
|
|
186
|
+
minify: false,
|
|
187
|
+
sourcemap: false,
|
|
188
|
+
legalComments: 'none',
|
|
189
|
+
// The protocol modules are dependency-light; anything that leaks in from
|
|
190
|
+
// the wider commander graph stays external exactly like the entry build.
|
|
191
|
+
external: ['ws', 'undici', 'blessed', '@anthropic-ai/claude-agent-sdk'],
|
|
192
|
+
});
|