agent-ide 0.3.3 → 0.4.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 (452) hide show
  1. package/README.md +11 -10
  2. package/dist/application/services/module-coordinator.service.d.ts +1 -21
  3. package/dist/application/services/module-coordinator.service.d.ts.map +1 -1
  4. package/dist/application/services/module-coordinator.service.js +10 -149
  5. package/dist/application/services/module-coordinator.service.js.map +1 -1
  6. package/dist/core/{transform/symbol/change-signature → change-signature}/change-signature-service.d.ts +2 -2
  7. package/dist/core/change-signature/change-signature-service.d.ts.map +1 -0
  8. package/dist/core/{transform/symbol/change-signature → change-signature}/change-signature-service.js +1 -1
  9. package/dist/core/change-signature/change-signature-service.js.map +1 -0
  10. package/dist/core/change-signature/index.d.ts.map +1 -0
  11. package/dist/core/change-signature/index.js.map +1 -0
  12. package/dist/core/{transform/symbol/change-signature → change-signature}/signature-parser.d.ts +2 -2
  13. package/dist/core/change-signature/signature-parser.d.ts.map +1 -0
  14. package/dist/core/change-signature/signature-parser.js.map +1 -0
  15. package/dist/core/{transform/symbol/change-signature → change-signature}/types.d.ts +1 -1
  16. package/dist/core/change-signature/types.d.ts.map +1 -0
  17. package/dist/core/change-signature/types.js.map +1 -0
  18. package/dist/core/indexing/index-engine.d.ts.map +1 -1
  19. package/dist/core/indexing/index-engine.js +1 -2
  20. package/dist/core/indexing/index-engine.js.map +1 -1
  21. package/dist/core/indexing/index.d.ts +1 -9
  22. package/dist/core/indexing/index.d.ts.map +1 -1
  23. package/dist/core/indexing/index.js +2 -12
  24. package/dist/core/indexing/index.js.map +1 -1
  25. package/dist/core/indexing/types.d.ts +12 -0
  26. package/dist/core/indexing/types.d.ts.map +1 -1
  27. package/dist/core/indexing/types.js +12 -0
  28. package/dist/core/indexing/types.js.map +1 -1
  29. package/dist/core/{transform/location/move-file → move-file}/import-resolver.d.ts +1 -1
  30. package/dist/core/move-file/import-resolver.d.ts.map +1 -0
  31. package/dist/core/{transform/location/move-file → move-file}/import-resolver.js +2 -2
  32. package/dist/core/move-file/import-resolver.js.map +1 -0
  33. package/dist/core/move-file/index.d.ts.map +1 -0
  34. package/dist/core/move-file/index.js.map +1 -0
  35. package/dist/core/{transform/location/move-file → move-file}/move-service.d.ts +3 -3
  36. package/dist/core/move-file/move-service.d.ts.map +1 -0
  37. package/dist/core/{transform/location/move-file → move-file}/move-service.js +1 -1
  38. package/dist/core/move-file/move-service.js.map +1 -0
  39. package/dist/core/{transform/location/move-file → move-file}/types.d.ts +1 -1
  40. package/dist/core/move-file/types.d.ts.map +1 -0
  41. package/dist/core/move-file/types.js.map +1 -0
  42. package/dist/core/move-member/index.d.ts.map +1 -0
  43. package/dist/core/move-member/index.js.map +1 -0
  44. package/dist/core/{transform/location/move-member → move-member}/member-extractor.d.ts +2 -2
  45. package/dist/core/move-member/member-extractor.d.ts.map +1 -0
  46. package/dist/core/move-member/member-extractor.js.map +1 -0
  47. package/dist/core/{transform/location/move-member → move-member}/move-member-service.d.ts +2 -2
  48. package/dist/core/move-member/move-member-service.d.ts.map +1 -0
  49. package/dist/core/{transform/location/move-member → move-member}/move-member-service.js +1 -1
  50. package/dist/core/move-member/move-member-service.js.map +1 -0
  51. package/dist/core/{transform/location/move-member → move-member}/types.d.ts +1 -1
  52. package/dist/core/move-member/types.d.ts.map +1 -0
  53. package/dist/core/move-member/types.js.map +1 -0
  54. package/dist/core/rename/index.d.ts.map +1 -0
  55. package/dist/core/rename/index.js.map +1 -0
  56. package/dist/core/{transform/symbol/rename → rename}/reference-updater.d.ts +5 -3
  57. package/dist/core/rename/reference-updater.d.ts.map +1 -0
  58. package/dist/core/{transform/symbol/rename → rename}/reference-updater.js +9 -6
  59. package/dist/core/rename/reference-updater.js.map +1 -0
  60. package/dist/core/{transform/symbol/rename → rename}/rename-engine.d.ts +5 -3
  61. package/dist/core/rename/rename-engine.d.ts.map +1 -0
  62. package/dist/core/{transform/symbol/rename → rename}/rename-engine.js +11 -8
  63. package/dist/core/rename/rename-engine.js.map +1 -0
  64. package/dist/core/{transform/symbol/rename → rename}/scope-analyzer.d.ts +3 -3
  65. package/dist/core/rename/scope-analyzer.d.ts.map +1 -0
  66. package/dist/core/{transform/symbol/rename → rename}/scope-analyzer.js +2 -2
  67. package/dist/core/rename/scope-analyzer.js.map +1 -0
  68. package/dist/core/{transform/symbol/rename → rename}/types.d.ts +2 -2
  69. package/dist/core/rename/types.d.ts.map +1 -0
  70. package/dist/core/rename/types.js.map +1 -0
  71. package/dist/core/shared/call-hierarchy-analyzer.d.ts +102 -0
  72. package/dist/core/shared/call-hierarchy-analyzer.d.ts.map +1 -0
  73. package/dist/core/shared/call-hierarchy-analyzer.js +328 -0
  74. package/dist/core/shared/call-hierarchy-analyzer.js.map +1 -0
  75. package/dist/core/shared/index.d.ts +7 -0
  76. package/dist/core/shared/index.d.ts.map +1 -0
  77. package/dist/core/shared/index.js +7 -0
  78. package/dist/core/shared/index.js.map +1 -0
  79. package/dist/core/{transform/shared → shared}/symbol-finder.d.ts +4 -4
  80. package/dist/core/shared/symbol-finder.d.ts.map +1 -0
  81. package/dist/core/shared/symbol-finder.js.map +1 -0
  82. package/dist/infrastructure/formatters/diff-generator.d.ts.map +1 -1
  83. package/dist/infrastructure/formatters/diff-generator.js +11 -1
  84. package/dist/infrastructure/formatters/diff-generator.js.map +1 -1
  85. package/dist/infrastructure/formatters/index.d.ts +1 -1
  86. package/dist/infrastructure/formatters/index.d.ts.map +1 -1
  87. package/dist/infrastructure/formatters/index.js.map +1 -1
  88. package/dist/infrastructure/formatters/query-formatter.d.ts +20 -0
  89. package/dist/infrastructure/formatters/query-formatter.d.ts.map +1 -1
  90. package/dist/infrastructure/formatters/query-formatter.js +145 -14
  91. package/dist/infrastructure/formatters/query-formatter.js.map +1 -1
  92. package/dist/infrastructure/formatters/query-types.d.ts +99 -26
  93. package/dist/infrastructure/formatters/query-types.d.ts.map +1 -1
  94. package/dist/infrastructure/formatters/query-types.js +2 -3
  95. package/dist/infrastructure/formatters/query-types.js.map +1 -1
  96. package/dist/infrastructure/formatters/types.d.ts +10 -0
  97. package/dist/infrastructure/formatters/types.d.ts.map +1 -1
  98. package/dist/infrastructure/parser/base.d.ts +0 -32
  99. package/dist/infrastructure/parser/base.d.ts.map +1 -1
  100. package/dist/infrastructure/parser/base.js +0 -64
  101. package/dist/infrastructure/parser/base.js.map +1 -1
  102. package/dist/infrastructure/parser/index.d.ts +0 -2
  103. package/dist/infrastructure/parser/index.d.ts.map +1 -1
  104. package/dist/infrastructure/parser/index.js +1 -2
  105. package/dist/infrastructure/parser/index.js.map +1 -1
  106. package/dist/infrastructure/parser/interface.d.ts +1 -58
  107. package/dist/infrastructure/parser/interface.d.ts.map +1 -1
  108. package/dist/infrastructure/parser/interface.js +1 -11
  109. package/dist/infrastructure/parser/interface.js.map +1 -1
  110. package/dist/infrastructure/storage/index.d.ts +0 -2
  111. package/dist/infrastructure/storage/index.d.ts.map +1 -1
  112. package/dist/infrastructure/storage/index.js +0 -2
  113. package/dist/infrastructure/storage/index.js.map +1 -1
  114. package/dist/interfaces/cli/cli.d.ts.map +1 -1
  115. package/dist/interfaces/cli/cli.js +11 -17
  116. package/dist/interfaces/cli/cli.js.map +1 -1
  117. package/dist/interfaces/cli/commands/call-hierarchy.command.d.ts +11 -0
  118. package/dist/interfaces/cli/commands/call-hierarchy.command.d.ts.map +1 -0
  119. package/dist/interfaces/cli/commands/call-hierarchy.command.js +161 -0
  120. package/dist/interfaces/cli/commands/call-hierarchy.command.js.map +1 -0
  121. package/dist/interfaces/cli/commands/change-signature.command.js +8 -17
  122. package/dist/interfaces/cli/commands/change-signature.command.js.map +1 -1
  123. package/dist/interfaces/cli/commands/cycles.command.d.ts +11 -0
  124. package/dist/interfaces/cli/commands/cycles.command.d.ts.map +1 -0
  125. package/dist/interfaces/cli/commands/cycles.command.js +87 -0
  126. package/dist/interfaces/cli/commands/cycles.command.js.map +1 -0
  127. package/dist/interfaces/cli/commands/find-references.command.d.ts +11 -0
  128. package/dist/interfaces/cli/commands/find-references.command.d.ts.map +1 -0
  129. package/dist/interfaces/cli/commands/find-references.command.js +122 -0
  130. package/dist/interfaces/cli/commands/find-references.command.js.map +1 -0
  131. package/dist/interfaces/cli/commands/impact.command.d.ts +11 -0
  132. package/dist/interfaces/cli/commands/impact.command.d.ts.map +1 -0
  133. package/dist/interfaces/cli/commands/impact.command.js +98 -0
  134. package/dist/interfaces/cli/commands/impact.command.js.map +1 -0
  135. package/dist/interfaces/cli/commands/index.d.ts +4 -6
  136. package/dist/interfaces/cli/commands/index.d.ts.map +1 -1
  137. package/dist/interfaces/cli/commands/index.js +6 -6
  138. package/dist/interfaces/cli/commands/index.js.map +1 -1
  139. package/dist/interfaces/cli/commands/move-member.command.js +7 -16
  140. package/dist/interfaces/cli/commands/move-member.command.js.map +1 -1
  141. package/dist/interfaces/cli/commands/move.command.js +21 -29
  142. package/dist/interfaces/cli/commands/move.command.js.map +1 -1
  143. package/dist/interfaces/cli/commands/rename.command.js +105 -119
  144. package/dist/interfaces/cli/commands/rename.command.js.map +1 -1
  145. package/dist/interfaces/cli/unified-output-handler.d.ts +3 -1
  146. package/dist/interfaces/cli/unified-output-handler.d.ts.map +1 -1
  147. package/dist/interfaces/cli/unified-output-handler.js +11 -2
  148. package/dist/interfaces/cli/unified-output-handler.js.map +1 -1
  149. package/dist/plugins/python/index.d.ts +0 -8
  150. package/dist/plugins/python/index.d.ts.map +1 -1
  151. package/dist/plugins/python/index.js +0 -9
  152. package/dist/plugins/python/index.js.map +1 -1
  153. package/dist/plugins/python/parser.d.ts +8 -41
  154. package/dist/plugins/python/parser.d.ts.map +1 -1
  155. package/dist/plugins/python/parser.js +30 -92
  156. package/dist/plugins/python/parser.js.map +1 -1
  157. package/dist/plugins/swift/parser.d.ts +4 -0
  158. package/dist/plugins/swift/parser.d.ts.map +1 -1
  159. package/dist/plugins/swift/parser.js +22 -4
  160. package/dist/plugins/swift/parser.js.map +1 -1
  161. package/dist/plugins/typescript/parser.d.ts +4 -37
  162. package/dist/plugins/typescript/parser.d.ts.map +1 -1
  163. package/dist/plugins/typescript/parser.js +17 -328
  164. package/dist/plugins/typescript/parser.js.map +1 -1
  165. package/dist/shared/types/symbol.d.ts +2 -1
  166. package/dist/shared/types/symbol.d.ts.map +1 -1
  167. package/dist/shared/types/symbol.js +1 -0
  168. package/dist/shared/types/symbol.js.map +1 -1
  169. package/package.json +2 -3
  170. package/dist/core/indexing/file-watcher.d.ts +0 -112
  171. package/dist/core/indexing/file-watcher.d.ts.map +0 -1
  172. package/dist/core/indexing/file-watcher.js +0 -284
  173. package/dist/core/indexing/file-watcher.js.map +0 -1
  174. package/dist/core/search/engines/text-engine.d.ts +0 -55
  175. package/dist/core/search/engines/text-engine.d.ts.map +0 -1
  176. package/dist/core/search/engines/text-engine.js +0 -377
  177. package/dist/core/search/engines/text-engine.js.map +0 -1
  178. package/dist/core/search/index.d.ts +0 -10
  179. package/dist/core/search/index.d.ts.map +0 -1
  180. package/dist/core/search/index.js +0 -11
  181. package/dist/core/search/index.js.map +0 -1
  182. package/dist/core/search/service.d.ts +0 -106
  183. package/dist/core/search/service.d.ts.map +0 -1
  184. package/dist/core/search/service.js +0 -384
  185. package/dist/core/search/service.js.map +0 -1
  186. package/dist/core/search/types.d.ts +0 -357
  187. package/dist/core/search/types.d.ts.map +0 -1
  188. package/dist/core/search/types.js +0 -47
  189. package/dist/core/search/types.js.map +0 -1
  190. package/dist/core/transform/index.d.ts +0 -10
  191. package/dist/core/transform/index.d.ts.map +0 -1
  192. package/dist/core/transform/index.js +0 -21
  193. package/dist/core/transform/index.js.map +0 -1
  194. package/dist/core/transform/location/index.d.ts +0 -8
  195. package/dist/core/transform/location/index.d.ts.map +0 -1
  196. package/dist/core/transform/location/index.js +0 -9
  197. package/dist/core/transform/location/index.js.map +0 -1
  198. package/dist/core/transform/location/move-file/import-resolver.d.ts.map +0 -1
  199. package/dist/core/transform/location/move-file/import-resolver.js.map +0 -1
  200. package/dist/core/transform/location/move-file/index.d.ts.map +0 -1
  201. package/dist/core/transform/location/move-file/index.js.map +0 -1
  202. package/dist/core/transform/location/move-file/move-service.d.ts.map +0 -1
  203. package/dist/core/transform/location/move-file/move-service.js.map +0 -1
  204. package/dist/core/transform/location/move-file/types.d.ts.map +0 -1
  205. package/dist/core/transform/location/move-file/types.js.map +0 -1
  206. package/dist/core/transform/location/move-member/index.d.ts.map +0 -1
  207. package/dist/core/transform/location/move-member/index.js.map +0 -1
  208. package/dist/core/transform/location/move-member/member-extractor.d.ts.map +0 -1
  209. package/dist/core/transform/location/move-member/member-extractor.js.map +0 -1
  210. package/dist/core/transform/location/move-member/move-member-service.d.ts.map +0 -1
  211. package/dist/core/transform/location/move-member/move-member-service.js.map +0 -1
  212. package/dist/core/transform/location/move-member/types.d.ts.map +0 -1
  213. package/dist/core/transform/location/move-member/types.js.map +0 -1
  214. package/dist/core/transform/location/shift/file-generator.d.ts +0 -45
  215. package/dist/core/transform/location/shift/file-generator.d.ts.map +0 -1
  216. package/dist/core/transform/location/shift/file-generator.js +0 -94
  217. package/dist/core/transform/location/shift/file-generator.js.map +0 -1
  218. package/dist/core/transform/location/shift/index.d.ts +0 -11
  219. package/dist/core/transform/location/shift/index.d.ts.map +0 -1
  220. package/dist/core/transform/location/shift/index.js +0 -13
  221. package/dist/core/transform/location/shift/index.js.map +0 -1
  222. package/dist/core/transform/location/shift/line-extractor.d.ts +0 -55
  223. package/dist/core/transform/location/shift/line-extractor.d.ts.map +0 -1
  224. package/dist/core/transform/location/shift/line-extractor.js +0 -123
  225. package/dist/core/transform/location/shift/line-extractor.js.map +0 -1
  226. package/dist/core/transform/location/shift/shift-service.d.ts +0 -57
  227. package/dist/core/transform/location/shift/shift-service.d.ts.map +0 -1
  228. package/dist/core/transform/location/shift/shift-service.js +0 -199
  229. package/dist/core/transform/location/shift/shift-service.js.map +0 -1
  230. package/dist/core/transform/location/shift/types.d.ts +0 -195
  231. package/dist/core/transform/location/shift/types.d.ts.map +0 -1
  232. package/dist/core/transform/location/shift/types.js +0 -89
  233. package/dist/core/transform/location/shift/types.js.map +0 -1
  234. package/dist/core/transform/shared/code-editor.d.ts +0 -70
  235. package/dist/core/transform/shared/code-editor.d.ts.map +0 -1
  236. package/dist/core/transform/shared/code-editor.js +0 -206
  237. package/dist/core/transform/shared/code-editor.js.map +0 -1
  238. package/dist/core/transform/shared/index.d.ts +0 -7
  239. package/dist/core/transform/shared/index.d.ts.map +0 -1
  240. package/dist/core/transform/shared/index.js +0 -7
  241. package/dist/core/transform/shared/index.js.map +0 -1
  242. package/dist/core/transform/shared/symbol-finder.d.ts.map +0 -1
  243. package/dist/core/transform/shared/symbol-finder.js.map +0 -1
  244. package/dist/core/transform/structure/extract/extract-function.d.ts +0 -197
  245. package/dist/core/transform/structure/extract/extract-function.d.ts.map +0 -1
  246. package/dist/core/transform/structure/extract/extract-function.js +0 -730
  247. package/dist/core/transform/structure/extract/extract-function.js.map +0 -1
  248. package/dist/core/transform/structure/extract/index.d.ts +0 -7
  249. package/dist/core/transform/structure/extract/index.d.ts.map +0 -1
  250. package/dist/core/transform/structure/extract/index.js +0 -9
  251. package/dist/core/transform/structure/extract/index.js.map +0 -1
  252. package/dist/core/transform/structure/extract/swift-extractor.d.ts +0 -98
  253. package/dist/core/transform/structure/extract/swift-extractor.d.ts.map +0 -1
  254. package/dist/core/transform/structure/extract/swift-extractor.js +0 -283
  255. package/dist/core/transform/structure/extract/swift-extractor.js.map +0 -1
  256. package/dist/core/transform/structure/index.d.ts +0 -8
  257. package/dist/core/transform/structure/index.d.ts.map +0 -1
  258. package/dist/core/transform/structure/index.js +0 -8
  259. package/dist/core/transform/structure/index.js.map +0 -1
  260. package/dist/core/transform/structure/inline/index.d.ts +0 -6
  261. package/dist/core/transform/structure/inline/index.d.ts.map +0 -1
  262. package/dist/core/transform/structure/inline/index.js +0 -6
  263. package/dist/core/transform/structure/inline/index.js.map +0 -1
  264. package/dist/core/transform/structure/inline/inline-function.d.ts +0 -175
  265. package/dist/core/transform/structure/inline/inline-function.d.ts.map +0 -1
  266. package/dist/core/transform/structure/inline/inline-function.js +0 -436
  267. package/dist/core/transform/structure/inline/inline-function.js.map +0 -1
  268. package/dist/core/transform/structure/patterns/design-patterns.d.ts +0 -178
  269. package/dist/core/transform/structure/patterns/design-patterns.d.ts.map +0 -1
  270. package/dist/core/transform/structure/patterns/design-patterns.js +0 -656
  271. package/dist/core/transform/structure/patterns/design-patterns.js.map +0 -1
  272. package/dist/core/transform/structure/patterns/index.d.ts +0 -6
  273. package/dist/core/transform/structure/patterns/index.d.ts.map +0 -1
  274. package/dist/core/transform/structure/patterns/index.js +0 -6
  275. package/dist/core/transform/structure/patterns/index.js.map +0 -1
  276. package/dist/core/transform/symbol/change-signature/change-signature-service.d.ts.map +0 -1
  277. package/dist/core/transform/symbol/change-signature/change-signature-service.js.map +0 -1
  278. package/dist/core/transform/symbol/change-signature/index.d.ts.map +0 -1
  279. package/dist/core/transform/symbol/change-signature/index.js.map +0 -1
  280. package/dist/core/transform/symbol/change-signature/signature-parser.d.ts.map +0 -1
  281. package/dist/core/transform/symbol/change-signature/signature-parser.js.map +0 -1
  282. package/dist/core/transform/symbol/change-signature/types.d.ts.map +0 -1
  283. package/dist/core/transform/symbol/change-signature/types.js.map +0 -1
  284. package/dist/core/transform/symbol/index.d.ts +0 -7
  285. package/dist/core/transform/symbol/index.d.ts.map +0 -1
  286. package/dist/core/transform/symbol/index.js +0 -7
  287. package/dist/core/transform/symbol/index.js.map +0 -1
  288. package/dist/core/transform/symbol/rename/index.d.ts.map +0 -1
  289. package/dist/core/transform/symbol/rename/index.js.map +0 -1
  290. package/dist/core/transform/symbol/rename/reference-updater.d.ts.map +0 -1
  291. package/dist/core/transform/symbol/rename/reference-updater.js.map +0 -1
  292. package/dist/core/transform/symbol/rename/rename-engine.d.ts.map +0 -1
  293. package/dist/core/transform/symbol/rename/rename-engine.js.map +0 -1
  294. package/dist/core/transform/symbol/rename/scope-analyzer.d.ts.map +0 -1
  295. package/dist/core/transform/symbol/rename/scope-analyzer.js.map +0 -1
  296. package/dist/core/transform/symbol/rename/types.d.ts.map +0 -1
  297. package/dist/core/transform/symbol/rename/types.js.map +0 -1
  298. package/dist/core/transform/types.d.ts +0 -185
  299. package/dist/core/transform/types.d.ts.map +0 -1
  300. package/dist/core/transform/types.js +0 -150
  301. package/dist/core/transform/types.js.map +0 -1
  302. package/dist/infrastructure/parser/factory.d.ts +0 -141
  303. package/dist/infrastructure/parser/factory.d.ts.map +0 -1
  304. package/dist/infrastructure/parser/factory.js +0 -306
  305. package/dist/infrastructure/parser/factory.js.map +0 -1
  306. package/dist/infrastructure/storage/file-watcher.d.ts +0 -84
  307. package/dist/infrastructure/storage/file-watcher.d.ts.map +0 -1
  308. package/dist/infrastructure/storage/file-watcher.js +0 -249
  309. package/dist/infrastructure/storage/file-watcher.js.map +0 -1
  310. package/dist/infrastructure/storage/path-utils.d.ts +0 -96
  311. package/dist/infrastructure/storage/path-utils.d.ts.map +0 -1
  312. package/dist/infrastructure/storage/path-utils.js +0 -272
  313. package/dist/infrastructure/storage/path-utils.js.map +0 -1
  314. package/dist/interfaces/cli/commands/analyze.command.d.ts +0 -11
  315. package/dist/interfaces/cli/commands/analyze.command.d.ts.map +0 -1
  316. package/dist/interfaces/cli/commands/analyze.command.js +0 -460
  317. package/dist/interfaces/cli/commands/analyze.command.js.map +0 -1
  318. package/dist/interfaces/cli/commands/deps.command.d.ts +0 -11
  319. package/dist/interfaces/cli/commands/deps.command.d.ts.map +0 -1
  320. package/dist/interfaces/cli/commands/deps.command.js +0 -143
  321. package/dist/interfaces/cli/commands/deps.command.js.map +0 -1
  322. package/dist/interfaces/cli/commands/extract.command.d.ts +0 -11
  323. package/dist/interfaces/cli/commands/extract.command.d.ts.map +0 -1
  324. package/dist/interfaces/cli/commands/extract.command.js +0 -314
  325. package/dist/interfaces/cli/commands/extract.command.js.map +0 -1
  326. package/dist/interfaces/cli/commands/inline.command.d.ts +0 -11
  327. package/dist/interfaces/cli/commands/inline.command.d.ts.map +0 -1
  328. package/dist/interfaces/cli/commands/inline.command.js +0 -208
  329. package/dist/interfaces/cli/commands/inline.command.js.map +0 -1
  330. package/dist/interfaces/cli/commands/refactor.command.d.ts +0 -11
  331. package/dist/interfaces/cli/commands/refactor.command.d.ts.map +0 -1
  332. package/dist/interfaces/cli/commands/refactor.command.js +0 -414
  333. package/dist/interfaces/cli/commands/refactor.command.js.map +0 -1
  334. package/dist/interfaces/cli/commands/search.command.d.ts +0 -11
  335. package/dist/interfaces/cli/commands/search.command.d.ts.map +0 -1
  336. package/dist/interfaces/cli/commands/search.command.js +0 -409
  337. package/dist/interfaces/cli/commands/search.command.js.map +0 -1
  338. package/dist/interfaces/cli/commands/shift.command.d.ts +0 -11
  339. package/dist/interfaces/cli/commands/shift.command.d.ts.map +0 -1
  340. package/dist/interfaces/cli/commands/shift.command.js +0 -143
  341. package/dist/interfaces/cli/commands/shift.command.js.map +0 -1
  342. package/dist/plugins/python/analyzers/complexity-analyzer.d.ts +0 -50
  343. package/dist/plugins/python/analyzers/complexity-analyzer.d.ts.map +0 -1
  344. package/dist/plugins/python/analyzers/complexity-analyzer.js +0 -172
  345. package/dist/plugins/python/analyzers/complexity-analyzer.js.map +0 -1
  346. package/dist/plugins/python/analyzers/duplication-detector.d.ts +0 -39
  347. package/dist/plugins/python/analyzers/duplication-detector.d.ts.map +0 -1
  348. package/dist/plugins/python/analyzers/duplication-detector.js +0 -146
  349. package/dist/plugins/python/analyzers/duplication-detector.js.map +0 -1
  350. package/dist/plugins/python/analyzers/error-handling-checker.d.ts +0 -28
  351. package/dist/plugins/python/analyzers/error-handling-checker.d.ts.map +0 -1
  352. package/dist/plugins/python/analyzers/error-handling-checker.js +0 -143
  353. package/dist/plugins/python/analyzers/error-handling-checker.js.map +0 -1
  354. package/dist/plugins/python/analyzers/naming-checker.d.ts +0 -56
  355. package/dist/plugins/python/analyzers/naming-checker.d.ts.map +0 -1
  356. package/dist/plugins/python/analyzers/naming-checker.js +0 -220
  357. package/dist/plugins/python/analyzers/naming-checker.js.map +0 -1
  358. package/dist/plugins/python/analyzers/pattern-detector.d.ts +0 -44
  359. package/dist/plugins/python/analyzers/pattern-detector.d.ts.map +0 -1
  360. package/dist/plugins/python/analyzers/pattern-detector.js +0 -222
  361. package/dist/plugins/python/analyzers/pattern-detector.js.map +0 -1
  362. package/dist/plugins/python/analyzers/security-checker.d.ts +0 -56
  363. package/dist/plugins/python/analyzers/security-checker.d.ts.map +0 -1
  364. package/dist/plugins/python/analyzers/security-checker.js +0 -279
  365. package/dist/plugins/python/analyzers/security-checker.js.map +0 -1
  366. package/dist/plugins/python/analyzers/type-safety-checker.d.ts +0 -44
  367. package/dist/plugins/python/analyzers/type-safety-checker.d.ts.map +0 -1
  368. package/dist/plugins/python/analyzers/type-safety-checker.js +0 -177
  369. package/dist/plugins/python/analyzers/type-safety-checker.js.map +0 -1
  370. package/dist/plugins/python/analyzers/unused-symbol-detector.d.ts +0 -37
  371. package/dist/plugins/python/analyzers/unused-symbol-detector.d.ts.map +0 -1
  372. package/dist/plugins/python/analyzers/unused-symbol-detector.js +0 -141
  373. package/dist/plugins/python/analyzers/unused-symbol-detector.js.map +0 -1
  374. package/dist/plugins/swift/analyzers/complexity-analyzer.d.ts +0 -41
  375. package/dist/plugins/swift/analyzers/complexity-analyzer.d.ts.map +0 -1
  376. package/dist/plugins/swift/analyzers/complexity-analyzer.js +0 -206
  377. package/dist/plugins/swift/analyzers/complexity-analyzer.js.map +0 -1
  378. package/dist/plugins/swift/analyzers/duplication-detector.d.ts +0 -89
  379. package/dist/plugins/swift/analyzers/duplication-detector.d.ts.map +0 -1
  380. package/dist/plugins/swift/analyzers/duplication-detector.js +0 -271
  381. package/dist/plugins/swift/analyzers/duplication-detector.js.map +0 -1
  382. package/dist/plugins/swift/analyzers/error-handling-checker.d.ts +0 -34
  383. package/dist/plugins/swift/analyzers/error-handling-checker.d.ts.map +0 -1
  384. package/dist/plugins/swift/analyzers/error-handling-checker.js +0 -135
  385. package/dist/plugins/swift/analyzers/error-handling-checker.js.map +0 -1
  386. package/dist/plugins/swift/analyzers/naming-checker.d.ts +0 -47
  387. package/dist/plugins/swift/analyzers/naming-checker.d.ts.map +0 -1
  388. package/dist/plugins/swift/analyzers/naming-checker.js +0 -161
  389. package/dist/plugins/swift/analyzers/naming-checker.js.map +0 -1
  390. package/dist/plugins/swift/analyzers/pattern-detector.d.ts +0 -78
  391. package/dist/plugins/swift/analyzers/pattern-detector.d.ts.map +0 -1
  392. package/dist/plugins/swift/analyzers/pattern-detector.js +0 -247
  393. package/dist/plugins/swift/analyzers/pattern-detector.js.map +0 -1
  394. package/dist/plugins/swift/analyzers/security-checker.d.ts +0 -38
  395. package/dist/plugins/swift/analyzers/security-checker.d.ts.map +0 -1
  396. package/dist/plugins/swift/analyzers/security-checker.js +0 -135
  397. package/dist/plugins/swift/analyzers/security-checker.js.map +0 -1
  398. package/dist/plugins/swift/analyzers/type-safety-checker.d.ts +0 -41
  399. package/dist/plugins/swift/analyzers/type-safety-checker.d.ts.map +0 -1
  400. package/dist/plugins/swift/analyzers/type-safety-checker.js +0 -121
  401. package/dist/plugins/swift/analyzers/type-safety-checker.js.map +0 -1
  402. package/dist/plugins/swift/analyzers/unused-symbol-detector.d.ts +0 -38
  403. package/dist/plugins/swift/analyzers/unused-symbol-detector.d.ts.map +0 -1
  404. package/dist/plugins/swift/analyzers/unused-symbol-detector.js +0 -211
  405. package/dist/plugins/swift/analyzers/unused-symbol-detector.js.map +0 -1
  406. package/dist/plugins/typescript/analyzers/complexity-analyzer.d.ts +0 -39
  407. package/dist/plugins/typescript/analyzers/complexity-analyzer.d.ts.map +0 -1
  408. package/dist/plugins/typescript/analyzers/complexity-analyzer.js +0 -196
  409. package/dist/plugins/typescript/analyzers/complexity-analyzer.js.map +0 -1
  410. package/dist/plugins/typescript/analyzers/duplication-detector.d.ts +0 -181
  411. package/dist/plugins/typescript/analyzers/duplication-detector.d.ts.map +0 -1
  412. package/dist/plugins/typescript/analyzers/duplication-detector.js +0 -695
  413. package/dist/plugins/typescript/analyzers/duplication-detector.js.map +0 -1
  414. package/dist/plugins/typescript/analyzers/error-handling-checker.d.ts +0 -26
  415. package/dist/plugins/typescript/analyzers/error-handling-checker.d.ts.map +0 -1
  416. package/dist/plugins/typescript/analyzers/error-handling-checker.js +0 -84
  417. package/dist/plugins/typescript/analyzers/error-handling-checker.js.map +0 -1
  418. package/dist/plugins/typescript/analyzers/naming-checker.d.ts +0 -30
  419. package/dist/plugins/typescript/analyzers/naming-checker.d.ts.map +0 -1
  420. package/dist/plugins/typescript/analyzers/naming-checker.js +0 -116
  421. package/dist/plugins/typescript/analyzers/naming-checker.js.map +0 -1
  422. package/dist/plugins/typescript/analyzers/pattern-detector.d.ts +0 -80
  423. package/dist/plugins/typescript/analyzers/pattern-detector.d.ts.map +0 -1
  424. package/dist/plugins/typescript/analyzers/pattern-detector.js +0 -267
  425. package/dist/plugins/typescript/analyzers/pattern-detector.js.map +0 -1
  426. package/dist/plugins/typescript/analyzers/security-checker.d.ts +0 -34
  427. package/dist/plugins/typescript/analyzers/security-checker.d.ts.map +0 -1
  428. package/dist/plugins/typescript/analyzers/security-checker.js +0 -126
  429. package/dist/plugins/typescript/analyzers/security-checker.js.map +0 -1
  430. package/dist/plugins/typescript/analyzers/type-safety-checker.d.ts +0 -32
  431. package/dist/plugins/typescript/analyzers/type-safety-checker.d.ts.map +0 -1
  432. package/dist/plugins/typescript/analyzers/type-safety-checker.js +0 -86
  433. package/dist/plugins/typescript/analyzers/type-safety-checker.js.map +0 -1
  434. package/dist/plugins/typescript/analyzers/unused-symbol-detector.d.ts +0 -47
  435. package/dist/plugins/typescript/analyzers/unused-symbol-detector.d.ts.map +0 -1
  436. package/dist/plugins/typescript/analyzers/unused-symbol-detector.js +0 -152
  437. package/dist/plugins/typescript/analyzers/unused-symbol-detector.js.map +0 -1
  438. /package/dist/core/{transform/symbol/change-signature → change-signature}/index.d.ts +0 -0
  439. /package/dist/core/{transform/symbol/change-signature → change-signature}/index.js +0 -0
  440. /package/dist/core/{transform/symbol/change-signature → change-signature}/signature-parser.js +0 -0
  441. /package/dist/core/{transform/symbol/change-signature → change-signature}/types.js +0 -0
  442. /package/dist/core/{transform/location/move-file → move-file}/index.d.ts +0 -0
  443. /package/dist/core/{transform/location/move-file → move-file}/index.js +0 -0
  444. /package/dist/core/{transform/location/move-file → move-file}/types.js +0 -0
  445. /package/dist/core/{transform/location/move-member → move-member}/index.d.ts +0 -0
  446. /package/dist/core/{transform/location/move-member → move-member}/index.js +0 -0
  447. /package/dist/core/{transform/location/move-member → move-member}/member-extractor.js +0 -0
  448. /package/dist/core/{transform/location/move-member → move-member}/types.js +0 -0
  449. /package/dist/core/{transform/symbol/rename → rename}/index.d.ts +0 -0
  450. /package/dist/core/{transform/symbol/rename → rename}/index.js +0 -0
  451. /package/dist/core/{transform/symbol/rename → rename}/types.js +0 -0
  452. /package/dist/core/{transform/shared → shared}/symbol-finder.js +0 -0
@@ -1,695 +0,0 @@
1
- /**
2
- * 重複程式碼檢測器
3
- * 檢測程式碼克隆,包括 Type-1、Type-2 和 Type-3 克隆
4
- */
5
- import { createHash } from 'crypto';
6
- /**
7
- * 計算程式碼片段的平均行數
8
- */
9
- function calculateAverageLines(fragments) {
10
- const totalLines = fragments.reduce((sum, f) => sum + (f.location.endLine - f.location.startLine + 1), 0);
11
- return Math.round(totalLines / fragments.length);
12
- }
13
- /**
14
- * Type-1 克隆檢測器(完全相同的代碼,除了空白和註釋)
15
- */
16
- export class Type1CloneDetector {
17
- /**
18
- * 檢測 Type-1 克隆
19
- * @param fragments 程式碼片段列表
20
- * @param config 檢測配置
21
- * @returns Type-1 克隆列表
22
- */
23
- detect(fragments, config) {
24
- const clones = [];
25
- const hashGroups = new Map();
26
- // 按 hash 分組
27
- for (const fragment of fragments) {
28
- if (fragment.tokens.length < config.minTokens) {
29
- continue;
30
- }
31
- const hash = this.computeHash(fragment, config);
32
- if (!hashGroups.has(hash)) {
33
- hashGroups.set(hash, []);
34
- }
35
- const group = hashGroups.get(hash);
36
- if (group) {
37
- group.push(fragment);
38
- }
39
- }
40
- // 找出重複的組
41
- for (const group of hashGroups.values()) {
42
- if (group.length > 1) {
43
- clones.push({
44
- type: 'type-1',
45
- instances: group,
46
- lines: calculateAverageLines(group),
47
- similarity: 1.0,
48
- severity: this.calculateSeverity(group.length, calculateAverageLines(group))
49
- });
50
- }
51
- }
52
- return clones;
53
- }
54
- /**
55
- * 計算程式碼片段的 hash
56
- */
57
- computeHash(fragment, config) {
58
- let tokens = fragment.tokens.slice();
59
- if (config.ignoreWhitespace) {
60
- tokens = tokens.filter(token => !/^\s+$/.test(token));
61
- }
62
- if (config.ignoreComments) {
63
- tokens = tokens.filter(token => !token.startsWith('//') && !token.startsWith('/*'));
64
- }
65
- const normalized = tokens.join('');
66
- return createHash('md5').update(normalized).digest('hex');
67
- }
68
- calculateSeverity(instanceCount, lines) {
69
- if (instanceCount >= 5 || lines >= 50) {
70
- return 'high';
71
- }
72
- if (instanceCount >= 3 || lines >= 20) {
73
- return 'medium';
74
- }
75
- return 'low';
76
- }
77
- }
78
- /**
79
- * Type-2 克隆檢測器(結構相同但變數名、類型、字面值不同)
80
- */
81
- export class Type2CloneDetector {
82
- /**
83
- * 檢測 Type-2 克隆
84
- * @param fragments 程式碼片段列表
85
- * @param config 檢測配置
86
- * @returns Type-2 克隆列表(僅包含跨檔案重複)
87
- */
88
- detect(fragments, config) {
89
- const clones = [];
90
- const normalizedGroups = new Map();
91
- for (const fragment of fragments) {
92
- if (fragment.tokens.length < config.minTokens) {
93
- continue;
94
- }
95
- const normalized = this.normalizeAST(fragment.ast);
96
- const hash = this.computeNormalizedHash(normalized);
97
- if (!normalizedGroups.has(hash)) {
98
- normalizedGroups.set(hash, []);
99
- }
100
- const group = normalizedGroups.get(hash);
101
- if (group) {
102
- group.push(fragment);
103
- }
104
- }
105
- for (const group of normalizedGroups.values()) {
106
- if (group.length > 1) {
107
- // 過濾掉同一檔案內的重複(同一個類的不同方法不應視為重複)
108
- const crossFileInstances = this.filterCrossFileInstances(group);
109
- if (crossFileInstances.length > 1) {
110
- clones.push({
111
- type: 'type-2',
112
- instances: crossFileInstances,
113
- lines: calculateAverageLines(crossFileInstances),
114
- similarity: this.calculateSimilarity(crossFileInstances),
115
- severity: this.calculateSeverity(crossFileInstances.length, calculateAverageLines(crossFileInstances))
116
- });
117
- }
118
- }
119
- }
120
- return clones;
121
- }
122
- /**
123
- * 過濾掉同一檔案內的實例,只保留跨檔案的重複
124
- */
125
- filterCrossFileInstances(instances) {
126
- const fileGroups = new Map();
127
- for (const instance of instances) {
128
- const file = instance.location.file;
129
- if (!fileGroups.has(file)) {
130
- fileGroups.set(file, []);
131
- }
132
- fileGroups.get(file).push(instance);
133
- }
134
- // 如果所有實例都在同一個檔案,返回空陣列
135
- if (fileGroups.size === 1) {
136
- return [];
137
- }
138
- // 每個檔案只保留一個代表
139
- return Array.from(fileGroups.values()).map(group => group[0]);
140
- }
141
- /**
142
- * 正規化 AST(移除變數名、字面值等)
143
- */
144
- normalizeAST(ast) {
145
- const normalized = {
146
- type: ast.type
147
- };
148
- // 對於變數和字面值,統一為佔位符
149
- if (ast.type === 'Identifier') {
150
- normalized.value = '$VAR$';
151
- }
152
- else if (ast.type === 'Literal') {
153
- normalized.value = '$LITERAL$';
154
- }
155
- else if (ast.value !== undefined) {
156
- normalized.value = ast.value;
157
- }
158
- // 遞歸處理子節點
159
- if (ast.children) {
160
- normalized.children = ast.children.map(child => this.normalizeAST(child));
161
- }
162
- return normalized;
163
- }
164
- /**
165
- * 計算正規化 AST 的 hash
166
- */
167
- computeNormalizedHash(ast) {
168
- const json = JSON.stringify(ast, Object.keys(ast).sort());
169
- return createHash('md5').update(json).digest('hex');
170
- }
171
- calculateSimilarity(fragments) {
172
- // Type-2 克隆的相似度計算
173
- return 0.85; // 簡化實作
174
- }
175
- calculateSeverity(instanceCount, lines) {
176
- if (instanceCount >= 4 || lines >= 40) {
177
- return 'high';
178
- }
179
- if (instanceCount >= 3 || lines >= 15) {
180
- return 'medium';
181
- }
182
- return 'low';
183
- }
184
- }
185
- /**
186
- * Type-3 克隆檢測器(結構相似但有些語句被修改、新增或刪除)
187
- */
188
- export class Type3CloneDetector {
189
- threshold = 0.7; // 預設相似度閾值
190
- /**
191
- * 設定相似度閾值
192
- * @param threshold 相似度閾值(0-1 之間)
193
- */
194
- setThreshold(threshold) {
195
- this.threshold = Math.max(0, Math.min(1, threshold));
196
- }
197
- /**
198
- * 檢測 Type-3 克隆
199
- * @param fragments 程式碼片段列表
200
- * @param config 檢測配置
201
- * @returns Type-3 克隆列表(僅包含跨檔案重複)
202
- */
203
- detect(fragments, config) {
204
- const clones = [];
205
- const effectiveThreshold = Math.min(config.similarityThreshold, this.threshold);
206
- // Type-3 檢測需要比較每對片段的相似度
207
- for (let i = 0; i < fragments.length; i++) {
208
- for (let j = i + 1; j < fragments.length; j++) {
209
- // 跳過同一檔案內的片段
210
- if (fragments[i].location.file === fragments[j].location.file) {
211
- continue;
212
- }
213
- const similarity = this.calculateSimilarity(fragments[i], fragments[j]);
214
- if (similarity >= effectiveThreshold && similarity < 0.95) { // Type-3 不是完全相同
215
- clones.push({
216
- type: 'type-3',
217
- instances: [fragments[i], fragments[j]],
218
- lines: Math.max(fragments[i].location.endLine - fragments[i].location.startLine + 1, fragments[j].location.endLine - fragments[j].location.startLine + 1),
219
- similarity,
220
- severity: this.calculateSeverity(similarity, Math.max(fragments[i].location.endLine - fragments[i].location.startLine + 1, fragments[j].location.endLine - fragments[j].location.startLine + 1))
221
- });
222
- }
223
- }
224
- }
225
- return clones;
226
- }
227
- /**
228
- * 計算兩個程式碼片段的相似度
229
- */
230
- calculateSimilarity(fragment1, fragment2) {
231
- // 使用改進的相似度計算
232
- return this.calculateAdvancedSimilarity(fragment1, fragment2);
233
- }
234
- /**
235
- * 計算編輯距離(Levenshtein Distance)
236
- */
237
- calculateEditDistance(tokens1, tokens2) {
238
- const m = tokens1.length;
239
- const n = tokens2.length;
240
- // 處理空陣列情況
241
- if (m === 0) {
242
- return n;
243
- }
244
- if (n === 0) {
245
- return m;
246
- }
247
- const dp = Array(m + 1).fill(null).map(() => Array(n + 1).fill(0));
248
- // 初始化邊界條件
249
- for (let i = 0; i <= m; i++) {
250
- dp[i][0] = i;
251
- }
252
- for (let j = 0; j <= n; j++) {
253
- dp[0][j] = j;
254
- }
255
- // 動態規劃計算編輯距離
256
- for (let i = 1; i <= m; i++) {
257
- for (let j = 1; j <= n; j++) {
258
- if (tokens1[i - 1] === tokens2[j - 1]) {
259
- dp[i][j] = dp[i - 1][j - 1]; // 無需編輯
260
- }
261
- else {
262
- dp[i][j] = Math.min(dp[i - 1][j] + 1, // 刪除
263
- dp[i][j - 1] + 1, // 插入
264
- dp[i - 1][j - 1] + 1 // 替換
265
- );
266
- }
267
- }
268
- }
269
- return dp[m][n];
270
- }
271
- /**
272
- * 改進的相似度計算(結合多種指標)
273
- */
274
- calculateAdvancedSimilarity(fragment1, fragment2) {
275
- const tokens1 = fragment1.tokens;
276
- const tokens2 = fragment2.tokens;
277
- if (tokens1.length === 0 && tokens2.length === 0) {
278
- return 1.0;
279
- }
280
- if (tokens1.length === 0 || tokens2.length === 0) {
281
- return 0.0;
282
- }
283
- // 1. 編輯距離相似度
284
- const editDistance = this.calculateEditDistance(tokens1, tokens2);
285
- const maxLength = Math.max(tokens1.length, tokens2.length);
286
- const editSimilarity = 1 - (editDistance / maxLength);
287
- // 2. Jaccard 相似度(基於 token 集合)
288
- const set1 = new Set(tokens1);
289
- const set2 = new Set(tokens2);
290
- const intersection = new Set([...set1].filter(x => set2.has(x)));
291
- const union = new Set([...set1, ...set2]);
292
- const jaccardSimilarity = intersection.size / union.size;
293
- // 3. 長度相似度
294
- const lengthSimilarity = Math.min(tokens1.length, tokens2.length) /
295
- Math.max(tokens1.length, tokens2.length);
296
- // 綜合相似度(加權平均)
297
- return (editSimilarity * 0.5) + (jaccardSimilarity * 0.3) + (lengthSimilarity * 0.2);
298
- }
299
- calculateSeverity(similarity, lines) {
300
- if (similarity >= 0.8 && lines >= 30) {
301
- return 'high';
302
- }
303
- if (similarity >= 0.7 && lines >= 15) {
304
- return 'medium';
305
- }
306
- return 'low';
307
- }
308
- }
309
- /**
310
- * 重複程式碼檢測器主類
311
- */
312
- export class DuplicationDetector {
313
- type1Detector = new Type1CloneDetector();
314
- type2Detector = new Type2CloneDetector();
315
- type3Detector = new Type3CloneDetector();
316
- /**
317
- * 設定 Type-3 檢測的相似度閾值
318
- */
319
- setThreshold(threshold) {
320
- this.type3Detector.setThreshold(threshold);
321
- }
322
- /**
323
- * 檢測程式碼克隆 (兼容舊介面)
324
- */
325
- detectClones(fragments) {
326
- const fullConfig = {
327
- minLines: 3,
328
- minTokens: 5,
329
- similarityThreshold: 0.7,
330
- ignoreWhitespace: true,
331
- ignoreComments: true
332
- };
333
- // 直接檢測不同類型的克隆
334
- const type1Clones = this.type1Detector.detect(fragments, fullConfig);
335
- const type2Clones = this.type2Detector.detect(fragments, fullConfig);
336
- const type3Clones = this.type3Detector.detect(fragments, fullConfig);
337
- return [...type1Clones, ...type2Clones, ...type3Clones];
338
- }
339
- /**
340
- * 檢測檔案中的重複程式碼
341
- * @param files 檔案路徑列表
342
- * @param config 檢測配置
343
- * @returns 重複程式碼檢測結果
344
- */
345
- async detect(files, config) {
346
- // 輸入驗證
347
- if (!Array.isArray(files)) {
348
- throw new Error('檔案列表必須是陣列');
349
- }
350
- const fullConfig = {
351
- minLines: 3,
352
- minTokens: 5,
353
- similarityThreshold: 0.7,
354
- ignoreWhitespace: true,
355
- ignoreComments: true,
356
- ...config
357
- };
358
- // 解析所有檔案並提取程式碼片段
359
- const fragments = await this.extractFragments(files);
360
- // 檢測不同類型的克隆
361
- const type1Clones = this.type1Detector.detect(fragments, fullConfig);
362
- const type2Clones = this.type2Detector.detect(fragments, fullConfig);
363
- const type3Clones = this.type3Detector.detect(fragments, fullConfig);
364
- return [...type1Clones, ...type2Clones, ...type3Clones];
365
- }
366
- /**
367
- * 從檔案中提取程式碼片段
368
- */
369
- async extractFragments(files) {
370
- const { readFile } = await import('fs/promises');
371
- const fragments = [];
372
- for (const file of files) {
373
- try {
374
- const content = await readFile(file, 'utf-8');
375
- const fileFragments = this.parseFileToFragments(file, content);
376
- fragments.push(...fileFragments);
377
- }
378
- catch (error) {
379
- continue;
380
- }
381
- }
382
- return fragments;
383
- }
384
- /**
385
- * 將檔案內容解析為程式碼片段(提取多種類型的代碼結構)
386
- */
387
- parseFileToFragments(filePath, content) {
388
- if (typeof filePath !== 'string' || filePath.trim() === '') {
389
- throw new Error('檔案路徑必須是非空字串');
390
- }
391
- if (typeof content !== 'string') {
392
- throw new Error('檔案內容必須是字串');
393
- }
394
- const fragments = [];
395
- // 1. 提取頂層註解(版權宣告等)
396
- fragments.push(...this.extractTopLevelComments(filePath, content));
397
- // 2. 提取常數定義
398
- fragments.push(...this.extractConstantDefinitions(filePath, content));
399
- // 3. 提取配置物件
400
- fragments.push(...this.extractConfigObjects(filePath, content));
401
- // 4. 提取方法和函式
402
- fragments.push(...this.extractMethods(filePath, content));
403
- // 如果仍然沒有找到任何片段,回退到按行分割
404
- if (fragments.length === 0) {
405
- const lines = content.split('\n');
406
- for (let i = 0; i < lines.length; i += 10) {
407
- const endLine = Math.min(i + 9, lines.length - 1);
408
- const fragmentContent = lines.slice(i, endLine + 1).join('\n');
409
- if (fragmentContent.trim().length > 0) {
410
- fragments.push({
411
- id: `${filePath}:${i + 1}-${endLine + 1}`,
412
- ast: this.parseToAST(fragmentContent),
413
- tokens: this.tokenize(fragmentContent),
414
- location: {
415
- file: filePath,
416
- startLine: i + 1,
417
- endLine: endLine + 1
418
- }
419
- });
420
- }
421
- }
422
- }
423
- return fragments;
424
- }
425
- /**
426
- * 提取檔案開頭的頂層註解(如版權宣告)
427
- */
428
- extractTopLevelComments(filePath, content) {
429
- const fragments = [];
430
- const lines = content.split('\n');
431
- // 只檢查檔案開頭的註解(前 50 行內)
432
- const headerLines = lines.slice(0, Math.min(50, lines.length));
433
- let commentStart = -1;
434
- let commentEnd = -1;
435
- let inBlockComment = false;
436
- for (let i = 0; i < headerLines.length; i++) {
437
- const line = headerLines[i].trim();
438
- // 檢測多行註解開始
439
- if (line.startsWith('/**') || line.startsWith('/*')) {
440
- if (commentStart === -1) {
441
- commentStart = i;
442
- }
443
- inBlockComment = true;
444
- }
445
- // 檢測多行註解結束
446
- if (inBlockComment && line.includes('*/')) {
447
- commentEnd = i;
448
- inBlockComment = false;
449
- // 提取完整的註解區塊
450
- const commentContent = lines.slice(commentStart, commentEnd + 1).join('\n');
451
- const lineCount = commentEnd - commentStart + 1;
452
- // 只處理 >= 3 行的註解區塊
453
- if (lineCount >= 3) {
454
- fragments.push({
455
- id: `${filePath}:comment:${commentStart + 1}-${commentEnd + 1}`,
456
- ast: this.parseToAST(commentContent),
457
- tokens: this.tokenize(commentContent, true), // 保留註解
458
- location: {
459
- file: filePath,
460
- startLine: commentStart + 1,
461
- endLine: commentEnd + 1
462
- }
463
- });
464
- }
465
- commentStart = -1;
466
- commentEnd = -1;
467
- }
468
- // 遇到非空白、非註解的行就停止(不再是頂層註解)
469
- if (!line.startsWith('//') &&
470
- !line.startsWith('/*') &&
471
- !line.startsWith('*') &&
472
- !line.includes('*/') &&
473
- line.length > 0) {
474
- break;
475
- }
476
- }
477
- return fragments;
478
- }
479
- /**
480
- * 提取常數定義(export const、const 等)
481
- */
482
- extractConstantDefinitions(filePath, content) {
483
- const fragments = [];
484
- // 匹配常數定義(包括物件定義)
485
- // 例如:export const XXX = { ... }; 或 const XXX = { ... };
486
- const constRegex = /(export\s+)?const\s+([A-Z_][A-Z0-9_]*)\s*=\s*\{/gm;
487
- let match;
488
- while ((match = constRegex.exec(content)) !== null) {
489
- const startPos = match.index;
490
- const startLine = content.substring(0, startPos).split('\n').length;
491
- const constName = match[2];
492
- // 找到物件定義的開始 { 位置
493
- const bracePos = match.index + match[0].length - 1;
494
- // 找到配對的 }
495
- const endPos = this.findMatchingBrace(content, bracePos);
496
- if (endPos === -1) {
497
- continue;
498
- }
499
- const endLine = content.substring(0, endPos + 1).split('\n').length;
500
- const fragmentContent = content.substring(startPos, endPos + 1);
501
- const lineCount = endLine - startLine + 1;
502
- // 只處理 >= 3 行的常數定義
503
- if (lineCount >= 3) {
504
- fragments.push({
505
- id: `${filePath}:const:${startLine}:${constName}`,
506
- ast: this.parseToAST(fragmentContent),
507
- tokens: this.tokenize(fragmentContent),
508
- location: {
509
- file: filePath,
510
- startLine,
511
- endLine
512
- }
513
- });
514
- }
515
- }
516
- return fragments;
517
- }
518
- /**
519
- * 提取配置物件(識別常見的配置模式)
520
- */
521
- extractConfigObjects(filePath, content) {
522
- const fragments = [];
523
- // 匹配常見的配置物件模式
524
- // 例如:{ host: ..., port: ..., database: ... }
525
- const configKeywords = ['host', 'port', 'database', 'uri', 'url', 'connection', 'options', 'config'];
526
- const lines = content.split('\n');
527
- for (let i = 0; i < lines.length; i++) {
528
- const line = lines[i];
529
- // 檢查是否包含配置相關關鍵字
530
- const hasConfigKeyword = configKeywords.some(keyword => line.includes(`${keyword}:`) || line.includes(`${keyword} =`));
531
- if (hasConfigKeyword && line.includes('{')) {
532
- // 找到配置物件的開始
533
- const startPos = content.substring(0, content.indexOf(lines.slice(0, i + 1).join('\n'))).length;
534
- const braceIndex = line.indexOf('{');
535
- const bracePos = startPos + braceIndex;
536
- const endPos = this.findMatchingBrace(content, bracePos);
537
- if (endPos === -1) {
538
- continue;
539
- }
540
- const startLine = i + 1;
541
- const endLine = content.substring(0, endPos + 1).split('\n').length;
542
- const fragmentContent = content.substring(bracePos, endPos + 1);
543
- const lineCount = endLine - startLine + 1;
544
- // 只處理 >= 3 行的配置物件
545
- if (lineCount >= 3) {
546
- fragments.push({
547
- id: `${filePath}:config:${startLine}-${endLine}`,
548
- ast: this.parseToAST(fragmentContent),
549
- tokens: this.tokenize(fragmentContent),
550
- location: {
551
- file: filePath,
552
- startLine,
553
- endLine
554
- }
555
- });
556
- // 跳過已處理的行
557
- i = endLine - 1;
558
- }
559
- }
560
- }
561
- return fragments;
562
- }
563
- /**
564
- * 提取方法和函式(原有邏輯)
565
- */
566
- extractMethods(filePath, content) {
567
- const fragments = [];
568
- // 提取方法和函式的正則表達式(更寬鬆的匹配)
569
- const methodRegex = /(\s*)(async\s+)?(\w+)\s*\([^)]*\)\s*\{/gm;
570
- let match;
571
- while ((match = methodRegex.exec(content)) !== null) {
572
- const startPos = match.index;
573
- const startLine = content.substring(0, startPos).split('\n').length;
574
- const methodName = match[3];
575
- // 找到方法開始的 { 位置
576
- const bracePos = startPos + match[0].length - 1;
577
- // 找到方法的結束位置(配對大括號)
578
- const endPos = this.findMatchingBrace(content, bracePos);
579
- if (endPos === -1) {
580
- continue;
581
- }
582
- const endLine = content.substring(0, endPos + 1).split('\n').length;
583
- const fragmentContent = content.substring(startPos, endPos + 1);
584
- const lineCount = endLine - startLine + 1;
585
- // 只處理行數 >= 3 的方法
586
- if (lineCount >= 3) {
587
- const tokens = this.tokenize(fragmentContent);
588
- fragments.push({
589
- id: `${filePath}:${startLine}:${methodName}`,
590
- ast: this.parseToAST(fragmentContent),
591
- tokens,
592
- location: {
593
- file: filePath,
594
- startLine,
595
- endLine
596
- }
597
- });
598
- }
599
- }
600
- return fragments;
601
- }
602
- /**
603
- * 找到配對的右大括號
604
- */
605
- findMatchingBrace(content, startPos) {
606
- let braceCount = 1;
607
- let inString = false;
608
- let stringChar = '';
609
- for (let i = startPos + 1; i < content.length; i++) {
610
- const char = content[i];
611
- const prevChar = content[i - 1];
612
- // 處理字串
613
- if ((char === '"' || char === '\'' || char === '`') && prevChar !== '\\') {
614
- if (!inString) {
615
- inString = true;
616
- stringChar = char;
617
- }
618
- else if (char === stringChar) {
619
- inString = false;
620
- }
621
- continue;
622
- }
623
- if (!inString) {
624
- if (char === '{') {
625
- braceCount++;
626
- }
627
- else if (char === '}') {
628
- braceCount--;
629
- if (braceCount === 0) {
630
- return i;
631
- }
632
- }
633
- }
634
- }
635
- return -1;
636
- }
637
- /**
638
- * 簡化的 AST 解析
639
- */
640
- parseToAST(content) {
641
- // 簡化實作:建立基本的 AST 結構
642
- return {
643
- type: 'Program',
644
- children: content.split('\n').map(line => ({
645
- type: 'Statement',
646
- value: line.trim()
647
- }))
648
- };
649
- }
650
- /**
651
- * 程式碼分詞
652
- * @param content 程式碼內容
653
- * @param preserveComments 是否保留註解(預設false會過濾註解)
654
- */
655
- tokenize(content, preserveComments = false) {
656
- // 按空白和操作符分割
657
- const tokens = content
658
- .split(/(\s+|[(){}[\];,.]|\+|\-|\*|\/|=|!|<|>|&|\|)/)
659
- .filter(token => token.trim().length > 0);
660
- // 如果不保留註解,過濾掉註解 tokens
661
- if (!preserveComments) {
662
- return tokens.filter(token => {
663
- const trimmed = token.trim();
664
- return !trimmed.startsWith('//') &&
665
- !trimmed.startsWith('/*') &&
666
- !trimmed.startsWith('*') &&
667
- !trimmed.includes('*/');
668
- });
669
- }
670
- return tokens;
671
- }
672
- /**
673
- * 獲取重複檢測統計
674
- */
675
- async getStatistics(clones) {
676
- const byType = { 'type-1': 0, 'type-2': 0, 'type-3': 0 };
677
- const bySeverity = { low: 0, medium: 0, high: 0 };
678
- let totalSimilarity = 0;
679
- let totalLines = 0;
680
- for (const clone of clones) {
681
- byType[clone.type]++;
682
- bySeverity[clone.severity]++;
683
- totalSimilarity += clone.similarity;
684
- totalLines += clone.lines * clone.instances.length;
685
- }
686
- return {
687
- totalClones: clones.length,
688
- byType,
689
- bySeverity,
690
- averageSimilarity: clones.length > 0 ? totalSimilarity / clones.length : 0,
691
- totalDuplicatedLines: totalLines
692
- };
693
- }
694
- }
695
- //# sourceMappingURL=duplication-detector.js.map