feat(#2088): migrate Codex onto the Embeddable Orchestration System (ADR-1239)
Drive Codex install/uninstall through the descriptor-driven Host-Integration Interface (declarative embedding adapter → engine surface dispatch) and fold every positive `runtime === 'codex'` / `isCodex` projection into descriptor-driven `runtime.hostBehaviors`. Install/uninstall output stays byte-parity-gated (tests/fixtures/golden-install-parity/codex.json); no other runtime changes. Three Context7-verified upgrades, each with a test on the user-reachable surface: - Skill root → canonical $HOME/.agents/skills via a skills-kind `home` override, with pre-move migration cleanup (stale ~/.codex/skills/gsd-* removed on install and uninstall; user content preserved). Fixes getGlobalSkillsBase, writeManifest, and the skill-manifest inventory to honor the override so --skills-root / sync-skills / the manifest report the real location. - Six new hooks.json lifecycle events (PreToolUse, PermissionRequest, PreCompact, PostCompact, SubagentStop, UserPromptSubmit) shared by install + uninstall; extendedHookEvents reconciled [] -> the schema-valid wired subset. - Explicit `[agents] max_depth = 1` in the managed config.toml block, pinning the negotiated dispatch.maxDepth:1 axis. validateCodexConfigSchema now permits a known-scalar-only bare `[agents]` AgentsToml table (still rejects [[agents]] and unknown-key break-forms, #2760); mergeCodexConfig preserves the user's own AgentsToml scalars (max_threads etc.) instead of dropping them. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
17
src/init.cts
17
src/init.cts
@@ -37,7 +37,7 @@ import { formatGsdSlash, resolveRuntime } from './runtime-slash.cjs';
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports -- commands.cjs is an export= CommonJS module
|
||||
import commandsMod = require('./commands.cjs');
|
||||
import { validatePath, loadTrustedGlobalRoots } from './security.cjs';
|
||||
import { getGlobalSkillDir, getGlobalSkillDisplayPath, getGlobalSkillsBase } from './runtime-homes.cjs';
|
||||
import { getGlobalSkillDir, getGlobalSkillDisplayPath, getGlobalSkillsBase, getGlobalConfigDir } from './runtime-homes.cjs';
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports -- frontmatter.cjs is an export= CommonJS module
|
||||
import frontmatterMod = require('./frontmatter.cjs');
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports -- verification.cjs is an export= CommonJS module
|
||||
@@ -2372,11 +2372,24 @@ function buildSkillManifest(cwd: string, skillsDir: string | null = null): Skill
|
||||
kind: 'skills',
|
||||
},
|
||||
{
|
||||
root: '~/.codex/skills',
|
||||
// ADR-1239 upgrade 3 (#2088): Codex's canonical skill root is
|
||||
// $HOME/.agents/skills (per codex core-skills loader.rs), resolved via
|
||||
// the skills-kind `home` override in getGlobalSkillsBase.
|
||||
root: '~/.agents/skills',
|
||||
path: getGlobalSkillsBase('codex') as string,
|
||||
scope: 'global',
|
||||
kind: 'skills',
|
||||
},
|
||||
{
|
||||
// Codex's deprecated fallback skill root ($CODEX_HOME/skills). Kept as a
|
||||
// discovery-only legacy root so pre-move installs remain inventoried;
|
||||
// GSD no longer installs here (#2088).
|
||||
root: '~/.codex/skills',
|
||||
path: path.join(getGlobalConfigDir('codex'), 'skills'),
|
||||
scope: 'global',
|
||||
kind: 'skills',
|
||||
deprecated: true,
|
||||
},
|
||||
{
|
||||
root: '.claude/gsd-core/skills',
|
||||
path: path.join(os.homedir(), '.claude', 'gsd-core', 'skills'),
|
||||
|
||||
@@ -276,15 +276,21 @@ function _copyStaged(stagedDir: string, destDir: string, kind: any, configDir: s
|
||||
'_copyStaged: configDir (install root) is required to confine writes — refusing to write',
|
||||
);
|
||||
}
|
||||
// The install root is normally configDir, but a kind may declare an alternate
|
||||
// `home` (ADR-1239 upgrade 3 / #2088, e.g. Codex skills -> $HOME/.agents) — in
|
||||
// that case this defense-in-depth check must confine against the resolved
|
||||
// alternate root instead, matching the upstream gate's own root selection in
|
||||
// createRuntimeArtifactInstallPlan.
|
||||
const installRoot = (kind && typeof kind.home === 'string' && kind.home !== '') ? kind.home : configDir;
|
||||
// Strict-subpath + NUL containment via the canonical gate (shared with the
|
||||
// layout-driven install plan); throws if destDir escapes the install root.
|
||||
// destDir here is an absolute path; path.resolve(configDir, absoluteDest) returns it unchanged, so the gate's strict-subpath check still correctly confines it to configDir.
|
||||
const resolvedDest = runtimeArtifactInstallPlan.assertDestWithinConfigHome(configDir, destDir);
|
||||
// Symlink-escape guard: reject if any path component between configDir and
|
||||
// destDir is a symlink that would redirect writes outside configDir.
|
||||
if (hasExistingSymlinkBetween(path.resolve(configDir), resolvedDest)) {
|
||||
// destDir here is an absolute path; path.resolve(installRoot, absoluteDest) returns it unchanged, so the gate's strict-subpath check still correctly confines it to installRoot.
|
||||
const resolvedDest = runtimeArtifactInstallPlan.assertDestWithinConfigHome(installRoot, destDir);
|
||||
// Symlink-escape guard: reject if any path component between the install root and
|
||||
// destDir is a symlink that would redirect writes outside the install root.
|
||||
if (hasExistingSymlinkBetween(path.resolve(installRoot), resolvedDest)) {
|
||||
throw new Error(
|
||||
`_copyStaged: destDir "${destDir}" contains a symlink escaping the install root "${configDir}" — refusing to write`,
|
||||
`_copyStaged: destDir "${destDir}" contains a symlink escaping the install root "${installRoot}" — refusing to write`,
|
||||
);
|
||||
}
|
||||
// Use the validated absolute path for the actual writes below.
|
||||
@@ -620,11 +626,17 @@ function installRuntimeArtifacts(
|
||||
if (!kind) throw new Error(`Install plan returned unknown artifact kind: ${item.kind}`);
|
||||
const dest = item.destDir;
|
||||
// Symlink-escape guard: reject before mkdir if dest (or any component
|
||||
// between configDir and dest) is a symlink pointing outside configDir.
|
||||
// mkdirSync follows symlinks, so this must run BEFORE the mkdir call.
|
||||
if (hasExistingSymlinkBetween(path.resolve(configDir), dest)) {
|
||||
// between the install root and dest) is a symlink pointing outside that
|
||||
// root. mkdirSync follows symlinks, so this must run BEFORE the mkdir
|
||||
// call. The install root is normally configDir, but a kind may declare
|
||||
// an alternate `home` (ADR-1239 upgrade 3 / #2088, e.g. Codex skills ->
|
||||
// $HOME/.agents) — in that case the guard must check against the
|
||||
// resolved alternate root instead, matching assertDestWithinConfigHome's
|
||||
// own root selection in createRuntimeArtifactInstallPlan.
|
||||
const installRoot = (kind && typeof kind.home === 'string' && kind.home !== '') ? kind.home : configDir;
|
||||
if (hasExistingSymlinkBetween(path.resolve(installRoot), dest)) {
|
||||
throw new Error(
|
||||
`installRuntimeArtifacts: destDir "${dest}" contains a symlink escaping the install root "${configDir}" — refusing to create`,
|
||||
`installRuntimeArtifacts: destDir "${dest}" contains a symlink escaping the install root "${installRoot}" — refusing to create`,
|
||||
);
|
||||
}
|
||||
fs.mkdirSync(dest, { recursive: true });
|
||||
|
||||
@@ -32,6 +32,10 @@ interface ArtifactKind {
|
||||
destSubpath: string;
|
||||
prefix?: string;
|
||||
stage: (resolvedProfile: ResolvedProfile, agentCtx?: AgentCtx) => string;
|
||||
/** Resolved absolute alternate install root for this kind, if the descriptor
|
||||
* specifies one (e.g. codex skills → $HOME/.agents). Undefined means the
|
||||
* kind installs under the runtime's normal configDir. */
|
||||
home?: string;
|
||||
}
|
||||
|
||||
interface Layout {
|
||||
@@ -216,7 +220,7 @@ function createRuntimeArtifactInstallPlan(args: CreateRuntimeArtifactInstallPlan
|
||||
items.push({
|
||||
kind: kind.kind,
|
||||
sourceDir,
|
||||
destDir: assertDestWithinConfigHome(layout.configDir, kind.destSubpath),
|
||||
destDir: assertDestWithinConfigHome(kind.home ?? layout.configDir, kind.destSubpath),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -227,7 +231,7 @@ function createRuntimeArtifactUninstallPlan(layout: Layout): UninstallPlan {
|
||||
return {
|
||||
items: layout.kinds.map((kind) => ({
|
||||
kind: kind.kind,
|
||||
destDir: assertDestWithinConfigHome(layout.configDir, kind.destSubpath),
|
||||
destDir: assertDestWithinConfigHome(kind.home ?? layout.configDir, kind.destSubpath),
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -73,6 +73,10 @@ interface ArtifactKind {
|
||||
/** For agents kind with a converter, accepts an optional AgentCtx as the second
|
||||
* arg so cross-cutting can be applied pre-converter (ADR-1235 §1). */
|
||||
stage: (resolvedProfile: ResolvedProfile, agentCtx?: AgentCtx) => string;
|
||||
/** Resolved absolute alternate install root for this kind, if the descriptor
|
||||
* specifies one (e.g. codex skills → $HOME/.agents). Undefined means the
|
||||
* kind installs under the runtime's normal configDir. */
|
||||
home?: string;
|
||||
}
|
||||
|
||||
interface Layout {
|
||||
@@ -419,6 +423,10 @@ interface ArtifactKindDescriptor {
|
||||
nesting: 'flat' | 'nested';
|
||||
recursive: boolean;
|
||||
converter: string | null;
|
||||
/** Optional alternate install home, relative to the user's home directory
|
||||
* (e.g. ".agents" for codex skills → $HOME/.agents/skills). When absent,
|
||||
* the kind installs under the runtime's normal configDir. */
|
||||
home?: string;
|
||||
}
|
||||
|
||||
interface ArtifactLayoutDescriptor {
|
||||
@@ -445,18 +453,19 @@ function dispatchKindEntry(entry: ArtifactKindDescriptor, runtime: string, confi
|
||||
const { kind, destSubpath, prefix, nesting, converter } = entry;
|
||||
const nested = nesting === 'nested';
|
||||
|
||||
let result: ArtifactKind;
|
||||
switch (kind) {
|
||||
case 'commands':
|
||||
if (converter == null) {
|
||||
return commandsKind(destSubpath, prefix, configDir);
|
||||
}
|
||||
return convertedCommandsKind(destSubpath, prefix, converter, configDir);
|
||||
result = converter == null
|
||||
? commandsKind(destSubpath, prefix, configDir)
|
||||
: convertedCommandsKind(destSubpath, prefix, converter, configDir);
|
||||
break;
|
||||
|
||||
case 'agents':
|
||||
if (converter == null) {
|
||||
return agentsKind(destSubpath, prefix, configDir);
|
||||
}
|
||||
return convertedAgentsKind(destSubpath, prefix, converter, configDir, scope);
|
||||
result = converter == null
|
||||
? agentsKind(destSubpath, prefix, configDir)
|
||||
: convertedAgentsKind(destSubpath, prefix, converter, configDir, scope);
|
||||
break;
|
||||
|
||||
case 'skills':
|
||||
if (converter == null) {
|
||||
@@ -464,16 +473,24 @@ function dispatchKindEntry(entry: ArtifactKindDescriptor, runtime: string, confi
|
||||
`resolveRuntimeArtifactLayout: skills entry for '${runtime}' has converter=null (converter is required for skills)`,
|
||||
);
|
||||
}
|
||||
return skillsKind(destSubpath, prefix, converter, runtime, configDir, nested, scope);
|
||||
result = skillsKind(destSubpath, prefix, converter, runtime, configDir, nested, scope);
|
||||
break;
|
||||
|
||||
case 'kimi-agents':
|
||||
return kimiAgentsKind(destSubpath, prefix, configDir);
|
||||
result = kimiAgentsKind(destSubpath, prefix, configDir);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new TypeError(
|
||||
`resolveRuntimeArtifactLayout: unknown kind '${kind}' in descriptor for runtime '${runtime}'`,
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof entry.home === 'string' && entry.home !== '') {
|
||||
result.home = path.join(os.homedir(), entry.home);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -118,6 +118,9 @@ type ConfigHomeDescriptor =
|
||||
interface RuntimeArtifactKindDescriptor {
|
||||
kind: string;
|
||||
destSubpath: string;
|
||||
// ADR-1239 upgrade 3 (#2088): optional split-home override (relative to
|
||||
// os.homedir()), e.g. Codex skills → ".agents". Absent for most runtimes.
|
||||
home?: string;
|
||||
}
|
||||
|
||||
interface RuntimeDescriptor {
|
||||
@@ -416,6 +419,14 @@ export function getGlobalSkillsBase(runtime: string): string | null {
|
||||
const runtimeEntry = getRegistry().runtimes[runtime];
|
||||
const descriptor = runtimeEntry?.runtime;
|
||||
const globalSkillsKind = descriptor?.artifactLayout?.global?.find((entry) => entry.kind === 'skills');
|
||||
// ADR-1239 upgrade 3 (#2088): honor a skills-kind `home` override (e.g. Codex
|
||||
// → $HOME/.agents/skills, independent of $CODEX_HOME) so the reported skills
|
||||
// root matches where the installer actually writes (the artifact layout /
|
||||
// _resolveSkillsRootDir). Without this, `--skills-root` and the sync-skills
|
||||
// workflow would look under configHome/skills while skills live under ~/.agents.
|
||||
if (globalSkillsKind?.home && globalSkillsKind?.destSubpath) {
|
||||
return path.join(os.homedir(), globalSkillsKind.home, globalSkillsKind.destSubpath);
|
||||
}
|
||||
if (descriptor?.configHome && globalSkillsKind?.destSubpath) {
|
||||
return resolveSkillsBaseFromDescriptor(
|
||||
descriptor.configHome,
|
||||
|
||||
Reference in New Issue
Block a user