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
shortcuts.ts3.7 KB
// The keys beside controls ("Stop (⇧⌘C)") are the keys bound now, read from
// `kernel/commands` and written as the host writes them for this platform:
// macOS's symbols in their standard order there, "Ctrl+Shift+C" elsewhere.
// A key the user rebinds shows its new key, and a command with no key shows
// none.
import * as Effect from "effect/Effect";
import * as Stream from "effect/Stream";
import { Events } from "divergence/effect";
import type { CommandInfo } from "divergence";
import type { Controller } from "./controller.ts";
import { errorMessage } from "./data.ts";
export type Shortcuts = {
/** The first key of each command that has one, as the keyboard shows it, by command id. */
readonly keys: Readonly<Record<string, string>>;
/** The host writes keys with macOS's symbols. */
readonly mac: boolean;
};
export const NO_SHORTCUTS: Shortcuts = { keys: {}, mac: false };
/** The sidebar's New chat, which the title strip and the empty center run. */
export const NEW_CHAT = "sidebar.newChat";
/** The sidebar's Close Chat, which Cmd+W runs on a chat's only tab. */
export const CLOSE_CHAT = "sidebar.closeChat";
/** The sidebar's Reopen Closed Chat, which Cmd+Shift+T runs for a chat Cmd+W closed. */
export const REOPEN_CHAT = "sidebar.reopenChat";
export function shortcutsOf(commands: readonly Pick<CommandInfo, "id" | "labels">[]): Shortcuts {
const keys: Record<string, string> = {};
for (const command of commands) if (command.labels[0]) keys[command.id] = command.labels[0];
// A plugin is not told the platform, but the host's labels say it: only
// on macOS are they written with these symbols.
return { keys, mac: commands.some((command) => command.labels.some((label) => /[⌘⌃⌥⇧↩⎋⇥⌫⌦]/.test(label))) };
}
/** What a control says with the key of `command`: "Stop (⇧⌘C)", or the words alone while no key runs it. */
export function hint(c: Controller, words: string, command: string): string {
return withKey(words, c.state.shortcuts.keys[command]);
}
/**
* What a control of the prompt says with the prompt's own key, which is not a command: Enter sends,
* and the platform key with Enter queues.
*/
export function promptHint(c: Controller, words: string, key: "send" | "queue"): string {
const mac = c.state.shortcuts.mac;
return withKey(words, key === "send" ? (mac ? "↩" : "Enter") : mac ? "⌘↩" : "Ctrl+Enter");
}
const withKey = (words: string, key: string | undefined) => (key ? `${words} (${key})` : words);
/** Reads the keys bound now and draws again the views that show them. */
export const loadShortcuts = Effect.fn("Chat.loadShortcuts")(function* (c: Controller) {
const { commands } = yield* c.kernel.call("commands", {});
c.state.shortcuts = shortcutsOf(commands);
// The title strip holds the panes' strips and their tab menus.
c.presentations?.updateAllTitles();
c.center?.update();
for (const chatId of Object.keys(c.state.panes)) c.refreshComposer(chatId);
});
/**
* Reads the keys at the start and again whenever they may have changed: `keybindings.json`, a plugin's
* manifest, or a plugin turned on or off.
*/
export const followShortcuts = Effect.fn("Chat.followShortcuts")(function* (c: Controller) {
const events = yield* Events;
const load = Effect.forkIn(
loadShortcuts(c).pipe(
Effect.catch((error) => c.notify.error(`The keyboard shortcuts could not be read: ${errorMessage(error)}`)),
),
c.scope,
{ startImmediately: true },
);
yield* load;
for (const event of ["keybindings_changed", "plugins_changed", "access_changed"] as const)
yield* events.stream(event).pipe(
Stream.runForEach(() => load),
Effect.forkScoped({ startImmediately: true }),
);
});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.