@polymorphism-tech/morph-spec 4.2.0 → 4.3.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.
- package/bin/morph-spec.js +283 -8
- package/bin/validate.js +4 -4
- package/docs/{v3.0 → next-generation}/AGENTS.md +1 -1
- package/docs/next-generation/CONTEXT-OPTIMIZATION.md +267 -0
- package/docs/next-generation/EXECUTION-FLOW.md +274 -0
- package/docs/next-generation/META-PROMPTS.md +235 -0
- package/docs/next-generation/MIGRATION-GUIDE.md +253 -0
- package/docs/next-generation/THREAD-MANAGEMENT.md +240 -0
- package/package.json +5 -5
- package/src/commands/agents/agents-fuse.js +96 -0
- package/src/commands/agents/micro-agent.js +112 -0
- package/src/commands/agents/spawn-team.js +69 -4
- package/src/commands/agents/squad-template.js +146 -0
- package/src/commands/analytics/analytics.js +176 -0
- package/src/commands/context/context-prime.js +63 -0
- package/src/commands/context/core-four.js +54 -0
- package/src/commands/mcp/mcp.js +102 -0
- package/src/commands/project/detect-agents.js +1 -1
- package/src/commands/project/doctor.js +573 -356
- package/src/commands/project/init.js +1 -1
- package/src/commands/project/update.js +1 -1
- package/src/commands/state/advance-phase.js +433 -416
- package/src/commands/templates/template-render.js +80 -1
- package/src/commands/threads/thread-template.js +103 -0
- package/src/commands/threads/threads.js +261 -0
- package/src/commands/trust/trust.js +205 -0
- package/src/{orchestrator.js → core/orchestrator.js} +8 -8
- package/src/core/state/state-manager.js +18 -2
- package/src/core/workflows/workflow-detector.js +100 -2
- package/src/lib/agents/micro-agent-factory.js +161 -0
- package/src/lib/analytics/analytics-engine.js +345 -0
- package/src/lib/checkpoints/checkpoint-hooks.js +293 -258
- package/src/lib/context/context-bundler.js +240 -0
- package/src/lib/context/context-optimizer.js +212 -0
- package/src/lib/context/context-tracker.js +273 -0
- package/src/lib/context/core-four-tracker.js +201 -0
- package/src/lib/context/mcp-optimizer.js +200 -0
- package/src/lib/execution/fusion-executor.js +304 -0
- package/src/lib/execution/parallel-executor.js +270 -0
- package/src/lib/generators/context-generator.js +3 -3
- package/src/lib/generators/recap-generator.js +2 -2
- package/src/lib/hooks/hook-executor.js +169 -0
- package/src/lib/hooks/stop-hook-executor.js +286 -0
- package/src/lib/hops/hop-composer.js +221 -0
- package/src/lib/threads/thread-coordinator.js +238 -0
- package/src/lib/threads/thread-manager.js +317 -0
- package/src/lib/tracking/artifact-trail.js +202 -0
- package/src/lib/trust/trust-manager.js +269 -0
- package/src/lib/validators/design-system/design-system-validator.js +2 -2
- package/src/lib/validators/validation-runner.js +6 -6
- package/stacks/blazor-azure/.morph/config/agents.json +72 -3
- package/stacks/nextjs-supabase/.morph/config/agents.json +3 -3
- package/CLAUDE.md +0 -993
- package/docs/llm-interaction-config.md +0 -735
- package/docs/v3.0/EXECUTION-FLOW.md +0 -1304
- package/src/commands/utils/migrate-state.js +0 -158
- package/src/commands/utils/upgrade.js +0 -346
- package/src/lib/validators/architecture-validator.js +0 -60
- package/src/lib/validators/content-validator.js +0 -164
- package/src/lib/validators/package-validator.js +0 -61
- package/src/lib/validators/ui-contrast-validator.js +0 -44
- package/stacks/blazor-azure/.claude/commands/morph-apply.md +0 -221
- package/stacks/blazor-azure/.claude/commands/morph-archive.md +0 -79
- package/stacks/blazor-azure/.claude/commands/morph-deploy.md +0 -529
- package/stacks/blazor-azure/.claude/commands/morph-infra.md +0 -209
- package/stacks/blazor-azure/.claude/commands/morph-preflight.md +0 -227
- package/stacks/blazor-azure/.claude/commands/morph-proposal.md +0 -122
- package/stacks/blazor-azure/.claude/commands/morph-status.md +0 -86
- package/stacks/blazor-azure/.claude/commands/morph-troubleshoot.md +0 -122
- package/stacks/blazor-azure/.claude/skills/level-0-meta/README.md +0 -7
- package/stacks/blazor-azure/.claude/skills/level-0-meta/code-review.md +0 -226
- package/stacks/blazor-azure/.claude/skills/level-0-meta/morph-checklist.md +0 -117
- package/stacks/blazor-azure/.claude/skills/level-0-meta/simulation-checklist.md +0 -77
- package/stacks/blazor-azure/.claude/skills/level-1-workflows/README.md +0 -7
- package/stacks/blazor-azure/.claude/skills/level-1-workflows/morph-replicate.md +0 -213
- package/stacks/blazor-azure/.claude/skills/level-1-workflows/phase-clarify.md +0 -131
- package/stacks/blazor-azure/.claude/skills/level-1-workflows/phase-design.md +0 -213
- package/stacks/blazor-azure/.claude/skills/level-1-workflows/phase-setup.md +0 -106
- package/stacks/blazor-azure/.claude/skills/level-1-workflows/phase-tasks.md +0 -164
- package/stacks/blazor-azure/.claude/skills/level-1-workflows/phase-uiux.md +0 -169
- package/stacks/blazor-azure/.claude/skills/level-2-domains/README.md +0 -14
- package/stacks/blazor-azure/.claude/skills/level-2-domains/ai-agents/ai-system-architect.md +0 -192
- package/stacks/blazor-azure/.claude/skills/level-2-domains/architecture/po-pm-advisor.md +0 -197
- package/stacks/blazor-azure/.claude/skills/level-2-domains/architecture/prompt-engineer.md +0 -189
- package/stacks/blazor-azure/.claude/skills/level-2-domains/architecture/seo-growth-hacker.md +0 -320
- package/stacks/blazor-azure/.claude/skills/level-2-domains/architecture/standards-architect.md +0 -156
- package/stacks/blazor-azure/.claude/skills/level-2-domains/backend/api-designer.md +0 -59
- package/stacks/blazor-azure/.claude/skills/level-2-domains/backend/dotnet-senior.md +0 -77
- package/stacks/blazor-azure/.claude/skills/level-2-domains/backend/ef-modeler.md +0 -58
- package/stacks/blazor-azure/.claude/skills/level-2-domains/backend/hangfire-orchestrator.md +0 -126
- package/stacks/blazor-azure/.claude/skills/level-2-domains/backend/ms-agent-expert.md +0 -45
- package/stacks/blazor-azure/.claude/skills/level-2-domains/frontend/blazor-builder.md +0 -210
- package/stacks/blazor-azure/.claude/skills/level-2-domains/frontend/nextjs-expert.md +0 -154
- package/stacks/blazor-azure/.claude/skills/level-2-domains/frontend/ui-ux-designer.md +0 -191
- package/stacks/blazor-azure/.claude/skills/level-2-domains/infrastructure/azure-architect.md +0 -142
- package/stacks/blazor-azure/.claude/skills/level-2-domains/infrastructure/azure-deploy-specialist.md +0 -699
- package/stacks/blazor-azure/.claude/skills/level-2-domains/infrastructure/bicep-architect.md +0 -126
- package/stacks/blazor-azure/.claude/skills/level-2-domains/infrastructure/container-specialist.md +0 -131
- package/stacks/blazor-azure/.claude/skills/level-2-domains/infrastructure/devops-engineer.md +0 -119
- package/stacks/blazor-azure/.claude/skills/level-2-domains/integrations/asaas-financial.md +0 -130
- package/stacks/blazor-azure/.claude/skills/level-2-domains/integrations/azure-identity.md +0 -142
- package/stacks/blazor-azure/.claude/skills/level-2-domains/integrations/clerk-auth.md +0 -108
- package/stacks/blazor-azure/.claude/skills/level-2-domains/integrations/hangfire-orchestrator.md +0 -64
- package/stacks/blazor-azure/.claude/skills/level-2-domains/integrations/resend-email.md +0 -119
- package/stacks/blazor-azure/.claude/skills/level-2-domains/quality/code-analyzer.md +0 -235
- package/stacks/blazor-azure/.claude/skills/level-2-domains/quality/testing-specialist.md +0 -126
- package/stacks/blazor-azure/.claude/skills/level-3-technologies/README.md +0 -7
- package/stacks/blazor-azure/.claude/skills/level-4-patterns/README.md +0 -7
- package/stacks/blazor-azure/.morph/archive/.gitkeep +0 -25
- package/stacks/blazor-azure/.morph/features/.gitkeep +0 -25
- package/stacks/blazor-azure/.morph/schemas/agent.schema.json +0 -296
- package/stacks/blazor-azure/.morph/schemas/tasks.schema.json +0 -220
- package/stacks/blazor-azure/.morph/specs/.gitkeep +0 -20
- package/stacks/blazor-azure/.morph/test-infra/example.bicep +0 -59
- package/stacks/nextjs-supabase/.claude/commands/morph-apply.md +0 -221
- package/stacks/nextjs-supabase/.claude/commands/morph-archive.md +0 -79
- package/stacks/nextjs-supabase/.claude/commands/morph-deploy.md +0 -529
- package/stacks/nextjs-supabase/.claude/commands/morph-infra.md +0 -209
- package/stacks/nextjs-supabase/.claude/commands/morph-preflight.md +0 -227
- package/stacks/nextjs-supabase/.claude/commands/morph-proposal.md +0 -122
- package/stacks/nextjs-supabase/.claude/commands/morph-status.md +0 -86
- package/stacks/nextjs-supabase/.claude/commands/morph-troubleshoot.md +0 -122
- package/stacks/nextjs-supabase/.claude/settings.local.json +0 -6
- package/stacks/nextjs-supabase/.claude/skills/level-2-domains/backend/dotnet-supabase.md +0 -244
- package/stacks/nextjs-supabase/.claude/skills/level-2-domains/frontend/nextjs-supabase.md +0 -335
- package/stacks/nextjs-supabase/.claude/skills/level-2-domains/infrastructure/easypanel-deployer.md +0 -189
- package/stacks/nextjs-supabase/.claude/skills/level-2-domains/integrations/supabase-expert.md +0 -50
- /package/docs/{v3.0 → next-generation}/ANALYSIS.md +0 -0
- /package/docs/{v3.0 → next-generation}/ARCHITECTURE.md +0 -0
- /package/docs/{v3.0 → next-generation}/FEATURES.md +0 -0
- /package/docs/{v3.0 → next-generation}/README.md +0 -0
- /package/docs/{v3.0 → next-generation}/ROADMAP.md +0 -0
|
@@ -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
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
# Thread Management — MORPH-SPEC v3.0
|
|
2
|
+
|
|
3
|
+
Thread management is the v3.0 system for coordinating multi-agent execution within a single feature. Threads allow parallel, sequential, and hybrid agent workflows with full lifecycle tracking.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Thread Types
|
|
8
|
+
|
|
9
|
+
| Thread | Code | Purpose | Auto-kill? |
|
|
10
|
+
|--------|------|---------|------------|
|
|
11
|
+
| **Base Thread** | B | Single agent, sequential implementation | No |
|
|
12
|
+
| **Parallel Thread** | P | Isolated domain worker in a parallel squad | No |
|
|
13
|
+
| **Fusion Thread** | F | One of N agents solving the same problem | No |
|
|
14
|
+
| **Long-Running** | L | Persistent background agent with stop hooks | Yes (on stop hook) |
|
|
15
|
+
| **Zero-Touch** | Z | Autonomous agent with auto-approval (requires max trust) | No |
|
|
16
|
+
|
|
17
|
+
### Choosing a Thread Type
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
Is this a single, sequential implementation?
|
|
21
|
+
└─ YES → B-Thread (Base)
|
|
22
|
+
|
|
23
|
+
Do you want N agents working on different domains simultaneously?
|
|
24
|
+
└─ YES → P-Thread (Parallel) per domain
|
|
25
|
+
|
|
26
|
+
Do you want N agents solving the SAME problem (pick best result)?
|
|
27
|
+
└─ YES → F-Thread (Fusion)
|
|
28
|
+
|
|
29
|
+
Will the agent run for >30 minutes or need periodic check-ins?
|
|
30
|
+
└─ YES → L-Thread (Long-Running)
|
|
31
|
+
|
|
32
|
+
Is trust level "maximum" (>95% checkpoint pass rate)?
|
|
33
|
+
└─ YES → Z-Thread (Zero-Touch) eligible
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Thread Lifecycle
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
pending → running → completed
|
|
42
|
+
└→ failed
|
|
43
|
+
└→ killed
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Each thread stores its state in `.morph/state.json` under `threads`:
|
|
47
|
+
|
|
48
|
+
```json
|
|
49
|
+
{
|
|
50
|
+
"threads": {
|
|
51
|
+
"thr_abc12345": {
|
|
52
|
+
"id": "thr_abc12345",
|
|
53
|
+
"type": "parallel",
|
|
54
|
+
"feature": "user-auth",
|
|
55
|
+
"agent": "dotnet-senior",
|
|
56
|
+
"status": "running",
|
|
57
|
+
"startedAt": "2026-02-19T10:00:00Z",
|
|
58
|
+
"completedAt": null,
|
|
59
|
+
"metrics": {
|
|
60
|
+
"tasksCompleted": 3,
|
|
61
|
+
"filesCreated": 5,
|
|
62
|
+
"filesModified": 2,
|
|
63
|
+
"checkpointsPassed": 1,
|
|
64
|
+
"checkpointsFailed": 0
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## CLI Reference
|
|
74
|
+
|
|
75
|
+
### List threads
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
morph-spec threads list
|
|
79
|
+
morph-spec threads list --feature user-auth
|
|
80
|
+
morph-spec threads list --status running
|
|
81
|
+
morph-spec threads list --type parallel
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Thread status
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
morph-spec threads status thr_abc12345
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Kill a thread
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
morph-spec threads kill thr_abc12345
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Analytics
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
morph-spec threads analytics --feature user-auth
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Wait for completion
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
# Wait for ALL threads in a feature
|
|
106
|
+
morph-spec threads wait-all user-auth --timeout 60
|
|
107
|
+
|
|
108
|
+
# Wait for ANY thread to complete
|
|
109
|
+
morph-spec threads wait-any user-auth --timeout 30
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## P-Thread Isolation Rules
|
|
115
|
+
|
|
116
|
+
Parallel threads (P-Threads) MUST follow strict isolation:
|
|
117
|
+
|
|
118
|
+
| Rule | Description |
|
|
119
|
+
|------|-------------|
|
|
120
|
+
| **File ownership** | Each P-Thread writes ONLY to its assigned file set |
|
|
121
|
+
| **Read-only shared** | Shared files (spec.md, contracts, standards) are READ-ONLY |
|
|
122
|
+
| **No cross-writes** | Never write to another thread's files |
|
|
123
|
+
| **Report on done** | Submit PARALLEL WORKER REPORT when complete |
|
|
124
|
+
| **No external calls** | Don't spawn additional threads |
|
|
125
|
+
|
|
126
|
+
### P-Thread Report Format
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
## PARALLEL WORKER REPORT
|
|
130
|
+
|
|
131
|
+
**Thread ID:** {id}
|
|
132
|
+
**Status:** completed | failed | blocked
|
|
133
|
+
|
|
134
|
+
**Files Created:**
|
|
135
|
+
- path/to/file1.cs
|
|
136
|
+
- path/to/file2.cs
|
|
137
|
+
|
|
138
|
+
**Tasks Completed:** T001, T002, T003
|
|
139
|
+
|
|
140
|
+
**Blockers (if any):** None
|
|
141
|
+
|
|
142
|
+
**Notes:** Any important implementation decisions
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## L-Thread Stop Hooks
|
|
148
|
+
|
|
149
|
+
Long-running threads respond to stop hooks. Configure in `.claude/settings.local.json`:
|
|
150
|
+
|
|
151
|
+
```json
|
|
152
|
+
{
|
|
153
|
+
"hooks": {
|
|
154
|
+
"Stop": [
|
|
155
|
+
{
|
|
156
|
+
"matcher": "",
|
|
157
|
+
"hooks": [
|
|
158
|
+
{
|
|
159
|
+
"type": "command",
|
|
160
|
+
"command": "node framework/hooks/agent-teams/validate-and-continue.js {feature}"
|
|
161
|
+
}
|
|
162
|
+
]
|
|
163
|
+
}
|
|
164
|
+
]
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Stop hooks run every N seconds (configurable in `zero-touch.json`):
|
|
170
|
+
|
|
171
|
+
```json
|
|
172
|
+
{
|
|
173
|
+
"monitoring": {
|
|
174
|
+
"stopHooks": {
|
|
175
|
+
"enabled": true,
|
|
176
|
+
"interval": 30,
|
|
177
|
+
"hooks": ["validate-and-continue", "validate-checkpoints"]
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## Thread Metrics Tracking
|
|
186
|
+
|
|
187
|
+
Each feature tracks aggregate thread metrics in `state.json`:
|
|
188
|
+
|
|
189
|
+
```json
|
|
190
|
+
{
|
|
191
|
+
"features": {
|
|
192
|
+
"user-auth": {
|
|
193
|
+
"threadMetrics": {
|
|
194
|
+
"totalThreads": 3,
|
|
195
|
+
"completedThreads": 2,
|
|
196
|
+
"failedThreads": 0,
|
|
197
|
+
"parallelBatches": 1
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Access via:
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
morph-spec analytics feature user-auth
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
## Decision Tree: When to Use Threads
|
|
213
|
+
|
|
214
|
+
```
|
|
215
|
+
Feature complexity?
|
|
216
|
+
SIMPLE (1-5 files) → B-Thread only, no parallelization
|
|
217
|
+
MEDIUM (6-15 files) → Consider P-Threads by domain
|
|
218
|
+
HIGH (>15 files) → P-Threads mandatory for speed
|
|
219
|
+
|
|
220
|
+
Multiple independent domains?
|
|
221
|
+
YES → Spawn P-Thread per domain (backend, frontend, infra)
|
|
222
|
+
NO → Single B-Thread is fine
|
|
223
|
+
|
|
224
|
+
Need best-quality output from N attempts?
|
|
225
|
+
YES → F-Thread (Fusion) with aggregation
|
|
226
|
+
|
|
227
|
+
Long implementation (>30 mins estimated)?
|
|
228
|
+
YES → L-Thread with stop hooks for periodic validation
|
|
229
|
+
|
|
230
|
+
Trust level maximum + fully automated pipeline?
|
|
231
|
+
YES → Z-Thread (check with: morph-spec trust status)
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
## Related
|
|
237
|
+
|
|
238
|
+
- [Parallel Execution](PARALLEL-EXECUTION.md) — Squad templates and P-Thread coordination
|
|
239
|
+
- [Context Optimization](CONTEXT-OPTIMIZATION.md) — Token efficiency during thread execution
|
|
240
|
+
- [Migration Guide](MIGRATION-GUIDE.md) — Upgrading state.json to v3.0 thread schema
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polymorphism-tech/morph-spec",
|
|
3
|
-
"version": "4.
|
|
4
|
-
"description": "MORPH-SPEC
|
|
3
|
+
"version": "4.3.0",
|
|
4
|
+
"description": "MORPH-SPEC: AI-First development framework with validation pipeline and multi-stack support",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"claude-code",
|
|
7
7
|
"claude",
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
"scripts": {
|
|
41
41
|
"postinstall": "node scripts/postinstall.js",
|
|
42
42
|
"start": "node bin/morph-spec.js",
|
|
43
|
-
"test": "node --test",
|
|
44
|
-
"test:coverage": "c8 --reporter=text --reporter=html --reporter=lcov node --test",
|
|
45
|
-
"test:coverage:summary": "c8 --reporter=text-summary node --test",
|
|
43
|
+
"test": "node --test --test-concurrency=1",
|
|
44
|
+
"test:coverage": "c8 --reporter=text --reporter=html --reporter=lcov node --test --test-concurrency=1",
|
|
45
|
+
"test:coverage:summary": "c8 --reporter=text-summary node --test --test-concurrency=1",
|
|
46
46
|
"docs": "jsdoc -c jsdoc.json",
|
|
47
47
|
"docs:watch": "jsdoc -c jsdoc.json --watch",
|
|
48
48
|
"docs:serve": "npx http-server docs/api -p 8080 -o"
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agents Fuse CLI command — F-Thread fusion execution
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* morph-spec agents fuse --prompt "..." --count=3 --strategy=best-of-n [--feature=<f>]
|
|
6
|
+
* morph-spec agents review aggregate <feature> --agents=a1,a2,a3
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import chalk from 'chalk';
|
|
10
|
+
import { runFusion, aggregateResults, displayFusionSummary } from '../../lib/execution/fusion-executor.js';
|
|
11
|
+
|
|
12
|
+
export async function agentsFuseCommand(options) {
|
|
13
|
+
if (!options.prompt) {
|
|
14
|
+
console.error(chalk.red('--prompt is required'));
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const count = parseInt(options.count || '3', 10);
|
|
19
|
+
const strategy = options.strategy || 'best-of-n';
|
|
20
|
+
const feature = options.feature || 'fusion-session';
|
|
21
|
+
const agents = options.agents ? options.agents.split(',').map(a => a.trim()) : null;
|
|
22
|
+
|
|
23
|
+
console.log(chalk.cyan(`\n F-Thread Fusion Execution\n`));
|
|
24
|
+
console.log(` Strategy: ${strategy}`);
|
|
25
|
+
console.log(` Agents: ${count}`);
|
|
26
|
+
console.log(` Feature: ${feature}`);
|
|
27
|
+
console.log(` Prompt: ${options.prompt.substring(0, 80)}${options.prompt.length > 80 ? '...' : ''}`);
|
|
28
|
+
console.log('');
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
const fusionSession = await runFusion(options.prompt, {
|
|
32
|
+
feature,
|
|
33
|
+
count,
|
|
34
|
+
strategy,
|
|
35
|
+
agents
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
console.log(chalk.cyan(` ${fusionSession.threads.length} fusion threads spawned:\n`));
|
|
39
|
+
for (let i = 0; i < fusionSession.threads.length; i++) {
|
|
40
|
+
const thread = fusionSession.threads[i];
|
|
41
|
+
const agent = fusionSession.agentConfigs[i];
|
|
42
|
+
console.log(` ${chalk.gray(thread.id.substring(0, 8))} — Agent: ${agent.agentId} (${thread.status})`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
console.log(chalk.yellow('\n ⚠ Fusion threads spawned. To aggregate results:'));
|
|
46
|
+
console.log(chalk.gray(' 1. Execute each thread using the Task tool with the agent configs'));
|
|
47
|
+
console.log(chalk.gray(' 2. Collect results from each agent'));
|
|
48
|
+
console.log(chalk.gray(' 3. Run: morph-spec agents fuse-aggregate --results=<file> --strategy=' + strategy));
|
|
49
|
+
console.log('');
|
|
50
|
+
|
|
51
|
+
if (options.json) {
|
|
52
|
+
console.log(JSON.stringify({
|
|
53
|
+
threads: fusionSession.threads.map(t => ({ id: t.id, agent: t.agent, status: t.status })),
|
|
54
|
+
agentConfigs: fusionSession.agentConfigs,
|
|
55
|
+
strategy,
|
|
56
|
+
feature
|
|
57
|
+
}, null, 2));
|
|
58
|
+
}
|
|
59
|
+
} catch (err) {
|
|
60
|
+
console.error(chalk.red(`Error: ${err.message}`));
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export async function agentsReviewAggregateCommand(feature, options) {
|
|
66
|
+
if (!options.agents) {
|
|
67
|
+
console.error(chalk.red('--agents is required (comma-separated list)'));
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const agentList = options.agents.split(',').map(a => a.trim());
|
|
72
|
+
const strategy = options.strategy || 'best-of-n';
|
|
73
|
+
|
|
74
|
+
console.log(chalk.cyan(`\n Aggregate Reviews — ${feature}\n`));
|
|
75
|
+
console.log(` Agents: ${agentList.join(', ')}`);
|
|
76
|
+
console.log(` Strategy: ${strategy}`);
|
|
77
|
+
console.log('');
|
|
78
|
+
|
|
79
|
+
// Mock results for demo — in real usage, results come from agent output files
|
|
80
|
+
const mockResults = agentList.map((agentId, i) => ({
|
|
81
|
+
agentId,
|
|
82
|
+
content: `Agent ${agentId} review for ${feature}`,
|
|
83
|
+
checkpointsPassed: Math.floor(Math.random() * 3) + 2,
|
|
84
|
+
checkpointsFailed: Math.floor(Math.random() * 2),
|
|
85
|
+
errors: Math.floor(Math.random() * 2),
|
|
86
|
+
warnings: Math.floor(Math.random() * 3)
|
|
87
|
+
}));
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
const aggregated = aggregateResults(mockResults, strategy);
|
|
91
|
+
displayFusionSummary(aggregated);
|
|
92
|
+
} catch (err) {
|
|
93
|
+
console.error(chalk.red(`Error: ${err.message}`));
|
|
94
|
+
process.exit(1);
|
|
95
|
+
}
|
|
96
|
+
}
|