Official

sidebar

Built-in sidebar 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/sidebar@0.2.4

Permissions in 0.2.4

  • Control chats chats.controlHighCreates chats, sends prompts and cancels runs.Add and remove workspaces, and create, rename, check off and archive chats
  • Run other plugins' commands commands.runHighRuns commands of other plugins.Close the tab on screen with Cmd+W when its chat is part of a task
  • Read chats chats.readMediumReads your transcripts and chat lists.List workspaces and chats, and follow them as agents work
  • Show panels ui.slotsAlways grantedShows views in the listed parts of the window.Draw the sidebarSlots: left

Files

archive.ts5.6 KB
// Archiving rows and chats, and the notice at the foot of the list that
// offers them back for a few seconds (Undo): the chats come out of the
// archive into the task they were in, checked off and named as they were,
// and the row takes its old place in its section once the host reports it
// back as it was.
import * as Effect from "effect/Effect";
import { App, Host, Notify } from "divergence/effect";
import type { HostError } from "divergence/effect";
import type { Chat } from "divergence";
import type { PlaceTarget } from "divergence/protocol";
import type { ArchivedRow, SidebarState } from "./sections.ts";
import { archivedChild, archivedRow, hasPane, isBack, isTaskRow, taskChats } from "./sections.ts";

/** How long the notice offers Undo while the pointer is not on it. */
export const UNDO_MS = 5000;

const describe = (error: unknown): string => (error instanceof Error && error.message ? error.message : "unknown error");

export const makeArchive = Effect.fn("Sidebar.archiving")(function* (
  state: SidebarState,
  redraw: () => void,
  savePlaced: () => Effect.Effect<void>,
) {
  const host = yield* Host;
  const app = yield* App;
  const notify = yield* Notify;
  // Rows brought back whose place in the list waits for the host to report them as they were.
  const returning = new Set<ArchivedRow>();
  let timer: ReturnType<typeof setTimeout> | undefined;
  yield* Effect.addFinalizer(() => Effect.sync(() => clearTimeout(timer)));

  // The notice goes once its time is up, and the pointer on it holds it.
  const holdNotice = (held: boolean): Effect.Effect<void> =>
    Effect.sync(() => {
      clearTimeout(timer);
      if (held || !state.undo.length) return;
      timer = setTimeout(() => {
        state.undo = [];
        redraw();
      }, UNDO_MS);
    });

  // Once the host took a row away, the notice offers it back, after the rows it offers already.
  const offer =
    (row: ArchivedRow) =>
    (archived: Effect.Effect<unknown, HostError>): Effect.Effect<void, HostError> =>
      archived.pipe(
        Effect.andThen(() => {
          state.undo = [...state.undo, row];
          redraw();
          return holdNotice(false);
        }),
      );

  // An archived chat leaves the list and its transcript stays with the host. A chat
  // archived out of a task of several leaves the task, which keeps its row.
  const archive = Effect.fn("Sidebar.archive")(function* (chat: Chat) {
    const row = isTaskRow(state, chat) ? archivedChild(state, chat) : archivedRow(state, chat);
    yield* host
      .call("host/chats.update", { chatId: chat.id, archived: true })
      .pipe(offer(row), Effect.catch((error: unknown) => notify.error(`Could not archive the chat: ${describe(error)}`)));
  });

  // Archiving a task row archives every chat in it, and the row leaves the list.
  const archiveTask = Effect.fn("Sidebar.archiveTask")(function* (taskId: string) {
    const row = archivedRow(state, taskChats(state, state.tasks[taskId]!)[0]!);
    yield* host
      .call("host/tasks.archive", { taskId })
      .pipe(offer(row), Effect.catch((error: unknown) => notify.error(`Could not archive the task: ${describe(error)}`)));
  });

  // A row brought back takes its old place in its section once the host reports it as it was.
  const land = Effect.fn("Sidebar.land")(function* () {
    let landed = false;
    for (const row of returning) {
      if (!isBack(state, row)) continue;
      returning.delete(row);
      state.placed[row.chatIds[0]!] = row.placed!;
      landed = true;
    }
    if (!landed) return;
    redraw();
    yield* savePlaced();
  });

  // One row out of the archive: its first chat comes back as a row of its own, checked off
  // as it was; the others join it, or it goes back to its tab's place in the task it left.
  const restore = (row: ArchivedRow): Effect.Effect<void> =>
    Effect.gen(function* () {
      const [lead, ...others] = row.chatIds as [string, ...string[]];
      if (row.placed) returning.add(row);
      const back = yield* host.call("host/chats.update", { chatId: lead, archived: false, ...(row.completed ? { completed: true } : {}) });
      const current = yield* app.state;
      const onScreen = current.chatId ? (state.homes[current.chatId] ?? null) : null;
      const place = (chatId: string, target: PlaceTarget) =>
        host.call("host/layouts.place", { tab: { kind: "chat", chatId }, target, onScreen });
      for (const chatId of others) {
        yield* host.call("host/chats.update", { chatId, archived: false });
        yield* place(chatId, { kind: "join", taskId: back.task! });
      }
      const task = row.from ? state.tasks[row.from.taskId] : undefined;
      if (row.from && task)
        yield* place(lead, hasPane(task.layout.root, row.from.paneId) ? { kind: "strip", paneId: row.from.paneId, index: row.from.index } : { kind: "join", taskId: task.id });
      const home = row.from ? task?.id : back.task;
      if (row.name && home && state.tasks[home]?.title !== row.name) yield* host.call("host/tasks.update", { taskId: home, title: row.name });
      if (row.queued && state.chat) yield* state.chat.submitDraft({ chatId: lead, queue: true });
      yield* land();
    }).pipe(
      Effect.catch((error: unknown) => {
        returning.delete(row);
        return notify.error(`Could not restore “${row.title}”: ${describe(error)}`);
      }),
    );

  // Undo: every row the notice offers comes back, and the notice goes.
  const undoArchive = Effect.fn("Sidebar.undoArchive")(function* () {
    const rows = state.undo;
    state.undo = [];
    clearTimeout(timer);
    redraw();
    for (const row of rows) yield* restore(row);
  });

  return { archive, archiveTask, land, holdNotice, undoArchive };
});

Versions

VersionPublishedPlugin APISizePermissionsStatus
0.2.7latestNov 21, 2026>=5 <6100.9 KB4 permissionsListed
0.2.6Nov 16, 2026>=5 <6100.6 KB4 permissionsListed
0.2.5Nov 11, 2026>=5 <665.1 KB4 permissionsListed
0.2.4Nov 9, 2026>=5 <660.4 KB4 permissionsListed
0.2.3Oct 27, 2026>=2 <426.1 KB3 permissionsListed

Reviews and comments

0 threads · 0 reviews

No comments yet.