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
subagents.test.ts14.8 KB
// Regression coverage for subagents using the real chat modules.
// Fixtures exercise the same behavior and assertions as the JavaScript tests.
import { item as fixtureItem, fixtureTask, taskItemAt, entryItems } from "./ui-for-tests.test.ts";
import assert from "node:assert/strict";
import * as Effect from "effect/Effect";
import test from "node:test";
import {
applyTask,
findTask,
withoutSpawnRows,
groupTasks,
allTasks,
counts,
countsLabel,
groupLabel,
elapsed,
tokens,
metaLine,
resultOf,
isLive,
} from "./subagents.ts";
const task = fixtureTask;
test("a subagent goes inside the one that started it, at any depth", () => {
const items: import("divergence").TranscriptItem[] = [];
applyTask(items, task("a"));
applyTask(items, task("b", { parentTaskId: "a" }));
applyTask(items, task("c", { parentTaskId: "b" }));
assert.equal(items.length, 1);
assert.equal(findTask(items, "c")?.task.id, "c");
assert.equal(findTask(items, "b")?.items?.[0].id, "task-c");
});
test("a later snapshot updates the task in place and keeps its items", () => {
const items: import("divergence").TranscriptItem[] = [];
applyTask(items, task("a"));
findTask(items, "a")?.items?.push(fixtureItem({ id: "m", role: "assistant", text: "hi" }));
applyTask(items, task("a", { status: "completed", summary: "done" }));
assert.equal(items.length, 1);
assert.equal(taskItemAt(items, 0).task.status, "completed");
assert.equal(taskItemAt(items, 0).items?.length, 1);
});
test("the tool row that started a subagent is hidden, other tools stay", () => {
const items = [
fixtureItem({ id: "t1", role: "tool", call: { id: "t1" } }),
fixtureItem({ id: "t2", role: "tool", call: { id: "t2" } }),
fixtureItem({ id: "task-x", role: "task", task: task("x", { toolCallId: "t1" }), items: [] }),
];
assert.deepEqual(
withoutSpawnRows(items).map((i) => i.id),
["t2", "task-x"],
);
});
test("two or more subagents in a row form a group; one alone does not", () => {
const t = (id: string) => ({
kind: "item" as const,
item: fixtureItem({ id, role: "task", task: task(id), items: [] }),
});
const text = { kind: "item" as const, item: fixtureItem({ id: "m", role: "assistant" }) };
const out = groupTasks([t("a"), t("b"), text, t("c")]);
assert.equal(out.length, 3);
assert.equal(out[0].kind, "tasks");
assert.deepEqual(
entryItems(out[0]).map((i) => i.id),
["a", "b"],
);
assert.equal(out[2].kind, "item");
});
test("a workflow keeps its own card: it never joins a group of subagents", () => {
const t = (id: string, extra: Parameters<typeof fixtureTask>[1] = {}) => ({
kind: "item" as const,
item: fixtureItem({ id, role: "task", task: task(id, extra), items: [] }),
});
const out = groupTasks([t("a"), t("wf", { workflow: { phases: [], logs: [] } }), t("b"), t("c")]);
assert.deepEqual(
out.map((entry) => entry.kind),
["item", "item", "tasks"],
);
assert.equal(out[1].kind === "item" ? out[1].item.id : "", "wf");
});
test("a queued agent is work in hand, counted apart from the running ones", () => {
const tasks = [task("a", { status: "queued" }), task("b"), task("c", { status: "queued" })];
assert.ok(isLive(tasks[0]));
assert.equal(countsLabel(counts(tasks)), "1 working · 2 queued");
});
test("the roster lists parents before their children with depth", () => {
const items: import("divergence").TranscriptItem[] = [];
applyTask(items, task("a"));
applyTask(items, task("b", { parentTaskId: "a" }));
applyTask(items, task("c"));
assert.deepEqual(
allTasks(items).map((r) => [r.task.id, r.depth]),
[
["a", 0],
["b", 1],
["c", 0],
],
);
});
test("counts and labels read like the t3code roster", () => {
const tasks = [
task("a"),
task("b", { status: "waiting" }),
task("c", { status: "completed" }),
task("d", { status: "failed" }),
];
assert.equal(countsLabel(counts(tasks)), "2 working · 1 completed · 1 failed");
assert.equal(groupLabel(tasks), "Kicked off 4 subagents");
assert.equal(groupLabel([task("c", { status: "completed" })]), "Ran 1 subagent");
});
test("elapsed time, tokens and the meta line", () => {
const start = "2026-09-23T10:00:00Z";
const now = Date.parse("2026-09-23T10:01:05Z");
assert.equal(elapsed(task("a", { startedAt: start }), now), "1m 05s");
assert.equal(elapsed(task("a", { startedAt: start, endedAt: "2026-09-23T10:00:42Z" }), now), "42s");
assert.equal(elapsed(task("a"), now), null);
assert.equal(tokens(850), "850 tok");
assert.equal(tokens(12_345), "12k tok");
assert.equal(tokens(1_500), "1.5k tok");
const meta = metaLine(
task("a", { model: "sonnet", effort: "high", startedAt: start, usage: { usedTokens: 1500 }, toolUses: 1 }),
now,
);
assert.equal(meta, "sonnet · high · 1m 05s · 1.5k tok · 1 tool");
});
test("a finished subagent shows what it handed back, once", () => {
const spawn = fixtureItem({
id: "c1",
role: "tool",
call: { id: "c1", content: [{ type: "text", text: "Found 3 files." }] },
});
const item = fixtureItem({
id: "task-x",
role: "task",
task: task("x", { status: "completed", toolCallId: "c1" }),
items: [],
});
assert.deepEqual(resultOf(item, [spawn, item]), { text: "Found 3 files.", repeats: null });
item.task.summary = "The summary";
assert.deepEqual(resultOf(item, [spawn, item]), { text: "The summary", repeats: null });
item.items?.push(fixtureItem({ id: "m", role: "assistant", text: "The summary" }));
assert.deepEqual(resultOf(item, [spawn, item]), { text: "The summary", repeats: "m" }, "the last message already says it");
item.task.status = "running";
assert.equal(resultOf({ ...item, items: [] }, [spawn, item]), null, "nothing while it runs");
});
test("a finished subagent's tab ends with its answer once, as a reply with Copy and Reply under it", async () => {
const { harness, chat, taskEvent, nodes } = await import("./ui-for-tests.test.ts");
const { applyEvent } = await import("./transcript.ts");
const { renderSubagentPane } = await import("./views/tasks.tsx");
const h = harness();
const c = chat();
h.controller.state.chats[c.id] = c;
const t = h.controller.transcript(c.id);
t.snapshot = { kind: "ready" };
applyEvent(t, taskEvent({ id: "s", title: "Scout", status: "completed", summary: "Three files." }));
findTask(t.items, "s")?.items?.push(fixtureItem({ id: "m", role: "assistant", text: "Three files." }));
const pane = nodes(renderSubagentPane(h.v, c.id, "s"));
assert.deepEqual(pane.filter((node) => node.type === "markdown" && node.text === "Three files.").map((node) => node.id), ["md-task-result-s"], "its last message is the answer, drawn once");
assert.equal(pane.find((node) => node.id === "task-result-s")?.type, "reply", "in the chat's reply type");
assert.ok(pane.some((node) => node.id === "copy-task-result-s") && pane.some((node) => node.id === "reply-task-result-s"), "with Copy and Reply");
assert.equal(pane.some((node) => node.id === "fork-task-result-s"), false, "but no Fork");
await h.close();
});
test("a subagent's prompt offers Read more only when the kernel says five lines cut it off, and wraps within the pane", async () => {
const { harness, chat, taskEvent, nodes } = await import("./ui-for-tests.test.ts");
const { applyEvent } = await import("./transcript.ts");
const { renderSubagentPane } = await import("./views/tasks.tsx");
const h = harness();
// The tab is a view of its own, which draws again only through the plugin's tabs.
let redraws = 0;
h.controller.api.layouts.redraw = () => void redraws++;
const c = chat();
h.controller.state.chats[c.id] = c;
h.controller.state.agents[c.agentId] = { icon: "<svg/>" } as never;
const t = h.controller.transcript(c.id);
t.snapshot = { kind: "ready" };
// Short by its characters, long as laid out (or the other way round): only the kernel's measure decides.
applyEvent(t, taskEvent({ id: "s", title: "Scout", status: "running", prompt: "/a/long/unbroken/path".repeat(40) }));
const pane = () => nodes(renderSubagentPane(h.v, c.id, "s"));
const prompt = () => pane().find((node) => node.id === "task-prompt-s");
const clamp = () => pane().find((node) => node.clampLines === 5);
const more = () => pane().find((node) => node.id === "task-prompt-more-s");
assert.equal(prompt()?.type, "bubble", "the user's message bubble, which may shrink to the pane");
assert.equal(clamp()?.minWidth, 0, "and so may the prompt in it, so every line wraps to the pane");
assert.equal(clamp()?.lineHeight, 21.3, "five lines of the prompt's own line height");
assert.equal(pane().some((node) => node.lineClamp !== undefined), false, "no guess at the lines from the characters");
assert.equal(more(), undefined, "nothing is offered before the kernel says the prompt is cut off");
(clamp()?.onClamp as (event: { clamped: boolean }) => void)({ clamped: false });
assert.equal(more(), undefined, "a prompt that fits has no Read more");
(clamp()?.onClamp as (event: { clamped: boolean }) => void)({ clamped: true });
assert.equal(more()?.label, "Read more");
assert.equal(clamp()?.clampOpen, false);
const drawn = redraws;
assert.ok(drawn > 0, "the tab draws again to show Read more");
more()?.onClick();
assert.equal(redraws, drawn + 1, "and again when it is pressed");
assert.equal(clamp()?.clampOpen, true, "expanded in place");
assert.equal(more()?.label, "Show less");
(clamp()?.onClamp as (event: { clamped: boolean }) => void)({ clamped: false });
assert.equal(more(), undefined, "a pane widened until the prompt fits takes the button away");
assert.ok(pane().some((node) => node.type === "icon" && node.svg === "<svg/>"), "the icon of the agent running it");
await h.close();
});
test("a subagent's tab whose chat nothing read yet reads it and shows the subagent, not that it is gone", async () => {
const { harness, chat, taskEvent, nodes, transcript } = await import("./ui-for-tests.test.ts");
const { applyEvent } = await import("./transcript.ts");
const { renderSubagentPane } = await import("./views/tasks.tsx");
const stored = transcript();
applyEvent(stored, taskEvent({ id: "s", title: "Scout", status: "completed", prompt: "Look around" }));
let reads = 0;
const h = harness((method) => {
if (method === "host/chats.transcript")
return Effect.sync(() => void reads++).pipe(Effect.as({ items: stored.items, start: 0, userSessions: {}, pendingApprovals: [], pendingQuestions: [], running: false }));
if (method === "host/chats.checkpoints") return Effect.succeed({ checkpoints: [] });
return undefined;
});
const c = chat();
h.controller.state.chats[c.id] = c;
// After a restart its chat is in no pane on screen, so only the tab can read it.
const before = nodes(renderSubagentPane(h.v, c.id, "s"));
assert.ok(!before.some((node) => node.text === "This subagent is no longer in the chat."));
await h.settle();
assert.equal(reads, 1);
assert.ok(nodes(renderSubagentPane(h.v, c.id, "s")).some((node) => node.id === "task-prompt-s"));
await h.close();
});
test("a subagent's tab shows its agent's icon, a spinner while it works, and the terminal's mark for a command", async () => {
const { harness, chat, taskEvent, nodes } = await import("./ui-for-tests.test.ts");
const { applyEvent } = await import("./transcript.ts");
const { noteTask } = await import("./layout.ts");
const { renderTaskTitle } = await import("./views/layout.tsx");
const h = harness();
const c = chat({ id: "a" });
h.controller.state.chats[c.id] = c;
h.controller.state.agents[c.agentId] = { icon: "<svg/>" } as never;
const t = h.controller.transcript(c.id);
t.snapshot = { kind: "ready" };
applyEvent(t, taskEvent({ id: "s", title: "Scout", status: "running" }));
applyEvent(t, taskEvent({ id: "sh", title: "Build", status: "completed", kind: "terminal" }));
const own = { kind: "chat" as const, chatId: c.id };
const item = (id: string, key: string) => ({ kind: "item" as const, id, owner: "chat", itemKind: "chat.subagent", key, title: key, icon: "bot", chatId: c.id });
const scout = item("i1", "s"), shell = item("i2", "sh");
const layout = { id: "t", layout: { root: { kind: "pane" as const, id: "p", tabs: [own], active: own }, focused: "p" }, createdAt: "", updatedAt: "" };
noteTask(h.controller.state.layouts, layout);
h.controller.state.layouts.side = {
layout: { root: { kind: "pane", id: "sp", tabs: [scout, shell], active: scout }, focused: "sp" },
remembered: [],
open: true,
width: 520,
};
const tabMark = (id: string) => nodes(renderTaskTitle(h.v, layout, null, c.id, false)).find((node) => node.id === `tab-item-${id}`)!.children[0]!.children[0]!;
assert.equal(nodes(tabMark("i1")).some((node) => node.type === "spinner"), true, "a running subagent's tab spins as a running chat's does");
applyEvent(t, taskEvent({ id: "s", title: "Scout", status: "waiting" }));
assert.equal(nodes(tabMark("i1")).some((node) => node.background === "warning"), true, "one that needs you has the warning dot");
applyEvent(t, taskEvent({ id: "s", title: "Scout", status: "completed" }));
assert.deepEqual([tabMark("i1").type, tabMark("i1").svg], ["icon", "<svg/>"], "a settled one shows the icon of the agent running it");
assert.equal(tabMark("i2").name, "square-terminal", "a background command shows the terminal's mark");
await h.close();
});
test("a running subagent's tab ends with how long it has been working, as a running chat does", async () => {
const { harness, chat, taskEvent, nodes } = await import("./ui-for-tests.test.ts");
const { applyEvent } = await import("./transcript.ts");
const { renderSubagentPane } = await import("./views/tasks.tsx");
const h = harness();
const c = chat();
h.controller.state.chats[c.id] = c;
const t = h.controller.transcript(c.id);
t.snapshot = { kind: "ready" };
const startedAt = new Date(Date.now() - 5000).toISOString();
applyEvent(t, taskEvent({ id: "s", title: "Scout", status: "running", startedAt }));
const texts = () => nodes(renderSubagentPane(h.v, c.id, "s")).flatMap((node) => (node.type === "text" ? [String(node.text ?? node.children?.[0] ?? "")] : []));
const pane = () => nodes(renderSubagentPane(h.v, c.id, "s"));
assert.ok(texts().some((text) => /^Working for \d/.test(text)), "the working row ends the tab");
assert.ok(pane().some((node) => node.type === "spinner" && node.activity), "with the activity spinner");
assert.ok(!texts().includes("Waiting for subagent output…"), "the working row says it, so no second spinner waits for output");
applyEvent(t, taskEvent({ id: "s", title: "Scout", status: "waiting", startedAt }));
assert.ok(!texts().some((text) => text.startsWith("Working")), "one that needs you is not working");
applyEvent(t, taskEvent({ id: "s", title: "Scout", status: "completed", startedAt, endedAt: new Date().toISOString() }));
assert.ok(!texts().some((text) => text.startsWith("Working")), "a settled one is not working");
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.