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(naming): run ✦ Name with AI under the node's Claude account; never adopt CLI errors as titles
review9a506fa07779
diff --git a/src/core/commit-message.test.ts b/src/core/commit-message.test.tsindex 594cd705e..2fef861e8 100644--- a/src/core/commit-message.test.ts+++ b/src/core/commit-message.test.ts@@ -202,3 +202,25 @@ describe.skipIf(process.platform !== 'win32')('runAgent — Windows npm shim', (})})})++describe('AI naming account + error output', () => {+ it('treats a CLI auth error printed to stdout as a failure, not an answer', async () => {+ const { isCliErrorOutput } = await import('./commit-message')+ expect(isCliErrorOutput('Failed to authenticate: OAuth session expired')).toBe(true)+ expect(isCliErrorOutput('Invalid API key · Please run /login')).toBe(true)+ expect(isCliErrorOutput('API Error: 401 {"type":"error"}')).toBe(true)+ expect(isCliErrorOutput('Refactor Auth Flow')).toBe(false)+ })++ it('runs under the account config dir with shadowing auth vars stripped', async () => {+ const { claudeAccountEnv } = await import('./commit-message')+ const env = claudeAccountEnv(+ { PATH: '/bin', ANTHROPIC_API_KEY: 'k', CLAUDE_CODE_OAUTH_TOKEN: 't' },+ '/data/claude-accounts/a1'+ )+ expect(env.CLAUDE_CONFIG_DIR).toBe('/data/claude-accounts/a1')+ expect(env.ANTHROPIC_API_KEY).toBeUndefined()+ expect(env.CLAUDE_CODE_OAUTH_TOKEN).toBeUndefined()+ expect(env.PATH).toBe('/bin')+ })+})diff --git a/src/core/commit-message.ts b/src/core/commit-message.tsindex 4659349dd..23cc16972 100644--- a/src/core/commit-message.ts+++ b/src/core/commit-message.ts@@ -6,6 +6,7 @@ import { promisify } from 'util'import type { GitResult, Settings } from '../shared/types'import { directExecutableInvocation, findInPathString, shellPathNow } from './exec-path'import { resolveGitRemote, runRemoteGit } from './remote-ssh/remote-git'+import { AUTH_ENV_STRIP } from './claude-accounts-core'const run = promisify(execFile)@@ -176,7 +177,8 @@ function spawnAgent(bin: string,args: string[],cwd: string,- stdin: string | null+ stdin: string | null,+ env: NodeJS.ProcessEnv = process.env): Promise<{ code: number; stdout: string; stderr: string }> {return new Promise((resolve) => {const invocation = directExecutableInvocation(bin, args)@@ -188,7 +190,7 @@ function spawnAgent(const child = spawn(invocation.executable, invocation.args, {...invocation.options,cwd,- env: process.env,+ env,stdio: ['pipe', 'pipe', 'pipe'],windowsHide: true})@@ -286,15 +288,46 @@ export function localAgentCwd(cwd: string, isRemote: boolean, home: string): strreturn !cwd || isRemote ? home : cwd}+/**+ * The env for running an agent under a managed Claude account: `CLAUDE_CONFIG_DIR` points at the+ * account's dir and the auth vars that would shadow its OAuth login are stripped — the same two+ * moves `PtyManager` makes for the node's own session, so a one-shot request goes out as the same+ * identity the node runs as.+ */+export function claudeAccountEnv(base: NodeJS.ProcessEnv, configDir: string): NodeJS.ProcessEnv {+ const env: NodeJS.ProcessEnv = { ...base, CLAUDE_CONFIG_DIR: configDir }+ for (const k of AUTH_ENV_STRIP) delete env[k]+ return env+}++/**+ * A CLI error printed where the answer should be. `claude -p` writes "Failed to authenticate: …" /+ * "Invalid API key …" / "API Error: …" to STDOUT, so the exit code alone is not enough evidence —+ * and treating that line as the answer is how a node ended up titled "Failed to authenticate: OAuth s…".+ */+const CLI_ERROR_OUTPUT =+ /^(failed to authenticate|invalid api key|api error|error:|oauth token|authentication_error|please run \/login|credit balance is too low)/i++export function isCliErrorOutput(message: string): boolean {+ return CLI_ERROR_OUTPUT.test(message.trim())+}+/** Plan + spawn the configured agent on a prompt and return its cleaned output. */-export async function runAgent(prompt: string, cwd: string, settings: Settings): Promise<GitResult> {+export async function runAgent(+ prompt: string,+ cwd: string,+ settings: Settings,+ env?: NodeJS.ProcessEnv+): Promise<GitResult> {const plan = planAgent(settings, prompt)if ('error' in plan) return { ok: false, message: plan.error }const spawnCwd = localAgentCwd(cwd, !!resolveGitRemote(cwd), os.homedir())- const res = await spawnAgent(plan.bin, plan.args, spawnCwd, plan.stdin)+ const res = await spawnAgent(plan.bin, plan.args, spawnCwd, plan.stdin, env)const message = cleanMessage(res.stdout)- if (res.code !== 0 && !message) {+ // A nonzero exit is a failure even when stdout has text: that text is the CLI's error message,+ // never an answer. Same for a known error line on a zero exit.+ if (res.code !== 0 || isCliErrorOutput(message)) {return { ok: false, message: extractError(res.stderr || res.stdout) }}if (!message) return { ok: false, message: 'Agent produced no output.' }@@ -305,7 +338,8 @@ export async function runAgent(prompt: string, cwd: string, settings: Settings):export async function generateTerminalName(content: string,cwd: string,- settings: Settings+ settings: Settings,+ env?: NodeJS.ProcessEnv): Promise<GitResult> {const trimmed = content.trim()if (!trimmed) return { ok: false, message: 'No terminal output to read yet.' }@@ -316,7 +350,7 @@ Terminal output:\`\`\`${clip}\`\`\``- const r = await runAgent(prompt, cwd, settings)+ const r = await runAgent(prompt, cwd, settings, env)if (!r.ok) return rconst name = r.message.split('\n')[0]diff --git a/src/main/index.ts b/src/main/index.tsindex aeeb0727a..4cc26f203 100644--- a/src/main/index.ts+++ b/src/main/index.ts@@ -141,7 +141,12 @@ import {MODEL_GATEWAY_SECRET_FILE,ModelGatewayCredentialService} from '../core/model-gateway-credentials'-import { generateCommitMessage, generateGroupName, generateTerminalName } from '../core/commit-message'+import {+ claudeAccountEnv,+ generateCommitMessage,+ generateGroupName,+ generateTerminalName+} from '../core/commit-message'import { initUpdater } from './updater'import { fetchCheck } from '../core/check'import {@@ -1516,12 +1521,27 @@ app.whenReady().then(async () => {const localNamingCwd = (keys: string[], cwd: string): string =>keys.some((k) => ptyManager.sshRemoteForNode(k)) ? '' : cwd- corePlatform.handle(IPC.ptyGenerateName, async (persistKey: string, cwd: string) =>- generateTerminalName(- await ptyManager.captureSession(persistKey),- localNamingCwd([persistKey], cwd),- settingsStore.get()- )+ // The naming agent runs under the NODE's managed Claude account (same resolution as the pty+ // spawn: a known, non-pending local account whose dir exists), else the system `~/.claude`.+ // Without this every ✦ request went out as the system login — which may be logged out or+ // expired even while the node's own account works fine.+ const namingEnv = (accountId?: string): NodeJS.ProcessEnv | undefined => {+ if (!accountId) return undefined+ const acct = settingsStore.get().claudeAccounts.find((a) => a.id === accountId)+ if (!acct || acct.pending || acct.host) return undefined+ const dir = claudeConfigDirFor(accountId)+ return existsSync(dir) ? claudeAccountEnv(process.env, dir) : undefined+ }++ corePlatform.handle(+ IPC.ptyGenerateName,+ async (persistKey: string, cwd: string, accountId?: string) =>+ generateTerminalName(+ await ptyManager.captureSession(persistKey),+ localNamingCwd([persistKey], cwd),+ settingsStore.get(),+ namingEnv(accountId)+ ))corePlatform.handle(IPC.ptyGenerateGroupName, async (memberKeys: string[], cwd: string) => {diff --git a/src/preload/index.ts b/src/preload/index.tsindex b44617016..a25a441fd 100644--- a/src/preload/index.ts+++ b/src/preload/index.ts@@ -90,7 +90,8 @@ const api: NodeTerminalApi = {destroy: (persistKey, opts) =>ipcRenderer.send(IPC.ptyDestroy, persistKey, opts?.everySocket === true),recycle: (persistKey) => ipcRenderer.send(IPC.ptyRecycle, persistKey),- generateName: (persistKey, cwd) => ipcRenderer.invoke(IPC.ptyGenerateName, persistKey, cwd),+ generateName: (persistKey, cwd, accountId) =>+ ipcRenderer.invoke(IPC.ptyGenerateName, persistKey, cwd, accountId),generateGroupName: (memberKeys, cwd) =>ipcRenderer.invoke(IPC.ptyGenerateGroupName, memberKeys, cwd),capture: (persistKey, full) => ipcRenderer.invoke(IPC.ptyCapture, persistKey, full),diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex e87f735a0..8eb4035bf 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -15427,7 +15427,15 @@ export function Canvas() {// unmounting mid-request; this Canvas-level call completes and applies the name anyway.useSessionNaming.getState().set(id, true)try {- const r = await api.pty.generateName(id, cwd ?? '')+ // The node's managed Claude account, so the naming request runs under the same login the+ // node does (live node first, then the serialized one for a non-active project).+ const accountId =+ (nodesRef.current.find((n) => n.id === id)?.data.accountId as string | undefined) ??+ useProjects+ .getState()+ .projects.find((p) => p.id === projectId)+ ?.nodes.find((n) => n.id === id)?.accountId+ const r = await api.pty.generateName(id, cwd ?? '', accountId)if (r.ok) renameSession(projectId, id, r.message)} finally {useSessionNaming.getState().set(id, false)diff --git a/src/renderer/components/kanban/CardModal.tsx b/src/renderer/components/kanban/CardModal.tsxindex 517433c3e..eab65b21a 100644--- a/src/renderer/components/kanban/CardModal.tsx+++ b/src/renderer/components/kanban/CardModal.tsx@@ -243,7 +243,7 @@ export function CardModal({ session, columnTitle, board, onChangeBoard, onClose,const nameWithAi = async () => {setNaming(true)- const r = await api.pty.generateName(session.id, session.spawn.cwd ?? '')+ const r = await api.pty.generateName(session.id, session.spawn.cwd ?? '', session.spawn.accountId)setNaming(false)if (r.ok) onRename(r.message)}diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsxindex 1b8cf6cbc..d5bca9711 100644--- a/src/renderer/nodes/TerminalNode.tsx+++ b/src/renderer/nodes/TerminalNode.tsx@@ -5655,7 +5655,11 @@ export function TerminalNode({// return the same name back, and clicking "Name with AI" repeatedly must not spam /rename.const nameWithAi = async () => {setNaming(true)- const r = await api.pty.generateName(id, (data.cwd as string) ?? '')+ const r = await api.pty.generateName(+ id,+ (data.cwd as string) ?? '',+ data.accountId as string | undefined+ )setNaming(false)if (r.ok) {const current = titleRef.current ?? (data.title as string) ?? ''diff --git a/src/shared/types.ts b/src/shared/types.tsindex acf4a7f19..75638af4c 100644--- a/src/shared/types.ts+++ b/src/shared/types.ts@@ -1249,8 +1249,10 @@ export interface PtyApi {* worktree"). Same tmux kill as `destroy`, opposite intent: the node stays on the canvas, so* co-viewers get `onRecycled` (restart + re-attach), never the permanent closed state. */recycle(persistKey: string): void- /** Suggest a terminal title from its recent output via the configured AI agent. */- generateName(persistKey: string, cwd: string): Promise<GitResult>+ /** Suggest a terminal title from its recent output via the configured AI agent. `accountId` is+ * the node's managed Claude account (trailing + optional: absent = system `~/.claude`), so the+ * naming request runs under the same login the node itself does. */+ generateName(persistKey: string, cwd: string, accountId?: string): Promise<GitResult>/** Suggest a group title from its member terminals' recent output via the configured AI agent. */generateGroupName(memberKeys: string[], cwd: string): Promise<GitResult>/** Capture a terminal session's output as text. `full` grabs the entire scrollback. */