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.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(ssh-p2a): raw node id in remote hook env + sync master kill on quit + transcript_path jail (final-review)
enes03283602fcd3
diff --git a/src/main/index.ts b/src/main/index.tsindex 282e6fbaf..7b74ae36d 100644--- a/src/main/index.ts+++ b/src/main/index.ts@@ -1,4 +1,5 @@-import { join } from 'path'+import { join, resolve, sep } from 'path'+import { homedir } from 'os'import { app, BrowserWindow, dialog, ipcMain, Notification, shell } from 'electron'import { IPC } from '../shared/ipc'import * as fsOps from './fs-ops'@@ -299,6 +300,18 @@ app.whenReady().then(async () => {hookServer.setListener((e) => {if (!win.isDestroyed()) win.webContents.send(IPC.agentStatus, e)})+ // Security: hook POSTs now arrive over the remote reverse tunnel too (SSH Phase 2a), so a+ // forged/remote POST could set transcript_path to an arbitrary LOCAL path (e.g. ~/.ssh/id_rsa)+ // and have the app read it. The tails read the LOCAL filesystem; legitimate LOCAL transcripts+ // always live under ~/.claude/projects. Phase 2a does NOT tail remote transcripts (that's 2b),+ // so we jail transcript_path to that root and skip the read otherwise. Returns the path only+ // when it resolves under the projects root.+ const TRANSCRIPT_ROOT = join(homedir(), '.claude', 'projects')+ const safeTranscriptPath = (tp: string | undefined): string | undefined => {+ if (!tp) return undefined+ const abs = resolve(tp)+ return abs === TRANSCRIPT_ROOT || abs.startsWith(TRANSCRIPT_ROOT + sep) ? abs : undefined+ }hookServer.setRawListener((agentId, nodeId, payload) => {if (agentId !== 'claude') returnconst p = payload as {@@ -308,16 +321,17 @@ app.whenReady().then(async () => {tool_name?: stringtool_use_id?: string}+ const transcriptPath = safeTranscriptPath(p.transcript_path)// Context-window meter: tail the session transcript (any event carrying both fields).- if (p.session_id && p.transcript_path) contextTail.track(p.session_id, p.transcript_path)+ if (p.session_id && transcriptPath) contextTail.track(p.session_id, transcriptPath)if (nodeId && p.session_id) nodeContextSession.set(nodeId, p.session_id)- if (nodeId && p.session_id && p.transcript_path) setNodeTranscript(nodeId, p.session_id, p.transcript_path)+ if (nodeId && p.session_id && transcriptPath) setNodeTranscript(nodeId, p.session_id, transcriptPath)if (p.hook_event_name === 'SessionEnd' && p.session_id) contextTail.untrack(p.session_id)// Subagent live transcript: track on PreToolUse / finish on PostToolUse for subagent tools.const SUBAGENT_TOOLS = new Set(['Agent', 'Task'])if (p.tool_use_id && p.tool_name && SUBAGENT_TOOLS.has(p.tool_name)) {if (p.hook_event_name === 'PreToolUse') {- subagentTail.track(p.tool_use_id, p.transcript_path)+ subagentTail.track(p.tool_use_id, transcriptPath)if (nodeId) {const set = nodeSubagents.get(nodeId) ?? new Set<string>()set.add(p.tool_use_id)diff --git a/src/main/pty-manager.ts b/src/main/pty-manager.tsindex 80130bb7b..8b6a63585 100644--- a/src/main/pty-manager.ts+++ b/src/main/pty-manager.ts@@ -370,10 +370,16 @@ export class PtyManager {// When the project's reverse tunnel + remote endpoint file are set up (Task 2), inject the// remote hook env into the remote tmux session so the installed hook script POSTs state back// over the unix-socket tunnel. Fail-open: no hookEndpointPath → no hook env (Phase-1 status).+ //+ // NODETERM_NODE_ID MUST be the RAW persistKey (the React Flow node id), NOT the tmux+ // session name (`nt-<id>`). The local path's hookServer.buildPtyEnv(persistKey, …) sets+ // NODETERM_NODE_ID = persistKey, and Canvas.tsx onAgentStatus keys agentStatus.byId /+ // selection off that raw id with no `nt-` stripping. Passing the session name here would+ // emit events under `nt-<id>` that match no node → no badge/notification/session/loop.const hookExtraEnv = options.sshRemote.hookEndpointPath? remoteHookEnvArgs(options.sshRemote.hookEndpointPath,- sessionName(options.persistKey),+ options.persistKey,hookServer.getVersion()): []diff --git a/src/main/remote-ssh/control-master.test.ts b/src/main/remote-ssh/control-master.test.tsindex 911051f2e..522b23841 100644--- a/src/main/remote-ssh/control-master.test.ts+++ b/src/main/remote-ssh/control-master.test.ts@@ -104,6 +104,17 @@ describe('hook forwarding', () => {'-e', 'NODETERM_HOOK_VERSION=1'])})+ it('emits NODETERM_NODE_ID as the RAW persistKey (not the nt-<id> tmux session name)', () => {+ // Cross-boundary contract: the remote hook env's NODETERM_NODE_ID MUST equal what the+ // LOCAL path's hookServer.buildPtyEnv(persistKey, …) sets — i.e. the RAW React Flow node id.+ // Canvas.tsx onAgentStatus keys agentStatus.byId / selection off that raw id with no `nt-`+ // stripping, so passing the session name (`nt-<id>`) would orphan every remote event.+ const persistKey = 'node-abc'+ const env = remoteHookEnvArgs('/ep', persistKey, '1')+ expect(env).toContain(`NODETERM_NODE_ID=${persistKey}`)+ // Guard against a regression that passes sessionName(persistKey) = `nt-<id>`.+ expect(env).not.toContain(`NODETERM_NODE_ID=nt-${persistKey}`)+ })it('remoteEndpointFileContents writes SOCK/TOKEN/VERSION', () => {expect(remoteEndpointFileContents('/r.sock', 'tok', '1')).toBe('NODETERM_HOOK_SOCK=/r.sock\nNODETERM_HOOK_TOKEN=tok\nNODETERM_HOOK_VERSION=1\n'diff --git a/src/main/remote-ssh/ssh-project.ts b/src/main/remote-ssh/ssh-project.tsindex a16421dcb..c83169bdb 100644--- a/src/main/remote-ssh/ssh-project.ts+++ b/src/main/remote-ssh/ssh-project.ts@@ -156,9 +156,22 @@ export class SshProjectManager {this.r.onStatus({ projectId, status: 'disconnected' })}- /** Tear down every live master (on app quit) so no `-N` master ssh child is orphaned. */+ /**+ * Tear down every live master (on app quit) so no `-N` master ssh child is orphaned.+ * This MUST be synchronous: `before-quit` (index.ts) is sync and the process can exit before+ * any awaited work runs. `disconnect()` awaits an `ssh -O cancel` round-trip BEFORE killing the+ * master, so on a hard quit `c.master.kill()` would never run → orphaned `-N` master (~5 min+ * ControlPersist). Here we kill the master immediately and skip the graceful `-O cancel`: the+ * reverse hook forward dies with the master, so cancelling it is unnecessary on quit.+ */disconnectAll(): void {- for (const projectId of [...this.conns.keys()]) void this.disconnect(projectId)+ for (const projectId of [...this.conns.keys()]) {+ const c = this.conns.get(projectId)+ if (!c) continue+ c.master.kill()+ this.conns.delete(projectId)+ this.r.onStatus({ projectId, status: 'disconnected' })+ }}}