agent-ide 0.1.6 → 0.1.8
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/core/analysis/complexity-analyzer.d.ts.map +1 -1
- package/dist/core/analysis/complexity-analyzer.js +3 -2
- package/dist/core/analysis/complexity-analyzer.js.map +1 -1
- package/dist/core/analysis/dead-code-detector.d.ts +34 -10
- package/dist/core/analysis/dead-code-detector.d.ts.map +1 -1
- package/dist/core/analysis/dead-code-detector.js +121 -82
- package/dist/core/analysis/dead-code-detector.js.map +1 -1
- package/dist/core/analysis/index.d.ts +1 -1
- package/dist/core/analysis/index.d.ts.map +1 -1
- package/dist/core/dependency/dependency-analyzer.d.ts.map +1 -1
- package/dist/core/dependency/dependency-analyzer.js +11 -4
- package/dist/core/dependency/dependency-analyzer.js.map +1 -1
- package/dist/core/indexing/index-engine.d.ts +9 -0
- package/dist/core/indexing/index-engine.d.ts.map +1 -1
- package/dist/core/indexing/index-engine.js +60 -1
- package/dist/core/indexing/index-engine.js.map +1 -1
- package/dist/core/move/import-resolver.d.ts +8 -0
- package/dist/core/move/import-resolver.d.ts.map +1 -1
- package/dist/core/move/import-resolver.js +62 -1
- package/dist/core/move/import-resolver.js.map +1 -1
- package/dist/core/move/move-service.d.ts +9 -0
- package/dist/core/move/move-service.d.ts.map +1 -1
- package/dist/core/move/move-service.js +105 -8
- package/dist/core/move/move-service.js.map +1 -1
- package/dist/core/move/types.d.ts +1 -1
- package/dist/core/move/types.d.ts.map +1 -1
- package/dist/core/refactor/extract-function.d.ts +26 -4
- package/dist/core/refactor/extract-function.d.ts.map +1 -1
- package/dist/core/refactor/extract-function.js +300 -48
- package/dist/core/refactor/extract-function.js.map +1 -1
- package/dist/core/rename/reference-updater.d.ts +10 -10
- package/dist/core/rename/reference-updater.d.ts.map +1 -1
- package/dist/core/rename/reference-updater.js +84 -79
- package/dist/core/rename/reference-updater.js.map +1 -1
- package/dist/core/rename/rename-engine.d.ts.map +1 -1
- package/dist/core/rename/rename-engine.js +68 -17
- package/dist/core/rename/rename-engine.js.map +1 -1
- package/dist/infrastructure/parser/base.d.ts +10 -0
- package/dist/infrastructure/parser/base.d.ts.map +1 -1
- package/dist/infrastructure/parser/base.js +39 -0
- package/dist/infrastructure/parser/base.js.map +1 -1
- package/dist/infrastructure/parser/interface.d.ts +12 -0
- package/dist/infrastructure/parser/interface.d.ts.map +1 -1
- package/dist/infrastructure/parser/interface.js +2 -0
- package/dist/infrastructure/parser/interface.js.map +1 -1
- package/dist/interfaces/cli/cli.d.ts +17 -1
- package/dist/interfaces/cli/cli.d.ts.map +1 -1
- package/dist/interfaces/cli/cli.js +220 -43
- package/dist/interfaces/cli/cli.js.map +1 -1
- package/dist/interfaces/cli/output-formatter.d.ts +55 -0
- package/dist/interfaces/cli/output-formatter.d.ts.map +1 -0
- package/dist/interfaces/cli/output-formatter.js +195 -0
- package/dist/interfaces/cli/output-formatter.js.map +1 -0
- package/dist/plugins/javascript/parser.d.ts +10 -0
- package/dist/plugins/javascript/parser.d.ts.map +1 -1
- package/dist/plugins/javascript/parser.js +62 -0
- package/dist/plugins/javascript/parser.js.map +1 -1
- package/dist/plugins/typescript/parser.d.ts +10 -0
- package/dist/plugins/typescript/parser.d.ts.map +1 -1
- package/dist/plugins/typescript/parser.js +59 -0
- package/dist/plugins/typescript/parser.js.map +1 -1
- package/package.json +8 -14
- package/dist/core/performance/analyzer.d.ts +0 -62
- package/dist/core/performance/analyzer.d.ts.map +0 -1
- package/dist/core/performance/analyzer.js +0 -378
- package/dist/core/performance/analyzer.js.map +0 -1
- package/dist/core/performance/cache-manager.d.ts +0 -161
- package/dist/core/performance/cache-manager.d.ts.map +0 -1
- package/dist/core/performance/cache-manager.js +0 -375
- package/dist/core/performance/cache-manager.js.map +0 -1
- package/dist/core/performance/index.d.ts +0 -14
- package/dist/core/performance/index.d.ts.map +0 -1
- package/dist/core/performance/index.js +0 -17
- package/dist/core/performance/index.js.map +0 -1
- package/dist/core/performance/interfaces.d.ts +0 -188
- package/dist/core/performance/interfaces.d.ts.map +0 -1
- package/dist/core/performance/interfaces.js +0 -17
- package/dist/core/performance/interfaces.js.map +0 -1
- package/dist/core/performance/memory-manager.d.ts +0 -176
- package/dist/core/performance/memory-manager.d.ts.map +0 -1
- package/dist/core/performance/memory-manager.js +0 -364
- package/dist/core/performance/memory-manager.js.map +0 -1
- package/dist/core/performance/monitor.d.ts +0 -92
- package/dist/core/performance/monitor.d.ts.map +0 -1
- package/dist/core/performance/monitor.js +0 -228
- package/dist/core/performance/monitor.js.map +0 -1
- package/dist/plugins/swift/index.d.ts +0 -11
- package/dist/plugins/swift/index.d.ts.map +0 -1
- package/dist/plugins/swift/index.js +0 -15
- package/dist/plugins/swift/index.js.map +0 -1
- package/dist/plugins/swift/parser.d.ts +0 -98
- package/dist/plugins/swift/parser.d.ts.map +0 -1
- package/dist/plugins/swift/parser.js +0 -612
- package/dist/plugins/swift/parser.js.map +0 -1
- package/dist/plugins/swift/types.d.ts +0 -196
- package/dist/plugins/swift/types.d.ts.map +0 -1
- package/dist/plugins/swift/types.js +0 -268
- package/dist/plugins/swift/types.js.map +0 -1
|
@@ -1,378 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Performance Analyzer 實作
|
|
3
|
-
* 提供檔案和專案級別的效能分析功能
|
|
4
|
-
*/
|
|
5
|
-
import { promises as fs } from 'fs';
|
|
6
|
-
import { join, extname } from 'path';
|
|
7
|
-
import { PerformanceIssueType } from './interfaces.js';
|
|
8
|
-
import { DefaultPerformanceMonitor, measureAsync } from './monitor.js';
|
|
9
|
-
import { ParserRegistry } from '../../infrastructure/parser/registry.js';
|
|
10
|
-
/**
|
|
11
|
-
* 預設效能分析配置
|
|
12
|
-
*/
|
|
13
|
-
export const DEFAULT_PERFORMANCE_CONFIG = {
|
|
14
|
-
largeFileThreshold: 50000, // 50KB
|
|
15
|
-
longFunctionThreshold: 50, // 50行
|
|
16
|
-
deepNestingThreshold: 5, // 5層嵌套
|
|
17
|
-
highComplexityThreshold: 10, // 循環複雜度
|
|
18
|
-
verbose: false,
|
|
19
|
-
enableCache: true
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* 預設效能分析器實作
|
|
23
|
-
*/
|
|
24
|
-
export class DefaultPerformanceAnalyzer {
|
|
25
|
-
parserRegistry;
|
|
26
|
-
analysisCache = new Map();
|
|
27
|
-
constructor() {
|
|
28
|
-
this.parserRegistry = ParserRegistry.getInstance();
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* 分析檔案效能
|
|
32
|
-
*/
|
|
33
|
-
async analyzeFile(filePath, config = DEFAULT_PERFORMANCE_CONFIG) {
|
|
34
|
-
// 檢查快取
|
|
35
|
-
if (config.enableCache && this.analysisCache.has(filePath)) {
|
|
36
|
-
const cached = this.analysisCache.get(filePath);
|
|
37
|
-
if (config.verbose) {
|
|
38
|
-
console.log(`使用快取結果: ${filePath}`);
|
|
39
|
-
}
|
|
40
|
-
return cached;
|
|
41
|
-
}
|
|
42
|
-
const { result: fileInfo } = await measureAsync(async () => {
|
|
43
|
-
return await this.analyzeFileInternal(filePath, config);
|
|
44
|
-
}, config.verbose ? `分析檔案: ${filePath}` : undefined);
|
|
45
|
-
// 快取結果
|
|
46
|
-
if (config.enableCache) {
|
|
47
|
-
this.analysisCache.set(filePath, fileInfo);
|
|
48
|
-
}
|
|
49
|
-
return fileInfo;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* 分析專案效能
|
|
53
|
-
*/
|
|
54
|
-
async analyzeProject(projectPath, config = DEFAULT_PERFORMANCE_CONFIG) {
|
|
55
|
-
const monitor = new DefaultPerformanceMonitor();
|
|
56
|
-
monitor.start();
|
|
57
|
-
try {
|
|
58
|
-
// 獲取所有程式碼檔案
|
|
59
|
-
const files = await this.getAllCodeFiles(projectPath);
|
|
60
|
-
if (config.verbose) {
|
|
61
|
-
console.log(`找到 ${files.length} 個程式碼檔案`);
|
|
62
|
-
}
|
|
63
|
-
// 分析每個檔案
|
|
64
|
-
const fileResults = [];
|
|
65
|
-
const allIssues = [];
|
|
66
|
-
for (const file of files) {
|
|
67
|
-
try {
|
|
68
|
-
const fileInfo = await this.analyzeFile(file, config);
|
|
69
|
-
fileResults.push(fileInfo);
|
|
70
|
-
// 檢測問題
|
|
71
|
-
const issues = this.detectIssues(fileInfo, config);
|
|
72
|
-
allIssues.push(...issues);
|
|
73
|
-
}
|
|
74
|
-
catch (error) {
|
|
75
|
-
if (config.verbose) {
|
|
76
|
-
console.warn(`跳過檔案 ${file}:`, error);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
const metrics = monitor.stop();
|
|
81
|
-
// 計算統計資料
|
|
82
|
-
const summary = this.calculateSummary(fileResults);
|
|
83
|
-
// 生成建議
|
|
84
|
-
const recommendations = this.generateRecommendations(allIssues, summary);
|
|
85
|
-
return {
|
|
86
|
-
metrics,
|
|
87
|
-
fileResults,
|
|
88
|
-
issues: allIssues,
|
|
89
|
-
summary,
|
|
90
|
-
recommendations
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
catch (error) {
|
|
94
|
-
monitor.stop();
|
|
95
|
-
throw error;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* 檢測效能問題
|
|
100
|
-
*/
|
|
101
|
-
detectIssues(fileInfo, config) {
|
|
102
|
-
const issues = [];
|
|
103
|
-
// 檢查大檔案
|
|
104
|
-
if (fileInfo.fileSize > config.largeFileThreshold) {
|
|
105
|
-
issues.push({
|
|
106
|
-
type: PerformanceIssueType.LARGE_FILE,
|
|
107
|
-
severity: this.calculateSeverity(fileInfo.fileSize, config.largeFileThreshold, 5),
|
|
108
|
-
filePath: fileInfo.filePath,
|
|
109
|
-
message: `檔案過大: ${(fileInfo.fileSize / 1024).toFixed(1)}KB`,
|
|
110
|
-
suggestions: [
|
|
111
|
-
'考慮將檔案拆分為多個較小的模組',
|
|
112
|
-
'移除未使用的程式碼',
|
|
113
|
-
'使用程式碼分割技術'
|
|
114
|
-
],
|
|
115
|
-
value: fileInfo.fileSize,
|
|
116
|
-
threshold: config.largeFileThreshold
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
// 檢查長函式
|
|
120
|
-
if (fileInfo.longFunctionCount > 0) {
|
|
121
|
-
issues.push({
|
|
122
|
-
type: PerformanceIssueType.LONG_FUNCTION,
|
|
123
|
-
severity: Math.min(10, fileInfo.longFunctionCount),
|
|
124
|
-
filePath: fileInfo.filePath,
|
|
125
|
-
message: `發現 ${fileInfo.longFunctionCount} 個長函式`,
|
|
126
|
-
suggestions: [
|
|
127
|
-
'將長函式拆分為多個較小的函式',
|
|
128
|
-
'提取重複的邏輯到共用函式',
|
|
129
|
-
'使用函式式程式設計減少複雜度'
|
|
130
|
-
],
|
|
131
|
-
value: fileInfo.longFunctionCount,
|
|
132
|
-
threshold: 0
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
// 檢查深度嵌套
|
|
136
|
-
if (fileInfo.nestingDepth > config.deepNestingThreshold) {
|
|
137
|
-
issues.push({
|
|
138
|
-
type: PerformanceIssueType.DEEP_NESTING,
|
|
139
|
-
severity: this.calculateSeverity(fileInfo.nestingDepth, config.deepNestingThreshold, 8),
|
|
140
|
-
filePath: fileInfo.filePath,
|
|
141
|
-
message: `嵌套過深: ${fileInfo.nestingDepth} 層`,
|
|
142
|
-
suggestions: [
|
|
143
|
-
'使用早期返回減少嵌套',
|
|
144
|
-
'提取條件邏輯到獨立函式',
|
|
145
|
-
'考慮使用策略模式或狀態機'
|
|
146
|
-
],
|
|
147
|
-
value: fileInfo.nestingDepth,
|
|
148
|
-
threshold: config.deepNestingThreshold
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
// 檢查高複雜度
|
|
152
|
-
if (fileInfo.cyclomaticComplexity > config.highComplexityThreshold) {
|
|
153
|
-
issues.push({
|
|
154
|
-
type: PerformanceIssueType.HIGH_COMPLEXITY,
|
|
155
|
-
severity: this.calculateSeverity(fileInfo.cyclomaticComplexity, config.highComplexityThreshold, 10),
|
|
156
|
-
filePath: fileInfo.filePath,
|
|
157
|
-
message: `循環複雜度過高: ${fileInfo.cyclomaticComplexity}`,
|
|
158
|
-
suggestions: [
|
|
159
|
-
'簡化條件邏輯',
|
|
160
|
-
'使用多型代替條件分支',
|
|
161
|
-
'將複雜函式拆分為多個簡單函式'
|
|
162
|
-
],
|
|
163
|
-
value: fileInfo.cyclomaticComplexity,
|
|
164
|
-
threshold: config.highComplexityThreshold
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
return issues;
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* 內部檔案分析實作
|
|
171
|
-
*/
|
|
172
|
-
async analyzeFileInternal(filePath, config) {
|
|
173
|
-
const parseStart = Date.now();
|
|
174
|
-
// 獲取檔案資訊
|
|
175
|
-
const stats = await fs.stat(filePath);
|
|
176
|
-
const content = await fs.readFile(filePath, 'utf-8');
|
|
177
|
-
// 基本指標
|
|
178
|
-
let functionCount = 0;
|
|
179
|
-
let classCount = 0;
|
|
180
|
-
let longFunctionCount = 0;
|
|
181
|
-
let nestingDepth = 0;
|
|
182
|
-
let cyclomaticComplexity = 1; // 基礎複雜度
|
|
183
|
-
try {
|
|
184
|
-
// 嘗試使用 parser 進行精確分析
|
|
185
|
-
const ext = extname(filePath);
|
|
186
|
-
const parser = this.parserRegistry.getParser(ext);
|
|
187
|
-
if (parser) {
|
|
188
|
-
const ast = await parser.parse(content, filePath);
|
|
189
|
-
const symbols = await parser.extractSymbols(ast);
|
|
190
|
-
// 統計符號
|
|
191
|
-
for (const symbol of symbols) {
|
|
192
|
-
if (symbol.type === 'function') {
|
|
193
|
-
functionCount++;
|
|
194
|
-
// 檢查函式長度(簡化)
|
|
195
|
-
if (symbol.location?.range) {
|
|
196
|
-
const lines = symbol.location.range.end.line - symbol.location.range.start.line;
|
|
197
|
-
if (lines > config.longFunctionThreshold) {
|
|
198
|
-
longFunctionCount++;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
else if (symbol.type === 'class') {
|
|
203
|
-
classCount++;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
catch (error) {
|
|
209
|
-
// 使用正則表達式作為備選方案
|
|
210
|
-
if (config.verbose) {
|
|
211
|
-
console.warn(`Parser 分析失敗,使用正則表達式: ${filePath}`);
|
|
212
|
-
}
|
|
213
|
-
// 簡化的正則表達式分析
|
|
214
|
-
const functionMatches = content.match(/function\s+\w+|=>\s*{|function\s*\(/g) || [];
|
|
215
|
-
functionCount = functionMatches.length;
|
|
216
|
-
const classMatches = content.match(/class\s+\w+|interface\s+\w+/g) || [];
|
|
217
|
-
classCount = classMatches.length;
|
|
218
|
-
// 檢查長函式(基於括號和行數的啟發式方法)
|
|
219
|
-
const functionBlocks = content.match(/function[^{]*{[^}]*}/g) || [];
|
|
220
|
-
longFunctionCount = functionBlocks.filter(block => block.split('\n').length > config.longFunctionThreshold).length;
|
|
221
|
-
}
|
|
222
|
-
// 計算嵌套深度
|
|
223
|
-
nestingDepth = this.calculateNestingDepth(content);
|
|
224
|
-
// 計算循環複雜度(簡化版本)
|
|
225
|
-
cyclomaticComplexity = this.calculateCyclomaticComplexity(content);
|
|
226
|
-
const parseTime = Date.now() - parseStart;
|
|
227
|
-
return {
|
|
228
|
-
filePath,
|
|
229
|
-
fileSize: stats.size,
|
|
230
|
-
parseTime,
|
|
231
|
-
functionCount,
|
|
232
|
-
classCount,
|
|
233
|
-
longFunctionCount,
|
|
234
|
-
nestingDepth,
|
|
235
|
-
cyclomaticComplexity
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* 獲取所有程式碼檔案
|
|
240
|
-
*/
|
|
241
|
-
async getAllCodeFiles(projectPath) {
|
|
242
|
-
const files = [];
|
|
243
|
-
const supportedExtensions = ['.ts', '.tsx', '.js', '.jsx', '.vue', '.svelte'];
|
|
244
|
-
async function scan(dir) {
|
|
245
|
-
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
246
|
-
for (const entry of entries) {
|
|
247
|
-
const fullPath = join(dir, entry.name);
|
|
248
|
-
if (entry.isDirectory()) {
|
|
249
|
-
// 跳過常見的忽略目錄
|
|
250
|
-
if (!['node_modules', '.git', 'dist', 'build', '.next'].includes(entry.name)) {
|
|
251
|
-
await scan(fullPath);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
else if (entry.isFile()) {
|
|
255
|
-
const ext = extname(entry.name);
|
|
256
|
-
if (supportedExtensions.includes(ext)) {
|
|
257
|
-
files.push(fullPath);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
await scan(projectPath);
|
|
263
|
-
return files;
|
|
264
|
-
}
|
|
265
|
-
/**
|
|
266
|
-
* 計算嵌套深度
|
|
267
|
-
*/
|
|
268
|
-
calculateNestingDepth(content) {
|
|
269
|
-
let maxDepth = 0;
|
|
270
|
-
let currentDepth = 0;
|
|
271
|
-
for (const char of content) {
|
|
272
|
-
if (char === '{') {
|
|
273
|
-
currentDepth++;
|
|
274
|
-
maxDepth = Math.max(maxDepth, currentDepth);
|
|
275
|
-
}
|
|
276
|
-
else if (char === '}') {
|
|
277
|
-
currentDepth--;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
return maxDepth;
|
|
281
|
-
}
|
|
282
|
-
/**
|
|
283
|
-
* 計算循環複雜度(簡化版本)
|
|
284
|
-
*/
|
|
285
|
-
calculateCyclomaticComplexity(content) {
|
|
286
|
-
// 基礎複雜度為 1
|
|
287
|
-
let complexity = 1;
|
|
288
|
-
// 計算條件分支
|
|
289
|
-
const conditions = [
|
|
290
|
-
/if\s*\(/g,
|
|
291
|
-
/else\s+if\s*\(/g,
|
|
292
|
-
/while\s*\(/g,
|
|
293
|
-
/for\s*\(/g,
|
|
294
|
-
/case\s+/g,
|
|
295
|
-
/catch\s*\(/g,
|
|
296
|
-
/\?\s*:/g, // 三元運算子
|
|
297
|
-
/&&/g,
|
|
298
|
-
/\|\|/g
|
|
299
|
-
];
|
|
300
|
-
for (const pattern of conditions) {
|
|
301
|
-
const matches = content.match(pattern);
|
|
302
|
-
if (matches) {
|
|
303
|
-
complexity += matches.length;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
return complexity;
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* 計算嚴重程度
|
|
310
|
-
*/
|
|
311
|
-
calculateSeverity(value, threshold, maxSeverity) {
|
|
312
|
-
const ratio = value / threshold;
|
|
313
|
-
return Math.min(maxSeverity, Math.ceil(ratio * 3));
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* 計算專案統計摘要
|
|
317
|
-
*/
|
|
318
|
-
calculateSummary(fileResults) {
|
|
319
|
-
const totalFiles = fileResults.length;
|
|
320
|
-
const totalSize = fileResults.reduce((sum, file) => sum + file.fileSize, 0);
|
|
321
|
-
const averageFileSize = totalFiles > 0 ? totalSize / totalFiles : 0;
|
|
322
|
-
const largeFileCount = fileResults.filter(file => file.fileSize > 50000).length;
|
|
323
|
-
const longFunctionCount = fileResults.reduce((sum, file) => sum + file.longFunctionCount, 0);
|
|
324
|
-
const highComplexityCount = fileResults.filter(file => file.cyclomaticComplexity > 10).length;
|
|
325
|
-
// 計算整體效能評分 (1-100)
|
|
326
|
-
const sizeScore = Math.max(0, 100 - (largeFileCount / totalFiles) * 100);
|
|
327
|
-
const functionScore = Math.max(0, 100 - (longFunctionCount / totalFiles) * 20);
|
|
328
|
-
const complexityScore = Math.max(0, 100 - (highComplexityCount / totalFiles) * 100);
|
|
329
|
-
const overallScore = Math.round((sizeScore + functionScore + complexityScore) / 3);
|
|
330
|
-
return {
|
|
331
|
-
totalFiles,
|
|
332
|
-
totalSize,
|
|
333
|
-
averageFileSize,
|
|
334
|
-
largeFileCount,
|
|
335
|
-
longFunctionCount,
|
|
336
|
-
highComplexityCount,
|
|
337
|
-
overallScore
|
|
338
|
-
};
|
|
339
|
-
}
|
|
340
|
-
/**
|
|
341
|
-
* 生成優化建議
|
|
342
|
-
*/
|
|
343
|
-
generateRecommendations(issues, summary) {
|
|
344
|
-
const recommendations = [];
|
|
345
|
-
// 基於問題類型的建議
|
|
346
|
-
const issueTypes = new Set(issues.map(issue => issue.type));
|
|
347
|
-
if (issueTypes.has(PerformanceIssueType.LARGE_FILE)) {
|
|
348
|
-
recommendations.push('考慮拆分大型檔案以提高載入和解析效能');
|
|
349
|
-
}
|
|
350
|
-
if (issueTypes.has(PerformanceIssueType.LONG_FUNCTION)) {
|
|
351
|
-
recommendations.push('重構長函式以提高可讀性和可維護性');
|
|
352
|
-
}
|
|
353
|
-
if (issueTypes.has(PerformanceIssueType.HIGH_COMPLEXITY)) {
|
|
354
|
-
recommendations.push('簡化複雜的邏輯以減少 CPU 負擔');
|
|
355
|
-
}
|
|
356
|
-
if (issueTypes.has(PerformanceIssueType.DEEP_NESTING)) {
|
|
357
|
-
recommendations.push('減少深度嵌套以提高執行效率');
|
|
358
|
-
}
|
|
359
|
-
// 基於整體統計的建議
|
|
360
|
-
if (summary.overallScore < 70) {
|
|
361
|
-
recommendations.push('專案整體效能需要優化,建議進行全面的程式碼審查');
|
|
362
|
-
}
|
|
363
|
-
if (summary.largeFileCount > summary.totalFiles * 0.2) {
|
|
364
|
-
recommendations.push('考慮採用模組化架構以改善專案結構');
|
|
365
|
-
}
|
|
366
|
-
if (recommendations.length === 0) {
|
|
367
|
-
recommendations.push('程式碼效能良好,繼續保持良好的開發實踐');
|
|
368
|
-
}
|
|
369
|
-
return recommendations;
|
|
370
|
-
}
|
|
371
|
-
/**
|
|
372
|
-
* 清理快取
|
|
373
|
-
*/
|
|
374
|
-
clearCache() {
|
|
375
|
-
this.analysisCache.clear();
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
//# sourceMappingURL=analyzer.js.map
|
|
@@ -1 +0,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AAY,CAAC,EAAE,CAAC;YACtD,eAAe,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QACxC,CAAC;QAED,YAAY;QACZ,IAAI,OAAO,CAAC,YAAY,GAAG,EAAE,EAAE,CAAC;YAC9B,eAAe,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;QAClD,CAAC;QAED,IAAI,OAAO,CAAC,cAAc,GAAG,OAAO,CAAC,UAAU,GAAG,GAAG,EAAE,CAAC;YACtD,eAAe,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;QAC3C,CAAC;QAED,IAAI,eAAe,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACjC,eAAe,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;QAC9C,CAAC;QAED,OAAO,eAAe,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,UAAU;QACR,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;CACF"}
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Performance Cache Manager
|
|
3
|
-
* 為效能分析提供智能快取管理
|
|
4
|
-
*/
|
|
5
|
-
import { CacheStatistics } from './interfaces.js';
|
|
6
|
-
/**
|
|
7
|
-
* 快取策略
|
|
8
|
-
*/
|
|
9
|
-
export declare enum CacheStrategy {
|
|
10
|
-
LRU = "lru",// 最近最少使用
|
|
11
|
-
LFU = "lfu",// 最少頻率使用
|
|
12
|
-
TTL = "ttl",// 基於時間
|
|
13
|
-
HYBRID = "hybrid"
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* 快取配置
|
|
17
|
-
*/
|
|
18
|
-
export interface CacheConfig {
|
|
19
|
-
/** 最大快取項目數 */
|
|
20
|
-
maxSize: number;
|
|
21
|
-
/** 預設 TTL(毫秒) */
|
|
22
|
-
defaultTtl?: number;
|
|
23
|
-
/** 快取策略 */
|
|
24
|
-
strategy: CacheStrategy;
|
|
25
|
-
/** 清理間隔(毫秒) */
|
|
26
|
-
cleanupInterval?: number;
|
|
27
|
-
/** 啟用統計 */
|
|
28
|
-
enableStats: boolean;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* 預設快取配置
|
|
32
|
-
*/
|
|
33
|
-
export declare const DEFAULT_CACHE_CONFIG: CacheConfig;
|
|
34
|
-
/**
|
|
35
|
-
* 效能快取管理器
|
|
36
|
-
*/
|
|
37
|
-
export declare class PerformanceCacheManager<T = any> {
|
|
38
|
-
private cache;
|
|
39
|
-
private config;
|
|
40
|
-
private stats;
|
|
41
|
-
private cleanupTimer?;
|
|
42
|
-
constructor(config?: Partial<CacheConfig>);
|
|
43
|
-
/**
|
|
44
|
-
* 獲取快取項目
|
|
45
|
-
*/
|
|
46
|
-
get(key: string): T | null;
|
|
47
|
-
/**
|
|
48
|
-
* 設置快取項目
|
|
49
|
-
*/
|
|
50
|
-
set(key: string, value: T, ttl?: number): void;
|
|
51
|
-
/**
|
|
52
|
-
* 檢查是否存在
|
|
53
|
-
*/
|
|
54
|
-
has(key: string): boolean;
|
|
55
|
-
/**
|
|
56
|
-
* 刪除快取項目
|
|
57
|
-
*/
|
|
58
|
-
delete(key: string): boolean;
|
|
59
|
-
/**
|
|
60
|
-
* 清空快取
|
|
61
|
-
*/
|
|
62
|
-
clear(): void;
|
|
63
|
-
/**
|
|
64
|
-
* 獲取快取統計
|
|
65
|
-
*/
|
|
66
|
-
getStatistics(): CacheStatistics;
|
|
67
|
-
/**
|
|
68
|
-
* 重置統計
|
|
69
|
-
*/
|
|
70
|
-
resetStatistics(): void;
|
|
71
|
-
/**
|
|
72
|
-
* 獲取所有鍵
|
|
73
|
-
*/
|
|
74
|
-
keys(): string[];
|
|
75
|
-
/**
|
|
76
|
-
* 獲取快取項目數
|
|
77
|
-
*/
|
|
78
|
-
size(): number;
|
|
79
|
-
/**
|
|
80
|
-
* 手動清理過期項目
|
|
81
|
-
*/
|
|
82
|
-
cleanup(): number;
|
|
83
|
-
/**
|
|
84
|
-
* 根據模式刪除項目
|
|
85
|
-
*/
|
|
86
|
-
deleteByPattern(pattern: RegExp): number;
|
|
87
|
-
/**
|
|
88
|
-
* 預熱快取
|
|
89
|
-
*/
|
|
90
|
-
warmup(loader: (key: string) => Promise<T>, keys: string[]): Promise<void>;
|
|
91
|
-
/**
|
|
92
|
-
* 批量獲取
|
|
93
|
-
*/
|
|
94
|
-
getBatch(keys: string[]): Map<string, T>;
|
|
95
|
-
/**
|
|
96
|
-
* 批量設置
|
|
97
|
-
*/
|
|
98
|
-
setBatch(items: Map<string, T>, ttl?: number): void;
|
|
99
|
-
/**
|
|
100
|
-
* 獲取快取使用情況
|
|
101
|
-
*/
|
|
102
|
-
getUsageInfo(): {
|
|
103
|
-
memoryUsage: number;
|
|
104
|
-
itemCount: number;
|
|
105
|
-
oldestItem: Date | null;
|
|
106
|
-
newestItem: Date | null;
|
|
107
|
-
mostAccessed: {
|
|
108
|
-
key: string;
|
|
109
|
-
count: number;
|
|
110
|
-
} | null;
|
|
111
|
-
};
|
|
112
|
-
/**
|
|
113
|
-
* 清理資源
|
|
114
|
-
*/
|
|
115
|
-
dispose(): void;
|
|
116
|
-
/**
|
|
117
|
-
* 檢查項目是否過期
|
|
118
|
-
*/
|
|
119
|
-
private isExpired;
|
|
120
|
-
/**
|
|
121
|
-
* 淘汰項目
|
|
122
|
-
*/
|
|
123
|
-
private evictItems;
|
|
124
|
-
/**
|
|
125
|
-
* 獲取 LRU 項目
|
|
126
|
-
*/
|
|
127
|
-
private getLRUItems;
|
|
128
|
-
/**
|
|
129
|
-
* 獲取 LFU 項目
|
|
130
|
-
*/
|
|
131
|
-
private getLFUItems;
|
|
132
|
-
/**
|
|
133
|
-
* 獲取過期項目
|
|
134
|
-
*/
|
|
135
|
-
private getExpiredItems;
|
|
136
|
-
/**
|
|
137
|
-
* 啟動清理定時器
|
|
138
|
-
*/
|
|
139
|
-
private startCleanupTimer;
|
|
140
|
-
/**
|
|
141
|
-
* 更新統計資訊
|
|
142
|
-
*/
|
|
143
|
-
private updateStats;
|
|
144
|
-
/**
|
|
145
|
-
* 更新大小統計
|
|
146
|
-
*/
|
|
147
|
-
private updateStatsSize;
|
|
148
|
-
/**
|
|
149
|
-
* 計算快取大小(估算)
|
|
150
|
-
*/
|
|
151
|
-
private calculateSize;
|
|
152
|
-
/**
|
|
153
|
-
* 估算物件大小
|
|
154
|
-
*/
|
|
155
|
-
private estimateObjectSize;
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* 全域效能快取實例
|
|
159
|
-
*/
|
|
160
|
-
export declare const globalPerformanceCache: PerformanceCacheManager<any>;
|
|
161
|
-
//# sourceMappingURL=cache-manager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cache-manager.d.ts","sourceRoot":"","sources":["../../../src/core/performance/cache-manager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAalD;;GAEG;AACH,oBAAY,aAAa;IACvB,GAAG,QAAQ,CAAE,SAAS;IACtB,GAAG,QAAQ,CAAE,SAAS;IACtB,GAAG,QAAQ,CAAE,OAAO;IACpB,MAAM,WAAW;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,cAAc;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW;IACX,QAAQ,EAAE,aAAa,CAAC;IACxB,eAAe;IACf,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW;IACX,WAAW,EAAE,OAAO,CAAC;CACtB;AAED;;GAEG;AACH,eAAO,MAAM,oBAAoB,EAAE,WAMlC,CAAC;AAEF;;GAEG;AACH,qBAAa,uBAAuB,CAAC,CAAC,GAAG,GAAG;IAC1C,OAAO,CAAC,KAAK,CAAmC;IAChD,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,KAAK,CAAkB;IAC/B,OAA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