Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

Track unread completions and clear obsolete waiting displays

justrach1cedc06ef858
diff --git a/apps/native/components/primitives/SidebarNav.tsx b/apps/native/components/primitives/SidebarNav.tsx
index 3213b3bf..58087584 100644
--- a/apps/native/components/primitives/SidebarNav.tsx
+++ b/apps/native/components/primitives/SidebarNav.tsx
@@ -41,6 +41,7 @@ const NAV_ITEMS: { key: string; label: string; icon: ReactNode; count?: string }
];
export type SidebarRecent = {
+ unread?: boolean;
id: string;
label: string;
prompt?: string;
@@ -451,6 +452,7 @@ export default function SidebarNav({
>
<span className={`sidebar-copy flex min-w-0 flex-1 flex-col ${onArchiveRecent || onDeleteRecent ? "pr-6" : ""}`}>
<span className={`truncate text-[13.5px] font-medium ${active ? "text-ink" : "text-ink-2"}`}>
+ {item.unread && <span role="img" aria-label="Unread response" className="mr-1.5 inline-block size-1.5 rounded-full bg-blue-500" />}
{item.label}
</span>
{item.hint && (
diff --git a/apps/native/components/site/ChatBubbles.tsx b/apps/native/components/site/ChatBubbles.tsx
index 076ceb85..9e48014e 100644
--- a/apps/native/components/site/ChatBubbles.tsx
+++ b/apps/native/components/site/ChatBubbles.tsx
@@ -119,7 +119,7 @@ export const AssistantBody = memo(function AssistantBody({
return (
<article data-turn-status={turn.status} aria-busy={live} className="min-w-0 [overflow-wrap:anywhere]" style={{ overflowAnchor: "none", animation: "fade-in 280ms ease both" }}>
- {((thinking && turn.activityKind === "agent_thought_chunk") || reasoningRows.length > 0 || (turn.thoughtMs ?? 0) >= 1500) && (
+ {((thinking && turn.activityKind === "agent_thought_chunk") || reasoningRows.length > 0) && (
<Reasoning
variant="Reasoning"
rows={reasoningRows.length ? reasoningRows : WAITING_ROWS}
diff --git a/apps/native/components/site/GraffHarness.tsx b/apps/native/components/site/GraffHarness.tsx
index ff46198b..c14d7438 100644
--- a/apps/native/components/site/GraffHarness.tsx
+++ b/apps/native/components/site/GraffHarness.tsx
@@ -1,5 +1,6 @@
"use client";
import { useNavigationPromptFocus } from "./useNavigationPromptFocus";
+import { useUnreadChats } from "./useUnreadChats";
import { useHarnessSessions } from "./useHarnessSessions";
import { resumeQueuedPrompt } from "@/lib/prompt-queue-resume";
import { createPromptRunner } from "./harness-prompt-runner";
@@ -146,6 +147,7 @@ export default function GraffHarness() {
const columnIds = (panes.length ? panes : [chatThread.id])
.filter((id, i, all) => all.indexOf(id) === i && chats.some((c) => c.id === id))
.slice(0, MAX_COLUMNS);
+ const { unread, completed } = useUnreadChats(chats.map(c => c.id), projectsOpen || conversationsOpen || agentsOpen || filesOpen ? [] : zoomedPane !== null ? [zoomedPane] : columnIds);
const columnKey = columnIds.join(",");
const { paneRef, tailing } = useChatScroll(chats, columnKey);
const sessionId = sessionIds[chatThread.id] ?? null;
@@ -196,7 +198,7 @@ export default function GraffHarness() {
.catch(() => undefined);
};
- const runPrompt = createPromptRunner({
+ const runPrompt = createPromptRunner({ onCompleted: completed,
runningRef, steerer, setFollowing, chatsRef, model, msgIdRef, setChats, setBusyFor, setHistory, pinsRef, handleOf, setPins, requireSession, adoptCatalog, refreshStored, takeQueuedPrompt, setCancelError
});
const settings = useQuietSettings({ requireSession, handleOf, running: runningRef.current, apply: (catalog) => setModels(catalog.models) });
@@ -369,7 +371,7 @@ export default function GraffHarness() {
if (file) openPath(file);
});
- const recents = sidebarRecents(stored, chats);
+ const recents = sidebarRecents(stored, chats, unread);
// The tab bar's folder chip is the *tab's* workspace; the sidebar's
// switcher is the *active* one (where new tabs open). They differ only
@@ -486,7 +488,7 @@ export default function GraffHarness() {
<div className="flex min-w-0 flex-1 flex-col gap-2.5">
{tabDrag.overlay}
- <HarnessChrome onTabPointerDown={tabDrag.begin} onTabClickCapture={tabDrag.suppressClick} chats={groups.tabs} activeId={groups.activeTab} busyIds={new Set(groups.groups.filter(group => group.ids.some(id => busyIds.has(id))).map(group => group.ids[0]))} focusChat={id => focusChat(groups.focusOf(id))} closeChat={closeTab} newChat={newChat}
+ <HarnessChrome unreadIds={unread} onTabPointerDown={tabDrag.begin} onTabClickCapture={tabDrag.suppressClick} chats={groups.tabs} activeId={groups.activeTab} busyIds={new Set(groups.groups.filter(group => group.ids.some(id => busyIds.has(id))).map(group => group.ids[0]))} focusChat={id => focusChat(groups.focusOf(id))} closeChat={closeTab} newChat={newChat}
conversationsOpen={conversationsOpen} openConversations={openConversations} split={panes.length > 0} toggleSplit={toggleSplit}
filesOpen={filesOpen} onFiles={() => { setAgentsOpen(false); setFileRequest(null); setProjectsOpen(false); setBrowserOpen(false); setConversationsOpen(false); setFilesOpen(fileRequest?.changes ? true : !filesOpen); }}
chatCwd={chatCwd} workspaceName={workspaceName} onFolder={() => setDialog({ mode: "new" })} openChanges={openChanges}
diff --git a/apps/native/components/site/HarnessChrome.tsx b/apps/native/components/site/HarnessChrome.tsx
index c73c0f4e..aa68db7b 100644
--- a/apps/native/components/site/HarnessChrome.tsx
+++ b/apps/native/components/site/HarnessChrome.tsx
@@ -7,6 +7,7 @@ import type { PointerEvent, MouseEvent } from "react";
import type { Chat } from "./harness-types";
import reviewStyles from "./ChangesPane.module.css";
type Props = {
+ unreadIds?: ReadonlySet<number>;
onTabPointerDown?(event: PointerEvent, id: number): void; onTabClickCapture?(event: MouseEvent): void;
chats: (Pick<Chat, "id" | "title"> & { paneIds?: number[]; direction?: "row" | "column"; tree?: SplitTree })[]; activeId: number; busyIds: ReadonlySet<number>;
focusChat(id: number): void; closeChat(id: number): void; newChat(): void;
@@ -16,7 +17,7 @@ type Props = {
terminalVisible: boolean; toggleTerminal(): void; agentsOpen: boolean; onAgents(): void; workingAgents?: number;
tasksOpen?: boolean; taskCount?: number; onTasks?: () => void; splitNotice?: string | null;
};
-export default function HarnessChrome({chats, activeId, busyIds, focusChat, closeChat, newChat,
+export default function HarnessChrome({unreadIds, chats, activeId, busyIds, focusChat, closeChat, newChat,
conversationsOpen, openConversations, split, toggleSplit, filesOpen, onFiles, chatCwd,
workspaceName, onFolder, openChanges, browserOpen, onBrowser, pinCount, terminalVisible,
toggleTerminal, agentsOpen, onAgents, workingAgents = 0, tasksOpen = false, taskCount = 0, onTasks, splitNotice, onTabPointerDown, onTabClickCapture}: Props) {
@@ -51,6 +52,7 @@ export default function HarnessChrome({chats, activeId, busyIds, focusChat, clos
aria-label="Working"
/>
)}
+ {!busyIds.has(c.id) && (c.paneIds ?? [c.id]).some(id => unreadIds?.has(id)) && <span role="img" aria-label="Unread response" className="mr-1 size-1.5 shrink-0 rounded-full bg-blue-500" />}
<button
type="button"
aria-pressed={c.id === activeId && !agentsOpen}
diff --git a/apps/native/components/site/harness-prompt-runner.ts b/apps/native/components/site/harness-prompt-runner.ts
index 5f83b310..705a4c2f 100644
--- a/apps/native/components/site/harness-prompt-runner.ts
+++ b/apps/native/components/site/harness-prompt-runner.ts
@@ -11,6 +11,7 @@ import type { Chat } from "./harness-types";
type Ref<T> = MutableRefObject<T>;
type Setter<T> = Dispatch<SetStateAction<T>>;
type Props = {
+ onCompleted(id: number): void;
runningRef: Ref<Set<number>>; steerer: ReturnType<typeof createQueueSteerer>; setFollowing: Setter<boolean>;
chatsRef: Ref<Chat[]>; model: string | null; msgIdRef: Ref<number>; setChats: Setter<Chat[]>;
setCancelError: Setter<Record<number, string>>;
@@ -20,7 +21,7 @@ type Props = {
adoptCatalog(id: number): Promise<void>; refreshStored(): Promise<void>;
takeQueuedPrompt(id: number): QueuedPrompt | undefined;
};
-export function createPromptRunner({runningRef, steerer, setFollowing, chatsRef, model, msgIdRef, setChats, setBusyFor, setHistory, pinsRef, handleOf, setPins, requireSession, adoptCatalog, refreshStored, takeQueuedPrompt, setCancelError}: Props) {
+export function createPromptRunner({onCompleted, runningRef, steerer, setFollowing, chatsRef, model, msgIdRef, setChats, setBusyFor, setHistory, pinsRef, handleOf, setPins, requireSession, adoptCatalog, refreshStored, takeQueuedPrompt, setCancelError}: Props) {
const patchAssistant = (chatId: number, msgId: number, next: AssistantTurn) => {
setChats((current) =>
current.map((c) =>
@@ -99,6 +100,7 @@ export function createPromptRunner({runningRef, steerer, setFollowing, chatsRef,
if (/^\/(effort|reasoning|fast)(?:\s|$)/.test(trimmed)) void adoptCatalog(chatId);
turn = finishAcpTurn(turn);
painter.finish(turn);
+ if (turn.status === "done" && !turn.error) onCompleted(chatId);
} catch (err) {
turn = finishAcpTurn({ ...turn, error: err instanceof Error ? err.message : String(err), status: "error" });
painter.finish(turn);
diff --git a/apps/native/components/site/harness-sidebar.ts b/apps/native/components/site/harness-sidebar.ts
index 10bddd19..946be06d 100644
--- a/apps/native/components/site/harness-sidebar.ts
+++ b/apps/native/components/site/harness-sidebar.ts
@@ -1,8 +1,8 @@
import {toSidebarRecent,type StoredSession} from '@/lib/sessions';
import type {Chat} from './harness-types';
-export function sidebarRecents(stored:StoredSession[],chats:Chat[]) {
+export function sidebarRecents(stored:StoredSession[],chats:Chat[],unread:ReadonlySet<number>=new Set()) {
const now=Date.now(),titles=new Map(chats.filter(chat=>chat.session&&chat.title).map(chat=>[chat.session,chat.title!]));
- return stored.map(session=>{const row=toSidebarRecent(session,now),title=titles.get(session.name);return title?{...row,label:title}:row;});
+ return stored.map(session=>{const row=toSidebarRecent(session,now),title=titles.get(session.name);return {...row,...(title?{label:title}:{}),unread:chats.some(chat=>chat.session===session.name&&(session.local||!session.workspace||chat.cwd===session.workspace)&&unread.has(chat.id))};});
}
export function sessionFooterTitle(session:string|undefined,acp:string|null,cwd:string|undefined) {
return session?`graff session ${session}${acp?` · ACP ${acp}`:''}${cwd?` · ${cwd}`:''}\nClick to copy the command that resumes it in a terminal.`:undefined;
diff --git a/apps/native/components/site/useUnreadChats.ts b/apps/native/components/site/useUnreadChats.ts
new file mode 100644
index 00000000..5de73ce9
--- /dev/null
+++ b/apps/native/components/site/useUnreadChats.ts
@@ -0,0 +1,34 @@
+import { useCallback, useEffect, useRef, useState } from "react";
+
+/** Completion is unread only when its conversation is not on screen. */
+export function completedUnread(current: ReadonlySet<number>, id: number, visible: readonly number[], present: readonly number[]) {
+ const next = new Set([...current].filter(key => present.includes(key)));
+ if (present.includes(id) && !visible.includes(id)) next.add(id);
+ for (const key of visible) next.delete(key);
+ return next;
+}
+
+export function useUnreadChats(present: number[], visible: number[]) {
+ const [unread, setUnread] = useState<ReadonlySet<number>>(new Set());
+ const state = useRef({ present, visible });
+ state.current = { present, visible };
+ const completed = useCallback((id: number) => {
+ const viewed = document.visibilityState === "hidden" ? [] : state.current.visible;
+ setUnread(current => completedUnread(current, id, viewed, state.current.present));
+ }, []);
+ const visibleKey = visible.join(","), presentKey = present.join(",");
+ useEffect(() => {
+ const viewed = () => {
+ if (document.visibilityState === "hidden") return;
+ setUnread(current => {
+ const next = completedUnread(current, -1, state.current.visible, state.current.present);
+ return next.size === current.size ? current : next;
+ });
+ };
+ viewed();
+ document.addEventListener("visibilitychange", viewed);
+ window.addEventListener("focus", viewed);
+ return () => { document.removeEventListener("visibilitychange", viewed); window.removeEventListener("focus", viewed); };
+ }, [visibleKey, presentKey]);
+ return { unread, completed };
+}
diff --git a/apps/native/lib/assistant-body.test.tsx b/apps/native/lib/assistant-body.test.tsx
new file mode 100644
index 00000000..04ec73ec
--- /dev/null
+++ b/apps/native/lib/assistant-body.test.tsx
@@ -0,0 +1,19 @@
+import { expect, test } from "bun:test";
+import { renderToStaticMarkup } from "react-dom/server";
+import { AssistantBody } from "../components/site/ChatBubbles";
+import { emptyTurn } from "./graff-events";
+
+test("completed turns do not retain a synthetic waiting disclosure", () => {
+ const turn = { ...emptyTurn(), status: "done" as const, thoughtMs: 8000, text: "Check finished." };
+ const html = renderToStaticMarkup(<AssistantBody turn={turn} following={false} />);
+ expect(html).toContain("Check finished.");
+ expect(html).not.toContain("Waiting on the model");
+ expect(html).not.toContain("Thought for");
+});
+
+test("actual reasoning is retained when a turn completes", () => {
+ const turn = { ...emptyTurn(), status: "done" as const, reasoning: "Inspect the relevant file.", thoughtMs: 8000 };
+ const html = renderToStaticMarkup(<AssistantBody turn={turn} following={false} />);
+ expect(html).toContain("Inspect the relevant file.");
+ expect(html).toContain("Thought for 8s");
+});
diff --git a/apps/native/lib/unread-chats.test.ts b/apps/native/lib/unread-chats.test.ts
new file mode 100644
index 00000000..906475d9
--- /dev/null
+++ b/apps/native/lib/unread-chats.test.ts
@@ -0,0 +1,23 @@
+import { expect, test } from "bun:test";
+import { completedUnread } from "../components/site/useUnreadChats";
+import { sidebarRecents } from "../components/site/harness-sidebar";
+
+test("background completion is unread until its pane is viewed", () => {
+ const unread = completedUnread(new Set(), 1, [2], [1, 2]);
+ expect([...unread]).toEqual([1]);
+ expect([...completedUnread(unread, -1, [1], [1, 2])]).toEqual([]);
+});
+
+test("visible split completions and closed chats do not become unread", () => {
+ expect(completedUnread(new Set(), 1, [1, 2], [1, 2]).size).toBe(0);
+ expect(completedUnread(new Set(), 1, [], [2]).size).toBe(0);
+});
+
+test("sidebar consumes the same unread identity as the chat", () => {
+ const saved = { name: "saved", title: "Check", updatedMs: 1, model: null, provider: null, size: 1, workspace: "/fixture" };
+ const chats = [{ id: 1, title: "Check", messages: [], session: "saved", cwd: "/fixture" }];
+ expect(sidebarRecents([saved], chats, new Set([1]))[0].unread).toBe(true);
+ expect(sidebarRecents([saved], chats, new Set())[0].unread).toBe(false);
+ expect(sidebarRecents([{ ...saved, local: true, workspace: "/another" }], chats, new Set([1]))[0].unread).toBe(true);
+ expect(sidebarRecents([{ ...saved, workspace: "/another" }], chats, new Set([1]))[0].unread).toBe(false);
+});