@menukfernandoo/canvas-flow 0.1.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/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Menuk Fernando
4
+
5
+ Portions of this software are derived from a prior
6
+ MIT-licensed work, (c) its original authors.
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in all
16
+ copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,199 @@
1
+ <h1 align="center">canvas-flow</h1>
2
+
3
+ <h3 align="center">For when a rich editor is not rich enough.</h3>
4
+
5
+ HTML is the new markdown. Canvas Flow is the new editor for your HTML artifacts.
6
+
7
+ Agents are good at producing rich HTML artifacts, but the human-agent collaboration loop on such artifacts is lacking and falls back into screenshots and long responses for “tell me what to change.”
8
+ That loses the thing HTML is best at: interactivity.
9
+
10
+ Canvas Flow opens agent-generated HTML files in a local browser, lets you pinpoint elements, selected text, or Mermaid diagram nodes and send feedback to the agent to address.
11
+
12
+ - **Local-first** - Review local HTML artifacts with a local CLI and no cloud dependency in the core feedback loop; hosted sharing through third-party ht-ml.app is explicit and opt-in.
13
+ - **Human-AI collaboration** - Annotate elements, selected text ranges, and Mermaid diagram nodes, and send messages to the agent without leaving Canvas Flow.
14
+ - **Battery included** - Canvas Flow teaches your agent good visualization for common use cases such as product or technical plans, design explorations and more out of the box.
15
+
16
+ Canvas Flow is an [AXI](https://axi.md), which means -
17
+
18
+ - It's just a CLI any capable agent can run without setup.
19
+ - It's optimized for agent ergonomics. TOON output, long polling, and contextual disclosure making it highly token efficient.
20
+ - The skill and hooks below only handle discovery; agents learn to use the AXI by using it.
21
+
22
+ ## Quick Start
23
+
24
+ Install the CanvasFlow skill in the [Agent Skills](https://agentskills.io) format with [`npx skills`](https://github.com/vercel-labs/skills):
25
+
26
+ ```sh
27
+ npx skills add fernandomenuk/canvas-flow --skill canvasflow
28
+ ```
29
+
30
+ That is the entire setup - no npm install needed.
31
+ The skill teaches your agent to run CanvasFlow through `npx -y @menukfernandoo/canvas-flow`, so the CLI comes along on demand.
32
+ Its frontmatter also includes Hermes Agent metadata, so Hermes-compatible harnesses can categorize and surface it as a first-class productivity skill.
33
+ This installs the public `canvasflow` skill.
34
+ The repository also contains an internal `canvasflow-design` brand skill for maintainers; default `npx skills add ... --list` and skills.sh discovery hide it unless `INSTALL_INTERNAL_SKILLS=1` is set.
35
+
36
+ Then, in agents that expose skills as slash commands (Claude Code, for example), invoke it directly:
37
+
38
+ ```
39
+ /canvasflow let's discuss our plan here
40
+ ```
41
+
42
+ Or just ask for anything that is easier to grasp visually - a plan, comparison, diagram, table, code view, or report - and the agent loads the skill on its own when it recognizes the task.
43
+
44
+ By default the skill lands in the current project's skills directory (`.claude/skills/`, for example); add `-g` to install it for all projects (`~/.claude/skills/`).
45
+
46
+ ## Other Ways to Use CanvasFlow
47
+
48
+ The skill is the recommended path, but it is not the only one.
49
+
50
+ ### Zero setup
51
+
52
+ CanvasFlow is an AXI, so any capable agent can run the CLI directly with nothing installed at all.
53
+ Just tell your agent:
54
+
55
+ ```
56
+ Use `npx @menukfernandoo/canvas-flow` to write a product or technical plan for what we discussed.
57
+ ```
58
+
59
+ ### Session hook
60
+
61
+ Want CanvasFlow's ambient context - including your live open sessions - fed into every agent session instead of loading on demand?
62
+ Install the CLI globally and opt into the hook:
63
+
64
+ ```sh
65
+ npm install -g @menukfernandoo/canvas-flow
66
+ canvas-flow setup hooks
67
+ ```
68
+
69
+ This installs a `SessionStart` hook for **Claude Code**, **Codex**, **OpenCode**, and **GitHub Copilot CLI** that surfaces open sessions, visualization playbooks, and usage guidance at the start of each session.
70
+ Unlike the skill, the hook also shows your live open sessions, so a fresh agent session can resume an in-flight review.
71
+ **Restart your agent session after running this** so the new hook takes effect.
72
+
73
+ ### From source
74
+
75
+ ```sh
76
+ git clone https://github.com/fernandomenuk/canvas-flow.git
77
+ cd canvas-flow
78
+ pnpm install --frozen-lockfile
79
+ pnpm run build
80
+ pnpm link
81
+ ```
82
+
83
+ ## How It Works
84
+
85
+ ```
86
+ ┌───────────────┐
87
+ │ Agent writes │
88
+ │ artifact.html │
89
+ └───────┬───────┘
90
+
91
+ ┌────────────────────────┐
92
+ │ canvas-flow <file_path> │
93
+ │ opens local browser UI │
94
+ └───────┬────────────────┘
95
+
96
+ ┌────────────────────────┐
97
+ │ Human annotates text │
98
+ │ or elements, sends │
99
+ │ chat, or browser audit │
100
+ │ reports layout issues │
101
+ └───────┬────────────────┘
102
+
103
+ ┌────────────────────────┐
104
+ │ canvas-flow poll waits │
105
+ │ and returns prompts │
106
+ │ or layout warnings │
107
+ └────────────────────────┘
108
+ ```
109
+
110
+ - **File-path identity** - Sessions are keyed by the canonical HTML file path, so agents do not need opaque IDs.
111
+ - **Portable artifacts** - The artifact runs in an iframe while CanvasFlow injects a small SDK for annotations, snapshots, feedback controls, and render-time layout checks.
112
+ CanvasFlow does not inject any design system, so the saved HTML file renders identically whether you open it through `canvas-flow` or directly in a browser.
113
+ Before writing HTML, choose a design system in strict priority order: follow a user-requested look first; otherwise inspect the project the artifact is about - the subject or product whose content or UI it represents, which may differ from your current working directory - and match that project's Tailwind or theme config, CSS variables or design tokens, component library, brand assets, or existing styled pages.
114
+ If the artifact previews, proposes, or mocks a specific app's UI, render it in that app's own design system so it faithfully shows the product, even when you are running in a different repo.
115
+ Only when both come up empty, run `canvas-flow design` for a copy-pasteable Tailwind CSS v4 + DaisyUI v5 CDN fallback, a content-to-playbook router, and Mermaid diagram tooling.
116
+ That fallback guidance recommends DaisyUI's `luxury` theme by default, warns not to `@apply` DaisyUI classes inside Tailwind browser-runtime style blocks, includes an optional layout safety CSS snippet for dense nested grid/flex layouts, and provides a pinned Mermaid CDN snippet with initialization for flows, architecture, state, and sequence diagrams.
117
+ - **Open-time layout gate** - The browser chrome masks each artifact until the real in-iframe layout audit reports no error-severity findings.
118
+ Warning-only artifacts reveal normally; error findings notify the agent through the same `layout_warnings` poll path and keep the curtain up until a clean reload.
119
+ The user can click **Show anyway**, and a bounded safety timeout reveals with a persistent layout-issues banner so review is never blocked indefinitely.
120
+ - **Layout warnings** - After fonts load and layout settles, the injected SDK audits the real browser render for page horizontal overflow, element overflow, clipped or visibly spilling text, and overlapping text.
121
+ Intentional horizontal scrollers using `overflow-x: auto` or `scroll` are excluded from horizontal checks, and `overflow-y: auto` or `scroll` is treated as intentional for vertical overflow.
122
+ Current findings are returned from `canvas-flow poll` as `layout_warnings` with `selector`, `kind`, `overflowPx`, `viewportWidth`, `severity`, and `persistent`.
123
+ Fresh error-severity findings should be fixed and rechecked before asking the human to review; repeated or warning-only findings can be surfaced to the human with a note when the cause is not obvious.
124
+ - **Local assets** - Copy local images, CSS, fonts, and scripts next to the HTML artifact and reference them with relative paths from that directory; root-prefixed paths such as `/assets/logo.png` will not resolve through CanvasFlow's artifact route.
125
+ - **Export and sharing** - `canvas-flow export` writes `<name>.export.html` by inlining local assets only, stripping the annotation SDK, and leaving remote CDN/font references as links that still need network access.
126
+ `canvas-flow share` publishes the same local-inlined HTML to [ht-ml.app](https://ht-ml.app), a third-party hosting service not part of CanvasFlow.
127
+ Publishing sends the artifact to ht-ml.app's servers, public by default, or private and password-protected with `--password`; the response includes a secret `update_key` shown once for later management.
128
+ Bundling never fetches remote URLs, CanvasFlow itself does not set a CSP, local reads stay confined and size-capped, and absolute `file://` paths outside safe inlined asset references are redacted before output.
129
+ Per-asset and per-bundle inline caps default to 10 MB and 25 MB, overridable with `CANVAS_FLOW_EXPORT_MAX_ASSET_BYTES` and `CANVAS_FLOW_EXPORT_MAX_BUNDLE_BYTES`.
130
+ Unresolved local assets or export notices such as author-set CSP meta tags and redacted file URLs are surfaced in command or browser output.
131
+ Use `--token` or `CANVAS_FLOW_HTML_APP_TOKEN` for an optional bearer token; set `CANVAS_FLOW_HTML_APP_API_URL` only when overriding the ht-ml.app API base.
132
+ - **Live reload** - CanvasFlow watches the HTML artifact file by default and preserves the artifact iframe scroll position across reloads. To also reload on sibling asset changes, add `data-canvasflow-live-reload-root` to the root element or `<meta name="canvasflow-live-reload" content="root">`.
133
+ - **Feedback controls** - Native controls (radios, checkboxes, inputs, selects, buttons, labels, disclosure summaries, contenteditable) are interactive automatically, so they do not need `data-canvasflow-action`.
134
+ For reversible choices, let option clicks update local state, then queue exactly one final answer from a per-question submit or Queue answer button with `window.canvasflow.queuePrompt()`.
135
+ Mark only custom (non-native) clickable elements with `data-canvasflow-action` so CanvasFlow does not annotate them, and use `data-canvasflow-question` or `queueKey` when pre-send updates for the same question should replace each other.
136
+ The browser chrome keeps editing actions in the overflow menu (copy path, reload artifact, copy DOM snapshot, export standalone HTML, publish link, end session) and can submit queued prompts with **Send & end session**, which sends the prompts and user-ended attribution together.
137
+ - **Keyboard shortcuts** - In the chrome composer, Enter sends queued prompts and Shift+Enter inserts a newline.
138
+ In the annotation card, Enter queues the annotation, Shift+Enter inserts a newline, and Ctrl+Enter (Cmd+Enter on macOS) queues it and sends all queued prompts immediately.
139
+ Cmd+I or Ctrl+I toggles between annotate and explore mode from either the browser chrome or the artifact iframe, including while focus is in a textarea or control.
140
+ - **Agent presence** - The browser shows when no agent is listening, keeps queued feedback and fresh layout warnings for the next successful `canvas-flow poll` send even across reloads, and only blocks human sends while the agent is working on delivered feedback. The no-timeout poll writes an immediate stderr banner and periodic stderr heartbeats while stdout stays reserved for the final response; if the poll is interrupted or times out, re-run it because queued feedback is never lost.
141
+ - **Session end etiquette** - CanvasFlow tracks who ended a session: a human clicking **End session** (or **Send & end session**) in the browser is a user-initiated end, while `canvas-flow end <html-file>` is agent-initiated.
142
+ A plain `canvas-flow <html-file>` after a user-initiated end refuses to reopen the browser and returns guidance instead; pass `--reopen` only when the user asks for further review or something important needs their visual attention.
143
+ Agent-initiated ends keep reopening normally, same as before.
144
+ `canvas-flow poll`'s `ended` response and the `feedback` response for the final batch before an end both carry `next_step` guidance telling the agent to stop polling and deliver remaining updates in chat instead of reopening.
145
+ - **Precise targets** - Text annotations include selected text plus range anchors, so agents are not limited to whole-element selectors.
146
+ - **Mermaid diagrams** - Rendered Mermaid diagrams become pannable and zoomable while you explore (drag to pan, scroll to zoom) and freeze when you turn on annotation so a click lands on a single node. Clicking a node annotates the whole node and sends the agent its diagram id, node id, and rendered label instead of just a CSS selector. CanvasFlow only enhances the live render, so the saved HTML still opens identically anywhere.
147
+ - **Server cleanup** - The detached server stops after the last session ends when nothing is connected, or after `CANVAS_FLOW_IDLE_TIMEOUT_MS` (default 30 minutes) with no browser or poll connections.
148
+ Set `CANVAS_FLOW_IDLE_TIMEOUT_MS=0` or `off` to disable idle self-shutdown.
149
+ - **Local-first state** - Session state stays under `~/.canvas-flow/` by default, or `CANVAS_FLOW_STATE_DIR` when set.
150
+ - **Network binding** - The server binds to loopback (`127.0.0.1`) by default. Set `CANVAS_FLOW_HOST` to bind elsewhere; a wildcard (`0.0.0.0` or `::`) binds every interface. Binding beyond loopback exposes an unauthenticated server that can read and serve arbitrary local files to anything that can reach it, so only do so on a trusted network. Set `CANVAS_FLOW_LINK_HOST` to control the hostname written into generated session links (defaults to the bind address, or loopback when bound to a wildcard).
151
+
152
+ ## CLI Reference
153
+
154
+ | Command | Description |
155
+ | -------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
156
+ | `canvas-flow` | Show current sessions and usage guidance. |
157
+ | `canvas-flow update` | Check for or apply the latest npm release through the AXI SDK self-updater. |
158
+ | `canvas-flow <html-file>` | Open or resume a Canvas Flow session, with the open-time layout gate enabled by default. Refuses to reopen a session the user explicitly ended from the browser unless `--reopen` is passed. |
159
+ | `canvas-flow poll <html-file>` | Long-poll until the user sends feedback, ends the session, or the browser reports fresh `layout_warnings`; leave no-timeout polls running, or re-run them if interrupted. On `status: ended`, stop polling and do not reopen uninvited. |
160
+ | `canvas-flow end <html-file>` | End a session as the agent; unlike a user-initiated end from the browser, this still allows a plain reopen later. |
161
+ | `canvas-flow export <html-file>` | Write a portable copy of the artifact: one HTML file with its local assets inlined, so it opens with no server and no sibling files. Remote CDN/font references are left as links. |
162
+ | `canvas-flow share <html-file>` | Publish the artifact (local assets inlined) to [ht-ml.app](https://ht-ml.app), a third-party host not part of CanvasFlow, and print a visitable URL plus a secret update key; shares are public by default, and `--password` makes viewers enter the password before viewing. |
163
+ | `canvas-flow stop` | Shut down the background server. |
164
+ | `canvas-flow playbook [id]` | List focused artifact guidance or show one playbook; agents must open each matching playbook before writing HTML. |
165
+ | `canvas-flow design` | Show the Tailwind + DaisyUI CDN fallback, content-to-playbook router, Mermaid diagram tooling, `luxury` default theme, DaisyUI `@apply` warning, and layout safety snippet. |
166
+ | `canvas-flow setup hooks` | Install or repair optional SessionStart hooks for Claude Code, Codex, OpenCode, and GitHub Copilot CLI; restart the agent session afterward. |
167
+ | `canvas-flow server` | Run the local Canvas Flow server. |
168
+
169
+ Known playbook IDs: `diagram`, `table`, `comparison`, `plan`, `code`, `input`, `slides`.
170
+ One artifact often combines several playbooks, such as a plan that includes a comparison and a diagram, so agents must match against each `use_when` trigger and open every matching playbook before writing HTML.
171
+ For flows, architecture, state, or sequence diagrams, open the diagram playbook and use the Mermaid tooling from `canvas-flow design` unless SVG is needed for richly annotated nodes; avoid hand-built div/flexbox boxes-and-arrows.
172
+
173
+ ### Flags
174
+
175
+ | Command | Flag | Description |
176
+ | ------------------------- | --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
177
+ | `canvas-flow <html-file>` | `--no-open` | Ensure the server/session exists without opening another browser window. |
178
+ | `canvas-flow <html-file>` | `--no-gate` | Skip the open-time layout curtain for this browser open. |
179
+ | `canvas-flow <html-file>` | `--reopen` | Reopen a session the user explicitly ended from the browser; without it, a plain open refuses and explains why instead of reopening uninvited. |
180
+ | `canvas-flow update` | `--check` | Report current vs latest npm version without installing an update. |
181
+ | `canvas-flow export` | `--out <path>` | Write the export to a specific path instead of `<name>.export.html` next to the source. |
182
+ | `canvas-flow share` | `--password <pw>` | Make the third-party ht-ml.app page private; viewers must supply the password. |
183
+ | `canvas-flow share` | `--token <t>` | Attach an optional bearer token (`CANVAS_FLOW_HTML_APP_TOKEN`); never required to publish. |
184
+ | `canvas-flow poll` | `--agent-reply "..."` | Show the agent's reply in the existing browser chat before polling again. |
185
+ | `canvas-flow poll` | `--timeout-ms <ms>` | Test/debug escape hatch only; agents should normally omit it and leave the long poll running. |
186
+ | `canvas-flow stop` | `--port <port>` | Shut down a server running on a non-default port. |
187
+ | `canvas-flow server` | `--verbose` | Log session and watcher events to stderr; can also be enabled with `CANVAS_FLOW_DEBUG=1`. Detached server output is appended to `~/.canvas-flow/server.log` (or `CANVAS_FLOW_STATE_DIR/server.log`) for startup and crash diagnostics. |
188
+
189
+ ## Development
190
+
191
+ ```sh
192
+ pnpm run check # Run all verification commands
193
+ pnpm run build # Bundle the publishable CLI, chrome, and design assets
194
+ pnpm run build:skill # Regenerate the installable canvasflow skill
195
+ pnpm test # Run node:test tests
196
+ pnpm run lint # Run ESLint
197
+ pnpm run format:check # Check Prettier formatting
198
+ pnpm run typecheck # Run TypeScript checkJs validation
199
+ ```