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

app-commands.ts5.5 KB
// Slash commands the app answers itself, for every agent: `/model`,
// `/effort`, `/mode` and `/speed` open the chat's settings menu at that
// setting, and `/rename` turns the title into a field. They work from
// anywhere in the prompt, and run in place of an agent's command of the
// same name, which would change the agent's session behind the menu's
// back. With a value (`/model sonnet`, `/rename Fix login`) they set it
// at once.
import * as Effect from "effect/Effect";
import type { ConfigOption } from "divergence";
import { Slash } from "divergence/effect";
import type { Controller } from "./controller.ts";
import type { Composer } from "./state.ts";
import { errorMessage } from "./data.ts";

type Setting = { name: string; category: string; description: string; icon: string; what: string };
/// The settings menu's rows a command opens, by the option's category.
const SETTINGS: readonly Setting[] = [
  { name: "model", category: "model", description: "Choose the model", icon: "cpu", what: "model" },
  { name: "effort", category: "reasoning", description: "Choose how hard the model thinks", icon: "brain", what: "effort" },
  { name: "mode", category: "mode", description: "Choose the agent's mode", icon: "layers", what: "mode" },
  { name: "speed", category: "speed", description: "Choose how fast the agent answers", icon: "zap", what: "speed" },
];
const RENAME = { name: "rename", description: "Rename this chat", icon: "pencil", inputHint: "[title]" };
export const APP_COMMANDS: ReadonlySet<string> = new Set([...SETTINGS.map((setting) => setting.name), RENAME.name]);

export type AppCommand = { name: string; description: string; icon: string };
/// The app's commands this chat can use now: a setting's only while the
/// agent offers that setting.
export function appCommands(c: Controller, composer: Composer): AppCommand[] {
  const options = c.visibleOptions(composer);
  return [...SETTINGS.filter((setting) => options.some((option) => option.category === setting.category)), RENAME];
}

/// The choice `input` names: its value, else the first name that starts
/// with it, else the first that holds it (case-insensitive).
function choiceNamed(option: ConfigOption, input: string) {
  const wanted = input.toLowerCase();
  const choices = option.choices ?? [];
  return (
    choices.find((choice) => choice.value.toLowerCase() === wanted || choice.name.toLowerCase() === wanted) ??
    choices.find((choice) => choice.name.toLowerCase().startsWith(wanted)) ??
    choices.find((choice) => choice.name.toLowerCase().includes(wanted) || choice.value.toLowerCase().includes(wanted))
  );
}

/// Runs the app's command `name` in a chat: with no input it opens the
/// setting's menu or the title field, with one it sets it.
export const runAppCommand = Effect.fn("Chat.runAppCommand")(function* (
  c: Controller,
  chatId: string,
  name: string,
  input = "",
) {
  const chat = c.state.chats[chatId];
  if (!chat) return;
  if (name === RENAME.name) return yield* input ? rename(c, chatId, input) : startRename(c, chatId);
  const setting = SETTINGS.find((known) => known.name === name);
  if (!setting) return;
  const composer = c.composer(chatId);
  const option = c.visibleOptions(composer).find((known) => known.category === setting.category);
  if (!option) {
    const agent = c.state.agents[chat.agentId]?.name ?? "This agent";
    return yield* c.notify.warning(`${agent} has no ${setting.what} setting`);
  }
  if (input) {
    const choice = choiceNamed(option, input);
    if (choice) return yield* c.setOption(chatId, option.id, choice.value);
    yield* c.notify.warning(`No ${setting.what} matches “${input}”`);
  }
  yield* c.views.focus(`models-${chatId}-${chat.agentId}`, option.id);
});

/// Turns the title in the title strip into a field holding the title.
export const startRename = Effect.fn("Chat.startRename")(function* (c: Controller, chatId: string) {
  const chat = c.state.chats[chatId];
  if (!chat) return;
  c.state.renaming = { chatId, text: c.titleOf(chat) };
  c.presentations?.updateTitle(chatId);
  yield* c.views.focus(`title-rename-${chatId}`);
});

/// Saves a chat's title, "New Chat" when it is blank, and closes the field.
export const rename = Effect.fn("Chat.rename")(function* (c: Controller, chatId: string, title: string) {
  if (c.state.renaming?.chatId === chatId) c.state.renaming = null;
  c.presentations?.updateTitle(chatId);
  yield* c.views.focus(`prompt-${chatId}`);
  yield* c.host
    .call("host/chats.update", { chatId, title: title.trim() || "New Chat" })
    .pipe(Effect.catch((error) => c.notify.error(`Rename failed: ${errorMessage(error)}`)));
});

/// Closes the title field without saving.
export const cancelRename = Effect.fn("Chat.cancelRename")(function* (c: Controller) {
  const chatId = c.state.renaming?.chatId;
  c.state.renaming = null;
  if (chatId) c.presentations?.updateTitle(chatId);
  if (chatId) yield* c.views.focus(`prompt-${chatId}`);
});

/// Registers the commands with the host, so a sent `/model sonnet` runs
/// here instead of reaching the agent.
export const registerAppCommands = Effect.fn("Chat.registerAppCommands")(function* (c: Controller) {
  const slash = yield* Slash;
  for (const command of [...SETTINGS.map((setting) => ({ ...setting, inputHint: "[name]" })), RENAME])
    yield* slash.register({
      name: command.name,
      description: command.description,
      inputHint: command.inputHint,
      run: Effect.fn("Chat.appCommand")(function* (input, context) {
        if (context.chatId) yield* runAppCommand(c, context.chatId, command.name, input.trim());
        return { action: "none" as const };
      }),
    });
});

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.