agent-ide 0.1.10 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -278
- package/dist/application/events/event-bus.d.ts.map +1 -1
- package/dist/application/events/event-bus.js.map +1 -1
- package/dist/application/index.d.ts +3 -1
- package/dist/application/index.d.ts.map +1 -1
- package/dist/application/index.js +10 -5
- package/dist/application/index.js.map +1 -1
- package/dist/application/services/cache-coordinator.service.d.ts.map +1 -1
- package/dist/application/services/cache-coordinator.service.js.map +1 -1
- package/dist/application/services/error-handler.service.d.ts.map +1 -1
- package/dist/application/services/error-handler.service.js.map +1 -1
- package/dist/application/services/module-coordinator.service.d.ts +13 -3
- package/dist/application/services/module-coordinator.service.d.ts.map +1 -1
- package/dist/application/services/module-coordinator.service.js +65 -25
- package/dist/application/services/module-coordinator.service.js.map +1 -1
- package/dist/application/services/session-manager.service.d.ts.map +1 -1
- package/dist/application/services/session-manager.service.js.map +1 -1
- package/dist/application/services/workflow-engine.service.d.ts +1 -1
- package/dist/application/services/workflow-engine.service.d.ts.map +1 -1
- package/dist/application/services/workflow-engine.service.js.map +1 -1
- package/dist/application/state/state-manager.d.ts +3 -3
- package/dist/application/state/state-manager.d.ts.map +1 -1
- package/dist/application/state/state-manager.js +3 -3
- package/dist/application/state/state-manager.js.map +1 -1
- package/dist/application/types.d.ts.map +1 -1
- package/dist/application/workflows/analysis-workflow.d.ts +1 -1
- package/dist/application/workflows/analysis-workflow.d.ts.map +1 -1
- package/dist/application/workflows/analysis-workflow.js +1 -1
- package/dist/application/workflows/analysis-workflow.js.map +1 -1
- package/dist/application/workflows/base-workflow.d.ts.map +1 -1
- package/dist/application/workflows/base-workflow.js.map +1 -1
- package/dist/application/workflows/index.d.ts +2 -2
- package/dist/application/workflows/index.d.ts.map +1 -1
- package/dist/application/workflows/index.js +2 -2
- package/dist/application/workflows/index.js.map +1 -1
- package/dist/application/workflows/refactor-workflow.d.ts +1 -1
- package/dist/application/workflows/refactor-workflow.d.ts.map +1 -1
- package/dist/application/workflows/refactor-workflow.js +1 -1
- package/dist/application/workflows/refactor-workflow.js.map +1 -1
- package/dist/core/dependency/cycle-detector.d.ts +1 -1
- package/dist/core/dependency/cycle-detector.d.ts.map +1 -1
- package/dist/core/dependency/cycle-detector.js +1 -1
- package/dist/core/dependency/cycle-detector.js.map +1 -1
- package/dist/core/dependency/dependency-analyzer.d.ts +3 -1
- package/dist/core/dependency/dependency-analyzer.d.ts.map +1 -1
- package/dist/core/dependency/dependency-analyzer.js +35 -24
- package/dist/core/dependency/dependency-analyzer.js.map +1 -1
- package/dist/core/dependency/types.d.ts.map +1 -1
- package/dist/core/indexing/file-index.d.ts.map +1 -1
- package/dist/core/indexing/file-index.js +1 -1
- package/dist/core/indexing/file-index.js.map +1 -1
- package/dist/core/indexing/file-watcher.d.ts +4 -2
- package/dist/core/indexing/file-watcher.d.ts.map +1 -1
- package/dist/core/indexing/file-watcher.js +10 -6
- package/dist/core/indexing/file-watcher.js.map +1 -1
- package/dist/core/indexing/index-engine.d.ts +7 -1
- package/dist/core/indexing/index-engine.d.ts.map +1 -1
- package/dist/core/indexing/index-engine.js +49 -16
- package/dist/core/indexing/index-engine.js.map +1 -1
- package/dist/core/indexing/symbol-index.d.ts +4 -0
- package/dist/core/indexing/symbol-index.d.ts.map +1 -1
- package/dist/core/indexing/symbol-index.js +17 -0
- package/dist/core/indexing/symbol-index.js.map +1 -1
- package/dist/core/indexing/types.d.ts.map +1 -1
- package/dist/core/search/engines/text-engine.d.ts +3 -0
- package/dist/core/search/engines/text-engine.d.ts.map +1 -1
- package/dist/core/search/engines/text-engine.js +8 -7
- package/dist/core/search/engines/text-engine.js.map +1 -1
- package/dist/core/search/service.d.ts +2 -1
- package/dist/core/search/service.d.ts.map +1 -1
- package/dist/core/search/service.js +3 -3
- package/dist/core/search/service.js.map +1 -1
- package/dist/core/search/types.d.ts.map +1 -1
- package/dist/core/snapshot/index.d.ts +7 -0
- package/dist/core/snapshot/index.d.ts.map +1 -0
- package/dist/core/snapshot/index.js +6 -0
- package/dist/core/snapshot/index.js.map +1 -0
- package/dist/core/snapshot/snapshot-generator.d.ts +66 -0
- package/dist/core/snapshot/snapshot-generator.d.ts.map +1 -0
- package/dist/core/snapshot/snapshot-generator.js +258 -0
- package/dist/core/snapshot/snapshot-generator.js.map +1 -0
- package/dist/core/snapshot/types.d.ts +67 -0
- package/dist/core/snapshot/types.d.ts.map +1 -0
- package/dist/core/snapshot/types.js +25 -0
- package/dist/core/snapshot/types.js.map +1 -0
- package/dist/core/transform/index.d.ts +10 -0
- package/dist/core/transform/index.d.ts.map +1 -0
- package/dist/core/transform/index.js +21 -0
- package/dist/core/transform/index.js.map +1 -0
- package/dist/core/transform/location/index.d.ts +8 -0
- package/dist/core/transform/location/index.d.ts.map +1 -0
- package/dist/core/transform/location/index.js +9 -0
- package/dist/core/transform/location/index.js.map +1 -0
- package/dist/core/{move → transform/location/move-file}/import-resolver.d.ts +1 -1
- package/dist/core/transform/location/move-file/import-resolver.d.ts.map +1 -0
- package/dist/core/{move → transform/location/move-file}/import-resolver.js +19 -12
- package/dist/core/transform/location/move-file/import-resolver.js.map +1 -0
- package/dist/core/{move → transform/location/move-file}/index.d.ts +2 -2
- package/dist/core/transform/location/move-file/index.d.ts.map +1 -0
- package/dist/core/{move → transform/location/move-file}/index.js +2 -2
- package/dist/core/transform/location/move-file/index.js.map +1 -0
- package/dist/core/{move → transform/location/move-file}/move-service.d.ts +5 -3
- package/dist/core/transform/location/move-file/move-service.d.ts.map +1 -0
- package/dist/core/{move → transform/location/move-file}/move-service.js +74 -92
- package/dist/core/transform/location/move-file/move-service.js.map +1 -0
- package/dist/core/{move → transform/location/move-file}/types.d.ts +1 -1
- package/dist/core/transform/location/move-file/types.d.ts.map +1 -0
- package/dist/core/transform/location/move-file/types.js.map +1 -0
- package/dist/core/transform/location/move-member/index.d.ts +10 -0
- package/dist/core/transform/location/move-member/index.d.ts.map +1 -0
- package/dist/core/transform/location/move-member/index.js +12 -0
- package/dist/core/transform/location/move-member/index.js.map +1 -0
- package/dist/core/transform/location/move-member/member-extractor.d.ts +96 -0
- package/dist/core/transform/location/move-member/member-extractor.d.ts.map +1 -0
- package/dist/core/transform/location/move-member/member-extractor.js +439 -0
- package/dist/core/transform/location/move-member/member-extractor.js.map +1 -0
- package/dist/core/transform/location/move-member/move-member-service.d.ts +87 -0
- package/dist/core/transform/location/move-member/move-member-service.d.ts.map +1 -0
- package/dist/core/transform/location/move-member/move-member-service.js +412 -0
- package/dist/core/transform/location/move-member/move-member-service.js.map +1 -0
- package/dist/core/transform/location/move-member/types.d.ts +182 -0
- package/dist/core/transform/location/move-member/types.d.ts.map +1 -0
- package/dist/core/transform/location/move-member/types.js +75 -0
- package/dist/core/transform/location/move-member/types.js.map +1 -0
- package/dist/core/transform/location/shift/file-generator.d.ts +45 -0
- package/dist/core/transform/location/shift/file-generator.d.ts.map +1 -0
- package/dist/core/transform/location/shift/file-generator.js +94 -0
- package/dist/core/transform/location/shift/file-generator.js.map +1 -0
- package/dist/core/transform/location/shift/index.d.ts +11 -0
- package/dist/core/transform/location/shift/index.d.ts.map +1 -0
- package/dist/core/transform/location/shift/index.js +13 -0
- package/dist/core/transform/location/shift/index.js.map +1 -0
- package/dist/core/transform/location/shift/line-extractor.d.ts +55 -0
- package/dist/core/transform/location/shift/line-extractor.d.ts.map +1 -0
- package/dist/core/transform/location/shift/line-extractor.js +123 -0
- package/dist/core/transform/location/shift/line-extractor.js.map +1 -0
- package/dist/core/transform/location/shift/shift-service.d.ts +57 -0
- package/dist/core/transform/location/shift/shift-service.d.ts.map +1 -0
- package/dist/core/transform/location/shift/shift-service.js +199 -0
- package/dist/core/transform/location/shift/shift-service.js.map +1 -0
- package/dist/core/transform/location/shift/types.d.ts +195 -0
- package/dist/core/transform/location/shift/types.d.ts.map +1 -0
- package/dist/core/transform/location/shift/types.js +89 -0
- package/dist/core/transform/location/shift/types.js.map +1 -0
- package/dist/core/transform/shared/code-editor.d.ts +70 -0
- package/dist/core/transform/shared/code-editor.d.ts.map +1 -0
- package/dist/core/transform/shared/code-editor.js +206 -0
- package/dist/core/transform/shared/code-editor.js.map +1 -0
- package/dist/core/transform/shared/index.d.ts +7 -0
- package/dist/core/transform/shared/index.d.ts.map +1 -0
- package/dist/core/transform/shared/index.js +7 -0
- package/dist/core/transform/shared/index.js.map +1 -0
- package/dist/core/transform/shared/symbol-finder.d.ts +154 -0
- package/dist/core/transform/shared/symbol-finder.d.ts.map +1 -0
- package/dist/core/transform/shared/symbol-finder.js +433 -0
- package/dist/core/transform/shared/symbol-finder.js.map +1 -0
- package/dist/core/transform/structure/extract/extract-function.d.ts.map +1 -0
- package/dist/core/{refactor → transform/structure/extract}/extract-function.js +1 -1
- package/dist/core/transform/structure/extract/extract-function.js.map +1 -0
- package/dist/core/transform/structure/extract/index.d.ts +7 -0
- package/dist/core/transform/structure/extract/index.d.ts.map +1 -0
- package/dist/core/transform/structure/extract/index.js +9 -0
- package/dist/core/transform/structure/extract/index.js.map +1 -0
- package/dist/core/transform/structure/extract/swift-extractor.d.ts +98 -0
- package/dist/core/transform/structure/extract/swift-extractor.d.ts.map +1 -0
- package/dist/core/transform/structure/extract/swift-extractor.js +283 -0
- package/dist/core/transform/structure/extract/swift-extractor.js.map +1 -0
- package/dist/core/transform/structure/index.d.ts +8 -0
- package/dist/core/transform/structure/index.d.ts.map +1 -0
- package/dist/core/transform/structure/index.js +8 -0
- package/dist/core/transform/structure/index.js.map +1 -0
- package/dist/core/transform/structure/inline/index.d.ts +6 -0
- package/dist/core/transform/structure/inline/index.d.ts.map +1 -0
- package/dist/core/transform/structure/inline/index.js +6 -0
- package/dist/core/transform/structure/inline/index.js.map +1 -0
- package/dist/core/transform/structure/inline/inline-function.d.ts.map +1 -0
- package/dist/core/{refactor → transform/structure/inline}/inline-function.js +37 -26
- package/dist/core/transform/structure/inline/inline-function.js.map +1 -0
- package/dist/core/transform/structure/patterns/design-patterns.d.ts.map +1 -0
- package/dist/core/transform/structure/patterns/design-patterns.js.map +1 -0
- package/dist/core/transform/structure/patterns/index.d.ts +6 -0
- package/dist/core/transform/structure/patterns/index.d.ts.map +1 -0
- package/dist/core/transform/structure/patterns/index.js +6 -0
- package/dist/core/transform/structure/patterns/index.js.map +1 -0
- package/dist/core/transform/symbol/change-signature/change-signature-service.d.ts +94 -0
- package/dist/core/transform/symbol/change-signature/change-signature-service.d.ts.map +1 -0
- package/dist/core/transform/symbol/change-signature/change-signature-service.js +544 -0
- package/dist/core/transform/symbol/change-signature/change-signature-service.js.map +1 -0
- package/dist/core/transform/symbol/change-signature/index.d.ts +10 -0
- package/dist/core/transform/symbol/change-signature/index.d.ts.map +1 -0
- package/dist/core/transform/symbol/change-signature/index.js +12 -0
- package/dist/core/transform/symbol/change-signature/index.js.map +1 -0
- package/dist/core/transform/symbol/change-signature/signature-parser.d.ts +76 -0
- package/dist/core/transform/symbol/change-signature/signature-parser.d.ts.map +1 -0
- package/dist/core/transform/symbol/change-signature/signature-parser.js +387 -0
- package/dist/core/transform/symbol/change-signature/signature-parser.js.map +1 -0
- package/dist/core/transform/symbol/change-signature/types.d.ts +244 -0
- package/dist/core/transform/symbol/change-signature/types.d.ts.map +1 -0
- package/dist/core/transform/symbol/change-signature/types.js +73 -0
- package/dist/core/transform/symbol/change-signature/types.js.map +1 -0
- package/dist/core/transform/symbol/index.d.ts +7 -0
- package/dist/core/transform/symbol/index.d.ts.map +1 -0
- package/dist/core/transform/symbol/index.js +7 -0
- package/dist/core/transform/symbol/index.js.map +1 -0
- package/dist/core/transform/symbol/rename/index.d.ts +9 -0
- package/dist/core/transform/symbol/rename/index.d.ts.map +1 -0
- package/dist/core/{rename → transform/symbol/rename}/index.js +5 -3
- package/dist/core/transform/symbol/rename/index.js.map +1 -0
- package/dist/core/{rename → transform/symbol/rename}/reference-updater.d.ts +2 -2
- package/dist/core/transform/symbol/rename/reference-updater.d.ts.map +1 -0
- package/dist/core/{rename → transform/symbol/rename}/reference-updater.js +16 -8
- package/dist/core/transform/symbol/rename/reference-updater.js.map +1 -0
- package/dist/core/{rename → transform/symbol/rename}/rename-engine.d.ts +2 -2
- package/dist/core/transform/symbol/rename/rename-engine.d.ts.map +1 -0
- package/dist/core/{rename → transform/symbol/rename}/rename-engine.js +3 -3
- package/dist/core/transform/symbol/rename/rename-engine.js.map +1 -0
- package/dist/core/{rename → transform/symbol/rename}/scope-analyzer.d.ts +3 -3
- package/dist/core/transform/symbol/rename/scope-analyzer.d.ts.map +1 -0
- package/dist/core/{rename → transform/symbol/rename}/scope-analyzer.js +2 -2
- package/dist/core/transform/symbol/rename/scope-analyzer.js.map +1 -0
- package/dist/core/{rename → transform/symbol/rename}/types.d.ts +2 -2
- package/dist/core/transform/symbol/rename/types.d.ts.map +1 -0
- package/dist/core/transform/symbol/rename/types.js.map +1 -0
- package/dist/core/transform/types.d.ts +185 -0
- package/dist/core/transform/types.d.ts.map +1 -0
- package/dist/core/transform/types.js +150 -0
- package/dist/core/transform/types.js.map +1 -0
- package/dist/infrastructure/cache/cache-manager.d.ts +1 -1
- package/dist/infrastructure/cache/cache-manager.d.ts.map +1 -1
- package/dist/infrastructure/cache/cache-manager.js +1 -1
- package/dist/infrastructure/cache/cache-manager.js.map +1 -1
- package/dist/infrastructure/cache/memory-cache.js +1 -1
- package/dist/infrastructure/cache/memory-cache.js.map +1 -1
- package/dist/infrastructure/cache/strategies.d.ts +1 -1
- package/dist/infrastructure/cache/strategies.d.ts.map +1 -1
- package/dist/infrastructure/cache/strategies.js +1 -1
- package/dist/infrastructure/cache/strategies.js.map +1 -1
- package/dist/infrastructure/formatters/diff-generator.d.ts +11 -0
- package/dist/infrastructure/formatters/diff-generator.d.ts.map +1 -0
- package/dist/infrastructure/formatters/diff-generator.js +217 -0
- package/dist/infrastructure/formatters/diff-generator.js.map +1 -0
- package/dist/infrastructure/formatters/index.d.ts +11 -0
- package/dist/infrastructure/formatters/index.d.ts.map +1 -0
- package/dist/infrastructure/formatters/index.js +13 -0
- package/dist/infrastructure/formatters/index.js.map +1 -0
- package/dist/infrastructure/formatters/preview-converter.d.ts +85 -0
- package/dist/infrastructure/formatters/preview-converter.d.ts.map +1 -0
- package/dist/infrastructure/formatters/preview-converter.js +209 -0
- package/dist/infrastructure/formatters/preview-converter.js.map +1 -0
- package/dist/infrastructure/formatters/preview-formatter.d.ts +61 -0
- package/dist/infrastructure/formatters/preview-formatter.d.ts.map +1 -0
- package/dist/infrastructure/formatters/preview-formatter.js +208 -0
- package/dist/infrastructure/formatters/preview-formatter.js.map +1 -0
- package/dist/infrastructure/formatters/query-formatter.d.ts +63 -0
- package/dist/infrastructure/formatters/query-formatter.d.ts.map +1 -0
- package/dist/infrastructure/formatters/query-formatter.js +218 -0
- package/dist/infrastructure/formatters/query-formatter.js.map +1 -0
- package/dist/infrastructure/formatters/query-types.d.ts +165 -0
- package/dist/infrastructure/formatters/query-types.d.ts.map +1 -0
- package/dist/infrastructure/formatters/query-types.js +30 -0
- package/dist/infrastructure/formatters/query-types.js.map +1 -0
- package/dist/infrastructure/formatters/types.d.ts +153 -0
- package/dist/infrastructure/formatters/types.d.ts.map +1 -0
- package/dist/infrastructure/formatters/types.js +27 -0
- package/dist/infrastructure/formatters/types.js.map +1 -0
- package/dist/infrastructure/parser/analysis-types.d.ts +198 -0
- package/dist/infrastructure/parser/analysis-types.d.ts.map +1 -0
- package/dist/infrastructure/parser/analysis-types.js +6 -0
- package/dist/infrastructure/parser/analysis-types.js.map +1 -0
- package/dist/infrastructure/parser/base.d.ts +37 -1
- package/dist/infrastructure/parser/base.d.ts.map +1 -1
- package/dist/infrastructure/parser/base.js +73 -1
- package/dist/infrastructure/parser/base.js.map +1 -1
- package/dist/infrastructure/parser/factory.d.ts +3 -3
- package/dist/infrastructure/parser/factory.d.ts.map +1 -1
- package/dist/infrastructure/parser/factory.js +1 -1
- package/dist/infrastructure/parser/factory.js.map +1 -1
- package/dist/infrastructure/parser/index.d.ts +1 -0
- package/dist/infrastructure/parser/index.d.ts.map +1 -1
- package/dist/infrastructure/parser/index.js.map +1 -1
- package/dist/infrastructure/parser/interface.d.ts +64 -1
- package/dist/infrastructure/parser/interface.d.ts.map +1 -1
- package/dist/infrastructure/parser/interface.js +11 -1
- package/dist/infrastructure/parser/interface.js.map +1 -1
- package/dist/infrastructure/parser/registry.d.ts +1 -1
- package/dist/infrastructure/parser/registry.d.ts.map +1 -1
- package/dist/infrastructure/parser/registry.js +1 -1
- package/dist/infrastructure/parser/registry.js.map +1 -1
- package/dist/infrastructure/parser/types.d.ts.map +1 -1
- package/dist/infrastructure/storage/file-system.d.ts +2 -1
- package/dist/infrastructure/storage/file-system.d.ts.map +1 -1
- package/dist/infrastructure/storage/file-system.interface.d.ts +69 -0
- package/dist/infrastructure/storage/file-system.interface.d.ts.map +1 -0
- package/dist/infrastructure/storage/file-system.interface.js +6 -0
- package/dist/infrastructure/storage/file-system.interface.js.map +1 -0
- package/dist/infrastructure/storage/file-system.js.map +1 -1
- package/dist/infrastructure/storage/index.d.ts +2 -2
- package/dist/infrastructure/storage/index.d.ts.map +1 -1
- package/dist/infrastructure/storage/index.js +1 -6
- package/dist/infrastructure/storage/index.js.map +1 -1
- package/dist/infrastructure/storage/mem-file-system.d.ts +44 -0
- package/dist/infrastructure/storage/mem-file-system.d.ts.map +1 -0
- package/dist/infrastructure/storage/mem-file-system.js +105 -0
- package/dist/infrastructure/storage/mem-file-system.js.map +1 -0
- package/dist/infrastructure/storage/path-utils.d.ts +1 -1
- package/dist/infrastructure/storage/path-utils.d.ts.map +1 -1
- package/dist/interfaces/cli/cli.d.ts +13 -70
- package/dist/interfaces/cli/cli.d.ts.map +1 -1
- package/dist/interfaces/cli/cli.js +65 -1186
- package/dist/interfaces/cli/cli.js.map +1 -1
- package/dist/interfaces/cli/commands/analyze.command.d.ts +11 -0
- package/dist/interfaces/cli/commands/analyze.command.d.ts.map +1 -0
- package/dist/interfaces/cli/commands/analyze.command.js +460 -0
- package/dist/interfaces/cli/commands/analyze.command.js.map +1 -0
- package/dist/interfaces/cli/commands/change-signature.command.d.ts +11 -0
- package/dist/interfaces/cli/commands/change-signature.command.d.ts.map +1 -0
- package/dist/interfaces/cli/commands/change-signature.command.js +299 -0
- package/dist/interfaces/cli/commands/change-signature.command.js.map +1 -0
- package/dist/interfaces/cli/commands/deps.command.d.ts +11 -0
- package/dist/interfaces/cli/commands/deps.command.d.ts.map +1 -0
- package/dist/interfaces/cli/commands/deps.command.js +143 -0
- package/dist/interfaces/cli/commands/deps.command.js.map +1 -0
- package/dist/interfaces/cli/commands/extract.command.d.ts +11 -0
- package/dist/interfaces/cli/commands/extract.command.d.ts.map +1 -0
- package/dist/interfaces/cli/commands/extract.command.js +314 -0
- package/dist/interfaces/cli/commands/extract.command.js.map +1 -0
- package/dist/interfaces/cli/commands/index.d.ts +16 -0
- package/dist/interfaces/cli/commands/index.d.ts.map +1 -0
- package/dist/interfaces/cli/commands/index.js +15 -0
- package/dist/interfaces/cli/commands/index.js.map +1 -0
- package/dist/interfaces/cli/commands/inline.command.d.ts +11 -0
- package/dist/interfaces/cli/commands/inline.command.d.ts.map +1 -0
- package/dist/interfaces/cli/commands/inline.command.js +208 -0
- package/dist/interfaces/cli/commands/inline.command.js.map +1 -0
- package/dist/interfaces/cli/commands/move-member.command.d.ts +11 -0
- package/dist/interfaces/cli/commands/move-member.command.d.ts.map +1 -0
- package/dist/interfaces/cli/commands/move-member.command.js +194 -0
- package/dist/interfaces/cli/commands/move-member.command.js.map +1 -0
- package/dist/interfaces/cli/commands/move.command.d.ts +11 -0
- package/dist/interfaces/cli/commands/move.command.d.ts.map +1 -0
- package/dist/interfaces/cli/commands/move.command.js +220 -0
- package/dist/interfaces/cli/commands/move.command.js.map +1 -0
- package/dist/interfaces/cli/commands/refactor.command.d.ts +11 -0
- package/dist/interfaces/cli/commands/refactor.command.d.ts.map +1 -0
- package/dist/interfaces/cli/commands/refactor.command.js +414 -0
- package/dist/interfaces/cli/commands/refactor.command.js.map +1 -0
- package/dist/interfaces/cli/commands/rename.command.d.ts +11 -0
- package/dist/interfaces/cli/commands/rename.command.d.ts.map +1 -0
- package/dist/interfaces/cli/commands/rename.command.js +272 -0
- package/dist/interfaces/cli/commands/rename.command.js.map +1 -0
- package/dist/interfaces/cli/commands/search.command.d.ts +11 -0
- package/dist/interfaces/cli/commands/search.command.d.ts.map +1 -0
- package/dist/interfaces/cli/commands/search.command.js +409 -0
- package/dist/interfaces/cli/commands/search.command.js.map +1 -0
- package/dist/interfaces/cli/commands/shift.command.d.ts +11 -0
- package/dist/interfaces/cli/commands/shift.command.d.ts.map +1 -0
- package/dist/interfaces/cli/commands/shift.command.js +143 -0
- package/dist/interfaces/cli/commands/shift.command.js.map +1 -0
- package/dist/interfaces/cli/commands/snapshot.command.d.ts +11 -0
- package/dist/interfaces/cli/commands/snapshot.command.d.ts.map +1 -0
- package/dist/interfaces/cli/commands/snapshot.command.js +68 -0
- package/dist/interfaces/cli/commands/snapshot.command.js.map +1 -0
- package/dist/interfaces/cli/commands/types.d.ts +18 -0
- package/dist/interfaces/cli/commands/types.d.ts.map +1 -0
- package/dist/interfaces/cli/commands/types.js +5 -0
- package/dist/interfaces/cli/commands/types.js.map +1 -0
- package/dist/interfaces/cli/index.d.ts +1 -1
- package/dist/interfaces/cli/index.d.ts.map +1 -1
- package/dist/interfaces/cli/index.js +1 -1
- package/dist/interfaces/cli/index.js.map +1 -1
- package/dist/interfaces/cli/preview-output-handler.d.ts +53 -0
- package/dist/interfaces/cli/preview-output-handler.d.ts.map +1 -0
- package/dist/interfaces/cli/preview-output-handler.js +73 -0
- package/dist/interfaces/cli/preview-output-handler.js.map +1 -0
- package/dist/interfaces/cli/unified-output-handler.d.ts +77 -0
- package/dist/interfaces/cli/unified-output-handler.d.ts.map +1 -0
- package/dist/interfaces/cli/unified-output-handler.js +140 -0
- package/dist/interfaces/cli/unified-output-handler.js.map +1 -0
- package/dist/plugins/javascript/index.d.ts +2 -2
- package/dist/plugins/javascript/index.d.ts.map +1 -1
- package/dist/plugins/javascript/index.js +1 -1
- package/dist/plugins/javascript/index.js.map +1 -1
- package/dist/plugins/javascript/parser.d.ts +41 -0
- package/dist/plugins/javascript/parser.d.ts.map +1 -1
- package/dist/plugins/javascript/parser.js +284 -0
- package/dist/plugins/javascript/parser.js.map +1 -1
- package/dist/plugins/javascript/types.d.ts.map +1 -1
- package/dist/plugins/javascript/types.js.map +1 -1
- package/dist/plugins/python/analyzers/complexity-analyzer.d.ts +50 -0
- package/dist/plugins/python/analyzers/complexity-analyzer.d.ts.map +1 -0
- package/dist/plugins/python/analyzers/complexity-analyzer.js +172 -0
- package/dist/plugins/python/analyzers/complexity-analyzer.js.map +1 -0
- package/dist/plugins/python/analyzers/duplication-detector.d.ts +39 -0
- package/dist/plugins/python/analyzers/duplication-detector.d.ts.map +1 -0
- package/dist/plugins/python/analyzers/duplication-detector.js +146 -0
- package/dist/plugins/python/analyzers/duplication-detector.js.map +1 -0
- package/dist/plugins/python/analyzers/error-handling-checker.d.ts +28 -0
- package/dist/plugins/python/analyzers/error-handling-checker.d.ts.map +1 -0
- package/dist/plugins/python/analyzers/error-handling-checker.js +143 -0
- package/dist/plugins/python/analyzers/error-handling-checker.js.map +1 -0
- package/dist/plugins/python/analyzers/naming-checker.d.ts +56 -0
- package/dist/plugins/python/analyzers/naming-checker.d.ts.map +1 -0
- package/dist/plugins/python/analyzers/naming-checker.js +220 -0
- package/dist/plugins/python/analyzers/naming-checker.js.map +1 -0
- package/dist/plugins/python/analyzers/pattern-detector.d.ts +44 -0
- package/dist/plugins/python/analyzers/pattern-detector.d.ts.map +1 -0
- package/dist/plugins/python/analyzers/pattern-detector.js +222 -0
- package/dist/plugins/python/analyzers/pattern-detector.js.map +1 -0
- package/dist/plugins/python/analyzers/security-checker.d.ts +56 -0
- package/dist/plugins/python/analyzers/security-checker.d.ts.map +1 -0
- package/dist/plugins/python/analyzers/security-checker.js +279 -0
- package/dist/plugins/python/analyzers/security-checker.js.map +1 -0
- package/dist/plugins/python/analyzers/type-safety-checker.d.ts +44 -0
- package/dist/plugins/python/analyzers/type-safety-checker.d.ts.map +1 -0
- package/dist/plugins/python/analyzers/type-safety-checker.js +177 -0
- package/dist/plugins/python/analyzers/type-safety-checker.js.map +1 -0
- package/dist/plugins/python/analyzers/unused-symbol-detector.d.ts +37 -0
- package/dist/plugins/python/analyzers/unused-symbol-detector.d.ts.map +1 -0
- package/dist/plugins/python/analyzers/unused-symbol-detector.js +141 -0
- package/dist/plugins/python/analyzers/unused-symbol-detector.js.map +1 -0
- package/dist/plugins/python/dependency-analyzer.d.ts +86 -0
- package/dist/plugins/python/dependency-analyzer.d.ts.map +1 -0
- package/dist/plugins/python/dependency-analyzer.js +252 -0
- package/dist/plugins/python/dependency-analyzer.js.map +1 -0
- package/dist/plugins/python/index.d.ts +17 -0
- package/dist/plugins/python/index.d.ts.map +1 -0
- package/dist/plugins/python/index.js +23 -0
- package/dist/plugins/python/index.js.map +1 -0
- package/dist/plugins/python/parser.d.ts +150 -0
- package/dist/plugins/python/parser.d.ts.map +1 -0
- package/dist/plugins/python/parser.js +476 -0
- package/dist/plugins/python/parser.js.map +1 -0
- package/dist/plugins/python/symbol-extractor.d.ts +108 -0
- package/dist/plugins/python/symbol-extractor.d.ts.map +1 -0
- package/dist/plugins/python/symbol-extractor.js +389 -0
- package/dist/plugins/python/symbol-extractor.js.map +1 -0
- package/dist/plugins/python/tree-sitter-bridge.d.ts +57 -0
- package/dist/plugins/python/tree-sitter-bridge.d.ts.map +1 -0
- package/dist/plugins/python/tree-sitter-bridge.js +267 -0
- package/dist/plugins/python/tree-sitter-bridge.js.map +1 -0
- package/dist/plugins/python/types.d.ts +179 -0
- package/dist/plugins/python/types.d.ts.map +1 -0
- package/dist/plugins/python/types.js +252 -0
- package/dist/plugins/python/types.js.map +1 -0
- package/dist/plugins/swift/analyzers/complexity-analyzer.d.ts +41 -0
- package/dist/plugins/swift/analyzers/complexity-analyzer.d.ts.map +1 -0
- package/dist/plugins/swift/analyzers/complexity-analyzer.js +206 -0
- package/dist/plugins/swift/analyzers/complexity-analyzer.js.map +1 -0
- package/dist/plugins/swift/analyzers/duplication-detector.d.ts +89 -0
- package/dist/plugins/swift/analyzers/duplication-detector.d.ts.map +1 -0
- package/dist/plugins/swift/analyzers/duplication-detector.js +271 -0
- package/dist/plugins/swift/analyzers/duplication-detector.js.map +1 -0
- package/dist/plugins/swift/analyzers/error-handling-checker.d.ts +34 -0
- package/dist/plugins/swift/analyzers/error-handling-checker.d.ts.map +1 -0
- package/dist/plugins/swift/analyzers/error-handling-checker.js +135 -0
- package/dist/plugins/swift/analyzers/error-handling-checker.js.map +1 -0
- package/dist/plugins/swift/analyzers/naming-checker.d.ts +47 -0
- package/dist/plugins/swift/analyzers/naming-checker.d.ts.map +1 -0
- package/dist/plugins/swift/analyzers/naming-checker.js +161 -0
- package/dist/plugins/swift/analyzers/naming-checker.js.map +1 -0
- package/dist/plugins/swift/analyzers/pattern-detector.d.ts +78 -0
- package/dist/plugins/swift/analyzers/pattern-detector.d.ts.map +1 -0
- package/dist/plugins/swift/analyzers/pattern-detector.js +247 -0
- package/dist/plugins/swift/analyzers/pattern-detector.js.map +1 -0
- package/dist/plugins/swift/analyzers/security-checker.d.ts +38 -0
- package/dist/plugins/swift/analyzers/security-checker.d.ts.map +1 -0
- package/dist/plugins/swift/analyzers/security-checker.js +135 -0
- package/dist/plugins/swift/analyzers/security-checker.js.map +1 -0
- package/dist/plugins/swift/analyzers/type-safety-checker.d.ts +41 -0
- package/dist/plugins/swift/analyzers/type-safety-checker.d.ts.map +1 -0
- package/dist/plugins/swift/analyzers/type-safety-checker.js +121 -0
- package/dist/plugins/swift/analyzers/type-safety-checker.js.map +1 -0
- package/dist/plugins/swift/analyzers/unused-symbol-detector.d.ts +38 -0
- package/dist/plugins/swift/analyzers/unused-symbol-detector.d.ts.map +1 -0
- package/dist/plugins/swift/analyzers/unused-symbol-detector.js +211 -0
- package/dist/plugins/swift/analyzers/unused-symbol-detector.js.map +1 -0
- package/dist/plugins/swift/dependency-analyzer.d.ts +33 -0
- package/dist/plugins/swift/dependency-analyzer.d.ts.map +1 -0
- package/dist/plugins/swift/dependency-analyzer.js +95 -0
- package/dist/plugins/swift/dependency-analyzer.js.map +1 -0
- package/dist/plugins/swift/index.d.ts +14 -0
- package/dist/plugins/swift/index.d.ts.map +1 -0
- package/dist/plugins/swift/index.js +19 -0
- package/dist/plugins/swift/index.js.map +1 -0
- package/dist/plugins/swift/parser.d.ts +160 -0
- package/dist/plugins/swift/parser.d.ts.map +1 -0
- package/dist/plugins/swift/parser.js +670 -0
- package/dist/plugins/swift/parser.js.map +1 -0
- package/dist/plugins/swift/swift-bridge/swift-parser +0 -0
- package/dist/plugins/swift/symbol-extractor.d.ts +46 -0
- package/dist/plugins/swift/symbol-extractor.d.ts.map +1 -0
- package/dist/plugins/swift/symbol-extractor.js +187 -0
- package/dist/plugins/swift/symbol-extractor.js.map +1 -0
- package/dist/plugins/swift/types.d.ts +137 -0
- package/dist/plugins/swift/types.d.ts.map +1 -0
- package/dist/plugins/swift/types.js +212 -0
- package/dist/plugins/swift/types.js.map +1 -0
- package/dist/plugins/typescript/analyzers/complexity-analyzer.d.ts +39 -0
- package/dist/plugins/typescript/analyzers/complexity-analyzer.d.ts.map +1 -0
- package/dist/plugins/typescript/analyzers/complexity-analyzer.js +196 -0
- package/dist/plugins/typescript/analyzers/complexity-analyzer.js.map +1 -0
- package/dist/{core/analysis → plugins/typescript/analyzers}/duplication-detector.d.ts +34 -3
- package/dist/plugins/typescript/analyzers/duplication-detector.d.ts.map +1 -0
- package/dist/plugins/typescript/analyzers/duplication-detector.js +695 -0
- package/dist/plugins/typescript/analyzers/duplication-detector.js.map +1 -0
- package/dist/plugins/typescript/analyzers/error-handling-checker.d.ts +26 -0
- package/dist/plugins/typescript/analyzers/error-handling-checker.d.ts.map +1 -0
- package/dist/plugins/typescript/analyzers/error-handling-checker.js +84 -0
- package/dist/plugins/typescript/analyzers/error-handling-checker.js.map +1 -0
- package/dist/plugins/typescript/analyzers/naming-checker.d.ts +30 -0
- package/dist/plugins/typescript/analyzers/naming-checker.d.ts.map +1 -0
- package/dist/plugins/typescript/analyzers/naming-checker.js +116 -0
- package/dist/plugins/typescript/analyzers/naming-checker.js.map +1 -0
- package/dist/plugins/typescript/analyzers/pattern-detector.d.ts +80 -0
- package/dist/plugins/typescript/analyzers/pattern-detector.d.ts.map +1 -0
- package/dist/plugins/typescript/analyzers/pattern-detector.js +267 -0
- package/dist/plugins/typescript/analyzers/pattern-detector.js.map +1 -0
- package/dist/plugins/typescript/analyzers/security-checker.d.ts +34 -0
- package/dist/plugins/typescript/analyzers/security-checker.d.ts.map +1 -0
- package/dist/plugins/typescript/analyzers/security-checker.js +126 -0
- package/dist/plugins/typescript/analyzers/security-checker.js.map +1 -0
- package/dist/plugins/typescript/analyzers/type-safety-checker.d.ts +32 -0
- package/dist/plugins/typescript/analyzers/type-safety-checker.d.ts.map +1 -0
- package/dist/plugins/typescript/analyzers/type-safety-checker.js +86 -0
- package/dist/plugins/typescript/analyzers/type-safety-checker.js.map +1 -0
- package/dist/plugins/typescript/analyzers/unused-symbol-detector.d.ts +47 -0
- package/dist/plugins/typescript/analyzers/unused-symbol-detector.d.ts.map +1 -0
- package/dist/plugins/typescript/analyzers/unused-symbol-detector.js +152 -0
- package/dist/plugins/typescript/analyzers/unused-symbol-detector.js.map +1 -0
- package/dist/plugins/typescript/parser.d.ts +41 -0
- package/dist/plugins/typescript/parser.d.ts.map +1 -1
- package/dist/plugins/typescript/parser.js +348 -3
- package/dist/plugins/typescript/parser.js.map +1 -1
- package/dist/plugins/typescript/symbol-extractor.d.ts.map +1 -1
- package/dist/plugins/typescript/symbol-extractor.js +12 -0
- package/dist/plugins/typescript/symbol-extractor.js.map +1 -1
- package/dist/plugins/typescript/types.d.ts.map +1 -1
- package/dist/plugins/typescript/types.js +10 -0
- package/dist/plugins/typescript/types.js.map +1 -1
- package/dist/shared/errors/config-error.d.ts +1 -1
- package/dist/shared/errors/config-error.d.ts.map +1 -1
- package/dist/shared/errors/config-error.js +1 -1
- package/dist/shared/errors/config-error.js.map +1 -1
- package/dist/shared/errors/file-error.d.ts +1 -1
- package/dist/shared/errors/file-error.d.ts.map +1 -1
- package/dist/shared/errors/file-error.js +1 -1
- package/dist/shared/errors/file-error.js.map +1 -1
- package/dist/shared/errors/index.d.ts +1 -1
- package/dist/shared/errors/index.d.ts.map +1 -1
- package/dist/shared/errors/index.js +4 -4
- package/dist/shared/errors/index.js.map +1 -1
- package/dist/shared/errors/parser-error.d.ts +1 -1
- package/dist/shared/errors/parser-error.d.ts.map +1 -1
- package/dist/shared/errors/parser-error.js +1 -1
- package/dist/shared/errors/parser-error.js.map +1 -1
- package/dist/shared/errors/validation-error.d.ts +1 -1
- package/dist/shared/errors/validation-error.d.ts.map +1 -1
- package/dist/shared/errors/validation-error.js +1 -1
- package/dist/shared/errors/validation-error.js.map +1 -1
- package/dist/shared/types/ast.d.ts +1 -1
- package/dist/shared/types/ast.d.ts.map +1 -1
- package/dist/shared/types/ast.js +1 -1
- package/dist/shared/types/ast.js.map +1 -1
- package/dist/shared/types/symbol.d.ts +8 -2
- package/dist/shared/types/symbol.d.ts.map +1 -1
- package/dist/shared/types/symbol.js +8 -2
- package/dist/shared/types/symbol.js.map +1 -1
- package/dist/shared/utils/index.d.ts +5 -5
- package/dist/shared/utils/index.d.ts.map +1 -1
- package/dist/shared/utils/index.js +5 -5
- package/dist/shared/utils/index.js.map +1 -1
- package/package.json +21 -9
- package/bin/mcp-server.js +0 -20
- package/dist/core/analysis/complexity-analyzer.d.ts +0 -81
- package/dist/core/analysis/complexity-analyzer.d.ts.map +0 -1
- package/dist/core/analysis/complexity-analyzer.js +0 -255
- package/dist/core/analysis/complexity-analyzer.js.map +0 -1
- package/dist/core/analysis/dead-code-detector.d.ts +0 -152
- package/dist/core/analysis/dead-code-detector.d.ts.map +0 -1
- package/dist/core/analysis/dead-code-detector.js +0 -351
- package/dist/core/analysis/dead-code-detector.js.map +0 -1
- package/dist/core/analysis/duplication-detector.d.ts.map +0 -1
- package/dist/core/analysis/duplication-detector.js +0 -433
- package/dist/core/analysis/duplication-detector.js.map +0 -1
- package/dist/core/analysis/index.d.ts +0 -9
- package/dist/core/analysis/index.d.ts.map +0 -1
- package/dist/core/analysis/index.js +0 -13
- package/dist/core/analysis/index.js.map +0 -1
- package/dist/core/analysis/quality-metrics.d.ts +0 -158
- package/dist/core/analysis/quality-metrics.d.ts.map +0 -1
- package/dist/core/analysis/quality-metrics.js +0 -442
- package/dist/core/analysis/quality-metrics.js.map +0 -1
- package/dist/core/move/import-resolver.d.ts.map +0 -1
- package/dist/core/move/import-resolver.js.map +0 -1
- package/dist/core/move/index.d.ts.map +0 -1
- package/dist/core/move/index.js.map +0 -1
- package/dist/core/move/move-service.d.ts.map +0 -1
- package/dist/core/move/move-service.js.map +0 -1
- package/dist/core/move/types.d.ts.map +0 -1
- package/dist/core/move/types.js.map +0 -1
- package/dist/core/refactor/design-patterns.d.ts.map +0 -1
- package/dist/core/refactor/design-patterns.js.map +0 -1
- package/dist/core/refactor/extract-function.d.ts.map +0 -1
- package/dist/core/refactor/extract-function.js.map +0 -1
- package/dist/core/refactor/index.d.ts +0 -8
- package/dist/core/refactor/index.d.ts.map +0 -1
- package/dist/core/refactor/index.js +0 -11
- package/dist/core/refactor/index.js.map +0 -1
- package/dist/core/refactor/inline-function.d.ts.map +0 -1
- package/dist/core/refactor/inline-function.js.map +0 -1
- package/dist/core/rename/index.d.ts +0 -9
- package/dist/core/rename/index.d.ts.map +0 -1
- package/dist/core/rename/index.js.map +0 -1
- package/dist/core/rename/reference-updater.d.ts.map +0 -1
- package/dist/core/rename/reference-updater.js.map +0 -1
- package/dist/core/rename/rename-engine.d.ts.map +0 -1
- package/dist/core/rename/rename-engine.js.map +0 -1
- package/dist/core/rename/scope-analyzer.d.ts.map +0 -1
- package/dist/core/rename/scope-analyzer.js.map +0 -1
- package/dist/core/rename/types.d.ts.map +0 -1
- package/dist/core/rename/types.js.map +0 -1
- package/dist/interfaces/mcp/index.d.ts +0 -7
- package/dist/interfaces/mcp/index.d.ts.map +0 -1
- package/dist/interfaces/mcp/index.js +0 -6
- package/dist/interfaces/mcp/index.js.map +0 -1
- package/dist/interfaces/mcp/mcp-server.d.ts +0 -34
- package/dist/interfaces/mcp/mcp-server.d.ts.map +0 -1
- package/dist/interfaces/mcp/mcp-server.js +0 -162
- package/dist/interfaces/mcp/mcp-server.js.map +0 -1
- package/dist/interfaces/mcp/mcp.d.ts +0 -52
- package/dist/interfaces/mcp/mcp.d.ts.map +0 -1
- package/dist/interfaces/mcp/mcp.js +0 -853
- package/dist/interfaces/mcp/mcp.js.map +0 -1
- /package/dist/core/{move → transform/location/move-file}/types.js +0 -0
- /package/dist/core/{refactor → transform/structure/extract}/extract-function.d.ts +0 -0
- /package/dist/core/{refactor → transform/structure/inline}/inline-function.d.ts +0 -0
- /package/dist/core/{refactor → transform/structure/patterns}/design-patterns.d.ts +0 -0
- /package/dist/core/{refactor → transform/structure/patterns}/design-patterns.js +0 -0
- /package/dist/core/{rename → transform/symbol/rename}/types.js +0 -0
|
@@ -3,19 +3,13 @@
|
|
|
3
3
|
* 提供命令列介面來操作 Agent IDE 功能
|
|
4
4
|
*/
|
|
5
5
|
import { Command } from 'commander';
|
|
6
|
-
import { IndexEngine } from '../../core/indexing/index-engine.js';
|
|
7
|
-
import { DependencyAnalyzer } from '../../core/dependency/dependency-analyzer.js';
|
|
8
|
-
import { RenameEngine } from '../../core/rename/rename-engine.js';
|
|
9
|
-
import { MoveService } from '../../core/move/index.js';
|
|
10
|
-
import { SearchService } from '../../core/search/service.js';
|
|
11
|
-
import { createIndexConfig } from '../../core/indexing/types.js';
|
|
12
6
|
import { ParserRegistry } from '../../infrastructure/parser/registry.js';
|
|
13
7
|
import { TypeScriptParser } from '../../plugins/typescript/parser.js';
|
|
14
8
|
import { JavaScriptParser } from '../../plugins/javascript/parser.js';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import
|
|
9
|
+
import { SwiftParser } from '../../plugins/swift/parser.js';
|
|
10
|
+
import { PythonParser } from '../../plugins/python/parser.js';
|
|
11
|
+
import { FileSystem } from '../../infrastructure/storage/index.js';
|
|
12
|
+
import { setupShiftCommand, setupMoveCommand, setupMoveMemberCommand, setupRenameCommand, setupChangeSignatureCommand, setupExtractCommand, setupInlineCommand, setupSearchCommand, setupAnalyzeCommand, setupDepsCommand, setupSnapshotCommand } from '../cli/commands/index.js';
|
|
19
13
|
import { readFileSync } from 'fs';
|
|
20
14
|
import * as path from 'path';
|
|
21
15
|
import { fileURLToPath } from 'url';
|
|
@@ -33,17 +27,24 @@ catch {
|
|
|
33
27
|
}
|
|
34
28
|
export class AgentIdeCLI {
|
|
35
29
|
program;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
constructor() {
|
|
30
|
+
fileSystem;
|
|
31
|
+
/**
|
|
32
|
+
* 建立 CLI 實例
|
|
33
|
+
* @param fileSystem - 檔案系統實例(可選,預設使用真實檔案系統)
|
|
34
|
+
*/
|
|
35
|
+
constructor(fileSystem) {
|
|
43
36
|
this.program = new Command();
|
|
37
|
+
// eslint-disable-next-line custom/no-default-instance-in-constructor -- CLI 入口點需要預設 FileSystem
|
|
38
|
+
this.fileSystem = fileSystem ?? new FileSystem();
|
|
44
39
|
this.setupCommands();
|
|
45
40
|
this.initializeParsers();
|
|
46
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* 建立測試用 CLI 實例
|
|
44
|
+
*/
|
|
45
|
+
static createForTesting(fileSystem) {
|
|
46
|
+
return new AgentIdeCLI(fileSystem);
|
|
47
|
+
}
|
|
47
48
|
/**
|
|
48
49
|
* 執行 CLI 程式
|
|
49
50
|
*/
|
|
@@ -91,6 +92,32 @@ export class AgentIdeCLI {
|
|
|
91
92
|
console.debug('JavaScript parser loading failed:', jsError);
|
|
92
93
|
console.debug('JavaScript Parser initialization warning:', jsError);
|
|
93
94
|
}
|
|
95
|
+
// 嘗試註冊內建的 Swift Parser
|
|
96
|
+
try {
|
|
97
|
+
// 解析 Swift CLI Bridge 路徑
|
|
98
|
+
const swiftBridgePath = path.resolve(__dirname, '../../plugins/swift/swift-bridge/swift-parser');
|
|
99
|
+
const swiftParser = new SwiftParser(swiftBridgePath);
|
|
100
|
+
if (!registry.getParserByName('swift')) {
|
|
101
|
+
registry.register(swiftParser);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
catch (swiftError) {
|
|
105
|
+
// 如果 Swift Parser 載入失敗,記錄錯誤
|
|
106
|
+
console.debug('Swift parser loading failed:', swiftError);
|
|
107
|
+
console.debug('Swift Parser initialization warning:', swiftError);
|
|
108
|
+
}
|
|
109
|
+
// 嘗試註冊內建的 Python Parser
|
|
110
|
+
try {
|
|
111
|
+
const pythonParser = new PythonParser();
|
|
112
|
+
if (!registry.getParserByName('python')) {
|
|
113
|
+
registry.register(pythonParser);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
catch (pythonError) {
|
|
117
|
+
// 如果 Python Parser 載入失敗,記錄錯誤
|
|
118
|
+
console.debug('Python parser loading failed:', pythonError);
|
|
119
|
+
console.debug('Python Parser initialization warning:', pythonError);
|
|
120
|
+
}
|
|
94
121
|
}
|
|
95
122
|
catch (error) {
|
|
96
123
|
// 靜默處理初始化錯誤,避免影響 CLI 啟動
|
|
@@ -102,1180 +129,32 @@ export class AgentIdeCLI {
|
|
|
102
129
|
.name('agent-ide')
|
|
103
130
|
.description('程式碼智能工具集 for AI Agents')
|
|
104
131
|
.version(packageVersion);
|
|
105
|
-
this.
|
|
106
|
-
|
|
107
|
-
this.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
.action(async (options) => {
|
|
124
|
-
await this.handleIndexCommand(options);
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
setupRenameCommand() {
|
|
128
|
-
this.program
|
|
129
|
-
.command('rename')
|
|
130
|
-
.description('重新命名程式碼元素')
|
|
131
|
-
.option('-t, --type <type>', '符號類型 (variable|function|class|interface)', 'variable')
|
|
132
|
-
.option('-s, --symbol <name>', '要重新命名的符號')
|
|
133
|
-
.option('-f, --from <name>', '原始名稱(--symbol 的別名)')
|
|
134
|
-
.option('-n, --new-name <name>', '新名稱')
|
|
135
|
-
.option('-o, --to <name>', '新名稱(--new-name 的別名)')
|
|
136
|
-
.option('-p, --path <path>', '檔案或目錄路徑', '.')
|
|
137
|
-
.option('--preview', '預覽變更而不執行')
|
|
138
|
-
.option('--format <format>', '輸出格式 (markdown|plain|json|minimal)', 'plain')
|
|
139
|
-
.action(async (options) => {
|
|
140
|
-
await this.handleRenameCommand(options);
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
setupRefactorCommand() {
|
|
144
|
-
this.program
|
|
145
|
-
.command('refactor <action>')
|
|
146
|
-
.description('重構程式碼 (extract-function | inline-function)')
|
|
147
|
-
.option('-f, --file <file>', '檔案路徑')
|
|
148
|
-
.option('-s, --start-line <line>', '起始行號')
|
|
149
|
-
.option('-e, --end-line <line>', '結束行號')
|
|
150
|
-
.option('-n, --function-name <name>', '函式名稱')
|
|
151
|
-
.option('-t, --target-file <file>', '目標檔案路徑(跨檔案提取)')
|
|
152
|
-
.option('-p, --path <path>', '專案路徑', '.')
|
|
153
|
-
.option('--preview', '預覽變更而不執行')
|
|
154
|
-
.option('--format <format>', '輸出格式 (markdown|plain|json|minimal)', 'plain')
|
|
155
|
-
.action(async (action, options) => {
|
|
156
|
-
await this.handleRefactorCommand(action, options);
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
setupMoveCommand() {
|
|
160
|
-
this.program
|
|
161
|
-
.command('move')
|
|
162
|
-
.description('移動檔案或目錄')
|
|
163
|
-
.argument('<source>', '來源路徑')
|
|
164
|
-
.argument('<target>', '目標路徑')
|
|
165
|
-
.option('--update-imports', '自動更新 import 路徑', true)
|
|
166
|
-
.option('--preview', '預覽變更而不執行')
|
|
167
|
-
.option('--format <format>', '輸出格式 (markdown|plain|json|minimal)', 'plain')
|
|
168
|
-
.action(async (source, target, options) => {
|
|
169
|
-
await this.handleMoveCommand(source, target, options);
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
setupSearchCommand() {
|
|
173
|
-
this.program
|
|
174
|
-
.command('search')
|
|
175
|
-
.description('搜尋程式碼')
|
|
176
|
-
.argument('<query>', '搜尋查詢')
|
|
177
|
-
.option('-t, --type <type>', '搜尋類型 (text|regex|fuzzy)', 'text')
|
|
178
|
-
.option('-p, --path <path>', '搜尋路徑', '.')
|
|
179
|
-
.option('-e, --extensions <exts>', '檔案副檔名', '.ts,.js,.tsx,.jsx')
|
|
180
|
-
.option('-l, --limit <num>', '結果數量限制', '50')
|
|
181
|
-
.option('-c, --context <lines>', '上下文行數', '2')
|
|
182
|
-
.option('--case-sensitive', '大小寫敏感')
|
|
183
|
-
.option('--whole-word', '全字匹配')
|
|
184
|
-
.option('--multiline', '多行匹配')
|
|
185
|
-
.option('--include <patterns>', '包含模式')
|
|
186
|
-
.option('--exclude <patterns>', '排除模式', 'node_modules/**,*.test.*')
|
|
187
|
-
.option('--format <format>', '輸出格式 (list|json|minimal)', 'list')
|
|
188
|
-
.action(async (query, options) => {
|
|
189
|
-
await this.handleSearchCommand(query, options);
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
setupAnalyzeCommand() {
|
|
193
|
-
this.program
|
|
194
|
-
.command('analyze [type]')
|
|
195
|
-
.description('分析程式碼品質')
|
|
196
|
-
.option('-p, --path <path>', '分析路徑', '.')
|
|
197
|
-
.option('--pattern <pattern>', '分析模式')
|
|
198
|
-
.option('--format <format>', '輸出格式 (json|table|summary)', 'summary')
|
|
199
|
-
.option('--all', '顯示所有掃描結果(預設只顯示有問題的項目)', false)
|
|
200
|
-
.action(async (type, options) => {
|
|
201
|
-
await this.handleAnalyzeCommand(type, options);
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
setupDepsCommand() {
|
|
205
|
-
this.program
|
|
206
|
-
.command('deps')
|
|
207
|
-
.description('分析依賴關係')
|
|
208
|
-
.option('-p, --path <path>', '分析路徑', '.')
|
|
209
|
-
.option('-t, --type <type>', '分析類型 (graph|cycles|impact)')
|
|
210
|
-
.option('-f, --file <file>', '特定檔案分析')
|
|
211
|
-
.option('--format <format>', '輸出格式 (json|dot|summary)', 'summary')
|
|
212
|
-
.option('--all', '顯示完整依賴圖(預設只顯示循環依賴和孤立檔案)', false)
|
|
213
|
-
.action(async (options) => {
|
|
214
|
-
await this.handleDepsCommand(options);
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
setupPluginsCommand() {
|
|
218
|
-
const pluginsCmd = this.program
|
|
219
|
-
.command('plugins')
|
|
220
|
-
.description('管理 Parser 插件');
|
|
221
|
-
pluginsCmd
|
|
222
|
-
.command('list')
|
|
223
|
-
.option('--enabled', '只顯示啟用的插件')
|
|
224
|
-
.option('--disabled', '只顯示停用的插件')
|
|
225
|
-
.description('列出所有插件')
|
|
226
|
-
.action(async (options) => {
|
|
227
|
-
await this.handlePluginsListCommand(options);
|
|
228
|
-
});
|
|
229
|
-
pluginsCmd
|
|
230
|
-
.command('info <plugin>')
|
|
231
|
-
.description('顯示插件資訊')
|
|
232
|
-
.action(async (pluginName) => {
|
|
233
|
-
await this.handlePluginInfoCommand(pluginName);
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
// Command handlers
|
|
237
|
-
async handleIndexCommand(options) {
|
|
238
|
-
const formatter = this.createFormatter(options.format);
|
|
239
|
-
const startTime = Date.now();
|
|
240
|
-
if (options.format !== 'json' && options.format !== 'minimal') {
|
|
241
|
-
console.log(formatter.formatTitle('程式碼索引', 1));
|
|
242
|
-
console.log('\n🔍 開始建立程式碼索引...\n');
|
|
243
|
-
}
|
|
244
|
-
try {
|
|
245
|
-
const config = createIndexConfig(options.path, {
|
|
246
|
-
includeExtensions: options.extensions.split(','),
|
|
247
|
-
excludePatterns: options.exclude.split(',')
|
|
248
|
-
});
|
|
249
|
-
this.indexEngine = new IndexEngine(config);
|
|
250
|
-
if (options.update) {
|
|
251
|
-
if (options.format !== 'json' && options.format !== 'minimal') {
|
|
252
|
-
console.log('📝 執行增量索引更新...');
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
else {
|
|
256
|
-
await this.indexEngine.indexProject(options.path);
|
|
257
|
-
}
|
|
258
|
-
const stats = await this.indexEngine.getStats();
|
|
259
|
-
const duration = Date.now() - startTime;
|
|
260
|
-
const statsData = {
|
|
261
|
-
檔案數: stats.totalFiles,
|
|
262
|
-
符號數: stats.totalSymbols,
|
|
263
|
-
'執行時間(ms)': duration
|
|
264
|
-
};
|
|
265
|
-
if (options.format === 'json') {
|
|
266
|
-
console.log(formatter.formatSuccess('索引完成', statsData));
|
|
267
|
-
}
|
|
268
|
-
else if (options.format === 'minimal') {
|
|
269
|
-
console.log(`index:success files=${stats.totalFiles} symbols=${stats.totalSymbols} time=${duration}ms`);
|
|
270
|
-
}
|
|
271
|
-
else {
|
|
272
|
-
console.log('\n' + formatter.formatSuccess('索引完成'));
|
|
273
|
-
console.log('\n' + formatter.formatTitle('統計資訊', 2));
|
|
274
|
-
console.log(formatter.formatStats(statsData));
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
catch (error) {
|
|
278
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
279
|
-
if (options.format === 'json') {
|
|
280
|
-
console.error(formatter.formatError(errorMessage));
|
|
281
|
-
}
|
|
282
|
-
else if (options.format === 'minimal') {
|
|
283
|
-
console.error(`index:error ${errorMessage}`);
|
|
284
|
-
}
|
|
285
|
-
else {
|
|
286
|
-
console.error('\n' + formatter.formatError(`索引失敗: ${errorMessage}`));
|
|
287
|
-
}
|
|
288
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
289
|
-
process.exit(1);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
async handleRenameCommand(options) {
|
|
294
|
-
// 支援多種參數名稱
|
|
295
|
-
const from = options.symbol || options.from;
|
|
296
|
-
const to = options.newName || options.to;
|
|
297
|
-
if (!from || !to) {
|
|
298
|
-
console.error('❌ 必須指定符號名稱和新名稱');
|
|
299
|
-
console.error(' 使用方式: agent-ide rename --symbol <name> --new-name <name>');
|
|
300
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
301
|
-
process.exit(1);
|
|
302
|
-
}
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
305
|
-
console.log(`🔄 重新命名 ${from} → ${to}`);
|
|
306
|
-
try {
|
|
307
|
-
const workspacePath = options.path || process.cwd();
|
|
308
|
-
// 初始化索引引擎(每次都重新索引以確保資料是最新的)
|
|
309
|
-
const config = createIndexConfig(workspacePath, {
|
|
310
|
-
includeExtensions: ['.ts', '.tsx', '.js', '.jsx'],
|
|
311
|
-
excludePatterns: ['node_modules/**', '*.test.*']
|
|
312
|
-
});
|
|
313
|
-
this.indexEngine = new IndexEngine(config);
|
|
314
|
-
await this.indexEngine.indexProject(workspacePath);
|
|
315
|
-
// 初始化重新命名引擎
|
|
316
|
-
if (!this.renameEngine) {
|
|
317
|
-
this.renameEngine = new RenameEngine();
|
|
318
|
-
}
|
|
319
|
-
// 1. 查找符號
|
|
320
|
-
console.log(`🔍 查找符號 "${from}"...`);
|
|
321
|
-
const searchResults = await this.indexEngine.findSymbol(from);
|
|
322
|
-
if (searchResults.length === 0) {
|
|
323
|
-
console.log(`❌ 找不到符號 "${from}"`);
|
|
324
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
325
|
-
process.exit(1);
|
|
326
|
-
}
|
|
327
|
-
return;
|
|
328
|
-
}
|
|
329
|
-
if (searchResults.length > 1) {
|
|
330
|
-
console.log('⚠️ 找到多個符號,使用第一個:');
|
|
331
|
-
searchResults.forEach((result, index) => {
|
|
332
|
-
console.log(` ${index + 1}. ${result.symbol.name} 在 ${result.symbol.location.filePath}:${result.symbol.location.range.start.line}`);
|
|
333
|
-
});
|
|
334
|
-
}
|
|
335
|
-
const targetSymbol = searchResults[0].symbol;
|
|
336
|
-
// 2. 預覽變更
|
|
337
|
-
if (options.preview) {
|
|
338
|
-
console.log('🔍 預覽變更...');
|
|
339
|
-
try {
|
|
340
|
-
// 取得所有專案檔案以進行跨檔案引用查找
|
|
341
|
-
const allProjectFiles = await this.getAllProjectFiles(options.path || workspacePath);
|
|
342
|
-
const preview = await this.renameEngine.previewRename({
|
|
343
|
-
symbol: targetSymbol,
|
|
344
|
-
newName: to,
|
|
345
|
-
filePaths: allProjectFiles
|
|
346
|
-
});
|
|
347
|
-
console.log('📝 預計變更:');
|
|
348
|
-
console.log(` 檔案數: ${preview.affectedFiles.length}`);
|
|
349
|
-
console.log(` 操作數: ${preview.operations.length}`);
|
|
350
|
-
if (preview.conflicts.length > 0) {
|
|
351
|
-
console.log('⚠️ 發現衝突:');
|
|
352
|
-
preview.conflicts.forEach(conflict => {
|
|
353
|
-
console.log(` - ${conflict.message}`);
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
preview.operations.forEach(op => {
|
|
357
|
-
console.log(` ${op.filePath}: "${op.oldText}" → "${op.newText}"`);
|
|
358
|
-
});
|
|
359
|
-
console.log('✅ 預覽完成');
|
|
360
|
-
return;
|
|
361
|
-
}
|
|
362
|
-
catch (previewError) {
|
|
363
|
-
console.error('❌ 預覽失敗:', previewError instanceof Error ? previewError.message : previewError);
|
|
364
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
365
|
-
process.exit(1);
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
// 3. 執行重新命名(處理跨檔案引用)
|
|
370
|
-
console.log('✏️ 執行重新命名...');
|
|
371
|
-
// 取得所有專案檔案(使用與 preview 相同的邏輯)
|
|
372
|
-
const allProjectFiles = await this.getAllProjectFiles(options.path || workspacePath);
|
|
373
|
-
// 使用 renameEngine 執行重新命名(與 preview 使用相同的引擎)
|
|
374
|
-
const renameResult = await this.renameEngine.rename({
|
|
375
|
-
symbol: targetSymbol,
|
|
376
|
-
newName: to,
|
|
377
|
-
filePaths: allProjectFiles
|
|
378
|
-
});
|
|
379
|
-
if (renameResult.success) {
|
|
380
|
-
console.log('✅ 重新命名成功!');
|
|
381
|
-
console.log(`📊 統計: ${renameResult.affectedFiles.length} 檔案, ${renameResult.operations.length} 變更`);
|
|
382
|
-
renameResult.operations.forEach(operation => {
|
|
383
|
-
console.log(` ✓ ${operation.filePath}: "${operation.oldText}" → "${operation.newText}"`);
|
|
384
|
-
});
|
|
385
|
-
}
|
|
386
|
-
else {
|
|
387
|
-
console.error('❌ 重新命名失敗:');
|
|
388
|
-
renameResult.errors?.forEach(error => {
|
|
389
|
-
console.error(` - ${error}`);
|
|
390
|
-
});
|
|
391
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
392
|
-
process.exit(1);
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
catch (error) {
|
|
397
|
-
console.error('❌ 重新命名失敗:', error instanceof Error ? error.message : error);
|
|
398
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
399
|
-
process.exit(1);
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
async handleRefactorCommand(action, options) {
|
|
404
|
-
if (!options.file) {
|
|
405
|
-
console.error('❌ 必須指定 --file 參數');
|
|
406
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
407
|
-
process.exit(1);
|
|
408
|
-
}
|
|
409
|
-
return;
|
|
410
|
-
}
|
|
411
|
-
console.log(`🔧 重構: ${action}`);
|
|
412
|
-
try {
|
|
413
|
-
const filePath = path.resolve(options.file);
|
|
414
|
-
if (action === 'extract-function') {
|
|
415
|
-
if (!options.startLine || !options.endLine || !options.functionName) {
|
|
416
|
-
console.error('❌ extract-function 需要 --start-line, --end-line 和 --function-name 參數');
|
|
417
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
418
|
-
process.exit(1);
|
|
419
|
-
}
|
|
420
|
-
return;
|
|
421
|
-
}
|
|
422
|
-
// 讀取檔案內容
|
|
423
|
-
const fs = await import('fs/promises');
|
|
424
|
-
const code = await fs.readFile(filePath, 'utf-8');
|
|
425
|
-
// 建立範圍
|
|
426
|
-
const range = {
|
|
427
|
-
start: { line: parseInt(options.startLine), column: 0 },
|
|
428
|
-
end: { line: parseInt(options.endLine), column: 0 }
|
|
429
|
-
};
|
|
430
|
-
// 初始化 FunctionExtractor
|
|
431
|
-
const { FunctionExtractor } = await import('../../core/refactor/extract-function.js');
|
|
432
|
-
const extractor = new FunctionExtractor();
|
|
433
|
-
// 執行提取
|
|
434
|
-
const extractConfig = {
|
|
435
|
-
functionName: options.functionName,
|
|
436
|
-
generateComments: true,
|
|
437
|
-
preserveFormatting: true,
|
|
438
|
-
validateExtraction: true,
|
|
439
|
-
...(options.targetFile ? {
|
|
440
|
-
targetFile: path.resolve(options.targetFile),
|
|
441
|
-
sourceFile: filePath
|
|
442
|
-
} : {})
|
|
443
|
-
};
|
|
444
|
-
const result = await extractor.extract(code, range, extractConfig);
|
|
445
|
-
if (result.success) {
|
|
446
|
-
// 套用編輯(按正確順序)
|
|
447
|
-
let modifiedCode = code;
|
|
448
|
-
// 先處理所有 insert 類型(在檔案開頭插入函式定義)
|
|
449
|
-
const insertEdits = result.edits.filter(e => e.type === 'insert');
|
|
450
|
-
const replaceEdits = result.edits.filter(e => e.type === 'replace');
|
|
451
|
-
// 先應用 replace(替換選取範圍為函式呼叫)
|
|
452
|
-
for (const edit of replaceEdits) {
|
|
453
|
-
modifiedCode = this.applyEditCorrectly(modifiedCode, edit);
|
|
454
|
-
}
|
|
455
|
-
// 再應用 insert(插入函式定義)
|
|
456
|
-
for (const edit of insertEdits) {
|
|
457
|
-
modifiedCode = this.applyEditCorrectly(modifiedCode, edit);
|
|
458
|
-
}
|
|
459
|
-
// 提取函式簽名(從修改後的程式碼中)
|
|
460
|
-
const functionSignatureMatch = modifiedCode.match(new RegExp(`(async\\s+)?function\\s+${result.functionName}\\s*\\([^)]*\\)`));
|
|
461
|
-
const functionSignature = functionSignatureMatch ? functionSignatureMatch[0] : `function ${result.functionName}`;
|
|
462
|
-
console.log('✅ 重構完成');
|
|
463
|
-
console.log(`📝 提取的函式: ${functionSignature}`);
|
|
464
|
-
console.log(functionSignature);
|
|
465
|
-
if (!options.preview) {
|
|
466
|
-
// 寫入原始檔案
|
|
467
|
-
await fs.writeFile(filePath, modifiedCode, 'utf-8');
|
|
468
|
-
console.log(`✓ 已更新 ${filePath}`);
|
|
469
|
-
// 如果是跨檔案提取,寫入目標檔案
|
|
470
|
-
if (result.targetFileContent && options.targetFile) {
|
|
471
|
-
const targetPath = path.resolve(options.targetFile);
|
|
472
|
-
// 確保目標目錄存在
|
|
473
|
-
const targetDir = path.dirname(targetPath);
|
|
474
|
-
await fs.mkdir(targetDir, { recursive: true });
|
|
475
|
-
// 寫入目標檔案
|
|
476
|
-
await fs.writeFile(targetPath, result.targetFileContent, 'utf-8');
|
|
477
|
-
console.log(`✓ 已建立/更新目標檔案 ${targetPath}`);
|
|
478
|
-
if (result.importStatement) {
|
|
479
|
-
console.log(`✓ 已加入 import: ${result.importStatement}`);
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
else {
|
|
484
|
-
console.log('\n🔍 預覽模式 - 未寫入檔案');
|
|
485
|
-
console.log(`📊 參數: ${result.parameters.map(p => p.name).join(', ')}`);
|
|
486
|
-
if (result.targetFileContent && options.targetFile) {
|
|
487
|
-
console.log(`📁 目標檔案: ${options.targetFile}`);
|
|
488
|
-
console.log(`📥 Import: ${result.importStatement || '(無)'}`);
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
else {
|
|
493
|
-
console.error('❌ 重構失敗:', result.errors.join(', '));
|
|
494
|
-
process.exitCode = 1;
|
|
495
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
496
|
-
process.exit(1);
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
else if (action === 'inline-function') {
|
|
501
|
-
console.error('❌ inline-function 尚未實作');
|
|
502
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
503
|
-
process.exit(1);
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
else {
|
|
507
|
-
console.error(`❌ 未知的重構操作: ${action}`);
|
|
508
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
509
|
-
process.exit(1);
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
catch (error) {
|
|
514
|
-
console.error('❌ 重構失敗:', error instanceof Error ? error.message : error);
|
|
515
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
516
|
-
process.exit(1);
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
async handleMoveCommand(source, target, options) {
|
|
521
|
-
console.log(`📦 移動 ${source} → ${target}`);
|
|
522
|
-
try {
|
|
523
|
-
// 檢查源檔案是否存在
|
|
524
|
-
const sourceExists = await this.fileExists(source);
|
|
525
|
-
if (!sourceExists) {
|
|
526
|
-
console.log(`❌ 移動失敗: 源檔案不存在 "${source}"`);
|
|
527
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
528
|
-
process.exit(1);
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
// 初始化移動服務
|
|
532
|
-
if (!this.moveService) {
|
|
533
|
-
// 讀取 tsconfig.json 路徑別名
|
|
534
|
-
const pathAliases = await this.loadPathAliases(process.cwd());
|
|
535
|
-
this.moveService = new MoveService({
|
|
536
|
-
pathAliases,
|
|
537
|
-
supportedExtensions: ['.ts', '.tsx', '.js', '.jsx', '.vue'],
|
|
538
|
-
includeNodeModules: false
|
|
539
|
-
});
|
|
540
|
-
}
|
|
541
|
-
const moveOperation = {
|
|
542
|
-
source: path.resolve(source),
|
|
543
|
-
target: path.resolve(target),
|
|
544
|
-
updateImports: options.updateImports
|
|
545
|
-
};
|
|
546
|
-
const moveOptions = {
|
|
547
|
-
preview: options.preview,
|
|
548
|
-
projectRoot: process.cwd()
|
|
549
|
-
};
|
|
550
|
-
// 執行移動操作
|
|
551
|
-
const result = await this.moveService.moveFile(moveOperation, moveOptions);
|
|
552
|
-
if (result.success) {
|
|
553
|
-
if (options.preview) {
|
|
554
|
-
console.log('🔍 預覽移動操作:');
|
|
555
|
-
}
|
|
556
|
-
else {
|
|
557
|
-
console.log('✅ 移動成功!');
|
|
558
|
-
}
|
|
559
|
-
console.log(`📊 統計: ${result.pathUpdates.length} 個 import 需要更新`);
|
|
560
|
-
if (result.pathUpdates.length > 0) {
|
|
561
|
-
console.log('📝 影響的檔案:');
|
|
562
|
-
const fileGroups = new Map();
|
|
563
|
-
result.pathUpdates.forEach(update => {
|
|
564
|
-
if (!fileGroups.has(update.filePath)) {
|
|
565
|
-
fileGroups.set(update.filePath, []);
|
|
566
|
-
}
|
|
567
|
-
fileGroups.get(update.filePath).push(update);
|
|
568
|
-
});
|
|
569
|
-
for (const [filePath, updates] of fileGroups) {
|
|
570
|
-
console.log(` 📄 ${path.relative(process.cwd(), filePath)}:`);
|
|
571
|
-
updates.forEach(update => {
|
|
572
|
-
console.log(` 第 ${update.line} 行: "${path.basename(source)}" → "${path.basename(target)}"`);
|
|
573
|
-
});
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
else {
|
|
578
|
-
console.error('❌ 移動失敗:', result.error);
|
|
579
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
580
|
-
process.exit(1);
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
catch (error) {
|
|
585
|
-
console.error('❌ 移動失敗:', error instanceof Error ? error.message : error);
|
|
586
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
587
|
-
process.exit(1);
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
async handleSearchCommand(query, options) {
|
|
592
|
-
const isMinimalOrJson = options.format === 'minimal' || options.format === 'json';
|
|
593
|
-
if (!isMinimalOrJson) {
|
|
594
|
-
console.log(`🔍 搜尋: "${query}"`);
|
|
595
|
-
}
|
|
596
|
-
try {
|
|
597
|
-
// 初始化搜尋服務
|
|
598
|
-
if (!this.searchService) {
|
|
599
|
-
this.searchService = new SearchService();
|
|
600
|
-
}
|
|
601
|
-
// 建構搜尋選項
|
|
602
|
-
const searchOptions = this.buildSearchOptions(options);
|
|
603
|
-
// 根據搜尋類型建立查詢
|
|
604
|
-
const searchQuery = {
|
|
605
|
-
type: 'text',
|
|
606
|
-
query,
|
|
607
|
-
options: searchOptions
|
|
608
|
-
};
|
|
609
|
-
// 執行搜尋
|
|
610
|
-
const startTime = Date.now();
|
|
611
|
-
const result = await this.searchService.searchText(searchQuery);
|
|
612
|
-
const searchTime = Date.now() - startTime;
|
|
613
|
-
// 顯示結果
|
|
614
|
-
if (result.matches.length === 0) {
|
|
615
|
-
if (!isMinimalOrJson) {
|
|
616
|
-
console.log('📝 沒有找到匹配結果');
|
|
617
|
-
}
|
|
618
|
-
else if (options.format === 'json') {
|
|
619
|
-
// JSON 格式輸出空結果
|
|
620
|
-
console.log(JSON.stringify({ results: [] }, null, 2));
|
|
621
|
-
}
|
|
622
|
-
return;
|
|
623
|
-
}
|
|
624
|
-
if (!isMinimalOrJson) {
|
|
625
|
-
console.log(`✅ 找到 ${result.matches.length} 個結果 (${searchTime}ms)`);
|
|
626
|
-
if (result.truncated) {
|
|
627
|
-
console.log(`⚠️ 結果已截斷,顯示前 ${options.limit} 個結果`);
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
// 格式化輸出
|
|
631
|
-
this.formatSearchResults(result, options);
|
|
632
|
-
}
|
|
633
|
-
catch (error) {
|
|
634
|
-
if (isMinimalOrJson) {
|
|
635
|
-
// 對於 minimal 和 json 格式,輸出空結果或錯誤
|
|
636
|
-
if (options.format === 'json') {
|
|
637
|
-
console.log(JSON.stringify({ matches: [], error: error instanceof Error ? error.message : String(error) }));
|
|
638
|
-
}
|
|
639
|
-
else {
|
|
640
|
-
console.error(`Error: ${error instanceof Error ? error.message : error}`);
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
else {
|
|
644
|
-
console.error('❌ 搜尋失敗:', error instanceof Error ? error.message : error);
|
|
645
|
-
}
|
|
646
|
-
// 測試環境不 exit
|
|
647
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
648
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
649
|
-
process.exit(1);
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
}
|
|
132
|
+
const context = this.createCommandContext();
|
|
133
|
+
// Transform 群組
|
|
134
|
+
const transformCmd = this.program
|
|
135
|
+
.command('transform')
|
|
136
|
+
.description('程式碼變換工具');
|
|
137
|
+
// 直接掛載到 transform(無中間層)
|
|
138
|
+
setupRenameCommand(transformCmd, context);
|
|
139
|
+
setupChangeSignatureCommand(transformCmd, context);
|
|
140
|
+
setupMoveCommand(transformCmd, context);
|
|
141
|
+
setupMoveMemberCommand(transformCmd, context);
|
|
142
|
+
setupShiftCommand(transformCmd, context);
|
|
143
|
+
setupExtractCommand(transformCmd, context);
|
|
144
|
+
setupInlineCommand(transformCmd, context);
|
|
145
|
+
// Query 命令(扁平式)
|
|
146
|
+
setupSearchCommand(this.program, context);
|
|
147
|
+
setupAnalyzeCommand(this.program, context);
|
|
148
|
+
setupDepsCommand(this.program, context);
|
|
149
|
+
setupSnapshotCommand(this.program, context);
|
|
653
150
|
}
|
|
654
151
|
/**
|
|
655
|
-
*
|
|
152
|
+
* 建立命令共用 Context
|
|
656
153
|
*/
|
|
657
|
-
|
|
658
|
-
const includeFiles = options.include ? options.include.split(',') : undefined;
|
|
659
|
-
const excludeFiles = options.exclude ? options.exclude.split(',') : undefined;
|
|
154
|
+
createCommandContext() {
|
|
660
155
|
return {
|
|
661
|
-
|
|
662
|
-
type: 'directory',
|
|
663
|
-
path: path.resolve(options.path),
|
|
664
|
-
recursive: true
|
|
665
|
-
},
|
|
666
|
-
maxResults: parseInt(options.limit),
|
|
667
|
-
caseSensitive: options.caseSensitive || false,
|
|
668
|
-
wholeWord: options.wholeWord || false,
|
|
669
|
-
regex: options.type === 'regex',
|
|
670
|
-
fuzzy: options.type === 'fuzzy',
|
|
671
|
-
multiline: options.multiline || false,
|
|
672
|
-
showContext: options.context > 0,
|
|
673
|
-
contextLines: parseInt(options.context),
|
|
674
|
-
includeFiles,
|
|
675
|
-
excludeFiles,
|
|
676
|
-
timeout: 30000
|
|
156
|
+
fileSystem: this.fileSystem
|
|
677
157
|
};
|
|
678
158
|
}
|
|
679
|
-
/**
|
|
680
|
-
* 格式化搜尋結果輸出
|
|
681
|
-
*/
|
|
682
|
-
formatSearchResults(result, options) {
|
|
683
|
-
switch (options.format) {
|
|
684
|
-
case 'json':
|
|
685
|
-
// 測試期望的格式是 { results: [...] } 而不是 { matches: [...] }
|
|
686
|
-
// 將絕對路徑轉換為相對路徑
|
|
687
|
-
const resultsWithRelativePaths = result.matches.map((match) => ({
|
|
688
|
-
...match,
|
|
689
|
-
file: this.formatFilePath(match.file)
|
|
690
|
-
}));
|
|
691
|
-
console.log(JSON.stringify({ results: resultsWithRelativePaths }, null, 2));
|
|
692
|
-
break;
|
|
693
|
-
case 'minimal':
|
|
694
|
-
// AI Agent 友善的最小輸出
|
|
695
|
-
result.matches.forEach((match) => {
|
|
696
|
-
console.log(`${match.file}:${match.line}:${match.column}:${match.content.trim()}`);
|
|
697
|
-
});
|
|
698
|
-
break;
|
|
699
|
-
case 'list':
|
|
700
|
-
default:
|
|
701
|
-
result.matches.forEach((match, index) => {
|
|
702
|
-
console.log(`\n${index + 1}. ${this.formatFilePath(match.file)}:${match.line}:${match.column}`);
|
|
703
|
-
console.log(` ${this.highlightMatch(match.content, options.query)}`);
|
|
704
|
-
// 顯示上下文
|
|
705
|
-
if (options.context > 0 && match.context) {
|
|
706
|
-
if (match.context.before.length > 0) {
|
|
707
|
-
match.context.before.forEach((line, i) => {
|
|
708
|
-
const lineNum = match.line - match.context.before.length + i;
|
|
709
|
-
console.log(` ${lineNum.toString().padStart(3, ' ')}: ${line}`);
|
|
710
|
-
});
|
|
711
|
-
}
|
|
712
|
-
console.log(`>> ${match.line.toString().padStart(3, ' ')}: ${this.highlightMatch(match.content, options.query)}`);
|
|
713
|
-
if (match.context.after.length > 0) {
|
|
714
|
-
match.context.after.forEach((line, i) => {
|
|
715
|
-
const lineNum = match.line + i + 1;
|
|
716
|
-
console.log(` ${lineNum.toString().padStart(3, ' ')}: ${line}`);
|
|
717
|
-
});
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
});
|
|
721
|
-
break;
|
|
722
|
-
}
|
|
723
|
-
}
|
|
724
|
-
/**
|
|
725
|
-
* 格式化檔案路徑(顯示相對路徑)
|
|
726
|
-
*/
|
|
727
|
-
formatFilePath(filePath) {
|
|
728
|
-
const cwd = process.cwd();
|
|
729
|
-
const relativePath = path.relative(cwd, filePath);
|
|
730
|
-
return relativePath.startsWith('..') ? filePath : relativePath;
|
|
731
|
-
}
|
|
732
|
-
/**
|
|
733
|
-
* 高亮匹配內容
|
|
734
|
-
*/
|
|
735
|
-
highlightMatch(text, query) {
|
|
736
|
-
if (!text || !query) {
|
|
737
|
-
return text;
|
|
738
|
-
}
|
|
739
|
-
// 簡單的高亮實作
|
|
740
|
-
try {
|
|
741
|
-
const regex = new RegExp(query.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gi');
|
|
742
|
-
return text.replace(regex, `[${query}]`);
|
|
743
|
-
}
|
|
744
|
-
catch {
|
|
745
|
-
return text;
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
async handleAnalyzeCommand(type, options) {
|
|
749
|
-
const analyzeType = type || 'complexity';
|
|
750
|
-
if (options.format !== 'json') {
|
|
751
|
-
console.log('📊 分析程式碼品質...');
|
|
752
|
-
}
|
|
753
|
-
try {
|
|
754
|
-
const analyzePath = options.path || process.cwd();
|
|
755
|
-
// 根據分析類型執行對應分析
|
|
756
|
-
if (analyzeType === 'complexity') {
|
|
757
|
-
const analyzer = new ComplexityAnalyzer();
|
|
758
|
-
// 獲取需要分析的檔案列表
|
|
759
|
-
const files = await this.getAllProjectFiles(analyzePath);
|
|
760
|
-
const results = await analyzer.analyzeFiles(files);
|
|
761
|
-
// 過濾高複雜度檔案(evaluation === 'high' 或 complexity > 10)
|
|
762
|
-
const highComplexityFiles = results.filter(r => r.complexity.evaluation === 'high' || r.complexity.cyclomaticComplexity > 10);
|
|
763
|
-
// 計算統計資訊
|
|
764
|
-
const complexities = results.map(r => r.complexity.cyclomaticComplexity);
|
|
765
|
-
const averageComplexity = complexities.length > 0
|
|
766
|
-
? complexities.reduce((sum, c) => sum + c, 0) / complexities.length
|
|
767
|
-
: 0;
|
|
768
|
-
const maxComplexity = complexities.length > 0
|
|
769
|
-
? Math.max(...complexities)
|
|
770
|
-
: 0;
|
|
771
|
-
if (options.format === 'json') {
|
|
772
|
-
const outputData = {
|
|
773
|
-
summary: {
|
|
774
|
-
totalScanned: results.length,
|
|
775
|
-
issuesFound: highComplexityFiles.length,
|
|
776
|
-
averageComplexity,
|
|
777
|
-
maxComplexity
|
|
778
|
-
}
|
|
779
|
-
};
|
|
780
|
-
if (options.all) {
|
|
781
|
-
outputData.all = results.map(r => ({
|
|
782
|
-
path: r.file,
|
|
783
|
-
complexity: r.complexity.cyclomaticComplexity,
|
|
784
|
-
cognitiveComplexity: r.complexity.cognitiveComplexity,
|
|
785
|
-
evaluation: r.complexity.evaluation
|
|
786
|
-
}));
|
|
787
|
-
}
|
|
788
|
-
else {
|
|
789
|
-
outputData.issues = highComplexityFiles.map(r => ({
|
|
790
|
-
path: r.file,
|
|
791
|
-
complexity: r.complexity.cyclomaticComplexity,
|
|
792
|
-
cognitiveComplexity: r.complexity.cognitiveComplexity,
|
|
793
|
-
evaluation: r.complexity.evaluation
|
|
794
|
-
}));
|
|
795
|
-
}
|
|
796
|
-
console.log(JSON.stringify(outputData, null, 2));
|
|
797
|
-
}
|
|
798
|
-
else {
|
|
799
|
-
console.log('✅ 複雜度分析完成!');
|
|
800
|
-
console.log(`📊 統計: ${results.length} 個檔案,${highComplexityFiles.length} 個高複雜度檔案`);
|
|
801
|
-
console.log(` 平均複雜度: ${averageComplexity.toFixed(2)}`);
|
|
802
|
-
console.log(` 最高複雜度: ${maxComplexity}`);
|
|
803
|
-
if (!options.all && highComplexityFiles.length > 0) {
|
|
804
|
-
console.log(`\n⚠️ 高複雜度檔案:`);
|
|
805
|
-
highComplexityFiles.forEach(r => {
|
|
806
|
-
console.log(` - ${r.file}: ${r.complexity.cyclomaticComplexity}`);
|
|
807
|
-
});
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
else if (analyzeType === 'dead-code') {
|
|
812
|
-
const detector = new DeadCodeDetector();
|
|
813
|
-
// 獲取需要分析的檔案列表
|
|
814
|
-
const files = await this.getAllProjectFiles(analyzePath);
|
|
815
|
-
const results = await detector.detectInFiles(files);
|
|
816
|
-
// 過濾有 dead code 的檔案
|
|
817
|
-
const filesWithDeadCode = results.filter(r => r.deadCode.length > 0);
|
|
818
|
-
// 統計結果
|
|
819
|
-
const allDeadCode = results.flatMap(r => r.deadCode);
|
|
820
|
-
const deadFunctions = allDeadCode.filter(d => d.type === 'function');
|
|
821
|
-
const deadVariables = allDeadCode.filter(d => d.type === 'variable');
|
|
822
|
-
if (options.format === 'json') {
|
|
823
|
-
const outputData = {
|
|
824
|
-
summary: {
|
|
825
|
-
totalScanned: results.length,
|
|
826
|
-
filesWithIssues: filesWithDeadCode.length,
|
|
827
|
-
totalDeadFunctions: deadFunctions.length,
|
|
828
|
-
totalDeadVariables: deadVariables.length,
|
|
829
|
-
totalDeadCode: allDeadCode.length
|
|
830
|
-
}
|
|
831
|
-
};
|
|
832
|
-
if (options.all) {
|
|
833
|
-
outputData.all = results.map(r => ({
|
|
834
|
-
path: r.file,
|
|
835
|
-
deadCode: r.deadCode
|
|
836
|
-
}));
|
|
837
|
-
}
|
|
838
|
-
else {
|
|
839
|
-
outputData.issues = filesWithDeadCode.map(r => ({
|
|
840
|
-
path: r.file,
|
|
841
|
-
deadCode: r.deadCode
|
|
842
|
-
}));
|
|
843
|
-
}
|
|
844
|
-
outputData.deadFunctions = deadFunctions;
|
|
845
|
-
outputData.deadVariables = deadVariables;
|
|
846
|
-
console.log(JSON.stringify(outputData, null, 2));
|
|
847
|
-
}
|
|
848
|
-
else {
|
|
849
|
-
console.log('✅ 死代碼檢測完成!');
|
|
850
|
-
console.log(`📊 統計: ${results.length} 個檔案,${filesWithDeadCode.length} 個有死代碼`);
|
|
851
|
-
console.log('📊 發現:');
|
|
852
|
-
console.log(` 未使用函式: ${deadFunctions.length} 個`);
|
|
853
|
-
console.log(` 未使用變數: ${deadVariables.length} 個`);
|
|
854
|
-
if (!options.all && filesWithDeadCode.length > 0) {
|
|
855
|
-
console.log(`\n⚠️ 有死代碼的檔案:`);
|
|
856
|
-
filesWithDeadCode.forEach(r => {
|
|
857
|
-
console.log(` - ${r.file}: ${r.deadCode.length} 項`);
|
|
858
|
-
});
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
|
-
}
|
|
862
|
-
else if (analyzeType === 'best-practices') {
|
|
863
|
-
// 檢查最佳實踐
|
|
864
|
-
const files = await this.getAllProjectFiles(analyzePath);
|
|
865
|
-
const issues = [];
|
|
866
|
-
const recommendations = [];
|
|
867
|
-
// 檢查 ES Module 使用情況
|
|
868
|
-
const hasEsmImports = files.some(async (file) => {
|
|
869
|
-
const content = await fs.readFile(file, 'utf-8');
|
|
870
|
-
return content.includes('import ') && content.includes('from ');
|
|
871
|
-
});
|
|
872
|
-
if (hasEsmImports) {
|
|
873
|
-
recommendations.push({
|
|
874
|
-
type: 'es-modules',
|
|
875
|
-
status: 'good',
|
|
876
|
-
message: '專案使用 ES Module'
|
|
877
|
-
});
|
|
878
|
-
}
|
|
879
|
-
if (options.format === 'json') {
|
|
880
|
-
console.log(JSON.stringify({
|
|
881
|
-
issues,
|
|
882
|
-
recommendations
|
|
883
|
-
}, null, 2));
|
|
884
|
-
}
|
|
885
|
-
else {
|
|
886
|
-
console.log('✅ 最佳實踐檢查完成!');
|
|
887
|
-
console.log(`📊 建議數: ${recommendations.length}`);
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
else if (analyzeType === 'patterns') {
|
|
891
|
-
// 檢測程式碼模式
|
|
892
|
-
const files = await this.getAllProjectFiles(analyzePath);
|
|
893
|
-
const patterns = [];
|
|
894
|
-
let asyncFunctionCount = 0;
|
|
895
|
-
for (const file of files) {
|
|
896
|
-
const content = await fs.readFile(file, 'utf-8');
|
|
897
|
-
// 檢測 async 函式
|
|
898
|
-
if (content.includes('async ')) {
|
|
899
|
-
asyncFunctionCount++;
|
|
900
|
-
if (!patterns.includes('async-functions')) {
|
|
901
|
-
patterns.push('async-functions');
|
|
902
|
-
}
|
|
903
|
-
}
|
|
904
|
-
// 檢測 Promise 使用
|
|
905
|
-
if (content.includes('Promise') || content.includes('.then(')) {
|
|
906
|
-
if (!patterns.includes('promise-usage')) {
|
|
907
|
-
patterns.push('promise-usage');
|
|
908
|
-
}
|
|
909
|
-
}
|
|
910
|
-
// TypeScript 特定模式
|
|
911
|
-
if (file.endsWith('.ts') || file.endsWith('.tsx')) {
|
|
912
|
-
// 檢測 interface 使用
|
|
913
|
-
if (content.includes('interface ') && !patterns.includes('interface-usage')) {
|
|
914
|
-
patterns.push('interface-usage');
|
|
915
|
-
}
|
|
916
|
-
// 檢測泛型類型
|
|
917
|
-
if (content.match(/<[A-Z]\w*(\s*extends\s+\w+)?>/g) && !patterns.includes('generic-types')) {
|
|
918
|
-
patterns.push('generic-types');
|
|
919
|
-
}
|
|
920
|
-
// 檢測 enum 使用
|
|
921
|
-
if (content.includes('enum ') && !patterns.includes('enum-usage')) {
|
|
922
|
-
patterns.push('enum-usage');
|
|
923
|
-
}
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
if (options.format === 'json') {
|
|
927
|
-
console.log(JSON.stringify({
|
|
928
|
-
patterns,
|
|
929
|
-
statistics: {
|
|
930
|
-
asyncFunctions: asyncFunctionCount
|
|
931
|
-
}
|
|
932
|
-
}, null, 2));
|
|
933
|
-
}
|
|
934
|
-
else {
|
|
935
|
-
console.log('✅ 模式檢測完成!');
|
|
936
|
-
console.log(`📊 發現模式: ${patterns.join(', ')}`);
|
|
937
|
-
}
|
|
938
|
-
}
|
|
939
|
-
else {
|
|
940
|
-
throw new Error(`不支援的分析類型: ${analyzeType}`);
|
|
941
|
-
}
|
|
942
|
-
}
|
|
943
|
-
catch (error) {
|
|
944
|
-
if (options.format === 'json') {
|
|
945
|
-
console.log(JSON.stringify({ error: error instanceof Error ? error.message : String(error) }));
|
|
946
|
-
}
|
|
947
|
-
else {
|
|
948
|
-
console.error('❌ 分析失敗:', error instanceof Error ? error.message : error);
|
|
949
|
-
}
|
|
950
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
951
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
952
|
-
process.exit(1);
|
|
953
|
-
}
|
|
954
|
-
}
|
|
955
|
-
}
|
|
956
|
-
}
|
|
957
|
-
async handleDepsCommand(options) {
|
|
958
|
-
if (options.format !== 'json') {
|
|
959
|
-
console.log('🕸️ 分析依賴關係...');
|
|
960
|
-
}
|
|
961
|
-
try {
|
|
962
|
-
const analyzePath = options.path || process.cwd();
|
|
963
|
-
// 初始化依賴分析器
|
|
964
|
-
if (!this.dependencyAnalyzer) {
|
|
965
|
-
this.dependencyAnalyzer = new DependencyAnalyzer();
|
|
966
|
-
}
|
|
967
|
-
// 分析專案依賴
|
|
968
|
-
const projectDeps = await this.dependencyAnalyzer.analyzeProject(analyzePath);
|
|
969
|
-
// 獲取統計資訊
|
|
970
|
-
const stats = this.dependencyAnalyzer.getStats();
|
|
971
|
-
// 使用 CycleDetector 檢測循環依賴
|
|
972
|
-
const cycleDetector = new (await import('../../core/dependency/cycle-detector.js')).CycleDetector();
|
|
973
|
-
const graph = await this.buildGraphFromProjectDeps(projectDeps);
|
|
974
|
-
const cycles = cycleDetector.detectCycles(graph);
|
|
975
|
-
// 輸出結果
|
|
976
|
-
if (options.format === 'json') {
|
|
977
|
-
// 根據 --file 選項決定輸出格式
|
|
978
|
-
if (options.file) {
|
|
979
|
-
// 單檔案依賴查詢模式
|
|
980
|
-
const targetFile = path.resolve(options.file);
|
|
981
|
-
const dependencies = {};
|
|
982
|
-
dependencies[options.file] = graph.getDependencies(targetFile);
|
|
983
|
-
console.log(JSON.stringify({
|
|
984
|
-
dependencies
|
|
985
|
-
}, null, 2));
|
|
986
|
-
}
|
|
987
|
-
else {
|
|
988
|
-
// 專案依賴圖模式
|
|
989
|
-
const outputData = {
|
|
990
|
-
summary: {
|
|
991
|
-
totalFiles: stats.totalFiles,
|
|
992
|
-
totalDependencies: stats.totalDependencies,
|
|
993
|
-
averageDependenciesPerFile: stats.averageDependenciesPerFile,
|
|
994
|
-
maxDependenciesInFile: stats.maxDependenciesInFile,
|
|
995
|
-
issuesFound: cycles.length + stats.orphanedFiles
|
|
996
|
-
},
|
|
997
|
-
issues: {
|
|
998
|
-
cycles: cycles.map(c => ({
|
|
999
|
-
cycle: c.cycle,
|
|
1000
|
-
length: c.length,
|
|
1001
|
-
severity: c.severity
|
|
1002
|
-
})),
|
|
1003
|
-
circularDependencies: cycles.length,
|
|
1004
|
-
orphanedFiles: stats.orphanedFiles
|
|
1005
|
-
}
|
|
1006
|
-
};
|
|
1007
|
-
// 只有在 --all 時才輸出完整依賴圖
|
|
1008
|
-
if (options.all) {
|
|
1009
|
-
const nodes = graph.getAllNodes().map((nodeId) => ({
|
|
1010
|
-
id: nodeId,
|
|
1011
|
-
dependencies: graph.getDependencies(nodeId)
|
|
1012
|
-
}));
|
|
1013
|
-
const edges = [];
|
|
1014
|
-
for (const nodeId of graph.getAllNodes()) {
|
|
1015
|
-
for (const depId of graph.getDependencies(nodeId)) {
|
|
1016
|
-
edges.push({ source: nodeId, target: depId });
|
|
1017
|
-
}
|
|
1018
|
-
}
|
|
1019
|
-
outputData.all = {
|
|
1020
|
-
nodes,
|
|
1021
|
-
edges
|
|
1022
|
-
};
|
|
1023
|
-
}
|
|
1024
|
-
console.log(JSON.stringify(outputData, null, 2));
|
|
1025
|
-
}
|
|
1026
|
-
}
|
|
1027
|
-
else {
|
|
1028
|
-
console.log('✅ 依賴分析完成!');
|
|
1029
|
-
console.log('📊 統計:');
|
|
1030
|
-
console.log(` 總檔案數: ${stats.totalFiles}`);
|
|
1031
|
-
console.log(` 總依賴數: ${stats.totalDependencies}`);
|
|
1032
|
-
console.log(` 平均依賴數: ${stats.averageDependenciesPerFile.toFixed(2)}`);
|
|
1033
|
-
console.log(` 最大依賴數: ${stats.maxDependenciesInFile}`);
|
|
1034
|
-
if (cycles.length > 0) {
|
|
1035
|
-
console.log(`⚠️ 發現 ${cycles.length} 個循環依賴:`);
|
|
1036
|
-
cycles.forEach((cycle, index) => {
|
|
1037
|
-
console.log(` ${index + 1}. ${cycle.cycle.join(' → ')} (長度: ${cycle.length}, 嚴重性: ${cycle.severity})`);
|
|
1038
|
-
});
|
|
1039
|
-
}
|
|
1040
|
-
else {
|
|
1041
|
-
console.log('✓ 無循環依賴');
|
|
1042
|
-
}
|
|
1043
|
-
if (stats.orphanedFiles > 0) {
|
|
1044
|
-
console.log(`⚠️ 發現 ${stats.orphanedFiles} 個孤立檔案`);
|
|
1045
|
-
}
|
|
1046
|
-
}
|
|
1047
|
-
}
|
|
1048
|
-
catch (error) {
|
|
1049
|
-
if (options.format === 'json') {
|
|
1050
|
-
console.log(JSON.stringify({ error: error instanceof Error ? error.message : String(error) }));
|
|
1051
|
-
}
|
|
1052
|
-
else {
|
|
1053
|
-
console.error('❌ 依賴分析失敗:', error instanceof Error ? error.message : error);
|
|
1054
|
-
}
|
|
1055
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
1056
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
1057
|
-
process.exit(1);
|
|
1058
|
-
}
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
}
|
|
1062
|
-
/**
|
|
1063
|
-
* 從專案依賴資訊建立依賴圖
|
|
1064
|
-
*/
|
|
1065
|
-
async buildGraphFromProjectDeps(projectDeps) {
|
|
1066
|
-
const { DependencyGraph } = await import('../../core/dependency/dependency-graph.js');
|
|
1067
|
-
const graph = new DependencyGraph();
|
|
1068
|
-
// 新增所有檔案節點及其依賴關係
|
|
1069
|
-
for (const fileDep of projectDeps.fileDependencies) {
|
|
1070
|
-
graph.addNode(fileDep.filePath);
|
|
1071
|
-
for (const dep of fileDep.dependencies) {
|
|
1072
|
-
graph.addDependency(fileDep.filePath, dep.path);
|
|
1073
|
-
}
|
|
1074
|
-
}
|
|
1075
|
-
return graph;
|
|
1076
|
-
}
|
|
1077
|
-
async handlePluginsListCommand(options) {
|
|
1078
|
-
console.log('🔌 插件列表:');
|
|
1079
|
-
const registry = ParserRegistry.getInstance();
|
|
1080
|
-
// 確保 registry 存在且有 listParsers 方法
|
|
1081
|
-
if (!registry || typeof registry.listParsers !== 'function') {
|
|
1082
|
-
console.log('📝 插件系統尚未初始化');
|
|
1083
|
-
return;
|
|
1084
|
-
}
|
|
1085
|
-
const parsers = registry.listParsers();
|
|
1086
|
-
if (!parsers || parsers.length === 0) {
|
|
1087
|
-
console.log('📝 未找到已註冊的插件');
|
|
1088
|
-
return;
|
|
1089
|
-
}
|
|
1090
|
-
console.table(parsers.map(p => ({
|
|
1091
|
-
名稱: p.name,
|
|
1092
|
-
版本: p.version,
|
|
1093
|
-
支援副檔名: p.supportedExtensions.join(', '),
|
|
1094
|
-
支援語言: p.supportedLanguages.join(', '),
|
|
1095
|
-
註冊時間: p.registeredAt.toLocaleString()
|
|
1096
|
-
})));
|
|
1097
|
-
}
|
|
1098
|
-
async handlePluginInfoCommand(pluginName) {
|
|
1099
|
-
const registry = ParserRegistry.getInstance();
|
|
1100
|
-
// 確保 registry 存在且有 getParserByName 方法
|
|
1101
|
-
if (!registry || typeof registry.getParserByName !== 'function') {
|
|
1102
|
-
console.error('❌ 插件系統尚未初始化');
|
|
1103
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
1104
|
-
process.exit(1);
|
|
1105
|
-
}
|
|
1106
|
-
}
|
|
1107
|
-
const plugin = registry.getParserByName(pluginName);
|
|
1108
|
-
if (!plugin) {
|
|
1109
|
-
console.error(`❌ 找不到插件: ${pluginName}`);
|
|
1110
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
1111
|
-
process.exit(1);
|
|
1112
|
-
}
|
|
1113
|
-
}
|
|
1114
|
-
console.log(`🔌 插件資訊: ${pluginName}`);
|
|
1115
|
-
// TODO: 顯示詳細插件資訊
|
|
1116
|
-
}
|
|
1117
|
-
/**
|
|
1118
|
-
* 檢查檔案是否存在
|
|
1119
|
-
*/
|
|
1120
|
-
async fileExists(filePath) {
|
|
1121
|
-
try {
|
|
1122
|
-
await fs.access(filePath);
|
|
1123
|
-
return true;
|
|
1124
|
-
}
|
|
1125
|
-
catch {
|
|
1126
|
-
return false;
|
|
1127
|
-
}
|
|
1128
|
-
}
|
|
1129
|
-
/**
|
|
1130
|
-
* 正確套用程式碼編輯
|
|
1131
|
-
*/
|
|
1132
|
-
applyEditCorrectly(code, edit) {
|
|
1133
|
-
const lines = code.split('\n');
|
|
1134
|
-
switch (edit.type) {
|
|
1135
|
-
case 'replace': {
|
|
1136
|
-
// 計算起始和結束位置的偏移量
|
|
1137
|
-
const startOffset = this.positionToOffset(lines, edit.range.start);
|
|
1138
|
-
const endOffset = this.positionToOffset(lines, edit.range.end);
|
|
1139
|
-
return code.substring(0, startOffset) + edit.newText + code.substring(endOffset);
|
|
1140
|
-
}
|
|
1141
|
-
case 'insert': {
|
|
1142
|
-
const offset = this.positionToOffset(lines, edit.range.start);
|
|
1143
|
-
return code.substring(0, offset) + edit.newText + code.substring(offset);
|
|
1144
|
-
}
|
|
1145
|
-
case 'delete': {
|
|
1146
|
-
const startOffset = this.positionToOffset(lines, edit.range.start);
|
|
1147
|
-
const endOffset = this.positionToOffset(lines, edit.range.end);
|
|
1148
|
-
return code.substring(0, startOffset) + code.substring(endOffset);
|
|
1149
|
-
}
|
|
1150
|
-
default:
|
|
1151
|
-
return code;
|
|
1152
|
-
}
|
|
1153
|
-
}
|
|
1154
|
-
/**
|
|
1155
|
-
* 將行列位置轉換為字元偏移量
|
|
1156
|
-
*/
|
|
1157
|
-
positionToOffset(lines, position) {
|
|
1158
|
-
let offset = 0;
|
|
1159
|
-
for (let i = 0; i < position.line - 1 && i < lines.length; i++) {
|
|
1160
|
-
offset += lines[i].length + 1; // +1 for newline
|
|
1161
|
-
}
|
|
1162
|
-
offset += position.column;
|
|
1163
|
-
return Math.min(offset, lines.join('\n').length);
|
|
1164
|
-
}
|
|
1165
|
-
/**
|
|
1166
|
-
* @deprecated 使用 applyEditCorrectly 代替
|
|
1167
|
-
*/
|
|
1168
|
-
applyCodeEdit(code, edit) {
|
|
1169
|
-
const lines = code.split('\n');
|
|
1170
|
-
const startLine = edit.range.start.line - 1; // 轉為 0-based
|
|
1171
|
-
const endLine = edit.range.end.line - 1;
|
|
1172
|
-
// 取得編輯範圍前後的內容
|
|
1173
|
-
const before = lines.slice(0, startLine);
|
|
1174
|
-
const after = lines.slice(endLine + 1);
|
|
1175
|
-
// 組合新的內容
|
|
1176
|
-
return [...before, edit.newText, ...after].join('\n');
|
|
1177
|
-
}
|
|
1178
|
-
/**
|
|
1179
|
-
* 獲取專案中的所有檔案
|
|
1180
|
-
*/
|
|
1181
|
-
async getAllProjectFiles(projectPath) {
|
|
1182
|
-
const files = [];
|
|
1183
|
-
const allowedExtensions = ['.ts', '.tsx', '.js', '.jsx'];
|
|
1184
|
-
const excludePatterns = ['node_modules', 'dist', '.git', 'coverage'];
|
|
1185
|
-
// 檢查路徑是檔案還是目錄
|
|
1186
|
-
try {
|
|
1187
|
-
const stats = await fs.stat(projectPath);
|
|
1188
|
-
if (stats.isFile()) {
|
|
1189
|
-
// 如果是單一檔案,直接返回
|
|
1190
|
-
if (allowedExtensions.some(ext => projectPath.endsWith(ext))) {
|
|
1191
|
-
return [projectPath];
|
|
1192
|
-
}
|
|
1193
|
-
return [];
|
|
1194
|
-
}
|
|
1195
|
-
}
|
|
1196
|
-
catch (error) {
|
|
1197
|
-
// 路徑不存在
|
|
1198
|
-
return [];
|
|
1199
|
-
}
|
|
1200
|
-
async function walkDir(dir) {
|
|
1201
|
-
try {
|
|
1202
|
-
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
1203
|
-
for (const entry of entries) {
|
|
1204
|
-
const fullPath = path.join(dir, entry.name);
|
|
1205
|
-
if (entry.isDirectory()) {
|
|
1206
|
-
// 跳過排除的目錄
|
|
1207
|
-
if (excludePatterns.some(pattern => entry.name.includes(pattern))) {
|
|
1208
|
-
continue;
|
|
1209
|
-
}
|
|
1210
|
-
await walkDir(fullPath);
|
|
1211
|
-
}
|
|
1212
|
-
else if (entry.isFile()) {
|
|
1213
|
-
// 只包含支援的副檔名
|
|
1214
|
-
if (allowedExtensions.some(ext => entry.name.endsWith(ext))) {
|
|
1215
|
-
files.push(fullPath);
|
|
1216
|
-
}
|
|
1217
|
-
}
|
|
1218
|
-
}
|
|
1219
|
-
}
|
|
1220
|
-
catch (error) {
|
|
1221
|
-
// 忽略無法存取的目錄
|
|
1222
|
-
}
|
|
1223
|
-
}
|
|
1224
|
-
await walkDir(projectPath);
|
|
1225
|
-
return files;
|
|
1226
|
-
}
|
|
1227
|
-
/**
|
|
1228
|
-
* 讀取 tsconfig.json 的路徑別名設定
|
|
1229
|
-
*/
|
|
1230
|
-
async loadPathAliases(projectRoot) {
|
|
1231
|
-
const pathAliases = {};
|
|
1232
|
-
try {
|
|
1233
|
-
const tsconfigPath = path.join(projectRoot, 'tsconfig.json');
|
|
1234
|
-
const tsconfigContent = await fs.readFile(tsconfigPath, 'utf-8');
|
|
1235
|
-
const tsconfig = JSON.parse(tsconfigContent);
|
|
1236
|
-
if (tsconfig.compilerOptions?.paths) {
|
|
1237
|
-
const baseUrl = tsconfig.compilerOptions.baseUrl || '.';
|
|
1238
|
-
const basePath = path.resolve(projectRoot, baseUrl);
|
|
1239
|
-
for (const [alias, paths] of Object.entries(tsconfig.compilerOptions.paths)) {
|
|
1240
|
-
if (Array.isArray(paths) && paths.length > 0) {
|
|
1241
|
-
// 移除 /* 後綴
|
|
1242
|
-
const cleanAlias = alias.replace(/\/\*$/, '');
|
|
1243
|
-
const cleanPath = paths[0].replace(/\/\*$/, '');
|
|
1244
|
-
// 轉換為絕對路徑
|
|
1245
|
-
pathAliases[cleanAlias] = path.resolve(basePath, cleanPath);
|
|
1246
|
-
}
|
|
1247
|
-
}
|
|
1248
|
-
}
|
|
1249
|
-
}
|
|
1250
|
-
catch (error) {
|
|
1251
|
-
// tsconfig.json 不存在或解析失敗,使用空的路徑別名
|
|
1252
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
1253
|
-
console.warn('⚠️ 無法讀取 tsconfig.json 路徑別名設定');
|
|
1254
|
-
}
|
|
1255
|
-
}
|
|
1256
|
-
return pathAliases;
|
|
1257
|
-
}
|
|
1258
|
-
/**
|
|
1259
|
-
* 建立輸出格式化器
|
|
1260
|
-
*/
|
|
1261
|
-
createFormatter(format) {
|
|
1262
|
-
let outputFormat;
|
|
1263
|
-
switch (format?.toLowerCase()) {
|
|
1264
|
-
case 'markdown':
|
|
1265
|
-
outputFormat = OutputFormat.Markdown;
|
|
1266
|
-
break;
|
|
1267
|
-
case 'json':
|
|
1268
|
-
outputFormat = OutputFormat.Json;
|
|
1269
|
-
break;
|
|
1270
|
-
case 'minimal':
|
|
1271
|
-
outputFormat = OutputFormat.Minimal;
|
|
1272
|
-
break;
|
|
1273
|
-
case 'plain':
|
|
1274
|
-
default:
|
|
1275
|
-
outputFormat = OutputFormat.Plain;
|
|
1276
|
-
break;
|
|
1277
|
-
}
|
|
1278
|
-
return new OutputFormatter(outputFormat);
|
|
1279
|
-
}
|
|
1280
159
|
}
|
|
1281
160
|
//# sourceMappingURL=cli.js.map
|