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(claude): /loop gets its own connected node (iterations + content)

enesb643f0287c22
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index a58499a5d..99be243b2 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -55,6 +55,7 @@ import { useProjects } from '../state/projects'
import { useClaudeStatus } from '../state/claudeStatus'
import { useAgentNodes } from '../state/agentNodes'
import { SubagentNode } from '../nodes/SubagentNode'
+import { LoopNode } from '../nodes/LoopNode'
import { branchClaudeSession } from '../lib/claudeBranch'
import { useSettings } from '../state/settings'
import {
@@ -123,7 +124,8 @@ export function Canvas() {
group: withNodeBoundary(GroupNode),
editor: withNodeBoundary(EditorNode),
diff: withNodeBoundary(DiffNode),
- subagent: withNodeBoundary(SubagentNode)
+ subagent: withNodeBoundary(SubagentNode),
+ loop: withNodeBoundary(LoopNode)
}),
[]
)
@@ -131,9 +133,40 @@ export function Canvas() {
// Ephemeral subagent nodes + edges (driven by Claude hooks; never persisted / no undo).
// Laid out fanning below the parent Claude node.
const agentById = useAgentNodes((s) => s.byId)
+ const claudeById = useClaudeStatus((s) => s.byId)
const { ephemeralNodes, ephemeralEdges } = useMemo(() => {
const eNodes: CanvasNode[] = []
const eEdges: Edge[] = []
+ // Loop nodes: one per terminal node currently running a /loop, placed below-left.
+ for (const [pid, st] of Object.entries(claudeById)) {
+ if (!st.loop) continue
+ const parent = nodes.find((n) => n.id === pid)
+ if (!parent) continue
+ const ph = parent.measured?.height ?? (parent.height as number) ?? 400
+ const lid = `loop-${pid}`
+ eNodes.push({
+ id: lid,
+ type: 'loop',
+ position: { x: parent.position.x - 250, y: parent.position.y + ph + 60 },
+ draggable: false,
+ selectable: false,
+ data: {
+ title: st.loop.prompt ?? '',
+ color: '#bf7af0',
+ group: null,
+ loopCount: st.loop.count,
+ loopItems: st.loop.items,
+ loopActive: st.state === 'working'
+ }
+ } as CanvasNode)
+ eEdges.push({
+ id: `e-${lid}`,
+ source: pid,
+ target: lid,
+ animated: st.state === 'working',
+ style: { stroke: '#bf7af0', strokeWidth: 1.5 }
+ })
+ }
const byParent: Record<string, string[]> = {}
for (const id of Object.keys(agentById)) {
;(byParent[agentById[id].parentNodeId] ??= []).push(id)
@@ -180,7 +213,7 @@ export function Canvas() {
})
}
return { ephemeralNodes: eNodes, ephemeralEdges: eEdges }
- }, [agentById, nodes])
+ }, [agentById, claudeById, nodes])
// 1) Load the whole workspace once and hydrate the projects store.
useEffect(() => {
@@ -329,7 +362,9 @@ export function Canvas() {
(changes) => {
// Drop changes targeting ephemeral subagent nodes (they live outside the managed state).
const eph = useAgentNodes.getState().byId
- const filtered = changes.filter((c) => !('id' in c && c.id in eph))
+ const filtered = changes.filter(
+ (c) => !('id' in c && (c.id in eph || c.id.startsWith('loop-')))
+ )
onNodesChange(filtered)
if (filtered.some((c) => c.type !== 'select')) markDirty()
},
@@ -909,11 +944,11 @@ export function Canvas() {
case 'UserPromptSubmit':
cs.setState(e.nodeId, 'working')
an.clearForParent(e.nodeId) // new turn → drop the previous fan-out
- if (/^\s*\/loop\b/.test(e.prompt ?? '')) cs.setLoop(e.nodeId, true)
+ if (/^\s*\/loop\b/.test(e.prompt ?? '')) cs.setLoop(e.nodeId, true, e.prompt)
break
case 'Stop':
cs.setState(e.nodeId, 'done')
- cs.bumpLoop(e.nodeId) // count loop iterations (no-op if not looping)
+ cs.bumpLoop(e.nodeId, e.lastMessage) // count loop iterations + summary (no-op if not looping)
alert('finished', 'Claude finished its turn.')
break
case 'Notification':
diff --git a/src/renderer/nodes/LoopNode.tsx b/src/renderer/nodes/LoopNode.tsx
new file mode 100644
index 000000000..183ff8194
--- /dev/null
+++ b/src/renderer/nodes/LoopNode.tsx
@@ -0,0 +1,50 @@
+import { useEffect, useRef, useState } from 'react'
+import { Handle, Position, type NodeProps } from '@xyflow/react'
+import type { CanvasNode } from '../state/workspace'
+
+/**
+ * Ephemeral node visualizing a /loop running on a Claude terminal: iteration count and a
+ * per-iteration summary list. Click to expand. Connected by an edge to its parent node.
+ */
+export function LoopNode({ data }: NodeProps<CanvasNode>) {
+ const count = (data.loopCount as number) ?? 0
+ const items = (data.loopItems as string[]) ?? []
+ const active = !!data.loopActive
+ const [expanded, setExpanded] = useState(false)
+ const bodyRef = useRef<HTMLDivElement>(null)
+
+ useEffect(() => {
+ if (expanded && bodyRef.current) bodyRef.current.scrollTop = bodyRef.current.scrollHeight
+ }, [items.length, expanded])
+
+ return (
+ <div className={`loop-node${active ? ' working' : ''}`}>
+ <Handle type="target" position={Position.Top} isConnectable={false} />
+ <div
+ className="loop-node__head nodrag"
+ onClick={() => setExpanded((v) => !v)}
+ title={expanded ? 'Collapse' : 'Click to expand'}
+ style={{ cursor: 'pointer' }}
+ >
+ <span className="loop-node__dot" />
+ <span className="loop-node__type">Loop</span>
+ <span className="loop-node__count">×{count}</span>
+ </div>
+ {data.title && !expanded && <div className="loop-node__task">{data.title as string}</div>}
+ {expanded && (
+ <div className="loop-node__items nodrag nowheel" ref={bodyRef}>
+ {data.title ? <div className="loop-node__task-full">{data.title as string}</div> : null}
+ {items.length ? (
+ items.map((it, i) => (
+ <div key={i} className="loop-node__item">
+ <span className="loop-node__item-n">{i + 1}.</span> {it}
+ </div>
+ ))
+ ) : (
+ <span className="loop-node__empty">No iterations yet.</span>
+ )}
+ </div>
+ )}
+ </div>
+ )
+}
diff --git a/src/renderer/state/claudeStatus.ts b/src/renderer/state/claudeStatus.ts
index 489f6a87a..e03e5f6de 100644
--- a/src/renderer/state/claudeStatus.ts
+++ b/src/renderer/state/claudeStatus.ts
@@ -16,8 +16,8 @@ export interface ClaudeNodeStatus {
session?: string
/** Claude session id (from hooks) — used to resume/branch the conversation. */
sessionId?: string
- /** Set when the node is running a /loop (heuristic); count = iterations so far. */
- loop?: { count: number }
+ /** Set when the node is running a /loop (heuristic); shown as a connected loop node. */
+ loop?: { count: number; prompt?: string; items: string[] }
}
interface ClaudeStatusState {
@@ -30,10 +30,10 @@ interface ClaudeStatusState {
setSessionId(id: string, sessionId: string): void
markUnread(id: string): void
clearUnread(id: string): void
- /** Start (active=true, resets count) or stop a /loop indicator. */
- setLoop(id: string, active: boolean): void
- /** Increment the /loop iteration count (only while a loop is active). */
- bumpLoop(id: string): void
+ /** Start (active=true, resets) or stop a /loop indicator. */
+ setLoop(id: string, active: boolean, prompt?: string): void
+ /** Record a /loop iteration (count++ and append its summary). No-op if not looping. */
+ bumpLoop(id: string, message?: string): void
remove(id: string): void
}
@@ -123,20 +123,25 @@ export const useClaudeStatus = create<ClaudeStatusState>((set) => ({
return { byId }
}),
- setLoop: (id, active) =>
+ setLoop: (id, active, prompt) =>
set((s) => {
const prev = s.byId[id] ?? EMPTY
- if (active) return { byId: { ...s.byId, [id]: { ...prev, loop: { count: 0 } } } }
+ if (active) return { byId: { ...s.byId, [id]: { ...prev, loop: { count: 0, prompt, items: [] } } } }
if (!prev.loop) return s
const { loop: _drop, ...rest } = prev
return { byId: { ...s.byId, [id]: rest } }
}),
- bumpLoop: (id) =>
+ bumpLoop: (id, message) =>
set((s) => {
const prev = s.byId[id]
if (!prev?.loop) return s
- return { byId: { ...s.byId, [id]: { ...prev, loop: { count: prev.loop.count + 1 } } } }
+ const items = message
+ ? [...prev.loop.items, message.replace(/\s+/g, ' ').trim().slice(0, 200)].slice(-50)
+ : prev.loop.items
+ return {
+ byId: { ...s.byId, [id]: { ...prev, loop: { ...prev.loop, count: prev.loop.count + 1, items } } }
+ }
}),
remove: (id) =>
diff --git a/src/renderer/styles.css b/src/renderer/styles.css
index 6edd38ea7..5a832fa79 100644
--- a/src/renderer/styles.css
+++ b/src/renderer/styles.css
@@ -2632,6 +2632,91 @@ body,
color: var(--muted);
}
+/* ---- Loop (ephemeral, hook-driven) node ---- */
+.loop-node {
+ width: 230px;
+ padding: 10px 12px;
+ background: #1c1c1e;
+ border: 1px solid var(--border);
+ border-left: 3px solid #bf7af0;
+ border-radius: 10px;
+ box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
+ font-size: 12px;
+ color: var(--text);
+}
+
+.loop-node__head {
+ display: flex;
+ align-items: center;
+ gap: 7px;
+}
+
+.loop-node__dot {
+ width: 8px;
+ height: 8px;
+ flex: none;
+ border-radius: 50%;
+ background: #bf7af0;
+}
+
+.loop-node.working .loop-node__dot {
+ animation: nt-pulse 1.1s ease-in-out infinite;
+}
+
+.loop-node__type {
+ font-weight: 600;
+}
+
+.loop-node__count {
+ margin-left: auto;
+ font-size: 10.5px;
+ font-weight: 700;
+ color: #bf7af0;
+ font-variant-numeric: tabular-nums;
+}
+
+.loop-node__task {
+ margin-top: 6px;
+ color: var(--muted);
+ font-size: 11.5px;
+ line-height: 1.4;
+ display: -webkit-box;
+ -webkit-line-clamp: 2;
+ -webkit-box-orient: vertical;
+ overflow: hidden;
+}
+
+.loop-node__items {
+ margin-top: 8px;
+ padding-top: 8px;
+ border-top: 1px solid var(--border);
+ max-height: 240px;
+ overflow: auto;
+ font-size: 11.5px;
+ line-height: 1.5;
+}
+
+.loop-node__task-full {
+ margin-bottom: 8px;
+ padding-bottom: 8px;
+ border-bottom: 1px solid var(--border);
+ color: var(--muted);
+}
+
+.loop-node__item {
+ margin-bottom: 6px;
+ word-break: break-word;
+}
+
+.loop-node__item-n {
+ color: #bf7af0;
+ font-weight: 700;
+}
+
+.loop-node__empty {
+ color: var(--muted);
+}
+
/* ---- Minimap ---- */
.minimap {
background: rgba(40, 40, 42, 0.85) !important;
diff --git a/src/shared/types.ts b/src/shared/types.ts
index b2b5ecbe6..41191659d 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -12,8 +12,8 @@ export interface PtyCreateOptions {
persistKey?: string
}
-// 'subagent' is render-only (ephemeral hook-driven viz) and never persisted.
-export type NodeKind = 'terminal' | 'sticky' | 'group' | 'editor' | 'diff' | 'subagent'
+// 'subagent' and 'loop' are render-only (ephemeral hook-driven viz) and never persisted.
+export type NodeKind = 'terminal' | 'sticky' | 'group' | 'editor' | 'diff' | 'subagent' | 'loop'
/** Persisted state of a single canvas node (terminal, sticky note, group frame, or editor). */
export interface CanvasNodeState {