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

Permissions in 0.2.6

  • 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.Open the chat search from the search button, and 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 sidebar, and its top controls in the title strip after the sidebar toggleSlots: lefttitle

Files

archive.ts7.5 KB
// Archiving rows and chats, and the toast 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, Plugin } 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, nextOpenChat, rememberClosed, taskChats, taskOf, undoLabel } from "./sections.ts";

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;
  const { api } = yield* Plugin;
  // Rows brought back whose place in the list waits for the host to report them as they were.
  const returning = new Set<ArchivedRow>();
  yield* Effect.addFinalizer(() => Effect.sync(() => api.dismissToast?.("archive")));

  const showNotice = () => {
    if (state.undo.length) {
      api.toast?.("archive", undoLabel(state.undo), { label: "Undo", onClick: () => Effect.runPromise(undoArchive()) }, () => { state.undo = []; });
    } else {
      api.dismissToast?.("archive");
    }
  };

  // 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(() => {
          if (api.toast) {
            state.undo = [...state.undo, row];
            redraw();
            showNotice();
          }
          return Effect.void;
        }),
      );

  // Archiving the chat on screen moves the screen, as Close Chat does: to
  // another chat of its task when the task keeps its row, else to the next
  // open row below the archived one (`lead`), or the one above. Chosen
  // before the host is asked, while the row is still in the list.
  const successor = Effect.fn("Sidebar.successor")(function* (gone: readonly string[], lead: string) {
    const current = yield* app.state;
    if (!current.chatId || !gone.includes(current.chatId)) return undefined;
    const task = taskOf(state, current.chatId);
    const sibling = task ? taskChats(state, task).find((chat) => !gone.includes(chat.id)) : undefined;
    return sibling ?? nextOpenChat(state, lead);
  });
  const moveTo = (next: Chat | undefined) => (next ? app.select(next.id, next.workspaceId) : Effect.void);

  // 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. One that
  // Close Chat archives (`closing`) is remembered for Reopen Closed Chat too.
  const archive = Effect.fn("Sidebar.archive")(function* (chat: Chat, closing = false) {
    const row = isTaskRow(state, chat) ? archivedChild(state, chat) : archivedRow(state, chat);
    const next = yield* successor([chat.id], chat.id);
    yield* host
      .call("host/chats.update", { chatId: chat.id, archived: true })
      .pipe(
        offer(row),
        Effect.tap(() =>
          Effect.sync(() => {
            if (closing) rememberClosed(state, chat.id, row);
          }),
        ),
        Effect.andThen(moveTo(next)),
        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 chats = taskChats(state, state.tasks[taskId]!);
    const row = archivedRow(state, chats[0]!);
    const next = yield* successor(
      chats.map((chat) => chat.id),
      chats[0]!.id,
    );
    yield* host
      .call("host/tasks.archive", { taskId })
      .pipe(
        offer(row),
        Effect.andThen(moveTo(next)),
        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.
  // Its first chat as the host has it back, or null when it could not come back.
  const restore = (row: ArchivedRow): Effect.Effect<Chat | null> =>
    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();
      return back;
    }).pipe(
      Effect.catch((error: unknown) => {
        returning.delete(row);
        return notify.error(`Could not restore “${row.title}”: ${describe(error)}`).pipe(Effect.as(null));
      }),
    );

  // 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 = [];
    // What Undo brings back, Reopen Closed Chat has nothing left to do for.
    state.closed = state.closed.filter((closed) => !closed.row || !rows.includes(closed.row));
    redraw();
    for (const row of rows) yield* restore(row);
  });

  // Reopen Closed Chat on a row Close Chat archived: it leaves the notice and comes back.
  const bringBack = Effect.fn("Sidebar.bringBack")(function* (row: ArchivedRow) {
    if (state.undo.includes(row)) {
      state.undo = state.undo.filter((offered) => offered !== row);
      redraw();
      showNotice();
    }
    return yield* restore(row);
  });

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

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.