Official

market

The plugin marketplace: browse, install through an agent's scan, update and publish plugins, and the marketplace tools of agents in the Plugins workspace.

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/market@0.1.6

Permissions in 0.1.6

  • Marketplace marketOfficial onlyUses the marketplace APIs. Only official plugins can have it.Search, read, install, update and publish marketplace plugins, and sign in to the marketplace
  • Manage plugins plugins.manageOfficial onlyReloads and enables plugins. Only official plugins can have it.Ask for the enable card of a plugin an agent installed
  • Control chats chats.controlHighCreates chats, sends prompts and cancels runs.Open the chat in the Plugins workspace where an agent scans, installs or updates a plugin
  • Provide agent tools tools.provideMediumGives tools to agents.Give agents in the Plugins workspace the marketplace tools
  • Read chats chats.readMediumReads your transcripts and chat lists.Find the agent, model and effort last used in the Plugins workspace
  • Show panels ui.slotsAlways grantedShows views in the listed parts of the window.Show the marketplace pageSlots: center

Files

listing.tsx23.1 KB
// One plugin's listing: its header with the figures that say how it is
// doing, the install row, its screenshots, then the tabs Overview,
// Permissions, Files, Comments, Versions and Mods.
import type { Element, ValueEvent } from "divergence";
import { RISK_NAMES, formatBytes, formatCount, isOfficial, languageOf, permissionRows, riskTone, runsAnything, shortDate } from "./logic.ts";
import type { Controller } from "./controller.ts";
import type { Listing, ListingMedia, MarketComment } from "./remote.ts";
import { EDGED, badge, clickable, column, fill, menus, row, textLink } from "./parts.tsx";
import type { Ctx } from "./parts.tsx";
import { listingMark, publisherName } from "./browse.tsx";

// The screenshot stage's height, and its thumbnails (16:10).
const STAGE = 400;
const THUMB = { width: 64, height: 40 } as const;
// The overview lists this many additions before "and N more".
const ADDITIONS = 12;

function permissionList(ctx: Ctx, market: Controller, permissions: unknown, official: boolean): Element | null {
  const { settings, error, fetch } = market.settingsOf(permissions);
  if (fetch) ctx.run(fetch);
  const rows = permissionRows(permissions, { official, describe: true, settings });
  if (!rows.length) return <text style="body" size="xs" tone="muted">It asks for no permissions.</text>;
  return (
    <div {...column} gap={2}>
      {error ? <text style="body" size="xs" tone="warning">{error}</text> : null}
      {rows.map(
            (entry) =>
              (
                <div key={entry.permission} {...row} gap="medium" padding="small" alignItems="start">
                  <div width={8} height={8} marginTop={5} borderRadius="full" background={riskTone(entry.risk)} />
                  <div {...column} {...fill} gap={2}>
                            <div {...row} gap="small" flexWrap="wrap">
                                      <text style="body" size="sm" weight={560}>{entry.label}</text>
                                      {entry.scopes.length ? <text style="mono" size="xs" tone="muted">{entry.scopes.join(", ")}</text> : null}
                                      <text style="mono" size="xs" tone="faint">{entry.permission}</text>
                                    </div>
                            <text style="body" size="xs" tone="muted">
                                      {entry.blocked ? "Only official plugins can have this; the app refuses it." : entry.reason}
                                    </text>
                          </div>
                  <text style="body" size="xs" color={riskTone(entry.risk)}>{RISK_NAMES[entry.risk]}</text>
                </div>
              ),
          )}
    </div>
  );
}

function dangerBox(text: string): Element | null {
  return (
    <div {...column} gap={4} padding="medium" borderRadius="md" background="danger/10" border={{ width: 1, color: "danger/35" }}>
      <div {...row} gap="small">
          <icon name="triangle-alert" small tone="danger" />
          <text style="body" size="sm" bold tone="danger">This plugin can run any program with your permissions</text>
        </div>
      <text style="body" size="xs" tone="muted">{text}</text>
    </div>
  );
}

function installRow(ctx: Ctx, market: Controller, listing: Listing): Element | null {
  const { state } = market;
  const installed = listing.installed;
  const update = state.updates.find((u) => u.id === listing.id && u.latest);
  const versions = market.installableVersions(listing);
  const chosen = listing.versions?.find((v) => v.version === state.version);
  const permissions = chosen?.permissions ?? listing.permissions;
  const busyKey = `install:${listing.id}`;
  const versionPick = versions.length
    ? (
      <div {...row} maxWidth={130}>
        <select id="market-version" value={state.version ?? ""} small options={versions.map((v) => ({ value: v.version, label: v.version }))} onChange={(e: ValueEvent<string>) => {
                    market.state.version = e.value;
                    market.state.tree = null;
                    market.state.treeError = null;
                    market.state.file = null;
                    market.redraw();
                  }} />
      </div>
    )
    : null;
  // Installed and current: the header says so, and there is nothing to do here.
  if (installed && !update) return null;
  if (installed && update) {
    return (
      <div {...row} gap="small" flexWrap="wrap">
        <text style="body" size="sm">{`Version ${update.latest} is out`}</text>
        <spacer />
        {menus(ctx, market)}
        <button id="market-update-listing" label={`Update to ${update.latest}`} small variant="primary" loading={!!state.busy[`update:${update.folder}`]} onClick={() => ctx.run(market.runUpdate(update))} />
      </div>
    );
  }
  const direct = state.direct && !runsAnything(permissions);
  return (
    <div {...column} gap="small">
      <div {...row} gap="small" flexWrap="wrap">
          {versionPick}
          {direct ? null : menus(ctx, market)}
          <spacer />
          <button id="market-install" label={direct ? "Install" : "Install…"} small variant="primary" loading={!!state.busy[busyKey]} disabled={!versions.length || !state.menus?.agents?.length} tooltip={direct ? "Download it, not enabled, and show its enable card" : "An agent reads it first, in the Plugins workspace"} onClick={() => ctx.run(market.install())} />
        </div>
      <text style="body" size="xs" tone="muted">
          {direct
                    ? "Installs directly (Updates > Install directly): the download is not enabled until you enable it on its card."
                    : "A chat opens in the Plugins workspace: the agent reads the plugin's files first, installs it only if it looks safe, and then asks you to enable it."}
        </text>
    </div>
  );
}

function fileTree(ctx: Ctx, market: Controller): Element | null {
  const { state } = market;
  if (state.treeError)
    return (
      <div {...column} gap="small" alignItems="start">
        <text style="body" size="sm">{`Could not read the release: ${state.treeError}`}</text>
        <button id="market-tree-retry" label="Try again" small variant="outline" onClick={() => ctx.run(market.loadTree())} />
      </div>
    );
  if (!state.tree) {
    ctx.run(market.loadTree());
    return <spinner />;
  }
  if (state.tree === "loading")
    return <div {...row} gap="small"><spinner /><text style="muted">Verifying and reading the package…</text></div>;
  const files = state.tree.files ?? [];
  const list = (
    <div {...column} gap={1} width={260} maxHeight={520} overflowY="scroll">
      {files.map(
            (file) =>
              (
                <div key={file.path} {...row} {...clickable} cursor="pointer" gap="small" padding="small" paddingY={3} borderRadius="sm" background={state.file?.path === file.path ? "accent" : undefined} hover={{ background: "hover" }} onClick={() => ctx.run(market.openFile(file.path))}>
                  <icon name={file.binary ? "file-lock" : "file-text"} small tone={file.binary || file.executable ? "warning" : "muted"} />
                  <text style="mono" size="xs" truncate>{file.path}</text>
                  <spacer />
                  <text style="body" size="xs" tone="faint">{formatCount(file.size)}B</text>
                </div>
              ),
          )}
    </div>
  );
  let content: Element | null;
  const file = state.file;
  if (!file) content = <empty>Choose a file to read it.</empty>;
  else if (file.kind === "loading") content = <spinner />;
  else if (file.kind === "failed") content = <empty>{`Could not read ${file.path}: ${file.error}`}</empty>;
  else if (file.kind === "binary")
    content = (
      <empty>
        {`${file.path} is a binary file (${formatCount(file.size)}B); it is not shown.`}
      </empty>
    );
  else {
    content = (
      <div {...column} {...fill} gap="small">
        {file.truncated ? <text style="body" size="xs" tone="warning">Only the start of this file is shown.</text> : null}
        <editor id={`market-file-${state.listingId}-${state.version}-${file.path}`} text={file.text} language={languageOf(file.path)} readOnly />
      </div>
    );
  }
  return <div {...row} gap="medium" alignItems="start">{list}<div {...column} {...fill} minHeight={320}>{content}</div></div>;
}

function comment(node: MarketComment, depth = 0): Element {
  const stars = node.stars ? "★".repeat(node.stars) + "☆".repeat(5 - node.stars) : null;
  return (
    <div key={node.id} {...column} gap={4} paddingLeft={depth ? 14 : 0} borderLeft={depth ? { width: 2, color: "border" } : undefined}>
      <div {...row} gap="small">
          <text style="body" size="xs" bold>{node.user?.name ?? "[deleted]"}</text>
          {stars ? <text style="body" size="xs" tone="warning">{stars}</text> : null}
          <text style="body" size="xs" tone="faint">
              {String(node.createdAt ?? "").slice(0, 10)}
              {node.pluginVersion ? ` · v${node.pluginVersion}` : ""}
            </text>
        </div>
      <text style="body" size="sm">{node.body}</text>
      {(node.replies ?? []).map((reply) => comment(reply, depth + 1))}
    </div>
  );
}

function commentsTab(ctx: Ctx, market: Controller): Element | null {
  const { state } = market;
  const onWebsite = (
    <div {...row} gap="small">
      <button id="market-comment-web" label="Write a comment on the website" icon="external-link" small variant="outline" onClick={() => ctx.run(market.openListingSite())} />
    </div>
  );
  if (!state.comments) {
    ctx.run(market.loadComments());
    return <spinner />;
  }
  if (state.comments === "loading") return <spinner />;
  if ("error" in state.comments)
    return (
      <div {...column} gap="small">
        <text style="body" size="xs" tone="muted">{`Comments are on the website (${state.comments.error}).`}</text>
        {onWebsite}
      </div>
    );
  const threads = state.comments.threads ?? [];
  return (
    <div {...column} gap="medium">
      {onWebsite}
      {threads.length ? threads.map((thread) => comment(thread)) : <empty>No comments yet.</empty>}
    </div>
  );
}

function versionsTab(listing: Listing): Element | null {
  return (
    <div {...column} gap={2}>
      {(listing.versions ?? []).map(
            (v) =>
              (
                <div key={v.version} {...row} gap="small" padding="small">
                  <text style="mono" size="sm">{v.version}</text>
                  {v.malicious ? badge("Malicious", "danger") : v.yanked ? badge("Yanked", "warning") : null}
                  <spacer />
                  <text style="body" size="xs" tone="muted">{String(v.publishedAt ?? "").slice(0, 10)}</text>
                </div>
              ),
          )}
    </div>
  );
}

function reportForm(ctx: Ctx, market: Controller): Element | null {
  const { state } = market;
  if (!state.report) {
    return textLink("market-report-open", "flag", "Report this plugin…", () => {
      market.state.report = { reason: "", files: "" };
      market.redraw();
    });
  }
  return (
    <card {...column} gap="small">
      <text style="body" size="sm" bold>Report this plugin to the moderators</text>
      <input id="market-report-reason" value={state.report.reason} placeholder="What is wrong, and how you know" multiline onChange={(e: ValueEvent<string>) => {
              if (market.state.report) market.state.report.reason = e.value;
            }} />
      <input id="market-report-files" value={state.report.files} placeholder="Files and lines, for example main.js:42 (optional)" onChange={(e: ValueEvent<string>) => {
              if (market.state.report) market.state.report.files = e.value;
            }} />
      <div {...row} gap="small">
          <spacer />
          <button id="market-report-cancel" label="Cancel" small variant="ghost" onClick={() => {
                    market.state.report = null;
                    market.redraw();
                  }} />
          <button id="market-report-next" label="Review report…" small variant="danger" loading={!!state.busy.report || !!state.report.requestId} onClick={() => ctx.run(market.sendReport())} />
        </div>
      <text style="body" size="xs" tone="muted">The app shows exactly what is sent before anything leaves.</text>
    </card>
  );
}

// Where the plugin is installed here, at the header's right edge.
function installedStatus(listing: Listing): Element | null {
  const installed = listing.installed;
  if (!installed) return null;
  const folder = installed.folder === listing.name ? "" : ` as ${installed.folder}`;
  return (
    <div {...row} gap={6}>
      <icon name="check" small tone={installed.enabled ? "success" : "muted"} />
      <text style="body" size="xs" tone="muted">
          {`Installed ${installed.version}${folder}${installed.enabled ? "" : ", turned off"}`}
        </text>
    </div>
  );
}

// The screenshots: the chosen one large with its caption, the others as
// thumbnails under it. A picture still on its way holds its place.
function gallery(ctx: Ctx, market: Controller, listing: Listing, shots: readonly ListingMedia[]): Element | null {
  const { state } = market;
  const chosen = shots[Math.min(state.shot, shots.length - 1)];
  if (!chosen) return null;
  const pictures = shots.map((shot) => {
    const picture = market.mediaOf(shot, listing.id);
    if (picture.fetch) ctx.run(picture.fetch);
    return picture;
  });
  const main = pictures[shots.indexOf(chosen)];
  const failed = pictures.find((picture) => picture.error)?.error;
  const thumbs =
    shots.length > 1
      ? (
        <div {...row} gap={6} flexShrink={0}>
          {shots.map(
                      (shot, i) =>
                        (
                          <div key={shot.sha256} id={`market-shot-${i}`} {...clickable} padding={2} borderRadius={8} background={shot === chosen ? "accent" : undefined} hover={{ background: shot === chosen ? "accent" : "hover" }} onClick={() => market.chooseShot(i)}>
                            <image path={pictures[i]?.path ?? undefined} width={THUMB.width} height={THUMB.height} radius={6} />
                          </div>
                        ),
                    )}
        </div>
      )
      : null;
  // The stage frames every screenshot at one height whatever its shape, so
  // choosing another never moves the page under it.
  return (
    <div {...column} gap={10}>
      <div {...row} justifyContent="center" height={STAGE} paddingY={16} background="card" borderRadius="lg">
          <div {...EDGED} borderRadius="sm">
              <image path={main?.path ?? undefined} pixelWidth={chosen.width ?? 1600} pixelHeight={chosen.height ?? 1000} maxHeight={STAGE - 32} radius="sm" zoomable />
            </div>
        </div>
      <div {...row} gap="medium" alignItems="start">
          <div {...column} {...fill} gap={2}>
              {chosen.caption ? <text style="body" size="xs" tone="muted">{chosen.caption}</text> : null}
              {failed ? <text style="body" size="xs" tone="faint">{`Could not load the screenshots: ${failed}`}</text> : null}
            </div>
          {thumbs}
        </div>
    </div>
  );
}

// What the overview lists, one group per kind: the kind once, beside its first row.
function additionsList(adds: readonly { kind: string; label: string; detail?: string }[]): Element | null {
  if (!adds.length) return null;
  const shown = adds.slice(0, ADDITIONS);
  return (
    <div {...column} gap="small">
      <text style="body" size="sm" weight={600}>What it adds</text>
      <div {...column} gap={4}>
          {shown.map(
                  (add, i) =>
                    (
                      <div key={`${add.kind}:${add.label}:${i}`} {...row} gap="medium" alignItems="start">
                        <div width={96} flexShrink={0}>
                                    <text style="body" size="xs" tone="muted">{shown[i - 1]?.kind === add.kind ? "" : add.kind}</text>
                                  </div>
                        <div {...column} {...fill} gap={1}>
                                    <text style="body" size="xs">{add.label}</text>
                                    {add.detail ? <text style="body" size="xs" tone="faint" lineClamp={2}>{add.detail}</text> : null}
                                  </div>
                      </div>
                    ),
                )}
          {adds.length > shown.length ? <text style="body" size="xs" tone="faint">{`and ${adds.length - shown.length} more`}</text> : null}
        </div>
    </div>
  );
}

// The release's links and size, in one quiet line over the overview.
function aboutLine(ctx: Ctx, market: Controller, listing: Listing, files: number, bytes: number): Element {
  const extras = listing.listing;
  return (
    <div {...row} gap={18} flexWrap="wrap">
      {extras?.homepage ? textLink("market-homepage", "external-link", "Homepage", () => ctx.run(market.openLink(extras.homepage ?? "")), extras.homepage) : null}
      {extras?.repository ? textLink("market-repository", "external-link", "Source code", () => ctx.run(market.openLink(extras.repository ?? "")), extras.repository) : null}
      <text style="body" size="xs" tone="faint">
          {`${formatCount(files)} ${files === 1 ? "file" : "files"}, ${formatBytes(bytes)}`}
        </text>
    </div>
  );
}

// The README beside what the release adds, its links and its size.
function overviewTab(ctx: Ctx, market: Controller, listing: Listing, permissions: unknown): Element | null {
  const fetch = market.overviewOf(listing, permissions);
  if (fetch) ctx.run(fetch);
  const overview = market.state.overview;
  if (!overview || overview.kind === "loading")
    return <div {...row} gap="small"><spinner /><text style="muted">Reading the release…</text></div>;
  if (overview.kind === "failed") return <empty>{`Could not read the release: ${overview.error}`}</empty>;
  // One column: the links and size, the README when there is one, then what
  // the release adds (the header already says what the description says).
  const readme = overview.readme
    ? (
      <div {...column} gap="small">
        <markdown text={overview.readme} />
        {overview.readmeTruncated ? <text style="body" size="xs" tone="faint">Only the start of the README is shown.</text> : null}
      </div>
    )
    : null;
  const adds = additionsList(overview.adds);
  return (
    <div {...column} gap={24}>
      {aboutLine(ctx, market, listing, overview.files, overview.bytes)}
      {readme}
      {adds}
      {readme || adds ? null : <text style="body" size="sm" tone="muted">The publisher wrote no README for this plugin.</text>}
    </div>
  );
}

export function listingPage(ctx: Ctx, market: Controller): Element | null {
  const { state } = market;
  const back = (
    <div {...row}>
      {textLink("market-back", "arrow-left", "All plugins", () => ctx.run(market.backToBrowse()))}
    </div>
  );
  if (state.listingError)
    return (
      <div {...column} gap="medium">
        {back}
        <empty>{`Could not load ${state.listingId}: ${state.listingError}`}</empty>
      </div>
    );
  const listing = state.listing;
  if (!listing)
    return (
      <div {...column} gap="medium">
        {back}
        <div {...row} gap="small"><spinner /><text style="muted">{`Loading ${state.listingId}…`}</text></div>
      </div>
    );
  const official = isOfficial(listing.id);
  const chosen = listing.versions?.find((v) => v.version === state.version);
  const permissions = chosen?.permissions ?? listing.permissions;
  const permissionCount = Object.keys((permissions as object | null) ?? {}).length;
  const shots = listing.listing?.screenshots ?? [];
  const tabs = [
    { id: "overview", label: "Overview" },
    { id: "permissions", label: permissionCount ? `Permissions (${permissionCount})` : "Permissions" },
    { id: "files", label: "Files" },
    { id: "comments", label: "Comments" },
    { id: "versions", label: `Versions (${listing.versions?.length ?? 0})` },
    ...(listing.mods?.length ? [{ id: "mods", label: `Mods (${listing.mods.length})` }] : []),
  ];
  const modsView = (
    <div {...column} gap={2}>
      {listing.mods?.map(
            (mod) =>
              (
                <div key={mod.id} {...row} {...clickable} cursor="pointer" gap="small" padding="small" borderRadius="sm" hover={{ background: "hover" }} onClick={() => ctx.run(market.openListing(mod.id))}>
                  <icon name="git-fork" small tone="muted" />
                  <text style="body" size="sm">{mod.id}</text>
                </div>
              ),
          )}
    </div>
  );
  const body =
    state.tab === "files"
      ? fileTree(ctx, market)
      : state.tab === "comments"
        ? commentsTab(ctx, market)
        : state.tab === "versions"
          ? versionsTab(listing)
          : state.tab === "mods"
            ? modsView
            : state.tab === "permissions"
              ? permissionList(ctx, market, permissions, official)
              : overviewTab(ctx, market, listing, permissions);
  const action = installRow(ctx, market, listing);
  const updated = shortDate(listing.updatedAt ?? chosen?.publishedAt ?? listing.createdAt);
  const installs = Number(listing.downloads) || 0;
  const facts = [
    listing.latestVersion ? `Version ${listing.latestVersion}` : null,
    updated ? `Updated ${updated}` : null,
    installs ? `${formatCount(installs)} ${installs === 1 ? "install" : "installs"}` : null,
    listing.rating?.average
      ? `★ ${listing.rating.average} from ${listing.rating.count} ${listing.rating.count === 1 ? "review" : "reviews"}`
      : null,
  ].filter(Boolean);
  return (
    <div {...column} gap={20}>
      {back}
      <div {...column} gap={12}>
          <div {...row} gap={14}>
              {listingMark(ctx, market, listing, 48)}
              <div {...column} {...fill} gap={2}>
                  <div {...row} gap="small">
                      <text style="body" size="xl" weight={600} truncate>{listing.name ?? listing.id}</text>
                      {listing.visibility && listing.visibility !== "public" ? badge(listing.visibility, "info") : null}
                    </div>
                  <div {...row} gap="small">
                      {publisherName(listing)}
                      <text style="body" size="xs" tone="faint" truncate>{facts.join(" · ")}</text>
                    </div>
                </div>
              {installedStatus(listing)}
            </div>
          {listing.description ? <text style="body" size="base">{listing.description}</text> : null}
          {listing.basedOn
                    ? (
                      <div {...row}>
                        <button id="market-mod-of" label={`Mod of ${listing.basedOn.id}@${listing.basedOn.version}`} icon="git-fork" small variant="chip" onClick={() => ctx.run(market.openListing(listing.basedOn?.id ?? "", listing.basedOn?.version ?? null))} />
                      </div>
                    )
                    : null}
        </div>
      {runsAnything(permissions) ? dangerBox("It can read and change your files, use your accounts and reach the network. It installs only after an agent scanned it, and enabling it needs a two-second hold.") : null}
      {action ? <card {...column}>{action}</card> : null}
      {gallery(ctx, market, listing, shots)}
      <tabs id="market-listing-tabs" active={state.tab} tabs={tabs} onChange={(e: ValueEvent<string>) => market.setListingTab(e.value)} />
      {body}
      <div {...row} marginTop={8}>{reportForm(ctx, market)}</div>
    </div>
  );
}

Versions

VersionPublishedPlugin APISizePermissionsStatus
0.1.6latestNov 21, 2026>=5 <671.9 KB6 permissionsListed
0.1.5Nov 18, 2026>=5 <671.4 KB6 permissionsListed
0.1.4Nov 16, 2026>=5 <670.5 KB6 permissionsListed
0.1.3Nov 11, 2026>=5 <662.7 KB6 permissionsListed
0.1.2Nov 9, 2026>=5 <657.5 KB6 permissionsListed
0.1.1Oct 27, 2026>=2 <446.2 KB6 permissionsListed

Reviews and comments

0 threads · 0 reviews

No comments yet.