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): thread remote tmux confPath + OSC 52 clipboard handler (remote scroll + copy)

enes5d0a0440ecff
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 3fb8e8937..63adf7661 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -509,11 +509,11 @@ export function Canvas() {
if (project.ssh) {
window.nodeTerminal.sshProject
.connect(project.id, project.ssh.server, project.ssh.remoteCwd)
- .then(async ({ controlPath, hookEndpointPath }) => {
+ .then(async ({ controlPath, hookEndpointPath, tmuxConfPath }) => {
// Arm remote git routing for the active project BEFORE the sshConn entry appears, so the
// Source Control panel's re-fetch (which keys off that entry) already hits the master.
await window.nodeTerminal.git.setActiveRemote(project.id)
- useSshConn.getState().setConn(project.id, { controlPath, hookEndpointPath })
+ useSshConn.getState().setConn(project.id, { controlPath, hookEndpointPath, tmuxConfPath })
})
.catch(() => {
/* status surfaced via onStatus → the connection banner */
diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsx
index 4c22dfa9c..2d07ee011 100644
--- a/src/renderer/nodes/TerminalNode.tsx
+++ b/src/renderer/nodes/TerminalNode.tsx
@@ -16,6 +16,7 @@ import { transport as localTransport } from '../terminal/local-transport'
import { RemoteTransport } from '../terminal/remote-transport'
import type { TerminalTransport } from '../terminal/transport'
import { patchTerminalScale } from '../terminal/scale-fix'
+import { parseOsc52 } from '../terminal/osc52'
import { FindBar } from '../components/FindBar'
import { IconSearch } from '../components/icons'
import { NodeTags } from '../components/NodeTags'
@@ -49,7 +50,13 @@ async function resolveSshRemote(
conn: SshConnection,
cwd: string | undefined
): Promise<
- | { controlPath: string; conn: SshConnection; remoteCwd: string; hookEndpointPath?: string }
+ | {
+ controlPath: string
+ conn: SshConnection
+ remoteCwd: string
+ hookEndpointPath?: string
+ tmuxConfPath?: string
+ }
| undefined
> {
const projectId = useProjects.getState().activeProjectId
@@ -75,7 +82,10 @@ async function resolveSshRemote(
// The remote hook endpoint (reverse tunnel + remote install) is set up alongside the master;
// pass it through so the remote tmux session carries the hook env. Optional (fail-open).
const hookEndpointPath = useSshConn.getState().getHookEndpointPath(projectId)
- return { controlPath, conn, remoteCwd: cwd || '~', hookEndpointPath }
+ // The remote tmux config (mouse on → scroll; set-clipboard on → OSC 52) is written + sourced
+ // alongside the master; pass its path so a fresh remote session launches with `-f`. Optional.
+ const tmuxConfPath = useSshConn.getState().getTmuxConfPath(projectId)
+ return { controlPath, conn, remoteCwd: cwd || '~', hookEndpointPath, tmuxConfPath }
}
/**
@@ -235,6 +245,17 @@ export function TerminalNode({ id, data, selected, parentId }: NodeProps<CanvasN
fit.fit()
patchTerminalScale(term, getZoom)
+ // OSC 52 clipboard write: the remote tmux (set-clipboard on) emits OSC 52 on copy; route the
+ // decoded text to the Mac clipboard. WRITE-ONLY — `parseOsc52` returns null for a `?` read
+ // query so a remote program can never read the local clipboard. Returning true swallows the
+ // sequence (also the read query). Local tmux uses pbcopy → emits no OSC 52, so this is a no-op
+ // for local terminals.
+ term.parser.registerOscHandler(52, (data) => {
+ const text = parseOsc52(data)
+ if (text !== null) window.nodeTerminal.clipboard.writeText(text)
+ return true
+ })
+
// Cmd+C copies the terminal selection (xterm renders to canvas, so the DOM-selection
// copy used elsewhere can't see it). Ctrl+C is left alone so it still sends SIGINT.
term.attachCustomKeyEventHandler((e) => {
diff --git a/src/renderer/state/sshConn.ts b/src/renderer/state/sshConn.ts
index e62c8822d..bd56f7140 100644
--- a/src/renderer/state/sshConn.ts
+++ b/src/renderer/state/sshConn.ts
@@ -7,6 +7,9 @@ export interface SshConnInfo {
/** Remote endpoint file the managed hook script sources (reverse-tunnel hook transport).
* Optional: absent when forwarding/remote install failed (fail-open → Phase-1 status). */
hookEndpointPath?: string
+ /** Remote path of the injected tmux config (`-f`), written + sourced on connect.
+ * Optional: absent when the conf write failed (fail-open → remote tmux defaults). */
+ tmuxConfPath?: string
}
/**
@@ -21,6 +24,7 @@ interface SshConnState {
setConn(projectId: string, info: SshConnInfo): void
getControlPath(projectId: string): string | undefined
getHookEndpointPath(projectId: string): string | undefined
+ getTmuxConfPath(projectId: string): string | undefined
clear(projectId: string): void
}
@@ -35,6 +39,9 @@ export const useSshConn = create<SshConnState>((set, get) => ({
getHookEndpointPath(projectId) {
return get().byProject[projectId]?.hookEndpointPath
},
+ getTmuxConfPath(projectId) {
+ return get().byProject[projectId]?.tmuxConfPath
+ },
clear(projectId) {
set((s) => {
const next = { ...s.byProject }
diff --git a/src/renderer/terminal/osc52.test.ts b/src/renderer/terminal/osc52.test.ts
new file mode 100644
index 000000000..70aca5d1b
--- /dev/null
+++ b/src/renderer/terminal/osc52.test.ts
@@ -0,0 +1,19 @@
+import { describe, expect, it } from 'vitest'
+import { parseOsc52 } from './osc52'
+
+describe('parseOsc52', () => {
+ it('decodes a base64 clipboard write payload', () => {
+ expect(parseOsc52('c;' + btoa('Hello, world'))).toBe('Hello, world')
+ })
+ it('ignores a read query (?)', () => {
+ expect(parseOsc52('c;?')).toBeNull()
+ })
+ it('ignores empty / malformed / no-semicolon', () => {
+ expect(parseOsc52('c;')).toBeNull()
+ expect(parseOsc52('garbage')).toBeNull()
+ expect(parseOsc52('c;not_base64!!')).toBeNull()
+ })
+ it('ignores an oversized payload', () => {
+ expect(parseOsc52('c;' + 'A'.repeat(1_000_001))).toBeNull()
+ })
+})
diff --git a/src/renderer/terminal/osc52.ts b/src/renderer/terminal/osc52.ts
new file mode 100644
index 000000000..0c9fdec77
--- /dev/null
+++ b/src/renderer/terminal/osc52.ts
@@ -0,0 +1,19 @@
+// Parse an OSC 52 payload (`<selection>;<base64>`) into clipboard text. WRITE-ONLY: a `?` read
+// query is ignored (never expose the local clipboard to remote programs). Returns null on a read
+// query / empty / malformed / oversized payload.
+const MAX_BASE64 = 1_000_000
+
+export function parseOsc52(data: string): string | null {
+ const i = data.indexOf(';')
+ if (i < 0) return null
+ const payload = data.slice(i + 1)
+ if (!payload || payload === '?' || payload.length > MAX_BASE64) return null
+ try {
+ const bin = atob(payload)
+ const bytes = Uint8Array.from(bin, (ch) => ch.charCodeAt(0))
+ const text = new TextDecoder('utf-8', { fatal: true }).decode(bytes)
+ return text
+ } catch {
+ return null
+ }
+}