Official

chat

Built-in chat 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/chat@0.2.9

Permissions in 0.2.9

  • Control chats chats.controlHighCreates chats, sends prompts and cancels runs.Send prompts, answer agent questions, and create, change, fork, revert, stop and group chats
  • Run other plugins' commands commands.runHighRuns commands of other plugins.Run the sidebar's New chat command from the title bar, and its Close Chat and Reopen Closed Chat for Cmd+W and Cmd+Shift+T on a chat's only tab
  • Read chats chats.readMediumReads your transcripts and chat lists.Show workspaces, tasks, chats and transcripts, and follow them as agents work
  • Read files fs.readMediumReads files in the listed places.Suggest workspace files for @ mentionsPlaces: the open workspace
  • Show panels ui.slotsAlways grantedShows views in the listed parts of the window.Draw the chat grid, the title bar, and the Session panel with its rail buttonSlots: centertitlerailright

Files

answers.ts3.8 KB
// Answers typed into a question card survive a plugin reload, as unsent
// prompts do: plugin storage keeps them per chat until the question goes.
import * as Effect from "effect/Effect";
import * as Semaphore from "effect/Semaphore";
import * as z from "zod";
import { parse } from "divergence/effect";
import type { Controller } from "./controller.ts";
import { errorMessage } from "./data.ts";
import { storableAnswers } from "./question-fields.ts";

// A field's answer is a string, a string array or a boolean (QuestionAnswer).
const stored = z.record(z.string(), z.record(z.string(), z.union([z.string(), z.boolean(), z.array(z.string())])));
type Stored = z.infer<typeof stored>;
const answersKey = (chatId: string) => `answers:${chatId}`;
export class Answers {
  // One write at a time: storage writes may otherwise land out of order.
  private readonly lane = Semaphore.makeUnsafe(1);
  private readonly dirty = new Set<string>();
  private readonly restored = new Set<string>();
  readonly controller: Controller;
  constructor(controller: Controller) {
    this.controller = controller;
  }
  /// The answers this chat had before the plugin started, once per chat:
  /// afterwards the ones in memory are newer.
  read = Effect.fn("Answers.read")((chatId: string) =>
    this.restored.has(chatId)
      ? Effect.succeed(undefined)
      : this.controller.host.call("host/storage.get", { key: answersKey(chatId) }).pipe(
          Effect.flatMap(({ value }) => parse("question answers", stored, value ?? {})),
          Effect.catch((error) =>
            this.controller.notify
              .error(`Typed answers could not be restored: ${errorMessage(error)}`)
              .pipe(Effect.as(undefined)),
          ),
        ),
  );
  /// Installs what `read` found beside the transcript's pending questions.
  restore = Effect.fn("Answers.restore")((chatId: string, saved: Stored | undefined) =>
    Effect.suspend(() => {
      if (saved) {
        this.restored.add(chatId);
        const transcript = this.controller.transcript(chatId);
        for (const [id, answers] of Object.entries(saved)) transcript.answers[id] ??= answers;
      }
      // Forgetting stale answers in storage must not hold the transcript's paint.
      return Effect.forkIn(this.prune(chatId), this.controller.scope, { startImmediately: true });
    }),
  );
  /// A question answered, withdrawn or ended with its turn takes its answers along.
  prune = Effect.fn("Answers.prune")((chatId: string) =>
    Effect.suspend(() => {
      const transcript = this.controller.state.transcripts[chatId];
      if (!transcript) return Effect.void;
      const gone = Object.keys(transcript.answers).filter((id) => !transcript.questions.some((q) => q.id === id));
      if (!gone.length) return Effect.void;
      for (const id of gone) delete transcript.answers[id];
      return this.save(chatId);
    }),
  );
  save = Effect.fn("Answers.save")((chatId: string) =>
    Effect.suspend(() => {
      this.dirty.add(chatId);
      return this.lane.withPermit(
        Effect.suspend(() => {
          // A write queued behind one that already took the latest answers.
          if (!this.dirty.delete(chatId)) return Effect.void;
          const transcript = this.controller.state.transcripts[chatId];
          // A secret answer lives only as long as its card.
          const value = Object.fromEntries(
            Object.entries(transcript?.answers ?? {}).map(([id, answers]) => [
              id,
              storableAnswers(transcript?.questions.find((question) => question.id === id)?.fields ?? [], answers),
            ]),
          );
          return this.controller.host.call("host/storage.set", { key: answersKey(chatId), value });
        }),
      );
    }).pipe(
      Effect.catch((error) => this.controller.notify.error(`Typed answers could not be saved: ${errorMessage(error)}`)),
    ),
  );
}

Versions

VersionPublishedPlugin APISizePermissionsStatus
0.2.9latestNov 21, 2026>=5 <6349 KB5 permissionsListed
0.2.8Nov 16, 2026>=5 <6348.6 KB5 permissionsListed
0.2.7Nov 11, 2026>=5 <6314.3 KB5 permissionsListed
0.2.6Nov 9, 2026>=5 <6306.2 KB5 permissionsListed
0.2.5Oct 27, 2026>=2 <4178.6 KB5 permissionsListed

Reviews and comments

0 threads · 0 reviews

No comments yet.