fix(browser): keep the panel closed when an agent opens a page

The agent's browser.open used to force the context panel open and steal
the active surface, which read as panels opening by themselves. Tab
upserts now take a reveal option: the agent's opener passes reveal: false,
so the tab mounts invisibly (panes are kept alive regardless of
visibility, so agent control still works) while the panel and the active
tab stay exactly as the user left them. Manual opens are unchanged.
This commit is contained in:
Bohdan Triapitsyn
2026-08-26 20:32:12 +03:00
parent 11d3c0d51e
commit 6770bc3717
3 changed files with 22 additions and 10 deletions
+16 -8
View File
@@ -393,7 +393,9 @@ const touchContextPanelState = (prev?: ContextPanelDirectoryState): ContextPanel
const upsertContextPanelTab = (
current: ContextPanelDirectoryState,
descriptor: ContextPanelTabDescriptor,
options?: { reveal?: boolean },
): ContextPanelDirectoryState => {
const reveal = options?.reveal !== false;
const nextTab = createContextPanelTab(descriptor);
// A real file tab replaces the empty editor placeholder ('file' with no
// target) that the rail can open before any file is picked.
@@ -418,12 +420,18 @@ const upsertContextPanelTab = (
}
: tab));
const activeTabId = nextTab.id;
// A background upsert (an agent working a page) keeps the panel exactly as
// the user left it: closed stays closed, and whatever tab they were on
// stays active. The tab still exists — panes are kept mounted regardless of
// visibility — so agent control and a later manual open both find it.
const activeTabId = reveal
? nextTab.id
: current.activeTabId ?? nextTab.id;
const clampedTabs = clampContextPanelTabs(tabs, CONTEXT_PANEL_MAX_TABS, activeTabId);
return {
...current,
isOpen: true,
isOpen: reveal ? true : current.isOpen,
tabs: clampedTabs,
activeTabId: resolveActiveContextPanelTabID(clampedTabs, activeTabId),
touchedAt: Date.now(),
@@ -806,14 +814,14 @@ interface UIStore {
toggleContextEditorTree: () => void;
setContextEditorTreeWidth: (width: number) => void;
openContextSurface: (directory: string, mode: ContextPanelMode) => void;
openContextPanelTab: (directory: string, tab: ContextPanelTabDescriptor) => void;
openContextPanelTab: (directory: string, tab: ContextPanelTabDescriptor, options?: { reveal?: boolean }) => void;
openContextDiff: (directory: string, filePath: string, staged?: boolean, scope?: PendingDiffScope | null) => void;
openContextFile: (directory: string, filePath: string) => void;
openContextFileAtLine: (directory: string, filePath: string, line: number, column?: number) => void;
openContextOverview: (directory: string) => void;
openContextPlan: (directory: string) => void;
openContextPreview: (directory: string, url: string) => void;
openContextBrowser: (directory: string, url?: string) => void;
openContextBrowser: (directory: string, url?: string, options?: { reveal?: boolean }) => void;
openNewContextBrowserTab: (directory: string) => void;
setContextPanelTabTargetPath: (directory: string, tabID: string, targetPath: string) => void;
setActiveContextPanelTab: (directory: string, tabID: string) => void;
@@ -1239,7 +1247,7 @@ export const useUIStore = create<UIStore>()(
state.openContextPanelTab(normalizedDirectory, { mode });
},
openContextPanelTab: (directory, tab) => {
openContextPanelTab: (directory, tab, options) => {
const normalizedDirectory = normalizeDirectoryPath((directory || '').trim());
if (!normalizedDirectory) {
return;
@@ -1250,7 +1258,7 @@ export const useUIStore = create<UIStore>()(
const current = touchContextPanelState(prev);
const byDirectory = {
...state.contextPanelByDirectory,
[normalizedDirectory]: upsertContextPanelTab(current, tab),
[normalizedDirectory]: upsertContextPanelTab(current, tab, options),
};
return { contextPanelByDirectory: clampContextPanelRoots(byDirectory, 20) };
@@ -1351,7 +1359,7 @@ export const useUIStore = create<UIStore>()(
label: null,
});
},
openContextBrowser: (directory, url = '') => {
openContextBrowser: (directory, url = '', options) => {
const normalizedDirectory = normalizeDirectoryPath((directory || '').trim());
if (!normalizedDirectory || isVSCodeRuntime()) return;
const targetUrl = typeof url === 'string' && url.trim().length > 0 ? url.trim() : '';
@@ -1360,7 +1368,7 @@ export const useUIStore = create<UIStore>()(
targetPath: targetUrl,
dedupeKey: targetUrl || 'browser',
label: null,
});
}, options);
},
setContextPanelTabTargetPath: (directory, tabID, targetPath) => {