musubi-sdd 5.1.0 → 5.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +106 -48
- package/README.md +110 -32
- package/bin/musubi-analyze.js +74 -67
- package/bin/musubi-browser.js +27 -26
- package/bin/musubi-change.js +48 -47
- package/bin/musubi-checkpoint.js +10 -7
- package/bin/musubi-convert.js +25 -25
- package/bin/musubi-costs.js +27 -10
- package/bin/musubi-gui.js +52 -46
- package/bin/musubi-init.js +1952 -10
- package/bin/musubi-orchestrate.js +327 -239
- package/bin/musubi-remember.js +69 -56
- package/bin/musubi-resolve.js +53 -45
- package/bin/musubi-trace.js +51 -22
- package/bin/musubi-validate.js +39 -30
- package/bin/musubi-workflow.js +33 -34
- package/bin/musubi.js +39 -2
- package/package.json +1 -1
- package/src/agents/agent-loop.js +94 -95
- package/src/agents/agentic/code-generator.js +119 -109
- package/src/agents/agentic/code-reviewer.js +105 -108
- package/src/agents/agentic/index.js +4 -4
- package/src/agents/browser/action-executor.js +13 -13
- package/src/agents/browser/ai-comparator.js +11 -10
- package/src/agents/browser/context-manager.js +6 -6
- package/src/agents/browser/index.js +5 -5
- package/src/agents/browser/nl-parser.js +31 -46
- package/src/agents/browser/screenshot.js +2 -2
- package/src/agents/browser/test-generator.js +6 -4
- package/src/agents/function-tool.js +71 -65
- package/src/agents/index.js +7 -7
- package/src/agents/schema-generator.js +98 -94
- package/src/analyzers/ast-extractor.js +158 -146
- package/src/analyzers/codegraph-auto-update.js +858 -0
- package/src/analyzers/complexity-analyzer.js +536 -0
- package/src/analyzers/context-optimizer.js +241 -126
- package/src/analyzers/impact-analyzer.js +1 -1
- package/src/analyzers/large-project-analyzer.js +766 -0
- package/src/analyzers/repository-map.js +77 -81
- package/src/analyzers/security-analyzer.js +19 -11
- package/src/analyzers/stuck-detector.js +19 -17
- package/src/converters/index.js +78 -57
- package/src/converters/ir/types.js +12 -12
- package/src/converters/parsers/musubi-parser.js +134 -126
- package/src/converters/parsers/openapi-parser.js +70 -53
- package/src/converters/parsers/speckit-parser.js +239 -175
- package/src/converters/writers/musubi-writer.js +123 -118
- package/src/converters/writers/speckit-writer.js +124 -113
- package/src/generators/rust-migration-generator.js +512 -0
- package/src/gui/public/index.html +1365 -1211
- package/src/gui/server.js +41 -40
- package/src/gui/services/file-watcher.js +23 -8
- package/src/gui/services/project-scanner.js +26 -20
- package/src/gui/services/replanning-service.js +27 -23
- package/src/gui/services/traceability-service.js +8 -8
- package/src/gui/services/workflow-service.js +14 -7
- package/src/index.js +151 -0
- package/src/integrations/cicd.js +90 -104
- package/src/integrations/codegraph-mcp.js +643 -0
- package/src/integrations/documentation.js +142 -103
- package/src/integrations/examples.js +95 -80
- package/src/integrations/github-client.js +17 -17
- package/src/integrations/index.js +5 -5
- package/src/integrations/mcp/index.js +21 -21
- package/src/integrations/mcp/mcp-context-provider.js +76 -78
- package/src/integrations/mcp/mcp-discovery.js +74 -72
- package/src/integrations/mcp/mcp-tool-registry.js +99 -94
- package/src/integrations/mcp-connector.js +70 -66
- package/src/integrations/platforms.js +50 -49
- package/src/integrations/tool-discovery.js +37 -31
- package/src/llm-providers/anthropic-provider.js +11 -11
- package/src/llm-providers/base-provider.js +16 -18
- package/src/llm-providers/copilot-provider.js +22 -19
- package/src/llm-providers/index.js +26 -25
- package/src/llm-providers/ollama-provider.js +11 -11
- package/src/llm-providers/openai-provider.js +12 -12
- package/src/managers/agent-memory.js +36 -24
- package/src/managers/checkpoint-manager.js +4 -8
- package/src/managers/delta-spec.js +19 -19
- package/src/managers/index.js +13 -4
- package/src/managers/memory-condenser.js +35 -45
- package/src/managers/repo-skill-manager.js +57 -31
- package/src/managers/skill-loader.js +25 -22
- package/src/managers/skill-tools.js +36 -72
- package/src/managers/workflow.js +30 -22
- package/src/monitoring/cost-tracker.js +48 -46
- package/src/monitoring/incident-manager.js +116 -106
- package/src/monitoring/index.js +144 -134
- package/src/monitoring/observability.js +75 -62
- package/src/monitoring/quality-dashboard.js +45 -41
- package/src/monitoring/release-manager.js +63 -53
- package/src/orchestration/agent-skill-binding.js +39 -47
- package/src/orchestration/error-handler.js +65 -107
- package/src/orchestration/guardrails/base-guardrail.js +26 -24
- package/src/orchestration/guardrails/guardrail-rules.js +50 -64
- package/src/orchestration/guardrails/index.js +5 -5
- package/src/orchestration/guardrails/input-guardrail.js +58 -45
- package/src/orchestration/guardrails/output-guardrail.js +104 -81
- package/src/orchestration/guardrails/safety-check.js +79 -79
- package/src/orchestration/index.js +38 -55
- package/src/orchestration/mcp-tool-adapters.js +96 -99
- package/src/orchestration/orchestration-engine.js +21 -21
- package/src/orchestration/pattern-registry.js +60 -45
- package/src/orchestration/patterns/auto.js +34 -47
- package/src/orchestration/patterns/group-chat.js +59 -65
- package/src/orchestration/patterns/handoff.js +67 -65
- package/src/orchestration/patterns/human-in-loop.js +51 -72
- package/src/orchestration/patterns/nested.js +25 -40
- package/src/orchestration/patterns/sequential.js +35 -34
- package/src/orchestration/patterns/swarm.js +63 -56
- package/src/orchestration/patterns/triage.js +150 -109
- package/src/orchestration/reasoning/index.js +9 -9
- package/src/orchestration/reasoning/planning-engine.js +143 -140
- package/src/orchestration/reasoning/reasoning-engine.js +206 -144
- package/src/orchestration/reasoning/self-correction.js +121 -128
- package/src/orchestration/replanning/adaptive-goal-modifier.js +107 -112
- package/src/orchestration/replanning/alternative-generator.js +37 -42
- package/src/orchestration/replanning/config.js +63 -59
- package/src/orchestration/replanning/goal-progress-tracker.js +98 -100
- package/src/orchestration/replanning/index.js +24 -20
- package/src/orchestration/replanning/plan-evaluator.js +49 -50
- package/src/orchestration/replanning/plan-monitor.js +32 -28
- package/src/orchestration/replanning/proactive-path-optimizer.js +175 -178
- package/src/orchestration/replanning/replan-history.js +33 -26
- package/src/orchestration/replanning/replanning-engine.js +106 -108
- package/src/orchestration/skill-executor.js +107 -109
- package/src/orchestration/skill-registry.js +85 -89
- package/src/orchestration/workflow-examples.js +228 -231
- package/src/orchestration/workflow-executor.js +65 -68
- package/src/orchestration/workflow-orchestrator.js +72 -73
- package/src/phase4-integration.js +47 -40
- package/src/phase5-integration.js +89 -30
- package/src/reporters/coverage-report.js +82 -30
- package/src/reporters/hierarchical-reporter.js +498 -0
- package/src/reporters/traceability-matrix-report.js +29 -20
- package/src/resolvers/issue-resolver.js +43 -31
- package/src/steering/advanced-validation.js +133 -124
- package/src/steering/auto-updater.js +60 -73
- package/src/steering/index.js +6 -6
- package/src/steering/quality-metrics.js +41 -35
- package/src/steering/steering-auto-update.js +83 -86
- package/src/steering/steering-validator.js +98 -106
- package/src/steering/template-constraints.js +53 -54
- package/src/templates/agents/claude-code/CLAUDE.md +32 -32
- package/src/templates/agents/claude-code/skills/agent-assistant/SKILL.md +13 -5
- package/src/templates/agents/claude-code/skills/ai-ml-engineer/mlops-guide.md +23 -23
- package/src/templates/agents/claude-code/skills/ai-ml-engineer/model-card-template.md +60 -41
- package/src/templates/agents/claude-code/skills/api-designer/api-patterns.md +27 -19
- package/src/templates/agents/claude-code/skills/api-designer/openapi-template.md +11 -7
- package/src/templates/agents/claude-code/skills/bug-hunter/SKILL.md +4 -3
- package/src/templates/agents/claude-code/skills/bug-hunter/root-cause-analysis.md +37 -15
- package/src/templates/agents/claude-code/skills/change-impact-analyzer/dependency-graph-patterns.md +36 -42
- package/src/templates/agents/claude-code/skills/change-impact-analyzer/impact-analysis-template.md +69 -60
- package/src/templates/agents/claude-code/skills/cloud-architect/aws-patterns.md +31 -38
- package/src/templates/agents/claude-code/skills/cloud-architect/azure-patterns.md +28 -23
- package/src/templates/agents/claude-code/skills/code-reviewer/SKILL.md +61 -0
- package/src/templates/agents/claude-code/skills/code-reviewer/best-practices.md +27 -0
- package/src/templates/agents/claude-code/skills/code-reviewer/review-checklist.md +29 -10
- package/src/templates/agents/claude-code/skills/code-reviewer/review-standards.md +29 -24
- package/src/templates/agents/claude-code/skills/constitution-enforcer/SKILL.md +8 -6
- package/src/templates/agents/claude-code/skills/constitution-enforcer/constitutional-articles.md +62 -26
- package/src/templates/agents/claude-code/skills/constitution-enforcer/phase-minus-one-gates.md +35 -16
- package/src/templates/agents/claude-code/skills/database-administrator/backup-recovery.md +27 -17
- package/src/templates/agents/claude-code/skills/database-administrator/tuning-guide.md +25 -20
- package/src/templates/agents/claude-code/skills/database-schema-designer/schema-patterns.md +39 -22
- package/src/templates/agents/claude-code/skills/devops-engineer/ci-cd-templates.md +25 -22
- package/src/templates/agents/claude-code/skills/issue-resolver/SKILL.md +24 -21
- package/src/templates/agents/claude-code/skills/orchestrator/SKILL.md +148 -63
- package/src/templates/agents/claude-code/skills/orchestrator/patterns.md +35 -16
- package/src/templates/agents/claude-code/skills/orchestrator/selection-matrix.md +69 -64
- package/src/templates/agents/claude-code/skills/performance-engineer/optimization-playbook.md +47 -47
- package/src/templates/agents/claude-code/skills/performance-optimizer/SKILL.md +69 -0
- package/src/templates/agents/claude-code/skills/performance-optimizer/benchmark-template.md +63 -45
- package/src/templates/agents/claude-code/skills/performance-optimizer/optimization-patterns.md +33 -35
- package/src/templates/agents/claude-code/skills/project-manager/SKILL.md +7 -6
- package/src/templates/agents/claude-code/skills/project-manager/agile-ceremonies.md +47 -28
- package/src/templates/agents/claude-code/skills/project-manager/project-templates.md +94 -78
- package/src/templates/agents/claude-code/skills/quality-assurance/SKILL.md +20 -17
- package/src/templates/agents/claude-code/skills/quality-assurance/qa-plan-template.md +63 -49
- package/src/templates/agents/claude-code/skills/release-coordinator/SKILL.md +5 -5
- package/src/templates/agents/claude-code/skills/release-coordinator/feature-flag-guide.md +30 -26
- package/src/templates/agents/claude-code/skills/release-coordinator/release-plan-template.md +67 -35
- package/src/templates/agents/claude-code/skills/requirements-analyst/ears-format.md +54 -42
- package/src/templates/agents/claude-code/skills/requirements-analyst/validation-rules.md +36 -33
- package/src/templates/agents/claude-code/skills/security-auditor/SKILL.md +77 -19
- package/src/templates/agents/claude-code/skills/security-auditor/audit-checklists.md +24 -24
- package/src/templates/agents/claude-code/skills/security-auditor/owasp-top-10.md +61 -20
- package/src/templates/agents/claude-code/skills/security-auditor/vulnerability-patterns.md +43 -11
- package/src/templates/agents/claude-code/skills/site-reliability-engineer/SKILL.md +1 -0
- package/src/templates/agents/claude-code/skills/site-reliability-engineer/incident-response-template.md +55 -25
- package/src/templates/agents/claude-code/skills/site-reliability-engineer/observability-patterns.md +78 -68
- package/src/templates/agents/claude-code/skills/site-reliability-engineer/slo-sli-guide.md +73 -53
- package/src/templates/agents/claude-code/skills/software-developer/solid-principles.md +83 -37
- package/src/templates/agents/claude-code/skills/software-developer/test-first-workflow.md +38 -31
- package/src/templates/agents/claude-code/skills/steering/SKILL.md +1 -0
- package/src/templates/agents/claude-code/skills/steering/auto-update-rules.md +31 -0
- package/src/templates/agents/claude-code/skills/system-architect/adr-template.md +25 -7
- package/src/templates/agents/claude-code/skills/system-architect/c4-model-guide.md +74 -61
- package/src/templates/agents/claude-code/skills/technical-writer/doc-templates/documentation-templates.md +70 -52
- package/src/templates/agents/claude-code/skills/test-engineer/SKILL.md +2 -0
- package/src/templates/agents/claude-code/skills/test-engineer/ears-test-mapping.md +75 -71
- package/src/templates/agents/claude-code/skills/test-engineer/test-types.md +85 -63
- package/src/templates/agents/claude-code/skills/traceability-auditor/coverage-matrix-template.md +39 -36
- package/src/templates/agents/claude-code/skills/traceability-auditor/gap-detection-rules.md +22 -17
- package/src/templates/agents/claude-code/skills/ui-ux-designer/SKILL.md +1 -0
- package/src/templates/agents/claude-code/skills/ui-ux-designer/accessibility-guidelines.md +49 -75
- package/src/templates/agents/claude-code/skills/ui-ux-designer/design-system-components.md +71 -59
- package/src/templates/agents/codex/AGENTS.md +74 -42
- package/src/templates/agents/cursor/AGENTS.md +74 -42
- package/src/templates/agents/gemini-cli/GEMINI.md +74 -42
- package/src/templates/agents/github-copilot/AGENTS.md +83 -51
- package/src/templates/agents/qwen-code/QWEN.md +74 -42
- package/src/templates/agents/windsurf/AGENTS.md +74 -42
- package/src/templates/architectures/README.md +41 -0
- package/src/templates/architectures/clean-architecture/README.md +113 -0
- package/src/templates/architectures/event-driven/README.md +162 -0
- package/src/templates/architectures/hexagonal/README.md +130 -0
- package/src/templates/index.js +6 -1
- package/src/templates/locale-manager.js +16 -16
- package/src/templates/shared/delta-spec-template.md +20 -13
- package/src/templates/shared/github-actions/musubi-issue-resolver.yml +5 -5
- package/src/templates/shared/github-actions/musubi-security-check.yml +3 -3
- package/src/templates/shared/github-actions/musubi-validate.yml +4 -4
- package/src/templates/shared/steering/structure.md +95 -0
- package/src/templates/skills/browser-agent.md +21 -16
- package/src/templates/skills/web-gui.md +8 -0
- package/src/templates/template-constraints.js +50 -53
- package/src/validators/advanced-validation.js +30 -36
- package/src/validators/constitutional-validator.js +77 -73
- package/src/validators/critic-system.js +49 -59
- package/src/validators/delta-format.js +59 -55
- package/src/validators/traceability-validator.js +7 -11
|
@@ -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 =
|
|
242
|
-
? pattern.pattern
|
|
243
|
-
|
|
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,
|
|
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,
|
|
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
|
};
|