Skip to content

[bug] codebase 图谱检索多处缺陷(不递归/camelCase 失效/全局图被覆盖/tokenizer 不一致) #84

Description

@jeff-r2026

codebase 图谱检索链路(src/code-knowledge-recall.ts / src/codebase-extract.ts)的若干缺陷,单独成条便于逐个修复:

1. loadWikiPages 不递归,子目录页面检索不到

// src/code-knowledge-recall.ts:217-242
files = await readdir(projectDir); // 只读项目根一层 *.md

而 extract 会在 modules/*.md 生成模块页(src/codebase-extract.ts:618-624),这些页永远进不了检索
建议:改用 listFilesRecursive / glob **/*.md

2. camelCase 拆分永久失效

// src/code-knowledge-recall.ts:43-45
const lower = text.toLowerCase();
const camelSplit = lower.replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase();

toLowerCase() 再做 ([a-z])([A-Z]) 替换——小写后已无大写字母,注释写的“B4 fix: camelCase splitting”实际从不执行getUserNameApiTimeout 等查询无法被拆词命中。
建议:在 toLowerCase() 之前做 camelCase split。

3. extractCodebase 覆盖全局图谱(多仓互相覆盖)

// src/codebase-extract.ts:573-577
saveGraphIndex(wikiRoot, mergedGraph); // 直接写全局 .indices/graph-index.json,不 merge 已有

单仓 extract 直接覆盖全局 graph-index.json,不合并已有内容;多仓 wiki 会被最后一次 extract 覆盖(只有 graph-aggregate.ts 才做多仓合并)。
建议:extract 只写 per-repo 图,再调 aggregateGlobalGraph;或 save 前先 load + merge。

4. 两套 tokenizer 不一致

learnings 索引用 Intl.Segmenter(保留单字 CJK token,src/utils/search-index.ts:213-253),codebase 用正则 + 仅 bigram(src/code-knowledge-recall.ts:41-57)。同一中文 query 在两侧产生不同 token 集,跨源召回不一致。
建议:抽取共享 tokenize() 供两路复用。

5. loadGraphIndex 对畸形 JSON 不健壮

文件缺失/parse 失败会返回 null(OK),但不校验 nodes/edges 是否为数组(src/wiki-engine/core/graph-index.schema.ts:351-358);半损坏的 graph-index.json 会让 recall 的 codebase 分支整段进 catch。
建议:load 后做最小 schema guard + 空图 fallback。

严重程度:中。

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions