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(agents): 12-item feedback batch

cyh2f4f100885a4
diff --git a/ui/src/components/ui/button.tsx b/ui/src/components/ui/button.tsx
index b4a977acf..38aeb64c2 100644
--- a/ui/src/components/ui/button.tsx
+++ b/ui/src/components/ui/button.tsx
@@ -30,6 +30,11 @@ const buttonVariants = cva(
'gap-1.5 border border-cyan/40 bg-cyan/[0.06] text-cyan hover:bg-cyan/[0.10]',
ghost: 'gap-1.5 text-foreground hover:bg-surface-2',
destructive: 'gap-1.5 bg-destructive text-destructive-foreground hover:opacity-90',
+ // Pink-soft destructive — design.pen T09T8Z. Pink-tinted fill +
+ // border + text, used for in-panel delete CTAs where a full
+ // destructive shouts too loud.
+ 'destructive-soft':
+ 'gap-1.5 border border-pink/40 bg-[#FF5B8A14] text-pink hover:bg-pink/[0.14]',
link: 'text-primary underline-offset-4 hover:underline',
accent: 'gap-1.5 border border-cyan/40 bg-cyan-soft text-cyan hover:bg-cyan/15',
},
diff --git a/ui/src/components/workbench/AgentsPage.tsx b/ui/src/components/workbench/AgentsPage.tsx
index 0d248b58e..98e7121c3 100644
--- a/ui/src/components/workbench/AgentsPage.tsx
+++ b/ui/src/components/workbench/AgentsPage.tsx
@@ -6,7 +6,6 @@ import {
ChevronRight,
Funnel,
Loader2,
- Pause,
Pencil,
Play,
Plus,
@@ -21,12 +20,14 @@ import { useApi } from '../../context/ApiContext';
import type { VibeAgentBrief, VibeAgentFull } from '../../context/ApiContext';
import { useToast } from '../../context/ToastContext';
import { NewAgentDialog } from './NewAgentDialog';
+import { RunAgentDialog } from './RunAgentDialog';
import { Badge } from '../ui/badge';
import { Button } from '../ui/button';
import { Switch } from '../ui/switch';
import { Combobox } from '../ui/combobox';
import type { ComboboxOption } from '../ui/combobox';
import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover';
+import { estimateTokens } from '../../lib/tokenEstimate';
const BACKEND_ORDER = ['claude', 'opencode', 'codex'] as const;
type Backend = (typeof BACKEND_ORDER)[number];
@@ -449,17 +450,18 @@ interface DetailProps {
onClose: () => void;
}
-// Mirrors design.pen s7QaWQ. Header (DEFAULT badge + name + close X) →
-// Enable card → Name → Backend (read-only) → Model (Combobox) → Reasoning
-// Effort segmented → System Prompt (collapsible) → footer Run / Disable /
-// Delete. The "Set as default" button I had here earlier wasn't in the
-// design — default selection happens elsewhere (new-agent dialog / global
-// settings); the panel just shows the DEFAULT badge.
-const AgentDetailPanel: React.FC<DetailProps> = ({ agent, isDefault, onChange, onDelete, onClose }) => {
+// Mirrors design.pen s7QaWQ. Header (name + close X) → Enable card →
+// Name → Backend (read-only) → Model (Combobox) → Reasoning effort →
+// System Prompt (collapsible) → footer Run / Delete. Name is editable
+// for user agents (rename = create-then-delete since backend keeps name
+// as the immutable reference id). System agents lock the name.
+const AgentDetailPanel: React.FC<DetailProps> = ({ agent, onChange, onDelete, onClose }) => {
const { t } = useTranslation();
const api = useApi();
+ const { showToast } = useToast();
const system = isSystemAgent(agent);
const [name, setName] = useState(agent.name);
+ const [renaming, setRenaming] = useState(false);
const [model, setModel] = useState(agent.model ?? '');
const [effort, setEffort] = useState(agent.reasoning_effort ?? 'medium');
const [systemPrompt, setSystemPrompt] = useState(agent.system_prompt ?? '');
@@ -501,17 +503,59 @@ const AgentDetailPanel: React.FC<DetailProps> = ({ agent, isDefault, onChange, o
};
}, [agent.backend, api]);
- const systemPromptCount = systemPrompt.length;
+ const systemPromptTokens = estimateTokens(systemPrompt);
+
+ // Backend rejects PATCH /agents/<name> with a new name; the supported
+ // way to rename is create-then-delete. We only let user agents do this
+ // (system agents block both delete and name change).
+ const commitRename = async () => {
+ const trimmed = name.trim();
+ if (!trimmed || trimmed === agent.name) {
+ setName(agent.name);
+ return;
+ }
+ if (system) {
+ setName(agent.name);
+ return;
+ }
+ setRenaming(true);
+ try {
+ // Clone with new name first so we never end up nameless on failure.
+ await api.createVibeAgent({
+ name: trimmed,
+ backend: agent.backend,
+ description: agent.description,
+ model: agent.model,
+ reasoning_effort: agent.reasoning_effort,
+ system_prompt: agent.system_prompt,
+ metadata: agent.metadata,
+ enabled: agent.enabled,
+ });
+ const removeResult = await api.removeVibeAgent(agent.name);
+ if (!removeResult.ok) {
+ // Old name still has references — keep it but tell the user the
+ // new one exists too.
+ showToast(removeResult.message || 'Agent renamed (old one kept due to references)', 'warning');
+ } else {
+ showToast('Agent renamed', 'success');
+ }
+ // Parent will refresh the list; the cloned agent shows up as the
+ // newly-selected detail row.
+ onClose();
+ } catch (err: any) {
+ showToast(err?.message ?? String(err), 'error');
+ setName(agent.name);
+ } finally {
+ setRenaming(false);
+ }
+ };
return (
<div className="flex flex-col gap-3.5">
- {/* Header row — design.pen j5dGQ8: default-badge + name + subtitle + X */}
+ {/* Header row — design.pen j5dGQ8 without DEFAULT badge (now read-
+ only via the list-row pill; the panel always shows the agent's
+ current identity, not its "is-default" status). */}
<div className="flex items-start gap-2.5">
- {isDefault && (
- <Badge variant="success" className="mt-0.5 px-1.5 py-0 font-mono text-[9px] uppercase">
- default
- </Badge>
- )}
<div className="flex min-w-0 flex-1 flex-col">
<div className="truncate text-[16px] font-bold text-foreground">{agent.name}</div>
<div className="truncate text-[10px] text-muted">
@@ -526,8 +570,6 @@ const AgentDetailPanel: React.FC<DetailProps> = ({ agent, isDefault, onChange, o
aria-label={t('common.close')}
className="size-6"
>
- <Pencil className="hidden" />
- <span className="sr-only">{t('common.close')}</span>
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>
</Button>
</div>
@@ -550,34 +592,30 @@ const AgentDetailPanel: React.FC<DetailProps> = ({ agent, isDefault, onChange, o
/>
</div>
- {/* Name — design.pen sfcdx (NAME label + editable input with pencil) */}
+ {/* Name — system agents are locked; user agents are editable via
+ create-then-delete (no DB-level rename support). */}
<Field label={t('agents.detail.name')}>
<div className="flex items-center gap-2 rounded-lg border border-border-strong bg-surface-2 px-3 py-2">
<input
value={name}
onChange={(e) => setName(e.target.value)}
- onBlur={() => {
- if (name !== agent.name && name.trim()) {
- // Name is the primary key for vibe agents; renaming isn't
- // currently supported by the backend so we just revert if
- // the value changes. Keep the editable affordance so the
- // panel matches design, but warn via title.
- setName(agent.name);
- }
+ onBlur={commitRename}
+ onKeyDown={(e) => {
+ if (e.key === 'Enter') (e.target as HTMLInputElement).blur();
+ if (e.key === 'Escape') setName(agent.name);
}}
- disabled
- title={t('agents.detail.systemLocked')}
- className="flex-1 bg-transparent text-[13px] font-medium text-foreground outline-none disabled:cursor-not-allowed"
+ disabled={system || renaming}
+ title={system ? t('agents.detail.systemLocked') : undefined}
+ className="flex-1 bg-transparent text-[13px] font-medium text-foreground outline-none disabled:cursor-not-allowed disabled:opacity-70"
/>
- <Pencil className="size-3 shrink-0 text-muted opacity-40" />
+ {!system && <Pencil className="size-3 shrink-0 text-muted" />}
</div>
</Field>
- {/* Backend (read-only) — design.pen JUopp */}
- <Field
- label={t('agents.detail.backend')}
- labelRight={<span className="font-mono text-[9px] text-muted">{t('agents.detail.backendLocked')}</span>}
- >
+ {/* Backend (read-only) — design.pen JUopp. "creation-time only ·
+ locked" hint sits inside the value chip on the right so users
+ don't mistake it for a note about the field above (the name). */}
+ <Field label={t('agents.detail.backend')}>
<div className="flex items-center gap-2 rounded-lg border border-border bg-surface-3 px-3 py-2">
<Bot className={clsx('size-3 shrink-0', BACKEND_ICON_CLASS[agent.backend as Backend] || 'text-muted')} />
<span className={clsx('font-mono text-[12px] font-bold', BACKEND_ICON_CLASS[agent.backend as Backend] || 'text-foreground')}>
@@ -585,13 +623,11 @@ const AgentDetailPanel: React.FC<DetailProps> = ({ agent, isDefault, onChange, o
</span>
<span className="text-[11px] text-muted">·</span>
<span className="text-[11px] text-muted">{BACKEND_LABEL[agent.backend as Backend] || agent.backend} CLI</span>
+ <span className="ml-auto font-mono text-[9px] text-muted">{t('agents.detail.backendLocked')}</span>
</div>
</Field>
- {/* Model — design.pen m1Y25H + b7INFU. Combobox with chevron, allows
- picking from the backend's known model list OR typing a custom
- value. Free-form typing matters because the model catalog lags
- behind providers' release cadence. */}
+ {/* Model — Combobox with chevron + searchable + custom values. */}
<Field label={t('agents.detail.model')}>
<Combobox
options={modelOptions}
@@ -606,8 +642,7 @@ const AgentDetailPanel: React.FC<DetailProps> = ({ agent, isDefault, onChange, o
/>
</Field>
- {/* Reasoning effort — design.pen LsjxT segmented control. Active
- segment fills mint-soft and shows mint bold text. */}
+ {/* Reasoning effort — design.pen LsjxT */}
<Field label={t('agents.detail.effort')}>
<div className="grid grid-cols-4 rounded-lg border border-border-strong bg-surface-2 p-0.5">
{EFFORT_OPTIONS.map((opt) => {
@@ -632,9 +667,11 @@ const AgentDetailPanel: React.FC<DetailProps> = ({ agent, isDefault, onChange, o
</div>
</Field>
- {/* System prompt — design.pen y3mRv: collapsed by default. The whole
- row is a button; click to expand the textarea below. Shows char
- count on the right while collapsed. */}
+ {/* System prompt — design.pen y3mRv: collapsed by default. Token
+ estimate (cheap heuristic, see lib/tokenEstimate) replaces the
+ old character count so it's actually useful for budgeting. The
+ textarea-level hint was deleted because the field label + the
+ chevron row already tell the user what this is. */}
<div className="flex flex-col gap-2">
<button
type="button"
@@ -651,31 +688,28 @@ const AgentDetailPanel: React.FC<DetailProps> = ({ agent, isDefault, onChange, o
{t('agents.detail.systemPrompt')}
</span>
<span className="font-mono text-[10px] text-muted">
- {t('agents.detail.systemPromptCount', { count: systemPromptCount })}
+ {t('agents.detail.systemPromptCount', { count: systemPromptTokens })}
</span>
</button>
{systemPromptOpen && (
- <div className="flex flex-col gap-1.5">
- <textarea
- value={systemPrompt}
- onChange={(e) => setSystemPrompt(e.target.value)}
- onBlur={() => {
- if (systemPrompt !== (agent.system_prompt ?? '')) {
- onChange({ system_prompt: systemPrompt.trim() || null });
- }
- }}
- rows={6}
- placeholder={t('agents.create.systemPromptPlaceholder')}
- className="rounded-md border border-border-strong bg-surface-3 px-3 py-2 text-[12px] text-foreground outline-none focus:border-cyan"
- />
- <span className="text-[10px] text-muted">{t('agents.detail.systemPromptHint')}</span>
- </div>
+ <textarea
+ value={systemPrompt}
+ onChange={(e) => setSystemPrompt(e.target.value)}
+ onBlur={() => {
+ if (systemPrompt !== (agent.system_prompt ?? '')) {
+ onChange({ system_prompt: systemPrompt.trim() || null });
+ }
+ }}
+ rows={6}
+ placeholder={t('agents.create.systemPromptPlaceholder')}
+ className="rounded-md border border-border-strong bg-surface-3 px-3 py-2 text-[12px] text-foreground outline-none focus:border-cyan"
+ />
)}
</div>
- {/* Footer — design.pen o8HTP. Run primary (mint outline) on the
- left, Disable/Enable secondary, spacer pushes Delete (pink) to
- the right. System agents hide Delete. */}
+ {/* Footer — Run on the left, Delete on the right. The Disable
+ button was redundant with the top Enable toggle and was
+ removed. */}
<div className="flex items-center gap-2 pt-2">
<Button
type="button"
@@ -683,29 +717,17 @@ const AgentDetailPanel: React.FC<DetailProps> = ({ agent, isDefault, onChange, o
size="xs"
onClick={() => setRunning(true)}
className="border-mint/40 bg-mint-soft text-mint hover:brightness-110"
- disabled
- title="Run from this panel — coming soon"
>
<Play className="size-3" />
{t('agents.detail.run')}
</Button>
- <Button
- type="button"
- variant="outline"
- size="xs"
- onClick={() => onChange({ enabled: !agent.enabled })}
- >
- {agent.enabled ? <Pause className="size-3" /> : <Play className="size-3" />}
- {agent.enabled ? t('agents.detail.disable') : t('agents.detail.enable')}
- </Button>
<div className="flex-1" />
{!system ? (
<Button
type="button"
- variant="outline"
+ variant="destructive-soft"
size="xs"
onClick={onDelete}
- className="border-pink/40 bg-[#FF5B8A14] text-pink hover:bg-pink/[0.14]"
>
<Trash2 className="size-3" />
{t('common.delete')}
@@ -714,9 +736,8 @@ const AgentDetailPanel: React.FC<DetailProps> = ({ agent, isDefault, onChange, o
<span className="text-[10px] text-muted">{t('agents.detail.systemLocked')}</span>
)}
</div>
- {/* Suppress unused-state warning for the Run handler stub until the
- real "run-from-panel" flow lands. */}
- {running && <span className="sr-only" aria-hidden>running</span>}
+
+ {running && <RunAgentDialog agent={agent} onClose={() => setRunning(false)} />}
</div>
);
};
diff --git a/ui/src/components/workbench/NewAgentDialog.tsx b/ui/src/components/workbench/NewAgentDialog.tsx
index 432774f0a..6393eb829 100644
--- a/ui/src/components/workbench/NewAgentDialog.tsx
+++ b/ui/src/components/workbench/NewAgentDialog.tsx
@@ -1,10 +1,12 @@
-import { useEffect, useState } from 'react';
+import { useEffect, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { ArrowRight, Bot, X } from 'lucide-react';
import clsx from 'clsx';
import { useApi } from '../../context/ApiContext';
import type { VibeAgentFull } from '../../context/ApiContext';
+import { Combobox } from '../ui/combobox';
+import type { ComboboxOption } from '../ui/combobox';
type BackendKey = 'claude' | 'opencode' | 'codex';
@@ -17,7 +19,10 @@ interface BackendOption {
const BACKEND_OPTIONS: BackendOption[] = [
{ key: 'claude', label: 'Claude', publisher: 'Anthropic', color: 'mint' },
- { key: 'opencode', label: 'OpenCode', publisher: 'sst.dev', color: 'cyan' },
+ // OpenCode is the upstream project at opencode.ai (not sst.dev — that
+ // was an older publisher attribution that doesn't match the current
+ // project page).
+ { key: 'opencode', label: 'OpenCode', publisher: 'opencode.ai', color: 'cyan' },
{ key: 'codex', label: 'Codex', publisher: 'OpenAI', color: 'violet' },
];
@@ -43,6 +48,7 @@ export const NewAgentDialog: React.FC<NewAgentDialogProps> = ({ open, onClose, o
const [systemPrompt, setSystemPrompt] = useState('');
const [submitting, setSubmitting] = useState(false);
const [error, setError] = useState<string | null>(null);
+ const [modelOptions, setModelOptions] = useState<ComboboxOption[]>([]);
useEffect(() => {
if (!open) {
@@ -56,6 +62,41 @@ export const NewAgentDialog: React.FC<NewAgentDialogProps> = ({ open, onClose, o
}
}, [open]);
+ // Reload the model catalog whenever the selected backend changes so
+ // the Combobox suggests the right list. allowCustomValue stays on so
+ // freshly-released model IDs can still be typed in.
+ useEffect(() => {
+ if (!open) return;
+ let cancelled = false;
+ async function loadModels() {
+ try {
+ let models: string[] = [];
+ if (backend === 'claude') {
+ const result = await api.claudeModels();
+ if (result.ok && result.models) models = result.models;
+ } else if (backend === 'codex') {
+ const result = await api.codexModels();
+ if (result.ok && result.models) models = result.models;
+ }
+ if (!cancelled) {
+ setModelOptions(models.map((m) => ({ value: m, label: m })));
+ // Clear model when the backend changes if the previous choice
+ // isn't in the new catalog — avoids silently mismatched pairs.
+ if (model && !models.includes(model)) setModel('');
+ }
+ } catch {
+ if (!cancelled) setModelOptions([]);
+ }
+ }
+ loadModels();
+ return () => {
+ cancelled = true;
+ };
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [backend, open, api]);
+
+ const modelComboboxOptions = useMemo(() => modelOptions, [modelOptions]);
+
useEffect(() => {
if (!open) return;
const onKey = (e: KeyboardEvent) => {
@@ -165,37 +206,42 @@ export const NewAgentDialog: React.FC<NewAgentDialogProps> = ({ open, onClose, o
onKeyDown={(e) => {
if (e.key === 'Enter' && canSubmit) handleSubmit();
}}
- placeholder="slack-triage"
+ placeholder="reviewer"
className="rounded-md border border-border-strong bg-surface-2 px-3 py-2 font-mono text-[13px] text-foreground outline-none focus:border-cyan"
/>
</div>
- {/* Model + Effort */}
+ {/* Model + Effort — both rows share a 38px height so the Combobox
+ on the left and the segmented control on the right align. The
+ segments use rounded-md py-2 (was py-0.5 which collapsed to
+ ~24px and looked stubby next to the model field). */}
<div className="grid grid-cols-2 gap-3">
<div className="flex flex-col gap-1.5">
<div className="font-mono text-[10px] font-bold uppercase tracking-[0.12em] text-muted">
{t('agents.create.model')}
</div>
- <input
+ <Combobox
+ options={modelComboboxOptions}
value={model}
- onChange={(e) => setModel(e.target.value)}
- placeholder={t('agents.create.modelPlaceholder')}
- className="rounded-md border border-border-strong bg-surface-2 px-3 py-2 font-mono text-[12px] text-foreground outline-none focus:border-cyan"
+ onValueChange={setModel}
+ placeholder={t('agents.detail.modelPlaceholder')}
+ emptyText={t('agents.detail.modelEmpty')}
+ allowCustomValue
/>
</div>
<div className="flex flex-col gap-1.5">
<div className="font-mono text-[10px] font-bold uppercase tracking-[0.12em] text-muted">
{t('agents.create.effort')}
</div>
- <div className="flex rounded-md border border-border-strong bg-surface-2 p-0.5">
+ <div className="grid h-[38px] grid-cols-4 rounded-md border border-border-strong bg-surface-2 p-0.5">
{EFFORT_OPTIONS.map((opt) => (
<button
key={opt}
type="button"
onClick={() => setEffort(opt)}
className={clsx(
- 'flex-1 rounded text-[11px] font-semibold capitalize transition',
- effort === opt ? 'bg-mint/[0.10] text-mint' : 'text-muted hover:text-foreground',
+ 'rounded text-[11px] capitalize transition',
+ effort === opt ? 'bg-mint-soft font-bold text-mint' : 'font-medium text-muted hover:text-foreground',
)}
>
{opt}
diff --git a/ui/src/components/workbench/RunAgentDialog.tsx b/ui/src/components/workbench/RunAgentDialog.tsx
new file mode 100644
index 000000000..b8ec5bc18
--- /dev/null
+++ b/ui/src/components/workbench/RunAgentDialog.tsx
@@ -0,0 +1,168 @@
+import { useEffect, useState } from 'react';
+import { useTranslation } from 'react-i18next';
+import { useNavigate } from 'react-router-dom';
+import { ArrowRight, Loader2, Play, X } from 'lucide-react';
+
+import { useApi } from '../../context/ApiContext';
+import type { VibeAgentFull, WorkbenchProject } from '../../context/ApiContext';
+import { Button } from '../ui/button';
+
+interface RunAgentDialogProps {
+ agent: VibeAgentFull;
+ onClose: () => void;
+}
+
+// Lightweight project picker that spins up a session under the picked
+// project bound to the given Agent, then routes the user straight into
+// the Chat page. Mirrors the Harness create-via-chat flow but skips the
+// seed-prompt step — Run means "start a clean chat using this agent",
+// not "ask the agent to set itself up".
+export const RunAgentDialog: React.FC<RunAgentDialogProps> = ({ agent, onClose }) => {
+ const { t } = useTranslation();
+ const api = useApi();
+ const navigate = useNavigate();
+ const [projects, setProjects] = useState<WorkbenchProject[] | null>(null);
+ const [projectId, setProjectId] = useState<string>('');
+ const [submitting, setSubmitting] = useState(false);
+ const [error, setError] = useState<string | null>(null);
+
+ useEffect(() => {
+ let cancelled = false;
+ api
+ .listProjects()
+ .then((result) => {
+ if (cancelled) return;
+ setProjects(result.projects);
+ if (result.projects.length > 0) {
+ const sorted = [...result.projects].sort((a, b) => {
+ const aTs = a.last_active_at || a.created_at;
+ const bTs = b.last_active_at || b.created_at;
+ return bTs.localeCompare(aTs);
+ });
+ setProjectId(sorted[0].id);
+ }
+ })
+ .catch((err) => {
+ if (!cancelled) setError(err?.message ?? String(err));
+ });
+ return () => {
+ cancelled = true;
+ };
+ }, [api]);
+
+ const open = async () => {
+ if (!projectId || submitting) return;
+ setSubmitting(true);
+ setError(null);
+ try {
+ const session = await api.createSession({
+ project_id: projectId,
+ agent_backend: agent.backend,
+ agent_name: agent.name,
+ agent_id: agent.id,
+ model: agent.model || undefined,
+ reasoning_effort: agent.reasoning_effort || undefined,
+ });
+ navigate(`/chat/${encodeURIComponent(session.id)}`);
+ } catch (err: any) {
+ setError(err?.message ?? String(err));
+ setSubmitting(false);
+ }
+ };
+
+ const noProjects = projects !== null && projects.length === 0;
+
+ return (
+ <div
+ className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 px-4"
+ role="dialog"
+ aria-modal="true"
+ aria-label={t('agents.runDialog.title')}
+ onClick={onClose}
+ >
+ <div
+ className="flex w-full max-w-md flex-col gap-4 rounded-2xl border border-border-strong bg-surface p-5 shadow-[0_24px_64px_-12px_rgba(0,0,0,0.6)]"
+ onClick={(e) => e.stopPropagation()}
+ >
+ <div className="flex items-start gap-3">
+ <div className="flex size-9 items-center justify-center rounded-lg border border-mint/30 bg-mint-soft text-mint">
+ <Play className="size-4" />
+ </div>
+ <div className="flex flex-1 flex-col gap-0.5">
+ <div className="text-[14px] font-bold text-foreground">{t('agents.runDialog.title')}</div>
+ <div className="text-[11.5px] leading-relaxed text-muted">
+ {t('agents.runDialog.description')}
+ </div>
+ </div>
+ <button
+ type="button"
+ onClick={onClose}
+ aria-label={t('common.close')}
+ className="text-muted transition hover:text-foreground"
+ >
+ <X className="size-4" />
+ </button>
+ </div>
+
+ <div className="flex flex-col gap-1.5">
+ <label className="font-mono text-[10px] font-bold uppercase tracking-[0.16em] text-muted">
+ {t('agents.runDialog.projectLabel')}
+ </label>
+ {projects === null ? (
+ <div className="flex items-center gap-2 rounded-md border border-border-strong bg-surface-2 px-3 py-2 text-[12px] text-muted">
+ <Loader2 className="size-3 animate-spin" />
+ {t('common.loading')}
+ </div>
+ ) : noProjects ? (
+ <div className="rounded-md border border-dashed border-border bg-foreground/[0.02] px-3 py-2 text-[12px] text-muted">
+ {t('agents.runDialog.noProject')}
+ </div>
+ ) : (
+ <select
+ value={projectId}
+ onChange={(e) => setProjectId(e.target.value)}
+ className="rounded-md border border-border-strong bg-surface-2 px-3 py-2 text-[12.5px] text-foreground outline-none transition focus:border-mint"
+ >
+ {projects.map((p) => (
+ <option key={p.id} value={p.id}>
+ {p.display_name} · {p.folder_path}
+ </option>
+ ))}
+ </select>
+ )}
+ </div>
+
+ {error && (
+ <div className="rounded-md border border-destructive/40 bg-destructive/[0.06] px-3 py-2 text-[12px] text-destructive">
+ {error}
+ </div>
+ )}
+
+ <div className="flex items-center justify-end gap-2">
+ <Button type="button" variant="outline" size="sm" onClick={onClose} disabled={submitting}>
+ {t('agents.runDialog.cancel')}
+ </Button>
+ <Button
+ type="button"
+ variant="brand"
+ size="sm"
+ onClick={open}
+ disabled={!projectId || submitting || noProjects}
+ >
+ {submitting ? (
+ <>
+ <Loader2 className="size-3.5 animate-spin" />
+ {t('agents.runDialog.opening')}
+ </>
+ ) : (
+ <>
+ {t('agents.runDialog.open')}
+ <ArrowRight className="size-3.5" />
+ </>
+ )}
+ </Button>
+ </div>
+ </div>
+ </div>
+ );
+};
diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.json
index 39bc949db..16d6ce254 100644
--- a/ui/src/i18n/en.json
+++ b/ui/src/i18n/en.json
@@ -1241,12 +1241,19 @@
"modelEmpty": "No matches — you can type a custom value.",
"effort": "Reasoning effort",
"systemPrompt": "System prompt",
- "systemPromptCount": "{{count}} chars",
- "systemPromptHint": "Optional. Prepended to every conversation that uses this agent.",
+ "systemPromptCount": "~{{count}} tokens",
"systemLocked": "System agents cannot be deleted. You can still adjust model, effort, and system prompt.",
- "run": "Run…",
- "disable": "Disable",
- "enable": "Enable"
+ "run": "Run",
+ "nameLocked": "Used as the reference id · locked after create"
+ },
+ "runDialog": {
+ "title": "Open a chat with this agent",
+ "description": "Pick a project. A new session is created under it and the chat opens immediately.",
+ "projectLabel": "Project",
+ "noProject": "No projects yet — add one from the sidebar + button first.",
+ "cancel": "Cancel",
+ "open": "Open chat",
+ "opening": "Creating session…"
},
"create": {
"title": "New Agent",
diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.json
index 1c64790a9..7d4a04ccb 100644
--- a/ui/src/i18n/zh.json
+++ b/ui/src/i18n/zh.json
@@ -1240,12 +1240,19 @@
"modelEmpty": "找不到匹配的模型,可以直接输入。",
"effort": "推理强度",
"systemPrompt": "系统提示词",
- "systemPromptCount": "{{count}} 字",
- "systemPromptHint": "可选。会拼接到使用本 Agent 的每一段对话前。",
+ "systemPromptCount": "~{{count}} tokens",
"systemLocked": "系统 Agent 不可删除,仍可调整模型、Effort 与系统提示词。",
- "run": "运行测试…",
- "disable": "禁用",
- "enable": "启用"
+ "run": "运行",
+ "nameLocked": "用作引用 ID,创建后不可改"
+ },
+ "runDialog": {
+ "title": "用此 Agent 开一个会话",
+ "description": "选个项目,会在项目下新建会话并立即跳到对话页。",
+ "projectLabel": "项目",
+ "noProject": "还没有项目 — 先在侧栏 + 按钮建一个。",
+ "cancel": "取消",
+ "open": "开始会话",
+ "opening": "创建会话中…"
},
"create": {
"title": "新建 Agent",
diff --git a/ui/src/lib/tokenEstimate.ts b/ui/src/lib/tokenEstimate.ts
new file mode 100644
index 000000000..e7d3cf8a5
--- /dev/null
+++ b/ui/src/lib/tokenEstimate.ts
@@ -0,0 +1,22 @@
+// Cheap token estimate without pulling in a 1MB tokenizer. Tuned against
+// OpenAI's cl100k_base on mixed EN/CJK content: ASCII words land near
+// 0.25 tokens/char, CJK characters compress to roughly 1.5 tokens each,
+// whitespace barely counts. Good enough for an inline counter — anything
+// that needs precise billing should round-trip through the backend
+// tokenizer.
+export function estimateTokens(text: string): number {
+ if (!text) return 0;
+ let tokens = 0;
+ for (let i = 0; i < text.length; i++) {
+ const code = text.charCodeAt(i);
+ if (code === 0x20 || code === 0x09 || code === 0x0a || code === 0x0d) {
+ tokens += 0.3;
+ } else if (code > 0x7f) {
+ // CJK + other non-ASCII; conservative 1.5x to avoid undercount.
+ tokens += 1.5;
+ } else {
+ tokens += 0.25;
+ }
+ }
+ return Math.max(1, Math.ceil(tokens));
+}