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

Function ha_process

src/cli/hook_augment.c:1652–1728  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1650#endif
1651
1652static char *ha_process(cbm_mcp_server_t *srv, const char *input_json, const char *forced_event,
1653 ha_lifecycle_dialect_t dialect) {
1654 if (!srv || !input_json) {
1655 return NULL;
1656 }
1657 if (strlen(input_json) > HA_STDIN_CAP) {
1658 return NULL;
1659 }
1660 yyjson_doc *doc = yyjson_read(input_json, strlen(input_json), 0);
1661 if (!doc) {
1662 return NULL;
1663 }
1664 yyjson_val *root = yyjson_doc_get_root(doc);
1665
1666 char *lifecycle = ha_lifecycle_json_from_root(srv, root, forced_event, dialect);
1667 if (lifecycle) {
1668 yyjson_doc_free(doc);
1669 return lifecycle;
1670 }
1671 const char *event = ha_hook_event_name(root);
1672 const char *tool = ha_obj_str(root, "tool_name");
1673 bool coverage = false;
1674 if (!ha_tool_event_supported(dialect, event, tool, &coverage)) {
1675 yyjson_doc_free(doc);
1676 return NULL;
1677 }
1678
1679 yyjson_val *tin = yyjson_obj_get(root, "tool_input");
1680
1681 /* Post-read coverage adapters warn only when the exact path is not fully
1682 * represented. They never block or rewrite the completed tool call. */
1683 if (coverage) {
1684 char fpbuf[4096];
1685 if (ha_normalized_tool_path(root, tin, fpbuf, sizeof(fpbuf))) {
1686 char *note = ha_resolve_coverage(srv, fpbuf);
1687 if (note) {
1688 char *output = ha_build_event_json(event, note);
1689 free(note);
1690 yyjson_doc_free(doc);
1691 return output;
1692 }
1693 }
1694 yyjson_doc_free(doc);
1695 return NULL;
1696 }
1697
1698 char bash_pattern[HA_BASH_TOK_SZ];
1699 const char *pattern;
1700 if (strcmp(tool, "Bash") == 0) {
1701 const char *cmd = ha_obj_str(tin, "command");
1702 if (!ha_parse_bash_search_pattern(cmd, bash_pattern, sizeof(bash_pattern))) {
1703 yyjson_doc_free(doc);
1704 return NULL;
1705 }
1706 pattern = bash_pattern;
1707 } else {
1708 pattern = ha_obj_str(tin, "pattern");
1709 }

Callers 2

cbm_cmd_hook_augmentFunction · 0.85

Calls 11

ha_hook_event_nameFunction · 0.85
ha_obj_strFunction · 0.85
ha_tool_event_supportedFunction · 0.85
ha_normalized_tool_pathFunction · 0.85
ha_resolve_coverageFunction · 0.85
ha_build_event_jsonFunction · 0.85
ha_extract_tokenFunction · 0.85
ha_resolve_and_queryFunction · 0.85

Tested by

no test coverage detected