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

Function remove_hooks_json

src/cli/cli.c:4213–4294  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4211 const char *match_command_exact;
4212} hooks_remove_args_t;
4213static int remove_hooks_json(hooks_remove_args_t args) {
4214 const char *settings_path = args.settings_path;
4215 const char *hook_event = args.hook_event;
4216 const char *matcher_str = args.matcher_str;
4217 const char *const *old_matchers = args.old_matchers;
4218 if (!settings_path || !hook_event || !args.match_command_exact) {
4219 return CLI_ERR;
4220 }
4221
4222 char *expected_content = NULL;
4223 size_t expected_length = 0U;
4224 int read_result =
4225 cbm_json_like_read_document(settings_path, &expected_content, &expected_length);
4226 if (read_result < 0) {
4227 return CLI_ERR;
4228 }
4229 if (read_result == 1) {
4230 return CLI_OK;
4231 }
4232
4233 int rc = CLI_ERR;
4234 yyjson_read_flag flags = YYJSON_READ_ALLOW_COMMENTS | YYJSON_READ_ALLOW_TRAILING_COMMAS;
4235 yyjson_doc *doc = yyjson_read(expected_content, expected_length, flags);
4236 if (!doc || !yyjson_is_obj(yyjson_doc_get_root(doc))) {
4237 yyjson_doc_free(doc);
4238 free(expected_content);
4239 return CLI_ERR;
4240 }
4241 yyjson_mut_doc *mdoc = yyjson_mut_doc_new(NULL);
4242 if (!mdoc) {
4243 yyjson_doc_free(doc);
4244 free(expected_content);
4245 return CLI_ERR;
4246 }
4247 yyjson_mut_val *root = yyjson_val_mut_copy(mdoc, yyjson_doc_get_root(doc));
4248 yyjson_doc_free(doc);
4249 if (!root) {
4250 yyjson_mut_doc_free(mdoc);
4251 free(expected_content);
4252 return CLI_ERR;
4253 }
4254 yyjson_mut_doc_set_root(mdoc, root);
4255
4256 yyjson_mut_val *hooks = yyjson_mut_obj_get(root, "hooks");
4257 if (!hooks) {
4258 yyjson_mut_doc_free(mdoc);
4259 free(expected_content);
4260 return CLI_OK;
4261 }
4262 if (!yyjson_mut_is_obj(hooks)) {
4263 yyjson_mut_doc_free(mdoc);
4264 free(expected_content);
4265 return CLI_ERR;
4266 }
4267
4268 yyjson_mut_val *event_arr = yyjson_mut_obj_get(hooks, hook_event);
4269 if (!event_arr) {
4270 yyjson_mut_doc_free(mdoc);

Calls 3

write_hook_event_arrayFunction · 0.85

Tested by

no test coverage detected