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

Source from the content-addressed store, hash-verified

4965#endif
4966
4967static int cbm_build_current_hook_script(const char *prefix, const char *binary_path, char *script,
4968 size_t script_size) {
4969#ifdef _WIN32
4970 char escaped_binary[CLI_BUF_8K];
4971 if (!prefix || !binary_path || !script ||
4972 cbm_escape_batch_value(binary_path, escaped_binary, sizeof(escaped_binary)) != CLI_OK) {
4973 return CLI_ERR;
4974 }
4975 const char *description = NULL;
4976 if (strcmp(prefix, cmm_gate_script_prefix) == 0) {
4977 description = "PreToolUse search and read coverage adapter";
4978 } else if (strcmp(prefix, cmm_session_script_prefix) == 0) {
4979 description = "SessionStart context adapter";
4980 } else if (strcmp(prefix, cmm_subagent_script_prefix) == 0) {
4981 description = "SubagentStart context adapter";
4982 } else {
4983 return CLI_ERR;
4984 }
4985 int written = snprintf(script, script_size,
4986 "@echo off\r\n"
4987 "setlocal DisableDelayedExpansion\r\n"
4988 "REM %s installed by codebase-memory-mcp.\r\n"
4989 "REM Fail-open: it never blocks or logs hook or prompt content.\r\n"
4990 "set \"BIN=%s\"\r\n"
4991 "if not exist \"%%BIN%%\" exit /b 0\r\n"
4992 "\"%%BIN%%\" hook-augment 2>NUL\r\n"
4993 "exit /b 0\r\n",
4994 description, escaped_binary);
4995#else
4996 char quoted_binary[CLI_BUF_8K];
4997 if (!prefix || !binary_path || !script ||
4998 cbm_shell_quote_word(binary_path, quoted_binary, sizeof(quoted_binary)) != CLI_OK) {
4999 return CLI_ERR;
5000 }
5001 int written =
5002 snprintf(script, script_size, "%s%s%s", prefix, quoted_binary, cmm_hook_script_suffix);
5003#endif
5004 return written > 0 && (size_t)written < script_size ? CLI_OK : CLI_ERR;
5005}
5006
5007static const char cmm_released_session_script[] =
5008 "#!/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