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:5110–5148  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5108#endif
5109
5110static int cbm_build_current_hook_script(const char *prefix, const char *binary_path, char *script,
5111 size_t script_size) {
5112#ifdef _WIN32
5113 char escaped_binary[CLI_BUF_8K];
5114 if (!prefix || !binary_path || !script ||
5115 cbm_escape_batch_value(binary_path, escaped_binary, sizeof(escaped_binary)) != CLI_OK) {
5116 return CLI_ERR;
5117 }
5118 const char *description = NULL;
5119 if (strcmp(prefix, cmm_gate_script_prefix) == 0) {
5120 description = "PreToolUse search and read coverage adapter";
5121 } else if (strcmp(prefix, cmm_session_script_prefix) == 0) {
5122 description = "SessionStart context adapter";
5123 } else if (strcmp(prefix, cmm_subagent_script_prefix) == 0) {
5124 description = "SubagentStart context adapter";
5125 } else {
5126 return CLI_ERR;
5127 }
5128 int written = snprintf(script, script_size,
5129 "@echo off\r\n"
5130 "setlocal DisableDelayedExpansion\r\n"
5131 "REM %s installed by codebase-memory-mcp.\r\n"
5132 "REM Fail-open: it never blocks or logs hook or prompt content.\r\n"
5133 "set \"BIN=%s\"\r\n"
5134 "if not exist \"%%BIN%%\" exit /b 0\r\n"
5135 "\"%%BIN%%\" hook-augment 2>NUL\r\n"
5136 "exit /b 0\r\n",
5137 description, escaped_binary);
5138#else
5139 char quoted_binary[CLI_BUF_8K];
5140 if (!prefix || !binary_path || !script ||
5141 cbm_shell_quote_word(binary_path, quoted_binary, sizeof(quoted_binary)) != CLI_OK) {
5142 return CLI_ERR;
5143 }
5144 int written =
5145 snprintf(script, script_size, "%s%s%s", prefix, quoted_binary, cmm_hook_script_suffix);
5146#endif
5147 return written > 0 && (size_t)written < script_size ? CLI_OK : CLI_ERR;
5148}
5149
5150static const char cmm_released_session_script[] =
5151 "#!/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