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(chat): shared contract — ChatEvent types, chat:* IPC, preload API

enesfd63359ae037
diff --git a/src/preload/index.ts b/src/preload/index.ts
index 508bf40fe..92ccbbc34 100644
--- a/src/preload/index.ts
+++ b/src/preload/index.ts
@@ -259,7 +259,20 @@ const api: NodeTerminalApi = {
},
chat: {
readTranscript: (sessionId, cwd) =>
- ipcRenderer.invoke(IPC.chatReadTranscript, sessionId, cwd)
+ ipcRenderer.invoke(IPC.chatReadTranscript, sessionId, cwd),
+ 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),
+ permissionReply: (nodeId, requestId, decision) =>
+ ipcRenderer.send(IPC.chatPermissionReply, nodeId, requestId, decision),
+ removeQueued: (nodeId, queueId) => ipcRenderer.send(IPC.chatRemoveQueued, nodeId, queueId),
+ dispose: (nodeId) => ipcRenderer.send(IPC.chatDispose, nodeId),
+ onEvent: (nodeId, listener) => {
+ const ch = IPC.chatEvent(nodeId)
+ const handler = (_e: unknown, payload: Parameters<typeof listener>[0]) => listener(payload)
+ ipcRenderer.on(ch, handler)
+ return () => ipcRenderer.removeListener(ch, handler)
+ }
},
transcripts: {
search: (query: string) => ipcRenderer.invoke(IPC.transcriptSearch, query)
diff --git a/src/renderer/nodes/ChatPanel.tsx b/src/renderer/nodes/ChatPanel.tsx
index 7dfc4119f..6634e68be 100644
--- a/src/renderer/nodes/ChatPanel.tsx
+++ b/src/renderer/nodes/ChatPanel.tsx
@@ -84,7 +84,7 @@ export function ChatPanel({ nodeId, sessionId, cwd }: ChatPanelProps) {
{messages.map((m, i) => (
<div key={i} className={`term-chat__msg term-chat__msg--${m.role}`}>
{m.parts.map((p, j) =>
- p.kind === 'text' ? (
+ p.kind === 'text' || p.kind === 'thinking' ? (
<MarkdownText key={j} text={p.text} />
) : (
<details key={j} className="term-chat__tool">
diff --git a/src/shared/ipc.ts b/src/shared/ipc.ts
index 1f029bc7c..b3c8d861b 100644
--- a/src/shared/ipc.ts
+++ b/src/shared/ipc.ts
@@ -15,6 +15,13 @@ export const IPC = {
ptyReadSessionName: 'pty:read-session-name',
claudeReadTranscript: 'claude:read-transcript',
chatReadTranscript: 'chat:read-transcript',
+ chatEnsure: 'chat:ensure',
+ chatSend: 'chat:send',
+ chatInterrupt: 'chat:interrupt',
+ chatPermissionReply: 'chat:permission-reply',
+ chatRemoveQueued: 'chat:remove-queued',
+ chatDispose: 'chat:dispose',
+ chatEvent: (nodeId: string) => `chat:event:${nodeId}`,
transcriptSearch: 'transcript:search',
appToggleMarkdown: 'app:toggle-markdown',
appCloseNode: 'app:close-node',
diff --git a/src/shared/types.ts b/src/shared/types.ts
index 6bc66601c..e59dd807d 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -39,7 +39,7 @@ export interface PtyCreateResult {
}
// 'subagent' and 'loop' are render-only (ephemeral hook-driven viz) and never persisted.
-export type NodeKind = 'terminal' | 'sticky' | 'group' | 'editor' | 'diff' | 'video' | 'web' | 'browser' | 'subagent' | 'loop' | 'dino'
+export type NodeKind = 'terminal' | 'sticky' | 'group' | 'editor' | 'diff' | 'video' | 'web' | 'browser' | 'subagent' | 'loop' | 'dino' | 'chat'
/** Persisted state of a single canvas node (terminal, sticky note, group frame, or editor). */
export interface CanvasNodeState {
@@ -667,6 +667,7 @@ export interface TranscriptLine {
/** One ordered piece of a chat message: prose, or a tool call with an optional result. */
export type ChatPart =
| { kind: 'text'; text: string }
+ | { kind: 'thinking'; text: string }
| { kind: 'tool'; name: string; arg: string; result?: string }
/** A structured chat message reconstructed from a Claude session transcript. */
@@ -675,6 +676,41 @@ export interface ChatMessage {
parts: ChatPart[]
}
+/** Edit/Write tool summary for diff-preview cards. */
+export interface ChatToolSummary {
+ filePath?: string
+ added?: number
+ removed?: number
+}
+
+/** One queued (not-yet-sent) chat input. */
+export interface ChatQueueItem {
+ id: string
+ text: string
+}
+
+/** A base64-encoded image attachment sent with a chat message. */
+export interface ChatImageAttachment {
+ mediaType: string
+ data: string // base64
+}
+
+/** The renderer's reply to a chat permission request. */
+export type ChatPermissionDecision = { behavior: 'allow' | 'deny'; alwaysSession?: boolean }
+
+/** One streamed chat-driver event, pushed on chat:event:<nodeId>. */
+export type ChatEvent =
+ | { kind: 'session'; sessionId: string; slashCommands: string[] }
+ | { kind: 'delta'; block: 'text' | 'thinking'; text: string }
+ | { kind: 'message'; msg: ChatMessage }
+ | { kind: 'tool'; toolUseId: string; name: string; arg: string; summary?: ChatToolSummary }
+ | { kind: 'tool-result'; toolUseId: string; result: string }
+ | { kind: 'permission'; requestId: string; toolName: string; input: unknown }
+ | { kind: 'permission-done'; requestId: string }
+ | { kind: 'turn-done'; costUsd?: number; usage?: { inputTokens: number; outputTokens: number } }
+ | { kind: 'queue'; items: ChatQueueItem[] }
+ | { kind: 'error'; message: string; fatal?: boolean }
+
export interface ChatApi {
/**
* Reads a Claude session transcript as structured chat messages ([] if unavailable).
@@ -685,6 +721,18 @@ export interface ChatApi {
sessionId: string | undefined,
cwd: string | undefined
): 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 }
+ ): Promise<{ ok: boolean; error?: string }>
+ send(nodeId: string, text: string, images?: ChatImageAttachment[]): void
+ interrupt(nodeId: string): void
+ permissionReply(nodeId: string, requestId: string, decision: ChatPermissionDecision): void
+ removeQueued(nodeId: string, queueId: string): void
+ /** Node closed for good: kill the driver process. */
+ dispose(nodeId: string): void
+ onEvent(nodeId: string, listener: (e: ChatEvent) => void): () => void
}
/** One ranked search hit across all on-disk Claude session transcripts. */