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

Function ha_coverage_context

src/cli/hook_augment.c:494–602  ·  view source on GitHub ↗

Parse a targeted check_index_coverage envelope and return a compact note for * the requested path. *is_error is set for MCP errors (project not indexed) so * the caller can climb to another candidate project root. */

Source from the content-addressed store, hash-verified

492 * the requested path. *is_error is set for MCP errors (project not indexed) so
493 * the caller can climb to another candidate project root. */
494static char *ha_coverage_context(const char *envelope, const char *rel, bool *is_error) {
495 *is_error = false;
496 yyjson_doc *edoc = yyjson_read(envelope, strlen(envelope), 0);
497 if (!edoc) {
498 return NULL;
499 }
500 yyjson_val *eroot = yyjson_doc_get_root(edoc);
501 yyjson_val *err = yyjson_obj_get(eroot, "isError");
502 if (err && yyjson_is_true(err)) {
503 *is_error = true;
504 yyjson_doc_free(edoc);
505 return NULL;
506 }
507 yyjson_val *content = yyjson_obj_get(eroot, "content");
508 yyjson_val *item0 = (content && yyjson_is_arr(content)) ? yyjson_arr_get(content, 0) : NULL;
509 const char *inner = ha_obj_str(item0, "text");
510 if (!inner) {
511 yyjson_doc_free(edoc);
512 return NULL;
513 }
514 yyjson_doc *idoc = yyjson_read(inner, strlen(inner), 0);
515 if (!idoc) {
516 yyjson_doc_free(edoc);
517 return NULL;
518 }
519 yyjson_val *iroot = yyjson_doc_get_root(idoc);
520 char *text = NULL;
521 yyjson_val *paths = yyjson_obj_get(iroot, "paths");
522 yyjson_val *item = paths && yyjson_is_arr(paths) ? yyjson_arr_get(paths, 0) : NULL;
523 const char *path = ha_obj_str(item, "path");
524 const char *status = ha_obj_str(item, "status");
525 const char *freshness = ha_obj_str(item, "freshness");
526 const char *action = ha_obj_str(item, "recommended_action");
527 if (item && (!path || strcmp(path, rel) == 0) && status &&
528 strcmp(status, "no_recorded_issue") != 0 && strcmp(status, "outside_project") != 0 &&
529 strcmp(status, "invalid_path") != 0) {
530 const char *kind = NULL;
531 const char *detail = NULL;
532 char *range_detail = NULL;
533 yyjson_val *coverage = yyjson_obj_get(item, "coverage");
534 yyjson_val *row = coverage && yyjson_is_arr(coverage) ? yyjson_arr_get(coverage, 0) : NULL;
535 if (row) {
536 kind = ha_obj_str(row, "kind");
537 detail = ha_obj_str(row, "detail");
538 yyjson_val *ranges = yyjson_obj_get(row, "ranges");
539 size_t range_count = ranges && yyjson_is_arr(ranges) ? yyjson_arr_size(ranges) : 0;
540 if ((!detail || !detail[0]) && range_count > 0 && range_count <= SIZE_MAX / 48U) {
541 range_detail = calloc(range_count * 48U + 1U, 1U);
542 if (range_detail) {
543 size_t used = 0;
544 size_t index;
545 size_t maximum;
546 yyjson_val *range;
547 yyjson_arr_foreach(ranges, index, maximum, range) {
548 yyjson_val *start_value = yyjson_obj_get(range, "start");
549 yyjson_val *end_value = yyjson_obj_get(range, "end");
550 if (!yyjson_is_int(start_value) || !yyjson_is_int(end_value)) {
551 continue;

Callers 1

ha_resolve_coverageFunction · 0.85

Calls 1

ha_obj_strFunction · 0.85

Tested by

no test coverage detected