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(chat): slash popup, image attachments, diff-preview cards
enes22852a88c6b7
diff --git a/src/renderer/nodes/ChatNode.tsx b/src/renderer/nodes/ChatNode.tsxindex d72c5620a..1f447d18f 100644--- a/src/renderer/nodes/ChatNode.tsx+++ b/src/renderer/nodes/ChatNode.tsx@@ -1,23 +1,39 @@// SDK-driven chat node: token-streaming conversation with Claude, permission cards,// send-while-working queue. Continuity is resume-based via data.chatSessionId — the// SDK process dies with the app; history reloads from the on-disk transcript.-import { useCallback, useEffect, useRef, useState, type KeyboardEvent } from 'react'+import {+ useCallback,+ useEffect,+ useRef,+ useState,+ type ClipboardEvent,+ type DragEvent,+ type KeyboardEvent+} from 'react'import { NodeResizer, useReactFlow, type NodeProps } from '@xyflow/react'import { MarkdownText } from './ChatPanel'import { useChatSessions } from '../state/chatSessions'import { useAgentStatus } from '../state/agentStatus'-import type { CanvasNode } from '../state/workspace'+import { createDiffNode, type CanvasNode } from '../state/workspace'import type { ChatImageAttachment } from '@shared/types'+const MAX_IMAGES = 5+const MAX_IMAGE_BYTES = 2 * 1024 * 1024 // 2 MB per image+export default function ChatNode({ id, data, selected }: NodeProps<CanvasNode>) {const chat = useChatSessions((s) => s.byId[id])const apply = useChatSessions((s) => s.apply)const seed = useChatSessions((s) => s.seed)const addLocalUser = useChatSessions((s) => s.addLocalUser)const status = useAgentStatus((s) => s.byId[id])- const { setNodes } = useReactFlow()+ const { setNodes, addNodes } = useReactFlow()const [input, setInput] = useState('')const [images, setImages] = useState<ChatImageAttachment[]>([])+ const [attachNote, setAttachNote] = useState<string | null>(null)+ // Slash-command popup: an index into the filtered matches, plus a manual-dismiss flag+ // (Escape / after completion) so the popup can close without changing the input text.+ const [slashIdx, setSlashIdx] = useState(0)+ const [slashDismissed, setSlashDismissed] = useState(false)const msgsRef = useRef<HTMLDivElement>(null)// Boot: subscribe to driver events, seed history from disk, start/reattach the driver.@@ -59,9 +75,117 @@ export default function ChatNode({ id, data, selected }: NodeProps<CanvasNode>)if (!chat?.working) addLocalUser(id, text)setInput('')setImages([])+ setAttachNote(null)+ setSlashDismissed(false)}, [input, images, id, chat?.working, addLocalUser])+ // --- Image attachments (paste + drag-drop) -------------------------------+ const addFiles = useCallback(+ (files: File[]) => {+ const imgs = files.filter((f) => f.type.startsWith('image/'))+ if (imgs.length === 0) return+ let dropped = imgs.length - imgs.filter((f) => f.size <= MAX_IMAGE_BYTES).length // oversized+ const ok = imgs.filter((f) => f.size <= MAX_IMAGE_BYTES)+ Promise.all(+ ok.map(+ (f) =>+ new Promise<ChatImageAttachment>((resolve, reject) => {+ const reader = new FileReader()+ reader.onload = () => {+ const res = String(reader.result)+ // strip the `data:<mime>;base64,` prefix → raw base64+ const comma = res.indexOf(',')+ resolve({ mediaType: f.type, data: comma >= 0 ? res.slice(comma + 1) : res })+ }+ reader.onerror = () => reject(reader.error)+ reader.readAsDataURL(f)+ })+ )+ ).then((atts) => {+ setImages((prev) => {+ const room = Math.max(0, MAX_IMAGES - prev.length)+ const accepted = atts.slice(0, room)+ dropped += atts.length - accepted.length // over the 5-image cap+ return accepted.length ? [...prev, ...accepted] : prev+ })+ setAttachNote(dropped > 0 ? `Skipped ${dropped} file(s) — max ${MAX_IMAGES} images, 2 MB each` : null)+ })+ },+ []+ )++ const removeImage = (i: number) => setImages((prev) => prev.filter((_, idx) => idx !== i))++ const onPaste = (e: ClipboardEvent<HTMLTextAreaElement>) => {+ const files = Array.from(e.clipboardData?.files ?? [])+ if (files.some((f) => f.type.startsWith('image/'))) {+ e.preventDefault() // don't also paste the image path/text+ addFiles(files)+ }+ }+ const onDrop = (e: DragEvent<HTMLTextAreaElement>) => {+ const files = Array.from(e.dataTransfer?.files ?? [])+ if (files.length) {+ e.preventDefault()+ addFiles(files)+ }+ }+ const onDragOver = (e: DragEvent<HTMLTextAreaElement>) => {+ if (Array.from(e.dataTransfer?.types ?? []).includes('Files')) e.preventDefault()+ }++ // --- Slash-command popup -------------------------------------------------+ const trimmed = input.trim()+ const slashMatches = trimmed.startsWith('/')+ ? (chat?.slashCommands ?? []).filter((c) => c.startsWith(trimmed)).slice(0, 8)+ : []+ const slashOpen = slashMatches.length > 0 && !slashDismissed+ const slashActive = slashOpen ? Math.min(slashIdx, slashMatches.length - 1) : -1++ const completeSlash = (cmd: string) => {+ setInput(cmd + ' ')+ setSlashDismissed(true) // programmatic setInput doesn't re-open the popup+ setSlashIdx(0)+ }++ const onInputChange = (value: string) => {+ setInput(value)+ setSlashIdx(0)+ setSlashDismissed(false)+ }++ // --- Diff-preview tool card ----------------------------------------------+ const openDiff = (filePath?: string) => {+ const cwd = data.cwd as string | undefined+ if (!filePath || !cwd || !filePath.startsWith(cwd)) return+ const rel = filePath.slice(cwd.length).replace(/^\//, '')+ if (!rel) return+ addNodes(createDiffNode(0, cwd, rel, false)) // false → unstaged (working ↔ index)+ }+const onKeyDown = (e: KeyboardEvent<HTMLTextAreaElement>) => {+ if (slashOpen) {+ if (e.key === 'ArrowDown') {+ e.preventDefault()+ setSlashIdx((i) => (i + 1) % slashMatches.length)+ return+ }+ if (e.key === 'ArrowUp') {+ e.preventDefault()+ setSlashIdx((i) => (i - 1 + slashMatches.length) % slashMatches.length)+ return+ }+ if (e.key === 'Tab' || (e.key === 'Enter' && !e.shiftKey)) {+ e.preventDefault()+ completeSlash(slashMatches[slashActive])+ return+ }+ if (e.key === 'Escape') {+ e.preventDefault()+ setSlashDismissed(true)+ return+ }+ }if (e.key === 'Enter' && !e.shiftKey) {e.preventDefault()send()@@ -70,6 +194,7 @@ export default function ChatNode({ id, data, selected }: NodeProps<CanvasNode>)const perm = chat?.permissionconst working = !!chat?.working || status?.state === 'working'+ const cwd = data.cwd as string | undefinedreturn (<div className={`chat-node${selected ? ' selected' : ''}`} style={{ borderTopColor: data.color }}>@@ -103,11 +228,25 @@ export default function ChatNode({ id, data, selected }: NodeProps<CanvasNode>))}{chat?.toolOrder.map((tid) => {const t = chat.tools[tid]+ const diffPath = t.summary?.filePath+ const canDiff = !!diffPath && !!cwd && diffPath.startsWith(cwd)return (<details key={tid} className="term-chat__tool" open={!t.result}><summary><span className="term-chat__tool-name">{t.name}</span>- <span className="term-chat__tool-arg">+ <span+ className={`term-chat__tool-arg${canDiff ? ' term-chat__tool-arg--link' : ''}`}+ title={canDiff ? 'Open diff' : undefined}+ onClick={+ canDiff+ ? (e) => {+ e.preventDefault() // don't toggle the <details>+ e.stopPropagation()+ openDiff(diffPath)+ }+ : undefined+ }+ >{t.summary ? `${t.summary.filePath} +${t.summary.added} −${t.summary.removed}` : t.arg}</span></summary>@@ -139,12 +278,43 @@ export default function ChatNode({ id, data, selected }: NodeProps<CanvasNode>)))}</div>)}+ {(images.length > 0 || attachNote) && (+ <div className="chat-node__attach nodrag">+ {images.map((img, i) => (+ <span key={i} className="chat-node__attach-chip">+ <img src={`data:${img.mediaType};base64,${img.data}`} alt="attachment" />+ <button onClick={() => removeImage(i)}>×</button>+ </span>+ ))}+ {attachNote && <div className="chat-node__attach-note">{attachNote}</div>}+ </div>+ )}<div className="chat-node__compose nodrag">+ {slashOpen && (+ <div className="chat-node__slash">+ {slashMatches.map((c, i) => (+ <div+ key={c}+ className={`chat-node__slash-item${i === slashActive ? ' chat-node__slash-item--active' : ''}`}+ onMouseEnter={() => setSlashIdx(i)}+ onMouseDown={(e) => {+ e.preventDefault() // keep focus on the textarea+ completeSlash(c)+ }}+ >+ {c}+ </div>+ ))}+ </div>+ )}<textareaclassName="term-chat__input"value={input}- onChange={(e) => setInput(e.target.value)}+ onChange={(e) => onInputChange(e.target.value)}onKeyDown={onKeyDown}+ onPaste={onPaste}+ onDrop={onDrop}+ onDragOver={onDragOver}placeholder={working ? 'Claude is working — message will queue…' : 'Message Claude… (Enter to send)'}rows={2}/>diff --git a/src/renderer/styles.css b/src/renderer/styles.cssindex 76e513321..bc97bbbe3 100644--- a/src/renderer/styles.css+++ b/src/renderer/styles.css@@ -4734,3 +4734,94 @@ body,.chat-node__stop:hover {background: rgba(255, 69, 58, 0.25);}+/* Clickable diff-preview summary line on a tool card (file +n −m → opens a diff node). */+.term-chat__tool-arg--link {+ cursor: pointer;+ text-decoration: underline;+ text-decoration-color: rgba(255, 255, 255, 0.25);+ text-underline-offset: 2px;+}+.term-chat__tool-arg--link:hover {+ color: var(--accent);+ text-decoration-color: var(--accent);+}+/* Slash-command popup, floated above the compose box. */+.chat-node__compose {+ position: relative;+}+.chat-node__slash {+ position: absolute;+ left: 8px;+ right: 8px;+ bottom: calc(100% - 2px);+ max-height: 200px;+ overflow-y: auto;+ background: var(--panel);+ border: 1px solid var(--border);+ border-radius: 8px;+ box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);+ padding: 4px;+ z-index: 20;+}+.chat-node__slash-item {+ padding: 4px 8px;+ font-size: 12px;+ font-variant-numeric: tabular-nums;+ color: var(--label, rgba(255, 255, 255, 0.92));+ border-radius: 5px;+ white-space: nowrap;+ overflow: hidden;+ text-overflow: ellipsis;+ cursor: pointer;+}+.chat-node__slash-item--active {+ background: var(--accent);+ color: #fff;+}+/* Image-attachment chips row (above the compose box). */+.chat-node__attach {+ flex: 0 0 auto;+ display: flex;+ flex-wrap: wrap;+ align-items: center;+ gap: 6px;+ padding: 6px 8px;+ border-top: 1px solid rgba(255, 255, 255, 0.08);+}+.chat-node__attach-chip {+ position: relative;+ display: inline-flex;+ width: 44px;+ height: 44px;+ border-radius: 6px;+ overflow: hidden;+ border: 1px solid var(--border);+}+.chat-node__attach-chip img {+ width: 100%;+ height: 100%;+ object-fit: cover;+}+.chat-node__attach-chip button {+ position: absolute;+ top: 1px;+ right: 1px;+ width: 15px;+ height: 15px;+ padding: 0;+ line-height: 13px;+ font-size: 12px;+ border: none;+ border-radius: 4px;+ background: rgba(0, 0, 0, 0.6);+ color: #fff;+ cursor: pointer;+}+.chat-node__attach-chip button:hover {+ background: rgba(255, 69, 58, 0.85);+}+.chat-node__attach-note {+ flex: 1 1 100%;+ font-size: 11px;+ color: var(--label-secondary, rgba(255, 255, 255, 0.55));+}