synapse-mcp 1.0.0 → 1.0.2
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 +1820 -147
- package/dist/constants.d.ts +10 -4
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +18 -8
- package/dist/constants.js.map +1 -1
- package/dist/events/emitter.d.ts +63 -0
- package/dist/events/emitter.d.ts.map +1 -0
- package/dist/events/emitter.js +112 -0
- package/dist/events/emitter.js.map +1 -0
- package/dist/events/index.d.ts +3 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +3 -0
- package/dist/events/index.js.map +1 -0
- package/dist/events/types.d.ts +51 -0
- package/dist/events/types.d.ts.map +1 -0
- package/dist/events/types.js +3 -0
- package/dist/events/types.js.map +1 -0
- package/dist/formatters/compose.d.ts +185 -0
- package/dist/formatters/compose.d.ts.map +1 -0
- package/dist/formatters/compose.js +397 -0
- package/dist/formatters/compose.js.map +1 -0
- package/dist/formatters/container.d.ts +84 -0
- package/dist/formatters/container.d.ts.map +1 -0
- package/dist/formatters/container.js +323 -0
- package/dist/formatters/container.js.map +1 -0
- package/dist/formatters/diagnostics.d.ts +20 -0
- package/dist/formatters/diagnostics.d.ts.map +1 -0
- package/dist/formatters/diagnostics.js +73 -0
- package/dist/formatters/diagnostics.js.map +1 -0
- package/dist/formatters/docker.d.ts +139 -0
- package/dist/formatters/docker.d.ts.map +1 -0
- package/dist/formatters/docker.js +216 -0
- package/dist/formatters/docker.js.map +1 -0
- package/dist/formatters/host.d.ts +137 -0
- package/dist/formatters/host.d.ts.map +1 -0
- package/dist/formatters/host.js +198 -0
- package/dist/formatters/host.js.map +1 -0
- package/dist/formatters/index.d.ts +17 -270
- package/dist/formatters/index.d.ts.map +1 -1
- package/dist/formatters/index.js +21 -456
- package/dist/formatters/index.js.map +1 -1
- package/dist/formatters/scout.d.ts +424 -0
- package/dist/formatters/scout.d.ts.map +1 -0
- package/dist/formatters/scout.js +687 -0
- package/dist/formatters/scout.js.map +1 -0
- package/dist/formatters/strategy.d.ts +105 -0
- package/dist/formatters/strategy.d.ts.map +1 -0
- package/dist/formatters/strategy.js +120 -0
- package/dist/formatters/strategy.js.map +1 -0
- package/dist/formatters/utils.d.ts +84 -0
- package/dist/formatters/utils.d.ts.map +1 -0
- package/dist/formatters/utils.js +129 -0
- package/dist/formatters/utils.js.map +1 -0
- package/dist/health-rate-limiter.d.ts +59 -0
- package/dist/health-rate-limiter.d.ts.map +1 -0
- package/dist/health-rate-limiter.js +159 -0
- package/dist/health-rate-limiter.js.map +1 -0
- package/dist/index.js +61 -100
- package/dist/index.js.map +1 -1
- package/dist/middleware/async-handler.d.ts +62 -0
- package/dist/middleware/async-handler.d.ts.map +1 -0
- package/dist/middleware/async-handler.js +58 -0
- package/dist/middleware/async-handler.js.map +1 -0
- package/dist/middleware/auth.d.ts +32 -0
- package/dist/middleware/auth.d.ts.map +1 -0
- package/dist/middleware/auth.js +63 -0
- package/dist/middleware/auth.js.map +1 -0
- package/dist/middleware/csrf-protection.d.ts +58 -0
- package/dist/middleware/csrf-protection.d.ts.map +1 -0
- package/dist/middleware/csrf-protection.js +123 -0
- package/dist/middleware/csrf-protection.js.map +1 -0
- package/dist/middleware/error-handler.d.ts +49 -0
- package/dist/middleware/error-handler.d.ts.map +1 -0
- package/dist/middleware/error-handler.js +90 -0
- package/dist/middleware/error-handler.js.map +1 -0
- package/dist/middleware/error-mapper.d.ts +44 -0
- package/dist/middleware/error-mapper.d.ts.map +1 -0
- package/dist/middleware/error-mapper.js +127 -0
- package/dist/middleware/error-mapper.js.map +1 -0
- package/dist/middleware/index.d.ts +13 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +13 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/middleware/request-id.d.ts +22 -0
- package/dist/middleware/request-id.d.ts.map +1 -0
- package/dist/middleware/request-id.js +31 -0
- package/dist/middleware/request-id.js.map +1 -0
- package/dist/middleware/types.d.ts +33 -0
- package/dist/middleware/types.d.ts.map +1 -0
- package/dist/middleware/types.js +2 -0
- package/dist/middleware/types.js.map +1 -0
- package/dist/schemas/common.d.ts +205 -8
- package/dist/schemas/common.d.ts.map +1 -1
- package/dist/schemas/common.js +290 -17
- package/dist/schemas/common.js.map +1 -1
- package/dist/schemas/flux/compose.d.ts +307 -44
- package/dist/schemas/flux/compose.d.ts.map +1 -1
- package/dist/schemas/flux/compose.js +74 -48
- package/dist/schemas/flux/compose.js.map +1 -1
- package/dist/schemas/flux/container.d.ts +423 -56
- package/dist/schemas/flux/container.d.ts.map +1 -1
- package/dist/schemas/flux/container.js +83 -61
- package/dist/schemas/flux/container.js.map +1 -1
- package/dist/schemas/flux/docker.d.ts +254 -37
- package/dist/schemas/flux/docker.d.ts.map +1 -1
- package/dist/schemas/flux/docker.js +69 -39
- package/dist/schemas/flux/docker.js.map +1 -1
- package/dist/schemas/flux/host.d.ts +312 -29
- package/dist/schemas/flux/host.d.ts.map +1 -1
- package/dist/schemas/flux/host.js +74 -31
- package/dist/schemas/flux/host.js.map +1 -1
- package/dist/schemas/flux/index.d.ts +503 -11
- package/dist/schemas/flux/index.d.ts.map +1 -1
- package/dist/schemas/flux/index.js +34 -70
- package/dist/schemas/flux/index.js.map +1 -1
- package/dist/schemas/host-config.d.ts +76 -0
- package/dist/schemas/host-config.d.ts.map +1 -0
- package/dist/schemas/host-config.js +105 -0
- package/dist/schemas/host-config.js.map +1 -0
- package/dist/schemas/scout/index.d.ts +80 -23
- package/dist/schemas/scout/index.d.ts.map +1 -1
- package/dist/schemas/scout/index.js +26 -11
- package/dist/schemas/scout/index.js.map +1 -1
- package/dist/schemas/scout/logs.d.ts +17 -5
- package/dist/schemas/scout/logs.d.ts.map +1 -1
- package/dist/schemas/scout/logs.js +41 -31
- package/dist/schemas/scout/logs.js.map +1 -1
- package/dist/schemas/scout/simple.d.ts +126 -11
- package/dist/schemas/scout/simple.d.ts.map +1 -1
- package/dist/schemas/scout/simple.js +112 -57
- package/dist/schemas/scout/simple.js.map +1 -1
- package/dist/schemas/scout/zfs.d.ts +17 -5
- package/dist/schemas/scout/zfs.d.ts.map +1 -1
- package/dist/schemas/scout/zfs.js +34 -25
- package/dist/schemas/scout/zfs.js.map +1 -1
- package/dist/services/cache-layer.d.ts +160 -0
- package/dist/services/cache-layer.d.ts.map +1 -0
- package/dist/services/cache-layer.js +138 -0
- package/dist/services/cache-layer.js.map +1 -0
- package/dist/services/compose-cache.d.ts +75 -0
- package/dist/services/compose-cache.d.ts.map +1 -0
- package/dist/services/compose-cache.js +178 -0
- package/dist/services/compose-cache.js.map +1 -0
- package/dist/services/compose-discovery.d.ts +46 -0
- package/dist/services/compose-discovery.d.ts.map +1 -0
- package/dist/services/compose-discovery.js +219 -0
- package/dist/services/compose-discovery.js.map +1 -0
- package/dist/services/compose-project-lister.d.ts +27 -0
- package/dist/services/compose-project-lister.d.ts.map +1 -0
- package/dist/services/compose-project-lister.js +71 -0
- package/dist/services/compose-project-lister.js.map +1 -0
- package/dist/services/compose-scanner.d.ts +63 -0
- package/dist/services/compose-scanner.d.ts.map +1 -0
- package/dist/services/compose-scanner.js +253 -0
- package/dist/services/compose-scanner.js.map +1 -0
- package/dist/services/compose.d.ts +64 -28
- package/dist/services/compose.d.ts.map +1 -1
- package/dist/services/compose.js +220 -98
- package/dist/services/compose.js.map +1 -1
- package/dist/services/config-loader.d.ts +23 -0
- package/dist/services/config-loader.d.ts.map +1 -0
- package/dist/services/config-loader.js +124 -0
- package/dist/services/config-loader.js.map +1 -0
- package/dist/services/config-service.d.ts +38 -0
- package/dist/services/config-service.d.ts.map +1 -0
- package/dist/services/config-service.js +225 -0
- package/dist/services/config-service.js.map +1 -0
- package/dist/services/container-host-map-cache.d.ts +121 -0
- package/dist/services/container-host-map-cache.d.ts.map +1 -0
- package/dist/services/container-host-map-cache.js +188 -0
- package/dist/services/container-host-map-cache.js.map +1 -0
- package/dist/services/container.d.ts +194 -6
- package/dist/services/container.d.ts.map +1 -1
- package/dist/services/container.js +386 -11
- package/dist/services/container.js.map +1 -1
- package/dist/services/diagnostics.d.ts +57 -0
- package/dist/services/diagnostics.d.ts.map +1 -0
- package/dist/services/diagnostics.js +271 -0
- package/dist/services/diagnostics.js.map +1 -0
- package/dist/services/docker/container-service.d.ts +123 -0
- package/dist/services/docker/container-service.d.ts.map +1 -0
- package/dist/services/docker/container-service.js +347 -0
- package/dist/services/docker/container-service.js.map +1 -0
- package/dist/services/docker/image-service.d.ts +82 -0
- package/dist/services/docker/image-service.d.ts.map +1 -0
- package/dist/services/docker/image-service.js +193 -0
- package/dist/services/docker/image-service.js.map +1 -0
- package/dist/services/docker/index.d.ts +80 -0
- package/dist/services/docker/index.d.ts.map +1 -0
- package/dist/services/docker/index.js +103 -0
- package/dist/services/docker/index.js.map +1 -0
- package/dist/services/docker/network-service.d.ts +22 -0
- package/dist/services/docker/network-service.d.ts.map +1 -0
- package/dist/services/docker/network-service.js +43 -0
- package/dist/services/docker/network-service.js.map +1 -0
- package/dist/services/docker/system-service.d.ts +49 -0
- package/dist/services/docker/system-service.d.ts.map +1 -0
- package/dist/services/docker/system-service.js +215 -0
- package/dist/services/docker/system-service.js.map +1 -0
- package/dist/services/docker/utils/client-factory.d.ts +56 -0
- package/dist/services/docker/utils/client-factory.d.ts.map +1 -0
- package/dist/services/docker/utils/client-factory.js +139 -0
- package/dist/services/docker/utils/client-factory.js.map +1 -0
- package/dist/services/docker/utils/client-manager.d.ts +88 -0
- package/dist/services/docker/utils/client-manager.d.ts.map +1 -0
- package/dist/services/docker/utils/client-manager.js +124 -0
- package/dist/services/docker/utils/client-manager.js.map +1 -0
- package/dist/services/docker/utils/exec-handler.d.ts +94 -0
- package/dist/services/docker/utils/exec-handler.d.ts.map +1 -0
- package/dist/services/docker/utils/exec-handler.js +197 -0
- package/dist/services/docker/utils/exec-handler.js.map +1 -0
- package/dist/services/docker/utils/formatters.d.ts +13 -0
- package/dist/services/docker/utils/formatters.d.ts.map +1 -0
- package/dist/services/docker/utils/formatters.js +33 -0
- package/dist/services/docker/utils/formatters.js.map +1 -0
- package/dist/services/docker/utils/log-parser.d.ts +10 -0
- package/dist/services/docker/utils/log-parser.d.ts.map +1 -0
- package/dist/services/docker/utils/log-parser.js +48 -0
- package/dist/services/docker/utils/log-parser.js.map +1 -0
- package/dist/services/docker/utils/stats-calculator.d.ts +68 -0
- package/dist/services/docker/utils/stats-calculator.d.ts.map +1 -0
- package/dist/services/docker/utils/stats-calculator.js +61 -0
- package/dist/services/docker/utils/stats-calculator.js.map +1 -0
- package/dist/services/docker/volume-service.d.ts +22 -0
- package/dist/services/docker/volume-service.d.ts.map +1 -0
- package/dist/services/docker/volume-service.js +48 -0
- package/dist/services/docker/volume-service.js.map +1 -0
- package/dist/services/docker-interfaces.d.ts +283 -0
- package/dist/services/docker-interfaces.d.ts.map +1 -0
- package/dist/services/docker-interfaces.js +13 -0
- package/dist/services/docker-interfaces.js.map +1 -0
- package/dist/services/docker.d.ts +42 -5
- package/dist/services/docker.d.ts.map +1 -1
- package/dist/services/docker.js +335 -127
- package/dist/services/docker.js.map +1 -1
- package/dist/services/file-service.d.ts +6 -2
- package/dist/services/file-service.d.ts.map +1 -1
- package/dist/services/file-service.js +156 -52
- package/dist/services/file-service.js.map +1 -1
- package/dist/services/host-config-repository.d.ts +133 -0
- package/dist/services/host-config-repository.d.ts.map +1 -0
- package/dist/services/host-config-repository.js +323 -0
- package/dist/services/host-config-repository.js.map +1 -0
- package/dist/services/host-resolver.d.ts +49 -0
- package/dist/services/host-resolver.d.ts.map +1 -0
- package/dist/services/host-resolver.js +176 -0
- package/dist/services/host-resolver.js.map +1 -0
- package/dist/services/interfaces.d.ts +61 -194
- package/dist/services/interfaces.d.ts.map +1 -1
- package/dist/services/local-executor.d.ts +31 -0
- package/dist/services/local-executor.d.ts.map +1 -0
- package/dist/services/local-executor.js +71 -0
- package/dist/services/local-executor.js.map +1 -0
- package/dist/services/ssh-config-loader.d.ts +35 -0
- package/dist/services/ssh-config-loader.d.ts.map +1 -0
- package/dist/services/ssh-config-loader.js +218 -0
- package/dist/services/ssh-config-loader.js.map +1 -0
- package/dist/services/ssh-pool.d.ts +26 -1
- package/dist/services/ssh-pool.d.ts.map +1 -1
- package/dist/services/ssh-pool.js +166 -25
- package/dist/services/ssh-pool.js.map +1 -1
- package/dist/services/ssh-service.d.ts +3 -0
- package/dist/services/ssh-service.d.ts.map +1 -1
- package/dist/services/ssh-service.js +53 -31
- package/dist/services/ssh-service.js.map +1 -1
- package/dist/services/ssh.d.ts +2 -6
- package/dist/services/ssh.d.ts.map +1 -1
- package/dist/services/ssh.js +9 -40
- package/dist/services/ssh.js.map +1 -1
- package/dist/tools/definitions/flux.d.ts +13 -0
- package/dist/tools/definitions/flux.d.ts.map +1 -0
- package/dist/tools/definitions/flux.js +101 -0
- package/dist/tools/definitions/flux.js.map +1 -0
- package/dist/tools/definitions/index.d.ts +8 -0
- package/dist/tools/definitions/index.d.ts.map +1 -0
- package/dist/tools/definitions/index.js +8 -0
- package/dist/tools/definitions/index.js.map +1 -0
- package/dist/tools/definitions/scout.d.ts +13 -0
- package/dist/tools/definitions/scout.d.ts.map +1 -0
- package/dist/tools/definitions/scout.js +78 -0
- package/dist/tools/definitions/scout.js.map +1 -0
- package/dist/tools/flux.d.ts +16 -8
- package/dist/tools/flux.d.ts.map +1 -1
- package/dist/tools/flux.js +27 -66
- package/dist/tools/flux.js.map +1 -1
- package/dist/tools/handlers/base-handler.d.ts +172 -0
- package/dist/tools/handlers/base-handler.d.ts.map +1 -0
- package/dist/tools/handlers/base-handler.js +234 -0
- package/dist/tools/handlers/base-handler.js.map +1 -0
- package/dist/tools/handlers/compose-handlers.d.ts +108 -0
- package/dist/tools/handlers/compose-handlers.d.ts.map +1 -0
- package/dist/tools/handlers/compose-handlers.js +293 -0
- package/dist/tools/handlers/compose-handlers.js.map +1 -0
- package/dist/tools/handlers/compose-utils.d.ts +35 -0
- package/dist/tools/handlers/compose-utils.d.ts.map +1 -0
- package/dist/tools/handlers/compose-utils.js +76 -0
- package/dist/tools/handlers/compose-utils.js.map +1 -0
- package/dist/tools/handlers/compose.d.ts +23 -0
- package/dist/tools/handlers/compose.d.ts.map +1 -0
- package/dist/tools/handlers/compose.js +125 -0
- package/dist/tools/handlers/compose.js.map +1 -0
- package/dist/tools/handlers/container.d.ts +23 -0
- package/dist/tools/handlers/container.d.ts.map +1 -0
- package/dist/tools/handlers/container.js +333 -0
- package/dist/tools/handlers/container.js.map +1 -0
- package/dist/tools/handlers/docker.d.ts +24 -0
- package/dist/tools/handlers/docker.d.ts.map +1 -0
- package/dist/tools/handlers/docker.js +155 -0
- package/dist/tools/handlers/docker.js.map +1 -0
- package/dist/tools/handlers/host.d.ts +23 -0
- package/dist/tools/handlers/host.d.ts.map +1 -0
- package/dist/tools/handlers/host.js +196 -0
- package/dist/tools/handlers/host.js.map +1 -0
- package/dist/tools/handlers/scout-logs.d.ts +24 -0
- package/dist/tools/handlers/scout-logs.d.ts.map +1 -0
- package/dist/tools/handlers/scout-logs.js +119 -0
- package/dist/tools/handlers/scout-logs.js.map +1 -0
- package/dist/tools/handlers/scout-simple.d.ts +23 -0
- package/dist/tools/handlers/scout-simple.d.ts.map +1 -0
- package/dist/tools/handlers/scout-simple.js +286 -0
- package/dist/tools/handlers/scout-simple.js.map +1 -0
- package/dist/tools/handlers/scout-zfs.d.ts +23 -0
- package/dist/tools/handlers/scout-zfs.d.ts.map +1 -0
- package/dist/tools/handlers/scout-zfs.js +82 -0
- package/dist/tools/handlers/scout-zfs.js.map +1 -0
- package/dist/tools/index.d.ts +32 -2
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +41 -35
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/registry.d.ts +135 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +151 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/scout.d.ts +16 -8
- package/dist/tools/scout.d.ts.map +1 -1
- package/dist/tools/scout.js +36 -78
- package/dist/tools/scout.js.map +1 -1
- package/dist/types.d.ts +629 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/command-security.d.ts +82 -0
- package/dist/utils/command-security.d.ts.map +1 -0
- package/dist/utils/command-security.js +122 -0
- package/dist/utils/command-security.js.map +1 -0
- package/dist/utils/error-sanitization.d.ts +77 -0
- package/dist/utils/error-sanitization.d.ts.map +1 -0
- package/dist/utils/error-sanitization.js +107 -0
- package/dist/utils/error-sanitization.js.map +1 -0
- package/dist/utils/errors.d.ts +30 -6
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/errors.js +91 -12
- package/dist/utils/errors.js.map +1 -1
- package/dist/utils/help-handler.d.ts +23 -0
- package/dist/utils/help-handler.d.ts.map +1 -0
- package/dist/utils/help-handler.js +21 -0
- package/dist/utils/help-handler.js.map +1 -0
- package/dist/utils/help.d.ts +1 -1
- package/dist/utils/help.d.ts.map +1 -1
- package/dist/utils/help.js +57 -16
- package/dist/utils/help.js.map +1 -1
- package/dist/utils/host-utils.d.ts +31 -0
- package/dist/utils/host-utils.d.ts.map +1 -0
- package/dist/utils/host-utils.js +80 -0
- package/dist/utils/host-utils.js.map +1 -0
- package/dist/utils/index.d.ts +8 -2
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +8 -2
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/init-detection.d.ts +36 -0
- package/dist/utils/init-detection.d.ts.map +1 -0
- package/dist/utils/init-detection.js +79 -0
- package/dist/utils/init-detection.js.map +1 -0
- package/dist/utils/logger.d.ts +11 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +32 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/pagination.d.ts +20 -0
- package/dist/utils/pagination.d.ts.map +1 -0
- package/dist/utils/pagination.js +29 -0
- package/dist/utils/pagination.js.map +1 -0
- package/dist/utils/path-security.d.ts +132 -18
- package/dist/utils/path-security.d.ts.map +1 -1
- package/dist/utils/path-security.js +164 -35
- package/dist/utils/path-security.js.map +1 -1
- package/dist/utils/sorting.d.ts +33 -0
- package/dist/utils/sorting.d.ts.map +1 -0
- package/dist/utils/sorting.js +57 -0
- package/dist/utils/sorting.js.map +1 -0
- package/dist/utils/text-filters.d.ts +13 -0
- package/dist/utils/text-filters.d.ts.map +1 -0
- package/dist/utils/text-filters.js +18 -0
- package/dist/utils/text-filters.js.map +1 -0
- package/dist/utils/time.d.ts +11 -0
- package/dist/utils/time.d.ts.map +1 -0
- package/dist/utils/time.js +13 -0
- package/dist/utils/time.js.map +1 -0
- package/dist/utils/validation.d.ts +25 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +56 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +45 -19
- package/dist/schemas/discriminator.d.ts +0 -20
- package/dist/schemas/discriminator.d.ts.map +0 -1
- package/dist/schemas/discriminator.js +0 -25
- package/dist/schemas/discriminator.js.map +0 -1
- package/dist/schemas/unified.d.ts +0 -674
- package/dist/schemas/unified.d.ts.map +0 -1
- package/dist/schemas/unified.js +0 -453
- package/dist/schemas/unified.js.map +0 -1
- package/dist/tools/unified.d.ts +0 -7
- package/dist/tools/unified.d.ts.map +0 -1
- package/dist/tools/unified.js +0 -827
- package/dist/tools/unified.js.map +0 -1
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Timeout for host resolution operations.
|
|
3
|
+
* Defaults to 30s, overridable via COMPOSE_HOST_RESOLUTION_TIMEOUT_MS.
|
|
4
|
+
*/
|
|
5
|
+
function getResolutionTimeoutMs() {
|
|
6
|
+
const raw = process.env.COMPOSE_HOST_RESOLUTION_TIMEOUT_MS;
|
|
7
|
+
if (!raw)
|
|
8
|
+
return 30000;
|
|
9
|
+
const parsed = Number.parseInt(raw, 10);
|
|
10
|
+
if (!Number.isFinite(parsed) || parsed <= 0)
|
|
11
|
+
return 30000;
|
|
12
|
+
return parsed;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Grace period (ms) after first match to collect concurrent matches
|
|
16
|
+
* for conflict detection. Defaults to 500ms unless overridden.
|
|
17
|
+
*/
|
|
18
|
+
function getConflictGraceMs() {
|
|
19
|
+
const raw = process.env.COMPOSE_CONFLICT_GRACE_MS;
|
|
20
|
+
if (!raw)
|
|
21
|
+
return 500;
|
|
22
|
+
const parsed = Number.parseInt(raw, 10);
|
|
23
|
+
if (!Number.isFinite(parsed) || parsed < 0)
|
|
24
|
+
return 500;
|
|
25
|
+
return parsed;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Error thrown when host resolution fails
|
|
29
|
+
*/
|
|
30
|
+
export class HostResolutionError extends Error {
|
|
31
|
+
constructor(message) {
|
|
32
|
+
super(message);
|
|
33
|
+
this.name = "HostResolutionError";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Resolves which host contains a compose project when not explicitly specified
|
|
38
|
+
*/
|
|
39
|
+
export class HostResolver {
|
|
40
|
+
discovery;
|
|
41
|
+
hosts;
|
|
42
|
+
constructor(discovery, hosts) {
|
|
43
|
+
this.discovery = discovery;
|
|
44
|
+
this.hosts = hosts;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Resolve which host to use for a compose operation
|
|
48
|
+
*
|
|
49
|
+
* @param projectName - Name of the compose project
|
|
50
|
+
* @param specifiedHost - Optional host name explicitly provided by user
|
|
51
|
+
* @returns The resolved host configuration
|
|
52
|
+
* @throws {HostResolutionError} If resolution fails
|
|
53
|
+
*/
|
|
54
|
+
async resolveHost(projectName, specifiedHost) {
|
|
55
|
+
// If host is specified, validate and return it
|
|
56
|
+
if (specifiedHost) {
|
|
57
|
+
const host = this.hosts.find((h) => h.name === specifiedHost);
|
|
58
|
+
if (!host) {
|
|
59
|
+
throw new HostResolutionError(`Host "${specifiedHost}" not found in configuration`);
|
|
60
|
+
}
|
|
61
|
+
return host;
|
|
62
|
+
}
|
|
63
|
+
// Auto-resolve: check all hosts in parallel
|
|
64
|
+
if (this.hosts.length === 0) {
|
|
65
|
+
throw new HostResolutionError("No hosts configured");
|
|
66
|
+
}
|
|
67
|
+
const matchingHosts = await this.findMatchingHosts(projectName);
|
|
68
|
+
if (matchingHosts.length === 0) {
|
|
69
|
+
throw new HostResolutionError(`Project "${projectName}" not found on any configured host`);
|
|
70
|
+
}
|
|
71
|
+
if (matchingHosts.length > 1) {
|
|
72
|
+
const hostNames = matchingHosts.map((h) => h.name).join(", ");
|
|
73
|
+
throw new HostResolutionError(`Project "${projectName}" found on multiple hosts: ${hostNames}. Please specify which host to use.`);
|
|
74
|
+
}
|
|
75
|
+
return matchingHosts[0];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Find all hosts that contain the specified project.
|
|
79
|
+
*
|
|
80
|
+
* Uses an AbortController to cancel remaining checks on early exit or timeout.
|
|
81
|
+
* SECURITY (CWE-404): Timer is properly cleared when resolution settles
|
|
82
|
+
* to prevent dangling promise rejection and memory leak.
|
|
83
|
+
*/
|
|
84
|
+
async findMatchingHosts(projectName) {
|
|
85
|
+
const resolutionTimeoutMs = getResolutionTimeoutMs();
|
|
86
|
+
const abortController = new AbortController();
|
|
87
|
+
let timeoutId;
|
|
88
|
+
const checkPromise = this.checkAllHosts(projectName, abortController.signal);
|
|
89
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
90
|
+
timeoutId = setTimeout(() => {
|
|
91
|
+
abortController.abort();
|
|
92
|
+
reject(new HostResolutionError(`Host resolution timed out after ${resolutionTimeoutMs}ms`));
|
|
93
|
+
}, resolutionTimeoutMs);
|
|
94
|
+
});
|
|
95
|
+
try {
|
|
96
|
+
const result = await Promise.race([checkPromise, timeoutPromise]);
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
99
|
+
finally {
|
|
100
|
+
abortController.abort();
|
|
101
|
+
if (timeoutId) {
|
|
102
|
+
clearTimeout(timeoutId);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Check all hosts in parallel for the project with early-exit.
|
|
108
|
+
*
|
|
109
|
+
* When the first match arrives, starts a short grace period to collect
|
|
110
|
+
* any near-simultaneous matches (for conflict detection). After the
|
|
111
|
+
* grace period or when all checks settle (whichever is first), resolves
|
|
112
|
+
* with all collected matches.
|
|
113
|
+
*
|
|
114
|
+
* If all checks fail before any match, resolves immediately with
|
|
115
|
+
* an empty array.
|
|
116
|
+
*
|
|
117
|
+
* This avoids blocking on slow/offline hosts while still detecting
|
|
118
|
+
* conflicts between responsive hosts.
|
|
119
|
+
*/
|
|
120
|
+
checkAllHosts(projectName, signal) {
|
|
121
|
+
const matchingHosts = [];
|
|
122
|
+
let settledCount = 0;
|
|
123
|
+
const totalChecks = this.hosts.length;
|
|
124
|
+
const conflictGraceMs = getConflictGraceMs();
|
|
125
|
+
return new Promise((resolve) => {
|
|
126
|
+
if (totalChecks === 0) {
|
|
127
|
+
resolve([]);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
let resolved = false;
|
|
131
|
+
let graceTimeoutId;
|
|
132
|
+
const doResolve = () => {
|
|
133
|
+
if (resolved)
|
|
134
|
+
return;
|
|
135
|
+
resolved = true;
|
|
136
|
+
if (graceTimeoutId) {
|
|
137
|
+
clearTimeout(graceTimeoutId);
|
|
138
|
+
}
|
|
139
|
+
resolve(matchingHosts);
|
|
140
|
+
};
|
|
141
|
+
const startGracePeriod = () => {
|
|
142
|
+
if (graceTimeoutId)
|
|
143
|
+
return; // Already started
|
|
144
|
+
graceTimeoutId = setTimeout(doResolve, conflictGraceMs);
|
|
145
|
+
};
|
|
146
|
+
const tryResolve = () => {
|
|
147
|
+
if (resolved || signal.aborted)
|
|
148
|
+
return;
|
|
149
|
+
settledCount++;
|
|
150
|
+
// All checks settled — no more results possible
|
|
151
|
+
if (settledCount === totalChecks) {
|
|
152
|
+
doResolve();
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
// First match arrived — start grace period for conflict detection
|
|
156
|
+
if (matchingHosts.length >= 1 && !graceTimeoutId) {
|
|
157
|
+
startGracePeriod();
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
for (const host of this.hosts) {
|
|
161
|
+
this.discovery
|
|
162
|
+
.resolveProjectPath(host, projectName)
|
|
163
|
+
.then(() => {
|
|
164
|
+
if (!resolved && !signal.aborted) {
|
|
165
|
+
matchingHosts.push(host);
|
|
166
|
+
}
|
|
167
|
+
tryResolve();
|
|
168
|
+
})
|
|
169
|
+
.catch(() => {
|
|
170
|
+
tryResolve();
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=host-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host-resolver.js","sourceRoot":"","sources":["../../src/services/host-resolver.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,SAAS,sBAAsB;IAC7B,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,kCAAkC,CAAC;IAC3D,IAAI,CAAC,GAAG;QAAE,OAAO,KAAK,CAAC;IAEvB,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IACxC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,MAAM,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IAC1D,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;GAGG;AACH,SAAS,kBAAkB;IACzB,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC;IAClD,IAAI,CAAC,GAAG;QAAE,OAAO,GAAG,CAAC;IAErB,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IACxC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MA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9B,IAAI,CAAC,SAAS;qBACX,kBAAkB,CAAC,IAAI,EAAE,WAAW,CAAC;qBACrC,IAAI,CAAC,GAAG,EAAE;oBACT,IAAI,CAAC,QAAQ,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;wBACjC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;oBAC3B,CAAC;oBACD,UAAU,EAAE,CAAC;gBACf,CAAC,CAAC;qBACD,KAAK,CAAC,GAAG,EAAE;oBACV,UAAU,EAAE,CAAC;gBACf,CAAC,CAAC,CAAC;YACP,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -1,197 +1,9 @@
|
|
|
1
|
-
import type { HostConfig, ContainerInfo, ContainerStats, HostStatus, LogEntry, ImageInfo } from "../types.js";
|
|
2
|
-
import type Docker from "dockerode";
|
|
3
1
|
import type { NodeSSH } from "node-ssh";
|
|
2
|
+
import type { ComposeProject, HostConfig } from "../types.js";
|
|
3
|
+
import type { DockerOperations } from "./docker-interfaces.js";
|
|
4
4
|
import type { HostResources } from "./ssh.js";
|
|
5
|
-
import type { DockerSystemInfo, DockerDiskUsage, PruneResult, ListImagesOptions } from "./docker.js";
|
|
6
5
|
import type { PoolStats } from "./ssh-pool.js";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Docker service interface for managing Docker containers, images, and resources.
|
|
10
|
-
* Provides operations for container lifecycle management, image operations, system queries,
|
|
11
|
-
* and Docker daemon interactions across multiple hosts.
|
|
12
|
-
*/
|
|
13
|
-
export interface IDockerService {
|
|
14
|
-
/**
|
|
15
|
-
* Get a Docker client instance for the specified host configuration.
|
|
16
|
-
* Clients are cached per host to reuse connections.
|
|
17
|
-
*
|
|
18
|
-
* @param config - Host configuration containing connection details
|
|
19
|
-
* @returns Docker client instance (dockerode)
|
|
20
|
-
*/
|
|
21
|
-
getDockerClient(config: HostConfig): Docker;
|
|
22
|
-
/**
|
|
23
|
-
* List containers across multiple hosts with optional filtering.
|
|
24
|
-
*
|
|
25
|
-
* @param hosts - Array of host configurations to query
|
|
26
|
-
* @param options - Filtering options
|
|
27
|
-
* @param options.state - Filter by container state (all, running, stopped, paused)
|
|
28
|
-
* @param options.nameFilter - Filter by container name (partial match)
|
|
29
|
-
* @param options.imageFilter - Filter by image name (partial match)
|
|
30
|
-
* @param options.labelFilter - Filter by label (format: "key=value")
|
|
31
|
-
* @returns Array of containers with their details and host information
|
|
32
|
-
*/
|
|
33
|
-
listContainers(hosts: HostConfig[], options?: {
|
|
34
|
-
state?: "all" | "running" | "stopped" | "paused";
|
|
35
|
-
nameFilter?: string;
|
|
36
|
-
imageFilter?: string;
|
|
37
|
-
labelFilter?: string;
|
|
38
|
-
}): Promise<ContainerInfo[]>;
|
|
39
|
-
/**
|
|
40
|
-
* Perform a lifecycle action on a container.
|
|
41
|
-
*
|
|
42
|
-
* @param containerId - Container ID or name
|
|
43
|
-
* @param action - Action to perform (start, stop, restart, pause, unpause)
|
|
44
|
-
* @param host - Host configuration where container is located
|
|
45
|
-
*/
|
|
46
|
-
containerAction(containerId: string, action: "start" | "stop" | "restart" | "pause" | "unpause", host: HostConfig): Promise<void>;
|
|
47
|
-
/**
|
|
48
|
-
* Retrieve logs from a container.
|
|
49
|
-
*
|
|
50
|
-
* @param containerId - Container ID or name
|
|
51
|
-
* @param host - Host configuration where container is located
|
|
52
|
-
* @param options - Log retrieval options
|
|
53
|
-
* @param options.lines - Number of lines to retrieve (default: 100)
|
|
54
|
-
* @param options.since - Show logs since timestamp or duration (e.g., "2023-01-01T00:00:00Z" or "10m")
|
|
55
|
-
* @param options.until - Show logs until timestamp or duration
|
|
56
|
-
* @param options.stream - Stream to retrieve (all, stdout, stderr)
|
|
57
|
-
* @returns Array of log entries with timestamps and content
|
|
58
|
-
*/
|
|
59
|
-
getContainerLogs(containerId: string, host: HostConfig, options?: {
|
|
60
|
-
lines?: number;
|
|
61
|
-
since?: string;
|
|
62
|
-
until?: string;
|
|
63
|
-
stream?: "all" | "stdout" | "stderr";
|
|
64
|
-
}): Promise<LogEntry[]>;
|
|
65
|
-
/**
|
|
66
|
-
* Get resource usage statistics for a container.
|
|
67
|
-
*
|
|
68
|
-
* @param containerId - Container ID or name
|
|
69
|
-
* @param host - Host configuration where container is located
|
|
70
|
-
* @returns Resource statistics including CPU, memory, network, and I/O
|
|
71
|
-
*/
|
|
72
|
-
getContainerStats(containerId: string, host: HostConfig): Promise<ContainerStats>;
|
|
73
|
-
/**
|
|
74
|
-
* Find which host a container is running on.
|
|
75
|
-
* Searches across all provided hosts.
|
|
76
|
-
*
|
|
77
|
-
* @param containerId - Container ID or name to find
|
|
78
|
-
* @param hosts - Array of host configurations to search
|
|
79
|
-
* @returns Host config and container info if found, null otherwise
|
|
80
|
-
*/
|
|
81
|
-
findContainerHost(containerId: string, hosts: HostConfig[]): Promise<{
|
|
82
|
-
host: HostConfig;
|
|
83
|
-
container: Docker.ContainerInfo;
|
|
84
|
-
} | null>;
|
|
85
|
-
/**
|
|
86
|
-
* Get Docker daemon status and version info for multiple hosts.
|
|
87
|
-
*
|
|
88
|
-
* @param hosts - Array of host configurations to check
|
|
89
|
-
* @returns Array of host statuses with daemon info and reachability
|
|
90
|
-
*/
|
|
91
|
-
getHostStatus(hosts: HostConfig[]): Promise<HostStatus[]>;
|
|
92
|
-
/**
|
|
93
|
-
* List Docker images across multiple hosts with optional filtering.
|
|
94
|
-
*
|
|
95
|
-
* @param hosts - Array of host configurations to query
|
|
96
|
-
* @param options - Filtering options (dangling, reference, etc.)
|
|
97
|
-
* @returns Array of images with their details and host information
|
|
98
|
-
*/
|
|
99
|
-
listImages(hosts: HostConfig[], options?: ListImagesOptions): Promise<ImageInfo[]>;
|
|
100
|
-
/**
|
|
101
|
-
* Get detailed information about a container.
|
|
102
|
-
*
|
|
103
|
-
* @param containerId - Container ID or name
|
|
104
|
-
* @param host - Host configuration where container is located
|
|
105
|
-
* @returns Full container inspection data from Docker API
|
|
106
|
-
*/
|
|
107
|
-
inspectContainer(containerId: string, host: HostConfig): Promise<Docker.ContainerInspectInfo>;
|
|
108
|
-
/**
|
|
109
|
-
* Get Docker daemon system information.
|
|
110
|
-
*
|
|
111
|
-
* @param host - Host configuration to query
|
|
112
|
-
* @returns System info including version, OS, architecture, and resource limits
|
|
113
|
-
*/
|
|
114
|
-
getDockerInfo(host: HostConfig): Promise<DockerSystemInfo>;
|
|
115
|
-
/**
|
|
116
|
-
* Get Docker disk usage information.
|
|
117
|
-
*
|
|
118
|
-
* @param host - Host configuration to query
|
|
119
|
-
* @returns Disk usage breakdown for images, containers, volumes, and build cache
|
|
120
|
-
*/
|
|
121
|
-
getDockerDiskUsage(host: HostConfig): Promise<DockerDiskUsage>;
|
|
122
|
-
/**
|
|
123
|
-
* Remove unused Docker resources (prune operation).
|
|
124
|
-
*
|
|
125
|
-
* @param host - Host configuration where pruning should occur
|
|
126
|
-
* @param target - Resource type to prune (containers, images, volumes, networks, buildcache, all)
|
|
127
|
-
* @returns Array of prune results showing what was removed and space reclaimed
|
|
128
|
-
*/
|
|
129
|
-
pruneDocker(host: HostConfig, target: "containers" | "images" | "volumes" | "networks" | "buildcache" | "all"): Promise<PruneResult[]>;
|
|
130
|
-
/**
|
|
131
|
-
* Pull a Docker image from a registry.
|
|
132
|
-
*
|
|
133
|
-
* @param imageName - Image name with optional tag (e.g., "nginx:latest")
|
|
134
|
-
* @param host - Host configuration where image should be pulled
|
|
135
|
-
* @returns Operation status
|
|
136
|
-
*/
|
|
137
|
-
pullImage(imageName: string, host: HostConfig): Promise<{
|
|
138
|
-
status: string;
|
|
139
|
-
}>;
|
|
140
|
-
/**
|
|
141
|
-
* Recreate a container with the same configuration.
|
|
142
|
-
* Optionally pulls the latest image before recreating.
|
|
143
|
-
*
|
|
144
|
-
* @param containerId - Container ID or name to recreate
|
|
145
|
-
* @param host - Host configuration where container is located
|
|
146
|
-
* @param options - Recreate options
|
|
147
|
-
* @param options.pull - Whether to pull latest image before recreating
|
|
148
|
-
* @returns Operation status and new container ID
|
|
149
|
-
*/
|
|
150
|
-
recreateContainer(containerId: string, host: HostConfig, options?: {
|
|
151
|
-
pull?: boolean;
|
|
152
|
-
}): Promise<{
|
|
153
|
-
status: string;
|
|
154
|
-
containerId: string;
|
|
155
|
-
}>;
|
|
156
|
-
/**
|
|
157
|
-
* Remove a Docker image.
|
|
158
|
-
*
|
|
159
|
-
* @param imageId - Image ID or name to remove
|
|
160
|
-
* @param host - Host configuration where image is located
|
|
161
|
-
* @param options - Removal options
|
|
162
|
-
* @param options.force - Force removal even if image is in use
|
|
163
|
-
* @returns Operation status
|
|
164
|
-
*/
|
|
165
|
-
removeImage(imageId: string, host: HostConfig, options?: {
|
|
166
|
-
force?: boolean;
|
|
167
|
-
}): Promise<{
|
|
168
|
-
status: string;
|
|
169
|
-
}>;
|
|
170
|
-
/**
|
|
171
|
-
* Build a Docker image from a Dockerfile.
|
|
172
|
-
*
|
|
173
|
-
* @param host - Host configuration where build should occur
|
|
174
|
-
* @param options - Build options
|
|
175
|
-
* @param options.context - Path to build context directory
|
|
176
|
-
* @param options.tag - Tag for the built image
|
|
177
|
-
* @param options.dockerfile - Path to Dockerfile (relative to context, default: "Dockerfile")
|
|
178
|
-
* @param options.noCache - Disable build cache
|
|
179
|
-
* @returns Operation status
|
|
180
|
-
*/
|
|
181
|
-
buildImage(host: HostConfig, options: {
|
|
182
|
-
context: string;
|
|
183
|
-
tag: string;
|
|
184
|
-
dockerfile?: string;
|
|
185
|
-
noCache?: boolean;
|
|
186
|
-
}): Promise<{
|
|
187
|
-
status: string;
|
|
188
|
-
}>;
|
|
189
|
-
/**
|
|
190
|
-
* Clear all cached Docker client connections.
|
|
191
|
-
* Useful for cleanup during shutdown or when connections need to be reset.
|
|
192
|
-
*/
|
|
193
|
-
clearClients(): void;
|
|
194
|
-
}
|
|
6
|
+
export type { DockerOperations, IContainerOperations, IDockerClientProvider, IDockerSystemInfo, IImageOperations, IResourceOperations, } from "./docker-interfaces.js";
|
|
195
7
|
/**
|
|
196
8
|
* SSH service interface for executing commands on remote hosts.
|
|
197
9
|
* Provides secure command execution and resource monitoring via SSH connections.
|
|
@@ -225,6 +37,13 @@ export interface ISSHService {
|
|
|
225
37
|
* Provides operations for Compose project lifecycle management, service control,
|
|
226
38
|
* and log retrieval.
|
|
227
39
|
*/
|
|
40
|
+
/**
|
|
41
|
+
* Interface for resolving compose project file paths.
|
|
42
|
+
* Extracted to break the circular dependency between ComposeService and ComposeDiscovery.
|
|
43
|
+
*/
|
|
44
|
+
export interface IComposePathResolver {
|
|
45
|
+
resolveProjectPath(host: HostConfig, projectName: string): Promise<string>;
|
|
46
|
+
}
|
|
228
47
|
export interface IComposeService {
|
|
229
48
|
/**
|
|
230
49
|
* Execute a Docker Compose command on a remote host.
|
|
@@ -392,6 +211,39 @@ export interface ISSHConnectionPool {
|
|
|
392
211
|
* @returns Statistics including active connections, pool size, and usage metrics
|
|
393
212
|
*/
|
|
394
213
|
getStats(): PoolStats;
|
|
214
|
+
/**
|
|
215
|
+
* Get pool health status.
|
|
216
|
+
* Returns whether the pool is healthy based on connection states and health check results.
|
|
217
|
+
*
|
|
218
|
+
* @returns Health status object with healthy flag
|
|
219
|
+
*/
|
|
220
|
+
getHealth(): {
|
|
221
|
+
healthy: boolean;
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Local command executor interface for executing commands on localhost.
|
|
226
|
+
* Provides secure command execution using Node.js child_process for local operations
|
|
227
|
+
* without SSH overhead.
|
|
228
|
+
*/
|
|
229
|
+
export interface ILocalExecutorService {
|
|
230
|
+
/**
|
|
231
|
+
* Execute a command locally using Node.js execFile.
|
|
232
|
+
* Uses execFile (not shell) to prevent command injection.
|
|
233
|
+
*
|
|
234
|
+
* @param command - Command to execute (path or binary name)
|
|
235
|
+
* @param args - Array of command arguments
|
|
236
|
+
* @param options - Execution options
|
|
237
|
+
* @param options.timeoutMs - Command timeout in milliseconds (default: 30000)
|
|
238
|
+
* @param options.cwd - Working directory for command execution
|
|
239
|
+
* @returns Command output as string (stdout, trimmed)
|
|
240
|
+
* @throws Error if command fails (non-zero exit code), times out, or binary not found
|
|
241
|
+
* @note stderr output is included in error messages but does not cause failure by itself
|
|
242
|
+
*/
|
|
243
|
+
executeLocalCommand(command: string, args?: string[], options?: {
|
|
244
|
+
timeoutMs?: number;
|
|
245
|
+
cwd?: string;
|
|
246
|
+
}): Promise<string>;
|
|
395
247
|
}
|
|
396
248
|
/**
|
|
397
249
|
* Service factory interface for creating service instances with dependency injection.
|
|
@@ -404,7 +256,7 @@ export interface IServiceFactory {
|
|
|
404
256
|
*
|
|
405
257
|
* @returns Docker service instance
|
|
406
258
|
*/
|
|
407
|
-
createDockerService():
|
|
259
|
+
createDockerService(): DockerOperations;
|
|
408
260
|
/**
|
|
409
261
|
* Create an SSH connection pool instance.
|
|
410
262
|
*
|
|
@@ -423,14 +275,22 @@ export interface IServiceFactory {
|
|
|
423
275
|
* @returns SSH service instance
|
|
424
276
|
*/
|
|
425
277
|
createSSHService(pool: ISSHConnectionPool): ISSHService;
|
|
278
|
+
/**
|
|
279
|
+
* Create a local executor service instance.
|
|
280
|
+
* Local executor runs commands on localhost without SSH.
|
|
281
|
+
*
|
|
282
|
+
* @returns Local executor service instance
|
|
283
|
+
*/
|
|
284
|
+
createLocalExecutor(): ILocalExecutorService;
|
|
426
285
|
/**
|
|
427
286
|
* Create a Docker Compose service instance.
|
|
428
|
-
* Compose service requires SSH service for
|
|
287
|
+
* Compose service requires SSH service for remote commands and local executor for local commands.
|
|
429
288
|
*
|
|
430
289
|
* @param sshService - SSH service to use for remote command execution
|
|
290
|
+
* @param localExecutor - Local executor service for local command execution
|
|
431
291
|
* @returns Compose service instance
|
|
432
292
|
*/
|
|
433
|
-
createComposeService(sshService: ISSHService): IComposeService;
|
|
293
|
+
createComposeService(sshService: ISSHService, localExecutor: ILocalExecutorService): IComposeService;
|
|
434
294
|
/**
|
|
435
295
|
* Create a File service instance.
|
|
436
296
|
* File service requires SSH service for remote file operations.
|
|
@@ -534,4 +394,11 @@ export interface IFileService {
|
|
|
534
394
|
*/
|
|
535
395
|
diffFiles(host1: HostConfig, path1: string, host2: HostConfig, path2: string, contextLines: number): Promise<string>;
|
|
536
396
|
}
|
|
397
|
+
/**
|
|
398
|
+
* Minimal interface for listing compose projects
|
|
399
|
+
* Used by ComposeDiscovery to avoid circular dependency with ComposeService
|
|
400
|
+
*/
|
|
401
|
+
export interface IComposeProjectLister {
|
|
402
|
+
listComposeProjects(host: HostConfig): Promise<ComposeProject[]>;
|
|
403
|
+
}
|
|
537
404
|
//# sourceMappingURL=interfaces.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../src/services/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../src/services/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG/C,YAAY,EACV,gBAAgB,EAChB,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,wBAAwB,CAAC;AAEhC;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;;;;;;;OAUG;IACH,iBAAiB,CACf,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,MAAM,EAAE,EACf,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,G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CACP,KAAK,EAAE,UAAU,EACjB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,UAAU,EACjB,KAAK,EAAE,MAAM,EACb,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,MAAM,CAAC,CAAC;CACpB;AAED;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,mBAAmB,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;CAClE"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ILocalExecutorService } from "./interfaces.js";
|
|
2
|
+
/**
|
|
3
|
+
* Options for local command execution
|
|
4
|
+
*/
|
|
5
|
+
export interface LocalCommandOptions {
|
|
6
|
+
timeoutMs?: number;
|
|
7
|
+
cwd?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* LocalExecutorService implementation for executing commands on localhost.
|
|
11
|
+
* Uses Node.js execFile for secure command execution without shell interpretation.
|
|
12
|
+
*
|
|
13
|
+
* SECURITY: Uses execFile (not exec) to prevent shell injection attacks.
|
|
14
|
+
* Command and arguments are passed separately, preventing metacharacter interpretation.
|
|
15
|
+
*/
|
|
16
|
+
export declare class LocalExecutorService implements ILocalExecutorService {
|
|
17
|
+
/**
|
|
18
|
+
* Execute a command locally using Node.js execFile
|
|
19
|
+
*
|
|
20
|
+
* SECURITY: Uses execFile which does NOT invoke a shell, preventing command injection.
|
|
21
|
+
* Arguments are passed as array elements, not concatenated strings.
|
|
22
|
+
*
|
|
23
|
+
* @param command - Command to execute (binary name or path)
|
|
24
|
+
* @param args - Command arguments (each element is a separate argument)
|
|
25
|
+
* @param options - Execution options (timeout, cwd)
|
|
26
|
+
* @returns Command stdout (trimmed)
|
|
27
|
+
* @throws Error if command fails, times out, or binary not found
|
|
28
|
+
*/
|
|
29
|
+
executeLocalCommand(command: string, args?: string[], options?: LocalCommandOptions): Promise<string>;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=local-executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-executor.d.ts","sourceRoot":"","sources":["../../src/services/local-executor.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAI7D;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;;;;;GAMG;AACH,qBAAa,oBAAqB,YAAW,qBAAqB;IAChE;;;;;;;;;;;OAWG;IACG,mBAAmB,CACvB,OAAO,EAAE,MAAM,EACf,IAAI,GAAE,MAAM,EAAO,EACnB,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,MAAM,CAAC;CAgEnB"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
const execFileAsync = promisify(execFile);
|
|
4
|
+
/**
|
|
5
|
+
* LocalExecutorService implementation for executing commands on localhost.
|
|
6
|
+
* Uses Node.js execFile for secure command execution without shell interpretation.
|
|
7
|
+
*
|
|
8
|
+
* SECURITY: Uses execFile (not exec) to prevent shell injection attacks.
|
|
9
|
+
* Command and arguments are passed separately, preventing metacharacter interpretation.
|
|
10
|
+
*/
|
|
11
|
+
export class LocalExecutorService {
|
|
12
|
+
/**
|
|
13
|
+
* Execute a command locally using Node.js execFile
|
|
14
|
+
*
|
|
15
|
+
* SECURITY: Uses execFile which does NOT invoke a shell, preventing command injection.
|
|
16
|
+
* Arguments are passed as array elements, not concatenated strings.
|
|
17
|
+
*
|
|
18
|
+
* @param command - Command to execute (binary name or path)
|
|
19
|
+
* @param args - Command arguments (each element is a separate argument)
|
|
20
|
+
* @param options - Execution options (timeout, cwd)
|
|
21
|
+
* @returns Command stdout (trimmed)
|
|
22
|
+
* @throws Error if command fails, times out, or binary not found
|
|
23
|
+
*/
|
|
24
|
+
async executeLocalCommand(command, args = [], options = {}) {
|
|
25
|
+
const timeoutMs = options.timeoutMs ?? 30000;
|
|
26
|
+
if (!command || command.trim() === "") {
|
|
27
|
+
throw new Error("Command cannot be empty");
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
// execFile does NOT use shell - args are passed directly to the binary
|
|
31
|
+
// This prevents injection: echo "foo; rm -rf /" becomes literal string, not executed
|
|
32
|
+
const { stdout } = await execFileAsync(command, args, {
|
|
33
|
+
timeout: timeoutMs,
|
|
34
|
+
cwd: options.cwd,
|
|
35
|
+
maxBuffer: 10 * 1024 * 1024, // 10MB max output
|
|
36
|
+
encoding: "utf8",
|
|
37
|
+
// IMPORTANT: no shell option - we want execFile's default behavior (no shell)
|
|
38
|
+
shell: false,
|
|
39
|
+
});
|
|
40
|
+
// execFile can succeed with stderr output in some cases
|
|
41
|
+
// We only fail on non-zero exit codes (handled by execFile rejection)
|
|
42
|
+
return stdout.trim();
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
// Type guard for Error objects
|
|
46
|
+
if (error instanceof Error) {
|
|
47
|
+
// execFile throws with code property on command errors
|
|
48
|
+
const execError = error;
|
|
49
|
+
// Handle timeout or forced termination
|
|
50
|
+
// killed=true indicates process was forcibly terminated
|
|
51
|
+
// SIGTERM is graceful termination, SIGKILL is forced termination
|
|
52
|
+
if (execError.killed || execError.signal === "SIGTERM" || execError.signal === "SIGKILL") {
|
|
53
|
+
throw new Error(`Local command timeout after ${timeoutMs}ms: ${command} ${args.join(" ")}`, { cause: error });
|
|
54
|
+
}
|
|
55
|
+
// Handle command not found
|
|
56
|
+
if (execError.code === "ENOENT") {
|
|
57
|
+
throw new Error(`Command not found: ${command}`, { cause: error });
|
|
58
|
+
}
|
|
59
|
+
// Handle command execution failure with context
|
|
60
|
+
const argsStr = args.length > 0 ? ` ${args.join(" ")}` : "";
|
|
61
|
+
const stderrInfo = execError.stderr ? `\nStderr: ${execError.stderr}` : "";
|
|
62
|
+
throw new Error(`Local command failed: ${command}${argsStr}${stderrInfo}\nOriginal error: ${error.message}`, { cause: error });
|
|
63
|
+
}
|
|
64
|
+
// Non-Error exceptions (rare) - preserve original error as cause
|
|
65
|
+
throw new Error(`Local command execution failed: ${String(error)}`, {
|
|
66
|
+
cause: error,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=local-executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-executor.js","sourceRoot":"","sources":["../../src/services/local-executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGtC,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAU1C;;;;;;GAMG;AACH,MAAM,OAAO,oBAAoB;IAC/B;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,mBAAmB,CACvB,OAAe,EACf,OAAiB,EAAE,EACnB,UAA+B,EAAE;QAEjC,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,KAAK,CAAC;QAE7C,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YACtC,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAC7C,CAAC;QAED,IAAI,CAAC;YACH,uEAAuE;YACvE,qFAAqF;YACrF,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,aAAa,CAAC,OAAO,EAAE,IAAI,EAAE;gBACpD,OAAO,EAAE,SAAS;gBAClB,GAAG,EAAE,OAAO,CAAC,GAAG;gBAChB,SAAS,EAAE,EAAE,GAAG,IAAI,GAAG,IAAI,EAAE,kBAAkB;gBAC/C,QAAQ,EAAE,MAAM;gBAChB,8EAA8E;gBAC9E,KAAK,EAAE,KAAK;aACb,CAAC,CAAC;YAEH,wDAAwD;Y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M,CAAC,KAAK,CAAC,EAAE,EAAE;gBAClE,KAAK,EAAE,KAAK;aACb,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { HostConfig } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Load host configurations from SSH config file
|
|
4
|
+
*
|
|
5
|
+
* @param configPath - Path to SSH config file (defaults to ~/.ssh/config)
|
|
6
|
+
* @returns Promise resolving to array of HostConfig objects parsed from SSH config
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const hosts = await loadFromSSHConfig("~/.ssh/config");
|
|
11
|
+
* // Returns: [{ name: "server1", host: "192.168.1.100", protocol: "ssh", ... }]
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare function loadFromSSHConfig(configPath?: string): Promise<HostConfig[]>;
|
|
15
|
+
/**
|
|
16
|
+
* Merge host configurations with manual config taking precedence
|
|
17
|
+
*
|
|
18
|
+
* Manual hosts completely replace SSH config hosts with the same name.
|
|
19
|
+
* No property merging - manual config is used as-is.
|
|
20
|
+
*
|
|
21
|
+
* @param sshConfigHosts - Hosts loaded from SSH config
|
|
22
|
+
* @param manualHosts - Hosts from manual configuration (config file or env var)
|
|
23
|
+
* @returns Merged array with manual hosts taking precedence
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const sshHosts = [{ name: "server1", host: "192.168.1.100", protocol: "ssh" }];
|
|
28
|
+
* const manualHosts = [{ name: "server1", host: "10.0.0.100", protocol: "http" }];
|
|
29
|
+
* const merged = mergeHostConfigs(sshHosts, manualHosts);
|
|
30
|
+
* // Result: [{ name: "server1", host: "10.0.0.100", protocol: "http" }]
|
|
31
|
+
* // Manual config completely replaces SSH config
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function mergeHostConfigs(sshConfigHosts: HostConfig[], manualHosts: HostConfig[]): HostConfig[];
|
|
35
|
+
//# sourceMappingURL=ssh-config-loader.d.ts.map
|