Skip to content

feat(canvas): one rich block vocabulary for the agent and its voice mode (abilityai/trinity-enterprise#536) - #2562

Merged
vybe merged 3 commits into
devfrom
feature/536-rich-canvas-vocabulary
Sep 7, 2026
Merged

vybe merged 3 commits into
devfrom
feature/536-rich-canvas-vocabulary

Conversation

@trinity-ability

Copy link
Copy Markdown
Contributor

Summary

  • New kinds + a wider chart. image (https URL · inline data:image raster ≤ 64 KiB · a workspace file through the authenticated preview route — one confinement gate for both writers), diagram (mermaid loaded lazily, strict with htmlLabels:false so DOMPurify does not blank every node, renders serialised), and chart on six types over the metric series shape series[{label, unit, points[{ts, value}]}] — a projection of the fix(SUB-003): rate-limit events age correctly; max_retries default → 0 (#476) #478 store so fix(deploy): align scripts, configs, and docs with production patterns (#504) #538 becomes a resolver, not a new kind. The ent#438 {labels, series[{data}]} shape still renders.
  • Rich fences + patch. A markdown block may carry chart / kpi / table / mermaid fences rendered by the same leaves (only an exact column-0 three-backtick fence with a usable body is extracted; everything else stays prose). Every stored block carries an id (b1..bN assigned); patch_canvas / PATCH …/canvas/{id} replaces named blocks in place, refuses unknown ids by name, and there is still no append.
  • One default canvas, one write path, write-side audience. main is what the MCP tools default to and what the voice panel draws on — no voice silo, no in-memory panel_state (the panel poll returns the row). canvas_service.write_canvas(audience=REQUIRED) is the only writer. Voice verbs are block edits on the voice* ids, so the agent's own board survives a call; a canvas stored wider than VoiceSession.canvas_audience (default operator; ent#534 sets roster) is refused with a spoken reason — never widens, never silently narrows. Both independent plan reviewers hit "voice replaces the whole canvas at an inherited audience" as the regret; this is the resolution.
  • The text agent is taught. ### Your Canvas in the platform prompt (tool guidance, MINIMAL-droppable), CI-pinned against the MCP BLOCK_KINDS enum and the frontend rules exactly as test_1535 pins the report block.

Security notes (read these)

  • Pre-existing HIGH resolved: TrendLineChart's hover tooltip concatenated agent-authored label/color into innerHTML and the canvas mounted it on the roster-visible Workspace. Rebuilt with createElement/textContent; colours hex-or-palette; labels plain text. (/cso --diff F2.)
  • Stated CSP posture change: img-src gains https: in both mirrors (vite.config.js, security-headers.conf). A web-URL image has been blocked by the browser since SEC: Missing Security Headers (CSP, X-Frame-Options, HSTS, etc.) #190 — feat: Voice Workspace canvas enrichment (Mermaid, images, panel history) + orb polish #979's "web URLs render directly" never held in production. Because the directive is page-global, the mitigation is too: utils/sanitizeHooks.js runs inside the app's one DOMPurify hook and gives every sanitised <img> referrerpolicy="no-referrer" and strips url()-bearing inline styles; the write gate admits https: only. Residual (documented): an https host of the agent's choosing sees a viewer's IP and view time. (/cso --diff F1, verifier-widened.) A Settings-surfaced host allowlist is a possible follow-up, not filed.
  • Report: docs/security-reports/cso-diff-2026-09-07-ent536-canvas-vocabulary.md.

Changes

  • Backend: models.py (kinds, id, CanvasPatch, caps, DEFAULT_CANVAS_ID), services/canvas_blocks.py (new pure leaf: image gate, ids, merges, voice verb mapper), services/canvas_service.py (write_canvas, patch_canvas, audience_within), routers/canvas.py (PATCH, # mcp: header), services/gemini_voice.py (panel tools → canvas, canvas_audience), routers/voice.py (panel returns the row), services/platform_prompt_service.py (### Your Canvas).
  • MCP: tools/canvas.ts (patch_canvas, default id, kind guide), client.ts.
  • Frontend: components/canvas/{canvasUtils.js, CanvasBlock, CanvasChart, CanvasPieChart, CanvasDiagram, CanvasImage, CanvasMarkdown, CanvasPanel}.vue, utils/{canvasPalette,sanitizeHooks,markdown}.js, TrendLineChart.vue + StackedBarChart.vue (labelFormat prop; index keys), the two CSP mirrors.
  • Docs: feature-flows/agent-canvas.md, requirements/core-agent.md §5.18 (FR-9..13), architecture/observability.md, flows index, learnings.md (two entries).
  • No DDL, no migration (ids and kinds live in the blocks JSON).

Test Plan

  • pytest tests/unit/test_ent536_canvas_vocabulary.py tests/unit/test_ent536_canvas_prompt_guidance.py tests/unit/test_ent438_agent_canvas.py tests/unit/test_voice_tools.py tests/unit/test_voice_auth.py — green; every unit file touching the changed modules (25 files): 713 passed, 2 skipped
  • src/frontend: npx vitest run — 2062 passed (incl. canvasUtils.spec.js, sanitizeHooks.spec.js); npm run check:tokens OK; raw-color ratchet did not grow; vite build OK (mermaid in its own chunk)
  • src/mcp-server: npm test — 314 passed; tsc --noEmit clean
  • Live on the rebuilt local backend: seeded a canvas with every kind, six chart types and all four fences; PUT assigns ids, PATCH replaces in place, every refusal is a named 400; Playwright in light and dark: charts, donut, both mermaid diagrams, fence figures, honest image placeholders, and (after the CSP change) a loaded https image — console clean of CSP errors
  • Not verified live: the issue's test-of-done ("a fresh agent asked in chat for a bar chart on its canvas produces one") needs a running agent with model credentials; the prompt is CI-pinned instead. Reviewer with a live agent: ask it in text chat.
  • Deferred with its consumer: a thin canvas_updated WS trigger lands with ent#534's canvas column.

Fixes abilityai/trinity-enterprise#536

🤖 Generated with Claude Code

https://claude.ai/code/session_013CgzGLnmPrQk6q5LqZCRru

sim and others added 3 commits September 7, 2026 11:26
…ode (abilityai/trinity-enterprise#536)

Widen the agent canvas so the text agent and its voice mode write the same
blocks onto the same default canvas, rendered by the same component wherever a
canvas is shown.

Vocabulary: `image` (https URL · inline data:image raster under 64 KiB ·
workspace path through the authenticated preview route, one confinement gate
for both writers) and `diagram` (mermaid loaded lazily, strict + htmlLabels
off, SVG through the one DOMPurify policy, renders serialised) join the kinds;
`chart` widens to line/area/bar/stacked_bar/pie/donut on the metric series
shape `series[{label, unit, points[{ts, value}]}]` (a projection of the
#478 store so #538 becomes a resolver, not a schema; the ent#438 shape stays
accepted). A `markdown` block may carry ```chart/```kpi/```table/```mermaid
fences rendered through the same leaves. Every stored block carries an id
(b1..bN assigned); `patch_canvas` / PATCH replaces named blocks in place and
refuses unknown ids by name — still no append.

One write path: `canvas_service.write_canvas` (audience REQUIRED) is the only
writer; the router and the voice panel tools both call it. `main` is the
default canvas for the MCP tools and the voice panel — no `voice` silo, no
in-memory `panel_state`; the panel poll returns the row. Voice verbs are block
edits on the `voice*` ids so the agent's own board survives a call, and a
canvas stored wider than the session's audience is refused with a spoken
reason. `### Your Canvas` teaches the text agent, CI-pinned against the MCP
enum and the frontend rules like the report block.

Security: the pre-existing trend-chart tooltip built innerHTML over
agent-authored labels/colours (roster-visible) — rebuilt with DOM APIs and
hex-only colours. CSP `img-src` gains `https:` in both mirrors so a web image
can load at all (never worked since #190); every sanitised <img> now carries
no-referrer and url()-bearing inline styles are stripped app-wide.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_013CgzGLnmPrQk6q5LqZCRru
…3 internals

`canvas.test.ts` reached the block-kind enum through `_def.type.shape` and
`_def.values`, which are zod v3 internals; the lockfile pins zod 4.5.4, where
`_def.type` is the literal string "array". The suite failed and `tsc --noEmit`
errored on a fresh `npm ci`. Use `.element` / `.options`, the public v4 API.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UFvKUcog6RtvSD7nVBhiaQ
…s-vocabulary

# Conflicts:
#	docs/memory/learnings.md

@vybe vybe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validated via /validate-pr: docs, security scans, packaging all clean. Fixed on-branch: canvas.test.ts used zod v3 internals against the zod 4.5.4 lockfile (MCP suite + tsc red on a fresh npm ci); merged dev resolving the learnings.md conflict. Local evidence on merged tree: pytest 273 passed, vitest 2085 passed, mcp-server 314 passed + tsc clean. CI: 26 pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants