@polymorphism-tech/morph-spec 4.9.0 → 4.10.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/README.md +2 -2
- package/bin/morph-spec.js +30 -0
- package/bin/task-manager.js +34 -22
- package/claude-plugin.json +1 -1
- package/docs/CHEATSHEET.md +1 -1
- package/docs/QUICKSTART.md +1 -1
- package/framework/CLAUDE.md +35 -98
- package/framework/agents/backend/api-designer.md +3 -0
- package/framework/agents/backend/dotnet-senior.md +3 -0
- package/framework/agents/backend/ef-modeler.md +2 -0
- package/framework/agents/backend/hangfire-orchestrator.md +2 -0
- package/framework/agents/backend/ms-agent-expert.md +2 -0
- package/framework/agents/frontend/blazor-builder.md +2 -0
- package/framework/agents/frontend/nextjs-expert.md +2 -0
- package/framework/agents/infrastructure/azure-architect.md +2 -0
- package/framework/agents/infrastructure/azure-deploy-specialist.md +2 -0
- package/framework/agents/infrastructure/bicep-architect.md +2 -0
- package/framework/agents/infrastructure/container-specialist.md +2 -0
- package/framework/agents/infrastructure/devops-engineer.md +3 -0
- package/framework/agents/infrastructure/infra-architect.md +3 -0
- package/framework/agents/integrations/asaas-financial.md +2 -0
- package/framework/agents/integrations/azure-identity.md +2 -0
- package/framework/agents/integrations/clerk-auth.md +3 -0
- package/framework/agents/integrations/hangfire-integration.md +2 -0
- package/framework/agents/integrations/resend-email.md +2 -0
- package/framework/agents.json +37 -7
- package/framework/commands/commit.md +166 -0
- package/framework/commands/morph-apply.md +156 -155
- package/framework/commands/morph-archive.md +33 -27
- package/framework/commands/morph-infra.md +83 -77
- package/framework/commands/morph-preflight.md +97 -55
- package/framework/commands/morph-proposal.md +131 -58
- package/framework/commands/morph-status.md +36 -30
- package/framework/commands/morph-troubleshoot.md +68 -59
- package/framework/hooks/claude-code/notification/approval-reminder.js +3 -2
- package/framework/hooks/claude-code/post-tool-use/dispatch.js +154 -31
- package/framework/hooks/claude-code/post-tool-use/skill-reminder.js +7 -84
- package/framework/hooks/claude-code/post-tool-use/validator-feedback.js +8 -17
- package/framework/hooks/claude-code/pre-compact/save-morph-context.js +16 -3
- package/framework/hooks/claude-code/pre-tool-use/enforce-phase-writes.js +4 -3
- package/framework/hooks/claude-code/pre-tool-use/protect-spec-files.js +3 -2
- package/framework/hooks/claude-code/pre-tool-use/task-tracking-guard.js +60 -0
- package/framework/hooks/claude-code/session-start/inject-morph-context.js +55 -2
- package/framework/hooks/claude-code/session-start/post-compact-restore.js +41 -0
- package/framework/hooks/claude-code/stop/validate-completion.js +2 -15
- package/framework/hooks/claude-code/user-prompt/enrich-prompt.js +23 -5
- package/framework/hooks/shared/compact-restore.js +100 -0
- package/framework/hooks/shared/dispatch-helpers.js +116 -0
- package/framework/hooks/shared/phase-utils.js +9 -5
- package/framework/hooks/shared/state-reader.js +27 -3
- package/framework/phases.json +30 -7
- package/framework/rules/csharp-standards.md +3 -0
- package/framework/rules/frontend-standards.md +2 -0
- package/framework/rules/infrastructure-standards.md +3 -0
- package/framework/rules/morph-workflow.md +143 -86
- package/framework/rules/nextjs-standards.md +2 -0
- package/framework/rules/testing-standards.md +3 -0
- package/framework/skills/level-0-meta/mcp-registry.json +86 -51
- package/framework/skills/level-0-meta/morph-brainstorming/SKILL.md +139 -0
- package/framework/skills/level-0-meta/morph-checklist/SKILL.md +42 -19
- package/framework/skills/level-0-meta/{code-review → morph-code-review}/SKILL.md +8 -5
- package/framework/skills/level-0-meta/{code-review-nextjs → morph-code-review-nextjs}/SKILL.md +8 -6
- package/framework/skills/level-0-meta/morph-frontend-review/SKILL.md +362 -0
- package/framework/skills/level-0-meta/morph-init/SKILL.md +114 -20
- package/framework/skills/level-0-meta/morph-post-implementation/SKILL.md +362 -0
- package/framework/skills/level-0-meta/morph-replicate/SKILL.md +95 -87
- package/framework/skills/level-0-meta/{simulation-checklist → morph-simulation-checklist}/SKILL.md +24 -0
- package/framework/skills/level-0-meta/{tool-usage-guide → morph-tool-usage-guide}/SKILL.md +43 -43
- package/framework/skills/level-0-meta/{tool-usage-guide → morph-tool-usage-guide}/references/tools-per-phase.md +1 -2
- package/framework/skills/level-0-meta/{verification-before-completion → morph-verification-before-completion}/SKILL.md +23 -12
- package/framework/skills/level-0-meta/{verification-before-completion → morph-verification-before-completion}/scripts/check-phase-outputs.mjs +2 -2
- package/framework/skills/level-1-workflows/morph-phase-clarify/SKILL.md +247 -0
- package/framework/skills/level-1-workflows/morph-phase-codebase-analysis/SKILL.md +270 -0
- package/framework/skills/level-1-workflows/morph-phase-design/SKILL.md +499 -0
- package/framework/skills/level-1-workflows/morph-phase-implement/.morph/logs/activity.json +38 -0
- package/framework/skills/level-1-workflows/morph-phase-implement/SKILL.md +472 -0
- package/framework/skills/level-1-workflows/morph-phase-implement/prompts/code-quality-reviewer-prompt.md +50 -0
- package/framework/skills/level-1-workflows/morph-phase-implement/prompts/implementer-prompt.md +45 -0
- package/framework/skills/level-1-workflows/morph-phase-implement/prompts/spec-reviewer-prompt.md +47 -0
- package/framework/skills/level-1-workflows/morph-phase-plan/SKILL.md +246 -0
- package/framework/skills/level-1-workflows/morph-phase-setup/SKILL.md +238 -0
- package/framework/skills/level-1-workflows/morph-phase-tasks/.morph/logs/activity.json +14 -0
- package/framework/skills/level-1-workflows/morph-phase-tasks/SKILL.md +312 -0
- package/framework/skills/level-1-workflows/{phase-tasks → morph-phase-tasks}/scripts/validate-tasks.mjs +3 -3
- package/framework/skills/level-1-workflows/morph-phase-uiux/SKILL.md +324 -0
- package/framework/skills/level-1-workflows/morph-scope-escalation/SKILL.md +146 -0
- package/framework/standards/integration/mcp/mcp-tools.md +25 -7
- package/framework/templates/docs/onboarding.md +2 -2
- package/package.json +3 -4
- package/src/commands/agents/dispatch-agents.js +50 -3
- package/src/commands/mcp/mcp-setup.js +39 -2
- package/src/commands/phase/phase-reset.js +74 -0
- package/src/commands/project/doctor.js +26 -7
- package/src/commands/project/update.js +4 -4
- package/src/commands/scope/escalate.js +215 -0
- package/src/commands/state/advance-phase.js +27 -53
- package/src/commands/state/state.js +1 -1
- package/src/commands/task/expand.js +100 -0
- package/src/core/paths/output-schema.js +4 -3
- package/src/core/state/phase-state-machine.js +7 -4
- package/src/core/state/state-manager.js +4 -3
- package/src/lib/detectors/claude-config-detector.js +93 -347
- package/src/lib/detectors/design-system-detector.js +189 -189
- package/src/lib/detectors/index.js +155 -57
- package/src/lib/generators/context-generator.js +2 -2
- package/src/lib/installers/mcp-installer.js +37 -5
- package/src/lib/phase-chain/phase-validator.js +22 -16
- package/src/lib/scope/impact-analyzer.js +106 -0
- package/src/lib/stack-filter.js +58 -0
- package/src/lib/tasks/task-parser.js +1 -1
- package/src/lib/validators/shared/emit-validator-dispatch.js +64 -0
- package/src/scripts/setup-infra.js +68 -18
- package/src/utils/agents-installer.js +51 -17
- package/src/utils/claude-md-injector.js +90 -0
- package/src/utils/file-copier.js +0 -1
- package/src/utils/hooks-installer.js +16 -5
- package/src/utils/skills-installer.js +67 -7
- package/CLAUDE.md +0 -98
- package/framework/memory/patterns-learned.md +0 -766
- package/framework/skills/level-0-meta/brainstorming/SKILL.md +0 -137
- package/framework/skills/level-0-meta/frontend-review/SKILL.md +0 -359
- package/framework/skills/level-0-meta/post-implementation/SKILL.md +0 -362
- package/framework/skills/level-0-meta/terminal-title/SKILL.md +0 -61
- package/framework/skills/level-0-meta/terminal-title/scripts/set_title.sh +0 -65
- package/framework/skills/level-1-workflows/phase-clarify/SKILL.md +0 -216
- package/framework/skills/level-1-workflows/phase-codebase-analysis/SKILL.md +0 -252
- package/framework/skills/level-1-workflows/phase-design/SKILL.md +0 -383
- package/framework/skills/level-1-workflows/phase-implement/SKILL.md +0 -492
- package/framework/skills/level-1-workflows/phase-setup/SKILL.md +0 -195
- package/framework/skills/level-1-workflows/phase-tasks/SKILL.md +0 -271
- package/framework/skills/level-1-workflows/phase-uiux/SKILL.md +0 -286
- package/src/commands/project/index.js +0 -8
- package/src/core/index.js +0 -10
- package/src/core/state/index.js +0 -8
- package/src/core/templates/index.js +0 -9
- package/src/core/templates/template-data-sources.js +0 -325
- package/src/core/workflows/index.js +0 -7
- package/src/lib/detectors/config-detector.js +0 -223
- package/src/lib/detectors/standards-generator.js +0 -335
- package/src/lib/detectors/structure-detector.js +0 -275
- package/src/lib/monitor/agent-resolver.js +0 -144
- package/src/lib/monitor/renderer.js +0 -230
- package/src/lib/orchestration/index.js +0 -7
- package/src/lib/orchestration/team-orchestrator.js +0 -404
- package/src/sanitizer/context-sanitizer.js +0 -221
- package/src/sanitizer/patterns.js +0 -163
- package/src/writer/file-writer.js +0 -86
- /package/framework/skills/level-0-meta/{brainstorming → morph-brainstorming}/references/proposal-example.md +0 -0
- /package/framework/skills/level-0-meta/{code-review → morph-code-review}/references/review-example.md +0 -0
- /package/framework/skills/level-0-meta/{code-review → morph-code-review}/references/review-guidelines.md +0 -0
- /package/framework/skills/level-0-meta/{code-review → morph-code-review}/scripts/scan-csharp.mjs +0 -0
- /package/framework/skills/level-0-meta/{code-review-nextjs → morph-code-review-nextjs}/references/review-example-nextjs.md +0 -0
- /package/framework/skills/level-0-meta/{code-review-nextjs → morph-code-review-nextjs}/scripts/scan-nextjs.mjs +0 -0
- /package/framework/skills/level-0-meta/{frontend-review → morph-frontend-review}/scripts/scan-accessibility.mjs +0 -0
- /package/framework/skills/level-0-meta/{post-implementation → morph-post-implementation}/scripts/detect-dev-server.mjs +0 -0
- /package/framework/skills/level-0-meta/{post-implementation → morph-post-implementation}/scripts/detect-stack.mjs +0 -0
- /package/framework/skills/level-1-workflows/{phase-clarify → morph-phase-clarify}/references/clarifications-example.md +0 -0
- /package/framework/skills/level-1-workflows/{phase-design → morph-phase-design}/references/architecture-analysis-guide.md +0 -0
- /package/framework/skills/level-1-workflows/{phase-design → morph-phase-design}/references/spec-authoring-guide.md +0 -0
- /package/framework/skills/level-1-workflows/{phase-design → morph-phase-design}/references/spec-example.md +0 -0
- /package/framework/skills/level-1-workflows/{phase-implement → morph-phase-implement}/references/recap-example.md +0 -0
- /package/framework/skills/level-1-workflows/{phase-implement → morph-phase-implement}/references/vsa-implementation-guide.md +0 -0
- /package/framework/skills/level-1-workflows/{phase-tasks → morph-phase-tasks}/references/task-planning-patterns.md +0 -0
- /package/framework/skills/level-1-workflows/{phase-tasks → morph-phase-tasks}/references/tasks-example.md +0 -0
|
@@ -1,404 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Hierarchical Agent Teams Orchestrator
|
|
3
|
-
*
|
|
4
|
-
* Builds Agent Teams using flattened 2-tier hierarchy:
|
|
5
|
-
* - Lead: standards-architect (in delegate mode, quality gate)
|
|
6
|
-
* - Teammates: Tier-2 domain leaders (each with specialists in their spawn prompt)
|
|
7
|
-
*
|
|
8
|
-
* NOTE: Agent Teams does NOT support nested teams (a teammate cannot spawn
|
|
9
|
-
* teammates). Therefore Tier-3 specialists are described in domain leader
|
|
10
|
-
* spawn prompts, not as separate teammates.
|
|
11
|
-
*
|
|
12
|
-
* @module team-orchestrator
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
import fs from 'fs/promises';
|
|
16
|
-
import path from 'path';
|
|
17
|
-
import { fileURLToPath } from 'url';
|
|
18
|
-
|
|
19
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
20
|
-
const __dirname = path.dirname(__filename);
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Load agents.json with hierarchical structure
|
|
24
|
-
* @param {string} projectPath - Root path of the project
|
|
25
|
-
* @returns {Promise<Object>} Parsed agents configuration
|
|
26
|
-
*/
|
|
27
|
-
async function loadAgentsConfig(projectPath) {
|
|
28
|
-
const agentsPath = path.join(projectPath, '.morph/framework/agents.json');
|
|
29
|
-
const content = await fs.readFile(agentsPath, 'utf8');
|
|
30
|
-
return JSON.parse(content);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Detect whether Agent Teams, subagents, or a single session should be used.
|
|
35
|
-
*
|
|
36
|
-
* Returns one of three modes:
|
|
37
|
-
* - 'agent-teams': complexity=critical OR (multiDomain AND estimatedFiles>=15)
|
|
38
|
-
* - 'subagents': shouldDispatch=true but below agent-teams threshold
|
|
39
|
-
* - 'single': trivial/low complexity or no parallelization benefit
|
|
40
|
-
*
|
|
41
|
-
* @param {Object} options
|
|
42
|
-
* @param {string[]} options.activeAgents - Agent IDs detected for feature
|
|
43
|
-
* @param {string} options.complexity - Complexity level (trivial|low|medium|high|critical)
|
|
44
|
-
* @param {number} options.estimatedFiles - Estimated files to modify
|
|
45
|
-
* @param {boolean} options.multiDomain - Does feature span multiple domains?
|
|
46
|
-
* @returns {{ mode: 'single'|'subagents'|'agent-teams', reason: string }}
|
|
47
|
-
*/
|
|
48
|
-
export function shouldSpawnAgentTeam(options) {
|
|
49
|
-
const { activeAgents = [], complexity, estimatedFiles = 0, multiDomain = false } = options;
|
|
50
|
-
|
|
51
|
-
// Never parallelize for trivial/low complexity
|
|
52
|
-
if (complexity === 'trivial' || complexity === 'low') {
|
|
53
|
-
return {
|
|
54
|
-
mode: 'single',
|
|
55
|
-
reason: 'Complexity too low — single session sufficient',
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Agent Teams for critical complexity (max parallelization needed)
|
|
60
|
-
if (complexity === 'critical') {
|
|
61
|
-
return {
|
|
62
|
-
mode: 'agent-teams',
|
|
63
|
-
reason: 'Critical complexity — Agent Teams with plan approval essential',
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Agent Teams for large multi-domain features (backend + frontend need contract coordination)
|
|
68
|
-
if (multiDomain && estimatedFiles >= 15) {
|
|
69
|
-
return {
|
|
70
|
-
mode: 'agent-teams',
|
|
71
|
-
reason: `Multi-domain feature with ${estimatedFiles}+ files — Agent Teams for contract coordination`,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Subagents for multi-domain below agent-teams threshold
|
|
76
|
-
if (multiDomain) {
|
|
77
|
-
return {
|
|
78
|
-
mode: 'subagents',
|
|
79
|
-
reason: 'Multi-domain feature — parallel subagents recommended',
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Subagents for high file count
|
|
84
|
-
if (estimatedFiles >= 15) {
|
|
85
|
-
return {
|
|
86
|
-
mode: 'subagents',
|
|
87
|
-
reason: `High file count (${estimatedFiles}) — parallel subagents recommended`,
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// Subagents when 5+ specialists are active
|
|
92
|
-
if (activeAgents.length >= 5) {
|
|
93
|
-
return {
|
|
94
|
-
mode: 'subagents',
|
|
95
|
-
reason: `${activeAgents.length} specialists active — subagents beneficial`,
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// Default: single session for medium complexity
|
|
100
|
-
return {
|
|
101
|
-
mode: 'single',
|
|
102
|
-
reason: 'Medium complexity — single session with subagents OK',
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Build hierarchical team structure from active agents.
|
|
108
|
-
* Flattened to 2 tiers for Agent Teams compatibility:
|
|
109
|
-
* - Lead: standards-architect
|
|
110
|
-
* - Teammates: Tier-2 domain leaders (specialists are in their spawn prompts)
|
|
111
|
-
*
|
|
112
|
-
* @param {string[]} activeAgentIds - Agent IDs to include in team
|
|
113
|
-
* @param {Object} agentsConfig - Loaded agents.json
|
|
114
|
-
* @returns {Object} Team structure with lead, domain leaders, specialists, validators
|
|
115
|
-
*/
|
|
116
|
-
export function buildTeamHierarchy(activeAgentIds, agentsConfig) {
|
|
117
|
-
const agents = agentsConfig.agents;
|
|
118
|
-
const activeAgents = activeAgentIds
|
|
119
|
-
.filter(id => !id.startsWith('_comment') && agents[id])
|
|
120
|
-
.map(id => ({ id, ...agents[id] }));
|
|
121
|
-
|
|
122
|
-
// Tier 1: Orchestrator (Team Lead)
|
|
123
|
-
const orchestrators = activeAgents.filter(a => a.tier === 1 && a.role === 'orchestrator');
|
|
124
|
-
const teamLead = orchestrators.find(a => a.id === 'standards-architect') || orchestrators[0];
|
|
125
|
-
|
|
126
|
-
// Tier 2: Domain Leaders (direct teammates in Agent Teams)
|
|
127
|
-
const domainLeaders = activeAgents.filter(a => a.tier === 2 && a.role === 'domain-leader');
|
|
128
|
-
|
|
129
|
-
// Tier 3: Specialists (grouped under domain leaders, NOT separate teammates)
|
|
130
|
-
const specialists = activeAgents.filter(a => a.tier === 3 && a.role === 'specialist');
|
|
131
|
-
|
|
132
|
-
// Tier 4: Validators (run in hooks, NOT teammates)
|
|
133
|
-
const validators = activeAgents.filter(a => a.tier === 4 && a.role === 'validator');
|
|
134
|
-
|
|
135
|
-
// Group specialists under their Domain Leaders for spawn prompt inclusion
|
|
136
|
-
const squads = {};
|
|
137
|
-
domainLeaders.forEach(leader => {
|
|
138
|
-
const squadMembers = specialists.filter(specialist => {
|
|
139
|
-
return specialist.relationships?.reports_to === leader.id;
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
squads[leader.id] = {
|
|
143
|
-
leader,
|
|
144
|
-
members: squadMembers,
|
|
145
|
-
};
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
return {
|
|
149
|
-
teamLead,
|
|
150
|
-
squads,
|
|
151
|
-
validators, // Run as hooks, not teammates
|
|
152
|
-
// Teammates = lead + domain leaders only (not tier-3 specialists)
|
|
153
|
-
totalTeammates: 1 + domainLeaders.length,
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Generate natural-language Agent Team creation prompt.
|
|
159
|
-
*
|
|
160
|
-
* Returns a string ready to be sent to Claude as instructions to create
|
|
161
|
-
* an agent team. Domain leaders are teammates; their tier-3 specialists
|
|
162
|
-
* are described within each leader's spawn context.
|
|
163
|
-
*
|
|
164
|
-
* @param {Object} teamHierarchy - Output from buildTeamHierarchy
|
|
165
|
-
* @param {string} featureName - Feature name
|
|
166
|
-
* @param {string} phase - Current MORPH phase
|
|
167
|
-
* @returns {string} Natural language team creation instructions
|
|
168
|
-
*/
|
|
169
|
-
export function generateAgentTeamPrompt(teamHierarchy, featureName, phase) {
|
|
170
|
-
const { teamLead, squads } = teamHierarchy;
|
|
171
|
-
const squadEntries = Object.entries(squads);
|
|
172
|
-
|
|
173
|
-
if (squadEntries.length === 0) {
|
|
174
|
-
return `No multi-domain squad found for feature '${featureName}'. Use single session or subagents instead.`;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
const teammateCount = squadEntries.length + 1; // domain leaders + quality lead
|
|
178
|
-
const lines = [
|
|
179
|
-
`Create an agent team to implement feature '${featureName}' with ${teammateCount} teammates:`,
|
|
180
|
-
'',
|
|
181
|
-
];
|
|
182
|
-
|
|
183
|
-
for (const [leaderId, squad] of squadEntries) {
|
|
184
|
-
const leader = squad.leader;
|
|
185
|
-
const domain = leader.domains?.[0] || leaderId;
|
|
186
|
-
const specialistList = squad.members.length > 0
|
|
187
|
-
? squad.members.map(m => m.title || m.id).join(', ')
|
|
188
|
-
: 'none';
|
|
189
|
-
|
|
190
|
-
lines.push(`- ${leader.title || leaderId} teammate (${leaderId}): Implement ${domain} tasks.`);
|
|
191
|
-
lines.push(` Context: spec.md, contracts.cs, standards/${domain}/`);
|
|
192
|
-
if (squad.members.length > 0) {
|
|
193
|
-
lines.push(` Specialists to coordinate (in your spawn prompt): ${specialistList}`);
|
|
194
|
-
}
|
|
195
|
-
lines.push(` Restriction: Modify ONLY files in the ${domain} domain.`);
|
|
196
|
-
lines.push('');
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
const leadId = teamLead?.id || 'standards-architect';
|
|
200
|
-
lines.push(`- Quality teammate (${leadId}): Review each teammate's output and run validate-feature.`);
|
|
201
|
-
lines.push(' Require plan approval before implementing. Only approve plans that match contracts.cs.');
|
|
202
|
-
lines.push('');
|
|
203
|
-
lines.push('Coordination protocol:');
|
|
204
|
-
lines.push(' - Backend must signal when contracts.cs/DTOs are stable before frontend implements API calls.');
|
|
205
|
-
lines.push(' - If teammates need to share interfaces, send a direct message to coordinate first.');
|
|
206
|
-
lines.push(' - Escalate contract conflicts to the quality teammate to resolve.');
|
|
207
|
-
|
|
208
|
-
return lines.join('\n');
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Generate team instructions as natural language (renamed from generateSpawnCommand).
|
|
213
|
-
* Use this for Agent Teams mode.
|
|
214
|
-
*
|
|
215
|
-
* @param {Object} teamHierarchy - Output from buildTeamHierarchy
|
|
216
|
-
* @param {string} featureName - Feature name
|
|
217
|
-
* @param {string} phase - Current MORPH phase
|
|
218
|
-
* @returns {string} Natural language team creation instructions
|
|
219
|
-
*/
|
|
220
|
-
export function generateTeamInstructions(teamHierarchy, featureName, phase) {
|
|
221
|
-
return generateAgentTeamPrompt(teamHierarchy, featureName, phase);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* Generate teammate spawn configs for subagent dispatch (unchanged from v1).
|
|
226
|
-
* Use this for 'subagents' mode (not Agent Teams).
|
|
227
|
-
*
|
|
228
|
-
* @param {Object} teamHierarchy - Output from buildTeamHierarchy
|
|
229
|
-
* @param {string} featureName - Feature name
|
|
230
|
-
* @param {string} phase - Current MORPH phase
|
|
231
|
-
* @returns {Object[]} Array of teammate configs for Task tool subagents
|
|
232
|
-
*/
|
|
233
|
-
export function generateTeammateConfigs(teamHierarchy, featureName, phase) {
|
|
234
|
-
const teammates = [];
|
|
235
|
-
const { teamLead, squads } = teamHierarchy;
|
|
236
|
-
|
|
237
|
-
// Add Team Lead (standards-architect in delegate mode)
|
|
238
|
-
if (teamLead && teamLead.teammate) {
|
|
239
|
-
teammates.push({
|
|
240
|
-
id: teamLead.id,
|
|
241
|
-
tier: teamLead.tier,
|
|
242
|
-
role: teamLead.teammate.role,
|
|
243
|
-
icon: teamLead.teammate.icon,
|
|
244
|
-
spawnPrompt: `${teamLead.teammate.spawn_prompt}
|
|
245
|
-
|
|
246
|
-
Feature: ${featureName}
|
|
247
|
-
Phase: ${phase}
|
|
248
|
-
|
|
249
|
-
Your Domain Leaders:
|
|
250
|
-
${Object.values(squads).map(s => `- ${s.leader.title} (${s.leader.id})`).join('\n')}
|
|
251
|
-
|
|
252
|
-
DO NOT implement code yourself. Coordinate Domain Leaders, resolve conflicts, synthesize results.`
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
// Add Domain Leaders + their squad members
|
|
257
|
-
Object.entries(squads).forEach(([leaderId, squad]) => {
|
|
258
|
-
const leader = squad.leader;
|
|
259
|
-
|
|
260
|
-
if (leader.teammate) {
|
|
261
|
-
teammates.push({
|
|
262
|
-
id: leader.id,
|
|
263
|
-
tier: leader.tier,
|
|
264
|
-
role: leader.teammate.role,
|
|
265
|
-
icon: leader.teammate.icon,
|
|
266
|
-
spawnPrompt: `${leader.teammate.spawn_prompt}
|
|
267
|
-
|
|
268
|
-
Feature: ${featureName}
|
|
269
|
-
Phase: ${phase}
|
|
270
|
-
|
|
271
|
-
Your Squad (${squad.members.length} specialists):
|
|
272
|
-
${squad.members.map(m => `- ${m.title} (${m.id})`).join('\n')}
|
|
273
|
-
|
|
274
|
-
Coordinate your specialists. Escalate conflicts to ${leader.relationships.escalates_to}.`
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
squad.members.forEach(specialist => {
|
|
279
|
-
if (specialist.teammate) {
|
|
280
|
-
teammates.push({
|
|
281
|
-
id: specialist.id,
|
|
282
|
-
tier: specialist.tier,
|
|
283
|
-
role: specialist.teammate.role,
|
|
284
|
-
icon: specialist.teammate.icon,
|
|
285
|
-
spawnPrompt: `${specialist.teammate.spawn_prompt}
|
|
286
|
-
|
|
287
|
-
Feature: ${featureName}
|
|
288
|
-
Phase: ${phase}
|
|
289
|
-
|
|
290
|
-
Reports to: ${specialist.relationships.reports_to}
|
|
291
|
-
Escalate to: ${specialist.relationships.escalates_to}
|
|
292
|
-
|
|
293
|
-
${specialist.relationships.collaborates_with ?
|
|
294
|
-
`Collaborate with: ${specialist.relationships.collaborates_with.join(', ')}` : ''}`
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
return teammates;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* @deprecated Use generateTeamInstructions() instead.
|
|
305
|
-
* Kept for backward compatibility — will be removed in a future version.
|
|
306
|
-
*/
|
|
307
|
-
export function generateSpawnCommand(teammates, _displayMode = 'auto') {
|
|
308
|
-
// Returns legacy JSON format for any code still calling the old signature.
|
|
309
|
-
// New code should call generateTeamInstructions(teamHierarchy, featureName, phase).
|
|
310
|
-
return JSON.stringify({
|
|
311
|
-
_deprecated: true,
|
|
312
|
-
_message: 'Use generateTeamInstructions() for Agent Teams mode.',
|
|
313
|
-
teammates: teammates.map(t => ({ id: t.id, role: t.role })),
|
|
314
|
-
}, null, 2);
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* Main orchestration function — decides if/when to use Agent Teams vs subagents.
|
|
319
|
-
*
|
|
320
|
-
* @param {Object} options
|
|
321
|
-
* @param {string} options.projectPath - Project root path
|
|
322
|
-
* @param {string} options.featureName - Feature name
|
|
323
|
-
* @param {string} options.phase - MORPH phase
|
|
324
|
-
* @param {string[]} options.activeAgents - Active agent IDs
|
|
325
|
-
* @param {string} options.complexity - Complexity level
|
|
326
|
-
* @param {number} options.estimatedFiles - Estimated file count
|
|
327
|
-
* @param {boolean} options.multiDomain - Multi-domain feature?
|
|
328
|
-
* @returns {Promise<Object>} Team orchestration result
|
|
329
|
-
*/
|
|
330
|
-
export async function orchestrateTeam(options) {
|
|
331
|
-
const {
|
|
332
|
-
projectPath,
|
|
333
|
-
featureName,
|
|
334
|
-
phase,
|
|
335
|
-
activeAgents = [],
|
|
336
|
-
complexity,
|
|
337
|
-
estimatedFiles = 0,
|
|
338
|
-
multiDomain = false,
|
|
339
|
-
} = options;
|
|
340
|
-
|
|
341
|
-
// Step 1: Decide mode
|
|
342
|
-
const modeDecision = shouldSpawnAgentTeam({
|
|
343
|
-
activeAgents,
|
|
344
|
-
complexity,
|
|
345
|
-
estimatedFiles,
|
|
346
|
-
multiDomain,
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
if (modeDecision.mode === 'single') {
|
|
350
|
-
return {
|
|
351
|
-
mode: 'single',
|
|
352
|
-
reason: modeDecision.reason,
|
|
353
|
-
recommendation: 'Use single session — sequential implementation',
|
|
354
|
-
};
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
// Step 2: Load agents config and build hierarchy
|
|
358
|
-
const agentsConfig = await loadAgentsConfig(projectPath);
|
|
359
|
-
const teamHierarchy = buildTeamHierarchy(activeAgents, agentsConfig);
|
|
360
|
-
|
|
361
|
-
if (modeDecision.mode === 'agent-teams') {
|
|
362
|
-
// Step 3a: Generate natural language Agent Teams instructions
|
|
363
|
-
const teamInstructions = generateTeamInstructions(teamHierarchy, featureName, phase);
|
|
364
|
-
|
|
365
|
-
return {
|
|
366
|
-
mode: 'agent-teams',
|
|
367
|
-
reason: modeDecision.reason,
|
|
368
|
-
teamHierarchy: {
|
|
369
|
-
teamLead: teamHierarchy.teamLead?.id,
|
|
370
|
-
squads: Object.keys(teamHierarchy.squads),
|
|
371
|
-
totalTeammates: teamHierarchy.totalTeammates,
|
|
372
|
-
validators: teamHierarchy.validators.map(v => v.id),
|
|
373
|
-
},
|
|
374
|
-
teamInstructions,
|
|
375
|
-
recommendation: `Create Agent Team with ${teamHierarchy.totalTeammates} teammates (lead + domain leaders). Require plan approval before implementation.`,
|
|
376
|
-
};
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
// mode === 'subagents'
|
|
380
|
-
// Step 3b: Generate Task tool subagent configs
|
|
381
|
-
const teammates = generateTeammateConfigs(teamHierarchy, featureName, phase);
|
|
382
|
-
|
|
383
|
-
return {
|
|
384
|
-
mode: 'subagents',
|
|
385
|
-
reason: modeDecision.reason,
|
|
386
|
-
teamHierarchy: {
|
|
387
|
-
teamLead: teamHierarchy.teamLead?.id,
|
|
388
|
-
squads: Object.keys(teamHierarchy.squads),
|
|
389
|
-
totalTeammates: teamHierarchy.totalTeammates,
|
|
390
|
-
validators: teamHierarchy.validators.map(v => v.id),
|
|
391
|
-
},
|
|
392
|
-
teammates,
|
|
393
|
-
recommendation: `Dispatch ${teammates.length} Task subagents in parallel`,
|
|
394
|
-
};
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
/**
|
|
398
|
-
* Get agent squad assignments (for informational purposes)
|
|
399
|
-
* @param {Object} agentsConfig - Loaded agents.json
|
|
400
|
-
* @returns {Object} Squad information
|
|
401
|
-
*/
|
|
402
|
-
export function getSquadInfo(agentsConfig) {
|
|
403
|
-
return agentsConfig.squads || {};
|
|
404
|
-
}
|
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview ContextSanitizer - Sanitizes project context before sending to LLM
|
|
3
|
-
* @module morph-spec/sanitizer/context-sanitizer
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { minimatch } from 'minimatch';
|
|
7
|
-
import {
|
|
8
|
-
WHITELIST_FILES,
|
|
9
|
-
BLACKLIST_DIRECTORIES,
|
|
10
|
-
BLACKLIST_FILES,
|
|
11
|
-
SECRET_PATTERNS,
|
|
12
|
-
MAX_FILE_SIZE,
|
|
13
|
-
MAX_SUMMARY_LENGTH
|
|
14
|
-
} from './patterns.js';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @typedef {import('../types/index.js').ProjectContext} ProjectContext
|
|
18
|
-
* @typedef {import('../types/index.js').SanitizedContext} SanitizedContext
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* ContextSanitizer - Removes secrets and sensitive data before LLM analysis
|
|
23
|
-
* Implements hybrid whitelist/blacklist approach per ADR-004
|
|
24
|
-
* @class
|
|
25
|
-
*/
|
|
26
|
-
export class ContextSanitizer {
|
|
27
|
-
/**
|
|
28
|
-
* Sanitize project context (remove secrets, truncate files)
|
|
29
|
-
* @param {ProjectContext} context - Raw project context
|
|
30
|
-
* @returns {SanitizedContext}
|
|
31
|
-
*/
|
|
32
|
-
sanitize(context) {
|
|
33
|
-
// Sanitize package.json (remove private fields, redact secrets)
|
|
34
|
-
const sanitizedPackageJson = this.sanitizePackageJson(context.packageJson);
|
|
35
|
-
|
|
36
|
-
// Extract only filenames from .csproj paths (not full content)
|
|
37
|
-
const csprojFilenames = context.csprojFiles.map(path => path.split('/').pop());
|
|
38
|
-
|
|
39
|
-
// Truncate README and CLAUDE.md to first 500 chars
|
|
40
|
-
const readmeSummary = context.readme
|
|
41
|
-
? this.truncateText(context.readme, MAX_SUMMARY_LENGTH)
|
|
42
|
-
: null;
|
|
43
|
-
|
|
44
|
-
const claudeMdSummary = context.claudeMd
|
|
45
|
-
? this.truncateText(context.claudeMd, MAX_SUMMARY_LENGTH)
|
|
46
|
-
: null;
|
|
47
|
-
|
|
48
|
-
// Sanitize infrastructure summary (remove secrets, just count files)
|
|
49
|
-
const infraSummary = {
|
|
50
|
-
dockerfilesCount: context.infraFiles.dockerfiles.length,
|
|
51
|
-
dockerComposeCount: context.infraFiles.dockerComposeFiles.length,
|
|
52
|
-
bicepFilesCount: context.infraFiles.bicepFiles.length,
|
|
53
|
-
pipelinesCount: context.infraFiles.pipelines.length,
|
|
54
|
-
hasAzure: context.infraFiles.hasAzure,
|
|
55
|
-
hasDocker: context.infraFiles.hasDocker,
|
|
56
|
-
hasDevOps: context.infraFiles.hasDevOps
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
// Extract git remote domain only (not full URL with credentials)
|
|
60
|
-
const gitRemoteDomain = context.gitRemote
|
|
61
|
-
? this.extractDomain(context.gitRemote)
|
|
62
|
-
: null;
|
|
63
|
-
|
|
64
|
-
// Estimate total files (approximate)
|
|
65
|
-
const totalFiles = context.structure.topLevelDirs.length * 10; // rough estimate
|
|
66
|
-
|
|
67
|
-
return {
|
|
68
|
-
packageJson: sanitizedPackageJson,
|
|
69
|
-
csprojFilenames,
|
|
70
|
-
hasSolution: context.solutionFile !== null,
|
|
71
|
-
readmeSummary,
|
|
72
|
-
claudeMdSummary,
|
|
73
|
-
structure: context.structure,
|
|
74
|
-
infraSummary,
|
|
75
|
-
gitRemoteDomain,
|
|
76
|
-
totalFiles
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Sanitize package.json - remove private fields and redact secrets
|
|
82
|
-
* @param {Object|null} packageJson - Raw package.json
|
|
83
|
-
* @returns {Object}
|
|
84
|
-
*/
|
|
85
|
-
sanitizePackageJson(packageJson) {
|
|
86
|
-
if (!packageJson) {
|
|
87
|
-
return {};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Keep only safe fields
|
|
91
|
-
const safe = {
|
|
92
|
-
name: packageJson.name || 'unknown',
|
|
93
|
-
version: packageJson.version,
|
|
94
|
-
description: packageJson.description,
|
|
95
|
-
type: packageJson.type,
|
|
96
|
-
engines: packageJson.engines
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
// Include dependencies (names only, no versions for simplicity)
|
|
100
|
-
if (packageJson.dependencies) {
|
|
101
|
-
safe.dependencies = Object.keys(packageJson.dependencies);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (packageJson.devDependencies) {
|
|
105
|
-
safe.devDependencies = Object.keys(packageJson.devDependencies);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// Include scripts (but redact any that might contain secrets)
|
|
109
|
-
if (packageJson.scripts) {
|
|
110
|
-
safe.scripts = {};
|
|
111
|
-
for (const [key, value] of Object.entries(packageJson.scripts)) {
|
|
112
|
-
safe.scripts[key] = this.redactSecrets(value);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return safe;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Detect and redact secrets from text
|
|
121
|
-
* @param {string} text - Text to sanitize
|
|
122
|
-
* @returns {string} Sanitized text
|
|
123
|
-
*/
|
|
124
|
-
redactSecrets(text) {
|
|
125
|
-
if (!text || typeof text !== 'string') {
|
|
126
|
-
return text;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
let sanitized = text;
|
|
130
|
-
|
|
131
|
-
// Apply all secret patterns
|
|
132
|
-
for (const pattern of SECRET_PATTERNS) {
|
|
133
|
-
sanitized = sanitized.replace(pattern.regex, pattern.replacement);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return sanitized;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Check if file should be excluded from LLM analysis
|
|
141
|
-
* @param {string} filepath - File path (relative or absolute)
|
|
142
|
-
* @returns {boolean} True if file should be excluded
|
|
143
|
-
*/
|
|
144
|
-
shouldExcludeFile(filepath) {
|
|
145
|
-
const normalizedPath = filepath.replace(/\\/g, '/');
|
|
146
|
-
|
|
147
|
-
// Check if path contains blacklisted directory
|
|
148
|
-
for (const blacklistDir of BLACKLIST_DIRECTORIES) {
|
|
149
|
-
if (normalizedPath.includes(`/${blacklistDir}/`) || normalizedPath.startsWith(`${blacklistDir}/`)) {
|
|
150
|
-
return true;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// Check if filename matches blacklist pattern
|
|
155
|
-
const filename = normalizedPath.split('/').pop();
|
|
156
|
-
for (const pattern of BLACKLIST_FILES) {
|
|
157
|
-
if (minimatch(filename, pattern, { nocase: true })) {
|
|
158
|
-
return true;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return false;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Check if file is whitelisted for reading
|
|
167
|
-
* @param {string} filepath - File path
|
|
168
|
-
* @returns {boolean} True if file is whitelisted
|
|
169
|
-
*/
|
|
170
|
-
isWhitelisted(filepath) {
|
|
171
|
-
const normalizedPath = filepath.replace(/\\/g, '/');
|
|
172
|
-
const filename = normalizedPath.split('/').pop();
|
|
173
|
-
|
|
174
|
-
for (const pattern of WHITELIST_FILES) {
|
|
175
|
-
if (minimatch(filename, pattern, { nocase: true })) {
|
|
176
|
-
return true;
|
|
177
|
-
}
|
|
178
|
-
// Also check full path for patterns like ".github/workflows/*.yml"
|
|
179
|
-
if (minimatch(normalizedPath, pattern, { nocase: true })) {
|
|
180
|
-
return true;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return false;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Truncate text to maximum length
|
|
189
|
-
* @param {string} text - Text to truncate
|
|
190
|
-
* @param {number} maxLength - Maximum length
|
|
191
|
-
* @returns {string} Truncated text
|
|
192
|
-
*/
|
|
193
|
-
truncateText(text, maxLength) {
|
|
194
|
-
if (!text || text.length <= maxLength) {
|
|
195
|
-
return text;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
return text.substring(0, maxLength) + '... [truncated]';
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Extract domain from git remote URL
|
|
203
|
-
* @param {string} url - Git remote URL
|
|
204
|
-
* @returns {string|null} Domain only (e.g., "github.com")
|
|
205
|
-
*/
|
|
206
|
-
extractDomain(url) {
|
|
207
|
-
try {
|
|
208
|
-
// Handle SSH format: git@github.com:user/repo.git
|
|
209
|
-
if (url.startsWith('git@')) {
|
|
210
|
-
const match = url.match(/git@([^:]+):/);
|
|
211
|
-
return match ? match[1] : null;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// Handle HTTPS format: https://github.com/user/repo.git
|
|
215
|
-
const urlObj = new URL(url);
|
|
216
|
-
return urlObj.hostname;
|
|
217
|
-
} catch (error) {
|
|
218
|
-
return null;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
}
|