Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: command palette (Cmd/Ctrl+P) (#6846)
Nilay476bea863dd9
diff --git a/studio/frontend/src/app/routes/__root.tsx b/studio/frontend/src/app/routes/__root.tsxindex e0d7838d8d8..da24154925d 100644--- a/studio/frontend/src/app/routes/__root.tsx+++ b/studio/frontend/src/app/routes/__root.tsx@@ -3,6 +3,7 @@import { useAppShellReadySignal } from "@/components/app-readiness";import { AppSidebar } from "@/components/app-sidebar";+import { CommandPalette } from "@/components/command-palette";import { Navbar } from "@/components/navbar";import { SidebarEdgeTrigger } from "@/components/sidebar-edge-trigger";import { SidebarInset, SidebarProvider } from "@/components/ui/sidebar";@@ -54,6 +55,7 @@ import { useIsMobileShell } from "@/hooks/use-mobile";import { useSidebarPin } from "@/hooks/use-sidebar-pin";import { type TranslationKey, useT } from "@/i18n";import { isTauri } from "@/lib/api-base";+import { createNavigationNonce } from "@/lib/navigation-nonce";import {Outlet,createRootRoute,@@ -508,7 +510,7 @@ function RootLayout() {chatRuntime.setIncognito(Boolean(options?.incognito));void navigate({to: "/chat",- search: projectId ? { project: projectId } : { new: crypto.randomUUID() },+ search: projectId ? { project: projectId } : { new: createNavigationNonce() },});};@@ -674,6 +676,7 @@ function RootLayout() {<TransformersUpgradeDialog />{/* At the root, not under /chat: a swap can start from the Hub too. */}<StopRunningChatsDialog />+ {!hideNavbar && <CommandPalette />}{hideNavbar ? (<main className="flex-1 pt-[var(--studio-hidden-route-top-inset,0px)] [--studio-titlebar-height:var(--studio-hidden-route-top-inset,0px)]"><RouteBoundary readyWhenCommitted={!routeOwnsReloadReadiness}>diff --git a/studio/frontend/src/components/app-sidebar.tsx b/studio/frontend/src/components/app-sidebar.tsxindex 792268aaad5..9f1b910c5a5 100644--- a/studio/frontend/src/components/app-sidebar.tsx+++ b/studio/frontend/src/components/app-sidebar.tsx@@ -80,6 +80,7 @@ import {import { WORKFLOW_TABS, type WorkflowId } from "@/features/images/workflows";/* eslint-enable no-restricted-imports */import { cn } from "@/lib/utils";+import { createNavigationNonce } from "@/lib/navigation-nonce";import { copyToClipboardFrom } from "@/lib/copy-to-clipboard";import { isTauri } from "@/lib/api-base";import { useWebUpdateCheck } from "@/hooks/use-web-update-check";@@ -558,13 +559,6 @@ function formatRelativeShort(iso: string): string {return `${d}d`;}-function createNavigationNonce(): string {- if (typeof globalThis.crypto?.randomUUID === "function") {- return globalThis.crypto.randomUUID();- }- return `${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;-}-function preloadSilently(request: Promise<unknown>): void {void request.catch(() => undefined);}diff --git a/studio/frontend/src/components/command-palette.tsx b/studio/frontend/src/components/command-palette.tsxnew file mode 100644index 00000000000..141086a80d0--- /dev/null+++ b/studio/frontend/src/components/command-palette.tsx@@ -0,0 +1,334 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++import { useAnimatedThemeToggle } from "@/components/ui/animated-theme-toggler";+import {+ Command,+ CommandDialog,+ CommandEmpty,+ CommandGroup,+ CommandInput,+ CommandItem,+ CommandList,+ CommandSeparator,+ CommandShortcut,+} from "@/components/ui/command";+import { useIsAccountOwner } from "@/features/auth";+import { useChatSearchStore } from "@/features/chat";+import {+ DIALOG_SETTINGS_SEARCH_INDEX,+ SETTINGS_TABS,+ type SettingsTab,+ type ShortcutId,+ settingsTabVisible,+ triggerShortcut,+ useSettingsDialogStore,+ useShortcut,+ useShortcutAvailable,+ useShortcutLabel,+} from "@/features/settings";+import { useT, type TranslationKey } from "@/i18n";+import { useCommandPaletteStore } from "@/stores/command-palette";+import {+ AudioWave01Icon,+ ChefHatIcon,+ DashboardCircleIcon,+ DownloadSquare01Icon,+ FlimSlateIcon,+ Folder01Icon,+ Globe02Icon,+ Image03Icon,+ LibrariesIcon,+ Message01Icon,+ PencilEdit02Icon,+ Search01Icon,+ Settings02Icon,+ Sun03Icon,+ TestTube01Icon,+} from "@hugeicons/core-free-icons";+import { HugeiconsIcon } from "@hugeicons/react";+import { useNavigate, useRouterState } from "@tanstack/react-router";+import { Moon } from "lucide-react";+import { useEffect, useState } from "react";++// matches sidebar: drop interior bubble paths+const TestTubeOutlineIcon = TestTube01Icon.slice(0, 3) as typeof TestTube01Icon;++// Through the root's workspace shortcuts: gated (Train, Video) and landing (Chat keeps its thread) as the chords do.+const WORKSPACES: {+ id: ShortcutId;+ icon: typeof Message01Icon;+ labelKey: TranslationKey;+ aliases?: string[];+}[] = [+ {+ id: "switchToChat",+ icon: Message01Icon,+ labelKey: "shell.commandPalette.chat",+ },+ {+ id: "switchToProjects",+ icon: Folder01Icon,+ labelKey: "shell.navigation.projects",+ },+ {+ id: "switchToHub",+ icon: DashboardCircleIcon,+ labelKey: "shell.navigation.hub",+ aliases: ["models"],+ },+ {+ id: "switchToTrain",+ icon: TestTubeOutlineIcon,+ labelKey: "shell.navigation.train",+ aliases: ["fine-tune", "training"],+ },+ {+ id: "switchToRecipes",+ icon: ChefHatIcon,+ labelKey: "shell.navigation.recipes",+ aliases: ["data", "datasets"],+ },+ {+ id: "switchToImages",+ icon: Image03Icon,+ labelKey: "shell.navigation.images",+ aliases: ["generate"],+ },+ {+ id: "switchToVideo",+ icon: FlimSlateIcon,+ labelKey: "shell.navigation.video",+ aliases: ["generate"],+ },+ {+ id: "switchToAudio",+ icon: AudioWave01Icon,+ labelKey: "shell.navigation.audio",+ },+ {+ id: "switchToExport",+ icon: DownloadSquare01Icon,+ labelKey: "shell.navigation.export",+ aliases: ["gguf", "checkpoint"],+ },+];++const SETTINGS_TAB_LABELS: Record<SettingsTab, TranslationKey> = {+ general: "settings.tabs.general",+ profile: "settings.tabs.profile",+ accounts: "settings.tabs.accounts",+ appearance: "settings.tabs.appearance",+ resources: "settings.tabs.resources",+ chat: "settings.tabs.chat",+ voice: "settings.tabs.voice",+ connections: "settings.tabs.connections",+ library: "shell.navigation.library",+ data: "settings.tabs.data",+ "api-keys": "settings.tabs.apiKeys",+ "remote-lan": "settings.tabs.remoteLan",+ agents: "settings.tabs.agents",+ "keyboard-shortcuts": "settings.tabs.keyboardShortcuts",+ debugging: "settings.tabs.debugging",+ about: "settings.tabs.about",+};++export function CommandPalette() {+ const isOpen = useCommandPaletteStore((s) => s.isOpen);+ const setOpen = useCommandPaletteStore((s) => s.setOpen);++ useShortcut("openCommandPalette", () =>+ useCommandPaletteStore.getState().toggle(),+ );++ // Auth routes unmount the palette; close it so it does not come back open.+ useEffect(() => () => useCommandPaletteStore.getState().setOpen(false), []);++ // A chord pressed over the palette (⌘, / ⌘K, a workspace or new chat) acts behind it; it gives way.+ const settingsOpen = useSettingsDialogStore((s) => s.open);+ const chatSearchOpen = useChatSearchStore((s) => s.isOpen);+ const href = useRouterState({ select: (s) => s.location.href });+ // biome-ignore lint/correctness/useExhaustiveDependencies: href is the trigger, not an input.+ useEffect(() => {+ useCommandPaletteStore.getState().close();+ }, [href]);+ useEffect(() => {+ if (settingsOpen || chatSearchOpen) {+ useCommandPaletteStore.getState().close();+ }+ }, [settingsOpen, chatSearchOpen]);++ return (+ <CommandDialog+ open={isOpen}+ onOpenChange={setOpen}+ className="w-140 max-w-[calc(100%-2rem)] sm:max-w-140"+ >+ <PaletteContent />+ </CommandDialog>+ );+}++function WorkspaceItem({+ workspace,+ onSelect,+}: {+ workspace: (typeof WORKSPACES)[number];+ onSelect: () => void;+}) {+ const t = useT();+ const available = useShortcutAvailable(workspace.id, false);+ const label = useShortcutLabel(workspace.id);+ if (!available) return null;+ return (+ <CommandItem onSelect={onSelect} keywords={workspace.aliases}>+ <HugeiconsIcon icon={workspace.icon} strokeWidth={1.75} />+ <span>{t(workspace.labelKey)}</span>+ {label && <CommandShortcut>{label}</CommandShortcut>}+ </CommandItem>+ );+}++function PaletteContent() {+ const t = useT();+ const navigate = useNavigate();+ const close = useCommandPaletteStore((s) => s.close);+ const isOwner = useIsAccountOwner();+ const { isDark, toggleTheme, anchorRef } = useAnimatedThemeToggle();+ const [query, setQuery] = useState("");+ // Content stays mounted through the exit animation, so a quick reopen would keep the old filter.+ const isOpen = useCommandPaletteStore((s) => s.isOpen);+ const [wasOpen, setWasOpen] = useState(isOpen);+ if (isOpen !== wasOpen) {+ setWasOpen(isOpen);+ if (isOpen) setQuery("");+ }+ const hasQuery = query.trim().length > 0;+ const newChatAvailable = useShortcutAvailable("newChat", false);+ const newChatLabel = useShortcutLabel("newChat");+ const searchLabel = useShortcutLabel("searchChats");+ const settingsLabel = useShortcutLabel("openSettings");++ const runAndClose = (action: () => void) => () => {+ close();+ action();+ };++ const openSettings = (tab?: SettingsTab) =>+ runAndClose(() => {+ useSettingsDialogStore.getState().openDialog(tab, {+ opener: useCommandPaletteStore.getState().opener,+ });+ });++ return (+ <Command>+ <CommandInput+ placeholder={t("shell.commandPalette.placeholder")}+ value={query}+ onValueChange={setQuery}+ />+ <CommandList className="max-h-105">+ <CommandEmpty className="text-muted-foreground text-xs">+ {t("shell.commandPalette.noResults")}+ </CommandEmpty>+ <CommandGroup heading={t("shell.commandPalette.navigation")}>+ {WORKSPACES.map((workspace) => (+ <WorkspaceItem+ key={workspace.id}+ workspace={workspace}+ onSelect={runAndClose(() => void triggerShortcut(workspace.id))}+ />+ ))}+ <CommandItem+ onSelect={runAndClose(() => void navigate({ to: "/library" }))}+ >+ <HugeiconsIcon icon={LibrariesIcon} strokeWidth={1.75} />+ <span>{t("shell.navigation.library")}</span>+ </CommandItem>+ <CommandItem+ onSelect={runAndClose(() => void navigate({ to: "/api-monitor" }))}+ keywords={["api", "monitor", "requests"]}+ >+ <HugeiconsIcon icon={Globe02Icon} strokeWidth={1.75} />+ <span>{t("shell.navigation.api")}</span>+ </CommandItem>+ <CommandItem onSelect={openSettings()} keywords={["preferences"]}>+ <HugeiconsIcon icon={Settings02Icon} strokeWidth={1.75} />+ <span>{t("shell.navigation.settings")}</span>+ {settingsLabel && (+ <CommandShortcut>{settingsLabel}</CommandShortcut>+ )}+ </CommandItem>+ </CommandGroup>+ <CommandSeparator />+ <CommandGroup heading={t("shell.commandPalette.actions")}>+ {newChatAvailable && (+ <CommandItem+ onSelect={runAndClose(() => void triggerShortcut("newChat"))}+ >+ <HugeiconsIcon icon={PencilEdit02Icon} strokeWidth={1.75} />+ <span>{t("shell.navigation.newChat")}</span>+ {newChatLabel && (+ <CommandShortcut>{newChatLabel}</CommandShortcut>+ )}+ </CommandItem>+ )}+ <CommandItem+ onSelect={runAndClose(() =>+ useChatSearchStore.getState().open({+ opener: useCommandPaletteStore.getState().opener,+ }),+ )}+ >+ <HugeiconsIcon icon={Search01Icon} strokeWidth={1.75} />+ <span>{t("shell.commandPalette.searchChats")}</span>+ {searchLabel && <CommandShortcut>{searchLabel}</CommandShortcut>}+ </CommandItem>+ <CommandItem+ ref={anchorRef as React.Ref<HTMLDivElement>}+ onSelect={runAndClose(() => void toggleTheme())}+ keywords={["theme"]}+ >+ {isDark ? (+ <HugeiconsIcon icon={Sun03Icon} strokeWidth={1.75} />+ ) : (+ <Moon strokeWidth={1.75} className="size-4" />+ )}+ <span>+ {isDark+ ? t("shell.navigation.lightMode")+ : t("shell.navigation.darkMode")}+ </span>+ </CommandItem>+ </CommandGroup>+ {/* Settings pages only once the user types. */}+ {hasQuery && (+ <>+ <CommandSeparator />+ <CommandGroup heading={t("shell.navigation.settings")}>+ {SETTINGS_TABS.filter((tab) =>+ settingsTabVisible(tab, isOwner),+ ).map((tab) => (+ <CommandItem+ key={tab}+ keywords={DIALOG_SETTINGS_SEARCH_INDEX[tab].map((key) =>+ t(key),+ )}+ onSelect={openSettings(tab)}+ >+ <HugeiconsIcon icon={Settings02Icon} strokeWidth={1.75} />+ <span className="text-muted-foreground">+ {t("shell.navigation.settings")}+ </span>+ <span className="text-muted-foreground">→</span>+ <span>{t(SETTINGS_TAB_LABELS[tab])}</span>+ </CommandItem>+ ))}+ </CommandGroup>+ </>+ )}+ </CommandList>+ </Command>+ );+}diff --git a/studio/frontend/src/components/ui/animated-theme-toggler.tsx b/studio/frontend/src/components/ui/animated-theme-toggler.tsxindex e4936b0240b..ef9666fc9db 100644--- a/studio/frontend/src/components/ui/animated-theme-toggler.tsx+++ b/studio/frontend/src/components/ui/animated-theme-toggler.tsx@@ -35,6 +35,7 @@ export function useAnimatedThemeToggle(duration = 400) {// otherwise queue up and land as invisible back-and-forth flips, so the// theme looks stuck until an odd number of clicks gets through.if (inFlightRef.current) return+ const anchorRect = anchorRef.current?.getBoundingClientRect() ?? nullconst applyTheme = () => {flushSync(() => {@@ -58,9 +59,8 @@ export function useAnimatedThemeToggle(duration = 400) {const transition = document.startViewTransition(applyTheme)await transition.ready- const anchor = anchorRef.current- if (anchor) {- const { top, left, width, height } = anchor.getBoundingClientRect()+ if (anchorRect) {+ const { top, left, width, height } = anchorRectconst x = left + width / 2const y = top + height / 2const maxRadius = Math.hypot(diff --git a/studio/frontend/src/components/ui/command.tsx b/studio/frontend/src/components/ui/command.tsxindex f766bc8bcdc..c6cdcb732bf 100644--- a/studio/frontend/src/components/ui/command.tsx+++ b/studio/frontend/src/components/ui/command.tsx@@ -42,6 +42,7 @@ function CommandDialog({className,overlayClassName,showCloseButton = false,+ onCloseAutoFocus,...props}: React.ComponentProps<typeof Dialog> & {title?: string;@@ -49,6 +50,7 @@ function CommandDialog({className?: string;overlayClassName?: string;showCloseButton?: boolean;+ onCloseAutoFocus?: React.ComponentProps<typeof DialogContent>["onCloseAutoFocus"];}) {return (<Dialog {...props}>@@ -63,6 +65,7 @@ function CommandDialog({)}overlayClassName={overlayClassName}showCloseButton={showCloseButton}+ onCloseAutoFocus={onCloseAutoFocus}>{children}</DialogContent>diff --git a/studio/frontend/src/features/chat/components/chat-search-dialog.tsx b/studio/frontend/src/features/chat/components/chat-search-dialog.tsxindex 385edd16752..ab63f3c8f5a 100644--- a/studio/frontend/src/features/chat/components/chat-search-dialog.tsx+++ b/studio/frontend/src/features/chat/components/chat-search-dialog.tsx@@ -66,6 +66,7 @@ export function ChatSearchDialog() {const isOpen = useChatSearchStore((s) => s.isOpen);const setOpen = useChatSearchStore((s) => s.setOpen);const close = useChatSearchStore((s) => s.close);+ const opener = useChatSearchStore((s) => s.opener);const navigate = useNavigate();const { items, loading } = useChatSearchIndex(isOpen);const [query, setQuery] = useState("");@@ -121,6 +122,12 @@ export function ChatSearchDialog() {<CommandDialogopen={isOpen}onOpenChange={setOpen}+ onCloseAutoFocus={(event) => {+ if (opener?.isConnected) {+ event.preventDefault();+ opener.focus({ preventScroll: true });+ }+ }}className="chat-search-surface rounded-3xl! max-sm:rounded-none! top-1/2 -translate-y-1/2 w-[calc(635px*var(--ui-space-scale,1))] max-w-[calc(100%-2rem)] gap-0 p-0 ring-0 duration-[180ms] ease-[cubic-bezier(0.16,1,0.3,1)] sm:max-w-[calc(635px*var(--ui-space-scale,1))]"overlayClassName="bg-transparent supports-backdrop-filter:backdrop-blur-none">diff --git a/studio/frontend/src/features/chat/stores/chat-search-store.ts b/studio/frontend/src/features/chat/stores/chat-search-store.tsindex 3719d4f10f3..18ae15491c3 100644--- a/studio/frontend/src/features/chat/stores/chat-search-store.ts+++ b/studio/frontend/src/features/chat/stores/chat-search-store.ts@@ -1,18 +1,45 @@// SPDX-License-Identifier: AGPL-3.0-only// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0+import { captureFocusedElement } from "@/lib/focus";import { create } from "zustand";+interface OpenChatSearchOptions {+ opener?: HTMLElement | null;+}+interface ChatSearchStore {isOpen: boolean;- open: () => void;+ // Radix cannot recover a trigger that unmounted first (the command palette).+ opener: HTMLElement | null;+ open: (options?: OpenChatSearchOptions) => void;close: () => void;setOpen: (open: boolean) => void;}export const useChatSearchStore = create<ChatSearchStore>((set) => ({isOpen: false,- open: () => set({ isOpen: true }),+ opener: null,+ open: (options) =>+ set((state) =>+ state.isOpen+ ? state+ : {+ isOpen: true,+ opener:+ options?.opener !== undefined+ ? options.opener+ : captureFocusedElement(),+ },+ ),close: () => set({ isOpen: false }),- setOpen: (isOpen) => set({ isOpen }),+ // Opener survives close: onCloseAutoFocus reads it after this update.+ setOpen: (isOpen) =>+ set((state) =>+ isOpen+ ? state.isOpen+ ? state+ : { isOpen: true, opener: captureFocusedElement() }+ : { isOpen: false },+ ),}));diff --git a/studio/frontend/src/features/settings/dialog-search-index.ts b/studio/frontend/src/features/settings/dialog-search-index.tsnew file mode 100644index 00000000000..4d8aa12db9c--- /dev/null+++ b/studio/frontend/src/features/settings/dialog-search-index.ts@@ -0,0 +1,18 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++import { getClientPlatform } from "@/components/tauri/window-titlebar";+import { isTauri } from "@/lib/api-base";+import { createSettingsSearchIndex } from "./settings-search";++const clientPlatform = getClientPlatform();++/** What the Settings dialog searches on this build; the command palette matches tabs on it too. */+export const DIALOG_SETTINGS_SEARCH_INDEX = createSettingsSearchIndex({+ desktop: isTauri,+ closeToTray:+ isTauri &&+ (clientPlatform.startsWith("win") ||+ clientPlatform.includes("windows") ||+ clientPlatform.includes("linux")),+});diff --git a/studio/frontend/src/features/settings/index.ts b/studio/frontend/src/features/settings/index.tsindex 84294356066..effde1179f8 100644--- a/studio/frontend/src/features/settings/index.ts+++ b/studio/frontend/src/features/settings/index.ts@@ -101,6 +101,7 @@ export {export type { ShortcutId } from "./lib/keyboard-shortcuts";export { SETTINGS_TABS, useSettingsDialogStore } from "./stores/settings-dialog-store";export { settingsTabVisible } from "./settings-tab-visibility";+export { DIALOG_SETTINGS_SEARCH_INDEX } from "./dialog-search-index";export type { SettingsTab } from "./stores/settings-dialog-store";export { requestSttDownload } from "./stores/stt-download-prompt-store";export {diff --git a/studio/frontend/src/features/settings/lib/keyboard-shortcuts.ts b/studio/frontend/src/features/settings/lib/keyboard-shortcuts.tsindex b0975192ff7..828bd5af6f5 100644--- a/studio/frontend/src/features/settings/lib/keyboard-shortcuts.ts+++ b/studio/frontend/src/features/settings/lib/keyboard-shortcuts.ts@@ -62,6 +62,7 @@ export type ShortcutId =| "copyChatAsMarkdown"| "copySessionId"| "forkChat"+ | "openCommandPalette"| "searchChats"| "renameChat"| "openKeyboardShortcuts";@@ -237,6 +238,9 @@ export const SHORTCUT_DEFS: ShortcutDef[] = [nonMacDefaultBinding: "Mod+Alt+KeyC",}),def("forkChat", null),+ // Takes the browser's Print, like find above takes its Find: printing a chat+ // shell is of no use, and the event is cancellable in every engine.+ def("openCommandPalette", "Mod+KeyP"),// No ⇧⌘P alternate: it is the command-menu chord everywhere else, but in// Firefox it opens a private window, and ⌘K is the one people reach for.def("searchChats", "Mod+KeyK"),diff --git a/studio/frontend/src/features/settings/settings-dialog.tsx b/studio/frontend/src/features/settings/settings-dialog.tsxindex 21de076443b..ee7e8084eb9 100644--- a/studio/frontend/src/features/settings/settings-dialog.tsx+++ b/studio/frontend/src/features/settings/settings-dialog.tsx@@ -3,7 +3,6 @@import { useIsAccountOwner } from "@/features/auth";import { resolveSettingsTab, settingsTabVisible } from "./settings-tab-visibility";-import { getClientPlatform } from "@/components/tauri/window-titlebar";import { Button } from "@/components/ui/button";import {Dialog,@@ -12,7 +11,6 @@ import {DialogTitle,} from "@/components/ui/dialog";import { type TranslationKey, useT } from "@/i18n";-import { isTauri } from "@/lib/api-base";import { useHubSource } from "@/lib/hf-endpoint";import { MicIcon } from "@/lib/mic-icon";import { cn } from "@/lib/utils";@@ -53,11 +51,8 @@ import {useState,useSyncExternalStore,} from "react";-import {- SETTINGS_SEARCH_KEYWORDS,- createSettingsSearchIndex,- renderedSearchEntries,-} from "./settings-search";+import { DIALOG_SETTINGS_SEARCH_INDEX as SETTINGS_SEARCH_INDEX } from "./dialog-search-index";+import { SETTINGS_SEARCH_KEYWORDS, renderedSearchEntries } from "./settings-search";import {type SettingsTab,useSettingsDialogStore,@@ -265,15 +260,6 @@ const TABS: TabDef[] = [{ id: "about", labelKey: "settings.tabs.about", icon: HelpCircleIcon },];-const clientPlatform = getClientPlatform();-const SETTINGS_SEARCH_INDEX = createSettingsSearchIndex({- desktop: isTauri,- closeToTray:- isTauri &&- (clientPlatform.startsWith("win") ||- clientPlatform.includes("windows") ||- clientPlatform.includes("linux")),-});/*** Stack the tab rail over the pane when the dialog is narrower than it is atdiff --git a/studio/frontend/src/features/settings/settings-search.ts b/studio/frontend/src/features/settings/settings-search.tsindex 8a20b8d2169..b1a62926a80 100644--- a/studio/frontend/src/features/settings/settings-search.ts+++ b/studio/frontend/src/features/settings/settings-search.ts@@ -273,6 +273,7 @@ export const SETTINGS_SEARCH_INDEX: Record<SettingsTab, TranslationKey[]> = {"settings.keyboardShortcuts.actions.copyChatAsMarkdown.label","settings.keyboardShortcuts.actions.copySessionId.label","settings.keyboardShortcuts.actions.forkChat.label",+ "settings.keyboardShortcuts.actions.openCommandPalette.label","settings.keyboardShortcuts.actions.searchChats.label","settings.keyboardShortcuts.actions.renameChat.label","settings.keyboardShortcuts.actions.openKeyboardShortcuts.label",diff --git a/studio/frontend/src/features/settings/stores/settings-dialog-store.ts b/studio/frontend/src/features/settings/stores/settings-dialog-store.tsindex 91df1519193..03d3d7fe0d2 100644--- a/studio/frontend/src/features/settings/stores/settings-dialog-store.ts+++ b/studio/frontend/src/features/settings/stores/settings-dialog-store.ts@@ -43,6 +43,7 @@ export type ArchivedShelf = "chats" | "images" | "videos" | "audio";interface OpenDialogOptions {scrollTarget?: SettingsScrollTarget;focusFallback?: HTMLElement | null;+ opener?: HTMLElement | null;}interface SettingsDialogState {@@ -90,6 +91,7 @@ function captureOpener(): HTMLElement | null {function focusForOpen(state: SettingsDialogState,requestedFallback: HTMLElement | null = null,+ requestedOpener?: HTMLElement | null,) {if (state.open) {return {@@ -97,6 +99,10 @@ function focusForOpen(openerFallback: state.openerFallback,};}+ // Handoff from a dialog that closed first (the command palette).+ if (requestedOpener !== undefined) {+ return { opener: requestedOpener, openerFallback: requestedFallback };+ }const opener = captureOpener();if (opener?.closest("[data-slot=dialog-content]")) {return {@@ -194,7 +200,7 @@ export const useSettingsDialogStore = create<SettingsDialogState>((set) => ({logFamilyRequested: pending.logFamilyRequested,logSourcePathRequested: pending.logSourcePathRequested,connectionRequested: pending.connectionRequested,- ...focusForOpen(state, options?.focusFallback),+ ...focusForOpen(state, options?.focusFallback, options?.opener),};}),openArchivedChats: () =>diff --git a/studio/frontend/src/i18n/locales/ar.ts b/studio/frontend/src/i18n/locales/ar.tsindex a6543a2e11b..319d3b3fb76 100644--- a/studio/frontend/src/i18n/locales/ar.ts+++ b/studio/frontend/src/i18n/locales/ar.ts@@ -203,6 +203,14 @@ export const ar = {logOut: "تسجيل الخروج",shutdown: "إيقاف التشغيل",},+ commandPalette: {+ placeholder: "اكتب أمرًا أو ابحث...",+ noResults: "لم يُعثر على أي نتائج.",+ navigation: "التنقل",+ actions: "الإجراءات",+ chat: "الدردشة",+ searchChats: "ابحث في الدردشات...",+ },notFound: {title: "الصفحة غير موجودة",description: "{path} غير موجود.",@@ -479,6 +487,10 @@ export const ar = {label: "اختصارات لوحة المفاتيح",description: "فتح قائمة الاختصارات هذه",},+ openCommandPalette: {+ label: "لوحة الأوامر",+ description: "فتح لوحة الأوامر",+ },searchChats: {label: "بحث في المحادثات",description: "فتح مربع حوار بحث المحادثات",diff --git a/studio/frontend/src/i18n/locales/de.ts b/studio/frontend/src/i18n/locales/de.tsindex 572a8ec8cf7..78454f782a3 100644--- a/studio/frontend/src/i18n/locales/de.ts+++ b/studio/frontend/src/i18n/locales/de.ts@@ -206,6 +206,14 @@ export const de = {logOut: "Abmelden",shutdown: "Herunterfahren",},+ commandPalette: {+ placeholder: "Befehl eingeben oder suchen...",+ noResults: "Keine Ergebnisse gefunden.",+ navigation: "Navigation",+ actions: "Aktionen",+ chat: "Chat",+ searchChats: "Chats durchsuchen...",+ },notFound: {title: "Seite nicht gefunden",description: "{path} existiert nicht.",@@ -483,6 +491,10 @@ export const de = {label: "Tastenkürzel",description: "Diese Kürzelliste öffnen",},+ openCommandPalette: {+ label: "Befehlspalette",+ description: "Die Befehlspalette öffnen",+ },searchChats: {label: "Chats durchsuchen",description: "Die Chat-Suche öffnen",diff --git a/studio/frontend/src/i18n/locales/en.ts b/studio/frontend/src/i18n/locales/en.tsindex ba3a25dc81a..d912f899df2 100644--- a/studio/frontend/src/i18n/locales/en.ts+++ b/studio/frontend/src/i18n/locales/en.ts@@ -208,6 +208,14 @@ export const en = {logOut: "Log out",shutdown: "Shutdown",},+ commandPalette: {+ placeholder: "Type a command or search...",+ noResults: "No results found.",+ navigation: "Navigation",+ actions: "Actions",+ chat: "Chat",+ searchChats: "Search chats...",+ },notFound: {title: "Page not found",description: "{path} does not exist.",@@ -486,6 +494,10 @@ export const en = {label: "Keyboard shortcuts",description: "Open this shortcuts list",},+ openCommandPalette: {+ label: "Command palette",+ description: "Open the command palette",+ },searchChats: {label: "Search chats",description: "Open the chat search dialog",diff --git a/studio/frontend/src/i18n/locales/es.ts b/studio/frontend/src/i18n/locales/es.tsindex ad27bf116e3..2ca8d60fddf 100644--- a/studio/frontend/src/i18n/locales/es.ts+++ b/studio/frontend/src/i18n/locales/es.ts@@ -205,6 +205,14 @@ export const es = {logOut: "Cerrar sesión",shutdown: "Apagar",},+ commandPalette: {+ placeholder: "Escribe un comando o busca...",+ noResults: "No se encontraron resultados.",+ navigation: "Navegación",+ actions: "Acciones",+ chat: "Chat",+ searchChats: "Buscar chats...",+ },notFound: {title: "Página no encontrada",description: "{path} no existe.",@@ -482,6 +490,10 @@ export const es = {label: "Atajos de teclado",description: "Abrir esta lista de atajos",},+ openCommandPalette: {+ label: "Paleta de comandos",+ description: "Abrir la paleta de comandos",+ },searchChats: {label: "Buscar chats",description: "Abrir el diálogo de búsqueda de chats",diff --git a/studio/frontend/src/i18n/locales/fr.ts b/studio/frontend/src/i18n/locales/fr.tsindex b80cd6292d5..44b55b20a94 100644--- a/studio/frontend/src/i18n/locales/fr.ts+++ b/studio/frontend/src/i18n/locales/fr.ts@@ -206,6 +206,14 @@ export const fr = {logOut: "Se déconnecter",shutdown: "Arrêter",},+ commandPalette: {+ placeholder: "Saisissez une commande ou recherchez...",+ noResults: "Aucun résultat trouvé.",+ navigation: "Navigation",+ actions: "Actions",+ chat: "Chat",+ searchChats: "Rechercher des chats...",+ },notFound: {title: "Page introuvable",description: "{path} n'existe pas.",@@ -483,6 +491,10 @@ export const fr = {label: "Raccourcis clavier",description: "Ouvrir cette liste de raccourcis",},+ openCommandPalette: {+ label: "Palette de commandes",+ description: "Ouvrir la palette de commandes",+ },searchChats: {label: "Rechercher dans les discussions",description: "Ouvrir la recherche de discussions",diff --git a/studio/frontend/src/i18n/locales/hi.ts b/studio/frontend/src/i18n/locales/hi.tsindex 9e1f3d73c3d..66772a1fba3 100644--- a/studio/frontend/src/i18n/locales/hi.ts+++ b/studio/frontend/src/i18n/locales/hi.ts@@ -206,6 +206,14 @@ export const hi = {logOut: "लॉग आउट",shutdown: "शटडाउन",},+ commandPalette: {+ placeholder: "कमांड टाइप करें या खोजें...",+ noResults: "कोई परिणाम नहीं मिला।",+ navigation: "नेविगेशन",+ actions: "क्रियाएँ",+ chat: "चैट",+ searchChats: "चैट खोजें...",+ },notFound: {title: "पेज नहीं मिला",description: "{path} मौजूद नहीं है।",@@ -482,6 +490,10 @@ export const hi = {label: "कीबोर्ड शॉर्टकट",description: "यह शॉर्टकट सूची खोलें",},+ openCommandPalette: {+ label: "कमांड पैलेट",+ description: "कमांड पैलेट खोलें",+ },searchChats: {label: "चैट खोजें",description: "चैट खोज संवाद खोलें",diff --git a/studio/frontend/src/i18n/locales/it.ts b/studio/frontend/src/i18n/locales/it.tsindex b069f63e4ae..88982e9a27b 100644--- a/studio/frontend/src/i18n/locales/it.ts+++ b/studio/frontend/src/i18n/locales/it.ts@@ -165,6 +165,14 @@ export const it = {logOut: "Esci",shutdown: "Arresta",},+ commandPalette: {+ placeholder: "Digita un comando o cerca...",+ noResults: "Nessun risultato trovato.",+ navigation: "Navigazione",+ actions: "Azioni",+ chat: "Chat",+ searchChats: "Cerca nelle chat...",+ },notFound: {title: "Pagina non trovata",description: "{path} non esiste.",@@ -442,6 +450,10 @@ export const it = {label: "Scorciatoie da tastiera",description: "Apri questo elenco di scorciatoie",},+ openCommandPalette: {+ label: "Tavolozza dei comandi",+ description: "Apri la tavolozza dei comandi",+ },searchChats: {label: "Cerca nelle chat",description: "Apri la ricerca delle chat",diff --git a/studio/frontend/src/i18n/locales/ja.ts b/studio/frontend/src/i18n/locales/ja.tsindex 0bad934c145..3cb71a906a5 100644--- a/studio/frontend/src/i18n/locales/ja.ts+++ b/studio/frontend/src/i18n/locales/ja.ts@@ -205,6 +205,14 @@ export const ja = {logOut: "ログアウト",shutdown: "シャットダウン",},+ commandPalette: {+ placeholder: "コマンドを入力または検索...",+ noResults: "結果が見つかりません。",+ navigation: "ナビゲーション",+ actions: "アクション",+ chat: "チャット",+ searchChats: "チャットを検索...",+ },notFound: {title: "ページが見つかりません",description: "{path} は存在しません。",@@ -481,6 +489,10 @@ export const ja = {label: "キーボードショートカット",description: "このショートカット一覧を開きます",},+ openCommandPalette: {+ label: "コマンドパレット",+ description: "コマンドパレットを開く",+ },searchChats: {label: "チャットを検索",description: "チャット検索ダイアログを開きます",diff --git a/studio/frontend/src/i18n/locales/ko.ts b/studio/frontend/src/i18n/locales/ko.tsindex 04cd3c7a0e3..59a22c70553 100644--- a/studio/frontend/src/i18n/locales/ko.ts+++ b/studio/frontend/src/i18n/locales/ko.ts@@ -203,6 +203,14 @@ export const ko = {logOut: "로그아웃",shutdown: "종료",},+ commandPalette: {+ placeholder: "명령어를 입력하거나 검색하세요...",+ noResults: "결과를 찾을 수 없습니다.",+ navigation: "탐색",+ actions: "작업",+ chat: "채팅",+ searchChats: "채팅 검색...",+ },notFound: {title: "페이지를 찾을 수 없습니다",description: "{path} 경로가 존재하지 않습니다.",@@ -479,6 +487,10 @@ export const ko = {label: "키보드 단축키",description: "이 단축키 목록을 엽니다",},+ openCommandPalette: {+ label: "명령 팔레트",+ description: "명령 팔레트 열기",+ },searchChats: {label: "채팅 검색",description: "채팅 검색 창을 엽니다",diff --git a/studio/frontend/src/i18n/locales/pt-br.ts b/studio/frontend/src/i18n/locales/pt-br.tsindex ad090834af4..d09441b945c 100644--- a/studio/frontend/src/i18n/locales/pt-br.ts+++ b/studio/frontend/src/i18n/locales/pt-br.ts@@ -205,6 +205,14 @@ export const ptBR = {logOut: "Sair",shutdown: "Desligar",},+ commandPalette: {+ placeholder: "Digite um comando ou pesquise...",+ noResults: "Nenhum resultado encontrado.",+ navigation: "Navegação",+ actions: "Ações",+ chat: "Chat",+ searchChats: "Buscar chats...",+ },notFound: {title: "Página não encontrada",description: "{path} não existe.",@@ -481,6 +489,10 @@ export const ptBR = {label: "Atalhos de teclado",description: "Abrir esta lista de atalhos",},+ openCommandPalette: {+ label: "Paleta de comandos",+ description: "Abrir a paleta de comandos",+ },searchChats: {label: "Pesquisar chats",description: "Abrir a busca de chats",diff --git a/studio/frontend/src/i18n/locales/ru.ts b/studio/frontend/src/i18n/locales/ru.tsindex 9b6869ae57f..c8cf0d56c9a 100644--- a/studio/frontend/src/i18n/locales/ru.ts+++ b/studio/frontend/src/i18n/locales/ru.ts@@ -205,6 +205,14 @@ export const ru = {logOut: "Выйти",shutdown: "Выключить",},+ commandPalette: {+ placeholder: "Введите команду или запрос...",+ noResults: "Ничего не найдено.",+ navigation: "Навигация",+ actions: "Действия",+ chat: "Чат",+ searchChats: "Поиск по чатам...",+ },notFound: {title: "Страница не найдена",description: "{path} не существует.",@@ -481,6 +489,10 @@ export const ru = {label: "Сочетания клавиш",description: "Открыть этот список сочетаний",},+ openCommandPalette: {+ label: "Палитра команд",+ description: "Открыть палитру команд",+ },searchChats: {label: "Поиск по чатам",description: "Открыть окно поиска по чатам",diff --git a/studio/frontend/src/i18n/locales/zh-CN.ts b/studio/frontend/src/i18n/locales/zh-CN.tsindex 4c627dacfe1..fde2696734e 100644--- a/studio/frontend/src/i18n/locales/zh-CN.ts+++ b/studio/frontend/src/i18n/locales/zh-CN.ts@@ -201,6 +201,14 @@ export const zhCN = {logOut: "退出登录",shutdown: "关闭服务",},+ commandPalette: {+ placeholder: "输入命令或搜索...",+ noResults: "未找到结果。",+ navigation: "导航",+ actions: "操作",+ chat: "聊天",+ searchChats: "搜索聊天...",+ },notFound: {title: "页面未找到",description: "{path} 不存在。",@@ -477,6 +485,10 @@ export const zhCN = {label: "键盘快捷键",description: "打开该快捷键列表",},+ openCommandPalette: {+ label: "命令面板",+ description: "打开命令面板",+ },searchChats: {label: "搜索聊天",description: "打开聊天搜索对话框",diff --git a/studio/frontend/src/lib/focus.ts b/studio/frontend/src/lib/focus.tsnew file mode 100644index 00000000000..533ffca46e3--- /dev/null+++ b/studio/frontend/src/lib/focus.ts@@ -0,0 +1,10 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++export function captureFocusedElement(): HTMLElement | null {+ return typeof document !== "undefined" &&+ document.activeElement instanceof HTMLElement &&+ document.activeElement !== document.body+ ? document.activeElement+ : null;+}diff --git a/studio/frontend/src/lib/navigation-nonce.ts b/studio/frontend/src/lib/navigation-nonce.tsnew file mode 100644index 00000000000..8ae99157140--- /dev/null+++ b/studio/frontend/src/lib/navigation-nonce.ts@@ -0,0 +1,10 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++// crypto.randomUUID is missing on non-secure (plain HTTP LAN) origins.+export function createNavigationNonce(): string {+ if (typeof globalThis.crypto?.randomUUID === "function") {+ return globalThis.crypto.randomUUID();+ }+ return `${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;+}diff --git a/studio/frontend/src/stores/command-palette.ts b/studio/frontend/src/stores/command-palette.tsnew file mode 100644index 00000000000..fd6306d11d4--- /dev/null+++ b/studio/frontend/src/stores/command-palette.ts@@ -0,0 +1,31 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++import { captureFocusedElement } from "@/lib/focus";+import { create } from "zustand";++interface CommandPaletteStore {+ isOpen: boolean;+ // Handed to the dialog an action opens, since the palette unmounts before that dialog closes.+ opener: HTMLElement | null;+ close: () => void;+ toggle: () => void;+ setOpen: (open: boolean) => void;+}++export const useCommandPaletteStore = create<CommandPaletteStore>((set) => ({+ isOpen: false,+ opener: null,+ close: () => set({ isOpen: false }),+ toggle: () =>+ set((s) =>+ s.isOpen+ ? { isOpen: false }+ : { isOpen: true, opener: captureFocusedElement() },+ ),+ setOpen: (isOpen) =>+ set((s) => {+ if (!isOpen) return { isOpen: false };+ return s.isOpen ? s : { isOpen: true, opener: captureFocusedElement() };+ }),+}));diff --git a/studio/frontend/tests/command-palette-handoffs.test.ts b/studio/frontend/tests/command-palette-handoffs.test.tsnew file mode 100644index 00000000000..1aba98a5816--- /dev/null+++ b/studio/frontend/tests/command-palette-handoffs.test.ts@@ -0,0 +1,73 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++import assert from "node:assert/strict";+import { readFile } from "node:fs/promises";+import test from "node:test";++const REGISTRY_SHORTCUT = /useShortcut\("openCommandPalette"/;+const RAW_KEY_LISTENER = /addEventListener\("keydown"/;+const SETTINGS_INDEX_IMPORT =+ /\bDIALOG_SETTINGS_SEARCH_INDEX,\n[^;]*from "@\/features\/settings"/;+const LOCALIZED_SETTINGS_KEYWORDS =+ /keywords=\{DIALOG_SETTINGS_SEARCH_INDEX\[tab\]\.map\(\(key\) =>\s*t\(key\),?\s*\)\}/;+const HARDCODED_SETTINGS_KEYWORDS = /keywords:\s*\[/;+const PALETTE_SEARCH_OPENER =+ /useChatSearchStore\.getState\(\)\.open\(\{\s*opener: useCommandPaletteStore\.getState\(\)\.opener/s;+const SEARCH_STORE_OPENER = /opener: HTMLElement \| null/;+const EXPLICIT_SEARCH_OPENER = /options\?\.opener !== undefined/;+const SEARCH_CLOSE_FOCUS = /onCloseAutoFocus=\{\(event\) => \{/;+const RESTORE_SEARCH_OPENER = /opener\.focus\(\{ preventScroll: true \}\)/;++const palette = await readFile(+ new URL("../src/components/command-palette.tsx", import.meta.url),+ "utf8",+);+const chatSearchStore = await readFile(+ new URL("../src/features/chat/stores/chat-search-store.ts", import.meta.url),+ "utf8",+);+const chatSearchDialog = await readFile(+ new URL(+ "../src/features/chat/components/chat-search-dialog.tsx",+ import.meta.url,+ ),+ "utf8",+);++test("the command-palette chord comes from the rebindable shortcut registry", () => {+ assert.match(palette, REGISTRY_SHORTCUT);+ assert.doesNotMatch(palette, RAW_KEY_LISTENER);+});++test("settings commands search the localized settings index", () => {+ assert.match(palette, SETTINGS_INDEX_IMPORT);+ assert.match(palette, LOCALIZED_SETTINGS_KEYWORDS);+ assert.doesNotMatch(palette, HARDCODED_SETTINGS_KEYWORDS);+});++test("chat search receives and restores the palette opener", () => {+ assert.match(palette, PALETTE_SEARCH_OPENER);+ assert.match(chatSearchStore, SEARCH_STORE_OPENER);+ assert.match(chatSearchStore, EXPLICIT_SEARCH_OPENER);+ assert.match(chatSearchDialog, SEARCH_CLOSE_FOCUS);+ assert.match(chatSearchDialog, RESTORE_SEARCH_OPENER);+});++test("reopening during the exit animation clears the previous query", () => {+ assert.match(+ palette,+ /if \(isOpen !== wasOpen\) \{\s*setWasOpen\(isOpen\);\s*if \(isOpen\) setQuery\(""\);/,+ );+});++test("a chord that navigates behind the palette closes it", () => {+ assert.match(+ palette,+ /useRouterState\(\{ select: \(s\) => s\.location\.href \}\)/,+ );+ assert.match(+ palette,+ /useEffect\(\(\) => \{\s*useCommandPaletteStore\.getState\(\)\.close\(\);\s*\}, \[href\]\);/,+ );+});diff --git a/studio/frontend/tests/keyboard-shortcuts.test.ts b/studio/frontend/tests/keyboard-shortcuts.test.tsindex 5a8dea4dba4..2e632657114 100644--- a/studio/frontend/tests/keyboard-shortcuts.test.ts+++ b/studio/frontend/tests/keyboard-shortcuts.test.ts@@ -525,6 +525,8 @@ test("no default takes a chord the browser owns without a reason", () => {// because the browser's own find is what it replaces. Reserving it is still// right -- it is what warns a web user before they rebind onto it."Mod+KeyF",+ // The command palette takes Print the same way.+ "Mod+KeyP",]);for (const def of SHORTCUT_DEFS) {for (const slot of SHORTCUT_SLOTS) {@@ -1514,6 +1516,7 @@ test("every action has a useShortcut call site", async () => {const files = ["../src/app/routes/__root.tsx","../src/components/app-sidebar.tsx",+ "../src/components/command-palette.tsx","../src/components/ui/sidebar.tsx","../src/components/assistant-ui/thread.tsx","../src/components/assistant-ui/tool-confirmation-controls.tsx",