Skip to content

feat(import): MR-triggered incremental teamwiki update - #112

Merged
jeff-r2026 merged 1 commit into
Tencent:mainfrom
m0Nst3r873:feat/mr-triggered-wiki-update
Jul 2, 2026
Merged

feat(import): MR-triggered incremental teamwiki update#112
jeff-r2026 merged 1 commit into
Tencent:mainfrom
m0Nst3r873:feat/mr-triggered-wiki-update

Conversation

@m0Nst3r873

Copy link
Copy Markdown
Collaborator

Summary

Redesign import --from-mr and ci extract-mr to trigger true incremental teamwiki updates, and implement facts-cache-based incremental output in extractCodebase.

Key changes

True incremental output (src/codebase-extract.ts):

  • New facts cache (teamwiki/.indices/facts-cache.json) persists extracted facts across runs
  • New interfaces cache (teamwiki/.indices/interfaces-cache.json) persists interface inventory
  • Incremental mode: load cache → prune facts from changed/deleted files → merge with new facts → regenerate all derived outputs from complete data
  • Hash-compare writes (writeIfChanged): only writes files that actually changed, preserving mtime on unchanged outputs
  • Fixed source-manifest.json bug: 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, triggers importFromRepo(incremental: true) on the affected repo, then pushes all changes via MR
  • ci extract-mr write mode: adds deepEnrich call after extractCodebase, producing G1-G6 + index updates
  • CI comment now includes "teamwiki knowledge base update preview" showing affected modules

Removed deprecated pipeline:

  • Removed CodebaseSuggestion AI pipeline from importFromMR (was targeting obsolete docs/codebase.md)
  • Removed --existing-codebase CLI option
  • Marked applyCodebaseSuggestions as @deprecated

Push strategy

Scenario Method Reason
CI pipeline (ci extract-mr) pushRepoDirectly Reviewer already approved via MR comment
Interactive (import --from-mr) autoPushViaMR Creates branch + MR for review

Test plan

  • 129 test files, 1581 tests passing
  • TypeScript type check clean
  • E2E: init → pull → import org (11 repos) → recall → graph integrity all passing
  • CI extract-mr tests updated for new API contract

🤖 Generated with Claude Code

@m0Nst3r873
m0Nst3r873 force-pushed the feat/mr-triggered-wiki-update branch from ff5df2d to 18ba738 Compare July 2, 2026 07:49

@jeff-r2026 jeff-r2026 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review — Medium Effort

这个 PR 将 import --from-mrci 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:697extractRepoUrlFromMrUrl 的 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.tsmr-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:98pruneInterfacesByFiles 粒度过粗

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

@m0Nst3r873
m0Nst3r873 force-pushed the feat/mr-triggered-wiki-update branch from 18ba738 to 4dac2bd Compare July 2, 2026 08:31
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.
@m0Nst3r873
m0Nst3r873 force-pushed the feat/mr-triggered-wiki-update branch from 4dac2bd to cb6d694 Compare July 2, 2026 08:34
@jeff-r2026
jeff-r2026 merged commit 251750f into Tencent:main Jul 2, 2026
7 checks passed
@hsuchifeng hsuchifeng mentioned this pull request Jul 3, 2026
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants