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.6
Permissions in 0.2.6
Files
turn-times.test.ts9.2 KB
// How long each run went and how it ended: the working row, the quiet line
// after the row a run ended on, a stopped run's notice, and errors.
import assert from "node:assert/strict";
import test from "node:test";
import type { TranscriptItem } from "divergence";
import { applyEvent, readRun, startRun, stoppedAfter, workedFor, workingFor } from "./transcript.ts";
import { renderItems, renderTranscript } from "./views/rows.tsx";
import { chat, harness, nodes, transcript as initial } from "./ui-for-tests.test.ts";
const ago = (ms: number) => new Date(Date.now() - ms).toISOString();
const at = (seconds: number) => new Date(Date.UTC(2026, 10, 3, 12, 0, seconds)).toISOString();
const say = (id: string, createdAt?: string): TranscriptItem => ({ id, createdAt, role: "user", blocks: [{ type: "text", text: id }] });
const reply = (id: string, createdAt?: string): TranscriptItem => ({ id, createdAt, role: "assistant", text: `reply ${id}` });
const notice = (id: string, text: string, createdAt?: string): TranscriptItem => ({ id, createdAt, role: "notice", text });
const idle = (items: TranscriptItem[] = []) => ({ ...initial(items), running: false });
const shownNodes = (t: ReturnType<typeof idle>) => {
const h = harness();
const c = chat();
h.controller.state.chats[c.id] = c;
h.controller.state.transcripts[c.id] = t;
return nodes(renderItems(h.v, c, t, t.items));
};
const texts = (t: ReturnType<typeof idle>) => shownNodes(t).flatMap((node) => (typeof node.text === "string" ? [node.text] : []));
test("the working row counts from your message, a steer keeps that start, and the run says how long it worked", () => {
const t = idle();
const first = say("u1", ago(42_000));
t.items.push(first);
startRun(t, first);
assert.equal(workingFor(t), "Working for 42s");
applyEvent(t, { event: "text_delta", itemId: "a1", text: "Looking." });
const steer = say("u2", ago(0));
t.items.push(steer);
startRun(t, steer);
assert.equal(workingFor(t), "Working for 42s", "a steer joins the run going");
applyEvent(t, { event: "text_delta", itemId: "a2", text: "Done." });
applyEvent(t, { event: "run_finished", outcome: { status: "completed" } });
assert.equal(t.started, undefined);
assert.match(workedFor(t, t.items.at(-1)!) ?? "", /^Worked for 4[23]s$/);
assert.equal(workedFor(t, t.items[1]!), null, "only the row the run ended on has the time");
// A reply says it once, at the head of its own action row.
assert.equal(texts(t).filter((text) => text.startsWith("Worked for")).length, 1);
const line = shownNodes(t).find((node) => node.id === "worked-a2");
assert.ok(nodes(line).some((node) => /^Worked for 4[23]s$/.test(String(node.text))));
// A run that ended on a tool row says it in a line after that row.
const tooled = idle([say("u1"), { id: "t1", role: "tool", call: { id: "t1", name: "read", title: "Read state.ts", kind: "read", status: "completed", content: [], locations: [] } } as never]);
tooled.worked.set("t1", 3_000);
assert.ok(texts(tooled).includes("Worked for 3s"));
// The agent going on by itself starts a run of its own.
applyEvent(t, { event: "run_started" });
assert.equal(workingFor(t), "Working for 0s");
});
test("a stopped run says how long it went, measured live or read back from the two times", () => {
const live = idle();
const message = say("u1", ago(12_000));
live.items.push(message);
startRun(live, message);
applyEvent(live, { event: "run_finished", outcome: { status: "cancelled" } });
const stop = live.items.at(-1)!;
assert.equal(stop.role === "notice" && stop.text, "Stopped.");
assert.equal(stoppedAfter(live, stop), "You stopped after 12s");
assert.equal(workedFor(live, stop), null, "the notice itself says the time");
const shown = texts(live);
assert.ok(shown.includes("You stopped after 12s") && !shown.includes("Stopped."));
const stored = idle([say("u1", at(0)), reply("a1", at(3)), notice("n1", "Stopped.", at(12))]);
assert.ok(texts(stored).includes("You stopped after 12s"));
// Without both times only the stop itself is known.
assert.ok(texts(idle([say("u1"), notice("n1", "Stopped.", at(12))])).includes("You stopped the agent."));
assert.equal(stoppedAfter(stored, notice("elsewhere", "Stopped.", at(12))), "You stopped the agent.");
});
test("a turn read back from history shows no time, since nothing stored marks when it ended", () => {
const t = idle([say("u1", at(0)), reply("a1", at(5))]);
readRun(t);
assert.equal(t.started, undefined);
assert.ok(!texts(t).some((text) => text.startsWith("Worked for")));
});
test("a transcript read while its run goes counts from your last message, unless the run was seen starting", () => {
const t = initial([say("u1", at(0)), reply("a1", at(3)), say("u2", at(60)), reply("a2", at(65))]);
readRun(t);
assert.equal(t.started, Date.parse(at(60)));
t.started = 5;
readRun(t);
assert.equal(t.started, 5, "a run this plugin saw start keeps its start");
const untimed = initial([say("u1"), reply("a1")]);
readRun(untimed);
assert.equal(workingFor(untimed), "Working…");
});
test("a run that ends right after your message says so, as the host's copy does", () => {
const t = idle();
const message = say("u1", ago(2_000));
t.items.push(message);
startRun(t, message);
applyEvent(t, { event: "run_finished", outcome: { status: "completed" } });
const end = t.items.at(-1)!;
assert.match(end.role === "notice" ? end.text : "", /^The agent ended the turn without a reply\./);
assert.equal(workedFor(t, end), null);
// A failure's own message says how it ended, with no time beside it.
const failed = idle();
startRun(failed, message);
failed.items.push(message, reply("a1"));
applyEvent(failed, { event: "run_finished", outcome: { status: "failed", message: "Out of credits" } });
assert.equal(workedFor(failed, failed.items.at(-1)!), null);
});
test("a failed run's message reads as an error, and decisions and held messages stay quiet", () => {
const decision = { id: "a", decision: "allow", decidedBy: "guard" } as const;
const t = idle([
say("u1", at(0)),
notice("n1", "Out of credits", at(4)),
{ id: "n2", role: "notice", text: "Allowed by guard", approval: decision },
notice("n3", "The message is sent once the Codex update finishes."),
]);
const h = harness();
const c = chat();
h.controller.state.chats[c.id] = c;
const shown = nodes(renderItems(h.v, c, t, t.items));
const errors = shown.filter((node) => node.type === "callout");
assert.deepEqual(
errors.map((node) => [node.tone, node.text]),
[["danger", "Out of credits"]],
);
for (const quiet of ["Allowed by guard", "The message is sent once the Codex update finishes."])
assert.ok(shown.some((node) => node.type === "text" && node.text === quiet), quiet);
});
test("the row a run ended on draws again when its time arrives, and the others are kept", () => {
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 = [say("u1", ago(5_000)), reply("a1", ago(4_000))];
t.snapshot = { kind: "ready" };
t.running = false;
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]));
};
const before = rows();
t.worked.set("a1", 5_000);
const after = rows();
assert.equal(after.get("transcript-row-u1"), before.get("transcript-row-u1"));
assert.notEqual(after.get("transcript-row-a1"), before.get("transcript-row-a1"));
assert.ok(nodes(after.get("transcript-row-a1")).some((node) => node.text === "Worked for 5s"));
});
test("a /compact turn shows its compaction from when it begins and ends without a no-reply error", () => {
const t = idle();
const message = say("u1", ago(2_000));
t.items.push(message);
startRun(t, message);
applyEvent(t, { event: "compacting" });
const begun = t.items.at(-1)!;
assert.equal(begun.role === "compaction" && begun.running, true);
// Claude repeats the report with the summary's progress: still one row.
applyEvent(t, { event: "compacting" });
applyEvent(t, { event: "compacting" });
assert.equal(t.items.length, 2);
applyEvent(t, { event: "compacted", summary: "We said hi." });
assert.equal(t.items.length, 2, "the compaction ends in the row it began in");
assert.deepEqual({ ...t.items[1], createdAt: undefined }, { id: begun.id, createdAt: undefined, role: "compaction", summary: "We said hi." });
applyEvent(t, { event: "run_finished", outcome: { status: "completed" } });
assert.ok(!t.items.some((item) => item.role === "notice"), "compacting is the turn's answer");
// One the run left unfinished goes with the run.
startRun(t, message);
applyEvent(t, { event: "compacting" });
applyEvent(t, { event: "run_finished", outcome: { status: "failed", message: "too large" } });
assert.ok(!t.items.some((item) => item.role === "compaction" && item.running));
// The same notice on both sides of a dropped compaction reads once.
startRun(t, message);
applyEvent(t, { event: "compacting" });
applyEvent(t, { event: "run_finished", outcome: { status: "failed", message: "too large" } });
assert.equal(t.items.filter((item) => item.role === "notice").length, 1);
});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.