Repository navigation
Unsloth Studio / Desktop: number chat turns and add a pinned turn navigator - #11668
mahiatlinux wants to merge 46 commits into
Conversation
Adds an opt-in "Turn navigation" setting under Settings > Chat. When on, each user message shows a "Turn N" label, turns can be pinned from the user action bar or the reply's More menu, and a rail on the right edge of long chats jumps to any turn with a hover preview of its prompt. Turn numbers come from one pass per message array (thread-turns.ts), so a streamed token or keystroke costs each message an O(1) lookup. Pins are kept per chat in localStorage, like pinned chats.
This comment has been minimized.
This comment has been minimized.
…gator # Conflicts: # studio/frontend/src/components/assistant-ui/thread.tsx # studio/frontend/src/features/chat/stores/chat-preferences-store.ts # studio/frontend/src/features/settings/tabs/chat-tab.tsx # studio/frontend/src/i18n/locales/ar.ts # studio/frontend/src/i18n/locales/de.ts # studio/frontend/src/i18n/locales/en.ts # studio/frontend/src/i18n/locales/es.ts # studio/frontend/src/i18n/locales/fr.ts # studio/frontend/src/i18n/locales/hi.ts # studio/frontend/src/i18n/locales/it.ts # studio/frontend/src/i18n/locales/ja.ts # studio/frontend/src/i18n/locales/ko.ts # studio/frontend/src/i18n/locales/pt-br.ts # studio/frontend/src/i18n/locales/ru.ts # studio/frontend/src/i18n/locales/zh-CN.ts
Dashes rest at 8px and the hovered one widens with its three neighbours on either side tapering off, while every dash thins. The card beside the rail shows the prompt on one line, the reply's opening lines and a pin toggle.
The hovered dash now reaches 20px instead of 34px, with the neighbours tapering 16, 12 and 10px, and the card moves in to sit beside it.
Pinning a turn is now bookmarking it everywhere: the action bar, the More menu, the turn label and the rail card show a bookmark that fills once set, and the strings, store, storage key and components are renamed to match, so it no longer reads like pinned chats. The dashes are 4px pills, thinning to 3px on hover, so their rounded ends show.
78d920a to
c229c6f
Compare
This comment has been minimized.
This comment has been minimized.
The rail was gated on a 52rem thread width, which only leaves a free gutter for the standard chat width. With the wide or full chat width the message column reaches the viewport edge and the rail sat over bubbles and their action bars, taking their clicks. Show it only when the gap beside the column fits it; the standard width keeps the same threshold. Also tighten comments and make the turn-signature test cover a same-count branch switch and an appended reply step.
This comment has been minimized.
This comment has been minimized.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dbc4223ca8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (hasPendingProgressiveMounts()) { | ||
| waitForSettle(); | ||
| return; | ||
| } |
There was a problem hiding this comment.
Wait for history to arrive before settling the turn index
On a cold persisted-thread open—especially in Safari/WebKitGTK, where scheduleIdleTask uses its 120 ms fallback—the history can still be loading with zero messages when this callback runs. hasPendingProgressiveMounts() is then false, so this marks the index settled permanently; when a long history subsequently arrives and starts progressive mounting, the rail creates all of its markers and the labels publish during that load rather than after it, reintroducing the switch-time DOM work this gate is intended to defer. Account for the thread's loading state (and reset settling when mounting begins) before setting settled.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Declined. This changes when the work happens, not what renders: the label box is mounted before its number fills in and the rail renders nothing under 5 turns, so a cold open that settles early shows the same labels and rail as one that settles late. The gate targets switches between loaded chats, where the messages are already in the runtime and the mounts are pending when the idle callback runs. Studio exposes no per-thread history loading flag to wait on, and the alternative, unsettling when a batch arrives, would blank labels that are already showing.
| if (Math.abs(offset) < 1) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
Keep polling alignment for the requested frames
When the initial jump lands within one pixel before a delayed math block above the target finishes laying out, the next animation frame takes this return and cancels all of the remaining JUMP_ALIGN_FRAMES. A layout shift in any later frame then moves the selected turn away from the top with no correction, defeating the multi-frame alignment this function is meant to provide; skip the scroll for a subpixel offset, but still schedule the remaining frames.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Declined after measuring. Jumping from the top into a chat whose 12 replies each carry a 70 line code fence and a display math block, the target's offset from the viewport top over the 40 frames after the click was -0.5, -0.5, then -0.1 px for every remaining frame, in three trials. Deferred fences reserve their height from the line count and math renders synchronously, so nothing above the target settles after the first frame; the remaining frames exist for a shift that lands in the frame right after the scroll, and that frame still runs.
|
@codex review |
What this PR does, file by fileA walkthrough of the full diff at 1. The setting
While the switch is off, nothing renders and nothing subscribes: 2. The turn index
Turn numbers follow the displayed branch, and context compaction is prompt side only, so they do not shift. Tests in Switching chats: the rail appears once the switch has settled, and the prompt bubbles are untouched, exactly as on main. 3. Bookmarks
Tests in Bookmarking from the prompt's action bar (the rail dash takes the accent colour and its card shows the filled icon), then removing it from the reply's More menu: 4. The rail
Pyramid magnify, the card, and a bookmark from the card: The rail following a 60 turn chat: 5. The cardHovering or focusing a dash shows a muted "Turn N" caption, the prompt on one line (240 characters of cleaned markdown), up to three lines of the reply (480 characters, with code fences, links and list markers stripped by
6. KeyboardArrow Up and Down move between dashes, Home and End go to the first and last, Enter jumps. Keyboard focus scrolls the rail to reveal its dash, the card follows the focused dash when the rail moves after a jump, and the rail follows the thread again once focus leaves. 7. Jump and shine
The bubble crops, dark and light, real speed and 4x slow, are in the PR body, and the comparison with the glass variant it replaces is in the comment above. Checks at
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dbc4223ca8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| </div> | ||
| {/* portaled out of the thread's autoscroll MutationObserver, and made invisible rather than | ||
| unmounted: adding or removing boxes trips a document-wide :has() restyle */} | ||
| {createPortal( |
There was a problem hiding this comment.
Hide the preview portal when its pane is backgrounded
When a preview is open and the app enters Compare without moving the pointer (for example through keyboard/programmatic navigation), chat-page.tsx deliberately keeps the prior single-chat provider mounted under a hidden wrapper. This portal escapes that wrapper, and the close effect only watches mouseout, resize, and window blur, so previewOpen can remain true and leave the old card over the Compare UI. Gate the navigator on useChatActive or close the preview whenever its pane becomes inactive.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Declined after reproducing the sequence. Compare is URL state, so the pointer-free way in is browser back into an earlier ?compare= view. With the card open on a hovered dash, and separately on a keyboard-focused dash with the pointer parked elsewhere, going back into Compare (in-app history, confirmed by a window marker surviving) leaves the card with visibility hidden and the dash blurred, in both Chromium 153 and WebKit 26.6: the hidden pane's dash gets its leave or blur event and hidePreview runs. The card never sits over the Compare UI, so there is nothing for an active gate to close.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dbc4223ca8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const threads = await listStoredChatThreads({ projectId }).catch(() => []); | ||
| const threadIds = threads.map((t) => t.id); | ||
| const kept = await deleteStoredChatProject(projectId, args); | ||
| useBookmarkedTurnsStore.getState().forgetThreads(threadIds); |
There was a problem hiding this comment.
Use transactional member IDs for bookmark cleanup
When a member chat is moved out of the project by another tab or API client after this pre-read but before the delete transaction, the backend preserves that chat while forgetThreads(threadIds) permanently removes its bookmarks; a chat moved in during the same window has the inverse stale-record problem. The backend transaction already computes authoritative membership under its lock as memberIds (studio/backend/storage/studio_db.py:3041-3081), so expose/consume those IDs from the delete result instead of cleaning up from this earlier snapshot.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Declined. This needs another tab or API client to move a chat into or out of the project in the window between this read and the delete transaction, and the cost is one browser-local bookmark record on that chat, which the user can set again; the chat itself is untouched. Widening the backend delete response to carry member ids is not worth that window.
| for (let index = 0; index < messages.length; index++) { | ||
| const message = messages[index]; | ||
| if (message.role === "user") { | ||
| openerIds.push(message.id); |
There was a problem hiding this comment.
Keep opaque IDs out of newline-delimited signatures
For chats written by an API client, message IDs may legally contain newlines because ChatMessage.id is an unconstrained string and the write routes do not validate its characters (studio/backend/routes/chat_history.py:308-316,1467-1476). Joining such an opener ID here and splitting it again in TurnIndexPublisher creates phantom opener IDs, leaves the real user message without a turn number, and also breaks bookmark-key splitting; keep the IDs structurally rather than using \n as a delimiter.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Declined. Message ids in Unsloth are UUIDs minted by the frontend and the backend; an id with a newline is malformed input from a hand-written API call, not something the UI produces or supports, and the same id would already break the per-message selector keys and the data-message-id lookups elsewhere in the thread.
| {threadId && !incognito && ( | ||
| <button | ||
| type="button" | ||
| tabIndex={-1} |
There was a problem hiding this comment.
Make the preview bookmark control keyboard reachable
When a keyboard user focuses and navigates the rail markers, the preview opens, but its only action is explicitly removed from the tab order here and has no equivalent key binding on the marker. Pressing Tab therefore leaves the rail and starts the preview's blur-hide timer instead of reaching the bookmark toggle; include this control in the focus flow and keep the card open while focus is inside it.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Declined. The card's toggle is a pointer shortcut; the keyboard path is the one the rail already gives: Enter on a marker jumps to the turn, and Tab then reaches the prompt's own Bookmark turn button in its action bar, which also sits in the reply's More menu. The card stays a tooltip (role=tooltip, aria-describedby) rather than a second focus stop.
|
Pushed |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 278242ac1c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Pushed |
|
@codex review |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Pushed |
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
|
Pushed Checks at |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1cb103df8f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
|
Pushed |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3dee72167f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| onPointerMove={onRailPointerMove} | ||
| onPointerLeave={clearMagnify} | ||
| onScroll={onRailScroll} | ||
| className="aui-turn-navigator group/rail pointer-events-auto absolute top-0 right-[-1.125rem] flex w-9 -translate-y-1/2 flex-col overflow-y-hidden py-1 transition-[height] duration-300 ease-[cubic-bezier(0.16,1,0.3,1)] [contain:layout_paint] [mask-image:linear-gradient(to_bottom,transparent,#000_var(--rail-fade-top,0px),#000_calc(100%_-_var(--rail-fade-bottom,0px)),transparent)] motion-reduce:transition-none" |
There was a problem hiding this comment.
Keep the rail hit area out of narrow message columns
When a chat has at least five turns on a narrow viewport (or uses a wide/full message column), the computed gutter can be zero, yet this 2.25rem pointer-events-auto nav is centered on the column edge via right: -1.125rem. Because every marker button fills that width, an 1.125rem strip sits above the right edge of user bubbles and their action bars and intercepts clicks or text selection whenever they pass behind the sticky rail. Hide or move the rail when the gutter cannot contain its hit area rather than only placing the visible dash in the padding.
Useful? React with 👍 / 👎.
…16300) ## Summary Long chats get a turn navigator at the chat's **left** edge: one short line per prompt. Hovering shows the prompt and the start of its reply; clicking jumps to that turn. This builds on #11668 by @mahiatlinux, with a new look: - **Look:** - The rail sits in the left gutter, and lines grow to the right with a small fisheye around the pointer. Only that hover scale animates; the on-screen tint switches without a transition, so scrolling never restyles the rail. - Prompts currently on screen are drawn brighter. - The preview card opens to the right of the rail: the prompt on one line, then up to three lines of the reply. - When the gutter is too narrow, the rail stays hidden until hovered or focused, so it never covers the chat. - Sizes: 8px between lines, 24px lines (8px at rest), 18px from the chat's left edge, the card 32px from the line, the rail capped at the window height less 18rem, and the card's prompt and reply at one size with a 20px line height and 12px padding. - Centred vertically on the chat, and the card uses the standard popup surface (no border, Studio's dropdown shadow and dark glow); its bookmark icon takes the prompt's colour. - **From #11668:** - Turn numbering that follows the displayed branch (`thread-turns.ts`). - Bookmarks from the prompt's action bar, the reply's More menu or the card. They are stored per chat and cleaned up when messages, chats, projects or all chats are deleted. - The rail follows the thread's scroll, with fades at its ends. - The jump completes progressive mounts first, then lands the prompt at the top with a short shine. - Arrow keys, Home and End move between turns. - The card follows a streaming reply. - A **Turn navigation** switch in Settings > Chat. Changes from #11668: - The rail is on the left. - On by default; the switch still removes it entirely. - Shows from 3 turns instead of 5. - The card drops the turn number; markers still announce "Turn N". #11668 conflicts with `main` today; this PR carries its code forward. With it, #11668 would be superseded. ## Hover lag in long chats Also fixes a lag that is on `main` today, independent of the rail. Hovering a message mounts its action bar, and Chromium then restyled the whole chat and sidebar (about 10k elements) whenever any `:has()` rule in the app had a broad subject. On a 200-turn chat that was about 30 ms per hover, and at 4x CPU throttle scrolling with the pointer over the thread stalled for 37 to 44 s of long tasks in some runs. - `vite-plugin-has-anchor.ts` rewrites Tailwind's `group-has-*` and `peer-has-*` output from `X:is(:where(.group):has(A) *)` to `:where(.group):has(A) X`: the same match and specificity, which Chromium invalidates precisely. - The composer pills' hover swap sets a variable on `.composer-pill-glyph` instead of styling `> :not(.composer-pill-x)` behind a `:has()`. - The glass sidebar rule matches a focused or open button itself instead of asking the row with `:has()`. - The glass page-route wallpaper rules use the `data-chat-wallpaper-workspace-ready` root flag that `background.tsx` already sets. - The unused avatar group count sizes its icon through a variable. | 200-turn chat, headless Chromium | Before | After | |---|---|---| | Style recalc over 40 message hovers | 305 ms | 43 ms (17 ms with every `:has()` rule removed) | | Long tasks scrolling over the thread, 4x throttle | 0.9 to 44 s (bimodal) | 0.3 to 0.6 s | | Frame time p95 while scrolling, 4x throttle | up to 400 ms | 16.8 ms | | Rail style recalc while scrolling, 4x throttle | 192 ms | 46 ms (12 ms with the rail off) | ## Verification - `npm run typecheck`, `npm run i18n:check:strict`, `npm test`, `npm run build` - `tests/thread-turns.test.ts`, `tests/bookmarked-turns-store.test.ts` (from #11668, updated for the left-side card) and `tests/turn-navigation-layout.test.ts` - In a local Studio build, with a 12-turn chat in dark and light themes: - The rail sits 18px from the chat's left edge and is centred vertically. - The card opens to the right of the rail and shows the right prompt and reply. - Clicking a turn lands its prompt at the top of the thread. - Bookmarking from the card turns that line the accent colour. - `tests/has-anchor-order.test.ts`: the rewrite on Tailwind's real output, equivalence cases, and selectors it must leave alone. - In a local Studio build: composer pills still swap their icon for the X on hover (Search, Tools, Skills), and compact pills with a menu keep their icon. The glass theme with a wallpaper and WebKit (Desktop on macOS and Linux) were not exercised here; the rewritten selectors match the same elements.








Adds opt-in turn navigation to Unsloth Studio / Desktop chat, requested on r/unsloth. Long chats get a rail on the right that numbers the turns, lets you bookmark them, and jumps to any of them. The prompt bubbles themselves look exactly as on main.
What it does
Turn numbers follow the displayed branch, and context compaction doesn't shift them.
Performance
Checks (at
3dee72167f)tsc: cleannpm test: 11,285 passed, 0 failednpm run build: passnpm run i18n:check:strict: pass, theturns.*andsettings.chat.turnNavigation*keys are in all 14 locales460f327, driven in an Unsloth Desktop shell on Windows 11 at 125% scaling: labels, bookmarks, rail hover and scroll, jumps, chat switching, and window resizing. The resize in the GIF also has Unsloth Desktop: keep the page sized to the window after a fast resize on Windows #12542 stacked in, a separate fix that keeps the page sized to the window.Earlier benchmarks (at
e22e297, before the rail rework) found no regression with the setting off or on; see the comments for those runs.Closes #10248.