easel-canvas 0.2.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -9
- package/bin/mcp.mjs +109 -9
- package/bin/server.mjs +22 -1
- package/dist/assets/index-DuziykA0.css +1 -0
- package/dist/assets/index-o294phw7.js +74 -0
- package/dist/index.html +2 -2
- package/dist/viewer/viewer.css +1 -1
- package/dist/viewer/viewer.js +20 -14
- package/examples/demo/.thumbs/home.html.1791613627606.jpg +0 -0
- package/package.json +8 -2
- package/server/activity.mjs +17 -2
- package/server/args.mjs +5 -4
- package/server/boards.mjs +64 -8
- package/server/browser.mjs +262 -32
- package/server/edit.mjs +27 -0
- package/server/export.mjs +40 -27
- package/server/index.mjs +33 -5
- package/server/livePatch.mjs +109 -0
- package/server/occupancy.mjs +14 -3
- package/server/place.mjs +11 -0
- package/server/registry.mjs +1 -1
- package/server/requests.mjs +560 -0
- package/server/routes.mjs +123 -42
- package/server/stamps.mjs +134 -0
- package/server/up.mjs +85 -0
- package/server/watch.mjs +31 -9
- package/dist/assets/index-CjyXUlEx.css +0 -1
- package/dist/assets/index-DFCSLJXY.js +0 -66
package/README.md
CHANGED
|
@@ -34,8 +34,23 @@ Already have HTML screens? Run it in your project:
|
|
|
34
34
|
npx easel-canvas # opens ./docs/design (or the current folder if it has screens/)
|
|
35
35
|
npx easel-canvas --init # starts a new ./docs/design with one screen
|
|
36
36
|
npx easel-canvas --dir ./designs # any folder of screens/*.html
|
|
37
|
+
npx easel-canvas up # the same in the background: prints the URL, reuses a canvas already running here
|
|
37
38
|
```
|
|
38
39
|
|
|
40
|
+
## Install into your agent
|
|
41
|
+
|
|
42
|
+
One line gives your agent the Easel tools and a skill that knows the canvas: when to open it, how to claim and write a board, check tokens, look at a screenshot and leave a comment, and how to lay out alternatives for you to pick from.
|
|
43
|
+
|
|
44
|
+
| Agent | Install | What you get |
|
|
45
|
+
| --- | --- | --- |
|
|
46
|
+
| **Claude Code** | `claude plugin marketplace add nemodleo/easel --sparse .claude-plugin plugin && claude plugin install easel@easel` | MCP tools, the `easel` skill, `/easel:open` and `/easel:variants` |
|
|
47
|
+
| **Codex** | `codex plugin marketplace add nemodleo/easel --sparse .agents/plugins --sparse plugin && codex plugin add easel@easel` | MCP tools and the `easel` skill |
|
|
48
|
+
| **Cursor** | `npx skills add nemodleo/easel --skill easel -a cursor` | The `easel` skill; add the tools with `npx easel-canvas connect` |
|
|
49
|
+
|
|
50
|
+
`--sparse` checks out only the plugin's folders instead of the whole repository with its screenshots, so the install stays fast on a slow connection.
|
|
51
|
+
|
|
52
|
+
Then, in your project, ask for what you want: *"open the design canvas"*, *"make three variants of the sign-up screen side by side"*, *"fix what I selected"*. In Claude Code, `/easel:open` starts the canvas for the project (or shows the one already running) and `/easel:variants signup.html 4` lays out four alternatives in a row below the original. The agent starts the canvas with `npx easel-canvas up`, which prints the URL and never starts a second one for the same folder.
|
|
53
|
+
|
|
39
54
|
## Why Easel
|
|
40
55
|
|
|
41
56
|
- **HTML is the source of truth.** Each `screens/*.html` file is one board. What you see is what ships to the browser, with nothing to export or keep in sync.
|
|
@@ -91,7 +106,7 @@ npx easel-canvas --dir ./designs # any folder of screens/*.html
|
|
|
91
106
|
|
|
92
107
|
Keep the canvas running (`npx easel-canvas`). Agents write HTML files directly, and what they change shows up in the canvas's undo history (one step per in-app AI request, or per burst of edits from an outside agent); the MCP server lets them **see** (`list_boards`, `read_board`, `screenshot`, `list_errors`), **know what you mean** (`get_selection` with the selected element, visible boards and the current page), **talk** (comments and replies) and **arrange** (`place_board`, `create_board`, notes, pages, `check_tokens`, `save_snapshot`). When several agents share a canvas, `claim_board` (before editing a file with their own tools) or `write_board` (a whole board through Easel) keeps one writer per board: a second agent on a busy board is given a fork next to it and told which file it is on.
|
|
93
108
|
|
|
94
|
-
Then, in your project folder:
|
|
109
|
+
Then, in your project folder (not needed for an agent that has the [plugin](#install-into-your-agent), which brings the same server):
|
|
95
110
|
|
|
96
111
|
```bash
|
|
97
112
|
npx easel-canvas connect
|
|
@@ -135,6 +150,18 @@ Then try:
|
|
|
135
150
|
|
|
136
151
|
New files with `<meta name="board-size" content="390x844">` are placed on the canvas automatically at that size.
|
|
137
152
|
|
|
153
|
+
### Send AI requests to the agent you're already talking to
|
|
154
|
+
|
|
155
|
+
When you already work with an agent next to the canvas (Claude desktop's Browser pane beside a Claude Code session, say), Easel does not need to start a second agent of its own. In the AI tab (or the **⋯** menu) set **AI requests go to** to **The agent you're talking to**; it is remembered for the project (`.easel/requests.json`, not committed).
|
|
156
|
+
|
|
157
|
+
From then on **Ask AI** on an element, **Send to AI** on a comment and **Ask AI to fix** (token check, accessibility, errors) leave a request on the canvas instead: a comment marked **For AI**, written in a small composer where the element toolbar sits. The pin gets an AI flag, the board says "1 waiting", and the AI button shows the count. Easel cannot type into your agent's chat, so then say there (the list shows this line once, with Copy, while a request waits):
|
|
158
|
+
|
|
159
|
+
> handle the Easel requests
|
|
160
|
+
|
|
161
|
+
(or `Easel 요청 처리해 줘`, or run `/easel:requests` with the plugin). The agent calls `list_requests`, `take_request` (one agent per request; the request says "Claude Code working" and the board "is editing…") and `finish_request`: its one-line reply lands under the comment, the comment is resolved, the changed board is one click away, and the board's activity tag has **Undo**. A request row is a comment with one mark and one line. A waiting request can be cancelled (it stays as a normal comment) or, behind its **⋯**, sent to **Easel chat** instead; a taken one cannot be cancelled, only undone afterwards. In a pane 1200 px wide or less the AI tab lists the requests first and shows the setting as one line ("Requests go to: your agent"). With two or more agents connected you can address one of them. View-only exports show For AI comments as ordinary comments.
|
|
162
|
+
|
|
163
|
+
Each board frame also carries `data-easel-file` (and `data-easel-path` while you have something selected on it), so when your host's own element picker grabs part of the canvas, the agent can turn it into a file and element with `resolve_pick`.
|
|
164
|
+
|
|
138
165
|
## Share a view-only copy
|
|
139
166
|
|
|
140
167
|
**Share** (at the top of the right card) writes a static, read-only copy of the whole canvas, the current page or the selected boards to `<project>/easel-export/`: boards with their pages, notes and comments, Play, and a stamp with the export time and `repo@commit`. Nothing in it calls back to Easel, so any static host works (Vercel, GitHub Pages, a PR preview, under any sub-path), and `index.html` also opens straight from disk (comment pins then stack in their board's corner, because browsers keep `file://` frames apart). **Copy deploy command** gives you `npx vercel deploy easel-export`. Turn on **One .html file** for a single self-contained file to attach to Slack, email or a PR; its size shows before you save. **PDF** (one board per page) and **PNG** (one 2× image per board) need Playwright's Chromium.
|
|
@@ -148,6 +175,12 @@ npx easel-canvas export --page Onboarding --pdf --png
|
|
|
148
175
|
npx easel-canvas export --boards home.html,ticket.html --out dist/design-preview
|
|
149
176
|
```
|
|
150
177
|
|
|
178
|
+
To show the copy inside another page, frame its `index.html` with `?embed`: the board list and comments card step aside, the zoom joins the dock, and the wheel stays with your page until someone clicks the canvas (Esc or a click outside gives it back). `fit` names the boards (or note ids) the opening view frames, `inset` keeps that view clear of what your page floats over the frame (CSS order, in px; a negative side lets boards run off that edge), and `dock` puts the dock `left`, `center` or `right`:
|
|
179
|
+
|
|
180
|
+
```html
|
|
181
|
+
<iframe src="easel-export/index.html?embed&fit=home.html,ticket.html&inset=80,24,0,668&dock=left" title="Design canvas"></iframe>
|
|
182
|
+
```
|
|
183
|
+
|
|
151
184
|
Exporting again replaces what the previous export of the same kind wrote there (a small `.easel-export.json` lists it) and leaves anything else in the folder alone; a non-empty folder Easel did not create is never cleared. Dot folders (`.easel/`, `.thumbs/`…) and files outside the design folder are never copied. A single file inlines the screens' images, fonts, CSS and scripts but not HTML embedded with `<iframe>`; the export lists what it skipped.
|
|
152
185
|
|
|
153
186
|
## Pin it in your project
|
|
@@ -180,6 +213,8 @@ npm run design # http://localhost:4317
|
|
|
180
213
|
|
|
181
214
|
`npx` keeps the copy it downloaded first, so run `npx easel-canvas@latest` to get a new version (and `npm i -D easel-canvas@latest` if you pinned it). To tell you when one is out, the canvas asks the npm registry once a day which version is the latest: one request to `registry.npmjs.org`, nothing about your project. When a newer one exists, the terminal says so at start and a toast at launch shows the update command for how you installed Easel; Copy command or × puts it away until the next version. Set `EASEL_NO_UPDATE_CHECK=1` to turn the check off; it is also off in CI and when Easel runs from a git checkout.
|
|
182
215
|
|
|
216
|
+
Screenshots, thumbnails and PDF/PNG export share one headless Chromium, started on the first one and closed after two minutes without any. Set `EASEL_BROWSER_IDLE_SECONDS` to change that wait (`0` closes it after every render).
|
|
217
|
+
|
|
183
218
|
|
|
184
219
|
<details>
|
|
185
220
|
<summary><b>Keyboard shortcuts and how-tos</b></summary>
|
|
@@ -187,18 +222,19 @@ npm run design # http://localhost:4317
|
|
|
187
222
|
| To do this | How |
|
|
188
223
|
| --- | --- |
|
|
189
224
|
| Pan and zoom | Drag empty space, Space, or Hand (H); trackpad scroll; ⌘+wheel or pinch (4–400%). ⇧1 Fit all, ⇧2 selection, ⌘0 Zoom to 100%, Minimap (M) |
|
|
190
|
-
| Find | Left "Boards" tab: ⌘K search and list; pages (drag to reorder; right-click to rename, delete, or set the launch page) |
|
|
191
|
-
| Boards | Draw with the board tool (B), use a "New board" template (Blank · Mobile
|
|
225
|
+
| Find | Left "Boards" tab (the first button in the top-left card): ⌘K search and list; pages (drag to reorder; right-click to rename, delete, or set the launch page). The top-left card shows the current page (with the page count when there are several): click it for every page (⋯ or → on a row for that page's menu) and New page |
|
|
226
|
+
| Boards | Draw with the board tool (B), use a "New board" template (Blank · Watch, Mobile, Tablet and Desktop screens · Document · Email), or drop an HTML file on the canvas. Duplicate ⌘D, rename F2 (renaming the file offers to update references), Delete (confirm, trash, undo), Bring to front / Send to back ⌘] ⌘[, Export PNG (right-click: downloads `<file>.png` at 2×, needs Playwright's Chromium) |
|
|
192
227
|
| Multiple items | Drag on empty space to marquee-select or use Shift; move together (snap guides, Alt to disable); arrow keys 1, Shift 10, Option 100 |
|
|
193
|
-
| Board options | Right "Properties": position, size, Radius, No frame, Show Play button (a dot and
|
|
194
|
-
| View | Focus view (F, ←→), Play in place on any board (P with one board selected, or right-click; ▶ on boards with Show Play button; Esc stops), Play full screen (right-click). Playing never writes to `board.json`. With no board or several selected, P is the pen |
|
|
228
|
+
| Board options | Right "Properties": position, size, Radius, No frame, Show Play button (a dot, and the label's ▶ stays visible at rest; not needed to play), Stretch to window, Open as launch screen, Layout guides (Columns · Rows · Grid, up to 6, ⌃G), Adjustable values |
|
|
229
|
+
| View | Focus view (F, ←→), Play in place on any board (P with one board selected, or right-click; ▶ at the top right of the label: on every board while it is selected or hovered, always on boards with Show Play button, Stop while playing; Esc stops), Play full screen (right-click). Playing never writes to `board.json`. With no board or several selected, P is the pen |
|
|
195
230
|
| Notes and shapes | Title (T), sticky note (N, 8 colors, size, bold, italic), Rectangle (R), Oval (O), Line (L), Arrow (A), Pen (P when no board is selected), image (Assets or paste) |
|
|
196
231
|
| Select elements | No mode to enter: click anything on a board (drag the board to move it). Shift-click or Shift-drag for several, Esc lets go (then of the board), ↑ parent, ↓ or Enter first child, ←→ siblings, Option+↑↓ to reorder, ⌘A for all siblings, ⌘G Wrap in flex, Tab into the element toolbar |
|
|
197
232
|
| Direct editing | The element toolbar, in the line above the dock: Text (size, weight), Fill (your tokens first, written as a CSS variable, then Custom), Radius, Spacing (padding, gap), Ask AI, Comment. Double-click text to edit it (Shift+Enter for a line break). Move with handles (Alt drops inside a box) and resize, 6 align options, Properties panel in design words with the breadcrumb (CSS names on hover, everything else under More (CSS), ⚠, contrast), Replace image, ⌘C/⌘V to paste into another board |
|
|
198
233
|
| Undo | ⌘Z / ⌘⇧Z. Canvas actions, HTML edits and board create/delete share one history (100 entries). The ▾ next to Undo lists it newest first (who, what, when; Now marks where you are): Go back to here undoes or redoes step by step to that entry, and Redo brings the rest back. The history lasts until Easel restarts |
|
|
199
234
|
| Who changed what | A board changed by someone else (an agent over MCP or the in-app chat, a file edited outside Easel, another browser) gets a tag above its title, e.g. "Codex · 2m · 1 change", with a person or agent mark and the name, and the changed element is outlined. Click the tag: the change ("Get started" → "Start free"), Before / After, and Undo (only that change; asks first if one of its boards changed since). Tags fade once you open them or select the board, and clear a day later |
|
|
200
|
-
| Design system | Register tokens (`tokens.json`) and themes in the left "Tokens" tab, Theme in the
|
|
235
|
+
| Design system | Register tokens (`tokens.json`) and themes in the left "Tokens" tab, Theme in the project menu (the title at the top left), Token check and Accessibility lists on the right |
|
|
201
236
|
| Collaboration | Comments (Reply, Resolve, author), Snapshot menu (git-commits only the design folder) |
|
|
237
|
+
| Language | English or Korean (한국어): the browser's language picks it on first load (ko-* is Korean, everything else English), Language in the project menu switches it and is remembered in this browser. The exported view-only copy follows the browser's language |
|
|
202
238
|
| Share | "Share" at the top of the right card: whole canvas, this page or the selected boards as a web folder or one .html file, PDF or PNG; Reveal, Copy deploy command, and the matching `npx easel-canvas export` line |
|
|
203
239
|
| Who is on which board | A board someone is editing says so above its title with a mark and the name: "Claude Code is editing…", "You · editing", then "Claude Code · done 13:52"; the board list shows a dot (blue for you, ink for anyone else). An agent holds a board from its first write until its in-app run ends, or 45 s after its last write over MCP (or when it disconnects). A second agent writing a board another agent holds works on a fork beside it ("Welcome · Codex"), with an arrow back that says when and why; you are never forked. When both are done, Use this one on either keeps that version under the original's name, title, position and comments, and sends the other to trash; one Undo brings both back |
|
|
204
240
|
| Pick a variant | Variants from the AI tab land in the first free row (never on notes or boards) and each gets Use this: Apply makes it the original board and sends the other variants to trash (toast with Undo), Keep all leaves them as ordinary boards |
|
|
@@ -206,7 +242,9 @@ npm run design # http://localhost:4317
|
|
|
206
242
|
| AI permissions | When Claude Code wants to run a command or edit outside what it may, the chat shows the exact request: Allow once, Always allow (that tool, or a command's first two words, until Easel restarts; never for file edits, for commands with `;` `&&` `\|` `>` and the like, or for `sh -c`-style wrappers), or Deny |
|
|
207
243
|
| Undo an AI run | Each run that changed files ends with the boards it changed and added: Undo this run (one step, ⌘Z brings it back; asks first if you changed one of them since), Redo, Compare before and after. After a restart: Restore the copy from before this run (the newest 10 are kept) |
|
|
208
244
|
| Custom agent | Agent menu › Custom command…: a name and a command with `{prompt}`, e.g. `aider --message {prompt} --yes`. Saved in `~/.easel/agents.json` (not in the project), run without a shell, output shown as plain text |
|
|
209
|
-
| Screen | F6
|
|
245
|
+
| Screen | An app bar above the canvas: the project's title menu (find, share, snapshot, appearance, theme, language, where AI requests go, keyboard shortcuts) on the left; Comments, **AI** and Share on the right. On the canvas, a top-left card (left panel, page, Canvas / Prototype) and a top-right card (▷ play, the properties panel ⌘\\, the zoom percent with zoom in/out, fit ⇧1, selection ⇧2, 50/100/200%, layout guides ⌃G, minimap M, clean view ⇧⌘\\). F6 moves between regions, Tab between boards; clean view leaves the canvas alone (Esc, the same key or the small handle at the bottom right bring the tools back). ▷ lists the page's prototypes and static boards; Canvas / Prototype in the top-left card switches to one board at a time (board switcher, ← →, Fill / Fit, Esc back). The URL keeps `#page-<id>`, `#artboard-<file>` or `#play-<file>`: back and forward walk pages and the prototype view, a link lands there, and Copy page link (a page's ⋯) and Copy link (a board's menu) copy one. Links are local to the port the canvas runs on |
|
|
246
|
+
| Pane width | The same arrangement at every width. At 1200 wide or less (the browser pane beside an agent's chat) the left panel opens over the canvas and steps away when you pick a board from it, press Esc or press on the canvas; opening it there lasts for that tab, the choice made in a wide window is the one remembered. The right panel opens at once, roomy, on a pick (Properties), on **AI**, on Comments or on a comment; it follows your next pick, and Esc, a press on the empty canvas, or a pan or zoom puts it back (not while you are typing in one of its fields). Resting bars keep their place and open panels grow away from them: the cards are 36 px, the dock 40 px and centred; the minimap sits at the bottom left (144 px wide at pane width, 192 wider), on unless you switched it off, shown where it fits beside the dock |
|
|
247
|
+
| Labels and hints | At rest a board's label is its title in grey; a change by someone else is a dot after it. Point at the board, select it or tab into its label for the file name and the full tag ("Outside Easel · 11m · 2 changes"); who is editing right now, forks and Use this one always show in full. No hint at rest: the first visit shows two hints above the dock for 8 seconds or until the first press. On hover, selection or keyboard focus a label offers ↓ export (PNG 2×), ⤢ full window (Fill / Fit, Esc back with the board selected), the board's adjustable values when it declares them, and ▷ Play with a menu (in place, full screen); playing in place ▷ reads Edit and the dock steps away |
|
|
210
248
|
|
|
211
249
|
</details>
|
|
212
250
|
|
|
@@ -237,8 +275,11 @@ npm run test:e2e # Playwright end-to-end tests against test/fixtures/design
|
|
|
237
275
|
npm run typecheck
|
|
238
276
|
npm run demo # run the repo's demo from source
|
|
239
277
|
npm run design:css # rebuild docs/design/assets/easel.css after changing app/src/style.css, so the boards in docs/design keep matching the app
|
|
278
|
+
npm run verify:agents # before a release: install Easel into each agent CLI on PATH, in throwaway config homes
|
|
240
279
|
```
|
|
241
280
|
|
|
281
|
+
`npm run verify:agents` (`tools/verify-agents.mjs`) checks the agent plugin for real. For each of `claude`, `codex`, `cursor-agent` and `gemini` found on PATH, it installs Easel into a config home under a temp folder (`CLAUDE_CONFIG_DIR`, `CODEX_HOME`, or `HOME` for Cursor and Gemini; never your own `~/.claude`, `~/.codex`, `~/.cursor` or `~/.gemini`). It checks that the plugin, the skill and the MCP server are listed, prints pass, skip or fail per check, and removes the temp folder. By default it installs from this checkout; `-- --source github` (or `github@<ref>`) installs from GitHub the way the README does. `-- --live` also asks each agent to call `list_boards` on a scratch canvas, but only for an agent that is logged in inside its temp home, which means its own API key variable is already set in your environment. The script reads and stores no keys. It is not part of `npm test`.
|
|
282
|
+
|
|
242
283
|
- `test/fixtures/design/` intentionally keeps Korean screen content and board titles: it mimics real user content and is needed to test Korean text input (IME) and rendering. Set `DESIGN_CANVAS_E2E_DIR=<folder>` to run the e2e tests against another design folder.
|
|
243
284
|
- `examples/demo/` is Intercut No.14, the project `--demo` copies and the one in the demo video and the screenshots above. Its two fonts are bundled under the SIL Open Font License (see [License](#license)).
|
|
244
285
|
|
|
@@ -246,9 +287,10 @@ npm run design:css # rebuild docs/design/assets/easel.css after changing app/s
|
|
|
246
287
|
| --- | --- |
|
|
247
288
|
| `bin/` | `server.mjs` (app server), `mcp.mjs` (MCP stdio server) |
|
|
248
289
|
| `server/` | API and routes, board.json, file watching, element paths and hashes, source patching, history, chat runner, tokens |
|
|
249
|
-
| `app/` | Canvas UI (Vite + React + TypeScript); all UI text lives in `app/src/strings.ts
|
|
290
|
+
| `app/` | Canvas UI (Vite + React + TypeScript); all UI text lives in `app/src/strings.ts`, in English and Korean (the Korean object is typed against the English one, so a missing string is a type error) |
|
|
250
291
|
| `test/` | `node --test` unit tests and Playwright e2e tests |
|
|
251
|
-
| `tools/` | Repo maintenance scripts, not shipped: `mkcss.mjs` builds the design boards' stylesheet from the app's |
|
|
292
|
+
| `tools/` | Repo maintenance scripts, not shipped: `mkcss.mjs` builds the design boards' stylesheet from the app's, `plugin-sync.mjs` keeps the plugin manifests at the package version, `verify-agents.mjs` checks real agent installs |
|
|
293
|
+
| `plugin/` | The agent plugin: MCP server entry, the `easel` skill, `/easel:open` and `/easel:variants` |
|
|
252
294
|
|
|
253
295
|
Background reading: the original plan is in [PLAN.md](PLAN.md) and the work log is in [tasks.md](tasks.md).
|
|
254
296
|
|
package/bin/mcp.mjs
CHANGED
|
@@ -4,10 +4,11 @@
|
|
|
4
4
|
// The agent creates and edits HTML by writing files directly. This server only observes, points at things, and places boards.
|
|
5
5
|
// With --chat (an in-app Claude Code run) it also carries the run's permission prompt, answered in the Easel chat, under the name easel-chat;
|
|
6
6
|
// --permission (older) carries only that permission tool.
|
|
7
|
-
// No port needed: the canvas for the folder the agent runs in is found through the registry (server/registry.mjs) on each call.
|
|
7
|
+
// No port needed: the canvas for the folder the agent runs in (or the client's MCP root, when started elsewhere) is found through the registry (server/registry.mjs) on each call.
|
|
8
8
|
import { readFileSync } from "node:fs";
|
|
9
9
|
import fs from "node:fs/promises";
|
|
10
10
|
import path from "node:path";
|
|
11
|
+
import { fileURLToPath } from "node:url";
|
|
11
12
|
|
|
12
13
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
13
14
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
@@ -15,7 +16,7 @@ import { z } from "zod";
|
|
|
15
16
|
|
|
16
17
|
import { agentLabel } from "../server/agents.mjs";
|
|
17
18
|
import { parseArgs, TOOL_ROOT } from "../server/args.mjs";
|
|
18
|
-
import { discoverPort } from "../server/registry.mjs";
|
|
19
|
+
import { discoverPort, real, within } from "../server/registry.mjs";
|
|
19
20
|
|
|
20
21
|
const args = parseArgs();
|
|
21
22
|
const pkg = JSON.parse(readFileSync(path.join(TOOL_ROOT, "package.json"), "utf8"));
|
|
@@ -24,7 +25,22 @@ const explicit = args.portGiven ? args.port : Number(process.env.DESIGN_CANVAS_P
|
|
|
24
25
|
const IMAGE_LIMIT = 4 * 1024 * 1024;
|
|
25
26
|
|
|
26
27
|
let port = null;
|
|
27
|
-
const resolvePort = async (fresh = false) => (port = !fresh && port ? port : await discoverPort({ port: explicit }));
|
|
28
|
+
const resolvePort = async (fresh = false) => (port = !fresh && port ? port : await discoverPort({ port: explicit, cwd: explicit ? undefined : await workDir() }));
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The folder to find the canvas for: this process's folder, unless the client offers MCP roots and that folder is in none
|
|
32
|
+
* of them (an agent plugin's server can be started in the plugin's own folder, as Codex does): then the first root.
|
|
33
|
+
*/
|
|
34
|
+
async function workDir() {
|
|
35
|
+
const here = process.cwd();
|
|
36
|
+
if (!server.server.getClientCapabilities()?.roots) return here;
|
|
37
|
+
try {
|
|
38
|
+
const roots = (await server.server.listRoots(undefined, { timeout: 2000 })).roots.filter((r) => r.uri.startsWith("file:")).map((r) => fileURLToPath(r.uri));
|
|
39
|
+
return !roots.length || roots.some((r) => within(real(here), real(r))) ? here : roots[0];
|
|
40
|
+
} catch {
|
|
41
|
+
return here;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
28
44
|
|
|
29
45
|
/** This MCP server's id at the canvas: the boards it writes are released when its client disconnects */
|
|
30
46
|
const CLIENT = `mcp-${process.pid.toString(36)}${Math.random().toString(36).slice(2, 8)}`;
|
|
@@ -176,17 +192,84 @@ tool(
|
|
|
176
192
|
tool(
|
|
177
193
|
"list_comments",
|
|
178
194
|
{
|
|
179
|
-
description: "List board comments (docs/design/comments.json), optionally for one file or only
|
|
180
|
-
inputSchema: { file: z.string().optional(), unresolved: z.boolean().optional() },
|
|
195
|
+
description: "List board comments (docs/design/comments.json), optionally for one file, only unresolved ones, or only the ones marked For AI (requests; use list_requests to handle them).",
|
|
196
|
+
inputSchema: { file: z.string().optional(), unresolved: z.boolean().optional(), for_agent: z.boolean().optional().describe("Only comments marked For AI") },
|
|
181
197
|
},
|
|
182
|
-
async ({ file, unresolved }) => {
|
|
198
|
+
async ({ file, unresolved, for_agent }) => {
|
|
183
199
|
const q = new URLSearchParams();
|
|
184
200
|
if (file) q.set("file", file);
|
|
185
201
|
if (unresolved) q.set("unresolved", "1");
|
|
202
|
+
if (for_agent) q.set("for_agent", "1");
|
|
186
203
|
return ok(await callJson("GET", `/api/comments?${q}`));
|
|
187
204
|
},
|
|
188
205
|
);
|
|
189
206
|
|
|
207
|
+
tool(
|
|
208
|
+
"list_requests",
|
|
209
|
+
{
|
|
210
|
+
description:
|
|
211
|
+
'List the requests the person left on the Easel canvas for you (comments marked For AI): waiting and taken ones. Each waiting request meant for you comes with the context block Easel\'s own chat would send (target file, element path, source excerpt, issues, token rules). Use it when the person says "handle the Easel requests" (or "Easel 요청 처리해 줘", or runs /easel:requests). Then, for each one meant for you: take_request, do only what it asks, check, finish_request. Skip requests another agent has taken or that name another agent.',
|
|
212
|
+
inputSchema: {},
|
|
213
|
+
},
|
|
214
|
+
async () => {
|
|
215
|
+
const { requests } = await callJson("GET", "/api/requests");
|
|
216
|
+
if (!requests.length) return ok("No requests are waiting on the Easel canvas.");
|
|
217
|
+
const mine = requests.filter((r) => r.state === "waiting" && r.meantForYou);
|
|
218
|
+
const head = `${requests.length} request${requests.length === 1 ? "" : "s"} on the canvas, ${mine.length} waiting for you. Take each with take_request(id) before you change anything; finish with finish_request.`;
|
|
219
|
+
const blocks = requests.map((r) => {
|
|
220
|
+
const where = `${r.file}${r.path ? ` path ${r.path}` : ""}`;
|
|
221
|
+
if (r.state === "taken") return `## ${r.id} · taken by ${r.by} · ${where}\nSkip it: ${r.by} is on it.`;
|
|
222
|
+
if (!r.meantForYou) return `## ${r.id} · for ${r.for} · ${where}\nSkip it: it is addressed to ${r.for}.`;
|
|
223
|
+
return `## ${r.id} · waiting · for ${r.for} · ${where}${r.left ? ` (${r.left} left before finishing it)` : ""}\n${r.context}`;
|
|
224
|
+
});
|
|
225
|
+
return ok([head, ...blocks].join("\n\n"));
|
|
226
|
+
},
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
tool(
|
|
230
|
+
"take_request",
|
|
231
|
+
{
|
|
232
|
+
description:
|
|
233
|
+
"Take one request from the Easel canvas before working on it (atomic: if another agent took it first you get \"Already taken by …\"; a request addressed to another agent is refused). It also claims the request's board, so the canvas shows you are editing it, and returns the board and the request's context. Change the board only through write_board (read_board, then the whole HTML); do not use file-editing tools.",
|
|
234
|
+
inputSchema: { id: z.string().describe("The request id from list_requests") },
|
|
235
|
+
},
|
|
236
|
+
async ({ id }) => {
|
|
237
|
+
const r = await callJson("POST", "/api/requests", { action: "take", id });
|
|
238
|
+
return ok(`Took ${r.request.id}. ${r.message}\n\n${r.context}`);
|
|
239
|
+
},
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
tool(
|
|
243
|
+
"finish_request",
|
|
244
|
+
{
|
|
245
|
+
description:
|
|
246
|
+
"Finish a request you took: status done (your one-line reply is added to the comment and it is resolved; the person can undo the change from the board) or failed (reply says why; the person can send it again or use Easel's chat). Check your edit first (check_tokens, screenshot).",
|
|
247
|
+
inputSchema: {
|
|
248
|
+
id: z.string(),
|
|
249
|
+
status: z.enum(["done", "failed"]),
|
|
250
|
+
reply: z.string().describe("One line for the person: what you changed, or why it failed"),
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
async ({ id, status, reply }) => {
|
|
254
|
+
const r = await callJson("POST", "/api/requests", { action: "finish", id, status, reply });
|
|
255
|
+
return ok(`${r.request.id} is ${r.request.state}.${r.changed.length ? ` Changed: ${r.changed.join(", ")}.` : " No board changed."}`);
|
|
256
|
+
},
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
tool(
|
|
260
|
+
"resolve_pick",
|
|
261
|
+
{
|
|
262
|
+
description:
|
|
263
|
+
"Turn an element the person picked on the Easel page (your host's element picker, a pasted snippet, a selector or visible text) into the board file, Easel element path and source outerHTML. A pick of Easel's board frame carries data-easel-file and, while an element is selected, data-easel-path. With no arguments it returns what is selected in Easel now.",
|
|
264
|
+
inputSchema: {
|
|
265
|
+
html: z.string().optional().describe("The picked element's HTML (outerHTML), as the picker gave it"),
|
|
266
|
+
selector: z.string().optional().describe("A CSS selector for the element"),
|
|
267
|
+
text: z.string().optional().describe("The element's visible text"),
|
|
268
|
+
},
|
|
269
|
+
},
|
|
270
|
+
async (args) => ok(await callJson("POST", "/api/pick/resolve", args)),
|
|
271
|
+
);
|
|
272
|
+
|
|
190
273
|
tool(
|
|
191
274
|
"add_comment",
|
|
192
275
|
{
|
|
@@ -230,11 +313,11 @@ tool(
|
|
|
230
313
|
tool(
|
|
231
314
|
"create_board",
|
|
232
315
|
{
|
|
233
|
-
description: "Create a new board (HTML file) from a template and place it on the canvas. Templates: blank (Blank), mobile (390×844 Mobile screen), desktop (1440×900 Desktop screen), doc (Document). Edit the created file directly afterwards.",
|
|
316
|
+
description: "Create a new board (HTML file) from a template and place it on the canvas. Templates: blank (Blank), mobile (390×844 Mobile screen), tablet (834×1194 Tablet screen), desktop (1440×900 Desktop screen), watch (198×242 Watch screen), doc (800×1000 Document), email (600×1200 Email). Edit the created file directly afterwards.",
|
|
234
317
|
inputSchema: {
|
|
235
318
|
file: z.string().optional().describe("File name, e.g. scr-40.html; generated if omitted"),
|
|
236
319
|
title: z.string().optional(),
|
|
237
|
-
template: z.enum(["blank", "mobile", "desktop", "doc"]).optional(),
|
|
320
|
+
template: z.enum(["blank", "mobile", "tablet", "desktop", "watch", "doc", "email"]).optional(),
|
|
238
321
|
x: z.number().optional(),
|
|
239
322
|
y: z.number().optional(),
|
|
240
323
|
w: z.number().optional(),
|
|
@@ -340,6 +423,19 @@ tool(
|
|
|
340
423
|
async ({ message }) => ok(await callJson("POST", "/api/snapshot", { message })),
|
|
341
424
|
);
|
|
342
425
|
|
|
426
|
+
// Say hello once the client has introduced itself (its name is the agent label), then every minute: the canvas lists connected
|
|
427
|
+
// agents, so the person can see who will pick up a request and address one. Easel's own chat runs do not say hello
|
|
428
|
+
const host = !args.chat && !args.permission;
|
|
429
|
+
const hello = () =>
|
|
430
|
+
host &&
|
|
431
|
+
call("POST", "/api/agents/hello", { client: CLIENT, label: agent(), cwd: process.cwd() }).catch(() => {
|
|
432
|
+
/* no canvas yet: the next hello finds it */
|
|
433
|
+
});
|
|
434
|
+
server.server.oninitialized = () => {
|
|
435
|
+
void hello();
|
|
436
|
+
setInterval(hello, 60000).unref();
|
|
437
|
+
};
|
|
438
|
+
|
|
343
439
|
await server.connect(new StdioServerTransport());
|
|
344
440
|
|
|
345
441
|
// The client went away (stdin closed, or we are told to stop): the boards this client was editing are released, then exit
|
|
@@ -348,7 +444,11 @@ const leave = async () => {
|
|
|
348
444
|
if (leaving) return;
|
|
349
445
|
leaving = true;
|
|
350
446
|
if (!permissionOnly && port)
|
|
351
|
-
await
|
|
447
|
+
await Promise.all(
|
|
448
|
+
["/api/boards/release", ...(host ? ["/api/agents/bye"] : [])].map((p) =>
|
|
449
|
+
fetch(`http://127.0.0.1:${port}${p}`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ client: CLIENT }), signal: AbortSignal.timeout(1000) }).catch(() => {}),
|
|
450
|
+
),
|
|
451
|
+
);
|
|
352
452
|
process.exit(0);
|
|
353
453
|
};
|
|
354
454
|
process.stdin.on("end", leave);
|
package/bin/server.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// AI-generated with Claude Code, 2026-10-09, reviewed by Hyun Park
|
|
3
|
-
// Usage: easel-canvas [--dir <design folder>] [--port 4317] [--open] [--demo] [--init] | easel-canvas connect [--agents …] [--dry-run]
|
|
3
|
+
// Usage: easel-canvas [--dir <design folder>] [--port 4317] [--open] [--demo] [--init] | easel-canvas up|status [--json] | easel-canvas connect [--agents …] [--dry-run]
|
|
4
4
|
// | easel-canvas export [--out <dir>] [--page …] [--boards a.html,b.html] [--single-file] [--pdf] [--png]
|
|
5
5
|
import { spawn } from "node:child_process";
|
|
6
6
|
import { cpSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
@@ -23,6 +23,8 @@ Usage
|
|
|
23
23
|
npx easel-canvas --demo copy the demo project to ./easel-demo and open it
|
|
24
24
|
npx easel-canvas --init create ./docs/design with a starter screen, then open it
|
|
25
25
|
npx easel-canvas --dir <folder> open a specific design folder
|
|
26
|
+
npx easel-canvas up start the canvas in the background unless one runs for this project; print its URL
|
|
27
|
+
npx easel-canvas status print the URL of the canvas running for this project (exit 1 when there is none)
|
|
26
28
|
npx easel-canvas connect add the Easel MCP server to your agents' configs (run in the project)
|
|
27
29
|
npx easel-canvas export write a view-only copy of the canvas to ./easel-export (no canvas needed)
|
|
28
30
|
|
|
@@ -32,6 +34,10 @@ Options
|
|
|
32
34
|
-h, --help show this help
|
|
33
35
|
-v, --version
|
|
34
36
|
|
|
37
|
+
up, status
|
|
38
|
+
--json one JSON object: running, url, port, pid, dir (up adds started, and log for a new canvas)
|
|
39
|
+
up opens the browser when it starts a canvas (--no-open to skip) and takes --dir, --port and --init as above.
|
|
40
|
+
|
|
35
41
|
connect
|
|
36
42
|
--agents <list> claude,cursor,gemini,codex (default: Claude Code, plus the others found on this machine)
|
|
37
43
|
--dry-run print what would be written, write nothing
|
|
@@ -66,6 +72,21 @@ if (args.command === "connect") {
|
|
|
66
72
|
process.exit(0);
|
|
67
73
|
}
|
|
68
74
|
|
|
75
|
+
if (args.command === "up" || args.command === "status") {
|
|
76
|
+
const { describe, findCanvas, up } = await import("../server/up.mjs");
|
|
77
|
+
let r;
|
|
78
|
+
try {
|
|
79
|
+
r = args.command === "up" ? await up({ dir: args.dir, dirGiven: args.dirGiven, port: args.portGiven ? args.port : null, init: args.init, open: !args.noOpen, prod: args.prod }) : await findCanvas({ dir: args.dir, dirGiven: args.dirGiven });
|
|
80
|
+
} catch (e) {
|
|
81
|
+
if (args.json) console.log(JSON.stringify({ running: false, dir: args.dir, error: e.message }));
|
|
82
|
+
else console.error(e.message);
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
if (args.json) console.log(JSON.stringify(r ?? { running: false, dir: args.dir }));
|
|
86
|
+
else console.log(describe(r, args.dir));
|
|
87
|
+
process.exit(r ? 0 : 1);
|
|
88
|
+
}
|
|
89
|
+
|
|
69
90
|
if (args.command === "export") {
|
|
70
91
|
const { exportDesign } = await import("../server/export.mjs");
|
|
71
92
|
const { closeBrowser } = await import("../server/browser.mjs");
|