Skip to content

fix(import): --dir code extraction + --skip-enrich batch pass-through + AI timeout/logging#76

Merged
jeff-r2026 merged 1 commit into
Tencent:mainfrom
m0Nst3r873:main
Jun 30, 2026
Merged

fix(import): --dir code extraction + --skip-enrich batch pass-through + AI timeout/logging#76
jeff-r2026 merged 1 commit into
Tencent:mainfrom
m0Nst3r873:main

Conversation

@m0Nst3r873

@m0Nst3r873 m0Nst3r873 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Multiple import improvements and fixes from E2E testing:

1. teamai import --dir <path> now runs code extraction

Previously --dir scanned for markdown files and did AI classification. Now it runs the same code knowledge extraction pipeline as --from-repo (extractCodebase + graph aggregation), just without the clone step. This is an intentional breaking change — the old markdown-scan behavior is preserved under --from-claude for rule file migration.

teamai import --dir ./my-project --skip-enrich

2. Remove --workspace (superseded by --dir .)

--workspace only generated a narrative codebase.md via AI — no graph, no structured knowledge, required AI to be available. It is fully superseded by --dir . which produces a complete teamwiki knowledge graph deterministically. Removed entirely (not hidden).

3. --skip-enrich correctly passed through batch import

--skip-enrich was only applied to --from-repo (single). Now correctly threaded through:

  • import.tsimportFromRepoList → each importFromRepo
  • import.tsimportFromOrgimportFromRepoList

E2E result: 11 repos batch import in 11 seconds (was 300s+ timeout before).

4. AI timeout extended to 10 minutes

DEFAULT_TIMEOUT_MS changed from 120s to 600s. Large repos with many modules need more time for AI document generation. Comment documents applicable scenarios.

5. AI model name in logs

  • callClaude logs CLI name on first use and per-call (visible with --verbose)
  • generateCodebaseMd and enrichWithAI log which CLI model is being used
  • Exported getAICliName() for use by other modules

6. Push success hint with repo URL

All import paths now log after successful push:

✔ 已推送到团队知识仓库 (https://git.woa.com/team/repo.git)

7. Fix http-repo-integration test

Test was failing because detectProjectConfig() found a stale .teamai/config.yaml in cwd. Fixed by chdir to tmpDir.

Review feedback addressed

Issue Fix
--output still wrote to team-repo --output now writes to specified dir only, skips team-repo entirely
fs.remove(srcWiki) could delete user's existing teamwiki/ Extract output now goes to a tmpdir; source directory never touched
Dead code opts.dir ?? '.' Removed (branch guarantees opts.dir is truthy)
CLI description still mentions "git workspace" Updated to current actual sources
--dir path has no unit tests Added 6 tests covering all paths
DEFAULT_TIMEOUT_MS has no rationale comment Added detailed comment explaining applicable scenarios
os dynamic import unnecessary Changed to static top-level import
Stale --workspace reference in codebase.ts error message Updated to --dir <path>
--dry-run still ran full extractCodebase (up to 10min AI call) Now early-returns before extraction, consistent with --from-repo behavior

E2E verification

Test Result
T1-T4 (init/pull/hooks/recall)
T5 import --from-repo --skip-enrich ✅ 4s, no AI warn
T6 import --from-org --skip-enrich (11 repos) ✅ 11s, 0 failures
T7 graph integrity (1179 nodes, 794 edges)
T8 codebase --lint
T9 doctor
import --dir (local project) ✅ 10 nodes, 5 edges, global graph aggregated
import --dir --output /tmp/draft ✅ writes to output dir, source dir clean

Test plan

  • npx tsc --noEmit — zero errors
  • npx vitest run — 1672 passed (128 files)
  • E2E: 9/9 modules passed
  • import --dir unit tests: 6 tests covering all paths
  • import --dir ./project --skip-enrich produces correct graph
  • import --dir --output <dir> writes only to output, no team-repo side effects
  • import --dir --dry-run skips extraction entirely (no AI call, instant return)
  • Source directory teamwiki/ not created or modified
  • tmpdir cleaned up even on error (finally block)
  • --workspace removed, no references remain

@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, /review)。两条实质问题(数据完整性 / 数据丢失)+ 两条清理项,已作为行内评论附在对应位置。--skip-enrich 全链路贯通、graph-index 路径一致性、getAICliName 引入均已核对,无可触发缺陷。

Comment thread src/import.ts Outdated
await aggregateGlobalGraph(teamwikiRoot);

// 推送
if (!opts.output) {

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.

--output--dir 下不再生效,且仍会修改团队仓库。 整个「复制 evidence 到 team-repo + 聚合全局图谱」代码块只受 if (!opts.dryRun) 保护,--output 仅在这里用于跳过 git push。但其它分支中 --output 的语义是「写草稿到指定目录、不碰团队仓库」(见选项注释)。

结果:teamai import --dir ./proj --output /tmp/draft 既不会写入 /tmp/draft,又会直接覆盖写入 teamRepoPath/teamwiki/evidence/code/<slug> 和全局 graph-index.json(只是没 push)。建议在 --output 时把产物写到该目录、并跳过对团队仓库的写入与聚合。

Comment thread src/import.ts Outdated
await fs.copy(srcGraph, path.join(destGraphDir, 'graph-index.json'), { overwrite: true });
}
log.info(`teamwiki/ 知识图谱已更新: ${slug}`);
await fs.remove(srcWiki);

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.

无条件 fs.remove(srcWiki) 可能删除被扫描目录中预先存在的 teamwiki/,造成数据丢失。 srcWiki = <dirPath>/teamwikiextractCodebase 会写入并合并到该目录,这里又无条件整目录删除,未区分本次新建还是用户原有。

对一个本身维护 teamwiki/ 的项目(如团队知识仓库自身,或用过 team-wiki-codebase 的项目)执行 teamai import --dir .,会先污染既有 teamwiki/ 再整体删除,用户原有图谱不可恢复。建议提取产物落到临时目录,或仅删除本次新建的内容。

Comment thread src/import.ts Outdated
codebaseOutputPath = path.join(repoPath, 'codebase.md');
} else if (opts.dir) {
// 分支 3:--dir <path>,代码知识提取(等同于 --from-repo 但跳过 clone)
const dirPath = path.resolve(opts.dir ?? '.');

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.

死代码:本行位于 else if (opts.dir) 分支内,opts.dir 必为真值,?? '.' 永不触发。建议简化为 path.resolve(opts.dir),否则会误导读者以为存在「--dir 缺省为当前目录」的逻辑。

Comment thread src/index.ts Outdated
@@ -590,9 +590,8 @@ program
program
.command('import')
.description('Import knowledge from local files, Claude/Cursor rules, git workspace, MRs, or iWiki')

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.

描述仍写着已被本 PR 删除的 “git workspace” 导入来源。--workspace 已整体移除,--help 不应再宣传它。建议更新为 local directory / repo / MRs / iWiki 等当前实际来源。

@m0Nst3r873 m0Nst3r873 force-pushed the main branch 4 times, most recently from e39a4ff to 262d3f9 Compare June 30, 2026 12:15
… to batch + push success hint

Three fixes:

1. `teamai import --dir <path>` now runs extractCodebase + graph
   aggregation (same as --from-repo) instead of the old markdown
   scan + AI classify flow. The old behavior is preserved under
   --from-claude for rule file migration.

2. --skip-enrich was not passed through the batch import chain
   (import.ts → importFromRepoList → importFromRepo). Now correctly
   threaded through all call sites including --from-org.

3. All import paths now log "已推送到团队知识仓库" after successful
   autoPushTeamRepo, so users know the knowledge is shared.

Also fixes http-repo-integration test (chdir to tmpDir before push
to avoid stale project config in cwd).
@jeff-r2026 jeff-r2026 merged commit 0bb9f58 into Tencent:main Jun 30, 2026
7 checks passed
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