From 1dca369c640da0f2a2144b1514106d54e4b704b1 Mon Sep 17 00:00:00 2001 From: babycoder-dev Date: Wed, 7 Oct 2026 16:46:29 +0800 Subject: [PATCH] docs(governance): dispose of the seven ungoverned docs, gate dangling pointers, and block work on main P2 of docs/agent-workflow.md plus a guard for a mistake I made twice in this session. Governance: archives four top-level docs into docs/archive/ with per-file headers (iteration-roadmap was self-marked obsolete since 2026-05, ai-handoff was superseded by mechanism, open-questions had zero references and mostly resolved content, github-cicd was bootstrap-era with a stale CI list), and brings three under governance with explicit authority statements (community-roadmap and good-first-issues are unreleased-project placeholders, desktop-client is a topic doc). Live content moved rather than buried: unresolved early questions into foundation-progress 7.7, CI steps and branch protection into development-workflow 8. Gates: scripts/check-doc-refs.mjs reports only references whose path was once committed and is gone, so forward-looking references do not become 32 false positives; scripts/check-branch.mjs refuses to let local main carry uncommitted changes or unpushed commits. The git pre-commit route was tried and abandoned because git here cannot spawn an extension-less hook script - an unverifiable guard is worse than none. --- README.md | 15 ++- docs/agent-workflow.md | 14 ++- docs/archive/README.md | 12 +++ docs/{ => archive}/ai-handoff.md | 5 + docs/{ => archive}/github-cicd.md | 5 + docs/{ => archive}/iteration-roadmap.md | 6 ++ docs/{ => archive}/open-questions.md | 5 + docs/community-roadmap.md | 4 + docs/development-workflow.md | 39 +++++++ docs/doc-index.md | 10 +- docs/foundation-progress.md | 15 +++ docs/goal/README.md | 2 +- docs/good-first-issues.md | 4 + docs/tasks/m5-1-rbac-data-model-scope.md | 2 +- docs/verification-log.md | 53 ++++++++++ package.json | 4 +- scripts/check-branch.mjs | 52 ++++++++++ scripts/check-doc-refs.mjs | 124 +++++++++++++++++++++++ scripts/lib/branch-rules.mjs | 36 +++++++ scripts/lib/branch-rules.spec.mjs | 37 +++++++ scripts/lib/doc-ref-rules.mjs | 60 +++++++++++ scripts/lib/doc-ref-rules.spec.mjs | 73 +++++++++++++ 22 files changed, 563 insertions(+), 14 deletions(-) create mode 100644 docs/archive/README.md rename docs/{ => archive}/ai-handoff.md (78%) rename docs/{ => archive}/github-cicd.md (72%) rename docs/{ => archive}/iteration-roadmap.md (84%) rename docs/{ => archive}/open-questions.md (84%) create mode 100644 scripts/check-branch.mjs create mode 100644 scripts/check-doc-refs.mjs create mode 100644 scripts/lib/branch-rules.mjs create mode 100644 scripts/lib/branch-rules.spec.mjs create mode 100644 scripts/lib/doc-ref-rules.mjs create mode 100644 scripts/lib/doc-ref-rules.spec.mjs diff --git a/README.md b/README.md index 64faf0d..31abf31 100644 --- a/README.md +++ b/README.md @@ -63,18 +63,23 @@ docs/ constitution.md architecture.md foundation-blueprint.md + foundation-progress.md + product-requirements.md security-baseline.md platform-core.md - im-foundation.md + module-contract.md + agent-workflow.md development-workflow.md deployment.md - github-cicd.md verification-log.md adr/ - module-contract.md - desktop-client.md - iteration-roadmap.md rfc/ + tasks/ + runbooks/ + research/ + design/ + goal/ + archive/ ``` ## 默认技术栈 diff --git a/docs/agent-workflow.md b/docs/agent-workflow.md index d7c9f22..b940de3 100644 --- a/docs/agent-workflow.md +++ b/docs/agent-workflow.md @@ -6,8 +6,8 @@ ## 0. 为什么有这份文档 项目由「人 + 多个编码代理」推进(Claude Code / Codex / DeepSeek Harness)。相关约定此前散落在 -`.claude/`、`docs/ai-handoff.md`、`docs/development-workflow.md` §6/§7 与各 `CLAUDE.md` 里, -且**手工维护的状态文档已被证明会漂移**:`docs/ai-handoff.md` 停在 M3.5(最新提交写 `9c887bd`), +`.claude/`、`docs/archive/ai-handoff.md`、`docs/development-workflow.md` §6/§7 与各 `CLAUDE.md` 里, +且**手工维护的状态文档已被证明会漂移**:`docs/archive/ai-handoff.md` 停在 M3.5(最新提交写 `9c887bd`), 而项目当时已走到 M9 合并完成——漂移约 4.5 个月,期间无人察觉。 本文件吸收 DeepSeek Harness(DSH)的机制形态,把这些约定收敛到**可执行的守卫**上,并为长任务、 @@ -43,6 +43,7 @@ | 设计还原度 B 类(人工并排比对,覆盖交互态) | 不可机器化,定稿前人工做 | 评审 | | 技能格式 | `scripts/check-skills.mjs`(`pnpm skills:validate`):`//SKILL.md` 形态、frontmatter 必填 `name`/`description`、name 与目录名一致、拒绝嵌套 | 本地 `pnpm verify` + CI | | 长任务状态 | `scripts/goal.mjs validate`(`pnpm goal:validate`) | 本地 `pnpm verify` + CI | +| 文档路径引用 | `scripts/check-doc-refs.mjs`(`pnpm doc-refs`):**只报"曾经存在、后被移动/删除"的悬空指针**(用 git 历史判定,前瞻引用与其他项目的路径不算),不扫归档与时间点快照 | 本地 `pnpm verify` + CI | **以上仓库级检查由 `pnpm check:repo` 聚合**(`pnpm verify` 与 CI 都只跑它一步);单独调试时跑各自的 script。新增检查加进 `check:repo` 即可,不必再加 CI 步骤。 @@ -111,7 +112,7 @@ hook 逻辑一律放 `scripts/hooks/*.mjs`(纯 Node;异常一律放行、绝 - **进度单一事实源** = `docs/foundation-progress.md`;会话启动由 `load-progress.mjs` 抽「总览 / 当前下一步 / 当前阻塞项」注入上下文。动态内容走 hook,**不写进 `CLAUDE.md`**(后者只留稳定指针与坑)。 -- **`docs/ai-handoff.md` 已废弃**(2026-10-07):手工维护的会话状态已被证明必然漂移——那份文档停在 +- **`docs/archive/ai-handoff.md` 已废弃**(2026-10-07):手工维护的会话状态已被证明必然漂移——那份文档停在 M3.5、最新提交写着 `9c887bd`,而项目已走到 M9 合并完成,**漂移约 4.5 个月无人察觉**;现在只保留一份 废弃说明与职责替代表。 - **长任务纪律**(借鉴 DSH goal,P1):phase = `active | paused | blocked | complete`;`blocked` 仅当 @@ -184,8 +185,11 @@ hook 逻辑一律放 `scripts/hooks/*.mjs`(纯 Node;异常一律放行、绝 `db-migration-discipline` 三个技能 + `pnpm skills:validate` 格式门禁;加载已实测)→ 一个真实 workflow 用例(✅ 已落地:文档漂移审计,8 篇 → 26 候选 → 独立复核驳回 21 → 确认 4 并全部修复; 配方与量化的驳回率见 §6)。 -- **P2 · 文档治理**:`docs/` 顶层 7 篇不在 `doc-index` 管辖内的文档逐一定性(纳入 / 归档 / 删除); - `iteration-roadmap.md`(自标已过时)归档。 +- **P2 · 文档治理(已完成)**:`docs/` 顶层 7 篇未受管辖文档逐一定性——**归档 4 篇** + (`iteration-roadmap`、`ai-handoff`、`open-questions`、`github-cicd` → `docs/archive/`,各带归档头; + 仍在生效的内容分别折进 `foundation-progress.md` §7.7 与 `development-workflow.md` §8)、 + **纳入 3 篇**(`community-roadmap`、`good-first-issues` 标注"未发布、非权威",`desktop-client` 登记)。 + 新增 `pnpm doc-refs` 门禁(悬空指针)并接入 `check:repo`。 ### 挂账(不阻塞 P1/P2) diff --git a/docs/archive/README.md b/docs/archive/README.md new file mode 100644 index 0000000..e65aaec --- /dev/null +++ b/docs/archive/README.md @@ -0,0 +1,12 @@ +# docs/archive/ —— 归档文档 + +这里放**已失效或已完成使命**的文档。约定: + +- 归档文档是**历史快照**:按当时的事实写,**不追改**(与 `docs/verification-log.md` 同理), + 因此也**不参与**「文档路径引用门禁」(`scripts/check-doc-refs.mjs`)的扫描。 +- 每个归档文件**开头必须写明**:何时归档、为什么归档、职责由谁接管。 +- 归档判据与处置方式(纳入 / 归档 / 删除)见 `docs/agent-workflow.md` §1 与 `docs/doc-index.md`。 + 要"什么被归档过"的清单,看各文件头部,或 `git log -- docs/archive/`。 + +**归档 ≠ 删除。** 保留的理由有两个:① 解释"为什么这件事不再按老办法做",避免有人重新发明; +② 保留当时的证据与措辞,便于追溯决策。 diff --git a/docs/ai-handoff.md b/docs/archive/ai-handoff.md similarity index 78% rename from docs/ai-handoff.md rename to docs/archive/ai-handoff.md index 0161ee4..bac592f 100644 --- a/docs/ai-handoff.md +++ b/docs/archive/ai-handoff.md @@ -1,5 +1,10 @@ # AI Handoff —— 已废弃(2026-10-07) +> **归档于 2026-10-07**(原 `docs/ai-handoff.md`)。归档理由:手工维护的会话交接文档, +> 自 2026-05-24 起漂移约 4.5 个月无人察觉(停在 M3.5、最新提交写 `9c887bd`,而项目已到 M9 合并完成)。 +> 职责由 `scripts/hooks/load-progress.mjs`(会话注入进度快照)、`docs/goal/`(长任务状态)与 +> git 历史接管。归档约定见 `docs/archive/README.md`。 + **本文件不再维护,其职责已被机制取代。** 保留这份说明只为留下废弃理由,避免有人再手写一份。 ## 为什么废弃 diff --git a/docs/github-cicd.md b/docs/archive/github-cicd.md similarity index 72% rename from docs/github-cicd.md rename to docs/archive/github-cicd.md index 7946638..714070b 100644 --- a/docs/github-cicd.md +++ b/docs/archive/github-cicd.md @@ -1,5 +1,10 @@ # GitHub 与 CI/CD +> **归档于 2026-10-07**(原 `docs/github-cicd.md`)。归档理由:这是仓库**引导期**的文档 +> ("是否需要上传 GitHub""初始化远程仓库"),其中 §3 的 CI 命令列表早已过期;仍未失效的两部分 +> 已折进 `docs/development-workflow.md`(CI 步骤与分支保护要求)。保留原文以记录引导期取舍。 +> 归档约定见 `docs/archive/README.md`。 + ## 1. 是否需要上传 GitHub 可以上传 GitHub,用 GitHub Actions 做 CI。若代码不能出企业网络,应改用内部 Git 服务与同等 CI 流水线。 diff --git a/docs/iteration-roadmap.md b/docs/archive/iteration-roadmap.md similarity index 84% rename from docs/iteration-roadmap.md rename to docs/archive/iteration-roadmap.md index ae2539d..ece4492 100644 --- a/docs/iteration-roadmap.md +++ b/docs/archive/iteration-roadmap.md @@ -1,5 +1,11 @@ # 迭代路径建议 +> **归档于 2026-10-07**(原 `docs/iteration-roadmap.md`)。归档理由:自 2026-05 起自标"已过时", +> 其 Phase 划分与现行里程碑不一致,且**零引用**(`README` 的目录树除外)。职责由 +> `docs/foundation-blueprint.md`(路线图)、`docs/foundation-progress.md`(进度)与 +> `docs/adr/0005-product-replan-roadmap.md` / `docs/adr/0006-vnext-roadmap.md`(决策)接管。 +> 保留原文以记录早期路线取舍。归档约定见 `docs/archive/README.md`。 + > **已过时(2026-05)。** 本文是项目早期的迭代建议,其 Phase 划分与当前里程碑已不一致 > (例如把审批/日报/通知排在在位之后、通知中心放在 Phase 5)。权威路线图以 > `docs/foundation-blueprint.md` §10、`docs/foundation-progress.md` 与 diff --git a/docs/open-questions.md b/docs/archive/open-questions.md similarity index 84% rename from docs/open-questions.md rename to docs/archive/open-questions.md index cf74d1f..9811d50 100644 --- a/docs/open-questions.md +++ b/docs/archive/open-questions.md @@ -1,5 +1,10 @@ # 待确认事项 +> **归档于 2026-10-07**(原 `docs/open-questions.md`)。归档理由:`2026-05` 时代的早期待确认清单, +> **零引用**;其中多数已解决(ORM=Drizzle、UI 自研 `@work/ui`、身份源、部署方式),**仍未决的条目已迁入 +> `docs/foundation-progress.md` §7.7**(含密码策略/等保、2FA、C/S 客户端离线与更新源、OpenIM 运维与保留策略)。 +> 保留原文以记录当时的候选方案。归档约定见 `docs/archive/README.md`。 + 以下事项不阻塞第一阶段基建,但会影响后续实现细节。 > 更新(2026-05):部分事项已定——ORM=Drizzle、数据库=PostgreSQL(见 `docs/architecture.md`);即时通讯/聊天本期不做、外部 IM 接入归 vNext(见 `docs/adr/0005-product-replan-roadmap.md`、`docs/product-requirements.md` §6)。其余仍为待确认,保留备查。 diff --git a/docs/community-roadmap.md b/docs/community-roadmap.md index 2cbc0b0..76e2097 100644 --- a/docs/community-roadmap.md +++ b/docs/community-roadmap.md @@ -1,5 +1,9 @@ # Community Roadmap +> **状态(2026-10-07)**:项目**尚未发布、无外部贡献者**(在研阶段)。本文是发布后的社区化**预留**, +> **不参与当前排期**,其阶段描述也可能滞后于实际进度。权威进度以 `docs/foundation-progress.md` 为准, +> 权威范围以 `docs/product-requirements.md` 为准。发布时需按当时状态整体重写本文。 + This roadmap explains where community contributions fit. The authoritative engineering milestones remain `docs/foundation-blueprint.md` and `docs/foundation-progress.md`; this document translates them into contributor-friendly work areas. ## Current Project Stage diff --git a/docs/development-workflow.md b/docs/development-workflow.md index db0856c..f667415 100644 --- a/docs/development-workflow.md +++ b/docs/development-workflow.md @@ -81,6 +81,16 @@ docs: document delivery workflow - 本地日志 - 未经确认的第三方源码拷贝 +**不要在 `main` 上干活。** `main` 受远端保护,本地同样走分支 + PR。`pnpm check:branch`(已进 +`pnpm check:repo`)会在 `main` 上有未提交改动或未推送提交时**直接失败**。这条规则来自一次真实教训: +2026-10-07 同一个会话里**两次**把改动直接提交到本地 `main`,两次都靠人工「建分支引用 + `reset --hard`」 +补救。提醒显然不够,所以要检查。 + +> 为什么不做成 git `pre-commit` hook:本机 git 无法 spawn 无扩展名的 hook 脚本 +> (`error: cannot spawn scripts/hooks/pre-commit`,与 `bash` 解析到 WSL 存根同类的机器问题)。 +> **一个我无法在本机验证的守卫,比没有守卫更糟**——它正是本仓一直在消灭的"配置存在但不生效"。 +> 详见 `scripts/lib/branch-rules.mjs` 头部。 + ## 4. 代码审查 PR 或交付前必须检查: @@ -139,3 +149,32 @@ AI 每完成一个可交付片段,应执行或说明以下结果: 不能只看默认静态截图——长报错撑宽、浮层错位等只在交互态暴露。可用无头浏览器脚本对每个状态各截一张并排比。 - **L1/L2 边界:** 视觉系统(组件库)、外壳 chrome、登录页、真实存在的屏的版式 = L1 严格像素级;设计稿里 本产品尚未建的功能内容 = L2 仅视觉参考,用设计的组件样式渲染真实数据,不为此造后端、不照搬虚构内容。 + +## 8. CI 与分支保护 + +(2026-10-07 自 `docs/archive/github-cicd.md` 折入——那份文档其余部分属仓库引导期内容。) + +`main` 受保护:必须通过必需状态检查才能合并,且 **review 会话必须全部解决**。常规路径是分支 + PR; +管理员虽可绕过保护,但不作为常规做法。 + +CI(`.github/workflows/ci.yml`)在 PR 与 push 到 `main` 时运行: + +```text +verify job(Node 22 + PostgreSQL 17 service) + pnpm install --frozen-lockfile + pnpm db:setup + pnpm lint + pnpm check:repo # fidelity / evidence / goal:validate / skills:validate / doc-refs + pnpm typecheck + pnpm test + pnpm test:db # env-gated(RUN_POSTGRES_INTEGRATION=true) + pnpm test:e2e + pnpm test:e2e:postgres # env-gated(RUN_POSTGRES_E2E=true + PLATFORM_REPOSITORY_DRIVER=postgres) + pnpm build + +docker-build job(needs: verify) + docker compose -f infra/docker-compose.prod.yml build +``` + +必需检查:`verify` 与 `docker-build`(strict)。CI 是**完整链路**的最终确认;本地遇到偶发红时按 +`docs/agent-workflow.md` §1.4 **分段复跑**,不要重跑到绿。 diff --git a/docs/doc-index.md b/docs/doc-index.md index 9b1300a..53bf09f 100644 --- a/docs/doc-index.md +++ b/docs/doc-index.md @@ -18,6 +18,10 @@ 10. `docs/runbooks/*.md`:可重跑的操作手册(部署、smoke、迁移演练等),自包含、可执行;不定义新规则。 11. `docs/research/*.md`:开源深评 spike 报告,支撑对应里程碑 RFC 的决策输入;不定义新规则,权威性同任务包。 12. `docs/verification-log.md`:验证记录,不定义新规则。 +13. `docs/archive/*.md`:归档快照,按**当时事实**写、**不追改**(权威性同历史记录);不参与 + `scripts/check-doc-refs.mjs` 的引用校验。归档约定见 `docs/archive/README.md`。 +14. `docs/community-roadmap.md`、`docs/good-first-issues.md`:**发布后社区化预留**,项目未发布期间 + 非权威、可能滞后;当前进度与范围分别以 `foundation-progress.md`、`product-requirements.md` 为准。 `README.md` 和 `AGENTS.md` 是入口文件,不承载详细设计。它们必须链接到权威文档,而不是复制复杂规则。 @@ -169,6 +173,10 @@ docs/research/README.md 与该里程碑对应 spike 报告 | `docs/runbooks/*.md` | 可重跑操作手册 | 每个 runbook 主题首次落地时 | | `docs/research/*.md` | 开源深评 spike 报告 | 每个大组件 RFC 前置 spike 完成时 | | `docs/verification-log.md` | 验证记录 | 每个重要交付点后追加 | +| `docs/desktop-client.md` | 桌面客户端架构取舍 | 客户端技术栈 / 交付范围变化 | +| `docs/community-roadmap.md` | 社区化预留(未发布,非权威) | 发布时整体重写 | +| `docs/good-first-issues.md` | 社区任务预留(未发布,非权威) | 发布时整体重写 | +| `docs/archive/*.md` | 归档快照(不追改) | 不更新 | ## 4. ADR 与 RFC 的区别 @@ -275,7 +283,7 @@ RFC: M1 Platform Core 持久化的 schema、迁移、seed、session、测试方 2026-10-05 立项,P0 首项已落地) - 长任务(goal)状态目录:`docs/goal/`(机制说明 + 文件格式 + 命令;一个目标一个 `docs/goal/.md`, 机器状态在 `` 块里;纪律执行者是 `scripts/goal.mjs`,已接入 `pnpm verify` 与 CI 的 - `pnpm goal:validate`。2026-10-07 随 P1.1 落地,同时废弃手工维护的 `docs/ai-handoff.md`) + `pnpm goal:validate`。2026-10-07 随 P1.1 落地,同时废弃手工维护的 `docs/archive/ai-handoff.md`) 后续建议补充: diff --git a/docs/foundation-progress.md b/docs/foundation-progress.md index 3b35530..f9db23a 100644 --- a/docs/foundation-progress.md +++ b/docs/foundation-progress.md @@ -416,6 +416,21 @@ M8 整段退出;下一步进入 M9 在位状态 v2。照片 / 重字段编辑 | 本人信息块职务/手机展示 | Pending | M9-3b 只用 runtime `getCurrentUser()` 的姓名、工号和部门;需扩 `employees/me` 镜像后再展示 title/mobile。 | | [Presence follow-up] 归档 key 的活跃记录展示不对称 | Pending | 人页抽屉按 D-1 `includeArchived` 显 label;看板只用 active 字典映射,归档 key 回退裸 key。收敛需改 getBoard,留后续切片。 | +### 7.7 早期待确认项(2026-10-07 迁自 `docs/archive/open-questions.md`) + +原清单 103 行,多数已解决(ORM=Drizzle、UI 自研 `@work/ui`、身份源=企业内账号、部署=Docker Compose)。 +**仍未决**的条目如下——它们不是阻塞项,而是需要在对应里程碑启动前拍板: + +| 待确认 | 何时需要决定 | 备注 | +| ---------------------------------------------------------------- | -------------------- | ---------------------------------------------------------------------- | +| 密码强度与过期策略是否按等保要求配置 | 对外交付前 | 现已有强 hash(scrypt)+ 失败锁定,策略参数未定 | +| 是否需要登录双因素认证 | 对外交付前 | 内网单租户,当前未做 | +| C/S 客户端是否需要离线草稿 / 离线可读缓存 | M20+ 桌面端启动前 | 见 `docs/desktop-client.md` | +| 客户端自动更新是否必须支持内网更新源 | M20+ 桌面端启动前 | 同上 | +| Ubuntu 之外的 Linux 发行版优先级(统信 UOS / 麒麟 / RHEL) | M20+ Linux 客户端前 | 同上 | +| OpenIM 由平台团队还是基础设施团队维护部署 | M13 启动前 | IM 运维归属,见 ADR-0008 | +| IM 数据保留周期 / 敏感词过滤 / 消息归档 / 离职人员消息交接 | M14 前(法务相关项) | 部分已在 ADR-0008 拍板(聊天保留、agent 可读);敏感词与离职交接仍未决 | + ## 8. M4 在位管理 MVP 状态:Done diff --git a/docs/goal/README.md b/docs/goal/README.md index 18aeb58..3224bbd 100644 --- a/docs/goal/README.md +++ b/docs/goal/README.md @@ -3,7 +3,7 @@ 本目录承载**跨多轮/多会话的长任务**状态。规则见 `docs/agent-workflow.md` §4;纪律的**执行者**是 `node scripts/goal.mjs`(纯规则在 `scripts/lib/goal-rules.mjs`,有单测)。 -它替代了此前的 `docs/ai-handoff.md`——那份手工维护的会话交接文档漂移了 4.5 个月(还停在 M3.5), +它替代了此前的 `docs/archive/ai-handoff.md`——那份手工维护的会话交接文档漂移了 4.5 个月(还停在 M3.5), 证明**手工状态文档必然失真**。这里的状态由脚本读写、由 hook 注入会话,不靠人记得去改。 ## 为什么需要它 diff --git a/docs/good-first-issues.md b/docs/good-first-issues.md index 7ad400e..64888ea 100644 --- a/docs/good-first-issues.md +++ b/docs/good-first-issues.md @@ -1,5 +1,9 @@ # Good First Issues +> **状态(2026-10-07)**:项目**尚未发布、无外部贡献者**(在研阶段)。本文是发布后的社区化**预留**, +> **不参与当前排期**;其中的任务清单可能滞后。当前可做的切片见 `docs/foundation-progress.md` 与 +> `docs/tasks/`。发布时需按当时状态整体重写本文。 + This file lists starter tasks that are intentionally small, low-risk, and useful. The GitHub issue tracker should be the source of truth once issues are created; this document explains the intended shape of those tasks. ## Starter Tasks diff --git a/docs/tasks/m5-1-rbac-data-model-scope.md b/docs/tasks/m5-1-rbac-data-model-scope.md index 29907a8..9c603d4 100644 --- a/docs/tasks/m5-1-rbac-data-model-scope.md +++ b/docs/tasks/m5-1-rbac-data-model-scope.md @@ -320,7 +320,7 @@ SELECT module_name, count(*) FROM platform.permissions GROUP BY module_name ORDE 1. `docs/foundation-progress.md`:§6.2 M5 切片表中 M5-1 置 `Done` + 日期 + verification-log 锚点;§6 “当前下一步”改为 `M5-2 角色管理 API`。 2. `docs/verification-log.md`:顶部加 `## YYYY-MM-DD` + `### M5-1 RBAC Data Model and Scope`,含 Change set、§10 各项实测结果(含 10.3 SQL 数字或“依赖 CI + 等价 spec”)、`security-reviewer` 结论、Follow-up=M5-2。 -3. **同步因 `resolveScope` 签名变更而失真的文档**(强制,否则它们会教错下游):把 `docs/platform-core.md`、`docs/module-contract.md`(§7.1.5 模块集成模板)、`docs/ai-handoff.md` 中旧的单参 `resolveScope(currentUser)` 改为 `resolveScope(currentUser, dataType)`,注明 `dataType ∈ 'profile' | 'presence' | 'report'`。(本切片实际交付时已先行同步,此项留作 checklist。) +3. **同步因 `resolveScope` 签名变更而失真的文档**(强制,否则它们会教错下游):把 `docs/platform-core.md`、`docs/module-contract.md`(§7.1.5 模块集成模板)、`docs/archive/ai-handoff.md`(该文件后已于 2026-10-07 归档,无需再同步)中旧的单参 `resolveScope(currentUser)` 改为 `resolveScope(currentUser, dataType)`,注明 `dataType ∈ 'profile' | 'presence' | 'report'`。(本切片实际交付时已先行同步,此项留作 checklist。) ## 13. 提交规范 diff --git a/docs/verification-log.md b/docs/verification-log.md index a6d01aa..44a8c34 100644 --- a/docs/verification-log.md +++ b/docs/verification-log.md @@ -2,6 +2,59 @@ ## 2026-10-07 +### P2 Documentation Governance + +**Change set** + +- Disposed of every top-level `docs/` file that sat outside `docs/doc-index.md` governance (seven files), + deciding each from its content rather than its title: + - **Archived four** into a new `docs/archive/` (with an archive-convention README and a per-file header + stating when, why and who took over): `iteration-roadmap.md` (self-marked obsolete since 2026-05), + `ai-handoff.md` (superseded by mechanism in P1.1), `open-questions.md` (zero references; most questions + since resolved), `github-cicd.md` (bootstrap-era; its CI command list had gone stale). + - **Brought three under governance**: `community-roadmap.md` and `good-first-issues.md` now carry a status + banner stating the project is unreleased and that they are non-authoritative and may lag; + `desktop-client.md` is registered as a topic doc. +- Migrated what was still live rather than burying it: unresolved early questions moved into + `foundation-progress.md` §7.7 (password policy/等保, 2FA, desktop offline & update source, Linux distro + priority, OpenIM operations and retention), and the CI steps plus branch-protection requirements moved into + `development-workflow.md` §8. +- Added `scripts/check-doc-refs.mjs` (`pnpm doc-refs`, wired into `check:repo`): a **dangling-pointer** gate + built from one `git log --all --diff-filter=DR` index. It reports a reference only when the path was once + committed and is gone now; forward-looking references and other projects' doc trees are listed + informationally instead of failing the build. +- Updated `README.md`'s docs tree and `doc-index.md` (priority list, responsibilities table, archive + convention). +- Added `scripts/check-branch.mjs` (`pnpm check:branch`, wired into `check:repo`): fails when local `main` + has uncommitted changes or unpushed commits. It exists because I committed straight onto `main` **twice in + one session**, each time needing a manual branch-reference-and-reset recovery. The git `pre-commit` route + was tried first and **abandoned** — git on this machine cannot spawn an extension-less hook script + (`error: cannot spawn scripts/hooks/pre-commit`), and an unverifiable guard is worse than none. + +**Validation** + +- `pnpm check:repo`: pass — UI fidelity 215 files, evidence form, goal validation, skills validation and the + new doc-refs gate over 90 files. +- `pnpm vitest run --config vitest.config.mts scripts`: pass — 98 tests across seven suites. +- **Negative verification of the new gate**: committing the four moves *before* updating references made + `pnpm doc-refs` fail with exactly six dangling pointers, all to `docs/ai-handoff.md` and none spurious; + after the reference updates it passes. Narrowing the rule was necessary — the naive "report every missing + path" version produced 32 hits, almost all legitimate forward references such as the planned + `docs/testing-strategy.md`. +- All four moves used `git mv`, so history is preserved; `docs/archive/**` and `docs/verification-log.md` are + excluded from the gate as point-in-time snapshots. +- **Negative verification of the branch guard**: on `main` with a tracked file modified it reports `[B1]` and + exits 1; on a feature branch it passes; detached HEAD (CI) is skipped. The first attempt at this test was + invalid — `git show : | Set-Content -NoNewline` collapsed the script to a single line, so it ran + as an empty program and silently exited 0; the test was redone with line endings preserved. + +**Carried forward** + +- Hook mounting remains unverified (`docs/agent-workflow.md` §3). +- The dependency-governance slice (nx 20→22 PR #42, vitest 3→4, 70+ open alerts) is still unscheduled. + +## 2026-10-07 + ### P1.3 Doc-Drift Audit (the one real workflow use case) **Change set** diff --git a/package.json b/package.json index adab6d9..8acce58 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,9 @@ "evidence": "node scripts/check-evidence.mjs", "goal:validate": "node scripts/goal.mjs validate", "skills:validate": "node scripts/check-skills.mjs", - "check:repo": "pnpm fidelity && pnpm evidence && pnpm goal:validate && pnpm skills:validate", + "doc-refs": "node scripts/check-doc-refs.mjs", + "check:branch": "node scripts/check-branch.mjs", + "check:repo": "pnpm fidelity && pnpm evidence && pnpm goal:validate && pnpm skills:validate && pnpm doc-refs && pnpm check:branch", "verify": "pnpm lint && pnpm check:repo && pnpm typecheck && pnpm test && pnpm test:e2e && pnpm build", "verify:full": "pnpm verify && pnpm test:db && pnpm test:e2e:postgres", "build": "pnpm -r --if-present build", diff --git a/scripts/check-branch.mjs b/scripts/check-branch.mjs new file mode 100644 index 0000000..88d6808 --- /dev/null +++ b/scripts/check-branch.mjs @@ -0,0 +1,52 @@ +#!/usr/bin/env node +// "不要在 main 上干活"门禁 — CLI +// +// 规则与动机见 scripts/lib/branch-rules.mjs(含"为什么不是 git pre-commit hook"的说明)。 +// +// 只在本地 main 分支上判定:有未提交改动或未推送提交即失败;CI 的 detached HEAD 与非 main 分支跳过。 +// +// 用法:node scripts/check-branch.mjs [--verbose] +// 退出码:0 = 通过(或无需判定);1 = 在 main 上还有活没搬走。 + +import { spawnSync } from 'node:child_process'; +import path from 'node:path'; +import { assess } from './lib/branch-rules.mjs'; + +const REPO = path.resolve(import.meta.dirname, '..'); +const VERBOSE = process.argv.includes('--verbose'); + +function git(args) { + const result = spawnSync('git', args, { cwd: REPO, encoding: 'utf8', timeout: 30_000 }); + return result.status === 0 ? (result.stdout ?? '').trim() : null; +} + +const branchRaw = git(['rev-parse', '--abbrev-ref', 'HEAD']); +const detached = branchRaw === null || branchRaw === 'HEAD'; + +let dirty = false; +let ahead = 0; +if (!detached && branchRaw === 'main') { + const status = git(['status', '--porcelain']) ?? ''; + // 只算已跟踪文件的改动(?? 未跟踪的临时产物不算"在 main 上干活")。 + dirty = status + .split(/\r?\n/) + .filter(Boolean) + .some((line) => !line.startsWith('??')); + const count = git(['rev-list', '--count', 'origin/main..HEAD']); + ahead = count === null ? 0 : Number(count) || 0; +} + +const problems = assess({ branch: branchRaw ?? 'HEAD', detached, dirty, ahead }); + +if (problems.length === 0) { + const scope = detached ? 'detached HEAD(CI),跳过' : `当前分支 ${branchRaw}`; + console.log(`分支门禁:通过(${scope};未提交改动=${dirty},未推送提交=${ahead})`); + process.exit(0); +} + +for (const problem of problems) { + console.log(`[B1] ${problem}`); +} +console.log('分支门禁:失败。main 受远端保护,本地同样走分支 + PR。'); +if (VERBOSE) console.log('(若确有例外,先切到分支再继续;不要用 --no-verify 之类的绕过方式。)'); +process.exit(1); diff --git a/scripts/check-doc-refs.mjs b/scripts/check-doc-refs.mjs new file mode 100644 index 0000000..675cf9b --- /dev/null +++ b/scripts/check-doc-refs.mjs @@ -0,0 +1,124 @@ +#!/usr/bin/env node +// 文档/脚本路径引用完整性门禁 — CLI +// +// 校验文档与配置里提到的 `docs/**`、`scripts/**` 路径是否真实存在。规则与豁免见 +// scripts/lib/doc-ref-rules.mjs。 +// +// **只报"曾经存在、后来被移动/删除"的悬空指针**:用一次 `git log --all --diff-filter=DR` 建索引判定。 +// 前瞻性引用(计划中的文档)与别的项目的文档树不算违规,只在 --verbose 下列出。 +// +// 不扫"快照型"文件:`docs/verification-log.md`(按时间点记录)、`docs/archive/**`(归档)、 +// `docs/superpowers/plans/**`(计划快照)——追改历史快照没有意义。 +// +// 用法:node scripts/check-doc-refs.mjs [--verbose] +// 退出码:0 = 通过;1 = 有悬空指针。 + +import { spawnSync } from 'node:child_process'; +import { existsSync, readFileSync, readdirSync } from 'node:fs'; +import path from 'node:path'; +import { lintText } from './lib/doc-ref-rules.mjs'; + +const REPO = path.resolve(import.meta.dirname, '..'); +const VERBOSE = process.argv.includes('--verbose'); + +const SKIP_DIRS = new Set(['node_modules', 'dist', 'build', 'coverage', '.git', '.nx', 'archive']); +/** 快照型文件:按当时事实写,不参与本门禁。 */ +const SNAPSHOT_RELS = new Set(['docs/verification-log.md']); + +/** 从 git 历史里取出"曾经存在过、现已不在工作树"的路径集合。 */ +function removedPaths() { + const result = spawnSync('git', ['log', '--all', '--name-status', '--diff-filter=DR', '--format='], { + cwd: REPO, + encoding: 'utf8', + timeout: 120_000, + }); + const removed = new Set(); + if (result.status !== 0) return removed; + for (const line of (result.stdout ?? '').split(/\r?\n/)) { + const parts = line.split('\t'); + if (parts.length < 2) continue; + const [status, first] = parts; + if (/^[DR]/.test(status) && first) removed.add(first); + } + return removed; +} + +function collectFiles() { + const files = []; + const walk = (dir, relBase) => { + let entries; + try { + entries = readdirSync(dir, { withFileTypes: true }); + } catch { + return; + } + for (const entry of entries) { + const rel = relBase ? `${relBase}/${entry.name}` : entry.name; + if (entry.isDirectory()) { + if (SKIP_DIRS.has(entry.name) || rel.endsWith('superpowers/plans')) continue; + walk(path.join(dir, entry.name), rel); + continue; + } + if (entry.isFile() && entry.name.endsWith('.md')) files.push({ abs: path.join(dir, entry.name), rel }); + } + }; + walk(path.join(REPO, 'docs'), 'docs'); + walk(path.join(REPO, '.agents'), '.agents'); + + for (const rel of [ + 'README.md', + 'AGENTS.md', + 'CLAUDE.md', + '.claude/settings.json', + '.github/pull_request_template.md', + ]) { + const abs = path.join(REPO, rel); + if (existsSync(abs)) files.push({ abs, rel }); + } + return files.filter((f) => !SNAPSHOT_RELS.has(f.rel)); +} + +const removed = removedPaths(); +const files = collectFiles(); +const violations = []; +let plannedCount = 0; + +for (const { abs, rel } of files) { + let text; + try { + text = readFileSync(abs, 'utf8'); + } catch { + continue; + } + const { violations: bad, planned } = lintText(rel, text, { + exists: (ref) => existsSync(path.join(REPO, ref)), + wasRemoved: (ref) => removed.has(ref), + }); + for (const v of bad) violations.push({ rel, ...v }); + plannedCount += planned.length; + if (VERBOSE && planned.length > 0) { + for (const p of planned) { + console.log(`(前瞻引用,不违规)${rel}:${p.line} → ${p.ref}`); + } + } +} + +if (VERBOSE || violations.length > 0) { + console.log( + `扫描 ${files.length} 个文件;git 历史中已移除路径 ${removed.size} 个;前瞻性引用 ${plannedCount} 处(不算违规)`, + ); +} + +if (violations.length === 0) { + console.log(`文档路径引用门禁:通过(${files.length} 个文件,无悬空指针)`); + process.exit(0); +} + +for (const v of violations) { + console.log(`${v.rel}:${v.line} [D1] 悬空指针:${v.ref} 曾经存在,现已不在工作树`); +} +console.log( + `文档路径引用门禁:失败,${violations.length} 处。文件被移动/删除时,引用它的活文档必须同步更新` + + '(历史快照不追改)。', +); +process.exit(1); diff --git a/scripts/lib/branch-rules.mjs b/scripts/lib/branch-rules.mjs new file mode 100644 index 0000000..c813131 --- /dev/null +++ b/scripts/lib/branch-rules.mjs @@ -0,0 +1,36 @@ +// "不要在 main 上干活" · 规则(纯函数,无 I/O) +// +// 理由(2026-10-07):同一个会话里**两次**把改动直接提交到本地 main。两次都靠人工 +// 「建分支引用 + reset --hard」补救成功,但这种"先提交再补救"完全没必要。 +// +// 为什么不是 git pre-commit hook:本机 git 无法 spawn 那个 hook +// (`error: cannot spawn scripts/hooks/pre-commit: No such file or directory` —— 与 `bash` 解析到 +// WSL 存根同类的机器问题)。一个我无法在本机验证的守卫,正是本仓一直在消灭的"配置存在但不生效"。 +// 因此改为在 `pnpm check:repo` 里做**可移植、当场可验证**的检查:每次跑门禁时都会拦。 +// +// 只在本地的 `main` 分支上判定;detached HEAD(CI)与非 main 分支一律跳过。 + +export const PROTECTED_BRANCH = 'main'; + +/** + * @param {{ branch: string, detached: boolean, dirty: boolean, ahead: number }} state + * @returns {string[]} 问题列表(空数组=通过) + */ +export function assess(state) { + const problems = []; + if (!state || state.detached) return problems; + if (state.branch !== PROTECTED_BRANCH) return problems; + + if (state.dirty) { + problems.push( + `\`${PROTECTED_BRANCH}\` 上有未提交改动:先 \`git checkout -b /\` 再继续`, + ); + } + if (state.ahead > 0) { + problems.push( + `\`${PROTECTED_BRANCH}\` 上有 ${state.ahead} 个未推送提交:` + + '把它们移到分支上(`git branch ` 然后 `git reset --hard origin/main`,再 `git checkout `)', + ); + } + return problems; +} diff --git a/scripts/lib/branch-rules.spec.mjs b/scripts/lib/branch-rules.spec.mjs new file mode 100644 index 0000000..e5fd07f --- /dev/null +++ b/scripts/lib/branch-rules.spec.mjs @@ -0,0 +1,37 @@ +// "不要在 main 上干活"规则的回归测试。 +// +// 重点:只在该管的时候管——CI 是 detached HEAD,且非 main 分支不该被拦,否则每次都得加豁免, +// 门禁很快会被绕过(本仓已有先例:一条会误报 32 次的门禁规则只能被削弱)。 + +import { describe, expect, it } from 'vitest'; +import { assess } from './branch-rules.mjs'; + +const on = (overrides = {}) => ({ branch: 'main', detached: false, dirty: false, ahead: 0, ...overrides }); + +describe('assess', () => { + it('main 上干净且与远端齐平 → 通过', () => { + expect(assess(on())).toEqual([]); + }); + + it('main 上有未提交改动 → 报', () => { + expect(assess(on({ dirty: true })).join()).toContain('未提交改动'); + }); + + it('main 上有未推送提交 → 报,并给出补救办法', () => { + const problems = assess(on({ ahead: 2 })); + expect(problems.join()).toContain('2 个未推送提交'); + expect(problems.join()).toContain('reset --hard origin/main'); + }); + + it('两种问题同时存在时都报', () => { + expect(assess(on({ dirty: true, ahead: 1 }))).toHaveLength(2); + }); + + it('非 main 分支一律放行(否则门禁会被绕过)', () => { + expect(assess(on({ branch: 'feat/x', dirty: true, ahead: 3 }))).toEqual([]); + }); + + it('detached HEAD(CI)一律放行', () => { + expect(assess({ branch: 'HEAD', detached: true, dirty: true, ahead: 5 })).toEqual([]); + }); +}); diff --git a/scripts/lib/doc-ref-rules.mjs b/scripts/lib/doc-ref-rules.mjs new file mode 100644 index 0000000..6b77f18 --- /dev/null +++ b/scripts/lib/doc-ref-rules.mjs @@ -0,0 +1,60 @@ +// 文档/脚本路径引用完整性 · 规则(纯函数,无 I/O) +// +// 立意:docs/agent-workflow.md §1「承诺必须落到会红的检查上」。 +// 2026-10-07 的漂移审计确认:本仓真正反复出现的不是"命令写错",而是**指针指向已移动/已删除的文件** +// (例:hook 从 `.claude/hooks/` 搬到 `scripts/hooks/` 后,文档仍指着旧路径;`ai-handoff.md` 废弃后 +// 仍有引用)。这类问题**可机器核验**,所以给它一道门禁,而不是靠下次审计再发现。 +// +// 只查两类高信号引用(避免把示例路径、代码片段误判): +// 1. `docs/**` 下的 markdown 文件被提及时必须存在; +// 2. `scripts/**` 下的文件被提及时必须存在。 +// +// **只报"曾经存在、后来被移走/删掉"的引用**(由调用方用 git 历史判定 wasRemoved), +// 而不是凡不存在的都报。理由:本仓大量引用是**前瞻性**的(`docs/testing-strategy.md` 这类 +// "建议后续补充"的文档),还有的是**别的项目的**文档树(研究报告中引用被评项目的 `docs/...`)。 +// 这两类都不是漂移;2026-10-07 实测:不区分会得到 32 处告警、其中绝大多数是误报, +// 那样的门禁只会训练人乱加豁免标记。 +// +// 需要指向"尚未创建"的文件时,可在**同一行**加 `doc-ref-allow` 标记显式豁免(很少需要)。 + +const REF_RE = /\b((?:docs|scripts)\/[\w./@-]+\.(?:md|mjs|cjs|js|ps1|sh|json))/g; + +/** 提取一行里提到的仓库内路径。 */ +export function extractRefs(line) { + const refs = []; + for (const match of line.matchAll(REF_RE)) { + refs.push(match[1]); + } + return refs; +} + +/** 该行是否显式豁免。 */ +export function isExempt(line) { + return line.includes('doc-ref-allow'); +} + +/** + * 校验一段文本里的路径引用。 + * @param {string} rel 文件相对路径(用于报表) + * @param {string} text 文件内容 + * @param {{ exists: (ref: string) => boolean, wasRemoved: (ref: string) => boolean }} io + * @returns {{ violations: {line:number, ref:string}[], planned: {line:number, ref:string}[] }} + */ +export function lintText(rel, text, io) { + const violations = []; + const planned = []; + const lines = text.split(/\r?\n/); + for (let i = 0; i < lines.length; i++) { + const line = lines[i]; + if (isExempt(line)) continue; + for (const ref of extractRefs(line)) { + if (ref === rel) continue; // 自引用 + if (io.exists(ref)) continue; + // 曾经存在过 → 这是被移动/删除后的悬空指针,是真漂移; + // 从未存在过 → 前瞻引用或其他项目的路径,不作为违规(仅登记备查)。 + if (io.wasRemoved(ref)) violations.push({ line: i + 1, ref }); + else planned.push({ line: i + 1, ref }); + } + } + return { violations, planned }; +} diff --git a/scripts/lib/doc-ref-rules.spec.mjs b/scripts/lib/doc-ref-rules.spec.mjs new file mode 100644 index 0000000..154066e --- /dev/null +++ b/scripts/lib/doc-ref-rules.spec.mjs @@ -0,0 +1,73 @@ +// 文档路径引用规则的回归测试。 +// +// 关键在**区分两类"不存在"**:曾存在过(悬空指针=真漂移)vs 从未存在(前瞻引用/别的项目的路径)。 +// 这个区分如果写错,门禁要么漏掉真漂移,要么制造 30+ 条误报(2026-10-07 实测过后者)。 + +import { describe, expect, it } from 'vitest'; +import { extractRefs, isExempt, lintText } from './doc-ref-rules.mjs'; + +const io = ({ exists = [], removed = [] } = {}) => ({ + exists: (ref) => exists.includes(ref), + wasRemoved: (ref) => removed.includes(ref), +}); + +describe('extractRefs', () => { + it('抓 docs/ 与 scripts/ 下的带扩展名路径', () => { + expect(extractRefs('见 `docs/agent-workflow.md` 与 scripts/hooks/load-progress.mjs')).toEqual([ + 'docs/agent-workflow.md', + 'scripts/hooks/load-progress.mjs', + ]); + }); + + it('不抓裸文件名与目录(避免把目录树列表、代码片段误判)', () => { + expect(extractRefs(' iteration-roadmap.md')).toEqual([]); + expect(extractRefs('docs/adr/')).toEqual([]); + }); +}); + +describe('isExempt', () => { + it('含 doc-ref-allow 的行豁免', () => { + expect(isExempt('见 `docs/nope.md` ')).toBe(true); + expect(isExempt('见 `docs/nope.md`')).toBe(false); + }); +}); + +describe('lintText', () => { + it('存在的引用不报', () => { + const { violations, planned } = lintText('x.md', '见 `docs/a.md`', io({ exists: ['docs/a.md'] })); + expect(violations).toEqual([]); + expect(planned).toEqual([]); + }); + + it('曾存在过的路径 → 悬空指针(违规)', () => { + const { violations } = lintText('x.md', '见 `docs/old.md`', io({ removed: ['docs/old.md'] })); + expect(violations).toHaveLength(1); + expect(violations[0].ref).toBe('docs/old.md'); + }); + + it('从未存在过的路径 → 前瞻引用,不算违规但登记', () => { + const { violations, planned } = lintText('x.md', '建议补充 `docs/planned.md`', io()); + expect(violations).toEqual([]); + expect(planned).toHaveLength(1); + }); + + it('豁免行被跳过', () => { + const { violations, planned } = lintText( + 'x.md', + '未创建 `docs/planned.md` ', + io({ removed: ['docs/planned.md'] }), + ); + expect(violations).toEqual([]); + expect(planned).toEqual([]); + }); + + it('自引用被跳过', () => { + const { violations } = lintText('docs/a.md', '本文件 docs/a.md', io({ removed: ['docs/a.md'] })); + expect(violations).toEqual([]); + }); + + it('报告行号', () => { + const { violations } = lintText('x.md', 'line1\nline2 `docs/old.md`\n', io({ removed: ['docs/old.md'] })); + expect(violations[0].line).toBe(2); + }); +});