Skip to content

feat: add a collapse all folders action to the sessions sidebar - #31330

Merged
bolichen97 merged 1 commit into
mainfrom
fix/11553-collapse-all-folders
Nov 8, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/11553-collapse-all-folders

Conversation

@bolichen97

@bolichen97 bolichen97 commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Let someone close every folder in the sessions sidebar with one click, so a grown folder tree can be reset and only the branch they need reopened.

The sessions sidebar has no single action that collapses every folder. Each folder has to be closed through its own disclosure, so the cost of resetting the tree grows with every folder added, which hits hardest the people who use nested folders the most.

Builds on #16035 by @tim-finnigan.

Why it matters

People who route their work through nested folders end up with a tall sidebar of mostly irrelevant context. Today the reset is manual and gets longer as the tree grows, so the folder tree becomes less useful the more it is used.

Not a goal

  • Collapse all but the active branch. This closes everything, the branch holding the open session included; opening a session or a folder reveal still reopens its branch.
  • Expand all, or restoring the tree's earlier shape.
  • The board view's per-column collapse state. Board columns keep their own collapse choices in the browser, so the action is offered in the folder tree view only.
  • Any change to folder order, visibility, ownership or membership.

What changed (motivation → approach → change)

Folder collapse state is stored on the server, one folder per PATCH /api/chat/folders/{id}. Done that way, a collapse-all would be one request per open folder, which can fail halfway and leave the tree half closed, and writes one audit line per folder.

So the reset is one write. A new route, POST /api/chat/folders/collapse-all, sets collapsed on every folder in a single pass under the folder-store lock, the same all-or-none shape as POST /api/chat/folders/reorder. It changes nothing else, and collapsed stays a layout field, so it never claims a folder an agent created. An app caller is refused (folder_collapse_all_forbidden), because through PATCH an app may collapse only the folders it owns; a crew member is already refused at the chat gate.

In the sidebar, the header ⋮ menu gains Collapse all folders, next to Clean up empty folders. It shows in the folder tree view while at least one folder is open. The click closes the tree at once in the cached list and sends that one request; if the request fails, the error notice says so and the refetch redraws what the server holds. Offline it closes the cached tree and sends nothing, the same as a single folder's toggle. The dashboard spec and feature map name the route and the menu item.

Part Where
the route, registered beside reorder and cleanup dashboard/chat_folders_routes.py, dashboard/routes/sessions.py
the client method api/client/chatOrganization.ts
the menu item chat-sidebar/SidebarHeader.tsx
the one-request write and its offline path chat-sidebar/folders.ts
the label, in every catalog i18n/locales/en.json and each other locale (pages.chatSidebar.collapse_all_folders)

Backwards compatibility

Compatible: one new route and one new menu item. No existing route, stored field or behaviour changes.

Removes nothing: the diff adds a route, a client method, a menu row and a string, and takes nothing away.

Tests

  • test/test_chat_folder_collapse_all.py: one request closes every folder in exactly one store write, leaving every other field (order, parent, owner, the agent-created mark) unchanged; an app caller gets 403 and nothing is written.
  • website/src/test/ChatSidebar.collapseAllFolders.test.tsx: the header menu item closes the tree and sends exactly one collapse-all request, never a per-folder PATCH.
  • website/src/test/ApiClient.refactor.surface.test.ts: the new client method takes its place in the method order.

Determinism: the backend file passed 20 runs at -n0, then 10 runs at -n 4 --dist loadgroup --max-worker-restart=2 beside test_chat_folder_reorder_atomic.py and test_chat_folder_cleanup.py, and a shuffled order with seed 27021. The vitest file passed 5 runs with --sequence.shuffle, seeds 27022 to 27026, beside ChatSidebar.flatFolderFilter.test.tsx.

Manual verification

Ran this change at commit 056101c4d4 (the same diff as this head, one rebase onto main earlier; main has changed no sidebar file since) as an isolated gateway on loopback, with a throwaway data home seeded from the rich fixture plus a few folders, one of them nested, and drove it with scripted Playwright. Opened the header ⋮ menu and picked Collapse all folders. The browser sent exactly one POST /api/chat/folders/collapse-all and no per-folder PATCH, GET /api/chat/folders then reported every folder collapsed, and the menu opened again no longer offered the item. Dark and light themes below.

Screenshots / video

All taken from 056101c4d4 against that gateway.

The header ⋮ menu while a folder is open: Collapse all folders sits between Clean up empty folders… and Switch all to model… (dark, light).

Header ⋮ menu with Collapse all folders, dark
Header ⋮ menu with Collapse all folders, light

The folder tree before and after the click (dark):

Folder tree before Collapse all folders, dark
Folder tree after Collapse all folders, dark

Before and after the click (light)

Folder tree before Collapse all folders, light
Folder tree after Collapse all folders, light

The same menu once every folder is closed: the item is no longer offered, because there is nothing left to collapse. There is no Expand all (see Not a goal); each folder still opens from its own disclosure (dark, light).

Header ⋮ menu once every folder is closed, no Collapse all folders, dark
Header ⋮ menu once every folder is closed, no Collapse all folders, light

Related Issues

Closes #11553

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributed under the project's Apache-2.0 license.

@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners November 6, 2026 10:13
@bolichen97
bolichen97 requested a review from Zedmor November 6, 2026 10:13
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 2a90c1d8c0f47f3154d4e3c446922a1bfe39f783 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks. Issue #11553 is the record for this new menu item. The one-write route is the smallest way to avoid a tree left half closed. One response field has no reader.

Notes

  • Item 2 — zero consumers: the route answers {ok, count}, but the only caller (collapseAllChatFolders: () => post(...).then(j) in chatOrganization.ts) never reads count. Only the test does. Subtraction: drop count from the response and return {ok: True}, the same as reorder does.

What this change ships

Inventory (5 items) — 4 justified

Intent: let a person close every sidebar folder in one click and then reopen only the branch they need. This is an ADDITION.

  1. The sidebar header ⋮ menu gains Collapse all folders. It appears in the tree view only, and only while some folder is open. — justified
  2. New route POST /api/chat/folders/collapse-all sets every folder's collapsed state in one write. It answers {ok, count}, and nothing reads count. — zero consumers (for count)
  3. App callers get a 403 with folder_collapse_all_forbidden, and the refusal is audited. — justified
  4. Offline, the click closes the cached tree and sends nothing. — justified
  5. The label is added to every locale catalog, and the feature map and spec rows are updated. — justified

[FIRST-PRINCIPLES-REVIEWED] 2a90c1d

Description read

[DESCRIPTION-READ] ce6cef5c0b136215709798f2a54727f8537733014ee20fac8ed2b5fc5ee425ef

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 2a90c1d8c0f47f3154d4e3c446922a1bfe39f783 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the change only adds things, does the collapse in one atomic write the same way reorder and cleanup do, and has screenshots for this revision.

[DESIGN-REVIEWED] 2a90c1d

Description read

[DESCRIPTION-READ] b7e32c33764d0f105accc810595128feb82be494985a0ca9ea1603140ef981b6

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS

UX-level review of 2a90c1d8c0f47f3154d4e3c446922a1bfe39f783 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

UX-Verdict: PASS

Nothing blocks. The blind reader read "Collapse all folders" correctly and said they would click it. Both themes are shown, before and after the click and with the item hidden.

Notes

  • SidebarHeader.tsx: the item is hidden when every folder is already closed. The blind reader "can't tell why 'Collapse all folders' shows up in shots 1 and 2 but not in shots 7 and 8." Keeping the row visible but disabled in that state would keep the menu's shape the same each time it opens and show that the action exists.

[UX-REVIEWED] 2a90c1d

Description read

[DESCRIPTION-READ] 2b4cfa38edd3d8dfdde9d05815f223417e06f7017b7057a382e5b50d1ae7dcef

That sha256 names everything this verdict read: the PR description, plus the 11 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 2a90c1d8c0f47f3154d4e3c446922a1bfe39f783 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 2a90c1d

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 2a90c1d8c0f47f3154d4e3c446922a1bfe39f783 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 2a90c1d8c0f47f3154d4e3c446922a1bfe39f783 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 2a90c1d

Verdict parsed from the review's SHA-scoped output markers for commit 2a90c1d8c0f47f3154d4e3c446922a1bfe39f783.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 2a90c1d8c0f47f3154d4e3c446922a1bfe39f783 false-positive: <reason, 20 to 500 characters>

@bolichen97
bolichen97 enabled auto-merge (squash) November 6, 2026 10:43
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 6, 2026
@bolichen97
bolichen97 force-pushed the fix/11553-collapse-all-folders branch from 56bb06b to 8eb5824 Compare November 6, 2026 15:05
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 6, 2026
@bolichen97
bolichen97 force-pushed the fix/11553-collapse-all-folders branch from 8eb5824 to 7f694f0 Compare November 6, 2026 15:51
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 6, 2026
@bolichen97
bolichen97 force-pushed the fix/11553-collapse-all-folders branch from 7f694f0 to 736a885 Compare November 6, 2026 18:33
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Nov 6, 2026
@bolichen97
bolichen97 force-pushed the fix/11553-collapse-all-folders branch from 736a885 to 7d16a42 Compare November 6, 2026 20:25
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 7, 2026
@bolichen97
bolichen97 force-pushed the fix/11553-collapse-all-folders branch from 086f569 to bbbb46e Compare November 7, 2026 14:00
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Rebased: main moved in the line-budget and platform collect-ignore tests (fixed on main by #32252 and #32209) since this head went red (eaf86e9 -> f58c3cf); CI re-running. The patch is unchanged (git range-diff shows the same commit); changed backend and frontend tests, flake8, isort, mypy and tsc pass locally, and local GPT and Opus reviews of bbbb46e passed.

AI-assisted, posted on behalf of bolichen97

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention labels Nov 7, 2026
buluoray
buluoray previously approved these changes Nov 7, 2026

@buluoray buluoray left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 Kiro Crew Auto-Pipeline [operator: buluoray]:

APPROVE at bbbb46e.

What it does for users: the sessions sidebar's header ⋮ menu gains "Collapse all folders". It appears in the folder tree view while any folder is open and closes the whole tree in one click. Before this, each folder had to be closed through its own disclosure. Nothing existing changes. The only other collapse-all strings in the catalog belong to a different surface, so this does not duplicate a sidebar control (issue #11553 asks for it).

Evidence:

  • Route (chat_folders_routes.py:1194-1242): one mutate_folders pass flips only collapsed on the folders that are open. It pushes a slots update only when something changed and writes one audit line with the count. Like the reorder route, the literal path is registered before the "{id}" delete (routes/sessions.py:116-117).
  • Caller fence: the route first runs _refuse_unattributable_caller, then refuses any non-person principal with 403 folder_collapse_all_forbidden. folder_principal (dashboard caller module, lines 960-985) returns a value for both app and crew-member callers, so the docstring's "an app or crew member is refused" is accurate. This matches PATCH, through which an app may collapse only folders it owns.
  • Client (folders.ts:506-529): the cached tree closes optimistically, the request goes out once, and a failure shows the error notice and refetches. Offline, the cached tree closes and nothing is sent, the same as the single-folder toggle. The menu item is hidden in the board view, whose per-column collapse overrides this write does not clear (SidebarHeader.tsx:109-115).
  • The label is present in all 13 locale catalogs. The dashboard spec row and the feature map name the menu item and the route in the same commit.

Mutation: the principal refusal changed to if False. Result: test_an_app_is_refused_and_nothing_is_written goes red; restored and the tree checked clean.

Tests: test_chat_folder_collapse_all plus test_chat_folder_reorder_atomic gave 24 passed. ChatSidebar.collapseAllFolders.test.tsx plus ApiClient.refactor.surface.test.ts gave 188 passed.

CI at this head: 82 success, 11 skipped, 1 failure. The failure is Sensitive Change Review, which could not read the PR from the API ("API rate limit exceeded for installation"). That is an infrastructure failure, not a finding, and the check needs a re-run. PR Readiness and both CodeBuild statuses are success. The GPT, Opus, Design, UX and First Principles lanes all report PASS or no findings. It merges cleanly with main.

Source-only: the light and dark rendering, judged from the screenshots in the description.

Follow-ups (non-blocking):

  • The test refuses only an app caller. A crew-member caller is refused by the same principal check and by the chat gate, but no test pins the member arm of this route.
  • The single-folder toggle in the list view keeps a pinned sticky header in place (armHold). Collapse-all does not, so the list may jump when a pinned header's folder closes. This is cosmetic and not a regression.

@github-actions github-actions Bot added merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running and removed readiness: passed Eligible automated validation passed for the current revision labels Nov 7, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

HOLD at bbbb46e.

This head conflicts with main. GitHub reports it as CONFLICTING, and a local merge against 0850c67 conflicts in docs/system-specs/modules/learn-cron-dashboard.md, which main has since edited. Please rebase. A new head needs a fresh review.

The PR also adds a new route, POST /api/chat/folders/collapse-all (sessions.py#L117), with its own caller check (chat_folders_routes.py#L1194-L1242). Under our sensitive-change rule, a human must sign off on that. I found no defect: unattributable callers and app callers are refused, the refusal is audited, and the single store pass changes only collapsed. On this head, Sensitive Change Review failed on a GitHub API rate limit and never reached a verdict, so it needs a re-run after the rebase.

Non-blocking UX notes: the open chat is hidden once its folder closes, which the description lists as not a goal, and no screenshot shows the menu once every folder is closed.

— crew-pr-reviewer (r149)

@bolichen97

Copy link
Copy Markdown
Contributor Author
  • Note: no screenshot shows the menu once every folder is closed

fixed in bbbb46e (description only, no code change): the description now shows the header ⋮ menu once every folder is closed, dark and light, and Collapse all folders is not in it.
All eight screenshots were taken again from bbbb46e, against an isolated gateway on loopback, and replace the earlier set: the menu with the item, the tree before and after the click, and the menu with every folder closed.
Leaving the item out there is deliberate: it is drawn only while folders.some(f => !f.collapsed) holds, so with nothing open there is nothing to collapse. Expand all is under Not a goal, and each folder still opens from its own disclosure.
This also answers the same note in #31330 (comment).

[operator: bolichen97]

A grown folder tree could only be reset one disclosure at a time. The
sidebar header menu now offers "Collapse all folders" in the folder
tree view while any folder is open. It sends one request to a new
POST /api/chat/folders/collapse-all route, which closes every folder in
a single folder-store write, so the tree is never left half closed and
nothing else on a folder changes. An app is refused, since through
PATCH it may collapse only the folders it owns.

Closes #11553
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in docs/system-specs/modules/learn-cron-dashboard.md since this head went green (f58c3cf -> 6d07df1); CI re-running. That file had a merge conflict: main edited the paragraph next to the one this PR changes. Main's paragraph is kept as is, and this PR's added and removed lines are byte-identical to the reviewed head bbbb46e194.

[operator: bolichen97]

@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Answering the HOLD at bbbb46e194, point by point:

  • Conflict: rebased onto main; the head is now 2a90c1d8c0, which merges cleanly. Its own added and removed lines match bbbb46e194 byte for byte (see the Rebased: note above).
  • Sensitive change sign-off on POST /api/chat/folders/collapse-all: that needs a maintainer other than me, so it stays open for one.
  • Sensitive Change Review rate-limit failure: the new push re-runs it on 2a90c1d8c0.
  • The open chat is hidden once its folder closes: kept. Not a goal lists it ("this closes everything, the branch holding the open session included"), and opening a session or revealing a folder reopens its branch.
  • No screenshot of the menu once every folder is closed: included. The description has it in dark and light, re-captured for this change.

@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] On the review's first follow-up (no test pins the crew-member arm of POST /api/chat/folders/collapse-all): keeping the code and the test set as they are.

The member arm is not a separate branch. The handler refuses on one condition, if principal: after folder_principal(state, request) (dashboard/chat_folders_routes.py, api_chat_folders_collapse_all), and folder_principal returns a non-empty value for an app caller and for a crew-member caller alike, as the review notes. test_an_app_is_refused_and_nothing_is_written drives that branch and checks the 403 and that nothing is written, and the review's own mutation (if False) turned it red. A crew member is also stopped earlier, at the chat gate, before this handler runs. A second test would exercise the same line through a different principal string, so it is left out under the one-test-per-finding rule.

@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] On the review's second follow-up (collapse-all does not arm the pinned sticky-header hold the single-folder toggle uses): keeping it as is.

The hold (armHold in chat-sidebar/stickyCollapse.ts, armed from toggleListFolderCollapse in folderBlocks.tsx) keeps the header the person just clicked painted where it was while that one folder closes. Collapse-all is picked from the sidebar header ⋮ menu, not from a folder header, so there is no clicked header to hold in place, and the lane shrinks to its top-level folder rows. As the review says, it is cosmetic and not a regression; a scroll anchor for the bulk action would be new scope this PR's goal does not need.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Nov 8, 2026

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approving. On this head the review read the full diff and checked four things. The new POST /api/chat/folders/collapse-all route runs as one mutate_folders transaction that changes only collapsed. The store write is confirmed before the slots update is pushed, and nothing is written when no folder is open. The frontend mutation shares CHAT_FOLDERS_WRITE_KEY with the single-folder toggle. The menu row shows only in tree view. The backend test drives the real FolderRepository.mutate and asserts one write with every other field unchanged. The vitest test asserts one bulk request and no per-folder PATCH. Done well: the route reuses the existing folder guards instead of adding new ones, and it is hidden in board view, where per-column collapse state would make a global write wrong.

Security: the route first refuses an unattributable caller. It then refuses any app or crew member principal with a 403 and writes a SEL event for both the allowed and the denied outcome. The person and agent callers it admits could already set collapsed on any folder one at a time through PATCH, because it is a layout-only field. So the route grants no new authority and cannot claim an agent-created folder.

Optional:

  • Add a test for the _refuse_unattributable_caller line (POST with X-Session-Key: dashboard:chat-1-100 and empty _slots, expect 403 caller_unattributable and no write). Every sibling folder write has this test.
  • A crew member is refused at the chat gate today only because collapse-all parses as a folder id that admits PATCH alone. Adding collapse-all to the reserved-literal tuple in _shared_route_guards.py, or a row in test_member_chat_folders_gate.py, would pin that.
  • count in the response has no reader. Returning {"ok": True} like reorder would keep the contract smaller.

@bolichen97
bolichen97 merged commit 4f41224 into main Nov 8, 2026
141 of 155 checks passed
@bolichen97
bolichen97 deleted the fix/11553-collapse-all-folders branch November 8, 2026 16:27
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 8, 2026
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.

Sessions sidebar: no way to collapse every folder at once, so a deep folder tree can only be reset by hand

4 participants