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(ui): agents config — system description lock, model-aware effort, create-dialog parity, import empty-state (#376)

Call White79d18effcfd8
diff --git a/ui/src/components/workbench/AgentsPage.tsx b/ui/src/components/workbench/AgentsPage.tsx
index 354d76ed4..3ac871a7e 100644
--- a/ui/src/components/workbench/AgentsPage.tsx
+++ b/ui/src/components/workbench/AgentsPage.tsx
@@ -33,6 +33,7 @@ import { EditorDialog } from '../ui/editor-dialog';
import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover';
import { estimateTokens } from '../../lib/tokenEstimate';
import { fetchBackendModels } from '../../lib/backendModels';
+import { resolveEffortOptions } from '../../lib/effortOptions';
import { WorkbenchPageHeader } from './WorkbenchPageHeader';
// Backend order / labels / accent classes live in lib/backendAccent, shared
// with the Skills surface (BACKEND_TEXT is this page's old BACKEND_ICON_CLASS).
@@ -43,7 +44,6 @@ import {
type Backend,
} from '../../lib/backendAccent';
-const EFFORT_OPTIONS = ['low', 'medium', 'high', 'max'];
// Sentinel option that clears the model override back to the backend default
// (a combobox can't submit an empty value, so this is the explicit clear path).
const MODEL_DEFAULT_OPTION = '__default__';
@@ -198,7 +198,13 @@ export const AgentsPage: React.FC = () => {
// the toast reported 0 even on a successful import.
const imported = result.imported?.length ?? 0;
const skipped = result.skipped?.length ?? 0;
- showToast(t('agents.importSuccess', { imported, skipped }), 'success');
+ if (imported === 0 && skipped === 0) {
+ // Nothing on disk for this backend — say where we looked instead of a
+ // confusing "imported 0" success toast.
+ showToast(t('agents.importNoneFound', { backend: BACKEND_LABEL[from] }), 'warning');
+ } else {
+ showToast(t('agents.importSuccess', { imported, skipped }), 'success');
+ }
refresh();
} else {
showToast(
@@ -494,6 +500,7 @@ const AgentDetailPanel: React.FC<DetailProps> = ({ agent, isDefault, onChange, o
const [systemPromptOpen, setSystemPromptOpen] = useState(false);
const [editorOpen, setEditorOpen] = useState(false);
const [modelOptions, setModelOptions] = useState<ComboboxOption[]>([]);
+ const [reasoningOptions, setReasoningOptions] = useState<Record<string, { value: string; label: string }[]>>({});
const [running, setRunning] = useState(false);
useEffect(() => {
@@ -513,8 +520,11 @@ const AgentDetailPanel: React.FC<DetailProps> = ({ agent, isDefault, onChange, o
let cancelled = false;
async function loadModels() {
try {
- const { models } = await fetchBackendModels(api, agent.backend);
- if (!cancelled) setModelOptions(models.map((m) => ({ value: m, label: m })));
+ const { models, reasoningOptions: opts } = await fetchBackendModels(api, agent.backend);
+ if (!cancelled) {
+ setModelOptions(models.map((m) => ({ value: m, label: m })));
+ setReasoningOptions(opts ?? {});
+ }
} catch {
if (!cancelled) setModelOptions([]);
}
@@ -526,6 +536,9 @@ const AgentDetailPanel: React.FC<DetailProps> = ({ agent, isDefault, onChange, o
}, [agent.backend, api]);
const systemPromptTokens = estimateTokens(systemPrompt);
+ // Effort options follow the backend + selected model — Claude is per-model via
+ // the catalog's reasoning_options; Codex/OpenCode use the backend superset.
+ const effortOptions = resolveEffortOptions(agent.backend, model, reasoningOptions);
// 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
@@ -692,20 +705,22 @@ const AgentDetailPanel: React.FC<DetailProps> = ({ agent, isDefault, onChange, o
</Field>
{/* Description — free-text summary of what the agent is for. Feeds the
- list-row subtitle (model · effort · description). Editable for every
- agent, system ones included: it's metadata, not an identity field. */}
+ list-row subtitle (model · effort · description). Locked for system
+ agents (same as the name); editable for user agents. */}
<Field label={t('agents.detail.description')}>
<Textarea
value={description}
onChange={(e) => setDescription(e.target.value)}
onBlur={() => {
- if (description !== (agent.description ?? '')) {
+ if (!system && description !== (agent.description ?? '')) {
onChange({ description: description.trim() || null });
}
}}
+ disabled={system}
+ title={system ? t('agents.detail.systemLocked') : undefined}
rows={2}
placeholder={t('agents.detail.descriptionPlaceholder')}
- className="text-[13px]"
+ className="text-[13px] disabled:cursor-not-allowed disabled:opacity-70"
/>
</Field>
@@ -735,7 +750,19 @@ const AgentDetailPanel: React.FC<DetailProps> = ({ agent, isDefault, onChange, o
onValueChange={(next) => {
const value = next === MODEL_DEFAULT_OPTION ? '' : next;
setModel(value);
- onChange({ model: value.trim() || null });
+ const patch: Partial<VibeAgentFull> = { model: value.trim() || null };
+ // If the new model can't use the current effort, fall back to a
+ // valid one and persist it in the same patch — otherwise the record
+ // keeps an effort the model can't run (Codex P2).
+ const opts = resolveEffortOptions(agent.backend, value, reasoningOptions);
+ if (effort && !opts.includes(effort)) {
+ const fallback = opts.includes('medium') ? 'medium' : opts[0];
+ if (fallback) {
+ setEffort(fallback);
+ patch.reasoning_effort = fallback;
+ }
+ }
+ onChange(patch);
}}
placeholder={t('agents.detail.modelPlaceholder')}
emptyText={t('agents.detail.modelEmpty')}
@@ -745,8 +772,11 @@ const AgentDetailPanel: React.FC<DetailProps> = ({ agent, isDefault, onChange, o
{/* 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) => {
+ <div
+ className="grid gap-0.5 rounded-lg border border-border-strong bg-surface-2 p-0.5"
+ style={{ gridTemplateColumns: `repeat(${effortOptions.length}, minmax(0, 1fr))` }}
+ >
+ {effortOptions.map((opt) => {
const active = effort === opt;
return (
<button
@@ -757,7 +787,7 @@ const AgentDetailPanel: React.FC<DetailProps> = ({ agent, isDefault, onChange, o
onChange({ reasoning_effort: opt });
}}
className={clsx(
- 'rounded-md py-1.5 text-[11px] capitalize transition',
+ 'truncate rounded-md px-1 py-1.5 text-[11px] capitalize transition',
active ? 'bg-mint-soft font-bold text-mint' : 'font-medium text-muted hover:text-foreground',
)}
>
diff --git a/ui/src/components/workbench/ChatPage.tsx b/ui/src/components/workbench/ChatPage.tsx
index c95466a14..2ba0ed246 100644
--- a/ui/src/components/workbench/ChatPage.tsx
+++ b/ui/src/components/workbench/ChatPage.tsx
@@ -10,24 +10,12 @@ import type { VibeAgentBrief, WorkbenchMessage, WorkbenchSession } from '../../c
import { apiFetch } from '../../lib/apiFetch';
import { formatLocalDateTime } from '../../lib/relativeTime';
import { fetchBackendModels } from '../../lib/backendModels';
+import { resolveEffortOptions } from '../../lib/effortOptions';
import { Button } from '../ui/button';
import { Input } from '../ui/input';
import { Markdown } from '../ui/markdown';
import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover';
-// Reasoning-effort options are backend-specific (mirrors the backend's own
-// lists in modules/agents/opencode/utils.py): Codex is minimal..xhigh, Claude is
-// low/medium/high. Offering a global low/medium/high/max let a Codex session
-// pick an invalid 'max' and hid valid 'minimal'/'xhigh' (Codex P2). OpenCode's
-// is model-dependent; use the broad superset as a reasonable default.
-const EFFORT_BY_BACKEND: Record<string, string[]> = {
- claude: ['low', 'medium', 'high'],
- codex: ['minimal', 'low', 'medium', 'high', 'xhigh'],
- opencode: ['minimal', 'low', 'medium', 'high', 'xhigh', 'max'],
-};
-const DEFAULT_EFFORTS = ['low', 'medium', 'high'];
-const effortOptionsFor = (backend: string): string[] => EFFORT_BY_BACKEND[backend] ?? DEFAULT_EFFORTS;
-
// Last-resort failsafe for a LOST ``turn.end`` event. The controller is the
// authority on turn end (``turn.start`` / ``turn.end`` over the bus) and its own
// dispatch safety timeout is 600s, so a real turn always ends by then. This is
@@ -994,14 +982,10 @@ const AgentRoutePicker: React.FC<AgentRoutePickerProps> = ({ session, agents, on
// static list (before /api/claude/models has resolved). The '__default__'
// sentinel is dropped — effort is cleared by switching agents, not via a
// pseudo-option. Other backends keep their static superset (Codex P2).
- const effortOptions = useMemo(() => {
- if (backend === 'claude') {
- const perModel = claudeReasoning[currentModel ?? ''] ?? claudeReasoning[''];
- const values = perModel?.filter((o) => o.value !== '__default__').map((o) => o.value);
- if (values && values.length) return values;
- }
- return effortOptionsFor(backend);
- }, [backend, currentModel, claudeReasoning]);
+ const effortOptions = useMemo(
+ () => resolveEffortOptions(backend, currentModel, claudeReasoning),
+ [backend, currentModel, claudeReasoning],
+ );
return (
<Popover open={open} onOpenChange={setOpen}>
diff --git a/ui/src/components/workbench/NewAgentDialog.tsx b/ui/src/components/workbench/NewAgentDialog.tsx
index 03648d6c2..8173c818b 100644
--- a/ui/src/components/workbench/NewAgentDialog.tsx
+++ b/ui/src/components/workbench/NewAgentDialog.tsx
@@ -1,15 +1,19 @@
import { useEffect, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
-import { ArrowRight, Bot, X } from 'lucide-react';
+import { ArrowRight, Bot, Maximize2, X } from 'lucide-react';
import clsx from 'clsx';
import { useApi } from '../../context/ApiContext';
import type { VibeAgentFull } from '../../context/ApiContext';
import { fetchBackendModels } from '../../lib/backendModels';
+import { resolveEffortOptions } from '../../lib/effortOptions';
+import { estimateTokens } from '../../lib/tokenEstimate';
import { Combobox } from '../ui/combobox';
import type { ComboboxOption } from '../ui/combobox';
import { Input } from '../ui/input';
import { Textarea } from '../ui/textarea';
+import { EditorDialog } from '../ui/editor-dialog';
+import { Button } from '../ui/button';
type BackendKey = 'claude' | 'opencode' | 'codex';
@@ -29,8 +33,6 @@ const BACKEND_OPTIONS: BackendOption[] = [
{ key: 'codex', label: 'Codex', publisher: 'OpenAI', color: 'violet' },
];
-const EFFORT_OPTIONS = ['low', 'medium', 'high', 'max'];
-
interface NewAgentDialogProps {
/** When false the modal renders nothing — controlled by the parent. */
open: boolean;
@@ -53,6 +55,8 @@ export const NewAgentDialog: React.FC<NewAgentDialogProps> = ({ open, onClose, o
const [submitting, setSubmitting] = useState(false);
const [error, setError] = useState<string | null>(null);
const [modelOptions, setModelOptions] = useState<ComboboxOption[]>([]);
+ const [reasoningOptions, setReasoningOptions] = useState<Record<string, { value: string; label: string }[]>>({});
+ const [editorOpen, setEditorOpen] = useState(false);
useEffect(() => {
if (!open) {
@@ -64,6 +68,7 @@ export const NewAgentDialog: React.FC<NewAgentDialogProps> = ({ open, onClose, o
setBackend('claude');
setError(null);
setSubmitting(false);
+ setEditorOpen(false);
}
}, [open]);
@@ -75,9 +80,10 @@ export const NewAgentDialog: React.FC<NewAgentDialogProps> = ({ open, onClose, o
let cancelled = false;
async function loadModels() {
try {
- const { models } = await fetchBackendModels(api, backend);
+ const { models, reasoningOptions: opts } = await fetchBackendModels(api, backend);
if (!cancelled) {
setModelOptions(models.map((m) => ({ value: m, label: m })));
+ setReasoningOptions(opts ?? {});
// 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('');
@@ -94,15 +100,31 @@ export const NewAgentDialog: React.FC<NewAgentDialogProps> = ({ open, onClose, o
}, [backend, open, api]);
const modelComboboxOptions = useMemo(() => modelOptions, [modelOptions]);
+ const effortOptions = useMemo(
+ () => resolveEffortOptions(backend, model, reasoningOptions),
+ [backend, model, reasoningOptions],
+ );
+ const systemPromptTokens = estimateTokens(systemPrompt);
+
+ // Keep the chosen effort valid as backend/model (and thus the option list)
+ // change, so handleSubmit never sends an effort the backend would reject
+ // (e.g. picking Codex `xhigh` then switching to Claude).
+ useEffect(() => {
+ if (effort && !effortOptions.includes(effort)) {
+ setEffort(effortOptions.includes('medium') ? 'medium' : effortOptions[0] ?? 'medium');
+ }
+ }, [effortOptions, effort]);
useEffect(() => {
if (!open) return;
const onKey = (e: KeyboardEvent) => {
- if (e.key === 'Escape') onClose();
+ // Don't let Esc close the whole create dialog when the expand editor is
+ // open on top — that Esc belongs to the editor.
+ if (e.key === 'Escape' && !editorOpen) onClose();
};
window.addEventListener('keydown', onKey);
return () => window.removeEventListener('keydown', onKey);
- }, [open, onClose]);
+ }, [open, onClose, editorOpen]);
if (!open) return null;
@@ -140,6 +162,7 @@ export const NewAgentDialog: React.FC<NewAgentDialogProps> = ({ open, onClose, o
};
return (
+ <>
<div
className="fixed inset-0 z-50 flex items-center justify-center bg-black/60"
role="dialog"
@@ -205,7 +228,7 @@ export const NewAgentDialog: React.FC<NewAgentDialogProps> = ({ open, onClose, o
onKeyDown={(e) => {
if (e.key === 'Enter' && canSubmit) handleSubmit();
}}
- placeholder="reviewer"
+ placeholder={t('agents.create.namePlaceholder')}
className="font-mono text-[13px]"
/>
</div>
@@ -244,16 +267,19 @@ export const NewAgentDialog: React.FC<NewAgentDialogProps> = ({ open, onClose, o
</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')}
+ {t('agents.detail.effort')}
</div>
- <div className="grid h-[38px] grid-cols-4 rounded-md border border-border-strong bg-surface-2 p-0.5">
- {EFFORT_OPTIONS.map((opt) => (
+ <div
+ className="grid h-[38px] gap-0.5 rounded-md border border-border-strong bg-surface-2 p-0.5"
+ style={{ gridTemplateColumns: `repeat(${effortOptions.length}, minmax(0, 1fr))` }}
+ >
+ {effortOptions.map((opt) => (
<button
key={opt}
type="button"
onClick={() => setEffort(opt)}
className={clsx(
- 'rounded text-[11px] capitalize transition',
+ 'truncate rounded px-0.5 text-[11px] capitalize transition',
effort === opt ? 'bg-mint-soft font-bold text-mint' : 'font-medium text-muted hover:text-foreground',
)}
>
@@ -264,13 +290,29 @@ export const NewAgentDialog: React.FC<NewAgentDialogProps> = ({ open, onClose, o
</div>
</div>
- {/* System prompt */}
+ {/* System prompt — with token estimate + expand-to-editor, mirroring
+ the Agents detail panel (shared EditorDialog). */}
<div className="flex flex-col gap-1.5">
- <div className="flex items-center justify-between">
+ <div className="flex items-center justify-between gap-2">
<div className="font-mono text-[10px] font-bold uppercase tracking-[0.12em] text-muted">
{t('agents.create.systemPrompt')}
</div>
- <span className="text-[10px] text-muted">{t('agents.create.systemPromptHint')}</span>
+ <div className="flex items-center gap-1.5">
+ <span className="font-mono text-[10px] text-muted">
+ {t('agents.detail.systemPromptCount', { count: systemPromptTokens })}
+ </span>
+ <Button
+ type="button"
+ variant="ghost"
+ size="icon"
+ className="size-6 shrink-0 text-muted hover:text-foreground"
+ onClick={() => setEditorOpen(true)}
+ aria-label={t('agents.detail.systemPromptExpand')}
+ title={t('agents.detail.systemPromptExpand')}
+ >
+ <Maximize2 className="size-3.5" />
+ </Button>
+ </div>
</div>
<Textarea
value={systemPrompt}
@@ -312,5 +354,19 @@ export const NewAgentDialog: React.FC<NewAgentDialogProps> = ({ open, onClose, o
</div>
</div>
</div>
+ {/* Rendered outside the create-dialog wrapper so its portal clicks
+ (textarea, preview toggle, Save) don't bubble to the wrapper's
+ onClick=onClose and discard the in-progress form. */}
+ <EditorDialog
+ open={editorOpen}
+ onClose={() => setEditorOpen(false)}
+ title={t('agents.detail.systemPrompt')}
+ description={t('agents.detail.systemPromptEditorHint')}
+ value={systemPrompt}
+ placeholder={t('agents.create.systemPromptPlaceholder')}
+ footerHint={(draft) => t('agents.detail.systemPromptCount', { count: estimateTokens(draft) })}
+ onSave={(next) => setSystemPrompt(next)}
+ />
+ </>
);
};
diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.json
index 612765cfb..651adc0c7 100644
--- a/ui/src/i18n/en.json
+++ b/ui/src/i18n/en.json
@@ -1283,6 +1283,7 @@
"importFromOpenCode": "Import from OpenCode",
"importSuccess": "Imported {{imported}}, skipped {{skipped}}.",
"importFailed": "Import failed: {{error}}",
+ "importNoneFound": "No {{backend}} agents found on disk to import.",
"renameSuccess": "Agent renamed",
"renameKeptOld": "Agent renamed (old one kept due to references)",
"searchPlaceholder": "Search agents…",
@@ -1336,6 +1337,7 @@
"body": "Pick a backend, name the agent, and fine-tune model and effort. Backend cannot be changed after creation.",
"backend": "Backend",
"name": "Name",
+ "namePlaceholder": "Agent name (e.g. reviewer)",
"description": "Description",
"descriptionPlaceholder": "What this agent is for…",
"model": "Model",
diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.json
index c510bfe6c..d2c0d2243 100644
--- a/ui/src/i18n/zh.json
+++ b/ui/src/i18n/zh.json
@@ -1283,6 +1283,7 @@
"importFromOpenCode": "从 OpenCode 导入",
"importSuccess": "已导入 {{imported}} 个,跳过 {{skipped}} 个。",
"importFailed": "导入失败:{{error}}",
+ "importNoneFound": "磁盘上没有找到可导入的 {{backend}} Agent。",
"renameSuccess": "Agent 已重命名",
"renameKeptOld": "Agent 已重命名(旧名因被引用而保留)",
"searchPlaceholder": "搜索 Agent…",
@@ -1335,6 +1336,7 @@
"body": "选择后端,命名 Agent,微调模型与 Effort。后端在创建后不可更改。",
"backend": "后端",
"name": "名称",
+ "namePlaceholder": "Agent 名称(例如 reviewer)",
"description": "描述",
"descriptionPlaceholder": "这个 Agent 用来做什么…",
"model": "模型",
diff --git a/ui/src/lib/effortOptions.ts b/ui/src/lib/effortOptions.ts
new file mode 100644
index 000000000..4147b0fc0
--- /dev/null
+++ b/ui/src/lib/effortOptions.ts
@@ -0,0 +1,42 @@
+// Single source of truth for reasoning-effort options, shared by ChatPage, the
+// Agents detail panel, and the New Agent dialog. Mirrors the backend lists in
+// modules/agents/opencode/utils.py: Codex is minimal..xhigh, Claude is
+// low/medium/high (+ xhigh/max on models that support it), OpenCode uses the
+// broad superset.
+export const EFFORT_BY_BACKEND: Record<string, string[]> = {
+ claude: ['low', 'medium', 'high'],
+ codex: ['minimal', 'low', 'medium', 'high', 'xhigh'],
+ opencode: ['minimal', 'low', 'medium', 'high', 'xhigh', 'max'],
+};
+
+const DEFAULT_EFFORTS = ['low', 'medium', 'high'];
+
+export const effortOptionsFor = (backend: string): string[] => EFFORT_BY_BACKEND[backend] ?? DEFAULT_EFFORTS;
+
+// Backends whose model catalog actually ships per-model reasoning options.
+// Today only Claude — Codex/OpenCode return a flat list, so a stale options map
+// left over from a previous backend (e.g. ChatPage's claudeReasoning cache,
+// which isn't cleared on backend switch) must NOT leak into their effort set.
+const PER_MODEL_EFFORT_BACKENDS = new Set(['claude']);
+
+// Resolve the selectable effort values for a backend + model. Only backends that
+// publish per-model reasoning options (Claude) consult ``reasoningOptions``; the
+// rest always use their backend superset, so a stale map can't leak. A known
+// model uses its own set (Opus exposes xhigh/max, Haiku doesn't); an inherited
+// (empty) or unknown/custom model uses the catalog's "" default set. We do NOT
+// union across all models: the backend re-derives the effective model and runs
+// normalize_claude_reasoning_effort, so a broader UI list would just surface
+// efforts the backend silently drops (a false affordance). ``reasoningOptions``
+// may be {} before the catalog loads — that yields the backend fallback.
+export function resolveEffortOptions(
+ backend: string,
+ model: string | null | undefined,
+ reasoningOptions: Record<string, { value: string; label: string }[]> | undefined,
+): string[] {
+ if (PER_MODEL_EFFORT_BACKENDS.has(backend) && reasoningOptions) {
+ const perModel = reasoningOptions[model ?? ''] ?? reasoningOptions[''];
+ const values = perModel?.filter((o) => o.value !== '__default__').map((o) => o.value);
+ if (values && values.length) return values;
+ }
+ return effortOptionsFor(backend);
+}