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.6
Permissions in 0.2.6
Files
paging.test.ts9.6 KB
import assert from "node:assert/strict";
import test from "node:test";
import * as Deferred from "effect/Deferred";
import * as Effect from "effect/Effect";
import { HostCallFailed } from "divergence/effect";
import { loadOlder, loadRequests, loadTranscript, PAGE } from "./data.ts";
import { renderTranscript } from "./views/rows.tsx";
import { chat, harness, item, nodes, security } from "./ui-for-tests.test.ts";
const messages = (prefix: string, count = 120) => Array.from({ length: count }, (_, n) => item({ id: `${prefix}${n}`, role: "assistant", text: `Reply ${n}` }));
const snapshot = (items: ReturnType<typeof item>[], start?: number) => ({ items, start, pendingApprovals: [], pendingQuestions: [], plan: null, usage: {}, running: false });
const tick = () => new Promise<void>((resolve) => setImmediate(resolve));
const scroller = (h: ReturnType<typeof harness>) => nodes(renderTranscript(h.v, h.controller.state.chats.a!)).find((node) => node.type === "scroller")!;
function paged(all: ReturnType<typeof item>[]) {
const reads: { limit: number; before?: number }[] = [];
const h = harness((method, params) => {
if (method === "host/chats.transcript") {
const { limit, before } = params as { limit: number; before?: number };
reads.push({ limit, before });
const end = before ?? all.length;
const start = Math.max(0, end - limit);
return Effect.succeed(snapshot(all.slice(start, end), start));
}
if (method === "host/chats.checkpoints") return Effect.succeed({ checkpoints: [] });
if (method === "host/security.pending")
return Effect.succeed({ requests: [security({ id: "request", afterItemId: all[0]!.id })] });
return undefined;
});
h.controller.state.chats.a = chat({ id: "a" });
return { ...h, reads };
}
test("range activation reads no history, while reach-start prepends one page with stable row identities", async () => {
const all = messages("a");
const h = paged(all);
try {
await Effect.runPromise(loadTranscript(h.controller, "a"));
await Effect.runPromise(loadRequests(h.controller, "a"));
await h.settle();
const t = h.controller.state.transcripts.a!;
assert.equal(t.items.length, PAGE);
assert.deepEqual(h.reads, [{ limit: PAGE, before: undefined }]);
assert.ok(nodes(scroller(h)).some((node) => node.type === "security_card" && node.id === "request"), "a pending request whose row is not loaded is still available");
const beforeItems = [...t.items];
const beforeKeys = nodes(scroller(h)).filter((node) => String(node.id).startsWith("transcript-row-")).map((node) => node.id);
for (const first of [40, 35, 20, 5]) (scroller(h).onRange as (event: { first: number }) => void)({ first });
await h.settle();
assert.equal(h.reads.length, 1, "window support and range changes never fetch stored history");
(scroller(h).onReachStart as () => void)();
await h.settle();
assert.deepEqual(h.reads.at(-1), { limit: PAGE, before: 70 });
assert.deepEqual(t.items.slice(-PAGE), beforeItems, "loaded row objects survive prepending");
const afterKeys = nodes(scroller(h)).filter((node) => String(node.id).startsWith("transcript-row-")).map((node) => node.id);
assert.deepEqual(afterKeys.slice(-PAGE), beforeKeys, "the native scroller receives the same keyed anchor rows");
assert.equal(t.start, 20);
(scroller(h).onReachStart as () => void)();
await h.settle();
assert.deepEqual(t.items.map((row) => row.id), all.map((row) => row.id));
assert.equal(scroller(h).onReachStart, undefined);
assert.equal(h.reads.length, 3);
} finally { await h.close(); }
});
test("duplicate viewport demands wait for the newest snapshot and install one older page", async () => {
const all = messages("a");
const gate = Deferred.makeUnsafe<void>();
const reads: (number | undefined)[] = [];
const h = harness((method, params) => {
if (method === "host/chats.checkpoints") return Effect.succeed({ checkpoints: [] });
if (method !== "host/chats.transcript") return undefined;
const before = (params as { before?: number }).before;
reads.push(before);
return before === undefined
? Deferred.await(gate).pipe(Effect.as(snapshot(all.slice(70), 70)))
: Effect.succeed(snapshot(all.slice(20, 70), 20));
});
h.controller.state.chats.a = chat({ id: "a" });
try {
const opening = Effect.runPromise(loadTranscript(h.controller, "a"));
await tick();
const older = Effect.runPromise(loadOlder(h.controller, "a"));
await Effect.runPromise(loadOlder(h.controller, "a"));
assert.deepEqual(reads, [undefined], "paging waits rather than racing the newest snapshot");
Effect.runSync(Deferred.succeed(gate, undefined));
await Promise.all([opening, older]);
assert.deepEqual(reads, [undefined, 70]);
assert.equal(h.controller.state.transcripts.a!.items.length, 100);
assert.equal(h.controller.state.transcripts.a!.older, false);
} finally { await h.close(); }
});
test("a same-offset reset rejects the stale older page and serves only the outstanding demand", async () => {
let all = messages("old");
const gate = Deferred.makeUnsafe<void>();
let olderReads = 0;
const h = harness((method, params) => {
if (method === "host/chats.checkpoints") return Effect.succeed({ checkpoints: [] });
if (method !== "host/chats.transcript") return undefined;
const before = (params as { before?: number }).before;
if (before === undefined) return Effect.succeed(snapshot(all.slice(70), 70));
const result = snapshot(all.slice(20, 70), 20);
return ++olderReads === 1 ? Deferred.await(gate).pipe(Effect.as(result)) : Effect.succeed(result);
});
h.controller.state.chats.a = chat({ id: "a" });
try {
await Effect.runPromise(loadTranscript(h.controller, "a"));
const older = Effect.runPromise(loadOlder(h.controller, "a"));
await tick();
all = messages("new");
const t = h.controller.state.transcripts.a!;
t.version++;
await Effect.runPromise(loadTranscript(h.controller, "a"));
assert.equal(t.start, 70, "the replacement has the same numeric cursor");
Effect.runSync(Deferred.succeed(gate, undefined));
await older;
assert.equal(olderReads, 2, "one obsolete response is retried, without draining the remaining history");
assert.deepEqual(t.items.map((row) => row.id), all.slice(20).map((row) => row.id));
assert.equal(t.start, 20);
} finally { await h.close(); }
});
test("an evicted transcript cannot prepend its delayed page into a new transcript with the same chat id", async () => {
const all = messages("old");
const gate = Deferred.makeUnsafe<void>();
const h = harness((method) => method === "host/chats.transcript" ? Deferred.await(gate).pipe(Effect.as(snapshot(all.slice(20, 70), 20))) : undefined);
h.controller.state.chats.a = chat({ id: "a" });
const old = h.controller.transcript("a");
Object.assign(old, { items: all.slice(70), snapshot: { kind: "ready" }, start: 70 });
try {
const read = Effect.runPromise(loadOlder(h.controller, "a"));
await tick();
delete h.controller.state.transcripts.a;
const replacement = h.controller.transcript("a");
replacement.items = messages("new", 1);
Effect.runSync(Deferred.succeed(gate, undefined));
await read;
assert.deepEqual(replacement.items.map((row) => row.id), ["new0"]);
assert.equal(old.older, false);
} finally { await h.close(); }
});
test("historical pages preserve current requests and surface read failures without discarding loaded rows", async () => {
const all = messages("a");
let fail = true;
const h = harness((method, params) => {
if (method === "host/chats.checkpoints") return Effect.succeed({ checkpoints: [] });
if (method !== "host/chats.transcript") return undefined;
if ((params as { before?: number }).before === undefined)
return Effect.succeed({ ...snapshot(all.slice(70), 70), pendingApprovals: [{ id: "current", title: "Current approval" }] });
return fail
? Effect.fail(new HostCallFailed({ method, code: -32000, message: "read failed" }))
: Effect.succeed({ ...snapshot(all.slice(20, 70), 20), pendingApprovals: [{ id: "stale", title: "Stale approval" }] });
});
h.controller.state.chats.a = chat({ id: "a" });
try {
await Effect.runPromise(loadTranscript(h.controller, "a"));
const t = h.controller.state.transcripts.a!;
const before = t.items;
await Effect.runPromise(loadOlder(h.controller, "a"));
assert.equal(t.items, before);
assert.equal(t.older, false);
assert.deepEqual(h.notices, ["Older messages unavailable: read failed"]);
fail = false;
await Effect.runPromise(loadOlder(h.controller, "a"));
assert.deepEqual(t.approvals.map((approval) => approval.id), ["current"]);
assert.equal(t.start, 20);
} finally { await h.close(); }
});
test("a legacy unpaged response stays complete and never advertises another history read", async () => {
const all = messages("legacy");
let reads = 0;
const h = harness((method) => {
if (method === "host/chats.checkpoints") return Effect.succeed({ checkpoints: [] });
if (method === "host/chats.transcript") { reads++; return Effect.succeed(snapshot(all)); }
return undefined;
});
h.controller.state.chats.a = chat({ id: "a" });
try {
await Effect.runPromise(loadTranscript(h.controller, "a"));
assert.equal(h.controller.state.transcripts.a!.start, 0);
assert.deepEqual(h.controller.state.transcripts.a!.items, all);
assert.equal(scroller(h).onReachStart, undefined);
(scroller(h).onRange as (event: { first: number }) => void)({ first: 0 });
await h.settle();
await Effect.runPromise(loadOlder(h.controller, "a"));
assert.equal(reads, 1);
} finally { 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.