Official

tabs

The tabbed detail pane beside the chat: files to edit and diffs (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/tabs@0.2.6

Permissions in 0.2.6

  • Read files fs.readMediumReads files in the listed places.Open workspace files in tabsPlaces: the open workspace
  • Write files fs.writeMediumCreates, changes and deletes files in the listed places.Save the files edited in tabsPlaces: the open workspace
  • Read chats chats.readMediumReads your transcripts and chat lists.Reload the open files when an agent finishes a turn, and find the folders of the workspaces whose files the tabs follow
  • Read git status and diffs git.readLowReads git status and diffs.Read a file's changes for a diff tab dragged from Source Control or brought back after a restart

Files

main.ts4.6 KB
// Files, diffs, terminals and diagrams: this plugin's tab kinds, which show
// in the side split or a task's pane (specs/tasks-and-splits/05), opened
// through the divergence/tabs service and, for third-party plugins, the
// legacy shared openTab/closeTab requests. The file-editor capability is
// resolved before the kinds register; their subscriptions and service follow.
import * as Effect from "effect/Effect";
import * as Stream from "effect/Stream";
import { App, Events, Layouts, Services, runPlugin } from "divergence/effect";
import type { EffectTabDefinition } from "divergence/effect";
import type { IconName } from "divergence";
import { Tabs, followApp } from "./controller.ts";
import { Tabs as TabsService } from "./contract.ts";
import { fileOfKey, isDirty, runFinished, tabFromKey, tabName, workspaceOfKey } from "./tabs.ts";
import type { Tab } from "./tabs.ts";
import { renderItem, tabIcon } from "./views.tsx";

const program = Effect.gen(function* () {
  const tabs = yield* Tabs;
  const layouts = yield* Layouts;
  // A tab's key is its id; one the app brings back after a restart is
  // made again from it: its file read again, a diff (a restart, a row
  // dragged from Source Control) read from the working tree as Source
  // Control opens it, a diagram's source taken from storage.
  const tabOf = (key: string): Tab | undefined => {
    const known = tabs.state.tabs.find((tab) => tab.id === key);
    if (known) return known;
    const made = tabFromKey(tabs.state, key);
    if (!made) return undefined;
    if (made.kind === "file" && tabs.nativeFiles) tabs.ensureFile(made);
    else if (made.kind === "file") Effect.runFork(tabs.readFile(made, made.id));
    if (made.kind === "diff") Effect.runFork(tabs.readDiff(made));
    if (made.kind === "diagram") Effect.runFork(tabs.restoreDiagram(made));
    Effect.runFork(tabs.follow(made));
    return made;
  };
  const kind = (name: Tab["kind"]): EffectTabDefinition<object> => ({
    opens: "side",
    title: (key: string) => {
      const tab = tabOf(key);
      return tab ? tabName(tab) : key;
    },
    icon: tabIcon(name) as IconName,
    // A file's and a diff's tabs show the file tree's icon for the file.
    file: fileOfKey,
    // In the side split, a workspace's tabs show beside its chats only.
    workspace: workspaceOfKey,
    render: (ctx) => {
      const tab = tabOf(ctx.key);
      if (!tab) return null;
      // A runtime before `visible` leaves it out.
      if (typeof ctx.visible === "boolean") tabs.visible(tab, ctx.visible);
      return renderItem(ctx, tabs, tab);
    },
    // A file with unsaved changes asks before its tab closes.
    beforeClose: (ctx) => {
      const tab = tabOf(ctx.key);
      return tab && isDirty(tabs.state.contents[tab.id]) ? `Discard the unsaved changes to ${tabName(tab)}?` : null;
    },
  });
  yield* layouts.kinds({ file: kind("file"), diff: kind("diff"), terminal: kind("terminal"), diagram: kind("diagram") });
  const app = yield* App;
  const events = yield* Events;
  yield* app.changes.pipe(
    Stream.runForEach((next) => Effect.forkScoped(followApp(tabs, next), { startImmediately: true })),
    Effect.forkScoped({ startImmediately: true }),
  );
  // A run may have changed the open files: native editors advance their
  // reload revision, while an older kernel takes the compatibility read path.
  // Only finished runs are asked for; an older runtime sends every agent event.
  yield* events.stream("agent", { kinds: ["run_finished"] }).pipe(
    Stream.runForEach((event) =>
      runFinished(event.kind)
        ? Effect.forEach(
            tabs.state.tabs.filter((tab) => tab.kind === "file"),
            (tab) => tabs.refreshFile(tab),
            { discard: true },
          )
        : Effect.void,
    ),
    Effect.forkScoped({ startImmediately: true }),
  );
  yield* followApp(tabs, yield* app.state);
  // A tab closed from its strip leaves the host's layouts: it is forgotten here.
  yield* layouts.changes.pipe(
    Stream.runForEach(() => tabs.reconcile().pipe(Effect.ignore({ log: "Warn", message: "Could not read the open tabs" }))),
    Effect.forkScoped({ startImmediately: true }),
  );
  // The service goes last: everything above registers synchronously, and a
  // provider that arrives later only adds calls, never views.
  const services = yield* Services;
  const handle = yield* services.provide(TabsService, {
    open: (params, _ctx) => tabs.open(params).pipe(Effect.map((tab) => ({ id: tab.id }))),
    close: (params, _ctx) => tabs.closeByRef(params),
    active: (_params, _ctx) => tabs.activeRef(),
  });
  tabs.emitActive((tab) => handle.emit("activeChanged", tab));
});

export default runPlugin(Tabs.layer, program);

Versions

VersionPublishedPlugin APISizePermissionsStatus
0.2.7latestNov 21, 2026>=5 <635.3 KB4 permissionsListed
0.2.6Nov 11, 2026>=5 <635 KB4 permissionsListed
0.2.5Nov 11, 2026>=5 <634.9 KB4 permissionsListed
0.2.4Nov 9, 2026>=5 <630 KB4 permissionsListed
0.2.3Oct 27, 2026>=2 <422 KB4 permissionsListed

Reviews and comments

0 threads · 0 reviews

No comments yet.