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(search): wire find-bar into terminal node (button, Cmd+F, xterm highlight)

enesda0a78827283
diff --git a/package-lock.json b/package-lock.json
index c84ba2c90..3a7705abf 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -8,8 +8,9 @@
"name": "node-terminal",
"version": "0.2.0",
"hasInstallScript": true,
- "license": "MIT",
+ "license": "SEE LICENSE IN LICENSE",
"dependencies": {
+ "@xterm/addon-search": "^0.15.0",
"dompurify": "^3.4.10",
"electron-updater": "^6.8.9",
"marked": "^12.0.2",
@@ -2425,11 +2426,19 @@
"@xterm/xterm": "^5.0.0"
}
},
+ "node_modules/@xterm/addon-search": {
+ "version": "0.15.0",
+ "resolved": "https://registry.npmjs.org/@xterm/addon-search/-/addon-search-0.15.0.tgz",
+ "integrity": "sha512-ZBZKLQ+EuKE83CqCmSSz5y1tx+aNOCUaA7dm6emgOX+8J9H1FWXZyrKfzjwzV+V14TV3xToz1goIeRhXBS5qjg==",
+ "license": "MIT",
+ "peerDependencies": {
+ "@xterm/xterm": "^5.0.0"
+ }
+ },
"node_modules/@xterm/xterm": {
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/@xterm/xterm/-/xterm-5.5.0.tgz",
"integrity": "sha512-hqJHYaQb5OptNunnyAnkHyM8aCjZ1MEIDTQu1iIbbTD/xops91NB5yq1ZK/dC2JDbVWtF23zUtl9JE2NqwT87A==",
- "dev": true,
"license": "MIT"
},
"node_modules/@xyflow/react": {
diff --git a/package.json b/package.json
index 25e128374..3a4e76178 100644
--- a/package.json
+++ b/package.json
@@ -64,6 +64,7 @@
}
},
"dependencies": {
+ "@xterm/addon-search": "^0.15.0",
"dompurify": "^3.4.10",
"electron-updater": "^6.8.9",
"marked": "^12.0.2",
diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsx
index caccbe24f..5001f9ff2 100644
--- a/src/renderer/nodes/TerminalNode.tsx
+++ b/src/renderer/nodes/TerminalNode.tsx
@@ -1,4 +1,4 @@
-import { useEffect, useRef, useState } from 'react'
+import { useCallback, useEffect, useRef, useState } from 'react'
import {
Handle,
NodeResizer,
@@ -9,11 +9,15 @@ import {
} from '@xyflow/react'
import { Terminal } from '@xterm/xterm'
import { FitAddon } from '@xterm/addon-fit'
+import { SearchAddon } from '@xterm/addon-search'
import { renderMarkdown } from '../lib/markdown'
import { transport } from '../terminal/local-transport'
import { patchTerminalScale } from '../terminal/scale-fix'
+import { FindBar } from '../components/FindBar'
+import { IconSearch } from '../components/icons'
import { NodeTags } from '../components/NodeTags'
import { Tooltip } from '../components/Tooltip'
+import { useTerminalSearch } from '../terminal/useTerminalSearch'
import { ContextMeter } from '../components/ContextMeter'
import { useSettings } from '../state/settings'
import { useAgentStatus } from '../state/agentStatus'
@@ -44,6 +48,7 @@ export function TerminalNode({ id, data, selected }: NodeProps<CanvasNode>) {
const bodyRef = useRef<HTMLDivElement>(null)
const termRef = useRef<Terminal | null>(null)
const fitRef = useRef<FitAddon | null>(null)
+ const searchAddonRef = useRef<SearchAddon | null>(null)
const dwellRef = useRef<ReturnType<typeof setTimeout> | null>(null)
const [showColors, setShowColors] = useState(false)
const [armed, setArmed] = useState(true)
@@ -67,6 +72,26 @@ export function TerminalNode({ id, data, selected }: NodeProps<CanvasNode>) {
const status = useAgentStatus((s) => s.byId[id])
const updateNodeInternals = useUpdateNodeInternals()
+ const [searchOpen, setSearchOpen] = useState(false)
+
+ // Stable fallback reader: serialize the live xterm buffer when tmux capture is unavailable.
+ const readBuffer = useCallback(() => {
+ const t = termRef.current
+ if (!t) return ''
+ const b = t.buffer.active
+ let s = ''
+ for (let i = 0; i < b.length; i++) s += (b.getLine(i)?.translateToString() ?? '') + '\n'
+ return s
+ }, [])
+
+ const search = useTerminalSearch({
+ nodeId: id,
+ sessionId: status?.sessionId,
+ searchTranscript: showUsage,
+ open: searchOpen,
+ readBuffer
+ })
+
// The bridge handles are added/positioned dynamically for bridge-capable nodes; make
// React Flow re-measure them so edges anchor to the (centered) handle, not a stale position.
useEffect(() => {
@@ -90,6 +115,9 @@ export function TerminalNode({ id, data, selected }: NodeProps<CanvasNode>) {
const fit = new FitAddon()
fitRef.current = fit
term.loadAddon(fit)
+ const searchAddon = new SearchAddon()
+ searchAddonRef.current = searchAddon
+ term.loadAddon(searchAddon)
term.open(container)
fit.fit()
patchTerminalScale(term, getZoom)
@@ -197,6 +225,7 @@ export function TerminalNode({ id, data, selected }: NodeProps<CanvasNode>) {
term.dispose()
termRef.current = null
fitRef.current = null
+ searchAddonRef.current = null
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
@@ -305,6 +334,37 @@ export function TerminalNode({ id, data, selected }: NodeProps<CanvasNode>) {
})
}, [id, updateNodeData])
+ // Best-effort: highlight matches that are in the live xterm buffer (on-screen scrollback).
+ useEffect(() => {
+ const sa = searchAddonRef.current
+ if (!sa) return
+ if (!searchOpen || !search.query.trim()) {
+ sa.clearDecorations()
+ return
+ }
+ sa.findNext(search.query, {
+ decorations: {
+ matchBackground: '#ffd54f55',
+ activeMatchBackground: '#ffb300',
+ matchOverviewRuler: '#ffd54f',
+ activeMatchColorOverviewRuler: '#ffb300'
+ }
+ })
+ }, [search.query, searchOpen])
+
+ // Cmd/Ctrl+F toggles the find-bar while this node is hovered. No main-process interception
+ // needed (the Electron renderer has no native find UI), unlike Cmd+M.
+ useEffect(() => {
+ const onKey = (e: KeyboardEvent) => {
+ if ((e.metaKey || e.ctrlKey) && !e.altKey && e.key.toLowerCase() === 'f' && hoveredRef.current) {
+ e.preventDefault()
+ setSearchOpen((v) => !v)
+ }
+ }
+ window.addEventListener('keydown', onKey, true)
+ return () => window.removeEventListener('keydown', onKey, true)
+ }, [])
+
// When markdown mode turns on, capture the terminal output and render it.
useEffect(() => {
if (data.mdMode) {
@@ -439,6 +499,15 @@ export function TerminalNode({ id, data, selected }: NodeProps<CanvasNode>) {
</span>
)}
{!editingTitle && <span className="term-node__spacer" />}
+ <Tooltip label={showUsage ? 'Search terminal + conversation' : 'Search this terminal'}>
+ <button
+ className="term-node__search nodrag"
+ onClick={() => setSearchOpen((v) => !v)}
+ aria-pressed={searchOpen}
+ >
+ <IconSearch />
+ </button>
+ </Tooltip>
<Tooltip label="Name with AI (from terminal output)">
<button className="term-node__ai nodrag" disabled={naming} onClick={nameWithAi}>
{naming ? '…' : '✦'}
@@ -456,6 +525,19 @@ export function TerminalNode({ id, data, selected }: NodeProps<CanvasNode>) {
</button>
</div>
+ {searchOpen && !collapsed && (
+ <FindBar
+ query={search.query}
+ onQueryChange={search.setQuery}
+ matchIndex={search.matchIndex}
+ matchCount={search.matchCount}
+ current={search.current}
+ onNext={search.next}
+ onPrev={search.prev}
+ onClose={() => setSearchOpen(false)}
+ />
+ )}
+
{!collapsed && (
<NodeTags tags={tags} onChange={(t) => updateNodeData(id, { tags: t })} />
)}