fix(import): --dir code extraction + --skip-enrich batch pass-through + AI timeout/logging#76
Conversation
jeff-r2026
left a comment
There was a problem hiding this comment.
Code review (medium effort, /review)。两条实质问题(数据完整性 / 数据丢失)+ 两条清理项,已作为行内评论附在对应位置。--skip-enrich 全链路贯通、graph-index 路径一致性、getAICliName 引入均已核对,无可触发缺陷。
| await aggregateGlobalGraph(teamwikiRoot); | ||
|
|
||
| // 推送 | ||
| if (!opts.output) { |
There was a problem hiding this comment.
--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 时把产物写到该目录、并跳过对团队仓库的写入与聚合。
| await fs.copy(srcGraph, path.join(destGraphDir, 'graph-index.json'), { overwrite: true }); | ||
| } | ||
| log.info(`teamwiki/ 知识图谱已更新: ${slug}`); | ||
| await fs.remove(srcWiki); |
There was a problem hiding this comment.
无条件 fs.remove(srcWiki) 可能删除被扫描目录中预先存在的 teamwiki/,造成数据丢失。 srcWiki = <dirPath>/teamwiki;extractCodebase 会写入并合并到该目录,这里又无条件整目录删除,未区分本次新建还是用户原有。
对一个本身维护 teamwiki/ 的项目(如团队知识仓库自身,或用过 team-wiki-codebase 的项目)执行 teamai import --dir .,会先污染既有 teamwiki/ 再整体删除,用户原有图谱不可恢复。建议提取产物落到临时目录,或仅删除本次新建的内容。
| codebaseOutputPath = path.join(repoPath, 'codebase.md'); | ||
| } else if (opts.dir) { | ||
| // 分支 3:--dir <path>,代码知识提取(等同于 --from-repo 但跳过 clone) | ||
| const dirPath = path.resolve(opts.dir ?? '.'); |
There was a problem hiding this comment.
死代码:本行位于 else if (opts.dir) 分支内,opts.dir 必为真值,?? '.' 永不触发。建议简化为 path.resolve(opts.dir),否则会误导读者以为存在「--dir 缺省为当前目录」的逻辑。
| @@ -590,9 +590,8 @@ program | |||
| program | |||
| .command('import') | |||
| .description('Import knowledge from local files, Claude/Cursor rules, git workspace, MRs, or iWiki') | |||
There was a problem hiding this comment.
描述仍写着已被本 PR 删除的 “git workspace” 导入来源。--workspace 已整体移除,--help 不应再宣传它。建议更新为 local directory / repo / MRs / iWiki 等当前实际来源。
e39a4ff to
262d3f9
Compare
… 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).
Summary
Multiple import improvements and fixes from E2E testing:
1.
teamai import --dir <path>now runs code extractionPreviously
--dirscanned 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-claudefor rule file migration.2. Remove
--workspace(superseded by--dir .)--workspaceonly generated a narrativecodebase.mdvia 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-enrichcorrectly passed through batch import--skip-enrichwas only applied to--from-repo(single). Now correctly threaded through:import.ts→importFromRepoList→ eachimportFromRepoimport.ts→importFromOrg→importFromRepoListE2E result: 11 repos batch import in 11 seconds (was 300s+ timeout before).
4. AI timeout extended to 10 minutes
DEFAULT_TIMEOUT_MSchanged 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
callClaudelogs CLI name on first use and per-call (visible with--verbose)generateCodebaseMdandenrichWithAIlog which CLI model is being usedgetAICliName()for use by other modules6. Push success hint with repo URL
All import paths now log after successful push:
7. Fix http-repo-integration test
Test was failing because
detectProjectConfig()found a stale.teamai/config.yamlin cwd. Fixed by chdir to tmpDir.Review feedback addressed
--outputstill wrote to team-repo--outputnow writes to specified dir only, skips team-repo entirelyfs.remove(srcWiki)could delete user's existingteamwiki/opts.dir ?? '.'opts.diris truthy)--dirpath has no unit testsDEFAULT_TIMEOUT_MShas no rationale commentosdynamic import unnecessary--workspacereference in codebase.ts error message--dir <path>--dry-runstill ran full extractCodebase (up to 10min AI call)--from-repobehaviorE2E verification
Test plan
npx tsc --noEmit— zero errorsnpx vitest run— 1672 passed (128 files)import --dirunit tests: 6 tests covering all pathsimport --dir ./project --skip-enrichproduces correct graphimport --dir --output <dir>writes only to output, no team-repo side effectsimport --dir --dry-runskips extraction entirely (no AI call, instant return)teamwiki/not created or modified--workspaceremoved, no references remain