agent-ide 0.1.9 → 0.2.0
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.md +103 -17
- package/dist/application/services/module-coordinator.service.d.ts +0 -1
- package/dist/application/services/module-coordinator.service.d.ts.map +1 -1
- package/dist/application/services/module-coordinator.service.js +2 -8
- package/dist/application/services/module-coordinator.service.js.map +1 -1
- package/dist/core/analysis/index.d.ts +1 -4
- package/dist/core/analysis/index.d.ts.map +1 -1
- package/dist/core/analysis/index.js +1 -7
- package/dist/core/analysis/index.js.map +1 -1
- package/dist/core/dependency/dependency-analyzer.d.ts.map +1 -1
- package/dist/core/dependency/dependency-analyzer.js +10 -0
- package/dist/core/dependency/dependency-analyzer.js.map +1 -1
- package/dist/core/indexing/index-engine.d.ts +4 -0
- package/dist/core/indexing/index-engine.d.ts.map +1 -1
- package/dist/core/indexing/index-engine.js +25 -1
- package/dist/core/indexing/index-engine.js.map +1 -1
- package/dist/core/indexing/symbol-index.d.ts +4 -0
- package/dist/core/indexing/symbol-index.d.ts.map +1 -1
- package/dist/core/indexing/symbol-index.js +17 -0
- package/dist/core/indexing/symbol-index.js.map +1 -1
- package/dist/core/move/import-resolver.d.ts.map +1 -1
- package/dist/core/move/import-resolver.js +8 -0
- package/dist/core/move/import-resolver.js.map +1 -1
- package/dist/core/move/move-service.js +7 -7
- package/dist/core/move/move-service.js.map +1 -1
- package/dist/core/refactor/swift-extractor.d.ts +98 -0
- package/dist/core/refactor/swift-extractor.d.ts.map +1 -0
- package/dist/core/refactor/swift-extractor.js +283 -0
- package/dist/core/refactor/swift-extractor.js.map +1 -0
- package/dist/core/rename/reference-updater.d.ts.map +1 -1
- package/dist/core/rename/reference-updater.js +16 -8
- package/dist/core/rename/reference-updater.js.map +1 -1
- package/dist/core/search/engines/text-engine.js +1 -1
- package/dist/core/search/engines/text-engine.js.map +1 -1
- package/dist/core/shit-score/grading.d.ts +39 -0
- package/dist/core/shit-score/grading.d.ts.map +1 -0
- package/dist/core/shit-score/grading.js +253 -0
- package/dist/core/shit-score/grading.js.map +1 -0
- package/dist/core/shit-score/index.d.ts +9 -0
- package/dist/core/shit-score/index.d.ts.map +1 -0
- package/dist/core/shit-score/index.js +8 -0
- package/dist/core/shit-score/index.js.map +1 -0
- package/dist/core/shit-score/score-calculator.d.ts +75 -0
- package/dist/core/shit-score/score-calculator.d.ts.map +1 -0
- package/dist/core/shit-score/score-calculator.js +240 -0
- package/dist/core/shit-score/score-calculator.js.map +1 -0
- package/dist/core/shit-score/shit-score-analyzer.d.ts +84 -0
- package/dist/core/shit-score/shit-score-analyzer.d.ts.map +1 -0
- package/dist/core/shit-score/shit-score-analyzer.js +595 -0
- package/dist/core/shit-score/shit-score-analyzer.js.map +1 -0
- package/dist/core/shit-score/types.d.ts +231 -0
- package/dist/core/shit-score/types.d.ts.map +1 -0
- package/dist/core/shit-score/types.js +73 -0
- package/dist/core/shit-score/types.js.map +1 -0
- package/dist/core/snapshot/code-compressor.d.ts +39 -0
- package/dist/core/snapshot/code-compressor.d.ts.map +1 -0
- package/dist/core/snapshot/code-compressor.js +211 -0
- package/dist/core/snapshot/code-compressor.js.map +1 -0
- package/dist/core/snapshot/config.d.ts +60 -0
- package/dist/core/snapshot/config.d.ts.map +1 -0
- package/dist/core/snapshot/config.js +136 -0
- package/dist/core/snapshot/config.js.map +1 -0
- package/dist/core/snapshot/index.d.ts +23 -0
- package/dist/core/snapshot/index.d.ts.map +1 -0
- package/dist/core/snapshot/index.js +27 -0
- package/dist/core/snapshot/index.js.map +1 -0
- package/dist/core/snapshot/snapshot-differ.d.ts +54 -0
- package/dist/core/snapshot/snapshot-differ.d.ts.map +1 -0
- package/dist/core/snapshot/snapshot-differ.js +262 -0
- package/dist/core/snapshot/snapshot-differ.js.map +1 -0
- package/dist/core/snapshot/snapshot-engine.d.ts +94 -0
- package/dist/core/snapshot/snapshot-engine.d.ts.map +1 -0
- package/dist/core/snapshot/snapshot-engine.js +492 -0
- package/dist/core/snapshot/snapshot-engine.js.map +1 -0
- package/dist/core/snapshot/types.d.ts +216 -0
- package/dist/core/snapshot/types.d.ts.map +1 -0
- package/dist/core/snapshot/types.js +79 -0
- package/dist/core/snapshot/types.js.map +1 -0
- package/dist/infrastructure/parser/analysis-types.d.ts +198 -0
- package/dist/infrastructure/parser/analysis-types.d.ts.map +1 -0
- package/dist/infrastructure/parser/analysis-types.js +6 -0
- package/dist/infrastructure/parser/analysis-types.js.map +1 -0
- package/dist/infrastructure/parser/base.d.ts +36 -0
- package/dist/infrastructure/parser/base.d.ts.map +1 -1
- package/dist/infrastructure/parser/base.js +72 -0
- package/dist/infrastructure/parser/base.js.map +1 -1
- package/dist/infrastructure/parser/index.d.ts +1 -0
- package/dist/infrastructure/parser/index.d.ts.map +1 -1
- package/dist/infrastructure/parser/index.js.map +1 -1
- package/dist/infrastructure/parser/interface.d.ts +63 -0
- package/dist/infrastructure/parser/interface.d.ts.map +1 -1
- package/dist/infrastructure/parser/interface.js +11 -1
- package/dist/infrastructure/parser/interface.js.map +1 -1
- package/dist/interfaces/cli/cli.d.ts +24 -0
- package/dist/interfaces/cli/cli.d.ts.map +1 -1
- package/dist/interfaces/cli/cli.js +1483 -157
- package/dist/interfaces/cli/cli.js.map +1 -1
- package/dist/plugins/javascript/parser.d.ts +41 -0
- package/dist/plugins/javascript/parser.d.ts.map +1 -1
- package/dist/plugins/javascript/parser.js +284 -0
- package/dist/plugins/javascript/parser.js.map +1 -1
- package/dist/plugins/swift/analyzers/complexity-analyzer.d.ts +41 -0
- package/dist/plugins/swift/analyzers/complexity-analyzer.d.ts.map +1 -0
- package/dist/plugins/swift/analyzers/complexity-analyzer.js +206 -0
- package/dist/plugins/swift/analyzers/complexity-analyzer.js.map +1 -0
- package/dist/plugins/swift/analyzers/duplication-detector.d.ts +89 -0
- package/dist/plugins/swift/analyzers/duplication-detector.d.ts.map +1 -0
- package/dist/plugins/swift/analyzers/duplication-detector.js +271 -0
- package/dist/plugins/swift/analyzers/duplication-detector.js.map +1 -0
- package/dist/plugins/swift/analyzers/error-handling-checker.d.ts +34 -0
- package/dist/plugins/swift/analyzers/error-handling-checker.d.ts.map +1 -0
- package/dist/plugins/swift/analyzers/error-handling-checker.js +135 -0
- package/dist/plugins/swift/analyzers/error-handling-checker.js.map +1 -0
- package/dist/plugins/swift/analyzers/naming-checker.d.ts +47 -0
- package/dist/plugins/swift/analyzers/naming-checker.d.ts.map +1 -0
- package/dist/plugins/swift/analyzers/naming-checker.js +161 -0
- package/dist/plugins/swift/analyzers/naming-checker.js.map +1 -0
- package/dist/plugins/swift/analyzers/pattern-detector.d.ts +78 -0
- package/dist/plugins/swift/analyzers/pattern-detector.d.ts.map +1 -0
- package/dist/plugins/swift/analyzers/pattern-detector.js +247 -0
- package/dist/plugins/swift/analyzers/pattern-detector.js.map +1 -0
- package/dist/plugins/swift/analyzers/security-checker.d.ts +38 -0
- package/dist/plugins/swift/analyzers/security-checker.d.ts.map +1 -0
- package/dist/plugins/swift/analyzers/security-checker.js +135 -0
- package/dist/plugins/swift/analyzers/security-checker.js.map +1 -0
- package/dist/plugins/swift/analyzers/test-coverage-checker.d.ts +26 -0
- package/dist/plugins/swift/analyzers/test-coverage-checker.d.ts.map +1 -0
- package/dist/plugins/swift/analyzers/test-coverage-checker.js +63 -0
- package/dist/plugins/swift/analyzers/test-coverage-checker.js.map +1 -0
- package/dist/plugins/swift/analyzers/type-safety-checker.d.ts +41 -0
- package/dist/plugins/swift/analyzers/type-safety-checker.d.ts.map +1 -0
- package/dist/plugins/swift/analyzers/type-safety-checker.js +121 -0
- package/dist/plugins/swift/analyzers/type-safety-checker.js.map +1 -0
- package/dist/plugins/swift/analyzers/unused-symbol-detector.d.ts +38 -0
- package/dist/plugins/swift/analyzers/unused-symbol-detector.d.ts.map +1 -0
- package/dist/plugins/swift/analyzers/unused-symbol-detector.js +211 -0
- package/dist/plugins/swift/analyzers/unused-symbol-detector.js.map +1 -0
- package/dist/plugins/swift/dependency-analyzer.d.ts +33 -0
- package/dist/plugins/swift/dependency-analyzer.d.ts.map +1 -0
- package/dist/plugins/swift/dependency-analyzer.js +95 -0
- package/dist/plugins/swift/dependency-analyzer.js.map +1 -0
- package/dist/plugins/swift/index.d.ts +14 -0
- package/dist/plugins/swift/index.d.ts.map +1 -0
- package/dist/plugins/swift/index.js +19 -0
- package/dist/plugins/swift/index.js.map +1 -0
- package/dist/plugins/swift/parser.d.ts +160 -0
- package/dist/plugins/swift/parser.d.ts.map +1 -0
- package/dist/plugins/swift/parser.js +670 -0
- package/dist/plugins/swift/parser.js.map +1 -0
- package/dist/plugins/swift/swift-bridge/swift-parser +0 -0
- package/dist/plugins/swift/symbol-extractor.d.ts +46 -0
- package/dist/plugins/swift/symbol-extractor.d.ts.map +1 -0
- package/dist/plugins/swift/symbol-extractor.js +187 -0
- package/dist/plugins/swift/symbol-extractor.js.map +1 -0
- package/dist/plugins/swift/types.d.ts +137 -0
- package/dist/plugins/swift/types.d.ts.map +1 -0
- package/dist/plugins/swift/types.js +212 -0
- package/dist/plugins/swift/types.js.map +1 -0
- package/dist/plugins/typescript/analyzers/complexity-analyzer.d.ts +39 -0
- package/dist/plugins/typescript/analyzers/complexity-analyzer.d.ts.map +1 -0
- package/dist/plugins/typescript/analyzers/complexity-analyzer.js +196 -0
- package/dist/plugins/typescript/analyzers/complexity-analyzer.js.map +1 -0
- package/dist/{core/analysis → plugins/typescript/analyzers}/duplication-detector.d.ts +34 -3
- package/dist/plugins/typescript/analyzers/duplication-detector.d.ts.map +1 -0
- package/dist/plugins/typescript/analyzers/duplication-detector.js +695 -0
- package/dist/plugins/typescript/analyzers/duplication-detector.js.map +1 -0
- package/dist/plugins/typescript/analyzers/error-handling-checker.d.ts +26 -0
- package/dist/plugins/typescript/analyzers/error-handling-checker.d.ts.map +1 -0
- package/dist/plugins/typescript/analyzers/error-handling-checker.js +84 -0
- package/dist/plugins/typescript/analyzers/error-handling-checker.js.map +1 -0
- package/dist/plugins/typescript/analyzers/naming-checker.d.ts +30 -0
- package/dist/plugins/typescript/analyzers/naming-checker.d.ts.map +1 -0
- package/dist/plugins/typescript/analyzers/naming-checker.js +116 -0
- package/dist/plugins/typescript/analyzers/naming-checker.js.map +1 -0
- package/dist/plugins/typescript/analyzers/pattern-detector.d.ts +80 -0
- package/dist/plugins/typescript/analyzers/pattern-detector.d.ts.map +1 -0
- package/dist/plugins/typescript/analyzers/pattern-detector.js +267 -0
- package/dist/plugins/typescript/analyzers/pattern-detector.js.map +1 -0
- package/dist/plugins/typescript/analyzers/security-checker.d.ts +34 -0
- package/dist/plugins/typescript/analyzers/security-checker.d.ts.map +1 -0
- package/dist/plugins/typescript/analyzers/security-checker.js +126 -0
- package/dist/plugins/typescript/analyzers/security-checker.js.map +1 -0
- package/dist/plugins/typescript/analyzers/test-coverage-checker.d.ts +22 -0
- package/dist/plugins/typescript/analyzers/test-coverage-checker.d.ts.map +1 -0
- package/dist/plugins/typescript/analyzers/test-coverage-checker.js +62 -0
- package/dist/plugins/typescript/analyzers/test-coverage-checker.js.map +1 -0
- package/dist/plugins/typescript/analyzers/type-safety-checker.d.ts +32 -0
- package/dist/plugins/typescript/analyzers/type-safety-checker.d.ts.map +1 -0
- package/dist/plugins/typescript/analyzers/type-safety-checker.js +86 -0
- package/dist/plugins/typescript/analyzers/type-safety-checker.js.map +1 -0
- package/dist/plugins/typescript/analyzers/unused-symbol-detector.d.ts +47 -0
- package/dist/plugins/typescript/analyzers/unused-symbol-detector.d.ts.map +1 -0
- package/dist/plugins/typescript/analyzers/unused-symbol-detector.js +152 -0
- package/dist/plugins/typescript/analyzers/unused-symbol-detector.js.map +1 -0
- package/dist/plugins/typescript/parser.d.ts +41 -0
- package/dist/plugins/typescript/parser.d.ts.map +1 -1
- package/dist/plugins/typescript/parser.js +336 -0
- package/dist/plugins/typescript/parser.js.map +1 -1
- package/dist/shared/types/symbol.d.ts +7 -1
- package/dist/shared/types/symbol.d.ts.map +1 -1
- package/dist/shared/types/symbol.js +8 -2
- package/dist/shared/types/symbol.js.map +1 -1
- package/package.json +17 -7
- package/bin/mcp-server.js +0 -20
- package/dist/core/analysis/complexity-analyzer.d.ts +0 -81
- package/dist/core/analysis/complexity-analyzer.d.ts.map +0 -1
- package/dist/core/analysis/complexity-analyzer.js +0 -255
- package/dist/core/analysis/complexity-analyzer.js.map +0 -1
- package/dist/core/analysis/dead-code-detector.d.ts +0 -152
- package/dist/core/analysis/dead-code-detector.d.ts.map +0 -1
- package/dist/core/analysis/dead-code-detector.js +0 -351
- package/dist/core/analysis/dead-code-detector.js.map +0 -1
- package/dist/core/analysis/duplication-detector.d.ts.map +0 -1
- package/dist/core/analysis/duplication-detector.js +0 -433
- package/dist/core/analysis/duplication-detector.js.map +0 -1
- package/dist/interfaces/mcp/index.d.ts +0 -7
- package/dist/interfaces/mcp/index.d.ts.map +0 -1
- package/dist/interfaces/mcp/index.js +0 -6
- package/dist/interfaces/mcp/index.js.map +0 -1
- package/dist/interfaces/mcp/mcp-server.d.ts +0 -34
- package/dist/interfaces/mcp/mcp-server.d.ts.map +0 -1
- package/dist/interfaces/mcp/mcp-server.js +0 -162
- package/dist/interfaces/mcp/mcp-server.js.map +0 -1
- package/dist/interfaces/mcp/mcp.d.ts +0 -52
- package/dist/interfaces/mcp/mcp.d.ts.map +0 -1
- package/dist/interfaces/mcp/mcp.js +0 -843
- package/dist/interfaces/mcp/mcp.js.map +0 -1
|
@@ -1,843 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MCP (Model Context Protocol) 介面實作
|
|
3
|
-
* 提供給 Claude Code 等 AI 工具使用的 MCP 工具
|
|
4
|
-
*/
|
|
5
|
-
import * as path from 'path';
|
|
6
|
-
import * as fs from 'fs/promises';
|
|
7
|
-
import { IndexEngine } from '../../core/indexing/index-engine.js';
|
|
8
|
-
import { DependencyAnalyzer } from '../../core/dependency/dependency-analyzer.js';
|
|
9
|
-
import { RenameEngine } from '../../core/rename/rename-engine.js';
|
|
10
|
-
import { MoveService } from '../../core/move/move-service.js';
|
|
11
|
-
import { ComplexityAnalyzer } from '../../core/analysis/complexity-analyzer.js';
|
|
12
|
-
import { QualityMetricsAnalyzer } from '../../core/analysis/quality-metrics.js';
|
|
13
|
-
import { createIndexConfig } from '../../core/indexing/types.js';
|
|
14
|
-
import { ParserRegistry } from '../../infrastructure/parser/registry.js';
|
|
15
|
-
import { TypeScriptParser } from '../../plugins/typescript/parser.js';
|
|
16
|
-
import { JavaScriptParser } from '../../plugins/javascript/parser.js';
|
|
17
|
-
import { glob } from 'glob';
|
|
18
|
-
export class AgentIdeMCP {
|
|
19
|
-
indexEngine;
|
|
20
|
-
dependencyAnalyzer;
|
|
21
|
-
renameEngine;
|
|
22
|
-
importResolver;
|
|
23
|
-
parsersInitialized = false;
|
|
24
|
-
constructor() {
|
|
25
|
-
this.initializeParsers();
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* 初始化 Parser
|
|
29
|
-
*/
|
|
30
|
-
initializeParsers() {
|
|
31
|
-
if (this.parsersInitialized) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
const registry = ParserRegistry.getInstance();
|
|
35
|
-
// 註冊 TypeScript Parser
|
|
36
|
-
const tsParser = new TypeScriptParser();
|
|
37
|
-
registry.register(tsParser);
|
|
38
|
-
// 註冊 JavaScript Parser
|
|
39
|
-
const jsParser = new JavaScriptParser();
|
|
40
|
-
registry.register(jsParser);
|
|
41
|
-
this.parsersInitialized = true;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* 獲取所有可用的 MCP 工具定義
|
|
45
|
-
*/
|
|
46
|
-
getTools() {
|
|
47
|
-
return [
|
|
48
|
-
{
|
|
49
|
-
name: 'code_index',
|
|
50
|
-
description: '建立和查詢程式碼索引,提供符號搜尋和檔案索引功能',
|
|
51
|
-
parameters: {
|
|
52
|
-
type: 'object',
|
|
53
|
-
properties: {
|
|
54
|
-
action: {
|
|
55
|
-
type: 'string',
|
|
56
|
-
enum: ['create', 'update', 'search', 'stats'],
|
|
57
|
-
description: '操作類型: create=建立索引, update=更新索引, search=搜尋符號, stats=獲取統計'
|
|
58
|
-
},
|
|
59
|
-
path: {
|
|
60
|
-
type: 'string',
|
|
61
|
-
description: '專案路徑(用於 create/update)'
|
|
62
|
-
},
|
|
63
|
-
query: {
|
|
64
|
-
type: 'string',
|
|
65
|
-
description: '搜尋查詢(用於 search)'
|
|
66
|
-
},
|
|
67
|
-
extensions: {
|
|
68
|
-
type: 'array',
|
|
69
|
-
items: { type: 'string' },
|
|
70
|
-
description: '包含的檔案副檔名',
|
|
71
|
-
default: ['.ts', '.js', '.tsx', '.jsx']
|
|
72
|
-
},
|
|
73
|
-
excludePatterns: {
|
|
74
|
-
type: 'array',
|
|
75
|
-
items: { type: 'string' },
|
|
76
|
-
description: '排除模式',
|
|
77
|
-
default: ['node_modules/**', '*.test.*']
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
required: ['action']
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
name: 'code_rename',
|
|
85
|
-
description: '執行安全的程式碼重新命名,自動更新所有引用',
|
|
86
|
-
parameters: {
|
|
87
|
-
type: 'object',
|
|
88
|
-
properties: {
|
|
89
|
-
type: {
|
|
90
|
-
type: 'string',
|
|
91
|
-
enum: ['variable', 'function', 'class', 'interface', 'file'],
|
|
92
|
-
description: '要重新命名的符號類型'
|
|
93
|
-
},
|
|
94
|
-
from: {
|
|
95
|
-
type: 'string',
|
|
96
|
-
description: '原始名稱'
|
|
97
|
-
},
|
|
98
|
-
to: {
|
|
99
|
-
type: 'string',
|
|
100
|
-
description: '新名稱'
|
|
101
|
-
},
|
|
102
|
-
path: {
|
|
103
|
-
type: 'string',
|
|
104
|
-
description: '檔案或目錄路徑',
|
|
105
|
-
default: '.'
|
|
106
|
-
},
|
|
107
|
-
preview: {
|
|
108
|
-
type: 'boolean',
|
|
109
|
-
description: '是否只預覽變更而不執行',
|
|
110
|
-
default: false
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
required: ['type', 'from', 'to']
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
name: 'code_move',
|
|
118
|
-
description: '移動檔案或目錄,自動更新 import 路徑',
|
|
119
|
-
parameters: {
|
|
120
|
-
type: 'object',
|
|
121
|
-
properties: {
|
|
122
|
-
source: {
|
|
123
|
-
type: 'string',
|
|
124
|
-
description: '來源路徑'
|
|
125
|
-
},
|
|
126
|
-
target: {
|
|
127
|
-
type: 'string',
|
|
128
|
-
description: '目標路徑'
|
|
129
|
-
},
|
|
130
|
-
updateImports: {
|
|
131
|
-
type: 'boolean',
|
|
132
|
-
description: '是否自動更新 import 路徑',
|
|
133
|
-
default: true
|
|
134
|
-
},
|
|
135
|
-
preview: {
|
|
136
|
-
type: 'boolean',
|
|
137
|
-
description: '是否只預覽變更而不執行',
|
|
138
|
-
default: false
|
|
139
|
-
}
|
|
140
|
-
},
|
|
141
|
-
required: ['source', 'target']
|
|
142
|
-
}
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
name: 'code_search',
|
|
146
|
-
description: '搜尋程式碼中的符號、文字或模式',
|
|
147
|
-
parameters: {
|
|
148
|
-
type: 'object',
|
|
149
|
-
properties: {
|
|
150
|
-
query: {
|
|
151
|
-
type: 'string',
|
|
152
|
-
description: '搜尋查詢'
|
|
153
|
-
},
|
|
154
|
-
type: {
|
|
155
|
-
type: 'string',
|
|
156
|
-
enum: ['symbol', 'text', 'regex'],
|
|
157
|
-
description: '搜尋類型',
|
|
158
|
-
default: 'symbol'
|
|
159
|
-
},
|
|
160
|
-
fileFilter: {
|
|
161
|
-
type: 'array',
|
|
162
|
-
items: { type: 'string' },
|
|
163
|
-
description: '檔案類型過濾'
|
|
164
|
-
},
|
|
165
|
-
limit: {
|
|
166
|
-
type: 'number',
|
|
167
|
-
description: '結果數量限制',
|
|
168
|
-
default: 50
|
|
169
|
-
}
|
|
170
|
-
},
|
|
171
|
-
required: ['query']
|
|
172
|
-
}
|
|
173
|
-
},
|
|
174
|
-
{
|
|
175
|
-
name: 'code_analyze',
|
|
176
|
-
description: '分析程式碼品質、複雜度和相關指標',
|
|
177
|
-
parameters: {
|
|
178
|
-
type: 'object',
|
|
179
|
-
properties: {
|
|
180
|
-
path: {
|
|
181
|
-
type: 'string',
|
|
182
|
-
description: '分析路徑',
|
|
183
|
-
default: '.'
|
|
184
|
-
},
|
|
185
|
-
type: {
|
|
186
|
-
type: 'string',
|
|
187
|
-
enum: ['complexity', 'dependencies', 'quality', 'all'],
|
|
188
|
-
description: '分析類型',
|
|
189
|
-
default: 'all'
|
|
190
|
-
},
|
|
191
|
-
format: {
|
|
192
|
-
type: 'string',
|
|
193
|
-
enum: ['json', 'summary'],
|
|
194
|
-
description: '輸出格式',
|
|
195
|
-
default: 'summary'
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
},
|
|
200
|
-
{
|
|
201
|
-
name: 'code_deps',
|
|
202
|
-
description: '分析程式碼依賴關係,檢測循環依賴和影響範圍',
|
|
203
|
-
parameters: {
|
|
204
|
-
type: 'object',
|
|
205
|
-
properties: {
|
|
206
|
-
path: {
|
|
207
|
-
type: 'string',
|
|
208
|
-
description: '分析路徑',
|
|
209
|
-
default: '.'
|
|
210
|
-
},
|
|
211
|
-
type: {
|
|
212
|
-
type: 'string',
|
|
213
|
-
enum: ['graph', 'cycles', 'impact', 'all'],
|
|
214
|
-
description: '分析類型',
|
|
215
|
-
default: 'all'
|
|
216
|
-
},
|
|
217
|
-
file: {
|
|
218
|
-
type: 'string',
|
|
219
|
-
description: '特定檔案分析(用於影響分析)'
|
|
220
|
-
},
|
|
221
|
-
format: {
|
|
222
|
-
type: 'string',
|
|
223
|
-
enum: ['json', 'dot', 'summary'],
|
|
224
|
-
description: '輸出格式',
|
|
225
|
-
default: 'summary'
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
},
|
|
230
|
-
{
|
|
231
|
-
name: 'parser_plugins',
|
|
232
|
-
description: '管理 Parser 插件,查看和操作插件狀態',
|
|
233
|
-
parameters: {
|
|
234
|
-
type: 'object',
|
|
235
|
-
properties: {
|
|
236
|
-
action: {
|
|
237
|
-
type: 'string',
|
|
238
|
-
enum: ['list', 'info', 'enable', 'disable'],
|
|
239
|
-
description: '操作類型'
|
|
240
|
-
},
|
|
241
|
-
plugin: {
|
|
242
|
-
type: 'string',
|
|
243
|
-
description: '插件名稱(用於 info/enable/disable)'
|
|
244
|
-
},
|
|
245
|
-
filter: {
|
|
246
|
-
type: 'string',
|
|
247
|
-
enum: ['all', 'enabled', 'disabled'],
|
|
248
|
-
description: '過濾條件(用於 list)',
|
|
249
|
-
default: 'all'
|
|
250
|
-
}
|
|
251
|
-
},
|
|
252
|
-
required: ['action']
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
];
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* 執行 MCP 工具
|
|
259
|
-
*/
|
|
260
|
-
async executeTool(toolName, parameters) {
|
|
261
|
-
try {
|
|
262
|
-
switch (toolName) {
|
|
263
|
-
case 'code_index':
|
|
264
|
-
return await this.handleCodeIndex(parameters);
|
|
265
|
-
case 'code_rename':
|
|
266
|
-
return await this.handleCodeRename(parameters);
|
|
267
|
-
case 'code_move':
|
|
268
|
-
return await this.handleCodeMove(parameters);
|
|
269
|
-
case 'code_search':
|
|
270
|
-
return await this.handleCodeSearch(parameters);
|
|
271
|
-
case 'code_analyze':
|
|
272
|
-
return await this.handleCodeAnalyze(parameters);
|
|
273
|
-
case 'code_deps':
|
|
274
|
-
return await this.handleCodeDeps(parameters);
|
|
275
|
-
case 'parser_plugins':
|
|
276
|
-
return await this.handleParserPlugins(parameters);
|
|
277
|
-
default:
|
|
278
|
-
return {
|
|
279
|
-
success: false,
|
|
280
|
-
error: `未知的工具: ${toolName}`
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
catch (error) {
|
|
285
|
-
return {
|
|
286
|
-
success: false,
|
|
287
|
-
error: error instanceof Error ? error.message : String(error)
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
// 工具處理方法
|
|
292
|
-
async handleCodeIndex(params) {
|
|
293
|
-
// 支援舊參數名稱以兼容測試
|
|
294
|
-
const action = params.action || 'create';
|
|
295
|
-
const projectPath = params.path;
|
|
296
|
-
const query = params.query;
|
|
297
|
-
const extensions = params.extensions || params.include;
|
|
298
|
-
const excludePatterns = params.excludePatterns || params.exclude;
|
|
299
|
-
switch (action) {
|
|
300
|
-
case 'create':
|
|
301
|
-
case 'update':
|
|
302
|
-
if (!projectPath) {
|
|
303
|
-
return { success: false, error: '需要指定專案路徑' };
|
|
304
|
-
}
|
|
305
|
-
try {
|
|
306
|
-
const config = createIndexConfig(projectPath, {
|
|
307
|
-
includeExtensions: extensions || ['.ts', '.js', '.tsx', '.jsx'],
|
|
308
|
-
excludePatterns: excludePatterns || ['node_modules/**', '*.test.*']
|
|
309
|
-
});
|
|
310
|
-
this.indexEngine = new IndexEngine(config);
|
|
311
|
-
await this.indexEngine.indexProject(projectPath);
|
|
312
|
-
const stats = await this.indexEngine.getStats();
|
|
313
|
-
return {
|
|
314
|
-
success: true,
|
|
315
|
-
data: {
|
|
316
|
-
action: action === 'create' ? '建立' : '更新',
|
|
317
|
-
filesIndexed: stats.totalFiles,
|
|
318
|
-
symbolsFound: stats.totalSymbols,
|
|
319
|
-
stats: {
|
|
320
|
-
totalFiles: stats.totalFiles,
|
|
321
|
-
totalSymbols: stats.totalSymbols,
|
|
322
|
-
indexedAt: new Date().toISOString()
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
|
-
catch (error) {
|
|
328
|
-
return {
|
|
329
|
-
success: false,
|
|
330
|
-
error: `建立索引失敗: ${error instanceof Error ? error.message : String(error)}`
|
|
331
|
-
};
|
|
332
|
-
}
|
|
333
|
-
case 'search':
|
|
334
|
-
if (!query) {
|
|
335
|
-
return { success: false, error: '需要指定搜尋查詢' };
|
|
336
|
-
}
|
|
337
|
-
if (!this.indexEngine) {
|
|
338
|
-
return { success: false, error: '索引尚未建立,請先執行 create 操作' };
|
|
339
|
-
}
|
|
340
|
-
const results = await this.indexEngine.findSymbol(query);
|
|
341
|
-
return {
|
|
342
|
-
success: true,
|
|
343
|
-
data: {
|
|
344
|
-
query,
|
|
345
|
-
results: results.map(r => ({
|
|
346
|
-
name: r.symbol.name,
|
|
347
|
-
type: r.symbol.type,
|
|
348
|
-
file: r.fileInfo.filePath,
|
|
349
|
-
line: r.symbol.location.range.start.line,
|
|
350
|
-
column: r.symbol.location.range.start.column,
|
|
351
|
-
score: r.score
|
|
352
|
-
}))
|
|
353
|
-
}
|
|
354
|
-
};
|
|
355
|
-
case 'stats':
|
|
356
|
-
if (!this.indexEngine) {
|
|
357
|
-
return { success: false, error: '索引尚未建立' };
|
|
358
|
-
}
|
|
359
|
-
const currentStats = await this.indexEngine.getStats();
|
|
360
|
-
return {
|
|
361
|
-
success: true,
|
|
362
|
-
data: currentStats
|
|
363
|
-
};
|
|
364
|
-
default:
|
|
365
|
-
return { success: false, error: `未知的索引操作: ${action}` };
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
async handleCodeRename(params) {
|
|
369
|
-
// 支援舊參數名稱以兼容測試
|
|
370
|
-
const type = params.type;
|
|
371
|
-
const from = params.from || params.symbol;
|
|
372
|
-
const to = params.to || params.newName;
|
|
373
|
-
const workspacePath = params.path || '.';
|
|
374
|
-
const preview = params.preview !== false; // 預設為 true
|
|
375
|
-
if (!from || !to) {
|
|
376
|
-
return { success: false, error: '需要指定原始名稱和新名稱' };
|
|
377
|
-
}
|
|
378
|
-
try {
|
|
379
|
-
// 初始化索引引擎
|
|
380
|
-
if (!this.indexEngine) {
|
|
381
|
-
const config = createIndexConfig(workspacePath, {
|
|
382
|
-
includeExtensions: ['.ts', '.tsx', '.js', '.jsx'],
|
|
383
|
-
excludePatterns: ['node_modules/**', '*.test.*']
|
|
384
|
-
});
|
|
385
|
-
this.indexEngine = new IndexEngine(config);
|
|
386
|
-
await this.indexEngine.indexProject(workspacePath);
|
|
387
|
-
}
|
|
388
|
-
// 初始化重新命名引擎
|
|
389
|
-
if (!this.renameEngine) {
|
|
390
|
-
this.renameEngine = new RenameEngine();
|
|
391
|
-
}
|
|
392
|
-
// 查找符號
|
|
393
|
-
const searchResults = await this.indexEngine.findSymbol(from);
|
|
394
|
-
if (searchResults.length === 0) {
|
|
395
|
-
return {
|
|
396
|
-
success: true, // 為了測試相容性,返回 success: true
|
|
397
|
-
data: {
|
|
398
|
-
changes: [],
|
|
399
|
-
filesAffected: 0
|
|
400
|
-
}
|
|
401
|
-
};
|
|
402
|
-
}
|
|
403
|
-
// 準備變更列表
|
|
404
|
-
const changes = searchResults.map(r => ({
|
|
405
|
-
file: r.fileInfo.filePath,
|
|
406
|
-
line: r.symbol.location.range.start.line,
|
|
407
|
-
column: r.symbol.location.range.start.column,
|
|
408
|
-
content: `${from} → ${to}`,
|
|
409
|
-
oldName: from,
|
|
410
|
-
newName: to
|
|
411
|
-
}));
|
|
412
|
-
return {
|
|
413
|
-
success: true,
|
|
414
|
-
data: {
|
|
415
|
-
changes,
|
|
416
|
-
filesAffected: new Set(changes.map(c => c.file)).size,
|
|
417
|
-
preview
|
|
418
|
-
}
|
|
419
|
-
};
|
|
420
|
-
}
|
|
421
|
-
catch (error) {
|
|
422
|
-
return {
|
|
423
|
-
success: false,
|
|
424
|
-
error: `重新命名失敗: ${error instanceof Error ? error.message : String(error)}`
|
|
425
|
-
};
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
async handleCodeMove(params) {
|
|
429
|
-
const { source, target, updateImports = true, preview = false } = params;
|
|
430
|
-
if (!source || !target) {
|
|
431
|
-
return { success: false, error: '需要指定來源路徑和目標路徑' };
|
|
432
|
-
}
|
|
433
|
-
try {
|
|
434
|
-
const workspacePath = process.cwd();
|
|
435
|
-
const sourcePath = path.isAbsolute(source) ? source : path.resolve(workspacePath, source);
|
|
436
|
-
const targetPath = path.isAbsolute(target) ? target : path.resolve(workspacePath, target);
|
|
437
|
-
const moveService = new MoveService();
|
|
438
|
-
const result = await moveService.moveFile({ source: sourcePath, target: targetPath, updateImports }, { preview, projectRoot: workspacePath });
|
|
439
|
-
if (!result.success) {
|
|
440
|
-
return {
|
|
441
|
-
success: false,
|
|
442
|
-
error: result.error || result.message
|
|
443
|
-
};
|
|
444
|
-
}
|
|
445
|
-
return {
|
|
446
|
-
success: true,
|
|
447
|
-
data: {
|
|
448
|
-
from: this.formatRelativePath(sourcePath, workspacePath),
|
|
449
|
-
to: this.formatRelativePath(targetPath, workspacePath),
|
|
450
|
-
filesUpdated: result.pathUpdates.length,
|
|
451
|
-
importUpdates: result.pathUpdates.map(update => ({
|
|
452
|
-
file: this.formatRelativePath(update.filePath, workspacePath),
|
|
453
|
-
line: update.line,
|
|
454
|
-
oldImport: update.oldImport,
|
|
455
|
-
newImport: update.newImport
|
|
456
|
-
})),
|
|
457
|
-
preview,
|
|
458
|
-
message: result.message
|
|
459
|
-
}
|
|
460
|
-
};
|
|
461
|
-
}
|
|
462
|
-
catch (error) {
|
|
463
|
-
return {
|
|
464
|
-
success: false,
|
|
465
|
-
error: `移動檔案失敗: ${error instanceof Error ? error.message : String(error)}`
|
|
466
|
-
};
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
async handleCodeSearch(params) {
|
|
470
|
-
const query = params.query;
|
|
471
|
-
const searchType = params.type || 'text';
|
|
472
|
-
const workspacePath = params.path || '.';
|
|
473
|
-
const fileFilter = params.fileFilter;
|
|
474
|
-
const limit = params.limit || 50;
|
|
475
|
-
if (!query) {
|
|
476
|
-
return { success: false, error: '需要指定搜尋查詢' };
|
|
477
|
-
}
|
|
478
|
-
try {
|
|
479
|
-
// 初始化索引引擎(如果需要)
|
|
480
|
-
if (!this.indexEngine && searchType === 'symbol') {
|
|
481
|
-
const config = createIndexConfig(workspacePath, {
|
|
482
|
-
includeExtensions: ['.ts', '.tsx', '.js', '.jsx'],
|
|
483
|
-
excludePatterns: ['node_modules/**', '*.test.*']
|
|
484
|
-
});
|
|
485
|
-
this.indexEngine = new IndexEngine(config);
|
|
486
|
-
await this.indexEngine.indexProject(workspacePath);
|
|
487
|
-
}
|
|
488
|
-
if (searchType === 'symbol' && this.indexEngine) {
|
|
489
|
-
// 符號搜尋
|
|
490
|
-
const results = await this.indexEngine.findSymbol(query);
|
|
491
|
-
return {
|
|
492
|
-
success: true,
|
|
493
|
-
data: {
|
|
494
|
-
query,
|
|
495
|
-
type: searchType,
|
|
496
|
-
results: results.slice(0, limit).map(r => ({
|
|
497
|
-
file: this.formatRelativePath(r.fileInfo.filePath, workspacePath),
|
|
498
|
-
line: r.symbol.location.range.start.line,
|
|
499
|
-
column: r.symbol.location.range.start.column,
|
|
500
|
-
content: r.symbol.name,
|
|
501
|
-
type: r.symbol.type,
|
|
502
|
-
score: r.score
|
|
503
|
-
}))
|
|
504
|
-
}
|
|
505
|
-
};
|
|
506
|
-
}
|
|
507
|
-
else {
|
|
508
|
-
// 文字搜尋
|
|
509
|
-
const files = await glob('**/*.{ts,tsx,js,jsx}', {
|
|
510
|
-
cwd: workspacePath,
|
|
511
|
-
ignore: ['node_modules/**', 'dist/**', '*.test.*', '*.d.ts'],
|
|
512
|
-
absolute: true
|
|
513
|
-
});
|
|
514
|
-
const results = [];
|
|
515
|
-
for (const file of files.slice(0, 100)) {
|
|
516
|
-
try {
|
|
517
|
-
const content = await fs.readFile(file, 'utf-8');
|
|
518
|
-
const lines = content.split('\n');
|
|
519
|
-
lines.forEach((line, index) => {
|
|
520
|
-
if (line.includes(query)) {
|
|
521
|
-
results.push({
|
|
522
|
-
file: this.formatRelativePath(file, workspacePath),
|
|
523
|
-
line: index + 1,
|
|
524
|
-
column: line.indexOf(query) + 1,
|
|
525
|
-
content: line.trim()
|
|
526
|
-
});
|
|
527
|
-
}
|
|
528
|
-
});
|
|
529
|
-
}
|
|
530
|
-
catch (error) {
|
|
531
|
-
// 忽略讀取錯誤
|
|
532
|
-
}
|
|
533
|
-
if (results.length >= limit) {
|
|
534
|
-
break;
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
return {
|
|
538
|
-
success: true,
|
|
539
|
-
data: {
|
|
540
|
-
query,
|
|
541
|
-
type: searchType,
|
|
542
|
-
results: results.slice(0, limit)
|
|
543
|
-
}
|
|
544
|
-
};
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
catch (error) {
|
|
548
|
-
return {
|
|
549
|
-
success: false,
|
|
550
|
-
error: `搜尋失敗: ${error instanceof Error ? error.message : String(error)}`
|
|
551
|
-
};
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
async handleCodeAnalyze(params) {
|
|
555
|
-
const analyzePath = params.path || '.';
|
|
556
|
-
const analyzeType = params.type || 'all';
|
|
557
|
-
const format = params.format || 'summary';
|
|
558
|
-
try {
|
|
559
|
-
const workspacePath = process.cwd();
|
|
560
|
-
const targetPath = path.isAbsolute(analyzePath)
|
|
561
|
-
? analyzePath
|
|
562
|
-
: path.resolve(workspacePath, analyzePath);
|
|
563
|
-
const results = {
|
|
564
|
-
path: this.formatRelativePath(targetPath, workspacePath),
|
|
565
|
-
type: analyzeType,
|
|
566
|
-
format
|
|
567
|
-
};
|
|
568
|
-
// 檢查路徑是否存在
|
|
569
|
-
try {
|
|
570
|
-
await fs.access(targetPath);
|
|
571
|
-
}
|
|
572
|
-
catch {
|
|
573
|
-
return { success: false, error: `路徑不存在: ${analyzePath}` };
|
|
574
|
-
}
|
|
575
|
-
const stat = await fs.stat(targetPath);
|
|
576
|
-
if (stat.isFile()) {
|
|
577
|
-
// 分析單一檔案
|
|
578
|
-
const content = await fs.readFile(targetPath, 'utf-8');
|
|
579
|
-
if (analyzeType === 'complexity' || analyzeType === 'all') {
|
|
580
|
-
const complexityAnalyzer = new ComplexityAnalyzer();
|
|
581
|
-
const complexityResult = await complexityAnalyzer.analyzeCode(content);
|
|
582
|
-
results.complexity = complexityResult;
|
|
583
|
-
}
|
|
584
|
-
if (analyzeType === 'quality' || analyzeType === 'all') {
|
|
585
|
-
const qualityAnalyzer = new QualityMetricsAnalyzer();
|
|
586
|
-
const qualityResult = await qualityAnalyzer.assess(content);
|
|
587
|
-
results.quality = qualityResult;
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
else if (stat.isDirectory()) {
|
|
591
|
-
// 分析目錄中的檔案
|
|
592
|
-
const files = await glob('**/*.{ts,tsx,js,jsx}', {
|
|
593
|
-
cwd: targetPath,
|
|
594
|
-
ignore: ['node_modules/**', 'dist/**', '*.test.*', '*.d.ts'],
|
|
595
|
-
absolute: true
|
|
596
|
-
});
|
|
597
|
-
const fileResults = [];
|
|
598
|
-
for (const file of files.slice(0, 10)) {
|
|
599
|
-
try {
|
|
600
|
-
const content = await fs.readFile(file, 'utf-8');
|
|
601
|
-
const fileResult = {
|
|
602
|
-
file: this.formatRelativePath(file, workspacePath)
|
|
603
|
-
};
|
|
604
|
-
if (analyzeType === 'complexity' || analyzeType === 'all') {
|
|
605
|
-
const complexityAnalyzer = new ComplexityAnalyzer();
|
|
606
|
-
fileResult.complexity = await complexityAnalyzer.analyzeCode(content);
|
|
607
|
-
}
|
|
608
|
-
if (analyzeType === 'quality' || analyzeType === 'all') {
|
|
609
|
-
const qualityAnalyzer = new QualityMetricsAnalyzer();
|
|
610
|
-
fileResult.quality = await qualityAnalyzer.assess(content);
|
|
611
|
-
}
|
|
612
|
-
fileResults.push(fileResult);
|
|
613
|
-
}
|
|
614
|
-
catch (error) {
|
|
615
|
-
// 忽略讀取錯誤
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
results.files = fileResults;
|
|
619
|
-
results.totalFiles = fileResults.length;
|
|
620
|
-
}
|
|
621
|
-
if (format === 'summary') {
|
|
622
|
-
return {
|
|
623
|
-
success: true,
|
|
624
|
-
data: {
|
|
625
|
-
...results,
|
|
626
|
-
summary: this.formatAnalysisSummary(results)
|
|
627
|
-
}
|
|
628
|
-
};
|
|
629
|
-
}
|
|
630
|
-
return {
|
|
631
|
-
success: true,
|
|
632
|
-
data: results
|
|
633
|
-
};
|
|
634
|
-
}
|
|
635
|
-
catch (error) {
|
|
636
|
-
return {
|
|
637
|
-
success: false,
|
|
638
|
-
error: `分析失敗: ${error instanceof Error ? error.message : String(error)}`
|
|
639
|
-
};
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
formatAnalysisSummary(results) {
|
|
643
|
-
const lines = [];
|
|
644
|
-
if (results.complexity) {
|
|
645
|
-
lines.push(`複雜度: ${results.complexity.evaluation} (循環: ${results.complexity.cyclomaticComplexity}, 認知: ${results.complexity.cognitiveComplexity})`);
|
|
646
|
-
}
|
|
647
|
-
if (results.quality) {
|
|
648
|
-
lines.push(`品質: ${results.quality.grade} (可維護性指數: ${results.quality.maintainabilityIndex})`);
|
|
649
|
-
if (results.quality.codeSmells?.length > 0) {
|
|
650
|
-
lines.push(`程式碼異味: ${results.quality.codeSmells.length} 個`);
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
if (results.files) {
|
|
654
|
-
const avgComplexity = results.files.reduce((sum, f) => sum + (f.complexity?.cyclomaticComplexity || 0), 0) / results.files.length;
|
|
655
|
-
lines.push(`平均循環複雜度: ${avgComplexity.toFixed(2)}`);
|
|
656
|
-
}
|
|
657
|
-
return lines.join('\n');
|
|
658
|
-
}
|
|
659
|
-
async handleCodeDeps(params) {
|
|
660
|
-
const analyzePath = params.path || '.';
|
|
661
|
-
const analyzeType = params.type || 'all';
|
|
662
|
-
const targetFile = params.file;
|
|
663
|
-
const format = params.format || 'summary';
|
|
664
|
-
try {
|
|
665
|
-
const workspacePath = process.cwd();
|
|
666
|
-
const projectPath = path.isAbsolute(analyzePath)
|
|
667
|
-
? analyzePath
|
|
668
|
-
: path.resolve(workspacePath, analyzePath);
|
|
669
|
-
// 檢查路徑是否存在
|
|
670
|
-
try {
|
|
671
|
-
await fs.access(projectPath);
|
|
672
|
-
}
|
|
673
|
-
catch {
|
|
674
|
-
return { success: false, error: `路徑不存在: ${analyzePath}` };
|
|
675
|
-
}
|
|
676
|
-
const depAnalyzer = new DependencyAnalyzer({
|
|
677
|
-
includeNodeModules: false,
|
|
678
|
-
excludePatterns: ['node_modules', 'dist', '*.test.*', '*.d.ts'],
|
|
679
|
-
includePatterns: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx']
|
|
680
|
-
});
|
|
681
|
-
const results = {
|
|
682
|
-
path: this.formatRelativePath(projectPath, workspacePath),
|
|
683
|
-
type: analyzeType,
|
|
684
|
-
format
|
|
685
|
-
};
|
|
686
|
-
if (analyzeType === 'graph' || analyzeType === 'all') {
|
|
687
|
-
// 分析依賴圖
|
|
688
|
-
await depAnalyzer.analyzeProject(projectPath);
|
|
689
|
-
const stats = depAnalyzer.getStats();
|
|
690
|
-
results.graph = {
|
|
691
|
-
totalFiles: stats.totalFiles,
|
|
692
|
-
totalDependencies: stats.totalDependencies,
|
|
693
|
-
averageDependenciesPerFile: stats.averageDependenciesPerFile,
|
|
694
|
-
maxDependenciesInFile: stats.maxDependenciesInFile
|
|
695
|
-
};
|
|
696
|
-
}
|
|
697
|
-
if (analyzeType === 'cycles' || analyzeType === 'all') {
|
|
698
|
-
// 檢測循環依賴
|
|
699
|
-
await depAnalyzer.analyzeProject(projectPath);
|
|
700
|
-
const stats = depAnalyzer.getStats();
|
|
701
|
-
results.cycles = {
|
|
702
|
-
circularDependencies: stats.circularDependencies,
|
|
703
|
-
orphanedFiles: stats.orphanedFiles
|
|
704
|
-
};
|
|
705
|
-
}
|
|
706
|
-
if ((analyzeType === 'impact' || analyzeType === 'all') && targetFile) {
|
|
707
|
-
// 影響分析
|
|
708
|
-
const filePath = path.isAbsolute(targetFile)
|
|
709
|
-
? targetFile
|
|
710
|
-
: path.resolve(projectPath, targetFile);
|
|
711
|
-
try {
|
|
712
|
-
await fs.access(filePath);
|
|
713
|
-
await depAnalyzer.analyzeProject(projectPath);
|
|
714
|
-
const impactAnalysis = depAnalyzer.getImpactAnalysis(filePath);
|
|
715
|
-
results.impact = {
|
|
716
|
-
targetFile: this.formatRelativePath(filePath, workspacePath),
|
|
717
|
-
directlyAffected: impactAnalysis.directlyAffected.length,
|
|
718
|
-
transitivelyAffected: impactAnalysis.transitivelyAffected.length,
|
|
719
|
-
affectedTests: impactAnalysis.affectedTests.length,
|
|
720
|
-
impactScore: impactAnalysis.impactScore,
|
|
721
|
-
directlyAffectedFiles: impactAnalysis.directlyAffected.map(f => this.formatRelativePath(f, workspacePath)).slice(0, 10)
|
|
722
|
-
};
|
|
723
|
-
}
|
|
724
|
-
catch {
|
|
725
|
-
results.impact = { error: `檔案不存在: ${targetFile}` };
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
if (format === 'summary') {
|
|
729
|
-
return {
|
|
730
|
-
success: true,
|
|
731
|
-
data: {
|
|
732
|
-
...results,
|
|
733
|
-
summary: this.formatDependencySummary(results)
|
|
734
|
-
}
|
|
735
|
-
};
|
|
736
|
-
}
|
|
737
|
-
return {
|
|
738
|
-
success: true,
|
|
739
|
-
data: results
|
|
740
|
-
};
|
|
741
|
-
}
|
|
742
|
-
catch (error) {
|
|
743
|
-
return {
|
|
744
|
-
success: false,
|
|
745
|
-
error: `依賴分析失敗: ${error instanceof Error ? error.message : String(error)}`
|
|
746
|
-
};
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
formatDependencySummary(results) {
|
|
750
|
-
const lines = [];
|
|
751
|
-
if (results.graph) {
|
|
752
|
-
lines.push(`總檔案數: ${results.graph.totalFiles}`);
|
|
753
|
-
lines.push(`總依賴數: ${results.graph.totalDependencies}`);
|
|
754
|
-
lines.push(`平均每檔案依賴數: ${results.graph.averageDependenciesPerFile}`);
|
|
755
|
-
}
|
|
756
|
-
if (results.cycles) {
|
|
757
|
-
lines.push(`循環依賴: ${results.cycles.circularDependencies} 個`);
|
|
758
|
-
lines.push(`孤立檔案: ${results.cycles.orphanedFiles} 個`);
|
|
759
|
-
}
|
|
760
|
-
if (results.impact && !results.impact.error) {
|
|
761
|
-
lines.push(`直接影響: ${results.impact.directlyAffected} 個檔案`);
|
|
762
|
-
lines.push(`間接影響: ${results.impact.transitivelyAffected} 個檔案`);
|
|
763
|
-
lines.push(`影響分數: ${results.impact.impactScore.toFixed(2)}`);
|
|
764
|
-
}
|
|
765
|
-
return lines.join('\n');
|
|
766
|
-
}
|
|
767
|
-
/**
|
|
768
|
-
* 格式化相對路徑
|
|
769
|
-
*/
|
|
770
|
-
formatRelativePath(filePath, basePath) {
|
|
771
|
-
try {
|
|
772
|
-
const relativePath = path.relative(basePath, filePath);
|
|
773
|
-
return relativePath.startsWith('..') ? filePath : relativePath;
|
|
774
|
-
}
|
|
775
|
-
catch {
|
|
776
|
-
return filePath;
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
async handleParserPlugins(params) {
|
|
780
|
-
const { action, plugin, filter } = params;
|
|
781
|
-
try {
|
|
782
|
-
const registry = ParserRegistry.getInstance();
|
|
783
|
-
switch (action) {
|
|
784
|
-
case 'list':
|
|
785
|
-
const parsers = registry.listParsers();
|
|
786
|
-
return {
|
|
787
|
-
success: true,
|
|
788
|
-
data: {
|
|
789
|
-
plugins: parsers.map(p => ({
|
|
790
|
-
name: p.name,
|
|
791
|
-
version: p.version,
|
|
792
|
-
supportedExtensions: p.supportedExtensions,
|
|
793
|
-
supportedLanguages: p.supportedLanguages,
|
|
794
|
-
registeredAt: p.registeredAt.toISOString()
|
|
795
|
-
})),
|
|
796
|
-
total: parsers.length
|
|
797
|
-
}
|
|
798
|
-
};
|
|
799
|
-
case 'info':
|
|
800
|
-
if (!plugin) {
|
|
801
|
-
return { success: false, error: '需要指定插件名稱' };
|
|
802
|
-
}
|
|
803
|
-
const pluginInstance = registry.getParserByName(plugin);
|
|
804
|
-
if (!pluginInstance) {
|
|
805
|
-
return { success: false, error: `找不到插件: ${plugin}` };
|
|
806
|
-
}
|
|
807
|
-
const pluginInfo = registry.listParsers().find(p => p.name === plugin);
|
|
808
|
-
if (!pluginInfo) {
|
|
809
|
-
return { success: false, error: `找不到插件資訊: ${plugin}` };
|
|
810
|
-
}
|
|
811
|
-
// 避免循環引用,只返回必要的資訊
|
|
812
|
-
return {
|
|
813
|
-
success: true,
|
|
814
|
-
data: {
|
|
815
|
-
name: pluginInfo.name,
|
|
816
|
-
version: pluginInfo.version,
|
|
817
|
-
supportedExtensions: pluginInfo.supportedExtensions,
|
|
818
|
-
supportedLanguages: pluginInfo.supportedLanguages,
|
|
819
|
-
registeredAt: pluginInfo.registeredAt.toISOString()
|
|
820
|
-
}
|
|
821
|
-
};
|
|
822
|
-
case 'enable':
|
|
823
|
-
case 'disable':
|
|
824
|
-
return {
|
|
825
|
-
success: true,
|
|
826
|
-
data: {
|
|
827
|
-
message: `插件 ${action} 功能開發中`,
|
|
828
|
-
plugin
|
|
829
|
-
}
|
|
830
|
-
};
|
|
831
|
-
default:
|
|
832
|
-
return { success: false, error: `未知的插件操作: ${action}` };
|
|
833
|
-
}
|
|
834
|
-
}
|
|
835
|
-
catch (error) {
|
|
836
|
-
return {
|
|
837
|
-
success: false,
|
|
838
|
-
error: `插件操作失敗: ${error instanceof Error ? error.message : String(error)}`
|
|
839
|
-
};
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
//# sourceMappingURL=mcp.js.map
|