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

Function remove_hooks_json

src/cli/cli.c:1962–2016  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1960 * entry command to claim ownership */
1961} hooks_remove_args_t;
1962static int remove_hooks_json(hooks_remove_args_t args) {
1963 const char *settings_path = args.settings_path;
1964 const char *hook_event = args.hook_event;
1965 const char *matcher_str = args.matcher_str;
1966 const char *const *old_matchers = args.old_matchers;
1967 if (!settings_path) {
1968 return CLI_ERR;
1969 }
1970
1971 yyjson_doc *doc = read_json_file(settings_path);
1972 if (!doc) {
1973 return CLI_ERR;
1974 }
1975
1976 yyjson_mut_doc *mdoc = yyjson_mut_doc_new(NULL);
1977 yyjson_mut_val *root = yyjson_val_mut_copy(mdoc, yyjson_doc_get_root(doc));
1978 yyjson_doc_free(doc);
1979 if (!root) {
1980 yyjson_mut_doc_free(mdoc);
1981 return CLI_ERR;
1982 }
1983 yyjson_mut_doc_set_root(mdoc, root);
1984
1985 yyjson_mut_val *hooks = yyjson_mut_obj_get(root, "hooks");
1986 if (!hooks) {
1987 yyjson_mut_doc_free(mdoc);
1988 return 0;
1989 }
1990
1991 yyjson_mut_val *event_arr = yyjson_mut_obj_get(hooks, hook_event);
1992 if (!event_arr || !yyjson_mut_is_arr(event_arr)) {
1993 yyjson_mut_doc_free(mdoc);
1994 return 0;
1995 }
1996
1997 size_t idx;
1998 size_t max;
1999 yyjson_mut_val *item;
2000 yyjson_mut_arr_foreach(event_arr, idx, max, item) {
2001 if (is_cmm_hook_entry(item, matcher_str, old_matchers, args.match_command_substr)) {
2002 yyjson_mut_arr_remove(event_arr, idx);
2003 break;
2004 }
2005 }
2006
2007 /* Prune the event key once its array is empty, so removing our hook leaves
2008 * no stale "<Event>": [] cruft behind. */
2009 if (yyjson_mut_arr_size(event_arr) == 0) {
2010 yyjson_mut_obj_remove_key(hooks, hook_event);
2011 }
2012
2013 int rc = write_json_file(settings_path, mdoc);
2014 yyjson_mut_doc_free(mdoc);
2015 return rc;
2016}
2017
2018int cbm_upsert_claude_hooks(const char *settings_path) {
2019 char command[CLI_BUF_1K];

Callers 5

cbm_remove_claude_hooksFunction · 0.85
cbm_remove_session_hooksFunction · 0.85
cbm_remove_gemini_hooksFunction · 0.85

Calls 3

read_json_fileFunction · 0.85
is_cmm_hook_entryFunction · 0.85
write_json_fileFunction · 0.85

Tested by

no test coverage detected