library: a Codex plugin's manifest is read like a Claude Code one, and its hooks go to Codex (#7255)
A folder with .codex-plugin/plugin.json is a plugin now. Its skills and mcpServers are read like Claude's manifest fields (Claude's win where both name one). The hooks it names (a path, a list of paths or inline) are Codex's own: kept as written as codex:<Event> hooks with their matcher and given to Codex alone, so .codex/hooks.json gets them and Claude's settings do not. An event Codex has none called (codexHookSpec's native list, from codex-rs/hooks) is left out and said. A manifest's mcpServers naming ./.mcp.json no longer reads that file twice. Codex 0.165's binary names .codex-plugin/plugin.json and resolves plugin.json#hooks; the shape matches hooks/hooks.json. Ported in outline from Arobotmaster's 874624ed, not its code: that commit also changed session-start matchers and put env on script hooks, which are other goals. Run on mote: gofmt, go vet ./internal/library, go test ./internal/library and ./internal/cli (whole packages, ok); new TestPluginCodexManifest (probe counts, Codex gets the hooks, Claude gets none, remove takes them out). Not tried: a real Codex plugin from a marketplace (Codex marketplaces are not read), a plugin with both manifests naming different hooks, Codex actually running the carried hooks.
This commit is contained in:
@@ -43,7 +43,7 @@ Pi's extensions and packages.
|
||||
| Slash commands | A `Command` (miantiao_me on X) is a name (lowercase letters, digits, - and _), a one-line description and a prompt, given to the agents ticked for it, and typed as /name there. The prompt says `$ARGUMENTS` for every word typed after the name and `$1`, `$2`… for the first, second… of them. `syncCommands` writes it as a file of its own in each agent's user-level folder, in that agent's shape (`commandSpecOf`): `<claude dir>/commands/<name>.md` (front matter `description`; `$n` becomes Claude Code's `$ARGUMENTS[n-1]`, counted from 0), OpenCode's `commands/<name>.md` beside its config and Pi's `<agent dir>/prompts/<name>.md` (`$ARGUMENTS` and `$n` as magpie's), `~/.gemini/commands/<name>.toml` (`description`, `prompt`, `$ARGUMENTS` as `{{args}}`), Qwen Code's `commands/<name>.md` (`{{args}}`) and `~/.factory/commands/<name>.md` (`$ARGUMENTS`). Gemini CLI, Qwen Code and Droid take no words by place, so a command that uses `$1`… isn't written for them: the agent gets a problem, the editor names them under the prompt while it uses one, and the tab says so under the list. Codex is listed but greyed: Codex 0.165 has no loader of `~/.codex/prompts` any more, its skills took their place. An agent in a WSL distro gets none. The page lists, per agent, its folder and whether it takes `$1`… (`CommandAgentView`). There is no CLI for them yet. | [`commands.go`](../../internal/library/commands.go), `TestCommandsEachAgentsFile`, `TestCommandsWordsByPlace` |
|
||||
| Slash commands from the agents | The Slash commands tab's "Find in agents" (miantiao_me on X: "can the ones I defined in Pi be imported?") lists the commands the user already made in each agent here (`ProbeCommands`), read where that agent reads them, at the folder's top only: Pi's `prompts/*.md`, Claude Code's `commands/*.md`, OpenCode's `commands/*.md` and `command/*.md`, Gemini CLI's `commands/*.toml`, Qwen Code's `commands/*.md` and `*.toml` (its FileCommandLoader reads both) and Droid's `commands/*.md`. The file's name is the command's; the description is the front matter's (a TOML's `description`), the prompt the body (a TOML's `prompt`), and each agent's way of saying the words typed in reads back as magpie's: Claude Code's `$ARGUMENTS[n]` and `$n`, counted from 0, as `$n+1` (the `\$0` magpie writes as `$0`), Pi's `$@` and Gemini's and Qwen's `{{args}}` as `$ARGUMENTS`; Pi's `${@:N}` is left as written. A name magpie can't take, a file over 1 MB or one with no prompt is listed as left out, with why. A file magpie wrote, still as it wrote it (`Applied.Commands`), isn't listed. One name saying the same in several agents is one candidate for all of them; saying different things, each is listed, tagged, and only one can be picked. A name the library has saying the same is tagged and joins (the import ticks these agents too); one the library has for another command can't be picked, and the user's file stays as it is. `ImportCommands` takes the paths picked, reads them again, and ticks the agents each was found in. Each command keeps the files it came from (`Command.Taken`, per agent: path, bytes, and a hash of what they said): while the command says the same, `syncCommands` writes those bytes at that path, so `syncOwnFiles` takes the user's own file as magpie's byte for byte, and nothing is doubled or written over (OpenCode's `command/` file stays there). After an edit here, the command is written in the agent's shape at the same path when its extension is the one magpie writes, else at magpie's own path. A rename drops `Taken`. Unticking or removing an imported command takes its file away, into the backups, as with any file of magpie's. `Taken` is this computer's: never in `Bundle.Commands` or the page's view, and a bundle put here keeps it for a command of the same name. | [`command_import.go`](../../internal/library/command_import.go), `TestCommandImportPiPrompts` (Pi's own `.pi/prompts` files in `testdata/pi-prompts`), `TestCommandImportArgs`, `TestCommandImportByName`, `TestCommandImportNotCarried`, `library-commands-import.test.cjs` |
|
||||
| Rules | A `Rule` (JonahFu on X) is a name (as a slash command's), a Markdown body and, if wanted, `Paths`: globs, one a line in the editor, that keep it to the files they match. `syncRules` writes it as `<name>.md` in each ticked agent's own folder of rules (`ruleSpecOf`), through the shared `syncOwnFiles`: Claude Code's `<claude dir>/rules` (front matter `paths`, the only key it reads; checked against the memory docs and v2.1.327, which reads every .md under the folder, loads one without `paths` at launch and one with them when Read/Write/Edit touches a match), Cline's `<cline dir>/rules` (CLINE_DIR, else ~/.cline; Cline 3.0.70 reads every rule always and has no paths key, so a rule with paths isn't written for it: the agent gets a problem (`noPaths`), and the editor names it under the paths) and Kiro CLI's steering folder beside its AGENTS.md (`inclusion: fileMatch` and `fileMatchPattern` for paths, else always; a rule called `agents` is refused there, as it would be AGENTS.md on a disk that ignores case). A body starting with `---` gets an empty front matter first, so it isn't read as one. Cursor (user rules live in its settings, `.cursor/rules` is per project), Codex (its rules are execpolicy) and Droid (command permissions) read no such folder and aren't listed; nor are Gemini CLI, Qwen Code and OpenCode, which read only their instructions file. An agent in a WSL distro gets none. The editor lists each agent's file as a path to show (`revealable`). Bundles carry them as slash commands; there is no CLI yet. | [`rules.go`](../../internal/library/rules.go), `TestRulesEachAgentsFile`, `TestRulesKeptToTheirPaths`, `TestRulesLeaveTheUsersFiles`, `TestRulesCarried`, `library-rules.test.cjs` |
|
||||
| Claude plugins | A `Plugin` (FakeshadowzZ on X) is a Claude Code plugin kept as one item: `.claude-plugin/plugin.json`, `skills/<name>/SKILL.md`, `agents/*.md`, `hooks/hooks.json` and `.mcp.json`, from a folder, a git address or a marketplace.json (`ProbePlugins`, `InstallPlugins`; a marketplace entry with a relative path, or a github/url/git source, is fetched when installed). Its files are copied to `<library>/plugins/<name>`; `${CLAUDE_PLUGIN_ROOT}` is that folder and `${CLAUDE_PLUGIN_DATA}` is `<library>/plugin-data/<name>`, which an update keeps. No agent sets either variable outside Claude Code's plugin runtime, so every reference is resolved before a part is written out ([`plugin_env.go`](../../internal/library/plugin_env.go)): `${NAME}`/`$NAME` in a hook command, a server's command, args and env, a subagent's prompt and a copied SKILL.md become the folder; a hook program's own read (`process.env.NAME`, `Bun.env`, `Deno.env.get`, Python's `os.environ`/`os.getenv`, Ruby's `ENV`) becomes a quoted string literal of the folder with forward slashes, and PowerShell's `$env:NAME` and cmd's `%NAME%` the folder (ponytail's hooks threw at every start without it, @AXmake110 on X); a command server is given both variables in its env, as Claude Code gives them. Parts a magpie before this wrote with the variables in them are resolved at load (`healPluginRefs`) and written out again at the next sync; a SKILL.md copied before is fixed by Update or a reinstall. Exec-form hooks (`args`) and `CLAUDE_PLUGIN_OPTION_<KEY>` are not carried yet (#6682). Its parts are ordinary library skills, MCP servers, hooks and subagents, each tagged `Bundle: <plugin>`, so every agent gets them through the code of its kind and the old tabs go on working; the plugin holds the names, its agents and `Off`. `PluginAgents` sets every part's agents, `PluginOn` clears them (kept in `Agents` for turning it on again) or gives them back, `RemovePlugin` removes the parts (and takes the plugin out of every project), `ProjectPlugin` gives it to a project (see Projects), and `UpdatePlugin` reads the source again. A hook whose Claude event and matcher have a portable event becomes it (Stop turn-end, PostToolUse after-tool, PreToolUse before-tool, UserPromptSubmit prompt, SessionStart session-start; Bash is shell, Edit/Write/MultiEdit is edit); any other event is `claude:<Event>`, for Claude Code only. Subagents go to the agents in `SubagentAgents`. A part whose name the library has gets the prefix `<plugin>-`: the user's own item is never written over or removed. Slash commands, LSP servers and hooks that aren't a command are listed in `Left` and shown, not carried. A plugin goes to another computer whole, by sync or a backup file (#6685, JJasonsun on Discord; [`plugin_carry.go`](../../internal/library/plugin_carry.go)): `Bundle.Plugins` carries each record (name, version, source, pick, agents, `Off`, and the parts taken out by hand), never its parts, which name this computer's folder. A plugin from a GitHub or git link goes as that source, and the other computer installs it from there as `UpdatePlugin` does, outside the library's lock; one it can't fetch yet is kept with `Pending`, its old parts if any, and a problem, the row says so, and Update or the next sync tries again. A plugin from a folder, or a link holding a sign-in (whose link isn't carried), goes with its files, on the skills' budget, and is installed from them. Either way that computer reads the parts again, so every hook, server and skill names its own `<library>/plugins/<name>`, Windows' too. A plugin the bundle no longer has is removed with its folder. A bundle from a magpie before this has no `plugins`, and this computer's plugins keep their parts over the same-named items it carries. A marketplace entry's own fields (`strict: false`) aren't carried, so a local marketplace plugin is read from its files alone there. A plugin installed from a marketplace under a name other than its manifest's names that folder in its parts too (`TestPluginCarriedWhole`, `TestPluginCarriedBySource`, `TestPluginOldBundleKeepsPlugins`, `TestPluginMarketplaceNameIsItsFolder`, davsync's `TestSyncLibraryPlugins`, `TestPluginImportCarryOnOffRemove`, `TestPluginHookReadsRootFromItsProgram`, `TestPluginHookWrittenBeforeIsResolved`, `TestPluginPartsGetItsFolders`, `TestPluginNameClashKeepsTheUsersOwn`, `TestPluginMarketplaceAndUpdate`, `TestPluginRefusesWhatIsNone`, `library-plugins.test.cjs`). | [`plugin.go`](../../internal/library/plugin.go), [`plugins/library/client.js`](../../internal/gui/assets/plugins/library/client.js) |
|
||||
| Claude plugins | A `Plugin` (FakeshadowzZ on X) is a Claude Code plugin kept as one item: `.claude-plugin/plugin.json` (or Codex's `.codex-plugin/plugin.json`, #7255: its `skills`, `mcpServers` and `hooks` read the same way, Claude's fields winning where both name one; the hooks it names are Codex's own, kept as written as `codex:<Event>` and given to Codex alone, an event Codex has none called is left out; `plugin_codex_test.go`), `skills/<name>/SKILL.md`, `agents/*.md`, `hooks/hooks.json` and `.mcp.json`, from a folder, a git address or a marketplace.json (`ProbePlugins`, `InstallPlugins`; a marketplace entry with a relative path, or a github/url/git source, is fetched when installed). Its files are copied to `<library>/plugins/<name>`; `${CLAUDE_PLUGIN_ROOT}` is that folder and `${CLAUDE_PLUGIN_DATA}` is `<library>/plugin-data/<name>`, which an update keeps. No agent sets either variable outside Claude Code's plugin runtime, so every reference is resolved before a part is written out ([`plugin_env.go`](../../internal/library/plugin_env.go)): `${NAME}`/`$NAME` in a hook command, a server's command, args and env, a subagent's prompt and a copied SKILL.md become the folder; a hook program's own read (`process.env.NAME`, `Bun.env`, `Deno.env.get`, Python's `os.environ`/`os.getenv`, Ruby's `ENV`) becomes a quoted string literal of the folder with forward slashes, and PowerShell's `$env:NAME` and cmd's `%NAME%` the folder (ponytail's hooks threw at every start without it, @AXmake110 on X); a command server is given both variables in its env, as Claude Code gives them. Parts a magpie before this wrote with the variables in them are resolved at load (`healPluginRefs`) and written out again at the next sync; a SKILL.md copied before is fixed by Update or a reinstall. Exec-form hooks (`args`) and `CLAUDE_PLUGIN_OPTION_<KEY>` are not carried yet (#6682). Its parts are ordinary library skills, MCP servers, hooks and subagents, each tagged `Bundle: <plugin>`, so every agent gets them through the code of its kind and the old tabs go on working; the plugin holds the names, its agents and `Off`. `PluginAgents` sets every part's agents, `PluginOn` clears them (kept in `Agents` for turning it on again) or gives them back, `RemovePlugin` removes the parts (and takes the plugin out of every project), `ProjectPlugin` gives it to a project (see Projects), and `UpdatePlugin` reads the source again. A hook whose Claude event and matcher have a portable event becomes it (Stop turn-end, PostToolUse after-tool, PreToolUse before-tool, UserPromptSubmit prompt, SessionStart session-start; Bash is shell, Edit/Write/MultiEdit is edit); any other event is `claude:<Event>`, for Claude Code only. Subagents go to the agents in `SubagentAgents`. A part whose name the library has gets the prefix `<plugin>-`: the user's own item is never written over or removed. Slash commands, LSP servers and hooks that aren't a command are listed in `Left` and shown, not carried. A plugin goes to another computer whole, by sync or a backup file (#6685, JJasonsun on Discord; [`plugin_carry.go`](../../internal/library/plugin_carry.go)): `Bundle.Plugins` carries each record (name, version, source, pick, agents, `Off`, and the parts taken out by hand), never its parts, which name this computer's folder. A plugin from a GitHub or git link goes as that source, and the other computer installs it from there as `UpdatePlugin` does, outside the library's lock; one it can't fetch yet is kept with `Pending`, its old parts if any, and a problem, the row says so, and Update or the next sync tries again. A plugin from a folder, or a link holding a sign-in (whose link isn't carried), goes with its files, on the skills' budget, and is installed from them. Either way that computer reads the parts again, so every hook, server and skill names its own `<library>/plugins/<name>`, Windows' too. A plugin the bundle no longer has is removed with its folder. A bundle from a magpie before this has no `plugins`, and this computer's plugins keep their parts over the same-named items it carries. A marketplace entry's own fields (`strict: false`) aren't carried, so a local marketplace plugin is read from its files alone there. A plugin installed from a marketplace under a name other than its manifest's names that folder in its parts too (`TestPluginCarriedWhole`, `TestPluginCarriedBySource`, `TestPluginOldBundleKeepsPlugins`, `TestPluginMarketplaceNameIsItsFolder`, davsync's `TestSyncLibraryPlugins`, `TestPluginImportCarryOnOffRemove`, `TestPluginHookReadsRootFromItsProgram`, `TestPluginHookWrittenBeforeIsResolved`, `TestPluginPartsGetItsFolders`, `TestPluginNameClashKeepsTheUsersOwn`, `TestPluginMarketplaceAndUpdate`, `TestPluginRefusesWhatIsNone`, `library-plugins.test.cjs`). | [`plugin.go`](../../internal/library/plugin.go), [`plugins/library/client.js`](../../internal/gui/assets/plugins/library/client.js) |
|
||||
| Backups | Before a change first writes an agent file, `backups` copies it to `BackupDir`, one folder per change. The last `keepBackups` (30) changes are kept. The Backups button at the top of every tab, beside Library folder, opens that folder (`libHead`; Dade on Discord found it at the foot of a long page). | [`backup.go`](../../internal/library/backup.go) |
|
||||
| RTK | `SetRTK` runs rtk's own installer (`rtk init -g …`) for an agent being switched on. For one being switched off, it removes exactly what the installer wrote, using magpie's own code, which works even with rtk gone. An rtk.exe in one of winget's folders that winget has no record of (`winget list` says so, or its records name another folder; netube99 on X, 0x8A150014) is upgraded from rtk's own Windows release over the file a `WinGet\Links` link points to, not by `winget upgrade`. `ReadRTK` reads each agent's files to say which have the hook. An agent gone for its CLI (`CLIMissing`, #2254) isn't offered rtk, but one that still has the hook is listed so it can be taken out. `rtkSpec.blocked` stops the installer where it would break an agent. `rtkSpec.env` tells the installer the agent's folder where rtk would pick another: Hermes Agent's is `appdir.HermesHome` (`%LOCALAPPDATA%\hermes` on Windows), which rtk is given as `HERMES_HOME`, since rtk 0.51 knows only `$HERMES_HOME` and `~/.hermes`. Antigravity CLI (`agy`, #2202) gets rtk 0.51's own plugin for Antigravity, `plugins/rtk` in its global customization folder `~/.gemini/config` (`plugin.json`, `hooks.json` with `PreToolUse` → `rtk hook antigravity`, `rules/AGENTS.md`), which `agy plugin list` lists; switching it off takes that one folder out. rtk 0.50 knows Antigravity only per project and fails `rtk init -g --agent antigravity`, so an older rtk is `blocked` (`agyBlocked`) and the row says to update RTK. OpenCode 2 loads only the plugin rtk 0.52 on writes (one default object with `id` and `setup()`, rtk-ai/rtk#4187); an older rtk's plugin is for OpenCode 1 and OpenCode 2 refuses it, so with an OpenCode 2 here an older rtk is `blocked` (`openCodeBlocked`) and the row says to update RTK (#2295). Under OpenCode 2, an old plugin left from before an rtk update counts as off once the rtk here can write the new one (`openCodeHas`), so switching it on writes the new one over it; with an older rtk it counts as on, so it can be switched off. Factory's Droid (lml0664 on Discord) gets rtk's own `rtk init -g --agent droid`, given Droid's folder as `FACTORY_HOME_OVERRIDE`; rtk puts its `Execute` group (`rtk hook droid`) in the root `hooks.json`, or in `settings.json`'s `hooks.PreToolUse` where Droid's hooks already are, so `droidHookFiles` reads and switches off all three places rtk 1.1.0 may use (`hooks.json`, `hooks/hooks.json`, `settings.json`), leaving the user's own hooks. rtk before 0.44 has no Droid agent, so it is `blocked` (`droidBlocked`). A detected agent RTK has no hook for at all is still listed, from `rtkNoHook`, with the reason and a switch that can't be turned on (dsh: its hooks can allow or deny a command but not rewrite it, and `rtk init` has no `--agent dsh`; Grok Build and Grok App: `rtk init` has no Grok or Grok App agent, so both are listed with the switch off; Qoder and Qoder CN: rtk 1.1.0 has no Qoder agent; Cline and Kimi Code: `rtk init --agent cline|kimi` writes only one project's `.clinerules` or `AGENTS.md`, instructions with no hook, and Kimi's refuses `-g`). RTK 1.1.0's Trae, Windsurf, Kilo Code and Mistral Vibe have no magpie agent. The page's No RTK hook tag gives each agent's own reason and rtk-ai/rtk issue (`rtkNoHookWhy` in plugins/library/client.js: dsh #3847, Grok Build and Grok App #2136, Qoder and Qoder CN #1327, Cline #3841), and an agent with no entry gets no link; `TestRTKNoHookIssuesAreEachAgents` fails when the page and `rtkNoHook` cite different issues, or two agents cite the same ones without a reason in `sharedRTKIssues`. | [`rtk.go`](../../internal/library/rtk.go) |
|
||||
| RTK in WSL | An agent in a WSL distro (`claude@wsl:Ubuntu`) is listed by its kind (`rtkKind`), and its hook runs in the distro, where Windows' rtk.exe is no command, so it gets the distro's own rtk (lex on Discord). `rtkDistroOf` asks the distro with `wsl.exe -d <distro> -e sh -lc` where rtk is (a login or interactive shell's PATH; else `~/.local/bin` or `~/.cargo/bin`, `offPath`), kept 15s; `ReadRTK` lists one `RTKDistro` for each distro its agents are in. Install RTK in WSL `<distro>` (`InstallRTKIn`, `POST /api/library/rtk/install` with `distro`, `magpie library rtk install <distro>`) runs RTK's own Linux installer in the distro (`curl -fsSL …/install.sh \| sh`, wget where there's no curl). Switching an agent on runs the distro's rtk there (`rtkInstallWSL`: `rtk init -g …` with its folder on PATH, Claude Code pointed at a folder of its own for the OpenCode and Cursor installers), and reads and edits its files under the distro's home as magpie opens it (`rtkClaudeDir`, `rtkCodexDir`, `rtkHome`). A distro that isn't running is never started (#3896): `rtkWSLLive` and `rtkDistroOf` check `agent.WSLRunning` first, its agents are listed `asleep` with the switch off, and switching or installing says to start it (`TestRTKWSLAsleep`). The page gives each distro a card (`rtkDistroCard` in plugins/library/client.js; library-rtk-wsl.test.cjs). | [`rtk_wsl.go`](../../internal/library/rtk_wsl.go) |
|
||||
|
||||
@@ -178,7 +178,7 @@ func pluginSlug(s string) string {
|
||||
|
||||
// isPlugin is whether dir looks like a plugin's folder.
|
||||
func isPlugin(dir string) bool {
|
||||
for _, p := range []string{".claude-plugin/plugin.json", "skills", "agents", "commands", "hooks/hooks.json", ".mcp.json"} {
|
||||
for _, p := range []string{".claude-plugin/plugin.json", ".codex-plugin/plugin.json", "skills", "agents", "commands", "hooks/hooks.json", ".mcp.json"} {
|
||||
if _, err := os.Stat(filepath.Join(dir, filepath.FromSlash(p))); err == nil {
|
||||
return true
|
||||
}
|
||||
@@ -199,13 +199,27 @@ func readPlugin(dir, hint, force string, over map[string]any) (*plLoaded, error)
|
||||
} else if !errors.Is(err, fs.ErrNotExist) {
|
||||
return nil, err
|
||||
}
|
||||
// Codex's own manifest (#7255) names the same parts the same way: skills,
|
||||
// mcpServers, hooks. Claude Code's fields win where both name one, so a
|
||||
// part is carried once. Its hooks are read apart below: they are Codex's.
|
||||
var codexHooks any
|
||||
if cx, err := readJSONFile(filepath.Join(dir, ".codex-plugin", "plugin.json")); err == nil {
|
||||
codexHooks = cx["hooks"]
|
||||
for k, v := range cx {
|
||||
if _, ok := man[k]; !ok && k != "hooks" {
|
||||
man[k] = v
|
||||
}
|
||||
}
|
||||
} else if !errors.Is(err, fs.ErrNotExist) {
|
||||
return nil, err
|
||||
}
|
||||
for k, v := range over {
|
||||
if _, ok := man[k]; !ok {
|
||||
man[k] = v
|
||||
}
|
||||
}
|
||||
if !isPlugin(dir) && len(man) == 0 {
|
||||
return nil, fmt.Errorf("no Claude Code plugin in %s: it has no .claude-plugin/plugin.json, skills, agents, hooks or .mcp.json", dir)
|
||||
return nil, fmt.Errorf("no plugin in %s: it has no .claude-plugin/plugin.json, .codex-plugin/plugin.json, skills, agents, hooks or .mcp.json", dir)
|
||||
}
|
||||
name := pluginSlug(force)
|
||||
if name == "" {
|
||||
@@ -292,6 +306,7 @@ func readPlugin(dir, hint, force string, over map[string]any) (*plLoaded, error)
|
||||
|
||||
// MCP servers
|
||||
var mcpDocs []map[string]any
|
||||
mcpRead := filepath.Join(dir, ".mcp.json")
|
||||
if m, err := readJSONFile(filepath.Join(dir, ".mcp.json")); err == nil {
|
||||
mcpDocs = append(mcpDocs, m)
|
||||
} else if !errors.Is(err, fs.ErrNotExist) {
|
||||
@@ -300,7 +315,8 @@ func readPlugin(dir, hint, force string, over map[string]any) (*plLoaded, error)
|
||||
for _, v := range manifestList(man["mcpServers"]) {
|
||||
switch x := v.(type) {
|
||||
case string:
|
||||
if d, ok := inside(dir, x); ok {
|
||||
// a manifest naming ./.mcp.json names the file already read
|
||||
if d, ok := inside(dir, x); ok && filepath.Clean(d) != mcpRead {
|
||||
if m, err := readJSONFile(d); err == nil {
|
||||
mcpDocs = append(mcpDocs, m)
|
||||
} else {
|
||||
@@ -347,6 +363,34 @@ func readPlugin(dir, hint, force string, over map[string]any) (*plLoaded, error)
|
||||
p.hooks = append(p.hooks, hooks...)
|
||||
p.left = append(p.left, left...)
|
||||
}
|
||||
// the hooks Codex's manifest names (a path, a list of paths or the hooks
|
||||
// themselves) are Codex's own, as written: its events and matchers, given
|
||||
// to Codex alone
|
||||
for _, v := range manifestList(codexHooks) {
|
||||
var doc map[string]any
|
||||
switch x := v.(type) {
|
||||
case string:
|
||||
d, ok := inside(dir, x)
|
||||
if !ok {
|
||||
leave(x, "the path leaves the plugin's folder")
|
||||
continue
|
||||
}
|
||||
m, err := readJSONFile(d)
|
||||
if err != nil {
|
||||
leave(x, err.Error())
|
||||
continue
|
||||
}
|
||||
doc = m
|
||||
case map[string]any:
|
||||
doc = x
|
||||
}
|
||||
if doc == nil {
|
||||
continue
|
||||
}
|
||||
hooks, left := plHooksOfAgent(doc, name, root, sub, &n, "codex")
|
||||
p.hooks = append(p.hooks, hooks...)
|
||||
p.left = append(p.left, left...)
|
||||
}
|
||||
|
||||
// what no agent here takes
|
||||
if es, err := os.ReadDir(filepath.Join(dir, "commands")); err == nil {
|
||||
@@ -541,6 +585,14 @@ func toolKind(m string) (string, bool) {
|
||||
// is the portable one; any other is given to Claude Code alone, as
|
||||
// written.
|
||||
func plHooksOf(doc map[string]any, bundle, root string, sub func(string) string, n *int) ([]*Hook, []PluginLeft) {
|
||||
return plHooksOfAgent(doc, bundle, root, sub, n, "")
|
||||
}
|
||||
|
||||
// plHooksOfAgent is plHooksOf for a hooks file one agent's own manifest
|
||||
// names: agent is that agent ("codex"), and each hook keeps its event and
|
||||
// matcher as the file wrote them, as that agent's own event, which no other
|
||||
// agent is given. "" is the portable reading.
|
||||
func plHooksOfAgent(doc map[string]any, bundle, root string, sub func(string) string, n *int, agent string) ([]*Hook, []PluginLeft) {
|
||||
m, _ := doc["hooks"].(map[string]any)
|
||||
if m == nil {
|
||||
m = doc
|
||||
@@ -579,7 +631,14 @@ func plHooksOf(doc map[string]any, bundle, root string, sub func(string) string,
|
||||
if t, ok := hm["timeout"].(float64); ok && t > 0 && t <= 86400 {
|
||||
x.Timeout = int(t)
|
||||
}
|
||||
if portable, ok := claudeEvents[ev]; ok {
|
||||
if agent == "codex" {
|
||||
if !slices.Contains(codexHookSpec("").native, ev) {
|
||||
left = append(left, PluginLeft{What: ev + " hook", Why: "Codex has no event called " + ev})
|
||||
*n--
|
||||
continue
|
||||
}
|
||||
x.Event, x.Matcher = "codex:"+ev, matcher
|
||||
} else if portable, ok := claudeEvents[ev]; ok {
|
||||
k, tools := toolKind(matcher)
|
||||
if slices.Contains(toolEvents, portable) && tools {
|
||||
x.Event, x.Matcher = portable, k
|
||||
@@ -587,7 +646,7 @@ func plHooksOf(doc map[string]any, bundle, root string, sub func(string) string,
|
||||
x.Event = portable
|
||||
}
|
||||
}
|
||||
if x.Event == "" {
|
||||
if x.Event == "" && agent == "" {
|
||||
if !slices.Contains(claudeHookEvents, ev) {
|
||||
left = append(left, PluginLeft{What: ev + " hook", Why: "Claude Code has no event called " + ev})
|
||||
*n--
|
||||
@@ -682,7 +741,7 @@ func resolvePluginRoot(input string) (root, tmp string, err error) {
|
||||
if !fi.IsDir() {
|
||||
// .claude-plugin/marketplace.json or plugin.json
|
||||
dir = filepath.Dir(dir)
|
||||
if filepath.Base(dir) == ".claude-plugin" {
|
||||
if filepath.Base(dir) == ".claude-plugin" || filepath.Base(dir) == ".codex-plugin" {
|
||||
dir = filepath.Dir(dir)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package library
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// A plugin with only Codex's manifest (#7255) is imported like a Claude Code
|
||||
// one: its skills and servers by the manifest's paths, and the hooks it names
|
||||
// are Codex's own, given to Codex alone, as written.
|
||||
func TestPluginCodexManifest(t *testing.T) {
|
||||
h := sandbox(t)
|
||||
pluginAgents(t, h)
|
||||
src := filepath.Join(t.TempDir(), "cx")
|
||||
write(t, filepath.Join(src, ".codex-plugin/plugin.json"), `{"name":"cx-kit","version":"0.3.0","description":"For Codex","skills":"./skills/","mcpServers":"./.mcp.json","hooks":"./codex-hooks.json"}`)
|
||||
write(t, filepath.Join(src, "skills/tdd/SKILL.md"), "---\nname: tdd\ndescription: Test first\n---\nWrite the test first.\n")
|
||||
write(t, filepath.Join(src, ".mcp.json"), `{"mcpServers":{"cx-db":{"command":"db"}}}`)
|
||||
write(t, filepath.Join(src, "codex-hooks.json"), `{"hooks":{
|
||||
"PermissionRequest":[{"matcher":"Bash","hooks":[{"type":"command","command":"echo ask"}]}],
|
||||
"Stop":[{"hooks":[{"type":"command","command":"echo done"}]}],
|
||||
"Nonsense":[{"hooks":[{"type":"command","command":"echo no"}]}]}}`)
|
||||
|
||||
p, err := ProbePlugins(src)
|
||||
if err != nil || len(p.Candidates) != 1 {
|
||||
t.Fatalf("probe: %v %+v", err, p)
|
||||
}
|
||||
c := p.Candidates[0]
|
||||
if c.Name != "cx-kit" || c.Skills != 1 || c.MCP != 1 || c.Hooks != 2 || len(c.Left) != 1 {
|
||||
t.Fatalf("candidate: %+v", c)
|
||||
}
|
||||
ok(t)(InstallPlugins(src, nil, []string{"claude", "codex"}))
|
||||
codex := read(t, filepath.Join(h, ".codex/hooks.json"))
|
||||
for _, want := range []string{"PermissionRequest", "echo ask", "Stop", "echo done"} {
|
||||
if !strings.Contains(codex, want) {
|
||||
t.Errorf("codex hooks lack %q:\n%s", want, codex)
|
||||
}
|
||||
}
|
||||
if s := read(t, filepath.Join(h, ".claude/settings.json")); strings.Contains(s, "echo ask") || strings.Contains(s, "echo done") {
|
||||
t.Errorf("claude was given Codex's hooks:\n%s", s)
|
||||
}
|
||||
if !strings.Contains(read(t, filepath.Join(h, ".codex/config.toml")), "cx-db") {
|
||||
t.Errorf("codex lacks the server")
|
||||
}
|
||||
ok(t)(RemovePlugin("cx-kit"))
|
||||
if s := read(t, filepath.Join(h, ".codex/hooks.json")); strings.Contains(s, "echo ask") {
|
||||
t.Errorf("hooks stay after remove:\n%s", s)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user