Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

chore(pipeline): integrate upstream indexing and call resolution

Pcristin05a18a7c1489
diff --cc src/foundation/mem_core.c
index 426dec44c,cc6e8f9d5..8dd30bef9
--- a/src/foundation/mem_core.c
+++ b/src/foundation/mem_core.c
@@@ -66,8 -66,8 +66,9 @@@ typedef struct
static mem_class_stats_t g_classes[CBM_MEM_CLASS_COUNT];
static const char *const g_class_names[CBM_MEM_CLASS_COUNT] = {
-- "other", "gbuf_node", "gbuf_edge", "gbuf_string", "gbuf_index", "extract", "arena",
- "ts_tree", "semantic", "dump", "store", "hash_table", "dyn_array", "resolve",
- "ts_tree", "semantic", "dump", "store", "hash_table", "dyn_array", "graph_cache",
++ "other", "gbuf_node", "gbuf_edge", "gbuf_string", "gbuf_index",
++ "extract", "arena", "ts_tree", "semantic", "dump",
++ "store", "hash_table", "dyn_array", "resolve", "graph_cache",
};
const char *cbm_mem_class_name(cbm_mem_class_t cls) {
diff --cc src/foundation/mem_core.h
index 6b5cb5cb3,e61de900a..5de1ba7bd
--- a/src/foundation/mem_core.h
+++ b/src/foundation/mem_core.h
@@@ -66,7 -66,10 +66,11 @@@ typedef enum
CBM_MEM_CLASS_STORE, /* SQLite (bound mem methods) + store batches and row buffers */
CBM_MEM_CLASS_HASH_TABLE, /* CBMHashTable buckets/entries not claimed by an owner class */
CBM_MEM_CLASS_DYN_ARRAY, /* CBM_DYN_ARRAY item storage (every cbm_da_* user) */
+ CBM_MEM_CLASS_RESOLVE, /* call resolution evidence and coverage capture */
+ /* The daemon's in-memory adjacency layers (store/graph_mem.h): resident
+ * across requests, so they are subtracted from index-worker budgets and
+ * must read apart from SQLite's request-scoped memory (STORE). */
+ CBM_MEM_CLASS_GRAPH_CACHE,
CBM_MEM_CLASS_COUNT
} cbm_mem_class_t;
diff --cc src/mcp/mcp.c
index 99ba4d519,1d1489e7f..bdd991932
--- a/src/mcp/mcp.c
+++ b/src/mcp/mcp.c
@@@ -72,7 -74,7 +74,8 @@@ enum
#include "watcher/watcher.h"
#include "foundation/mem.h"
#include "foundation/mem_core.h"
+#include "foundation/hash_table.h"
+ #include "foundation/json_writer.h"
#include "foundation/arena.h"
#include "foundation/diagnostics.h"
#include "foundation/platform.h"
diff --cc src/pipeline/pass_calls.c
index 73ea8f0f1,1eb3bddff..4becb5f95
--- a/src/pipeline/pass_calls.c
+++ b/src/pipeline/pass_calls.c
@@@ -388,10 -561,10 +567,10 @@@ cbm_svc_kind_t cbm_pipeline_external_im
/* Handle a route registration call: create Route node + HANDLES edge.
* route_mount is the framework mount of the registering file ("/api" for a
* Laravel 11+ `withRouting(api: ...)` file, #1146) or "". */
-static void handle_route_registration(cbm_pipeline_ctx_t *ctx, const CBMCall *call,
+static bool handle_route_registration(cbm_pipeline_ctx_t *ctx, const CBMCall *call,
const cbm_gbuf_node_t *source_node, const char *module_qn,
const char **imp_keys, const char **imp_vals, int imp_count,
- const char *route_mount) {
+ const char *route_mount, CBMLanguage lang) {
const char *method = cbm_service_pattern_route_method(call->callee_name);
char mounted[CBM_SZ_256];
const char *path =
@@@ -519,7 -698,12 +705,12 @@@ static void calls_append_args(char *pro
}
}
+ /* Test seam for the formatter above. Not part of the public API. */
+ void cbm_pipeline_calls_append_args_for_tests(char *props, size_t cap, const CBMCall *call) {
+ calls_append_args(props, cap, call);
+ }
+
-static void calls_emit_edge(cbm_gbuf_t *gbuf, int64_t src, int64_t tgt, const char *type,
+static bool calls_emit_edge(cbm_gbuf_t *gbuf, int64_t src, int64_t tgt, const char *type,
char *props, size_t cap, const CBMCall *call) {
if (call && call->start_line > 0 && strcmp(type, "CALLS") == 0) {
size_t len = strlen(props);
@@@ -592,12 -777,8 +785,9 @@@ static bool emit_http_async_edge(cbm_pi
if (broker && n > 0 && (size_t)n < sizeof(props)) {
n += snprintf(props + n, sizeof(props) - (size_t)n, ",\"broker\":\"%s\"", broker);
}
- if (n > 0 && (size_t)n < sizeof(props) - 1) {
- props[n] = '}';
- props[n + 1] = '\0';
- }
- calls_emit_edge(ctx->gbuf, source->id, route_id, edge_type, props, sizeof(props), call);
+ cbm_pipeline_close_call_props(props, n, call, false);
+ cbm_gbuf_insert_edge(ctx->gbuf, source->id, route_id, edge_type, props);
+ return false;
}
/* Classify a resolved call and emit the appropriate edge. */
@@@ -609,14 -790,17 +799,15 @@@ static bool emit_classified_edge(cbm_pi
const cbm_gbuf_node_t *source, const cbm_gbuf_node_t *target,
const cbm_resolution_t *res, const char *module_qn,
const char **imp_keys, const char **imp_vals, int imp_count,
- bool suppress_plain_calls, const char *route_mount) {
+ bool suppress_plain_calls, const char *route_mount,
+ CBMLanguage lang) {
cbm_svc_kind_t svc = cbm_service_pattern_match(res->qualified_name);
if (svc == CBM_SVC_ROUTE_REG && call->first_string_arg && call->first_string_arg[0] == '/') {
- handle_route_registration(ctx, call, source, module_qn, imp_keys, imp_vals, imp_count,
- route_mount, lang);
- return;
+ return handle_route_registration(ctx, call, source, module_qn, imp_keys, imp_vals,
- imp_count, route_mount);
++ imp_count, route_mount, lang);
}
if (svc == CBM_SVC_HTTP || svc == CBM_SVC_ASYNC) {
- emit_http_async_edge(ctx, call, source, target, res, svc, suppress_plain_calls);
- return;
+ return emit_http_async_edge(ctx, call, source, target, res, svc, suppress_plain_calls);
}
if (svc == CBM_SVC_CONFIG) {
char esc_c[CBM_SZ_256];
@@@ -662,152 -846,13 +853,204 @@@ static const cbm_gbuf_node_t *calls_fin
return src;
}
+static CBMCallEvidence *calls_evidence_at(CBMCallEvidence *evidence, int index,
+ CBMCallEvidence *fallback) {
+ if (evidence) {
+ return &evidence[index];
+ }
+ return fallback;
+}
+
+static CBMCallEvidence *calls_evidence_new(cbm_pipeline_t *pipeline, const CBMFileResult *result) {
+ CBMCallEvidence *evidence =
+ cbm_calloc(CBM_MEM_CLASS_RESOLVE, (size_t)result->calls.count * sizeof(*evidence));
+ if (!evidence) {
+ cbm_pipeline_mark_unresolved_capture_failed(pipeline);
+ }
+ return evidence;
+}
+
+/* Report whether a service spelling handled this call, independently of
+ * whether its classified edge is CALLS and therefore covers the occurrence. */
+static bool calls_emit_service_call(cbm_pipeline_ctx_t *ctx, const CBMCall *call,
+ const cbm_gbuf_node_t *source_node, cbm_svc_kind_t svc,
+ const cbm_resolution_t *resolved, CBMCallEvidence *evidence) {
+ if (svc != CBM_SVC_HTTP && svc != CBM_SVC_ASYNC) {
+ return false;
+ }
+ const char *url = call->first_string_arg;
+ if (!url || !url[0]) {
+ return false;
+ }
+ bool has_url_or_topic = url[0] == '/' || strstr(url, "://") != NULL ||
+ (svc == CBM_SVC_ASYNC && strlen(url) > PAIR_LEN);
+ if (!has_url_or_topic) {
+ return false;
+ }
+ cbm_resolution_t fallback = {.qualified_name = call->callee_name,
+ .confidence = PC_SVC_PATTERN_CONF,
+ .strategy = "service_pattern",
+ .candidate_count = 0};
+ const cbm_resolution_t *res = resolved ? resolved : &fallback;
+ evidence->calls_emitted |= emit_http_async_edge(ctx, call, source_node, NULL, res, svc, false);
+ return true;
+}
+
+/* Route registration counts as handled even when its edge is not CALLS. */
+static bool calls_emit_route_call(cbm_pipeline_ctx_t *ctx, const CBMCall *call,
+ const cbm_gbuf_node_t *source_node, const char *module_qn,
+ const char **imp_keys, const char **imp_vals, int imp_count,
- const char *route_mount, CBMCallEvidence *evidence) {
++ const char *route_mount, CBMLanguage lang,
++ CBMCallEvidence *evidence) {
+ if (cbm_service_pattern_route_method(call->callee_name) == NULL || !call->first_string_arg ||
+ call->first_string_arg[0] != '/') {
+ return false;
+ }
+ evidence->calls_emitted |= handle_route_registration(
- ctx, call, source_node, module_qn, imp_keys, imp_vals, imp_count, route_mount);
++ ctx, call, source_node, module_qn, imp_keys, imp_vals, imp_count, route_mount, lang);
+ return true;
+}
+
+/* An external callee can still register a route or address an HTTP/async service. */
+static int calls_emit_unresolved_service(cbm_pipeline_ctx_t *ctx, const CBMCall *call,
+ const cbm_gbuf_node_t *source_node, const char *module_qn,
+ const char **imp_keys, const char **imp_vals,
- int imp_count, const char *route_mount,
++ int imp_count, const char *route_mount, CBMLanguage lang,
+ CBMCallEvidence *evidence) {
+ if (calls_emit_route_call(ctx, call, source_node, module_qn, imp_keys, imp_vals, imp_count,
- route_mount, evidence)) {
++ route_mount, lang, evidence)) {
+ return SKIP_ONE;
+ }
+ cbm_svc_kind_t svc = cbm_service_pattern_match(call->callee_name);
+ if (svc == CBM_SVC_NONE && cbm_service_pattern_is_global_fetch(call->callee_name)) {
+ svc = CBM_SVC_HTTP;
+ }
+ return calls_emit_service_call(ctx, call, source_node, svc, NULL, evidence);
+}
+
+/* Apply the field-call policy after a registry target has been found. */
+static const cbm_gbuf_node_t *calls_field_target(cbm_pipeline_ctx_t *ctx, const CBMCall *call,
+ const CBMResolvedCallArray *lsp_calls,
+ CBMLanguage lang, const char *rel,
+ const cbm_gbuf_node_t *source_node,
+ const cbm_gbuf_node_t *target_node,
+ bool arrow_bound, cbm_resolution_t *res) {
+ switch (cbm_call_onto_field_policy(lang, call->callee_name, target_node->label,
+ target_node->file_path)) {
+ case CBM_FIELD_CALL_DROP:
+ return NULL;
+ case CBM_FIELD_CALL_BY_OWNER:
+ /* An arrow call was already bound this way by registry resolution. */
+ if (!arrow_bound) {
+ target_node = cbm_pipeline_c_member_call_resolve(
+ lsp_calls, NULL, ctx->gbuf, ctx->registry, ctx->project_name,
+ call->enclosing_func_qn, call->callee_name, cbm_c_member_rule_file(lang, rel), res);
+ }
+ if (!target_node || source_node->id == target_node->id) {
+ return NULL;
+ }
+ break;
+ case CBM_FIELD_CALL_KEEP:
+ break;
+ }
+ return target_node;
+}
+
+static bool calls_emit_lsp_target(cbm_pipeline_ctx_t *ctx, const CBMCall *call,
+ const CBMResolvedCall *lsp, bool allow_tail, CBMLanguage lang,
+ const CBMImportArray *imports, const cbm_gbuf_node_t *source_node,
+ const char *module_qn, const char **imp_keys,
+ const char **imp_vals, int imp_count, const char *route_mount,
+ CBMCallEvidence *evidence) {
+ if (!lsp) {
+ return false;
+ }
+ bool exact_external_target =
+ call->requires_lsp_resolution && cbm_pipeline_kotlin_external_target(lang, lsp->callee_qn);
+ const cbm_gbuf_node_t *target_node =
+ exact_external_target ? cbm_pipeline_lsp_target_node_strict(ctx->gbuf, ctx->project_name,
+ lsp->callee_qn, allow_tail)
+ : cbm_pipeline_lsp_target_node(ctx->gbuf, ctx->project_name,
+ lsp->callee_qn, allow_tail);
+ if (!target_node || source_node->id == target_node->id) {
+ return false;
+ }
+ cbm_resolution_t res = {0};
+ /* Keep the canonical graph QN, including project prefixes added by fallback. */
+ res.qualified_name = target_node->qualified_name;
+ res.confidence = lsp->confidence;
+ res.strategy = lsp->strategy;
+ res.candidate_count = PC_SINGLE_CANDIDATE_COUNT;
+ evidence->candidate_qn = target_node->qualified_name;
+ /* Synthetic builtins can still denote a spawn; keep the parallel pass policy. */
+ cbm_pipeline_spawn_t spawn;
+ if (cbm_pipeline_spawn_site(ctx->gbuf, lang, call, imports, &res, &spawn)) {
+ cbm_pipeline_emit_spawn(ctx->gbuf, source_node, call, &spawn);
+ return true;
+ }
+ evidence->calls_emitted |=
+ emit_classified_edge(ctx, call, source_node, target_node, &res, module_qn, imp_keys,
- imp_vals, imp_count, false, route_mount);
++ imp_vals, imp_count, false, route_mount, lang);
+ return true;
+}
+
++/* Vendor receivers and cross-language name guesses cannot bind project calls.
++ * Keep the registry policy shared with the parallel resolver. */
++static cbm_resolution_t calls_registry_resolution(cbm_pipeline_ctx_t *ctx, const CBMCall *call,
++ const char *module_qn, const char **imp_keys,
++ const char **imp_vals, int imp_count,
++ CBMLanguage lang, bool rust_external,
++ bool php_vendor_call) {
++ cbm_resolution_t res = {0};
++ if (!rust_external && !php_vendor_call) {
++ res = cbm_registry_resolve_call_lang(ctx->registry, call->callee_name, module_qn, imp_keys,
++ imp_vals, imp_count, lang);
++ /* Cross-language veto: a name-only guess never binds another
++ * language's symbol (a JS app.get must not become Python's
++ * builtins.dict.get). The vetoed answer becomes EMPTY here, before
++ * the fallbacks below, so the route/HTTP classification still runs.
++ * MUST match pass_parallel.c. */
++ if (cbm_registry_name_guess_vetoed(ctx->registry, lang, &res)) {
++ res = (cbm_resolution_t){0};
++ }
++ }
++ return res;
++}
++
++static int calls_emit_import_service(cbm_pipeline_ctx_t *ctx, const CBMCall *call,
++ const cbm_gbuf_node_t *source_node, const char *rel,
++ CBMLanguage lang, const CBMImportArray *imports,
++ cbm_external_import_index_t *ext_imports,
++ CBMCallEvidence *evidence) {
++ /* A callee an import binds to an external client library
++ * (`send` under `from paho.mqtt import publish as send`): spelled
++ * through its import, then classified. MUST match pass_parallel.c. */
++ char spelled[CBM_SZ_512];
++ cbm_svc_kind_t isvc =
++ cbm_pipeline_external_import_service(ext_imports, ctx->gbuf, ctx->project_name, rel, lang,
++ imports, call, spelled, sizeof(spelled));
++ if (isvc != CBM_SVC_NONE) {
++ CBMCall through = *call;
++ through.callee_name = spelled;
++ cbm_resolution_t imp_res = {.qualified_name = spelled,
++ .confidence = PC_SVC_PATTERN_CONF,
++ .strategy = "import_binding",
++ .candidate_count = 0};
++ evidence->calls_emitted |=
++ emit_http_async_edge(ctx, &through, source_node, NULL, &imp_res, isvc, false);
++ return SKIP_ONE;
++ }
++ return 0;
++}
++
/* Resolve one call and emit the appropriate edge. Returns 1 if resolved, 0 if not. */
- static int resolve_single_call(cbm_pipeline_ctx_t *ctx, const CBMCall *call,
- const CBMFileResult *result, const char *rel, const char *module_qn,
- const char **imp_keys, const char **imp_vals, int imp_count,
- CBMLanguage lang, const CBMImportArray *imports,
- const char *route_mount, CBMCallEvidence *evidence) {
+ static int resolve_single_call(cbm_pipeline_ctx_t *ctx, CBMCall *call, const CBMFileResult *result,
+ const char *rel, const char *module_qn, const char **imp_keys,
+ const char **imp_vals, int imp_count, CBMLanguage lang,
+ const CBMImportArray *imports, const char *route_mount,
+ const cbm_php_vendor_names_t *php_vendor,
- cbm_external_import_index_t *ext_imports) {
++ cbm_external_import_index_t *ext_imports,
++ CBMCallEvidence *evidence) {
const CBMResolvedCallArray *lsp_calls = &result->resolved_calls;
const cbm_gbuf_node_t *source_node = calls_find_source(ctx, rel, call->enclosing_func_qn);
if (!source_node) {
@@@ -819,9 -864,41 +1062,15 @@@
bool allow_tail = cbm_pipeline_lsp_allow_tail_match(lang);
const CBMResolvedCall *lsp = cbm_pipeline_find_lsp_resolution_in_graph(
lsp_calls, call, allow_tail, ctx->gbuf, ctx->project_name);
+ /* #1186: a PHP call on a vendor type (`new Request`, or a receiver the LSP
+ * typed as an imported vendor class) takes the LSP result or no target: a
+ * same-named project symbol found by name alone is never the vendor's.
+ * Service/route classification below still runs. Mirrors pass_parallel.c. */
+ bool php_vendor_call = cbm_pipeline_php_vendor_call(php_vendor, result, call) ||
+ cbm_pipeline_lsp_external_receiver(lsp);
- if (lsp) {
- bool exact_external_target = call->requires_lsp_resolution &&
- cbm_pipeline_kotlin_external_target(lang, lsp->callee_qn);
- const cbm_gbuf_node_t *target_node =
- exact_external_target ? cbm_pipeline_lsp_target_node_strict(
- ctx->gbuf, ctx->project_name, lsp->callee_qn, allow_tail)
- : cbm_pipeline_lsp_target_node(ctx->gbuf, ctx->project_name,
- lsp->callee_qn, allow_tail);
- if (target_node && source_node->id != target_node->id) {
- cbm_resolution_t res = {0};
- /* Use the gbuf node's QN so downstream edge props show the canonical
- * project-qualified form even when fallback prefixed the project. */
- res.qualified_name = target_node->qualified_name;
- res.confidence = lsp->confidence;
- res.strategy = lsp->strategy;
- res.candidate_count = 1;
- /* An LSP answer on a synthetic builtin (`<python-builtins>`) is
- * not project code: a spawn spelling still spawns. The parallel
- * pass keeps the LSP answer in `res` and asks the same question.
- * MUST match pass_parallel.c. */
- cbm_pipeline_spawn_t spawn;
- if (cbm_pipeline_spawn_site(ctx->gbuf, lang, call, imports, &res, &spawn)) {
- cbm_pipeline_emit_spawn(ctx->gbuf, source_node, call, &spawn);
- return SKIP_ONE;
- }
- emit_classified_edge(ctx, call, source_node, target_node, &res, module_qn, imp_keys,
- imp_vals, imp_count, false, route_mount, lang);
- return SKIP_ONE;
- }
+ if (calls_emit_lsp_target(ctx, call, lsp, allow_tail, lang, imports, source_node, module_qn,
+ imp_keys, imp_vals, imp_count, route_mount, evidence)) {
+ return SKIP_ONE;
}
/* Synthetic semantic candidates (currently implicit C++ operators) are
@@@ -857,13 -934,28 +1106,22 @@@
.confidence = PC_SVC_PATTERN_CONF,
.strategy = "http_client_instance",
.candidate_count = 0};
- emit_http_async_edge(ctx, &routed, source_node, NULL, &svc_res, CBM_SVC_HTTP, false);
+ evidence->calls_emitted |=
+ emit_http_async_edge(ctx, &routed, source_node, NULL, &svc_res, CBM_SVC_HTTP, false);
return SKIP_ONE;
}
- if (calls_emit_service_call(ctx, call, source_node,
- cbm_service_pattern_match(call->callee_name), NULL, evidence)) {
+ /* A PHP call on a proven vendor class is classified by that class
+ * (#1186): it skips the registry below, so the route-verb fallback would
+ * otherwise mint a route registration for `GuzzleClient::get('/x')`. An
+ * LSP row with a graph target returned above. MUST match pass_parallel.c. */
+ cbm_svc_kind_t csvc;
+ const char *svc_name = cbm_pipeline_service_name(call, lsp, &csvc);
- if (csvc == CBM_SVC_HTTP || csvc == CBM_SVC_ASYNC) {
- const char *cu = call->first_string_arg;
- bool chas_url = cu && cu[0] != '\0' &&
- (cu[0] == '/' || strstr(cu, "://") != NULL ||
- (csvc == CBM_SVC_ASYNC && strlen(cu) > PAIR_LEN));
- if (chas_url) {
- cbm_resolution_t svc_res = {.qualified_name = svc_name,
- .confidence = PC_SVC_PATTERN_CONF,
- .strategy = "service_pattern",
- .candidate_count = 0};
- emit_http_async_edge(ctx, call, source_node, NULL, &svc_res, csvc, false);
- return SKIP_ONE;
- }
++ cbm_resolution_t svc_res = {.qualified_name = svc_name,
++ .confidence = PC_SVC_PATTERN_CONF,
++ .strategy = "service_pattern",
++ .candidate_count = 0};
++ if (calls_emit_service_call(ctx, call, source_node, csvc, &svc_res, evidence)) {
+ return SKIP_ONE;
}
/* #2053: a Rust call the LSP placed on an EXTERNAL symbol (std's
@@@ -873,19 -965,19 +1131,8 @@@
* classify the call. MUST match pass_parallel.c. */
bool rust_external = lsp && cbm_pipeline_rust_external_target(
lang, lsp->strategy, lsp->callee_qn, ctx->project_name);
-- cbm_resolution_t res = {0};
- if (!rust_external) {
- res = cbm_registry_resolve(ctx->registry, call->callee_name, module_qn, imp_keys, imp_vals,
- imp_count);
- if (!rust_external && !php_vendor_call) {
- res = cbm_registry_resolve_call_lang(ctx->registry, call->callee_name, module_qn, imp_keys,
- imp_vals, imp_count, lang);
-- /* Cross-language veto: a name-only guess never binds another
-- * language's symbol (a JS app.get must not become Python's
-- * builtins.dict.get). The vetoed answer becomes EMPTY here, before
-- * the fallbacks below, so the route/HTTP classification still runs.
-- * MUST match pass_parallel.c. */
-- if (cbm_registry_name_guess_vetoed(ctx->registry, lang, &res)) {
-- res = (cbm_resolution_t){0};
-- }
-- }
++ cbm_resolution_t res = calls_registry_resolution(
++ ctx, call, module_qn, imp_keys, imp_vals, imp_count, lang, rust_external, php_vendor_call);
/* `p->open(fd)`: the registry does not split a callee on the arrow, and a
* member is not a name it could resolve anyway. The object's type decides,
* exactly as for the dot call handled further down. MUST match
@@@ -926,8 -1018,48 +1173,12 @@@
* apps. Classify by callee suffix + path-shaped first arg, exactly
* like the parallel path's callee_suffix fallback; without this the
* sequential path minted zero Route nodes for such files. */
- return calls_emit_unresolved_service(ctx, call, source_node, module_qn, imp_keys, imp_vals,
- imp_count, route_mount, evidence);
- if (cbm_service_pattern_route_method(call->callee_name) != NULL && call->first_string_arg &&
- call->first_string_arg[0] == '/') {
- handle_route_registration(ctx, call, source_node, module_qn, imp_keys, imp_vals,
- imp_count, route_mount, lang);
++ if (calls_emit_unresolved_service(ctx, call, source_node, module_qn, imp_keys, imp_vals,
++ imp_count, route_mount, lang, evidence)) {
+ return SKIP_ONE;
+ }
- cbm_svc_kind_t esvc = cbm_service_pattern_match(call->callee_name);
- if (esvc == CBM_SVC_NONE && cbm_service_pattern_is_global_fetch(call->callee_name)) {
- esvc = CBM_SVC_HTTP;
- }
- if (esvc == CBM_SVC_HTTP || esvc == CBM_SVC_ASYNC) {
- const char *u = call->first_string_arg;
- bool has_url_or_topic = u && u[0] != '\0' &&
- (u[0] == '/' || strstr(u, "://") != NULL ||
- (esvc == CBM_SVC_ASYNC && strlen(u) > PAIR_LEN));
- if (has_url_or_topic) {
- cbm_resolution_t svc_res = {.qualified_name = call->callee_name,
- .confidence = PC_SVC_PATTERN_CONF,
- .strategy = "service_pattern",
- .candidate_count = 0};
- emit_http_async_edge(ctx, call, source_node, NULL, &svc_res, esvc, false);
- return SKIP_ONE;
- }
- }
- /* A callee an import binds to an external client library
- * (`send` under `from paho.mqtt import publish as send`): spelled
- * through its import, then classified. MUST match pass_parallel.c. */
- char spelled[CBM_SZ_512];
- cbm_svc_kind_t isvc =
- cbm_pipeline_external_import_service(ext_imports, ctx->gbuf, ctx->project_name, rel,
- lang, imports, call, spelled, sizeof(spelled));
- if (isvc != CBM_SVC_NONE) {
- CBMCall through = *call;
- through.callee_name = spelled;
- cbm_resolution_t imp_res = {.qualified_name = spelled,
- .confidence = PC_SVC_PATTERN_CONF,
- .strategy = "import_binding",
- .candidate_count = 0};
- emit_http_async_edge(ctx, &through, source_node, NULL, &imp_res, isvc, false);
- return SKIP_ONE;
- }
- return 0;
++ return calls_emit_import_service(ctx, call, source_node, rel, lang, imports, ext_imports,
++ evidence);
}
/* Perl call-graph noise guard (#476). Perl has no LSP resolver, so the
@@@ -1032,13 -1185,16 +1283,13 @@@
* unresolved-callee fallback above mints, and nothing else. Dropping
* the whole call lost every GET registration in a mixed-language repo
* while POST (no `post` to collide with) survived. */
- if (cbm_service_pattern_route_method(call->callee_name) != NULL && call->first_string_arg &&
- call->first_string_arg[0] == '/') {
- handle_route_registration(ctx, call, source_node, module_qn, imp_keys, imp_vals,
- imp_count, route_mount, lang);
- return SKIP_ONE;
- }
- return 0;
+ return calls_emit_route_call(ctx, call, source_node, module_qn, imp_keys, imp_vals,
- imp_count, route_mount, evidence);
++ imp_count, route_mount, lang, evidence);
}
- emit_classified_edge(ctx, call, source_node, target_node, &res, module_qn, imp_keys, imp_vals,
- imp_count, drop_plain_call, route_mount, lang);
+ evidence->candidate_qn = target_node->qualified_name;
+ evidence->calls_emitted |=
+ emit_classified_edge(ctx, call, source_node, target_node, &res, module_qn, imp_keys,
- imp_vals, imp_count, drop_plain_call, route_mount);
++ imp_vals, imp_count, drop_plain_call, route_mount, lang);
return SKIP_ONE;
}
@@@ -1224,16 -1379,16 +1478,19 @@@ int cbm_pipeline_pass_calls(cbm_pipelin
total_calls++;
if (resolve_single_call(ctx, call, result, rel, module_qn, imp_keys, imp_vals,
imp_count, files[i].language, &result->imports, route_mount,
- &php_vendor, &ext_imports)) {
++ &php_vendor, &ext_imports,
+ calls_evidence_at(evidence, c, &fallback))) {
resolved++;
} else {
unresolved++;
}
}
+ cbm_pipeline_external_import_index_free(&ext_imports);
+ cbm_pipeline_record_unresolved_calls(ctx->pipeline, rel, result, evidence);
+ cbm_free(CBM_MEM_CLASS_RESOLVE, evidence);
free(module_qn);
+ cbm_pipeline_php_vendor_names_free(&php_vendor);
free_import_map(imp_keys, imp_vals, imp_count);
if (result_owned) {
cbm_free_result(result);
diff --cc src/pipeline/pass_parallel.c
index 35af08481,2c0a9023a..eba665b0a
--- a/src/pipeline/pass_parallel.c
+++ b/src/pipeline/pass_parallel.c
@@@ -2255,8 -2280,13 +2280,14 @@@ void cbm_pipeline_close_call_props(cha
props[pos + SKIP_ONE] = '\0';
}
}
+ }
+
+ /* Build props JSON, append args, close brace, emit edge. */
-static void finalize_and_emit(cbm_gbuf_t *gbuf, int64_t src_id, int64_t tgt_id,
++static bool finalize_and_emit(cbm_gbuf_t *gbuf, int64_t src_id, int64_t tgt_id,
+ const char *edge_type, char *props, int n, const CBMCall *call) {
+ cbm_pipeline_close_call_props(props, n, call, strcmp(edge_type, "CALLS") == 0);
- cbm_gbuf_insert_edge(gbuf, src_id, tgt_id, edge_type, props);
+ return cbm_gbuf_insert_edge(gbuf, src_id, tgt_id, edge_type, props) > 0 &&
+ strcmp(edge_type, "CALLS") == 0;
}
/* Build Route node QN and properties for HTTP/async service edges. */
@@@ -2378,10 -2408,10 +2409,10 @@@ static bool emit_route_registration(cbm
snprintf(props, sizeof(props),
"{\"callee\":\"%s\",\"url_path\":\"%s\",\"via\":\"route_registration\"}", esc_cn,
esc_rp);
- cbm_gbuf_insert_edge(gbuf, source->id, rid, "CALLS", props);
+ bool emitted = cbm_gbuf_insert_edge(gbuf, source->id, rid, "CALLS", props) > 0;
if (handler_ref && handler_ref[0] != '\0') {
- cbm_resolution_t hres =
- cbm_registry_resolve_handler(registry, handler_ref, module_qn, ik, iv, ic, main_gbuf);
+ cbm_resolution_t hres = cbm_registry_resolve_handler(registry, handler_ref, module_qn, ik,
+ iv, ic, main_gbuf, lang);
if (hres.qualified_name && hres.qualified_name[0] != '\0') {
const cbm_gbuf_node_t *h = cbm_gbuf_find_by_qn(main_gbuf, hres.qualified_name);
if (h) {
@@@ -2704,9 -2767,10 +2769,9 @@@ static bool emit_service_edge(cbm_gbuf_
const char *handler_ref = NULL;
const char *route_path = find_route_path_in_args(call, &handler_ref);
if (route_path) {
- emit_route_registration(gbuf, source, call, route_path, handler_ref, module_qn,
- registry, main_gbuf, imp_keys, imp_vals, imp_count, route_mount,
- lang);
- return;
+ return emit_route_registration(gbuf, source, call, route_path, handler_ref, module_qn,
+ registry, main_gbuf, imp_keys, imp_vals, imp_count,
- route_mount);
++ route_mount, lang);
}
/* No path found — fall through to normal CALLS edge */
}
@@@ -2738,9 -2801,8 +2803,9 @@@
* __route__ANY__ twin of the typed edge, which cross-repo matching then
* bound to server handlers of any method. */
if (!http_edge_emitted) {
- detect_url_in_args(gbuf, source, call);
+ detect_url_in_args(gbuf, source, call, svc, pp_client_navigation_lang(lang));
}
+ return calls_emitted;
}
/* The #725 guard refuses a suffix_match binding across a language boundary,
@@@ -2757,9 -2819,9 +2822,9 @@@ static bool emit_xlang_refused_route(cb
const CBMCall *call, const char *module_qn,
const cbm_registry_t *registry, const cbm_gbuf_t *main_gbuf,
const char **imp_keys, const char **imp_vals, int imp_count,
- const char *route_mount) {
+ const char *route_mount, CBMLanguage lang) {
if (cbm_service_pattern_route_method(call->callee_name) == NULL) {
- return;
+ return false;
}
cbm_svc_kind_t svc = cbm_service_pattern_match(call->callee_name);
if (svc != CBM_SVC_NONE && svc != CBM_SVC_ROUTE_REG) {
@@@ -2768,11 -2830,9 +2833,11 @@@
const char *handler_ref = NULL;
const char *route_path = find_route_path_in_args(call, &handler_ref);
if (route_path) {
- emit_route_registration(gbuf, source, call, route_path, handler_ref, module_qn, registry,
- main_gbuf, imp_keys, imp_vals, imp_count, route_mount, lang);
+ return emit_route_registration(gbuf, source, call, route_path, handler_ref, module_qn,
+ registry, main_gbuf, imp_keys, imp_vals, imp_count,
- route_mount);
++ route_mount, lang);
}
+ return false;
}
/* Find the source node for an edge: enclosing function or file node. */
@@@ -3049,7 -3089,7 +3114,8 @@@ static CBMCallEvidence *resolve_evidenc
static void resolve_file_calls(resolve_ctx_t *rc, resolve_worker_state_t *ws, CBMFileResult *result,
const char *rel, const char *module_qn, const char **imp_keys,
const char **imp_vals, int imp_count, CBMLanguage lang,
- const cbm_php_vendor_names_t *php_vendor) {
++ const cbm_php_vendor_names_t *php_vendor,
+ CBMCallEvidence *evidence) {
/* Framework mount of this file's routes (Laravel 11+ withRouting, #1146). */
char route_mount[CBM_SZ_128];
cbm_laravel_file_route_mount(rc->repo_path, rel, lang, result, route_mount,
@@@ -3348,12 -3396,12 +3424,13 @@@
(cu[0] == '/' || strstr(cu, "://") != NULL ||
(csvc == CBM_SVC_ASYNC && strlen(cu) > PP_ESC_SPACE));
if (chas_url) {
- cbm_resolution_t svc_res = {.qualified_name = call->callee_name,
+ cbm_resolution_t svc_res = {.qualified_name = svc_name,
.confidence = PP_HALF_CONF,
.strategy = "service_pattern"};
- site_evidence->calls_emitted |= emit_service_edge(
- ws->local_edge_buf, source_node, source_node, call, &svc_res, module_qn,
- rc->registry, rc->main_gbuf, imp_keys, imp_vals, imp_count, false, route_mount);
- emit_service_edge(ws->local_edge_buf, source_node, source_node, call, &svc_res,
- module_qn, rc->registry, rc->main_gbuf, imp_keys, imp_vals,
- imp_count, false, route_mount, lang);
++ site_evidence->calls_emitted |=
++ emit_service_edge(ws->local_edge_buf, source_node, source_node, call, &svc_res,
++ module_qn, rc->registry, rc->main_gbuf, imp_keys, imp_vals,
++ imp_count, false, route_mount, lang);
continue;
}
}
@@@ -3378,9 -3426,9 +3455,10 @@@
* route path (`cache.get(key)`) would be a self-loop; that holds
* for #2053's LSP-external Rust calls too. Suppress it always;
* route/HTTP/service classification is unchanged. */
- site_evidence->calls_emitted |= emit_service_edge(
- ws->local_edge_buf, source_node, source_node, call, &fake_res, module_qn,
- rc->registry, rc->main_gbuf, imp_keys, imp_vals, imp_count, true, route_mount);
- emit_service_edge(ws->local_edge_buf, source_node, source_node, call, &fake_res,
- module_qn, rc->registry, rc->main_gbuf, imp_keys, imp_vals,
- imp_count, true, route_mount, lang);
++ site_evidence->calls_emitted |=
++ emit_service_edge(ws->local_edge_buf, source_node, source_node, call, &fake_res,
++ module_qn, rc->registry, rc->main_gbuf, imp_keys, imp_vals,
++ imp_count, true, route_mount, lang);
} else if (cbm_service_pattern_is_global_fetch(call->callee_name)) {
/* Native `fetch()` (#856): only the global API once resolution
* has failed to find a local/imported `fetch`. Call the low-level
@@@ -3440,9 -3506,9 +3536,9 @@@
/* #725: same guard as pass_calls.c — do not emit a suffix_match
* CALLS edge across a language boundary. A route registration
* behind the refused binding still gets its Route. */
- emit_xlang_refused_route(ws->local_edge_buf, source_node, call, module_qn, rc->registry,
- rc->main_gbuf, imp_keys, imp_vals, imp_count, route_mount,
- lang);
+ site_evidence->calls_emitted |= emit_xlang_refused_route(
+ ws->local_edge_buf, source_node, call, module_qn, rc->registry, rc->main_gbuf,
- imp_keys, imp_vals, imp_count, route_mount);
++ imp_keys, imp_vals, imp_count, route_mount, lang);
continue;
}
if (!target_node || source_node->id == target_node->id) {
@@@ -3458,19 -3524,18 +3554,19 @@@
(u[0] == '/' || strstr(u, "://") != NULL ||
(psvc == CBM_SVC_ASYNC && strlen(u) > PP_ESC_SPACE));
if (url_or_topic) {
- emit_service_edge(ws->local_edge_buf, source_node, NULL, call, &res, module_qn,
- rc->registry, rc->main_gbuf, imp_keys, imp_vals, imp_count,
- false, route_mount, lang);
+ site_evidence->calls_emitted |= emit_service_edge(
+ ws->local_edge_buf, source_node, NULL, call, &res, module_qn, rc->registry,
- rc->main_gbuf, imp_keys, imp_vals, imp_count, false, route_mount);
++ rc->main_gbuf, imp_keys, imp_vals, imp_count, false, route_mount, lang);
ws->calls_resolved++;
}
}
continue;
}
+ site_evidence->candidate_qn = target_node->qualified_name;
_rc_t0 = extract_now_ns();
- emit_service_edge(ws->local_edge_buf, source_node, target_node, call, &res, module_qn,
- rc->registry, rc->main_gbuf, imp_keys, imp_vals, imp_count,
- drop_plain_call, route_mount, lang);
+ site_evidence->calls_emitted |= emit_service_edge(
+ ws->local_edge_buf, source_node, target_node, call, &res, module_qn, rc->registry,
- rc->main_gbuf, imp_keys, imp_vals, imp_count, drop_plain_call, route_mount);
++ rc->main_gbuf, imp_keys, imp_vals, imp_count, drop_plain_call, route_mount, lang);
atomic_fetch_add_explicit(&rc->time_ns_rc_emit, extract_now_ns() - _rc_t0,
memory_order_relaxed);
ws->calls_resolved++;
@@@ -4276,7 -4354,7 +4403,7 @@@ static void resolve_worker(int worker_i
/* ── CALLS resolution ──────────────────────────────────── */
_ph_t0 = extract_now_ns();
resolve_file_calls(rc, ws, result, rel, module_qn, imp_keys, imp_vals, imp_count, lang,
- evidence);
- &php_vendor);
++ &php_vendor, evidence);
atomic_fetch_add_explicit(&rc->time_ns_calls, extract_now_ns() - _ph_t0,
memory_order_relaxed);
diff --cc src/pipeline/pipeline_incremental.c
index 33e1bba55,519dac749..e7c12e16d
--- a/src/pipeline/pipeline_incremental.c
+++ b/src/pipeline/pipeline_incremental.c
@@@ -31,9 -32,9 +32,10 @@@ enum { INCR_RING_BUF = 4, INCR_RING_MAS
#include "foundation/compat.h"
#include "foundation/compat_fs.h"
#include "foundation/compat_thread.h"
+ #include "foundation/limits.h" /* cbm_max_file_bytes */
#include "foundation/platform.h"
#include "foundation/sha256.h"
+#include "result_spill.h"
#include <ctype.h>
#include <errno.h>
@@@ -3295,6 -3743,62 +3780,60 @@@ static bool incr_doc_links_current(cbm_
return current;
}
+ /* The exact no-op test: the stored generation's metadata is current for this
+ * mode, its doc-link layer is usable, and its recorded semantic manifest
+ * equals the baseline byte for byte. Read-only. The two out flags report the
+ * halves the staged route also needs for its own routing. */
+ static bool incr_generation_exact(cbm_pipeline_t *p, cbm_store_t *store, const char *project,
+ const cbm_file_hash_t *stored, int stored_count,
+ const cbm_file_hash_t *baseline_manifest, int baseline_count,
+ bool *metadata_current_out, bool *doc_links_current_out) {
+ cbm_coverage_meta_t meta = {0};
+ int meta_rc = cbm_store_coverage_meta_get(store, project, &meta);
+ const char *mode_name = incr_mode_name(cbm_pipeline_get_mode(p));
- bool metadata_current =
- meta_rc == CBM_STORE_OK && meta.coverage_version == CBM_SEMANTIC_INDEX_VERSION &&
- meta.hash_records_complete && meta.index_mode && strcmp(meta.index_mode, mode_name) == 0;
++ bool metadata_current = incremental_metadata_current(meta_rc, &meta, mode_name);
+ /* A generation whose doc-link layer is missing or failed is not
+ * current even with identical inputs: index_status tells the user to
+ * re-run, and the re-run has to rebuild. */
+ bool doc_links_current = metadata_current && incr_doc_links_current(store, project);
+ bool exact = doc_links_current && cbm_pipeline_semantic_manifests_equal(
+ stored, stored_count, baseline_manifest, baseline_count);
+ cbm_store_coverage_meta_clear(&meta);
+ *metadata_current_out = metadata_current;
+ *doc_links_current_out = doc_links_current;
+ return exact;
+ }
+
+ bool cbm_pipeline_incremental_generation_exact(cbm_pipeline_t *p, cbm_store_t *store,
+ const cbm_file_hash_t *baseline_manifest,
+ int baseline_count) {
+ #if defined(CBM_INCREMENTAL_TEST_API) && CBM_INCREMENTAL_TEST_API
+ /* A forced legacy-partial run must reach the staged route that takes
+ * the one-shot flag; answering here would consume the run without it. */
+ if (atomic_load(&g_incr_test_force_legacy_partial)) {
+ return false;
+ }
+ #endif
+ const char *project = cbm_pipeline_project_name(p);
+ cbm_file_hash_t *stored = NULL;
+ int stored_count = 0;
+ if (!store ||
+ cbm_store_get_file_hashes(store, project, &stored, &stored_count) != CBM_STORE_OK) {
+ return false;
+ }
+ bool metadata_current = false;
+ bool doc_links_current = false;
+ bool exact = incr_generation_exact(p, store, project, stored, stored_count, baseline_manifest,
+ baseline_count, &metadata_current, &doc_links_current);
+ cbm_store_free_file_hashes(stored, stored_count);
+ #if defined(CBM_INCREMENTAL_TEST_API) && CBM_INCREMENTAL_TEST_API
+ if (exact) {
+ incr_test_set_last_route(CBM_INCREMENTAL_ROUTE_NOOP);
+ }
+ #endif
+ return exact;
+ }
+
int cbm_pipeline_run_incremental(cbm_pipeline_t *p, const char *db_path, cbm_file_info_t *files,
int file_count, const cbm_file_hash_t *baseline_manifest,
int baseline_count, bool force_full_on_mismatch) {
diff --cc src/pipeline/pipeline_internal.h
index 5e58410c7,a54dea245..b26d48124
--- a/src/pipeline/pipeline_internal.h
+++ b/src/pipeline/pipeline_internal.h
@@@ -1288,15 -1537,52 +1537,57 @@@ int cbm_pipeline_build_fresh_semantic_m
* diagrams are Diagram/DiagramElement nodes with DIAGRAM_ARROW edges;
* OpenAPI operations are Routes; a Markdown section's text keeps a
* diagram fence's labels instead of its syntax, and its candidates
- * carry the p of its diagrams' kind family.
- * 8: combine document links and TF-IDF with unresolved-call evidence
- * capture and its candidate index. This branch's earlier versions 5
- * and 6 lacked the document layers; upstream 7 lacked call capture.
- * 9: combine unresolved-call capture with the language documentation and
- * diagram layers above. This branch's version 8 predates those layers,
- * so unchanged files must rebuild once on upgrade.
+ * carry the p of its diagrams' kind family; a non-static file-scope
+ * C/C++/CUDA/ObjC function in a platform file or directory (foo_win.c,
+ * src/unix/) keeps its path QN and carries a `variant_key` property
+ * (its platform-neutral QN) that relates its platform variants.
+ * 8: a file and the directory beside it with one stem (`pkg/foo.sh`,
+ * `pkg/foo/`) no longer share a QN (cbm_stem_marks_t): the Folder is
+ * spelled `proj.pkg.foo/`, or, where the directory is a Java/Go package,
+ * the file's Module is `proj.pkg.foo#sh`. The Module the Folder used to
+ * swallow is a node again. An index built before holds neither, so it
+ * rebuilds once on upgrade.
+ * 9: a container's variable reaches its program: the EnvVar a container
+ * sets CONFIGURES {strategy:env_read} the readers of its name inside the
+ * files the container's image is built from (pass_envjoin.c); a K8s
+ * image reference says its container (USAGE {ref:image, container}) and
+ * a Dockerfile's Module its image's files (image_context, image_files,
+ * image_ignore). A workload or compose service CONNECTS_TO the Service
+ * its environment addresses (extract_k8s.c, pass_docker.c). A script's
+ * curl / wget HTTP_CALLS the Route of the URL it states (pass_shell.c).
+ * A kustomize patch OVERRIDEs the objects of its build it changes, its
+ * file an IMPORTS of the kustomization; a Resource keeps the version of
+ * its apiVersion and its labels; a kustomization DEPLOYS the charts it inflates
+ * (helmCharts); an object a namePrefix / nameSuffix renames has a
+ * variant Resource {ecosystem:kustomize} with its deployed name, which
+ * OVERRIDEs {via:namePrefix|nameSuffix} it (extract_k8s.c,
+ * pass_k8s.c). A Terraform reference
+ * USAGEs {ref, via:terraform}, from its block, the block of its module
+ * (directory) declaring it (one in depends_on: DEPENDS_ON), instead of
+ * the generic name matcher's USAGE / CALLS; a bare block label names
+ * its block like a quoted one; a module call with a local source
+ * IMPORTS its directory's Folder (the root: the Project) and module.X.Y
+ * USAGEs {ref:output} the output there; a .tfvars assignment OVERRIDEs
+ * {via:tfvars} the variable block of its own directory (or, inferred,
+ * of the nearest ancestor module declaring its names); a Terragrunt
+ * unit's include / read_terragrunt_config IMPORTS {via:terragrunt} the
+ * file it names, a dependency DEPENDS_ON the other unit; a
+ * kubernetes_* resource with a literal name is a Resource
+ * {ecosystem:terraform} its block DEPLOYS
+ * (pass_terraform.c, extract_unified.c, extract_defs.c); an Ansible
+ * playbook / task file IMPORTS {via:ansible} the playbooks, task files
+ * and roles its directives name, its tasks and handlers are Functions
+ * {source:ansible}, a notify CALLS {via:notify} the handlers it names,
+ * a kube / k8s task DEPLOYS {via:ansible} the template it applies
+ * (pass_ansible.c). An external Chart is keyed by its publisher URL.
+ * An index built before holds none of them, so it rebuilds once on
- * upgrade. */
-enum { CBM_SEMANTIC_INDEX_VERSION = 9 };
++ * upgrade.
++ * 10: combine the platform variants, stem disambiguation and infrastructure
++ * layers above with unresolved-call evidence capture and its candidate
++ * index. Both upstream version 9 and this branch's earlier version 9
++ * lack part of these semantics, so unchanged files rebuild once.
+ * The unresolved-call coverage threshold remains independent. */
- enum { CBM_SEMANTIC_INDEX_VERSION = 9 };
++enum { CBM_SEMANTIC_INDEX_VERSION = 10 };
typedef struct {
cbm_gbuf_t *gbuf;
diff --cc src/store/store.c
index 9c0f21c38,d19e52890..112624383
--- a/src/store/store.c
+++ b/src/store/store.c
@@@ -346,20 -423,34 +423,48 @@@ static int init_schema(cbm_store_t *s)
" detail TEXT DEFAULT '',"
" PRIMARY KEY (project, rel_path, kind)"
");"
+ "CREATE INDEX IF NOT EXISTS idx_index_coverage_project_kind "
+ "ON index_coverage(project, kind);"
+ /* Derived candidate lookup: inbound traces read only this index, not
+ * every file's diagnostic JSON. An empty candidate marks truncated or
+ * malformed evidence, whose omitted candidates cannot be ruled out. */
+ "CREATE TABLE IF NOT EXISTS index_unresolved_candidates ("
+ " project TEXT NOT NULL,"
+ " candidate TEXT NOT NULL,"
+ " rel_path TEXT NOT NULL,"
+ " kind TEXT NOT NULL DEFAULT 'unresolved_calls' CHECK(kind='unresolved_calls'),"
+ " PRIMARY KEY(project, candidate, rel_path),"
+ " FOREIGN KEY(project, rel_path, kind) "
+ " REFERENCES index_coverage(project, rel_path, kind) ON DELETE CASCADE"
+ ");"
+ /* Observed runtime calls (ingest_traces). Deliberately SEPARATE from
+ * the graph tables (like index_coverage) and keyed by QUALIFIED NAME,
+ * not node id: node ids are reassigned on every reindex, so id-keyed
+ * observation would silently rot — qualified names survive by
+ * construction and join at read time. One row per (caller, callee,
+ * run label); count accumulates across ingests of the same run. */
+ "CREATE TABLE IF NOT EXISTS observed_calls ("
+ " project TEXT NOT NULL REFERENCES projects(name) ON DELETE CASCADE,"
+ " caller_qn TEXT NOT NULL,"
+ " callee_qn TEXT NOT NULL,"
+ " label TEXT NOT NULL DEFAULT '',"
+ " count INTEGER NOT NULL DEFAULT 1,"
+ " first_seen TEXT NOT NULL,"
+ " last_seen TEXT NOT NULL,"
+ " PRIMARY KEY (project, caller_qn, callee_qn, label)"
+ ");"
+ /* Whole observed journeys, kept alongside the pair decomposition so
+ * the Flows view can show "this path actually ran", not only
+ * per-edge markers. path_json is the JSON array of qualified names. */
+ "CREATE TABLE IF NOT EXISTS observed_paths ("
+ " project TEXT NOT NULL REFERENCES projects(name) ON DELETE CASCADE,"
+ " label TEXT NOT NULL DEFAULT '',"
+ " path_json TEXT NOT NULL,"
+ " count INTEGER NOT NULL DEFAULT 1,"
+ " first_seen TEXT NOT NULL,"
+ " last_seen TEXT NOT NULL,"
+ " PRIMARY KEY (project, label, path_json)"
+ ");"
/* One row per completed coverage persistence attempt. Kept separate
* from projects so existing graph/artifact schema stays compatible and
* a missing row unambiguously means coverage metadata is unavailable. */
diff --cc tests/test_mcp.c
index fc8179e75,ebf24a827..fbc236c67
--- a/tests/test_mcp.c
+++ b/tests/test_mcp.c
@@@ -24145,8 -24559,273 +24949,274 @@@ TEST(search_code_drops_walker_hits_that
#endif
}
+ /* ── In-process search_code scan ───────────────────────────────────
+ * The scoped scan used to shell out to grep (POSIX) or Select-String
+ * (Windows) and now runs in process. These cases pin its records to the
+ * `grep -Hn` shape the subprocess wrote: path:line:content on POSIX, the
+ * same fields TAB-separated on Windows. */
+
+ #ifdef _WIN32
+ #define SCAN_FS "\t"
+ #define SCAN_RS '\n'
+ #else
+ #define SCAN_FS ":"
+ #define SCAN_RS '\0'
+ #endif
+
+ typedef struct {
+ char dir[256];
+ char list[512];
+ char out[512];
+ char files[4][512];
+ int count;
+ } scan_fixture_t;
+
+ static bool scan_fixture_open(scan_fixture_t *fx) {
+ memset(fx, 0, sizeof(*fx));
+ const char *tmp = th_mktempdir("cbm_scan");
+ if (!tmp) {
+ return false;
+ }
+ snprintf(fx->dir, sizeof(fx->dir), "%s", tmp);
+ snprintf(fx->list, sizeof(fx->list), "%s/list", tmp);
+ snprintf(fx->out, sizeof(fx->out), "%s/out", tmp);
+ return true;
+ }
+
+ /* Add a file holding exactly `length` bytes (NUL bytes allowed). */
+ static bool scan_fixture_add(scan_fixture_t *fx, const char *name, const char *data,
+ size_t length) {
+ if (fx->count >= 4) {
+ return false;
+ }
+ /* Format from a copy: GCC's -Werror=restrict rejects a source and a
+ * destination inside the same struct. */
+ char dir[sizeof(fx->dir)];
+ memcpy(dir, fx->dir, sizeof(dir));
+ char *path = fx->files[fx->count];
+ snprintf(path, sizeof(fx->files[0]), "%s/%s", dir, name);
+ FILE *fp = cbm_fopen(path, "wb");
+ if (!fp) {
+ return false;
+ }
+ bool ok = fwrite(data, 1, length, fp) == length;
+ ok = fclose(fp) == 0 && ok;
+ fx->count += ok ? 1 : 0;
+ return ok;
+ }
+
+ /* Write the scoped file list as search_code does (NUL records on POSIX,
+ * lines on Windows); `extra` names one more path that need not exist. */
+ static bool scan_fixture_list(const scan_fixture_t *fx, const char *extra) {
+ FILE *fp = cbm_fopen(fx->list, "wb");
+ if (!fp) {
+ return false;
+ }
+ bool ok = true;
+ for (int i = 0; i < fx->count; i++) {
+ ok = ok && fputs(fx->files[i], fp) != EOF && fputc(SCAN_RS, fp) != EOF;
+ }
+ if (extra) {
+ ok = ok && fputs(extra, fp) != EOF && fputc(SCAN_RS, fp) != EOF;
+ }
+ return fclose(fp) == 0 && ok;
+ }
+
+ /* Run the scan; returns the records it wrote (caller frees), CRs kept. */
+ static char *scan_fixture_run(const scan_fixture_t *fx, const char *pattern, bool use_regex,
+ size_t output_limit, int *cause) {
+ *cause = cbm_mcp_search_scan_for_test(NULL, fx->list, pattern, use_regex, fx->out,
+ output_limit, UINT64_MAX);
+ FILE *fp = cbm_fopen(fx->out, "rb");
+ if (!fp) {
+ return NULL;
+ }
+ char *text = calloc(CBM_SZ_64K, 1);
+ size_t length = text ? fread(text, 1, CBM_SZ_64K - 1, fp) : 0;
+ (void)fclose(fp);
+ if (text) {
+ text[length] = '\0';
+ }
+ return text;
+ }
+
+ /* Append one expected record to `buf`. */
+ static void scan_expect(char *buf, size_t cap, const char *path, int line, const char *content) {
+ size_t used = strlen(buf);
+ snprintf(buf + used, cap - used, "%s" SCAN_FS "%d" SCAN_FS "%s\n", path, line, content);
+ }
+
+ TEST(search_code_scan_in_process_writes_grep_records) {
+ scan_fixture_t fx;
+ ASSERT_TRUE(scan_fixture_open(&fx));
+ /* The last line has no newline and line 3 is empty. */
+ static const char a[] = "alpha\nbeta gamma\n\nalpha beta\nlast alpha";
+ static const char b[] = "nothing\nalpha\n";
+ ASSERT_TRUE(scan_fixture_add(&fx, "a.txt", a, sizeof(a) - 1));
+ ASSERT_TRUE(scan_fixture_add(&fx, "b.txt", b, sizeof(b) - 1));
+ ASSERT_TRUE(scan_fixture_list(&fx, NULL));
+ const char *pa = fx.files[0];
+ const char *pb = fx.files[1];
+ char want[4096];
+ int cause = -1;
+
+ /* Literal: every matching line, file order, then line order. */
+ want[0] = '\0';
+ scan_expect(want, sizeof(want), pa, 1, "alpha");
+ scan_expect(want, sizeof(want), pa, 4, "alpha beta");
+ scan_expect(want, sizeof(want), pa, 5, "last alpha");
+ scan_expect(want, sizeof(want), pb, 2, "alpha");
+ char *got = scan_fixture_run(&fx, "alpha", false, 0, &cause);
+ ASSERT_NOT_NULL(got);
+ ASSERT_EQ(cause, 0);
+ ASSERT_STR_EQ(got, want);
+ free(got);
+
+ /* A multi-line pattern is one pattern per line, as with grep -f. */
+ want[0] = '\0';
+ scan_expect(want, sizeof(want), pa, 2, "beta gamma");
+ scan_expect(want, sizeof(want), pa, 4, "alpha beta");
+ got = scan_fixture_run(&fx, "gamma\nbeta", false, 0, &cause);
+ ASSERT_NOT_NULL(got);
+ ASSERT_EQ(cause, 0);
+ ASSERT_STR_EQ(got, want);
+ free(got);
+
+ /* An empty pattern matches every line, the empty one included. */
+ want[0] = '\0';
+ scan_expect(want, sizeof(want), pa, 1, "alpha");
+ scan_expect(want, sizeof(want), pa, 2, "beta gamma");
+ scan_expect(want, sizeof(want), pa, 3, "");
+ scan_expect(want, sizeof(want), pa, 4, "alpha beta");
+ scan_expect(want, sizeof(want), pa, 5, "last alpha");
+ scan_expect(want, sizeof(want), pb, 1, "nothing");
+ scan_expect(want, sizeof(want), pb, 2, "alpha");
+ got = scan_fixture_run(&fx, "", false, 0, &cause);
+ ASSERT_NOT_NULL(got);
+ ASSERT_EQ(cause, 0);
+ ASSERT_STR_EQ(got, want);
+ free(got);
+
+ /* Extended regex, anchored per line. */
+ want[0] = '\0';
+ scan_expect(want, sizeof(want), pa, 1, "alpha");
+ scan_expect(want, sizeof(want), pa, 4, "alpha beta");
+ scan_expect(want, sizeof(want), pa, 5, "last alpha");
+ scan_expect(want, sizeof(want), pb, 2, "alpha");
+ got = scan_fixture_run(&fx, "^(alpha|last)", true, 0, &cause);
+ ASSERT_NOT_NULL(got);
+ ASSERT_EQ(cause, 0);
+ ASSERT_STR_EQ(got, want);
+ free(got);
+
+ /* No match: success with no records. */
+ got = scan_fixture_run(&fx, "zzqqxx", false, 0, &cause);
+ ASSERT_NOT_NULL(got);
+ ASSERT_EQ(cause, 0);
+ ASSERT_STR_EQ(got, "");
+ free(got);
+ th_rmtree(fx.dir);
+ PASS();
+ }
+
+ TEST(search_code_scan_in_process_binary_and_crlf) {
+ scan_fixture_t fx;
+ ASSERT_TRUE(scan_fixture_open(&fx));
+ /* A NUL in the first 32 KiB marks the whole file binary: no records. */
+ static const char bin[] = "alpha\n\0alpha\n";
+ ASSERT_TRUE(scan_fixture_add(&fx, "bin.dat", bin, sizeof(bin) - 1));
+ /* A later NUL ends the text at the last complete line before it. */
+ enum { FILLER_LINES = 4000 }; /* 10 bytes each: past the 32 KiB probe */
+ size_t late_cap = (size_t)FILLER_LINES * 10 + 64;
+ char *late = malloc(late_cap);
+ ASSERT_NOT_NULL(late);
+ size_t used = 0;
+ for (int i = 0; i < FILLER_LINES; i++) {
+ memcpy(late + used, "xxxxxxxxx\n", 10);
+ used += 10;
+ }
+ static const char tail[] = "alpha one\nalpha two\0\nalpha three\n";
+ memcpy(late + used, tail, sizeof(tail) - 1);
+ used += sizeof(tail) - 1;
+ ASSERT_TRUE(scan_fixture_add(&fx, "late.txt", late, used));
+ free(late);
+ static const char crlf[] = "alpha\r\nbeta\r\n";
+ ASSERT_TRUE(scan_fixture_add(&fx, "crlf.txt", crlf, sizeof(crlf) - 1));
+ ASSERT_TRUE(scan_fixture_list(&fx, NULL));
+ char want[4096];
+ int cause = -1;
+
+ /* The record keeps the line's CR; the result parser trims it. */
+ want[0] = '\0';
+ scan_expect(want, sizeof(want), fx.files[1], FILLER_LINES + 1, "alpha one");
+ scan_expect(want, sizeof(want), fx.files[2], 1, "alpha\r");
+ char *got = scan_fixture_run(&fx, "alpha", false, 0, &cause);
+ ASSERT_NOT_NULL(got);
+ ASSERT_EQ(cause, 0);
+ ASSERT_STR_EQ(got, want);
+ free(got);
+
+ /* `$` before a CR: grep on POSIX sees the CR and does not match;
+ * Select-String's Line on Windows had no CR and did. */
+ want[0] = '\0';
+ #ifdef _WIN32
+ scan_expect(want, sizeof(want), fx.files[2], 2, "beta\r");
+ #endif
+ got = scan_fixture_run(&fx, "^beta$", true, 0, &cause);
+ ASSERT_NOT_NULL(got);
+ ASSERT_EQ(cause, 0);
+ ASSERT_STR_EQ(got, want);
+ free(got);
+ th_rmtree(fx.dir);
+ PASS();
+ }
+
+ TEST(search_code_scan_in_process_limits_and_failures) {
+ scan_fixture_t fx;
+ ASSERT_TRUE(scan_fixture_open(&fx));
+ static const char a[] = "alpha\nalpha\nalpha\n";
+ ASSERT_TRUE(scan_fixture_add(&fx, "a.txt", a, sizeof(a) - 1));
+ ASSERT_TRUE(scan_fixture_list(&fx, NULL));
+ int cause = -1;
+
+ /* Past the output limit: the output-limit cause (3), not a failure. */
+ char *got = scan_fixture_run(&fx, "alpha", false, 8, &cause);
+ free(got);
+ ASSERT_EQ(cause, 3);
+
+ /* An invalid regex is a command failure (1), as grep's exit 2 was. */
+ got = scan_fixture_run(&fx, "(", true, 0, &cause);
+ free(got);
+ ASSERT_EQ(cause, 1);
+
+ /* A passed deadline stops the scan before the next file (4); a request
+ * cancelled under the server stops it too, and takes precedence (5). */
+ ASSERT_EQ(cbm_mcp_search_scan_for_test(NULL, fx.list, "alpha", false, fx.out, 0, 0), 4);
+ cbm_mcp_server_t *srv = cbm_mcp_server_new(NULL);
+ ASSERT_NOT_NULL(srv);
+ ASSERT_TRUE(cbm_mcp_server_request_scope_begin(srv));
+ ASSERT_TRUE(cbm_mcp_server_cancel_active(srv));
+ cause = cbm_mcp_search_scan_for_test(srv, fx.list, "alpha", false, fx.out, 0, 0);
+ cbm_mcp_server_request_scope_end(srv);
+ cbm_mcp_server_free(srv);
+ ASSERT_EQ(cause, 5);
+
+ /* A listed file that cannot be read is a command failure (1) as well. */
+ char missing[600];
+ snprintf(missing, sizeof(missing), "%s/missing.txt", fx.dir);
+ ASSERT_TRUE(scan_fixture_list(&fx, missing));
+ got = scan_fixture_run(&fx, "alpha", false, 0, &cause);
+ free(got);
+ ASSERT_EQ(cause, 1);
+ th_rmtree(fx.dir);
+ PASS();
+ }
+
+ #undef SCAN_FS
+ #undef SCAN_RS
+
SUITE(mcp) {
+ RUN_TEST(tool_check_index_coverage_parse_gap_precedes_unresolved_calls);
RUN_TEST(index_repository_async_and_status_refused_without_daemon_issue2144);
RUN_TEST(index_repository_schema_documents_async_polling_issue2144);
RUN_TEST(tool_result_add_notice_keeps_payload_shape_issue2144);