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.7

Permissions in 0.2.7

  • 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

changes.ts5.4 KB
// What each finished turn changed: a summary at the end of the turn lists
// the files with the lines each gained and lost. It is read with the
// transcript's rows (`turnFiles`, `data.ts`) and kept current by the host's
// `turn_changes` event, and a click on a file opens what the turn did to
// it in a diff tab. An older host sends neither the files nor the summaries,
// so it shows none.
import * as Effect from "effect/Effect";
import * as Stream from "effect/Stream";
import { Events } from "divergence/effect";
import type { ChangedFile, TranscriptItem, TurnSummary } from "divergence";
import type { Controller } from "./controller.ts";
import type { Transcript } from "./state.ts";
import type { groupTasks } from "./subagents.ts";
import { errorMessage } from "./data.ts";

type Entry = ReturnType<typeof groupTasks>[number];

/** The entry each summary ends, by its index: the one before the message
 * the summary goes before, or the last entry for the chat's latest turn. A
 * summary whose message is not among the rows read yet waits for them. The
 * latest turn's summary shows only while the chat is not running: a run that
 * settles and another that starts without a message from you is a pause, and
 * the summary goes once the agent works again, until its turn ends. */
export function summariesAt(entries: readonly Entry[], turns: ReadonlyMap<string, TurnSummary>, running: boolean): Map<number, TurnSummary> {
  const at = new Map<number, TurnSummary>();
  if (!turns.size) return at;
  const index = new Map<string, number>();
  entries.forEach((entry, i) => {
    if (entry.kind === "item") index.set(entry.item.id, i);
  });
  for (const turn of turns.values()) {
    if (turn.before === undefined && running) continue;
    const end = turn.before === undefined ? entries.length : index.get(turn.before);
    if (end) at.set(end - 1, turn);
  }
  return at;
}

/** A message you sent after a turn's summary arrived begins the next turn,
 * so the summary stays before it, as the host places it on the next read. */
export function endTurns(transcript: Transcript, item: TranscriptItem) {
  if (item.role !== "user" || item.from != null) return;
  for (const turn of transcript.turnFiles.values())
    if (turn.before === undefined && turn.itemId !== item.id)
      transcript.turnFiles.set(turn.itemId, { ...turn, before: item.id });
}

export type Folder = { folder: string; files: ChangedFile[] };

const order = (a: string, b: string) => a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" });
/** The last part of a path: the name a file's row shows under its folder. */
export const nameOf = (path: string) => path.slice(path.lastIndexOf("/") + 1);

/** A turn's files under the folder each is in: the folders in order, then
 * the files at the top of the workspace, whose folder is "". */
export function byFolder(files: readonly ChangedFile[]): Folder[] {
  const folders = new Map<string, ChangedFile[]>();
  for (const file of files) {
    const folder = file.path.slice(0, Math.max(file.path.lastIndexOf("/"), 0));
    folders.set(folder, [...(folders.get(folder) ?? []), file]);
  }
  return [...folders]
    .map(([folder, files]) => ({ folder, files: files.sort((a, b) => order(nameOf(a.path), nameOf(b.path))) }))
    .sort((a, b) => (a.folder ? (b.folder ? order(a.folder, b.folder) : -1) : b.folder ? 1 : 0));
}

/** The lines all of a turn's files gained and lost, of those whose lines are known. */
export function totals(files: readonly ChangedFile[]): { added: number; removed: number } | null {
  const known = files.filter((file) => file.added !== undefined);
  if (!known.length) return null;
  return {
    added: known.reduce((sum, file) => sum + (file.added ?? 0), 0),
    removed: known.reduce((sum, file) => sum + (file.removed ?? 0), 0),
  };
}

/** Opens what the turn that `itemId` began did to `path` in a diff tab of
 * the chat's task. Without the tabs plugin there is nowhere to show it. */
export const openTurnDiff = Effect.fn("Chat.openTurnDiff")(function* (
  c: Controller,
  chatId: string,
  itemId: string,
  path: string,
) {
  const chat = c.state.chats[chatId];
  const tabs = c.tabs;
  if (!chat || !tabs) return;
  const read = yield* c.host.call("host/chats.turn_diff", { chatId, itemId, path }).pipe(
    Effect.map((result) => result.diff),
    Effect.catch((error) =>
      c.notify.error(`Could not show the changes to ${path}: ${errorMessage(error)}`).pipe(Effect.as(null)),
    ),
  );
  if (read === null) return;
  yield* tabs.open({ kind: "diff", workspaceId: chat.workspaceId, path, diff: read, chatId }).pipe(
    // A call that loses its provider on the way behaves like no reader,
    // and the failure is logged.
    Effect.ignore({ log: "Warn", message: "Could not open the diff in a tab" }),
  );
});

/** A turn that ended with files changed adds its summary at once. */
export const followTurnChanges = Effect.fn("Chat.followTurnChanges")(function* (c: Controller) {
  const events = yield* Events;
  yield* events.stream("turn_changes").pipe(
    Stream.runForEach((event) =>
      Effect.sync(() => {
        const transcript = c.state.transcripts[event.chatId];
        if (!transcript || !event.files?.length) return;
        // A read already under way would not have it: it reads again.
        transcript.version++;
        transcript.turnFiles.set(event.itemId, { itemId: event.itemId, files: event.files });
        c.refresh(event.chatId);
      }),
    ),
    Effect.forkScoped({ startImmediately: true }),
  );
});

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.