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(agents): never launch claude with an `--permission-mode auto` it would reject
enes32fc8ab9dfb0
diff --git a/src/main/remote-ssh/ssh-project.ts b/src/main/remote-ssh/ssh-project.tsindex 175584467..9614c64ec 100644--- a/src/main/remote-ssh/ssh-project.ts+++ b/src/main/remote-ssh/ssh-project.ts@@ -6,6 +6,7 @@ import { IPC } from '../../shared/ipc'import { parseLsDirs, posixQuote, quoteRemotePath, remoteTmuxConf, type SshConnection } from '../../shared/ssh'import type { SshProjectStatus } from '../../shared/types'import { remoteAccountConfigDir, isSupportedClaudeVersion } from '../../core/claude-accounts-core'+import { supportsAutoPermissionMode } from '../../shared/agents/config'import {controlPathFor,masterArgs,@@ -50,6 +51,11 @@ interface Conn {/** The project's remote repo cwd (Phase 4). Lets `refForRemoteCwd` route remote git ops to this* connection's master. Undefined when the project has no folder selected. */remoteCwd?: string+ /** Does the REMOTE host's claude CLI accept `--permission-mode auto` (>= 2.1.90)? Probed once at+ * connect: the remote CLI can be older than the local one, and the local answer must never be+ * applied to a remote launch. Undefined/false ⇒ the renderer omits the flag for this project's+ * Claude nodes (bare command — today's behavior), never a failed launch. */+ claudeAutoPermissionMode?: boolean}/**@@ -121,7 +127,13 @@ export class SshProjectManager {projectId: string,conn: SshConnection,remoteCwd?: string- ): Promise<{ controlPath: string; hookEndpointPath?: string; tmuxConfPath?: string; remoteHome?: string }> {+ ): Promise<{+ controlPath: string+ hookEndpointPath?: string+ tmuxConfPath?: string+ remoteHome?: string+ claudeAutoPermissionMode?: boolean+ }> {const existing = this.conns.get(projectId)if (existing) {// Verify the cached master is still alive before reusing it — a dropped/timed-out master@@ -132,7 +144,13 @@ export class SshProjectManager {// Keep the remote git cwd current even on an idempotent reuse (the folder may have changed).// Guard against a later connect without remoteCwd clearing a known cwd.existing.remoteCwd = remoteCwd ?? existing.remoteCwd- return { controlPath: existing.controlPath, hookEndpointPath: existing.hookEndpointPath, tmuxConfPath: existing.tmuxConfPath, remoteHome: existing.remoteHome }+ return {+ controlPath: existing.controlPath,+ hookEndpointPath: existing.hookEndpointPath,+ tmuxConfPath: existing.tmuxConfPath,+ remoteHome: existing.remoteHome,+ claudeAutoPermissionMode: existing.claudeAutoPermissionMode+ }}this.r.onStatus({ projectId, status: 'reconnecting' })existing.master.kill()@@ -192,14 +210,21 @@ export class SshProjectManager {/* fail-open: no conf → remote tmux uses host defaults */}}+ // Probe the REMOTE claude CLI once per connect: `--permission-mode auto` only exists in+ // >= 2.1.90 and the host's CLI may be older than the local one. Unknown ⇒ false ⇒ the+ // renderer launches this project's Claude nodes with the bare command (fail-open).+ const claudeAutoPermissionMode = supportsAutoPermissionMode(+ await this.remoteClaudeVersion(conn, controlPath)+ )const entry = this.conns.get(projectId)if (entry) {entry.hookEndpointPath = hookEndpointPathentry.remoteHome = remoteHomeentry.tmuxConfPath = tmuxConfPath+ entry.claudeAutoPermissionMode = claudeAutoPermissionMode}this.r.onStatus({ projectId, status: 'connected' })- return { controlPath, hookEndpointPath, tmuxConfPath, remoteHome }+ return { controlPath, hookEndpointPath, tmuxConfPath, remoteHome, claudeAutoPermissionMode }}await new Promise((res) => setTimeout(res, 100))}@@ -369,18 +394,34 @@ export class SshProjectManager {await this.r.run(childArgs(c.conn, c.controlPath, `rm -rf ${quoteRemotePath(dir)}`))}- /** Best-effort remote `claude --version` check. Returns true when it can't be determined (a- * non-login ssh shell may lack claude on PATH) so remote add is never blocked on detection. */- private async remoteClaudeVersionOk(c: Conn): Promise<boolean> {+ /**+ * Best-effort `claude --version` ON THE REMOTE HOST. Null when it can't be determined.+ *+ * An ssh EXEC channel gets a non-interactive, non-login shell, whose rc file usually bails out+ * early — so a claude installed via nvm/asdf/homebrew-on-PATH may be invisible to a plain+ * `claude --version`. The remote tmux session that actually RUNS the node uses a login shell, so+ * we try that first and only then the bare command.+ */+ private async remoteClaudeVersion(conn: SshConnection, controlPath: string): Promise<string | null> {try {- const { code, stdout } = await this.r.run(childArgs(c.conn, c.controlPath, 'claude --version'))- if (code !== 0) return true- return isSupportedClaudeVersion(stdout.trim())+ const { code, stdout } = await this.r.run(+ childArgs(conn, controlPath, `$SHELL -lc 'claude --version' 2>/dev/null || claude --version 2>/dev/null`)+ )+ const out = stdout.trim()+ return code === 0 && out ? out : null} catch {- return true+ return null}}+ /** Is the remote claude new enough to scope credentials per config dir? Returns true when it+ * can't be determined so remote account add is never blocked on detection (fail-open). */+ private async remoteClaudeVersionOk(c: Conn): Promise<boolean> {+ const version = await this.remoteClaudeVersion(c.conn, c.controlPath)+ if (!version) return true+ return isSupportedClaudeVersion(version)+ }+async disconnect(projectId: string): Promise<void> {const c = this.conns.get(projectId)if (!c) returndiff --git a/src/renderer/boot.tsx b/src/renderer/boot.tsxindex 417ad22b2..f585a553d 100644--- a/src/renderer/boot.tsx+++ b/src/renderer/boot.tsx@@ -1,9 +1,16 @@import React from 'react'import ReactDOM from 'react-dom/client'import App from './App'+import { ensureClaudeCliCaps } from './state/permissionMode'import './styles.css'import './tailwind.css'+// Probe the local Claude CLI once, up front (never awaited — a launch is never blocked on it):+// `--permission-mode auto` only exists in Claude Code >= 2.1.90, and until we know the version we+// conservatively omit the flag. The shell warms the same memo at startup, so this normally+// resolves immediately.+void ensureClaudeCliCaps()+// Note: StrictMode is intentionally not used — its double mount in dev would open// two PTY sessions per terminal node.ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(<App />)diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex b602e5013..7769de849 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -736,11 +736,11 @@ export function Canvas() {requireProOr('SSH Remote Projects', () => {window.nodeTerminal.sshProject.connect(project.id, ssh.server, ssh.remoteCwd)- .then(async ({ controlPath, hookEndpointPath, tmuxConfPath, remoteHome }) => {+ .then(async (info) => {// 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, tmuxConfPath, remoteHome })+ useSshConn.getState().setConn(project.id, info)}).catch(() => {/* status surfaced via onStatus → the connection banner */diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsxindex 5933a4b68..e5a6eab01 100644--- a/src/renderer/nodes/TerminalNode.tsx+++ b/src/renderer/nodes/TerminalNode.tsx@@ -32,7 +32,7 @@ import { useProjects } from '../state/projects'import { useSshConn } from '../state/sshConn'import { accountChipLabel, COLLAPSED_HEIGHT, NODE_COLORS, type CanvasNode } from '../state/workspace'import { hasHooks, canRecur, canContextLink, hasUsage, canChat, canResume, canRename, resumeCommand, withPermissionMode, agentConfig, type AgentId } from '@shared/agents/config'-import { activePermissionMode } from '../state/permissionMode'+import { ensureActivePermissionMode } from '../state/permissionMode'import { buildSshArgs, type SshConnection } from '@shared/ssh'/** Backslash-escape shell-special characters, like a native terminal does on file drop. */@@ -556,8 +556,10 @@ export function TerminalNode({ id, data, selected, parentId }: NodeProps<CanvasN// Re-resolve the mode at relaunch: it's a property of how a session is launched, not// a persisted property of the node, so the current setting wins after a reboot. `base`// is always freshly built here — never a command string read back from node data — so- // it can never end up double-flagged.- const cmd = base && withPermissionMode(base, agentId, activePermissionMode())+ // it can never end up double-flagged. Awaited (not the sync `activePermissionMode`)+ // because this fires on mount: right after a machine reboot it can beat the CLI version+ // probe, and an unanswered probe would conservatively drop `auto`.+ const cmd = base && withPermissionMode(base, agentId, await ensureActivePermissionMode())if (cmd) transport.write(sid, `${cmd}\n`)}})diff --git a/src/renderer/state/permissionMode.test.ts b/src/renderer/state/permissionMode.test.tsindex e4c36b5c6..7e883db93 100644--- a/src/renderer/state/permissionMode.test.ts+++ b/src/renderer/state/permissionMode.test.ts@@ -1,30 +1,61 @@-import { describe, it, expect, beforeEach } from 'vitest'-import { DEFAULT_SETTINGS } from '@shared/types'+import { describe, it, expect, beforeEach, vi } from 'vitest'+import { DEFAULT_SETTINGS, UNKNOWN_CLAUDE_CLI_CAPS, type ClaudeCliCaps } from '@shared/types'+import type { SshConnection } from '@shared/ssh'import { useProjects } from './projects'import { useSettings } from './settings'-import { activePermissionMode } from './permissionMode'+import { useSshConn } from './sshConn'+import {+ activePermissionMode,+ ensureActivePermissionMode,+ ensureClaudeCliCaps,+ resetClaudeCliCapsForTests+} from './permissionMode'++/** Stand in for the preload/bridge `claude.cliCaps()` probe. */+function mockCliCaps(caps: ClaudeCliCaps | Error): ReturnType<typeof vi.fn> {+ const fn = vi.fn(() => (caps instanceof Error ? Promise.reject(caps) : Promise.resolve(caps)))+ ;(globalThis as { window?: unknown }).window = { nodeTerminal: { claude: { cliCaps: fn } } }+ return fn+}++const MODERN: ClaudeCliCaps = { version: '2.1.207 (Claude Code)', autoPermissionMode: true }+const OLD: ClaudeCliCaps = { version: '2.1.50 (Claude Code)', autoPermissionMode: false }++const SSH_SERVER = { id: 's1', label: 'box', host: 'box', user: 'me' } as unknown as SshConnectionbeforeEach(() => {useProjects.getState().hydrate({ version: 2, activeProjectId: '', projects: [] })useSettings.setState({ settings: { ...DEFAULT_SETTINGS }, hydrated: false })+ useSshConn.setState({ byProject: {} })+ resetClaudeCliCapsForTests()+ mockCliCaps(MODERN)})+/** Adds a project and makes it active. */+function activeProject(name = 'p', ssh?: { server: SshConnection; remoteCwd: string }) {+ const p = useProjects.getState().addProject(name, '/tmp/p')+ if (ssh) useProjects.getState().replaceProject({ ...p, ssh })+ useProjects.getState().setActive(p.id)+ return p+}+describe('activePermissionMode', () => {- it('returns the global setting when the active project has no override', () => {+ it('returns the global setting when the active project has no override', async () => {useSettings.setState((s) => ({ settings: { ...s.settings, claudePermissionMode: 'plan' } }))- const p = useProjects.getState().addProject('my-app', '/tmp/my-app')- useProjects.getState().setActive(p.id)+ activeProject()+ await ensureClaudeCliCaps()expect(activePermissionMode()).toBe('plan')})- it("returns the active project's override, not another project's", () => {+ it("returns the active project's override, not another project's", async () => {useSettings.setState((s) => ({ settings: { ...s.settings, claudePermissionMode: 'auto' } }))const other = useProjects.getState().addProject('other', '/tmp/other')useProjects.getState().setProjectDefaultPermissionMode(other.id, 'bypassPermissions')const active = useProjects.getState().addProject('active', '/tmp/active')useProjects.getState().setProjectDefaultPermissionMode(active.id, 'acceptEdits')useProjects.getState().setActive(active.id)+ await ensureClaudeCliCaps()// The bug this test exists to catch: a stray project.find()-style lookup could pick up// the wrong project's override (e.g. the first one in the array) instead of the active one.@@ -32,11 +63,126 @@ describe('activePermissionMode', () => {expect(activePermissionMode()).not.toBe('bypassPermissions')})- it('falls back to the global setting when there is no active project', () => {+ it('falls back to the global setting when there is no active project', async () => {useSettings.setState((s) => ({ settings: { ...s.settings, claudePermissionMode: 'manual' } }))useProjects.getState().addProject('solo', '/tmp/solo')useProjects.getState().setActive('nonexistent-id')+ await ensureClaudeCliCaps()++ expect(activePermissionMode()).toBe('manual')+ })+})++// The whole point of the version gate: `auto` is our DEFAULT, and a Claude CLI < 2.1.90 exits 1+// on `--permission-mode auto`. Degrading to `manual` (= no flag) keeps every launch working.+describe('activePermissionMode — the `auto` version gate', () => {+ it('keeps auto when the local CLI is new enough', async () => {+ mockCliCaps(MODERN)+ activeProject()+ await ensureClaudeCliCaps()++ expect(activePermissionMode()).toBe('auto')+ })++ it('degrades auto to manual (bare command) when the local CLI is too old', async () => {+ mockCliCaps(OLD)+ activeProject()+ await ensureClaudeCliCaps()expect(activePermissionMode()).toBe('manual')})++ it('degrades auto to manual before the probe has answered (conservative)', () => {+ mockCliCaps(MODERN)+ activeProject()+ // Deliberately NOT awaiting ensureClaudeCliCaps: an unknown version means no flag.+ expect(activePermissionMode()).toBe('manual')+ })++ it('degrades auto to manual when the probe rejects', async () => {+ mockCliCaps(new Error('spawn ENOENT'))+ activeProject()+ await ensureClaudeCliCaps()++ expect(activePermissionMode()).toBe('manual')+ })++ it('never touches the other four modes, even with an old CLI', async () => {+ mockCliCaps(OLD)+ const p = activeProject()+ await ensureClaudeCliCaps()++ for (const mode of ['manual', 'acceptEdits', 'plan', 'bypassPermissions'] as const) {+ useProjects.getState().setProjectDefaultPermissionMode(p.id, mode)+ expect(activePermissionMode()).toBe(mode)+ }+ })++ it('probes once and caches (the CLI version does not change under a running app)', async () => {+ const fn = mockCliCaps(MODERN)+ activeProject()+ await Promise.all([ensureClaudeCliCaps(), ensureClaudeCliCaps()])+ await ensureClaudeCliCaps()++ expect(fn).toHaveBeenCalledTimes(1)+ })+})++// An SSH project's terminals run on the REMOTE host, whose claude CLI can be older than the local+// one. The local probe's answer must never be applied to a remote launch.+describe('activePermissionMode — SSH projects', () => {+ it('ignores the local CLI and uses the remote probe', async () => {+ mockCliCaps(MODERN) // local supports auto…+ const p = activeProject('remote', { server: SSH_SERVER, remoteCwd: '/srv/app' })+ await ensureClaudeCliCaps()+ // …but the remote does not.+ useSshConn.getState().setConn(p.id, { controlPath: '/tmp/cm', claudeAutoPermissionMode: false })++ expect(activePermissionMode()).toBe('manual')+ })++ it('keeps auto when the REMOTE host is known to support it', async () => {+ mockCliCaps(OLD) // local is old — irrelevant for a remote launch+ const p = activeProject('remote', { server: SSH_SERVER, remoteCwd: '/srv/app' })+ await ensureClaudeCliCaps()+ useSshConn.getState().setConn(p.id, { controlPath: '/tmp/cm', claudeAutoPermissionMode: true })++ expect(activePermissionMode()).toBe('auto')+ })++ it('omits auto while the project is not connected / not yet probed', async () => {+ mockCliCaps(MODERN)+ activeProject('remote', { server: SSH_SERVER, remoteCwd: '/srv/app' })+ await ensureClaudeCliCaps()+ // No sshConn entry at all: unknown remote version ⇒ bare command.+ expect(activePermissionMode()).toBe('manual')+ })++ it('still honors an explicitly chosen non-auto mode on an unprobed remote', async () => {+ mockCliCaps(MODERN)+ const p = activeProject('remote', { server: SSH_SERVER, remoteCwd: '/srv/app' })+ useProjects.getState().setProjectDefaultPermissionMode(p.id, 'plan')+ await ensureClaudeCliCaps()++ expect(activePermissionMode()).toBe('plan')+ })+})++describe('ensureActivePermissionMode', () => {+ it('awaits the probe, so a launch right after boot still gets auto', async () => {+ mockCliCaps(MODERN)+ activeProject()++ // Without the await this would be 'manual' (see the conservative case above).+ await expect(ensureActivePermissionMode()).resolves.toBe('auto')+ })++ it('resolves to the fail-open mode when the probe is unavailable', async () => {+ ;(globalThis as { window?: unknown }).window = {}+ resetClaudeCliCapsForTests()+ activeProject()++ await expect(ensureActivePermissionMode()).resolves.toBe('manual')+ expect(await ensureClaudeCliCaps()).toEqual(UNKNOWN_CLAUDE_CLI_CAPS)+ })})diff --git a/src/renderer/state/permissionMode.ts b/src/renderer/state/permissionMode.tsindex dacdf8ecd..73bd1b7b5 100644--- a/src/renderer/state/permissionMode.ts+++ b/src/renderer/state/permissionMode.ts@@ -1,10 +1,58 @@-import { resolvePermissionMode, type AgentPermissionMode } from '@shared/agents/config'+import { gatePermissionMode, resolvePermissionMode, type AgentPermissionMode } from '@shared/agents/config'+import { UNKNOWN_CLAUDE_CLI_CAPS, type ClaudeCliCaps, type Project } from '@shared/types'import { useProjects } from './projects'import { useSettings } from './settings'+import { useSshConn } from './sshConn'/**- * The permission mode a session launched right now should start in: the active project's- * override, else the global setting.+ * Local Claude CLI capabilities, probed once per app run through `claude.cliCaps()` (main/server →+ * core/claude-cli.ts). Kept as a module-level memo rather than a zustand store: nothing renders+ * from it — it is read only at the moment a launch command is built — and a store would invite+ * re-renders on a value that never changes while the app runs.+ *+ * Until the probe answers, `caps` is the FAIL-OPEN unknown: no `auto` flag, i.e. the bare `claude`+ * command. A launch is never blocked on the probe.+ */+let caps: ClaudeCliCaps = UNKNOWN_CLAUDE_CLI_CAPS+let capsPromise: Promise<ClaudeCliCaps> | null = null++/** Kick off (or join) the local CLI probe. Never rejects. Called once at boot; awaited by any+ * launch path that can run before boot settles (a cold-restored agent node). */+export function ensureClaudeCliCaps(): Promise<ClaudeCliCaps> {+ if (!capsPromise) {+ capsPromise = Promise.resolve()+ .then(() => window.nodeTerminal.claude.cliCaps())+ .then((c) => (caps = c ?? UNKNOWN_CLAUDE_CLI_CAPS))+ .catch(() => UNKNOWN_CLAUDE_CLI_CAPS)+ }+ return capsPromise+}++/** Test seam: drop the memo (and optionally preload a known answer). */+export function resetClaudeCliCapsForTests(next?: ClaudeCliCaps): void {+ caps = next ?? UNKNOWN_CLAUDE_CLI_CAPS+ capsPromise = null+}++/**+ * Does the CLI that will actually RUN this project's sessions accept `--permission-mode auto`?+ *+ * An SSH project's terminals run on the remote host, whose claude can be OLDER than the local one+ * — so the local probe's answer is never applied to a remote launch. The remote is probed on its+ * own host at connect (SshProjectManager) and cached in `useSshConn`; not connected / not yet+ * probed / older CLI all answer false, which omits the flag (conservative, and exactly the+ * command nodeterm shipped before this setting existed).+ */+function autoSupportedFor(project: Project | undefined): boolean {+ if (project?.ssh) return useSshConn.getState().supportsAutoPermissionMode(project.id)+ return caps.autoPermissionMode+}++/**+ * The permission mode a session launched RIGHT NOW actually starts in: the active project's+ * override, else the global setting — with `auto` degraded to `manual` (no flag → bare command)+ * when the CLI that will run it is too old to know the value (Claude Code < 2.1.90, which exits 1+ * on it) or hasn't been probed yet. The other four modes are never touched by the gate.** Lives in its own module rather than in workspace.ts because projects.ts imports workspace.ts* (createProject) — importing the projects store from workspace.ts would close that cycle.@@ -12,5 +60,17 @@ import { useSettings } from './settings'export function activePermissionMode(): AgentPermissionMode {const { settings } = useSettings.getState()const { getProject, activeProjectId } = useProjects.getState()- return resolvePermissionMode(getProject(activeProjectId), settings)+ const project = getProject(activeProjectId)+ return gatePermissionMode(resolvePermissionMode(project, settings), autoSupportedFor(project))+}++/**+ * `activePermissionMode()` for callers that can run BEFORE the boot-time probe has answered — the+ * cold-restore agent relaunch fires on node mount. Awaiting the (memoized, warmed in the shell)+ * probe there means a rebooted machine still gets `auto`, instead of silently falling back to the+ * bare command for one session.+ */+export async function ensureActivePermissionMode(): Promise<AgentPermissionMode> {+ await ensureClaudeCliCaps()+ return activePermissionMode()}diff --git a/src/renderer/state/sshConn.ts b/src/renderer/state/sshConn.tsindex ca69fb0e1..34398d8fa 100644--- a/src/renderer/state/sshConn.ts+++ b/src/renderer/state/sshConn.ts@@ -13,6 +13,10 @@ export interface SshConnInfo {/** The connection's resolved remote `$HOME`. Used to build an ABSOLUTE remote* `CLAUDE_CONFIG_DIR` for a managed remote account. Optional: absent if it couldn't resolve. */remoteHome?: string+ /** Does the REMOTE host's claude CLI accept `--permission-mode auto` (>= 2.1.90)? Probed on the+ * host at connect — the local CLI's answer says nothing about the remote one. Absent/false ⇒+ * this project's Claude nodes launch with the bare command (no `auto` flag). */+ claudeAutoPermissionMode?: boolean}/**@@ -29,6 +33,9 @@ interface SshConnState {getHookEndpointPath(projectId: string): string | undefinedgetTmuxConfPath(projectId: string): string | undefinedgetRemoteHome(projectId: string): string | undefined+ /** True ONLY when the remote CLI was probed and is known to accept `--permission-mode auto`.+ * Not connected / never probed / older CLI all answer false (conservative — omit the flag). */+ supportsAutoPermissionMode(projectId: string): booleanclear(projectId: string): void}@@ -49,6 +56,9 @@ export const useSshConn = create<SshConnState>((set, get) => ({getRemoteHome(projectId) {return get().byProject[projectId]?.remoteHome},+ supportsAutoPermissionMode(projectId) {+ return get().byProject[projectId]?.claudeAutoPermissionMode === true+ },clear(projectId) {set((s) => {const next = { ...s.byProject }