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(fqn): keep structural nodes from dir-module QN collision; correct dotfile module QN

Martin Vogele51c93554f87
diff --git a/internal/cbm/helpers.c b/internal/cbm/helpers.c
index da3fe7f9d..c079c5b96 100644
--- a/internal/cbm/helpers.c
+++ b/internal/cbm/helpers.c
@@ -1109,6 +1109,15 @@ bool cbm_is_module_level(TSNode node, CBMLanguage lang) {
static size_t strip_ext_len(const char *s, size_t len) {
for (size_t i = len; i > 0; i--) {
if (s[i - SKIP_ONE] == '.') {
+ /* A dot at the very start of a filename segment (index 0, or right
+ * after a '/') is a DOTFILE marker (".env", ".gitignore"), NOT an
+ * extension separator. Stripping there leaves an empty stem whose
+ * module QN collides with the parent directory/project root. Keep
+ * the whole name as the stem; the leading dot is dropped later in
+ * append_path_segments. */
+ if (i - SKIP_ONE == 0 || s[i - SKIP_ONE - SKIP_ONE] == '/') {
+ return len;
+ }
return i - SKIP_ONE;
}
if (s[i - SKIP_ONE] == '/') {
@@ -1144,9 +1153,22 @@ static char *append_path_segments(char *out, const char *rel_path, size_t plen,
if (part_len > 0) {
bool is_last = (part_end == end_ptr);
if (!should_skip_fqn_part(start, part_len, is_last, has_name)) {
- *out++ = '.';
- memcpy(out, start, part_len);
- out += part_len;
+ /* Drop a leading '.' from a dotfile / hidden-dir segment
+ * (".env" -> "env", ".github" -> "github"). Otherwise the QN
+ * separator '.' plus the segment's own leading '.' produce a
+ * malformed "proj..env" double-dot, and a root dotfile's empty
+ * stem collides with the project QN. */
+ const char *seg = start;
+ size_t seg_len = part_len;
+ if (seg[0] == '.') {
+ seg++;
+ seg_len--;
+ }
+ if (seg_len > 0) {
+ *out++ = '.';
+ memcpy(out, seg, seg_len);
+ out += seg_len;
+ }
}
}
start = part_end + SKIP_ONE;
diff --git a/src/graph_buffer/graph_buffer.c b/src/graph_buffer/graph_buffer.c
index ef94f9839..e0ebcd7ad 100644
--- a/src/graph_buffer/graph_buffer.c
+++ b/src/graph_buffer/graph_buffer.c
@@ -593,7 +593,19 @@ int64_t cbm_gbuf_upsert_node(cbm_gbuf_t *gb, const char *label, const char *name
* label == existing->label), so the old value is replaced, never freed. */
char *new_name = heap_strdup(name);
char *new_props = properties_json ? heap_strdup(properties_json) : NULL;
- existing->label = (char *)gb_intern(gb, label);
+ /* Don't let a per-file "Module" def downgrade a structural directory node
+ * ("Project" root or "Folder"). In a directory-based-module language
+ * (Go/Java) a file's module_qn equals its directory QN: a root file →
+ * the project name (== the "Project" node's QN); a file in pkg/ →
+ * proj.pkg (== the "pkg/" Folder node's QN). Its always-emitted Module
+ * def collides here; the directory node is the package/module container
+ * and must keep its structural label. (Both the sequential upsert and the
+ * parallel local-gbuf merge route through this function.) */
+ if (!(existing->label && label && strcmp(label, "Module") == 0 &&
+ (strcmp(existing->label, "Project") == 0 ||
+ strcmp(existing->label, "Folder") == 0))) {
+ existing->label = (char *)gb_intern(gb, label);
+ }
free(existing->name);
existing->name = new_name;
existing->file_path = (char *)gb_intern(gb, file_path);