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
feat(core): probe the local claude CLI's capabilities
enesb1cba810d707
diff --git a/src/core/claude-cli.test.ts b/src/core/claude-cli.test.tsnew file mode 100644index 000000000..4188abc8c--- /dev/null+++ b/src/core/claude-cli.test.ts@@ -0,0 +1,31 @@+import { describe, it, expect } from 'vitest'+import { claudeCliCapsFrom, UNKNOWN_CLAUDE_CLI_CAPS } from './claude-cli'++describe('claudeCliCapsFrom', () => {+ it('reads a real `claude --version` line', () => {+ expect(claudeCliCapsFrom('2.1.207 (Claude Code)\n')).toEqual({+ version: '2.1.207 (Claude Code)',+ autoPermissionMode: true+ })+ })++ it('marks an older CLI as not knowing `auto` (it would exit 1 on the flag value)', () => {+ expect(claudeCliCapsFrom('2.1.50 (Claude Code)')).toEqual({+ version: '2.1.50 (Claude Code)',+ autoPermissionMode: false+ })+ })++ it('collapses no output to the fail-open caps (no version → no auto → bare command)', () => {+ expect(claudeCliCapsFrom(null)).toEqual(UNKNOWN_CLAUDE_CLI_CAPS)+ expect(claudeCliCapsFrom(undefined)).toEqual(UNKNOWN_CLAUDE_CLI_CAPS)+ expect(claudeCliCapsFrom(' ')).toEqual(UNKNOWN_CLAUDE_CLI_CAPS)+ })++ it('never claims `auto` from output it cannot parse a version out of', () => {+ // `version` is diagnostic only (it's whatever the CLI printed); the load-bearing field is the+ // capability, which must stay false for anything that isn't a readable version.+ expect(claudeCliCapsFrom('claude: command not found').autoPermissionMode).toBe(false)+ expect(claudeCliCapsFrom('some unrelated banner').autoPermissionMode).toBe(false)+ })+})diff --git a/src/core/claude-cli.ts b/src/core/claude-cli.tsnew file mode 100644index 000000000..d525c0e8b--- /dev/null+++ b/src/core/claude-cli.ts@@ -0,0 +1,61 @@+// Capability probe for the LOCAL Claude CLI. Today it answers exactly one question — does this+// CLI accept `--permission-mode auto`? (Claude Code >= 2.1.90; older CLIs exit 1 on the value, see+// AUTO_PERMISSION_MODE_MIN_VERSION) — but it is shaped as a caps bag so the next version-gated+// flag lands here instead of growing another probe.+//+// Lives in core (not main) so the Server Edition boots it through the same CorePlatform seam.+// The remote (SSH) CLI is probed separately on its own host — see SshProjectManager.+import { execFile } from 'child_process'+import { promisify } from 'util'+import { supportsAutoPermissionMode } from '../shared/agents/config'+import { IPC } from '../shared/ipc'+import { UNKNOWN_CLAUDE_CLI_CAPS, type ClaudeCliCaps } from '../shared/types'+import { findInLoginPath } from './pty-manager'+import { platform } from './platform'++const execFileP = promisify(execFile)+const PROBE_TIMEOUT_MS = 5000++export { UNKNOWN_CLAUDE_CLI_CAPS, type ClaudeCliCaps }++/** Pure: `claude --version` output → caps. The impure probe below is just plumbing around it. */+export function claudeCliCapsFrom(versionOutput: string | null | undefined): ClaudeCliCaps {+ const version = versionOutput?.trim() || null+ return { version, autoPermissionMode: supportsAutoPermissionMode(version) }+}++let cached: Promise<ClaudeCliCaps> | null = null++async function probe(): Promise<ClaudeCliCaps> {+ try {+ // GUI apps don't inherit the shell PATH — resolve through the login shell like every other+ // CLI lookup in the app (pty-manager, commit-message).+ const bin = await findInLoginPath('claude')+ if (!bin) return UNKNOWN_CLAUDE_CLI_CAPS+ const { stdout } = await execFileP(bin, ['--version'], { timeout: PROBE_TIMEOUT_MS })+ return claudeCliCapsFrom(stdout)+ } catch {+ // Missing CLI, timeout, non-zero exit — all mean "unknown", which means "omit the flag".+ return UNKNOWN_CLAUDE_CLI_CAPS+ }+}++/**+ * The local Claude CLI's capabilities. Memoized for the process lifetime: `claude --version`+ * spawns a login shell + node, and the answer only changes when the user upgrades the CLI (a+ * relaunch — or a manual `refresh` — picks that up). Never rejects.+ */+export function claudeCliCaps(): Promise<ClaudeCliCaps> {+ if (!cached) cached = probe()+ return cached+}++/** Drop the memo so the next call re-probes (used by the tests; also survives a CLI upgrade). */+export function resetClaudeCliCaps(): void {+ cached = null+}++/** Wire the probe onto the platform's RPC surface (Electron ipcMain / server WS-RPC alike). */+export function registerClaudeCliIpc(): void {+ platform().handle(IPC.claudeCliCaps, () => claudeCliCaps())+}diff --git a/src/main/index.ts b/src/main/index.tsindex 5b2fab993..f32e4d3a1 100644--- a/src/main/index.ts+++ b/src/main/index.ts@@ -46,6 +46,7 @@ import { initTelemetry } from './telemetry'import { initClaudeUsage } from './claude-usage'import { initLicense, isPremium, getStoredEntitlement } from '../core/license'import { initClaudeAccounts } from './claude-accounts'+import { claudeCliCaps, registerClaudeCliIpc } from '../core/claude-cli'import { claudeConfigDirFor } from '../core/claude-config-dir'import { isSafeLocalTranscriptPath } from '../core/claude-accounts-core'import { installClaudeHooksInto } from '../core/agents/hooks/claude'@@ -324,6 +325,11 @@ app.whenReady().then(async () => {ptyManager.registerIpc()workspaceStore.registerIpc()gitService.registerIpc()+ registerClaudeCliIpc()+ // Warm the `claude --version` probe now (it spawns a login shell + node, ~sub-second) so the+ // renderer's first `claude.cliCaps()` — awaited on the launch path of a cold-restored agent+ // node — resolves from cache instead of racing the probe into a conservative "no auto".+ void claudeCliCaps()ipcMain.handle(IPC.commitGenerate, (_e, cwd: string) =>generateCommitMessage(cwd, settingsStore.get())diff --git a/src/preload/index.ts b/src/preload/index.tsindex af7791bb1..f0d843299 100644--- a/src/preload/index.ts+++ b/src/preload/index.ts@@ -268,6 +268,7 @@ const api: NodeTerminalApi = {ipcRenderer.send(IPC.contextEnsure, sessionId, cwd, accountId)},claude: {+ cliCaps: () => ipcRenderer.invoke(IPC.claudeCliCaps),readTranscript: (sessionId, cwd, accountId) =>ipcRenderer.invoke(IPC.claudeReadTranscript, sessionId, cwd, accountId)},diff --git a/src/renderer/bridge/stubs.ts b/src/renderer/bridge/stubs.tsindex c8b2086d8..0e20dff82 100644--- a/src/renderer/bridge/stubs.ts+++ b/src/renderer/bridge/stubs.ts@@ -13,7 +13,13 @@// | 'files' | 'context' | 'dialog'>`, so the TypeScript compiler is the completeness test: if// `NodeTerminalApi` gains a member, this file fails to typecheck until the stub is declared.-import type { ClaudeUsage, NodeTerminalApi, NotifyPayload, UpdatePolicy } from '../../shared/types'+import {+ UNKNOWN_CLAUDE_CLI_CAPS,+ type ClaudeUsage,+ type NodeTerminalApi,+ type NotifyPayload,+ type UpdatePolicy+} from '../../shared/types'import { E_UNSUPPORTED } from '../../shared/rpc'/** Reject with a coded error the RPC layer + renderer recognize (renderer degrades silently). */@@ -133,6 +139,9 @@ export function buildStubApi(): Omit<onUpdate: noopUnsub},claude: {+ // Overridden by the real WS-backed namespace in ws-bridge; the stub still answers with the+ // fail-open caps (never rejects) because the permission-mode gate reads it on the boot path.+ cliCaps: () => Promise.resolve(UNKNOWN_CLAUDE_CLI_CAPS),readTranscript: U('claude.readTranscript')},chat: {diff --git a/src/renderer/bridge/ws-bridge.ts b/src/renderer/bridge/ws-bridge.tsindex 152c4e4e3..37a7b6ba8 100644--- a/src/renderer/bridge/ws-bridge.ts+++ b/src/renderer/bridge/ws-bridge.ts@@ -8,18 +8,21 @@import { parseRpcMessage, decodePtyData, type RpcMessage } from '../../shared/rpc'import { IPC } from '../../shared/ipc'-import type {- ContextApi,- FilesApi,- FsApi,- GitApi,- NodeTerminalApi,- PtyApi,- PtyCreateOptions,- SettingsApi,- Settings,- Workspace,- WorkspaceApi+import {+ UNKNOWN_CLAUDE_CLI_CAPS,+ type ClaudeApi,+ type ClaudeCliCaps,+ type ContextApi,+ type FilesApi,+ type FsApi,+ type GitApi,+ type NodeTerminalApi,+ type PtyApi,+ type PtyCreateOptions,+ type SettingsApi,+ type Settings,+ type Workspace,+ type WorkspaceApi} from '../../shared/types'import { buildStubApi } from './stubs'import { mountPickerRoot, openDirectoryPicker } from './dialog-picker'@@ -329,6 +332,24 @@ export function buildAgentApi(}}+/**+ * Build the `claude` namespace over an RpcClient. `cliCaps` is a REAL handler on the server+ * (`registerClaudeCliIpc` runs in the server shell too), so the browser resolves the very same+ * `--permission-mode auto` version gate as desktop instead of silently no-opping into "auto+ * unsupported" — which would strip the flag from every Claude launch in the Server Edition.+ * A failed request degrades to the fail-open caps (bare command), never a rejection: the launch+ * path awaits this. `readTranscript` has no server handler yet, so it keeps the stub's reject.+ */+export function buildClaudeApi(client: RpcClient, stub: ClaudeApi): ClaudeApi {+ return {+ ...stub,+ cliCaps: () =>+ (client.request(IPC.claudeCliCaps) as Promise<ClaudeCliCaps>).catch(+ () => UNKNOWN_CLAUDE_CLI_CAPS+ )+ }+}+/** WS URL for the current page: same host, `/ws`, ws→http / wss→https. */function wsUrl(): string {const scheme = location.protocol === 'https:' ? 'wss' : 'ws'@@ -433,11 +454,14 @@ export async function installWsBridge(): Promise<boolean> {return false}client.onClose(() => startReconnect())+ const stubApi = buildStubApi()const api: NodeTerminalApi = {- ...buildStubApi(),+ ...stubApi,...buildRealApi(client),...buildFilesApi(client),...buildAgentApi(client),+ // Only `cliCaps` is real here — the rest of the namespace stays stubbed (see buildClaudeApi).+ claude: buildClaudeApi(client, stubApi.claude),// Web replacement for the Electron native dialog: an in-app server-directory browser over// fs.list (the stub's E_UNSUPPORTED reject is dropped in favor of this real picker).dialog: (() => {diff --git a/src/server/handlers/index.ts b/src/server/handlers/index.tsindex 1af6cba50..56753ef6d 100644--- a/src/server/handlers/index.ts+++ b/src/server/handlers/index.ts@@ -3,6 +3,7 @@ import type { ServerPlatform } from '../platform-server'import { GitService } from '../../core/git-service'import { generateCommitMessage } from '../../core/commit-message'import { registerFsHandlers } from './fs'+import { claudeCliCaps, registerClaudeCliIpc } from '../../core/claude-cli'import { IPC } from '../../shared/ipc'/** Register the Phase-3a handler surface (fs + git + commit) on the server platform.@@ -25,5 +26,10 @@ export function registerCoreHandlers(// Local server has no SSH projects; keep git running against the local remote.platform.handle(IPC.gitSetActiveRemote, () => null)+ // The browser needs the same `--permission-mode auto` version gate as desktop: the server's own+ // claude CLI is the one that will run the terminal nodes. Warm it so the first call is cached.+ registerClaudeCliIpc()+ void claudeCliCaps()+return { gitService }}diff --git a/src/shared/ipc.ts b/src/shared/ipc.tsindex 8629d9c4e..2f65655d2 100644--- a/src/shared/ipc.ts+++ b/src/shared/ipc.ts@@ -26,6 +26,7 @@ export const IPC = {claudeAccountsWaitLogin: 'claude-accounts:wait-login',claudeAccountsCancelWait: 'claude-accounts:cancel-wait',claudeAccountsRemove: 'claude-accounts:remove',+ claudeCliCaps: 'claude-cli:caps',transcriptSearch: 'transcript:search',appToggleMarkdown: 'app:toggle-markdown',appCloseNode: 'app:close-node',diff --git a/src/shared/types.ts b/src/shared/types.tsindex 8f34dc063..5713af8ae 100644--- a/src/shared/types.ts+++ b/src/shared/types.ts@@ -440,7 +440,14 @@ export interface SshProjectApi {projectId: string,server: import('./ssh').SshConnection,remoteCwd?: string- ): Promise<{ controlPath: string; hookEndpointPath?: string; tmuxConfPath?: string; remoteHome?: string }>+ ): Promise<{+ controlPath: string+ hookEndpointPath?: string+ tmuxConfPath?: string+ remoteHome?: string+ /** Whether the REMOTE host's claude CLI accepts `--permission-mode auto` (probed on connect). */+ claudeAutoPermissionMode?: boolean+ }>/** Tear down the master (remote tmux is unaffected). */disconnect(projectId: string): Promise<void>/**@@ -856,7 +863,22 @@ export interface TranscriptsApi {search(query: string): Promise<TranscriptHit[]>}+/** What the Claude CLI on THIS machine can do. Fed by the `claude --version` probe in+ * core/claude-cli.ts; every field fails open to the conservative answer when the version+ * is unknown (missing CLI, timeout, unreadable output). */+export interface ClaudeCliCaps {+ version: string | null+ /** `--permission-mode auto` is only accepted by Claude Code >= 2.1.90. */+ autoPermissionMode: boolean+}++/** The answer whenever the CLI version can't be determined: no `auto` flag → bare command. */+export const UNKNOWN_CLAUDE_CLI_CAPS: ClaudeCliCaps = { version: null, autoPermissionMode: false }+export interface ClaudeApi {+ /** Capabilities of the local Claude CLI (memoized in the shell; safe to call repeatedly).+ * Never rejects — an unknown version resolves to the fail-open caps. */+ cliCaps(): Promise<ClaudeCliCaps>/*** Reads a Claude session's full transcript as flat searchable lines ([] if unavailable).* Resolves by `sessionId` when known (exact); otherwise falls back to `cwd` (durable —