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

chat-queue.test.ts6.8 KB
// A queued draft stays a draft, its prompt in the composer, until no chat
// runs; then the queue sends it and it becomes a running chat, one at a time.
import assert from "node:assert/strict";
import test from "node:test";
import * as Effect from "effect/Effect";
import * as Fiber from "effect/Fiber";
import { DraftLedger, InputLedger, withController } from "./testing.ts";
import { onSubmit, queueChat } from "./composer.ts";
import { onChatChanged } from "./events.ts";
import { chat } from "./ui-for-tests.test.ts";
import type { Controller } from "./controller.ts";
import type { Chat } from "divergence";

const settle = Effect.promise(() => new Promise((resolve) => setTimeout(resolve, 20)));
const change = (c: Controller, id: string, overrides: Partial<Chat>) =>
  onChatChanged(c, { event: "chat_changed", chat: { ...c.state.chats[id]!, ...overrides, updatedAt: new Date().toISOString() } });
const queued = (c: Controller) => c.state.chatQueue.map((entry) => entry.chatId);

for (const fail of [false, true]) {
  test(`draft queue hydration owns one release and retains failed reads (fail=${fail})`, async () => {
    const ledger = new DraftLedger();
    delete ledger.snapshots.c1.sessionId;
    ledger.draft = { chatId: "c1", revision: 1, blocks: [{ type: "text", text: "Read README.md" }] };
    const entered = Promise.withResolvers<void>(), gate = Promise.withResolvers<void>();
    const call = ledger.call.bind(ledger);
    let reads = 0;
    ledger.call = async (method, params) => {
      if (method === "host/drafts.get") {
        reads++;
        entered.resolve();
        await gate.promise;
        if (fail && reads === 1) throw new Error("draft read failed");
      }
      return call(method, params);
    };
    await withController(ledger, (c) => Effect.gen(function* () {
      delete c.state.composers.c1;
      c.state.chatQueue = [{ chatId: "c1" }];
      const first = yield* Effect.forkChild(c.pumpChatQueue());
      yield* Effect.promise(() => entered.promise);
      assert.equal(c.state.releasing, "c1");
      yield* c.pumpChatQueue();
      assert.equal(reads, 1, "another pump cannot acquire the same queued draft");
      gate.resolve();
      yield* Fiber.join(first);
      if (fail) {
        assert.equal(c.state.releasing, null);
        assert.deepEqual(queued(c), ["c1"]);
        assert.deepEqual(ledger.deliveries, []);
        assert.ok(ledger.notices.some((notice) => notice.includes("draft read failed")));
        yield* c.pumpChatQueue();
      }
      assert.equal(ledger.deliveries.length, 1);
      assert.deepEqual(ledger.deliveries[0].blocks, [{ type: "text", text: "Read README.md" }]);
      assert.deepEqual(queued(c), []);
    }));
  });
}

test("a restored draft queue loads its durable image-only prompt before release", async () => {
  const ledger = new DraftLedger();
  delete ledger.snapshots.c1.sessionId;
  const blocks = [{ type: "image" as const, data: "saved-image-bytes", mimeType: "image/png" }];
  ledger.draft = { chatId: "c1", revision: 1, blocks };
  ledger.storage.queues = { chats: [{ chatId: "c1" }] };
  await withController(ledger, (c) => Effect.gen(function* () {
    delete c.state.composers.c1;
    c.state.chats.busy = chat({ id: "busy", status: "running", sessionId: "busy-session" });
    yield* c.restoreQueues();
    yield* settle;
    assert.deepEqual(queued(c), ["c1"]);
    assert.equal(ledger.deliveries.length, 0);
    c.state.chats.busy = { ...c.state.chats.busy, status: "idle" };
    yield* c.pumpChatQueue();
    assert.deepEqual(ledger.deliveries.map((delivery) => delivery.blocks), [blocks]);
    assert.deepEqual(queued(c), []);
    assert.deepEqual(ledger.draft.blocks, []);
    assert.deepEqual(ledger.notices, []);
  }));
});

test("a queued draft keeps its prompt and starts only when no chat runs", async () => {
  const ledger = new InputLedger(["busy", "d1"]);
  await withController(ledger, (c) =>
    Effect.gen(function* () {
      c.state.chats.busy = chat({ id: "busy", sessionId: "s", status: "running" });
      c.state.chats.d1 = chat({ id: "d1" });
      c.composer("d1").loading = false;
      c.composer("d1").text = "Fix the tests";
      yield* queueChat(c, "d1");
      yield* settle;
      assert.deepEqual(queued(c), ["d1"]);
      assert.equal(c.composer("d1").text, "Fix the tests", "the prompt stays in the draft");
      assert.equal(ledger.deliveries.length, 0, "another chat runs");
      // Still editable while it waits: the edit is what is sent.
      c.composer("d1").text = "Fix the failing tests";
      yield* change(c, "busy", { status: "idle" });
      yield* settle;
      assert.deepEqual(queued(c), []);
      assert.deepEqual(ledger.deliveries.map((d) => [d.chatId, d.blocks]), [
        ["d1", [{ type: "text", text: "Fix the failing tests" }]],
      ]);
    }),
  );
});

test("queued drafts start one at a time, in order", async () => {
  const ledger = new InputLedger(["d1", "d2"]);
  await withController(ledger, (c) =>
    Effect.gen(function* () {
      for (const id of ["d1", "d2"]) {
        c.state.chats[id] = chat({ id });
        c.composer(id).loading = false;
        c.composer(id).text = `prompt ${id}`;
      }
      // Nothing runs: the first starts at once, the second waits for it.
      yield* queueChat(c, "d1");
      yield* queueChat(c, "d2");
      yield* settle;
      assert.deepEqual(ledger.deliveries.map((d) => d.chatId), ["d1"]);
      assert.deepEqual(queued(c), ["d2"]);
      yield* change(c, "d1", { status: "running" });
      yield* settle;
      assert.deepEqual(ledger.deliveries.map((d) => d.chatId), ["d1"]);
      yield* change(c, "d1", { status: "idle", sessionId: "s1" });
      yield* settle;
      assert.deepEqual(ledger.deliveries.map((d) => d.chatId), ["d1", "d2"]);
      assert.deepEqual(queued(c), []);
    }),
  );
});

test("sending a queued draft by hand takes it out of the queue", async () => {
  const ledger = new InputLedger(["busy", "d1"]);
  await withController(ledger, (c) =>
    Effect.gen(function* () {
      c.state.chats.busy = chat({ id: "busy", sessionId: "s", status: "running" });
      c.state.chats.d1 = chat({ id: "d1" });
      c.composer("d1").loading = false;
      c.composer("d1").text = "Now";
      yield* queueChat(c, "d1");
      yield* onSubmit(c, "d1", { value: "Now", secondary: false, shift: false });
      assert.deepEqual(queued(c), []);
      assert.deepEqual(ledger.deliveries.map((d) => d.chatId), ["d1"]);
    }),
  );
});

test("a queue saved with its prompt puts the prompt back in the draft", async () => {
  const ledger = new InputLedger(["d1"]);
  ledger.storage.queues = { chats: [{ chatId: "d1", text: "Old prompt", started: false }] };
  await withController(ledger, (c) =>
    Effect.gen(function* () {
      yield* c.restoreQueues();
      assert.deepEqual(queued(c), ["d1"]);
      assert.equal(c.composer("d1").text, "Old prompt");
      assert.deepEqual(ledger.storage.queues, { prompts: {}, chats: [{ chatId: "d1" }] });
    }),
  );
});

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.