fix(#2602): discover project-local Codex agents (#2623)

* fix(#2602): discover project-local Codex agents

- Select an existing local Codex agents directory before global fallback
- Prove init reports the canonical local installation through compiled CJS

* test(#2602): lock Codex agent precedence

- Cover override, local authority, global fallback, and runtime compatibility
- Exercise installed state through the compiled resolver

* fix(#2602): resolve local Codex agent skills

- Pass the canonical project root to the non-Claude persona fallback
- Cover nested-Codex fallback and Claude compatibility through the CLI

* test(#2602): cover local Codex validation status

- Assert emitted validate and health commands use the project-local install
- Preserve empty local-directory authority beside complete global agents

* fix(#2602): align validation with local Codex discovery

- Pass the resolved runtime and project root to health W010
- Resolve the validate-agents runtime before checking installation status

* test(#2602): cover local Codex docs status

- Assert docs-init reports an authoritative empty local install as unhealthy

* fix(#2602): align docs with local Codex discovery

- Pass the resolved runtime and canonical project root to the shared agent checker

* fix(#2602): honor agent-skills runtime override

- Resolve agent-skills fallback runtime through the canonical project resolver
- Cover conflicting config and GSD_RUNTIME values through the emitted CLI

* fix(#2602): ignore non-directory local agents paths

- Treat only a local Codex agents directory as authoritative
- Cover regular-file fallback through the emitted install checker

* chore(#2602): add changelog fragment

- record the user-visible local Codex agent discovery fix for PR #2623

* fix(#2602): align local agent discovery with runtime policy

- Resolve Codex's local config directory through the canonical runtime policy
- Use test-managed cleanup for local-agent discovery coverage

* fix(#2602): discover local agents across runtimes

- Prefer manifest-backed project-local installs for non-Claude runtimes
- Respect runtime-specific local install roots and preserve global fallback behavior
- Cover native, partial, cross-runtime, and project-root local discovery

* fix(#2602): preserve agent discovery fallback

- Fall back globally when local-install probes fail
- Document and test symlink rejection
- Align the changeset with repository format

* fix(#2602): reuse local directory policy

- Resolve runtimes without local config through the canonical sentinel
- Document the manifest gate and refresh the context index

---------

Co-authored-by: Daniel E. <daniel.e@teachingstrategies.com>
Co-authored-by: Rezolv <dave@sienkowski.com>
This commit is contained in:
Daniel Einspanjer
2026-07-31 21:20:46 -04:00
committed by GitHub
parent 7b204ad2ac
commit f0ff23635e
10 changed files with 495 additions and 12 deletions

View File

@@ -30,6 +30,7 @@ const TEST_ENV_BASE = {
WT_SESSION: '',
TMUX_PANE: '',
ZELLIJ_SESSION_NAME: '',
GSD_WORKSTREAM: '',
TTY: '',
SSH_TTY: '',
};
@@ -71,6 +72,13 @@ function readConfig(tmpDir) {
return JSON.parse(fs.readFileSync(configPath, 'utf-8'));
}
function markLocalGsdInstall(tmpDir) {
fs.writeFileSync(
path.join(tmpDir, '.codex', 'gsd-file-manifest.json'),
JSON.stringify({ files: {} }),
);
}
// Run agent-skills with --json for typed IR assertions
function runAgentSkillsJson(args, tmpDir, env) {
// Insert --json after 'agent-skills' subcommand
@@ -128,6 +136,59 @@ describe('agent-skills command', () => {
assert.strictEqual(r.ir.block, '');
});
test('unconfigured Codex reads its local companion agent from a descendant cwd', () => {
const agentsDir = path.join(tmpDir, '.codex', 'agents');
const descendant = path.join(tmpDir, 'src', 'feature');
const localPersona = '# Local Codex executor\nUse the project-local agent.\n';
fs.mkdirSync(agentsDir, { recursive: true });
fs.mkdirSync(descendant, { recursive: true });
fs.writeFileSync(path.join(agentsDir, 'gsd-executor.md'), localPersona);
markLocalGsdInstall(tmpDir);
writeConfig(tmpDir, { runtime: 'codex' });
const r = runAgentSkillsJson(['agent-skills', 'gsd-executor'], descendant, {
HOME: tmpDir,
USERPROFILE: tmpDir,
CODEX_HOME: path.join(tmpDir, 'global-codex'),
GSD_RUNTIME: '',
});
assert.ok(r.success, `Command failed: ${r.error}`);
assert.strictEqual(r.ir.block, localPersona);
});
test('workstream runtime selects the local Codex companion when root config differs', () => {
const agentsDir = path.join(tmpDir, '.codex', 'agents');
const localPersona = '# Local Codex executor\nUse the overridden runtime.\n';
fs.mkdirSync(agentsDir, { recursive: true });
fs.writeFileSync(path.join(agentsDir, 'gsd-executor.md'), localPersona);
markLocalGsdInstall(tmpDir);
writeConfig(tmpDir, { runtime: 'claude' });
const workstreamDir = path.join(tmpDir, '.planning', 'workstreams', 'feature-x');
fs.mkdirSync(workstreamDir, { recursive: true });
fs.writeFileSync(path.join(workstreamDir, 'config.json'), JSON.stringify({ runtime: 'codex' }));
const r = runAgentSkillsJson(['agent-skills', 'gsd-executor'], tmpDir, {
HOME: tmpDir,
USERPROFILE: tmpDir,
CODEX_HOME: path.join(tmpDir, 'global-codex'),
GSD_RUNTIME: '',
GSD_WORKSTREAM: 'feature-x',
});
assert.ok(r.success, `Command failed: ${r.error}`);
assert.strictEqual(r.ir.block, localPersona);
});
test('unconfigured Claude remains empty when a local Codex companion exists', () => {
const agentsDir = path.join(tmpDir, '.codex', 'agents');
fs.mkdirSync(agentsDir, { recursive: true });
fs.writeFileSync(path.join(agentsDir, 'gsd-executor.md'), '# Local Codex executor\n');
writeConfig(tmpDir, { runtime: 'claude' });
const r = runAgentSkillsJson(['agent-skills', 'gsd-executor'], tmpDir, { GSD_RUNTIME: 'claude' });
assert.ok(r.success, `Command failed: ${r.error}`);
assert.strictEqual(r.ir.block, '');
});
test('returns block containing agent_skills XML for configured agent', () => {
const skillDir = path.join(tmpDir, 'skills', 'test-skill');
fs.mkdirSync(skillDir, { recursive: true });