| 4238 | } |
| 4239 | |
| 4240 | static int cbm_upsert_qoder_context_hook(const char *settings_path, const char *binary_path) { |
| 4241 | char command[CLI_BUF_8K]; |
| 4242 | char shell[CLI_BUF_32]; |
| 4243 | if (cbm_build_qoder_hook_command(binary_path, cbm_current_platform_is_windows(), command, |
| 4244 | sizeof(command), shell, sizeof(shell)) != CLI_OK) { |
| 4245 | return CLI_ERR; |
| 4246 | } |
| 4247 | int legacy_result = remove_hooks_json((hooks_remove_args_t){ |
| 4248 | .settings_path = settings_path, |
| 4249 | .hook_event = "UserPromptSubmit", |
| 4250 | .match_command_exact = command, |
| 4251 | }); |
| 4252 | int session_result = upsert_hooks_json((hooks_upsert_args_t){ |
| 4253 | .settings_path = settings_path, |
| 4254 | .hook_event = "SessionStart", |
| 4255 | .matcher_str = "startup|resume|clear|compact|new", |
| 4256 | .command_str = command, |
| 4257 | .shell = shell[0] ? shell : NULL, |
| 4258 | .timeout_value = CMM_HOOK_TIMEOUT_SEC, |
| 4259 | .match_command_exact = command, |
| 4260 | }); |
| 4261 | int subagent_result = upsert_hooks_json((hooks_upsert_args_t){ |
| 4262 | .settings_path = settings_path, |
| 4263 | .hook_event = "SubagentStart", |
| 4264 | .matcher_str = "*", |
| 4265 | .command_str = command, |
| 4266 | .shell = shell[0] ? shell : NULL, |
| 4267 | .timeout_value = CMM_HOOK_TIMEOUT_SEC, |
| 4268 | .match_command_exact = command, |
| 4269 | }); |
| 4270 | int read_result = upsert_hooks_json((hooks_upsert_args_t){ |
| 4271 | .settings_path = settings_path, |
| 4272 | .hook_event = "PostToolUse", |
| 4273 | .matcher_str = "Read", |
| 4274 | .command_str = command, |
| 4275 | .shell = shell[0] ? shell : NULL, |
| 4276 | .timeout_value = CMM_HOOK_TIMEOUT_SEC, |
| 4277 | .match_command_exact = command, |
| 4278 | }); |
| 4279 | return legacy_result == CLI_OK && session_result == CLI_OK && subagent_result == CLI_OK && |
| 4280 | read_result == CLI_OK |
| 4281 | ? CLI_OK |
| 4282 | : CLI_ERR; |
| 4283 | } |
| 4284 | |
| 4285 | static int cbm_remove_qoder_context_hook(const char *settings_path, const char *binary_path) { |
| 4286 | char command[CLI_BUF_8K]; |
no test coverage detected