visuals
HTML pages (html_preview, html_render) and native inline charts, positioned diagrams and sortable tables in agent replies.
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 convergence/visuals@0.2.0
Visuals — official plugin
convergence/visuals provides publish_visual for interactive, native visual
replies. It ships enabled on a fresh install; an existing install keeps the
choice it has, and users can turn it off or on in Settings → Plugins. It starts
only when a reply first contains one of its fences and loads Pele only on the
first Mermaid fence, so a chat without fences pays nothing. Its only requested
permission is tools.provide.
HTML pages (T3 Code's html_preview and html_render)
html.ts holds T3's contract (pingdotgg/t3code b24f0fbb): the tool names,
descriptions, limits (HTML 1–512000 UTF-16 units, title 1–200, preview width
240–1600 with 728 by default, frame height 80–2000), the result shapes and
messages, the frame-height rule, and the theme bootstrap with Divergence's
colours. Both tools are direct, so in code mode they stay tools of their
own and the preview's PNG reaches the agent as an MCP image part.
html_previewsends the themed page tohost/web.preview. With a confined renderer it answers T3's metadata as text and structured content plus the PNG. Without one it is an error,HtmlBackendUnavailable: <raw reason>, with no image: nothing renders unconfined and no screenshot is made up.html_rendersaves the agent's page unchanged as ahtmlv1 transcript artifact (the host stamps the owner) and answers T3'shtmlRenderreference and message. Measuredheightsare not supplied.- Inline (
html-view.ts) the page is live (ui.webDocument): borderless in the reply, as wide as the column and as tall as the page up to the agent's height, with one small glass Open in panel control. The panel is a detail-pane tab (theconvergence/tabsservice): the page live again, its Source, Copy and Save (kernel/copy_text,kernel/save_text, both after a click).
The renderer is the host's: Debian's Chromium in a disposable container of
the local Docker engine, admitted through chrome://sandbox
(crates/host/src/web). Differences from T3 and from a system web view:
pages are offline (remote URLs and local image paths never load;
missingImages lists the paths a page names), fonts and text metrics are
Linux's (DejaVu, Liberation, Noto Color Emoji), there is no GPU, and native
browser menus, pickers, IME composition, accessibility, clipboard and drag
from the page are not available. Without Docker or the built renderer image
the page says why and its source, copy and save still work.
Version 2 supports responsive multi-panel compositions: bar (grouped/stacked/
percent; horizontal/vertical), line, area, scatter/bubble, pie/donut, heatmap,
histogram, range/timeline, waterfall and boxplot, plus metrics, text, typed tables
and positioned diagrams. document.ts defines the strict, bounded JSON schema;
rules.md is the agent-facing reference. Version 1 documents still replay.
Rendering and interaction
Rust/GPUI draws every shape, label, control and floating tooltip. A pinned,
DOM-free D3 math subset computes scales, numeric/UTC ticks and paths inside
QuickJS; there is no browser, JavaScript UI execution, graph auto-layout, network,
file, process or plugin-storage access. math.LICENSES.txt includes provenance
and licenses; scripts/bundle-visuals-math.mjs reproduces the readable bundle.
Charts use the native canvas's onResize({width,height}) logical-pixel measurement,
not a scaled viewBox. Text remains readable as panels grow or wrap. Compact
legends keep original domains, colors and percentage denominators when hidden.
Null breaks paths and stays explicitly missing in shared bar inspection.
Hover opens a clamped floating tooltip; click pins/unpins. Arrow keys, Home/End traverse observations, Enter/Space pin, Escape clears inspection. In the expanded overlay Escape unpins first, then closes. Tables retain stable raw row identity, sort nulls last in either direction, paginate and expose full selected values. Diagram node details remain accessible through a native picker.
State and cached geometry belong to each artifact's ctx.state, with separate
panels and inline/expanded inspection. Hover does not recompute paths. Native
resize reports are change-only and coalesced off-paint. No JavaScript frame loop
or render-time notification runs.
Persistence and compatibility
The host owns immutable transcript artifacts. ctx.artifacts.publish persists
the complete document independently of the surrounding tool result, including
discarded acknowledgements and later code-mode errors. The plugin registers
removable visual renderers for versions 1 and 2; Source retains original input
and Data retains all raw values, including hidden series and nulls.
This plugin requires the updated native host and canvas resize API. Older hosts without artifact support fail with an explicit update message. Invalid persisted documents keep their readable summary and expose a validation error.
Verification
node --import ./plugins/testing/register.mjs --test plugins/visuals/*.test.ts
pnpm -C plugins typecheck
pnpm -C plugins exec prettier --check 'visuals/**/*.{ts,json,md}'
Geometry tests use asymmetric data and independent numeric expectations; view tests exercise real native element factories and handlers. Native desktop checks and app-owned Metal captures supplement these tests; they do not use a browser.
Permissions in 0.2.0
Files
// Scoped native renderer/tool wiring. The host persists publications in the transcript,
// independently of an outer code-mode tool result; the plugin never stores documents itself.
import * as Data from "effect/Data";
import * as Effect from "effect/Effect";
import * as Stream from "effect/Stream";
import * as z from "zod";
import { Plugin, Services, Tools, Views, promise, runPlugin } from "convergence/effect";
import type { EffectClient } from "convergence/effect";
import type { Tabs } from "../tabs/contract.ts";
import type { ToolContext } from "convergence";
import { visualDocumentSchema } from "./document.ts";
import type { VisualDocument } from "./document.ts";
import { renderArtifact } from "./views.ts";
import { renderMermaid } from "./mermaid.ts";
import {
HTML_PREVIEW_DESCRIPTION,
HTML_RENDER_DESCRIPTION,
htmlPreviewInput,
htmlPreviewOutput,
htmlRenderInput,
htmlRenderOutput,
} from "./html.ts";
import { previewHtml, renderHtml } from "./html-tools.ts";
import { htmlRenderer, newPanelState, renderPanel } from "./html-view.ts";
import type { PanelPage } from "./html-view.ts";
export class VisualHostRequired extends Data.TaggedError("VisualHostRequired")<{ readonly message: string }> {}
export const publishVisual = Effect.fn("Visuals.publish")(function* (document: VisualDocument, ctx: ToolContext) {
if (!ctx.artifacts || typeof ctx.artifacts.publish !== "function")
return yield* new VisualHostRequired({
message: "Visual replies require a newer Convergence host with transcript artifacts.",
});
const result = yield* promise("artifacts.publish", () =>
ctx.artifacts.publish({
type: "visual",
version: document.version,
title: document.title,
summary: document.summary,
data: document,
}),
);
return { artifactId: result.id, published: true as const };
});
export const program = Effect.gen(function* () {
const { api } = yield* Plugin;
if (typeof api.artifactRenderer !== "function")
return yield* new VisualHostRequired({
message:
"Visual replies require a newer Convergence host with native artifact rendering. Update the app before enabling Visuals.",
});
// The detail pane's HTML page: one view, a tab of the tabs plugin when it runs.
const panel = newPanelState();
const panelView = yield* (yield* Views).slot<Record<string, unknown>>("visuals-page", (ctx) =>
renderPanel(api, panel, ctx),
);
let tabs: EffectClient<typeof Tabs> | undefined;
yield* (yield* Services).when<typeof Tabs>("convergence/tabs").pipe(
Stream.runForEach((option) =>
Effect.sync(() => {
tabs = option._tag === "Some" ? option.value : undefined;
}),
),
Effect.forkScoped({ startImmediately: true }),
);
const openPanel = (page: PanelPage) => {
panel.page = page;
panel.tab = "rendered";
panel.notice = null;
panelView.update();
const workspaceId = api.app.state().workspaceId;
if (!tabs || !workspaceId) {
api.notify("The detail pane is not available, so the page cannot open in a panel.", "warning");
return;
}
Effect.runPromise(
tabs.open({
kind: "view",
workspaceId,
path: `html/${page.item}`,
title: page.document.title,
icon: "code",
view: panelView.id,
}),
).catch((error: unknown) => {
// The tabs plugin's own answer, shown as it is: in a notice and in the panel.
// A service failure is a tagged value with a message, not always an Error.
const message =
typeof error === "object" && error !== null && "message" in error
? String((error as { message: unknown }).message)
: String(error);
api.notify(`The page could not open in a panel: ${message}`, "error");
panel.notice = message;
panelView.update();
});
};
const renderers = [
...[1, 2].map((version) => ({ type: "visual", version, render: renderArtifact })),
{ type: "html", version: 1, render: htmlRenderer(openPanel) },
];
for (const renderer of renderers)
yield* Effect.acquireRelease(
Effect.sync(() => api.artifactRenderer(renderer)),
(registration) => Effect.sync(() => registration.remove()),
);
// Older hosts have no fence renderers; there a mermaid fence stays a code block.
const fences = api.fences;
if (fences)
yield* Effect.acquireRelease(
Effect.sync(() => fences.svg("mermaid", renderMermaid)),
(registration) => Effect.sync(() => registration.remove()),
);
const tools = yield* Tools;
// T3's HTML tools, under their own names in code mode too: the preview's PNG must reach the
// agent as an image, which an `execute` program's JSON return would turn into text.
yield* tools.register({
name: "html_preview",
title: "Preview HTML",
description: HTML_PREVIEW_DESCRIPTION,
direct: true,
input: htmlPreviewInput,
output: htmlPreviewOutput,
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
run: (input) => previewHtml(api, input),
});
yield* tools.register({
name: "html_render",
title: "Render HTML",
description: HTML_RENDER_DESCRIPTION,
direct: true,
input: htmlRenderInput,
output: htmlRenderOutput,
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: false, openWorldHint: false },
run: renderHtml,
});
yield* tools.register({
name: "publish_visual",
title: "Publish visual reply",
description:
"Publish an interactive native visual reply. Prefer version 2: a titled, explained document with up to 12 responsive panels (charts, metrics, text, tables, positioned diagrams). Charts include grouped/stacked/percent bars, line/area with category/numeric/UTC axes, scatter/bubbles, pie/donut, heatmap, histogram, range/timeline, waterfall and boxplot. Use raw values and null for missing observations; native tooltips, pinned inspection and legends are automatic. Version 1 remains supported. No UI code, HTML, SVG or external resources. Publications persist even when an outer execute result is discarded; the small result acknowledges publication.",
input: visualDocumentSchema,
output: z.strictObject({ artifactId: z.string().min(1), published: z.literal(true) }),
annotations: { destructiveHint: false, idempotentHint: false, openWorldHint: false },
run: publishVisual,
});
});
export const activate = runPlugin(program);
No comments yet.