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

Source from the content-addressed store, hash-verified

5704#endif
5705
5706static int cbm_build_current_hook_script(const char *prefix, const char *binary_path, char *script,
5707 size_t script_size) {
5708#ifdef _WIN32
5709 char escaped_binary[CLI_BUF_8K];
5710 if (!prefix || !binary_path || !script ||
5711 cbm_escape_batch_value(binary_path, escaped_binary, sizeof(escaped_binary)) != CLI_OK) {
5712 return CLI_ERR;
5713 }
5714 const char *description = NULL;
5715 if (strcmp(prefix, cmm_gate_script_prefix) == 0) {
5716 description = "PreToolUse search and read coverage adapter";
5717 } else if (strcmp(prefix, cmm_session_script_prefix) == 0) {
5718 description = "SessionStart context adapter";
5719 } else if (strcmp(prefix, cmm_subagent_script_prefix) == 0) {
5720 description = "SubagentStart context adapter";
5721 } else {
5722 return CLI_ERR;
5723 }
5724 int written = snprintf(script, script_size,
5725 "@echo off\r\n"
5726 "setlocal DisableDelayedExpansion\r\n"
5727 "REM %s installed by codebase-memory-mcp.\r\n"
5728 "REM Fail-open: it never blocks or logs hook or prompt content.\r\n"
5729 "set \"BIN=%s\"\r\n"
5730 "if not exist \"%%BIN%%\" exit /b 0\r\n"
5731 "\"%%BIN%%\" hook-augment 2>NUL\r\n"
5732 "exit /b 0\r\n",
5733 description, escaped_binary);
5734#else
5735 char quoted_binary[CLI_BUF_8K];
5736 if (!prefix || !binary_path || !script ||
5737 cbm_shell_quote_word(binary_path, quoted_binary, sizeof(quoted_binary)) != CLI_OK) {
5738 return CLI_ERR;
5739 }
5740 int written =
5741 snprintf(script, script_size, "%s%s%s", prefix, quoted_binary, cmm_hook_script_suffix);
5742#endif
5743 return written > 0 && (size_t)written < script_size ? CLI_OK : CLI_ERR;
5744}
5745
5746static const char cmm_released_session_script[] =
5747 "#!/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