| 1313 | #endif |
| 1314 | |
| 1315 | static char *ha_process(cbm_mcp_server_t *srv, const char *input_json, const char *forced_event, |
| 1316 | ha_lifecycle_dialect_t dialect) { |
| 1317 | if (!srv || !input_json) { |
| 1318 | return NULL; |
| 1319 | } |
| 1320 | if (strlen(input_json) > HA_STDIN_CAP) { |
| 1321 | return NULL; |
| 1322 | } |
| 1323 | yyjson_doc *doc = yyjson_read(input_json, strlen(input_json), 0); |
| 1324 | if (!doc) { |
| 1325 | return NULL; |
| 1326 | } |
| 1327 | yyjson_val *root = yyjson_doc_get_root(doc); |
| 1328 | |
| 1329 | char *lifecycle = ha_lifecycle_json_from_root(srv, root, forced_event, dialect); |
| 1330 | if (lifecycle) { |
| 1331 | yyjson_doc_free(doc); |
| 1332 | return lifecycle; |
| 1333 | } |
| 1334 | const char *event = ha_hook_event_name(root); |
| 1335 | const char *tool = ha_obj_str(root, "tool_name"); |
| 1336 | bool coverage = false; |
| 1337 | if (!ha_tool_event_supported(dialect, event, tool, &coverage)) { |
| 1338 | yyjson_doc_free(doc); |
| 1339 | return NULL; |
| 1340 | } |
| 1341 | |
| 1342 | yyjson_val *tin = yyjson_obj_get(root, "tool_input"); |
| 1343 | |
| 1344 | /* Post-read coverage adapters warn only when the exact path is not fully |
| 1345 | * represented. They never block or rewrite the completed tool call. */ |
| 1346 | if (coverage) { |
| 1347 | char fpbuf[4096]; |
| 1348 | if (ha_normalized_tool_path(root, tin, fpbuf, sizeof(fpbuf))) { |
| 1349 | char *note = ha_resolve_coverage(srv, fpbuf); |
| 1350 | if (note) { |
| 1351 | char *output = ha_build_event_json(event, note); |
| 1352 | free(note); |
| 1353 | yyjson_doc_free(doc); |
| 1354 | return output; |
| 1355 | } |
| 1356 | } |
| 1357 | yyjson_doc_free(doc); |
| 1358 | return NULL; |
| 1359 | } |
| 1360 | |
| 1361 | const char *pattern = ha_obj_str(tin, "pattern"); |
| 1362 | char token[HA_MAX_TOKEN + 1]; |
| 1363 | if (!ha_extract_token(pattern, token, sizeof(token))) { |
| 1364 | yyjson_doc_free(doc); |
| 1365 | return NULL; |
| 1366 | } |
| 1367 | |
| 1368 | char cwdbuf[4096]; |
| 1369 | const char *cwd = ha_normalized_cwd_with_server(root, srv, cwdbuf, sizeof(cwdbuf)); |
| 1370 | if (!cwd) { |
| 1371 | yyjson_doc_free(doc); |
| 1372 | return NULL; |
no test coverage detected