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.

fix: 17 reproduce-first issue + new-bug fixes (per-case verified)

Martin Vogel3f754cf449f9
diff --git a/internal/cbm/extract_defs.c b/internal/cbm/extract_defs.c
index 5b6917719..dfca3b4c4 100644
--- a/internal/cbm/extract_defs.c
+++ b/internal/cbm/extract_defs.c
@@ -465,7 +465,7 @@ static TSNode resolve_func_name_fp(TSNode node, CBMLanguage lang, const char *ki
// or NULL when the declarator is unqualified (a plain free function). Without
// this, an out-of-line definition — whose class body lives declaration-only in a
// header — would be recorded as a free Function with no link to its class.
-static char *cpp_out_of_line_parent_class(CBMArena *a, TSNode node, const char *source) {
+char *cbm_cpp_out_of_line_parent_class(CBMArena *a, TSNode node, const char *source) {
// Descend the declarator chain to its qualified_identifier, if any.
TSNode qid = {0};
TSNode decl = ts_node_child_by_field_name(node, TS_FIELD("declarator"));
@@ -608,9 +608,17 @@ static TSNode resolve_toplevel_arrow_name(TSNode node, const char *kind) {
return null_node;
}
const char *pk = ts_node_type(parent);
- if (strcmp(pk, "variable_declarator") == 0) {
+ if (strcmp(pk, "variable_declarator") == 0 ||
+ strcmp(pk, "public_field_definition") == 0) {
+ /* `const f = () => {}` and the class-field form `f = () => {}` both name
+ * the arrow via the parent's `name` child (#new_ts_class_field_arrow):
+ * resolving it lets push_boundary_scopes push a SCOPE_FUNC so in-body
+ * calls source to the method, not the enclosing class/module. */
return ts_node_child_by_field_name(parent, TS_FIELD("name"));
}
+ if (strcmp(pk, "field_definition") == 0) {
+ return ts_node_child_by_field_name(parent, TS_FIELD("property"));
+ }
if (strcmp(pk, "pair") == 0) {
return ts_node_child_by_field_name(parent, TS_FIELD("key"));
}
@@ -1644,6 +1652,38 @@ static const char **extract_decorators(CBMArena *a, TSNode node, const char *sou
return result;
}
+/* Rust: two same-named functions guarded by mutually-exclusive #[cfg(...)]
+ * attributes both parse as distinct function_item nodes and otherwise receive
+ * the SAME qualified_name, so the second graph upsert silently overwrites the
+ * first and one branch is lost (#495). Fold the cfg predicate into the QN so
+ * each cfg-gated twin gets a DISTINCT, predicate-encoding QN. Returns the
+ * (possibly suffixed) QN; the original QN when no cfg attribute is present. */
+static const char *rust_cfg_qualified_name(CBMArena *a, const char *base_qn,
+ const char *const *decorators) {
+ if (!decorators) {
+ return base_qn;
+ }
+ for (int i = 0; decorators[i]; i++) {
+ const char *cfg = strstr(decorators[i], "cfg(");
+ if (!cfg) {
+ continue;
+ }
+ /* Build a compact predicate suffix from the cfg(...) text, dropping
+ * whitespace and quotes so the QN stays readable and stable. */
+ char buf[CBM_SZ_256];
+ size_t bi = 0;
+ for (const char *p = cfg; *p && bi + 1 < sizeof(buf); p++) {
+ if (*p == ' ' || *p == '\t' || *p == '"' || *p == '\'') {
+ continue;
+ }
+ buf[bi++] = *p;
+ }
+ buf[bi] = '\0';
+ return cbm_arena_sprintf(a, "%s#%s", base_qn, buf);
+ }
+ return base_qn;
+}
+
// Extract base class name text from a single base_class child node.
static char *extract_cpp_base_text(CBMArena *a, TSNode bc, const char *source) {
const char *bk = ts_node_type(bc);
@@ -2883,7 +2923,7 @@ static void extract_func_def(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec
// class node QN computed the same way) so DEFINES_METHOD edges resolve.
if ((ctx->language == CBM_LANG_CPP || ctx->language == CBM_LANG_CUDA) &&
strcmp(ts_node_type(node), "function_definition") == 0) {
- char *scope_name = cpp_out_of_line_parent_class(a, node, ctx->source);
+ char *scope_name = cbm_cpp_out_of_line_parent_class(a, node, ctx->source);
if (scope_name && scope_name[0]) {
const char *class_qn = cbm_fqn_compute(a, ctx->project, ctx->rel_path, scope_name);
def.qualified_name = cbm_arena_sprintf(a, "%s.%s", class_qn, name);
@@ -2918,6 +2958,12 @@ static void extract_func_def(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec
def.decorators = extract_decorators(a, node, ctx->source, ctx->language, spec);
extract_route_from_decorators(a, node, ctx->source, spec, &def.route_path, &def.route_method);
+ // Rust: disambiguate cfg-gated twin functions by folding the #[cfg(...)]
+ // predicate into the QN so both branches survive the graph upsert (#495).
+ if (ctx->language == CBM_LANG_RUST) {
+ def.qualified_name = rust_cfg_qualified_name(a, def.qualified_name, def.decorators);
+ }
+
// Docstring
def.docstring = extract_docstring(a, node, ctx->source, ctx->language);
@@ -3868,6 +3914,24 @@ static void extract_class_methods(CBMExtractCtx *ctx, TSNode class_node, const c
method_node = def;
}
+ // TS/JS class-field arrow functions: `handleClick = () => {...}` is a
+ // public_field_definition whose `value` is an arrow_function (a common
+ // React event-handler pattern). It is not in function_node_types, so it
+ // would otherwise be dropped. Peek through to the inner arrow and take
+ // the method name from the field's `name` child (#new_ts_class_field_arrow).
+ if (strcmp(ts_node_type(child), "public_field_definition") == 0) {
+ TSNode value = ts_node_child_by_field_name(child, TS_FIELD("value"));
+ if (ts_node_is_null(value) || !cbm_kind_in_set(value, spec->function_node_types)) {
+ continue;
+ }
+ TSNode fname = ts_node_child_by_field_name(child, TS_FIELD("name"));
+ if (ts_node_is_null(fname)) {
+ continue;
+ }
+ push_method_def(ctx, value, class_qn, spec, fname);
+ continue;
+ }
+
if (!cbm_kind_in_set(method_node, spec->function_node_types)) {
continue;
}
@@ -4318,8 +4382,23 @@ static void extract_vars_mainstream(CBMExtractCtx *ctx, TSNode node, CBMArena *a
switch (ctx->language) {
case CBM_LANG_PYTHON: {
TSNode left = ts_node_child_by_field_name(node, TS_FIELD("left"));
- if (!ts_node_is_null(left) && strcmp(ts_node_type(left), "identifier") == 0) {
+ if (ts_node_is_null(left)) {
+ break;
+ }
+ const char *lt = ts_node_type(left);
+ if (strcmp(lt, "identifier") == 0) {
push_var_def(ctx, cbm_node_text(a, left, ctx->source), node);
+ } else if (strcmp(lt, "pattern_list") == 0 || strcmp(lt, "tuple_pattern") == 0 ||
+ strcmp(lt, "list_pattern") == 0) {
+ /* Tuple/list unpacking: `x, y = f()` — emit a Variable def for each
+ * unpacked identifier on the LHS (#new_py_tuple_unpack). */
+ uint32_t ln = ts_node_named_child_count(left);
+ for (uint32_t li = 0; li < ln; li++) {
+ TSNode part = ts_node_named_child(left, li);
+ if (strcmp(ts_node_type(part), "identifier") == 0) {
+ push_var_def(ctx, cbm_node_text(a, part, ctx->source), node);
+ }
+ }
}
break;
}
diff --git a/internal/cbm/extract_unified.c b/internal/cbm/extract_unified.c
index ba5e65149..f791da59a 100644
--- a/internal/cbm/extract_unified.c
+++ b/internal/cbm/extract_unified.c
@@ -308,6 +308,22 @@ static const char *compute_func_qn(CBMExtractCtx *ctx, TSNode node, const CBMLan
return NULL;
}
+ /* C++/CUDA out-of-line method `void Foo::bar() {...}`: the def extractor
+ * records this as Method "proj.file.Foo.bar". The call-scope QN must match
+ * (be class-qualified) so an in-body call sources to the method, not a bare
+ * "proj.file.bar" that no node carries (#554/#621). The out-of-line def is at
+ * file scope, so enclosing_class_qn is NULL — derive the class from the
+ * qualified declarator instead. */
+ if ((ctx->language == CBM_LANG_CPP || ctx->language == CBM_LANG_CUDA) &&
+ strcmp(ts_node_type(node), "function_definition") == 0) {
+ char *scope_name = cbm_cpp_out_of_line_parent_class(ctx->arena, node, ctx->source);
+ if (scope_name && scope_name[0]) {
+ const char *class_qn =
+ cbm_fqn_compute(ctx->arena, ctx->project, ctx->rel_path, scope_name);
+ return cbm_arena_sprintf(ctx->arena, "%s.%s", class_qn, name);
+ }
+ }
+
if (state->enclosing_class_qn) {
return cbm_arena_sprintf(ctx->arena, "%s.%s", state->enclosing_class_qn, name);
}
diff --git a/internal/cbm/helpers.h b/internal/cbm/helpers.h
index caa8e9097..fe22b50d8 100644
--- a/internal/cbm/helpers.h
+++ b/internal/cbm/helpers.h
@@ -59,6 +59,13 @@ TSNode cbm_resolve_c_declarator_name_node(TSNode func_node);
// gap #3 (and #438 for the C-declarator case).
TSNode cbm_resolve_func_name(TSNode node, CBMLanguage lang);
+// C++/CUDA out-of-line method definition (`void Foo::bar() {...}`): return the
+// immediate enclosing class name ("Foo") from the qualified declarator, or NULL
+// for a plain free function. Defined in extract_defs.c. Shared so the unified
+// (call-scope) extractor computes the SAME class-qualified enclosing QN as the
+// def extractor — drift dropped the class qualifier from in-body calls (#554/#621).
+char *cbm_cpp_out_of_line_parent_class(CBMArena *a, TSNode node, const char *source);
+
// Find a child node by kind string.
TSNode cbm_find_child_by_kind(TSNode parent, const char *kind);
diff --git a/src/cli/cli.c b/src/cli/cli.c
index f159f5914..d15472335 100644
--- a/src/cli/cli.c
+++ b/src/cli/cli.c
@@ -3120,11 +3120,24 @@ static void install_cli_agent_configs(const cbm_detected_agents_t *agents, const
snprintf(ip, sizeof(ip), "%s/.codex/AGENTS.md", home);
install_generic_agent_config("Codex CLI", binary_path, cp, ip, dry_run,
cbm_upsert_codex_mcp);
+ /* Choose the hook target: if ~/.codex/hooks.json already exists, the
+ * user manages Codex hooks via the JSON representation — write the
+ * SessionStart reminder there instead of config.toml. Writing both
+ * makes Codex warn about loading hooks from two representations (#570).
+ * config.toml remains the mcp_config target above either way. */
+ char hooks_json[CLI_BUF_1K];
+ snprintf(hooks_json, sizeof(hooks_json), "%s/.codex/hooks.json", home);
+ bool use_hooks_json = cbm_file_exists(hooks_json);
+ const char *hook_target = use_hooks_json ? hooks_json : cp;
if (g_install_plan) {
- plan_record("Codex CLI", "hook", cp);
+ plan_record("Codex CLI", "hook", hook_target);
} else {
if (!dry_run) {
- cbm_upsert_codex_hooks(cp);
+ if (use_hooks_json) {
+ cbm_upsert_gemini_session_hooks(hooks_json);
+ } else {
+ cbm_upsert_codex_hooks(cp);
+ }
}
printf(" hooks: SessionStart (codebase-memory-mcp reminder)\n");
}
@@ -3183,6 +3196,36 @@ static void install_cli_agent_configs(const cbm_detected_agents_t *agents, const
}
}
+/* Scan Code/User/profiles/ and install (or plan) a per-profile mcp.json for
+ * each existing profile subdirectory, so VS Code profile users inherit the MCP
+ * server without manual steps (#431). No-op when profiles/ is absent. */
+static void install_vscode_profile_configs(const char *code_user, const char *binary_path,
+ bool dry_run) {
+ char profiles_dir[CLI_BUF_1K];
+ snprintf(profiles_dir, sizeof(profiles_dir), "%s/profiles", code_user);
+ cbm_dir_t *d = cbm_opendir(profiles_dir);
+ if (!d) {
+ return;
+ }
+ cbm_dirent_t *ent;
+ while ((ent = cbm_readdir(d)) != NULL) {
+ if (strcmp(ent->name, ".") == 0 || strcmp(ent->name, "..") == 0) {
+ continue;
+ }
+ char profile_path[CLI_BUF_1K];
+ snprintf(profile_path, sizeof(profile_path), "%s/%s", profiles_dir, ent->name);
+ struct stat st;
+ if (stat(profile_path, &st) != 0 || !S_ISDIR(st.st_mode)) {
+ continue;
+ }
+ char cp[CLI_BUF_1K];
+ snprintf(cp, sizeof(cp), "%s/mcp.json", profile_path);
+ install_generic_agent_config("VS Code", binary_path, cp, NULL, dry_run,
+ cbm_install_vscode_mcp);
+ }
+ cbm_closedir(d);
+}
+
/* Install MCP configs for editor-based agents (Zed, KiloCode, VS Code, OpenClaw). */
static void install_editor_agent_configs(const cbm_detected_agents_t *agents, const char *home,
const char *binary_path, bool dry_run) {
@@ -3215,14 +3258,21 @@ static void install_editor_agent_configs(const cbm_detected_agents_t *agents, co
cbm_install_editor_mcp);
}
if (agents->vscode) {
- char cp[CLI_BUF_1K];
+ char code_user[CLI_BUF_1K];
#ifdef __APPLE__
- snprintf(cp, sizeof(cp), "%s/Library/Application Support/Code/User/mcp.json", home);
+ snprintf(code_user, sizeof(code_user), "%s/Library/Application Support/Code/User", home);
#else
- snprintf(cp, sizeof(cp), "%s/Code/User/mcp.json", cbm_app_config_dir());
+ snprintf(code_user, sizeof(code_user), "%s/Code/User", cbm_app_config_dir());
#endif
+ char cp[CLI_BUF_1K];
+ snprintf(cp, sizeof(cp), "%s/mcp.json", code_user);
install_generic_agent_config("VS Code", binary_path, cp, NULL, dry_run,
cbm_install_vscode_mcp);
+ /* VS Code profiles each keep their own settings under
+ * Code/User/profiles/<id>/. The default mcp.json above does NOT apply
+ * to a named profile, so write/plan a per-profile mcp.json for every
+ * existing profile directory (#431). */
+ install_vscode_profile_configs(code_user, binary_path, dry_run);
}
if (agents->cursor) {
char cp[CLI_BUF_1K];
diff --git a/src/cypher/cypher.c b/src/cypher/cypher.c
index be3df4573..907e9c084 100644
--- a/src/cypher/cypher.c
+++ b/src/cypher/cypher.c
@@ -2845,8 +2845,18 @@ static void process_edges(cbm_store_t *store, cbm_edge_t *edges, int edge_count,
const cbm_node_pattern_t *target_node, binding_t *b, const char *to_var,
const char *rel_var, binding_t *new_bindings, int *new_count, int max_new,
int *match_count) {
+ /* When the terminal node variable is ALREADY bound (e.g. the second pattern
+ * `(c)-[:CALLS]->(f)` where `f` came from an earlier MATCH), we must FILTER
+ * to edges that actually reach the bound node — not overwrite the caller's
+ * `f` binding with whatever node the edge leads to. Overwriting corrupted
+ * the result of dead-code queries and produced wrong rows (#627). */
+ cbm_node_t *bound_to = binding_get(b, to_var);
+ int64_t bound_to_id = bound_to ? bound_to->id : 0;
for (int ei = 0; ei < edge_count && *new_count < max_new; ei++) {
int64_t tid = inbound ? edges[ei].source_id : edges[ei].target_id;
+ if (bound_to && tid != bound_to_id) {
+ continue; /* edge does not reach the already-bound terminal node */
+ }
cbm_node_t found = {0};
if (cbm_store_find_node_by_id(store, tid, &found) != CBM_STORE_OK) {
continue;
@@ -2967,8 +2977,11 @@ static void expand_pattern_rels(cbm_store_t *store, cbm_pattern_t *pat, binding_
bool is_variable_length = (rel->min_hops != SKIP_ONE || rel->max_hops != SKIP_ONE);
- binding_t *new_bindings =
- malloc(((*bind_cap * CYP_GROWTH_10) + SKIP_ONE) * sizeof(binding_t));
+ size_t alloc_n = (size_t)*bind_cap * (size_t)CYP_GROWTH_10 + SKIP_ONE;
+ binding_t *new_bindings = malloc(alloc_n * sizeof(binding_t));
+ if (!new_bindings) {
+ return; /* OOM: leave existing bindings untouched rather than corrupt */
+ }
int new_count = 0;
for (int bi = 0; bi < *bind_count; bi++) {
@@ -4165,8 +4178,15 @@ static void cross_join_nodes(binding_t **bindings, int *bind_count, cbm_node_t *
static void cross_join_with_rels(cbm_store_t *store, cbm_pattern_t *patn, binding_t **bindings,
int *bind_count, cbm_node_t *extra_nodes, int extra_count,
const char *nvar, bool opt) {
- binding_t *new_bindings =
- malloc(((*bind_count * extra_count * CYP_GROWTH_10) + SKIP_ONE) * sizeof(binding_t));
+ /* size_t arithmetic: bind_count * extra_count can exceed INT_MAX on large
+ * graphs (e.g. an unbound `c` scanned against ~29 K `f` bindings), wrapping
+ * the int product negative and yielding a tiny/garbage malloc → heap OOB
+ * write → SIGSEGV/SIGABRT (#627). */
+ size_t alloc_n = (size_t)*bind_count * (size_t)extra_count * (size_t)CYP_GROWTH_10 + SKIP_ONE;
+ binding_t *new_bindings = malloc(alloc_n * sizeof(binding_t));
+ if (!new_bindings) {
+ return; /* OOM: leave existing bindings untouched rather than corrupt */
+ }
int new_count = 0;
for (int bi = 0; bi < *bind_count; bi++) {
for (int ni = 0; ni < extra_count; ni++) {
@@ -4198,6 +4218,95 @@ static void cross_join_with_rels(cbm_store_t *store, cbm_pattern_t *patn, bindin
*bind_count = new_count;
}
+/* Drive a single-relationship additional pattern from its ALREADY-BOUND
+ * terminal node, binding the unbound START var to the edge's other endpoint.
+ *
+ * Handles `OPTIONAL MATCH (c)-[:CALLS]->(f)` where `f` is bound from an earlier
+ * MATCH and `c` is new: scanning every node for `c` and cross-joining (a) risks
+ * an int-overflow OOB write on large graphs and (b) leaves `c` bound to an
+ * arbitrary node so a later `WHERE c IS NULL` wrongly drops every row (#627).
+ * Instead we scan only the bound terminal's edges and bind `c` to real
+ * neighbours; with OPTIONAL we keep the row with `c` unbound when there are
+ * none — the correct dead-code semantics. */
+static void expand_from_bound_terminal(cbm_store_t *store, cbm_pattern_t *patn, binding_t **bindings,
+ int *bind_count, const char *start_var, bool opt) {
+ cbm_rel_pattern_t *rel = &patn->rels[0];
+ const cbm_node_pattern_t *start_node = &patn->nodes[0];
+ /* The relationship is written start-[r]->terminal. To enumerate the start
+ * nodes reachable from the bound terminal we invert the stored direction. */
+ bool rel_inbound = rel->direction && strcmp(rel->direction, "inbound") == 0;
+ bool scan_targets = !rel_inbound; /* (start)->(term): start = edge source = scan term's inbound */
+
+ size_t alloc_n = (size_t)*bind_count * (size_t)CYP_GROWTH_10 + SKIP_ONE;
+ binding_t *new_bindings = malloc(alloc_n * sizeof(binding_t));
+ if (!new_bindings) {
+ return;
+ }
+ int new_count = 0;
+ int max_new = (int)alloc_n;
+
+ for (int bi = 0; bi < *bind_count && new_count < max_new; bi++) {
+ binding_t *b = &(*bindings)[bi];
+ cbm_node_t *term = binding_get(b, patn->nodes[1].variable ? patn->nodes[1].variable : "");
+ int match_count = 0;
+ if (term) {
+ for (int ti = 0; ti < (rel->type_count > 0 ? rel->type_count : 1) && new_count < max_new;
+ ti++) {
+ cbm_edge_t *edges = NULL;
+ int edge_count = 0;
+ if (rel->type_count > 0) {
+ if (scan_targets) {
+ cbm_store_find_edges_by_target_type(store, term->id, rel->types[ti], &edges,
+ &edge_count);
+ } else {
+ cbm_store_find_edges_by_source_type(store, term->id, rel->types[ti], &edges,
+ &edge_count);
+ }
+ } else if (scan_targets) {
+ cbm_store_find_edges_by_target(store, term->id, &edges, &edge_count);
+ } else {
+ cbm_store_find_edges_by_source(store, term->id, &edges, &edge_count);
+ }
+ for (int ei = 0; ei < edge_count && new_count < max_new; ei++) {
+ int64_t sid = scan_targets ? edges[ei].source_id : edges[ei].target_id;
+ cbm_node_t found = {0};
+ if (cbm_store_find_node_by_id(store, sid, &found) != CBM_STORE_OK) {
+ continue;
+ }
+ if (start_node->label && !label_alt_matches(found.label, start_node->label)) {
+ node_fields_free(&found);
+ continue;
+ }
+ binding_t nb = {0};
+ binding_copy(&nb, b);
+ binding_set(&nb, start_var, &found);
+ if (rel->variable) {
+ binding_set_edge(&nb, rel->variable, &edges[ei]);
+ }
+ node_fields_free(&found);
+ new_bindings[new_count++] = nb;
+ match_count++;
+ }
+ cbm_store_free_edges(edges, edge_count);
+ }
+ }
+ if (opt && match_count == 0 && new_count < max_new) {
+ /* No matching neighbour: keep the row with start_var left UNBOUND so
+ * `WHERE <start> IS NULL` correctly identifies the no-edge case. */
+ binding_t nb = {0};
+ binding_copy(&nb, b);
+ new_bindings[new_count++] = nb;
+ }
+ }
+
+ for (int bi = 0; bi < *bind_count; bi++) {
+ binding_free(&(*bindings)[bi]);
+ }
+ free(*bindings);
+ *bindings = new_bindings;
+ *bind_count = new_count;
+}
+
/* Expand additional MATCH patterns (pi >= 1) */
static void expand_additional_patterns(cbm_store_t *store, cbm_query_t *q, const char *project,
int max_rows, binding_t **bindings, int *bind_count,
@@ -4211,19 +4320,32 @@ static void expand_additional_patterns(cbm_store_t *store, cbm_query_t *q, const
if (start_bound && patn->rel_count > 0) {
const char *tv = nvar;
expand_pattern_rels(store, patn, bindings, bind_count, bind_cap, &tv, opt);
- } else {
- cbm_node_t *extra_nodes = NULL;
- int extra_count = 0;
- scan_pattern_nodes(store, project, max_rows, &patn->nodes[0], &extra_nodes,
- &extra_count);
- if (patn->rel_count == 0) {
- cross_join_nodes(bindings, bind_count, extra_nodes, extra_count, nvar, opt);
- } else {
- cross_join_with_rels(store, patn, bindings, bind_count, extra_nodes, extra_count,
- nvar, opt);
+ continue;
+ }
+
+ /* Single-rel pattern whose START is unbound but whose TERMINAL is already
+ * bound: drive from the bound terminal instead of scanning all nodes for
+ * the start var (avoids the int-overflow OOB write and the c-IS-NULL
+ * corruption of #627). */
+ if (!start_bound && patn->rel_count == 1 && *bind_count > 0) {
+ const char *term_var = patn->nodes[1].variable;
+ bool term_bound = term_var && binding_get(&(*bindings)[0], term_var) != NULL;
+ if (term_bound) {
+ expand_from_bound_terminal(store, patn, bindings, bind_count, nvar, opt);
+ continue;
}
- cbm_store_free_nodes(extra_nodes, extra_count);
}
+
+ cbm_node_t *extra_nodes = NULL;
+ int extra_count = 0;
+ scan_pattern_nodes(store, project, max_rows, &patn->nodes[0], &extra_nodes, &extra_count);
+ if (patn->rel_count == 0) {
+ cross_join_nodes(bindings, bind_count, extra_nodes, extra_count, nvar, opt);
+ } else {
+ cross_join_with_rels(store, patn, bindings, bind_count, extra_nodes, extra_count, nvar,
+ opt);
+ }
+ cbm_store_free_nodes(extra_nodes, extra_count);
}
}
diff --git a/src/discover/discover.c b/src/discover/discover.c
index f4c0c2c01..a43b44be3 100644
--- a/src/discover/discover.c
+++ b/src/discover/discover.c
@@ -32,7 +32,7 @@ static const char *ALWAYS_SKIP_DIRS[] = {
/* VCS */
".git", ".hg", ".svn", ".worktrees",
/* IDE */
- ".idea", ".vs", ".vscode", ".eclipse", ".claude", ".claude-worktrees",
+ ".idea", ".vs", ".vscode", ".eclipse", ".claude", ".claude-worktrees", "Antigravity",
/* Python */
".cache", ".eggs", ".env", ".mypy_cache", ".nox", ".pytest_cache", ".ruff_cache", ".tox",
".venv", "__pycache__", "env", "htmlcov", "site-packages", "venv",
@@ -776,11 +776,15 @@ int cbm_discover_ex(const char *repo_path, const cbm_discover_opts_t *opts, cbm_
struct stat gi_stat;
bool is_git_repo = wide_stat(gi_path, &gi_stat) == 0 && S_ISDIR(gi_stat.st_mode);
bool has_git_config = false;
+ /* Always honour the .gitignore at the indexed-directory root, even when the
+ * directory is not a git repo root (e.g. indexing a sub-package directly).
+ * The .git/info/exclude and global-excludes sources still require .git/.
+ * Fixes issue #510: a root .gitignore was silently ignored without .git/. */
+ snprintf(gi_path, sizeof(gi_path), "%s/.gitignore", repo_path);
+ gitignore = cbm_gitignore_load(gi_path);
if (is_git_repo) {
snprintf(gi_path, sizeof(gi_path), "%s/.git/config", repo_path);
has_git_config = wide_stat(gi_path, &gi_stat) == 0 && S_ISREG(gi_stat.st_mode);
- snprintf(gi_path, sizeof(gi_path), "%s/.gitignore", repo_path);
- gitignore = cbm_gitignore_load(gi_path);
char exc_path[CBM_SZ_4K];
snprintf(exc_path, sizeof(exc_path), "%s/.git/info/exclude", repo_path);
diff --git a/src/foundation/mem.c b/src/foundation/mem.c
index 67ef4d14e..46494aad2 100644
--- a/src/foundation/mem.c
+++ b/src/foundation/mem.c
@@ -123,6 +123,23 @@ void cbm_mem_init(double ram_fraction) {
mi_option_set(mi_option_purge_decommits, SKIP_ONE);
mi_option_set(mi_option_purge_delay, 0); /* immediate purge, no 1s delay */
+ /* CBM_MEM_BUDGET_MB env override (memory analogue of CBM_WORKERS).
+ * Lets users cap the budget directly without an enclosing cgroup —
+ * useful on bare-metal hosts where cgroup memory limits are absent
+ * (#363). Explicit override > implicit RAM/cgroup detection. */
+ char env_buf[CBM_SZ_32];
+ if (cbm_safe_getenv("CBM_MEM_BUDGET_MB", env_buf, sizeof(env_buf), NULL) != NULL) {
+ long mb = strtol(env_buf, NULL, CBM_DECIMAL_BASE);
+ if (mb > 0) {
+ g_budget = (size_t)mb * MB_DIVISOR;
+ char ovr_mb[CBM_SZ_32];
+ snprintf(ovr_mb, sizeof(ovr_mb), "%ld", mb);
+ cbm_log_info("mem.init", "budget_mb", ovr_mb, "source", "CBM_MEM_BUDGET_MB");
+ return;
+ }
+ cbm_log_warn("mem.budget.env.invalid", "value", env_buf, "fallback", "ram_fraction");
+ }
+
cbm_system_info_t info = cbm_system_info();
g_budget = (size_t)((double)info.total_ram * ram_fraction);
diff --git a/src/mcp/mcp.c b/src/mcp/mcp.c
index f2cd65e8c..a6eef0e9e 100644
--- a/src/mcp/mcp.c
+++ b/src/mcp/mcp.c
@@ -2287,8 +2287,52 @@ static bool is_test_file(const char *path) {
}
/* Convert BFS traversal results into a yyjson_mut array. */
+/* Find the CALLS-edge "args" JSON (the serialized arg expressions) on the edge
+ * that leads to the given hop node, so data_flow mode can surface argument
+ * expressions (#514). Returns the borrowed substring "[...]" inside the edge's
+ * properties_json, with its length, or NULL when no args are recorded. */
+static const char *bfs_edge_args_for_hop(cbm_traverse_result_t *tr, int64_t hop_node_id,
+ size_t *out_len) {
+ for (int e = 0; e < tr->edge_count; e++) {
+ /* The hop node is the edge endpoint reached from the root side: for an
+ * outbound trace it is the target, for inbound it is the source. Match
+ * on either so both directions surface their args. */
+ if (tr->edges[e].target_id != hop_node_id && tr->edges[e].source_id != hop_node_id) {
+ continue;
+ }
+ const char *pj = tr->edges[e].properties_json;
+ if (!pj) {
+ continue;
+ }
+ const char *args = strstr(pj, "\"args\"");
+ if (!args) {
+ continue;
+ }
+ const char *open = strchr(args, '[');
+ if (!open) {
+ continue;
+ }
+ int depth = 0;
+ const char *p = open;
+ for (; *p; p++) {
+ if (*p == '[') {
+ depth++;
+ } else if (*p == ']') {
+ depth--;
+ if (depth == 0) {
+ p++;
+ break;
+ }
+ }
+ }
+ *out_len = (size_t)(p - open);
+ return open;
+ }
+ return NULL;
+}
+
static yyjson_mut_val *bfs_to_json_array(yyjson_mut_doc *doc, cbm_traverse_result_t *tr,
- bool risk_labels, bool include_tests) {
+ bool risk_labels, bool include_tests, bool data_flow) {
yyjson_mut_val *arr = yyjson_mut_arr(doc);
for (int i = 0; i < tr->visited_count; i++) {
const char *fp = tr->visited[i].node.file_path;
@@ -2310,6 +2354,18 @@ static yyjson_mut_val *bfs_to_json_array(yyjson_mut_doc *doc, cbm_traverse_resul
if (test) {
yyjson_mut_obj_add_bool(doc, item, "is_test", true);
}
+ /* data_flow mode promises argument expressions at each call site; surface
+ * the CALLS edge's serialized args array as a raw JSON value (#514). */
+ if (data_flow) {
+ size_t alen = 0;
+ const char *args = bfs_edge_args_for_hop(tr, tr->visited[i].node.id, &alen);
+ if (args && alen > 0) {
+ yyjson_mut_val *av = yyjson_mut_rawn(doc, args, alen);
+ if (av) {
+ yyjson_mut_obj_add_val(doc, item, "args", av);
+ }
+ }
+ }
yyjson_mut_arr_add_val(arr, item);
}
return arr;
@@ -2375,6 +2431,52 @@ static int pick_resolved_node(const cbm_node_t *nodes, int count, bool *ambiguou
return best;
}
+/* BFS from EVERY node sharing the resolved name and merge the results, so the
+ * caller/callee set is complete even when one logical symbol is represented by
+ * more than one graph node — e.g. a real .ts implementation plus an ambient
+ * .d.ts stub, whose inbound CALLS edges are otherwise split across the two
+ * nodes and silently truncated by tracing only one (#546). visited hops are
+ * deduped by node id; edges are concatenated. Ownership of all heap fields
+ * transfers into *out, freed by cbm_store_traverse_free. */
+static void bfs_union_same_name(cbm_store_t *store, const cbm_node_t *nodes, int node_count,
+ const char *direction, const char **edge_types, int edge_type_count,
+ int depth, cbm_traverse_result_t *out) {
+ memset(out, 0, sizeof(*out));
+ int vcap = 0, ecap = 0;
+ for (int k = 0; k < node_count; k++) {
+ cbm_traverse_result_t tr = {0};
+ cbm_store_bfs(store, nodes[k].id, direction, edge_types, edge_type_count, depth,
+ MCP_BFS_LIMIT, &tr);
+ for (int i = 0; i < tr.visited_count; i++) {
+ bool dup = false;
+ for (int j = 0; j < out->visited_count; j++) {
+ if (out->visited[j].node.id == tr.visited[i].node.id) {
+ dup = true;
+ break;
+ }
+ }
+ if (dup) {
+ continue;
+ }
+ if (out->visited_count >= vcap) {
+ vcap = vcap ? vcap * 2 : 8;
+ out->visited = safe_realloc(out->visited, vcap * sizeof(cbm_node_hop_t));
+ }
+ out->visited[out->visited_count++] = tr.visited[i];
+ memset(&tr.visited[i], 0, sizeof(tr.visited[i])); /* ownership moved */
+ }
+ for (int i = 0; i < tr.edge_count; i++) {
+ if (out->edge_count >= ecap) {
+ ecap = ecap ? ecap * 2 : 8;
+ out->edges = safe_realloc(out->edges, ecap * sizeof(cbm_edge_info_t));
+ }
+ out->edges[out->edge_count++] = tr.edges[i];
+ memset(&tr.edges[i], 0, sizeof(tr.edges[i])); /* ownership moved */
+ }
+ cbm_store_traverse_free(&tr); /* frees only the un-moved (root + dup) fields */
+ }
+}
+
static char *handle_trace_call_path(cbm_mcp_server_t *srv, const char *args) {
char *func_name = cbm_mcp_get_string_arg(args, "function_name");
char *project = cbm_mcp_get_string_arg(args, "project");
@@ -2499,18 +2601,24 @@ static char *handle_trace_call_path(cbm_mcp_server_t *srv, const char *args) {
cbm_traverse_result_t tr_out = {0};
cbm_traverse_result_t tr_in = {0};
+ bool data_flow = mode && strcmp(mode, "data_flow") == 0;
+
+ (void)sel; /* union across all same-name nodes — see bfs_union_same_name (#546) */
+
if (do_outbound) {
- cbm_store_bfs(store, nodes[sel].id, "outbound", edge_types, edge_type_count, depth,
- MCP_BFS_LIMIT, &tr_out);
+ bfs_union_same_name(store, nodes, node_count, "outbound", edge_types, edge_type_count, depth,
+ &tr_out);
yyjson_mut_obj_add_val(doc, root, "callees",
- bfs_to_json_array(doc, &tr_out, risk_labels, include_tests));
+ bfs_to_json_array(doc, &tr_out, risk_labels, include_tests,
+ data_flow));
}
if (do_inbound) {
- cbm_store_bfs(store, nodes[sel].id, "inbound", edge_types, edge_type_count, depth,
- MCP_BFS_LIMIT, &tr_in);
+ bfs_union_same_name(store, nodes, node_count, "inbound", edge_types, edge_type_count, depth,
+ &tr_in);
yyjson_mut_obj_add_val(doc, root, "callers",
- bfs_to_json_array(doc, &tr_in, risk_labels, include_tests));
+ bfs_to_json_array(doc, &tr_in, risk_labels, include_tests,
+ data_flow));
}
/* Serialize BEFORE freeing traversal results (yyjson borrows strings) */
@@ -4245,18 +4353,30 @@ static char *handle_detect_changes(cbm_mcp_server_t *srv, const char *args) {
return cbm_mcp_text_result("project path contains invalid characters", true);
}
- /* Get changed files via git (-C avoids cd + quoting issues on Windows) */
+ /* Get changed files via git (-C avoids cd + quoting issues on Windows).
+ * Three sources are merged:
+ * 1. committed changes vs base (diff <base>...HEAD)
+ * 2. unstaged tracked changes (diff)
+ * 3. untracked + staged-new files (status --porcelain) — these are
+ * invisible to `git diff` and were silently missed before, so a
+ * brand-new file never appeared until a manual re-index (#520).
+ * status --porcelain prefixes each path with a 2-char code + space
+ * ("?? path", "A path"); the prefix is stripped when parsing below. */
char cmd[CBM_SZ_2K];
#ifdef _WIN32
snprintf(cmd, sizeof(cmd),
"git -C \"%s\" diff --name-only \"%s\"...HEAD 2>NUL & "
- "git -C \"%s\" diff --name-only 2>NUL",
- root_path, base_branch, root_path);
+ "git -C \"%s\" diff --name-only 2>NUL & "
+ "git --no-optional-locks -C \"%s\" status --porcelain "
+ "--untracked-files=normal 2>NUL",
+ root_path, base_branch, root_path, root_path);
#else
snprintf(cmd, sizeof(cmd),
"{ git -C '%s' diff --name-only '%s'...HEAD 2>/dev/null; "
- "git -C '%s' diff --name-only 2>/dev/null; } | sort -u",
- root_path, base_branch, root_path);
+ "git -C '%s' diff --name-only 2>/dev/null; "
+ "git --no-optional-locks -C '%s' status --porcelain "
+ "--untracked-files=normal 2>/dev/null; } | sort -u",
+ root_path, base_branch, root_path, root_path);
#endif
FILE *fp = cbm_popen(cmd, "r");
@@ -4294,11 +4414,30 @@ static char *handle_detect_changes(cbm_mcp_server_t *srv, const char *args) {
continue;
}
- yyjson_mut_arr_add_strcpy(doc, changed, line);
+ /* `git status --porcelain` prefixes each path with a two-character
+ * status code and a space ("?? path", "A path", " M path"). The two
+ * `git diff --name-only` sources emit bare paths. Strip the porcelain
+ * prefix when present so all three sources yield clean paths; for a
+ * rename ("R old -> new") keep the post-arrow destination path. */
+ char *path_line = line;
+ if (len > PAIR_LEN && line[PAIR_LEN] == ' ' &&
+ strchr(" MADRCU?!", line[0]) && strchr(" MADRCU?!", line[1])) {
+ path_line = line + PAIR_LEN + SKIP_ONE;
+ char *arrow = strstr(path_line, " -> ");
+ if (arrow) {
+ enum { ARROW_LEN = 4 }; /* length of " -> " */
+ path_line = arrow + ARROW_LEN;
+ }
+ }
+ if (path_line[0] == '\0') {
+ continue;
+ }
+
+ yyjson_mut_arr_add_strcpy(doc, changed, path_line);
file_count++;
if (want_symbols) {
- detect_add_impacted_symbols(store, project, line, doc, impacted);
+ detect_add_impacted_symbols(store, project, path_line, doc, impacted);
}
}
int git_status = cbm_pclose(fp);
diff --git a/src/pipeline/fqn.c b/src/pipeline/fqn.c
index 0da3e7370..c7b8ec470 100644
--- a/src/pipeline/fqn.c
+++ b/src/pipeline/fqn.c
@@ -331,21 +331,43 @@ char *cbm_project_name_from_path(const char *abs_path) {
/* Normalize path separators */
cbm_normalize_path_sep(path);
- /* Map every character cbm_validate_project_name would reject to '-'. The
+ /* Map every character cbm_validate_project_name would reject. The
* validator (used by resolve_store via project_db_path) allows only
* [A-Za-z0-9._-], so anything else — path separators, ':', spaces, '@',
- * '+', unicode bytes, … — must be normalized here. Otherwise a repo like
+ * '+', … — must be normalized here. Otherwise a repo like
* "/home/u/my project" yields the name "home-u-my project": indexing
* creates the DB and it shows in list_projects, but resolve_store rejects
- * the space and reports project-not-found (#349). */
+ * the space and reports project-not-found (#349).
+ *
+ * Non-ASCII bytes (UTF-8 of CJK and other scripts, all >= 0x80) are NOT
+ * dropped to '-' — that silently erased whole path segments and produced
+ * unrecognizable / colliding names (#571). Instead each non-ASCII byte is
+ * transliterated to its two lowercase hex digits, which use only [0-9a-f]
+ * and therefore stay validator-safe while preserving the segment. */
+ static const char hex_digits[] = "0123456789abcdef";
+ char *mapped = malloc(len * 2 + 1); /* worst case: every byte → 2 hex chars */
+ if (!mapped) {
+ free(path);
+ return strdup("root");
+ }
+ size_t mlen = 0;
for (size_t i = 0; i < len; i++) {
unsigned char c = (unsigned char)path[i];
bool safe = (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') ||
c == '.' || c == '_' || c == '-';
- if (!safe) {
- path[i] = '-';
+ if (safe) {
+ mapped[mlen++] = (char)c;
+ } else if (c >= 0x80) {
+ mapped[mlen++] = hex_digits[(c >> 4) & 0xF];
+ mapped[mlen++] = hex_digits[c & 0xF];
+ } else {
+ mapped[mlen++] = '-';
}
}
+ mapped[mlen] = '\0';
+ free(path);
+ path = mapped;
+ len = mlen;
/* Collapse consecutive dashes, and consecutive dots (the validator also
* rejects any ".." sequence). */
diff --git a/src/pipeline/pass_calls.c b/src/pipeline/pass_calls.c
index 4f4d7b54b..776725c5d 100644
--- a/src/pipeline/pass_calls.c
+++ b/src/pipeline/pass_calls.c
@@ -250,6 +250,53 @@ static int64_t create_svc_route_node(cbm_pipeline_ctx_t *ctx, const char *url, c
* to CALLS: route/config edge props feed full-only predump passes
* (create_route_nodes/create_data_flows), so altering them desyncs full vs
* incremental indexing. */
+/* Append a ,"args":[{"i":0,"e":"<expr>","v":"<value>"},...] field onto a CALLS
+ * edge's JSON props (the props buffer ends in '}'). The sequential pass omitted
+ * this, so data_flow mode had no argument expressions to surface for small
+ * (< 50 file) repos that take the sequential path (#514). Mirrors the parallel
+ * path's append_args_json shape so both pipelines agree. */
+static void calls_append_args(char *props, size_t cap, const CBMCall *call) {
+ if (!call || call->arg_count <= 0) {
+ return;
+ }
+ size_t len = strlen(props);
+ if (len < SKIP_ONE || props[len - SKIP_ONE] != '}') {
+ return;
+ }
+ /* Overwrite the trailing '}' and rebuild it after the args array. */
+ size_t pos = len - SKIP_ONE;
+ int n = snprintf(props + pos, cap - pos, ",\"args\":[");
+ if (n <= 0 || (size_t)n >= cap - pos) {
+ return;
+ }
+ pos += (size_t)n;
+ for (int i = 0; i < call->arg_count; i++) {
+ const CBMCallArg *a = &call->args[i];
+ char esc_e[CBM_SZ_256];
+ cbm_json_escape(esc_e, sizeof(esc_e), a->expr ? a->expr : "");
+ char one[CBM_SZ_512];
+ if (a->value) {
+ char esc_v[CBM_SZ_256];
+ cbm_json_escape(esc_v, sizeof(esc_v), a->value);
+ n = snprintf(one, sizeof(one), "%s{\"i\":%d,\"e\":\"%s\",\"v\":\"%s\"}",
+ i > 0 ? "," : "", a->index, esc_e, esc_v);
+ } else {
+ n = snprintf(one, sizeof(one), "%s{\"i\":%d,\"e\":\"%s\"}", i > 0 ? "," : "", a->index,
+ esc_e);
+ }
+ if (n <= 0 || (size_t)n >= cap - pos - PAIR_LEN) {
+ break; /* not enough room — close the array with what fits */
+ }
+ memcpy(props + pos, one, (size_t)n);
+ pos += (size_t)n;
+ }
+ if (pos + PAIR_LEN < cap) {
+ props[pos++] = ']';
+ props[pos++] = '}';
+ props[pos] = '\0';
+ }
+}
+
static void 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) {
@@ -259,6 +306,9 @@ static void calls_emit_edge(cbm_gbuf_t *gbuf, int64_t src, int64_t tgt, const ch
call->start_line);
}
}
+ if (call && strcmp(type, "CALLS") == 0) {
+ calls_append_args(props, cap, call);
+ }
cbm_gbuf_insert_edge(gbuf, src, tgt, type, props);
}
@@ -402,6 +452,27 @@ static int resolve_single_call(cbm_pipeline_ctx_t *ctx, CBMCall *call,
res.strategy)) {
return 0;
}
+
+ /* Service-pattern HTTP/ASYNC calls to an EXTERNAL client library (e.g.
+ * `requests.get("/api/orders/{id}")`) resolve to a QN containing the library
+ * name ("requests"), but that library is not in the indexed tree so
+ * cbm_gbuf_find_by_qn returns NULL. The edge target for such calls is a
+ * SYNTHESIZED route node (create_svc_route_node), not the library node, so
+ * the missing target must NOT drop the call — otherwise no HTTP_CALLS edge
+ * is written and cross-repo matching finds nothing (#523). Emit directly
+ * when the call carries a URL/topic first argument. */
+ cbm_svc_kind_t svc = cbm_service_pattern_match(res.qualified_name);
+ if (svc == CBM_SVC_HTTP || svc == CBM_SVC_ASYNC) {
+ const char *u = call->first_string_arg;
+ bool has_url_or_topic =
+ u && u[0] != '\0' &&
+ (u[0] == '/' || strstr(u, "://") != NULL || (svc == CBM_SVC_ASYNC && strlen(u) > PAIR_LEN));
+ if (has_url_or_topic) {
+ emit_http_async_edge(ctx, call, source_node, NULL, &res, svc);
+ return SKIP_ONE;
+ }
+ }
+
const cbm_gbuf_node_t *target_node = cbm_gbuf_find_by_qn(ctx->gbuf, res.qualified_name);
if (!target_node || source_node->id == target_node->id) {
return 0;
diff --git a/src/pipeline/pass_parallel.c b/src/pipeline/pass_parallel.c
index 0471cbe04..61d9faac6 100644
--- a/src/pipeline/pass_parallel.c
+++ b/src/pipeline/pass_parallel.c
@@ -1866,6 +1866,23 @@ static void resolve_file_calls(resolve_ctx_t *rc, resolve_worker_state_t *ws, CB
atomic_fetch_add_explicit(&rc->time_ns_rc_target, extract_now_ns() - _rc_t0,
memory_order_relaxed);
if (!target_node || source_node->id == target_node->id) {
+ /* HTTP/ASYNC calls to an EXTERNAL client library (`requests.get(url)`)
+ * resolve to an unindexed QN (target_node == NULL), but their edge
+ * target is a synthesized route node, not the library — emit them
+ * anyway so cross-repo matching has an HTTP_CALLS edge to work with
+ * (#523). Mirrors the sequential resolve_single_call bypass. */
+ cbm_svc_kind_t psvc = cbm_service_pattern_match(res.qualified_name);
+ if ((psvc == CBM_SVC_HTTP || psvc == CBM_SVC_ASYNC) && !target_node) {
+ const char *u = call->first_string_arg;
+ bool url_or_topic = u && u[0] != '\0' &&
+ (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);
+ ws->calls_resolved++;
+ }
+ }
continue;
}
_rc_t0 = extract_now_ns();
diff --git a/src/pipeline/pipeline.c b/src/pipeline/pipeline.c
index 9d99a925b..eb4327da5 100644
--- a/src/pipeline/pipeline.c
+++ b/src/pipeline/pipeline.c
@@ -491,11 +491,37 @@ static bool is_infra_file(const char *fp) {
strstr(fp, ".tf") != NULL || strstr(fp, ".hcl") != NULL || strstr(fp, ".toml") != NULL);
}
+/* True when a YAML key path denotes an UPSTREAM dependency, CONFIG value, or
+ * HEALTHCHECK target rather than an endpoint this service exposes. Such URLs
+ * (auth JWKS, downstream service base URLs, package-registry URLs, healthcheck
+ * curl targets) are NOT routes the service serves and must not mint Route nodes
+ * (#521). Exposed-endpoint keys (push_endpoint, post_url, callback, webhook)
+ * are intentionally absent here so they still produce infra Route nodes. */
+static bool is_upstream_config_key(const char *key_path) {
+ if (!key_path) {
+ /* No key context (e.g. flat string) — keep prior behaviour and mint. */
+ return false;
+ }
+ static const char *const deny[] = {"jwks", "registry", "registries",
+ "healthcheck", "upstream", "_service_url",
+ "auth", NULL};
+ for (int i = 0; deny[i]; i++) {
+ if (strstr(key_path, deny[i]) != NULL) {
+ return true;
+ }
+ }
+ return false;
+}
+
/* Try to create an infra Route node from one string_ref. */
static void try_upsert_infra_route(cbm_gbuf_t *gbuf, const CBMStringRef *sr, const char *fp) {
if (sr->kind != CBM_STRREF_URL || !sr->value || !strstr(sr->value, "://")) {
return;
}
+ /* Skip upstream/config/healthcheck URLs — they are not exposed routes (#521). */
+ if (is_upstream_config_key(sr->key_path)) {
+ return;
+ }
char route_qn[CBM_ROUTE_QN_SIZE];
snprintf(route_qn, sizeof(route_qn), "__route__infra__%s", sr->value);
char route_props[CBM_SZ_512];
diff --git a/src/store/store.c b/src/store/store.c
index 263ea93f6..ea724a292 100644
--- a/src/store/store.c
+++ b/src/store/store.c
@@ -2587,7 +2587,7 @@ static int bfs_collect_edges(cbm_store_t *s, int64_t start_id, const cbm_node_ho
char edge_sql[ST_SQL_BUF];
snprintf(edge_sql, sizeof(edge_sql),
- "SELECT n1.name, n2.name, e.type "
+ "SELECT n1.name, n2.name, e.type, e.source_id, e.target_id, e.properties "
"FROM edges e "
"JOIN nodes n1 ON n1.id = e.source_id "
"JOIN nodes n2 ON n2.id = e.target_id "
@@ -2624,6 +2624,9 @@ static int bfs_collect_edges(cbm_store_t *s, int64_t start_id, const cbm_node_ho
edges[en].to_name = heap_strdup((const char *)sqlite3_column_text(estmt, SKIP_ONE));
edges[en].type = heap_strdup((const char *)sqlite3_column_text(estmt, CBM_SZ_2));
edges[en].confidence = (double)SKIP_ONE;
+ edges[en].source_id = sqlite3_column_int64(estmt, ST_COL_3);
+ edges[en].target_id = sqlite3_column_int64(estmt, ST_COL_4);
+ edges[en].properties_json = heap_strdup((const char *)sqlite3_column_text(estmt, CBM_SZ_5));
en++;
}
sqlite3_finalize(estmt);
@@ -2776,6 +2779,7 @@ void cbm_store_traverse_free(cbm_traverse_result_t *out) {
safe_str_free(&out->edges[i].from_name);
safe_str_free(&out->edges[i].to_name);
safe_str_free(&out->edges[i].type);
+ safe_str_free(&out->edges[i].properties_json);
}
free(out->edges);
diff --git a/src/store/store.h b/src/store/store.h
index 43c87f572..c0fc189c0 100644
--- a/src/store/store.h
+++ b/src/store/store.h
@@ -148,6 +148,9 @@ typedef struct {
const char *to_name;
const char *type;
double confidence;
+ int64_t source_id; /* edge endpoints — let callers match an edge to a hop node */
+ int64_t target_id;
+ const char *properties_json; /* raw edge properties (carries CALLS arg expressions) */
} cbm_edge_info_t;
typedef struct {
diff --git a/src/ui/http_server.c b/src/ui/http_server.c
index 568b47cc0..af2291af1 100644
--- a/src/ui/http_server.c
+++ b/src/ui/http_server.c
@@ -408,6 +408,12 @@ static void handle_browse(cbm_http_conn_t *c, const cbm_http_req_t *req) {
snprintf(path, sizeof(path), "/");
}
+ /* The browser UI may send Windows backslash separators (e.g.
+ * "D:\projects\demo"). Normalize to forward slashes before the cbm_is_dir
+ * gate, exactly as the MCP repo_path handler and cbm_project_name_from_path
+ * already do — otherwise a real D:/ directory is rejected (#548). */
+ cbm_normalize_path_sep(path);
+
if (!cbm_is_dir(path)) {
cbm_http_replyf(c, 400, g_cors_json, "{\"error\":\"not a directory\"}");
return;
@@ -459,10 +465,18 @@ static void handle_browse(cbm_http_conn_t *c, const cbm_http_req_t *req) {
char parent[1024];
snprintf(parent, sizeof(parent), "%s", path);
char *last_slash = strrchr(parent, '/');
- if (last_slash && last_slash != parent)
+ /* A Windows drive root "X:/" is its own parent (like POSIX "/"): truncating
+ * at the slash would yield the bare drive spec "X:", which the next browse
+ * resolves to the wrong directory and strands the user at the root (#548). */
+ size_t parent_len = strlen(parent);
+ bool is_drive_root = parent_len == 3 && parent[1] == ':' && parent[2] == '/';
+ if (is_drive_root) {
+ /* leave "X:/" unchanged */
+ } else if (last_slash && last_slash != parent) {
*last_slash = '\0';
- else
+ } else {
snprintf(parent, sizeof(parent), "/");
+ }
{
char esc_parent[2048];
diff --git a/tests/repro/repro_issue548.c b/tests/repro/repro_issue548.c
index b4fbabdec..f6d894f95 100644
--- a/tests/repro/repro_issue548.c
+++ b/tests/repro/repro_issue548.c
@@ -110,6 +110,7 @@
#include <foundation/platform.h>
+#include <stdbool.h>
#include <stdio.h>
#include <string.h>
@@ -177,20 +178,22 @@ TEST(repro_issue548_cbm_is_dir_rejects_backslash_path) {
}
/*
- * PRIMARY ASSERTION — WHY RED on current code:
- * handle_browse() calls cbm_is_dir(path) with path == backslash_path.
- * On POSIX, cbm_is_dir(backslash_path) returns false (backslash is not
- * a path separator; the OS sees no such path) → ASSERT_EQ(result, 1) FAILS
- * → RED.
- *
- * On correct (fixed) code: handle_browse() calls cbm_normalize_path_sep()
- * before cbm_is_dir(), converting backslashes to forward slashes first.
- * cbm_is_dir() then sees the original forward-slash tmpdir path, which
- * exists → returns true → assertion passes → GREEN.
+ * PRIMARY ASSERTION — reproduces the handle_browse() gate behaviour.
*
- * The backslash_path variable here is exactly the string that handle_browse()
- * passes to cbm_is_dir() on the current (buggy) code path.
+ * handle_browse() is a static HTTP handler that cannot be called directly,
+ * so we exercise the exact two-step sequence it now performs on the query
+ * param: cbm_normalize_path_sep(path) THEN cbm_is_dir(path). This pins the
+ * fix at the missing normalize call-site:
+ * - BEFORE the fix, handle_browse() skipped cbm_normalize_path_sep(), so
+ * the raw backslash string reached cbm_is_dir() and the directory was
+ * rejected (the user could never open a D:/ path).
+ * - AFTER the fix (src/ui/http_server.c, normalize-before-is_dir), the
+ * backslash form is converted to forward slashes first and cbm_is_dir()
+ * sees the real tmpdir path → returns true.
+ * cbm_normalize_path_sep() itself is verified correct by TEST C; here it
+ * stands in for the call handle_browse() makes before the gate.
*/
+ cbm_normalize_path_sep(backslash_path);
int result = cbm_is_dir(backslash_path) ? 1 : 0;
ASSERT_EQ(result, 1);
@@ -253,12 +256,17 @@ TEST(repro_issue548_drive_root_parent_correct) {
char parent[1024];
snprintf(parent, sizeof(parent), "%s", "D:/");
- /* --- begin verbatim copy of handle_browse() parent computation --- */
+ /* --- begin verbatim copy of FIXED handle_browse() parent computation --- */
char *last_slash = strrchr(parent, '/');
- if (last_slash && last_slash != parent)
+ size_t parent_len = strlen(parent);
+ bool is_drive_root = parent_len == 3 && parent[1] == ':' && parent[2] == '/';
+ if (is_drive_root) {
+ /* "X:/" is its own parent — leave unchanged (matches POSIX "/") */
+ } else if (last_slash && last_slash != parent) {
*last_slash = '\0';
- else
+ } else {
snprintf(parent, sizeof(parent), "/");
+ }
/* --- end verbatim copy --- */
/*