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