atlas-pipeline-mcp 1.0.19 → 1.0.21
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/dist/mcp.js +191 -0
- package/dist/mcp.js.map +1 -1
- package/dist/tools/context.d.ts +33 -7
- package/dist/tools/context.d.ts.map +1 -1
- package/dist/tools/context.js +167 -82
- package/dist/tools/context.js.map +1 -1
- package/dist/tools/dashboard.d.ts +107 -0
- package/dist/tools/dashboard.d.ts.map +1 -0
- package/dist/tools/dashboard.js +544 -0
- package/dist/tools/dashboard.js.map +1 -0
- package/dist/tools/dependencies.d.ts +105 -0
- package/dist/tools/dependencies.d.ts.map +1 -0
- package/dist/tools/dependencies.js +410 -0
- package/dist/tools/dependencies.js.map +1 -0
- package/dist/tools/git.d.ts +27 -4
- package/dist/tools/git.d.ts.map +1 -1
- package/dist/tools/git.js +156 -59
- package/dist/tools/git.js.map +1 -1
- package/dist/tools/profiler.d.ts +83 -0
- package/dist/tools/profiler.d.ts.map +1 -0
- package/dist/tools/profiler.js +385 -0
- package/dist/tools/profiler.js.map +1 -0
- package/dist/tools/refactor.d.ts +63 -0
- package/dist/tools/refactor.d.ts.map +1 -0
- package/dist/tools/refactor.js +308 -0
- package/dist/tools/refactor.js.map +1 -0
- package/dist/tools/resource-manager.d.ts +167 -0
- package/dist/tools/resource-manager.d.ts.map +1 -0
- package/dist/tools/resource-manager.js +352 -0
- package/dist/tools/resource-manager.js.map +1 -0
- package/dist/tools/review.d.ts +98 -0
- package/dist/tools/review.d.ts.map +1 -0
- package/dist/tools/review.js +428 -0
- package/dist/tools/review.js.map +1 -0
- package/dist/tools/test-utils.d.ts +170 -0
- package/dist/tools/test-utils.d.ts.map +1 -0
- package/dist/tools/test-utils.js +490 -0
- package/dist/tools/test-utils.js.map +1 -0
- package/dist/tools/validation.d.ts +237 -0
- package/dist/tools/validation.d.ts.map +1 -0
- package/dist/tools/validation.js +323 -0
- package/dist/tools/validation.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Atlas Server - AI-Powered Code Refactoring Tool
|
|
3
|
+
*
|
|
4
|
+
* Advanced refactoring capabilities beyond simple code cleanup:
|
|
5
|
+
* - Pattern detection (design patterns, anti-patterns)
|
|
6
|
+
* - Complexity reduction (cyclomatic complexity analysis)
|
|
7
|
+
* - SOLID principles enforcement
|
|
8
|
+
* - Performance hotspot identification
|
|
9
|
+
* - Automated Extract Method/Class/Interface
|
|
10
|
+
* - Dead code elimination
|
|
11
|
+
* - Type inference and migration
|
|
12
|
+
* - Dependency injection suggestions
|
|
13
|
+
*
|
|
14
|
+
* @module refactor
|
|
15
|
+
* @author Nishant Unavane
|
|
16
|
+
* @version 1.0.0
|
|
17
|
+
*/
|
|
18
|
+
import { getActiveProvider, isNoLLMMode } from '../providers/index.js';
|
|
19
|
+
import { logger, createTimer } from '../utils.js';
|
|
20
|
+
import { validateInput } from './validation.js';
|
|
21
|
+
import { z } from 'zod';
|
|
22
|
+
// ============================================================================
|
|
23
|
+
// Validation Schema
|
|
24
|
+
// ============================================================================
|
|
25
|
+
const RefactorOptionsSchema = z.object({
|
|
26
|
+
code: z.string().min(1).max(500000),
|
|
27
|
+
language: z.string().min(1),
|
|
28
|
+
filePath: z.string().optional(),
|
|
29
|
+
targets: z.array(z.enum([
|
|
30
|
+
'complexity', 'duplication', 'naming', 'structure',
|
|
31
|
+
'performance', 'solid', 'patterns', 'types',
|
|
32
|
+
'async', 'functional', 'deadcode'
|
|
33
|
+
])).optional(),
|
|
34
|
+
maxComplexity: z.number().min(1).max(50).optional(),
|
|
35
|
+
enforceSOLID: z.boolean().optional(),
|
|
36
|
+
preserveBehavior: z.boolean().optional(),
|
|
37
|
+
addTypes: z.boolean().optional(),
|
|
38
|
+
modernize: z.boolean().optional(),
|
|
39
|
+
projectContext: z.string().optional(),
|
|
40
|
+
dependencies: z.array(z.string()).optional(),
|
|
41
|
+
});
|
|
42
|
+
// ============================================================================
|
|
43
|
+
// Code Metrics Calculator
|
|
44
|
+
// ============================================================================
|
|
45
|
+
/**
|
|
46
|
+
* Calculate code metrics for before/after comparison
|
|
47
|
+
*/
|
|
48
|
+
function calculateMetrics(code, language) {
|
|
49
|
+
const lines = code.split('\n');
|
|
50
|
+
const nonEmptyLines = lines.filter(l => l.trim().length > 0);
|
|
51
|
+
const commentLines = lines.filter(l => {
|
|
52
|
+
const trimmed = l.trim();
|
|
53
|
+
return trimmed.startsWith('//') ||
|
|
54
|
+
trimmed.startsWith('/*') ||
|
|
55
|
+
trimmed.startsWith('*') ||
|
|
56
|
+
trimmed.startsWith('#');
|
|
57
|
+
});
|
|
58
|
+
// Simple cyclomatic complexity (count decision points)
|
|
59
|
+
const decisionPoints = (code.match(/\b(if|else|for|while|case|catch|\?|&&|\|\|)\b/g) || []).length;
|
|
60
|
+
const cyclomaticComplexity = decisionPoints + 1;
|
|
61
|
+
// Maintainability Index (simplified formula)
|
|
62
|
+
// MI = max(0, (171 - 5.2 * ln(Halstead Volume) - 0.23 * CC - 16.2 * ln(LOC)) * 100 / 171)
|
|
63
|
+
const volume = Math.log(nonEmptyLines.length + 1) * 10; // Simplified
|
|
64
|
+
const mi = Math.max(0, (171 - 5.2 * volume - 0.23 * cyclomaticComplexity - 16.2 * Math.log(nonEmptyLines.length + 1)) * 100 / 171);
|
|
65
|
+
// Count functions and classes
|
|
66
|
+
const functionCount = (code.match(/\b(function|def|fn|func)\s+\w+/g) || []).length +
|
|
67
|
+
(code.match(/=>\s*{/g) || []).length;
|
|
68
|
+
const classCount = (code.match(/\b(class|struct|interface)\s+\w+/g) || []).length;
|
|
69
|
+
return {
|
|
70
|
+
linesOfCode: nonEmptyLines.length,
|
|
71
|
+
cyclomaticComplexity,
|
|
72
|
+
maintainabilityIndex: Math.round(mi),
|
|
73
|
+
duplicatedLines: 0, // Would need more sophisticated analysis
|
|
74
|
+
functionCount,
|
|
75
|
+
classCount,
|
|
76
|
+
commentRatio: commentLines.length / (nonEmptyLines.length || 1),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
// ============================================================================
|
|
80
|
+
// Pattern Detection
|
|
81
|
+
// ============================================================================
|
|
82
|
+
/**
|
|
83
|
+
* Detect common code smells and anti-patterns
|
|
84
|
+
*/
|
|
85
|
+
function detectPatterns(code, language) {
|
|
86
|
+
const smells = [];
|
|
87
|
+
const patterns = [];
|
|
88
|
+
// God Class detection
|
|
89
|
+
if (code.match(/class\s+\w+\s*{[^}]{2000,}}/s)) {
|
|
90
|
+
smells.push('God Class: Class with too many responsibilities');
|
|
91
|
+
}
|
|
92
|
+
// Long Method detection
|
|
93
|
+
const methods = code.match(/(?:function|def|fn)\s+\w+[^{]*{[^}]{500,}}/gs) || [];
|
|
94
|
+
if (methods.length > 0) {
|
|
95
|
+
smells.push(`Long Method: ${methods.length} functions with 50+ lines`);
|
|
96
|
+
}
|
|
97
|
+
// Magic Numbers
|
|
98
|
+
const magicNumbers = code.match(/\b\d{3,}\b/g) || [];
|
|
99
|
+
if (magicNumbers.length > 3) {
|
|
100
|
+
smells.push(`Magic Numbers: ${magicNumbers.length} hardcoded numeric literals`);
|
|
101
|
+
}
|
|
102
|
+
// Nested Conditionals
|
|
103
|
+
if (code.match(/if\s*\([^)]+\)\s*{[^}]*if\s*\([^)]+\)\s*{[^}]*if/s)) {
|
|
104
|
+
smells.push('Deeply Nested Conditionals: Consider guard clauses');
|
|
105
|
+
}
|
|
106
|
+
// Singleton Pattern detection
|
|
107
|
+
if (code.match(/private\s+static\s+\w+\s+instance\s*[=;]/)) {
|
|
108
|
+
patterns.push('Singleton Pattern detected');
|
|
109
|
+
}
|
|
110
|
+
// Factory Pattern detection
|
|
111
|
+
if (code.match(/class\s+\w*Factory/)) {
|
|
112
|
+
patterns.push('Factory Pattern detected');
|
|
113
|
+
}
|
|
114
|
+
// Observer Pattern detection
|
|
115
|
+
if (code.match(/\b(on|addEventListener|subscribe|emit)\b/)) {
|
|
116
|
+
patterns.push('Observer Pattern detected');
|
|
117
|
+
}
|
|
118
|
+
return { smells, patterns };
|
|
119
|
+
}
|
|
120
|
+
// ============================================================================
|
|
121
|
+
// Main Refactor Function
|
|
122
|
+
// ============================================================================
|
|
123
|
+
/**
|
|
124
|
+
* AI-powered code refactoring with pattern detection
|
|
125
|
+
*/
|
|
126
|
+
export async function refactorCode(options) {
|
|
127
|
+
const timer = createTimer();
|
|
128
|
+
// Validate input
|
|
129
|
+
const validated = validateInput(RefactorOptionsSchema, options);
|
|
130
|
+
const { code, language, filePath, targets = [], maxComplexity = 10, enforceSOLID = true } = validated;
|
|
131
|
+
logger.info({ language, targets, filePath }, 'Starting code refactoring');
|
|
132
|
+
// Calculate initial metrics
|
|
133
|
+
const beforeMetrics = calculateMetrics(code, language);
|
|
134
|
+
// Detect patterns
|
|
135
|
+
const { smells, patterns } = detectPatterns(code, language);
|
|
136
|
+
const warnings = [];
|
|
137
|
+
const changes = [];
|
|
138
|
+
// Build refactoring prompt
|
|
139
|
+
const targetsStr = targets.length > 0
|
|
140
|
+
? targets.join(', ')
|
|
141
|
+
: 'all common refactorings';
|
|
142
|
+
const prompt = `You are a senior software architect with 50 years of experience. Refactor this ${language} code.
|
|
143
|
+
|
|
144
|
+
**Original Code:**
|
|
145
|
+
\`\`\`${language}
|
|
146
|
+
${code}
|
|
147
|
+
\`\`\`
|
|
148
|
+
|
|
149
|
+
**Current Metrics:**
|
|
150
|
+
- Lines of Code: ${beforeMetrics.linesOfCode}
|
|
151
|
+
- Cyclomatic Complexity: ${beforeMetrics.cyclomaticComplexity}
|
|
152
|
+
- Maintainability Index: ${beforeMetrics.maintainabilityIndex}/100
|
|
153
|
+
- Functions: ${beforeMetrics.functionCount}
|
|
154
|
+
- Classes: ${beforeMetrics.classCount}
|
|
155
|
+
|
|
156
|
+
**Detected Issues:**
|
|
157
|
+
${smells.length > 0 ? smells.map(s => `- ${s}`).join('\n') : '- No major code smells detected'}
|
|
158
|
+
|
|
159
|
+
**Detected Patterns:**
|
|
160
|
+
${patterns.length > 0 ? patterns.map(p => `- ${p}`).join('\n') : '- No design patterns detected'}
|
|
161
|
+
|
|
162
|
+
**Refactoring Targets:** ${targetsStr}
|
|
163
|
+
**Max Complexity Target:** ${maxComplexity}
|
|
164
|
+
**Enforce SOLID Principles:** ${enforceSOLID ? 'Yes' : 'No'}
|
|
165
|
+
|
|
166
|
+
**Instructions:**
|
|
167
|
+
1. Refactor the code to improve:
|
|
168
|
+
- Readability and maintainability
|
|
169
|
+
- Performance where applicable
|
|
170
|
+
- Type safety (add types if missing)
|
|
171
|
+
- Follow SOLID principles ${enforceSOLID ? '(strictly)' : '(loosely)'}
|
|
172
|
+
- Reduce cyclomatic complexity to ${maxComplexity} or below
|
|
173
|
+
2. Add descriptive comments for complex logic
|
|
174
|
+
3. Use modern ${language} features and best practices
|
|
175
|
+
4. Extract reusable functions/classes
|
|
176
|
+
5. Remove code duplication
|
|
177
|
+
6. Preserve original behavior exactly
|
|
178
|
+
|
|
179
|
+
**Provide:**
|
|
180
|
+
1. The refactored code
|
|
181
|
+
2. A list of changes made (one per line, format: "TYPE: Description")
|
|
182
|
+
3. Suggestions for further improvements
|
|
183
|
+
|
|
184
|
+
Format your response as:
|
|
185
|
+
\`\`\`${language}
|
|
186
|
+
[refactored code here]
|
|
187
|
+
\`\`\`
|
|
188
|
+
|
|
189
|
+
CHANGES:
|
|
190
|
+
- [change 1]
|
|
191
|
+
- [change 2]
|
|
192
|
+
...
|
|
193
|
+
|
|
194
|
+
SUGGESTIONS:
|
|
195
|
+
- [suggestion 1]
|
|
196
|
+
- [suggestion 2]
|
|
197
|
+
...`;
|
|
198
|
+
// Get LLM provider
|
|
199
|
+
let refactoredCode = code;
|
|
200
|
+
let suggestions = [];
|
|
201
|
+
if (isNoLLMMode()) {
|
|
202
|
+
warnings.push('No LLM provider available - using basic refactoring only');
|
|
203
|
+
// Basic automated refactorings without LLM
|
|
204
|
+
refactoredCode = applyBasicRefactorings(code, language, targets);
|
|
205
|
+
suggestions = [
|
|
206
|
+
'Install an LLM provider for advanced AI-powered refactoring',
|
|
207
|
+
'Consider manual code review for complex changes'
|
|
208
|
+
];
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
const provider = await getActiveProvider();
|
|
212
|
+
try {
|
|
213
|
+
const response = await provider.complete(prompt, {
|
|
214
|
+
maxTokens: 4000,
|
|
215
|
+
temperature: 0.3, // Lower temp for more consistent refactoring
|
|
216
|
+
});
|
|
217
|
+
const responseText = response.text;
|
|
218
|
+
// Parse response
|
|
219
|
+
const codeMatch = responseText.match(new RegExp(`\`\`\`${language}\\s*([\\s\\S]*?)\`\`\``));
|
|
220
|
+
if (codeMatch && codeMatch[1]) {
|
|
221
|
+
refactoredCode = codeMatch[1].trim();
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
warnings.push('Could not extract refactored code from LLM response');
|
|
225
|
+
refactoredCode = code;
|
|
226
|
+
}
|
|
227
|
+
// Parse changes
|
|
228
|
+
const changesMatch = responseText.match(/CHANGES:\s*([\s\S]*?)(?:SUGGESTIONS:|$)/);
|
|
229
|
+
if (changesMatch && changesMatch[1]) {
|
|
230
|
+
const changeLines = changesMatch[1].trim().split('\n')
|
|
231
|
+
.filter((line) => line.trim().startsWith('-'))
|
|
232
|
+
.map((line) => line.replace(/^-\s*/, '').trim());
|
|
233
|
+
changeLines.forEach((changeLine, idx) => {
|
|
234
|
+
const [typeStr, ...descParts] = changeLine.split(':');
|
|
235
|
+
const type = typeStr?.toLowerCase().trim() || 'structure';
|
|
236
|
+
const description = descParts.join(':').trim();
|
|
237
|
+
if (description) {
|
|
238
|
+
changes.push({
|
|
239
|
+
type,
|
|
240
|
+
description,
|
|
241
|
+
lineNumber: 1, // Would need more sophisticated parsing
|
|
242
|
+
impact: beforeMetrics.cyclomaticComplexity > 15 ? 'high' : 'medium',
|
|
243
|
+
autoApplicable: true,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
// Parse suggestions
|
|
249
|
+
const suggestionsMatch = responseText.match(/SUGGESTIONS:\s*([\s\S]*?)$/);
|
|
250
|
+
if (suggestionsMatch && suggestionsMatch[1]) {
|
|
251
|
+
suggestions = suggestionsMatch[1].trim().split('\n')
|
|
252
|
+
.filter((line) => line.trim().startsWith('-'))
|
|
253
|
+
.map((line) => line.replace(/^-\s*/, '').trim())
|
|
254
|
+
.filter(Boolean);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
catch (error) {
|
|
258
|
+
logger.error({ error }, 'Refactoring failed');
|
|
259
|
+
warnings.push(`LLM error: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
260
|
+
refactoredCode = code;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
// Calculate final metrics
|
|
264
|
+
const afterMetrics = calculateMetrics(refactoredCode, language);
|
|
265
|
+
// Add metrics comparison to suggestions
|
|
266
|
+
if (afterMetrics.cyclomaticComplexity < beforeMetrics.cyclomaticComplexity) {
|
|
267
|
+
suggestions.unshift(`✅ Complexity reduced from ${beforeMetrics.cyclomaticComplexity} to ${afterMetrics.cyclomaticComplexity}`);
|
|
268
|
+
}
|
|
269
|
+
if (afterMetrics.maintainabilityIndex > beforeMetrics.maintainabilityIndex) {
|
|
270
|
+
suggestions.unshift(`✅ Maintainability improved from ${beforeMetrics.maintainabilityIndex} to ${afterMetrics.maintainabilityIndex}`);
|
|
271
|
+
}
|
|
272
|
+
const executionTimeMs = timer.elapsed();
|
|
273
|
+
logger.info({
|
|
274
|
+
beforeComplexity: beforeMetrics.cyclomaticComplexity,
|
|
275
|
+
afterComplexity: afterMetrics.cyclomaticComplexity,
|
|
276
|
+
changesCount: changes.length,
|
|
277
|
+
executionTimeMs
|
|
278
|
+
}, 'Refactoring completed');
|
|
279
|
+
return {
|
|
280
|
+
originalCode: code,
|
|
281
|
+
refactoredCode,
|
|
282
|
+
changes,
|
|
283
|
+
metrics: afterMetrics,
|
|
284
|
+
suggestions,
|
|
285
|
+
executionTimeMs,
|
|
286
|
+
warnings,
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Apply basic refactorings without LLM
|
|
291
|
+
*/
|
|
292
|
+
function applyBasicRefactorings(code, language, targets) {
|
|
293
|
+
let result = code;
|
|
294
|
+
// Remove trailing whitespace
|
|
295
|
+
result = result.split('\n').map(line => line.trimEnd()).join('\n');
|
|
296
|
+
// Consistent indentation
|
|
297
|
+
result = result.replace(/\t/g, ' ');
|
|
298
|
+
// Remove multiple blank lines
|
|
299
|
+
result = result.replace(/\n{3,}/g, '\n\n');
|
|
300
|
+
// Add space after keywords
|
|
301
|
+
result = result.replace(/\b(if|for|while|switch|catch)\(/g, '$1 (');
|
|
302
|
+
return result;
|
|
303
|
+
}
|
|
304
|
+
// ============================================================================
|
|
305
|
+
// Export
|
|
306
|
+
// ============================================================================
|
|
307
|
+
export default refactorCode;
|
|
308
|
+
//# sourceMappingURL=refactor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refactor.js","sourceRoot":"","sources":["../../src/tools/refactor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAiB,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAoExB,+EAA+E;AAC/E,oBAAoB;AACpB,+EAA+E;AAE/E,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC;IACnC,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC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I,CAAC,IAAI,CAAC,CAAC;IAEnE,yBAAyB;IACzB,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAErC,8BAA8B;IAC9B,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAE3C,2BAA2B;IAC3B,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,kCAAkC,EAAE,MAAM,CAAC,CAAC;IAEpE,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,+EAA+E;AAC/E,SAAS;AACT,+EAA+E;AAE/E,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Atlas Server - Resource Management and Cleanup
|
|
3
|
+
*
|
|
4
|
+
* Comprehensive resource lifecycle management to prevent memory leaks:
|
|
5
|
+
* - Automatic cleanup of resources
|
|
6
|
+
* - Graceful shutdown handling
|
|
7
|
+
* - Resource pooling and recycling
|
|
8
|
+
* - Memory usage tracking
|
|
9
|
+
* - File handle management
|
|
10
|
+
*
|
|
11
|
+
* @module resource-manager
|
|
12
|
+
* @version 1.0.0
|
|
13
|
+
*/
|
|
14
|
+
import type { SimpleGit } from 'simple-git';
|
|
15
|
+
/**
|
|
16
|
+
* Resource that requires cleanup
|
|
17
|
+
*/
|
|
18
|
+
export interface ManagedResource {
|
|
19
|
+
/** Unique identifier for the resource */
|
|
20
|
+
readonly id: string;
|
|
21
|
+
/** Resource type for tracking */
|
|
22
|
+
readonly type: ResourceType;
|
|
23
|
+
/** Timestamp when resource was created */
|
|
24
|
+
readonly createdAt: number;
|
|
25
|
+
/** Last access timestamp for LRU eviction */
|
|
26
|
+
lastAccessedAt: number;
|
|
27
|
+
/** Cleanup function to release the resource */
|
|
28
|
+
cleanup(): Promise<void> | void;
|
|
29
|
+
/** Check if resource is still valid */
|
|
30
|
+
isValid(): boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Types of managed resources
|
|
34
|
+
*/
|
|
35
|
+
export type ResourceType = 'git-instance' | 'file-handle' | 'cache' | 'timer' | 'connection' | 'stream' | 'subprocess' | 'other';
|
|
36
|
+
/**
|
|
37
|
+
* Git instance wrapper with lifecycle management
|
|
38
|
+
*/
|
|
39
|
+
export declare class ManagedGitInstance implements ManagedResource {
|
|
40
|
+
readonly repoPath: string;
|
|
41
|
+
private git;
|
|
42
|
+
readonly id: string;
|
|
43
|
+
readonly type: ResourceType;
|
|
44
|
+
readonly createdAt: number;
|
|
45
|
+
lastAccessedAt: number;
|
|
46
|
+
constructor(repoPath: string, git: SimpleGit);
|
|
47
|
+
/** Get the git instance and update access time */
|
|
48
|
+
getGit(): SimpleGit;
|
|
49
|
+
/** Check if instance is still valid */
|
|
50
|
+
isValid(): boolean;
|
|
51
|
+
/** Cleanup the git instance */
|
|
52
|
+
cleanup(): Promise<void>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Centralized resource manager for automatic cleanup
|
|
56
|
+
*/
|
|
57
|
+
export declare class ResourceManager {
|
|
58
|
+
private readonly options;
|
|
59
|
+
private resources;
|
|
60
|
+
private cleanupTimer;
|
|
61
|
+
private shutdownHandlers;
|
|
62
|
+
private isShuttingDown;
|
|
63
|
+
constructor(options?: {
|
|
64
|
+
/** Cleanup interval in milliseconds */
|
|
65
|
+
cleanupIntervalMs?: number;
|
|
66
|
+
/** Maximum idle time before resource cleanup (milliseconds) */
|
|
67
|
+
maxIdleTimeMs?: number;
|
|
68
|
+
/** Maximum number of resources to keep */
|
|
69
|
+
maxResources?: number;
|
|
70
|
+
});
|
|
71
|
+
/**
|
|
72
|
+
* Register a resource for management
|
|
73
|
+
*/
|
|
74
|
+
register(resource: ManagedResource): void;
|
|
75
|
+
/**
|
|
76
|
+
* Unregister and cleanup a resource
|
|
77
|
+
*/
|
|
78
|
+
unregister(id: string): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Get a resource by ID
|
|
81
|
+
*/
|
|
82
|
+
get<T extends ManagedResource>(id: string): T | null;
|
|
83
|
+
/**
|
|
84
|
+
* Check if a resource exists
|
|
85
|
+
*/
|
|
86
|
+
has(id: string): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Get all resources of a specific type
|
|
89
|
+
*/
|
|
90
|
+
getByType<T extends ManagedResource>(type: ResourceType): T[];
|
|
91
|
+
/**
|
|
92
|
+
* Perform periodic cleanup of idle resources
|
|
93
|
+
*/
|
|
94
|
+
private performCleanup;
|
|
95
|
+
/**
|
|
96
|
+
* Cleanup a single resource
|
|
97
|
+
*/
|
|
98
|
+
private cleanupResource;
|
|
99
|
+
/**
|
|
100
|
+
* Register a custom shutdown handler
|
|
101
|
+
*/
|
|
102
|
+
onShutdown(handler: () => Promise<void> | void): void;
|
|
103
|
+
/**
|
|
104
|
+
* Graceful shutdown - cleanup all resources
|
|
105
|
+
*/
|
|
106
|
+
shutdown(): Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* Register signal handlers for graceful shutdown
|
|
109
|
+
*/
|
|
110
|
+
private registerShutdownHandlers;
|
|
111
|
+
/**
|
|
112
|
+
* Get resource statistics
|
|
113
|
+
*/
|
|
114
|
+
getStats(): {
|
|
115
|
+
total: number;
|
|
116
|
+
byType: Record<ResourceType, number>;
|
|
117
|
+
oldestResourceAge: number;
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/** Global resource manager instance */
|
|
121
|
+
export declare const globalResourceManager: ResourceManager;
|
|
122
|
+
/**
|
|
123
|
+
* Create a managed resource with automatic cleanup
|
|
124
|
+
*
|
|
125
|
+
* @param create - Function to create the resource
|
|
126
|
+
* @param cleanup - Function to cleanup the resource
|
|
127
|
+
* @param options - Resource options
|
|
128
|
+
* @returns The created resource
|
|
129
|
+
*/
|
|
130
|
+
export declare function withManagedResource<T>(create: () => Promise<T> | T, cleanup: (resource: T) => Promise<void> | void, options: {
|
|
131
|
+
id: string;
|
|
132
|
+
type: ResourceType;
|
|
133
|
+
autoRegister?: boolean;
|
|
134
|
+
}): Promise<T>;
|
|
135
|
+
/**
|
|
136
|
+
* Execute a function with automatic resource cleanup
|
|
137
|
+
*
|
|
138
|
+
* @param fn - Function to execute
|
|
139
|
+
* @param resources - Resources to cleanup after execution
|
|
140
|
+
* @returns Result of the function
|
|
141
|
+
*/
|
|
142
|
+
export declare function withCleanup<T>(fn: () => Promise<T> | T, resources: ManagedResource[]): Promise<T>;
|
|
143
|
+
/**
|
|
144
|
+
* Memory usage monitor
|
|
145
|
+
*/
|
|
146
|
+
export declare class MemoryMonitor {
|
|
147
|
+
private readonly threshold;
|
|
148
|
+
private warnings;
|
|
149
|
+
constructor(thresholdMB?: number);
|
|
150
|
+
/**
|
|
151
|
+
* Check current memory usage
|
|
152
|
+
*/
|
|
153
|
+
check(): {
|
|
154
|
+
heapUsed: number;
|
|
155
|
+
heapTotal: number;
|
|
156
|
+
external: number;
|
|
157
|
+
rss: number;
|
|
158
|
+
isOverThreshold: boolean;
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* Force garbage collection if available
|
|
162
|
+
*/
|
|
163
|
+
forceGC(): boolean;
|
|
164
|
+
}
|
|
165
|
+
/** Global memory monitor */
|
|
166
|
+
export declare const globalMemoryMonitor: MemoryMonitor;
|
|
167
|
+
//# sourceMappingURL=resource-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-manager.d.ts","sourceRoot":"","sources":["../../src/tools/resource-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAM5C;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,yCAAyC;IACzC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,iCAAiC;IACjC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,0CAA0C;IAC1C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC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