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(git-history): DiffNode commit mode + factory/serializer plumbing

enese3f0c976a40e
diff --git a/src/renderer/nodes/DiffNode.tsx b/src/renderer/nodes/DiffNode.tsx
index 21e835e72..acdb57e8f 100644
--- a/src/renderer/nodes/DiffNode.tsx
+++ b/src/renderer/nodes/DiffNode.tsx
@@ -14,6 +14,7 @@ export function DiffNode({ id, data, selected }: NodeProps<CanvasNode>) {
const cwd = (data.cwd as string) ?? ''
const rel = (data.filePath as string) ?? ''
const staged = !!data.diffStaged
+ const commitOid = (data.commitOid as string | undefined) || ''
useEffect(() => {
const el = bodyRef.current
@@ -25,9 +26,17 @@ export function DiffNode({ id, data, selected }: NodeProps<CanvasNode>) {
const git = window.nodeTerminal.git
const abs = `${cwd}/${rel}`
- // staged: HEAD (original) vs index (modified). unstaged: index (original) vs working (modified).
- const origP = staged ? git.showFile(cwd, 'HEAD', rel) : git.showFile(cwd, '', rel)
- const modP = staged ? git.showFile(cwd, '', rel) : window.nodeTerminal.fs.read(abs)
+ // commit mode: parent (<oid>^) vs commit (<oid>). staged: HEAD vs index. unstaged: index vs working.
+ const origP = commitOid
+ ? git.showFile(cwd, `${commitOid}^`, rel)
+ : staged
+ ? git.showFile(cwd, 'HEAD', rel)
+ : git.showFile(cwd, '', rel)
+ const modP = commitOid
+ ? git.showFile(cwd, commitOid, rel)
+ : staged
+ ? git.showFile(cwd, '', rel)
+ : window.nodeTerminal.fs.read(abs)
Promise.all([origP, modP]).then(([orig, mod]) => {
if (disposed) return
@@ -66,9 +75,9 @@ export function DiffNode({ id, data, selected }: NodeProps<CanvasNode>) {
<NodeResizer minWidth={420} minHeight={220} isVisible={selected} color={data.color} />
<div className="term-node__header">
- <span className="term-node__title-text" title={`${rel} — ${staged ? 'staged' : 'working'}`}>
+ <span className="term-node__title-text" title={`${rel} — ${commitOid ? commitOid.slice(0, 7) : staged ? 'staged' : 'working'}`}>
{rel.split('/').pop()}
- <span className="diff-node__tag">{staged ? 'staged' : 'changes'}</span>
+ <span className="diff-node__tag">{commitOid ? commitOid.slice(0, 7) : staged ? 'staged' : 'changes'}</span>
</span>
<span className="term-node__spacer" />
<button
diff --git a/src/renderer/state/workspace.ts b/src/renderer/state/workspace.ts
index 46b344250..15390cfab 100644
--- a/src/renderer/state/workspace.ts
+++ b/src/renderer/state/workspace.ts
@@ -40,6 +40,7 @@ export interface NodeData {
text?: string
filePath?: string
diffStaged?: boolean
+ commitOid?: string
/** Which agent runs in this terminal node (claude/codex/gemini/custom). */
agentId?: AgentId
[key: string]: unknown
@@ -48,6 +49,11 @@ export interface NodeData {
/** React Flow node type string mirrors the persisted NodeKind. */
export type CanvasNode = Node<NodeData, NodeKind>
+/** Single-quote a string for safe use as one shell argument (POSIX). */
+export function shellSingleQuote(s: string): string {
+ return `'${s.replace(/'/g, `'\\''`)}'`
+}
+
let idCounter = 0
function nextId(prefix: string): string {
return `${prefix}-${Date.now().toString(36)}-${++idCounter}`
@@ -134,10 +140,14 @@ export function createAgentNode(
agentId: AgentId,
index: number,
cwd?: string,
- center?: { x: number; y: number }
+ center?: { x: number; y: number },
+ initialPrompt?: string
): CanvasNode {
const { label, color, launchCmd } = resolveAgent(agentId)
- const initialCommand = agentId === 'claude' ? claudeLaunchCommand() : launchCmd
+ const baseCmd = agentId === 'claude' ? claudeLaunchCommand() : launchCmd
+ const initialCommand = initialPrompt
+ ? `${baseCmd} ${shellSingleQuote(initialPrompt.replace(/\s+/g, ' ').trim())}`
+ : baseCmd
return {
id: nextId('term'),
type: 'terminal',
@@ -194,7 +204,8 @@ export function createDiffNode(
cwd: string,
relPath: string,
staged: boolean,
- center?: { x: number; y: number }
+ center?: { x: number; y: number },
+ commitOid?: string
): CanvasNode {
return {
id: nextId('diff'),
@@ -204,12 +215,13 @@ export function createDiffNode(
height: DIFF_SIZE.height,
style: { width: DIFF_SIZE.width, height: DIFF_SIZE.height },
data: {
- title: `${relPath.split('/').pop() || relPath} (diff)`,
+ title: `${relPath.split('/').pop() || relPath} (${commitOid ? commitOid.slice(0, 7) : 'diff'})`,
color: '#e0af68',
group: null,
cwd,
filePath: relPath,
- diffStaged: staged
+ diffStaged: staged,
+ commitOid
}
}
}
@@ -380,6 +392,7 @@ export function nodeStatesToFlow(states: CanvasNodeState[]): CanvasNode[] {
text: n.text,
filePath: n.filePath,
diffStaged: n.diffStaged,
+ commitOid: n.commitOid,
agentId
}
}
@@ -423,6 +436,7 @@ export function flowToNodeStates(nodes: CanvasNode[]): CanvasNodeState[] {
text: n.data.text,
filePath: n.data.filePath,
diffStaged: n.data.diffStaged,
+ commitOid: n.data.commitOid,
agentId: n.data.agentId
}
})
diff --git a/src/shared/types.ts b/src/shared/types.ts
index 8c023f576..552f157f4 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -50,6 +50,8 @@ export interface CanvasNodeState {
filePath?: string
/** diff-only: true = staged diff (HEAD vs index), false = unstaged (index vs working). */
diffStaged?: boolean
+ /** diff-only: when set, the diff shows parent (<oid>^) vs commit (<oid>) for a file from history. */
+ commitOid?: string
}
/** Canvas pan/zoom state. */