| 4171 | } |
| 4172 | |
| 4173 | static char *cbm_build_copilot_hook_manifest(const char *binary_path) { |
| 4174 | char session_bash[CLI_BUF_8K]; |
| 4175 | char session_powershell[CLI_BUF_8K]; |
| 4176 | char subagent_bash[CLI_BUF_8K]; |
| 4177 | char subagent_powershell[CLI_BUF_8K]; |
| 4178 | if (cbm_build_copilot_hook_command(binary_path, "SessionStart", false, session_bash, |
| 4179 | sizeof(session_bash)) != CLI_OK || |
| 4180 | cbm_build_copilot_hook_command(binary_path, "SessionStart", true, session_powershell, |
| 4181 | sizeof(session_powershell)) != CLI_OK || |
| 4182 | cbm_build_copilot_hook_command(binary_path, "SubagentStart", false, subagent_bash, |
| 4183 | sizeof(subagent_bash)) != CLI_OK || |
| 4184 | cbm_build_copilot_hook_command(binary_path, "SubagentStart", true, subagent_powershell, |
| 4185 | sizeof(subagent_powershell)) != CLI_OK) { |
| 4186 | return NULL; |
| 4187 | } |
| 4188 | |
| 4189 | yyjson_mut_doc *doc = yyjson_mut_doc_new(NULL); |
| 4190 | yyjson_mut_val *root = doc ? yyjson_mut_obj(doc) : NULL; |
| 4191 | yyjson_mut_val *hooks = doc ? yyjson_mut_obj(doc) : NULL; |
| 4192 | if (!doc || !root || !hooks) { |
| 4193 | if (doc) { |
| 4194 | yyjson_mut_doc_free(doc); |
| 4195 | } |
| 4196 | return NULL; |
| 4197 | } |
| 4198 | yyjson_mut_doc_set_root(doc, root); |
| 4199 | bool ok = |
| 4200 | yyjson_mut_obj_add_int(doc, root, "version", 1) && |
| 4201 | cbm_copilot_add_hook_event(doc, hooks, "sessionStart", session_bash, session_powershell) && |
| 4202 | cbm_copilot_add_hook_event(doc, hooks, "subagentStart", subagent_bash, |
| 4203 | subagent_powershell) && |
| 4204 | yyjson_mut_obj_add_val(doc, root, "hooks", hooks); |
| 4205 | char *manifest = ok ? yyjson_mut_write(doc, YYJSON_WRITE_PRETTY, NULL) : NULL; |
| 4206 | yyjson_mut_doc_free(doc); |
| 4207 | return manifest; |
| 4208 | } |
| 4209 | |
| 4210 | /* Copilot loads every manifest in $COPILOT_HOME/hooks. Treat our dedicated |
| 4211 | * filename as an exact-owned document: a foreign collision fails closed, and |
no test coverage detected