@nexart/cli 0.2.2 → 0.3.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
@@ -1,6 +1,6 @@
1
- # @nexart/cli v0.2.2
1
+ # @nexart/cli v0.3.0
2
2
 
3
- Command-line interface for NexArt CodeMode — run, replay, and verify deterministic generative art.
3
+ Command-line interface for NexArt — run, replay, and verify deterministic generative art, plus AI execution certification commands.
4
4
 
5
5
  ## Installation
6
6
 
@@ -12,6 +12,57 @@ npm install -g @nexart/cli
12
12
  nexart run sketch.js --seed 12345
13
13
  ```
14
14
 
15
+ ## Quickstart: Run an Example
16
+
17
+ The SDK includes example sketches in the `examples/` folder:
18
+
19
+ ```bash
20
+ # 1. Set up authentication
21
+ export NEXART_RENDERER_ENDPOINT=https://nexart-canonical-renderer-production.up.railway.app
22
+ export NEXART_API_KEY=nx_live_your_key_here
23
+
24
+ # 2. Run the main example sketch (outputs to current directory)
25
+ npx @nexart/cli run ./examples/sketch.js --seed 12345 --include-code --out ./out.png
26
+ # Creates: ./out.png and ./out.snapshot.json
27
+
28
+ # 3. Verify the output is deterministic
29
+ npx @nexart/cli verify ./out.snapshot.json
30
+ # Output: [nexart] Result: PASS
31
+ ```
32
+
33
+ ### Output Files
34
+
35
+ When you run with `--out ./out.png`, the CLI creates:
36
+ - `./out.png` — The rendered PNG image
37
+ - `./out.snapshot.json` — Snapshot for replay/verify
38
+
39
+ ### Example Sketches
40
+
41
+ | File | Description |
42
+ |------|-------------|
43
+ | `examples/sketch.js` | Main example — VAR controls + random palette, protocol-safe |
44
+ | `examples/sketch-minimal.js` | Simple shapes, no randomness — identical output every run |
45
+ | `examples/sketch-vars.js` | Uses VAR + random() — demonstrates determinism with same seed |
46
+
47
+ ## Canonical Size
48
+
49
+ The canonical renderer enforces a fixed canvas size:
50
+
51
+ | Property | Value |
52
+ |----------|-------|
53
+ | Width | 1950 |
54
+ | Height | 2400 |
55
+
56
+ **Important:** Do not pass custom `--width` or `--height` to the canonical renderer endpoint. The canonical size is enforced server-side for consistent, verifiable output.
57
+
58
+ ```bash
59
+ # Correct: use default canonical size
60
+ nexart run sketch.js --seed 12345
61
+
62
+ # Avoid: custom sizes may be rejected by canonical renderer
63
+ # nexart run sketch.js --width 800 --height 600 # NOT recommended
64
+ ```
65
+
15
66
  ## Quick Start (npx)
16
67
 
17
68
  Run without installing globally:
@@ -25,14 +76,11 @@ npx @nexart/cli replay out.snapshot.json --out replay.png
25
76
 
26
77
  ## Overview
27
78
 
28
- The CLI renders Code Mode sketches via a **remote canonical renderer** and creates verifiable snapshots.
79
+ The CLI has two command groups:
80
+
81
+ **Code Mode commands** — render generative art sketches, create verifiable snapshots, replay and verify them.
29
82
 
30
- **v0.2.2 features:**
31
- - Authenticated remote rendering with API keys
32
- - Real PNG output via remote renderer
33
- - Snapshot v1 format with SHA-256 hashing
34
- - Verify and replay commands
35
- - Optional code embedding in snapshots
83
+ **AI certification commands** — create, certify, and verify tamper-evident Canonical Execution Records (CERs) for AI operations via the NexArt node API.
36
84
 
37
85
  ## Authentication
38
86
 
@@ -46,7 +94,7 @@ export NEXART_RENDERER_ENDPOINT=https://nexart-canonical-renderer-production.up.
46
94
  export NEXART_API_KEY=nx_live_your_key_here
47
95
 
48
96
  # Run with authentication
49
- npx @nexart/cli@0.2.2 run sketch.js --seed 12345 --include-code --out out.png
97
+ npx @nexart/cli run sketch.js --seed 12345 --include-code --out out.png
50
98
  ```
51
99
 
52
100
  ### API Key Options
@@ -71,7 +119,7 @@ If authentication fails:
71
119
 
72
120
  ## Commands
73
121
 
74
- ### Run
122
+ ### run
75
123
 
76
124
  Execute a sketch and create a snapshot:
77
125
 
@@ -92,8 +140,8 @@ nexart run sketch.js --renderer local
92
140
  | `--out, -o` | out.png | Output PNG path |
93
141
  | `--seed, -s` | random | PRNG seed |
94
142
  | `--vars, -v` | 0,0,0,0,0,0,0,0,0,0 | VAR values (comma-separated) |
95
- | `--width, -w` | 1950 | Canvas width |
96
- | `--height` | 2400 | Canvas height |
143
+ | `--width, -w` | 1950 | Canvas width (use default for canonical) |
144
+ | `--height` | 2400 | Canvas height (use default for canonical) |
97
145
  | `--renderer` | remote | `remote` or `local` |
98
146
  | `--endpoint` | env/localhost:5000 | Remote renderer URL |
99
147
  | `--api-key` | env | API key for authentication |
@@ -104,7 +152,7 @@ nexart run sketch.js --renderer local
104
152
  - `render.png` — The rendered image
105
153
  - `render.snapshot.json` — Snapshot for replay/verify
106
154
 
107
- ### Verify
155
+ ### verify
108
156
 
109
157
  Check that a snapshot produces the expected output:
110
158
 
@@ -119,7 +167,7 @@ nexart verify render.snapshot.json --code sketch.js
119
167
  - `0` — PASS (hashes match)
120
168
  - `1` — FAIL (hashes differ or error)
121
169
 
122
- ### Replay
170
+ ### replay
123
171
 
124
172
  Re-execute from a snapshot:
125
173
 
@@ -130,6 +178,165 @@ nexart replay render.snapshot.json --out replay.png
130
178
  nexart replay render.snapshot.json --code sketch.js --out replay.png
131
179
  ```
132
180
 
181
+ ---
182
+
183
+ ## AI Certification Commands (`nexart ai`)
184
+
185
+ These commands interact with the NexArt node API to manage Canonical Execution Records (CERs) for AI operations. CERs are tamper-evident bundles that cryptographically certify an AI execution (input, output, model, parameters).
186
+
187
+ ### Environment Variables
188
+
189
+ | Variable | Description |
190
+ |----------|-------------|
191
+ | `NEXART_NODE_ENDPOINT` | NexArt node API URL (default: `https://node.nexart.art`) |
192
+ | `NEXART_API_KEY` | Shared API key for authenticated requests |
193
+
194
+ ### `nexart ai create`
195
+
196
+ Create a CER bundle from an AI execution record.
197
+
198
+ ```bash
199
+ # From file
200
+ nexart ai create execution.json
201
+
202
+ # From stdin
203
+ cat execution.json | nexart ai create
204
+
205
+ # With explicit endpoint and API key
206
+ nexart ai create execution.json \
207
+ --endpoint https://node.nexart.art \
208
+ --api-key nx_live_...
209
+
210
+ # Save to file
211
+ nexart ai create execution.json --out cer.json
212
+ ```
213
+
214
+ **Input format** (JSON file or stdin):
215
+ ```json
216
+ {
217
+ "executionId": "exec-001",
218
+ "provider": "openai",
219
+ "model": "gpt-4o",
220
+ "input": "What is 2+2?",
221
+ "output": "4",
222
+ "parameters": { "temperature": 0 }
223
+ }
224
+ ```
225
+
226
+ **Output:** CER bundle JSON printed to stdout (or saved via `--out`).
227
+
228
+ **Options:**
229
+ | Flag | Default | Description |
230
+ |------|---------|-------------|
231
+ | `--endpoint` | env/`https://node.nexart.art` | NexArt node URL |
232
+ | `--api-key` | env | API key |
233
+ | `--out` | stdout | Save bundle to file |
234
+
235
+ **Exit codes:**
236
+ - `0` — Success
237
+ - `1` — API error or missing input
238
+
239
+ ### `nexart ai certify`
240
+
241
+ Certify an AI execution and receive an attested CER bundle. The node API signs the bundle and attaches an attestation.
242
+
243
+ ```bash
244
+ # From file
245
+ nexart ai certify execution.json
246
+
247
+ # From stdin
248
+ cat execution.json | nexart ai certify
249
+
250
+ # JSON output (machine-readable)
251
+ nexart ai certify execution.json --json
252
+
253
+ # Save output
254
+ nexart ai certify execution.json --out certified.json
255
+ ```
256
+
257
+ **Default output:**
258
+ ```
259
+ [nexart] CER certified successfully
260
+ bundleType : cer.ai.execution.v1
261
+ hash : sha256:a1b2c3...
262
+ attestation: present
263
+ ```
264
+
265
+ **JSON output** (`--json`):
266
+ ```json
267
+ {
268
+ "ok": true,
269
+ "bundleType": "cer.ai.execution.v1",
270
+ "certificateHash": "sha256:a1b2c3...",
271
+ "hasAttestation": true,
272
+ "bundle": { ... }
273
+ }
274
+ ```
275
+
276
+ **Options:**
277
+ | Flag | Default | Description |
278
+ |------|---------|-------------|
279
+ | `--endpoint` | env/`https://node.nexart.art` | NexArt node URL |
280
+ | `--api-key` | env | API key |
281
+ | `--out` | stdout | Save bundle to file |
282
+ | `--json` | false | Machine-readable JSON output |
283
+
284
+ **Exit codes:**
285
+ - `0` — Certified successfully
286
+ - `1` — API error (e.g. 401 Unauthorized), missing input, or invalid response
287
+
288
+ ### `nexart ai verify`
289
+
290
+ Verify a CER bundle locally. No network call — computes and compares the `certificateHash` against the bundle contents.
291
+
292
+ ```bash
293
+ # From file
294
+ nexart ai verify cer.json
295
+
296
+ # From stdin
297
+ cat cer.json | nexart ai verify
298
+
299
+ # JSON output
300
+ nexart ai verify cer.json --json
301
+ ```
302
+
303
+ **Default output (PASS):**
304
+ ```
305
+ [nexart] CER verification: PASS
306
+ bundleType : cer.ai.execution.v1
307
+ hash : sha256:a1b2c3...
308
+ attestation: present
309
+ ```
310
+
311
+ **Default output (FAIL):**
312
+ ```
313
+ [nexart] CER verification: FAIL
314
+ reason : hash mismatch
315
+ expected : sha256:a1b2c3...
316
+ computed : sha256:d4e5f6...
317
+ ```
318
+
319
+ **JSON output** (`--json`):
320
+ ```json
321
+ {
322
+ "ok": true,
323
+ "bundleType": "cer.ai.execution.v1",
324
+ "certificateHash": "sha256:a1b2c3...",
325
+ "hasAttestation": true
326
+ }
327
+ ```
328
+
329
+ **Options:**
330
+ | Flag | Default | Description |
331
+ |------|---------|-------------|
332
+ | `--json` | false | Machine-readable JSON output |
333
+
334
+ **Exit codes:**
335
+ - `0` — PASS (hash matches)
336
+ - `1` — FAIL (hash mismatch or invalid bundle)
337
+
338
+ ---
339
+
133
340
  ## Remote Renderer
134
341
 
135
342
  The CLI calls a canonical Node.js renderer endpoint for real PNG generation.
@@ -172,7 +379,7 @@ Headers:
172
379
  curl -X POST https://nexart-canonical-renderer-production.up.railway.app/api/render \
173
380
  -H "Content-Type: application/json" \
174
381
  -H "Authorization: Bearer nx_live_..." \
175
- -d '{"code":"createCanvas(400,400);\nbackground(0);\n","seed":12345,"VAR":[0,0,0,0,0,0,0,0,0,0],"width":400,"height":400,"protocolVersion":"1.2.0"}' \
382
+ -d '{"code":"createCanvas(1950,2400);\nbackground(0);\n","seed":12345,"VAR":[0,0,0,0,0,0,0,0,0,0],"width":1950,"height":2400,"protocolVersion":"1.2.0"}' \
176
383
  --output render.png
177
384
  ```
178
385
 
@@ -221,7 +428,8 @@ Real local/offline rendering is planned for a future release.
221
428
  | Variable | Description |
222
429
  |----------|-------------|
223
430
  | `NEXART_RENDERER_ENDPOINT` | Remote renderer URL (default: http://localhost:5000) |
224
- | `NEXART_API_KEY` | API key for authenticated rendering |
431
+ | `NEXART_NODE_ENDPOINT` | NexArt node API URL (default: https://node.nexart.art) |
432
+ | `NEXART_API_KEY` | API key for authenticated requests |
225
433
 
226
434
  ## License
227
435
 
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @nexart/cli v0.3.0 — AI command tests
3
+ *
4
+ * Tests:
5
+ * A) canonicalJson + computeBundleHash (unit)
6
+ * B) readInputJson — file input
7
+ * C) readInputJson — stdin input
8
+ * D) aiCreateCommand — request/response
9
+ * E) aiCertifyCommand — summary output
10
+ * F) aiCertifyCommand — --json output
11
+ * G) aiVerifyCommand — PASS
12
+ * H) aiVerifyCommand — FAIL (tampered hash)
13
+ * I) aiVerifyCommand — FAIL (wrong bundleType)
14
+ * J) aiVerifyCommand — attestation present/absent
15
+ * K) aiVerifyCommand — --json output
16
+ * L) backward compat — Code Mode exports exist
17
+ * M) callNodeApi — sets Authorization header and sends body
18
+ * N) aiCreateCommand — stdin input
19
+ * O) aiCertifyCommand — stdin input
20
+ * P) aiCreateCommand — saves --out file
21
+ * Q) aiCertifyCommand — 401 handling
22
+ */
23
+ export {};
24
+ //# sourceMappingURL=ai.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/ai.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG"}