qfai 2.3.0 → 2.4.0

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 (128) hide show
  1. package/README.md +23 -3
  2. package/assets/init/.claude/settings.json +35 -1
  3. package/assets/init/.codex/hooks.json +24 -0
  4. package/assets/init/.github/instructions/code-review.instructions.md +1 -1
  5. package/assets/init/.qfai/assistant/agent/architecture-reviewer.md +2 -2
  6. package/assets/init/.qfai/assistant/agent/fullstack-engineer.md +32 -4
  7. package/assets/init/.qfai/assistant/agent/implementation-reviewer.md +4 -4
  8. package/assets/init/.qfai/assistant/agent/product-surface-reviewer.md +7 -3
  9. package/assets/init/.qfai/assistant/agent/requirements-reviewer.md +2 -2
  10. package/assets/init/.qfai/assistant/rule/agent-selection.md +1 -1
  11. package/assets/init/.qfai/assistant/rule/communication.md +1 -1
  12. package/assets/init/.qfai/assistant/rule/constitution.md +77 -242
  13. package/assets/init/.qfai/assistant/rule/drift-protocol.md +30 -164
  14. package/assets/init/.qfai/assistant/rule/references/asset-authoring.md +3 -2
  15. package/assets/init/.qfai/assistant/rule/references/gate-failure-autorepair.md +2 -2
  16. package/assets/init/.qfai/assistant/rule/references/placeholder-scan.md +2 -3
  17. package/assets/init/.qfai/assistant/rule/references/reviewer-findings.md +3 -3
  18. package/assets/init/.qfai/assistant/rule/references/worker-edit-boundary.md +12 -3
  19. package/assets/init/.qfai/assistant/rule/review-convergence.md +6 -6
  20. package/assets/init/.qfai/assistant/rule/shared-skill-delegation-baseline.md +6 -6
  21. package/assets/init/.qfai/assistant/rule/shared-skill-operating-baseline.md +17 -17
  22. package/assets/init/.qfai/assistant/rule/test-layers.md +1 -1
  23. package/assets/init/.qfai/assistant/rule/thinking.md +2 -2
  24. package/assets/init/.qfai/assistant/rule/ui-definition-protocol.md +5 -5
  25. package/assets/init/.qfai/assistant/rule/ui-procurement.md +1 -1
  26. package/assets/init/.qfai/assistant/rule/workflow.md +12 -12
  27. package/assets/init/.qfai/assistant/skill/qfai-configure/SKILL.md +12 -14
  28. package/assets/init/.qfai/assistant/skill/qfai-discussion/SKILL.md +2 -4
  29. package/assets/init/.qfai/assistant/skill/qfai-discussion/templates/03_Story-Workshop.md +1 -2
  30. package/assets/init/.qfai/assistant/skill/qfai-discussion/templates/uiux/50_review_input_bundle.md +4 -3
  31. package/assets/init/.qfai/assistant/skill/qfai-grill/SKILL.md +1 -3
  32. package/assets/init/.qfai/assistant/skill/qfai-grilling/SKILL.md +30 -43
  33. package/assets/init/.qfai/assistant/skill/qfai-grilling/references/confirmation-sheet.md +71 -0
  34. package/assets/init/.qfai/assistant/skill/qfai-grilling/references/delegated-session.md +18 -1
  35. package/assets/init/.qfai/assistant/skill/qfai-implement/SKILL.md +2 -4
  36. package/assets/init/.qfai/assistant/skill/qfai-implement/references/parallelization-policy.md +3 -3
  37. package/assets/init/.qfai/assistant/skill/qfai-implement/references/ui-affecting.md +35 -2
  38. package/assets/init/.qfai/assistant/skill/qfai-maintain/SKILL.md +2 -4
  39. package/assets/init/.qfai/assistant/skill/qfai-migration-v1-to-v2/SKILL.md +0 -2
  40. package/assets/init/.qfai/assistant/skill/qfai-migration-v1-to-v2/references/migration-guide.md +2 -3
  41. package/assets/init/.qfai/assistant/skill/qfai-prototyping/SKILL.md +5 -6
  42. package/assets/init/.qfai/assistant/skill/qfai-prototyping/references/generator-prompt.md +75 -4
  43. package/assets/init/.qfai/assistant/skill/qfai-prototyping/references/handoff.md +2 -1
  44. package/assets/init/.qfai/assistant/skill/qfai-prototyping/references/iteration-loop.md +58 -3
  45. package/assets/init/.qfai/assistant/skill/qfai-prototyping/references/review-payload-schema.md +11 -2
  46. package/assets/init/.qfai/assistant/skill/qfai-prototyping/references/reviewer-prompt.md +41 -10
  47. package/assets/init/.qfai/assistant/skill/qfai-run/SKILL.md +7 -8
  48. package/assets/init/.qfai/assistant/skill/qfai-run/references/extraction.md +12 -7
  49. package/assets/init/.qfai/assistant/skill/qfai-run/references/stage-points.md +1 -1
  50. package/assets/init/.qfai/assistant/skill/qfai-sdd/SKILL.md +10 -12
  51. package/assets/init/.qfai/assistant/skill/qfai-sdd/references/concrete-abstract-cycle.md +25 -27
  52. package/assets/init/.qfai/assistant/skill/qfai-sdd/references/contract-artifact-rules.md +8 -10
  53. package/assets/init/.qfai/assistant/skill/qfai-sdd/references/design-anti-patterns.md +36 -3
  54. package/assets/init/.qfai/assistant/skill/qfai-sdd/references/design-md-authoring.md +8 -9
  55. package/assets/init/.qfai/assistant/skill/qfai-sdd/references/requirements-decomposition.md +6 -6
  56. package/assets/init/.qfai/assistant/skill/qfai-sdd/references/sdd-execution-playbook.md +6 -6
  57. package/assets/init/.qfai/assistant/skill/qfai-sdd/references/sdd-phase-checklists.md +5 -5
  58. package/assets/init/.qfai/assistant/skill/qfai-sdd/references/sdd-pre-draft-grilling.md +5 -5
  59. package/assets/init/.qfai/assistant/skill/qfai-sdd/references/sdd-quality-gate.md +3 -3
  60. package/assets/init/.qfai/assistant/skill/qfai-sdd/references/sdd-triage.md +115 -199
  61. package/assets/init/.qfai/assistant/skill/qfai-sdd/references/spec-traceability-rules.md +25 -25
  62. package/assets/init/.qfai/assistant/skill/qfai-sdd/references/ui-contract-guide.md +23 -113
  63. package/assets/init/.qfai/assistant/skill/qfai-sdd/references/ui-design-contract-normalization.md +2 -2
  64. package/assets/init/.qfai/assistant/skill/qfai-sdd/templates/contracts/ui-contract.sample.yaml +8 -7
  65. package/assets/init/.qfai/assistant/skill/qfai-sdd/templates/spec/03_contract/tech.md +1 -0
  66. package/assets/init/.qfai/assistant/skill/qfai-sdd/templates/spec/decisions/page-NNNN.md +2 -2
  67. package/assets/init/.qfai/assistant/skill/qfai-sdd/templates/spec/decisions.md +59 -31
  68. package/assets/init/.qfai/assistant/skill/qfai-sdd/templates/spec/open-questions.md +15 -11
  69. package/assets/init/.qfai/assistant/skill/qfai-triage/SKILL.md +1 -3
  70. package/assets/init/.qfai/assistant/skill/qfai-verify/SKILL.md +2 -4
  71. package/assets/init/.qfai/assistant/skill/qfai-verify/references/verify-output-contract.md +1 -1
  72. package/assets/init/.qfai/assistant/skill/web-research/SKILL.md +1 -3
  73. package/assets/init/.qfai/assistant/step/common-design-md/STEP.md +9 -9
  74. package/assets/init/.qfai/assistant/step/common-gate-run/STEP.md +2 -2
  75. package/assets/init/.qfai/assistant/step/common-grilling-record/STEP.md +3 -3
  76. package/assets/init/.qfai/assistant/step/common-policy-check/STEP.md +1 -1
  77. package/assets/init/.qfai/assistant/step/common-review-cycle/STEP.md +6 -4
  78. package/assets/init/.qfai/assistant/step/discussion-interview/STEP.md +7 -7
  79. package/assets/init/.qfai/assistant/step/discussion-pack/STEP.md +43 -0
  80. package/assets/init/.qfai/assistant/step/implement-acceptance/STEP.md +1 -1
  81. package/assets/init/.qfai/assistant/step/implement-dep-bump/STEP.md +11 -13
  82. package/assets/init/.qfai/assistant/step/implement-procedure/STEP.md +1 -1
  83. package/assets/init/.qfai/assistant/step/implement-regression-fix/STEP.md +2 -2
  84. package/assets/init/.qfai/assistant/step/implement-scaffold/STEP.md +5 -5
  85. package/assets/init/.qfai/assistant/step/implement-tdd/STEP.md +7 -8
  86. package/assets/init/.qfai/assistant/step/maintain-edit/STEP.md +17 -17
  87. package/assets/init/.qfai/assistant/step/prototyping-grill/STEP.md +1 -1
  88. package/assets/init/.qfai/assistant/step/prototyping-loop/STEP.md +89 -12
  89. package/assets/init/.qfai/assistant/step/sdd-contract/STEP.md +16 -15
  90. package/assets/init/.qfai/assistant/step/sdd-cycle/STEP.md +7 -8
  91. package/assets/init/.qfai/assistant/step/sdd-flow/STEP.md +25 -4
  92. package/assets/init/.qfai/assistant/step/sdd-story/STEP.md +6 -6
  93. package/assets/init/.qfai/assistant/step/sdd-triage/STEP.md +66 -75
  94. package/assets/init/.qfai/assistant/step/triage-operate/STEP.md +29 -15
  95. package/assets/init/.qfai/assistant/step/verify-commit/STEP.md +2 -4
  96. package/assets/init/.qfai/assistant/step/verify-context/STEP.md +1 -1
  97. package/assets/init/root/.agents/rules/ai-readable-markdown.md +8 -1
  98. package/assets/init/root/.agents/rules/delegation-steering.md +69 -0
  99. package/assets/init/root/.agents/rules/grilling.md +72 -43
  100. package/assets/init/root/.agents/rules/minimal-implementation.md +5 -5
  101. package/assets/init/root/.agents/rules/reply-forms.md +191 -0
  102. package/assets/init/root/.agents/rules/session-feedback.md +104 -27
  103. package/assets/init/root/.agents/rules/user-questions.md +6 -1
  104. package/assets/init/root/.gitattributes +5 -6
  105. package/assets/init/root/AGENTS.md +4 -2
  106. package/assets/mdschema/story/03_contract/tech.mdschema.yml +1 -1
  107. package/assets/mdschema/story/decisions/page-NNNN.mdschema.yml +3 -3
  108. package/assets/mdschema/story/decisions.mdschema.yml +4 -4
  109. package/assets/mdschema/story/open-questions.mdschema.yml +3 -3
  110. package/assets/schemas/workflow/extraction.schema.json +0 -2
  111. package/dist/cli/index.cjs +3749 -3029
  112. package/dist/cli/index.cjs.map +1 -1
  113. package/dist/cli/index.mjs +3718 -3006
  114. package/dist/cli/index.mjs.map +1 -1
  115. package/dist/hook/turn-end.cjs +1022 -0
  116. package/dist/hook/turn-end.cjs.map +1 -0
  117. package/dist/hook/turn-end.d.cts +2 -0
  118. package/dist/hook/turn-end.d.ts +2 -0
  119. package/dist/hook/turn-end.mjs +998 -0
  120. package/dist/hook/turn-end.mjs.map +1 -0
  121. package/dist/index.cjs +3626 -3577
  122. package/dist/index.cjs.map +1 -1
  123. package/dist/index.d.cts +19 -3
  124. package/dist/index.d.ts +19 -3
  125. package/dist/index.mjs +3544 -3498
  126. package/dist/index.mjs.map +1 -1
  127. package/package.json +2 -2
  128. package/assets/init/.qfai/assistant/skill/qfai-sdd/templates/change-request.md +0 -52
@@ -129,6 +129,49 @@ finalize the design system here. The brand direction is the exception — which
129
129
  published theme the product is built on is the user's decision, and there is no
130
130
  later stage where they are asked.
131
131
 
132
+ ## Parse the diagrams
133
+
134
+ Before the gate, parse every Mermaid diagram the pack holds with Mermaid's own
135
+ grammar. `npx qfai validate` checks only that a diagram is there; a diagram that
136
+ does not parse is otherwise found by CI, after handoff.
137
+
138
+ 1. Where the project has no `node_modules/qfai`, install the release that
139
+ `npx qfai --version` prints into a directory of its own, and read
140
+ `tmp/qfai-release/node_modules/qfai/` wherever the steps below name
141
+ `node_modules/qfai/`.
142
+
143
+ ```bash
144
+ npm install --no-save --no-audit --no-fund --ignore-scripts --prefix=tmp/qfai-release qfai@<version>
145
+ ```
146
+
147
+ 2. Read the `mermaid@` and `jsdom@` versions from the install step of
148
+ `node_modules/qfai/assets/init/root/.github/workflows/qfai-docs.yml`, or of
149
+ `tmp/qfai-release/node_modules/qfai/assets/init/root/.github/workflows/qfai-docs.yml`,
150
+ the shipped copy of the installed release.
151
+ 3. Install them into a directory of their own, never into the project's
152
+ dependency tree.
153
+
154
+ ```bash
155
+ npm install --no-save --no-audit --no-fund --ignore-scripts --include=optional --prefix=tmp/qfai-mermaid mermaid@<version> jsdom@<version>
156
+ ```
157
+
158
+ 4. Run the parser over the pack directory.
159
+
160
+ ```bash
161
+ node node_modules/qfai/assets/scripts/check-mermaid.mjs --tools tmp/qfai-mermaid <pack directory>
162
+ ```
163
+
164
+ Where step 1 installed the release, run its checker instead:
165
+
166
+ ```bash
167
+ node tmp/qfai-release/node_modules/qfai/assets/scripts/check-mermaid.mjs --tools tmp/qfai-mermaid <pack directory>
168
+ ```
169
+
170
+ 5. Fix each diagram it rejects, and run it again until it exits 0.
171
+
172
+ When the install or the run fails for a reason other than a rejected diagram,
173
+ report the syntax check as not run, never as passed, and give the reason.
174
+
132
175
  ## Gate
133
176
 
134
177
  The reviewer confirms:
@@ -54,7 +54,7 @@ contract IDs are not coverage annotations.
54
54
  mutation.
55
55
  4. A test that fails because the product is wrong is not repaired here: report
56
56
  it as a defect for `implement-tdd` or a fix route. A test that cannot be
57
- written because the story or contract is wrong is a change request under
57
+ written because the story or contract is wrong is a specification change under
58
58
  `.qfai/assistant/rule/drift-protocol.md`.
59
59
 
60
60
  ## Gate
@@ -49,31 +49,29 @@ finding that names a spec contract moves the work as the next section says.
49
49
  When `validate`, or another check the update runs, reports a finding that
50
50
  names a spec contract to change, leave the contract unchanged. Finish every
51
51
  other part of the update first, so the contract finding is the only open item.
52
- Then get the change approved as `.qfai/assistant/rule/drift-protocol.md`
52
+ Then put the change to the operator as `.qfai/assistant/rule/drift-protocol.md`
53
53
  describes:
54
54
 
55
55
  1. Put the finding, the contract it names and the fix it states to the
56
56
  operator as a critical decision: return `awaiting_input` and change nothing
57
57
  more. The attempt holding the answer carries on.
58
- 2. On approval, append one `Change request:` row to `decisions.md` under
59
- `paths.specsDir`. Its Content names the contract's path, and its Approach
60
- records the finding, the fix, who approved it and when. The row starts at
61
- WIP.
62
- 3. Report `branch: { outcome: contract-finding }` citing that row's DEC ID.
63
- The work moves to `apply-settled`, whose `spec` stage edits the contract
64
- under its change request. Its settled triage applies the cited row.
58
+ 2. On approval, report `branch: { outcome: contract-finding }` naming the
59
+ contract's path, the finding, the fix, who approved it and when. The work
60
+ moves to `apply-settled`, whose `spec` stage edits the contract as approved.
61
+ The approval is a `decisions.md` row only when it meets the recording test
62
+ of the `qfai-sdd` decisions template.
65
63
 
66
- On a decline, append the row at REJECTED, leave the contract as it is and
67
- report the finding as unresolved, with no branch. When the operator cannot be
68
- asked, write no row and report the change as the decision still needed.
64
+ On a decline, leave the contract as it is, append a `Declined:` row naming the
65
+ contract change and who declined it and when, and report the finding as
66
+ unresolved, with no branch. When the operator cannot be asked, report the
67
+ change as the decision still needed.
69
68
 
70
69
  ## What it writes
71
70
 
72
71
  - The actual changed paths for the manifest, lockfile and any adapted call,
73
72
  listed in the stage report. When the dependency is `qfai` itself, they also
74
73
  include a new key in `qfai.config.yaml`.
75
- - On a contract finding the operator answered, the change request row in
76
- `decisions.md`, and its DEC ID in the stage report.
74
+ - On a contract finding the operator answered, the answer in the stage report.
77
75
  - A record of the versions, the breaking changes read and how each was met, in the stage report.
78
76
 
79
77
  ## Gate
@@ -93,4 +93,4 @@ no checker covers the changed files, the stage report records "no applicable
93
93
  checker", which neither passes nor blocks the gate.
94
94
  A changed named script passes its existing tests and checks, with coverage
95
95
  added where the repository has tests for it.
96
- Protected edits and uncovered actions were stopped before writing or acting.
96
+ Edits to upstream artifacts and uncovered actions were stopped before writing or acting.
@@ -32,8 +32,8 @@ The route's code review judges the fix. A fix that changes a screen, as
32
32
  to that review. The full suite and the
33
33
  project gates run once, in the verify stage.
34
34
 
35
- The example stays annotated by the same test. No `Change request:` row is
36
- appended and no evidence entry is removed. A contradiction or obstacle found
35
+ The example stays annotated by the same test. No story or contract changes,
36
+ and no evidence entry is removed. A contradiction or obstacle found
37
37
  here stops the work under Article IX of
38
38
  `.qfai/assistant/rule/constitution.md`.
39
39
 
@@ -33,8 +33,8 @@ the system's shape has settled.
33
33
 
34
34
  1. Run `npx qfai validate --profile atdd --flow BF-NNNN --fail-on never` as
35
35
  `common-gate-run` says, and list the BF and AC items no test annotates.
36
- Drop from that list each item a `Test exception:` row at DONE names: it is
37
- owed no test.
36
+ Drop from that list each item a `Test exception:` row names: it is owed no
37
+ test.
38
38
  2. Unless § Purpose-named test files applies, when the flow is still on that
39
39
  list, run `npx qfai atdd scaffold --flow BF-NNNN`. It writes
40
40
  `<testsDir>/e2e/<BF-ID>.test.<ext>`.
@@ -76,12 +76,12 @@ apply.
76
76
  ## Passes when
77
77
 
78
78
  Read first: the BF and AC items of the flow that no `Test exception:` row
79
- at DONE names, and the tests that annotate them. The step passes when every one
79
+ names, and the tests that annotate them. The step passes when every one
80
80
  already has an annotating test at its layer. The pass names the test for each item.
81
81
 
82
82
  ## Gate
83
83
 
84
- PASS when every BF and AC of the flow that no `Test exception:` row at DONE
85
- names has an annotating test at its layer, and
84
+ PASS when every BF and AC of the flow that no `Test exception:` row names
85
+ has an annotating test at its layer, and
86
86
  `npx qfai validate --profile atdd --flow BF-NNNN --fail-on error` reports no
87
87
  error owned by this flow.
@@ -36,9 +36,9 @@ Green and Refactor cycle. The pass names the examples and their tests.
36
36
  ## Scope
37
37
 
38
38
  Send a decision, a question for the user or an out-of-scope discovery to
39
- `/qfai-sdd` as a change request. An out-of-scope discovery does not stop the
39
+ `/qfai-sdd` as a specification change. An out-of-scope discovery does not stop the
40
40
  current flow. A diagnosed missing test on behaviour an existing AC states is
41
- the one scope gap that raises no change request: an EX that states the case is
41
+ the one scope gap that goes to no specification change: an EX that states the case is
42
42
  worked as an EX no test annotates, and where none does, this step appends it,
43
43
  as [A diagnosed missing example](#a-diagnosed-missing-example) states.
44
44
 
@@ -52,7 +52,7 @@ as [A diagnosed missing example](#a-diagnosed-missing-example) states.
52
52
  `.qfai/assistant/rule/drift-protocol.md` before dependent work resumes.
53
53
  2. Read the **Standard commands** section of
54
54
  `<paths.contractsDir>/tech.md`, as
55
- `.qfai/assistant/rule/shared-skill-operating-baseline.md#standard-commands-mandatory`
55
+ `.qfai/assistant/rule/shared-skill-operating-baseline.md#standard-commands`
56
56
  states. Obtain the Test command only from that section. Lint, Typecheck
57
57
  and Build run once, in the verify stage. Read its
58
58
  `## Architecture` table too: place each new module in one layer, and
@@ -104,9 +104,8 @@ requires, so the step asks the user nothing:
104
104
  - Add the new EX ID to the selected rule's Examples cell. Its Statement is
105
105
  unchanged. This choice of equivalent rules asks no extra question.
106
106
  - Change no story, AC, rule statement or existing EX.
107
- - Append no `decisions.md` row: the drift gate needs no `Change request:` row
108
- for appended example rows and the new EX ID in the citing rule's Examples
109
- cell.
107
+ - Append no `decisions.md` row for the appended example row and the new EX ID
108
+ in the citing rule's Examples cell.
110
109
  - List the EX, chosen BR and the reason for choosing it in the run's final
111
110
  report.
112
111
  - No concrete-abstract cycle runs.
@@ -126,8 +125,8 @@ Work the examples in this order:
126
125
  3. Otherwise the flow's EX IDs that no test annotates, in EX ID order. A test
127
126
  annotating an example is what says the example is done.
128
127
 
129
- An EX that a `decisions.md` row opening `Test exception:` names, with Status
130
- DONE, is exempt and is not selected.
128
+ An EX that a `decisions.md` row opening `Test exception:` names is exempt while
129
+ that row exists, and is not selected.
131
130
 
132
131
  See `.qfai/assistant/skill/qfai-implement/references/cross-spec-ownership.md`
133
132
  for changes that touch another flow and
@@ -42,20 +42,16 @@ changes.
42
42
  In the `resolve-conflicts` route, the step merges the named base into the
43
43
  branch and keeps every record's meaning. `verify-commit` concludes the merge.
44
44
 
45
- 1. Fetch the base (`git fetch`), then on a clean tree, before the merge,
46
- renumber every `decisions.md` row the branch added, from the lowest one
47
- whose ID the fetched base now declares upward, lowest first, by the
48
- `npx qfai sdd renumber-decision` procedure in
49
- `.qfai/assistant/skill/qfai-sdd/references/sdd-triage.md` (two branches
50
- taking the same ID), and commit after each run. The union merge of
51
- `decisions.md` duplicates a colliding ID without a conflict, so this runs
52
- first. When a merge has already stopped with conflicts, run
53
- `git merge --abort`, renumber, and merge again.
54
- 2. Start or resume the merge with `git merge --no-commit <base>`.
55
- 3. Resolve each conflict. The base's item keeps its ID; never rename it. An
56
- item the branch added whose ID collides takes the next free ID of its scope,
57
- with every citation of it. Every other edit only keeps what one side already
58
- had: what each side added to a conflicting block.
45
+ 1. Fetch the base (`git fetch`).
46
+ 2. Start or resume the merge with `git merge --no-commit <base>`. The union
47
+ merge resolves `decisions.md`, its pages and `open-questions.md` by keeping
48
+ both sides' rows. Edit, move and renumber no register row, except that a
49
+ question row the union merge kept although one side deleted it is deleted
50
+ again, since that deletion settled the question.
51
+ 3. Resolve each other conflict. The base's item keeps its ID; never rename it.
52
+ A story-tree item the branch added whose ID collides takes the next free ID
53
+ of its scope, with every citation of it. Every other edit only keeps what
54
+ one side already had: what each side added to a conflicting block.
59
55
 
60
56
  Stop before the edit, as [A semantic effect](#a-semantic-effect) says, on any
61
57
  of these:
@@ -70,8 +66,11 @@ of these:
70
66
  file or a lockfile, stops: its owner route resolves or regenerates it.
71
67
  - A conflict in a pin or digest file, or in a file with an owner marker or a
72
68
  CODEOWNERS entry, stops.
73
- - After the merge, check each union-merged register, such as `decisions.md`,
74
- for an ID declared twice. A duplicate is a semantic effect: stop.
69
+ - After the merge, check each union-merged register for an ID declared twice.
70
+ Stop, and name the ID. A row the base holds is never renumbered: when the
71
+ branch's own unmerged row collides, the branch deletes that row and appends
72
+ it again under a new timestamp ID, updating the citations of it the branch
73
+ added.
75
74
 
76
75
  ### Several branches
77
76
 
@@ -158,5 +157,6 @@ its reason, and every check run over the changed files exited 0. The review that
158
157
  follows (`implementation-reviewer`) confirms the diff changes no behaviour; the
159
158
  reviewer is never the agent that made the edit. In the `resolve-conflicts`
160
159
  route, that review runs as `common-review-cycle` says: a resolution that
161
- touches no story-tree file, contract or register row gets no reviewer. The
160
+ touches no story-tree file or contract gets no reviewer, and the union merge of
161
+ the registers adds none. The
162
162
  combined diff passes the added-line check before `verify-commit` commits.
@@ -149,7 +149,7 @@ and name it.
149
149
  and `## Escalated` for a critical decision the user has yet to settle, plus
150
150
  `## Run scope` when the run is scoped (see [Run scope](#run-scope)). The
151
151
  generator and the reviewer both take that file as an input — named in
152
- `prototyping-loop`'s `## Evaluator Inputs (Mandatory)` and in the generator's
152
+ `prototyping-loop`'s `## Evaluator Inputs` and in the generator's
153
153
  contract set — because a decision the loop cannot read is one it will
154
154
  contradict on the next iteration, and the user will be asked to re-settle what they
155
155
  already settled.
@@ -9,8 +9,9 @@ requires: []
9
9
 
10
10
  The build and review loop. Each iteration builds a prototype under root
11
11
  `DESIGN.md`, has it reviewed, and puts it to the user. The loop ends when the
12
- user confirms the prototype; until then it runs another iteration on the user's
13
- answer. No command, score or check decides that the loop is done.
12
+ user confirms the prototype, or when a restyle with nothing to fix stops before
13
+ iteration 00; until then it runs another iteration on the user's answer. No
14
+ command, score or check decides that the loop is done.
14
15
 
15
16
  ## Reads
16
17
 
@@ -23,8 +24,12 @@ answer. No command, score or check decides that the loop is done.
23
24
  - `.qfai/prototype/iter-NN/index.html` (the generator), and in a `restyle`
24
25
  loop the project's stylesheet and motion files it restyles.
25
26
  - `.qfai/prototype/iter-NN/review.json` and
26
- `iter-NN/<ui-contract-id>/<screen>.review.json` (the reviewer).
27
+ `iter-NN/<ui-contract-id>/<screen>.review.json` (the reviewer); in an
28
+ iteration with variants, the same files under `iter-NN/variant-<id>/`.
27
29
  - `.qfai/prototype/progress.md` (the session agent).
30
+ - In a `restyle` loop, `.qfai/prototype/baseline/<ui-contract-id>/<screen>.txt`
31
+ (the session agent), before iteration 00, and the audit lines and
32
+ `restyleLevel` in `progress.md`.
28
33
  - The session rows of `.qfai/prototype/grilling.md`.
29
34
 
30
35
  ## Required References
@@ -87,6 +92,45 @@ qualifier `restyle` is planned with only such scopes.
87
92
  If the route's scope has no implement stage, stop and ask the user to re-plan
88
93
  before iteration 00.
89
94
 
95
+ ### Before a restyle edits anything
96
+
97
+ The session agent does two things before iteration 00 changes a file:
98
+
99
+ 1. **Baseline.** Open each in-scope live route with the setup its link names
100
+ and save the text the screen shows to
101
+ `.qfai/prototype/baseline/<ui-contract-id>/<screen>.txt`. Capture it twice
102
+ and leave out only text that differs between the two captures, such as a
103
+ clock. The reviewer of every restyle iteration compares the route with it.
104
+ 2. **Audit.** Read the rendered routes against
105
+ `.qfai/assistant/skill/qfai-sdd/references/design-anti-patterns.md` and
106
+ root `DESIGN.md`, one line per finding with the screen and the place it
107
+ sits. Record `restyleLevel` in `progress.md` beside `iterationKind`, with
108
+ the audit lines under it. The level is the session agent's judgement of
109
+ those lines:
110
+
111
+ | Level | When | What the restyle changes |
112
+ | ---------- | ------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- |
113
+ | `full` | Many patterns across several aspects | Every aspect the stylesheet and motion reach |
114
+ | `targeted` | A few patterns on screens that are otherwise deliberate | Only what the audit found; the palette, type and layout stay, and larger ideas go to the report as suggestions |
115
+ | `none` | No pattern | At most three refinements, each with exact values; only those the user accepts, listed in `progress.md` |
116
+
117
+ Every level stays within the root `DESIGN.md` tokens: a fix that needs a
118
+ value `DESIGN.md` does not declare is reported as a `DESIGN.md` change, not
119
+ made.
120
+
121
+ Put the audit and the level to the user before the first edit, so they can
122
+ steer it. A screen that is already good is not changed to be different: at
123
+ `none`, iteration 00 applies only the refinements the user accepted, and
124
+ when the user accepts none, the run ends there as **Stopped**, with no edit
125
+ and no handoff; the route's later stages then change nothing, and the final
126
+ report says the screens were left as they were. Under a no-question mode, the
127
+ level is taken as an assumption the report names; at `none` nobody can accept
128
+ a refinement, so the run stops before iteration 00.
129
+
130
+ The baseline is written afresh each run, replacing the files of the last one.
131
+ It holds the live app's text, which can be real customer data: like the rest
132
+ of `.qfai/prototype/`, it is a working file and is not committed.
133
+
90
134
  ## Run scope
91
135
 
92
136
  Each run records `runScope` in `progress.md` afresh, beside `iterationKind`,
@@ -110,6 +154,15 @@ answer: those start with this run.
110
154
 
111
155
  With `runScope` absent, every screen is in scope and nothing here applies.
112
156
 
157
+ ## Variants
158
+
159
+ Record `variants` in `progress.md` with the planning fields above, before the
160
+ run's first iteration: `A, B` or `A, B, C` when the direction is open, else
161
+ `none`. The iteration loop reference's First-iteration variants section says
162
+ when it is open and where each variant's review goes. Only that first
163
+ iteration has variants: set `variants` to `none` before the next iteration,
164
+ which builds one prototype from the user's answer.
165
+
113
166
  ## Procedure
114
167
 
115
168
  Run these for iteration `NN`: the next index after the iterations already
@@ -122,19 +175,24 @@ under `.qfai/prototype/`, or `00` when there are none.
122
175
  `.qfai/prototype/final/index.html`, every iteration. It starts from the
123
176
  primary UI contract preflight resolved: the one the request names, else
124
177
  `prototyping.primaryUiContract`. Writes
125
- `.qfai/prototype/iter-NN/index.html`.
178
+ `.qfai/prototype/iter-NN/index.html`, holding every variant when this is
179
+ the run's first iteration and `variants` is not `none`.
126
180
  2. **Build** (the session agent). Serves `.qfai/prototype/` at the URL
127
181
  preflight checked, starting the server on the first iteration and keeping it
128
- running for the loop, and hands `<url>/iter-NN/` to the reviewer.
182
+ running for the loop, and hands `<url>/iter-NN/` to the reviewer. In an
183
+ iteration with variants it starts one fresh reviewer per variant and hands
184
+ each only `<url>/iter-NN/?variant=<id>`.
129
185
  3. **Reviewer** (product-surface-reviewer). Opens that URL, operates
130
186
  Playwright live and returns the payload for each UI contract and screen
131
187
  pair, and the per-iteration summary aggregated from them, per the reviewer
132
188
  prompt: the four ordinal UX axes, a critique of at most 500 words,
133
189
  `blockingFindings`, `layoutAntiPatternsDetected[]`,
134
- `designMdViolations[]` and `pivotDirective`.
190
+ `designMdViolations[]` and `pivotDirective`. A variant's reviewer reviews
191
+ that variant alone and never opens another.
135
192
  4. **Session agent.** Writes each payload to
136
193
  `iter-NN/<ui-contract-id>/<screen>.review.json` and the summary to
137
- `iter-NN/review.json`. Each payload is checked against the closed schema
194
+ `iter-NN/review.json`. Each variant's files go under `iter-NN/variant-<id>/`.
195
+ Each payload is checked against the closed schema
138
196
  before it is written, and one that does not conform is asked for again. A
139
197
  summary whose `layoutAntiPatternsDetected[]` is not empty scores
140
198
  `informationArchitecture` at most `acceptable`; a higher score is written as
@@ -158,6 +216,15 @@ Show the user where the prototype is, the four scores, and every blocking
158
216
  finding, layout anti-pattern and `DESIGN.md` violation the review lists. The
159
217
  review informs the answer; it does not replace it.
160
218
 
219
+ With variants, the reaction is put as one compare sheet, not through
220
+ `AskUserQuestion`: the sheet follows `.agents/rules/reply-forms.md`, in its
221
+ carrier order and reply text, and shows each variant's `?variant=<id>`
222
+ address, scores, blocking findings, layout anti-patterns and `DESIGN.md`
223
+ violations. A reply whose `keep from` line names another variant is a
224
+ combination. A reply with no `pick:` whose `why:` turns down every variant is
225
+ a rejection. Neither the agent nor a review's scores pick a variant. The sheet
226
+ recommends only as `.agents/rules/reply-forms.md` § 1 permits.
227
+
161
228
  Record the answer in `.qfai/prototype/grilling.md` under `## Session`,
162
229
  **replacing any row with the same `Scope` and decision rather than adding beside
163
230
  it, and removing its row from `## Escalated`** — the file is the current state
@@ -165,6 +232,10 @@ of the tree, not its history.
165
232
 
166
233
  How the session ends decides the route:
167
234
 
235
+ - **A pick, a combination or a rejection** — the answer to an iteration with
236
+ variants — runs the next iteration as one prototype: the variant picked, the
237
+ parts combined, or a pivot carrying the rejection. An iteration with
238
+ variants is never confirmed as it stands, so its handoff does not run.
168
239
  - **Confirmed** — the user says the prototype is done — goes to
169
240
  `prototyping-handoff`. A blocking finding the latest review still lists does
170
241
  not stop it; the final report names it.
@@ -176,18 +247,23 @@ How the session ends decides the route:
176
247
  every other open decision as a labelled assumption and asks this question
177
248
  again. It is what the loop exists to answer, so a closure cannot assume it.
178
249
  - **Stopped** — the user said `stop` — ends the run there and reports every
179
- open decision as open.
250
+ open decision as open. A restyle at `none` with no refinement accepted ends
251
+ the same way, as _Before a restyle edits anything_ says.
180
252
 
181
253
  Under a no-question mode nobody can answer, so the question is written to
182
254
  `## Escalated` and the run stops there. A reviewer's scores are not the user's
183
255
  confirmation.
184
256
 
185
- ## Evaluator Inputs (Mandatory)
257
+ ## Evaluator Inputs
186
258
 
187
259
  - The live prototype, opened in the reviewer's own Playwright session.
260
+ - In a `restyle` iteration, each route's baseline at
261
+ `.qfai/prototype/baseline/<ui-contract-id>/<screen>.txt`.
188
262
  - Root `DESIGN.md` (read-only), `axisDefs`, `previousScore` and
189
263
  `designSystemChecklist`. `previousScore` and the prior reviews come from
190
- this run's own iterations; the run's first iteration has none.
264
+ this run's own iterations; the run's first iteration has none. After an
265
+ iteration with variants they are read as the iteration loop reference's
266
+ First-iteration variants section says.
191
267
  - The prior `review.json` files and `progress.md`.
192
268
  - The layout anti-pattern registry the package ships.
193
269
  - `.qfai/prototype/grilling.md` — what the prototype is for, what counts as
@@ -199,8 +275,9 @@ confirmation.
199
275
 
200
276
  ## Critical Constraints
201
277
 
202
- - One lineage only — no parallel candidates, no best-of-history; the latest
203
- iteration is always the one put to the user.
278
+ - One prototype per iteration, except the variants of a run's first iteration
279
+ while the direction is open; no best-of-history; the latest iteration is
280
+ always the one put to the user.
204
281
  - Token-only colors, fonts, radii and shadows — a value `DESIGN.md` does not
205
282
  declare lands in `designMdViolations[]`.
206
283
  - No `mode / round / polish / branch / concept-fit` artifacts.
@@ -38,8 +38,8 @@ number is never reused. The file is `<kind>-NNNN-<slug>.<ext>`, and it declares
38
38
  its ID once: in the H1 of a Markdown contract (`# CLI-0001: <title>`), or on a
39
39
  `QFAI-CONTRACT-ID: API-0002` line in YAML or SQL.
40
40
 
41
- Write only what the user approved, as
42
- `.qfai/assistant/skill/qfai-sdd/references/sdd-triage.md#a-change-to-the-story-tree`
41
+ Write only the triaged scope, as
42
+ `.qfai/assistant/skill/qfai-sdd/references/sdd-triage.md#critical-decisions-and-no-question-mode`
43
43
  states.
44
44
 
45
45
  ## Procedure
@@ -74,14 +74,14 @@ surface also needs the root `DESIGN.md`, which `common-design-md` writes and
74
74
  validates after this step. A CLI-only surface does not require one. Do not
75
75
  adopt a sample design.
76
76
 
77
- Each screen records its copy decisions in the contract: `supplements` and, for any
78
- heading beyond the title, `structure`. Check every text element the discussion or
79
- the story proposes against the screen's tasks and the information the user needs at
80
- that point. A text that repeats a heading, an action, or a condition the user already
81
- has is left out; one that carries a condition, cost, destination, result, recovery
82
- step or consequence stays, with its reason. Fix a control that needs explaining
83
- before adding text for it. The discussion sidecar stays an input; the contract is
84
- the one place the decision is written.
77
+ Check every text element the discussion or the story proposes against the
78
+ screen's tasks and the information the user needs at that point. A text that
79
+ repeats a heading, an action, or a condition the user already has is left out;
80
+ one that carries a condition, cost, destination, result, recovery step or
81
+ consequence stays, with its reason. Fix a control that needs explaining before
82
+ adding text for it. A screen may describe the copy that stays in its optional
83
+ `supplements` and `structure`; `npx qfai validate` does not check them, and the
84
+ reason that counts is the `qfai-text` comment written in the UI source.
85
85
 
86
86
  ## A named contract
87
87
 
@@ -92,14 +92,15 @@ the run.
92
92
  1. Scope the work to the named contract, its paired contracts, and the existing
93
93
  flows whose AC, EX, or BR depend on them.
94
94
  2. Read every affected flow's existing AC and EX and the paired contracts, then
95
- repair only the contract scope approved by the change request. No previous
96
- triage approval can substitute for approval of a new change-request row.
95
+ repair only the triaged contract scope. A repair outside it that is a
96
+ critical decision goes to the user first; an earlier answer covers only the
97
+ change it described.
97
98
  3. Recompute affected flows after each contract change until no new flow or
98
99
  contract write is found. Gather the newly exposed decisions and grill again
99
100
  before the next mutation.
100
- 4. Do not silently rewrite a story in this mode; ask for a wider change request
101
- when only the story can move.
102
- 5. A `confirm-only` change request stays read-only and stops on a mismatch.
101
+ 4. Do not silently rewrite a story in this mode; put the story change to the
102
+ user as a critical decision when only the story can move.
103
+ 5. A `confirm-only` request stays read-only and stops on a mismatch.
103
104
  6. An activated API contract without an owning flow remains planned until an
104
105
  owner is established.
105
106
 
@@ -27,17 +27,16 @@ rules against their examples. Follow
27
27
  - **Scope.** A proposed EX must be implied by an existing BR, an existing AC or
28
28
  the request; otherwise the session drops it.
29
29
  - **Applying.** An item this invocation wrote changes directly. An item that
30
- existed before changes only under an in-force `Change request:` row whose
31
- approved change covers the change, or on the user's approval. A BF or US
32
- split, merge, creation or retirement is put to the user. Under `--contract`,
33
- a story change asks for a wider change request. Rewrite the affected BRs
34
- afterwards.
30
+ existed before changes directly when the user's request names the change, and
31
+ otherwise is put to the user as a critical decision. A BF or US split, merge,
32
+ creation or retirement is put to the user. Under `--contract`, a story change
33
+ is put to the user. Rewrite the affected BRs afterwards.
35
34
  - **Stop.** At most two cycles; a cycle that adopts nothing ends the loop. A
36
- finding still undecided at the end becomes one `open-questions.md` row at
37
- TODO whose Content opens `Unadjudicated:`. No other record is written.
35
+ finding still undecided at the end becomes one `open-questions.md` row
36
+ whose Content opens `Unadjudicated:`. No other record is written.
38
37
  - **Not raised again.** A finding matching one the session decided, by kind,
39
38
  target IDs and an equal, including or included case, is not raised again,
40
- nor one a declined change request already answers.
39
+ nor one a declined change already answers.
41
40
 
42
41
  ## Passes when
43
42
 
@@ -11,7 +11,7 @@ Stage 2 of the story tree: policy and business flows.
11
11
 
12
12
  ## Reads
13
13
 
14
- - The triage decisions `sdd-triage` made, and the scope the user approved.
14
+ - The triage decisions `sdd-triage` made, and the scope it triaged.
15
15
  Write only that scope.
16
16
  - The paired templates under
17
17
  `.qfai/assistant/skill/qfai-sdd/templates/spec/01_policy/`,
@@ -32,8 +32,8 @@ Stage 2 of the story tree: policy and business flows.
32
32
  - `02_business-flow/business-flows.md` and each affected
33
33
  `business-flow-NNNN/business-flow.md`.
34
34
 
35
- Use the paired template for every file. Write only what the user approved, as
36
- `.qfai/assistant/skill/qfai-sdd/references/sdd-triage.md#a-change-to-the-story-tree`
35
+ Use the paired template for every file. Write only the triaged scope, as
36
+ `.qfai/assistant/skill/qfai-sdd/references/sdd-triage.md#critical-decisions-and-no-question-mode`
37
37
  states.
38
38
 
39
39
  ## Procedure
@@ -96,9 +96,30 @@ states.
96
96
  8. Allocate BF IDs as
97
97
  `.qfai/assistant/skill/qfai-sdd/references/sdd-triage.md#id-allocation`
98
98
  states, and add the new rows to the flow index.
99
+ 9. Parse the diagrams in the Markdown files this step wrote, as
100
+ `.qfai/assistant/step/discussion-pack/STEP.md#parse-the-diagrams` says, with
101
+ those files in place of the pack directory:
102
+ - First do steps 1 to 3 there. Where the project has no `node_modules/qfai`,
103
+ they install the release and read the parser versions from it. They
104
+ install the parser into `tmp/qfai-mermaid`, never into the project's
105
+ dependency tree.
106
+ - Then run the checker:
107
+
108
+ ```bash
109
+ node node_modules/qfai/assets/scripts/check-mermaid.mjs --tools tmp/qfai-mermaid <files written>
110
+ ```
111
+
112
+ Where step 1 installed the release, run its checker instead:
113
+
114
+ ```bash
115
+ node tmp/qfai-release/node_modules/qfai/assets/scripts/check-mermaid.mjs --tools tmp/qfai-mermaid <files written>
116
+ ```
117
+
118
+ - Fix each diagram it rejects. When the install or the run fails for
119
+ another reason, report the syntax check as not run, never as passed.
99
120
 
100
121
  ## Passes when
101
122
 
102
- Read first: the triage decisions and the scope the user approved. The step passes when
123
+ Read first: the triage decisions and the triaged scope. The step passes when
103
124
  that scope changes no policy fact, no `tech.md` entry and no flow document. The
104
125
  pass names the triage decisions it read.
@@ -11,7 +11,7 @@ Stage 3 of the story tree: stories and examples.
11
11
 
12
12
  ## Reads
13
13
 
14
- - The triage decisions `sdd-triage` made and the scope the user approved, and
14
+ - The triage decisions `sdd-triage` made and the scope it triaged, and
15
15
  the flows `sdd-flow` wrote.
16
16
  - The paired templates under
17
17
  `.qfai/assistant/skill/qfai-sdd/templates/spec/02_business-flow/business-flow-NNNN/`.
@@ -32,8 +32,8 @@ Stage 3 of the story tree: stories and examples.
32
32
  - The `// QFAI:EX-NNNN-NNNN-NN` annotation line that maps an example to an
33
33
  existing test, as procedure item 9 states, and nothing else in a test file.
34
34
 
35
- Write only what the user approved, as
36
- `.qfai/assistant/skill/qfai-sdd/references/sdd-triage.md#a-change-to-the-story-tree`
35
+ Write only the triaged scope, as
36
+ `.qfai/assistant/skill/qfai-sdd/references/sdd-triage.md#critical-decisions-and-no-question-mode`
37
37
  states.
38
38
 
39
39
  ## Procedure
@@ -45,7 +45,7 @@ states.
45
45
  `.qfai/assistant/skill/qfai-sdd/references/sdd-triage.md#capacity-before-writing`.
46
46
  Report the retired-inclusive remaining capacity and requested count, and
47
47
  stop an over-capacity batch before any dependent declaration.
48
- For an approved capacity-only sibling or actual move, read
48
+ For a capacity-only sibling or actual move the user decided, read
49
49
  `.qfai/assistant/skill/qfai-sdd/references/sdd-triage.md#capacity-partition`
50
50
  and its following complete-map procedure before the affected write.
51
51
  2. Write the story index and the three files of each affected story, each in
@@ -69,8 +69,8 @@ states.
69
69
  AC/API or Integration, and EX/other test obligations. Do not author
70
70
  acceptance tests in this step. Item 9's annotation line is not test
71
71
  authoring.
72
- 7. Retire a story by removing its directory under the change request that names
73
- it, and never recycle its IDs.
72
+ 7. Retire a story, once the user has decided it, by removing its directory, and
73
+ never recycle its IDs.
74
74
  8. Where a decision replaced a claim, such as an input, a threshold or a
75
75
  count, search the whole story tree and the contracts for the old claim
76
76
  before finishing. List each hit in the stage report, with what it now