feat(import): MR-triggered incremental teamwiki update - #112
Conversation
ff5df2d to
18ba738
Compare
jeff-r2026
left a comment
There was a problem hiding this comment.
Code Review — Medium Effort
这个 PR 将 import --from-mr 和 ci extract-mr 重新设计为触发真正的增量 teamwiki 更新,用 facts-cache 替代了旧的 CodebaseSuggestion AI 管线。整体架构方向正确,旧代码清理干净,但增量模式的边界条件处理有几个需要关注的问题。
发现(按严重程度排序)
1. src/import.ts:171 — Learning 写入磁盘后不推送(当 repoUrl 为空时)
用户使用不匹配 regex 的 URL(如嵌套 TGit 组)运行 --from-mr 时,importFromMR 通过 repoPath 将 learning 写入磁盘,但 autoPushViaMR 嵌套在 if (!opts.dryRun && !opts.output && repoUrl) 内且无 fallback。旧代码总是无条件调用 autoPushTeamRepo。
建议: 在 if (repoUrl) 块之外添加 fallback push(当 didUpdate && !repoUrl 时回退到 autoPushTeamRepo)。
2. src/import-mr.ts:697 — extractRepoUrlFromMrUrl 的 TGit regex 不支持嵌套组
const tgitMatch = mrUrl.match(/^(https:\/\/git\.woa\.com\/[^/]+\/[^/]+)\/merge_requests\//);[^/]+\/[^/]+ 只匹配两段路径。输入 git.woa.com/group/subgroup/repo/merge_requests/123 会错误返回 group/subgroup.git。项目中其他解析器(mr-comment.ts、mr-fetch.ts)使用 (.+)\/([^/]+)\/merge_requests\/ 正确处理了此场景。
建议: 改为 /^(https:\/\/git\.woa\.com\/.+\/[^/]+)\/merge_requests\// 或直接复用 parseMrUrl。
3. src/ci/extract-mr.ts:367 — CI 中 extractCodebase 写入 business repo 且清理不在 finally 块
extractCodebase({path: businessRepo}) 将 teamwiki/ 写入 process.cwd()(CI 中是被分析的业务仓库)。清理代码 fse.remove(srcWiki) 在 try 块内(line 380),不在 finally 中——中间步骤抛异常时污染工作目录。
建议: 将 fse.remove(srcWiki) 移入 finally 块,或传 outputRoot 指向 tmpDir。
4. src/codebase-extract.ts:563 — Deletion-only 增量运行绕过缓存合并
当仅有文件删除时 changedFiles = [...added, ...changed] 得到 []。if (changedFiles && changedFiles.length > 0) 为 false(跳过缓存合并),但 if (changedFiles) 为 true(空数组 truthy)→ callChains = [],dependency-paths.md 可能被清空。
建议: 将 deletion-only 视为增量模式的一种,对 changedFiles.length > 0 || deletedFiles.length > 0 走缓存合并分支。
5. src/wiki-engine/code-knowledge/code-incremental.ts:98 — pruneInterfacesByFiles 粒度过粗
affectedDirs.add(f.split('/')[0]); // 'src/controllers/user.ts' → 'src'
inventory.entries.filter(e => !affectedDirs.has(e.component));在典型项目(所有代码在 src/ 下)中,任何单文件变更都会清空整个 interface 缓存。
建议: 按 e.file(接口来源文件)而非 e.component(顶层目录)进行精确剪枝。
🤖 Generated with Claude Code code review
18ba738 to
4dac2bd
Compare
Redesign `import --from-mr` and `ci extract-mr` to use teamwiki incremental update instead of the deprecated codebase.md suggestion pipeline: import --from-mr (interactive): - Extract learning + detect affected repo from MR URL - If repo has existing teamwiki evidence, trigger incremental importFromRepo (extractCodebase + deepEnrich + aggregateGlobalGraph) - Push all changes (learning + wiki update) via MR (autoPushViaMR) ci extract-mr (CI pipeline): - Add deepEnrich call after extractCodebase in write mode - Add teamwiki update preview to graph change MR comment - Keep pushRepoDirectly (reviewer already approved via comment) Removals: - CodebaseSuggestion AI pipeline from importFromMR (extractPrompt, reviewSuggestions, callClaudeParallel, applyCodebaseSuggestions) - --existing-codebase CLI option (no longer needed) - existingCodebaseMd parameter throughout the chain New: importFromMR returns `repoUrl` field for caller to trigger incremental update on the affected repository.
4dac2bd to
cb6d694
Compare
Summary
Redesign
import --from-mrandci extract-mrto trigger true incremental teamwiki updates, and implement facts-cache-based incremental output inextractCodebase.Key changes
True incremental output (
src/codebase-extract.ts):teamwiki/.indices/facts-cache.json) persists extracted facts across runsteamwiki/.indices/interfaces-cache.json) persists interface inventorywriteIfChanged): only writes files that actually changed, preserving mtime on unchanged outputssource-manifest.jsonbug: now records ALL files in incremental mode (not just changed subset)MR-triggered update (
src/import.ts,src/ci/extract-mr.ts):import --from-mr: after extracting learning, triggersimportFromRepo(incremental: true)on the affected repo, then pushes all changes via MRci extract-mrwrite mode: addsdeepEnrichcall afterextractCodebase, producing G1-G6 + index updatesRemoved deprecated pipeline:
CodebaseSuggestionAI pipeline fromimportFromMR(was targeting obsoletedocs/codebase.md)--existing-codebaseCLI optionapplyCodebaseSuggestionsas@deprecatedPush strategy
ci extract-mr)pushRepoDirectlyimport --from-mr)autoPushViaMRTest plan
🤖 Generated with Claude Code