diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index 9764233..24a541a 100644 --- a/.claude-plugin/marketplace.json +++ b/.claude-plugin/marketplace.json @@ -7,7 +7,7 @@ { "name": "dx-workflow", "source": "./plugins/dx-workflow", - "description": "Acceptance first, one design and one backend contract, enforced verification per lane (frontend, backend) with independent review and evidence." + "description": "Request to merge with real gates: spec and tasks for large changes, acceptance first, one design and one backend contract, enforced verification per lane (frontend, backend) with independent review and evidence." } ] } diff --git a/README.md b/README.md index a376353..7f91a4c 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ 仓库:`davidxiaodev/workflow`。 -一个 Claude Code 插件:让 AI 改前端和后端时,先说清楚"做成什么样算对",按项目的约定去做, -在独立验证之前不能说"做完了",并且把每次犯过的错变成下次能自动拦住的检查。 +一个 Claude Code 插件:把一个需求从"说清楚要什么"一路带到"可以合并",每一步之间都有能真正执行的关卡。 +AI 先说清楚"做成什么样算对",按项目的约定去做,在独立验证之前不能说"做完了",并且把每次犯过的错变成下次能自动拦住的检查。 人不再逐行读 diff,而是看证据包:验收标准逐条由独立评审标记,机器检查只认真实退出码,合并分档由脚本计算。 @@ -15,16 +15,36 @@ | 步骤 | 做什么 | frontend lane | backend lane | | --- | --- | --- | --- | | 0 准备 | 每个项目一次:写约定、接检查、加 lint 护栏、标出 `sensitive` 路径 | `docs/design.md` + token 文件 | `docs/backend.md` + 契约文件(OpenAPI 等)+ 迁移目录 | -| 1 澄清 | 只在大改动时:先追问需求、边界、失败时怎么办 | 同左 | 同左 | -| 2 验收标准 | 写 `.verify/acceptance.md`:可观察的结果,每条写明用什么证明;逐项过一遍异常情况清单;可选写明怎么回滚、能否撤回 | 无效输入、键盘、慢请求、双击提交、390 宽…… | 边界值、越权、重复请求、并发写、下游失败…… | -| 3 实现 | 按约定做 | 需要时出 3 个结构不同的原型 | 先改契约,再按验收标准一条条先写测试后写实现 | -| 4 机器检查 | `run-verify.mjs` 按 lane 跑,只认真实退出码,遇到第一个失败就停 | 样式、类型、截图 + 可访问性、用户路径(Web 用 Playwright;移动端用模拟器截图 `rn-look.mjs` 和 Maestro) | 类型、单元、真实数据库的集成测试、**负向检查**、契约、迁移、用户路径 | -| 5 独立评审 | `review-brief.mjs` 写 brief,交给没参与实现的子代理;逐条标记验收标准和触发的清单项;最多 3 轮 | `design-review.md` 看截图,再用前端版 `code-review.md` 看代码(状态、请求竞态、错误态、XSS、可访问性) | `code-review.md` 看 diff,按专项逐一检查,并跑一遍证明关键事实 | -| 6 证据和分档 | `make-evidence.mjs` 生成证据包:验收标准和机器检查分开写,算合并分档,写明能否撤回、影响范围、怎么回滚 | 前后对比截图、录屏 | 检查日志、负向检查结果、契约与迁移改动 | -| 7 沉淀 | 评审的 Blocker、回滚、你的纠正,按 `shared/ratchet.md` 变成检查或清单项 | 同左 | 同左 | +| 1 定义(L) | 写规格 `docs/specs/<名字>.md`:问题、目标 `S1…`、不做什么、决定、未决问题,以及整个功能的验收标准;你同意(`Status: agreed`)后才往下走 | 同左 | 同左 | +| 2 验收标准 | 每条可观察、写明用什么证明,L 的写在规格里并标注对应哪个目标;逐项过一遍异常情况清单;可选写明怎么回滚、能否撤回 | 无效输入、键盘、慢请求、双击提交、390 宽;移动端:大字号、断网、切后台…… | 边界值、越权、重复请求、并发写、下游失败…… | +| 3 拆任务(L) | `docs/specs/<名字>.tasks.md`:每个任务一个 PR(S 或 M),写明 lane、负责哪几条验收标准、依赖、预估风险档;开工时由脚本生成这个任务的 `.verify/acceptance.md` | 同左 | 同左 | +| 4 实现 | 按约定做,先写测试;没有依赖关系的任务可以各开一个 worktree 并行做 | 需要时出 3 个结构不同的原型 | 先改契约,再按验收标准一条条先写测试后写实现 | +| 4′ 调试 | 同一个检查连续两次失败,`run-verify` 就要求停下来先找根因(`shared/debug.md`),根因写进 `.verify/debug.md`,再修 | 同左 | 同左 | +| 5 机器检查 | `run-verify.mjs` 按 lane 跑,只认真实退出码,遇到第一个失败就停 | 样式、类型、截图 + 可访问性、用户路径(Web 用 Playwright;移动端用模拟器截图 `rn-look.mjs` 和 Maestro) | 类型、单元、真实数据库的集成测试、**负向检查**、契约、迁移、用户路径 | +| 6 独立评审 | `review-brief.mjs` 写 brief,交给没参与实现的子代理;逐条标记验收标准和触发的清单项;最多 3 轮 | `design-review.md` 看截图,再用前端版 `code-review.md` 看代码(状态、请求竞态、错误态、XSS、可访问性) | `code-review.md` 看 diff,按专项逐一检查,并跑一遍证明关键事实 | +| 7 证据和分档 | `make-evidence.mjs` 生成证据包:验收标准和机器检查分开写,算合并分档,写明能否撤回、影响范围、怎么回滚 | 前后对比截图、录屏 | 检查日志、负向检查结果、契约与迁移改动 | +| 8 沉淀 | 评审的 Blocker、回滚、你的纠正,按 `shared/ratchet.md` 变成检查或清单项 | 同左 | 同左 | + +入口是 `flow` 技能(`dx-workflow:flow`),它先给改动定大小,再决定走哪些步骤: + +| 大小 | 什么时候 | 步骤 | +| --- | --- | --- | +| S | 改文案、颜色、一行修复、配置值;不碰契约、迁移、鉴权、原生 | 验收标准 1–3 条 → 实现 → 验证,评审一般是 quick | +| M | 一两条 lane 内、一个 PR 放得下(约 400 行)的功能或修复,不改契约 | 验收标准 + 异常情况 → 实现 → 验证 | +| L | 新流程;接口、数据或设计契约变更;迁移;鉴权或支付;原生改动;超过一个 PR;或者还说不清怎样算做完 | 定义 → 规格里的验收标准 → 拆任务 → 每个任务按 M 走 | + +步骤之间的关卡是能执行的命令: + +```bash +node /scripts/flow-check.mjs spec docs/specs/x.md # 规格:你已同意、没有未决问题、每个目标都有验收标准 +node /scripts/flow-check.mjs tasks docs/specs/x.tasks.md # 任务:每条验收标准都有任务负责、没有循环依赖、没有超过 M 的任务 +node /scripts/flow-check.mjs next docs/specs/x.tasks.md --done T1 # 现在可以开工的任务 +node /scripts/flow-check.mjs acceptance docs/specs/x.md T2 --write # 生成这个任务的 .verify/acceptance.md +``` -改动大小决定流程轻重:改文案、改颜色这类小改动不用追问,验收标准写 1 到 3 条,评审走 quick; -新流程、接口或数据契约变更、迁移、鉴权才走完整流程,评审走 deep。 +生成的验收文件会带上 `Spec:` 和 `Task:`,证据包和 PR 描述里也会写明,所以评审的每一条标记都能追溯到你同意过的目标。 + +上线(部署、灰度、监控、回滚)这一步还没做:目前按合并分档决定谁批准合并,之后的流程按你们团队现有的做法。 **移动端(React Native / Expo)**:lane 写 `"kind": "frontend", "platform": "react-native"`,默认覆盖全部 JS/TS 代码和 `app.json`、`ios/`、`android/` 等原生配置。和 Web 的区别: @@ -43,6 +63,29 @@ **负向检查**:把这条 lane 里的源码改动退回到基线、保留新测试,再跑一遍测试,测试必须失败。 测试在没有实现时也能通过,说明它没测到这次改动。 +## 和其他 skill 包一起用 + +装了 Matt Pocock 的 skills、superpowers 或 agent-skills 的话,`flow` 会把某些步骤里的具体工作交给它们, +关卡和作为记录的文件仍以 dx-workflow 为准(详见 `shared/skill-packs.md`): + +| 步骤 | 交给(装了才用) | +| --- | --- | +| 定义、访谈 | `mattpocock-skills:grilling` / `grill-with-docs`,`agent-skills:interview-me` / `spec-driven-development`,`superpowers:brainstorming` | +| 拆任务 | `agent-skills:planning-and-task-breakdown`,`superpowers:writing-plans`,`mattpocock-skills:to-tickets` | +| 先写测试 | `mattpocock-skills:tdd`,`superpowers:test-driven-development`,`agent-skills:test-driven-development` | +| 并行 | `superpowers:using-git-worktrees` / `dispatching-parallel-agents` | +| 调试 | `mattpocock-skills:diagnosing-bugs`,`superpowers:systematic-debugging`,`agent-skills:debugging-and-error-recovery` | +| 浏览器排查 | `agent-skills:browser-testing-with-devtools` | +| 架构和清理 | `mattpocock-skills:improve-codebase-architecture` / `codebase-design`,`agent-skills:code-simplification` | + +冲突时以 dx-workflow 为准: +- 规格和任务以 `docs/specs/` 下的文件为准,别的 skill 写到 `docs/superpowers/`、`SPEC.md`、`tasks/todo.md` 或 issue 里的只算草稿; +- "做完"以 Stop 钩子放行为准,别的 skill 的"测试过了就算完"只是其中一部分; +- 独立评审以 `review-brief.mjs` 派出的为准,它们的评审只能作为额外的检查; +- 合并按分档来,证据包出来之前不在本地 merge,也不开可以直接合并的 PR。 + +安装命令和锁定的版本见 `vendor.lock.json` 的 `routed`。 + ## 合并分档 脚本算,不能手动改。 @@ -155,7 +198,8 @@ baoyu-design 是可选的看图调色工具,只在项目仓库外用(它含 两者都会写约定文件、接好 `.verify/config.json`、加 lint 护栏、建一个空的 `docs/checklist.md`、和你一起填 `sensitive` 路径; 没有可脚本化的用户路径时生成 `ctl` 控制命令;最后用 `run-verify.mjs --config working` 在未改动的代码上跑一遍全部检查 -(配置合进默认分支之后,就不再需要 `--config working`)。之后正常让 Claude 改代码即可。 +(配置合进默认分支之后,就不再需要 `--config working`)。之后正常提需求即可:`flow` 技能会先给改动定大小, +大的改动先和你一起写规格、拆任务,再一个任务一个 PR 地做。 接着可以做的:装提交盖章钩子、接 CI 模板。 @@ -172,10 +216,13 @@ baoyu-design 是可选的看图调色工具,只在项目仓库外用(它含 | 路径 | 作用 | | --- | --- | +| `plugins/dx-workflow/skills/flow/` | 入口:给改动定大小,按步骤和关卡走完整个流程,按步骤分派给其他 skill 包 | | `plugins/dx-workflow/skills/frontend/` | 前端:`SKILL.md`(入口)、`setup.md`、`build.md`、`verify.md`、`mobile.md`(React Native / Expo)、`design-review.md`(截图评审)、`code-review.md`(前端代码评审)、`templates/`(design.md、Web 截图测试、页面清单、`rn-look.json`、Maestro journey) | | `plugins/dx-workflow/skills/backend/` | 后端:`SKILL.md`(入口)、`setup.md`、`build.md`、`verify.md`、`code-review.md`(代码评审)、`templates/backend.md` | | `plugins/dx-workflow/shared/acceptance.md` | 怎么写验收标准、异常情况清单、评审怎么标记 | | `plugins/dx-workflow/shared/ctl.md` | 生成项目的控制命令(读写分开),以及 `verify-` skill 和用户路径 | +| `plugins/dx-workflow/shared/spec.md`、`tasks.md`、`debug.md` | 定义、拆任务、调试三步的做法和文件格式 | +| `plugins/dx-workflow/shared/skill-packs.md` | 和 Matt Pocock、superpowers、agent-skills 一起用:谁做哪一步,冲突时以谁为准 | | `plugins/dx-workflow/shared/ratchet.md` | 把犯过的错变成检查:分类、准入、单独提交、清理;清单格式 | | `plugins/dx-workflow/shared/verify.config.json` | `.verify/config.json` 模板(frontend 和 backend 两条 lane) | | `plugins/dx-workflow/shared/verify-ci.yml` | 项目用的 CI 模板 | @@ -186,6 +233,8 @@ 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/flow-check.mjs` | 步骤之间的关卡:规格、任务、下一步可做的任务、生成任务的验收文件 | +| `plugins/dx-workflow/scripts/lib/flow.mjs` | 解析规格和任务文件 | | `plugins/dx-workflow/scripts/review-brief.mjs` | 写评审 brief:内容哈希、深度、触发的清单项、轮次 | | `plugins/dx-workflow/scripts/make-evidence.mjs` | 生成证据包和合并分档;`--pr` 输出 PR 描述,`--checks-only --exit-code` 给 CI 用 | | `plugins/dx-workflow/scripts/stop-gate.mjs` | Stop 钩子 | @@ -215,11 +264,12 @@ 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.5.0`),CI 模板按 tag 锁定插件版本。 +发版:改 `plugins/dx-workflow/.claude-plugin/plugin.json` 的版本,合并后打同名 tag(如 `v0.6.0`),CI 模板按 tag 锁定插件版本。 升级第三方工具:一次只升一个,读它的改动,在两个项目上各跑一次 `run-verify.mjs`,结果没变差再改 `vendor.lock.json` 里的 commit。 ## 思路来源 Anthropic Claude Code 团队关于代码评审和验证的文章,Lauren Tan(poteto)的 pstack 和"倒金字塔",Matt Pocock 的 skills -(grilling、tdd、code-review、retro、pr),Garry Tan 的 gstack,Damola Akinleye 的 interface-design。改编的文字和许可见 `NOTICE.md`。 +(grilling、tdd、code-review、retro、pr),Jesse Vincent 的 superpowers,Addy Osmani 的 agent-skills,Garry Tan 的 gstack, +Damola Akinleye 的 interface-design。改编的文字和许可见 `NOTICE.md`;分派给其他 skill 包的步骤见 `shared/skill-packs.md`。 diff --git a/docs/adr/0006-a-full-flow-with-gates.md b/docs/adr/0006-a-full-flow-with-gates.md new file mode 100644 index 0000000..a27087e --- /dev/null +++ b/docs/adr/0006-a-full-flow-with-gates.md @@ -0,0 +1,35 @@ +# 6. A full flow with gates, delegating the steps + +Date: 2026-11-18 · Status: accepted + +## Context + +The plugin proved a change right (acceptance, checks, independent review, evidence, tier) but said +nothing about the steps before and around that: when to write a spec, how to split work into pull +requests, what to do when a check keeps failing. Agents improvised between the pieces, and a +misunderstood requirement surfaced only at review. Matt Pocock's skills, superpowers and agent-skills +each cover the whole path and do several steps very well; each also has its own files, its own +definition of done, its own reviewers and, for some, its own merge. + +## Decision + +- A `flow` skill is the entry: it sizes a change (S, M, L) and runs it through define, acceptance, + tasks, build, debug, verify and learn, with a gate between steps. +- The gates are commands. `flow-check.mjs spec` (agreed, no open question, every goal has a criterion + with a proof), `tasks` (every criterion in a task, lanes exist, tasks S or M with a risk tier, no + cycle), `next`, and `acceptance --write`, which generates a task's `.verify/acceptance.md` with + `Spec:` and `Task:` lines that the evidence pack and pull request body carry. `run-verify.mjs` + counts consecutive failures per check and sends the second to `shared/debug.md`; the root cause in + `.verify/debug.md` appears in the evidence pack. +- Files of record: `docs/specs/.md` and `docs/specs/.tasks.md`. +- Other skill packs do the work inside steps when installed (`shared/skill-packs.md`); this plugin + keeps the files of record, the definition of done, the independent review and the merge tier. Their + versions are pinned under `routed` in `vendor.lock.json`; they are never vendored. +- Shipping (deploy, rollout, monitoring, rollback) is out of scope until the team's deployment + setup is known; merging follows the tier. + +## Consequences + +Large changes take a spec and a task list before code, and the user agrees the spec. The routing +table depends on other packs' skill names; when one is renamed the step falls back to this plugin's +own text. The consecutive-failure trigger is advisory: it prints and records, it does not block. diff --git a/plugins/dx-workflow/.claude-plugin/plugin.json b/plugins/dx-workflow/.claude-plugin/plugin.json index 6429bad..09c1ae4 100644 --- a/plugins/dx-workflow/.claude-plugin/plugin.json +++ b/plugins/dx-workflow/.claude-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "dx-workflow", - "version": "0.5.0", - "description": "Front-end and back-end changes you can trust: 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.6.0", + "description": "A request to a mergeable change with a gate between every step: size the change, spec and tasks for large ones (flow-check), 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. Works with Matt Pocock's skills, superpowers and agent-skills for the work inside a step.", "author": { "name": "davidxiaodev" }, diff --git a/plugins/dx-workflow/scripts/flow-check.mjs b/plugins/dx-workflow/scripts/flow-check.mjs new file mode 100644 index 0000000..ab196ac --- /dev/null +++ b/plugins/dx-workflow/scripts/flow-check.mjs @@ -0,0 +1,82 @@ +#!/usr/bin/env node +// The gates between the flow's stages, as checks that exit for real. +// +// node flow-check.mjs spec may we plan and build from this spec? +// node flow-check.mjs tasks is the task list complete and buildable? +// node flow-check.mjs next [--done T1,T2] which tasks can start now +// node flow-check.mjs acceptance [T2] [--write] the task's .verify/acceptance.md +// +// The task list's spec is the file next to it without ".tasks". Exit 0 = gate open, 1 = problems +// (printed one per line), 2 = usage error. `acceptance --write` refuses while the spec gate is shut. +import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"; +import { dirname, join, relative, resolve } from "node:path"; +import { checkSpec, checkTasks, parseSpec, parseTasks, readyTasks, taskAcceptance } from "./lib/flow.mjs"; +import { gitRoot, loadConfig } from "./lib/verify-config.mjs"; + +const [cmd, file, ...rest] = process.argv.slice(2); +const opt = (name) => { + const i = rest.indexOf(`--${name}`); + return i === -1 ? undefined : rest[i + 1]; +}; +if (!cmd || !file) usage(); +const path = resolve(file); +if (!existsSync(path)) fail(`flow-check: no ${file}.`); +const root = gitRoot(dirname(path)) ?? process.cwd(); +const rel = (p) => relative(root, p); +const specPathFor = (tasksFile) => tasksFile.replace(/\.tasks\.md$/, ".md"); +const read = (p) => readFileSync(p, "utf8"); + +if (cmd === "spec") { + report("spec", checkSpec(parseSpec(read(path))), `the spec is agreed and complete: write the task list (shared/tasks.md) or, for one pull request, the acceptance: flow-check.mjs acceptance ${rel(path)} --write`); +} else if (cmd === "tasks") { + const specFile = specPathFor(path); + if (specFile === path || !existsSync(specFile)) fail(`flow-check: a task list is .tasks.md next to its spec; no ${rel(specFile)}.`); + const spec = parseSpec(read(specFile)); + const lanes = loadConfig(root)?.lanes.map((l) => l.name) ?? null; + const tasks = parseTasks(read(path)); + const problems = [...checkSpec(spec).map((p) => `spec: ${p}`), ...checkTasks(tasks, spec, lanes)]; + report("tasks", problems, `${tasks.length} task(s) cover every criterion. Start with: ${readyTasks(tasks).map((t) => t.id).join(", ")}`); +} else if (cmd === "next") { + const done = (opt("done") ?? "").split(",").filter(Boolean); + const ready = readyTasks(parseTasks(read(path)), done); + console.log(ready.length ? ready.map((t) => `${t.id} ${t.title} · lanes: ${t.lanes.join(", ")} · ${t.acceptance.join(", ")}`).join("\n") : "no task is ready (all done, or waiting on a dependency)"); +} else if (cmd === "acceptance") { + const spec = parseSpec(read(path)); + const taskId = rest.find((a) => /^T\d+$/.test(a)); + const tasksFile = path.replace(/\.md$/, ".tasks.md"); + let task = null; + if (taskId) { + if (!existsSync(tasksFile)) fail(`flow-check: no ${rel(tasksFile)} for ${taskId}.`); + task = parseTasks(read(tasksFile)).find((t) => t.id === taskId); + if (!task) fail(`flow-check: no task ${taskId} in ${rel(tasksFile)}.`); + } + const text = taskAcceptance(spec, task, { specPath: rel(path), tasksPath: rel(tasksFile) }); + if (rest.includes("--write")) { + const problems = checkSpec(spec); + if (problems.length) report("spec", problems, ""); + const out = join(root, ".verify", "acceptance.md"); + mkdirSync(dirname(out), { recursive: true }); + writeFileSync(out, text); + console.log(`flow-check: wrote ${rel(out)} (${task ? `${task.id}, ` : ""}${text.split("\n").filter((l) => /^- A\d+/.test(l)).length} criteria). Add the adverse cases for its lanes.`); + } else process.stdout.write(text); +} else usage(); + +function report(gate, problems, next) { + if (problems.length) { + console.log(`flow-check ${gate}: shut, ${problems.length} problem(s)`); + for (const p of problems) console.log(`- ${p}`); + process.exit(1); + } + console.log(`flow-check ${gate}: open. ${next}`.trim()); + process.exit(0); +} + +function usage() { + console.error("usage: flow-check.mjs spec | tasks | next [--done T1,T2] | acceptance [T] [--write]"); + process.exit(2); +} + +function fail(message) { + console.error(message); + process.exit(2); +} diff --git a/plugins/dx-workflow/scripts/lib/flow.mjs b/plugins/dx-workflow/scripts/lib/flow.mjs new file mode 100644 index 0000000..1cc80b5 --- /dev/null +++ b/plugins/dx-workflow/scripts/lib/flow.mjs @@ -0,0 +1,159 @@ +// Specs and task lists: the artifacts of the define and plan stages, and the gates between stages. +// +// docs/specs/.md the spec: goals S1…, non-goals, decisions D1…, open questions Q1…, and +// the feature's acceptance criteria A1…, each citing the goals it proves +// docs/specs/.tasks.md the task list: T1…, each with lanes, the acceptance ids it delivers, +// what it depends on, a size and a risk guess +// +// A task's .verify/acceptance.md is generated from both (taskAcceptance), so a review's marks trace +// back to the spec's goals. + +const section = (text, name) => { + const lines = text.split("\n"); + const start = lines.findIndex((l) => new RegExp(`^##\\s+${name}\\b`, "i").test(l)); + if (start === -1) return null; + const end = lines.findIndex((l, i) => i > start && /^##\s/.test(l)); + return lines.slice(start + 1, end === -1 ? undefined : end); +}; +const items = (lines, prefix) => + (lines ?? []) + .map((l) => new RegExp(`^\\s*-\\s*(${prefix}\\d+)\\b\\s*(.*)$`).exec(l)) + .filter(Boolean) + .map(([, id, rest]) => ({ id, text: rest.trim() })); +const field = (text, name) => new RegExp(`^${name}:\\s*(.+)$`, "im").exec(text)?.[1].trim() ?? null; + +export function parseSpec(text) { + const goals = items(section(text, "Goals"), "S"); + const nonGoals = (section(text, "Non-goals") ?? []).filter((l) => /^\s*-\s*\S/.test(l) && !/^\s*-\s* ({ + ...q, + resolved: /→\s*D\d+|·\s*resolved\b|·\s*deferred:\s*\S/i.test(q.text), + })); + const criteria = items(section(text, "Acceptance"), "A").map((c) => ({ + ...c, + refs: [...new Set([...c.text.matchAll(/\bS\d+\b/g)].map((m) => m[0]))], + proof: /·\s*proof:\s*\S/i.test(c.text), + })); + return { title: /^#\s*Spec:\s*(.+)$/m.exec(text)?.[1].trim() ?? null, status: field(text, "Status"), goals, nonGoals, decisions, questions, criteria }; +} + +/** Problems that keep a spec from gating into acceptance and tasks. */ +export function checkSpec(spec) { + const p = []; + if (!/^agreed$/i.test(spec.status ?? "")) p.push(`Status is "${spec.status ?? "missing"}": the user agrees the spec before building ("Status: agreed").`); + if (!spec.goals.length) p.push("no goals (## Goals with - S1 …): what outcome makes this worth doing?"); + if (!spec.nonGoals.length) p.push("no non-goals (## Non-goals): say what this does not do, so nobody builds it."); + for (const q of spec.questions.filter((q) => !q.resolved)) p.push(`${q.id} is open: answer it (→ D), or write "· deferred: ".`); + if (!spec.criteria.length) p.push("no acceptance criteria (## Acceptance with - A1 … (S1) · proof: …)."); + const goalIds = new Set(spec.goals.map((g) => g.id)); + for (const g of spec.goals) if (!spec.criteria.some((c) => c.refs.includes(g.id))) p.push(`${g.id} has no acceptance criterion: nothing would show it was reached.`); + for (const c of spec.criteria) { + for (const r of c.refs.filter((r) => !goalIds.has(r))) p.push(`${c.id} cites ${r}, which is not a goal.`); + if (!c.proof) p.push(`${c.id} names no proof ("· proof: ").`); + } + for (const [kind, list] of [["goal", spec.goals], ["criterion", spec.criteria], ["decision", spec.decisions], ["question", spec.questions]]) { + const seen = new Set(); + for (const x of list) { + if (seen.has(x.id)) p.push(`${kind} id ${x.id} is used twice.`); + seen.add(x.id); + } + } + return p; +} + +export function parseTasks(text) { + const tasks = []; + let t = null; + for (const line of text.split("\n")) { + const head = /^##\s+(T\d+)\b\s*(.*)$/.exec(line); + if (head) { + t = { id: head[1], title: head[2].trim(), lanes: [], acceptance: [], depends: [], size: null, risk: null }; + tasks.push(t); + continue; + } + if (/^#{1,2}\s/.test(line)) t = null; + const f = t && /^\s*-\s*(lanes|acceptance|depends|size|risk):\s*(.*)$/i.exec(line); + if (!f) continue; + const [, key, value] = f; + const k = key.toLowerCase(); + if (k === "lanes") t.lanes = value.split(/[\s,]+/).filter(Boolean); + else if (k === "acceptance") t.acceptance = [...value.matchAll(/\bA\d+\b/g)].map((m) => m[0]); + else if (k === "depends") t.depends = [...value.matchAll(/\bT\d+\b/g)].map((m) => m[0]); + else t[k] = value.trim(); + } + return tasks; +} + +/** Problems with a task list against its spec (and the project's lane names, when known). */ +export function checkTasks(tasks, spec, laneNames = null) { + const p = []; + if (!tasks.length) p.push("no tasks (## T1 with - lanes:, - acceptance:, - depends:, - size:, - risk:)."); + const ids = new Set(tasks.map((t) => t.id)); + const criteria = new Set(spec.criteria.map((c) => c.id)); + for (const t of tasks) { + if (!t.lanes.length) p.push(`${t.id} names no lanes.`); + for (const l of laneNames ? t.lanes.filter((l) => !laneNames.includes(l)) : []) p.push(`${t.id}: lane "${l}" is not in .verify/config.json.`); + if (!t.acceptance.length) p.push(`${t.id} delivers no acceptance criterion: what will its review mark?`); + for (const a of t.acceptance.filter((a) => !criteria.has(a))) p.push(`${t.id} cites ${a}, which is not in the spec's acceptance.`); + for (const d of t.depends.filter((d) => !ids.has(d))) p.push(`${t.id} depends on ${d}, which is not a task.`); + if (!/^(S|M)\b/i.test(t.size ?? "")) p.push(`${t.id} size is "${t.size ?? "missing"}": split it until each task is S or M (one pull request, about 400 changed lines at most).`); + if (!/^[123]\b/.test(t.risk ?? "")) p.push(`${t.id} risk is "${t.risk ?? "missing"}": guess the merge tier (1, 2 or 3) and say why.`); + } + for (const c of spec.criteria) if (!tasks.some((t) => t.acceptance.includes(c.id))) p.push(`${c.id} is in no task: nothing would deliver it.`); + const cycle = findCycle(tasks); + if (cycle) p.push(`tasks depend on each other in a circle: ${cycle.join(" → ")}.`); + return p; +} + +/** Tasks that can start now: every dependency is in `done`. */ +export function readyTasks(tasks, done = []) { + return tasks.filter((t) => !done.includes(t.id) && t.depends.every((d) => done.includes(d))); +} + +/** The .verify/acceptance.md for one task (or the whole spec when task is null). */ +export function taskAcceptance(spec, task, { specPath, tasksPath }) { + const wanted = task ? spec.criteria.filter((c) => task.acceptance.includes(c.id)) : spec.criteria; + const goals = new Map(spec.goals.map((g) => [g.id, g.text])); + return [ + `# Acceptance: ${task ? `${task.id} ${task.title}` : spec.title}`, + `Request: ${spec.title}`, + `Spec: ${specPath}`, + ...(task ? [`Task: ${task.id} (${tasksPath})`] : []), + `Lanes: ${task ? task.lanes.join(", ") : "<lanes>"}`, + "", + "## Goals this serves", + ...[...new Set(wanted.flatMap((c) => c.refs))].map((r) => `- ${r} ${goals.get(r) ?? ""}`.trimEnd()), + "", + "## Criteria", + ...wanted.map((c) => `- ${c.id} ${c.text}`), + "", + "## Considered, not applicable", + "- <go through the adverse cases in shared/acceptance.md for this task's lanes>", + "", + ].join("\n"); +} + +function findCycle(tasks) { + const byId = new Map(tasks.map((t) => [t.id, t])); + const state = new Map(); + const stack = []; + const visit = (id) => { + if (state.get(id) === 2) return null; + if (state.get(id) === 1) return [...stack.slice(stack.indexOf(id)), id]; + state.set(id, 1); + stack.push(id); + for (const d of byId.get(id)?.depends ?? []) { + const c = byId.has(d) && visit(d); + if (c) return c; + } + stack.pop(); + state.set(id, 2); + return null; + }; + for (const t of tasks) { + const c = visit(t.id); + if (c) return c; + } + return null; +} diff --git a/plugins/dx-workflow/scripts/make-evidence.mjs b/plugins/dx-workflow/scripts/make-evidence.mjs index 0d44cf2..87e44ec 100644 --- a/plugins/dx-workflow/scripts/make-evidence.mjs +++ b/plugins/dx-workflow/scripts/make-evidence.mjs @@ -199,6 +199,14 @@ const md = []; md.push(`# Evidence: ${basename(runDir)}`, ""); md.push(`**Merge tier: ${tier.id}.** ${tier.rule}`, ""); md.push(`Tree: ${current ?? "unknown"}`, `Base: ${cfg.base ?? "none"}`, ""); +// Where this change comes from: the spec and task its acceptance was generated from (flow-check). +const specRef = /^Spec:\s*(.+)$/m.exec(acceptanceText)?.[1].trim(); +const taskRef = /^Task:\s*(.+)$/m.exec(acceptanceText)?.[1].trim(); +const trace = [specRef && `Spec: ${specRef}`, taskRef && `Task: ${taskRef}`].filter(Boolean); +if (trace.length) md.push(...trace, ""); +// A check that failed run after run was diagnosed before it was fixed (shared/debug.md). +const debugPath = join(cfg.dir, "debug.md"); +const debugText = existsSync(debugPath) ? readFileSync(debugPath, "utf8").trim() : ""; md.push(`- Lanes: ${lanes.map((l) => l.name).join(", ") || "none"}`); for (const r of reviews) md.push(`- Review ${r.lane.name}: ${r.verdict}, by ${r.reviewer}; ${r.open.length} open, ${r.deferred.length} deferred`); md.push(`- Contract changes: ${list(contractChanges)}`); @@ -209,6 +217,7 @@ md.push(`- Shared parts changed: ${list(sharedChanges)}`); for (const r of reviews) md.push(`- Not checked (${r.lane.name}): ${r.notChecked}`); md.push(""); md.push("## Merge danger", "", ...danger, ""); +if (debugText) md.push("## Diagnosed failures", "", debugText.replace(/^#.*\n+/, ""), ""); md.push("## Acceptance: verified by the independent reviewers", ""); if (checksOnly) md.push("- not part of a checks-only run", ""); else if (criteria.length === 0) md.push("- no .verify/acceptance.md criteria", ""); @@ -264,6 +273,7 @@ if (wantPr) { "", `**Merge tier: ${tier.id}.** ${tier.rule}`, "", + ...(trace.length ? [trace.join(" · "), ""] : []), "### Merge danger", ...danger, "", diff --git a/plugins/dx-workflow/scripts/run-verify.mjs b/plugins/dx-workflow/scripts/run-verify.mjs index 830152b..648d3e5 100644 --- a/plugins/dx-workflow/scripts/run-verify.mjs +++ b/plugins/dx-workflow/scripts/run-verify.mjs @@ -166,6 +166,30 @@ if (treeBefore !== treeAfter) { console.log("run-verify: files changed while the checks ran, so the result does not describe what is on disk. Run formatters and generators in check mode, then rerun."); } +// The same check failing run after run means guessing, not fixing. Count consecutive failures per +// check; from the second, stop and diagnose (shared/debug.md) before the next fix. +const failuresPath = join(cfg.dir, "failures.json"); +const failures = readJson(failuresPath) ?? {}; +const stuck = []; +for (const name of ranLanes) { + for (const c of record.lanes[name].checks) { + const key = `${name}/${c.name}`; + if (c.skipped) continue; + if (c.exitCode === 0) delete failures[key]; + else { + failures[key] = { count: (failures[key]?.count ?? 0) + 1, since: failures[key]?.since ?? new Date().toISOString() }; + c.failedRunsInARow = failures[key].count; + if (failures[key].count >= 2) stuck.push(`${key} (${failures[key].count} runs)`); + } + } +} +writeFileSync(failuresPath, JSON.stringify(failures, null, 2) + "\n"); +if (stuck.length) { + console.log( + `run-verify: failed again: ${stuck.join(", ")}. Stop changing code until you know why: follow <plugin>/shared/debug.md (or a debugging skill it names), write the root cause in .verify/debug.md, then fix it once.`, + ); +} + record.finishedAt = new Date().toISOString(); writeFileSync(join(cfg.dir, "last-run.json"), JSON.stringify(record, null, 2) + "\n"); diff --git a/plugins/dx-workflow/shared/acceptance.md b/plugins/dx-workflow/shared/acceptance.md index 10bb374..3c659b2 100644 --- a/plugins/dx-workflow/shared/acceptance.md +++ b/plugins/dx-workflow/shared/acceptance.md @@ -12,7 +12,7 @@ as the requirement being met. | --- | --- | | Copy, a colour, a one-line fix | 1 to 3 criteria, no interview | | A feature inside one lane, no contract change | the criteria plus the adverse cases below that apply | -| A new flow, an API or data contract change, a migration, auth | interview the user first (below), then the full list | +| A new flow, an API or data contract change, a migration, auth | a spec first (`shared/spec.md`, size L in the `flow` skill): the criteria live in the spec and each task's file is generated from it | ## Interview first when the change is big @@ -71,6 +71,8 @@ to prevent. ```markdown # Acceptance: <the change, one line> Request: <the user's words, or a link to the issue> +Spec: <optional: docs/specs/<slug>.md, when the change has one (flow-check.mjs acceptance writes these two lines)> +Task: <optional: T<n> (docs/specs/<slug>.tasks.md)> Lanes: <frontend, backend> Revert: <optional: how to undo it if it is more than reverting the commit (a flag to turn off, data to restore)> Door: <optional: "one-way: <why>" when it cannot be undone (an email sent, a third party called); migrations and contracts are detected> diff --git a/plugins/dx-workflow/shared/debug.md b/plugins/dx-workflow/shared/debug.md new file mode 100644 index 0000000..929f57b --- /dev/null +++ b/plugins/dx-workflow/shared/debug.md @@ -0,0 +1,43 @@ +# Debug: find the cause before the next fix + +`run-verify.mjs` prints "failed again" when the same check has failed two runs in a row. From then +on, another change made to see if it helps is guessing: it costs a run, can pass by luck, and leaves +the real cause in the code. Stop, and diagnose. The same applies to any bug the user reports. + +If one of these is installed, follow it for the loop below (`shared/skill-packs.md`): +`mattpocock-skills:diagnosing-bugs`, `superpowers:systematic-debugging`, +`agent-skills:debugging-and-error-recovery`. Whichever you use, the result goes in `.verify/debug.md`. + +## The loop + +1. **Reproduce it on demand.** The smallest command that fails every time: one test, one request, one + journey step, with the log. If it does not fail every time, the first job is to find what makes it + fail (order, timing, data, environment), not to fix it. +2. **Read the evidence.** The full error and stack, the log around it, the screenshot or trace, the + diff since it last passed (`git diff <last passing tree> <current tree>`). Write down what you see, + not what you expect. +3. **List causes and test the cheapest first.** Two or three hypotheses, each with the observation + that would rule it out. Add logging or a breakpoint, change one thing, rerun the reproduction. +4. **Narrow mechanically when stuck.** Bisect the diff (revert half, rerun), bisect the input, or + compare with the last passing run's logs line by line. +5. **Fix the cause, once.** Keep the reproduction as a test (it must fail before the fix and pass + after). Remove the temporary logging. +6. **Record it** in `.verify/debug.md` (the evidence pack shows it): + +```markdown +# Debug +- check: backend/integration · failed 3 runs in a row +- symptom: POST /orders returns 500 on the second call with the same Idempotency-Key +- cause: the unique index is on (key) but the lookup filters by (key, user_id), so a retry by the same user misses and inserts +- proof: test "same key twice returns the first order" failed before, passes after +- ratchet: checklist item C4 (shared/ratchet.md) +``` + +## Never + +- rerun until it passes, add a sleep or a retry, raise a timeout, loosen an assertion or a screenshot + threshold, skip or delete the test (each of these is also a guarded change: merge tier 2 or 3); +- fix two things at once, so you cannot tell which one mattered; +- call it flaky without the reproduction that shows the race or the shared state. + +A cause that a check could have caught goes through `shared/ratchet.md`. diff --git a/plugins/dx-workflow/shared/skill-packs.md b/plugins/dx-workflow/shared/skill-packs.md new file mode 100644 index 0000000..5068ac9 --- /dev/null +++ b/plugins/dx-workflow/shared/skill-packs.md @@ -0,0 +1,52 @@ +# Working with other skill packs + +Matt Pocock's skills, superpowers and agent-skills each cover the whole path from idea to merge, and +do several steps very well. Inside this plugin's flow they do the work of a step; this plugin keeps the +files of record and the gates. Use a skill below only when it appears in your available skills +(installed as a plugin they show as `mattpocock-skills:<name>`, `superpowers:<name>`, +`agent-skills:<name>`); otherwise follow this plugin's own instructions for the step. + +## Who does which step + +| Step | Use, if installed (first match) | This plugin's file of record and gate | +| --- | --- | --- | +| Define: interview, spec | `mattpocock-skills:grilling` · `grill-with-docs`; `agent-skills:interview-me` · `spec-driven-development`; `superpowers:brainstorming` | `docs/specs/<slug>.md`, `flow-check.mjs spec` (`shared/spec.md`) | +| Domain language | `mattpocock-skills:domain-modeling` · `grill-with-docs` | `GLOSSARY.md` | +| Tasks | `agent-skills:planning-and-task-breakdown`; `superpowers:writing-plans`; `mattpocock-skills:to-tickets` | `docs/specs/<slug>.tasks.md`, `flow-check.mjs tasks` (`shared/tasks.md`) | +| Test first | `mattpocock-skills:tdd`; `superpowers:test-driven-development`; `agent-skills:test-driven-development` | the negative check in `run-verify.mjs` | +| Parallel tasks | `superpowers:using-git-worktrees` · `dispatching-parallel-agents` | one task, one worktree, one `.verify/`, one pull request | +| Debug | `mattpocock-skills:diagnosing-bugs`; `superpowers:systematic-debugging`; `agent-skills:debugging-and-error-recovery` | `.verify/debug.md` (`shared/debug.md`) | +| Browser inspection | `agent-skills:browser-testing-with-devtools` (console errors, failed requests, performance) | findings go into the frontend review | +| Architecture, cleanup | `mattpocock-skills:improve-codebase-architecture` · `codebase-design`; `agent-skills:code-simplification` | its own change; old patterns removed (`shared/ratchet.md`) | +| Security, performance depth | `agent-skills:security-and-hardening` · `performance-optimization` | findings feed the review lenses and `docs/checklist.md` | +| Retro | `mattpocock-skills:retro` | `shared/ratchet.md` | + +## Where they disagree with this plugin, this plugin wins + +- **Files of record.** Specs live in `docs/specs/<slug>.md` and tasks in `docs/specs/<slug>.tasks.md`, + in the formats `flow-check.mjs` reads. A pack that writes elsewhere (`docs/superpowers/specs/`, + `SPEC.md`, `tasks/todo.md`, `.scratch/`, issue tracker tickets) is a draft or a mirror: carry the + content over and link it under `Sources:`. +- **Done.** A change is done when this plugin's Stop gate lets it end: `run-verify.mjs` passed on the + tree on disk, an independent review of that tree approved it from `review-brief.mjs`, and the evidence + pack has a merge tier. "Tests pass" (`superpowers:verification-before-completion`) or a pack's own + definition of done is part of that, not a replacement for it. +- **Review.** The independent review comes from `review-brief.mjs`. A pack's reviewers + (`superpowers:requesting-code-review`, `agent-skills:code-review-and-quality`, + `mattpocock-skills:code-review`, the task reviewer in `superpowers:subagent-driven-development`) may + run as extra passes while building; their verdicts do not replace it and are not "Verdict: approved". +- **Merge.** The merge tier decides who must look. Do not merge locally or open a ready pull request + before the evidence pack exists (`superpowers:finishing-a-development-branch` options "merge locally" + and "push and create a PR" wait for it). A pack's `/ship` checklist adds to the tier; it cannot lower it. +- **Commits.** Plans that commit after each step are fine on the task's branch; the commit stamp + (`stamp.mjs`) records whether each was verified. +- **Session start.** Meta-skills that route every message (`superpowers:using-superpowers`, + `agent-skills:using-agent-skills`) may stay on; when one routes work in a project with + `.verify/config.json`, start from this plugin's `flow` skill. +- **Never weaken a check** to satisfy a pack's step: a skipped test, a loosened threshold or an + edited `.verify/config.json` is a guarded change whatever skill asked for it. + +## Versions + +The table was written against the commits in `vendor.lock.json` ("routed"). When a pack renames or +removes a skill, the step falls back to this plugin's own instructions; update the table in its own change. diff --git a/plugins/dx-workflow/shared/spec.md b/plugins/dx-workflow/shared/spec.md new file mode 100644 index 0000000..b4ec398 --- /dev/null +++ b/plugins/dx-workflow/shared/spec.md @@ -0,0 +1,68 @@ +# Define: a spec the user agrees before anything is built + +For size L (`skills/flow/SKILL.md`). The spec says what problem this solves, what outcome counts as +success, what it will not do, and the observable criteria that prove it. It is a file in the repo, +`docs/specs/<slug>.md`, because tasks, acceptance files, reviews and evidence packs point back to it. + +## 1. Get the answers + +Interview the user until every goal and criterion can be written without guessing: who it is for, +what problem, what success looks like, what must never happen, what is out of scope, which failure +cases matter. One question at a time, each with your recommended answer. Look in the code before +asking what the code can tell you. + +If one of these is installed, use it for the interview (`shared/skill-packs.md`): +`mattpocock-skills:grilling` (or `grill-with-docs` to also build the glossary), +`agent-skills:interview-me` or `agent-skills:spec-driven-development`, `superpowers:brainstorming`. +Whatever it writes, the spec of record is the file below; link theirs under `Sources:`. + +## 2. Write the spec + +```markdown +# Spec: <the change, one line> +Status: draft +Owner: <who decides the open questions> +Sources: <the issue, the conversation, a design doc another skill wrote> + +## Problem +<who has it, when, what it costs them today> + +## Goals +- S1 <an outcome you could observe or measure: "a returning customer reorders in two taps"> +- S2 … + +## Non-goals +- <what this does not do, so nobody builds it> + +## Constraints +- <deadlines, platforms, compatibility (old app builds, old API clients), performance, data rules> + +## Decisions +- D1 <what was decided> · <why> · <who decided> + +## Open questions +- Q1 <question> · owner: <who> (open: blocks the gate) +- Q2 <question> → D3 (answered: the decision records it) +- Q3 <question> · deferred: <why it is safe to build without the answer> + +## Acceptance +- A1 <observable result for an input or action> (S1) · proof: <test, journey, screenshot page, query> +- A2 … (S1, S2) · proof: … +``` + +Criteria follow `shared/acceptance.md` (observable, one behaviour each, with a proof) and cite the +goals they prove. Go through its adverse cases for every lane the work touches; the ones that apply +become criteria here. + +## 3. The gate + +```bash +node <plugin>/scripts/flow-check.mjs spec docs/specs/<slug>.md +``` + +It stays shut until `Status: agreed`, every goal has a criterion, every criterion cites real goals +and names a proof, there are non-goals, and no question is open. Only the user sets `Status: agreed`: +show them the spec, ask, then write it. Commit the spec on its own (`docs(spec): <slug>`), before code. + +When the work later shows the spec is wrong, change the spec first, set `Status: draft`, get it +agreed again, then change tasks and code. diff --git a/plugins/dx-workflow/shared/tasks.md b/plugins/dx-workflow/shared/tasks.md new file mode 100644 index 0000000..85b007b --- /dev/null +++ b/plugins/dx-workflow/shared/tasks.md @@ -0,0 +1,64 @@ +# Tasks: split an agreed spec into pull requests + +For size L, after `flow-check.mjs spec` passes. Each task is one pull request: small enough to review +and to revert alone, verified alone, and owning specific acceptance criteria, so its review marks +exactly those. + +## How to split + +- **Vertical slices.** A task delivers something a user or caller can observe (its criteria), across + the layers it needs. Not "all the models", then "all the endpoints", then "all the screens". +- **Contract first when lanes meet.** When the frontend needs a new endpoint, the first task changes + the contract (OpenAPI, schema) and the backend; frontend tasks depend on it. A migration that + must run before code reads it is its own task, expand before contract (`backend/build.md`). +- **S or M only.** About 400 changed lines at most. A larger task hides its risk and its review + stalls; split it again. +- **Risk up front.** Guess each task's merge tier now (1, 2 or 3, with the reason). A tier 3 task + needs the owner's attention: put it early, so a "no" comes before the work that depends on it. +- **Independent where possible.** Tasks without dependencies between them can be built in parallel. + +If one of these is installed, use it to draft the split (`shared/skill-packs.md`): +`agent-skills:planning-and-task-breakdown`, `superpowers:writing-plans`, `mattpocock-skills:to-tickets`. +The task list of record is the file below; their plans and tickets can link to it. + +## The file: `docs/specs/<slug>.tasks.md` + +```markdown +# Tasks: <spec title> + +## T1 Orders API accepts an Idempotency-Key +- lanes: api +- acceptance: A1, A2 +- depends: none +- size: M +- risk: 3 · contract change (openapi.yaml) + +## T2 Checkout sends the key and shows the first order on retry +- lanes: web, app +- acceptance: A3 +- depends: T1 +- size: M +- risk: 2 · shared checkout button +- status: done · PR #123 +``` + +`lanes` are lane names from `.verify/config.json`. + +## The gate + +```bash +node <plugin>/scripts/flow-check.mjs tasks docs/specs/<slug>.tasks.md +``` + +Open when the spec gate is open, every criterion belongs to a task, every task names lanes, +criteria, a size of S or M and a risk tier, its lanes exist, and no dependency is missing or circular. + +## Working through them + +```bash +node <plugin>/scripts/flow-check.mjs next docs/specs/<slug>.tasks.md --done T1 # what can start now +node <plugin>/scripts/flow-check.mjs acceptance docs/specs/<slug>.md T2 --write # its .verify/acceptance.md +``` + +Then the lane's `build.md` and `verify.md` as for any M change. The generated acceptance file names +the spec and the task; the evidence pack and the pull request body carry both. diff --git a/plugins/dx-workflow/skills/backend/SKILL.md b/plugins/dx-workflow/skills/backend/SKILL.md index 9a2efaa..b6a3ca9 100644 --- a/plugins/dx-workflow/skills/backend/SKILL.md +++ b/plugins/dx-workflow/skills/backend/SKILL.md @@ -19,6 +19,8 @@ the contract. `<skill>` is this skill's folder; `<plugin>` is two levels up (it | Project state | Read | | --- | --- | +| A new feature, a contract or migration change, or unsure which steps a change needs | the `flow` skill first: it sizes the change and may need a spec and tasks before this skill | +| The same check failed two runs in a row, or the user reports a bug | `<plugin>/shared/debug.md` before the next fix | | No `docs/backend.md` or no `backend` lane in `.verify/config.json` | `setup.md`, then come back | | Any change | `<plugin>/shared/acceptance.md` first: write `.verify/acceptance.md` | | Building or changing endpoints, jobs, schema | `build.md`, then `verify.md` | diff --git a/plugins/dx-workflow/skills/backend/verify.md b/plugins/dx-workflow/skills/backend/verify.md index 20792ca..2dc3a7f 100644 --- a/plugins/dx-workflow/skills/backend/verify.md +++ b/plugins/dx-workflow/skills/backend/verify.md @@ -30,8 +30,10 @@ How to read a red result: check, the base or the spec history to make it pass. - **A run is interrupted during the negative check.** `run-verify.mjs --restore` puts the source back. -Rerun one check with `--only <name>` while fixing it, then the full lane before review. Stop after five -runs or when the same failure returns twice after a fix: report what is red and why. +Rerun one check with `--only <name>` while fixing it, then the full lane before review. When +`run-verify.mjs` says the same check "failed again" (two runs in a row), stop fixing and diagnose with +`<plugin>/shared/debug.md`: the root cause goes in `.verify/debug.md` before the next fix. If you cannot +find it, report what is red, what you ruled out, and why. Never weaken, skip, delete or edit a test, a check command or a threshold to get green. Those change the contract; propose them to the user. diff --git a/plugins/dx-workflow/skills/flow/SKILL.md b/plugins/dx-workflow/skills/flow/SKILL.md new file mode 100644 index 0000000..1a412af --- /dev/null +++ b/plugins/dx-workflow/skills/flow/SKILL.md @@ -0,0 +1,71 @@ +--- +name: flow +description: Use at the start of any feature, fix or change request bigger than a one-line edit, and whenever unsure what comes next. Sizes the change and runs it through define, acceptance, tasks, build, debug, verify and learn, with a gate between each step; routes each step to the frontend or backend skill, or to an installed skill pack (Matt Pocock's skills, superpowers, agent-skills) where one does that step well. +--- + +# Flow: from request to merged, with a gate between every step + +## Overview + +The `frontend` and `backend` skills prove a change is right. This skill decides which steps a change +needs before that, in what order, and what must be true before the next step starts. Each step leaves +a file the next step reads, so a review's marks trace back to the goals the user agreed: + +```text +request → spec (S goals, A criteria) → tasks (T, each owning some A) → .verify/acceptance.md + → tests and code → run-verify → independent review → evidence pack + merge tier → ratchet +``` + +`<plugin>` is two levels up from this skill (it holds `scripts/` and `shared/`). Other skill packs +may do a step's work; the gates and the files of record stay this plugin's +(`<plugin>/shared/skill-packs.md`). + +## 1. Size the change + +| Size | When | Steps | +| --- | --- | --- | +| S | copy, a colour, a one-line fix, a config value; no contract, no migration, no auth, no native change | acceptance (1 to 3 criteria) → build → verify | +| M | one feature or fix inside one or two lanes that fits one pull request (about 400 changed lines), no contract change | acceptance with the adverse cases → build → verify | +| L | a new flow; an API, data or design contract change; a migration; auth or payments; a native change; more than one pull request; or the user cannot yet say what done looks like | define → acceptance in the spec → tasks → per task as M → verify each | + +When unsure between two sizes, take the larger. Tell the user the size and the steps in one line +before starting, so they can say "smaller". + +## 2. The steps and their gates + +| Step | Produces | Gate to the next step | How | +| --- | --- | --- | --- | +| Define (L) | `docs/specs/<slug>.md`: problem, goals `S1…`, non-goals, constraints, decisions `D1…`, open questions `Q1…` | `node <plugin>/scripts/flow-check.mjs spec docs/specs/<slug>.md` exits 0: the user agreed it, no question is open, every goal has a criterion | `<plugin>/shared/spec.md` | +| Acceptance | L: the spec's `## Acceptance` (`A1 … (S1) · proof: …`). S and M: `.verify/acceptance.md` | every criterion observable, with a proof; adverse cases decided | `<plugin>/shared/acceptance.md` | +| Tasks (L) | `docs/specs/<slug>.tasks.md`: `T1…`, each with lanes, the criteria it delivers, dependencies, size S or M, a risk tier guess | `flow-check.mjs tasks docs/specs/<slug>.tasks.md` exits 0: every criterion in a task, no cycle, nothing larger than M | `<plugin>/shared/tasks.md` | +| Start a task | `.verify/acceptance.md` for that task, traced to the spec | `flow-check.mjs acceptance docs/specs/<slug>.md T<n> --write`, then add the adverse cases for its lanes | below | +| Build | tests first, then code, at the seams `docs/backend.md` and `docs/design.md` name | the new tests fail without the code (the negative check proves it later) | the lane's skill: `frontend` or `backend`, `build.md` | +| Debug | the root cause in `.verify/debug.md`, and a test that reproduces it | `run-verify.mjs` reports the same check failing two runs in a row: stop and diagnose before the next fix | `<plugin>/shared/debug.md` | +| Verify | `run-verify.mjs` pass, an independent review of the same tree, the evidence pack with a merge tier | the Stop gate; the tier says who must look | the lane's skill, `verify.md` | +| Learn | a check, a checklist item or a contract line for every Blocker, revert and correction | admitted with evidence, in its own change | `<plugin>/shared/ratchet.md` | +| Ship | the merge, by tier | tier 1: merge; 2: a person looks at what the pack flags; 3: the owner approves | your team's process; this plugin does not deploy | + +A step's gate is a command or a file, not a feeling. If a gate is shut, the next step does not start; +say which gate and why. + +## 3. Several tasks + +- Take the tasks `flow-check.mjs next docs/specs/<slug>.tasks.md --done <ids>` lists; independent + ones can run in parallel, each on its own branch and worktree (superpowers `using-git-worktrees` + does this well). Every worktree has its own `.verify/`, so each task is verified alone. +- One task, one pull request, one evidence pack. Mark a task done in the tasks file + (`- status: done · PR #123`) when its pull request merges, not when its code is written. +- When a task shows the spec was wrong, change the spec first (the user agrees again), then the + tasks, then the code. Never let code and spec drift apart silently. + +## 4. Size S and M + +No spec file: write `.verify/acceptance.md` straight from the request with `shared/acceptance.md` +(for M, with the adverse cases), then the lane's `build.md` and `verify.md`. The steps are the same; +the define and tasks steps are empty. + +## 5. When another skill pack is installed + +Use it for the work inside a step, never for the gates. The table of which skill does which step, +and the rules when they disagree with this plugin, is `<plugin>/shared/skill-packs.md`. Read it +before invoking one of them inside this flow. diff --git a/plugins/dx-workflow/skills/frontend/SKILL.md b/plugins/dx-workflow/skills/frontend/SKILL.md index 9fe3bd4..909bc9d 100644 --- a/plugins/dx-workflow/skills/frontend/SKILL.md +++ b/plugins/dx-workflow/skills/frontend/SKILL.md @@ -17,6 +17,8 @@ Third-party design skills are tools this workflow calls; they never override the | Project state | Read | | --- | --- | +| A new feature, a contract or migration change, or unsure which steps a change needs | the `flow` skill first: it sizes the change and may need a spec and tasks before this skill | +| The same check failed two runs in a row, or the user reports a bug | `<plugin>/shared/debug.md` before the next fix | | No `docs/design.md` | `setup.md`, then come back | | The app is React Native or Expo (a lane with `"platform": "react-native"`) | `mobile.md` alongside every file below | | Any change | `<plugin>/shared/acceptance.md` first: write `.verify/acceptance.md` | diff --git a/test/flow.test.mjs b/test/flow.test.mjs new file mode 100644 index 0000000..befb61c --- /dev/null +++ b/test/flow.test.mjs @@ -0,0 +1,155 @@ +import assert from "node:assert/strict"; +import { after, describe, it } from "node:test"; +import { checkSpec, checkTasks, parseSpec, parseTasks, readyTasks } from "../plugins/dx-workflow/scripts/lib/flow.mjs"; +import { addFeature, cleanup, evidenceText, makeProject, node, read, verify, write } from "./helpers.mjs"; + +const roots = []; +const project = (opts) => { + const r = makeProject(opts); + roots.push(r); + return r; +}; +after(() => roots.forEach(cleanup)); + +const SPEC = `# Spec: Subtraction for the calculator +Status: agreed +Owner: David + +## Problem +Users can only add. + +## Goals +- S1 A user can subtract two numbers +- S2 Negative results are shown, not hidden + +## Non-goals +- Multiplication + +## Decisions +- D1 Integers only · keeps parsing simple · David + +## Open questions +- Q1 Decimals? → D1 +- Q2 Locale formatting? · deferred: integers have no separators to localise + +## Acceptance +- A1 sub(5, 3) returns 2 (S1) · proof: test/run.mjs +- A2 sub(3, 5) returns -2 (S1, S2) · proof: test/run.mjs +`; + +const TASKS = `# Tasks: Subtraction + +## T1 Core sub +- lanes: backend +- acceptance: A1 +- depends: none +- size: S +- risk: 1 · new function only + +## T2 Negative results +- lanes: backend +- acceptance: A2 +- depends: T1 +- size: S +- risk: 1 · same module +`; + +describe("spec gate", () => { + it("opens for a complete, agreed spec", () => { + assert.deepEqual(checkSpec(parseSpec(SPEC)), []); + }); + + it("names every reason it is shut", () => { + const bad = SPEC.replace("Status: agreed", "Status: draft") + .replace("- Q1 Decimals? → D1", "- Q1 Decimals? · owner: David") + .replace("- A2 sub(3, 5) returns -2 (S1, S2) · proof: test/run.mjs", "- A2 sub(3, 5) returns -2 (S1, S9)") + .replace("- Multiplication\n", ""); + const p = checkSpec(parseSpec(bad)).join("\n"); + assert.match(p, /Status is "draft"/); + assert.match(p, /Q1 is open/); + assert.match(p, /S2 has no acceptance criterion/); + assert.match(p, /A2 cites S9, which is not a goal/); + assert.match(p, /A2 names no proof/); + assert.match(p, /no non-goals/); + }); +}); + +describe("tasks gate", () => { + const spec = parseSpec(SPEC); + + it("opens when every criterion is in a task, and lists what can start", () => { + const tasks = parseTasks(TASKS); + assert.deepEqual(checkTasks(tasks, spec, ["backend"]), []); + assert.deepEqual(readyTasks(tasks).map((t) => t.id), ["T1"]); + assert.deepEqual(readyTasks(tasks, ["T1"]).map((t) => t.id), ["T2"]); + }); + + it("shuts on uncovered criteria, unknown lanes, large tasks, missing risk and cycles", () => { + const bad = TASKS.replace("- acceptance: A2", "- acceptance: A7") + .replace("- depends: none", "- depends: T2") + .replace("- lanes: backend\n- acceptance: A1", "- lanes: mobile\n- acceptance: A1") + .replace("- size: S\n- risk: 1 · same module", "- size: L"); + const p = checkTasks(parseTasks(bad), spec, ["backend"]).join("\n"); + assert.match(p, /T2 cites A7/); + assert.match(p, /A2 is in no task/); + assert.match(p, /T1: lane "mobile" is not in/); + assert.match(p, /T2 size is "L"/); + assert.match(p, /T2 risk is "missing"/); + assert.match(p, /circle: T1 → T2 → T1|circle: T2 → T1 → T2/); + }); +}); + +describe("flow-check CLI", () => { + it("gates, lists the next task, and writes a traced acceptance file the evidence pack carries", () => { + const root = project(); + write(root, { "docs/specs/sub.md": SPEC, "docs/specs/sub.tasks.md": TASKS }); + assert.equal(node("flow-check.mjs", ["spec", "docs/specs/sub.md"], { cwd: root }).code, 0); + const t = node("flow-check.mjs", ["tasks", "docs/specs/sub.tasks.md"], { cwd: root }); + assert.equal(t.code, 0, t.stdout); + assert.match(t.stdout, /Start with: T1/); + assert.match(node("flow-check.mjs", ["next", "docs/specs/sub.tasks.md", "--done", "T1"], { cwd: root }).stdout, /^T2 Negative results/); + + const w = node("flow-check.mjs", ["acceptance", "docs/specs/sub.md", "T1", "--write"], { cwd: root }); + assert.equal(w.code, 0, w.stderr); + const acc = read(root, ".verify/acceptance.md"); + assert.match(acc, /^Spec: docs\/specs\/sub\.md$/m); + assert.match(acc, /^Task: T1 \(docs\/specs\/sub\.tasks\.md\)$/m); + assert.match(acc, /^Lanes: backend$/m); + assert.match(acc, /^- A1 sub\(5, 3\) returns 2/m); + assert.doesNotMatch(acc, /A2/); + assert.match(acc, /^- S1 A user can subtract two numbers$/m); + + addFeature(root); + verify(root, { acceptance: false }); + assert.match(evidenceText(root), /^Spec: docs\/specs\/sub\.md\nTask: T1/m); + }); + + it("refuses to write acceptance from a spec the user has not agreed", () => { + const root = project(); + write(root, { "docs/specs/sub.md": SPEC.replace("Status: agreed", "Status: draft") }); + const r = node("flow-check.mjs", ["acceptance", "docs/specs/sub.md", "--write"], { cwd: root }); + assert.equal(r.code, 1); + assert.match(r.stdout, /Status is "draft"/); + }); +}); + +describe("repeated failures", () => { + it("sends the second failure in a row to debugging, resets on a pass, and the evidence shows the cause", () => { + const root = project(); + write(root, { "src/math.mjs": "export const add = (a, b) => a - b;\n" }); + let r = node("run-verify.mjs", ["--only", "unit"], { cwd: root }); + assert.doesNotMatch(r.stdout, /failed again/); + r = node("run-verify.mjs", ["--only", "unit"], { cwd: root }); + assert.match(r.stdout, /failed again: backend\/unit \(2 runs\)\. .*shared\/debug\.md/); + assert.equal(JSON.parse(read(root, ".verify/last-run.json")).lanes.backend.checks[0].failedRunsInARow, 2); + + write(root, { "src/math.mjs": "export const add = (a, b) => a + b;\n" }); + node("run-verify.mjs", ["--only", "unit"], { cwd: root }); + assert.deepEqual(JSON.parse(read(root, ".verify/failures.json")), {}); + + addFeature(root); + write(root, { ".verify/debug.md": "# Debug\n- check: backend/unit · failed 2 runs in a row\n- cause: add subtracted\n" }); + verify(root); + assert.match(evidenceText(root), /## Diagnosed failures\n\n- check: backend\/unit/); + }); +}); diff --git a/test/helpers.mjs b/test/helpers.mjs index b866ce2..c5f455f 100644 --- a/test/helpers.mjs +++ b/test/helpers.mjs @@ -100,11 +100,11 @@ export function addFeature(root) { } /** Everything the gate asks for: a passing run, acceptance, an approved review naming the run's tree, evidence. */ -export function verify(root, { runArgs = [], reviewTree, lane = "backend" } = {}) { +export function verify(root, { runArgs = [], reviewTree, lane = "backend", acceptance = true } = {}) { const run = node("run-verify.mjs", runArgs, { cwd: root }); const last = JSON.parse(read(root, ".verify/last-run.json")); + if (acceptance) write(root, { ".verify/acceptance.md": "# Acceptance: sub\n## Criteria\n- A1 sub(5, 3) returns 2 · proof: test/run.mjs\n" }); write(root, { - ".verify/acceptance.md": "# Acceptance: sub\n## Criteria\n- A1 sub(5, 3) returns 2 · proof: test/run.mjs\n", [`.verify/review-${lane}.md`]: [ `# Review ${last.lanes[lane].runDir}`, "Reviewer: test", diff --git a/vendor.lock.json b/vendor.lock.json index 0af34fe..9868f3d 100644 --- a/vendor.lock.json +++ b/vendor.lock.json @@ -1,5 +1,5 @@ { - "note": "Third-party tools dx-workflow calls or adapted from. Upgrade one at a time: read its diff, rerun run-verify on two projects, then bump the commit here.", + "note": "Third-party tools dx-workflow calls, routes to, or adapted from. Upgrade one at a time: read its diff, rerun run-verify on two projects, then bump the commit here.", "called": { "taste-skill": { "repo": "https://github.com/Leonxlnx/taste-skill", @@ -32,6 +32,72 @@ ] } }, + "routed": { + "note": "Used for the work inside a flow step when installed; never vendored. shared/skill-packs.md says which step and where this plugin overrides them.", + "mattpocock-skills": { + "repo": "https://github.com/mattpocock/skills", + "commit": "5863806dd4e15c63174bee4e7515a4256792ecfa", + "version": "1.3.2", + "license": "MIT", + "install": "/plugin install mattpocock-skills@claude-plugins-official", + "skills": [ + "grilling", + "grill-with-docs", + "domain-modeling", + "to-tickets", + "tdd", + "diagnosing-bugs", + "improve-codebase-architecture", + "codebase-design", + "retro" + ] + }, + "superpowers": { + "repo": "https://github.com/obra/superpowers", + "commit": "22f0b463e7a5e579904dd6211a520321035526f7", + "version": "7.0.2", + "license": "MIT, Copyright (c) 2025 Jesse Vincent", + "install": "/plugin install superpowers@claude-plugins-official (or /plugin marketplace add obra/superpowers-marketplace && /plugin install superpowers@superpowers-marketplace)", + "skills": [ + "brainstorming", + "writing-plans", + "test-driven-development", + "using-git-worktrees", + "dispatching-parallel-agents", + "systematic-debugging" + ], + "overridden": [ + "verification-before-completion", + "requesting-code-review", + "subagent-driven-development (task reviewer)", + "finishing-a-development-branch", + "using-superpowers" + ] + }, + "agent-skills": { + "repo": "https://github.com/addyosmani/agent-skills", + "commit": "39b723ceebf81474d0557c1fecd01eddab585563", + "version": "0.6.16", + "license": "MIT, Copyright (c) 2025 Addy Osmani", + "install": "/plugin marketplace add addyosmani/agent-skills && /plugin install agent-skills@addy-agent-skills", + "skills": [ + "interview-me", + "spec-driven-development", + "planning-and-task-breakdown", + "test-driven-development", + "debugging-and-error-recovery", + "browser-testing-with-devtools", + "code-simplification", + "security-and-hardening", + "performance-optimization" + ], + "overridden": [ + "code-review-and-quality", + "shipping-and-launch", + "using-agent-skills" + ] + } + }, "adapted": { "pstack": { "repo": "https://github.com/cursor/plugins/tree/main/pstack",