easel-canvas 0.3.0 → 0.5.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 CHANGED
@@ -31,10 +31,10 @@ That copies the demo to `./easel-demo` and opens it at http://localhost:4317: In
31
31
  Already have HTML screens? Run it in your project:
32
32
 
33
33
  ```bash
34
- npx easel-canvas # opens ./docs/design (or the current folder if it has screens/)
35
- npx easel-canvas --init # starts a new ./docs/design with one screen
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
34
+ npx easel-canvas@latest # opens ./docs/design (or the current folder if it has screens/)
35
+ npx easel-canvas@latest --init # starts a new ./docs/design with one screen
36
+ npx easel-canvas@latest --dir ./designs # any folder of screens/*.html
37
+ npx easel-canvas@latest up # the same in the background: prints the URL, reuses a canvas already running here
38
38
  ```
39
39
 
40
40
  ## Install into your agent
@@ -43,13 +43,13 @@ One line gives your agent the Easel tools and a skill that knows the canvas: whe
43
43
 
44
44
  | Agent | Install | What you get |
45
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` |
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`, `/easel:variants`, and a hook that [wakes the session](#claude-code-wakes-up-for-a-request) for canvas requests |
47
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
48
  | **Cursor** | `npx skills add nemodleo/easel --skill easel -a cursor` | The `easel` skill; add the tools with `npx easel-canvas connect` |
49
49
 
50
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
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.
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 -y easel-canvas@latest up`, which prints the URL and never starts a second one for the same folder.
53
53
 
54
54
  ## Why Easel
55
55
 
@@ -104,7 +104,7 @@ Then, in your project, ask for what you want: *"open the design canvas"*, *"make
104
104
 
105
105
  ## Connect your AI agent
106
106
 
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.
107
+ Keep the canvas running (`npx easel-canvas@latest`). 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.
108
108
 
109
109
  Then, in your project folder (not needed for an agent that has the [plugin](#install-into-your-agent), which brings the same server):
110
110
 
@@ -150,6 +150,30 @@ Then try:
150
150
 
151
151
  New files with `<meta name="board-size" content="390x844">` are placed on the canvas automatically at that size.
152
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. With the Claude Code plugin the session [wakes up by itself](#claude-code-wakes-up-for-a-request); otherwise 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
+ #### Claude Code wakes up for a request
164
+
165
+ The Claude Code plugin (not the MCP server alone, and not Codex, Cursor or Gemini) adds a hook that ends the "now go tell your agent" step: while the session sits idle, a request you leave on the canvas wakes it within a few seconds, and it handles the request as `/easel:requests` does. You see the session start working on its own.
166
+
167
+ - **How.** `plugin/hooks/claude-code.json` (declared in the Claude Code manifest `plugin/.claude-plugin/plugin.json` only, and not at the default `hooks/hooks.json`, so other agents' plugin loaders, such as Codex's, do not pick it up) runs `plugin/hooks/wake.mjs` (Node, no dependencies) on `SessionStart` and again after every turn (`Stop`), as an `asyncRewake` hook: it waits in the background and exits with code 2 to wake the session. It finds the running canvas for the session's folder in the registry (`~/.easel/servers`), the same way the MCP server does, but only a canvas whose folder contains the session's folder or is the one canvas inside it; it never starts a canvas, and when none is running it checks again every 5 seconds. Every 2 seconds it reads the waiting requests (`GET /api/requests`, read only; it does not count as an agent looking).
168
+ - **What wakes it.** Only waiting requests meant for Claude Code (for any agent, or addressed to Claude Code), and only while **AI requests go to** is **The agent you're talking to**. Easel's own chat runs and requests for another agent never wake it.
169
+ - **Once per request, again if the wake was lost.** A request is announced as soon as it waits (`~/.easel/wake/announced/`). A wake that lands while the session's turn is still running can be dropped, so after the session's next turn ends the new watcher announces the request again if no agent has listed it yet (the request has no `seenAt`), at most 3 more times and no sooner than 20 seconds after the last announcement. A request an agent has listed but not taken is not announced again. It starts over when it goes back to waiting (sent again after a failure, or the agent that took it left).
170
+ - **Several sessions on one project.** Each session has its own watcher (one per session; a second one exits at once), but they share the announcements, so only one watcher wins each announcement and wakes its session; a watcher that was already running when a request was announced never announces it again. If two sessions do act on the same request, `take_request` lets only one take it.
171
+ - **What Claude reads.** One line with the number of new requests and what to do. The request text is never in it; Claude reads it with `list_requests`.
172
+ - **Opt out.** Set `EASEL_NO_WAKE=1` in the environment Claude Code starts with, or keep **AI requests go to** on **Easel chat**.
173
+ - **Limits.** The hook runs for at most a day (`timeout: 86400`); a session idle for longer than that is not woken until its next turn ends, which starts a new watcher. A request made while the session is busy is announced during that turn; if that wake is lost, it is announced again once the turn has ended and at least 20 seconds have passed since the first announcement. With several sessions open, the repeat can wake another session started or re-armed since then, not necessarily the one that lost it. macOS and Linux; on Windows the hook does nothing. It needs a Claude Code version with `asyncRewake` hooks. Set `EASEL_WAKE_LOG=<file>` to log what the watcher does.
174
+
175
+ 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`.
176
+
153
177
  ## Share a view-only copy
154
178
 
155
179
  **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.
@@ -173,7 +197,7 @@ Exporting again replaces what the previous export of the same kind wrote there (
173
197
 
174
198
  ## Pin it in your project
175
199
 
176
- `npx easel-canvas` is all most projects need. To pin an exact version for your team, add it as a dev dependency (`npm i -D easel-canvas`, then `"design": "easel-canvas"` in your scripts) or as a git submodule. With your designs in `<project>/docs/design/screens/`:
200
+ `npx easel-canvas@latest` is all most projects need. To pin an exact version for your team, add it as a dev dependency (`npm i -D easel-canvas`, then `"design": "easel-canvas"` in your scripts) or as a git submodule. With your designs in `<project>/docs/design/screens/`:
177
201
 
178
202
  ```bash
179
203
  git submodule add https://github.com/nemodleo/easel.git tools/easel
@@ -210,7 +234,7 @@ Screenshots, thumbnails and PDF/PNG export share one headless Chromium, started
210
234
  | To do this | How |
211
235
  | --- | --- |
212
236
  | 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) |
213
- | Find | Left "Boards" tab: ⌘K search and list; pages (drag to reorder; right-click to rename, delete, or set the launch page) |
237
+ | 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 |
214
238
  | 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) |
215
239
  | 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 |
216
240
  | 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 |
@@ -220,9 +244,9 @@ Screenshots, thumbnails and PDF/PNG export share one headless Chromium, started
220
244
  | 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 |
221
245
  | 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 |
222
246
  | 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 |
223
- | Design system | Register tokens (`tokens.json`) and themes in the left "Tokens" tab, Theme in the View menu (⋯ at the top of the right card), Token check and Accessibility lists on the right |
247
+ | 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 |
224
248
  | Collaboration | Comments (Reply, Resolve, author), Snapshot menu (git-commits only the design folder) |
225
- | Language | English or Korean (한국어): the browser's language picks it on first load (ko-* is Korean, everything else English), Language in the View menu switches it and is remembered in this browser. The exported view-only copy follows the browser's language |
249
+ | 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 |
226
250
  | 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 |
227
251
  | 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 |
228
252
  | 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 |
@@ -230,7 +254,9 @@ Screenshots, thumbnails and PDF/PNG export share one headless Chromium, started
230
254
  | 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 |
231
255
  | 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) |
232
256
  | 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 |
233
- | Screen | F6 to move between regions, Tab to move between boards, ⌘\\ to fold both cards away and back, Appearance (System · Light · Dark) |
257
+ | 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 |
258
+ | 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 |
259
+ | 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 |
234
260
 
235
261
  </details>
236
262
 
@@ -276,7 +302,7 @@ npm run verify:agents # before a release: install Easel into each agent CLI on
276
302
  | `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) |
277
303
  | `test/` | `node --test` unit tests and Playwright e2e tests |
278
304
  | `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 |
279
- | `plugin/` | The agent plugin: MCP server entry, the `easel` skill, `/easel:open` and `/easel:variants` |
305
+ | `plugin/` | The agent plugin: MCP server entry, the `easel` skill, `/easel:open`, `/easel:variants` and `/easel:requests`, and the Claude Code wake hook (`hooks/`) |
280
306
 
281
307
  Background reading: the original plan is in [PLAN.md](PLAN.md) and the work log is in [tasks.md](tasks.md).
282
308
 
package/bin/mcp.mjs CHANGED
@@ -68,7 +68,7 @@ async function call(method, path, body) {
68
68
  res = await send();
69
69
  } catch (e2) {
70
70
  if (e2.message?.startsWith("Several Easel canvases")) throw e2;
71
- throw new Error(`Easel is not running for this project (tried http://localhost:${port}). Start it in the project with \`npx easel-canvas\` (add --dir <design folder> when the screens are not in ./docs/design or the current folder), then try again.`);
71
+ throw new Error(`Easel is not running for this project (tried http://localhost:${port}). Start it in the project with \`npx easel-canvas@latest\` (add --dir <design folder> when the screens are not in ./docs/design or the current folder), then try again.`);
72
72
  }
73
73
  }
74
74
  const text = await res.text();
@@ -164,7 +164,7 @@ tool(
164
164
  "get_selection",
165
165
  {
166
166
  description:
167
- "What the user is looking at right now: selection (the element the user clicked on a board: file, path as element indexes from the children of <body>, tag, kind and label, text, source outerHTML up to 4KB, hash, computed styles), mode (canvas, edit = an element is selected, focus, play), page and pageName, visibleArtboards (boards visible on screen), selectedArtboards, dirty (pending saves), edits (recent edit history), erroredArtboards and firstError (boards with errors). Use it for requests like 'fix the selected element' or 'this screen'.",
167
+ "What the user is looking at right now: selection (the element the user clicked on a board: file, path as element indexes from the children of <body>, tag, kind and label, text, source outerHTML up to 4KB, hash, computed styles), mode (canvas, edit = an element is selected, focus, play), page and pageName, visibleArtboards (boards visible on screen), selectedArtboards, dirty (pending saves), edits (recent edit history), erroredArtboards and firstError (boards with errors). Call it first whenever a message points at something without naming it ('fix this', 'make it bigger', 'this screen', 'the selected element', '이거 고쳐'), and work on what it returns.",
168
168
  inputSchema: {},
169
169
  },
170
170
  async () => {
@@ -192,17 +192,84 @@ tool(
192
192
  tool(
193
193
  "list_comments",
194
194
  {
195
- description: "List board comments (docs/design/comments.json), optionally for one file or only unresolved ones.",
196
- 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") },
197
197
  },
198
- async ({ file, unresolved }) => {
198
+ async ({ file, unresolved, for_agent }) => {
199
199
  const q = new URLSearchParams();
200
200
  if (file) q.set("file", file);
201
201
  if (unresolved) q.set("unresolved", "1");
202
+ if (for_agent) q.set("for_agent", "1");
202
203
  return ok(await callJson("GET", `/api/comments?${q}`));
203
204
  },
204
205
  );
205
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
+
206
273
  tool(
207
274
  "add_comment",
208
275
  {
@@ -356,6 +423,19 @@ tool(
356
423
  async ({ message }) => ok(await callJson("POST", "/api/snapshot", { message })),
357
424
  );
358
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
+
359
439
  await server.connect(new StdioServerTransport());
360
440
 
361
441
  // The client went away (stdin closed, or we are told to stop): the boards this client was editing are released, then exit
@@ -364,7 +444,11 @@ const leave = async () => {
364
444
  if (leaving) return;
365
445
  leaving = true;
366
446
  if (!permissionOnly && port)
367
- await fetch(`http://127.0.0.1:${port}/api/boards/release`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ client: CLIENT }), signal: AbortSignal.timeout(1000) }).catch(() => {});
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
+ );
368
452
  process.exit(0);
369
453
  };
370
454
  process.stdin.on("end", leave);
package/bin/server.mjs CHANGED
@@ -19,14 +19,14 @@ if (args.help) {
19
19
  console.log(`Easel ${pkg.version} — an HTML design canvas for AI agents
20
20
 
21
21
  Usage
22
- npx easel-canvas open ./docs/design (or the current folder if it has screens/)
23
- npx easel-canvas --demo copy the demo project to ./easel-demo and open it
24
- npx easel-canvas --init create ./docs/design with a starter screen, then open it
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)
28
- npx easel-canvas connect add the Easel MCP server to your agents' configs (run in the project)
29
- npx easel-canvas export write a view-only copy of the canvas to ./easel-export (no canvas needed)
22
+ npx easel-canvas@latest open ./docs/design (or the current folder if it has screens/)
23
+ npx easel-canvas@latest --demo copy the demo project to ./easel-demo and open it
24
+ npx easel-canvas@latest --init create ./docs/design with a starter screen, then open it
25
+ npx easel-canvas@latest --dir <folder> open a specific design folder
26
+ npx easel-canvas@latest 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)
28
+ npx easel-canvas connect add the Easel MCP server to your agents' configs (run in the project)
29
+ npx easel-canvas export write a view-only copy of the canvas to ./easel-export (no canvas needed)
30
30
 
31
31
  Options
32
32
  --port <n> port to listen on (default 4317; when it is busy and --port is not given, the next free one)
@@ -64,7 +64,7 @@ if (args.command === "connect") {
64
64
  try {
65
65
  const lines = await connect({ project: args.dirGiven ? rootOf(args.dir) : process.cwd(), agents: args.agents, dryRun: args.dryRun });
66
66
  console.log(lines.join("\n"));
67
- if (!args.dryRun) console.log("\nStart the canvas with npx easel-canvas, then restart your agent so it loads the MCP server.");
67
+ if (!args.dryRun) console.log("\nStart the canvas with npx easel-canvas@latest, then restart your agent so it loads the MCP server.");
68
68
  } catch (e) {
69
69
  console.error(e.message);
70
70
  process.exit(1);
@@ -132,25 +132,57 @@ if (!existsSync(dir)) {
132
132
  console.error(`No design folder at ${dir}
133
133
 
134
134
  Try one of:
135
- npx easel-canvas --demo open the demo project
136
- npx easel-canvas --init start a new design folder here (./docs/design)
137
- npx easel-canvas --dir <folder> open an existing folder of screens/*.html`);
135
+ npx easel-canvas@latest --demo open the demo project
136
+ npx easel-canvas@latest --init start a new design folder here (./docs/design)
137
+ npx easel-canvas@latest --dir <folder> open an existing folder of screens/*.html`);
138
138
  process.exit(1);
139
139
  }
140
140
 
141
141
  const { createServer } = await import("../server/index.mjs");
142
142
  const { attach, closeBrowser, extraRoutes } = await import("../server/routes.mjs");
143
+ const { waitForNew } = await import("../server/selfupdate.mjs");
143
144
  let app;
145
+ let child = null; // after a hand-over: the new server, which this process only waits on
146
+ const start = async (port, autoPort) => {
147
+ const a = await createServer({ dir, port, dev: !args.prod, extraRoutes, autoPort, register: true, updateCheck: true });
148
+ await attach(a);
149
+ a.ctx.handover = handover;
150
+ return a;
151
+ };
152
+ /**
153
+ * One-click update (server/selfupdate.mjs installed the new files at root): this server lets go of its port, the new one starts on the
154
+ * same port and folder, and this process stays as its parent (Ctrl+C and the terminal still reach it). If the new one has not answered
155
+ * in 30 s it is stopped and this one listens again, so there is always a canvas. Resolves to whether the new one took over.
156
+ */
157
+ async function handover(root) {
158
+ const port = app.port;
159
+ await app.close();
160
+ const next = spawn(process.execPath, [path.join(root, "bin", "server.mjs"), "--dir", dir, "--port", String(port), "--no-open", ...(args.prod ? ["--prod"] : [])], { stdio: "inherit", env: process.env, windowsHide: true });
161
+ let dead = false;
162
+ next.on("exit", () => (dead = true));
163
+ next.on("error", () => (dead = true));
164
+ if (await waitForNew({ port, pid: process.pid, alive: () => !dead })) {
165
+ child = next;
166
+ next.on("exit", (code, sig) => process.exit(code ?? (sig ? 1 : 0)));
167
+ return true;
168
+ }
169
+ try {
170
+ next.kill("SIGTERM");
171
+ } catch {}
172
+ await new Promise((r) => (dead ? r() : next.once("exit", r), setTimeout(r, 3000)));
173
+ app = await start(port, false);
174
+ app.ctx.updateState = { phase: "failed", why: "restart" };
175
+ console.error(`The new Easel did not start on port ${port}; this one keeps running.`);
176
+ return false;
177
+ }
144
178
  try {
145
- app = await createServer({ dir, port: args.port, dev: !args.prod, extraRoutes, autoPort: !args.portGiven, register: true, updateCheck: true });
179
+ app = await start(args.port, !args.portGiven);
146
180
  } catch (e) {
147
181
  if (e.code !== "EADDRINUSE") throw e;
148
182
  console.error(e.message);
149
183
  process.exit(1);
150
184
  }
151
- await attach(app);
152
185
  console.log(`Easel: ${app.url} (design folder ${dir})${app.port !== args.port ? ` port ${args.port} was busy` : ""}`);
153
- app.update.then((u) => u && console.log(`Easel ${u.latest} is out (you have ${u.current}). Update: ${u.command}, then restart.`));
154
186
 
155
187
  if (open && !args.noOpen) {
156
188
  const [cmd, cmdArgs] = process.platform === "darwin" ? ["open", [app.url]] : process.platform === "win32" ? ["cmd", ["/c", "start", "", app.url]] : ["xdg-open", [app.url]];
@@ -160,6 +192,7 @@ if (open && !args.noOpen) {
160
192
  process.on("exit", () => app.unregister());
161
193
  for (const sig of ["SIGTERM", "SIGINT", "SIGHUP"])
162
194
  process.on(sig, async () => {
195
+ if (child) return void child.kill(sig); // the new server ends, then this process with it
163
196
  app.unregister();
164
197
  await closeBrowser();
165
198
  process.exit(0);