Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
feat(sidebar): add Shift/Cmd multi-select with batch delete & archive
vastsa07ba6bd03468
diff --git a/apps/desktop/src/components/Sidebar.tsx b/apps/desktop/src/components/Sidebar.tsxindex c42fb25e2..9eab45510 100644--- a/apps/desktop/src/components/Sidebar.tsx+++ b/apps/desktop/src/components/Sidebar.tsx@@ -281,6 +281,9 @@ export function Sidebar({// Which row menu item is armed for its second, confirming click.const { armed: armedDelete, setArmed: setArmedDelete } = useArmedDelete();const [projectMenu, setProjectMenu] = useState<string | null>(null);+ // Multi-select: Shift/Cmd+click session rows for batch operations.+ const [selectedIds, setSelectedIds] = useState<Set<string>>(new Set());+ const lastClickedIdRef = useRef<string | null>(null);const [sectionMenu, setSectionMenu] = useState<"sessions" | "projects" | null>(null);const [menuPosition, setMenuPosition] = useState<{top: number;@@ -451,6 +454,20 @@ export function Sidebar({};}, []);+ // Escape clears multi-select (only when no menu is open — menus consume+ // their own Escape first, so clearing happens on the next press).+ useEffect(() => {+ if (selectedIds.size === 0) return;+ const onKeyDown = (event: KeyboardEvent) => {+ if (event.key !== "Escape") return;+ // Let menu/sort close handlers consume Escape first.+ if (sessionMenu || projectMenu || sectionMenu || sortOpen) return;+ setSelectedIds(new Set());+ };+ window.addEventListener("keydown", onKeyDown);+ return () => window.removeEventListener("keydown", onKeyDown);+ }, [selectedIds.size, sessionMenu, projectMenu, sectionMenu, sortOpen]);+const showArchived = sessionView.archived;const sessionSort = sessionView.sort;const displaySessionSort: Exclude<SessionSort, "manual"> =@@ -965,6 +982,88 @@ export function Sidebar({() => temporarySessions.filter((session) => !pinnedSessionIds.has(session.id)),[temporarySessions, pinnedSessionIds],);+ // Flat ordered list of every visible session id — used for Shift+click range selection.+ const flatSessionOrder = useMemo(() => {+ const ids: string[] = [];+ // Pinned first (same order as rendered)+ for (const s of pinnedSessions) ids.push(s.id);+ // Then project sessions+ for (const entry of projectEntries) {+ for (const s of entry.sessions) {+ if (!pinnedSessionIds.has(s.id)) ids.push(s.id);+ }+ }+ // Then temporary (standalone) sessions+ for (const s of temporarySessionHistory) ids.push(s.id);+ return ids;+ }, [pinnedSessions, projectEntries, pinnedSessionIds, temporarySessionHistory]);++ /** Handle multi-select click on a session row. Returns true if the click was consumed by multi-select. */+ const handleMultiSelectClick = (event: React.MouseEvent, sessionId: string): boolean => {+ const isMeta = event.metaKey || event.ctrlKey;+ const isShift = event.shiftKey;+ if (!isMeta && !isShift) {+ // Plain click: clear selection, let normal handler run.+ if (selectedIds.size > 0) setSelectedIds(new Set());+ lastClickedIdRef.current = sessionId;+ return false;+ }+ event.preventDefault();+ event.stopPropagation();+ if (isMeta && !isShift) {+ // Toggle individual item+ setSelectedIds((prev) => {+ const next = new Set(prev);+ if (next.has(sessionId)) next.delete(sessionId);+ else next.add(sessionId);+ return next;+ });+ lastClickedIdRef.current = sessionId;+ return true;+ }+ if (isShift) {+ // Range select from lastClickedId to current+ const anchor = lastClickedIdRef.current;+ if (!anchor) {+ setSelectedIds(new Set([sessionId]));+ lastClickedIdRef.current = sessionId;+ return true;+ }+ const startIdx = flatSessionOrder.indexOf(anchor);+ const endIdx = flatSessionOrder.indexOf(sessionId);+ if (startIdx === -1 || endIdx === -1) {+ setSelectedIds(new Set([sessionId]));+ lastClickedIdRef.current = sessionId;+ return true;+ }+ const lo = Math.min(startIdx, endIdx);+ const hi = Math.max(startIdx, endIdx);+ const range = flatSessionOrder.slice(lo, hi + 1);+ setSelectedIds((prev) => {+ const next = new Set(prev);+ for (const id of range) next.add(id);+ return next;+ });+ // Don't update lastClickedIdRef on shift-click so further shifts extend from same anchor+ return true;+ }+ return false;+ };++ // Clear multi-select when sessions list changes (e.g. after batch delete)+ const sessionIdSet = useMemo(() => new Set(sessions.map((s) => s.id)), [sessions]);+ useEffect(() => {+ if (selectedIds.size === 0) return;+ // Remove any selected ids that no longer exist+ let changed = false;+ const next = new Set<string>();+ for (const id of selectedIds) {+ if (sessionIdSet.has(id)) next.add(id);+ else changed = true;+ }+ if (changed) setSelectedIds(next);+ }, [sessionIdSet]); // intentionally not including selectedIds to avoid loop+const renderSessionStatus = (status: SidebarSessionStatus) => {const labelKey =status === "running"@@ -1209,6 +1308,68 @@ export function Sidebar({void deleteSession(session);};+ /** Batch delete: delete all selected sessions sequentially. */+ const batchDeleteSessions = async () => {+ const ids = [...selectedIds];+ if (ids.length === 0) return;+ closeMenus();+ const toDelete = sessions.filter(+ (s) => ids.includes(s.id) && s.source !== "pi-native",+ );+ for (const session of toDelete) {+ try {+ await deleteSessionAction(session.id);+ } catch (error) {+ reportError(error);+ }+ }+ // If we deleted the active session, create or select a fallback+ if (ids.includes(activeSessionId ?? "")) {+ const remaining = sessions.find(+ (s) => !ids.includes(s.id) && !sessionArchived(s, sessionMeta[s.id]),+ );+ try {+ if (remaining) await selectSession(remaining.id);+ else await newSession({ projectPath: null });+ } catch (error) {+ reportError(error);+ }+ }+ setSelectedIds(new Set());+ };++ /** Batch archive: archive all selected sessions. */+ const batchArchiveSessions = async () => {+ const ids = [...selectedIds];+ if (ids.length === 0) return;+ closeMenus();+ for (const id of ids) {+ const session = sessions.find((s) => s.id === id);+ if (!session) continue;+ const alreadyArchived = sessionArchived(session, sessionMeta[session.id]);+ if (alreadyArchived) continue;+ archiveSessionAction(id);+ }+ // If we archived the active session (and it wasn't already archived), select a fallback+ const activeWasArchived = (() => {+ if (!activeSessionId || !ids.includes(activeSessionId)) return false;+ const s = sessions.find((s) => s.id === activeSessionId);+ return s ? !sessionArchived(s, sessionMeta[s.id]) : false;+ })();+ if (activeWasArchived) {+ const remaining = sessions.find(+ (s) => !ids.includes(s.id) && !sessionArchived(s, sessionMeta[s.id]),+ );+ try {+ if (remaining) await selectSession(remaining.id);+ else await newSession({ projectPath: null });+ } catch (error) {+ reportError(error);+ }+ }+ setSelectedIds(new Set());+ };+/** Menu items of different surfaces never share an armed key. */const projectDeleteKey = (entry: ProjectEntry) => `project:${entry.key}`;@@ -1536,7 +1697,7 @@ export function Sidebar({return (<divkey={session.id}- className={`thread-item ${active ? "active" : ""} ${archived ? "archived" : ""} ${draggingSessionId === session.id ? "is-dragging" : ""}`}+ className={`thread-item ${active ? "active" : ""} ${archived ? "archived" : ""} ${draggingSessionId === session.id ? "is-dragging" : ""} ${selectedIds.has(session.id) ? "selected" : ""}`}data-sidebar-session-row={session.id}draggable={!running}onDragStart={(event) => {@@ -1548,12 +1709,9 @@ export function Sidebar({}}onDragEnd={endSessionDrag}onClick={(event) => {- // The row's own controls are the only click targets spelled out in- // markup; a click on the row container or its gap to the actions- // column - including where a hidden overflow control would sit -- // still opens the conversation instead of dying on the wrapper.const target = event.target as HTMLElement | null;if (target?.closest("button, [data-action]")) return;+ if (handleMultiSelectClick(event, session.id)) return;cancelSessionPrefetch();hideSessionHoverCard();void (temporary@@ -1563,6 +1721,11 @@ export function Sidebar({onContextMenu={(event) => {event.preventDefault();event.stopPropagation();+ // If right-clicking a non-selected row while multi-select is active,+ // add it to the selection instead of replacing.+ if (selectedIds.size > 0 && !selectedIds.has(session.id)) {+ setSelectedIds((prev) => new Set([...prev, session.id]));+ }placeMenuAtPoint(event.clientX, event.clientY);openSessionRowMenu(session.id,@@ -1587,7 +1750,8 @@ export function Sidebar({showSessionHoverCard(session, event.currentTarget, temporary)}onBlur={scheduleSessionHoverCardHide}- onClick={() => {+ onClick={(event) => {+ if (handleMultiSelectClick(event, session.id)) return;cancelSessionPrefetch();hideSessionHoverCard();void (temporary@@ -1923,6 +2087,40 @@ export function Sidebar({}}>{session ? (+ selectedIds.size > 1 && selectedIds.has(session.id) ? (+ <>+ <button+ ref={menuFirstItemRef}+ type="button"+ role="menuitem"+ data-action="batch-archive"+ onClick={() => void batchArchiveSessions()}+ >+ <IconArchive size={14} />+ {t("nav.batchArchive", { defaultValue: "Archive {{count}} sessions", count: selectedIds.size })}+ </button>+ <button+ type="button"+ role="menuitem"+ className={cx("danger", armedDelete === "batch" && "is-armed")}+ data-action="batch-delete"+ data-armed={armedDelete === "batch" ? "true" : undefined}+ onClick={() => {+ if (armedDelete !== "batch") {+ setArmedDelete("batch");+ return;+ }+ setArmedDelete(null);+ void batchDeleteSessions();+ }}+ >+ <IconTrash size={14} />+ {armedDelete === "batch"+ ? t("nav.batchDeleteConfirm", { defaultValue: "Delete {{count}} sessions?", count: selectedIds.size })+ : t("nav.batchDelete", { defaultValue: "Delete {{count}} sessions", count: selectedIds.size })}+ </button>+ </>+ ) : (<>{session.source !== "pi-native" ? (<button@@ -2015,6 +2213,7 @@ export function Sidebar({</button>) : null}</>+ )) : null}{entry ? (<>diff --git a/apps/desktop/src/styles/sidebar-threads.css b/apps/desktop/src/styles/sidebar-threads.cssindex 790f143a9..42e5646bb 100644--- a/apps/desktop/src/styles/sidebar-threads.css+++ b/apps/desktop/src/styles/sidebar-threads.css@@ -321,3 +321,15 @@text-overflow: ellipsis;white-space: nowrap;}++/* Multi-select highlight: visually distinct from the single active row. */+.thread-item.selected {+ background: color-mix(in oklab, var(--ds-accent) 12%, transparent);+ color: var(--ds-text-primary);+}++.thread-item.selected.active {+ background: var(--ds-bg-active);+}++diff --git a/packages/i18n/src/locales/de/index.ts b/packages/i18n/src/locales/de/index.tsindex e8ea9e896..9f192e2c0 100644--- a/packages/i18n/src/locales/de/index.ts+++ b/packages/i18n/src/locales/de/index.ts@@ -171,6 +171,9 @@ export const de = {"branchTitle": "{{title}} (Verzweigung)","deleteTask": "Löschen","deleteTaskConfirm": "Löschen?",+ batchArchive: "{{count}} Sitzungen archivieren",+ batchDelete: "{{count}} Sitzungen löschen",+ batchDeleteConfirm: "{{count}} Sitzungen löschen?","copyConversationId": "Gesprächs-ID kopieren","openSessionPath": "Sitzungspfad öffnen","timeGroupYesterday": "Gestern",diff --git a/packages/i18n/src/locales/en/index.ts b/packages/i18n/src/locales/en/index.tsindex 9a151d0d4..c8f55d3f2 100644--- a/packages/i18n/src/locales/en/index.ts+++ b/packages/i18n/src/locales/en/index.ts@@ -178,6 +178,9 @@ export const en = {branchTitle: "{{title}} (branch)",deleteTask: "Delete",deleteTaskConfirm: "Delete?",+ batchArchive: "Archive {{count}} sessions",+ batchDelete: "Delete {{count}} sessions",+ batchDeleteConfirm: "Delete {{count}} sessions?",copyConversationId: "Copy conversation ID",openSessionPath: "Open session path",timeGroupYesterday: "Yesterday",diff --git a/packages/i18n/src/locales/es/index.ts b/packages/i18n/src/locales/es/index.tsindex 527f32c68..60e5966ce 100644--- a/packages/i18n/src/locales/es/index.ts+++ b/packages/i18n/src/locales/es/index.ts@@ -171,6 +171,9 @@ export const es = {"branchTitle": "{{title}} (rama)","deleteTask": "Eliminar","deleteTaskConfirm": "¿Eliminar?",+ batchArchive: "Archivar {{count}} sesiones",+ batchDelete: "Eliminar {{count}} sesiones",+ batchDeleteConfirm: "¿Eliminar {{count}} sesiones?","copyConversationId": "Copiar ID de conversación","openSessionPath": "Abrir ruta de sesión","timeGroupYesterday": "Ayer",diff --git a/packages/i18n/src/locales/fr/index.ts b/packages/i18n/src/locales/fr/index.tsindex 457d12eb2..65a8602e7 100644--- a/packages/i18n/src/locales/fr/index.ts+++ b/packages/i18n/src/locales/fr/index.ts@@ -171,6 +171,9 @@ export const fr = {"branchTitle": "{{title}} (branche)","deleteTask": "Supprimer","deleteTaskConfirm": "Supprimer ?",+ batchArchive: "Archiver {{count}} sessions",+ batchDelete: "Supprimer {{count}} sessions",+ batchDeleteConfirm: "Supprimer {{count}} sessions ?","copyConversationId": "Copier l'ID de conversation","openSessionPath": "Ouvrir le chemin de la session","timeGroupYesterday": "Hier",diff --git a/packages/i18n/src/locales/ko/index.ts b/packages/i18n/src/locales/ko/index.tsindex 68a6265a7..c6058f78e 100644--- a/packages/i18n/src/locales/ko/index.ts+++ b/packages/i18n/src/locales/ko/index.ts@@ -180,6 +180,9 @@ export const ko = {branchTitle: "{{title}} (브랜치)",deleteTask: "삭제",deleteTaskConfirm: "삭제할까요?",+ batchArchive: "{{count}}개 세션 보관",+ batchDelete: "{{count}}개 세션 삭제",+ batchDeleteConfirm: "{{count}}개 세션을 삭제하시겠습니까?",copyConversationId: "대화 ID 복사",openSessionPath: "세션 경로 열기",timeGroupYesterday: "어제",diff --git a/packages/i18n/src/locales/pt-BR/index.ts b/packages/i18n/src/locales/pt-BR/index.tsindex d92ad79c2..79ccc1447 100644--- a/packages/i18n/src/locales/pt-BR/index.ts+++ b/packages/i18n/src/locales/pt-BR/index.ts@@ -170,6 +170,9 @@ export const ptBR = {branchTitle: "{{title}} (ramificação)",deleteTask: "Excluir",deleteTaskConfirm: "Excluir?",+ batchArchive: "Arquivar {{count}} sessões",+ batchDelete: "Excluir {{count}} sessões",+ batchDeleteConfirm: "Excluir {{count}} sessões?",copyConversationId: "Copiar ID da conversa",openSessionPath: "Abrir caminho da sessão",timeGroupYesterday: "Ontem",diff --git a/packages/i18n/src/locales/tr/index.ts b/packages/i18n/src/locales/tr/index.tsindex 7e67c5133..05b208566 100644--- a/packages/i18n/src/locales/tr/index.ts+++ b/packages/i18n/src/locales/tr/index.ts@@ -180,6 +180,9 @@ export const tr = {branchTitle: "{{title}} (dal)",deleteTask: "Sil",deleteTaskConfirm: "Silinsin mi?",+ batchArchive: "{{count}} oturumu arşivle",+ batchDelete: "{{count}} oturumu sil",+ batchDeleteConfirm: "{{count}} oturum silinsin mi?",copyConversationId: "Konuşma kimliğini kopyala",openSessionPath: "Oturum yolunu aç",timeGroupYesterday: "Dün",diff --git a/packages/i18n/src/locales/zh-CN/index.ts b/packages/i18n/src/locales/zh-CN/index.tsindex 12e35cd33..bedb27b4d 100644--- a/packages/i18n/src/locales/zh-CN/index.ts+++ b/packages/i18n/src/locales/zh-CN/index.ts@@ -173,6 +173,9 @@ export const zhCN = {branchTitle: "{{title}}(分支)",deleteTask: "删除",deleteTaskConfirm: "确认删除?",+ batchArchive: "归档 {{count}} 个会话",+ batchDelete: "删除 {{count}} 个会话",+ batchDeleteConfirm: "确认删除 {{count}} 个会话?",copyConversationId: "复制对话 ID",openSessionPath: "打开会话路径",timeGroupYesterday: "昨天",diff --git a/packages/i18n/src/locales/zh-TW/index.ts b/packages/i18n/src/locales/zh-TW/index.tsindex 9b42f509c..99dcb50e7 100644--- a/packages/i18n/src/locales/zh-TW/index.ts+++ b/packages/i18n/src/locales/zh-TW/index.ts@@ -173,6 +173,9 @@ export const zhTW = {branchTitle: "{{title}}(分支)",deleteTask: "刪除",deleteTaskConfirm: "確認刪除?",+ batchArchive: "封存 {{count}} 個對話",+ batchDelete: "刪除 {{count}} 個對話",+ batchDeleteConfirm: "確認刪除 {{count}} 個對話?",copyConversationId: "複製對話 ID",openSessionPath: "開啟會話路徑",timeGroupYesterday: "昨天",