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
newtab.test.ts12.5 KB
// The New tab page: what a strip's + opens and what the empty side split shows.
import assert from "node:assert/strict";
import test from "node:test";
import * as Effect from "effect/Effect";
import type { Layout, Tab } from "divergence/protocol";
import { noteTask, showTabAt, stepPane, stepTab, tabNumber, toggleSideSplit } from "./layout.ts";
import { NEW_TAB, renderNewTab } from "./newtab.tsx";
import { shortcutsOf } from "./shortcuts.ts";
import { renderTitle } from "./views/title.tsx";
import { chat, harness, nodes } from "./ui-for-tests.test.ts";
const page: Tab = { kind: "item", id: "item-new", owner: "chat", itemKind: `chat.${NEW_TAB}`, key: "k1", title: "New tab" };
/** A chat on screen, alone in its task's one pane, with `extra` tabs after it. */
function onScreen(extra: Tab[] = []) {
const made: { paneId: string }[] = [];
const h = Object.assign(
harness((method, params) => {
if (method !== "host/layouts.new_chat") return undefined;
made.push(params as { paneId: string });
return Effect.succeed({ chat: chat({ id: "n" }) });
}),
{ made },
);
const a = chat({ id: "a" });
h.controller.state.chats.a = a;
const tabs: Tab[] = [{ kind: "chat", chatId: "a" }, ...extra];
const root: Layout = { kind: "pane", id: "p1", tabs, active: tabs[tabs.length - 1]! };
noteTask(h.controller.state.layouts, { id: "t", layout: { root, focused: "p1" }, createdAt: "", updatedAt: "" });
Effect.runSync(h.controller.app.select("a", a.workspaceId));
return h;
}
const opened = (h: ReturnType<typeof harness>) => (h.controller.api as unknown as { layouts: { opened: unknown[] } }).layouts.opened;
test("a strip's + lists the page's steps with their icons, makes a new chat in its own pane and runs the others' commands", async () => {
const h = onScreen();
const plus = () =>
nodes(renderTitle({ ...h.v, ctx: { ...h.v.ctx, app: { route: "chat", chatId: "a" } } })).find((node) => node.id === "strip-new-p1") as unknown as {
options: { value: string; icon?: string }[];
onChange: (e: { value: string }) => void;
};
assert.deepEqual(
plus().options.map((option) => option.value),
["chat", "terminal", "changes", "files", "chats", "split-right", "split-down"],
"no New tab row: the page's steps are in the list itself",
);
assert.ok(plus().options.every((option) => option.icon), "every row has an icon");
plus().onChange({ value: "chat" });
await h.settle();
assert.deepEqual(h.made.map((call) => call.paneId), ["p1"], "a new chat is made in the +'s pane");
plus().onChange({ value: "terminal" });
await h.settle();
assert.ok(h.calls.some((call) => call.method === "run_command" && (call.params as { id: string }).id === "terminal.new"));
assert.deepEqual(opened(h), [], "no New tab page opens");
await h.close();
});
test("the side split opens on a New tab page when it has nothing for the task on screen", async () => {
const h = onScreen();
const all = nodes(renderTitle({ ...h.v, ctx: { ...h.v.ctx, app: { route: "chat", chatId: "a" } } }));
assert.ok(all.some((node) => node.id === "side-split-toggle"), "its toggle shows with nothing in it");
await Effect.runPromise(toggleSideSplit(h.controller));
assert.equal((opened(h)[0] as { where: unknown }).where, "side");
assert.ok(!h.calls.some((call) => call.method === "host/layouts.update"), "it opens through the page, not an empty split");
await h.close();
});
test("the page lists the next steps with their keys, and a new chat takes the page's place", async () => {
const h = onScreen([page]);
h.controller.state.shortcuts = shortcutsOf([
{ id: "chat.newTab", labels: ["⌘T"] },
{ id: "terminal.new", labels: ["⌘J"] },
]);
const all = nodes(renderNewTab(h.v, "k1"));
for (const id of ["chat", "terminal", "changes", "files", "chats"]) assert.ok(all.some((node) => node.id === `new-tab-${id}`), id);
const text = JSON.stringify(renderNewTab(h.v, "k1"));
assert.ok(text.includes("⌘T") && text.includes("⌘J"), "each step shows its key");
(all.find((node) => node.id === "new-tab-chat") as unknown as { onClick: () => void }).onClick();
await h.settle();
assert.deepEqual(h.made.map((call) => call.paneId), ["p1"], "a new chat is made in the page's pane");
const closed = h.calls.find((call) => call.method === "host/layouts.close_tab");
assert.deepEqual((closed?.params as { tab: Tab } | undefined)?.tab, page, "and the page closes");
await h.close();
});
test("a step that opens a panel leaves the page where it is", async () => {
const h = onScreen([page]);
(nodes(renderNewTab(h.v, "k1")).find((node) => node.id === "new-tab-files") as unknown as { onClick: () => void }).onClick();
await h.settle();
assert.ok(h.calls.some((call) => call.method === "run_command" && (call.params as { id: string }).id === "files.toggle"));
assert.ok(!h.calls.some((call) => call.method === "host/layouts.close_tab"));
await h.close();
});
test("the tab and pane keys reach the side split and come back", async () => {
const item = (id: string): Tab => ({ kind: "item", id, owner: "tabs", itemKind: "tabs.file", key: id, title: id });
const h = onScreen();
h.controller.state.layouts.side = {
open: true,
width: 520,
remembered: [],
layout: { root: { kind: "pane", id: "s1", tabs: [item("x"), item("y")], active: item("x") }, focused: "s1" },
} as never;
const updates = () => h.calls.filter((call) => call.method === "host/layouts.update").map((call) => call.params as { paneId?: string; active?: Tab });
await Effect.runPromise(stepPane(h.controller, "right"));
assert.equal(updates().at(-1)?.paneId, "s1", "right of the task's last pane is the side split");
assert.equal(h.controller.state.layouts.sideFocused, true);
await Effect.runPromise(stepTab(h.controller, 1));
assert.deepEqual(updates().at(-1), { paneId: "s1", active: item("y"), focused: true, onScreen: "t" }, "the next tab is the side split's");
await Effect.runPromise(stepPane(h.controller, "left"));
assert.equal(h.controller.state.layouts.sideFocused, false, "left of the side split is the task again");
await h.close();
});
test("Alt and a number show the focused pane's tab at that place, and Alt+9 its last", async () => {
const item = (id: string): Tab => ({ kind: "item", id, owner: "tabs", itemKind: "tabs.file", key: id, title: id });
const h = onScreen([item("x"), item("y")]);
const updates = () => h.calls.filter((call) => call.method === "host/layouts.update").map((call) => call.params as { paneId?: string; active?: Tab });
await Effect.runPromise(showTabAt(h.controller, "last"));
await Effect.runPromise(showTabAt(h.controller, 5));
assert.equal(updates().length, 0, "the last tab is already on screen and there is no sixth tab");
await Effect.runPromise(showTabAt(h.controller, 1));
assert.deepEqual(updates().at(-1), { paneId: "p1", active: item("x"), focused: true, onScreen: "t" }, "Alt+2 shows the second tab");
await h.close();
});
test("the tabs are numbered as Alt and a digit show them: the first eight, then the last as 9", () => {
assert.deepEqual(
Array.from({ length: 10 }, (_, index) => tabNumber(index, 10)),
[1, 2, 3, 4, 5, 6, 7, 8, null, 9],
);
assert.deepEqual([0, 1, 2].map((index) => tabNumber(index, 3)), [1, 2, 3]);
});
test("while Alt alone is held, the focused pane's tabs show their numbers instead of their marks", async () => {
const item = (id: string): Tab => ({ kind: "item", id, owner: "tabs", itemKind: "tabs.file", key: id, title: id });
const h = onScreen([item("x")]);
const title = () => nodes(renderTitle({ ...h.v, ctx: { ...h.v.ctx, app: { route: "chat", chatId: "a" } } }));
const numberIn = (id: string) => {
const tab = title().find((node) => node.id === id);
return nodes(tab).find((node) => node.type === "text" && /^\d$/.test(String(node.text)))?.text;
};
const hold = (modifiers: { alt: boolean; meta?: boolean }) => {
const strips = title().find((node) => node.id === "title-strips") as unknown as { onModifiersChanged: (e: unknown) => void };
strips.onModifiersChanged({ modifiers: { shift: false, ctrl: false, meta: false, ...modifiers } });
};
assert.equal(numberIn("tab-chat-a"), undefined, "no numbers at rest");
hold({ alt: true });
assert.equal(numberIn("tab-chat-a"), "1");
assert.equal(numberIn("tab-item-x"), "2");
hold({ alt: true, meta: true });
assert.equal(numberIn("tab-chat-a"), undefined, "Alt with another modifier is a different shortcut");
await h.close();
});
/** Two panes side by side on a kernel that tells each strip's tabs in view: p1 holds chat a and files x and y, p2
* files z and w. */
function splitOnScreen() {
const item = (id: string): Tab => ({ kind: "item", id, owner: "tabs", itemKind: "tabs.file", key: id, title: id });
const h = harness();
Object.defineProperty(h.controller.api, "uiCapabilities", { configurable: true, value: ["inView"] });
const a = chat({ id: "a" });
h.controller.state.chats.a = a;
const left: Tab[] = [{ kind: "chat", chatId: "a" }, item("x"), item("y")];
const right: Tab[] = [item("z"), item("w")];
const root: Layout = {
kind: "split",
id: "s",
direction: "row",
children: [
{ share: 0.5, layout: { kind: "pane", id: "p1", tabs: left, active: left[0]! } },
{ share: 0.5, layout: { kind: "pane", id: "p2", tabs: right, active: right[0]! } },
],
};
noteTask(h.controller.state.layouts, { id: "t", layout: { root, focused: "p1" }, createdAt: "", updatedAt: "" });
Effect.runSync(h.controller.app.select("a", a.workspaceId));
return { h, item };
}
test("Alt and a number count every tab in view in every strip, left to right, and skip those scrolled away", async () => {
const { h, item } = splitOnScreen();
const title = () => nodes(renderTitle({ ...h.v, ctx: { ...h.v.ctx, app: { route: "chat", chatId: "a" } } }));
// The first strip has scrolled so that chat a is out of view.
const strips = title().filter((node) => typeof node.onInView === "function") as unknown as { onInView: (e: { ids: string[] }) => void }[];
assert.equal(strips.length, 2, "both strips hear which of their tabs are in view");
strips[0]!.onInView({ ids: ["tab-item-x", "tab-item-y"] });
strips[1]!.onInView({ ids: ["tab-item-z", "tab-item-w"] });
const updates = () => h.calls.filter((call) => call.method === "host/layouts.update").map((call) => call.params as { paneId?: string; active?: Tab });
await Effect.runPromise(showTabAt(h.controller, 2));
assert.deepEqual(updates().at(-1), { paneId: "p2", active: item("z"), focused: true, onScreen: "t" }, "Alt+3 is the second strip's first tab");
await Effect.runPromise(showTabAt(h.controller, 0));
assert.deepEqual(updates().at(-1), { paneId: "p1", active: item("x"), focused: true, onScreen: "t" }, "Alt+1 is the first tab in view, not chat a");
await Effect.runPromise(showTabAt(h.controller, "last"));
assert.deepEqual(updates().at(-1), { paneId: "p2", active: item("w"), focused: true, onScreen: "t" }, "Alt+9 is the last tab in view");
await h.close();
});
test("while Alt alone is held, every strip numbers its tabs in view as Alt and a digit show them", async () => {
const { h } = splitOnScreen();
const title = () => nodes(renderTitle({ ...h.v, ctx: { ...h.v.ctx, app: { route: "chat", chatId: "a" } } }));
const numberIn = (id: string) => nodes(title().find((node) => node.id === id)).find((node) => node.type === "text" && /^\d$/.test(String(node.text)))?.text;
const strips = title().filter((node) => typeof node.onInView === "function") as unknown as { onInView: (e: { ids: string[] }) => void }[];
strips[0]!.onInView({ ids: ["tab-chat-a", "tab-item-x"] });
strips[1]!.onInView({ ids: ["tab-item-z"] });
const held = title().find((node) => node.id === "title-strips") as unknown as { onModifiersChanged: (e: unknown) => void };
held.onModifiersChanged({ modifiers: { alt: true, shift: false, ctrl: false, meta: false } });
assert.deepEqual(["tab-chat-a", "tab-item-x", "tab-item-y", "tab-item-z", "tab-item-w"].map(numberIn), ["1", "2", undefined, "3", undefined]);
// A scroll while Alt is held moves the numbers with the tabs.
strips[1]!.onInView({ ids: ["tab-item-z", "tab-item-w"] });
assert.equal(numberIn("tab-item-w"), "4");
await h.close();
});
test("a tab is drawn as it is, without fading in, so a chat's strip shown for the first time does not flicker", async () => {
const h = onScreen();
const tab = nodes(renderTitle({ ...h.v, ctx: { ...h.v.ctx, app: { route: "chat", chatId: "a" } } })).find((node) => node.id === "tab-chat-a");
assert.ok(tab);
assert.equal(tab.motion, undefined);
assert.equal(tab.opacity, undefined);
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.