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

  • 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

history.ts3.8 KB
// Prompt history: in an empty prompt box, Up brings back the prompts sent in
// this chat, the newest first, and Down goes forward again, past the newest
// to the empty box. The field does not tell this plugin where its caret is
// until its text changes, so the arrows keep going through the prompts for
// as long as the box still shows the one they brought back, wherever the
// caret is, and hand back to the field once the user types in it.
import { filePaths, withFiles } from "./segments.ts";
import * as Effect from "effect/Effect";
import type { Controller } from "./controller.ts";
import type { Composer } from "./state.ts";
import { textChanged } from "./data.ts";

export type Recalled = { id: string; text: string; files?: readonly string[] };
export type ArrowKey = "up" | "down";

/**
 * The prompts the user sent in this chat, oldest first, as they wrote them (the text the Edit
 * button starts from). A message another agent sent is not the user's, and a prompt sent twice in
 * a row counts once.
 */
export function promptHistory(c: Controller, chatId: string): Recalled[] {
  const entries: Recalled[] = [];
  for (const item of c.state.transcripts[chatId]?.items ?? []) {
    if (item.role !== "user" || item.from) continue;
    const text = c.plainText(item.blocks).trim();
    if (!text) continue;
    const files = filePaths(item.blocks),
      entry = { id: item.id, text, ...(files.length ? { files } : {}) };
    if (entries[entries.length - 1]?.text === text) entries[entries.length - 1] = entry;
    else entries.push(entry);
  }
  return entries;
}

/** Which of `entries` the box shows, or -1 when it shows its own text. */
function shownIndex(entries: readonly Recalled[], composer: Composer): number {
  const recalled = composer.recalled;
  if (recalled?.text !== composer.text) return -1;
  for (let at = entries.length - 1; at >= 0; at--) if (entries[at]!.id === recalled.id) return at;
  return -1;
}

/**
 * Which entry Up or Down shows next, from the one shown (`-1`, the box's own text): Up goes to an
 * older prompt and stays on the oldest, Down to a newer one and past the newest to the empty box.
 */
export function nextShown(count: number, shown: number, key: ArrowKey): number {
  if (key === "up") return shown < 0 ? count - 1 : Math.max(shown - 1, 0);
  return shown < 0 || shown + 1 >= count ? -1 : shown + 1;
}

/**
 * The arrows the prompt field hands to this plugin: both while it shows a prompt they brought back,
 * Up while it is empty and the chat has prompts to bring back, and none otherwise. An image in the
 * box counts as something typed.
 */
export function historyKeys(c: Controller, chatId: string): ArrowKey[] {
  const composer = c.composer(chatId);
  if (composer.recalled?.text === composer.text) return ["up", "down"];
  const empty = !composer.text.trim() && !composer.attachments.length && !composer.carriedBlocks?.length;
  return empty && promptHistory(c, chatId).length ? ["up"] : [];
}

/**
 * Puts the prompt Up or Down takes the box to in it, with the caret at its end. The keys the field
 * handed over were the ones of its last render; a key that no longer applies (the user typed since)
 * does nothing.
 */
export const recallPrompt = Effect.fn("Chat.recallPrompt")(function* (c: Controller, chatId: string, key: ArrowKey) {
  if (!historyKeys(c, chatId).includes(key)) return;
  const composer = c.composer(chatId),
    entries = promptHistory(c, chatId);
  const shown = shownIndex(entries, composer),
    next = nextShown(entries.length, shown, key);
  if (next === shown) return;
  composer.recalled = entries[next];
  composer.text = composer.recalled?.text ?? "";
  composer.tagged = withFiles(composer.tagged, composer.recalled?.files ?? []);
  composer.caret = composer.text.length;
  composer.place = { text: composer.text, at: composer.caret };
  c.refreshComposer(chatId);
  yield* textChanged(c, chatId);
});

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.