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): terminal→chat fork action + fatal-error reconnect

enes3f363eb1729e
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index e7efe68d3..f61c54e29 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -1294,6 +1294,33 @@ export function Canvas() {
[setNodes, markDirty, activeProjectId, viewCenter]
)
+ // Terminal → chat fork (Task 10): a Claude terminal node dispatches 'nodeterm:open-chat'
+ // with its own session id; open a chat node beside it that resumes+forks that session so
+ // the conversation continues in the chat UI while the original terminal keeps working.
+ useEffect(() => {
+ const onOpenChat = (ev: Event) => {
+ const detail = (ev as CustomEvent).detail as
+ | { nodeId: string; sessionId?: string; cwd?: string }
+ | undefined
+ if (!detail?.sessionId) return
+ const source = nodesRef.current.find((n) => n.id === detail.nodeId)
+ const node = createChatNode(nodesRef.current.length, detail.cwd, undefined, {
+ forkFrom: detail.sessionId
+ })
+ if (source) {
+ node.position = {
+ x: source.position.x + ((source.width as number) ?? 600) + 40,
+ y: source.position.y
+ }
+ }
+ node.selected = true
+ setNodes((ns) => [...ns.map((n) => ({ ...n, selected: false })), node])
+ markDirty()
+ }
+ window.addEventListener('nodeterm:open-chat', onOpenChat)
+ return () => window.removeEventListener('nodeterm:open-chat', onOpenChat)
+ }, [setNodes, markDirty])
+
const addAgentNode = useCallback(
(agentId: AgentId, center?: { x: number; y: number }, groupId?: string) => {
const project = useProjects.getState().getProject(activeProjectId)
diff --git a/src/renderer/nodes/ChatNode.tsx b/src/renderer/nodes/ChatNode.tsx
index 1f447d18f..90a8a32e3 100644
--- a/src/renderer/nodes/ChatNode.tsx
+++ b/src/renderer/nodes/ChatNode.tsx
@@ -25,6 +25,7 @@ export default function ChatNode({ id, data, selected }: NodeProps<CanvasNode>)
const apply = useChatSessions((s) => s.apply)
const seed = useChatSessions((s) => s.seed)
const addLocalUser = useChatSessions((s) => s.addLocalUser)
+ const clearError = useChatSessions((s) => s.clearError)
const status = useAgentStatus((s) => s.byId[id])
const { setNodes, addNodes } = useReactFlow()
const [input, setInput] = useState('')
@@ -255,7 +256,14 @@ export default function ChatNode({ id, data, selected }: NodeProps<CanvasNode>)
)
})}
{chat?.streamText && <div className="term-chat__msg term-chat__msg--assistant"><MarkdownText text={chat.streamText} /></div>}
- {chat?.error && <div className="chat-node__error">{chat.error.message}</div>}
+ {/* Non-fatal errors: a dismissible inline line. Fatal errors get the reconnect bar
+ in place of the compose box (below). */}
+ {chat?.error && !chat.error.fatal && (
+ <div className="chat-node__error">
+ <span>{chat.error.message}</span>
+ <button className="chat-node__error-dismiss" title="Dismiss" onClick={() => clearError(id)}>×</button>
+ </div>
+ )}
{perm && (
<div className="chat-node__permission">
<div className="chat-node__permission-title">Allow {perm.toolName}?</div>
@@ -289,6 +297,23 @@ export default function ChatNode({ id, data, selected }: NodeProps<CanvasNode>)
{attachNote && <div className="chat-node__attach-note">{attachNote}</div>}
</div>
)}
+ {chat?.error?.fatal ? (
+ <div className="chat-node__errorbar nodrag">
+ <span className="chat-node__errorbar-msg">{chat.error.message || 'Chat session ended.'}</span>
+ <button
+ className="chat-node__errorbar-reconnect"
+ onClick={() => {
+ clearError(id)
+ void window.nodeTerminal.chat.ensure(id, {
+ cwd: data.cwd as string | undefined,
+ sessionId: data.chatSessionId as string | undefined
+ })
+ }}
+ >
+ Reconnect
+ </button>
+ </div>
+ ) : (
<div className="chat-node__compose nodrag">
{slashOpen && (
<div className="chat-node__slash">
@@ -321,6 +346,7 @@ export default function ChatNode({ id, data, selected }: NodeProps<CanvasNode>)
{/* Stop = interrupt: the driver's turn-done then auto-flushes the next queued item (Task 5). */}
{working && <button className="chat-node__stop" onClick={() => window.nodeTerminal.chat.interrupt(id)}>Stop</button>}
</div>
+ )}
</div>
)
}
diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsx
index 8185731cd..bb6c13d7a 100644
--- a/src/renderer/nodes/TerminalNode.tsx
+++ b/src/renderer/nodes/TerminalNode.tsx
@@ -19,7 +19,7 @@ import type { TerminalTransport } from '../terminal/transport'
import { patchTerminalScale } from '../terminal/scale-fix'
import { parseOsc52 } from '../terminal/osc52'
import { FindBar } from '../components/FindBar'
-import { IconSearch } from '../components/icons'
+import { IconSearch, IconChat } from '../components/icons'
import { NodeTags } from '../components/NodeTags'
import { Tooltip } from '../components/Tooltip'
import { useTerminalSearch } from '../terminal/useTerminalSearch'
@@ -899,6 +899,27 @@ export function TerminalNode({ id, data, selected, parentId }: NodeProps<CanvasN
{naming ? '…' : '✦'}
</button>
</Tooltip>
+ {showChat && !!status?.sessionId && (
+ <Tooltip label="Open chat node (experimental — forks this session)">
+ <button
+ className="term-node__chat nodrag"
+ title="Open chat node (experimental — forks this session)"
+ onClick={() =>
+ window.dispatchEvent(
+ new CustomEvent('nodeterm:open-chat', {
+ detail: {
+ nodeId: id,
+ sessionId: status!.sessionId,
+ cwd: data.cwd as string | undefined
+ }
+ })
+ )
+ }
+ >
+ <IconChat />
+ </button>
+ </Tooltip>
+ )}
<button
className="term-node__close"
title="Close (ends the session)"
diff --git a/src/renderer/styles.css b/src/renderer/styles.css
index bc97bbbe3..50b14fe74 100644
--- a/src/renderer/styles.css
+++ b/src/renderer/styles.css
@@ -809,6 +809,24 @@ body,
color: #6cb0ff;
}
+.term-node__chat {
+ background: transparent;
+ border: none;
+ color: var(--muted);
+ cursor: pointer;
+ line-height: 1;
+ padding: 2px 5px;
+ border-radius: 4px;
+ flex-shrink: 0;
+ display: inline-flex;
+ align-items: center;
+}
+
+.term-node__chat:hover {
+ background: rgba(10, 132, 255, 0.18);
+ color: #6cb0ff;
+}
+
.term-node__find {
display: flex;
flex-direction: column;
@@ -4633,6 +4651,9 @@ body,
list-style: none;
}
.chat-node__error {
+ display: flex;
+ align-items: flex-start;
+ gap: 8px;
padding: 8px 10px;
border-radius: 8px;
font-size: 12px;
@@ -4640,6 +4661,52 @@ body,
background: rgba(255, 69, 58, 0.12);
border: 1px solid rgba(255, 69, 58, 0.35);
}
+.chat-node__error span {
+ flex: 1 1 auto;
+}
+.chat-node__error-dismiss {
+ flex: 0 0 auto;
+ border: none;
+ background: transparent;
+ color: inherit;
+ cursor: pointer;
+ font-size: 13px;
+ line-height: 1;
+ padding: 0;
+ opacity: 0.7;
+}
+.chat-node__error-dismiss:hover {
+ opacity: 1;
+}
+/* Fatal-error bar: replaces the compose box until the user reconnects. */
+.chat-node__errorbar {
+ flex: 0 0 auto;
+ display: flex;
+ align-items: center;
+ gap: 10px;
+ padding: 8px 10px;
+ border-top: 1px solid rgba(255, 69, 58, 0.35);
+ background: rgba(255, 69, 58, 0.1);
+}
+.chat-node__errorbar-msg {
+ flex: 1 1 auto;
+ font-size: 12px;
+ color: #ff453a;
+}
+.chat-node__errorbar-reconnect {
+ flex: 0 0 auto;
+ padding: 6px 12px;
+ font-size: 12px;
+ font-weight: 600;
+ border-radius: 6px;
+ border: 1px solid rgba(255, 69, 58, 0.5);
+ background: rgba(255, 69, 58, 0.15);
+ color: #ff453a;
+ cursor: pointer;
+}
+.chat-node__errorbar-reconnect:hover {
+ background: rgba(255, 69, 58, 0.25);
+}
.chat-node__permission {
padding: 10px;
border-radius: 8px;