A desktop coding agent with free access to frontier models.
TypeScript
fix(composer): stop the Sub-agents chip crushing the model selector and its menu running off screen
Samrat Talukdar6688076dda73
diff --git a/apps/app/src/components/model-select.tsx b/apps/app/src/components/model-select.tsxindex cbc38031..0d3abb42 100644--- a/apps/app/src/components/model-select.tsx+++ b/apps/app/src/components/model-select.tsx@@ -453,24 +453,27 @@ export function ModelSelect({disabled={disabled}aria-label="Change model"aria-keyshortcuts="Meta+Alt+/"- className="flex h-9 max-h-9 min-w-0 max-w-fit flex-1 items-center overflow-hidden gap-1.5 rounded-md px-2.5 text-sm text-gray-10 transition-colors hover:bg-gray-3 hover:text-gray-12 disabled:pointer-events-none disabled:opacity-60"+ data-testid="model-select-trigger"+ // Shrinks (truncating the model name) before it would push into+ // the controls beside it; never below a readable width.+ className="flex h-9 max-h-9 min-w-24 shrink items-center gap-1.5 overflow-hidden rounded-md px-2.5 text-sm text-gray-10 transition-colors hover:bg-gray-3 hover:text-gray-12 disabled:pointer-events-none disabled:opacity-60"/>}>- <span className="flex min-w-0 max-w-56 items-center gap-1.5">- <span className="truncate">+ <span className="flex min-w-0 max-w-64 items-center gap-1.5">+ <span className="min-w-0 truncate">{selectedValueHidden || !value.modelID? "Select model": selectedModelTitle}</span>{!selectedValueHidden && value.modelID && selectedProviderTitle ? (- <span className="hidden shrink-0 text-xs text-gray-9 sm:inline">· {selectedProviderTitle}</span>+ <span className="hidden shrink-0 text-xs text-gray-9 @min-[820px]/composer:inline">· {selectedProviderTitle}</span>) : null}{showBehavior ? (<span className="shrink-0 text-gray-9">· {effectiveBehaviorLabel}</span>) : null}</span>- <ChevronDown className="h-3 w-3" />+ <ChevronDown className="h-3 w-3 shrink-0" /></TooltipTrigger><TooltipContent>Change model · Cycle thinking ({shortcutLabel} forward, {reverseShortcutLabel} back)diff --git a/apps/app/src/react-app/domains/session/surface/composer/subagent-model-menu.tsx b/apps/app/src/react-app/domains/session/surface/composer/subagent-model-menu.tsxindex 3667d88a..51c48bb6 100644--- a/apps/app/src/react-app/domains/session/surface/composer/subagent-model-menu.tsx+++ b/apps/app/src/react-app/domains/session/surface/composer/subagent-model-menu.tsx@@ -65,14 +65,17 @@ function SubagentModelPicker(props: { client: SubagentModelClient; policyLocked:data-testid="subagent-model-trigger"aria-label={`Sub-agents: ${summary}`}title={props.policyLocked ? SUBAGENT_MENU_POLICY_LOCK : `Sub-agents: ${summary}${unavailable ? " (not available, sub-agents use the main model)" : ""}`}- className={`flex h-9 max-h-9 min-w-0 max-w-56 shrink items-center gap-1.5 rounded-md px-2.5 text-sm transition-colors hover:bg-gray-3 ${+ // An icon (the summary in its tooltip) until the composer is wide+ // enough for the label, so it never squeezes the model selector.+ className={`flex h-9 max-h-9 min-w-9 max-w-64 shrink-[4] items-center justify-center gap-1.5 overflow-hidden rounded-md px-2.5 text-sm transition-colors hover:bg-gray-3 @min-[720px]/composer:justify-start ${unavailable ? "text-orange-600 dark:text-orange-400" : custom ? "text-gray-12" : "text-gray-10 hover:text-gray-12"}`}>{saving ? <LoaderCircle className="size-4 shrink-0 animate-spin" /> : <Users className="size-4 shrink-0" />}- <span className="truncate whitespace-nowrap">{custom ? summary : "Sub-agents"}</span>+ <span data-testid="subagent-model-label" className="hidden min-w-0 truncate whitespace-nowrap @min-[720px]/composer:inline">{custom ? summary : "Sub-agents"}</span></DropdownMenuTrigger>- <DropdownMenuContent side="top" sideOffset={10} className="max-h-[min(560px,70vh)] w-[min(340px,calc(100vw-32px))] overflow-y-auto p-2">+ {/* Capped to the room the positioner measured, so a long menu scrolls inside the viewport instead of running off it. */}+ <DropdownMenuContent side="top" sideOffset={10} className="max-h-[min(560px,var(--available-height))] w-[min(340px,calc(100vw-32px))] overflow-y-auto p-2"><DropdownMenuGroup><DropdownMenuLabel className="px-3 text-sm">Sub-agents: model</DropdownMenuLabel><DropdownMenuRadioGroup value={setting.model ?? SAME}>diff --git a/apps/app/tests/subagent-model-menu.test.tsx b/apps/app/tests/subagent-model-menu.test.tsxindex a8a4f763..431afb87 100644--- a/apps/app/tests/subagent-model-menu.test.tsx+++ b/apps/app/tests/subagent-model-menu.test.tsx@@ -25,9 +25,10 @@ if (typeof globalThis.window === "undefined" || typeof globalThis.document === "}Object.defineProperty(globalThis, "IS_REACT_ACT_ENVIRONMENT", { configurable: true, value: true });-const [{ SubagentModelMenu }, { createOmniRushServerClient, OmniRushServerError }] = await Promise.all([+const [{ SubagentModelMenu }, { createOmniRushServerClient, OmniRushServerError }, { Popover, PopoverContent, PopoverTrigger }] = await Promise.all([import("../src/react-app/domains/session/surface/composer/subagent-model-menu"),import("../src/app/lib/omnirush-server"),+ import("../src/components/ui/popover"),]);const codex = ["low", "high", "xhigh", "max"];@@ -45,6 +46,7 @@ function fakeClient(initial: OmniRushSubagentModelSetting, signedIn = true) {{ id: "gpt-6-sol", name: "GPT 6 Sol", family: "OpenAI", default: false, efforts: codex },{ id: "gpt-5.6-sol", name: "GPT-5.6 Sol", family: "OpenAI", default: false, efforts: codex },{ id: "meta-muse-spark", name: "Meta Muse Spark", family: "Meta Muse", default: false, efforts: ["minimal", "low", "medium", "high", "xhigh"] },+ { id: "muse-spark-1.1", name: "Muse Spark 1.1", family: "Meta Muse", default: false, efforts: ["minimal", "low", "medium", "high", "xhigh"] },],}),setSubagentModel: async (next: OmniRushSubagentModelSetting) => {@@ -172,3 +174,91 @@ test("the server client rejects a failed save with the server's readable messageglobalThis.fetch = originalFetch;}});++async function settle() {+ await act(async () => { await new Promise((resolve) => setTimeout(resolve, 20)); });+}++function menu(): HTMLElement | null {+ return document.querySelector('[data-slot="dropdown-menu-content"]');+}++function pressOutside(target: Element) {+ for (const type of ["pointerdown", "mousedown", "pointerup", "mouseup", "click"]) {+ const init = { bubbles: true, cancelable: true, composed: true, button: 0 };+ target.dispatchEvent(type.startsWith("pointer") ? new PointerEvent(type, { ...init, pointerType: "mouse" }) : new MouseEvent(type, init));+ }+}++test("in a narrow composer the chip is an icon that still names the setting, and never squeezes the model selector", async () => {+ const { client } = fakeClient({ model: "meta-muse-spark", effort: "xhigh" });+ await mount(<SubagentModelMenu client={client} />);+ const chip = trigger()!;+ // The label only shows once the composer container is wide enough; the+ // icon-only chip keeps the full summary for screen readers and the tooltip.+ const label = document.querySelector('[data-testid="subagent-model-label"]')!;+ expect(label.textContent).toBe("Meta Muse Spark · Xhigh");+ expect(label.className.split(" ")).toEqual(expect.arrayContaining(["hidden", "truncate", "@min-[720px]/composer:inline"]));+ expect(chip.getAttribute("aria-label")).toBe("Sub-agents: Meta Muse Spark · Xhigh");+ expect(chip.getAttribute("title")).toBe("Sub-agents: Meta Muse Spark · Xhigh");+ // It gives up its width before the model selector does, down to the icon.+ expect(chip.className.split(" ")).toEqual(expect.arrayContaining(["min-w-9", "shrink-[4]", "overflow-hidden"]));+});++test("the menu lists every model and stays inside the viewport, scrolling instead of running off the top", async () => {+ const { client } = fakeClient({ model: "meta-muse-spark", effort: "xhigh" });+ await mount(<SubagentModelMenu client={client} />);+ await act(async () => { trigger()!.click(); });+ await settle();+ const content = menu()!;+ // Portalled out of the composer, above the toolbar.+ expect(content.closest("[data-composer-toolbar]")).toBeNull();+ expect(content.className).toContain("max-h-[min(560px,var(--available-height))]");+ expect(content.className).toContain("overflow-y-auto");+ expect(content.className).not.toContain("70vh");+ for (const id of ["gpt-6-astra", "gpt-6-sol", "gpt-5.6-sol", "meta-muse-spark", "muse-spark-1.1"]) {+ expect(document.querySelector(`[data-testid="subagent-model-${id}"]`)).not.toBeNull();+ }+});++test("Escape and an outside click close the menu; opening the model picker leaves only one menu open", async () => {+ const { client } = fakeClient({ model: null, effort: null });+ const container = await mount(+ <div data-composer-toolbar>+ <Popover>+ <PopoverTrigger data-testid="model-picker-stand-in">Change model</PopoverTrigger>+ <PopoverContent data-testid="model-list">GPT 6 Astra</PopoverContent>+ </Popover>+ <SubagentModelMenu client={client} />+ <p data-testid="outside">Describe your task</p>+ </div>,+ );++ await act(async () => { trigger()!.click(); });+ await settle();+ expect(menu()).not.toBeNull();+ await act(async () => { document.activeElement?.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true })); });+ await settle();+ expect(menu()).toBeNull();++ await act(async () => { trigger()!.click(); });+ await settle();+ expect(menu()).not.toBeNull();+ await act(async () => { pressOutside(container.querySelector('[data-testid="outside"]')!); });+ await settle();+ expect(menu()).toBeNull();++ await act(async () => { trigger()!.click(); });+ await settle();+ expect(menu()).not.toBeNull();+ const modelTrigger = container.querySelector<HTMLElement>('[data-testid="model-picker-stand-in"]')!;+ await act(async () => { pressOutside(modelTrigger); });+ await settle();+ if (!document.querySelector('[data-testid="model-list"]')) {+ await act(async () => { modelTrigger.click(); });+ await settle();+ }+ expect(menu()).toBeNull();+ expect(document.querySelector('[data-testid="model-list"]')).not.toBeNull();+ expect(document.querySelectorAll('[data-slot="dropdown-menu-content"], [data-slot="popover-content"]').length).toBe(1);+});