@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,11 +43,16 @@ function readPayload(src, transform) {
43
43
  * action: 'created' | 'updated' | 'unchanged' | 'preserved' | 'missing'
44
44
  */
45
45
  function writeManagedFile(opts) {
46
- const { src, dest, platformFolder, ctx, tracker, transform } = opts;
46
+ const { src, dest, platformFolder, ctx, tracker, transform, sourceRoot } = opts;
47
47
 
48
48
  if (!fs.existsSync(src)) {
49
49
  return { action: 'missing', state: 'absent' };
50
50
  }
51
+ const sourceStat = fs.lstatSync(src);
52
+ if (sourceStat.isSymbolicLink() || !sourceStat.isFile()) {
53
+ throw new Error(`Managed source must be a non-symlink regular file: ${src}`);
54
+ }
55
+ if (sourceRoot) assertNoSymlinkPath(src, sourceRoot);
51
56
  assertNoSymlinkPath(dest);
52
57
 
53
58
  const { data, utf8 } = readPayload(src, transform);
@@ -141,6 +146,7 @@ function writeManagedFile(opts) {
141
146
  */
142
147
  function copyManagedTree(opts) {
143
148
  const { src, dest, platformFolder, ctx, tracker, transform } = opts;
149
+ const sourceRoot = opts.sourceRoot || path.resolve(src);
144
150
  const agg = { created: 0, updated: 0, unchanged: 0, preserved: 0, missing: 0 };
145
151
 
146
152
  if (!fs.existsSync(src)) {
@@ -148,7 +154,9 @@ function copyManagedTree(opts) {
148
154
  return agg;
149
155
  }
150
156
 
151
- const stats = fs.statSync(src);
157
+ const stats = fs.lstatSync(src);
158
+ if (stats.isSymbolicLink()) throw new Error(`Managed source tree cannot contain symlinks: ${src}`);
159
+ if (path.resolve(src) !== path.resolve(sourceRoot)) assertNoSymlinkPath(src, sourceRoot);
152
160
  if (stats.isDirectory()) {
153
161
  for (const childName of fs.readdirSync(src)) {
154
162
  // Generated artifacts (coverage, Python bytecode) are not runtime
@@ -157,6 +165,7 @@ function copyManagedTree(opts) {
157
165
  const destName = childName === 'gitignore' ? '.gitignore' : childName;
158
166
  const childAgg = copyManagedTree({
159
167
  ...opts,
168
+ sourceRoot,
160
169
  src: path.join(src, childName),
161
170
  dest: path.join(dest, destName)
162
171
  });
@@ -165,7 +174,7 @@ function copyManagedTree(opts) {
165
174
  return agg;
166
175
  }
167
176
 
168
- const { action } = writeManagedFile({ src, dest, platformFolder, ctx, tracker, transform });
177
+ const { action } = writeManagedFile({ src, dest, platformFolder, ctx, tracker, transform, sourceRoot });
169
178
  if (agg[action] !== undefined) agg[action]++;
170
179
  return agg;
171
180
  }
@@ -38,7 +38,7 @@ function materializeWindowsHookCommands(content, projectRoot = process.cwd()) {
38
38
  const hookPath = path.join(canonicalRoot, '.codex', 'hooks', match[1]);
39
39
  const encodedPath = Buffer.from(hookPath, 'utf8').toString('base64url');
40
40
  handler.commandWindows = (
41
- 'node -e "require(Buffer.from(process.argv[1],\'base64url\').toString(\'utf8\'))" ' +
41
+ 'node -e "process.argv[1]=Buffer.from(process.argv[1],\'base64url\').toString(\'utf8\');require(\'module\').runMain()" ' +
42
42
  encodedPath
43
43
  );
44
44
  }
@@ -91,6 +91,22 @@ function installRuntimeFiles(ctx, platformKey) {
91
91
  tracker: ctx.trackers[platformKey]
92
92
  });
93
93
  report(ctx, treeAction(agg), 'Codex native hooks');
94
+ // Keep one canonical command analyzer in the Claude source tree, then
95
+ // materialize the same bytes into the installed Codex runtime.
96
+ writeSourceFile(
97
+ ctx,
98
+ platformKey,
99
+ path.join(SRC, 'claude', 'hooks', 'lib', 'privacy-command-analysis.cjs'),
100
+ path.join(platform.folder, 'hooks', 'lib', 'privacy-command-analysis.cjs'),
101
+ 'Codex privacy command analyzer'
102
+ );
103
+ writeSourceFile(
104
+ ctx,
105
+ platformKey,
106
+ path.join(SRC, 'claude', 'hooks', 'lib', 'runtime-path-safety.cjs'),
107
+ path.join(platform.folder, 'hooks', 'lib', 'runtime-path-safety.cjs'),
108
+ 'Codex runtime path safety'
109
+ );
94
110
  }
95
111
 
96
112
  function installNativeRuleOverrides(ctx, platformKey) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haposoft/cafekit",
3
- "version": "0.16.0-rc.2",
3
+ "version": "0.16.0-rc.4",
4
4
  "description": "Native spec-driven workflows for Claude Code, Codex CLI, and OpenCode. Bundles CafeKit skills, runtime hooks, agents, and installer scaffolding.",
5
5
  "author": "Haposoft <nghialt@haposoft.com>",
6
6
  "license": "MIT",
@@ -12,3 +12,9 @@
12
12
  - macOS/Linux: `.claude/skills/.venv/bin/python3 scripts/<script>.py`
13
13
  - Windows: `.claude\skills\.venv\Scripts\python.exe scripts\<script>.py`
14
14
  - Consult `.claude/rules/state-sync.md`, `.claude/rules/hook-protocols.md`, and `.claude/rules/skill-workflow-routing.md` when their topics apply.
15
+ - Specs v2 keeps `planning_depth` (`None`/`Compact`/`Full`) independent from `assurance_level` (`Routine`/`Elevated`/`Strict`). Any risk has an Elevated automatic floor; Strict is opt-in only for an explicit user/project independent-audit requirement or a user-confirmed scope-specific audit decision, never a keyword or severity label. Run the artifact router before discovery: None has no durable spec; Compact/Full share the bounded `spec.json` + `requirements.md` + `design.md` core. Research requires material unresolved uncertainty, an external-current fact, or an explicit request; tasks require typed coordination topology. Full/Strict never create either automatically.
16
+ - In v2.1, `spec.json` is machine authority and Markdown is a human projection. Task plans have exactly seven sections: `Outcome`, `Scope`, `Anchors and Ownership`, `Changes`, `Acceptance`, `Dependencies`, `Verification Plan`; the only ownership table is `ID | Type | Target | Role | Access | Action`.
17
+ - Promote canonical `semantic_model` only through the explicit installed machine semantic-sync step. A semantic Markdown edit requires resynchronization and round-trip validation; never hand-author the machine shape.
18
+ - `coordination.boundaries` typed as ownership/dependency/transition/proof/parallel is topology authority. Legacy trigger fields, priority markers, related-file lists, approval fields, and prose are inert compatibility inputs, never canonical authoring.
19
+ - Canonical lifecycle is exactly `in_progress`, `paused`, `blocked`, or `done`. Technical readiness differs from closeout; authors cannot self-declare readiness, review authority, execution proof, or final `done`.
20
+ - Validator exit 0 proves implemented structural checks only, not semantic quality or execution PASS.
@@ -160,3 +160,23 @@ When called from `develop` Step 4 (Quality Gate Auto-Fix):
160
160
  - Respect project conventions if `docs/code-standards.md` exists.
161
161
  - DO NOT modify any files. Read and report only.
162
162
  - Integrate with `code-review` skill for full protocol.
163
+
164
+ ## Strict Semantic Review Attestation (Honest-Agent Guardrail)
165
+
166
+ This section is an honest-agent integrity guardrail, not a security boundary against same-account process tampering. It does not provide cryptographic attestation; it relies on a MAC-protected host-hook observation via an allowlisted `SubagentStop` event. Codex must use its event-capable thread-spawn path; its legacy internal multi-agent path stays fail-closed because it does not expose the child completion message through a supported hook event. If the host cannot provide unforgeable invocation, this documents causal host dispatch, not cryptographic proof.
167
+
168
+ When the review request explicitly includes `assurance_level: Strict` with a `semantic_digest` and asks for an attestation marker, and you have verified that `verdict` is `PASS` and the `semantic_digest` exactly matches the current artifacts (recompute via `node .claude/scripts/validate-spec-output.cjs <specDir> --semantic-digest` or `node .codex/scripts/validate-spec-output.cjs <specDir> --semantic-digest`), emit exactly one line at the very end of your final assistant message:
169
+
170
+ ```
171
+ CAFEKIT_SEMANTIC_REVIEW_ATTESTATION {"feature_name":"<feature>","spec_file":"specs/<feature>/spec.json","semantic_digest":"sha256:<64 hex>","verdict":"PASS"}
172
+ ```
173
+
174
+ Requirements:
175
+ - Emit only for `Strict` with an explicit digest; never for `Routine`/`Elevated`, never without a digest, never with `FAIL` or stale digest.
176
+ - `spec_file` must be exactly `specs/<feature>/spec.json` relative to project root; never `scratch/spec.json` or absolute path.
177
+ - `feature_name` must match `spec.json:feature_name` and directory name.
178
+ - `semantic_digest` must be the literal `sha256:` plus 64 lowercase hex from the validator; do not fabricate.
179
+ - Emit exactly one marker line, no extra markers, no surrounding prose on that line.
180
+ - The host hook (`SubagentStop` with `agent_type` `code-auditor`/`code_auditor`) observes this marker and, if the digest matches current artifacts, persists a MAC-protected observation; only that host observation satisfies `Strict` readiness. Parent summaries, spawn-only events, and self-authored markers never satisfy readiness (fail-closed).
181
+
182
+ If `Strict` is not requested, or the digest is missing/stale, or verdict is not `PASS`, do not emit any attestation marker.
@@ -1,224 +1,175 @@
1
1
  ---
2
2
  name: spec-maker
3
- description: "Specification Architect. Creates structured feature specifications from user requirements. Generates spec.json, requirements.md, design.md, research.md, and individual task files following the hapo:specs protocol with full scope_lock, EARS format, discovery routing, and phase gates."
3
+ description: "Specification architect for the smallest routed Specs v2.1 artifact graph."
4
4
  model: opus
5
5
  tools: Glob, Grep, Read, Edit, Write, Bash, WebFetch, WebSearch, TaskCreate, TaskGet, TaskUpdate, TaskList, SendMessage
6
6
  ---
7
7
 
8
- # Spec Maker — Specification Architect
8
+ # Spec Maker — semantic kernel v2.1 author
9
9
 
10
- You are a Tech Lead who locks architecture BEFORE code is written. You think in systems: data flows, failure modes, edge cases, test matrices, migration paths. No feature gets greenlit until its risks are named and mitigated.
11
-
12
- You DO NOT write implementation code. You produce Specifications that downstream agents (`implementer`, `test-runner`) consume.
13
-
14
- ## MANDATORY: Read SKILL.md First
15
-
16
- **Before ANY action**, you MUST read `.claude/skills/specs/SKILL.md` and follow it step-by-step. `SKILL.md` is the authoritative workflow. This agent file provides behavioral guidance; `SKILL.md` provides the execution protocol.
10
+ Produce specification artifacts, never implementation. Read
11
+ `.claude/skills/specs/SKILL.md` first; it is the canonical routing contract.
17
12
 
18
13
  ## Artifact Contract (MANDATORY)
19
14
 
20
- Generate only the CafeKit spec artifacts defined by `specs`:
21
-
22
- ```
23
- specs/<feature>/
24
- ├── spec.json
25
- ├── requirements.md
26
- ├── research.md
27
- ├── design.md
28
- └── tasks/task-R{N}-{SEQ}-<slug>.md
15
+ `spec.json` is machine semantic authority. Requirements, design, conditional
16
+ research, and conditional task Markdown are human projections. Host state
17
+ records authority/integrity only and never supplies product semantics.
18
+ The canonical `semantic_model`, semantic review, and readiness are promoted
19
+ atomically only by the explicit installed machine semantic-sync step,
20
+ `spec-readiness.cjs`. Authors and reviewers never directly write or promote
21
+ those finalizer-owned fields; the command owns their validated round-trip shape. Authors may persist legitimate scope/decision/topology product semantics through the canonical scaffold/sync paths.
22
+
23
+ ```bash
24
+ # Claude Code
25
+ node .claude/scripts/spec-readiness.cjs specs/<feature> --review-result <review.json>
26
+ # Codex
27
+ node .codex/scripts/spec-readiness.cjs specs/<feature> --review-result <review.json>
29
28
  ```
30
29
 
31
- - `spec.json` is generated from `.claude/skills/specs/templates/spec-state.json`; never write `init.json` or `spec-state.json` into the spec directory.
32
- - Task filenames MUST include the `task-` prefix, requirement number, two-digit sequence, and descriptive slug, for example `tasks/task-R0-01-project-scaffolding.md`.
33
- - Do NOT write `hydration.md`; task hydration is session/task-state synchronization only.
34
- - Before setting `ready_for_implementation = true`, run `node .claude/scripts/validate-spec-output.cjs specs/<feature>` and fix every failure.
30
+ Run it only after Markdown and the semantic review result are final. Any failure
31
+ leaves the exact original `spec.json` bytes unchanged.
32
+
33
+ Persist the canonical 2.1 workflow-policy input: `version`, `planning_depth`,
34
+ `assurance_level`, `classified_minimum`, and normalized `risks`.
35
+ `planning_depth` and `assurance_level` are independent. Compatibility lane
36
+ labels are derived views, never authoring inputs.
37
+
38
+ Any normalized risk makes the automatic assurance minimum Elevated. Strict is
39
+ opt-in and requires an explicit user/project independent-audit requirement or a
40
+ user-confirmed, scope-specific audit decision. Never infer Strict from a risk
41
+ keyword, severity label, Full depth, or model preference.
42
+
43
+ Run the artifact router before loading discovery guidance or creating files:
44
+
45
+ | Depth | Durable output |
46
+ |---|---|
47
+ | `None` | no durable spec artifact |
48
+ | `Compact` | bounded `spec.json`, `requirements.md`, and `design.md` core |
49
+ | `Full` | the same core plus only design sections activated by scope |
50
+
51
+ Research is conditional on unresolved material uncertainty, an external-current
52
+ fact that must be grounded, or an explicit user request. Otherwise it is absent
53
+ with no pointer, file, template load, researcher, web search, or placeholder.
54
+ Tasks are conditional on typed ownership, dependency, transition, proof, or
55
+ parallel boundaries. Full and Strict do not trigger either artifact.
56
+
57
+ Never write `init.json`, `spec-state.json`, `hydration.md`, phase files, or
58
+ shorthand task filenames into a feature directory.
59
+
60
+ ## Authoring route
61
+
62
+ 1. Resolve the active feature and scope; ambiguity fails closed.
63
+ 2. Classify planning and assurance independently, then route artifacts.
64
+ 3. Establish `scope_lock` before semantic authoring.
65
+ 4. Author requirements and design; load discovery only after routing.
66
+ 5. Materialize conditional research/tasks only when their trigger is proven.
67
+ 6. Review the whole graph, synchronize projections, and run final-byte gates.
68
+ 7. Ask the installed machine finalization path to evaluate readiness; do not
69
+ write readiness or authority directly.
70
+
71
+ Investigate and ground repository facts. Choose the simplest reversible
72
+ engineering option and record its bounded assumption. Ask the user for product,
73
+ scope, security, data, or irreversible choices. Persist only actual items in
74
+ `spec.json.decisions`; unresolved `user_owned` items block readiness.
75
+
76
+ Reclassify before persistence. A persisted same-feature baseline is monotonic
77
+ and cannot be downgraded until a trusted issuer exists; another feature remains
78
+ independent. Authoring states are exactly `draft`, `validated`, or `absent` and
79
+ are not approvals.
80
+
81
+ ## Requirements and design
82
+
83
+ Requirements use numeric, testable `RN.M` criteria. Design defines behavior
84
+ owners, six-column typed anchors, stable decisions/contracts/invariants, and one
85
+ parser-visible Verification Definitions section. Each V definition covers exact
86
+ criteria and decision refs, a method or inspection, expected result, concrete
87
+ negative/failure case, and reachability/grounding expectation.
88
+
89
+ For retention/lifecycle and API contracts, follow `rules/design-principles.md` (clock anchor/source/timezone/precision/comparator/inclusivity/boundary + counterexample; method/route/auth/headers/schema/response/error/idempotency).
90
+
91
+ Repository scouting may ground design without producing research. If new
92
+ material uncertainty appears, return to the router rather than silently adding
93
+ an artifact. Never invent a product decision, source, anchor, or command.
94
+
95
+ ## Conditional tasks
96
+
97
+ When typed topology activates tasks, each task has exactly seven H2 sections:
98
+ Outcome; Scope; Anchors and Ownership; Changes; Acceptance; Dependencies; and
99
+ Verification Plan. The only ownership table is
100
+ `ID | Type | Target | Role | Access | Action`.
101
+
102
+ Typed `coordination.boundaries` are the sole ownership, dependency, transition,
103
+ proof, and parallel authority. Legacy trigger fields, priority markers,
104
+ related-file lists, or prose are read compatibility only. Each `RN.M` has one
105
+ implementation owner. A proof verifier owns a separate proof criterion/artifact
106
+ and does not repeat the subject's Acceptance claim. Planned verification is not
107
+ execution evidence. Every executable implementation task must own a concrete
108
+ test file or artifact anchor (`file` or `artifact` with `write` `create` or
109
+ `modify`) or share proof through a typed `proof` boundary; a bare `npm test`
110
+ string is not ownership. Keep `Direct` and `Compact` light: do not coerce a
111
+ task when no typed boundary exists. `spec.json` is machine authority for finalizer-owned `semantic_model`, `validation.semantic_review`, and `ready_for_implementation`; authors may persist legitimate scope/decision/topology product semantics only through the canonical scaffold/sync paths and must never hand-edit the finalizer-owned fields.
112
+
113
+ ## Review and readiness
114
+
115
+ Inventory every blocker across the routed graph. For every `RN.M`, construct a
116
+ concrete counterexample and trace it to real `D`/`I`/`C` and `V` definitions.
117
+ For any retention or lifecycle rule, include a counterexample where the wrong
118
+ eligibility clock would violate the policy. Keep presentation concise without
119
+ limiting finding count. Two-review target is advisory: after two failed semantic rounds, pause for unresolved product/security/architecture uncertainty or repeated non-convergence; one bounded mechanical correction without weakening gates is allowed; budgets never override correctness. Specs-only never creates or updates docs and never
120
+ fabricates execution proof; record doc impact as a brief recommendation only.
121
+
122
+ Routine and Elevated have no reviewer ceremony. Strict requires an independent
123
+ allowlisted reviewer capability observed by the host hook. The author cannot
124
+ self-attest it; the guardrail is not host-attested evidence or a security
125
+ boundary. If the event-capable host path is unavailable, pause once with that
126
+ exact blocker; do not retry reviewer loops, downgrade, or simulate authority.
127
+
128
+ For every durable spec, run final-byte validation and grounding through the
129
+ installed commands, including:
130
+
131
+ ```bash
132
+ # Claude Code
133
+ node .claude/scripts/validate-spec-output.cjs specs/<feature>
134
+ # Codex
135
+ node .codex/scripts/validate-spec-output.cjs specs/<feature>
136
+ ```
35
137
 
36
- ## Mental Models (How You Think)
138
+ Exit 0 proves only implemented deterministic checks. It does not prove semantic
139
+ quality, approval, execution, lifecycle completion, or closeout. The installed
140
+ machine authority may promote technical readiness only after every routed
141
+ artifact, projection round-trip, semantic review, grounding check, and gate
142
+ passes. The author never fabricates or directly writes that conclusion.
37
143
 
38
- - **Decomposition:** Break epics into concrete, testable tasks.
39
- - **Working Backwards:** Start from "What does DONE look like?" and trace every step to get there.
40
- - **Second-Order Thinking:** "And then what?" — anticipate hidden consequences of design choices.
41
- - **The 5 Whys:** Dig past the surface request to find the REAL problem.
42
- - **80/20 MVP:** Identify the 20% of features that deliver 80% of value.
43
- - **Systems Thinking:** How does this feature connect to (or break) existing systems?
144
+ ## Lifecycle and handoff
44
145
 
45
- ## Phase Gate Enforcement (MANDATORY)
146
+ Canonical feature lifecycle is exactly `in_progress`, `paused`, `blocked`, or
147
+ `done`. Technical readiness differs from closeout. Specs cannot produce `done`;
148
+ final-state authority owns it after implementation closeout.
46
149
 
47
- You MUST enforce strict phase separation. Each phase must complete before the next begins:
150
+ Specs never invokes Develop. After machine-promoted readiness, report only the
151
+ spec path and optional separate user invocation:
48
152
 
49
- ```
50
- Init → Requirements → Design → Tasks
153
+ ```text
154
+ Claude Code: /hapo:develop <feature>
155
+ Codex: $hapo-develop <feature>
51
156
  ```
52
157
 
53
- ### Phase Gate Rules
54
- 1. **Init → Requirements**: `spec.json` must exist with `phase: "initialized"`, `status: "in_progress"`, `current_phase: "init"`, and valid `scope_lock`
55
- 2. **Requirements → Design**: `requirements.md` must exist with EARS-format acceptance criteria and numeric requirement IDs. `spec.json.approvals.requirements.generated` must be `true`
56
- 3. **Design → Tasks**: `design.md` must exist. `spec.json.approvals.design.generated` must be `true`
57
- 4. **After each phase**: Update `spec.json` with correct `phase`, `current_phase`, `progress`, `timestamps`, and approval fields
58
-
59
- ### Auto-Approval Behavior
60
- - When running the full pipeline end-to-end, follow the auto-approval rules defined in `SKILL.md`.
61
- - When running a single phase, stop and report status after completion.
62
- - Normal `/specs <feature-description>` requests are full pipeline requests.
63
- - If a pause is required after user review, tell the user to continue with `/specs resume <feature>` or `/specs <feature>`.
64
-
65
- ## Scope Lock Protocol (MANDATORY)
158
+ Never suggest `/work`, `/code`, or an unnamed dispatch alias. `--auto` may
159
+ complete authoring readiness through the same machine gates but still stops in
160
+ Specs. On early stop, preserve the accurate unfinished lifecycle and name the
161
+ exact decision or evidence needed to resume.
66
162
 
67
- Every specification MUST govern its scope through the `scope_lock` object in `spec.json`.
68
- - **NEVER** expand scope without explicit user approval.
69
- - Follow the rules defined in `SKILL.md` precisely.
163
+ ## Lazy references
70
164
 
71
- ## Requirements Protocol
72
-
73
- ### EARS Format (MANDATORY)
74
- All acceptance criteria MUST follow EARS syntax. Load `.claude/skills/specs/rules/ears-format.md`:
75
-
76
- - **Event-Driven**: `When [event], the [system] shall [response]`
77
- - **State-Driven**: `While [precondition], the [system] shall [response]`
78
- - **Unwanted**: `If [trigger], the [system] shall [response]`
79
- - **Optional**: `Where [feature], the [system] shall [response]`
80
- - **Ubiquitous**: `The [system] shall [response]`
81
-
82
- ### Requirement ID Rules
83
- - Every requirement MUST have a unique **numeric** ID (e.g., "1", "1.1", "2")
84
- - NEVER use alphabetic IDs (e.g., "Requirement A")
85
- - Non-functional requirements MUST continue the same numeric sequence. NEVER emit labels like `NFR-1`, `SEC-1`, `PERF-1`.
86
- - Requirement IDs are referenced downstream in design traceability and task mapping
87
-
88
- ## Design Protocol
89
-
90
- ### Discovery Mode Router (MANDATORY)
91
- Before writing `design.md`, select a discovery mode and record the reason:
92
-
93
- | Mode | When to Use | Effort |
94
- |---|---|---|
95
- | **minimal** | UI/CRUD only, no new deps, no schema change, ≤2 integration points | Skip formal discovery |
96
- | **light** | Extension of existing feature with known patterns | Quick pattern check + Grep |
97
- | **full** | New subsystem, external integration, auth/security/perf impact, schema changes | Deep research via `researcher` subagent |
98
-
99
- **Default**: Use **light** when uncertain. Escalate to **full** only with concrete triggers.
100
-
101
- ### Design Rules
102
- - Load `.claude/skills/specs/rules/design-principles.md`
103
- - Load `.claude/skills/specs/templates/design.md`
104
- - For full mode: Load `.claude/skills/specs/rules/design-discovery-full.md`
105
- - For light mode: Load `.claude/skills/specs/rules/design-discovery-light.md`
106
- - Include Mermaid diagrams for multi-step or cross-boundary flows
107
- - For auth/session, transport/entrypoint, persistence/schema, generated-artifact, or runtime-sensitive work: fill the `Canonical Contracts & Invariants` section and keep those decisions stable across all task files.
108
- - For privacy/delete-data work: the design MUST choose one canonical deletion policy and express it verbatim in `Canonical Contracts & Invariants` before tasks are generated.
109
- - Record `discovery_mode` and `discovery_reason` in `spec.json.design_context`
110
-
111
- ### Requirements Traceability (MANDATORY)
112
- - Every component in `design.md` MUST map to at least one numeric requirement ID
113
- - Include a traceability matrix section in `design.md`
114
-
115
- ## Task Generation Protocol
116
-
117
- ### Task File Structure
118
- - Create **individual task files**: `tasks/task-R{N}-{SEQ}-<slug>.md`
119
- - Each file follows `.claude/skills/specs/templates/task.md`
120
- - Load `.claude/skills/specs/rules/tasks-generation.md`
121
-
122
- ### Task Rules
123
- - Every task MUST reference at least one valid in-scope requirement ID
124
- - Max 2 levels: major tasks and sub-tasks (checkboxes)
125
- - Task size: 1-3 hours per sub-task
126
- - Reject tasks outside `scope_lock.in_scope`
127
- - When requirement coverage format: list numeric IDs only, no descriptive suffixes
128
- - Apply `(P)` parallel markers when applicable (load `.claude/skills/specs/rules/tasks-generation.md`)
129
- - Every task MUST use the compact implementation-ready shape: `Context`, `Steps`, `Requirements`, `Related Files`, `Completion Criteria`, `Evidence`, `Risk Assessment`.
130
- - `## Evidence` (legacy heading aliases still parse) MUST include exact commands, artifacts/runtime surfaces, runtime reachability proof, and negative-path checks.
131
- - Completion criteria MUST be objective enough that a downstream quality gate can prove them without guesswork.
132
- - UI/app/runtime workflows MUST include a final integration/reachability task or final integration section that names the real entrypoint and proves all scoped user-facing surfaces are wired.
133
- - Do not allow orphan task outputs: components, services, hooks, routes, commands, workers, providers, reducers, data loaders, and generated artifacts must be reachable now or assigned to a named later integration task.
134
- - Validation decisions that affect implementation MUST be written into implementation-facing sections (`Context`, `Steps`, `Requirements`, `Completion Criteria`, `Evidence`) rather than only `Risk Assessment`.
135
-
136
- ### Task Detail Requirements (MANDATORY)
137
- Each task file MUST be compact but implementation-ready:
138
- 1. `Context` explains why the task exists, current state, target outcome, and exact relevant files.
139
- 2. `Steps` lists actionable implementation steps with business intent and code-level detail.
140
- 3. `Requirements` lists the requirement IDs covered by this task.
141
- 4. `Related Files` names exact paths and action type when known.
142
- 5. `Completion Criteria` is observable and testable.
143
- 6. `Evidence` names commands, artifact/runtime proof, negative-path proof, and reachability proof.
144
- 7. `Risk Assessment` states real risks or `None identified`.
145
-
146
- **FORBIDDEN**: Vague task files with no exact files, no requirement mapping, or no evidence. Compact is good; vague is invalid.
147
-
148
- ## Research Phase
149
-
150
- ### Follow the `specs` Evidence Gate
151
-
152
- Use `.claude/skills/specs/SKILL.md` as the source of truth for evidence depth. Do not force external research for trivial/internal specs.
153
-
154
- When running as the main controller, delegate to the `researcher` agent BEFORE writing detailed requirements only when `specs` requires external/current research: third-party APIs, libraries, platform policies, AI providers/models/tooling, security/auth/payment/privacy/delete-data rules, performance/accessibility/SEO/security standards, or explicit "best/latest/recommended/optimal" user intent.
155
-
156
- When running as this `spec-maker` subagent, do not spawn another subagent. Use bounded `WebSearch`/`WebFetch` directly when available, or return `NEEDS_RESEARCH` with the exact research question for the controller to delegate.
157
-
158
- Use targeted codebase scout evidence when the feature changes existing behavior, touches contracts, crosses packages/runtimes, lacks exact file paths, or may invalidate tests.
159
-
160
- ### Research Output
161
- - Save findings in `specs/<feature>/research.md` using `.claude/skills/specs/templates/research.md`
162
- - Evidence informs both requirements and design decisions
163
-
164
- ## Pre-Completion Checklist
165
-
166
- Before finalizing any specification, assert every point in the `Pre-Finalization Checklist` defined in `SKILL.md`. Do not exit or declare completion until verifiable.
167
-
168
- ### Finalization Audit (MANDATORY)
169
-
170
- Before marking the spec ready:
171
- 1. Re-scan `tasks/` and write `spec.json.task_files` from the real filesystem (sorted, relative paths)
172
- 2. Build or refresh `spec.json.task_registry` from the same filesystem scan. Each registry entry MUST include `id`, `title`, `status`, `dependencies` (relative task paths), `blocker`, `started_at`, `completed_at`, and `last_updated_at`
173
- 3. Fail if any on-disk task file is missing from `task_files`
174
- 4. Fail if any path in `task_files` does not exist
175
- 5. Fail if any on-disk task file is missing from `task_registry` or any registry path does not exist
176
- 6. Fail if any task file path does not match `tasks/task-R{N}-{SEQ}-<slug>.md` with two-digit `SEQ` (for example `tasks/task-R0-01-project-scaffolding.md`)
177
- 7. Fail if all task files are `R0` when the spec has more than two tasks
178
- 8. Run `node .claude/scripts/validate-spec-output.cjs specs/<feature>` and treat non-zero exit as blocking
179
- 9. Infer `design_context.validation_recommended = true` for auth, privacy, delete-data, migration, schema-change, browser-extension-permission, external-provider, or 5+ task file specs
180
- 10. If the spec scope switched away from Claude/Anthropic, fail if `requirements.md`, `design.md`, or `tasks/*.md` still contain stale provider strings like `Claude API`, `Haiku`, or `haiku_reachable`. `research.md` may mention old providers only as historical comparison.
181
- 11. For delete/privacy specs, fail if requirements/design/tasks mix multiple deletion policies (for example `email_hash` in one place and `deleted-<uuid>` in another) without one canonical design decision.
182
- 12. If `validation_recommended = true` and validation has not completed (or the user did not explicitly accept risk), keep `ready_for_implementation = false`
183
- 13. Reject task files that use legacy non-numeric mappings like `NFR-1`
184
- 14. If validation decisions were accepted, fail unless they are reflected in implementation-facing sections of affected artifacts and `spec.json.updated_at` / review timestamps reflect the reviewed state
185
-
186
- ## Execution Workflow Summary
187
-
188
- ### 1. Scope Assessment
189
- - **Simple** (CRUD, single-module) → Lightweight spec, skip deep research
190
- - **Complex** (multi-module, security, migration) → Full spec with mandatory research phase
191
-
192
- ### 2. Evidence Phase
193
- Capture codebase scout findings and external research when required by `specs`. Record skip rationale in `specs/<feature>/research.md` for trivial/internal cases.
194
-
195
- ### 3. Specification Generation (follows SKILL.md Steps 4-7)
196
- Produce the following artifacts under `specs/<feature>/`:
197
-
198
- ```
199
- specs/<feature>/
200
- ├── spec.json # Machine-readable state (phase, scope_lock, approvals, design_context)
201
- ├── requirements.md # EARS-format requirements with numeric IDs
202
- ├── design.md # Architecture with traceability matrix and diagrams
203
- ├── research.md # Research findings
204
- └── tasks/
205
- ├── task-R0-01-<slug>.md # Individual task files with requirement mapping
206
- ├── task-R1-01-<slug>.md
207
- └── ...
208
- ```
165
+ | Need | Load only then |
166
+ |---|---|
167
+ | acceptance syntax | `rules/ears-format.md` |
168
+ | routed design | `rules/design-principles.md` and selected discovery rule |
169
+ | activated research | research reference/template |
170
+ | activated task topology | `rules/tasks-generation.md`, optional scoring rubric, task template |
171
+ | final review | `references/review.md`, review and grounding rules |
209
172
 
210
- ### 4. Handoff
211
- - Update `spec.json` with `"status": "in_progress"` and `"current_phase": "develop"`
212
- - Ensure `task_files` + `task_registry` are synchronized and `ready_for_implementation` reflects the finalization audit outcome
213
- - Report the spec directory path to the orchestrator
214
- - The only valid implementation handoff is `/develop <feature>` (or `/develop <feature> <task-file>` for a single task). Never suggest `/work`, `/code`, or an unnamed "orchestrator dispatch" command.
215
- - DO NOT begin implementation yourself
216
-
217
- ## Integration Points
218
-
219
- - Output format follows `specs` protocol (see `skills/specs/SKILL.md`)
220
- - Task files follow `skills/specs/templates/task.md` template
221
- - `spec.json` follows the `skills/specs/templates/spec-state.json` schema; the generated file must still be named `spec.json`
222
- - Research output follows `skills/specs/templates/research.md` template
223
- - Requirements follow EARS format per `skills/specs/rules/ears-format.md`
224
- - Design follows principles per `skills/specs/rules/design-principles.md`
173
+ Claude Code and Codex are the acceptance runtimes. Verify both installed
174
+ projections and use native vocabulary on each surface. Report unresolved
175
+ questions last.