Skip to content

refactor(studio): move the last two hand-rolled disclosures to Collapsible - #2367

Merged
peppescg merged 6 commits into
mainfrom
refactor/studio-collapsible-disclosures
Oct 19, 2026
Merged

peppescg merged 6 commits into
mainfrom
refactor/studio-collapsible-disclosures

Conversation

@peppescg

@peppescg peppescg commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Stack note: this was stacked on #2352 (merge after it). #2352 merged while this was in progress, so the branch is rebased onto main and targets main; there is nothing left to merge first.

Summary

Moves the last two hand-rolled disclosures to the Collapsible primitive that #2352 added: the Memory card's "Show current values" <details>, and a turn's tool-call toggle in the transcript. Neither gains a heading or a region (the reason kantord gave on #2334 for Collapsible over Accordion). Both keep their closed content findable with the browser's find-in-page. Every captured state is pixel-identical to main.

Part of #2340
Part of #2201
Part of #2210

What changed

  • components/ui/collapsible.tsx: CollapsibleContent hiddenUntilFound. Closed content stays in the document as hidden="until-found" instead of unmounting, and a beforematch event (fired by the browser just before it reveals a find-in-page match) opens the collapsible. Three things in the stack made this need code rather than a prop:

    • Radix exposes no hook into its open state. Collapsible now keeps the state itself (uncontrolled through defaultOpen, or controlled through open and onOpenChange, the same API as before) and shares it with the content.
    • Radix's content drops its children while closed unless it is force-mounted, so hiddenUntilFound forces forceMount.
    • React 19.3 writes hidden as a boolean (hidden="" for any truthy value), so the attribute and the listener are set on the node.

    Closed until-found content still lays out its own box (content-visibility: hidden), so margins and padding go on its children.

  • memory/consolidate-memory-card.tsx. The <details> becomes Collapsible, CollapsibleTrigger and CollapsibleContent hiddenUntilFound. The trigger draws the same disclosure triangle <summary> drew, from an empty inside list item (list-style: disclosure-closed / disclosure-open), so the text, the marker and the spacing are unchanged.

  • chat/tool-call-list.tsx. The button with hand-set aria-expanded over a hidden list becomes a controlled Collapsible, still driven by useDetailsOpen and still held open while a call carries an ask or an authorization. The <ol> is the content (asChild) and is hidden until found. Its top margin applies only when open.

Behaviour differences

  • Tool calls: more of the closed list is findable. On main, the closed list was hidden, so find-in-page reached only the tool names in the toggle. Now it also reaches each call's arguments and result, and a match opens the list. This is intended: it is what refactor(studio): use Label for the settings switch labels (#2201 group B) #2359 kept the hand-rolled list for.
  • Memory: the trigger is a <button>, not a <summary>. It is reached and operated the same way (Tab, Enter, Space, pointer), and now reports aria-expanded. It also reports aria-controls, but only while open: Radix's trigger (@radix-ui/react-collapsible 1.1.21) sets "aria-controls": context.open ? context.contentId : undefined, even though the force-mounted content keeps its id while closed.
  • Tool calls: the toggle gains aria-controls while open (Radix omits it while closed, as above), plus Radix's data-state on the toggle and the list.
  • Closed content is still out of the accessibility tree: Chromium leaves hidden="until-found" content out of its accessibility tree, as it does a closed <details> (checked with Accessibility.getFullAXTree).

No visible difference.

No regression

  • Pins first (11a1d5468), passing on the old code and on the head:

    • consolidate-memory-card.pinning.test.tsx (5), reusing the Memory pins from the earlier refactor(studio): use the Tabs and Toggle primitives in two hand-rolled controls #2334 branch: each change has its own closed disclosure; click opens and closes it with the kept and merged-in values; placeholders for an unnamed or empty memory; the closed values stay in the document; no heading or region, closed or open.
    • tool-call-list.pinning.test.tsx (4): one button named by its summary; the closed rows stay in the document but hidden, with the names in the toggle; pointer, Enter and Space toggle it; no heading or region.
    • e2e/memory-consolidation.spec.ts (3 × desktop and 390px): keyboard reach and toggling; find-in-page: window.find reaches three closed values, and a text-fragment navigation (#:~:text=, which runs the browser's own find-in-page match and fires beforematch) reveals the matched change and only that one, after which one press of its trigger closes it; no heading or region.
    • e2e/tool-call-list.spec.ts (3 × 2): keyboard toggling; the tool names stay findable with window.find; no heading or region.
  • New behaviour, failing on the old code:

    • e2e/tool-call-list.spec.ts: "find-in-page reaches a closed list's arguments and opens the list". Against the hand-rolled list, window.find returns false.
    • collapsible.test.tsx (+2): closed content is hidden="until-found" and opens on beforematch; a controlled owner is asked to open.
  • Modified test, justified: one test in consolidate-memory-card.test.tsx found the content through closest("details"). It now finds it through the trigger's aria-controls, after checking aria-expanded, with the same four content assertions. No assertion was removed or weakened. transcript-alignment.test.tsx passes unmodified.

  • Mutation proof, each mutation applied alone:

    Mutation Failing tests
    Memory content without hiddenUntilFound (Radix unmounts it) 1 unit and 1 e2e (find-in-page)
    Tool list without hiddenUntilFound 2 unit and 1 e2e
    No beforematch listener 2 unit and 2 e2e (Memory: the text shows but the trigger stays closed)
    Plain hidden instead of until-found 2 unit and 2 e2e (window.find false)
    Memory trigger out of the tab order 1 e2e (keyboard)
    Tool list ignores onOpenChange 2 unit and 3 e2e
  • Pixels: 20 states (Memory closed, open and focused; tool calls closed, open and focused, at desktop and 390px, light and dark), each captured twice per tree. All 20 are identical to main, or differ only inside the noise floor of a second main capture (6 px of the top bar on a phone, 13 px of focus-ring corner antialiasing). Box geometry matches too. pixel-report.txt has the counts.

Screenshots

Before is origin/main (8cc7c2347), After is this branch (8b2328ce3), and Prototype is stack-08. Red boxes would mark Before/After differences; there are none.

Memory, two suggested changes, values closed (identical to Before; matches the prototype's Consolidate memory card styling; the prototype has no suggestion fixture, so its column is the Memory page)

memory-closed-desktop-light

Memory, two suggested changes, values closed: desktop dark and 390px, light and dark

memory-closed-desktop-dark:

memory-closed-desktop-dark

memory-closed-mobile-light:

memory-closed-mobile-light

memory-closed-mobile-dark:

memory-closed-mobile-dark

Memory, first change's current values open (identical to Before; prototype column as above)

memory-open-desktop-light

Memory, first change's current values open: desktop dark and 390px, light and dark

memory-open-desktop-dark:

memory-open-desktop-dark

memory-open-mobile-light:

memory-open-mobile-light

memory-open-mobile-dark:

memory-open-mobile-dark

Memory, keyboard focus on Show current values (desktop) (identical to Before; same focus ring as <summary>)

memory-focus-desktop-light

Memory, keyboard focus on Show current values (desktop): desktop dark

memory-focus-desktop-dark:

memory-focus-desktop-dark

Transcript, tool-call group closed (identical to Before; matches the prototype's closed Activity row)

tools-closed-desktop-light

Transcript, tool-call group closed: desktop dark and 390px, light and dark

tools-closed-desktop-dark:

tools-closed-desktop-dark

tools-closed-mobile-light:

tools-closed-mobile-light

tools-closed-mobile-dark:

tools-closed-mobile-dark

Transcript, tool-call group open (identical to Before; matches the prototype's open Activity rows)

tools-open-desktop-light

Transcript, tool-call group open: desktop dark and 390px, light and dark

tools-open-desktop-dark:

tools-open-desktop-dark

tools-open-mobile-light:

tools-open-mobile-light

tools-open-mobile-dark:

tools-open-mobile-dark

Transcript, keyboard focus on the Activity toggle (desktop) (identical to Before; prototype column is the closed transcript)

tools-focus-desktop-light

Transcript, keyboard focus on the Activity toggle (desktop): desktop dark

tools-focus-desktop-dark:

tools-focus-desktop-dark

Gates

On the head rebased onto main (43c1a02c8; main has since gained only #2357, in an unrelated learning file):

  • task studio:check: passed. Web 1624 tests in 190 files, server 252 tests in 27 files.
  • task studio:browser: passed. 150 passed, 38 skipped.

Before the rebase, on #2352's head, the same gates passed with web 1514 in 177 files (#2352 reported 1503 in 175; +11 here) and browser 138 passed (124 on #2352; +14 here).

Review changes

Addresses kantord's review of 8b2328ce3. Two commits on top, no rebase:

  • 7966befd0 fix(studio): open a Collapsible only for a match in its own content. In components/ui/collapsible.tsx:
    • The beforematch listener returns unless event.target is its own content node. beforematch bubbles, so a match inside a nested hidden-until-found Collapsible used to ask the outer one to open too, and a toggle-style owner such as the tool-call list (onOpenChange={toggleExpanded}) would close an already open list.
    • setOpen returns when the requested value equals the current one, so onOpenChange is never called for a no-op, as with Radix's own state.
    • The CollapsibleContent JSDoc states the controlled-owner contract: an owner must accept the onOpenChange(true) a match sends, because the browser has already removed hidden; an owner that keeps open false leaves the content visible with aria-expanded="false".
  • 51e66b09c fix(studio): align the Memory change trigger to the start. text-left becomes text-start, as <summary> aligned. Left-to-right rendering is unchanged (0 changed pixels below).
  • PR body: the aria-controls sentences now say what Radix 1.1.21 emits: the trigger sets aria-controls only while open. The earlier "when open" wording was accurate; it now cites the source.

No consumer changes behaviour: failed-turn-card, reasoning-disclosure and proposal-row call neither path with a no-op value, and the tool-call list's trigger always requests the opposite of its current open (also when an ask holds it open), so the guard never drops a real toggle.

Tests

collapsible.test.tsx +4 (8 in total):

  • an open outer Collapsible with a toggle-style onOpenChange stays open, and its callback isn't called, when a match opens a nested one;
  • a closed outer Collapsible stays closed when a match bubbles up from a nested one (pins the target check by itself);
  • onOpenChange isn't called when a match asks an already open Collapsible to open;
  • the trigger has no aria-controls while closed and names the content once open.

The first and third failed on 8b2328ce3 before the fix. Mutation proof, each applied alone:

Mutation Failing tests
No event.target !== node check 1 (closed outer stays closed)
No next === open guard 1 (no-op setOpen)
Both removed 3 (both of the above, plus the open outer list)
Trigger always sets aria-controls 3 (including the new one)

The open-outer test passes with either guard alone, since each one stops the stray toggle; the two single-guard tests pin each fix separately.

Screenshots

Before is 8b2328ce3 (the reviewed head) and After is 51e66b09c. The fixes change behaviour only, and every state is identical: amber boxes mark the reviewed disclosure triggers, and there are no red boxes. The 20 states are the same as above (Memory closed, open and focused; tool calls closed, open and focused; desktop and 390px; light and dark). pixel-report.txt has the counts: 17 states have 0 changed pixels, and 3 dark-theme tool-call states differ by 6 or 13 px, the noise floor recorded on the original captures. The nested case can't be shown in the app, because nothing nests hidden-until-found content today. The unit tests above cover it, and the existing find-in-page e2e (memory-consolidation.spec.ts, tool-call-list.spec.ts) still passes.

Memory, values open (identical; amber marks the reviewed trigger)

memory-open-desktop-light

Memory, values open: desktop dark and 390px, light and dark

memory-open-desktop-dark:

memory-open-desktop-dark

memory-open-mobile-light:

memory-open-mobile-light

memory-open-mobile-dark:

memory-open-mobile-dark

Memory, values closed (identical; amber marks the reviewed trigger)

memory-closed-desktop-light

Memory, values closed: desktop dark and 390px, light and dark

memory-closed-desktop-dark:

memory-closed-desktop-dark

memory-closed-mobile-light:

memory-closed-mobile-light

memory-closed-mobile-dark:

memory-closed-mobile-dark

Memory, keyboard focus on Show current values (identical; amber marks the reviewed trigger)

memory-focus-desktop-light

Memory, keyboard focus on Show current values: desktop dark

memory-focus-desktop-dark:

memory-focus-desktop-dark

Transcript, tool-call group closed (identical; amber marks the reviewed trigger)

tools-closed-desktop-light

Transcript, tool-call group closed: desktop dark and 390px, light and dark

tools-closed-desktop-dark:

tools-closed-desktop-dark

tools-closed-mobile-light:

tools-closed-mobile-light

tools-closed-mobile-dark:

tools-closed-mobile-dark

Transcript, tool-call group open (identical; amber marks the reviewed trigger)

tools-open-desktop-light

Transcript, tool-call group open: desktop dark and 390px, light and dark

tools-open-desktop-dark:

tools-open-desktop-dark

tools-open-mobile-light:

tools-open-mobile-light

tools-open-mobile-dark:

tools-open-mobile-dark

Transcript, keyboard focus on the Activity toggle (identical; amber marks the reviewed trigger)

tools-focus-desktop-light

Transcript, keyboard focus on the Activity toggle: desktop dark

tools-focus-desktop-dark:

tools-focus-desktop-dark

Gates

On 51e66b09c:

  • task studio:check: passed. Web 1628 tests in 190 files, server 252 tests in 27 files.
  • task studio:browser: passed. 150 passed, 38 skipped.

🤖 Generated with Claude Code

peppescg and others added 4 commits October 15, 2026 19:05
…ible

Before the last two hand-rolled disclosures move to the Collapsible
primitive, pin what they do today, against roles, names and state, so the
same tests hold on both implementations:

- each suggested change's "Show current values" opens and closes on its
  own by click, Enter and Space, shows the kept and merged-in values, and
  keeps its closed values in the document;
- in Chromium, window.find reaches a change's closed values, and a
  text-fragment navigation (the browser's find-in-page match) reveals the
  matched change and only that one;
- a turn's tool-call toggle is one button named by its summary, opens and
  closes from the pointer and the keyboard, keeps the closed rows in the
  document but hidden, and keeps the tool names findable;
- neither disclosure adds a heading or a region.

Refs #2340
Refs #2201

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`CollapsibleContent hiddenUntilFound` keeps closed content in the document
as `hidden="until-found"` instead of unmounting it, so the browser's
find-in-page searches it, and opens the collapsible on the `beforematch`
event the browser fires before revealing a match. This is what `<details>`
gives for free.

Radix offers no hook into its open state, so `Collapsible` now keeps the
open state itself (uncontrolled through `defaultOpen`, or controlled
through `open` and `onOpenChange`, exactly as before) and shares it with
the content. Radix renders closed children only when the content is
force-mounted, and React writes `hidden` as a boolean only, so the
attribute and the listener go on the node directly.

Refs #2340
Refs #2201

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Each suggested change's "Show current values" `<details>` becomes a
Collapsible, as kantord asked on #2334: one disclosure, so no Accordion
heading or region per change. The closed values stay in the page, hidden
until found, so find-in-page still reaches them and opens the change. The
trigger draws the same disclosure triangle `<summary>` drew, from an empty
inside list item, so the text, the marker and the spacing are unchanged.

The card test named the `<details>` element; it now reads the content the
trigger controls, with the same four assertions.

Refs #2340
Refs #2201

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The hand-rolled `aria-expanded` toggle over a `hidden` list becomes a
controlled Collapsible, with no heading per tool group. The closed list
still stays in the page: it is now hidden until found rather than hidden,
so find-in-page also reaches a call's arguments and result, not only the
names in the toggle, and a match opens the list. The gap above the list
applies only when open, since closed hidden-until-found content keeps its
own box.

Refs #2340
Refs #2201

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

@kantord kantord left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking the Collapsible and hidden="until-found" route after #2334, and for the care in the wrapper: the three existing consumers (failed-turn-card, reasoning-disclosure, proposal-row) are unaffected, since open and onOpenChange are destructured so the later {...props} can't override them and asChild still flows through. I'm requesting changes for one thing in the shared primitive, plus a design question.

Requested change: the beforematch listener has no target check

The listener is attached to the content node and calls setOpen(true) (collapsible.tsx L86-L92). beforematch bubbles (the unit test dispatches it with bubbles: true, collapsible.test.tsx L74). If a closed hiddenUntilFound Collapsible ever sits inside an open one, a match in the inner one reaches the outer listener and calls the outer setOpen(true).

For the tool-call list that is worse than a no-op: it passes onOpenChange={toggleExpanded} (tool-call-list.tsx L186), and toggleExpanded flips state and ignores its argument (use-details-open.ts L25-L27). The bubbled event would close an already-open list, hiding the text the user just searched for. Nothing nests hiddenUntilFound content today, so this is latent, but it is a trap in a shared primitive.

Suggested change: if (event.target !== node) return; in the listener. A closely related fix is in setOpen itself (L21-L28): it calls onOpenChange even when the value doesn't change, which Radix's own state would not. An if (next === open) return; keeps toggle-style callers safe. A unit test for the nested case would pin it.

Question for the author (not a request)

The wrapper is about 60 lines, plus a CSS list-marker hack on the Memory trigger (consolidate-memory-card.tsx L408-L416), all to recover find-in-page that a native <details> already gave for free, and only in browsers that support hidden="until-found". Given the repo's "simplest thing that solves the problem" guidance, what does moving the Memory card off <details> buy beyond a uniform primitive? I'm asking, not asserting, because I don't think it's a defect, but I'd like the reasoning written down.

Smaller points, not blocking

  • If a controlled owner ignores setOpen(true), the browser has already removed hidden, open stays false, and the layout effect (L79-L84) never re-applies until-found. The result is visible content with aria-expanded=false. Probably fine as a documented contract; worth a line in the JSDoc.
  • The Memory trigger hard-codes text-left (L409), where <summary> aligned to the start. text-start would keep RTL behaviour; I found no RTL support in the app, so this is minor.
  • The unit test only proves the wiring with a synthetic event. The real find-in-page coverage is Playwright, and the configured projects are Chromium only (playwright.config.ts), so Firefox and WebKit behaviour is untested. The window.find plus #:~:text= approach may be flaky; I did not run it.
  • The PR body says aria-controls appears "when open"; I believe Radix emits it unconditionally, and with force-mount the id always resolves, so the code is fine and the sentence is just inaccurate.
  • The "pixel-identical" and "closed content is out of the accessibility tree" claims rest on the author's captures; I couldn't check them.

I read the code and CI only and didn't run the app or the tests.

Fully or partially written by an AI agent.

peppescg and others added 2 commits October 16, 2026 21:29
`beforematch` bubbles, so a find-in-page match inside a nested
hidden-until-found Collapsible also reached the outer listener and asked
the outer one to open. With a toggle-style `onOpenChange`, such as the
tool-call list's, that closed an already open list.

The listener now ignores events whose target is not its own content
node, and `setOpen` no longer reports a request that changes nothing,
as Radix's own state does. The JSDoc documents that a controlled owner
must accept the `onOpenChange(true)` a match sends.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`<summary>` aligned to the start of the line; `text-start` keeps that
for right-to-left text, where `text-left` would not. Left-to-right
rendering is unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
peppescg added a commit that referenced this pull request Oct 16, 2026
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

@kantord kantord left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick follow-up. I read the new commits against my requests and they are resolved:

  • beforematch now ignores events from nested content (event.target !== node), and setOpen only reports real changes, so a toggle-style onOpenChange can't flip on a no-op.
  • The controlled-owner contract is now written in the JSDoc.
  • The Memory trigger uses text-start.

Approving. My one open question, what moving the Memory card off native <details> buys beyond a uniform primitive, is still unanswered, so a line in the PR description would be good, but it doesn't block. I read the diff and CI only and did not run the app or the tests.

Fully or partially written by an AI agent.

@peppescg
peppescg merged commit 3816f08 into main Oct 19, 2026
31 checks passed
@peppescg
peppescg deleted the refactor/studio-collapsible-disclosures branch October 19, 2026 08:57
@toolhive-release-app toolhive-release-app Bot mentioned this pull request Oct 20, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants