@haposoft/cafekit 0.16.0-rc.3 → 0.16.0-rc.5

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 (98) hide show
  1. package/bin/__tests__/change-firewall.semantic-firewall.test.js +2134 -0
  2. package/bin/__tests__/codex-hooks.test.js +531 -29
  3. package/bin/__tests__/codex-native.test.js +228 -7
  4. package/bin/__tests__/develop-contract.test.js +653 -185
  5. package/bin/__tests__/finalizer-pass-gate.semantic-firewall.test.js +342 -0
  6. package/bin/__tests__/installer-safety.test.js +39 -0
  7. package/bin/__tests__/opencode-spec-gate.test.js +24 -16
  8. package/bin/__tests__/package-inventory.test.js +705 -13
  9. package/bin/__tests__/release-preflight.semantic-firewall.test.js +578 -0
  10. package/bin/__tests__/review-receipt-c2.semantic-firewall.test.js +378 -0
  11. package/bin/__tests__/specs-v2-execution-closeout.test.js +468 -0
  12. package/bin/__tests__/specs-v2-policy-and-scaffold.test.js +665 -0
  13. package/bin/__tests__/specs-v2-validator-grounder-contract.test.js +1132 -0
  14. package/bin/__tests__/test-runtime-dependency-closure.cjs +182 -0
  15. package/bin/__tests__/validator-grounding.test.js +2013 -221
  16. package/bin/lib/managed-writer.js +12 -3
  17. package/bin/phases/codex-runtime.js +17 -1
  18. package/package.json +5 -2
  19. package/src/claude/CLAUDE.md +6 -0
  20. package/src/claude/agents/code-auditor.md +20 -0
  21. package/src/claude/agents/spec-maker.md +143 -99
  22. package/src/claude/hooks/__tests__/completion-authority.test.js +321 -58
  23. package/src/claude/hooks/__tests__/privacy-block.test.js +254 -0
  24. package/src/claude/hooks/__tests__/semantic-review-authority.test.js +257 -0
  25. package/src/claude/hooks/__tests__/spec-gate.test.js +115 -40
  26. package/src/claude/hooks/completion-authority-check.cjs +37 -288
  27. package/src/claude/hooks/completion-authority-state.cjs +10 -8
  28. package/src/claude/hooks/completion-authority.cjs +13 -7
  29. package/src/claude/hooks/docs-sync.cjs +5 -2
  30. package/src/claude/hooks/lib/privacy-command-analysis.cjs +393 -0
  31. package/src/claude/hooks/lib/runtime-path-safety.cjs +119 -0
  32. package/src/claude/hooks/privacy-block.cjs +99 -28
  33. package/src/claude/hooks/semantic-review-authority.cjs +152 -0
  34. package/src/claude/hooks/spec-gate.cjs +47 -117
  35. package/src/claude/hooks/spec-state.cjs +8 -2
  36. package/src/claude/migration-manifest.json +9 -1
  37. package/src/claude/rules/state-sync.md +52 -21
  38. package/src/claude/rules/workflow.md +17 -9
  39. package/src/claude/scripts/change-firewall.cjs +1748 -0
  40. package/src/claude/scripts/spec-authoring-digest.cjs +151 -0
  41. package/src/claude/scripts/spec-authoring-validation.cjs +126 -0
  42. package/src/claude/scripts/spec-final-state.cjs +290 -0
  43. package/src/claude/scripts/spec-ground.cjs +571 -173
  44. package/src/claude/scripts/spec-readiness.cjs +425 -0
  45. package/src/claude/scripts/spec-receipt.cjs +162 -0
  46. package/src/claude/scripts/spec-resolver.cjs +67 -16
  47. package/src/claude/scripts/spec-scaffold.cjs +1594 -139
  48. package/src/claude/scripts/spec-semantic-model.cjs +396 -0
  49. package/src/claude/scripts/validate-spec-output.cjs +3110 -218
  50. package/src/claude/scripts/workflow-policy.cjs +501 -183
  51. package/src/claude/settings/settings.json +4 -0
  52. package/src/claude/skills/code-review/SKILL.md +12 -3
  53. package/src/claude/skills/code-review/references/spec-compliance-review.md +10 -2
  54. package/src/claude/skills/code-review/references/verification-gate.md +13 -0
  55. package/src/claude/skills/develop/SKILL.md +47 -60
  56. package/src/claude/skills/develop/references/parallel-waves.md +9 -6
  57. package/src/claude/skills/develop/references/quality-gate.md +19 -12
  58. package/src/claude/skills/specs/SKILL.md +183 -177
  59. package/src/claude/skills/specs/references/ask-user-question-gates.md +27 -18
  60. package/src/claude/skills/specs/references/cross-spec-dependency.md +8 -4
  61. package/src/claude/skills/specs/references/research-strategy.md +4 -1
  62. package/src/claude/skills/specs/references/review.md +214 -262
  63. package/src/claude/skills/specs/references/scope-inquiry.md +18 -5
  64. package/src/claude/skills/specs/rules/design-discovery-full.md +33 -81
  65. package/src/claude/skills/specs/rules/design-discovery-light.md +21 -42
  66. package/src/claude/skills/specs/rules/design-principles.md +136 -180
  67. package/src/claude/skills/specs/rules/design-review.md +42 -97
  68. package/src/claude/skills/specs/rules/ears-format.md +42 -50
  69. package/src/claude/skills/specs/rules/phase-decision-matrix.md +42 -41
  70. package/src/claude/skills/specs/rules/task-scoring-rubric.md +2 -1
  71. package/src/claude/skills/specs/rules/tasks-generation.md +189 -300
  72. package/src/claude/skills/specs/templates/design.md +49 -263
  73. package/src/claude/skills/specs/templates/requirements.md +26 -36
  74. package/src/claude/skills/specs/templates/research.md +9 -98
  75. package/src/claude/skills/specs/templates/spec-state.json +35 -85
  76. package/src/claude/skills/specs/templates/task.md +30 -102
  77. package/src/claude/skills/sync/SKILL.md +33 -10
  78. package/src/claude/skills/sync/references/sync-protocols.md +31 -13
  79. package/src/claude/skills/test/SKILL.md +17 -7
  80. package/src/codex/AGENTS.md +6 -0
  81. package/src/codex/hooks/completion-authority-check.cjs +43 -240
  82. package/src/codex/hooks/completion-authority-state.cjs +10 -8
  83. package/src/codex/hooks/completion-authority.cjs +13 -7
  84. package/src/codex/hooks/lib/hook-context.cjs +16 -2
  85. package/src/codex/hooks/lib/privacy-command-analysis.cjs +3 -0
  86. package/src/codex/hooks/lib/privacy-state.cjs +61 -38
  87. package/src/codex/hooks/lib/runtime-path-safety.cjs +3 -0
  88. package/src/codex/hooks/lib/spec-receipt.cjs +72 -134
  89. package/src/codex/hooks/lib/spec-utils.cjs +56 -5
  90. package/src/codex/hooks/privacy-approval.cjs +6 -2
  91. package/src/codex/hooks/privacy-block.cjs +94 -15
  92. package/src/codex/hooks/semantic-review-authority.cjs +130 -0
  93. package/src/codex/hooks/spec-gate.cjs +49 -34
  94. package/src/codex/hooks/spec-state.cjs +10 -3
  95. package/src/codex/hooks/state.cjs +2 -0
  96. package/src/codex/hooks.json +6 -1
  97. package/src/codex/rules/state-sync.md +47 -27
  98. package/src/common/AGENTS.md +1 -1
@@ -1,291 +1,243 @@
1
- # Spec Review (Red Team + Validate)
1
+ # Whole-spec semantic review v2.1
2
2
 
3
3
  ## Purpose
4
4
 
5
- Review a spec before implementation. The system auto-decides the review depth based on spec complexity — from lightweight validation interview to full adversarial red team assault.
6
-
7
- ## Spec Resolution
8
-
9
- 1. If `<feature>` argument provided → use `specs/<feature>/`
10
- 2. If not → check active spec (spec with `in_progress` status; accept legacy `in-progress` when reading existing files)
11
- 3. If nothing found → ask user to specify path
12
-
13
- ## Deterministic Validator Gate (MANDATORY)
14
-
15
- This gate is the hard source of truth for `hapo:specs --validate`. LLM red-team tables and markdown validation reports are advisory until this script passes.
16
-
17
- After resolving the spec path, run:
18
-
19
- ```bash
20
- node .claude/scripts/validate-spec-output.cjs specs/<feature>
21
- ```
22
-
23
- Required behavior:
24
- 1. Run the validator once before the final PASS decision. If it fails, copy the exact failing categories into the validation findings/blockers and fix the physical spec artifacts.
25
- 2. Red Team and Validate may continue while fixing issues, but they cannot approve the spec while validator errors remain.
26
- 3. Run the validator again after every accepted Red Team / Validate fix set and before any final verdict.
27
- 4. The final report MUST include the validator command and the final PASS/FAIL result.
28
- 5. If the validator exits non-zero, final verdict is **FAIL / BLOCKED**, `validation.status` MUST NOT become `completed`, `ready_for_implementation` MUST remain `false`, and the output MUST NOT suggest `/hapo:develop`.
29
- 6. A markdown checklist, manual QA table, or "all required sections present" claim cannot override validator failure.
30
- 7. For specs with 5+ task files, a pre-review validator PASS only proves artifact shape. It does not mean implementation can start until Red Team + Validate finish, accepted fixes are propagated, and `spec.json.validation.status` is written as `completed`.
31
-
32
- ## Auto-Decision: When to Red Team vs Validate
33
-
34
- The system evaluates the spec and picks the appropriate review mode:
35
-
36
- | Signal | Mode | Rationale |
37
- |---|---|---|
38
- | < 3 task files, no security/perf concerns | **Validate only** | Lightweight interview is sufficient |
39
- | 3-4 task files, medium complexity | **Validate only** | Interview catches most issues |
40
- | >= 5 task files | **Red Team → then Validate** | Complex enough to warrant adversarial review |
41
- | Keywords: "auth", "security", "payment", "migration", "database schema" | **Red Team → then Validate** | High-risk areas need hostile reviewers |
42
- | Keywords: "refactor", "architecture", "breaking change" | **Red Team → then Validate** | Structural changes need stress testing |
43
- | User says "quick review" or "just validate" | **Validate only** | Respect user's explicit intent |
44
- | User says "tear it apart" or "find flaws" | **Red Team only** | Respect user's explicit intent |
45
-
46
- **Important:** When both modes run, Red Team ALWAYS runs BEFORE Validate because:
47
- 1. Red Team may change the spec (added risks, removed sections)
48
- 2. Validate should confirm the FINAL spec, not a pre-review draft
49
-
50
- ## Guardrails (NON-NEGOTIABLE)
51
-
52
- These rules override any self-reasoning or optimization the system may attempt:
53
-
54
- 1. **No self-override of auto-decision.** If the table above says "Red Team → then Validate", you MUST run Red Team. You CANNOT skip it because:
55
- - A `code-auditor` previously reviewed the spec (code review ≠ spec review)
56
- - The spec "looks good" to you
57
- - You want to "save time"
58
- - Only the USER can downgrade the mode by explicitly saying "just validate" or "skip red team"
59
- 2. **No implementation code files.** This workflow produces ONLY `.md` files. If a finding requires a new shared module or config file, describe it inside the relevant `task-*.md` file. Do NOT create `.ts`, `.js`, `.py`, or any source code file.
60
- 3. **Findings must use the exact format** defined in Part A Step 5 below. No shortened or custom formats.
61
- 4. **Apply YAGNI to fixes.** When user says "configure later" or "decide later", add a single note to the task file. Do NOT generate multiple concrete implementations (e.g., 4 provider files when user only asked for abstraction).
62
- 5. **No false completion.** You MUST NOT set `validation.status = "completed"` or `ready_for_implementation = true` until a reconciliation audit proves the accepted findings and validation decisions are reflected in the physical spec artifacts.
63
- 6. **Provider drift is a real defect.** If the scope changed away from Claude/Anthropic, stale strings like `Claude API`, `Haiku`, or `haiku_reachable` in `requirements.md`, `design.md`, or `tasks/*.md` are validation failures. `research.md` may mention them only as historical comparison.
64
- 7. **Implementation-facing propagation is mandatory.** A decision that affects implementation is NOT considered applied if it only appears in `Risk Assessment`, `validate-log.md`, or `red-team-report.md`. It must update at least one of: `requirements.md`, `Canonical Contracts & Invariants`, `Context`, `Steps`, `Requirements`, `Completion Criteria`, or `Evidence`.
65
- 8. **CafeKit command dialect only.** Validation output MUST use `/hapo:develop <feature>` as the implementation handoff. Never mention `/sdd:execute-spec`, `/sdd:*`, `/work`, `/code`, `/specs <feature> --approve`, `/hapo:specs <feature> --approve`, or non-CafeKit aliases.
66
- 9. **CafeKit task filename convention only.** Task files MUST use `tasks/task-R{N}-{SEQ}-<slug>.md` with two-digit `SEQ` (for example `tasks/task-R0-01-project-scaffolding.md`). Files like `tasks/R0-1-project-scaffolding.md` are legacy/foreign format; rename them and update `spec.json.task_files`, `spec.json.task_registry`, and dependency references before passing validation.
67
- 10. **Deterministic validator is mandatory.** The final validation verdict MUST be derived from `node .claude/scripts/validate-spec-output.cjs specs/<feature>`. If that command fails, report FAIL/BLOCKED and list the script output. Do NOT report PASS.
68
-
69
- ---
70
-
71
- ## Part A: Red Team Review (Adversarial)
72
-
73
- ### 8-Step Workflow
74
-
75
- #### Step 1: Read Entire Spec
76
- - `spec.json` — metadata and scope
77
- - `requirements.md` — technical requirements
78
- - `design.md` — architectural design
79
- - `tasks/task-*.md` — all task files
80
-
81
- #### Step 2: Determine Reviewer Count
82
-
83
- | Task file count | Reviewers | Lenses |
84
- |---|---|---|
85
- | 1-2 | 2 | Security + Assumption Destroyer |
86
- | 3-5 | 3 | + Failure Mode Analyst |
87
- | 6+ | 4 | + Scope & Complexity Critic (all) |
88
-
89
- #### Step 3: Assign Analysis Lenses
90
-
91
- | Reviewer | Lens | Focus |
92
- |---|---|---|
93
- | **Security Adversary** | Attacker mindset | Auth bypass, injection, data exposure, privilege escalation, OWASP Top 10 |
94
- | **Failure Mode Analyst** | Murphy's Law | Race conditions, data loss, cascading failures, recovery gaps, rollback holes |
95
- | **Assumption Destroyer** | Skeptic | Unstated dependencies, false claims, missing error paths, scale assumptions |
96
- | **Scope & Complexity Critic** | YAGNI enforcer | Over-engineering, premature abstraction, scope creep, gold plating |
97
-
98
- #### Step 4: Spawn Reviewers in Parallel
99
- Each reviewer receives:
100
- - Their specific lens and persona
101
- - Spec file paths to read directly
102
- - Instructions: report findings only when backed by concrete citations
103
-
104
- **Reviewer instructions:**
5
+ Review the spec as one consistency graph. A structural validator exit 0 proves
6
+ only implemented structural checks; it does not prove semantic completeness,
7
+ grounding, product correctness, negative paths, or executable behavior.
8
+
9
+ ## Resolve and inventory
10
+
11
+ 1. Resolve the exact spec path; ambiguous active specs fail closed.
12
+ 2. Read final physical `spec.json`, `requirements.md`, `design.md`, optional
13
+ `research.md`, every task, and the machine-recorded semantic-review state.
14
+ 3. Confirm the physical artifact set matches `planning_depth` and its justified
15
+ optional gates:
16
+ - `None`: no durable spec;
17
+ - `Compact`: three-file core plus an optional task bundle/registry only when
18
+ ownership, dependency, durable transition, separate proof, or parallel
19
+ coordination activates the task gate;
20
+ - `Full`: the same three-file core plus only justified optional research,
21
+ task, or complex-task-graph phase metadata. Full depth
22
+ alone does not justify any optional artifact.
23
+ 4. Reject `feature-receipt.md` in spec authoring. It belongs to execution
24
+ closeout only.
25
+
26
+ ## Consistency graph
27
+
28
+ Build and inspect these edges:
29
+
30
+ ```text
31
+ scope_lock
32
+ -> outcomes/non-goals
33
+ -> RN.M acceptance
34
+ -> design boundary + typed anchors
35
+ -> named contracts/invariants
36
+ -> conditional task owners/consumers
37
+ -> verification + negative paths
38
+ -> technical readiness
105
39
  ```
106
- You are a hostile reviewer. Your job is to DESTROY this spec.
107
- Adopt the {LENS_NAME} perspective. Find every flaw you can.
108
-
109
- Rules:
110
- - Be specific: cite exact task/section where flaw lives
111
- - Be concrete: describe failure scenario, not just "could be a problem"
112
- - Rate severity: Critical (blocks success) | High (significant risk) | Medium (notable concern)
113
- - Skip trivial observations (style, naming, formatting)
114
- - No praise. No "overall looks good". Only evidence-backed findings.
115
- - Quality over quantity; do not pad to a count.
116
- ```
117
-
118
- #### Step 5: Collect → Deduplicate → Cap
119
- 1. Gather all findings from all reviewers
120
- 2. Remove duplicate or overlapping findings
121
- 3. Sort by severity: Critical → High → Medium
122
- 4. Cap at 15 findings maximum
123
-
124
- #### Step 5.5: Evidence Filter (MANDATORY — auto-reject before merit)
125
- Before adjudicating, drop any finding whose `Location`/`Evidence` does not point at a concrete spot in the spec: a task/section name (`task-R2-01... §Steps`) or a verbatim quote of the offending text. A finding that only asserts a problem in the abstract ("this might race", "auth could be bypassed") **without citing where in the spec** is auto-`Reject (no evidence)` and is NOT counted toward the cap or shown to the user.
126
-
127
- Rationale: this is the spec-level analogue of ck-plan's `file:line` evidence gate. It stops reviewers from inventing plausible-sounding flaws that aren't actually in the artifact. A real flaw can always be located; an imagined one cannot.
128
-
129
- #### Step 6: Adjudicate
130
- For each finding (that survived the Evidence Filter), evaluate and propose: **Accept** or **Reject** with rationale.
131
40
 
132
- #### Step 7: User Review
133
- Present via `AskUserQuestion`:
134
- - "Apply all accepted findings"
135
- - "Let me review each one"
136
- - "Reject all, spec is fine"
41
+ Check both directions:
42
+
43
+ - every scoped outcome reaches measurable acceptance and proof;
44
+ - every design decision traces to scope or acceptance;
45
+ - every anchor has an ID unique across the whole spec, allowed type, exact
46
+ target, and role;
47
+ - design anchors use `A-D-NN`; task-owned anchors use the canonical task-scoped
48
+ `A-R{requirement}-{sequence}-NN` namespace;
49
+ - file anchors come first and symbols identify their containing files;
50
+ - a task that only consumes a design target references its canonical `A-D-NN`
51
+ anchor instead of redefining the same target under a task-local ID;
52
+ - every named contract/invariant has one canonical definition;
53
+ - tasks reference contract IDs without copying bodies;
54
+ - every cross-task contract/transition has exactly one owner before consumers;
55
+ - every `RN.M` has exactly one implementation owner; a proof verifier owns a
56
+ separate proof criterion/artifact and does not repeat the subject's Acceptance;
57
+ - every dependency is real and Markdown agrees with `task_registry`;
58
+ - every task has one canonical `**Status:**` header using `pending`,
59
+ `in_progress`, `blocked`, or `done`, and its exact status token matches
60
+ `spec.json.task_registry[path].status`;
61
+ - every task has exactly seven H2 sections and one
62
+ `ID | Type | Target | Role | Access | Action` table;
63
+ - typed `coordination.boundaries` own topology; legacy trigger fields, priority
64
+ markers, related-file lists, and prose own nothing;
65
+ - every executable implementation task owns a concrete test file or artifact
66
+ anchor or shares proof through a typed `proof` boundary; a bare `npm test`
67
+ string without such an anchor is not ownership;
68
+ - specs-only never creates or updates docs and never fabricates execution
69
+ proof; doc impact is a brief recommendation at most;
70
+ - no task, phase, research note, or review finding expands `scope_lock`;
71
+ - optional phases exist only as compact `spec.json` groups for a complex Full
72
+ task graph and never repeat prose.
73
+ - exactly one `## Verification Definitions` section uses parser-visible lines
74
+ `- **Vn**: Criteria RN.M; Owner ...; [Proof criteria ...; Proof owner ...;
75
+ Evidence anchor ...;] Decision refs D/I/C; Method ...; Expected ...;
76
+ Negative/failure ...; Reachability/grounding ...`; the proof extension is
77
+ conditional on a typed proof boundary; tables and V headings are not canonical.
78
+
79
+ ## Counterexample review
80
+
81
+ For every `RN.M`, try at least one concrete counterexample that could
82
+ make two competent implementers choose different behavior. Use relevant lenses:
83
+
84
+ - missing/invalid input or permission;
85
+ - dependency unavailable, timeout, partial success, retry, or duplicate event;
86
+ - conflicting state, ordering, concurrency, restart, rollback, or migration;
87
+ - boundary bypass, data disclosure, retention, or authorization confusion;
88
+ - wrong clock anchor/source/timezone/precision or cutoff comparator/inclusivity or enforcement boundary for a retention/lifecycle rule (for example creation time or UTC vs local or `>` vs `>=` mismatch) that would retain or delete the wrong records;
89
+ - partial public, replay, or operator API contract (missing method, route, auth, headers, request or response schema, error semantics, or idempotency and concurrency behavior);
90
+ - orphaned route/component/worker/artifact with no runtime reachability;
91
+ - task consumer beginning before its contract/schema/transition owner;
92
+ - verification command passing while the user-visible behavior is wrong;
93
+ - an executable task with only a generic test command and no owned test file or typed proof verifier.
94
+
95
+ A counterexample passes only when requirements or design already choose the
96
+ behavior and the verification plan can distinguish the correct result. Do not
97
+ invent a product decision during review; unresolved choices require a user
98
+ decision. Two-review target is advisory: after two failed semantic rounds, pause for unresolved product/security/architecture uncertainty or repeated non-convergence; one clearly bounded mechanical correction without weakening gates is allowed; budgets never override correctness. Specs-only never creates or updates docs and never fabricates execution proof; record doc impact as a brief recommendation only.
99
+
100
+ ## Assurance depth
101
+
102
+ | Level | Required semantic review |
103
+ |---|---|
104
+ | Routine | Same-session graph check and relevant counterexamples; no reviewer ceremony. |
105
+ | Elevated | Same-session targeted adversarial review; no reviewer ceremony. |
106
+ | Strict | Full red-team plus a host-hook-observed event from an allowlisted reviewer capability. |
137
107
 
138
- If "Review each one": For each finding, ask: "Apply" | "Reject" | "Modify suggestion"
108
+ Risk presence sets the automatic minimum to Elevated. Strict is opt-in only
109
+ for an explicit user/project independent-audit requirement or a user-confirmed,
110
+ scope-specific audit decision. Never select it from a keyword, severity label,
111
+ Full depth, or reviewer availability. If the required host event is unavailable,
112
+ pause once and report the capability blocker; do not retry loops or downgrade.
139
113
 
140
- #### Step 8: Apply to Spec
141
- - Edit design.md / task files directly for accepted findings
142
- - Create `reports/red-team-report.md` documenting the full review session
143
- - Mark a finding as `Applied To = ...` only after the physical file really contains the change
114
+ Strict red-team lenses are Security Adversary, Failure Mode Analyst, Assumption
115
+ Destroyer, and Scope & Complexity Critic. Findings without a concrete physical
116
+ location and counterexample are rejected as unsupported.
144
117
 
145
- ### Finding Output Format
118
+ ## Finding format
146
119
 
147
120
  ```markdown
148
- ## Finding {N}: {title}
121
+ ## Finding N: <title>
149
122
  - **Severity:** Critical | High | Medium
150
- - **Location:** Task {X}, section "{name}"
151
- - **Flaw:** {description}
152
- - **Failure scenario:** {concrete description of how this fails}
153
- - **Evidence:** {quote from spec or missing element}
154
- - **Suggested fix:** {brief recommendation}
123
+ - **Location:** <file:line or exact section/anchor/requirement ID>
124
+ - **Broken edge:** <source -> target in the consistency graph>
125
+ - **Flaw:** <specific contradiction or omission>
126
+ - **Counterexample:** <concrete input/state/event and incorrect possible result>
127
+ - **Evidence:** <short quote or missing required mapping>
128
+ - **Suggested fix:** <smallest semantic correction>
155
129
  - **Disposition:** Accept | Reject
156
- - **Rationale:** {explanation}
130
+ - **Rationale:** <why>
157
131
  ```
158
132
 
159
- ### Red Team Summary
160
-
161
- ```markdown
162
- ## Red Team Review — {YYYY-MM-DD}
163
- **Findings:** {total} ({N} accepted, {M} rejected)
164
- **Severity breakdown:** {N} Critical, {N} High, {N} Medium
133
+ Apply accepted findings to requirements, design, task acceptance/changes, named
134
+ contracts/invariants, dependencies, or verification. A report-only fix is not a
135
+ fix. Scope or product decisions require explicit user approval before editing.
136
+
137
+ ## Deterministic and grounding gates
138
+
139
+ Finalize requirements, design, optional research, task files, and canonical
140
+ `spec.json` topology first. Every required authoring stage (`requirements`,
141
+ `design`, and, when present, `research`/`tasks`) must already read `validated`
142
+ via a fresh run of `spec-authoring-validation.cjs` — the sole atomic writer of
143
+ that transition and its C16 `AuthoringValidationReceipt` — before the digest
144
+ below is computed; a `validated` reading with no matching fresh receipt digest
145
+ is treated as `draft` everywhere it is read. Compute the candidate digest
146
+ read-only, then provide a review JSON object with exactly `verdict`,
147
+ `findings`, `unresolved_decisions`, `graph_coverage`, `reviewed_criteria`,
148
+ `counterexamples`, and `reviewer_evidence` — the frozen C2 fields the reviewer
149
+ itself supplies. `lifecycle_disposition` and `repair_round` are never authored
150
+ in this JSON: the finalizer derives both (repair_round is the C13 `attempt_index`
151
+ for the current review_epoch; lifecycle_disposition is CONTINUE unless a
152
+ non-PASS at the epoch's third attempt forces BLOCKED) and appends the completed
153
+ receipt to the durable, append-only `semantic_review_history` lineage. The
154
+ author must not fabricate or directly write authority state.
155
+
156
+ The digest projects task registry semantics as `id`, `dependencies`, and optional
157
+ `artifacts`. Execution-only status, blocker, timestamps, Markdown `Status`, and
158
+ checkbox checked state do not stale review; requirement, design, research, task
159
+ prose, dependency, artifact, or coordination changes do.
165
160
 
166
- | # | Finding | Severity | Disposition | Applied To |
167
- |---|---------|----------|-------------|------------|
168
- | 1 | {title} | Critical | Accept | task-R0-02-... |
161
+ ```bash
162
+ # Claude Code
163
+ node .claude/scripts/validate-spec-output.cjs specs/<feature> --semantic-digest
164
+ # Codex (installed projection — verify, not raw .claude path)
165
+ node .codex/scripts/validate-spec-output.cjs specs/<feature> --semantic-digest
169
166
  ```
170
167
 
171
- ---
172
-
173
- ## Part B: Validation Interview
174
-
175
- ### 8-Step Workflow
176
-
177
- #### Step 1: Read Spec
178
- - `requirements.md` — technical requirements
179
- - `design.md` — architectural design
180
- - `tasks/task-*.md` — all task files
181
- - Look for: decision points, assumptions, risks, trade-offs
182
-
183
- #### Step 2: Extract Question Topics
184
-
185
- | Category | Detection Keywords |
186
- |---|---|
187
- | **Architecture** | "approach", "pattern", "design", "structure", "database", "API" |
188
- | **Assumptions** | "assume", "expect", "should", "will", "must", "default" |
189
- | **Trade-offs** | "tradeoff", "vs", "alternative", "option", "choice" |
190
- | **Risks** | "risk", "might", "could fail", "dependency", "blocker" |
191
- | **Scope** | "phase", "MVP", "future", "out of scope", "nice to have" |
192
-
193
- #### Step 3: Generate Questions
194
- - Each question has 2-4 concrete options
195
- - Mark recommended option with "(Recommended)" suffix
196
- - "Other" option is automatically added
197
- - Questions should surface implicit decisions
198
-
199
- #### Step 4: Interview User
200
- - Use `AskUserQuestion` tool
201
- - Group max 4 questions per call
202
- - Focus on: assumptions → risks → trade-offs → architecture
203
- - If spec is simple → fewer than 3 questions is OK
204
-
205
- #### Step 5: Document Answers
206
-
207
- Save to `reports/validate-log.md`:
208
-
209
- ```markdown
210
- ## Validation Log — Session {N} — {YYYY-MM-DD}
211
- **Trigger:** {what prompted this validation session}
212
- **Questions asked:** {N}
168
+ The machine-recorded state binds the returned digest, exact reviewed `RN.M`
169
+ criteria, and one concrete counterexample per criterion. Each counterexample uses exactly `criterion`,
170
+ `case_kind`, `scenario`, `expected`, `decision_refs`, and `verification_ref`.
171
+ Decision refs resolve to real `D`/`I`/`C` definitions; the `V` definition traces
172
+ both the criterion and decisions. This state binds what was reviewed; it never
173
+ substitutes for semantic judgment or resolves ambiguity.
174
+
175
+ Routine and Elevated have no reviewer ceremony. Strict requires a real event
176
+ observed by the installed host hook from an allowlisted reviewer capability.
177
+ The hook derives reviewer identity/capability and binds the digest; authoring
178
+ prose cannot self-declare it.
179
+ The final reviewer message contains
180
+ exactly one line:
181
+
182
+ ```text
183
+ CAFEKIT_SEMANTIC_REVIEW_ATTESTATION {"feature_name":"<feature>","spec_file":"specs/<feature>/spec.json","semantic_digest":"sha256:<digest>","verdict":"PASS"}
184
+ ```
213
185
 
214
- ### Questions & Answers
186
+ The `SubagentStop` hook recomputes the digest and stores a MAC-protected record
187
+ outside the project, bound to canonical project/spec/feature identity. Codex
188
+ must use its event-capable thread-spawn path for this Strict gate. Its legacy
189
+ internal multi-agent path does not expose the child completion message through
190
+ a supported hook event, so it stays not-ready; never derive authority from a
191
+ parent summary or a spawn-only `PostToolUse` event.
192
+ Do not add reviewer identity or independence claims to `semantic_review`.
193
+ This is a host-hook-observed honest-agent guardrail. It is not host-attested
194
+ evidence and not a security boundary against another process running as the
195
+ same OS account.
215
196
 
216
- 1. **[{Category}]** {full question text}
217
- - Options: {A} | {B} | {C}
218
- - **Answer:** {user's choice}
219
- - **Custom input:** {verbatim "Other" text if applicable}
220
- - **Rationale:** {why this decision affects implementation}
197
+ After the Strict observation (or immediately for Routine/Elevated), invoke the
198
+ only supported atomic promotion path:
221
199
 
222
- ### Confirmed Decisions
223
- - {decision}: {choice} — {brief why}
200
+ ```bash
201
+ # Claude Code
202
+ node .claude/scripts/spec-readiness.cjs specs/<feature> --review-result <review.json>
203
+ # Codex (installed projection — verify, not raw .claude path)
204
+ node .codex/scripts/spec-readiness.cjs specs/<feature> --review-result <review.json>
205
+ ```
224
206
 
225
- ### Action Items
226
- - [ ] {specific change needed}
207
+ Run normal validation only after the installed finalizer records that state:
227
208
 
228
- ### Impact on Tasks
229
- - Task {N}: {what needs updating and why}
209
+ ```bash
210
+ # Claude Code
211
+ node .claude/scripts/validate-spec-output.cjs specs/<feature>
212
+ # Codex (installed projection)
213
+ node .codex/scripts/validate-spec-output.cjs specs/<feature>
230
214
  ```
231
215
 
232
- #### Step 6: Propagate Changes
233
- - Auto-update task files affected by new decisions
234
- - Add marker: `<!-- Updated: Validation Session N — {change} -->`
235
- - Change mapping:
216
+ Run the runtime-provided grounding command for every durable spec. It
217
+ deterministically recomputes factual anchor/path/symbol/command reachability and
218
+ creates no additional receipt. Record command, exit code, and failing categories.
219
+ Non-zero blocks readiness. Exit 0 does not override a broken consistency edge or
220
+ counterexample; semantic review remains mandatory at the selected assurance level.
236
221
 
237
- | Change Type | Update Target |
238
- |---|---|
239
- | Requirements | `requirements.md` |
240
- | Architecture | `design.md` |
241
- | Scope | `requirements.md` + task files |
242
- | Risk | Task files (Risk Assessment section) |
243
- | Unknown | `design.md` (add new subsection) |
244
-
245
- **Additional propagation rules:**
246
- - If the decision changes implementation behavior, update an implementation-facing section, not only `Risk Assessment`.
247
- - If the decision changes scope or provider choice, scan `requirements.md`, `design.md`, and `tasks/*.md` for stale wording and normalize it.
248
- - If the decision changes deletion/privacy behavior, update `Canonical Contracts & Invariants` first, then tasks that inherit that contract.
249
-
250
- #### Step 7: Reconciliation Audit (MANDATORY)
251
- Before declaring validation complete:
252
- 1. Re-read `spec.json`, `requirements.md`, `design.md`, and all `tasks/task-*.md`
253
- 2. Verify every accepted red-team finding and every validation action item is reflected in the correct physical file(s)
254
- 3. Run `node .claude/scripts/validate-spec-output.cjs specs/<feature>` and keep the raw result visible
255
- 4. Fail the audit if:
256
- - a report says "applied" but the file still contains the old text
257
- - stale provider strings remain after a provider change
258
- - delete-data/privacy artifacts mix multiple canonical policies
259
- - any task path fails the CafeKit `tasks/task-R{N}-{SEQ}-<slug>.md` naming convention
260
- - `spec.json.updated_at`, `timestamps.review_done`, or `timestamps.validation_done` do not reflect the final reviewed state
261
- - deterministic validator exits non-zero
262
- 5. Only after the audit passes may you:
263
- - set `spec.json.validation.status = "completed"`
264
- - set `spec.json.timestamps.validation_done`
265
- - set `spec.json.timestamps.review_done`
266
- - set `spec.json.ready_for_implementation = true` when all other gates are satisfied
267
-
268
- #### Step 8: Final Status Write-Back
269
- - Update `spec.json.updated_at` to the reconciliation time
270
- - On final PASS, set `spec.json.validation.status = "completed"`, `spec.json.timestamps.validation_done`, and, when Red Team ran, `spec.json.timestamps.review_done`
271
- - On final PASS, set `spec.json.ready_for_implementation = true` only after the deterministic validator passes on the final physical artifacts
272
- - Ensure `red-team-report.md` and `validate-log.md` do not contradict `spec.json`
273
- - If reconciliation or deterministic validation fails, keep `validation.status` as `not-run` or `in_progress`, keep `ready_for_implementation = false`, list blockers explicitly, and do not provide an implementation handoff.
274
-
275
- ---
276
-
277
- ## Combined Output
278
-
279
- When both Red Team and Validate run:
222
+ ## Final reconciliation
280
223
 
281
- ```
282
- 📋 Review Complete: specs/<feature>/
224
+ Before readiness:
283
225
 
284
- Red Team: {N} findings ({A} accepted, {R} rejected)
285
- Validate: {Q} questions asked, {D} decisions confirmed
226
+ 1. Re-read all physical artifacts after fixes.
227
+ 2. Confirm accepted findings changed implementation-facing content.
228
+ 3. Confirm requirements, globally unique anchor IDs, canonical design-anchor
229
+ references, contracts, owners/consumers, dependencies, negative paths, and
230
+ verification form a closed graph.
231
+ 4. Confirm `feature-receipt.md`, phase files, copied contract bodies, legacy
232
+ topology markers, and unused template sections are absent.
233
+ 5. Write coherent final timestamps/status and rerun deterministic gates;
234
+ readiness means technical artifact readiness, not permission to implement.
286
235
 
287
- Files modified: {list}
288
- Deterministic validator: PASS via `node .claude/scripts/validate-spec-output.cjs specs/<feature>`
236
+ If any check fails, report `FAIL` or `BLOCKED`, preserve unfinished lifecycle
237
+ state, and do not suggest implementation handoff.
289
238
 
290
- 📌 Next step: /hapo:develop <feature> (ONLY if reconciliation audit passed)
291
- ```
239
+ ## Platform acceptance
240
+
241
+ Acceptance covers Claude Code and Codex artifacts only. Verify the semantic
242
+ rules/templates installed for both runtimes remain equivalent. Do not add a
243
+ third runtime to this acceptance scope.
@@ -2,7 +2,9 @@
2
2
 
3
3
  ## Purpose
4
4
 
5
- Before investing time in planning, confirm with the user the appropriate level of investment. Avoid wasting time on deep research for simple tasks, or missing risks for complex ones.
5
+ Before investing time in planning, select the smallest scope consistent with the
6
+ request and evidence. Scope inquiry is an analysis step, not a mandatory user
7
+ question.
6
8
 
7
9
  ## Skip Conditions
8
10
 
@@ -38,7 +40,9 @@ Classify the *knowability* of the solution path:
38
40
  - **Complex**: Outcome is uncertain; solution emerges through experimentation (e.g., AI/ML tuning, novel UX interactions, performance bottleneck with unknown root cause). Requires prototyping or spike tasks before committing to a full spec.
39
41
  - **Chaotic**: No clear path; urgent stabilization needed first (e.g., production outage, data corruption). Skip spec workflow entirely — use `hapo:hotfix` instead.
40
42
 
41
- > **Rule**: If Dimension 4 = Complex or Chaotic, flag this to the user immediately. Complex tasks should include explicit spike/prototype tasks in the spec. Chaotic tasks should exit the spec workflow.
43
+ > **Rule**: If Dimension 4 = Complex, record the uncertainty and add a bounded
44
+ > spike only when it is a real dependency. Chaotic tasks exit to `hapo:hotfix`.
45
+ > Ask only when the response requires a user-owned scope or irreversible choice.
42
46
 
43
47
  ### Dimension 5: Dependency & Blast Radius
44
48
  Assess how many other parts of the system are affected if this change breaks or behaves unexpectedly:
@@ -57,11 +61,20 @@ After the qualitative 5-Dimension pass, run a quick quantitative gut-check. Thes
57
61
  - **> 12 task files** → the spec is large; consider splitting by deliverable boundary into sibling specs (cross-spec `blockedBy`) rather than one mega-spec.
58
62
  - **> 15 task files** → strong signal to split. A single mega-spec is slow to generate, prone to mid-run failure, and hard to review. Prefer 2-3 focused specs unless the work is genuinely one indivisible slice.
59
63
 
60
- If any tripwire fires, surface it in the Scope Inquiry summary and let the user decide (Expand / Hold / Reduce / Split). Do not silently build the mega-version.
64
+ If a tripwire fires, first reduce or split using the simplest reversible boundary.
65
+ HOLD and ASK only when that change would alter user-owned deliverables or scope.
66
+ Do not silently build the mega-version.
61
67
 
62
68
  ## Level Selection
63
69
 
64
- After completing the 5-Dimension Assessment, present via `AskUserQuestion`:
70
+ After the assessment, classify the remaining choice:
71
+
72
+ - Ground current size, dependencies, and blast radius as `repository_fact`.
73
+ - Choose the smallest `reversible_assumption` and record its bounded reversal.
74
+ - For a `user_owned` Expand/Hold/Reduce/Split decision, HOLD and present via
75
+ `AskUserQuestion`; unresolved scope blocks readiness.
76
+
77
+ When a user-owned choice exists, use:
65
78
 
66
79
  **Title:** "Scope Inquiry"
67
80
  **Question:** "Based on analysis, what scope level do you want?"
@@ -90,5 +103,5 @@ Scope Inquiry:
90
103
  - Blast Radius: [Isolated/Moderate/Critical Path] — [affected modules]
91
104
  - Complexity smells: [none | >8 files | >2 new services | >12 tasks → consider split | >15 tasks → split]
92
105
  - Minimum Change: [Essential gap vs Niceties]
93
- - User chose: [Expand / Hold / Reduce / Split]
106
+ - Decision: [grounded fact | reversible default + reversal boundary | user choice]
94
107
  ```