This commit is contained in:
Timothy Jaeryang Baek committed 2026-06-06 00:39:19 -04:00
1 parent c1e8636dd1
commit e0badc879c
3 files changed
+64 -12

No files matched your search

@@ -5,6 +5,7 @@
workspaceList,
currentWorkspace,
removeWorkspace,
reorderWorkspaces,
sidebarOpen,
} from '$lib/stores';
import Sortable from 'sortablejs';
@@ -30,10 +31,15 @@
let appVersion = $state('');
let menuButtonEl: HTMLButtonElement | undefined = $state();
let wsListEl: HTMLDivElement | undefined = $state();
let sortable: Sortable | null = null;
// Current workspace path from URL
const currentPath = $derived($page.url.searchParams.get('workspace'));
function isTouchDevice(): boolean {
return typeof window !== 'undefined' && ('ontouchstart' in window || navigator.maxTouchPoints > 0);
}
function handleWorkspaceClick(e: MouseEvent, path: string) {
// Let Cmd/Ctrl+click open in new tab naturally (it's an <a>)
if (e.metaKey || e.ctrlKey) return;
@@ -82,6 +88,25 @@
getWelcome()
.then(d => { appVersion = d.version || ''; })
.catch(() => {});
// Enable drag-reorder on non-touch devices
if (wsListEl && !isTouchDevice()) {
sortable = Sortable.create(wsListEl, {
animation: 150,
ghostClass: 'opacity-30',
dragClass: 'cursor-grabbing',
direction: 'vertical',
onEnd: (evt) => {
if (evt.oldIndex != null && evt.newIndex != null && evt.oldIndex !== evt.newIndex) {
reorderWorkspaces(evt.oldIndex, evt.newIndex);
}
},
});
}
});
onDestroy(() => {
sortable?.destroy();
});
</script>
@@ -1,6 +1,7 @@
<script lang="ts">
import { onMount } from 'svelte';
import { toolApprovalMode, type ToolApprovalMode } from '$lib/stores';
import { tooltip } from '$lib/tooltip';
interface Props {
onfiles: (files: FileList) => void;
@@ -14,10 +15,10 @@
let pos = $state<{ x: number; bottom: number }>({ x: -9999, bottom: -9999 });
let ready = $state(false);
const modes: { value: ToolApprovalMode; label: string }[] = [
{ value: 'ask', label: 'Ask for approval' },
{ value: 'auto', label: 'Approve for me' },
{ value: 'full', label: 'Full access' },
const modes: { value: ToolApprovalMode; label: string; desc: string }[] = [
{ value: 'ask', label: 'Ask for approval', desc: 'Confirm each tool call before it runs' },
{ value: 'auto', label: 'Auto-approve', desc: 'Approve safe actions, ask for risky ones' },
{ value: 'full', label: 'Full access', desc: 'All tool calls run without confirmation' },
];
function toggle() {
@@ -116,6 +117,7 @@
? 'text-gray-900 dark:text-white bg-gray-50 dark:bg-white/5'
: 'text-gray-500 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-white/5 hover:text-gray-900 dark:hover:text-white'}"
onclick={() => selectMode(mode.value)}
use:tooltip={{ content: mode.desc, placement: 'right' }}
>
<span class="flex-1 text-left truncate">{mode.label}</span>
{#if $toolApprovalMode === mode.value}
+33 -8
View File
@@ -69,6 +69,7 @@ export interface UserPreferences {
sidebarOpen: boolean;
toolApprovalMode: ToolApprovalMode;
locale: string;
workspaceOrder?: string[]; // ordered paths for sidebar drag-reorder
}
export type Theme = 'dark' | 'light' | 'system';
@@ -114,7 +115,7 @@ export const workspaceList = writable<{ path: string; name: string }[]>([]);
/** Global user preferences. */
export const sidebarOpen = writable(typeof window !== 'undefined' ? window.innerWidth >= 768 : false);
export const theme = writable<Theme>('dark');
export const toolApprovalMode = writable<ToolApprovalMode>('ask');
export const toolApprovalMode = writable<ToolApprovalMode>('auto');
/** @deprecated Use toolApprovalMode */
export const autoApproveTools = {
subscribe: toolApprovalMode.subscribe,
@@ -125,6 +126,9 @@ export const stateLoaded = writable(false);
export const gitReviewOpen = writable(false);
export const isGitRepo = writable(false);
/** Saved workspace path order for sidebar drag-reorder. */
export const workspaceOrder = writable<string[]>([]);
// ── Derived stores ──────────────────────────────────────────────
/** @deprecated Alias for currentWorkspace. Helps migration of existing imports */
@@ -251,6 +255,7 @@ function persistPreferences(): void {
sidebarOpen: get(sidebarOpen),
toolApprovalMode: get(toolApprovalMode),
locale: i18next.language,
workspaceOrder: get(workspaceOrder),
};
savePreferences(prefs as unknown as Record<string, unknown>).catch(() => {});
}, 300);
@@ -264,6 +269,7 @@ function subscribeForPersistence() {
theme.subscribe(() => { if (get(stateLoaded)) persistPreferences(); });
sidebarOpen.subscribe(() => { if (get(stateLoaded)) persistPreferences(); });
toolApprovalMode.subscribe(() => { if (get(stateLoaded)) persistPreferences(); });
workspaceOrder.subscribe(() => { if (get(stateLoaded)) persistPreferences(); });
i18next.on('languageChanged', () => { if (get(stateLoaded)) persistPreferences(); });
}
@@ -282,6 +288,7 @@ export async function loadPreferences(): Promise<void> {
toolApprovalMode.set((prefs.autoApproveTools as unknown as boolean) ? 'full' : 'ask');
}
if (prefs.locale) changeLocale(prefs.locale as string);
if (Array.isArray(prefs.workspaceOrder)) workspaceOrder.set(prefs.workspaceOrder as string[]);
} catch {
// First run, no preferences yet
}
@@ -292,6 +299,12 @@ export async function loadPreferences(): Promise<void> {
export async function loadWorkspaceList(): Promise<void> {
try {
const list = await getWorkspaceList();
const order = get(workspaceOrder);
if (order.length > 0 && list) {
// Sort by saved order; unknown paths go to end
const orderMap = new Map(order.map((p, i) => [p, i]));
list.sort((a, b) => (orderMap.get(a.path) ?? Infinity) - (orderMap.get(b.path) ?? Infinity));
}
workspaceList.set(list || []);
} catch {
workspaceList.set([]);
@@ -404,12 +417,19 @@ export function addWorkspace(path: string): void {
if (list.some((w) => w.path === path)) return list;
return [...list, { path, name }];
});
// Append to order
workspaceOrder.update((order) => {
if (order.includes(path)) return order;
return [...order, path];
});
}
export async function removeWorkspace(path: string): Promise<void> {
const { deleteWorkspace: deleteWs } = await import('$lib/apis/state');
await deleteWs(path);
workspaceList.update((list) => list.filter((w) => w.path !== path));
workspaceOrder.update((order) => order.filter((p) => p !== path));
// If this was the current workspace, clear it
const ws = get(currentWorkspace);
@@ -418,6 +438,18 @@ export async function removeWorkspace(path: string): Promise<void> {
}
}
/** Reorder workspaces in the sidebar (from drag-and-drop). */
export function reorderWorkspaces(oldIndex: number, newIndex: number): void {
workspaceList.update((list) => {
const reordered = [...list];
const [moved] = reordered.splice(oldIndex, 1);
reordered.splice(newIndex, 0, moved);
// Sync order preference
workspaceOrder.set(reordered.map((w) => w.path));
return reordered;
});
}
export function updateWorkspace(partial: Partial<WorkspaceState>): void {
currentWorkspace.update((ws) => {
if (!ws) return ws;
@@ -879,10 +911,3 @@ export function setSplitRatio(ratio: number): void {
ws ? { ...ws, splitRatio: Math.max(0.2, Math.min(0.8, ratio)) } : ws
);
}
// ── Workspace tab reordering (no-op now, workspaces are in sidebar list) ──
export function reorderWorkspaces(_oldIndex: number, _newIndex: number): void {
// Workspace ordering is now managed by the server-side workspace list.
// This is a no-op stub to avoid breaking existing imports.
}