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

Permissions in 0.2.5

  • 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

views/session.ts8.8 KB
// The Session panel of the right rail: the chat open in the center, its
// context window, the account's usage limits and its subagents. 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 { html } from "divergence";
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 } from "../subagents.ts";
import { displayStatus, modelName } from "../workflows.ts";
import { ago, optionLabel, pinned, sessionOpen, statusOf, when, working } from "../session.ts";
import { contextDetails, limitRow, limitsNote } from "./usage.ts";
import { mark } from "./tasks.ts";
import { AGENT_MARK, column, fill, full, markIcon, markOf, row } from "./styles.ts";

// 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(v.controller.state.transcripts[chat.id]?.items ?? []) : 0;
  return html`
    <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 html`
    <div ...${column} ...${fill} ...${full} padding="small" paddingX="small">
      <div ...${row} gap="small" padding="small" paddingY="small">
        <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
          ? html`
          <div ...${column} ...${fill} gap="medium" padding="small" overflowY="scroll">
            ${sessionSection(v, chat)}
            ${contextSection(v, chat)}
            ${limitsSection(v, chat)}
            ${subagentsSection(v, chat)}
          </div>`
          : html`<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
    ? html`<item heading id=${`session-${id}`} label=${label}><text style="body" size=${9.84} tone="muted">${String(count)}</text></item>`
    : html`<item heading id=${`session-${id}`} label=${label} />`;
  return html`<div ...${column} gap=${2}>${heading}${body}</div>`;
}

// One muted line where a section has nothing to show.
const note = (text: string) =>
  html`<div ...${row} paddingX=${INSET} paddingY=${3}><text style="small" tone="muted">${text}</text></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 html`
    <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) => html`<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(c.state.transcripts[chat.id]?.items ?? []).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", [html`<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 ? html`<spinner activity />` : html`<icon name="circle" small tone=${status.tone} />`,
      plain(status.label),
    ]),
    sessionId
      ? field(
          "id",
          "Session id",
          [html`<text style="mono" size="xs" truncate>${sessionId}</text>`],
          html`<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,
  ]);
}

function contextSection(v: ChatView, chat: Chat): Element {
  const usage = v.controller.state.transcripts[chat.id]?.usage;
  return section("context", "Context window", [
    usage?.contextWindow
      ? html`<div ...${column} paddingX=${INSET} paddingY=${4}>${contextDetails(usage)}</div>`
      : note("The agent has not reported its context window yet."),
  ]);
}

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

function subagentsSection(v: ChatView, chat: Chat): Element {
  const rows = allTasks(v.controller.state.transcripts[chat.id]?.items ?? []).sort(
    (a, b) => Number(isLive(b.task)) - Number(isLive(a.task)),
  );
  const model = v.controller.state.composers[chat.id]?.options.find((option) => option.category === "model");
  return section(
    "subagents",
    "Tasks",
    rows.length ? rows.map((taskRow) => subagentRow(v, chat, taskRow, model)) : [note("No tasks in this chat.")],
    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 html`
    <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(v, AGENT_MARK[status as keyof typeof AGENT_MARK])}</slot>
        ${task.workflow ? html`<icon name="workflow" small tone="muted" />` : null}
      </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.