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(pty): pane-command IPC — pane_current_command for restart choreography

enesfa00113ddc6f
diff --git a/src/core/pty-manager.ts b/src/core/pty-manager.ts
index 773c3e8ff..b8dd22edd 100644
--- a/src/core/pty-manager.ts
+++ b/src/core/pty-manager.ts
@@ -24,7 +24,8 @@ import {
remoteTmuxKillArgs,
remoteTmuxPtyArgs,
remoteTmuxSendKeysArgs,
- remoteCapturePaneArgs
+ remoteCapturePaneArgs,
+ remotePaneCommandArgs
} from './remote-ssh/control-master'
import { TMUX_SOCKET, sessionName } from './tmux-naming'
import { bracketedInjection } from './paste-injection'
@@ -690,6 +691,7 @@ export class PtyManager {
this.sendText(persistKey, text, enter === undefined ? undefined : { enter })
)
platform().handle(IPC.ptyTmuxStatus, () => this.tmuxStatus())
+ platform().handle(IPC.ptyPaneCommand, (persistKey: string) => this.paneCommand(persistKey))
}
/** Feeds the renderer's "tmux not found" banner. Without tmux the app silently degrades to a
@@ -1939,6 +1941,50 @@ export class PtyManager {
}
}
+ /**
+ * The command currently in the foreground of a node's tmux pane (e.g. 'claude', 'zsh') — how
+ * the in-place agent restart observes that the CLI has exited and a shell owns the pane again.
+ * null when it is unknown: no live session, tmux unavailable, or the query failed. Unknown is
+ * never evidence of a particular command, so every failure path answers null rather than
+ * throwing — the caller polls this behind its own deadline.
+ *
+ * Mirrors `sendText`'s dispatch: an SSH-project node has no LOCAL tmux session to target, so a
+ * session registered with `sshRemote` is queried on the REMOTE tmux over the project's
+ * ControlMaster (`remotePaneCommandArgs`); everything else asks the local socket.
+ */
+ async paneCommand(persistKey: string): Promise<string | null> {
+ const target = sessionName(persistKey)
+ const sshRemote = this.sessionByPersistKey(persistKey)?.sshRemote
+ if (sshRemote) {
+ const ssh = findSsh()
+ if (!ssh) return null
+ try {
+ const { stdout } = await runAsync(
+ ssh,
+ remotePaneCommandArgs(sshRemote.conn, sshRemote.controlPath, target)
+ )
+ return stdout.trim() || null
+ } catch {
+ return null
+ }
+ }
+ if (!this.tmuxPath) return null
+ try {
+ const { stdout } = await runAsync(this.tmuxPath, [
+ '-L',
+ TMUX_SOCKET,
+ 'display-message',
+ '-p',
+ '-t',
+ target,
+ '#{pane_current_command}'
+ ])
+ return stdout.trim() || null
+ } catch {
+ return null
+ }
+ }
+
/**
* Did the application in this pane request bracketed-paste mode? tmux tracks the DECSET
* 2004 state per pane and exposes it as `bracket_paste_flag`. Unknown — query fails, old
diff --git a/src/core/remote-ssh/control-master.test.ts b/src/core/remote-ssh/control-master.test.ts
index a9d79fca5..a60406ebd 100644
--- a/src/core/remote-ssh/control-master.test.ts
+++ b/src/core/remote-ssh/control-master.test.ts
@@ -8,6 +8,7 @@ import {
remoteTmuxSendKeysArgs,
probeSaysAbsent,
remoteCapturePaneArgs,
+ remotePaneCommandArgs,
remoteTmuxPtyArgs,
listDirArgs,
mkDirArgs,
@@ -156,6 +157,15 @@ describe('remoteCapturePaneArgs', () => {
})
})
+describe('remotePaneCommandArgs', () => {
+ it('asks the remote tmux for the pane_current_command of the session', () => {
+ const args = remotePaneCommandArgs(conn, '/s.sock', 'nt-x')
+ expect(args[args.length - 1]).toBe(
+ `tmux -L ${RMT_TMUX_SOCKET} display-message -p -t nt-x '#{pane_current_command}'`
+ )
+ })
+})
+
describe('remoteTmuxPtyArgs', () => {
it('runs the remote tmux command as a forced-TTY child (-t then childArgs)', () => {
const args = remoteTmuxPtyArgs(conn, '/s.sock', 'nt-x', '/srv/app')
diff --git a/src/core/remote-ssh/control-master.ts b/src/core/remote-ssh/control-master.ts
index 59e14abc0..db02a5fda 100644
--- a/src/core/remote-ssh/control-master.ts
+++ b/src/core/remote-ssh/control-master.ts
@@ -175,6 +175,19 @@ export function remoteCapturePaneArgs(conn: SshConnection, controlPath: string,
`tmux -L ${RMT_TMUX_SOCKET} capture-pane -p -e -t ${sessionId} -S ${full ? '-' : '-200'}`
)
}
+/**
+ * Ask the REMOTE tmux which command is in the foreground of a node's pane — the remote
+ * counterpart of `PtyManager.paneCommand`'s local `display-message` path. The format is
+ * single-quoted so `#{…}` survives the remote shell verbatim (same idiom as the
+ * `bracket_paste_flag` probe in `remoteTmuxSendKeysArgs`).
+ */
+export function remotePaneCommandArgs(conn: SshConnection, controlPath: string, sessionId: string): string[] {
+ return childArgs(
+ conn,
+ controlPath,
+ `tmux -L ${RMT_TMUX_SOCKET} display-message -p -t ${sessionId} '#{pane_current_command}'`
+ )
+}
export function tmuxProbeArgs(conn: SshConnection, controlPath: string): string[] {
return childArgs(conn, controlPath, 'command -v tmux')
}
diff --git a/src/preload/index.ts b/src/preload/index.ts
index 92e082689..fccd18742 100644
--- a/src/preload/index.ts
+++ b/src/preload/index.ts
@@ -69,6 +69,7 @@ const api: NodeTerminalApi = {
sendText: (persistKey, text, opts) =>
ipcRenderer.invoke(IPC.ptySendText, persistKey, text, opts?.enter),
tmuxStatus: () => ipcRenderer.invoke(IPC.ptyTmuxStatus),
+ paneCommand: (persistKey) => ipcRenderer.invoke(IPC.ptyPaneCommand, persistKey),
readSessionName: (sessionId, accountId) =>
ipcRenderer.invoke(IPC.ptyReadSessionName, sessionId, accountId),
onData: (sessionId, listener) => {
diff --git a/src/renderer/bridge/ws-bridge.ts b/src/renderer/bridge/ws-bridge.ts
index 37e9bf8e1..c7cd9e246 100644
--- a/src/renderer/bridge/ws-bridge.ts
+++ b/src/renderer/bridge/ws-bridge.ts
@@ -219,6 +219,10 @@ export function buildRealApi(
client
.request(IPC.ptyTmuxStatus)
.catch(() => ({ available: true, installCommand: null, installLabel: null, platform: 'linux' })) as Promise<TmuxStatus>,
+ // Unknown on failure (null), never a rejection: the restart poller reads null as "not a
+ // shell yet" and gives up on its own deadline.
+ paneCommand: (persistKey) =>
+ client.request(IPC.ptyPaneCommand, persistKey).catch(() => null) as Promise<string | null>,
// No server handler — the session-name poll degrades to no adopted name.
readSessionName: () => Promise.resolve(''),
onData: (sessionId, listener) =>
diff --git a/src/server/index.ts b/src/server/index.ts
index a55bccaf7..55e41097c 100644
--- a/src/server/index.ts
+++ b/src/server/index.ts
@@ -197,7 +197,8 @@ export async function startServer(
// ptyCapture delegates purely to core (ptyManager.captureSession), so it belongs here.
// The others (ptyGenerateName / ptyGenerateGroupName → commit-message.ts; ptyReadSessionName
// → transcript-reader.ts) depend on src/main-resident modules and are stubbed by the bridge
- // in Task 8. readScrollback + sendText are already registered inside PtyManager.registerIpc().
+ // in Task 8. readScrollback + sendText + paneCommand are already registered inside
+ // PtyManager.registerIpc().
platform.handle(IPC.ptyCapture, (persistKey: string, full?: boolean) =>
ptyManager.captureSession(persistKey, full)
)
diff --git a/src/shared/ipc.ts b/src/shared/ipc.ts
index 6b7c655be..f7662391e 100644
--- a/src/shared/ipc.ts
+++ b/src/shared/ipc.ts
@@ -18,6 +18,9 @@ export const IPC = {
ptyReadScrollback: 'pty:read-scrollback',
ptySendText: 'pty:send-text',
ptyTmuxStatus: 'pty:tmux-status',
+ /** The foreground command of a node's tmux pane (`#{pane_current_command}`) — how the in-place
+ * agent restart sees that the CLI has exited and a shell owns the pane again. */
+ ptyPaneCommand: 'pty:pane-command',
ptyReadSessionName: 'pty:read-session-name',
claudeReadTranscript: 'claude:read-transcript',
chatReadTranscript: 'chat:read-transcript',
diff --git a/src/shared/types.ts b/src/shared/types.ts
index baeff70ba..d11e990c3 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -432,6 +432,10 @@ export interface PtyApi {
/** Is tmux available on this host (else the silent plain-shell fallback), plus a suggested
* install command for the "tmux not found" banner. */
tmuxStatus(): Promise<TmuxStatus>
+ /** The command currently in the foreground of a node's tmux pane (e.g. 'claude', 'zsh'), by
+ * node persistKey. null when it is unknown — no session, no tmux, or the query failed — which
+ * callers must read as "not observed", never as evidence of a particular command. */
+ paneCommand(persistKey: string): Promise<string | null>
/** The agent session's display name (`/rename` name, else auto name) read from its transcript,
* resolved strictly by sessionId; null if unknown. Keeps a node title in sync with the
* `/resume` name (e.g. after resume) without cross-contaminating same-folder sessions.