-
Notifications
You must be signed in to change notification settings - Fork 5.3k
fix(codex): send skill mentions as typed skill input #9494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
apps/server/src/provider/Drivers/CodexSkillDispatch.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { assert, it } from "@effect/vitest"; | ||
|
|
||
| import { hasCodexSkillMention, resolveCodexSkillMentions } from "./CodexSkillDispatch.ts"; | ||
|
|
||
| const skills = [ | ||
| { name: "ask-matt", path: "/home/theo/.agents/skills/ask-matt/SKILL.md", enabled: true }, | ||
| { name: "release", path: "/home/theo/.agents/skills/release/SKILL.md", enabled: true }, | ||
| { name: "retired", path: "/home/theo/.agents/skills/retired/SKILL.md", enabled: false }, | ||
| ]; | ||
|
|
||
| it("gates the catalog read on a skill token", () => { | ||
| assert.isTrue(hasCodexSkillMention("$ask-matt which flow fits?")); | ||
| assert.isTrue(hasCodexSkillMention("please run $release")); | ||
| assert.isFalse(hasCodexSkillMention("costs $5 and echo $ is fine")); | ||
| assert.isFalse(hasCodexSkillMention("email me@$host")); | ||
| }); | ||
|
|
||
| it("resolves each mentioned skill once, in first-mention order", () => { | ||
| assert.deepEqual( | ||
| resolveCodexSkillMentions("$release then $ask-matt and $release again", skills), | ||
| [ | ||
| { name: "release", path: "/home/theo/.agents/skills/release/SKILL.md" }, | ||
| { name: "ask-matt", path: "/home/theo/.agents/skills/ask-matt/SKILL.md" }, | ||
| ], | ||
| ); | ||
| }); | ||
|
|
||
| it("leaves unknown and disabled mentions as prose", () => { | ||
| assert.deepEqual(resolveCodexSkillMentions("set $HOME and try $retired", skills), []); | ||
| assert.deepEqual(resolveCodexSkillMentions("no tokens here", skills), []); | ||
| // A token is whitespace-delimited, as the composer chip is. | ||
| assert.deepEqual(resolveCodexSkillMentions("$ask-matt, please", skills), []); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /** | ||
| * CodexSkillDispatch — turns `$skill` mentions in a composer prompt into the | ||
| * typed `skill` input the Codex app server loads. | ||
| * | ||
| * The composer inserts `$name` for every provider. The Codex app server takes | ||
| * that as prose, and a skill that only the user may start | ||
| * (`allow_implicit_invocation: false`) is absent from the catalog the model | ||
| * sees, so the prompt names a skill the model cannot reach. Verified against | ||
| * Codex 0.152.1 by pointing it at a recording model endpoint: only a | ||
| * `{ type: "skill", name, path }` input item makes the app server inject the | ||
| * SKILL.md body into the turn; plain text and `mention` items do not. The item | ||
| * goes out beside the text, so the user's words are kept as written. | ||
| * | ||
| * The same run showed the app server dropping skill items from input that | ||
| * steers a turn already running, so the item only lands on a turn Codex starts | ||
| * fresh. That limit is Codex's own and nothing here works around it. | ||
| * | ||
| * @module provider/Drivers/CodexSkillDispatch | ||
| */ | ||
|
|
||
| /** | ||
| * Same token shape the timeline chip recognises on a sent message | ||
| * (`apps/web/src/components/chat/SkillInlineText.tsx`) and that Claude | ||
| * dispatch uses, so a rendered chip and a dispatched skill are always the same | ||
| * set. End of text counts as a boundary because the composer trims the prompt | ||
| * on send: a skill picked last arrives as `$name` with nothing after it. The | ||
| * editor's own regex (`packages/shared/src/composerInlineTokens.ts`) wants | ||
| * trailing whitespace only because the picker inserts one while typing. | ||
| */ | ||
| const SKILL_MENTION_PATTERN = /(^|\s)\$([a-zA-Z][a-zA-Z0-9:_-]*)(?=\s|$)/g; | ||
| const SKILL_MENTION_TEST = /(^|\s)\$[a-zA-Z][a-zA-Z0-9:_-]*(?=\s|$)/; | ||
|
|
||
| export interface CodexSkillInput { | ||
| readonly name: string; | ||
| readonly path: string; | ||
| } | ||
|
|
||
| /** Cheap gate for the catalog read: a prompt with no `$name` token needs none. */ | ||
| export function hasCodexSkillMention(prompt: string): boolean { | ||
| return SKILL_MENTION_TEST.test(prompt); | ||
| } | ||
|
|
||
| /** | ||
| * Every discovered, enabled skill the prompt names, once each in first-mention | ||
| * order. Mentions that name nothing discovered stay literal: a `$HOME` in prose | ||
| * must not become an invocation. | ||
| */ | ||
| export function resolveCodexSkillMentions( | ||
| prompt: string, | ||
| skills: ReadonlyArray<{ | ||
| readonly name: string; | ||
| readonly path: string; | ||
| readonly enabled: boolean; | ||
| }>, | ||
| ): ReadonlyArray<CodexSkillInput> { | ||
| const pathByName = new Map<string, string>(); | ||
| for (const skill of skills) { | ||
| if (skill.enabled && !pathByName.has(skill.name)) pathByName.set(skill.name, skill.path); | ||
| } | ||
| const resolved = new Map<string, string>(); | ||
| for (const match of prompt.matchAll(SKILL_MENTION_PATTERN)) { | ||
| const name = match[2] ?? ""; | ||
| const path = pathByName.get(name); | ||
| if (path !== undefined && !resolved.has(name)) resolved.set(name, path); | ||
| } | ||
| return Array.from(resolved, ([name, path]) => ({ name, path })); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.