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

Permissions in 0.2.5

  • 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

panes.test.ts13.9 KB
// Chat panes: a hidden pane waits to render until it shows, transcripts
// outlive a reload of this plugin, and a chat on its way shows a skeleton.
import assert from "node:assert/strict";
import test from "node:test";
import * as Deferred from "effect/Deferred";
import * as Effect from "effect/Effect";
import type { HostEvents } from "divergence";
import { onAgent } from "./events.ts";
import { ensureChat, ensurePane, followApp, removePane } from "./panes.ts";
import { PAGE, WHOLE, loadOlder, loadTranscript } from "./data.ts";
import { HostCallFailed } from "divergence/effect";
import { initialTranscript } from "./state.ts";
import type { Transcript } from "./state.ts";
import { renderCenter, renderPane } from "./views/panes.ts";
import { chat, harness, item, nodes } from "./ui-for-tests.test.ts";

// What a composer reads as it is made: no options, commands or skills.
const composerReads = (method: string) =>
  method === "host/chats.options"
    ? Effect.succeed({ options: [] })
    : method === "host/chats.commands"
      ? Effect.succeed({ commands: [] })
      : method === "host/chats.skills"
        ? Effect.succeed({ skills: [] })
        : undefined;

const delta = (chatId: string): HostEvents["agent"] => ({
  event: "agent",
  chatId,
  kind: { event: "text_delta", itemId: `reply-${chatId}`, text: "more", mode: "append" },
});

test("a hidden pane renders once when it shows again, not on every event", async () => {
  const h = harness();
  const rendered: string[] = [];
  for (const id of ["a", "b"]) {
    h.controller.state.chats[id] = chat({ id, sessionId: `session-${id}` });
    h.controller.transcript(id);
    h.controller.state.panes[id] = { chatId: id, view: { id: 1, update: () => rendered.push(id), remove() {} } };
  }
  Effect.runSync(h.controller.app.update({ route: "chat", chatId: "a" }));
  for (let i = 0; i < 3; i++) {
    await Effect.runPromise(onAgent(h.controller, delta("b")));
    await Effect.runPromise(onAgent(h.controller, delta("a")));
  }
  assert.deepEqual(rendered, ["a", "a", "a"], "only the pane on screen renders");
  assert.equal(h.controller.state.panes.b?.stale, true);
  Effect.runSync(h.controller.app.update({ chatId: "b" }));
  await Effect.runPromise(ensurePane(h.controller, "b"));
  assert.deepEqual(rendered, ["a", "a", "a", "b"], "it renders once as it shows");
  assert.equal(h.controller.state.panes.b?.stale, false);
  await h.close();
});

test("moving the main prompt box to another chat renders the two composers, not the panes", async () => {
  const h = harness();
  const rendered: string[] = [];
  const handle = (name: string) => ({ id: 1, update: () => rendered.push(name), remove() {} });
  for (const id of ["a", "b"]) {
    h.controller.state.chats[id] = chat({ id, sessionId: `session-${id}` });
    h.controller.transcript(id);
    h.controller.state.panes[id] = { chatId: id, view: handle(`pane ${id}`), composer: handle(`composer ${id}`) };
  }
  h.controller.state.mainPrompt = "a";
  renderCenter({ ...h.v, ctx: { ...h.v.ctx, app: { route: "chat", chatId: "b" } } });
  // A pane carries the whole transcript: rendering the one the user left
  // made the switch to a new chat wait for its tree to be applied.
  assert.deepEqual(rendered.sort(), ["composer a", "composer b"]);
  assert.equal(h.controller.state.mainPrompt, "b");
  await h.close();
});

test("transcripts kept across a reload show at once and are read again", async () => {
  const before = harness();
  const kept: Transcript = {
    ...initialTranscript(),
    items: [item({ id: "u1", role: "user", text: "hello" })],
    loaded: true,
    // A read of the code that unloaded: it never ends now.
    loading: Deferred.makeUnsafe<void>(),
  };
  kept.expanded.add("u1");
  before.controller.state.transcripts.a = kept;
  // The center view's `ctx.state`, which the reload keeps.
  const state: { transcripts?: Record<string, Transcript> } = {};
  before.controller.keepTranscripts(state);
  await before.close();

  const asked: string[] = [];
  const after = harness((method) => {
    asked.push(method);
    if (method === "host/chats.transcript")
      return Effect.succeed({
        items: [item({ id: "u1", role: "user", text: "hello" }), item({ id: "a1", role: "assistant", text: "hi" })],
        pendingApprovals: [],
        pendingQuestions: [],
        plan: null,
        usage: {},
        running: false,
      });
    if (method === "host/security.pending") return Effect.succeed({ requests: [] });
    if (method === "host/chats.checkpoints") return Effect.succeed({ checkpoints: [] });
    return composerReads(method);
  });
  after.controller.state.chats.a = chat({ id: "a", sessionId: "session-a" });
  after.controller.keepTranscripts(state);
  const carried = after.controller.state.transcripts.a;
  assert.ok(carried);
  assert.deepEqual(
    carried.items.map((row) => row.id),
    ["u1"],
    "the rows show before any read",
  );
  assert.ok(carried.expanded.has("u1"), "what the user opened stays open");
  assert.equal(carried.loading, undefined, "a read of the old code is not waited for");
  assert.equal(carried.loaded, false);
  assert.ok(nodes(renderPane(after.v, "a")).every((node) => node.type !== "empty"));
  await Effect.runPromise(ensureChat(after.controller, "a"));
  await after.settle();
  assert.ok(asked.includes("host/security.pending"), "its security requests are read again");
  assert.ok(asked.includes("host/chats.transcript"), "its transcript is read again");
  assert.deepEqual(
    after.controller.state.transcripts.a?.items.map((row) => row.id),
    ["u1", "a1"],
  );
  assert.equal(after.controller.state.transcripts.a?.carried, false);
  await after.close();
});

test("a chat whose history is on its way shows a skeleton and its composer", async () => {
  // The transcript's read does not come back while the pane shows.
  const h = harness((method) => (method === "host/chats.transcript" ? Effect.never : composerReads(method)));
  h.controller.state.chats.a = chat({ id: "a", sessionId: "session-a" });
  const shown = nodes(renderPane(h.v, "a"));
  assert.ok(!shown.some((node) => node.type === "empty"), "no line of loading text");
  assert.ok(shown.some((node) => node.background === "muted" && node.borderRadius === "xl"), "the skeleton's message");
  assert.ok(shown.some((node) => node.id === "prompt-a"), "the composer takes typing at once");
  await h.close();
});

test("the host prepares a chat once each time it shows, and a failure is a notice", async () => {
  let fail = false;
  const prepared: unknown[] = [];
  const h = harness((method, params) => {
    if (method !== "host/chats.prepare") return composerReads(method);
    prepared.push(params);
    return fail ? Effect.fail(new HostCallFailed({ method, code: -32000, message: "no session" })) : Effect.succeed({});
  });
  for (const id of ["a", "b"]) {
    h.controller.state.chats[id] = chat({ id, sessionId: `session-${id}` });
    h.controller.transcript(id);
  }
  const prepares = () => prepared;
  Effect.runSync(h.controller.app.update({ route: "chat", chatId: "a" }));
  for (let i = 0; i < 3; i++) await Effect.runPromise(followApp(h.controller));
  await h.settle();
  assert.deepEqual(prepares(), [{ chatId: "a" }], "renders of the same chat prepare once");
  Effect.runSync(h.controller.app.update({ chatId: "b" }));
  fail = true;
  await Effect.runPromise(followApp(h.controller));
  await h.settle();
  assert.deepEqual(prepares(), [{ chatId: "a" }, { chatId: "b" }]);
  assert.ok(h.notices.some((notice) => notice.includes("no session")));
  await h.close();
});

// A host holding `all` that answers transcript reads by `limit` and `before`.
function pagedHost(all: ReturnType<typeof item>[], asked: { method: string; params: unknown }[]) {
  return harness((method, params) => {
    asked.push({ method, params });
    if (method === "host/chats.transcript") {
      const { limit, before } = params as { limit?: number; before?: number };
      const end = before ?? all.length;
      const start = limit === undefined ? 0 : Math.max(0, end - limit);
      return Effect.succeed({
        items: all.slice(start, end),
        start,
        total: all.length,
        pendingApprovals: [],
        pendingQuestions: [],
        plan: null,
        usage: {},
        running: false,
      });
    }
    if (method === "host/chats.close") return Effect.succeed({});
    if (method === "host/chats.checkpoints") return Effect.succeed({ checkpoints: [] });
    return composerReads(method);
  });
}

test("a transcript opens on its newest page, reads the rest right after, and is dropped when its pane goes", async () => {
  const all = Array.from({ length: 120 }, (_, n) => item({ id: `a${n}`, role: "assistant", text: `reply ${n}` }));
  const asked: { method: string; params: unknown }[] = [];
  const h = pagedHost(all, asked);
  h.controller.state.chats.a = chat({ id: "a", sessionId: "session-a" });
  await Effect.runPromise(loadTranscript(h.controller, "a"));
  await h.settle();
  const ids = () => h.controller.state.transcripts.a?.items.map((row) => row.id) ?? [];
  const reads = asked.filter((call) => call.method === "host/chats.transcript").map((call) => call.params);
  assert.deepEqual(
    reads,
    [
      { chatId: "a", limit: PAGE },
      { chatId: "a", limit: WHOLE - PAGE, before: 70 },
    ],
    "the newest page, then everything before it",
  );
  assert.deepEqual([ids().length, ids()[0], ids().at(-1)], [120, "a0", "a119"]);
  assert.equal(nodes(renderPane(h.v, "a")).find((node) => node.type === "scroller")?.onReachStart, undefined);

  // Another chat on screen, the pane goes: its transcript goes with it.
  Effect.runSync(h.controller.app.update({ route: "chat", chatId: "b" }));
  removePane(h.controller, "a");
  assert.equal(h.controller.state.transcripts.a, undefined);
  await new Promise((resolve) => setTimeout(resolve, 0));
  assert.ok(asked.some((call) => call.method === "host/chats.close"), "the host is told it closed");
  await h.close();
});

test("a transcript longer than it holds whole reads the rows before those a page at a time near its top", async () => {
  const all = Array.from({ length: WHOLE + 120 }, (_, n) => item({ id: `a${n}`, role: "assistant", text: `reply ${n}` }));
  const asked: { method: string; params: unknown }[] = [];
  const h = pagedHost(all, asked);
  h.controller.state.chats.a = chat({ id: "a", sessionId: "session-a" });
  await Effect.runPromise(loadTranscript(h.controller, "a"));
  await h.settle();
  const transcript = () => h.controller.state.transcripts.a!;
  assert.deepEqual([transcript().items.length, transcript().start], [WHOLE, 120]);

  const scroller = nodes(renderPane(h.v, "a")).find((node) => node.type === "scroller");
  assert.equal(typeof scroller?.onReachStart, "function", "the list asks for older rows near its top");
  await Effect.runPromise(loadOlder(h.controller, "a"));
  assert.deepEqual([transcript().items[0]?.id, transcript().start], ["a70", 70], "the page before it goes first");
  await Effect.runPromise(loadOlder(h.controller, "a"));
  await Effect.runPromise(loadOlder(h.controller, "a"));
  assert.deepEqual([transcript().items.length, transcript().start], [WHOLE + 120, 0]);
  assert.equal(asked.filter((call) => call.method === "host/chats.transcript").length, 5, "nothing is read before the first row");
  assert.equal(nodes(renderPane(h.v, "a")).find((node) => node.type === "scroller")?.onReachStart, undefined);
  await h.close();
});

test("the new chat page leaves as its prompt goes: its background fades and the text rises into its message", async () => {
  const h = harness(composerReads);
  const updates: string[] = [];
  h.controller.state.chats.a = chat({ id: "a" });
  h.controller.state.panes.a = { chatId: "a", view: { id: 1, update: () => updates.push("a"), remove() {} } };
  h.controller.state.onScreen = "a";
  const page = nodes(renderPane(h.v, "a"));
  assert.ok(page.some((node) => node.id === "landing-stage" && node.ambient === "caustics" && !node.motion));
  for (const id of ["dock-a", "rising-a", "landing-headline-a", "landing-chip-a"])
    assert.equal(page.find((node) => node.id === id)?.travels, true, `${id} travels`);

  h.controller.composer("a").submitting = true;
  h.controller.state.transcripts.a = {
    ...initialTranscript(),
    loaded: true,
    items: [item({ id: "u1", role: "user", blocks: [{ type: "text", text: "Hello" }] })],
  };
  const leaving = nodes(renderPane(h.v, "a"));
  const stage = leaving.find((node) => node.id === "landing-stage");
  assert.equal((stage?.motion as { to?: unknown } | undefined)?.to && JSON.stringify((stage?.motion as { to: unknown }).to), '{"opacity":0}', "the background fades");
  assert.ok(leaving.find((node) => node.id === "landing-headline-a")?.motion, "the headline rides down as it fades");
  assert.equal(leaving.filter((node) => node.id === "rising-a").length, 1, "only the message carries the sent text's id");
  assert.equal(leaving.find((node) => node.id === "rising-a")?.background, "bubble");
  assert.equal(leaving.find((node) => node.id === "dock-a")?.travels, true);

  (stage?.motion as { onDone: () => void }).onDone();
  assert.deepEqual(updates, ["a"]);
  const settled = nodes(renderPane(h.v, "a"));
  assert.ok(!settled.some((node) => node.id === "landing-stage" || node.id === "landing-headline-a"), "the departure is over");
  assert.ok(settled.some((node) => node.id === "rising-a"), "the message keeps its id");
  await h.close();
});

test("a reply arriving on the new chat page without a send just shows the transcript", async () => {
  const h = harness(composerReads);
  h.controller.state.chats.a = chat({ id: "a" });
  h.controller.state.panes.a = { chatId: "a", view: { id: 1, update() {}, remove() {} } };
  h.controller.state.onScreen = "a";
  renderPane(h.v, "a");
  h.controller.state.transcripts.a = {
    ...initialTranscript(),
    loaded: true,
    running: true,
    items: [item({ id: "r1", role: "assistant", text: "Hi" })],
  };
  const shown = nodes(renderPane(h.v, "a"));
  assert.ok(!shown.some((node) => node.id === "landing-stage"), "no departure");
  assert.ok(shown.some((node) => node.text === "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.