MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / cbm_build_current_hook_script

Function cbm_build_current_hook_script

src/cli/cli.c:4946–4984  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4944#endif
4945
4946static int cbm_build_current_hook_script(const char *prefix, const char *binary_path, char *script,
4947 size_t script_size) {
4948#ifdef _WIN32
4949 char escaped_binary[CLI_BUF_8K];
4950 if (!prefix || !binary_path || !script ||
4951 cbm_escape_batch_value(binary_path, escaped_binary, sizeof(escaped_binary)) != CLI_OK) {
4952 return CLI_ERR;
4953 }
4954 const char *description = NULL;
4955 if (strcmp(prefix, cmm_gate_script_prefix) == 0) {
4956 description = "PreToolUse search and read coverage adapter";
4957 } else if (strcmp(prefix, cmm_session_script_prefix) == 0) {
4958 description = "SessionStart context adapter";
4959 } else if (strcmp(prefix, cmm_subagent_script_prefix) == 0) {
4960 description = "SubagentStart context adapter";
4961 } else {
4962 return CLI_ERR;
4963 }
4964 int written = snprintf(script, script_size,
4965 "@echo off\r\n"
4966 "setlocal DisableDelayedExpansion\r\n"
4967 "REM %s installed by codebase-memory-mcp.\r\n"
4968 "REM Fail-open: it never blocks or logs hook or prompt content.\r\n"
4969 "set \"BIN=%s\"\r\n"
4970 "if not exist \"%%BIN%%\" exit /b 0\r\n"
4971 "\"%%BIN%%\" hook-augment 2>NUL\r\n"
4972 "exit /b 0\r\n",
4973 description, escaped_binary);
4974#else
4975 char quoted_binary[CLI_BUF_8K];
4976 if (!prefix || !binary_path || !script ||
4977 cbm_shell_quote_word(binary_path, quoted_binary, sizeof(quoted_binary)) != CLI_OK) {
4978 return CLI_ERR;
4979 }
4980 int written =
4981 snprintf(script, script_size, "%s%s%s", prefix, quoted_binary, cmm_hook_script_suffix);
4982#endif
4983 return written > 0 && (size_t)written < script_size ? CLI_OK : CLI_ERR;
4984}
4985
4986static const char cmm_released_session_script[] =
4987 "#!/usr/bin/env bash\n"

Calls 2

cbm_escape_batch_valueFunction · 0.85
cbm_shell_quote_wordFunction · 0.85

Tested by

no test coverage detected