@@ -23,7 +23,7 @@ import { renderError } from "../errors.js"
2323import { applyGithubForkConfig } from "../github-fork.js"
2424import { defaultProjectsRoot } from "../menu-helpers.js"
2525import { findSshPrivateKey } from "../path-helpers.js"
26- import { buildSshCommand } from "../projects-core.js"
26+ import { buildSshCommand , getContainerIpIfInsideContainer } from "../projects-core.js"
2727import { resolveTemplateResourceLimits } from "../resource-limits.js"
2828import { autoSyncState } from "../state-repo.js"
2929import { ensureTerminalCursorVisible } from "../terminal-cursor.js"
@@ -97,8 +97,11 @@ const isInteractiveTty = (): boolean => process.stdin.isTTY && process.stdout.is
9797const buildSshArgs = (
9898 config : CreateCommand [ "config" ] ,
9999 sshKeyPath : string | null ,
100- remoteCommand ?: string
100+ remoteCommand ?: string ,
101+ ipAddress ?: string
101102) : ReadonlyArray < string > => {
103+ const host = ipAddress ?? "localhost"
104+ const port = ipAddress ? 22 : config . sshPort
102105 const args : Array < string > = [ ]
103106 if ( sshKeyPath !== null ) {
104107 args . push ( "-i" , sshKeyPath )
@@ -113,8 +116,8 @@ const buildSshArgs = (
113116 "-o" ,
114117 "UserKnownHostsFile=/dev/null" ,
115118 "-p" ,
116- String ( config . sshPort ) ,
117- `${ config . sshUser } @localhost `
119+ String ( port ) ,
120+ `${ config . sshUser } @${ host } `
118121 )
119122 if ( remoteCommand !== undefined ) {
120123 args . push ( remoteCommand )
@@ -140,8 +143,14 @@ const openSshBestEffort = (
140143 const fs = yield * _ ( FileSystem . FileSystem )
141144 const path = yield * _ ( Path . Path )
142145
146+ const ipAddress = yield * _ (
147+ getContainerIpIfInsideContainer ( fs , process . cwd ( ) , template . containerName ) . pipe (
148+ Effect . orElse ( ( ) => Effect . succeed < string | undefined > ( "" ) )
149+ )
150+ )
151+
143152 const sshKey = yield * _ ( findSshPrivateKey ( fs , path , process . cwd ( ) ) )
144- const sshCommand = buildSshCommand ( template , sshKey )
153+ const sshCommand = buildSshCommand ( template , sshKey , ipAddress )
145154
146155 const remoteCommandLabel = remoteCommand === undefined ? "" : ` (${ remoteCommand } )`
147156
@@ -152,7 +161,7 @@ const openSshBestEffort = (
152161 {
153162 cwd : process . cwd ( ) ,
154163 command : "ssh" ,
155- args : buildSshArgs ( template , sshKey , remoteCommand )
164+ args : buildSshArgs ( template , sshKey , remoteCommand , ipAddress )
156165 } ,
157166 [ 0 , 130 ] ,
158167 ( exitCode ) => new CommandFailedError ( { command : "ssh" , exitCode } )
0 commit comments