Official
palette
Built-in command palette (⌘⇧P) and chat search (⌘P).
The app opens the listing; nothing installs until an agent in your Plugins workspace has read the files and you enable the plugin. In a terminal: dvg install divergence/palette@0.2.5
Permissions in 0.2.5
Files
model.test.ts9.8 KB
// Preserve the palette matching, ranking, and navigation assertions.
// These tests import the pure model directly, using the same cases as the JavaScript suite.
import assert from "node:assert/strict";
import test from "node:test";
import { RECENT_LIMIT, commandLabel, keptWhileSame, modeOf, move, rankChats, rankCommands, remember, shownRows, SIDE } from "./model.ts";
import { activeAt, chatMarkOf } from "../sdk/ui/chat-row.ts";
const command = (
id: string,
title: string,
extra: { category?: string; enabled?: boolean; registered?: boolean } = {},
) => ({ id, title, category: extra.category, enabled: true, registered: true, ...extra });
test("commands: hidden when their when is false or their plugin does not run", () => {
const commands = [
command("a.one", "Open", { category: "Alpha" }),
command("b.two", "Open Later", { enabled: false }),
command("c.three", "Open Other", { registered: false }),
];
assert.deepEqual(
rankCommands(commands, "open").map((r) => r.command.id),
["a.one"],
);
assert.deepEqual(
rankCommands(commands, "").map((r) => r.command.id),
["a.one"],
);
});
test("commands: fuzzy on the title and the category, recently run first", () => {
const commands = [
command("git.toggle", "Show Source Control", { category: "Git" }),
command("sidebar.newChat", "New Chat", { category: "Sidebar" }),
command("chat.switchNext", "Switch to the Previous Chat", { category: "Chat" }),
command("kernel.quit", "Quit Divergence", { category: "Divergence" }),
];
assert.deepEqual(
rankCommands(commands, "git").map((r) => r.command.id),
["git.toggle"],
"the category is searched",
);
assert.equal(rankCommands(commands, "new chat")[0].command.id, "sidebar.newChat");
// With no query: recent first, then by label.
const listed = rankCommands(commands, "", ["kernel.quit", "chat.switchNext"]).map((r) => r.command.id);
assert.deepEqual(listed, ["kernel.quit", "chat.switchNext", "git.toggle", "sidebar.newChat"]);
// A recent command wins a close match.
const ranked = rankCommands([command("a.x", "Toggle A"), command("b.x", "Toggle B")], "toggle", ["b.x"]);
assert.equal(ranked[0].command.id, "b.x");
assert.equal(commandLabel(commands[0]), "Git: Show Source Control");
assert.equal(commandLabel({ title: "Plain" }), "Plain");
});
// The row draws "Category: Title", so a query that matches only in the
// title ("how" loses the category's "h" of "Chat") must mark the title's
// letters in the label, not the label's first letters.
test("commands: a match in the title alone marks the title's letters in the label", () => {
const [ranked] = rankCommands([command("git.show", "Show Source Control", { category: "Chat" })], "how");
assert.ok(ranked);
const label = commandLabel(ranked.command);
assert.equal(ranked.positions.map((at) => label[at]).join(""), "how");
});
test("chats: by title and workspace, newest first, archived ones never", () => {
const workspaces = { w1: { name: "nexus" }, w2: { name: "landing" } };
const chats = [
{ id: "a", title: "Fix the palette", workspaceId: "w1", updatedAt: "2026-09-20" },
{ id: "b", title: "Hero section", workspaceId: "w2", updatedAt: "2026-09-25" },
{ id: "c", title: "Old palette notes", workspaceId: "w1", updatedAt: "2026-09-01", archived: true },
];
assert.deepEqual(
rankChats(chats, workspaces, "").map((r) => r.chat.id),
["b", "a"],
);
assert.deepEqual(
rankChats(chats, workspaces, "palette").map((r) => r.chat.id),
["a"],
);
assert.deepEqual(
rankChats(chats, workspaces, "landing").map((r) => r.chat.id),
["b"],
"the workspace name is searched",
);
assert.deepEqual(rankChats(chats, workspaces, "zzz"), []);
});
test("the chat search switches mode by prefix", () => {
const providers = [
{ plugin: "files", id: "files", prefix: "@" },
{ plugin: "x", id: "long", prefix: "@@" },
];
assert.deepEqual(modeOf("> new", providers), { mode: "commands", query: "new" });
const mode = modeOf("@@deep", providers);
assert.equal(mode.mode, "provider");
assert.ok(mode.mode === "provider");
assert.equal(mode.provider.id, "long", "the longest prefix wins");
assert.deepEqual(modeOf("@main.rs", providers), { mode: "provider", provider: providers[0], query: "main.rs" });
assert.deepEqual(modeOf("hello", providers), { mode: "chats", query: "hello" });
});
test("the selection wraps; recent commands are bounded", () => {
assert.equal(move(0, 3, -1), 2);
assert.equal(move(2, 3, 1), 0);
assert.equal(move(0, 0, 1), 0);
let recent: string[] = [];
for (let i = 0; i < RECENT_LIMIT + 5; i++) recent = remember(recent, `c${i}`);
assert.equal(recent.length, RECENT_LIMIT);
assert.equal(remember(recent, recent[3])[0], recent[3]);
});
// A longer title used to lose to a shorter one that matched the same way, so
// an older chat came before the one the user worked on a minute ago.
test("chats that match equally well come most recently active first", () => {
const workspaces = { w1: { name: "nexus" } };
const chats = [
{ id: "old", title: "Palette", workspaceId: "w1", updatedAt: "2026-09-01" },
{ id: "new", title: "Palette rows two lines tall", workspaceId: "w1", updatedAt: "2026-09-20" },
{ id: "inside", title: "Fix the palette", workspaceId: "w1", updatedAt: "2026-09-30" },
];
assert.deepEqual(
rankChats(chats, workspaces, "palette").map((r) => r.chat.id),
["inside", "new", "old"],
"a title that starts with the text is no better than one with it inside",
);
assert.deepEqual(
rankChats(chats, workspaces, "nexus").map((r) => r.chat.id),
["inside", "new", "old"],
);
});
// "cmd+p" listed a chat from October that said "cmd+shift+g ... pane" above
// today's chats that said "cmd+p": letters picked apart at word starts
// scored more than the words typed, found whole.
test("chats holding the words typed come first, the newest of them first", () => {
const workspaces = { w1: { name: "nexus" } };
const chats = [
{ id: "apart", title: "Make cmd+shift+g open the git pane", workspaceId: "w1", updatedAt: "2026-10-29" },
{ id: "older", title: "Make it so when I hit cmd+n and make a new chat or the plugin", workspaceId: "w1", updatedAt: "2026-09-19" },
{ id: "whole", title: "Make cmd+p focus the cmd+p chat search", workspaceId: "w1", updatedAt: "2026-11-14T11:53" },
{ id: "newest", title: "Make the search button open the cmd+p search menu", workspaceId: "w1", updatedAt: "2026-11-14T12:41" },
{ id: "inside", title: "Note that xcmd+pane is a word", workspaceId: "w1", updatedAt: "2026-11-15" },
{ id: "first", title: "cmd+p does nothing", workspaceId: "w1", updatedAt: "2026-01-01" },
];
const ranked = rankChats(chats, workspaces, "cmd+p");
assert.deepEqual(
ranked.map((r) => r.chat.id),
["newest", "whole", "first", "inside", "apart", "older"],
"whole at word starts (at the beginning or further on), then whole inside a word, each newest first, then letters apart",
);
const title = chats[2].title;
assert.equal(ranked[1].positions.map((at) => title[at]).join(""), "cmd+p", "the words found whole are the ones marked");
assert.deepEqual(
rankChats(chats, workspaces, "search cmd+p").map((r) => r.chat.id),
["newest", "whole"],
"each word of several found whole, in any order",
);
});
test("a chat's row says when it was last active, the nearer the shorter", () => {
const now = new Date(2026, 10, 14, 15, 0).getTime();
const at = (...parts: [number, number, number, number, number]) => new Date(...parts).toISOString();
assert.equal(activeAt(at(2026, 10, 14, 9, 5), now, "en-US"), "9:05 AM");
assert.equal(activeAt(at(2026, 10, 13, 21, 30), now, "en-US"), "Yesterday, 9:30 PM");
assert.equal(activeAt(at(2026, 2, 3, 8, 0), now, "en-US"), "Mar 3, 8:00 AM");
assert.equal(activeAt(at(2025, 11, 31, 8, 0), now, "en-US"), "Dec 31, 2025");
assert.equal(activeAt("not a date", now), "");
});
test("a chat's status mark: waiting on you, at work with its subagents, failed or idle", () => {
assert.equal(chatMarkOf({ status: "waiting_question" }), "blocked");
assert.equal(chatMarkOf({ status: "running" }), "running");
assert.equal(chatMarkOf({ status: "idle", working: { agents: 1, commands: 0 } }), "running");
assert.equal(chatMarkOf({ status: "idle", working: { agents: 0, commands: 2 } }), "idle");
assert.equal(chatMarkOf({ status: "failed" }), "failed");
assert.equal(chatMarkOf({ status: "running" }, true), "done", "a checked-off chat shows its check whatever it does");
});
// Every arrow key used to rank every chat again, and to put every chat's
// time in words, so moving the selection took a fifth of a second with
// hundreds of chats.
test("the rows are made again only when what they come from changed", () => {
let query = "a";
let made = 0;
const rows = keptWhileSame(() => [query], () => ++made);
assert.equal(rows(), 1);
assert.equal(rows(), 1, "the same query keeps the rows");
query = "ab";
assert.equal(rows(), 2);
});
// Hundreds of chats used to be windowed by the plugin alone, eight rows at
// a time, so the wheel could not scroll them; the scroller now holds them,
// and a long list is sent as the rows around where the reader is.
test("a long list sends the rows around its top and the selection", () => {
assert.deepEqual(shownRows(40, 0, 0, 8), [0, 40], "a short list is sent whole");
const count = 1000;
assert.deepEqual(shownRows(count, 0, 0, 8), [0, 8 + SIDE]);
assert.deepEqual(shownRows(count, 500, 503, 8), [500 - SIDE, 508 + SIDE]);
const [lo, hi] = shownRows(count, 0, 900, 8);
assert.ok(lo <= 900 && hi > 900, "the selection is always among the rows sent, so the list can bring it into view");
assert.equal(shownRows(count, 990, 995, 8)[1], count);
// Past the kernel's margin on both sides of the top, so it asks again only once the rows must move.
const [from, to] = shownRows(count, 400, 400, 8);
assert.ok(400 - from > 150 && to - 400 > 150);
});
No comments yet.