Skip to content

fix(docs): remove stale local documents during pull - #817

Merged
jeff-r2026 merged 4 commits into
Tencent:mainfrom
Yong-yuan-X:fix/docs-prune-794
Sep 24, 2026
Merged

jeff-r2026 merged 4 commits into
Tencent:mainfrom
Yong-yuan-X:fix/docs-prune-794

Conversation

@Yong-yuan-X

@Yong-yuan-X Yong-yuan-X commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

修复 docs 同步只增不删的问题:团队库删除文档后,普通 teamai pull 会同步删除 sharing.docs.localDir 中的旧文件,包括嵌套文档、最后一篇文档及整个 docs 目录被删除的情况,无需新增参数或配置。

docs 同步失败时不再误报成功,后续资源仍继续同步,并清除同步版本标记以便下次 pull 重试。teamai doctor 同时检查缺失与过期文档,包括团队文档已删空但本地仍有残留的情况。

同步更新中英文使用指南和 core skill 的简短行为说明,相关单测归并到 docs.test.ts。

Type of Change

  • Bug fix
  • Breaking change:本地文档目录改为镜像同步,非隐藏的本地独有文件也会被清理

Test Plan

本地 Windows 环境已完成:

  • npx tsc --noEmit
  • npm run build
  • 本次功能的单元及集成回归测试通过
  • 构建后的真实 CLI 端到端验证通过
  • 新增及更新本次变更的测试

回归测试覆盖:

  • 普通删除、嵌套删除、空目录及整个团队 docs 目录删除。
  • 隐藏文件保留、目录链接清理及危险目标目录保护。
  • 复制或清理失败后不误报成功;复制失败时不执行后续清理。
  • docs 失败后继续同步其他资源,下次普通 pull 可以重试。
  • doctor 同时报告缺失与过期文档,且不修改本地文件。
  • dry-run 不执行实际删除。

Real CLI Verification

构建后,在隔离 HOME、本地 Git 远端及 Claude 工具目录环境中,执行实际 dist/index.js pull 和 doctor --json:

  1. 首次拉取两篇文档,确认文档落盘。
  2. 团队库删除一篇嵌套文档并更新另一篇,提交后再次普通 pull:旧文档和空目录删除,保留文档内容更新。
  3. 同步完成后,doctor 的文档检查通过。
  4. 团队库删除全部文档并提交,更新本地团队仓库副本:doctor 能识别本地残留的旧文档。
  5. dry-run 保留本地文件;随后普通 pull 清理全部旧文档。
  6. 清理后 doctor 不再报告文档残留,隐藏文件始终保留,再次 pull 正常进入已同步路径。

以上流程没有使用 prune 开关

Related Issues

Fixes #794

Notes for Reviewers

  • localDir 应为专用文档目录:镜像同步也会删除本地独有的非隐藏草稿。
  • 隐藏文件和隐藏目录保留;清理目录链接时不遍历其目标。
  • 先复制再清理,复制失败时不执行后续删除。
  • 拒绝可能覆盖团队仓库或主目录/项目根目录的危险目标;源和目标已是同一 docs 目录时无需同步。
  • 旧版 CLI 已同步过的版本,可用 teamai pull --force 清理历史残留。

@Yong-yuan-X
Yong-yuan-X marked this pull request as ready for review September 24, 2026 15:50
@jeff-r2026 jeff-r2026 self-assigned this Sep 24, 2026
@github-actions

Copy link
Copy Markdown
  • [P1 阻断] src/resources/docs.ts:117 未处理同名条目的文件/目录类型变化。若团队仓库把 guide/ 改为 guide 文件(或反向),目标端仍是旧类型,fse.copy() 会在 pruneDocs() 执行前因类型冲突失败;后续普通 pull 会持续重试并持续失败,无法形成镜像。需在复制前安全替换冲突条目,或通过临时目录完成镜像切换。

PR 描述已包含构建后真实 CLI 端到端验证记录,测试说明符合要求。

@github-actions

Copy link
Copy Markdown
  • [P2 非阻断] src/pull.ts:1507 的失败状态没有跨 scope 聚合。项目启用 inheritUserScope 时,若继承的 user scope 先成功,会将共享的 result.completed 设为 true;随后 project scope 的 docs 同步失败只是不再赋值,无法撤销该状态,最终 src/index.ts:131 仍发送 “Pull Complete” webhook,继续误报部分失败的 pull 为成功。应在 pull() 层记录任一 scope 的 docs 失败,再统一决定完成状态。
  • [P3 可选] src/pull.ts:1169 在团队 docs 与本地目录的文件计数都为零时直接跳过,因此当 localDir 只剩非隐藏的空目录时,pruneDocs() 不会执行,空目录会永久残留;src/doctor-delivery.ts:682 同样不会报告它。这与文档中“过期的空目录也会删除”的行为说明不一致。

先前提出的文件/目录类型切换冲突已通过暂存替换及回滚逻辑修复,不再重复提出。PR 描述包含构建后的真实 CLI 端到端验证记录,测试说明符合要求。

@github-actions

Copy link
Copy Markdown

未发现新的确定性问题。

  • 先前 [P1 阻断] 文件/目录类型切换冲突已通过暂存替换与回滚逻辑修复。
  • 先前 [P2 非阻断] 跨 scope 完成状态误报已通过统一聚合 docsSyncFailed 修复。
  • 先前 [P3 可选] 过期空目录未清理的问题已通过空目录检测修复。
  • PR 描述包含构建后的真实 CLI 端到端验证记录,测试说明符合要求。
  • 按要求仅静态阅读指定 diff,未运行、构建或安装 PR 内容。

@jeff-r2026
jeff-r2026 merged commit 49cf3fd into Tencent:main Sep 24, 2026
11 checks passed
SaulMoro added a commit to SaulMoro/teamai-cli that referenced this pull request Sep 24, 2026
Merges Tencent#817 (docs mirror), Tencent#788/Tencent#790 and Tencent#809/Tencent#813.

The docs mirror now targets the member's resolved docs set: it copies
only the delivered files and prunes every local entry the team repo does
not have, but a local copy of a team doc in an inactive namespace follows
the Tencent#707 rule (removed when byte-equal, kept and named when edited).
Withdrawal runs inside the mirror, after the single-repo early return, so
it never deletes from the team repo's own docs/. Doctor expects the
delivered set and does not report a withheld namespace's team doc as
stale. Tencent#817's failure handling (docsSyncFailed, cleared revision,
result.completed) is kept.
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
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.

[bug]docs 同步不清理团队库已删除的文件,本地 localDir 残留孤儿文件

2 participants