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.7

Permissions in 0.2.7

  • Control chats chats.controlHighCreates chats, sends prompts and cancels runs.Send prompts, answer agent questions, and create, change, fork, revert, stop and group chats
  • Run other plugins' commands commands.runHighRuns commands of other plugins.Run the sidebar's New chat command from the title bar
  • Read chats chats.readMediumReads your transcripts and chat lists.Show workspaces, tasks, chats and transcripts, and follow them as agents work
  • Read files fs.readMediumReads files in the listed places.Suggest workspace files for @ mentionsPlaces: the open workspace
  • Show panels ui.slotsAlways grantedShows views in the listed parts of the window.Draw the chat grid, the title bar, and the Session panel with its rail buttonSlots: centertitlerailright

Files

subagents.test.ts13.4 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.equal(resultOf(item, [spawn, item]), "Found 3 files.");
  item.task.summary = "The summary";
  assert.equal(resultOf(item, [spawn, item]), "The summary");
  item.items?.push(fixtureItem({ id: "m", role: "assistant", text: "The summary" }));
  assert.equal(resultOf(item, [spawn, item]), null, "the last message already says it");
  item.task.status = "running";
  assert.equal(resultOf({ ...item, items: [] }, [spawn, item]), null, "nothing while it runs");
});

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()?.minWidth, 0, "the bubble 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

VersionPublishedPlugin APISizePermissionsStatus
0.2.9latestNov 21, 2026>=5 <6349 KB5 permissionsListed
0.2.8Nov 16, 2026>=5 <6348.6 KB5 permissionsListed
0.2.7Nov 11, 2026>=5 <6314.3 KB5 permissionsListed
0.2.6Nov 9, 2026>=5 <6306.2 KB5 permissionsListed
0.2.5Oct 27, 2026>=2 <4178.6 KB5 permissionsListed

Reviews and comments

0 threads · 0 reviews

No comments yet.