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(workbench): project + session browsing in sidebar

cyhbc98d293df41
diff --git a/ui/src/components/workbench/NewProjectDialog.tsx b/ui/src/components/workbench/NewProjectDialog.tsx
new file mode 100644
index 000000000..eb1efaa9e
--- /dev/null
+++ b/ui/src/components/workbench/NewProjectDialog.tsx
@@ -0,0 +1,157 @@
+import { useState } from 'react';
+import { useTranslation } from 'react-i18next';
+import { Folder, FolderOpen, Loader2, X } from 'lucide-react';
+
+import { useApi } from '../../context/ApiContext';
+import type { WorkbenchProject } from '../../context/ApiContext';
+import { DirectoryBrowser } from '../ui/directory-browser';
+import { Button } from '../ui/button';
+
+interface NewProjectDialogProps {
+ onClose: () => void;
+ onCreated: (project: WorkbenchProject) => void;
+}
+
+// Two-phase modal: first the macOS-style DirectoryBrowser picks a folder,
+// then a compact confirm card lets the user override the display name and
+// fire the create call. The backend defaults display_name to the folder
+// basename — keep the input empty to accept that default.
+export const NewProjectDialog: React.FC<NewProjectDialogProps> = ({ onClose, onCreated }) => {
+ const { t } = useTranslation();
+ const api = useApi();
+ const [phase, setPhase] = useState<'pick' | 'confirm'>('pick');
+ const [folderPath, setFolderPath] = useState<string>('');
+ const [displayName, setDisplayName] = useState<string>('');
+ const [submitting, setSubmitting] = useState(false);
+ const [error, setError] = useState<string | null>(null);
+
+ if (phase === 'pick') {
+ return (
+ <DirectoryBrowser
+ onClose={onClose}
+ onSelect={(path) => {
+ setFolderPath(path);
+ setPhase('confirm');
+ }}
+ />
+ );
+ }
+
+ const folderBasename = folderPath.split('/').filter(Boolean).pop() || folderPath || '—';
+
+ const submit = async () => {
+ if (!folderPath || submitting) return;
+ setSubmitting(true);
+ setError(null);
+ try {
+ const project = await api.createProject({
+ folder_path: folderPath,
+ display_name: displayName.trim() || undefined,
+ });
+ onCreated(project);
+ } catch (err: any) {
+ setError(err?.message ?? String(err));
+ setSubmitting(false);
+ }
+ };
+
+ return (
+ <div
+ className="fixed inset-0 z-50 flex items-center justify-center bg-black/50"
+ role="dialog"
+ aria-modal="true"
+ aria-label={t('workbench.newProjectDialog.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/[0.08] text-mint">
+ <Folder className="size-4" />
+ </div>
+ <div className="flex flex-1 flex-col gap-0.5">
+ <div className="text-[14px] font-bold text-foreground">{t('workbench.newProjectDialog.title')}</div>
+ <div className="text-[11.5px] leading-relaxed text-muted">
+ {t('workbench.newProjectDialog.description')}
+ </div>
+ </div>
+ <button
+ type="button"
+ onClick={onClose}
+ aria-label={t('workbench.newProjectDialog.cancel')}
+ 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('workbench.newProjectDialog.folderLabel')}
+ </label>
+ <button
+ type="button"
+ onClick={() => setPhase('pick')}
+ className="flex items-center gap-2 rounded-md border border-border-strong bg-surface-2 px-3 py-2 text-left text-[12px] font-mono text-foreground transition hover:bg-foreground/[0.04]"
+ >
+ <FolderOpen className="size-3.5 shrink-0 text-gold" />
+ <span className="flex-1 truncate">{folderPath || '—'}</span>
+ <span className="shrink-0 text-[10px] text-muted">{t('workbench.newProjectDialog.pickFolder')}</span>
+ </button>
+ </div>
+
+ <div className="flex flex-col gap-1.5">
+ <label
+ htmlFor="new-project-display-name"
+ className="font-mono text-[10px] font-bold uppercase tracking-[0.16em] text-muted"
+ >
+ {t('workbench.newProjectDialog.displayName')}
+ </label>
+ <input
+ id="new-project-display-name"
+ type="text"
+ value={displayName}
+ onChange={(e) => setDisplayName(e.target.value)}
+ placeholder={folderBasename}
+ className="rounded-md border border-border-strong bg-surface-2 px-3 py-2 text-[13px] text-foreground outline-none transition focus:border-mint placeholder:text-muted"
+ onKeyDown={(e) => {
+ if (e.key === 'Enter') submit();
+ }}
+ autoFocus
+ />
+ <div className="text-[10.5px] text-muted">{t('workbench.newProjectDialog.displayNamePlaceholder')}</div>
+ </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('workbench.newProjectDialog.cancel')}
+ </Button>
+ <Button
+ type="button"
+ variant="brand"
+ size="sm"
+ onClick={submit}
+ disabled={!folderPath || submitting}
+ >
+ {submitting ? (
+ <>
+ <Loader2 className="size-3.5 animate-spin" />
+ {t('workbench.newProjectDialog.creating')}
+ </>
+ ) : (
+ t('workbench.newProjectDialog.create')
+ )}
+ </Button>
+ </div>
+ </div>
+ </div>
+ );
+};
diff --git a/ui/src/components/workbench/WorkbenchSidebar.tsx b/ui/src/components/workbench/WorkbenchSidebar.tsx
index 7b9c9603e..a5d6a392d 100644
--- a/ui/src/components/workbench/WorkbenchSidebar.tsx
+++ b/ui/src/components/workbench/WorkbenchSidebar.tsx
@@ -1,24 +1,27 @@
-import { useEffect, useMemo, useRef, useState } from 'react';
+import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
-import { NavLink, useNavigate } from 'react-router-dom';
+import { NavLink, useLocation, useNavigate } from 'react-router-dom';
import {
Activity,
ArrowRight,
Bot,
- CheckCheck,
+ ChevronDown,
ChevronRight,
Folder,
Inbox,
KeyRound,
+ Loader2,
Plus,
WandSparkles,
} from 'lucide-react';
import clsx from 'clsx';
import type { LucideIcon } from 'lucide-react';
+import { useApi } from '../../context/ApiContext';
import { useWorkbenchInbox } from '../../context/WorkbenchInboxContext';
-import type { WorkbenchMessage } from '../../context/ApiContext';
+import type { WorkbenchMessage, WorkbenchProject, WorkbenchSession } from '../../context/ApiContext';
import { formatRelativeTime } from '../../lib/relativeTime';
+import { NewProjectDialog } from './NewProjectDialog';
interface CapabilityNavItem {
to: string;
@@ -137,14 +140,233 @@ const InboxHoverPopover: React.FC<{
);
};
+// One project row + (when expanded) the session list under it. Mirrors
+// design.pen N96dsm/C68Ul (project row) and C7clY/R2C8U (session row).
+const ProjectRow: React.FC<{
+ project: WorkbenchProject;
+ expanded: boolean;
+ sessions: WorkbenchSession[] | null;
+ loading: boolean;
+ onToggle: () => void;
+ onCreateSession: () => void;
+ creatingSession: boolean;
+ unreadByScope: Record<string, number>;
+ onSessionMarkRead: (sessionId: string) => void;
+}> = ({
+ project,
+ expanded,
+ sessions,
+ loading,
+ onToggle,
+ onCreateSession,
+ creatingSession,
+ unreadByScope,
+ onSessionMarkRead,
+}) => {
+ const { t } = useTranslation();
+ const navigate = useNavigate();
+ const location = useLocation();
+ const Chevron = expanded ? ChevronDown : ChevronRight;
+
+ return (
+ <div className="flex flex-col gap-0.5">
+ <div
+ className="group flex items-center gap-1.5 rounded-md px-2 py-1.5 transition hover:bg-foreground/[0.04]"
+ title={project.folder_path}
+ >
+ <button
+ type="button"
+ onClick={onToggle}
+ className="flex flex-1 items-center gap-1.5 text-left"
+ >
+ <Chevron className="size-3 shrink-0 text-muted" />
+ <Folder className="size-3.5 shrink-0 text-muted" />
+ <span className="flex-1 truncate text-[12px] font-medium text-foreground">
+ {project.display_name}
+ </span>
+ </button>
+ <button
+ type="button"
+ aria-label={t('workbench.addSession')}
+ onClick={onCreateSession}
+ disabled={creatingSession}
+ className={clsx(
+ 'flex size-5 shrink-0 items-center justify-center rounded-md text-muted transition',
+ 'opacity-0 group-hover:opacity-100 hover:text-foreground hover:bg-foreground/[0.06]',
+ creatingSession && 'opacity-100',
+ )}
+ >
+ {creatingSession ? <Loader2 className="size-3 animate-spin" /> : <Plus className="size-3" />}
+ </button>
+ </div>
+
+ {expanded && (
+ <div className="flex flex-col gap-0.5 pb-0.5">
+ {loading && sessions === null && (
+ <div className="px-3 py-2 pl-[30px] text-[11px] italic text-muted">{t('workbench.sessionsLoading')}</div>
+ )}
+ {sessions !== null && sessions.length === 0 && !loading && (
+ <div className="px-3 py-2 pl-[30px] text-[11px] italic text-muted">{t('workbench.sessionsEmpty')}</div>
+ )}
+ {sessions !== null &&
+ sessions.map((session) => {
+ const active = location.pathname === `/chat/${session.id}`;
+ const unread = session.scope_id ? unreadByScope[session.scope_id] || 0 : 0;
+ const displayName = session.title?.trim() || t('workbench.untitledSession');
+ return (
+ <button
+ key={session.id}
+ type="button"
+ onClick={() => {
+ navigate(`/chat/${encodeURIComponent(session.id)}`);
+ if (unread > 0) onSessionMarkRead(session.id);
+ }}
+ className={clsx(
+ 'group/sess flex items-center gap-2 rounded-md py-1.5 pl-[30px] pr-2.5 text-left transition',
+ active
+ ? 'border-l-2 border-mint bg-mint-soft pl-[28px] font-semibold text-foreground'
+ : 'hover:bg-foreground/[0.04]',
+ )}
+ >
+ <span
+ className={clsx(
+ 'size-[5px] shrink-0 rounded-full bg-mint',
+ unread > 0 && 'shadow-[0_0_6px_0_rgba(91,255,160,0.6)]',
+ )}
+ />
+ <span
+ className={clsx(
+ 'flex-1 truncate text-[12px]',
+ active ? 'font-semibold text-foreground' : 'font-medium text-foreground',
+ )}
+ >
+ {displayName}
+ </span>
+ {unread > 0 && (
+ <span className="inline-flex min-w-[1.1rem] items-center justify-center rounded-full bg-mint px-1.5 font-mono text-[9px] font-bold text-[#080812]">
+ {unread > 99 ? '99+' : unread}
+ </span>
+ )}
+ </button>
+ );
+ })}
+ </div>
+ )}
+ </div>
+ );
+};
export const WorkbenchSidebar: React.FC = () => {
const { t } = useTranslation();
+ const api = useApi();
const navigate = useNavigate();
- const { totalUnread, recentMessages, markRead } = useWorkbenchInbox();
+ const { totalUnread, recentMessages, markRead, unreadByScope } = useWorkbenchInbox();
const [popoverOpen, setPopoverOpen] = useState(false);
const closeTimer = useRef<number | null>(null);
+ // Projects state
+ const [projects, setProjects] = useState<WorkbenchProject[] | null>(null);
+ const [projectsError, setProjectsError] = useState<string | null>(null);
+ const [expanded, setExpanded] = useState<Set<string>>(new Set());
+ const [sessionsByProject, setSessionsByProject] = useState<Record<string, WorkbenchSession[]>>({});
+ const [sessionsLoading, setSessionsLoading] = useState<Record<string, boolean>>({});
+ const [creatingSession, setCreatingSession] = useState<Set<string>>(new Set());
+ const [showNewProject, setShowNewProject] = useState(false);
+
+ const fetchProjects = useCallback(async () => {
+ try {
+ const result = await api.listProjects();
+ setProjects(result.projects);
+ setProjectsError(null);
+ } catch (err: any) {
+ setProjectsError(err?.message ?? String(err));
+ }
+ }, [api]);
+
+ useEffect(() => {
+ fetchProjects();
+ }, [fetchProjects]);
+
+ const fetchSessions = useCallback(
+ async (projectId: string) => {
+ setSessionsLoading((prev) => ({ ...prev, [projectId]: true }));
+ try {
+ const result = await api.listSessions({ projectId, status: 'active', limit: 50 });
+ setSessionsByProject((prev) => ({ ...prev, [projectId]: result.sessions }));
+ } catch (err) {
+ // Surface as empty list; user can collapse + re-expand to retry.
+ setSessionsByProject((prev) => ({ ...prev, [projectId]: prev[projectId] ?? [] }));
+ } finally {
+ setSessionsLoading((prev) => ({ ...prev, [projectId]: false }));
+ }
+ },
+ [api],
+ );
+
+ const toggleExpanded = useCallback(
+ (projectId: string) => {
+ setExpanded((prev) => {
+ const next = new Set(prev);
+ if (next.has(projectId)) {
+ next.delete(projectId);
+ } else {
+ next.add(projectId);
+ if (!sessionsByProject[projectId]) {
+ fetchSessions(projectId);
+ }
+ }
+ return next;
+ });
+ },
+ [fetchSessions, sessionsByProject],
+ );
+
+ const createSessionForProject = useCallback(
+ async (projectId: string) => {
+ setCreatingSession((prev) => {
+ const next = new Set(prev);
+ next.add(projectId);
+ return next;
+ });
+ try {
+ // Default backend = 'claude' — backend resolves agent + model defaults
+ // from the project's stored settings (or the global defaults if the
+ // project never overrode them).
+ const session = await api.createSession({ project_id: projectId, agent_backend: 'claude' });
+ // Optimistically prepend so the user sees it before refetch lands.
+ setSessionsByProject((prev) => {
+ const existing = prev[projectId] ?? [];
+ return { ...prev, [projectId]: [session, ...existing] };
+ });
+ setExpanded((prev) => {
+ if (prev.has(projectId)) return prev;
+ const next = new Set(prev);
+ next.add(projectId);
+ return next;
+ });
+ navigate(`/chat/${encodeURIComponent(session.id)}`);
+ } catch (err: any) {
+ // No toast service available here without prop drilling — fall back
+ // to opening the project so the user notices nothing happened.
+ console.error('[sidebar] create session failed', err);
+ } finally {
+ setCreatingSession((prev) => {
+ const next = new Set(prev);
+ next.delete(projectId);
+ return next;
+ });
+ }
+ },
+ [api, navigate],
+ );
+
+ const onSessionMarkRead = useCallback(
+ (sessionId: string) => {
+ markRead(sessionId);
+ },
+ [markRead],
+ );
+
// Small open/close delays so the popover doesn't flicker as the cursor
// brushes through the inbox row on its way somewhere else, and survives
// the gap between the row and the popover body.
@@ -200,9 +422,7 @@ export const WorkbenchSidebar: React.FC = () => {
return (
<div className="flex flex-col gap-4">
- {/* Inbox entry — hover opens the floating popover. The wrapper element
- owns the group's hover state so moving from the row into the popover
- stays inside the open zone. */}
+ {/* Inbox entry — hover opens the floating popover. */}
<div
className="relative"
onMouseEnter={openPopover}
@@ -272,29 +492,77 @@ export const WorkbenchSidebar: React.FC = () => {
</nav>
</div>
- <div className="flex flex-col gap-2">
- {/* Empty-state card sits directly under capability nav; the
- "Projects" label was redundant once the section's only
- content is the empty state + dashed border. */}
- <div className="relative flex flex-col items-center gap-1.5 rounded-lg border border-dashed border-border px-3 py-4 text-center">
+ {/* Projects section — design.pen b8wX2.
+ Header row (matches Ee9AA) has no label — per user feedback — but
+ keeps the 22x22 bordered + button on the right. */}
+ <div className="flex flex-col gap-1.5">
+ <div className="flex items-center justify-end px-1">
<button
type="button"
aria-label={t('workbench.addProject')}
- className="absolute right-2 top-2 flex size-5 items-center justify-center rounded-md border border-border-strong text-foreground transition hover:bg-foreground/[0.04]"
- disabled
+ onClick={() => setShowNewProject(true)}
+ className="flex size-[22px] items-center justify-center rounded-md border border-border-strong text-foreground transition hover:bg-foreground/[0.04]"
>
<Plus className="size-3" />
</button>
- <Folder className="size-4 text-muted" />
- <div className="text-[11px] text-muted">{t('workbench.projectsEmpty')}</div>
+ </div>
+
+ <div className="flex flex-col gap-0.5">
+ {projects === null && !projectsError && (
+ <div className="flex items-center gap-2 rounded-md border border-dashed border-border px-3 py-3 text-[11px] text-muted">
+ <Loader2 className="size-3 animate-spin" />
+ {t('workbench.projectsLoading')}
+ </div>
+ )}
+ {projectsError && (
+ <div className="rounded-md border border-destructive/40 bg-destructive/[0.06] px-3 py-2 text-[11px] text-destructive">
+ {t('workbench.projectsLoadError')}
+ </div>
+ )}
+ {projects !== null && projects.length === 0 && (
+ <div className="flex flex-col items-center gap-1.5 rounded-md border border-dashed border-border px-3 py-4 text-center">
+ <Folder className="size-4 text-muted" />
+ <div className="text-[11px] text-muted">{t('workbench.projectsEmpty')}</div>
+ </div>
+ )}
+ {projects !== null &&
+ projects.map((project) => (
+ <ProjectRow
+ key={project.id}
+ project={project}
+ expanded={expanded.has(project.id)}
+ sessions={sessionsByProject[project.id] ?? null}
+ loading={!!sessionsLoading[project.id]}
+ onToggle={() => toggleExpanded(project.id)}
+ onCreateSession={() => createSessionForProject(project.id)}
+ creatingSession={creatingSession.has(project.id)}
+ unreadByScope={unreadByScope}
+ onSessionMarkRead={onSessionMarkRead}
+ />
+ ))}
</div>
</div>
+
+ {showNewProject && (
+ <NewProjectDialog
+ onClose={() => setShowNewProject(false)}
+ onCreated={(project) => {
+ setShowNewProject(false);
+ setProjects((prev) => (prev ? [project, ...prev] : [project]));
+ setExpanded((prev) => {
+ const next = new Set(prev);
+ next.add(project.id);
+ return next;
+ });
+ // Pre-seed empty sessions list so the expand shows the empty state
+ // immediately instead of a flash of "Loading…"
+ setSessionsByProject((prev) => ({ ...prev, [project.id]: [] }));
+ }}
+ />
+ )}
</div>
);
};
// Re-export for tests / future inbox-specific UIs.
export { InboxHoverPopover };
-// Silence the import that exists only for the un-used CheckCheck icon —
-// it'll be wired into the full Inbox view in commit 09 too.
-void CheckCheck;
diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.json
index 0d0f3bea4..535b18fe0 100644
--- a/ui/src/i18n/en.json
+++ b/ui/src/i18n/en.json
@@ -408,7 +408,25 @@
"capabilitiesLabel": "Capabilities",
"projectsLabel": "Projects",
"addProject": "Add project",
- "projectsEmpty": "No projects yet — coming next commit.",
+ "addSession": "New session in this project",
+ "projectActions": "Project actions",
+ "projectsEmpty": "No projects yet — add one to start a session.",
+ "projectsLoading": "Loading projects…",
+ "projectsLoadError": "Couldn't load projects.",
+ "sessionsLoading": "Loading sessions…",
+ "sessionsEmpty": "No sessions in this project.",
+ "untitledSession": "Untitled session",
+ "newProjectDialog": {
+ "title": "New project",
+ "description": "Pick a working directory. An avibe project gives every session in it a shared cwd and inbox.",
+ "pickFolder": "Choose folder",
+ "displayName": "Display name",
+ "displayNamePlaceholder": "Auto from folder name",
+ "folderLabel": "Folder",
+ "create": "Create project",
+ "creating": "Creating…",
+ "cancel": "Cancel"
+ },
"nav": {
"inbox": "Inbox",
"agents": "Agents",
diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.json
index f95f46442..9ea3fe389 100644
--- a/ui/src/i18n/zh.json
+++ b/ui/src/i18n/zh.json
@@ -408,7 +408,25 @@
"capabilitiesLabel": "能力模块",
"projectsLabel": "项目",
"addProject": "添加项目",
- "projectsEmpty": "还没有项目 — 下一个 commit 接上。",
+ "addSession": "在该项目新建会话",
+ "projectActions": "项目操作",
+ "projectsEmpty": "还没有项目 — 添加一个就能开始会话。",
+ "projectsLoading": "加载项目中…",
+ "projectsLoadError": "项目加载失败。",
+ "sessionsLoading": "加载会话中…",
+ "sessionsEmpty": "项目里还没有会话。",
+ "untitledSession": "未命名会话",
+ "newProjectDialog": {
+ "title": "新建项目",
+ "description": "选一个工作目录。avibe 项目里的每个会话共用同一个 cwd 和收件箱。",
+ "pickFolder": "选择文件夹",
+ "displayName": "显示名",
+ "displayNamePlaceholder": "默认使用文件夹名",
+ "folderLabel": "目录",
+ "create": "创建项目",
+ "creating": "创建中…",
+ "cancel": "取消"
+ },
"nav": {
"inbox": "收件箱",
"agents": "Agents",