Official
sidebar
Built-in sidebar UI (JavaScript UI plugin).
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/sidebar@0.2.7
Permissions in 0.2.7
Files
rest-prefetch.test.ts3.8 KB
// Reading a chat ahead builds its whole pane, which the kernel takes on the
// main thread, so the sidebar reads ahead only on a sign of intent: a row the
// pointer rests on, or Cmd held for a check-off. A pointer sweeping down the
// list reads nothing.
import assert from "node:assert/strict";
import { afterEach, mock, test } from "node:test";
import activate from "./main.ts";
import { REST_MS } from "./rest.ts";
import { fakeHost } from "./testing.ts";
afterEach(() => mock.timers.reset());
const day = (n: number) => `2026-10-0${n}T00:00:00.000Z`;
function setup() {
const prefetched: string[] = [];
const fake = fakeHost(
[
{ id: "c1", title: "First", at: day(3) },
{ id: "c2", title: "Second", at: day(2) },
{ id: "c3", title: "Third", at: day(1) },
],
[],
{
queued: () => [],
draftTitles: () => ({}),
starting: () => [],
prefetch: (params) => void prefetched.push((params as { chatId: string }).chatId),
},
);
return { fake, prefetched };
}
const flush = () => new Promise<void>((resolve) => setImmediate(resolve));
// A row's pointer event, once the sidebar has acted on it.
const pointer = async (fake: ReturnType<typeof fakeHost>, id: string, event: "onPointerEnter" | "onPointerLeave") => {
fake.click(`row-${id}`, event);
await flush();
};
test("a pointer sweeping over rows reads none of them ahead", async () => {
const { fake, prefetched } = setup();
const dispose = activate(fake.api);
try {
await fake.settle();
for (const id of ["c1", "c2", "c3"]) {
await pointer(fake, id, "onPointerEnter");
mock.timers.tick(REST_MS / 3);
await pointer(fake, id, "onPointerLeave");
}
mock.timers.tick(REST_MS * 4);
await fake.settle();
assert.deepEqual(prefetched, []);
} finally {
await dispose();
}
});
test("a pointer resting on a row reads that chat ahead once", async () => {
const { fake, prefetched } = setup();
const dispose = activate(fake.api);
try {
await fake.settle();
await pointer(fake, "c1", "onPointerEnter");
mock.timers.tick(REST_MS / 3);
await pointer(fake, "c1", "onPointerLeave");
await pointer(fake, "c2", "onPointerEnter");
mock.timers.tick(REST_MS);
await fake.settle();
assert.deepEqual(prefetched, ["c2"]);
await pointer(fake, "c2", "onPointerEnter");
mock.timers.tick(REST_MS * 2);
await fake.settle();
assert.deepEqual(prefetched, ["c2", "c2"], "entering again after the read rests again");
} finally {
await dispose();
}
});
// Checking off the chat on screen shows the next open chat, which is read
// ahead when the pointer rests on the row of the chat on screen.
test("resting on the row of the chat on screen reads the chat its check-off would show", async () => {
const { fake, prefetched } = setup();
const dispose = activate(fake.api);
try {
await fake.settle();
fake.update({ chatId: "c1", workspaceId: "w1", route: "chat" });
await fake.settle();
await pointer(fake, "c1", "onPointerEnter");
mock.timers.tick(REST_MS);
await fake.settle();
assert.deepEqual(prefetched, ["c2"]);
} finally {
await dispose();
}
});
// Cmd held may be for Cmd+Shift+M, which checks off the chat on screen.
test("holding Cmd reads the chat a check-off of the chat on screen would show", async () => {
const { fake, prefetched } = setup();
const dispose = activate(fake.api);
try {
await fake.settle();
fake.update({ chatId: "c1", workspaceId: "w1", route: "chat" });
await fake.settle();
const modifiersChanged = fake.node("sidebar")?.onModifiersChanged as (event: unknown) => void;
modifiersChanged({ modifiers: { secondary: true, meta: true, ctrl: false, alt: false, shift: false } });
await fake.settle();
assert.deepEqual(prefetched, ["c2"]);
} finally {
await dispose();
}
});
No comments yet.