Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
feat(ui): quick switcher lists nothing until typed, then A to Z
rubenluetke10-beep001597e1b44c
diff --git a/jarvis/ui/web/frontend/src/components/QuickSwitchList.tsx b/jarvis/ui/web/frontend/src/components/QuickSwitchList.tsxindex 44a78a9862..af98c879aa 100644--- a/jarvis/ui/web/frontend/src/components/QuickSwitchList.tsx+++ b/jarvis/ui/web/frontend/src/components/QuickSwitchList.tsx@@ -35,6 +35,10 @@ import {} from "@/lib/agenticIdeApi";import {ambiguousEntryKeys,+ compareMatches,+ labelStartsWith,+ normalizeQuery,+ SHORT_QUERY,rankQuickSwitch,strongSettingsMatches,type QuickSwitchEntry,@@ -75,7 +79,7 @@ const GROUP = cn();/** How many live results each group may show, so the sections stay in view. */-const LIMIT = { chats: 6, terminals: 6, workspaces: 4, recentChats: 4 } as const;+const LIMIT = { chats: 6, terminals: 6, workspaces: 4 } as const;/** Row sizes: the Spotlight window is roomier than the sidebar dropdown. */const SIZE = {@@ -188,32 +192,45 @@ export function QuickSwitchList({// About forty destinations — ranked inline on every keystroke, no memo needed.const labelFor = (item: QuickSwitchEntry) => label(item.labelKey, item.fallbackLabel);- const ranked = rankQuickSwitch(query, labelFor);const ambiguous = ambiguousEntryKeys(labelFor);+ // A label two rows share names its area up front, e.g. "Voice › API Keys"+ // beside the API Keys page itself — and the alphabet follows what is SHOWN,+ // so that row sorts under "V…", where the eye looks for it.+ const ranked = rankQuickSwitch(query, labelFor)+ .map((row) => {+ const area = row.entry.parentLabelKey ? label(row.entry.parentLabelKey, "") : "";+ const shown = area && ambiguous.has(row.entry.key) ? `${area} › ${row.label}` : row.label;+ return { ...row, area, shown, prefix: labelStartsWith(shown, normalizeQuery(query)) };+ })+ // One or two letters list only what visibly starts with them: "a" must not+ // show "Voice › API Keys" just because the tab underneath is "API Keys".+ .filter((row) => row.prefix || normalizeQuery(query).length > SHORT_QUERY)+ .sort((a, b) => compareMatches({ ...a, label: a.shown }, { ...b, label: b.shown }));const settingsMatches = useMemo(() => strongSettingsMatches(query, searchSettingsOptions(language, query, t)),[query, language, t],);- // Nothing typed yet: the most recent chats, like Spotlight's recents.- const chatHits = typed- ? rankItems(query, chatRows, (row) => [row.title, row.preview], LIMIT.chats)- : chatRows.slice(0, LIMIT.recentChats);- const paneHits = typed- ? rankItems(- query,- panes,- (pane) => [pane.recap, pane.last_prompt, pane.display_name, pane.key, pane.workspace_name],- LIMIT.terminals,- )- : [];- const workspaceHits = typed- ? rankItems(- query,- workspaces,- (workspace) => [workspace.name, folderName(workspace.folder), workspace.branch],- LIMIT.workspaces,- )- : [];+ const chatHits = rankItems(+ query,+ chatRows,+ (row) => [row.title, row.preview],+ LIMIT.chats,+ (row) => row.title || row.preview,+ );+ const paneHits = rankItems(+ query,+ panes,+ (pane) => [pane.recap, pane.last_prompt, pane.display_name, pane.key, pane.workspace_name],+ LIMIT.terminals,+ paneTitle,+ );+ const workspaceHits = rankItems(+ query,+ workspaces,+ (workspace) => [workspace.name, folderName(workspace.folder), workspace.branch],+ LIMIT.workspaces,+ (workspace) => workspace.name,+ );const rowValues = [...ranked.map(({ entry }) => `section:${entry.key}`),@@ -229,6 +246,9 @@ export function QuickSwitchList({// eslint-disable-next-line react-hooks/exhaustive-deps}, [signature]);+ // Nothing typed: no list at all — the field stands alone, like Spotlight.+ if (!typed) return null;+const go = (item: QuickSwitchEntry) => {if (item.surface) setSurface(item.surface);setActiveSection(item.section);@@ -267,12 +287,8 @@ export function QuickSwitchList({</Command.Empty>{ranked.length > 0 && (<Command.Group heading={t("quick_switch.group_sections")} className={GROUP}>- {ranked.map(({ entry: item, label: text }) => {+ {ranked.map(({ entry: item, label: text, area, shown }) => {const here = item.section === activeSection && !item.surface;- const area = item.parentLabelKey ? label(item.parentLabelKey, "") : "";- // A label two rows share names its area up front, e.g.- // "Voice › API Keys" beside the API Keys page itself.- const shown = area && ambiguous.has(item.key) ? `${area} › ${text}` : text;return (<ResultRowkey={item.key}@@ -289,10 +305,7 @@ export function QuickSwitchList({</Command.Group>)}{chatHits.length > 0 && (- <Command.Group- heading={t(typed ? "quick_switch.group_chats" : "quick_switch.group_recent_chats")}- className={GROUP}- >+ <Command.Group heading={t("quick_switch.group_chats")} className={GROUP}>{chatHits.map((row) => (<ResultRowkey={`${row.kind}:${row.id}`}diff --git a/jarvis/ui/web/frontend/src/components/QuickSwitcher.test.tsx b/jarvis/ui/web/frontend/src/components/QuickSwitcher.test.tsxindex 9d4e2ff422..9a0b1b70f3 100644--- a/jarvis/ui/web/frontend/src/components/QuickSwitcher.test.tsx+++ b/jarvis/ui/web/frontend/src/components/QuickSwitcher.test.tsx@@ -42,10 +42,25 @@ describe("QuickSwitcher", () => {});afterEach(cleanup);- it("lists every destination before anything is typed", () => {+ it("shows the field alone until something is typed", () => {renderOpen();- expect(screen.getByTestId("quick-switch-agentic-ide")).toBeTruthy();- expect(screen.getByTestId("quick-switch-settings")).toBeTruthy();+ expect(screen.queryByTestId("quick-switch-agentic-ide")).toBeNull();+ expect(document.querySelectorAll("[cmdk-item]")).toHaveLength(0);+ });++ it("lists the A-names A to Z after one letter", () => {+ renderOpen();+ fireEvent.change(screen.getByTestId("quick-switcher-input"), { target: { value: "a" } });+ // Each group is alphabetical on its own; the sections group comes first.+ const sections = document.querySelector("[cmdk-group]");+ const labels = [...(sections?.querySelectorAll("[cmdk-item]") ?? [])].map(+ (row) => row.querySelector("span.min-w-0")?.textContent ?? "",+ );+ expect(labels.length).toBeGreaterThan(3);+ // Every SHOWN name starts with A — "Voice › API Keys" does not, so it is out.+ for (const label of labels) expect(label.toLowerCase().startsWith("a")).toBe(true);+ const sorted = [...labels].sort((x, y) => x.localeCompare(y, undefined, { sensitivity: "base" }));+ expect(labels).toEqual(sorted);});it("goes to the top match on Enter and closes", () => {@@ -60,6 +75,7 @@ describe("QuickSwitcher", () => {it("flips the front page to the face that was picked", () => {useHomeStore.getState().setSurface("voice");renderOpen();+ fireEvent.change(screen.getByTestId("quick-switcher-input"), { target: { value: "chat" } });fireEvent.click(screen.getByTestId("quick-switch-chat"));expect(useEventStore.getState().activeSection).toBe("chats");expect(useHomeStore.getState().surface).toBe("chat");@@ -134,8 +150,10 @@ describe("QuickSwitcher", () => {});afterEach(() => vi.unstubAllGlobals());- it("lists recent chats before anything is typed", () => {+ it("finds a chat by the first letter of its title", () => {renderOpen();+ expect(screen.queryByTestId("quick-switch-chat-c1")).toBeNull();+ fireEvent.change(screen.getByTestId("quick-switcher-input"), { target: { value: "b" } });expect(screen.getByTestId("quick-switch-chat-c1")).toBeTruthy();});diff --git a/jarvis/ui/web/frontend/src/components/QuickSwitcher.tsx b/jarvis/ui/web/frontend/src/components/QuickSwitcher.tsxindex 4aeec23d2e..c0fd9e9eba 100644--- a/jarvis/ui/web/frontend/src/components/QuickSwitcher.tsx+++ b/jarvis/ui/web/frontend/src/components/QuickSwitcher.tsx@@ -88,7 +88,7 @@ export function QuickSwitcher({onFirstChange={setSelected}className="max-h-[min(30rem,62dvh)] border-t border-border"/>- <div className="flex items-center justify-end gap-4 border-t border-border px-4 py-2 text-xs text-muted-foreground">+ {query.trim() && <div className="flex items-center justify-end gap-4 border-t border-border px-4 py-2 text-xs text-muted-foreground"><span className="inline-flex items-center gap-1.5"><kbd className="inline-flex h-5 items-center rounded border border-border px-1 font-sans"><CornerDownLeft className="h-3 w-3" aria-hidden />@@ -99,7 +99,7 @@ export function QuickSwitcher({<kbd className="inline-flex h-5 items-center rounded border border-border px-1 font-sans">esc</kbd>{t("quick_switch.hint_close")}</span>- </div>+ </div>}</Command></Dialog.Content></Dialog.Portal>diff --git a/jarvis/ui/web/frontend/src/components/layout/InlineQuickSwitch.test.tsx b/jarvis/ui/web/frontend/src/components/layout/InlineQuickSwitch.test.tsxindex 1de8a58bb5..e1c5d103c4 100644--- a/jarvis/ui/web/frontend/src/components/layout/InlineQuickSwitch.test.tsx+++ b/jarvis/ui/web/frontend/src/components/layout/InlineQuickSwitch.test.tsx@@ -39,8 +39,10 @@ describe("InlineQuickSwitch", () => {beforeEach(() => useEventStore.getState().setActiveSection("chats"));afterEach(cleanup);- it("stays closed until focused", () => {- renderField();+ it("stays closed until something is typed", () => {+ const input = renderField();+ expect(screen.queryByTestId("sidebar-search-results")).toBeNull();+ fireEvent.focus(input);expect(screen.queryByTestId("sidebar-search-results")).toBeNull();});@@ -60,9 +62,11 @@ describe("InlineQuickSwitch", () => {const input = renderField();fireEvent.focus(input);fireEvent.change(input, { target: { value: "set" } });+ expect(screen.getByTestId("sidebar-search-results")).toBeTruthy();fireEvent.keyDown(input, { key: "Escape" });+ // Cleared: an empty field shows no list, but keeps the focus.expect(input.value).toBe("");- expect(screen.getByTestId("sidebar-search-results")).toBeTruthy();+ expect(screen.queryByTestId("sidebar-search-results")).toBeNull();fireEvent.keyDown(input, { key: "Escape" });expect(screen.queryByTestId("sidebar-search-results")).toBeNull();});diff --git a/jarvis/ui/web/frontend/src/components/layout/InlineQuickSwitch.tsx b/jarvis/ui/web/frontend/src/components/layout/InlineQuickSwitch.tsxindex 3579bdea77..c8a3721dc2 100644--- a/jarvis/ui/web/frontend/src/components/layout/InlineQuickSwitch.tsx+++ b/jarvis/ui/web/frontend/src/components/layout/InlineQuickSwitch.tsx@@ -144,6 +144,7 @@ export function InlineQuickSwitch({</div>{open &&rect &&+ query.trim() !== "" &&createPortal(<divdata-testid="sidebar-search-results"diff --git a/jarvis/ui/web/frontend/src/lib/quickSwitch.test.ts b/jarvis/ui/web/frontend/src/lib/quickSwitch.test.tsindex f3aafad94c..407d6796b2 100644--- a/jarvis/ui/web/frontend/src/lib/quickSwitch.test.ts+++ b/jarvis/ui/web/frontend/src/lib/quickSwitch.test.ts@@ -48,9 +48,33 @@ describe("destinations", () => {});describe("ranking", () => {- it("lists everything in sidebar order for an empty query", () => {- const rows = rankQuickSwitch("", englishLabel);- expect(rows.map((r) => r.entry.key)).toEqual(QUICK_SWITCH_ENTRIES.map((e) => e.key));+ it("lists nothing until something is typed", () => {+ expect(rankQuickSwitch("", englishLabel)).toEqual([]);+ expect(rankQuickSwitch(" ", englishLabel)).toEqual([]);+ });++ it("lists, for one letter, exactly the names starting with it, A to Z", () => {+ const rows = rankQuickSwitch("a", englishLabel);+ const labels = rows.map((r) => r.label);+ expect(labels.length).toBeGreaterThan(3);+ for (const label of labels) expect(label.toLowerCase().startsWith("a")).toBe(true);+ const sorted = [...labels].sort((x, y) => x.localeCompare(y, undefined, { sensitivity: "base" }));+ expect(labels).toEqual(sorted);+ expect(labels).toContain("Agentic IDE");+ expect(labels).toContain("Artifacts");+ });++ it("does not reach through synonyms on one or two letters", () => {+ // "Board" carries the synonym "activity"; "a" must still list only A-names.+ expect(rankQuickSwitch("a", englishLabel).map((r) => r.entry.key)).not.toContain("board");+ });++ it("puts names that start with the query before names that only contain it", () => {+ const rows = rankQuickSwitch("voice", englishLabel);+ const firstOther = rows.findIndex((r) => !r.prefix);+ const lastPrefix = rows.map((r) => r.prefix).lastIndexOf(true);+ expect(rows[0].label).toBe("Voice");+ if (firstOther !== -1) expect(lastPrefix).toBeLessThan(firstOther);});it.each([diff --git a/jarvis/ui/web/frontend/src/lib/quickSwitch.ts b/jarvis/ui/web/frontend/src/lib/quickSwitch.tsindex 44f024be3e..7a9050b987 100644--- a/jarvis/ui/web/frontend/src/lib/quickSwitch.ts+++ b/jarvis/ui/web/frontend/src/lib/quickSwitch.ts@@ -257,19 +257,50 @@ export function scoreTerm(term: string, needle: string): number {return 0;}-/** How far a tab ranks below a top-level page with the same match quality. */-const TAB_PENALTY = 25;+/**+ * Up to this many letters a query only matches what a row is CALLED, from its+ * first letter: "a" lists exactly the rows whose name starts with A. Longer+ * queries also reach a row through its other-language names and synonyms+ * ("einst" finds Settings, "ollama" Local models).+ */+export const SHORT_QUERY = 2;++/** Alphabetical, case- and accent-blind, numbers in natural order. */+export function compareLabels(a: string, b: string): number {+ return a.localeCompare(b, undefined, { sensitivity: "base", numeric: true });+}++/**+ * The order every result group shares: rows whose name STARTS with the query+ * first, then the rest; alphabetical within each. So "a" reads like an index+ * (Aa… first, Az… last) and an exact name is still on top — "Voice" before+ * "Voice Shortcuts" — because the shortest matching name sorts first.+ */+export function compareMatches(+ a: { label: string; prefix: boolean },+ b: { label: string; prefix: boolean },+): number {+ if (a.prefix !== b.prefix) return a.prefix ? -1 : 1;+ return compareLabels(a.label, b.label);+}++/** Does this name start with the query (accents and case folded)? */+export function labelStartsWith(label: string, needle: string): boolean {+ return normalizeQuery(label).startsWith(needle);+}export interface RankedEntry {entry: QuickSwitchEntry;label: string;- score: number;+ /** The name starts with the query — these rows lead the group. */+ prefix: boolean;}/**- * The entries that match, best first. An empty query lists everything in- * sidebar order, so the switcher doubles as a browsable map of the app.- * Ties keep sidebar order — `Array.prototype.sort` is stable.+ * The entries that match, in `compareMatches` order. An empty query matches+ * nothing: the switcher shows its field alone until something is typed.+ * Two rows with the same name (the API Keys page and the voice tab of that+ * name) keep the page first.*/export function rankQuickSwitch(query: string,@@ -277,19 +308,21 @@ export function rankQuickSwitch(entries: readonly QuickSwitchEntry[] = QUICK_SWITCH_ENTRIES,): RankedEntry[] {const needle = normalizeQuery(query);- const all = entries.map((item) => {+ if (!needle) return [];+ const rows: RankedEntry[] = [];+ for (const item of entries) {const label = labelFor(item);- let score = needle- ? Math.max(0, ...entryTerms(item, label).map((term) => scoreTerm(term, needle)))- : 1;- // A tab inside another area yields to a page of its own on the same word:- // "API Keys" means the API Keys page, not the voice section's key tab, and- // a word for "language" the app languages, not the dictation language. Large enough to- // drop an exact tab hit (100) below a page's prefix hit (80).- if (needle && score > 0 && item.parentLabelKey) score = Math.max(1, score - TAB_PENALTY);- return { entry: item, label, score };- });- return all.filter((row) => row.score > 0).sort((a, b) => b.score - a.score);+ const prefix = labelStartsWith(label, needle);+ const matches =+ prefix ||+ (needle.length > SHORT_QUERY &&+ entryTerms(item, label).some((term) => scoreTerm(term, needle) > 0));+ if (matches) rows.push({ entry: item, label, prefix });+ }+ return rows.sort(+ (a, b) =>+ compareMatches(a, b) || Number(Boolean(a.entry.parentLabelKey)) - Number(Boolean(b.entry.parentLabelKey)),+ );}/**@@ -308,9 +341,14 @@ export function strongSettingsMatches<T extends { label: string; detail?: stringif (!needle) return [];return matches.filter((match) =>- [match.label, match.detail ?? ""].some((text) => scoreTerm(normalizeQuery(text), needle) >= 60),+ needle.length <= SHORT_QUERY+ ? labelStartsWith(match.label, needle)+ : [match.label, match.detail ?? ""].some((text) => scoreTerm(normalizeQuery(text), needle) >= 60),)- .slice(0, limit);+ .map((match) => ({ match, label: match.label, prefix: labelStartsWith(match.label, needle) }))+ .sort(compareMatches)+ .slice(0, limit)+ .map((row) => row.match);}/**diff --git a/jarvis/ui/web/frontend/src/lib/quickSwitchSources.ts b/jarvis/ui/web/frontend/src/lib/quickSwitchSources.tsindex 91f252baaa..f25a4ccadf 100644--- a/jarvis/ui/web/frontend/src/lib/quickSwitchSources.ts+++ b/jarvis/ui/web/frontend/src/lib/quickSwitchSources.ts@@ -9,7 +9,13 @@* initials > mid-word from four letters), so "ide" still does not find* "provide" here either.*/-import { normalizeQuery, scoreTerm } from "@/lib/quickSwitch";+import {+ SHORT_QUERY,+ compareMatches,+ labelStartsWith,+ normalizeQuery,+ scoreTerm,+} from "@/lib/quickSwitch";/** 0 when some word of the query is found nowhere in `fields`. */export function matchScore(query: string, fields: readonly (string | null | undefined)[]): number {@@ -26,19 +32,30 @@ export function matchScore(query: string, fields: readonly (string | null | unde}/**- * The items that match, best first, at most `limit`. Ties keep the input- * order, which the callers make "most recent first".+ * The items that match, at most `limit`, in the order the sections use: names+ * starting with the query first, alphabetical within each part. A query of up+ * to `SHORT_QUERY` letters matches the NAME from its first letter only ("a"+ * lists the chats whose title starts with A); a longer one matches when every+ * word is found anywhere in `fields`.*/export function rankItems<T>(query: string,items: readonly T[],fields: (item: T) => readonly (string | null | undefined)[],limit: number,+ labelOf: (item: T) => string = (item) => fields(item)[0] ?? "",): T[] {+ const needle = normalizeQuery(query);+ if (!needle) return [];return items- .map((item, index) => ({ item, index, score: matchScore(query, fields(item)) }))- .filter((row) => row.score > 0)- .sort((a, b) => b.score - a.score || a.index - b.index)+ .map((item) => {+ const label = labelOf(item);+ const prefix = labelStartsWith(label, needle);+ const hit = needle.length <= SHORT_QUERY ? prefix : prefix || matchScore(query, fields(item)) > 0;+ return { item, label, prefix, hit };+ })+ .filter((row) => row.hit)+ .sort(compareMatches).slice(0, limit).map((row) => row.item);}