@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
@@ -43,6 +43,11 @@
43
43
  "command": "node \"$(git rev-parse --show-toplevel)/.codex/hooks/privacy-approval.cjs\"",
44
44
  "commandWindows": "node \".codex/hooks/privacy-approval.cjs\""
45
45
  },
46
+ {
47
+ "type": "command",
48
+ "command": "node \"$(git rev-parse --show-toplevel)/.codex/hooks/completion-authority.cjs\"",
49
+ "commandWindows": "node \".codex/hooks/completion-authority.cjs\""
50
+ },
46
51
  {
47
52
  "type": "command",
48
53
  "command": "node \"$(git rev-parse --show-toplevel)/.codex/hooks/rules.cjs\"",
@@ -58,7 +63,7 @@
58
63
  ],
59
64
  "PreToolUse": [
60
65
  {
61
- "matcher": "Bash|apply_patch|Edit|Write|Read|Glob|Grep|mcp__.*",
66
+ "matcher": "Bash|exec_command|apply_patch|Edit|Write|Read|Glob|Grep|mcp__.*|shell",
62
67
  "hooks": [
63
68
  {
64
69
  "type": "command",
@@ -98,6 +103,11 @@
98
103
  "command": "node \"$(git rev-parse --show-toplevel)/.codex/hooks/spec-gate.cjs\"",
99
104
  "commandWindows": "node \".codex/hooks/spec-gate.cjs\""
100
105
  },
106
+ {
107
+ "type": "command",
108
+ "command": "node \"$(git rev-parse --show-toplevel)/.codex/hooks/completion-authority.cjs\"",
109
+ "commandWindows": "node \".codex/hooks/completion-authority.cjs\""
110
+ },
101
111
  {
102
112
  "type": "command",
103
113
  "command": "node \"$(git rev-parse --show-toplevel)/.codex/hooks/state.cjs\"",
@@ -110,6 +120,11 @@
110
120
  {
111
121
  "matcher": "*",
112
122
  "hooks": [
123
+ {
124
+ "type": "command",
125
+ "command": "node \"$(git rev-parse --show-toplevel)/.codex/hooks/semantic-review-authority.cjs\"",
126
+ "commandWindows": "node \".codex/hooks/semantic-review-authority.cjs\""
127
+ },
113
128
  {
114
129
  "type": "command",
115
130
  "command": "node \"$(git rev-parse --show-toplevel)/.codex/hooks/state.cjs\"",
@@ -1,41 +1,61 @@
1
- # Tollgate Protocol (State Sync)
1
+ # Specs v2.1 state synchronization
2
2
 
3
- ## Sources Of Truth
3
+ ## Authority layers
4
4
 
5
- Spec-driven work persists state in two synchronized layers:
5
+ `spec.json` is machine semantic authority. Requirements, design, conditional
6
+ research, and conditional task Markdown are human projections. Host state may
7
+ record authority or integrity, but it never supplies product semantics.
6
8
 
7
- 1. `spec.json` tracks phase, overall status, and `task_registry`.
8
- 2. `tasks/task-*.md` tracks the human-readable checklist and verification receipt.
9
+ Planning depth and assurance level remain independent. Route artifacts before
10
+ discovery: None persists no spec; Compact and Full persist the bounded core;
11
+ research and tasks remain absent unless their semantic triggers exist.
9
12
 
10
- ## Sync-back Rule
13
+ ## Canonical lifecycle
11
14
 
12
- Before reporting a task completed or blocked:
15
+ The feature lifecycle is exactly `in_progress`, `paused`, `blocked`, or `done`.
16
+ Authoring state is independently `draft`, `validated`, or `absent`. New 2.1
17
+ artifacts never emit legacy lifecycle aliases.
13
18
 
14
- ### On success
19
+ Technical readiness is not lifecycle completion. `ready_for_implementation`
20
+ may change only through the installed machine finalization path after every
21
+ routed artifact, projection, semantic review, grounding check, and deterministic
22
+ gate passes. The author cannot directly declare readiness, authority, approval,
23
+ review capability, execution proof, or closeout.
15
24
 
16
- 1. Update `spec.json` only after verification. Keep `current_phase`,
17
- `task_files`, status, timestamps, and the matching `task_registry` entry accurate.
18
- 2. Update the matching task Markdown status, checkboxes, completion criteria,
19
- and `## Evidence` receipt from the current verification run.
20
- 3. Update native plan or task state when the active Codex session provides it,
21
- but never use chat-only state as a substitute for the files above.
25
+ ## Projection sync
22
26
 
23
- ### On block after repeated attempts
27
+ After a semantic Markdown edit:
24
28
 
25
- 1. Set the spec and matching registry entry to `blocked`, with the root cause and timestamp.
26
- 2. Mark the task Markdown `blocked` and record the evidence.
27
- 3. Tell the user or orchestrator exactly what external input or state change is required.
29
+ 1. invoke the explicit installed machine semantic-sync step to promote `semantic_model`;
30
+ 2. regenerate or reconcile every affected Markdown projection;
31
+ 3. verify requirements, decisions, anchors, task registry, typed boundaries,
32
+ and verification refs round-trip without loss; and
33
+ 4. rerun applicable deterministic validation and grounding checks.
28
34
 
29
- New specs use `in_progress`; legacy `in-progress` may be read but not emitted.
30
- Never let `task_registry` disagree with its task Markdown file.
35
+ For Codex, the isolated promotion is
36
+ `node .codex/scripts/spec-scaffold.cjs <feature> --sync-semantic-model`.
31
37
 
32
- ## Completion Gate
38
+ Task Markdown exists only for typed ownership, dependency, transition, proof,
39
+ or parallel topology. Its status and dependencies project the matching
40
+ `task_registry` entry. Its Verification Plan is prospective, never execution
41
+ proof. Typed `coordination.boundaries` alone define topology; legacy trigger
42
+ fields, priority markers, related-file lists, and prose do not.
33
43
 
34
- The Stop hook checks newly completed tasks. Each requires:
44
+ ## Lifecycle updates
35
45
 
36
- - `Status: done`;
37
- - a non-placeholder `## Evidence` section with a command block or PASS/FAIL result;
38
- - a non-empty `task_registry[path].completed_at`.
46
+ - Active work uses `in_progress`.
47
+ - A deliberate resumable stop uses `paused` with the exact remaining decision.
48
+ - An external or semantic blocker uses `blocked` with a concrete cause.
49
+ - Task state changes update the registry and matching projection together only
50
+ from observed work and verification.
51
+ - Feature `done` is reserved for final-state authority after implementation
52
+ closeout; authoring or readiness cannot produce it.
39
53
 
40
- The first run seeds completion history without blocking. Humans can disable the
41
- gate with `"spec": { "completion_gate": false }` in `.codex/runtime.json`.
54
+ State synchronization never fabricates commands, PASS results, timestamps,
55
+ receipts, completed work, reviewer identity, or user approval. When execution
56
+ evidence is absent, preserve unfinished state and report the missing proof.
57
+ Never hand-author the `semantic_model` shape or treat an unsynchronized Markdown
58
+ edit as machine authority.
59
+
60
+ Codex-native plan or task state may mirror physical state when available, but
61
+ it is never a substitute for `spec.json` or authority to advance lifecycle.
@@ -3,7 +3,7 @@
3
3
  ## Shared CafeKit instructions
4
4
 
5
5
  - Deliver exactly what was asked. Do not expand, polish, or add optional work beyond the request. Match existing code style and structure.
6
- - For spec work, `Completion Criteria` and `## Evidence` in `specs/<feature>/tasks/*.md` are the source of truth for task state.
6
+ - For Specs v2.1, treat `spec.json` as machine authority and Markdown as human projections. Keep task status and plan synchronized with `task_registry`; derive ownership, dependencies, transitions, proof, and parallelism only from typed `coordination.boundaries`. Never invent proof, readiness, approval, or audit state.
7
7
  - `NO_TESTS` and `0 tests + exit 0` do not pass when the task requires automated tests.
8
8
  - When a hook blocks an action, that is an instruction boundary — do not work around it.
9
9
  - Use conventional commits. Do not add AI attribution unless requested.
@@ -28,9 +28,11 @@ The underlying CafeKit skills are still named `hapo:*` in their documentation.
28
28
 
29
29
  ## OpenCode limits
30
30
 
31
- Claude Code hooks, statusline, and settings do not run in OpenCode. Map Claude-only tools to OpenCode built-ins: `TodoWrite` → `todowrite`, `AskUserQuestion` → `question`, `Task` → the agent/subtask flow. The installed plugins under `.opencode/plugins/` provide the privacy, inspect-scope, spec-state, scaffold-guard, session-state, and docs-sync gates; other Claude runtime behavior has no OpenCode equivalent. The completion gate (`spec-gate`: `Verification: PASS` + `## Evidence` + `task_registry.completed_at`) is **advisory in OpenCode** — OpenCode has no Stop-hook equivalent and the `spec-gate` plugin (if present) runs as a best-effort `tool.execute.after` check, not a hard turn block like Claude/Codex.
31
+ Claude Code hooks, statusline, and settings do not run in OpenCode. Map Claude-only tools to OpenCode built-ins: `TodoWrite` → `todowrite`, `AskUserQuestion` → `question`, `Task` → the agent/subtask flow. The installed plugins under `.opencode/plugins/` provide the privacy, inspect-scope, spec-state, scaffold-guard, session-state, and docs-sync gates; other Claude runtime behavior has no OpenCode equivalent.
32
32
 
33
- Runtime tier: OpenCode is **tier-2** for completion enforcement. Do not claim parity with Claude/Codex on `completion_gate`; `done` without a receipt emits an advisory warning/banner but does not hard-block the turn — rely on `spec-state` tollgate + manual `/hapo:test` verification.
33
+ The installed `spec-gate` plugin uses the cancellable `tool.execute.before` hook to hard-block supported completion/state tools (`task`, `taskupdate`, and `todowrite`) with a controlled `CAFEKIT_SPEC_GATE_BLOCKED` result when shared policy/resolver or receipt evidence is invalid or unavailable. Receipt-repair tools remain available where the host boundary permits correction.
34
+
35
+ OpenCode does not expose a cancellable `session.idle`/Stop hook or final assistant-turn cancellation boundary. Those event and prompt-injection paths are observational only; do not claim full-turn parity with Claude/Codex.
34
36
 
35
37
  ## Combined-install boundary
36
38