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

  • 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, and its Close Chat and Reopen Closed Chat for Cmd+W and Cmd+Shift+T on a chat's only tab
  • 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

composition.ts7.3 KB
// Capture a complete structured composition before acknowledging or clearing it.
// Reading one attachment fails the submission, never silently sends a subset.
import * as Effect from "effect/Effect";
import type { Chat, ContentBlock, InputComposition } from "divergence";
import type { Controller } from "./controller.ts";
import type { Prompt } from "./state.ts";
import { mentionInstructions, tagTokens } from "./mentions.ts";
import { fileAt, typedPath, withFiles } from "./segments.ts";

let sequence = 0;
export const inputId = () => `chat:${Date.now()}:${++sequence}:${Math.random().toString(36).slice(2)}`;
export function steeringReason(c: Controller, chat: Chat): string | undefined {
  if (!c.isRunning(chat)) return;
  if (c.scheduler.available === false) return "Active steering needs an updated app; Queue retains the prompt";
}
// Legacy drafts use only the established first-text editable convention. No
// later block is classified by its contents; explicit provenance is the owner.
export function editableComposition(value: { blocks: readonly ContentBlock[]; composition?: InputComposition }) {
  if (value.composition) {
    const generated = new Set(value.composition.generated);
    return { text: value.composition.text, carriedBlocks: value.blocks.filter((_, index) => !generated.has(index)) };
  }
  const first = value.blocks[0];
  return {
    text: first?.type === "text" ? first.text : "",
    carriedBlocks: first?.type === "text" ? value.blocks.slice(1) : value.blocks,
  };
}
/// The text as blocks, with each `$name` of one of the agent's skills as a
/// skill block: one that starts the message takes the rest as its input,
/// as the agent's own `$name args` (or `/name args`) does; one later in it
/// stands where it was written, between the text around it.
export function withSkills(text: string, skills: readonly { name: string }[]): ContentBlock[] {
  const known = new Set(skills.map((skill) => skill.name));
  const lead = /^\$(\S+)/.exec(text)?.[1];
  if (lead && known.has(lead)) return [{ type: "skill", name: lead, input: text.slice(1 + lead.length).trim() }];
  const blocks: ContentBlock[] = [];
  let from = 0;
  for (const match of text.matchAll(/(^|\s)\$(\S+)/g)) {
    const name = match[2] ?? "";
    if (!known.has(name)) continue;
    const start = match.index + (match[1] ?? "").length;
    if (start > from) blocks.push({ type: "text", text: text.slice(from, start) });
    blocks.push({ type: "skill", name });
    from = start + 1 + name.length;
  }
  if (from < text.length) blocks.push({ type: "text", text: text.slice(from) });
  return blocks;
}
/// Each `@path` that names one of `files` (picked, dropped, stored or typed
/// and found on disk; a path may hold spaces) and is not a mention tag as a
/// `file_ref` block where it stands, between the text around it: the
/// blocks read in order, as the protocol's plain text has them, so an
/// agent that writes a reference as `@path` does not get it twice. Trailing
/// punctuation stays text. A skill's input keeps its words, and its files
/// follow it.
export function withFileRefs(blocks: readonly ContentBlock[], tags: ReadonlySet<string>, files: readonly string[] = []): ContentBlock[] {
  const refs = (text: string) => {
    const found: { start: number; path: string }[] = [];
    for (const match of text.matchAll(/(^|\s)(@\S+)/g)) {
      const start = match.index + (match[1] ?? "").length;
      const last = found.at(-1);
      if (last && start < last.start + 1 + last.path.length) continue;
      if (tags.has(match[2] ?? "")) continue;
      const path = fileAt(text, start, files);
      if (path) found.push({ start, path });
    }
    return found;
  };
  return blocks.flatMap((block): ContentBlock[] => {
    if (block.type === "skill") return [block, ...refs(block.input ?? "").map(({ path }) => ({ type: "file_ref" as const, path }))];
    if (block.type !== "text") return [block];
    const out: ContentBlock[] = [];
    let from = 0;
    for (const { start, path } of refs(block.text)) {
      if (start > from) out.push({ type: "text", text: block.text.slice(from, start) });
      out.push({ type: "file_ref", path });
      from = start + 1 + path.length;
    }
    if (from < block.text.length) out.push({ type: "text", text: block.text.slice(from) });
    return out;
  });
}
function refsAfter(text: string, tags: ReadonlySet<string>, files: readonly string[]): ContentBlock[] {
  return withFileRefs([{ type: "text", text }], tags, files).filter((block) => block.type === "file_ref");
}
/// The paths typed by hand after a `@` in `text`, without a pick, that are
/// files in the chat's workspace. A path the host cannot find (or read)
/// stays the text it was typed as.
const typedFiles = Effect.fn("Chat.typedFiles")(function* (
  c: Controller,
  chatId: string,
  text: string,
  tags: ReadonlySet<string>,
  files: readonly string[],
) {
  const workspaceId = c.state.chats[chatId]?.workspaceId;
  const found: string[] = [];
  for (const match of text.matchAll(/(^|\s)(@\S+)/g)) {
    const start = match.index + (match[1] ?? "").length;
    const path = !tags.has(match[2] ?? "") && !fileAt(text, start, files) ? typedPath(text, start) : null;
    if (!path || found.includes(path)) continue;
    const stat = yield* c.host.call("host/fs.stat", { workspaceId, path }).pipe(Effect.result);
    if (stat._tag === "Success") found.push(path);
  }
  return found;
});
export const compositionFor = Effect.fn("Chat.compositionFor")(function* (
  c: Controller,
  chatId: string,
  editableText: string,
  attachments: Prompt["attachments"],
  carried: readonly ContentBlock[] = c.composer(chatId).carriedBlocks ?? [],
  expand = true,
  tagged: readonly string[] = [],
) {
  const composer = c.composer(chatId);
  const files = withFiles(composer.tagged, tagged);
  const blocks: ContentBlock[] = [];
  const text = expand ? editableText.trim() : editableText;
  const mentions = c.api.mentions.list(),
    tags = tagTokens(text, mentions);
  // A draft keeps its text as typed, with its files after it: its blocks
  // are rebuilt from that text when it is sent.
  if (expand) {
    const typed = yield* typedFiles(c, chatId, text, tags, files);
    blocks.push(...withFileRefs(withSkills(text, composer.skills), tags, [...files, ...typed]));
  }
  else if (text) blocks.push({ type: "text", text }, ...refsAfter(text, tags, files));
  const instructions = expand ? mentionInstructions(text, mentions) : undefined;
  // A paragraph of its own: an agent that joins the text blocks (Claude
  // Code) reads it apart from the message.
  if (instructions) blocks.push({ type: "text", text: `\n\n${instructions}` });
  const composition: InputComposition = { text: editableText, generated: blocks.map((_, index) => index) };
  for (const image of attachments) {
    const { mimeType, data } = yield* c.kernel.call("image_data", { id: image.id });
    blocks.push({ type: "image", mimeType, data });
  }
  blocks.push(...carried);
  return { blocks, composition };
});
export const blocksFor = Effect.fn("Chat.blocksFor")((...args: Parameters<typeof compositionFor>) =>
  compositionFor(...args).pipe(Effect.map((value) => value.blocks)),
);
export function amendedInput(snapshot: import("divergence").InputSnapshot, id: string) {
  return (
    snapshot.inputs.find((input) => input.id === id) ??
    snapshot.inputs.filter((input) => input.intent === "steer" && input.state === "held").at(-1)
  );
}

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.