graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
fix(gui): synchronize responsive activity state
Rach Pradhaneabdd901ff35
diff --git a/gui/src/app/sessionClientActions.ts b/gui/src/app/sessionClientActions.tsindex 7ef334c4..c0c16669 100644--- a/gui/src/app/sessionClientActions.ts+++ b/gui/src/app/sessionClientActions.ts@@ -1,7 +1,7 @@import * as desktopClient from "../services/desktop/client";import type { RuntimeStatus } from "../services/desktop/types/contracts";-import { sessionStore } from "./sessionStore";+import { getWorkspaceMetaStoreKey, sessionStore } from "./sessionStore";import type {FollowupResponseInput,WorkspacePromptSettingsUpdateInput,@@ -83,3 +83,26 @@ export async function updateWorkspacePromptSettings(return null;}}++export async function updateWorkspaceFastMode(+ workspacePath: string | null,+ enabled: boolean,+) {+ try {+ await desktopClient.setFast(enabled, workspacePath);+ const state = sessionStore.getState();+ const workspaceMetaKey = getWorkspaceMetaStoreKey(workspacePath);+ const promptSettings =+ state.workspaceMetaByKey[workspaceMetaKey]?.promptSettings ?? null;++ if (promptSettings != null) {+ state.setWorkspacePromptSettings(workspacePath, {+ ...promptSettings,+ fastEnabled: enabled,+ });+ }+ return true;+ } catch {+ return false;+ }+}diff --git a/gui/src/app/sessionStore.test.ts b/gui/src/app/sessionStore.test.tsindex 4875aa04..1a79e0ff 100644--- a/gui/src/app/sessionStore.test.ts+++ b/gui/src/app/sessionStore.test.ts@@ -9,6 +9,10 @@ import type {let runtimeStatusCallCount = 0;let promptSettingsCallCount = 0;let conversationViewCallCount = 0;+let setFastCall:+ | { enabled: boolean; workspacePath: string | null | undefined }+ | null = null;+let setFastImpl: () => Promise<void>;let runtimeStatusImpl: (workspacePath: string | null) => Promise<RuntimeStatus | null>;let promptSettingsImpl: (workspacePath: string | null,@@ -99,7 +103,13 @@ function createSnapshot(}mock.module("../services/desktop/client", () => ({- setFast: async () => {},+ setFast: async (+ enabled: boolean,+ workspacePath?: string | null,+ ) => {+ setFastCall = { enabled, workspacePath };+ await setFastImpl();+ },savePastedImage: async () => "/tmp/pasted-image.png",imageThumbnail: async () => "data:image/jpeg;base64,",openExternalUrl: async () => {},@@ -130,18 +140,51 @@ const {resetSessionStore,sessionStore,} = await import("./sessionStore");+const { updateWorkspaceFastMode } = await import("./sessionClientActions");describe("sessionStore", () => {beforeEach(() => {conversationViewCallCount = 0;runtimeStatusCallCount = 0;promptSettingsCallCount = 0;+ setFastCall = null;+ setFastImpl = async () => {};conversationViewImpl = async () => createSnapshot();runtimeStatusImpl = async () => runtimeStatusFixture;promptSettingsImpl = async () => promptSettingsFixture;resetSessionStore();});+ test("successful fast-mode updates synchronize shared prompt settings", async () => {+ const workspacePath = "/workspace/codegraff-gui";+ sessionStore+ .getState()+ .setWorkspacePromptSettings(workspacePath, promptSettingsFixture);++ expect(await updateWorkspaceFastMode(workspacePath, true)).toBe(true);+ expect(setFastCall).toEqual({ enabled: true, workspacePath });+ expect(+ sessionStore.getState().workspaceMetaByKey[workspacePath]?.promptSettings+ ?.fastEnabled,+ ).toBe(true);+ });++ test("failed fast-mode updates preserve authoritative prompt settings", async () => {+ const workspacePath = "/workspace/codegraff-gui";+ sessionStore+ .getState()+ .setWorkspacePromptSettings(workspacePath, promptSettingsFixture);+ setFastImpl = async () => {+ throw new Error("backend unavailable");+ };++ expect(await updateWorkspaceFastMode(workspacePath, true)).toBe(false);+ expect(+ sessionStore.getState().workspaceMetaByKey[workspacePath]?.promptSettings+ ?.fastEnabled,+ ).toBe(false);+ });+test("applySessionSnapshot derives views, request agents, and request timings", () => {sessionStore.getState().applySessionSnapshot(createSnapshot({diff --git a/gui/src/components/PromptInputCard.tsx b/gui/src/components/PromptInputCard.tsxindex cf8adf10..d8b48ce0 100644--- a/gui/src/components/PromptInputCard.tsx+++ b/gui/src/components/PromptInputCard.tsx@@ -22,7 +22,8 @@ import { useAttachments } from "@/hooks/useSession";import { useCommandAutocomplete } from "@/hooks/useCommandAutocomplete";import { useDropZone } from "@/hooks/useFileDrop";import { usePromptModelPicker } from "@/hooks/usePromptModelPicker";-import { savePastedImage, setFast } from "@/services/desktop/client";+import { updateWorkspaceFastMode } from "@/app/sessionClientActions";+import { savePastedImage } from "@/services/desktop/client";import { cn } from "@/utils/cn";import {getPromptHistoryNavigationResult,@@ -147,7 +148,7 @@ export function PromptInputCard({if (!fastApplies) return;const next = !fastEnabled;setFastOverride({ source: authoritativeFastEnabled, value: next });- void setFast(next, workspacePath).catch(() => {+ void updateWorkspaceFastMode(workspacePath ?? null, next).then(() => {setFastOverride(null);});}diff --git a/gui/src/components/chat/ChatActivityRow.tsx b/gui/src/components/chat/ChatActivityRow.tsxindex fa49d1ed..06736ba7 100644--- a/gui/src/components/chat/ChatActivityRow.tsx+++ b/gui/src/components/chat/ChatActivityRow.tsx@@ -40,6 +40,10 @@ import { classifyUnknownToolName } from "./utils/classifyActivityResult";import { ChatInlineText } from "./ChatInlineText";import { ChatStatusLabel } from "./ChatStatusLabel";import { ActivityResultRenderer } from "./activity-results/ActivityResultRenderer";+import {+ createActivityDisclosureState,+ reconcileActivityDisclosure,+} from "./utils/chatActivityDisclosure";import { getActivityResultModel } from "./utils/getActivityResultModel";const activityTriggerClassName = cn(@@ -190,20 +194,16 @@ function ActivityOperationRow({}export function ChatActivityRow({ item, workspacePath }: ChatActivityRowProps) {- const [disclosure, setDisclosure] = useState({- isOpen: item.isThinking || item.isRunning || item.hasError,- observedRunning: item.isRunning,- });+ const [disclosure, setDisclosure] = useState(() =>+ createActivityDisclosureState(item),+ );// Reconcile the stream transition before rendering children. This preserves// the user's open state when work completes, auto-opens newly running work,// and keeps failures visible without scheduling an extra effect render.- if (!item.isThinking && disclosure.observedRunning !== item.isRunning) {- setDisclosure({- isOpen:- item.isRunning || item.hasError ? true : disclosure.isOpen,- observedRunning: item.isRunning,- });+ const reconciledDisclosure = reconcileActivityDisclosure(disclosure, item);+ if (reconciledDisclosure !== disclosure) {+ setDisclosure(reconciledDisclosure);}const open = disclosure.isOpen;diff --git a/gui/src/components/chat/markdown/MermaidDiagram.tsx b/gui/src/components/chat/markdown/MermaidDiagram.tsxindex 642115ad..bf87a603 100644--- a/gui/src/components/chat/markdown/MermaidDiagram.tsx+++ b/gui/src/components/chat/markdown/MermaidDiagram.tsx@@ -106,9 +106,10 @@ export function MermaidDiagram({ code }: { code: string }) {status: "ready" | "failed";svg: string | null;} | null>(null);- const [zoomed, setZoomed] = useState(false);+ const [zoomedRenderKey, setZoomedRenderKey] = useState<string | null>(null);const currentResult =renderResult?.key === renderKey ? renderResult : null;+ const zoomed = zoomedRenderKey === renderKey;useEffect(() => {let cancelled = false;@@ -165,11 +166,11 @@ export function MermaidDiagram({ code }: { code: string }) {role="button"tabIndex={0}title="Click to zoom"- onClick={() => setZoomed(true)}+ onClick={() => setZoomedRenderKey(renderKey)}onKeyDown={(event) => {if (event.key === "Enter" || event.key === " ") {event.preventDefault();- setZoomed(true);+ setZoomedRenderKey(renderKey);}}}className="cg-mermaid group relative cursor-zoom-in rounded-md border border-border/70 bg-card/40"@@ -185,7 +186,7 @@ export function MermaidDiagram({ code }: { code: string }) {{zoomed ? (<MermaidZoomsvg={currentResult.svg}- onClose={() => setZoomed(false)}+ onClose={() => setZoomedRenderKey(null)}/>) : null}</>diff --git a/gui/src/components/chat/utils/chatActivityDisclosure.test.ts b/gui/src/components/chat/utils/chatActivityDisclosure.test.tsnew file mode 100644index 00000000..0e0fc360--- /dev/null+++ b/gui/src/components/chat/utils/chatActivityDisclosure.test.ts@@ -0,0 +1,79 @@+import { describe, expect, test } from "bun:test";++import {+ createActivityDisclosureState,+ reconcileActivityDisclosure,+} from "./chatActivityDisclosure";++describe("activity disclosure transitions", () => {+ test("opens when an idle activity starts running", () => {+ const idle = createActivityDisclosureState({+ hasError: false,+ isRunning: false,+ isThinking: false,+ });++ expect(+ reconcileActivityDisclosure(idle, {+ hasError: false,+ isRunning: true,+ isThinking: false,+ }),+ ).toEqual({+ isOpen: true,+ observedRunning: true,+ });+ });++ test("preserves the user's disclosure state after successful completion", () => {+ const runningButClosed = {+ isOpen: false,+ observedRunning: true,+ };++ expect(+ reconcileActivityDisclosure(runningButClosed, {+ hasError: false,+ isRunning: false,+ isThinking: false,+ }),+ ).toEqual({+ isOpen: false,+ observedRunning: false,+ });+ });++ test("forces a failed completion open", () => {+ expect(+ reconcileActivityDisclosure(+ {+ isOpen: false,+ observedRunning: true,+ },+ {+ hasError: true,+ isRunning: false,+ isThinking: false,+ },+ ),+ ).toEqual({+ isOpen: true,+ observedRunning: false,+ });+ });++ test("returns the same state when no stream transition occurred", () => {+ const state = {+ isOpen: true,+ observedRunning: false,+ };++ expect(+ reconcileActivityDisclosure(state, {+ hasError: false,+ isRunning: false,+ isThinking: false,+ }),+ ).toBe(state);+ });+});diff --git a/gui/src/components/chat/utils/chatActivityDisclosure.ts b/gui/src/components/chat/utils/chatActivityDisclosure.tsnew file mode 100644index 00000000..2bc08092--- /dev/null+++ b/gui/src/components/chat/utils/chatActivityDisclosure.ts@@ -0,0 +1,37 @@+export interface ActivityDisclosureState {+ isOpen: boolean;+ observedRunning: boolean;+}++interface ActivityDisclosureInput {+ hasError: boolean;+ isRunning: boolean;+ isThinking: boolean;+}++export function createActivityDisclosureState(+ input: ActivityDisclosureInput,+): ActivityDisclosureState {+ return {+ isOpen: input.isThinking || input.isRunning || input.hasError,+ observedRunning: input.isRunning,+ };+}++export function reconcileActivityDisclosure(+ state: ActivityDisclosureState,+ input: ActivityDisclosureInput,+): ActivityDisclosureState {+ if (+ input.isThinking ||+ state.observedRunning === input.isRunning+ ) {+ return state;+ }++ return {+ isOpen:+ input.isRunning || input.hasError ? true : state.isOpen,+ observedRunning: input.isRunning,+ };+}diff --git a/gui/src/components/new-chat-screen/NewChatScreen.tsx b/gui/src/components/new-chat-screen/NewChatScreen.tsxindex 241f1935..577e5eae 100644--- a/gui/src/components/new-chat-screen/NewChatScreen.tsx+++ b/gui/src/components/new-chat-screen/NewChatScreen.tsx@@ -192,6 +192,9 @@ function NewChatScreenContent({const hasCommandResults = commandResults.length > 0;const hasProvider = hasConfiguredProvider(providerSetup.providers);const onboardingCompletedBySetup = hasProvider && hasCurrentWorkspace;+ if (!onboardingCompleted && onboardingCompletedBySetup) {+ setOnboardingCompleted(true);+ }const showOnboarding =!hasCommandResults &&shouldShowOnboardingPanel({@@ -201,14 +204,14 @@ function NewChatScreenContent({});useEffect(() => {- if (onboardingCompleted || !onboardingCompletedBySetup) {+ if (!onboardingCompletedBySetup) {return;}writeOnboardingCompleted(typeof window === "undefined" ? null : window.localStorage,);- }, [onboardingCompleted, onboardingCompletedBySetup]);+ }, [onboardingCompletedBySetup]);function completeOnboarding() {setOnboardingCompleted(true);diff --git a/gui/src/components/ui/ThinkingGlyph.tsx b/gui/src/components/ui/ThinkingGlyph.tsxindex d4c8de7e..c8e5061f 100644--- a/gui/src/components/ui/ThinkingGlyph.tsx+++ b/gui/src/components/ui/ThinkingGlyph.tsx@@ -26,6 +26,13 @@ export function ThinkingGlyph({ className }: { className?: string }) {useEffect(() => {const effect = new BrailleWave();const reduceMotion = prefersReducedMotion();+ let freed = false;+ const freeEffect = () => {+ if (!freed) {+ effect.free();+ freed = true;+ }+ };let last = 0;let raf = 0;const tick = (time: number) => {@@ -34,7 +41,7 @@ export function ThinkingGlyph({ className }: { className?: string }) {last = time;}if (reduceMotion) {- effect.free();+ freeEffect();} else {raf = requestAnimationFrame(tick);}@@ -43,9 +50,7 @@ export function ThinkingGlyph({ className }: { className?: string }) {return () => {cancelAnimationFrame(raf);- if (!reduceMotion) {- effect.free();- }+ freeEffect();};}, []);