@polymorphism-tech/morph-spec 4.8.19 → 4.10.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/CLAUDE.md +21 -0
- package/README.md +2 -2
- package/bin/morph-spec.js +44 -55
- package/bin/task-manager.js +133 -20
- package/bin/validate.js +67 -33
- package/claude-plugin.json +1 -1
- package/docs/CHEATSHEET.md +201 -203
- package/docs/QUICKSTART.md +2 -2
- package/framework/CLAUDE.md +99 -77
- package/framework/agents.json +734 -182
- package/framework/commands/commit.md +166 -0
- package/framework/commands/morph-apply.md +13 -2
- package/framework/commands/morph-archive.md +8 -2
- package/framework/commands/morph-infra.md +6 -0
- package/framework/commands/morph-preflight.md +6 -0
- package/framework/commands/morph-proposal.md +56 -7
- package/framework/commands/morph-status.md +6 -0
- package/framework/commands/morph-troubleshoot.md +6 -0
- package/framework/hooks/claude-code/notification/approval-reminder.js +3 -2
- package/framework/hooks/claude-code/post-tool-use/context-refresh.js +1 -1
- package/framework/hooks/claude-code/post-tool-use/dispatch.js +155 -32
- package/framework/hooks/claude-code/post-tool-use/skill-reminder.js +78 -0
- 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 +4 -3
- 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 +124 -2
- package/framework/hooks/claude-code/session-start/post-compact-restore.js +41 -0
- package/framework/hooks/claude-code/statusline.py +76 -30
- 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/claude-code/user-prompt/set-terminal-title.js +14 -6
- package/framework/hooks/shared/activity-logger.js +0 -24
- 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 +12 -5
- package/framework/hooks/shared/skill-reminder-helpers.js +79 -0
- package/framework/hooks/shared/stale-task-reset.js +57 -0
- package/framework/hooks/shared/state-reader.js +29 -5
- package/framework/hooks/shared/worktree-helpers.js +53 -0
- package/framework/phases.json +69 -14
- package/framework/rules/morph-workflow.md +88 -86
- package/framework/skills/level-0-meta/mcp-registry.json +86 -51
- package/framework/skills/level-0-meta/{brainstorming → morph-brainstorming}/SKILL.md +14 -17
- package/framework/skills/level-0-meta/morph-checklist/SKILL.md +2 -2
- package/framework/skills/level-0-meta/{code-review → morph-code-review}/SKILL.md +2 -2
- package/framework/skills/level-0-meta/{code-review-nextjs → morph-code-review-nextjs}/SKILL.md +163 -163
- package/framework/skills/level-0-meta/{frontend-review → morph-frontend-review}/SKILL.md +9 -9
- package/framework/skills/level-0-meta/morph-init/SKILL.md +77 -12
- package/framework/skills/level-0-meta/{post-implementation → morph-post-implementation}/SKILL.md +62 -15
- package/framework/skills/level-0-meta/morph-replicate/SKILL.md +5 -5
- package/framework/skills/level-0-meta/morph-replicate/references/blazor-html-mapping.md +1 -1
- package/framework/skills/level-0-meta/{simulation-checklist → morph-simulation-checklist}/SKILL.md +1 -1
- package/framework/skills/level-0-meta/{terminal-title → morph-terminal-title}/SKILL.md +2 -2
- package/framework/skills/level-0-meta/{tool-usage-guide → morph-tool-usage-guide}/SKILL.md +3 -4
- package/framework/skills/level-0-meta/{tool-usage-guide → morph-tool-usage-guide}/references/tools-per-phase.md +7 -7
- package/framework/skills/level-0-meta/{verification-before-completion → morph-verification-before-completion}/SKILL.md +2 -2
- 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 +238 -0
- package/framework/skills/level-1-workflows/{phase-codebase-analysis → morph-phase-codebase-analysis}/SKILL.md +3 -3
- package/framework/skills/level-1-workflows/morph-phase-design/SKILL.md +507 -0
- package/framework/skills/level-1-workflows/{phase-implement → morph-phase-implement}/SKILL.md +168 -27
- 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 +254 -0
- package/framework/skills/level-1-workflows/{phase-setup → morph-phase-setup}/SKILL.md +50 -3
- package/framework/skills/level-1-workflows/{phase-tasks → morph-phase-tasks}/SKILL.md +48 -11
- package/framework/skills/level-1-workflows/{phase-tasks → morph-phase-tasks}/scripts/validate-tasks.mjs +3 -3
- package/framework/skills/level-1-workflows/{phase-uiux → morph-phase-uiux}/SKILL.md +46 -11
- package/framework/skills/level-1-workflows/morph-scope-escalation/SKILL.md +97 -0
- package/framework/standards/STANDARDS.json +640 -88
- package/framework/standards/infrastructure/vercel/vercel-database.md +106 -0
- package/framework/standards/integration/mcp/mcp-tools.md +25 -7
- package/framework/templates/REGISTRY.json +1825 -1909
- package/framework/templates/context/CONTEXT-FEATURE.md +276 -276
- package/framework/templates/docs/onboarding.md +3 -7
- package/package.json +2 -7
- package/src/commands/agents/dispatch-agents.js +104 -6
- package/src/commands/mcp/mcp-setup.js +39 -2
- package/src/commands/phase/phase-reset.js +74 -0
- package/src/commands/project/doctor.js +34 -51
- package/src/commands/project/init.js +1 -1
- package/src/commands/project/status.js +2 -2
- package/src/commands/project/update.js +381 -365
- package/src/commands/project/worktree.js +154 -0
- package/src/commands/scope/escalate.js +215 -0
- package/src/commands/state/advance-phase.js +132 -68
- package/src/commands/state/approve.js +2 -2
- package/src/commands/state/index.js +7 -8
- package/src/commands/state/phase-runner.js +1 -1
- package/src/commands/state/state.js +61 -6
- package/src/commands/task/expand.js +100 -0
- package/src/commands/tasks/task.js +78 -99
- package/src/commands/templates/template-render.js +93 -173
- package/src/commands/trust/trust.js +26 -21
- package/src/core/paths/output-schema.js +19 -3
- package/src/core/state/phase-state-machine.js +7 -4
- package/src/core/state/state-manager.js +32 -57
- package/src/core/workflows/workflow-detector.js +9 -87
- 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 +336 -0
- package/src/lib/scope/impact-analyzer.js +106 -0
- package/src/lib/stack/stack-profile.js +88 -0
- package/src/lib/tasks/task-classifier.js +16 -0
- package/src/lib/tasks/task-parser.js +1 -1
- package/src/lib/tasks/test-runner.js +77 -0
- package/src/lib/trust/trust-manager.js +32 -144
- package/src/lib/validators/shared/emit-validator-dispatch.js +64 -0
- package/src/lib/validators/spec-validator.js +58 -4
- package/src/lib/validators/validation-runner.js +23 -11
- package/src/scripts/setup-infra.js +255 -224
- package/src/utils/agents-installer.js +34 -14
- package/src/utils/banner.js +1 -1
- package/src/utils/claude-settings-manager.js +1 -1
- package/src/utils/file-copier.js +1 -1
- package/src/utils/hooks-installer.js +272 -8
- package/framework/hooks/dev/check-sync-health.js +0 -117
- package/framework/hooks/dev/guard-version-numbers.js +0 -57
- package/framework/hooks/dev/sync-standards-registry.js +0 -60
- package/framework/hooks/dev/sync-template-registry.js +0 -60
- package/framework/hooks/dev/validate-skill-format.js +0 -70
- package/framework/hooks/dev/validate-standard-format.js +0 -73
- package/framework/skills/level-1-workflows/phase-clarify/SKILL.md +0 -190
- package/framework/skills/level-1-workflows/phase-design/SKILL.md +0 -366
- package/framework/templates/meta-prompts/hops/hop-retry.md +0 -78
- package/framework/templates/meta-prompts/hops/hop-validation.md +0 -97
- package/framework/templates/meta-prompts/hops/hop-wrapper.md +0 -36
- package/framework/workflows/configs/design-impl.json +0 -49
- package/framework/workflows/configs/express.json +0 -45
- package/framework/workflows/configs/fast-track.json +0 -42
- package/framework/workflows/configs/full-morph.json +0 -79
- package/framework/workflows/configs/fusion.json +0 -39
- package/framework/workflows/configs/long-running.json +0 -33
- package/framework/workflows/configs/spec-only.json +0 -43
- package/framework/workflows/configs/ui-refresh.json +0 -49
- package/framework/workflows/configs/zero-touch.json +0 -82
- package/src/commands/project/index.js +0 -8
- package/src/commands/project/monitor.js +0 -295
- package/src/commands/project/tutorial.js +0 -115
- package/src/commands/state/validate-phase.js +0 -238
- package/src/commands/templates/generate-contracts.js +0 -445
- package/src/core/index.js +0 -10
- package/src/core/orchestrator.js +0 -171
- package/src/core/registry/command-registry.js +0 -28
- package/src/core/registry/index.js +0 -8
- package/src/core/registry/validator-registry.js +0 -204
- 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/templates/template-validator.js +0 -296
- package/src/core/workflows/index.js +0 -7
- package/src/generator/config-generator.js +0 -206
- package/src/generator/templates/config.json.template +0 -40
- package/src/generator/templates/project.md.template +0 -67
- package/src/lib/agents/micro-agent-factory.js +0 -161
- package/src/lib/analysis/complexity-analyzer.js +0 -441
- package/src/lib/analysis/index.js +0 -7
- package/src/lib/analytics/analytics-engine.js +0 -345
- package/src/lib/checkpoints/checkpoint-hooks.js +0 -298
- package/src/lib/checkpoints/index.js +0 -7
- package/src/lib/context/context-bundler.js +0 -241
- package/src/lib/context/context-optimizer.js +0 -212
- package/src/lib/context/context-tracker.js +0 -273
- package/src/lib/context/core-four-tracker.js +0 -201
- package/src/lib/context/mcp-optimizer.js +0 -200
- 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/execution/fusion-executor.js +0 -304
- package/src/lib/execution/parallel-executor.js +0 -270
- package/src/lib/hooks/stop-hook-executor.js +0 -286
- package/src/lib/hops/hop-composer.js +0 -221
- 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/lib/phase-chain/eligibility-checker.js +0 -243
- package/src/lib/threads/thread-coordinator.js +0 -238
- package/src/lib/threads/thread-manager.js +0 -317
- package/src/lib/tracking/artifact-trail.js +0 -202
- package/src/sanitizer/context-sanitizer.js +0 -221
- package/src/sanitizer/patterns.js +0 -163
- package/src/scanner/project-scanner.js +0 -242
- package/src/ui/diff-display.js +0 -91
- package/src/ui/interactive-wizard.js +0 -96
- package/src/ui/user-review.js +0 -211
- package/src/ui/wizard-questions.js +0 -188
- package/src/utils/color-utils.js +0 -70
- package/src/utils/process-handler.js +0 -97
- 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-0-meta/{terminal-title → morph-terminal-title}/scripts/set_title.sh +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,243 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Phase Eligibility Checker
|
|
3
|
-
*
|
|
4
|
-
* Determines whether a feature is eligible to auto-advance to the next phase.
|
|
5
|
-
* Used by phase-runner.js and the dispatch.js PostToolUse hook.
|
|
6
|
-
*
|
|
7
|
-
* Eligibility criteria (all must pass):
|
|
8
|
-
* 1. Required outputs for the current phase exist on disk
|
|
9
|
-
* 2. No tasks in state with status = 'blocked'
|
|
10
|
-
* 3. validationHistory passRate >= minPassRate (from workflow config)
|
|
11
|
-
* 4. Trust level meets the workflow's trustLevel requirement
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import { existsSync } from 'fs';
|
|
15
|
-
import { join } from 'path';
|
|
16
|
-
import { loadState } from '../../core/state/state-manager.js';
|
|
17
|
-
import { getWorkflowConfig } from '../../core/workflows/workflow-detector.js';
|
|
18
|
-
import { derivePhase } from '../../core/state/state-manager.js';
|
|
19
|
-
import { PHASES } from '../../commands/state/validate-phase.js';
|
|
20
|
-
import { shouldAutoApprove } from '../trust/trust-manager.js';
|
|
21
|
-
|
|
22
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
23
|
-
// Types (JSDoc)
|
|
24
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* @typedef {Object} EligibilityBlocker
|
|
28
|
-
* @property {'missing_outputs'|'blocked_tasks'|'low_pass_rate'|'trust_too_low'|'state_error'} type
|
|
29
|
-
* @property {string[]} [items] - Specific items causing the block
|
|
30
|
-
* @property {number} [current] - Current value (for rate/level comparisons)
|
|
31
|
-
* @property {number|string} [required] - Required value
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* @typedef {Object} EligibilityResult
|
|
36
|
-
* @property {boolean} eligible
|
|
37
|
-
* @property {EligibilityBlocker[]} blockers
|
|
38
|
-
* @property {string} currentPhase
|
|
39
|
-
* @property {string|null} nextPhase
|
|
40
|
-
* @property {number|null} passRate - Current validation pass rate (null if no data)
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
44
|
-
// Helpers
|
|
45
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
46
|
-
|
|
47
|
-
/** Phase order (canonical from advance-phase.js) */
|
|
48
|
-
const PHASE_ORDER = ['proposal', 'setup', 'uiux', 'design', 'clarify', 'tasks', 'implement', 'sync'];
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Get the next phase in the standard sequence.
|
|
52
|
-
* Returns null when at the last phase.
|
|
53
|
-
*/
|
|
54
|
-
function getNextPhase(currentPhase) {
|
|
55
|
-
const idx = PHASE_ORDER.indexOf(currentPhase);
|
|
56
|
-
if (idx === -1 || idx >= PHASE_ORDER.length - 1) return null;
|
|
57
|
-
return PHASE_ORDER[idx + 1];
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Compute the overall validation pass rate from validationHistory.
|
|
62
|
-
* Returns null when no history exists.
|
|
63
|
-
*
|
|
64
|
-
* @param {Object} validationHistory - feature.validationHistory
|
|
65
|
-
* @returns {number|null}
|
|
66
|
-
*/
|
|
67
|
-
export function computePassRate(validationHistory) {
|
|
68
|
-
if (!validationHistory || Object.keys(validationHistory).length === 0) return null;
|
|
69
|
-
|
|
70
|
-
const entries = Object.values(validationHistory);
|
|
71
|
-
const total = entries.length;
|
|
72
|
-
const passed = entries.filter(e => e.status === 'passed').length;
|
|
73
|
-
|
|
74
|
-
return total > 0 ? passed / total : null;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Check if required outputs exist on disk for the given phase.
|
|
79
|
-
*
|
|
80
|
-
* @param {string} featureName
|
|
81
|
-
* @param {string} phase
|
|
82
|
-
* @param {string} projectPath
|
|
83
|
-
* @returns {string[]} Array of missing output descriptions
|
|
84
|
-
*/
|
|
85
|
-
function getMissingRequiredOutputs(featureName, phase, projectPath) {
|
|
86
|
-
const phaseDef = PHASES[phase];
|
|
87
|
-
if (!phaseDef?.requiredOutputs) return [];
|
|
88
|
-
|
|
89
|
-
const missing = [];
|
|
90
|
-
const featureBase = join(projectPath, '.morph', 'features', featureName);
|
|
91
|
-
|
|
92
|
-
// Map output type names to common file paths
|
|
93
|
-
const outputPathMap = {
|
|
94
|
-
'proposal': '0-proposal/proposal.md',
|
|
95
|
-
'spec': '1-design/spec.md',
|
|
96
|
-
'contracts': '1-design/contracts.cs',
|
|
97
|
-
'tasks': '3-tasks/tasks.md',
|
|
98
|
-
'schemaAnalysis': '1-design/schema-analysis.md',
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
for (const output of phaseDef.requiredOutputs) {
|
|
102
|
-
const relPath = outputPathMap[output];
|
|
103
|
-
if (relPath && !existsSync(join(featureBase, relPath))) {
|
|
104
|
-
missing.push(output);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return missing;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Get tasks that are blocked (attempt >= 3, no resolution).
|
|
113
|
-
*
|
|
114
|
-
* @param {Object} feature - Feature state object
|
|
115
|
-
* @returns {string[]} Array of blocked task IDs
|
|
116
|
-
*/
|
|
117
|
-
function getBlockedTasks(feature) {
|
|
118
|
-
const history = feature.validationHistory || {};
|
|
119
|
-
return Object.entries(history)
|
|
120
|
-
.filter(([, entry]) => entry.status === 'blocked')
|
|
121
|
-
.map(([taskId]) => taskId);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
125
|
-
// Main export
|
|
126
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Check whether a feature is eligible to auto-advance to the next phase.
|
|
130
|
-
*
|
|
131
|
-
* @param {string} featureName
|
|
132
|
-
* @param {Object} [opts]
|
|
133
|
-
* @param {string} [opts.projectPath] - Project root (defaults to cwd)
|
|
134
|
-
* @param {boolean} [opts.dryRun] - Only compute, don't enforce
|
|
135
|
-
* @returns {EligibilityResult}
|
|
136
|
-
*/
|
|
137
|
-
export function checkPhaseEligibility(featureName, opts = {}) {
|
|
138
|
-
const projectPath = opts.projectPath || process.cwd();
|
|
139
|
-
|
|
140
|
-
// ── Load state ────────────────────────────────────────────────────────────
|
|
141
|
-
const state = loadState(false);
|
|
142
|
-
if (!state) {
|
|
143
|
-
return {
|
|
144
|
-
eligible: false,
|
|
145
|
-
blockers: [{ type: 'state_error', items: ['state.json not found'] }],
|
|
146
|
-
currentPhase: 'unknown',
|
|
147
|
-
nextPhase: null,
|
|
148
|
-
passRate: null,
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const feature = state.features?.[featureName];
|
|
153
|
-
if (!feature) {
|
|
154
|
-
return {
|
|
155
|
-
eligible: false,
|
|
156
|
-
blockers: [{ type: 'state_error', items: [`Feature '${featureName}' not found in state.json`] }],
|
|
157
|
-
currentPhase: 'unknown',
|
|
158
|
-
nextPhase: null,
|
|
159
|
-
passRate: null,
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// ── Derive current phase ──────────────────────────────────────────────────
|
|
164
|
-
const featureFolderPath = join(projectPath, '.morph', 'features', featureName);
|
|
165
|
-
const currentPhase = feature.phase || derivePhase(featureFolderPath);
|
|
166
|
-
const nextPhase = getNextPhase(currentPhase);
|
|
167
|
-
|
|
168
|
-
if (!nextPhase) {
|
|
169
|
-
return {
|
|
170
|
-
eligible: false,
|
|
171
|
-
blockers: [{ type: 'state_error', items: ['Feature is at the final phase'] }],
|
|
172
|
-
currentPhase,
|
|
173
|
-
nextPhase: null,
|
|
174
|
-
passRate: null,
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// ── Load workflow config ──────────────────────────────────────────────────
|
|
179
|
-
let workflowConfig = null;
|
|
180
|
-
if (feature.workflow && feature.workflow !== 'auto') {
|
|
181
|
-
try {
|
|
182
|
-
workflowConfig = getWorkflowConfig(feature.workflow);
|
|
183
|
-
} catch {
|
|
184
|
-
// Non-blocking: fall through to defaults
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
const minPassRate = workflowConfig?.phaseChain?.pauseOn
|
|
189
|
-
? 0.80 // Default minimum
|
|
190
|
-
: workflowConfig?.eligibility?.minPassRate ?? 0.80;
|
|
191
|
-
|
|
192
|
-
const blockers = [];
|
|
193
|
-
|
|
194
|
-
// ── Check 1: Missing required outputs ────────────────────────────────────
|
|
195
|
-
const missingOutputs = getMissingRequiredOutputs(featureName, currentPhase, projectPath);
|
|
196
|
-
if (missingOutputs.length > 0) {
|
|
197
|
-
blockers.push({ type: 'missing_outputs', items: missingOutputs });
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// ── Check 2: Blocked tasks ────────────────────────────────────────────────
|
|
201
|
-
const blockedTasks = getBlockedTasks(feature);
|
|
202
|
-
if (blockedTasks.length > 0) {
|
|
203
|
-
blockers.push({ type: 'blocked_tasks', items: blockedTasks });
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// ── Check 3: Validation pass rate ────────────────────────────────────────
|
|
207
|
-
const passRate = computePassRate(feature.validationHistory);
|
|
208
|
-
if (passRate !== null && passRate < minPassRate) {
|
|
209
|
-
blockers.push({
|
|
210
|
-
type: 'low_pass_rate',
|
|
211
|
-
current: passRate,
|
|
212
|
-
required: minPassRate,
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
// ── Check 4: Trust level ─────────────────────────────────────────────────
|
|
217
|
-
try {
|
|
218
|
-
const requiredGateMap = { design: 'design', tasks: 'tasks', uiux: 'uiux' };
|
|
219
|
-
const gate = requiredGateMap[currentPhase];
|
|
220
|
-
if (gate) {
|
|
221
|
-
const trustResult = shouldAutoApprove(featureName, gate);
|
|
222
|
-
if (!trustResult.autoApprove) {
|
|
223
|
-
const gateStatus = feature.approvalGates?.[gate];
|
|
224
|
-
if (!gateStatus?.approved) {
|
|
225
|
-
blockers.push({
|
|
226
|
-
type: 'trust_too_low',
|
|
227
|
-
items: [`Gate '${gate}' requires trust level ${trustResult.level || 'medium+'}`],
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
} catch {
|
|
233
|
-
// Trust manager unavailable — non-blocking, don't add blocker
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
return {
|
|
237
|
-
eligible: blockers.length === 0,
|
|
238
|
-
blockers,
|
|
239
|
-
currentPhase,
|
|
240
|
-
nextPhase,
|
|
241
|
-
passRate,
|
|
242
|
-
};
|
|
243
|
-
}
|