From 49600db3e65cb6d3cb1f4d2176175a8fc9d0e3f2 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 11:01:43 +0000 Subject: [PATCH 1/2] Faster draft runs: quick check, runner parts, Behind layer, gate questions Learnt on a 540-frame caster to target effect that took about 15 minutes. - dr: `quick` command (sheet checks and light measure only, 2 s vs 36 s on a 540-frame draft); `Spec.parts` with `dr::Part` and `Effect::part` write and check cast, travel and impact sheets; `Layer::Behind` ships in the sheet and draws under the caster in previews; parts in `Spec.extra` join the aura parts. - gate: without Jev, list each knob's stated and applies questions. - Docs: SKILL.md, API.md, DRAFTS.md, export.md, caster.md, CLAUDE.md, CHANGELOG. - Tests: new snapshot case `halo` (Behind + Effect equals the single-layer sheet); earlier snapshots unchanged. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_014BGZyg2BhjJ2sSkPNmY5F9 --- CHANGELOG.md | 16 +++ CLAUDE.md | 2 +- plugins/beanfx/skills/beanfx/SKILL.md | 19 +++- plugins/beanfx/skills/beanfx/caster.md | 4 +- plugins/beanfx/skills/beanfx/export.md | 4 +- plugins/beanfx/skills/beanfx/kit/API.md | 19 +++- plugins/beanfx/skills/beanfx/kit/DRAFTS.md | 1 + plugins/beanfx/skills/beanfx/kit/src/dr.rs | 105 ++++++++++++++++-- plugins/beanfx/skills/beanfx/kit/src/gate.rs | 20 +++- .../kit/tests/fixtures/snapshots/halo.txt | 17 +++ .../beanfx/skills/beanfx/kit/tests/gate.rs | 8 ++ .../beanfx/skills/beanfx/kit/tests/runner.rs | 22 ++++ .../skills/beanfx/kit/tests/snapshot.rs | 82 ++++++++++++++ 13 files changed, 291 insertions(+), 28 deletions(-) create mode 100644 plugins/beanfx/skills/beanfx/kit/tests/fixtures/snapshots/halo.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index 02a16b1..b315b5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,22 @@ Versions follow `plugins/beanfx/.claude-plugin/plugin.json`. A release is a tag `v` on `main`; see `CONTRIBUTING.md`. +## Unreleased + +Shorter runs for long, caster to target effects (learnt on a 540-frame nine-sun cast that took about 15 minutes). + +- `Layer::Behind`: the part of the effect behind the character (a ring at the back, a halo). The sheet is `Behind` + then `Effect` on one canvas, the same bytes as drawing both in `Effect`; the previews draw it under the caster. +- `Spec.parts` (`dr::Part`) and `Effect::part`: the runner writes, checks and lists cast, travel and impact sheets + beside the aura parts. The default `part` crops the sheet, so only a part on its own clock needs code. A + `parts` object in `Spec.extra` now joins the runner's parts instead of replacing the aura parts. +- `cargo run --release -q -- quick`: the sheet's checks and light measure only, no previews, gif, parts, page or + reseeds, for the fix loop. +- The gate without Jev lists each knob's `stated` and `applies` questions (`questions`), so the model decides from + one output and opens only the files of the knobs it asks, instead of reading all 18. +- `SKILL.md`: look at the risky frames (hits, the widest, the last) before the first full run, and use `quick` while + fixing. New snapshot case `halo`; every earlier case is unchanged. + ## 2.4.0 The phases knob: how a cast's time splits, with timing recommendations (2026-11-24). diff --git a/CLAUDE.md b/CLAUDE.md index 4576bfa..af8c3bf 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -90,7 +90,7 @@ node plugins/beanfx/skills/beanfx/tools/layers.mjs --out /src --pixe - Each brief knob is a file in the skill's `knobs/` (role, view, size, timing, phases, loop, shape, style, palette, glow, clarity, density, states, caster, combo, placement, aura, sound). The gate, `/.beanfx/bin/beanfx gate ""`, says which knobs the prompt leaves open. It asks Jev (an optional prompt classifier, run through - `python3` only when its client is installed) in one call; without it the model decides from the files. Each open + `python3` only when its client is installed) in one call; without it the gate lists each knob's two frontmatter questions and the model decides from them, opening only the files of the knobs it asks. Each open knob is one AskUserQuestion question, and no draft file is written before the brief is in the reply. - Tests: `cd S/kit && cargo test --locked` (unit and integration tests of the crate, including the gate, the export, the facing fields and the preview page check), and `node S/tests/test_runtime.mjs` (the browser diff --git a/plugins/beanfx/skills/beanfx/SKILL.md b/plugins/beanfx/skills/beanfx/SKILL.md index 7d8b848..76fcceb 100644 --- a/plugins/beanfx/skills/beanfx/SKILL.md +++ b/plugins/beanfx/skills/beanfx/SKILL.md @@ -82,8 +82,9 @@ PROMPT lists the knobs to ask, in order; `skip` the ones the prompt fixes or that do not apply. Follow it. Override one only when the owner's words plainly contradict it (the prompt gives "64x48" and `size` is in `ask`), and say so in one line. -- `"source": "model"`: the default without Jev (or with `BEANFX_GATE=model`). Read each knob file's "Fixed when" - and "Applies" and decide yourself. A knob counts as fixed only when the prompt states it or an image shows it; +- `"source": "model"`: the default without Jev (or with `BEANFX_GATE=model`). Decide from the `questions` list in + the output, each knob's `stated` and `applies` question, without opening the knob files: skip a knob whose + `applies` is no or whose `stated` is yes; open the files only of the knobs you ask. A knob counts as fixed only when the prompt states it or an image shows it; the subject's colour or name alone fixes neither palette nor shape. **Ask, one question per knob.** For each knob in `ask`, read its file and build the question from its "Ask" part: @@ -134,7 +135,8 @@ upgrades. main element, a look, then the other elements with Edit. ``` -cd drafts/ && cargo run --release -q # every output and check; exit 1 a check, 2 an error +cd drafts/ && cargo run --release -q -- quick # the sheet's checks only, seconds: use it while fixing +cargo run --release -q # every output and check; exit 1 a check, 2 an error cargo run --release -q -- look # just those frames at 3x, in a second ``` @@ -170,11 +172,18 @@ first pass, so the cover lands in its row. character (`rig`) and the target dummy go into the previews only, and the binding goes into the JSON. Read `caster.md` when the brief has a caster; time blows on the character's contact frames and take slash arcs from the rig, never from a guess. Hits, poses, the target, directions and caster to target parts are fields of the -`Spec` (`export.md`). +`Spec` (`export.md`): the cast, travel and impact sheets are `Spec.parts`, and what sits behind the character (a +ring at the back, a halo) is drawn in `Layer::Behind`, so the preview shows it behind the body. ## 3. Run, and fix only what fails -Run the draft. Each run prints its checks and the light measure and exits 1 when a check fails. +Run the draft. Each run prints its checks and the light measure and exits 1 when a check fails. A full run +renders every frame many times (previews, aura and parts, three reseeds, the gif), so its cost grows with frames: + +- Before the first full run, `look` the risky frames once (each hit and its sparks, the widest frame, the last + frame): an edge cut or an empty end shows there in a second. +- While fixing, rerun with `quick` (the sheet's checks and light measure only); go back to the full run for the + parts, the reseeds and the outputs. Run each command once per fix, never twice to filter its output. - Fix every check line (edge, empty frame, pop-off, loop seam, seed, framing, budget, act) and every error, then rerun. `kit/DRAFTS.md` says what each check means. diff --git a/plugins/beanfx/skills/beanfx/caster.md b/plugins/beanfx/skills/beanfx/caster.md index e9b3ee9..3560884 100644 --- a/plugins/beanfx/skills/beanfx/caster.md +++ b/plugins/beanfx/skills/beanfx/caster.md @@ -1,7 +1,9 @@ # Casters: the mockup caster and a game character Read only when the brief has a caster (`knobs/caster.md`). Signatures are in `kit/API.md`. On the runner, set -`Spec.caster_foot` (size the cell so the caster and the foe both fit) and draw the caster in `Layer::Caster` with `cv.caster(..)`; the raw `cs` calls below are what it +`Spec.caster_foot` (size the cell so the caster and the foe both fit) and draw the caster in `Layer::Caster` with `cv.caster(..)`; what sits behind the character (a ring of +suns at the back, a halo) goes in `Layer::Behind`, which ships in the sheet and draws under the caster in the +previews (mark the part `layer: behind`); the raw `cs` calls below are what it runs, and a draft writes them only in its own `run()`. **Mockup caster** (only when the brief says yes): `cs` (`kit/src/cs.rs`) draws a golden robed silhouette with no face, diff --git a/plugins/beanfx/skills/beanfx/export.md b/plugins/beanfx/skills/beanfx/export.md index c10983f..8e29d36 100644 --- a/plugins/beanfx/skills/beanfx/export.md +++ b/plugins/beanfx/skills/beanfx/export.md @@ -69,7 +69,9 @@ the fields with `fc` (`kit/src/fc.rs`) and pass the whole meta through `fc::chec pass the rows to `ex::write`, which lays heading k after heading k - 1 and tags each: row k faces `tau * k / n`, y down (0 east, n/4 south); the JSON tells the engine `row = round(atan2(dy, dx) / tau * n) mod n`. - **Caster to target** (a projectile that lands, a beam, a strike on a foe): the distance between them changes in - play, so never only bake it into one sheet. Export three parts in `parts`, each from `fc::part(sheet, w, h, frames, fps, pivot, looped, anchor, extra)`: `cast` + play, so never only bake it into one sheet. Export three parts in `parts` (on the runner: `Spec.parts` entries, drawn by `Effect::part`; the default + crops the sheet, so only a travel loop or an impact on its own clock overrides it; in a draft's own `run()`: + `fc::part(sheet, w, h, frames, fps, pivot, looped, anchor, extra)`): `cast` (anchor caster, one-shot, the charge and release), `travel` (anchor travel, a loop the engine moves at `speed` px/s from the caster to the target, with its own direction rows for top-down or `facing` for side) and `impact` (anchor target, one-shot, the hit and dissolve). Keep the joined preview sheet and gif too, for review. When the owner wants one fixed-range sheet, record `target` and its mirror and say the range is diff --git a/plugins/beanfx/skills/beanfx/kit/API.md b/plugins/beanfx/skills/beanfx/kit/API.md index 3ad15a6..6fe04b6 100644 --- a/plugins/beanfx/skills/beanfx/kit/API.md +++ b/plugins/beanfx/skills/beanfx/kit/API.md @@ -39,24 +39,33 @@ Read these before opening the kit source. `P = [f64; 2]` world px (y down), `Rgb ### dr -- `dr::main(fx: &(dyn Effect + Sync), env!("CARGO_MANIFEST_DIR")) -> ExitCode`. Args: none (full run), `look [frames]` +- `dr::main(fx: &(dyn Effect + Sync), env!("CARGO_MANIFEST_DIR")) -> ExitCode`. Args: none (full run), `quick` (the sheet's + own checks and light measure only: no previews, gif, parts, page or reseeds; seconds on a long sheet), `look [frames]` (out/look.png at 3x on dark, look_1x.png), `glow` (out/glow_takes.png at gains 0.6, 1.0, 1.3), `bench ` (out/bench.png against out/ref from tools/layers.mjs). -- `trait Effect { fn spec(&self) -> Spec; fn draw(&self, cv: &mut Canvas, f: usize, seed: u64, layer: Layer) -> Result<(), String>; }`. +- `trait Effect { fn spec(&self) -> Spec; fn draw(&self, cv: &mut Canvas, f: usize, seed: u64, layer: Layer) -> Result<(), String>; + fn part(&self, cv: &mut Canvas, key: &str, f: usize, seed: u64) -> Result<(), String> { /* Behind, then Effect */ } }`. + `part` draws frame f of a `Spec.parts` entry on a canvas placed at its origin (world px); the default crops the + sheet's layers, so override it only for a part with its own clock (a travel loop, an impact from contact). `draw` is pure in (f, seed, layer); return `Ok(())` untouched for a layer the effect lacks. Pass kit errors on with `?` (an `Err` stops the run with exit 2), never `let _ =`, which hides a missing caster. - The runner draws frames on every core (`dr::par`), so `Fx` must be `Sync`: a plain struct is; keep a cache in a `LazyLock` or `thread_local!`, never a `RefCell` field. The output is the same at any thread count; `BEANFX_THREADS=1` runs in order on one thread (for a debugger or a print trace). -- `Layer::{Effect, Caster, AuraBack, AuraFront}`. The sheet is `Effect`. Previews stack AuraBack, Caster, AuraFront, - Effect over the dummy. Aura parts are cut round `caster_foot` with `Canvas::at`, so draw in world px. +- `Layer::{Effect, Caster, AuraBack, AuraFront, Behind}`. The sheet is `Behind` then `Effect` on one canvas. Previews + stack AuraBack, Behind, Caster, AuraFront, Effect over the dummy: draw what sits behind the character (a ring at the + back, a halo, the far side of a swirl) in `Behind`, so the preview matches the game, and mark that part's `layer` + behind. A `match` on `layer` needs a `Behind` arm or `_ => {}`. Aura parts are cut round `caster_foot` with `Canvas::at`, so draw in world px. - `Spec::new(name, w, h, n, fps)`; fields and defaults: `pivot` [w/2, h/2], `seed` 7, `looped` false, `hold` false, `view` "side", `dirs: fc::Meta` (`facing` "east" or "west" for one row), `glow` "medium", `clarity` "clear", `light_ramp: Vec` (dark to white), `steps: Option` (hard retro light, `Some(lt::Steps::default())`; also caps colours at 48 a frame, so take every colour from a ramp tone at a few fixed alphas, never a per-pixel blend), `edge_fade` 0.0 px, `hits: Vec` (`ex::hit`), `states: Vec<(String, [i64; 2])>`, `poses: Vec` (`ex::pose`), `windup` 0.0, `target: Option`, `dummy: Option

` (preview dummy foot), `caster_foot: Option

`, - `aura: Option`, `extra: Map` (more meta.beanfx), `trim: Option` (`ex::TRIM`; + `aura: Option`, `parts: Vec` (cast, travel, impact sheets: + `dr::Part::new(key, frames, w, h, origin, pivot, anchor)` with `looped` and `more` fields; the runner draws each with + `Effect::part`, writes `_`, checks it and lists it in `meta.beanfx.parts` beside the aura parts), + `extra: Map` (more meta.beanfx; a `parts` object in it joins the runner's parts), `trim: Option` (`ex::TRIM`; None when the cell keeps room on purpose, such as the caster's side of a cast), `pick`, `takes` (frame lists). - Aura parts and the sheet pass the same checks: every frame needs colour (light alone is an empty frame) and a one-shot's last frame keeps at most 5 % of the peak pixels. `hold` does not exempt an aura: it starts with colour diff --git a/plugins/beanfx/skills/beanfx/kit/DRAFTS.md b/plugins/beanfx/skills/beanfx/kit/DRAFTS.md index c102bea..39e9efa 100644 --- a/plugins/beanfx/skills/beanfx/kit/DRAFTS.md +++ b/plugins/beanfx/skills/beanfx/kit/DRAFTS.md @@ -17,6 +17,7 @@ fades in a 32x32 cell over 10 frames) that already writes the sheet and runs the ``` cd drafts/ && cargo run --release -q # writes out/, exits 1 when a check fails, 2 on an error +cargo run --release -q -- quick # the sheet's checks and light measure only, seconds on a long sheet cargo run --release -q -- look 20 30 44 # just those frames, 3x, in a second cargo run --release -q -- glow # the three glow takes round the first hit ``` diff --git a/plugins/beanfx/skills/beanfx/kit/src/dr.rs b/plugins/beanfx/skills/beanfx/kit/src/dr.rs index c6d50e4..ec5cc89 100644 --- a/plugins/beanfx/skills/beanfx/kit/src/dr.rs +++ b/plugins/beanfx/skills/beanfx/kit/src/dr.rs @@ -1,5 +1,6 @@ //! dr: the draft runner. A draft fills a `Spec`, draws layers on a `Canvas` in `Effect::draw`, and the runner -//! writes previews, sheets, JSON and page and runs the checks (commands: `look [frames]`, `glow`, `bench `). +//! writes previews, sheets, JSON and page and runs the checks (commands: `quick`, `look [frames]`, `glow`, +//! `bench `). use crate::serde_json::{json, Map, Value}; use crate::{cs, ex, fc, img, lt, np, pfx, tg}; @@ -342,14 +343,39 @@ pub struct Cel { pub light: Array2, } -/// The layer `Effect::draw` is asked for. The sheet is `Effect` alone; previews stack AuraBack, Caster, -/// AuraFront and Effect over the target dummy. +/// The layer `Effect::draw` is asked for. The sheet is `Behind` then `Effect` on one canvas; previews stack +/// AuraBack, Behind, Caster, AuraFront and Effect over the target dummy, so `Behind` is the part of the effect +/// that sits behind the character (a ring of suns at the back, a halo) and still ships in the sheet. #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Layer { Effect, Caster, AuraBack, AuraFront, + Behind, +} + +/// A part sheet of the effect beside the aura (cast, travel, impact; `export.md`): `frames` long, a w x h cell +/// whose top-left sits at `origin` in world px, the part's pivot at `pivot` in cell px. The runner draws it with +/// `Effect::part`, writes `_` and lists it in `meta.beanfx.parts.` with `anchor` and `more`. +#[derive(Clone, Debug)] +pub struct Part { + pub key: String, + pub frames: usize, + pub w: usize, + pub h: usize, + pub origin: P, + pub pivot: P, + pub looped: bool, + pub anchor: String, + pub more: Value, +} + +impl Part { + /// A one-shot part with no extra fields; set `looped` and `more` on the result. + pub fn new(key: &str, frames: usize, w: usize, h: usize, origin: P, pivot: P, anchor: &str) -> Part { + Part { key: key.into(), frames, w, h, origin, pivot, looped: false, anchor: anchor.into(), more: json!({}) } + } } /// Aura parts: own sheets round the caster's feet, `frames` long, cell w x h with the feet at pivot. @@ -412,6 +438,8 @@ pub struct Spec { /// The caster's foot in world px (aura parts are cut round it). pub caster_foot: Option

, pub aura: Option, + /// Part sheets beside the aura (cast, travel, impact), drawn by `Effect::part`. + pub parts: Vec, /// More meta.beanfx fields (caster binding, range note, sound). pub extra: Map, /// The framing check's trim limit (`ex::TRIM`); None when the empty space is wanted (caster room in the cell). @@ -433,7 +461,7 @@ impl Spec { view: "side".into(), dirs: fc::Meta::default(), glow: "medium".into(), clarity: "clear".into(), light_ramp: vec!["#40306a".into(), "#c0a0ff".into(), "#f0e8ff".into(), "#ffffff".into()], steps: None, edge_fade: 0.0, hits: vec![], states: vec![], poses: vec![], windup: 0.0, target: None, - dummy: None, caster_foot: None, aura: None, extra: Map::new(), trim: Some(ex::TRIM), pick: vec![], takes: vec![], + dummy: None, caster_foot: None, aura: None, parts: vec![], extra: Map::new(), trim: Some(ex::TRIM), pick: vec![], takes: vec![], ramp: vec![], variants: vec![], } } @@ -444,6 +472,14 @@ impl Spec { pub trait Effect { fn spec(&self) -> Spec; fn draw(&self, cv: &mut Canvas, f: usize, seed: u64, layer: Layer) -> Result<(), String>; + /// Frame f of the part `key` from `Spec.parts`, on a canvas placed at the part's origin (draw in world px). + /// The default draws the sheet's layers (Behind, then Effect) in that window, so a part that is a crop of + /// the sheet needs no code; a part with its own frame clock (a travel loop, an impact from contact) overrides it. + fn part(&self, cv: &mut Canvas, key: &str, f: usize, seed: u64) -> Result<(), String> { + let _ = key; + self.draw(cv, f, seed, Layer::Behind)?; + self.draw(cv, f, seed, Layer::Effect) + } } /// `fn main() -> ExitCode { dr::main(&Fx, env!("CARGO_MANIFEST_DIR")) }`: exit 0 clean, 1 on a failed check, 2 on @@ -477,8 +513,13 @@ impl Ctx<'_> { Ok(cv.cel()) } - fn full(&self, f: usize, seed: u64, layer: Layer) -> Result { - self.layer(Canvas::new(self.sp.w, self.sp.h), f, seed, layer) + /// The sheet's frame f: Behind, then Effect, on one canvas. + fn sheet(&self, f: usize, seed: u64) -> Result { + let mut cv = Canvas::new(self.sp.w, self.sp.h); + for layer in [Layer::Behind, Layer::Effect] { + self.fx.draw(&mut cv, f, seed, layer).map_err(|e| format!("frame {f} {layer:?}: {e}"))?; + } + Ok(cv.cel()) } /// Light after gain and edge fade (the measured light), then stepped and tinted. @@ -515,7 +556,7 @@ impl Ctx<'_> { } fn frame(&self, f: usize, seed: u64, gain: f64) -> Result { - let c = self.full(f, seed, Layer::Effect)?; + let c = self.sheet(f, seed)?; let (measured, light) = self.finish_light(&c.light, gain)?; Ok(Frame { fin: pfx::composite(&c.col, &light, None)?, col: c.col, light, measured }) } @@ -523,7 +564,7 @@ impl Ctx<'_> { fn preview(&self, f: usize, gain: f64, bg: Option<&str>) -> Result, String> { let sp = &self.sp; let mut cv = Canvas::new(sp.w, sp.h); - for layer in [Layer::AuraBack, Layer::Caster, Layer::AuraFront, Layer::Effect] { + for layer in [Layer::AuraBack, Layer::Behind, Layer::Caster, Layer::AuraFront, Layer::Effect] { self.fx.draw(&mut cv, f, sp.seed, layer).map_err(|e| format!("frame {f} {layer:?}: {e}"))?; } let c = cv.cel(); @@ -674,6 +715,28 @@ fn command(ctx: &Ctx, out: &Path, args: &[String]) -> Result { let sp = &ctx.sp; let dark = "#101018"; match args[0].as_str() { + "quick" => { + // the sheet's own checks only: no previews, gif, parts, page or reseeds; seconds instead of minutes + let frames = par(sp.n, |f| ctx.frame(f, sp.seed, 1.0))?; + let ms: Vec<(f64, f64)> = frames.iter().filter_map(|fr| measure(&fr.col, &fr.measured)).collect(); + if !ms.is_empty() { + let cover = np::median(&ms.iter().map(|m| m.0).collect::>()); + let mean = np::median(&ms.iter().map(|m| m.1).collect::>()); + println!("light: cover {:.0} %, mean {:.3} (glow {}, clarity {})", 100.0 * cover, mean, sp.glow, sp.clarity); + } + let cols: Vec> = frames.iter().map(|fr| fr.col.clone()).collect(); + let lights: Vec> = frames.into_iter().map(|fr| fr.light).collect(); + let bad = ex::check(&cols, ex::Check { + light: Some((&lights).into()), looped: sp.looped, hold: sp.hold, max_colours: sp.steps.map(|_| 48.0), + trim: sp.trim, ..Default::default() + })?; + for line in &bad { + println!("{line}"); + } + println!("{}", if bad.is_empty() { "quick: clean (the full run also checks parts, reseeds and the act)".to_string() } + else { format!("quick: {} problems", bad.len()) }); + return Ok(u8::from(!bad.is_empty())); + } "look" => { let mut pick: Vec = args[1..].iter().filter_map(|a| a.parse().ok()).filter(|&f| f < sp.n).collect(); if pick.is_empty() { @@ -704,7 +767,7 @@ fn command(ctx: &Ctx, out: &Path, args: &[String]) -> Result { names: [sp.name.clone(), id.clone()], ..Default::default() })?; println!("bench.png"); } - other => return Err(format!("unknown command {other}: look [frames], glow, bench ")), + other => return Err(format!("unknown command {other}: quick, look [frames], glow, bench ")), } Ok(0) } @@ -767,6 +830,20 @@ pub fn run(fx: &(dyn Effect + Sync), dir: &Path, args: &[String]) -> Result = sp.variants.iter() .map(|v| json!({"name": v.name, "sheet": format!("{name}_{}.png", v.name), "ramp": v.ramp, "light_ramp": v.light_ramp})) @@ -774,7 +851,13 @@ pub fn run(fx: &(dyn Effect + Sync), dir: &Path, args: &[String]) -> Result have.extend(add.clone()), + _ => { + extra.insert(k.clone(), v.clone()); + } + } } let extra = Value::Object(extra); fc::check(&extra)?; @@ -796,7 +879,7 @@ pub fn run(fx: &(dyn Effect + Sync), dir: &Path, args: &[String]) -> Result = seeds.iter().flat_map(|&sd| (0..sp.n).step_by(step).map(move |f| (sd, f))).collect(); - let mut drawn = par(order.len(), |i| ctx.full(order[i].1, order[i].0, Layer::Effect).map(|c| c.col))?.into_iter(); + let mut drawn = par(order.len(), |i| ctx.sheet(order[i].1, order[i].0).map(|c| c.col))?.into_iter(); bad.extend(ex::check_seeds(|_, _| drawn.next().unwrap_or_else(|| Array3::zeros((sp.h, sp.w, 4))), sp.n, &seeds, step)?); if let Some(act) = meta.pointer("/meta/beanfx/act") { bad.extend(ex::check_act(act, sp.n as i64, sp.fps, sp.looped)?); diff --git a/plugins/beanfx/skills/beanfx/kit/src/gate.rs b/plugins/beanfx/skills/beanfx/kit/src/gate.rs index d69e6e5..3f22e2b 100644 --- a/plugins/beanfx/skills/beanfx/kit/src/gate.rs +++ b/plugins/beanfx/skills/beanfx/kit/src/gate.rs @@ -24,8 +24,9 @@ const USAGE: &str = "The /beanfx brief gate: which knobs to ask the owner about beanfx gate - < prompt.txt Prints one JSON object and exits 0. Source \"jev\": `ask` (knob names in order) and `skip`. Source \"model\": Jev is -not available (no jev.py, no key, breaker open, an error); the model reads each knob file's \"Fixed when\" and -decides. BEANFX_GATE=model turns Jev off. BEANFX_KNOBS names the knobs folder. Exit 2 only on bad usage."; +not available (no jev.py, no key, breaker open, an error); `questions` lists each knob's stated and applies +questions so the model decides from this output and opens only the files of the knobs it asks. +BEANFX_GATE=model turns Jev off. BEANFX_KNOBS names the knobs folder. Exit 2 only on bad usage."; /// Runs inside python3: asks Jev and prints one JSON line, {"fallback": reason} or {"answers", "ms"}. const JEV_SCRIPT: &str = r#" @@ -156,8 +157,19 @@ fn dumps(v: &Value) -> String { fn fallback(knobs: &[Knob], reason: &str) -> i32 { let files: Vec<&str> = knobs.iter().map(|k| k.file.as_str()).collect(); - let out = json!({"source": "model", "reason": reason, "knobs": files, - "note": "Read each knob file's 'Fixed when' and decide which to ask."}); + // each knob's two frontmatter questions inline, so the model decides from one output and opens a knob file + // only for a knob it asks (reading all 18 files cost minutes per run) + let questions: Vec = knobs.iter().map(|k| { + let mut q = json!({"name": k.name, "stated": k.stated}); + if let Some(a) = &k.applies { + q["applies"] = json!(a); + } + q["file"] = json!(k.file); + q + }).collect(); + let out = json!({"source": "model", "reason": reason, "knobs": files, "questions": questions, + "note": "For each knob in order: skip it when its `applies` question is no, or its `stated` question is yes for \ + the prompt; ask the rest. Open a knob's file only to build the question for a knob you ask."}); println!("{}", dumps(&out)); 0 } diff --git a/plugins/beanfx/skills/beanfx/kit/tests/fixtures/snapshots/halo.txt b/plugins/beanfx/skills/beanfx/kit/tests/fixtures/snapshots/halo.txt new file mode 100644 index 0000000..ce6a417 --- /dev/null +++ b/plugins/beanfx/skills/beanfx/kit/tests/fixtures/snapshots/halo.txt @@ -0,0 +1,17 @@ +83d6396e02ecd781 contact.png +e30418a1954d925e halo.gif +ffda15940b642dca halo_1x.png +a875fb8573da30b7 halo_4x_dark.png +e071ccfabc22dbaa halo_4x_mid.png +2112e257404fe187 sheets/halo.json +fda81d38e6badda8 sheets/halo.png +74ce0a7e575f5461 sheets/halo_cast.json +b1227efa552015a0 sheets/halo_cast.png +d06fb1d58eabb329 sheets/halo_cast_color.png +43c7fc8186de444c sheets/halo_cast_light.png +988b54048192b469 sheets/halo_color.png +3083b424dcb33dae sheets/halo_light.png +0c53c7ba4bc3a7d9 sheets/halo_travel.json +be318c15730d998d sheets/halo_travel.png +be318c15730d998d sheets/halo_travel_color.png +69f7563bfcc21c03 sheets/halo_travel_light.png diff --git a/plugins/beanfx/skills/beanfx/kit/tests/gate.rs b/plugins/beanfx/skills/beanfx/kit/tests/gate.rs index 9ca2745..d1c1777 100644 --- a/plugins/beanfx/skills/beanfx/kit/tests/gate.rs +++ b/plugins/beanfx/skills/beanfx/kit/tests/gate.rs @@ -168,6 +168,14 @@ fn model_fallbacks() { assert_eq!(code, 0); assert_eq!(out["source"], "model"); assert_eq!(out["knobs"].as_array().unwrap().len(), 18); + let qs = out["questions"].as_array().unwrap(); + assert_eq!(qs.len(), 18, "one question entry per knob"); + assert_eq!(qs[0]["name"], "role", "in knob order: {:?}", qs[0]); + assert!(qs.iter().all(|q| q["stated"].as_str().is_some_and(|s| s.contains('?'))), "every knob has its stated question"); + let sound = qs.iter().find(|q| q["name"] == "sound").unwrap(); + assert!(sound["applies"].as_str().is_some(), "an optional knob carries its applies question: {sound:?}"); + let style = qs.iter().find(|q| q["name"] == "style").unwrap(); + assert!(style.get("applies").is_none(), "a knob that always applies has no applies question: {style:?}"); let missing = e.dir.join("nope.py"); let (code, out) = e.run(&["x"], &[("BEANFX_JEV_PY", missing.to_str().unwrap())]); assert_eq!((code, out["reason"].as_str()), (0, Some("no jev.py"))); diff --git a/plugins/beanfx/skills/beanfx/kit/tests/runner.rs b/plugins/beanfx/skills/beanfx/kit/tests/runner.rs index 633eeec..8ac6b8b 100644 --- a/plugins/beanfx/skills/beanfx/kit/tests/runner.rs +++ b/plugins/beanfx/skills/beanfx/kit/tests/runner.rs @@ -28,6 +28,8 @@ impl Effect for Burst { if self.steps { sp.steps = Some(lt::Steps::default()); } + let note = beanfx::fc::part("x.png", 8, 8, 2, FPS, [4.0, 4.0], false, "target", None); + sp.extra.insert("parts".into(), beanfx::serde_json::json!({"note_part": note})); if self.aura { sp.caster_foot = Some([16.0, 28.0]); sp.aura = Some(Aura { frames: 4, w: 16, h: 12, pivot: [8.0, 10.0] }); @@ -55,6 +57,7 @@ impl Effect for Burst { cv.ellipse(16.0, 26.0 + dy, 4.0, 1.5, dr::hex("#80c0ff"), 0.8); cv.glow(16.0, 26.0, 3.0, 0.3); } + Layer::Behind => {} } Ok(()) } @@ -91,6 +94,7 @@ fn run_writes_every_output_and_the_parts() { assert_eq!(bfx["glow"], "medium"); assert_eq!(bfx["parts"]["aura_back"]["layer"], "behind"); assert_eq!(bfx["parts"]["aura_front"]["layer"], "front"); + assert_eq!(bfx["parts"]["note_part"]["anchor"], "target", "parts in Spec.extra join the aura parts: {}", bfx["parts"]); assert!(bfx["act"]["hits"].as_array().is_some_and(|h| h.len() == 1)); } @@ -101,6 +105,7 @@ fn run_with_stepped_light_and_the_commands() { assert!(dr::run(&fx, &dir, &[]).unwrap() <= 1); let out = dir.join("out"); + assert!(dr::run(&fx, &dir, &args(&["quick"])).unwrap() <= 1); assert_eq!(dr::run(&fx, &dir, &args(&["look"])).unwrap(), 0); assert!(out.join("look.png").is_file() && out.join("look_1x.png").is_file()); assert_eq!(dr::run(&fx, &dir, &args(&["look", "1", "4", "99"])).unwrap(), 0); @@ -109,6 +114,23 @@ fn run_with_stepped_light_and_the_commands() { assert!(dr::run(&fx, &dir, &args(&["bench"])).unwrap_err().contains("pixelfx id")); assert!(dr::run(&fx, &dir, &args(&["nope"])).unwrap_err().contains("unknown command nope")); + + // quick flags what the full run flags on the sheet: a disc cut by the cell edge exits 1 + struct Cut; + impl Effect for Cut { + fn spec(&self) -> Spec { + Spec::new("cut", 16, 16, 4, FPS) + } + fn draw(&self, cv: &mut Canvas, _f: usize, _seed: u64, layer: Layer) -> Result<(), String> { + if layer == Layer::Effect { + cv.ellipse(1.0, 8.0, 4.0, 4.0, [1.0; 3], 1.0); + } + Ok(()) + } + } + let quick = dr::run(&Cut, &dir, &args(&["quick"])).unwrap(); + let full = dr::run(&Cut, &dir, &[]).unwrap(); + assert_eq!((quick, full), (1, 1), "quick and the full run both fail an edge cut"); } #[test] diff --git a/plugins/beanfx/skills/beanfx/kit/tests/snapshot.rs b/plugins/beanfx/skills/beanfx/kit/tests/snapshot.rs index 3a44854..5fa1a51 100644 --- a/plugins/beanfx/skills/beanfx/kit/tests/snapshot.rs +++ b/plugins/beanfx/skills/beanfx/kit/tests/snapshot.rs @@ -332,3 +332,85 @@ fn a_smoky_variant_is_a_note_not_a_failure() { assert_eq!(code, 0, "a variant that leaves smoke grey passes"); assert!(out.join("sheets").join("smoky_frost.png").exists(), "the variant is still written"); } + +/// A halo of three dots behind a caster, a dot in front, and two parts: a crop of the sheet (the default +/// `Effect::part`) and a travel loop with its own clock. `split` false draws the halo in `Effect` instead, as a +/// draft did before `Layer::Behind` existed. +struct Halo { + split: bool, +} + +impl Halo { + fn halo(cv: &mut Canvas, f: usize) { + for i in 0..3 { + let a = std::f64::consts::TAU * (i as f64 / 3.0 + f as f64 / 12.0); + cv.ellipse(16.0 + 7.0 * a.cos(), 12.0 + 7.0 * a.sin(), 2.0, 2.0, hex("#ffc93c"), 1.0); + cv.glow(16.0 + 7.0 * a.cos(), 12.0 + 7.0 * a.sin(), 3.0, 0.3); + } + } +} + +impl Effect for Halo { + fn spec(&self) -> Spec { + let mut sp = Spec::new("halo", 40, 32, 12, 12.0); + sp.pivot = [16.0, 28.0]; + sp.caster_foot = Some([16.0, 28.0]); + sp.trim = None; + sp.light_ramp = vec!["#5a1a08".into(), "#f07a1e".into(), "#ffd070".into(), "#ffffff".into()]; + let mut travel = dr::Part::new("travel", 4, 12, 8, [0.0, 0.0], [6.0, 4.0], "travel"); + travel.looped = true; + travel.more = beanfx::serde_json::json!({"speed": 120}); + sp.parts = vec![dr::Part::new("cast", 12, 24, 24, [4.0, 0.0], [12.0, 28.0], "caster"), travel]; + sp + } + + fn draw(&self, cv: &mut Canvas, f: usize, _seed: u64, layer: Layer) -> Result<(), String> { + let fade = 1.0 - 0.9 * dr::span(f as f64, 6.0, 11.0); + match layer { + Layer::Behind if self.split => Halo::halo(cv, f), + Layer::Effect => { + if !self.split { + Halo::halo(cv, f); + } + cv.ellipse(30.0, 20.0, 2.0 * fade, 2.0 * fade, hex("#fff6d8"), 1.0); + } + Layer::Caster => cv.ellipse(16.0, 20.0, 3.0, 8.0, hex("#404050"), 1.0), + _ => {} + } + Ok(()) + } + + fn part(&self, cv: &mut Canvas, key: &str, f: usize, seed: u64) -> Result<(), String> { + if key != "travel" { + // the cast part: the default crop of the sheet + self.draw(cv, f, seed, Layer::Behind)?; + return self.draw(cv, f, seed, Layer::Effect); + } + let r = 2.0 + 0.5 * (std::f64::consts::TAU * f as f64 / 4.0).sin(); + cv.ellipse(6.0, 4.0, r, r, hex("#ffc93c"), 1.0); + cv.line([0.0, 4.0], [4.0, 4.0], hex("#f07a1e"), 0.8); + Ok(()) + } +} + +#[test] +fn behind_layer_ships_in_the_sheet_and_parts_are_written() { + let got = case(&Halo { split: true }, "halo"); + for f in ["sheets/halo_cast.png", "sheets/halo_travel.json"] { + assert!(got.contains_key(f), "missing {f}: {:?}", got.keys().collect::>()); + } + // before Layer::Behind the halo was drawn in Effect: the sheet is the same bytes, only the previews change + let _g = ENV.lock().unwrap_or_else(|e| e.into_inner()); + let (old, _) = run(&Halo { split: false }, "halo_old", "1"); + let before = hashes(&old); + for f in ["sheets/halo.png", "sheets/halo_color.png", "sheets/halo_light.png", "halo_1x.png", "sheets/halo_cast.png"] { + assert_eq!(got.get(f), before.get(f), "{f}: Behind + Effect is the sheet the single layer drew"); + } + assert_ne!(got.get("halo_4x_dark.png"), before.get("halo_4x_dark.png"), "the preview puts the halo behind the caster"); + let js: beanfx::serde_json::Value = + beanfx::serde_json::from_str(&std::fs::read_to_string(old.join("sheets/halo.json")).unwrap()).unwrap(); + let parts = &js["meta"]["beanfx"]["parts"]; + assert_eq!(parts["cast"]["anchor"], "caster", "{parts}"); + assert_eq!(parts["travel"]["speed"], 120, "{parts}"); + assert_eq!(parts["travel"]["json"], "halo_travel.json", "{parts}"); +} From 4a527b2e650d99e7c8bc1395e8f611c0ff73d7bb Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 11:17:53 +0000 Subject: [PATCH 2/2] Release 2.5.0 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_014BGZyg2BhjJ2sSkPNmY5F9 --- CHANGELOG.md | 4 ++-- plugins/beanfx/.claude-plugin/plugin.json | 2 +- plugins/beanfx/skills/beanfx/kit/Cargo.lock | 2 +- plugins/beanfx/skills/beanfx/kit/Cargo.toml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b315b5c..e624404 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,9 +3,9 @@ Versions follow `plugins/beanfx/.claude-plugin/plugin.json`. A release is a tag `v` on `main`; see `CONTRIBUTING.md`. -## Unreleased +## 2.5.0 -Shorter runs for long, caster to target effects (learnt on a 540-frame nine-sun cast that took about 15 minutes). +Shorter runs for long, caster to target effects (2026-11-24). - `Layer::Behind`: the part of the effect behind the character (a ring at the back, a halo). The sheet is `Behind` then `Effect` on one canvas, the same bytes as drawing both in `Effect`; the previews draw it under the caster. diff --git a/plugins/beanfx/.claude-plugin/plugin.json b/plugins/beanfx/.claude-plugin/plugin.json index e100000..03e4549 100644 --- a/plugins/beanfx/.claude-plugin/plugin.json +++ b/plugins/beanfx/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "beanfx", - "version": "2.4.0", + "version": "2.5.0", "description": "Pixel-art effects drawn as code: /beanfx designs an effect from words or a reference image and exports a sprite sheet, JSON and gifs.", "author": { "name": "bien" diff --git a/plugins/beanfx/skills/beanfx/kit/Cargo.lock b/plugins/beanfx/skills/beanfx/kit/Cargo.lock index d7aab8d..7c888a0 100644 --- a/plugins/beanfx/skills/beanfx/kit/Cargo.lock +++ b/plugins/beanfx/skills/beanfx/kit/Cargo.lock @@ -16,7 +16,7 @@ checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" [[package]] name = "beanfx" -version = "2.4.0" +version = "2.5.0" dependencies = [ "gif", "ndarray", diff --git a/plugins/beanfx/skills/beanfx/kit/Cargo.toml b/plugins/beanfx/skills/beanfx/kit/Cargo.toml index a664adb..828cee2 100644 --- a/plugins/beanfx/skills/beanfx/kit/Cargo.toml +++ b/plugins/beanfx/skills/beanfx/kit/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "beanfx" -version = "2.4.0" +version = "2.5.0" edition = "2021" description = "The /beanfx kit: numpy-exact arrays and random draws, PNG, sheet export and checks, sound, preview writers" license = "MIT"