| 5278 | } |
| 5279 | |
| 5280 | static int cbm_remove_hermes_context_hook(const char *config_path, const char *binary_path) { |
| 5281 | static const char *const sequence_path[] = {"hooks", "pre_llm_call"}; |
| 5282 | static const char identity[] = "\"" CMM_HERMES_HOOK_ID "\""; |
| 5283 | char item[CLI_BUF_8K]; |
| 5284 | if (cbm_build_hermes_context_hook_item(binary_path, item, sizeof(item)) != CLI_OK) { |
| 5285 | return CBM_YAML_IDENTITY_EDIT_ERROR; |
| 5286 | } |
| 5287 | size_t before_len = 0U; |
| 5288 | char *before = read_file_str(config_path, &before_len); |
| 5289 | int result = cbm_yaml_remove_mapping_sequence_item( |
| 5290 | config_path, sequence_path, sizeof(sequence_path) / sizeof(sequence_path[0]), "id", |
| 5291 | identity, item); |
| 5292 | if (result != CBM_YAML_IDENTITY_EDIT_OK || !before) { |
| 5293 | free(before); |
| 5294 | return result; |
| 5295 | } |
| 5296 | size_t after_len = 0U; |
| 5297 | char *after = read_file_str(config_path, &after_len); |
| 5298 | if (!after) { |
| 5299 | free(before); |
| 5300 | return CBM_YAML_IDENTITY_EDIT_ERROR; |
| 5301 | } |
| 5302 | bool exact_removed = before_len != after_len || memcmp(before, after, before_len) != 0; |
| 5303 | bool remove_empty_sequence = exact_removed && cbm_hermes_pre_llm_sequence_is_empty(after); |
| 5304 | free(before); |
| 5305 | free(after); |
| 5306 | if (remove_empty_sequence && |
| 5307 | cbm_yaml_remove_mapping_entry(config_path, "hooks", "pre_llm_call") != CLI_OK) { |
| 5308 | return CBM_YAML_IDENTITY_EDIT_ERROR; |
| 5309 | } |
| 5310 | return CBM_YAML_IDENTITY_EDIT_OK; |
| 5311 | } |
| 5312 | |
| 5313 | static int cbm_remove_previous_claude_exec_hook(const char *settings_path, const char *hook_event, |
| 5314 | const char *matcher_str, |
no test coverage detected