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

Permissions in 0.2.7

  • 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

next-chat.ts5.3 KB
// The draft ⌘N opens next, declared to the kernel as the command's action
// so that the key shows the new chat on its own frame instead of after a
// trip through this plugin, the host and the chat plugin. The host makes it
// ahead (`host/chats.reserve`, which keeps it out of the lists until
// `host/chats.create` opens it) and the chat plugin builds its page. It is
// asked for again when the workspace, the agent or the drafts in use change,
// or once the draft has stopped being an untouched draft. A host without the
// method leaves the command to its handler.
import * as Effect from "effect/Effect";
import { Host, Plugin } from "divergence/effect";
import type { Chat } from "divergence";
import { isDraft, recentAgent } from "./sections.ts";
import type { SidebarState } from "./sections.ts";
import { isUnknownMethod } from "./peek.ts";

// The title the host gives a chat until its first prompt names it.
const NEW_CHAT = "New Chat";

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

// A draft with typed text, a place in the queue or a prompt on its way to
// the host (one that waits for the chat to be ready included) is in use: New
// chat from it opens another draft rather than the same one. The chat
// plugin's events say which, as they happen; New chat never waits on it, so
// a busy chat plugin cannot hold the new chat up.
export const chatsInUse = (state: SidebarState): string[] => [...Object.keys(state.draftTitles), ...state.queued, ...state.starting];

// New chat's workspace: the one the picker shows alone, the app's, or the first.
export const newChatWorkspace = (state: SidebarState, workspaceId: string | null | undefined): string | null =>
  (state.filter.length === 1 ? state.filter[0] : undefined) ?? workspaceId ?? state.workspaces[0]?.id ?? null;

// New chat's agent: the one worked with last in the workspace, else the last chosen, else the first.
export const newChatAgent = (state: SidebarState, workspaceId: string): string | undefined =>
  recentAgent(state, workspaceId) ?? state.lastAgent ?? state.agents[0]?.id;

type Target = { workspaceId: string; agentId: string; inUse: string[] };

export const makeNextChat = Effect.fn("Sidebar.nextChat")(function* (state: SidebarState) {
  const host = yield* Host;
  const plugin = yield* Plugin;
  const scope = yield* Effect.scope;
  let next: { key: string; chat: Chat | null; listed: boolean } | null = null;
  let missing = false;
  const target = (): Target | null => {
    const workspaceId = newChatWorkspace(state, plugin.api.app.state().workspaceId);
    const agentId = workspaceId && newChatAgent(state, workspaceId);
    return workspaceId && agentId ? { workspaceId, agentId, inUse: chatsInUse(state) } : null;
  };
  // Still the draft New chat opens: not yet listed, or listed and untouched.
  const usable = (current: NonNullable<typeof next>): boolean => {
    if (!current.chat) return true;
    const listed = state.chats.find((chat) => chat.id === current.chat?.id);
    if (!listed) return !current.listed;
    current.listed = true;
    return !listed.archived && listed.title === NEW_CHAT && isDraft(state, listed);
  };
  // The key points at the draft only once the chat plugin can show its page
  // natively: an action declared earlier would switch to a page that is not
  // built yet, and the center would wait on the chat plugin and show a skeleton.
  const reserve = Effect.fn("Sidebar.reserveNewChat")(function* (wanted: Target, key: string) {
    const chat = yield* host.call("host/chats.reserve", wanted).pipe(
      Effect.catchIf(isUnknownMethod, () => Effect.sync(() => void (missing = true))),
      Effect.catch((error: unknown) => Effect.logWarning(`Could not ready the next new chat: ${describe(error)}`)),
    );
    if (!chat || !state.chat || next?.key !== key) return;
    const built = yield* state.chat.prepareNewChat({ chat }).pipe(
      Effect.as(true),
      Effect.catch((error: unknown) => Effect.logWarning(`The chat plugin could not build the next new chat ahead: ${describe(error)}`).pipe(Effect.as(false))),
    );
    if (!built || next?.key !== key) return;
    if (next.chat?.id !== chat.id) next.listed = false;
    next.chat = chat;
    plugin.api.commandAction?.("sidebar.newChat", { chatId: chat.id, workspaceId: chat.workspaceId, route: "chat", shared: { selectedChat: chat } });
  });
  return (): void => {
    if (missing || typeof plugin.api?.commandAction !== "function") return;
    const wanted = target();
    const key = wanted ? `${wanted.workspaceId}\n${wanted.agentId}\n${wanted.inUse.join(",")}` : "";
    if (next?.key === key && usable(next)) return;
    // A declared draft New chat may still open keeps the key while the next
    // one is asked for, so a change elsewhere (another chat's prompt or
    // queue) never leaves the key without a page.
    const declared = next?.chat;
    const kept =
      declared && wanted && next && declared.workspaceId === wanted.workspaceId && declared.agentId === wanted.agentId && !wanted.inUse.includes(declared.id) && usable(next)
        ? next
        : null;
    if (!kept) plugin.api.commandAction("sidebar.newChat", null);
    next = { key, chat: kept?.chat ?? null, listed: kept?.listed ?? false };
    if (wanted) Effect.runFork(Effect.forkIn(reserve(wanted, key), scope, { startImmediately: true }));
  };
});

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.