Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
feat(desktop-app): reorder workspace tabs by drag and keyboard
Diego Zacarias8d9d30aa2ea5
diff --git a/desktop-app/ui/src/App.tsx b/desktop-app/ui/src/App.tsxindex e65f21839..5acd63763 100644--- a/desktop-app/ui/src/App.tsx+++ b/desktop-app/ui/src/App.tsx@@ -68,6 +68,7 @@ import {newChatTab,openAppTab,reconcileWorkspaceChatTab,+ reorderWorkspaceTab,selectLastWorkspaceTab,selectWorkspaceTab,selectWorkspaceTabAt,@@ -482,6 +483,15 @@ export function App() {[revealWorkspaceTab, setWorkspaceTabs, vm.clearAppsPicker])+ // Session-only strip reorder (drag & drop / keyboard). It never changes the+ // active tab, so no reveal is needed — the route seam stays put.+ const handleReorderWorkspaceTab = React.useCallback(+ (fromId: string, toIndex: number) => {+ setWorkspaceTabs(state => reorderWorkspaceTab(state, fromId, toIndex))+ },+ [setWorkspaceTabs]+ )+const handleNewWorkspaceChatTab = React.useCallback(() => {vm.clearAppsPicker()const agentRef = vm.selectedAgent@@ -2452,6 +2462,7 @@ export function App() {vm.appsPickerActive ? null : workspaceTabs.activeTabId}onClose={handleCloseWorkspaceTab}+ onReorder={handleReorderWorkspaceTab}onSelect={handleSelectWorkspaceTab}panelId={vm.navItem === DESKTOP_ROUTES.chatdiff --git a/desktop-app/ui/src/components/WorkspaceTabStrip/WorkspaceTabStrip.test.tsx b/desktop-app/ui/src/components/WorkspaceTabStrip/WorkspaceTabStrip.test.tsxindex 095fcad12..340d49d11 100644--- a/desktop-app/ui/src/components/WorkspaceTabStrip/WorkspaceTabStrip.test.tsx+++ b/desktop-app/ui/src/components/WorkspaceTabStrip/WorkspaceTabStrip.test.tsx@@ -1,18 +1,21 @@// @vitest-environment jsdom-import { afterEach, describe, expect, it, vi } from 'vitest'+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import { makeTaskKey } from '@contexts/AgentTaskTrackerContext/types'import { ChatListProvider } from '@contexts/ChatListContext'-import { cleanup, fireEvent, render, screen } from '@testing-library/react'+import { cleanup, createEvent, fireEvent, render, screen } from '@testing-library/react'import { readFileSync } from 'node:fs'import path from 'node:path'import { createSessionFsmStore, projectSessionState } from '@hooks/domain/sessionFsm'import {+ createEmptyWorkspaceTabsState,createWorkspaceTabsState,newChatTab,openAppTab,openChatTab,openSettingsTab,+ reorderWorkspaceTab,} from '@lib/workspaceTabs'+import type { WorkspaceTabsState } from '@lib/workspaceTabs.types'import { WorkspaceTabStrip } from '.'afterEach(cleanup)@@ -42,6 +45,7 @@ describe('WorkspaceTabStrip', () => {activeTabId="one"onSelect={onSelect}onClose={onClose}+ onReorder={vi.fn()}/>)@@ -64,7 +68,13 @@ describe('WorkspaceTabStrip', () => {title: longTitle,}).tabsconst { container } = render(- <WorkspaceTabStrip tabs={longTabs} activeTabId="one" onSelect={vi.fn()} onClose={vi.fn()} />+ <WorkspaceTabStrip+ tabs={longTabs}+ activeTabId="one"+ onSelect={vi.fn()}+ onClose={vi.fn()}+ onReorder={vi.fn()}+ />)const select = screen.getByRole('button', { name: longTitle })@@ -112,6 +122,7 @@ describe('WorkspaceTabStrip', () => {<WorkspaceTabStripactiveTabId="one"onClose={vi.fn()}+ onReorder={vi.fn()}onSelect={vi.fn()}panelId="chat-view-panel"tabs={tabs}@@ -173,7 +184,13 @@ describe('WorkspaceTabStrip', () => {sessionStateByChatKey,}}>- <WorkspaceTabStrip tabs={tabs} activeTabId="seed" onSelect={vi.fn()} onClose={vi.fn()} />+ <WorkspaceTabStrip+ tabs={tabs}+ activeTabId="seed"+ onSelect={vi.fn()}+ onClose={vi.fn()}+ onReorder={vi.fn()}+ /></ChatListProvider>)@@ -227,7 +244,13 @@ describe('WorkspaceTabStrip', () => {sessionStateByChatKey,}}>- <WorkspaceTabStrip tabs={tabs} activeTabId="app-1" onSelect={vi.fn()} onClose={vi.fn()} />+ <WorkspaceTabStrip+ tabs={tabs}+ activeTabId="app-1"+ onSelect={vi.fn()}+ onClose={vi.fn()}+ onReorder={vi.fn()}+ /></ChatListProvider>)@@ -239,3 +262,194 @@ describe('WorkspaceTabStrip', () => {expect(screen.getAllByRole('status')).toHaveLength(1)})})++describe('WorkspaceTabStrip — reorder (drag & keyboard)', () => {+ // App tabs keep their ids and never dedupe, so this yields three distinct,+ // stably-ordered tabs [a, b, c] derived from the real store producer (T1).+ const threeTabs = openAppTab(+ openAppTab(+ openAppTab(createEmptyWorkspaceTabsState(), { id: 'a', appRef: 'ns/x', title: 'Alpha' }),+ { id: 'b', appRef: 'ns/x', title: 'Bravo' }+ ),+ { id: 'c', appRef: 'ns/x', title: 'Charlie' }+ ).tabs++ // jsdom returns a zeroed rect from getBoundingClientRect, so the drop side is+ // computed as 'after' for any clientX >= 0. Pin a real 100px-wide rect (midpoint+ // at x=50) on every element so `clientX` selects the half deterministically:+ // clientX < 50 → 'before', >= 50 → 'after'.+ let rectSpy: ReturnType<typeof vi.spyOn> | undefined+ beforeEach(() => {+ rectSpy = vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockReturnValue({+ left: 0,+ width: 100,+ right: 100,+ top: 0,+ bottom: 0,+ height: 0,+ x: 0,+ y: 0,+ toJSON: () => ({}),+ } as DOMRect)+ })+ afterEach(() => {+ rectSpy?.mockRestore()+ })++ const makeDataTransfer = () => {+ const store: Record<string, string> = {}+ return {+ effectAllowed: '',+ setData: (type: string, value: string) => {+ store[type] = value+ },+ getData: (type: string) => store[type] ?? '',+ }+ }++ const containerFor = (root: HTMLElement, name: string): HTMLElement =>+ screen.getByRole('button', { name }).closest('.chat-view-tab') as HTMLElement++ // jsdom has no DragEvent, so `fireEvent.drop(..., { clientX })` drops clientX on+ // the floor. Build the event explicitly and pin clientX so the side is real.+ const fireDrag = (+ kind: 'dragOver' | 'drop',+ node: HTMLElement,+ dataTransfer: unknown,+ clientX: number+ ): void => {+ const event = createEvent[kind](node, { dataTransfer })+ Object.defineProperty(event, 'clientX', { value: clientX })+ fireEvent(node, event)+ }++ it('drags a left tab to the right of a later tab (shift-adjusted final index)', () => {+ const onReorder = vi.fn()+ const { container } = render(+ <WorkspaceTabStrip+ tabs={threeTabs}+ activeTabId="a"+ onSelect={vi.fn()}+ onClose={vi.fn()}+ onReorder={onReorder}+ />+ )+ const source = containerFor(container, 'Alpha')+ const target = containerFor(container, 'Charlie')+ const dataTransfer = makeDataTransfer()+ fireEvent.dragStart(source, { dataTransfer })+ fireDrag('dragOver', target, dataTransfer, 90)+ fireDrag('drop', target, dataTransfer, 90)+ // Drop after 'c' (index 2); 'a' sat before it, so the final index is 2.+ expect(onReorder).toHaveBeenCalledWith('a', 2)+ })++ it('drags a right tab to the left of an earlier tab (no shift adjustment)', () => {+ const onReorder = vi.fn()+ const { container } = render(+ <WorkspaceTabStrip+ tabs={threeTabs}+ activeTabId="a"+ onSelect={vi.fn()}+ onClose={vi.fn()}+ onReorder={onReorder}+ />+ )+ const source = containerFor(container, 'Charlie')+ const target = containerFor(container, 'Alpha')+ const dataTransfer = makeDataTransfer()+ fireEvent.dragStart(source, { dataTransfer })+ fireDrag('dragOver', target, dataTransfer, 10)+ fireDrag('drop', target, dataTransfer, 10)+ // Drop before 'a' (index 0); 'c' sat after it, so the final index is 0.+ expect(onReorder).toHaveBeenCalledWith('c', 0)+ })++ it('does not reorder when dropped on itself', () => {+ const onReorder = vi.fn()+ const { container } = render(+ <WorkspaceTabStrip+ tabs={threeTabs}+ activeTabId="a"+ onSelect={vi.fn()}+ onClose={vi.fn()}+ onReorder={onReorder}+ />+ )+ const self = containerFor(container, 'Bravo')+ const dataTransfer = makeDataTransfer()+ fireEvent.dragStart(self, { dataTransfer })+ fireDrag('drop', self, dataTransfer, 90)+ expect(onReorder).not.toHaveBeenCalled()+ })++ it('moves a tab with Alt+ArrowRight / Alt+ArrowLeft from the focused select', () => {+ const onReorder = vi.fn()+ render(+ <WorkspaceTabStrip+ tabs={threeTabs}+ activeTabId="a"+ onSelect={vi.fn()}+ onClose={vi.fn()}+ onReorder={onReorder}+ />+ )+ const bravo = screen.getByRole('button', { name: 'Bravo' })+ fireEvent.keyDown(bravo, { key: 'ArrowRight', altKey: true })+ expect(onReorder).toHaveBeenLastCalledWith('b', 2) // index 1 -> 2+ fireEvent.keyDown(bravo, { key: 'ArrowLeft', altKey: true })+ expect(onReorder).toHaveBeenLastCalledWith('b', 0) // index 1 -> 0+ })++ it('ignores arrow keys without Alt (leaves navigation/select alone)', () => {+ const onReorder = vi.fn()+ render(+ <WorkspaceTabStrip+ tabs={threeTabs}+ activeTabId="a"+ onSelect={vi.fn()}+ onClose={vi.fn()}+ onReorder={onReorder}+ />+ )+ const bravo = screen.getByRole('button', { name: 'Bravo' })+ fireEvent.keyDown(bravo, { key: 'ArrowRight' })+ fireEvent.keyDown(bravo, { key: 'ArrowLeft' })+ expect(onReorder).not.toHaveBeenCalled()+ })++ it('keeps focus on the moved tab after a keyboard reorder (list keyed by id)', () => {+ // Drive the real store reducer so the rerender reflects the new order; the+ // moved tab's DOM node persists (keyed by id) and thus keeps DOM focus.+ let state: WorkspaceTabsState = { tabs: threeTabs, activeTabId: 'a' }+ const onReorder = (fromId: string, toIndex: number) => {+ state = reorderWorkspaceTab(state, fromId, toIndex)+ }+ const { rerender } = render(+ <WorkspaceTabStrip+ tabs={state.tabs}+ activeTabId={state.activeTabId}+ onSelect={vi.fn()}+ onClose={vi.fn()}+ onReorder={onReorder}+ />+ )+ const bravo = screen.getByRole('button', { name: 'Bravo' })+ bravo.focus()+ expect(document.activeElement).toBe(bravo)+ fireEvent.keyDown(bravo, { key: 'ArrowRight', altKey: true })+ rerender(+ <WorkspaceTabStrip+ tabs={state.tabs}+ activeTabId={state.activeTabId}+ onSelect={vi.fn()}+ onClose={vi.fn()}+ onReorder={onReorder}+ />+ )+ expect(state.tabs.map(t => t.id)).toEqual(['a', 'c', 'b'])+ // Same DOM node, now last, still focused.+ expect(document.activeElement).toBe(screen.getByRole('button', { name: 'Bravo' }))+ expect(document.activeElement).toBe(bravo)+ })+})diff --git a/desktop-app/ui/src/components/WorkspaceTabStrip/index.tsx b/desktop-app/ui/src/components/WorkspaceTabStrip/index.tsxindex 847e2c968..093f23717 100644--- a/desktop-app/ui/src/components/WorkspaceTabStrip/index.tsx+++ b/desktop-app/ui/src/components/WorkspaceTabStrip/index.tsx@@ -1,10 +1,20 @@-import { useContext } from 'react'+import { useContext, useState } from 'react'import { makeTaskKey } from '@contexts/AgentTaskTrackerContext/types'import { ChatListContext } from '@contexts/ChatListContext'import { Button } from '@components/Common'import { ChatStateBadge } from '@components/agents/ChatStateBadge'+import type { WorkspaceTab } from '@lib/workspaceTabs.types'import type { WorkspaceTabStripProps } from './types'+type DropSide = 'before' | 'after'+type DropTarget = { id: string; side: DropSide }++/** Which half of a tab the cursor is over — the insertion side for the drop. */+function sideFromEvent(event: React.DragEvent<HTMLElement>): DropSide {+ const rect = event.currentTarget.getBoundingClientRect()+ return event.clientX < rect.left + rect.width / 2 ? 'before' : 'after'+}+/*** The single global workspace strip (spec 01 §4.2, mini-spec 03 §3). It renders* every tab in the universal store — chat, app, files, settings — and is the@@ -12,28 +22,101 @@ import type { WorkspaceTabStripProps } from './types'* show their live session badge via `sessionStateByChatKey`, exactly as the* former strip did; non-chat tabs carry no badge. Selecting a tab activates it* (the seam derives the route from the active tab); the close control removes it.+ *+ * Tabs reorder by native HTML5 drag & drop (mouse) and by Alt+ArrowLeft/Right+ * on the focused select control (keyboard). The drag ghost / drop-indicator+ * feedback is local UI state only; the order itself lives in the store via+ * `onReorder`, which never changes which tab is active.*/export function WorkspaceTabStrip({tabs,activeTabId,onSelect,onClose,+ onReorder,panelId,}: WorkspaceTabStripProps) {const chatList = useContext(ChatListContext)+ const [draggingId, setDraggingId] = useState<string | null>(null)+ const [dropTarget, setDropTarget] = useState<DropTarget | null>(null)++ const clearDrag = () => {+ setDraggingId(null)+ setDropTarget(null)+ }++ const handleDrop = (event: React.DragEvent<HTMLElement>, target: WorkspaceTab) => {+ event.preventDefault()+ const fromId = event.dataTransfer.getData('text/plain') || draggingId+ const side = sideFromEvent(event)+ clearDrag()+ if (!fromId || fromId === target.id) return+ const fromIndex = tabs.findIndex(tab => tab.id === fromId)+ const targetIndex = tabs.findIndex(tab => tab.id === target.id)+ if (fromIndex < 0 || targetIndex < 0) return+ // The reducer's `toIndex` is the final index in the array WITHOUT the dragged+ // tab: when the dragged tab sits before the target, removing it shifts the+ // target left by one, so the drop slot moves with it.+ const targetAdjusted = targetIndex - (fromIndex < targetIndex ? 1 : 0)+ onReorder(fromId, side === 'after' ? targetAdjusted + 1 : targetAdjusted)+ }++ const handleSelectKeyDown = (+ event: React.KeyboardEvent<HTMLButtonElement>,+ tab: WorkspaceTab,+ index: number+ ) => {+ if (!event.altKey) return+ if (event.key === 'ArrowLeft') {+ event.preventDefault()+ onReorder(tab.id, index - 1)+ } else if (event.key === 'ArrowRight') {+ event.preventDefault()+ onReorder(tab.id, index + 1)+ }+ }return (<div className="chat-view-tabs" role="toolbar" aria-label="Workspace tabs"><div className="chat-view-tabs__scroller"><div className="chat-view-tabs__list">- {tabs.map(tab => {+ {tabs.map((tab, index) => {const active = tab.id === activeTabIdconst sessionState =tab.kind === 'chat' && tab.chat?.agentRef && tab.chat?.chatId? chatList?.sessionStateByChatKey[makeTaskKey(tab.chat.agentRef, tab.chat.chatId)]: undefined+ const drop = dropTarget?.id === tab.id ? dropTarget.side : undefined+ const className =+ `chat-view-tab${active ? ' is-active' : ''}` ++ `${draggingId === tab.id ? ' is-dragging' : ''}` ++ `${drop === 'before' ? ' is-drop-before' : ''}` ++ `${drop === 'after' ? ' is-drop-after' : ''}`return (- <div className={`chat-view-tab${active ? ' is-active' : ''}`} key={tab.id}>+ <div+ className={className}+ draggable+ key={tab.id}+ onDragEnd={clearDrag}+ onDragOver={event => {+ // preventDefault always, so a drop on the source tab is a valid+ // (no-op) target; but don't paint a drop indicator on the tab+ // being dragged — it would show `is-dragging` and `is-drop-*`+ // at once.+ event.preventDefault()+ if (tab.id === draggingId) {+ setDropTarget(null)+ return+ }+ setDropTarget({ id: tab.id, side: sideFromEvent(event) })+ }}+ onDragStart={event => {+ event.dataTransfer.setData('text/plain', tab.id)+ event.dataTransfer.effectAllowed = 'move'+ setDraggingId(tab.id)+ }}+ onDrop={event => handleDrop(event, tab)}+ ><Buttonalign="start"aria-controls={active ? panelId : undefined}@@ -42,6 +125,7 @@ export function WorkspaceTabStrip({className="chat-view-tab__select"color="neutral"onClick={() => onSelect(tab.id)}+ onKeyDown={event => handleSelectKeyDown(event, tab, index)}size="sm"variant="ghost">diff --git a/desktop-app/ui/src/components/WorkspaceTabStrip/types.ts b/desktop-app/ui/src/components/WorkspaceTabStrip/types.tsindex d59653d70..8d0f8cb12 100644--- a/desktop-app/ui/src/components/WorkspaceTabStrip/types.ts+++ b/desktop-app/ui/src/components/WorkspaceTabStrip/types.ts@@ -5,5 +5,7 @@ export type WorkspaceTabStripProps = {activeTabId: string | nullonSelect: (id: string) => voidonClose: (id: string) => void+ /** Move a tab to `toIndex` (its desired FINAL array index; see reorderWorkspaceTab). */+ onReorder: (fromId: string, toIndex: number) => voidpanelId?: string}diff --git a/desktop-app/ui/src/lib/__tests__/workspaceTabs.test.ts b/desktop-app/ui/src/lib/__tests__/workspaceTabs.test.tsindex 1aab1c6e6..587774053 100644--- a/desktop-app/ui/src/lib/__tests__/workspaceTabs.test.ts+++ b/desktop-app/ui/src/lib/__tests__/workspaceTabs.test.ts@@ -14,6 +14,7 @@ import {openFilesTab,openSettingsTab,reconcileWorkspaceChatTab,+ reorderWorkspaceTab,selectLastWorkspaceTab,selectWorkspaceTab,selectWorkspaceTabAt,@@ -410,6 +411,146 @@ describe('workspaceTabs — close (no re-seed; empty allowed §5)', () => {})})+describe('workspaceTabs — reorderWorkspaceTab', () => {+ function four(): WorkspaceTabsState {+ let state = createEmptyWorkspaceTabsState()+ state = openChatTab(state, { id: 't0', agentRef: 'a', chatId: 'c0' })+ state = openAppTab(state, { id: 't1', appRef: 'app' })+ state = openFilesTab(state, { id: 't2' })+ state = openSettingsTab(state, { id: 't3', section: 'agents' })+ return { ...state, activeTabId: 't1' }+ }++ it('moves the first tab to the last position (toIndex = final index)', () => {+ const state = four()+ const next = reorderWorkspaceTab(state, 't0', 3)+ expect(next.tabs.map(t => t.id)).toEqual(['t1', 't2', 't3', 't0'])+ expect(next.activeTabId).toBe('t1')+ })++ it('moves the last tab to the first position', () => {+ const state = four()+ const next = reorderWorkspaceTab(state, 't3', 0)+ expect(next.tabs.map(t => t.id)).toEqual(['t3', 't0', 't1', 't2'])+ expect(next.activeTabId).toBe('t1')+ })++ it('moves a middle tab forward and backward, landing exactly at toIndex', () => {+ const state = four()+ expect(reorderWorkspaceTab(state, 't1', 2).tabs.map(t => t.id)).toEqual([+ 't0',+ 't2',+ 't1',+ 't3',+ ])+ expect(reorderWorkspaceTab(state, 't2', 0).tabs.map(t => t.id)).toEqual([+ 't2',+ 't0',+ 't1',+ 't3',+ ])+ })++ it('is a no-op (same reference) for the current index, an unknown id, and < 2 tabs', () => {+ const state = four()+ expect(reorderWorkspaceTab(state, 't2', 2)).toBe(state) // already at index 2+ expect(reorderWorkspaceTab(state, 'ghost', 0)).toBe(state) // unknown id+ const one = openAppTab(createEmptyWorkspaceTabsState(), { id: 'solo', appRef: 'x' })+ expect(reorderWorkspaceTab(one, 'solo', 5)).toBe(one) // single tab: any target clamps to self+ expect(reorderWorkspaceTab(createEmptyWorkspaceTabsState(), 'x', 0)).toEqual({+ tabs: [],+ activeTabId: null,+ })+ })++ it('clamps an out-of-range toIndex instead of throwing or dropping a tab', () => {+ const state = four()+ expect(reorderWorkspaceTab(state, 't0', 99).tabs.map(t => t.id)).toEqual([+ 't1',+ 't2',+ 't3',+ 't0',+ ])+ expect(reorderWorkspaceTab(state, 't3', -5).tabs.map(t => t.id)).toEqual([+ 't3',+ 't0',+ 't1',+ 't2',+ ])+ })++ // T2 property-based: reorder is a pure permutation that fixes the active id.+ it('property: preserves the id set, length, and activeTabId; lands the tab at clamp(toIndex)', () => {+ fc.assert(+ fc.property(+ fc.array(openOpArb, { minLength: 1, maxLength: 25 }),+ fc.integer({ min: 0, max: 24 }),+ fc.integer({ min: -10, max: 40 }),+ (ops, activeRaw, toIndex) => {+ const base = applyOpens(ops)+ if (base.tabs.length === 0) return+ const activeId = base.tabs[activeRaw % base.tabs.length]!.id+ const state: WorkspaceTabsState = { ...base, activeTabId: activeId }+ const idsBefore = state.tabs.map(t => t.id)++ for (const fromId of idsBefore) {+ const next = reorderWorkspaceTab(state, fromId, toIndex)++ // (3) activeTabId is always preserved.+ expect(next.activeTabId).toBe(activeId)+ // (2) length conserved.+ expect(next.tabs.length).toBe(state.tabs.length)+ // (1) the id set is identical (no loss, no duplicate).+ expect(new Set(next.tabs.map(t => t.id))).toEqual(new Set(idsBefore))++ // (4) the moved tab lands exactly at clamp(toIndex, 0, len-1).+ const clamped = Math.max(0, Math.min(toIndex, state.tabs.length - 1))+ expect(next.tabs[clamped]!.id).toBe(fromId)++ // (5) a no-op returns the SAME reference.+ const fromIndex = idsBefore.indexOf(fromId)+ if (clamped === fromIndex) expect(next).toBe(state)+ }++ // (5) an unknown id is always the same reference.+ expect(reorderWorkspaceTab(state, 'no-such-id', toIndex)).toBe(state)+ }+ )+ )+ })++ // T2 property: idempotence — moving a tab to where it already is, is a no-op.+ it('property: reorder to a tab’s own index is idempotent (same ref)', () => {+ fc.assert(+ fc.property(fc.array(openOpArb, { minLength: 1, maxLength: 20 }), ops => {+ const state = applyOpens(ops)+ state.tabs.forEach((tab, index) => {+ expect(reorderWorkspaceTab(state, tab.id, index)).toBe(state)+ })+ })+ )+ })++ // T2 property: applying the SAME (id, toIndex) twice is idempotent —+ // reorder(reorder(s, id, k), id, k) === reorder(s, id, k) for any k. After the+ // first move the tab already sits at clamp(k), so the second call bails to the+ // same reference.+ it('property: applying the same (id, toIndex) twice returns the same ref', () => {+ fc.assert(+ fc.property(+ fc.array(openOpArb, { minLength: 1, maxLength: 20 }),+ fc.nat(30),+ (ops, toIndex) => {+ const state = applyOpens(ops)+ const { id: fromId } = state.tabs[toIndex % state.tabs.length]!+ const once = reorderWorkspaceTab(state, fromId, toIndex)+ expect(reorderWorkspaceTab(once, fromId, toIndex)).toBe(once)+ }+ )+ )+ })+})+// ---- T2 property-based (§7) --------------------------------------------------type OpenOp =diff --git a/desktop-app/ui/src/lib/workspaceTabs.ts b/desktop-app/ui/src/lib/workspaceTabs.tsindex 89a40cef9..1a80bf848 100644--- a/desktop-app/ui/src/lib/workspaceTabs.ts+++ b/desktop-app/ui/src/lib/workspaceTabs.ts@@ -336,6 +336,38 @@ export function cycleWorkspaceTab(return { ...state, activeTabId: state.tabs[targetIndex]!.id }}+// ---- reorder (strip drag & drop / keyboard; session-only) -------------------++/**+ * Move a tab to a new position. `toIndex` is the DESIRED FINAL index of the+ * moved tab in the resulting array (0..len-1) — not an insertion slot — so the+ * caller owns "where it lands" and this stays the single source of truth.+ *+ * Reordering NEVER changes `activeTabId`: the route seam derives the active+ * tab's navItem, so with the active id fixed a pure reorder causes no route+ * churn (dragging an inactive tab past the active one, or dragging the active+ * tab itself, both keep the same tab active). Order is the array order — there+ * is no `order` field to keep in sync.+ *+ * No-ops return the SAME reference so a `setState` bails out (no render): an+ * unknown `fromId`, or a `toIndex` that clamps back to the tab's current index+ * — which by construction includes every workspace with fewer than 2 tabs.+ */+export function reorderWorkspaceTab(+ state: WorkspaceTabsState,+ fromId: string,+ toIndex: number+): WorkspaceTabsState {+ const fromIndex = state.tabs.findIndex(tab => tab.id === fromId)+ if (fromIndex < 0) return state+ const clamped = Math.max(0, Math.min(toIndex, state.tabs.length - 1))+ if (clamped === fromIndex) return state+ const tabs = [...state.tabs]+ const [moved] = tabs.splice(fromIndex, 1)+ tabs.splice(clamped, 0, moved!)+ return { ...state, tabs }+}+// ---- close (no re-seed; empty workspace allowed, §5) ------------------------/**diff --git a/desktop-app/ui/src/styles.css b/desktop-app/ui/src/styles.cssindex ab96ead48..07b5fe754 100644--- a/desktop-app/ui/src/styles.css+++ b/desktop-app/ui/src/styles.css@@ -16650,6 +16650,38 @@ pre {flex: 0 0 auto;}+/* Reorder feedback (session-only drag & drop / keyboard). The dragged tab dims;+ a vertical accent bar marks the insertion side. The bar is a pseudo-element so+ it composes with the active tab's top accent box-shadow instead of fighting+ it. */+.chat-view-tab.is-dragging {+ opacity: 0.5;+}++.chat-view-tab.is-drop-before,+.chat-view-tab.is-drop-after {+ position: relative;+}++.chat-view-tab.is-drop-before::after,+.chat-view-tab.is-drop-after::after {+ background: var(--accent);+ bottom: 0;+ content: '';+ position: absolute;+ top: 0;+ width: 2px;+ z-index: 2;+}++.chat-view-tab.is-drop-before::after {+ left: 0;+}++.chat-view-tab.is-drop-after::after {+ right: 0;+}+.chat-view-workspace {--chat-view-selected-border: rgba(var(--accent-rgb), 0.25);