From 150cc83478b2bb67adffdced8fde151a8ef75b90 Mon Sep 17 00:00:00 2001 From: Theo Browne Date: Mon, 27 Jul 2026 04:00:18 -0700 Subject: [PATCH] Fix skill inventory disclosure state --- .../settings/SkillsSettings.logic.ts | 19 ++++++++++++++ .../settings/SkillsSettings.test.ts | 15 +++++++++++ .../components/settings/SkillsSettings.tsx | 25 +++++++++---------- 3 files changed, 46 insertions(+), 13 deletions(-) diff --git a/apps/web/src/components/settings/SkillsSettings.logic.ts b/apps/web/src/components/settings/SkillsSettings.logic.ts index c7f3be6cd5..cc372a68ac 100644 --- a/apps/web/src/components/settings/SkillsSettings.logic.ts +++ b/apps/web/src/components/settings/SkillsSettings.logic.ts @@ -31,6 +31,25 @@ export function filterSkillInventory(inventory: SkillInventory, query: string): }; } +export function displayedSkillCount( + inventory: SkillInventory | null, + isConnected: boolean, +): number | null { + if (!isConnected || !inventory) return null; + return inventory.installations.length; +} + +export function setKeyCollapsed( + keys: ReadonlySet, + key: string, + collapsed: boolean, +): ReadonlySet { + const next = new Set(keys); + if (collapsed) next.add(key); + else next.delete(key); + return next; +} + export interface SkillHarnessGroup { readonly key: string; readonly harness: ProviderDriverKind; diff --git a/apps/web/src/components/settings/SkillsSettings.test.ts b/apps/web/src/components/settings/SkillsSettings.test.ts index 68f5769330..376f5c270f 100644 --- a/apps/web/src/components/settings/SkillsSettings.test.ts +++ b/apps/web/src/components/settings/SkillsSettings.test.ts @@ -2,9 +2,11 @@ import { describe, expect, it } from "vite-plus/test"; import { ProviderDriverKind, ProviderInstanceId, type SkillInventory } from "@t3tools/contracts"; import { + displayedSkillCount, filterSkillInventory, formatSkillPath, groupSkillsByHarness, + setKeyCollapsed, skillContentForDisplay, } from "./SkillsSettings.logic"; @@ -62,6 +64,19 @@ describe("formatSkillPath", () => { }); describe("skill explorer helpers", () => { + it("hides a previously loaded skill count after disconnecting", () => { + expect(displayedSkillCount(inventory, true)).toBe(2); + expect(displayedSkillCount(inventory, false)).toBeNull(); + expect(displayedSkillCount(null, true)).toBeNull(); + }); + + it("applies the requested harness collapsed state without toggling blindly", () => { + const collapsed = setKeyCollapsed(new Set(), "codex", true); + expect([...collapsed]).toEqual(["codex"]); + expect([...setKeyCollapsed(collapsed, "codex", true)]).toEqual(["codex"]); + expect([...setKeyCollapsed(collapsed, "codex", false)]).toEqual([]); + }); + it("groups installations by harness instance and derives their shared root", () => { const groups = groupSkillsByHarness(inventory.installations); expect( diff --git a/apps/web/src/components/settings/SkillsSettings.tsx b/apps/web/src/components/settings/SkillsSettings.tsx index 21d2c3912f..b6a208b2bc 100644 --- a/apps/web/src/components/settings/SkillsSettings.tsx +++ b/apps/web/src/components/settings/SkillsSettings.tsx @@ -19,9 +19,11 @@ import { toastManager } from "../ui/toast"; import { SettingsPageContainer, SettingsSection } from "./settingsLayout"; import { searchableSetting } from "./settingsSearch"; import { + displayedSkillCount, filterSkillInventory, formatSkillPath, groupSkillsByHarness, + setKeyCollapsed, skillContentForDisplay, skillKey, } from "./SkillsSettings.logic"; @@ -42,12 +44,6 @@ function connectionDotClassName(phase: string): string { return "bg-muted-foreground/40"; } -function toggleKey(keys: ReadonlySet, key: string): ReadonlySet { - const next = new Set(keys); - if (!next.delete(key)) next.add(key); - return next; -} - /** Chevron that points right when collapsed and down when open. */ function DisclosureChevron({ open, className }: { open: boolean; className?: string }) { return ( @@ -159,7 +155,8 @@ function EnvironmentSkillInventory({ () => (state.status === "loaded" ? filterSkillInventory(state.inventory, query) : null), [query, state], ); - const skillCount = visibleInventory?.installations.length; + const isConnected = Option.isSome(prepared); + const skillCount = displayedSkillCount(visibleInventory, isConnected); const phase = environment.connection.phase; const isSearching = query.trim().length > 0; const open = !collapsed; @@ -198,7 +195,7 @@ function EnvironmentSkillInventory({ : null } /> - {skillCount !== undefined ? ( + {skillCount !== null ? ( {skillCount} {skillCount === 1 ? "skill" : "skills"} @@ -253,7 +250,9 @@ function SkillHarnessGroups({ rootPath={group.rootPath} skills={group.skills} open={!collapsedHarnesses.has(group.key)} - onToggle={() => setCollapsedHarnesses((keys) => toggleKey(keys, group.key))} + onOpenChange={(nextOpen) => + setCollapsedHarnesses((keys) => setKeyCollapsed(keys, group.key, !nextOpen)) + } /> )); } @@ -264,14 +263,14 @@ function SkillHarnessGroup({ rootPath, skills, open, - onToggle, + onOpenChange, }: { harnessDisplayName: string; harness: SkillInventoryInstallation["harness"]; rootPath: string | null; skills: ReadonlyArray; open: boolean; - onToggle: () => void; + onOpenChange: (open: boolean) => void; }) { const panelId = useId(); const HarnessIcon = PROVIDER_ICON_BY_PROVIDER[harness] ?? null; @@ -282,7 +281,7 @@ function SkillHarnessGroup({ type="button" aria-expanded={open} aria-controls={open ? panelId : undefined} - onClick={onToggle} + onClick={() => onOpenChange(!open)} className="flex w-full min-w-0 cursor-pointer items-center gap-2 rounded-lg py-1.5 pl-7 pr-3 text-left transition-colors hover:bg-muted/25 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset sm:pl-8 sm:pr-4" > @@ -300,7 +299,7 @@ function SkillHarnessGroup({ ) : null} - + {skills.map((skill) => (