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

Permissions in 0.2.9

  • 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

picker.ts6.2 KB
// What the composer's picker lists for its word: files and plugin mentions
// after `@`, skills after `$`, the app's commands then skills after a `/`
// later in the text, and the app's commands, the agent's and plugins'
// commands, then skills after a `/` that starts the text. One list for the
// rows, the keys and Enter.
import type { Controller } from "./controller.ts";
import type { Composer } from "./state.ts";
import type { Mention } from "./mentions.ts";
import { matchMentions } from "./mentions.ts";
import { deriveSegments, isFolder, parentOf, pathName, pillLook, written, type Segment, type SegmentKind } from "./segments.ts";
import { appCommands } from "./app-commands.ts";

export type Entry = {
  /// The row's id: `file-<path>`, `mention-<plugin>-<id>`, `skill-<name>`, `cmd-<name>`.
  id: string;
  kind: SegmentKind;
  /// What taking it writes in the text.
  text: string;
  label: string;
  detail?: string;
  icon?: string;
  /// A file's name, for the file tree's icon.
  file?: string;
  command?: { name: string; inputHint?: string | null };
  mention?: Mention;
  /// One of the app's own commands (`app-commands.ts`): taking it opens
  /// what it names instead of writing anything.
  app?: string;
};
/// At most this many rows: the list stays a glance tall.
const ROWS = 10;
/// Plugin mentions shown before the files.
const MENTION_ROWS = 3;

/// The highlighted entry's index: the one the keys moved to, or the last
/// when the list got shorter under it.
export function highlighted(composer: Composer, count: number) {
  return Math.max(0, Math.min(composer.picker?.index ?? 0, count - 1));
}

/// The items whose name starts with `query`, then those whose name holds
/// it, then those whose description does, at most `ROWS` (case-insensitive).
export function ranked<T extends { name: string }>(items: readonly T[], query: string, description: (item: T) => string) {
  const wanted = query.toLowerCase();
  const scored: { score: number; item: T }[] = [];
  for (const item of items) {
    const name = item.name.toLowerCase();
    const score = name.startsWith(wanted) ? 0 : name.includes(wanted) ? 1 : description(item).toLowerCase().includes(wanted) ? 2 : -1;
    if (score >= 0) scored.push({ score, item });
  }
  return scored
    .sort((a, b) => a.score - b.score)
    .slice(0, ROWS)
    .map(({ item }) => item);
}

/// Whether `query`'s characters appear in `path` in order, ignoring case:
/// how the host's search matches, so a stand-in row is one it could answer.
function matches(path: string, query: string) {
  const lower = path.toLowerCase();
  let at = 0;
  for (const char of query.toLowerCase()) {
    at = lower.indexOf(char, at) + 1;
    if (!at) return false;
  }
  return true;
}

export function entries(c: Controller, composer: Composer): Entry[] {
  const picker = composer.picker;
  if (!picker) return [];
  if (picker.kind === "files") {
    const mentions = matchMentions(c.api.mentions.list(), picker.query, MENTION_ROWS).map(
      (mention): Entry => ({
        id: `mention-${mention.plugin}-${mention.id}`,
        kind: "mention",
        text: written.mention(mention.token),
        label: mention.label,
        detail: mention.detail ?? `@${mention.token}`,
        icon: mention.icon ?? "bot",
        mention,
      }),
    );
    // Until the search for this query answers, the last results that
    // still match stand in for it, or all of them when none does, so the
    // list never empties or closes while it waits.
    const still = composer.filesFor === picker.query ? [] : composer.files.filter((path) => matches(path, picker.query));
    const shown = still.length ? still : composer.files;
    const files = shown.map(
      (path): Entry => ({
        id: `file-${path}`,
        kind: "file",
        text: written.file(path),
        label: pathName(path),
        detail: parentOf(path),
        ...(isFolder(path) ? { icon: "folder" } : { file: pathName(path) }),
      }),
    );
    return [...mentions, ...files].slice(0, ROWS);
  }
  const skills = c.matchingSkills(composer, picker.query).map(
    (skill): Entry => ({
      id: `skill-${skill.name}`,
      kind: "skill",
      text: written.skill(skill.name),
      label: skill.name,
      detail: skill.description || skill.source,
      icon: "sparkles",
    }),
  );
  if (picker.kind === "skills") return skills.slice(0, ROWS);
  // By name only: they go first, so a description that merely mentions
  // the query must not push the agent's commands down.
  const app = ranked(appCommands(c, composer), picker.query, () => "").map(
    (command): Entry => ({
      id: `cmd-${command.name}`,
      kind: "command",
      text: written.command(command.name),
      label: command.name,
      detail: command.description,
      icon: command.icon,
      app: command.name,
    }),
  );
  if (picker.kind === "slash") return [...app, ...skills].slice(0, ROWS);
  const commands = c.matchingCommands(composer, picker.query).map(
    (command): Entry => ({
      id: `cmd-${command.name}`,
      kind: "command",
      text: written.command(command.name),
      label: command.name,
      detail: command.description,
      icon: "square-slash",
      command,
    }),
  );
  // An agent may publish a skill as a command as well (Claude Code does):
  // one row per name, the command, which runs it the agent's own way.
  const named = new Set(commands.map((command) => command.label));
  return [...app, ...commands, ...skills.filter((skill) => !named.has(skill.label))].slice(0, ROWS);
}

/// The pills of the composer's text: where the field last said they are,
/// or for a text it did not report (a restored draft, a sent prompt
/// cleared), the words a pick would have written.
export function segmentsOf(c: Controller, composer: Composer): Segment[] {
  if (composer.segments?.text === composer.text) return composer.segments.list;
  const list = deriveSegments(
    composer.text,
    { mentions: c.api.mentions.list(), skills: composer.skills, commands: c.commandList(composer) },
    composer.tagged,
  );
  composer.segments = { text: composer.text, list };
  return list;
}

/// How a pill in the prompt looks.
export const pillOf = (c: Controller, composer: Composer, segment: Segment) =>
  pillLook(segment.kind, composer.text.slice(segment.start, segment.end), c.api.mentions.list());

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.