| 4006 | enum { COPILOT_HOOK_TIMEOUT_SEC = 5 }; |
| 4007 | |
| 4008 | static int cbm_build_copilot_hook_command(const char *binary_path, const char *event, |
| 4009 | bool powershell, char *out, size_t out_size) { |
| 4010 | if (!binary_path || !event || !out || |
| 4011 | (strcmp(event, "SessionStart") != 0 && strcmp(event, "SubagentStart") != 0)) { |
| 4012 | return CLI_ERR; |
| 4013 | } |
| 4014 | char quoted[CLI_BUF_8K]; |
| 4015 | int quote_rc = powershell ? cbm_powershell_quote_word(binary_path, quoted, sizeof(quoted)) |
| 4016 | : cbm_shell_quote_word(binary_path, quoted, sizeof(quoted)); |
| 4017 | if (quote_rc != CLI_OK) { |
| 4018 | return CLI_ERR; |
| 4019 | } |
| 4020 | int written = snprintf(out, out_size, |
| 4021 | powershell ? "& %s hook-augment --event %s --dialect copilot" |
| 4022 | : "%s hook-augment --event %s --dialect copilot", |
| 4023 | quoted, event); |
| 4024 | return written > 0 && (size_t)written < out_size ? CLI_OK : CLI_ERR; |
| 4025 | } |
| 4026 | |
| 4027 | static bool cbm_copilot_add_hook_event(yyjson_mut_doc *doc, yyjson_mut_val *hooks, |
| 4028 | const char *event_key, const char *bash_command, |
no test coverage detected