From 69d7bb3b317557240e3fbf491ebcaf844c9f7afc Mon Sep 17 00:00:00 2001 From: viragtripathi Date: Fri, 9 Oct 2026 03:24:56 -0400 Subject: [PATCH] fix: make the safety hooks and MCP servers work in Codex The safety hooks never ran in Codex, for four separate reasons: - Codex looks for plugin hooks in hooks/hooks.json, and the file sat at the plugin root, so it was never loaded. It now lives in plugins/cockroachdb/hooks/hooks.json. - Codex replaces every character outside [A-Za-z0-9_] in MCP tool names, so the Toolbox SQL tool is mcp__cockroachdb_toolbox__cockroachdb_execute_sql. The hyphenated matcher never matched it. - Codex runs hook commands in the session's working directory, so python3 ./scripts/... couldn't find the script, and Python's exit 2 would have blocked every matched call. Commands now reference "${PLUGIN_ROOT}/scripts/...", which Codex substitutes, and end with "; exit 0" so a missing or crashing script fails open. - Codex rejects unknown top-level keys in hook output and then ignores the whole output, so the scripts' Copilot CLI fields made a deny a no-op. The scripts take a --codex flag that emits only the keys Codex accepts; without it their output is unchanged. check-sql-files.py also reads the edited paths out of apply_patch input, which is how Codex edits files, so the lint now runs after Codex edits. The localhost cockroachdb-toolbox-http server is gone: it failed unless Toolbox was already serving HTTP on port 5000. The README no longer says the cluster ID is required, documents turning off a backend through config.toml, replaces the nonexistent codex plugin trust command with /hooks, fixes the secure-cluster troubleshooting (Codex never forwarded the SSL variables it described), and adds Toolbox over HTTP and the first-party CockroachDB MCP Server as alternative backends. The execute-sql description no longer promises DDL and DML, since Toolbox runs read-only. Related to cockroachdb/claude-plugin#27 --- AGENTS.md | 8 +- CONTRIBUTING.md | 16 ++- README.md | 96 ++++++++++----- plugins/cockroachdb/.mcp.json | 5 - plugins/cockroachdb/hooks.json | 28 ----- plugins/cockroachdb/hooks/hooks.json | 30 +++++ .../cockroachdb/scripts/check-sql-files.py | 109 ++++++++++++++---- plugins/cockroachdb/scripts/validate-sql.py | 51 ++++++-- plugins/cockroachdb/tools.yaml | 8 +- scripts/validate-marketplace-install.sh | 2 +- tests/test_plugin_package.py | 81 ++++++++++++- 11 files changed, 318 insertions(+), 116 deletions(-) delete mode 100644 plugins/cockroachdb/hooks.json create mode 100644 plugins/cockroachdb/hooks/hooks.json diff --git a/AGENTS.md b/AGENTS.md index 8984038..2a20bc5 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -19,21 +19,21 @@ codex plugin add cockroachdb@cockroachdb-codex-plugin - **Never edit `plugins/cockroachdb/skills/` by hand.** Skills are synced from the [cockroachdb-skills](https://github.com/cockroachlabs/cockroachdb-skills) submodule by `scripts/sync-skills.sh`. The sync uses `rsync -aL` on purpose: upstream uses symlinks for shared reference files, and symlinks break on Windows clones (`core.symlinks=false` checks them out as text files). Keep the `-L`. - **Skills keep the upstream domain-grouped layout** (unlike the copilot plugin, which flattens). Cross-skill relative links resolve on disk here, so no link rewriting is needed. If you change the layout, re-verify every `../` link still resolves. -- **Hook commands use paths relative to the plugin payload** (`python3 ./scripts/...`), matching Codex conventions. The hook scripts emit both output contracts (top-level `permissionDecision`/`additionalContext` plus `hookSpecificOutput`/`systemMessage`) and are shared verbatim with the copilot plugin; if you change one, change both. Note that Codex runtime support for plugin hooks has version-dependent gaps; the scripts must always fail open (exit 0) so a runtime that does run them can never get stuck. +- **Hooks live in `plugins/cockroachdb/hooks/hooks.json`** (Codex's default location) and their commands are `python3 "${PLUGIN_ROOT}/scripts/