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

Function remove_hooks_json

src/cli/cli.c:4916–4998  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4914 size_t match_arg_count;
4915} hooks_remove_args_t;
4916static int remove_hooks_json(hooks_remove_args_t args) {
4917 const char *settings_path = args.settings_path;
4918 const char *hook_event = args.hook_event;
4919 const char *matcher_str = args.matcher_str;
4920 const char *const *old_matchers = args.old_matchers;
4921 if (!settings_path || !hook_event || !args.match_command_exact) {
4922 return CLI_ERR;
4923 }
4924
4925 char *expected_content = NULL;
4926 size_t expected_length = 0U;
4927 int read_result =
4928 cbm_json_like_read_document(settings_path, &expected_content, &expected_length);
4929 if (read_result < 0) {
4930 return CLI_ERR;
4931 }
4932 if (read_result == 1) {
4933 return CLI_OK;
4934 }
4935
4936 int rc = CLI_ERR;
4937 yyjson_read_flag flags = YYJSON_READ_ALLOW_COMMENTS | YYJSON_READ_ALLOW_TRAILING_COMMAS;
4938 yyjson_doc *doc = yyjson_read(expected_content, expected_length, flags);
4939 if (!doc || !yyjson_is_obj(yyjson_doc_get_root(doc))) {
4940 yyjson_doc_free(doc);
4941 free(expected_content);
4942 return CLI_ERR;
4943 }
4944 yyjson_mut_doc *mdoc = yyjson_mut_doc_new(NULL);
4945 if (!mdoc) {
4946 yyjson_doc_free(doc);
4947 free(expected_content);
4948 return CLI_ERR;
4949 }
4950 yyjson_mut_val *root = yyjson_val_mut_copy(mdoc, yyjson_doc_get_root(doc));
4951 yyjson_doc_free(doc);
4952 if (!root) {
4953 yyjson_mut_doc_free(mdoc);
4954 free(expected_content);
4955 return CLI_ERR;
4956 }
4957 yyjson_mut_doc_set_root(mdoc, root);
4958
4959 yyjson_mut_val *hooks = yyjson_mut_obj_get(root, "hooks");
4960 if (!hooks) {
4961 yyjson_mut_doc_free(mdoc);
4962 free(expected_content);
4963 return CLI_OK;
4964 }
4965 if (!yyjson_mut_is_obj(hooks)) {
4966 yyjson_mut_doc_free(mdoc);
4967 free(expected_content);
4968 return CLI_ERR;
4969 }
4970
4971 yyjson_mut_val *event_arr = yyjson_mut_obj_get(hooks, hook_event);
4972 if (!event_arr) {
4973 yyjson_mut_doc_free(mdoc);

Calls 3

write_hook_event_arrayFunction · 0.85

Tested by

no test coverage detected