Skip to content

fix(sidebar): keep worktree row ordered after closing a chat - #65

Merged
enisze merged 1 commit into
mainfrom
feature/keep-sidebar-order-on-chat-close
Aug 20, 2026
Merged

fix(sidebar): keep worktree row ordered after closing a chat#65
enisze merged 1 commit into
mainfrom
feature/keep-sidebar-order-on-chat-close

Conversation

@enisze

@enisze enisze commented Aug 20, 2026

Copy link
Copy Markdown
Owner

Problem

In the sidebar, a worktree's chats collapse into a single row positioned by the worktree's newest surviving chat (collapsing keeps the group at that chat's slot). Closing (archiving) the newest chat dropped it from the list, so the row fell back to an older sibling's timestamp and sank down the sidebar — even though closing a chat is itself a recent interaction. The bottom-right/ordering no longer reflected that the worktree was just touched.

Fix

Treat closing a chat as worktree activity and factor it into the sort:

  • Persisted client store: added worktreeLastActivityAtByKey to useUiStateStore (localStorage-backed, sanitized on load like threadLastVisitedAtById), keyed by the same environmentId\0worktreePath key the collapse uses. New markWorktreeActive reducer advances the timestamp (never moves it backwards).
  • Record on close: WorktreeThreadTabs.closeTab records the interaction before archiving.
  • Sort augmentation: sortThreadsForSidebarV2 now takes the activity map and each chat's effective sort time is max(own activity, worktree recorded activity), so the collapsed row keeps its place. Local (non-worktree) chats and callers that omit the map are unchanged.

Tests

  • uiStateStore.test.ts: markWorktreeActive monotonicity + guards; persistence/parse round-trip includes the new field.
  • Sidebar.logic.test.ts: a surviving chat is lifted above a more-recently-active chat in another worktree once its worktree's close activity is recorded.

Typecheck clean, targeted unit tests pass (132), lint clean for changed files.

🤖 Generated with Claude Code

A worktree's collapsed sidebar row is positioned by its newest surviving
chat — collapsing keeps the group at that chat's slot. Closing (archiving)
the newest chat dropped it from the list, so the row fell back to an older
sibling's timestamp and sank down the sidebar, even though closing a chat
is itself a recent interaction.

Record closing a chat as worktree activity in a persisted client store
(`useUiStateStore.worktreeLastActivityAtByKey`, keyed by the same
environment+worktree key the collapse uses) and fold that timestamp into
the sidebar sort: each chat's effective sort time is the max of its own
activity and its worktree's recorded activity. The row now keeps its place
instead of sinking. Local (non-worktree) chats and callers that omit the
map are unaffected.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@enisze
enisze merged commit 8aa550c into main Aug 20, 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.

1 participant