@haposoft/cafekit 0.16.0-rc.3 → 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 (91) hide show
  1. package/bin/__tests__/codex-hooks.test.js +444 -14
  2. package/bin/__tests__/codex-native.test.js +228 -7
  3. package/bin/__tests__/develop-contract.test.js +615 -185
  4. package/bin/__tests__/installer-safety.test.js +39 -0
  5. package/bin/__tests__/opencode-spec-gate.test.js +24 -16
  6. package/bin/__tests__/package-inventory.test.js +687 -13
  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 +1914 -221
  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 +143 -99
  18. package/src/claude/hooks/__tests__/completion-authority.test.js +291 -58
  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 +115 -40
  22. package/src/claude/hooks/completion-authority-check.cjs +37 -288
  23. package/src/claude/hooks/completion-authority-state.cjs +10 -8
  24. package/src/claude/hooks/completion-authority.cjs +13 -7
  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/spec-gate.cjs +47 -117
  31. package/src/claude/hooks/spec-state.cjs +8 -2
  32. package/src/claude/migration-manifest.json +9 -1
  33. package/src/claude/rules/state-sync.md +52 -21
  34. package/src/claude/rules/workflow.md +17 -9
  35. package/src/claude/scripts/spec-final-state.cjs +244 -0
  36. package/src/claude/scripts/spec-ground.cjs +535 -173
  37. package/src/claude/scripts/spec-readiness.cjs +118 -0
  38. package/src/claude/scripts/spec-receipt.cjs +162 -0
  39. package/src/claude/scripts/spec-resolver.cjs +67 -16
  40. package/src/claude/scripts/spec-scaffold.cjs +1354 -139
  41. package/src/claude/scripts/spec-semantic-model.cjs +396 -0
  42. package/src/claude/scripts/validate-spec-output.cjs +2782 -142
  43. package/src/claude/scripts/workflow-policy.cjs +501 -183
  44. package/src/claude/settings/settings.json +4 -0
  45. package/src/claude/skills/code-review/SKILL.md +12 -3
  46. package/src/claude/skills/code-review/references/spec-compliance-review.md +10 -2
  47. package/src/claude/skills/code-review/references/verification-gate.md +13 -0
  48. package/src/claude/skills/develop/SKILL.md +47 -60
  49. package/src/claude/skills/develop/references/parallel-waves.md +9 -6
  50. package/src/claude/skills/develop/references/quality-gate.md +19 -12
  51. package/src/claude/skills/specs/SKILL.md +183 -177
  52. package/src/claude/skills/specs/references/ask-user-question-gates.md +27 -18
  53. package/src/claude/skills/specs/references/cross-spec-dependency.md +8 -4
  54. package/src/claude/skills/specs/references/research-strategy.md +4 -1
  55. package/src/claude/skills/specs/references/review.md +200 -260
  56. package/src/claude/skills/specs/references/scope-inquiry.md +18 -5
  57. package/src/claude/skills/specs/rules/design-discovery-full.md +33 -81
  58. package/src/claude/skills/specs/rules/design-discovery-light.md +21 -42
  59. package/src/claude/skills/specs/rules/design-principles.md +136 -180
  60. package/src/claude/skills/specs/rules/design-review.md +42 -97
  61. package/src/claude/skills/specs/rules/ears-format.md +42 -50
  62. package/src/claude/skills/specs/rules/phase-decision-matrix.md +42 -41
  63. package/src/claude/skills/specs/rules/task-scoring-rubric.md +2 -1
  64. package/src/claude/skills/specs/rules/tasks-generation.md +189 -300
  65. package/src/claude/skills/specs/templates/design.md +49 -263
  66. package/src/claude/skills/specs/templates/requirements.md +26 -36
  67. package/src/claude/skills/specs/templates/research.md +9 -98
  68. package/src/claude/skills/specs/templates/spec-state.json +23 -85
  69. package/src/claude/skills/specs/templates/task.md +30 -102
  70. package/src/claude/skills/sync/SKILL.md +33 -10
  71. package/src/claude/skills/sync/references/sync-protocols.md +31 -13
  72. package/src/claude/skills/test/SKILL.md +17 -7
  73. package/src/codex/AGENTS.md +6 -0
  74. package/src/codex/hooks/completion-authority-check.cjs +43 -240
  75. package/src/codex/hooks/completion-authority-state.cjs +10 -8
  76. package/src/codex/hooks/completion-authority.cjs +13 -7
  77. package/src/codex/hooks/lib/hook-context.cjs +16 -2
  78. package/src/codex/hooks/lib/privacy-command-analysis.cjs +3 -0
  79. package/src/codex/hooks/lib/privacy-state.cjs +38 -16
  80. package/src/codex/hooks/lib/runtime-path-safety.cjs +3 -0
  81. package/src/codex/hooks/lib/spec-receipt.cjs +72 -134
  82. package/src/codex/hooks/lib/spec-utils.cjs +56 -5
  83. package/src/codex/hooks/privacy-approval.cjs +1 -1
  84. package/src/codex/hooks/privacy-block.cjs +67 -11
  85. package/src/codex/hooks/semantic-review-authority.cjs +130 -0
  86. package/src/codex/hooks/spec-gate.cjs +49 -34
  87. package/src/codex/hooks/spec-state.cjs +10 -3
  88. package/src/codex/hooks/state.cjs +2 -0
  89. package/src/codex/hooks.json +6 -1
  90. package/src/codex/rules/state-sync.md +47 -27
  91. package/src/common/AGENTS.md +1 -1
@@ -1,93 +1,45 @@
1
- # Full Discovery Process for Technical Design
1
+ # Full design discovery
2
2
 
3
- ## Objective
4
- Conduct comprehensive research and analysis to ensure the technical design is based on complete, accurate, and up-to-date information.
3
+ Load this rule only after the artifact router selects `Full`. Full controls
4
+ design detail; it does not select research, web access, tasks, or ceremony.
5
5
 
6
- ## Discovery Steps
6
+ ## Discovery boundary
7
7
 
8
- ### 1. Requirements Analysis
9
- **Map Requirements to Technical Needs**
10
- - Extract all functional requirements from EARS format
11
- - Identify non-functional requirements (performance, security, scalability)
12
- - Determine technical constraints and dependencies
13
- - List core technical challenges
8
+ Inspect only facts needed to remove an implementation-significant ambiguity:
14
9
 
15
- ### 2. Existing Implementation Analysis
16
- **Understand Current System** (if modifying/extending):
17
- - Analyze codebase structure and architecture patterns
18
- - Map reusable components, services, utilities
19
- - Identify domain boundaries and data flows
20
- - Document integration points and dependencies
21
- - Determine approach: extend vs refactor vs wrap
10
+ 1. map scoped requirements to existing entrypoints and behavior owners;
11
+ 2. inspect reusable contracts, data flows, dependencies, and recovery paths;
12
+ 3. identify decisions whose alternatives would change observable behavior;
13
+ 4. ground each chosen decision to repository anchors or, when needed, a
14
+ primary external source; and
15
+ 5. stop when the routed design can be implemented without a product decision.
22
16
 
23
- ### 3. Technology Research
24
- **Investigate Best Practices and Solutions**:
25
- - **Use WebSearch** to find:
26
- - Latest architectural patterns for similar problems
27
- - Industry best practices for the technology stack
28
- - Recent updates or changes in relevant technologies
29
- - Common pitfalls and solutions
17
+ Do not inventory unrelated architecture, compare fashionable patterns, or
18
+ collect findings merely because they are available. Repository scouting is
19
+ normal design work and does not by itself create `research.md`.
30
20
 
31
- - **Use WebFetch** to analyze:
32
- - Official documentation for frameworks/libraries
33
- - API references and usage examples
34
- - Migration guides and breaking changes
35
- - Performance benchmarks and comparisons
21
+ ## Research gate
36
22
 
37
- ### 4. External Dependencies Investigation
38
- **For Each External Service/Library**:
39
- - Search for official documentation and GitHub repositories
40
- - Verify API signatures and authentication methods
41
- - Check version compatibility with existing stack
42
- - Investigate rate limits and usage constraints
43
- - Find community resources and known issues
44
- - Document security considerations
45
- - Note any gaps requiring implementation investigation
23
+ Create `research.md` only when the router has found at least one of:
46
24
 
47
- ### 5. Architecture Pattern & Boundary Analysis
48
- **Evaluate Architectural Options**:
49
- - Compare relevant patterns (MVC, Clean, Hexagonal, Event-driven)
50
- - Assess fit with existing architecture and steering principles
51
- - Identify domain boundaries and ownership seams required to avoid team conflicts
52
- - Consider scalability implications and operational concerns
53
- - Evaluate maintainability and team expertise
54
- - Document preferred pattern and rejected alternatives in `research.md`
25
+ - unresolved material uncertainty that can change requirements or design;
26
+ - an external-current fact that must be grounded; or
27
+ - an explicit user request for durable research.
55
28
 
56
- ### 6. Risk Assessment
57
- **Identify Technical Risks**:
58
- - Performance bottlenecks and scaling limits
59
- - Security vulnerabilities and attack vectors
60
- - Integration complexity and coupling
61
- - Technical debt creation vs resolution
62
- - Knowledge gaps and training needs
29
+ If none applies, research is absent: do not load the research template, invoke
30
+ a researcher, search the web, or create a placeholder. When external-current
31
+ facts matter, prefer primary authoritative sources and capture only evidence
32
+ that resolves the named uncertainty. General best-practice browsing is not a
33
+ research trigger.
63
34
 
64
- ## Research Guidelines
35
+ ## Projection
65
36
 
66
- ### When to Search
67
- **Always search for**:
68
- - External API documentation and updates
69
- - Security best practices for authentication/authorization
70
- - Performance optimization techniques for identified bottlenecks
71
- - Latest versions and migration paths for dependencies
37
+ Put settled behavior, contracts, invariants, negative paths, and grounded
38
+ anchors in `design.md`. If research was selected, keep `research.md` minimal:
39
+ named uncertainty, relevant evidence, resulting decision, and remaining gaps.
40
+ Synchronize every promoted semantic decision into `spec.json`; research notes
41
+ that do not affect semantics remain supporting evidence, not authority.
72
42
 
73
- **Search if uncertain about**:
74
- - Architectural patterns for specific use cases
75
- - Industry standards for data formats/protocols
76
- - Compliance requirements (GDPR, HIPAA, etc.)
77
- - Scalability approaches for expected load
78
-
79
- ### Search Strategy
80
- 1. Start with official sources (documentation, GitHub)
81
- 2. Check recent blog posts and articles (last 6 months)
82
- 3. Review Stack Overflow for common issues
83
- 4. Investigate similar open-source implementations
84
-
85
- ## Output Requirements
86
- Capture all findings that impact design decisions in `research.md` using the shared template:
87
- - Key insights affecting architecture, technology alignment, and contracts
88
- - Constraints discovered during research
89
- - Recommended approaches and selected architecture pattern with rationale
90
- - Rejected alternatives and trade-offs (documented in the Design Decisions section)
91
- - Updated domain boundaries that inform Components & Interface Contracts
92
- - Risks and mitigation strategies
93
- - Gaps requiring further investigation during implementation
43
+ Full may add flow, data, error/recovery, security/privacy, migration, or proof
44
+ detail only when the scoped topology activates that section. Delete unused
45
+ sections rather than reserving them for implementation.
@@ -1,49 +1,28 @@
1
- # Light Discovery Process for Extensions
1
+ # Compact design discovery
2
2
 
3
- ## Objective
4
- Quickly analyze existing system and integration requirements for feature extensions.
3
+ Load this rule only after the artifact router selects `Compact`. The goal is a
4
+ bounded durable design, not a reduced version of a default research process.
5
5
 
6
- ## Focused Discovery Steps
6
+ ## Focus
7
7
 
8
- ### 1. Extension Point Analysis
9
- **Identify Integration Approach**:
10
- - Locate existing extension points or interfaces
11
- - Determine modification scope (files, components)
12
- - Check for existing patterns to follow
13
- - Identify backward compatibility requirements
8
+ 1. locate the real entrypoint and existing behavior owner;
9
+ 2. inspect the smallest set of contracts and dependencies touched by scope;
10
+ 3. record compatibility, negative-path, and verification constraints; and
11
+ 4. ground the selected anchors and stop.
14
12
 
15
- ### 2. Dependency Check
16
- **Verify Compatibility**:
17
- - Check version compatibility of new dependencies
18
- - Validate API contracts haven't changed
19
- - Ensure no breaking changes in pipeline
13
+ Keep the result in `design.md`. File lists without behavior ownership, generic
14
+ best practices, and broad architecture inventories are not useful discovery.
20
15
 
21
- ### 3. Quick Technology Verification
22
- **For New Libraries Only**:
23
- - Use WebSearch for official documentation
24
- - Verify basic usage patterns
25
- - Check for known compatibility issues
26
- - Confirm licensing compatibility
27
- - Record key findings in `research.md` (technology alignment section)
16
+ ## Research gate
28
17
 
29
- ### 4. Integration Risk Assessment
30
- **Quick Risk Check**:
31
- - Impact on existing functionality
32
- - Performance implications
33
- - Security considerations
34
- - Testing requirements
18
+ Research remains absent unless there is unresolved material uncertainty, an
19
+ external-current fact that must be grounded, or an explicit user request. A new
20
+ library is not automatically a trigger: inspect repository declarations first;
21
+ consult primary external documentation only when a current fact can change the
22
+ decision. When the gate opens, create the minimal uncertainty-to-evidence-to-
23
+ decision projection and retain any honest remaining gap.
35
24
 
36
- ## When to Escalate to Full Discovery
37
- Switch to full discovery if you find:
38
- - Significant architectural changes needed
39
- - Complex external service integrations
40
- - Security-sensitive implementations
41
- - Performance-critical components
42
- - Unknown or poorly documented dependencies
43
-
44
- ## Output Requirements
45
- - Clear integration approach (note boundary impacts in `research.md`)
46
- - List of files/components to modify
47
- - New dependencies with versions
48
- - Integration risks and mitigations
49
- - Testing focus areas
25
+ If discovery reveals cross-boundary behavior needing materially more design
26
+ detail, reclassify planning depth before persistence. If the Compact baseline
27
+ is already persisted, expand monotonically to Full; do not silently downgrade
28
+ or create optional artifacts merely to resemble Full.
@@ -1,182 +1,138 @@
1
- # Technical Design Rules and Principles
2
-
3
- ## Core Design Principles
4
-
5
- ### 1. Type Safety is Mandatory
6
- - **NEVER** use generic/loosely-typed patterns (e.g., `any` in TypeScript, `object` in Python, `interface{}` in Go unless strictly necessary)
7
- - Define explicit types for all parameters and returns
8
- - Use discriminated unions for error handling where supported
9
- - Specify generic constraints clearly
10
-
11
- ### 2. Design vs Implementation
12
- - **Focus on WHAT, not HOW**
13
- - Define interfaces and contracts, not code
14
- - Specify behavior through pre/post conditions
15
- - Document architectural decisions, not algorithms
16
-
17
- ### 3. Visual Communication
18
- - **Simple features**: Basic component diagram or none
19
- - **Medium complexity**: Architecture + data flow
20
- - **High complexity**: Multiple diagrams (architecture, sequence, state)
21
- - **Always pure Mermaid**: No styling, just structure
22
-
23
- ### 4. Component Design Rules
24
- - **Single Responsibility**: One clear purpose per component
25
- - **Clear Boundaries**: Explicit domain ownership
26
- - **Dependency Direction**: Follow architectural layers
27
- - **Interface Segregation**: Minimal, focused interfaces
28
- - **Team-safe Interfaces**: Design boundaries that allow parallel implementation without merge conflicts
29
- - **Research Traceability**: Record boundary decisions and rationale in `research.md`
30
-
31
- ### 5. Data Modeling Standards
32
- - **Domain First**: Start with business concepts
33
- - **Consistency Boundaries**: Clear aggregate roots
34
- - **Normalization**: Balance between performance and integrity
35
- - **Evolution**: Plan for schema changes
36
-
37
- ### 6. Error Handling Philosophy
38
- - **Fail Fast**: Validate early and clearly
39
- - **Graceful Degradation**: Partial functionality over complete failure
40
- - **User Context**: Actionable error messages
41
- - **Observability**: Comprehensive logging and monitoring
42
-
43
- ### 7. Integration Patterns
44
- - **Loose Coupling**: Minimize dependencies
45
- - **Contract First**: Define interfaces before implementation
46
- - **Versioning**: Plan for API evolution
47
- - **Idempotency**: Design for retry safety
48
- - **Contract Visibility**: Surface API and event contracts in design.md while linking extended details from `research.md`
49
-
50
- ## Documentation Standards
51
-
52
- ### Language and Tone
53
- - **Declarative**: "The system authenticates users" not "The system should authenticate"
54
- - **Precise**: Specific technical terms over vague descriptions
55
- - **Concise**: Essential information only
56
- - **Formal**: Professional technical writing
57
-
58
- ### Structure Requirements
59
- - **Hierarchical**: Clear section organization
60
- - **Traceable**: Requirements to components mapping
61
- - **Complete**: All aspects covered for implementation
62
- - **Consistent**: Uniform terminology throughout
63
- - **Focused**: Keep design.md centered on architecture and contracts; move investigation logs and lengthy comparisons to `research.md`
64
-
65
- ## Section Authoring Guidance
66
-
67
- ### Global Ordering
68
- - Default flow: Overview → Goals/Non-Goals → Requirements Traceability → Architecture → Technology Stack → System Flows → Components & Interfaces → Data Models → Optional sections.
69
- - Teams may swap Traceability earlier or place Data Models nearer Architecture when it improves clarity, but keep section headings intact.
70
- - Within each section, follow **Summary → Scope → Decisions → Impacts/Risks** so reviewers can scan consistently.
71
-
72
- ### Requirement IDs
73
- - Reference requirements as `2.1, 2.3` without prefixes (no “Requirement 2.1”).
74
- - All requirements MUST have numeric IDs. If a requirement lacks a numeric ID, stop and fix `requirements.md` before continuing.
75
- - Use `N.M`-style numeric IDs where `N` is the top-level requirement number from requirements.md (for example, Requirement 1 → 1.1, 1.2; Requirement 2 → 2.1, 2.2).
76
- - Every component, task, and traceability row must reference the same canonical numeric ID.
77
-
78
- ### Technology Stack
79
- - Include ONLY layers impacted by this feature (frontend, backend, data, messaging, infra).
80
- - For each layer specify tool/library + version + the role it plays; push extended rationale, comparisons, or benchmarks to `research.md`.
81
- - When extending an existing system, highlight deviations from the current stack and list new dependencies.
82
-
83
- ### System Flows
84
- - Add diagrams only when they clarify behavior:
85
- - **Sequence** for multi-step interactions
86
- - **Process/State** for branching rules or lifecycle
87
- - **Data/Event** for pipelines or async patterns
88
- - Always use pure Mermaid. If no complex flow exists, omit the entire section.
89
-
90
- ### Requirements Traceability
91
- - Use the standard table (`Requirement | Summary | Components | Interfaces | Flows`) to prove coverage.
92
- - Collapse to bullet form only when a single requirement maps 1:1 to a component.
93
- - Prefer the component summary table for simple mappings; reserve the full traceability table for complex or compliance-sensitive requirements.
94
- - Re-run this mapping whenever requirements or components change to avoid drift.
95
-
96
- ### Components & Interfaces Authoring
97
- - Group components by domain/layer and provide one block per component.
98
- - Begin with a summary table listing Component, Domain, Intent, Requirement coverage, key dependencies, and selected contracts.
99
- - Table fields: Intent (one line), Requirements (`2.1, 2.3`), Owner/Reviewers (optional).
100
- - Dependencies table must mark each entry as Inbound/Outbound/External and assign Criticality (`P0` blocking, `P1` high-risk, `P2` informational).
101
- - Summaries of external dependency research stay here; detailed investigation (API signatures, rate limits, migration notes) belongs in `research.md`.
102
- - design.md must remain a self-contained reviewer artifact. Reference `research.md` only for background, and restate any conclusions or decisions here.
103
- - Contracts: tick only the relevant types (Service/API/Event/Batch/State). Unchecked types should not appear later in the component section.
104
- - Service interfaces must declare method signatures, inputs/outputs, and error envelopes. API/Event/Batch contracts require schema tables or bullet lists covering trigger, payload, delivery, idempotency.
105
- - Use **Integration & Migration Notes**, **Validation Hooks**, and **Open Questions / Risks** to document rollout strategy, observability, and unresolved decisions.
106
- - Detail density rules:
107
- - **Full block**: components introducing new boundaries (logic hooks, shared services, external integrations, data layers).
108
- - **Summary-only**: presentational/UI components with no new boundaries (plus a short Implementation Note if needed).
109
- - Implementation Notes must combine Integration / Validation / Risks into a single bulleted subsection to reduce repetition.
110
- - Prefer lists or inline descriptors for short data (dependencies, contract selections). Use tables only when comparing multiple items.
111
-
112
- ### Shared Interfaces & Props
113
- - Define a base interface (e.g., `BaseUIPanelProps`) for recurring UI components and extend it per component to capture only the deltas.
114
- - Hooks, utilities, and integration adapters that introduce new contracts should still include full TypeScript signatures.
115
- - When reusing a base contract, reference it explicitly (e.g., “Extends `BaseUIPanelProps` with `onSubmitAnswer` callback”) instead of duplicating the code block.
116
-
117
- ### Data Models
118
- - Domain Model covers aggregates, entities, value objects, domain events, and invariants. Add Mermaid diagrams only when relationships are non-trivial.
119
- - Logical Data Model should articulate structure, indexing, sharding, and storage-specific considerations (event store, KV/wide-column) relevant to the change.
120
- - Data Contracts & Integration section documents API payloads, event schemas, and cross-service synchronization patterns when the feature crosses boundaries.
121
- - Lengthy type definitions or vendor-specific option objects should be placed in the Supporting References section within design.md, linked from the relevant section. Investigation notes stay in `research.md`.
122
- - Supporting References usage is optional; only create it when keeping the content in the main body would reduce readability. All decisions must still appear in the main sections so design.md stands alone.
123
-
124
- ### Error/Testing/Security/Performance Sections
125
- - Record only feature-specific decisions or deviations. Link or reference organization-wide standards (steering) for baseline practices instead of restating them.
126
-
127
- ### Diagram & Text Deduplication
128
- - Do not restate diagram content verbatim in prose. Use the text to highlight key decisions, trade-offs, or impacts that are not obvious from the visual.
129
- - When a decision is fully captured in the diagram annotations, a short “Key Decisions” bullet is sufficient.
130
-
131
- ### General Deduplication
132
- - Avoid repeating the same information across Overview, Architecture, and Components. Reference earlier sections when context is identical.
133
- - If a requirement/component relationship is captured in the summary table, do not rewrite it elsewhere unless extra nuance is added.
134
-
135
- ## Diagram Guidelines
136
-
137
- ### When to include a diagram
138
- - **Architecture**: Use a structural diagram when 3+ components or external systems interact.
139
- - **Sequence**: Draw a sequence diagram when calls/handshakes span multiple steps.
140
- - **State / Flow**: Capture complex state machines or business flows in a dedicated diagram.
141
- - **ER**: Provide an entity-relationship diagram for non-trivial data models.
142
- - **Skip**: Minor one-component changes generally do not need diagrams.
143
-
144
- ### Mermaid requirements
145
- ```mermaid
146
- graph TB
147
- Client --> ApiGateway
148
- ApiGateway --> ServiceA
149
- ApiGateway --> ServiceB
150
- ServiceA --> Database
1
+ # Adaptive design principles
2
+
3
+ The design exists to remove implementation guesses. It defines behavior-owning
4
+ boundaries and stable contracts without prescribing incidental code.
5
+
6
+ ## Detail by planning depth
7
+
8
+ ### Compact
9
+
10
+ Keep only:
11
+
12
+ 1. boundary and responsibilities;
13
+ 2. typed source anchors;
14
+ 3. decisions, named contracts, and invariants needed for consistency; and
15
+ 4. verification, including relevant negative paths.
16
+
17
+ Delete every unused heading. Compact is a complete durable design, not a teaser
18
+ for a later Full document.
19
+
20
+ ### Full
21
+
22
+ Start from Compact. Add only relevant sections for:
23
+
24
+ - cross-boundary contracts and flows;
25
+ - data ownership, schema, consistency, and concurrency;
26
+ - error classification and recovery;
27
+ - security/privacy boundaries;
28
+ - migration, compatibility, rollback, or deployment transition; and
29
+ - proof that spans owners or runtime surfaces.
30
+
31
+ Do not add a section because the template contains it. Empty tables, generic
32
+ best practices, and restated requirements form a template cemetery and must be
33
+ deleted.
34
+
35
+ ## Boundaries and typed anchors
36
+
37
+ A boundary names what owns, reads, writes, calls, registers, or exposes the
38
+ behavior. “Service”, “module”, or “layer” without a grounded target is invalid.
39
+
40
+ Design and task anchors use the same closed six-column machine model:
41
+ `ID | Type | Target | Role | Access | Action`. Every implementation-facing
42
+ anchor has:
43
+
44
+ | Field | Rule |
45
+ |---|---|
46
+ | ID | Unique across the entire spec. Design-owned anchors use `A-D-NN`; task-owned anchors use `A-R{requirement}-{sequence}-NN`. |
47
+ | Type | `file`, `symbol`, `command`, `route`, `schema`, `contract`, `artifact`, or `external`. |
48
+ | Target | Exact path, identifier, command, route, schema object, contract ID, artifact path, or primary source. |
49
+ | Role | Why the target matters: owner, consumer, entrypoint, proof, constraint, or reference. |
50
+ | Access | `read` or `write`. |
51
+ | Action | `read` for read access; `create`, `modify`, or `delete` for write access. |
52
+
53
+ Files-first is canonical. List `file` anchors before symbols, routes, schemas,
54
+ or contracts they contain. A symbol anchor names its file. A command anchor is
55
+ an exact project command. An external anchor states which decision it grounds.
56
+ Role is descriptive only and never implies Action; words such as create,
57
+ planned, new, producer, or output in prose have zero machine authority. Never
58
+ reuse an anchor ID, even in another task. A task that consumes a canonical
59
+ design anchor references its `A-D-NN` ID and does not redefine the same target in
60
+ its task-scoped namespace.
61
+
62
+ ## Named contracts and invariants
63
+
64
+ - Give every implementation-significant contract and invariant a stable ID,
65
+ such as `C1` or `I1`.
66
+ - Define the canonical body once in `design.md`.
67
+ - Task files reference IDs; they do not copy contract bodies.
68
+ - Name one implementation owner before any cross-task consumer. Consumers
69
+ depend directly or transitively on the owner.
70
+ - If implementation needs a different contract, revise and explicitly approve
71
+ the design before changing consumers.
72
+
73
+ Contracts are required when drift could change auth/session, transport, API or
74
+ event shape, persistence/schema, deletion/retention, generated artifacts,
75
+ runtime entrypoints, or recovery behavior. Do not invent contract ceremony for
76
+ local details that cannot drift across a boundary.
77
+
78
+ For any public, replay, or operator surface contract, specify method, route,
79
+ auth, required headers, request schema, success response, error semantics, and
80
+ idempotency/concurrency behavior in one place; a partial contract is not a
81
+ contract.
82
+
83
+ ## Decision quality
84
+
85
+ Record a decision only when another reasonable implementation would behave
86
+ differently. For each decision state:
87
+
88
+ - chosen behavior and boundary;
89
+ - relevant alternative or ambiguity rejected;
90
+ - invariant or negative path that constrains implementation; and
91
+ - anchor or evidence that makes it feasible.
92
+
93
+ Use explicit types for public inputs, outputs, states, and errors. Avoid generic
94
+ `any`, `object`, or unbounded maps unless the contract explains why they are
95
+ intentional.
96
+
97
+ ## Conditional detail
98
+
99
+ - Flow: include only for branching, asynchronous, or multi-party behavior.
100
+ - Data: include only when shape, ownership, consistency, or lifecycle changes. Any retention/lifecycle policy must state clock anchor, clock source, timezone/precision, cutoff comparator/inclusivity, enforcement boundary, and a wrong-clock/boundary counterexample; domain-generic.
101
+ - Error/recovery: include concrete triggers, responses, retry/rollback, and
102
+ terminal states only when relevant.
103
+ - Security/privacy: include trust boundary, authorization, sensitive data, and
104
+ retention decisions only when touched.
105
+ - Migration: include compatibility window, ordering, rollback trigger, and
106
+ verification only when existing state or public contracts change.
107
+ - Diagrams: use plain Mermaid only when the relationship is materially clearer
108
+ than prose; do not duplicate the diagram in text.
109
+
110
+ ## Traceability and verification
111
+
112
+ Every acceptance criterion has exactly one implementation owner and maps to a
113
+ boundary, contract/invariant, or explicit verification definition. Keep exactly
114
+ one visible `## Verification Definitions`
115
+ section. The validator's canonical grammar is a single line per definition:
116
+
117
+ ```markdown
118
+ - **V1**: Criteria R1.1; Owner A-D-01; Decision refs D1, I1, C1; Method command `npm test`; Expected exit 0 and the persisted state; Negative/failure invalid input returns the named error; Reachability/grounding entrypoint `src/entry.js` via A-D-01.
151
119
  ```
152
120
 
153
- - **Plain Mermaid only** – avoid custom styling or unsupported syntax.
154
- - **Node IDs** – alphanumeric plus underscores only (e.g., `Client`, `ServiceA`). Do not use `@`, `/`, or leading `-`.
155
- - **Labels** – simple words. Do not embed parentheses `()`, square brackets `[]`, quotes `"`, or slashes `/`.
156
- - ❌ `DnD[@dnd-kit/core]` → invalid ID (`@`).
157
- - ❌ `UI[KanbanBoard(React)]` → invalid label (`()`).
158
- - ✅ `DndKit[dnd-kit core]` → use plain text in labels, keep technology details in the accompanying description.
159
- - ℹ️ Mermaid strict-mode will otherwise fail with errors like `Expecting 'SQE' ... got 'PS'`; remove punctuation from labels before rendering.
160
- - **Edges** – show data or control flow direction.
161
- - **Groups** – using Mermaid subgraphs to cluster related components is allowed; use it sparingly for clarity.
162
-
163
- ## Quality Metrics
164
- ### Design Completeness Checklist
165
- - All requirements addressed
166
- - No implementation details leaked
167
- - Clear component boundaries
168
- - Explicit error handling
169
- - Comprehensive test strategy
170
- - Security considered
171
- - Performance targets defined
172
- - Migration path clear (if applicable)
173
-
174
- ### Common Anti-patterns to Avoid
175
- ❌ Mixing design with implementation
176
- ❌ Vague interface definitions
177
- ❌ Missing error scenarios
178
- ❌ Ignored non-functional requirements
179
- ❌ Overcomplicated architectures
180
- ❌ Tight coupling between components
181
- ❌ Missing data consistency strategy
182
- ❌ Incomplete dependency analysis
121
+ Do not use a V table, `### V1` heading, or prose-only “see verification” alias;
122
+ the semantic-review parser recognizes the bold V-ID line above. Each line names
123
+ every exact `RN.M` it covers, all applicable `D`/`I`/`C` refs, a command or anchored
124
+ inspection, observable expected result, concrete negative/failure case, and
125
+ runtime reachability plus grounding expectation.
126
+
127
+ For a typed proof boundary, extend the same line after Owner with `Proof criteria
128
+ R1.2; Proof owner A-D-02; Evidence anchor A-D-02;`. Both criteria remain
129
+ single-owner; without that boundary, omit the extension.
130
+
131
+ Validator success proves structure only. The author and reviewer still test the
132
+ design against concrete counterexamples and check that an implementer can act
133
+ without choosing unspecified product behavior.
134
+
135
+ For task-bearing specs, typed `spec.json.coordination.boundaries` are the only
136
+ authority for ownership, dependencies, transitions, proof separation, and
137
+ parallel eligibility. Design prose explains semantics but cannot replace those
138
+ typed edges.