The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(desktop): drag sessions to pin / unpin in the sidebar (#142672)
Austin Pickett8f555f4f9200
diff --git a/apps/desktop/src/app/chat/session-drag.test.ts b/apps/desktop/src/app/chat/session-drag.test.tsindex 72241a440ce..02bc80fb20d 100644--- a/apps/desktop/src/app/chat/session-drag.test.ts+++ b/apps/desktop/src/app/chat/session-drag.test.ts@@ -3,6 +3,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import { group } from '@/components/pane-shell/tree/model'import { $layoutTree, closeTreePane } from '@/components/pane-shell/tree/store'+import { $pinnedSessionIds } from '@/store/layout'import { requestFreshSession } from '@/store/profile'import { moveSessionToProject, projectIdForCwd } from '@/store/projects'import { $selectedStoredSessionId, $sessions } from '@/store/session'@@ -105,6 +106,7 @@ afterEach(() => {$selectedStoredSessionId.set(null)$sessionTiles.set([])$sessions.set([])+ $pinnedSessionIds.set([])})describe('session drop targeting across stacked tabs', () => {@@ -231,3 +233,116 @@ describe('session drop targeting onto a sidebar project row', () => {expect(moveSessionToProject).not.toHaveBeenCalled()})})++/** The sidebar Pinned section, exactly as `SidebarSessionsSection` tags it. */+function mountPinnedSection(box = { left: 0, top: 0, right: 200, bottom: 120 }) {+ const section = document.createElement('div')+ section.setAttribute('data-session-pin-drop', '')+ document.body.appendChild(section)+ stubRect(section, box)++ return section+}++describe('session drop targeting onto the Pinned section', () => {+ beforeEach(() => {+ mountStackedTabs()+ $layoutTree.set(group(['sessions'], { id: 'g1' }))+ })++ it('pins the dragged session under its durable lineage id', () => {+ $sessions.set([{ id: 'dragged', cwd: '', _lineage_root_id: 'root-1' } as never])+ mountPinnedSection()++ dragTo(document.getElementById('row')!, 100, 20)++ expect($pinnedSessionIds.get()).toEqual(['root-1'])+ expect(openSessionTile).not.toHaveBeenCalled()+ expect(requestComposerInsertRefs).not.toHaveBeenCalled()+ })++ it('lights the section while hovered and clears it on release', async () => {+ const section = mountPinnedSection()+ const row = document.getElementById('row')!++ startSessionDrag({ id: 'dragged', profile: 'default', title: 'Dragged chat' }, {+ button: 0,+ clientX: 0,+ clientY: 0,+ currentTarget: row,+ pointerId: 1+ } as unknown as ReactPointerEvent<HTMLElement>)+ window.dispatchEvent(new MouseEvent('pointermove', { bubbles: true, clientX: 100, clientY: 20 }))+ await new Promise(resolve => requestAnimationFrame(resolve))+ expect(section.getAttribute('data-session-drop-hover')).toBe('true')++ window.dispatchEvent(new MouseEvent('pointerup', { bubbles: true, clientX: 100, clientY: 20 }))+ expect(section.hasAttribute('data-session-drop-hover')).toBe(false)+ })++ it('keeps an already-pinned session in place when its tile tab is dropped on Pinned', () => {+ $sessions.set([{ id: 'dragged', cwd: '', _lineage_root_id: 'root-1' } as never])+ $pinnedSessionIds.set(['root-1', 'other'])+ const section = mountPinnedSection()++ dragTo(document.getElementById('row')!, 100, 20)++ expect($pinnedSessionIds.get()).toEqual(['root-1', 'other'])+ expect(section.hasAttribute('data-session-drop-hover')).toBe(false)+ })++ it('is not a target for a row dragged from inside Pinned — that reorders', () => {+ const section = mountPinnedSection()+ const row = document.getElementById('row')!+ section.appendChild(row)++ dragTo(row, 100, 20)++ expect($pinnedSessionIds.get()).toEqual([])+ })+})++describe('session drop targeting from Pinned back onto a session list', () => {+ beforeEach(() => {+ mountStackedTabs()+ $layoutTree.set(group(['sessions'], { id: 'g1' }))+ $sessions.set([{ id: 'dragged', cwd: '', _lineage_root_id: 'root-1' } as never])+ $pinnedSessionIds.set(['root-1'])+ })++ /** A pinned row sitting in Pinned (top), above the Recents list (below). */+ function mountPinnedAndList() {+ const pinned = mountPinnedSection({ left: 0, top: 0, right: 200, bottom: 100 })+ const row = document.getElementById('row')!+ pinned.appendChild(row)+ const list = document.createElement('div')+ list.setAttribute('data-session-unpin-drop', '')+ document.body.appendChild(list)+ stubRect(list, { left: 0, top: 100, right: 200, bottom: 600 })++ return row+ }++ it('unpins a pinned row dropped onto the session list', () => {+ dragTo(mountPinnedAndList(), 100, 300)++ expect($pinnedSessionIds.get()).toEqual([])+ expect(openSessionTile).not.toHaveBeenCalled()+ })++ it('leaves the pin alone when the pinned row is dropped back inside Pinned', () => {+ dragTo(mountPinnedAndList(), 100, 50)++ expect($pinnedSessionIds.get()).toEqual(['root-1'])+ })++ it('never unpins a row that was not dragged out of Pinned', () => {+ mountPinnedAndList()+ const outside = document.createElement('div')+ document.body.appendChild(outside)++ dragTo(outside, 100, 300)++ expect($pinnedSessionIds.get()).toEqual(['root-1'])+ })+})diff --git a/apps/desktop/src/app/chat/session-drag.ts b/apps/desktop/src/app/chat/session-drag.tsindex 064eeac0cfd..7eafdf553e8 100644--- a/apps/desktop/src/app/chat/session-drag.ts+++ b/apps/desktop/src/app/chat/session-drag.ts@@ -12,6 +12,10 @@* into that surface's composer (ChatDropOverlay owns the visual);* - a sidebar PROJECT ROW → move: re-home the session under that project* (same call the row's own "Move to project" menu item makes);+ * - the sidebar PINNED section → pin: same call as the row's "Pin" menu+ * item (a row already in Pinned isn't a pin target — it reorders there);+ * - a sidebar SESSION LIST, from a pinned row → unpin: same call as the+ * row's "Unpin" menu item;* - anything else (terminal, gutters) → deny.** Zones that don't host a chat surface are NOT targets — the overlay never@@ -48,10 +52,11 @@ import {} from '@/components/pane-shell/tree/store'import type { EngineZone, ZoneRect } from '@/components/pane-shell/tree/zones-engine'import { translateNow } from '@/i18n'+import { $pinnedSessionIds, pinSession, unpinSession } from '@/store/layout'import { notifyError } from '@/store/notifications'import { requestFreshSession } from '@/store/profile'import { moveSessionToProject, projectIdForCwd } from '@/store/projects'-import { $selectedStoredSessionId, $sessions, sessionMatchesStoredId } from '@/store/session'+import { $selectedStoredSessionId, $sessions, sessionMatchesStoredId, sessionPinId } from '@/store/session'import { $sessionTiles, nextSessionTileForWorkspace, openSessionTile, type TileDock } from '@/store/session-states'import { requestComposerInsertRefs } from './composer/focus'@@ -60,6 +65,8 @@ import { NO_PROJECT_ID } from './sidebar/projects/workspace-groups'import { tileZoneHost } from './tile-zone-host'const PROJECT_ROW_DROP_ATTR = 'data-session-drop-hover'+const PIN_DROP_SELECTOR = '[data-session-pin-drop]'+const UNPIN_DROP_SELECTOR = '[data-session-unpin-drop]'/** A sidebar project row's drop geometry — tagged by `ProjectOverviewRow` via* `data-sessions-project`. */@@ -130,12 +137,17 @@ export function startSessionDrag(let composers: ZoneRect[] = []let zoneHost = new Map<string, ReturnType<typeof tileZoneHost>>()let projectRows: ProjectRowSnapshot[] = []+ let pinTarget: { el: HTMLElement; rect: ZoneRect } | null = null+ let unpinTargets: { el: HTMLElement; rect: ZoneRect }[] = []// Commit intent, updated per resolved move (the machinery flushes the final// move before commit, so these always match the released-at position).let split: { anchor: string; before?: null | string; pos: TileDock } | null = nulllet link: null | string = nulllet moveToProject: null | string = null+ let pin = false+ let unpin = false+ let hoveredUnpin: HTMLElement | null = null// The project row currently painted as the drop target, so a move to a// different row (or off any row) clears the one it left — imperative like// the source's own opacity, not React state (a repaint here shouldn't@@ -147,6 +159,26 @@ export function startSessionDrag(hoveredProjectRow = null}+ const setUnpinHover = (el: HTMLElement | null) => {+ unpin = el !== null++ if (hoveredUnpin !== el) {+ hoveredUnpin?.removeAttribute(PROJECT_ROW_DROP_ATTR)+ el?.setAttribute(PROJECT_ROW_DROP_ATTR, 'true')+ hoveredUnpin = el+ }+ }++ const setPinHover = (on: boolean) => {+ pin = on++ if (on) {+ pinTarget?.el.setAttribute(PROJECT_ROW_DROP_ATTR, 'true')+ } else {+ pinTarget?.el.removeAttribute(PROJECT_ROW_DROP_ATTR)+ }+ }+// The drag SOURCE (sidebar row or tile tab). Captured synchronously — React// clears `currentTarget` after the pointerdown handler returns, but this runs// inside it. Dimmed while lifted so the source reads as "picked up" — the@@ -169,6 +201,22 @@ export function startSessionDrag(const draggedSession = $sessions.get().find(s => sessionMatchesStoredId(s, payload.id))const cwd = draggedSession?.cwd?.trim() || ''projectRows = snapshotProjectRows(cwd ? projectIdForCwd(cwd) : null)+ // A row dragged out of Pinned has nothing to pin (it reorders there) —+ // instead the session lists become unpin targets. Any other row gets+ // Pinned as its pin target.+ const fromPinned = Boolean(source?.closest(PIN_DROP_SELECTOR))++ // A session that's already pinned (e.g. dragged from its tile tab) has+ // nothing to pin either: pinSession would re-append it to the bottom.+ const alreadyPinned = draggedSession+ ? $pinnedSessionIds.get().includes(sessionPinId(draggedSession))+ : $pinnedSessionIds.get().includes(payload.id)++ const pinEl = fromPinned || alreadyPinned ? null : queryAllVisible<HTMLElement>(PIN_DROP_SELECTOR)[0]+ pinTarget = pinEl ? { el: pinEl, rect: snapRect(pinEl) } : null+ unpinTargets = fromPinned+ ? queryAllVisible<HTMLElement>(UNPIN_DROP_SELECTOR).map(el => ({ el, rect: snapRect(el) }))+ : []source?.style.setProperty('opacity', '0.45')// The same sentinel the zone overlay + chat surfaces key off — the// whole drop language (sheets, pills, caret, link overlay) lights up.@@ -181,9 +229,23 @@ export function startSessionDrag(}clearProjectHover()+ setPinHover(false)+ setUnpinHover(null)},resolveMove(x, y): DropHint | null {+ if (pinTarget && rectContains(pinTarget.rect, x, y)) {+ split = null+ link = null+ moveToProject = null+ clearProjectHover()+ setPinHover(true)++ return null+ }++ setPinHover(false)+// The sidebar hosts no MAIN tile, so it's outside every pane-shell// zone — a project row is the one thing in that dead space a session// drop still resolves against. Checked first: it's a flat, disjoint@@ -207,6 +269,16 @@ export function startSessionDrag(moveToProject = nullclearProjectHover()+ const unpinTarget = unpinTargets.find(t => rectContains(t.rect, x, y))+ setUnpinHover(unpinTarget?.el ?? null)++ if (unpinTarget) {+ split = null+ link = null++ return null+ }+const zone = zones.find(z => rectContains(z.rect, x, y))const host = zone ? zoneHost.get(zone.id) : null@@ -279,6 +351,16 @@ export function startSessionDrag(} else if (link) {// The "link to chat" drop: an @session chip in that surface's composer.requestComposerInsertRefs([sessionInlineRef(payload)], { target: link })+ } else if (pin || unpin) {+ // Same store calls as the row's own "Pin" / "Unpin" menu items.+ const session = $sessions.get().find(s => sessionMatchesStoredId(s, payload.id))+ const pinId = session ? sessionPinId(session) : payload.id++ if (pin) {+ pinSession(pinId)+ } else {+ unpinSession(pinId)+ }} else if (moveToProject) {// Same RPC the row's own "Move to project" menu item calls — the drop// is a shortcut onto that existing path, not a parallel one.diff --git a/apps/desktop/src/app/chat/sidebar/sessions-section.tsx b/apps/desktop/src/app/chat/sidebar/sessions-section.tsxindex cc310f655a0..98dcd623ac5 100644--- a/apps/desktop/src/app/chat/sidebar/sessions-section.tsx+++ b/apps/desktop/src/app/chat/sidebar/sessions-section.tsx@@ -624,7 +624,7 @@ export function SidebarSessionsSection({const resolvedContentClassName = cn(contentClassName, flatVirtualized && 'overflow-visible')return (- <SidebarGroup className={rootClassName}>+ <SidebarGroup className={cn(rootClassName, DROP_TARGET_RING)} {...sessionDropTargetProps(pinned)}><SidebarSectionHeaderaction={headerAction}collapsible={collapsible}@@ -644,6 +644,15 @@ export function SidebarSessionsSection({)}+// Painted imperatively by session-drag.ts while a session hovers a pin+// (Pinned) or unpin (any other list) target — same ring as a project row drop+// target.+const DROP_TARGET_RING =+ 'rounded-[6px] data-[session-drop-hover=true]:outline-2 data-[session-drop-hover=true]:-outline-offset-2 data-[session-drop-hover=true]:outline-sidebar-ring'++const sessionDropTargetProps = (pinned: boolean) =>+ pinned ? { 'data-session-pin-drop': '' } : { 'data-session-unpin-drop': '' }+interface SortableSessionRowProps {session: SessionInfoisPinned: boolean