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

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 (51) hide show
  1. package/bin/__tests__/codex-hooks.test.js +355 -12
  2. package/bin/__tests__/codex-native.test.js +1 -1
  3. package/bin/__tests__/develop-contract.test.js +1374 -78
  4. package/bin/__tests__/installer-safety.test.js +43 -29
  5. package/bin/__tests__/opencode-spec-gate.test.js +791 -0
  6. package/bin/__tests__/package-inventory.test.js +157 -0
  7. package/bin/__tests__/validator-grounding.test.js +707 -2
  8. package/package.json +1 -1
  9. package/src/claude/agents/code-auditor.md +8 -1
  10. package/src/claude/agents/spec-maker.md +107 -200
  11. package/src/claude/hooks/__tests__/completion-authority.test.js +720 -0
  12. package/src/claude/hooks/__tests__/spec-gate.test.js +511 -38
  13. package/src/claude/hooks/completion-authority-check.cjs +307 -0
  14. package/src/claude/hooks/completion-authority-state.cjs +525 -0
  15. package/src/claude/hooks/completion-authority.cjs +148 -0
  16. package/src/claude/hooks/session.cjs +33 -19
  17. package/src/claude/hooks/spec-gate.cjs +173 -61
  18. package/src/claude/hooks/spec-state.cjs +104 -45
  19. package/src/claude/migration-manifest.json +6 -1
  20. package/src/claude/scripts/provenance.cjs +315 -0
  21. package/src/claude/scripts/spec-resolver.cjs +450 -0
  22. package/src/claude/scripts/spec-scaffold.cjs +716 -41
  23. package/src/claude/scripts/validate-spec-output.cjs +355 -53
  24. package/src/claude/scripts/workflow-policy.cjs +1529 -162
  25. package/src/claude/settings/settings.json +8 -0
  26. package/src/claude/skills/backend-development/references/backend-security.md +52 -0
  27. package/src/claude/skills/code-review/SKILL.md +85 -66
  28. package/src/claude/skills/develop/SKILL.md +153 -285
  29. package/src/claude/skills/develop/references/quality-gate.md +112 -124
  30. package/src/claude/skills/develop/references/subagent-patterns.md +42 -37
  31. package/src/claude/skills/specs/SKILL.md +170 -381
  32. package/src/claude/skills/specs/rules/task-scoring-rubric.md +45 -46
  33. package/src/claude/skills/specs/rules/tasks-generation.md +49 -20
  34. package/src/claude/skills/specs/templates/spec-state.json +23 -2
  35. package/src/claude/skills/specs/templates/task.md +20 -0
  36. package/src/claude/skills/sync/SKILL.md +15 -8
  37. package/src/claude/skills/sync/references/sync-protocols.md +4 -4
  38. package/src/claude/skills/test/SKILL.md +141 -167
  39. package/src/codex/hooks/completion-authority-check.cjs +260 -0
  40. package/src/codex/hooks/completion-authority-state.cjs +525 -0
  41. package/src/codex/hooks/completion-authority.cjs +100 -0
  42. package/src/codex/hooks/lib/hook-context.cjs +42 -2
  43. package/src/codex/hooks/lib/spec-receipt.cjs +76 -43
  44. package/src/codex/hooks/lib/spec-utils.cjs +53 -27
  45. package/src/codex/hooks/session.cjs +2 -0
  46. package/src/codex/hooks/spec-gate.cjs +132 -20
  47. package/src/codex/hooks/spec-state.cjs +56 -10
  48. package/src/codex/hooks.json +10 -0
  49. package/src/opencode/AGENTS.md +4 -2
  50. package/src/opencode/plugins/spec-gate.ts +296 -122
  51. 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\""
@@ -257,6 +257,58 @@ const dbPassword = process.env.DB_PASSWORD;
257
257
  if (!dbPassword) throw new Error('DB_PASSWORD not set');
258
258
  ```
259
259
 
260
+ ## Critical Security Invariants (apply only when the task touches these surfaces)
261
+
262
+ These invariants are lane-aware: enforce them for Critical tasks that touch the
263
+ named surface; for Direct/Standard tasks that happen to touch it, apply the same
264
+ checks with proportional evidence (targeted unit test + diff self-check for Direct,
265
+ bounded suite for Standard). Do not impose a fixed heavy ceremony on every task.
266
+
267
+ ### Logging & Secret Redaction
268
+
269
+ - Match secret names by exact token boundaries, not broad substrings. Never redact
270
+ by substring inside safe identifiers — e.g. names ending in `_file`, `_path`,
271
+ `_hint`, `_label` or containing `tokenizer` must stay intact. Preserve the
272
+ field/key name, replace only the value with `[REDACTED]` (use `[REDACTED-PEM]`
273
+ for PEM blocks, keeping the surrounding structure).
274
+ - Leave public URLs and credential-free strings untouched. URL redaction applies
275
+ only when a credential is present in the URL (e.g. `user:pass@host`).
276
+ - Authorization redaction is quote-aware and delimiter-safe: match schemes
277
+ `Bearer`/`Basic` case-insensitively, redact only the credential that follows,
278
+ preserve surrounding quotes and trailing delimiters (`,`, `;`, whitespace) outside
279
+ the redacted value, and never drop the closing quote.
280
+ - Idempotence: `redact(redact(x)) === redact(x)`. The markers `[REDACTED]` /
281
+ `[REDACTED-PEM]` are stable and not re-wrapped or corrupted.
282
+ - Verification guidance: cover true-positive credential cases, false-positive
283
+ safe-identifier and public-URL cases, quoted `Bearer`/`Basic` with trailing
284
+ delimiters, multi-line/PEM cases when relevant, and an idempotence round-trip.
285
+ Assert that no secret appears in error messages or completion reports and that
286
+ safe values are byte-identical after redaction.
287
+
288
+ ### Filesystem Write Boundary
289
+
290
+ - Require an existing real directory as root. Reject before any mutation when
291
+ `targetPath` is empty or whitespace-only, contains a URI scheme, is absolute,
292
+ escapes via `..` segments, or escapes via sibling-prefix (`root` vs
293
+ `root-evil`).
294
+ - Containment needs two checks: lexical containment of the resolved path
295
+ (`path.resolve(root, target)` inside root) **and** `realpath` containment of
296
+ the deepest existing parent directory. This blocks symlink-pointing-outside
297
+ and traversal that lexical check alone would miss. Never follow or overwrite a
298
+ symlink at the final target; never create parent directories outside root.
299
+ - Perform atomic same-directory write: create a temporary file in the target
300
+ directory, write fully, then `rename` into place. Remove the temp file on any
301
+ error. Rejections must happen before creating or modifying anything outside root.
302
+ - Return the canonical `realpath` of the target on success (e.g. macOS
303
+ `/var` → `/private/var` alias must resolve). Keep the public API otherwise
304
+ unchanged.
305
+ - Verification guidance: nested success, traversal / absolute / URI / sibling-prefix
306
+ rejection, parent-symlink rejection, final-symlink rejection (do not follow or
307
+ overwrite), no-outside-mutation assertion (filesystem outside root unchanged on
308
+ failure), atomic temp cleanup, and canonical return-path equality. Critical runs
309
+ the full project suite; Direct/Standard use proportional lane evidence (targeted
310
+ unit test + diff self-check for Direct, bounded suite for Standard).
311
+
260
312
  ## API Security Checklist
261
313
 
262
314
  - [ ] Use HTTPS/TLS 1.3 only
@@ -1,100 +1,119 @@
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 the persisted lane, risk, and blast radius:
27
27
 
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.
28
+ - Direct: targeted correctness/security/spec check;
29
+ - Standard: bounded feature review at closeout;
30
+ - Critical: independent, adversarial review covering every required obligation.
29
31
 
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.
32
+ Do not use file count as the depth selector. `execution_tier` is a read-only
33
+ legacy adapter and cannot choose a review sequence. The review contract has no
34
+ fixed Light/Standard/Deep sequence.
33
35
 
34
- ## Usage & Input Modes
36
+ ## Review stages
35
37
 
36
- If invoked without explicit arguments, default to reviewing recent changes (pending diff).
38
+ ### 1. Specification compliance
37
39
 
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 |
40
+ Compare the diff with `scope_lock`, requirements, design contracts, active task
41
+ criteria, and declared runtime reachability. Identify missing behavior,
42
+ unjustified extras, contract substitution, orphaned outputs, and incorrect
43
+ completion claims. If a design image or document carries requirements, load its
44
+ multimodal reference only when needed; do not guess from a filename.
44
45
 
45
- ## 3-Stage Adversarial Protocol
46
+ ### 2. Correctness and security
46
47
 
47
- Ensure verification walks through these three stages before delivering a final verdict.
48
+ Trace changed entrypoints and callers. Check boundary validation, error paths,
49
+ resource handling, race assumptions, secrets, authorization, persistence, and
50
+ failure recovery in proportion to risk. Apply YAGNI/KISS/DRY as maintainability
51
+ signals, not as a numeric score.
48
52
 
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?
53
+ ### 3. Adversarial checks
54
54
 
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.
55
+ Try empty, malformed, unauthorized, duplicate, stale, boundary, and concurrent
56
+ inputs where the changed contract makes them relevant. For Critical obligations,
57
+ review the required independent evidence and provenance. A marker such as
58
+ `Audit: PASS` is not independent evidence.
59
59
 
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).
60
+ The independent-audit proof must be a durable object with exactly
61
+ `schema_version: "1"`, distinct concrete `reviewer_session_id` and
62
+ `implementation_session_id`, `expected_provenance: { base, head }` matching the
63
+ runtime binding, concrete `evidence`, and literal `verdict: "PASS"`.
64
+ `independent: true`, `PASS_WITH_WARNINGS`, missing binding, or reused session
65
+ provenance is insufficient.
66
66
 
67
- ## Output
67
+ ## Execution-proof boundary
68
68
 
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.
69
+ Consume the current canonical receipt when available and report its identity,
70
+ scope, and caveats. Never rerun commands to manufacture proof. If execution
71
+ proof is missing, say `execution proof unavailable` and leave the overall
72
+ closeout to the test owner; do not claim PASS on the feature from review alone.
73
+ A review can still return a correctness verdict when its review inputs are
74
+ complete.
75
+
76
+ ## Verdict
77
+
78
+ Use the shared adapter surface exactly:
79
+
80
+ `PASS | PASS_WITH_WARNINGS | FAIL | BLOCKED`
81
+
82
+ Legacy adapter inputs may include `PASS | FAIL | BLOCKED`, but they are
83
+ normalized to the shared surface and no second enum is allowed. `PASS` means no
84
+ Critical/High correctness, security, or compliance finding. `PASS_WITH_WARNINGS`
85
+ means only documented non-blocking findings remain. `FAIL` requires remediation;
86
+ `PASS` also requires no blocking Medium finding. `PASS_WITH_WARNINGS` may carry
87
+ documented non-blocking findings. Finding count never selects depth or overrides
88
+ missing execution proof. A review `PASS_WITH_WARNINGS` remains an unfinished
89
+ closeout result; only literal `PASS` can finish a task. `BLOCKED` means the review input or a user-owned
90
+ decision is unavailable.
73
91
 
74
- Format:
75
92
  ```markdown
76
93
  # Code Review Results [hapo:code-review]
77
94
 
78
- **Verdict:** PASS | FAIL | BLOCKED
95
+ **Verdict:** PASS | PASS_WITH_WARNINGS | FAIL | BLOCKED
79
96
  **Target:** [PR | Commit | Path]
97
+ **Lane / risk:** [snapshot and relevant signals]
98
+ **Execution proof:** consumed | unavailable (owned by hapo:test)
80
99
 
81
- ## Stage 1: Spec Compliance
82
- - [Issue or OK] (If visual/PDF used, mention ai-multimodal analysis result)
100
+ ## Findings
101
+ - [Critical|High|Medium|Low] path:line — issue, failure scenario, evidence,
102
+ and fix boundary.
83
103
 
84
- ## Stage 2: Code Quality
85
- - [Issue or OK]
104
+ ## Decision
105
+ - Scope/spec compliance: PASS | WARN | FAIL
106
+ - Correctness/security: PASS | WARN | FAIL
107
+ - Reachability/provenance review: PASS | WARN | FAIL
108
+ ```
86
109
 
87
- ## Stage 3: Adversarial Findings
88
- - [🔴 Critical] ...
89
- - [🟠 High] ...
90
- - [🟡 Medium] ...
91
- - [🔵 Suggestion] ...
110
+ Do not add a test command, a fabricated receipt, or an `Audit: PASS` marker to
111
+ make the review look complete. Return unresolved questions at the end.
92
112
 
93
- ## Fix Commands (Terminal ready)
94
- [List exact bash commands or SED replacements to fix the issues quickly if possible]
95
- ```
113
+ ## References
96
114
 
97
- ## Related
98
- - Parallel skill: `/hapo:test`
99
- - AI Hub: `/hapo:ai-multimodal`
100
- - Parent orchestrator: `quality-gate.md`
115
+ - `references/spec-compliance-review.md` — load for detailed scope checks.
116
+ - `references/pre-landing-checklists.md` — load for the selected risk surface.
117
+ - `references/adversarial-review.md` — load for Critical/adversarial depth.
118
+ - `references/verification-gate.md` — receipt consumption only; execution stays
119
+ with `hapo:test`.