agent-ide 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +678 -0
- package/bin/agent-ide.js +19 -0
- package/bin/mcp-server.js +20 -0
- package/dist/application/events/event-bus.d.ts +107 -0
- package/dist/application/events/event-bus.d.ts.map +1 -0
- package/dist/application/events/event-bus.js +364 -0
- package/dist/application/events/event-bus.js.map +1 -0
- package/dist/application/events/event-types.d.ts +195 -0
- package/dist/application/events/event-types.d.ts.map +1 -0
- package/dist/application/events/event-types.js +36 -0
- package/dist/application/events/event-types.js.map +1 -0
- package/dist/application/events/index.d.ts +6 -0
- package/dist/application/events/index.d.ts.map +1 -0
- package/dist/application/events/index.js +6 -0
- package/dist/application/events/index.js.map +1 -0
- package/dist/application/index.d.ts +85 -0
- package/dist/application/index.d.ts.map +1 -0
- package/dist/application/index.js +138 -0
- package/dist/application/index.js.map +1 -0
- package/dist/application/services/cache-coordinator.service.d.ts +69 -0
- package/dist/application/services/cache-coordinator.service.d.ts.map +1 -0
- package/dist/application/services/cache-coordinator.service.js +251 -0
- package/dist/application/services/cache-coordinator.service.js.map +1 -0
- package/dist/application/services/error-handler.service.d.ts +56 -0
- package/dist/application/services/error-handler.service.d.ts.map +1 -0
- package/dist/application/services/error-handler.service.js +273 -0
- package/dist/application/services/error-handler.service.js.map +1 -0
- package/dist/application/services/index.d.ts +8 -0
- package/dist/application/services/index.d.ts.map +1 -0
- package/dist/application/services/index.js +8 -0
- package/dist/application/services/index.js.map +1 -0
- package/dist/application/services/module-coordinator.service.d.ts +70 -0
- package/dist/application/services/module-coordinator.service.d.ts.map +1 -0
- package/dist/application/services/module-coordinator.service.js +418 -0
- package/dist/application/services/module-coordinator.service.js.map +1 -0
- package/dist/application/services/session-manager.service.d.ts +86 -0
- package/dist/application/services/session-manager.service.d.ts.map +1 -0
- package/dist/application/services/session-manager.service.js +318 -0
- package/dist/application/services/session-manager.service.js.map +1 -0
- package/dist/application/services/workflow-engine.service.d.ts +76 -0
- package/dist/application/services/workflow-engine.service.d.ts.map +1 -0
- package/dist/application/services/workflow-engine.service.js +405 -0
- package/dist/application/services/workflow-engine.service.js.map +1 -0
- package/dist/application/state/application-state.d.ts +164 -0
- package/dist/application/state/application-state.d.ts.map +1 -0
- package/dist/application/state/application-state.js +290 -0
- package/dist/application/state/application-state.js.map +1 -0
- package/dist/application/state/index.d.ts +15 -0
- package/dist/application/state/index.d.ts.map +1 -0
- package/dist/application/state/index.js +15 -0
- package/dist/application/state/index.js.map +1 -0
- package/dist/application/state/session-state.d.ts +114 -0
- package/dist/application/state/session-state.d.ts.map +1 -0
- package/dist/application/state/session-state.js +188 -0
- package/dist/application/state/session-state.js.map +1 -0
- package/dist/application/state/state-manager.d.ts +122 -0
- package/dist/application/state/state-manager.d.ts.map +1 -0
- package/dist/application/state/state-manager.js +234 -0
- package/dist/application/state/state-manager.js.map +1 -0
- package/dist/application/types.d.ts +280 -0
- package/dist/application/types.d.ts.map +1 -0
- package/dist/application/types.js +13 -0
- package/dist/application/types.js.map +1 -0
- package/dist/application/workflows/analysis-workflow.d.ts +239 -0
- package/dist/application/workflows/analysis-workflow.d.ts.map +1 -0
- package/dist/application/workflows/analysis-workflow.js +395 -0
- package/dist/application/workflows/analysis-workflow.js.map +1 -0
- package/dist/application/workflows/base-workflow.d.ts +108 -0
- package/dist/application/workflows/base-workflow.d.ts.map +1 -0
- package/dist/application/workflows/base-workflow.js +236 -0
- package/dist/application/workflows/base-workflow.js.map +1 -0
- package/dist/application/workflows/index.d.ts +115 -0
- package/dist/application/workflows/index.d.ts.map +1 -0
- package/dist/application/workflows/index.js +218 -0
- package/dist/application/workflows/index.js.map +1 -0
- package/dist/application/workflows/refactor-workflow.d.ts +107 -0
- package/dist/application/workflows/refactor-workflow.d.ts.map +1 -0
- package/dist/application/workflows/refactor-workflow.js +310 -0
- package/dist/application/workflows/refactor-workflow.js.map +1 -0
- package/dist/core/analysis/complexity-analyzer.d.ts +81 -0
- package/dist/core/analysis/complexity-analyzer.d.ts.map +1 -0
- package/dist/core/analysis/complexity-analyzer.js +254 -0
- package/dist/core/analysis/complexity-analyzer.js.map +1 -0
- package/dist/core/analysis/dead-code-detector.d.ts +123 -0
- package/dist/core/analysis/dead-code-detector.d.ts.map +1 -0
- package/dist/core/analysis/dead-code-detector.js +275 -0
- package/dist/core/analysis/dead-code-detector.js.map +1 -0
- package/dist/core/analysis/duplication-detector.d.ts +150 -0
- package/dist/core/analysis/duplication-detector.d.ts.map +1 -0
- package/dist/core/analysis/duplication-detector.js +433 -0
- package/dist/core/analysis/duplication-detector.js.map +1 -0
- package/dist/core/analysis/index.d.ts +9 -0
- package/dist/core/analysis/index.d.ts.map +1 -0
- package/dist/core/analysis/index.js +13 -0
- package/dist/core/analysis/index.js.map +1 -0
- package/dist/core/analysis/quality-metrics.d.ts +158 -0
- package/dist/core/analysis/quality-metrics.d.ts.map +1 -0
- package/dist/core/analysis/quality-metrics.js +442 -0
- package/dist/core/analysis/quality-metrics.js.map +1 -0
- package/dist/core/dependency/cycle-detector.d.ts +81 -0
- package/dist/core/dependency/cycle-detector.d.ts.map +1 -0
- package/dist/core/dependency/cycle-detector.js +300 -0
- package/dist/core/dependency/cycle-detector.js.map +1 -0
- package/dist/core/dependency/dependency-analyzer.d.ts +152 -0
- package/dist/core/dependency/dependency-analyzer.d.ts.map +1 -0
- package/dist/core/dependency/dependency-analyzer.js +458 -0
- package/dist/core/dependency/dependency-analyzer.js.map +1 -0
- package/dist/core/dependency/dependency-graph.d.ts +156 -0
- package/dist/core/dependency/dependency-graph.d.ts.map +1 -0
- package/dist/core/dependency/dependency-graph.js +371 -0
- package/dist/core/dependency/dependency-graph.js.map +1 -0
- package/dist/core/dependency/index.d.ts +27 -0
- package/dist/core/dependency/index.d.ts.map +1 -0
- package/dist/core/dependency/index.js +36 -0
- package/dist/core/dependency/index.js.map +1 -0
- package/dist/core/dependency/types.d.ts +168 -0
- package/dist/core/dependency/types.d.ts.map +1 -0
- package/dist/core/dependency/types.js +103 -0
- package/dist/core/dependency/types.js.map +1 -0
- package/dist/core/indexing/file-index.d.ts +117 -0
- package/dist/core/indexing/file-index.d.ts.map +1 -0
- package/dist/core/indexing/file-index.js +302 -0
- package/dist/core/indexing/file-index.js.map +1 -0
- package/dist/core/indexing/file-watcher.d.ts +110 -0
- package/dist/core/indexing/file-watcher.d.ts.map +1 -0
- package/dist/core/indexing/file-watcher.js +280 -0
- package/dist/core/indexing/file-watcher.js.map +1 -0
- package/dist/core/indexing/index-engine.d.ts +120 -0
- package/dist/core/indexing/index-engine.d.ts.map +1 -0
- package/dist/core/indexing/index-engine.js +445 -0
- package/dist/core/indexing/index-engine.js.map +1 -0
- package/dist/core/indexing/index.d.ts +25 -0
- package/dist/core/indexing/index.d.ts.map +1 -0
- package/dist/core/indexing/index.js +36 -0
- package/dist/core/indexing/index.js.map +1 -0
- package/dist/core/indexing/symbol-index.d.ts +107 -0
- package/dist/core/indexing/symbol-index.d.ts.map +1 -0
- package/dist/core/indexing/symbol-index.js +352 -0
- package/dist/core/indexing/symbol-index.js.map +1 -0
- package/dist/core/indexing/types.d.ts +222 -0
- package/dist/core/indexing/types.d.ts.map +1 -0
- package/dist/core/indexing/types.js +143 -0
- package/dist/core/indexing/types.js.map +1 -0
- package/dist/core/move/import-resolver.d.ts +54 -0
- package/dist/core/move/import-resolver.d.ts.map +1 -0
- package/dist/core/move/import-resolver.js +268 -0
- package/dist/core/move/import-resolver.js.map +1 -0
- package/dist/core/move/index.d.ts +10 -0
- package/dist/core/move/index.d.ts.map +1 -0
- package/dist/core/move/index.js +12 -0
- package/dist/core/move/index.js.map +1 -0
- package/dist/core/move/move-service.d.ts +67 -0
- package/dist/core/move/move-service.d.ts.map +1 -0
- package/dist/core/move/move-service.js +400 -0
- package/dist/core/move/move-service.js.map +1 -0
- package/dist/core/move/types.d.ts +266 -0
- package/dist/core/move/types.d.ts.map +1 -0
- package/dist/core/move/types.js +101 -0
- package/dist/core/move/types.js.map +1 -0
- package/dist/core/performance/analyzer.d.ts +62 -0
- package/dist/core/performance/analyzer.d.ts.map +1 -0
- package/dist/core/performance/analyzer.js +378 -0
- package/dist/core/performance/analyzer.js.map +1 -0
- package/dist/core/performance/cache-manager.d.ts +161 -0
- package/dist/core/performance/cache-manager.d.ts.map +1 -0
- package/dist/core/performance/cache-manager.js +375 -0
- package/dist/core/performance/cache-manager.js.map +1 -0
- package/dist/core/performance/index.d.ts +14 -0
- package/dist/core/performance/index.d.ts.map +1 -0
- package/dist/core/performance/index.js +17 -0
- package/dist/core/performance/index.js.map +1 -0
- package/dist/core/performance/interfaces.d.ts +188 -0
- package/dist/core/performance/interfaces.d.ts.map +1 -0
- package/dist/core/performance/interfaces.js +17 -0
- package/dist/core/performance/interfaces.js.map +1 -0
- package/dist/core/performance/memory-manager.d.ts +176 -0
- package/dist/core/performance/memory-manager.d.ts.map +1 -0
- package/dist/core/performance/memory-manager.js +364 -0
- package/dist/core/performance/memory-manager.js.map +1 -0
- package/dist/core/performance/monitor.d.ts +92 -0
- package/dist/core/performance/monitor.d.ts.map +1 -0
- package/dist/core/performance/monitor.js +228 -0
- package/dist/core/performance/monitor.js.map +1 -0
- package/dist/core/refactor/design-patterns.d.ts +178 -0
- package/dist/core/refactor/design-patterns.d.ts.map +1 -0
- package/dist/core/refactor/design-patterns.js +656 -0
- package/dist/core/refactor/design-patterns.js.map +1 -0
- package/dist/core/refactor/extract-function.d.ts +175 -0
- package/dist/core/refactor/extract-function.d.ts.map +1 -0
- package/dist/core/refactor/extract-function.js +478 -0
- package/dist/core/refactor/extract-function.js.map +1 -0
- package/dist/core/refactor/index.d.ts +8 -0
- package/dist/core/refactor/index.d.ts.map +1 -0
- package/dist/core/refactor/index.js +11 -0
- package/dist/core/refactor/index.js.map +1 -0
- package/dist/core/refactor/inline-function.d.ts +175 -0
- package/dist/core/refactor/inline-function.d.ts.map +1 -0
- package/dist/core/refactor/inline-function.js +425 -0
- package/dist/core/refactor/inline-function.js.map +1 -0
- package/dist/core/rename/index.d.ts +9 -0
- package/dist/core/rename/index.d.ts.map +1 -0
- package/dist/core/rename/index.js +13 -0
- package/dist/core/rename/index.js.map +1 -0
- package/dist/core/rename/reference-updater.d.ts +77 -0
- package/dist/core/rename/reference-updater.d.ts.map +1 -0
- package/dist/core/rename/reference-updater.js +400 -0
- package/dist/core/rename/reference-updater.js.map +1 -0
- package/dist/core/rename/rename-engine.d.ts +69 -0
- package/dist/core/rename/rename-engine.d.ts.map +1 -0
- package/dist/core/rename/rename-engine.js +350 -0
- package/dist/core/rename/rename-engine.js.map +1 -0
- package/dist/core/rename/scope-analyzer.d.ts +75 -0
- package/dist/core/rename/scope-analyzer.d.ts.map +1 -0
- package/dist/core/rename/scope-analyzer.js +269 -0
- package/dist/core/rename/scope-analyzer.js.map +1 -0
- package/dist/core/rename/types.d.ts +163 -0
- package/dist/core/rename/types.d.ts.map +1 -0
- package/dist/core/rename/types.js +80 -0
- package/dist/core/rename/types.js.map +1 -0
- package/dist/core/search/engines/text-engine.d.ts +52 -0
- package/dist/core/search/engines/text-engine.d.ts.map +1 -0
- package/dist/core/search/engines/text-engine.js +376 -0
- package/dist/core/search/engines/text-engine.js.map +1 -0
- package/dist/core/search/index.d.ts +10 -0
- package/dist/core/search/index.d.ts.map +1 -0
- package/dist/core/search/index.js +11 -0
- package/dist/core/search/index.js.map +1 -0
- package/dist/core/search/service.d.ts +105 -0
- package/dist/core/search/service.d.ts.map +1 -0
- package/dist/core/search/service.js +384 -0
- package/dist/core/search/service.js.map +1 -0
- package/dist/core/search/types.d.ts +357 -0
- package/dist/core/search/types.d.ts.map +1 -0
- package/dist/core/search/types.js +47 -0
- package/dist/core/search/types.js.map +1 -0
- package/dist/infrastructure/cache/cache-manager.d.ts +113 -0
- package/dist/infrastructure/cache/cache-manager.d.ts.map +1 -0
- package/dist/infrastructure/cache/cache-manager.js +279 -0
- package/dist/infrastructure/cache/cache-manager.js.map +1 -0
- package/dist/infrastructure/cache/index.d.ts +138 -0
- package/dist/infrastructure/cache/index.d.ts.map +1 -0
- package/dist/infrastructure/cache/index.js +266 -0
- package/dist/infrastructure/cache/index.js.map +1 -0
- package/dist/infrastructure/cache/memory-cache.d.ts +94 -0
- package/dist/infrastructure/cache/memory-cache.d.ts.map +1 -0
- package/dist/infrastructure/cache/memory-cache.js +327 -0
- package/dist/infrastructure/cache/memory-cache.js.map +1 -0
- package/dist/infrastructure/cache/strategies.d.ts +99 -0
- package/dist/infrastructure/cache/strategies.d.ts.map +1 -0
- package/dist/infrastructure/cache/strategies.js +230 -0
- package/dist/infrastructure/cache/strategies.js.map +1 -0
- package/dist/infrastructure/cache/types.d.ts +220 -0
- package/dist/infrastructure/cache/types.d.ts.map +1 -0
- package/dist/infrastructure/cache/types.js +42 -0
- package/dist/infrastructure/cache/types.js.map +1 -0
- package/dist/infrastructure/parser/base.d.ts +126 -0
- package/dist/infrastructure/parser/base.d.ts.map +1 -0
- package/dist/infrastructure/parser/base.js +269 -0
- package/dist/infrastructure/parser/base.js.map +1 -0
- package/dist/infrastructure/parser/factory.d.ts +141 -0
- package/dist/infrastructure/parser/factory.d.ts.map +1 -0
- package/dist/infrastructure/parser/factory.js +306 -0
- package/dist/infrastructure/parser/factory.js.map +1 -0
- package/dist/infrastructure/parser/index.d.ts +12 -0
- package/dist/infrastructure/parser/index.d.ts.map +1 -0
- package/dist/infrastructure/parser/index.js +12 -0
- package/dist/infrastructure/parser/index.js.map +1 -0
- package/dist/infrastructure/parser/interface.d.ts +108 -0
- package/dist/infrastructure/parser/interface.d.ts.map +1 -0
- package/dist/infrastructure/parser/interface.js +72 -0
- package/dist/infrastructure/parser/interface.js.map +1 -0
- package/dist/infrastructure/parser/registry.d.ts +141 -0
- package/dist/infrastructure/parser/registry.d.ts.map +1 -0
- package/dist/infrastructure/parser/registry.js +289 -0
- package/dist/infrastructure/parser/registry.js.map +1 -0
- package/dist/infrastructure/parser/types.d.ts +172 -0
- package/dist/infrastructure/parser/types.d.ts.map +1 -0
- package/dist/infrastructure/parser/types.js +147 -0
- package/dist/infrastructure/parser/types.js.map +1 -0
- package/dist/infrastructure/storage/file-system.d.ts +74 -0
- package/dist/infrastructure/storage/file-system.d.ts.map +1 -0
- package/dist/infrastructure/storage/file-system.js +334 -0
- package/dist/infrastructure/storage/file-system.js.map +1 -0
- package/dist/infrastructure/storage/file-watcher.d.ts +84 -0
- package/dist/infrastructure/storage/file-watcher.d.ts.map +1 -0
- package/dist/infrastructure/storage/file-watcher.js +249 -0
- package/dist/infrastructure/storage/file-watcher.js.map +1 -0
- package/dist/infrastructure/storage/index.d.ts +11 -0
- package/dist/infrastructure/storage/index.d.ts.map +1 -0
- package/dist/infrastructure/storage/index.js +16 -0
- package/dist/infrastructure/storage/index.js.map +1 -0
- package/dist/infrastructure/storage/path-utils.d.ts +96 -0
- package/dist/infrastructure/storage/path-utils.d.ts.map +1 -0
- package/dist/infrastructure/storage/path-utils.js +272 -0
- package/dist/infrastructure/storage/path-utils.js.map +1 -0
- package/dist/infrastructure/storage/types.d.ts +106 -0
- package/dist/infrastructure/storage/types.d.ts.map +1 -0
- package/dist/infrastructure/storage/types.js +53 -0
- package/dist/infrastructure/storage/types.js.map +1 -0
- package/dist/interfaces/cli/cli.d.ts +70 -0
- package/dist/interfaces/cli/cli.d.ts.map +1 -0
- package/dist/interfaces/cli/cli.js +1054 -0
- package/dist/interfaces/cli/cli.js.map +1 -0
- package/dist/interfaces/cli/index.d.ts +7 -0
- package/dist/interfaces/cli/index.d.ts.map +1 -0
- package/dist/interfaces/cli/index.js +22 -0
- package/dist/interfaces/cli/index.js.map +1 -0
- package/dist/interfaces/mcp/index.d.ts +7 -0
- package/dist/interfaces/mcp/index.d.ts.map +1 -0
- package/dist/interfaces/mcp/index.js +6 -0
- package/dist/interfaces/mcp/index.js.map +1 -0
- package/dist/interfaces/mcp/mcp-server.d.ts +34 -0
- package/dist/interfaces/mcp/mcp-server.d.ts.map +1 -0
- package/dist/interfaces/mcp/mcp-server.js +154 -0
- package/dist/interfaces/mcp/mcp-server.js.map +1 -0
- package/dist/interfaces/mcp/mcp.d.ts +44 -0
- package/dist/interfaces/mcp/mcp.d.ts.map +1 -0
- package/dist/interfaces/mcp/mcp.js +559 -0
- package/dist/interfaces/mcp/mcp.js.map +1 -0
- package/dist/plugins/javascript/index.d.ts +12 -0
- package/dist/plugins/javascript/index.d.ts.map +1 -0
- package/dist/plugins/javascript/index.js +16 -0
- package/dist/plugins/javascript/index.js.map +1 -0
- package/dist/plugins/javascript/parser.d.ts +81 -0
- package/dist/plugins/javascript/parser.d.ts.map +1 -0
- package/dist/plugins/javascript/parser.js +457 -0
- package/dist/plugins/javascript/parser.js.map +1 -0
- package/dist/plugins/javascript/types.d.ts +131 -0
- package/dist/plugins/javascript/types.d.ts.map +1 -0
- package/dist/plugins/javascript/types.js +366 -0
- package/dist/plugins/javascript/types.js.map +1 -0
- package/dist/plugins/swift/index.d.ts +11 -0
- package/dist/plugins/swift/index.d.ts.map +1 -0
- package/dist/plugins/swift/index.js +15 -0
- package/dist/plugins/swift/index.js.map +1 -0
- package/dist/plugins/swift/parser.d.ts +98 -0
- package/dist/plugins/swift/parser.d.ts.map +1 -0
- package/dist/plugins/swift/parser.js +612 -0
- package/dist/plugins/swift/parser.js.map +1 -0
- package/dist/plugins/swift/types.d.ts +196 -0
- package/dist/plugins/swift/types.d.ts.map +1 -0
- package/dist/plugins/swift/types.js +268 -0
- package/dist/plugins/swift/types.js.map +1 -0
- package/dist/plugins/typescript/dependency-analyzer.d.ts +78 -0
- package/dist/plugins/typescript/dependency-analyzer.d.ts.map +1 -0
- package/dist/plugins/typescript/dependency-analyzer.js +305 -0
- package/dist/plugins/typescript/dependency-analyzer.js.map +1 -0
- package/dist/plugins/typescript/index.d.ts +9 -0
- package/dist/plugins/typescript/index.d.ts.map +1 -0
- package/dist/plugins/typescript/index.js +8 -0
- package/dist/plugins/typescript/index.js.map +1 -0
- package/dist/plugins/typescript/parser.d.ts +117 -0
- package/dist/plugins/typescript/parser.d.ts.map +1 -0
- package/dist/plugins/typescript/parser.js +888 -0
- package/dist/plugins/typescript/parser.js.map +1 -0
- package/dist/plugins/typescript/symbol-extractor.d.ts +76 -0
- package/dist/plugins/typescript/symbol-extractor.d.ts.map +1 -0
- package/dist/plugins/typescript/symbol-extractor.js +339 -0
- package/dist/plugins/typescript/symbol-extractor.js.map +1 -0
- package/dist/plugins/typescript/types.d.ts +131 -0
- package/dist/plugins/typescript/types.d.ts.map +1 -0
- package/dist/plugins/typescript/types.js +331 -0
- package/dist/plugins/typescript/types.js.map +1 -0
- package/dist/shared/errors/base-error.d.ts +27 -0
- package/dist/shared/errors/base-error.d.ts.map +1 -0
- package/dist/shared/errors/base-error.js +58 -0
- package/dist/shared/errors/base-error.js.map +1 -0
- package/dist/shared/errors/config-error.d.ts +21 -0
- package/dist/shared/errors/config-error.d.ts.map +1 -0
- package/dist/shared/errors/config-error.js +34 -0
- package/dist/shared/errors/config-error.js.map +1 -0
- package/dist/shared/errors/file-error.d.ts +21 -0
- package/dist/shared/errors/file-error.d.ts.map +1 -0
- package/dist/shared/errors/file-error.js +34 -0
- package/dist/shared/errors/file-error.js.map +1 -0
- package/dist/shared/errors/index.d.ts +59 -0
- package/dist/shared/errors/index.d.ts.map +1 -0
- package/dist/shared/errors/index.js +114 -0
- package/dist/shared/errors/index.js.map +1 -0
- package/dist/shared/errors/parser-error.d.ts +72 -0
- package/dist/shared/errors/parser-error.d.ts.map +1 -0
- package/dist/shared/errors/parser-error.js +104 -0
- package/dist/shared/errors/parser-error.js.map +1 -0
- package/dist/shared/errors/validation-error.d.ts +21 -0
- package/dist/shared/errors/validation-error.d.ts.map +1 -0
- package/dist/shared/errors/validation-error.js +34 -0
- package/dist/shared/errors/validation-error.js.map +1 -0
- package/dist/shared/index.d.ts +11 -0
- package/dist/shared/index.d.ts.map +1 -0
- package/dist/shared/index.js +22 -0
- package/dist/shared/index.js.map +1 -0
- package/dist/shared/types/ast.d.ts +78 -0
- package/dist/shared/types/ast.d.ts.map +1 -0
- package/dist/shared/types/ast.js +215 -0
- package/dist/shared/types/ast.js.map +1 -0
- package/dist/shared/types/core.d.ts +65 -0
- package/dist/shared/types/core.d.ts.map +1 -0
- package/dist/shared/types/core.js +114 -0
- package/dist/shared/types/core.js.map +1 -0
- package/dist/shared/types/index.d.ts +11 -0
- package/dist/shared/types/index.d.ts.map +1 -0
- package/dist/shared/types/index.js +12 -0
- package/dist/shared/types/index.js.map +1 -0
- package/dist/shared/types/symbol.d.ts +119 -0
- package/dist/shared/types/symbol.d.ts.map +1 -0
- package/dist/shared/types/symbol.js +197 -0
- package/dist/shared/types/symbol.js.map +1 -0
- package/dist/shared/utils/array.d.ts +68 -0
- package/dist/shared/utils/array.d.ts.map +1 -0
- package/dist/shared/utils/array.js +165 -0
- package/dist/shared/utils/array.js.map +1 -0
- package/dist/shared/utils/async.d.ts +87 -0
- package/dist/shared/utils/async.d.ts.map +1 -0
- package/dist/shared/utils/async.js +185 -0
- package/dist/shared/utils/async.js.map +1 -0
- package/dist/shared/utils/index.d.ts +32 -0
- package/dist/shared/utils/index.d.ts.map +1 -0
- package/dist/shared/utils/index.js +37 -0
- package/dist/shared/utils/index.js.map +1 -0
- package/dist/shared/utils/memory-monitor.d.ts +83 -0
- package/dist/shared/utils/memory-monitor.d.ts.map +1 -0
- package/dist/shared/utils/memory-monitor.js +168 -0
- package/dist/shared/utils/memory-monitor.js.map +1 -0
- package/dist/shared/utils/object.d.ts +71 -0
- package/dist/shared/utils/object.d.ts.map +1 -0
- package/dist/shared/utils/object.js +284 -0
- package/dist/shared/utils/object.js.map +1 -0
- package/dist/shared/utils/path.d.ts +59 -0
- package/dist/shared/utils/path.d.ts.map +1 -0
- package/dist/shared/utils/path.js +201 -0
- package/dist/shared/utils/path.js.map +1 -0
- package/dist/shared/utils/string.d.ts +74 -0
- package/dist/shared/utils/string.d.ts.map +1 -0
- package/dist/shared/utils/string.js +201 -0
- package/dist/shared/utils/string.js.map +1 -0
- package/package.json +81 -0
|
@@ -0,0 +1,656 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 設計模式重構器
|
|
3
|
+
* 提供常見設計模式的自動重構功能
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 設計模式分析器
|
|
7
|
+
* 分析程式碼並建議適用的設計模式
|
|
8
|
+
*/
|
|
9
|
+
export class DesignPatternAnalyzer {
|
|
10
|
+
/**
|
|
11
|
+
* 分析程式碼並建議設計模式
|
|
12
|
+
*/
|
|
13
|
+
analyzeSuggestions(code) {
|
|
14
|
+
const suggestions = [];
|
|
15
|
+
const classes = this.parseClasses(code);
|
|
16
|
+
// 分析各種設計模式的適用性
|
|
17
|
+
suggestions.push(...this.analyzeSingleton(classes, code));
|
|
18
|
+
suggestions.push(...this.analyzeFactory(classes, code));
|
|
19
|
+
suggestions.push(...this.analyzeObserver(classes, code));
|
|
20
|
+
suggestions.push(...this.analyzeStrategy(classes, code));
|
|
21
|
+
suggestions.push(...this.analyzeDecorator(classes, code));
|
|
22
|
+
// 按置信度排序
|
|
23
|
+
return suggestions.sort((a, b) => b.confidence - a.confidence);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 分析 Singleton 模式適用性
|
|
27
|
+
*/
|
|
28
|
+
analyzeSingleton(classes, code) {
|
|
29
|
+
const suggestions = [];
|
|
30
|
+
for (const cls of classes) {
|
|
31
|
+
let confidence = 0;
|
|
32
|
+
const reasons = [];
|
|
33
|
+
// 檢查是否有靜態實例屬性
|
|
34
|
+
const hasStaticInstance = cls.properties.some(p => p.isStatic && p.name.includes('instance'));
|
|
35
|
+
if (hasStaticInstance) {
|
|
36
|
+
confidence += 0.4;
|
|
37
|
+
}
|
|
38
|
+
// 檢查是否有 getInstance 方法
|
|
39
|
+
const hasGetInstance = cls.methods.some(m => m.name === 'getInstance' && m.isStatic);
|
|
40
|
+
if (hasGetInstance) {
|
|
41
|
+
confidence += 0.5;
|
|
42
|
+
reasons.push('已有 getInstance 方法,建議完善 Singleton 實作');
|
|
43
|
+
}
|
|
44
|
+
// 檢查建構子是否私有
|
|
45
|
+
const hasPrivateConstructor = cls.constructor?.isPrivate;
|
|
46
|
+
if (hasPrivateConstructor) {
|
|
47
|
+
confidence += 0.3;
|
|
48
|
+
}
|
|
49
|
+
// 檢查是否全域使用
|
|
50
|
+
const globalUsageCount = (code.match(new RegExp(cls.name, 'g')) || []).length;
|
|
51
|
+
if (globalUsageCount > 5) {
|
|
52
|
+
confidence += 0.2;
|
|
53
|
+
reasons.push('類別被廣泛使用,適合 Singleton 模式');
|
|
54
|
+
}
|
|
55
|
+
// 檢查是否有 static config 或類似管理狀態的屬性
|
|
56
|
+
if (cls.properties.some(p => p.isStatic && (p.name.includes('config') || p.name.includes('Config')))) {
|
|
57
|
+
confidence += 0.3;
|
|
58
|
+
reasons.push('有靜態配置管理,適合 Singleton 模式');
|
|
59
|
+
}
|
|
60
|
+
// 檢查 loadConfig 或類似方法
|
|
61
|
+
if (cls.methods.some(m => m.isStatic && m.name.toLowerCase().includes('load'))) {
|
|
62
|
+
confidence += 0.3;
|
|
63
|
+
reasons.push('有靜態載入方法,適合 Singleton 模式');
|
|
64
|
+
}
|
|
65
|
+
if (confidence >= 0.5) {
|
|
66
|
+
suggestions.push({
|
|
67
|
+
pattern: 'singleton',
|
|
68
|
+
confidence,
|
|
69
|
+
reason: reasons.join(', ') || '類別結構適合 Singleton 模式',
|
|
70
|
+
location: cls.location,
|
|
71
|
+
benefits: [
|
|
72
|
+
'確保全域只有一個實例',
|
|
73
|
+
'提供全域存取點',
|
|
74
|
+
'懶載入實例化'
|
|
75
|
+
],
|
|
76
|
+
effort: 'low'
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return suggestions;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* 分析 Factory 模式適用性
|
|
84
|
+
*/
|
|
85
|
+
analyzeFactory(classes, code) {
|
|
86
|
+
const suggestions = [];
|
|
87
|
+
// 查找創建對象的函式
|
|
88
|
+
const createMethods = code.match(/function\s+create\w*|\.create\w*/g) || [];
|
|
89
|
+
const switchCreation = code.match(/switch\s*\([^)]*\)\s*{[^}]*new\s+\w+/g) || [];
|
|
90
|
+
if (createMethods.length > 2 || switchCreation.length > 0) {
|
|
91
|
+
suggestions.push({
|
|
92
|
+
pattern: 'factory',
|
|
93
|
+
confidence: 0.7,
|
|
94
|
+
reason: '發現多個創建函式或條件式物件創建',
|
|
95
|
+
location: { start: { line: 1, column: 0 }, end: { line: 1, column: 0 } },
|
|
96
|
+
benefits: [
|
|
97
|
+
'封裝物件創建邏輯',
|
|
98
|
+
'減少程式碼重複',
|
|
99
|
+
'易於擴展新類型'
|
|
100
|
+
],
|
|
101
|
+
effort: 'medium'
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return suggestions;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* 分析 Observer 模式適用性
|
|
108
|
+
*/
|
|
109
|
+
analyzeObserver(classes, code) {
|
|
110
|
+
const suggestions = [];
|
|
111
|
+
// 查找事件相關代碼
|
|
112
|
+
const eventPatterns = [
|
|
113
|
+
/addEventListener|on\w+|emit|trigger/g,
|
|
114
|
+
/callback|listener|observer/g,
|
|
115
|
+
/notify|update|subscribe/g
|
|
116
|
+
];
|
|
117
|
+
let eventScore = 0;
|
|
118
|
+
for (const pattern of eventPatterns) {
|
|
119
|
+
const matches = code.match(pattern) || [];
|
|
120
|
+
eventScore += matches.length;
|
|
121
|
+
}
|
|
122
|
+
if (eventScore >= 5) {
|
|
123
|
+
suggestions.push({
|
|
124
|
+
pattern: 'observer',
|
|
125
|
+
confidence: Math.min(0.8, eventScore / 10),
|
|
126
|
+
reason: '發現大量事件相關程式碼',
|
|
127
|
+
location: { start: { line: 1, column: 0 }, end: { line: 1, column: 0 } },
|
|
128
|
+
benefits: [
|
|
129
|
+
'鬆耦合的事件處理',
|
|
130
|
+
'動態新增/移除監聽器',
|
|
131
|
+
'更好的可測試性'
|
|
132
|
+
],
|
|
133
|
+
effort: 'medium'
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
return suggestions;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* 分析 Strategy 模式適用性
|
|
140
|
+
*/
|
|
141
|
+
analyzeStrategy(classes, code) {
|
|
142
|
+
const suggestions = [];
|
|
143
|
+
// 查找策略相關模式
|
|
144
|
+
const strategyIndicators = [
|
|
145
|
+
/if\s*\([^)]*type[^)]*\)|switch\s*\([^)]*type[^)]*\)/g,
|
|
146
|
+
/algorithm|strategy|method/gi,
|
|
147
|
+
/calculate|process|handle/gi
|
|
148
|
+
];
|
|
149
|
+
let strategyScore = 0;
|
|
150
|
+
for (const pattern of strategyIndicators) {
|
|
151
|
+
const matches = code.match(pattern) || [];
|
|
152
|
+
strategyScore += matches.length;
|
|
153
|
+
}
|
|
154
|
+
// 查找大型 if-else 鏈或 switch 語句
|
|
155
|
+
const largeConditionals = code.match(/if\s*\([^{]*\)\s*{[^}]{50,}}\s*else/g) || [];
|
|
156
|
+
const largeSwitches = code.match(/switch\s*\([^{]*\)\s*{[^}]{100,}}/g) || [];
|
|
157
|
+
if (strategyScore >= 3 || largeConditionals.length > 0 || largeSwitches.length > 0) {
|
|
158
|
+
suggestions.push({
|
|
159
|
+
pattern: 'strategy',
|
|
160
|
+
confidence: 0.6,
|
|
161
|
+
reason: '發現複雜的條件邏輯或演算法選擇',
|
|
162
|
+
location: { start: { line: 1, column: 0 }, end: { line: 1, column: 0 } },
|
|
163
|
+
benefits: [
|
|
164
|
+
'將演算法封裝成獨立類別',
|
|
165
|
+
'運行時切換演算法',
|
|
166
|
+
'符合開放封閉原則'
|
|
167
|
+
],
|
|
168
|
+
effort: 'high'
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
return suggestions;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* 分析 Decorator 模式適用性
|
|
175
|
+
*/
|
|
176
|
+
analyzeDecorator(classes, code) {
|
|
177
|
+
const suggestions = [];
|
|
178
|
+
// 查找裝飾器相關模式
|
|
179
|
+
const decoratorPatterns = [
|
|
180
|
+
/@\w+/g, // 註解/裝飾器語法
|
|
181
|
+
/wrap|decorator|enhance/gi,
|
|
182
|
+
/before|after|around/gi
|
|
183
|
+
];
|
|
184
|
+
let decoratorScore = 0;
|
|
185
|
+
for (const pattern of decoratorPatterns) {
|
|
186
|
+
const matches = code.match(pattern) || [];
|
|
187
|
+
decoratorScore += matches.length;
|
|
188
|
+
}
|
|
189
|
+
if (decoratorScore >= 3) {
|
|
190
|
+
suggestions.push({
|
|
191
|
+
pattern: 'decorator',
|
|
192
|
+
confidence: 0.5,
|
|
193
|
+
reason: '發現裝飾器或包裝器模式的使用',
|
|
194
|
+
location: { start: { line: 1, column: 0 }, end: { line: 1, column: 0 } },
|
|
195
|
+
benefits: [
|
|
196
|
+
'動態新增物件功能',
|
|
197
|
+
'避免繼承爆炸',
|
|
198
|
+
'遵循單一職責原則'
|
|
199
|
+
],
|
|
200
|
+
effort: 'medium'
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
return suggestions;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* 簡化的類別解析
|
|
207
|
+
*/
|
|
208
|
+
parseClasses(code) {
|
|
209
|
+
const classes = [];
|
|
210
|
+
const classMatches = code.matchAll(/class\s+(\w+)[^{]*{([^}]*)}/g);
|
|
211
|
+
for (const match of classMatches) {
|
|
212
|
+
const className = match[1];
|
|
213
|
+
const classBody = match[2];
|
|
214
|
+
const methods = this.parseMethods(classBody);
|
|
215
|
+
const properties = this.parseProperties(classBody);
|
|
216
|
+
classes.push({
|
|
217
|
+
name: className,
|
|
218
|
+
location: this.getMatchLocation(code, match),
|
|
219
|
+
methods,
|
|
220
|
+
properties,
|
|
221
|
+
constructor: methods.find(m => m.name === 'constructor')
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
return classes;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* 解析方法
|
|
228
|
+
*/
|
|
229
|
+
parseMethods(classBody) {
|
|
230
|
+
const methods = [];
|
|
231
|
+
const methodMatches = classBody.matchAll(/(static\s+)?(private\s+)?(\w+)\s*\(([^)]*)\)/g);
|
|
232
|
+
for (const match of methodMatches) {
|
|
233
|
+
const isStatic = !!match[1];
|
|
234
|
+
const isPrivate = !!match[2];
|
|
235
|
+
const name = match[3];
|
|
236
|
+
const params = match[4] ? match[4].split(',').map(p => p.trim()) : [];
|
|
237
|
+
methods.push({
|
|
238
|
+
name,
|
|
239
|
+
location: { start: { line: 1, column: 0 }, end: { line: 1, column: 0 } },
|
|
240
|
+
parameters: params,
|
|
241
|
+
isStatic,
|
|
242
|
+
isPrivate
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
return methods;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* 解析屬性
|
|
249
|
+
*/
|
|
250
|
+
parseProperties(classBody) {
|
|
251
|
+
const properties = [];
|
|
252
|
+
const propMatches = classBody.matchAll(/(static\s+)?(private\s+)?(\w+)\s*[=:]/g);
|
|
253
|
+
for (const match of propMatches) {
|
|
254
|
+
const isStatic = !!match[1];
|
|
255
|
+
const isPrivate = !!match[2];
|
|
256
|
+
const name = match[3];
|
|
257
|
+
properties.push({
|
|
258
|
+
name,
|
|
259
|
+
location: { start: { line: 1, column: 0 }, end: { line: 1, column: 0 } },
|
|
260
|
+
isPrivate,
|
|
261
|
+
isStatic
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
return properties;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* 獲取匹配位置
|
|
268
|
+
*/
|
|
269
|
+
getMatchLocation(code, match) {
|
|
270
|
+
const start = match.index || 0;
|
|
271
|
+
const end = start + match[0].length;
|
|
272
|
+
return {
|
|
273
|
+
start: this.offsetToPosition(code, start),
|
|
274
|
+
end: this.offsetToPosition(code, end)
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* 偏移量轉位置
|
|
279
|
+
*/
|
|
280
|
+
offsetToPosition(code, offset) {
|
|
281
|
+
const lines = code.substring(0, offset).split('\n');
|
|
282
|
+
return {
|
|
283
|
+
line: lines.length,
|
|
284
|
+
column: lines[lines.length - 1].length
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* 設計模式重構器主類
|
|
290
|
+
*/
|
|
291
|
+
export class DesignPatternRefactorer {
|
|
292
|
+
analyzer = new DesignPatternAnalyzer();
|
|
293
|
+
/**
|
|
294
|
+
* 應用設計模式重構
|
|
295
|
+
*/
|
|
296
|
+
async applyPattern(code, pattern, className, config = {
|
|
297
|
+
generateTests: false,
|
|
298
|
+
addDocumentation: true,
|
|
299
|
+
useTypeScript: true,
|
|
300
|
+
preserveComments: true
|
|
301
|
+
}) {
|
|
302
|
+
// 輸入驗證
|
|
303
|
+
if (!code || !pattern || !className) {
|
|
304
|
+
return {
|
|
305
|
+
success: false,
|
|
306
|
+
pattern: pattern || 'unknown',
|
|
307
|
+
edits: [],
|
|
308
|
+
modifiedClasses: [],
|
|
309
|
+
errors: ['輸入參數無效'],
|
|
310
|
+
warnings: []
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
try {
|
|
314
|
+
switch (pattern) {
|
|
315
|
+
case 'singleton':
|
|
316
|
+
return await this.applySingletonPattern(code, className, config);
|
|
317
|
+
case 'factory':
|
|
318
|
+
return await this.applyFactoryPattern(code, className, config);
|
|
319
|
+
case 'observer':
|
|
320
|
+
return await this.applyObserverPattern(code, className, config);
|
|
321
|
+
case 'strategy':
|
|
322
|
+
return await this.applyStrategyPattern(code, className, config);
|
|
323
|
+
case 'decorator':
|
|
324
|
+
return await this.applyDecoratorPattern(code, className, config);
|
|
325
|
+
default:
|
|
326
|
+
throw new Error(`不支援的設計模式: ${pattern}`);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
catch (error) {
|
|
330
|
+
return {
|
|
331
|
+
success: false,
|
|
332
|
+
pattern,
|
|
333
|
+
edits: [],
|
|
334
|
+
modifiedClasses: [],
|
|
335
|
+
errors: [error instanceof Error ? error.message : '未知錯誤'],
|
|
336
|
+
warnings: []
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* 應用 Singleton 模式
|
|
342
|
+
*/
|
|
343
|
+
async applySingletonPattern(code, className, config) {
|
|
344
|
+
const edits = [];
|
|
345
|
+
// 找到類別定義 - 使用更準確的正則表達式
|
|
346
|
+
// 使用遞迴匹配來處理嵌套的大括號
|
|
347
|
+
const classPattern = `class\\s+${className}[^{]*{`;
|
|
348
|
+
const classStartMatch = code.match(new RegExp(classPattern));
|
|
349
|
+
if (!classStartMatch) {
|
|
350
|
+
throw new Error(`找不到類別: ${className}`);
|
|
351
|
+
}
|
|
352
|
+
// 找到類別的完整內容(包含嵌套的大括號)
|
|
353
|
+
const classStartIndex = code.indexOf(classStartMatch[0]);
|
|
354
|
+
let braceCount = 1;
|
|
355
|
+
let classEndIndex = classStartIndex + classStartMatch[0].length;
|
|
356
|
+
while (braceCount > 0 && classEndIndex < code.length) {
|
|
357
|
+
if (code[classEndIndex] === '{') {
|
|
358
|
+
braceCount++;
|
|
359
|
+
}
|
|
360
|
+
if (code[classEndIndex] === '}') {
|
|
361
|
+
braceCount--;
|
|
362
|
+
}
|
|
363
|
+
classEndIndex++;
|
|
364
|
+
}
|
|
365
|
+
const classBody = code.substring(classStartIndex + classStartMatch[0].length, classEndIndex - 1);
|
|
366
|
+
const singletonCode = this.generateSingletonCode(className, classBody, config);
|
|
367
|
+
// 替換整個類別
|
|
368
|
+
const classStart = classStartIndex;
|
|
369
|
+
const classEnd = classEndIndex;
|
|
370
|
+
edits.push({
|
|
371
|
+
range: {
|
|
372
|
+
start: this.offsetToPosition(code, classStart),
|
|
373
|
+
end: this.offsetToPosition(code, classEnd)
|
|
374
|
+
},
|
|
375
|
+
newText: singletonCode,
|
|
376
|
+
type: 'replace'
|
|
377
|
+
});
|
|
378
|
+
return {
|
|
379
|
+
success: true,
|
|
380
|
+
pattern: 'singleton',
|
|
381
|
+
edits,
|
|
382
|
+
modifiedClasses: [className],
|
|
383
|
+
errors: [],
|
|
384
|
+
warnings: [],
|
|
385
|
+
documentation: config.addDocumentation ? this.generateSingletonDocumentation(className) : undefined
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* 生成 Singleton 程式碼
|
|
390
|
+
*/
|
|
391
|
+
generateSingletonCode(className, originalBody, config) {
|
|
392
|
+
const typescript = config.useTypeScript;
|
|
393
|
+
const instanceType = typescript ? `: ${className} | null` : '';
|
|
394
|
+
// 修正:static 關鍵字應該在屬性前,而不是型別前
|
|
395
|
+
return `${config.addDocumentation ? `/**\n * ${className} - Singleton 模式實作\n * 確保全域只有一個實例\n */\n` : ''}class ${className} {
|
|
396
|
+
private static instance${instanceType} = null;
|
|
397
|
+
|
|
398
|
+
private constructor() {
|
|
399
|
+
${this.extractConstructorBody(originalBody)}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
public static getInstance()${typescript ? `: ${className}` : ''} {
|
|
403
|
+
if (!${className}.instance) {
|
|
404
|
+
${className}.instance = new ${className}();
|
|
405
|
+
}
|
|
406
|
+
return ${className}.instance;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
${this.extractMethodsAndProperties(originalBody)}
|
|
410
|
+
}`;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* 應用 Factory 模式
|
|
414
|
+
*/
|
|
415
|
+
async applyFactoryPattern(code, className, config) {
|
|
416
|
+
const factoryCode = this.generateFactoryCode(className, config);
|
|
417
|
+
const createdFiles = [{
|
|
418
|
+
path: `${className}Factory.${config.useTypeScript ? 'ts' : 'js'}`,
|
|
419
|
+
content: factoryCode
|
|
420
|
+
}];
|
|
421
|
+
return {
|
|
422
|
+
success: true,
|
|
423
|
+
pattern: 'factory',
|
|
424
|
+
edits: [],
|
|
425
|
+
createdFiles,
|
|
426
|
+
modifiedClasses: [],
|
|
427
|
+
errors: [],
|
|
428
|
+
warnings: ['建議重構現有的物件創建邏輯使用 Factory'],
|
|
429
|
+
documentation: config.addDocumentation ? this.generateFactoryDocumentation(className) : undefined
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* 生成 Factory 程式碼
|
|
434
|
+
*/
|
|
435
|
+
generateFactoryCode(className, config) {
|
|
436
|
+
return `${config.addDocumentation ? `/**\n * ${className} Factory - 工廠模式實作\n * 封裝物件創建邏輯\n */\n` : ''}class ${className}Factory {
|
|
437
|
+
static create(type${config.useTypeScript ? ': string' : ''})${config.useTypeScript ? `: ${className}` : ''} {
|
|
438
|
+
switch (type) {
|
|
439
|
+
case 'default':
|
|
440
|
+
return new ${className}();
|
|
441
|
+
// 新增更多類型...
|
|
442
|
+
default:
|
|
443
|
+
throw new Error(\`不支援的類型: \${type}\`);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}`;
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* 應用 Observer 模式
|
|
450
|
+
*/
|
|
451
|
+
async applyObserverPattern(code, className, config) {
|
|
452
|
+
const observerCode = this.generateObserverCode(className, config);
|
|
453
|
+
const createdFiles = [
|
|
454
|
+
{
|
|
455
|
+
path: `Observer.${config.useTypeScript ? 'ts' : 'js'}`,
|
|
456
|
+
content: observerCode.observerInterface
|
|
457
|
+
},
|
|
458
|
+
{
|
|
459
|
+
path: `Observable.${config.useTypeScript ? 'ts' : 'js'}`,
|
|
460
|
+
content: observerCode.observableClass
|
|
461
|
+
}
|
|
462
|
+
];
|
|
463
|
+
return {
|
|
464
|
+
success: true,
|
|
465
|
+
pattern: 'observer',
|
|
466
|
+
edits: [],
|
|
467
|
+
createdFiles,
|
|
468
|
+
modifiedClasses: [],
|
|
469
|
+
errors: [],
|
|
470
|
+
warnings: ['需要手動實作 Observer 介面和修改現有事件處理'],
|
|
471
|
+
documentation: config.addDocumentation ? this.generateObserverDocumentation() : undefined
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* 生成 Observer 模式程式碼
|
|
476
|
+
*/
|
|
477
|
+
generateObserverCode(className, config) {
|
|
478
|
+
const typescript = config.useTypeScript;
|
|
479
|
+
const observerInterface = typescript ?
|
|
480
|
+
'interface Observer {\n update(data: any): void;\n}' :
|
|
481
|
+
'// Observer interface\n// Implement update(data) method';
|
|
482
|
+
const observableClass = `${config.addDocumentation ? '/**\n * Observable - 觀察者模式主題\n * 管理觀察者列表並通知變更\n */\n' : ''}class Observable {
|
|
483
|
+
private observers${typescript ? ': Observer[]' : ''} = [];
|
|
484
|
+
|
|
485
|
+
addObserver(observer${typescript ? ': Observer' : ''})${typescript ? ': void' : ''} {
|
|
486
|
+
this.observers.push(observer);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
removeObserver(observer${typescript ? ': Observer' : ''})${typescript ? ': void' : ''} {
|
|
490
|
+
const index = this.observers.indexOf(observer);
|
|
491
|
+
if (index > -1) {
|
|
492
|
+
this.observers.splice(index, 1);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
notifyObservers(data${typescript ? ': any' : ''})${typescript ? ': void' : ''} {
|
|
497
|
+
this.observers.forEach(observer => observer.update(data));
|
|
498
|
+
}
|
|
499
|
+
}`;
|
|
500
|
+
return { observerInterface, observableClass };
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* 應用 Strategy 模式
|
|
504
|
+
*/
|
|
505
|
+
async applyStrategyPattern(code, className, config) {
|
|
506
|
+
const strategyCode = this.generateStrategyCode(className, config);
|
|
507
|
+
const createdFiles = [
|
|
508
|
+
{
|
|
509
|
+
path: `Strategy.${config.useTypeScript ? 'ts' : 'js'}`,
|
|
510
|
+
content: strategyCode.strategyInterface
|
|
511
|
+
},
|
|
512
|
+
{
|
|
513
|
+
path: `${className}Context.${config.useTypeScript ? 'ts' : 'js'}`,
|
|
514
|
+
content: strategyCode.contextClass
|
|
515
|
+
}
|
|
516
|
+
];
|
|
517
|
+
return {
|
|
518
|
+
success: true,
|
|
519
|
+
pattern: 'strategy',
|
|
520
|
+
edits: [],
|
|
521
|
+
createdFiles,
|
|
522
|
+
modifiedClasses: [],
|
|
523
|
+
errors: [],
|
|
524
|
+
warnings: ['需要將現有的演算法邏輯重構為獨立的策略類別'],
|
|
525
|
+
documentation: config.addDocumentation ? this.generateStrategyDocumentation() : undefined
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* 生成 Strategy 模式程式碼
|
|
530
|
+
*/
|
|
531
|
+
generateStrategyCode(className, config) {
|
|
532
|
+
const typescript = config.useTypeScript;
|
|
533
|
+
const strategyInterface = typescript ?
|
|
534
|
+
'interface Strategy {\n execute(data: any): any;\n}' :
|
|
535
|
+
'// Strategy interface\n// Implement execute(data) method';
|
|
536
|
+
const contextClass = `${config.addDocumentation ? `/**\n * ${className}Context - 策略模式上下文\n * 使用策略物件執行演算法\n */\n` : ''}class ${className}Context {
|
|
537
|
+
private strategy${typescript ? ': Strategy' : ''};
|
|
538
|
+
|
|
539
|
+
constructor(strategy${typescript ? ': Strategy' : ''}) {
|
|
540
|
+
this.strategy = strategy;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
setStrategy(strategy${typescript ? ': Strategy' : ''})${typescript ? ': void' : ''} {
|
|
544
|
+
this.strategy = strategy;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
executeStrategy(data${typescript ? ': any' : ''})${typescript ? ': any' : ''} {
|
|
548
|
+
return this.strategy.execute(data);
|
|
549
|
+
}
|
|
550
|
+
}`;
|
|
551
|
+
return { strategyInterface, contextClass };
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* 應用 Decorator 模式
|
|
555
|
+
*/
|
|
556
|
+
async applyDecoratorPattern(code, className, config) {
|
|
557
|
+
// Decorator 模式實作相對複雜,這裡提供基本架構
|
|
558
|
+
return {
|
|
559
|
+
success: false,
|
|
560
|
+
pattern: 'decorator',
|
|
561
|
+
edits: [],
|
|
562
|
+
modifiedClasses: [],
|
|
563
|
+
errors: ['Decorator 模式需要更詳細的需求分析'],
|
|
564
|
+
warnings: ['建議先分析具體的裝飾需求再實作']
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* 取得設計模式建議
|
|
569
|
+
*/
|
|
570
|
+
async getSuggestions(code) {
|
|
571
|
+
return this.analyzer.analyzeSuggestions(code);
|
|
572
|
+
}
|
|
573
|
+
// 輔助方法
|
|
574
|
+
extractConstructorBody(classBody) {
|
|
575
|
+
// 找到 constructor 並提取其內容
|
|
576
|
+
const constructorStart = classBody.indexOf('constructor');
|
|
577
|
+
if (constructorStart === -1) {
|
|
578
|
+
return '// 建構子邏輯';
|
|
579
|
+
}
|
|
580
|
+
// 找到 constructor 的開始大括號
|
|
581
|
+
const braceStart = classBody.indexOf('{', constructorStart);
|
|
582
|
+
if (braceStart === -1) {
|
|
583
|
+
return '// 建構子邏輯';
|
|
584
|
+
}
|
|
585
|
+
// 找到對應的結束大括號
|
|
586
|
+
let braceCount = 1;
|
|
587
|
+
let braceEnd = braceStart + 1;
|
|
588
|
+
while (braceCount > 0 && braceEnd < classBody.length) {
|
|
589
|
+
if (classBody[braceEnd] === '{') {
|
|
590
|
+
braceCount++;
|
|
591
|
+
}
|
|
592
|
+
if (classBody[braceEnd] === '}') {
|
|
593
|
+
braceCount--;
|
|
594
|
+
}
|
|
595
|
+
braceEnd++;
|
|
596
|
+
}
|
|
597
|
+
const constructorBody = classBody.substring(braceStart + 1, braceEnd - 1).trim();
|
|
598
|
+
return constructorBody || '// 建構子邏輯';
|
|
599
|
+
}
|
|
600
|
+
extractMethodsAndProperties(classBody) {
|
|
601
|
+
// 找到並移除 constructor
|
|
602
|
+
const constructorStart = classBody.indexOf('constructor');
|
|
603
|
+
if (constructorStart === -1) {
|
|
604
|
+
// 沒有 constructor,返回整個類別體
|
|
605
|
+
return classBody.trim();
|
|
606
|
+
}
|
|
607
|
+
// 找到 constructor 的結束位置
|
|
608
|
+
const braceStart = classBody.indexOf('{', constructorStart);
|
|
609
|
+
if (braceStart === -1) {
|
|
610
|
+
return classBody.trim();
|
|
611
|
+
}
|
|
612
|
+
let braceCount = 1;
|
|
613
|
+
let braceEnd = braceStart + 1;
|
|
614
|
+
while (braceCount > 0 && braceEnd < classBody.length) {
|
|
615
|
+
if (classBody[braceEnd] === '{') {
|
|
616
|
+
braceCount++;
|
|
617
|
+
}
|
|
618
|
+
if (classBody[braceEnd] === '}') {
|
|
619
|
+
braceCount--;
|
|
620
|
+
}
|
|
621
|
+
braceEnd++;
|
|
622
|
+
}
|
|
623
|
+
// 移除 constructor 並保留其餘部分
|
|
624
|
+
const beforeConstructor = classBody.substring(0, constructorStart).trim();
|
|
625
|
+
const afterConstructor = classBody.substring(braceEnd).trim();
|
|
626
|
+
let result = '';
|
|
627
|
+
if (beforeConstructor) {
|
|
628
|
+
result += beforeConstructor + '\n\n ';
|
|
629
|
+
}
|
|
630
|
+
if (afterConstructor) {
|
|
631
|
+
result += afterConstructor;
|
|
632
|
+
}
|
|
633
|
+
return result.trim();
|
|
634
|
+
}
|
|
635
|
+
offsetToPosition(code, offset) {
|
|
636
|
+
const lines = code.substring(0, offset).split('\n');
|
|
637
|
+
return {
|
|
638
|
+
line: lines.length,
|
|
639
|
+
column: lines[lines.length - 1].length
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
// 文件生成方法
|
|
643
|
+
generateSingletonDocumentation(className) {
|
|
644
|
+
return `# ${className} Singleton 模式\n\n## 使用方式\n\`\`\`javascript\nconst instance = ${className}.getInstance();\n\`\`\`\n\n## 特點\n- 全域唯一實例\n- 懶載入初始化\n- 執行緒安全(在單執行緒環境)`;
|
|
645
|
+
}
|
|
646
|
+
generateFactoryDocumentation(className) {
|
|
647
|
+
return `# ${className} Factory 模式\n\n## 使用方式\n\`\`\`javascript\nconst obj = ${className}Factory.create('default');\n\`\`\`\n\n## 特點\n- 封裝物件創建\n- 易於擴展類型\n- 降低耦合度`;
|
|
648
|
+
}
|
|
649
|
+
generateObserverDocumentation() {
|
|
650
|
+
return '# Observer 模式\n\n## 使用方式\n```javascript\nconst observable = new Observable();\nobservable.addObserver(myObserver);\nobservable.notifyObservers(data);\n```\n\n## 特點\n- 鬆耦合設計\n- 動態訂閱\n- 一對多通知';
|
|
651
|
+
}
|
|
652
|
+
generateStrategyDocumentation() {
|
|
653
|
+
return '# Strategy 模式\n\n## 使用方式\n```javascript\nconst context = new Context(new ConcreteStrategy());\nconst result = context.executeStrategy(data);\n```\n\n## 特點\n- 演算法封裝\n- 運行時切換\n- 開放封閉原則';
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
//# sourceMappingURL=design-patterns.js.map
|