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

Source from the content-addressed store, hash-verified

4888#endif
4889
4890static int cbm_build_current_hook_script(const char *prefix, const char *binary_path, char *script,
4891 size_t script_size) {
4892#ifdef _WIN32
4893 char escaped_binary[CLI_BUF_8K];
4894 if (!prefix || !binary_path || !script ||
4895 cbm_escape_batch_value(binary_path, escaped_binary, sizeof(escaped_binary)) != CLI_OK) {
4896 return CLI_ERR;
4897 }
4898 const char *description = NULL;
4899 if (strcmp(prefix, cmm_gate_script_prefix) == 0) {
4900 description = "PreToolUse search and read coverage adapter";
4901 } else if (strcmp(prefix, cmm_session_script_prefix) == 0) {
4902 description = "SessionStart context adapter";
4903 } else if (strcmp(prefix, cmm_subagent_script_prefix) == 0) {
4904 description = "SubagentStart context adapter";
4905 } else {
4906 return CLI_ERR;
4907 }
4908 int written = snprintf(script, script_size,
4909 "@echo off\r\n"
4910 "setlocal DisableDelayedExpansion\r\n"
4911 "REM %s installed by codebase-memory-mcp.\r\n"
4912 "REM Fail-open: it never blocks or logs hook or prompt content.\r\n"
4913 "set \"BIN=%s\"\r\n"
4914 "if not exist \"%%BIN%%\" exit /b 0\r\n"
4915 "\"%%BIN%%\" hook-augment 2>NUL\r\n"
4916 "exit /b 0\r\n",
4917 description, escaped_binary);
4918#else
4919 char quoted_binary[CLI_BUF_8K];
4920 if (!prefix || !binary_path || !script ||
4921 cbm_shell_quote_word(binary_path, quoted_binary, sizeof(quoted_binary)) != CLI_OK) {
4922 return CLI_ERR;
4923 }
4924 int written =
4925 snprintf(script, script_size, "%s%s%s", prefix, quoted_binary, cmm_hook_script_suffix);
4926#endif
4927 return written > 0 && (size_t)written < script_size ? CLI_OK : CLI_ERR;
4928}
4929
4930static const char cmm_released_session_script[] =
4931 "#!/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