Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.
fix(desktop): a blue dot on Chat always points to a conversation you can see
Salman Qureshif627dd4d380c
diff --git a/apps/desktop/src/app/conversation.ts b/apps/desktop/src/app/conversation.tsindex 0ed9d60b..a72f9ddc 100644--- a/apps/desktop/src/app/conversation.ts+++ b/apps/desktop/src/app/conversation.ts@@ -94,6 +94,11 @@ export function useConversationStore(): ConversationStore {return useContext(ConversationContext);}+/** The list a conversation shows in: Code's (a Code session) or Chat's. */+export function listOf(thread: { id: string; title?: string | null }, codeIds: Set<string>): Surface {+ return codeIds.has(thread.id) || (thread.title ?? "").startsWith("Code · ") ? "code" : "chat";+}+/* ── Code sessions: which runtime sessions belong to Code, and their folder ── */export interface CodeSession {diff --git a/apps/desktop/src/app/events.ts b/apps/desktop/src/app/events.tsindex 4c65d2a8..441561c9 100644--- a/apps/desktop/src/app/events.ts+++ b/apps/desktop/src/app/events.ts@@ -211,6 +211,7 @@ export async function refreshThreads(): Promise<void> {try {const { threads } = await api.chat.threads();useChat.getState().setThreads(threads);+ useNotify.getState().keepOnly(new Set(threads.map((t) => t.id)));} catch { /* offline: keep what we have */ }}diff --git a/apps/desktop/src/app/notify/notify.test.ts b/apps/desktop/src/app/notify/notify.test.tsindex 4b224453..127767a1 100644--- a/apps/desktop/src/app/notify/notify.test.ts+++ b/apps/desktop/src/app/notify/notify.test.ts@@ -71,4 +71,23 @@ describe("notifications", () => {useNotify.getState().seen("x");expect(useNotify.getState().unread.x).toBeUndefined();});++ it("forgets marks on deleted conversations", () => {+ useNotify.getState().markUnread("kept");+ useNotify.getState().markUnread("deleted");+ useNotify.getState().markWaiting("gone", "p1");+ useNotify.getState().keepOnly(new Set(["kept"]));+ expect(Object.keys(useNotify.getState().unread)).toEqual(["kept"]);+ expect(useNotify.getState().waiting).toEqual({});+ });+});++describe("which list a conversation shows in", async () => {+ const { listOf } = await import("../conversation");+ it("Code sessions and Code-titled ones go to Code, the rest to Chat", () => {+ const code = new Set(["c1"]);+ expect(listOf({ id: "c1", title: "Fix the build" }, code)).toBe("code");+ expect(listOf({ id: "x", title: "Code · refactor" }, code)).toBe("code");+ expect(listOf({ id: "y", title: "Srinagar news" }, code)).toBe("chat");+ });});diff --git a/apps/desktop/src/app/notify/notify.ts b/apps/desktop/src/app/notify/notify.tsindex 49227fb7..baa00238 100644--- a/apps/desktop/src/app/notify/notify.ts+++ b/apps/desktop/src/app/notify/notify.ts@@ -148,7 +148,10 @@ export function handleActivity(e: ActivityEvent): void {case "done":case "failed": {n.clearWaiting(e.sessionId);- if (!onScreen(e.sessionId)) n.markUnread(e.sessionId);+ if (!onScreen(e.sessionId)) {+ n.markUnread(e.sessionId);+ void import("../events").then(({ refreshThreads }) => refreshThreads());+ }if (watching(e.sessionId) || !worthTelling(e.kind, e.ms ?? 0, n.prefs)) return;if (e.kind === "done") tell("done", e.sessionId, `Done: ${label(e)}`, e.preview || "Mercury finished.");else tell("failed", e.sessionId, `Stopped with an error: ${label(e)}`, e.message || "Something went wrong.");diff --git a/apps/desktop/src/app/notify/store.ts b/apps/desktop/src/app/notify/store.tsindex 99a40d84..2c8ebad5 100644--- a/apps/desktop/src/app/notify/store.ts+++ b/apps/desktop/src/app/notify/store.ts@@ -61,6 +61,8 @@ interface NotifyState {markWaiting(id: string, promptId: string): void;clearWaiting(id: string, promptId?: string): void;seen(id: string): void;+ /** Forget marks on conversations that no longer exist (deleted). */+ keepOnly(ids: Set<string>): void;pushAlert(a: Omit<Alert, "id">): void;dismiss(id: string): void;}@@ -88,6 +90,17 @@ export const useNotify = create<NotifyState>((set) => ({write(SEEN_KEY, unread);return { unread };}),+ keepOnly: (ids) => set((s) => {+ const gone = Object.keys(s.unread).filter((id) => !ids.has(id));+ const goneWaiting = Object.keys(s.waiting).filter((id) => !ids.has(id));+ if (!gone.length && !goneWaiting.length) return s;+ const unread = { ...s.unread };+ for (const id of gone) delete unread[id];+ const waiting = { ...s.waiting };+ for (const id of goneWaiting) delete waiting[id];+ write(SEEN_KEY, unread);+ return { unread, waiting };+ }),pushAlert: (a) => set((s) => ({ alerts: [...s.alerts.filter((x) => !(a.sessionId && x.sessionId === a.sessionId && x.kind === a.kind)), { ...a, id: crypto.randomUUID() }].slice(-3) })),dismiss: (id) => set((s) => ({ alerts: s.alerts.filter((a) => a.id !== id) })),}));diff --git a/apps/desktop/src/layout/Rail.tsx b/apps/desktop/src/layout/Rail.tsxindex ddbe2d2e..042a93bf 100644--- a/apps/desktop/src/layout/Rail.tsx+++ b/apps/desktop/src/layout/Rail.tsx@@ -1,12 +1,12 @@import { Bot, Brain, Code2, MessageSquare, Puzzle, Settings, Sparkles, Layers } from "lucide-react";import { useEffect, useMemo } from "react";import { cx } from "~/lib/cx";-import { useRuntimeState, useUi, type View } from "~/app/store";+import { useChat, useRuntimeState, useUi, type View } from "~/app/store";import { Mark } from "~/components/Logo";import { LABELS } from "~/components/indicators/StateOrb";import { Tooltip } from "~/components/ui/Tooltip";import { useNotify } from "~/app/notify/store";-import { useCodeSessions } from "~/app/conversation";+import { listOf, useCodeSessions } from "~/app/conversation";const ITEMS: Array<{ view: View; label: string; icon: typeof MessageSquare; key: string }> = [{ view: "chat", label: "Chat", icon: MessageSquare, key: "1" },@@ -32,14 +32,17 @@ export function Rail({ connectionName }: { connectionName: string }) {const unread = useNotify((s) => s.unread);const waiting = useNotify((s) => s.waiting);const codeIds = useCodeSessions((s) => s.sessions);+ const threads = useChat((s) => s.threads);+ // Count only conversations that are in that list, so every dot here has a dot to find there.const dots = useMemo(() => {const code = new Set(codeIds.map((c) => c.id));- const of = (ids: string[], surface: "chat" | "code") => ids.filter((id) => code.has(id) === (surface === "code")).length;+ const where = new Map(threads.map((t) => [t.id, listOf(t, code)]));+ const of = (ids: string[], surface: "chat" | "code") => ids.filter((id) => where.get(id) === surface).length;return {chat: { waiting: of(Object.keys(waiting), "chat"), unread: of(Object.keys(unread), "chat") },code: { waiting: of(Object.keys(waiting), "code"), unread: of(Object.keys(unread), "code") },};- }, [unread, waiting, codeIds]);+ }, [unread, waiting, codeIds, threads]);useEffect(() => {const onKey = (e: KeyboardEvent) => {diff --git a/apps/desktop/src/views/chat/ChatView.tsx b/apps/desktop/src/views/chat/ChatView.tsxindex badf0714..c22b09bf 100644--- a/apps/desktop/src/views/chat/ChatView.tsx+++ b/apps/desktop/src/views/chat/ChatView.tsx@@ -1,7 +1,7 @@import { PanelLeft } from "lucide-react";import { useEffect } from "react";import { useChat, useUi } from "~/app/store";-import { conversations, ConversationContext, useCodeSessions } from "~/app/conversation";+import { conversations, ConversationContext, useCodeSessions, listOf } from "~/app/conversation";import { refreshThreads, openThread } from "~/app/events";import { Button } from "~/components/ui/Button";import { Tooltip } from "~/components/ui/Tooltip";@@ -64,7 +64,7 @@ export function ChatView() {<div className="flex h-full min-h-0">{sidebar && (<ThreadList- threads={threads.filter((t) => !codeSet.has(t.id) && !(t.title ?? "").startsWith("Code · "))}+ threads={threads.filter((t) => listOf(t, codeSet) === "chat")}activeId={activeId}onOpen={(id) => { setVoiceOpen(false); void openThread("chat", id); }}onNew={() => { setVoiceOpen(false); void openThread("chat", null); }}diff --git a/apps/desktop/src/views/chat/ThreadList.tsx b/apps/desktop/src/views/chat/ThreadList.tsxindex 0d8c7522..72a62b1a 100644--- a/apps/desktop/src/views/chat/ThreadList.tsx+++ b/apps/desktop/src/views/chat/ThreadList.tsx@@ -72,6 +72,11 @@ export function ThreadList({ threads, activeId, onOpen, onNew, newLabel, searchL</div><div className="min-h-0 flex-1 overflow-y-auto px-2 pb-3">{pinned}+ {threads.some((t) => unread[t.id] && t.id !== activeId) && (+ <div className="flex justify-end px-3 pb-1">+ <button onClick={() => { const seen = useNotify.getState().seen; for (const t of threads) if (unread[t.id]) seen(t.id); }} className="text-xs text-ink4 hover:text-ink">Mark all as read</button>+ </div>+ )}{filtered.length === 0 && <p className="px-3 pt-2 text-base text-ink4">{query ? "Nothing matches." : "No sessions yet."}</p>}{groups.map(([day, list]) => (<div key={day} className="mb-5">diff --git a/src/channels/web.ts b/src/channels/web.tsindex 0445e013..40bea138 100644--- a/src/channels/web.ts+++ b/src/channels/web.ts@@ -263,7 +263,7 @@ export class WebChannel extends BaseChannel {this.pendingInteractions.delete(id);this.broadcast({type: interaction.kind === 'choice' ? 'choice_resolved' : 'permission_resolved',- data: { id, status: 'expired', targetId: interaction.targetId },+ data: { id, status: 'expired', targetId: interaction.sessionId ?? interaction.targetId },});resolve(fallback);}, waitMs);