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.8
Permissions in 0.2.8
Files
changes.test.ts15.8 KB
// A turn that changed files ends with a summary of them: where it goes,
// in one card with the time the run worked, open or folded, the files under
// their folders with their lines, the diff a click opens, the summaries a
// transcript read and the host's events bring, and nothing at all from an
// older host.
import assert from "node:assert/strict";
import test from "node:test";
import * as Effect from "effect/Effect";
import * as Stream from "effect/Stream";
import { Events, HostCallFailed } from "divergence/effect";
import type { ChangedFile, HostEvents, TurnSummary } from "divergence";
import type { Controller } from "./controller.ts";
import { byFolder, endTurns, followTurnChanges, openTurnDiff, totals } from "./changes.ts";
import { loadOlder, loadTranscript } from "./data.ts";
import { renderTranscript } from "./views/rows.tsx";
import { chat, harness, item, nodes } from "./ui-for-tests.test.ts";
import type { TestNode } from "./ui-for-tests.test.ts";
const file = (path: string, added?: number, removed?: number): ChangedFile =>
added === undefined ? { path } : { path, added, removed };
// u1 and its reply, then u2 with a tool call and its reply.
const ITEMS = [
item({ id: "u1", role: "user", text: "first" }),
item({ id: "a1", role: "assistant", text: "reply one" }),
item({ id: "u2", role: "user", text: "second" }),
item({ id: "t1", role: "tool", call: { kind: "read", title: "Read a.ts" } }),
item({ id: "a2", role: "assistant", text: "reply two" }),
];
function setup(turns: TurnSummary[] = []) {
const diffs: unknown[] = [];
const h = harness((method, params) => {
if (method !== "host/chats.turn_diff") return undefined;
diffs.push(params);
return Effect.succeed({ diff: "--- a/src/a.rs\n+++ b/src/a.rs\n" });
});
h.controller.api.toolRenderers = () => [];
h.controller.state.chats.c = chat({ id: "c", workspaceId: "w1", sessionId: "s" });
const t = h.controller.transcript("c");
t.items = [...ITEMS];
t.snapshot = { kind: "ready" };
t.running = false;
for (const turn of turns) t.turnFiles.set(turn.itemId, turn);
const rows = () => {
const scroller = nodes(renderTranscript(h.v, h.controller.state.chats.c!)).find((node) => node.type === "scroller");
return new Map((scroller?.items ?? []).map((row) => [String(row.id), row]));
};
return { h, t, rows, diffs };
}
const find = (row: unknown, id: string) => nodes(row).find((node) => node.id === id);
const texts = (row: unknown) => nodes(row).flatMap((node) => (typeof node.text === "string" ? [node.text] : []));
// The card that holds a node: the `muted` box around it.
const cardOf = (row: unknown, id: string) =>
nodes(row).find((node: TestNode & { borderRadius?: unknown }) => node.background === "muted" && !!find(node, id));
test("each turn ends with its summary, every one folded until it is clicked", async () => {
const { h, rows } = setup([
{ itemId: "u1", files: [file("src/a.rs", 3, 1)], before: "u2" },
{ itemId: "u2", files: [file("src/a.rs", 2, 0), file("README.md", 1, 1)] },
]);
const shown = rows();
const first = find(shown.get("transcript-row-a1"), "changes-u1");
assert.ok(first, "u1's summary ends its turn, after its reply");
assert.deepEqual(texts(first), ["1 changed file", "+3", "-1"]);
assert.equal(find(shown.get("transcript-row-a1"), "changes-scroll-u1"), undefined, "a turn before the latest starts folded");
assert.equal(find(shown.get("transcript-row-a2"), "changes-scroll-u2"), undefined, "and so does the latest, so its list never takes the room unasked");
const latest = find(shown.get("transcript-row-a2"), "changes-u2");
assert.ok(latest, "the latest turn's summary ends the transcript");
assert.deepEqual(texts(latest), ["2 changed files", "+3", "-1"]);
for (const id of ["transcript-row-u1", "transcript-row-u2"]) assert.equal(find(shown.get(id), "changes-u1"), undefined);
latest!.onClick();
const opened = rows().get("transcript-row-a2");
assert.ok(find(opened, "changes-scroll-u2"), "a click opens it");
assert.equal(find(find(opened, "changes-u2"), "changes-scroll-u2"), undefined, "the list opens under the card, not inside it");
assert.ok(find(opened, "change-u2-src/a.rs") && find(opened, "change-u2-README.md"));
find(opened, "changes-u2")!.onClick();
assert.equal(find(rows().get("transcript-row-a2"), "changes-scroll-u2"), undefined, "and a second click folds it");
await h.close();
});
test("the time a run worked and what its turn changed are one card, which is there with either alone", async () => {
const { h, t, rows } = setup([{ itemId: "u2", files: [file("src/a.rs", 2, 0), file("README.md", 1, 1)] }]);
t.worked.set("a2", 42_000);
t.worked.set("a1", 5_000);
const shown = rows();
const card = find(shown.get("transcript-row-a2"), "changes-u2") as (TestNode & Record<string, unknown>) | undefined;
assert.ok(card && find(card, "worked-a2"), "the reply's time sits in its turn's card");
assert.deepEqual(texts(card), ["Worked for 42s", "2 changed files", "+3", "-1"]);
assert.equal(card.background, "muted", "a filled button's surface");
assert.equal(card.elevation, undefined, "no edge or shadow");
assert.equal(card.height, 22.5, "as tall as the small buttons beside it");
assert.equal(typeof card.onClick, "function");
// A turn that changed no file keeps the same card around its time alone.
const alone = cardOf(shown.get("transcript-row-a1"), "worked-a1") as (TestNode & Record<string, unknown>) | undefined;
assert.ok(alone, "a time alone has the card too");
assert.deepEqual(texts(alone), ["Worked for 5s"]);
assert.equal(alone.height, 22.5);
assert.equal(alone.onClick, undefined, "and nothing to open");
// A run that ended on a group of tool calls puts the card after it.
t.items = t.items.filter((entry) => entry.id !== "a2");
t.worked.set("t1", 3_000);
const tooled = cardOf(rows().get("transcript-row-tools-t1"), "worked-t1");
assert.ok(tooled && tooled.id === "changes-u2", "after the group, with the turn's files");
assert.deepEqual(texts(tooled), ["Worked for 3s", "2 changed files", "+3", "-1"]);
await h.close();
});
test("a late command does not separate the run time from its changed files", async () => {
const { h, t, rows } = setup([{ itemId: "u2", files: [file("src/a.rs", 2, 0)] }]);
t.worked.set("a2", 42_000);
t.items.push(item({ id: "late", role: "tool", call: { kind: "execute", title: "Run" } }));
const shown = rows();
const card = find(shown.get("transcript-row-tools-late"), "changes-u2");
assert.ok(card && find(card, "worked-a2"));
assert.deepEqual(texts(card), ["Worked for 42s", "1 changed file", "+2", "-0"]);
assert.equal(find(shown.get("transcript-row-a2"), "changes-u2"), undefined);
assert.equal(find(shown.get("transcript-row-a2"), "copy-a2"), undefined);
assert.ok(find(shown.get("transcript-row-tools-late"), "copy-a2") && find(shown.get("transcript-row-tools-late"), "reply-a2"));
h.controller.state.chats.c = { ...h.controller.state.chats.c!, working: { agents: 0, commands: 1 } };
const active = rows().get("transcript-row-tools-late");
assert.ok(find(active, "changes-u2") && find(active, "background-tasks"), "a running command shares the reply's action row");
h.controller.state.chats.c = { ...h.controller.state.chats.c!, working: { agents: 0, commands: 0 } };
assert.equal(find(rows().get("transcript-row-tools-late"), "background-tasks"), undefined, "a finished command is not counted");
await h.close();
});
test("a summary that changes draws its row again and leaves the others as they were", async () => {
const { h, t, rows } = setup([{ itemId: "u1", files: [file("a.rs", 1, 0)], before: "u2" }]);
const before = rows();
t.turnFiles.set("u2", { itemId: "u2", files: [file("b.rs", 4, 0)] });
const after = rows();
assert.equal(after.get("transcript-row-a1"), before.get("transcript-row-a1"), "u1's row is kept");
assert.notEqual(after.get("transcript-row-a2"), before.get("transcript-row-a2"), "the row u2's summary joined draws again");
await h.close();
});
test("a turn's files sit under their folders, folders first, with each file's lines and the turn's totals", async () => {
const files = [file("src/b.rs", 1, 0), file("README.md", 2, 2), file("src/a10.rs", 1, 1), file("src/a2.rs", 0, 3), file("crates/x/y.rs", 5, 0), file("logo.png")];
assert.deepEqual(
byFolder(files).map(({ folder, files }) => [folder, files.map((file) => file.path)]),
[
["crates/x", ["crates/x/y.rs"]],
["src", ["src/a2.rs", "src/a10.rs", "src/b.rs"]],
["", ["logo.png", "README.md"]],
],
);
assert.deepEqual(totals(files), { added: 9, removed: 6 }, "a file whose lines are unknown counts for none");
assert.equal(totals([file("logo.png")]), null);
const { h, rows } = setup([{ itemId: "u2", files }]);
find(rows().get("transcript-row-a2"), "changes-u2")!.onClick();
const summary = rows().get("transcript-row-a2");
const nested = find(summary, "change-u2-src/a2.rs");
assert.equal(nested?.paddingLeft, 20, "a file in a folder sits one step in");
assert.deepEqual(texts(nested), ["a2.rs", "+0", "-3"]);
assert.equal(find(summary, "change-u2-README.md")?.paddingLeft, 6);
assert.deepEqual(texts(find(summary, "change-u2-logo.png")), ["logo.png"], "a binary file shows no lines");
assert.ok(texts(summary).includes("crates/x") && texts(summary).includes("src"), "each folder heads its files");
await h.close();
});
test("a click on a file opens what the turn did to it in a diff tab of the chat's task", async () => {
const { h, rows, diffs } = setup([{ itemId: "u2", files: [file("src/a.rs", 1, 1)] }]);
const opened: unknown[] = [];
h.controller.tabs = {
open: (params: unknown) => Effect.sync(() => (opened.push(params), { id: "diff" })),
} as unknown as Controller["tabs"];
find(rows().get("transcript-row-a2"), "changes-u2")!.onClick();
find(rows().get("transcript-row-a2"), "change-u2-src/a.rs")!.onClick();
await h.settle();
assert.deepEqual(diffs, [{ chatId: "c", itemId: "u2", path: "src/a.rs" }]);
assert.deepEqual(opened, [
{ kind: "diff", workspaceId: "w1", path: "src/a.rs", diff: "--- a/src/a.rs\n+++ b/src/a.rs\n", chatId: "c" },
]);
assert.deepEqual(h.notices, []);
await h.close();
});
test("a diff the host no longer has says so and opens no tab", async () => {
const h = harness((method) =>
method === "host/chats.turn_diff"
? Effect.fail(new HostCallFailed({ method, code: -32000, message: "the changes of that turn are no longer kept" }))
: undefined,
);
h.controller.state.chats.c = chat({ id: "c" });
const opened: unknown[] = [];
h.controller.tabs = { open: (params: unknown) => Effect.sync(() => opened.push(params)) } as unknown as Controller["tabs"];
await Effect.runPromise(openTurnDiff(h.controller, "c", "u1", "a.rs"));
assert.deepEqual(opened, []);
assert.deepEqual(h.notices, ["Could not show the changes to a.rs: the changes of that turn are no longer kept"]);
await h.close();
});
test("the summaries come with the transcript's pages, and an older host's read brings none", async () => {
const pages: Record<string, unknown> = {
newest: { items: ITEMS.slice(2), start: 2, turnChanges: [{ itemId: "u2", files: [file("b.rs", 1, 0)] }] },
older: { items: ITEMS.slice(0, 2), start: 0, turnChanges: [{ itemId: "u1", files: [file("a.rs", 2, 0)], before: "u2" }] },
};
const h = harness((method, params) => {
if (method === "host/chats.transcript") {
const page = (params as { before?: number }).before === undefined ? pages.newest : pages.older;
return Effect.succeed({ pendingApprovals: [], pendingQuestions: [], plan: null, usage: {}, running: false, ...(page as object) });
}
if (method === "host/chats.checkpoints") return Effect.succeed({ checkpoints: [] });
return undefined;
});
h.controller.state.chats.c = chat({ id: "c" });
await Effect.runPromise(loadTranscript(h.controller, "c", { history: false }));
const t = h.controller.state.transcripts.c!;
assert.deepEqual([...t.turnFiles.keys()], ["u2"]);
await Effect.runPromise(loadOlder(h.controller, "c"));
assert.deepEqual([...t.turnFiles.keys()], ["u2", "u1"], "an older page adds the turns that end in it");
assert.equal(t.turnFiles.get("u1")?.before, "u2");
pages.newest = { items: ITEMS, start: 0 };
await Effect.runPromise(loadTranscript(h.controller, "c", { history: false }));
assert.equal(t.turnFiles.size, 0, "an older host's transcript has no summaries");
assert.ok(!nodes(renderTranscript(h.v, h.controller.state.chats.c!)).some((node) => String(node.id).startsWith("changes-")));
await h.close();
});
/** Follows these host events, each delivered once to whoever follows its name. */
const follow = (c: Controller, list: HostEvents[keyof HostEvents][]) => {
const events = { stream: (name: string) => Stream.fromIterable(list.filter((event) => event.event === name)) };
return Effect.runPromise(
Effect.scoped(
followTurnChanges(c).pipe(
Effect.provideService(Events, events as unknown as Events["Service"]),
Effect.andThen(Effect.sleep("10 millis")),
),
),
);
};
test("a turn that just ended adds its summary, and the next message you send ends it", async () => {
const { h, t, rows } = setup();
const changes = (itemId: string, files?: ChangedFile[]): HostEvents["turn_changes"] => ({
event: "turn_changes",
chatId: "c",
itemId,
workspaceId: "w1",
paths: ["a.rs"],
...(files ? { files } : {}),
});
await follow(h.controller, [changes("u1"), changes("u9", [])]);
assert.equal(t.turnFiles.size, 0, "an older host sends paths alone, and a turn that changed nothing has no summary");
const version = t.version;
await follow(h.controller, [changes("u2", [file("a.rs", 1, 0)])]);
assert.deepEqual(t.turnFiles.get("u2"), { itemId: "u2", files: [file("a.rs", 1, 0)] });
assert.ok(t.version > version, "a transcript read under way reads again");
assert.ok(find(rows().get("transcript-row-a2"), "changes-u2"), "its card ends the turn, folded");
endTurns(t, item({ id: "u2", role: "user", text: "second" }));
endTurns(t, { ...item({ id: "r1", role: "user", text: "from another agent" }), from: "other" });
assert.equal(t.turnFiles.get("u2")?.before, undefined, "neither the turn's own message nor another agent's ends it");
const next = item({ id: "u3", role: "user", text: "third" });
t.items.push(next);
endTurns(t, next);
assert.equal(t.turnFiles.get("u2")?.before, "u3");
const shown = rows();
assert.equal(find(shown.get("transcript-row-u3"), "changes-u2"), undefined, "the summary stays before the new message");
const kept = find(shown.get("transcript-row-a2"), "changes-u2");
assert.ok(kept && !find(kept, "changes-scroll-u2"), "and stays folded once a turn comes after it");
await h.close();
});
test("a pause shows the latest turn's summary, and the agent working again takes it away until the turn ends", async () => {
const { h, t, rows } = setup([{ itemId: "u2", files: [file("a.rs", 1, 0)] }]);
assert.ok(find(rows().get("transcript-row-a2"), "changes-u2"), "a settled run shows what its turn changed");
// The agent starts another run without a message from you.
t.running = true;
t.items.push(item({ id: "a3", role: "assistant", text: "carrying on" }));
let shown = rows();
for (const id of ["transcript-row-a2", "transcript-row-a3"])
assert.equal(find(shown.get(id), "changes-u2"), undefined, "the summary leaves the end of a turn still at work");
t.running = false;
shown = rows();
assert.ok(find(shown.get("transcript-row-a3"), "changes-u2"), "and comes back where the turn now ends");
assert.equal(find(shown.get("transcript-row-a2"), "changes-u2"), undefined);
// A turn that a later message ended keeps its summary while the next one runs.
t.turnFiles.set("u2", { itemId: "u2", files: [file("a.rs", 1, 0)], before: "u3" });
t.items.push(item({ id: "u3", role: "user", text: "third" }));
t.running = true;
assert.ok(find(rows().get("transcript-row-a3"), "changes-u2"));
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.