@polymorphism-tech/morph-spec 2.4.0 → 3.0.0

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 (218) hide show
  1. package/CLAUDE.md +158 -26
  2. package/LICENSE +72 -72
  3. package/bin/detect-agents.js +225 -225
  4. package/bin/morph-spec.js +8 -0
  5. package/bin/render-template.js +302 -302
  6. package/bin/semantic-detect-agents.js +246 -246
  7. package/bin/validate-agents-skills.js +251 -251
  8. package/bin/validate-agents.js +69 -69
  9. package/bin/validate-phase.js +263 -263
  10. package/content/.azure/README.md +293 -293
  11. package/content/.azure/docs/azure-devops-setup.md +454 -454
  12. package/content/.azure/docs/branch-strategy.md +398 -398
  13. package/content/.azure/docs/local-development.md +515 -515
  14. package/content/.azure/pipelines/pipeline-variables.yml +34 -34
  15. package/content/.azure/pipelines/prod-pipeline.yml +319 -319
  16. package/content/.azure/pipelines/staging-pipeline.yml +234 -234
  17. package/content/.azure/pipelines/templates/build-dotnet.yml +75 -75
  18. package/content/.azure/pipelines/templates/deploy-app-service.yml +94 -94
  19. package/content/.azure/pipelines/templates/deploy-container-app.yml +120 -120
  20. package/content/.azure/pipelines/templates/infra-deploy.yml +90 -90
  21. package/content/.claude/commands/morph-archive.md +79 -79
  22. package/content/.claude/commands/morph-deploy.md +529 -0
  23. package/content/.claude/commands/morph-infra.md +209 -209
  24. package/content/.claude/commands/morph-preflight.md +227 -227
  25. package/content/.claude/commands/morph-troubleshoot.md +122 -122
  26. package/content/.claude/settings.local.json +15 -15
  27. package/content/.claude/skills/infra/azure-deploy-specialist.md +699 -0
  28. package/content/.claude/skills/level-0-meta/README.md +7 -0
  29. package/content/.claude/skills/{checklists → level-0-meta}/morph-checklist.md +117 -117
  30. package/content/.claude/skills/level-1-workflows/README.md +7 -0
  31. package/content/.claude/skills/{workflows → level-1-workflows}/morph-replicate.md +213 -213
  32. package/content/.claude/skills/{workflows → level-1-workflows}/phase-clarify.md +131 -131
  33. package/content/.claude/skills/{workflows → level-1-workflows}/phase-design.md +213 -205
  34. package/content/.claude/skills/{workflows → level-1-workflows}/phase-setup.md +106 -92
  35. package/content/.claude/skills/{workflows → level-1-workflows}/phase-tasks.md +164 -164
  36. package/content/.claude/skills/{workflows → level-1-workflows}/phase-uiux.md +169 -138
  37. package/content/.claude/skills/level-2-domains/README.md +14 -0
  38. package/content/.claude/skills/{specialists → level-2-domains/quality}/testing-specialist.md +126 -126
  39. package/content/.claude/skills/level-3-technologies/README.md +7 -0
  40. package/content/.claude/skills/level-4-patterns/README.md +7 -0
  41. package/content/.claude/skills/specialists/prompt-engineer.md +189 -0
  42. package/content/.claude/skills/specialists/seo-growth-hacker.md +320 -0
  43. package/content/.morph/.morphversion +5 -5
  44. package/content/.morph/archive/.gitkeep +25 -25
  45. package/content/.morph/config/agents.json +742 -358
  46. package/content/.morph/config/config.template.json +33 -0
  47. package/content/.morph/docs/STORY-DRIVEN-DEVELOPMENT.md +392 -392
  48. package/content/.morph/docs/workflows/enforcement-pipeline.md +668 -0
  49. package/content/.morph/examples/api-nextjs/README.md +241 -241
  50. package/content/.morph/examples/api-nextjs/contracts.ts +307 -307
  51. package/content/.morph/examples/api-nextjs/spec.md +399 -399
  52. package/content/.morph/examples/api-nextjs/tasks.md +168 -168
  53. package/content/.morph/examples/micro-saas/README.md +125 -125
  54. package/content/.morph/examples/micro-saas/contracts.cs +358 -358
  55. package/content/.morph/examples/micro-saas/decisions.md +246 -246
  56. package/content/.morph/examples/micro-saas/spec.md +236 -236
  57. package/content/.morph/examples/micro-saas/tasks.md +150 -150
  58. package/content/.morph/examples/multi-agent/README.md +309 -309
  59. package/content/.morph/examples/multi-agent/contracts.cs +433 -433
  60. package/content/.morph/examples/multi-agent/spec.md +479 -479
  61. package/content/.morph/examples/multi-agent/tasks.md +185 -185
  62. package/content/.morph/examples/scheduled-reports/decisions.md +158 -158
  63. package/content/.morph/examples/scheduled-reports/proposal.md +95 -95
  64. package/content/.morph/examples/scheduled-reports/spec.md +267 -267
  65. package/content/.morph/examples/state-v3.json +188 -188
  66. package/content/.morph/features/.gitkeep +25 -25
  67. package/content/.morph/hooks/README.md +158 -0
  68. package/content/.morph/hooks/pre-commit-all.sh +48 -48
  69. package/content/.morph/hooks/pre-commit-specs.sh +49 -49
  70. package/content/.morph/hooks/pre-commit-tests.sh +60 -60
  71. package/content/.morph/hooks/task-completed.js +73 -0
  72. package/content/.morph/hooks/teammate-idle.js +68 -0
  73. package/content/.morph/project.md +160 -160
  74. package/content/.morph/schemas/agent.schema.json +296 -296
  75. package/content/.morph/schemas/tasks.schema.json +220 -220
  76. package/content/.morph/specs/.gitkeep +20 -20
  77. package/content/.morph/standards/agent-teams-workflow.md +474 -0
  78. package/content/.morph/standards/coding.md +377 -377
  79. package/content/.morph/standards/fluent-ui-setup.md +590 -590
  80. package/content/.morph/standards/migration-guide.md +514 -514
  81. package/content/.morph/standards/passkeys-auth.md +423 -423
  82. package/content/.morph/standards/vector-search-rag.md +536 -536
  83. package/content/.morph/state.json +17 -17
  84. package/content/.morph/templates/CONTEXT-FEATURE.md +276 -0
  85. package/content/.morph/templates/CONTEXT.md +170 -0
  86. package/content/.morph/templates/FluentDesignTheme.cs +149 -149
  87. package/content/.morph/templates/MudTheme.cs +281 -281
  88. package/content/.morph/templates/clarify-questions.md +159 -159
  89. package/content/.morph/templates/component.razor +239 -239
  90. package/content/.morph/templates/contracts/Commands.cs +74 -74
  91. package/content/.morph/templates/contracts/Entities.cs +25 -25
  92. package/content/.morph/templates/contracts/Queries.cs +74 -74
  93. package/content/.morph/templates/contracts/README.md +74 -74
  94. package/content/.morph/templates/contracts.cs +217 -217
  95. package/content/.morph/templates/design-system.css +226 -226
  96. package/content/.morph/templates/infra/.dockerignore.example +89 -89
  97. package/content/.morph/templates/infra/Dockerfile.example +82 -82
  98. package/content/.morph/templates/infra/README.md +286 -286
  99. package/content/.morph/templates/infra/app-insights.bicep +63 -63
  100. package/content/.morph/templates/infra/app-service.bicep +164 -164
  101. package/content/.morph/templates/infra/azure-pipelines-deploy.yml +480 -0
  102. package/content/.morph/templates/infra/container-app-env.bicep +49 -49
  103. package/content/.morph/templates/infra/container-app.bicep +156 -156
  104. package/content/.morph/templates/infra/deploy-checklist.md +426 -426
  105. package/content/.morph/templates/infra/deploy.ps1 +229 -229
  106. package/content/.morph/templates/infra/deploy.sh +208 -208
  107. package/content/.morph/templates/infra/key-vault.bicep +91 -91
  108. package/content/.morph/templates/infra/main.bicep +189 -189
  109. package/content/.morph/templates/infra/parameters.dev.json +29 -29
  110. package/content/.morph/templates/infra/parameters.prod.json +29 -29
  111. package/content/.morph/templates/infra/parameters.staging.json +29 -29
  112. package/content/.morph/templates/infra/sql-database.bicep +103 -103
  113. package/content/.morph/templates/infra/storage.bicep +106 -106
  114. package/content/.morph/templates/integrations/asaas-client.cs +387 -387
  115. package/content/.morph/templates/integrations/asaas-webhook.cs +351 -351
  116. package/content/.morph/templates/integrations/azure-identity-config.cs +288 -288
  117. package/content/.morph/templates/integrations/clerk-config.cs +258 -258
  118. package/content/.morph/templates/job.cs +171 -171
  119. package/content/.morph/templates/migration.cs +83 -83
  120. package/content/.morph/templates/repository.cs +141 -141
  121. package/content/.morph/templates/saas/subscription.cs +347 -347
  122. package/content/.morph/templates/saas/tenant.cs +338 -338
  123. package/content/.morph/templates/service.cs +139 -139
  124. package/content/.morph/templates/sprint-status.yaml +68 -68
  125. package/content/.morph/templates/story.md +143 -143
  126. package/content/.morph/templates/test.cs +239 -239
  127. package/content/.morph/templates/ui-design-system.md +286 -286
  128. package/content/.morph/templates/ui-flows.md +336 -336
  129. package/content/.morph/templates/ui-mockups.md +133 -133
  130. package/content/.morph/test-infra/example.bicep +59 -59
  131. package/content/README.md +79 -79
  132. package/detectors/config-detector.js +223 -223
  133. package/detectors/conversation-analyzer.js +163 -163
  134. package/detectors/index.js +84 -84
  135. package/detectors/standards-generator.js +275 -275
  136. package/docs/api/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +977 -977
  137. package/docs/api/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +1048 -1048
  138. package/docs/api/scripts/collapse.js +38 -38
  139. package/docs/api/scripts/commonNav.js +28 -28
  140. package/docs/api/scripts/linenumber.js +25 -25
  141. package/docs/api/scripts/nav.js +12 -12
  142. package/docs/api/scripts/polyfill.js +3 -3
  143. package/docs/api/scripts/prettify/Apache-License-2.0.txt +202 -202
  144. package/docs/api/scripts/prettify/lang-css.js +2 -2
  145. package/docs/api/scripts/prettify/prettify.js +28 -28
  146. package/docs/api/scripts/search.js +98 -98
  147. package/docs/api/styles/jsdoc.css +776 -776
  148. package/docs/api/styles/prettify.css +80 -80
  149. package/docs/examples.md +328 -328
  150. package/docs/templates.md +418 -418
  151. package/package.json +1 -1
  152. package/scripts/postinstall.js +132 -132
  153. package/src/commands/advance-phase.js +83 -0
  154. package/src/commands/analyze-blazor-concurrency.js +193 -193
  155. package/src/commands/create-story.js +351 -351
  156. package/src/commands/deploy.js +780 -0
  157. package/src/commands/detect-agents.js +34 -6
  158. package/src/commands/detect.js +104 -104
  159. package/src/commands/generate-context.js +40 -0
  160. package/src/commands/generate.js +149 -149
  161. package/src/commands/lint-fluent.js +352 -352
  162. package/src/commands/rollback-phase.js +185 -185
  163. package/src/commands/session-summary.js +291 -291
  164. package/src/commands/shard-spec.js +224 -224
  165. package/src/commands/sprint-status.js +250 -250
  166. package/src/commands/state.js +333 -333
  167. package/src/commands/sync.js +167 -167
  168. package/src/commands/troubleshoot.js +222 -222
  169. package/src/commands/validate-blazor-state.js +210 -210
  170. package/src/commands/validate-blazor.js +156 -156
  171. package/src/commands/validate-css.js +84 -84
  172. package/src/commands/validate-phase.js +221 -221
  173. package/src/lib/blazor-concurrency-analyzer.js +288 -288
  174. package/src/lib/blazor-state-validator.js +291 -291
  175. package/src/lib/blazor-validator.js +374 -374
  176. package/src/lib/context-generator.js +513 -0
  177. package/src/lib/css-validator.js +352 -352
  178. package/src/lib/design-system-detector.js +187 -0
  179. package/src/lib/design-system-generator.js +298 -298
  180. package/src/lib/design-system-scaffolder.js +299 -0
  181. package/src/lib/hook-executor.js +256 -0
  182. package/src/lib/learning-system.js +520 -520
  183. package/src/lib/mockup-generator.js +366 -366
  184. package/src/lib/spec-validator.js +258 -0
  185. package/src/lib/standards-context-injector.js +287 -0
  186. package/src/lib/team-orchestrator.js +322 -0
  187. package/src/lib/troubleshoot-grep.js +194 -194
  188. package/src/lib/troubleshoot-index.js +144 -144
  189. package/src/lib/ui-detector.js +350 -350
  190. package/src/lib/validation-runner.js +65 -13
  191. package/src/lib/validators/architecture-validator.js +387 -387
  192. package/src/lib/validators/design-system-validator.js +231 -0
  193. package/src/lib/validators/package-validator.js +360 -360
  194. package/src/lib/validators/ui-contrast-validator.js +422 -422
  195. package/src/utils/file-copier.js +9 -1
  196. package/src/utils/logger.js +32 -32
  197. package/src/utils/version-checker.js +175 -175
  198. /package/content/.claude/skills/{checklists → level-0-meta}/code-review.md +0 -0
  199. /package/content/.claude/skills/{checklists → level-0-meta}/simulation-checklist.md +0 -0
  200. /package/content/.claude/skills/{specialists → level-2-domains/ai-agents}/ai-system-architect.md +0 -0
  201. /package/content/.claude/skills/{specialists → level-2-domains/architecture}/po-pm-advisor.md +0 -0
  202. /package/content/.claude/skills/{specialists → level-2-domains/architecture}/standards-architect.md +0 -0
  203. /package/content/.claude/skills/{specialists → level-2-domains/backend}/dotnet-senior.md +0 -0
  204. /package/content/.claude/skills/{specialists → level-2-domains/backend}/ef-modeler.md +0 -0
  205. /package/content/.claude/skills/{specialists → level-2-domains/backend}/hangfire-orchestrator.md +0 -0
  206. /package/content/.claude/skills/{specialists → level-2-domains/backend}/ms-agent-expert.md +0 -0
  207. /package/content/.claude/skills/{stacks/dotnet-blazor.md → level-2-domains/frontend/blazor-builder.md} +0 -0
  208. /package/content/.claude/skills/{stacks/dotnet-nextjs.md → level-2-domains/frontend/nextjs-expert.md} +0 -0
  209. /package/content/.claude/skills/{specialists → level-2-domains/frontend}/ui-ux-designer.md +0 -0
  210. /package/content/.claude/skills/{specialists → level-2-domains/infrastructure}/azure-architect.md +0 -0
  211. /package/content/.claude/skills/{infra → level-2-domains/infrastructure}/bicep-architect.md +0 -0
  212. /package/content/.claude/skills/{infra → level-2-domains/infrastructure}/container-specialist.md +0 -0
  213. /package/content/.claude/skills/{infra → level-2-domains/infrastructure}/devops-engineer.md +0 -0
  214. /package/content/.claude/skills/{integrations → level-2-domains/integrations}/asaas-financial.md +0 -0
  215. /package/content/.claude/skills/{integrations → level-2-domains/integrations}/azure-identity.md +0 -0
  216. /package/content/.claude/skills/{integrations → level-2-domains/integrations}/clerk-auth.md +0 -0
  217. /package/content/.claude/skills/{integrations → level-2-domains/integrations}/resend-email.md +0 -0
  218. /package/content/.claude/skills/{specialists → level-2-domains/quality}/code-analyzer.md +0 -0
@@ -0,0 +1,668 @@
1
+ # Standards Enforcement Pipeline
2
+
3
+ > MORPH-SPEC 3.0 Phases 1-6 Implementation
4
+
5
+ Comprehensive enforcement pipeline that guarantees code quality and standards compliance through automated validation gates.
6
+
7
+ ---
8
+
9
+ ## Overview
10
+
11
+ The enforcement pipeline consists of **6 integrated phases** that work together to ensure all code follows MORPH standards without manual checking:
12
+
13
+ | Phase | Component | When | What |
14
+ |-------|-----------|------|------|
15
+ | **1** | Data-Driven Validators | FASE 5 (task done) | Maps agents → validators via agents.json |
16
+ | **2** | Standards Context Injector | Agent detection | Auto-loads 55k+ chars of standards per agent |
17
+ | **3** | Design System Enforcement | FASE 5 gate | Blocks UI features without design system |
18
+ | **4** | Spec-Time Validation | FASE 2 gate | Validates contracts.cs before implementation |
19
+ | **5** | Standards Optimization | N/A | Optimized standards (23% token reduction) |
20
+ | **6** | Comprehensive Testing | All phases | 242 tests, 100% pass rate |
21
+
22
+ **Total Files:** 20 modules | **Tests:** 242 | **Token Savings:** ~5k per agent activation
23
+
24
+ ---
25
+
26
+ ## Phase 1: Data-Driven Validators
27
+
28
+ ### Problem Solved
29
+
30
+ Before: Hardcoded AGENT_VALIDATOR_MAP in validation-runner.js made it impossible to customize validator behavior without code changes.
31
+
32
+ **After:** Single source of truth in `agents.json` - modify validator mapping without touching code.
33
+
34
+ ### Implementation
35
+
36
+ **agents.json structure:**
37
+ ```json
38
+ {
39
+ "agents": {
40
+ "blazor-builder": {
41
+ "validators": ["architecture", "blazor", "blazor-concurrency", "blazor-state", "css", "design-system"]
42
+ },
43
+ "standards-architect": {
44
+ "validators": ["architecture", "packages"]
45
+ }
46
+ }
47
+ }
48
+ ```
49
+
50
+ **validation-runner.js behavior:**
51
+ 1. `loadAgentValidatorMap(projectPath)` reads agents.json
52
+ 2. `detectValidators(featureName)` loads feature's activeAgents from state.json
53
+ 3. Maps agents → validators using data-driven map
54
+ 4. Runs each validator with options (including decision constraints)
55
+
56
+ ### Usage
57
+
58
+ ```bash
59
+ # Validators run automatically on task completion
60
+ morph-spec task done my-feature T001
61
+
62
+ # To customize: edit content/.morph/config/agents.json
63
+ {
64
+ "my-custom-agent": {
65
+ "validators": ["architecture", "custom-validator"]
66
+ }
67
+ }
68
+ ```
69
+
70
+ **Benefits:**
71
+ - No code changes to add/remove validators
72
+ - Per-agent validator customization
73
+ - Fail-fast on missing agents.json (honest failure)
74
+
75
+ ---
76
+
77
+ ## Phase 2: Standards Context Injector
78
+
79
+ ### Problem Solved
80
+
81
+ Before: Specialists had to manually read standards files, often missing relevant patterns.
82
+
83
+ **After:** All relevant standards automatically loaded into agent context (55k+ chars for blazor-builder).
84
+
85
+ ### Implementation
86
+
87
+ **standards-context-injector.js:**
88
+ ```javascript
89
+ export function loadStandardsForAgent(agentId, projectPath) {
90
+ // Resolution order:
91
+ // 1. .morph/project/standards/{file}.md (project overrides)
92
+ // 2. content/.morph/standards/{file}.md (content standards)
93
+ // 3. framework/standards/{file}.md (framework standards)
94
+
95
+ return {
96
+ sections: [...], // Array of { standard, content }
97
+ fullContent: string, // Concatenated standards (55k+ chars)
98
+ standardNames: [...] // List of loaded standards
99
+ };
100
+ }
101
+ ```
102
+
103
+ **Agent → Standards Mapping:**
104
+ | Agent | Standards Loaded |
105
+ |-------|------------------|
106
+ | `blazor-builder` | blazor-lifecycle, blazor-state, blazor-efcore, blazor-pitfalls, html-to-blazor, fluent-ui-blazor, css-*, coding, architecture |
107
+ | `ai-system-architect` | agent-framework-*, architecture, coding |
108
+ | `azure-architect` | azure, architecture, dotnet10-compatibility |
109
+ | `ms-agent-expert` | agent-framework-*, coding, architecture |
110
+
111
+ ### Usage
112
+
113
+ ```bash
114
+ # Standards auto-injected when running detect-agents with --json
115
+ npx morph-spec detect-agents --json "create blazor dashboard"
116
+
117
+ # Output includes standardsSummary for each agent:
118
+ {
119
+ "standardsSummary": {
120
+ "blazor-builder": {
121
+ "fullContent": "... 55304 characters ...",
122
+ "sections": [...]
123
+ }
124
+ }
125
+ }
126
+ ```
127
+
128
+ **Benefits:**
129
+ - Zero manual context loading
130
+ - Always up-to-date standards
131
+ - Project-specific overrides supported
132
+ - No token waste (200k context available)
133
+
134
+ ---
135
+
136
+ ## Phase 3: Design System Enforcement
137
+
138
+ ### Problem Solved
139
+
140
+ Before: UI features implemented with hardcoded colors, inconsistent styling, no design tokens.
141
+
142
+ **After:** Gate blocks implementation without design system; validator detects violations.
143
+
144
+ ### Components
145
+
146
+ **1. design-system-detector.js**
147
+ - Checks 4 levels (priority order):
148
+ 1. Feature-level: `.morph/project/outputs/{feature}/ui-design-system.md`
149
+ 2. Project-level: `.morph/project/design-system.md`
150
+ 3. Generated CSS: `wwwroot/css/design-system.css`
151
+ 4. Existing CSS variables: scans `.css` files for `--app-*` tokens
152
+
153
+ **2. design-system-scaffolder.js**
154
+ - Auto-creates design system from template
155
+ - Scans existing CSS for color variables
156
+ - Populates with sensible defaults
157
+
158
+ **3. design-system-validator.js**
159
+ - Parses design system tokens (colors, typography, spacing)
160
+ - Scans CSS/Razor for hardcoded colors
161
+ - Detects inline `style=""` attributes
162
+ - Reports violations with file:line references
163
+
164
+ **4. Gate in advance-phase.js**
165
+ ```javascript
166
+ if (nextPhase === 'implement') {
167
+ const gateResult = designSystemGate(feature);
168
+ if (gateResult.blocked) {
169
+ // Block advancement + show solutions
170
+ process.exit(1);
171
+ }
172
+ }
173
+ ```
174
+
175
+ ### Usage
176
+
177
+ ```bash
178
+ # Gate blocks automatically if UI agents active without design system
179
+ morph-spec phase advance my-ui-feature
180
+
181
+ # Output:
182
+ # ✗ Cannot advance to implementation — UI agents are active but no design system found
183
+ #
184
+ # Create a design system with one of these options:
185
+ # 1. Project-level: .morph/project/design-system.md
186
+ # 2. Feature-level: .morph/project/outputs/my-ui-feature/ui-design-system.md
187
+ # 3. Auto-generate: morph-spec generate design-system
188
+
189
+ # Auto-scaffold design system
190
+ morph-spec generate design-system # Project-level
191
+ morph-spec generate design-system my-ui-feature # Feature-level
192
+ ```
193
+
194
+ **Benefits:**
195
+ - No hardcoded colors in production
196
+ - Consistent design tokens
197
+ - Auto-scaffolding from existing CSS
198
+ - Clear error messages with solutions
199
+
200
+ ---
201
+
202
+ ## Phase 4: Spec-Time Validation
203
+
204
+ ### Problem Solved
205
+
206
+ Before: C# coding violations only discovered during code review or runtime.
207
+
208
+ **After:** contracts.cs validated at FASE 2 (design phase) before any implementation.
209
+
210
+ ### Validation Rules
211
+
212
+ **spec-validator.js enforces 7 rules:**
213
+
214
+ 1. **CancellationToken Required**
215
+ ```csharp
216
+ // ❌ WRONG
217
+ public async Task<Order> GetOrderAsync(int id)
218
+
219
+ // ✅ CORRECT
220
+ public async Task<Order> GetOrderAsync(int id, CancellationToken ct = default)
221
+ ```
222
+
223
+ 2. **PascalCase Constants**
224
+ ```csharp
225
+ // ❌ WRONG
226
+ private const int MAX_RETRY_COUNT = 3;
227
+
228
+ // ✅ CORRECT
229
+ private const int MaxRetryCount = 3;
230
+ ```
231
+
232
+ 3. **Async Suffix**
233
+ ```csharp
234
+ // ❌ WRONG
235
+ public async Task ProcessOrder(int id)
236
+
237
+ // ✅ CORRECT
238
+ public async Task ProcessOrderAsync(int id)
239
+ ```
240
+
241
+ 4. **Sealed Classes**
242
+ ```csharp
243
+ // ⚠️ WARNING
244
+ public class OrderService { }
245
+
246
+ // ✅ CORRECT
247
+ public sealed class OrderService { }
248
+ ```
249
+
250
+ 5. **DTOs as Records**
251
+ ```csharp
252
+ // ⚠️ WARNING
253
+ public class OrderResponse { }
254
+
255
+ // ✅ CORRECT
256
+ public record OrderResponse(int Id, string Status);
257
+ ```
258
+
259
+ 6. **Interface Naming**
260
+ ```csharp
261
+ // ❌ WRONG
262
+ public interface OrderService { }
263
+
264
+ // ✅ CORRECT
265
+ public interface IOrderService { }
266
+ ```
267
+
268
+ 7. **Required Spec Sections**
269
+ - Overview
270
+ - Functional Requirements
271
+ - Non-Functional Requirements
272
+ - Technical Architecture
273
+ - Data Model
274
+
275
+ ### Gate Integration
276
+
277
+ ```javascript
278
+ // advance-phase.js
279
+ if (currentPhase === 'design' && (nextPhase === 'clarify' || nextPhase === 'tasks')) {
280
+ const specValidation = await validateSpec('.', feature);
281
+ if (specValidation.errors > 0) {
282
+ // Block advancement + show violations
283
+ process.exit(1);
284
+ }
285
+ }
286
+ ```
287
+
288
+ ### Usage
289
+
290
+ ```bash
291
+ # Runs automatically when advancing from design phase
292
+ morph-spec phase advance my-feature
293
+
294
+ # Manual validation
295
+ morph-spec validate-spec my-feature
296
+
297
+ # Output example:
298
+ # ❌ Validation FAILED - 6 errors, 3 warnings
299
+ #
300
+ # Errors:
301
+ # 1. ❌ [contracts] Async method 'GetOrderAsync' missing CancellationToken parameter
302
+ # 💡 Solution: Add 'CancellationToken ct = default' parameter
303
+ # 2. ❌ [contracts] Constant 'MAX_RETRY_COUNT' uses UPPER_SNAKE_CASE
304
+ # 💡 Solution: Use PascalCase: 'MaxRetryCount'
305
+ ```
306
+
307
+ **Benefits:**
308
+ - Catches violations before implementation
309
+ - Saves code review time
310
+ - Enforces Microsoft C# guidelines
311
+ - Actionable error messages
312
+
313
+ ---
314
+
315
+ ## Phase 5: Standards Optimization
316
+
317
+ ### Problem Solved
318
+
319
+ Before: Standards files verbose (1761 lines total), wasting tokens on redundant explanations and emojis.
320
+
321
+ **After:** 23% reduction (405 lines removed), optimized for LLM consumption.
322
+
323
+ ### Optimization Techniques
324
+
325
+ 1. **Removed Emojis** (per user feedback: "not necessary for LLMs")
326
+ ```markdown
327
+ <!-- Before -->
328
+ | ✅ Correct | ❌ Wrong |
329
+
330
+ <!-- After -->
331
+ | Correct | Wrong |
332
+ ```
333
+
334
+ 2. **Comparison Tables**
335
+ ```markdown
336
+ <!-- Before -->
337
+ **WRONG:** Using UPPER_SNAKE_CASE for constants
338
+ **CORRECT:** Use PascalCase instead
339
+
340
+ <!-- After -->
341
+ | Wrong | Right |
342
+ |-------|-------|
343
+ | `MAX_RETRY_COUNT` | `MaxRetryCount` |
344
+ ```
345
+
346
+ 3. **Condensed Code Examples**
347
+ ```markdown
348
+ <!-- Before: 15 lines with comments + boilerplate -->
349
+ public class OrderService
350
+ {
351
+ // Constructor with dependency injection
352
+ private readonly IOrderRepository _repository;
353
+ public OrderService(IOrderRepository repository)
354
+ {
355
+ _repository = repository;
356
+ }
357
+
358
+ // Main method
359
+ public async Task<Order> GetAsync(int id) { ... }
360
+ }
361
+
362
+ <!-- After: 3 lines, essential pattern only -->
363
+ public sealed class OrderService(IOrderRepository repository)
364
+ {
365
+ public async Task<Order> GetAsync(int id, CancellationToken ct = default)
366
+ => await repository.GetByIdAsync(id, ct);
367
+ }
368
+ ```
369
+
370
+ 4. **Removed Meta-Commentary**
371
+ - Kept: "what" and "how"
372
+ - Removed: verbose "why" explanations, pattern origins, historical context
373
+
374
+ ### Results
375
+
376
+ | File | Before | After | Reduction |
377
+ |------|--------|-------|-----------|
378
+ | coding.md | 320 | 211 | 109 lines (34%) |
379
+ | blazor-pitfalls.md | 254 | 143 | 111 lines (44%) |
380
+ | architecture.md | 227 | 183 | 44 lines (19%) |
381
+ | blazor-efcore.md | 227 | 173 | 54 lines (24%) |
382
+ | css-naming.md | 108 | 62 | 46 lines (43%) |
383
+ | blazor-lifecycle.md | 172 | 159 | 13 lines (7.6%) |
384
+ | blazor-state.md | 164 | 161 | 3 lines (1.8%) |
385
+ | css-animations.md | 157 | 149 | 8 lines (5.1%) |
386
+ | dotnet10-compatibility.md | 132 | 115 | 17 lines (12.9%) |
387
+ | **TOTAL** | **1761** | **1356** | **405 lines (23%)** |
388
+
389
+ **Token Savings:** ~5,063 tokens per agent activation (when standards loaded via Phase 2)
390
+
391
+ ---
392
+
393
+ ## Phase 6: Comprehensive Testing
394
+
395
+ ### Test Coverage
396
+
397
+ **18 test files, 242 tests total, 100% pass rate:**
398
+
399
+ | Test File | Tests | Coverage |
400
+ |-----------|-------|----------|
401
+ | standards-context-injector.test.js | 15 | Agent→standards mapping, project overrides |
402
+ | design-system-detector.test.js | 10 | 4-level detection priority |
403
+ | design-system-scaffolder.test.js | 12 | Template + CSS scanning |
404
+ | design-system-validator.test.js | 12 | Color detection, inline styles |
405
+ | spec-validator.test.js | 12 | 7 C# coding rules |
406
+ | validation-runner.test.js | 20 | Constraint injection, data-driven map |
407
+ | advance-phase-design-gate.test.js | 8 | Design system gate |
408
+ | advance-phase-spec-gate.test.js | 8 | Spec validation gate |
409
+ | contract-compliance-validator.test.js | 15 | Contract parsing + checking |
410
+ | decision-constraint-loader.test.js | 10 | ADR parsing |
411
+ | + 8 existing test files | 120 | Complexity analyzer, context generator, etc. |
412
+
413
+ ### Integration Tests
414
+
415
+ **6 verification tasks completed:**
416
+ 1. ✅ Run Tests (242/242 passing)
417
+ 2. ✅ Data-Driven Validator Map (agents.json → validators)
418
+ 3. ✅ Decision Wiring (decisions.md → constraints → validators)
419
+ 4. ✅ Design System Gate (blocks UI features without design system)
420
+ 5. ✅ Spec Validator (detects 9 C# violations in test)
421
+ 6. ✅ Standards Injector (55k+ chars loaded for blazor-builder)
422
+
423
+ ---
424
+
425
+ ## Integration Points
426
+
427
+ ### Complete Data Flow
428
+
429
+ ```
430
+ 1. User creates feature
431
+
432
+ 2. detect-agents --json → agents registered in state.json
433
+ ↓ (standards-context-injector loads 55k+ chars per agent)
434
+
435
+ 3. FASE 2: Design → spec.md + contracts.cs created
436
+
437
+ 4. Spec validator runs → blocks if C# violations found
438
+ ↓ (decisions.md ADRs parsed → constraints extracted)
439
+
440
+ 5. FASE 4: Tasks → advance-phase checks prerequisites
441
+
442
+ 6. FASE 5: Implement → design system gate blocks if UI agents + no design system
443
+
444
+ 7. Each `task done` → validation-runner orchestrates validators
445
+ ↓ (validators use: agents.json mapping + decision constraints + standards content)
446
+
447
+ 8. Validation results → per-validator details + summary
448
+
449
+ 9. Checkpoint includes validation summary
450
+ ```
451
+
452
+ ### Enforcement Levels
453
+
454
+ | Level | Mechanism | When | Action |
455
+ |-------|-----------|------|--------|
456
+ | **Soft** | Standards context injection | Agent detection | Auto-load 55k+ chars of standards |
457
+ | **Medium** | Validators | `task done` | Detect violations, show warnings |
458
+ | **Hard** | Gates | `phase advance` | Block on critical failures (spec, design system) |
459
+
460
+ ---
461
+
462
+ ## Commands Reference
463
+
464
+ ### Automatic Execution
465
+
466
+ ```bash
467
+ # Validators run automatically
468
+ morph-spec task done {feature} {task-id}
469
+
470
+ # Gates run automatically
471
+ morph-spec phase advance {feature}
472
+ ```
473
+
474
+ ### Manual Validation
475
+
476
+ ```bash
477
+ # Run all validators for a feature
478
+ morph-spec validate {feature}
479
+
480
+ # Run specific validator
481
+ morph-spec validate {feature} --validator=blazor
482
+
483
+ # Verbose output
484
+ morph-spec validate {feature} --verbose
485
+
486
+ # Validate spec/contracts only
487
+ morph-spec validate-spec {feature}
488
+
489
+ # Check design system
490
+ morph-spec validate-design-system {feature}
491
+ ```
492
+
493
+ ### Emergency Bypass
494
+
495
+ **⚠️ ONLY with explicit user authorization:**
496
+
497
+ ```bash
498
+ # Skip validation (emergencies only)
499
+ morph-spec task done {feature} {task-id} --skip-validation
500
+
501
+ # Ignore warnings (not errors)
502
+ morph-spec phase advance {feature} --skip-warnings
503
+ ```
504
+
505
+ ---
506
+
507
+ ## Troubleshooting
508
+
509
+ ### Validator Not Running
510
+
511
+ **Symptom:** Expected validator didn't run for task completion
512
+
513
+ **Check:**
514
+ 1. Is agent active? `morph-spec state get {feature}` → check activeAgents
515
+ 2. Is validator mapped? Check `content/.morph/config/agents.json` → agent's `validators` array
516
+ 3. Is agents.json readable? Run `morph-spec validate-agents-skills`
517
+
518
+ **Fix:**
519
+ ```bash
520
+ # Add agent to feature
521
+ morph-spec state add-agent {feature} {agent-id}
522
+
523
+ # Or edit agents.json directly
524
+ {
525
+ "my-agent": {
526
+ "validators": ["architecture", "custom-validator"]
527
+ }
528
+ }
529
+ ```
530
+
531
+ ### Gate Blocking Unexpectedly
532
+
533
+ **Symptom:** Design system gate blocks even though design system exists
534
+
535
+ **Check:**
536
+ 1. Detection order: feature > project > generated > existing CSS
537
+ 2. File location: `.morph/project/design-system.md` or `.morph/project/outputs/{feature}/ui-design-system.md`
538
+ 3. Format: Must have `# Design System` or `## Colors` sections
539
+
540
+ **Fix:**
541
+ ```bash
542
+ # Create design system
543
+ morph-spec generate design-system {feature}
544
+
545
+ # Or manually create .morph/project/design-system.md with:
546
+ # # Design System
547
+ # ## Colors
548
+ # - primary: #007bff
549
+ ```
550
+
551
+ ### Spec Validation False Positives
552
+
553
+ **Symptom:** Spec validator reports violations for valid code
554
+
555
+ **Common cases:**
556
+ - Method intentionally doesn't have CancellationToken (event handler, constructor)
557
+ - Constant should be UPPER_CASE (external API constant)
558
+ - DTO should be class (EF Core entity)
559
+
560
+ **Fix:**
561
+ ```bash
562
+ # Skip validation for this task (with user approval)
563
+ morph-spec task done {feature} {task-id} --skip-validation
564
+
565
+ # Or update contracts.cs to match coding.md standards
566
+ ```
567
+
568
+ ---
569
+
570
+ ## Extending the Pipeline
571
+
572
+ ### Adding a Custom Validator
573
+
574
+ **1. Create validator file:**
575
+ ```javascript
576
+ // src/lib/validators/my-custom-validator.js
577
+ export async function validateMyCustom(projectPath, featureName, options) {
578
+ return {
579
+ passed: true,
580
+ errors: 0,
581
+ warnings: 0,
582
+ issues: []
583
+ };
584
+ }
585
+ ```
586
+
587
+ **2. Register in validation-runner.js:**
588
+ ```javascript
589
+ case 'my-custom': {
590
+ const { validateMyCustom } = await import('./validators/my-custom-validator.js');
591
+ return await validateMyCustom(projectPath, featureName, options);
592
+ }
593
+ ```
594
+
595
+ **3. Map to agents in agents.json:**
596
+ ```json
597
+ {
598
+ "my-agent": {
599
+ "validators": ["architecture", "my-custom"]
600
+ }
601
+ }
602
+ ```
603
+
604
+ **4. Add tests:**
605
+ ```javascript
606
+ // test/lib/validators/my-custom-validator.test.js
607
+ import { describe, it } from 'node:test';
608
+ import assert from 'node:assert';
609
+ import { validateMyCustom } from '../../../src/lib/validators/my-custom-validator.js';
610
+
611
+ describe('MyCustomValidator', () => {
612
+ it('should pass valid code', async () => {
613
+ const result = await validateMyCustom('.', 'test-feature');
614
+ assert.strictEqual(result.passed, true);
615
+ });
616
+ });
617
+ ```
618
+
619
+ ### Adding a Custom Gate
620
+
621
+ **1. Add gate function in advance-phase.js:**
622
+ ```javascript
623
+ function myCustomGate(feature, projectPath = '.') {
624
+ // Check condition
625
+ if (conditionNotMet) {
626
+ return {
627
+ blocked: true,
628
+ message: 'Cannot advance - custom gate failed',
629
+ solution: ['Do X', 'Or do Y']
630
+ };
631
+ }
632
+ return { blocked: false };
633
+ }
634
+ ```
635
+
636
+ **2. Call gate before phase transition:**
637
+ ```javascript
638
+ if (nextPhase === 'my-target-phase') {
639
+ const gateResult = myCustomGate(feature);
640
+ if (gateResult.blocked) {
641
+ // Show error + exit
642
+ }
643
+ }
644
+ ```
645
+
646
+ ---
647
+
648
+ ## Performance Considerations
649
+
650
+ **Token Usage:**
651
+ - Phase 2 (Standards Injector): ~55k chars per agent = ~14k tokens
652
+ - 200k context window = room for 14 agents with full standards + code
653
+ - Phase 5 (Optimization): Saved ~5k tokens per agent activation
654
+
655
+ **Execution Time:**
656
+ - Validators: ~100-500ms per validator (fast)
657
+ - Gates: ~50-100ms per gate (very fast)
658
+ - Standards injection: One-time cost at agent detection
659
+
660
+ **Test Suite:**
661
+ - 242 tests run in ~665ms total
662
+ - Parallel test execution
663
+ - No performance regressions
664
+
665
+ ---
666
+
667
+ *MORPH-SPEC Standards Enforcement Pipeline v3.0*
668
+ *Documentation generated: 2026-02-13*