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
Files
picker.ts6.3 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, 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);
}
const baseName = (path: string) => path.slice(path.lastIndexOf("/") + 1);
const folderOf = (path: string) => path.slice(0, Math.max(0, path.lastIndexOf("/")));
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, so the list neither empties nor waits.
const wanted = picker.query.toLowerCase();
const shown =
composer.filesFor === picker.query ? composer.files : composer.files.filter((path) => path.toLowerCase().includes(wanted));
const files = shown.map(
(path): Entry => ({
id: `file-${path}`,
kind: "file",
text: written.file(path),
label: baseName(path),
detail: folderOf(path),
file: baseName(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 looks: its label and mark, from what it stands for.
export function pillOf(c: Controller, composer: Composer, segment: Segment) {
const text = composer.text.slice(segment.start, segment.end);
const name = text.slice(1);
if (segment.kind === "file") return { label: baseName(name) || name, file: baseName(name) || name };
if (segment.kind === "skill") return { label: name, icon: "sparkles" };
if (segment.kind === "command") return { label: name, icon: "square-slash" };
return { label: name, icon: c.api.mentions.list().find((known) => known.token === name)?.icon ?? "bot" };
}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.