graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
fix(native): keep browser pane closed across chat selection
yxlyxa9eec74e3a3f
diff --git a/apps/native/components/site/GraffHarness.tsx b/apps/native/components/site/GraffHarness.tsxindex 948e61bc..c2183659 100644--- a/apps/native/components/site/GraffHarness.tsx+++ b/apps/native/components/site/GraffHarness.tsx@@ -56,9 +56,6 @@ import {type Workspace,} from "@/lib/workspaces";-/** Whether the sidecar browser pane was open, restored after a reload. */-const BROWSER_OPEN_KEY = "graff.native.browser.open";-export default function GraffHarness() {const navigation = useResponsiveNavigation();const [chats, setChats] = useState<Chat[]>([{ id: 1, title: null, messages: [] }]);@@ -109,7 +106,7 @@ export default function GraffHarness() {const [dialog, setDialog] = useState<null | { mode: "new" } | { mode: "settings" }>(null);// The sidecar browser: one Chrome tab per chat, and the pins the user// drops on it, which ride ahead of the chat's next prompt.- const [browserOpen, setBrowserOpen] = useBrowserVisibility(BROWSER_OPEN_KEY, (chat) => {+ const [browserOpen, setBrowserOpen] = useBrowserVisibility((chat) => {const target = chats.find(c => chat ? chatHandle(pageRef.current, c.id) === chat : c.id === activeId);if (target) { focusChat(target.id); setFilesOpen(false); } return target ? chatHandle(pageRef.current, target.id) : false;});@@ -135,7 +132,7 @@ export default function GraffHarness() {const [pinsByChat, setPinsByChat] = useState<Record<number, BrowserPin[]>>({});const pinsRef = useRef<Record<number, BrowserPin[]>>({});const { promptFocusRoot, requestPromptFocus } = useNavigationPromptFocus();- const activateChat = (id: number) => { setActiveId(id); requestPromptFocus(id); };+ const activateChat = (id: number) => { setBrowserOpen(false); setActiveId(id); requestPromptFocus(id); };const chatIdRef = useRef(1);const msgIdRef = useRef(0);// Split view: ordered visible chats, independent of focus. Each keeps its@@ -284,6 +281,7 @@ export default function GraffHarness() {/** Focus a pane in place, or restore the selected workspace tab’s layout. */const focusChat = (id: number, focusPrompt = true) => {+ if (id !== activeIdRef.current) setBrowserOpen(false);setProjectsOpen(false); setAgentsOpen(false);setConversationsOpen(false);const folder = chatsRef.current.find(chat => chat.id === id)?.cwd;diff --git a/apps/native/components/site/useBrowserVisibility.ts b/apps/native/components/site/useBrowserVisibility.tsindex bfab581b..2d15e8ab 100644--- a/apps/native/components/site/useBrowserVisibility.ts+++ b/apps/native/components/site/useBrowserVisibility.ts@@ -1,16 +1,9 @@"use client";import { useEffect, useRef, useState } from "react";import { desktop } from "@/lib/desktop";-export function useBrowserVisibility(key: string, onAgentOpen: (chat?: string) => string | false) {+export function useBrowserVisibility(onAgentOpen: (chat?: string) => string | false) {const [open, setOpen] = useState(false);- const restored = useRef(false);const callback = useRef(onAgentOpen); callback.current = onAgentOpen;- useEffect(() => {- try {- if (!restored.current) { restored.current = true; setOpen(localStorage.getItem(key) !== "0"); }- else localStorage.setItem(key, open ? "1" : "0");- } catch {}- }, [key, open]);useEffect(() => desktop()?.subscribe(event => {if (event.type === "show" && event.chat) { if (callback.current(event.chat)) setOpen(true); }if (event.type === "open-link" && event.url) {diff --git a/apps/native/electron/browser-focus-frontend.cjs b/apps/native/electron/browser-focus-frontend.cjsindex 79f10fd8..df6963cc 100644--- a/apps/native/electron/browser-focus-frontend.cjs+++ b/apps/native/electron/browser-focus-frontend.cjs@@ -46,9 +46,8 @@ async function runBrowserFocus({ win, output, click, until, report }) {await js(`Array.from(document.querySelectorAll('button[aria-label="New chat"]')).find(e=>e.checkVisibility()).setAttribute('data-browser-new-chat','true')`);await click('[data-browser-new-chat="true"]');await until(async () => (await focused()) !== a && browser.visible !== chatA, 'second chat');- if (!await js(`!!document.querySelector('[aria-label="Address"]')?.checkVisibility()`)) {- await openBrowser();- }+ assert.equal(await js(`!!document.querySelector('[aria-label="Close browser"]')`), false, 'switching chats closes the browser pane');+ await openBrowser();await navigateUser(`${origin}/selected`);const b = await focused(), chatB = browser.visible;await click('textarea[aria-label="Prompt"]');@@ -81,6 +80,7 @@ async function runBrowserFocus({ win, output, click, until, report }) {assert.equal(browser.visible, chatA);assert.ok(events.some(event => event.type === 'show' && event.chat === chatA));await click(`[data-tab-members="${b}"] button[aria-pressed]`);+ assert.equal(await js(`!!document.querySelector('[aria-label="Close browser"]')`), false, 'explicit browser reveal does not leak into the next chat');assert.equal(await js(`document.querySelector('[data-chat="${b}"] textarea').value`), 'Keep my draft here');report.passed.push('native background browser open, popup and failed navigation preserve selected chat, composer draft and native view; explicit user reveal still works');} finally {