musubi-sdd 5.0.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.
Files changed (232) hide show
  1. package/README.ja.md +106 -48
  2. package/README.md +110 -32
  3. package/bin/musubi-analyze.js +74 -67
  4. package/bin/musubi-browser.js +27 -26
  5. package/bin/musubi-change.js +48 -47
  6. package/bin/musubi-checkpoint.js +10 -7
  7. package/bin/musubi-convert.js +25 -25
  8. package/bin/musubi-costs.js +27 -10
  9. package/bin/musubi-gui.js +52 -46
  10. package/bin/musubi-init.js +1952 -10
  11. package/bin/musubi-orchestrate.js +327 -239
  12. package/bin/musubi-remember.js +69 -56
  13. package/bin/musubi-resolve.js +53 -45
  14. package/bin/musubi-trace.js +51 -22
  15. package/bin/musubi-validate.js +39 -30
  16. package/bin/musubi-workflow.js +33 -34
  17. package/bin/musubi.js +39 -2
  18. package/package.json +1 -1
  19. package/src/agents/agent-loop.js +94 -95
  20. package/src/agents/agentic/code-generator.js +119 -109
  21. package/src/agents/agentic/code-reviewer.js +105 -108
  22. package/src/agents/agentic/index.js +4 -4
  23. package/src/agents/browser/action-executor.js +13 -13
  24. package/src/agents/browser/ai-comparator.js +11 -10
  25. package/src/agents/browser/context-manager.js +6 -6
  26. package/src/agents/browser/index.js +5 -5
  27. package/src/agents/browser/nl-parser.js +31 -46
  28. package/src/agents/browser/screenshot.js +2 -2
  29. package/src/agents/browser/test-generator.js +6 -4
  30. package/src/agents/function-tool.js +71 -65
  31. package/src/agents/index.js +7 -7
  32. package/src/agents/schema-generator.js +98 -94
  33. package/src/analyzers/ast-extractor.js +164 -145
  34. package/src/analyzers/codegraph-auto-update.js +858 -0
  35. package/src/analyzers/complexity-analyzer.js +536 -0
  36. package/src/analyzers/context-optimizer.js +247 -125
  37. package/src/analyzers/impact-analyzer.js +1 -1
  38. package/src/analyzers/large-project-analyzer.js +766 -0
  39. package/src/analyzers/repository-map.js +83 -80
  40. package/src/analyzers/security-analyzer.js +19 -11
  41. package/src/analyzers/stuck-detector.js +19 -17
  42. package/src/converters/index.js +78 -57
  43. package/src/converters/ir/types.js +12 -12
  44. package/src/converters/parsers/musubi-parser.js +134 -126
  45. package/src/converters/parsers/openapi-parser.js +70 -53
  46. package/src/converters/parsers/speckit-parser.js +239 -175
  47. package/src/converters/writers/musubi-writer.js +123 -118
  48. package/src/converters/writers/speckit-writer.js +124 -113
  49. package/src/generators/rust-migration-generator.js +512 -0
  50. package/src/gui/public/index.html +1365 -1211
  51. package/src/gui/server.js +41 -40
  52. package/src/gui/services/file-watcher.js +23 -8
  53. package/src/gui/services/project-scanner.js +26 -20
  54. package/src/gui/services/replanning-service.js +27 -23
  55. package/src/gui/services/traceability-service.js +8 -8
  56. package/src/gui/services/workflow-service.js +14 -7
  57. package/src/index.js +151 -0
  58. package/src/integrations/cicd.js +90 -104
  59. package/src/integrations/codegraph-mcp.js +643 -0
  60. package/src/integrations/documentation.js +142 -103
  61. package/src/integrations/examples.js +95 -80
  62. package/src/integrations/github-client.js +17 -17
  63. package/src/integrations/index.js +5 -5
  64. package/src/integrations/mcp/index.js +21 -21
  65. package/src/integrations/mcp/mcp-context-provider.js +76 -78
  66. package/src/integrations/mcp/mcp-discovery.js +74 -72
  67. package/src/integrations/mcp/mcp-tool-registry.js +99 -94
  68. package/src/integrations/mcp-connector.js +70 -66
  69. package/src/integrations/platforms.js +50 -49
  70. package/src/integrations/tool-discovery.js +37 -31
  71. package/src/llm-providers/anthropic-provider.js +11 -11
  72. package/src/llm-providers/base-provider.js +16 -18
  73. package/src/llm-providers/copilot-provider.js +22 -19
  74. package/src/llm-providers/index.js +26 -25
  75. package/src/llm-providers/ollama-provider.js +11 -11
  76. package/src/llm-providers/openai-provider.js +12 -12
  77. package/src/managers/agent-memory.js +36 -24
  78. package/src/managers/checkpoint-manager.js +4 -8
  79. package/src/managers/delta-spec.js +19 -19
  80. package/src/managers/index.js +13 -4
  81. package/src/managers/memory-condenser.js +35 -45
  82. package/src/managers/repo-skill-manager.js +57 -31
  83. package/src/managers/skill-loader.js +25 -22
  84. package/src/managers/skill-tools.js +36 -72
  85. package/src/managers/workflow.js +30 -22
  86. package/src/monitoring/cost-tracker.js +53 -44
  87. package/src/monitoring/incident-manager.js +123 -103
  88. package/src/monitoring/index.js +144 -134
  89. package/src/monitoring/observability.js +82 -59
  90. package/src/monitoring/quality-dashboard.js +51 -39
  91. package/src/monitoring/release-manager.js +70 -50
  92. package/src/orchestration/agent-skill-binding.js +39 -47
  93. package/src/orchestration/error-handler.js +65 -107
  94. package/src/orchestration/guardrails/base-guardrail.js +26 -24
  95. package/src/orchestration/guardrails/guardrail-rules.js +50 -64
  96. package/src/orchestration/guardrails/index.js +5 -5
  97. package/src/orchestration/guardrails/input-guardrail.js +58 -45
  98. package/src/orchestration/guardrails/output-guardrail.js +104 -81
  99. package/src/orchestration/guardrails/safety-check.js +79 -79
  100. package/src/orchestration/index.js +38 -55
  101. package/src/orchestration/mcp-tool-adapters.js +96 -99
  102. package/src/orchestration/orchestration-engine.js +21 -21
  103. package/src/orchestration/pattern-registry.js +60 -45
  104. package/src/orchestration/patterns/auto.js +34 -47
  105. package/src/orchestration/patterns/group-chat.js +59 -65
  106. package/src/orchestration/patterns/handoff.js +67 -65
  107. package/src/orchestration/patterns/human-in-loop.js +51 -72
  108. package/src/orchestration/patterns/nested.js +25 -40
  109. package/src/orchestration/patterns/sequential.js +35 -34
  110. package/src/orchestration/patterns/swarm.js +63 -56
  111. package/src/orchestration/patterns/triage.js +150 -109
  112. package/src/orchestration/reasoning/index.js +9 -9
  113. package/src/orchestration/reasoning/planning-engine.js +143 -140
  114. package/src/orchestration/reasoning/reasoning-engine.js +206 -144
  115. package/src/orchestration/reasoning/self-correction.js +121 -128
  116. package/src/orchestration/replanning/adaptive-goal-modifier.js +107 -112
  117. package/src/orchestration/replanning/alternative-generator.js +37 -42
  118. package/src/orchestration/replanning/config.js +63 -59
  119. package/src/orchestration/replanning/goal-progress-tracker.js +98 -100
  120. package/src/orchestration/replanning/index.js +24 -20
  121. package/src/orchestration/replanning/plan-evaluator.js +49 -50
  122. package/src/orchestration/replanning/plan-monitor.js +32 -28
  123. package/src/orchestration/replanning/proactive-path-optimizer.js +175 -178
  124. package/src/orchestration/replanning/replan-history.js +33 -26
  125. package/src/orchestration/replanning/replanning-engine.js +106 -108
  126. package/src/orchestration/skill-executor.js +107 -109
  127. package/src/orchestration/skill-registry.js +85 -89
  128. package/src/orchestration/workflow-examples.js +228 -231
  129. package/src/orchestration/workflow-executor.js +65 -68
  130. package/src/orchestration/workflow-orchestrator.js +72 -73
  131. package/src/phase4-integration.js +47 -40
  132. package/src/phase5-integration.js +89 -30
  133. package/src/reporters/coverage-report.js +82 -30
  134. package/src/reporters/hierarchical-reporter.js +498 -0
  135. package/src/reporters/traceability-matrix-report.js +29 -20
  136. package/src/resolvers/issue-resolver.js +43 -31
  137. package/src/steering/advanced-validation.js +133 -124
  138. package/src/steering/auto-updater.js +60 -73
  139. package/src/steering/index.js +6 -6
  140. package/src/steering/quality-metrics.js +41 -35
  141. package/src/steering/steering-auto-update.js +83 -86
  142. package/src/steering/steering-validator.js +98 -106
  143. package/src/steering/template-constraints.js +53 -54
  144. package/src/templates/agents/claude-code/CLAUDE.md +32 -32
  145. package/src/templates/agents/claude-code/skills/agent-assistant/SKILL.md +13 -5
  146. package/src/templates/agents/claude-code/skills/ai-ml-engineer/mlops-guide.md +23 -23
  147. package/src/templates/agents/claude-code/skills/ai-ml-engineer/model-card-template.md +60 -41
  148. package/src/templates/agents/claude-code/skills/api-designer/api-patterns.md +27 -19
  149. package/src/templates/agents/claude-code/skills/api-designer/openapi-template.md +11 -7
  150. package/src/templates/agents/claude-code/skills/bug-hunter/SKILL.md +4 -3
  151. package/src/templates/agents/claude-code/skills/bug-hunter/root-cause-analysis.md +37 -15
  152. package/src/templates/agents/claude-code/skills/change-impact-analyzer/dependency-graph-patterns.md +36 -42
  153. package/src/templates/agents/claude-code/skills/change-impact-analyzer/impact-analysis-template.md +69 -60
  154. package/src/templates/agents/claude-code/skills/cloud-architect/aws-patterns.md +31 -38
  155. package/src/templates/agents/claude-code/skills/cloud-architect/azure-patterns.md +28 -23
  156. package/src/templates/agents/claude-code/skills/code-reviewer/SKILL.md +61 -0
  157. package/src/templates/agents/claude-code/skills/code-reviewer/best-practices.md +27 -0
  158. package/src/templates/agents/claude-code/skills/code-reviewer/review-checklist.md +29 -10
  159. package/src/templates/agents/claude-code/skills/code-reviewer/review-standards.md +29 -24
  160. package/src/templates/agents/claude-code/skills/constitution-enforcer/SKILL.md +8 -6
  161. package/src/templates/agents/claude-code/skills/constitution-enforcer/constitutional-articles.md +62 -26
  162. package/src/templates/agents/claude-code/skills/constitution-enforcer/phase-minus-one-gates.md +35 -16
  163. package/src/templates/agents/claude-code/skills/database-administrator/backup-recovery.md +27 -17
  164. package/src/templates/agents/claude-code/skills/database-administrator/tuning-guide.md +25 -20
  165. package/src/templates/agents/claude-code/skills/database-schema-designer/schema-patterns.md +39 -22
  166. package/src/templates/agents/claude-code/skills/devops-engineer/ci-cd-templates.md +25 -22
  167. package/src/templates/agents/claude-code/skills/issue-resolver/SKILL.md +24 -21
  168. package/src/templates/agents/claude-code/skills/orchestrator/SKILL.md +148 -63
  169. package/src/templates/agents/claude-code/skills/orchestrator/patterns.md +35 -16
  170. package/src/templates/agents/claude-code/skills/orchestrator/selection-matrix.md +69 -64
  171. package/src/templates/agents/claude-code/skills/performance-engineer/optimization-playbook.md +47 -47
  172. package/src/templates/agents/claude-code/skills/performance-optimizer/SKILL.md +69 -0
  173. package/src/templates/agents/claude-code/skills/performance-optimizer/benchmark-template.md +63 -45
  174. package/src/templates/agents/claude-code/skills/performance-optimizer/optimization-patterns.md +33 -35
  175. package/src/templates/agents/claude-code/skills/project-manager/SKILL.md +7 -6
  176. package/src/templates/agents/claude-code/skills/project-manager/agile-ceremonies.md +47 -28
  177. package/src/templates/agents/claude-code/skills/project-manager/project-templates.md +94 -78
  178. package/src/templates/agents/claude-code/skills/quality-assurance/SKILL.md +20 -17
  179. package/src/templates/agents/claude-code/skills/quality-assurance/qa-plan-template.md +63 -49
  180. package/src/templates/agents/claude-code/skills/release-coordinator/SKILL.md +5 -5
  181. package/src/templates/agents/claude-code/skills/release-coordinator/feature-flag-guide.md +30 -26
  182. package/src/templates/agents/claude-code/skills/release-coordinator/release-plan-template.md +67 -35
  183. package/src/templates/agents/claude-code/skills/requirements-analyst/ears-format.md +54 -42
  184. package/src/templates/agents/claude-code/skills/requirements-analyst/validation-rules.md +36 -33
  185. package/src/templates/agents/claude-code/skills/security-auditor/SKILL.md +77 -19
  186. package/src/templates/agents/claude-code/skills/security-auditor/audit-checklists.md +24 -24
  187. package/src/templates/agents/claude-code/skills/security-auditor/owasp-top-10.md +61 -20
  188. package/src/templates/agents/claude-code/skills/security-auditor/vulnerability-patterns.md +43 -11
  189. package/src/templates/agents/claude-code/skills/site-reliability-engineer/SKILL.md +1 -0
  190. package/src/templates/agents/claude-code/skills/site-reliability-engineer/incident-response-template.md +55 -25
  191. package/src/templates/agents/claude-code/skills/site-reliability-engineer/observability-patterns.md +78 -68
  192. package/src/templates/agents/claude-code/skills/site-reliability-engineer/slo-sli-guide.md +73 -53
  193. package/src/templates/agents/claude-code/skills/software-developer/solid-principles.md +83 -37
  194. package/src/templates/agents/claude-code/skills/software-developer/test-first-workflow.md +38 -31
  195. package/src/templates/agents/claude-code/skills/steering/SKILL.md +1 -0
  196. package/src/templates/agents/claude-code/skills/steering/auto-update-rules.md +31 -0
  197. package/src/templates/agents/claude-code/skills/system-architect/adr-template.md +25 -7
  198. package/src/templates/agents/claude-code/skills/system-architect/c4-model-guide.md +74 -61
  199. package/src/templates/agents/claude-code/skills/technical-writer/doc-templates/documentation-templates.md +70 -52
  200. package/src/templates/agents/claude-code/skills/test-engineer/SKILL.md +2 -0
  201. package/src/templates/agents/claude-code/skills/test-engineer/ears-test-mapping.md +75 -71
  202. package/src/templates/agents/claude-code/skills/test-engineer/test-types.md +85 -63
  203. package/src/templates/agents/claude-code/skills/traceability-auditor/coverage-matrix-template.md +39 -36
  204. package/src/templates/agents/claude-code/skills/traceability-auditor/gap-detection-rules.md +22 -17
  205. package/src/templates/agents/claude-code/skills/ui-ux-designer/SKILL.md +1 -0
  206. package/src/templates/agents/claude-code/skills/ui-ux-designer/accessibility-guidelines.md +49 -75
  207. package/src/templates/agents/claude-code/skills/ui-ux-designer/design-system-components.md +71 -59
  208. package/src/templates/agents/codex/AGENTS.md +74 -42
  209. package/src/templates/agents/cursor/AGENTS.md +74 -42
  210. package/src/templates/agents/gemini-cli/GEMINI.md +74 -42
  211. package/src/templates/agents/github-copilot/AGENTS.md +83 -51
  212. package/src/templates/agents/qwen-code/QWEN.md +74 -42
  213. package/src/templates/agents/windsurf/AGENTS.md +74 -42
  214. package/src/templates/architectures/README.md +41 -0
  215. package/src/templates/architectures/clean-architecture/README.md +113 -0
  216. package/src/templates/architectures/event-driven/README.md +162 -0
  217. package/src/templates/architectures/hexagonal/README.md +130 -0
  218. package/src/templates/index.js +6 -1
  219. package/src/templates/locale-manager.js +16 -16
  220. package/src/templates/shared/delta-spec-template.md +20 -13
  221. package/src/templates/shared/github-actions/musubi-issue-resolver.yml +5 -5
  222. package/src/templates/shared/github-actions/musubi-security-check.yml +3 -3
  223. package/src/templates/shared/github-actions/musubi-validate.yml +4 -4
  224. package/src/templates/shared/steering/structure.md +95 -0
  225. package/src/templates/skills/browser-agent.md +21 -16
  226. package/src/templates/skills/web-gui.md +8 -0
  227. package/src/templates/template-constraints.js +50 -53
  228. package/src/validators/advanced-validation.js +30 -36
  229. package/src/validators/constitutional-validator.js +77 -73
  230. package/src/validators/critic-system.js +49 -59
  231. package/src/validators/delta-format.js +59 -55
  232. package/src/validators/traceability-validator.js +7 -11
@@ -22,7 +22,7 @@ class AlternativeGenerator {
22
22
  maxAlternatives: 3,
23
23
  minConfidence: 0.5,
24
24
  includeRetryOption: true,
25
- respectDependencies: true
25
+ respectDependencies: true,
26
26
  };
27
27
  this.contextAnalyzer = new ContextAnalyzer();
28
28
  this.confidenceScorer = new ConfidenceScorer(options.scorerConfig);
@@ -35,7 +35,7 @@ class AlternativeGenerator {
35
35
  * @param {Object} [options={}] - Generation options
36
36
  * @returns {Promise<Alternative[]>} Ranked alternatives
37
37
  */
38
- async generateAlternatives(failedTask, context, options = {}) {
38
+ async generateAlternatives(failedTask, context, _options = {}) {
39
39
  // Analyze context to understand the situation
40
40
  const analysis = await this.analyzeContext(failedTask, context);
41
41
 
@@ -60,9 +60,7 @@ class AlternativeGenerator {
60
60
  const scoredAlternatives = await this.scoreAlternatives(alternatives, context);
61
61
 
62
62
  // Filter by minimum confidence
63
- const filtered = scoredAlternatives.filter(
64
- alt => alt.confidence >= this.config.minConfidence
65
- );
63
+ const filtered = scoredAlternatives.filter(alt => alt.confidence >= this.config.minConfidence);
66
64
 
67
65
  // Limit to max alternatives
68
66
  const limited = filtered.slice(0, this.config.maxAlternatives);
@@ -86,7 +84,7 @@ class AlternativeGenerator {
86
84
  * @param {Object} context - Execution context
87
85
  * @returns {string} Goal description
88
86
  */
89
- extractGoal(task, context) {
87
+ extractGoal(task, _context) {
90
88
  // Try to get goal from task metadata
91
89
  if (task.goal) return task.goal;
92
90
  if (task.description) return task.description;
@@ -112,7 +110,7 @@ class AlternativeGenerator {
112
110
  * @private
113
111
  */
114
112
  buildPrompt(failedTask, context, analysis, goal) {
115
- const errorInfo = failedTask.error
113
+ const errorInfo = failedTask.error
116
114
  ? `Error: ${failedTask.error.message || failedTask.error}`
117
115
  : 'Unknown error';
118
116
 
@@ -168,16 +166,16 @@ Provide your confidence (0.0-1.0) for each alternative based on likelihood of su
168
166
  properties: {
169
167
  name: { type: 'string' },
170
168
  skill: { type: 'string' },
171
- parameters: { type: 'object' }
172
- }
169
+ parameters: { type: 'object' },
170
+ },
173
171
  },
174
172
  confidence: { type: 'number', minimum: 0, maximum: 1 },
175
173
  reasoning: { type: 'string' },
176
- risks: { type: 'array', items: { type: 'string' } }
177
- }
178
- }
179
- }
180
- }
174
+ risks: { type: 'array', items: { type: 'string' } },
175
+ },
176
+ },
177
+ },
178
+ },
181
179
  };
182
180
  }
183
181
 
@@ -189,7 +187,7 @@ Provide your confidence (0.0-1.0) for each alternative based on likelihood of su
189
187
  * @returns {Alternative[]} Processed alternatives
190
188
  * @private
191
189
  */
192
- processLLMResponse(response, failedTask, context) {
190
+ processLLMResponse(response, failedTask, _context) {
193
191
  if (!response || !response.alternatives) {
194
192
  return [];
195
193
  }
@@ -202,14 +200,14 @@ Provide your confidence (0.0-1.0) for each alternative based on likelihood of su
202
200
  name: alt.task?.name || failedTask.name,
203
201
  skill: alt.task?.skill || failedTask.skill,
204
202
  parameters: alt.task?.parameters || failedTask.parameters,
205
- originalTaskId: failedTask.id
203
+ originalTaskId: failedTask.id,
206
204
  },
207
205
  confidence: alt.confidence || 0.5,
208
206
  llmConfidence: alt.confidence || 0.5,
209
207
  reasoning: alt.reasoning || '',
210
208
  risks: alt.risks || [],
211
209
  source: 'llm',
212
- analysisContext: response.analysis
210
+ analysisContext: response.analysis,
213
211
  }));
214
212
  }
215
213
 
@@ -226,13 +224,13 @@ Provide your confidence (0.0-1.0) for each alternative based on likelihood of su
226
224
  task: {
227
225
  ...failedTask,
228
226
  id: `${failedTask.id || 'task'}-retry`,
229
- retryOf: failedTask.id
227
+ retryOf: failedTask.id,
230
228
  },
231
229
  confidence: 0.3, // Low initial confidence for retries
232
230
  llmConfidence: 0.3,
233
231
  reasoning: 'Retry the failed task - may succeed on transient errors',
234
232
  risks: ['May fail with same error', 'Time cost if error persists'],
235
- source: 'system'
233
+ source: 'system',
236
234
  };
237
235
  }
238
236
 
@@ -245,12 +243,12 @@ Provide your confidence (0.0-1.0) for each alternative based on likelihood of su
245
243
  */
246
244
  async scoreAlternatives(alternatives, context) {
247
245
  const scored = await Promise.all(
248
- alternatives.map(async (alt) => {
246
+ alternatives.map(async alt => {
249
247
  const score = await this.confidenceScorer.score(alt, context);
250
248
  return {
251
249
  ...alt,
252
250
  confidence: score.overall,
253
- confidenceBreakdown: score
251
+ confidenceBreakdown: score,
254
252
  };
255
253
  })
256
254
  );
@@ -286,8 +284,8 @@ class ContextAnalyzer {
286
284
  failureContext: {
287
285
  error: failedTask.error,
288
286
  attemptCount: failedTask.attempts || 1,
289
- lastAttemptTime: failedTask.lastAttemptTime || Date.now()
290
- }
287
+ lastAttemptTime: failedTask.lastAttemptTime || Date.now(),
288
+ },
291
289
  };
292
290
  }
293
291
 
@@ -300,10 +298,7 @@ class ContextAnalyzer {
300
298
  extractAvailableSkills(context) {
301
299
  if (context.skills) return Object.keys(context.skills);
302
300
  if (context.registry) return context.registry.getSkillNames();
303
- return [
304
- 'analyze', 'generate', 'validate', 'implement',
305
- 'test', 'review', 'document', 'deploy'
306
- ];
301
+ return ['analyze', 'generate', 'validate', 'implement', 'test', 'review', 'document', 'deploy'];
307
302
  }
308
303
 
309
304
  /**
@@ -316,11 +311,11 @@ class ContextAnalyzer {
316
311
  extractDependencies(task, context) {
317
312
  const taskDeps = task.dependencies || [];
318
313
  const completedIds = (context.completed || []).map(t => t.id);
319
-
314
+
320
315
  return {
321
316
  required: taskDeps,
322
317
  satisfied: taskDeps.filter(d => completedIds.includes(d)),
323
- unsatisfied: taskDeps.filter(d => !completedIds.includes(d))
318
+ unsatisfied: taskDeps.filter(d => !completedIds.includes(d)),
324
319
  };
325
320
  }
326
321
 
@@ -333,10 +328,10 @@ class ContextAnalyzer {
333
328
  extractResources(context) {
334
329
  return {
335
330
  concurrency: context.maxConcurrency || 5,
336
- timeRemaining: context.timeout
331
+ timeRemaining: context.timeout
337
332
  ? context.timeout - (Date.now() - (context.startTime || Date.now()))
338
333
  : null,
339
- memoryAvailable: true
334
+ memoryAvailable: true,
340
335
  };
341
336
  }
342
337
  }
@@ -354,7 +349,7 @@ class ConfidenceScorer {
354
349
  llm: config.llmWeight || 0.4,
355
350
  history: config.historyWeight || 0.3,
356
351
  resource: config.resourceWeight || 0.2,
357
- complexity: config.complexityWeight || 0.1
352
+ complexity: config.complexityWeight || 0.1,
358
353
  };
359
354
  this.history = new Map();
360
355
  }
@@ -379,7 +374,7 @@ class ConfidenceScorer {
379
374
  const complexityScore = this.getComplexityScore(alternative);
380
375
 
381
376
  // Weighted combination
382
- const overall =
377
+ const overall =
383
378
  llmScore * this.weights.llm +
384
379
  historyScore * this.weights.history +
385
380
  resourceScore * this.weights.resource +
@@ -391,8 +386,8 @@ class ConfidenceScorer {
391
386
  llm: Math.round(llmScore * 100) / 100,
392
387
  history: Math.round(historyScore * 100) / 100,
393
388
  resource: Math.round(resourceScore * 100) / 100,
394
- complexity: Math.round(complexityScore * 100) / 100
395
- }
389
+ complexity: Math.round(complexityScore * 100) / 100,
390
+ },
396
391
  };
397
392
  }
398
393
 
@@ -417,7 +412,7 @@ class ConfidenceScorer {
417
412
  */
418
413
  getResourceScore(alternative, context) {
419
414
  let score = 1.0;
420
-
415
+
421
416
  // Check time constraints
422
417
  if (context.resources?.timeRemaining != null) {
423
418
  const estimatedTime = alternative.estimatedTime || 30000;
@@ -445,12 +440,12 @@ class ConfidenceScorer {
445
440
  */
446
441
  getComplexityScore(alternative) {
447
442
  let complexity = 0;
448
-
443
+
449
444
  // More risks = lower score
450
445
  if (alternative.risks) {
451
446
  complexity += alternative.risks.length * 0.1;
452
447
  }
453
-
448
+
454
449
  // More parameters = slightly lower score
455
450
  const params = alternative.task.parameters || {};
456
451
  complexity += Object.keys(params).length * 0.02;
@@ -501,8 +496,8 @@ class ConfidenceScorer {
501
496
  * @property {Object} components - Component scores
502
497
  */
503
498
 
504
- module.exports = {
505
- AlternativeGenerator,
506
- ContextAnalyzer,
507
- ConfidenceScorer
499
+ module.exports = {
500
+ AlternativeGenerator,
501
+ ContextAnalyzer,
502
+ ConfidenceScorer,
508
503
  };
@@ -13,24 +13,24 @@
13
13
  const ReplanTrigger = {
14
14
  /** Task execution failed */
15
15
  TASK_FAILED: 'task-failed',
16
-
16
+
17
17
  /** Task execution timed out */
18
18
  TIMEOUT: 'timeout',
19
-
19
+
20
20
  /** Context or requirements changed */
21
21
  CONTEXT_CHANGED: 'context-changed',
22
-
22
+
23
23
  /** A more efficient path was discovered */
24
24
  BETTER_PATH_FOUND: 'better-path-found',
25
-
25
+
26
26
  /** Human operator requested replanning */
27
27
  HUMAN_REQUEST: 'human-request',
28
-
28
+
29
29
  /** Goal determined to be unreachable with current approach */
30
30
  GOAL_UNREACHABLE: 'goal-unreachable',
31
-
31
+
32
32
  /** Resource constraints changed */
33
- RESOURCE_CHANGED: 'resource-changed'
33
+ RESOURCE_CHANGED: 'resource-changed',
34
34
  };
35
35
 
36
36
  /**
@@ -40,30 +40,30 @@ const ReplanTrigger = {
40
40
  const ReplanDecision = {
41
41
  /** Continue with current plan */
42
42
  CONTINUE: 'continue',
43
-
43
+
44
44
  /** Retry the failed task */
45
45
  RETRY: 'retry',
46
-
46
+
47
47
  /** Skip the failed task */
48
48
  SKIP: 'skip',
49
-
49
+
50
50
  /** Replace task with alternative */
51
51
  REPLACE: 'replace',
52
-
52
+
53
53
  /** Insert new tasks into plan */
54
54
  INSERT: 'insert',
55
-
55
+
56
56
  /** Remove tasks from plan */
57
57
  REMOVE: 'remove',
58
-
58
+
59
59
  /** Reorder remaining tasks */
60
60
  REORDER: 'reorder',
61
-
61
+
62
62
  /** Abort execution */
63
63
  ABORT: 'abort',
64
-
64
+
65
65
  /** Request human intervention */
66
- HUMAN_REVIEW: 'human-review'
66
+ HUMAN_REVIEW: 'human-review',
67
67
  };
68
68
 
69
69
  /**
@@ -85,30 +85,30 @@ const defaultReplanningConfig = {
85
85
  * @type {string}
86
86
  */
87
87
  provider: 'auto',
88
-
88
+
89
89
  /**
90
90
  * Model override (optional)
91
91
  * @type {string|null}
92
92
  */
93
93
  model: null,
94
-
94
+
95
95
  /**
96
96
  * Maximum tokens for LLM response
97
97
  * @type {number}
98
98
  */
99
99
  maxTokens: 2048,
100
-
100
+
101
101
  /**
102
102
  * Temperature for LLM generation
103
103
  * @type {number}
104
104
  */
105
105
  temperature: 0.7,
106
-
106
+
107
107
  /**
108
108
  * Timeout for LLM requests in milliseconds
109
109
  * @type {number}
110
110
  */
111
- timeout: 60000
111
+ timeout: 60000,
112
112
  },
113
113
 
114
114
  /**
@@ -123,26 +123,26 @@ const defaultReplanningConfig = {
123
123
  ReplanTrigger.TASK_FAILED,
124
124
  ReplanTrigger.TIMEOUT,
125
125
  ReplanTrigger.CONTEXT_CHANGED,
126
- ReplanTrigger.HUMAN_REQUEST
126
+ ReplanTrigger.HUMAN_REQUEST,
127
127
  ],
128
-
128
+
129
129
  /**
130
130
  * Number of consecutive failures before triggering replanning
131
131
  * @type {number}
132
132
  */
133
133
  failureThreshold: 2,
134
-
134
+
135
135
  /**
136
136
  * Task timeout in milliseconds
137
137
  * @type {number}
138
138
  */
139
139
  taskTimeout: 300000, // 5 minutes
140
-
140
+
141
141
  /**
142
142
  * Enable proactive better-path detection
143
143
  * @type {boolean}
144
144
  */
145
- enableBetterPathDetection: false
145
+ enableBetterPathDetection: false,
146
146
  },
147
147
 
148
148
  /**
@@ -154,30 +154,30 @@ const defaultReplanningConfig = {
154
154
  * @type {number}
155
155
  */
156
156
  maxAlternatives: 3,
157
-
157
+
158
158
  /**
159
159
  * Minimum confidence score to accept an alternative (0.0 - 1.0)
160
160
  * @type {number}
161
161
  */
162
162
  minConfidence: 0.5,
163
-
163
+
164
164
  /**
165
165
  * Confidence threshold requiring human approval
166
166
  * @type {number}
167
167
  */
168
168
  humanApprovalThreshold: 0.7,
169
-
169
+
170
170
  /**
171
171
  * Include original task as fallback option
172
172
  * @type {boolean}
173
173
  */
174
174
  includeRetryOption: true,
175
-
175
+
176
176
  /**
177
177
  * Consider task dependencies when generating alternatives
178
178
  * @type {boolean}
179
179
  */
180
- respectDependencies: true
180
+ respectDependencies: true,
181
181
  },
182
182
 
183
183
  /**
@@ -189,24 +189,24 @@ const defaultReplanningConfig = {
189
189
  * @type {number}
190
190
  */
191
191
  llmWeight: 0.4,
192
-
192
+
193
193
  /**
194
194
  * Weight for historical success rate
195
195
  * @type {number}
196
196
  */
197
197
  historyWeight: 0.3,
198
-
198
+
199
199
  /**
200
200
  * Weight for resource availability
201
201
  * @type {number}
202
202
  */
203
203
  resourceWeight: 0.2,
204
-
204
+
205
205
  /**
206
206
  * Weight for complexity score
207
207
  * @type {number}
208
208
  */
209
- complexityWeight: 0.1
209
+ complexityWeight: 0.1,
210
210
  },
211
211
 
212
212
  /**
@@ -218,30 +218,30 @@ const defaultReplanningConfig = {
218
218
  * @type {boolean}
219
219
  */
220
220
  enabled: true,
221
-
221
+
222
222
  /**
223
223
  * Maximum events to keep in memory
224
224
  * @type {number}
225
225
  */
226
226
  maxEvents: 1000,
227
-
227
+
228
228
  /**
229
229
  * Persist history to file system
230
230
  * @type {boolean}
231
231
  */
232
232
  persist: false,
233
-
233
+
234
234
  /**
235
235
  * History file path (relative to project root)
236
236
  * @type {string}
237
237
  */
238
238
  filePath: 'storage/replanning-history.json',
239
-
239
+
240
240
  /**
241
241
  * Export format for reports
242
242
  * @type {string}
243
243
  */
244
- exportFormat: 'markdown'
244
+ exportFormat: 'markdown',
245
245
  },
246
246
 
247
247
  /**
@@ -253,24 +253,24 @@ const defaultReplanningConfig = {
253
253
  * @type {boolean}
254
254
  */
255
255
  enabled: true,
256
-
256
+
257
257
  /**
258
258
  * Timeout for human response in milliseconds
259
259
  * @type {number}
260
260
  */
261
261
  timeout: 300000, // 5 minutes
262
-
262
+
263
263
  /**
264
264
  * Default action on timeout
265
265
  * @type {string}
266
266
  */
267
267
  defaultOnTimeout: 'abort',
268
-
268
+
269
269
  /**
270
270
  * Always require approval for these trigger types
271
271
  * @type {string[]}
272
272
  */
273
- alwaysApprove: [ReplanTrigger.GOAL_UNREACHABLE]
273
+ alwaysApprove: [ReplanTrigger.GOAL_UNREACHABLE],
274
274
  },
275
275
 
276
276
  /**
@@ -282,19 +282,19 @@ const defaultReplanningConfig = {
282
282
  * @type {string[]}
283
283
  */
284
284
  enabledPatterns: ['swarm', 'sequential', 'workflow'],
285
-
285
+
286
286
  /**
287
287
  * Emit events for replanning actions
288
288
  * @type {boolean}
289
289
  */
290
290
  emitEvents: true,
291
-
291
+
292
292
  /**
293
293
  * Event prefix for replanning events
294
294
  * @type {string}
295
295
  */
296
- eventPrefix: 'replan'
297
- }
296
+ eventPrefix: 'replan',
297
+ },
298
298
  };
299
299
 
300
300
  /**
@@ -315,7 +315,7 @@ function mergeConfig(userConfig = {}) {
315
315
  */
316
316
  function deepMerge(target, source) {
317
317
  const result = { ...target };
318
-
318
+
319
319
  for (const key of Object.keys(source)) {
320
320
  if (source[key] instanceof Object && key in target && target[key] instanceof Object) {
321
321
  result[key] = deepMerge(target[key], source[key]);
@@ -323,7 +323,7 @@ function deepMerge(target, source) {
323
323
  result[key] = source[key];
324
324
  }
325
325
  }
326
-
326
+
327
327
  return result;
328
328
  }
329
329
 
@@ -339,18 +339,22 @@ function validateConfig(config) {
339
339
  if (config.alternatives?.minConfidence < 0 || config.alternatives?.minConfidence > 1) {
340
340
  errors.push('alternatives.minConfidence must be between 0 and 1');
341
341
  }
342
-
343
- if (config.alternatives?.humanApprovalThreshold < 0 || config.alternatives?.humanApprovalThreshold > 1) {
342
+
343
+ if (
344
+ config.alternatives?.humanApprovalThreshold < 0 ||
345
+ config.alternatives?.humanApprovalThreshold > 1
346
+ ) {
344
347
  errors.push('alternatives.humanApprovalThreshold must be between 0 and 1');
345
348
  }
346
349
 
347
350
  // Validate evaluation weights sum to 1
348
351
  const evaluation = config.evaluation || {};
349
- const weightSum = (evaluation.llmWeight || 0) +
350
- (evaluation.historyWeight || 0) +
351
- (evaluation.resourceWeight || 0) +
352
- (evaluation.complexityWeight || 0);
353
-
352
+ const weightSum =
353
+ (evaluation.llmWeight || 0) +
354
+ (evaluation.historyWeight || 0) +
355
+ (evaluation.resourceWeight || 0) +
356
+ (evaluation.complexityWeight || 0);
357
+
354
358
  if (Math.abs(weightSum - 1.0) > 0.01) {
355
359
  errors.push(`Evaluation weights must sum to 1.0, got ${weightSum}`);
356
360
  }
@@ -365,7 +369,7 @@ function validateConfig(config) {
365
369
 
366
370
  return {
367
371
  valid: errors.length === 0,
368
- errors
372
+ errors,
369
373
  };
370
374
  }
371
375
 
@@ -374,5 +378,5 @@ module.exports = {
374
378
  ReplanDecision,
375
379
  defaultReplanningConfig,
376
380
  mergeConfig,
377
- validateConfig
381
+ validateConfig,
378
382
  };