@haposoft/cafekit 0.16.0-rc.2 → 0.16.0-rc.4

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__/codex-hooks.test.js +794 -21
  2. package/bin/__tests__/codex-native.test.js +228 -7
  3. package/bin/__tests__/develop-contract.test.js +1838 -112
  4. package/bin/__tests__/installer-safety.test.js +82 -29
  5. package/bin/__tests__/opencode-spec-gate.test.js +799 -0
  6. package/bin/__tests__/package-inventory.test.js +841 -10
  7. package/bin/__tests__/specs-v2-execution-closeout.test.js +421 -0
  8. package/bin/__tests__/specs-v2-policy-and-scaffold.test.js +601 -0
  9. package/bin/__tests__/specs-v2-validator-grounder-contract.test.js +952 -0
  10. package/bin/__tests__/test-runtime-dependency-closure.cjs +182 -0
  11. package/bin/__tests__/validator-grounding.test.js +2469 -71
  12. package/bin/lib/managed-writer.js +12 -3
  13. package/bin/phases/codex-runtime.js +17 -1
  14. package/package.json +1 -1
  15. package/src/claude/CLAUDE.md +6 -0
  16. package/src/claude/agents/code-auditor.md +20 -0
  17. package/src/claude/agents/spec-maker.md +153 -202
  18. package/src/claude/hooks/__tests__/completion-authority.test.js +953 -0
  19. package/src/claude/hooks/__tests__/privacy-block.test.js +172 -0
  20. package/src/claude/hooks/__tests__/semantic-review-authority.test.js +257 -0
  21. package/src/claude/hooks/__tests__/spec-gate.test.js +604 -56
  22. package/src/claude/hooks/completion-authority-check.cjs +56 -0
  23. package/src/claude/hooks/completion-authority-state.cjs +527 -0
  24. package/src/claude/hooks/completion-authority.cjs +154 -0
  25. package/src/claude/hooks/docs-sync.cjs +5 -2
  26. package/src/claude/hooks/lib/privacy-command-analysis.cjs +393 -0
  27. package/src/claude/hooks/lib/runtime-path-safety.cjs +119 -0
  28. package/src/claude/hooks/privacy-block.cjs +77 -30
  29. package/src/claude/hooks/semantic-review-authority.cjs +152 -0
  30. package/src/claude/hooks/session.cjs +33 -19
  31. package/src/claude/hooks/spec-gate.cjs +181 -139
  32. package/src/claude/hooks/spec-state.cjs +112 -47
  33. package/src/claude/migration-manifest.json +15 -2
  34. package/src/claude/rules/state-sync.md +52 -21
  35. package/src/claude/rules/workflow.md +17 -9
  36. package/src/claude/scripts/provenance.cjs +315 -0
  37. package/src/claude/scripts/spec-final-state.cjs +244 -0
  38. package/src/claude/scripts/spec-ground.cjs +535 -173
  39. package/src/claude/scripts/spec-readiness.cjs +118 -0
  40. package/src/claude/scripts/spec-receipt.cjs +162 -0
  41. package/src/claude/scripts/spec-resolver.cjs +501 -0
  42. package/src/claude/scripts/spec-scaffold.cjs +1945 -55
  43. package/src/claude/scripts/spec-semantic-model.cjs +396 -0
  44. package/src/claude/scripts/validate-spec-output.cjs +3204 -262
  45. package/src/claude/scripts/workflow-policy.cjs +1888 -203
  46. package/src/claude/settings/settings.json +12 -0
  47. package/src/claude/skills/code-review/SKILL.md +94 -66
  48. package/src/claude/skills/code-review/references/spec-compliance-review.md +10 -2
  49. package/src/claude/skills/code-review/references/verification-gate.md +13 -0
  50. package/src/claude/skills/develop/SKILL.md +138 -283
  51. package/src/claude/skills/develop/references/parallel-waves.md +9 -6
  52. package/src/claude/skills/develop/references/quality-gate.md +123 -148
  53. package/src/claude/skills/develop/references/subagent-patterns.md +42 -37
  54. package/src/claude/skills/specs/SKILL.md +192 -397
  55. package/src/claude/skills/specs/references/ask-user-question-gates.md +27 -18
  56. package/src/claude/skills/specs/references/cross-spec-dependency.md +8 -4
  57. package/src/claude/skills/specs/references/research-strategy.md +4 -1
  58. package/src/claude/skills/specs/references/review.md +200 -260
  59. package/src/claude/skills/specs/references/scope-inquiry.md +18 -5
  60. package/src/claude/skills/specs/rules/design-discovery-full.md +33 -81
  61. package/src/claude/skills/specs/rules/design-discovery-light.md +21 -42
  62. package/src/claude/skills/specs/rules/design-principles.md +136 -180
  63. package/src/claude/skills/specs/rules/design-review.md +42 -97
  64. package/src/claude/skills/specs/rules/ears-format.md +42 -50
  65. package/src/claude/skills/specs/rules/phase-decision-matrix.md +42 -41
  66. package/src/claude/skills/specs/rules/task-scoring-rubric.md +46 -46
  67. package/src/claude/skills/specs/rules/tasks-generation.md +189 -271
  68. package/src/claude/skills/specs/templates/design.md +49 -263
  69. package/src/claude/skills/specs/templates/requirements.md +26 -36
  70. package/src/claude/skills/specs/templates/research.md +9 -98
  71. package/src/claude/skills/specs/templates/spec-state.json +26 -67
  72. package/src/claude/skills/specs/templates/task.md +30 -82
  73. package/src/claude/skills/sync/SKILL.md +45 -15
  74. package/src/claude/skills/sync/references/sync-protocols.md +34 -16
  75. package/src/claude/skills/test/SKILL.md +151 -167
  76. package/src/codex/AGENTS.md +6 -0
  77. package/src/codex/hooks/completion-authority-check.cjs +63 -0
  78. package/src/codex/hooks/completion-authority-state.cjs +527 -0
  79. package/src/codex/hooks/completion-authority.cjs +106 -0
  80. package/src/codex/hooks/lib/hook-context.cjs +58 -4
  81. package/src/codex/hooks/lib/privacy-command-analysis.cjs +3 -0
  82. package/src/codex/hooks/lib/privacy-state.cjs +38 -16
  83. package/src/codex/hooks/lib/runtime-path-safety.cjs +3 -0
  84. package/src/codex/hooks/lib/spec-receipt.cjs +86 -115
  85. package/src/codex/hooks/lib/spec-utils.cjs +104 -27
  86. package/src/codex/hooks/privacy-approval.cjs +1 -1
  87. package/src/codex/hooks/privacy-block.cjs +67 -11
  88. package/src/codex/hooks/semantic-review-authority.cjs +130 -0
  89. package/src/codex/hooks/session.cjs +2 -0
  90. package/src/codex/hooks/spec-gate.cjs +151 -24
  91. package/src/codex/hooks/spec-state.cjs +65 -12
  92. package/src/codex/hooks/state.cjs +2 -0
  93. package/src/codex/hooks.json +16 -1
  94. package/src/codex/rules/state-sync.md +47 -27
  95. package/src/common/AGENTS.md +1 -1
  96. package/src/opencode/AGENTS.md +4 -2
  97. package/src/opencode/plugins/spec-gate.ts +296 -122
  98. package/src/opencode/plugins/spec-state.ts +183 -116
@@ -42,6 +42,10 @@
42
42
  "type": "command",
43
43
  "command": "node \"$CLAUDE_PROJECT_DIR/.claude/hooks/rules.cjs\""
44
44
  },
45
+ {
46
+ "type": "command",
47
+ "command": "node \"$CLAUDE_PROJECT_DIR/.claude/hooks/completion-authority.cjs\""
48
+ },
45
49
  {
46
50
  "type": "command",
47
51
  "command": "node \"$CLAUDE_PROJECT_DIR/.claude/hooks/spec-state.cjs\""
@@ -106,6 +110,10 @@
106
110
  "type": "command",
107
111
  "command": "node \"$CLAUDE_PROJECT_DIR/.claude/hooks/spec-gate.cjs\""
108
112
  },
113
+ {
114
+ "type": "command",
115
+ "command": "node \"$CLAUDE_PROJECT_DIR/.claude/hooks/completion-authority.cjs\""
116
+ },
109
117
  {
110
118
  "type": "command",
111
119
  "command": "node \"$CLAUDE_PROJECT_DIR/.claude/hooks/state.cjs\""
@@ -116,6 +124,10 @@
116
124
  "SubagentStop": [
117
125
  {
118
126
  "hooks": [
127
+ {
128
+ "type": "command",
129
+ "command": "node \"$CLAUDE_PROJECT_DIR/.claude/hooks/semantic-review-authority.cjs\""
130
+ },
119
131
  {
120
132
  "type": "command",
121
133
  "command": "node \"$CLAUDE_PROJECT_DIR/.claude/hooks/state.cjs\""
@@ -1,100 +1,128 @@
1
1
  ---
2
2
  name: hapo:code-review
3
- description: "Adversarial code review with technical rigor. Supports 3-Stage Protocol with ai-multimodal injection for multimodal spec compliance. Red-team analysis finds security holes, logic gaps, and architecture violations."
3
+ description: "Review a change for correctness, security, and specification compliance without owning execution proof."
4
4
  user-invocable: true
5
- when_to_use: "Invoke to review a diff for correctness and quality before merge."
5
+ when_to_use: "Use for a pending diff, commit, PR, or explicitly scoped review."
6
6
  category: dev-tools
7
- keywords: [review, diff, quality, correctness]
7
+ keywords: [review, diff, correctness, security]
8
8
  argument-hint: "[#PR | COMMIT | --pending | scope]"
9
9
  metadata:
10
10
  author: haposoft
11
- version: "1.0.0"
11
+ version: "2.0.0"
12
12
  ---
13
- # Code Review
13
+ # Code Review — correctness and compliance owner
14
14
 
15
- Adversarial code review with technical rigor, evidence-based claims, and visual/document intelligence via the `hapo:ai-multimodal` Hub.
15
+ Review evaluates correctness, security, scope, architecture, and specification
16
+ compliance. It does not execute the test suite, create a canonical execution
17
+ receipt, or turn a missing test result into a review-owned proof. `hapo:test`
18
+ owns execution proof; the single closeout owner combines both results.
16
19
 
17
- Runs during the `hapo:develop` Quality Gate (parallel to `hapo:test`), or standalone.
20
+ ## Input and depth
18
21
 
19
- ## Load First
20
- Before executing any review, firmly grasp these two pillars:
21
- - `references/spec-compliance-review.md` (Stage 1 rules)
22
- - `references/verification-gate.md` (Execution Proofs)
23
- - `references/pre-landing-checklists.md` (Stage 2 rules)
24
- - `references/adversarial-review.md` (Stage 3 rules)
22
+ With no argument, review the pending diff. Supported targets are a PR, commit,
23
+ pending changes, or an explicit path. Load only the spec and references needed
24
+ for the target.
25
25
 
26
- ## Core Principles
26
+ Select review depth from `assurance_level`, risk, and blast radius. Lane is a
27
+ derived view:
27
28
 
28
- Executable policy source: `.claude/scripts/workflow-policy.cjs` (source: `src/claude/scripts/workflow-policy.cjs`). Review outputs and consumers must use its exact `PASS | FAIL | BLOCKED` verdict enum.
29
+ - Direct: targeted correctness/security/spec check;
30
+ - Standard: bounded feature review at closeout;
31
+ - Critical: independent, adversarial review covering every required obligation.
29
32
 
30
- 1. **YAGNI**, **KISS**, **DRY** always prevail.
31
- 2. Technical correctness over social comfort. Be honest and straight to the point.
32
- 3. If Specs are provided as PDF or Design Images, do not guess — use `hapo:ai-multimodal` to verify.
33
+ Do not use file count as the depth selector. `execution_tier` is a read-only
34
+ legacy adapter and cannot choose a review sequence. The review contract has no
35
+ fixed Light/Standard/Deep sequence.
33
36
 
34
- ## Usage & Input Modes
37
+ ## Review stages
35
38
 
36
- If invoked without explicit arguments, default to reviewing recent changes (pending diff).
39
+ ### 1. Specification compliance
37
40
 
38
- | Input | Mode | Target Definition |
39
- |-------|------|--------------------|
40
- | `#123` | **PR** | Full PR diff via `gh pr diff` |
41
- | `abc1234` | **Commit** | Single commit diff via `git show` |
42
- | `--pending`| **Pending** | Staged + unstaged changes via `git diff` |
43
- | `scope` | **Path** | Specific files or directories |
41
+ Compare the diff with `scope_lock`, requirements, design contracts, active task
42
+ Outcome/Scope/Anchors and Ownership/Changes/Acceptance/Dependencies/
43
+ `Verification Plan`, typed `coordination.boundaries`, and declared
44
+ runtime reachability. Identify missing behavior,
45
+ unjustified extras, contract substitution, orphaned outputs, and incorrect
46
+ completion claims. If a design image or document carries requirements, load its
47
+ multimodal reference only when needed; do not guess from a filename.
44
48
 
45
- ## 3-Stage Adversarial Protocol
49
+ ### 2. Correctness and security
46
50
 
47
- Ensure verification walks through these three stages before delivering a final verdict.
51
+ Trace changed entrypoints and callers. Check boundary validation, error paths,
52
+ resource handling, race assumptions, secrets, authorization, persistence, and
53
+ failure recovery in proportion to risk. Apply YAGNI/KISS/DRY as maintainability
54
+ signals, not as a numeric score.
48
55
 
49
- ### Stage 1 — Spec Compliance (with `ai-multimodal` injection)
50
- Does the code match what was requested?
51
- - Read contextual spec records (markdown files).
52
- - **Multimodal Delegation:** If the spec references or provides PDF requirements, architecture diagrams, or UI mockups (images), **STOP**. Delegate to `hapo:ai-multimodal` scripts (e.g. `gemini_batch_process.py`) to parse the JSON constraints from the document, then compare the implementation against the true layout/logic constraints.
53
- - Any missing requirements? Any unjustified extras?
56
+ ### 3. Adversarial checks
54
57
 
55
- ### Stage 2 — Code Quality
56
- - Identify YAGNI, DRY, KISS violations.
57
- - Ensure readability, naming conventions, and proper component boundaries (MVC/Clean Architecture compliance).
58
- - Check for hardcoded values and missing tests.
58
+ Try empty, malformed, unauthorized, duplicate, stale, boundary, and concurrent
59
+ inputs where the changed contract makes them relevant. For Critical obligations,
60
+ review the required independent evidence and provenance. A marker such as
61
+ `Audit: PASS` is not independent evidence.
59
62
 
60
- ### Stage 3 — Adversarial Review (Red-Team)
61
- Actively try to break the code.
62
- - **Edge Case Scouting:** If the Pull Request modifies >= 5 files, activate `hapo:inspect` or call the `inspector` agent to scout where modified functions/components are imported and whether boundary errors exist before finishing the review.
63
- - Find security holes (XSS, SQL Injection, Hardcoded tokens, Exposed Secrets).
64
- - Find false assumptions, resource exhaustion loops, and race conditions.
65
- - Find unhandled edge cases (e.g. empty strings, null pointers, negative integers).
63
+ The independent-audit proof must be a durable object with exactly
64
+ `schema_version: "1"`, distinct concrete `reviewer_session_id` and
65
+ `implementation_session_id`, `expected_provenance: { base, head }` matching the
66
+ runtime binding, concrete `evidence`, and literal `verdict: "PASS"`.
67
+ `independent: true`, `PASS_WITH_WARNINGS`, missing binding, or reused session
68
+ provenance is insufficient.
66
69
 
67
- ## Output
70
+ ## Execution-proof boundary
68
71
 
69
- Your report MUST classify every finding by severity and return exactly one verdict from `PASS | FAIL | BLOCKED`. Every review verdict/output consumer MUST accept only `PASS | FAIL | BLOCKED` and reject any other value.
70
- - **PASS:** no Critical findings, no High findings, at most one Medium.
71
- - **FAIL:** one or more Critical or High findings, or two or more Medium findings.
72
- - **BLOCKED:** missing execution proof, permission, environment, or user-owned decision prevents review completion. Stop without blind retry; report blocker and required input.
72
+ Consume the current canonical receipt when available and report its identity,
73
+ scope, and caveats. Never rerun commands to manufacture proof. If execution
74
+ proof is missing, say `execution proof unavailable` and leave the overall
75
+ closeout to the test owner; do not claim PASS on the feature from review alone.
76
+ A review can still return a correctness verdict when its review inputs are
77
+ complete.
78
+
79
+ For new tasks, read proof from `receipts/<task-basename>.md`; use legacy task
80
+ `## Evidence` only as fallback. If both exist and their proof identities
81
+ conflict, fail closed. At feature closeout also consume `feature-receipt.md`.
82
+ Receipt validity never supplies approval, readiness, audit status, or product
83
+ semantics.
84
+
85
+ ## Verdict
86
+
87
+ Use the shared adapter surface exactly:
88
+
89
+ `PASS | PASS_WITH_WARNINGS | FAIL | BLOCKED`
90
+
91
+ Legacy adapter inputs may include `PASS | FAIL | BLOCKED`, but they are
92
+ normalized to the shared surface and no second enum is allowed. `PASS` means no
93
+ Critical/High correctness, security, or compliance finding. `PASS_WITH_WARNINGS`
94
+ means only documented non-blocking findings remain. `FAIL` requires remediation;
95
+ `PASS` also requires no blocking Medium finding. `PASS_WITH_WARNINGS` may carry
96
+ documented non-blocking findings. Finding count never selects depth or overrides
97
+ missing execution proof. A review `PASS_WITH_WARNINGS` remains an unfinished
98
+ closeout result; only literal `PASS` can finish a task. `BLOCKED` means the review input or a user-owned
99
+ decision is unavailable.
73
100
 
74
- Format:
75
101
  ```markdown
76
102
  # Code Review Results [hapo:code-review]
77
103
 
78
- **Verdict:** PASS | FAIL | BLOCKED
104
+ **Verdict:** PASS | PASS_WITH_WARNINGS | FAIL | BLOCKED
79
105
  **Target:** [PR | Commit | Path]
106
+ **Assurance / risk:** [canonical policy input and relevant signals]
107
+ **Execution proof:** consumed | unavailable (owned by hapo:test)
80
108
 
81
- ## Stage 1: Spec Compliance
82
- - [Issue or OK] (If visual/PDF used, mention ai-multimodal analysis result)
109
+ ## Findings
110
+ - [Critical|High|Medium|Low] path:line — issue, failure scenario, evidence,
111
+ and fix boundary.
83
112
 
84
- ## Stage 2: Code Quality
85
- - [Issue or OK]
113
+ ## Decision
114
+ - Scope/spec compliance: PASS | WARN | FAIL
115
+ - Correctness/security: PASS | WARN | FAIL
116
+ - Reachability/provenance review: PASS | WARN | FAIL
117
+ ```
86
118
 
87
- ## Stage 3: Adversarial Findings
88
- - [🔴 Critical] ...
89
- - [🟠 High] ...
90
- - [🟡 Medium] ...
91
- - [🔵 Suggestion] ...
119
+ Do not add a test command, a fabricated receipt, or an `Audit: PASS` marker to
120
+ make the review look complete. Return unresolved questions at the end.
92
121
 
93
- ## Fix Commands (Terminal ready)
94
- [List exact bash commands or SED replacements to fix the issues quickly if possible]
95
- ```
122
+ ## References
96
123
 
97
- ## Related
98
- - Parallel skill: `/hapo:test`
99
- - AI Hub: `/hapo:ai-multimodal`
100
- - Parent orchestrator: `quality-gate.md`
124
+ - `references/spec-compliance-review.md` — load for detailed scope checks.
125
+ - `references/pre-landing-checklists.md` — load for the selected risk surface.
126
+ - `references/adversarial-review.md` — load for Critical/adversarial depth.
127
+ - `references/verification-gate.md` — receipt consumption only; execution stays
128
+ with `hapo:test`.
@@ -23,11 +23,19 @@ Do not attempt a standard text-based review if the project includes Visual Specs
23
23
  - *Prompt:* "Hey `hapo:ai-multimodal`, please look at this design mockup/document and compare it with the layout/logic described in this Code. Are there any discrepancies?"
24
24
  3. If NO (Markdown Spec only): Read the spec directly and extract:
25
25
  - requirement bullets
26
- - task `Completion Criteria`
27
- - task `## Evidence` (legacy heading aliases still parse)
26
+ - task `Outcome`, `Scope`, `Anchors and Ownership`, `Changes`, `Acceptance`,
27
+ `Dependencies`, and `Verification Plan`
28
+ - typed `coordination.boundaries` as the only ownership/DAG/proof/parallel authority
29
+ - task `Verification Plan`
28
30
  - canonical contracts/invariants from `design.md`
29
31
  Then verify the changed files against those concrete obligations.
30
32
 
33
+ Execution proof is separate from the task plan. Consume
34
+ `receipts/<task-basename>.md` first and legacy `## Evidence` only as fallback;
35
+ conflicting proof identities fail closed. At final integration, consume
36
+ `feature-receipt.md`. Review never creates either receipt and never treats a
37
+ receipt as approval, readiness, audit status, or semantic judgment.
38
+
31
39
  ## 3. Verdict Scale
32
40
 
33
41
  Each Requirement in the Spec must return 1 of 3 states:
@@ -27,6 +27,19 @@ To clear the Verification Gate, you must cite one of the following concrete proo
27
27
  - **Linter Completion:** Output proving no syntax errors exist.
28
28
  - **Multimodal Visual Evidence:** `hapo:ai-multimodal` confirming that the visual rendering perfectly matches the design layout.
29
29
 
30
+ For Specs v2, accepted proof must be persisted by the test owner at
31
+ `receipts/<task-basename>.md`; legacy `## Evidence` remains fallback-only. The
32
+ receipt includes identity/path, exact command, exit/result, expected versus
33
+ observed behavior, applicable negative/reachability/artifact proof, and bound
34
+ Base/Head. Final integration uses `feature-receipt.md`. Missing final receipt is
35
+ normal before closeout, but mandatory at closeout. Neither receipt grants
36
+ approval, readiness, audit status, or product semantics.
37
+
38
+ For v2.1, the semantic receipt is reviewed input, not execution proof. It binds
39
+ exact criteria and counterexamples shaped as `criterion`, `case_kind`,
40
+ `scenario`, `expected`, `decision_refs`, and `verification_ref`. Deterministic
41
+ validator success is never a semantic-review verdict.
42
+
30
43
  ## 4. How to Handle Missing Proof
31
44
  If you are asked to review a PR or commit and no execution proof is available:
32
45
  1. **Return `BLOCKED`** and name missing commands, artifacts, permissions, or environment access.