@polymorphism-tech/morph-spec 4.2.0 → 4.3.1

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 (140) hide show
  1. package/CLAUDE.md +108 -946
  2. package/bin/morph-spec.js +284 -9
  3. package/bin/task-manager.cjs +102 -14
  4. package/bin/validate.js +4 -4
  5. package/docs/{v3.0 → next-generation}/AGENTS.md +1 -1
  6. package/docs/next-generation/CONTEXT-OPTIMIZATION.md +267 -0
  7. package/docs/next-generation/EXECUTION-FLOW.md +274 -0
  8. package/docs/next-generation/META-PROMPTS.md +235 -0
  9. package/docs/next-generation/MIGRATION-GUIDE.md +253 -0
  10. package/docs/next-generation/THREAD-MANAGEMENT.md +240 -0
  11. package/package.json +5 -5
  12. package/src/commands/agents/agents-fuse.js +97 -0
  13. package/src/commands/agents/micro-agent.js +112 -0
  14. package/src/commands/agents/spawn-team.js +69 -4
  15. package/src/commands/agents/squad-template.js +146 -0
  16. package/src/commands/analytics/analytics.js +176 -0
  17. package/src/commands/context/context-prime.js +63 -0
  18. package/src/commands/context/core-four.js +54 -0
  19. package/src/commands/mcp/mcp.js +102 -0
  20. package/src/commands/project/detect-agents.js +32 -2
  21. package/src/commands/project/detect.js +11 -1
  22. package/src/commands/project/doctor.js +573 -356
  23. package/src/commands/project/init.js +9 -2
  24. package/src/commands/project/update.js +13 -3
  25. package/src/commands/state/advance-phase.js +448 -416
  26. package/src/commands/state/state.js +14 -12
  27. package/src/commands/tasks/task.js +1 -1
  28. package/src/commands/templates/template-render.js +80 -1
  29. package/src/commands/threads/thread-template.js +103 -0
  30. package/src/commands/threads/threads.js +261 -0
  31. package/src/commands/trust/trust.js +205 -0
  32. package/src/{orchestrator.js → core/orchestrator.js} +8 -8
  33. package/src/core/state/state-manager.js +37 -17
  34. package/src/core/workflows/workflow-detector.js +114 -3
  35. package/src/lib/agents/micro-agent-factory.js +161 -0
  36. package/src/lib/analytics/analytics-engine.js +345 -0
  37. package/src/lib/checkpoints/checkpoint-hooks.js +298 -258
  38. package/src/lib/context/context-bundler.js +240 -0
  39. package/src/lib/context/context-optimizer.js +212 -0
  40. package/src/lib/context/context-tracker.js +273 -0
  41. package/src/lib/context/core-four-tracker.js +201 -0
  42. package/src/lib/context/mcp-optimizer.js +200 -0
  43. package/src/lib/detectors/index.js +1 -1
  44. package/src/lib/detectors/standards-generator.js +77 -17
  45. package/src/lib/detectors/structure-detector.js +67 -39
  46. package/src/lib/execution/fusion-executor.js +304 -0
  47. package/src/lib/execution/parallel-executor.js +270 -0
  48. package/src/lib/generators/context-generator.js +3 -3
  49. package/src/lib/generators/recap-generator.js +32 -12
  50. package/src/lib/hooks/hook-executor.js +169 -0
  51. package/src/lib/hooks/stop-hook-executor.js +286 -0
  52. package/src/lib/hops/hop-composer.js +221 -0
  53. package/src/lib/threads/thread-coordinator.js +238 -0
  54. package/src/lib/threads/thread-manager.js +317 -0
  55. package/src/lib/tracking/artifact-trail.js +202 -0
  56. package/src/lib/trust/trust-manager.js +269 -0
  57. package/src/lib/validators/design-system/design-system-validator.js +2 -2
  58. package/src/lib/validators/validation-runner.js +14 -30
  59. package/src/utils/hooks-installer.js +69 -0
  60. package/stacks/blazor-azure/.morph/config/agents.json +72 -3
  61. package/stacks/nextjs-supabase/.morph/config/agents.json +3 -3
  62. package/docs/llm-interaction-config.md +0 -735
  63. package/docs/v3.0/EXECUTION-FLOW.md +0 -1304
  64. package/src/commands/utils/migrate-state.js +0 -158
  65. package/src/commands/utils/upgrade.js +0 -346
  66. package/src/lib/validators/architecture-validator.js +0 -60
  67. package/src/lib/validators/content-validator.js +0 -164
  68. package/src/lib/validators/package-validator.js +0 -61
  69. package/src/lib/validators/ui-contrast-validator.js +0 -44
  70. package/stacks/blazor-azure/.claude/commands/morph-apply.md +0 -221
  71. package/stacks/blazor-azure/.claude/commands/morph-archive.md +0 -79
  72. package/stacks/blazor-azure/.claude/commands/morph-deploy.md +0 -529
  73. package/stacks/blazor-azure/.claude/commands/morph-infra.md +0 -209
  74. package/stacks/blazor-azure/.claude/commands/morph-preflight.md +0 -227
  75. package/stacks/blazor-azure/.claude/commands/morph-proposal.md +0 -122
  76. package/stacks/blazor-azure/.claude/commands/morph-status.md +0 -86
  77. package/stacks/blazor-azure/.claude/commands/morph-troubleshoot.md +0 -122
  78. package/stacks/blazor-azure/.claude/skills/level-0-meta/README.md +0 -7
  79. package/stacks/blazor-azure/.claude/skills/level-0-meta/code-review.md +0 -226
  80. package/stacks/blazor-azure/.claude/skills/level-0-meta/morph-checklist.md +0 -117
  81. package/stacks/blazor-azure/.claude/skills/level-0-meta/simulation-checklist.md +0 -77
  82. package/stacks/blazor-azure/.claude/skills/level-1-workflows/README.md +0 -7
  83. package/stacks/blazor-azure/.claude/skills/level-1-workflows/morph-replicate.md +0 -213
  84. package/stacks/blazor-azure/.claude/skills/level-1-workflows/phase-clarify.md +0 -131
  85. package/stacks/blazor-azure/.claude/skills/level-1-workflows/phase-design.md +0 -213
  86. package/stacks/blazor-azure/.claude/skills/level-1-workflows/phase-setup.md +0 -106
  87. package/stacks/blazor-azure/.claude/skills/level-1-workflows/phase-tasks.md +0 -164
  88. package/stacks/blazor-azure/.claude/skills/level-1-workflows/phase-uiux.md +0 -169
  89. package/stacks/blazor-azure/.claude/skills/level-2-domains/README.md +0 -14
  90. package/stacks/blazor-azure/.claude/skills/level-2-domains/ai-agents/ai-system-architect.md +0 -192
  91. package/stacks/blazor-azure/.claude/skills/level-2-domains/architecture/po-pm-advisor.md +0 -197
  92. package/stacks/blazor-azure/.claude/skills/level-2-domains/architecture/prompt-engineer.md +0 -189
  93. package/stacks/blazor-azure/.claude/skills/level-2-domains/architecture/seo-growth-hacker.md +0 -320
  94. package/stacks/blazor-azure/.claude/skills/level-2-domains/architecture/standards-architect.md +0 -156
  95. package/stacks/blazor-azure/.claude/skills/level-2-domains/backend/api-designer.md +0 -59
  96. package/stacks/blazor-azure/.claude/skills/level-2-domains/backend/dotnet-senior.md +0 -77
  97. package/stacks/blazor-azure/.claude/skills/level-2-domains/backend/ef-modeler.md +0 -58
  98. package/stacks/blazor-azure/.claude/skills/level-2-domains/backend/hangfire-orchestrator.md +0 -126
  99. package/stacks/blazor-azure/.claude/skills/level-2-domains/backend/ms-agent-expert.md +0 -45
  100. package/stacks/blazor-azure/.claude/skills/level-2-domains/frontend/blazor-builder.md +0 -210
  101. package/stacks/blazor-azure/.claude/skills/level-2-domains/frontend/nextjs-expert.md +0 -154
  102. package/stacks/blazor-azure/.claude/skills/level-2-domains/frontend/ui-ux-designer.md +0 -191
  103. package/stacks/blazor-azure/.claude/skills/level-2-domains/infrastructure/azure-architect.md +0 -142
  104. package/stacks/blazor-azure/.claude/skills/level-2-domains/infrastructure/azure-deploy-specialist.md +0 -699
  105. package/stacks/blazor-azure/.claude/skills/level-2-domains/infrastructure/bicep-architect.md +0 -126
  106. package/stacks/blazor-azure/.claude/skills/level-2-domains/infrastructure/container-specialist.md +0 -131
  107. package/stacks/blazor-azure/.claude/skills/level-2-domains/infrastructure/devops-engineer.md +0 -119
  108. package/stacks/blazor-azure/.claude/skills/level-2-domains/integrations/asaas-financial.md +0 -130
  109. package/stacks/blazor-azure/.claude/skills/level-2-domains/integrations/azure-identity.md +0 -142
  110. package/stacks/blazor-azure/.claude/skills/level-2-domains/integrations/clerk-auth.md +0 -108
  111. package/stacks/blazor-azure/.claude/skills/level-2-domains/integrations/hangfire-orchestrator.md +0 -64
  112. package/stacks/blazor-azure/.claude/skills/level-2-domains/integrations/resend-email.md +0 -119
  113. package/stacks/blazor-azure/.claude/skills/level-2-domains/quality/code-analyzer.md +0 -235
  114. package/stacks/blazor-azure/.claude/skills/level-2-domains/quality/testing-specialist.md +0 -126
  115. package/stacks/blazor-azure/.claude/skills/level-3-technologies/README.md +0 -7
  116. package/stacks/blazor-azure/.claude/skills/level-4-patterns/README.md +0 -7
  117. package/stacks/blazor-azure/.morph/archive/.gitkeep +0 -25
  118. package/stacks/blazor-azure/.morph/features/.gitkeep +0 -25
  119. package/stacks/blazor-azure/.morph/schemas/agent.schema.json +0 -296
  120. package/stacks/blazor-azure/.morph/schemas/tasks.schema.json +0 -220
  121. package/stacks/blazor-azure/.morph/specs/.gitkeep +0 -20
  122. package/stacks/blazor-azure/.morph/test-infra/example.bicep +0 -59
  123. package/stacks/nextjs-supabase/.claude/commands/morph-apply.md +0 -221
  124. package/stacks/nextjs-supabase/.claude/commands/morph-archive.md +0 -79
  125. package/stacks/nextjs-supabase/.claude/commands/morph-deploy.md +0 -529
  126. package/stacks/nextjs-supabase/.claude/commands/morph-infra.md +0 -209
  127. package/stacks/nextjs-supabase/.claude/commands/morph-preflight.md +0 -227
  128. package/stacks/nextjs-supabase/.claude/commands/morph-proposal.md +0 -122
  129. package/stacks/nextjs-supabase/.claude/commands/morph-status.md +0 -86
  130. package/stacks/nextjs-supabase/.claude/commands/morph-troubleshoot.md +0 -122
  131. package/stacks/nextjs-supabase/.claude/settings.local.json +0 -6
  132. package/stacks/nextjs-supabase/.claude/skills/level-2-domains/backend/dotnet-supabase.md +0 -244
  133. package/stacks/nextjs-supabase/.claude/skills/level-2-domains/frontend/nextjs-supabase.md +0 -335
  134. package/stacks/nextjs-supabase/.claude/skills/level-2-domains/infrastructure/easypanel-deployer.md +0 -189
  135. package/stacks/nextjs-supabase/.claude/skills/level-2-domains/integrations/supabase-expert.md +0 -50
  136. /package/docs/{v3.0 → next-generation}/ANALYSIS.md +0 -0
  137. /package/docs/{v3.0 → next-generation}/ARCHITECTURE.md +0 -0
  138. /package/docs/{v3.0 → next-generation}/FEATURES.md +0 -0
  139. /package/docs/{v3.0 → next-generation}/README.md +0 -0
  140. /package/docs/{v3.0 → next-generation}/ROADMAP.md +0 -0
@@ -0,0 +1,235 @@
1
+ # Meta-Prompts (HOPs) — MORPH-SPEC v3.0
2
+
3
+ Higher-Order Prompts (HOPs) are Handlebars-powered prompt templates that generate consistent, context-rich system prompts for agent spawning. Instead of writing prompts from scratch each time, HOPs inject standards, mission context, and role definitions automatically.
4
+
5
+ ---
6
+
7
+ ## HOP Categories
8
+
9
+ ### 1. Squad Leaders (`squad-leaders/`)
10
+
11
+ Prompts for orchestrating domain squads. Use when spawning the head of a multi-agent squad.
12
+
13
+ | HOP ID | File | Use Case |
14
+ |--------|------|----------|
15
+ | `hop-backend-squad` | `backend-squad.md` | .NET backend squad with dotnet-senior as lead |
16
+ | `hop-frontend-squad` | `frontend-squad.md` | Blazor or Next.js frontend squad |
17
+
18
+ ### 2. Parallel Workers (`parallel-workers/`)
19
+
20
+ Prompts for P-Thread agents working in isolation.
21
+
22
+ | HOP ID | File | Use Case |
23
+ |--------|------|----------|
24
+ | `hop-parallel-worker` | `parallel-worker.md` | Individual domain worker in a parallel squad |
25
+ | `hop-parallel-coordinator` | `parallel-coordinator.md` | Coordinator managing multiple parallel workers |
26
+
27
+ ### 3. Generic HOPs (`hops/`)
28
+
29
+ General-purpose prompt wrappers.
30
+
31
+ | HOP ID | File | Use Case |
32
+ |--------|------|----------|
33
+ | `hop-wrapper` | `hop-wrapper.md` | Wrap any agent prompt with standard context injection |
34
+ | `hop-retry` | `hop-retry.md` | Retry a failed task with per-attempt strategy hints |
35
+ | `hop-validation` | `hop-validation.md` | Spawn a validation agent for specific validator types |
36
+
37
+ ### 4. Validators (`validators/`)
38
+
39
+ Prompts for checkpoint and pre-commit validation agents.
40
+
41
+ | HOP ID | File | Use Case |
42
+ |--------|------|----------|
43
+ | `hop-checkpoint-validator` | `checkpoint-validator.md` | Run full checkpoint validation (architecture, security, etc.) |
44
+ | `hop-pre-commit-validator` | `pre-commit-validator.md` | Pre-commit hook validation agent |
45
+
46
+ ### 5. Fusion (`fusion/`)
47
+
48
+ Prompts for F-Thread fusion workflows.
49
+
50
+ | HOP ID | File | Use Case |
51
+ |--------|------|----------|
52
+ | `hop-fusion-agent` | `fusion-agent.md` | One of N agents in a fusion run |
53
+ | `hop-fusion-aggregator` | `fusion-aggregator.md` | Aggregates N fusion results into the best output |
54
+
55
+ ---
56
+
57
+ ## Rendering HOPs
58
+
59
+ ### CLI
60
+
61
+ ```bash
62
+ # List all available HOPs
63
+ morph-spec hop list
64
+
65
+ # Render a HOP to stdout
66
+ morph-spec hop render hop-backend-squad \
67
+ --variables '{"AGENT_ID":"dotnet-senior","MISSION":"Implement auth API","FEATURE_NAME":"user-auth"}'
68
+
69
+ # Render and save to file
70
+ morph-spec hop render hop-backend-squad output.md \
71
+ --variables '{"AGENT_ID":"dotnet-senior","MISSION":"Implement auth API"}'
72
+ ```
73
+
74
+ ### Programmatic (Node.js)
75
+
76
+ ```javascript
77
+ import { renderHOP, listAvailableHOPs } from './src/lib/hop-composer.js';
78
+ import { join } from 'path';
79
+
80
+ const frameworkRoot = join(process.cwd(), 'framework');
81
+
82
+ // List HOPs
83
+ const hops = listAvailableHOPs(frameworkRoot);
84
+ console.log(hops); // [{ id, type, file, description }, ...]
85
+
86
+ // Render a HOP
87
+ const prompt = renderHOP('hop-backend-squad', {
88
+ AGENT_ID: 'dotnet-senior',
89
+ MISSION: 'Implement user authentication',
90
+ FEATURE_NAME: 'user-auth',
91
+ SPEC_SUMMARY: 'JWT auth with BCrypt, Supabase JWT validation',
92
+ TASKS: '- T001: User entity\n- T002: AuthService\n- T003: AuthController',
93
+ DELIVERABLES: 'Entities/User.cs, Services/AuthService.cs, Controllers/AuthController.cs',
94
+ CONSTRAINTS: 'IDbContextFactory, no direct DbContext injection'
95
+ }, { frameworkRoot });
96
+ ```
97
+
98
+ ---
99
+
100
+ ## Variable Reference
101
+
102
+ ### Standard Variables (auto-injected)
103
+
104
+ | Variable | Source | Example |
105
+ |----------|--------|---------|
106
+ | `{{FEATURE_NAME}}` | CLI arg | `user-auth` |
107
+ | `{{DATE}}` | System | `2026-02-19` |
108
+ | `{{TIMESTAMP}}` | System | `2026-02-19T10:00:00Z` |
109
+ | `{{STACK}}` | config.json | `Blazor` |
110
+
111
+ ### Squad Leader Variables
112
+
113
+ | Variable | Required | Description |
114
+ |----------|----------|-------------|
115
+ | `{{AGENT_ID}}` | Yes | Agent identifier (e.g., `dotnet-senior`) |
116
+ | `{{MISSION}}` | Yes | One-sentence mission statement |
117
+ | `{{SPEC_SUMMARY}}` | Yes | 2-5 sentence spec summary |
118
+ | `{{ADDITIONAL_LEADERS}}` | No | Domain leader list (markdown bullets) |
119
+ | `{{TASKS}}` | Yes | Task list (markdown bullets with IDs) |
120
+ | `{{DELIVERABLES}}` | Yes | Expected output files |
121
+ | `{{CONSTRAINTS}}` | No | Architecture constraints |
122
+
123
+ ### Parallel Worker Variables
124
+
125
+ | Variable | Required | Description |
126
+ |----------|----------|-------------|
127
+ | `{{THREAD_ID}}` | Yes | Unique thread identifier |
128
+ | `{{DOMAIN}}` | Yes | Domain name (backend, frontend, infra) |
129
+ | `{{ASSIGNED_FILES}}` | Yes | Files this worker owns |
130
+ | `{{SHARED_FILES}}` | No | Read-only shared context files |
131
+ | `{{TASKS}}` | Yes | Tasks assigned to this worker |
132
+
133
+ ### Fusion Variables
134
+
135
+ | Variable | Required | Description |
136
+ |----------|----------|-------------|
137
+ | `{{FUSION_INDEX}}` | Yes | Agent number (1, 2, 3...) |
138
+ | `{{TOTAL_AGENTS}}` | Yes | Total agents in fusion run |
139
+ | `{{STRATEGY}}` | Yes | Aggregation strategy |
140
+ | `{{MISSION}}` | Yes | Shared mission for all agents |
141
+
142
+ ### Retry Variables
143
+
144
+ | Variable | Required | Description |
145
+ |----------|----------|-------------|
146
+ | `{{ATTEMPT}}` | Yes | Current attempt number (1-3) |
147
+ | `{{MAX_ATTEMPTS}}` | Yes | Maximum retry count |
148
+ | `{{FAILURE_REASON}}` | Yes | Why the previous attempt failed |
149
+ | `{{ORIGINAL_TASK}}` | Yes | The task being retried |
150
+
151
+ ---
152
+
153
+ ## Handlebars Helpers
154
+
155
+ HOPs use Handlebars v2.0 helpers:
156
+
157
+ ```handlebars
158
+ {{pascalCase FEATURE_NAME}} → UserAuth
159
+ {{camelCase FEATURE_NAME}} → userAuth
160
+ {{snakeCase FEATURE_NAME}} → user_auth
161
+ {{pluralize "entity"}} → entities
162
+ {{#if IS_BLAZOR}}...{{/if}} → Conditional blocks
163
+ ```
164
+
165
+ Conditionals available in squad leader HOPs:
166
+ - `{{#if IS_BLAZOR}}` — Blazor-specific content
167
+ - `{{#if IS_NEXTJS}}` — Next.js-specific content
168
+ - `{{#if HAS_BACKEND}}` — Backend domain present
169
+ - `{{#if HAS_INFRA}}` — Infrastructure domain present
170
+
171
+ ---
172
+
173
+ ## HOP Composition Example
174
+
175
+ Combining HOPs for a full parallel execution:
176
+
177
+ ```javascript
178
+ // 1. Render coordinator prompt
179
+ const coordinatorPrompt = renderHOP('hop-parallel-coordinator', {
180
+ FEATURE_NAME: 'user-auth',
181
+ SQUADS: 'backend, frontend',
182
+ TOTAL_THREADS: '2'
183
+ }, { frameworkRoot });
184
+
185
+ // 2. Render worker prompts per domain
186
+ const backendPrompt = renderHOP('hop-parallel-worker', {
187
+ THREAD_ID: 'thr_backend_001',
188
+ DOMAIN: 'backend',
189
+ ASSIGNED_FILES: 'Services/UserService.cs\nControllers/AuthController.cs',
190
+ TASKS: '- T001: UserService\n- T002: AuthController'
191
+ }, { frameworkRoot });
192
+
193
+ const frontendPrompt = renderHOP('hop-parallel-worker', {
194
+ THREAD_ID: 'thr_frontend_001',
195
+ DOMAIN: 'frontend',
196
+ ASSIGNED_FILES: 'components/LoginForm.tsx\npages/login.tsx',
197
+ TASKS: '- T003: LoginForm\n- T004: Login page'
198
+ }, { frameworkRoot });
199
+
200
+ // 3. Spawn via Task tool
201
+ // Use backendPrompt and frontendPrompt as subagent prompts
202
+ ```
203
+
204
+ ---
205
+
206
+ ## REGISTRY.json
207
+
208
+ All HOPs are registered in `framework/templates/meta-prompts/REGISTRY.json`:
209
+
210
+ ```json
211
+ {
212
+ "hops": [
213
+ {
214
+ "id": "hop-backend-squad",
215
+ "type": "squad-leader",
216
+ "file": "squad-leaders/backend-squad.md",
217
+ "description": "Backend squad leader for .NET implementation",
218
+ "variables": ["AGENT_ID", "MISSION", "SPEC_SUMMARY", "TASKS", "DELIVERABLES"]
219
+ }
220
+ ]
221
+ }
222
+ ```
223
+
224
+ To add a custom HOP:
225
+ 1. Create your `.md` file in the appropriate category folder
226
+ 2. Add an entry to `REGISTRY.json`
227
+ 3. Use `morph-spec hop list` to verify it appears
228
+
229
+ ---
230
+
231
+ ## Related
232
+
233
+ - [Thread Management](THREAD-MANAGEMENT.md) — How HOPs are used in thread spawning
234
+ - [Context Optimization](CONTEXT-OPTIMIZATION.md) — Token-efficient prompt design
235
+ - `src/lib/hop-composer.js` — Rendering engine source
@@ -0,0 +1,253 @@
1
+ # Migration Guide — MORPH-SPEC v2.x → v3.0
2
+
3
+ This guide covers migrating an existing MORPH-SPEC v2.x installation to v3.0.0.
4
+
5
+ ---
6
+
7
+ ## What Changes in v3.0
8
+
9
+ ### state.json Schema (breaking)
10
+
11
+ v3.0 adds required fields to `state.json`:
12
+
13
+ | Field | Where | Description |
14
+ |-------|-------|-------------|
15
+ | `version` | root | Updated from `2.x.x` → `3.0.0` |
16
+ | `threads` | root | New `{}` object for thread tracking |
17
+ | `features.*.threadMetrics` | per-feature | Thread statistics object |
18
+ | `features.*.trustConfig` | per-feature | Trust level and override |
19
+ | `features.*.contextBundles` | per-feature | Array of context bundle references |
20
+ | `features.*.checkpoints` | per-feature | Array (if not already present) |
21
+ | `metadata.migratedAt` | metadata | Migration timestamp |
22
+
23
+ ### agents.json (additive, non-breaking)
24
+
25
+ v3.0 adds 4 new agents. Existing agents are preserved unchanged:
26
+ - `vector-search-expert` — Azure AI Search + RAG
27
+ - `thread-orchestrator` — Parallel execution coordination
28
+ - `context-optimizer` — Token efficiency
29
+ - `observability-expert` — App Insights, Serilog, OpenTelemetry
30
+
31
+ ### New CLI Commands
32
+
33
+ All new — no existing commands changed:
34
+ - `morph-spec threads [list|status|kill|analytics|wait-all|wait-any]`
35
+ - `morph-spec trust [status|set|history|auto-calculate|clear]`
36
+ - `morph-spec migrate [status|v2-to-v3|rollback-to-v2]`
37
+ - `morph-spec hop [list|render]`
38
+ - `morph-spec analytics [feature|context|project]`
39
+ - `morph-spec core-four`
40
+ - `morph-spec parallel [plan|run|status]`
41
+ - `morph-spec fusion [run|aggregate]`
42
+ - `morph-spec mcp [optimize|list]`
43
+ - `morph-spec micro-agent [create|list|show]`
44
+ - `morph-spec prime`
45
+
46
+ ### New Framework Files
47
+
48
+ 83 new files added across:
49
+ - `src/lib/` — 15 new library files
50
+ - `src/commands/` — 11 new command files
51
+ - `src/migrations/` — 2 migration scripts
52
+ - `framework/templates/meta-prompts/` — 12 HOP templates
53
+ - `framework/standards/` — 23 new standards files
54
+ - `framework/workflows/configs/zero-touch.json`
55
+ - `test/integration/` — 4 integration test suites
56
+ - `docs/next-generation/` — 6 documentation files
57
+
58
+ ---
59
+
60
+ ## Prerequisites
61
+
62
+ Before migrating:
63
+
64
+ - [ ] MORPH-SPEC CLI version ≥ 4.2.0 (`morph-spec --version`)
65
+ - [ ] Node.js ≥ 18 (`node --version`)
66
+ - [ ] Git working tree clean (`git status`)
67
+ - [ ] Current `.morph/state.json` is valid JSON
68
+
69
+ ```bash
70
+ # Verify CLI version
71
+ morph-spec --version
72
+ # Should show: 4.2.0 or higher
73
+
74
+ # Check migration status before starting
75
+ morph-spec migrate status
76
+ ```
77
+
78
+ ---
79
+
80
+ ## Step-by-Step Migration
81
+
82
+ ### Step 1: Check current state
83
+
84
+ ```bash
85
+ morph-spec migrate status
86
+ ```
87
+
88
+ Expected output:
89
+ ```
90
+ 📊 Migration Status
91
+
92
+ state.json
93
+ Version: ⚠ Needs migration (current: v2.1.1)
94
+ Needs update: Yes
95
+ Has backup: No
96
+
97
+ agents.json files
98
+ ⚠ .morph/config/agents.json
99
+ Missing: vector-search-expert, thread-orchestrator, context-optimizer, observability-expert
100
+ ```
101
+
102
+ ### Step 2: Run the migration
103
+
104
+ ```bash
105
+ morph-spec migrate v2-to-v3
106
+ ```
107
+
108
+ This will:
109
+ 1. Backup `state.json` → `state.v2.backup.json`
110
+ 2. Update `state.json` version to `3.0.0`
111
+ 3. Add `threads: {}` to root
112
+ 4. Add `threadMetrics`, `trustConfig`, `contextBundles` to each feature
113
+ 5. Add 4 new agents to each `agents.json` file found
114
+
115
+ Expected output:
116
+ ```
117
+ 🚀 Migrating MORPH-SPEC v2 → v3.0
118
+
119
+ Step 1: Migrating state.json (2.1.1 → 3.0.0)
120
+ ✓ Migration complete: v2.1.1 → 3.0.0
121
+ Backup: .morph/state.v2.backup.json
122
+ Changes:
123
+ • Version: 2.1.1 → 3.0.0
124
+ • Added: threads: {}
125
+ • Feature "user-auth": added threadMetrics, trustConfig, contextBundles, checkpoints
126
+ • Updated metadata.lastUpdated and migratedAt
127
+
128
+ Step 2: Updating agents.json files
129
+ ✓ .morph/config/agents.json: added vector-search-expert, thread-orchestrator, context-optimizer, observability-expert
130
+ – stacks/blazor-azure/.morph/config/agents.json: already up to date
131
+
132
+ ✅ Migration complete! MORPH-SPEC is now on v3.0.0
133
+ ```
134
+
135
+ ### Step 3: Verify migration
136
+
137
+ ```bash
138
+ morph-spec doctor --v3
139
+ ```
140
+
141
+ All checks should pass:
142
+ ```
143
+ ✅ 8/8 — All v3.0 checks passed!
144
+ ```
145
+
146
+ ### Step 4: Commit the migration
147
+
148
+ ```bash
149
+ git add .morph/state.json .morph/config/agents.json
150
+ git commit -m "chore(migration): upgrade MORPH-SPEC state to v3.0.0"
151
+ ```
152
+
153
+ ---
154
+
155
+ ## Rollback
156
+
157
+ If the migration causes issues, restore the v2 backup:
158
+
159
+ ```bash
160
+ morph-spec migrate rollback-to-v2 --force
161
+ ```
162
+
163
+ This restores `state.v2.backup.json` → `state.json`.
164
+
165
+ **Note:** `agents.json` changes are NOT rolled back (additive only, safe to keep).
166
+
167
+ ---
168
+
169
+ ## Manual Migration (Fallback)
170
+
171
+ If the automated migration fails, update `state.json` manually:
172
+
173
+ ```json
174
+ {
175
+ "version": "3.0.0",
176
+ "threads": {},
177
+ "features": {
178
+ "your-feature": {
179
+ "threadMetrics": {
180
+ "totalThreads": 0,
181
+ "completedThreads": 0,
182
+ "failedThreads": 0,
183
+ "parallelBatches": 0
184
+ },
185
+ "trustConfig": {
186
+ "level": "low",
187
+ "passRate": 0,
188
+ "lastCalculated": "2026-02-19T10:00:00.000Z"
189
+ },
190
+ "contextBundles": [],
191
+ "checkpoints": []
192
+ }
193
+ },
194
+ "metadata": {
195
+ "migratedAt": "2026-02-19T10:00:00.000Z",
196
+ "migratedFrom": "2.1.1"
197
+ }
198
+ }
199
+ ```
200
+
201
+ ---
202
+
203
+ ## Post-Migration: Enable v3.0 Features
204
+
205
+ After migration, v3.0 features are available immediately:
206
+
207
+ ```bash
208
+ # Check trust level (starts at "low")
209
+ morph-spec trust status
210
+
211
+ # View thread management
212
+ morph-spec threads list
213
+
214
+ # Try context priming
215
+ morph-spec prime feature
216
+
217
+ # Explore HOPs
218
+ morph-spec hop list
219
+ ```
220
+
221
+ **Trust level** starts at `low` until checkpoints accumulate. To reach `maximum` trust (required for zero-touch), complete 10+ checkpoints with >95% pass rate.
222
+
223
+ ---
224
+
225
+ ## Troubleshooting
226
+
227
+ ### "state.json not found"
228
+
229
+ Run `morph-spec state init` first to create the initial state.
230
+
231
+ ### "agents.json: Failed to parse"
232
+
233
+ Check for JSON syntax errors: `cat .morph/config/agents.json | node -e "JSON.parse(require('fs').readFileSync('/dev/stdin','utf8'))"`
234
+
235
+ ### "migration fails with unknown version"
236
+
237
+ The migration handles any version string that isn't `3.0.0`. If your version field is missing or corrupted, set it manually to `2.1.1` before running migration.
238
+
239
+ ### Rollback backup missing
240
+
241
+ If `state.v2.backup.json` is gone but you need v2:
242
+ - Restore from git: `git show HEAD:.morph/state.json > .morph/state.json`
243
+ - Or re-run migration (it's idempotent for already-migrated files)
244
+
245
+ ---
246
+
247
+ ## Related
248
+
249
+ - [Thread Management](THREAD-MANAGEMENT.md) — New thread features in v3.0
250
+ - [Context Optimization](CONTEXT-OPTIMIZATION.md) — Using new context tools
251
+ - [Meta-Prompts](META-PROMPTS.md) — HOP system overview
252
+ - `src/migrations/v2-to-v3.js` — Migration script source
253
+ - `src/migrations/agents-update.js` — Agents update script source