dsh-brain/docs/plans/REPO_CLEANUP_PLAN.md

119 lines
8.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# P1 · 仓库整理实施方案(Repo Cleanup)
版本:v1(规划稿,本会话只做规划,不实施)
日期:2026-11-24
依据:LOCAL_MEMORY_PLAN.md §19 + 本轮逐项核实(39 个 verify 脚本的引用扫描、Git 状态、目录实测)。
执行归属:实施会话/人工;每步独立 commit,门禁见 §7。
## 0. 前置核对(执行前必读)
**基线已固化(2026-11-24 20:33 复核)**:P0 完成——HEAD `1dfc7c7`(0.10.1 本地记忆+Mnemon 集成),
tag `v0.10.1`,工作树干净,已推送 origin/main。本方案的回滚点即 v0.10.1。
C0 仍保留"动手前再核对一次 Git 状态"的动作,防执行时隔了新的改动。
## 1. 现状盘点(已核实事实)
根目录现有内容分类:
| 类别 | 内容 | 处置 |
| --- | --- | --- |
| 源码/产物(保留原位) | src/ client/ lib/ vendor/ scripts/ docs/ | 不动(lib 是发布入口,.gitignore 明确入库) |
| 验证脚本 ×39 | 根目录 verify-*.mjs(26 tracked + 13 untracked) | 迁入 tests/verification/(§3) |
| 预览生成器 ×3 | preview-card/import-mcp.mjs(tracked) | 迁入 scripts/preview/,输出改 artifacts/preview(§4) |
| 可再生输出 | _preview/(2.3 MB,12 个 html/png,已忽略) | 删除,可由生成器重建 |
| 索引缓存 | .codegraph/cache(26.7 MB,已忽略) | 保留不动(重建成本高,非垃圾) |
| 历史会话导出 | .codegraph/*.txt ×4(planning-context、session-recap-b1×2、mnemon-storage-investigation)+ code-graph.json/CODE-GRAPH.md/manifest.json | txt 移入 artifacts/analysis/;json/md 是 codegraph 工具自身数据,留在 .codegraph |
| §19.2 列举的旧临时文件 | .tmp-b1.txt、.review-context.txt 等 10 项 | **已不存在**(本轮实测根目录无任何 .tmp*),无需清理 |
| 项目记忆数据 | .dsh/brain/(已忽略) | 不动,不混入 artifacts |
其他事实:
- package.json 的 verify/test 都指向 scripts/verify-all.mjs;typecheck/build/prepack 不涉及根目录脚本。
- .npmignore 已排除 *.mjs 与 scripts/,files 字段只含 lib/client/cordis.patch.yml/README/LICENSE——**迁移不影响发布件**。
- pack-guard.mjs / release-prep.mjs / fork-mnemon.mjs 无 verify-*/_preview/.codegraph 引用(已扫描)。
- .gitignore 已含 artifacts/、_preview/、.tmp-*、.codegraph/ 规则,artifacts 目录建立后无需新增忽略规则。
## 2. 目标目录(沿用 §19.1,微调预览生成器归属)
dsh-brain/
├─ docs/plans/ ← 方案(已就位:LOCAL_MEMORY/NEXT_PHASE/DEPARTMENT/本文档)
├─ tests/verification/ ← 39 个 verify-*.mjs 统一收纳
├─ scripts/
│ ├─ verify-all.mjs ← 扫描目录改为 tests/verification
│ └─ preview/ ← 3 个 preview-*.mjs 生成器(源码归 scripts)
├─ artifacts/ ← 已忽略,不提交
│ ├─ analysis/ ← .codegraph 历史 txt 导出
│ ├─ logs/ ← 预留:验证/运行日志
│ └─ preview/ ← 预览生成器的新输出目录(替代 _preview)
├─ src/ client/ lib/ vendor/ ← 不动
└─ 根目录 ← 只剩标准配置 + README + LICENSE
## 3. 验证脚本迁移(核心步骤,引用已全量扫描)
39 个脚本的项目引用只有三种形态,全部要改:
1. **相对导入 `./lib/...`(36 个脚本)** → 改 `../../lib/...`。
涉及 api/store/config/reporter/kernel/entries/local-memory/mnemon/skills 等,
逐脚本正则替换 `from './lib/` → `from '../../lib/`(含动态 import())。
2. **cwd 相对读取(1 个)**:verify-theme.mjs 读 `'./client/index.js'`。
verify-all 以 cwd=root 跑子进程,迁移后 cwd 不变则仍可用;
但为消除 cwd 依赖,统一改成基于 import.meta.url 定位仓库根(与第 3 类同法)。
3. **here 相对读取(2 个)**:verify-card-debug/card-render 用
`dirname(fileURLToPath(import.meta.url))` join 'client'。
迁移后 here 变成 tests/verification,须改为 `join(here,'..','..','client')`
或引入统一的 root 常量。
配套改动:
- scripts/verify-all.mjs:扫描目录从仓库根改为 `join(root,'tests','verification')`;
子进程 cwd 保持仓库根不变(保证第 2 类兼容);文件名过滤正则不变。
- README.md:8 处 `node verify-*.mjs` 示例路径更新为 `node tests/verification/verify-*.mjs`。
- docs/management-surface.md:约 20 处脚本名提及多为纯文件名(无路径),核对后仅改带路径的。
- docs/plans/LOCAL_MEMORY_PLAN.md §19 与验收文档中的路径描述追加"已迁移"注记,不改历史记录正文。
**保留红线(§19.3)**:verify-review-fixes.mjs、src/version.ts、lib/version.js 是成果;
.tmp-remote-skill-sync.ts 若在其他检出存在,归并前不得删(本检出未见此文件)。
## 4. 预览生成器与输出
- preview-card/import/mcp.mjs 迁至 scripts/preview/(tracked 源码,git mv 保历史)。
- 三个脚本的 outDir 从 `join(here,'_preview')` 改为仓库根下 `artifacts/preview`
(here 现在指向 scripts/preview,用 `join(here,'..','..','artifacts','preview')`)。
- README 中 `node preview-card.mjs` 的调用示例同步更新。
- 旧 _preview/(2.3 MB)确认生成器可重建后删除;.gitignore 的 _preview/ 规则可留可删(建议留,防旧工具复活)。
## 5. 历史导出归档
- .codegraph/planning-context.txt、session-recap-b1.txt、session-recap-b1-full.txt、
mnemon-storage-investigation.txt → 移入 artifacts/analysis/(移动即出 Git 视野,因 .codegraph 本就忽略)。
- .codegraph/code-graph.json、CODE-GRAPH.md、manifest.json、cache/ 留在原地(工具工作数据)。
- 本轮解码产生的 .codegraph/cache/dept-*.jsonl、sess-*.jsonl 属可重建缓存,随 cache 保留或由实施者清理,不影响仓库。
## 6. 执行切片(每步独立 commit + 验证)
| 步 | 动作 | commit 主题 | 验证 |
| --- | --- | --- | --- |
| C0 | 核对 Git 基线(§0),产出待处理清单 | 无(只读) | 清单评审 |
| C1 | 建 tests/verification + git mv 39 个脚本 + 改三类引用 + verify-all 扫描目录 | refactor(tests): move verify scripts into tests/verification | typecheck + build + npm run verify 全绿(38 过 + 2 环境跳过口径不变) |
| C2 | 预览生成器迁 scripts/preview + 输出改 artifacts/preview + 删 _preview | chore(preview): relocate generators and outputs | 跑一次 preview-card 确认产物落 artifacts/preview |
| C3 | .codegraph 历史 txt 归档 artifacts/analysis + 建 artifacts/logs 占位 | chore(artifacts): archive historical exports | git status 干净度核对 |
| C4 | README / management-surface / 计划文档路径注记 | docs: update paths after repo cleanup | 文档内路径抽查 |
| C5 | 终验:typecheck + build + verify-all + verify-plugin-entry + npm pack --dry-run 比对 files 清单 | 无(验证) | 发布件与整理前一致(lib/client 字节不变) |
预计工作量:半天~1 天(C1 占大头,36 个脚本的机械替换 + 全量验证)。
## 7. 门禁与回滚
1. C0 清单先行:任何删除/移动前列出文件名、来源、Git 状态(§19.4)。
2. 每步 commit 独立,出问题 revert 单步即可;C1 之前打轻量 tag(如 pre-cleanup)可选。
3. lib/ client/ src/ vendor/ 的字节在本阶段**零改动**——整理只动位置与引用,
npm pack --dry-run 前后对比作为硬证据。
4. artifacts/ 不提交;.dsh/brain 数据不进 artifacts;不误加忽略规则覆盖源码。
5. 完成后根目录仅剩:配置文件(package/tsconfig/git/npm 系)、README、LICENSE、
cordis.patch.yml 与标准目录。
## 8. 与后续阶段的衔接
- 本方案即 NEXT_PHASE_PLAN 的 P1;推荐执行序中排在 P1.5 部门接线之后
(部门 D1–D4 会新增 verify-departments-wiring.mjs,先接线后迁移可少搬一次)。
- 若用户决定先整理后接线,本方案同样成立:新验证脚本直接写进 tests/verification 即可。
- P2 cloud-sync 的新 verify-cloud-sync-*.mjs 一律出生在新位置,不再回落根目录。