Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

feat(ui): terminal scrollback search + clickable links (#838)

Call White6247219ee4d4
diff --git a/ui/package-lock.json b/ui/package-lock.json
index 4e596f255..685113150 100644
--- a/ui/package-lock.json
+++ b/ui/package-lock.json
@@ -22,6 +22,8 @@
"@shikijs/themes": "^4.2.0",
"@uiw/react-json-view": "^2.0.0-alpha.43",
"@xterm/addon-fit": "^0.11.0",
+ "@xterm/addon-search": "^0.16.0",
+ "@xterm/addon-web-links": "^0.12.0",
"@xterm/xterm": "^6.0.0",
"agentation": "^3.0.2",
"chart.js": "^4.4.0",
@@ -3034,6 +3036,18 @@
"integrity": "sha512-jYcgT6xtVYhnhgxh3QgYDnnNMYTcf8ElbxxFzX0IZo+vabQqSPAjC3c1wJrKB5E19VwQei89QCiZZP86DCPF7g==",
"license": "MIT"
},
+ "node_modules/@xterm/addon-search": {
+ "version": "0.16.0",
+ "resolved": "https://registry.npmjs.org/@xterm/addon-search/-/addon-search-0.16.0.tgz",
+ "integrity": "sha512-9OeuBFu0/uZJPu+9AHKY6g/w0Czyb/Ut0A5t79I4ULoU4IfU5BEpPFVGQxP4zTTMdfZEYkVIRYbHBX1xWwjeSA==",
+ "license": "MIT"
+ },
+ "node_modules/@xterm/addon-web-links": {
+ "version": "0.12.0",
+ "resolved": "https://registry.npmjs.org/@xterm/addon-web-links/-/addon-web-links-0.12.0.tgz",
+ "integrity": "sha512-4Smom3RPyVp7ZMYOYDoC/9eGJJJqYhnPLGGqJ6wOBfB8VxPViJNSKdgRYb8NpaM6YSelEKbA2SStD7lGyqaobw==",
+ "license": "MIT"
+ },
"node_modules/@xterm/xterm": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/@xterm/xterm/-/xterm-6.0.0.tgz",
diff --git a/ui/package.json b/ui/package.json
index 941113da5..6ed3e5233 100644
--- a/ui/package.json
+++ b/ui/package.json
@@ -29,6 +29,8 @@
"@shikijs/themes": "^4.2.0",
"@uiw/react-json-view": "^2.0.0-alpha.43",
"@xterm/addon-fit": "^0.11.0",
+ "@xterm/addon-search": "^0.16.0",
+ "@xterm/addon-web-links": "^0.12.0",
"@xterm/xterm": "^6.0.0",
"agentation": "^3.0.2",
"chart.js": "^4.4.0",
diff --git a/ui/src/components/workbench/TerminalView.tsx b/ui/src/components/workbench/TerminalView.tsx
index b0d1adb94..fb18e1198 100644
--- a/ui/src/components/workbench/TerminalView.tsx
+++ b/ui/src/components/workbench/TerminalView.tsx
@@ -2,10 +2,13 @@ import { useEffect, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Terminal } from '@xterm/xterm';
import { FitAddon } from '@xterm/addon-fit';
+import { SearchAddon } from '@xterm/addon-search';
+import { WebLinksAddon } from '@xterm/addon-web-links';
import '@xterm/xterm/css/xterm.css';
-import { RotateCw } from 'lucide-react';
+import { ChevronDown, ChevronUp, RotateCw, Search, X } from 'lucide-react';
import { Button } from '../ui/button';
+import { Input } from '../ui/input';
// xterm.js wired to the /api/terminal/{id} WebSocket. Protocol (locked with the
// backend): client sends raw stdin as BINARY frames and JSON control as TEXT
@@ -28,6 +31,20 @@ const TERMINAL_THEME = {
selectionBackground: 'rgba(148,163,184,0.35)',
};
+// Search-match highlight colors for the SearchAddon. Amber reads clearly on the dark terminal and
+// stays out of the app theme's way (the terminal is theme-locked dark). Colors must be #RRGGBB; the
+// active (current) match is brighter than the rest. Decorations rely on the terminal's proposed
+// decoration API — allowProposedApi is already enabled below. The overview-ruler colors are only
+// painted when overviewRulerWidth is set (we don't set it), but the type requires them.
+const SEARCH_DECORATIONS = {
+ matchBackground: '#664d00',
+ matchBorder: '#8a6d1a',
+ matchOverviewRuler: '#b8860b',
+ activeMatchBackground: '#b8860b',
+ activeMatchBorder: '#ffcf5c',
+ activeMatchColorOverviewRuler: '#ffcf5c',
+};
+
// Accessory key bar for phones (their soft keyboards lack these). Each button sends the raw
// byte sequence the PTY expects; Ctrl is a sticky modifier. Labels go through i18n (the
// control sequences stay here).
@@ -51,6 +68,28 @@ function buildWsUrl(sessionId: string, cwd?: string | null): string {
return cwd ? `${base}?cwd=${encodeURIComponent(cwd)}` : base;
}
+// Apple vs. non-Apple decides the Find chord below. Detected once (navigator.platform is deprecated but
+// remains the most reliable signal, with userAgent as a fallback).
+const IS_APPLE =
+ typeof navigator !== 'undefined' &&
+ /Mac|iP(hone|ad|od)/i.test(navigator.platform || navigator.userAgent || '');
+
+// The chord that opens Find: ⌘F on Apple platforms, Ctrl+Shift+F everywhere else. Plain Ctrl+F is a live
+// terminal key on BOTH macOS and Linux (readline forward-char, less/vim page-forward), so it must keep
+// reaching the PTY — hence ⌘ on Apple (a free modifier) and the Shift-qualified chord elsewhere, which is
+// exactly what native terminals bind for find (GNOME Terminal, Konsole, Windows Terminal). Shared by the
+// terminal key handler and the search field so both agree; altKey is excluded to avoid stray combos.
+const isFindHotkey = (e: {
+ metaKey: boolean;
+ ctrlKey: boolean;
+ shiftKey: boolean;
+ altKey: boolean;
+ key: string;
+}): boolean =>
+ !e.altKey &&
+ (e.key === 'f' || e.key === 'F') &&
+ (IS_APPLE ? e.metaKey && !e.ctrlKey : e.ctrlKey && e.shiftKey && !e.metaKey);
+
export const TerminalView: React.FC<{
sessionId: string;
/** Start directory for a newly created session (from "Open Terminal Here"). Stable per tab. */
@@ -62,6 +101,8 @@ export const TerminalView: React.FC<{
const { t } = useTranslation();
const containerRef = useRef<HTMLDivElement | null>(null);
const termRef = useRef<Terminal | null>(null);
+ const searchRef = useRef<SearchAddon | null>(null);
+ const searchInputRef = useRef<HTMLInputElement | null>(null);
const wsRef = useRef<WebSocket | null>(null);
const ctrlStickyRef = useRef(false);
const busyRetriesRef = useRef(0);
@@ -74,6 +115,11 @@ export const TerminalView: React.FC<{
const [status, setStatus] = useState<TerminalStatus>('connecting');
const [exitCode, setExitCode] = useState<number | null>(null);
const [reconnectKey, setReconnectKey] = useState(0);
+ // Scrollback search (SearchAddon). Opened with ⌘F/Ctrl+F while the terminal has focus; results
+ // carry {index,count} for the "3/12" match counter (index is -1 past the highlight threshold).
+ const [searchOpen, setSearchOpen] = useState(false);
+ const [query, setQuery] = useState('');
+ const [matches, setMatches] = useState<{ index: number; count: number }>({ index: -1, count: 0 });
// Surface connection status to the parent (tab bar). The standalone status row inside the
// body was removed — only the terminating states render an in-body overlay (below).
@@ -93,6 +139,40 @@ export const TerminalView: React.FC<{
});
const fit = new FitAddon();
term.loadAddon(fit);
+ // Clickable URLs open in a new tab, but only on a modifier-click (⌘ on Apple, Ctrl elsewhere).
+ // Persistent sessions run tmux with `mouse on`, so an unmodified click is meaningful input for
+ // tmux/copy-mode and mouse-aware TUIs — gating on the modifier keeps plain clicks as terminal input
+ // and matches how VS Code / iTerm / GNOME Terminal follow terminal links. noopener defeats reverse-
+ // tabnabbing (the addon's own typings call this out); window.open never navigates the app frame.
+ term.loadAddon(
+ new WebLinksAddon((event, uri) => {
+ if (IS_APPLE ? event.metaKey : event.ctrlKey) {
+ window.open(uri, '_blank', 'noopener');
+ }
+ }),
+ );
+ const search = new SearchAddon();
+ term.loadAddon(search);
+ searchRef.current = search;
+ const searchResults = search.onDidChangeResults((e) =>
+ setMatches({ index: e.resultIndex, count: e.resultCount }),
+ );
+ // Intercept the Find chord only while xterm's textarea has focus (this handler runs solely for
+ // terminal key events), so the browser's own find stays available everywhere else in the app.
+ // Returning false stops xterm forwarding the key to the PTY; preventDefault stops the browser find.
+ term.attachCustomKeyEventHandler((e) => {
+ if (e.type === 'keydown' && isFindHotkey(e)) {
+ e.preventDefault();
+ setSearchOpen(true);
+ // Focus once the bar has mounted (first open) or refocus it (already open); rAF waits for commit.
+ requestAnimationFrame(() => {
+ searchInputRef.current?.focus();
+ searchInputRef.current?.select();
+ });
+ return false;
+ }
+ return true;
+ });
termRef.current = term;
const settleTimers: number[] = [];
let resizeSendTimer: number | null = null;
@@ -160,6 +240,7 @@ export const TerminalView: React.FC<{
});
setStatus('connecting');
setExitCode(null);
+ setMatches({ index: -1, count: 0 }); // a reconnect rebuilds the SearchAddon; drop the stale count
const ws = new WebSocket(buildWsUrl(sessionId, cwd));
ws.binaryType = 'arraybuffer';
wsRef.current = ws;
@@ -219,6 +300,7 @@ export const TerminalView: React.FC<{
for (const id of settleTimers) window.clearTimeout(id);
ro.disconnect();
onData.dispose();
+ searchResults.dispose();
// Detach handlers before closing. A closing socket's onclose can fire asynchronously
// *after* its replacement has already reported 'ready' (reconnect / effect remount);
// left attached, the stale onclose would mark the live terminal 'closed' or schedule a
@@ -235,6 +317,7 @@ export const TerminalView: React.FC<{
term.dispose();
wsRef.current = null;
termRef.current = null;
+ searchRef.current = null;
};
}, [sessionId, cwd, reconnectKey]);
@@ -253,6 +336,55 @@ export const TerminalView: React.FC<{
setReconnectKey((k) => k + 1);
};
+ // Step between matches. Incremental (type-ahead) applies only to findNext — it grows the current
+ // selection while it still matches; explicit next/prev jump to the adjacent match.
+ const runFind = (direction: 'next' | 'prev', incremental = false) => {
+ const s = searchRef.current;
+ if (!s || !query) return;
+ if (direction === 'prev') s.findPrevious(query, { decorations: SEARCH_DECORATIONS });
+ else s.findNext(query, { decorations: SEARCH_DECORATIONS, incremental });
+ };
+
+ const onQueryChange = (value: string) => {
+ setQuery(value);
+ const s = searchRef.current;
+ if (!s) return;
+ if (!value) {
+ s.clearDecorations();
+ setMatches({ index: -1, count: 0 });
+ return;
+ }
+ s.findNext(value, { decorations: SEARCH_DECORATIONS, incremental: true });
+ };
+
+ const closeSearch = () => {
+ setSearchOpen(false);
+ setQuery(''); // drop the term so reopening starts fresh instead of showing a stale "0/0" counter
+ searchRef.current?.clearDecorations();
+ setMatches({ index: -1, count: 0 });
+ termRef.current?.focus();
+ };
+
+ const onSearchKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
+ // Mid-IME-composition (e.g. a CJK candidate), Enter/Escape belong to the IME — accepting or
+ // cancelling the candidate — not to search navigation. Let them through untouched.
+ if (e.nativeEvent.isComposing) return;
+ if (e.key === 'Enter') {
+ e.preventDefault();
+ runFind(e.shiftKey ? 'prev' : 'next');
+ } else if (e.key === 'Escape') {
+ e.preventDefault();
+ closeSearch();
+ } else if (isFindHotkey(e)) {
+ // Focus is already in the field — keep the browser find bar from opening; reselect instead.
+ e.preventDefault();
+ e.currentTarget.select();
+ }
+ };
+
+ const matchLabel =
+ matches.count === 0 ? '0/0' : `${matches.index >= 0 ? matches.index + 1 : '?'}/${matches.count}`;
+
return (
<div className="flex h-full min-h-0 flex-col" style={{ backgroundColor: TERMINAL_BG }}>
{status === 'disabled' ? (
@@ -262,6 +394,60 @@ export const TerminalView: React.FC<{
) : (
<div className="relative min-h-0 flex-1">
<div ref={containerRef} className="absolute inset-0 overflow-hidden p-1.5" />
+ {searchOpen && (
+ // Compact find widget pinned to the terminal's top-right, like an editor's find bar. Colors
+ // are fixed-dark (not theme tokens) because the terminal body is theme-locked dark — the
+ // same reason the touch key bar below uses fixed colors rather than the global palette.
+ <div className="absolute right-2 top-2 z-10 flex items-center gap-0.5 rounded-lg border border-zinc-700/80 bg-zinc-900/95 px-1.5 py-1 shadow-lg backdrop-blur-sm">
+ <Search className="ml-0.5 size-3.5 shrink-0 text-zinc-500" aria-hidden />
+ <Input
+ ref={searchInputRef}
+ variant="bare"
+ value={query}
+ onChange={(e) => onQueryChange(e.target.value)}
+ onKeyDown={onSearchKeyDown}
+ placeholder={t('apps.terminal.search.placeholder')}
+ aria-label={t('apps.terminal.search.ariaLabel')}
+ spellCheck={false}
+ autoComplete="off"
+ className="h-6 w-36 px-1 text-[12px] text-zinc-100 placeholder:text-zinc-500 sm:w-48"
+ />
+ {query && (
+ <span
+ className="shrink-0 px-1 text-[11px] tabular-nums text-zinc-500"
+ aria-live="polite"
+ >
+ {matchLabel}
+ </span>
+ )}
+ <button
+ type="button"
+ onClick={() => runFind('prev')}
+ disabled={matches.count === 0}
+ aria-label={t('apps.terminal.search.prev')}
+ className="grid size-6 shrink-0 place-items-center rounded text-zinc-400 hover:bg-zinc-800 hover:text-zinc-100 disabled:opacity-40 disabled:hover:bg-transparent"
+ >
+ <ChevronUp className="size-3.5" />
+ </button>
+ <button
+ type="button"
+ onClick={() => runFind('next')}
+ disabled={matches.count === 0}
+ aria-label={t('apps.terminal.search.next')}
+ className="grid size-6 shrink-0 place-items-center rounded text-zinc-400 hover:bg-zinc-800 hover:text-zinc-100 disabled:opacity-40 disabled:hover:bg-transparent"
+ >
+ <ChevronDown className="size-3.5" />
+ </button>
+ <button
+ type="button"
+ onClick={closeSearch}
+ aria-label={t('apps.terminal.search.close')}
+ className="grid size-6 shrink-0 place-items-center rounded text-zinc-400 hover:bg-zinc-800 hover:text-zinc-100"
+ >
+ <X className="size-3.5" />
+ </button>
+ </div>
+ )}
{(status === 'closed' || status === 'error') && (
// The "connected" status no longer occupies its own row — it lives in the tab bar.
// Only the terminating states surface in the body, as a centred overlay that offers
diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.json
index 1253fccb9..11940e556 100644
--- a/ui/src/i18n/en.json
+++ b/ui/src/i18n/en.json
@@ -806,7 +806,14 @@
"interrupt": "^C",
"pipe": "|"
},
- "renameHint": "Double-click to rename"
+ "renameHint": "Double-click to rename",
+ "search": {
+ "placeholder": "Search",
+ "ariaLabel": "Search terminal output",
+ "prev": "Previous match",
+ "next": "Next match",
+ "close": "Close search"
+ }
},
"picker": {
"openFolderTitle": "Open Folder",
diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.json
index 3bd53af28..50c7038d5 100644
--- a/ui/src/i18n/zh.json
+++ b/ui/src/i18n/zh.json
@@ -806,7 +806,14 @@
"interrupt": "^C",
"pipe": "|"
},
- "renameHint": "双击重命名"
+ "renameHint": "双击重命名",
+ "search": {
+ "placeholder": "搜索",
+ "ariaLabel": "搜索终端输出",
+ "prev": "上一个匹配",
+ "next": "下一个匹配",
+ "close": "关闭搜索"
+ }
},
"picker": {
"openFolderTitle": "打开文件夹",