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

views/panes.tsx15 KB
// Panes rendering preserves the chat's retained tree and interaction keys.
import { VISIBLE, reconcile as reconcileCycle, visible } from "../switcher.ts";
import type { Chat, Element } from "divergence";
import { registeredPane } from "../state.ts";
import type { Pane } from "../state.ts";
import type { ChatView } from "../controller.ts";
import { renderTranscript, reading } from "./rows.tsx";
import {
  dock,
  landingChips,
  landingHeadline,
  renderComposer,
  renderLanding,
  risingFrom,
  stageLook,
  stageTop,
} from "./composer.tsx";
import { column, row, fill, full } from "./styles.tsx";
import { panesOf } from "../layout.ts";
import type { PresentationLayout } from "../layout.ts";
import type { Task } from "divergence/protocol";

/** A chat row's one pane. */
const taskPane = (task: Task) => panesOf(task.layout.root)[0] ?? null;
import { drawsPanes, dropPreview, paneDrop, renderTaskCenter } from "./layout.tsx";
import { measureRoom, roomOf } from "./room.tsx";
import { newChat } from "./title.tsx";
import { NEW_CHAT } from "../shortcuts.ts";
export function switcherRow(v: ChatView, id: string, chosen: boolean): Element | null {
  const chat = v.controller.state.chats[id];
  if (!chat) return null;
  const workspace = v.controller.state.workspaces[chat.workspaceId]?.name ?? "";
  return (
    <item
      id={`switch-${id}`}
      label={v.controller.titleOf(chat)}
      sublabel={workspace || undefined}
      selected={chosen}
      busy={v.controller.isRunning(chat)}
      icon="bot"
      iconSvg={v.controller.state.agents[chat.agentId]?.icon}
      onClick={() => {
        v.controller.state.switcher = { list: [id], selected: id, input: "overlay" };
        v.ctx.run(v.controller.commitSwitcher());
      }}
    />
  );
}

export function renderSwitcher(v: ChatView): Element | null {
  // The list is checked against the chats the app still has: one closed
  // while the cycle is open must not leave a row behind.
  const open = reconcileCycle(v.controller.state.switcher, v.controller.state.chats);
  v.controller.state.switcher = open;
  const { rows } = open ? visible(open.list, open.selected, VISIBLE) : { rows: [] };
  const keys = {
    up: () => v.controller.switchBy(-1),
    left: () => v.controller.switchBy(-1),
    down: () => v.controller.switchBy(1),
    right: () => v.controller.switchBy(1),
    enter: () => v.ctx.run(v.controller.commitSwitcher()),
    escape: v.controller.closeSwitcher,
  };
  // The overlay draws the card around the column; only the rows are ours.
  return (
    <overlay
      id="chat-switcher"
      open={!!open}
      width={544}
      hold="ctrl"
      onRelease={() => {
        if (v.controller.state.switcher?.input === "overlay") v.ctx.run(v.controller.commitSwitcher());
      }}
      onDismiss={() => {
        if (v.controller.state.switcher?.input === "overlay") v.controller.closeSwitcher();
      }}
      keys={keys}
    >
      <div {...column} gap={2} padding="small">
        <div {...row} gap="small" padding="small" paddingX={8} paddingY={2}>
          <text style="section" size={9.84} weight={700} tone="muted">
            Recent chats
          </text>
        </div>
        {rows.map((id) => switcherRow(v, id, id === open?.selected))}
      </div>
    </overlay>
  );
}

// How far above the prompt box the blur starts, and the backdrop under the
// composer: no blur at its top, 8px at the pane's edge; the fade reaches the
// pane's colour where the controls under the prompt box start.
const FOOTER_LEAD = 16;
const FOOTER_BACKDROP = { blur: [0, 8], fade: [0, 1.35] } as const;

// The transcript's top edge, under the tab: the rows scrolling up fade into
// the pane instead of being cut off on a hard line.
const TOP_FADE = (
  <div position="absolute" left={0} right={0} top={0} height={20} background={{ linearGradient: { angle: 180, stops: [["background", 0], ["background/0", 1]] } }} />
);

// The pane shows its chat, not a skeleton waiting for its rows.
export function paneReady(c: ChatView["controller"], chatId: string): boolean {
  const chat = c.state.chats[chatId];
  if (!chat) return false;
  const t = c.transcript(chatId);
  const submitting = c.state.composers[chatId]?.submitting;
  return t.snapshot.kind !== "unread" || t.items.length > 0 || !!submitting;
}

// One chat: the landing page while it is fresh, else its transcript with
// the composer floating over its bottom.
export function renderPane(v: ChatView, chatId: string): Element | null {
  const chat = v.controller.state.chats[chatId];
  if (!chat) return null;
  const t = v.controller.transcript(chat.id);
  const submitting = v.controller.state.composers[chat.id]?.submitting;
  const landing = !t.items.length && !t.running && !submitting && t.snapshot.kind === "ready";
  // The page on screen sending its prompt is a departure: the page's
  // background fades, its headline and chip ride down with the prompt box
  // as they fade, and the sent text rises into its message.
  const pane = registeredPane(v.controller.state.panes[chat.id]);
  if (pane) {
    if (pane.landing && !landing && submitting && v.controller.state.onScreen === chat.id) pane.departing = true;
    pane.landing = landing;
  }
  const departing = !landing && !!pane?.departing;
  // A narrow or short pane gives the chat small insets above and below; at its sides
  // the reading column keeps the same small room in every pane, about what the prompt
  // box has under it.
  const { compact } = roomOf(chat.id);
  const inset = compact ? 0 : "small";
  // The landing page draws its own composer.
  const composer = () => (
    <div {...column} gap="small" paddingTop={compact ? "small" : "medium"}>
      {reading([dock(chat, composerOf(v, chat), departing ? departingPage(v, chat) : [])])}
    </div>
  );
  // The transcript scrolls under the composer. Over its bottom, from a
  // little above the prompt box down to the pane's edge, the blur grows
  // row by row and the chat fades into the pane, gone before the controls
  // under the prompt box.
  const footer = () => (
    <div {...column} paddingTop={FOOTER_LEAD} backdrop={FOOTER_BACKDROP}>
      {composer()}
    </div>
  );
  const body = landing ? (
    renderLanding(v, chat, composerOf(v, chat))
  ) : (
    <div {...column} {...fill} {...full} paddingY={inset}>
      {t.snapshot.kind === "failed" ? reading([
        <div {...row} gap="small" paddingY="small" id={`transcript-error-${chat.id}`}>
          <text size="xs" tone="warning">{t.snapshot.error}</text>
          <button id={`transcript-retry-${chat.id}`} label="Retry" variant="ghost" small disabled={!!t.loading}
            onClick={() => {
              if (!t.loading) v.ctx.run(v.controller.loadTranscript(chat.id, { history: false }));
            }} />
        </div>,
      ]) : null}
      {t.snapshot.kind === "unread" && !t.items.length && !submitting
        ? [renderSkeleton(v), composer()]
        : <div {...column} {...fill} position="relative">{renderTranscript(v, chat, footer())}{TOP_FADE}</div>}
    </div>
  );
  // The landing page's stage runs to the pane's edges and draws its own
  // background; the transcript keeps the pane's inset, over grain.
  const grain = !landing && v.controller.api.settings.get("transcriptGrain") === true;
  return (
    <div
      {...column}
      {...fill}
      {...full}
      id={`pane-${chat.id}`}
      paddingY={landing ? undefined : inset}
      position="relative"
      grain={grain}
    >
      {landing ? null : measureRoom(v, chat.id)}
      {departing && pane ? fadingStage(v, pane) : null}
      {body}
    </div>
  );
}

// The page's headline and chip over the prompt box on its way down, where
// they sat above it on the page, taking no room; and, until the sent text
// has its message, where that text rises from.
function departingPage(v: ChatView, chat: Chat): (Element | null)[] {
  const fade = { to: { opacity: 0 }, duration: 160 };
  const t = v.controller.transcript(chat.id);
  const sent = t.items.some((item) => item.role === "user") || !!v.controller.composer(chat.id).outgoing?.preview;
  return [
    <div height={0} position="relative">
      <div
        {...column}
        position="absolute"
        left={0}
        right={0}
        bottom={0}
        gap={18.75}
        paddingBottom="small"
        alignItems="center"
      >
        {landingHeadline(v, chat, fade)}
        {landingChips(v, chat, fade)}
      </div>
    </div>,
    sent ? null : risingFrom(chat),
  ];
}

// The page's background, still running under the transcript as it fades;
// the departure ends with it. It fades as long as the prompt takes to rise
// into its place (the glide spring is within a pixel by 300 ms), so the two
// end together.
function fadingStage(v: ChatView, pane: Pane): Element {
  const { ambient, grain } = stageLook(v);
  const onDone = () => {
    pane.departing = false;
    pane.view.update();
  };
  return (
    <div
      id="landing-stage"
      position="absolute"
      left={0}
      right={0}
      top={0}
      bottom={0}
      background={grain ? undefined : "stage"}
      grain={grain}
      ambient={ambient}
      motion={{ to: { opacity: 0 }, duration: 300, onDone }}
    >
      {stageTop()}
    </div>
  );
}

// The chat's composer view, which renders on its own as the user types; a
// pane drawn without one (as the tests draw it) draws the composer itself.
function composerOf(v: ChatView, chat: Chat): Element | null {
  const view = registeredPane(v.controller.state.panes[chat.id])?.composer;
  return view ? <view view={view.id} fit /> : renderComposer(v, chat);
}

// The composer view of one chat.
export function renderComposerView(v: ChatView, chatId: string): Element | null {
  const chat = v.controller.state.chats[chatId];
  return chat ? renderComposer(v, chat) : null;
}

// A chat whose rows are on their way: the shapes of a conversation where
// they will be, in the same frame as the click, so the pane is never empty
// and nothing jumps when the rows come.
export function renderSkeleton(v: ChatView): Element {
  const line = (width: string) => <div width={width} height={9} borderRadius="sm" background="muted" />;
  const activity = (width: string) => <div width={width} height={22} borderRadius="sm" background="muted" />;
  return (
    <div {...column} {...fill} {...full} id="chat-skeleton" paddingY="large">
      {reading([
        <div {...row} justifyContent="end">
          <div width="46%" height={40} borderRadius="xl" background="muted" />
        </div>,
        <div {...column} gap={9} paddingY="medium">
          {["94%", "88%", "63%"].map(line)}
        </div>,
        <div {...column} gap="small">
          {["34%", "41%"].map(activity)}
        </div>,
        <div {...column} gap={9} paddingY="medium">
          {["91%", "76%"].map(line)}
        </div>,
      ])}
    </div>
  );
}

// The center with no chat selected: what to do next, with New chat's key.
function noChat(v: ChatView): Element {
  const key = v.controller.state.shortcuts.keys[NEW_CHAT];
  return (
    <div {...column} {...fill} {...full} id="center-empty" alignItems="center" justifyContent="center" gap="medium">
      <text style="heading" text="No chat open" />
      <div {...row} gap="small">
        <button id="center-new-chat" icon="plus" label="New chat" onClick={() => newChat(v)} />
        {key ? <text keys text={key} /> : null}
      </div>
    </div>
  );
}

// The skeleton where the pane will be, with the pane's own insets.
export const centerSkeleton = (v: ChatView) => (
  <div {...column} {...fill} {...full} paddingY="small">
    <div {...column} {...fill} {...full} paddingY="small">
      {renderSkeleton(v)}
    </div>
  </div>
);

// Three frames at 60 Hz: a chat ready sooner replaces the last one directly.
export const SKELETON_AFTER = 50;

function syncMainPrompt(v: ChatView, chatId: string | null): void {
  // Kept panes render only when their chat changes, so the panes that
  // gain and lose the main prompt box render now.
  const mainPrompt = chatId;
  const was = v.controller.state.mainPrompt;
  if (was !== mainPrompt) {
    v.controller.state.mainPrompt = mainPrompt;
    for (const chatId of [was, mainPrompt]) {
      const pane = chatId ? registeredPane(v.controller.state.panes[chatId]) : undefined;
      (pane?.composer ?? pane?.view)?.update();
    }
  }
}

// The dynamic fallback for a cold chat and an older host without native
// app-state selection.
export function renderCenter(v: ChatView): Element | null {
  const app = v.ctx.app;
  if (app.route !== "chat") {
    syncMainPrompt(v, null);
    return null;
  }
  if (!app.chatId) {
    return noChat(v);
  }
  const chat = v.controller.state.chats[app.chatId];
  if (!chat) return centerSkeleton(v);
  return renderChatCenter(v, chat.id, true, false);
}

/** A retained complete center for one navigation context. */
export function renderCenterPresentation(v: ChatView, chatId: string, layout?: PresentationLayout): Element {
  return renderChatCenter(v, chatId, v.ctx.app.route === "chat" && v.ctx.app.chatId === chatId, true, layout);
}

function renderChatCenter(v: ChatView, chatId: string, active: boolean, retained: boolean, layout?: PresentationLayout): Element {
  const chat = v.controller.state.chats[chatId];
  if (!chat) return centerSkeleton(v);
  if (active) syncMainPrompt(v, chatId);
  // A task of more than one chat draws its panes; a chat row draws as it
  // always has, one pane in the shell's own surface.
  const home = v.controller.state.layouts.homes[chat.id];
  const task = layout ? layout.task : home ? v.controller.state.layouts.tasks[home] : undefined;
  if (task && drawsPanes(v, task)) {
    if (active) v.controller.state.onScreen = chat.id;
    return renderTaskCenter(v, task, chat.id, retained ? chat.id : undefined, layout);
  }
  // The center keeps the chat it showed until the new one is ready, so a
  // switch is one step with nothing between. Only a chat that takes longer
  // than SKELETON_AFTER shows its skeleton; with no chat before, it shows
  // at once.
  const { state } = v.controller;
  const pane = registeredPane(state.panes[chat.id]);
  if (!active) {
    if (!pane?.ready) return centerSkeleton(v);
    return taskCenter(v, task, pane);
  }
  const before = state.onScreen && state.onScreen !== chat.id ? registeredPane(state.panes[state.onScreen]) : undefined;
  let shown = pane?.ready ? pane : undefined;
  if (!shown && before) {
    if (state.switching?.chatId !== chat.id) {
      state.switching = { chatId: chat.id, at: Date.now() };
      setTimeout(() => v.controller.center?.update(), SKELETON_AFTER);
    }
    if (Date.now() - state.switching.at < SKELETON_AFTER) shown = before;
  }
  if (!shown) return centerSkeleton(v);
  if (shown.chatId === chat.id) state.switching = null;
  state.onScreen = shown.chatId;
  return taskCenter(v, task, shown);
}

function taskCenter(v: ChatView, task: Task | undefined, shown: Pane): Element {
  // A chat dropped on the chat on screen joins its row: by an edge in a
  // pane of its own, in the middle as its next tab (document 4).
  const own = task ? taskPane(task) : null;
  if (!task || !own) return <view view={shown.view.id} />;
  return (
    <div {...column} {...fill} {...full} position="relative" drop={paneDrop(v, task, own)}>
      <view view={shown.view.id} />
      {dropPreview(own.id)}
    </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.