| name | canv-extension-author |
| description | Use when the user asks you to build, edit, or debug a Canv extension. Triggers on "build me a Canv extension", "build me a Canv panel", "build me a fileHandler for X", "add a Canv extension that …", "write an extension for Canv that …", or any explicit request to add UI or functionality to Canv via its extension system. Provides the manifest schema, all six contribution types, runtime constraints, CSP rules, and working recipes. |
Canv extension author
You are building an extension for Canv — a desktop writing app (Electron + React + TypeScript). Extensions extend Canv's UI via six contribution types: panel, fileHandler, command, menu, statusBar, language. An extension is a directory with manifest.json plus entry files; users install via Extensions tab → "Install from folder…".
When to activate
Activate for:
- Creating a new Canv extension from scratch
- Editing an existing extension in the user's workspace
- Debugging an installed Canv extension
Do not activate for unrelated Canv tasks (writing markdown, configuring profiles, switching themes, etc.).
Workflow
- Pick contribution type(s). Read
contributions/<type>.md for each type you'll use.
- Read
reference/conventions.md once. It covers manifest fields, capability declarations, visual rules, and the pre-emit checklist — applies to every extension.
- Scaffold the directory. Default location:
<workspace>/canv-extensions/<extension-id>/. Confirm with the user if not obvious.
- Write
manifest.json + entry files. Use reference/manifest-schema.md for field-level details.
- Third-party libraries — if the extension needs an npm package:
- Tell the user to install: Extensions tab → "Install from folder…" → pick the extension dir → trust when prompted → enable.
Hard constraints
| Rule | Detail |
|---|
| CSP | script-src 'self' canv-extension://canv-shared. No CDN scripts. No inline <script>. No onclick="...". No eval. All JS in separate .js files; wire events with addEventListener. |
| Capabilities | Every canv.* call needs its capability in manifest.capabilities. See reference/canv-api.md for the mapping. Missing capability = silent runtime failure. |
| Panel location | "left-sidebar" or "bottom-dock" only. "right-sidebar" is rejected. |
| CSS tokens | Use --canv-* design tokens from the auto-injected canv-ui.css. Never hard-code hex / rgb / system fonts. |
| Icons | <canv-icon name="..."> only. Never <img> or emoji in UI chrome. |
| fileHandler read | activeDoc.read is required even for mode: "viewer". |
| Vendor libs | Must live in vendor/<name>.js, bundled self-contained. No CDN imports. |
Testing loop
After scaffolding:
- Tell the user: open Canv → Extensions tab → Install from folder → pick the dir → trust workspace + extension → enable.
- Manifest validation errors appear in the install consent modal. User reports; you regenerate.
- Runtime errors appear in the extension DevTools (right-click inside the panel → Inspect Extension). User pastes; you iterate.
- After any file change: uninstall + reinstall — Canv copies files at install time; changes are not picked up live.
Pre-emit checklist
Before reporting done:
Reference index
| File | Purpose |
|---|
contributions/panel.md | Panel contribution — activity-bar tab, iframe lifecycle |
contributions/fileHandler.md | File viewer/editor — byte-level read/write API |
contributions/command.md | Command palette + keybindings |
contributions/menu.md | File-tree context menu items |
contributions/statusBar.md | Status-bar items |
contributions/language.md | CodeMirror language contributions (red trust prompt — read this) |
reference/conventions.md | Manifest fields summary, visual rules, capability mapping |
reference/manifest-schema.md | Full Zod schema including settings + activationEvents |
reference/canv-api.md | Full canv.* API surface with capability mapping |
reference/csp-and-protocol.md | CSP details + canv-extension:// protocol |
reference/debugging.md | DevTools, reload, common errors |
recipes/ | Working examples: PDF viewer, chart panel, markdown render, word-count status bar |