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

Function remove_hooks_json

src/cli/cli.c:4377–4458  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4375 const char *match_command_exact;
4376} hooks_remove_args_t;
4377static int remove_hooks_json(hooks_remove_args_t args) {
4378 const char *settings_path = args.settings_path;
4379 const char *hook_event = args.hook_event;
4380 const char *matcher_str = args.matcher_str;
4381 const char *const *old_matchers = args.old_matchers;
4382 if (!settings_path || !hook_event || !args.match_command_exact) {
4383 return CLI_ERR;
4384 }
4385
4386 char *expected_content = NULL;
4387 size_t expected_length = 0U;
4388 int read_result =
4389 cbm_json_like_read_document(settings_path, &expected_content, &expected_length);
4390 if (read_result < 0) {
4391 return CLI_ERR;
4392 }
4393 if (read_result == 1) {
4394 return CLI_OK;
4395 }
4396
4397 int rc = CLI_ERR;
4398 yyjson_read_flag flags = YYJSON_READ_ALLOW_COMMENTS | YYJSON_READ_ALLOW_TRAILING_COMMAS;
4399 yyjson_doc *doc = yyjson_read(expected_content, expected_length, flags);
4400 if (!doc || !yyjson_is_obj(yyjson_doc_get_root(doc))) {
4401 yyjson_doc_free(doc);
4402 free(expected_content);
4403 return CLI_ERR;
4404 }
4405 yyjson_mut_doc *mdoc = yyjson_mut_doc_new(NULL);
4406 if (!mdoc) {
4407 yyjson_doc_free(doc);
4408 free(expected_content);
4409 return CLI_ERR;
4410 }
4411 yyjson_mut_val *root = yyjson_val_mut_copy(mdoc, yyjson_doc_get_root(doc));
4412 yyjson_doc_free(doc);
4413 if (!root) {
4414 yyjson_mut_doc_free(mdoc);
4415 free(expected_content);
4416 return CLI_ERR;
4417 }
4418 yyjson_mut_doc_set_root(mdoc, root);
4419
4420 yyjson_mut_val *hooks = yyjson_mut_obj_get(root, "hooks");
4421 if (!hooks) {
4422 yyjson_mut_doc_free(mdoc);
4423 free(expected_content);
4424 return CLI_OK;
4425 }
4426 if (!yyjson_mut_is_obj(hooks)) {
4427 yyjson_mut_doc_free(mdoc);
4428 free(expected_content);
4429 return CLI_ERR;
4430 }
4431
4432 yyjson_mut_val *event_arr = yyjson_mut_obj_get(hooks, hook_event);
4433 if (!event_arr) {
4434 yyjson_mut_doc_free(mdoc);

Calls 3

write_hook_event_arrayFunction · 0.85

Tested by

no test coverage detected