MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / cbm_install_hook_gate_script

Function cbm_install_hook_gate_script

src/cli/cli.c:5093–5136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5091#endif
5092
5093bool cbm_install_hook_gate_script(const char *home, const char *binary_path) {
5094 if (!home || !binary_path) {
5095 return false;
5096 }
5097 char config_dir[CLI_BUF_1K];
5098 cbm_claude_config_dir(home, config_dir, sizeof(config_dir));
5099 if (!config_dir[0]) {
5100 return false;
5101 }
5102 char hooks_dir[CLI_BUF_1K];
5103 int hooks_written = snprintf(hooks_dir, sizeof(hooks_dir), "%s/hooks", config_dir);
5104 if (hooks_written <= 0 || (size_t)hooks_written >= sizeof(hooks_dir)) {
5105 return false;
5106 }
5107 if (!cbm_mkdir_p(hooks_dir, CLI_OCTAL_PERM)) {
5108 return false;
5109 }
5110
5111 char script_path[CLI_BUF_1K];
5112 int script_written =
5113 snprintf(script_path, sizeof(script_path), "%s/" CMM_HOOK_GATE_SCRIPT, hooks_dir);
5114 if (script_written <= 0 || (size_t)script_written >= sizeof(script_path)) {
5115 return false;
5116 }
5117
5118 char script[CLI_BUF_8K];
5119 if (cbm_build_current_hook_script(cmm_gate_script_prefix, binary_path, script,
5120 sizeof(script)) != CLI_OK) {
5121 return false;
5122 }
5123 char released_script[CLI_BUF_8K];
5124 const char *const legacy[] = {released_script};
5125 size_t legacy_count = cbm_build_released_gate_script(binary_path, released_script,
5126 sizeof(released_script)) == CLI_OK
5127 ? 1U
5128 : 0U;
5129#ifdef _WIN32
5130 if (cbm_remove_owned_legacy_hook_script(hooks_dir, CMM_HOOK_GATE_SCRIPT_LEGACY, script, legacy,
5131 legacy_count) != CLI_OK) {
5132 return false;
5133 }
5134#endif
5135 return cbm_write_owned_hook_script_with_legacy(script_path, script, legacy, legacy_count);
5136}
5137
5138/* SessionStart hook: remind agent to use MCP tools on every context reset. */
5139#ifdef _WIN32

Callers 3

test_cli.cFile · 0.85
repro_issue409.cFile · 0.85

Tested by

no test coverage detected