| 4458 | } |
| 4459 | |
| 4460 | static int cbm_upsert_qoder_context_hook(const char *settings_path, const char *binary_path) { |
| 4461 | char command[CLI_BUF_8K]; |
| 4462 | char shell[CLI_BUF_32]; |
| 4463 | if (cbm_build_qoder_hook_command(binary_path, cbm_current_platform_is_windows(), command, |
| 4464 | sizeof(command), shell, sizeof(shell)) != CLI_OK) { |
| 4465 | return CLI_ERR; |
| 4466 | } |
| 4467 | int legacy_result = remove_hooks_json((hooks_remove_args_t){ |
| 4468 | .settings_path = settings_path, |
| 4469 | .hook_event = "UserPromptSubmit", |
| 4470 | .match_command_exact = command, |
| 4471 | }); |
| 4472 | int session_result = upsert_hooks_json((hooks_upsert_args_t){ |
| 4473 | .settings_path = settings_path, |
| 4474 | .hook_event = "SessionStart", |
| 4475 | .matcher_str = "startup|resume|clear|compact|new", |
| 4476 | .command_str = command, |
| 4477 | .shell = shell[0] ? shell : NULL, |
| 4478 | .timeout_value = CMM_HOOK_TIMEOUT_SEC, |
| 4479 | .match_command_exact = command, |
| 4480 | }); |
| 4481 | int subagent_result = upsert_hooks_json((hooks_upsert_args_t){ |
| 4482 | .settings_path = settings_path, |
| 4483 | .hook_event = "SubagentStart", |
| 4484 | .matcher_str = "*", |
| 4485 | .command_str = command, |
| 4486 | .shell = shell[0] ? shell : NULL, |
| 4487 | .timeout_value = CMM_HOOK_TIMEOUT_SEC, |
| 4488 | .match_command_exact = command, |
| 4489 | }); |
| 4490 | int read_result = upsert_hooks_json((hooks_upsert_args_t){ |
| 4491 | .settings_path = settings_path, |
| 4492 | .hook_event = "PostToolUse", |
| 4493 | .matcher_str = "Read", |
| 4494 | .command_str = command, |
| 4495 | .shell = shell[0] ? shell : NULL, |
| 4496 | .timeout_value = CMM_HOOK_TIMEOUT_SEC, |
| 4497 | .match_command_exact = command, |
| 4498 | }); |
| 4499 | return legacy_result == CLI_OK && session_result == CLI_OK && subagent_result == CLI_OK && |
| 4500 | read_result == CLI_OK |
| 4501 | ? CLI_OK |
| 4502 | : CLI_ERR; |
| 4503 | } |
| 4504 | |
| 4505 | static int cbm_remove_qoder_context_hook(const char *settings_path, const char *binary_path) { |
| 4506 | char command[CLI_BUF_8K]; |
no test coverage detected