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

Source from the content-addressed store, hash-verified

5338#define CMM_SUBAGENT_REMINDER_SCRIPT_LEGACY "cbm-subagent-reminder"
5339
5340static bool cbm_install_subagent_reminder_script(const char *home, const char *binary_path) {
5341 if (!home || !binary_path) {
5342 return false;
5343 }
5344 char config_dir[CLI_BUF_1K];
5345 cbm_claude_config_dir(home, config_dir, sizeof(config_dir));
5346 if (!config_dir[0]) {
5347 return false;
5348 }
5349 char hooks_dir[CLI_BUF_1K];
5350 int hooks_written = snprintf(hooks_dir, sizeof(hooks_dir), "%s/hooks", config_dir);
5351 if (hooks_written <= 0 || (size_t)hooks_written >= sizeof(hooks_dir)) {
5352 return false;
5353 }
5354 if (!cbm_mkdir_p(hooks_dir, CLI_OCTAL_PERM)) {
5355 return false;
5356 }
5357
5358 char script_path[CLI_BUF_1K];
5359 int script_written =
5360 snprintf(script_path, sizeof(script_path), "%s/" CMM_SUBAGENT_REMINDER_SCRIPT, hooks_dir);
5361 if (script_written <= 0 || (size_t)script_written >= sizeof(script_path)) {
5362 return false;
5363 }
5364
5365 char script[CLI_BUF_8K];
5366 if (cbm_build_current_hook_script(cmm_subagent_script_prefix, binary_path, script,
5367 sizeof(script)) != CLI_OK) {
5368 return false;
5369 }
5370 const char *const legacy[] = {cmm_released_subagent_script};
5371#ifdef _WIN32
5372 if (cbm_remove_owned_legacy_hook_script(hooks_dir, CMM_SUBAGENT_REMINDER_SCRIPT_LEGACY, script,
5373 legacy, 1U) != CLI_OK) {
5374 return false;
5375 }
5376#endif
5377 return cbm_write_owned_hook_script_with_legacy(script_path, script, legacy, 1U);
5378}
5379
5380/* #1387 dry-run predicate: would writing this hook script succeed, or would
5381 * the owned-document migration refuse it because the file on disk is not ours?

Callers 1

Tested by

no test coverage detected