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(accounts): chat node runs on the node's managed account

enese95ff365c660
diff --git a/src/main/chat-driver.ts b/src/main/chat-driver.ts
index 2223fd34d..65b1a3ffd 100644
--- a/src/main/chat-driver.ts
+++ b/src/main/chat-driver.ts
@@ -8,6 +8,8 @@ import type { NormalizedAgentEvent } from '../shared/agents/normalize'
import { sdkMessageToEvents } from './chat-events'
import { ChatInputQueue, createPushIterable } from './chat-queue'
import { resolveTranscriptPath } from './transcript-reader'
+import { claudeConfigDirFor } from './claude-accounts'
+import { AUTH_ENV_STRIP } from './claude-accounts-core'
interface PendingPermission { resolve: (d: ChatPermissionDecision) => void }
@@ -15,6 +17,8 @@ interface ChatSession {
nodeId: string
cwd?: string
sessionId?: string
+ // Managed account this chat runs on (its CLAUDE_CONFIG_DIR); undefined = default login.
+ accountId?: string
working: boolean
input: ReturnType<typeof createPushIterable<unknown>>
queue: ChatInputQueue
@@ -62,18 +66,18 @@ export class ChatDriver {
async ensure(
nodeId: string,
- opts: { cwd?: string; sessionId?: string; fork?: boolean }
+ opts: { cwd?: string; sessionId?: string; fork?: boolean; accountId?: string }
): Promise<{ ok: boolean; error?: string }> {
if (this.sessions.has(nodeId)) return { ok: true }
// Resume validation: a sessionId whose transcript is gone would silently start a
- // fresh session with mismatched history — surface it instead.
+ // fresh session with mismatched history — surface it instead. Look in the account dir.
let resume = opts.sessionId
- if (resume && !(await resolveTranscriptPath(resume))) {
+ if (resume && !(await resolveTranscriptPath(resume, opts.accountId))) {
this.emit(nodeId, { kind: 'error', message: 'Previous session transcript not found — starting fresh.' })
resume = undefined
}
const s: ChatSession = {
- nodeId, cwd: opts.cwd, sessionId: resume, working: false,
+ nodeId, cwd: opts.cwd, sessionId: resume, accountId: opts.accountId, working: false,
input: createPushIterable<unknown>(), queue: new ChatInputQueue(),
pending: new Map(), allowedForSession: new Set(),
interruptedByUser: false, disposed: false
@@ -99,6 +103,18 @@ export class ChatDriver {
cwd: s.cwd,
...(resume ? { resume } : {}),
...(fork ? { forkSession: true } : {}),
+ // Managed account: the SDK's claude subprocess inherits this env, so credentials
+ // AND the transcript live in the account dir. AUTH_ENV_STRIP mirrors the PTY path.
+ // Account-less sessions get no env option at all (inherit the default login untouched).
+ ...(s.accountId
+ ? {
+ env: (() => {
+ const env: NodeJS.ProcessEnv = { ...process.env, CLAUDE_CONFIG_DIR: claudeConfigDirFor(s.accountId) }
+ for (const k of AUTH_ENV_STRIP) delete env[k]
+ return env as Record<string, string>
+ })()
+ }
+ : {}),
includePartialMessages: true,
permissionMode: 'default',
canUseTool: async (toolName: string, input: Record<string, unknown>, { toolUseID }: { toolUseID: string }) => {
diff --git a/src/main/index.ts b/src/main/index.ts
index ff0bb2505..cd3de9b32 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -477,11 +477,12 @@ app.whenReady().then(async () => {
// need a live hook event.
const resolveTranscript = async (
sessionId: string | undefined,
- cwd: string | undefined
+ cwd: string | undefined,
+ accountId?: string
): Promise<string | undefined> => {
let p: string | undefined
if (sessionId && SESSION_ID_RE.test(sessionId)) {
- p = contextTail.pathFor(sessionId) ?? (await resolveTranscriptPath(sessionId))
+ p = contextTail.pathFor(sessionId) ?? (await resolveTranscriptPath(sessionId, accountId))
}
if (!p && cwd) p = await transcriptPathForCwd(cwd)
return p
@@ -506,13 +507,18 @@ app.whenReady().then(async () => {
ipcMain.handle(
IPC.chatReadTranscript,
- async (_e, sessionId: string | undefined, cwd: string | undefined) => {
+ async (
+ _e,
+ sessionId: string | undefined,
+ cwd: string | undefined,
+ accountId: string | undefined
+ ) => {
const ref = sessionId ? remoteTranscriptBySession.get(sessionId) : undefined
if (ref) {
const text = await remoteFile.readTail(ref, REMOTE_TRANSCRIPT_CAP)
return parseChatMessages(text.split('\n'))
}
- const p = await resolveTranscript(sessionId, cwd)
+ const p = await resolveTranscript(sessionId, cwd, accountId)
return p ? readChatMessages(p) : []
}
)
diff --git a/src/preload/index.ts b/src/preload/index.ts
index de4c381cb..6dfc13bfb 100644
--- a/src/preload/index.ts
+++ b/src/preload/index.ts
@@ -259,8 +259,8 @@ const api: NodeTerminalApi = {
ipcRenderer.invoke(IPC.claudeReadTranscript, sessionId, cwd)
},
chat: {
- readTranscript: (sessionId, cwd) =>
- ipcRenderer.invoke(IPC.chatReadTranscript, sessionId, cwd),
+ readTranscript: (sessionId, cwd, accountId) =>
+ ipcRenderer.invoke(IPC.chatReadTranscript, sessionId, cwd, accountId),
ensure: (nodeId, opts) => ipcRenderer.invoke(IPC.chatEnsure, nodeId, opts),
send: (nodeId, text, images) => ipcRenderer.send(IPC.chatSend, nodeId, text, images),
interrupt: (nodeId) => ipcRenderer.send(IPC.chatInterrupt, nodeId),
diff --git a/src/renderer/nodes/ChatNode.tsx b/src/renderer/nodes/ChatNode.tsx
index ac0e2d50f..d1cd65edf 100644
--- a/src/renderer/nodes/ChatNode.tsx
+++ b/src/renderer/nodes/ChatNode.tsx
@@ -55,11 +55,13 @@ export default function ChatNode({ id, data, selected }: NodeProps<CanvasNode>)
// Fork path (Task 10): until our own session id arrives, resume the SOURCE session with
// fork:true; once the driver's `session` event persists chatSessionId, forkFrom is ignored.
const sessionId = own ?? forkFrom
- if (sessionId) void window.nodeTerminal.chat.readTranscript(sessionId, data.cwd as string | undefined).then((m) => seed(id, m))
+ const accountId = data.accountId as string | undefined
+ if (sessionId) void window.nodeTerminal.chat.readTranscript(sessionId, data.cwd as string | undefined, accountId).then((m) => seed(id, m))
void window.nodeTerminal.chat.ensure(id, {
cwd: data.cwd as string | undefined,
sessionId,
- fork: !own && !!forkFrom ? true : undefined
+ fork: !own && !!forkFrom ? true : undefined,
+ accountId
})
return off
// eslint-disable-next-line react-hooks/exhaustive-deps
@@ -328,7 +330,8 @@ export default function ChatNode({ id, data, selected }: NodeProps<CanvasNode>)
clearError(id)
void window.nodeTerminal.chat.ensure(id, {
cwd: data.cwd as string | undefined,
- sessionId: data.chatSessionId as string | undefined
+ sessionId: data.chatSessionId as string | undefined,
+ accountId: data.accountId as string | undefined
})
}}
>
diff --git a/src/shared/types.ts b/src/shared/types.ts
index afa48377e..8c7d501b1 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -755,12 +755,13 @@ export interface ChatApi {
*/
readTranscript(
sessionId: string | undefined,
- cwd: string | undefined
+ cwd: string | undefined,
+ accountId?: string
): Promise<ChatMessage[]>
/** Start (or reattach) the driver for a node. fork=true resumes by forking (terminal takeover). */
ensure(
nodeId: string,
- opts: { cwd?: string; sessionId?: string; fork?: boolean }
+ opts: { cwd?: string; sessionId?: string; fork?: boolean; accountId?: string }
): Promise<{ ok: boolean; error?: string }>
send(nodeId: string, text: string, images?: ChatImageAttachment[]): void
interrupt(nodeId: string): void