@trohde/excal-cli 1.0.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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Thomas Rohde
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,195 @@
1
+ # excal
2
+
3
+ ![version](https://img.shields.io/badge/version-1.0.0-blue)
4
+ [![npm](https://img.shields.io/npm/v/@trohde/excal-cli)](https://www.npmjs.com/package/@trohde/excal-cli)
5
+ ![license](https://img.shields.io/badge/license-MIT-green)
6
+
7
+ Agent-first CLI for [Excalidraw](https://excalidraw.com) scene inspection, validation, and rendering.
8
+
9
+ Built for AI agents, CI pipelines, and developers who need deterministic, non-interactive workflows around `.excalidraw` files. Every command returns a structured JSON envelope on stdout with stable error codes and exit semantics.
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ npm install -g @trohde/excal-cli
15
+ ```
16
+
17
+ Or run directly with npx:
18
+
19
+ ```bash
20
+ npx @trohde/excal-cli inspect diagram.excalidraw
21
+ ```
22
+
23
+ PNG and PDF export require Playwright (optional):
24
+
25
+ ```bash
26
+ npx playwright install chromium
27
+ ```
28
+
29
+ ### From source
30
+
31
+ ```bash
32
+ git clone https://github.com/ThomasRohde/excalidraw-cli.git
33
+ cd excalidraw-cli
34
+ npm install
35
+ npm run build
36
+ ```
37
+
38
+ ## Quick Start
39
+
40
+ ```bash
41
+ # Inspect a scene
42
+ excal inspect diagram.excalidraw
43
+
44
+ # Validate structure
45
+ excal validate diagram.excalidraw --check-assets
46
+
47
+ # Export to SVG
48
+ excal render diagram.excalidraw --outDir ./out
49
+
50
+ # Export to PNG + PDF
51
+ excal render diagram.excalidraw --outDir ./out --png --pdf
52
+
53
+ # Pipe from stdin
54
+ cat diagram.excalidraw | excal inspect -
55
+
56
+ # Agent bootstrapping
57
+ excal guide
58
+ excal skill
59
+ ```
60
+
61
+ ## Commands
62
+
63
+ ### `excal inspect <file|->`
64
+
65
+ Return element counts, type breakdown, frame details, text stats, bounding box, image info, and binary file metadata.
66
+
67
+ ```bash
68
+ excal inspect diagram.excalidraw
69
+ excal inspect diagram.excalidraw --frame "Login Flow"
70
+ excal inspect diagram.excalidraw --include-deleted
71
+ ```
72
+
73
+ | Flag | Description |
74
+ |------|-------------|
75
+ | `--include-deleted` | Include soft-deleted elements |
76
+ | `--frame <id\|name>` | Filter to a specific frame by ID or name |
77
+
78
+ ### `excal validate <file|->`
79
+
80
+ Check structural consistency: frame references, bound text bindings, arrow bindings, and optionally image asset references.
81
+
82
+ ```bash
83
+ excal validate diagram.excalidraw
84
+ excal validate diagram.excalidraw --check-assets
85
+ ```
86
+
87
+ | Flag | Description |
88
+ |------|-------------|
89
+ | `--check-assets` | Verify image elements reference existing binary files |
90
+
91
+ ### `excal render <file|->`
92
+
93
+ Render a scene to SVG, PNG, or PDF. SVG is the default. PNG and PDF require Playwright.
94
+
95
+ ```bash
96
+ excal render diagram.excalidraw --outDir ./out
97
+ excal render diagram.excalidraw --outDir ./out --svg --png
98
+ excal render diagram.excalidraw --outDir ./out --frame "Dashboard" --dark-mode
99
+ excal render diagram.excalidraw --dry-run
100
+ ```
101
+
102
+ | Flag | Description |
103
+ |------|-------------|
104
+ | `--outDir <dir>` | Output directory (default: `.`) |
105
+ | `--svg` | Export SVG (default if no format specified) |
106
+ | `--png` | Export PNG (requires Playwright) |
107
+ | `--pdf` | Export PDF (requires Playwright) |
108
+ | `--dark-mode` | Dark theme |
109
+ | `--no-background` | Transparent background |
110
+ | `--scale <n>` | PNG scale factor (default: `2`) |
111
+ | `--padding <n>` | Padding in pixels (default: `20`) |
112
+ | `--frame <id\|name>` | Export a specific frame only |
113
+ | `--element <id>` | Export a specific element only |
114
+ | `--dry-run` | Run the full pipeline but write no files |
115
+
116
+ ### `excal guide`
117
+
118
+ Print a Markdown CLI reference — commands, flags, error codes, envelope schema. Designed for agent bootstrapping.
119
+
120
+ ### `excal skill`
121
+
122
+ Print Markdown domain knowledge about Excalidraw scene structure, element types, frames, arrows, bound text, images, and export tips.
123
+
124
+ ## Response Envelope
125
+
126
+ Every command writes a JSON envelope to stdout:
127
+
128
+ ```jsonc
129
+ {
130
+ "schema_version": "1.0",
131
+ "request_id": "req_20260302_143000_7f3a",
132
+ "ok": true,
133
+ "command": "scene.inspect",
134
+ "target": { "file": "diagram.excalidraw", "fingerprint": "ab12..." },
135
+ "result": { ... },
136
+ "warnings": [],
137
+ "errors": [],
138
+ "metrics": { "duration_ms": 42 }
139
+ }
140
+ ```
141
+
142
+ - `ok`, `result`, `warnings`, `errors`, and `metrics` are always present.
143
+ - On failure, `result` is `null` and `errors` contains structured error objects.
144
+ - Each error has `code`, `message`, `retryable`, and `suggested_action`.
145
+
146
+ ## Error Codes
147
+
148
+ | Code | Exit | Description |
149
+ |------|------|-------------|
150
+ | `ERR_VALIDATION_INVALID_JSON` | 10 | Input is not valid JSON |
151
+ | `ERR_VALIDATION_INVALID_SCENE` | 10 | Scene structure validation failed |
152
+ | `ERR_VALIDATION_UNKNOWN_FORMAT` | 10 | Unrecognized input format |
153
+ | `ERR_RENDER_BROWSER_UNAVAILABLE` | 20 | Playwright is not installed |
154
+ | `ERR_RENDER_EXPORT_FAILED` | 20 | Browser-side export failed |
155
+ | `ERR_IO_READ_FAILED` | 50 | Could not read input file |
156
+ | `ERR_IO_WRITE_FAILED` | 50 | Could not write output file |
157
+ | `ERR_INTERNAL_UNEXPECTED` | 90 | Unexpected internal error |
158
+
159
+ ## Input Formats
160
+
161
+ The CLI auto-detects three input formats:
162
+
163
+ - **Full scene** — standard `.excalidraw` JSON with `elements`, `appState`, `files`
164
+ - **Elements-only** — a bare JSON array of elements
165
+ - **Clipboard** — `{ "type": "excalidraw/clipboard", "elements": [...] }`
166
+
167
+ ## Architecture
168
+
169
+ ```
170
+ src/
171
+ cli/ Commander commands (inspect, validate, render, guide, skill)
172
+ core/ Envelope, errors, IO, fingerprinting, exit codes
173
+ scene/ Zod schemas, scene loading, normalization, inspection, validation, filtering
174
+ render/ Playwright browser bridge using @excalidraw/utils
175
+ guide/ Guide + skill markdown content
176
+ ```
177
+
178
+ **Dual bundle** via tsup:
179
+ - CLI entry — ESM, Node.js, Playwright external
180
+ - Bridge entry — IIFE, browser, `@excalidraw/utils` bundled in
181
+
182
+ Rendering works by loading a minimal HTML page in headless Chromium, passing scene JSON via `page.evaluate()`, and calling `exportToSvg`/`exportToBlob` from `@excalidraw/utils`.
183
+
184
+ ## Development
185
+
186
+ ```bash
187
+ npm run build # Build CLI + bridge bundles
188
+ npm test # Run all tests
189
+ npm run dev # Watch mode build
190
+ npm run typecheck # TypeScript type checking
191
+ ```
192
+
193
+ ## License
194
+
195
+ MIT
@@ -0,0 +1,2 @@
1
+
2
+ export { }