@nexart/codemode-sdk 1.6.0 → 1.8.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.
Files changed (121) hide show
  1. package/CHANGELOG.md +101 -0
  2. package/README.md +221 -9
  3. package/dist/core-index.d.ts +1 -1
  4. package/dist/core-index.js +1 -1
  5. package/dist/entry/browser.d.ts +43 -0
  6. package/dist/entry/browser.d.ts.map +1 -0
  7. package/dist/entry/browser.js +63 -0
  8. package/dist/entry/node.d.ts +23 -0
  9. package/dist/entry/node.d.ts.map +1 -0
  10. package/dist/entry/node.js +34 -0
  11. package/dist/index.d.ts +14 -33
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +41 -33
  14. package/dist/runtime.d.ts +52 -0
  15. package/dist/runtime.d.ts.map +1 -0
  16. package/dist/runtime.js +219 -0
  17. package/dist/sdk/codemode/builder-manifest.d.ts +79 -0
  18. package/dist/sdk/codemode/builder-manifest.d.ts.map +1 -0
  19. package/dist/sdk/codemode/builder-manifest.js +97 -0
  20. package/dist/sdk/codemode/core-index.d.ts +21 -0
  21. package/dist/sdk/codemode/core-index.d.ts.map +1 -0
  22. package/dist/sdk/codemode/core-index.js +26 -0
  23. package/dist/sdk/codemode/engine.d.ts +24 -0
  24. package/dist/sdk/codemode/engine.d.ts.map +1 -0
  25. package/dist/sdk/codemode/engine.js +67 -0
  26. package/dist/sdk/codemode/execute.d.ts +46 -0
  27. package/dist/sdk/codemode/execute.d.ts.map +1 -0
  28. package/dist/sdk/codemode/execute.js +283 -0
  29. package/dist/sdk/codemode/execution-sandbox.d.ts +107 -0
  30. package/dist/sdk/codemode/execution-sandbox.d.ts.map +1 -0
  31. package/dist/sdk/codemode/execution-sandbox.js +207 -0
  32. package/dist/sdk/codemode/index.d.ts +31 -0
  33. package/dist/sdk/codemode/index.d.ts.map +1 -0
  34. package/dist/sdk/codemode/index.js +63 -0
  35. package/dist/sdk/codemode/loop-engine.d.ts +22 -0
  36. package/dist/sdk/codemode/loop-engine.d.ts.map +1 -0
  37. package/dist/sdk/codemode/loop-engine.js +229 -0
  38. package/dist/sdk/codemode/noise-bridge.d.ts +44 -0
  39. package/dist/sdk/codemode/noise-bridge.d.ts.map +1 -0
  40. package/dist/sdk/codemode/noise-bridge.js +68 -0
  41. package/dist/sdk/codemode/noise-engine.d.ts +74 -0
  42. package/dist/sdk/codemode/noise-engine.d.ts.map +1 -0
  43. package/dist/sdk/codemode/noise-engine.js +132 -0
  44. package/dist/sdk/codemode/noise-sketches/fractalNoise.d.ts +11 -0
  45. package/dist/sdk/codemode/noise-sketches/fractalNoise.d.ts.map +1 -0
  46. package/dist/sdk/codemode/noise-sketches/fractalNoise.js +121 -0
  47. package/dist/sdk/codemode/noise-sketches/index.d.ts +21 -0
  48. package/dist/sdk/codemode/noise-sketches/index.d.ts.map +1 -0
  49. package/dist/sdk/codemode/noise-sketches/index.js +28 -0
  50. package/dist/sdk/codemode/p5-runtime.d.ts +75 -0
  51. package/dist/sdk/codemode/p5-runtime.d.ts.map +1 -0
  52. package/dist/sdk/codemode/p5-runtime.js +1031 -0
  53. package/dist/sdk/codemode/sound-bridge.d.ts +89 -0
  54. package/dist/sdk/codemode/sound-bridge.d.ts.map +1 -0
  55. package/dist/sdk/codemode/sound-bridge.js +128 -0
  56. package/dist/sdk/codemode/soundart-engine.d.ts +87 -0
  57. package/dist/sdk/codemode/soundart-engine.d.ts.map +1 -0
  58. package/dist/sdk/codemode/soundart-engine.js +173 -0
  59. package/dist/sdk/codemode/soundart-sketches/chladniBloom.d.ts +3 -0
  60. package/dist/sdk/codemode/soundart-sketches/chladniBloom.d.ts.map +1 -0
  61. package/dist/sdk/codemode/soundart-sketches/chladniBloom.js +53 -0
  62. package/dist/sdk/codemode/soundart-sketches/dualVortex.d.ts +3 -0
  63. package/dist/sdk/codemode/soundart-sketches/dualVortex.d.ts.map +1 -0
  64. package/dist/sdk/codemode/soundart-sketches/dualVortex.js +67 -0
  65. package/dist/sdk/codemode/soundart-sketches/geometryIllusion.d.ts +3 -0
  66. package/dist/sdk/codemode/soundart-sketches/geometryIllusion.d.ts.map +1 -0
  67. package/dist/sdk/codemode/soundart-sketches/geometryIllusion.js +89 -0
  68. package/dist/sdk/codemode/soundart-sketches/index.d.ts +39 -0
  69. package/dist/sdk/codemode/soundart-sketches/index.d.ts.map +1 -0
  70. package/dist/sdk/codemode/soundart-sketches/index.js +72 -0
  71. package/dist/sdk/codemode/soundart-sketches/isoflow.d.ts +3 -0
  72. package/dist/sdk/codemode/soundart-sketches/isoflow.d.ts.map +1 -0
  73. package/dist/sdk/codemode/soundart-sketches/isoflow.js +60 -0
  74. package/dist/sdk/codemode/soundart-sketches/loomWeave.d.ts +3 -0
  75. package/dist/sdk/codemode/soundart-sketches/loomWeave.d.ts.map +1 -0
  76. package/dist/sdk/codemode/soundart-sketches/loomWeave.js +59 -0
  77. package/dist/sdk/codemode/soundart-sketches/noiseTerraces.d.ts +3 -0
  78. package/dist/sdk/codemode/soundart-sketches/noiseTerraces.d.ts.map +1 -0
  79. package/dist/sdk/codemode/soundart-sketches/noiseTerraces.js +53 -0
  80. package/dist/sdk/codemode/soundart-sketches/orb.d.ts +3 -0
  81. package/dist/sdk/codemode/soundart-sketches/orb.d.ts.map +1 -0
  82. package/dist/sdk/codemode/soundart-sketches/orb.js +50 -0
  83. package/dist/sdk/codemode/soundart-sketches/pixelGlyphs.d.ts +3 -0
  84. package/dist/sdk/codemode/soundart-sketches/pixelGlyphs.d.ts.map +1 -0
  85. package/dist/sdk/codemode/soundart-sketches/pixelGlyphs.js +72 -0
  86. package/dist/sdk/codemode/soundart-sketches/prismFlowFields.d.ts +3 -0
  87. package/dist/sdk/codemode/soundart-sketches/prismFlowFields.d.ts.map +1 -0
  88. package/dist/sdk/codemode/soundart-sketches/prismFlowFields.js +51 -0
  89. package/dist/sdk/codemode/soundart-sketches/radialBurst.d.ts +3 -0
  90. package/dist/sdk/codemode/soundart-sketches/radialBurst.d.ts.map +1 -0
  91. package/dist/sdk/codemode/soundart-sketches/radialBurst.js +60 -0
  92. package/dist/sdk/codemode/soundart-sketches/resonantSoundBodies.d.ts +3 -0
  93. package/dist/sdk/codemode/soundart-sketches/resonantSoundBodies.d.ts.map +1 -0
  94. package/dist/sdk/codemode/soundart-sketches/resonantSoundBodies.js +89 -0
  95. package/dist/sdk/codemode/soundart-sketches/rings.d.ts +11 -0
  96. package/dist/sdk/codemode/soundart-sketches/rings.d.ts.map +1 -0
  97. package/dist/sdk/codemode/soundart-sketches/rings.js +89 -0
  98. package/dist/sdk/codemode/soundart-sketches/squares.d.ts +3 -0
  99. package/dist/sdk/codemode/soundart-sketches/squares.d.ts.map +1 -0
  100. package/dist/sdk/codemode/soundart-sketches/squares.js +52 -0
  101. package/dist/sdk/codemode/soundart-sketches/waveStripes.d.ts +3 -0
  102. package/dist/sdk/codemode/soundart-sketches/waveStripes.d.ts.map +1 -0
  103. package/dist/sdk/codemode/soundart-sketches/waveStripes.js +44 -0
  104. package/dist/sdk/codemode/static-engine.d.ts +20 -0
  105. package/dist/sdk/codemode/static-engine.d.ts.map +1 -0
  106. package/dist/sdk/codemode/static-engine.js +144 -0
  107. package/dist/sdk/codemode/types.d.ts +191 -0
  108. package/dist/sdk/codemode/types.d.ts.map +1 -0
  109. package/dist/sdk/codemode/types.js +32 -0
  110. package/dist/shared/noiseSnapshot.d.ts +59 -0
  111. package/dist/shared/noiseSnapshot.d.ts.map +1 -0
  112. package/dist/shared/noiseSnapshot.js +72 -0
  113. package/dist/shared/soundSnapshot.d.ts +94 -0
  114. package/dist/shared/soundSnapshot.d.ts.map +1 -0
  115. package/dist/shared/soundSnapshot.js +128 -0
  116. package/dist/static-engine.d.ts.map +1 -1
  117. package/dist/static-engine.js +24 -11
  118. package/examples/basic.ts +61 -0
  119. package/examples/preflight-test.ts +275 -0
  120. package/examples/verify.ts +151 -0
  121. package/package.json +45 -5
package/CHANGELOG.md CHANGED
@@ -4,6 +4,107 @@ All notable changes to @nexart/codemode-sdk will be documented in this file.
4
4
 
5
5
  ---
6
6
 
7
+ ## [1.8.0] — 2026-01-24
8
+
9
+ ### Added — Agent-First Runtime Authority Layer
10
+
11
+ **Additive, Non-Breaking Release**
12
+
13
+ This release introduces `createRuntime()` — an agent-first API designed for AI coding assistants (Replit, Lovable, Claude Code) to reliably execute deterministic code without rolling their own PRNG/noise implementations.
14
+
15
+ #### New Runtime API (`createRuntime`)
16
+ - **`createRuntime(options)`** — Create a deterministic runtime instance
17
+ - `seed: string | number` — Seed for deterministic randomness
18
+ - `vars?: number[]` — VAR array (0-100 inputs), defaults to zeros
19
+ - `strict?: boolean` — Enable strict mode (default: false)
20
+ - `mode?: 'static' | 'loop'` — Execution mode (default: 'static')
21
+ - `metadata?: Record<string, any>` — Optional user metadata for digest
22
+
23
+ #### Runtime Methods
24
+ - **`random(): number`** — Deterministic random [0, 1) using Mulberry32
25
+ - **`randomInt(min, max): number`** — Deterministic integer in range
26
+ - **`randomRange(min, max): number`** — Deterministic float in range
27
+ - **`noise(x, y?, z?): number`** — Deterministic Perlin noise
28
+ - **`run(fn): T`** — Execute code with optional strict enforcement
29
+ - **`digest(): string`** — Stable hash for verification (FNV-1a)
30
+ - **`getState(): RuntimeState`** — Canonical state snapshot for replay
31
+
32
+ #### Strict Mode Enforcement
33
+ When `strict: true`, the runtime intercepts non-deterministic APIs during `run()`:
34
+ - `Math.random` → Throws with actionable error message
35
+ - `Date.now` → Throws with actionable error message
36
+ - `performance.now` → Throws with actionable error message
37
+
38
+ Error format: `NEXART_STRICT: Non-deterministic API used: {api}. {guidance}`
39
+
40
+ #### Documentation Updates
41
+ - Added "For AI Coding Agents" section at top of README
42
+ - Added "Determinism Contract" with ✅/❌ checklist
43
+ - Added "Why Not Just Use a PRNG?" comparison table
44
+ - Added "Environment Imports" matrix
45
+ - Simplified license section for clarity
46
+
47
+ #### Examples
48
+ - `examples/basic.ts` — Basic usage demonstration
49
+ - `examples/verify.ts` — Determinism verification tests
50
+ - `npm run example:basic` — Run basic example
51
+ - `npm run example:verify` — Run verification tests
52
+
53
+ #### Package Updates
54
+ - Added keywords: deterministic, reproducible, verifiable, replay, canonical, simulation, procedural, seed, prng, ai-agent, strict-mode
55
+ - Updated description for agent discoverability
56
+
57
+ ### Unchanged
58
+
59
+ - No changes to protocol behavior or determinism
60
+ - No changes to protocol version (remains v1.2.0)
61
+ - No changes to existing APIs (executeCodeMode, createEngine, etc.)
62
+ - Default import remains browser-safe
63
+ - Full backward compatibility with v1.7.x
64
+
65
+ ---
66
+
67
+ ## [1.7.0] — 2026-01-21
68
+
69
+ ### Added — Browser-Safe Entrypoint + Conditional Exports
70
+
71
+ **Packaging/Exports Update — No Breaking Changes**
72
+
73
+ This release makes the SDK reliably usable in browser environments (Vite/React) without any Node.js dependency leakage.
74
+
75
+ #### New Entry Points
76
+ - **`@nexart/codemode-sdk/browser`** — Browser-safe modules only
77
+ - All types, P5 runtime, loop engine, execution sandbox, validation, builder manifest
78
+ - Does NOT include static-engine or executeCodeMode (which require Node.js canvas)
79
+ - **`@nexart/codemode-sdk/node`** — Full SDK for Node.js
80
+ - Everything from browser entry plus static-engine and executeCodeMode
81
+ - Requires `canvas` package for static rendering
82
+
83
+ #### Package.json Conditional Exports
84
+ - Default import (`.`) uses conditional exports:
85
+ - Browser bundlers (Vite, webpack) → browser entry
86
+ - Node.js → node entry
87
+ - Explicit subpaths for direct control: `./browser` and `./node`
88
+
89
+ #### Why This Matters
90
+ - AI agents and bundlers will no longer accidentally import Node.js modules
91
+ - Vite/React apps can safely import without "createRequire is not defined" errors
92
+ - Server-side code gets full functionality including static image rendering
93
+
94
+ #### Files Added
95
+ - `entry/browser.ts` — Browser-safe entry point
96
+ - `entry/node.ts` — Node.js entry point (re-exports browser + adds static-engine)
97
+
98
+ ### Unchanged
99
+
100
+ - No changes to protocol behavior or determinism
101
+ - No changes to protocol version (remains v1.2.0)
102
+ - No changes to API surface (all functions work the same)
103
+ - Full backward compatibility with v1.6.x
104
+ - Existing sketches run unchanged
105
+
106
+ ---
107
+
7
108
  ## [1.6.0] — 2026-01-12
8
109
 
9
110
  ### Added — Licensing & Builder Identity Scaffolding
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # NexArt Code Mode Runtime SDK
2
2
 
3
- **Version: 1.6.0 (Protocol v1.2.0)**
3
+ **Version: 1.8.0 (Protocol v1.2.0)**
4
4
 
5
5
  ╔══════════════════════════════════════════════════════════════════════════════╗
6
6
  ║ @nexart/codemode-sdk — Canonical Execution Surface ║
@@ -9,7 +9,7 @@
9
9
  ║ ║
10
10
  ║ Protocol: nexart ║
11
11
  ║ Engine: codemode ║
12
- ║ SDK Version: 1.6.0 ║
12
+ ║ SDK Version: 1.8.0 ║
13
13
  ║ Protocol Version: 1.2.0 ║
14
14
  ║ Phase: 3 ║
15
15
  ║ Enforcement: HARD ║
@@ -17,12 +17,90 @@
17
17
 
18
18
  ---
19
19
 
20
- ## Commercial Licensing
20
+ ## For AI Coding Agents (Replit / Lovable / Claude Code)
21
21
 
22
- > **Commercial usage of NexArt Protocol requires a license.**
23
- > **Enforcement is not active yet.**
22
+ **ALWAYS use `createRuntime({ seed, strict: true })` for deterministic execution.**
24
23
 
25
- The SDK is currently provided under the MIT License for all usage. A future version may introduce commercial licensing requirements. See [LICENSE.md](./LICENSE.md) for details.
24
+ ```typescript
25
+ import { createRuntime } from "@nexart/codemode-sdk";
26
+
27
+ const runtime = createRuntime({
28
+ seed: "my-artwork-42",
29
+ vars: [50, 75, 25],
30
+ strict: true, // IMPORTANT: Throws on Math.random, Date.now, etc.
31
+ mode: "static"
32
+ });
33
+
34
+ // Use runtime.random() instead of Math.random()
35
+ const value = runtime.random(); // Deterministic [0, 1)
36
+ const intVal = runtime.randomInt(0, 10); // Deterministic integer
37
+ const n = runtime.noise(x, y); // Deterministic Perlin noise
38
+
39
+ // Verify determinism
40
+ console.log(runtime.digest()); // Stable hash for verification
41
+ console.log(runtime.getState()); // Canonical state snapshot
42
+ ```
43
+
44
+ **Strict mode throws actionable errors:**
45
+ - `NEXART_STRICT: Non-deterministic API used: Math.random. Use runtime.random() instead.`
46
+ - `NEXART_STRICT: Non-deterministic API used: Date.now. Pass time as an input or use deterministic counters.`
47
+ - `NEXART_STRICT: Non-deterministic API used: performance.now.`
48
+
49
+ ---
50
+
51
+ ## Determinism Contract
52
+
53
+ ✅ **Guaranteed:**
54
+ - Same `sdkVersion` + `seed` + `vars` → identical output
55
+ - Cross-environment stable digest (browser, Node.js, CI)
56
+ - Seeded PRNG via `runtime.random()` (Mulberry32)
57
+ - Seeded noise via `runtime.noise()` (Perlin)
58
+
59
+ ❌ **Forbidden (blocked in strict mode):**
60
+ - `Math.random()` — use `runtime.random()` instead
61
+ - `Date.now()` — pass time as input or use frame counters
62
+ - `performance.now()` — use deterministic timing
63
+ - External IO during deterministic runs (not supported)
64
+
65
+ ---
66
+
67
+ ## Why Not Just Use a PRNG?
68
+
69
+ | Feature | Plain PRNG | NexArt Runtime |
70
+ |---------|-----------|----------------|
71
+ | Seeded random | ✅ | ✅ |
72
+ | Seeded noise | ❌ (separate lib) | ✅ built-in |
73
+ | Strict mode (blocks entropy) | ❌ | ✅ |
74
+ | Canonical state snapshot | ❌ | ✅ `getState()` |
75
+ | Cross-env stable digest | ❌ | ✅ `digest()` |
76
+ | VAR protocol (0-100 inputs) | ❌ | ✅ |
77
+ | Replay/verification | Manual | Built-in |
78
+ | Error messages for agents | ❌ | ✅ actionable |
79
+
80
+ **The runtime provides a complete determinism layer, not just random numbers.**
81
+
82
+ ---
83
+
84
+ ## Environment Imports
85
+
86
+ | Environment | Import Path |
87
+ |-------------|-------------|
88
+ | Browser / Vite / Next.js / React | `import { createRuntime } from "@nexart/codemode-sdk"` |
89
+ | Node.js (general use) | `import { createRuntime } from "@nexart/codemode-sdk"` |
90
+ | Node.js server rendering (canvas) | `import { executeCodeMode } from "@nexart/codemode-sdk/node"` |
91
+
92
+ **The default import is always browser-safe.** Node-only features (`executeCodeMode`, `runStaticMode`) require explicit `/node` import.
93
+
94
+ ---
95
+
96
+ ## License
97
+
98
+ **Free for:**
99
+ - Experiments and prototypes
100
+ - Personal projects
101
+ - Open-source projects
102
+
103
+ **Commercial production deployments require a license.** See [LICENSING.md](./LICENSING.md) for details.
26
104
 
27
105
  ---
28
106
 
@@ -62,6 +140,80 @@ The answer is: "Whatever @nexart/codemode-sdk does — that is the protocol."
62
140
 
63
141
  ---
64
142
 
143
+ ## What's New in v1.8.0
144
+
145
+ **Agent-First Runtime Authority Layer**
146
+
147
+ This release introduces `createRuntime()` — an agent-first API designed for AI coding assistants to reliably execute deterministic code.
148
+
149
+ ### New Runtime API
150
+ ```typescript
151
+ import { createRuntime } from "@nexart/codemode-sdk";
152
+
153
+ const runtime = createRuntime({
154
+ seed: "my-seed",
155
+ vars: [50, 75],
156
+ strict: true,
157
+ mode: "static",
158
+ metadata: { artist: "demo" }
159
+ });
160
+
161
+ runtime.random(); // Deterministic PRNG
162
+ runtime.randomInt(0, 100); // Deterministic integer
163
+ runtime.noise(x, y, z); // Deterministic Perlin noise
164
+ runtime.digest(); // Stable hash for verification
165
+ runtime.getState(); // Canonical state snapshot
166
+ runtime.run(() => { ... }); // Execute with strict enforcement
167
+ ```
168
+
169
+ ### Strict Mode
170
+ - Throws actionable errors on `Math.random`, `Date.now`, `performance.now`
171
+ - Only applies during `runtime.run()` — non-invasive
172
+ - Error messages guide agents to correct usage
173
+
174
+ ### Agent-First Documentation
175
+ - "For AI Coding Agents" section at top of README
176
+ - Determinism Contract with ✅/❌ checklist
177
+ - PRNG comparison table
178
+ - Environment import matrix
179
+
180
+ ### Examples
181
+ - `npm run example:basic` — Basic usage demonstration
182
+ - `npm run example:verify` — Determinism verification tests
183
+
184
+ ### No Breaking Changes
185
+ - All existing APIs work unchanged
186
+ - Default import remains browser-safe
187
+ - Protocol version unchanged (v1.2.0)
188
+
189
+ ---
190
+
191
+ ## What's New in v1.7.0
192
+
193
+ **Browser-Safe Entrypoint + Conditional Exports**
194
+
195
+ This release makes the SDK reliably usable in browser environments (Vite/React) without any Node.js dependency leakage.
196
+
197
+ ### New Entry Points
198
+ - `@nexart/codemode-sdk/browser` — Browser-safe modules only (no Node.js dependencies)
199
+ - `@nexart/codemode-sdk/node` — Full SDK including static-engine (requires `canvas` package)
200
+
201
+ ### Package.json Conditional Exports
202
+ - Default import (`.`) now uses conditional exports: browser gets browser entry, Node gets Node entry
203
+ - Explicit subpaths: `./browser` and `./node` for direct control
204
+
205
+ ### Why This Matters
206
+ - AI agents and bundlers will no longer accidentally import Node.js modules in browser builds
207
+ - Vite/React apps can safely import the SDK without "createRequire is not defined" errors
208
+ - Server-side code gets full functionality including static image rendering
209
+
210
+ ### No Breaking Changes
211
+ - Protocol behavior and determinism unchanged
212
+ - API surface unchanged
213
+ - Existing Node.js code continues to work
214
+
215
+ ---
216
+
65
217
  ## What's New in v1.6.0
66
218
 
67
219
  **Licensing & Builder Identity Scaffolding (Metadata Only)**
@@ -214,6 +366,61 @@ cp -r sdk/codemode your-project/lib/codemode
214
366
 
215
367
  ---
216
368
 
369
+ ## Browser Usage (v1.7.0+)
370
+
371
+ For Vite, React, Next.js, or any browser environment, import from the browser-safe entry:
372
+
373
+ ```typescript
374
+ import {
375
+ runLoopMode,
376
+ cancelLoopMode,
377
+ createP5Runtime,
378
+ validateCodeModeSource,
379
+ PROTOCOL_IDENTITY,
380
+ DEFAULT_CONFIG,
381
+ } from '@nexart/codemode-sdk/browser';
382
+ ```
383
+
384
+ **What's included in `@nexart/codemode-sdk/browser`:**
385
+ - All types (RenderMode, EngineConfig, ExecuteCodeModeInput, etc.)
386
+ - P5 runtime (createP5Runtime, injectTimeVariables, injectProtocolVariables)
387
+ - Loop engine (runLoopMode, cancelLoopMode)
388
+ - Execution sandbox (FORBIDDEN_APIS, createSafeMath)
389
+ - Validation (validateCodeModeSource)
390
+ - Builder manifest (registerBuilderManifest)
391
+
392
+ **What's NOT included (Node.js only):**
393
+ - `executeCodeMode` — Uses static-engine which requires Node.js canvas
394
+ - `runStaticMode` — Requires Node.js canvas package
395
+
396
+ For static rendering in browser apps, use your server-side API endpoint.
397
+
398
+ ---
399
+
400
+ ## Node.js Usage (v1.7.0+)
401
+
402
+ For server-side rendering, oracles, or CLI tools, import from the Node entry:
403
+
404
+ ```typescript
405
+ import {
406
+ executeCodeMode,
407
+ runStaticMode,
408
+ runLoopMode,
409
+ validateCodeModeSource,
410
+ } from '@nexart/codemode-sdk/node';
411
+ ```
412
+
413
+ **What's included in `@nexart/codemode-sdk/node`:**
414
+ - Everything from the browser entry
415
+ - `executeCodeMode` — Canonical execution API
416
+ - `runStaticMode` — Node.js static rendering (requires `canvas` package)
417
+
418
+ **Requirements:**
419
+ - Node.js 18+
420
+ - `canvas` package installed for static mode (`npm install canvas`)
421
+
422
+ ---
423
+
217
424
  ## Canonical API
218
425
 
219
426
  ### `executeCodeMode(input: ExecuteCodeModeInput): Promise<ExecuteCodeModeResult>`
@@ -602,13 +809,18 @@ Ensure your server has this endpoint available (NexArt provides this).
602
809
 
603
810
  ```
604
811
  sdk/codemode/
605
- ├── index.ts # Main export
812
+ ├── entry/
813
+ │ ├── browser.ts # Browser-safe entry point (v1.7.0)
814
+ │ └── node.ts # Node.js entry point (v1.7.0)
815
+ ├── index.ts # Main export (app integration layer)
816
+ ├── core-index.ts # Core runtime exports
606
817
  ├── execute.ts # executeCodeMode canonical entry point
607
818
  ├── engine.ts # createEngine entry point (legacy)
608
819
  ├── types.ts # TypeScript types
609
- ├── static-engine.ts # Static mode implementation
610
- ├── loop-engine.ts # Loop mode implementation
820
+ ├── static-engine.ts # Static mode implementation (Node.js)
821
+ ├── loop-engine.ts # Loop mode implementation (browser)
611
822
  ├── p5-runtime.ts # p5.js-like runtime
823
+ ├── execution-sandbox.ts # Determinism enforcement
612
824
  ├── builder-manifest.ts # Builder manifest (write-only)
613
825
  ├── CHANGELOG.md # Version history
614
826
  └── README.md # This file
@@ -16,6 +16,6 @@ export { createEngine, } from './engine';
16
16
  /**
17
17
  * SDK Identity
18
18
  */
19
- export declare const SDK_VERSION = "1.1.1";
19
+ export declare const SDK_VERSION = "1.8.0";
20
20
  export declare const SDK_NAME = "@nexart/codemode-sdk";
21
21
  //# sourceMappingURL=core-index.d.ts.map
@@ -22,5 +22,5 @@ export { createEngine, } from './engine';
22
22
  /**
23
23
  * SDK Identity
24
24
  */
25
- export const SDK_VERSION = '1.1.1';
25
+ export const SDK_VERSION = '1.8.0';
26
26
  export const SDK_NAME = '@nexart/codemode-sdk';
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @nexart/codemode-sdk/browser — Browser-Safe Entry Point
3
+ *
4
+ * ╔══════════════════════════════════════════════════════════════════════════╗
5
+ * ║ BROWSER-SAFE SDK ENTRY POINT (v1.8.0) ║
6
+ * ║ ║
7
+ * ║ This entrypoint exports ONLY browser-safe modules. ║
8
+ * ║ It does NOT include static-engine or any Node.js dependencies. ║
9
+ * ║ ║
10
+ * ║ Use this for Vite, React, Next.js, or any browser environment. ║
11
+ * ║ ║
12
+ * ║ For Node.js/server: import from '@nexart/codemode-sdk/node' ║
13
+ * ║ ║
14
+ * ║ AI AGENTS: Start with createRuntime({ seed, strict: true }) ║
15
+ * ╚══════════════════════════════════════════════════════════════════════════╝
16
+ */
17
+ export type { RenderMode, RuntimeCanvas, EngineConfig, RenderResult, RunOptions, ProgressInfo, Engine, TimeVariables, ProtocolVariables, ProtocolMetadata, ExecuteCodeModeInput, ExecuteCodeModeResult, NexArtBuilderManifest, } from '../types';
18
+ export { PROTOCOL_IDENTITY, DEFAULT_VARS, DEFAULT_CONFIG, } from '../types';
19
+ export { FORBIDDEN_APIS, FORBIDDEN_API_NAMES, createSafeMath, buildSandboxContext, createSandboxedExecutor, executeSandboxed, } from '../execution-sandbox';
20
+ export { createP5Runtime, injectTimeVariables, injectProtocolVariables, createProtocolVAR, VAR_COUNT, VAR_MIN, VAR_MAX, CODE_MODE_PROTOCOL_VERSION, CODE_MODE_PROTOCOL_PHASE, CODE_MODE_ENFORCEMENT, } from '../p5-runtime';
21
+ export type { P5Runtime, P5RuntimeConfig, } from '../p5-runtime';
22
+ export { runLoopMode, cancelLoopMode, } from '../loop-engine';
23
+ export { validateCodeModeSource, } from '../execute';
24
+ export { createEngine, } from '../engine';
25
+ export { registerBuilderManifest, } from '../builder-manifest';
26
+ export { createRuntime, NexArtRuntime, RUNTIME_VERSION, } from '../runtime';
27
+ export type { RuntimeOptions, RuntimeState, NexArtRuntime as NexArtRuntimeType, } from '../runtime';
28
+ export declare const SDK_VERSION = "1.8.0";
29
+ export declare const SDK_NAME = "@nexart/codemode-sdk";
30
+ export declare const SDK_ENTRY = "browser";
31
+ /**
32
+ * Note: executeCodeMode is NOT exported from browser entry.
33
+ *
34
+ * In browser environments, static mode requires the canvas package which
35
+ * has Node.js dependencies. For browser apps:
36
+ *
37
+ * - Use runLoopMode() directly for animations
38
+ * - For static rendering, use the server-side endpoint
39
+ * - Or import from '@nexart/codemode-sdk/node' in SSR contexts
40
+ *
41
+ * AI AGENTS: Use createRuntime({ seed, strict: true }) for deterministic execution.
42
+ */
43
+ //# sourceMappingURL=browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../entry/browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH,YAAY,EACV,UAAU,EACV,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,MAAM,EACN,aAAa,EACb,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,cAAc,GACf,MAAM,UAAU,CAAC;AAKlB,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,cAAc,EACd,mBAAmB,EACnB,uBAAuB,EACvB,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAK9B,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,uBAAuB,EACvB,iBAAiB,EACjB,SAAS,EACT,OAAO,EACP,OAAO,EACP,0BAA0B,EAC1B,wBAAwB,EACxB,qBAAqB,GACtB,MAAM,eAAe,CAAC;AAEvB,YAAY,EACV,SAAS,EACT,eAAe,GAChB,MAAM,eAAe,CAAC;AAKvB,OAAO,EACL,WAAW,EACX,cAAc,GACf,MAAM,gBAAgB,CAAC;AAKxB,OAAO,EACL,sBAAsB,GACvB,MAAM,YAAY,CAAC;AAKpB,OAAO,EACL,YAAY,GACb,MAAM,WAAW,CAAC;AAKnB,OAAO,EACL,uBAAuB,GACxB,MAAM,qBAAqB,CAAC;AAK7B,OAAO,EACL,aAAa,EACb,aAAa,EACb,eAAe,GAChB,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,cAAc,EACd,YAAY,EACZ,aAAa,IAAI,iBAAiB,GACnC,MAAM,YAAY,CAAC;AAKpB,eAAO,MAAM,WAAW,UAAU,CAAC;AACnC,eAAO,MAAM,QAAQ,yBAAyB,CAAC;AAC/C,eAAO,MAAM,SAAS,YAAY,CAAC;AAEnC;;;;;;;;;;;GAWG"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * @nexart/codemode-sdk/browser — Browser-Safe Entry Point
3
+ *
4
+ * ╔══════════════════════════════════════════════════════════════════════════╗
5
+ * ║ BROWSER-SAFE SDK ENTRY POINT (v1.8.0) ║
6
+ * ║ ║
7
+ * ║ This entrypoint exports ONLY browser-safe modules. ║
8
+ * ║ It does NOT include static-engine or any Node.js dependencies. ║
9
+ * ║ ║
10
+ * ║ Use this for Vite, React, Next.js, or any browser environment. ║
11
+ * ║ ║
12
+ * ║ For Node.js/server: import from '@nexart/codemode-sdk/node' ║
13
+ * ║ ║
14
+ * ║ AI AGENTS: Start with createRuntime({ seed, strict: true }) ║
15
+ * ╚══════════════════════════════════════════════════════════════════════════╝
16
+ */
17
+ export { PROTOCOL_IDENTITY, DEFAULT_VARS, DEFAULT_CONFIG, } from '../types';
18
+ // ═══════════════════════════════════════════════════════════════════════════
19
+ // EXECUTION SANDBOX — Browser-safe (no Node dependencies)
20
+ // ═══════════════════════════════════════════════════════════════════════════
21
+ export { FORBIDDEN_APIS, FORBIDDEN_API_NAMES, createSafeMath, buildSandboxContext, createSandboxedExecutor, executeSandboxed, } from '../execution-sandbox';
22
+ // ═══════════════════════════════════════════════════════════════════════════
23
+ // P5 RUNTIME — Browser-safe (DOM-based canvas)
24
+ // ═══════════════════════════════════════════════════════════════════════════
25
+ export { createP5Runtime, injectTimeVariables, injectProtocolVariables, createProtocolVAR, VAR_COUNT, VAR_MIN, VAR_MAX, CODE_MODE_PROTOCOL_VERSION, CODE_MODE_PROTOCOL_PHASE, CODE_MODE_ENFORCEMENT, } from '../p5-runtime';
26
+ // ═══════════════════════════════════════════════════════════════════════════
27
+ // LOOP ENGINE — Browser-safe (uses document.createElement, fetch)
28
+ // ═══════════════════════════════════════════════════════════════════════════
29
+ export { runLoopMode, cancelLoopMode, } from '../loop-engine';
30
+ // ═══════════════════════════════════════════════════════════════════════════
31
+ // VALIDATION — Browser-safe (pure logic)
32
+ // ═══════════════════════════════════════════════════════════════════════════
33
+ export { validateCodeModeSource, } from '../execute';
34
+ // ═══════════════════════════════════════════════════════════════════════════
35
+ // ENGINE FACTORY — Browser-safe wrapper
36
+ // ═══════════════════════════════════════════════════════════════════════════
37
+ export { createEngine, } from '../engine';
38
+ // ═══════════════════════════════════════════════════════════════════════════
39
+ // BUILDER MANIFEST — Browser-safe (data-only, no side effects)
40
+ // ═══════════════════════════════════════════════════════════════════════════
41
+ export { registerBuilderManifest, } from '../builder-manifest';
42
+ // ═══════════════════════════════════════════════════════════════════════════
43
+ // AGENT-FIRST RUNTIME — v1.8.0 (Browser-safe, no Node dependencies)
44
+ // ═══════════════════════════════════════════════════════════════════════════
45
+ export { createRuntime, NexArtRuntime, RUNTIME_VERSION, } from '../runtime';
46
+ // ═══════════════════════════════════════════════════════════════════════════
47
+ // SDK IDENTITY
48
+ // ═══════════════════════════════════════════════════════════════════════════
49
+ export const SDK_VERSION = '1.8.0';
50
+ export const SDK_NAME = '@nexart/codemode-sdk';
51
+ export const SDK_ENTRY = 'browser';
52
+ /**
53
+ * Note: executeCodeMode is NOT exported from browser entry.
54
+ *
55
+ * In browser environments, static mode requires the canvas package which
56
+ * has Node.js dependencies. For browser apps:
57
+ *
58
+ * - Use runLoopMode() directly for animations
59
+ * - For static rendering, use the server-side endpoint
60
+ * - Or import from '@nexart/codemode-sdk/node' in SSR contexts
61
+ *
62
+ * AI AGENTS: Use createRuntime({ seed, strict: true }) for deterministic execution.
63
+ */
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @nexart/codemode-sdk/node — Node.js Entry Point
3
+ *
4
+ * ╔══════════════════════════════════════════════════════════════════════════╗
5
+ * ║ NODE.JS SDK ENTRY POINT (v1.8.0) ║
6
+ * ║ ║
7
+ * ║ This entrypoint exports Node.js-specific modules that require: ║
8
+ * ║ - canvas package (node-canvas) ║
9
+ * ║ - Node.js built-ins (module, fs, path) ║
10
+ * ║ ║
11
+ * ║ Use this for server-side rendering, oracles, or CLI tools. ║
12
+ * ║ ║
13
+ * ║ For browser/Vite: import from '@nexart/codemode-sdk/browser' ║
14
+ * ║ ║
15
+ * ║ AI AGENTS: Start with createRuntime({ seed, strict: true }) ║
16
+ * ╚══════════════════════════════════════════════════════════════════════════╝
17
+ */
18
+ export * from './browser';
19
+ export { runStaticMode, } from '../static-engine';
20
+ export { executeCodeMode, } from '../execute';
21
+ export { SDK_VERSION, SDK_NAME } from './browser';
22
+ export declare const SDK_ENTRY = "node";
23
+ //# sourceMappingURL=node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../entry/node.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAKH,cAAc,WAAW,CAAC;AAK1B,OAAO,EACL,aAAa,GACd,MAAM,kBAAkB,CAAC;AAK1B,OAAO,EACL,eAAe,GAChB,MAAM,YAAY,CAAC;AAKpB,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAClD,eAAO,MAAM,SAAS,SAAS,CAAC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @nexart/codemode-sdk/node — Node.js Entry Point
3
+ *
4
+ * ╔══════════════════════════════════════════════════════════════════════════╗
5
+ * ║ NODE.JS SDK ENTRY POINT (v1.8.0) ║
6
+ * ║ ║
7
+ * ║ This entrypoint exports Node.js-specific modules that require: ║
8
+ * ║ - canvas package (node-canvas) ║
9
+ * ║ - Node.js built-ins (module, fs, path) ║
10
+ * ║ ║
11
+ * ║ Use this for server-side rendering, oracles, or CLI tools. ║
12
+ * ║ ║
13
+ * ║ For browser/Vite: import from '@nexart/codemode-sdk/browser' ║
14
+ * ║ ║
15
+ * ║ AI AGENTS: Start with createRuntime({ seed, strict: true }) ║
16
+ * ╚══════════════════════════════════════════════════════════════════════════╝
17
+ */
18
+ // ═══════════════════════════════════════════════════════════════════════════
19
+ // RE-EXPORT ALL BROWSER-SAFE MODULES
20
+ // ═══════════════════════════════════════════════════════════════════════════
21
+ export * from './browser';
22
+ // ═══════════════════════════════════════════════════════════════════════════
23
+ // STATIC ENGINE — Node.js only (requires canvas package)
24
+ // ═══════════════════════════════════════════════════════════════════════════
25
+ export { runStaticMode, } from '../static-engine';
26
+ // ═══════════════════════════════════════════════════════════════════════════
27
+ // CANONICAL EXECUTION — Node.js only (imports static-engine)
28
+ // ═══════════════════════════════════════════════════════════════════════════
29
+ export { executeCodeMode, } from '../execute';
30
+ // ═══════════════════════════════════════════════════════════════════════════
31
+ // SDK IDENTITY (override browser entry)
32
+ // ═══════════════════════════════════════════════════════════════════════════
33
+ export { SDK_VERSION, SDK_NAME } from './browser';
34
+ export const SDK_ENTRY = 'node';
package/dist/index.d.ts CHANGED
@@ -1,50 +1,31 @@
1
1
  /**
2
- * NexArt Code Mode Runtime SDK
3
- * Version: 1.1.0 (Protocol v1.0.0)
2
+ * NexArt Code Mode Runtime SDK - App Integration Layer
4
3
  *
5
4
  * ╔══════════════════════════════════════════════════════════════════════════╗
6
- * ║ @nexart/codemode-sdk Canonical Code Mode Authority
5
+ * ║ LOCAL SDK WRAPPER
7
6
  * ║ ║
8
- * ║ This SDK defines the official Code Mode execution surface.
9
- * ║ All implementations (NexArt, ByX, external) MUST use this SDK.
7
+ * ║ This file re-exports the core runtime from @nexart/codemode-sdk (npm)
8
+ * ║ and adds app-specific integrations (SoundArt, Noise, etc.)
10
9
  * ║ ║
11
- * ║ Protocol: nexart
12
- * ║ Engine: codemode
13
- * ║ SDK Version: 1.1.0 ║
14
- * ║ Protocol Version: 1.0.0 ║
15
- * ║ Phase: 1 ║
16
- * ║ Enforcement: HARD ║
10
+ * ║ For core Code Mode: import from '@nexart/codemode-sdk'
11
+ * ║ For app integrations: import from 'sdk/codemode'
17
12
  * ╚══════════════════════════════════════════════════════════════════════════╝
18
- *
19
- * @example
20
- * ```typescript
21
- * import { executeCodeMode } from '@nexart/codemode-sdk';
22
- *
23
- * const result = await executeCodeMode({
24
- * source: `function setup() { background(255); ellipse(width/2, height/2, 100); }`,
25
- * width: 1950,
26
- * height: 2400,
27
- * seed: 12345,
28
- * vars: [50, 0, 0, 0, 0, 0, 0, 0, 0, 0],
29
- * mode: 'static'
30
- * });
31
- *
32
- * console.log(result.metadata.protocolVersion); // '1.0.0'
33
- * ```
34
13
  */
35
- export { executeCodeMode, validateCodeModeSource } from './execute';
36
- export type { ExecuteCodeModeInput, ExecuteCodeModeResult, ProtocolMetadata, } from './types';
37
- export { PROTOCOL_IDENTITY } from './types';
14
+ export { executeCodeMode, validateCodeModeSource, DEFAULT_CONFIG, PROTOCOL_IDENTITY, } from '@nexart/codemode-sdk';
15
+ export type { ExecuteCodeModeInput, ExecuteCodeModeResult, ProtocolMetadata, RenderResult, TimeVariables, } from '@nexart/codemode-sdk';
16
+ export { createP5Runtime, injectTimeVariables, injectProtocolVariables, createProtocolVAR } from './p5-runtime';
17
+ export type { P5Runtime, P5RuntimeConfig } from './p5-runtime';
38
18
  export { createEngine } from './engine';
39
- export type { Engine, EngineConfig, RunOptions, RenderResult, ProgressInfo, RenderMode, TimeVariables, } from './types';
40
- export { DEFAULT_CONFIG } from './types';
19
+ export type { Engine, EngineConfig, RunOptions, ProgressInfo, RenderMode, } from './types';
20
+ export { DEFAULT_CONFIG as LOCAL_DEFAULT_CONFIG } from './types';
41
21
  export { renderSoundArtViaCodeMode, canRenderViaCodeMode, getCodeModeAvailableStyles, type SoundArtEngineConfig, type SoundArtRenderOptions, type SoundArtRenderResult, type SoundArtMetadata, } from './soundart-engine';
42
22
  export { type SoundSnapshot, type SoundFeatures, createSoundSnapshot, createEmptySoundSnapshot, freezeSoundSnapshot, } from '../../shared/soundSnapshot';
43
23
  export { injectSoundGlobals, createSoundGlobals, createEmptySoundGlobals, generateSoundPalette, inferGenreProfile, createSoundHelpers, type SoundGlobals, type GenreProfile, } from './sound-bridge';
44
24
  export { getSoundArtSketch, getAvailableSoundArtSketches, isSoundArtSketchAvailable, type SoundArtSketchName, } from './soundart-sketches';
45
- export { createP5Runtime, type P5Runtime, type P5RuntimeConfig } from './p5-runtime';
46
25
  export { renderNoiseViaCodeMode, compileNoiseSystem, canRenderNoiseViaCodeMode, type NoiseEngineConfig, type NoiseRenderOptions, type NoiseRenderResult, type NoiseMetadata, } from './noise-engine';
47
26
  export { type NoiseSnapshot, type NoiseParams, type NoiseBlendMode, createNoiseSnapshot, validateNoiseSnapshot, } from '../../shared/noiseSnapshot';
48
27
  export { createNoiseGlobals, injectNoiseGlobals, type NoiseGlobals, } from './noise-bridge';
49
28
  export { getNoiseSketch, getAvailableNoiseSketchNames, isValidNoiseSketch, type NoiseSketchName, } from './noise-sketches';
29
+ export { registerBuilderManifest } from './builder-manifest';
30
+ export type { NexArtBuilderManifest } from './types';
50
31
  //# sourceMappingURL=index.d.ts.map