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

Function cbm_install_subagent_reminder_script

src/cli/cli.c:5483–5521  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5481#define CMM_SUBAGENT_REMINDER_SCRIPT_LEGACY "cbm-subagent-reminder"
5482
5483static bool cbm_install_subagent_reminder_script(const char *home, const char *binary_path) {
5484 if (!home || !binary_path) {
5485 return false;
5486 }
5487 char config_dir[CLI_BUF_1K];
5488 cbm_claude_config_dir(home, config_dir, sizeof(config_dir));
5489 if (!config_dir[0]) {
5490 return false;
5491 }
5492 char hooks_dir[CLI_BUF_1K];
5493 int hooks_written = snprintf(hooks_dir, sizeof(hooks_dir), "%s/hooks", config_dir);
5494 if (hooks_written <= 0 || (size_t)hooks_written >= sizeof(hooks_dir)) {
5495 return false;
5496 }
5497 if (!cbm_mkdir_p(hooks_dir, CLI_OCTAL_PERM)) {
5498 return false;
5499 }
5500
5501 char script_path[CLI_BUF_1K];
5502 int script_written =
5503 snprintf(script_path, sizeof(script_path), "%s/" CMM_SUBAGENT_REMINDER_SCRIPT, hooks_dir);
5504 if (script_written <= 0 || (size_t)script_written >= sizeof(script_path)) {
5505 return false;
5506 }
5507
5508 char script[CLI_BUF_8K];
5509 if (cbm_build_current_hook_script(cmm_subagent_script_prefix, binary_path, script,
5510 sizeof(script)) != CLI_OK) {
5511 return false;
5512 }
5513 const char *const legacy[] = {cmm_released_subagent_script};
5514#ifdef _WIN32
5515 if (cbm_remove_owned_legacy_hook_script(hooks_dir, CMM_SUBAGENT_REMINDER_SCRIPT_LEGACY, script,
5516 legacy, 1U) != CLI_OK) {
5517 return false;
5518 }
5519#endif
5520 return cbm_write_owned_hook_script_with_legacy(script_path, script, legacy, 1U);
5521}
5522
5523/* #1387 dry-run predicate: would writing this hook script succeed, or would
5524 * the owned-document migration refuse it because the file on disk is not ours?

Callers 1

Tested by

no test coverage detected