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
history.test.ts5.8 KB
// Prompt history: Up in an empty prompt box brings back the chat's earlier
// prompts, the newest first, and Down goes forward again to the empty box.
import assert from "node:assert/strict";
import test from "node:test";
import * as Effect from "effect/Effect";
import type { TranscriptItem } from "divergence";
import type { ChatView } from "./controller.ts";
import { onChange } from "./composer.ts";
import { historyKeys, nextShown, promptHistory, recallPrompt } from "./history.ts";
import { InputLedger, withController } from "./testing.ts";
import { renderPane } from "./views/panes.tsx";
import { nodes } from "./ui-for-tests.test.ts";
const user = (id: string, text: string, from?: string): TranscriptItem => ({
id,
role: "user",
blocks: [{ type: "text", text }],
...(from ? { from } : {}),
});
const ITEMS: TranscriptItem[] = [
user("u1", "Fix the parser"),
{ id: "a1", role: "assistant", text: "Done." },
user("u2", "Review this", "chat-other"),
user("u3", " "),
user("u4", "Run the tests"),
user("u5", "Run the tests\n"),
];
test("the history is the user's own prompts, oldest first, a repeat counting once", async () => {
await withController(new InputLedger(), (c) =>
Effect.sync(() => {
c.transcript("c1").items = ITEMS;
assert.deepEqual(promptHistory(c, "c1"), [
{ id: "u1", text: "Fix the parser" },
{ id: "u5", text: "Run the tests" },
]);
assert.deepEqual(promptHistory(c, "c2"), [], "a chat with no transcript has none");
}),
);
});
test("Up goes to older prompts and stays on the oldest; Down goes past the newest to the empty box", () => {
assert.equal(nextShown(3, -1, "up"), 2);
assert.equal(nextShown(3, 2, "up"), 1);
assert.equal(nextShown(3, 0, "up"), 0);
assert.equal(nextShown(3, 0, "down"), 1);
assert.equal(nextShown(3, 2, "down"), -1);
assert.equal(nextShown(3, -1, "down"), -1);
assert.equal(nextShown(0, -1, "up"), -1);
});
test("the arrows go through the prompts while the box shows one, and typing hands them back to the field", async () => {
await withController(new InputLedger(), (c) =>
Effect.gen(function* () {
const composer = c.composer("c1");
assert.deepEqual(historyKeys(c, "c1"), [], "a chat with no prompts keeps its arrows");
c.transcript("c1").items = ITEMS;
assert.deepEqual(historyKeys(c, "c1"), ["up"], "an empty box hands over Up only");
yield* recallPrompt(c, "c1", "down");
assert.equal(composer.text, "", "Down in the empty box is the field's");
yield* recallPrompt(c, "c1", "up");
assert.equal(composer.text, "Run the tests");
assert.deepEqual(composer.place, { text: "Run the tests", at: 13 }, "the caret goes to the end");
assert.deepEqual(historyKeys(c, "c1"), ["up", "down"]);
yield* recallPrompt(c, "c1", "up");
assert.equal(composer.text, "Fix the parser");
yield* recallPrompt(c, "c1", "up");
assert.equal(composer.text, "Fix the parser", "Up stays on the oldest");
yield* recallPrompt(c, "c1", "down");
assert.equal(composer.text, "Run the tests");
yield* recallPrompt(c, "c1", "down");
assert.equal(composer.text, "", "past the newest the box is empty again");
assert.deepEqual(historyKeys(c, "c1"), ["up"]);
yield* recallPrompt(c, "c1", "up");
yield* onChange(c, "c1", "Run the tests again", { caret: 19 });
assert.deepEqual(historyKeys(c, "c1"), [], "an edited prompt is the user's own text");
yield* recallPrompt(c, "c1", "up");
assert.equal(composer.text, "Run the tests again", "a key handed over before the edit does nothing");
yield* onChange(c, "c1", "", { caret: 0 });
composer.attachments = [{ id: "i1", name: "Image", mimeType: "image/png", bytes: 1, width: null, height: null }];
assert.deepEqual(historyKeys(c, "c1"), [], "an image in the box counts as something typed");
}),
);
});
test("the prompt hands Up to history only from its edges and draws again when an edit ends the recall", async () => {
await withController(new InputLedger(), (c) =>
Effect.gen(function* () {
c.transcript("c1").items = ITEMS;
const runs: Promise<unknown>[] = [];
const view: ChatView = {
controller: c,
ctx: {
state: {},
set: () => {},
app: { route: "chat", chatId: "c1" },
plugin: "chat",
update() {},
run: (effect) => {
runs.push(Effect.runPromise(effect as Effect.Effect<unknown>));
},
},
};
const prompt = () => nodes(renderPane(view, "c1")).find((node) => node.id === "prompt-c1");
assert.deepEqual(prompt()?.keys, ["up"]);
assert.equal(prompt()?.arrowsAtEdges, true, "the field keeps the arrows that move its caret");
(prompt()?.onKey as (event: unknown) => void)({ key: "up", code: "ArrowUp", char: null, modifiers: {}, repeat: false });
yield* Effect.promise(() => Promise.all(runs));
assert.equal(prompt()?.value, "Run the tests");
assert.equal(prompt()?.caret, 13);
assert.deepEqual(prompt()?.keys, ["up", "down"]);
assert.equal(prompt()?.arrowsAtEdges, true, "a recalled prompt of several lines keeps its caret moves");
c.composer("c1").picker = { kind: "files", query: "", start: 0, end: 0 };
c.composer("c1").filesFor = "";
assert.equal(prompt()?.arrowsAtEdges, false, "an open picker takes the arrows on every line");
c.composer("c1").picker = null;
let drawn = 0;
c.state.panes.c1 = {
chatId: "c1",
view: { id: 1, update() {}, remove() {} },
composer: { id: 2, update: () => drawn++, remove() {} },
};
yield* onChange(c, "c1", "Run the tests!", { caret: 14 });
assert.ok(drawn > 0, "the composer draws again, so the field gets its arrows back");
delete c.state.panes.c1;
assert.deepEqual(prompt()?.keys, []);
}),
);
});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.