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

Source from the content-addressed store, hash-verified

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