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
terminal.test.ts14.7 KB
import test from "node:test";
import assert from "node:assert/strict";
import * as Effect from "effect/Effect";
import { ansiLines, terminalOutput } from "./terminal.tsx";
import { applyEvent } from "./transcript.ts";
import { openSubagent } from "./panes.ts";
import { renderSubagentPane, renderTask } from "./views/tasks.tsx";
import { chat, harness, item, nodes, taskEvent } from "./ui-for-tests.test.ts";
import { HostCallFailed } from "divergence/effect";
test("captured output keeps ANSI colours and whitespace while discarding control sequences", () => {
assert.deepEqual(ansiLines("\x1b[31;1mred\x1b[0m plain\n\x1b[38;2;1;2;3mrgb"), [
[{ text: "red", color: "danger", bold: true }, { text: " plain" }],
[{ text: "rgb", color: "#010203" }],
]);
assert.deepEqual(ansiLines("10%\r20%\x1b]0;title\x07\r\nend"), [[{ text: "20%" }], [{ text: "end" }]]);
});
test("opening a terminal opens its tab without reading subagent history", async () => {
const h = harness(),
c = chat();
h.controller.state.chats[c.id] = c;
const t = h.controller.transcript(c.id);
t.snapshot = { kind: "ready" };
applyEvent(
t,
taskEvent({
id: "build",
kind: "terminal",
command: "cargo build",
title: "Build",
output: "\x1b[32m done\x1b[0m\n",
status: "running",
}),
);
await Effect.runPromise(openSubagent(h.controller, c, "build"));
assert.deepEqual(
(h.controller.api as unknown as { layouts: { opened: unknown[] } }).layouts.opened,
[{ kind: "subagent", key: "build", chatId: c.id }],
);
assert.equal(
h.calls.some((call) => call.method === "host/chats.load_task"),
false,
);
const output = nodes(renderSubagentPane(h.v, c.id, "build"));
assert.ok(output.some((node) => node.text === "$ cargo build"));
assert.ok(output.some((node) => node.text === " done" && node.color === "success"));
// Lines wrap at the pane's edge instead of scrolling sideways one by one.
assert.ok(!output.some((node) => node.overflowX === "scroll" || node.whiteSpace === "nowrap"));
applyEvent(t, taskEvent({ id: "build", kind: "terminal", title: "Build", outputDelta: "more\n", status: "running" }));
assert.ok(nodes(renderSubagentPane(h.v, c.id, "build")).some((node) => node.text === "more"));
applyEvent(
t,
taskEvent({
id: "build",
kind: "terminal",
command: "cargo build",
title: "Build",
output: "done\n",
status: "completed",
}),
);
// Like a terminal, the pane is the command and its output, with no status header.
const done = nodes(renderSubagentPane(h.v, c.id, "build"));
assert.ok(done.some((node) => node.text === "done"));
assert.ok(!done.some((node) => node.text === "Completed" || node.text === "Running"));
await h.close();
});
test("a line of several styles wraps between its runs; a plain line is one text", () => {
const [plain, mixed] = terminalOutput("one long plain line\n\x1b[31merror\x1b[0m: details\n");
assert.equal(plain?.type, "text");
assert.equal(nodes(mixed)[0]?.flexWrap, "wrap");
assert.deepEqual(
nodes(mixed)
.filter((node) => node.type === "text")
.map((node) => node.text),
["error", ": details"],
);
});
test("a background command shows the terminal's mark in the chat and reads like a terminal pane in its tab", () => {
const h = harness(),
c = chat();
h.controller.state.chats[c.id] = c;
const t = h.controller.transcript(c.id);
t.snapshot = { kind: "ready" };
applyEvent(t, taskEvent({ id: "serve", kind: "terminal", command: "pnpm dev", title: "Dev server", output: "ready\n", status: "running" }));
const item = t.items.find((entry) => entry.id === "serve" || (entry as { task?: { id: string } }).task?.id === "serve");
assert.ok(item, "the command is in the transcript");
// Like a Run row, it has one mark: the spinner while it runs, the terminal's mark once it ends.
const draw = () => {
const all = nodes(renderTask(h.v, c, t, item as never));
const marks = all.filter((node) => node.type === "icon" && !String(node.name).startsWith("chevron")).map((node) => node.name);
return { all, marks, slot: nodes(all.find((node) => node.width === 14)!) };
};
const running = draw();
assert.equal(running.all.filter((node) => node.type === "spinner").length, 1);
assert.ok(running.slot.some((node) => node.type === "spinner"), "the spinner is in the icon slot");
assert.deepEqual(running.marks, [], "no second mark beside the spinner");
(item as { task: { status: string } }).task.status = "completed";
const done = draw();
assert.deepEqual(done.marks, ["square-terminal"], "the terminal's mark alone");
assert.ok(!done.all.some((node) => node.type === "spinner"));
(item as { task: { status: string } }).task.status = "running";
const pane = nodes(renderSubagentPane(h.v, c.id, "serve"));
const prompt = pane.find((node) => node.text === "$ pnpm dev");
assert.ok(prompt && prompt.tone === undefined, "the command reads as typed, not as a muted label");
assert.ok(!pane.some((node) => node.paddingX === "medium"), "the tab keeps a terminal pane's small inset");
});
test("a command left running after the turn keeps the transcript's working row, counted as a command", async () => {
const { tree } = await import("./ui-for-tests.test.ts");
const { renderTranscript } = await import("./views/rows.tsx");
const h = harness(),
c = chat();
h.controller.state.chats[c.id] = c;
const t = h.controller.transcript(c.id);
t.snapshot = { kind: "ready" };
applyEvent(t, taskEvent({ id: "serve", kind: "terminal", command: "pnpm dev", title: "Dev server", status: "running" }));
t.running = false;
const working = () => nodes(tree(renderTranscript(h.v, c))).find((node) => node.type === "text" && /running|working/.test(String(node.text)))?.text;
assert.equal(working(), "1 command running", "an older host's transcript is counted by kind");
assert.equal(nodes(tree(renderTranscript(h.v, { ...c, working: { agents: 1, commands: 2 } }))).some((node) => node.text === "1 agent and 2 commands working"), true, "the host's count wins");
assert.equal(nodes(tree(renderTranscript(h.v, { ...c, working: { agents: 0, commands: 0 } }))).some((node) => /running|working/.test(String(node.text))), false, "and none means the turn is over");
await h.close();
});
test("the working row left after the turn opens onto the commands still running", async () => {
const { tree } = await import("./ui-for-tests.test.ts");
const { renderTranscript } = await import("./views/rows.tsx");
const h = harness(),
c = chat();
h.controller.state.chats[c.id] = c;
const t = h.controller.transcript(c.id);
t.snapshot = { kind: "ready" };
applyEvent(t, taskEvent({ id: "serve", kind: "terminal", command: "pnpm dev", title: "Dev server", status: "running" }));
applyEvent(t, taskEvent({ id: "watch", kind: "terminal", command: "tsc -w", title: "Type check", status: "running" }));
applyEvent(t, taskEvent({ id: "lint", kind: "terminal", command: "pnpm lint", title: "Lint", status: "completed" }));
t.running = false;
const draw = () => nodes(tree(renderTranscript(h.v, c)));
const list = () => draw().find((node) => node.id === "background-tasks-list");
assert.equal(list(), undefined, "the row starts closed");
const toggle = draw().find((node) => node.id === "background-tasks")!;
const header = nodes(toggle).find((node) => typeof node.onClick === "function")!;
(header.onClick as () => void)();
const titles = nodes(list()!).filter((node) => node.type === "text").map((node) => node.text);
assert.ok(titles.includes("Dev server") && titles.includes("Type check"), "each running command is listed");
assert.ok(!titles.includes("Lint"), "a command that ended is not");
await h.close();
});
test("a reply that ends the transcript tells what its turn left running in its action row, and opens the list under it", async () => {
const { tree } = await import("./ui-for-tests.test.ts");
const { renderTranscript } = await import("./views/rows.tsx");
const h = harness(),
c = chat();
h.controller.state.chats[c.id] = c;
const t = h.controller.transcript(c.id);
t.snapshot = { kind: "ready" };
applyEvent(t, taskEvent({ id: "serve", kind: "terminal", command: "pnpm dev", title: "Dev server", status: "running" }));
t.items.push(item({ id: "reply", role: "assistant", text: "The server is up." }));
t.running = false;
const draw = () => nodes(tree(renderTranscript(h.v, c)));
const toggle = draw().find((node) => node.id === "background-tasks")!;
const actions = draw().find((node) => nodes(node).some((n) => n.id === "copy-reply") && nodes(node).includes(toggle) && node.flexDirection === "row");
assert.ok(nodes(toggle).some((node) => node.text === "1 command running"), "the count is in the toggle");
assert.ok(actions, "the toggle shares the reply's action row with its buttons");
assert.equal(draw().filter((node) => node.text === "1 command running").length, 1, "no working row of its own as well");
(toggle.onClick as () => void)();
const titles = nodes(draw().find((node) => node.id === "background-tasks-list")!).filter((node) => node.type === "text").map((node) => node.text);
assert.ok(titles.includes("Dev server"), "the running command is listed under the reply");
await h.close();
});
test("a subagent that started before the loaded rows is listed, opened and updated where the page put it", async () => {
const { tree } = await import("./ui-for-tests.test.ts");
const { renderTranscript } = await import("./views/rows.tsx");
const { loadTranscript } = await import("./data.ts");
const { event: _, ...research } = taskEvent({ id: "research", title: "Research", status: "running" });
const h = harness((method) =>
method === "host/chats.transcript"
? Effect.succeed({
items: [item({ id: "a1", role: "assistant", text: "Started it." })],
start: 40,
total: 41,
liveTasks: [{ id: "task-research", role: "task", task: research, items: [] }],
pendingApprovals: [],
pendingQuestions: [],
plan: null,
usage: {},
running: false,
})
: undefined,
),
c = { ...chat(), working: { agents: 1, commands: 0 } };
h.controller.state.chats[c.id] = c;
await Effect.runPromise(loadTranscript(h.controller, c.id, { history: false }));
const t = h.controller.transcript(c.id);
const draw = () => nodes(tree(renderTranscript(h.v, c)));
const toggle = nodes(draw().find((node) => node.id === "background-tasks")).find((node) => typeof node.onClick === "function");
assert.ok(toggle, "the working line opens although the subagent is not among the loaded rows");
(toggle.onClick as () => void)();
const list = draw().find((node) => node.id === "background-tasks-list");
assert.ok(list && nodes(list).some((node) => node.text === "Research"), "the subagent is listed");
assert.ok(!nodes(renderSubagentPane(h.v, c.id, "research")).some((node) => /no longer in the chat/.test(String(node.text))), "and its tab finds it");
applyEvent(t, taskEvent({ id: "research", title: "Research", status: "completed" }));
assert.deepEqual(t.items.map((row) => row.id), ["a1"], "an update does not add it again at the end");
assert.equal(t.earlierTasks[0]?.role === "task" && t.earlierTasks[0].task.status, "completed");
await h.close();
});
test("the reply's working count opens once what it counts arrives, though the count stays the same", async () => {
const { tree } = await import("./ui-for-tests.test.ts");
const { renderTranscript } = await import("./views/rows.tsx");
const h = harness(),
c = { ...chat(), working: { agents: 1, commands: 0 } };
h.controller.state.chats[c.id] = c;
const t = h.controller.transcript(c.id);
t.snapshot = { kind: "ready" };
t.items = [item({ id: "a1", role: "assistant", text: "Started it." })];
t.running = false;
const opens = () => nodes(tree(renderTranscript(h.v, c))).some((node) => node.id === "background-tasks" && typeof node.onClick === "function");
assert.equal(opens(), false, "nothing it counts is read yet");
const { event: _, ...research } = taskEvent({ id: "research", title: "Research", status: "running" });
t.earlierTasks = [{ id: "task-research", role: "task", task: research, items: [] }];
assert.equal(opens(), true, "the kept reply row is drawn again when there is something to open");
await h.close();
});
test("a settled subagent's tab shows nothing while its transcript is read, and says so when the read fails", async () => {
let fail: (error: HostCallFailed) => void = () => {};
const h = harness((method) =>
method === "host/chats.load_task"
? Effect.callback<unknown, HostCallFailed>((resume) => {
fail = (error) => resume(Effect.fail(error));
})
: undefined,
),
c = chat();
h.controller.state.chats[c.id] = c;
const t = h.controller.transcript(c.id);
t.snapshot = { kind: "ready" };
applyEvent(t, taskEvent({ id: "helper", title: "Count the tests", status: "completed" }));
await Effect.runPromise(openSubagent(h.controller, c, "helper"));
const texts = () => nodes(renderSubagentPane(h.v, c.id, "helper")).map((node) => node.text);
assert.ok(!texts().includes("The subagent left no transcript."), "nothing is said while it reads");
fail(new HostCallFailed({ method: "host/chats.load_task", code: -32603, message: "the history cannot be aligned" }));
await new Promise((resolve) => setTimeout(resolve, 0));
assert.ok(!texts().includes("The subagent left no transcript."));
assert.ok(texts().includes("Could not read the subagent's transcript: the history cannot be aligned"), String(texts()));
});
test("on its own row only a background subagent keeps its marks; any subagent in a group keeps them", () => {
const h = harness(),
c = chat();
h.controller.state.chats[c.id] = c;
const t = h.controller.transcript(c.id);
t.snapshot = { kind: "ready" };
applyEvent(t, taskEvent({ id: "fg", title: "Look around", status: "running" }));
applyEvent(t, taskEvent({ id: "bg", title: "Watch the build", status: "running", background: true }));
const task = (id: string) => t.items.find((entry) => (entry as { task?: { id: string } }).task?.id === id) as never;
const marks = (id: string, compact?: boolean) => {
const all = nodes(renderTask(h.v, c, t, task(id), compact));
return { slot: all.some((node) => node.width === 14), spinners: all.filter((node) => node.type === "spinner").length, bot: all.some((node) => node.type === "icon" && node.name === "bot") };
};
assert.deepEqual(marks("fg"), { slot: false, spinners: 1, bot: false }, "a foreground subagent spins at the row's end and shows no icon");
assert.deepEqual(marks("bg"), { slot: true, spinners: 1, bot: true }, "a background subagent keeps its status mark and its agent's mark");
assert.deepEqual(marks("fg", true), { slot: true, spinners: 1, bot: true }, "in a group every subagent keeps its marks");
});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.