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.

feat(ssh): pure ssh arg builder + shared types

enes6566af886105
diff --git a/src/shared/ssh.test.ts b/src/shared/ssh.test.ts
new file mode 100644
index 000000000..488484ed2
--- /dev/null
+++ b/src/shared/ssh.test.ts
@@ -0,0 +1,39 @@
+import { describe, expect, it } from 'vitest'
+import { buildSshArgs, parseExtraArgs } from './ssh'
+
+describe('buildSshArgs', () => {
+ it('minimal host/user', () => {
+ expect(buildSshArgs({ host: 'example.com', user: 'alice' })).toEqual([
+ '-p',
+ '22',
+ ])
+ })
+
+ it('custom port + identity file', () => {
+ expect(
+ buildSshArgs({ host: 'h', user: 'u', port: 2222, identityFile: '/keys/id_ed25519' })
+ ).toEqual(['-p', '2222', '-i', '/keys/id_ed25519', 'u@h'])
+ })
+
+ it('extra args are tokenized and inserted before the target', () => {
+ expect(
+ buildSshArgs({ host: 'h', user: 'u', extraArgs: '-A -o ServerAliveInterval=30' })
+ ).toEqual(['-p', '22', '-A', '-o', 'ServerAliveInterval=30', 'u@h'])
+ })
+})
+
+describe('parseExtraArgs', () => {
+ it('respects single and double quotes', () => {
+ expect(parseExtraArgs(`-o "ProxyCommand=ssh -W %h:%p bastion" -A`)).toEqual([
+ '-o',
+ 'ProxyCommand=ssh -W %h:%p bastion',
+ '-A'
+ ])
+ })
+
+ it('empty/undefined → []', () => {
+ expect(parseExtraArgs(undefined)).toEqual([])
+ expect(parseExtraArgs(' ')).toEqual([])
+ })
+})
diff --git a/src/shared/ssh.ts b/src/shared/ssh.ts
new file mode 100644
index 000000000..e9ef6dd5a
--- /dev/null
+++ b/src/shared/ssh.ts
@@ -0,0 +1,63 @@
+/**
+ * Pure helpers for launching the system `ssh` binary as a terminal session program.
+ * No Electron, no node-pty — unit-testable in isolation.
+ */
+
+/** A single SSH connection's parameters (inline-persisted on a node as `data.ssh`). */
+export interface SshConnection {
+ host: string
+ user: string
+ /** Defaults to 22. */
+ port?: number
+ /** Optional `-i` identity file path. */
+ identityFile?: string
+ /** Optional raw extra ssh args (advanced), POSIX-tokenized. */
+ extraArgs?: string
+ /** Display label, copied from the saved server when the node is created. */
+ label?: string
+}
+
+/** A saved server in the app's SSH store. `label` is required for display. */
+export interface SshServer extends SshConnection {
+ id: string
+ label: string
+}
+
+/**
+ * Split a raw extra-args string into argv tokens, honoring single and double quotes.
+ * Unquoted whitespace separates tokens; quotes group; quote chars are stripped.
+ */
+export function parseExtraArgs(s: string | undefined): string[] {
+ if (!s || !s.trim()) return []
+ const tokens: string[] = []
+ let cur = ''
+ let quote: '"' | "'" | null = null
+ let has = false
+ for (const ch of s) {
+ if (quote) {
+ if (ch === quote) quote = null
+ else cur += ch
+ } else if (ch === '"' || ch === "'") {
+ quote = ch
+ has = true
+ } else if (/\s/.test(ch)) {
+ if (has) tokens.push(cur)
+ cur = ''
+ has = false
+ } else {
+ cur += ch
+ has = true
+ }
+ }
+ if (has) tokens.push(cur)
+ return tokens
+}
+
+/** Build the `ssh` argv: `-p <port> [-i <id>] [...extra] user@host`. */
+export function buildSshArgs(conn: SshConnection): string[] {
+ const args = ['-p', String(conn.port ?? 22)]
+ if (conn.identityFile) args.push('-i', conn.identityFile)
+ args.push(...parseExtraArgs(conn.extraArgs))
+ args.push(`${conn.user}@${conn.host}`)
+ return args
+}
diff --git a/src/shared/types.ts b/src/shared/types.ts
index 3d372d3f3..a569025e1 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -5,6 +5,8 @@ import type { AgentId, PromptInjectionMode } from './agents/config'
export interface PtyCreateOptions {
shell?: string
+ /** Arguments for `shell` when it is run as the session program (e.g. ssh args). */
+ shellArgs?: string[]
cwd?: string
cols: number
rows: number