@linzumi/cli 1.0.272 → 1.0.274

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 (44) 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 +355 -314
  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 +495 -495
  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/check-package-size-budget.mjs +9 -0
  11. package/scripts/build-auth-parity-oracle.mjs +0 -709
  12. package/scripts/build-canonical-codex-transpiler-oracle.mjs +0 -93
  13. package/scripts/build-config-identity-parity-oracle.mjs +0 -526
  14. package/scripts/build-core-commander-seams-parity-oracle.mjs +0 -799
  15. package/scripts/build-core-daemon-parity-oracle.mjs +0 -573
  16. package/scripts/build-core-dispatch-input-queue-parity-oracle.mjs +0 -225
  17. package/scripts/build-core-fate-ladder-parity-oracle.mjs +0 -350
  18. package/scripts/build-core-generation-overlap-parity-oracle.mjs +0 -292
  19. package/scripts/build-core-integration-parity-oracle.mjs +0 -453
  20. package/scripts/build-core-lifecycle-guards-parity-oracle.mjs +0 -443
  21. package/scripts/build-core-lock-parity-oracle.mjs +0 -462
  22. package/scripts/build-core-reconnect-resume-parity-oracle.mjs +0 -365
  23. package/scripts/build-core-startup-resume-scan-parity-oracle.mjs +0 -296
  24. package/scripts/build-core-supervisor-parity-oracle.mjs +0 -781
  25. package/scripts/build-cross-harness-failover-oracle.mjs +0 -349
  26. package/scripts/build-editor-parity-oracle.mjs +0 -1525
  27. package/scripts/build-forwarding-parity-oracle.mjs +0 -1390
  28. package/scripts/build-harness-claude-parity-oracle.mjs +0 -407
  29. package/scripts/build-harness-codex-parity-oracle.mjs +0 -479
  30. package/scripts/build-mcp-parity-oracle.mjs +0 -412
  31. package/scripts/build-mcp-selector-parity-oracle.mjs +0 -65
  32. package/scripts/build-onboarding-discovery-parity-oracle.mjs +0 -388
  33. package/scripts/build-onboarding-flow-parity-oracle.mjs +0 -562
  34. package/scripts/build-onboarding-gateway-parity-oracle.mjs +0 -313
  35. package/scripts/build-onboarding-support-parity-oracle.mjs +0 -519
  36. package/scripts/build-pipeline-parity-oracle.mjs +0 -614
  37. package/scripts/build-protocol-parity-oracle.mjs +0 -398
  38. package/scripts/build-queue-parity-oracle.mjs +0 -1012
  39. package/scripts/build-session-registry-parity-oracle.mjs +0 -582
  40. package/scripts/build-transport-parity-oracle.mjs +0 -694
  41. package/scripts/build-tui-parity-oracle.mjs +0 -577
  42. package/scripts/build-vm-sandbox-parity-oracle.mjs +0 -1281
  43. package/scripts/build-worker-entry-parity-oracle.mjs +0 -424
  44. package/scripts/build-worker-spawn-parity-oracle.mjs +0 -823
@@ -1,412 +0,0 @@
1
- // Spec: kandan/plans/2026-07-10-compute-nodes-rescript-commander-zero-ts-program.md
2
- // (M3 cluster 14, mcp).
3
- // Wake schema parity: spec/agent-process-lifecycle-rules.md
4
- // :agent-process-lifecycle/rule-08-agent-scheduled-wakes.
5
- // Relationship: Builds the TS-side PARITY ORACLE for the mcp cluster of the
6
- // ReScript commander port. Two artifacts:
7
- //
8
- // 1. .differential/mcp-parity-oracle.mjs - the REAL TS mcp modules
9
- // (mcpConfig.ts, mcpServer.ts, mcpServerEntry.ts, linzumiApiClient.ts,
10
- // devServiceRegistry.ts, mediaGuidance.ts) behind a one-shot stdin/stdout
11
- // JSON batch driver. The ReScript parity conformance
12
- // (packages/linzumi-cli-rescript/src/parity/McpParityConformance.res)
13
- // drives the SAME inputs through the ported modules and compares
14
- // serialized results byte for byte. The `toolSurface` op runs the REAL
15
- // registerLinzumiMcpTools against a capturing fake server + a recording
16
- // fetch, so tool names/descriptions/schema verdicts/handler request
17
- // mappings are all differential.
18
- //
19
- // 2. .differential/mcp-server-oracle-entry.mjs - a runnable bundle of the
20
- // REAL src/mcpServerEntry.ts, so the flow suite
21
- // (McpLawsConformance.res) can spawn the TS MCP server as a stdio child
22
- // next to the ReScript entry and assert byte-equal JSON-RPC traffic,
23
- // stdout/stderr, and scripted-backend requests.
24
- //
25
- // Like the sibling oracles, both outputs are local test artifacts
26
- // (.differential/ is gitignored, never published) and stay unminified for
27
- // debuggability.
28
- import { mkdir } from 'node:fs/promises';
29
- import { dirname, join } from 'node:path';
30
- import { fileURLToPath } from 'node:url';
31
- import { build } from 'esbuild';
32
-
33
- const packageRoot = dirname(dirname(fileURLToPath(import.meta.url)));
34
-
35
- const driverSource = `
36
- import {
37
- claudeCodeMcpConfigJson,
38
- claudeCodeSdkMcpServers,
39
- codexMcpConfigArgs,
40
- codexMcpConfigToml,
41
- linzumiMcpCommandForProcess,
42
- linzumiMcpServerConfig,
43
- } from './src/mcpConfig';
44
- import {
45
- absolutizeAttachmentUrls,
46
- customEmojiNameSchema,
47
- devServiceStatusJson,
48
- devServicesOptionsFromEnv,
49
- mcpHelpText,
50
- mcpJsonResult,
51
- mcpOperatingMode,
52
- mcpToolScope,
53
- normalizeCustomEmojiNameForSchema,
54
- paramsWithDefaultThread,
55
- registerLinzumiMcpTools,
56
- resolveLinzumiUploadUrl,
57
- strictFlagValues,
58
- targetWithDefaultThread,
59
- textModeGatedMessagePostingMcpTools,
60
- uiControlToolResult,
61
- withUploadChannelRemediation,
62
- } from './src/mcpServer';
63
- import { createLinzumiMcpApiClient } from './src/linzumiApiClient';
64
- import {
65
- devServiceLogPath,
66
- devServiceRecordBytes,
67
- devServiceWatchdogProgram,
68
- devServiceWatchdogSpawn,
69
- devServicesScopeDir,
70
- normalizeDevServiceName,
71
- parseDevServiceRecord,
72
- } from './src/devServiceRegistry';
73
- import { linzumiMarkdownMediaGuidance } from './src/mediaGuidance';
74
- import { z } from 'zod/v3';
75
-
76
- // mcpServerEntry.ts auto-runs when import.meta.url matches argv[1] - true for
77
- // this bundle when node runs it directly. Import it DYNAMICALLY behind an
78
- // argv[1] guard so the real module's direct-invocation gate stays untouched
79
- // but cannot fire inside the oracle.
80
- const argv1ForEntryImport = process.argv[1];
81
- process.argv[1] = '/linzumi-mcp-parity-oracle-guard';
82
- const { mcpServerEntryArgs } = await import('./src/mcpServerEntry');
83
- process.argv[1] = argv1ForEntryImport;
84
-
85
- // Encode a call outcome so undefined stays distinguishable from null after
86
- // JSON serialization.
87
- function outcome(run) {
88
- try {
89
- const value = run();
90
- return value === undefined ? { defined: false } : { defined: true, value };
91
- } catch (error) {
92
- return { threw: true, message: error instanceof Error ? error.message : String(error) };
93
- }
94
- }
95
-
96
- async function asyncOutcome(run) {
97
- try {
98
- const value = await run();
99
- return value === undefined ? { defined: false } : { defined: true, value };
100
- } catch (error) {
101
- return { threw: true, message: error instanceof Error ? error.message : String(error) };
102
- }
103
- }
104
-
105
- function safeParseVerdict(schema, input) {
106
- const parsed = schema.safeParse(input);
107
- return parsed.success
108
- ? { success: true, data: parsed.data === undefined ? null : parsed.data }
109
- : {
110
- success: false,
111
- issues: JSON.parse(JSON.stringify(parsed.error.issues)),
112
- };
113
- }
114
-
115
- // A recording fetch for the api-client seam: every request is captured and
116
- // answered from the scripted queue (default {ok: true}).
117
- function recordingFetch(script) {
118
- const requests = [];
119
- const responses = [...(script?.responses ?? [])];
120
- const fetchImpl = async (url, init) => {
121
- requests.push({
122
- url: String(url),
123
- method: init?.method ?? 'GET',
124
- authorization: init?.headers?.authorization ?? null,
125
- contentType: init?.headers?.['content-type'] ?? null,
126
- body: typeof init?.body === 'string' ? init.body : null,
127
- });
128
- const next = responses.shift() ?? { status: 200, body: { ok: true } };
129
- return new Response(JSON.stringify(next.body), {
130
- status: next.status ?? 200,
131
- headers: { 'content-type': 'application/json' },
132
- });
133
- };
134
- return { requests, fetchImpl };
135
- }
136
-
137
- async function toolSurface(testCase) {
138
- const captured = [];
139
- const handlers = new Map();
140
- const schemaShape = (schema) => {
141
- if (schema?.shape !== undefined) {
142
- return schema.shape;
143
- }
144
- if (schema?._def?.schema !== undefined) {
145
- return schemaShape(schema._def.schema);
146
- }
147
- throw new Error('captured MCP schema does not expose an object shape');
148
- };
149
- const fakeServer = {
150
- tool(name, description, shape, handler) {
151
- captured.push({ name, description, schemaKeys: Object.keys(shape) });
152
- handlers.set(name, { schema: z.object(shape), handler });
153
- },
154
- registerTool(name, config, handler) {
155
- const shape = schemaShape(config.inputSchema);
156
- captured.push({ name, description: config.description, schemaKeys: Object.keys(shape) });
157
- handlers.set(name, { schema: config.inputSchema, handler });
158
- },
159
- };
160
- const { requests, fetchImpl } = recordingFetch(testCase.script);
161
- const client = createLinzumiMcpApiClient({
162
- kandanUrl: testCase.options.apiUrl,
163
- accessToken: 'synthetic-parity-token',
164
- authMode: testCase.options.authMode,
165
- operatingMode: testCase.options.operatingMode,
166
- fetchImpl,
167
- });
168
- registerLinzumiMcpTools(fakeServer, {
169
- client,
170
- toolScope: testCase.options.toolScope,
171
- operatingMode: testCase.options.operatingMode,
172
- cwd: testCase.options.cwd,
173
- kandanUrl: testCase.options.apiUrl,
174
- defaultThreadId: testCase.options.defaultThreadId ?? undefined,
175
- ownerUsername: testCase.options.ownerUsername ?? undefined,
176
- agentSession: testCase.options.agentSession === true,
177
- documentSurfaces: testCase.options.documentSurfaces === true,
178
- multiAgentJobs: testCase.options.multiAgentJobs === true,
179
- devServices:
180
- testCase.options.devServices === undefined || testCase.options.devServices === null
181
- ? undefined
182
- : testCase.options.devServices,
183
- });
184
-
185
- const probes = [];
186
- for (const probe of testCase.probes ?? []) {
187
- const entry = handlers.get(probe.tool);
188
- probes.push(
189
- entry === undefined
190
- ? { tool: probe.tool, missing: true }
191
- : { tool: probe.tool, verdict: safeParseVerdict(entry.schema, probe.input) }
192
- );
193
- }
194
-
195
- const calls = [];
196
- for (const call of testCase.calls ?? []) {
197
- const entry = handlers.get(call.tool);
198
- if (entry === undefined) {
199
- calls.push({ tool: call.tool, missing: true });
200
- continue;
201
- }
202
- const before = requests.length;
203
- const result = await asyncOutcome(() => entry.handler(call.params));
204
- calls.push({ tool: call.tool, result, requests: requests.slice(before) });
205
- }
206
-
207
- return { tools: captured, probes, calls };
208
- }
209
-
210
- async function handle(testCase) {
211
- switch (testCase.op) {
212
- case 'serverConfig': {
213
- const config = outcome(() => linzumiMcpServerConfig(testCase.options));
214
- if (config.threw === true || config.defined !== true) {
215
- return { config };
216
- }
217
- return {
218
- config,
219
- // Both approval-scoping branches (#3819 security P1): the pin rides
220
- // codexArgs ONLY for granular never-equivalent sessions.
221
- codexArgs: outcome(() =>
222
- codexMcpConfigArgs(config.value, {
223
- neverEquivalentGranularApprovalPolicy: false,
224
- })
225
- ),
226
- codexArgsNeverEquivalentGranular: outcome(() =>
227
- codexMcpConfigArgs(config.value, {
228
- neverEquivalentGranularApprovalPolicy: true,
229
- })
230
- ),
231
- codexToml: outcome(() => codexMcpConfigToml(config.value)),
232
- claudeCodeJson: outcome(() => claudeCodeMcpConfigJson(config.value)),
233
- claudeSdkMcpServers: outcome(() =>
234
- claudeCodeSdkMcpServers(config.value)
235
- ),
236
- };
237
- }
238
- case 'commandForProcess':
239
- return outcome(() =>
240
- linzumiMcpCommandForProcess(
241
- testCase.processExecPath,
242
- testCase.scriptPath ?? undefined,
243
- testCase.execArgv ?? []
244
- )
245
- );
246
- case 'strictFlags':
247
- return outcome(() => [...strictFlagValues(testCase.args).entries()]);
248
- case 'helpText':
249
- return mcpHelpText();
250
- case 'mediaGuidance':
251
- return linzumiMarkdownMediaGuidance;
252
- case 'entryArgs':
253
- return mcpServerEntryArgs(testCase.argv);
254
- case 'operatingMode':
255
- return outcome(() => mcpOperatingMode(testCase.value ?? undefined));
256
- case 'toolScope':
257
- return outcome(() => mcpToolScope(testCase.value ?? undefined));
258
- case 'textModeGatedTools':
259
- return [...textModeGatedMessagePostingMcpTools];
260
- case 'mcpJsonResult':
261
- return mcpJsonResult(testCase.value);
262
- case 'uiControlResult':
263
- return await asyncOutcome(() =>
264
- uiControlToolResult(
265
- testCase.throwMessage === undefined || testCase.throwMessage === null
266
- ? Promise.resolve(testCase.value)
267
- : Promise.reject(new Error(testCase.throwMessage))
268
- )
269
- );
270
- case 'uploadRemediation': {
271
- const mapped = withUploadChannelRemediation(new Error(testCase.message));
272
- return {
273
- message: mapped instanceof Error ? mapped.message : String(mapped),
274
- causeMessage:
275
- mapped instanceof Error && mapped.cause instanceof Error
276
- ? mapped.cause.message
277
- : null,
278
- };
279
- }
280
- case 'targetWithDefaultThread':
281
- return targetWithDefaultThread(testCase.target, testCase.defaultThreadId ?? undefined);
282
- case 'paramsWithDefaultThread':
283
- return paramsWithDefaultThread(testCase.params, testCase.defaultThreadId ?? undefined);
284
- case 'resolveUploadUrl':
285
- return outcome(() => resolveLinzumiUploadUrl(testCase.apiUrl, testCase.uploadUrl));
286
- case 'absolutize':
287
- return outcome(() => absolutizeAttachmentUrls(testCase.apiUrl, testCase.result));
288
- case 'emojiNormalize':
289
- return normalizeCustomEmojiNameForSchema(testCase.value);
290
- case 'emojiSchemaVerdict':
291
- return safeParseVerdict(customEmojiNameSchema, testCase.value);
292
- case 'devServicesOptionsFromEnv':
293
- return outcome(() => devServicesOptionsFromEnv(testCase.env));
294
- case 'devServicesScopeDir':
295
- return devServicesScopeDir(testCase.scope);
296
- case 'normalizeDevServiceName':
297
- return outcome(() => normalizeDevServiceName(testCase.name));
298
- case 'devServiceLogPath':
299
- return devServiceLogPath(testCase.scopeDir, testCase.name);
300
- case 'parseDevServiceRecord':
301
- return outcome(() => parseDevServiceRecord(testCase.value));
302
- case 'devServiceRecordBytes':
303
- return devServiceRecordBytes(testCase.record);
304
- case 'watchdogProgram':
305
- return devServiceWatchdogProgram();
306
- case 'watchdogSpawn':
307
- return devServiceWatchdogSpawn(testCase.nodeExecPath, testCase.config);
308
- case 'devServiceStatusJson':
309
- return devServiceStatusJson({
310
- record: testCase.status.record,
311
- liveness: testCase.status.liveness,
312
- portProbes: testCase.status.portProbes,
313
- lastExit: testCase.status.lastExit ?? undefined,
314
- failure: testCase.status.failure ?? undefined,
315
- });
316
- case 'devServiceStatusOutputBytes':
317
- return JSON.stringify(devServiceStatusJson({
318
- record: testCase.status.record,
319
- liveness: testCase.status.liveness,
320
- portProbes: testCase.status.portProbes,
321
- lastExit: testCase.status.lastExit ?? undefined,
322
- failure: testCase.status.failure ?? undefined,
323
- }));
324
- case 'devServiceMcpResponseBytes': {
325
- const status = devServiceStatusJson({
326
- record: testCase.status.record,
327
- liveness: testCase.status.liveness,
328
- portProbes: testCase.status.portProbes,
329
- lastExit: testCase.status.lastExit ?? undefined,
330
- failure: testCase.status.failure ?? undefined,
331
- });
332
- return JSON.stringify(mcpJsonResult({services: [status]}));
333
- }
334
- case 'toolSurface':
335
- return await toolSurface(testCase);
336
- case 'clientCall': {
337
- // One api-client method driven directly (the full method->endpoint
338
- // map, including the runner-internal endpoints no MCP tool calls).
339
- const { requests, fetchImpl } = recordingFetch(testCase.script);
340
- const client = createLinzumiMcpApiClient({
341
- kandanUrl: testCase.apiUrl,
342
- accessToken: 'synthetic-parity-token',
343
- authMode: testCase.authMode ?? undefined,
344
- operatingMode: testCase.operatingMode ?? undefined,
345
- fetchImpl,
346
- });
347
- const method = client[testCase.method];
348
- if (typeof method !== 'function') {
349
- return { threw: true, message: 'unknown client method ' + testCase.method };
350
- }
351
- const result = await asyncOutcome(() => method(testCase.params));
352
- return { result, requests };
353
- }
354
- default:
355
- return { threw: true, message: 'unknown op ' + String(testCase.op) };
356
- }
357
- }
358
-
359
- let stdin = '';
360
- process.stdin.setEncoding('utf8');
361
- for await (const chunk of process.stdin) {
362
- stdin += chunk;
363
- }
364
- const cases = JSON.parse(stdin);
365
- const results = [];
366
- for (const testCase of cases) {
367
- results.push(await handle(testCase));
368
- }
369
- process.stdout.write(JSON.stringify(results));
370
- `;
371
-
372
- await mkdir(join(packageRoot, '.differential'), { recursive: true });
373
-
374
- const banner = {
375
- js: "import { createRequire } from 'node:module';\nconst require = createRequire(import.meta.url);",
376
- };
377
-
378
- await build({
379
- stdin: {
380
- contents: driverSource,
381
- resolveDir: packageRoot,
382
- sourcefile: 'mcp-parity-driver.ts',
383
- loader: 'ts',
384
- },
385
- bundle: true,
386
- platform: 'node',
387
- target: 'node20',
388
- format: 'esm',
389
- outfile: join(packageRoot, '.differential/mcp-parity-oracle.mjs'),
390
- minify: false,
391
- sourcemap: false,
392
- legalComments: 'none',
393
- external: ['ws', 'undici', 'blessed', '@anthropic-ai/claude-agent-sdk'],
394
- banner,
395
- });
396
-
397
- // The runnable REAL TS MCP server entry, for the flow-parity legs: same code
398
- // path as `linzumi mcp ...` (mcpServerEntry strips the leading 'mcp' and
399
- // dispatches through runMcpCommand), bundled unminified like the driver.
400
- await build({
401
- entryPoints: [join(packageRoot, 'src/mcpServerEntry.ts')],
402
- bundle: true,
403
- platform: 'node',
404
- target: 'node20',
405
- format: 'esm',
406
- outfile: join(packageRoot, '.differential/mcp-server-oracle-entry.mjs'),
407
- minify: false,
408
- sourcemap: false,
409
- legalComments: 'none',
410
- external: ['ws', 'undici', 'blessed', '@anthropic-ai/claude-agent-sdk'],
411
- banner,
412
- });
@@ -1,65 +0,0 @@
1
- // Spec: kandan/plans/2026-07-10-compute-nodes-rescript-commander-zero-ts-program.md
2
- // (M3 cluster 14, mcp-editor-forwarding-vm-sandbox - the explicit
3
- // mcp-server.mjs selector story).
4
- // Relationship: Builds the TS-side PARITY ORACLE for the mcp-server.mjs
5
- // dual-impl selector seam. The oracle bundles the REAL
6
- // mcpServerBundleCandidates ladder (src/vmSandbox/startVmCodexAppServer.ts,
7
- // the guest-injection selection-by-co-location seam) behind a one-shot
8
- // batch driver: a JSON array of cases on stdin, a JSON array of results on
9
- // stdout. The ReScript package's selector conformance
10
- // (packages/linzumi-cli-rescript/src/parity/McpSelectorConformance.res)
11
- // drives the SAME cases through CommanderMcpBundleSelection and asserts
12
- // the candidate ladders byte-equal - the two impls' selectors cannot
13
- // drift while both ship. Post-M4.3 the ladder collapses to its bare
14
- // ['mcp-server.mjs'] tail and this oracle retires with the TS impl.
15
- //
16
- // Like the other parity oracles, the output is a local test artifact
17
- // (.differential/ is gitignored, never published) and stays unminified for
18
- // debuggability.
19
- import { mkdir } from 'node:fs/promises';
20
- import { dirname, join } from 'node:path';
21
- import { fileURLToPath } from 'node:url';
22
- import { build } from 'esbuild';
23
-
24
- const packageRoot = dirname(dirname(fileURLToPath(import.meta.url)));
25
-
26
- const driverSource = `
27
- import { mcpServerBundleCandidates } from './src/vmSandbox/startVmCodexAppServer';
28
-
29
- function handle(testCase) {
30
- switch (testCase.op) {
31
- case 'candidates':
32
- return { candidates: mcpServerBundleCandidates(testCase.impl) };
33
- default:
34
- return { threw: true, message: 'unknown op ' + String(testCase.op) };
35
- }
36
- }
37
-
38
- let stdin = '';
39
- process.stdin.setEncoding('utf8');
40
- for await (const chunk of process.stdin) {
41
- stdin += chunk;
42
- }
43
- const cases = JSON.parse(stdin);
44
- process.stdout.write(JSON.stringify(cases.map(handle)));
45
- `;
46
-
47
- await mkdir(join(packageRoot, '.differential'), { recursive: true });
48
-
49
- await build({
50
- stdin: {
51
- contents: driverSource,
52
- resolveDir: packageRoot,
53
- sourcefile: 'mcp-selector-parity-driver.ts',
54
- loader: 'ts',
55
- },
56
- bundle: true,
57
- platform: 'node',
58
- target: 'node20',
59
- format: 'esm',
60
- outfile: join(packageRoot, '.differential/mcp-selector-parity-oracle.mjs'),
61
- minify: false,
62
- sourcemap: false,
63
- legalComments: 'none',
64
- external: ['ws', 'undici', 'blessed', '@anthropic-ai/claude-agent-sdk'],
65
- });