prizmkit 1.1.129 → 1.1.131

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 (88) hide show
  1. package/bundled/VERSION.json +3 -3
  2. package/bundled/dev-pipeline/.env.example +1 -1
  3. package/bundled/dev-pipeline/prizmkit_runtime/checkpoint_state.py +445 -8
  4. package/bundled/dev-pipeline/prizmkit_runtime/runner_classification.py +87 -66
  5. package/bundled/dev-pipeline/prizmkit_runtime/runner_models.py +53 -3
  6. package/bundled/dev-pipeline/prizmkit_runtime/runner_recovery.py +55 -25
  7. package/bundled/dev-pipeline/prizmkit_runtime/runner_status.py +4 -0
  8. package/bundled/dev-pipeline/prizmkit_runtime/runners.py +15 -1
  9. package/bundled/dev-pipeline/scripts/generate-bootstrap-prompt.py +398 -6
  10. package/bundled/dev-pipeline/scripts/generate-bugfix-prompt.py +61 -3
  11. package/bundled/dev-pipeline/scripts/generate-refactor-prompt.py +64 -4
  12. package/bundled/dev-pipeline/scripts/prompt_framework.py +156 -7
  13. package/bundled/dev-pipeline/scripts/update-bug-status.py +53 -0
  14. package/bundled/dev-pipeline/scripts/update-checkpoint.py +294 -69
  15. package/bundled/dev-pipeline/scripts/update-feature-status.py +57 -0
  16. package/bundled/dev-pipeline/scripts/update-refactor-status.py +53 -0
  17. package/bundled/dev-pipeline/templates/bootstrap-prompt.md +2 -2
  18. package/bundled/dev-pipeline/templates/bootstrap-tier3.md +20 -14
  19. package/bundled/dev-pipeline/templates/bugfix-bootstrap-prompt.md +21 -4
  20. package/bundled/dev-pipeline/templates/refactor-bootstrap-prompt.md +18 -0
  21. package/bundled/dev-pipeline/templates/sections/bugfix-phase-diagnose-plan.md +1 -1
  22. package/bundled/dev-pipeline/templates/sections/bugfix-phase-review.md +5 -15
  23. package/bundled/dev-pipeline/templates/sections/bugfix-phase-test.md +21 -0
  24. package/bundled/dev-pipeline/templates/sections/checkpoint-system.md +10 -10
  25. package/bundled/dev-pipeline/templates/sections/headless-commit-authorization.md +16 -0
  26. package/bundled/dev-pipeline/templates/sections/phase-prizmkit-test.md +26 -23
  27. package/bundled/dev-pipeline/templates/sections/phase-review-full.md +12 -8
  28. package/bundled/dev-pipeline/templates/sections/refactor-phase-review.md +1 -1
  29. package/bundled/dev-pipeline/templates/sections/refactor-phase-test.md +21 -0
  30. package/bundled/dev-pipeline/tests/test_checkpoint_state.py +362 -3
  31. package/bundled/dev-pipeline/tests/test_generate_bootstrap_prompt.py +404 -24
  32. package/bundled/dev-pipeline/tests/test_generate_bugfix_prompt.py +132 -0
  33. package/bundled/dev-pipeline/tests/test_generate_refactor_prompt.py +91 -0
  34. package/bundled/dev-pipeline/tests/test_python_runner_parity.py +411 -18
  35. package/bundled/dev-pipeline/tests/test_unified_cli.py +3 -3
  36. package/bundled/skills/_metadata.json +62 -25
  37. package/bundled/skills/app-planner/SKILL.md +4 -3
  38. package/bundled/skills/bug-fix-workflow/SKILL.md +89 -180
  39. package/bundled/skills/bug-planner/SKILL.md +12 -27
  40. package/bundled/skills/bugfix-pipeline-launcher/SKILL.md +131 -220
  41. package/bundled/skills/bugfix-pipeline-launcher/references/configuration.md +36 -90
  42. package/bundled/skills/feature-pipeline-launcher/SKILL.md +129 -271
  43. package/bundled/skills/feature-pipeline-launcher/references/configuration.md +35 -76
  44. package/bundled/skills/feature-planner/SKILL.md +27 -22
  45. package/bundled/skills/feature-planner/assets/planning-guide.md +4 -4
  46. package/bundled/skills/feature-workflow/SKILL.md +94 -121
  47. package/bundled/skills/prizmkit/SKILL.md +130 -94
  48. package/bundled/skills/prizmkit/references/workflow-state-protocol.md +181 -0
  49. package/bundled/skills/prizmkit-code-review/SKILL.md +114 -84
  50. package/bundled/skills/prizmkit-code-review/references/review-report-template.md +1 -1
  51. package/bundled/skills/prizmkit-code-review/references/workflow-state-protocol.md +181 -0
  52. package/bundled/skills/prizmkit-committer/SKILL.md +131 -47
  53. package/bundled/skills/prizmkit-committer/references/workflow-state-protocol.md +181 -0
  54. package/bundled/skills/prizmkit-implement/SKILL.md +99 -73
  55. package/bundled/skills/prizmkit-implement/references/implementation-subagent-procedure.md +1 -1
  56. package/bundled/skills/prizmkit-implement/references/workflow-state-protocol.md +181 -0
  57. package/bundled/skills/prizmkit-init/SKILL.md +5 -5
  58. package/bundled/skills/prizmkit-plan/SKILL.md +132 -105
  59. package/bundled/skills/prizmkit-plan/references/workflow-state-protocol.md +181 -0
  60. package/bundled/skills/prizmkit-retrospective/SKILL.md +111 -53
  61. package/bundled/skills/prizmkit-retrospective/references/knowledge-injection-steps.md +7 -6
  62. package/bundled/skills/prizmkit-retrospective/references/structural-sync-steps.md +5 -4
  63. package/bundled/skills/prizmkit-retrospective/references/workflow-state-protocol.md +181 -0
  64. package/bundled/skills/prizmkit-test/SKILL.md +28 -6
  65. package/bundled/skills/prizmkit-test/references/examples.md +1 -1
  66. package/bundled/skills/prizmkit-test/references/test-report-template.md +1 -1
  67. package/bundled/skills/prizmkit-test/references/workflow-state-protocol.md +181 -0
  68. package/bundled/skills/prizmkit-workflow/SKILL.md +266 -0
  69. package/bundled/skills/prizmkit-workflow/references/workflow-state-protocol.md +181 -0
  70. package/bundled/skills/recovery-workflow/SKILL.md +62 -241
  71. package/bundled/skills/recovery-workflow/evals/evals.json +17 -33
  72. package/bundled/skills/recovery-workflow/references/detection.md +28 -52
  73. package/bundled/skills/recovery-workflow/scripts/detect-recovery-state.py +105 -439
  74. package/bundled/skills/refactor-pipeline-launcher/SKILL.md +136 -275
  75. package/bundled/skills/refactor-pipeline-launcher/references/configuration.md +53 -88
  76. package/bundled/skills/refactor-planner/SKILL.md +12 -57
  77. package/bundled/skills/refactor-planner/references/behavior-preservation.md +111 -230
  78. package/bundled/skills/refactor-planner/references/error-recovery.md +37 -0
  79. package/bundled/skills/refactor-planner/references/planning-phases.md +11 -17
  80. package/bundled/skills/refactor-planner/scripts/validate-and-generate-refactor.py +1 -1
  81. package/bundled/skills/refactor-workflow/SKILL.md +98 -139
  82. package/bundled/templates/project-memory-template.md +4 -4
  83. package/package.json +1 -1
  84. package/src/index.js +4 -0
  85. package/src/prompts.js +10 -3
  86. package/src/scaffold.js +1 -1
  87. package/bundled/dev-pipeline/tests/test-deploy-safety.sh +0 -223
  88. package/bundled/skills/feature-pipeline-launcher/scripts/preflight-check.py +0 -462
@@ -1,55 +1,64 @@
1
1
  ---
2
2
  name: "prizmkit-code-review"
3
- description: "Review the complete current change in a bounded Main-Agent loop. Adjudicate findings with evidence, directly repair accepted findings, verify repairs, and append progress until the review converges to PASS or stops with unresolved findings as NEEDS_FIXES. (project)"
3
+ description: "Review the complete current change for a formal PrizmKit requirement in a bounded Main-Agent loop. Directly repair accepted findings, verify repairs, converge to PASS or stop with NEEDS_FIXES, and hand off to prizmkit-test. (project)"
4
4
  ---
5
5
 
6
6
  # PrizmKit Code Review
7
7
 
8
- Use one Main-Agent review loop. The current Main Agent is the only Code Review executor: it performs the complete review, filters candidate findings, repairs accepted findings, verifies the repairs, and decides the final result.
8
+ `/prizmkit-code-review` is the mandatory review stage after implementation and before the full test stage. The current Main Agent is the only Code Review executor. It owns the complete review loop: it discovers findings, adjudicates them, directly repairs accepted findings, verifies repairs, and continues until the review converges or stops safely.
9
9
 
10
10
  ## Execution Boundary
11
11
 
12
12
  - Do not delegate any part of Code Review directly or indirectly.
13
13
  - Do not invoke another review skill or review workflow from inside this skill.
14
14
  - Do not launch review work through a general-purpose execution unit or relabel it as a finder, verifier, audit, compatibility review, verification, or gap sweep.
15
- - These restrictions apply for the entire review phase, including candidate discovery, evidence checks, repair verification, and final gap analysis.
16
- - The Main Agent may directly use non-delegating read, search, edit, and test capabilities in the active workspace.
17
- - `{artifact_dir}/review-report.md` is the only persisted review artifact. Do not append separate Review Notes to `context-snapshot.md`.
15
+ - The Main Agent may directly read, search, edit, and run targeted verification in the active workspace.
16
+ - Review repairs occur before the full `/prizmkit-test` stage so final test evidence represents the final reviewed workspace.
17
+ - `{artifact_dir}/review-report.md` is the only persisted review artifact for this execution.
18
+
19
+ ## Atomic Stage Boundary
20
+
21
+ `prizmkit-code-review` owns only the complete Main-Agent review, accepted-finding repairs, and review verification. It writes its truthful terminal result and `next_stage`, then returns control. It must not invoke `prizmkit-test` or `prizmkit-implement` itself; the active orchestrator owns outer repair routing and the next-stage invocation.
18
22
 
19
23
  ## When to Use
20
24
 
21
- - After `/prizmkit-implement` as the Full path quality gate
22
- - For Fast path when behavior, impact, or the user warrants review
23
- - When the user asks to validate implementation, find defects, assess regressions, or decide commit readiness
25
+ - After `/prizmkit-implement` reports `IMPLEMENTED`.
26
+ - After implementation repairs that changed production code, runtime configuration, schema, dependencies, or public interfaces.
27
+ - When workflow state routes a formal requirement back to review after `TEST_FAIL`.
28
+ - When the user asks for a complete review or commit readiness decision.
29
+
30
+ ## When NOT to Use
24
31
 
25
- ## Input
32
+ - No valid `spec.md` and `plan.md` exist for the active requirement.
33
+ - Implementation tasks or required repair work remain incomplete.
34
+ - A test-stage environment stop is caused by availability rather than a review concern; resume from test when the environment is available.
35
+ - The request is a direct low-risk edit outside the formal requirement lifecycle.
36
+
37
+ ## Input and State
26
38
 
27
39
  | Parameter | Required | Description |
28
40
  |---|---|---|
29
- | `artifact_dir` | No | Directory containing `spec.md` and `plan.md`. Reuse a caller-provided directory; otherwise locate the current completed change artifact. |
30
-
31
- ## Required Asset
41
+ | `artifact_dir` | No | Directory containing `spec.md` and `plan.md`. Reuse the caller's directory or workflow-state value. |
42
+ | `review_scope` | No | `full` for the initial review; `delta` for a production-affecting repair after a prior review pass. |
32
43
 
33
- - `${SKILL_DIR}/references/review-report-template.md`: report lifecycle and append contract
44
+ Every invocation must reuse the same `artifact_dir`. If workflow state is missing, reconstruct it from `spec.md`, `plan.md`, `review-report.md`, the current diff, and any test evidence, and report the reconstruction.
34
45
 
35
- ## Phase 0: Initialize Report and Collect Context
46
+ ## Phase 0: Initialize Report and Reuse Current Context
36
47
 
37
- 1. Resolve `{artifact_dir}` and `{artifact_dir}/review-report.md`.
38
- 2. At the start of every execution, replace any prior report with a new execution header using the report template. The new report begins with `## Status: IN_PROGRESS` and contains no prior Final Result.
39
- 3. Read `spec.md`, `plan.md`, relevant `/prizmkit-test` evidence, `.prizmkit/prizm-docs/root.prizm`, applicable progressive docs, and project rules.
40
- 4. Inspect the complete current Git change:
41
- - staged and unstaged tracked changes;
42
- - untracked files;
43
- - deleted and renamed files;
44
- - relevant unchanged callers, dependents, contracts, and tests.
45
- 5. Review in the active workspace so dirty and untracked content is authoritative.
46
- 6. If no changes exist, append final verification and exactly one final result with `PASS`, then finish.
48
+ 1. Resolve `{artifact_dir}` and `{artifact_dir}/review-report.md` from the active requirement context.
49
+ 2. At the start of each execution, replace any prior report with a new execution header using `${SKILL_DIR}/references/review-report-template.md`.
50
+ 3. Within that execution, append progress after every review round, repair batch, final verification, and exactly one `## Final Result`.
51
+ 4. Start from the Main Agent's current requirement context and inspect the complete workspace change first: `git status --short`, the staged diff, and the unstaged diff. Include untracked, deleted, and renamed files in the review scope.
52
+ 5. Do not reread `spec.md`, `plan.md`, project rules, progressive docs, or unchanged source merely to recreate context the Main Agent already holds. Load only the missing or potentially stale material required to resolve a concrete ambiguity, verify an acceptance criterion, understand a changed contract, or reconstruct missing workflow state.
53
+ 6. Inspect unchanged callers, dependents, contracts, or tests only when the diff changes or may violate an interface, shared behavior, or regression boundary. Do not perform an unconditional repository-wide dependency sweep.
54
+ 7. For `review_scope=delta`, focus on files and behavior affected since the prior review pass and expand only across contracts implicated by that delta.
55
+ 8. If no changes exist, record final verification and `PASS` only when the current requirement context and prior implementation state prove there is nothing left to review.
47
56
 
48
57
  ## Phase 1: Main-Agent Review Loop
49
58
 
50
- The Main Agent reviews and repairs in the current context. The fixed limit is ten completed review rounds.
59
+ The Main Agent reviews the complete current change, using the active requirement context and expanding beyond the diff only when a concrete acceptance criterion, contract, dependency, or regression risk requires it.
51
60
 
52
- Track cumulative counts:
61
+ Use at most ten completed review rounds per execution. Track:
53
62
 
54
63
  ```yaml
55
64
  main_review_rounds: 0
@@ -59,85 +68,106 @@ rejected_findings: 0
59
68
  unresolved_findings: 0
60
69
  ```
61
70
 
62
- ### Review One Round
71
+ For every candidate finding:
63
72
 
64
- Each round examines the complete current change against goals, contracts, rules, callers, dependents, regression risks, and test evidence.
73
+ 1. Describe a reproducible failure scenario, affected behavior, and evidence.
74
+ 2. Classify exactly one of:
75
+ - `accepted`: evidence proves an in-scope repair is needed;
76
+ - `rejected`: evidence disproves the failure scenario;
77
+ - `unresolved`: correctness or safe repair cannot be established.
78
+ 3. Treat Missing tools, permissions, environment, or required evidence as an unresolved finding when they prevent review verification.
79
+ 4. If a repair cannot be completed safely, record an unresolved finding and return `NEEDS_FIXES`.
80
+ 5. Append the review round to `review-report.md`.
65
81
 
66
- 1. Identify concrete candidate findings. A finding must describe a reproducible failure scenario, affected behavior, and supporting evidence.
67
- 2. Classify each candidate as exactly one of:
68
- - `accepted`: concrete evidence supports the failure scenario and an in-scope repair is required;
69
- - `rejected`: code, tests, contracts, or governing evidence disproves the failure scenario;
70
- - `unresolved`: correctness cannot be established or repaired safely with the available evidence or environment.
71
- 3. Treat Missing tools, permissions, environment, or required evidence as an unresolved finding when they prevent required verification. Do not treat missing evidence as success.
72
- 4. Append `## Main Review Round N` with findings, accepted, rejected, unresolved, and the next action.
73
- 5. Apply these rules:
82
+ Round behavior:
74
83
 
75
84
  ```text
76
- accepted = 0 and unresolved = 0 -> review converged
77
- accepted > 0 and round < 10 -> Main Agent directly repairs, verifies, and continues
78
- accepted > 0 at ten completed review rounds -> NEEDS_FIXES
79
- unresolved > 0 -> NEEDS_FIXES
80
- repair cannot be completed safely -> unresolved finding -> NEEDS_FIXES
81
- required verification fails or cannot be performed -> unresolved finding -> NEEDS_FIXES
82
- ```
85
+ accepted = 0 and unresolved = 0
86
+ review converged
87
+ → when all candidate findings are rejected, accepted remains 0 and the review converges
83
88
 
84
- When all candidate findings are rejected, `accepted = 0` and `unresolved = 0`, so the review converges. Rejected findings do not cause another round.
89
+ accepted > 0 and rounds remain
90
+ → Main Agent directly repairs accepted findings
91
+ → targeted verification
92
+ → next complete review round
93
+
94
+ unresolved > 0 or safe repair impossible
95
+ → NEEDS_FIXES
96
+
97
+ maximum ten completed rounds reached with accepted findings
98
+ → NEEDS_FIXES
99
+ ```
85
100
 
86
101
  ## Phase 2: Repair and Verification
87
102
 
88
- When a round has accepted findings and fewer than ten rounds have completed:
103
+ For accepted findings while the round limit remains:
89
104
 
90
- 1. Main Agent directly repairs every accepted in-scope finding in the active workspace.
91
- 2. Run targeted tests, static checks, or other verification appropriate to each repaired behavior.
92
- 3. Inspect resulting changes and ensure the repair did not introduce a new regression.
93
- 4. Append `## Repair Verification` with fixed findings, verification evidence, and the next round.
94
- 5. Start the next complete review round.
105
+ 1. Repair directly in the active workspace.
106
+ 2. Run targeted tests, static checks, or other verification appropriate to each repair.
107
+ 3. Inspect the complete resulting diff for unrelated changes and regressions.
108
+ 4. Append repair verification and continue the review loop.
95
109
 
96
- If a repair is unsafe, incomplete, or cannot receive required verification, record the affected finding as unresolved and finish with `NEEDS_FIXES`.
110
+ Do not run the full auditable testing protocol as a substitute for this review stage. The full testing stage follows only after review `PASS`.
97
111
 
98
- ## Phase 3: Append-Only Reporting
112
+ If a repair is unsafe, incomplete, or unverifiable, record an unresolved finding and finish with `NEEDS_FIXES`.
99
113
 
100
- `{artifact_dir}/review-report.md` is the only required persisted review artifact.
114
+ ## Phase 3: Final Result
101
115
 
102
- Within one execution, append new sections only. Do not rewrite an earlier progress section. Append after:
116
+ Before completing:
103
117
 
104
- - every Main-Agent review round;
105
- - every repair and verification batch;
106
- - final verification;
107
- - the final result.
118
+ 1. Confirm the final workspace is the complete reviewed change.
119
+ 2. Confirm all accepted findings are fixed and no unresolved finding remains for `PASS`.
120
+ 3. Append final verification and exactly one final result.
108
121
 
109
- An interrupted execution remains `IN_PROGRESS` and shows its latest completed phase. It has no terminal verdict.
122
+ Valid results:
110
123
 
111
- ## Phase 4: Final Verification and Result
124
+ ```text
125
+ PASS | NEEDS_FIXES
126
+ ```
112
127
 
113
- Before completing:
128
+ `PASS` requires review convergence, no unresolved findings, and credible targeted verification. `NEEDS_FIXES` means an outer implementation repair is required or completion must stop safely.
129
+
130
+ ## Workflow State and Outer Repair Routing
131
+
132
+ Before reading or updating workflow state, read `${SKILL_DIR}/references/workflow-state-protocol.md`.
133
+
134
+ On `PASS`, update workflow state:
114
135
 
115
- 1. Confirm the final workspace still represents the complete reviewed change.
116
- 2. Confirm required tests and checks have credible evidence.
117
- 3. Confirm no accepted or unresolved finding remains for `PASS`.
118
- 4. Append `## Final Verification`.
119
- 5. Append exactly one final result:
120
-
121
- ```markdown
122
- ## Final Result
123
-
124
- - Verdict: PASS | NEEDS_FIXES
125
- - Main Review Rounds: <count>
126
- - Accepted Findings: <count>
127
- - Fixed Findings: <count>
128
- - Rejected Findings: <count>
129
- - Unresolved Findings: <count>
130
- - Summary: <concise conclusion>
136
+ ```json
137
+ {
138
+ "stage": "code-review",
139
+ "status": "REVIEW_PASS",
140
+ "stage_result": "PASS",
141
+ "completed_stages": ["plan", "implement", "code-review"],
142
+ "next_stage": "test",
143
+ "resume_from": "prizmkit-test"
144
+ }
131
145
  ```
132
146
 
133
- Final outcomes:
147
+ On `NEEDS_FIXES` caused by code findings, update workflow state:
148
+
149
+ ```json
150
+ {
151
+ "stage": "code-review",
152
+ "status": "REVIEW_NEEDS_FIXES",
153
+ "stage_result": "NEEDS_FIXES",
154
+ "repair_scope": "production",
155
+ "next_stage": "implement",
156
+ "resume_from": "prizmkit-implement"
157
+ }
158
+ ```
159
+
160
+ Increment the outer `repair_round` only when returning to implementation; the review-internal ten-round loop never increments it. The outer workflow permits at most three repair rounds and must return a truthful unresolved `NEEDS_FIXES` result instead of beginning a fourth.
161
+
162
+ ## Handoff
134
163
 
135
- - `PASS`: review converged with `accepted = 0`, `unresolved = 0`, and required verification evidence is complete.
136
- - `NEEDS_FIXES`: round ten still has accepted findings, any finding remains unresolved, a repair cannot be completed safely, or required verification is unavailable or failed.
164
+ After `PASS`:
137
165
 
138
- Exactly one final result is allowed. Do not append progress after Final Result.
166
+ ```text
167
+ REVIEW_PASS
168
+ → /prizmkit-test
169
+ ```
139
170
 
140
- Completion handoff:
171
+ If workflow state names an active `orchestrator`, return `REVIEW_PASS`, the report/state paths, and `next_stage=test` to it; do not invoke test independently. For direct stage use, report the exact `/prizmkit-test` invocation and same `artifact_dir`; a host may perform that semantic handoff on the user's behalf.
141
172
 
142
- - `PASS`: run `/prizmkit-retrospective` when structural docs or durable knowledge changed; otherwise proceed to `/prizmkit-committer`.
143
- - `NEEDS_FIXES`: report unresolved findings and stop.
173
+ After `NEEDS_FIXES`, stop and hand off to `/prizmkit-implement`; do not test or commit the unrepaired production change.
@@ -74,4 +74,4 @@ Exactly one Final Result terminates a completed execution:
74
74
  - An IN_PROGRESS report without Final Result is incomplete.
75
75
  - Generic or incidental verdict text outside the last Final Result does not prove completion.
76
76
  - Do not append any section after Final Result.
77
- - Do not persist a separate review-state JSON file.
77
+ - A separate review-state JSON file is not required; the shared workflow state under `.prizmkit/state/workflows/` may record lifecycle handoff and recovery metadata.
@@ -0,0 +1,181 @@
1
+ # PrizmKit Workflow State Protocol
2
+
3
+ `workflow-state.json` is lifecycle runtime metadata for one formal requirement. It preserves stage handoff, repair routing, orchestrator ownership, and resume information without replacing authoritative artifacts or any host-owned execution checkpoint.
4
+
5
+ ## Location and Identity
6
+
7
+ ```text
8
+ .prizmkit/state/workflows/<requirement-slug>.json
9
+ ```
10
+
11
+ The state file is created only when a lifecycle runs. The active `artifact_dir` is the generic requirement artifact root and must be preserved exactly across every stage:
12
+
13
+ ```text
14
+ .prizmkit/specs/<requirement-slug>/
15
+ .prizmkit/bugfix/<bug-id>/
16
+ .prizmkit/refactor/<refactor-id>/
17
+ ```
18
+
19
+ Never select a different most-recent plan when resuming or handing off. Any execution checkpoint maintained by an external host remains separate from this lifecycle state. Never merge, substitute, or infer one schema from the other. The target project controls whether generated `.prizmkit/` files are committed, ignored, or shared.
20
+
21
+ ## Authority
22
+
23
+ The state file is an index, not the authority for stage completion:
24
+
25
+ | Information | Authority |
26
+ |---|---|
27
+ | Requirement goals and acceptance criteria | `{artifact_dir}/spec.md` |
28
+ | Implementation tasks and completion | `{artifact_dir}/plan.md` plus current workspace |
29
+ | Review findings and verdict | `{artifact_dir}/review-report.md` final result |
30
+ | Test execution, verdict, and repair scope | Validated evidence package and authoritative `verdict.json` |
31
+ | Test report presentation | `{artifact_dir}/test-report.md` as a derived view only |
32
+ | Retrospective completion and result | `{artifact_dir}/retrospective-result.json` |
33
+ | Durable architecture knowledge | `.prizmkit/prizm-docs/` |
34
+ | Local commit | Git history and confirmed or authorized commit identity |
35
+ | Current stage, orchestrator, and resume entry | Workflow state |
36
+ | External orchestration progress | The external host's own checkpoint, never this state |
37
+
38
+ Every consumer compares workflow state with authoritative artifacts and the current workspace. Missing or stale state is reconstructed from those sources and is never accepted as success by itself.
39
+
40
+ ## Schema
41
+
42
+ ```json
43
+ {
44
+ "schema_version": 1,
45
+ "artifact_dir": ".prizmkit/specs/example",
46
+ "orchestrator": "prizmkit-workflow",
47
+ "stage": "test",
48
+ "status": "TEST_PASS",
49
+ "stage_result": "TEST_PASS",
50
+ "completed_stages": ["plan", "implement", "code-review", "test"],
51
+ "repair_scope": null,
52
+ "repair_round": 0,
53
+ "next_stage": "retrospective",
54
+ "resume_from": "prizmkit-retrospective"
55
+ }
56
+ ```
57
+
58
+ ### Fields
59
+
60
+ | Field | Meaning |
61
+ |---|---|
62
+ | `schema_version` | State schema version. Current value is `1`. |
63
+ | `artifact_dir` | The single generic requirement artifact root reused by every stage. |
64
+ | `orchestrator` | `prizmkit-workflow`, another semantic coordinator identifier, or `null` for direct stage use. |
65
+ | `stage` | The stage that most recently wrote state. |
66
+ | `status` | Lifecycle progression status, distinct from the domain `stage_result`. |
67
+ | `stage_result` | Domain result such as `PASS`, `NEEDS_FIXES`, `TEST_*`, `DOCS_UPDATED`, or `NO_DOC_CHANGE`. |
68
+ | `completed_stages` | Ordered stages completed for this requirement. |
69
+ | `repair_scope` | `null`, `test-infrastructure`, `production`, `runtime`, `schema`, `dependency`, `public-interface`, or `unknown`. |
70
+ | `repair_round` | Outer cross-stage repair round, from `0` through `3`. |
71
+ | `next_stage` | Next semantic stage, or `null` after commit. |
72
+ | `resume_from` | Exact atomic skill that can resume, or `null` after commit. |
73
+
74
+ ## Lifecycle and Verdict Mappings
75
+
76
+ The mandatory formal lifecycle is:
77
+
78
+ ```text
79
+ PLAN_READY
80
+ → IMPLEMENTED
81
+ → REVIEW_PASS
82
+ → TEST_PASS
83
+ → RETRO_COMPLETE
84
+ → COMMIT_PENDING
85
+ → COMMITTED
86
+ ```
87
+
88
+ No formal stage is silently optional. Domain evidence maps as follows:
89
+
90
+ ```text
91
+ review-report final PASS → status=REVIEW_PASS, stage_result=PASS
92
+ review-report final NEEDS_FIXES → status=REVIEW_NEEDS_FIXES, stage_result=NEEDS_FIXES
93
+ validated verdict TEST_PASS → status=TEST_PASS, stage_result=TEST_PASS
94
+ validated verdict TEST_FAIL → status=TEST_FAIL, stage_result=TEST_FAIL
95
+ validated verdict TEST_BLOCKED → status=TEST_BLOCKED, stage_result=TEST_BLOCKED
96
+ retrospective result DOCS_UPDATED → status=RETRO_COMPLETE, stage_result=DOCS_UPDATED
97
+ retrospective result NO_DOC_CHANGE → status=RETRO_COMPLETE, stage_result=NO_DOC_CHANGE
98
+ ```
99
+
100
+ `RETRO_COMPLETE` is the stable completion status. `DOCS_UPDATED` and `NO_DOC_CHANGE` are mutually exclusive retrospective results, not substitute statuses. A derived Markdown test report never establishes a `TEST_*` status without validated authoritative evidence.
101
+
102
+ ## Repair Routing
103
+
104
+ ```text
105
+ REVIEW_NEEDS_FIXES
106
+ → implement
107
+ → code-review
108
+ → test
109
+
110
+ TEST_FAIL with repair_scope=test-infrastructure
111
+ → implement
112
+ → test
113
+
114
+ TEST_FAIL with repair_scope=production|runtime|schema|dependency|public-interface
115
+ → implement
116
+ → code-review
117
+ → test
118
+
119
+ TEST_FAIL with repair_scope=unknown
120
+ → conservative production route only when safe
121
+ → otherwise WORKFLOW_BLOCKED
122
+
123
+ TEST_BLOCKED
124
+ → never make speculative production edits
125
+ → interactive execution stops with a prizmkit-test resume entry
126
+ → a trusted headless host may perform bounded environment recovery, then records WORKFLOW_BLOCKED if unresolved
127
+
128
+ RETRO_BLOCKED
129
+ → WORKFLOW_BLOCKED
130
+ WORKFLOW_BLOCKED
131
+ → resume only after the recorded blocker is resolved
132
+ ```
133
+
134
+ The outer workflow permits at most three automatic repair rounds. These are cross-stage rounds (`repair_round` `0` through `3`). The code-review internal loop permits at most ten completed review rounds and is separate; review-internal repairs do not increment the outer counter.
135
+
136
+ ## Orchestrator Ownership and Handoff
137
+
138
+ 1. An atomic stage performs only its own stage, writes the truthful terminal result and `next_stage`, and returns control.
139
+ 2. When `orchestrator` is non-null, only that orchestrator invokes the next skill. The atomic stage must not auto-invoke it again.
140
+ 3. Direct stage use may report one deterministic next invocation but does not claim the next stage ran.
141
+ 4. Every handoff preserves the same `artifact_dir`.
142
+ 5. External automation invokes atomic stages directly and does not invoke `prizmkit-workflow` as a nested coordinator.
143
+ 6. Workflow state never replaces or absorbs an external host's checkpoint.
144
+
145
+ ## Commit Authorization
146
+
147
+ Interactive execution:
148
+
149
+ ```text
150
+ committer previews intended files and message
151
+ → waits for explicit confirmation from the current user
152
+ → creates the local commit
153
+ ```
154
+
155
+ Trusted headless execution:
156
+
157
+ ```text
158
+ a trusted host explicitly authorizes the current local task commit
159
+ → host injects mode=<host-defined-headless-mode>, owner=<trusted-host-identifier>,
160
+ local_commit_authorized=true, push_authorized=false
161
+ → committer verifies gates and commits automatically
162
+ → no question, wait, or push is permitted
163
+ ```
164
+
165
+ A self-declared or otherwise untrusted headless context does not authorize a commit. Push is never implied by either mode.
166
+
167
+ ## Recovery
168
+
169
+ When state is missing, stale, or inconsistent:
170
+
171
+ 1. Read `spec.md` and `plan.md` from `artifact_dir` only when they are not already available in current context.
172
+ 2. Inspect task markers and the current workspace.
173
+ 3. Read the latest review report and final result when needed to establish review authority.
174
+ 4. Validate authoritative test evidence and `repair_scope`.
175
+ 5. Validate `retrospective-result.json` when retrospective is claimed complete.
176
+ 6. Verify the commit when commit is claimed complete.
177
+ 7. When an external host is active, let that host validate its own checkpoint independently; never merge the schemas.
178
+ 8. Reconstruct the latest safe predecessor and report the reconstruction.
179
+ 9. Continue only from the first incomplete or invalid stage.
180
+
181
+ Stale state never bypasses review, testing, retrospective, commit authorization, or external host checkpoint enforcement.