@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
package/bin/morph-spec.js
CHANGED
|
@@ -60,8 +60,44 @@ import searchPatternsProgram from '../src/commands/learning/search-patterns.js';
|
|
|
60
60
|
// Utility commands
|
|
61
61
|
import troubleshootCommand from '../src/commands/utils/troubleshoot.js';
|
|
62
62
|
import { sessionSummaryCommand } from '../src/commands/utils/session-summary.js';
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
|
|
64
|
+
// Thread, Analytics, Core Four commands
|
|
65
|
+
import {
|
|
66
|
+
threadsListCommand, threadsStatusCommand, threadsKillCommand,
|
|
67
|
+
threadsAnalyticsCommand, threadsWaitAllCommand, threadsWaitAnyCommand
|
|
68
|
+
} from '../src/commands/threads/threads.js';
|
|
69
|
+
import {
|
|
70
|
+
analyticsFeatureCommand, analyticsContextCommand, analyticsProjectCommand
|
|
71
|
+
} from '../src/commands/analytics/analytics.js';
|
|
72
|
+
import { coreFourCommand } from '../src/commands/context/core-four.js';
|
|
73
|
+
|
|
74
|
+
// Context Optimization commands
|
|
75
|
+
import { mcpOptimizeCommand, mcpListCommand } from '../src/commands/mcp/mcp.js';
|
|
76
|
+
import {
|
|
77
|
+
microAgentCreateCommand, microAgentListCommand, microAgentShowCommand
|
|
78
|
+
} from '../src/commands/agents/micro-agent.js';
|
|
79
|
+
import { contextPrimeCommand } from '../src/commands/context/context-prime.js';
|
|
80
|
+
|
|
81
|
+
// Parallelization commands
|
|
82
|
+
import {
|
|
83
|
+
squadTemplateListCommand, squadTemplateUseCommand, squadTemplateShowCommand
|
|
84
|
+
} from '../src/commands/agents/squad-template.js';
|
|
85
|
+
import {
|
|
86
|
+
threadTemplateListCommand, threadTemplateUseCommand
|
|
87
|
+
} from '../src/commands/threads/thread-template.js';
|
|
88
|
+
import { spawnTeamParallelCommand } from '../src/commands/agents/spawn-team.js';
|
|
89
|
+
|
|
90
|
+
// Fusion commands
|
|
91
|
+
import { agentsFuseCommand, agentsReviewAggregateCommand } from '../src/commands/agents/agents-fuse.js';
|
|
92
|
+
|
|
93
|
+
// Meta-Prompts (HOP) commands
|
|
94
|
+
import { hopRenderCommand, hopListCommand } from '../src/commands/templates/template-render.js';
|
|
95
|
+
|
|
96
|
+
// Trust commands
|
|
97
|
+
import {
|
|
98
|
+
trustStatusCommand, trustSetCommand, trustHistoryCommand,
|
|
99
|
+
trustAutoCalculateCommand, trustClearCommand
|
|
100
|
+
} from '../src/commands/trust/trust.js';
|
|
65
101
|
|
|
66
102
|
// Libraries
|
|
67
103
|
import { LearningSystem } from '../src/lib/learning/learning-system.js';
|
|
@@ -105,6 +141,7 @@ program
|
|
|
105
141
|
program
|
|
106
142
|
.command('doctor')
|
|
107
143
|
.description('Check MORPH installation health')
|
|
144
|
+
.option('--v3', 'Run v3.0 specific checks (lib files, HOPs, standards, agents, migration status)')
|
|
108
145
|
.action(doctorCommand);
|
|
109
146
|
|
|
110
147
|
program
|
|
@@ -423,6 +460,53 @@ templateCommand
|
|
|
423
460
|
.option('-v, --verbose', 'Show detailed validation information')
|
|
424
461
|
.action(templateValidateCommand);
|
|
425
462
|
|
|
463
|
+
// HOP (Higher-Order Prompts) commands
|
|
464
|
+
const hopCommand = program
|
|
465
|
+
.command('hop')
|
|
466
|
+
.description('Higher-Order Prompts — render and manage meta-prompt templates');
|
|
467
|
+
|
|
468
|
+
hopCommand
|
|
469
|
+
.command('list')
|
|
470
|
+
.description('List all available HOP templates')
|
|
471
|
+
.action(hopListCommand);
|
|
472
|
+
|
|
473
|
+
hopCommand
|
|
474
|
+
.command('render <hop-id> [output-path]')
|
|
475
|
+
.description('Render a HOP template with variables')
|
|
476
|
+
.option('--variables <json>', 'Variables JSON string', '{}')
|
|
477
|
+
.option('--dry-run', 'Preview without writing file')
|
|
478
|
+
.action((hopId, outputPath, options) => hopRenderCommand(hopId, outputPath, options.variables, options));
|
|
479
|
+
|
|
480
|
+
// Trust commands
|
|
481
|
+
const trustCommand = program
|
|
482
|
+
.command('trust')
|
|
483
|
+
.description('Trust level management for zero-touch execution');
|
|
484
|
+
|
|
485
|
+
trustCommand
|
|
486
|
+
.command('status [feature]')
|
|
487
|
+
.description('Show trust level and auto-approval status')
|
|
488
|
+
.action(trustStatusCommand);
|
|
489
|
+
|
|
490
|
+
trustCommand
|
|
491
|
+
.command('set <feature> <level> [reason]')
|
|
492
|
+
.description('Manually set trust level (low|medium|high|maximum)')
|
|
493
|
+
.action(trustSetCommand);
|
|
494
|
+
|
|
495
|
+
trustCommand
|
|
496
|
+
.command('history')
|
|
497
|
+
.description('Show trust history for all features')
|
|
498
|
+
.action(trustHistoryCommand);
|
|
499
|
+
|
|
500
|
+
trustCommand
|
|
501
|
+
.command('auto-calculate <feature>')
|
|
502
|
+
.description('Recalculate trust from checkpoint history')
|
|
503
|
+
.action(trustAutoCalculateCommand);
|
|
504
|
+
|
|
505
|
+
trustCommand
|
|
506
|
+
.command('clear <feature>')
|
|
507
|
+
.description('Clear manual trust override (revert to calculated)')
|
|
508
|
+
.action(trustClearCommand);
|
|
509
|
+
|
|
426
510
|
// Troubleshooting command
|
|
427
511
|
program
|
|
428
512
|
.command('troubleshoot <keywords...>')
|
|
@@ -467,7 +551,7 @@ program
|
|
|
467
551
|
.option('-v, --verbose', 'Show detailed output')
|
|
468
552
|
.action(rollbackPhaseCommand);
|
|
469
553
|
|
|
470
|
-
// Approval workflow commands
|
|
554
|
+
// Approval workflow commands
|
|
471
555
|
program
|
|
472
556
|
.command('approve <feature> <gate>')
|
|
473
557
|
.description('Approve a phase gate (design, tasks, uiux, proposal)')
|
|
@@ -486,7 +570,7 @@ program
|
|
|
486
570
|
.option('--json', 'Output as JSON')
|
|
487
571
|
.action((feature, options) => approvalStatusCommand(feature, options));
|
|
488
572
|
|
|
489
|
-
// Agent team spawning
|
|
573
|
+
// Agent team spawning
|
|
490
574
|
program
|
|
491
575
|
.command('spawn-team <feature>')
|
|
492
576
|
.description('Generate agent team configuration for Task tool')
|
|
@@ -494,13 +578,204 @@ program
|
|
|
494
578
|
.option('--verbose', 'Show detailed team configuration')
|
|
495
579
|
.action((feature, options) => spawnTeamCommand(feature, options));
|
|
496
580
|
|
|
497
|
-
// Pattern learning system
|
|
581
|
+
// Pattern learning system - Add as subcommands
|
|
498
582
|
program.addCommand(capturePatternProgram);
|
|
499
583
|
program.addCommand(searchPatternsProgram);
|
|
500
584
|
|
|
501
|
-
//
|
|
502
|
-
|
|
503
|
-
|
|
585
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
586
|
+
// Thread Management
|
|
587
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
588
|
+
const threadsCommand = program
|
|
589
|
+
.command('threads')
|
|
590
|
+
.description('Thread lifecycle management');
|
|
591
|
+
|
|
592
|
+
threadsCommand
|
|
593
|
+
.command('list')
|
|
594
|
+
.description('List threads (optionally filtered by feature/status/type)')
|
|
595
|
+
.option('--feature <feature>', 'Filter by feature name')
|
|
596
|
+
.option('--status <status>', 'Filter by status (pending|running|completed|failed|killed)')
|
|
597
|
+
.option('--type <type>', 'Filter by type (base|parallel|fusion|long-running|zero-touch)')
|
|
598
|
+
.action((options) => threadsListCommand(options));
|
|
599
|
+
|
|
600
|
+
threadsCommand
|
|
601
|
+
.command('status <id>')
|
|
602
|
+
.description('Show detailed status of a thread')
|
|
603
|
+
.action((id) => threadsStatusCommand(id));
|
|
604
|
+
|
|
605
|
+
threadsCommand
|
|
606
|
+
.command('kill <id>')
|
|
607
|
+
.description('Terminate a running thread')
|
|
608
|
+
.action((id) => threadsKillCommand(id));
|
|
609
|
+
|
|
610
|
+
threadsCommand
|
|
611
|
+
.command('analytics')
|
|
612
|
+
.description('Show thread analytics dashboard for a feature')
|
|
613
|
+
.option('--feature <feature>', 'Feature name (required)')
|
|
614
|
+
.action((options) => threadsAnalyticsCommand(options));
|
|
615
|
+
|
|
616
|
+
threadsCommand
|
|
617
|
+
.command('wait-all <feature>')
|
|
618
|
+
.description('Block until all threads for a feature complete')
|
|
619
|
+
.option('--timeout <minutes>', 'Timeout in minutes (default: 60)', '60')
|
|
620
|
+
.action((feature, options) => threadsWaitAllCommand(feature, options));
|
|
621
|
+
|
|
622
|
+
threadsCommand
|
|
623
|
+
.command('wait-any <feature>')
|
|
624
|
+
.description('Block until any thread for a feature completes')
|
|
625
|
+
.option('--timeout <minutes>', 'Timeout in minutes (default: 60)', '60')
|
|
626
|
+
.action((feature, options) => threadsWaitAnyCommand(feature, options));
|
|
627
|
+
|
|
628
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
629
|
+
// Analytics
|
|
630
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
631
|
+
const analyticsCommand = program
|
|
632
|
+
.command('analytics')
|
|
633
|
+
.description('Metrics and analytics dashboards');
|
|
634
|
+
|
|
635
|
+
analyticsCommand
|
|
636
|
+
.command('feature <name>')
|
|
637
|
+
.description('Show thread analytics dashboard for a feature')
|
|
638
|
+
.action((name, options) => analyticsFeatureCommand(name, options));
|
|
639
|
+
|
|
640
|
+
analyticsCommand
|
|
641
|
+
.command('context <name>')
|
|
642
|
+
.description('Show context token usage and optimization opportunities')
|
|
643
|
+
.action((name, options) => analyticsContextCommand(name, options));
|
|
644
|
+
|
|
645
|
+
analyticsCommand
|
|
646
|
+
.command('project')
|
|
647
|
+
.description('Show project-wide analytics dashboard (30-day summary)')
|
|
648
|
+
.option('--period <days>', 'Period in days (default: 30)', '30')
|
|
649
|
+
.action((options) => analyticsProjectCommand(options));
|
|
650
|
+
|
|
651
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
652
|
+
// Core Four
|
|
653
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
654
|
+
program
|
|
655
|
+
.command('core-four <feature>')
|
|
656
|
+
.description('Show Core Four dashboard: Context/Model/Prompt/Tools')
|
|
657
|
+
.option('--json', 'Output as JSON')
|
|
658
|
+
.action((feature, options) => coreFourCommand(feature, options));
|
|
659
|
+
|
|
660
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
661
|
+
// MCP Optimizer
|
|
662
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
663
|
+
const mcpCommand = program
|
|
664
|
+
.command('mcp')
|
|
665
|
+
.description('MCP server analysis and optimization');
|
|
666
|
+
|
|
667
|
+
mcpCommand
|
|
668
|
+
.command('optimize')
|
|
669
|
+
.description('Analyze MCP servers and suggest optimizations')
|
|
670
|
+
.action((options) => mcpOptimizeCommand(options));
|
|
671
|
+
|
|
672
|
+
mcpCommand
|
|
673
|
+
.command('list')
|
|
674
|
+
.description('List configured MCP servers with usage stats')
|
|
675
|
+
.action((options) => mcpListCommand(options));
|
|
676
|
+
|
|
677
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
678
|
+
// Micro Agents
|
|
679
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
680
|
+
const microAgentCommand = program
|
|
681
|
+
.command('micro-agent')
|
|
682
|
+
.description('Create and manage ultra-specialized micro-agents');
|
|
683
|
+
|
|
684
|
+
microAgentCommand
|
|
685
|
+
.command('create <name>')
|
|
686
|
+
.description('Create a new micro-agent')
|
|
687
|
+
.option('--base-agent <agent>', 'Base agent ID to specialize from')
|
|
688
|
+
.option('--mission <mission>', 'Single focused mission for this agent')
|
|
689
|
+
.option('--standards <files>', 'Comma-separated standards files to load (1-3 max)')
|
|
690
|
+
.option('--tools <tools>', 'Comma-separated tools to allow (default: Read,Write,Edit)')
|
|
691
|
+
.action((name, options) => microAgentCreateCommand(name, options));
|
|
692
|
+
|
|
693
|
+
microAgentCommand
|
|
694
|
+
.command('list')
|
|
695
|
+
.description('List all micro-agents')
|
|
696
|
+
.action((options) => microAgentListCommand(options));
|
|
697
|
+
|
|
698
|
+
microAgentCommand
|
|
699
|
+
.command('show <name>')
|
|
700
|
+
.description('Show micro-agent details')
|
|
701
|
+
.option('--show-prompt', 'Show the generated system prompt')
|
|
702
|
+
.action((name, options) => microAgentShowCommand(name, options));
|
|
703
|
+
|
|
704
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
705
|
+
// Context Prime
|
|
706
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
707
|
+
program
|
|
708
|
+
.command('prime [type]')
|
|
709
|
+
.description('Output context priming file (feature|bug|refactor|design|infra)')
|
|
710
|
+
.option('--json', 'Output as JSON')
|
|
711
|
+
.action((type, options) => contextPrimeCommand(type, options));
|
|
712
|
+
|
|
713
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
714
|
+
// Fusion (F-Thread)
|
|
715
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
716
|
+
const agentsFuseCmd = program
|
|
717
|
+
.command('agents-fuse')
|
|
718
|
+
.description('F-Thread fusion execution: run N agents, aggregate best result');
|
|
719
|
+
|
|
720
|
+
agentsFuseCmd
|
|
721
|
+
.command('run')
|
|
722
|
+
.description('Run fusion: spawn N agents with same prompt, aggregate results')
|
|
723
|
+
.option('--prompt <prompt>', 'Prompt/mission for all fusion agents (required)')
|
|
724
|
+
.option('--count <n>', 'Number of agents to run (default: 3)', '3')
|
|
725
|
+
.option('--strategy <strategy>', 'Aggregation strategy: best-of-n | consensus | manual-select', 'best-of-n')
|
|
726
|
+
.option('--feature <feature>', 'Feature name for tracking')
|
|
727
|
+
.option('--agents <list>', 'Comma-separated agent IDs to use')
|
|
728
|
+
.option('--json', 'Output as JSON')
|
|
729
|
+
.action((options) => agentsFuseCommand(options));
|
|
730
|
+
|
|
731
|
+
agentsFuseCmd
|
|
732
|
+
.command('aggregate-reviews <feature>')
|
|
733
|
+
.description('Aggregate review results from N agents')
|
|
734
|
+
.option('--agents <list>', 'Comma-separated agent IDs (required)')
|
|
735
|
+
.option('--strategy <strategy>', 'Aggregation strategy', 'best-of-n')
|
|
736
|
+
.action((feature, options) => agentsReviewAggregateCommand(feature, options));
|
|
737
|
+
|
|
738
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
739
|
+
// Squad Templates
|
|
740
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
741
|
+
const squadTemplateCmd = program
|
|
742
|
+
.command('squad-template')
|
|
743
|
+
.description('Squad template management for parallel execution');
|
|
744
|
+
|
|
745
|
+
squadTemplateCmd
|
|
746
|
+
.command('list')
|
|
747
|
+
.description('List available squad templates')
|
|
748
|
+
.action((options) => squadTemplateListCommand(options));
|
|
749
|
+
|
|
750
|
+
squadTemplateCmd
|
|
751
|
+
.command('use <template-id>')
|
|
752
|
+
.description('Configure a feature to use a squad template')
|
|
753
|
+
.option('--feature <feature>', 'Feature name (required)')
|
|
754
|
+
.action((id, options) => squadTemplateUseCommand(id, options));
|
|
755
|
+
|
|
756
|
+
squadTemplateCmd
|
|
757
|
+
.command('show <template-id>')
|
|
758
|
+
.description('Show squad template details')
|
|
759
|
+
.option('--json', 'Output as JSON')
|
|
760
|
+
.action((id, options) => squadTemplateShowCommand(id, options));
|
|
761
|
+
|
|
762
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
763
|
+
// Commands — Thread Templates
|
|
764
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
765
|
+
const threadTemplateCmd = program
|
|
766
|
+
.command('thread-template')
|
|
767
|
+
.description('Thread type management');
|
|
768
|
+
|
|
769
|
+
threadTemplateCmd
|
|
770
|
+
.command('list')
|
|
771
|
+
.description('List available thread types (B/P/F/L/Z-Thread)')
|
|
772
|
+
.action((options) => threadTemplateListCommand(options));
|
|
773
|
+
|
|
774
|
+
threadTemplateCmd
|
|
775
|
+
.command('use <type>')
|
|
776
|
+
.description('Configure thread type for a feature')
|
|
777
|
+
.option('--feature <feature>', 'Feature name (required)')
|
|
778
|
+
.action((type, options) => threadTemplateUseCommand(type, options));
|
|
504
779
|
|
|
505
780
|
// Wire global --stack flag to stack-resolver before any command executes
|
|
506
781
|
program.hook('preAction', () => {
|
package/bin/validate.js
CHANGED
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
import chalk from 'chalk';
|
|
20
|
-
import { validatePackages } from '../src/lib/validators/package-validator.js';
|
|
21
|
-
import { validateArchitecture } from '../src/lib/validators/architecture-validator.js';
|
|
22
|
-
import { validateContrast } from '../src/lib/validators/ui-contrast-validator.js';
|
|
20
|
+
import { validatePackages } from '../src/lib/validators/packages/package-validator.js';
|
|
21
|
+
import { validateArchitecture } from '../src/lib/validators/architecture/architecture-validator.js';
|
|
22
|
+
import { validateContrast } from '../src/lib/validators/ui/ui-contrast-validator.js';
|
|
23
23
|
import { LearningSystem } from '../src/lib/learning/learning-system.js';
|
|
24
24
|
|
|
25
25
|
const VALIDATORS = {
|
|
@@ -51,7 +51,7 @@ const VALIDATORS = {
|
|
|
51
51
|
async function validateSpecVsTasks(projectPath, options = {}) {
|
|
52
52
|
const path = await import('path');
|
|
53
53
|
const fs = await import('fs');
|
|
54
|
-
const { loadState } = await import('../src/
|
|
54
|
+
const { loadState } = await import('../src/core/state/state-manager.js');
|
|
55
55
|
|
|
56
56
|
const results = [];
|
|
57
57
|
let errors = 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
|