musubi-sdd 5.1.0 → 5.6.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.ja.md +106 -48
- package/README.md +110 -32
- package/bin/musubi-analyze.js +74 -67
- package/bin/musubi-browser.js +27 -26
- package/bin/musubi-change.js +48 -47
- package/bin/musubi-checkpoint.js +10 -7
- package/bin/musubi-convert.js +25 -25
- package/bin/musubi-costs.js +27 -10
- package/bin/musubi-gui.js +52 -46
- package/bin/musubi-init.js +1952 -10
- package/bin/musubi-orchestrate.js +327 -239
- package/bin/musubi-remember.js +69 -56
- package/bin/musubi-resolve.js +53 -45
- package/bin/musubi-trace.js +51 -22
- package/bin/musubi-validate.js +39 -30
- package/bin/musubi-workflow.js +33 -34
- package/bin/musubi.js +39 -2
- package/package.json +1 -1
- package/src/agents/agent-loop.js +94 -95
- package/src/agents/agentic/code-generator.js +119 -109
- package/src/agents/agentic/code-reviewer.js +105 -108
- package/src/agents/agentic/index.js +4 -4
- package/src/agents/browser/action-executor.js +13 -13
- package/src/agents/browser/ai-comparator.js +11 -10
- package/src/agents/browser/context-manager.js +6 -6
- package/src/agents/browser/index.js +5 -5
- package/src/agents/browser/nl-parser.js +31 -46
- package/src/agents/browser/screenshot.js +2 -2
- package/src/agents/browser/test-generator.js +6 -4
- package/src/agents/function-tool.js +71 -65
- package/src/agents/index.js +7 -7
- package/src/agents/schema-generator.js +98 -94
- package/src/analyzers/ast-extractor.js +158 -146
- package/src/analyzers/codegraph-auto-update.js +858 -0
- package/src/analyzers/complexity-analyzer.js +536 -0
- package/src/analyzers/context-optimizer.js +241 -126
- package/src/analyzers/impact-analyzer.js +1 -1
- package/src/analyzers/large-project-analyzer.js +766 -0
- package/src/analyzers/repository-map.js +77 -81
- package/src/analyzers/security-analyzer.js +19 -11
- package/src/analyzers/stuck-detector.js +19 -17
- package/src/converters/index.js +78 -57
- package/src/converters/ir/types.js +12 -12
- package/src/converters/parsers/musubi-parser.js +134 -126
- package/src/converters/parsers/openapi-parser.js +70 -53
- package/src/converters/parsers/speckit-parser.js +239 -175
- package/src/converters/writers/musubi-writer.js +123 -118
- package/src/converters/writers/speckit-writer.js +124 -113
- package/src/generators/rust-migration-generator.js +512 -0
- package/src/gui/public/index.html +1365 -1211
- package/src/gui/server.js +41 -40
- package/src/gui/services/file-watcher.js +23 -8
- package/src/gui/services/project-scanner.js +26 -20
- package/src/gui/services/replanning-service.js +27 -23
- package/src/gui/services/traceability-service.js +8 -8
- package/src/gui/services/workflow-service.js +14 -7
- package/src/index.js +151 -0
- package/src/integrations/cicd.js +90 -104
- package/src/integrations/codegraph-mcp.js +643 -0
- package/src/integrations/documentation.js +142 -103
- package/src/integrations/examples.js +95 -80
- package/src/integrations/github-client.js +17 -17
- package/src/integrations/index.js +5 -5
- package/src/integrations/mcp/index.js +21 -21
- package/src/integrations/mcp/mcp-context-provider.js +76 -78
- package/src/integrations/mcp/mcp-discovery.js +74 -72
- package/src/integrations/mcp/mcp-tool-registry.js +99 -94
- package/src/integrations/mcp-connector.js +70 -66
- package/src/integrations/platforms.js +50 -49
- package/src/integrations/tool-discovery.js +37 -31
- package/src/llm-providers/anthropic-provider.js +11 -11
- package/src/llm-providers/base-provider.js +16 -18
- package/src/llm-providers/copilot-provider.js +22 -19
- package/src/llm-providers/index.js +26 -25
- package/src/llm-providers/ollama-provider.js +11 -11
- package/src/llm-providers/openai-provider.js +12 -12
- package/src/managers/agent-memory.js +36 -24
- package/src/managers/checkpoint-manager.js +4 -8
- package/src/managers/delta-spec.js +19 -19
- package/src/managers/index.js +13 -4
- package/src/managers/memory-condenser.js +35 -45
- package/src/managers/repo-skill-manager.js +57 -31
- package/src/managers/skill-loader.js +25 -22
- package/src/managers/skill-tools.js +36 -72
- package/src/managers/workflow.js +30 -22
- package/src/monitoring/cost-tracker.js +48 -46
- package/src/monitoring/incident-manager.js +116 -106
- package/src/monitoring/index.js +144 -134
- package/src/monitoring/observability.js +75 -62
- package/src/monitoring/quality-dashboard.js +45 -41
- package/src/monitoring/release-manager.js +63 -53
- package/src/orchestration/agent-skill-binding.js +39 -47
- package/src/orchestration/error-handler.js +65 -107
- package/src/orchestration/guardrails/base-guardrail.js +26 -24
- package/src/orchestration/guardrails/guardrail-rules.js +50 -64
- package/src/orchestration/guardrails/index.js +5 -5
- package/src/orchestration/guardrails/input-guardrail.js +58 -45
- package/src/orchestration/guardrails/output-guardrail.js +104 -81
- package/src/orchestration/guardrails/safety-check.js +79 -79
- package/src/orchestration/index.js +38 -55
- package/src/orchestration/mcp-tool-adapters.js +96 -99
- package/src/orchestration/orchestration-engine.js +21 -21
- package/src/orchestration/pattern-registry.js +60 -45
- package/src/orchestration/patterns/auto.js +34 -47
- package/src/orchestration/patterns/group-chat.js +59 -65
- package/src/orchestration/patterns/handoff.js +67 -65
- package/src/orchestration/patterns/human-in-loop.js +51 -72
- package/src/orchestration/patterns/nested.js +25 -40
- package/src/orchestration/patterns/sequential.js +35 -34
- package/src/orchestration/patterns/swarm.js +63 -56
- package/src/orchestration/patterns/triage.js +150 -109
- package/src/orchestration/reasoning/index.js +9 -9
- package/src/orchestration/reasoning/planning-engine.js +143 -140
- package/src/orchestration/reasoning/reasoning-engine.js +206 -144
- package/src/orchestration/reasoning/self-correction.js +121 -128
- package/src/orchestration/replanning/adaptive-goal-modifier.js +107 -112
- package/src/orchestration/replanning/alternative-generator.js +37 -42
- package/src/orchestration/replanning/config.js +63 -59
- package/src/orchestration/replanning/goal-progress-tracker.js +98 -100
- package/src/orchestration/replanning/index.js +24 -20
- package/src/orchestration/replanning/plan-evaluator.js +49 -50
- package/src/orchestration/replanning/plan-monitor.js +32 -28
- package/src/orchestration/replanning/proactive-path-optimizer.js +175 -178
- package/src/orchestration/replanning/replan-history.js +33 -26
- package/src/orchestration/replanning/replanning-engine.js +106 -108
- package/src/orchestration/skill-executor.js +107 -109
- package/src/orchestration/skill-registry.js +85 -89
- package/src/orchestration/workflow-examples.js +228 -231
- package/src/orchestration/workflow-executor.js +65 -68
- package/src/orchestration/workflow-orchestrator.js +72 -73
- package/src/phase4-integration.js +47 -40
- package/src/phase5-integration.js +89 -30
- package/src/reporters/coverage-report.js +82 -30
- package/src/reporters/hierarchical-reporter.js +498 -0
- package/src/reporters/traceability-matrix-report.js +29 -20
- package/src/resolvers/issue-resolver.js +43 -31
- package/src/steering/advanced-validation.js +133 -124
- package/src/steering/auto-updater.js +60 -73
- package/src/steering/index.js +6 -6
- package/src/steering/quality-metrics.js +41 -35
- package/src/steering/steering-auto-update.js +83 -86
- package/src/steering/steering-validator.js +98 -106
- package/src/steering/template-constraints.js +53 -54
- package/src/templates/agents/claude-code/CLAUDE.md +32 -32
- package/src/templates/agents/claude-code/skills/agent-assistant/SKILL.md +13 -5
- package/src/templates/agents/claude-code/skills/ai-ml-engineer/mlops-guide.md +23 -23
- package/src/templates/agents/claude-code/skills/ai-ml-engineer/model-card-template.md +60 -41
- package/src/templates/agents/claude-code/skills/api-designer/api-patterns.md +27 -19
- package/src/templates/agents/claude-code/skills/api-designer/openapi-template.md +11 -7
- package/src/templates/agents/claude-code/skills/bug-hunter/SKILL.md +4 -3
- package/src/templates/agents/claude-code/skills/bug-hunter/root-cause-analysis.md +37 -15
- package/src/templates/agents/claude-code/skills/change-impact-analyzer/dependency-graph-patterns.md +36 -42
- package/src/templates/agents/claude-code/skills/change-impact-analyzer/impact-analysis-template.md +69 -60
- package/src/templates/agents/claude-code/skills/cloud-architect/aws-patterns.md +31 -38
- package/src/templates/agents/claude-code/skills/cloud-architect/azure-patterns.md +28 -23
- package/src/templates/agents/claude-code/skills/code-reviewer/SKILL.md +61 -0
- package/src/templates/agents/claude-code/skills/code-reviewer/best-practices.md +27 -0
- package/src/templates/agents/claude-code/skills/code-reviewer/review-checklist.md +29 -10
- package/src/templates/agents/claude-code/skills/code-reviewer/review-standards.md +29 -24
- package/src/templates/agents/claude-code/skills/constitution-enforcer/SKILL.md +8 -6
- package/src/templates/agents/claude-code/skills/constitution-enforcer/constitutional-articles.md +62 -26
- package/src/templates/agents/claude-code/skills/constitution-enforcer/phase-minus-one-gates.md +35 -16
- package/src/templates/agents/claude-code/skills/database-administrator/backup-recovery.md +27 -17
- package/src/templates/agents/claude-code/skills/database-administrator/tuning-guide.md +25 -20
- package/src/templates/agents/claude-code/skills/database-schema-designer/schema-patterns.md +39 -22
- package/src/templates/agents/claude-code/skills/devops-engineer/ci-cd-templates.md +25 -22
- package/src/templates/agents/claude-code/skills/issue-resolver/SKILL.md +24 -21
- package/src/templates/agents/claude-code/skills/orchestrator/SKILL.md +148 -63
- package/src/templates/agents/claude-code/skills/orchestrator/patterns.md +35 -16
- package/src/templates/agents/claude-code/skills/orchestrator/selection-matrix.md +69 -64
- package/src/templates/agents/claude-code/skills/performance-engineer/optimization-playbook.md +47 -47
- package/src/templates/agents/claude-code/skills/performance-optimizer/SKILL.md +69 -0
- package/src/templates/agents/claude-code/skills/performance-optimizer/benchmark-template.md +63 -45
- package/src/templates/agents/claude-code/skills/performance-optimizer/optimization-patterns.md +33 -35
- package/src/templates/agents/claude-code/skills/project-manager/SKILL.md +7 -6
- package/src/templates/agents/claude-code/skills/project-manager/agile-ceremonies.md +47 -28
- package/src/templates/agents/claude-code/skills/project-manager/project-templates.md +94 -78
- package/src/templates/agents/claude-code/skills/quality-assurance/SKILL.md +20 -17
- package/src/templates/agents/claude-code/skills/quality-assurance/qa-plan-template.md +63 -49
- package/src/templates/agents/claude-code/skills/release-coordinator/SKILL.md +5 -5
- package/src/templates/agents/claude-code/skills/release-coordinator/feature-flag-guide.md +30 -26
- package/src/templates/agents/claude-code/skills/release-coordinator/release-plan-template.md +67 -35
- package/src/templates/agents/claude-code/skills/requirements-analyst/ears-format.md +54 -42
- package/src/templates/agents/claude-code/skills/requirements-analyst/validation-rules.md +36 -33
- package/src/templates/agents/claude-code/skills/security-auditor/SKILL.md +77 -19
- package/src/templates/agents/claude-code/skills/security-auditor/audit-checklists.md +24 -24
- package/src/templates/agents/claude-code/skills/security-auditor/owasp-top-10.md +61 -20
- package/src/templates/agents/claude-code/skills/security-auditor/vulnerability-patterns.md +43 -11
- package/src/templates/agents/claude-code/skills/site-reliability-engineer/SKILL.md +1 -0
- package/src/templates/agents/claude-code/skills/site-reliability-engineer/incident-response-template.md +55 -25
- package/src/templates/agents/claude-code/skills/site-reliability-engineer/observability-patterns.md +78 -68
- package/src/templates/agents/claude-code/skills/site-reliability-engineer/slo-sli-guide.md +73 -53
- package/src/templates/agents/claude-code/skills/software-developer/solid-principles.md +83 -37
- package/src/templates/agents/claude-code/skills/software-developer/test-first-workflow.md +38 -31
- package/src/templates/agents/claude-code/skills/steering/SKILL.md +1 -0
- package/src/templates/agents/claude-code/skills/steering/auto-update-rules.md +31 -0
- package/src/templates/agents/claude-code/skills/system-architect/adr-template.md +25 -7
- package/src/templates/agents/claude-code/skills/system-architect/c4-model-guide.md +74 -61
- package/src/templates/agents/claude-code/skills/technical-writer/doc-templates/documentation-templates.md +70 -52
- package/src/templates/agents/claude-code/skills/test-engineer/SKILL.md +2 -0
- package/src/templates/agents/claude-code/skills/test-engineer/ears-test-mapping.md +75 -71
- package/src/templates/agents/claude-code/skills/test-engineer/test-types.md +85 -63
- package/src/templates/agents/claude-code/skills/traceability-auditor/coverage-matrix-template.md +39 -36
- package/src/templates/agents/claude-code/skills/traceability-auditor/gap-detection-rules.md +22 -17
- package/src/templates/agents/claude-code/skills/ui-ux-designer/SKILL.md +1 -0
- package/src/templates/agents/claude-code/skills/ui-ux-designer/accessibility-guidelines.md +49 -75
- package/src/templates/agents/claude-code/skills/ui-ux-designer/design-system-components.md +71 -59
- package/src/templates/agents/codex/AGENTS.md +74 -42
- package/src/templates/agents/cursor/AGENTS.md +74 -42
- package/src/templates/agents/gemini-cli/GEMINI.md +74 -42
- package/src/templates/agents/github-copilot/AGENTS.md +83 -51
- package/src/templates/agents/qwen-code/QWEN.md +74 -42
- package/src/templates/agents/windsurf/AGENTS.md +74 -42
- package/src/templates/architectures/README.md +41 -0
- package/src/templates/architectures/clean-architecture/README.md +113 -0
- package/src/templates/architectures/event-driven/README.md +162 -0
- package/src/templates/architectures/hexagonal/README.md +130 -0
- package/src/templates/index.js +6 -1
- package/src/templates/locale-manager.js +16 -16
- package/src/templates/shared/delta-spec-template.md +20 -13
- package/src/templates/shared/github-actions/musubi-issue-resolver.yml +5 -5
- package/src/templates/shared/github-actions/musubi-security-check.yml +3 -3
- package/src/templates/shared/github-actions/musubi-validate.yml +4 -4
- package/src/templates/shared/steering/structure.md +95 -0
- package/src/templates/skills/browser-agent.md +21 -16
- package/src/templates/skills/web-gui.md +8 -0
- package/src/templates/template-constraints.js +50 -53
- package/src/validators/advanced-validation.js +30 -36
- package/src/validators/constitutional-validator.js +77 -73
- package/src/validators/critic-system.js +49 -59
- package/src/validators/delta-format.js +59 -55
- package/src/validators/traceability-validator.js +7 -11
|
@@ -8,7 +8,12 @@
|
|
|
8
8
|
'use strict';
|
|
9
9
|
|
|
10
10
|
const EventEmitter = require('events');
|
|
11
|
-
const {
|
|
11
|
+
const {
|
|
12
|
+
_ReplanTrigger,
|
|
13
|
+
ReplanDecision,
|
|
14
|
+
mergeConfig,
|
|
15
|
+
_defaultReplanningConfig,
|
|
16
|
+
} = require('./config');
|
|
12
17
|
const { PlanMonitor } = require('./plan-monitor');
|
|
13
18
|
const { PlanEvaluator } = require('./plan-evaluator');
|
|
14
19
|
const { AlternativeGenerator } = require('./alternative-generator');
|
|
@@ -26,26 +31,26 @@ class ReplanningEngine extends EventEmitter {
|
|
|
26
31
|
*/
|
|
27
32
|
constructor(orchestrationEngine = null, options = {}) {
|
|
28
33
|
super();
|
|
29
|
-
|
|
34
|
+
|
|
30
35
|
this.engine = orchestrationEngine;
|
|
31
36
|
this.config = mergeConfig(options.config || options);
|
|
32
|
-
|
|
37
|
+
|
|
33
38
|
// Initialize components
|
|
34
39
|
this.llmProvider = options.llmProvider || this.createLLMProvider();
|
|
35
40
|
this.monitor = new PlanMonitor({ config: this.config });
|
|
36
41
|
this.evaluator = new PlanEvaluator({ config: this.config.evaluation });
|
|
37
42
|
this.generator = new AlternativeGenerator(this.llmProvider, {
|
|
38
43
|
config: this.config.alternatives,
|
|
39
|
-
scorerConfig: this.config.evaluation
|
|
44
|
+
scorerConfig: this.config.evaluation,
|
|
40
45
|
});
|
|
41
46
|
this.history = new ReplanHistory({ config: this.config.history });
|
|
42
|
-
|
|
47
|
+
|
|
43
48
|
// State
|
|
44
49
|
this.currentPlan = null;
|
|
45
50
|
this.planVersion = 0;
|
|
46
51
|
this.isExecuting = false;
|
|
47
52
|
this.executionContext = null;
|
|
48
|
-
|
|
53
|
+
|
|
49
54
|
// Wire up monitor events
|
|
50
55
|
this.setupMonitorEvents();
|
|
51
56
|
}
|
|
@@ -63,13 +68,13 @@ class ReplanningEngine extends EventEmitter {
|
|
|
63
68
|
console.warn('Failed to create LLM provider:', error.message);
|
|
64
69
|
// Return a mock provider that warns on use
|
|
65
70
|
return {
|
|
66
|
-
complete: async () => {
|
|
67
|
-
throw new Error('No LLM provider available for replanning');
|
|
71
|
+
complete: async () => {
|
|
72
|
+
throw new Error('No LLM provider available for replanning');
|
|
68
73
|
},
|
|
69
|
-
completeJSON: async () => {
|
|
70
|
-
throw new Error('No LLM provider available for replanning');
|
|
74
|
+
completeJSON: async () => {
|
|
75
|
+
throw new Error('No LLM provider available for replanning');
|
|
71
76
|
},
|
|
72
|
-
isAvailable: async () => false
|
|
77
|
+
isAvailable: async () => false,
|
|
73
78
|
};
|
|
74
79
|
}
|
|
75
80
|
}
|
|
@@ -79,11 +84,11 @@ class ReplanningEngine extends EventEmitter {
|
|
|
79
84
|
* @private
|
|
80
85
|
*/
|
|
81
86
|
setupMonitorEvents() {
|
|
82
|
-
this.monitor.on('trigger', async
|
|
87
|
+
this.monitor.on('trigger', async trigger => {
|
|
83
88
|
if (this.config.integration?.emitEvents) {
|
|
84
89
|
this.emit(`${this.config.integration.eventPrefix}:trigger`, trigger);
|
|
85
90
|
}
|
|
86
|
-
|
|
91
|
+
|
|
87
92
|
// Handle the trigger
|
|
88
93
|
try {
|
|
89
94
|
await this.handleTrigger(trigger);
|
|
@@ -108,7 +113,7 @@ class ReplanningEngine extends EventEmitter {
|
|
|
108
113
|
this.currentPlan = this.normalizePlan(plan);
|
|
109
114
|
this.planVersion = 0;
|
|
110
115
|
this.isExecuting = true;
|
|
111
|
-
|
|
116
|
+
|
|
112
117
|
// Initialize execution context
|
|
113
118
|
this.executionContext = {
|
|
114
119
|
planId: this.currentPlan.id,
|
|
@@ -116,30 +121,26 @@ class ReplanningEngine extends EventEmitter {
|
|
|
116
121
|
completed: [],
|
|
117
122
|
pending: [...(this.currentPlan.tasks || [])],
|
|
118
123
|
failed: [],
|
|
119
|
-
retries: 0
|
|
124
|
+
retries: 0,
|
|
120
125
|
};
|
|
121
126
|
|
|
122
127
|
// Record initial snapshot
|
|
123
|
-
this.history.recordSnapshot(
|
|
124
|
-
this.currentPlan.id,
|
|
125
|
-
this.currentPlan,
|
|
126
|
-
'Initial plan'
|
|
127
|
-
);
|
|
128
|
+
this.history.recordSnapshot(this.currentPlan.id, this.currentPlan, 'Initial plan');
|
|
128
129
|
|
|
129
130
|
// Start monitoring
|
|
130
131
|
this.monitor.watch(this.currentPlan.id, {
|
|
131
132
|
plan: this.currentPlan,
|
|
132
133
|
tasks: this.currentPlan.tasks,
|
|
133
|
-
...this.executionContext
|
|
134
|
+
...this.executionContext,
|
|
134
135
|
});
|
|
135
136
|
|
|
136
137
|
try {
|
|
137
138
|
// Execute with replanning loop
|
|
138
139
|
const result = await this.executeLoop(options);
|
|
139
|
-
|
|
140
|
+
|
|
140
141
|
this.isExecuting = false;
|
|
141
142
|
this.monitor.unwatch(this.currentPlan.id);
|
|
142
|
-
|
|
143
|
+
|
|
143
144
|
return result;
|
|
144
145
|
} catch (error) {
|
|
145
146
|
this.isExecuting = false;
|
|
@@ -157,55 +158,54 @@ class ReplanningEngine extends EventEmitter {
|
|
|
157
158
|
async executeLoop(options) {
|
|
158
159
|
while (this.executionContext.pending.length > 0 && this.isExecuting) {
|
|
159
160
|
const task = this.executionContext.pending.shift();
|
|
160
|
-
|
|
161
|
+
|
|
161
162
|
try {
|
|
162
163
|
// Execute task
|
|
163
164
|
const result = await this.executeTask(task, options);
|
|
164
|
-
|
|
165
|
+
|
|
165
166
|
// Record success
|
|
166
167
|
this.executionContext.completed.push({
|
|
167
168
|
...task,
|
|
168
169
|
result,
|
|
169
170
|
duration: result.duration,
|
|
170
|
-
completedAt: Date.now()
|
|
171
|
+
completedAt: Date.now(),
|
|
171
172
|
});
|
|
172
|
-
|
|
173
|
+
|
|
173
174
|
// Report to monitor
|
|
174
175
|
this.monitor.reportResult(this.currentPlan.id, {
|
|
175
176
|
taskId: task.id,
|
|
176
177
|
status: 'success',
|
|
177
|
-
output: result
|
|
178
|
+
output: result,
|
|
178
179
|
});
|
|
179
|
-
|
|
180
|
+
|
|
180
181
|
// Record in evaluator
|
|
181
182
|
this.evaluator.recordExecution(task.skill || task.name, {
|
|
182
183
|
success: true,
|
|
183
|
-
duration: result.duration
|
|
184
|
+
duration: result.duration,
|
|
184
185
|
});
|
|
185
|
-
|
|
186
186
|
} catch (error) {
|
|
187
187
|
// Record failure
|
|
188
188
|
const failedTask = {
|
|
189
189
|
...task,
|
|
190
190
|
error,
|
|
191
191
|
failedAt: Date.now(),
|
|
192
|
-
attempts: (task.attempts || 0) + 1
|
|
192
|
+
attempts: (task.attempts || 0) + 1,
|
|
193
193
|
};
|
|
194
194
|
this.executionContext.failed.push(failedTask);
|
|
195
|
-
|
|
195
|
+
|
|
196
196
|
// Report to monitor (may trigger replanning)
|
|
197
197
|
const trigger = this.monitor.reportResult(this.currentPlan.id, {
|
|
198
198
|
taskId: task.id,
|
|
199
199
|
status: 'failed',
|
|
200
|
-
error
|
|
200
|
+
error,
|
|
201
201
|
});
|
|
202
|
-
|
|
202
|
+
|
|
203
203
|
// Record in evaluator
|
|
204
204
|
this.evaluator.recordExecution(task.skill || task.name, {
|
|
205
205
|
success: false,
|
|
206
|
-
duration: Date.now() - (task.startTime || Date.now())
|
|
206
|
+
duration: Date.now() - (task.startTime || Date.now()),
|
|
207
207
|
});
|
|
208
|
-
|
|
208
|
+
|
|
209
209
|
// If trigger was detected, wait for replanning to complete
|
|
210
210
|
if (trigger) {
|
|
211
211
|
// Replanning is handled by trigger event
|
|
@@ -227,18 +227,18 @@ class ReplanningEngine extends EventEmitter {
|
|
|
227
227
|
*/
|
|
228
228
|
async executeTask(task, options) {
|
|
229
229
|
task.startTime = Date.now();
|
|
230
|
-
|
|
230
|
+
|
|
231
231
|
if (this.engine) {
|
|
232
232
|
// Delegate to orchestration engine
|
|
233
233
|
return this.engine.executeSkill(task.skill || task.name, task.parameters, options);
|
|
234
234
|
}
|
|
235
|
-
|
|
235
|
+
|
|
236
236
|
// Mock execution for testing
|
|
237
237
|
await new Promise(resolve => setTimeout(resolve, 100));
|
|
238
238
|
return {
|
|
239
239
|
success: true,
|
|
240
240
|
duration: Date.now() - task.startTime,
|
|
241
|
-
output: `Executed ${task.skill || task.name}
|
|
241
|
+
output: `Executed ${task.skill || task.name}`,
|
|
242
242
|
};
|
|
243
243
|
}
|
|
244
244
|
|
|
@@ -250,16 +250,16 @@ class ReplanningEngine extends EventEmitter {
|
|
|
250
250
|
*/
|
|
251
251
|
async handleTrigger(trigger) {
|
|
252
252
|
const failedTask = this.executionContext.failed[this.executionContext.failed.length - 1];
|
|
253
|
-
|
|
253
|
+
|
|
254
254
|
// Generate alternatives
|
|
255
255
|
const alternatives = await this.generator.generateAlternatives(
|
|
256
256
|
failedTask,
|
|
257
257
|
this.executionContext
|
|
258
258
|
);
|
|
259
|
-
|
|
259
|
+
|
|
260
260
|
// Select best alternative or request human input
|
|
261
261
|
const decision = await this.selectAlternative(alternatives, trigger);
|
|
262
|
-
|
|
262
|
+
|
|
263
263
|
// Record the replan event
|
|
264
264
|
const event = this.history.record({
|
|
265
265
|
trigger: trigger.type,
|
|
@@ -269,29 +269,31 @@ class ReplanningEngine extends EventEmitter {
|
|
|
269
269
|
id: failedTask.id,
|
|
270
270
|
name: failedTask.name,
|
|
271
271
|
skill: failedTask.skill,
|
|
272
|
-
error: failedTask.error?.message
|
|
272
|
+
error: failedTask.error?.message,
|
|
273
273
|
},
|
|
274
274
|
alternatives: alternatives.map(a => ({
|
|
275
275
|
id: a.id,
|
|
276
276
|
description: a.description,
|
|
277
|
-
confidence: a.confidence
|
|
277
|
+
confidence: a.confidence,
|
|
278
278
|
})),
|
|
279
|
-
selectedAlternative: decision.alternative
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
279
|
+
selectedAlternative: decision.alternative
|
|
280
|
+
? {
|
|
281
|
+
id: decision.alternative.id,
|
|
282
|
+
description: decision.alternative.description,
|
|
283
|
+
confidence: decision.alternative.confidence,
|
|
284
|
+
reasoning: decision.alternative.reasoning,
|
|
285
|
+
}
|
|
286
|
+
: null,
|
|
285
287
|
context: {
|
|
286
288
|
completedCount: this.executionContext.completed.length,
|
|
287
289
|
pendingCount: this.executionContext.pending.length,
|
|
288
|
-
failedCount: this.executionContext.failed.length
|
|
289
|
-
}
|
|
290
|
+
failedCount: this.executionContext.failed.length,
|
|
291
|
+
},
|
|
290
292
|
});
|
|
291
|
-
|
|
293
|
+
|
|
292
294
|
// Apply the decision
|
|
293
295
|
await this.applyDecision(decision, trigger);
|
|
294
|
-
|
|
296
|
+
|
|
295
297
|
// Emit replan event
|
|
296
298
|
this.emit('replan', { event, decision, alternatives });
|
|
297
299
|
}
|
|
@@ -307,17 +309,17 @@ class ReplanningEngine extends EventEmitter {
|
|
|
307
309
|
// Check if human approval is always required for this trigger
|
|
308
310
|
const alwaysApprove = this.config.humanInLoop?.alwaysApprove || [];
|
|
309
311
|
const requiresApproval = alwaysApprove.includes(trigger.type);
|
|
310
|
-
|
|
312
|
+
|
|
311
313
|
if (alternatives.length === 0) {
|
|
312
314
|
return {
|
|
313
315
|
type: ReplanDecision.ABORT,
|
|
314
316
|
alternative: null,
|
|
315
|
-
reason: 'No viable alternatives found'
|
|
317
|
+
reason: 'No viable alternatives found',
|
|
316
318
|
};
|
|
317
319
|
}
|
|
318
|
-
|
|
320
|
+
|
|
319
321
|
const bestAlternative = alternatives[0];
|
|
320
|
-
|
|
322
|
+
|
|
321
323
|
// Check if confidence is below threshold
|
|
322
324
|
const threshold = this.config.alternatives?.humanApprovalThreshold || 0.7;
|
|
323
325
|
if (requiresApproval || bestAlternative.confidence < threshold) {
|
|
@@ -325,12 +327,12 @@ class ReplanningEngine extends EventEmitter {
|
|
|
325
327
|
return this.requestHumanApproval(alternatives, trigger);
|
|
326
328
|
}
|
|
327
329
|
}
|
|
328
|
-
|
|
330
|
+
|
|
329
331
|
// Auto-select best alternative
|
|
330
332
|
return {
|
|
331
333
|
type: this.getDecisionType(bestAlternative),
|
|
332
334
|
alternative: bestAlternative,
|
|
333
|
-
reason: `Auto-selected with confidence ${bestAlternative.confidence}
|
|
335
|
+
reason: `Auto-selected with confidence ${bestAlternative.confidence}`,
|
|
334
336
|
};
|
|
335
337
|
}
|
|
336
338
|
|
|
@@ -358,26 +360,26 @@ class ReplanningEngine extends EventEmitter {
|
|
|
358
360
|
* @private
|
|
359
361
|
*/
|
|
360
362
|
async requestHumanApproval(alternatives, trigger) {
|
|
361
|
-
return new Promise(
|
|
363
|
+
return new Promise(resolve => {
|
|
362
364
|
const timeout = this.config.humanInLoop?.timeout || 300000;
|
|
363
|
-
|
|
365
|
+
|
|
364
366
|
// Emit event for human review
|
|
365
367
|
this.emit('replan:review-required', {
|
|
366
368
|
trigger,
|
|
367
369
|
alternatives,
|
|
368
370
|
timeout,
|
|
369
|
-
respond:
|
|
371
|
+
respond: decision => {
|
|
370
372
|
resolve(decision);
|
|
371
|
-
}
|
|
373
|
+
},
|
|
372
374
|
});
|
|
373
|
-
|
|
375
|
+
|
|
374
376
|
// Timeout handling
|
|
375
377
|
setTimeout(() => {
|
|
376
378
|
const defaultAction = this.config.humanInLoop?.defaultOnTimeout || 'abort';
|
|
377
379
|
resolve({
|
|
378
380
|
type: defaultAction === 'abort' ? ReplanDecision.ABORT : ReplanDecision.SKIP,
|
|
379
381
|
alternative: null,
|
|
380
|
-
reason: 'Human approval timeout'
|
|
382
|
+
reason: 'Human approval timeout',
|
|
381
383
|
});
|
|
382
384
|
}, timeout);
|
|
383
385
|
});
|
|
@@ -389,31 +391,32 @@ class ReplanningEngine extends EventEmitter {
|
|
|
389
391
|
* @param {Object} trigger - Original trigger
|
|
390
392
|
* @private
|
|
391
393
|
*/
|
|
392
|
-
async applyDecision(decision,
|
|
394
|
+
async applyDecision(decision, _trigger) {
|
|
393
395
|
const planId = this.currentPlan.id;
|
|
394
|
-
|
|
396
|
+
|
|
395
397
|
switch (decision.type) {
|
|
396
|
-
case ReplanDecision.RETRY:
|
|
398
|
+
case ReplanDecision.RETRY: {
|
|
397
399
|
// Add task back to pending
|
|
398
400
|
const retryTask = {
|
|
399
401
|
...decision.alternative.task,
|
|
400
|
-
attempts: (decision.alternative.task.attempts || 0) + 1
|
|
402
|
+
attempts: (decision.alternative.task.attempts || 0) + 1,
|
|
401
403
|
};
|
|
402
404
|
this.executionContext.pending.unshift(retryTask);
|
|
403
405
|
this.executionContext.retries++;
|
|
404
406
|
break;
|
|
405
|
-
|
|
407
|
+
}
|
|
408
|
+
|
|
406
409
|
case ReplanDecision.REPLACE:
|
|
407
410
|
// Add alternative task to pending
|
|
408
411
|
this.executionContext.pending.unshift(decision.alternative.task);
|
|
409
412
|
this.planVersion++;
|
|
410
413
|
this.history.recordSnapshot(planId, this.currentPlan, 'Task replaced');
|
|
411
414
|
break;
|
|
412
|
-
|
|
415
|
+
|
|
413
416
|
case ReplanDecision.SKIP:
|
|
414
417
|
// Do nothing, task is already removed from pending
|
|
415
418
|
break;
|
|
416
|
-
|
|
419
|
+
|
|
417
420
|
case ReplanDecision.INSERT:
|
|
418
421
|
// Insert new tasks at appropriate position
|
|
419
422
|
if (decision.tasks) {
|
|
@@ -421,26 +424,26 @@ class ReplanningEngine extends EventEmitter {
|
|
|
421
424
|
this.planVersion++;
|
|
422
425
|
}
|
|
423
426
|
break;
|
|
424
|
-
|
|
427
|
+
|
|
425
428
|
case ReplanDecision.ABORT:
|
|
426
429
|
// Stop execution
|
|
427
430
|
this.isExecuting = false;
|
|
428
431
|
break;
|
|
429
|
-
|
|
432
|
+
|
|
430
433
|
case ReplanDecision.HUMAN_REVIEW:
|
|
431
434
|
// Already handled
|
|
432
435
|
break;
|
|
433
|
-
|
|
436
|
+
|
|
434
437
|
default:
|
|
435
438
|
console.warn(`Unknown decision type: ${decision.type}`);
|
|
436
439
|
}
|
|
437
|
-
|
|
440
|
+
|
|
438
441
|
// Update history with outcome
|
|
439
442
|
const lastEvent = this.history.getEvents({ limit: 1, sort: 'desc' })[0];
|
|
440
443
|
if (lastEvent) {
|
|
441
444
|
lastEvent.outcome = {
|
|
442
445
|
success: decision.type !== ReplanDecision.ABORT,
|
|
443
|
-
applied: decision.type
|
|
446
|
+
applied: decision.type,
|
|
444
447
|
};
|
|
445
448
|
}
|
|
446
449
|
}
|
|
@@ -451,11 +454,8 @@ class ReplanningEngine extends EventEmitter {
|
|
|
451
454
|
* @private
|
|
452
455
|
*/
|
|
453
456
|
generateResult() {
|
|
454
|
-
const evaluation = this.evaluator.evaluate(
|
|
455
|
-
|
|
456
|
-
this.executionContext
|
|
457
|
-
);
|
|
458
|
-
|
|
457
|
+
const evaluation = this.evaluator.evaluate(this.currentPlan, this.executionContext);
|
|
458
|
+
|
|
459
459
|
return {
|
|
460
460
|
planId: this.currentPlan.id,
|
|
461
461
|
planVersion: this.planVersion,
|
|
@@ -466,7 +466,7 @@ class ReplanningEngine extends EventEmitter {
|
|
|
466
466
|
evaluation,
|
|
467
467
|
replanCount: this.planVersion,
|
|
468
468
|
history: this.history.getMetrics(),
|
|
469
|
-
duration: Date.now() - this.executionContext.startTime
|
|
469
|
+
duration: Date.now() - this.executionContext.startTime,
|
|
470
470
|
};
|
|
471
471
|
}
|
|
472
472
|
|
|
@@ -484,16 +484,16 @@ class ReplanningEngine extends EventEmitter {
|
|
|
484
484
|
name: task.name || task.skill,
|
|
485
485
|
skill: task.skill || task.name,
|
|
486
486
|
parameters: task.parameters || {},
|
|
487
|
-
dependencies: task.dependencies || []
|
|
487
|
+
dependencies: task.dependencies || [],
|
|
488
488
|
};
|
|
489
489
|
return normalized;
|
|
490
490
|
});
|
|
491
|
-
|
|
491
|
+
|
|
492
492
|
return {
|
|
493
493
|
...plan,
|
|
494
494
|
id: plan.id || `plan-${Date.now()}`,
|
|
495
495
|
version: plan.version || 1,
|
|
496
|
-
tasks: normalizedTasks
|
|
496
|
+
tasks: normalizedTasks,
|
|
497
497
|
};
|
|
498
498
|
}
|
|
499
499
|
|
|
@@ -510,7 +510,7 @@ class ReplanningEngine extends EventEmitter {
|
|
|
510
510
|
}
|
|
511
511
|
return this.engine.execute(plan.pattern || 'sequential', {
|
|
512
512
|
...options,
|
|
513
|
-
tasks: plan.tasks
|
|
513
|
+
tasks: plan.tasks,
|
|
514
514
|
});
|
|
515
515
|
}
|
|
516
516
|
|
|
@@ -523,7 +523,7 @@ class ReplanningEngine extends EventEmitter {
|
|
|
523
523
|
if (!this.isExecuting) {
|
|
524
524
|
throw new Error('Cannot replan when not executing');
|
|
525
525
|
}
|
|
526
|
-
|
|
526
|
+
|
|
527
527
|
this.monitor.requestReplan(this.currentPlan.id, reason);
|
|
528
528
|
}
|
|
529
529
|
|
|
@@ -536,12 +536,12 @@ class ReplanningEngine extends EventEmitter {
|
|
|
536
536
|
if (!this.currentPlan) {
|
|
537
537
|
throw new Error('No active plan');
|
|
538
538
|
}
|
|
539
|
-
|
|
539
|
+
|
|
540
540
|
const normalizedTask = {
|
|
541
541
|
id: task.id || `task-${Date.now()}`,
|
|
542
|
-
...task
|
|
542
|
+
...task,
|
|
543
543
|
};
|
|
544
|
-
|
|
544
|
+
|
|
545
545
|
if (position === 'start') {
|
|
546
546
|
this.executionContext.pending.unshift(normalizedTask);
|
|
547
547
|
} else if (position === 'end') {
|
|
@@ -555,7 +555,7 @@ class ReplanningEngine extends EventEmitter {
|
|
|
555
555
|
this.executionContext.pending.push(normalizedTask);
|
|
556
556
|
}
|
|
557
557
|
}
|
|
558
|
-
|
|
558
|
+
|
|
559
559
|
this.planVersion++;
|
|
560
560
|
this.emit('plan:modified', { action: 'add', task: normalizedTask });
|
|
561
561
|
}
|
|
@@ -569,7 +569,7 @@ class ReplanningEngine extends EventEmitter {
|
|
|
569
569
|
if (!this.currentPlan) {
|
|
570
570
|
throw new Error('No active plan');
|
|
571
571
|
}
|
|
572
|
-
|
|
572
|
+
|
|
573
573
|
const index = this.executionContext.pending.findIndex(t => t.id === taskId);
|
|
574
574
|
if (index !== -1) {
|
|
575
575
|
const removed = this.executionContext.pending.splice(index, 1)[0];
|
|
@@ -577,7 +577,7 @@ class ReplanningEngine extends EventEmitter {
|
|
|
577
577
|
this.emit('plan:modified', { action: 'remove', task: removed });
|
|
578
578
|
return true;
|
|
579
579
|
}
|
|
580
|
-
|
|
580
|
+
|
|
581
581
|
return false;
|
|
582
582
|
}
|
|
583
583
|
|
|
@@ -589,11 +589,9 @@ class ReplanningEngine extends EventEmitter {
|
|
|
589
589
|
if (!this.currentPlan) {
|
|
590
590
|
throw new Error('No active plan');
|
|
591
591
|
}
|
|
592
|
-
|
|
593
|
-
const taskMap = new Map(
|
|
594
|
-
|
|
595
|
-
);
|
|
596
|
-
|
|
592
|
+
|
|
593
|
+
const taskMap = new Map(this.executionContext.pending.map(t => [t.id, t]));
|
|
594
|
+
|
|
597
595
|
const reordered = [];
|
|
598
596
|
for (const id of taskIds) {
|
|
599
597
|
const task = taskMap.get(id);
|
|
@@ -602,10 +600,10 @@ class ReplanningEngine extends EventEmitter {
|
|
|
602
600
|
taskMap.delete(id);
|
|
603
601
|
}
|
|
604
602
|
}
|
|
605
|
-
|
|
603
|
+
|
|
606
604
|
// Add remaining tasks at end
|
|
607
605
|
reordered.push(...taskMap.values());
|
|
608
|
-
|
|
606
|
+
|
|
609
607
|
this.executionContext.pending = reordered;
|
|
610
608
|
this.planVersion++;
|
|
611
609
|
this.emit('plan:modified', { action: 'reorder', order: taskIds });
|
|
@@ -621,7 +619,7 @@ class ReplanningEngine extends EventEmitter {
|
|
|
621
619
|
if (!this.currentPlan) {
|
|
622
620
|
throw new Error('No active plan');
|
|
623
621
|
}
|
|
624
|
-
|
|
622
|
+
|
|
625
623
|
const task = this.executionContext.pending.find(t => t.id === taskId);
|
|
626
624
|
if (task) {
|
|
627
625
|
Object.assign(task, updates);
|
|
@@ -629,7 +627,7 @@ class ReplanningEngine extends EventEmitter {
|
|
|
629
627
|
this.emit('plan:modified', { action: 'modify', taskId, updates });
|
|
630
628
|
return true;
|
|
631
629
|
}
|
|
632
|
-
|
|
630
|
+
|
|
633
631
|
return false;
|
|
634
632
|
}
|
|
635
633
|
|
|
@@ -642,7 +640,7 @@ class ReplanningEngine extends EventEmitter {
|
|
|
642
640
|
return {
|
|
643
641
|
events: this.history.getEvents(filter),
|
|
644
642
|
metrics: this.history.getMetrics(),
|
|
645
|
-
snapshots: this.currentPlan ? this.history.getSnapshots(this.currentPlan.id) : []
|
|
643
|
+
snapshots: this.currentPlan ? this.history.getSnapshots(this.currentPlan.id) : [],
|
|
646
644
|
};
|
|
647
645
|
}
|
|
648
646
|
|
|
@@ -652,11 +650,11 @@ class ReplanningEngine extends EventEmitter {
|
|
|
652
650
|
*/
|
|
653
651
|
getCurrentPlan() {
|
|
654
652
|
if (!this.currentPlan) return null;
|
|
655
|
-
|
|
653
|
+
|
|
656
654
|
return {
|
|
657
655
|
...this.currentPlan,
|
|
658
656
|
version: this.planVersion,
|
|
659
|
-
context: this.executionContext
|
|
657
|
+
context: this.executionContext,
|
|
660
658
|
};
|
|
661
659
|
}
|
|
662
660
|
|