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
session.test.ts11.8 KB
// The Session panel of the right rail, the subagent rows in the transcript
// and the title strip's failure mark, with the real chat modules.
import assert from "node:assert/strict";
import test from "node:test";
import * as Effect from "effect/Effect";
import type { AgentInfo, AppState, Chat } from "divergence";
import type { ChatView } from "./controller.ts";
import { applyEvent } from "./transcript.ts";
import { ago, optionLabel, sessionOpen, statusOf, when, working } from "./session.ts";
import { renderSessionPanel, renderSessionRail } from "./views/session.tsx";
import { renderItems } from "./views/rows.tsx";
import { renderTitle } from "./views/title.tsx";
import { harness, nodes, tree, chat as makeChat, transcript as initial, taskEvent } from "./ui-for-tests.test.ts";
const texts = (node: unknown) =>
nodes(node).flatMap((n) => [n.text, n.label].filter((t): t is string => typeof t === "string" && t !== ""));
function setup(app: AppState) {
const h = harness();
const opened: string[] = [];
h.controller.openSubagent = (_chat, id) =>
Effect.sync(() => {
opened.push(id);
});
const chat = (h.controller.state.chats.c1 = makeChat({
id: "c1",
workspaceId: "w1",
agentId: "claude",
sessionId: "sess-123",
createdAt: "2026-10-11T09:30:00Z",
updatedAt: new Date(Date.now() - 5 * 60_000).toISOString(),
status: "running",
}));
h.controller.state.workspaces.w1 = { id: "w1", name: "nexus", path: "/p/nexus" } as never;
h.controller.state.agents.claude = {
id: "claude",
name: "Claude",
capabilities: { usageLimits: true, cancelTask: true },
status: { state: "ready" },
usageLimits: { windows: [{ id: "five_hour", label: "5 hours", usedPercent: 40, windowMinutes: 300 }] },
} as AgentInfo;
h.controller.state.composers.c1 = {
...h.controller.composer("c1"),
options: [
{
id: "model",
name: "Model",
kind: "select",
category: "model",
value: "opus",
choices: [{ value: "opus", name: "Opus 4.1" }],
},
{
id: "effort",
name: "Effort",
kind: "select",
category: "reasoning",
value: "high",
choices: [{ value: "high", name: "High" }],
},
{
id: "approval",
name: "Approval",
kind: "select",
category: "approval",
value: "ask",
choices: [{ value: "ask", name: "Ask every time" }],
},
],
};
const t = (h.controller.state.transcripts.c1 = initial());
t.usage = { usedTokens: 50_000, contextWindow: 200_000, inputTokens: 1200, outputTokens: 300 };
applyEvent(
t,
taskEvent({ id: "a", title: "Find the bug", name: "explorer", model: "opus", startedAt: new Date().toISOString() }),
);
applyEvent(t, taskEvent({ id: "b", title: "Read a file", parentTaskId: "a", status: "waiting" }));
applyEvent(
t,
taskEvent({ id: "c", title: "Write tests", status: "completed", usage: { usedTokens: 12_000 }, toolUses: 3 }),
);
const v: ChatView = { ...h.v, ctx: { ...h.v.ctx, app } };
return { h, v, chat, t, opened };
}
test("the panel shows while pinned or previewed, and never otherwise", () => {
assert.equal(sessionOpen({}), false);
assert.equal(sessionOpen({ shared: { rightPanel: "files" } }), false);
assert.equal(sessionOpen({ shared: { rightPanel: "chat" } }), true);
assert.equal(sessionOpen({ shared: { rightPanelPreview: "chat" } }), true);
const { v } = setup({ route: "chat", chatId: "c1", shared: { rightPanel: "git" } });
assert.equal(renderSessionPanel(v), null);
});
test("the session section names the agent, its options, workspace, status, id and times", () => {
const { v } = setup({ route: "chat", chatId: "c1", shared: { rightPanelPreview: "chat" } });
const panel = renderSessionPanel(v);
const words = texts(panel);
for (const expected of [
"Session",
"Claude",
"Opus 4.1 · High",
"Ask every time",
"nexus",
"Running",
"sess-123",
"5m ago",
])
assert.ok(words.includes(expected), `shows ${expected}`);
assert.ok(
nodes(panel).some((n) => n.id === "session-copy-id"),
"the session id can be copied",
);
// The context window and the account's limits, with the same helpers as the meters.
assert.ok(words.includes("Context window") && words.includes("25%") && words.includes("150,000"));
assert.ok(words.includes("Usage limits") && words.includes("5 hours") && words.includes("60% remaining"));
// The context window's bar, and the limit's bar of the share left, filled from the right.
assert.ok(nodes(panel).some((n) => n.type === "progress"));
assert.ok(nodes(panel).some((n) => n.justifyContent === "end" && n.background === "muted"));
});
test("subagents are listed nested under their parent; a row opens its tab", async () => {
const { h, v, opened } = setup({ route: "chat", chatId: "c1", shared: { rightPanel: "chat" } });
const panel = renderSessionPanel(v);
const rows = nodes(panel).filter((n) => n.type === "item" && String(n.id).startsWith("session-task-"));
assert.deepEqual(
rows.map((n) => n.label),
["Find the bug", "Read a file", "Write tests"],
);
const holders = nodes(panel).filter((n) => n.children?.some?.((child) => rows.includes(child)));
assert.deepEqual(
holders.map((n) => n.paddingLeft),
[0, 14, 0],
"a child sits one level in",
);
assert.match(String(rows[0].sublabel), /^explorer · Opus 4\.1/);
assert.equal(rows[1].sublabelTone, "warning", "one that waits on the user says so");
assert.match(String(rows[1].sublabel), /^Needs you/);
assert.match(String(rows[2].sublabel), /12k tok · 3 tools/);
rows[1].onClick();
await h.settle();
assert.deepEqual(opened, ["b"]);
});
test("background terminals have their own section, sort live work first and open like subagents", async () => {
const { h, v, t, opened } = setup({ route: "chat", chatId: "c1", shared: { rightPanel: "chat" } });
applyEvent(
t,
taskEvent({
id: "finished-terminal",
kind: "terminal",
title: "Old build",
command: "cargo check",
status: "completed",
}),
);
applyEvent(
t,
taskEvent({
id: "running-terminal",
kind: "terminal",
title: "Release build",
command: "cargo build --release",
status: "running",
}),
);
const panel = renderSessionPanel(v);
// Background terminals have a section of their own, after the subagents.
const all = nodes(panel);
const at = (id: string) => all.findIndex((node) => node.id === id);
assert.ok(at("session-subagents") < at("session-task-c"));
assert.ok(at("session-task-c") < at("session-terminals"));
assert.ok(texts(panel).includes("Background terminals"));
const section = all.find((n) => n.children?.some?.((child) => child.id === "session-terminals"));
const rows = nodes(section).filter((node) => String(node.id).startsWith("session-task-"));
assert.deepEqual(
rows.map((node) => node.id),
["session-task-running-terminal", "session-task-finished-terminal"],
"only terminals, live work first",
);
const terminal = rows[0]!;
assert.match(String(terminal.sublabel), /Running · cargo build --release/);
terminal.onClick();
await h.settle();
assert.deepEqual(opened, ["running-terminal"]);
});
test("sections with nothing in them for the chat are left out", () => {
const { h, v } = setup({ route: "chat", chatId: "c1", shared: { rightPanel: "chat" } });
h.controller.state.transcripts.c1 = initial();
delete (h.controller.state.agents.claude as { usageLimits?: unknown }).usageLimits;
const words = texts(renderSessionPanel(v));
assert.ok(words.includes("Session"));
for (const heading of ["Context window", "Usage limits", "Subagents", "Background terminals"])
assert.ok(!words.includes(heading), `no ${heading} section`);
});
test("the rail icon counts working subagents and pins the panel", async () => {
const { h, v } = setup({ route: "chat", chatId: "c1", shared: {} });
const rail = tree(renderSessionRail(v));
assert.equal(rail.badge, "2", "running and waiting, not finished");
assert.equal(rail.active, false);
Effect.runSync(h.controller.app.update({ chatId: "c1", route: "chat" }));
rail.onClick();
await h.settle();
assert.equal(Effect.runSync(h.controller.app.state).shared?.rightPanel, "chat");
tree(renderSessionRail(v)).onClick();
await h.settle();
assert.equal(Effect.runSync(h.controller.app.state).shared?.rightPanel, null);
});
test("the title has no subagent button; the rail opens the Session panel", () => {
const { v } = setup({ route: "chat", chatId: "c1", shared: {} });
assert.ok(!nodes(renderTitle(v)).some((n) => n.type === "button" && n.icon === "network"));
});
test("a failed chat's title reads like the sidebar: a danger dot and muted text", () => {
const { h, v } = setup({ route: "chat", chatId: "c1", shared: {} });
h.controller.state.chats.c1 = { ...(h.controller.state.chats.c1 as Chat), status: "failed" };
const all = nodes(renderTitle(v));
const failed = all.find((n) => n.type === "text" && n.text === "Failed");
assert.equal(failed?.tone, "muted");
assert.ok(all.some((n) => n.type === "icon" && n.name === "circle" && n.tone === "danger"));
assert.ok(!all.some((n) => n.type === "text" && n.tone === "danger"), "no red text");
});
test("a subagent in the transcript is one activity row that opens its tab", async () => {
const { h, v, chat, opened } = setup({ route: "chat", chatId: "c1", shared: {} });
const t = initial();
applyEvent(
t,
taskEvent({ id: "x", title: "Survey the code", name: "explorer", model: "opus", usage: { usedTokens: 2_000 } }),
);
const rows = renderItems(v, chat, t, t.items);
assert.equal(rows.length, 1);
const words = texts(rows[0]);
assert.ok(words.includes("explorer") && words.includes("Survey the code"));
assert.ok(
words.some((w) => w.startsWith("Opus 4.1 · ") && w.endsWith("2.0k tok")),
"model, time and tokens",
);
assert.ok(!nodes(rows[0]).some((n) => n.background === "card"), "no card");
const row = nodes(rows[0]).find((n) => typeof n.onClick === "function");
row?.onClick();
await h.settle();
assert.deepEqual(opened, ["x"]);
});
test("subagents started together fold into one row that stays visible while one needs the user", () => {
const { v, chat } = setup({ route: "chat", chatId: "c1", shared: {} });
const t = initial();
applyEvent(t, taskEvent({ id: "x", title: "One", status: "completed" }));
applyEvent(t, taskEvent({ id: "y", title: "Two", status: "waiting" }));
const [group] = renderItems(v, chat, t, t.items);
const words = texts(group);
assert.ok(words.includes("Kicked off 2 subagents"));
assert.ok(words.includes("Needs you"));
assert.ok(words.includes("One") && words.includes("Two"), "open while one is live");
});
test("helpers: option names, chat status, times and the working count", () => {
assert.equal(optionLabel({ value: "a", choices: [{ value: "a", name: "Alpha" }] }), "Alpha");
assert.equal(optionLabel({ value: "raw" }), "raw");
assert.equal(optionLabel({ value: null }), null);
assert.equal(optionLabel(undefined), null);
assert.deepEqual(statusOf({ status: "waiting_question" }), { label: "Needs you", tone: "warning", running: false });
assert.equal(statusOf({ status: "idle" }).label, "Not started");
assert.equal(statusOf({ status: "idle", sessionId: "s" }).label, "Idle");
assert.equal(statusOf({ status: "failed" }).tone, "danger");
const now = Date.parse("2026-10-11T12:00:00Z");
assert.equal(ago("2026-10-11T11:59:40Z", now), "just now");
assert.equal(ago("2026-10-11T09:00:00Z", now), "3h ago");
assert.equal(ago("2026-10-09T12:00:00Z", now), "2d ago");
assert.equal(ago("nope", now), null);
assert.equal(when(""), null);
assert.ok(when("2026-10-11T09:30:00Z")?.startsWith("Oct 11"));
const t = initial();
applyEvent(t, taskEvent({ id: "q", status: "queued" }));
applyEvent(t, taskEvent({ id: "r", status: "running" }));
assert.equal(working(t.items), 1, "a queued subagent is not working yet");
});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.