diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index 788a82b228253..82cfa81e245ec 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -184,16 +184,20 @@ import { useLazurioThreadTabs, } from "../lazurio/LazurioEnvironmentBrowser"; import { + BuddyBackToConversation, BuddyThreadDetailsPanel, buddyRightPanelState, buddyRuntimeMode, buddyTerminalUiState, useBuddyChatShortcuts, useBuddyPage, + useBuddyPanelEscape, + useBuddyPanels, useBuddyQueuedRunCount, useBuddyWindowInView, useBuddyHermesControls, } from "../lazurio/BuddySurface"; +import { buddyPanelOpensItself } from "../lazurio/buddySurfaceFrame"; import { BuddyPageChip } from "../lazurio/BuddySurfacePageChip"; import { ThreadPreviewMiniPlayer, @@ -604,6 +608,15 @@ export default function ChatView(props: ChatViewProps) { // default and the chat is only the conversation; Buddy's window on the shared server is a whole // T3 thread (GEN4). const buddySurface = useBuddyHermesControls(environmentId); + // Lazurio overlay: Buddy's small window offers neither the right panel nor the terminal, and in his + // full-screen window the right panel opens over the whole window (BuddySurface.tsx). + // Read as plain values: the React Compiler memoizes what reads them. + const { + offered: buddyPanelsOffered, + wholeWindow: buddyWholeWindow, + framed: buddyFramed, + backLabel: buddyBackLabel, + } = useBuddyPanels(); // The page Buddy is asked from travels with the person's next message (buddySurfacePage.ts). const buddyPage = useBuddyPage(environmentId); const buddyInView = useBuddyWindowInView(environmentId); @@ -799,7 +812,7 @@ export default function ChatView(props: ChatViewProps) { // (BuddySurface.tsx). Read inside the selector, as the right panel's state below is. const terminalUiState = useTerminalUiStateStore((state) => buddyTerminalUiState( - buddySurface, + buddySurface || !buddyPanelsOffered, selectThreadTerminalUiState(state.terminalUiStateByThreadKey, routeThreadRef), ), ); @@ -1112,8 +1125,9 @@ export default function ChatView(props: ChatViewProps) { // changed on every render and looped as soon as the panel opened. const rightPanelState = useRightPanelStore((state) => buddyRightPanelState( - buddySurface, + buddySurface || !buddyPanelsOffered, selectThreadRightPanelState(state.byThreadKey, activeThreadRef), + buddyWholeWindow, ), ); const shouldUsePlanSidebarSheet = prefersPlanSidebarSheet && rightPanelState.maximized !== true; @@ -1140,7 +1154,7 @@ export default function ChatView(props: ChatViewProps) { // A side chat has no panel of its own (upstream's `embedded`); its parent's strip serves it. // Buddy's surface, with no panel, does not follow them either (plan DEV-6676). useLazurioThreadTabs(buddySurface || embedded ? null : activeThreadRef, { - inlinePanel: !shouldUsePlanSidebarSheet, + inlinePanel: buddyPanelOpensItself(!shouldUsePlanSidebarSheet, buddyFramed), draft: !isServerThread, }); const { active: panelAnimationsActive, durationMs: panelAnimationDurationMs } = @@ -2081,7 +2095,9 @@ export default function ChatView(props: ChatViewProps) { const activeRunningTurnId = activeRuntime?.activeRunId ?? null; useProactivePanels({ threadRef: isServerThread && !embedded ? activeThreadRef : null, - enabled: settings.proactivePanelsEnabled && !shouldUsePlanSidebarSheet && !embedded, + // Lazurio overlay: nothing opens by itself over Buddy's conversation in his window. + enabled: + settings.proactivePanelsEnabled && !shouldUsePlanSidebarSheet && !embedded && !buddyFramed, settingsHydrated: clientSettingsHydrated, threadDetailLoading, runningTurnId: activeRunningTurnId, @@ -2480,6 +2496,7 @@ export default function ChatView(props: ChatViewProps) { onDiffPanelOpen, closeRightPanelSurface, }); + useBuddyPanelEscape(buddyWholeWindow && rightPanelOpen, toggleRightPanelStable); const pullRequestSurfaceAvailable = supportsPullRequests && pullRequestPanelTarget !== null; const { acknowledgeActiveThreadWoke, @@ -2794,9 +2811,9 @@ export default function ChatView(props: ChatViewProps) { } }); - // Lazurio overlay (plan DEV-6676): Buddy's surface has no terminal or right panel, so their keys - // stay the browser's there (buddySurfaceControls.ts). - useBuddyChatShortcuts(buddySurface, { + // Lazurio overlay (plan DEV-6676): Buddy's surface, and his small window, have no terminal or right + // panel, so their keys stay the browser's there (buddySurfaceControls.ts). + useBuddyChatShortcuts(buddySurface || !buddyPanelsOffered, { enabled: activeThreadId !== null && !backgroundThread, embedded, composerElement: composerOverlayElement, @@ -3383,6 +3400,8 @@ export default function ChatView(props: ChatViewProps) { onToggleTerminal: toggleTerminalVisibilityStable, onToggleThreadPanel: toggleThreadPanelStable, onToggleRightPanel: toggleRightPanelStable, + showTerminalControl: buddyPanelsOffered, + showRightPanelControl: buddyPanelsOffered, } satisfies PanelLayoutControlsProps; const panelToggleControls = ( ; const panelLayoutControls = ( + {buddyWholeWindow && rightPanelOpen ? ( + + ) : null} {panelToggleControls} ); diff --git a/apps/web/src/lazurio/BuddySurface.tsx b/apps/web/src/lazurio/BuddySurface.tsx index 9d3e859f97dff..c649998fb517b 100644 --- a/apps/web/src/lazurio/BuddySurface.tsx +++ b/apps/web/src/lazurio/BuddySurface.tsx @@ -61,7 +61,14 @@ import { pageRecordOf } from "./buddySurfacePage"; import { useLinkedUnlistedProjectIds } from "./unlistedRows"; import { BUDDY_WORKING_ROW, buddyConversationRows, buddyFailureOf } from "./buddySurfaceTimeline"; import { prefersCzech } from "./threadTabs"; -import { buddyHostOfWindow, buddyWindowInView } from "./buddySurfaceFrame"; +import { RIGHT_PANEL_INLINE_LAYOUT_MEDIA_QUERY } from "../rightPanelLayout"; +import { + buddyEscapeTaken, + buddyHostOfWindow, + buddyPanelOverWholeWindow, + buddyPanelsOffered, + buddyWindowInView, +} from "./buddySurfaceFrame"; import { useBuddyFrame } from "./useBuddyFrame"; type BuddyConfig = { readonly lazurioBuddy?: true; readonly lazurioBuddyOrigin?: string } | null; @@ -101,6 +108,64 @@ export function useBuddyWindowInView(environmentId: string): boolean { return buddyWindowInView(framed, shown, context !== null); } +/** + * Buddy's window's panels: `offered` the right panel and the terminal, never in his small window; + * `wholeWindow` the right panel opens over the whole window, as Matěj decided on 2026-11-21, with + * `backLabel` on its control back to the conversation. Elsewhere T3's own layout. + */ +export function useBuddyPanels() { + const framed = buddyHostOfWindow(window) !== null; + const narrow = useMediaQuery(RIGHT_PANEL_INLINE_LAYOUT_MEDIA_QUERY); + const { mode } = useBuddyFrame(framed); + const czech = useCzech(framed); + const offered = buddyPanelsOffered(framed, mode, narrow); + return { + framed, + offered, + wholeWindow: framed && offered, + backLabel: TEXT[czech ? "cs" : "en"].backToConversation, + }; +} + +/** In Buddy's window, the way from the right panel over the whole window back to the conversation. */ +export function BuddyBackToConversation(props: { + readonly label: string; + readonly onBack: () => void; +}) { + return ( + + ); +} + +/** + * Escape over the right panel that covers Buddy's window goes back to the conversation, before the + * frame would make the window small (buddySurfaceFrame.ts). A field or a dialog keeps its own. + */ +export function useBuddyPanelEscape(active: boolean, back: () => void) { + // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- listens to the window's keys while the panel covers it. + useEffect(() => { + if (!active) return; + const onKeyDown = (event: KeyboardEvent) => { + if (event.key !== "Escape" || event.isComposing) return; + if (event.metaKey || event.ctrlKey || event.altKey || event.shiftKey) return; + const target = event.target instanceof HTMLElement ? event.target : null; + if (target?.closest("input, textarea, select, [contenteditable='true']")) return; + if (buddyEscapeTaken(document)) return; + back(); + }; + window.addEventListener("keydown", onKeyDown); + return () => window.removeEventListener("keydown", onKeyDown); + }, [active, back]); +} + /** Buddy's surface, read outside React when a command runs: false until the config is known. */ export const isBuddySurfaceNow = (): boolean => isBuddySurfaceConfig(appAtomRegistry.get(primaryServerConfigAtom)); @@ -133,6 +198,7 @@ function useCzech(buddy: boolean): boolean { const TEXT = { cs: { fullscreen: "Na celou obrazovku", + backToConversation: "Zpět k rozhovoru", panel: "Zmenšit do panelu", close: "Zavřít", days: "Dny", @@ -153,6 +219,7 @@ const TEXT = { }, en: { fullscreen: "Full screen", + backToConversation: "Back to the conversation", panel: "Back to the panel", close: "Close", days: "Days", @@ -458,13 +525,18 @@ export const buddyTerminalUiState = (buddy: boolean, state: TerminalUiState): Te type RightPanelState = ReturnType; /** - * The thread's right panel as the chat reads it: in Buddy's surface closed and empty, whatever the - * thread holds (a panel opened on it earlier, a link followed into it, a page an agent showed), - * since Buddy's chat is only the conversation (root decision 0210, addendum of - * HumanAndMachines/Lazurio#648). The stored panel stays as it is. As T3's elsewhere. + * The thread's right panel as the chat reads it: closed and empty in Buddy's surface, which is only + * the conversation (root decision 0210, addendum of HumanAndMachines/Lazurio#648); maximized over + * his whole window (`wholeWindow`). The stored panel stays as it is. As T3's elsewhere. */ -export const buddyRightPanelState = (buddy: boolean, state: RightPanelState): RightPanelState => - buddy ? selectThreadRightPanelState({}, null) : state; +export const buddyRightPanelState = ( + buddy: boolean, + state: RightPanelState, + wholeWindow = false, +): RightPanelState => { + if (buddy) return selectThreadRightPanelState({}, null); + return wholeWindow ? buddyPanelOverWholeWindow(state) : state; +}; /** The chat's shortcuts, without those Buddy's surface has no use for there. */ export function useBuddyChatShortcuts(buddy: boolean, input: ChatShortcutsInput) { diff --git a/apps/web/src/lazurio/buddySurfaceFrame.test.ts b/apps/web/src/lazurio/buddySurfaceFrame.test.ts index 8c5d5d000e8c4..3772996c02c42 100644 --- a/apps/web/src/lazurio/buddySurfaceFrame.test.ts +++ b/apps/web/src/lazurio/buddySurfaceFrame.test.ts @@ -1,6 +1,13 @@ import { describe, expect, it } from "vite-plus/test"; -import { buddyHostOfWindow, buddyWindowInView, startBuddyFrame } from "./buddySurfaceFrame"; +import { + buddyHostOfWindow, + buddyPanelOpensItself, + buddyPanelOverWholeWindow, + buddyPanelsOffered, + buddyWindowInView, + startBuddyFrame, +} from "./buddySurfaceFrame"; const HOST = "https://launchpad.example-person.lazurio.io"; // What the host sends after the frame's ready, about its own Environment. @@ -17,7 +24,13 @@ const personalContext = { }; /** A frame's window as far as the frame uses it: its parent, its ancestors and its listeners. */ -function frameWindow(options: { readonly host?: string; readonly openMenu?: boolean } = {}) { +function frameWindow( + options: { + readonly host?: string; + readonly openMenu?: boolean; + readonly panelOverWindow?: boolean; + } = {}, +) { const posted: Array<{ readonly message: unknown; readonly origin: string }> = []; const listeners = new Map void>(); const parent = { @@ -28,7 +41,14 @@ function frameWindow(options: { readonly host?: string; readonly openMenu?: bool location: { ancestorOrigins: [options.host ?? HOST] }, document: { referrer: "", - querySelector: () => (options.openMenu === true ? {} : null), + // As the DOM does, it also finds the hidden dialog below. + querySelector: (selector: string) => + selector.includes("maximized-away") ? (options.panelOverWindow === true ? {} : null) : {}, + // A narrow window keeps a closed sheet mounted as a hidden dialog. + querySelectorAll: () => [ + { checkVisibility: () => false }, + ...(options.openMenu === true ? [{ checkVisibility: () => true }] : []), + ], }, addEventListener: (type: string, listener: (event: unknown) => void) => listeners.set(type, listener), @@ -69,12 +89,18 @@ describe("Buddy's frame", () => { expect(frame.layout()).toBe("panel"); }); - it("leaves Escape to an open menu, a modifier or an input method", () => { + it("leaves Escape to an open menu, a panel over the window, a modifier or an input method", () => { const menu = frameWindow({ openMenu: true }); startBuddyFrame(menu.win); menu.key(); expect(layouts(menu.posted)).toEqual([]); + // Escape over the panel goes back to the conversation first (BuddySurface.tsx). + const panel = frameWindow({ panelOverWindow: true }); + startBuddyFrame(panel.win).requestLayout("fullscreen"); + panel.key(); + expect(layouts(panel.posted)).toEqual(["fullscreen"]); + const { win, posted, key } = frameWindow(); startBuddyFrame(win); key({ shiftKey: true }); @@ -136,6 +162,61 @@ describe("Buddy's frame", () => { ).toBe(true); }); + it("takes the size the host's window shows, also one the host chose itself, and drops a defect", () => { + const { win, posted, key, receive } = frameWindow(); + const frame = startBuddyFrame(win); + expect(frame.mode()).toBeNull(); + // The launcher opened the remembered full screen: one Escape leaves it. + receive({ type: "lazurio.buddy.layout", v: 1, mode: "fullscreen" }); + expect(frame.mode()).toBe("fullscreen"); + key(); + expect(layouts(posted)).toEqual(["panel"]); + for (const defect of [ + { type: "lazurio.buddy.layout", v: 2, mode: "panel" }, + { type: "lazurio.buddy.layout", v: 1, mode: "huge" }, + { type: "lazurio.buddy.layout", v: 1, mode: "panel", extra: true }, + ]) + receive(defect); + receive({ type: "lazurio.buddy.layout", v: 1, mode: "panel" }, "https://example.com"); + receive({ type: "lazurio.buddy.layout", v: 1, mode: "panel" }, HOST, {}); + expect(frame.mode()).toBe("fullscreen"); + receive({ type: "lazurio.buddy.layout", v: 1, mode: "closed" }); + expect(frame.mode()).toBe("closed"); + expect(frame.layout()).toBe("panel"); + }); + + it("offers the panels in the full-screen window, also a phone's, and never in the small one", () => { + const { win } = frameWindow(); + const framed = buddyHostOfWindow(win) !== null; + // As the host says: full screen on a phone or a computer offers both, the small window neither. + expect(buddyPanelsOffered(framed, "fullscreen", true)).toBe(true); + expect(buddyPanelsOffered(framed, "fullscreen", false)).toBe(true); + expect(buddyPanelsOffered(framed, "panel", true)).toBe(false); + expect(buddyPanelsOffered(framed, "closed", false)).toBe(false); + // An older host never says: a frame too narrow for the panels reads as the small window. + expect(buddyPanelsOffered(framed, null, true)).toBe(false); + expect(buddyPanelsOffered(framed, null, false)).toBe(true); + // Chat on its own page, also a narrow one, keeps T3's own layout. + expect(buddyPanelsOffered(false, null, true)).toBe(true); + }); + + it("reads the right panel over the whole window as maximized, the same object for the same state", () => { + const stored: { isOpen: boolean; surfaces: string[]; maximized?: true } = { + isOpen: true, + surfaces: [], + }; + const whole = buddyPanelOverWholeWindow(stored); + expect(whole).toEqual({ isOpen: true, surfaces: [], maximized: true }); + expect(buddyPanelOverWholeWindow(stored)).toBe(whole); + expect(stored).toEqual({ isOpen: true, surfaces: [] }); + const maximized = { isOpen: true, maximized: true as const }; + expect(buddyPanelOverWholeWindow(maximized)).toBe(maximized); + // A page an agent reveals never opens the panel by itself in Buddy's window. + expect(buddyPanelOpensItself(true, false)).toBe(true); + expect(buddyPanelOpensItself(true, true)).toBe(false); + expect(buddyPanelOpensItself(false, false)).toBe(false); + }); + it("talks to nobody outside a host's frame", () => { const { win, posted, key } = frameWindow({ host: "https://example.com" }); const frame = startBuddyFrame(win); diff --git a/apps/web/src/lazurio/buddySurfaceFrame.ts b/apps/web/src/lazurio/buddySurfaceFrame.ts index 20c0ab79b8542..09be6e88c00c2 100644 --- a/apps/web/src/lazurio/buddySurfaceFrame.ts +++ b/apps/web/src/lazurio/buddySurfaceFrame.ts @@ -1,11 +1,12 @@ /** * Lazurio overlay (root decision 0210, plan DEV-6676): Buddy's surface as the frame of the bubble - * (buddySurfaceProtocol.ts). The host draws no controls over the frame and sees no keys inside it, - * so Escape asks for the panel unless something in the surface took it (the composer's editor marks - * every Escape handled, so that alone does not count). The frame keeps the size it asked for last. + * (buddySurfaceProtocol.ts). The host sees no keys inside the frame, so Escape asks for the panel + * unless something in the surface took it (the composer's editor marks every Escape handled, so that + * alone does not count). The frame keeps the size it asked for or the host said last. */ import { acceptBuddyContext, + acceptBuddyLayout, acceptBuddyShown, type BuddyContext, type BuddyLayout, @@ -18,10 +19,12 @@ export interface BuddyFrame { /** The page around the frame, a host of the bubble; null outside a frame or another page. */ readonly hostOrigin: string | null; readonly context: () => BuddyContext | null; - /** The size the frame asked for last; the panel until it asks. */ + /** The size the frame asked for or the host said last; the panel until either. */ readonly layout: () => Exclude; /** Whether the host's window shows the frame; null until the host says (an older Lazurio never does). */ readonly shown: () => boolean | null; + /** The size the host's window shows; null until the host says (an older Lazurio never does). */ + readonly mode: () => BuddyLayout | null; readonly subscribe: (listener: () => void) => () => void; readonly requestLayout: (mode: BuddyLayout) => void; readonly stop: () => void; @@ -38,8 +41,53 @@ export const buddyWindowInView = ( heardContext: boolean, ): boolean => !framed || shown === true || (shown === null && heardContext); -/** An open menu, dialog or list inside the surface takes Escape before the frame does. */ -const ESCAPE_TAKERS = '[role="dialog"], [role="alertdialog"], [role="menu"], [role="listbox"]'; +/** + * Whether Buddy's window offers the right panel and the terminal: in his full-screen window, never in + * the small one (LazurioPlatform F47, addendum of 2026-11-20). Before the host says its size (an older + * Lazurio), a frame too narrow for the panels reads as the small window. + */ +export const buddyPanelsOffered = ( + framed: boolean, + mode: BuddyLayout | null, + narrow: boolean, +): boolean => !framed || (mode === null ? !narrow : mode === "fullscreen"); + +/** + * Whether a page an agent reveals may open the right panel by itself: never in Buddy's window, + * where nothing opens over his conversation (F60); its tab still joins the strip. + */ +export const buddyPanelOpensItself = (inlinePanel: boolean, framed: boolean): boolean => + inlinePanel && !framed; + +const overWholeWindow = new WeakMap(); + +/** + * A thread's right panel read as covering the whole window, its stored size untouched; the same + * object for the same state, since the chat reads it inside a store selector. + */ +export function buddyPanelOverWholeWindow(state: T): T { + if (state.maximized === true) return state; + let whole = overWholeWindow.get(state) as T | undefined; + if (whole === undefined) { + whole = { ...state, maximized: true }; + overWholeWindow.set(state, whole); + } + return whole; +} + +const OPEN_TAKERS = '[role="dialog"], [role="alertdialog"], [role="menu"], [role="listbox"]'; + +/** + * Whether an open menu, dialog or list the person sees takes Escape: a narrow window keeps T3's + * closed sheets mounted as hidden dialogs, which take nothing. + */ +export const buddyEscapeTaken = (doc: Pick): boolean => + [...doc.querySelectorAll(OPEN_TAKERS)].some( + (element) => typeof element.checkVisibility !== "function" || element.checkVisibility(), + ); + +/** A right panel over the whole window takes it too: Escape there goes back to the conversation. */ +const PANEL_OVER_WINDOW = '[data-chat-column-maximized-away="true"]'; /** The host page around this one, if a host of the bubble frames it; read without side effects. */ export const buddyHostOfWindow = (win: Window): string | null => @@ -52,6 +100,7 @@ export function startBuddyFrame(win: Window): BuddyFrame { let context: BuddyContext | null = null; let layout: Exclude = "panel"; let shown: boolean | null = null; + let mode: BuddyLayout | null = null; const listeners = new Set<() => void>(); const notify = () => { for (const listener of listeners) listener(); @@ -78,6 +127,15 @@ export function startBuddyFrame(win: Window): BuddyFrame { notify(); return; } + const nowMode = acceptBuddyLayout(received, hostOrigin); + if (nowMode !== null) { + if (nowMode === mode) return; + mode = nowMode; + // The host's size is the one to leave from, also after it changed the size by itself. + if (nowMode !== "closed") layout = nowMode; + notify(); + return; + } const nowShown = acceptBuddyShown(received, hostOrigin); if (nowShown === null || nowShown === shown) return; shown = nowShown; @@ -91,7 +149,8 @@ export function startBuddyFrame(win: Window): BuddyFrame { event.ctrlKey || event.altKey || event.shiftKey || - win.document.querySelector(ESCAPE_TAKERS) !== null + buddyEscapeTaken(win.document) || + win.document.querySelector(PANEL_OVER_WINDOW) !== null ) return; requestLayout("panel"); @@ -106,6 +165,7 @@ export function startBuddyFrame(win: Window): BuddyFrame { context: () => context, layout: () => layout, shown: () => shown, + mode: () => mode, subscribe: (listener) => { listeners.add(listener); return () => listeners.delete(listener); diff --git a/apps/web/src/lazurio/buddySurfaceProtocol.ts b/apps/web/src/lazurio/buddySurfaceProtocol.ts index 9772d3cc148a3..eb6a490bbac99 100644 --- a/apps/web/src/lazurio/buddySurfaceProtocol.ts +++ b/apps/web/src/lazurio/buddySurfaceProtocol.ts @@ -293,6 +293,28 @@ export function acceptBuddyShown( return data.shown; } +/** + * The frame's side of the host's `lazurio.buddy.layout` (LazurioPlatform#1139): the size the host's + * window shows, which the host also changes by itself; from the same parent and origin as a context. + */ +export function acceptBuddyLayout( + event: { readonly data: unknown; readonly origin: string; readonly fromParent: boolean }, + hostOrigin: string | null, +): BuddyLayout | null { + if (event.fromParent !== true) return null; + if (buddyHostEnvironment(hostOrigin) === null || event.origin !== hostOrigin) return null; + const data = event.data; + if ( + !isPlain(data) || + !hasOnly(data, ["type", "v", "mode"]) || + data.type !== BUDDY_MESSAGE.layout || + data.v !== BUDDY_PROTOCOL_VERSION || + !isOneOf(BUDDY_LAYOUTS, data.mode) + ) + return null; + return data.mode; +} + export const buddyReady = () => ({ type: BUDDY_MESSAGE.ready, v: BUDDY_PROTOCOL_VERSION }); /** A request for the window's size; null for a size there is none of. */ diff --git a/apps/web/src/lazurio/buddySurfaceTheme.browser.test.tsx b/apps/web/src/lazurio/buddySurfaceTheme.browser.test.tsx index cbf2a1692531d..a8bb45c60f799 100644 --- a/apps/web/src/lazurio/buddySurfaceTheme.browser.test.tsx +++ b/apps/web/src/lazurio/buddySurfaceTheme.browser.test.tsx @@ -21,6 +21,7 @@ vi.mock(import("./useBuddyFrame"), async (original) => ({ context: frame.context, layout: "panel" as const, shown: null, + mode: null, requestLayout: () => {}, }), })); diff --git a/apps/web/src/lazurio/threadTabs.browser.test.ts b/apps/web/src/lazurio/threadTabs.browser.test.ts index e550d0a04585c..b1835fc2f5813 100644 --- a/apps/web/src/lazurio/threadTabs.browser.test.ts +++ b/apps/web/src/lazurio/threadTabs.browser.test.ts @@ -157,9 +157,21 @@ describe("reveals", () => { receiveSnapshot(threadA, snapshot([])); receiveSnapshot(threadA, snapshot([{ tabId: id(1), revealRequest: { id: "epoch-1:1" } }])); expect(panel()).toMatchObject({ isOpen: false, surfaces: [tab(1)] }); + // Another Environment's tab an agent reveals joins the strip and opens nothing either (Buddy's + // window, where nothing opens over the conversation by itself). + receiveForeign(threadA, { + tabId: "AB".repeat(16), + view: foreign.view, + revealRequest: { id: "e:0" }, + }); + expect(panel()).toMatchObject({ isOpen: false, surfaces: [tab(1), foreign] }); syncOf(threadA).inlinePanel = true; receiveSnapshot(threadA, snapshot([{ tabId: id(1), revealRequest: { id: "epoch-1:2" } }])); - expect(panel()).toEqual({ isOpen: true, activeSurfaceId: tab(1).id, surfaces: [tab(1)] }); + expect(panel()).toEqual({ + isOpen: true, + activeSurfaceId: tab(1).id, + surfaces: [tab(1), foreign], + }); }); it("bring a tab the strip already has to the front, behind another surface in view", () => { diff --git a/apps/web/src/lazurio/useBuddyFrame.ts b/apps/web/src/lazurio/useBuddyFrame.ts index f4806175352aa..a05fe1d256bc4 100644 --- a/apps/web/src/lazurio/useBuddyFrame.ts +++ b/apps/web/src/lazurio/useBuddyFrame.ts @@ -21,6 +21,7 @@ const NO_FRAME: Omit = { context: () => null, layout: () => "panel", shown: () => null, + mode: () => null, subscribe: () => () => {}, requestLayout: () => {}, }; @@ -31,11 +32,13 @@ export function useBuddyFrame(buddy: boolean) { const context = useSyncExternalStore(current.subscribe, current.context, () => null); const layout = useSyncExternalStore(current.subscribe, current.layout, () => "panel" as const); const shown = useSyncExternalStore(current.subscribe, current.shown, () => null); + const mode = useSyncExternalStore(current.subscribe, current.mode, () => null); return { framed: current.hostOrigin !== null, context, layout, shown, + mode, requestLayout: current.requestLayout, }; } diff --git a/scripts/lazurio-release-contract.test.mjs b/scripts/lazurio-release-contract.test.mjs index e7a8162b3f07f..353a9f81a7b2e 100644 --- a/scripts/lazurio-release-contract.test.mjs +++ b/scripts/lazurio-release-contract.test.mjs @@ -1996,7 +1996,7 @@ NodeTest.test( // (pingdotgg/t3code#26901). NodeAssert.match( chatView, - /useLazurioThreadTabs\(buddySurface \|\| embedded \? null : activeThreadRef, \{\n\s+inlinePanel: !shouldUsePlanSidebarSheet,\n\s+draft: !isServerThread,\n\s+\}\);/, + /useLazurioThreadTabs\(buddySurface \|\| embedded \? null : activeThreadRef, \{\n\s+inlinePanel: buddyPanelOpensItself\(!shouldUsePlanSidebarSheet, buddyFramed\),\n\s+draft: !isServerThread,\n\s+\}\);/, ); NodeAssert.match(chatView, /const rightPanelActiveContent = activeThreadRef \? \(/); NodeAssert.match( @@ -3450,25 +3450,45 @@ NodeTest.test("Buddy's chat reads like a chat with a friend through its seams", ); NodeAssert.match( chat, - /\n\s+useBuddyChatShortcuts\(buddySurface, \{\n\s+enabled: activeThreadId !== null && !backgroundThread,/, + /\n\s+useBuddyChatShortcuts\(buddySurface \|\| !buddyPanelsOffered, \{\n\s+enabled: activeThreadId !== null && !backgroundThread,/, ); NodeAssert.doesNotMatch(chat, /\buseChatShortcuts\(/); NodeAssert.doesNotMatch(chat, /activeTasksProgress|activeComposerTask/); NodeAssert.match(root, /\{buddySurface \? null : \}/); + // Buddy GEN4's small window offers neither panel either (LazurioPlatform F47, addendum of + // 2026-11-20), and in his full-screen window the right panel covers the whole window, Escape goes + // back to the conversation and nothing opens by itself (LazurioPlatform#1139): `useBuddyPanels`. + NodeAssert.match( + chat, + /\n\s+wholeWindow: buddyWholeWindow,[\s\S]{0,80}\} = useBuddyPanels\(\);\n/, + ); + NodeAssert.match( + chat, + /\n\s+useBuddyPanelEscape\(buddyWholeWindow && rightPanelOpen, toggleRightPanelStable\);\n/, + ); + NodeAssert.match(chat, /&& !embedded && !buddyFramed,\n/); + NodeAssert.match( + chat, + /inlinePanel: buddyPanelOpensItself\(!shouldUsePlanSidebarSheet, buddyFramed\),/, + ); + NodeAssert.match( + chat, + /showMaximizeControl=\{!shouldUsePlanSidebarSheet && !buddyWholeWindow\}[\s\S]{0,400}\{buddyWholeWindow && rightPanelOpen \? \(\n\s+/, + ); // Root decision 0210, addendum of HumanAndMachines/Lazurio#648: Buddy's surface shows neither T3's // terminal nor its right panel. Their states are read closed inside the stores' selectors (outside, // the React Compiler leaves what reads them unmemoized and the panel re-rendered until React error // 301), no thread tabs are followed, code blocks get no Run in terminal, links open in a new tab. NodeAssert.match( chat, - /\n\s+const terminalUiState = useTerminalUiStateStore\(\(state\) =>\n\s+buddyTerminalUiState\(\n\s+buddySurface,\n\s+selectThreadTerminalUiState\(state\.terminalUiStateByThreadKey, routeThreadRef\),\n/, + /\n\s+const terminalUiState = useTerminalUiStateStore\(\(state\) =>\n\s+buddyTerminalUiState\(\n\s+buddySurface \|\| !buddyPanelsOffered,\n\s+selectThreadTerminalUiState\(state\.terminalUiStateByThreadKey, routeThreadRef\),\n/, ); NodeAssert.equal(chat.match(/\bselectThreadTerminalUiState\(/g)?.length, 1); NodeAssert.match(chat, /\{embedded \|\| buddySurface \? null : \(\n\s+\n\s+buddyRightPanelState\(\n\s+buddySurface,\n\s+selectThreadRightPanelState\(state\.byThreadKey, activeThreadRef\),\n/, + /\n\s+const rightPanelState = useRightPanelStore\(\(state\) =>\n\s+buddyRightPanelState\(\n\s+buddySurface \|\| !buddyPanelsOffered,\n\s+selectThreadRightPanelState\(state\.byThreadKey, activeThreadRef\),\n\s+buddyWholeWindow,\n/, ); NodeAssert.equal(chat.match(/\bselectThreadRightPanelState\(/g)?.length, 1); NodeAssert.match(chat, /\n\s+const rightPanelOpen = rightPanelState\.isOpen;\n/);