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
message-actions.test.ts7.1 KB
// Copy, Reply and Fork under messages, and where a fork may start.
import assert from "node:assert/strict";
import test from "node:test";
import * as Effect from "effect/Effect";
import { harness, nodes, chat as makeChat, transcript as initial } from "./ui-for-tests.test.ts";
import { renderItems, turnEnds } from "./views/rows.tsx";
import { renderTitle } from "./views/title.tsx";
import { sentAt } from "./time.ts";
import type { TranscriptItem } from "divergence";
const say = (id: string): TranscriptItem => ({ id, role: "user", blocks: [{ type: "text", text: id }] });
const reply = (id: string, text = `reply ${id}`): TranscriptItem => ({ id, role: "assistant", text });
const tool = (id: string): TranscriptItem =>
({ id, role: "tool", call: { id, name: "read", title: "Read", kind: "read", status: "completed", content: [], locations: [] } }) as never;
const conversation = () => [say("u1"), reply("a1"), tool("t1"), reply("a2"), say("u2"), reply("b1")];
test("each turn ends at its last reply, and a fork from it stops before the next message", () => {
assert.deepEqual(Object.fromEntries(turnEnds(conversation(), false)), { a2: "u2", b1: null });
// The turn still running has no end yet.
assert.deepEqual(Object.fromEntries(turnEnds(conversation(), true)), { a2: "u2" });
// A blank reply ends nothing; the reply before it does.
assert.deepEqual(Object.fromEntries(turnEnds([say("u1"), reply("a1"), reply("a2", " \n")], false)), { a1: null });
});
const shownIds = (capabilities: Record<string, boolean>, running = false) => {
const h = harness();
const chat = makeChat({ agentId: "agent", sessionId: "s" });
h.controller.state.chats[chat.id] = chat;
h.controller.state.agents.agent = { id: "agent", name: "Agent", capabilities } as never;
const t = initial(conversation());
t.running = running;
h.controller.state.transcripts[chat.id] = t;
return nodes(renderItems(h.v, chat, t, t.items)).flatMap((node) => (node.id ? [node.id] : []));
};
test("copy sits under every message, reply under replies, fork only where the agent can fork", () => {
const ids = shownIds({ fork: true });
for (const id of ["copy-u1", "copy-a2", "reply-a2", "copy-u2", "copy-b1", "reply-b1"])
assert.ok(ids.includes(id), id);
// Under a prompt, Reply beside Revert would look like a second undo.
assert.ok(!ids.includes("reply-u1") && !ids.includes("reply-u2"), "a prompt has no reply");
assert.ok(!ids.includes("copy-a1"), "a reply in the middle of a turn has none");
// Forking only whole conversations: the latest reply alone.
assert.deepEqual(
ids.filter((id) => id.startsWith("fork-")),
["fork-b1"],
);
assert.deepEqual(
shownIds({ fork: true, forkAt: true }).filter((id) => id.startsWith("fork-")),
["fork-a2", "fork-b1"],
);
assert.deepEqual(
shownIds({}).filter((id) => id.startsWith("fork-")),
[],
);
// While the last turn runs its reply is not finished.
const running = shownIds({ fork: true, forkAt: true }, true);
assert.ok(running.includes("fork-a2") && !running.includes("fork-b1") && !running.includes("copy-b1"));
});
test("the final reply's actions follow late tools in each settled turn", () => {
const h = harness();
const chat = makeChat({ agentId: "agent", sessionId: "s" });
h.controller.state.chats[chat.id] = chat;
h.controller.state.agents.agent = { id: "agent", name: "Agent", capabilities: { fork: true, forkAt: true } } as never;
const t = h.controller.transcript(chat.id);
t.items = [say("u1"), reply("a1"), tool("t1"), say("u2"), reply("a2"), tool("t2")];
t.running = false;
const rows = renderItems(h.v, chat, t, t.items);
const ids = (index: number) => nodes(rows[index]).map((node) => node.id);
assert.ok(!ids(1).includes("copy-a1") && ids(2).includes("fork-a1"));
assert.ok(!ids(4).includes("copy-a2") && ids(5).includes("fork-a2"));
t.running = true;
const active = renderItems(h.v, chat, t, t.items);
assert.ok(!nodes(active[5]).some((node) => node.id === "copy-a2"));
});
test("fork asks the host for a copy that stops before the next message, and opens it", async () => {
const forks: unknown[] = [];
const h = harness((method, params) => {
if (method !== "host/chats.fork") return undefined;
forks.push(params);
return Effect.succeed(makeChat({ id: "copy", workspaceId: "w" }));
});
const chat = makeChat({ sessionId: "s" });
h.controller.state.chats[chat.id] = chat;
h.controller.state.agents.agent = { id: "agent", name: "Agent", capabilities: { fork: true, forkAt: true } } as never;
const t = initial(conversation());
t.running = false;
h.controller.state.transcripts[chat.id] = t;
const press = (id: string) => {
const button = nodes(renderItems(h.v, chat, t, t.items)).find((node) => node.id === id);
button?.onClick();
};
press("fork-a2");
press("fork-b1");
await h.settle();
assert.deepEqual(forks, [{ chatId: "c", before: "u2" }, { chatId: "c" }]);
assert.equal(h.controller.api.app.state().chatId, "copy", "the copy opens");
});
test("copy writes the message to the clipboard and shows a check", async () => {
const h = harness();
const chat = makeChat();
h.controller.state.chats[chat.id] = chat;
const t = initial(conversation());
t.running = false;
h.controller.state.transcripts[chat.id] = t;
const find = (id: string) => nodes(renderItems(h.v, chat, t, t.items)).find((node) => node.id === id);
find("copy-b1")?.onClick();
await new Promise<void>((resolve) => setImmediate(resolve));
assert.deepEqual(
h.calls.filter((call) => call.method === "copy_text").map((call) => call.params),
[{ text: "reply b1" }],
);
assert.equal(find("copy-b1")?.icon, "check");
assert.equal(find("copy-a2")?.icon, "copy");
});
test("a message's action row says when it was sent, with the whole date and time on hover", () => {
const h = harness();
const chat = makeChat();
h.controller.state.chats[chat.id] = chat;
const sent = new Date(Date.now() - 60_000).toISOString();
const t = initial([{ ...say("u1"), createdAt: sent }, { ...reply("a1"), createdAt: sent }, say("u2"), reply("b1")]);
t.running = false;
h.controller.state.transcripts[chat.id] = t;
const shown = nodes(renderItems(h.v, chat, t, t.items));
const expected = sentAt(sent)!;
for (const id of ["sent-u1", "sent-a1"]) {
const node = shown.find((n) => n.id === id);
assert.equal(node?.tooltip, expected.full, id);
assert.ok(nodes(node).some((n) => n.text === expected.label), id);
}
// Under your message the time always shows, as the buttons do.
assert.equal(shown.find((n) => n.id === "sent-u1")?.visibility, undefined);
assert.ok(!shown.some((n) => n.id === "sent-u2" || n.id === "sent-b1"), "a message without a time shows none");
});
test("the title strip no longer has a fork button", () => {
const h = harness();
const chat = makeChat();
h.controller.state.chats[chat.id] = chat;
h.controller.state.agents.agent = { id: "agent", name: "Agent", capabilities: { fork: true } } as never;
const v = { ...h.v, ctx: { ...h.v.ctx, app: { route: "chat", chatId: chat.id } } };
const ids = nodes(renderTitle(v)).flatMap((node) => (node.id ? [node.id] : []));
assert.ok(!ids.some((id) => id.startsWith("fork-")));
});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.