Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.
C aiderastclaude-codecode-analysiscode-intelligencecodexcursorcypherdeveloper-toolsgemini-cligraph-visualizationkilocodeknowledge-graphmcpmcp-servermodel-context-protocolopencodesqlitetree-sitterwindsurf
Merge pull request #1337 from abendrothj/bash-tool-hook-augment
Martin Vogeld706c33ac2f9
diff --cc src/cli/cli.cindex 63b3e50a3,6a8515c3b..56af212d1--- a/src/cli/cli.c+++ b/src/cli/cli.c@@@ -4092,58 -3817,11 +4092,58 @@@ static int cbm_remove_vibe_mcp_owned(co"codebase-memory-mcp", body);}+/* ── Grok Build MCP config (TOML) ────────────────────────────── */++#define GROK_CMM_TABLE "mcp_servers.codebase-memory-mcp"+#define GROK_CMM_SECTION "[" GROK_CMM_TABLE "]"+#define GROK_MCP_BEGIN "# >>> codebase-memory-mcp MCP >>>"+#define GROK_MCP_END "# <<< codebase-memory-mcp MCP <<<"++/* A pre-marker table with the known owned shape (what `grok mcp add` writes+ * for this binary) is adopted; any other same-name table is foreign and left+ * byte-identical, because a second [mcp_servers.codebase-memory-mcp] header+ * would make Grok reject the whole config.toml. */+static int cbm_remove_grok_legacy_mcp(const char *config_path) {+ return cbm_toml_remove_legacy_table(config_path, GROK_CMM_TABLE, GROK_MCP_BEGIN, GROK_MCP_END);+}++static int cbm_upsert_grok_mcp(const char *binary_path, const char *config_path) {+ if (!binary_path || !config_path) {+ return CLI_ERR;+ }+ char escaped[CLI_BUF_8K];+ if (cbm_toml_escape_basic_string(binary_path, escaped, sizeof(escaped)) != 0) {+ return CLI_ERR;+ }+ /* Grok spawns stdio servers with the full parent environment (verified+ * against grok 1.0.5), so unlike Codex (#1562) nothing has to be+ * forwarded: CBM_CACHE_DIR and CBM_RUNTIME_DIR reach the server as-is. */+ char block[CLI_BUF_8K];+ int written =+ snprintf(block, sizeof(block), GROK_CMM_SECTION "\ncommand = \"%s\"\nargs = []\n", escaped);+ if (written < 0 || (size_t)written >= sizeof(block) ||+ cbm_remove_grok_legacy_mcp(config_path) != 0) {+ return CLI_ERR;+ }+ return cbm_toml_upsert_managed_block(config_path, GROK_MCP_BEGIN, GROK_MCP_END, block) == 0+ ? CLI_OK+ : CLI_ERR;+}++static int cbm_remove_grok_mcp_owned(const char *binary_path, const char *config_path) {+ (void)binary_path;+ if (!config_path ||+ cbm_toml_remove_managed_block(config_path, GROK_MCP_BEGIN, GROK_MCP_END) != 0) {+ return CLI_ERR;+ }+ return cbm_remove_grok_legacy_mcp(config_path) >= 0 ? CLI_OK : CLI_ERR;+}+/* ── Claude Code pre-tool hooks ───────────────────────────────── */- /* Search augmentation runs before Grep/Glob; exact coverage context runs after+ /* Search augmentation runs before Grep/Glob/Bash; exact coverage context runs after* Read. Both adapters are context-only and fail open. */- #define CMM_HOOK_SEARCH_MATCHER "Grep|Glob"+ #define CMM_HOOK_SEARCH_MATCHER "Grep|Glob|Bash"#define CMM_HOOK_READ_MATCHER "Read"/* Basename only; the full command path is resolved at install time via* cbm_resolve_hook_command so $CLAUDE_CONFIG_DIR is honored. */diff --cc src/cli/cli.hindex 0493ef5ca,622303dd6..da2c4512a--- a/src/cli/cli.h+++ b/src/cli/cli.h@@@ -524,21 -477,11 +525,25 @@@ char *cbm_hook_augment_lifecycle_json_f* hard fail-open deadline without constructing a local MCP/store instance. */void cbm_hook_augment_arm_deadline(void);char *cbm_hook_augment_read_stdin(void);+ /* Pure no-op gate for the hook-client fast path (see hook_augment.c). */+ bool cbm_hook_augment_input_is_noop_bash(const char *input);+ /* Hand back stdin bytes main() consumed early; the next read returns them. */+ void cbm_hook_augment_prefetch_stdin(char *owned);+/* Why a hook client is not augmenting. The hook caller only ever sees stdout,+ * so each reason that is actionable by the user must have a stdout notice+ * (#1388: a build-conflicted daemon used to report on stderr alone, which is+ * invisible in-session and reads as silent skips). */+typedef enum {+ CBM_HOOK_ADMISSION_DAEMON_ABSENT = 0, /* no daemon running: `daemon start` heals it */+ CBM_HOOK_ADMISSION_BUILD_CONFLICT /* daemon runs another build: needs `daemon stop` */+} cbm_hook_admission_t;++/* The JSON systemMessage a hook client must print on stdout for `reason`, or+ * NULL when nothing should be printed. hook_dialect NULL = Claude Code, the+ * only dialect that surfaces a stdout systemMessage to the user. */+const char *cbm_hook_admission_notice(cbm_hook_admission_t reason, const char *hook_dialect);+/* Process one already-read hook payload using a caller-owned MCP session.* Returns a malloc-owned hook output JSON string, or NULL for fail-open/no* augmentation. This is the daemon entry; it never arms a process-globaldiff --cc tests/test_cli.cindex fafdfd20e,6ab6e44b2..a72ed6474--- a/tests/test_cli.c+++ b/tests/test_cli.c@@@ -13793,10 -12079,9 +13897,12 @@@ SUITE(cli)RUN_TEST(cli_claude_hook_scripts_shell_quote_binary_path);RUN_TEST(cli_claude_hook_commands_shell_quote_custom_config_dir);RUN_TEST(cli_codex_migrates_to_single_hook_representation);+#ifndef _WIN32+ RUN_TEST(cli_codex_preflight_reports_heading_and_reason);+#endifRUN_TEST(cli_hook_augment_context_tracks_search_json_shape);+ RUN_TEST(cli_hook_augment_bash_pretooluse_reaches_augmenter);+ RUN_TEST(cli_hook_augment_bash_pattern_extractor);RUN_TEST(cli_hook_augment_lifecycle_output_contract);RUN_TEST(cli_hook_augment_subagent_tier_router_contract);RUN_TEST(cli_hook_augment_subagent_no_project_guidance_is_read_only);