11import type * as CommandExecutor from "@effect/platform/CommandExecutor"
22import type { PlatformError } from "@effect/platform/Error"
3- import * as FileSystem from "@effect/platform/FileSystem"
4- import * as Path from "@effect/platform/Path"
3+ import type * as FileSystem from "@effect/platform/FileSystem"
4+ import type * as Path from "@effect/platform/Path"
55import { Duration , Effect , Fiber , Schedule } from "effect"
66
77import type { CreateCommand } from "../../core/domain.js"
@@ -12,14 +12,12 @@ import {
1212 runDockerComposeUpRecreate ,
1313 runDockerExecExitCode ,
1414 runDockerInspectContainerBridgeIp ,
15- runDockerInspectContainerIp ,
1615 runDockerNetworkConnectBridge
1716} from "../../shell/docker.js"
1817import type { DockerCommandError } from "../../shell/errors.js"
1918import { AgentFailedError , CloneFailedError } from "../../shell/errors.js"
2019import { ensureComposeNetworkReady } from "../docker-network-gc.js"
21- import { findSshPrivateKey , resolveAuthorizedKeysPath } from "../path-helpers.js"
22- import { buildSshCommand } from "../projects.js"
20+ import { formatEditorSshAccessDetails , resolveProjectSshAccess } from "../ssh-access.js"
2321
2422const maxPortAttempts = 25
2523const clonePollInterval = Duration . seconds ( 1 )
@@ -34,33 +32,14 @@ const logSshAccess = (
3432 config : CreateCommand [ "config" ]
3533) : Effect . Effect < void , PlatformError , FileSystem . FileSystem | Path . Path | CommandExecutor . CommandExecutor > =>
3634 Effect . gen ( function * ( _ ) {
37- const fs = yield * _ ( FileSystem . FileSystem )
38- const path = yield * _ ( Path . Path )
35+ const access = yield * _ ( resolveProjectSshAccess ( baseDir , config ) )
3936
40- const isInsideContainer = yield * _ ( fs . exists ( "/.dockerenv" ) )
41- let ipAddress : string | undefined
42-
43- if ( isInsideContainer ) {
44- const containerIp = yield * _ (
45- runDockerInspectContainerIp ( baseDir , config . containerName ) . pipe (
46- Effect . orElse ( ( ) => Effect . succeed ( "" ) )
47- )
48- )
49- if ( containerIp . length > 0 ) {
50- ipAddress = containerIp
51- }
52- }
53-
54- const resolvedAuthorizedKeys = resolveAuthorizedKeysPath ( path , baseDir , config . authorizedKeysPath )
55- const authExists = yield * _ ( fs . exists ( resolvedAuthorizedKeys ) )
56- const sshKey = yield * _ ( findSshPrivateKey ( fs , path , process . cwd ( ) ) )
57- const sshCommand = buildSshCommand ( config , sshKey , ipAddress )
58-
59- yield * _ ( Effect . log ( `SSH access: ${ sshCommand } ` ) )
60- if ( ! authExists ) {
37+ yield * _ ( Effect . log ( `SSH access: ${ access . sshCommand } ` ) )
38+ yield * _ ( Effect . log ( formatEditorSshAccessDetails ( access . editor , config . clonedOnHostname ) ) )
39+ if ( ! access . authorizedKeysExists ) {
6140 yield * _ (
6241 Effect . logWarning (
63- `Authorized keys file missing: ${ resolvedAuthorizedKeys } (SSH may fail without a matching key).`
42+ `Authorized keys file missing: ${ access . authorizedKeysPath } (SSH may fail without a matching key).`
6443 )
6544 )
6645 }
0 commit comments