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.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
feat(workbench): per-session unread counts in the sidebar
cyhe68c4c57fa0a
diff --git a/storage/messages_service.py b/storage/messages_service.pyindex fec4d7485..dc622c38c 100644--- a/storage/messages_service.py+++ b/storage/messages_service.py@@ -208,6 +208,31 @@ def unread_counts(return {scope: int(count) for scope, count in conn.execute(query).all()}+def unread_counts_by_session(+ conn: Connection,+ *,+ platform: Optional[str] = None,+) -> dict[str, int]:+ """Return ``{session_id: count}`` for unread agent messages.++ Per-session granularity for the sidebar: a project can hold several+ sessions, so a scope-level count (see ``unread_counts``) would stamp the+ same badge on every session row. Rows with a null ``session_id`` are+ skipped — they can't be attributed to a specific session.+ """++ query = (+ select(messages.c.session_id, func.count(messages.c.id))+ .where(messages.c.author == "agent")+ .where(messages.c.read_at.is_(None))+ .where(messages.c.session_id.is_not(None))+ .group_by(messages.c.session_id)+ )+ if platform is not None:+ query = query.where(messages.c.platform == platform)+ return {session_id: int(count) for session_id, count in conn.execute(query).all()}++def mark_session_read(conn: Connection,session_id: str,diff --git a/tests/test_messages_service.py b/tests/test_messages_service.pyindex ea0558d4b..23d0f8a70 100644--- a/tests/test_messages_service.py+++ b/tests/test_messages_service.py@@ -186,3 +186,32 @@ def test_list_inbox_cursor_uses_clamped_limit(isolated_state):page = messages_service.list_inbox(conn, platform="avibe", limit=1000)assert len(page["messages"]) == 200assert page["next_before_id"] is not None+++def test_unread_counts_by_session_splits_within_a_scope(isolated_state):+ """Two sessions in one project must report distinct per-session unread+ counts, even though the scope-level aggregate lumps them together."""+ engine = create_sqlite_engine()+ with engine.begin() as conn:+ scope_id = _seed_scope(conn)+ _seed_session(conn, scope_id, "ses_a")+ _seed_session(conn, scope_id, "ses_b")+ for _ in range(2):+ messages_service.append(+ conn, scope_id=scope_id, session_id="ses_a", platform="avibe", author="agent", text="a"+ )+ messages_service.append(+ conn, scope_id=scope_id, session_id="ses_b", platform="avibe", author="agent", text="b"+ )+ # A user message and a read agent message must not count.+ messages_service.append(+ conn, scope_id=scope_id, session_id="ses_b", platform="avibe", author="user", text="hi"+ )++ with engine.connect() as conn:+ by_session = messages_service.unread_counts_by_session(conn, platform="avibe")+ by_scope = messages_service.unread_counts(conn, platform="avibe")++ assert by_session == {"ses_a": 2, "ses_b": 1}+ # Scope aggregate still lumps both sessions together.+ assert by_scope == {scope_id: 3}diff --git a/ui/src/components/workbench/WorkbenchSidebar.tsx b/ui/src/components/workbench/WorkbenchSidebar.tsxindex 5b9a15c24..b2a69d92a 100644--- a/ui/src/components/workbench/WorkbenchSidebar.tsx+++ b/ui/src/components/workbench/WorkbenchSidebar.tsx@@ -154,7 +154,7 @@ const ProjectRow: React.FC<{onToggle: () => void;onCreateSession: () => void;creatingSession: boolean;- unreadByScope: Record<string, number>;+ unreadBySession: Record<string, number>;onSessionMarkRead: (sessionId: string) => void;onRename: (next: string) => Promise<void>;onArchive: () => Promise<void>;@@ -166,7 +166,7 @@ const ProjectRow: React.FC<{onToggle,onCreateSession,creatingSession,- unreadByScope,+ unreadBySession,onSessionMarkRead,onRename,onArchive,@@ -306,7 +306,7 @@ const ProjectRow: React.FC<{{sessions !== null &&sessions.map((session) => {const active = location.pathname === `/chat/${session.id}`;- const unread = session.scope_id ? unreadByScope[session.scope_id] || 0 : 0;+ const unread = unreadBySession[session.id] || 0;const displayName = session.title?.trim() || t('workbench.untitledSession');return (<button@@ -355,7 +355,7 @@ export const WorkbenchSidebar: React.FC = () => {const { t } = useTranslation();const api = useApi();const navigate = useNavigate();- const { totalUnread, recentMessages, markRead, unreadByScope } = useWorkbenchInbox();+ const { totalUnread, recentMessages, markRead, unreadBySession } = useWorkbenchInbox();const [popoverOpen, setPopoverOpen] = useState(false);const closeTimer = useRef<number | null>(null);@@ -678,7 +678,7 @@ export const WorkbenchSidebar: React.FC = () => {onToggle={() => toggleExpanded(project.id)}onCreateSession={() => createSessionForProject(project.id)}creatingSession={creatingSession.has(project.id)}- unreadByScope={unreadByScope}+ unreadBySession={unreadBySession}onSessionMarkRead={onSessionMarkRead}onRename={(next) => renameProject(project.id, next)}onArchive={() => archiveProject(project.id)}diff --git a/ui/src/context/ApiContext.tsx b/ui/src/context/ApiContext.tsxindex 787211df5..32b0779ce 100644--- a/ui/src/context/ApiContext.tsx+++ b/ui/src/context/ApiContext.tsx@@ -103,9 +103,9 @@ export type ApiContextType = {archiveSession: (sessionId: string) => Promise<WorkbenchSession>;listSessionMessages: (sessionId: string, params?: { afterId?: string; limit?: number }) => Promise<{ messages: WorkbenchMessage[]; next_after_id: string | null }>;sendSessionMessage: (sessionId: string, payload: { text?: string; content?: Record<string, unknown>; metadata?: Record<string, unknown>; author_id?: string; author_name?: string }) => Promise<WorkbenchMessage>;- markSessionRead: (sessionId: string, untilMessageId?: string) => Promise<{ updated: number; unread_counts: Record<string, number> }>;+ markSessionRead: (sessionId: string, untilMessageId?: string) => Promise<{ updated: number; unread_counts: Record<string, number>; unread_by_session: Record<string, number> }>;cancelSession: (sessionId: string) => Promise<{ ok: boolean; status?: string; code?: string; detail?: string }>;- listInbox: (params?: { platform?: string; unreadOnly?: boolean; limit?: number; beforeId?: string }) => Promise<{ messages: WorkbenchMessage[]; next_before_id: string | null; unread_counts: Record<string, number> }>;+ listInbox: (params?: { platform?: string; unreadOnly?: boolean; limit?: number; beforeId?: string }) => Promise<{ messages: WorkbenchMessage[]; next_before_id: string | null; unread_counts: Record<string, number>; unread_by_session: Record<string, number> }>;connectWorkbenchEvents: (handlers: WorkbenchEventHandlers) => () => void;listVibeAgents: (params?: { backend?: string; includeDisabled?: boolean }) => Promise<{ ok: boolean; agents: VibeAgentBrief[]; default_agent_name: string | null }>;getVibeAgent: (name: string) => Promise<{ ok: boolean; agent: VibeAgentFull; default_agent_name: string | null }>;@@ -250,6 +250,7 @@ export type WorkbenchEventHandlers = {scope_id?: string | null;delta?: number;unread_counts: Record<string, number>;+ unread_by_session?: Record<string, number>;}) => void;onAny?: (event: WorkbenchEventEnvelope) => void;onError?: (err: Event) => void;diff --git a/ui/src/context/WorkbenchInboxContext.tsx b/ui/src/context/WorkbenchInboxContext.tsxindex add1dab7f..9eb1db6a5 100644--- a/ui/src/context/WorkbenchInboxContext.tsx+++ b/ui/src/context/WorkbenchInboxContext.tsx@@ -5,8 +5,11 @@ import { useApi } from './ApiContext';import type { WorkbenchMessage } from './ApiContext';interface InboxState {- /** Per-scope unread counts (only agent-authored messages count). */+ /** Per-scope (project) unread counts (only agent-authored messages count). */unreadByScope: Record<string, number>;+ /** Per-session unread counts — a project can hold several sessions, so the+ * sidebar badges each session row from this rather than the scope total. */+ unreadBySession: Record<string, number>;/** Sum of ``unreadByScope`` — cached so consumers don't re-derive. */totalUnread: number;/** Recent agent messages across all sessions (reverse-chronological). */@@ -28,6 +31,7 @@ const WorkbenchInboxContext = createContext<InboxState | undefined>(undefined);export const WorkbenchInboxProvider = ({ children }: { children: ReactNode }) => {const api = useApi();const [unreadByScope, setUnreadByScope] = useState<Record<string, number>>({});+ const [unreadBySession, setUnreadBySession] = useState<Record<string, number>>({});const [recentMessages, setRecentMessages] = useState<WorkbenchMessage[]>([]);const [loading, setLoading] = useState(false);// Avoid duplicate refresh-on-first-mount during StrictMode double-invoke.@@ -39,6 +43,7 @@ export const WorkbenchInboxProvider = ({ children }: { children: ReactNode }) =>const result = await api.listInbox({ platform: 'avibe', limit: 30 });setRecentMessages(result.messages);setUnreadByScope(result.unread_counts);+ setUnreadBySession(result.unread_by_session ?? {});} catch (err) {console.error('[inbox] refresh failed', err);} finally {@@ -50,6 +55,7 @@ export const WorkbenchInboxProvider = ({ children }: { children: ReactNode }) =>async (sessionId: string, untilMessageId?: string) => {const result = await api.markSessionRead(sessionId, untilMessageId);setUnreadByScope(result.unread_counts);+ setUnreadBySession(result.unread_by_session ?? {});},[api],);@@ -76,11 +82,20 @@ export const WorkbenchInboxProvider = ({ children }: { children: ReactNode }) =>[message.scope_id as string]: (prev[message.scope_id as string] ?? 0) + 1,}));}+ if (!message.read_at && message.session_id) {+ setUnreadBySession((prev) => ({+ ...prev,+ [message.session_id as string]: (prev[message.session_id as string] ?? 0) + 1,+ }));+ }},onInboxUnreadChanged: (data) => {if (data?.unread_counts) {setUnreadByScope(data.unread_counts);}+ if (data?.unread_by_session) {+ setUnreadBySession(data.unread_by_session);+ }},onError: (err) => {// Browser EventSource will auto-reconnect; keep this as a log@@ -100,13 +115,14 @@ export const WorkbenchInboxProvider = ({ children }: { children: ReactNode }) =>const value = useMemo<InboxState>(() => ({unreadByScope,+ unreadBySession,totalUnread,recentMessages,loading,refresh,markRead,}),- [unreadByScope, totalUnread, recentMessages, loading, refresh, markRead],+ [unreadByScope, unreadBySession, totalUnread, recentMessages, loading, refresh, markRead],);return <WorkbenchInboxContext.Provider value={value}>{children}</WorkbenchInboxContext.Provider>;diff --git a/vibe/ui_server.py b/vibe/ui_server.pyindex 9f00967c1..51654fdaa 100644--- a/vibe/ui_server.py+++ b/vibe/ui_server.py@@ -2990,6 +2990,7 @@ def sessions_mark_read(session_id: str):conn, session_id, until_message_id=until_message_id)unread_counts = messages_service.unread_counts(conn, platform="avibe")+ unread_by_session = messages_service.unread_counts_by_session(conn, platform="avibe")except LookupError as err:return jsonify({"error": str(err)}), 404if updated:@@ -3000,9 +3001,16 @@ def sessions_mark_read(session_id: str):"scope_id": session["scope_id"],"delta": -updated,"unread_counts": unread_counts,+ "unread_by_session": unread_by_session,},)- return jsonify({"updated": updated, "unread_counts": unread_counts})+ return jsonify(+ {+ "updated": updated,+ "unread_counts": unread_counts,+ "unread_by_session": unread_by_session,+ }+ )@app.route("/api/events", methods=["GET"])@@ -3080,8 +3088,10 @@ def inbox_list():limit=limit,before_id=before_id,)- result["unread_counts"] = messages_service.unread_counts(- conn, platform=platform if platform != "all" else None+ scope_filter = platform if platform != "all" else None+ result["unread_counts"] = messages_service.unread_counts(conn, platform=scope_filter)+ result["unread_by_session"] = messages_service.unread_counts_by_session(+ conn, platform=scope_filter)return jsonify(result)@@ -3399,14 +3409,8 @@ if os.environ.get("E2E_TEST_MODE", "").lower() in ("true", "1", "yes"):or modal_values.get("codex_reasoning_effort")),opencode_agent=modal_values.get("opencode_agent"),- opencode_model=modal_values.get("opencode_model"),- opencode_reasoning_effort=modal_values.get("opencode_reasoning_effort"),claude_agent=modal_values.get("claude_agent"),- claude_model=modal_values.get("claude_model"),- claude_reasoning_effort=modal_values.get("claude_reasoning_effort"),codex_agent=modal_values.get("codex_agent"),- codex_model=modal_values.get("codex_model"),- codex_reasoning_effort=modal_values.get("codex_reasoning_effort"),)store.save()return jsonify({"ok": True, "action": action})@@ -3452,14 +3456,8 @@ if os.environ.get("E2E_TEST_MODE", "").lower() in ("true", "1", "yes"):or modal_values.get("codex_reasoning_effort")),opencode_agent=modal_values.get("opencode_agent"),- opencode_model=modal_values.get("opencode_model"),- opencode_reasoning_effort=modal_values.get("opencode_reasoning_effort"),claude_agent=modal_values.get("claude_agent"),- claude_model=modal_values.get("claude_model"),- claude_reasoning_effort=modal_values.get("claude_reasoning_effort"),codex_agent=modal_values.get("codex_agent"),- codex_model=modal_values.get("codex_model"),- codex_reasoning_effort=modal_values.get("codex_reasoning_effort"),)store.save()return jsonify({"ok": True, "action": action})