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

Source from the content-addressed store, hash-verified

5234#endif
5235
5236bool cbm_install_hook_gate_script(const char *home, const char *binary_path) {
5237 if (!home || !binary_path) {
5238 return false;
5239 }
5240 char config_dir[CLI_BUF_1K];
5241 cbm_claude_config_dir(home, config_dir, sizeof(config_dir));
5242 if (!config_dir[0]) {
5243 return false;
5244 }
5245 char hooks_dir[CLI_BUF_1K];
5246 int hooks_written = snprintf(hooks_dir, sizeof(hooks_dir), "%s/hooks", config_dir);
5247 if (hooks_written <= 0 || (size_t)hooks_written >= sizeof(hooks_dir)) {
5248 return false;
5249 }
5250 if (!cbm_mkdir_p(hooks_dir, CLI_OCTAL_PERM)) {
5251 return false;
5252 }
5253
5254 char script_path[CLI_BUF_1K];
5255 int script_written =
5256 snprintf(script_path, sizeof(script_path), "%s/" CMM_HOOK_GATE_SCRIPT, hooks_dir);
5257 if (script_written <= 0 || (size_t)script_written >= sizeof(script_path)) {
5258 return false;
5259 }
5260
5261 char script[CLI_BUF_8K];
5262 if (cbm_build_current_hook_script(cmm_gate_script_prefix, binary_path, script,
5263 sizeof(script)) != CLI_OK) {
5264 return false;
5265 }
5266 char released_script[CLI_BUF_8K];
5267 const char *const legacy[] = {released_script};
5268 size_t legacy_count = cbm_build_released_gate_script(binary_path, released_script,
5269 sizeof(released_script)) == CLI_OK
5270 ? 1U
5271 : 0U;
5272#ifdef _WIN32
5273 if (cbm_remove_owned_legacy_hook_script(hooks_dir, CMM_HOOK_GATE_SCRIPT_LEGACY, script, legacy,
5274 legacy_count) != CLI_OK) {
5275 return false;
5276 }
5277#endif
5278 return cbm_write_owned_hook_script_with_legacy(script_path, script, legacy, legacy_count);
5279}
5280
5281/* SessionStart hook: remind agent to use MCP tools on every context reset. */
5282#ifdef _WIN32

Callers 3

test_cli.cFile · 0.85
repro_issue409.cFile · 0.85

Tested by

no test coverage detected