Art and animation, written as code. Illustrations, loops, interactive web art, launch-videos and scored films in dozens of styles, identical on every render.
TypeScript agent-skillsanimationcanvasclaude-codeclaude-pluginclaude-skillscodex-plugincreative-codecreative-codingcreative-toolsdeterministicgenerative-arthand-drawnillustrationlaunch-videomotion-designmotion-graphicspluginprocedural-generationskill
chore: resync Codex mirror
Alex Greenshpun1087b754c95e
diff --git a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/launchTemplate.ts b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/launchTemplate.tsindex 04f2bad..8a32921 100644--- a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/launchTemplate.ts+++ b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/launchTemplate.ts@@ -31,6 +31,8 @@ import * as launchPieces from "./music/pieces/launch";import * as nocturnePieces from "./music/pieces/nocturne";import * as samplers from "./music/pieces/samplers";import type { Piece } from "./music/plan";+import { composePiece, type Material } from "./music/compose";+import { novelty } from "./music/novelty";export type LaunchAsk = {prompt: string; // what the user types, in their words@@ -56,17 +58,25 @@ export type LaunchSpec = {// The score: a piece COMPOSED for this product's brief (references/music/compose.md), or null for// a silent film. Required, so no film inherits a score by default. anidoodle's own pieces are// refused: every user's film gets its own music, never ours.- score: (() => Piece) | null;+ // A Material (what compose.md writes) is composed here; a finished Piece is used as is.+ score: (() => Piece | Material) | null;audio?: Film["audio"]; // or your own finished mix; wins over score};const W = 1920, H = 1080;// anidoodle's own pieces (the demos and our launch score) are examples of the composer, never a-// user's soundtrack. Refused by identity and by title, so a thin wrapper does not slip through.+// user's soundtrack. Refused by identity, by title and by content (the novelty gate), so a thin or+// retitled wrapper does not slip through. `audio` is the caller's own finished mix and is not checked.const OURS: (() => Piece)[] = [...Object.values(families), ...Object.values(launchPieces), ...Object.values(nocturnePieces), ...Object.values(samplers)].filter((v): v is () => Piece => typeof v === "function");-const refuseOurs = (score: () => Piece) => {+const asPiece = (score: () => Piece | Material) => (): Piece => { const x = score(); return "plan" in x ? x : composePiece(x); };+const refuseOurs = (score: () => Piece | Material) => {const ours = () => new Set(OURS.map((f) => { try { return f().title; } catch { return null; } }).filter(Boolean));- if (OURS.includes(score) || ours().has(score().title)) throw new Error(`launchTemplate: "${score().title}" is one of anidoodle's own pieces; compose a score for this product's brief (references/music/compose.md) or pass score: null`);+ if ((OURS as unknown[]).includes(score) || ours().has(score().title)) throw new Error(`launchTemplate: "${score().title}" is one of anidoodle's own pieces; compose a score for this product's brief (references/music/compose.md) or pass score: null`);+ // by content too: a retitled copy, a transposition or a quoted line of ours fails the same novelty gate `music.mjs check` runs+ const corpus: Record<string, () => Piece> = {};+ OURS.forEach((f, i) => { try { const p = asPiece(f)(); corpus[`${p.title} #${i}`] = () => p; } catch { /* not a piece */ } });+ const v = novelty(asPiece(score)(), corpus);+ if (!v.pass) throw new Error(`launchTemplate: "${score().title}" is too close to anidoodle's own "${v.worst.name.replace(/ #\d+$/, "")}" (similarity ${v.worst.score}, ${v.worst.reusedFragments} reused 6-note fragments); compose a score for this product's brief (references/music/compose.md) or pass score: null`);};const TYPE_O = { lead: -4, stagger: 18 }; // the word starts as the bloom closes over the frame; lines run on without a gapconst TOP = 170, VIEW_BOTTOM = INPUT.y - 26, BUBBLE = 58, CARD = 460;@@ -201,7 +211,7 @@ export const makeLaunchFilm = (spec: LaunchSpec): Film & { cut: ReturnType<typeometa: { title: `${spec.title} · launch`, W, H, fps, bpm: spec.bpm, durationFrames: cut.N, raster: "cpu", kind: "launch", holds },assets: { images: {} },shots: [{ id: "cut", start: 0, end: cut.N, draw }],- audio: spec.audio ?? (spec.score ? musicBed(spec.score, cut.N, fps) : undefined),+ audio: spec.audio ?? (spec.score ? musicBed(asPiece(spec.score), cut.N, fps) : undefined),cut,};};diff --git a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/music/compose.ts b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/music/compose.tsindex 07b0612..aca83ca 100644--- a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/music/compose.ts+++ b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/music/compose.ts@@ -57,11 +57,12 @@ export const composePiece = (m: Material): Piece => {const V = VOCAB[m.style]; need(V, `no vocabulary for style "${m.style}" (have: ${Object.keys(VOCAB).join(", ")}).`);const vocab = V!, meter = m.meter ?? vocab.meters[0], bpb = beatsPerBar(meter);need(m.title && Number.isFinite(m.seed) && m.mood, "a piece needs its own title, seed and mood.");+ need(Number.isFinite(m.bpm) && m.bpm > 0, `no tempo: set bpm (this style plays ${vocab.tempo[0]}-${vocab.tempo[1]} bpm).`);need(m.sections?.length, "no form: write the sections (kind, bars, harmony, lines).");need(m.chords && Object.keys(m.chords).length, "no harmony: write your chords (voicing + bass line per chord).");const lay = layout(m.sections), B = lay[lay.length - 1].to;need(m.sections.some((s) => s.lead), "no melody: at least one section needs a lead line (your own motif).");- const motif = (x: string) => m.motifs?.[x] ?? x;+ const motif = (x: string) => { const v = m.motifs?.[x]; if (v !== undefined) return v; need(/[:|]/.test(x), `no motif named "${x}": add motifs["${x}"] = "<bars of notation>", or write the notes inline (NOTE:DUR ...).`); return x; };const lineOf = (spec: LineSpec) => (Array.isArray(spec) ? spec : [spec]).map(motif).join(" | ");// ---- harmony per bar (a bar may split into chords: "A B" = two halves)diff --git a/plugins/anidoodle/skills/anidoodle/engine/test/launchTemplate.test.ts b/plugins/anidoodle/skills/anidoodle/engine/test/launchTemplate.test.tsnew file mode 100644index 0000000..446e5d6--- /dev/null+++ b/plugins/anidoodle/skills/anidoodle/engine/test/launchTemplate.test.ts@@ -0,0 +1,29 @@+// LAUNCH TEMPLATE TESTS. makeLaunchFilm takes a score composed for the product: a Material (what+// compose.md writes) or a Piece. anidoodle's own pieces are refused by identity, by title and by+// content, so a retitled or transposed copy of our launch score cannot ship as a user's film.+import { makeLaunchFilm } from "../src/canvas-core/launchTemplate";+import { chiptunePlayful, daylightCopy, launchLofi3, launchLofi3Material, type Material } from "../src/canvas-core/music";+import type { Film } from "../src/canvas-core/film";++export const name = "launchTemplate";+export const run = (ok: (cond: boolean, label: string) => void) => {+ const plate: Film = { meta: { title: "plate", W: 1080, H: 1080, fps: 30, bpm: 120, durationFrames: 60 }, assets: { images: {} }, shots: [{ id: "p", start: 0, end: 60, draw: () => {} }] };+ const base = { title: "Tally", asks: [{ prompt: "draw it", plate, label: "l" }], tagline: "t", install: ["npm i tally"], bpm: 120, askBeats: 8, endBeats: 12 };+ const refused = (score: unknown, re = /anidoodle's own/) => { try { makeLaunchFilm({ ...base, score } as never); return false; } catch (e) { return re.test(String((e as Error).message)); } };+ const mine = (): Material => ({+ style: "playful", title: "Tally, counted", seed: 5, mood: "curious", bpm: 120, key: "G", mode: "mixolydian",+ chords: { G: { voicing: "[D4 G4 B4]", bass: "G2:1.5 D3:.5 G2:1 F2:1" }, F: { voicing: "[C4 F4 A4]", bass: "F2:1.5 C3:.5 F2:1 E2:1" } },+ motifs: { a: "B4:.5 D5:.5 G5:1 r:.5 F5:.25 E5:.25 D5:1", b: "r:1 A4:.5 C5:.5 F5:1 E5:.5 C5:.5" },+ grooves: { main: { family: "shuffle", density: 0.45, variation: 0.35 } },+ sections: [{ kind: "groove", bars: 4, harmony: ["G", "F"], lead: ["a", "b", "a", "b"], groove: "main", stretch: true }, { kind: "outro", bars: 1, harmony: ["G"], lead: ["a"] }],+ });+ let film: Film | null = null; try { film = makeLaunchFilm({ ...base, score: mine }); } catch (e) { ok(false, `a composed Material is accepted: ${(e as Error).message}`); }+ ok(!!film && typeof film.audio === "function", "a composed Material is accepted as the score");+ ok(refused(launchLofi3), "refuses our launch score by identity");+ ok(refused(launchLofi3Material), "refuses our launch score's material by identity");+ ok(refused(chiptunePlayful), "refuses a demo");+ ok(refused(() => ({ ...launchLofi3(), title: "Mine" })), "refuses a retitled copy of our launch score");+ ok(refused(() => ({ ...launchLofi3Material(), title: "Mine" })), "refuses retitled launch material");+ ok(refused(daylightCopy), "refuses the transposed copy of our launch score (the Daylight fixture)");+ ok(refused(undefined, /required/), "a missing score is an error, never a default");+};diff --git a/plugins/anidoodle/skills/anidoodle/engine/tools/adapters/playwright.mjs b/plugins/anidoodle/skills/anidoodle/engine/tools/adapters/playwright.mjsindex be46717..10bdcc3 100644--- a/plugins/anidoodle/skills/anidoodle/engine/tools/adapters/playwright.mjs+++ b/plugins/anidoodle/skills/anidoodle/engine/tools/adapters/playwright.mjs@@ -1,6 +1,7 @@// PLAYWRIGHT ADAPTER. Thin by design: open the generated page, ask it for frame N, take the// canvas pixels. Frame accuracy comes from the pull model (frame N is a pure function of N),// not from anything Playwright does.+import { createHash } from "node:crypto";import { pathToFileURL } from "node:url";import { bakeCacheOn, loadBakes, saveBakes } from "../bake-cache.mjs";@@ -8,7 +9,10 @@ export const name = "playwright";// bakeCache (default on): finished plate frames come from and go to .cache/bakes (see bake-cache.mjs)export const open = async ({ pw, browser: found }, pagePath, { scale = 1, workers = 1, bakeCache } = {}) => {const browser = await pw.lib.chromium.launch({ executablePath: found.executablePath, args: ["--disable-background-timer-throttling"] });- const useBakes = bakeCacheOn(bakeCache), bv = browser.version(); let loadedBakes = 0;+ // the bake folder is keyed by the browser BINARY, not just its version: Chrome for Testing and+ // chrome-headless-shell report the same version and rasterise differently, so one must never+ // replay the other's plate frames+ const useBakes = bakeCacheOn(bakeCache), bv = `${browser.version()}-${createHash("md5").update(found.executablePath ?? "playwright-default").digest("hex").slice(0, 8)}`; let loadedBakes = 0;const context = await browser.newContext({ viewport: { width: 640, height: 640 }, deviceScaleFactor: 1 });const pages = [];for (let i = 0; i < workers; i++) { const page = await context.newPage(); const errors = []; page.on("pageerror", (e) => errors.push(e.message)); await page.goto(pathToFileURL(pagePath).href + "?adapter=playwright"); await page.evaluate(async (s) => { await window.FILM.ready; window.FILM.mount(s); }, scale); if (useBakes) loadedBakes = await loadBakes(page, bv); await page.evaluate(() => window.FILM.warm()); /* warm = build texture tiles once, outside the timed frames */ if (errors.length) throw new Error("page failed: " + errors.join("; ")); pages.push(page); }diff --git a/plugins/anidoodle/skills/anidoodle/engine/tools/bake-cache.mjs b/plugins/anidoodle/skills/anidoodle/engine/tools/bake-cache.mjsindex c1fe9da..2489479 100644--- a/plugins/anidoodle/skills/anidoodle/engine/tools/bake-cache.mjs+++ b/plugins/anidoodle/skills/anidoodle/engine/tools/bake-cache.mjs@@ -1,5 +1,5 @@// BAKE CACHE, the disk half of Env.bake (the page half is hosts/page.ts). Finished plate frames-// live in .cache/bakes/<browser version>/<source hash>.<frame>.<w>x<h>.png. The source hash is+// live in .cache/bakes/<browser version>-<binary hash>/<source hash>.<frame>.<w>x<h>.png. The source hash is// computed by build-page.mjs over the plate's whole import closure, so an edited plate simply// misses and is drawn again; a different browser build (which may rasterise differently) gets a// different folder. Nothing here is ever needed: delete .cache/ and every frame is drawn cold.diff --git a/plugins/anidoodle/skills/anidoodle/engine/tools/scaffold.mjs b/plugins/anidoodle/skills/anidoodle/engine/tools/scaffold.mjsindex ee4e64f..45ab858 100644--- a/plugins/anidoodle/skills/anidoodle/engine/tools/scaffold.mjs+++ b/plugins/anidoodle/skills/anidoodle/engine/tools/scaffold.mjs@@ -150,5 +150,5 @@ const tree = (dir, depth = 0) => readdirSync(dir, { withFileTypes: true }).filteconsole.log(`scaffolded ${target}\n${tree(target)}\n`);console.log(`next:\n cd ${target}\n npm install`);if (still) console.log(` node tools/still.mjs ${still} --out out/${still}.png # the picture; --scale 2 for print size`);-if (film) console.log(` node tools/still.mjs ${film} --out out/look.png\n node tools/gate.mjs ${film}`);+if (film) console.log(` node tools/still.mjs ${film} --out out/look.png\n node tools/render.mjs ${film} # the gate measures the MP4\n node tools/gate.mjs ${film}`);if (opt.example) console.log(` node tools/gate.mjs mechanicalLepidoptera --mp4 out/mechanical-lepidoptera.mp4 # the worked example`);diff --git a/plugins/anidoodle/skills/anidoodle/references/workflows/launch-video-kit.md b/plugins/anidoodle/skills/anidoodle/references/workflows/launch-video-kit.mdindex fab2a0b..7251aa9 100644--- a/plugins/anidoodle/skills/anidoodle/references/workflows/launch-video-kit.md+++ b/plugins/anidoodle/skills/anidoodle/references/workflows/launch-video-kit.md@@ -56,7 +56,7 @@ product's world in the chosen hand, as a still plus its `*Draw` film. anidoodle'(the lighthouse and fox in `launchExample.ts`) are placeholders, never a user's film. The scoreis composed for the brief's style, mood and length (`references/music/compose.md`); `score` isrequired (`null` means silent), `bpm` has no default, and the template refuses anidoodle's own-pieces, by identity and by title.+pieces, by identity, by title and by content (the same novelty gate `music.mjs check` runs).| Spec field | Meaning ||---|---|@@ -66,7 +66,7 @@ pieces, by identity and by title.| `tagline`, `install[]`, `footer` | the end card; install lines are shown exactly as given || `bpm` (required), `fps`, `askBeats`, `typeBeats`, `endBeats` | the beat grid (a beat is 60 x fps / bpm frames) and each part's length in beats || `claimBar` | land the end card on this bar's downbeat; throws if it cannot |-| `score` (required) or `audio` | a piece composed for this product, as a bed; `null` for silence; or your own finished mix |+| `score` (required) or `audio` | the score composed for this product (the `Material` function compose.md writes, or a `Piece`), as a bed; `null` for silence; or your own finished mix (not checked) |The template refuses a feature list (more than 3 asks) and an end card too short to read.diff --git a/plugins/anidoodle/skills/anidoodle/references/workflows/start-here.md b/plugins/anidoodle/skills/anidoodle/references/workflows/start-here.mdindex cf0e5bd..060618a 100644--- a/plugins/anidoodle/skills/anidoodle/references/workflows/start-here.md+++ b/plugins/anidoodle/skills/anidoodle/references/workflows/start-here.md@@ -14,7 +14,7 @@ pick", pick, say what you picked and why in one line, and carry on.explainer, an infographic, a launch or product video, an interactive web piece, a drawinglesson, a character, or a style matched from their image. The table in `SKILL.md` routes eachone to its workflow file.-2. **Which style?** Show the gallery (`assets/gallery/styles.jpg`, one tile per hand; the list with+2. **Which style?** Show the gallery (`assets/styles.jpg`, one tile per hand; the list witheach hand's medium is `references/styles/INDEX.md`). Recommend two or three hands that suit thesubject and the audience, with one reason each. Offer two other routes:- **"Match my image"**: they bring a picture and you adapt its hand (`adapt-a-style.md`).diff --git a/plugins/anidoodle/skills/anidoodle/references/working-method.md b/plugins/anidoodle/skills/anidoodle/references/working-method.mdindex 9ab1010..2990a04 100644--- a/plugins/anidoodle/skills/anidoodle/references/working-method.md+++ b/plugins/anidoodle/skills/anidoodle/references/working-method.md@@ -67,7 +67,7 @@ None of that was drawing. These habits cut it by an order of magnitude:in one page (one build, one launch, plates baked once); ranges work too, `--frames 0-300:50`is every 50th frame from 0 to 300. Add `--sheet out/sheet.jpg` for a contact sheet of them at`--sheet-scale` (default 0.4). `--out out/dir/` or `--out out/x-{frame}.png` names the PNGs.-- **Plate cache.** Finished plate frames are kept in `engine/.cache/bakes/<browser version>/`,+- **Plate cache.** Finished plate frames are kept in `engine/.cache/bakes/<browser version>-<binary>/`,keyed by a hash of the plate's whole import closure, so a wall of 31 live plates stopsre-baking (about 60 s) on every still, and an edited plate simply misses and is drawn again.It is never needed: delete `.cache/` any time. `--no-bake-cache` (or `ANIDOODLE_BAKE_CACHE=0`)