qfai 2.2.0 → 2.2.1

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 (117) hide show
  1. package/README.md +46 -6
  2. package/assets/defaults/workflows/bump-dependency.yml +4 -1
  3. package/assets/defaults/workflows/decide-design.yml +5 -1
  4. package/assets/defaults/workflows/rename-concept.yml +30 -0
  5. package/assets/defaults/workflows/resolve-conflicts.yml +14 -0
  6. package/assets/defaults/workflows/retire-feature.yml +26 -0
  7. package/assets/defaults/workflows/run-release.yml +12 -0
  8. package/assets/init/.claude/settings.json +11 -11
  9. package/assets/init/.codex/hooks.json +9 -9
  10. package/assets/init/.qfai/assistant/agent/backend-engineer.md +1 -1
  11. package/assets/init/.qfai/assistant/agent/frontend-engineer.md +1 -1
  12. package/assets/init/.qfai/assistant/agent/implementation-reviewer.md +5 -0
  13. package/assets/init/.qfai/assistant/agent/product-surface-reviewer.md +8 -3
  14. package/assets/init/.qfai/assistant/rule/constitution.md +5 -3
  15. package/assets/init/.qfai/assistant/rule/drift-protocol.md +18 -0
  16. package/assets/init/.qfai/assistant/rule/references/gate-failure-autorepair.md +1 -1
  17. package/assets/init/.qfai/assistant/rule/review-convergence.md +9 -3
  18. package/assets/init/.qfai/assistant/rule/shared-skill-delegation-baseline.md +11 -2
  19. package/assets/init/.qfai/assistant/rule/shared-skill-operating-baseline.md +6 -4
  20. package/assets/init/.qfai/assistant/rule/ui-definition-protocol.md +2 -1
  21. package/assets/init/.qfai/assistant/skill/qfai-discussion/SKILL.md +5 -2
  22. package/assets/init/.qfai/assistant/skill/qfai-discussion/references/discussion-completion-matrix.md +15 -2
  23. package/assets/init/.qfai/assistant/skill/qfai-discussion/references/ui-bearing-playbook.md +17 -0
  24. package/assets/init/.qfai/assistant/skill/qfai-discussion/references/ui_ux/trend_scan_playbook.md +3 -1
  25. package/assets/init/.qfai/assistant/skill/qfai-discussion/templates/01_Context.md +4 -1
  26. package/assets/init/.qfai/assistant/skill/qfai-discussion/templates/04_Sources.md +5 -1
  27. package/assets/init/.qfai/assistant/skill/qfai-discussion/templates/uiux/00_index.md +4 -1
  28. package/assets/init/.qfai/assistant/skill/qfai-implement/SKILL.md +2 -2
  29. package/assets/init/.qfai/assistant/skill/qfai-implement/references/parallelization-policy.md +10 -0
  30. package/assets/init/.qfai/assistant/skill/qfai-implement/references/red-admissibility.md +35 -0
  31. package/assets/init/.qfai/assistant/skill/qfai-implement/references/test-runner-recipes.md +445 -0
  32. package/assets/init/.qfai/assistant/skill/qfai-implement/references/ui-affecting.md +2 -2
  33. package/assets/init/.qfai/assistant/skill/qfai-prototyping/SKILL.md +10 -9
  34. package/assets/init/.qfai/assistant/skill/qfai-prototyping/references/generator-prompt.md +33 -2
  35. package/assets/init/.qfai/assistant/skill/qfai-prototyping/references/handoff.md +77 -2
  36. package/assets/init/.qfai/assistant/skill/qfai-prototyping/references/iteration-loop.md +12 -3
  37. package/assets/init/.qfai/assistant/skill/qfai-prototyping/references/review-payload-schema.md +3 -1
  38. package/assets/init/.qfai/assistant/skill/qfai-prototyping/references/reviewer-prompt.md +31 -5
  39. package/assets/init/.qfai/assistant/skill/qfai-run/SKILL.md +17 -17
  40. package/assets/init/.qfai/assistant/skill/qfai-run/references/extraction.md +194 -129
  41. package/assets/init/.qfai/assistant/skill/qfai-run/references/operator-screens.md +29 -14
  42. package/assets/init/.qfai/assistant/skill/qfai-run/references/plan.md +46 -22
  43. package/assets/init/.qfai/assistant/skill/qfai-run/references/reached-step-observations.md +2 -0
  44. package/assets/init/.qfai/assistant/skill/qfai-run/references/stage-points.md +7 -4
  45. package/assets/init/.qfai/assistant/skill/qfai-sdd/references/concrete-abstract-cycle.md +2 -1
  46. package/assets/init/.qfai/assistant/skill/qfai-sdd/references/contract-artifact-rules.md +1 -1
  47. package/assets/init/.qfai/assistant/skill/qfai-sdd/references/sdd-execution-playbook.md +2 -2
  48. package/assets/init/.qfai/assistant/skill/qfai-sdd/references/sdd-phase-checklists.md +1 -1
  49. package/assets/init/.qfai/assistant/skill/qfai-sdd/references/sdd-pre-draft-grilling.md +1 -0
  50. package/assets/init/.qfai/assistant/skill/qfai-sdd/references/sdd-quality-gate.md +1 -1
  51. package/assets/init/.qfai/assistant/skill/qfai-sdd/references/sdd-triage.md +83 -6
  52. package/assets/init/.qfai/assistant/skill/qfai-sdd/references/spec-traceability-rules.md +1 -1
  53. package/assets/init/.qfai/assistant/skill/qfai-sdd/references/ui-contract-guide.md +23 -5
  54. package/assets/init/.qfai/assistant/skill/qfai-sdd/templates/change-request.md +1 -1
  55. package/assets/init/.qfai/assistant/skill/qfai-sdd/templates/spec/decisions/page-NNNN.md +6 -0
  56. package/assets/init/.qfai/assistant/skill/qfai-sdd/templates/spec/decisions.md +9 -0
  57. package/assets/init/.qfai/assistant/skill/qfai-sdd/templates/spec/open-questions.md +13 -0
  58. package/assets/init/.qfai/assistant/skill/qfai-verify/references/verify-output-contract.md +15 -9
  59. package/assets/init/.qfai/assistant/skill/web-research/SKILL.md +1 -1
  60. package/assets/init/.qfai/assistant/step/common-gate-run/STEP.md +11 -8
  61. package/assets/init/.qfai/assistant/step/common-grilling-record/STEP.md +15 -2
  62. package/assets/init/.qfai/assistant/step/common-review-cycle/STEP.md +48 -11
  63. package/assets/init/.qfai/assistant/step/discussion-interview/STEP.md +11 -3
  64. package/assets/init/.qfai/assistant/step/discussion-oq/STEP.md +12 -0
  65. package/assets/init/.qfai/assistant/step/discussion-pack/STEP.md +18 -2
  66. package/assets/init/.qfai/assistant/step/discussion-uiux/STEP.md +4 -0
  67. package/assets/init/.qfai/assistant/step/implement-acceptance/STEP.md +3 -0
  68. package/assets/init/.qfai/assistant/step/implement-credentials/STEP.md +4 -0
  69. package/assets/init/.qfai/assistant/step/implement-dep-bump/STEP.md +31 -7
  70. package/assets/init/.qfai/assistant/step/implement-diagnose/STEP.md +12 -3
  71. package/assets/init/.qfai/assistant/step/implement-procedure/STEP.md +35 -6
  72. package/assets/init/.qfai/assistant/step/implement-refactor/STEP.md +25 -5
  73. package/assets/init/.qfai/assistant/step/implement-retire/STEP.md +26 -0
  74. package/assets/init/.qfai/assistant/step/implement-scaffold/STEP.md +28 -5
  75. package/assets/init/.qfai/assistant/step/implement-tdd/STEP.md +20 -5
  76. package/assets/init/.qfai/assistant/step/maintain-edit/STEP.md +70 -6
  77. package/assets/init/.qfai/assistant/step/prototyping-grill/STEP.md +39 -6
  78. package/assets/init/.qfai/assistant/step/prototyping-handoff/STEP.md +12 -3
  79. package/assets/init/.qfai/assistant/step/prototyping-loop/STEP.md +56 -6
  80. package/assets/init/.qfai/assistant/step/prototyping-preflight/STEP.md +5 -0
  81. package/assets/init/.qfai/assistant/step/sdd-contract/STEP.md +8 -0
  82. package/assets/init/.qfai/assistant/step/sdd-cycle/STEP.md +9 -4
  83. package/assets/init/.qfai/assistant/step/sdd-story/STEP.md +22 -1
  84. package/assets/init/.qfai/assistant/step/sdd-triage/STEP.md +48 -12
  85. package/assets/init/.qfai/assistant/step/triage-close/STEP.md +7 -2
  86. package/assets/init/.qfai/assistant/step/triage-handoff/STEP.md +6 -0
  87. package/assets/init/.qfai/assistant/step/triage-operate/STEP.md +76 -3
  88. package/assets/init/.qfai/assistant/step/verify-commit/STEP.md +35 -10
  89. package/assets/init/.qfai/assistant/step/verify-repo-gate/STEP.md +65 -7
  90. package/assets/init/root/.agents/rules/api-budget.md +8 -3
  91. package/assets/init/root/.agents/rules/graph-exploration.md +18 -4
  92. package/assets/init/root/.agents/rules/reminders.json +20 -28
  93. package/assets/init/root/.agents/rules/user-questions.md +21 -11
  94. package/assets/init/root/.gitattributes +2 -0
  95. package/assets/init/root/AGENTS.md +1 -1
  96. package/assets/mdschema/manifest.yml +3 -0
  97. package/assets/mdschema/story/03_contract/tech.mdschema.yml +1 -1
  98. package/assets/mdschema/story/decisions/page-NNNN.mdschema.yml +32 -0
  99. package/assets/mdschema/story/decisions.mdschema.yml +12 -0
  100. package/assets/schemas/workflow/extraction.schema.json +94 -2
  101. package/assets/schemas/workflow/plan.schema.json +34 -1
  102. package/assets/scripts/check-mdschema.mjs +434 -45
  103. package/dist/cli/index.cjs +4930 -2264
  104. package/dist/cli/index.cjs.map +1 -1
  105. package/dist/cli/index.mjs +4690 -2016
  106. package/dist/cli/index.mjs.map +1 -1
  107. package/dist/graph/cli.cjs.map +1 -1
  108. package/dist/graph/cli.mjs.map +1 -1
  109. package/dist/graph/hook.cjs.map +1 -1
  110. package/dist/graph/hook.mjs.map +1 -1
  111. package/dist/index.cjs +3338 -1830
  112. package/dist/index.cjs.map +1 -1
  113. package/dist/index.d.cts +59 -3
  114. package/dist/index.d.ts +59 -3
  115. package/dist/index.mjs +3154 -1649
  116. package/dist/index.mjs.map +1 -1
  117. package/package.json +1 -1
@@ -0,0 +1,445 @@
1
+ # Test runner recipes: session reuse, shared state, business time and CI
2
+
3
+ Optional recipes for Playwright and Vitest that put the worker session-reuse rules of
4
+ `implement-credentials` into runnable form, together with the shared-state, business-time and CI
5
+ patterns that make a parallel acceptance suite trustworthy. Copy what fits and adapt it. The rules
6
+ stay the obligation; a recipe is one way to meet them.
7
+
8
+ ## Contents
9
+
10
+ - Status and what the adopter supplies
11
+ - The run-owned session directory
12
+ - Vitest: one session per pool slot and actor
13
+ - Playwright: one account and storage state per worker
14
+ - Business data each file owns
15
+ - Database hooks only where a group needs them
16
+ - Shared and exclusive access to a common database or server
17
+ - Deterministic business time
18
+ - Credential directory hygiene
19
+ - CI: auxiliary jobs inside the protected result
20
+ - Adoption checklist
21
+
22
+ ## Status and what the adopter supplies
23
+
24
+ The Vitest session cache and the CI aggregate job come from one adopter's working implementation,
25
+ reduced to the parts that do not depend on the application. The Playwright recipe and the other
26
+ sections were written from that adopter's description of its suite. QFAI's own suite signs
27
+ nothing in and runs no browser, so nothing here is executed in this repository: read each recipe as a
28
+ pattern to adopt, then prove it in your own suite with the adoption checklist at the end.
29
+
30
+ The application supplies five adapters. QFAI ships none of them, and no recipe below assumes how
31
+ they work inside:
32
+
33
+ | Adapter | What it does |
34
+ | ---------------- | ------------------------------------------------------------------------------------- |
35
+ | `createAccount` | `createAccount(actor, slot)` creates a private account for this run, returning its ID |
36
+ | `issueSession` | Signs that account in and returns the session the product accepts |
37
+ | `signIn` | Completes the same sign-in on a browser page, for Playwright |
38
+ | `acceptsSession` | Asks the product whether a restored session is still valid |
39
+ | `deleteAccount` | Removes an account this run created, and nothing else |
40
+
41
+ When a test needs a controlled business time, the application also supplies a clock adapter, as
42
+ the business time section describes.
43
+
44
+ ## The run-owned session directory
45
+
46
+ Both runners share these helpers. The run's global setup creates one private directory and exports
47
+ it as `TEST_SESSION_CACHE_DIR`; every worker reads that same directory. Each account the run
48
+ creates is recorded by its ID in `created.jsonl`, which holds no secret, and the teardown deletes
49
+ every recorded account, so an account made by a refresh is removed too.
50
+
51
+ ```ts
52
+ // session-directory.ts
53
+ import { statSync } from "node:fs";
54
+ import fs from "node:fs/promises";
55
+ import os from "node:os";
56
+ import path from "node:path";
57
+
58
+ export async function createSessionDirectory(): Promise<string> {
59
+ const directory = await fs.mkdtemp(path.join(os.tmpdir(), "session-cache-"));
60
+ await fs.chmod(directory, 0o700);
61
+ process.env.TEST_SESSION_CACHE_DIR = directory;
62
+ return directory;
63
+ }
64
+
65
+ /** Every worker calls this; a missing or shared directory stops the run. */
66
+ export function ownedSessionDirectory(): string {
67
+ const directory = process.env.TEST_SESSION_CACHE_DIR;
68
+ if (!directory) throw new Error("TEST_SESSION_CACHE_DIR is not set: global setup creates it");
69
+ const stat = statSync(directory);
70
+ if (!stat.isDirectory()) throw new Error(`${directory} is not a directory`);
71
+ if (process.platform !== "win32" && (stat.mode & 0o077) !== 0)
72
+ throw new Error(`${directory} is readable by other users`);
73
+ return directory;
74
+ }
75
+
76
+ export async function recordCreated(directory: string, id: string): Promise<void> {
77
+ await fs.appendFile(path.join(directory, "created.jsonl"), `${JSON.stringify({ id })}\n`, {
78
+ mode: 0o600,
79
+ });
80
+ }
81
+
82
+ export async function deleteCreatedAccounts(directory: string): Promise<void> {
83
+ let lines: string[] = [];
84
+ try {
85
+ lines = (await fs.readFile(path.join(directory, "created.jsonl"), "utf8")).split("\n");
86
+ } catch (error) {
87
+ if (!(error instanceof Error && "code" in error && error.code === "ENOENT")) throw error;
88
+ }
89
+ for (const line of lines.filter((entry) => entry.trim() !== "")) {
90
+ const { id }: { id: string } = JSON.parse(line);
91
+ await deleteAccount(id);
92
+ }
93
+ }
94
+ ```
95
+
96
+ The directory is how both recipes meet the rule that binds the cache's lifetime to the worker's:
97
+ here a worker is a pool slot or a parallel index, which lasts the whole run, and the run's teardown
98
+ removes the directory with every cached session in it.
99
+
100
+ ## Vitest: one session per pool slot and actor
101
+
102
+ Vitest isolates each test file in its own module registry, so a module-level cache does not outlive
103
+ one file. A process ID or a per-file counter does not give a worker lifetime either. What survives
104
+ is the pool slot, `VITEST_POOL_ID`, a stable number per worker slot. Key the cache by the private
105
+ directory the run owns, the slot and the actor. In this recipe a worker is that pool slot, and the
106
+ cache lives as long as the slot does: until the run's teardown removes the directory.
107
+
108
+ ```ts
109
+ import { createHash } from "node:crypto";
110
+ import fs from "node:fs/promises";
111
+ import path from "node:path";
112
+
113
+ type SessionOptions = {
114
+ actor: string;
115
+ create: (slot: string) => Promise<string>;
116
+ accepted: (session: string) => Promise<boolean>;
117
+ };
118
+
119
+ /** The run owns the directory; the pool slot survives isolated file registries. */
120
+ export async function workerSession({ actor, create, accepted }: SessionOptions): Promise<string> {
121
+ const directory = ownedSessionDirectory();
122
+ const worker = process.env.VITEST_POOL_ID;
123
+ if (!worker || !/^\d+$/.test(worker)) throw new Error("A worker session requires VITEST_POOL_ID");
124
+ const key = createHash("sha256").update(actor).digest("hex").slice(0, 20);
125
+ const file = path.join(directory, `${worker}-${key}.json`);
126
+ const record = (event: "issued" | "reused" | "refreshed") =>
127
+ fs.appendFile(
128
+ path.join(directory, `${worker}.events.jsonl`),
129
+ `${JSON.stringify({ worker, actor: key, event })}\n`,
130
+ );
131
+ let session: string | undefined;
132
+ try {
133
+ const restored: unknown = JSON.parse(await fs.readFile(file, "utf8"));
134
+ if (typeof restored === "string") session = restored;
135
+ } catch (error) {
136
+ const missing = error instanceof Error && "code" in error && error.code === "ENOENT";
137
+ if (!(error instanceof SyntaxError) && !missing) throw error;
138
+ }
139
+ if (session !== undefined && (await accepted(session))) {
140
+ await record("reused");
141
+ return session;
142
+ }
143
+ const event = session === undefined ? "issued" : "refreshed";
144
+ session = await create(worker);
145
+ await fs.writeFile(file, JSON.stringify(session), { mode: 0o600 });
146
+ await record(event);
147
+ return session;
148
+ }
149
+ ```
150
+
151
+ A file-local map validates each actor once per file registry, so a file does not ask the product
152
+ about the same session for every test:
153
+
154
+ ```ts
155
+ const sessions = new Map<string, Promise<string>>();
156
+
157
+ export function sessionFor(actor: string): Promise<string> {
158
+ let pending = sessions.get(actor);
159
+ if (pending === undefined) {
160
+ pending = workerSession({
161
+ actor,
162
+ create: async (slot) => {
163
+ const account = await createAccount(actor, slot);
164
+ await recordCreated(ownedSessionDirectory(), account.id);
165
+ return issueSession(account);
166
+ },
167
+ accepted: acceptsSession,
168
+ });
169
+ sessions.set(actor, pending);
170
+ }
171
+ return pending;
172
+ }
173
+ ```
174
+
175
+ Global setup creates the directory before the workers start, and the teardown it returns, which
176
+ runs after a failed run too, deletes the recorded accounts and removes the directory:
177
+
178
+ ```ts
179
+ // vitest.global-setup.ts
180
+ import fs from "node:fs/promises";
181
+
182
+ export default async function setup() {
183
+ const directory = await createSessionDirectory();
184
+ return async () => {
185
+ await deleteCreatedAccounts(directory);
186
+ await fs.rm(directory, { recursive: true, force: true });
187
+ };
188
+ }
189
+ ```
190
+
191
+ The workers see `TEST_SESSION_CACHE_DIR` because Vitest starts them after global setup and they
192
+ inherit its environment; the recipe relies on that start-up order. Vitest's documented channel from
193
+ global setup to tests is `provide` and `inject`: where your version offers it, pass the directory
194
+ that way and have `ownedSessionDirectory()` read it from `inject`.
195
+
196
+ Keep these behaviours when you adapt it:
197
+
198
+ - An explicit session, a bearer credential or an intentionally anonymous request bypasses the
199
+ default fixture.
200
+ - A rejected cache is refreshed while the fixture is prepared. A product request that returns 401
201
+ is never repeated automatically: that 401 is the result under test.
202
+ - A store error propagates. Only a missing file or an unreadable record means "no session"; an
203
+ error reading the directory is not an invalid credential.
204
+ - Login, logout, expiry and password-change tests use their own subjects, never a pooled actor.
205
+
206
+ ## Playwright: one account and storage state per worker
207
+
208
+ A global setup creates the run's private directory; a setup project signs one account in per
209
+ worker and saves its storage state there; the test project picks the state by the worker's parallel
210
+ index; a teardown project deletes the recorded accounts and their states. The worker count is fixed
211
+ in the configuration, so the setup and the run agree on it. In this recipe a worker is a parallel
212
+ index, and its storage state lives until the run's teardown removes the directory.
213
+
214
+ ```ts
215
+ // playwright.config.ts
216
+ import { defineConfig } from "@playwright/test";
217
+
218
+ export default defineConfig({
219
+ globalSetup: "./global-setup.ts",
220
+ workers: 4,
221
+ projects: [
222
+ { name: "setup", testMatch: /auth\.setup\.ts/, teardown: "teardown" },
223
+ { name: "teardown", testMatch: /auth\.teardown\.ts/ },
224
+ {
225
+ name: "e2e",
226
+ dependencies: ["setup"],
227
+ testIgnore: [/auth\.(setup|teardown)\.ts/, /\.exclusive\.spec\.ts/],
228
+ },
229
+ { name: "exclusive", dependencies: ["setup"], testMatch: /\.exclusive\.spec\.ts/ },
230
+ ],
231
+ });
232
+ ```
233
+
234
+ ```ts
235
+ // global-setup.ts: the environment it sets reaches every worker
236
+ import fs from "node:fs/promises";
237
+
238
+ export default async function globalSetup() {
239
+ const directory = await createSessionDirectory();
240
+ return async () => {
241
+ await fs.rm(directory, { recursive: true, force: true });
242
+ };
243
+ }
244
+ ```
245
+
246
+ ```ts
247
+ // auth.setup.ts
248
+ import { chmod } from "node:fs/promises";
249
+ import { test as setup } from "@playwright/test";
250
+
251
+ setup("sign in one account per worker", async ({ browser }) => {
252
+ const directory = ownedSessionDirectory();
253
+ for (let slot = 0; slot < setup.info().config.workers; slot++) {
254
+ const account = await createAccount("member", String(slot));
255
+ await recordCreated(directory, account.id);
256
+ const context = await browser.newContext();
257
+ await signIn(await context.newPage(), account);
258
+ await context.storageState({ path: statePath(directory, slot) });
259
+ await chmod(statePath(directory, slot), 0o600);
260
+ await context.close();
261
+ }
262
+ });
263
+ ```
264
+
265
+ ```ts
266
+ // fixtures.ts
267
+ import { test as base } from "@playwright/test";
268
+
269
+ export const test = base.extend({
270
+ storageState: async ({}, use, testInfo) => {
271
+ await use(statePath(ownedSessionDirectory(), testInfo.parallelIndex));
272
+ },
273
+ });
274
+ ```
275
+
276
+ ```ts
277
+ // auth.teardown.ts
278
+ import { rm } from "node:fs/promises";
279
+ import { test as teardown } from "@playwright/test";
280
+
281
+ teardown("delete the run's accounts and storage states", async () => {
282
+ const directory = ownedSessionDirectory();
283
+ await deleteCreatedAccounts(directory);
284
+ for (let slot = 0; slot < teardown.info().config.workers; slot++) {
285
+ await rm(statePath(directory, slot), { force: true });
286
+ }
287
+ });
288
+ ```
289
+
290
+ A test whose subject is the session itself (login, logout, expiry, password change) starts from an
291
+ empty storage state with `test.use({ storageState: { cookies: [], origins: [] } })` and creates its own
292
+ subject. When the suite runs once per clock profile, each profile runs its own setup and teardown.
293
+
294
+ ## Business data each file owns
295
+
296
+ Reusing an authenticated actor must not make one file depend on another file's business data.
297
+
298
+ - Each file prepares the minimum business data its tests read, in its own hooks.
299
+ - Identities are unique per creation: a real-millisecond timestamp plus a random suffix, such as
300
+ `` `order-${Date.now()}-${randomUUID().slice(0, 8)}` ``. A fixed name collides across workers.
301
+ - Cleanup removes what the file created, and only that, including after a failed test.
302
+ - No file resets a mutable business seed. A reset in one worker deletes data another worker is
303
+ asserting on.
304
+
305
+ ## Database hooks only where a group needs them
306
+
307
+ When one file holds source-only cases and live cases, register the database preparation inside
308
+ the group that needs it, not at the top of the file:
309
+
310
+ ```ts
311
+ describe("source contract", () => {
312
+ it("parses the export format", () => {
313
+ /* no database */
314
+ });
315
+ });
316
+
317
+ describe("live store", () => {
318
+ let owned: OwnedRows | undefined;
319
+ beforeAll(async () => {
320
+ owned = await createMinimumRows(requireDatabase());
321
+ });
322
+ afterAll(async () => {
323
+ await owned?.remove();
324
+ });
325
+ it("persists an order", async () => {
326
+ /* uses owned */
327
+ });
328
+ });
329
+ ```
330
+
331
+ A source-only CI selector then creates no business rows. `requireDatabase()` throws when the
332
+ database is not configured, so a selected live case fails without it rather than skipping.
333
+
334
+ ## Shared and exclusive access to a common database or server
335
+
336
+ Four workers do not by themselves make concurrency safe. Admit files to a shared database or server
337
+ by declared access:
338
+
339
+ - **Shared**: the file reads and writes only data it owns. Shared files run in parallel, bounded by
340
+ what the database and server can serve, measured, not by the CPU count.
341
+ - **Exclusive**: the file changes something global: a setting, a schema, a clock, a feature flag, a
342
+ queue drained by everyone. An exclusive file runs alone.
343
+ - **Unknown**: a file that imports a helper whose effects you have not classified, or that mutates
344
+ global state, is exclusive until shown otherwise.
345
+
346
+ The simplest bounded admission is two passes: the shared files with the measured worker count,
347
+ then the exclusive files with one worker, for example a Vitest project with
348
+ `fileParallelism: false`, or `npx --no-install playwright test --project=exclusive --workers=1` after a run of the `e2e`
349
+ project.
350
+
351
+ ## Deterministic business time
352
+
353
+ A test that depends on the wall clock waits for a time of day or skips outside it. Control
354
+ business time instead:
355
+
356
+ - **Clock adapter.** The application reads business time through an adapter it supplies, with an
357
+ explicit time zone and a fixed date and time per profile. Server-side decisions read the same
358
+ adapter as the browser display; fixing only the browser leaves the server deciding on real time.
359
+ - **Production-safe boundary.** Test clock control is enabled only by start-up configuration of a
360
+ non-production build or environment. No ordinary production request can enable it or set it,
361
+ and a test proves that a production configuration ignores the control.
362
+ - **Independent cases per profile.** Each profile, such as inside and outside a business window,
363
+ runs its own cases: before, inside and after the window, and holiday and boundary instants where
364
+ the business has them. No case waits for real time and none skips on the time of day.
365
+ - **Workers.** A profile's clock is immutable while that profile is active. Workers sharing one
366
+ server and database share its clock, so two profiles never run against one mutable clock at once:
367
+ give each concurrently active profile its own server, or run the profiles one after another.
368
+ Data stays owned per file, as above.
369
+ - **Reports.** CI shows that every profile ran: one report per profile, each with the actual worker
370
+ count, the cases run, the skips and the flaky results.
371
+
372
+ ```ts
373
+ // One definition read by the server start-up and by the browser context of each profile.
374
+ export const clockProfiles = {
375
+ "in-window": { timeZone: "Asia/Tokyo", instant: "2030-01-15T10:30:00+09:00" },
376
+ "out-of-window": { timeZone: "Asia/Tokyo", instant: "2030-01-15T22:30:00+09:00" },
377
+ } as const;
378
+ ```
379
+
380
+ ## Credential directory hygiene
381
+
382
+ - The run owns its session directory: it creates it fresh, outside the checked-out tree, and
383
+ refuses a directory that already holds files it did not write.
384
+ - The directory is private (mode 700, files 600) and is removed by the teardown, which also runs
385
+ after a failure.
386
+ - Playwright traces, HAR files and HTML reports from an authenticated project carry cookies and
387
+ tokens. Do not upload them, or upload them only to a restricted location with a short retention,
388
+ and never from a public run.
389
+ - Artifact uploads exclude the directory. Keep only noncredential reuse metrics, such as the counts
390
+ of issued, reused and refreshed sessions per slot, copied out before the teardown removes it.
391
+
392
+ ## CI: auxiliary jobs inside the protected result
393
+
394
+ Independent auxiliary jobs, such as tooling checks or extra mutation probes, belong in the result
395
+ the branch protection requires. An aggregate job keeps the protected check name stable and fails
396
+ when any required job fails, is cancelled or is skipped when it should have run:
397
+
398
+ ```yaml
399
+ tests-required:
400
+ name: tests (required)
401
+ needs: [changes, unit, tooling, behavioral-proofs]
402
+ if: ${{ always() }}
403
+ runs-on: ubuntu-latest
404
+ timeout-minutes: 2
405
+ permissions:
406
+ contents: read
407
+ steps:
408
+ - name: required test verdict
409
+ env:
410
+ CHANGE_RESULT: ${{ needs.changes.result }}
411
+ CODE_CHANGED: ${{ needs.changes.outputs.code }}
412
+ UNIT_RESULT: ${{ needs.unit.result }}
413
+ TOOLING_RESULT: ${{ needs.tooling.result }}
414
+ PROOF_RESULT: ${{ needs.behavioral-proofs.result }}
415
+ run: |
416
+ set -euo pipefail
417
+ [ "$CHANGE_RESULT" = success ] || { echo "Change detection: $CHANGE_RESULT"; exit 1; }
418
+ expected=success
419
+ if [ "$CODE_CHANGED" = false ]; then expected=skipped; fi
420
+ for result in "$UNIT_RESULT" "$TOOLING_RESULT" "$PROOF_RESULT"; do
421
+ [ "$result" = "$expected" ] || { echo "Lane returned $result, expected $expected"; exit 1; }
422
+ done
423
+ ```
424
+
425
+ The change-detection job and the lanes are the application's. Report ordinary test counts, extra
426
+ source-mutation probes and their counts separately; a probe count is not a test count.
427
+
428
+ ## Adoption checklist
429
+
430
+ - Sign-ins per run equal workers times actors, plus the dedicated subjects, plus refreshes; the
431
+ reuse metrics show it.
432
+ - A second file on the same slot and actor reuses the session; two slots or two actors never share
433
+ one.
434
+ - A rejected session is refreshed once and rewritten; a store error fails the run.
435
+ - The source-only selector passes with no database configured and creates no rows; a live case
436
+ fails without its database.
437
+ - Every file passes alone and in any order, with no seed reset.
438
+ - Exclusive files never overlap another file on the same database or server.
439
+ - Each clock profile's report shows its cases ran with zero skips; a production configuration
440
+ ignores the test clock.
441
+ - The aggregate check fails when any required lane fails, is cancelled or is skipped unexpectedly.
442
+ - No artifact holds a session, a storage state or an account secret, and no trace, HAR file or
443
+ HTML report from an authenticated project is uploaded where it is public or kept long.
444
+ - The teardown deletes every account recorded in `created.jsonl`, after a failed run too.
445
+ - Parallel workers are bounded by shared-state exclusion; measure before claiming a speedup.
@@ -3,7 +3,7 @@
3
3
  ## Inputs
4
4
 
5
5
  Read the UI surface paths `uiux.surfacePaths` declares in qfai.config.yaml, and resolve paths.contractsDir from the same file. Read every UI contract under its ui/ directory, and the root DESIGN.md if present for the brand tokens.
6
- When a prototyping loop ran in this checkout, read its handoff at .qfai/prototype/final/handoff.json: the final prototype, its procurement and the implementation notes.
6
+ When a prototyping loop ran in this checkout, read its handoff at .qfai/prototype/final/handoff.json: the final prototype, its procurement and the implementation notes, or, for a restyle, its live routes, its stylesheet and motion entry points and the implementation notes.
7
7
  Read the flow, story, acceptance criterion, and example that the implementation changes.
8
8
  For each screen the change renders, read its `supplements` and `structure` in the UI contract before adding text: the screen shows its title, group headings, labels and declared supplements, and no other text.
9
9
 
@@ -22,6 +22,6 @@ product-surface-reviewer. Do not infer that a change has no UI effect from its d
22
22
 
23
23
  For a UI affecting example, report the screen state, action, expected and observed result, and a capture or rendered artifact. The artifact must identify the source revision. In the review that reads the change, product-surface-reviewer judges each UI affecting example, its UI contracts, and its captured state. The review verdict refers to that revision.
24
24
 
25
- A fix made for a finding of that review refreshes the capture it changes and is not reviewed again (`.qfai/assistant/rule/review-convergence.md#one-review`). A passing code test cannot substitute for the visual and interaction evidence that the acceptance criterion requires.
25
+ A fix made for a finding of that review refreshes the capture it changes, and a fix that changes behaviour gets its one focused re-review (`.qfai/assistant/rule/review-convergence.md#one-review`). A passing code test cannot substitute for the visual and interaction evidence that the acceptance criterion requires.
26
26
 
27
27
  Capture each declared task at a desktop width and a narrow width, in the normal state and in every declared empty, error, loading and success state the screen has. A text the contract declares that the capture lacks, or a text the capture shows that the contract does not declare, is a finding.
@@ -42,8 +42,9 @@ no `prototyping` command group, and no command or check certifies the result:
42
42
  prototyping completes when the user confirms the prototype.
43
43
 
44
44
  Every file the loop writes stays under `.qfai/prototype/`: the session record,
45
- each iteration and its reviews, and the handoff. No `qfai` command writes
46
- there. The one file a command reads is the handoff record
45
+ each iteration and its reviews, and the handoff. A `restyle` loop also edits
46
+ the project's stylesheet and motion entry points its handoff names. No `qfai`
47
+ command writes any of these files. The one file a command reads is the handoff record
47
48
  `.qfai/prototype/final/handoff.json`, which
48
49
  `npx qfai validate --profile saas-package` checks against the CLI-HANDOFF schema.
49
50
 
@@ -59,12 +60,12 @@ When unsure, read inputs in this order:
59
60
 
60
61
  ## Steps
61
62
 
62
- | Step | Runs |
63
- | ----------------------- | ------------------------------------------------------------------------------------ |
64
- | `prototyping-grill` | Always, first: fixes the scope and settles by talking what the prototype is for |
65
- | `prototyping-preflight` | Always: checks the UI contracts, root `DESIGN.md` and the Playwright environment |
66
- | `prototyping-loop` | Always: build, review, and put each reviewed prototype to the user until they accept |
67
- | `prototyping-handoff` | Only after the user confirmed the prototype: copy it and write the handoff |
63
+ | Step | Runs |
64
+ | ----------------------- | --------------------------------------------------------------------------------------------------------- |
65
+ | `prototyping-grill` | Always, first: fixes the scope and settles by talking what the prototype is for |
66
+ | `prototyping-preflight` | Always: checks the UI contracts, root `DESIGN.md` and the Playwright environment |
67
+ | `prototyping-loop` | Always: build, review, and put each reviewed prototype to the user until they accept |
68
+ | `prototyping-handoff` | Only after the user confirmed the prototype: copy it and write the handoff (restyle: `handoff.json` only) |
68
69
 
69
70
  A step's gate that ends the run ends the invocation: zero UI-bearing contracts
70
71
  at preflight, an escalated decision before the first iteration, or a stop or a
@@ -113,4 +114,4 @@ no question. Under a no-question mode, list any remaining actions instead.
113
114
  project_memory:
114
115
 
115
116
  - Prototyping completes on the user's confirmation; no command certifies it.
116
- - Every file the loop writes is under `.qfai/prototype/`; a `qfai` command reads only `final/handoff.json`.
117
+ - Every file the loop writes is under `.qfai/prototype/`, except the stylesheet and motion entry points a `restyle` loop edits; a `qfai` command reads only `final/handoff.json`.
@@ -33,11 +33,15 @@ identity.
33
33
  makes it answerable and leave it open — treating it as a settled constraint
34
34
  decides on the user's behalf the one kind of question this loop exists to
35
35
  return to them.
36
- 5. From the second iteration on: the user's last answer,
36
+ 5. From the run's second iteration on: the user's last answer in this run,
37
37
  `iter-(NN-1)/review.json` (critique, scores,
38
38
  `layoutAntiPatternsDetected`, `designMdViolations`,
39
39
  `pivotDirective`), `iter-(NN-2)/review.json` when present, and
40
- `progress.md`.
40
+ `progress.md`. A review or confirmation from an earlier run is not one of
41
+ them: the run's first iteration is the first after `progress.md` records
42
+ its `runScope`, present or absent.
43
+ 6. In a scoped run, every iteration: `runScope` in `progress.md` and
44
+ `.qfai/prototype/final/index.html`.
41
45
 
42
46
  ## HTML envelope (mandatory on every iter)
43
47
 
@@ -271,6 +275,33 @@ match the routing shape to what the server in use does with an unknown
271
275
  path: a path route needs a server that falls back to `index.html`, and a
272
276
  hash route (`/#/settings`) works on any static server.
273
277
 
278
+ ### Restyle iterations
279
+
280
+ In a `restyle` iteration the project's app is the prototype. The HTML
281
+ envelope, the one self-contained file, the `<link rel="stylesheet">` ban and
282
+ "nothing else" above do not apply:
283
+
284
+ - Edit only the project's stylesheet and motion entry points, and record each
285
+ file edited for the handoff. Values that root `DESIGN.md` does not declare
286
+ are still findings.
287
+ - Write `iter-NN/index.html` as the list of live routes in scope: one link
288
+ per declared screen, each with its absolute URL and the setup it needs, such
289
+ as a login or seed data.
290
+ - The seed and pivot rules below do not apply as written. The first restyle
291
+ iteration restyles the screens as they are, and a restyle `pivot` rethinks
292
+ only the visual treatment: screens, fields and behaviour stay.
293
+
294
+ ### Scoped runs
295
+
296
+ When `progress.md` records a `runScope`, the run's first iteration starts from
297
+ a copy of `.qfai/prototype/final/index.html`, not from a seed, and each later
298
+ iteration builds on the previous one, whose out-of-scope parts are still
299
+ `final/`'s. Change only the in-scope screen routes and each in-scope shared
300
+ component wherever a screen route renders it, with the style only they use.
301
+ Leave everything else as `final/` has it, so the handoff can merge the
302
+ in-scope parts back. A `pivot` rethinks only what is inside the scope. A
303
+ change the scope needs outside those parts is reported, not made.
304
+
274
305
  ## The first iteration (seed)
275
306
 
276
307
  Produce one self-contained `iter-00/index.html` that satisfies the spec
@@ -1,10 +1,23 @@
1
1
  # Handoff (post-loop)
2
2
 
3
+ ## Contents
4
+
5
+ - Inputs
6
+ - Outputs
7
+ - Scoped handoff
8
+ - Restyle handoff
9
+ - Checking an implementation's tokens
10
+
3
11
  ## Inputs
4
12
 
5
13
  `.qfai/prototype/iter-<final>/index.html` — the iteration the user
6
14
  confirmed. It is one self-contained file with one client-side route per
7
15
  declared screen, written by the generator.
16
+ A `restyle` loop has no such file: its iterations restyled the live app
17
+ in place, and its handoff is the short form under Restyle handoff below.
18
+ A scoped run also reads the `final/index.html` and `final/handoff.json` an
19
+ earlier run confirmed, which the merge under Scoped handoff below keeps
20
+ outside the scope.
8
21
 
9
22
  Root `DESIGN.md` remains the brand SSOT through handoff.
10
23
 
@@ -12,8 +25,9 @@ Root `DESIGN.md` remains the brand SSOT through handoff.
12
25
 
13
26
  ### `.qfai/prototype/final/index.html`
14
27
 
15
- A copy (not a symlink) of the confirmed iteration. `/qfai-implement`
16
- reads this as a read-only artifact.
28
+ A copy (not a symlink) of the confirmed iteration, or in a scoped run the
29
+ merge under Scoped handoff below. `/qfai-implement` reads this as a
30
+ read-only artifact.
17
31
 
18
32
  ### `.qfai/prototype/final/handoff.json`
19
33
 
@@ -75,6 +89,67 @@ same checkout. `npx qfai validate --profile saas-package` requires it to be pres
75
89
  and to conform, and reports `QFAI-SAAS-002` naming the file
76
90
  otherwise; no other command reads it.
77
91
 
92
+ ## Scoped handoff
93
+
94
+ When `progress.md` records a `runScope`, the confirmed iteration changed
95
+ only the in-scope parts of a `final/index.html` an earlier run confirmed.
96
+ The unit of the merge is the screen route, one per declared screen, and each
97
+ place a route renders an in-scope shared component.
98
+
99
+ - In `final/index.html`, replace each in-scope screen's route, and each
100
+ in-scope component wherever a route renders it, together with the style
101
+ only they use, with the confirmed iteration's version. Keep every other
102
+ part as it was.
103
+ - A difference between the confirmed iteration and `final/` outside those
104
+ parts is a change the scope left out: keep `final/`'s version and name the
105
+ difference in the completion report.
106
+ - In `final/handoff.json`, replace the `procurement` rows of the in-scope
107
+ screens and components, keep every other row, so every declared screen
108
+ still appears, and record the scope the user confirmed as `runScope`.
109
+ Keep `finalArtifact`, `implementationNotes` and every other existing key,
110
+ extending `implementationNotes` with what this run decided rather than
111
+ rewriting it:
112
+
113
+ ```json
114
+ {
115
+ "runScope": {
116
+ "screens": ["<ui-contract-id>/<screen>"],
117
+ "components": ["<repository path or procurement item>"]
118
+ }
119
+ }
120
+ ```
121
+
122
+ The confirmed prototype is then the whole of `final/`: the in-scope parts
123
+ this run confirmed, and every other part as an earlier run confirmed it. A
124
+ run with no scope copies the whole iteration and writes no `runScope`.
125
+
126
+ ## Restyle handoff
127
+
128
+ When `.qfai/prototype/progress.md` records `iterationKind` `restyle`, every
129
+ screen is one the project already runs, so there is no prototype to copy and no region to
130
+ procure. No `final/index.html` is written, and
131
+ `final/handoff.json` takes this short form in place of `finalArtifact` and `procurement`:
132
+
133
+ ```json
134
+ {
135
+ "iterationKind": "restyle",
136
+ "liveRoutes": ["<route the confirmed iteration listed>"],
137
+ "entryPoints": {
138
+ "stylesheet": ["<repository-relative path>"],
139
+ "motion": ["<repository-relative path>"]
140
+ },
141
+ "implementationNotes": "Plain prose ..."
142
+ }
143
+ ```
144
+
145
+ - `liveRoutes` names every live route the confirmed iteration listed.
146
+ - `entryPoints` names the files the restyle changed: the stylesheet entry
147
+ points and the motion entry points, each list empty when the restyle
148
+ changed none.
149
+ - `implementationNotes` is as above.
150
+ - `npx qfai validate --profile saas-package` reports a `restyle` record
151
+ without a non-empty `liveRoutes` or without both `entryPoints` lists.
152
+
78
153
  ## Checking an implementation's tokens
79
154
 
80
155
  QFAI checks the prototype against the tokens in root `DESIGN.md`. It does