opencode-agent-harness 0.0.0-stage → 0.3.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/CHANGELOG.md +217 -0
  2. package/LICENSE +21 -0
  3. package/README.md +636 -2
  4. package/bin/agent-harness.js +3182 -0
  5. package/contrib/global-plugins/README.md +49 -0
  6. package/contrib/global-plugins/harness-freshness.ts +355 -0
  7. package/package.json +86 -4
  8. package/templates/.agents/AGENTS.md +148 -0
  9. package/templates/.agents/features/INDEX.md +10 -0
  10. package/templates/.agents/handoffs/README.md +87 -0
  11. package/templates/.agents/memory/dev-loop.md +59 -0
  12. package/templates/.agents/memory/domain-map.md +29 -0
  13. package/templates/.agents/memory/environments.md +35 -0
  14. package/templates/.agents/memory/flow-map.md +23 -0
  15. package/templates/.agents/memory/history.md +7 -0
  16. package/templates/.agents/memory/locations.md +14 -0
  17. package/templates/.agents/memory/model-routing.md +261 -0
  18. package/templates/.agents/memory/orchestration.md +183 -0
  19. package/templates/.agents/memory/owned-files.md +19 -0
  20. package/templates/.agents/memory/product-principles.md +37 -0
  21. package/templates/.agents/memory/quality-parameters.md +37 -0
  22. package/templates/.agents/memory/stack-versions.md +35 -0
  23. package/templates/.agents/memory/test-design-parameters.md +36 -0
  24. package/templates/.agents/nightly.json +17 -0
  25. package/templates/.agents/qa-plans/README.md +70 -0
  26. package/templates/.agents/qa-runs/README.md +21 -0
  27. package/templates/.agents/reviews/README.md +47 -0
  28. package/templates/.agents/rules/00-operating.md +199 -0
  29. package/templates/.agents/skills/data-engineer/SKILL.md +31 -0
  30. package/templates/.agents/skills/devops-engineer/SKILL.md +50 -0
  31. package/templates/.agents/skills/diagnostics-expert/SKILL.md +44 -0
  32. package/templates/.agents/skills/docs/SKILL.md +140 -0
  33. package/templates/.agents/skills/features/SKILL.md +187 -0
  34. package/templates/.agents/skills/frontend-engineer/SKILL.md +81 -0
  35. package/templates/.agents/skills/handoff/SKILL.md +85 -0
  36. package/templates/.agents/skills/mobile-engineer/SKILL.md +101 -0
  37. package/templates/.agents/skills/planner/SKILL.md +112 -0
  38. package/templates/.agents/skills/product-manager/SKILL.md +115 -0
  39. package/templates/.agents/skills/qa-architect/SKILL.md +224 -0
  40. package/templates/.agents/skills/qa-runner/SKILL.md +64 -0
  41. package/templates/.agents/skills/security-engineer/SKILL.md +53 -0
  42. package/templates/.agents/skills/system-architect/SKILL.md +42 -0
  43. package/templates/.agents/skills/ui-designer/SKILL.md +71 -0
  44. package/templates/.github/workflows/ci.yml +148 -0
  45. package/templates/.github/workflows/deploy-uat.yml +95 -0
  46. package/templates/.github/workflows/nightly.yml +83 -0
  47. package/templates/.github/workflows/uat-health.yml +41 -0
  48. package/templates/.husky/pre-push +23 -0
  49. package/templates/.ignore +28 -0
  50. package/templates/.opencode/agents/data-engineer.md +37 -0
  51. package/templates/.opencode/agents/devops-engineer.md +37 -0
  52. package/templates/.opencode/agents/diagnostics-expert.md +37 -0
  53. package/templates/.opencode/agents/docs.md +37 -0
  54. package/templates/.opencode/agents/features.md +21 -0
  55. package/templates/.opencode/agents/frontend-engineer.md +37 -0
  56. package/templates/.opencode/agents/handoff.md +21 -0
  57. package/templates/.opencode/agents/mobile-engineer.md +37 -0
  58. package/templates/.opencode/agents/planner.md +34 -0
  59. package/templates/.opencode/agents/product-manager.md +29 -0
  60. package/templates/.opencode/agents/qa-architect.md +27 -0
  61. package/templates/.opencode/agents/qa-runner.md +17 -0
  62. package/templates/.opencode/agents/security-engineer.md +37 -0
  63. package/templates/.opencode/agents/system-architect.md +37 -0
  64. package/templates/.opencode/agents/ui-designer.md +37 -0
  65. package/templates/.opencode/commands/board.md +15 -0
  66. package/templates/.opencode/commands/checkpoint.md +25 -0
  67. package/templates/.opencode/commands/feature.md +56 -0
  68. package/templates/.opencode/commands/finish.md +36 -0
  69. package/templates/.opencode/commands/next.md +49 -0
  70. package/templates/.opencode/commands/report.md +55 -0
  71. package/templates/.opencode/commands/resume.md +39 -0
  72. package/templates/.opencode/commands/switch-model.md +34 -0
  73. package/templates/.opencode/commands/tidy.md +49 -0
  74. package/templates/.opencode/plugins/backlog-notify.ts +57 -0
  75. package/templates/.opencode/plugins/backlog.ts +272 -0
  76. package/templates/.opencode/plugins/checkpoint.ts +160 -0
  77. package/templates/.opencode/plugins/context-guard.ts +1164 -0
  78. package/templates/.opencode/plugins/diff.ts +85 -0
  79. package/templates/.opencode/plugins/gates.ts +71 -0
  80. package/templates/.opencode/plugins/job-notify.ts +241 -0
  81. package/templates/.opencode/plugins/orient.ts +67 -0
  82. package/templates/.opencode/plugins/session.ts +89 -0
  83. package/templates/.opencode/plugins/wait.ts +101 -0
  84. package/templates/.opencode/plugins/where.ts +70 -0
  85. package/templates/.opencode/skills/bounded-explore/SKILL.md +38 -0
  86. package/templates/.opencode/skills/dev-loop/SKILL.md +87 -0
  87. package/templates/.vercelignore +16 -0
  88. package/templates/AGENTS.md +27 -0
  89. package/templates/BACKLOG.md +95 -0
  90. package/templates/docs/ci-cd-pipeline.md +81 -0
  91. package/templates/docs/gates.md +128 -0
  92. package/templates/docs/mcp-integrations.md +97 -0
  93. package/templates/docs/mobile-testing.md +555 -0
  94. package/templates/docs/nightly-testing.md +106 -0
  95. package/templates/docs/wsl-optimizations.md +290 -0
  96. package/templates/opencode.json +188 -0
  97. package/templates/scripts/agent-report.js +541 -0
  98. package/templates/scripts/agent-search.sh +117 -0
  99. package/templates/scripts/backlog.js +1924 -0
  100. package/templates/scripts/board-service.sh +214 -0
  101. package/templates/scripts/checkpoint.js +290 -0
  102. package/templates/scripts/finalize.js +416 -0
  103. package/templates/scripts/nightly.js +913 -0
  104. package/templates/scripts/orient.js +514 -0
  105. package/templates/scripts/qa/board-client.js +323 -0
  106. package/templates/scripts/qa/board-lib.js +96 -0
  107. package/templates/scripts/qa/board-sync.js +499 -0
  108. package/templates/scripts/qa/capacity-lib.js +916 -0
  109. package/templates/scripts/qa/check-backlog.js +434 -0
  110. package/templates/scripts/qa/check-capacity.js +85 -0
  111. package/templates/scripts/qa/check-ci-policy.js +164 -0
  112. package/templates/scripts/qa/check-concurrency.js +344 -0
  113. package/templates/scripts/qa/check-dispatch-config.js +296 -0
  114. package/templates/scripts/qa/check-docs.js +288 -0
  115. package/templates/scripts/qa/check-integrate.js +98 -0
  116. package/templates/scripts/qa/check-linger.js +160 -0
  117. package/templates/scripts/qa/check-prefix-stability.js +187 -0
  118. package/templates/scripts/qa/check-product.js +177 -0
  119. package/templates/scripts/qa/check-qa-plan.js +378 -0
  120. package/templates/scripts/qa/check-qa-scripts.js +85 -0
  121. package/templates/scripts/qa/check-quality.js +249 -0
  122. package/templates/scripts/qa/check-test-wiring.js +253 -0
  123. package/templates/scripts/qa/check-worktrees.js +93 -0
  124. package/templates/scripts/qa/ci-triage.js +346 -0
  125. package/templates/scripts/qa/ci-usage-lib.js +185 -0
  126. package/templates/scripts/qa/ci-wait-lib.js +294 -0
  127. package/templates/scripts/qa/command-classifier.js +552 -0
  128. package/templates/scripts/qa/context-guard-core.js +1618 -0
  129. package/templates/scripts/qa/diff.js +174 -0
  130. package/templates/scripts/qa/feature-scaffold.js +224 -0
  131. package/templates/scripts/qa/fixtures/backlog.md +104 -0
  132. package/templates/scripts/qa/governance.js +174 -0
  133. package/templates/scripts/qa/hash-file.js +32 -0
  134. package/templates/scripts/qa/lease-lib.js +263 -0
  135. package/templates/scripts/qa/merge-backlog.js +324 -0
  136. package/templates/scripts/qa/mobile-e2e/analyze-timings.js +300 -0
  137. package/templates/scripts/qa/mobile-e2e/apk-cache.js +420 -0
  138. package/templates/scripts/qa/mobile-e2e/backend-build-cache.js +203 -0
  139. package/templates/scripts/qa/mobile-e2e/boot-emulator.sh +432 -0
  140. package/templates/scripts/qa/mobile-e2e/build-apk.sh +210 -0
  141. package/templates/scripts/qa/mobile-e2e/check-flows.js +568 -0
  142. package/templates/scripts/qa/mobile-e2e/config.yaml +18 -0
  143. package/templates/scripts/qa/mobile-e2e/device-down.sh +88 -0
  144. package/templates/scripts/qa/mobile-e2e/device-up.sh +258 -0
  145. package/templates/scripts/qa/mobile-e2e/ios-simulator-down.sh +72 -0
  146. package/templates/scripts/qa/mobile-e2e/ios-simulator-up.sh +153 -0
  147. package/templates/scripts/qa/mobile-e2e/job-events.js +181 -0
  148. package/templates/scripts/qa/mobile-e2e/prewarm.sh +56 -0
  149. package/templates/scripts/qa/mobile-e2e/run-detached.sh +222 -0
  150. package/templates/scripts/qa/mobile-e2e/run-maestro.js +1543 -0
  151. package/templates/scripts/qa/mobile-e2e/ui-dump.js +327 -0
  152. package/templates/scripts/qa/models.allowlist.txt +32 -0
  153. package/templates/scripts/qa/provider-stats.js +878 -0
  154. package/templates/scripts/qa/run-clean.js +83 -0
  155. package/templates/scripts/qa/run-gates.js +213 -0
  156. package/templates/scripts/qa/run-loop.js +220 -0
  157. package/templates/scripts/qa/session-recon.js +512 -0
  158. package/templates/scripts/qa/store-lib.js +324 -0
  159. package/templates/scripts/qa/tool-lib.js +134 -0
  160. package/templates/scripts/qa/where.js +214 -0
  161. package/templates/scripts/qa/worktree-hygiene.js +217 -0
  162. package/templates/scripts/qa/wslconfig-merge.js +157 -0
  163. package/templates/scripts/serve.js +1328 -0
  164. package/templates/scripts/setup-nightly.sh +185 -0
  165. package/templates/scripts/setup-tmpfs.sh +374 -0
  166. package/templates/scripts/ship.js +586 -0
  167. package/templates/scripts/switch-reasoning-model.ps1 +101 -0
  168. package/templates/scripts/switch-reasoning-model.sh +104 -0
  169. package/templates/scripts/wait-for.js +342 -0
  170. package/templates/scripts/wsl-gpu.sh +180 -0
  171. package/templates/scripts/wsl-tune.sh +319 -0
@@ -0,0 +1,378 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /*
4
+ * test:qa-plan — diff-coverage gate (harness-shipped).
5
+ *
6
+ * The anti-verification-from-unrelated-suites gate. A tier label never proves
7
+ * coverage; this gate forces a change's QA plan to actually cover the code it
8
+ * modified — otherwise "verified" is meaningless.
9
+ *
10
+ * Two stages:
11
+ *
12
+ * 1. Coverage map — inspects the live git diff and requires every changed CODE
13
+ * path to appear in some QA plan's `## Coverage map` (persisted by
14
+ * qa-architect, or by the main orchestrator as the qa-architect fallback)
15
+ * BEFORE a change may be declared verified. Trivial diffs (copy/docs/not
16
+ * code) and waivered paths are exempt.
17
+ *
18
+ * QA plans are SHARDED: one file per change under `.agents/qa-plans/`
19
+ * (e.g. `F-003.md`, `return-no-condition.md`). The gate reads EVERY `.md`
20
+ * under that directory — plus the legacy single-file `.agents/memory/qa-plan.md`
21
+ * for backward compatibility — and unions their coverage maps, waivers, and
22
+ * audits. A changed path is covered if ANY plan file names it. Each session
23
+ * owns its own file, so concurrent sessions never collide on a shared plan.
24
+ *
25
+ * 2. Flow closure — reads `.agents/memory/flow-map.md` (project-owned): a
26
+ * registry of user-facing flows, each listing the SURFACES that implement the
27
+ * same behavior (web / mobile / API — any codebase/layer) and its optional
28
+ * VARIANTS. Any flow whose surfaces intersect this diff must have every
29
+ * sibling surface and every declared variant addressed in some plan's
30
+ * `## Parallel-surface & variant audit` (covered `->` or `audited:` with a
31
+ * reason). This is the gate that makes "Fix One, Fix All" mechanical: a
32
+ * web-only diff can no longer silently leave the mobile twin on old behavior.
33
+ * If flow-map.md is absent or lists no flows, the stage warns but never fails
34
+ * (backward compatible — projects opt into flow closure by filling it in).
35
+ *
36
+ * node scripts/qa/check-qa-plan.js # diff vs HEAD
37
+ * node scripts/qa/check-qa-plan.js --base main # diff vs a ref
38
+ * node scripts/qa/check-qa-plan.js --strict # non-code changes too
39
+ *
40
+ * Exit 0 on: no code-path changes, full coverage, valid waivers, full flow closure.
41
+ * Exit 1 on: a changed code path with no covering assertion/waiver, or a flow
42
+ * sibling surface / declared variant the QA plan does not address.
43
+ */
44
+ const fs = require("fs");
45
+ const path = require("path");
46
+ const { execFileSync } = require("child_process");
47
+
48
+ const root = path.resolve(__dirname, "..", "..");
49
+
50
+ const argv = process.argv.slice(2);
51
+ const base = (argv.find((a) => a.startsWith("--base=")) || "").split("=")[1] || "HEAD";
52
+ const strict = argv.includes("--strict");
53
+
54
+ // Paths that are tooling/harness, not application code under test. A change
55
+ // that only touches these needs no runtime QA plan (they are guarded by
56
+ // test:dispatch / test:governance themselves).
57
+ const TOOLING = [
58
+ "opencode.json",
59
+ ".harness.json",
60
+ ".opencode/",
61
+ ".agents/",
62
+ "scripts/qa/",
63
+ ".github/",
64
+ "package.json",
65
+ // Harness-shipped standalone CLIs (regenerated by `init`/`update`, guarded by
66
+ // test:dispatch / test:governance and the harness's own suite). These are not
67
+ // application code a project QA plan should cover — without this exemption a
68
+ // plain harness `update` that ships a new script trips test:qa-plan.
69
+ "scripts/backlog.js",
70
+ "scripts/checkpoint.js",
71
+ "scripts/agent-report.js",
72
+ "scripts/serve.js",
73
+ "scripts/ship.js",
74
+ "scripts/switch-reasoning-model.sh",
75
+ "scripts/switch-reasoning-model.ps1",
76
+ ];
77
+ // Non-code files never need a runtime path (copy/docs/styling/data-flat).
78
+ const NON_CODE = /\.(md|mdx|png|jpg|jpeg|gif|svg|webp|ico|json|lock|txt|env|yml|yaml|toml|csv)$/i;
79
+
80
+ const CODE = /\.(ts|tsx|js|jsx|css|scss|sass|prisma|sql)$/i;
81
+
82
+ function norm(p) {
83
+ return p.replace(/\\/g, "/");
84
+ }
85
+
86
+ function gitChangedFiles() {
87
+ let files = [];
88
+ try {
89
+ const out = execFileSync("git", ["diff", "--name-only", base, "--"], {
90
+ cwd: root,
91
+ encoding: "utf8",
92
+ });
93
+ files = out.split(/\r?\n/).filter(Boolean);
94
+ } catch (e) {
95
+ // 128 = not a git repo / bad ref / no base history (e.g. empty repo).
96
+ if (e.status === 128) return null;
97
+ throw e;
98
+ }
99
+ // include untracked files so brand-new sources can't silently skip the gate
100
+ try {
101
+ const untracked = execFileSync(
102
+ "git",
103
+ ["ls-files", "--others", "--exclude-standard", "--", root],
104
+ { cwd: root, encoding: "utf8" }
105
+ )
106
+ .split(/\r?\n/)
107
+ .filter(Boolean);
108
+ files = [...new Set([...files, ...untracked])];
109
+ } catch (_) {
110
+ /* ls-files is best-effort */
111
+ }
112
+ return files.map(norm);
113
+ }
114
+
115
+ function isTooling(p) {
116
+ const n = norm(p);
117
+ return TOOLING.some((t) => n === t || n.startsWith(t));
118
+ }
119
+
120
+ /* All QA plan files to union: every `.md` under `.agents/qa-plans/` (recursive),
121
+ * plus the legacy single `.agents/memory/qa-plan.md` if present (backward compat
122
+ * for projects deployed before sharding). `README.md` files are documentation,
123
+ * not plans, so they are skipped. Sorted for deterministic output. */
124
+ function planFiles(root) {
125
+ const files = [];
126
+ const collect = (dir) => {
127
+ if (!fs.existsSync(dir)) return;
128
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
129
+ const abs = path.join(dir, entry.name);
130
+ if (entry.isDirectory()) collect(abs);
131
+ else if (
132
+ entry.name.toLowerCase().endsWith(".md") &&
133
+ entry.name.toLowerCase() !== "readme.md"
134
+ )
135
+ files.push(abs);
136
+ }
137
+ };
138
+ collect(path.join(root, ".agents", "qa-plans"));
139
+ const legacy = path.join(root, ".agents", "memory", "qa-plan.md");
140
+ if (fs.existsSync(legacy)) files.push(legacy);
141
+ return files.sort();
142
+ }
143
+
144
+ /* Parse the QA plan file into { covered:Set, waivers:Set } of normalized paths.
145
+ * Coverage map format (one entry per changed path, under `## Coverage map`):
146
+ * - components/return/ReturnConfirmDrawer.tsx -> test:quick::progression (click-through)
147
+ * Waivers live anywhere and carry a reason on the same line:
148
+ * waived: components/nav.tsx reason: pure-copy change, no runtime path
149
+ */
150
+ function parsePlan(file) {
151
+ const out = { covered: new Set(), waivers: new Set() };
152
+ if (!fs.existsSync(file)) return out;
153
+ const src = fs.readFileSync(file, "utf8");
154
+ const lines = src.split(/\r?\n/);
155
+
156
+ // Coverage map section only
157
+ let inMap = false;
158
+ for (const raw of lines) {
159
+ const line = raw.trim();
160
+ if (!line) continue;
161
+ if (/^#{1,6}\s*Coverage map\s*$/i.test(line)) {
162
+ inMap = true;
163
+ continue;
164
+ }
165
+ if (/^[#;/]/.test(line)) continue;
166
+ if (inMap && /^#{1,6}\s/.test(line)) inMap = false;
167
+ if (!inMap) continue;
168
+
169
+ const m = line.match(/^[-*]\s*["']?([^\s"'>]+)/);
170
+ if (m) out.covered.add(norm(m[1]));
171
+ }
172
+
173
+ // Waivers (anywhere) — path then reason
174
+ for (const raw of lines) {
175
+ const line = raw.trim();
176
+ if (!/\bwaived:\s*\S/i.test(line)) continue;
177
+ const p = (line.match(/\bwaived:\s*["']?([^\s"',]+)/i) || [])[1];
178
+ if (p && /\breason:\s*\S/i.test(line)) out.waivers.add(norm(p));
179
+ }
180
+ return out;
181
+ }
182
+
183
+ function isCovered(pathi, covered, waivers) {
184
+ if (covered.has(pathi) || waivers.has(pathi)) return true;
185
+ // directory-prefix coverage (a plan may cover a whole folder)
186
+ for (const c of covered) if (pathi.startsWith(c.replace(/\/?$/, "/"))) return true;
187
+ for (const w of waivers) if (pathi.startsWith(w.replace(/\/?$/, "/"))) return true;
188
+ return false;
189
+ }
190
+
191
+ /* Parse `.agents/memory/flow-map.md` into [{ name, surfaces:[], variants:[] }].
192
+ * Format (one flow per `## flow:` header):
193
+ * ## flow: return
194
+ * behavior: "Mark as Returned" — optional condition payload (condition selector)
195
+ * surfaces: components/LendingActionDrawers.tsx, mobile/features/return/ReturnStatusSheet.tsx, app/api/transactions/[id]/return/route.ts
196
+ * variants: condition-selector-present, condition-selector-absent
197
+ */
198
+ function parseFlowMap(file) {
199
+ const flows = [];
200
+ if (!fs.existsSync(file)) return flows;
201
+ let cur = null;
202
+ for (const raw of fs.readFileSync(file, "utf8").split(/\r?\n/)) {
203
+ const line = raw.trim();
204
+ if (!line) continue;
205
+ const h = line.match(/^#{1,6}\s*flow:\s*(.+)$/i);
206
+ if (h) {
207
+ cur = { name: h[1].trim(), surfaces: [], variants: [] };
208
+ flows.push(cur);
209
+ continue;
210
+ }
211
+ if (/^[#;]/.test(line)) continue;
212
+ if (!cur) continue;
213
+ const s = line.match(/^surfaces?:\s*(.+)$/i);
214
+ if (s) cur.surfaces = s[1].split(",").map((x) => norm(x.trim())).filter(Boolean);
215
+ const v = line.match(/^variants?:\s*(.+)$/i);
216
+ if (v) cur.variants = v[1].split(",").map((x) => x.trim()).filter(Boolean);
217
+ }
218
+ return flows.filter((f) => f.name && f.surfaces.length > 0);
219
+ }
220
+
221
+ /* Parse the plan's `## Parallel-surface & variant audit` entries.
222
+ * Entry forms:
223
+ * - <surface> -> <assertion>
224
+ * - <surface> audited: <reason>
225
+ * - flow: <name> variant: <label> -> <assertion>
226
+ * - flow: <name> variant: <label> audited: <reason>
227
+ */
228
+ function parseAudit(file) {
229
+ const entries = [];
230
+ if (!fs.existsSync(file)) return entries;
231
+ let inAudit = false;
232
+ for (const raw of fs.readFileSync(file, "utf8").split(/\r?\n/)) {
233
+ const line = raw.trim();
234
+ if (!line) continue;
235
+ if (/^#{1,6}\s*Parallel[ -]surface.{0,40}(?:&\s*|and\s+).{0,40}audit\s*$/i.test(line)) {
236
+ inAudit = true;
237
+ continue;
238
+ }
239
+ if (/^[#;]/.test(line)) continue;
240
+ if (inAudit && /^#{1,6}\s/.test(line)) inAudit = false;
241
+ if (!inAudit) continue;
242
+
243
+ const vm = line.match(/^[-*]\s*flow:\s*["']?([^\s"']+)\s+variant:\s*["']?([^\s"']+)\s+(audited:.+|->\s*.+)$/i);
244
+ if (vm) {
245
+ entries.push({ flow: vm[1], variant: vm[2], surface: null, disposition: vm[3].trim() });
246
+ continue;
247
+ }
248
+ const pm = line.match(/^[-*]\s*["']?([^\s"'>]+)\s+(audited:.+|->\s*.+)$/);
249
+ if (pm) entries.push({ surface: norm(pm[1]), disposition: pm[2].trim() });
250
+ }
251
+ return entries;
252
+ }
253
+
254
+ /* True when path a and path b are the same file/dir or one nests under the other
255
+ * as a directory prefix — lenient matching for surfaces vs coverage/audit paths. */
256
+ function matches(a, b) {
257
+ const A = norm(a).replace(/\/$/, "");
258
+ const B = norm(b).replace(/\/$/, "");
259
+ return A === B || A.startsWith(B + "/") || B.startsWith(A + "/");
260
+ }
261
+
262
+ const failures = [];
263
+ const pass = (m) => console.log(" \u2713 " + m);
264
+ const fail = (m) => {
265
+ failures.push(m);
266
+ console.log(" \u2717 " + m);
267
+ };
268
+
269
+ console.log("diff-coverage gate \u2014 QA plan covers every changed code path");
270
+
271
+ const changed = gitChangedFiles();
272
+ if (changed == null) {
273
+ console.log(" \u26a0 not a git repo or no base history \u2014 coverage gate skipped");
274
+ console.log("\nRESULT: skipped (0 failures)");
275
+ process.exit(0);
276
+ }
277
+ if (changed.length === 0) {
278
+ console.log(" \u2713 no diff vs " + base + " \u2014 nothing to cover");
279
+ console.log("\nRESULT: green");
280
+ process.exit(0);
281
+ }
282
+
283
+ const plans = planFiles(root);
284
+ const covered = new Set();
285
+ const waivers = new Set();
286
+ const audit = [];
287
+ for (const file of plans) {
288
+ const p = parsePlan(file);
289
+ for (const c of p.covered) covered.add(c);
290
+ for (const w of p.waivers) waivers.add(w);
291
+ audit.push(...parseAudit(file));
292
+ }
293
+
294
+ if (plans.length === 0) {
295
+ console.log(
296
+ " \u26a0 no QA plan files found \u2014 add one under .agents/qa-plans/<feature-id>.md (or .agents/memory/qa-plan.md)"
297
+ );
298
+ } else {
299
+ console.log(
300
+ " checked against: " + plans.map((f) => path.relative(root, f)).join(", ")
301
+ );
302
+ }
303
+
304
+ const changedCode = [];
305
+ for (const f of changed) {
306
+ if (isTooling(f)) {
307
+ pass(`${f} (harness/tooling \u2014 self-guarded)`);
308
+ continue;
309
+ }
310
+ if (NON_CODE.test(f) && !strict) {
311
+ pass(`${f} (non-code \u2014 no runtime path required)`);
312
+ continue;
313
+ }
314
+ if (!CODE.test(f)) {
315
+ pass(`${f} (not a code path)`);
316
+ continue;
317
+ }
318
+ changedCode.push(f);
319
+ if (isCovered(f, covered, waivers)) pass(`${f} covered by QA plan`);
320
+ else
321
+ fail(
322
+ `${f} NOT covered \u2014 add it to the \`## Coverage map\` in a .agents/qa-plans/<feature-id>.md plan (or a waivered entry with a reason)`
323
+ );
324
+ }
325
+
326
+ // ------------------------------------------------------------ flow closure
327
+ const flowMap = parseFlowMap(path.join(root, ".agents", "memory", "flow-map.md"));
328
+ const hitFlows = new Set();
329
+ for (const f of flowMap) {
330
+ if (changedCode.some((c) => f.surfaces.some((s) => matches(c, s)))) hitFlows.add(f);
331
+ }
332
+
333
+ if (!flowMap.length) {
334
+ console.log(
335
+ " \u26a0 flow-map.md has no flows \u2014 sibling/variant closure NOT enforced (add flows to secure \"Fix One, Fix All\")"
336
+ );
337
+ } else if (hitFlows.size) {
338
+ console.log("flow-closure gate \u2014 every sibling surface & variant of a touched flow is addressed");
339
+ for (const f of flowMap) {
340
+ if (!hitFlows.has(f)) {
341
+ pass(`flow "${f.name}" not touched \u2014 no sibling requirement`);
342
+ continue;
343
+ }
344
+ // Sibling surfaces: every declared surface must be addressed by the diff
345
+ // (as a changed path) or by a named audit entry, or audited with a reason.
346
+ for (const s of f.surfaces) {
347
+ if (changedCode.some((c) => matches(c, s))) {
348
+ continue; // the changed path itself is required in the Coverage map above
349
+ }
350
+ const addressed = audit.some((e) => e.surface && matches(e.surface, s));
351
+ if (addressed) pass(`flow "${f.name}": sibling \`${s}\` addressed in audit`);
352
+ else
353
+ fail(
354
+ `flow "${f.name}": sibling surface \`${s}\` not addressed \u2014 add it to \`## Parallel-surface & variant audit\` as \`-> <assertion>\` or \`audited: <reason>\``
355
+ );
356
+ }
357
+ // Declared variants: each must be named with a disposition for this flow.
358
+ for (const v of f.variants) {
359
+ const addressed = audit.some((e) => e.flow && e.variant && e.flow === f.name && e.variant === v);
360
+ if (addressed) pass(`flow "${f.name}": variant \`${v}\` addressed`);
361
+ else
362
+ fail(
363
+ `flow "${f.name}": declared variant \`${v}\` not addressed \u2014 add \`flow: ${f.name} variant: ${v} -> <assertion>\` or \`... audited: <reason>\` to \`## Parallel-surface & variant audit\``
364
+ );
365
+ }
366
+ }
367
+ }
368
+
369
+ if (!changedCode.length) {
370
+ console.log(" \u2713 no application code paths changed");
371
+ }
372
+ console.log(
373
+ "\nRESULT: " +
374
+ (failures.length
375
+ ? `${failures.length} FAILURE(S) \u2014 every changed code path needs a covering assertion or a waivered reason; every touched flow's sibling surfaces & variants must be addressed in the audit`
376
+ : "green \u2014 all changed code paths have a covering QA plan and all touched flows are closed")
377
+ );
378
+ process.exit(failures.length ? 1 : 0);
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /*
4
+ * check-qa-scripts — verify the QA-tier npm scripts the rulebook's Definition of
5
+ * Done references actually exist in the target project's package.json.
6
+ *
7
+ * The harness ships only `test:dispatch` and `test:governance`; the runtime QA
8
+ * tiers (test:quick / test:routes / test:api / test:verify / test:security) are
9
+ * PROJECT-PROVIDED. This gate emits warnings for missing ones so a fresh deploy
10
+ * doesn't silently claim a QA tier that isn't wired up.
11
+ *
12
+ * node scripts/qa/check-qa-scripts.js # warnings only, exit 0
13
+ * node scripts/qa/check-qa-scripts.js --strict # fail (exit 1) on missing
14
+ */
15
+ const fs = require("fs");
16
+ const path = require("path");
17
+
18
+ const root = path.resolve(__dirname, "..", "..");
19
+ const strict = process.argv.includes("--strict");
20
+
21
+ // npm scripts referenced by the DoD / QA tier matrix.
22
+ const EXPECTED = {
23
+ "test:dispatch": "harness — persona model-pin preflight (shipped)",
24
+ "test:governance": "harness — session-governance gate (shipped)",
25
+ "test:qa-plan": "harness — diff-coverage + flow-closure gate (changed code paths covered; touched flows' sibling surfaces/variants audited)",
26
+ "test:backlog": "harness — canonical single-file backlog gate (board schema + depends-on references valid)",
27
+ "test:concurrency": "harness — cross-session working-tree guard (a concurrent session's uncommitted work must not leak into your push)",
28
+ "test:integrate": "harness — pre-push rebase check (rebase onto main before push, so conflicts surface early)",
29
+ "test:quality": "harness — mechanical code-quality gate on new/changed code (dead exports + oversized files; rubric in .agents/memory/quality-parameters.md)",
30
+ "test:wiring": "harness — orphan-test gate (every *.test.* file is executed by a package script; test-design param T7)",
31
+ "test:linger": "harness — exit-contract gate (process wall-clock vs runner-reported test duration on a tier; wraps test:quick by default; test-design params T1/T6/T9)",
32
+ "test:quick": "Tier 1 — types + translations + mobile smoke",
33
+ "test:routes": "Tier 2 — route/page render",
34
+ "test:api": "Tier 3 — API/ORM edge cases",
35
+ "test:verify": "Tier 5 — full regression",
36
+ "test:security": "Tier 6 — npm audit + security checks",
37
+ "deploy:uat": "deploy to the User Acceptance environment (build + migrate deploy + idempotent seed)",
38
+ "deploy:prod": "deploy to production (human-gated)",
39
+ "test:data-hygiene": "forward-boundary check — fail when test-data markers exist in uat/prod",
40
+ };
41
+
42
+ const pkgPath = path.join(root, "package.json");
43
+ if (!fs.existsSync(pkgPath)) {
44
+ console.error("FATAL: no package.json in project root");
45
+ process.exit(2);
46
+ }
47
+
48
+ let pkg;
49
+ try {
50
+ pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
51
+ } catch (e) {
52
+ console.error(`FATAL: unparseable package.json: ${e.message}`);
53
+ process.exit(2);
54
+ }
55
+
56
+ const scripts = pkg.scripts || {};
57
+ const missing = [];
58
+ const present = [];
59
+
60
+ console.log("QA script wiring check — DoD-referenced npm scripts");
61
+ for (const [name, desc] of Object.entries(EXPECTED)) {
62
+ if (scripts[name]) {
63
+ present.push(name);
64
+ console.log(` \u2713 ${name} (${desc})`);
65
+ } else {
66
+ missing.push(name);
67
+ console.log(` \u26a0 ${name} MISSING (${desc})`);
68
+ }
69
+ }
70
+
71
+ if (missing.length) {
72
+ const verb = strict ? "FAILURE" : "WARNING";
73
+ console.log(
74
+ `\nRESULT: ${present.length}/${Object.keys(EXPECTED).length} wired. ` +
75
+ `${missing.length} missing: ${missing.join(", ")}.`
76
+ );
77
+ console.log(
78
+ `These are project-provided scripts — add them to package.json or narrow the QA tiers you use. ` +
79
+ `(Run with --strict to treat this as a failure.)`
80
+ );
81
+ process.exit(strict ? 1 : 0);
82
+ }
83
+
84
+ console.log("\nRESULT: all DoD-referenced QA scripts wired.");
85
+ process.exit(0);