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.3
Permissions in 0.2.3
Files
items.test.ts3.8 KB
// Rows other plugins put in the sidebar's footer: each publishes a view id
// under `sidebarItem.<plugin>` in the shared app state, and the sidebar
// draws it above Settings (the market's Marketplace row).
import assert from "node:assert/strict";
import { test } from "node:test";
import type { AppState } from "divergence";
import type { EffectViewContext } from "divergence/effect";
import type { Sidebar } from "./controller.ts";
import { initialState } from "./sections.ts";
import { renderSidebar, sidebarItems } from "./views.ts";
test("published sidebar items are view ids in the order of their keys; cleared ones go", () => {
assert.deepEqual(sidebarItems(undefined), []);
assert.deepEqual(
sidebarItems({
rightPanel: "files",
"sidebarItem.zeta": 9,
"sidebarItem.market": 4,
"sidebarItem.gone": null,
openTab: { nonce: 1 },
}),
[4, 9],
);
});
test("the footer draws each published item directly above Settings", () => {
const state = initialState();
state.loaded = true;
const app: AppState = { route: "chat", shared: { "sidebarItem.market": 7 } };
const ctx = { app, state: {}, plugin: "sidebar", update() {}, run() {} } as unknown as EffectViewContext<{
queueDraft?: boolean;
}>;
const tree = renderSidebar(ctx, { state } as unknown as Sidebar["Service"]);
type Node = { type?: string; id?: string; view?: number; children?: Node[] };
const order: string[] = [];
const walk = (node: Node | null | undefined) => {
if (!node) return;
if (node.type === "view") {
// As tall as its row: a view that fills its place collapses to
// nothing in the footer.
assert.equal((node as { fit?: boolean }).fit, true);
order.push(`view:${node.view}`);
}
if (node.id === "sidebar-settings") order.push("settings");
for (const child of node.children ?? []) walk(child);
};
walk(tree as unknown as Node);
assert.deepEqual(order, ["view:7", "settings"]);
});
// "Show more" on Complete used to put hundreds of rows in a scrolling
// column that laid out and drew every one of them in each frame of a
// scroll. The chats are one flat list of rows in a scroller that draws
// only the rows on screen, with the selected chat's fill leading it.
test("the chats are rows of a list that opens at its start, even after Show more", () => {
const state = initialState();
state.loaded = true;
state.chats = Array.from({ length: 300 }, (_, i) => ({
id: `c${i}`,
workspaceId: "ws",
agentId: "agent",
title: `Chat ${i}`,
createdAt: "2026-01-01T00:00:00.000Z",
updatedAt: "2026-01-02T00:00:00.000Z",
completedAt: "2026-01-03T00:00:00.000Z",
archived: false,
options: {},
status: "idle",
}));
state.showAll.settled = true;
const app: AppState = { route: "chat", chatId: "c7" };
const ctx = { app, state: {}, plugin: "sidebar", update() {}, run() {} } as unknown as EffectViewContext<{
queueDraft?: boolean;
}>;
type Node = { type?: string; id?: string; follows?: string; followEnd?: boolean; children?: Node[]; items?: Node[] };
const find = (node: Node | null | undefined, type: string): Node | undefined => {
if (!node) return undefined;
if (node.type === type) return node;
for (const child of node.children ?? []) {
const found = find(child, type);
if (found) return found;
}
return undefined;
};
const list = find(renderSidebar(ctx, { state } as unknown as Sidebar["Service"]) as unknown as Node, "scroller");
assert.equal(list?.followEnd, false);
const items = list?.items ?? [];
assert.equal(items[0]?.follows, "row-c7", "the selected chat's fill leads the rows");
assert.equal(items[1]?.id, "heading-settled");
assert.equal(items.filter((item) => item.id?.startsWith("row-")).length, 300, "every chat is a row of its own");
assert.equal(items.at(-1)?.id, "less-settled");
});
No comments yet.