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

  • 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

views/session.tsx9.2 KB
// The Session panel of the right rail: the chat open in the center, its
// context window, the account's usage limits, its subagents and its
// background terminals. Rendering only reads state; handlers run
// controller effects.
// HTM whitespace is significant; keep these templates out of Prettier's HTML formatter.
import * as Effect from "effect/Effect";
import type { Chat, ConfigOption, Element } from "divergence";
import type { ChatView } from "../controller.ts";
import type { TaskRow } from "../subagents.ts";
import { allTasks, isLive, metaLine, nameOf, statusOf as taskStatus, taskItems } from "../subagents.ts";
import { displayStatus, modelName } from "../workflows.ts";
import { ago, optionLabel, pinned, sessionOpen, statusOf, when, working } from "../session.ts";
import { contextDetails, limitRow } from "./usage.tsx";
import { agentMark, mark } from "./tasks.tsx";
import { AGENT_MARK, column, fill, full, markIcon, markOf, row } from "./styles.tsx";

// An item's side inset: the lines between the rows start where their marks do.
const INSET = 9;
// Each level of subagents steps in by a tree level.
const LEVEL = 14;

/// The chat in the center, while the center shows one.
function shownChat(v: ChatView): Chat | undefined {
  const app = v.ctx.app;
  return app.route === "chat" && app.chatId ? v.controller.state.chats[app.chatId] : undefined;
}

export function renderSessionRail(v: ChatView): Element | null {
  const chat = shownChat(v);
  const count = chat ? working(taskItems(v.controller.state.transcripts[chat.id])) : 0;
  return <button id="rail-session" icon="activity" variant="ghost" active={pinned(v.ctx.app)} tooltip={count ? `Session: ${count} ${count === 1 ? "task" : "tasks"} working` : "Session"} badge={count ? String(count) : undefined} onClick={() => v.ctx.run(v.controller.toggleSession())} />;
}

export function renderSessionPanel(v: ChatView): Element | null {
  if (!sessionOpen(v.ctx.app)) return null;
  const chat = shownChat(v);
  return (
    <div {...column} {...fill} {...full} padding="small" paddingTop={0}>
      <div {...row} gap="small" paddingX="small" height="2rem">
          <div {...row} {...fill} padding="small" paddingX={10}><text style="body" size={13.125} weight={600} truncate>Session</text></div>
          <button id="session-close" icon="x" variant="ghost" small tooltip="Close" onClick={() => v.ctx.run(v.controller.closeSession())} />
        </div>
      {chat
                ? (
                  <div {...column} {...fill} gap="medium" padding="small" overflowY="scroll">
                    {sessionSection(v, chat)}
                    {contextSection(v, chat)}
                    {limitsSection(v, chat)}
                    {subagentsSection(v, chat)}
                    {terminalsSection(v, chat)}
                  </div>
                )
                : <div {...column} gap="small" padding="medium"><text style="muted">Open a chat to see its session.</text></div>}
    </div>
  );
}

// A heading and its rows; a count at the heading's end when there is one.
function section(id: string, label: string, body: readonly (Element | null)[], count?: number): Element {
  const heading = count
    ? <item heading id={`session-${id}`} label={label}><text style="body" size={9.84} tone="muted">{String(count)}</text></item>
    : <item heading id={`session-${id}`} label={label} />;
  return <div {...column} gap={2}>{heading}{body}</div>;
}

// A line of the Session section: its name in a column of its own, the
// value, and a button at the end.
function field(id: string, name: string, value: readonly (Element | null)[], end?: Element): Element {
  return (
    <div {...row} id={`session-${id}`} gap="small" paddingX={INSET} paddingY={3} minHeight={24}>
      <div {...row} width={84} flexShrink={0}><text style="small" tone="muted">{name}</text></div>
      <div {...row} {...fill} gap={6}>{value}</div>
      {end ?? null}
    </div>
  );
}

const plain = (text: string) => <text style="small" truncate>{text}</text>;

function sessionSection(v: ChatView, chat: Chat): Element {
  const c = v.controller;
  const agent = c.state.agents[chat.agentId];
  const composer = c.state.composers[chat.id];
  const options = composer ? c.visibleOptions(composer) : [];
  const chosen = (category: string) => optionLabel(options.find((option: ConfigOption) => option.category === category));
  const model = [chosen("model"), chosen("reasoning")].filter(Boolean).join(" · ");
  const approval = chosen("approval");
  const workspace = c.state.workspaces[chat.workspaceId];
  const live = allTasks(taskItems(c.state.transcripts[chat.id])).some(({ task }) => isLive(task));
  const status = statusOf(live && !chat.status.startsWith("waiting_") ? { ...chat, status: "running" } : chat);
  const created = when(chat.createdAt);
  const active = ago(chat.updatedAt);
  const sessionId = chat.sessionId;
  const copy = (text: string) =>
    c.kernel.call("copy_text", { text }).pipe(
      Effect.andThen(c.notify.info("Copied the session id.")),
      Effect.catch((error) => c.notify.error(`Copy failed: ${error.message}`)),
    );
  return section("info", "Session", [
    field("agent", "Agent", [<icon name="bot" small tone="muted" svg={agent?.icon} />, plain(agent?.name ?? chat.agentId)]),
    model ? field("model", "Model", [plain(model)]) : null,
    approval ? field("approval", "Approval", [plain(approval)]) : null,
    workspace ? field("workspace", "Workspace", [markIcon(markOf(workspace), 14, true), plain(workspace.name)]) : null,
    field("status", "Status", [
      status.running ? <spinner activity /> : <icon name="circle" small tone={status.tone} />,
      plain(status.label),
    ]),
    sessionId
      ? field(
          "id",
          "Session id",
          [<text style="mono" size="xs" truncate>{sessionId}</text>],
          <button id="session-copy-id" icon="copy" variant="ghost" small tooltip="Copy session id" onClick={() => v.ctx.run(copy(sessionId))} />,
        )
      : null,
    created ? field("created", "Created", [plain(created)]) : null,
    active ? field("active", "Last active", [plain(active)]) : null,
  ]);
}

// The sections below show only once the chat has something for them.
function contextSection(v: ChatView, chat: Chat): Element | null {
  const usage = v.controller.state.transcripts[chat.id]?.usage;
  if (!usage?.contextWindow) return null;
  return section("context", "Context window", [
    <div {...column} paddingX={INSET} paddingY={4}>{contextDetails(usage)}</div>,
  ]);
}

function limitsSection(v: ChatView, chat: Chat): Element | null {
  const windows = v.controller.state.agents[chat.agentId]?.usageLimits?.windows ?? [];
  if (!windows.length) return null;
  return section("limits", "Usage limits", [
    <div {...column} gap="medium" paddingX={INSET} paddingY={4}>{windows.map(limitRow)}</div>,
  ]);
}

// Live work first, then the rest in the order it started.
function tasksOf(v: ChatView, chat: Chat, terminal: boolean): TaskRow[] {
  return allTasks(taskItems(v.controller.state.transcripts[chat.id]))
    .filter(({ task }) => (task.kind === "terminal") === terminal)
    .sort((a, b) => Number(isLive(b.task)) - Number(isLive(a.task)));
}

function subagentsSection(v: ChatView, chat: Chat): Element | null {
  const rows = tasksOf(v, chat, false);
  if (!rows.length) return null;
  const model = v.controller.state.composers[chat.id]?.options.find((option) => option.category === "model");
  return section(
    "subagents",
    "Subagents",
    rows.map((taskRow) => subagentRow(v, chat, taskRow, model)),
    rows.length,
  );
}

// Commands the agent left running in the background, each at the top
// level: they belong to the chat, not to the subagent that started them.
function terminalsSection(v: ChatView, chat: Chat): Element | null {
  const rows = tasksOf(v, chat, true);
  if (!rows.length) return null;
  return section(
    "terminals",
    "Background terminals",
    rows.map((taskRow) => subagentRow(v, chat, { ...taskRow, depth: 0 }, undefined)),
    rows.length,
  );
}

// A subagent or a workflow: its status mark, title, and a line with its
// name, model, time, tokens and tool uses. A click opens its tab.
function subagentRow(v: ChatView, chat: Chat, { item, task, depth }: TaskRow, model: ConfigOption | undefined): Element {
  const status = task.workflow ? displayStatus(item) : task.status;
  const waiting = status === "waiting";
  const meta = [task.name, metaLine({ ...task, model: modelName(model, task.model) ?? undefined }, Date.now())]
    .filter(Boolean)
    .join(" · ");
  const sublabel =
    task.kind === "terminal"
      ? [taskStatus(task).label, task.command !== task.title ? task.command : null].filter(Boolean).join(" · ")
      : waiting
        ? ["Needs you", meta].filter(Boolean).join(" · ")
        : meta;
  return (
    <div {...column} paddingLeft={depth * LEVEL}>
      <item id={`session-task-${task.id}`} label={task.title || nameOf(task)} sublabel={sublabel || undefined} sublabelTone={waiting ? "warning" : undefined} onClick={() => v.ctx.run(v.controller.openSubagent(chat, task.id))}>
          <slot name="leading">{mark(AGENT_MARK[status as keyof typeof AGENT_MARK])}</slot>
          {task.workflow ? <icon name="workflow" small tone="muted" /> : task.kind === "terminal" ? <icon name="square-terminal" small tone="muted" /> : agentMark(v, chat)}
        </item>
    </div>
  );
}

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.