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

sections.test.ts25.5 KB
// The sidebar's list rules, without a window: real imports of the pure
// model.
import assert from "node:assert/strict";
import test from "node:test";
import type { Chat } from "divergence";
import type { Task } from "divergence/protocol";
import {
  applyAgentEvent,
  applyChatChange,
  applyChatRemoved,
  applyTranscriptReset,
  archivedChild,
  archivedRow,
  canPlace,
  chatStatus,
  dragOver,
  dropDragged,
  endDrag,
  elapsed,
  initialState,
  listedChats,
  matches,
  prunePlaced,
  recentAgent,
  sectionOf,
  sections,
  togglePinned,
  undoLabel,
  visibleChats,
  stillWorking,
  completedOf,
  noteTask,
  workspaceLooks,
  workspaceMarkOf,
} from "./sections.ts";
import type { Over, SidebarState } from "./sections.ts";

/** A chat's own task, as the host keeps one for every chat; `completedAt` checks it off. */
const task = (id: string, completedAt: string | null = null, chats: string[] = [id]): Task => ({
  id,
  layout: {
    root: { kind: "pane", id: `pane-${id}`, tabs: chats.map((chatId) => ({ kind: "chat" as const, chatId })), active: { kind: "chat", chatId: chats[0]! } },
    focused: `pane-${id}`,
  },
  completedAt,
  createdAt: "2026-01-01T00:00:00.000Z",
  updatedAt: "2026-01-01T00:00:00.000Z",
});
/** Checks a row off (or gives it an open task, with `null`). */
const checkOff = (state: SidebarState, id: string, at: string | null) => noteTask(state, task(id, at));

let n = 0;
const chat = (over: Partial<Chat> = {}): Chat => ({
  id: `chat-${++n}`,
  workspaceId: "ws",
  agentId: "agent",
  title: "Chat",
  createdAt: "2026-01-01T00:00:00.000Z",
  updatedAt: "2026-01-02T00:00:00.000Z",
  archived: false,
  options: {},
  status: "idle",
  ...over,
});

test("chat status ranks blocked first, then running, review, idle", () => {
  const state = initialState();
  state.finished = { r: Date.now() };
  assert.equal(chatStatus(state, { id: "a", status: "waiting_approval" }), "blocked");
  assert.equal(chatStatus(state, { id: "a", status: "waiting_question" }), "blocked");
  assert.equal(chatStatus(state, { id: "a", status: "running" }), "running");
  assert.equal(chatStatus(state, { id: "r", status: "idle", sessionId: "s" }), "review");
  assert.equal(chatStatus(state, { id: "x", status: "idle" }), "idle");
});

test("a chat whose background subagents still work stays running after its turn", () => {
  const state = initialState();
  state.subagents = {
    a: new Map([
      ["t1", "running"],
      ["t2", "completed"],
    ]),
  };
  assert.equal(chatStatus(state, { id: "a", status: "idle", sessionId: "s" }), "running");
  state.subagents.a?.set("t1", "completed");
  assert.equal(chatStatus(state, { id: "a", status: "idle", sessionId: "s" }), "idle");
});

test("a chat the host counts subagents or background commands for runs after its turn", () => {
  const state = initialState();
  const chat = (agents: number, commands: number) => ({ id: "a", status: "idle" as const, sessionId: "s", working: { agents, commands } });
  assert.equal(chatStatus(state, chat(0, 1)), "running", "a background command keeps the chat running");
  assert.equal(chatStatus(state, chat(1, 0)), "running", "so does a subagent");
  assert.equal(sectionOf(state, chat(1, 0)), "running", "a subagent at work keeps the chat in Running");
  assert.equal(sectionOf(state, chat(0, 1)), "open", "a chat whose agent is done shows where it would without its commands");
  state.finished.a = 1;
  assert.equal(sectionOf(state, chat(0, 1)), "finished", "a chat that finished a run shows in Finished while its commands run");
  assert.equal(chatStatus(state, chat(0, 1)), "running", "and keeps the spinner as its mark");
  delete state.finished.a;
  assert.equal(chatStatus(state, chat(0, 0)), "idle");
  // The host's count is the answer, even where this sidebar saw a subagent start and never end.
  state.subagents = { a: new Map([["t1", "running"]]) };
  assert.equal(chatStatus(state, chat(0, 0)), "idle");
  assert.deepEqual(stillWorking(state, { id: "a", status: "idle" }), { agents: 1, commands: 0 }, "an older host's chat falls back to them");
});

test("each chat shows in the section of its status", () => {
  const state = initialState();
  state.queued = new Set(["q"]);
  state.finished = { f: Date.now() };
  assert.equal(sectionOf(state, { id: "d", status: "idle" }), "drafts");
  assert.equal(sectionOf(state, { id: "q", status: "idle" }), "queued");
  assert.equal(sectionOf(state, { id: "b", status: "waiting_question", sessionId: "s" }), "needs-you");
  assert.equal(sectionOf(state, { id: "r", status: "running" }), "running", "a sent first prompt is no draft");
  state.starting = new Set(["s"]);
  assert.equal(sectionOf(state, { id: "s", status: "idle" }), "running", "nor is one the host has not reported yet");
  assert.equal(sectionOf(state, { id: "f", status: "idle", sessionId: "s" }), "finished");
  assert.equal(sectionOf(state, { id: "o", status: "idle", sessionId: "s" }), "open");
  checkOff(state, "c", "2026-01-01T00:00:00Z");
  assert.equal(sectionOf(state, { id: "c", status: "idle", sessionId: "s" }), "settled");
});

test("a chat checked off moves to Complete at once, whatever it was doing", () => {
  const state = initialState();
  state.finished.c = Date.now();
  checkOff(state, "c", "2026-01-01T00:00:00Z");
  assert.equal(sectionOf(state, { id: "c", status: "idle" as const, sessionId: "s" }), "settled");
});

test("sections leave empty ones out and put the newest checked off first", () => {
  const state = initialState();
  state.chats = [
    chat({ id: "old-done", sessionId: "s" }),
    chat({ id: "new-done", sessionId: "s" }),
    chat({ id: "open", sessionId: "s" }),
  ];
  checkOff(state, "old-done", "2026-01-01T00:00:00Z");
  checkOff(state, "new-done", "2026-02-01T00:00:00Z");
  assert.deepEqual(
    sections(state).map((s) => [s.id, s.chats.map((c) => c.id)]),
    [
      ["open", ["open"]],
      ["settled", ["new-done", "old-done"]],
    ],
  );
});

test("the list holds the workspace's chats, newest activity first, without archived ones", () => {
  const state = initialState();
  state.chats = [
    chat({ id: "old", updatedAt: "2026-01-01T00:00:00.000Z" }),
    chat({ id: "new", updatedAt: "2026-03-01T00:00:00.000Z" }),
    chat({ id: "archived", archived: true, updatedAt: "2026-04-01T00:00:00.000Z" }),
    chat({ id: "elsewhere", workspaceId: "other", updatedAt: "2026-02-01T00:00:00.000Z" }),
  ];
  assert.deepEqual(
    visibleChats(state).map((c) => c.id),
    ["new", "elsewhere", "old"],
  );
  state.filter = ["ws"];
  assert.deepEqual(
    visibleChats(state).map((c) => c.id),
    ["new", "old"],
  );
  state.filter = ["ws", "other"];
  assert.deepEqual(
    visibleChats(state).map((c) => c.id),
    ["new", "elsewhere", "old"],
  );
});

test("the search matches titles, a draft's typed title included", () => {
  const state = initialState();
  const draft = chat({ id: "d", title: "New Chat" });
  state.chats = [chat({ id: "a", title: "Fix the parser" }), draft];
  state.draftTitles = { d: "Parser tests" };
  state.query = "  PARSER ";
  assert.deepEqual(
    visibleChats(state).map((c) => c.id),
    ["a", "d"],
  );
  state.query = "missing";
  assert.equal(matches(state, draft), false);
});

test("the search is fuzzy and puts the best matches of a section first", () => {
  const state = initialState();
  state.chats = [
    chat({ id: "strewn", sessionId: "s", title: "Rename the output plugin", updatedAt: "2026-01-05T00:00:00.000Z" }),
    chat({ id: "starts", sessionId: "s", title: "Plugin search ranking", updatedAt: "2026-01-02T00:00:00.000Z" }),
    chat({ id: "initials", sessionId: "s", title: "Palette search", updatedAt: "2026-01-04T00:00:00.000Z" }),
    chat({ id: "none", sessionId: "s", title: "Fix the build", updatedAt: "2026-01-06T00:00:00.000Z" }),
  ];
  state.query = "plugin";
  assert.deepEqual(
    sections(state).flatMap((s) => s.chats.map((c) => c.id)),
    ["starts", "strewn"],
    "a title that starts with the query beats a newer one with it inside",
  );
  // Letters in order at word starts: "p" alette "s" earch.
  state.query = "ps";
  assert.deepEqual(
    sections(state).flatMap((s) => s.chats.map((c) => c.id)),
    ["initials", "starts"],
  );
});

// Every match used to show, unpaged: one letter in the search turned a
// list of 20 rows into hundreds, and the list took over a second to draw.
test("a search pages Complete like the list does, its best matches first", () => {
  const state = initialState();
  state.collapsed = { settled: true };
  state.chats = Array.from({ length: 40 }, (_, i) =>
    chat({
      id: `done-${i}`,
      sessionId: "s",
      title: i === 30 ? "Search the chats" : `Old chat ${i} about search`,
      updatedAt: `2026-01-${String(1 + (i % 28)).padStart(2, "0")}T00:00:00.000Z`,
    }),
  );
  for (const c of state.chats) checkOff(state, c.id, "2026-02-01T00:00:00.000Z");
  state.query = "search";
  const listed = listedChats(state);
  assert.equal(listed.length, 3, "a folded section shows its matches, a page of them (Complete's is three)");
  assert.equal(listed[0]!.id, "done-30");
  state.showAll = { settled: true };
  assert.equal(listedChats(state).length, 40);
});

test("event mutators keep chats and previews current", () => {
  const state = initialState();
  const c = chat({ id: "c" });
  applyChatChange(state, c);
  applyChatChange(state, { ...c, title: "Renamed" });
  assert.equal(state.chats[0]?.title, "Renamed");
  state.previews.c = { line: "x" } as SidebarState["previews"][string];
  applyTranscriptReset(state, "c");
  assert.equal("c" in state.previews, false);
  state.previews.c = { line: "x" } as SidebarState["previews"][string];
  applyChatRemoved(state, "c");
  assert.equal(state.chats.length, 0);
  assert.equal("c" in state.previews, false);
});

test("recentAgent follows the most recently touched enabled chat", () => {
  const state = initialState();
  state.agents = [
    { id: "a", name: "A" },
    { id: "b", name: "B" },
  ] as SidebarState["agents"];
  state.chats = [
    chat({ id: "old", agentId: "a", updatedAt: "2026-01-01T00:00:00.000Z" }),
    chat({ id: "new", agentId: "b", updatedAt: "2026-02-01T00:00:00.000Z" }),
    chat({ id: "disabled", agentId: "z", updatedAt: "2026-03-01T00:00:00.000Z" }),
  ];
  assert.equal(recentAgent(state, "ws"), "b");
});

test("elapsed renders short relative times", () => {
  const now = new Date("2026-01-02T00:00:00.000Z").getTime();
  assert.equal(elapsed(now, "2026-01-01T00:00:30.000Z"), "23h");
  assert.equal(elapsed(now, "2026-01-01T23:59:10.000Z"), "50s");
  assert.equal(elapsed(now, "2026-01-02T00:00:10.000Z"), "");
});

test("the chat service starts unfollowed, with an empty queue and no draft titles", () => {
  const state = initialState();
  assert.equal(state.chat, undefined);
  assert.equal(state.follow, undefined);
  assert.deepEqual([...state.queued], []);
  assert.deepEqual(state.draftTitles, {});
});

test("agent events redraw only when the visible line changes", () => {
  const state = initialState();
  assert.equal(
    applyAgentEvent(state, {
      event: "agent",
      chatId: "c",
      kind: { event: "task", id: "t1", title: "T", status: "running" },
    }),
    true,
  );
  assert.equal(
    applyAgentEvent(state, {
      event: "agent",
      chatId: "c",
      kind: { event: "task", id: "t1", title: "T", status: "running" },
    }),
    false,
  );
  // A subagent's own turn is not the chat's line.
  assert.equal(
    applyAgentEvent(state, {
      event: "agent",
      chatId: "c",
      taskId: "t1",
      kind: { event: "text_delta", itemId: "a", text: "hi", mode: "append" },
    }),
    false,
  );
  assert.equal(
    applyAgentEvent(state, {
      event: "agent",
      chatId: "c",
      kind: { event: "text_delta", itemId: "a", text: "hello", mode: "append" },
    }),
    true,
  );
  assert.equal(
    applyAgentEvent(state, {
      event: "agent",
      chatId: "c",
      kind: { event: "run_finished", outcome: { status: "completed" } },
    }),
    true,
  );
});

test("an older host's task events count the subagents a chat runs, not its background commands", () => {
  const state = initialState();
  const task = (id: string, kind?: "agent" | "terminal") =>
    applyAgentEvent(state, {
      event: "agent",
      chatId: "c",
      kind: { event: "task", id, title: "T", status: "running", ...(kind ? { kind } : {}) },
    });
  const chat = { id: "c", status: "idle" as const };
  assert.equal(task("shell", "terminal"), false);
  assert.deepEqual(stillWorking(state, chat), { agents: 0, commands: 0 });
  assert.equal(task("agent"), true);
  assert.deepEqual(stillWorking(state, chat), { agents: 1, commands: 0 });
});

test("a workspace's mark is its icon, else its coloured folder, or the folder when chosen", () => {
  const base = { id: "w", name: "w", path: "/w", position: 0 };
  assert.deepEqual(workspaceMarkOf({ ...base, icon: "/w/icon.png", color: "teal" }), { image: "/w/icon.png" });
  assert.deepEqual(workspaceMarkOf({ ...base, icon: "/w/icon.png", color: "teal", useColor: true }), {
    icon: "folder-solid",
    color: "teal",
  });
  assert.deepEqual(workspaceMarkOf({ ...base, color: "pink" }), { icon: "folder-solid", color: "pink" });
  assert.deepEqual(workspaceMarkOf({ ...base, mark: "divergence" }), { icon: "divergence" });
  // An older host sends no colour: a plain folder.
  assert.deepEqual(workspaceMarkOf(base), { icon: "folder" });
  const looks = workspaceLooks({ ...base, icon: "/w/icon.png", color: "teal" }, ["blue", "teal"]);
  assert.equal(looks.value, "icon");
  assert.deepEqual(
    looks.options.map((option) => option.value),
    ["icon", "blue", "teal"],
  );
  assert.equal(workspaceLooks({ ...base, color: "teal" }, ["blue", "teal"]).value, "teal");
});

test("the listed chats run top to bottom: section order, folded sections out, paged sections a page", () => {
  const state = initialState();
  const drafts = Array.from({ length: 7 }, (_, i) => chat({ updatedAt: `2026-01-0${9 - i}T00:00:00.000Z` }));
  const running = chat({ status: "running", sessionId: "s1" });
  const open = chat({ sessionId: "s2", updatedAt: "2026-01-09T00:00:00.000Z" });
  const done = chat({ sessionId: "s3" });
  state.chats = [done, open, running, ...drafts];
  checkOff(state, done.id, "2026-01-03T00:00:00.000Z");
  const ids = () => listedChats(state).map((c) => c.id);
  assert.deepEqual(ids(), [...drafts.slice(0, 5), running, open, done].map((c) => c.id));
  state.showAll.drafts = true;
  assert.deepEqual(ids(), [...drafts, running, open, done].map((c) => c.id));
  state.collapsed.drafts = true;
  assert.deepEqual(ids(), [running, open, done].map((c) => c.id));
});

test("a chat whose turn failed shows failed, not finished, in Finished", () => {
  const state = initialState();
  const failed = chat({ sessionId: "s", status: "failed" });
  state.finished[failed.id] = Date.now();
  assert.equal(chatStatus(state, failed), "failed");
  assert.equal(sectionOf(state, failed), "finished");
  assert.equal(chatStatus(state, { ...failed, status: "running" }), "running", "a new turn runs again");
});

// Drags the chat `id` over each of `overs` in turn and drops it, as an
// older kernel does: it tells only where the chat was dropped.
const drag = (state: SidebarState, id: string, ...overs: Over[]) => {
  for (const over of overs.slice(0, -1)) dragOver(state, id, over);
  return dropDragged(state, id, overs.at(-1));
};
const ids = (state: SidebarState, section: string) =>
  sections(state)
    .find((s) => s.id === section)
    ?.chats.map((c) => c.id);

test("a chat dragged in its section stays where it was put, even as its neighbours get newer", () => {
  const state = initialState();
  const at = (day: number) => `2026-01-0${day}T00:00:00.000Z`;
  state.chats = [1, 2, 3, 4].map((day) => chat({ id: `c${day}`, sessionId: "s", updatedAt: at(day) }));
  assert.deepEqual(ids(state, "open"), ["c4", "c3", "c2", "c1"]);
  assert.deepEqual(drag(state, "c1", { row: "c4", zone: "before" }), { completed: undefined });
  assert.deepEqual(ids(state, "open"), ["c1", "c4", "c3", "c2"]);
  drag(state, "c4", { row: "c2", zone: "after" });
  assert.deepEqual(ids(state, "open"), ["c1", "c3", "c2", "c4"]);
  // A kernel without `reorder` reports `into`: the chat takes the other's place.
  drag(state, "c2", { row: "c1", zone: "into" });
  assert.deepEqual(ids(state, "open"), ["c2", "c1", "c3", "c4"]);
  // A neighbour's new activity does not move it past the chat put there.
  applyChatChange(state, { ...state.chats.find((c) => c.id === "c4")!, updatedAt: "2026-02-01T00:00:00.000Z" });
  assert.deepEqual(ids(state, "open"), ["c2", "c1", "c3", "c4"]);
  // A chat new to the section comes in at the top.
  state.chats.push(chat({ id: "new", sessionId: "s", updatedAt: new Date(Date.now() + 1000).toISOString() }));
  assert.deepEqual(ids(state, "open"), ["new", "c2", "c1", "c3", "c4"]);
  // Dropped where it already is, nothing moves.
  assert.equal(drag(state, "c1", { row: "c2", zone: "after" }), null);
  // A chat that starts running leaves Open; its place there is forgotten.
  applyChatChange(state, { ...state.chats.find((c) => c.id === "c2")!, status: "running" });
  assert.equal(prunePlaced(state), true);
  assert.equal(state.placed["c2"], undefined);
  assert.equal(prunePlaced(state), false);
});

test("while a chat is dragged its place follows the pointer and the sections it may land in show", () => {
  const state = initialState();
  state.chats = [chat({ id: "a", sessionId: "s" }), chat({ id: "b", sessionId: "s" }), chat({ id: "r", sessionId: "s", status: "running" })];
  assert.deepEqual(
    sections(state).map((s) => s.id),
    ["running", "open"],
  );
  dragOver(state, "a", { row: "a", zone: "before" });
  // Pinned, Finished and Complete show, empty, to drop into; Running does not take an idle chat.
  assert.deepEqual(
    sections(state).map((s) => s.id),
    ["pinned", "running", "finished", "open", "settled"],
  );
  assert.equal(dragOver(state, "a", { row: "r", zone: "after" }), false);
  assert.equal(dragOver(state, "a", { heading: "pinned" }), true);
  assert.deepEqual(ids(state, "pinned"), ["a"]);
  assert.deepEqual(ids(state, "open"), ["b"]);
  // Off the list it goes back where it was, and a drag let go there lands nowhere.
  assert.equal(dragOver(state, "a", { inside: false }), true);
  assert.deepEqual(ids(state, "open"), ["a", "b"]);
  assert.equal(endDrag(state), true);
  assert.deepEqual(
    sections(state).map((s) => s.id),
    ["running", "open"],
  );
  assert.deepEqual(state.placed, {});
});

test("dragging a chat to another section changes its state", () => {
  const state = initialState();
  const open = chat({ id: "o", sessionId: "s" });
  const done = chat({ id: "d", sessionId: "s" });
  const failed = chat({ id: "f", sessionId: "s", status: "failed" });
  const reviewed = chat({ id: "v", sessionId: "s" });
  state.finished[reviewed.id] = Date.now();
  state.chats = [open, done, failed, reviewed];
  for (const c of state.chats) checkOff(state, c.id, c.id === "d" ? "2026-01-03T00:00:00.000Z" : null);
  // To Pinned: pinned, above Running, whatever it does next.
  assert.deepEqual(drag(state, "o", { heading: "pinned" }), { completed: undefined });
  assert.equal(sectionOf(state, state.chats[0]!), "pinned");
  applyChatChange(state, { ...state.chats[0]!, status: "running" });
  assert.equal(prunePlaced(state), false);
  assert.equal(sectionOf(state, state.chats[0]!), "pinned");
  // To Complete: checked off, and the pin is gone.
  assert.deepEqual(drag(state, "o", { row: "d", zone: "before" }), { completed: true });
  assert.ok(completedOf(state, { id: "o" }));
  assert.deepEqual(ids(state, "settled"), ["o", "d"]);
  // Out of Complete: opened again.
  assert.deepEqual(drag(state, "d", { heading: "open" }), { completed: false });
  assert.equal(completedOf(state, { id: "d" }), undefined);
  assert.equal(sectionOf(state, state.chats.find((c) => c.id === "d")!), "open");
  // Finished to Open: a finished chat is seen; a failed one stays in Open until it runs again.
  drag(state, "v", { heading: "open" });
  assert.equal(state.finished["v"], undefined);
  drag(state, "f", { heading: "open" });
  assert.equal(sectionOf(state, failed), "open");
  // Open to Finished, until it runs again.
  drag(state, "d", { heading: "finished" });
  assert.equal(sectionOf(state, state.chats.find((c) => c.id === "d")!), "finished");
  applyChatChange(state, { ...state.chats.find((c) => c.id === "d")!, status: "running" });
  prunePlaced(state);
  applyChatChange(state, { ...state.chats.find((c) => c.id === "d")!, status: "idle" });
  assert.equal(sectionOf(state, state.chats.find((c) => c.id === "d")!), "open");
});

test("sections a drag shows above the chat push the list under the pointer without moving the chat", () => {
  const state = initialState();
  state.chats = [chat({ id: "a", sessionId: "s" }), chat({ id: "b", sessionId: "s" })];
  // The pointer is on b, the lower row; Pinned, Finished and Complete show.
  assert.equal(dragOver(state, "b", { row: "b", zone: "after" }), true);
  // Pinned and Finished pushed the rows down: the pointer is on a now,
  // though it did not move.
  assert.equal(dragOver(state, "b", { row: "a", zone: "before" }), false);
  assert.deepEqual(ids(state, "open"), ["a", "b"]);
  // A move of the user's own does move it.
  assert.equal(dragOver(state, "b", { row: "a", zone: "after" }), false, "after a is where b is");
  assert.equal(dragOver(state, "b", { row: "a", zone: "before" }), true);
  assert.deepEqual(ids(state, "open"), ["b", "a"]);
});

test("a pin survives the moment a just-sent chat shows among the drafts", () => {
  const state = initialState();
  const sent = chat({ id: "s" });
  state.chats = [sent];
  state.starting = new Set(["s"]);
  togglePinned(state, sent);
  assert.equal(sectionOf(state, sent), "pinned");
  // The send ended before the host reported the run.
  state.starting = new Set();
  assert.equal(sectionOf(state, sent), "drafts");
  assert.equal(prunePlaced(state), false);
  applyChatChange(state, { ...sent, status: "running", sessionId: "x" });
  assert.equal(sectionOf(state, state.chats[0]!), "pinned");
  // Checked off, the pin goes.
  checkOff(state, state.chats[0]!.id, "2026-01-03T00:00:00.000Z");
  assert.equal(prunePlaced(state), true);
});

test("a running chat can be pinned or checked off, but not moved to Open or Finished", () => {
  const state = initialState();
  state.chats = [chat({ id: "r", sessionId: "s", status: "running" }), chat({ id: "o", sessionId: "s" })];
  dragOver(state, "r", { row: "o", zone: "before" });
  assert.deepEqual(ids(state, "running"), ["r"]);
  assert.equal(dropDragged(state, "r"), null);
});

test("a draft moves only among the drafts", () => {
  const state = initialState();
  state.chats = [chat({ id: "d1" }), chat({ id: "d2" }), chat({ id: "o", sessionId: "s" })];
  assert.equal(drag(state, "d1", { heading: "pinned" }), null);
  assert.equal(drag(state, "d2", { row: "o", zone: "before" }), null);
  assert.deepEqual(drag(state, "d2", { row: "d1", zone: "before" }), { completed: undefined });
});

test("the pin button pins a chat at the top of Pinned and unpins it back", () => {
  const state = initialState();
  const a = chat({ id: "a", sessionId: "s" });
  const b = chat({ id: "b", sessionId: "s" });
  state.chats = [a, b];
  togglePinned(state, a);
  assert.deepEqual(
    sections(state).map((s) => s.id),
    ["pinned", "open"],
  );
  togglePinned(state, b);
  assert.deepEqual(ids(state, "pinned"), ["b", "a"]);
  togglePinned(state, a);
  assert.deepEqual(ids(state, "open"), ["a"]);
});

test("queued chats keep the queue's order and cannot be dragged", () => {
  const state = initialState();
  state.chats = [chat({ id: "q1" }), chat({ id: "q2" })];
  state.queued = new Set(["q1", "q2"]);
  assert.equal(canPlace("queued"), false);
  assert.equal(drag(state, "q1", { row: "q2", zone: "after" }), null);
});

test("an archived row keeps where it was: its section and rank, a pin, its check and its task's chats and name", () => {
  const state = initialState();
  const newer = chat({ id: "n", sessionId: "s", updatedAt: "2026-01-03T00:00:00.000Z" });
  const older = chat({ id: "o", sessionId: "s", updatedAt: "2026-01-02T00:00:00.000Z", title: "Older" });
  const done = chat({ id: "d", sessionId: "s" });
  const lead = chat({ id: "a", sessionId: "s", title: "Plan" });
  const member = chat({ id: "b", sessionId: "s", title: "Build" });
  state.chats = [newer, older, done, lead, member];
  for (const id of ["n", "o"]) checkOff(state, id, null);
  checkOff(state, "d", "2026-01-05T00:00:00.000Z");
  noteTask(state, { ...task("t", null, ["a", "b"]), title: "Release" });
  // An open chat keeps its rank there, which coming back would otherwise change.
  assert.deepEqual(archivedRow(state, older), {
    title: "Older",
    chatIds: ["o"],
    name: null,
    completed: false,
    queued: false,
    placed: { section: "open", rank: Date.parse(older.updatedAt) },
    from: null,
  });
  // A checked-off one keeps when it was checked off, and a pin is the user's own place.
  assert.deepEqual(archivedRow(state, done).placed, { section: "settled", rank: Date.parse("2026-01-05T00:00:00.000Z") });
  assert.equal(archivedRow(state, done).completed, true);
  togglePinned(state, newer);
  assert.deepEqual(archivedRow(state, newer).placed, state.placed["n"]);
  // A task row takes its chats and its name; one of its chats alone, its tab's place.
  assert.deepEqual(archivedRow(state, lead).chatIds, ["a", "b"]);
  assert.equal(archivedRow(state, lead).name, "Release");
  assert.deepEqual(archivedChild(state, member).from, { taskId: "t", paneId: "pane-t", index: 1 });
  assert.equal(archivedChild(state, member).placed, null);
  // The notice names one row, and counts the chats of several.
  assert.equal(undoLabel([archivedRow(state, older)]), "Archived “Older”");
  assert.equal(undoLabel([archivedRow(state, older), archivedRow(state, lead)]), "Archived 3 chats");
});

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.