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.

fix(workbench): address pre-PR review (connection leak + i18n + dead code)

cyh4a14bf4ff2bf
diff --git a/ui/src/components/ui/directory-browser.tsx b/ui/src/components/ui/directory-browser.tsx
index 10c75c192..5e90d7d20 100644
--- a/ui/src/components/ui/directory-browser.tsx
+++ b/ui/src/components/ui/directory-browser.tsx
@@ -41,6 +41,10 @@ export const DirectoryBrowser: React.FC<DirectoryBrowserProps> = ({
const api = useApi();
const [currentPath, setCurrentPath] = useState('');
+ // Resolved user home — captured on the first browse('~') response so the
+ // breadcrumb collapse to ⌂ has a real prefix to match against. Falls back
+ // to '' (no collapse) if the user opened the picker with an absolute path.
+ const [homePath, setHomePath] = useState<string>('');
const [parent, setParent] = useState<string | null>(null);
const [dirs, setDirs] = useState<{ name: string; path: string }[]>([]);
const [loading, setLoading] = useState(false);
@@ -105,10 +109,24 @@ export const DirectoryBrowser: React.FC<DirectoryBrowserProps> = ({
return null;
}
if (result.ok) {
- setCurrentPath(result.path ?? path);
+ const resolvedPath = result.path ?? path;
+ setCurrentPath(resolvedPath);
setParent(result.parent ?? null);
setDirs(result.dirs ?? []);
- return result.path ?? path;
+ // Snapshot the resolved user home the first time the backend
+ // expands a tilde-prefixed path. Backend behavior: passing "~"
+ // returns the home directory in result.path; passing "~/x"
+ // returns "<home>/x". We derive home by trimming the requested
+ // suffix off the resolved path.
+ if (!homePath && path.startsWith('~')) {
+ const suffix = path === '~' ? '' : path.slice(1);
+ const derived = suffix && resolvedPath.endsWith(suffix)
+ ? resolvedPath.slice(0, resolvedPath.length - suffix.length)
+ : resolvedPath;
+ const cleaned = derived.replace(/\/+$/, '');
+ if (cleaned) setHomePath(cleaned);
+ }
+ return resolvedPath;
}
setError(result.error ?? 'Unknown error');
return null;
@@ -122,7 +140,7 @@ export const DirectoryBrowser: React.FC<DirectoryBrowserProps> = ({
}
}
},
- [api, showHidden],
+ [api, showHidden, homePath],
);
const navigate = useCallback(
@@ -187,21 +205,21 @@ export const DirectoryBrowser: React.FC<DirectoryBrowserProps> = ({
};
// Breadcrumb: collapse the home prefix to ⌂ so deeply-nested paths still fit
- // in the toolbar without scrolling.
+ // in the toolbar without scrolling. ``homePath`` is captured on the first
+ // tilde-expanded browse response (see fetchPath).
const breadcrumbs = (() => {
if (!currentPath) return [] as { label: string; path: string; isHome?: boolean }[];
- const home = (typeof window !== 'undefined' && (window as any).__USER_HOME__) || '';
- const startsAtHome = home && currentPath.startsWith(home);
- const segments = (startsAtHome ? currentPath.slice(home.length) : currentPath)
+ const startsAtHome = !!homePath && currentPath.startsWith(homePath);
+ const segments = (startsAtHome ? currentPath.slice(homePath.length) : currentPath)
.split('/')
.filter(Boolean);
const out: { label: string; path: string; isHome?: boolean }[] = [];
if (startsAtHome) {
- out.push({ label: '⌂', path: home, isHome: true });
+ out.push({ label: '⌂', path: homePath, isHome: true });
} else {
out.push({ label: '/', path: '/' });
}
- let acc = startsAtHome ? home : '';
+ let acc = startsAtHome ? homePath : '';
for (const seg of segments) {
acc = acc === '/' || acc === '' ? `${acc}${seg}` : `${acc}/${seg}`;
if (!acc.startsWith('/')) acc = `/${acc}`;
diff --git a/ui/src/components/workbench/HarnessPage.tsx b/ui/src/components/workbench/HarnessPage.tsx
index 8520540ac..361907144 100644
--- a/ui/src/components/workbench/HarnessPage.tsx
+++ b/ui/src/components/workbench/HarnessPage.tsx
@@ -23,6 +23,7 @@ import type {
HarnessTask,
HarnessWatch,
} from '../../context/ApiContext';
+import { formatRelativeTime } from '../../lib/relativeTime';
type TabKey = 'tasks' | 'watches' | 'webhooks' | 'runs';
@@ -279,8 +280,8 @@ const TasksList: React.FC<TasksListProps> = ({ tasks, loading, selectedId, onSel
<div className="flex items-center gap-2">
<span className="text-[14px] font-semibold text-foreground">{task.name || task.id}</span>
{!task.enabled && (
- <span className="rounded border border-border-strong bg-foreground/[0.04] px-1.5 py-0 font-mono text-[9px] text-muted">
- DISABLED
+ <span className="rounded border border-border-strong bg-foreground/[0.04] px-1.5 py-0 font-mono text-[9px] uppercase text-muted">
+ {t('harness.runtime.disabled')}
</span>
)}
</div>
@@ -293,7 +294,7 @@ const TasksList: React.FC<TasksListProps> = ({ tasks, loading, selectedId, onSel
</div>
</div>
{task.last_run_at && (
- <span className="font-mono text-[10px] text-muted">{formatRelative(task.last_run_at)}</span>
+ <span className="font-mono text-[10px] text-muted">{formatRelativeTime(task.last_run_at, t)}</span>
)}
</button>
);
@@ -379,25 +380,25 @@ const WatchesList: React.FC<WatchesListProps> = ({ watches, loading, selectedId,
<div className="flex items-center gap-2">
<span className="text-[14px] font-semibold text-foreground">{watch.name || watch.id}</span>
{watch.runtime.running ? (
- <span className="inline-flex items-center gap-1 rounded-full border border-mint/30 bg-mint/[0.08] px-2 py-0 font-mono text-[9px] font-bold text-mint">
+ <span className="inline-flex items-center gap-1 rounded-full border border-mint/30 bg-mint/[0.08] px-2 py-0 font-mono text-[9px] font-bold uppercase text-mint">
<span className="size-1.5 rounded-full bg-mint" />
- RUNNING
+ {t('harness.runtime.running')}
</span>
) : !watch.enabled ? (
- <span className="inline-flex items-center gap-1 rounded-full border border-border-strong bg-foreground/[0.04] px-2 py-0 font-mono text-[9px] text-muted">
+ <span className="inline-flex items-center gap-1 rounded-full border border-border-strong bg-foreground/[0.04] px-2 py-0 font-mono text-[9px] uppercase text-muted">
<PauseCircle className="size-2.5" />
- PAUSED
+ {t('harness.runtime.paused')}
</span>
) : (
- <span className="rounded border border-border-strong bg-foreground/[0.04] px-1.5 py-0 font-mono text-[9px] text-muted">
- IDLE
+ <span className="rounded border border-border-strong bg-foreground/[0.04] px-1.5 py-0 font-mono text-[9px] uppercase text-muted">
+ {t('harness.runtime.idle')}
</span>
)}
</div>
<div className="truncate font-mono text-[11px] text-muted">{cmd}</div>
</div>
{watch.last_event_at && (
- <span className="font-mono text-[10px] text-muted">{formatRelative(watch.last_event_at)}</span>
+ <span className="font-mono text-[10px] text-muted">{formatRelativeTime(watch.last_event_at, t)}</span>
)}
</button>
);
@@ -517,7 +518,7 @@ const RunsList: React.FC<RunsListProps> = ({ runs, loading, selectedId, onSelect
</div>
<div className="flex items-center gap-3 text-[11px] text-muted">
<span>{run.agent_name || '—'}</span>
- {run.created_at && <span>· {formatRelative(run.created_at)}</span>}
+ {run.created_at && <span>· {formatRelativeTime(run.created_at, t)}</span>}
</div>
</div>
</button>
@@ -657,24 +658,25 @@ interface StatusPillProps {
}
const StatusPill: React.FC<StatusPillProps> = ({ enabled, runtimeRunning }) => {
+ const { t } = useTranslation();
if (runtimeRunning) {
return (
- <span className="inline-flex items-center gap-1 rounded-full border border-mint/30 bg-mint/[0.08] px-2 py-0 font-mono text-[9px] font-bold text-mint">
+ <span className="inline-flex items-center gap-1 rounded-full border border-mint/30 bg-mint/[0.08] px-2 py-0 font-mono text-[9px] font-bold uppercase text-mint">
<span className="size-1.5 rounded-full bg-mint" />
- RUNNING
+ {t('harness.runtime.running')}
</span>
);
}
if (!enabled) {
return (
- <span className="rounded-full border border-border-strong bg-foreground/[0.04] px-2 py-0 font-mono text-[9px] text-muted">
- DISABLED
+ <span className="rounded-full border border-border-strong bg-foreground/[0.04] px-2 py-0 font-mono text-[9px] uppercase text-muted">
+ {t('harness.runtime.disabled')}
</span>
);
}
return (
- <span className="rounded-full border border-border-strong bg-foreground/[0.04] px-2 py-0 font-mono text-[9px] text-muted">
- ENABLED
+ <span className="rounded-full border border-border-strong bg-foreground/[0.04] px-2 py-0 font-mono text-[9px] uppercase text-muted">
+ {t('harness.runtime.enabled')}
</span>
);
};
@@ -701,18 +703,3 @@ const EmptyState: React.FC<{ i18nKey: string }> = ({ i18nKey }) => {
);
};
-function formatRelative(value: string | null | undefined): string {
- if (!value) return '—';
- const dt = new Date(value);
- if (Number.isNaN(dt.valueOf())) return value;
- const diffMs = Date.now() - dt.valueOf();
- const secs = Math.round(diffMs / 1000);
- if (secs < 60) return `${secs}s ago`;
- const mins = Math.round(secs / 60);
- if (mins < 60) return `${mins}m ago`;
- const hours = Math.round(mins / 60);
- if (hours < 24) return `${hours}h ago`;
- const days = Math.round(hours / 24);
- if (days < 7) return `${days}d ago`;
- return dt.toISOString().slice(0, 10);
-}
diff --git a/ui/src/components/workbench/InboxPage.tsx b/ui/src/components/workbench/InboxPage.tsx
index 51b7925d0..d5d316cd6 100644
--- a/ui/src/components/workbench/InboxPage.tsx
+++ b/ui/src/components/workbench/InboxPage.tsx
@@ -6,17 +6,7 @@ import clsx from 'clsx';
import { useWorkbenchInbox } from '../../context/WorkbenchInboxContext';
import type { WorkbenchMessage } from '../../context/ApiContext';
-
-function formatRelativeTime(iso: string): string {
- if (!iso) return '';
- const then = new Date(iso).getTime();
- if (Number.isNaN(then)) return '';
- const diff = (Date.now() - then) / 1000;
- if (diff < 60) return 'just now';
- if (diff < 3600) return `${Math.floor(diff / 60)} min ago`;
- if (diff < 86400) return `${Math.floor(diff / 3600)} h ago`;
- return `${Math.floor(diff / 86400)} d ago`;
-}
+import { formatRelativeTime } from '../../lib/relativeTime';
type FilterMode = 'unread' | 'all';
@@ -157,7 +147,7 @@ export const InboxPage: React.FC = () => {
<span className="flex-1 truncate text-[13px] font-semibold text-foreground">
{sessionLabel}
</span>
- <span className="font-mono text-muted">{formatRelativeTime(m.created_at)}</span>
+ <span className="font-mono text-muted">{formatRelativeTime(m.created_at, t)}</span>
</div>
<div className="flex flex-col gap-1">
diff --git a/ui/src/components/workbench/WorkbenchSidebar.tsx b/ui/src/components/workbench/WorkbenchSidebar.tsx
index 5c9ea4277..a6201560c 100644
--- a/ui/src/components/workbench/WorkbenchSidebar.tsx
+++ b/ui/src/components/workbench/WorkbenchSidebar.tsx
@@ -18,6 +18,7 @@ import type { LucideIcon } from 'lucide-react';
import { useWorkbenchInbox } from '../../context/WorkbenchInboxContext';
import type { WorkbenchMessage } from '../../context/ApiContext';
+import { formatRelativeTime } from '../../lib/relativeTime';
interface CapabilityNavItem {
to: string;
@@ -107,7 +108,7 @@ const InboxHoverPopover: React.FC<{
{m.metadata?.session_title as string | undefined || m.session_id}
</span>
<span className="font-mono text-muted">
- {formatRelativeTime(m.created_at)}
+ {formatRelativeTime(m.created_at, t)}
</span>
</div>
<div
@@ -136,18 +137,6 @@ const InboxHoverPopover: React.FC<{
);
};
-// Render an ISO timestamp as a Slack-ish relative label (2m / 14m / 3h / 1d).
-// Browser-side only; keeps the popover snappy without pulling a date lib.
-function formatRelativeTime(iso: string): string {
- if (!iso) return '';
- const then = new Date(iso).getTime();
- if (Number.isNaN(then)) return '';
- const diff = (Date.now() - then) / 1000;
- if (diff < 60) return 'now';
- if (diff < 3600) return `${Math.floor(diff / 60)}m`;
- if (diff < 86400) return `${Math.floor(diff / 3600)}h`;
- return `${Math.floor(diff / 86400)}d`;
-}
export const WorkbenchSidebar: React.FC = () => {
const { t } = useTranslation();
diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.json
index 1c4c97205..037225e6f 100644
--- a/ui/src/i18n/en.json
+++ b/ui/src/i18n/en.json
@@ -50,6 +50,12 @@
"delete": "Delete",
"previous": "Previous",
"next": "Next",
+ "relative": {
+ "justNow": "just now",
+ "minutesAgo": "{{count}}m ago",
+ "hoursAgo": "{{count}}h ago",
+ "daysAgo": "{{count}}d ago"
+ },
"test": "Test",
"testing": "Testing…",
"themeSystem": "System theme",
@@ -1229,6 +1235,13 @@
"webhooksSoonBody": "Inbound HTTP triggers will land in a follow-up release. Tasks and watches cover scheduled and event-driven runs today.",
"unknownSchedule": "unknown schedule",
"pageLabel": "page {{page}}",
+ "runtime": {
+ "running": "Running",
+ "paused": "Paused",
+ "idle": "Idle",
+ "enabled": "Enabled",
+ "disabled": "Disabled"
+ },
"tabs": {
"tasks": "Tasks",
"watches": "Watches",
diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.json
index d9fe87c37..8edb78100 100644
--- a/ui/src/i18n/zh.json
+++ b/ui/src/i18n/zh.json
@@ -50,6 +50,12 @@
"delete": "删除",
"previous": "上一页",
"next": "下一页",
+ "relative": {
+ "justNow": "刚刚",
+ "minutesAgo": "{{count}} 分钟前",
+ "hoursAgo": "{{count}} 小时前",
+ "daysAgo": "{{count}} 天前"
+ },
"test": "测试",
"testing": "测试中…",
"themeSystem": "跟随系统主题",
@@ -1229,6 +1235,13 @@
"webhooksSoonBody": "入站 HTTP 触发将在后续版本中落地。Tasks 和 Watches 已覆盖定时与事件驱动的运行。",
"unknownSchedule": "未知计划",
"pageLabel": "第 {{page}} 页",
+ "runtime": {
+ "running": "运行中",
+ "paused": "已暂停",
+ "idle": "空闲",
+ "enabled": "已启用",
+ "disabled": "已禁用"
+ },
"tabs": {
"tasks": "Tasks",
"watches": "Watches",
diff --git a/ui/src/lib/relativeTime.ts b/ui/src/lib/relativeTime.ts
new file mode 100644
index 000000000..084ca3ca5
--- /dev/null
+++ b/ui/src/lib/relativeTime.ts
@@ -0,0 +1,19 @@
+// Shared relative-time formatter. Three workbench surfaces (Inbox popover,
+// full Inbox page, Harness page) had near-identical copies that hardcoded
+// English suffixes; centralise here so the i18n strings live in one place.
+import type { TFunction } from 'i18next';
+
+export function formatRelativeTime(iso: string | null | undefined, t: TFunction): string {
+ if (!iso) return '—';
+ const then = new Date(iso).getTime();
+ if (Number.isNaN(then)) return iso;
+ const diffSec = Math.round((Date.now() - then) / 1000);
+ if (diffSec < 60) return t('common.relative.justNow');
+ const mins = Math.round(diffSec / 60);
+ if (mins < 60) return t('common.relative.minutesAgo', { count: mins });
+ const hours = Math.round(mins / 60);
+ if (hours < 24) return t('common.relative.hoursAgo', { count: hours });
+ const days = Math.round(hours / 24);
+ if (days < 7) return t('common.relative.daysAgo', { count: days });
+ return new Date(iso).toISOString().slice(0, 10);
+}
diff --git a/vibe/ui_server.py b/vibe/ui_server.py
index 649ee77a6..6af302529 100644
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@ -13,6 +13,7 @@ import socket
import subprocess
import threading
import time
+from contextlib import contextmanager
from datetime import datetime
from pathlib import Path
from typing import Any, Callable
@@ -2743,22 +2744,33 @@ def inbox_list():
# lands in a follow-up commit.
+@contextmanager
def _harness_store():
+ # ``SQLiteBackgroundTaskStore`` opens a dedicated ``SqliteInvalidationProbe``
+ # connection in __init__ that only closes when ``store.close()`` is
+ # called. Harness routes are polled frequently from the workbench UI,
+ # so leaking a connection per request exhausts the SQLite pool. The
+ # context manager makes ownership explicit at every call site.
from storage.background import SQLiteBackgroundTaskStore
- return SQLiteBackgroundTaskStore()
+ store = SQLiteBackgroundTaskStore()
+ try:
+ yield store
+ finally:
+ store.close()
@app.route("/api/harness/tasks", methods=["GET"])
def harness_tasks_list():
- return jsonify({"tasks": _harness_store().list_scheduled_tasks()})
+ with _harness_store() as store:
+ return jsonify({"tasks": store.list_scheduled_tasks()})
@app.route("/api/harness/watches", methods=["GET"])
def harness_watches_list():
- store = _harness_store()
- watches = store.list_watches()
- runtime = store.load_watch_runtime().get("watches") or {}
+ with _harness_store() as store:
+ watches = store.list_watches()
+ runtime = store.load_watch_runtime().get("watches") or {}
for watch in watches:
watch["runtime"] = runtime.get(watch["id"]) or {"running": False}
return jsonify({"watches": watches})
@@ -2783,15 +2795,16 @@ def harness_runs_list():
query = request.args.get("query") or None
page_request = make_page_request(page=page, limit=limit)
- page_result = _harness_store().list_runs_page(
- status=status,
- run_type=run_type,
- agent_name=agent_name,
- definition_id=definition_id,
- query=query,
- page_request=page_request,
- newest_first=True,
- )
+ with _harness_store() as store:
+ page_result = store.list_runs_page(
+ status=status,
+ run_type=run_type,
+ agent_name=agent_name,
+ definition_id=definition_id,
+ query=query,
+ page_request=page_request,
+ newest_first=True,
+ )
return jsonify(
{
"runs": page_result.items,
@@ -2804,7 +2817,8 @@ def harness_runs_list():
@app.route("/api/harness/runs/<run_id>", methods=["GET"])
def harness_run_detail(run_id: str):
- run = _harness_store().get_run(run_id)
+ with _harness_store() as store:
+ run = store.get_run(run_id)
if not run:
return jsonify({"ok": False, "code": "run_not_found"}), 404
return jsonify({"ok": True, "run": run})