| 6118 | #define CMM_SUBAGENT_REMINDER_SCRIPT_LEGACY "cbm-subagent-reminder" |
| 6119 | |
| 6120 | static bool cbm_install_subagent_reminder_script(const char *home, const char *binary_path) { |
| 6121 | if (!home || !binary_path) { |
| 6122 | return false; |
| 6123 | } |
| 6124 | char config_dir[CLI_BUF_1K]; |
| 6125 | cbm_claude_config_dir(home, config_dir, sizeof(config_dir)); |
| 6126 | if (!config_dir[0]) { |
| 6127 | return false; |
| 6128 | } |
| 6129 | char hooks_dir[CLI_BUF_1K]; |
| 6130 | int hooks_written = snprintf(hooks_dir, sizeof(hooks_dir), "%s/hooks", config_dir); |
| 6131 | if (hooks_written <= 0 || (size_t)hooks_written >= sizeof(hooks_dir)) { |
| 6132 | return false; |
| 6133 | } |
| 6134 | if (!cbm_mkdir_p_ex(hooks_dir, CLI_OCTAL_PERM, CBM_MKDIR_FOLLOW_OWNED)) { |
| 6135 | return false; |
| 6136 | } |
| 6137 | |
| 6138 | char script_path[CLI_BUF_1K]; |
| 6139 | int script_written = |
| 6140 | snprintf(script_path, sizeof(script_path), "%s/" CMM_SUBAGENT_REMINDER_SCRIPT, hooks_dir); |
| 6141 | if (script_written <= 0 || (size_t)script_written >= sizeof(script_path)) { |
| 6142 | return false; |
| 6143 | } |
| 6144 | |
| 6145 | char script[CLI_BUF_8K]; |
| 6146 | if (cbm_build_current_hook_script(cmm_subagent_script_prefix, binary_path, script, |
| 6147 | sizeof(script)) != CLI_OK) { |
| 6148 | return false; |
| 6149 | } |
| 6150 | const char *const legacy[] = {cmm_released_subagent_script}; |
| 6151 | #ifdef _WIN32 |
| 6152 | if (cbm_remove_owned_legacy_hook_script(hooks_dir, CMM_SUBAGENT_REMINDER_SCRIPT_LEGACY, script, |
| 6153 | legacy, 1U) != CLI_OK) { |
| 6154 | return false; |
| 6155 | } |
| 6156 | #endif |
| 6157 | return cbm_write_owned_hook_script_with_legacy(script_path, script, legacy, 1U); |
| 6158 | } |
| 6159 | |
| 6160 | /* #1387 dry-run predicate: would writing this hook script succeed, or would |
| 6161 | * the owned-document migration refuse it because the file on disk is not ours? |
no test coverage detected