Official
chat
Built-in chat 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/chat@0.2.9
Permissions in 0.2.9
Files
presentations.test.ts9.9 KB
import assert from "node:assert/strict";
import test from "node:test";
import * as Effect from "effect/Effect";
import type { Layout, SideSplit, Tab, Task } from "divergence/protocol";
import { forgetTask, noteTask } from "./layout.ts";
import { PresentationRoutes, centerPresentation, titlePresentation, registerPresentationRoutes } from "./presentations.tsx";
import { renderCenterPresentation } from "./views/panes.tsx";
import { renderTitlePresentation } from "./views/title.tsx";
import { chat, harness, nodes } from "./ui-for-tests.test.ts";
const tab = (chatId: string): Tab => ({ kind: "chat", chatId });
const pane = (id: string, tabs: Tab[] = [tab(id)]): Layout => ({ kind: "pane", id: `pane-${id}`, tabs, active: tabs[0]! });
const task = (id: string, root: Layout = pane(id)): Task => ({ id, layout: { root, focused: `pane-${id}` }, createdAt: "", updatedAt: "" });
const side = (tabs: Tab[], fields: Partial<SideSplit> = {}): SideSplit => ({ layout: { root: pane("side", tabs), focused: "pane-side" }, open: true, width: 400, remembered: [], ...fields });
function setup(ids: string[]) {
const h = harness();
const updates: string[] = [];
let nextView = 0;
const view = (name: string) => ({ id: ++nextView, update: () => updates.push(name), remove() {} });
const makeRoutes = () => new PresentationRoutes(h.controller, view("center-fallback"), view("center-cases"), view("title-fallback"), view("title-cases"), view("title-off-route"));
const routes = makeRoutes();
h.controller.presentations = routes;
const add = (id: string, ready = true) => {
h.controller.state.chats[id] = chat({ id });
h.controller.transcript(id).snapshot = { kind: "ready" };
h.controller.state.panes[id] = {
chatId: id,
view: view(`pane:${id}`),
composer: view(`composer:${id}`),
centerPresentation: view(`center:${id}`),
titlePresentation: view(`title:${id}`),
drawn: ready,
ready,
centerPresented: ready,
titlePresented: ready,
};
h.controller.state.recentPanes.push(id);
};
for (const id of ids) {
add(id);
noteTask(h.controller.state.layouts, task(id));
}
routes.updateLayouts();
updates.length = 0;
const presentations = () => updates.filter((name) => /^(center|title):/.test(name)).sort();
return { ...h, routes, updates, add, presentations, makeRoutes };
}
test("fresh task adoption and pane registration leave unrelated retained presentations intact", async () => {
const h = setup(["a", "b"]);
try {
Effect.runSync(h.controller.app.update({ route: "chat", chatId: "a" }));
noteTask(h.controller.state.layouts, task("fresh"));
h.routes.updateLayouts("fresh");
assert.deepEqual(h.presentations(), []);
h.add("fresh");
h.routes.paneChanged("fresh");
assert.deepEqual(h.presentations(), ["center:fresh", "title:fresh"]);
assert.ok(h.routes.canSelect("a") && h.routes.canSelect("b"));
h.updates.length = 0;
h.routes.updateLayouts("fresh");
assert.deepEqual(h.presentations(), [], "repeated delivery of the same layout has no work");
} finally { await h.close(); }
});
test("task changes and tab titles update their shared task without redrawing another task", async () => {
const h = setup(["a", "b", "c"]);
try {
forgetTask(h.controller.state.layouts, "b");
noteTask(h.controller.state.layouts, task("a", pane("a", [tab("a"), tab("b")])));
h.routes.updateLayouts();
assert.deepEqual(h.presentations(), ["center:a", "center:b", "title:a", "title:b"]);
h.updates.length = 0;
h.routes.updateTitle("b");
assert.deepEqual(h.presentations(), ["title:a", "title:b"], "an inactive tab still contributes its title to both destinations");
h.updates.length = 0;
forgetTask(h.controller.state.layouts, "a");
h.routes.updateLayouts("a");
assert.deepEqual(h.presentations(), ["center:a", "center:b", "title:a", "title:b"], "removal follows the previous home dependency");
} finally { await h.close(); }
});
test("side-split changes follow scoped tabs, global items, closing and reopening", async () => {
const h = setup(["a", "b"]);
try {
const owned = { kind: "item", id: "file-a", owner: "tabs", itemKind: "tabs.file", key: "a.rs", title: "a.rs", chatId: "a" } as Tab;
h.controller.state.layouts.side = side([owned]);
h.routes.updateLayouts();
assert.deepEqual(h.presentations(), ["center:a", "title:a"]);
h.updates.length = 0;
h.controller.state.layouts.side = side([owned], { open: false });
h.routes.updateLayouts();
assert.deepEqual(h.presentations(), ["center:a", "title:a"]);
h.updates.length = 0;
h.controller.state.layouts.side = side([owned]);
h.routes.updateLayouts();
assert.deepEqual(h.presentations(), ["center:a", "title:a"]);
h.updates.length = 0;
const global = { ...owned, id: "window-file", chatId: null } as Tab;
h.controller.state.layouts.side = side([owned, global]);
h.routes.updateLayouts();
assert.deepEqual(h.presentations(), ["center:a", "center:b", "title:a", "title:b"]);
h.updates.length = 0;
h.controller.state.layouts.side = side([owned, global], { width: 500, resized: true });
h.routes.updateLayouts();
assert.deepEqual(h.presentations(), ["center:a", "center:b", "title:a", "title:b"]);
} finally { await h.close(); }
});
test("a cold added pane preserves the published layout and keeps its switcher responsive", async () => {
const h = setup(["a", "b"]);
try {
const before = h.routes.layoutFor("a");
h.add("cold", false);
const root: Layout = { kind: "split", id: "split-a", direction: "row", children: [{ share: 0.5, layout: pane("a") }, { share: 0.5, layout: pane("cold") }] };
noteTask(h.controller.state.layouts, task("a", root));
h.routes.updateLayouts("a");
assert.equal(h.routes.layoutFor("a"), before);
assert.ok(h.routes.canSelect("a"), "the old complete destination remains selectable");
assert.deepEqual(h.presentations(), [], "the incomplete successor does not replace either retained tree");
Effect.runSync(h.controller.app.update({ route: "settings", chatId: "a" }));
h.controller.state.switcher = { list: ["a", "b"], selected: "b", input: "overlay" };
h.routes.updateSwitcher();
assert.ok(h.presentations().includes("title:a"), "the overlay is still updated on the old layout");
const v = { ...h.v, ctx: { ...h.v.ctx, app: h.controller.api.app.state() } };
const title = nodes(renderTitlePresentation(v, "a", h.routes.layoutFor("a")));
assert.ok(title.some((node) => node.id === "chat-switcher" && node.open));
assert.ok(!title.some((node) => node.id === "tab-chat-cold"));
const center = nodes(renderCenterPresentation(v, "a", h.routes.layoutFor("a")));
assert.ok(!center.some((node) => node.id === "pane-cold"), "rendering still uses the old complete task");
h.controller.state.panes.cold!.ready = true;
h.controller.state.panes.cold!.drawn = true;
h.updates.length = 0;
h.routes.paneChanged("cold");
assert.equal(h.routes.layoutFor("a")?.task?.layout.root, root);
assert.deepEqual(h.presentations(), ["center:a", "center:cold", "title:a", "title:cold"]);
assert.ok(h.routes.canSelect("a") && h.routes.canSelect("b"));
} finally { await h.close(); }
});
test("eviction withdraws only dependent destinations and a fresh scope rebuilds the index", async () => {
const h = setup(["a", "b", "c"]);
try {
forgetTask(h.controller.state.layouts, "b");
noteTask(h.controller.state.layouts, task("a", { kind: "split", id: "ab", direction: "row", children: [{ share: 0.5, layout: pane("a") }, { share: 0.5, layout: pane("b") }] }));
h.routes.updateLayouts();
delete h.controller.state.panes.b;
h.routes.remove("b");
assert.equal(h.routes.canSelect("a"), false);
assert.equal(h.routes.canSelect("b"), false);
assert.equal(h.routes.canSelect("c"), true);
h.add("b");
h.routes.paneChanged("b");
assert.equal(h.routes.canSelect("a"), true);
const reloaded = h.makeRoutes();
assert.equal(reloaded.canSelect("a"), false, "a new scope inherits no dependency state");
reloaded.updateLayouts();
assert.ok(reloaded.canSelect("a") && reloaded.canSelect("b") && reloaded.canSelect("c"));
} finally { await h.close(); }
});
test("retained center and title views explicitly avoid unrelated host-event invalidation", async () => {
const h = setup(["a"]);
const subscriptions: unknown[] = [];
try {
h.controller.views.add = ((_key: string, definition: { on?: unknown }) => {
subscriptions.push(definition.on);
return Effect.succeed({ id: 100, update() {}, remove() {} });
}) as typeof h.controller.views.add;
await Effect.runPromise(Effect.scoped(centerPresentation(h.controller, "a")));
await Effect.runPromise(Effect.scoped(titlePresentation(h.controller, "a")));
assert.deepEqual(subscriptions, [["plugin_changed"], ["plugin_changed"]]);
} finally { await h.close(); }
});
test("structural routes receive lifecycle events and case changes retain their update owners", async () => {
const h = harness();
const subscriptions = new Map<string, unknown>();
const updates: string[] = [];
let id = 0;
try {
h.controller.views.add = ((key: string, definition: { on?: unknown }) => {
subscriptions.set(key, definition.on);
return Effect.succeed({ id: ++id, update: () => updates.push(key), remove() {} });
}) as typeof h.controller.views.add;
const routes = await Effect.runPromise(Effect.scoped(registerPresentationRoutes(h.controller)));
for (const key of ["center", "center-cases", "title-cases", "title"])
assert.deepEqual(subscriptions.get(key), ["plugin_changed"], `${key} must not receive unrelated host events`);
updates.length = 0;
routes.updateCases();
assert.deepEqual(updates, ["center-cases", "title-cases"]);
assert.deepEqual(subscriptions.get("center-fallback"), ["chat_changed", "agents_changed", "app_state"]);
assert.deepEqual(subscriptions.get("title-fallback"), ["chat_changed", "agents_changed", "app_state", "workspaces_changed"]);
} finally { await h.close(); }
});Versions
| Version | Published | Plugin API | Size | Permissions | Status |
|---|---|---|---|---|---|
| 0.2.9latest | Nov 21, 2026 | >=5 <6 | 349 KB | 5 permissions | Listed |
| 0.2.8 | Nov 16, 2026 | >=5 <6 | 348.6 KB | 5 permissions | Listed |
| 0.2.7 | Nov 11, 2026 | >=5 <6 | 314.3 KB | 5 permissions | Listed |
| 0.2.6 | Nov 9, 2026 | >=5 <6 | 306.2 KB | 5 permissions | Listed |
| 0.2.5 | Oct 27, 2026 | >=2 <4 | 178.6 KB | 5 permissions | Listed |
No comments yet.