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
find.test.ts6.1 KB
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import test from "node:test";
import type { ContentBlock, TranscriptItem } from "divergence";
import type { Controller } from "./controller.ts";
import { closeFind, countIn, drawnText, hitsIn, lowercase, markings, positionOf, search, step, stepped, type Hit } from "./find.ts";
import { initialTranscript } from "./state.ts";
import { changed } from "./transcript.ts";
// The kernel's tests check the same cases (`crates/kernel/src/markdown/find.rs`), so the matches the plugin numbers
// are the ones the kernel marks.
const cases: { markdown: string; query: string; count: number }[] = JSON.parse(
readFileSync(new URL("../../crates/kernel/src/markdown/find_cases.json", import.meta.url), "utf8"),
);
test("a message's matches are counted as the kernel counts them in what it draws", () => {
for (const { markdown, query, count } of cases)
assert.equal(countIn(lowercase(drawnText(markdown, "soft")), lowercase(query)), count, `${query} in ${JSON.stringify(markdown)}`);
});
test("a typed message keeps its lines, and a reply joins the lines of a paragraph", () => {
assert.equal(drawnText("first line\nsecond line", "hard"), "first line\nsecond line");
assert.equal(drawnText("first line\nsecond line", "soft"), "first line second line");
assert.equal(drawnText("text\n- item\n- next", "soft"), "text\nitem\nnext", "a list item starts a block of its own");
});
test("a sent message's pills are found by their names, not their addresses", () => {
const sent = 'read [`AGENTS.md`](<docs/AGENTS.md> "divergence:pill:file") with [`review`](<> "divergence:pill:sparkles")';
assert.equal(drawnText(sent, "hard"), "read AGENTS.md with review");
});
const text = (id: string, role: "user" | "assistant", words: string): TranscriptItem =>
(role === "user" ? { id, role, blocks: [{ type: "text", text: words }] } : { id, role, text: words }) as TranscriptItem;
const plain = { plainText: (blocks: readonly ContentBlock[]) => blocks.map((block) => (block.type === "text" ? block.text : "")).join("") };
test("the chat's messages are searched in reading order, and nothing else is", () => {
const items = [
text("u1", "user", "Fix the Parser"),
{ id: "r1", role: "reasoning", text: "the parser is slow" } as TranscriptItem,
text("a1", "assistant", "The parser now **parses**; see [parser docs](https://parser.example)."),
text("u2", "user", "thanks"),
];
assert.deepEqual(hitsIn(plain, items, "PARSER"), [
{ id: "u1", index: 0 },
{ id: "a1", index: 0 },
{ id: "a1", index: 1 },
]);
assert.deepEqual(hitsIn(plain, items, ""), [], "an empty query finds nothing");
});
test("a reply that streams in is searched again", () => {
const reply = text("a1", "assistant", "first") as Extract<TranscriptItem, { role: "assistant" }>;
assert.equal(hitsIn(plain, [reply], "second").length, 0);
reply.text += " and second";
changed(reply);
assert.equal(hitsIn(plain, [reply], "second").length, 1);
});
test("stepping goes round at both ends, and on from where a match that went was", () => {
const hits: Hit[] = [
{ id: "a", index: 0 },
{ id: "a", index: 1 },
{ id: "c", index: 0 },
];
const order = (id: string) => ["a", "b", "c"].indexOf(id);
assert.deepEqual(stepped(hits, hits[2]!, 1, order), hits[0]);
assert.deepEqual(stepped(hits, hits[0]!, -1, order), hits[2]);
assert.deepEqual(stepped(hits, hits[0]!, 1, order), hits[1]);
// A match in message b went: the next one after it is in c, the one before it the last in a.
assert.deepEqual(stepped(hits, { id: "b", index: 0 }, 1, order), hits[2]);
assert.deepEqual(stepped(hits, { id: "b", index: 0 }, -1, order), hits[1]);
assert.equal(stepped([], hits[0]!, 1, order), null);
});
// What the bar's actions read of the controller.
function chatWith(items: TranscriptItem[]) {
const t = initialTranscript();
t.items = items;
let refreshed = 0;
const c = {
...plain,
transcript: () => t,
refresh: () => refreshed++,
api: { settings: { get: () => true } },
} as unknown as Controller;
return { c, t, refreshes: () => refreshed };
}
test("typing goes to the newest match, Enter to older ones and Shift+Enter back", () => {
const { c, t } = chatWith([text("u1", "user", "a cat"), text("a1", "assistant", "cat and cat"), text("u2", "user", "dog")]);
t.find = { query: "", current: null, moves: 0 };
search(c, "c1", "cat");
assert.deepEqual(t.find.current, { id: "a1", index: 1 });
step(c, "c1", -1);
assert.deepEqual(t.find.current, { id: "a1", index: 0 });
step(c, "c1", -1);
step(c, "c1", -1);
assert.deepEqual(t.find.current, { id: "a1", index: 1 }, "past the oldest it goes round to the newest");
step(c, "c1", 1);
assert.deepEqual(t.find.current, { id: "u1", index: 0 }, "past the newest it goes round to the oldest");
assert.equal(t.find.moves, 5, "each move brings its match into view");
search(c, "c1", "bird");
assert.equal(t.find.current, null);
});
test("each message with a match marks the query, and the reader's message its match", () => {
const { c, t } = chatWith([text("u1", "user", "a cat"), text("a1", "assistant", "cat and cat"), text("u2", "user", "dog")]);
t.find = { query: "", current: null, moves: 0 };
search(c, "c1", "Cat");
step(c, "c1", -1);
assert.deepEqual(Object.fromEntries(markings(c, t)), {
u1: { query: "Cat" },
a1: { query: "Cat", current: 0, reveal: 2 },
});
assert.equal(positionOf(hitsIn(c, t.items, "cat"), t.find.current), 1);
});
test("a match in a prompt cut to its first lines opens the prompt", () => {
const { c, t } = chatWith([text("u1", "user", "line\nline\nline\nline\nline\nline needle")]);
t.clamped.add("u1");
t.find = { query: "", current: null, moves: 0 };
search(c, "c1", "needle");
assert.ok(t.expanded.has("u1"));
});
test("closing the bar marks nothing", () => {
const { c, t, refreshes } = chatWith([text("a1", "assistant", "cat")]);
t.find = { query: "", current: null, moves: 0 };
search(c, "c1", "cat");
closeFind(c, "c1");
assert.equal(t.find, undefined);
assert.equal(markings(c, t).size, 0);
assert.equal(refreshes(), 2);
});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.