MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / remove_hooks_json

Function remove_hooks_json

src/cli/cli.c:4151–4232  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4149 const char *match_command_exact;
4150} hooks_remove_args_t;
4151static int remove_hooks_json(hooks_remove_args_t args) {
4152 const char *settings_path = args.settings_path;
4153 const char *hook_event = args.hook_event;
4154 const char *matcher_str = args.matcher_str;
4155 const char *const *old_matchers = args.old_matchers;
4156 if (!settings_path || !hook_event || !args.match_command_exact) {
4157 return CLI_ERR;
4158 }
4159
4160 char *expected_content = NULL;
4161 size_t expected_length = 0U;
4162 int read_result =
4163 cbm_json_like_read_document(settings_path, &expected_content, &expected_length);
4164 if (read_result < 0) {
4165 return CLI_ERR;
4166 }
4167 if (read_result == 1) {
4168 return CLI_OK;
4169 }
4170
4171 int rc = CLI_ERR;
4172 yyjson_read_flag flags = YYJSON_READ_ALLOW_COMMENTS | YYJSON_READ_ALLOW_TRAILING_COMMAS;
4173 yyjson_doc *doc = yyjson_read(expected_content, expected_length, flags);
4174 if (!doc || !yyjson_is_obj(yyjson_doc_get_root(doc))) {
4175 yyjson_doc_free(doc);
4176 free(expected_content);
4177 return CLI_ERR;
4178 }
4179 yyjson_mut_doc *mdoc = yyjson_mut_doc_new(NULL);
4180 if (!mdoc) {
4181 yyjson_doc_free(doc);
4182 free(expected_content);
4183 return CLI_ERR;
4184 }
4185 yyjson_mut_val *root = yyjson_val_mut_copy(mdoc, yyjson_doc_get_root(doc));
4186 yyjson_doc_free(doc);
4187 if (!root) {
4188 yyjson_mut_doc_free(mdoc);
4189 free(expected_content);
4190 return CLI_ERR;
4191 }
4192 yyjson_mut_doc_set_root(mdoc, root);
4193
4194 yyjson_mut_val *hooks = yyjson_mut_obj_get(root, "hooks");
4195 if (!hooks) {
4196 yyjson_mut_doc_free(mdoc);
4197 free(expected_content);
4198 return CLI_OK;
4199 }
4200 if (!yyjson_mut_is_obj(hooks)) {
4201 yyjson_mut_doc_free(mdoc);
4202 free(expected_content);
4203 return CLI_ERR;
4204 }
4205
4206 yyjson_mut_val *event_arr = yyjson_mut_obj_get(hooks, hook_event);
4207 if (!event_arr) {
4208 yyjson_mut_doc_free(mdoc);

Calls 3

write_hook_event_arrayFunction · 0.85

Tested by

no test coverage detected