net-art 0.0.0-stage → 0.0.2

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.
@@ -0,0 +1,118 @@
1
+ ---
2
+ name: Net-art
3
+ description: Use the Net-art pixel-art CLI or live server to generate, inspect, atomically edit, and export canonical 8x8, 16x16, or 32x32 pixel art. Produce high-quality pixel art with clear silhouettes, limited coherent palettes, intentional shading, and readback verification.
4
+ ---
5
+
6
+ # Net-art for AI agents
7
+
8
+ Use this skill when driving Net-art, producing or fixing pixel art, or verifying agent-visible canvas state. Net-art has exactly three engine tools: `write_pixels`, `read_pixels`, `edit_pixels`. PNG export is separate, not a fourth engine tool. No MCP, layers, animation, non-square canvases, cloud service, or hidden state.
9
+
10
+ ## Interface
11
+
12
+ From a Net-art repo checkout, run `npm install`, `npm run build`, then `node dist/cli/pixelart.js ...`. From an installed package, use `pixelart ...`. CLI output is JSON on stdout; do not require a TTY. Stable errors are `{ "ok": false, "error": { "code", "message", "field?" } }`. Exit codes: `0` success, `1` validation, `2` revision conflict, `3` IO, `4` not found/server. JSON input can be a file path or `-` for stdin.
13
+
14
+ Default project is `pixelart.json`. `write_pixels`, `read_pixels`, and `edit_pixels` accept `--project <path>`. Agent shells and humans share the same canonical state. Offline mode edits the file; `pixelart serve --project pixelart.json --port 4173` starts one local writer. With `--server http://127.0.0.1:4173`, send commands through that server. Pick one writer per project; do not edit the file directly while serving.
15
+
16
+ ## Canonical state
17
+
18
+ - `size` is exactly `8`, `16`, or `32`; canvas is square.
19
+ - `pixels` is a flat row-major array length `size * size`; `(x,y) -> y*size + x`.
20
+ - Colors output as lowercase `#rrggbbaa`; transparent is `#00000000`.
21
+ - Accepted input colors include `#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`, `"transparent"`, and `null`; canonical output is always `#rrggbbaa`.
22
+ - `name` is optional display name. `palette` is optional; pixels are truth. If `palette` is omitted, it is derived in first-appearance order. `revision` starts at `0`; increments only on canonical change; no-op writes/edits do not bump it; callers cannot set or reset `revision`.
23
+ - Successful reads return `ok`, `revision`, `size`, `name`, `pixels`, `palette`, `updatedAt`. `edit_pixels` also returns `applied` and `changed_pixels: [{x,y,from,to}]`.
24
+
25
+ ## `write_pixels`
26
+
27
+ Create or overwrite the whole canvas in one batch. Never emit individual per-pixel writes. Supply every pixel; no partial update. Full batch is required before reading back.
28
+
29
+ ```bash
30
+ pixelart write_pixels \
31
+ --project pixelart.json \
32
+ --size 8 \
33
+ --pixels pixels.json \
34
+ [--palette palette.json] \
35
+ [--name sprite] \
36
+ [--server http://127.0.0.1:4173]
37
+ ```
38
+
39
+ `pixels.json` is `["#00000000", "#ff0000ff", ...]` length `size*size`. `pixels` may be `-` for stdin. Output includes canonical snapshot. `write_pixels` can overwrite `size` only with a complete matching `pixels` array.
40
+
41
+ ## `read_pixels`
42
+
43
+ ```bash
44
+ pixelart read_pixels --project pixelart.json
45
+ pixelart read_pixels --server http://127.0.0.1:4173
46
+ ```
47
+
48
+ No mutation. Use `revision` before `edit_pixels`. Verify `ok`, `size`, full `pixels`, `palette`, and canonical colors; do not assume generation succeeded.
49
+
50
+ ## `edit_pixels`
51
+
52
+ Atomic ordered edit; validate all; no partial mutation. Prefer targeted edits for mistakes instead of rewriting the whole canvas.
53
+
54
+ ```bash
55
+ pixelart edit_pixels \
56
+ --project pixelart.json \
57
+ --ops ops.json \
58
+ [--base-revision 3] \
59
+ [--server http://127.0.0.1:4173]
60
+ ```
61
+
62
+ `ops.json` is `{ "base_revision": 3, "ops": [...] }` or a bare array. `base_revision` may be in file or `--base-revision`. If present it must equal current `revision`; mismatch returns `revision_conflict`, exit `2`, no mutation. If omitted, last-write-wins. Retry safe pattern: `read_pixels` -> recompute -> `edit_pixels` with `base_revision`.
63
+
64
+ ```json
65
+ {
66
+ "base_revision": 3,
67
+ "ops": [
68
+ { "type": "set", "x": 3, "y": 3, "color": "#00ff00ff" },
69
+ { "type": "rect", "x": 0, "y": 0, "w": 8, "h": 1, "color": "#ffffffff" },
70
+ { "type": "fill", "x": 4, "y": 4, "color": "#ff0000ff" },
71
+ { "type": "clear" }
72
+ ]
73
+ }
74
+ ```
75
+
76
+ - `set`: integer in-bounds `x,y`; `color` `"transparent"`/`null` erases.
77
+ - `rect`: integer `x,y,w,h`, `w>=1`, `h>=1`; clipped to canvas; filled `color`.
78
+ - `fill`: 4-neighbor flood fill same-color region from `x,y`.
79
+ - `clear`: all transparent; size retained.
80
+ Ops are ordered; invalid op rejects entire edit. No extra ops. Human UI edits use `edit_pixels` with `base_revision`; undo/redo are local UI, not engine tools.
81
+
82
+ ## PNG export
83
+
84
+ PNG is not a fourth tool. `pixelart export --project pixelart.json --out art.png --scale 16`. `scale` is positive integer; no anti-aliasing; transparency preserved; output size `size*scale`. Server `GET /api/export.png?scale=16`. Web UI exports PNG. Verify signature/dimensions if needed; do not claim visual inspection without seeing pixels.
85
+
86
+ ## Live server / web UI
87
+
88
+ `pixelart serve --project pixelart.json --port 4173 --host 127.0.0.1`. APIs: `GET /api/read_pixels`, `POST /api/write_pixels`, `POST /api/edit_pixels`, `GET /api/export.png`, `GET /api/health`. WebSocket `/ws` sends `{type:"hello",...}` then `{type:"state",...}`; one broadcast per mutation. Web UI is vanilla canvas; no extra engine tools.
89
+
90
+ ## Agent workflow for high-quality pixel art
91
+
92
+ 1. **Brief.** Choose `size` `8|16|32`, square sprite/icon/tile/scene, subject, viewpoint, pose, background transparent vs filled, light direction, outline policy, symmetry, palette size, target scale, PNG output. Ask only if ambiguity changes work; otherwise choose sensible defaults. `8x8` = tiny symbol; `16x16` = readable sprite; `32x32` = detailed sprite with restraint.
93
+ 2. **Plan silhouette first.** Ensure readable silhouette at `1x`; no noisy stray pixels; cluster shapes; align intentionally; use symmetry where it serves subject; keep simple negative space. Do not anti-alias canvas pixels. Canvas `image-rendering:pixelated`.
94
+ 3. **Plan palette.** Limited coherent palette. `8x8` usually 2-4 colors; `16x16` 4-8; `32x32` still limited. Pick transparent `#00000000`, outline, base, shadow, highlight, one accent. Use harmonious ramps; shadows cooler/darker, highlights warmer/lighter as appropriate; avoid pure black/white unless intentional. `palette` optional but no unlisted accidental colors. Keep transparency separate from dark outline.
95
+ 4. **Draw in one full `write_pixels`.** Produce complete row-major `size*size` canonical `#rrggbbaa`. No per-pixel calls. Simple art may have few colors; do not fill every pixel accidentally. Use `#00000000` for transparent.
96
+ 5. **Construct deliberately.** Use `fill` for contiguous regions, `rect` for clean spans, `set` for details. No random dithering on `8x8`; use sparse intentional dithering on `16/32` only. Keep outlines consistent; avoid isolated shading; shade clusters; no AA; no half-alpha unless purposeful; preserve canonical color independence from chrome.
97
+ 6. **Read back.** `read_pixels`; verify `ok`, `size`, length, canonical lowercase colors, no unintended palette drift, `revision`, changed pixels. Compare to intended composition.
98
+ 7. **Fix mistakes atomically.** `edit_pixels` targeted `set`/`rect`/`fill`/`clear`, with `base_revision` from read. Do not claim success before readback. On `revision_conflict`, re-read and recompute. On validation, no partial mutation.
99
+ 8. **Verify output.** Re-read final state; export PNG integer scale; check PNG signature/dimensions `size*scale`; no AA; transparency. Report what was generated/checked, not visual claims without evidence.
100
+ 9. **Persist safely.** Project JSON atomic; corrupt project rejected, not silently reset. No secrets in project.
101
+
102
+ ## Non-goals
103
+
104
+ No AI generation inside Net-art; no MCP; no auth/cloud; no multi-user CRDT; no layers/animation; no non-square; no `swap_color`, `shift`, `flip`, `rotate`, `set_palette`; no engine undo; no `idempotency_key`; no GIF/sprite sheet; no `region` reads.
105
+
106
+ ## Minimal reliable pattern
107
+
108
+ ```bash
109
+ # 1. full batch
110
+ pixelart write_pixels --project pixelart.json --size 8 --pixels pixels.json --name sprite
111
+ # 2. read
112
+ pixelart read_pixels --project pixelart.json
113
+ # 3. targeted atomic fix with current revision
114
+ pixelart edit_pixels --project pixelart.json --ops ops.json --base-revision 1
115
+ # 4. verify
116
+ pixelart read_pixels --project pixelart.json
117
+ pixelart export --project pixelart.json --out sprite.png --scale 16
118
+ ```
package/README.md CHANGED
@@ -1,3 +1,175 @@
1
- # Temporary Holding Version
1
+ # Net-art v0.0.2
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Agent-native pixel art engine for extremely fast pixel art generation. One canonical canvas, one revision, three engine tools. A self-hosted webapp shows live agent work and lets a human edit manually. No cloud, no external service.
4
+
5
+ ## Requirements
6
+
7
+ - Node.js >= 22
8
+ - Chromium for Playwright e2e (`npx playwright install chromium`)
9
+
10
+ ## Build / run
11
+
12
+ ```bash
13
+ npm install
14
+ npm run build
15
+
16
+ # self-hosted live webapp
17
+ node dist/cli/pixelart.js serve --project pixelart.json --port 4173 --host 127.0.0.1
18
+ # open http://127.0.0.1:4173
19
+ ```
20
+
21
+ When `pixelart` is installed as a package, the binary is `pixelart`. All commands below use `node dist/cli/pixelart.js` from a repo checkout.
22
+
23
+ ## Agent-native CLI
24
+
25
+ No TTY. No interactive prompts. JSON on stdout. `--json` is default. Input JSON from file or `-` stdin. Stable error shape `{ "ok": false, "error": { "code", "message", "field?" } }`. Exit codes: `0` ok, `1` validation, `2` revision conflict, `3` io, `4` not found/server.
26
+
27
+ ### The 3 engine tools
28
+
29
+ #### 1. `write_pixels`
30
+
31
+ Create or overwrite the whole canvas in **one batch**.
32
+
33
+ ```bash
34
+ node dist/cli/pixelart.js write_pixels \
35
+ --project pixelart.json \
36
+ --size 8 \
37
+ --pixels pixels.json \
38
+ [--palette palette.json] \
39
+ [--name mushroom] \
40
+ [--server http://127.0.0.1:4173]
41
+ ```
42
+
43
+ `pixels.json`: flat row-major array length `size * size`. `size` = `8 | 16 | 32`.
44
+
45
+ ```json
46
+ ["#00000000", "#ff0000ff", "#00ff00ff", "..."]
47
+ ```
48
+
49
+ Accepted color input: `#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`, `"transparent"`, `null`. Canonical output `#rrggbbaa` lowercase; transparent `#00000000`. `palette` optional; pixels are truth. If `palette` omitted, derived in first-appearance order. Order `(x,y) -> y*size+x`.
50
+
51
+ Output: `{ ok:true, revision, size, name, pixels, palette, updatedAt }`.
52
+
53
+ #### 2. `read_pixels`
54
+
55
+ ```bash
56
+ node dist/cli/pixelart.js read_pixels --project pixelart.json
57
+ node dist/cli/pixelart.js read_pixels --server http://127.0.0.1:4173
58
+ ```
59
+
60
+ Output canonical snapshot. No mutation.
61
+
62
+ #### 3. `edit_pixels`
63
+
64
+ Atomic ordered ops. Validate all; no partial mutation.
65
+
66
+ ```bash
67
+ node dist/cli/pixelart.js edit_pixels \
68
+ --project pixelart.json \
69
+ --ops ops.json \
70
+ [--base-revision 3] \
71
+ [--server http://127.0.0.1:4173]
72
+ ```
73
+
74
+ `ops.json`: `{ "ops": [...] }` or bare `[...]`; `base_revision` can be in file or `--base-revision`.
75
+
76
+ ```json
77
+ {
78
+ "base_revision": 3,
79
+ "ops": [
80
+ { "type": "set", "x": 3, "y": 3, "color": "#00ff00ff" },
81
+ { "type": "rect", "x": 0, "y": 0, "w": 8, "h": 1, "color": "#ffffffff" },
82
+ { "type": "fill", "x": 4, "y": 4, "color": "#ff0000ff" },
83
+ { "type": "clear" }
84
+ ]
85
+ }
86
+ ```
87
+
88
+ - `set`: `x,y` in bounds; `color` `"transparent"`/`null` erases.
89
+ - `rect`: integer `x,y,w,h`; `w/h>=1`; clipped to canvas.
90
+ - `fill`: 4-neighbor flood fill same-color region.
91
+ - `clear`: all transparent; size retained.
92
+
93
+ Output adds `applied`, `changed_pixels: [{x,y,from,to}]`.
94
+
95
+ ### Stdin
96
+
97
+ ```bash
98
+ node dist/cli/pixelart.js write_pixels --project pixelart.json --size 8 --pixels - < pixels.json
99
+ ```
100
+
101
+ ### Server mode (single writer)
102
+
103
+ Pick one per project. Offline CLI edits file; `serve` owns writes when `--server` is used. Do not edit the file directly while server runs.
104
+
105
+ ```bash
106
+ node dist/cli/pixelart.js serve --project pixelart.json --port 4173
107
+ node dist/cli/pixelart.js edit_pixels --server http://127.0.0.1:4173 --ops ops.json --base-revision 3
108
+ ```
109
+
110
+ ### PNG export (not a 4th engine tool)
111
+
112
+ ```bash
113
+ node dist/cli/pixelart.js export --project pixelart.json --out art.png --scale 16
114
+ ```
115
+
116
+ Integer `scale`; no anti-aliasing; transparency preserved. Browser UI also exports PNG. Server `GET /api/export.png?scale=16`.
117
+
118
+ ## Concurrency
119
+
120
+ - Single canonical `ProjectState`; mutations serialized; atomic; no silent partial.
121
+ - `revision` starts `0`; increments only when canonical `size`, `pixels`, `palette`, `name` changes; no-op returns `revision` unchanged, `changed_pixels: []`.
122
+ - `edit_pixels.base_revision` optional. If present must equal current; mismatch -> `revision_conflict`, no mutation. If omitted last-write-wins.
123
+ - Human UI uses `edit_pixels` with `base_revision`; human edits increment `revision` like agent edits. No locks in v0.0.1.
124
+ - Retry: `read_pixels` -> recompute -> `edit_pixels { base_revision }`.
125
+
126
+ ## Project file
127
+
128
+ Default `pixelart.json`. Atomic tmp+rename. Corrupt file rejected, not silently reset.
129
+
130
+ ```json
131
+ {
132
+ "version": 1,
133
+ "name": "mushroom",
134
+ "size": 8,
135
+ "pixels": ["#00000000"],
136
+ "palette": ["#00000000"],
137
+ "revision": 1,
138
+ "updatedAt": "2026-11-29T00:00:00.000Z"
139
+ }
140
+ ```
141
+
142
+ `pixels` length `size*size`. `version=1`. No secrets.
143
+
144
+ ## Webapp
145
+
146
+ `pixelart serve` serves UI + API + WebSocket. No framework; vanilla TS canvas. Local self-hosted.
147
+
148
+ - Live `WebSocket /ws`: `{type:"hello",...}`, `{type:"state",...}`; one broadcast per mutation.
149
+ - APIs: `GET /api/read_pixels`, `POST /api/write_pixels`, `POST /api/edit_pixels`, `GET /api/export.png`, `GET /api/health`.
150
+ - Human tools: paint, erase, eyedropper, flood fill, filled rect, clear, palette, current color, transparent, undo/redo, zoom +/-, grid, keyboard, new `8/16/32`, rename, PNG.
151
+ - Canvas `image-rendering:pixelated`; transparency checkerboard; `aria` + keyboard + focus; reduced motion. No layers/animation.
152
+ - Keyboard: `B` paint, `E` erase, `I` pick, `F` fill, `R` rect, `G` grid, `Ctrl/Cmd+Z`, `Ctrl/Cmd+Shift+Z`, `Ctrl/Cmd+Y`, arrows + Enter/Space on canvas, `+`/`-` zoom.
153
+
154
+ ## Design
155
+
156
+ Operate mode. "The Calm Instrument." `PRODUCT.md`, `DESIGN.md`, `.impeccable/design.json`, `.impeccable/surfaces/src-web-index-html.md`. Impeccable used; mechanical detector `impeccable detect --json` returns no findings. Screenshots `.impeccable/review/`. No generated raster assets. No icons/fonts external.
157
+
158
+ ## Non-goals v0.0.1
159
+
160
+ No AI generation inside engine; no MCP; no cloud/auth; no multi-user CRDT; no layers/animation; no non-square; no `swap_color`/`shift`/`flip`/`rotate`; no `set_palette` tool; no engine-level undo; no `idempotency_key`; no GIF/sprite sheet; no `region` reads.
161
+
162
+ ## Tests
163
+
164
+ ```bash
165
+ npm run typecheck
166
+ npm run build
167
+ npm test # build + vitest unit + CLI + server + Playwright e2e
168
+ npm run test:unit
169
+ npm run test:cli
170
+ npm run test:server
171
+ npm run test:e2e # Playwright; uses built dist
172
+ npx playwright install chromium
173
+ ```
174
+
175
+ E2E uses Playwright Chromium. Verifies live UI, agent batch, human read, undo/redo, tools, keyboard, new size, PNG download, CLI, server, conflict, persistence, corrupt-file safety. Screenshots `test-results/pixel-art-*.png`.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,198 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from "commander";
3
+ import { readFile, writeFile } from "node:fs/promises";
4
+ import { resolve } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import { asEngineError, editPixels, readPixels, toSnapshot, writePixels } from "../engine/engine.js";
7
+ import { loadProject, saveProject } from "../engine/store.js";
8
+ import { renderPng } from "../export/png.js";
9
+ import { startServer } from "../server/http.js";
10
+ const EXIT_VALIDATION = 1;
11
+ const EXIT_CONFLICT = 2;
12
+ const EXIT_IO = 3;
13
+ const EXIT_NOT_FOUND = 4;
14
+ const program = new Command();
15
+ program.name("pixelart").version("0.0.1").description("Agent-native pixel art engine").option("--json", "JSON output", true);
16
+ program
17
+ .command("write_pixels")
18
+ .description("Create or overwrite a canvas in one batch")
19
+ .requiredOption("--size <n>", "8 | 16 | 32", (value) => Number(value))
20
+ .requiredOption("--pixels <file>", "flat row-major pixel array JSON, or - for stdin")
21
+ .option("--palette <file>", "palette JSON array")
22
+ .option("--name <name>", "project name")
23
+ .option("--project <file>", "project file", "pixelart.json")
24
+ .option("--server <url>", "use running server as single writer")
25
+ .action(async (opts) => {
26
+ await run(async () => {
27
+ const pixels = await readJsonInput(opts.pixels);
28
+ const payload = { size: opts.size, pixels };
29
+ if (opts.palette !== undefined)
30
+ payload["palette"] = await readJsonInput(opts.palette);
31
+ if (opts.name !== undefined)
32
+ payload["name"] = opts.name;
33
+ if (opts.server !== undefined) {
34
+ const result = await requestJson(opts.server, "POST", "/api/write_pixels", payload);
35
+ print(result);
36
+ return;
37
+ }
38
+ const current = await loadProjectOrNull(opts.project);
39
+ const result = writePixels(current, payload);
40
+ if (!result.ok)
41
+ throw new CliError(result.error);
42
+ await saveProject(opts.project, result.data.state);
43
+ print({ ...toSnapshot(result.data.state), ok: true });
44
+ });
45
+ });
46
+ program
47
+ .command("read_pixels")
48
+ .description("Read current canonical snapshot")
49
+ .option("--project <file>", "project file", "pixelart.json")
50
+ .option("--server <url>", "use running server")
51
+ .action(async (opts) => {
52
+ await run(async () => {
53
+ if (opts.server !== undefined) {
54
+ print(await requestJson(opts.server, "GET", "/api/read_pixels"));
55
+ return;
56
+ }
57
+ const state = await loadProject(opts.project);
58
+ const result = readPixels(state);
59
+ if (!result.ok)
60
+ throw new CliError(result.error);
61
+ print(result.data);
62
+ });
63
+ });
64
+ program
65
+ .command("edit_pixels")
66
+ .description("Apply atomic edit ops")
67
+ .requiredOption("--ops <file>", "ops JSON, or - for stdin")
68
+ .option("--base-revision <n>", "expected revision", (value) => Number(value))
69
+ .option("--project <file>", "project file", "pixelart.json")
70
+ .option("--server <url>", "use running server as single writer")
71
+ .action(async (opts) => {
72
+ await run(async () => {
73
+ const opsRaw = await readJsonInput(opts.ops);
74
+ const ops = Array.isArray(opsRaw) ? opsRaw : opsRaw.ops;
75
+ const baseRevision = opts.baseRevision ?? opsRaw.base_revision;
76
+ const payload = { ops };
77
+ if (baseRevision !== undefined)
78
+ payload["base_revision"] = baseRevision;
79
+ if (opts.server !== undefined) {
80
+ print(await requestJson(opts.server, "POST", "/api/edit_pixels", payload));
81
+ return;
82
+ }
83
+ const state = await loadProject(opts.project);
84
+ const result = editPixels(state, payload);
85
+ if (!result.ok)
86
+ throw new CliError(result.error);
87
+ await saveProject(opts.project, result.data.state);
88
+ print({
89
+ ...toSnapshot(result.data.state),
90
+ ok: true,
91
+ applied: result.data.applied,
92
+ changed_pixels: result.data.changedPixels,
93
+ });
94
+ });
95
+ });
96
+ program
97
+ .command("serve")
98
+ .description("Start self-hosted webapp")
99
+ .option("--project <file>", "project file", "pixelart.json")
100
+ .option("--port <n>", "port", (value) => Number(value), 4173)
101
+ .option("--host <host>", "host", "127.0.0.1")
102
+ .action(async (opts) => {
103
+ await run(async () => {
104
+ const webRoot = fileURLToPath(new URL("../web", import.meta.url));
105
+ const running = await startServer({ projectPath: resolve(opts.project), port: opts.port, host: opts.host, webRoot });
106
+ print({ ok: true, url: running.url, project: resolve(opts.project) });
107
+ const shutdown = async () => {
108
+ await running.close();
109
+ process.exit(0);
110
+ };
111
+ process.on("SIGINT", shutdown);
112
+ process.on("SIGTERM", shutdown);
113
+ await new Promise(() => { });
114
+ });
115
+ });
116
+ program
117
+ .command("export")
118
+ .description("Export PNG")
119
+ .requiredOption("--out <file>", "output PNG")
120
+ .option("--scale <n>", "integer scale", (value) => Number(value), 16)
121
+ .option("--project <file>", "project file", "pixelart.json")
122
+ .action(async (opts) => {
123
+ await run(async () => {
124
+ const state = await loadProject(opts.project);
125
+ const png = renderPng(state, opts.scale);
126
+ await writeFile(opts.out, png);
127
+ print({ ok: true, out: resolve(opts.out), scale: opts.scale, size: state.size, revision: state.revision });
128
+ });
129
+ });
130
+ program.parseAsync(process.argv).catch((error) => {
131
+ fail(asEngineError(error, "internal_error"));
132
+ });
133
+ async function run(operation) {
134
+ try {
135
+ await operation();
136
+ }
137
+ catch (error) {
138
+ if (error instanceof CliError) {
139
+ fail(error.engineError);
140
+ return;
141
+ }
142
+ fail(asEngineError(error, "io_error"));
143
+ }
144
+ }
145
+ function fail(error) {
146
+ print({ ok: false, error });
147
+ process.exitCode = exitCodeFor(error.code);
148
+ }
149
+ function exitCodeFor(code) {
150
+ switch (code) {
151
+ case "revision_conflict": return EXIT_CONFLICT;
152
+ case "not_found": return EXIT_NOT_FOUND;
153
+ case "io_error": return EXIT_IO;
154
+ case "internal_error": return EXIT_IO;
155
+ case "validation_error": return EXIT_VALIDATION;
156
+ }
157
+ }
158
+ async function readJsonInput(source) {
159
+ const raw = source === "-" ? await readStdin() : await readFile(source, "utf8");
160
+ return JSON.parse(raw);
161
+ }
162
+ async function readStdin() {
163
+ const chunks = [];
164
+ for await (const chunk of process.stdin)
165
+ chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
166
+ return Buffer.concat(chunks).toString("utf8");
167
+ }
168
+ async function loadProjectOrNull(projectPath) {
169
+ try {
170
+ return await loadProject(projectPath);
171
+ }
172
+ catch (error) {
173
+ if (asEngineError(error).code === "not_found")
174
+ return null;
175
+ throw error;
176
+ }
177
+ }
178
+ async function requestJson(server, method, path, body) {
179
+ const init = { method, headers: { "content-type": "application/json" } };
180
+ if (body !== undefined)
181
+ init.body = JSON.stringify(body);
182
+ const response = await fetch(new URL(path, server.endsWith("/") ? server : `${server}/`), init);
183
+ const json = (await response.json());
184
+ if (!response.ok || json.ok === false)
185
+ throw new CliError(json.error ?? { code: "internal_error", message: `server ${response.status}` });
186
+ return json;
187
+ }
188
+ function print(value) {
189
+ process.stdout.write(`${JSON.stringify(value)}\n`);
190
+ }
191
+ class CliError extends Error {
192
+ engineError;
193
+ constructor(engineError) {
194
+ super(engineError.message);
195
+ this.engineError = engineError;
196
+ }
197
+ }
198
+ //# sourceMappingURL=pixelart.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pixelart.js","sourceRoot":"","sources":["../../src/cli/pixelart.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACrG,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD,MAAM,eAAe,GAAG,CAAC,CAAC;AAC1B,MAAM,aAAa,GAAG,CAAC,CAAC;AACxB,MAAM,OAAO,GAAG,CAAC,CAAC;AAClB,MAAM,cAAc,GAAG,CAAC,CAAC;AAEzB,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAC9B,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,+BAA+B,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,aAAa,EAAE,IAAI,CAAC,CAAC;AAE7H,OAAO;KACJ,OAAO,CAAC,cAAc,CAAC;KACvB,WAAW,CAAC,2CAA2C,CAAC;KACxD,cAAc,CAAC,YAAY,EAAE,aAAa,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;KACrE,cAAc,CAAC,iBAAiB,EAAE,iDAAiD,CAAC;KACpF,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,CAAC;AACd,CAAC;AAED,SAAS,KAAK,CAAC,KAAc;IAC3B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACrD,CAAC;AAED,MAAM,QAAS,SAAQ,KAAK;IACjB,WAAW,CAAc;IAClC,YAAY,WAAwB;QAClC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QAC3B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;CACF"}
@@ -0,0 +1,11 @@
1
+ import { type CanonicalColor, type ChangedPixel, type EditOp, type PixelSize, type ProjectState } from "./types.js";
2
+ export declare function parseSize(value: unknown, field?: string): PixelSize;
3
+ export declare function createEmptyState(size: PixelSize, name: string, now?: string): ProjectState;
4
+ export declare function cloneState(state: ProjectState): ProjectState;
5
+ export declare function parsePixelArray(raw: unknown, size: PixelSize, field?: string): CanonicalColor[];
6
+ export declare function parsePalette(raw: unknown, field?: string): CanonicalColor[];
7
+ export declare function parseName(raw: unknown, fallback?: string, field?: string): string;
8
+ export declare function parseEditOps(raw: unknown, size: PixelSize, field?: string): EditOp[];
9
+ export declare function applyEditOps(pixels: readonly CanonicalColor[], size: PixelSize, ops: readonly EditOp[]): CanonicalColor[];
10
+ export declare function diffPixels(before: readonly CanonicalColor[], after: readonly CanonicalColor[], size: PixelSize): ChangedPixel[];
11
+ export declare function isPixelSize(value: unknown): value is PixelSize;