Skip to content

Commit 3f754cf

Browse files
committed
fix: 17 reproduce-first issue + new-bug fixes (per-case verified)
Each was RED (reproduce-first). Verdicts: production bug unless noted. - DeusData#510 nested .gitignore: load root .gitignore unconditionally (discover.c). - DeusData#403 IDE dir: add "Antigravity" to ALWAYS_SKIP_DIRS. - DeusData#571 CJK project name: transliterate non-ASCII bytes to hex in fqn.c (was -> "-"). - DeusData#520 detect_changes: include untracked files (git status --porcelain -uno) (mcp.c). - DeusData#363 CBM_MEM_BUDGET_MB env override (mem.c). - DeusData#570 Codex dual-hook: write the hook to hooks.json when present (cli.c). - DeusData#431 VSCode per-profile mcp.json (cli.c). - DeusData#521 routes from config URLs: deny upstream/jwks/healthcheck/... keys (pipeline.c). - DeusData#548 D:\ browse: normalize sep before is_dir + drive-root self-parent (http_server.c); TEST A was a broken fixture (called is_dir on backslash) -> corrected to the production sequence; assertion unchanged. - DeusData#495 Rust cfg-gated twins: fold #[cfg(...)] into the QN (extract_defs.c). - new_py_tuple_unpack: handle pattern_list/tuple_pattern LHS -> Variable per id. - new_ts_class_field_arrow: class arrow-field -> Method + scope (extract_defs.c). - repro_extraction/DeusData#554 C++ out-of-line: compute_func_qn class-qualifies the call's enclosing QN via cbm_cpp_out_of_line_parent_class (extract_unified.c + helpers.h). - DeusData#523 cross-repo HTTP_CALLS: emit service-pattern edge with target=NULL when the client lib is unindexed (pass_calls.c, pass_parallel.c). - DeusData#514 data_flow arg expressions: serialize "args" on CALLS edges + propagate through store BFS + mcp data_flow (pass_calls.c, store.h/.c, mcp.c). - DeusData#627 query_graph: size_t malloc + NULL-check; OPTIONAL MATCH from bound terminal so WHERE c IS NULL returns orphans correctly (cypher.c). - DeusData#546/DeusData#480 trace_path: union BFS across same-name nodes (.d.ts dup) (mcp.c). DEFERRED (need a maintainer decision, untouched): DeusData#56 cross-crate Rust (needs Cargo workspace plumbing / Rust cross-LSP — architectural), DeusData#607 reinstall-deletes-index (cbm_remove_indexes is shared with uninstall/update where deletion is intended). Signed-off-by: Martin Vogel <[email protected]>
1 parent b9b4669 commit 3f754cf

16 files changed

Lines changed: 663 additions & 64 deletions

File tree

‎internal/cbm/extract_defs.c‎

Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ static TSNode resolve_func_name_fp(TSNode node, CBMLanguage lang, const char *ki
465465
// or NULL when the declarator is unqualified (a plain free function). Without
466466
// this, an out-of-line definition — whose class body lives declaration-only in a
467467
// header — would be recorded as a free Function with no link to its class.
468-
static char *cpp_out_of_line_parent_class(CBMArena *a, TSNode node, const char *source) {
468+
char *cbm_cpp_out_of_line_parent_class(CBMArena *a, TSNode node, const char *source) {
469469
// Descend the declarator chain to its qualified_identifier, if any.
470470
TSNode qid = {0};
471471
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) {
608608
return null_node;
609609
}
610610
const char *pk = ts_node_type(parent);
611-
if (strcmp(pk, "variable_declarator") == 0) {
611+
if (strcmp(pk, "variable_declarator") == 0 ||
612+
strcmp(pk, "public_field_definition") == 0) {
613+
/* `const f = () => {}` and the class-field form `f = () => {}` both name
614+
* the arrow via the parent's `name` child (#new_ts_class_field_arrow):
615+
* resolving it lets push_boundary_scopes push a SCOPE_FUNC so in-body
616+
* calls source to the method, not the enclosing class/module. */
612617
return ts_node_child_by_field_name(parent, TS_FIELD("name"));
613618
}
619+
if (strcmp(pk, "field_definition") == 0) {
620+
return ts_node_child_by_field_name(parent, TS_FIELD("property"));
621+
}
614622
if (strcmp(pk, "pair") == 0) {
615623
return ts_node_child_by_field_name(parent, TS_FIELD("key"));
616624
}
@@ -1644,6 +1652,38 @@ static const char **extract_decorators(CBMArena *a, TSNode node, const char *sou
16441652
return result;
16451653
}
16461654

1655+
/* Rust: two same-named functions guarded by mutually-exclusive #[cfg(...)]
1656+
* attributes both parse as distinct function_item nodes and otherwise receive
1657+
* the SAME qualified_name, so the second graph upsert silently overwrites the
1658+
* first and one branch is lost (#495). Fold the cfg predicate into the QN so
1659+
* each cfg-gated twin gets a DISTINCT, predicate-encoding QN. Returns the
1660+
* (possibly suffixed) QN; the original QN when no cfg attribute is present. */
1661+
static const char *rust_cfg_qualified_name(CBMArena *a, const char *base_qn,
1662+
const char *const *decorators) {
1663+
if (!decorators) {
1664+
return base_qn;
1665+
}
1666+
for (int i = 0; decorators[i]; i++) {
1667+
const char *cfg = strstr(decorators[i], "cfg(");
1668+
if (!cfg) {
1669+
continue;
1670+
}
1671+
/* Build a compact predicate suffix from the cfg(...) text, dropping
1672+
* whitespace and quotes so the QN stays readable and stable. */
1673+
char buf[CBM_SZ_256];
1674+
size_t bi = 0;
1675+
for (const char *p = cfg; *p && bi + 1 < sizeof(buf); p++) {
1676+
if (*p == ' ' || *p == '\t' || *p == '"' || *p == '\'') {
1677+
continue;
1678+
}
1679+
buf[bi++] = *p;
1680+
}
1681+
buf[bi] = '\0';
1682+
return cbm_arena_sprintf(a, "%s#%s", base_qn, buf);
1683+
}
1684+
return base_qn;
1685+
}
1686+
16471687
// Extract base class name text from a single base_class child node.
16481688
static char *extract_cpp_base_text(CBMArena *a, TSNode bc, const char *source) {
16491689
const char *bk = ts_node_type(bc);
@@ -2883,7 +2923,7 @@ static void extract_func_def(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec
28832923
// class node QN computed the same way) so DEFINES_METHOD edges resolve.
28842924
if ((ctx->language == CBM_LANG_CPP || ctx->language == CBM_LANG_CUDA) &&
28852925
strcmp(ts_node_type(node), "function_definition") == 0) {
2886-
char *scope_name = cpp_out_of_line_parent_class(a, node, ctx->source);
2926+
char *scope_name = cbm_cpp_out_of_line_parent_class(a, node, ctx->source);
28872927
if (scope_name && scope_name[0]) {
28882928
const char *class_qn = cbm_fqn_compute(a, ctx->project, ctx->rel_path, scope_name);
28892929
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
29182958
def.decorators = extract_decorators(a, node, ctx->source, ctx->language, spec);
29192959
extract_route_from_decorators(a, node, ctx->source, spec, &def.route_path, &def.route_method);
29202960

2961+
// Rust: disambiguate cfg-gated twin functions by folding the #[cfg(...)]
2962+
// predicate into the QN so both branches survive the graph upsert (#495).
2963+
if (ctx->language == CBM_LANG_RUST) {
2964+
def.qualified_name = rust_cfg_qualified_name(a, def.qualified_name, def.decorators);
2965+
}
2966+
29212967
// Docstring
29222968
def.docstring = extract_docstring(a, node, ctx->source, ctx->language);
29232969

@@ -3868,6 +3914,24 @@ static void extract_class_methods(CBMExtractCtx *ctx, TSNode class_node, const c
38683914
method_node = def;
38693915
}
38703916

3917+
// TS/JS class-field arrow functions: `handleClick = () => {...}` is a
3918+
// public_field_definition whose `value` is an arrow_function (a common
3919+
// React event-handler pattern). It is not in function_node_types, so it
3920+
// would otherwise be dropped. Peek through to the inner arrow and take
3921+
// the method name from the field's `name` child (#new_ts_class_field_arrow).
3922+
if (strcmp(ts_node_type(child), "public_field_definition") == 0) {
3923+
TSNode value = ts_node_child_by_field_name(child, TS_FIELD("value"));
3924+
if (ts_node_is_null(value) || !cbm_kind_in_set(value, spec->function_node_types)) {
3925+
continue;
3926+
}
3927+
TSNode fname = ts_node_child_by_field_name(child, TS_FIELD("name"));
3928+
if (ts_node_is_null(fname)) {
3929+
continue;
3930+
}
3931+
push_method_def(ctx, value, class_qn, spec, fname);
3932+
continue;
3933+
}
3934+
38713935
if (!cbm_kind_in_set(method_node, spec->function_node_types)) {
38723936
continue;
38733937
}
@@ -4318,8 +4382,23 @@ static void extract_vars_mainstream(CBMExtractCtx *ctx, TSNode node, CBMArena *a
43184382
switch (ctx->language) {
43194383
case CBM_LANG_PYTHON: {
43204384
TSNode left = ts_node_child_by_field_name(node, TS_FIELD("left"));
4321-
if (!ts_node_is_null(left) && strcmp(ts_node_type(left), "identifier") == 0) {
4385+
if (ts_node_is_null(left)) {
4386+
break;
4387+
}
4388+
const char *lt = ts_node_type(left);
4389+
if (strcmp(lt, "identifier") == 0) {
43224390
push_var_def(ctx, cbm_node_text(a, left, ctx->source), node);
4391+
} else if (strcmp(lt, "pattern_list") == 0 || strcmp(lt, "tuple_pattern") == 0 ||
4392+
strcmp(lt, "list_pattern") == 0) {
4393+
/* Tuple/list unpacking: `x, y = f()` — emit a Variable def for each
4394+
* unpacked identifier on the LHS (#new_py_tuple_unpack). */
4395+
uint32_t ln = ts_node_named_child_count(left);
4396+
for (uint32_t li = 0; li < ln; li++) {
4397+
TSNode part = ts_node_named_child(left, li);
4398+
if (strcmp(ts_node_type(part), "identifier") == 0) {
4399+
push_var_def(ctx, cbm_node_text(a, part, ctx->source), node);
4400+
}
4401+
}
43234402
}
43244403
break;
43254404
}

‎internal/cbm/extract_unified.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,22 @@ static const char *compute_func_qn(CBMExtractCtx *ctx, TSNode node, const CBMLan
308308
return NULL;
309309
}
310310

311+
/* C++/CUDA out-of-line method `void Foo::bar() {...}`: the def extractor
312+
* records this as Method "proj.file.Foo.bar". The call-scope QN must match
313+
* (be class-qualified) so an in-body call sources to the method, not a bare
314+
* "proj.file.bar" that no node carries (#554/#621). The out-of-line def is at
315+
* file scope, so enclosing_class_qn is NULL — derive the class from the
316+
* qualified declarator instead. */
317+
if ((ctx->language == CBM_LANG_CPP || ctx->language == CBM_LANG_CUDA) &&
318+
strcmp(ts_node_type(node), "function_definition") == 0) {
319+
char *scope_name = cbm_cpp_out_of_line_parent_class(ctx->arena, node, ctx->source);
320+
if (scope_name && scope_name[0]) {
321+
const char *class_qn =
322+
cbm_fqn_compute(ctx->arena, ctx->project, ctx->rel_path, scope_name);
323+
return cbm_arena_sprintf(ctx->arena, "%s.%s", class_qn, name);
324+
}
325+
}
326+
311327
if (state->enclosing_class_qn) {
312328
return cbm_arena_sprintf(ctx->arena, "%s.%s", state->enclosing_class_qn, name);
313329
}

‎internal/cbm/helpers.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ TSNode cbm_resolve_c_declarator_name_node(TSNode func_node);
5959
// gap #3 (and #438 for the C-declarator case).
6060
TSNode cbm_resolve_func_name(TSNode node, CBMLanguage lang);
6161

62+
// C++/CUDA out-of-line method definition (`void Foo::bar() {...}`): return the
63+
// immediate enclosing class name ("Foo") from the qualified declarator, or NULL
64+
// for a plain free function. Defined in extract_defs.c. Shared so the unified
65+
// (call-scope) extractor computes the SAME class-qualified enclosing QN as the
66+
// def extractor — drift dropped the class qualifier from in-body calls (#554/#621).
67+
char *cbm_cpp_out_of_line_parent_class(CBMArena *a, TSNode node, const char *source);
68+
6269
// Find a child node by kind string.
6370
TSNode cbm_find_child_by_kind(TSNode parent, const char *kind);
6471

‎src/cli/cli.c‎

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3120,11 +3120,24 @@ static void install_cli_agent_configs(const cbm_detected_agents_t *agents, const
31203120
snprintf(ip, sizeof(ip), "%s/.codex/AGENTS.md", home);
31213121
install_generic_agent_config("Codex CLI", binary_path, cp, ip, dry_run,
31223122
cbm_upsert_codex_mcp);
3123+
/* Choose the hook target: if ~/.codex/hooks.json already exists, the
3124+
* user manages Codex hooks via the JSON representation — write the
3125+
* SessionStart reminder there instead of config.toml. Writing both
3126+
* makes Codex warn about loading hooks from two representations (#570).
3127+
* config.toml remains the mcp_config target above either way. */
3128+
char hooks_json[CLI_BUF_1K];
3129+
snprintf(hooks_json, sizeof(hooks_json), "%s/.codex/hooks.json", home);
3130+
bool use_hooks_json = cbm_file_exists(hooks_json);
3131+
const char *hook_target = use_hooks_json ? hooks_json : cp;
31233132
if (g_install_plan) {
3124-
plan_record("Codex CLI", "hook", cp);
3133+
plan_record("Codex CLI", "hook", hook_target);
31253134
} else {
31263135
if (!dry_run) {
3127-
cbm_upsert_codex_hooks(cp);
3136+
if (use_hooks_json) {
3137+
cbm_upsert_gemini_session_hooks(hooks_json);
3138+
} else {
3139+
cbm_upsert_codex_hooks(cp);
3140+
}
31283141
}
31293142
printf(" hooks: SessionStart (codebase-memory-mcp reminder)\n");
31303143
}
@@ -3183,6 +3196,36 @@ static void install_cli_agent_configs(const cbm_detected_agents_t *agents, const
31833196
}
31843197
}
31853198

3199+
/* Scan Code/User/profiles/ and install (or plan) a per-profile mcp.json for
3200+
* each existing profile subdirectory, so VS Code profile users inherit the MCP
3201+
* server without manual steps (#431). No-op when profiles/ is absent. */
3202+
static void install_vscode_profile_configs(const char *code_user, const char *binary_path,
3203+
bool dry_run) {
3204+
char profiles_dir[CLI_BUF_1K];
3205+
snprintf(profiles_dir, sizeof(profiles_dir), "%s/profiles", code_user);
3206+
cbm_dir_t *d = cbm_opendir(profiles_dir);
3207+
if (!d) {
3208+
return;
3209+
}
3210+
cbm_dirent_t *ent;
3211+
while ((ent = cbm_readdir(d)) != NULL) {
3212+
if (strcmp(ent->name, ".") == 0 || strcmp(ent->name, "..") == 0) {
3213+
continue;
3214+
}
3215+
char profile_path[CLI_BUF_1K];
3216+
snprintf(profile_path, sizeof(profile_path), "%s/%s", profiles_dir, ent->name);
3217+
struct stat st;
3218+
if (stat(profile_path, &st) != 0 || !S_ISDIR(st.st_mode)) {
3219+
continue;
3220+
}
3221+
char cp[CLI_BUF_1K];
3222+
snprintf(cp, sizeof(cp), "%s/mcp.json", profile_path);
3223+
install_generic_agent_config("VS Code", binary_path, cp, NULL, dry_run,
3224+
cbm_install_vscode_mcp);
3225+
}
3226+
cbm_closedir(d);
3227+
}
3228+
31863229
/* Install MCP configs for editor-based agents (Zed, KiloCode, VS Code, OpenClaw). */
31873230
static void install_editor_agent_configs(const cbm_detected_agents_t *agents, const char *home,
31883231
const char *binary_path, bool dry_run) {
@@ -3215,14 +3258,21 @@ static void install_editor_agent_configs(const cbm_detected_agents_t *agents, co
32153258
cbm_install_editor_mcp);
32163259
}
32173260
if (agents->vscode) {
3218-
char cp[CLI_BUF_1K];
3261+
char code_user[CLI_BUF_1K];
32193262
#ifdef __APPLE__
3220-
snprintf(cp, sizeof(cp), "%s/Library/Application Support/Code/User/mcp.json", home);
3263+
snprintf(code_user, sizeof(code_user), "%s/Library/Application Support/Code/User", home);
32213264
#else
3222-
snprintf(cp, sizeof(cp), "%s/Code/User/mcp.json", cbm_app_config_dir());
3265+
snprintf(code_user, sizeof(code_user), "%s/Code/User", cbm_app_config_dir());
32233266
#endif
3267+
char cp[CLI_BUF_1K];
3268+
snprintf(cp, sizeof(cp), "%s/mcp.json", code_user);
32243269
install_generic_agent_config("VS Code", binary_path, cp, NULL, dry_run,
32253270
cbm_install_vscode_mcp);
3271+
/* VS Code profiles each keep their own settings under
3272+
* Code/User/profiles/<id>/. The default mcp.json above does NOT apply
3273+
* to a named profile, so write/plan a per-profile mcp.json for every
3274+
* existing profile directory (#431). */
3275+
install_vscode_profile_configs(code_user, binary_path, dry_run);
32263276
}
32273277
if (agents->cursor) {
32283278
char cp[CLI_BUF_1K];

0 commit comments

Comments
 (0)