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

Source from the content-addressed store, hash-verified

5014#endif
5015
5016bool cbm_install_hook_gate_script(const char *home, const char *binary_path) {
5017 if (!home || !binary_path) {
5018 return false;
5019 }
5020 char config_dir[CLI_BUF_1K];
5021 cbm_claude_config_dir(home, config_dir, sizeof(config_dir));
5022 if (!config_dir[0]) {
5023 return false;
5024 }
5025 char hooks_dir[CLI_BUF_1K];
5026 int hooks_written = snprintf(hooks_dir, sizeof(hooks_dir), "%s/hooks", config_dir);
5027 if (hooks_written <= 0 || (size_t)hooks_written >= sizeof(hooks_dir)) {
5028 return false;
5029 }
5030 if (!cbm_mkdir_p(hooks_dir, CLI_OCTAL_PERM)) {
5031 return false;
5032 }
5033
5034 char script_path[CLI_BUF_1K];
5035 int script_written =
5036 snprintf(script_path, sizeof(script_path), "%s/" CMM_HOOK_GATE_SCRIPT, hooks_dir);
5037 if (script_written <= 0 || (size_t)script_written >= sizeof(script_path)) {
5038 return false;
5039 }
5040
5041 char script[CLI_BUF_8K];
5042 if (cbm_build_current_hook_script(cmm_gate_script_prefix, binary_path, script,
5043 sizeof(script)) != CLI_OK) {
5044 return false;
5045 }
5046 char released_script[CLI_BUF_8K];
5047 const char *const legacy[] = {released_script};
5048 size_t legacy_count = cbm_build_released_gate_script(binary_path, released_script,
5049 sizeof(released_script)) == CLI_OK
5050 ? 1U
5051 : 0U;
5052#ifdef _WIN32
5053 if (cbm_remove_owned_legacy_hook_script(hooks_dir, CMM_HOOK_GATE_SCRIPT_LEGACY, script, legacy,
5054 legacy_count) != CLI_OK) {
5055 return false;
5056 }
5057#endif
5058 return cbm_write_owned_hook_script_with_legacy(script_path, script, legacy, legacy_count);
5059}
5060
5061/* SessionStart hook: remind agent to use MCP tools on every context reset. */
5062#ifdef _WIN32

Callers 3

test_cli.cFile · 0.85
repro_issue409.cFile · 0.85

Tested by

no test coverage detected