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.
Files changed (227) hide show
  1. package/README.md +103 -17
  2. package/dist/application/services/module-coordinator.service.d.ts +0 -1
  3. package/dist/application/services/module-coordinator.service.d.ts.map +1 -1
  4. package/dist/application/services/module-coordinator.service.js +2 -8
  5. package/dist/application/services/module-coordinator.service.js.map +1 -1
  6. package/dist/core/analysis/index.d.ts +1 -4
  7. package/dist/core/analysis/index.d.ts.map +1 -1
  8. package/dist/core/analysis/index.js +1 -7
  9. package/dist/core/analysis/index.js.map +1 -1
  10. package/dist/core/dependency/dependency-analyzer.d.ts.map +1 -1
  11. package/dist/core/dependency/dependency-analyzer.js +10 -0
  12. package/dist/core/dependency/dependency-analyzer.js.map +1 -1
  13. package/dist/core/indexing/index-engine.d.ts +4 -0
  14. package/dist/core/indexing/index-engine.d.ts.map +1 -1
  15. package/dist/core/indexing/index-engine.js +25 -1
  16. package/dist/core/indexing/index-engine.js.map +1 -1
  17. package/dist/core/indexing/symbol-index.d.ts +4 -0
  18. package/dist/core/indexing/symbol-index.d.ts.map +1 -1
  19. package/dist/core/indexing/symbol-index.js +17 -0
  20. package/dist/core/indexing/symbol-index.js.map +1 -1
  21. package/dist/core/move/import-resolver.d.ts.map +1 -1
  22. package/dist/core/move/import-resolver.js +8 -0
  23. package/dist/core/move/import-resolver.js.map +1 -1
  24. package/dist/core/move/move-service.js +7 -7
  25. package/dist/core/move/move-service.js.map +1 -1
  26. package/dist/core/refactor/swift-extractor.d.ts +98 -0
  27. package/dist/core/refactor/swift-extractor.d.ts.map +1 -0
  28. package/dist/core/refactor/swift-extractor.js +283 -0
  29. package/dist/core/refactor/swift-extractor.js.map +1 -0
  30. package/dist/core/rename/reference-updater.d.ts.map +1 -1
  31. package/dist/core/rename/reference-updater.js +16 -8
  32. package/dist/core/rename/reference-updater.js.map +1 -1
  33. package/dist/core/search/engines/text-engine.js +1 -1
  34. package/dist/core/search/engines/text-engine.js.map +1 -1
  35. package/dist/core/shit-score/grading.d.ts +39 -0
  36. package/dist/core/shit-score/grading.d.ts.map +1 -0
  37. package/dist/core/shit-score/grading.js +253 -0
  38. package/dist/core/shit-score/grading.js.map +1 -0
  39. package/dist/core/shit-score/index.d.ts +9 -0
  40. package/dist/core/shit-score/index.d.ts.map +1 -0
  41. package/dist/core/shit-score/index.js +8 -0
  42. package/dist/core/shit-score/index.js.map +1 -0
  43. package/dist/core/shit-score/score-calculator.d.ts +75 -0
  44. package/dist/core/shit-score/score-calculator.d.ts.map +1 -0
  45. package/dist/core/shit-score/score-calculator.js +240 -0
  46. package/dist/core/shit-score/score-calculator.js.map +1 -0
  47. package/dist/core/shit-score/shit-score-analyzer.d.ts +84 -0
  48. package/dist/core/shit-score/shit-score-analyzer.d.ts.map +1 -0
  49. package/dist/core/shit-score/shit-score-analyzer.js +595 -0
  50. package/dist/core/shit-score/shit-score-analyzer.js.map +1 -0
  51. package/dist/core/shit-score/types.d.ts +231 -0
  52. package/dist/core/shit-score/types.d.ts.map +1 -0
  53. package/dist/core/shit-score/types.js +73 -0
  54. package/dist/core/shit-score/types.js.map +1 -0
  55. package/dist/core/snapshot/code-compressor.d.ts +39 -0
  56. package/dist/core/snapshot/code-compressor.d.ts.map +1 -0
  57. package/dist/core/snapshot/code-compressor.js +211 -0
  58. package/dist/core/snapshot/code-compressor.js.map +1 -0
  59. package/dist/core/snapshot/config.d.ts +60 -0
  60. package/dist/core/snapshot/config.d.ts.map +1 -0
  61. package/dist/core/snapshot/config.js +136 -0
  62. package/dist/core/snapshot/config.js.map +1 -0
  63. package/dist/core/snapshot/index.d.ts +23 -0
  64. package/dist/core/snapshot/index.d.ts.map +1 -0
  65. package/dist/core/snapshot/index.js +27 -0
  66. package/dist/core/snapshot/index.js.map +1 -0
  67. package/dist/core/snapshot/snapshot-differ.d.ts +54 -0
  68. package/dist/core/snapshot/snapshot-differ.d.ts.map +1 -0
  69. package/dist/core/snapshot/snapshot-differ.js +262 -0
  70. package/dist/core/snapshot/snapshot-differ.js.map +1 -0
  71. package/dist/core/snapshot/snapshot-engine.d.ts +94 -0
  72. package/dist/core/snapshot/snapshot-engine.d.ts.map +1 -0
  73. package/dist/core/snapshot/snapshot-engine.js +492 -0
  74. package/dist/core/snapshot/snapshot-engine.js.map +1 -0
  75. package/dist/core/snapshot/types.d.ts +216 -0
  76. package/dist/core/snapshot/types.d.ts.map +1 -0
  77. package/dist/core/snapshot/types.js +79 -0
  78. package/dist/core/snapshot/types.js.map +1 -0
  79. package/dist/infrastructure/parser/analysis-types.d.ts +198 -0
  80. package/dist/infrastructure/parser/analysis-types.d.ts.map +1 -0
  81. package/dist/infrastructure/parser/analysis-types.js +6 -0
  82. package/dist/infrastructure/parser/analysis-types.js.map +1 -0
  83. package/dist/infrastructure/parser/base.d.ts +36 -0
  84. package/dist/infrastructure/parser/base.d.ts.map +1 -1
  85. package/dist/infrastructure/parser/base.js +72 -0
  86. package/dist/infrastructure/parser/base.js.map +1 -1
  87. package/dist/infrastructure/parser/index.d.ts +1 -0
  88. package/dist/infrastructure/parser/index.d.ts.map +1 -1
  89. package/dist/infrastructure/parser/index.js.map +1 -1
  90. package/dist/infrastructure/parser/interface.d.ts +63 -0
  91. package/dist/infrastructure/parser/interface.d.ts.map +1 -1
  92. package/dist/infrastructure/parser/interface.js +11 -1
  93. package/dist/infrastructure/parser/interface.js.map +1 -1
  94. package/dist/interfaces/cli/cli.d.ts +24 -0
  95. package/dist/interfaces/cli/cli.d.ts.map +1 -1
  96. package/dist/interfaces/cli/cli.js +1483 -157
  97. package/dist/interfaces/cli/cli.js.map +1 -1
  98. package/dist/plugins/javascript/parser.d.ts +41 -0
  99. package/dist/plugins/javascript/parser.d.ts.map +1 -1
  100. package/dist/plugins/javascript/parser.js +284 -0
  101. package/dist/plugins/javascript/parser.js.map +1 -1
  102. package/dist/plugins/swift/analyzers/complexity-analyzer.d.ts +41 -0
  103. package/dist/plugins/swift/analyzers/complexity-analyzer.d.ts.map +1 -0
  104. package/dist/plugins/swift/analyzers/complexity-analyzer.js +206 -0
  105. package/dist/plugins/swift/analyzers/complexity-analyzer.js.map +1 -0
  106. package/dist/plugins/swift/analyzers/duplication-detector.d.ts +89 -0
  107. package/dist/plugins/swift/analyzers/duplication-detector.d.ts.map +1 -0
  108. package/dist/plugins/swift/analyzers/duplication-detector.js +271 -0
  109. package/dist/plugins/swift/analyzers/duplication-detector.js.map +1 -0
  110. package/dist/plugins/swift/analyzers/error-handling-checker.d.ts +34 -0
  111. package/dist/plugins/swift/analyzers/error-handling-checker.d.ts.map +1 -0
  112. package/dist/plugins/swift/analyzers/error-handling-checker.js +135 -0
  113. package/dist/plugins/swift/analyzers/error-handling-checker.js.map +1 -0
  114. package/dist/plugins/swift/analyzers/naming-checker.d.ts +47 -0
  115. package/dist/plugins/swift/analyzers/naming-checker.d.ts.map +1 -0
  116. package/dist/plugins/swift/analyzers/naming-checker.js +161 -0
  117. package/dist/plugins/swift/analyzers/naming-checker.js.map +1 -0
  118. package/dist/plugins/swift/analyzers/pattern-detector.d.ts +78 -0
  119. package/dist/plugins/swift/analyzers/pattern-detector.d.ts.map +1 -0
  120. package/dist/plugins/swift/analyzers/pattern-detector.js +247 -0
  121. package/dist/plugins/swift/analyzers/pattern-detector.js.map +1 -0
  122. package/dist/plugins/swift/analyzers/security-checker.d.ts +38 -0
  123. package/dist/plugins/swift/analyzers/security-checker.d.ts.map +1 -0
  124. package/dist/plugins/swift/analyzers/security-checker.js +135 -0
  125. package/dist/plugins/swift/analyzers/security-checker.js.map +1 -0
  126. package/dist/plugins/swift/analyzers/test-coverage-checker.d.ts +26 -0
  127. package/dist/plugins/swift/analyzers/test-coverage-checker.d.ts.map +1 -0
  128. package/dist/plugins/swift/analyzers/test-coverage-checker.js +63 -0
  129. package/dist/plugins/swift/analyzers/test-coverage-checker.js.map +1 -0
  130. package/dist/plugins/swift/analyzers/type-safety-checker.d.ts +41 -0
  131. package/dist/plugins/swift/analyzers/type-safety-checker.d.ts.map +1 -0
  132. package/dist/plugins/swift/analyzers/type-safety-checker.js +121 -0
  133. package/dist/plugins/swift/analyzers/type-safety-checker.js.map +1 -0
  134. package/dist/plugins/swift/analyzers/unused-symbol-detector.d.ts +38 -0
  135. package/dist/plugins/swift/analyzers/unused-symbol-detector.d.ts.map +1 -0
  136. package/dist/plugins/swift/analyzers/unused-symbol-detector.js +211 -0
  137. package/dist/plugins/swift/analyzers/unused-symbol-detector.js.map +1 -0
  138. package/dist/plugins/swift/dependency-analyzer.d.ts +33 -0
  139. package/dist/plugins/swift/dependency-analyzer.d.ts.map +1 -0
  140. package/dist/plugins/swift/dependency-analyzer.js +95 -0
  141. package/dist/plugins/swift/dependency-analyzer.js.map +1 -0
  142. package/dist/plugins/swift/index.d.ts +14 -0
  143. package/dist/plugins/swift/index.d.ts.map +1 -0
  144. package/dist/plugins/swift/index.js +19 -0
  145. package/dist/plugins/swift/index.js.map +1 -0
  146. package/dist/plugins/swift/parser.d.ts +160 -0
  147. package/dist/plugins/swift/parser.d.ts.map +1 -0
  148. package/dist/plugins/swift/parser.js +670 -0
  149. package/dist/plugins/swift/parser.js.map +1 -0
  150. package/dist/plugins/swift/swift-bridge/swift-parser +0 -0
  151. package/dist/plugins/swift/symbol-extractor.d.ts +46 -0
  152. package/dist/plugins/swift/symbol-extractor.d.ts.map +1 -0
  153. package/dist/plugins/swift/symbol-extractor.js +187 -0
  154. package/dist/plugins/swift/symbol-extractor.js.map +1 -0
  155. package/dist/plugins/swift/types.d.ts +137 -0
  156. package/dist/plugins/swift/types.d.ts.map +1 -0
  157. package/dist/plugins/swift/types.js +212 -0
  158. package/dist/plugins/swift/types.js.map +1 -0
  159. package/dist/plugins/typescript/analyzers/complexity-analyzer.d.ts +39 -0
  160. package/dist/plugins/typescript/analyzers/complexity-analyzer.d.ts.map +1 -0
  161. package/dist/plugins/typescript/analyzers/complexity-analyzer.js +196 -0
  162. package/dist/plugins/typescript/analyzers/complexity-analyzer.js.map +1 -0
  163. package/dist/{core/analysis → plugins/typescript/analyzers}/duplication-detector.d.ts +34 -3
  164. package/dist/plugins/typescript/analyzers/duplication-detector.d.ts.map +1 -0
  165. package/dist/plugins/typescript/analyzers/duplication-detector.js +695 -0
  166. package/dist/plugins/typescript/analyzers/duplication-detector.js.map +1 -0
  167. package/dist/plugins/typescript/analyzers/error-handling-checker.d.ts +26 -0
  168. package/dist/plugins/typescript/analyzers/error-handling-checker.d.ts.map +1 -0
  169. package/dist/plugins/typescript/analyzers/error-handling-checker.js +84 -0
  170. package/dist/plugins/typescript/analyzers/error-handling-checker.js.map +1 -0
  171. package/dist/plugins/typescript/analyzers/naming-checker.d.ts +30 -0
  172. package/dist/plugins/typescript/analyzers/naming-checker.d.ts.map +1 -0
  173. package/dist/plugins/typescript/analyzers/naming-checker.js +116 -0
  174. package/dist/plugins/typescript/analyzers/naming-checker.js.map +1 -0
  175. package/dist/plugins/typescript/analyzers/pattern-detector.d.ts +80 -0
  176. package/dist/plugins/typescript/analyzers/pattern-detector.d.ts.map +1 -0
  177. package/dist/plugins/typescript/analyzers/pattern-detector.js +267 -0
  178. package/dist/plugins/typescript/analyzers/pattern-detector.js.map +1 -0
  179. package/dist/plugins/typescript/analyzers/security-checker.d.ts +34 -0
  180. package/dist/plugins/typescript/analyzers/security-checker.d.ts.map +1 -0
  181. package/dist/plugins/typescript/analyzers/security-checker.js +126 -0
  182. package/dist/plugins/typescript/analyzers/security-checker.js.map +1 -0
  183. package/dist/plugins/typescript/analyzers/test-coverage-checker.d.ts +22 -0
  184. package/dist/plugins/typescript/analyzers/test-coverage-checker.d.ts.map +1 -0
  185. package/dist/plugins/typescript/analyzers/test-coverage-checker.js +62 -0
  186. package/dist/plugins/typescript/analyzers/test-coverage-checker.js.map +1 -0
  187. package/dist/plugins/typescript/analyzers/type-safety-checker.d.ts +32 -0
  188. package/dist/plugins/typescript/analyzers/type-safety-checker.d.ts.map +1 -0
  189. package/dist/plugins/typescript/analyzers/type-safety-checker.js +86 -0
  190. package/dist/plugins/typescript/analyzers/type-safety-checker.js.map +1 -0
  191. package/dist/plugins/typescript/analyzers/unused-symbol-detector.d.ts +47 -0
  192. package/dist/plugins/typescript/analyzers/unused-symbol-detector.d.ts.map +1 -0
  193. package/dist/plugins/typescript/analyzers/unused-symbol-detector.js +152 -0
  194. package/dist/plugins/typescript/analyzers/unused-symbol-detector.js.map +1 -0
  195. package/dist/plugins/typescript/parser.d.ts +41 -0
  196. package/dist/plugins/typescript/parser.d.ts.map +1 -1
  197. package/dist/plugins/typescript/parser.js +336 -0
  198. package/dist/plugins/typescript/parser.js.map +1 -1
  199. package/dist/shared/types/symbol.d.ts +7 -1
  200. package/dist/shared/types/symbol.d.ts.map +1 -1
  201. package/dist/shared/types/symbol.js +8 -2
  202. package/dist/shared/types/symbol.js.map +1 -1
  203. package/package.json +17 -7
  204. package/bin/mcp-server.js +0 -20
  205. package/dist/core/analysis/complexity-analyzer.d.ts +0 -81
  206. package/dist/core/analysis/complexity-analyzer.d.ts.map +0 -1
  207. package/dist/core/analysis/complexity-analyzer.js +0 -255
  208. package/dist/core/analysis/complexity-analyzer.js.map +0 -1
  209. package/dist/core/analysis/dead-code-detector.d.ts +0 -152
  210. package/dist/core/analysis/dead-code-detector.d.ts.map +0 -1
  211. package/dist/core/analysis/dead-code-detector.js +0 -351
  212. package/dist/core/analysis/dead-code-detector.js.map +0 -1
  213. package/dist/core/analysis/duplication-detector.d.ts.map +0 -1
  214. package/dist/core/analysis/duplication-detector.js +0 -433
  215. package/dist/core/analysis/duplication-detector.js.map +0 -1
  216. package/dist/interfaces/mcp/index.d.ts +0 -7
  217. package/dist/interfaces/mcp/index.d.ts.map +0 -1
  218. package/dist/interfaces/mcp/index.js +0 -6
  219. package/dist/interfaces/mcp/index.js.map +0 -1
  220. package/dist/interfaces/mcp/mcp-server.d.ts +0 -34
  221. package/dist/interfaces/mcp/mcp-server.d.ts.map +0 -1
  222. package/dist/interfaces/mcp/mcp-server.js +0 -162
  223. package/dist/interfaces/mcp/mcp-server.js.map +0 -1
  224. package/dist/interfaces/mcp/mcp.d.ts +0 -52
  225. package/dist/interfaces/mcp/mcp.d.ts.map +0 -1
  226. package/dist/interfaces/mcp/mcp.js +0 -843
  227. package/dist/interfaces/mcp/mcp.js.map +0 -1
@@ -1,255 +0,0 @@
1
- /**
2
- * 程式碼複雜度分析器
3
- * 提供循環複雜度和認知複雜度分析功能
4
- */
5
- /**
6
- * 循環複雜度分析器
7
- * 基於 McCabe 複雜度計算方法
8
- */
9
- export class CyclomaticComplexityAnalyzer {
10
- /**
11
- * 計算循環複雜度
12
- * @param ast AST 節點
13
- * @returns 複雜度數值
14
- */
15
- calculate(ast) {
16
- let complexity = 1; // 基礎路徑
17
- const traverse = (node) => {
18
- switch (node.type) {
19
- case 'IfStatement':
20
- case 'ConditionalExpression':
21
- case 'ForStatement':
22
- case 'WhileStatement':
23
- case 'DoWhileStatement':
24
- case 'CatchClause':
25
- complexity++;
26
- break;
27
- case 'SwitchCase':
28
- if (!node.default) {
29
- complexity++;
30
- }
31
- break;
32
- case 'LogicalExpression':
33
- if (node.operator === '||' || node.operator === '&&') {
34
- complexity++;
35
- }
36
- break;
37
- }
38
- // 遍歷子節點
39
- if (node.children) {
40
- node.children.forEach(traverse);
41
- }
42
- };
43
- traverse(ast);
44
- return complexity;
45
- }
46
- /**
47
- * 評估複雜度等級
48
- * @param complexity 複雜度數值
49
- * @returns 複雜度等級
50
- */
51
- evaluate(complexity) {
52
- if (complexity <= 5) {
53
- return 'simple';
54
- }
55
- else if (complexity <= 10) {
56
- return 'moderate';
57
- }
58
- else if (complexity <= 20) {
59
- return 'complex';
60
- }
61
- else {
62
- return 'very-complex';
63
- }
64
- }
65
- }
66
- /**
67
- * 認知複雜度分析器
68
- * 考慮巢狀深度對程式碼理解難度的影響
69
- */
70
- export class CognitiveComplexityAnalyzer {
71
- nestingLevel = 0;
72
- /**
73
- * 計算認知複雜度
74
- * @param ast AST 節點
75
- * @returns 認知複雜度數值
76
- */
77
- calculate(ast) {
78
- let complexity = 0;
79
- this.nestingLevel = 0;
80
- const traverse = (node) => {
81
- switch (node.type) {
82
- case 'IfStatement':
83
- case 'ForStatement':
84
- case 'WhileStatement':
85
- case 'DoWhileStatement':
86
- complexity += 1 + this.nestingLevel;
87
- this.nestingLevel++;
88
- if (node.children) {
89
- node.children.forEach(traverse);
90
- }
91
- this.nestingLevel--;
92
- return; // 避免重複遍歷子節點
93
- case 'CallExpression':
94
- if (this.isRecursive(node)) {
95
- complexity += 1;
96
- }
97
- break;
98
- case 'FunctionExpression':
99
- case 'ArrowFunctionExpression':
100
- this.nestingLevel++;
101
- if (node.children) {
102
- node.children.forEach(traverse);
103
- }
104
- this.nestingLevel--;
105
- return;
106
- case 'CatchClause':
107
- complexity += 1 + this.nestingLevel;
108
- break;
109
- case 'SwitchStatement':
110
- complexity += 1 + this.nestingLevel;
111
- this.nestingLevel++;
112
- if (node.children) {
113
- node.children.forEach(traverse);
114
- }
115
- this.nestingLevel--;
116
- return;
117
- case 'ConditionalExpression':
118
- case 'LogicalExpression':
119
- if (node.operator === '&&' || node.operator === '||') {
120
- complexity += 1;
121
- }
122
- break;
123
- }
124
- // 遍歷子節點
125
- if (node.children) {
126
- node.children.forEach(traverse);
127
- }
128
- };
129
- traverse(ast);
130
- return complexity;
131
- }
132
- /**
133
- * 檢查是否為遞歸調用
134
- */
135
- isRecursive(node) {
136
- // 簡化實作,實際應該檢查調用的函式名稱
137
- return false;
138
- }
139
- /**
140
- * 評估認知複雜度等級
141
- */
142
- evaluate(complexity) {
143
- if (complexity <= 5) {
144
- return 'simple';
145
- }
146
- else if (complexity <= 10) {
147
- return 'moderate';
148
- }
149
- else if (complexity <= 15) {
150
- return 'complex';
151
- }
152
- else {
153
- return 'very-complex';
154
- }
155
- }
156
- }
157
- /**
158
- * 綜合複雜度分析器
159
- * 整合循環複雜度和認知複雜度分析
160
- */
161
- export class ComplexityAnalyzer {
162
- cyclomaticAnalyzer = new CyclomaticComplexityAnalyzer();
163
- cognitiveAnalyzer = new CognitiveComplexityAnalyzer();
164
- /**
165
- * 分析程式碼複雜度
166
- * @param code 程式碼字串
167
- * @returns 複雜度分析結果
168
- */
169
- async analyzeCode(code) {
170
- // 輸入驗證
171
- if (typeof code !== 'string') {
172
- throw new Error('程式碼必須是字串類型');
173
- }
174
- if (code.length === 0) {
175
- return {
176
- cyclomaticComplexity: 1,
177
- cognitiveComplexity: 0,
178
- evaluation: 'simple'
179
- };
180
- }
181
- // 簡化的 AST 生成(實際應該使用真正的 parser)
182
- const ast = this.parseCodeToAST(code);
183
- const cyclomaticComplexity = this.cyclomaticAnalyzer.calculate(ast);
184
- const cognitiveComplexity = this.cognitiveAnalyzer.calculate(ast);
185
- return {
186
- cyclomaticComplexity,
187
- cognitiveComplexity,
188
- evaluation: this.cyclomaticAnalyzer.evaluate(cyclomaticComplexity)
189
- };
190
- }
191
- /**
192
- * 簡化的程式碼解析為 AST
193
- * 實際實作中應該使用完整的 TypeScript 或 JavaScript parser
194
- */
195
- parseCodeToAST(code) {
196
- // 簡化實作:根據程式碼內容建立模擬的 AST
197
- const children = [];
198
- // 檢測條件語句
199
- const ifMatches = code.match(/if\s*\(/g) || [];
200
- ifMatches.forEach(() => {
201
- children.push({ type: 'IfStatement', children: [] });
202
- });
203
- // 檢測迴圈
204
- const forMatches = code.match(/for\s*\(/g) || [];
205
- forMatches.forEach(() => {
206
- children.push({ type: 'ForStatement', children: [] });
207
- });
208
- const whileMatches = code.match(/while\s*\(/g) || [];
209
- whileMatches.forEach(() => {
210
- children.push({ type: 'WhileStatement', children: [] });
211
- });
212
- // 檢測邏輯運算子
213
- const logicalMatches = code.match(/(\|\||&&)/g) || [];
214
- logicalMatches.forEach((operator) => {
215
- children.push({
216
- type: 'LogicalExpression',
217
- operator: operator,
218
- children: []
219
- });
220
- });
221
- return {
222
- type: 'Program',
223
- children
224
- };
225
- }
226
- /**
227
- * 批次分析多個檔案的複雜度
228
- */
229
- async analyzeFiles(files) {
230
- if (!Array.isArray(files)) {
231
- throw new Error('檔案列表必須是陣列');
232
- }
233
- const results = await Promise.all(files.map(async (file) => {
234
- try {
235
- // 讀取檔案內容
236
- const fs = await import('fs/promises');
237
- const code = await fs.readFile(file, 'utf-8');
238
- const complexity = await this.analyzeCode(code);
239
- return { file, complexity };
240
- }
241
- catch (error) {
242
- return {
243
- file,
244
- complexity: {
245
- cyclomaticComplexity: 0,
246
- cognitiveComplexity: 0,
247
- evaluation: 'error'
248
- }
249
- };
250
- }
251
- }));
252
- return results;
253
- }
254
- }
255
- //# sourceMappingURL=complexity-analyzer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"complexity-analyzer.js","sourceRoot":"","sources":["../../../src/core/analysis/complexity-analyzer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAiBH;;;GAGG;AACH,MAAM,OAAO,4BAA4B;IACvC;;;;OAIG;IACH,SAAS,CAAC,GAAY;QACpB,IAAI,UAAU,GAAG,CAAC,CAAC,CAAC,OAAO;QAE3B,MAAM,QAAQ,GAAG,CAAC,IAAa,EAAE,EAAE;YACjC,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;gBACpB,KAAK,aAAa,CAAC;gBACnB,KAAK,uBAAuB,CAAC;gBAC7B,KAAK,cAAc,CAAC;gBACpB,KAAK,gBAAgB,CAAC;gBACtB,KAAK,kBAAkB,CAAC;gBACxB,KAAK,aAAa;oBAChB,UAAU,EAAE,CAAC;oBACb,MAAM;gBACR,KAAK,YAAY;oBACf,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;wBAClB,UAAU,EAAE,CAAC;oBACf,CAAC;oBACD,MAAM;gBACR,KAAK,mBAAmB;oBACtB,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;wBACrD,UAAU,EAAE,CAAC;oBACf,CAAC;oBACD,MAAM;YACR,CAAC;YAED,QAAQ;YACR,IAAI,IA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AAe;QAIhC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CAAC,WAAW,CAAC,CAAC;QAC/B,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAC/B,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;YACvB,IAAI,CAAC;gBACH,SAAS;gBACT,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,CAAC;gBACvC,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;gBAC9C,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;gBAChD,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;YAC9B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO;oBACL,IAAI;oBACJ,UAAU,EAAE;wBACV,oBAAoB,EAAE,CAAC;wBACvB,mBAAmB,EAAE,CAAC;wBACtB,UAAU,EAAE,OAAO;qBACpB;iBACF,CAAC;YACJ,CAAC;QACH,CAAC,CAAC,CACH,CAAC;QAEF,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
@@ -1,152 +0,0 @@
1
- /**
2
- * 死代碼檢測器
3
- * 檢測未使用的變數、函式、類別和不可達代碼
4
- */
5
- import { TypeScriptParser } from '../../plugins/typescript/parser.js';
6
- import type { AST } from '../../shared/types/index.js';
7
- export interface LegacySymbol {
8
- name: string;
9
- type: 'variable' | 'function' | 'class' | 'import';
10
- location: {
11
- line: number;
12
- column: number;
13
- };
14
- references: Reference[];
15
- exported: boolean;
16
- parameter: boolean;
17
- }
18
- export interface Reference {
19
- location: {
20
- line: number;
21
- column: number;
22
- };
23
- type: 'read' | 'write' | 'call';
24
- }
25
- export interface UnusedCode {
26
- type: 'variable' | 'function' | 'class' | 'import' | 'unreachable';
27
- name?: string;
28
- location: {
29
- line: number;
30
- column: number;
31
- };
32
- confidence: number;
33
- reason?: string;
34
- }
35
- export interface ASTNode {
36
- type: string;
37
- children?: ASTNode[];
38
- location: {
39
- line: number;
40
- column: number;
41
- };
42
- isTerminator?: boolean;
43
- name?: string;
44
- exported?: boolean;
45
- }
46
- /**
47
- * 未使用符號檢測器
48
- */
49
- export declare class UnusedSymbolDetector {
50
- /**
51
- * 檢測未使用的符號
52
- * @param ast AST 物件
53
- * @param parser TypeScript parser 實例(重用以提升效能)
54
- * @returns 未使用的符號列表
55
- */
56
- detect(ast: AST, parser: TypeScriptParser): Promise<UnusedCode[]>;
57
- /**
58
- * 建立引用映射表(批次處理)
59
- * 優化:使用 Promise.all 並行處理多個符號
60
- */
61
- private buildReferenceMap;
62
- /**
63
- * 檢查符號是否已匯出
64
- */
65
- private isExported;
66
- /**
67
- * 檢查是否為函式參數
68
- */
69
- private isParameter;
70
- /**
71
- * 檢查是否為 public 或 protected 類別成員
72
- * 這些成員可能被子類別或外部程式碼使用,單檔案模式無法檢測
73
- */
74
- private isPublicOrProtectedMember;
75
- /**
76
- * 映射符號類型到 UnusedCode 類型
77
- */
78
- private mapSymbolType;
79
- /**
80
- * 計算檢測置信度
81
- */
82
- private calculateConfidence;
83
- /**
84
- * 清理資源
85
- */
86
- dispose(): Promise<void>;
87
- }
88
- /**
89
- * 不可達代碼檢測器
90
- */
91
- export declare class UnreachableCodeDetector {
92
- /**
93
- * 檢測不可達代碼
94
- * @param ast AST 根節點
95
- * @returns 不可達代碼列表
96
- */
97
- detect(ast: ASTNode): UnusedCode[];
98
- /**
99
- * 遍歷 AST 檢測不可達代碼
100
- */
101
- private traverse;
102
- /**
103
- * 檢查是否為可執行語句
104
- */
105
- private isExecutableStatement;
106
- /**
107
- * 檢查是否為終止語句
108
- */
109
- private isTerminatingStatement;
110
- }
111
- /**
112
- * 死代碼檢測器主類
113
- */
114
- export declare class DeadCodeDetector {
115
- private unusedSymbolDetector;
116
- private unreachableCodeDetector;
117
- private parser;
118
- /**
119
- * 檢測檔案中的死代碼
120
- * @param filePath 檔案路徑
121
- * @param content 檔案內容
122
- * @returns 死代碼檢測結果
123
- */
124
- detectInFile(filePath: string, content: string): Promise<UnusedCode[]>;
125
- /**
126
- * 批次檢測多個檔案
127
- * @param files 檔案路徑列表
128
- * @returns 每個檔案的死代碼檢測結果
129
- */
130
- detectInFiles(files: string[]): Promise<Array<{
131
- file: string;
132
- deadCode: UnusedCode[];
133
- }>>;
134
- /**
135
- * 轉換 TypeScript AST 到舊版 AST 格式(用於不可達代碼檢測)
136
- */
137
- private convertToLegacyAST;
138
- /**
139
- * 獲取檢測統計
140
- */
141
- getStatistics(files: string[]): Promise<{
142
- totalFiles: number;
143
- totalDeadCode: number;
144
- byType: Record<string, number>;
145
- averageConfidence: number;
146
- }>;
147
- /**
148
- * 清理資源
149
- */
150
- dispose(): Promise<void>;
151
- }
152
- //# sourceMappingURL=dead-code-detector.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dead-code-detector.d.ts","sourceRoot":"","sources":["../../../src/core/analysis/dead-code-detector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,KAAK,EAAU,GAAG,EAAE,MAAM,6BAA6B,CAAC;AAI/D,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,UAAU,GAAG,UAAU,GAAG,OAAO,GAAG,QAAQ,CAAC;IACnD,QAAQ,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAC3C,UAAU,EAAE,SAAS,EAAE,CAAC;IACxB,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC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