mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-22 16:11:34 +01:00
Codex skill suggestions name each skill the way Codex lists it (GST-3195) (#4523)
On Codex, gstack's routing hint now names each skill by the `name:` in its installed SKILL.md (`review`), the name Codex lists, so `$review` loads the suggested skill. Before, the hint said `gstack-review` (the folder name), which Codex doesn't list, so mentioning it loaded nothing. Nothing to do: the next `./setup --host codex` picks it up. Claude Code's hint is unchanged. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
f82b6f76f3
commit
be83949eb6
6 files changed
+79
-13
No files matched your search
@@ -69,6 +69,41 @@ async function codexExec(extra: string[]): Promise<string> {
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Run codex exec to completion against a local stub model that answers every turn at once; returns each request body. */
|
||||
async function codexAgainstStub(prompt: string): Promise<string[]> {
|
||||
const bodies: string[] = [];
|
||||
const sse = (data: Record<string, unknown>) => `event: ${data.type}\ndata: ${JSON.stringify(data)}\n\n`;
|
||||
const server = Bun.serve({
|
||||
port: 0, hostname: '127.0.0.1',
|
||||
async fetch(req) {
|
||||
bodies.push(await req.text());
|
||||
const item = { type: 'message', id: 'msg_stub', role: 'assistant', status: 'completed', content: [{ type: 'output_text', text: 'stub', annotations: [] }] };
|
||||
const usage = { input_tokens: 1, input_tokens_details: null, output_tokens: 1, output_tokens_details: null, total_tokens: 2 };
|
||||
return new Response(sse({ type: 'response.created', response: { id: 'resp_stub' } })
|
||||
+ sse({ type: 'response.output_item.done', output_index: 0, item })
|
||||
+ sse({ type: 'response.completed', response: { id: 'resp_stub', usage } }), { headers: { 'content-type': 'text/event-stream' } });
|
||||
},
|
||||
});
|
||||
try {
|
||||
const work = path.join(dir, 'work');
|
||||
fs.mkdirSync(work, { recursive: true });
|
||||
const child = spawn('codex', ['exec', '--skip-git-repo-check', '--dangerously-bypass-hook-trust', '-c', 'model_provider=gstack_stub',
|
||||
'-c', `model_providers.gstack_stub={name="stub",base_url="http://127.0.0.1:${server.port}/v1",wire_api="responses"}`, prompt], {
|
||||
cwd: work, stdio: ['ignore', 'ignore', 'ignore'],
|
||||
env: {
|
||||
PATH: process.env.PATH ?? '', HOME: dir, CODEX_HOME: home(), OPENAI_API_KEY: 'sk-not-a-real-key', SHELL: '/bin/bash',
|
||||
GSTACK_STATE_ROOT: path.join(dir, 'state'), GSTACK_INSTALLED_SKILLS_DIR: path.join(home(), 'skills'),
|
||||
},
|
||||
});
|
||||
const killer = setTimeout(() => child.kill('SIGKILL'), 60_000);
|
||||
await new Promise(resolve => child.on('exit', resolve));
|
||||
clearTimeout(killer);
|
||||
} finally {
|
||||
server.stop(true);
|
||||
}
|
||||
return bodies;
|
||||
}
|
||||
|
||||
describe.skipIf(!usable && !required)('real codex reads the hooks.json gstack writes', () => {
|
||||
test('codex 0.170 or newer is on PATH', () => {
|
||||
expect(version?.[0] ?? 'no codex on PATH').toMatch(/^codex-cli /);
|
||||
@@ -79,10 +114,23 @@ describe.skipIf(!usable && !required)('real codex reads the hooks.json gstack wr
|
||||
install();
|
||||
const out = await codexExec(['--dangerously-bypass-hook-trust']);
|
||||
expect(fs.existsSync(marker())).toBe(true);
|
||||
expect(fs.readFileSync(routeLog(), 'utf8')).toMatch(/event=routed skill=gstack-review .*host=codex/);
|
||||
expect(fs.readFileSync(routeLog(), 'utf8')).toMatch(/event=routed skill=review .*host=codex/);
|
||||
expect(out).not.toContain('failed to parse hooks config');
|
||||
}, 90_000);
|
||||
|
||||
test("the routing hint names the skill the way Codex lists it, and that $mention loads the skill's body", async () => {
|
||||
install();
|
||||
const skill = path.join(home(), 'skills', 'gstack-review');
|
||||
fs.mkdirSync(skill, { recursive: true });
|
||||
fs.writeFileSync(path.join(skill, 'SKILL.md'), '---\nname: review\ndescription: Review a diff before it lands.\n---\nREAL_CODEX_SKILL_BODY\n');
|
||||
const [routed] = await codexAgainstStub('please review my changes');
|
||||
const hinted = /this request fits the ([A-Za-z0-9_:-]+) skill/.exec(routed ?? '')?.[1];
|
||||
expect(hinted).toBe('review');
|
||||
expect(routed).toContain(`- ${hinted}: Review a diff before it lands. (file: `);
|
||||
expect((await codexAgainstStub(`$${hinted} look at this`)).join('\n')).toContain('REAL_CODEX_SKILL_BODY');
|
||||
expect((await codexAgainstStub('$gstack-review look at this')).join('\n')).not.toContain('REAL_CODEX_SKILL_BODY');
|
||||
}, 200_000);
|
||||
|
||||
test('negative controls: an unknown key makes Codex skip the whole file, and untrusted hooks never run', async () => {
|
||||
install();
|
||||
const file = path.join(home(), 'hooks.json');
|
||||
|
||||
@@ -256,19 +256,35 @@ describe('skill routing on Codex', () => {
|
||||
|
||||
test("gstack's Codex skills take Codex's names and the triggers of the same skill in this checkout", () => {
|
||||
const { skills } = scanCodexSkills(codexSkills());
|
||||
const review = skills.find(s => s.name === 'gstack-review');
|
||||
const review = skills.find(s => s.name === 'review');
|
||||
expect(review?.gstack).toBe(true);
|
||||
expect(review?.triggers).toContain('review my changes');
|
||||
expect(skills.find(s => s.name === 'my-notes')?.triggers).toEqual([]);
|
||||
const decision = routePrompt(PAYLOADS.UserPromptSubmit.prompt, skills, undefined, 'codex');
|
||||
expect(decision.route?.skill).toBe('gstack-review');
|
||||
expect(decision.route?.skill).toBe('review');
|
||||
});
|
||||
|
||||
test('a Codex skill is named by its SKILL.md name, with or without skill_prefix, and by its folder when that name is unusable', () => {
|
||||
const names = (frontmatterName: string | null) => {
|
||||
const skills = path.join(dir, 'codex-named');
|
||||
fs.rmSync(skills, { recursive: true, force: true });
|
||||
fs.mkdirSync(path.join(skills, 'gstack-review'), { recursive: true });
|
||||
fs.writeFileSync(path.join(skills, 'gstack-review', 'SKILL.md'), '---\n' + (frontmatterName === null ? '' : 'name: ' + frontmatterName + '\n') + 'description: d\n---\n');
|
||||
const scan = scanCodexSkills(skills);
|
||||
const decision = routePrompt(PAYLOADS.UserPromptSubmit.prompt, scan.skills, undefined, 'codex');
|
||||
return { name: scan.skills[0]?.name, routed: decision.route?.skill, problems: scan.problems };
|
||||
};
|
||||
expect(names('review')).toEqual({ name: 'review', routed: 'review', problems: [] });
|
||||
expect(names('gstack-review')).toEqual({ name: 'gstack-review', routed: 'gstack-review', problems: [] });
|
||||
expect(names(null)).toEqual({ name: 'gstack-review', routed: 'gstack-review', problems: [] });
|
||||
expect(names('"not a name"')).toEqual({ name: 'gstack-review', routed: 'gstack-review', problems: [] });
|
||||
});
|
||||
|
||||
test('a $ skill mention or a / command is never routed on Codex; on Claude Code a $ prompt still routes as before', () => {
|
||||
const { skills } = scanCodexSkills(codexSkills());
|
||||
expect(routePrompt('$gstack-review review my changes', skills, undefined, 'codex')).toMatchObject({ route: null, reason: 'skill-mention' });
|
||||
expect(routePrompt('/review review my changes', skills, undefined, 'codex')).toMatchObject({ route: null, reason: 'slash-command' });
|
||||
expect(routePrompt(' $ review my changes', skills).route?.skill).toBe('gstack-review');
|
||||
expect(routePrompt(' $ review my changes', skills).route?.skill).toBe('review');
|
||||
});
|
||||
|
||||
test("the Codex line names Codex's skill; Claude Code's line is unchanged", () => {
|
||||
@@ -289,8 +305,8 @@ describe('skill routing on Codex', () => {
|
||||
expect(r.status).toBe(0);
|
||||
const out = JSON.parse(r.stdout).hookSpecificOutput;
|
||||
expect(out.hookEventName).toBe('UserPromptSubmit');
|
||||
expect(out.additionalContext).toContain('this request fits the gstack-review skill. Read and follow the gstack-review skill');
|
||||
expect(fs.readFileSync(path.join(dir, 'state', 'hooks', 'skill-route.log'), 'utf8')).toMatch(/event=routed skill=gstack-review .*host=codex/);
|
||||
expect(out.additionalContext).toContain('this request fits the review skill. Read and follow the review skill');
|
||||
expect(fs.readFileSync(path.join(dir, 'state', 'hooks', 'skill-route.log'), 'utf8')).toMatch(/event=routed skill=review .*host=codex/);
|
||||
expect(run({ GSTACK_SKILL_ROUTING: 'off' }).stdout).toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user