agent-ide 0.2.0 → 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 (543) hide show
  1. package/README.md +29 -355
  2. package/dist/application/events/event-bus.d.ts.map +1 -1
  3. package/dist/application/events/event-bus.js.map +1 -1
  4. package/dist/application/index.d.ts +3 -1
  5. package/dist/application/index.d.ts.map +1 -1
  6. package/dist/application/index.js +10 -5
  7. package/dist/application/index.js.map +1 -1
  8. package/dist/application/services/cache-coordinator.service.d.ts.map +1 -1
  9. package/dist/application/services/cache-coordinator.service.js.map +1 -1
  10. package/dist/application/services/error-handler.service.d.ts.map +1 -1
  11. package/dist/application/services/error-handler.service.js.map +1 -1
  12. package/dist/application/services/module-coordinator.service.d.ts +5 -14
  13. package/dist/application/services/module-coordinator.service.d.ts.map +1 -1
  14. package/dist/application/services/module-coordinator.service.js +15 -108
  15. package/dist/application/services/module-coordinator.service.js.map +1 -1
  16. package/dist/application/services/session-manager.service.d.ts.map +1 -1
  17. package/dist/application/services/session-manager.service.js.map +1 -1
  18. package/dist/application/services/workflow-engine.service.d.ts +1 -1
  19. package/dist/application/services/workflow-engine.service.d.ts.map +1 -1
  20. package/dist/application/services/workflow-engine.service.js.map +1 -1
  21. package/dist/application/state/state-manager.d.ts +3 -3
  22. package/dist/application/state/state-manager.d.ts.map +1 -1
  23. package/dist/application/state/state-manager.js +3 -3
  24. package/dist/application/state/state-manager.js.map +1 -1
  25. package/dist/application/types.d.ts.map +1 -1
  26. package/dist/application/workflows/analysis-workflow.d.ts +1 -1
  27. package/dist/application/workflows/analysis-workflow.d.ts.map +1 -1
  28. package/dist/application/workflows/analysis-workflow.js +1 -1
  29. package/dist/application/workflows/analysis-workflow.js.map +1 -1
  30. package/dist/application/workflows/base-workflow.d.ts.map +1 -1
  31. package/dist/application/workflows/base-workflow.js.map +1 -1
  32. package/dist/application/workflows/index.d.ts +2 -2
  33. package/dist/application/workflows/index.d.ts.map +1 -1
  34. package/dist/application/workflows/index.js +2 -2
  35. package/dist/application/workflows/index.js.map +1 -1
  36. package/dist/application/workflows/refactor-workflow.d.ts +1 -1
  37. package/dist/application/workflows/refactor-workflow.d.ts.map +1 -1
  38. package/dist/application/workflows/refactor-workflow.js +1 -1
  39. package/dist/application/workflows/refactor-workflow.js.map +1 -1
  40. package/dist/core/change-signature/change-signature-service.d.ts +94 -0
  41. package/dist/core/change-signature/change-signature-service.d.ts.map +1 -0
  42. package/dist/core/change-signature/change-signature-service.js +544 -0
  43. package/dist/core/change-signature/change-signature-service.js.map +1 -0
  44. package/dist/core/change-signature/index.d.ts +10 -0
  45. package/dist/core/change-signature/index.d.ts.map +1 -0
  46. package/dist/core/change-signature/index.js +12 -0
  47. package/dist/core/change-signature/index.js.map +1 -0
  48. package/dist/core/change-signature/signature-parser.d.ts +76 -0
  49. package/dist/core/change-signature/signature-parser.d.ts.map +1 -0
  50. package/dist/core/change-signature/signature-parser.js +387 -0
  51. package/dist/core/change-signature/signature-parser.js.map +1 -0
  52. package/dist/core/change-signature/types.d.ts +244 -0
  53. package/dist/core/change-signature/types.d.ts.map +1 -0
  54. package/dist/core/change-signature/types.js +73 -0
  55. package/dist/core/change-signature/types.js.map +1 -0
  56. package/dist/core/dependency/cycle-detector.d.ts +1 -1
  57. package/dist/core/dependency/cycle-detector.d.ts.map +1 -1
  58. package/dist/core/dependency/cycle-detector.js +1 -1
  59. package/dist/core/dependency/cycle-detector.js.map +1 -1
  60. package/dist/core/dependency/dependency-analyzer.d.ts +3 -1
  61. package/dist/core/dependency/dependency-analyzer.d.ts.map +1 -1
  62. package/dist/core/dependency/dependency-analyzer.js +25 -24
  63. package/dist/core/dependency/dependency-analyzer.js.map +1 -1
  64. package/dist/core/dependency/types.d.ts.map +1 -1
  65. package/dist/core/indexing/file-index.d.ts.map +1 -1
  66. package/dist/core/indexing/file-index.js +1 -1
  67. package/dist/core/indexing/file-index.js.map +1 -1
  68. package/dist/core/indexing/index-engine.d.ts +3 -1
  69. package/dist/core/indexing/index-engine.d.ts.map +1 -1
  70. package/dist/core/indexing/index-engine.js +25 -17
  71. package/dist/core/indexing/index-engine.js.map +1 -1
  72. package/dist/core/indexing/index.d.ts +1 -9
  73. package/dist/core/indexing/index.d.ts.map +1 -1
  74. package/dist/core/indexing/index.js +2 -12
  75. package/dist/core/indexing/index.js.map +1 -1
  76. package/dist/core/indexing/symbol-index.d.ts.map +1 -1
  77. package/dist/core/indexing/types.d.ts +12 -0
  78. package/dist/core/indexing/types.d.ts.map +1 -1
  79. package/dist/core/indexing/types.js +12 -0
  80. package/dist/core/indexing/types.js.map +1 -1
  81. package/dist/core/move-file/import-resolver.d.ts.map +1 -0
  82. package/dist/core/{move → move-file}/import-resolver.js +9 -10
  83. package/dist/core/move-file/import-resolver.js.map +1 -0
  84. package/dist/core/{move → move-file}/index.d.ts +2 -2
  85. package/dist/core/move-file/index.d.ts.map +1 -0
  86. package/dist/core/{move → move-file}/index.js +2 -2
  87. package/dist/core/move-file/index.js.map +1 -0
  88. package/dist/core/{move → move-file}/move-service.d.ts +3 -1
  89. package/dist/core/move-file/move-service.d.ts.map +1 -0
  90. package/dist/core/{move → move-file}/move-service.js +66 -84
  91. package/dist/core/move-file/move-service.js.map +1 -0
  92. package/dist/core/move-file/types.d.ts.map +1 -0
  93. package/dist/core/move-file/types.js.map +1 -0
  94. package/dist/core/move-member/index.d.ts +10 -0
  95. package/dist/core/move-member/index.d.ts.map +1 -0
  96. package/dist/core/move-member/index.js +12 -0
  97. package/dist/core/move-member/index.js.map +1 -0
  98. package/dist/core/move-member/member-extractor.d.ts +96 -0
  99. package/dist/core/move-member/member-extractor.d.ts.map +1 -0
  100. package/dist/core/move-member/member-extractor.js +439 -0
  101. package/dist/core/move-member/member-extractor.js.map +1 -0
  102. package/dist/core/move-member/move-member-service.d.ts +87 -0
  103. package/dist/core/move-member/move-member-service.d.ts.map +1 -0
  104. package/dist/core/move-member/move-member-service.js +412 -0
  105. package/dist/core/move-member/move-member-service.js.map +1 -0
  106. package/dist/core/move-member/types.d.ts +182 -0
  107. package/dist/core/move-member/types.d.ts.map +1 -0
  108. package/dist/core/move-member/types.js +75 -0
  109. package/dist/core/move-member/types.js.map +1 -0
  110. package/dist/core/rename/index.d.ts +3 -3
  111. package/dist/core/rename/index.d.ts.map +1 -1
  112. package/dist/core/rename/index.js +5 -3
  113. package/dist/core/rename/index.js.map +1 -1
  114. package/dist/core/rename/reference-updater.d.ts +3 -1
  115. package/dist/core/rename/reference-updater.d.ts.map +1 -1
  116. package/dist/core/rename/reference-updater.js +9 -6
  117. package/dist/core/rename/reference-updater.js.map +1 -1
  118. package/dist/core/rename/rename-engine.d.ts +3 -1
  119. package/dist/core/rename/rename-engine.d.ts.map +1 -1
  120. package/dist/core/rename/rename-engine.js +8 -5
  121. package/dist/core/rename/rename-engine.js.map +1 -1
  122. package/dist/core/rename/scope-analyzer.d.ts.map +1 -1
  123. package/dist/core/rename/scope-analyzer.js.map +1 -1
  124. package/dist/core/rename/types.d.ts.map +1 -1
  125. package/dist/core/shared/call-hierarchy-analyzer.d.ts +102 -0
  126. package/dist/core/shared/call-hierarchy-analyzer.d.ts.map +1 -0
  127. package/dist/core/shared/call-hierarchy-analyzer.js +328 -0
  128. package/dist/core/shared/call-hierarchy-analyzer.js.map +1 -0
  129. package/dist/core/shared/index.d.ts +7 -0
  130. package/dist/core/shared/index.d.ts.map +1 -0
  131. package/dist/core/shared/index.js +7 -0
  132. package/dist/core/shared/index.js.map +1 -0
  133. package/dist/core/shared/symbol-finder.d.ts +154 -0
  134. package/dist/core/shared/symbol-finder.d.ts.map +1 -0
  135. package/dist/core/shared/symbol-finder.js +433 -0
  136. package/dist/core/shared/symbol-finder.js.map +1 -0
  137. package/dist/core/snapshot/index.d.ts +3 -19
  138. package/dist/core/snapshot/index.d.ts.map +1 -1
  139. package/dist/core/snapshot/index.js +2 -23
  140. package/dist/core/snapshot/index.js.map +1 -1
  141. package/dist/core/snapshot/snapshot-generator.d.ts +66 -0
  142. package/dist/core/snapshot/snapshot-generator.d.ts.map +1 -0
  143. package/dist/core/snapshot/snapshot-generator.js +258 -0
  144. package/dist/core/snapshot/snapshot-generator.js.map +1 -0
  145. package/dist/core/snapshot/types.d.ts +41 -190
  146. package/dist/core/snapshot/types.d.ts.map +1 -1
  147. package/dist/core/snapshot/types.js +13 -67
  148. package/dist/core/snapshot/types.js.map +1 -1
  149. package/dist/infrastructure/cache/cache-manager.d.ts +1 -1
  150. package/dist/infrastructure/cache/cache-manager.d.ts.map +1 -1
  151. package/dist/infrastructure/cache/cache-manager.js +1 -1
  152. package/dist/infrastructure/cache/cache-manager.js.map +1 -1
  153. package/dist/infrastructure/cache/memory-cache.js +1 -1
  154. package/dist/infrastructure/cache/memory-cache.js.map +1 -1
  155. package/dist/infrastructure/cache/strategies.d.ts +1 -1
  156. package/dist/infrastructure/cache/strategies.d.ts.map +1 -1
  157. package/dist/infrastructure/cache/strategies.js +1 -1
  158. package/dist/infrastructure/cache/strategies.js.map +1 -1
  159. package/dist/infrastructure/formatters/diff-generator.d.ts +11 -0
  160. package/dist/infrastructure/formatters/diff-generator.d.ts.map +1 -0
  161. package/dist/infrastructure/formatters/diff-generator.js +227 -0
  162. package/dist/infrastructure/formatters/diff-generator.js.map +1 -0
  163. package/dist/infrastructure/formatters/index.d.ts +11 -0
  164. package/dist/infrastructure/formatters/index.d.ts.map +1 -0
  165. package/dist/infrastructure/formatters/index.js +13 -0
  166. package/dist/infrastructure/formatters/index.js.map +1 -0
  167. package/dist/infrastructure/formatters/preview-converter.d.ts +85 -0
  168. package/dist/infrastructure/formatters/preview-converter.d.ts.map +1 -0
  169. package/dist/infrastructure/formatters/preview-converter.js +209 -0
  170. package/dist/infrastructure/formatters/preview-converter.js.map +1 -0
  171. package/dist/infrastructure/formatters/preview-formatter.d.ts +61 -0
  172. package/dist/infrastructure/formatters/preview-formatter.d.ts.map +1 -0
  173. package/dist/infrastructure/formatters/preview-formatter.js +208 -0
  174. package/dist/infrastructure/formatters/preview-formatter.js.map +1 -0
  175. package/dist/infrastructure/formatters/query-formatter.d.ts +83 -0
  176. package/dist/infrastructure/formatters/query-formatter.d.ts.map +1 -0
  177. package/dist/infrastructure/formatters/query-formatter.js +349 -0
  178. package/dist/infrastructure/formatters/query-formatter.js.map +1 -0
  179. package/dist/infrastructure/formatters/query-types.d.ts +238 -0
  180. package/dist/infrastructure/formatters/query-types.d.ts.map +1 -0
  181. package/dist/infrastructure/formatters/query-types.js +29 -0
  182. package/dist/infrastructure/formatters/query-types.js.map +1 -0
  183. package/dist/infrastructure/formatters/types.d.ts +163 -0
  184. package/dist/infrastructure/formatters/types.d.ts.map +1 -0
  185. package/dist/infrastructure/formatters/types.js +27 -0
  186. package/dist/infrastructure/formatters/types.js.map +1 -0
  187. package/dist/infrastructure/parser/base.d.ts +1 -33
  188. package/dist/infrastructure/parser/base.d.ts.map +1 -1
  189. package/dist/infrastructure/parser/base.js +1 -65
  190. package/dist/infrastructure/parser/base.js.map +1 -1
  191. package/dist/infrastructure/parser/index.d.ts +0 -2
  192. package/dist/infrastructure/parser/index.d.ts.map +1 -1
  193. package/dist/infrastructure/parser/index.js +1 -2
  194. package/dist/infrastructure/parser/index.js.map +1 -1
  195. package/dist/infrastructure/parser/interface.d.ts +2 -59
  196. package/dist/infrastructure/parser/interface.d.ts.map +1 -1
  197. package/dist/infrastructure/parser/interface.js +1 -11
  198. package/dist/infrastructure/parser/interface.js.map +1 -1
  199. package/dist/infrastructure/parser/registry.d.ts +1 -1
  200. package/dist/infrastructure/parser/registry.d.ts.map +1 -1
  201. package/dist/infrastructure/parser/registry.js +1 -1
  202. package/dist/infrastructure/parser/registry.js.map +1 -1
  203. package/dist/infrastructure/parser/types.d.ts.map +1 -1
  204. package/dist/infrastructure/storage/file-system.d.ts +2 -1
  205. package/dist/infrastructure/storage/file-system.d.ts.map +1 -1
  206. package/dist/infrastructure/storage/file-system.interface.d.ts +69 -0
  207. package/dist/infrastructure/storage/file-system.interface.d.ts.map +1 -0
  208. package/dist/infrastructure/storage/file-system.interface.js +6 -0
  209. package/dist/infrastructure/storage/file-system.interface.js.map +1 -0
  210. package/dist/infrastructure/storage/file-system.js.map +1 -1
  211. package/dist/infrastructure/storage/index.d.ts +2 -4
  212. package/dist/infrastructure/storage/index.d.ts.map +1 -1
  213. package/dist/infrastructure/storage/index.js +1 -8
  214. package/dist/infrastructure/storage/index.js.map +1 -1
  215. package/dist/infrastructure/storage/mem-file-system.d.ts +44 -0
  216. package/dist/infrastructure/storage/mem-file-system.d.ts.map +1 -0
  217. package/dist/infrastructure/storage/mem-file-system.js +105 -0
  218. package/dist/infrastructure/storage/mem-file-system.js.map +1 -0
  219. package/dist/interfaces/cli/cli.d.ts +13 -94
  220. package/dist/interfaces/cli/cli.d.ts.map +1 -1
  221. package/dist/interfaces/cli/cli.js +47 -2450
  222. package/dist/interfaces/cli/cli.js.map +1 -1
  223. package/dist/interfaces/cli/commands/call-hierarchy.command.d.ts +11 -0
  224. package/dist/interfaces/cli/commands/call-hierarchy.command.d.ts.map +1 -0
  225. package/dist/interfaces/cli/commands/call-hierarchy.command.js +161 -0
  226. package/dist/interfaces/cli/commands/call-hierarchy.command.js.map +1 -0
  227. package/dist/interfaces/cli/commands/change-signature.command.d.ts +11 -0
  228. package/dist/interfaces/cli/commands/change-signature.command.d.ts.map +1 -0
  229. package/dist/interfaces/cli/commands/change-signature.command.js +290 -0
  230. package/dist/interfaces/cli/commands/change-signature.command.js.map +1 -0
  231. package/dist/interfaces/cli/commands/cycles.command.d.ts +11 -0
  232. package/dist/interfaces/cli/commands/cycles.command.d.ts.map +1 -0
  233. package/dist/interfaces/cli/commands/cycles.command.js +87 -0
  234. package/dist/interfaces/cli/commands/cycles.command.js.map +1 -0
  235. package/dist/interfaces/cli/commands/find-references.command.d.ts +11 -0
  236. package/dist/interfaces/cli/commands/find-references.command.d.ts.map +1 -0
  237. package/dist/interfaces/cli/commands/find-references.command.js +122 -0
  238. package/dist/interfaces/cli/commands/find-references.command.js.map +1 -0
  239. package/dist/interfaces/cli/commands/impact.command.d.ts +11 -0
  240. package/dist/interfaces/cli/commands/impact.command.d.ts.map +1 -0
  241. package/dist/interfaces/cli/commands/impact.command.js +98 -0
  242. package/dist/interfaces/cli/commands/impact.command.js.map +1 -0
  243. package/dist/interfaces/cli/commands/index.d.ts +14 -0
  244. package/dist/interfaces/cli/commands/index.d.ts.map +1 -0
  245. package/dist/interfaces/cli/commands/index.js +15 -0
  246. package/dist/interfaces/cli/commands/index.js.map +1 -0
  247. package/dist/interfaces/cli/commands/move-member.command.d.ts +11 -0
  248. package/dist/interfaces/cli/commands/move-member.command.d.ts.map +1 -0
  249. package/dist/interfaces/cli/commands/move-member.command.js +185 -0
  250. package/dist/interfaces/cli/commands/move-member.command.js.map +1 -0
  251. package/dist/interfaces/cli/commands/move.command.d.ts +11 -0
  252. package/dist/interfaces/cli/commands/move.command.d.ts.map +1 -0
  253. package/dist/interfaces/cli/commands/move.command.js +212 -0
  254. package/dist/interfaces/cli/commands/move.command.js.map +1 -0
  255. package/dist/interfaces/cli/commands/rename.command.d.ts +11 -0
  256. package/dist/interfaces/cli/commands/rename.command.d.ts.map +1 -0
  257. package/dist/interfaces/cli/commands/rename.command.js +258 -0
  258. package/dist/interfaces/cli/commands/rename.command.js.map +1 -0
  259. package/dist/interfaces/cli/commands/snapshot.command.d.ts +11 -0
  260. package/dist/interfaces/cli/commands/snapshot.command.d.ts.map +1 -0
  261. package/dist/interfaces/cli/commands/snapshot.command.js +68 -0
  262. package/dist/interfaces/cli/commands/snapshot.command.js.map +1 -0
  263. package/dist/interfaces/cli/commands/types.d.ts +18 -0
  264. package/dist/interfaces/cli/commands/types.d.ts.map +1 -0
  265. package/dist/interfaces/cli/commands/types.js +5 -0
  266. package/dist/interfaces/cli/commands/types.js.map +1 -0
  267. package/dist/interfaces/cli/index.d.ts +1 -1
  268. package/dist/interfaces/cli/index.d.ts.map +1 -1
  269. package/dist/interfaces/cli/index.js +1 -1
  270. package/dist/interfaces/cli/index.js.map +1 -1
  271. package/dist/interfaces/cli/preview-output-handler.d.ts +53 -0
  272. package/dist/interfaces/cli/preview-output-handler.d.ts.map +1 -0
  273. package/dist/interfaces/cli/preview-output-handler.js +73 -0
  274. package/dist/interfaces/cli/preview-output-handler.js.map +1 -0
  275. package/dist/interfaces/cli/unified-output-handler.d.ts +79 -0
  276. package/dist/interfaces/cli/unified-output-handler.d.ts.map +1 -0
  277. package/dist/interfaces/cli/unified-output-handler.js +149 -0
  278. package/dist/interfaces/cli/unified-output-handler.js.map +1 -0
  279. package/dist/plugins/javascript/index.d.ts +2 -2
  280. package/dist/plugins/javascript/index.d.ts.map +1 -1
  281. package/dist/plugins/javascript/index.js +1 -1
  282. package/dist/plugins/javascript/index.js.map +1 -1
  283. package/dist/plugins/javascript/types.d.ts.map +1 -1
  284. package/dist/plugins/javascript/types.js.map +1 -1
  285. package/dist/plugins/python/dependency-analyzer.d.ts +86 -0
  286. package/dist/plugins/python/dependency-analyzer.d.ts.map +1 -0
  287. package/dist/plugins/python/dependency-analyzer.js +252 -0
  288. package/dist/plugins/python/dependency-analyzer.js.map +1 -0
  289. package/dist/plugins/python/index.d.ts +9 -0
  290. package/dist/plugins/python/index.d.ts.map +1 -0
  291. package/dist/plugins/python/index.js +14 -0
  292. package/dist/plugins/python/index.js.map +1 -0
  293. package/dist/plugins/python/parser.d.ts +117 -0
  294. package/dist/plugins/python/parser.d.ts.map +1 -0
  295. package/dist/plugins/python/parser.js +414 -0
  296. package/dist/plugins/python/parser.js.map +1 -0
  297. package/dist/plugins/python/symbol-extractor.d.ts +108 -0
  298. package/dist/plugins/python/symbol-extractor.d.ts.map +1 -0
  299. package/dist/plugins/python/symbol-extractor.js +389 -0
  300. package/dist/plugins/python/symbol-extractor.js.map +1 -0
  301. package/dist/plugins/python/tree-sitter-bridge.d.ts +57 -0
  302. package/dist/plugins/python/tree-sitter-bridge.d.ts.map +1 -0
  303. package/dist/plugins/python/tree-sitter-bridge.js +267 -0
  304. package/dist/plugins/python/tree-sitter-bridge.js.map +1 -0
  305. package/dist/plugins/python/types.d.ts +179 -0
  306. package/dist/plugins/python/types.d.ts.map +1 -0
  307. package/dist/plugins/python/types.js +252 -0
  308. package/dist/plugins/python/types.js.map +1 -0
  309. package/dist/plugins/swift/dependency-analyzer.d.ts +1 -1
  310. package/dist/plugins/swift/dependency-analyzer.d.ts.map +1 -1
  311. package/dist/plugins/swift/dependency-analyzer.js +1 -1
  312. package/dist/plugins/swift/dependency-analyzer.js.map +1 -1
  313. package/dist/plugins/swift/parser.d.ts +4 -0
  314. package/dist/plugins/swift/parser.d.ts.map +1 -1
  315. package/dist/plugins/swift/parser.js +24 -6
  316. package/dist/plugins/swift/parser.js.map +1 -1
  317. package/dist/plugins/swift/symbol-extractor.d.ts +1 -1
  318. package/dist/plugins/swift/symbol-extractor.d.ts.map +1 -1
  319. package/dist/plugins/swift/symbol-extractor.js.map +1 -1
  320. package/dist/plugins/swift/types.d.ts.map +1 -1
  321. package/dist/plugins/swift/types.js.map +1 -1
  322. package/dist/plugins/typescript/parser.d.ts +4 -37
  323. package/dist/plugins/typescript/parser.d.ts.map +1 -1
  324. package/dist/plugins/typescript/parser.js +29 -331
  325. package/dist/plugins/typescript/parser.js.map +1 -1
  326. package/dist/plugins/typescript/symbol-extractor.d.ts.map +1 -1
  327. package/dist/plugins/typescript/symbol-extractor.js +12 -0
  328. package/dist/plugins/typescript/symbol-extractor.js.map +1 -1
  329. package/dist/plugins/typescript/types.d.ts.map +1 -1
  330. package/dist/plugins/typescript/types.js +10 -0
  331. package/dist/plugins/typescript/types.js.map +1 -1
  332. package/dist/shared/errors/config-error.d.ts +1 -1
  333. package/dist/shared/errors/config-error.d.ts.map +1 -1
  334. package/dist/shared/errors/config-error.js +1 -1
  335. package/dist/shared/errors/config-error.js.map +1 -1
  336. package/dist/shared/errors/file-error.d.ts +1 -1
  337. package/dist/shared/errors/file-error.d.ts.map +1 -1
  338. package/dist/shared/errors/file-error.js +1 -1
  339. package/dist/shared/errors/file-error.js.map +1 -1
  340. package/dist/shared/errors/index.d.ts +1 -1
  341. package/dist/shared/errors/index.d.ts.map +1 -1
  342. package/dist/shared/errors/index.js +4 -4
  343. package/dist/shared/errors/index.js.map +1 -1
  344. package/dist/shared/errors/parser-error.d.ts +1 -1
  345. package/dist/shared/errors/parser-error.d.ts.map +1 -1
  346. package/dist/shared/errors/parser-error.js +1 -1
  347. package/dist/shared/errors/parser-error.js.map +1 -1
  348. package/dist/shared/errors/validation-error.d.ts +1 -1
  349. package/dist/shared/errors/validation-error.d.ts.map +1 -1
  350. package/dist/shared/errors/validation-error.js +1 -1
  351. package/dist/shared/errors/validation-error.js.map +1 -1
  352. package/dist/shared/types/ast.d.ts +1 -1
  353. package/dist/shared/types/ast.d.ts.map +1 -1
  354. package/dist/shared/types/ast.js +1 -1
  355. package/dist/shared/types/ast.js.map +1 -1
  356. package/dist/shared/types/symbol.d.ts +3 -2
  357. package/dist/shared/types/symbol.d.ts.map +1 -1
  358. package/dist/shared/types/symbol.js +1 -0
  359. package/dist/shared/types/symbol.js.map +1 -1
  360. package/dist/shared/utils/index.d.ts +5 -5
  361. package/dist/shared/utils/index.d.ts.map +1 -1
  362. package/dist/shared/utils/index.js +5 -5
  363. package/dist/shared/utils/index.js.map +1 -1
  364. package/package.json +9 -8
  365. package/dist/core/analysis/index.d.ts +0 -6
  366. package/dist/core/analysis/index.d.ts.map +0 -1
  367. package/dist/core/analysis/index.js +0 -7
  368. package/dist/core/analysis/index.js.map +0 -1
  369. package/dist/core/analysis/quality-metrics.d.ts +0 -158
  370. package/dist/core/analysis/quality-metrics.d.ts.map +0 -1
  371. package/dist/core/analysis/quality-metrics.js +0 -442
  372. package/dist/core/analysis/quality-metrics.js.map +0 -1
  373. package/dist/core/indexing/file-watcher.d.ts +0 -110
  374. package/dist/core/indexing/file-watcher.d.ts.map +0 -1
  375. package/dist/core/indexing/file-watcher.js +0 -280
  376. package/dist/core/indexing/file-watcher.js.map +0 -1
  377. package/dist/core/move/import-resolver.d.ts.map +0 -1
  378. package/dist/core/move/import-resolver.js.map +0 -1
  379. package/dist/core/move/index.d.ts.map +0 -1
  380. package/dist/core/move/index.js.map +0 -1
  381. package/dist/core/move/move-service.d.ts.map +0 -1
  382. package/dist/core/move/move-service.js.map +0 -1
  383. package/dist/core/move/types.d.ts.map +0 -1
  384. package/dist/core/move/types.js.map +0 -1
  385. package/dist/core/refactor/design-patterns.d.ts +0 -178
  386. package/dist/core/refactor/design-patterns.d.ts.map +0 -1
  387. package/dist/core/refactor/design-patterns.js +0 -656
  388. package/dist/core/refactor/design-patterns.js.map +0 -1
  389. package/dist/core/refactor/extract-function.d.ts +0 -197
  390. package/dist/core/refactor/extract-function.d.ts.map +0 -1
  391. package/dist/core/refactor/extract-function.js +0 -730
  392. package/dist/core/refactor/extract-function.js.map +0 -1
  393. package/dist/core/refactor/index.d.ts +0 -8
  394. package/dist/core/refactor/index.d.ts.map +0 -1
  395. package/dist/core/refactor/index.js +0 -11
  396. package/dist/core/refactor/index.js.map +0 -1
  397. package/dist/core/refactor/inline-function.d.ts +0 -175
  398. package/dist/core/refactor/inline-function.d.ts.map +0 -1
  399. package/dist/core/refactor/inline-function.js +0 -425
  400. package/dist/core/refactor/inline-function.js.map +0 -1
  401. package/dist/core/refactor/swift-extractor.d.ts +0 -98
  402. package/dist/core/refactor/swift-extractor.d.ts.map +0 -1
  403. package/dist/core/refactor/swift-extractor.js +0 -283
  404. package/dist/core/refactor/swift-extractor.js.map +0 -1
  405. package/dist/core/search/engines/text-engine.d.ts +0 -52
  406. package/dist/core/search/engines/text-engine.d.ts.map +0 -1
  407. package/dist/core/search/engines/text-engine.js +0 -376
  408. package/dist/core/search/engines/text-engine.js.map +0 -1
  409. package/dist/core/search/index.d.ts +0 -10
  410. package/dist/core/search/index.d.ts.map +0 -1
  411. package/dist/core/search/index.js +0 -11
  412. package/dist/core/search/index.js.map +0 -1
  413. package/dist/core/search/service.d.ts +0 -105
  414. package/dist/core/search/service.d.ts.map +0 -1
  415. package/dist/core/search/service.js +0 -384
  416. package/dist/core/search/service.js.map +0 -1
  417. package/dist/core/search/types.d.ts +0 -357
  418. package/dist/core/search/types.d.ts.map +0 -1
  419. package/dist/core/search/types.js +0 -47
  420. package/dist/core/search/types.js.map +0 -1
  421. package/dist/core/shit-score/grading.d.ts +0 -39
  422. package/dist/core/shit-score/grading.d.ts.map +0 -1
  423. package/dist/core/shit-score/grading.js +0 -253
  424. package/dist/core/shit-score/grading.js.map +0 -1
  425. package/dist/core/shit-score/index.d.ts +0 -9
  426. package/dist/core/shit-score/index.d.ts.map +0 -1
  427. package/dist/core/shit-score/index.js +0 -8
  428. package/dist/core/shit-score/index.js.map +0 -1
  429. package/dist/core/shit-score/score-calculator.d.ts +0 -75
  430. package/dist/core/shit-score/score-calculator.d.ts.map +0 -1
  431. package/dist/core/shit-score/score-calculator.js +0 -240
  432. package/dist/core/shit-score/score-calculator.js.map +0 -1
  433. package/dist/core/shit-score/shit-score-analyzer.d.ts +0 -84
  434. package/dist/core/shit-score/shit-score-analyzer.d.ts.map +0 -1
  435. package/dist/core/shit-score/shit-score-analyzer.js +0 -595
  436. package/dist/core/shit-score/shit-score-analyzer.js.map +0 -1
  437. package/dist/core/shit-score/types.d.ts +0 -231
  438. package/dist/core/shit-score/types.d.ts.map +0 -1
  439. package/dist/core/shit-score/types.js +0 -73
  440. package/dist/core/shit-score/types.js.map +0 -1
  441. package/dist/core/snapshot/code-compressor.d.ts +0 -39
  442. package/dist/core/snapshot/code-compressor.d.ts.map +0 -1
  443. package/dist/core/snapshot/code-compressor.js +0 -211
  444. package/dist/core/snapshot/code-compressor.js.map +0 -1
  445. package/dist/core/snapshot/config.d.ts +0 -60
  446. package/dist/core/snapshot/config.d.ts.map +0 -1
  447. package/dist/core/snapshot/config.js +0 -136
  448. package/dist/core/snapshot/config.js.map +0 -1
  449. package/dist/core/snapshot/snapshot-differ.d.ts +0 -54
  450. package/dist/core/snapshot/snapshot-differ.d.ts.map +0 -1
  451. package/dist/core/snapshot/snapshot-differ.js +0 -262
  452. package/dist/core/snapshot/snapshot-differ.js.map +0 -1
  453. package/dist/core/snapshot/snapshot-engine.d.ts +0 -94
  454. package/dist/core/snapshot/snapshot-engine.d.ts.map +0 -1
  455. package/dist/core/snapshot/snapshot-engine.js +0 -492
  456. package/dist/core/snapshot/snapshot-engine.js.map +0 -1
  457. package/dist/infrastructure/parser/factory.d.ts +0 -141
  458. package/dist/infrastructure/parser/factory.d.ts.map +0 -1
  459. package/dist/infrastructure/parser/factory.js +0 -306
  460. package/dist/infrastructure/parser/factory.js.map +0 -1
  461. package/dist/infrastructure/storage/file-watcher.d.ts +0 -84
  462. package/dist/infrastructure/storage/file-watcher.d.ts.map +0 -1
  463. package/dist/infrastructure/storage/file-watcher.js +0 -249
  464. package/dist/infrastructure/storage/file-watcher.js.map +0 -1
  465. package/dist/infrastructure/storage/path-utils.d.ts +0 -96
  466. package/dist/infrastructure/storage/path-utils.d.ts.map +0 -1
  467. package/dist/infrastructure/storage/path-utils.js +0 -272
  468. package/dist/infrastructure/storage/path-utils.js.map +0 -1
  469. package/dist/plugins/swift/analyzers/complexity-analyzer.d.ts +0 -41
  470. package/dist/plugins/swift/analyzers/complexity-analyzer.d.ts.map +0 -1
  471. package/dist/plugins/swift/analyzers/complexity-analyzer.js +0 -206
  472. package/dist/plugins/swift/analyzers/complexity-analyzer.js.map +0 -1
  473. package/dist/plugins/swift/analyzers/duplication-detector.d.ts +0 -89
  474. package/dist/plugins/swift/analyzers/duplication-detector.d.ts.map +0 -1
  475. package/dist/plugins/swift/analyzers/duplication-detector.js +0 -271
  476. package/dist/plugins/swift/analyzers/duplication-detector.js.map +0 -1
  477. package/dist/plugins/swift/analyzers/error-handling-checker.d.ts +0 -34
  478. package/dist/plugins/swift/analyzers/error-handling-checker.d.ts.map +0 -1
  479. package/dist/plugins/swift/analyzers/error-handling-checker.js +0 -135
  480. package/dist/plugins/swift/analyzers/error-handling-checker.js.map +0 -1
  481. package/dist/plugins/swift/analyzers/naming-checker.d.ts +0 -47
  482. package/dist/plugins/swift/analyzers/naming-checker.d.ts.map +0 -1
  483. package/dist/plugins/swift/analyzers/naming-checker.js +0 -161
  484. package/dist/plugins/swift/analyzers/naming-checker.js.map +0 -1
  485. package/dist/plugins/swift/analyzers/pattern-detector.d.ts +0 -78
  486. package/dist/plugins/swift/analyzers/pattern-detector.d.ts.map +0 -1
  487. package/dist/plugins/swift/analyzers/pattern-detector.js +0 -247
  488. package/dist/plugins/swift/analyzers/pattern-detector.js.map +0 -1
  489. package/dist/plugins/swift/analyzers/security-checker.d.ts +0 -38
  490. package/dist/plugins/swift/analyzers/security-checker.d.ts.map +0 -1
  491. package/dist/plugins/swift/analyzers/security-checker.js +0 -135
  492. package/dist/plugins/swift/analyzers/security-checker.js.map +0 -1
  493. package/dist/plugins/swift/analyzers/test-coverage-checker.d.ts +0 -26
  494. package/dist/plugins/swift/analyzers/test-coverage-checker.d.ts.map +0 -1
  495. package/dist/plugins/swift/analyzers/test-coverage-checker.js +0 -63
  496. package/dist/plugins/swift/analyzers/test-coverage-checker.js.map +0 -1
  497. package/dist/plugins/swift/analyzers/type-safety-checker.d.ts +0 -41
  498. package/dist/plugins/swift/analyzers/type-safety-checker.d.ts.map +0 -1
  499. package/dist/plugins/swift/analyzers/type-safety-checker.js +0 -121
  500. package/dist/plugins/swift/analyzers/type-safety-checker.js.map +0 -1
  501. package/dist/plugins/swift/analyzers/unused-symbol-detector.d.ts +0 -38
  502. package/dist/plugins/swift/analyzers/unused-symbol-detector.d.ts.map +0 -1
  503. package/dist/plugins/swift/analyzers/unused-symbol-detector.js +0 -211
  504. package/dist/plugins/swift/analyzers/unused-symbol-detector.js.map +0 -1
  505. package/dist/plugins/typescript/analyzers/complexity-analyzer.d.ts +0 -39
  506. package/dist/plugins/typescript/analyzers/complexity-analyzer.d.ts.map +0 -1
  507. package/dist/plugins/typescript/analyzers/complexity-analyzer.js +0 -196
  508. package/dist/plugins/typescript/analyzers/complexity-analyzer.js.map +0 -1
  509. package/dist/plugins/typescript/analyzers/duplication-detector.d.ts +0 -181
  510. package/dist/plugins/typescript/analyzers/duplication-detector.d.ts.map +0 -1
  511. package/dist/plugins/typescript/analyzers/duplication-detector.js +0 -695
  512. package/dist/plugins/typescript/analyzers/duplication-detector.js.map +0 -1
  513. package/dist/plugins/typescript/analyzers/error-handling-checker.d.ts +0 -26
  514. package/dist/plugins/typescript/analyzers/error-handling-checker.d.ts.map +0 -1
  515. package/dist/plugins/typescript/analyzers/error-handling-checker.js +0 -84
  516. package/dist/plugins/typescript/analyzers/error-handling-checker.js.map +0 -1
  517. package/dist/plugins/typescript/analyzers/naming-checker.d.ts +0 -30
  518. package/dist/plugins/typescript/analyzers/naming-checker.d.ts.map +0 -1
  519. package/dist/plugins/typescript/analyzers/naming-checker.js +0 -116
  520. package/dist/plugins/typescript/analyzers/naming-checker.js.map +0 -1
  521. package/dist/plugins/typescript/analyzers/pattern-detector.d.ts +0 -80
  522. package/dist/plugins/typescript/analyzers/pattern-detector.d.ts.map +0 -1
  523. package/dist/plugins/typescript/analyzers/pattern-detector.js +0 -267
  524. package/dist/plugins/typescript/analyzers/pattern-detector.js.map +0 -1
  525. package/dist/plugins/typescript/analyzers/security-checker.d.ts +0 -34
  526. package/dist/plugins/typescript/analyzers/security-checker.d.ts.map +0 -1
  527. package/dist/plugins/typescript/analyzers/security-checker.js +0 -126
  528. package/dist/plugins/typescript/analyzers/security-checker.js.map +0 -1
  529. package/dist/plugins/typescript/analyzers/test-coverage-checker.d.ts +0 -22
  530. package/dist/plugins/typescript/analyzers/test-coverage-checker.d.ts.map +0 -1
  531. package/dist/plugins/typescript/analyzers/test-coverage-checker.js +0 -62
  532. package/dist/plugins/typescript/analyzers/test-coverage-checker.js.map +0 -1
  533. package/dist/plugins/typescript/analyzers/type-safety-checker.d.ts +0 -32
  534. package/dist/plugins/typescript/analyzers/type-safety-checker.d.ts.map +0 -1
  535. package/dist/plugins/typescript/analyzers/type-safety-checker.js +0 -86
  536. package/dist/plugins/typescript/analyzers/type-safety-checker.js.map +0 -1
  537. package/dist/plugins/typescript/analyzers/unused-symbol-detector.d.ts +0 -47
  538. package/dist/plugins/typescript/analyzers/unused-symbol-detector.d.ts.map +0 -1
  539. package/dist/plugins/typescript/analyzers/unused-symbol-detector.js +0 -152
  540. package/dist/plugins/typescript/analyzers/unused-symbol-detector.js.map +0 -1
  541. /package/dist/core/{move → move-file}/import-resolver.d.ts +0 -0
  542. /package/dist/core/{move → move-file}/types.d.ts +0 -0
  543. /package/dist/core/{move → move-file}/types.js +0 -0
@@ -1,730 +0,0 @@
1
- /**
2
- * 提取函式重構器
3
- * 將選取的程式碼片段提取為獨立函式
4
- */
5
- import * as ts from 'typescript';
6
- import { TypeScriptParser } from '../../plugins/typescript/parser.js';
7
- /**
8
- * 函式提取分析器
9
- * 分析選取的程式碼是否適合提取為函式
10
- */
11
- export class ExtractionAnalyzer {
12
- parser;
13
- constructor() {
14
- this.parser = new TypeScriptParser();
15
- }
16
- /**
17
- * 分析程式碼片段的可提取性
18
- */
19
- async analyze(code, selection) {
20
- const issues = [];
21
- const variables = [];
22
- const dependencies = [];
23
- // 基本驗證
24
- if (!code || code.trim().length === 0) {
25
- issues.push('選取的程式碼為空');
26
- return { canExtract: false, issues, variables, dependencies };
27
- }
28
- // 解析 AST
29
- const ast = await this.parseCode(code);
30
- if (!ast) {
31
- issues.push('程式碼解析失敗');
32
- return { canExtract: false, issues, variables, dependencies };
33
- }
34
- // 分析變數使用
35
- const variableAnalysis = this.analyzeVariables(ast);
36
- variables.push(...variableAnalysis.variables);
37
- // 檢查提取限制
38
- this.checkExtractionConstraints(ast, selection, issues);
39
- // 分析依賴
40
- dependencies.push(...this.findDependencies(ast));
41
- // 推導返回值型別
42
- const returnType = this.extractReturnType(ast);
43
- return {
44
- canExtract: issues.length === 0,
45
- issues,
46
- variables,
47
- dependencies,
48
- returnType
49
- };
50
- }
51
- /**
52
- * 檢查提取限制
53
- */
54
- checkExtractionConstraints(ast, selection, issues) {
55
- // 檢查是否包含 return 語句
56
- const hasReturn = this.containsReturn(ast);
57
- // 檢查是否包含 break/continue
58
- if (this.containsJumpStatement(ast)) {
59
- issues.push('選取範圍包含 break 或 continue 語句');
60
- }
61
- // 檢查是否跨越語句邊界
62
- if (!this.isCompleteStatements(ast)) {
63
- issues.push('選取範圍不是完整的語句');
64
- }
65
- // 檢查巢狀函式定義
66
- if (this.containsFunctionDefinition(ast)) {
67
- issues.push('選取範圍包含函式定義');
68
- }
69
- // 檢查外部變數修改
70
- if (ast.code) {
71
- // 先找出所有宣告的變數
72
- const declaredVars = new Set();
73
- const declarationPattern = /(?:const|let|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)/g;
74
- let declMatch;
75
- while ((declMatch = declarationPattern.exec(ast.code)) !== null) {
76
- declaredVars.add(declMatch[1]);
77
- }
78
- // 然後找出所有賦值(簡化邏輯:只檢測真正的外部變數修改)
79
- // 使用更精確的模式:變數名後面直接跟 = (中間只能有空白)
80
- const simpleAssignmentPattern = /([a-zA-Z_$][a-zA-Z0-9_$]*)\s*=(?!=)/g;
81
- const uniqueAssignments = new Set();
82
- let assignMatch;
83
- while ((assignMatch = simpleAssignmentPattern.exec(ast.code)) !== null) {
84
- const varName = assignMatch[1];
85
- const position = assignMatch.index || 0;
86
- const fullMatch = assignMatch[0]; // 例如 "varName ="
87
- // 檢查完整匹配中是否包含型別註解
88
- // 如果變數名前面有 ':' 字元,很可能是型別註解
89
- const beforeVar = ast.code.substring(Math.max(0, position - 5), position);
90
- if (beforeVar.includes(':') || beforeVar.includes('.')) {
91
- continue;
92
- }
93
- // 檢查是否為變數宣告
94
- const beforeDecl = ast.code.substring(Math.max(0, position - 10), position);
95
- if (/(?:const|let|var|type|interface)\s+$/.test(beforeDecl)) {
96
- continue;
97
- }
98
- // 檢查是否為外部變數(沒有在程式碼中宣告)
99
- if (!declaredVars.has(varName) &&
100
- !['return', 'function', 'if', 'else', 'for', 'while', 'case'].includes(varName)) {
101
- uniqueAssignments.add(varName);
102
- }
103
- }
104
- // FIXME: 外部變數檢測使用正則表達式太不可靠,暫時禁用
105
- // TODO: 未來使用真正的 TypeScript AST parser 改進
106
- // 如果有多個不同的外部變數修改,發出警告但不阻止提取
107
- const uniqueCount = uniqueAssignments.size;
108
- if (uniqueCount > 1) {
109
- // 暫時只警告,不阻止
110
- // const vars = Array.from(uniqueAssignments).join(', ');
111
- // issues.push(`警告:可能有多個返回值 (檢測到: ${vars})`);
112
- }
113
- }
114
- }
115
- /**
116
- * 分析變數使用情況
117
- */
118
- analyzeVariables(ast) {
119
- const variables = [];
120
- const definedVars = new Set();
121
- const usedVars = new Set();
122
- // 簡化實作:使用正規表達式解析變數
123
- if (ast.code) {
124
- // 找出程式碼中的變數使用
125
- const variableMatches = ast.code.match(/\b[a-zA-Z_$][a-zA-Z0-9_$]*\b/g) || [];
126
- // 過濾出真正的變數(排除關鍵字)
127
- const keywords = new Set(['if', 'else', 'for', 'while', 'do', 'break', 'continue',
128
- 'function', 'return', 'var', 'let', 'const', 'true', 'false', 'null',
129
- 'undefined', 'new', 'this', 'typeof', 'instanceof', 'console', 'log',
130
- 'map', 'filter', 'reduce', 'forEach', 'length', 'push', 'pop', 'item', 'i']);
131
- for (const match of variableMatches) {
132
- if (!keywords.has(match) && !definedVars.has(match)) {
133
- usedVars.add(match);
134
- }
135
- }
136
- // 檢查本地定義的變數
137
- const localDeclarations = ast.code.match(/(?:let|const|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)/g) || [];
138
- for (const decl of localDeclarations) {
139
- const varName = decl.replace(/(?:let|const|var)\s+/, '');
140
- definedVars.add(varName);
141
- usedVars.delete(varName); // 移除本地定義的變數
142
- }
143
- // 檢查函式參數
144
- const functionParams = ast.code.match(/function\s*\w*\s*\(([^)]*)\)/);
145
- if (functionParams && functionParams[1]) {
146
- const params = functionParams[1].split(',').map(p => p.trim().replace(/:\s*\w+/, ''));
147
- for (const param of params) {
148
- if (param) {
149
- definedVars.add(param);
150
- usedVars.delete(param);
151
- }
152
- }
153
- }
154
- }
155
- // 建立變數資訊
156
- for (const varName of usedVars) {
157
- variables.push({
158
- name: varName,
159
- type: 'any', // 簡化實作
160
- isParameter: true,
161
- isReturned: false,
162
- scope: 'closure',
163
- usages: []
164
- });
165
- }
166
- return { variables };
167
- }
168
- /**
169
- * 使用 TypeScript Parser 解析程式碼
170
- */
171
- async parseCode(code) {
172
- try {
173
- // 使用 TypeScript Parser 解析程式碼片段
174
- // 為了解析片段,我們將它包裝在一個函式中以形成完整的語句
175
- const wrappedCode = `function __extractedCode__() {\n${code}\n}`;
176
- const virtualPath = 'virtual-extract.ts';
177
- const tsAST = await this.parser.parse(wrappedCode, virtualPath);
178
- const sourceFile = tsAST.tsSourceFile;
179
- if (!sourceFile) {
180
- return null;
181
- }
182
- // 找到我們包裝的函式內部的語句
183
- let extractedStatements = null;
184
- ts.forEachChild(sourceFile, (node) => {
185
- if (ts.isFunctionDeclaration(node) && node.name?.text === '__extractedCode__') {
186
- if (node.body) {
187
- extractedStatements = node.body;
188
- }
189
- }
190
- });
191
- if (!extractedStatements) {
192
- return null;
193
- }
194
- // 建立我們的 ASTNode 結構(相容舊版介面)
195
- return {
196
- type: 'Program',
197
- start: 0,
198
- end: code.length,
199
- loc: {
200
- start: { line: 1, column: 0 },
201
- end: { line: code.split('\n').length, column: 0 }
202
- },
203
- children: [],
204
- code,
205
- tsNode: extractedStatements, // 保存 TypeScript AST 節點
206
- tsSourceFile: sourceFile // 保存 SourceFile 供型別檢查使用
207
- };
208
- }
209
- catch (error) {
210
- console.debug('Parse error:', error);
211
- return null;
212
- }
213
- }
214
- /**
215
- * 遍歷 AST
216
- */
217
- traverse(node, visitor) {
218
- visitor(node);
219
- if (node.children) {
220
- for (const child of node.children) {
221
- this.traverse(child, visitor);
222
- }
223
- }
224
- }
225
- /**
226
- * 檢查是否包含 return 語句(使用真實 TypeScript AST)
227
- */
228
- containsReturn(ast) {
229
- if (!ast.tsNode) {
230
- // 降級到舊邏輯
231
- let hasReturn = false;
232
- this.traverse(ast, (node) => {
233
- if (node.type === 'ReturnStatement') {
234
- hasReturn = true;
235
- }
236
- });
237
- return hasReturn;
238
- }
239
- let hasReturn = false;
240
- const visit = (node) => {
241
- if (ts.isReturnStatement(node)) {
242
- hasReturn = true;
243
- return; // 找到就可以停止
244
- }
245
- ts.forEachChild(node, visit);
246
- };
247
- visit(ast.tsNode);
248
- return hasReturn;
249
- }
250
- /**
251
- * 推導返回值型別
252
- */
253
- extractReturnType(ast) {
254
- if (!ast.tsNode || !ast.tsSourceFile) {
255
- // 降級:簡單檢查是否有 return
256
- return this.containsReturn(ast) ? 'any' : 'void';
257
- }
258
- // 收集所有 return 語句的型別
259
- const returnTypes = [];
260
- let hasReturnWithoutValue = false;
261
- const visit = (node) => {
262
- if (ts.isReturnStatement(node)) {
263
- if (node.expression) {
264
- // 嘗試推導 return 表達式的型別
265
- const type = this.inferTypeFromExpression(node.expression, ast.tsSourceFile);
266
- returnTypes.push(type);
267
- }
268
- else {
269
- hasReturnWithoutValue = true;
270
- }
271
- }
272
- ts.forEachChild(node, visit);
273
- };
274
- visit(ast.tsNode);
275
- // 決定最終返回型別
276
- if (returnTypes.length === 0 && !hasReturnWithoutValue) {
277
- return 'void';
278
- }
279
- if (hasReturnWithoutValue && returnTypes.length === 0) {
280
- return 'void';
281
- }
282
- if (returnTypes.length === 0) {
283
- return 'void';
284
- }
285
- // 如果所有返回型別都相同,使用該型別
286
- const uniqueTypes = [...new Set(returnTypes)];
287
- if (uniqueTypes.length === 1) {
288
- return uniqueTypes[0];
289
- }
290
- // 如果有多種型別,使用 union type
291
- return uniqueTypes.join(' | ');
292
- }
293
- /**
294
- * 從表達式推導型別
295
- */
296
- inferTypeFromExpression(expr, sourceFile) {
297
- // 字串字面量
298
- if (ts.isStringLiteral(expr) || ts.isNoSubstitutionTemplateLiteral(expr)) {
299
- return 'string';
300
- }
301
- // 數字字面量
302
- if (ts.isNumericLiteral(expr)) {
303
- return 'number';
304
- }
305
- // 布林字面量
306
- if (expr.kind === ts.SyntaxKind.TrueKeyword || expr.kind === ts.SyntaxKind.FalseKeyword) {
307
- return 'boolean';
308
- }
309
- // null
310
- if (expr.kind === ts.SyntaxKind.NullKeyword) {
311
- return 'null';
312
- }
313
- // undefined
314
- if (expr.kind === ts.SyntaxKind.UndefinedKeyword) {
315
- return 'undefined';
316
- }
317
- // 識別符號(變數)- 嘗試從上下文推導
318
- if (ts.isIdentifier(expr)) {
319
- // 檢查是否是參數或已知變數
320
- const varName = expr.text;
321
- // 嘗試在包裝函式的參數中查找型別
322
- // 這裡簡化處理,實際專案中應該從完整檔案的上下文取得
323
- const text = sourceFile.text;
324
- const paramPattern = new RegExp(`\\b${varName}\\s*:\\s*([a-zA-Z][a-zA-Z0-9]*)`);
325
- const match = text.match(paramPattern);
326
- if (match) {
327
- return match[1];
328
- }
329
- return 'any';
330
- }
331
- // 陣列字面量
332
- if (ts.isArrayLiteralExpression(expr)) {
333
- if (expr.elements.length === 0) {
334
- return 'any[]';
335
- }
336
- const elementType = this.inferTypeFromExpression(expr.elements[0], sourceFile);
337
- return `${elementType}[]`;
338
- }
339
- // 物件字面量
340
- if (ts.isObjectLiteralExpression(expr)) {
341
- return 'object';
342
- }
343
- // 函式呼叫
344
- if (ts.isCallExpression(expr)) {
345
- // 簡化:返回 any
346
- return 'any';
347
- }
348
- // 預設返回 any
349
- return 'any';
350
- }
351
- /**
352
- * 檢查是否包含跳躍語句
353
- */
354
- containsJumpStatement(ast) {
355
- let hasJump = false;
356
- this.traverse(ast, (node) => {
357
- if (node.type === 'BreakStatement' || node.type === 'ContinueStatement') {
358
- hasJump = true;
359
- }
360
- });
361
- return hasJump;
362
- }
363
- /**
364
- * 檢查是否為完整語句
365
- */
366
- isCompleteStatements(ast) {
367
- // 簡化實作:假設總是完整的
368
- return true;
369
- }
370
- /**
371
- * 檢查是否包含函式定義
372
- */
373
- containsFunctionDefinition(ast) {
374
- let hasFunction = false;
375
- this.traverse(ast, (node) => {
376
- if (node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression') {
377
- hasFunction = true;
378
- }
379
- });
380
- return hasFunction;
381
- }
382
- /**
383
- * 找出依賴項
384
- */
385
- findDependencies(ast) {
386
- const dependencies = [];
387
- // 簡化實作
388
- return dependencies;
389
- }
390
- }
391
- /**
392
- * 函式提取器主類
393
- */
394
- export class FunctionExtractor {
395
- analyzer = new ExtractionAnalyzer();
396
- /**
397
- * 提取函式 (別名,保持向後相容)
398
- * 支援兩種呼叫方式:
399
- * 1. extractFunction(code, selection, config)
400
- * 2. extractFunction(code, start, end, name) - 舊格式
401
- */
402
- async extractFunction(code, selectionOrStart, configOrEnd, nameOrUndefined) {
403
- // 檢查是否為舊格式呼叫 (4 個參數)
404
- if (typeof selectionOrStart === 'number' && typeof configOrEnd === 'number') {
405
- // 將行號轉換為 Range 格式
406
- const startLine = selectionOrStart;
407
- const endLine = configOrEnd;
408
- const selection = {
409
- start: { line: startLine, column: 0 },
410
- end: { line: endLine, column: 0 }
411
- };
412
- const config = {
413
- functionName: nameOrUndefined,
414
- generateComments: true,
415
- preserveFormatting: true,
416
- validateExtraction: true
417
- };
418
- return this.extract(code, selection, config);
419
- }
420
- // 新格式呼叫
421
- return this.extract(code, selectionOrStart, configOrEnd);
422
- }
423
- /**
424
- * 提取函式
425
- */
426
- async extract(code, selection, config = {
427
- generateComments: true,
428
- preserveFormatting: true,
429
- validateExtraction: true,
430
- insertionPoint: 'before'
431
- }) {
432
- // 輸入驗證
433
- if (typeof code !== 'string') {
434
- throw new Error('程式碼必須是字串');
435
- }
436
- if (!selection || !this.isValidRange(selection)) {
437
- throw new Error('選取範圍無效');
438
- }
439
- // 分析可提取性(現在是 async)
440
- const analysis = await this.analyzer.analyze(code, selection);
441
- if (!analysis.canExtract) {
442
- return {
443
- success: false,
444
- functionName: '',
445
- edits: [],
446
- parameters: [],
447
- errors: analysis.issues,
448
- warnings: []
449
- };
450
- }
451
- // 提取選取的程式碼
452
- const selectedCode = this.extractSelectedCode(code, selection);
453
- // 產生函式名稱
454
- const functionName = config.functionName || this.generateFunctionName(selectedCode);
455
- // 產生函式程式碼(使用推導出的返回型別)
456
- const functionCode = this.generateFunction(functionName, selectedCode, analysis.variables, config, analysis.returnType);
457
- // 檢查是否為跨檔案提取
458
- if (config.targetFile && config.sourceFile) {
459
- // 跨檔案提取模式
460
- return await this.extractToSeparateFile(code, selection, functionName, functionCode, analysis.variables, config);
461
- }
462
- // 一般提取模式(同檔案)
463
- const edits = this.generateEdits(code, selection, functionName, functionCode, analysis.variables);
464
- return {
465
- success: true,
466
- functionName,
467
- edits,
468
- parameters: analysis.variables,
469
- returnType: analysis.returnType,
470
- errors: [],
471
- warnings: []
472
- };
473
- }
474
- /**
475
- * 驗證範圍格式
476
- */
477
- isValidRange(range) {
478
- return range.start && range.end &&
479
- typeof range.start.line === 'number' &&
480
- typeof range.start.column === 'number' &&
481
- typeof range.end.line === 'number' &&
482
- typeof range.end.column === 'number' &&
483
- (range.start.line < range.end.line ||
484
- (range.start.line === range.end.line && range.start.column < range.end.column));
485
- }
486
- /**
487
- * 提取選取的程式碼
488
- */
489
- extractSelectedCode(code, selection) {
490
- const lines = code.split('\n');
491
- const selectedLines = [];
492
- for (let i = selection.start.line - 1; i < selection.end.line; i++) {
493
- if (i < 0 || i >= lines.length) {
494
- continue;
495
- }
496
- let line = lines[i];
497
- // 處理開始行
498
- if (i === selection.start.line - 1) {
499
- line = line.substring(selection.start.column);
500
- }
501
- // 處理結束行
502
- if (i === selection.end.line - 1) {
503
- line = line.substring(0, selection.end.column - (i === selection.start.line - 1 ? selection.start.column : 0));
504
- }
505
- selectedLines.push(line);
506
- }
507
- return selectedLines.join('\n');
508
- }
509
- /**
510
- * 產生函式名稱
511
- */
512
- generateFunctionName(code) {
513
- // 簡單的函式名稱生成邏輯
514
- const words = code.match(/\b[a-zA-Z_][a-zA-Z0-9_]*\b/g) || [];
515
- const uniqueWords = [...new Set(words)].filter(word => !['const', 'let', 'var', 'if', 'else', 'for', 'while', 'function', 'return'].includes(word));
516
- if (uniqueWords.length > 0) {
517
- return `extracted${uniqueWords[0].charAt(0).toUpperCase()}${uniqueWords[0].slice(1)}`;
518
- }
519
- return 'extractedFunction';
520
- }
521
- /**
522
- * 產生函式程式碼
523
- */
524
- generateFunction(functionName, code, parameters, config, inferredReturnType) {
525
- // 生成帶型別的參數列表
526
- const params = parameters
527
- .filter(p => p.isParameter)
528
- .map(p => `${p.name}: ${p.type}`)
529
- .join(', ');
530
- const returnVars = parameters.filter(p => p.isReturned);
531
- const returnStatement = returnVars.length > 0
532
- ? `\n return ${returnVars.map(v => v.name).join(', ')};`
533
- : '';
534
- // 使用推導出的返回型別,如果沒有則降級到舊邏輯
535
- let returnType;
536
- if (inferredReturnType) {
537
- returnType = `: ${inferredReturnType}`;
538
- }
539
- else {
540
- const hasReturn = code.includes('return') || returnVars.length > 0;
541
- returnType = hasReturn ? ': any' : ': void';
542
- }
543
- const comment = config.generateComments
544
- ? `/**\n * 提取的函式\n * @param ${params.split(', ').map(p => `${p.split(':')[0]} 參數`).join('\n * @param ')}\n */\n`
545
- : '';
546
- // 縮排程式碼
547
- const indentedCode = code.split('\n').map(line => ` ${line}`).join('\n');
548
- return `${comment}function ${functionName}(${params})${returnType} {${indentedCode}${returnStatement}\n}`;
549
- }
550
- /**
551
- * 產生編輯操作
552
- */
553
- generateEdits(originalCode, selection, functionName, functionCode, parameters) {
554
- const edits = [];
555
- // 1. 替換選取的程式碼為函式呼叫
556
- const callParams = parameters
557
- .filter(p => p.isParameter)
558
- .map(p => p.name)
559
- .join(', ');
560
- const returnVars = parameters.filter(p => p.isReturned);
561
- const assignment = returnVars.length > 0
562
- ? `${returnVars.map(v => v.name).join(', ')} = `
563
- : '';
564
- const functionCall = `${assignment}${functionName}(${callParams});`;
565
- edits.push({
566
- range: selection,
567
- newText: functionCall,
568
- type: 'replace'
569
- });
570
- // 2. 插入函式定義
571
- // 簡化實作:在檔案開頭插入
572
- edits.push({
573
- range: { start: { line: 1, column: 0 }, end: { line: 1, column: 0 } },
574
- newText: functionCode + '\n\n',
575
- type: 'insert'
576
- });
577
- return edits;
578
- }
579
- /**
580
- * 跨檔案提取:將函式提取到獨立檔案
581
- */
582
- async extractToSeparateFile(code, selection, functionName, functionCode, parameters, config) {
583
- const fs = await import('fs/promises');
584
- const path = await import('path');
585
- try {
586
- // 計算相對 import 路徑
587
- const sourceDir = path.dirname(config.sourceFile);
588
- const targetDir = path.dirname(config.targetFile);
589
- const targetFileName = path.basename(config.targetFile, path.extname(config.targetFile));
590
- // 計算相對路徑
591
- let relativePath = path.relative(sourceDir, config.targetFile);
592
- // 移除副檔名
593
- if (relativePath.endsWith('.ts')) {
594
- relativePath = relativePath.slice(0, -3);
595
- }
596
- else if (relativePath.endsWith('.js')) {
597
- relativePath = relativePath.slice(0, -3);
598
- }
599
- // 確保路徑以 ./ 或 ../ 開頭
600
- if (!relativePath.startsWith('.')) {
601
- relativePath = './' + relativePath;
602
- }
603
- // 生成 import 語句
604
- const importStatement = `import { ${functionName} } from '${relativePath}';`;
605
- // 生成 export function(移除註解中的 @param 部分,因為跨檔案不需要)
606
- const exportedFunctionCode = functionCode
607
- .replace(/\/\*\*[\s\S]*?\*\/\n?/, '') // 移除註解
608
- .replace(/^function /, 'export function '); // 加上 export
609
- // 讀取或建立目標檔案內容
610
- let targetFileContent = '';
611
- try {
612
- targetFileContent = await fs.readFile(config.targetFile, 'utf-8');
613
- }
614
- catch (error) {
615
- // 檔案不存在,建立新檔案
616
- targetFileContent = '';
617
- }
618
- // 在目標檔案末尾加入函式
619
- if (targetFileContent.trim().length > 0) {
620
- targetFileContent += '\n\n' + exportedFunctionCode + '\n';
621
- }
622
- else {
623
- targetFileContent = exportedFunctionCode + '\n';
624
- }
625
- // 生成原始檔案的編輯:加入 import + 替換為函式呼叫
626
- const edits = [];
627
- // 1. 替換選取範圍為函式呼叫
628
- const callParams = parameters
629
- .filter(p => p.isParameter)
630
- .map(p => p.name)
631
- .join(', ');
632
- const returnVars = parameters.filter(p => p.isReturned);
633
- const assignment = returnVars.length > 0
634
- ? `${returnVars.map(v => v.name).join(', ')} = `
635
- : '';
636
- const functionCall = `${assignment}${functionName}(${callParams});`;
637
- edits.push({
638
- range: selection,
639
- newText: functionCall,
640
- type: 'replace'
641
- });
642
- // 2. 在檔案開頭加入 import 語句
643
- edits.push({
644
- range: { start: { line: 1, column: 0 }, end: { line: 1, column: 0 } },
645
- newText: importStatement + '\n',
646
- type: 'insert'
647
- });
648
- return {
649
- success: true,
650
- functionName,
651
- edits,
652
- parameters,
653
- errors: [],
654
- warnings: [],
655
- targetFileContent,
656
- importStatement
657
- };
658
- }
659
- catch (error) {
660
- return {
661
- success: false,
662
- functionName,
663
- edits: [],
664
- parameters: [],
665
- errors: [`跨檔案提取失敗: ${error instanceof Error ? error.message : String(error)}`],
666
- warnings: []
667
- };
668
- }
669
- }
670
- /**
671
- * 批次提取
672
- */
673
- async extractMultiple(extractions) {
674
- const results = await Promise.all(extractions.map(({ code, selection, config }) => this.extract(code, selection, config)));
675
- return results;
676
- }
677
- /**
678
- * 預覽提取結果
679
- */
680
- async preview(code, selection, config) {
681
- const result = await this.extract(code, selection, config);
682
- if (!result.success) {
683
- throw new Error(`提取預覽失敗: ${result.errors.join(', ')}`);
684
- }
685
- // 應用編輯操作
686
- let modifiedCode = code;
687
- for (const edit of result.edits.reverse()) { // 反向應用避免位置偏移
688
- modifiedCode = this.applyEdit(modifiedCode, edit);
689
- }
690
- return {
691
- originalCode: code,
692
- modifiedCode,
693
- functionCode: result.edits.find(edit => edit.type === 'insert')?.newText || ''
694
- };
695
- }
696
- /**
697
- * 應用編輯操作
698
- */
699
- applyEdit(code, edit) {
700
- const lines = code.split('\n');
701
- switch (edit.type) {
702
- case 'replace':
703
- // 簡化實作
704
- return code.substring(0, this.rangeToOffset(code, edit.range.start)) +
705
- edit.newText +
706
- code.substring(this.rangeToOffset(code, edit.range.end));
707
- case 'insert':
708
- const offset = this.rangeToOffset(code, edit.range.start);
709
- return code.substring(0, offset) + edit.newText + code.substring(offset);
710
- case 'delete':
711
- return code.substring(0, this.rangeToOffset(code, edit.range.start)) +
712
- code.substring(this.rangeToOffset(code, edit.range.end));
713
- default:
714
- return code;
715
- }
716
- }
717
- /**
718
- * 將範圍轉換為偏移量
719
- */
720
- rangeToOffset(code, position) {
721
- const lines = code.split('\n');
722
- let offset = 0;
723
- for (let i = 0; i < position.line - 1 && i < lines.length; i++) {
724
- offset += lines[i].length + 1; // +1 for newline
725
- }
726
- offset += position.column;
727
- return Math.min(offset, code.length);
728
- }
729
- }
730
- //# sourceMappingURL=extract-function.js.map