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
rows.test.ts7 KB
// A transcript keeps the rows that did not change between renders, so the
// runtime skips them, and draws again every row whose inputs changed.
import assert from "node:assert/strict";
import test from "node:test";
import type { AgentEventKind } from "divergence";
import { applyEvent } from "./transcript.ts";
import { renderTool, renderTranscript } from "./views/rows.tsx";
import { chat, harness, item, nodes } from "./ui-for-tests.test.ts";
import { carriedTranscript } from "./state.ts";
import { noteWindows } from "./window.ts";
import { TOP_FADE_HEIGHT } from "./views/styles.tsx";
function setup() {
const h = harness();
h.controller.api.toolRenderers = () => [];
h.controller.state.chats.a = chat({ id: "a", sessionId: "s" });
const t = h.controller.transcript("a");
t.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", content: [{ type: "text", text: "x" }] } }),
item({ id: "a2", role: "assistant", text: "reply" }),
];
t.snapshot = { kind: "ready" };
// The rows of the scroller, by the id each row's column carries.
const rows = () => {
const scroller = nodes(renderTranscript(h.v, h.controller.state.chats.a!)).find((node) => node.type === "scroller");
return new Map((scroller?.items ?? []).map((row) => [String(row.id), row]));
};
return { h, t, rows };
}
test("rows that did not change are the same elements as last render", () => {
const { t, rows } = setup();
const before = rows();
const after = rows();
for (const [id, row] of before) assert.equal(after.get(id), row, id);
applyEvent(t, { event: "text_delta", itemId: "a2", text: " more" } as AgentEventKind);
const streamed = rows();
assert.notEqual(streamed.get("transcript-row-a2"), after.get("transcript-row-a2"), "the streamed reply draws again");
assert.equal(streamed.get("transcript-row-a1"), after.get("transcript-row-a1"), "the replies before it are kept");
assert.ok(nodes(streamed.get("transcript-row-a2")).some((node) => node.text === "reply more"));
});
test("the first row keeps its column under the top fade, and gets a new one when a row comes before it", () => {
const { t, rows } = setup();
const first = rows().get("transcript-row-u1");
assert.equal(first?.paddingTop, TOP_FADE_HEIGHT, "the first row starts below the top fade");
assert.equal(rows().get("transcript-row-u1"), first, "drawn again, it is the same element");
t.items = [item({ id: "a0", role: "assistant", text: "earlier" }), ...t.items];
const moved = rows().get("transcript-row-u1");
assert.notEqual(moved, first, "no longer first, it is placed again");
assert.equal(moved?.paddingTop, undefined, "without the room of the top fade");
assert.equal(rows().get("transcript-row-a0")?.paddingTop, TOP_FADE_HEIGHT);
assert.equal(rows().get("transcript-row-u1"), moved, "and it is kept from then on");
});
test("what a transcript drew stays with it and is not carried across a reload", () => {
const { t, rows } = setup();
rows();
assert.ok(t.drawn?.rows.size, "the drawn rows are kept on the transcript");
assert.equal("drawn" in carriedTranscript(t), false, "a reload carries the transcript's data, not the rows the old code drew");
});
test("a reload keeps the last navigation revision so the next click is a new request", () => {
const { t } = setup();
t.scrollTo = { id: "transcript-row-u1", revision: 4, inset: TOP_FADE_HEIGHT };
assert.deepEqual(carriedTranscript(t).scrollTo, t.scrollTo);
});
test("navigation to a prompt outside a long transcript's window keeps the current rows", () => {
const { h, t } = setup();
noteWindows();
t.items = [item({ id: "u1", role: "user", text: "first" }), ...Array.from({ length: 1300 }, (_, i) => item({ id: `a${i}`, role: "assistant", text: `reply ${i}` }))];
const scroller = () => nodes(renderTranscript(h.v, h.controller.state.chats.a!)).find((node) => node.type === "scroller")!;
const before = scroller();
t.scrollTo = { id: "transcript-row-u1", revision: 1, inset: TOP_FADE_HEIGHT };
const after = scroller();
assert.equal((after.scrollTo as { index: number }).index, 0);
assert.equal(after.rowsBefore, before.rowsBefore, "the window stays at the reader while scrolling starts");
assert.ok(Number(after.rowsBefore) > 0, "the target starts outside the rendered window");
});
test("a tool update, a toggle and the run starting draw the rows they change", () => {
const { t, rows } = setup();
const before = rows();
const fold = [...before.keys()].find((id) => id.includes("tools-t1"))!;
applyEvent(t, { event: "tool_call_updated", id: "t1", status: "failed" } as AgentEventKind);
const updated = rows();
assert.notEqual(updated.get(fold), before.get(fold), "the updated call's fold draws again");
assert.equal(updated.get("transcript-row-u1"), before.get("transcript-row-u1"));
t.folds.set("tools-t1", false);
const folded = rows();
assert.notEqual(folded.get(fold), updated.get(fold), "closing the fold draws it again");
// A user row offers its edit only while nothing runs: every one draws again.
t.running = true;
const running = rows();
assert.notEqual(running.get("transcript-row-u1"), folded.get("transcript-row-u1"));
assert.notEqual(running.get("transcript-row-u2"), folded.get("transcript-row-u2"));
});
test("a running command on its own row spins at the row's end and shows no icon", () => {
const { h, t } = setup();
const run = item({ id: "t2", role: "tool", call: { kind: "execute", title: "cargo build", status: "running" } });
const draw = () => nodes(renderTool(h.v, t, run, h.controller.state.chats.a!));
const running = draw();
assert.equal(running.filter((node) => node.type === "spinner").length, 1);
assert.ok(!running.some((node) => node.width === 14), "no icon slot");
run.call.status = "completed";
const done = draw();
assert.ok(!done.some((node) => node.type === "spinner"));
assert.ok(!done.some((node) => node.type === "icon" && node.name === "square-terminal"));
});
test("a running command in a group spins where its terminal icon goes, and nowhere else", () => {
const { h, t } = setup();
const run = item({ id: "t2", role: "tool", call: { kind: "execute", title: "cargo build", status: "running" } });
const draw = () => {
const all = nodes(renderTool(h.v, t, run, h.controller.state.chats.a!, true));
const slot = all.find((node) => node.width === 14)!;
return { all, slot: nodes(slot) };
};
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.ok(!running.all.some((node) => node.type === "icon" && node.name === "square-terminal"));
run.call.status = "completed";
const done = draw();
assert.ok(!done.all.some((node) => node.type === "spinner"));
assert.ok(done.slot.some((node) => node.type === "icon" && node.name === "square-terminal"));
});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.