update_algorithm
Replaces a sketch's algorithm source code, optionally resolving new component dependencies, so you can revise generative art logic and then preview the result.
Instructions
Replace the algorithm source code of a sketch. If adding/changing components, pass them in the components field alongside the algorithm. After updating, use preview_sketch to open an interactive preview in the browser.
Algorithm data bridge: Algorithms can publish data for design layers by setting window.__genart_data properties:
Stroke paths: Set window.__genart_data.strokePaths = [{points:[{x,y},...], depth, width, pressure:[...], group}, ...]
Multiple channels: Publish separate arrays (e.g. strokePaths for all paths, leafPaths for depth-filtered subset)
Grid data: Set window.__genart_data.flowField/valueMap/mask as Float32Arrays for spatial algorithms Painting layers bind to these channels via pathSource: 'algorithm:'. Declare channels in the sketch's dataChannels field via update_sketch.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| agent | No | Your CLI agent name (e.g. 'claude-code', 'codex-cli', 'gemini-cli', 'opencode', 'kiro') | |
| model | No | Your AI model identifier (e.g. 'claude-opus-4-6', 'gpt-4o', 'gemini-2.5-pro') | |
| sketchId | Yes | ID of the sketch to update | |
| validate | No | Run renderer-specific validation before saving (default: true) | |
| algorithm | Yes | New algorithm source code. State API by renderer: p5: `function sketch(p, state) { ... }` — state.canvas.width/height, state.seed, state.params.key, state.colorPalette[index]. Prefix all p5 calls with `p.` canvas2d: `function sketch(ctx, state) { ... }` — same state API as p5. three: `function sketch(THREE, state, container) { ... }` svg: `function sketch(state) { ... }` — return SVG string. glsl: uniforms auto-injected (u_resolution, u_seed, u_param_<key>, u_color_<index>), no state object. genart: GenArt Script source — globals: w, h, t, frame, fps, rnd(n), noise(x,y), vec(x,y), PI, lerp, clamp, map, dist, mouseX/Y, pmouseX/Y, mouseDown, touchX/Y, touches, prev (previous frame ImageData); drawing: circle/rect/line/arc/dot/poly/path x y ...; color: #hex, named, white.50, linear(#a,#b angle:90), radial(#a,#b); params: `param count 100 range:10..500`; colors: `color bg #000`; layers: `layer "terrain:sky" "noon" opacity:0.8 blend:"multiply"`; animation: `frame:` block; once: async (await loadFont ok); post: vignette/grain/blur/bloom/grade/scanlines/pixelate/chromatic_aberration/distort/dither/halftone — effects accept optional quality:"auto"|"high"|"fast" last arg. No state object — params/colors are globals. Data bridge: set window.__genart_data = { strokePaths: [{points:[{x,y},...], depth, width}, ...] }. Use `mulberry32(state.seed)` from "prng" component for p5/canvas2d/three/svg — NEVER `Math.random()`. For genart renderer use built-in rnd() which is seeded automatically. | |
| components | No | Component dependencies to resolve alongside the algorithm update. Use list_components to see available. |