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
@@ -16,7 +16,7 @@ const SEVERITY = {
16
16
  INFO: 'info',
17
17
  WARNING: 'warning',
18
18
  ERROR: 'error',
19
- CRITICAL: 'critical'
19
+ CRITICAL: 'critical',
20
20
  };
21
21
 
22
22
  /**
@@ -30,7 +30,7 @@ const CORRECTION_STRATEGY = {
30
30
  SIMPLIFY: 'simplify',
31
31
  ESCALATE: 'escalate',
32
32
  SKIP: 'skip',
33
- ROLLBACK: 'rollback'
33
+ ROLLBACK: 'rollback',
34
34
  };
35
35
 
36
36
  /**
@@ -83,62 +83,62 @@ const DEFAULT_PATTERNS = [
83
83
  pattern: /syntax\s*error/i,
84
84
  type: 'syntax',
85
85
  strategy: CORRECTION_STRATEGY.SIMPLIFY,
86
- description: 'Syntax error in code'
86
+ description: 'Syntax error in code',
87
87
  },
88
88
  {
89
89
  pattern: /undefined|not\s*defined/i,
90
90
  type: 'reference',
91
91
  strategy: CORRECTION_STRATEGY.FALLBACK,
92
- description: 'Undefined reference'
92
+ description: 'Undefined reference',
93
93
  },
94
94
  {
95
95
  pattern: /timeout|timed?\s*out/i,
96
96
  type: 'timeout',
97
97
  strategy: CORRECTION_STRATEGY.RETRY,
98
- description: 'Operation timed out'
98
+ description: 'Operation timed out',
99
99
  },
100
100
  {
101
101
  pattern: /permission|access\s*denied|forbidden/i,
102
102
  type: 'permission',
103
103
  strategy: CORRECTION_STRATEGY.ESCALATE,
104
- description: 'Permission denied'
104
+ description: 'Permission denied',
105
105
  },
106
106
  {
107
107
  pattern: /not\s*found|missing|does\s*not\s*exist/i,
108
108
  type: 'not-found',
109
109
  strategy: CORRECTION_STRATEGY.FALLBACK,
110
- description: 'Resource not found'
110
+ description: 'Resource not found',
111
111
  },
112
112
  {
113
113
  pattern: /out\s*of\s*memory|heap|allocation/i,
114
114
  type: 'memory',
115
115
  strategy: CORRECTION_STRATEGY.DECOMPOSE,
116
- description: 'Memory allocation error'
116
+ description: 'Memory allocation error',
117
117
  },
118
118
  {
119
119
  pattern: /network|connection|socket/i,
120
120
  type: 'network',
121
121
  strategy: CORRECTION_STRATEGY.RETRY,
122
- description: 'Network error'
122
+ description: 'Network error',
123
123
  },
124
124
  {
125
125
  pattern: /invalid|malformed|corrupt/i,
126
126
  type: 'validation',
127
127
  strategy: CORRECTION_STRATEGY.SIMPLIFY,
128
- description: 'Invalid input or data'
128
+ description: 'Invalid input or data',
129
129
  },
130
130
  {
131
131
  pattern: /deadlock|race\s*condition/i,
132
132
  type: 'concurrency',
133
133
  strategy: CORRECTION_STRATEGY.RETRY,
134
- description: 'Concurrency issue'
134
+ description: 'Concurrency issue',
135
135
  },
136
136
  {
137
137
  pattern: /assertion|expect|test.*fail/i,
138
138
  type: 'test',
139
139
  strategy: CORRECTION_STRATEGY.FALLBACK,
140
- description: 'Test assertion failure'
141
- }
140
+ description: 'Test assertion failure',
141
+ },
142
142
  ];
143
143
 
144
144
  /**
@@ -152,26 +152,26 @@ class SelfCorrection extends EventEmitter {
152
152
  */
153
153
  constructor(options = {}) {
154
154
  super();
155
-
155
+
156
156
  this.maxRetries = options.maxRetries ?? 3;
157
157
  this.retryDelay = options.retryDelay ?? 1000;
158
158
  this.exponentialBackoff = options.exponentialBackoff ?? true;
159
159
  this.maxBackoff = options.maxBackoff ?? 30000;
160
160
  this.learnFromErrors = options.learnFromErrors ?? true;
161
161
  this.memorySize = options.memorySize ?? 100;
162
-
162
+
163
163
  // State
164
164
  this.patterns = [...DEFAULT_PATTERNS];
165
165
  this.errorMemory = [];
166
166
  this.corrections = new Map();
167
167
  this.successPatterns = new Map();
168
168
  this.errorCounter = 0;
169
-
169
+
170
170
  // Handlers
171
171
  this.strategyHandlers = new Map();
172
172
  this.registerDefaultHandlers();
173
173
  }
174
-
174
+
175
175
  /**
176
176
  * Register default strategy handlers
177
177
  * @private
@@ -185,7 +185,7 @@ class SelfCorrection extends EventEmitter {
185
185
  this.strategyHandlers.set(CORRECTION_STRATEGY.SKIP, this.handleSkip.bind(this));
186
186
  this.strategyHandlers.set(CORRECTION_STRATEGY.ROLLBACK, this.handleRollback.bind(this));
187
187
  }
188
-
188
+
189
189
  /**
190
190
  * Analyze an error
191
191
  * @param {Error|string} error - Error to analyze
@@ -195,10 +195,10 @@ class SelfCorrection extends EventEmitter {
195
195
  analyzeError(error, context = {}) {
196
196
  const message = error instanceof Error ? error.message : String(error);
197
197
  const stack = error instanceof Error ? error.stack : null;
198
-
198
+
199
199
  // Classify error
200
200
  const classification = this.classifyError(message);
201
-
201
+
202
202
  const record = {
203
203
  id: `err-${++this.errorCounter}`,
204
204
  message,
@@ -210,20 +210,20 @@ class SelfCorrection extends EventEmitter {
210
210
  description: classification.description,
211
211
  attempts: [],
212
212
  resolved: false,
213
- timestamp: Date.now()
213
+ timestamp: Date.now(),
214
214
  };
215
-
215
+
216
216
  // Store in memory
217
217
  this.errorMemory.push(record);
218
218
  if (this.errorMemory.length > this.memorySize) {
219
219
  this.errorMemory.shift();
220
220
  }
221
-
221
+
222
222
  this.emit('error:analyzed', { record });
223
-
223
+
224
224
  return record;
225
225
  }
226
-
226
+
227
227
  /**
228
228
  * Classify error based on patterns
229
229
  * @private
@@ -235,30 +235,29 @@ class SelfCorrection extends EventEmitter {
235
235
  return info;
236
236
  }
237
237
  }
238
-
238
+
239
239
  // Check default patterns
240
240
  for (const pattern of this.patterns) {
241
- const regex = pattern.pattern instanceof RegExp
242
- ? pattern.pattern
243
- : new RegExp(pattern.pattern, 'i');
244
-
241
+ const regex =
242
+ pattern.pattern instanceof RegExp ? pattern.pattern : new RegExp(pattern.pattern, 'i');
243
+
245
244
  if (regex.test(message)) {
246
245
  return {
247
246
  type: pattern.type,
248
247
  strategy: pattern.strategy,
249
- description: pattern.description
248
+ description: pattern.description,
250
249
  };
251
250
  }
252
251
  }
253
-
252
+
254
253
  // Default classification
255
254
  return {
256
255
  type: 'unknown',
257
256
  strategy: CORRECTION_STRATEGY.RETRY,
258
- description: 'Unknown error'
257
+ description: 'Unknown error',
259
258
  };
260
259
  }
261
-
260
+
262
261
  /**
263
262
  * Determine severity based on error type
264
263
  * @private
@@ -275,12 +274,12 @@ class SelfCorrection extends EventEmitter {
275
274
  validation: SEVERITY.ERROR,
276
275
  concurrency: SEVERITY.ERROR,
277
276
  test: SEVERITY.INFO,
278
- unknown: SEVERITY.ERROR
277
+ unknown: SEVERITY.ERROR,
279
278
  };
280
-
279
+
281
280
  return severities[type] || SEVERITY.ERROR;
282
281
  }
283
-
282
+
284
283
  /**
285
284
  * Attempt to correct an error
286
285
  * @param {ErrorRecord} record - Error record
@@ -290,14 +289,14 @@ class SelfCorrection extends EventEmitter {
290
289
  */
291
290
  async correct(record, operation, options = {}) {
292
291
  const startTime = Date.now();
293
-
292
+
294
293
  this.emit('correction:start', { errorId: record.id, strategy: record.strategy });
295
-
294
+
296
295
  const handler = this.strategyHandlers.get(record.strategy);
297
296
  if (!handler) {
298
297
  throw new Error(`No handler for strategy: ${record.strategy}`);
299
298
  }
300
-
299
+
301
300
  const attempt = {
302
301
  id: `attempt-${record.attempts.length + 1}`,
303
302
  errorId: record.id,
@@ -305,105 +304,103 @@ class SelfCorrection extends EventEmitter {
305
304
  successful: false,
306
305
  result: null,
307
306
  timestamp: Date.now(),
308
- duration: 0
307
+ duration: 0,
309
308
  };
310
-
309
+
311
310
  try {
312
311
  const result = await handler(record, operation, options);
313
-
312
+
314
313
  attempt.successful = true;
315
314
  attempt.result = 'Correction successful';
316
315
  record.resolved = true;
317
-
316
+
318
317
  // Learn from success
319
318
  if (this.learnFromErrors) {
320
319
  this.learnSuccess(record);
321
320
  }
322
-
321
+
323
322
  this.emit('correction:success', { errorId: record.id, attempt });
324
-
323
+
325
324
  return { success: true, result, attempt };
326
-
327
325
  } catch (correctionError) {
328
326
  attempt.successful = false;
329
327
  attempt.result = correctionError.message;
330
-
331
- this.emit('correction:failure', {
332
- errorId: record.id,
333
- attempt,
334
- error: correctionError.message
328
+
329
+ this.emit('correction:failure', {
330
+ errorId: record.id,
331
+ attempt,
332
+ error: correctionError.message,
335
333
  });
336
-
337
- return {
338
- success: false,
339
- error: correctionError,
334
+
335
+ return {
336
+ success: false,
337
+ error: correctionError,
340
338
  attempt,
341
- canRetry: record.attempts.length < this.maxRetries
339
+ canRetry: record.attempts.length < this.maxRetries,
342
340
  };
343
-
344
341
  } finally {
345
342
  attempt.duration = Date.now() - startTime;
346
343
  record.attempts.push(attempt);
347
344
  this.corrections.set(record.id, record);
348
345
  }
349
346
  }
350
-
347
+
351
348
  /**
352
349
  * Handle retry strategy
353
350
  * @private
354
351
  */
355
- async handleRetry(record, operation, options) {
352
+ async handleRetry(record, operation, _options) {
356
353
  const attemptNumber = record.attempts.length;
357
-
354
+
358
355
  // Calculate delay
359
356
  let delay = this.retryDelay;
360
357
  if (this.exponentialBackoff) {
361
358
  delay = Math.min(this.retryDelay * Math.pow(2, attemptNumber), this.maxBackoff);
362
359
  }
363
-
360
+
364
361
  // Wait before retry
365
362
  await this.delay(delay);
366
-
363
+
367
364
  // Retry the operation
368
365
  return operation();
369
366
  }
370
-
367
+
371
368
  /**
372
369
  * Handle fallback strategy
373
370
  * @private
374
371
  */
375
372
  async handleFallback(record, operation, options) {
376
373
  const fallback = options.fallback;
377
-
374
+
378
375
  if (fallback) {
379
376
  if (typeof fallback === 'function') {
380
377
  return fallback(record);
381
378
  }
382
379
  return fallback;
383
380
  }
384
-
381
+
385
382
  // Try simpler version of operation
386
383
  if (options.simplifiedOperation) {
387
384
  return options.simplifiedOperation();
388
385
  }
389
-
386
+
390
387
  throw new Error('No fallback available');
391
388
  }
392
-
389
+
393
390
  /**
394
391
  * Handle decompose strategy
395
392
  * @private
396
393
  */
397
394
  async handleDecompose(record, operation, options) {
398
395
  const decomposer = options.decompose;
399
-
396
+
400
397
  if (!decomposer) {
401
398
  throw new Error('No decomposer provided');
402
399
  }
403
-
400
+
404
401
  // Decompose into smaller operations
405
402
  const subOperations = await decomposer(record);
406
-
403
+
407
404
  // Execute sub-operations
408
405
  const results = [];
409
406
  for (const subOp of subOperations) {
@@ -414,74 +411,74 @@ class SelfCorrection extends EventEmitter {
414
411
  results.push({ success: false, error: error.message });
415
412
  }
416
413
  }
417
-
414
+
418
415
  return { results, successful: results.every(r => r.success) };
419
416
  }
420
-
417
+
421
418
  /**
422
419
  * Handle simplify strategy
423
420
  * @private
424
421
  */
425
422
  async handleSimplify(record, operation, options) {
426
423
  const simplifier = options.simplify;
427
-
424
+
428
425
  if (simplifier) {
429
426
  const simplified = await simplifier(record);
430
427
  return simplified;
431
428
  }
432
-
429
+
433
430
  // Default simplification: retry with reduced scope
434
431
  if (options.simplifiedOperation) {
435
432
  return options.simplifiedOperation();
436
433
  }
437
-
434
+
438
435
  throw new Error('Cannot simplify operation');
439
436
  }
440
-
437
+
441
438
  /**
442
439
  * Handle escalate strategy
443
440
  * @private
444
441
  */
445
442
  async handleEscalate(record, operation, options) {
446
443
  const escalationHandler = options.escalate;
447
-
444
+
448
445
  this.emit('correction:escalated', { record });
449
-
446
+
450
447
  if (escalationHandler) {
451
448
  return escalationHandler(record);
452
449
  }
453
-
450
+
454
451
  // Mark as requiring human intervention
455
452
  record.escalated = true;
456
453
  throw new Error('Error escalated - requires human intervention');
457
454
  }
458
-
455
+
459
456
  /**
460
457
  * Handle skip strategy
461
458
  * @private
462
459
  */
463
- async handleSkip(record, operation, options) {
460
+ async handleSkip(record, _operation, _options) {
464
461
  this.emit('correction:skipped', { record });
465
-
462
+
466
463
  return { skipped: true, reason: record.message };
467
464
  }
468
-
465
+
469
466
  /**
470
467
  * Handle rollback strategy
471
468
  * @private
472
469
  */
473
470
  async handleRollback(record, operation, options) {
474
471
  const rollbackHandler = options.rollback;
475
-
472
+
476
473
  if (!rollbackHandler) {
477
474
  throw new Error('No rollback handler provided');
478
475
  }
479
-
476
+
480
477
  this.emit('correction:rollback', { record });
481
-
478
+
482
479
  return rollbackHandler(record);
483
480
  }
484
-
481
+
485
482
  /**
486
483
  * Learn from successful correction
487
484
  * @private
@@ -489,16 +486,16 @@ class SelfCorrection extends EventEmitter {
489
486
  learnSuccess(record) {
490
487
  // Extract key part of error message
491
488
  const key = this.extractErrorSignature(record.message);
492
-
489
+
493
490
  if (key) {
494
491
  this.successPatterns.set(key, {
495
492
  type: record.type,
496
493
  strategy: record.strategy,
497
- description: record.description
494
+ description: record.description,
498
495
  });
499
496
  }
500
497
  }
501
-
498
+
502
499
  /**
503
500
  * Extract error signature for learning
504
501
  * @private
@@ -511,7 +508,7 @@ class SelfCorrection extends EventEmitter {
511
508
  .replace(/\/[^\s]+/g, '/PATH')
512
509
  .substring(0, 50);
513
510
  }
514
-
511
+
515
512
  /**
516
513
  * Add custom error pattern
517
514
  * @param {ErrorPattern} pattern - Pattern definition
@@ -519,7 +516,7 @@ class SelfCorrection extends EventEmitter {
519
516
  addPattern(pattern) {
520
517
  this.patterns.unshift(pattern);
521
518
  }
522
-
519
+
523
520
  /**
524
521
  * Register custom strategy handler
525
522
  * @param {string} strategy - Strategy name
@@ -528,18 +525,16 @@ class SelfCorrection extends EventEmitter {
528
525
  registerHandler(strategy, handler) {
529
526
  this.strategyHandlers.set(strategy, handler);
530
527
  }
531
-
528
+
532
529
  /**
533
530
  * Get error by ID
534
531
  * @param {string} errorId - Error identifier
535
532
  * @returns {ErrorRecord|null}
536
533
  */
537
534
  getError(errorId) {
538
- return this.corrections.get(errorId) ||
539
- this.errorMemory.find(e => e.id === errorId) ||
540
- null;
535
+ return this.corrections.get(errorId) || this.errorMemory.find(e => e.id === errorId) || null;
541
536
  }
542
-
537
+
543
538
  /**
544
539
  * Get recent errors
545
540
  * @param {number} [count=10] - Number of errors to return
@@ -548,7 +543,7 @@ class SelfCorrection extends EventEmitter {
548
543
  getRecentErrors(count = 10) {
549
544
  return this.errorMemory.slice(-count);
550
545
  }
551
-
546
+
552
547
  /**
553
548
  * Get unresolved errors
554
549
  * @returns {ErrorRecord[]}
@@ -556,7 +551,7 @@ class SelfCorrection extends EventEmitter {
556
551
  getUnresolvedErrors() {
557
552
  return this.errorMemory.filter(e => !e.resolved);
558
553
  }
559
-
554
+
560
555
  /**
561
556
  * Get error statistics
562
557
  * @returns {Object}
@@ -567,13 +562,13 @@ class SelfCorrection extends EventEmitter {
567
562
  const byType = {};
568
563
  const bySeverity = {};
569
564
  const byStrategy = {};
570
-
565
+
571
566
  for (const error of this.errorMemory) {
572
567
  byType[error.type] = (byType[error.type] || 0) + 1;
573
568
  bySeverity[error.severity] = (bySeverity[error.severity] || 0) + 1;
574
569
  byStrategy[error.strategy] = (byStrategy[error.strategy] || 0) + 1;
575
570
  }
576
-
571
+
577
572
  // Calculate success rates by strategy
578
573
  const strategySuccess = {};
579
574
  for (const [, record] of this.corrections) {
@@ -586,7 +581,7 @@ class SelfCorrection extends EventEmitter {
586
581
  strategySuccess[strategy].success++;
587
582
  }
588
583
  }
589
-
584
+
590
585
  return {
591
586
  total,
592
587
  resolved,
@@ -596,10 +591,10 @@ class SelfCorrection extends EventEmitter {
596
591
  bySeverity,
597
592
  byStrategy,
598
593
  strategySuccess,
599
- learnedPatterns: this.successPatterns.size
594
+ learnedPatterns: this.successPatterns.size,
600
595
  };
601
596
  }
602
-
597
+
603
598
  /**
604
599
  * Get correction recommendations for an error
605
600
  * @param {ErrorRecord} record - Error record
@@ -607,7 +602,7 @@ class SelfCorrection extends EventEmitter {
607
602
  */
608
603
  getRecommendations(record) {
609
604
  const recommendations = [];
610
-
605
+
611
606
  // Based on error type
612
607
  const typeRecs = {
613
608
  syntax: ['Check for typos', 'Verify code structure', 'Use linter'],
@@ -619,34 +614,32 @@ class SelfCorrection extends EventEmitter {
619
614
  network: ['Check connection', 'Retry request', 'Check firewall'],
620
615
  validation: ['Verify input format', 'Check data types', 'Validate schema'],
621
616
  concurrency: ['Add locking', 'Use queue', 'Retry with backoff'],
622
- test: ['Review test logic', 'Check expected values', 'Update assertions']
617
+ test: ['Review test logic', 'Check expected values', 'Update assertions'],
623
618
  };
624
-
619
+
625
620
  recommendations.push(...(typeRecs[record.type] || ['Review error details']));
626
-
621
+
627
622
  // Based on similar past errors
628
623
  const similar = this.findSimilarErrors(record);
629
624
  if (similar.length > 0 && similar[0].resolved) {
630
625
  recommendations.push(`Similar error resolved using: ${similar[0].strategy}`);
631
626
  }
632
-
627
+
633
628
  return {
634
629
  primaryStrategy: record.strategy,
635
630
  alternatives: this.getAlternativeStrategies(record.strategy),
636
- actionItems: recommendations
631
+ actionItems: recommendations,
637
632
  };
638
633
  }
639
-
634
+
640
635
  /**
641
636
  * Find similar past errors
642
637
  * @private
643
638
  */
644
639
  findSimilarErrors(record) {
645
- return this.errorMemory
646
- .filter(e => e.id !== record.id && e.type === record.type)
647
- .slice(-5);
640
+ return this.errorMemory.filter(e => e.id !== record.id && e.type === record.type).slice(-5);
648
641
  }
649
-
642
+
650
643
  /**
651
644
  * Get alternative strategies
652
645
  * @private
@@ -655,7 +648,7 @@ class SelfCorrection extends EventEmitter {
655
648
  const all = Object.values(CORRECTION_STRATEGY);
656
649
  return all.filter(s => s !== primaryStrategy);
657
650
  }
658
-
651
+
659
652
  /**
660
653
  * Delay helper
661
654
  * @private
@@ -663,7 +656,7 @@ class SelfCorrection extends EventEmitter {
663
656
  delay(ms) {
664
657
  return new Promise(resolve => setTimeout(resolve, ms));
665
658
  }
666
-
659
+
667
660
  /**
668
661
  * Clear error memory
669
662
  */
@@ -672,49 +665,49 @@ class SelfCorrection extends EventEmitter {
672
665
  this.corrections.clear();
673
666
  this.errorCounter = 0;
674
667
  }
675
-
668
+
676
669
  /**
677
670
  * Reset learned patterns
678
671
  */
679
672
  resetLearning() {
680
673
  this.successPatterns.clear();
681
674
  }
682
-
675
+
683
676
  /**
684
677
  * Export error report
685
678
  * @returns {string}
686
679
  */
687
680
  exportReport() {
688
681
  const stats = this.getStats();
689
-
682
+
690
683
  let report = `# Error Correction Report\n\n`;
691
684
  report += `## Summary\n`;
692
685
  report += `- Total Errors: ${stats.total}\n`;
693
686
  report += `- Resolved: ${stats.resolved} (${(stats.resolutionRate * 100).toFixed(1)}%)\n`;
694
687
  report += `- Learned Patterns: ${stats.learnedPatterns}\n\n`;
695
-
688
+
696
689
  report += `## Errors by Type\n`;
697
690
  for (const [type, count] of Object.entries(stats.byType)) {
698
691
  report += `- ${type}: ${count}\n`;
699
692
  }
700
-
693
+
701
694
  report += `\n## Errors by Severity\n`;
702
695
  for (const [severity, count] of Object.entries(stats.bySeverity)) {
703
696
  report += `- ${severity}: ${count}\n`;
704
697
  }
705
-
698
+
706
699
  report += `\n## Strategy Effectiveness\n`;
707
700
  for (const [strategy, data] of Object.entries(stats.strategySuccess)) {
708
- const rate = data.total > 0 ? (data.success / data.total * 100).toFixed(1) : 0;
701
+ const rate = data.total > 0 ? ((data.success / data.total) * 100).toFixed(1) : 0;
709
702
  report += `- ${strategy}: ${rate}% success (${data.success}/${data.total})\n`;
710
703
  }
711
-
704
+
712
705
  report += `\n## Recent Errors\n`;
713
706
  for (const error of this.getRecentErrors(5)) {
714
707
  const status = error.resolved ? '✅' : '❌';
715
708
  report += `- ${status} [${error.type}] ${error.message.substring(0, 50)}...\n`;
716
709
  }
717
-
710
+
718
711
  return report;
719
712
  }
720
713
  }
@@ -747,5 +740,5 @@ module.exports = {
747
740
  correctError,
748
741
  SEVERITY,
749
742
  CORRECTION_STRATEGY,
750
- DEFAULT_PATTERNS
743
+ DEFAULT_PATTERNS,
751
744
  };