agent-canvas
by arvsrn
README.md
# agent-canvas
A shared canvas where agents put images and people leave comments on them.
- Agents use the MCP server to make files and sections, add images and read comments.
- People pan and zoom the canvas, then click (point) or drag (area) on an image to comment.
- The canvas is the source of truth. Any agent session can read what's open and mark comments as addressed.
## Run
```sh
bun install
bun run dev # API + MCP on :4400, web app on :4401
bun scripts/seed.ts # optional demo canvases
```
Open http://localhost:4401.
Production: `bun run build && AGENT_CANVAS_PUBLIC_URL=https://… bun run start` serves the web app and API from one port (`PORT`, default 4400). Data lives in `./data` (`AGENT_CANVAS_DATA` to change).
## Connect an agent
MCP endpoint: `http://localhost:4400/mcp` (streamable HTTP, no auth).
OpenCode (`~/.config/opencode/opencode.json`):
```json
{ "mcp": { "agent-canvas": { "type": "remote", "url": "http://localhost:4400/mcp" } } }
```
The agent guide is in `skill/agent-canvas/SKILL.md`. Short instructions are also sent by the MCP server itself.
Images can also be uploaded without MCP:
```sh
curl -F image=@shot.png -F title="Settings dialog, dark mode" -F section=dialogs -F scale=2 \
http://localhost:4400/api/files/desktop-audit/images
```
## How it's built
- `shared/layout.ts`: section grid layout and relative section placement, used by server and client.
- `server/`: Bun, SQLite (`bun:sqlite`), sharp. Images are stored by content hash with 256px and 1024px versions, plus 32, 128 and 512px squares (the image stretched to fill) that the client packs into texture atlases. `/thumbs/<size>?h=<hash>,…` returns many squares in one response.
- `mcp.ts`: tools and instructions. Every call is logged to the `mcp_log` table for reviewing how agents use it.
- `render.ts`: server-side rendering for `view`, `get_image` and `view_comments`.
- `index.ts`: HTTP, assets, and the per-file WebSocket (changes, presence, cursors).
- `web/`: Svelte 5. Three layers:
- Scene (`canvas/scene.ts`): the layout packed into flat arrays with a uniform grid over the images, rebuilt only when the document changes. Culling and hit testing cost what's on screen, not what's in the file.
- WebGPU (`canvas/renderer.ts`): sections, images, pixel grid at 800%+. Images up to 640 device pixels draw from atlas pages of square thumbnails (32, 128 or 512px slots by on-screen size), one instanced draw call per page. Bigger ones get their own texture at the server tier they need, with nearest sampling when magnified. Loads go nearest-to-centre first, and atlas slots and textures are evicted least recently drawn first.
- Canvas 2D (`canvas/labels.ts`): section chips and image titles at a fixed screen size.
- DOM: comments, clusters, cursors, menus. Pins sit at world positions and are placed in CSS from `--cx`, `--cy` and `--s` on the canvas, so panning doesn't rerender them. Only pins near the viewport are in the DOM.
Performance: press Shift+P (or add `?perf` to the URL) for frame times, draw calls and texture memory. `bun scripts/bulk.ts 30000` fills a file with 30,000 images from existing assets, and `scripts/bench.browser.js` drives a fixed pan and zoom path in the page and reports per-frame main-thread time.
Reviewing agent behaviour:
```sh
sqlite3 data/agent-canvas.sqlite "select datetime(ts/1000,'unixepoch'), tool, ok, args from mcp_log order by id desc limit 50"
```
## License
MIT
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues