Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion docs/design/context-profile-delivery.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,15 @@ The task call sends the query and selected reference content on standard input t

`profile start` is an explicit terminal-only boundary. It revalidates the store and native generation, then launches the pinned Codex binary with inherited terminal capabilities and the isolated home. The bootstrap tells the active agent to resolve context at material task boundaries through bounded structured stdin. It remains prompt-advisory, grants no tools or permissions, and persists no task prose or selected skill bodies. Authentication must be completed separately inside the isolated home; the start path does not inherit or copy provider credentials.

Switching the managed profile makes the old native generation stale until `prepare-native` succeeds. To undo a switch, first `rollback` the managed store, then use `native-rollback` with both roots. `native-recover` handles a retained interruption journal without deleting provider data. Existing sessions retain their original context. These commands support isolated Codex generations, not migration of an existing global installation or native activation for other providers.
## Isolated native Claude generations

A managed store with `--target claude` uses the same `prepare-native`, `native-status`, `native-rollback`, `native-recover`, `run` and `start` commands. Claude Code loads the carrier for each session with `--plugin-dir`; nothing is installed, no marketplace is registered and no settings are written. The generation holds a private `home/.claude` used as `CLAUDE_CONFIG_DIR`, an empty project and a verified copy of the carrier in `plugin/`. Every Claude call sets `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC` and `CLAUDE_CODE_DISABLE_OFFICIAL_MARKETPLACE_AUTOINSTALL`, so the isolated home gains no other plugins.

Preparation admits Claude Code 2.1.292 and later 2.1 patches; the receipt records the exact version, and a changed binary needs a new preparation. It requires a clean `claude plugin validate --json` report, exactly one session plugin (`ecc-context-carrier@inline`, enabled, at the generation's `plugin/` path) from `claude --plugin-dir … plugin list --json`, and a `claude --plugin-dir … plugin details` inventory whose skills equal the carrier selection with zero agents, hooks, MCP servers and LSP servers. `details` has no JSON form; an unparseable or changed report fails closed, which is why the admitted range is bounded to the 2.1 series. The copied files must match the carrier digests after the provider calls.

The receipt records the host's always-on projection as `nativeObservation` (`surface: plugin-always-on-listing`, `method: claude-plugin-details@<version>`, `approximate: true`). It is Claude Code's own estimate of the listing cost of this one plugin, not whole-context usage. `native-status` checks file integrity of the plugin copy, `CLAUDE.md`, user settings, skills, agents and commands in the isolated home; provider runtime state such as `.claude.json` and plugin bookkeeping is outside those controls, and plugin registration is verified again at each preparation.

Switching the managed profile makes the old native generation stale until `prepare-native` succeeds. To undo a switch, first `rollback` the managed store, then use `native-rollback` with both roots. `native-recover` handles a retained interruption journal without deleting provider data. Existing sessions retain their original context. These commands support isolated Codex and Claude generations, not migration of an existing global installation or native activation for other providers.

Discovery evidence comes from the generation's empty project. Task launch inherits the caller's task working directory, whose repository instructions and native configuration may add context or affect policy. Native readiness attests the isolated home's recorded inventory and integrity, not the complete context or permissions of every possible task directory.

Expand Down
10 changes: 10 additions & 0 deletions docs/design/context-profile-delivery.tdd.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,14 @@ Current combined verification after recovery:
- The default sandbox checkout's 5,000-path capture limit truncated a real Tier 1 install diff and failed closed. The reviewed ECC-029 sandbox implementation raises the bounded cap to 50,000, passes its 26-case boundary suite, and produced both final reports. The driver receipt binds its 51-file implementation digest `a84e09ab848b8cd05f33792c13734f7aabe16bfe16d50d8f8292eb5261a93c3a`.
- No real AI outcome call ran because `CODEX_API_KEY` was absent. Host ChatGPT authentication was neither copied nor exposed to the disposable evaluator.

## Isolated Claude native generations

Session-only Claude discovery adapts the ownership and receipt intent of #2788 to the existing native store; it never writes a marketplace or user settings.

- RED: 22 cases fail before the provider adapter (preview, prepare, version gate, nine discovery corruptions, details mismatch, static integrity, runtime-state tolerance, provider-home roots, Codex-to-Claude staleness, task launch and interactive start).
- GREEN: all 22 pass. Codex native (39), interactive (8), launch (12), auto launch (5), evaluation (31), store (31) and profile CLI suites pass unchanged; Codex receipts keep their shape, and evaluator Claude launches without a plugin directory keep their arguments and environment.
- Credential-free real run on Linux x64 with Claude Code 2.1.292 and the actual registry: Lean prepared ready with three skills and a 398-token always-on projection; Full prepared ready with 293 skills and 35,658 tokens; Full excluding `skill:python-patterns` verified 292 skills without it at 35,561 tokens. Switching profiles reported `stale`, and native rollback restored the Lean generation. `run --dry-run` resolved the pinned binary with `--plugin-dir`; `start --dry-run` proposed the Claude generation.
- Claude Code auto-updated to 2.1.293 during review, and the exact 2.1.292 pin rejected it. RED: tests for later 2.1 patches fail. GREEN admits 2.1.292 and later 2.1 patches while rejecting 2.1.291, 2.2.0, prereleases and malformed output. A real 2.1.293 run prepared Lean ready at the same 398-token projection; preparation took 2.4 s (provider calls 1.2 s), an unchanged re-preparation 0.9 s and status 11 ms.
- No authenticated model call, interactive turn or native skill invocation ran. The projection is the host's estimate for the plugin listing, not whole-context truth.

These boundaries keep the shipped behavior distinct from the M1 release gate. Authenticated outcome observations, a complete Tier 2 disk diff, live-install migration, other-provider activation, whole-context token truth and release defaults remain unverified until their explicit prerequisites are available.
7 changes: 4 additions & 3 deletions scripts/lib/context-profile-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@ function execute(options) {
stateRoot: options['state-root'], nativeRoot: options['native-root'] }) : null;
if (native && !native.ready) throw new Error('Prepare or recover the native generation before launching');
return { launch: require('./context-profile-launch').launchTaskContext({ ...launchInput, dryRun: options.dryRun,
nativeEnvironment: native ? { home: native.home, codexHome: native.codexHome,
codexPath: native.codexPath, executableDigest: native.executableDigest } : null,
nativeEnvironment: native ? { home: native.home, executableDigest: native.executableDigest,
...(native.target === 'claude' ? { claudeConfigDir: native.claudeConfigDir, claudePath: native.claudePath, pluginDir: native.pluginDir }
: { codexHome: native.codexHome, codexPath: native.codexPath }) } : null,
assertCurrent() {
if (stored) {
const current = require('./context-profile-store').getStoreStatus({ stateRoot: options['state-root'] });
Expand Down Expand Up @@ -162,7 +163,7 @@ function run(argv) {
const options = parse(argv);
const value = execute(options);
return { schemaVersion: 'ecc.profile-operation.v1', status: (value.launch?.status === 'failed' || value.interactive?.status === 'failed') ? 'error' : 'success',
summary: options.command === 'start' ? 'Opt-in interactive Codex uses the verified isolated generation and inherited terminal. Context selection remains advisory.'
summary: options.command === 'start' ? 'Opt-in interactive session uses the verified isolated generation and inherited terminal. Context selection remains advisory.'
: options.command === 'run' ? 'Task launch uses selected context and the provider configuration. Inspect the launch result.'
: options.command === 'resolve' ? 'Task context resolved within the selected profile.'
: 'Managed profile generation inspected. Native activation is a separate provider boundary.',
Expand Down
11 changes: 6 additions & 5 deletions scripts/lib/context-profile-interactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,19 @@ function startInteractiveProfile({ stateRoot, nativeRoot, dryRun = false } = {},
if (carrier.carrierDigest !== stored.carrierDigest) throw new Error('Stored profile source is stale; set and prepare the current generation before starting');
const current = native.getNativeProfileStatus(input);
if (!current.ready || current.revision !== prepared.revision) throw new Error('Native generation changed before interactive launch');
const env = { PATH: process.env.PATH, HOME: current.home, USERPROFILE: current.home,
CODEX_HOME: current.codexHome, LANG: 'C.UTF-8' };
const claude = current.target === 'claude';
const env = { PATH: process.env.PATH, HOME: current.home, USERPROFILE: current.home, LANG: 'C.UTF-8',
...(claude ? { CLAUDE_CONFIG_DIR: current.claudeConfigDir, ...native.CLAUDE_ISOLATION_ENV } : { CODEX_HOME: current.codexHome }) };
// Terminal capabilities are needed by the TUI; credentials and provider overrides are not inherited.
for (const key of ['TERM', 'COLORTERM', 'TERM_PROGRAM', 'SystemRoot']) {
if (process.env[key]) env[key] = process.env[key];
}
const bootstrapDigest = io.hash(io.read(path.join(current.codexHome, 'AGENTS.md')));
const result = (dependencies.execute || spawnSync)(current.codexPath, [], {
const bootstrapDigest = io.hash(io.read(claude ? path.join(current.claudeConfigDir, 'CLAUDE.md') : path.join(current.codexHome, 'AGENTS.md')));
const result = (dependencies.execute || spawnSync)(current.executable, claude ? ['--plugin-dir', current.pluginDir] : [], {
cwd: process.cwd(), env, shell: false, stdio: 'inherit' });
return { schemaVersion: 'ecc.interactive-profile.v1', status: result.error || result.status !== 0 ? 'failed' : 'exited',
launched: !result.error, exitCode: result.status ?? null, signal: result.signal || null,
...(result.error ? { error: 'Native interactive Codex could not be started' } : {}),
...(result.error ? { error: `Native interactive ${claude ? 'Claude' : 'Codex'} could not be started` } : {}),
nativeRevision: current.revision, providerVersion: current.providerVersion,
bootstrapDigest,
credentialsCopied: false, taskSuccess: 'unverified', enforcement: 'prompt-advisory' };
Expand Down
14 changes: 8 additions & 6 deletions scripts/lib/context-profile-launch.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function isolatedEnvironment(nativeEnvironment) {
USERPROFILE: nativeEnvironment.home,
...(nativeEnvironment.codexHome ? { CODEX_HOME: nativeEnvironment.codexHome } : {}),
...(nativeEnvironment.claudeConfigDir ? { CLAUDE_CONFIG_DIR: nativeEnvironment.claudeConfigDir } : {}),
...(nativeEnvironment.pluginDir ? require('./context-profile-native').CLAUDE_ISOLATION_ENV : {}),
TMPDIR: nativeEnvironment.home, LANG: 'C.UTF-8' };
if (process.platform === 'win32' && process.env.SystemRoot) env.SystemRoot = process.env.SystemRoot;
return env;
Expand All @@ -22,19 +23,20 @@ function launchTaskContext({ task, target = 'codex', dryRun = false, execute = s
if (!Object.hasOwn(adapters, target)) throw new Error(`Unsupported task launcher target: ${target}`);
if (!task || typeof task.query !== 'string' || !task.query.trim()) throw new Error('Task launch requires a non-empty query');
if (nativeEnvironment) {
const launchKeys = target === 'claude'
? { directory: nativeEnvironment.claudeConfigDir, executable: nativeEnvironment.claudePath }
: { directory: nativeEnvironment.codexHome, executable: nativeEnvironment.codexPath };
if (!path.isAbsolute(nativeEnvironment.home || '') || !path.isAbsolute(launchKeys.directory || '')
|| !path.isAbsolute(launchKeys.executable || '')
const launchPaths = target === 'claude'
? [nativeEnvironment.claudeConfigDir, nativeEnvironment.claudePath,
...(nativeEnvironment.pluginDir === undefined ? [] : [nativeEnvironment.pluginDir])]
: [nativeEnvironment.codexHome, nativeEnvironment.codexPath];
if (![nativeEnvironment.home, ...launchPaths].every(value => path.isAbsolute(value || ''))
|| !/^[a-f0-9]{64}$/.test(nativeEnvironment.executableDigest || '')) throw new Error('Invalid isolated native launch environment');
}
let selection = bare
? { schemaVersion: 'ecc.selected-context.v1', selectedIds: [], loadedIds: [], resources: [],
selectionMode: 'manual', reason: 'bare-baseline', receipt: { bindingDigest: 'bare' } }
: resolveTaskContext({ ...selectionOptions, task, target, load: !dryRun });
const adapter = { ...adapters[target],
...(nativeEnvironment ? { command: nativeEnvironment.codexPath || nativeEnvironment.claudePath } : {}) };
...(nativeEnvironment ? { command: target === 'claude' ? nativeEnvironment.claudePath : nativeEnvironment.codexPath } : {}),
...(nativeEnvironment?.pluginDir && target === 'claude' ? { args: ['--plugin-dir', nativeEnvironment.pluginDir, ...adapters.claude.args] } : {}) };
function verifyLaunch() {
assertCurrent();
if (nativeEnvironment && require('./context-profile-native-executable').fingerprintExecutable(adapter.command).digest
Expand Down
11 changes: 7 additions & 4 deletions scripts/lib/context-profile-native-executable.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ function nativeFormat(header) {
|| header.subarray(0, 2).toString() === 'MZ';
}

function resolveExecutable(command) {
const LABELS = { codex: 'Codex', claude: 'Claude Code' };

function resolveExecutable(command, name = 'codex') {
if (!Object.hasOwn(LABELS, name)) throw new Error(`Unsupported native executable: ${name}`);
const candidate = path.isAbsolute(command) ? command : (process.env.PATH || '').split(path.delimiter)
.filter(directory => path.isAbsolute(directory)).map(directory => path.join(directory, process.platform === 'win32' ? 'codex.exe' : 'codex'))
.filter(directory => path.isAbsolute(directory)).map(directory => path.join(directory, process.platform === 'win32' ? `${name}.exe` : name))
.find(file => fs.existsSync(file));
if (!candidate) throw new Error('Native Codex executable was not found');
if (!candidate) throw new Error(`Native ${LABELS[name]} executable was not found`);
let executable = fs.realpathSync(candidate);
const before = io.inspect(executable);
if (!before.stat.isFile() || before.stat.nlink !== 1 || before.stat.size < 4 || before.stat.size > MAX_BYTES) {
Expand All @@ -33,7 +36,7 @@ function resolveExecutable(command) {
} finally { fs.closeSync(fd); }
if (!nativeFormat(header)) {
// Supported npm distribution: bind its platform binary, never only its JS shim.
if (path.basename(executable) !== 'codex.js') throw new Error('Native adapter requires a native Codex executable');
if (name !== 'codex' || path.basename(executable) !== 'codex.js') throw new Error(`Native adapter requires a native ${LABELS[name]} executable`);
const packageName = `@openai/codex-${process.platform}-${process.arch}`;
let manifest;
try { manifest = createRequire(executable).resolve(`${packageName}/package.json`); }
Expand Down
Loading