@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,274 @@
|
|
|
1
|
+
# Execution Flow — MORPH-SPEC v3.0
|
|
2
|
+
|
|
3
|
+
This document describes the complete execution flow of a v3.0 feature from first request to sync, including all new v3.0 decision points and automation paths.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## High-Level Flow
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
User Request
|
|
11
|
+
│
|
|
12
|
+
▼
|
|
13
|
+
┌─────────────┐
|
|
14
|
+
│ WORKFLOW │ Auto-detect: fast-track / standard / full-morph
|
|
15
|
+
│ DETECTION │ Command: morph-spec detect-workflow "<request>"
|
|
16
|
+
└──────┬──────┘
|
|
17
|
+
│
|
|
18
|
+
▼
|
|
19
|
+
┌─────────────┐
|
|
20
|
+
│ CONTEXT │ Load priming file (500 tokens vs 23K CLAUDE.md)
|
|
21
|
+
│ PRIMING │ Command: morph-spec prime feature
|
|
22
|
+
└──────┬──────┘
|
|
23
|
+
│
|
|
24
|
+
▼
|
|
25
|
+
┌─────────────┐
|
|
26
|
+
│ PROPOSAL │ Agents detected, workflow confirmed
|
|
27
|
+
│ PHASE │ Gate: proposal approval (auto if trust >= high)
|
|
28
|
+
└──────┬──────┘
|
|
29
|
+
│
|
|
30
|
+
▼
|
|
31
|
+
┌─────────────┐
|
|
32
|
+
│ DESIGN │ spec.md + contracts + decisions.md
|
|
33
|
+
│ PHASE │ Gate: design approval (auto if trust >= medium)
|
|
34
|
+
└──────┬──────┘
|
|
35
|
+
│
|
|
36
|
+
▼
|
|
37
|
+
┌─────────────┐
|
|
38
|
+
│ CLARIFY │ Resolve ambiguities, update spec
|
|
39
|
+
│ PHASE │ (no gate, auto-continues)
|
|
40
|
+
└──────┬──────┘
|
|
41
|
+
│
|
|
42
|
+
▼
|
|
43
|
+
┌─────────────┐
|
|
44
|
+
│ TASKS │ tasks.json: IDs, deps, phases
|
|
45
|
+
│ PHASE │ Gate: tasks approval (auto if trust >= high)
|
|
46
|
+
└──────┬──────┘
|
|
47
|
+
│
|
|
48
|
+
▼
|
|
49
|
+
┌─────────────────────────────────────────────────────────┐
|
|
50
|
+
│ IMPLEMENT PHASE │
|
|
51
|
+
│ │
|
|
52
|
+
│ ┌─────────────┐ ┌─────────────┐ │
|
|
53
|
+
│ │ Single │ │ Parallel │ │
|
|
54
|
+
│ │ B-Thread │ │ P-Threads │ │
|
|
55
|
+
│ │ (simple) │ │ (complex) │ │
|
|
56
|
+
│ └──────┬──────┘ └──────┬──────┘ │
|
|
57
|
+
│ │ │ │
|
|
58
|
+
│ │ ┌────────┴────────┐ │
|
|
59
|
+
│ │ │ Squad Planning │ │
|
|
60
|
+
│ │ │ morph-spec │ │
|
|
61
|
+
│ │ │ parallel plan │ │
|
|
62
|
+
│ │ └────────┬────────┘ │
|
|
63
|
+
│ │ │ │
|
|
64
|
+
│ │ ┌─────────────┼─────────────┐ │
|
|
65
|
+
│ │ ▼ ▼ ▼ │
|
|
66
|
+
│ │ Backend Frontend Infra │
|
|
67
|
+
│ │ P-Thread P-Thread P-Thread │
|
|
68
|
+
│ │ │ │ │ │
|
|
69
|
+
│ │ └─────────────┴─────────────┘ │
|
|
70
|
+
│ │ │ │
|
|
71
|
+
│ │ Coordinator │
|
|
72
|
+
│ │ Merges results │
|
|
73
|
+
│ │ │ │
|
|
74
|
+
│ └──────────────────┘ │
|
|
75
|
+
│ │ │
|
|
76
|
+
│ Every 3 tasks: │
|
|
77
|
+
│ CHECKPOINT ──> Validators │
|
|
78
|
+
│ │ - architecture │
|
|
79
|
+
│ │ - security │
|
|
80
|
+
│ │ - packages │
|
|
81
|
+
│ │ │
|
|
82
|
+
│ Trust updates automatically │
|
|
83
|
+
└─────────────────────────────┬───────────────────────────┘
|
|
84
|
+
│
|
|
85
|
+
▼
|
|
86
|
+
┌─────────────┐
|
|
87
|
+
│ SYNC │ Recap + decisions archive
|
|
88
|
+
│ PHASE │
|
|
89
|
+
└──────┬──────┘
|
|
90
|
+
│
|
|
91
|
+
▼
|
|
92
|
+
┌─────────────┐
|
|
93
|
+
│ ARCHIVED │ Feature complete
|
|
94
|
+
└─────────────┘
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## v3.0 Decision Points
|
|
100
|
+
|
|
101
|
+
### 1. Workflow Detection
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
morph-spec detect-workflow "<request>"
|
|
105
|
+
│
|
|
106
|
+
├─ fast-track → 2 phases (skip most)
|
|
107
|
+
├─ standard → 4 phases (skip UIUX, CLARIFY, SYNC)
|
|
108
|
+
├─ full-morph → ALL phases
|
|
109
|
+
├─ design-impl → prototype-focused
|
|
110
|
+
└─ ui-refresh → visual-only
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### 2. Trust-Based Auto-Approval
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
Phase gate reached?
|
|
117
|
+
│
|
|
118
|
+
├─ Trust: low (<80%) → Manual approval required
|
|
119
|
+
├─ Trust: medium (>=80%) → Auto-approve: design gate
|
|
120
|
+
├─ Trust: high (>=90%) → Auto-approve: design + tasks gates
|
|
121
|
+
└─ Trust: maximum (>=95%)→ Auto-approve: all gates + zero-touch eligible
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Check current trust: `morph-spec trust status`
|
|
125
|
+
|
|
126
|
+
### 3. Parallel vs Sequential Implementation
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
Task count > 10 AND multi-domain?
|
|
130
|
+
YES → morph-spec parallel plan {feature}
|
|
131
|
+
→ Spawn P-Threads per domain
|
|
132
|
+
→ Wait: morph-spec threads wait-all {feature}
|
|
133
|
+
→ Merge results
|
|
134
|
+
NO → Single B-Thread sequential implementation
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### 4. Fusion Decision
|
|
138
|
+
|
|
139
|
+
```
|
|
140
|
+
Need highest-quality output for critical component?
|
|
141
|
+
YES → morph-spec agents-fuse run --count 3 --strategy best-of-n
|
|
142
|
+
→ 3 F-Threads run independently
|
|
143
|
+
→ Aggregator picks best result
|
|
144
|
+
NO → Standard single-agent approach
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### 5. Checkpoint Gate
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
Task 3, 6, 9, ... completed?
|
|
151
|
+
│
|
|
152
|
+
├─ Run validators (architecture, security, packages)
|
|
153
|
+
├─ ALL PASS → Continue, update trust metrics
|
|
154
|
+
└─ FAIL → Block progress
|
|
155
|
+
→ Attempt 2: fix violations
|
|
156
|
+
→ Attempt 3: fix violations
|
|
157
|
+
→ Attempt 4: AskUserQuestion
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## Zero-Touch Path (Maximum Trust)
|
|
163
|
+
|
|
164
|
+
When trust level is `maximum` (>95% checkpoint pass rate across 10+ checkpoints):
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
Feature request
|
|
168
|
+
│
|
|
169
|
+
▼ morph-spec feature create --auto
|
|
170
|
+
┌──────────────────────────────────────┐
|
|
171
|
+
│ ZERO-TOUCH EXECUTION │
|
|
172
|
+
│ │
|
|
173
|
+
│ Proposal auto-approved │
|
|
174
|
+
│ Design auto-approved │
|
|
175
|
+
│ Tasks auto-approved │
|
|
176
|
+
│ Commits auto-signed │
|
|
177
|
+
│ Rollback auto-triggered on fail │
|
|
178
|
+
│ │
|
|
179
|
+
│ Escalation triggers: │
|
|
180
|
+
│ - Checkpoint fails 3x → pause │
|
|
181
|
+
│ - Architecture error → pause │
|
|
182
|
+
│ - Security error → BLOCK │
|
|
183
|
+
│ - Out-of-scope change → pause │
|
|
184
|
+
└──────────────────────────────────────┘
|
|
185
|
+
│
|
|
186
|
+
▼
|
|
187
|
+
Feature complete (no human intervention)
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Configure zero-touch: `framework/workflows/configs/zero-touch.json`
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## Analytics & Observability
|
|
195
|
+
|
|
196
|
+
At every step, analytics events are logged to `.morph/analytics/`:
|
|
197
|
+
|
|
198
|
+
| Event | Log File | When |
|
|
199
|
+
|-------|----------|------|
|
|
200
|
+
| Phase advanced | `threads-log.jsonl` | Each phase transition |
|
|
201
|
+
| Task completed | `threads-log.jsonl` | Each `task done` |
|
|
202
|
+
| Checkpoint passed/failed | `threads-log.jsonl` | Every 3 tasks |
|
|
203
|
+
| Trust level changed | `trust-log.jsonl` | After each checkpoint |
|
|
204
|
+
| Auto-approval used | `trust-log.jsonl` | When gate auto-approved |
|
|
205
|
+
| Thread created/killed | `threads-log.jsonl` | Thread lifecycle events |
|
|
206
|
+
|
|
207
|
+
View analytics: `morph-spec analytics feature {feature-name}`
|
|
208
|
+
|
|
209
|
+
---
|
|
210
|
+
|
|
211
|
+
## Context Efficiency at Each Phase
|
|
212
|
+
|
|
213
|
+
Recommended context loading per phase:
|
|
214
|
+
|
|
215
|
+
| Phase | Context Budget | Load |
|
|
216
|
+
|-------|---------------|------|
|
|
217
|
+
| Proposal | 5K tokens | `morph-spec prime feature` output only |
|
|
218
|
+
| Design | 15K tokens | Prime + relevant 2-3 standards |
|
|
219
|
+
| Clarify | 10K tokens | Spec summary + decisions |
|
|
220
|
+
| Tasks | 8K tokens | Spec summary + existing tasks |
|
|
221
|
+
| Implement | 20K/thread | Bundle + task-specific standards |
|
|
222
|
+
| Sync | 5K tokens | Recap + new decisions |
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
## CLI Quick Reference (v3.0 New Commands)
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
# Workflow detection
|
|
230
|
+
morph-spec detect-workflow "implement X"
|
|
231
|
+
|
|
232
|
+
# Context
|
|
233
|
+
morph-spec prime feature
|
|
234
|
+
morph-spec context bundle create {feature}
|
|
235
|
+
|
|
236
|
+
# Threads
|
|
237
|
+
morph-spec threads list
|
|
238
|
+
morph-spec threads wait-all {feature}
|
|
239
|
+
|
|
240
|
+
# Trust
|
|
241
|
+
morph-spec trust status
|
|
242
|
+
morph-spec trust auto-calculate {feature}
|
|
243
|
+
|
|
244
|
+
# Parallel
|
|
245
|
+
morph-spec parallel plan {feature}
|
|
246
|
+
morph-spec squad-template list
|
|
247
|
+
|
|
248
|
+
# Fusion
|
|
249
|
+
morph-spec agents-fuse run --count 3 --prompt "..."
|
|
250
|
+
|
|
251
|
+
# HOPs
|
|
252
|
+
morph-spec hop list
|
|
253
|
+
morph-spec hop render hop-backend-squad output.md --variables '{...}'
|
|
254
|
+
|
|
255
|
+
# Migration
|
|
256
|
+
morph-spec migrate status
|
|
257
|
+
morph-spec migrate v2-to-v3
|
|
258
|
+
|
|
259
|
+
# Analytics
|
|
260
|
+
morph-spec analytics feature {feature}
|
|
261
|
+
morph-spec core-four {feature}
|
|
262
|
+
|
|
263
|
+
# Doctor
|
|
264
|
+
morph-spec doctor --v3
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
---
|
|
268
|
+
|
|
269
|
+
## Related
|
|
270
|
+
|
|
271
|
+
- [Thread Management](THREAD-MANAGEMENT.md) — Thread types and lifecycle
|
|
272
|
+
- [Context Optimization](CONTEXT-OPTIMIZATION.md) — Token efficiency techniques
|
|
273
|
+
- [Meta-Prompts](META-PROMPTS.md) — HOP template system
|
|
274
|
+
- [Migration Guide](MIGRATION-GUIDE.md) — Upgrading from v2.x
|
|
@@ -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
|