| 3523 | } |
| 3524 | |
| 3525 | static char *cbm_build_copilot_hook_manifest(const char *binary_path) { |
| 3526 | char session_bash[CLI_BUF_8K]; |
| 3527 | char session_powershell[CLI_BUF_8K]; |
| 3528 | char subagent_bash[CLI_BUF_8K]; |
| 3529 | char subagent_powershell[CLI_BUF_8K]; |
| 3530 | if (cbm_build_copilot_hook_command(binary_path, "SessionStart", false, session_bash, |
| 3531 | sizeof(session_bash)) != CLI_OK || |
| 3532 | cbm_build_copilot_hook_command(binary_path, "SessionStart", true, session_powershell, |
| 3533 | sizeof(session_powershell)) != CLI_OK || |
| 3534 | cbm_build_copilot_hook_command(binary_path, "SubagentStart", false, subagent_bash, |
| 3535 | sizeof(subagent_bash)) != CLI_OK || |
| 3536 | cbm_build_copilot_hook_command(binary_path, "SubagentStart", true, subagent_powershell, |
| 3537 | sizeof(subagent_powershell)) != CLI_OK) { |
| 3538 | return NULL; |
| 3539 | } |
| 3540 | |
| 3541 | yyjson_mut_doc *doc = yyjson_mut_doc_new(NULL); |
| 3542 | yyjson_mut_val *root = doc ? yyjson_mut_obj(doc) : NULL; |
| 3543 | yyjson_mut_val *hooks = doc ? yyjson_mut_obj(doc) : NULL; |
| 3544 | if (!doc || !root || !hooks) { |
| 3545 | if (doc) { |
| 3546 | yyjson_mut_doc_free(doc); |
| 3547 | } |
| 3548 | return NULL; |
| 3549 | } |
| 3550 | yyjson_mut_doc_set_root(doc, root); |
| 3551 | bool ok = |
| 3552 | yyjson_mut_obj_add_int(doc, root, "version", 1) && |
| 3553 | cbm_copilot_add_hook_event(doc, hooks, "sessionStart", session_bash, session_powershell) && |
| 3554 | cbm_copilot_add_hook_event(doc, hooks, "subagentStart", subagent_bash, |
| 3555 | subagent_powershell) && |
| 3556 | yyjson_mut_obj_add_val(doc, root, "hooks", hooks); |
| 3557 | char *manifest = ok ? yyjson_mut_write(doc, YYJSON_WRITE_PRETTY, NULL) : NULL; |
| 3558 | yyjson_mut_doc_free(doc); |
| 3559 | return manifest; |
| 3560 | } |
| 3561 | |
| 3562 | /* Copilot loads every manifest in $COPILOT_HOME/hooks. Treat our dedicated |
| 3563 | * filename as an exact-owned document: a foreign collision fails closed, and |
no test coverage detected