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

Permissions in 0.1.4

  • 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

views.tsx21.8 KB
// The marketplace page's frame (header, account and tabs), the Updates and
// Bug reports tabs, and the sidebar row; Browse is in browse.ts and a
// listing in listing.ts. Rendering only reads state; view handlers run the
// controller's effects, and plain input handlers mutate state and redraw.
import type { Element, ListItem, ValueEvent } from "divergence";
import { FIX_NOTE, accountName, badgeCount, formatCount, profileEditable } from "./logic.ts";
import { ROUTE } from "./state.ts";
import type { Controller } from "./controller.ts";
import type { BugAttachment, DraftPlugin, MarketUpdateItem, SentReport } from "./remote.ts";
import { badge, column, fill, full, menus, reading, row } from "./parts.tsx";
import type { Ctx } from "./parts.tsx";
import { browsePage } from "./browse.tsx";
import { listingPage } from "./listing.tsx";
import { profilePage } from "./profile.tsx";

function updateRow(ctx: Ctx, market: Controller, item: MarketUpdateItem): Element | null {
  const { state } = market;
  const key = `update:${item.folder}`;
  return (
    <div key={item.folder} {...row} gap="medium" padding="medium">
      <icon name={item.malicious ? "shield-alert" : "package"} small tone={item.malicious ? "danger" : "muted"} />
      <div {...column} {...fill} gap={2}>
          <div {...row} gap="small" flexWrap="wrap">
              <text style="body" size="sm" bold>{item.folder}</text>
              <text style="mono" size="xs" tone="muted">{item.id}</text>
              {item.official ? badge("Official", "success") : null}
              {item.malicious ? badge("Malicious", "danger") : item.yanked ? badge("Yanked", "warning") : null}
            </div>
          <text style="body" size="xs" tone={item.malicious ? "danger" : "muted"}>
              {item.malicious
                          ? `${item.installed} was marked malicious${item.reason ? ` (${item.reason})` : ""}. It is off; remove it in Settings > Plugins.`
                          : item.latest
                            ? `${item.installed} → ${item.latest}${item.direct ? " · replaced directly" : " · an agent merges it in the Plugins workspace"}`
                            : `${item.installed} was yanked${item.reason ? `: ${item.reason}` : ""}.`}
            </text>
        </div>
      <button id={`market-open-${item.folder}`} label="Listing" small variant="ghost" onClick={() => ctx.run(market.openListing(item.id))} />
      {item.latest && !item.malicious
              ? <button id={`market-update-${item.folder}`} label="Update" small variant="primary" loading={!!state.busy[key]} onClick={() => ctx.run(market.runUpdate(item))} />
              : null}
    </div>
  );
}

function updatesPage(ctx: Ctx, market: Controller): Element | null {
  const { state } = market;
  const list = state.updates.length
    ? (
      <card {...column}>
        {state.updates.map((item, i) => [i ? <divider /> : null, updateRow(ctx, market, item)])}
      </card>
    )
    : <empty>Every installed plugin is up to date.</empty>;
  const needsAgent = state.updates.some((u) => u.latest && !u.direct && !u.malicious);
  return (
    <div {...column} gap="large">
      <div {...column} gap="small">
          <div {...row} gap="small">
              <text style="section">Updates</text>
              <spacer />
              <button id="market-check" label="Check now" icon="refresh-cw" small variant="outline" loading={!!state.busy.check} onClick={() => ctx.run(market.busy("check", market.loadUpdates(true)))} />
            </div>
          <text style="body" size="xs" tone="muted">
              {"Nothing updates by itself. An unchanged official plugin is replaced after its signature is checked; any other\n        update opens a chat where an agent reads the new version, scans the difference and merges it into your\n        copy."}
            </text>
          {needsAgent ? menus(ctx, market) : null}
          {list}
        </div>
      <div {...column} gap="small">
          <text style="section">Installing</text>
          <card {...row} gap="large">
              <div {...column} {...fill} gap={2}>
                  <text style="body" size="sm" bold>Install directly</text>
                  <text style="body" size="xs" tone="muted">
                      {"Skip the agent's scan: the download lands not enabled, and its enable card opens in a small chat. Plugins\n            that can run any program are always scanned first."}
                    </text>
                  {state.directError
                                ? <text style="body" size="xs" tone="danger">{`Could not read this setting, so it is off: ${state.directError}`}</text>
                                : null}
                </div>
              <switch id="market-direct" label="" checked={state.direct} onChange={(e: ValueEvent<boolean>) => ctx.run(market.setDirect(e.value))} />
            </card>
        </div>
    </div>
  );
}

function accountArea(ctx: Ctx, market: Controller): Element | null {
  const { state } = market;
  const account = state.account;
  // The account answers in a moment; the header waits for it rather than spinning.
  if (!account) return null;
  if (account.signedIn) {
    const name = accountName("account" in account ? account.account : undefined);
    return (
      <div {...row} gap="small">
        <text style="body" size="xs" tone="muted">{name}</text>
        <button id="market-sign-out" label="Sign out" small variant="ghost" loading={!!state.busy["sign-out"]} onClick={() => ctx.run(market.signOut())} />
      </div>
    );
  }
  if (state.signIn) {
    return (
      <div {...row} gap="small">
        <text style="body" size="xs" tone="muted">Code</text>
        <text style="mono" size="sm" bold>{state.signIn.code}</text>
        <button id="market-sign-in-open" label="Open sign-in page" icon="external-link" small variant="primary" onClick={() => ctx.run(market.openSignInPage())} />
        <button id="market-sign-in-cancel" icon="x" small variant="ghost" tooltip="Cancel" onClick={() => ctx.run(market.cancelSignIn())} />
      </div>
    );
  }
  return (
    <div {...row} gap="small">
      {account.expired ? <text style="body" size="xs" tone="muted">Your sign-in expired.</text> : null}
      <button id="market-sign-in" label="Sign in" small variant="ghost" tooltip="Sign in to publish plugins and comment on them" loading={!!state.busy["sign-in"]} onClick={() => ctx.run(market.signIn())} />
    </div>
  );
}

function bugPluginRow(ctx: Ctx, market: Controller, plugin: DraftPlugin): Element | null {
  const bug = market.state.bug;
  if (!bug) return null;
  const chosen = bug.chosen.has(plugin.name);
  const thirdParty = !plugin.official;
  return (
    <div key={plugin.name} {...row} gap="small" padding="small" paddingY={3}>
      <div {...row} {...fill}>
          <checkbox id={`bug-plugin-${plugin.name}`} label={`${plugin.name} · ${plugin.id} ${plugin.version ?? ""}`} checked={chosen} onChange={(e: ValueEvent<boolean>) => ctx.run(market.togglePlugin(plugin.name, e.value))} />
        </div>
      {plugin.official ? badge("Official", "success") : null}
      {plugin.changed ? badge("Changed", "warning") : null}
      {plugin.reasons?.length ? <text style="body" size="xs" tone="muted">{plugin.reasons.join(", ")}</text> : null}
      {chosen && thirdParty
              ? <checkbox id={`bug-source-${plugin.name}`} label="Full source" checked={bug.fullSource.has(plugin.name)} onChange={(e: ValueEvent<boolean>) => ctx.run(market.toggleSource(plugin.name, e.value))} />
              : null}
    </div>
  );
}

function attachmentRow(ctx: Ctx, market: Controller, attachment: BugAttachment): Element | null {
  const bug = market.state.bug;
  if (!bug) return null;
  const on = !bug.unchecked.has(attachment.id);
  const open = bug.open.has(attachment.id);
  const removed = attachment.removed ?? [];
  const shown = open
    ? attachment.kind === "screenshot"
      ? <image path={attachment.path} maxHeight={240} radius={8} zoomable />
      : attachment.kind === "diff"
        ? <diff diff={attachment.text ?? ""} />
        : <code text={attachment.text ?? ""} language="text" />
    : null;
  return (
    <card key={attachment.id} {...column} gap={4}>
      <div {...row} gap="small">
          <div {...row} {...fill}>
              <checkbox id={`bug-attach-${attachment.id}`} label={attachment.title} checked={on} onChange={(e: ValueEvent<boolean>) => {
                          if (!market.state.bug) return;
                          if (e.value) market.state.bug.unchecked.delete(attachment.id);
                          else market.state.bug.unchecked.add(attachment.id);
                          market.redraw();
                        }} />
            </div>
          <text style="body" size="xs" tone="faint">{`${attachment.name} · ${formatCount(attachment.size)}B`}</text>
          <button id={`bug-show-${attachment.id}`} label={open ? "Hide" : "Show"} small variant="ghost" onClick={() => {
                    if (!market.state.bug) return;
                    if (open) market.state.bug.open.delete(attachment.id);
                    else market.state.bug.open.add(attachment.id);
                    market.redraw();
                  }} />
        </div>
      {removed.length
              ? (
                <text style="body" size="xs" tone="warning">
                  {`Secrets removed: ${removed.map((r) => `line ${r.line} (${r.kind})`).join(", ")}. Check that nothing else is left.`}
                </text>
              )
              : null}
      {shown}
    </card>
  );
}

function reportsList(ctx: Ctx, market: Controller): Element | null {
  const { state } = market;
  if (!state.reports.length && !state.reportsError) return null;
  return (
    <div {...column} gap="small">
      <text style="section">Your reports</text>
      {state.reportsError
              ? <text style="body" size="xs" tone="danger">{`Could not list your reports: ${state.reportsError}`}</text>
              : null}
      <card {...column}>
          {state.reports.map((report, i) => [
                  i ? <divider /> : null,
                  (
                    <div key={report.id} {...row} gap="medium" padding="small">
                      <text style="mono" size="sm">{`#${report.number}`}</text>
                      <div {...column} {...fill} gap={2}>
                                <text style="body" size="sm" lineClamp={1}>{report.text}</text>
                                <text style="body" size="xs" tone="muted">{(report.plugins ?? []).map((p) => p.id).join(", ")}</text>
                              </div>
                      <button id={`bug-fix-${report.id}`} label="Fix with an agent" small variant="outline" loading={!!state.busy[`fix:${report.id}`]} onClick={() => ctx.run(market.fixReport(report))} />
                      <button id={`bug-attach-fix-${report.id}`} label="Attach fix…" small variant="ghost" loading={!!state.busy[`attach:${report.id}`]} onClick={() => ctx.run(market.attachFix(report))} />
                    </div>
                  ),
                ])}
        </card>
    </div>
  );
}

function bugPage(ctx: Ctx, market: Controller): Element | null {
  const { state } = market;
  const bug = state.bug;
  if (!bug) {
    return (
      <div {...column} gap="large">
        <div {...column} gap="small">
              <text style="section">Report a bug</text>
              <text style="body" size="sm">{FIX_NOTE}</text>
              <div {...row}>
                    <button id="bug-new" label="Report a bug…" icon="bug" small variant="primary" onClick={() => ctx.run(market.openBugForm())} />
                  </div>
            </div>
        {reportsList(ctx, market)}
      </div>
    );
  }
  if (bug.sent) {
    const report: SentReport = bug.sent;
    return (
      <div {...column} gap="large">
        <card {...column} gap="small">
              <text style="section">{`Bug report #${report.number} is sent`}</text>
              <text style="body" size="sm">{FIX_NOTE}</text>
              <text style="body" size="xs" tone="muted">
                    There is no status page: the maintainers email you when they have a question or a result.
                  </text>
              <div {...row} gap="small" flexWrap="wrap">
                    {menus(ctx, market)}
                    <spacer />
                    <button id="bug-fix-now" label="Try to fix it with an agent" small variant="primary" loading={!!state.busy[`fix:${report.id}`]} disabled={!state.menus?.agents?.length} onClick={() => ctx.run(market.fixReport(report))} />
                    <button id="bug-another" label="Report another bug" small variant="ghost" onClick={() => ctx.run(market.openBugForm())} />
                  </div>
            </card>
        {reportsList(ctx, market)}
      </div>
    );
  }
  if (bug.loading)
    return <div {...row} gap="small"><spinner /><text style="muted">Reading your plugins…</text></div>;
  if (bug.error)
    return (
      <div {...column} gap="small" alignItems="start">
        <text style="body" size="sm">{`Could not read your plugins: ${bug.error}`}</text>
        <button id="bug-draft-retry" label="Try again" small variant="outline" onClick={() => ctx.run(market.loadBugDraft())} />
      </div>
    );
  const plugins = bug.draft?.plugins ?? [];
  const attachments = bug.preview?.attachments ?? [];
  const waiting = !!bug.requestId;
  // The card attaches what the list shows, so it waits for the list of the current choice.
  const locked = waiting || bug.previewing;
  return (
    <div {...column} gap="large">
      <div {...column} gap="small">
          <text style="section">Report a bug</text>
          <div {...column} gap={4} padding="medium" borderRadius="md" background="primary/8"><text style="body" size="sm">{FIX_NOTE}</text></div>
        </div>
      <div {...column} gap="small">
          <text style="body" size="sm" bold>Related plugins</text>
          <text style="body" size="xs" tone="muted">
              The suggested ones are first: plugins you changed, and plugins the log names in an error.
            </text>
          <card {...column} maxHeight={280} overflowY="scroll">{plugins.map((plugin) => bugPluginRow(ctx, market, plugin))}</card>
        </div>
      <div {...column} gap="small">
          <text style="body" size="sm" bold>What happened, and what you expected</text>
          <input id="bug-text" value={bug.text} multiline placeholder="The steps, what happened, and what you expected" onChange={(e: ValueEvent<string>) => {
                    if (market.state.bug) market.state.bug.text = e.value;
                  }} />
        </div>
      {bug.draft?.signedIn
              ? null
              : (
                <div {...column} gap="small">
                  <text style="body" size="sm" bold>Contact email (optional)</text>
                  <input id="bug-email" value={bug.email} placeholder="Only the maintainers see it" onChange={(e: ValueEvent<string>) => {
                                  if (market.state.bug) market.state.bug.email = e.value;
                                }} />
                </div>
              )}
      <div {...column} gap="small">
          <div {...row} gap="small">
              <text style="body" size="sm" bold>Attachments</text>
              {bug.previewing ? <spinner /> : null}
              <spacer />
              <button id="bug-screenshots" label="Add screenshots…" icon="image" small variant="outline" onClick={() => ctx.run(market.addScreenshots())} />
            </div>
          <text style="body" size="xs" tone="muted">
              {"Everything checked is sent. Open each one to see exactly what it holds. Config and diagnostics go to the\n        Divergence maintainers only."}
            </text>
          {bug.previewError ? <text style="body" size="xs" tone="danger">{bug.previewError}</text> : null}
          <div {...column} gap="small">{attachments.map((attachment) => attachmentRow(ctx, market, attachment))}</div>
        </div>
      <card {...column} gap="small">
          <div {...row} gap="small" flexWrap="wrap">
              <button id="bug-review" label="Review and send…" small variant="primary" loading={!!state.busy["bug-review"]} disabled={locked} onClick={() => ctx.run(market.reviewReport(false))} />
              <button id="bug-review-fix" label="Send, then try to fix it with an agent…" small variant="outline" disabled={locked || !state.menus?.agents?.length} onClick={() => ctx.run(market.reviewReport(true))} />
              <spacer />
              {menus(ctx, market)}
            </div>
          <text style="body" size="xs" tone="muted">
              {waiting
                          ? "The card over the window shows everything that is sent. Send it there, or cancel."
                          : "Nothing is sent from here: a card shows exactly what is sent, and you send it there."}
            </text>
        </card>
      {reportsList(ctx, market)}
    </div>
  );
}

export function renderCenter(ctx: Ctx, market: Controller): Element | null {
  if (ctx.app.route !== ROUTE) return null;
  const { state } = market;
  const count = badgeCount(state.updates);
  // Profile while the account can be edited from here; signing out takes
  // the tab away and shows Browse.
  const editable = profileEditable(state.account);
  const tabs = [
    { id: "browse", label: "Browse" },
    { id: "updates", label: count ? `Updates (${count})` : "Updates" },
    { id: "bugs", label: "Bug reports" },
    ...(editable ? [{ id: "profile", label: "Profile" }] : []),
  ];
  const page = state.page === "profile" && !editable ? "browse" : state.page;
  const active = page === "updates" || page === "bugs" || page === "profile" ? page : "browse";
  const body =
    page === "updates"
      ? updatesPage(ctx, market)
      : page === "bugs"
        ? bugPage(ctx, market)
        : page === "profile"
          ? profilePage(ctx, market)
          : page === "listing"
            ? listingPage(ctx, market)
            : browsePage(ctx, market);
  // One left edge for the title, the tabs and the page under them (the
  // reading column's inset); the header's controls end on its right edge.
  return (
    <div {...column} {...fill} {...full} padding="small">
      <div {...column} {...reading} paddingX={24} paddingTop={20} gap={12}>
          <div {...row} gap="small" height={32}>
              <text style="body" size="xl" weight={600}>Marketplace</text>
              <spacer />
              {accountArea(ctx, market)}
              <button id="market-close" icon="x" variant="ghost" small tooltip="Back to chat" onClick={() => ctx.run(market.toggleRoute(true))} />
            </div>
          <tabs id="market-tabs" active={active} tabs={tabs} onChange={(e: ValueEvent<string>) => {
                    const page = e.value === "updates" || e.value === "bugs" || e.value === "profile" ? e.value : "browse";
                    ctx.run(market.selectPage(page));
                  }} />
        </div>
      <div {...column} {...fill} overflowY="scroll">
          <div {...column} {...reading} gap="large" paddingX={24} paddingTop={20} paddingBottom={32}>{body}</div>
        </div>
    </div>
  );
}

// The sidebar's Options menu draws every view whose id a plugin publishes in
// the app's shared state under a key starting with `sidebarMenu.`, above
// Settings, in the order of their keys: the account, then the Marketplace.
// The view published under PICTURE_ITEM is drawn in Options' circle.
export const SIDEBAR_ITEM = "sidebarMenu.market";
export const ACCOUNT_ITEM = "sidebarMenu.account";

// The account row at the top of the Options menu. Signed out, Sign in asks
// for a code and opens the sign-in page with it, and the row then shows the
// code until the browser approves it (a press opens the page again, the x
// stops waiting). Signed in, the row names the account and opens its
// profile page (its page on the website when the host cannot edit it), with
// Sign out under the pointer.
export function renderAccountItem(ctx: Ctx, market: Controller): Element | null {
  const { account, signIn, busy } = market.state;
  if (!account) return null;
  let item: ListItem;
  if (account.signedIn) {
    const record = "account" in account ? account.account : undefined;
    const label = accountName(record);
    item = { id: "sidebar-profile", icon: "user-round", label, sublabel: record?.email && record.email !== label ? record.email : undefined, onClick: () => ctx.run(market.openProfile()), actions: [{ icon: "log-out", tooltip: "Sign out", onClick: () => ctx.run(market.signOut()) }] };
  } else if (signIn) {
    item = { id: "sidebar-sign-in-code", icon: "external-link", label: `Code ${signIn.code}`, sublabel: "Approve it in your browser", onClick: () => ctx.run(market.openSignInPage()), actions: [{ icon: "x", tooltip: "Cancel", onClick: () => ctx.run(market.cancelSignIn()) }] };
  } else {
    item = { id: "sidebar-sign-in", icon: "log-in", label: busy["sign-in"] ? "Signing in…" : "Sign in", sublabel: account.expired ? "Your sign-in expired" : undefined, onClick: () => ctx.run(market.signIn(true)) };
  }
  return <list id="sidebar-account-list" items={[item]} />;
}

// The signed-in publisher's picture, drawn in the sidebar's Options circle.
export function renderPicture(market: Controller): Element | null {
  const { account } = market.state;
  const picture = account?.signedIn && "picture" in account ? account.picture : null;
  return picture ? <image path={picture} width={22} height={22} radius="full" /> : null;
}

// The Marketplace row in the sidebar's Options menu, like the Settings row under
// it: the update count at its end, selected while the page is open.
export function renderSidebarItem(ctx: Ctx, market: Controller): Element | null {
  const count = badgeCount(market.state.updates);
  const open = ctx.app.route === ROUTE;
  // A row of the sidebar's Options menu, so a dropdown list's row (`list`).
  return <list id="sidebar-market-list" items={[{ id: "sidebar-market", icon: "store", label: "Marketplace", selected: open, badge: count ? String(count) : undefined, onClick: () => ctx.run(market.toggleRoute(open)) }]} />;
}

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.