| 3726 | } |
| 3727 | |
| 3728 | static char *cbm_build_copilot_hook_manifest(const char *binary_path) { |
| 3729 | char session_bash[CLI_BUF_8K]; |
| 3730 | char session_powershell[CLI_BUF_8K]; |
| 3731 | char subagent_bash[CLI_BUF_8K]; |
| 3732 | char subagent_powershell[CLI_BUF_8K]; |
| 3733 | if (cbm_build_copilot_hook_command(binary_path, "SessionStart", false, session_bash, |
| 3734 | sizeof(session_bash)) != CLI_OK || |
| 3735 | cbm_build_copilot_hook_command(binary_path, "SessionStart", true, session_powershell, |
| 3736 | sizeof(session_powershell)) != CLI_OK || |
| 3737 | cbm_build_copilot_hook_command(binary_path, "SubagentStart", false, subagent_bash, |
| 3738 | sizeof(subagent_bash)) != CLI_OK || |
| 3739 | cbm_build_copilot_hook_command(binary_path, "SubagentStart", true, subagent_powershell, |
| 3740 | sizeof(subagent_powershell)) != CLI_OK) { |
| 3741 | return NULL; |
| 3742 | } |
| 3743 | |
| 3744 | yyjson_mut_doc *doc = yyjson_mut_doc_new(NULL); |
| 3745 | yyjson_mut_val *root = doc ? yyjson_mut_obj(doc) : NULL; |
| 3746 | yyjson_mut_val *hooks = doc ? yyjson_mut_obj(doc) : NULL; |
| 3747 | if (!doc || !root || !hooks) { |
| 3748 | if (doc) { |
| 3749 | yyjson_mut_doc_free(doc); |
| 3750 | } |
| 3751 | return NULL; |
| 3752 | } |
| 3753 | yyjson_mut_doc_set_root(doc, root); |
| 3754 | bool ok = |
| 3755 | yyjson_mut_obj_add_int(doc, root, "version", 1) && |
| 3756 | cbm_copilot_add_hook_event(doc, hooks, "sessionStart", session_bash, session_powershell) && |
| 3757 | cbm_copilot_add_hook_event(doc, hooks, "subagentStart", subagent_bash, |
| 3758 | subagent_powershell) && |
| 3759 | yyjson_mut_obj_add_val(doc, root, "hooks", hooks); |
| 3760 | char *manifest = ok ? yyjson_mut_write(doc, YYJSON_WRITE_PRETTY, NULL) : NULL; |
| 3761 | yyjson_mut_doc_free(doc); |
| 3762 | return manifest; |
| 3763 | } |
| 3764 | |
| 3765 | /* Copilot loads every manifest in $COPILOT_HOME/hooks. Treat our dedicated |
| 3766 | * filename as an exact-owned document: a foreign collision fails closed, and |
no test coverage detected