AI-native design editor. Open-source Figma alternative.
docs: refresh agent guide
Danila Poyarkovd195bb67d27d
diff --git a/AGENTS.md b/AGENTS.mdindex 61b6d7ba1..75db9178d 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -2,128 +2,68 @@Vue 3 + CanvasKit (Skia WASM) + Yoga WASM design editor. Tauri v2 desktop, also runs in browser.-**Roadmap:** `packages/docs/development/roadmap.md` tracks product direction, Figma compatibility gaps, and raw metadata coverage. Current architecture and commands live in this file.+**Roadmap:** `packages/docs/development/roadmap.md` tracks product direction, Figma compatibility gaps, and raw metadata coverage. This file keeps agent-facing architecture, conventions, and commands; detailed public docs live under `packages/docs/**`.## MonorepoBun workspace packages:-- `packages/core` — `@open-pencil/core`: scene graph, renderer, layout, codec, kiwi, clipboard, vector, snap, undo. Zero DOM deps, runs headless in Bun.-- `packages/cli` — `@open-pencil/cli`: headless CLI for .fig inspection, export, linting. Uses `citty` + `agentfmt`.-- `packages/docs` — `@open-pencil/docs`: VitePress documentation site. Run with `cd packages/docs && bun run dev`.-- `packages/mcp` — `@open-pencil/mcp`: MCP server for AI coding tools. Stdio + HTTP (Hono). Reuses `createServer()` factory with all core tools.-- `packages/dom-css` — `@open-pencil/dom-css`: DOM/CSS projection layer for HTML/CSS/JSX/Tailwind compatibility. Owns DesignDOM types and browser/headless CSS runtime adapters; depends on core scene-graph types but keeps DOM/CSS parser dependencies out of core.+- `packages/scene-graph` — `@open-pencil/scene-graph`: SceneGraph, node types, copy/snap/undo helpers, variables, instances, hit testing. Framework-agnostic.+- `packages/pen` — `@open-pencil/pen`: Pen/vector editing helpers shared by core/editor surfaces.- `packages/kiwi` — `@open-pencil/kiwi`: pure Kiwi schema/runtime/protocol package. Owns low-level Figma Kiwi codec/container/parse helpers and stays SceneGraph-agnostic.-- `packages/fig` — `@open-pencil/fig`: scaffold for future `.fig` document policy package. Planned home for SceneGraph ⇄ NodeChange conversion, raw metadata invalidation, and component/instance interpretation; production `.fig` APIs still live in core for now.-+- `packages/fig` — `@open-pencil/fig`: publishable `.fig` package shell and low-level smoke/test boundary. Production SceneGraph `.fig` policy still lives mostly in core while this package grows.+- `packages/core` — `@open-pencil/core`: renderer, layout, editor core, Figma API, tools, clipboard, vector conversion, and app/CLI-facing document I/O. Depends on scene-graph/pen/kiwi but keeps browser DOM out of core.+- `packages/dom-css` — `@open-pencil/dom-css`: DOM/CSS projection layer for HTML/CSS/JSX/Tailwind compatibility. Owns DesignDOM types and browser/headless CSS runtime adapters; keeps DOM/CSS parser dependencies out of core.- `packages/vue` — `@open-pencil/vue`: headless Vue 3 SDK (Reka UI-style) for building custom OpenPencil-powered editor shells and embedded editing surfaces. Renderless components and composables. The app is one consumer of the SDK.+- `packages/cli` — `@open-pencil/cli`: headless CLI for .fig inspection, export, linting. Uses `citty` + `agentfmt`.+- `packages/mcp` — `@open-pencil/mcp`: MCP server for AI coding tools. Stdio + HTTP (Hono). Reuses core tools.+- `packages/docs` — `@open-pencil/docs`: published VitePress documentation site. Run with `bun run docs:dev`.The root app (`src/`) is the Tauri/Vite desktop editor. App-specific editor, document, AI, collaboration, shell, tabs, demo, and automation code lives under `src/app/*`. The app consumes scene graph primitives from `@open-pencil/scene-graph`, editor/rendering services through targeted `@open-pencil/core` subpath exports, and `@open-pencil/vue` through the public Vue SDK entrypoint.-### Core subpath exports--`@open-pencil/core` exposes domain-specific subpath exports for targeted imports. The main `"."` entry re-exports everything for backward compatibility.--| Subpath | What | Heavy dep isolated |-|---|---|---|-| `@open-pencil/core` | editor/rendering engine barrel | all core subsystems |-| `@open-pencil/scene-graph` | SceneGraph, node types, hit-test, copy, snap, undo | — |-| `@open-pencil/core/color` | parseColor, colorToHex, color management, OkHCL | culori |-| `@open-pencil/core/text` | fonts, text editor, style runs, direction | — |-| `@open-pencil/core/vector` | vector network encode/decode, bezier math | — |-| `@open-pencil/core/figma-api` | FigmaAPI, FigmaNodeProxy | — |-| `@open-pencil/core/icons` | Iconify API client, icon rendering | @iconify/utils |-| `@open-pencil/core/canvas` | SkiaRenderer (Skia/CanvasKit painting engine) | — |-| `@open-pencil/core/design-jsx` | JSX-to-design renderer | sucrase |-| `@open-pencil/core/editor` | createEditor, Editor, EditorState | — |-| `@open-pencil/core/tools` | ToolDef, ALL_TOOLS, AI adapter | diff |-| `@open-pencil/core/kiwi` | .fig parse/serialize, codec, protocol | fflate, fzstd |-| `@open-pencil/core/clipboard` | Figma/OpenPencil clipboard parsing and import helpers | — |-| `@open-pencil/core/rpc` | RPC commands for CLI | — |-| `@open-pencil/core/lint` | design linter rules and presets | — |-| `@open-pencil/core/profiler` | render profiling | — |-| `@open-pencil/core/canvaskit` | getCanvasKit loader | canvaskit-wasm |-| `@open-pencil/core/layout` | computeLayout | yoga-layout |--Runtime `canvaskit-wasm` import exists only in `canvaskit.ts` — all other files use `import type`. CanvasKit instance is passed as a parameter everywhere.+### Public package exports-### Editor architecture+Use public package exports across package/app boundaries. Do not import workspace package internals from app code.-`packages/core/src/editor/` is the framework-agnostic editor core — 13 modules sharing an `EditorContext` interface:--| Module | What |-|---|---|-| `types.ts` | EditorState, EditorOptions, EditorEvents, Tool, EditorToolDef, EditorContext |-| `create.ts` | `createEditor()` assembler — wires context, event bus + all modules |-| `viewport.ts` | screenToCanvas, applyZoom, pan, zoomToFit/100/Selection |-| `selection.ts` | select, clearSelection, marquee, snap, hover, entered container |-| `pages.ts` | switchPage, addPage, deletePage, renamePage |-| `shapes.ts` | createShape, pen tool, adoptNodesIntoSection |-| `structure.ts` | group, ungroup, wrapInAutoLayout, reorder, reparent, z-order |-| `components.ts` | component/instance/detach/componentSet |-| `clipboard.ts` | duplicate, copy, paste, delete, storeImage |-| `undo.ts` | commitMove/Resize/Rotation, snapshot/restore |-| `text.ts` | startTextEditing, commitTextEdit |-| `nodes.ts` | updateNode, updateNodeWithUndo, setLayoutMode |--Each module exports a factory: `createXxxActions(ctx: EditorContext) => { ... }`.-`create.ts` assembles context + all modules, spreads into a flat return object.-`Editor` type = `ReturnType<typeof createEditor>`.+- `@open-pencil/scene-graph` — SceneGraph, node types, primitives, copy/snap/undo, instance helpers, variable helpers, vector-network types.+- `@open-pencil/core` — broad compatibility barrel for editor/rendering/tooling APIs.+- Common targeted core subpaths keep imports smaller and dependency intent clearer: `@open-pencil/core/color`, `/text`, `/vector`, `/figma-api`, `/icons`, `/canvas`, `/design-jsx`, `/editor`, `/tools`, `/kiwi`, `/clipboard`, `/rpc`, `/lint`, `/profiler`, `/io`, `/canvaskit`, `/layout`.+- Use `@open-pencil/kiwi` for low-level Kiwi/FIG schema-runtime, codec, container, GUID, and parse helpers.-#### Editor event bus+CanvasKit runtime loading is centralized in `@open-pencil/core/canvaskit` for app/browser use. Headless raster export may dynamically load `canvaskit-wasm/full`; elsewhere prefer `import type` and pass the CanvasKit instance in.-The editor exposes a typed nanoevents emitter for lifecycle events. Defined in `EditorEvents` (`types.ts`), emitted via `emitEditorEvent()` on the context, subscribed via `editor.onEditorEvent(event, handler)` which returns an unbind function.+### Editor architecture-| Event | Payload | Emitted by |-|---|---|---|-| `render:requested` | `{ renderVersion, sceneVersion }` | `requestRender()` |-| `repaint:requested` | `{ renderVersion, sceneVersion }` | `requestRepaint()` |-| `graph:replaced` | `SceneGraph` | `replaceGraph()` |-| `node:created` | `SceneNode` | SceneGraph emitter → `graph-events.ts` |-| `node:updated` | `id, changes` | SceneGraph emitter → `graph-events.ts` |-| `node:deleted` | `id` | SceneGraph emitter → `graph-events.ts` |-| `node:reparented` | `nodeId, oldParentId, newParentId` | SceneGraph emitter → `graph-events.ts` |-| `node:reordered` | `nodeId, parentId, index` | SceneGraph emitter → `graph-events.ts` |-| `selection:changed` | `selectedIds[], previousIds[]` | `setSelectedIds()` |-| `tool:changed` | `tool, previousTool` | `setActiveTool()` |-| `page:changed` | `pageId, previousPageId` | `switchPage()`, `replaceGraph()` |-| `viewport:changed` | `{ panX, panY, zoom }, previous` | viewport actions |+`packages/core/src/editor/` is the framework-agnostic editor core. `createEditor()` in `create.ts` assembles an `EditorContext` plus domain action modules for viewport, selection, pages, shapes, structure, components, clipboard, undo/history, text, variables, layout, color space, graph reads, tool registry, and related helpers. Check the folder before adding editor behavior; keep new actions in the nearest domain module/folder instead of growing unrelated files.-All selection mutations in core use `ctx.setSelectedIds()` and all tool changes use `ctx.setActiveTool()` so the event bus fires consistently. App-layer code uses `editor.clearSelection()`, `editor.select()`, or `editor.setTool()` — never direct `state.selectedIds =` or `state.activeTool =` assignments.+`Editor` type = `ReturnType<typeof createEditor>`. Core modules should share state through `EditorContext` rather than importing app code or Vue.-Vue SDK provides `useEditorEvent(event, handler)` composable (`packages/vue/src/editor/events/use.ts`) that auto-disposes on scope cleanup.+#### Editor event bus-The app editor session (`src/app/editor/session/create.ts`) is a thin Vue wrapper: creates `shallowReactive` state, calls `createEditor()`, and assembles app-specific modules for document I/O, autosave, export, vector edit, pen resume, flashes, profiler, and mobile clipboard. Tabs live in `src/app/tabs/`; active editor access lives in `src/app/editor/active-store/`.+The editor exposes a typed nanoevents emitter. Event names/payloads live in `EditorEvents` in `packages/core/src/editor/types.ts`; graph events are bridged from SceneGraph by `graph-events.ts`. Subscribe with `editor.onEditorEvent(event, handler)`, or in Vue use `useEditorEvent(event, handler)` from `packages/vue/src/editor/events/use.ts`.++Important invariant: all selection mutations in core go through `ctx.setSelectedIds()` and all tool changes go through `ctx.setActiveTool()` so events fire consistently. App-layer code should use editor actions such as `clearSelection()`, `select()`, or `setTool()` — never direct `state.selectedIds =` or `state.activeTool =` assignments.++The app editor session (`src/app/editor/session/create.ts`) is a Vue wrapper around core: it creates reactive state, calls `createEditor()`, and assembles app-specific document I/O, autosave, export, vector edit, pen resume, flashes, profiler, and mobile clipboard. Tabs live in `src/app/tabs/`; active editor access lives in `src/app/editor/active-store/`.## Commands- `bun run check` — type-aware lint + typecheck via oxlint + tsgo + architecture checks (run before committing)- `bun run check:arch` — Steiger architecture lint for project-specific import boundaries-- `bun run check:vue` — vue-tsc type-check for .vue files (has pre-existing errors, fix progressively)+- `bun run check:vue` — vue-tsc type-check for app and Vue SDK .vue files- `bun run test:dupes` — jscpd copy-paste detection across product TS sources- `bun run test:tools` — tests for private repo tooling under `tools/*`- `bun run format` — oxfmt with import sorting-- `bun test ./tests/engine` — unit tests-- `bun run test` — Playwright visual regression+- `bun run test:unit` — engine/unit tests+- `bun run test` — Playwright E2E and visual regression tests- `bun run tauri dev` — desktop app with hot reload-- `bun open-pencil info <file>` — document stats-- `bun open-pencil tree <file>` — node tree-- `bun open-pencil find <file>` — search nodes-- `bun open-pencil node <file> --id <id>` — detailed node properties-- `bun open-pencil pages <file>` — list pages-- `bun open-pencil variables <file>` — list design variables-- `bun open-pencil export <file>` — headless render to PNG/JPG/WEBP-- `bun open-pencil analyze colors <file>` — color palette usage-- `bun open-pencil analyze typography <file>` — font/size/weight stats-- `bun open-pencil analyze spacing <file>` — gap/padding values-- `bun open-pencil analyze clusters <file>` — repeated patterns-- `bun open-pencil eval <file> --code '<js>'` — execute JS with Figma Plugin API+- `bun open-pencil --help` — list CLI commands. Common commands include `info`, `tree`, `find`, `node`, `pages`, `variables`, `export`, `convert`, `lint`, `query`, `selection`, `formats`, `analyze ...`, and `eval` for Figma Plugin API scripting.## Releases & CI### How to release-1. Update version in `package.json`, `packages/core/package.json`, `packages/cli/package.json`, `packages/dom-css/package.json`, `packages/mcp/package.json`, `packages/vue/package.json`, `desktop/tauri.conf.json`, and `desktop/Cargo.toml`+1. Update version in the root `package.json`, publishable `packages/*/package.json`, `desktop/tauri.conf.json`, and `desktop/Cargo.toml`2. Update `CHANGELOG.md` — move "Unreleased" items under new version heading with date3. Commit: `Release v0.x.y`4. Tag: `git tag v0.x.y && git push --tags`@@ -131,31 +71,12 @@ The app editor session (`src/app/editor/session/create.ts`) is a thin Vue wrappe6. The `build.yml` workflow triggers on `v*` tags and:- Builds Tauri binaries for macOS (arm64 + x64), Windows (x64 + arm64), Linux (x64)- Creates a draft GitHub Release with all platform binaries- - Publishes `@open-pencil/core`, `@open-pencil/cli`, `@open-pencil/dom-css`, `@open-pencil/mcp`, and `@open-pencil/vue` to npm with provenance+ - Publishes public workspace packages to npm with provenance. Keep the exact package list in sync with `.github/workflows/build.yml`.7. Go to GitHub Releases → edit the draft → paste changelog section → publish### CI workflows-| Workflow | Trigger | What it does |-|----------|---------|--------------|-| `build.yml` | `v*` tag push or manual | Build Tauri desktop apps (5 targets), create GitHub Release, publish `@open-pencil/core`, `@open-pencil/cli`, `@open-pencil/dom-css`, `@open-pencil/mcp`, and `@open-pencil/vue` |-| `homebrew.yml` | Release published | Update `open-pencil/homebrew-tap` cask with new version + SHA256 hashes |-| `app.yml` | Push to `master` (non-docs) | Build web app, deploy to Cloudflare Pages (`app.openpencil.dev`) |-| `docs.yml` | Push to `master` (`packages/docs/**`) | Build VitePress docs, deploy to Cloudflare Pages (`openpencil.dev`) |--### Before committing--Run all quality gates (see [Code quality](#code-quality) for the self-review checklist):--```sh-bun run check # oxlint + tsgo type-aware lint & typecheck-bun run format # oxfmt-bun run test:dupes # jscpd — zero clones-bun run test:tools # private repo tooling tests-bun run test:unit # bun:test-cd packages/dom-css && bun run check # standalone DOM/CSS package checks-bun run test # Playwright E2E-```+Key workflows live in `.github/workflows/`. Use `build.yml` as the source of truth for release packaging and npm publishing, `ci.yml` / `heavy-tests.yml` for validation gates, and `app.yml` / `docs.yml` for Cloudflare Pages deploys.## Documentation@@ -192,62 +113,33 @@ Release commits are the exception: keep using `Release v0.x.y`.- All CLI output must use `agentfmt` formatters — `fmtList`, `fmtHistogram`, `fmtSummary`, `fmtNode`, `fmtTree`, `kv`, `entity`, `bold`, `dim`, etc.- Don't hand-roll `console.log` formatting — use the helpers from `packages/cli/src/format.ts` which re-exports agentfmt with project-specific adapters (`nodeToData`, `nodeDetails`, `nodeToTreeNode`, `nodeToListItem`)-- Every command supports `--json` for machine-readable output+- CLI data/inspection commands should support `--json` for machine-readable output## Tools (AI / MCP / CLI)-- Tool operations live in `packages/core/src/tools/` as framework-agnostic `ToolDef` objects, split by domain:- - `schema.ts` — `ToolDef` type, `defineTool()`, shared helpers (`nodeSummary`, `nodeToResult`)- - `read.ts` — query tools: selection, find, pages, fonts, components- - `create.ts` — shape/component/page creation, JSX render- - `modify.ts` — property setters: fills, strokes, effects, text, layout- - `structure.ts` — tree ops: delete, clone, reparent, group, arrange- - `variables.ts` — variable/collection CRUD and binding- - `vector.ts` — boolean ops, paths, viewport, SVG/image export- - `analyze.ts` — analyze (colors, typography, spacing, clusters), diff, eval- - `registry.ts` — assembles all tools into the `ALL_TOOLS` array-- Each tool has: name, description, typed params, and an `execute(figma: FigmaAPI, args)` function-- `defineTool()` gives type-safe params in the execute body; the array `ALL_TOOLS` erases the generics for adapters-- AI adapter (`packages/core/src/tools/ai-adapter.ts`): `toolsToAI()` converts ToolDefs → valibot schemas + Vercel AI `tool()` wrappers-- `src/app/ai/tools/index.ts` is just a thin wire: creates FigmaAPI from editor store, calls `toolsToAI()`-- CLI commands (`packages/cli/src/commands/`) are **not** generated from ToolDefs — they have custom agentfmt formatting, tree walking, pagination. The `eval` command is the CLI's access to all ToolDef operations via FigmaAPI.-- MCP adapter (`packages/mcp/src/server.ts`): `startServer()` creates unified HTTP + WebSocket server. Registers all ToolDefs as MCP tools (zod schemas). Single entry point: `index.ts` (Hono + Streamable HTTP with sessions). Browser connects via WebSocket, tool calls proxied through.-- MCP-only tools (`open_file`, `new_document`, `save_file`, `get_codegen_prompt`) are registered directly in `server.ts`, not as ToolDefs — they need Node.js fs access or don't operate on the scene graph-- `open_file` and `new_document` are only registered when `OPENPENCIL_MCP_ROOT` is set (path scoping for security)-- Export tools (`export_image`, `export_svg`, `get_jsx`) accept an optional `path` param — when provided and `OPENPENCIL_MCP_ROOT` is set, the MCP server writes output to disk and returns `{ written, byteLength }` instead of the raw data-- Core prompts (`CODEGEN_PROMPT`, `JSX_REFERENCE`) live as markdown files in `packages/core/src/tools/prompts/`, loaded via raw-md bundler plugin; app chat/ACP prompts live under `src/app/ai/**` markdown files.-- To add a new tool: add a `defineTool()` in the appropriate domain file, add to `ALL_TOOLS` in `registry.ts` — it's instantly available in AI chat, MCP, and via `eval` in CLI-- `FigmaAPI` (`packages/core/src/figma-api/`) is the execution target for all tools — Figma Plugin API compatible, uses Symbols for hidden internals--## ACP (Agent Client Protocol)--- ACP transport (`src/app/ai/acp/transport.ts`) spawns agents via dynamic import of `@tauri-apps/plugin-shell`-- Pure mapping logic in `src/app/ai/acp/map-update.ts` — converts `SessionUpdate` → `UIMessageChunk`-- ACP design context prompt (`ACP_DESIGN_CONTEXT`) is authored in `src/app/ai/acp/design-context.md` and re-exported from `src/constants.ts`-- Agent definitions (`ACP_AGENTS`) in `packages/core/src/constants.ts`-- MCP server: Vite plugin in dev, `openpencil-mcp` via shell plugin in production Tauri (requires `npm i -g @open-pencil/mcp`; follow-up: bundle as Tauri sidecar)-- Architecture: browser ↔ WebSocket :7601 ↔ MCP server :7600 ↔ HTTP ↔ agent subprocess-- Shell permissions scoped per-command in `desktop/capabilities/default.json` (`args: true` — agents need dynamic SDK flags)-- ACP providers visible only in Tauri desktop when MCP server is reachable-- Permission requests shown in AlertDialog — user must approve/reject each request (60s auto-reject timeout)--## Collaboration--- P2P via Trystero (WebRTC) — no server relay. Signaling over MQTT public brokers.-- Yjs CRDT for document state sync. Awareness protocol for cursors/selections/presence.-- y-indexeddb for local persistence — room survives page refresh.-- Constants in `src/constants.ts`: `TRYSTERO_APP_ID`, `PEER_COLORS`, `ROOM_ID_LENGTH`, `ROOM_ID_CHARS`, `YJS_JSON_FIELDS`-- `src/app/collab/use.ts` — composable: connect/disconnect, cursor/selection broadcasting, follow mode, Yjs ↔ SceneGraph sync-- Provided via `COLLAB_KEY` injection — `useCollabInjected()` in child components-- ICE servers: Google STUN + Cloudflare STUN + Open Relay TURN (TCP + UDP)-- Room IDs use `crypto.getRandomValues()` — no `Math.random()` anywhere in codebase-- Stale cursors cleaned on peer disconnect via `removeAwarenessStates()`+- Framework-agnostic tool operations live under `packages/core/src/tools/**` as `ToolDef` objects. Domains include read, create, modify, structure, variables, vector, analyze, describe, codegen, stock-photo, and helpers. Check the existing domain folder before adding a new file.+- `schema.ts` defines `ToolDef`, `defineTool()`, and shared result helpers. Each tool has a name, description, typed params, and an `execute(figma: FigmaAPI, args)` function.+- Registries (`registry*.ts`) assemble tool sets. Add new tools to the appropriate registry so AI chat, MCP, and CLI eval paths can see them.+- AI adapter (`packages/core/src/tools/ai-adapter.ts`) converts ToolDefs to Vercel AI tools with valibot schemas. `src/app/ai/tools/index.ts` is a thin app wire that creates `FigmaAPI` from the active editor.+- CLI commands in `packages/cli/src/commands/**` are not generated from ToolDefs; they own CLI UX, pagination, and agentfmt formatting. The `eval` command exposes ToolDef operations through `FigmaAPI`.+- MCP server code lives in `packages/mcp/src/server.ts`. MCP-only tools such as `open_file`, `new_document`, `save_file`, and `get_codegen_prompt` are registered there because they need server filesystem access or are not scene-graph tools.+- `open_file` and `new_document` are only registered when `OPENPENCIL_MCP_ROOT` is set. Export tools can write files under that root when given a `path`.+- Core codegen prompts live as markdown under `packages/core/src/tools/prompts/`; app chat/ACP prompts live under `src/app/ai/**` markdown files.+- `FigmaAPI` (`packages/core/src/figma-api/`) is the execution target for tools and CLI eval. It is Figma Plugin API compatible and uses Symbols for hidden internals.++## ACP and collaboration++Keep this section light; implementation details move often.++- ACP UI/transport lives under `src/app/ai/acp/**`; provider definitions live in `packages/core/src/constants.ts`; app prompts live under `src/app/ai/**`. Public docs: `packages/docs/programmable/ai-chat.md` and `packages/docs/programmable/mcp-server.md`.+- ACP transport uses Tauri shell permissions, so check `desktop/capabilities/**` when changing agent launch behavior.+- Collaboration lives under `src/app/collab/**` and is documented in `packages/docs/programmable/collaboration.md`. It uses Trystero + Yjs + awareness; preserve crypto-safe room IDs and peer cleanup semantics when changing it.## Code conventions- Do not place code or tests ad hoc. Before adding or moving files, inspect the existing folder structure and nearby patterns, then put changes in the established domain-specific location. If no proper location exists, create one deliberately and update docs/conventions as needed.-- Architecture boundaries are enforced by Steiger (`bun run check:arch`). App code must use public workspace package exports, workspace packages must not import app `src/` code, package-local aliases (`#core`, `#vue`, `#cli`, `#dom-css`, `#mcp`) are only for their owning package, core must stay framework-agnostic, app service/domain code (`src/app/**`) must not import app component/view layers, components must not import views, shared UI (`src/components/ui/**`) must not import app services/stores, property-panel internals must stay inside the property panel, canvas/editor overlay code must not import property-panel internals, Vue components must not use `<style>` blocks, code outside core editor internals must not assign `editor.state.selectedIds` or `editor.state.activeTool` directly, committed code must not import scratch/generated/vendor internals, and durable docs belong under `packages/docs/**` unless the root Markdown allowlist is deliberately updated.-- Test placement is strict and enforced by Steiger: app E2E tests live under `tests/e2e/**` and use `*.spec.ts`; Figma automation tests live under `tests/figma/**` and use `*.spec.ts`; engine/unit tests live under `tests/engine/**` and use `*.test.ts` (with `helpers.ts`, `*.bench.ts`, and `visual-*` support scripts allowed); shared test utilities live under `tests/helpers/**`; standalone package tests for `@open-pencil/dom-css` live under `packages/dom-css/tests/**`. Do not commit temporary/profile specs (`*.tmp.*`, `*.profile.*`). Do not put store-only/internal-state assertions in E2E. If a test drives the UI like a user and verifies visible behavior, it can be E2E; if it creates nodes through internals and asserts graph state, it belongs in engine/unit coverage.+- Architecture boundaries are enforced by `bun run check:arch` and related lint rules; keep app/package boundaries clean instead of relying on review to catch private imports. In practice: use public workspace exports across boundaries, keep core framework-agnostic, keep app services separate from component/view layers, keep shared UI free of app stores/services, and keep property-panel internals inside the property panel.+- Test placement is strict: app E2E in `tests/e2e/**/*.spec.ts`, Figma automation in `tests/figma/**/*.spec.ts`, engine/unit tests in `tests/engine/**/*.test.ts`, shared test utilities in `tests/helpers/**`, and standalone package tests in their package `tests/**` when established. UI-visible behavior belongs in E2E; graph/internal-state assertions belong in engine/unit tests. Do not commit temporary/profile specs.### File and folder naming@@ -280,9 +172,8 @@ Use `scripts/` only for tiny compatibility entrypoint shims that import `../tool- No `any` — use proper types, generics, declaration merging- No `!` non-null assertions — use guards, `?.`, `??`- No `Math.random()` — use `crypto.getRandomValues()` everywhere-- No inline type definitions when a named type exists — use `Color` not `{ r: number; g: number; b: number; a: number }`, use `Vector` not `{ x: number; y: number }`, use `SceneNode` / `Effect` / `Fill` / `Stroke` from `@open-pencil/scene-graph` instead of re-spelling their shapes inline-- Shared types (GUID, Color, Vector, Matrix, Rect) live in `packages/core/src/types.ts`-- Domain types (SceneNode, Fill, Stroke, Effect, BlendMode, etc.) live in `packages/scene-graph/src/` and are exported from `@open-pencil/scene-graph`+- No inline type definitions when a named type exists — use `Color` not `{ r: number; g: number; b: number; a: number }`, use `Vector` not `{ x: number; y: number }`, and import `SceneNode` / `Effect` / `Fill` / `Stroke` from `@open-pencil/scene-graph` instead of re-spelling their shapes.+- Shared geometry/color primitives live in `packages/scene-graph/src/primitives.ts`; scene/node domain types live in `packages/scene-graph/src/types.ts` and are exported from `@open-pencil/scene-graph`.- Window API extensions (showOpenFilePicker, queryLocalFonts) live in `src/global.d.ts` and `packages/core/src/global.d.ts`- Use `culori` for color conversions — don't reimplement parseColor/colorToRgba- Use `@vueuse/core` hooks — prefer higher-level composables (`useBreakpoints`, `useEventListener`, `onClickOutside`, etc.) over raw APIs (`useMediaQuery`, manual `addEventListener`)@@ -290,9 +181,9 @@ Use `scripts/` only for tiny compatibility entrypoint shims that import `../tool- No module-level mutable state in components — use the editor store- Prefer `tw-animate-css` for animations — don't hand-write `<style>` transition keyframes- No duplicated component logic — if two components share data (icon maps, util functions, constants), export from one place and import in both-- `packages/core/src/kiwi/schema-runtime/` contains the vendored Kiwi codec runtime; keep runtime changes minimal and prefer wrappers/helpers for project-specific validation-- Core code must guard browser APIs: `typeof window !== 'undefined'`, `typeof document === 'undefined'`-- Constants in `src/constants.ts` — no magic numbers in components or composables+- `packages/kiwi/src/schema-runtime/` contains the Kiwi codec runtime; keep runtime changes minimal and prefer wrappers/helpers for project-specific validation+- Core code must guard browser APIs with explicit runtime checks such as `typeof window !== 'undefined'` / `typeof document !== 'undefined'` before using them.+- Name repeated or cross-feature constants; use `src/constants.ts` for app-wide constants rather than feature-local values.## Code quality@@ -308,21 +199,25 @@ bun run test # Playwright E2E```Self-review checklist:+- Run `bun run test:dupes` — if duplication rises, extract shared helpers or use existing types- No inline type definitions that duplicate named types (Color, Vector, SceneNode, Effect, Fill, Stroke, etc.)- No copy-pasted logic — extract into functions. If two components share a util, icon map, or data structure, export from one place. If `jscpd` flags it, fix it.- Use precise union types — `'closed' | 'half' | 'full'` not `number | string | null`- Files should stay under ~600 lines — split by domain when they grow (see `packages/core/src/tools/` for the pattern)- `structuredClone` for deep copies, never shallow spread when mutating nested objects-- Don't hand-roll what a dependency already does. Check existing deps first (`package.json`, `packages/*/package.json`). If none covers it, find a quality library instead of inlining an implementation — e.g. use `diff` for unified diffs, not a custom line-by-line loop; use `culori` for color math, not manual RGB parsing+- Don't hand-roll what a dependency already does. Check existing deps first (`package.json`, `packages/*/package.json`). If none covers it, find a quality library instead of inlining an implementation — e.g. use `diff` for unified diffs, not a custom line-by-line loop; use `culori` for color math, not manual RGB parsing.+- Before custom UI/control/composable work, read upstream docs for the relevant dependency instead of guessing from local usage. Prefer their `llms.txt` entrypoints when available:+ - Reka UI (`https://reka-ui.com/llms.txt`) before building dialogs, popovers, dropdowns, menus, selects, tooltips, toasts, trees, splitters, or other primitives.+ - VueUse (`https://vueuse.org/llms.txt`) before hand-rolling DOM events, browser APIs, refs/focus, media queries, timers, clipboard, storage, async state, or observers.+ - Tailwind / tailwind-variants docs before inventing one-off styling prop APIs or variant composition.+- If upstream docs contradict local patterns, prefer current upstream APIs and update local wrappers deliberately.- `es-toolkit` is available in core for small, focused utility helpers when it clearly improves readability. Prefer subpath imports such as `es-toolkit/object`, `es-toolkit/array`, and `es-toolkit/predicate`; good fits include `omit` / `pick` for object key selection, `uniq` for dedupe, and `isNotNil` for typed nullish filtering. Do not replace clear native JavaScript just for consistency, and avoid `es-toolkit/compat` unless deliberately migrating lodash-compatible behavior.-- Check Reka UI for existing components (Dialog, Popover, DropdownMenu, Select, Tooltip, Toast, etc.) before building custom ones — especially dropdowns, popovers, and modals-## Rendering- Canvas is CanvasKit (Skia WASM) on a WebGL surface, not DOM-- `renderVersion` vs `sceneVersion`: `renderVersion` = canvas repaint (pan/zoom/hover); `sceneVersion` = scene graph mutations. UI panels watch `sceneVersion` only.+- `renderVersion` vs `sceneVersion`: `renderVersion` = canvas repaint (pan/zoom/hover); `sceneVersion` = scene graph mutations. UI that only cares about graph data should avoid watching repaint-only state; use editor events for incremental surfaces such as the layer tree.- `requestRender()` bumps both counters; `requestRepaint()` bumps only `renderVersion`- `renderNow()` is only for surface recreation and font loading (need immediate draw)- Resize observer uses rAF throttle, not debounce — debounce causes canvas skew@@ -347,8 +242,8 @@ Self-review checklist:- Purple (#9747ff) for COMPONENT, COMPONENT_SET, INSTANCE — matches Figma- Instance children map to component children via `componentId` for 1:1 sync- Override key format: `"childId:propName"` in instance's `overrides` record-- Editing a component must call `syncIfInsideComponent()` to propagate to instances-- `SceneGraph.copyProp<K>()` typed helper — uses `structuredClone` for arrays+- Editing a component must propagate to instances through the editor/component sync path; do not hand-copy instance fields in app UI code.+- Instance property copying lives in `@open-pencil/scene-graph` helpers and uses structured copies for nested values.## Layout@@ -377,43 +272,42 @@ Self-review checklist:- Regenerate the native menu with `bun run generate:tauri-menu` after editing the shared menu schema; `desktop/generated/menu.json` is consumed by the Tauri menu builder. Tauri also runs this generator from `desktop/tauri.conf.json` via `beforeDevCommand` and `beforeBuildCommand`.- Every shared menu item with an `id` must be handled by `src/app/shell/menu/use.ts`, an editor command, or explicitly marked browser/native-only in the schema.- Tailwind 4 for styling — no inline CSS, no component-level `<style>` blocks+- Use `Tip` / tooltip components for hover help; do not add native `title` attributes in Vue UI.- Mac keyboards: use `e.code` not `e.key` for shortcuts with modifiers (Option transforms characters)-- Splitter resize handles need inner div with `pointer-events-none` for sizing (zero-width handle collapses without it)-- Number input spinner hiding is global CSS in `app.css`, not per-component-- ScrubInput (drag-to-change number) — cursor and pointerdown on outer container, not inner spans- Icons: use unplugin-icons with Iconify/Lucide (`<icon-lucide-*>`) — don't use raw SVG or Unicode symbols- App menu (`src/components/Shell/AppMenu.vue`) — browser-only menu bar using reka-ui Menubar components; Tauri uses native menus, so menu is hidden when `IS_TAURI` is true-- Sections are draggable by title pill, not by the area to the right of the title-- CSS `contain: paint layout style` on side panels to isolate repaints from WebGL canvas+- Preserve established UI gotchas in nearby components before refactoring: splitter handle sizing, ScrubInput pointer ownership, section drag targets, side-panel containment, and global number-spinner styling.## File format-- .fig files use Kiwi binary codec — schema in `packages/core/src/kiwi/binary/codec.ts`-- `NodeChange` is the central type for Kiwi encode/decode-- Vector data uses reverse-engineered `vectorNetworkBlob` binary format — encoder/decoder in `packages/core/src/vector/`-- showOpenFilePicker/showSaveFilePicker are File System Access API (Chrome/Edge), not Tauri-only — code has fallbacks-- Safari save: no File System Access API → uses `<a>` download link with deferred `revokeObjectURL`. SafariBanner warns users about limitations.-- Tauri detection: `IS_TAURI` constant from `packages/core/src/constants.ts` — don't use `'__TAURI_INTERNALS__' in window` inline-- .fig export: compression with fflate (browser) or Tauri Rust commands-- Test .fig round-trip by exporting and reimporting in Figma-- Test fixtures (`tests/fixtures/*.fig`) are Git LFS — use `git push --no-verify` to skip the slow LFS pre-push hook. Use regular `git push` only when `.fig` fixtures changed.+- `.fig` files use Figma's Kiwi schema and `NodeChange[]` records. Low-level schema/runtime/codec/container/parse helpers live in `packages/kiwi/src/fig/**` and `packages/kiwi/src/schema-runtime/**`.+- Core still owns SceneGraph `.fig` policy: import/export orchestration in `packages/core/src/io/formats/fig/**`, SceneGraph ⇄ NodeChange conversion in `packages/core/src/kiwi/fig/node-change/**`, and component/instance override interpretation in `packages/core/src/kiwi/fig/instance-overrides/**`.+- `packages/fig` is the publishable boundary for future `.fig` policy extraction; do not move behavior there without package-local tests and dist smoke.+- Vector data uses reverse-engineered `vectorNetworkBlob` binary format — encoder/decoder in `packages/core/src/vector/` and scene-graph vector-network types in `@open-pencil/scene-graph`.+- `showOpenFilePicker` / `showSaveFilePicker` are File System Access API (Chrome/Edge), not Tauri-only; code must keep browser fallbacks.+- Safari save: no File System Access API → use an `<a>` download fallback with deferred `revokeObjectURL`. SafariBanner warns users about limitations.+- Tauri detection: use `IS_TAURI` from `@open-pencil/core/constants` / `src/constants.ts`; don't inline `__TAURI_INTERNALS__` checks.+- `.fig` export compression uses fflate in browser paths and Tauri Rust commands where available.+- Test `.fig` round-trip by exporting and reimporting in Figma when changing file-format behavior.+- Test fixtures (`tests/fixtures/*.fig`) are Git LFS. If no `.fig` fixtures changed, `git push --no-verify` can skip the slow LFS pre-push hook; use regular `git push` when fixtures changed.## Tauri-- Tauri v2 with plugin-dialog, plugin-fs, plugin-opener-- File system permissions must be configured in `desktop/tauri.conf.json` — "Internal error" on save means missing permissions-- Dev tools: add a menu item to toggle, don't rely on keyboard shortcut+- Tauri v2 desktop app lives under `desktop/`; check `desktop/Cargo.toml`, `desktop/capabilities/**`, and `desktop/tauri.conf.json` before adding desktop capabilities.+- File system and shell permissions must be configured explicitly; vague "Internal error" save failures often mean missing permissions.+- Dev tools: add or use a menu item to toggle, don't rely on keyboard shortcuts.## Publishing- `bun publish` from package dirs — resolves `workspace:*` → actual versions- Public packages publish built `dist/` output, not runtime TypeScript entrypoints-- Core, DOM/CSS, Vue, MCP, and CLI build with tsdown before publishing+- Public workspace packages build before publishing; most use tsdown, and split packages may also run `tsc --emitDeclarationOnly` plus dist smoke checks. Keep release tooling package lists in sync with `.github/workflows/build.yml`.- CLI publishes a Node-compatible `bin/openpencil.js` wrapper; do not point package `bin` entries at TypeScript source## Reference-[figma-use](https://github.com/dannote/figma-use) — our Figma toolkit. Use as reference for:+[figma-use](https://github.com/dannote/figma-use) — historical Figma toolkit reference. Verify current paths/types in that repo before copying assumptions. Useful areas:+- Kiwi binary format, schema, encode/decode (`packages/shared/src/kiwi/`)- Figma WebSocket multiplayer protocol (`packages/plugin/src/ws/`)- Vector network blob format (`packages/shared/src/vector/`)@@ -421,7 +315,3 @@ Self-review checklist:- MCP tools / design operations (`packages/mcp/`)- JSX-to-design renderer (`packages/render/`)- Design linter rules (`packages/linter/`)--## Known issues--- Safari ew-resize/col-resize/ns-resize cursor bug (WebKit #303845) — fixed in Safari 26.3 Beta