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
@@ -17,7 +17,7 @@ const STRATEGY = {
17
17
  TREE_OF_THOUGHT: 'tree-of-thought',
18
18
  REFLECTION: 'reflection',
19
19
  DECOMPOSITION: 'decomposition',
20
- ANALOGY: 'analogy'
20
+ ANALOGY: 'analogy',
21
21
  };
22
22
 
23
23
  /**
@@ -30,7 +30,7 @@ const STEP_TYPE = {
30
30
  PLAN: 'plan',
31
31
  ACT: 'act',
32
32
  REFLECT: 'reflect',
33
- REFINE: 'refine'
33
+ REFINE: 'refine',
34
34
  };
35
35
 
36
36
  /**
@@ -75,20 +75,20 @@ class ReasoningEngine extends EventEmitter {
75
75
  */
76
76
  constructor(options = {}) {
77
77
  super();
78
-
78
+
79
79
  this.strategy = options.strategy || STRATEGY.CHAIN_OF_THOUGHT;
80
80
  this.maxSteps = options.maxSteps ?? 20;
81
81
  this.minConfidence = options.minConfidence ?? 0.6;
82
82
  this.enableReflection = options.enableReflection ?? true;
83
83
  this.enableBacktracking = options.enableBacktracking ?? true;
84
84
  this.timeout = options.timeout ?? 60000;
85
-
85
+
86
86
  // State
87
87
  this.traces = new Map();
88
88
  this.currentTrace = null;
89
89
  this.stepCounter = 0;
90
90
  }
91
-
91
+
92
92
  /**
93
93
  * Start reasoning about a problem
94
94
  * @param {string} problem - Problem statement
@@ -98,7 +98,7 @@ class ReasoningEngine extends EventEmitter {
98
98
  async reason(problem, context = {}) {
99
99
  const traceId = this.generateId();
100
100
  const startTime = Date.now();
101
-
101
+
102
102
  const trace = {
103
103
  id: traceId,
104
104
  problem,
@@ -106,14 +106,14 @@ class ReasoningEngine extends EventEmitter {
106
106
  steps: [],
107
107
  conclusion: null,
108
108
  successful: false,
109
- totalTime: 0
109
+ totalTime: 0,
110
110
  };
111
-
111
+
112
112
  this.currentTrace = trace;
113
113
  this.traces.set(traceId, trace);
114
-
114
+
115
115
  this.emit('reasoning:start', { traceId, problem, strategy: this.strategy });
116
-
116
+
117
117
  try {
118
118
  // Select reasoning strategy
119
119
  let result;
@@ -136,23 +136,27 @@ class ReasoningEngine extends EventEmitter {
136
136
  default:
137
137
  result = await this.chainOfThought(problem, context);
138
138
  }
139
-
139
+
140
140
  trace.conclusion = result.conclusion;
141
141
  trace.successful = result.successful;
142
-
143
142
  } catch (error) {
144
- this.addStep(STEP_TYPE.REFLECT, `Reasoning failed: ${error.message}`, { error: error.message }, 0);
143
+ this.addStep(
144
+ STEP_TYPE.REFLECT,
145
+ `Reasoning failed: ${error.message}`,
146
+ { error: error.message },
147
+ 0
148
+ );
145
149
  trace.successful = false;
146
150
  }
147
-
151
+
148
152
  trace.totalTime = Date.now() - startTime;
149
153
  this.currentTrace = null;
150
-
154
+
151
155
  this.emit('reasoning:complete', { trace });
152
-
156
+
153
157
  return trace;
154
158
  }
155
-
159
+
156
160
  /**
157
161
  * Chain of Thought reasoning
158
162
  * @private
@@ -160,39 +164,54 @@ class ReasoningEngine extends EventEmitter {
160
164
  async chainOfThought(problem, context) {
161
165
  // Step 1: Observe
162
166
  this.addStep(STEP_TYPE.OBSERVE, `Analyzing problem: ${problem}`, { context }, 0.9);
163
-
167
+
164
168
  // Step 2: Decompose into sub-problems
165
169
  const subProblems = this.decomposeProlem(problem);
166
- this.addStep(STEP_TYPE.THINK, `Identified ${subProblems.length} sub-problems:\n${subProblems.map((p, i) => `${i + 1}. ${p}`).join('\n')}`, { subProblems }, 0.8);
167
-
170
+ this.addStep(
171
+ STEP_TYPE.THINK,
172
+ `Identified ${subProblems.length} sub-problems:\n${subProblems.map((p, i) => `${i + 1}. ${p}`).join('\n')}`,
173
+ { subProblems },
174
+ 0.8
175
+ );
176
+
168
177
  // Step 3: Process each sub-problem
169
178
  const solutions = [];
170
179
  for (const subProblem of subProblems) {
171
180
  this.addStep(STEP_TYPE.THINK, `Working on: ${subProblem}`, {}, 0.7);
172
-
181
+
173
182
  const solution = await this.solveSubProblem(subProblem, context);
174
183
  solutions.push({ problem: subProblem, solution });
175
-
184
+
176
185
  this.addStep(STEP_TYPE.ACT, `Solution: ${solution}`, { subProblem, solution }, 0.8);
177
186
  }
178
-
187
+
179
188
  // Step 4: Synthesize
180
189
  const conclusion = this.synthesize(solutions);
181
- this.addStep(STEP_TYPE.PLAN, `Synthesizing solutions into final answer`, { solutionCount: solutions.length }, 0.85);
182
-
190
+ this.addStep(
191
+ STEP_TYPE.PLAN,
192
+ `Synthesizing solutions into final answer`,
193
+ { solutionCount: solutions.length },
194
+ 0.85
195
+ );
196
+
183
197
  // Step 5: Reflect if enabled
184
198
  if (this.enableReflection) {
185
199
  const reflection = this.reflect(problem, conclusion, solutions);
186
- this.addStep(STEP_TYPE.REFLECT, reflection.content, { confidence: reflection.confidence }, reflection.confidence);
187
-
200
+ this.addStep(
201
+ STEP_TYPE.REFLECT,
202
+ reflection.content,
203
+ { confidence: reflection.confidence },
204
+ reflection.confidence
205
+ );
206
+
188
207
  if (reflection.confidence < this.minConfidence && this.enableBacktracking) {
189
208
  return this.backtrack(problem, context, reflection);
190
209
  }
191
210
  }
192
-
211
+
193
212
  return { conclusion, successful: true };
194
213
  }
195
-
214
+
196
215
  /**
197
216
  * Tree of Thought reasoning - explore multiple paths
198
217
  * @private
@@ -200,43 +219,58 @@ class ReasoningEngine extends EventEmitter {
200
219
  async treeOfThought(problem, context) {
201
220
  const branches = [];
202
221
  const maxBranches = 3;
203
-
222
+
204
223
  this.addStep(STEP_TYPE.OBSERVE, `Exploring multiple reasoning paths for: ${problem}`, {}, 0.9);
205
-
224
+
206
225
  // Generate multiple initial thoughts
207
226
  const initialThoughts = this.generateThoughts(problem, maxBranches);
208
- this.addStep(STEP_TYPE.THINK, `Generated ${initialThoughts.length} reasoning branches`, { branches: initialThoughts }, 0.8);
209
-
227
+ this.addStep(
228
+ STEP_TYPE.THINK,
229
+ `Generated ${initialThoughts.length} reasoning branches`,
230
+ { branches: initialThoughts },
231
+ 0.8
232
+ );
233
+
210
234
  // Explore each branch
211
235
  for (const thought of initialThoughts) {
212
236
  const branch = {
213
237
  thought,
214
238
  steps: [],
215
239
  conclusion: null,
216
- score: 0
240
+ score: 0,
217
241
  };
218
-
242
+
219
243
  this.addStep(STEP_TYPE.PLAN, `Exploring branch: ${thought}`, {}, 0.7);
220
-
244
+
221
245
  // Develop this branch
222
246
  const developed = await this.developBranch(thought, problem, context);
223
247
  branch.steps = developed.steps;
224
248
  branch.conclusion = developed.conclusion;
225
249
  branch.score = this.evaluateBranch(branch);
226
-
250
+
227
251
  branches.push(branch);
228
- this.addStep(STEP_TYPE.REFLECT, `Branch score: ${branch.score.toFixed(2)}`, { conclusion: branch.conclusion }, branch.score);
252
+ this.addStep(
253
+ STEP_TYPE.REFLECT,
254
+ `Branch score: ${branch.score.toFixed(2)}`,
255
+ { conclusion: branch.conclusion },
256
+ branch.score
257
+ );
229
258
  }
230
-
259
+
231
260
  // Select best branch
232
261
  branches.sort((a, b) => b.score - a.score);
233
262
  const best = branches[0];
234
-
235
- this.addStep(STEP_TYPE.ACT, `Selected best reasoning path with score ${best.score.toFixed(2)}`, { conclusion: best.conclusion }, best.score);
236
-
263
+
264
+ this.addStep(
265
+ STEP_TYPE.ACT,
266
+ `Selected best reasoning path with score ${best.score.toFixed(2)}`,
267
+ { conclusion: best.conclusion },
268
+ best.score
269
+ );
270
+
237
271
  return { conclusion: best.conclusion, successful: best.score >= this.minConfidence };
238
272
  }
239
-
273
+
240
274
  /**
241
275
  * Reflective reasoning - iterate and improve
242
276
  * @private
@@ -245,81 +279,111 @@ class ReasoningEngine extends EventEmitter {
245
279
  let currentSolution = null;
246
280
  let iterations = 0;
247
281
  const maxIterations = 3;
248
-
282
+
249
283
  this.addStep(STEP_TYPE.OBSERVE, `Starting reflective reasoning for: ${problem}`, {}, 0.9);
250
-
284
+
251
285
  while (iterations < maxIterations) {
252
286
  iterations++;
253
-
287
+
254
288
  // Generate or refine solution
255
289
  if (!currentSolution) {
256
290
  currentSolution = await this.generateInitialSolution(problem, context);
257
- this.addStep(STEP_TYPE.THINK, `Initial solution: ${currentSolution}`, { iteration: iterations }, 0.7);
291
+ this.addStep(
292
+ STEP_TYPE.THINK,
293
+ `Initial solution: ${currentSolution}`,
294
+ { iteration: iterations },
295
+ 0.7
296
+ );
258
297
  } else {
259
298
  currentSolution = await this.refineSolution(currentSolution, problem, context);
260
- this.addStep(STEP_TYPE.REFINE, `Refined solution: ${currentSolution}`, { iteration: iterations }, 0.8);
299
+ this.addStep(
300
+ STEP_TYPE.REFINE,
301
+ `Refined solution: ${currentSolution}`,
302
+ { iteration: iterations },
303
+ 0.8
304
+ );
261
305
  }
262
-
306
+
263
307
  // Reflect on solution
264
308
  const reflection = this.reflect(problem, currentSolution, []);
265
- this.addStep(STEP_TYPE.REFLECT, reflection.content, { confidence: reflection.confidence }, reflection.confidence);
266
-
309
+ this.addStep(
310
+ STEP_TYPE.REFLECT,
311
+ reflection.content,
312
+ { confidence: reflection.confidence },
313
+ reflection.confidence
314
+ );
315
+
267
316
  if (reflection.confidence >= this.minConfidence) {
268
317
  return { conclusion: currentSolution, successful: true };
269
318
  }
270
319
  }
271
-
320
+
272
321
  return { conclusion: currentSolution, successful: false };
273
322
  }
274
-
323
+
275
324
  /**
276
325
  * Decomposition reasoning - divide and conquer
277
326
  * @private
278
327
  */
279
328
  async decompositionReasoning(problem, context) {
280
329
  this.addStep(STEP_TYPE.OBSERVE, `Decomposing problem: ${problem}`, {}, 0.9);
281
-
330
+
282
331
  // Hierarchical decomposition
283
332
  const decomposition = this.hierarchicalDecompose(problem);
284
- this.addStep(STEP_TYPE.PLAN, `Problem decomposition:\n${this.formatDecomposition(decomposition)}`, { decomposition }, 0.85);
285
-
333
+ this.addStep(
334
+ STEP_TYPE.PLAN,
335
+ `Problem decomposition:\n${this.formatDecomposition(decomposition)}`,
336
+ { decomposition },
337
+ 0.85
338
+ );
339
+
286
340
  // Solve bottom-up
287
341
  const solved = await this.solveBottomUp(decomposition, context);
288
- this.addStep(STEP_TYPE.ACT, `Solved ${solved.solvedCount} sub-problems`, { solved: solved.results }, 0.8);
289
-
342
+ this.addStep(
343
+ STEP_TYPE.ACT,
344
+ `Solved ${solved.solvedCount} sub-problems`,
345
+ { solved: solved.results },
346
+ 0.8
347
+ );
348
+
290
349
  // Compose solution
291
350
  const conclusion = this.composeSolution(solved.results);
292
351
  this.addStep(STEP_TYPE.THINK, `Composed final solution`, { conclusion }, 0.85);
293
-
352
+
294
353
  return { conclusion, successful: true };
295
354
  }
296
-
355
+
297
356
  /**
298
357
  * Analogy reasoning - use similar cases
299
358
  * @private
300
359
  */
301
360
  async analogyReasoning(problem, context) {
302
361
  this.addStep(STEP_TYPE.OBSERVE, `Finding analogies for: ${problem}`, {}, 0.9);
303
-
362
+
304
363
  // Find similar cases
305
364
  const analogies = this.findAnalogies(problem, context);
306
365
  this.addStep(STEP_TYPE.THINK, `Found ${analogies.length} similar cases`, { analogies }, 0.8);
307
-
366
+
308
367
  if (analogies.length === 0) {
309
- this.addStep(STEP_TYPE.REFLECT, 'No suitable analogies found, falling back to chain of thought', {}, 0.5);
368
+ this.addStep(
369
+ STEP_TYPE.REFLECT,
370
+ 'No suitable analogies found, falling back to chain of thought',
371
+ {},
372
+ 0.5
373
+ );
310
374
  return this.chainOfThought(problem, context);
311
375
  }
312
-
376
+
313
377
  // Apply best analogy
314
378
  const best = analogies[0];
315
379
  this.addStep(STEP_TYPE.PLAN, `Applying analogy: ${best.description}`, { analogy: best }, 0.75);
316
-
380
+
317
381
  const conclusion = this.applyAnalogy(best, problem, context);
318
382
  this.addStep(STEP_TYPE.ACT, `Derived solution from analogy`, { conclusion }, 0.8);
319
-
383
+
320
384
  return { conclusion, successful: true };
321
385
  }
322
-
386
+
323
387
  /**
324
388
  * Add a reasoning step
325
389
  * @param {string} type - Step type
@@ -329,25 +393,25 @@ class ReasoningEngine extends EventEmitter {
329
393
  */
330
394
  addStep(type, content, metadata = {}, confidence = 0.5) {
331
395
  if (!this.currentTrace) return;
332
-
396
+
333
397
  const step = {
334
398
  id: `step-${++this.stepCounter}`,
335
399
  type,
336
400
  content,
337
401
  metadata,
338
402
  confidence,
339
- timestamp: Date.now()
403
+ timestamp: Date.now(),
340
404
  };
341
-
405
+
342
406
  this.currentTrace.steps.push(step);
343
407
  this.emit('reasoning:step', { step, traceId: this.currentTrace.id });
344
-
408
+
345
409
  // Check step limit
346
410
  if (this.currentTrace.steps.length >= this.maxSteps) {
347
411
  throw new Error('Maximum reasoning steps exceeded');
348
412
  }
349
413
  }
350
-
414
+
351
415
  /**
352
416
  * Decompose problem into sub-problems
353
417
  * @private
@@ -355,11 +419,11 @@ class ReasoningEngine extends EventEmitter {
355
419
  decomposeProlem(problem) {
356
420
  // Simple keyword-based decomposition
357
421
  const parts = [];
358
-
422
+
359
423
  // Look for conjunction patterns
360
424
  const conjunctions = ['and', 'then', 'also', 'additionally', 'furthermore'];
361
425
  let remaining = problem;
362
-
426
+
363
427
  for (const conj of conjunctions) {
364
428
  const regex = new RegExp(`\\s+${conj}\\s+`, 'gi');
365
429
  if (regex.test(remaining)) {
@@ -369,26 +433,24 @@ class ReasoningEngine extends EventEmitter {
369
433
  break;
370
434
  }
371
435
  }
372
-
436
+
373
437
  if (remaining) {
374
438
  parts.push(remaining);
375
439
  }
376
-
440
+
377
441
  // Clean up and filter
378
- return parts
379
- .map(p => p.trim())
380
- .filter(p => p.length > 0);
442
+ return parts.map(p => p.trim()).filter(p => p.length > 0);
381
443
  }
382
-
444
+
383
445
  /**
384
446
  * Solve a sub-problem
385
447
  * @private
386
448
  */
387
- async solveSubProblem(subProblem, context) {
449
+ async solveSubProblem(subProblem, _context) {
388
450
  // Simplified solution generation
389
451
  return `Resolved: ${subProblem.substring(0, 50)}...`;
390
452
  }
391
-
453
+
392
454
  /**
393
455
  * Synthesize solutions
394
456
  * @private
@@ -396,10 +458,10 @@ class ReasoningEngine extends EventEmitter {
396
458
  synthesize(solutions) {
397
459
  if (solutions.length === 0) return 'No solutions found';
398
460
  if (solutions.length === 1) return solutions[0].solution;
399
-
461
+
400
462
  return solutions.map(s => s.solution).join(' → ');
401
463
  }
402
-
464
+
403
465
  /**
404
466
  * Reflect on solution
405
467
  * @private
@@ -408,40 +470,45 @@ class ReasoningEngine extends EventEmitter {
408
470
  // Simple reflection logic
409
471
  const hasConclusion = conclusion && conclusion.length > 0;
410
472
  const hasMultipleSolutions = solutions.length > 1;
411
-
473
+
412
474
  let confidence = 0.5;
413
475
  let content = 'Analyzing solution quality...';
414
-
476
+
415
477
  if (hasConclusion) {
416
478
  confidence += 0.2;
417
479
  content = 'Solution generated successfully.';
418
480
  }
419
-
481
+
420
482
  if (hasMultipleSolutions) {
421
483
  confidence += 0.1;
422
484
  content += ' Multiple approaches considered.';
423
485
  }
424
-
486
+
425
487
  // Check if conclusion addresses the problem
426
488
  const problemWords = problem.toLowerCase().split(/\s+/);
427
489
  const conclusionWords = (conclusion || '').toLowerCase().split(/\s+/);
428
490
  const overlap = problemWords.filter(w => conclusionWords.includes(w)).length;
429
-
491
+
430
492
  if (overlap > 2) {
431
493
  confidence += 0.1;
432
494
  content += ' Conclusion appears relevant to problem.';
433
495
  }
434
-
496
+
435
497
  return { confidence: Math.min(confidence, 1), content };
436
498
  }
437
-
499
+
438
500
  /**
439
501
  * Backtrack and try alternative approach
440
502
  * @private
441
503
  */
442
504
  async backtrack(problem, context, reflection) {
443
- this.addStep(STEP_TYPE.REFLECT, `Confidence too low (${reflection.confidence.toFixed(2)}), backtracking...`, {}, reflection.confidence);
444
-
505
+ this.addStep(
506
+ STEP_TYPE.REFLECT,
507
+ `Confidence too low (${reflection.confidence.toFixed(2)}), backtracking...`,
508
+ {},
509
+ reflection.confidence
510
+ );
511
+
445
512
  // Try decomposition as fallback
446
513
  const decomposition = this.decomposeProlem(problem);
447
514
  if (decomposition.length > 1) {
@@ -453,44 +520,40 @@ class ReasoningEngine extends EventEmitter {
453
520
  const conclusion = this.synthesize(solutions);
454
521
  return { conclusion, successful: true };
455
522
  }
456
-
523
+
457
524
  return { conclusion: 'Unable to reach confident solution', successful: false };
458
525
  }
459
-
526
+
460
527
  /**
461
528
  * Generate multiple initial thoughts
462
529
  * @private
463
530
  */
464
531
  generateThoughts(problem, count) {
465
532
  const thoughts = [];
466
- const approaches = [
467
- 'Direct approach: ',
468
- 'Step-by-step: ',
469
- 'Alternative perspective: '
470
- ];
471
-
533
+ const approaches = ['Direct approach: ', 'Step-by-step: ', 'Alternative perspective: '];
534
+
472
535
  for (let i = 0; i < Math.min(count, approaches.length); i++) {
473
536
  thoughts.push(`${approaches[i]}${problem.substring(0, 50)}`);
474
537
  }
475
-
538
+
476
539
  return thoughts;
477
540
  }
478
-
541
+
479
542
  /**
480
543
  * Develop a reasoning branch
481
544
  * @private
482
545
  */
483
- async developBranch(thought, problem, context) {
546
+ async developBranch(thought, _problem, _context) {
484
547
  const steps = [];
485
-
548
+
486
549
  steps.push({ content: `Developing: ${thought}`, type: 'develop' });
487
550
  steps.push({ content: `Analyzing implications`, type: 'analyze' });
488
-
551
+
489
552
  const conclusion = `Branch conclusion for: ${thought.substring(0, 30)}`;
490
-
553
+
491
554
  return { steps, conclusion };
492
555
  }
493
-
556
+
494
557
  /**
495
558
  * Evaluate a reasoning branch
496
559
  * @private
@@ -498,30 +561,30 @@ class ReasoningEngine extends EventEmitter {
498
561
  evaluateBranch(branch) {
499
562
  // Simple scoring based on step count and conclusion
500
563
  let score = 0.5;
501
-
564
+
502
565
  if (branch.conclusion) score += 0.2;
503
566
  if (branch.steps.length > 0) score += 0.1;
504
567
  if (branch.steps.length > 2) score += 0.1;
505
-
568
+
506
569
  return Math.min(score, 1);
507
570
  }
508
-
571
+
509
572
  /**
510
573
  * Generate initial solution
511
574
  * @private
512
575
  */
513
- async generateInitialSolution(problem, context) {
576
+ async generateInitialSolution(problem, _context) {
514
577
  return `Initial approach to: ${problem.substring(0, 50)}`;
515
578
  }
516
-
579
+
517
580
  /**
518
581
  * Refine existing solution
519
582
  * @private
520
583
  */
521
- async refineSolution(solution, problem, context) {
584
+ async refineSolution(solution, _problem, _context) {
522
585
  return `Refined: ${solution}`;
523
586
  }
524
-
587
+
525
588
  /**
526
589
  * Hierarchical decomposition
527
590
  * @private
@@ -531,11 +594,11 @@ class ReasoningEngine extends EventEmitter {
531
594
  root: problem,
532
595
  children: this.decomposeProlem(problem).map(p => ({
533
596
  content: p,
534
- children: []
535
- }))
597
+ children: [],
598
+ })),
536
599
  };
537
600
  }
538
-
601
+
539
602
  /**
540
603
  * Format decomposition for display
541
604
  * @private
@@ -543,23 +606,23 @@ class ReasoningEngine extends EventEmitter {
543
606
  formatDecomposition(decomposition, indent = 0) {
544
607
  const prefix = ' '.repeat(indent);
545
608
  let result = `${prefix}└ ${decomposition.root || decomposition.content}`;
546
-
609
+
547
610
  if (decomposition.children) {
548
611
  for (const child of decomposition.children) {
549
612
  result += '\n' + this.formatDecomposition(child, indent + 1);
550
613
  }
551
614
  }
552
-
615
+
553
616
  return result;
554
617
  }
555
-
618
+
556
619
  /**
557
620
  * Solve problems bottom-up
558
621
  * @private
559
622
  */
560
623
  async solveBottomUp(decomposition, context) {
561
624
  const results = [];
562
-
625
+
563
626
  // Solve leaf nodes first
564
627
  if (decomposition.children) {
565
628
  for (const child of decomposition.children) {
@@ -567,10 +630,10 @@ class ReasoningEngine extends EventEmitter {
567
630
  results.push({ problem: child.content, solution });
568
631
  }
569
632
  }
570
-
633
+
571
634
  return { results, solvedCount: results.length };
572
635
  }
573
-
636
+
574
637
  /**
575
638
  * Compose solution from parts
576
639
  * @private
@@ -579,25 +642,25 @@ class ReasoningEngine extends EventEmitter {
579
642
  if (results.length === 0) return 'No solution components';
580
643
  return results.map(r => r.solution).join('; ');
581
644
  }
582
-
645
+
583
646
  /**
584
647
  * Find analogies for problem
585
648
  * @private
586
649
  */
587
- findAnalogies(problem, context) {
650
+ findAnalogies(_problem, _context) {
588
651
  // Placeholder for analogy retrieval
589
652
  // In real implementation, would search knowledge base
590
653
  return [];
591
654
  }
592
-
655
+
593
656
  /**
594
657
  * Apply analogy to derive solution
595
658
  * @private
596
659
  */
597
- applyAnalogy(analogy, problem, context) {
660
+ applyAnalogy(analogy, _problem, _context) {
598
661
  return `Applied ${analogy.description} to derive solution`;
599
662
  }
600
-
663
+
601
664
  /**
602
665
  * Generate unique ID
603
666
  * @private
@@ -605,7 +668,7 @@ class ReasoningEngine extends EventEmitter {
605
668
  generateId() {
606
669
  return `trace-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
607
670
  }
608
-
671
+
609
672
  /**
610
673
  * Get reasoning trace by ID
611
674
  * @param {string} traceId - Trace identifier
@@ -614,7 +677,7 @@ class ReasoningEngine extends EventEmitter {
614
677
  getTrace(traceId) {
615
678
  return this.traces.get(traceId) || null;
616
679
  }
617
-
680
+
618
681
  /**
619
682
  * Get all traces
620
683
  * @returns {ReasoningTrace[]}
@@ -622,7 +685,7 @@ class ReasoningEngine extends EventEmitter {
622
685
  getAllTraces() {
623
686
  return Array.from(this.traces.values());
624
687
  }
625
-
688
+
626
689
  /**
627
690
  * Clear all traces
628
691
  */
@@ -630,7 +693,7 @@ class ReasoningEngine extends EventEmitter {
630
693
  this.traces.clear();
631
694
  this.stepCounter = 0;
632
695
  }
633
-
696
+
634
697
  /**
635
698
  * Get statistics
636
699
  * @returns {Object}
@@ -639,20 +702,19 @@ class ReasoningEngine extends EventEmitter {
639
702
  const traces = this.getAllTraces();
640
703
  const successful = traces.filter(t => t.successful).length;
641
704
  const totalSteps = traces.reduce((sum, t) => sum + t.steps.length, 0);
642
- const avgTime = traces.length > 0
643
- ? traces.reduce((sum, t) => sum + t.totalTime, 0) / traces.length
644
- : 0;
645
-
705
+ const avgTime =
706
+ traces.length > 0 ? traces.reduce((sum, t) => sum + t.totalTime, 0) / traces.length : 0;
707
+
646
708
  return {
647
709
  totalTraces: traces.length,
648
710
  successfulTraces: successful,
649
711
  successRate: traces.length > 0 ? successful / traces.length : 0,
650
712
  totalSteps,
651
713
  averageStepsPerTrace: traces.length > 0 ? totalSteps / traces.length : 0,
652
- averageTime: avgTime
714
+ averageTime: avgTime,
653
715
  };
654
716
  }
655
-
717
+
656
718
  /**
657
719
  * Export trace to readable format
658
720
  * @param {string} traceId - Trace identifier
@@ -661,22 +723,22 @@ class ReasoningEngine extends EventEmitter {
661
723
  exportTrace(traceId) {
662
724
  const trace = this.getTrace(traceId);
663
725
  if (!trace) return '';
664
-
726
+
665
727
  let output = `# Reasoning Trace: ${trace.id}\n\n`;
666
728
  output += `**Problem:** ${trace.problem}\n\n`;
667
729
  output += `**Strategy:** ${trace.strategy}\n\n`;
668
730
  output += `## Steps\n\n`;
669
-
731
+
670
732
  for (const step of trace.steps) {
671
733
  output += `### ${step.type.toUpperCase()} (confidence: ${step.confidence.toFixed(2)})\n`;
672
734
  output += `${step.content}\n\n`;
673
735
  }
674
-
736
+
675
737
  output += `## Conclusion\n\n`;
676
738
  output += `${trace.conclusion || 'No conclusion reached'}\n\n`;
677
739
  output += `**Successful:** ${trace.successful ? 'Yes' : 'No'}\n`;
678
740
  output += `**Total Time:** ${trace.totalTime}ms\n`;
679
-
741
+
680
742
  return output;
681
743
  }
682
744
  }
@@ -706,5 +768,5 @@ module.exports = {
706
768
  createReasoningEngine,
707
769
  reason,
708
770
  STRATEGY,
709
- STEP_TYPE
771
+ STEP_TYPE,
710
772
  };