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
projections.test.mjs5.9 KB
import assert from "node:assert/strict";
import { test } from "node:test";
import { initialState, noteTask, forgetTask } from "./sections.ts";
import { renderSidebar } from "./views.tsx";
import { bindAppState, projectAppState, readChanged, tracked } from "../../crates/sandbox/src/runtime/app-state.js";
function fixture(native = true) {
const state = initialState();
state.loaded = true;
state.chats = Array.from({ length: 200 }, (_, i) => ({
id: `c${i}`, title: `Chat ${i}`, workspaceId: "w", agentId: "agent", sessionId: "session",
createdAt: "2026-01-01T00:00:00Z", updatedAt: "2026-01-01T00:00:00Z", status: "idle", options: {}, archived: false,
}));
const task = (ids) => ({
id: "task", title: "Together", layout: {
root: { kind: "pane", id: "pane", tabs: ids.map((chatId) => ({ kind: "chat", chatId })), active: { kind: "chat", chatId: ids[0] } }, focused: "pane",
}, createdAt: "2026-01-01T00:00:00Z", updatedAt: "2026-01-01T00:00:00Z",
});
noteTask(state, task(["c198", "c199"]));
let app = { route: "chat", workspaceId: "w", chatId: "c0", shared: {} };
let reads;
const sidebar = { state, ensurePreview() {}, ...(native ? { nativeApp: {
bind: bindAppState, project: (definition) => projectAppState(app, definition, reads),
} } : {}) };
const render = () => {
reads = new Set();
return renderSidebar({ app: tracked(app, reads), state: {}, update() {}, run() {} }, sidebar);
};
const list = (tree) => {
if (tree?.type === "scroller") return tree;
for (const node of tree?.children ?? []) { const found = list(node); if (found) return found; }
};
const value = (binding) => !binding?.$appState ? binding : "value" in binding.$appState
? app[binding.$appState.key] === binding.$appState.value : projectAppState(app, binding.$appState);
return { state, task, render, list, value, select: (chatId) => { app = { ...app, chatId }; },
route: (route) => { app = { ...app, route }; },
invalidated: (key = "chatId") => readChanged(reads, new Set([key]), app),
reads: () => reads,
};
}
test("ordinary and same-task selections keep the flat rows while native selection and reveal follow the destination", () => {
const f = fixture();
const ordinary = f.list(f.render());
assert.equal(ordinary.followEnd, false);
assert.equal(f.reads().has("chatId"), false, "the sidebar has no raw selected-chat render dependency");
f.select("c1");
assert.equal(f.invalidated(), false);
assert.equal(f.value(ordinary.reveal), "row-c1");
assert.equal(f.value(ordinary.items.find((row) => row.id === "row-c0").selected), false);
assert.equal(f.value(ordinary.items.find((row) => row.id === "row-c1").selected), true);
f.select("c198");
assert.equal(f.invalidated(), true, "entering a multi-chat task changes row structure");
const task = f.list(f.render());
assert.deepEqual(task.items.filter((row) => row.id?.startsWith("child-")).map((row) => row.id), ["child-c198", "child-c199"]);
assert(task.items.findIndex((row) => row.id === "child-c199") > 190, "the destination can be far outside the viewport");
f.select("c199");
assert.equal(f.invalidated(), false, "members share one structural task identity");
assert.equal(f.value(task.reveal), "child-c199", "reveal uses the existing offscreen child row");
assert.equal(f.value(task.items.find((row) => row.id === "child-c198").selected), false);
assert.equal(f.value(task.items.find((row) => row.id === "child-c199").selected), true);
assert.equal(task.items.find((row) => row.id === "row-c198").children.some((row) => row.id?.startsWith("child-")), false, "children remain flat virtualized siblings");
f.select("c2");
assert.equal(f.invalidated(), true);
assert.equal(f.list(f.render()).items.some((row) => row.id?.startsWith("child-")), false);
f.route("settings");
assert.equal(f.invalidated("route"), true);
assert.equal(f.render(), null);
});
test("section collapse, explicit expansion and membership replacement replace projection inputs correctly", () => {
const f = fixture();
f.state.expanded.add("task");
assert.equal(f.list(f.render()).items.filter((row) => row.id?.startsWith("child-")).length, 2);
f.state.expanded.clear();
f.state.collapsed.open = true;
const rowIds = () => f.list(f.render()).items.filter((row) => row.id?.startsWith("row-") || row.id?.startsWith("child-")).map((row) => row.id);
assert.deepEqual(rowIds(), ["row-c0"], "a folded section shows the chat on screen alone");
f.select("c5");
assert.equal(f.invalidated(), true, "another chat of the folded section changes which row it shows");
assert.deepEqual(rowIds(), ["row-c5"]);
f.select("c199");
assert.deepEqual(rowIds(), ["row-c198", "child-c198", "child-c199"], "a task's chat shows its task's row and children");
f.state.collapsed.open = false;
f.select("c198");
let list = f.list(f.render());
assert.equal(list.items.filter((row) => row.id?.startsWith("child-")).length, 2, "the selected task lists all of its children");
noteTask(f.state, f.task(["c198"]));
list = f.list(f.render());
assert.equal(list.items.some((row) => row.id?.startsWith("child-")), false);
f.select("c199");
assert.equal(f.invalidated(), false, "removed membership no longer retains a task dependency");
forgetTask(f.state, "task");
f.state.chats = f.state.chats.filter((chat) => chat.id !== "c199");
assert.equal(f.value(f.list(f.render()).reveal), null, "a deleted chat has no reveal target");
});
test("older runtimes retain computed selection, task expansion and corrected child reveal after restored selection", () => {
const f = fixture(false);
f.select("c199");
const list = f.list(f.render());
assert.equal(list.reveal, "child-c199");
assert.equal(list.items.find((row) => row.id === "child-c199").selected, true);
assert.equal(f.reads().has("chatId"), true, "the older runtime keeps its existing raw-state fallback");
f.select("c198");
assert.equal(f.invalidated(), true);
assert.equal(f.list(f.render()).reveal, "child-c198");
});
No comments yet.