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.
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 +158 -146
  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 +241 -126
  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 +77 -81
  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 +48 -46
  87. package/src/monitoring/incident-manager.js +116 -106
  88. package/src/monitoring/index.js +144 -134
  89. package/src/monitoring/observability.js +75 -62
  90. package/src/monitoring/quality-dashboard.js +45 -41
  91. package/src/monitoring/release-manager.js +63 -53
  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
@@ -1,21 +1,21 @@
1
1
  /**
2
2
  * TriagePattern - Request classification and routing pattern
3
- *
3
+ *
4
4
  * Classifies incoming requests and routes them to specialized agents.
5
5
  * Implements intelligent routing based on intent detection and agent capabilities.
6
- *
6
+ *
7
7
  * @module orchestration/patterns/triage
8
8
  * @version 1.0.0
9
9
  */
10
10
 
11
11
  const { BasePattern } = require('../pattern-registry');
12
- const { ExecutionContext, ExecutionStatus } = require('../orchestration-engine');
13
- const {
14
- HandoffPattern,
15
- HandoffPatternType,
16
- HandoffConfig,
12
+ const { ExecutionContext, _ExecutionStatus } = require('../orchestration-engine');
13
+ const {
14
+ HandoffPattern,
15
+ HandoffPatternType,
16
+ HandoffConfig: _HandoffConfig,
17
17
  EscalationData,
18
- handoff
18
+ handoff,
19
19
  } = require('./handoff');
20
20
 
21
21
  /**
@@ -29,18 +29,18 @@ const TriageCategory = {
29
29
  REFUND: 'refund',
30
30
  GENERAL: 'general',
31
31
  ESCALATION: 'escalation',
32
- UNKNOWN: 'unknown'
32
+ UNKNOWN: 'unknown',
33
33
  };
34
34
 
35
35
  /**
36
36
  * Triage routing strategies
37
37
  */
38
38
  const TriageStrategy = {
39
- KEYWORD: 'keyword', // Keyword-based classification
40
- INTENT: 'intent', // Intent detection
41
- CAPABILITY: 'capability', // Match agent capabilities
42
- HYBRID: 'hybrid', // Combine multiple strategies
43
- LLM: 'llm' // LLM-based classification
39
+ KEYWORD: 'keyword', // Keyword-based classification
40
+ INTENT: 'intent', // Intent detection
41
+ CAPABILITY: 'capability', // Match agent capabilities
42
+ HYBRID: 'hybrid', // Combine multiple strategies
43
+ LLM: 'llm', // LLM-based classification
44
44
  };
45
45
 
46
46
  /**
@@ -62,8 +62,7 @@ class AgentCapability {
62
62
  * Check if agent can handle given category
63
63
  */
64
64
  canHandle(category) {
65
- return this.categories.includes(category) ||
66
- this.categories.includes(TriageCategory.GENERAL);
65
+ return this.categories.includes(category) || this.categories.includes(TriageCategory.GENERAL);
67
66
  }
68
67
 
69
68
  /**
@@ -79,26 +78,26 @@ class AgentCapability {
79
78
  */
80
79
  calculateScore(input, category) {
81
80
  let score = 0;
82
-
81
+
83
82
  // Category match
84
83
  if (this.canHandle(category)) score += 10;
85
-
84
+
86
85
  // Keyword matches
87
- const keywordMatches = this.keywords.filter(kw =>
86
+ const keywordMatches = this.keywords.filter(kw =>
88
87
  input.toLowerCase().includes(kw.toLowerCase())
89
88
  ).length;
90
89
  score += keywordMatches * 2;
91
-
90
+
92
91
  // Priority bonus
93
92
  score += this.priority;
94
-
93
+
95
94
  // Load penalty (prefer less loaded agents)
96
95
  if (this.currentLoad >= this.maxConcurrent) {
97
96
  score -= 100; // Heavy penalty for overloaded agents
98
97
  } else {
99
98
  score -= (this.currentLoad / this.maxConcurrent) * 5;
100
99
  }
101
-
100
+
102
101
  return score;
103
102
  }
104
103
 
@@ -111,7 +110,7 @@ class AgentCapability {
111
110
  description: this.description,
112
111
  priority: this.priority,
113
112
  maxConcurrent: this.maxConcurrent,
114
- currentLoad: this.currentLoad
113
+ currentLoad: this.currentLoad,
115
114
  };
116
115
  }
117
116
  }
@@ -140,7 +139,7 @@ class TriageResult {
140
139
  selectedAgent: this.selectedAgent?.name || this.selectedAgent,
141
140
  alternativeAgents: this.alternativeAgents.map(a => a.name || a),
142
141
  reasoning: this.reasoning,
143
- timestamp: this.timestamp.toISOString()
142
+ timestamp: this.timestamp.toISOString(),
144
143
  };
145
144
  }
146
145
  }
@@ -150,29 +149,75 @@ class TriageResult {
150
149
  */
151
150
  const DEFAULT_KEYWORD_MAPPINGS = {
152
151
  [TriageCategory.BILLING]: [
153
- 'invoice', 'payment', 'charge', 'bill', 'subscription',
154
- 'pricing', 'cost', 'fee', 'receipt', 'transaction'
152
+ 'invoice',
153
+ 'payment',
154
+ 'charge',
155
+ 'bill',
156
+ 'subscription',
157
+ 'pricing',
158
+ 'cost',
159
+ 'fee',
160
+ 'receipt',
161
+ 'transaction',
155
162
  ],
156
163
  [TriageCategory.REFUND]: [
157
- 'refund', 'money back', 'return', 'cancel', 'cancelled',
158
- 'reimbursement', 'credit', 'chargeback'
164
+ 'refund',
165
+ 'money back',
166
+ 'return',
167
+ 'cancel',
168
+ 'cancelled',
169
+ 'reimbursement',
170
+ 'credit',
171
+ 'chargeback',
159
172
  ],
160
173
  [TriageCategory.SUPPORT]: [
161
- 'help', 'issue', 'problem', 'not working', 'error', 'bug',
162
- 'broken', 'fix', 'trouble', 'stuck', 'assistance'
174
+ 'help',
175
+ 'issue',
176
+ 'problem',
177
+ 'not working',
178
+ 'error',
179
+ 'bug',
180
+ 'broken',
181
+ 'fix',
182
+ 'trouble',
183
+ 'stuck',
184
+ 'assistance',
163
185
  ],
164
186
  [TriageCategory.TECHNICAL]: [
165
- 'api', 'code', 'integration', 'developer', 'sdk', 'documentation',
166
- 'endpoint', 'authentication', 'token', 'webhook'
187
+ 'api',
188
+ 'code',
189
+ 'integration',
190
+ 'developer',
191
+ 'sdk',
192
+ 'documentation',
193
+ 'endpoint',
194
+ 'authentication',
195
+ 'token',
196
+ 'webhook',
167
197
  ],
168
198
  [TriageCategory.SALES]: [
169
- 'buy', 'purchase', 'pricing', 'plan', 'upgrade', 'enterprise',
170
- 'demo', 'trial', 'quote', 'discount'
199
+ 'buy',
200
+ 'purchase',
201
+ 'pricing',
202
+ 'plan',
203
+ 'upgrade',
204
+ 'enterprise',
205
+ 'demo',
206
+ 'trial',
207
+ 'quote',
208
+ 'discount',
171
209
  ],
172
210
  [TriageCategory.ESCALATION]: [
173
- 'manager', 'supervisor', 'escalate', 'complaint', 'urgent',
174
- 'unacceptable', 'lawyer', 'legal', 'sue'
175
- ]
211
+ 'manager',
212
+ 'supervisor',
213
+ 'escalate',
214
+ 'complaint',
215
+ 'urgent',
216
+ 'unacceptable',
217
+ 'lawyer',
218
+ 'legal',
219
+ 'sue',
220
+ ],
176
221
  };
177
222
 
178
223
  /**
@@ -191,12 +236,12 @@ class TriagePattern extends BasePattern {
191
236
  'Intent-based agent selection',
192
237
  'Load-balanced request distribution',
193
238
  'Specialized agent dispatch',
194
- 'Escalation handling'
239
+ 'Escalation handling',
195
240
  ],
196
241
  complexity: 'medium',
197
242
  supportsParallel: false,
198
243
  supportsReplanning: true,
199
- requiresHuman: false
244
+ requiresHuman: false,
200
245
  });
201
246
 
202
247
  this.options = {
@@ -208,16 +253,16 @@ class TriagePattern extends BasePattern {
208
253
  enableHandoff: options.enableHandoff !== false,
209
254
  maxRetries: options.maxRetries || 2,
210
255
  llmClassifier: options.llmClassifier || null, // Optional LLM for classification
211
- ...options
256
+ ...options,
212
257
  };
213
258
 
214
259
  // Agent registry with capabilities
215
260
  this.agentRegistry = new Map();
216
-
261
+
217
262
  // Internal handoff pattern for delegation
218
263
  this.handoffPattern = new HandoffPattern({
219
264
  strategy: 'best-match',
220
- maxHandoffs: options.maxHandoffs || 5
265
+ maxHandoffs: options.maxHandoffs || 5,
221
266
  });
222
267
 
223
268
  // Classification history
@@ -231,13 +276,14 @@ class TriagePattern extends BasePattern {
231
276
  * @returns {TriagePattern} This pattern for chaining
232
277
  */
233
278
  registerAgent(agent, capability) {
234
- const cap = capability instanceof AgentCapability
235
- ? capability
236
- : new AgentCapability({ agent, ...capability });
237
-
279
+ const cap =
280
+ capability instanceof AgentCapability
281
+ ? capability
282
+ : new AgentCapability({ agent, ...capability });
283
+
238
284
  const agentName = typeof agent === 'string' ? agent : agent.name;
239
285
  this.agentRegistry.set(agentName, cap);
240
-
286
+
241
287
  return this;
242
288
  }
243
289
 
@@ -265,7 +311,7 @@ class TriagePattern extends BasePattern {
265
311
  * @param {OrchestrationEngine} engine - Orchestration engine
266
312
  * @returns {object} Validation result
267
313
  */
268
- validate(context, engine) {
314
+ validate(context, _engine) {
269
315
  const errors = [];
270
316
  const input = context.input;
271
317
 
@@ -281,7 +327,7 @@ class TriagePattern extends BasePattern {
281
327
 
282
328
  return {
283
329
  valid: errors.length === 0,
284
- errors
330
+ errors,
285
331
  };
286
332
  }
287
333
 
@@ -304,13 +350,11 @@ class TriagePattern extends BasePattern {
304
350
  history = [],
305
351
  agents = [],
306
352
  sharedContext = {},
307
- enableHandoff
353
+ enableHandoff,
308
354
  } = context.input;
309
355
 
310
356
  // Override enableHandoff from input if provided
311
- const shouldHandoff = enableHandoff !== undefined
312
- ? enableHandoff
313
- : this.options.enableHandoff;
357
+ const shouldHandoff = enableHandoff !== undefined ? enableHandoff : this.options.enableHandoff;
314
358
 
315
359
  // Auto-register agents from input if registry is empty
316
360
  if (this.agentRegistry.size === 0 && agents.length > 0) {
@@ -327,30 +371,25 @@ class TriagePattern extends BasePattern {
327
371
  context,
328
372
  inputText: inputText.substring(0, 100),
329
373
  strategy: this.options.strategy,
330
- registeredAgents: this.agentRegistry.size
374
+ registeredAgents: this.agentRegistry.size,
331
375
  });
332
376
 
333
377
  try {
334
378
  // Step 1: Classify the request
335
379
  engine.emit('triage:classifying', {
336
380
  context,
337
- strategy: this.options.strategy
381
+ strategy: this.options.strategy,
338
382
  });
339
383
 
340
384
  const classification = await this.classifyRequest(inputText, context);
341
385
 
342
386
  engine.emit('triage:classified', {
343
387
  context,
344
- classification: classification.toJSON()
388
+ classification: classification.toJSON(),
345
389
  });
346
390
 
347
391
  // Step 2: Select best agent
348
- const selectedAgent = await this.selectAgent(
349
- classification,
350
- inputText,
351
- context,
352
- engine
353
- );
392
+ const selectedAgent = await this.selectAgent(classification, inputText, context, engine);
354
393
 
355
394
  if (!selectedAgent) {
356
395
  // Use fallback agent if available
@@ -368,7 +407,7 @@ class TriagePattern extends BasePattern {
368
407
  this.classificationHistory.push({
369
408
  timestamp: new Date(),
370
409
  input: inputText.substring(0, 200),
371
- classification: classification.toJSON()
410
+ classification: classification.toJSON(),
372
411
  });
373
412
 
374
413
  // Step 4: Perform handoff if enabled
@@ -376,7 +415,7 @@ class TriagePattern extends BasePattern {
376
415
  if (shouldHandoff && classification.selectedAgent) {
377
416
  engine.emit('triage:routing', {
378
417
  context,
379
- targetAgent: this._getAgentName(classification.selectedAgent)
418
+ targetAgent: this._getAgentName(classification.selectedAgent),
380
419
  });
381
420
 
382
421
  result = await this.routeToAgent(
@@ -391,7 +430,7 @@ class TriagePattern extends BasePattern {
391
430
  result = {
392
431
  action: 'classified',
393
432
  classification: classification.toJSON(),
394
- message: 'Request classified but handoff disabled'
433
+ message: 'Request classified but handoff disabled',
395
434
  };
396
435
  }
397
436
 
@@ -402,20 +441,19 @@ class TriagePattern extends BasePattern {
402
441
  context,
403
442
  classification: classification.toJSON(),
404
443
  selectedAgent: this._getAgentName(classification.selectedAgent),
405
- duration: endTime - startTime
444
+ duration: endTime - startTime,
406
445
  });
407
446
 
408
447
  return {
409
448
  success: true,
410
449
  classification: classification.toJSON(),
411
450
  result,
412
- duration: endTime - startTime
451
+ duration: endTime - startTime,
413
452
  };
414
-
415
453
  } catch (error) {
416
454
  engine.emit('triage:failed', {
417
455
  context,
418
- error: error.message
456
+ error: error.message,
419
457
  });
420
458
 
421
459
  throw error;
@@ -478,21 +516,21 @@ class TriagePattern extends BasePattern {
478
516
  }
479
517
 
480
518
  // Calculate confidence based on keyword matches
481
- const totalKeywords = Object.values(this.options.keywordMappings).flat().length;
519
+ const _totalKeywords = Object.values(this.options.keywordMappings).flat().length;
482
520
  const confidence = Math.min(bestScore / 3, 1); // Max confidence after 3 matches
483
521
 
484
522
  return new TriageResult({
485
523
  category: bestCategory,
486
524
  confidence,
487
525
  keywords: matchedKeywords,
488
- reasoning: `Matched ${bestScore} keywords for category ${bestCategory}`
526
+ reasoning: `Matched ${bestScore} keywords for category ${bestCategory}`,
489
527
  });
490
528
  }
491
529
 
492
530
  /**
493
531
  * Classify by intent detection (simple pattern-based)
494
532
  */
495
- _classifyByIntent(inputText, context) {
533
+ _classifyByIntent(inputText, _context) {
496
534
  const intents = [];
497
535
  const lowerText = inputText.toLowerCase();
498
536
 
@@ -515,23 +553,23 @@ class TriagePattern extends BasePattern {
515
553
 
516
554
  // Map intents to categories
517
555
  const intentToCategory = {
518
- 'request_refund': TriageCategory.REFUND,
519
- 'ask_question': TriageCategory.SUPPORT,
520
- 'report_issue': TriageCategory.TECHNICAL,
521
- 'purchase': TriageCategory.SALES,
522
- 'cancel_subscription': TriageCategory.BILLING
556
+ request_refund: TriageCategory.REFUND,
557
+ ask_question: TriageCategory.SUPPORT,
558
+ report_issue: TriageCategory.TECHNICAL,
559
+ purchase: TriageCategory.SALES,
560
+ cancel_subscription: TriageCategory.BILLING,
523
561
  };
524
562
 
525
563
  if (intents.length > 0) {
526
564
  // Sort by confidence
527
565
  intents.sort((a, b) => b.confidence - a.confidence);
528
566
  const topIntent = intents[0];
529
-
567
+
530
568
  return new TriageResult({
531
569
  category: intentToCategory[topIntent.intent] || this.options.defaultCategory,
532
570
  confidence: topIntent.confidence,
533
571
  intents,
534
- reasoning: `Detected intent: ${topIntent.intent} with ${(topIntent.confidence * 100).toFixed(0)}% confidence`
572
+ reasoning: `Detected intent: ${topIntent.intent} with ${(topIntent.confidence * 100).toFixed(0)}% confidence`,
535
573
  });
536
574
  }
537
575
 
@@ -546,7 +584,7 @@ class TriagePattern extends BasePattern {
546
584
  let bestMatch = null;
547
585
  let bestScore = -1;
548
586
 
549
- for (const [agentName, capability] of this.agentRegistry) {
587
+ for (const [_agentName, capability] of this.agentRegistry) {
550
588
  if (capability.matchesKeywords(inputText)) {
551
589
  const score = capability.calculateScore(inputText, null);
552
590
  if (score > bestScore) {
@@ -562,14 +600,14 @@ class TriagePattern extends BasePattern {
562
600
  category,
563
601
  confidence: Math.min(bestScore / 20, 1),
564
602
  selectedAgent: bestMatch.agent,
565
- reasoning: `Best capability match: ${this._getAgentName(bestMatch.agent)} with score ${bestScore.toFixed(2)}`
603
+ reasoning: `Best capability match: ${this._getAgentName(bestMatch.agent)} with score ${bestScore.toFixed(2)}`,
566
604
  });
567
605
  }
568
606
 
569
607
  return new TriageResult({
570
608
  category: this.options.defaultCategory,
571
609
  confidence: 0,
572
- reasoning: 'No agent capability matches found'
610
+ reasoning: 'No agent capability matches found',
573
611
  });
574
612
  }
575
613
 
@@ -596,7 +634,7 @@ Respond with JSON: {"category": "<category>", "confidence": <0-1>, "reasoning":
596
634
  return new TriageResult({
597
635
  category: parsed.category || this.options.defaultCategory,
598
636
  confidence: parsed.confidence || 0.5,
599
- reasoning: parsed.reasoning || 'LLM classification'
637
+ reasoning: parsed.reasoning || 'LLM classification',
600
638
  });
601
639
  } catch (error) {
602
640
  // Fall back to hybrid on LLM failure
@@ -610,27 +648,28 @@ Respond with JSON: {"category": "<category>", "confidence": <0-1>, "reasoning":
610
648
  _classifyHybrid(inputText, context) {
611
649
  // Run keyword classification
612
650
  const keywordResult = this._classifyByKeyword(inputText);
613
-
651
+
614
652
  // Run intent classification
615
653
  const intentResult = this._classifyByIntent(inputText, context);
616
-
654
+
617
655
  // Run capability classification if agents registered
618
- const capabilityResult = this.agentRegistry.size > 0
619
- ? this._classifyByCapability(inputText)
620
- : null;
656
+ const capabilityResult =
657
+ this.agentRegistry.size > 0 ? this._classifyByCapability(inputText) : null;
621
658
 
622
659
  // Combine results with weighted voting
623
660
  const votes = {};
624
-
661
+
625
662
  // Keyword vote (weight: 1)
626
663
  votes[keywordResult.category] = (votes[keywordResult.category] || 0) + keywordResult.confidence;
627
-
664
+
628
665
  // Intent vote (weight: 1.5)
629
- votes[intentResult.category] = (votes[intentResult.category] || 0) + (intentResult.confidence * 1.5);
630
-
666
+ votes[intentResult.category] =
667
+ (votes[intentResult.category] || 0) + intentResult.confidence * 1.5;
668
+
631
669
  // Capability vote (weight: 2) - more weight to direct agent matching
632
670
  if (capabilityResult && capabilityResult.category !== TriageCategory.UNKNOWN) {
633
- votes[capabilityResult.category] = (votes[capabilityResult.category] || 0) + (capabilityResult.confidence * 2);
671
+ votes[capabilityResult.category] =
672
+ (votes[capabilityResult.category] || 0) + capabilityResult.confidence * 2;
634
673
  }
635
674
 
636
675
  // Find winning category
@@ -654,7 +693,7 @@ Respond with JSON: {"category": "<category>", "confidence": <0-1>, "reasoning":
654
693
  keywords: keywordResult.keywords,
655
694
  intents: intentResult.intents,
656
695
  selectedAgent: capabilityResult?.selectedAgent,
657
- reasoning: `Hybrid classification: keyword=${keywordResult.category}, intent=${intentResult.category}, capability=${capabilityResult?.category || 'N/A'}`
696
+ reasoning: `Hybrid classification: keyword=${keywordResult.category}, intent=${intentResult.category}, capability=${capabilityResult?.category || 'N/A'}`,
658
697
  });
659
698
  }
660
699
 
@@ -666,7 +705,7 @@ Respond with JSON: {"category": "<category>", "confidence": <0-1>, "reasoning":
666
705
  * @param {OrchestrationEngine} engine - Orchestration engine
667
706
  * @returns {Promise<Agent|null>} Selected agent or null
668
707
  */
669
- async selectAgent(classification, inputText, context, engine) {
708
+ async selectAgent(classification, inputText, _context, _engine) {
670
709
  // If classification already has selected agent, return it
671
710
  if (classification.selectedAgent) {
672
711
  return classification.selectedAgent;
@@ -675,7 +714,7 @@ Respond with JSON: {"category": "<category>", "confidence": <0-1>, "reasoning":
675
714
  const candidates = [];
676
715
 
677
716
  // Find agents that can handle this category
678
- for (const [agentName, capability] of this.agentRegistry) {
717
+ for (const [_agentName, capability] of this.agentRegistry) {
679
718
  if (capability.canHandle(classification.category)) {
680
719
  const score = capability.calculateScore(inputText, classification.category);
681
720
  candidates.push({ agent: capability.agent, capability, score });
@@ -712,8 +751,8 @@ Respond with JSON: {"category": "<category>", "confidence": <0-1>, "reasoning":
712
751
  sourceAgent: 'triage-agent',
713
752
  context: {
714
753
  classification: classification.toJSON(),
715
- originalInput: inputText.substring(0, 500)
716
- }
754
+ originalInput: inputText.substring(0, 500),
755
+ },
717
756
  });
718
757
 
719
758
  // Create target agents list
@@ -731,10 +770,10 @@ Respond with JSON: {"category": "<category>", "confidence": <0-1>, "reasoning":
731
770
  task: `Route ${classification.category} request to specialized agent`,
732
771
  input: {
733
772
  sourceAgent: 'triage-agent',
734
- targetAgents: targetAgents.map(agent =>
773
+ targetAgents: targetAgents.map(agent =>
735
774
  handoff({
736
775
  agent,
737
- inputFilter: (h) => h // Keep all history for now
776
+ inputFilter: h => h, // Keep all history for now
738
777
  })
739
778
  ),
740
779
  message: inputText,
@@ -742,13 +781,13 @@ Respond with JSON: {"category": "<category>", "confidence": <0-1>, "reasoning":
742
781
  escalationData: escalation,
743
782
  sharedContext: {
744
783
  ...sharedContext,
745
- triageClassification: classification.toJSON()
746
- }
784
+ triageClassification: classification.toJSON(),
785
+ },
747
786
  },
748
787
  metadata: {
749
788
  triageCategory: classification.category,
750
- triageConfidence: classification.confidence
751
- }
789
+ triageConfidence: classification.confidence,
790
+ },
752
791
  });
753
792
 
754
793
  parentContext.children.push(handoffContext);
@@ -772,7 +811,7 @@ Respond with JSON: {"category": "<category>", "confidence": <0-1>, "reasoning":
772
811
  */
773
812
  getStats() {
774
813
  const categoryStats = {};
775
-
814
+
776
815
  for (const record of this.classificationHistory) {
777
816
  const category = record.classification.category;
778
817
  categoryStats[category] = (categoryStats[category] || 0) + 1;
@@ -782,9 +821,11 @@ Respond with JSON: {"category": "<category>", "confidence": <0-1>, "reasoning":
782
821
  totalClassifications: this.classificationHistory.length,
783
822
  registeredAgents: this.agentRegistry.size,
784
823
  categoryDistribution: categoryStats,
785
- averageConfidence: this.classificationHistory.length > 0
786
- ? this.classificationHistory.reduce((sum, r) => sum + r.classification.confidence, 0) / this.classificationHistory.length
787
- : 0
824
+ averageConfidence:
825
+ this.classificationHistory.length > 0
826
+ ? this.classificationHistory.reduce((sum, r) => sum + r.classification.confidence, 0) /
827
+ this.classificationHistory.length
828
+ : 0,
788
829
  };
789
830
  }
790
831
 
@@ -814,5 +855,5 @@ module.exports = {
814
855
  AgentCapability,
815
856
  TriageResult,
816
857
  DEFAULT_KEYWORD_MAPPINGS,
817
- createTriagePattern
858
+ createTriagePattern,
818
859
  };
@@ -6,12 +6,12 @@
6
6
 
7
7
  'use strict';
8
8
 
9
- const {
10
- ReasoningEngine,
11
- createReasoningEngine,
9
+ const {
10
+ ReasoningEngine,
11
+ createReasoningEngine,
12
12
  reason,
13
13
  STRATEGY,
14
- STEP_TYPE
14
+ STEP_TYPE,
15
15
  } = require('./reasoning-engine');
16
16
 
17
17
  const {
@@ -20,7 +20,7 @@ const {
20
20
  createPlan,
21
21
  PLAN_STATUS,
22
22
  TASK_STATUS,
23
- PRIORITY
23
+ PRIORITY,
24
24
  } = require('./planning-engine');
25
25
 
26
26
  const {
@@ -29,7 +29,7 @@ const {
29
29
  correctError,
30
30
  SEVERITY,
31
31
  CORRECTION_STRATEGY,
32
- DEFAULT_PATTERNS
32
+ DEFAULT_PATTERNS,
33
33
  } = require('./self-correction');
34
34
 
35
35
  module.exports = {
@@ -39,7 +39,7 @@ module.exports = {
39
39
  reason,
40
40
  STRATEGY,
41
41
  STEP_TYPE,
42
-
42
+
43
43
  // Planning Engine
44
44
  PlanningEngine,
45
45
  createPlanningEngine,
@@ -47,12 +47,12 @@ module.exports = {
47
47
  PLAN_STATUS,
48
48
  TASK_STATUS,
49
49
  PRIORITY,
50
-
50
+
51
51
  // Self-Correction
52
52
  SelfCorrection,
53
53
  createSelfCorrection,
54
54
  correctError,
55
55
  SEVERITY,
56
56
  CORRECTION_STRATEGY,
57
- DEFAULT_PATTERNS
57
+ DEFAULT_PATTERNS,
58
58
  };