@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.
- package/CLAUDE.md +108 -946
- package/bin/morph-spec.js +284 -9
- package/bin/task-manager.cjs +102 -14
- 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 +97 -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 +32 -2
- package/src/commands/project/detect.js +11 -1
- package/src/commands/project/doctor.js +573 -356
- package/src/commands/project/init.js +9 -2
- package/src/commands/project/update.js +13 -3
- package/src/commands/state/advance-phase.js +448 -416
- package/src/commands/state/state.js +14 -12
- package/src/commands/tasks/task.js +1 -1
- 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 +37 -17
- package/src/core/workflows/workflow-detector.js +114 -3
- 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 +298 -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/detectors/index.js +1 -1
- package/src/lib/detectors/standards-generator.js +77 -17
- package/src/lib/detectors/structure-detector.js +67 -39
- 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 +32 -12
- 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 +14 -30
- package/src/utils/hooks-installer.js +69 -0
- package/stacks/blazor-azure/.morph/config/agents.json +72 -3
- package/stacks/nextjs-supabase/.morph/config/agents.json +3 -3
- 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,267 @@
|
|
|
1
|
+
# Context Optimization — MORPH-SPEC v3.0
|
|
2
|
+
|
|
3
|
+
Context optimization is the practice of maximizing what useful work fits in the AI model's context window. v3.0 introduces structured techniques to reduce token waste and increase implementation quality per session.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## The Context Budget Problem
|
|
8
|
+
|
|
9
|
+
Claude's context window has a hard limit. A typical morph-next-gen feature session consumes:
|
|
10
|
+
|
|
11
|
+
| Component | Tokens (approx) |
|
|
12
|
+
|-----------|----------------|
|
|
13
|
+
| CLAUDE.md (full) | ~23,000 |
|
|
14
|
+
| spec.md (large) | ~8,000 |
|
|
15
|
+
| tasks.json | ~3,000 |
|
|
16
|
+
| Standards (3 files) | ~6,000 |
|
|
17
|
+
| Conversation history | Grows per turn |
|
|
18
|
+
| **Total overhead** | **~40,000+** |
|
|
19
|
+
|
|
20
|
+
Without optimization, implementation tokens are crowded out by reference material.
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## 12 Optimization Techniques
|
|
25
|
+
|
|
26
|
+
### 1. Context Priming (Biggest Win: ~80% reduction)
|
|
27
|
+
|
|
28
|
+
Instead of loading full CLAUDE.md, use a priming file (500 tokens vs 23,000):
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
# Output a focused priming file for your current task type
|
|
32
|
+
morph-spec prime feature
|
|
33
|
+
morph-spec prime bug
|
|
34
|
+
morph-spec prime refactor
|
|
35
|
+
morph-spec prime design
|
|
36
|
+
morph-spec prime infra
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Each prime file contains only the essential rules for that task type. Paste the output at the start of your session.
|
|
40
|
+
|
|
41
|
+
**Priming file locations:** `framework/templates/prime/{type}.md`
|
|
42
|
+
|
|
43
|
+
### 2. Context Bundles
|
|
44
|
+
|
|
45
|
+
Pre-compress feature context from ~180K tokens to ~15K:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# Create a bundle (compress all outputs for a feature)
|
|
49
|
+
morph-spec context bundle create user-auth
|
|
50
|
+
|
|
51
|
+
# Load a bundle at session start
|
|
52
|
+
morph-spec context bundle load user-auth
|
|
53
|
+
|
|
54
|
+
# List available bundles
|
|
55
|
+
morph-spec context bundle list
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Bundle structure:
|
|
59
|
+
|
|
60
|
+
```json
|
|
61
|
+
{
|
|
62
|
+
"id": "bundle-user-auth-2026-02",
|
|
63
|
+
"feature": "user-auth",
|
|
64
|
+
"created": "2026-02-19T10:00:00Z",
|
|
65
|
+
"tokenCount": 14800,
|
|
66
|
+
"includes": ["spec-summary", "decisions-summary", "task-list", "key-standards"],
|
|
67
|
+
"compressed": true
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### 3. Selective Standards Loading
|
|
72
|
+
|
|
73
|
+
Don't load all standards — load only what's relevant to the current task:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
# Bad: loads everything
|
|
77
|
+
# cat framework/standards/*.md
|
|
78
|
+
|
|
79
|
+
# Good: load only relevant standards
|
|
80
|
+
morph-spec prime feature | head -20
|
|
81
|
+
# Then manually load: coding.md, and ONE domain standard
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Standards priority for implementation tasks:
|
|
85
|
+
1. `coding.md` — always load
|
|
86
|
+
2. Domain standard (e.g., `supabase-rls.md` if working on auth)
|
|
87
|
+
3. Skip everything else
|
|
88
|
+
|
|
89
|
+
### 4. Micro-Agents for Narrow Tasks
|
|
90
|
+
|
|
91
|
+
Create ultra-specialized agents with minimal context (1-3 standards, narrow mission):
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
morph-spec micro-agent create rls-writer \
|
|
95
|
+
--base-agent supabase-expert \
|
|
96
|
+
--mission "Write RLS policies only" \
|
|
97
|
+
--standards supabase-rls.md \
|
|
98
|
+
--tools Read,Write
|
|
99
|
+
|
|
100
|
+
morph-spec micro-agent show rls-writer --show-prompt
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Micro-agents have 90%+ fewer tokens than full agents.
|
|
104
|
+
|
|
105
|
+
### 5. MCP Server Hygiene
|
|
106
|
+
|
|
107
|
+
Unnecessary MCP servers consume tokens via tool definitions:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
# Analyze current MCP overhead
|
|
111
|
+
morph-spec mcp optimize
|
|
112
|
+
|
|
113
|
+
# List configured servers with usage stats
|
|
114
|
+
morph-spec mcp list
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Disable MCP servers not used in current task via `.claude/settings.local.json`.
|
|
118
|
+
|
|
119
|
+
### 6. Checkpoint Summaries Instead of Full History
|
|
120
|
+
|
|
121
|
+
At each checkpoint, generate a compact summary instead of keeping full conversation:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
morph-spec session-summary user-auth
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
This produces a ~500-token summary replacing thousands of tokens of history.
|
|
128
|
+
|
|
129
|
+
### 7. Core Four Dashboard
|
|
130
|
+
|
|
131
|
+
Before starting a session, check the Core Four to identify context wastage:
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
morph-spec core-four user-auth
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Output shows: Context efficiency %, active model, prompt quality score, tool count.
|
|
138
|
+
|
|
139
|
+
**Context efficiency** = (useful tokens) / (total tokens). Target: >70%.
|
|
140
|
+
|
|
141
|
+
### 8. Thread-Based Context Isolation
|
|
142
|
+
|
|
143
|
+
Each parallel thread (P-Thread) gets a clean context window. Instead of one massive session, split into 3 parallel sessions:
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
morph-spec parallel plan user-auth
|
|
147
|
+
# Output: 3 squads × ~20K tokens each = 60K total but 20K per session
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
vs. single session with 60K+ tokens of context.
|
|
151
|
+
|
|
152
|
+
### 9. Artifact Trail
|
|
153
|
+
|
|
154
|
+
Track what was produced to avoid re-reading files:
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
# The artifact-trail.js lib tracks: file path, producer agent, timestamp, token cost
|
|
158
|
+
# Access via:
|
|
159
|
+
morph-spec analytics feature user-auth
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
This shows which files were produced and their approximate token cost.
|
|
163
|
+
|
|
164
|
+
### 10. Output-First Prompting
|
|
165
|
+
|
|
166
|
+
In your prompts to agents, always list expected outputs first:
|
|
167
|
+
|
|
168
|
+
```markdown
|
|
169
|
+
## Your Deliverables (produce these files):
|
|
170
|
+
1. Services/UserService.cs
|
|
171
|
+
2. DTOs/LoginRequest.cs
|
|
172
|
+
|
|
173
|
+
## Then implement following these specs...
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
This front-loads the goal, keeping the model focused and reducing verbose exploration.
|
|
177
|
+
|
|
178
|
+
### 11. Incremental Spec Loading
|
|
179
|
+
|
|
180
|
+
Don't load the full spec at once. Load sections on demand:
|
|
181
|
+
|
|
182
|
+
```markdown
|
|
183
|
+
# Load only the section relevant to current task
|
|
184
|
+
## API Contracts (relevant to T003)
|
|
185
|
+
POST /api/auth/login
|
|
186
|
+
Request: { email, password }
|
|
187
|
+
Response: { token, refreshToken }
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### 12. Session Handoffs
|
|
191
|
+
|
|
192
|
+
When approaching context limit, generate a handoff document:
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
morph-spec generate recap user-auth
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
The recap captures: progress %, tasks completed, decisions made, next steps. Start a new session with just the recap (~1,000 tokens).
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## Context Analytics
|
|
203
|
+
|
|
204
|
+
Monitor context efficiency over time:
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
# Feature-level analytics
|
|
208
|
+
morph-spec analytics context user-auth
|
|
209
|
+
|
|
210
|
+
# Project-level (30-day)
|
|
211
|
+
morph-spec analytics project
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Analytics track:
|
|
215
|
+
- Context efficiency score (0-100%)
|
|
216
|
+
- Token usage by phase
|
|
217
|
+
- Optimization opportunities detected
|
|
218
|
+
|
|
219
|
+
**Optimization triggers** (auto-detected):
|
|
220
|
+
- Efficiency < 60% → Recommend priming
|
|
221
|
+
- Session > 50K tokens → Recommend bundle
|
|
222
|
+
- Standards loaded > 5 → Recommend selective loading
|
|
223
|
+
- MCP servers > 3 active → Recommend MCP hygiene
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
## Context Bundle Format
|
|
228
|
+
|
|
229
|
+
```json
|
|
230
|
+
{
|
|
231
|
+
"id": "bundle-{feature}-{date}",
|
|
232
|
+
"feature": "user-auth",
|
|
233
|
+
"created": "2026-02-19T10:00:00Z",
|
|
234
|
+
"tokenCount": 14800,
|
|
235
|
+
"sections": {
|
|
236
|
+
"specSummary": "...",
|
|
237
|
+
"keyDecisions": ["ADR-001: JWT over sessions", "ADR-002: BCrypt for hashing"],
|
|
238
|
+
"taskProgress": "8/12 completed (67%)",
|
|
239
|
+
"standards": ["coding.md summary", "supabase-auth.md summary"],
|
|
240
|
+
"nextTasks": ["T009", "T010", "T011"]
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
Store bundles at: `.morph/project/bundles/{feature}/`
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
## Quick Reference
|
|
250
|
+
|
|
251
|
+
| Technique | Token Savings | When to Use |
|
|
252
|
+
|-----------|--------------|-------------|
|
|
253
|
+
| Context Priming | ~80% | Always — start of every session |
|
|
254
|
+
| Context Bundles | ~70% | Features with large outputs |
|
|
255
|
+
| Selective Standards | ~50% | Implementation phases |
|
|
256
|
+
| Micro-Agents | ~90% | Narrow, repetitive tasks |
|
|
257
|
+
| MCP Hygiene | ~10-20% | When >3 MCP servers active |
|
|
258
|
+
| Thread Isolation | Resets per thread | Multi-domain features |
|
|
259
|
+
| Session Handoffs | Resets context | Long-running features |
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
## Related
|
|
264
|
+
|
|
265
|
+
- [Thread Management](THREAD-MANAGEMENT.md) — Thread isolation for context efficiency
|
|
266
|
+
- [Meta-Prompts](META-PROMPTS.md) — HOP templates for structured agent prompting
|
|
267
|
+
- [Migration Guide](MIGRATION-GUIDE.md) — Upgrading to v3.0 context features
|
|
@@ -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
|