Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(ssh-project): tilde-expand ~ in remote cwd/listDir paths

enesc5b7b28eff70
diff --git a/src/main/remote-ssh/control-master.test.ts b/src/main/remote-ssh/control-master.test.ts
index 67573d55e..f4eb7374a 100644
--- a/src/main/remote-ssh/control-master.test.ts
+++ b/src/main/remote-ssh/control-master.test.ts
@@ -54,11 +54,25 @@ describe('remoteTmuxHasSessionArgs', () => {
})
describe('listDirArgs', () => {
- it('lists directory entries of a quoted path', () => {
+ it('lists directory entries of a quoted absolute path', () => {
expect(listDirArgs(conn, '/s.sock', '/srv/app')).toEqual([
'-o', 'ControlMaster=no', '-o', 'ControlPath=/s.sock', '-p', '2222',
`ls -1Ap '/srv/app'`
])
})
+ it('leaves a bare ~ unquoted so the remote shell expands it', () => {
+ expect(listDirArgs(conn, '/s.sock', '~')).toEqual([
+ '-o', 'ControlMaster=no', '-o', 'ControlPath=/s.sock', '-p', '2222',
+ `ls -1Ap ~`
+ ])
+ })
+ it('tilde-expands a home-relative path, quoting the remainder', () => {
+ expect(listDirArgs(conn, '/s.sock', '~/my dir')).toEqual([
+ '-o', 'ControlMaster=no', '-o', 'ControlPath=/s.sock', '-p', '2222',
+ `ls -1Ap ~/'my dir'`
+ ])
+ })
})
diff --git a/src/main/remote-ssh/control-master.ts b/src/main/remote-ssh/control-master.ts
index c5eb1aabe..7e9143cb7 100644
--- a/src/main/remote-ssh/control-master.ts
+++ b/src/main/remote-ssh/control-master.ts
@@ -1,6 +1,6 @@
// Pure ssh/tmux argv + remote-command builders for SSH projects. No electron/node-pty imports
// — unit-testable in isolation. The electron/spawn wiring lives in ssh-project.ts + pty-manager.
-import { posixQuote, remoteTmuxCommand, type SshConnection } from '../../shared/ssh'
+import { quoteRemotePath, remoteTmuxCommand, type SshConnection } from '../../shared/ssh'
/** Dedicated remote tmux socket so an SSH project never collides with the user's own tmux. */
export const RMT_TMUX_SOCKET = 'nodeterm-rmt'
@@ -68,7 +68,7 @@ export function tmuxProbeArgs(conn: SshConnection, controlPath: string): string[
return childArgs(conn, controlPath, 'command -v tmux')
}
export function listDirArgs(conn: SshConnection, controlPath: string, path: string): string[] {
- return childArgs(conn, controlPath, `ls -1Ap ${posixQuote(path)}`)
+ return childArgs(conn, controlPath, `ls -1Ap ${quoteRemotePath(path)}`)
}
/** The remote PTY program is `ssh <childArgs> host -t '<remoteTmuxCommand>'`. */
diff --git a/src/shared/ssh.test.ts b/src/shared/ssh.test.ts
index a341b4abf..02919877f 100644
--- a/src/shared/ssh.test.ts
+++ b/src/shared/ssh.test.ts
@@ -4,6 +4,7 @@ import {
parseExtraArgs,
parseSshConfig,
posixQuote,
+ quoteRemotePath,
remoteTmuxCommand,
parseLsDirs
} from './ssh'
@@ -93,12 +94,35 @@ describe('posixQuote', () => {
})
})
+describe('quoteRemotePath', () => {
+ it('leaves a bare ~ unquoted so the remote shell expands it', () => {
+ expect(quoteRemotePath('~')).toBe('~')
+ })
+ it('keeps a leading ~/ unquoted and single-quotes the remainder', () => {
+ expect(quoteRemotePath('~/a b')).toBe(`~/'a b'`)
+ })
+ it('a bare ~/ stays ~/', () => {
+ expect(quoteRemotePath('~/')).toBe('~/')
+ })
+ it('fully quotes an absolute path (byte-identical to posixQuote)', () => {
+ expect(quoteRemotePath('/srv/x')).toBe(`'/srv/x'`)
+ })
+ it('only a leading ~ or ~/ is special — ~weird is fully quoted', () => {
+ expect(quoteRemotePath('~weird')).toBe(`'~weird'`)
+ })
+})
+
describe('remoteTmuxCommand', () => {
it('builds attach-or-create on the remote socket with a quoted cwd', () => {
expect(remoteTmuxCommand({ sessionId: 'nt-x', remoteCwd: '/srv/app' })).toBe(
`tmux -L nodeterm-rmt new-session -A -s 'nt-x' -c '/srv/app'`
)
})
+ it('tilde-expands a home-relative cwd (leaves ~/ unquoted)', () => {
+ expect(remoteTmuxCommand({ sessionId: 'nt-x', remoteCwd: '~/project' })).toBe(
+ `tmux -L nodeterm-rmt new-session -A -s 'nt-x' -c ~/'project'`
+ )
+ })
it('appends a quoted program + args when given', () => {
expect(
remoteTmuxCommand({ sessionId: 'nt-x', remoteCwd: '/a', program: 'ssh', programArgs: ['-A', 'h'] })
diff --git a/src/shared/ssh.ts b/src/shared/ssh.ts
index 00eba282d..cf0fd132b 100644
--- a/src/shared/ssh.ts
+++ b/src/shared/ssh.ts
@@ -67,6 +67,17 @@ export function posixQuote(s: string): string {
return `'${s.replace(/'/g, `'\\''`)}'`
}
+/**
+ * Quote a remote path as one shell token, but leave a leading `~` / `~/` UNQUOTED so the remote
+ * shell tilde-expands it (single quotes suppress `~` expansion). The remainder stays quoted, so a
+ * directory name can never inject shell. `~` alone → `~`; `~/a b` → `~/'a b'`; `/srv/x` → `'/srv/x'`.
+ */
+export function quoteRemotePath(p: string): string {
+ if (p === '~') return '~'
+ if (p.startsWith('~/')) return p.length > 2 ? `~/${posixQuote(p.slice(2))}` : '~/'
+ return posixQuote(p)
+}
+
/** Build the remote shell command that attaches-or-creates this node's remote tmux session. */
export function remoteTmuxCommand(opts: {
sessionId: string
@@ -85,7 +96,7 @@ export function remoteTmuxCommand(opts: {
'-s',
posixQuote(opts.sessionId),
'-c',
- posixQuote(opts.remoteCwd)
+ quoteRemotePath(opts.remoteCwd)
]
if (opts.program) {
parts.push(posixQuote(opts.program))