@aisac/cli 0.4.0-beta.2 → 0.4.0-beta.21
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 +115 -10
- package/dist/assets/claude/hooks/context-compaction.ts +17 -5
- package/dist/assets/claude/hooks/native-host-contract-runtime.ts +1 -1
- package/dist/assets/claude/hooks/native-host-contract.test.ts +8 -4
- package/dist/assets/claude/hooks/provider-window.d.ts +83 -0
- package/dist/assets/codex-context-compaction.mjs +243 -5
- package/dist/assets/jev-paid-pilot-terminal.mjs +6 -0
- package/dist/claude-compatibility.mjs +26 -25
- package/dist/claude-observation.mjs +2 -1
- package/dist/cli.mjs +584 -35
- package/dist/codex-compatibility.mjs +48 -2
- package/dist/codex-engineering.mjs +165 -0
- package/dist/codex-hooks.mjs +411 -0
- package/dist/codex-permissions.mjs +67 -34
- package/dist/codex-protocol-fingerprint.json +11 -11
- package/dist/engineering-init.mjs +615 -0
- package/dist/engineering-pack.mjs +259 -23
- package/dist/engineering-scan-pins.json +42 -0
- package/dist/engineering-scan-report.mjs +1274 -0
- package/dist/engineering-scan-tools.mjs +1418 -0
- package/dist/engineering-scan.mjs +1265 -0
- package/dist/extensions-catalog.mjs +373 -0
- package/dist/extensions-cli.mjs +492 -0
- package/dist/extensions-preferences.mjs +151 -0
- package/dist/guardrails/continuity.mjs +239 -0
- package/dist/guardrails/format.mjs +111 -0
- package/dist/guardrails/guards.mjs +449 -0
- package/dist/guardrails/patch.mjs +33 -0
- package/dist/guardrails/run.mjs +286 -0
- package/dist/guardrails/shell-words.mjs +206 -0
- package/dist/guardrails-plugin.mjs +207 -0
- package/dist/launch.mjs +278 -34
- package/dist/managed-host.mjs +977 -0
- package/dist/mcp-servers.mjs +192 -0
- package/dist/mcp.mjs +10 -2
- package/dist/monitor.mjs +76 -1
- package/dist/package.json +1 -1
- package/dist/platform.mjs +78 -29
- package/dist/release-manifest-public-keys.json +10 -0
- package/dist/release-manifest.json +328 -0
- package/dist/release-manifest.mjs +817 -0
- package/dist/release-settings.mjs +210 -0
- package/dist/self-update.mjs +1036 -0
- package/dist/state.mjs +25 -1
- package/dist/token-guide.mjs +132 -0
- package/dist/update-actions.mjs +442 -0
- package/package.json +1 -1
package/dist/launch.mjs
CHANGED
|
@@ -14,10 +14,38 @@ import {
|
|
|
14
14
|
} from './state.mjs';
|
|
15
15
|
import { codexPolicyJson, makePolicy } from './policy.mjs';
|
|
16
16
|
import {
|
|
17
|
+
liveLaunchHosts,
|
|
17
18
|
prepareEngineeringPack,
|
|
19
|
+
readStoredLocale,
|
|
20
|
+
resolvePackLocale,
|
|
18
21
|
sweepStaleLaunches,
|
|
19
22
|
writeLaunchMarker,
|
|
20
23
|
} from './engineering-pack.mjs';
|
|
24
|
+
import { prepareCodexGuardrails, prepareGuardrails } from './guardrails-plugin.mjs';
|
|
25
|
+
import { installedClientVersion, refreshReleaseManifest } from './release-manifest.mjs';
|
|
26
|
+
import { readReleaseSettings, updateCommandFor } from './release-settings.mjs';
|
|
27
|
+
import { REEXEC_ENV, releaseUpdateLock } from './update-actions.mjs';
|
|
28
|
+
import {
|
|
29
|
+
collectManagedHosts,
|
|
30
|
+
hostFallbackLine,
|
|
31
|
+
managedHostEnvironment,
|
|
32
|
+
resolveHostExecutable,
|
|
33
|
+
} from './managed-host.mjs';
|
|
34
|
+
import { recordLaunchHost } from './self-update.mjs';
|
|
35
|
+
import { CODEX_HOOKS_ENV, GUARDRAILS_SESSION_ENV, supportsCodexHooks } from './codex-hooks.mjs';
|
|
36
|
+
import {
|
|
37
|
+
CODEX_MCP_ENV,
|
|
38
|
+
claudeDenyRules,
|
|
39
|
+
claudeMcpEntries,
|
|
40
|
+
mcpLaunchLines,
|
|
41
|
+
sessionServers,
|
|
42
|
+
} from './mcp-servers.mjs';
|
|
43
|
+
import { enabledServerIds, readPreferences } from './extensions-preferences.mjs';
|
|
44
|
+
import {
|
|
45
|
+
CODEX_ENGINEERING_ENV,
|
|
46
|
+
CODEX_ENGINEERING_SKILLS_ROOT_ENV,
|
|
47
|
+
supportsCodexEngineering,
|
|
48
|
+
} from './codex-engineering.mjs';
|
|
21
49
|
import {
|
|
22
50
|
CODEX_LAUNCH_ENVELOPE,
|
|
23
51
|
CODEX_MONITOR_CWD,
|
|
@@ -132,6 +160,12 @@ function childEnvironment(root) {
|
|
|
132
160
|
delete environment.CODEX_CONTEXT_COMPACT_AT;
|
|
133
161
|
delete environment[CODEX_LAUNCH_ENVELOPE];
|
|
134
162
|
delete environment[CODEX_MONITOR_CWD];
|
|
163
|
+
delete environment[CODEX_ENGINEERING_ENV];
|
|
164
|
+
delete environment[CODEX_ENGINEERING_SKILLS_ROOT_ENV];
|
|
165
|
+
delete environment[CODEX_MCP_ENV];
|
|
166
|
+
delete environment[CODEX_HOOKS_ENV];
|
|
167
|
+
delete environment[GUARDRAILS_SESSION_ENV];
|
|
168
|
+
delete environment[REEXEC_ENV];
|
|
135
169
|
environment.AIBRAIN_STATE_DIR = resolve(root);
|
|
136
170
|
return environment;
|
|
137
171
|
}
|
|
@@ -368,22 +402,34 @@ async function assertClaudeCheckpointHelper(packageRoot) {
|
|
|
368
402
|
|
|
369
403
|
/**
|
|
370
404
|
* A fresh private directory for one launch. Directories left by launches whose
|
|
371
|
-
* processes are gone are swept first; this one records its launcher
|
|
405
|
+
* processes are gone are swept first; this one records its launcher and the
|
|
406
|
+
* host it runs, `pending` until resolved (release-manifest FR5: a managed
|
|
407
|
+
* version a live launch names is never garbage-collected, and nothing is
|
|
408
|
+
* collected while a live launch is still resolving its host).
|
|
372
409
|
* @param {string} root @param {string} prefix
|
|
410
|
+
* @param {import('./engineering-pack.mjs').LaunchHost} host
|
|
373
411
|
*/
|
|
374
|
-
async function launchDirectory(root, prefix) {
|
|
412
|
+
async function launchDirectory(root, prefix, host) {
|
|
375
413
|
await sweepStaleLaunches(root);
|
|
376
414
|
const parent = await privateDirectory(join(root, 'runtime'));
|
|
377
415
|
const directory = await mkdtemp(join(parent, `${prefix}-`));
|
|
378
416
|
await chmod(directory, 0o700);
|
|
379
|
-
await writeLaunchMarker(directory, { launcherPid: process.pid, childPid: null });
|
|
417
|
+
await writeLaunchMarker(directory, { launcherPid: process.pid, childPid: null, host });
|
|
418
|
+
// This launch now counts as live for other launchers, so the update lock the
|
|
419
|
+
// self-update step took can go (release-manifest FR6).
|
|
420
|
+
await releaseUpdateLock(root).catch(() => undefined);
|
|
380
421
|
return directory;
|
|
381
422
|
}
|
|
382
423
|
|
|
383
|
-
/**
|
|
384
|
-
|
|
424
|
+
/**
|
|
425
|
+
* @param {string} directory @param {number | undefined} childPid
|
|
426
|
+
* @param {import('./engineering-pack.mjs').LaunchHost} host
|
|
427
|
+
*/
|
|
428
|
+
async function recordChild(directory, childPid, host) {
|
|
385
429
|
if (childPid === undefined) return;
|
|
386
|
-
await writeLaunchMarker(directory, { launcherPid: process.pid, childPid }).catch(
|
|
430
|
+
await writeLaunchMarker(directory, { launcherPid: process.pid, childPid, host }).catch(
|
|
431
|
+
() => undefined,
|
|
432
|
+
);
|
|
387
433
|
}
|
|
388
434
|
|
|
389
435
|
/** @param {import('node:child_process').ChildProcess} child @param {string} directory */
|
|
@@ -418,9 +464,30 @@ function waitForChild(child, directory) {
|
|
|
418
464
|
});
|
|
419
465
|
}
|
|
420
466
|
|
|
467
|
+
/**
|
|
468
|
+
* The catalog servers that join this session: the user's enabled choices from
|
|
469
|
+
* the preferences file. Called only after the license was confirmed.
|
|
470
|
+
* @param {string} root
|
|
471
|
+
* @param {'claude' | 'codex'} client
|
|
472
|
+
* @param {NodeJS.ProcessEnv} environment
|
|
473
|
+
*/
|
|
474
|
+
export async function readSessionServers(root, client, environment) {
|
|
475
|
+
return sessionServers(enabledServerIds(await readPreferences(root)), client, environment);
|
|
476
|
+
}
|
|
477
|
+
|
|
421
478
|
/**
|
|
422
479
|
* @typedef {object} LaunchDependencies
|
|
423
480
|
* @property {typeof prepareEngineeringPack} [preparePack] AISAC Engineering pack loader (E4b)
|
|
481
|
+
* @property {typeof prepareGuardrails} [prepareGuardrails] Guardrail hooks plugin writer (E6a)
|
|
482
|
+
* @property {typeof readSessionServers} [readSessionServers] MCP catalog servers to load (E6c)
|
|
483
|
+
* @property {typeof prepareCodexGuardrails} [prepareCodexGuardrails] Codex guardrail hooks (E6b)
|
|
484
|
+
* @property {typeof refreshReleaseManifest} [refreshReleaseManifest] Release manifest refresh (ADR-0056 R2)
|
|
485
|
+
* @property {typeof resolveHostExecutable} [resolveHost] Managed or system host resolution (ADR-0056 R4)
|
|
486
|
+
*/
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* @typedef {object} LaunchOptions
|
|
490
|
+
* @property {import('./release-settings.mjs').HostMode | null} [hostMode] `--host managed|system` for this launch (FR5)
|
|
424
491
|
*/
|
|
425
492
|
|
|
426
493
|
/**
|
|
@@ -428,22 +495,28 @@ function waitForChild(child, directory) {
|
|
|
428
495
|
* @param {string} root
|
|
429
496
|
* @param {string[]} args
|
|
430
497
|
* @param {LaunchDependencies} [dependencies]
|
|
498
|
+
* @param {LaunchOptions} [launchOptions]
|
|
431
499
|
*/
|
|
432
|
-
export async function launchClaude(config, root, args, dependencies = {}) {
|
|
500
|
+
export async function launchClaude(config, root, args, dependencies = {}, launchOptions = {}) {
|
|
433
501
|
const preparePack = dependencies.preparePack ?? prepareEngineeringPack;
|
|
502
|
+
const refreshManifest = dependencies.refreshReleaseManifest ?? refreshReleaseManifest;
|
|
503
|
+
const writeGuardrails = dependencies.prepareGuardrails ?? prepareGuardrails;
|
|
504
|
+
const readServers = dependencies.readSessionServers ?? readSessionServers;
|
|
505
|
+
const resolveHost = dependencies.resolveHost ?? resolveHostExecutable;
|
|
434
506
|
const validated = assertConfig(config);
|
|
435
507
|
const launchArgs = await parseClaudeLaunchArgs(args, process.cwd());
|
|
436
508
|
assertClaudeArgs(launchArgs.args);
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
const
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
509
|
+
// Release manifest (ADR-0056 R2): refreshed at most every six hours, bounded by
|
|
510
|
+
// its own timeout; it never blocks the launch. R4 reads the Claude pin from it.
|
|
511
|
+
const manifest = await refreshManifest({
|
|
512
|
+
root,
|
|
513
|
+
packageRoot: validated.packageRoot,
|
|
514
|
+
endpoint: validated.endpoint,
|
|
515
|
+
token: validated.token,
|
|
516
|
+
host: 'claude',
|
|
517
|
+
});
|
|
518
|
+
// Everything that can fail without the host: the package's own assets, before any
|
|
519
|
+
// launch directory exists.
|
|
447
520
|
const pluginRoot = await assertClaudeAssets(validated.packageRoot);
|
|
448
521
|
const telemetryActive =
|
|
449
522
|
validated.telemetry?.enabled === true && validated.telemetry?.disclosedAt != null;
|
|
@@ -463,7 +536,65 @@ export async function launchClaude(config, root, args, dependencies = {}) {
|
|
|
463
536
|
const checkpointHelperPath = await assertClaudeCheckpointHelper(validated.packageRoot);
|
|
464
537
|
const checkpointConfigDigest = claudeCheckpointConfigBinding(validated);
|
|
465
538
|
const checkpointStateDir = await privateDirectory(join(root, 'claude', 'checkpoints'));
|
|
466
|
-
|
|
539
|
+
// The launch marker first, its host `pending` (FR5): another launch's garbage
|
|
540
|
+
// collection skips while it exists, so the version this launch is about to run
|
|
541
|
+
// is never removed between its resolution and its spawn.
|
|
542
|
+
const directory = await launchDirectory(root, 'claude', {
|
|
543
|
+
name: 'claude',
|
|
544
|
+
mode: 'pending',
|
|
545
|
+
version: null,
|
|
546
|
+
});
|
|
547
|
+
// Managed or system host (ADR-0056 R4, FR5): the managed copy when the settings
|
|
548
|
+
// or `--host` ask for it and it is installed, pinned and qualified; otherwise the
|
|
549
|
+
// user's own binary, with the reason on stderr when a managed launch fell back.
|
|
550
|
+
const locale = resolvePackLocale(await readStoredLocale(root), process.env);
|
|
551
|
+
const host = await resolveHost({
|
|
552
|
+
host: 'claude',
|
|
553
|
+
root,
|
|
554
|
+
packageRoot: validated.packageRoot,
|
|
555
|
+
manifest,
|
|
556
|
+
settings: await readReleaseSettings(root),
|
|
557
|
+
env: process.env,
|
|
558
|
+
flag: launchOptions.hostMode ?? null,
|
|
559
|
+
clientVersion: await installedClientVersion(validated.packageRoot),
|
|
560
|
+
locale,
|
|
561
|
+
progress: (line) => process.stderr.write(`${line}\n`),
|
|
562
|
+
});
|
|
563
|
+
if (host.fallback !== null) process.stderr.write(`${hostFallbackLine('claude', host, locale)}\n`);
|
|
564
|
+
const executable = host.executable;
|
|
565
|
+
if (!executable) {
|
|
566
|
+
await rm(directory, { recursive: true, force: true }).catch(() => undefined);
|
|
567
|
+
throw new Error('claude_not_found');
|
|
568
|
+
}
|
|
569
|
+
const compatibility =
|
|
570
|
+
host.compatibility ?? (await resolveClaudeCompatibility(executable, validated.packageRoot));
|
|
571
|
+
if (compatibility.status === 'rejected') {
|
|
572
|
+
await rm(directory, { recursive: true, force: true }).catch(() => undefined);
|
|
573
|
+
throw new Error(claudeCompatibilityError(compatibility));
|
|
574
|
+
}
|
|
575
|
+
const pinnedExecutable = compatibility.executable ?? executable;
|
|
576
|
+
if (compatibility.status === 'host_checked')
|
|
577
|
+
process.stderr.write(
|
|
578
|
+
`aisac: Claude ${compatibility.version ?? 'unknown'} accepted by the local native host contract; end-to-end recovery remains separately qualified.\n`,
|
|
579
|
+
);
|
|
580
|
+
const currentVersion = compatibility.version ?? nativeVersion(pinnedExecutable);
|
|
581
|
+
/** @type {import('./engineering-pack.mjs').LaunchHost} */
|
|
582
|
+
const launchHost = { name: 'claude', mode: host.mode, version: compatibility.version ?? null };
|
|
583
|
+
await writeLaunchMarker(directory, {
|
|
584
|
+
launcherPid: process.pid,
|
|
585
|
+
childPid: null,
|
|
586
|
+
host: launchHost,
|
|
587
|
+
});
|
|
588
|
+
await recordLaunchHost(
|
|
589
|
+
root,
|
|
590
|
+
{
|
|
591
|
+
name: 'claude',
|
|
592
|
+
mode: host.mode,
|
|
593
|
+
version: launchHost.version,
|
|
594
|
+
reason: host.fallback ?? host.reason,
|
|
595
|
+
},
|
|
596
|
+
manifest === null ? null : { sequence: manifest.sequence, source: manifest.source },
|
|
597
|
+
).catch(() => undefined);
|
|
467
598
|
const settingsPath = join(directory, 'settings.json');
|
|
468
599
|
const mcpPath = join(directory, 'mcp.json');
|
|
469
600
|
const context = validated.context;
|
|
@@ -535,6 +666,14 @@ export async function launchClaude(config, root, args, dependencies = {}) {
|
|
|
535
666
|
for (const rule of [...userAllow, ...requiredAllow]) {
|
|
536
667
|
if (!mergedAllow.includes(rule)) mergedAllow.push(rule);
|
|
537
668
|
}
|
|
669
|
+
// Catalog tools that spend money stay denied whatever the user allows or the
|
|
670
|
+
// permission mode is (spec aisac-engineering-extensions FR7.2).
|
|
671
|
+
const userDeny = Array.isArray(userPermissions.deny) ? userPermissions.deny : [];
|
|
672
|
+
/** @type {unknown[]} */
|
|
673
|
+
const mergedDeny = [];
|
|
674
|
+
for (const rule of [...userDeny, ...claudeDenyRules()]) {
|
|
675
|
+
if (!mergedDeny.includes(rule)) mergedDeny.push(rule);
|
|
676
|
+
}
|
|
538
677
|
const settings = {
|
|
539
678
|
...(launchArgs.settings?.sandbox === undefined ? {} : { sandbox: launchArgs.settings.sandbox }),
|
|
540
679
|
pluginConfigs: {
|
|
@@ -544,20 +683,11 @@ export async function launchClaude(config, root, args, dependencies = {}) {
|
|
|
544
683
|
permissions: {
|
|
545
684
|
...userPermissions,
|
|
546
685
|
allow: mergedAllow,
|
|
547
|
-
|
|
548
|
-
};
|
|
549
|
-
const mcp = {
|
|
550
|
-
mcpServers: {
|
|
551
|
-
[MCP_ALIAS]: {
|
|
552
|
-
type: 'http',
|
|
553
|
-
url: validated.endpoint,
|
|
554
|
-
headers: { Authorization: `Bearer ${validated.token}` },
|
|
555
|
-
},
|
|
686
|
+
deny: mergedDeny,
|
|
556
687
|
},
|
|
557
688
|
};
|
|
558
689
|
try {
|
|
559
690
|
await privateJson(settingsPath, settings);
|
|
560
|
-
await privateJson(mcpPath, mcp);
|
|
561
691
|
} catch (error) {
|
|
562
692
|
await rm(directory, { recursive: true, force: true });
|
|
563
693
|
throw error;
|
|
@@ -569,9 +699,47 @@ export async function launchClaude(config, root, args, dependencies = {}) {
|
|
|
569
699
|
root,
|
|
570
700
|
directory,
|
|
571
701
|
packageRoot: validated.packageRoot,
|
|
702
|
+
updateCommand: await updateCommandFor(root, validated.packageRoot),
|
|
572
703
|
}).catch(() => ({ pluginRoot: null, line: null }));
|
|
573
704
|
if (engineering.line !== null) process.stderr.write(`${engineering.line}\n`);
|
|
574
|
-
|
|
705
|
+
// Guardrails need the license this launch confirmed (the pack loaded), and
|
|
706
|
+
// like the pack they never block the launch (spec aisac-engineering-extensions FR5).
|
|
707
|
+
const guardrails =
|
|
708
|
+
engineering.pluginRoot === null
|
|
709
|
+
? null
|
|
710
|
+
: await writeGuardrails({ directory, root, packageRoot: validated.packageRoot }).catch(
|
|
711
|
+
() => null,
|
|
712
|
+
);
|
|
713
|
+
if (guardrails !== null) process.stderr.write(`${guardrails.line}\n`);
|
|
714
|
+
// Catalog servers need the same confirmed license, and never block the launch.
|
|
715
|
+
const servers =
|
|
716
|
+
engineering.pluginRoot === null
|
|
717
|
+
? null
|
|
718
|
+
: await readServers(root, 'claude', process.env).catch(() => null);
|
|
719
|
+
for (const line of servers === null ? [] : mcpLaunchLines(servers, 'claude'))
|
|
720
|
+
process.stderr.write(`${line}\n`);
|
|
721
|
+
const mcp = {
|
|
722
|
+
mcpServers: {
|
|
723
|
+
...(servers === null ? {} : claudeMcpEntries(servers.ready)),
|
|
724
|
+
[MCP_ALIAS]: {
|
|
725
|
+
type: 'http',
|
|
726
|
+
url: validated.endpoint,
|
|
727
|
+
headers: { Authorization: `Bearer ${validated.token}` },
|
|
728
|
+
},
|
|
729
|
+
},
|
|
730
|
+
};
|
|
731
|
+
try {
|
|
732
|
+
await privateJson(mcpPath, mcp);
|
|
733
|
+
} catch (error) {
|
|
734
|
+
await rm(directory, { recursive: true, force: true });
|
|
735
|
+
throw error;
|
|
736
|
+
}
|
|
737
|
+
// The managed copy never updates itself (FR5); a system launch keeps the
|
|
738
|
+
// user's environment as it is.
|
|
739
|
+
const environment =
|
|
740
|
+
host.mode === 'managed'
|
|
741
|
+
? managedHostEnvironment(childEnvironment(root))
|
|
742
|
+
: childEnvironment(root);
|
|
575
743
|
environment.CLAUDE_CODE_ENABLE_FUNCTION_HOOKS = '1';
|
|
576
744
|
/** @type {import('node:child_process').ChildProcess} */
|
|
577
745
|
let child;
|
|
@@ -588,6 +756,7 @@ export async function launchClaude(config, root, args, dependencies = {}) {
|
|
|
588
756
|
'--plugin-dir',
|
|
589
757
|
pluginRoot,
|
|
590
758
|
...(engineering.pluginRoot === null ? [] : ['--plugin-dir', engineering.pluginRoot]),
|
|
759
|
+
...(guardrails === null ? [] : ['--plugin-dir', guardrails.pluginRoot]),
|
|
591
760
|
...launchArgs.args,
|
|
592
761
|
],
|
|
593
762
|
{ cwd: process.cwd(), env: environment, stdio: 'inherit' },
|
|
@@ -598,12 +767,40 @@ export async function launchClaude(config, root, args, dependencies = {}) {
|
|
|
598
767
|
}
|
|
599
768
|
// Listen for exit before any await, so a child that exits at once is not missed.
|
|
600
769
|
const finished = waitForChild(child, directory);
|
|
601
|
-
await recordChild(directory, child.pid);
|
|
770
|
+
await recordChild(directory, child.pid, launchHost);
|
|
771
|
+
// Garbage collection after a successful launch (FR5): the versions the manifest
|
|
772
|
+
// still carries lock sets for stay, as does any version a live launch runs.
|
|
773
|
+
// The live markers are read under the host lock, by the collector; a live launch
|
|
774
|
+
// still resolving its host (`pending`) could run any version and vetoes it.
|
|
775
|
+
if (manifest !== null && manifest.manifest !== null)
|
|
776
|
+
await collectManagedHosts({
|
|
777
|
+
root,
|
|
778
|
+
host: 'claude',
|
|
779
|
+
keep: Object.keys(manifest.manifest.hosts.claude.versions),
|
|
780
|
+
live: async () => {
|
|
781
|
+
const hosts = await liveLaunchHosts(root);
|
|
782
|
+
if (hosts.some((entry) => entry.mode === 'pending')) return null;
|
|
783
|
+
return hosts.flatMap((entry) =>
|
|
784
|
+
entry.name === 'claude' && entry.mode === 'managed' && entry.version !== null
|
|
785
|
+
? [entry.version]
|
|
786
|
+
: [],
|
|
787
|
+
);
|
|
788
|
+
},
|
|
789
|
+
}).catch(() => undefined);
|
|
602
790
|
return finished;
|
|
603
791
|
}
|
|
604
792
|
|
|
605
|
-
/**
|
|
606
|
-
|
|
793
|
+
/**
|
|
794
|
+
* @param {LaunchConfig} config
|
|
795
|
+
* @param {string} root
|
|
796
|
+
* @param {string[]} args
|
|
797
|
+
* @param {LaunchDependencies} [dependencies]
|
|
798
|
+
*/
|
|
799
|
+
export async function launchCodex(config, root, args, dependencies = {}) {
|
|
800
|
+
const preparePack = dependencies.preparePack ?? prepareEngineeringPack;
|
|
801
|
+
const refreshManifest = dependencies.refreshReleaseManifest ?? refreshReleaseManifest;
|
|
802
|
+
const readServers = dependencies.readSessionServers ?? readSessionServers;
|
|
803
|
+
const writeCodexGuardrails = dependencies.prepareCodexGuardrails ?? prepareCodexGuardrails;
|
|
607
804
|
const validated = assertConfig(config);
|
|
608
805
|
assertCodexArgs(args);
|
|
609
806
|
const captureLockPlatform = captureLockPlatformCheck();
|
|
@@ -630,7 +827,9 @@ export async function launchCodex(config, root, args) {
|
|
|
630
827
|
]);
|
|
631
828
|
const checkpoints = await privateDirectory(join(root, 'codex', 'checkpoints'));
|
|
632
829
|
const notes = await privateDirectory(join(root, 'codex', 'notes'));
|
|
633
|
-
|
|
830
|
+
/** @type {import('./engineering-pack.mjs').LaunchHost} */
|
|
831
|
+
const launchHost = { name: 'codex', mode: 'system', version: compatibility.version };
|
|
832
|
+
const directory = await launchDirectory(root, 'codex', launchHost);
|
|
634
833
|
const environment = childEnvironment(root);
|
|
635
834
|
try {
|
|
636
835
|
if (
|
|
@@ -654,6 +853,51 @@ export async function launchCodex(config, root, args) {
|
|
|
654
853
|
await rm(directory, { recursive: true, force: true });
|
|
655
854
|
throw error;
|
|
656
855
|
}
|
|
856
|
+
// Release manifest (ADR-0056 R2): same contract as for Claude.
|
|
857
|
+
await refreshManifest({
|
|
858
|
+
root,
|
|
859
|
+
packageRoot: validated.packageRoot,
|
|
860
|
+
endpoint: validated.endpoint,
|
|
861
|
+
token: validated.token,
|
|
862
|
+
host: 'codex',
|
|
863
|
+
});
|
|
864
|
+
// The pack never blocks the launch: every failure starts Codex without it.
|
|
865
|
+
const engineering = await preparePack({
|
|
866
|
+
endpoint: validated.endpoint,
|
|
867
|
+
token: validated.token,
|
|
868
|
+
root,
|
|
869
|
+
directory,
|
|
870
|
+
packageRoot: validated.packageRoot,
|
|
871
|
+
client: 'codex',
|
|
872
|
+
hostSupported: supportsCodexEngineering(compatibility.version),
|
|
873
|
+
updateCommand: await updateCommandFor(root, validated.packageRoot),
|
|
874
|
+
}).catch(() => ({ pluginRoot: null, codex: null, line: null }));
|
|
875
|
+
if (engineering.line !== null) process.stderr.write(`${engineering.line}\n`);
|
|
876
|
+
if (engineering.codex != null) {
|
|
877
|
+
environment[CODEX_ENGINEERING_ENV] = JSON.stringify(engineering.codex);
|
|
878
|
+
// Catalog servers need the license the pack confirmed (spec extensions FR6).
|
|
879
|
+
const servers = await readServers(root, 'codex', environment).catch(() => null);
|
|
880
|
+
for (const line of servers === null ? [] : mcpLaunchLines(servers, 'codex'))
|
|
881
|
+
process.stderr.write(`${line}\n`);
|
|
882
|
+
if (servers !== null && servers.ready.length > 0)
|
|
883
|
+
environment[CODEX_MCP_ENV] = JSON.stringify(servers.ready.map((entry) => entry.id));
|
|
884
|
+
// Guardrail hooks need the same license and a Codex measured with them
|
|
885
|
+
// (0.166.0+); like the pack they never block the launch (spec extensions FR6).
|
|
886
|
+
const guardrails = supportsCodexHooks(compatibility.version)
|
|
887
|
+
? await writeCodexGuardrails({
|
|
888
|
+
root,
|
|
889
|
+
packageRoot,
|
|
890
|
+
executable,
|
|
891
|
+
cwd: launchPlan.effectiveCwd,
|
|
892
|
+
profile: launchPlan.profile,
|
|
893
|
+
environment,
|
|
894
|
+
}).catch(() => null)
|
|
895
|
+
: null;
|
|
896
|
+
if (guardrails !== null) {
|
|
897
|
+
environment[CODEX_HOOKS_ENV] = guardrails.value;
|
|
898
|
+
process.stderr.write(`${guardrails.line}\n`);
|
|
899
|
+
}
|
|
900
|
+
}
|
|
657
901
|
environment.AI_BRAIN_MCP_SERVER = MCP_ALIAS;
|
|
658
902
|
environment.CODEX_BIN = executable;
|
|
659
903
|
environment.CODEX_MONITOR_COMMAND = monitor;
|
|
@@ -683,7 +927,7 @@ export async function launchCodex(config, root, args) {
|
|
|
683
927
|
});
|
|
684
928
|
// Listen for exit before any await, so a child that exits at once is not missed.
|
|
685
929
|
const finished = waitForChild(child, directory);
|
|
686
|
-
await recordChild(directory, child.pid);
|
|
930
|
+
await recordChild(directory, child.pid, launchHost);
|
|
687
931
|
return finished;
|
|
688
932
|
}
|
|
689
933
|
|