forgecraft-mcp 1.2.0 → 1.3.2

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 (136) hide show
  1. package/README.md +525 -525
  2. package/dist/cli/help.js +44 -44
  3. package/dist/registry/renderer-skeletons.js +92 -92
  4. package/dist/shared/gs-score-logger.js +6 -6
  5. package/dist/tools/add-module.js +123 -123
  6. package/dist/tools/advice-registry.js +18 -18
  7. package/dist/tools/check-cascade-report.js +64 -64
  8. package/dist/tools/configure-mcp.d.ts +3 -0
  9. package/dist/tools/configure-mcp.d.ts.map +1 -1
  10. package/dist/tools/configure-mcp.js +10 -0
  11. package/dist/tools/configure-mcp.js.map +1 -1
  12. package/dist/tools/forgecraft-dispatch.d.ts.map +1 -1
  13. package/dist/tools/forgecraft-dispatch.js +3 -0
  14. package/dist/tools/forgecraft-dispatch.js.map +1 -1
  15. package/dist/tools/forgecraft-schema-params.d.ts +9 -0
  16. package/dist/tools/forgecraft-schema-params.d.ts.map +1 -1
  17. package/dist/tools/forgecraft-schema-params.js +21 -0
  18. package/dist/tools/forgecraft-schema-params.js.map +1 -1
  19. package/dist/tools/forgecraft-schema.d.ts +9 -0
  20. package/dist/tools/forgecraft-schema.d.ts.map +1 -1
  21. package/dist/tools/refresh-output.js +14 -14
  22. package/dist/tools/scaffold-spec-stubs.js +115 -115
  23. package/dist/tools/scaffold-templates.js +62 -62
  24. package/dist/tools/setup-artifact-writers.d.ts +30 -0
  25. package/dist/tools/setup-artifact-writers.d.ts.map +1 -1
  26. package/dist/tools/setup-artifact-writers.js +120 -8
  27. package/dist/tools/setup-artifact-writers.js.map +1 -1
  28. package/dist/tools/setup-phase1.d.ts +3 -0
  29. package/dist/tools/setup-phase1.d.ts.map +1 -1
  30. package/dist/tools/setup-phase1.js +79 -35
  31. package/dist/tools/setup-phase1.js.map +1 -1
  32. package/dist/tools/setup-phase2.d.ts +2 -0
  33. package/dist/tools/setup-phase2.d.ts.map +1 -1
  34. package/dist/tools/setup-phase2.js +10 -1
  35. package/dist/tools/setup-phase2.js.map +1 -1
  36. package/dist/tools/setup-project.d.ts +18 -0
  37. package/dist/tools/setup-project.d.ts.map +1 -1
  38. package/dist/tools/setup-project.js +77 -1
  39. package/dist/tools/setup-project.js.map +1 -1
  40. package/dist/tools/spec-parser-tags.d.ts +9 -0
  41. package/dist/tools/spec-parser-tags.d.ts.map +1 -1
  42. package/dist/tools/spec-parser-tags.js +92 -0
  43. package/dist/tools/spec-parser-tags.js.map +1 -1
  44. package/package.json +89 -86
  45. package/templates/analytics/instructions.yaml +37 -37
  46. package/templates/analytics/mcp-servers.yaml +11 -11
  47. package/templates/analytics/structure.yaml +25 -25
  48. package/templates/api/instructions.yaml +231 -231
  49. package/templates/api/mcp-servers.yaml +22 -13
  50. package/templates/api/nfr.yaml +23 -23
  51. package/templates/api/review.yaml +103 -103
  52. package/templates/api/structure.yaml +34 -34
  53. package/templates/api/verification.yaml +132 -132
  54. package/templates/cli/instructions.yaml +31 -31
  55. package/templates/cli/mcp-servers.yaml +11 -11
  56. package/templates/cli/review.yaml +53 -53
  57. package/templates/cli/structure.yaml +16 -16
  58. package/templates/data-lineage/instructions.yaml +28 -28
  59. package/templates/data-lineage/mcp-servers.yaml +22 -22
  60. package/templates/data-pipeline/instructions.yaml +84 -84
  61. package/templates/data-pipeline/mcp-servers.yaml +13 -13
  62. package/templates/data-pipeline/nfr.yaml +39 -39
  63. package/templates/data-pipeline/structure.yaml +23 -23
  64. package/templates/fintech/hooks.yaml +55 -55
  65. package/templates/fintech/instructions.yaml +112 -112
  66. package/templates/fintech/mcp-servers.yaml +13 -13
  67. package/templates/fintech/nfr.yaml +46 -46
  68. package/templates/fintech/playbook.yaml +210 -210
  69. package/templates/fintech/verification.yaml +239 -239
  70. package/templates/game/instructions.yaml +289 -289
  71. package/templates/game/mcp-servers.yaml +38 -38
  72. package/templates/game/nfr.yaml +64 -64
  73. package/templates/game/playbook.yaml +214 -214
  74. package/templates/game/review.yaml +97 -97
  75. package/templates/game/structure.yaml +67 -67
  76. package/templates/game/verification.yaml +174 -174
  77. package/templates/healthcare/instructions.yaml +42 -42
  78. package/templates/healthcare/mcp-servers.yaml +13 -13
  79. package/templates/healthcare/nfr.yaml +47 -47
  80. package/templates/hipaa/instructions.yaml +41 -41
  81. package/templates/hipaa/mcp-servers.yaml +13 -13
  82. package/templates/infra/instructions.yaml +104 -104
  83. package/templates/infra/mcp-servers.yaml +20 -20
  84. package/templates/infra/nfr.yaml +46 -46
  85. package/templates/infra/review.yaml +65 -65
  86. package/templates/infra/structure.yaml +25 -25
  87. package/templates/library/instructions.yaml +36 -36
  88. package/templates/library/mcp-servers.yaml +20 -20
  89. package/templates/library/review.yaml +56 -56
  90. package/templates/library/structure.yaml +19 -19
  91. package/templates/medallion-architecture/instructions.yaml +41 -41
  92. package/templates/medallion-architecture/mcp-servers.yaml +22 -22
  93. package/templates/ml/instructions.yaml +85 -85
  94. package/templates/ml/mcp-servers.yaml +11 -11
  95. package/templates/ml/nfr.yaml +39 -39
  96. package/templates/ml/structure.yaml +25 -25
  97. package/templates/ml/verification.yaml +156 -156
  98. package/templates/mobile/instructions.yaml +44 -44
  99. package/templates/mobile/mcp-servers.yaml +11 -11
  100. package/templates/mobile/nfr.yaml +49 -49
  101. package/templates/mobile/structure.yaml +27 -27
  102. package/templates/mobile/verification.yaml +121 -121
  103. package/templates/observability-xray/instructions.yaml +40 -40
  104. package/templates/observability-xray/mcp-servers.yaml +15 -15
  105. package/templates/realtime/instructions.yaml +42 -42
  106. package/templates/realtime/mcp-servers.yaml +13 -13
  107. package/templates/soc2/instructions.yaml +41 -41
  108. package/templates/soc2/mcp-servers.yaml +24 -24
  109. package/templates/social/instructions.yaml +43 -43
  110. package/templates/social/mcp-servers.yaml +24 -24
  111. package/templates/state-machine/instructions.yaml +42 -42
  112. package/templates/state-machine/mcp-servers.yaml +11 -11
  113. package/templates/tools-registry.yaml +164 -164
  114. package/templates/universal/hooks.yaml +531 -531
  115. package/templates/universal/instructions.yaml +1692 -1692
  116. package/templates/universal/mcp-servers.yaml +50 -50
  117. package/templates/universal/nfr.yaml +197 -197
  118. package/templates/universal/reference.yaml +326 -326
  119. package/templates/universal/review.yaml +204 -204
  120. package/templates/universal/skills.yaml +262 -262
  121. package/templates/universal/structure.yaml +67 -67
  122. package/templates/universal/verification.yaml +416 -416
  123. package/templates/web-react/hooks.yaml +44 -44
  124. package/templates/web-react/instructions.yaml +207 -207
  125. package/templates/web-react/mcp-servers.yaml +20 -20
  126. package/templates/web-react/nfr.yaml +27 -27
  127. package/templates/web-react/review.yaml +94 -94
  128. package/templates/web-react/structure.yaml +46 -46
  129. package/templates/web-react/verification.yaml +126 -126
  130. package/templates/web-static/instructions.yaml +115 -115
  131. package/templates/web-static/mcp-servers.yaml +20 -20
  132. package/templates/web3/instructions.yaml +44 -44
  133. package/templates/web3/mcp-servers.yaml +11 -11
  134. package/templates/web3/verification.yaml +159 -159
  135. package/templates/zero-trust/instructions.yaml +41 -41
  136. package/templates/zero-trust/mcp-servers.yaml +15 -15
@@ -1,326 +1,326 @@
1
- tag: UNIVERSAL
2
- section: reference
3
- blocks:
4
- - id: domain-driven-design
5
- title: "Domain-Driven Design Essentials"
6
- content: |
7
- ## Domain-Driven Design (DDD) Essentials
8
-
9
- ### Entities vs. Value Objects
10
- - **Entity**: has identity (ID) that persists across state changes. Two users with the
11
- same name are NOT the same user. Compared by ID.
12
- - **Value Object**: defined by its attributes, not identity. Two `Money(100, "USD")` are
13
- the same. Immutable. Compared by value.
14
- - When in doubt, make it a Value Object — they're simpler and safer.
15
-
16
- ### Eliminate Primitive Obsession
17
- - Don't use raw `string` for email, `number` for currency, `string` for phone.
18
- - Wrap domain concepts in typed Value Objects: `EmailAddress`, `Money`, `PhoneNumber`.
19
- - Value Objects enforce validation at construction — an invalid email can never exist.
20
- - This moves validation FROM every call site TO the constructor — DRY + safe.
21
-
22
- ### Aggregates
23
- - An aggregate is a cluster of domain objects treated as a single unit for data changes.
24
- - One entity is the **aggregate root** — all external access goes through it.
25
- - Aggregates enforce invariants: `Order` ensures its `OrderLines` don't exceed the limit.
26
- - Reference other aggregates by ID, not by direct object reference.
27
-
28
- ### Bounded Contexts
29
- - A bounded context is a boundary within which a domain model has a specific meaning.
30
- - The word "Account" means different things in Billing vs. Auth vs. Social.
31
- - Each context owns its models, language, and persistence — no shared database tables.
32
- - Contexts communicate via well-defined interfaces, events, or an **Anti-Corruption Layer**
33
- that translates between contexts.
34
-
35
- ### Domain Events
36
- - When something important happens in the domain, publish an event: `OrderPlaced`,
37
- `MemberDeactivated`, `PaymentFailed`.
38
- - Events decouple modules: the Order module publishes `OrderPlaced`, the Notification
39
- module subscribes — neither imports the other.
40
- - Events are past-tense named facts. They carry the data needed by subscribers.
41
- - In-process event bus for monoliths; message broker (SQS, Kafka, NATS) for distributed.
42
-
43
- - id: cqrs-event-patterns
44
- title: "CQRS & Event Patterns"
45
- content: |
46
- ## CQRS & Event-Driven Patterns
47
-
48
- ### CQRS (Command Query Responsibility Segregation)
49
- When read and write patterns diverge significantly:
50
- - **Command side**: validates, enforces business rules, writes to the canonical store.
51
- - **Query side**: reads from optimized read models (denormalized views, search indices).
52
- - Start simple: same database, separate service methods. Optimize to separate stores
53
- only when read/write scaling demands it.
54
- - CQRS is not mandatory everywhere — use it where read/write asymmetry is real.
55
-
56
- ### Event Sourcing (when appropriate)
57
- - Store the sequence of events, not just current state.
58
- - Useful for: audit trails, temporal queries, debugging, undo/redo.
59
- - NOT appropriate for: simple CRUD, low-value data, early-stage features.
60
- - If you use event sourcing, you MUST also maintain a read-projection.
61
-
62
- ### Pub/Sub & Message Patterns
63
- - **Fire and forget**: publish event, don't wait for subscribers.
64
- - **Request/Reply**: send command, wait for response.
65
- - In-process: use an event emitter or mediator.
66
- - Distributed: use durable message queues with at-least-once delivery.
67
-
68
- - id: design-patterns-reference
69
- title: "Design Patterns Quick Reference"
70
- content: |
71
- ## Design Patterns — When to Reach for What
72
-
73
- ### Creational
74
- - **Factory Method / Abstract Factory**: Use when instantiation logic is complex or varies by context.
75
- Prefer over `new` in business logic — keep constructors for DI only.
76
- - **Builder**: Use when constructing objects with many optional parameters. Fluent API preferred.
77
- - **Singleton**: Almost never in application code. Use DI to manage lifecycle instead.
78
- Acceptable only for: loggers, config singletons in composition root.
79
-
80
- ### Structural
81
- - **Adapter**: Wrap third-party APIs to match your port interfaces. Isolates vendor lock-in.
82
- - **Facade**: Simplify complex subsystem interactions behind a unified interface.
83
- Every module's public exports are a facade.
84
- - **Decorator**: Add behavior (logging, caching, retry, auth) without modifying the original.
85
- Middleware pipelines are decorator chains.
86
- - **Proxy**: Lazy loading, access control, or caching in front of expensive resources.
87
-
88
- ### Behavioral
89
- - **Strategy**: Extract interchangeable algorithms behind an interface. Inject the right one.
90
- Examples: pricing calculators, render strategies, sort algorithms.
91
- - **Observer / Pub-Sub**: Decouple event producers from consumers. Use for: domain events,
92
- UI state changes, webhook fan-out. See CQRS & Event Patterns section.
93
- - **Chain of Responsibility**: Middleware pipelines (Express, Koa). Each handler decides
94
- to process or pass to the next. Order matters.
95
- - **Command**: Encapsulate actions as objects. Enables: undo/redo, queuing, audit trail.
96
-
97
- ### Enterprise
98
- - **Repository**: Encapsulate data access behind a collection-like interface. Defined in the
99
- domain layer, implemented in the infrastructure layer as adapters.
100
- - **Unit of Work**: Track changes within a transaction boundary. Commit or roll back atomically.
101
- Pair with Repository for database operations.
102
- - **Saga**: Coordinate multi-step distributed operations. Each step has a compensating action
103
- for rollback. Use for: order processing, payment flows, multi-service workflows.
104
- - **Outbox**: Write events to a local outbox table in the same transaction as the state change.
105
- A separate process reliably publishes them. Guarantees at-least-once event delivery.
106
-
107
- ### Anti-Patterns to Avoid
108
- - **God Object**: One class that knows/does everything. Split by responsibility.
109
- - **Service Locator**: Global registry looked up at runtime. Use constructor injection instead.
110
- - **Anemic Domain Model**: Entities with only getters/setters, logic in services.
111
- Push behavior into domain objects.
112
-
113
- # ── GS Practitioner Protocol — on-demand only (not inlined in CLAUDE.md) ────
114
-
115
- - id: gs-guidance-session-loop
116
- title: "GS — Session Loop Procedure"
117
- topic: guidance
118
- content: |
119
- ## Generative Specification: Session Loop
120
-
121
- Every session begins and ends at the same steady state: code, tests, and documentation
122
- mutually consistent; the specification accurately describing what exists; the commit
123
- history recording how it changed; Status.md capturing intent for the next session.
124
- A session that ends with passing tests but a stale specification has not completed the loop.
125
-
126
- ### Phase 1 — Intake and Clarification
127
- Check for exactly two conditions before implementation begins:
128
- - **Ambiguity**: the request admits two or more valid interpretations producing different implementations.
129
- - **Unverifiable assumptions**: the request presupposes facts about scope, schema, or behavior
130
- not verifiable from the current codebase.
131
-
132
- If either is present, batch ALL clarifying questions into a single prompt — answered once.
133
- If neither is present, implementation proceeds immediately.
134
- The constraint on asking is as important as the obligation to ask.
135
-
136
- ### Phase 2 — Specification Gate ⛔
137
- Before any code is written: does this change **fit** the existing specification, or does
138
- it **change** it?
139
- - A feature the specification anticipates: implement directly.
140
- - A feature the specification does not yet cover: **update the specification first**.
141
- The ADR, the schema change, the new constitution section — these precede implementation.
142
- Code written against the old specification is wrong by the grammar it was supposed to
143
- serve, regardless of whether the tests pass.
144
-
145
- ### Phase 3 — Implementation and Verification
146
- Three conditions must hold before any commit:
147
- 1. Full test suite passes.
148
- 2. Feature exercised at the HTTP or CLI boundary — not only unit-tested internally.
149
- 3. No new anti-patterns: no hardcoded values, no bare exception throws, no diagnostic
150
- logging in production paths.
151
-
152
- ### Phase 4 — Documentation Cascade
153
- After a passing commit, restore all artifacts to consistency in this order:
154
- 1. Spec files — if a public contract changed (endpoint, CLI command, schema).
155
- 2. ADR — if a non-obvious architectural decision was made.
156
- 3. Architectural constitution — if a new pattern was established for future sessions.
157
- 4. Architecture diagrams — if a new component or boundary was introduced.
158
- 5. Sequence diagrams — if a new inter-component flow was added.
159
- 6. Tech spec — if implementation diverged from the written spec (spec is the truth; update it).
160
- 7. Status.md — every session, without exception.
161
-
162
- The cascade closes the loop. A session that skips this phase has not completed.
163
-
164
- - id: gs-guidance-context-loading
165
- title: "GS — Context Loading Strategy"
166
- topic: guidance
167
- content: |
168
- ## Generative Specification: Context Loading Strategy
169
-
170
- The order in which artifacts are loaded at session start determines what the AI holds
171
- as authoritative. Load in this order:
172
-
173
- 1. **Architectural constitution** (`CLAUDE.md`) first. This is the grammar. Everything
174
- else is read against it.
175
- 2. **Technical specification** — the section relevant to this session's scope. Load the
176
- whole document for cross-cutting tasks; load the relevant section for bounded tasks.
177
- 3. **Active ADRs** — those covering the area being modified. Do not load the full ADR
178
- directory on every session; load the decisions that govern the current scope.
179
- 4. **Status.md** — what was done, what is in progress, what is next.
180
- 5. **Session prompt** — last, after all context artifacts are loaded.
181
-
182
- ### What to Exclude
183
- Test files (unless the session is about the test suite), generated files, `node_modules`,
184
- `dist`, `build`, lock files. Context budget is finite; loading noise competes with signal.
185
-
186
- ### MCP Server Budget
187
- Maximum **three** active MCP servers in any session:
188
- - Built-in file/search/terminal tools (treated as one).
189
- - Optionally one semantic search tool (CodeSeeker) for large codebases.
190
- - Optionally one specification-management tool (ForgeCraft).
191
-
192
- Each declared tool is read by the model on every turn whether invoked or not. Beyond
193
- three servers, tooling overhead begins to compete with the specification for context attention.
194
-
195
- - id: gs-guidance-bound-roadmap
196
- title: "GS — Bound Roadmap and Waiting State"
197
- topic: guidance
198
- content: |
199
- ## Generative Specification: Bound Roadmap
200
-
201
- A roadmap item without a pre-generated prompt is a task title — it requires the
202
- practitioner to reconstruct context at execution time. A roadmap item *with* a bound
203
- prompt is an independent execution unit: it already contains the specification references,
204
- the acceptance criteria, and the verification steps.
205
-
206
- Bound prompts live in `DEVELOPMENT_PROMPTS.md` (Procedural Memory). This file is a
207
- first-class specification artifact. The criteria for "specific enough" is:
208
- can the agent execute this prompt to completion without any narration?
209
-
210
- ### Bound Prompt Format
211
- ```markdown
212
- ## [Prompt ID] — [Feature or Task Name]
213
-
214
- **Specification references:** [Artifacts to load before beginning]
215
- **Precondition:** [What must be true before this task begins]
216
- **Scope:** [What to build AND what NOT to touch]
217
- **Acceptance criteria:**
218
- - [ ] [Specific, verifiable criterion]
219
- - [ ] [Full test suite passes]
220
- - [ ] [Feature exercised at HTTP or CLI boundary]
221
- **Architecture constraints:** [Layer rules or patterns specific to this task]
222
- **Commit message:** feat([scope]): [description]
223
- ```
224
-
225
- "Build the connection system" is not a bound prompt.
226
- "Implement the `createConnection` service method against the `ConnectionRepository`
227
- interface, write unit tests for all three error paths, verify via HTTP test against
228
- `/connections`, run the full suite before committing" is a bound prompt.
229
-
230
- ### Valid Waiting State
231
- A project in a valid waiting state requires zero practitioner effort until cycled back.
232
- Requirements:
233
- - Current commit passes the full test suite.
234
- - Status.md names the immediate next action specifically enough to begin from it alone.
235
- - No partial work in the working tree — everything is committed or staged with a note.
236
- - Inflight ADR decisions are noted in Status.md.
237
-
238
- Cycling back in: read Status.md → run test suite → load bound prompt → begin.
239
- The specification holds the context. The practitioner holds nothing.
240
-
241
- - id: gs-guidance-incremental-cascade
242
- title: "GS — Incremental Cascade"
243
- topic: guidance
244
- content: |
245
- ## Generative Specification: Incremental Cascade
246
-
247
- Every change consists of two decisions: *what* to change and *which artifacts* that
248
- change affects. The incremental cascade manages the second decision.
249
-
250
- ### 1. Name the Delta
251
- Observe something: a discrepancy in the running system, a new requirement, a bug. Write
252
- it in precise terms. Vague deltas produce vague cascades.
253
-
254
- ### 2. Change Impact Assessment (CIA)
255
- Before propagating anything: Which artifacts reference the changed element? Which roadmap
256
- items in progress share a dependency with it? Does the delta change a shared interface
257
- contract or schema? Skipping CIA risks propagating a change into implementation before
258
- discovering it breaks a parallel item already in progress.
259
-
260
- ### 3. Determine Minimum Cascade Depth
261
- | Change Type | Minimum Depth |
262
- |---|---|
263
- | Bug the spec correctly describes | Implementation only |
264
- | New behavior within existing architecture | Use case, possibly tech spec |
265
- | New component or service boundary | C4 → constitution → ADR → use cases → implementation |
266
- | Change to shared interface contract | Contract spec → dependent use cases → all affected prompts → implementation |
267
-
268
- ### 4. Propagate Upward First, Then Downward
269
- When a layer needs updating, all layers above it are made consistent **before** any layer
270
- below it receives the change.
271
- ```
272
- Functional specification ← top
273
-
274
- Architecture / C4 diagrams
275
-
276
- Architectural constitution (CLAUDE.md)
277
-
278
- ADRs
279
-
280
- Use cases / sequence diagrams
281
-
282
- Implementation + tests ← bottom
283
- ```
284
- Code that was correct relative to the old specification and is now wrong relative to the new
285
- one is a derivation gap, not a bug. The correct response is re-derivation, not patching.
286
-
287
- ### 5. Close the Cascade
288
- After implementation commits, run Phase 4 (Documentation Cascade) of the session loop
289
- to restore all artifacts to consistency.
290
-
291
- - id: gs-guidance-diagnostic-checklist
292
- title: "GS — Memory Diagnostic Checklist"
293
- topic: guidance
294
- content: |
295
- ## Generative Specification: Diagnostic Checklist
296
-
297
- Run before beginning any session on a new or inherited project. A "no" on any semantic
298
- or procedural item is a **blocker** — fill the gap before implementation begins.
299
- A "no" on episodic, relationship, or working items must be resolved in the first 10 minutes.
300
-
301
- ```
302
- SEMANTIC MEMORY
303
- [ ] CLAUDE.md exists and is current (describes the current architecture, not a prior one)
304
- [ ] Technical specification covers current scope
305
- [ ] Domain vocabulary is defined (no ambiguous names across modules)
306
-
307
- PROCEDURAL MEMORY
308
- [ ] Bound prompts exist for the next 3+ roadmap items (DEVELOPMENT_PROMPTS.md)
309
- [ ] CI/CD pipeline is specified (not just configured)
310
- [ ] Pre-commit hooks are active and tested
311
-
312
- EPISODIC MEMORY
313
- [ ] ADRs exist for every non-obvious architectural decision currently in force
314
- [ ] Status.md was updated at the close of the last session
315
- [ ] Git history is typed (conventional commits, not 'wip' and 'changes')
316
-
317
- RELATIONSHIP MEMORY
318
- [ ] C4 context and container diagrams are current
319
- [ ] Primary flows have sequence diagrams
320
- [ ] Use cases cover every behavioral contract being modified this session
321
-
322
- WORKING MEMORY
323
- [ ] Session prompt is specific enough to begin without narration
324
- [ ] Context loading plan covers what's needed and excludes what isn't
325
- [ ] MCP server count ≤ 3
326
- ```
1
+ tag: UNIVERSAL
2
+ section: reference
3
+ blocks:
4
+ - id: domain-driven-design
5
+ title: "Domain-Driven Design Essentials"
6
+ content: |
7
+ ## Domain-Driven Design (DDD) Essentials
8
+
9
+ ### Entities vs. Value Objects
10
+ - **Entity**: has identity (ID) that persists across state changes. Two users with the
11
+ same name are NOT the same user. Compared by ID.
12
+ - **Value Object**: defined by its attributes, not identity. Two `Money(100, "USD")` are
13
+ the same. Immutable. Compared by value.
14
+ - When in doubt, make it a Value Object — they're simpler and safer.
15
+
16
+ ### Eliminate Primitive Obsession
17
+ - Don't use raw `string` for email, `number` for currency, `string` for phone.
18
+ - Wrap domain concepts in typed Value Objects: `EmailAddress`, `Money`, `PhoneNumber`.
19
+ - Value Objects enforce validation at construction — an invalid email can never exist.
20
+ - This moves validation FROM every call site TO the constructor — DRY + safe.
21
+
22
+ ### Aggregates
23
+ - An aggregate is a cluster of domain objects treated as a single unit for data changes.
24
+ - One entity is the **aggregate root** — all external access goes through it.
25
+ - Aggregates enforce invariants: `Order` ensures its `OrderLines` don't exceed the limit.
26
+ - Reference other aggregates by ID, not by direct object reference.
27
+
28
+ ### Bounded Contexts
29
+ - A bounded context is a boundary within which a domain model has a specific meaning.
30
+ - The word "Account" means different things in Billing vs. Auth vs. Social.
31
+ - Each context owns its models, language, and persistence — no shared database tables.
32
+ - Contexts communicate via well-defined interfaces, events, or an **Anti-Corruption Layer**
33
+ that translates between contexts.
34
+
35
+ ### Domain Events
36
+ - When something important happens in the domain, publish an event: `OrderPlaced`,
37
+ `MemberDeactivated`, `PaymentFailed`.
38
+ - Events decouple modules: the Order module publishes `OrderPlaced`, the Notification
39
+ module subscribes — neither imports the other.
40
+ - Events are past-tense named facts. They carry the data needed by subscribers.
41
+ - In-process event bus for monoliths; message broker (SQS, Kafka, NATS) for distributed.
42
+
43
+ - id: cqrs-event-patterns
44
+ title: "CQRS & Event Patterns"
45
+ content: |
46
+ ## CQRS & Event-Driven Patterns
47
+
48
+ ### CQRS (Command Query Responsibility Segregation)
49
+ When read and write patterns diverge significantly:
50
+ - **Command side**: validates, enforces business rules, writes to the canonical store.
51
+ - **Query side**: reads from optimized read models (denormalized views, search indices).
52
+ - Start simple: same database, separate service methods. Optimize to separate stores
53
+ only when read/write scaling demands it.
54
+ - CQRS is not mandatory everywhere — use it where read/write asymmetry is real.
55
+
56
+ ### Event Sourcing (when appropriate)
57
+ - Store the sequence of events, not just current state.
58
+ - Useful for: audit trails, temporal queries, debugging, undo/redo.
59
+ - NOT appropriate for: simple CRUD, low-value data, early-stage features.
60
+ - If you use event sourcing, you MUST also maintain a read-projection.
61
+
62
+ ### Pub/Sub & Message Patterns
63
+ - **Fire and forget**: publish event, don't wait for subscribers.
64
+ - **Request/Reply**: send command, wait for response.
65
+ - In-process: use an event emitter or mediator.
66
+ - Distributed: use durable message queues with at-least-once delivery.
67
+
68
+ - id: design-patterns-reference
69
+ title: "Design Patterns Quick Reference"
70
+ content: |
71
+ ## Design Patterns — When to Reach for What
72
+
73
+ ### Creational
74
+ - **Factory Method / Abstract Factory**: Use when instantiation logic is complex or varies by context.
75
+ Prefer over `new` in business logic — keep constructors for DI only.
76
+ - **Builder**: Use when constructing objects with many optional parameters. Fluent API preferred.
77
+ - **Singleton**: Almost never in application code. Use DI to manage lifecycle instead.
78
+ Acceptable only for: loggers, config singletons in composition root.
79
+
80
+ ### Structural
81
+ - **Adapter**: Wrap third-party APIs to match your port interfaces. Isolates vendor lock-in.
82
+ - **Facade**: Simplify complex subsystem interactions behind a unified interface.
83
+ Every module's public exports are a facade.
84
+ - **Decorator**: Add behavior (logging, caching, retry, auth) without modifying the original.
85
+ Middleware pipelines are decorator chains.
86
+ - **Proxy**: Lazy loading, access control, or caching in front of expensive resources.
87
+
88
+ ### Behavioral
89
+ - **Strategy**: Extract interchangeable algorithms behind an interface. Inject the right one.
90
+ Examples: pricing calculators, render strategies, sort algorithms.
91
+ - **Observer / Pub-Sub**: Decouple event producers from consumers. Use for: domain events,
92
+ UI state changes, webhook fan-out. See CQRS & Event Patterns section.
93
+ - **Chain of Responsibility**: Middleware pipelines (Express, Koa). Each handler decides
94
+ to process or pass to the next. Order matters.
95
+ - **Command**: Encapsulate actions as objects. Enables: undo/redo, queuing, audit trail.
96
+
97
+ ### Enterprise
98
+ - **Repository**: Encapsulate data access behind a collection-like interface. Defined in the
99
+ domain layer, implemented in the infrastructure layer as adapters.
100
+ - **Unit of Work**: Track changes within a transaction boundary. Commit or roll back atomically.
101
+ Pair with Repository for database operations.
102
+ - **Saga**: Coordinate multi-step distributed operations. Each step has a compensating action
103
+ for rollback. Use for: order processing, payment flows, multi-service workflows.
104
+ - **Outbox**: Write events to a local outbox table in the same transaction as the state change.
105
+ A separate process reliably publishes them. Guarantees at-least-once event delivery.
106
+
107
+ ### Anti-Patterns to Avoid
108
+ - **God Object**: One class that knows/does everything. Split by responsibility.
109
+ - **Service Locator**: Global registry looked up at runtime. Use constructor injection instead.
110
+ - **Anemic Domain Model**: Entities with only getters/setters, logic in services.
111
+ Push behavior into domain objects.
112
+
113
+ # ── GS Practitioner Protocol — on-demand only (not inlined in CLAUDE.md) ────
114
+
115
+ - id: gs-guidance-session-loop
116
+ title: "GS — Session Loop Procedure"
117
+ topic: guidance
118
+ content: |
119
+ ## Generative Specification: Session Loop
120
+
121
+ Every session begins and ends at the same steady state: code, tests, and documentation
122
+ mutually consistent; the specification accurately describing what exists; the commit
123
+ history recording how it changed; Status.md capturing intent for the next session.
124
+ A session that ends with passing tests but a stale specification has not completed the loop.
125
+
126
+ ### Phase 1 — Intake and Clarification
127
+ Check for exactly two conditions before implementation begins:
128
+ - **Ambiguity**: the request admits two or more valid interpretations producing different implementations.
129
+ - **Unverifiable assumptions**: the request presupposes facts about scope, schema, or behavior
130
+ not verifiable from the current codebase.
131
+
132
+ If either is present, batch ALL clarifying questions into a single prompt — answered once.
133
+ If neither is present, implementation proceeds immediately.
134
+ The constraint on asking is as important as the obligation to ask.
135
+
136
+ ### Phase 2 — Specification Gate ⛔
137
+ Before any code is written: does this change **fit** the existing specification, or does
138
+ it **change** it?
139
+ - A feature the specification anticipates: implement directly.
140
+ - A feature the specification does not yet cover: **update the specification first**.
141
+ The ADR, the schema change, the new constitution section — these precede implementation.
142
+ Code written against the old specification is wrong by the grammar it was supposed to
143
+ serve, regardless of whether the tests pass.
144
+
145
+ ### Phase 3 — Implementation and Verification
146
+ Three conditions must hold before any commit:
147
+ 1. Full test suite passes.
148
+ 2. Feature exercised at the HTTP or CLI boundary — not only unit-tested internally.
149
+ 3. No new anti-patterns: no hardcoded values, no bare exception throws, no diagnostic
150
+ logging in production paths.
151
+
152
+ ### Phase 4 — Documentation Cascade
153
+ After a passing commit, restore all artifacts to consistency in this order:
154
+ 1. Spec files — if a public contract changed (endpoint, CLI command, schema).
155
+ 2. ADR — if a non-obvious architectural decision was made.
156
+ 3. Architectural constitution — if a new pattern was established for future sessions.
157
+ 4. Architecture diagrams — if a new component or boundary was introduced.
158
+ 5. Sequence diagrams — if a new inter-component flow was added.
159
+ 6. Tech spec — if implementation diverged from the written spec (spec is the truth; update it).
160
+ 7. Status.md — every session, without exception.
161
+
162
+ The cascade closes the loop. A session that skips this phase has not completed.
163
+
164
+ - id: gs-guidance-context-loading
165
+ title: "GS — Context Loading Strategy"
166
+ topic: guidance
167
+ content: |
168
+ ## Generative Specification: Context Loading Strategy
169
+
170
+ The order in which artifacts are loaded at session start determines what the AI holds
171
+ as authoritative. Load in this order:
172
+
173
+ 1. **Architectural constitution** (`CLAUDE.md`) first. This is the grammar. Everything
174
+ else is read against it.
175
+ 2. **Technical specification** — the section relevant to this session's scope. Load the
176
+ whole document for cross-cutting tasks; load the relevant section for bounded tasks.
177
+ 3. **Active ADRs** — those covering the area being modified. Do not load the full ADR
178
+ directory on every session; load the decisions that govern the current scope.
179
+ 4. **Status.md** — what was done, what is in progress, what is next.
180
+ 5. **Session prompt** — last, after all context artifacts are loaded.
181
+
182
+ ### What to Exclude
183
+ Test files (unless the session is about the test suite), generated files, `node_modules`,
184
+ `dist`, `build`, lock files. Context budget is finite; loading noise competes with signal.
185
+
186
+ ### MCP Server Budget
187
+ Maximum **three** active MCP servers in any session:
188
+ - Built-in file/search/terminal tools (treated as one).
189
+ - Optionally one semantic search tool (CodeSeeker) for large codebases.
190
+ - Optionally one specification-management tool (ForgeCraft).
191
+
192
+ Each declared tool is read by the model on every turn whether invoked or not. Beyond
193
+ three servers, tooling overhead begins to compete with the specification for context attention.
194
+
195
+ - id: gs-guidance-bound-roadmap
196
+ title: "GS — Bound Roadmap and Waiting State"
197
+ topic: guidance
198
+ content: |
199
+ ## Generative Specification: Bound Roadmap
200
+
201
+ A roadmap item without a pre-generated prompt is a task title — it requires the
202
+ practitioner to reconstruct context at execution time. A roadmap item *with* a bound
203
+ prompt is an independent execution unit: it already contains the specification references,
204
+ the acceptance criteria, and the verification steps.
205
+
206
+ Bound prompts live in `DEVELOPMENT_PROMPTS.md` (Procedural Memory). This file is a
207
+ first-class specification artifact. The criteria for "specific enough" is:
208
+ can the agent execute this prompt to completion without any narration?
209
+
210
+ ### Bound Prompt Format
211
+ ```markdown
212
+ ## [Prompt ID] — [Feature or Task Name]
213
+
214
+ **Specification references:** [Artifacts to load before beginning]
215
+ **Precondition:** [What must be true before this task begins]
216
+ **Scope:** [What to build AND what NOT to touch]
217
+ **Acceptance criteria:**
218
+ - [ ] [Specific, verifiable criterion]
219
+ - [ ] [Full test suite passes]
220
+ - [ ] [Feature exercised at HTTP or CLI boundary]
221
+ **Architecture constraints:** [Layer rules or patterns specific to this task]
222
+ **Commit message:** feat([scope]): [description]
223
+ ```
224
+
225
+ "Build the connection system" is not a bound prompt.
226
+ "Implement the `createConnection` service method against the `ConnectionRepository`
227
+ interface, write unit tests for all three error paths, verify via HTTP test against
228
+ `/connections`, run the full suite before committing" is a bound prompt.
229
+
230
+ ### Valid Waiting State
231
+ A project in a valid waiting state requires zero practitioner effort until cycled back.
232
+ Requirements:
233
+ - Current commit passes the full test suite.
234
+ - Status.md names the immediate next action specifically enough to begin from it alone.
235
+ - No partial work in the working tree — everything is committed or staged with a note.
236
+ - Inflight ADR decisions are noted in Status.md.
237
+
238
+ Cycling back in: read Status.md → run test suite → load bound prompt → begin.
239
+ The specification holds the context. The practitioner holds nothing.
240
+
241
+ - id: gs-guidance-incremental-cascade
242
+ title: "GS — Incremental Cascade"
243
+ topic: guidance
244
+ content: |
245
+ ## Generative Specification: Incremental Cascade
246
+
247
+ Every change consists of two decisions: *what* to change and *which artifacts* that
248
+ change affects. The incremental cascade manages the second decision.
249
+
250
+ ### 1. Name the Delta
251
+ Observe something: a discrepancy in the running system, a new requirement, a bug. Write
252
+ it in precise terms. Vague deltas produce vague cascades.
253
+
254
+ ### 2. Change Impact Assessment (CIA)
255
+ Before propagating anything: Which artifacts reference the changed element? Which roadmap
256
+ items in progress share a dependency with it? Does the delta change a shared interface
257
+ contract or schema? Skipping CIA risks propagating a change into implementation before
258
+ discovering it breaks a parallel item already in progress.
259
+
260
+ ### 3. Determine Minimum Cascade Depth
261
+ | Change Type | Minimum Depth |
262
+ |---|---|
263
+ | Bug the spec correctly describes | Implementation only |
264
+ | New behavior within existing architecture | Use case, possibly tech spec |
265
+ | New component or service boundary | C4 → constitution → ADR → use cases → implementation |
266
+ | Change to shared interface contract | Contract spec → dependent use cases → all affected prompts → implementation |
267
+
268
+ ### 4. Propagate Upward First, Then Downward
269
+ When a layer needs updating, all layers above it are made consistent **before** any layer
270
+ below it receives the change.
271
+ ```
272
+ Functional specification ← top
273
+
274
+ Architecture / C4 diagrams
275
+
276
+ Architectural constitution (CLAUDE.md)
277
+
278
+ ADRs
279
+
280
+ Use cases / sequence diagrams
281
+
282
+ Implementation + tests ← bottom
283
+ ```
284
+ Code that was correct relative to the old specification and is now wrong relative to the new
285
+ one is a derivation gap, not a bug. The correct response is re-derivation, not patching.
286
+
287
+ ### 5. Close the Cascade
288
+ After implementation commits, run Phase 4 (Documentation Cascade) of the session loop
289
+ to restore all artifacts to consistency.
290
+
291
+ - id: gs-guidance-diagnostic-checklist
292
+ title: "GS — Memory Diagnostic Checklist"
293
+ topic: guidance
294
+ content: |
295
+ ## Generative Specification: Diagnostic Checklist
296
+
297
+ Run before beginning any session on a new or inherited project. A "no" on any semantic
298
+ or procedural item is a **blocker** — fill the gap before implementation begins.
299
+ A "no" on episodic, relationship, or working items must be resolved in the first 10 minutes.
300
+
301
+ ```
302
+ SEMANTIC MEMORY
303
+ [ ] CLAUDE.md exists and is current (describes the current architecture, not a prior one)
304
+ [ ] Technical specification covers current scope
305
+ [ ] Domain vocabulary is defined (no ambiguous names across modules)
306
+
307
+ PROCEDURAL MEMORY
308
+ [ ] Bound prompts exist for the next 3+ roadmap items (DEVELOPMENT_PROMPTS.md)
309
+ [ ] CI/CD pipeline is specified (not just configured)
310
+ [ ] Pre-commit hooks are active and tested
311
+
312
+ EPISODIC MEMORY
313
+ [ ] ADRs exist for every non-obvious architectural decision currently in force
314
+ [ ] Status.md was updated at the close of the last session
315
+ [ ] Git history is typed (conventional commits, not 'wip' and 'changes')
316
+
317
+ RELATIONSHIP MEMORY
318
+ [ ] C4 context and container diagrams are current
319
+ [ ] Primary flows have sequence diagrams
320
+ [ ] Use cases cover every behavioral contract being modified this session
321
+
322
+ WORKING MEMORY
323
+ [ ] Session prompt is specific enough to begin without narration
324
+ [ ] Context loading plan covers what's needed and excludes what isn't
325
+ [ ] MCP server count ≤ 3
326
+ ```