@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,519 +0,0 @@
1
- // Spec: kandan/plans/2026-07-10-compute-nodes-rescript-commander-zero-ts-program.md
2
- // (M3 cluster 13, onboarding - the SUPPORT slice: the commander-side
3
- // starter-task suggestion engine and the hello-demo project materializer).
4
- // Relationship: Builds the TS-side PARITY ORACLE for the onboarding
5
- // support modules of the ReScript commander port, the sibling of
6
- // build-worker-entry-parity-oracle.mjs (cluster 12). The oracle bundles
7
- // the REAL signupTaskSuggestions.ts (suggestSignupTasksWithCodex /
8
- // signupTaskSuggestionProcessForTest + the tagged oracle exports of the
9
- // model/prompt/schema/parse internals), signupTaskSuggestionsProgress.ts
10
- // (progressLabelForCodexEvent / createTaskSuggestionProgressParser), and
11
- // helloLinzumiProject.ts (createHelloLinzumiProject + the default
12
- // constants) behind the cluster 1/2 one-shot BATCH driver (a JSON array
13
- // of cases on stdin, a JSON array of results on stdout).
14
- //
15
- // Determinism + normalization: fs cases run in realpath'd scratch dirs (or
16
- // a caller-provided externalRoot for the hello byte-tree law, so both
17
- // impls can build at the SAME root and compare without normalization);
18
- // paths normalize through the "$DIR" placeholder and the random
19
- // linzumi-signup-codex-tasks-* scratch roots through the "$TASKS"
20
- // placeholder. The suggestion flow's codex binary is a case-scripted
21
- // executable planted from the case tree, so both impls drive identical
22
- // bytes.
23
- //
24
- // helloLinzumiProject.ts reads its logo asset relative to the bundled
25
- // module, so the build copies src/assets/linzumi-logo.svg next to the
26
- // bundle (.differential/assets/).
27
- //
28
- // SECRETS: the oracle only ever sees the conformance suite's synthetic
29
- // trees and synthetic credentials. The output is a local test artifact
30
- // (.differential/ is gitignored, never published) and stays unminified
31
- // for debuggability.
32
- import { copyFile, mkdir } from 'node:fs/promises';
33
- import { dirname, join } from 'node:path';
34
- import { fileURLToPath } from 'node:url';
35
- import { build } from 'esbuild';
36
-
37
- const packageRoot = dirname(dirname(fileURLToPath(import.meta.url)));
38
-
39
- const driverSource = `
40
- import {
41
- chmodSync,
42
- existsSync,
43
- lstatSync,
44
- mkdirSync,
45
- mkdtempSync,
46
- readdirSync,
47
- readFileSync,
48
- readlinkSync,
49
- realpathSync,
50
- rmSync,
51
- writeFileSync,
52
- } from 'node:fs';
53
- import { tmpdir } from 'node:os';
54
- import { dirname as pathDirname, join, relative } from 'node:path';
55
- import {
56
- extractTaskSuggestionPathTokens,
57
- groundTaskSuggestions,
58
- parseTaskSuggestionResponseForTest,
59
- resolveTaskSuggestionModelForTest,
60
- signupTaskSuggestionProcessForTest,
61
- suggestSignupTasksWithCodex,
62
- taskSuggestionJsonSchemaForTest,
63
- taskSuggestionPromptForTest,
64
- } from './src/signupTaskSuggestions';
65
- import {
66
- createTaskSuggestionProgressParser,
67
- progressLabelForCodexEvent,
68
- } from './src/signupTaskSuggestionsProgress';
69
- import {
70
- createHelloLinzumiProject,
71
- defaultHelloLinzumiHost,
72
- defaultHelloLinzumiParentDir,
73
- defaultHelloLinzumiPort,
74
- defaultHelloLinzumiProjectDir,
75
- defaultHelloLinzumiProjectName,
76
- } from './src/helloLinzumiProject';
77
-
78
- // --- Placeholder + snapshot plumbing --------------------------------------------
79
-
80
- const dirPlaceholder = '$DIR';
81
-
82
- function scratch() {
83
- // realpath so macOS /var -> /private/var never splits the two impls'
84
- // placeholder substitution.
85
- return realpathSync(mkdtempSync(join(tmpdir(), 'linzumi-onboarding-oracle-')));
86
- }
87
-
88
- function substitute(value, from, to) {
89
- if (typeof value === 'string') {
90
- return value.split(from).join(to);
91
- }
92
- if (Array.isArray(value)) {
93
- return value.map((entry) => substitute(entry, from, to));
94
- }
95
- if (typeof value === 'object' && value !== null) {
96
- return Object.fromEntries(
97
- Object.entries(value).map(([key, entry]) => [
98
- substitute(key, from, to),
99
- substitute(entry, from, to),
100
- ])
101
- );
102
- }
103
- return value;
104
- }
105
-
106
- // The suggestion flow's per-attempt scratch roots are random mkdtemp dirs
107
- // under the OS tmpdir; normalize the WHOLE path through one placeholder.
108
- function normalizeTasksTemp(value) {
109
- if (typeof value === 'string') {
110
- return value.replace(/\\S*linzumi-signup-codex-tasks-[^/"'\\s]+/g, '$TASKS');
111
- }
112
- if (Array.isArray(value)) {
113
- return value.map((entry) => normalizeTasksTemp(entry));
114
- }
115
- if (typeof value === 'object' && value !== null) {
116
- return Object.fromEntries(
117
- Object.entries(value).map(([key, entry]) => [
118
- normalizeTasksTemp(key),
119
- normalizeTasksTemp(entry),
120
- ])
121
- );
122
- }
123
- return value;
124
- }
125
-
126
- function buildTree(root, files) {
127
- for (const [relPath, spec] of Object.entries(files ?? {})) {
128
- const full = join(root, relPath);
129
- if (relPath.endsWith('/')) {
130
- mkdirSync(full, { recursive: true });
131
- } else {
132
- mkdirSync(pathDirname(full), { recursive: true });
133
- if (spec !== null && typeof spec === 'object') {
134
- writeFileSync(full, String(spec.content), 'utf8');
135
- if (spec.mode !== undefined) {
136
- chmodSync(full, spec.mode);
137
- }
138
- } else {
139
- writeFileSync(full, String(spec), 'utf8');
140
- }
141
- }
142
- }
143
- }
144
-
145
- function snapshotFiles(dir) {
146
- const files = {};
147
- const walk = (current) => {
148
- let names;
149
- try {
150
- names = readdirSync(current).sort();
151
- } catch {
152
- return;
153
- }
154
- for (const name of names) {
155
- const full = join(current, name);
156
- // lstat (never follow): the isolated home's auth.json is a SYMLINK to
157
- // the user's real login (fix/codex-auth-rotation-burn - possibly
158
- // dangling when logged out), and the honest snapshot of a link is its
159
- // target, not the bytes behind it.
160
- const stats = lstatSync(full);
161
- if (stats.isSymbolicLink()) {
162
- // Dir-relative target so oracle and local scratch roots compare
163
- // equal in the differential.
164
- files[relative(dir, full)] = {
165
- link: relative(dir, readlinkSync(full)),
166
- };
167
- } else if (stats.isDirectory()) {
168
- files[relative(dir, full) + '/'] = '<dir>';
169
- walk(full);
170
- } else {
171
- files[relative(dir, full)] = {
172
- content: readFileSync(full, 'utf8'),
173
- mode: stats.mode & 0o777,
174
- };
175
- }
176
- }
177
- };
178
- walk(dir);
179
- return files;
180
- }
181
-
182
- // Env manipulation is per-case and restored afterwards (the batch runs
183
- // sequentially in one process).
184
- function withEnv(overrides, run) {
185
- const saved = {};
186
- for (const [key, value] of Object.entries(overrides)) {
187
- saved[key] = process.env[key];
188
- if (value === null) {
189
- delete process.env[key];
190
- } else {
191
- process.env[key] = value;
192
- }
193
- }
194
- const restore = () => {
195
- for (const [key, value] of Object.entries(saved)) {
196
- if (value === undefined) {
197
- delete process.env[key];
198
- } else {
199
- process.env[key] = value;
200
- }
201
- }
202
- };
203
- return { run, restore };
204
- }
205
-
206
- async function runWithEnv(overrides, run) {
207
- const { restore } = withEnv(overrides, run);
208
- try {
209
- return await run();
210
- } finally {
211
- restore();
212
- }
213
- }
214
-
215
- // --- Suggestion transforms ---------------------------------------------------------
216
-
217
- function handleResolveModel(testCase) {
218
- return runWithEnv(
219
- { LINZUMI_SIGNUP_TASK_MODEL: testCase.envModel ?? null },
220
- () => ({
221
- value: resolveTaskSuggestionModelForTest(
222
- testCase.explicitModel ?? undefined,
223
- testCase.wafer === true
224
- ? {
225
- config: {
226
- id: 'linzumi',
227
- name: 'Linzumi',
228
- baseUrl: 'https://example.invalid/llm',
229
- envKey: 'LINZUMI_LLM_PROXY_TOKEN',
230
- wireApi: 'responses',
231
- },
232
- env: {},
233
- }
234
- : undefined
235
- ),
236
- })
237
- );
238
- }
239
-
240
- function providerOfCase(spec) {
241
- if (spec === undefined || spec === null) {
242
- return undefined;
243
- }
244
- return {
245
- config: {
246
- id: spec.config.id,
247
- name: spec.config.name,
248
- baseUrl: spec.config.baseUrl,
249
- envKey: spec.config.envKey,
250
- wireApi: spec.config.wireApi,
251
- ...(spec.config.httpHeaders === undefined ? {} : { httpHeaders: spec.config.httpHeaders }),
252
- ...(spec.config.envHttpHeaders === undefined
253
- ? {}
254
- : { envHttpHeaders: spec.config.envHttpHeaders }),
255
- },
256
- env: spec.env ?? {},
257
- };
258
- }
259
-
260
- function handleBuildProcess(testCase) {
261
- const built = signupTaskSuggestionProcessForTest({
262
- command: testCase.command,
263
- model: testCase.model,
264
- ...(testCase.modelProvider === undefined
265
- ? {}
266
- : { modelProvider: providerOfCase(testCase.modelProvider) }),
267
- projectPath: testCase.projectPath,
268
- schemaPath: testCase.schemaPath,
269
- outputPath: testCase.outputPath,
270
- prompt: testCase.prompt,
271
- ...(testCase.timeoutMs === undefined ? {} : { timeoutMs: testCase.timeoutMs }),
272
- codexHome: testCase.codexHome,
273
- ...(testCase.forwardableOpenAiApiKey === undefined
274
- ? {}
275
- : { forwardableOpenAiApiKey: testCase.forwardableOpenAiApiKey }),
276
- });
277
- return {
278
- value: {
279
- command: built.command,
280
- args: [...built.args],
281
- cwd: built.cwd,
282
- stdin: built.stdin,
283
- env: built.env ?? null,
284
- timeoutMs: built.timeoutMs,
285
- },
286
- };
287
- }
288
-
289
- function handleProgressChunks(testCase) {
290
- const labels = [];
291
- const throwOn = new Set(testCase.throwOnLabels ?? []);
292
- const parser = createTaskSuggestionProgressParser((label) => {
293
- labels.push(label);
294
- if (throwOn.has(label)) {
295
- throw new Error('scripted consumer failure');
296
- }
297
- });
298
- for (const chunk of testCase.chunks ?? []) {
299
- parser.push(chunk);
300
- }
301
- if (testCase.flush !== false) {
302
- parser.flush();
303
- }
304
- return { labels };
305
- }
306
-
307
- // --- The suggestion flow -------------------------------------------------------------
308
-
309
- async function handleSuggestFlow(testCase) {
310
- const dir = scratch();
311
- const sub = (value) => substitute(value, dirPlaceholder, dir);
312
- buildTree(dir, sub(testCase.files ?? {}));
313
-
314
- const labels = [];
315
- const onProgress =
316
- testCase.withProgress === true ? (label) => labels.push(label) : undefined;
317
-
318
- const outcome = await runWithEnv(
319
- {
320
- LINZUMI_CODEX_HOME: join(dir, 'isolated-home'),
321
- CODEX_HOME: join(dir, 'user-codex'),
322
- OPENAI_API_KEY: null,
323
- LINZUMI_SIGNUP_TASK_MODEL: null,
324
- },
325
- async () => {
326
- try {
327
- const tasks = await suggestSignupTasksWithCodex({
328
- projectPath: join(dir, testCase.projectRelDir ?? 'project'),
329
- codexBin: sub(testCase.codexBin),
330
- ...(testCase.model === undefined ? {} : { model: testCase.model }),
331
- ...(testCase.modelProvider === undefined
332
- ? {}
333
- : { modelProvider: providerOfCase(sub(testCase.modelProvider)) }),
334
- ...(onProgress === undefined ? {} : { onProgress }),
335
- });
336
- return { ok: true, tasks };
337
- } catch (error) {
338
- return { ok: false, error: error instanceof Error ? error.message : String(error) };
339
- }
340
- }
341
- );
342
-
343
- // Give any straggling stdout events a beat before reading labels (the
344
- // scripted binary sleeps before exiting, so labels are ordinarily
345
- // delivered pre-exit in both impls).
346
- await new Promise((resolve) => setTimeout(resolve, 50));
347
-
348
- const invocationsPath = join(dir, 'invocations.jsonl');
349
- const invocations = existsSync(invocationsPath)
350
- ? readFileSync(invocationsPath, 'utf8')
351
- .split('\\n')
352
- .filter((line) => line !== '')
353
- .map((line) => JSON.parse(line))
354
- : [];
355
-
356
- // The per-attempt scratch roots must be gone after the flow (the TS
357
- // finally); derive them from the recorded argv.
358
- const tempRoots = new Set();
359
- for (const invocation of invocations) {
360
- const index = invocation.argv.indexOf('--output-schema');
361
- if (index !== -1) {
362
- tempRoots.add(pathDirname(invocation.argv[index + 1]));
363
- }
364
- }
365
- const tempRootsGone = [...tempRoots].every((root) => !existsSync(root));
366
-
367
- const result = {
368
- outcome,
369
- labels,
370
- invocations,
371
- isolatedHome: snapshotFiles(join(dir, 'isolated-home')),
372
- tempRootsGone,
373
- };
374
- return normalizeTasksTemp(substitute(result, dir, dirPlaceholder));
375
- }
376
-
377
- // --- The hello-demo project ----------------------------------------------------------
378
-
379
- function handleHelloCreate(testCase) {
380
- const externalRoot = testCase.externalRoot;
381
- const dir = externalRoot ?? scratch();
382
- const sub = (value) => substitute(value, dirPlaceholder, dir);
383
- buildTree(dir, sub(testCase.files ?? {}));
384
-
385
- let result;
386
- try {
387
- const input = sub(testCase.input);
388
- const project = createHelloLinzumiProject(
389
- typeof input === 'string'
390
- ? input
391
- : {
392
- ...(input.rootPath === undefined ? {} : { rootPath: input.rootPath }),
393
- ...(input.parentDir === undefined ? {} : { parentDir: input.parentDir }),
394
- ...(input.name === undefined ? {} : { name: input.name }),
395
- ...(input.port === undefined ? {} : { port: input.port }),
396
- ...(input.host === undefined ? {} : { host: input.host }),
397
- ...(input.reset === undefined ? {} : { reset: input.reset }),
398
- }
399
- );
400
- result = { ok: project };
401
- } catch (error) {
402
- result = { threw: error instanceof Error ? error.message : String(error) };
403
- }
404
-
405
- return substitute(
406
- {
407
- result,
408
- ...(externalRoot === undefined ? { tree: snapshotFiles(dir) } : {}),
409
- },
410
- dir,
411
- dirPlaceholder
412
- );
413
- }
414
-
415
- // --- Dispatch -----------------------------------------------------------------------
416
-
417
- async function handle(testCase) {
418
- switch (testCase.op) {
419
- case 'resolveModel':
420
- return handleResolveModel(testCase);
421
- case 'prompt':
422
- return {
423
- value: taskSuggestionPromptForTest(
424
- testCase.previousResponse === undefined
425
- ? undefined
426
- : {
427
- previousResponse: testCase.previousResponse,
428
- fictionalPaths: testCase.fictionalPaths ?? [],
429
- }
430
- ),
431
- };
432
- case 'extractPathTokens':
433
- return { value: extractTaskSuggestionPathTokens(testCase.title) };
434
- case 'groundSuggestions': {
435
- const existing = new Set(testCase.existingPaths ?? []);
436
- return {
437
- value: groundTaskSuggestions(testCase.suggestions, (candidate) =>
438
- existing.has(candidate)
439
- ),
440
- };
441
- }
442
- case 'schemaFile':
443
- return {
444
- value: JSON.stringify(taskSuggestionJsonSchemaForTest(), null, 2) + '\\n',
445
- };
446
- case 'parseResponse': {
447
- const parsed = parseTaskSuggestionResponseForTest(testCase.response);
448
- return { value: parsed === undefined ? null : parsed };
449
- }
450
- case 'buildProcess':
451
- return handleBuildProcess(testCase);
452
- case 'progressEvent': {
453
- const label = progressLabelForCodexEvent(testCase.event);
454
- return { value: label === undefined ? null : label };
455
- }
456
- case 'progressChunks':
457
- return handleProgressChunks(testCase);
458
- case 'suggestFlow':
459
- return handleSuggestFlow(testCase);
460
- case 'helloCreate':
461
- return handleHelloCreate(testCase);
462
- case 'helloDefaults':
463
- return {
464
- value: {
465
- projectDir: defaultHelloLinzumiProjectDir,
466
- projectName: defaultHelloLinzumiProjectName,
467
- parentDir: defaultHelloLinzumiParentDir,
468
- port: defaultHelloLinzumiPort,
469
- host: defaultHelloLinzumiHost,
470
- },
471
- };
472
- default:
473
- return { threw: true, message: 'unknown op ' + String(testCase.op) };
474
- }
475
- }
476
-
477
- let stdin = '';
478
- process.stdin.setEncoding('utf8');
479
- for await (const chunk of process.stdin) {
480
- stdin += chunk;
481
- }
482
- const cases = JSON.parse(stdin);
483
- const results = [];
484
- for (const testCase of cases) {
485
- results.push(await handle(testCase));
486
- }
487
- process.stdout.write(JSON.stringify(results));
488
- `;
489
-
490
- await mkdir(join(packageRoot, '.differential'), { recursive: true });
491
-
492
- await build({
493
- stdin: {
494
- contents: driverSource,
495
- resolveDir: packageRoot,
496
- sourcefile: 'onboarding-support-parity-driver.ts',
497
- loader: 'ts',
498
- },
499
- bundle: true,
500
- platform: 'node',
501
- target: 'node20',
502
- format: 'esm',
503
- outfile: join(
504
- packageRoot,
505
- '.differential/onboarding-support-parity-oracle.mjs'
506
- ),
507
- minify: false,
508
- sourcemap: false,
509
- legalComments: 'none',
510
- external: ['ws', 'undici', 'blessed', '@anthropic-ai/claude-agent-sdk'],
511
- });
512
-
513
- // helloLinzumiProject.ts reads its logo relative to the executing module;
514
- // the bundle executes from .differential/, so mirror the asset beside it.
515
- await mkdir(join(packageRoot, '.differential/assets'), { recursive: true });
516
- await copyFile(
517
- join(packageRoot, 'src/assets/linzumi-logo.svg'),
518
- join(packageRoot, '.differential/assets/linzumi-logo.svg')
519
- );