Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,20 @@ node <plugin>/scripts/run-verify.mjs --config working # 在未改动的代码

**风险**由脚本从 diff 算出来,决定要验证多严(`node <plugin>/scripts/level.mjs` 随时可以看):

| 级别 | 什么时候 | 要求 |
| 级别 | 什么时候 | 改完准备提 PR 时要求 |
| --- | --- | --- |
| light | 小改动(默认 ≤40 行、≤3 个文件),什么风险都没碰 | 检查通过就行。不写验收文件、不派评审、不生成证据包 |
| standard | 其余的改动 | 验收标准 + 检查 + 一次独立评审;证据包自动生成 |
| light | 小改动(默认 ≤40 行、≤3 个文件),什么风险都没碰 | 完整检查通过就行。不写验收文件、不派评审、不生成证据包 |
| standard | 其余的改动 | 验收标准 + 完整检查 + 一次独立评审;证据包自动生成 |
| strict | 不管多小,只要碰到鉴权、支付、权限、迁移、接口契约、原生配置、`sensitive` 路径,或者改了检查本身 | 再加深度评审和安全检查;合并前由 owner 确认(3 档) |

**验证分两段**,不管哪个级别都一样:

- **实现过程中,每一轮**只跑快检查:`run-verify.mjs --fast`(样式、类型、lint、单元、负向检查)。Stop 钩子每轮只要求这一段。
- **改完准备提 PR 时,跑一次**完整检查:不加 `--fast`,配置里标了 `"stage": "final"` 的慢检查(截图、e2e 用户路径、inspect、安全扫描)这时才跑;
然后按级别做评审、生成证据包。截图和评审放在最后,是因为中途改一次代码,前面的截图和评审就作废了。

需要用户挑方案的原型(`frontend/build.md`)仍然在前面做:那是设计决定,不是验证。

风险不用配置也能识别:按路径(`auth/`、`payment`、`migrations/`、`.sql`、`.env` 等)和代码内容(Stripe、JWT、bcrypt、`DROP TABLE`、
`dangerouslySetInnerHTML`、权限判断等)判断;可以在配置的 `risk` 里调整或关掉。所以改动再小,碰了登录也会走严格验证;AI 也没法自称"这是小改动"来跳过。

Expand Down Expand Up @@ -81,7 +89,7 @@ node <plugin>/scripts/run-verify.mjs --config working # 在未改动的代码
| 调试 | `superpowers:systematic-debugging`、`mattpocock-skills:diagnosing-bugs` |
| 代码质量、复盘 | `mattpocock-skills:improve-codebase-architecture`、`code-review`、`retro` |

dx-workflow 自己负责:工作流编排、验证、独立评审、证据包、ratchet。重叠的地方以 dx-workflow 为准("做完"看 Stop 钩子,
dx-workflow 自己负责:工作流编排、验证、独立评审、证据包、ratchet。重叠的地方以 dx-workflow 为准("做完"看最后一段的完整验证,
独立评审看 `review-brief.mjs`,合并看分档),详见 `shared/skill-packs.md`。

上线(部署、灰度、监控、回滚)还没做:目前按合并分档决定谁批准合并,之后按你们团队现有的流程。
Expand All @@ -101,6 +109,9 @@ dx-workflow 自己负责:工作流编排、验证、独立评审、证据包
| 检查 | 写死的样式、类型、lint、截图 + 可访问性、用户路径(Web 用 Playwright) | 类型、lint、单元、真实数据库的集成测试、契约、迁移、用户路径 |
| 评审 | 有界面改动时看截图(`design-review.md`),代码看 `frontend/code-review.md` | `backend/code-review.md` |

**检查的阶段**:`config.json` 里慢的、判断"做完的改动"的检查标 `"stage": "final"`(模板里默认标了截图 `look`、
用户路径 `functional`、`inspect`、`security`),`run-verify --fast` 跳过它们;其余检查按从快到慢排,第一个失败就停。

**负向检查**:把这条 lane 里的源码改动退回到基线、保留新测试,再跑一遍测试,测试必须失败。
测试在没有实现时也能通过,说明它没测到这次改动。

Expand All @@ -118,9 +129,6 @@ dx-workflow 自己负责:工作流编排、验证、独立评审、证据包

详见 `skills/frontend/mobile.md`。

**负向检查**:把这条 lane 里的源码改动退回到基线、保留新测试,再跑一遍测试,测试必须失败。
测试在没有实现时也能通过,说明它没测到这次改动。

## 合并分档

脚本算,不能手动改。
Expand Down Expand Up @@ -185,12 +193,14 @@ lint 规则、类型或约束 > 由 diff 触发的清单项 > 写进约定文件

## 收尾检查和提交盖章

**Stop 钩子**:这一轮改动了某条 lane 的文件(内容和这一轮开始时不同,由 UserPromptSubmit 钩子记录)时,按级别检查:
light 只要求这条 lane 的 `run-verify` 在当前内容上通过;standard 还要求独立评审针对当前内容且已通过、验收标准和清单项都已标记;
strict 还要求评审是 deep。证据包由钩子自己生成,其他条件都满足时它会自动跑 `make-evidence`。不满足时第一次结束会被拦下。仍未通过就结束时,AI 必须写明"未验证"
(钩子只拦一次,避免无限循环)。只聊天、没改内容的一轮不会被拦。
**Stop 钩子**:这一轮改动了某条 lane 的文件(内容和这一轮开始时不同,由 UserPromptSubmit 钩子记录)时:

- **拦下**:这条 lane 的快检查(`run-verify --fast` 或完整运行)没跑、没过,或者跑的不是当前内容。仍未通过就结束时,AI 必须写明"未验证"
(钩子只拦一次,避免无限循环)。只聊天、没改内容的一轮不会被拦。
- **不拦,但告诉你**:最后一段还缺什么(final 检查没跑;standard 的评审、验收标准、清单项;strict 的 deep 评审)。这时证据包的分档是"未就绪",
CI 也会把所有检查重跑一遍,所以把关没有放松,只是不再每一轮都跑。其他条件都满足时,钩子会自己跑 `make-evidence` 生成证据包。

`DX_WORKFLOW_GATE`:`enforce`(默认,拦截)、`observe`(只记录本来会拦什么,用来先看误报)、`off`(关闭)。
`DX_WORKFLOW_GATE`:`enforce`(默认,见上)、`full`(每一轮都要求全部完成,0.7 的做法)、`observe`(只记录本来会拦什么,用来先看误报)、`off`(关闭)。
每次判断都追加到 `.verify/gate.log`,`ratchet.md` 建议每周看一次。

**提交盖章**(可选):`node <plugin>/scripts/stamp.mjs --install` 装一个 `prepare-commit-msg` 钩子。每个改了 lane 文件的提交带上
Expand Down Expand Up @@ -228,7 +238,7 @@ baoyu-design 是可选的看图调色工具,只在项目仓库外用(它含
| 变量 | 作用 |
| --- | --- |
| `VERIFY_BASE` | 基线提交(默认:和 `origin/HEAD`、`origin/main`、`origin/master` 的 merge-base,都没有就是 `HEAD`) |
| `DX_WORKFLOW_GATE` | Stop 钩子:`enforce`(默认)、`observe`、`off` |
| `DX_WORKFLOW_GATE` | Stop 钩子:`enforce`(默认)、`full`、`observe`、`off` |

## 文件

Expand All @@ -252,7 +262,7 @@ baoyu-design 是可选的看图调色工具,只在项目仓库外用(它含
| 路径 | 作用 |
| --- | --- |
| `plugins/dx-workflow/hooks/hooks.json` | 注册 UserPromptSubmit 和 Stop 两个钩子 |
| `plugins/dx-workflow/scripts/run-verify.mjs` | 按 lane 跑检查(含负向检查),记录退出码和内容哈希;`--config working`、`--keep-going`、`--restore` |
| `plugins/dx-workflow/scripts/run-verify.mjs` | 按 lane 跑检查(含负向检查),记录退出码和内容哈希;`--fast`(不跑 final 检查)、`--config working`、`--keep-going`、`--restore` |
| `plugins/dx-workflow/scripts/init.mjs` | 接入:找出已有的检查命令,生成最小的 `.verify/config.json` |
| `plugins/dx-workflow/scripts/level.mjs`、`lib/level.mjs` | 这次改动的验证级别(light / standard / strict)和原因 |
| `plugins/dx-workflow/scripts/flow-check.mjs` | 步骤之间的关卡:规格、任务、下一步可做的任务、生成任务的验收文件 |
Expand Down Expand Up @@ -286,7 +296,7 @@ npm test #
node evals/run.mjs all --reviewer "claude -p --permission-mode acceptEdits" # 改 code-review.md、brief 或换模型之前先跑,和 evals/results/ 里上一次比
```

发版:改 `plugins/dx-workflow/.claude-plugin/plugin.json` 的版本,合并后打同名 tag(如 `v0.7.0`),CI 模板按 tag 锁定插件版本。
发版:改 `plugins/dx-workflow/.claude-plugin/plugin.json` 的版本,合并后打同名 tag(如 `v0.8.0`),CI 模板按 tag 锁定插件版本。

升级第三方工具:一次只升一个,读它的改动,在两个项目上各跑一次 `run-verify.mjs`,结果没变差再改 `vendor.lock.json` 里的 commit。

Expand Down
37 changes: 37 additions & 0 deletions docs/adr/0008-fast-loop-final-verification.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 8. A fast loop every turn, the final verification once

Date: 2026-12-03 · Status: accepted

## Context

After 0007 the steps depended on the change, but not on when in the change they ran. The Stop gate
judged every turn that touched a lane as if the change were finished: the whole `run-verify` (for a
frontend lane: Playwright screenshots at three widths, the e2e journeys, inspect; on a phone:
simulators), and for standard and strict changes a fresh review and the evidence pack. All of it is
bound to the content hash, so the next edit threw it away. A change built over five turns paid for
five screenshot runs and five reviews, of which only the last meant anything. The UI checks were the
slowest and the most wasted: a screenshot of a screen that is still moving judges nothing.

## Decision

- A check can be marked `"stage": "final"` in `.verify/config.json`. The template marks the slow
checks that judge a finished change: `look`, `functional`, `inspect`, `security` (and the
simulator checks of a React Native lane).
- `run-verify.mjs --fast` skips them and records the lane as `fast`. A full run records `pass`.
- The Stop gate (default `enforce`) blocks a turn only when the touched lanes' fast checks are
missing, failing or stale. What the final verification still lacks (final checks, review,
acceptance, evidence) is shown to the person as a message, not blocked, and logged as
`final-pending`. `DX_WORKFLOW_GATE=full` keeps the 0.7 behaviour.
- The final verification happens once, in the workflow's Verify step: the full run, then the review
by level. `review-brief.mjs` refuses a `fast` run; `make-evidence.mjs` marks it "not ready".
- The prototype step (frontend `build.md`) stays early: picking a structure is a design decision,
not verification.

## Consequences

A turn costs the fast checks only. A change can end a turn, or a session, without its final
verification; the person sees that in the gate's message, the evidence pack says "not ready", the
commit stamp says `Verified: none`, and CI reruns every check, so nothing unverified reaches a merge
unnoticed. What is lost is the guarantee that the agent itself ran the review before saying "done";
the workflow skill tells it to say so plainly, and `full` restores the guarantee for teams that want it.
A project whose config has no `stage` marks behaves as before: `--fast` runs everything.
4 changes: 2 additions & 2 deletions plugins/dx-workflow/.claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dx-workflow",
"version": "0.7.0",
"description": "One workflow from request to mergeable change, light by default and strict where it matters: the developer describes the change; it sizes it, computes how strictly to check it from the diff (light, standard, strict), uses superpowers and Matt Pocock's skills inside steps, acceptance criteria first, a design contract and a backend contract, checks per lane (frontend on the web or React Native / Expo, backend) including a negative check, independent review, an evidence pack with a computed merge tier, and a Stop gate. Checks are read from the base commit, runs and reviews are bound to a content hash, and changes to the checks themselves are tier 3. ",
"version": "0.8.0",
"description": "One workflow from request to mergeable change, light by default and strict where it matters: the developer describes the change; it sizes it, computes how strictly to check it from the diff (light, standard, strict), uses superpowers and Matt Pocock's skills inside steps, acceptance criteria first, a design contract and a backend contract, checks per lane (frontend on the web or React Native / Expo, backend) including a negative check, independent review, an evidence pack with a computed merge tier, and a Stop gate that asks for fast checks each turn and the slow ones (screenshots, e2e) once, when the change is ready. Checks are read from the base commit, runs and reviews are bound to a content hash, and changes to the checks themselves are tier 3. ",
"author": {
"name": "davidxiaodev"
},
Expand Down
5 changes: 4 additions & 1 deletion plugins/dx-workflow/scripts/make-evidence.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ const why3 = [
})(),
].filter(Boolean);
const notReady = [
!lanesReady && "a lane's checks did not pass",
!lanesReady &&
(lanes.some((l) => last.lanes[l.name]?.result === "fast") && lanes.every((l) => ["pass", "fast"].includes(last.lanes[l.name]?.result))
? "only the fast checks ran (run run-verify.mjs without --fast for the final checks)"
: "a lane's checks did not pass"),
!reviewsReady && "a review is not approved or has open lines",
!acceptanceReady && "an acceptance criterion is not met or not reviewed",
!sameTree && `verified a different tree than the one on disk (${[...staleRuns.map((n) => `run ${n}`), ...staleReviews.map((n) => `review ${n}`)].join(", ")})`,
Expand Down
7 changes: 6 additions & 1 deletion plugins/dx-workflow/scripts/review-brief.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ const current = treeHash(root);
const last = readJson(join(cfg.dir, "last-run.json"));
const run = last?.lanes?.[lane.name];
if (!run || run.tree !== current || run.result !== "pass") {
fail(2, `review-brief: run-verify has not passed lane ${lane.name} on the current tree; run it first (the reviewer reviews what the checks passed).`);
fail(
2,
run?.result === "fast" && run.tree === current
? `review-brief: only the fast checks ran on lane ${lane.name}; run run-verify.mjs without --fast first (the review comes after the final checks, once).`
: `review-brief: run-verify has not passed lane ${lane.name} on the current tree; run it first (the reviewer reviews what the checks passed).`,
);
}

// What changed, for this lane.
Expand Down
18 changes: 16 additions & 2 deletions plugins/dx-workflow/scripts/run-verify.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
// .verify/last-run.json from real exit codes only, so the Stop gate can trust it.
//
// node run-verify.mjs [--lane frontend,backend] [--only name,name] [--root <project root>]
// [--config base|working] [--base <ref>] [--keep-going]
// [--config base|working] [--base <ref>] [--keep-going] [--fast]
//
// --fast skips the checks marked "stage": "final" (screenshots, e2e journeys, inspect: the slow
// ones that judge a finished change). Use it while implementing; the lane is recorded as "fast",
// which satisfies the Stop gate turn by turn but not the evidence pack or the merge tier. Run
// without --fast once, when the change is ready.
//
// A lane stops at its first failing check (cheap checks first: order them in config.json from
// fastest to slowest); the rest are recorded as skipped. --keep-going runs every check anyway.
Expand Down Expand Up @@ -61,6 +66,7 @@ if (backupExists(cfg.dir)) {

const wantLanes = opt("lane")?.split(",").filter(Boolean);
const only = opt("only")?.split(",").filter(Boolean);
const fast = args.includes("--fast");
const lanes = cfg.lanes.filter((l) => !wantLanes || wantLanes.includes(l.name));
const unknown = (wantLanes ?? []).filter((n) => !cfg.lanes.some((l) => l.name === n));
if (unknown.length) {
Expand Down Expand Up @@ -102,6 +108,11 @@ for (const lane of lanes) {
const laneStarted = new Date().toISOString();
const results = [];
for (const check of checks) {
if (fast && check.stage === "final") {
console.log(`run-verify: ${lane.name}/${check.name} … not run (stage final; runs without --fast)`);
results.push({ name: check.name, run: check.run ?? "built-in negative check", exitCode: null, skipped: true, stage: "final", seconds: 0, log: null, note: "stage final, not run with --fast" });
continue;
}
if (process.env.CI && check.ci === false) {
console.log(`run-verify: ${lane.name}/${check.name} … skipped in CI ("ci": false; it needs a simulator, a device or a local service)`);
results.push({ name: check.name, run: check.run ?? "built-in negative check", exitCode: null, skipped: true, seconds: 0, log: null, note: 'not run in CI ("ci": false)' });
Expand Down Expand Up @@ -140,7 +151,7 @@ for (const lane of lanes) {
record.lanes[lane.name] = {
startedAt: laneStarted,
finishedAt: new Date().toISOString(),
result: failed.length ? "fail" : only ? "partial" : "pass",
result: failed.length ? "fail" : only ? "partial" : results.some((r) => r.stage === "final" && r.skipped) ? "fast" : "pass",
runDir,
tree: null,
config: cfg.source,
Expand Down Expand Up @@ -195,5 +206,8 @@ writeFileSync(join(cfg.dir, "last-run.json"), JSON.stringify(record, null, 2) +

console.log(`\nrun-verify: logs and evidence in ${runDir}`);
if (anyFailed) console.log("Read the failing logs before changing anything. Never weaken a test or a check to get green.");
if (fast && !anyFailed && ranLanes.some((n) => record.lanes[n].result === "fast")) {
console.log("Fast checks only. Before the pull request, run run-verify.mjs without --fast (the final checks), then the review for standard and strict changes.");
}
if (only) console.log("A run with --only is recorded as partial and does not satisfy the Stop gate.");
process.exit(anyFailed ? 1 : 0);
Loading
Loading