Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.
docs: two cycles in one loop are suspected and counted, never cut on the pixels' word; --cycles; changelog
Soohong Kim203bc1d7ae3c
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 0b44e92..60ae242 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -2,6 +2,14 @@All notable public changes to `sprite-gen` are recorded here. Versions track the `version:` field in `SKILL.md` and `pyproject.toml`.+## Unreleased - A set is not aligned with a loop that may hold two cycles until someone counts them, and only that count takes one cycle out of it++- **Output change: which sets `video-cycle-align` rewrites.** `video-loop`'s output is 2.25.0's and 2.26.0's: every cut keeps its period, length and start, whatever its legs or shading (the report gains `cycle.fundamental`, and `strip.json` gains `state`). `video-cycle-align` now **stops a set** — nothing rewritten, exit status 1 — where one of its loops may hold two or three cycles (a half or a third of it repeats and is no shorter than the gait floor), and 2.26.0 aligned it; the report is written with `applied: false`, `refused: "cycle-suspects"` and the typed `suspects`. A set with no suspect is aligned as before, every loop resampled from all of its filmed frames. `video-set --align-cycles auto` skips such a state with a warning (`applied: false`, `reason: "cycle-suspects"`, `suspects`) where it aligned it, and the RIFE skip now carries `reason: "rife-not-installed"`. The number of cycles in a loop changes only through the new `--cycles`.+- **Fix: a walk filmed through two strides walked twice as fast as its set, without a word.** A clip drawn on twos whose stride is an odd number of frames repeats better two strides on than one, so `video-loop` cut two strides as one loop, and `video-cycle-align`, which gives every loop one length on the assumption that each holds one cycle, squeezed both into it. The engine does not cut such a loop shorter on the pixels' word: half a stride on, the legs are back in place with near and far swapped, and where they are drawn alike that one step and a true stride half a drawing late are the same picture, so every rule that took the half took some one-stride walk or run to its half step. Instead the shorter repeat is screened (`sprite_gen/video/period.py`: `screen` measures the half and the third — `periodicity`, `pose` off the motion's path, and for the record the legs' `steps` and `follow` — and one rule, `period.verdict`, decides: a half or a third that repeats is a `suspect`, whatever its pose; nothing says "a cycle" and nothing says "not one"). `video-loop` records it (`cycle.fundamental`: `checked`, `suspects`, `legs`), and so does the local search of `--anchor motion-auto`. `video-cycle-align` screens each loop as a ring (`align.cycle_screen`) and stops a set on a suspect, naming the loop, where it returns (frames and seconds), the evidence and the command that settles it (`command`, the same alignment with `--cycles <loop>=<1|2>` to fill in); `--multi-cycle warn` aligns it as it is with a warning per suspect. The pose is not a reason to refuse: a rule that refused "another pose" missed most two-stride loops whose second stride was redrawn a pixel aside or a few per cent lighter, which in pixels is off the motion's path just as a swapped step is. The cost is the other way: a run's half step repeats too, so a run set stops nearly every time until its loops are counted ([docs/video-pipeline.md](docs/video-pipeline.md) section 4, "The fundamental period").+- **New `video-cycle-align --cycles <loop>=k`** (repeatable; the loop by its `--loop-dir`, its strip's name, its directory's name or a `video-set` item's name): how many cycles a loop holds, as counted by whoever looked at it (a person, or a vision call asked how often each foot lands). `1` aligns it as it is; `2` or `3` takes one cycle out of the loop as filmed (`cycle.source/`, `align.take_cycle`: round(L/k) frames from the start whose frame one cycle on is the most like it) and aligns that, without cutting the clip again. Loop rows record `cycles_given`, `cycle_screen` and `cycle_taken`; the report `cycles_given`, `suspects` and `multi_cycle`. Also new: `--multi-cycle fail|warn` and `--state` (the gait floor for loops cut before `strip.json` carried `state`).+- **The foot-strike signals moved to `sprite_gen/video/legs.py`** (`align.strike_signals` and the `align` constants still name them), with one more per frame, `gap` (the widest empty run in the foot band). The turn reads them as before.+- **Docs**: [docs/loop-repair.md](docs/loop-repair.md) section 4 (two cycles in one loop are stopped and counted; `--cycles`), [docs/video-pipeline.md](docs/video-pipeline.md) section 4 ("The fundamental period": the engine does not cut shorter on the pixels' word, because a gait's half step with the legs alike and a cycle half a drawing late are the same picture) and section 5, [docs/loop-review.md](docs/loop-review.md).+## v2.26.0 - The size hold reads a walk's change of size one cycle on, and a follow-through that would fold its region can take the largest gain that does not- **Output change: which walk and run loops are held at their size.** `video-loop --anchor motion-auto` with `--size-hold auto` (the default) reads the clip's change of size one cycle on instead of off a line fitted through the clip (`gait_fallback.cycle_drift`). A clip whose reading crosses 1 % one way or the other is cut differently: one that starts from a standing pose and settles into the walk is no longer held (the line read the settle as a shrinking body), and one whose settle pulled the line under 1 % while the body did grow is now held. A clip held either way is scaled back by the change one cycle on, not by the line's, so its frames differ too: a clip whose first frames zoom in reads its walk's own change, not the zoom, and can find a cycle it did not find scaled by the line. A clip under 1 % both ways, and every clip with `--size-hold off`, is cut exactly as before. `video-follow` with its default `--on-fold refuse` writes what 2.24.0 wrote.diff --git a/SKILL.md b/SKILL.mdindex 204e6e2..09f480f 100644--- a/SKILL.md+++ b/SKILL.md@@ -101,7 +101,7 @@ hold the arms still, and check the loop with `handed-check --state walk`.| Continue or edit an existing clip | `video-extend`, `video-edit` | [video](docs/video.md) || Grok video sprites | `video-set` | [video-pipeline](docs/video-pipeline.md) || A soft part of a walk loop follows the body (a chest, a belly): an ellipse in the first cell, after `video-cycle-align` | `video-follow` | [video-pipeline](docs/video-pipeline.md#6-follow-through--video-follow) |-| Video sprites from a clip your agent makes with a connected video MCP (ZCRE, 지크) | `video-canvas`, `video-prompt --no-last-frame`, the agent's own MCP tools (quote, user approval, generate, save the mp4), then `video-frames` and `video-loop` (a walk or run with `--anchor motion-auto`, which holds its size), and for a walk or run cut in two or more directions `video-cycle-align --view …` over their loop directories. `video-set` is not run on this route, so the set stage it runs by default (`--align-cycles auto`) is yours to run. sprite-gen never calls the MCP. Walk, run and jump only: ZCRE's `grok-imagine-video-1.5` has no end frame, so idle, attack and diagonal walks are refused unless `--unpinned` | [video-pipeline](docs/video-pipeline.md#a-clip-from-a-video-mcp-on-your-agent--zcre) |+| Video sprites from a clip your agent makes with a connected video MCP (ZCRE, 지크) | `video-canvas`, `video-prompt --no-last-frame`, the agent's own MCP tools (quote, user approval, generate, save the mp4), then `video-frames` and `video-loop` (a walk or run with `--anchor motion-auto`, which holds its size), and for a walk or run cut in two or more directions `video-cycle-align --view …` over their loop directories (a set it stops on a loop that may hold two cycles: look at that loop, count its strides, and pass `--cycles <loop>=<k>`). `video-set` is not run on this route, so the set stage it runs by default (`--align-cycles auto`) is yours to run. sprite-gen never calls the MCP. Walk, run and jump only: ZCRE's `grok-imagine-video-1.5` has no end frame, so idle, attack and diagonal walks are refused unless `--unpinned` | [video-pipeline](docs/video-pipeline.md#a-clip-from-a-video-mcp-on-your-agent--zcre) || Ordinary image or edit | `gen --provider codex` or `gen --provider grok` (subscription routes) | [gen](docs/gen.md) || Image generation with no login available (server, container, SaaS) | `gen --provider openai` — server/SaaS route on `OPENAI_API_KEY`, **billed per call**, never a default or a fallback | [gen](docs/gen.md#subscription-first--openai-is-named-or-it-does-not-run) || Base and direction anchors | `anchor` | [directional-anchor-workflow](docs/directional-anchor-workflow.md) |@@ -137,4 +137,4 @@ Scene creation consumes finished assets and remains optional. Asset metadata own## Contracts and advanced tools-[run-contract](docs/run-contract.md) owns numeric requests, run layout, atomic publication and curated exports. [architecture](docs/architecture.md) explains domain ownership. [docs index](docs/README.md) lists every specialized feature and QA procedure. `sprite-gen --help` derives the command map from the package catalog. Never replace an engine stage — extraction, the loop cut, set alignment, loop repair — with a script of your own while presenting the result as a pipeline output. Where a stage's result is wrong, use the engine's own options first (another cut with `video-loop --max-len` or `--cycle fixed`, `video-cycle-align --length` or `--between nearest`), keep the engine's result as the comparison, report the defect against the engine, and name in the delivery each stage done by hand and why. A new clip is for what no stage can reach: the drawing, the motion itself, a clip that holds no whole cycle ([loop-review](docs/loop-review.md)).+[run-contract](docs/run-contract.md) owns numeric requests, run layout, atomic publication and curated exports. [architecture](docs/architecture.md) explains domain ownership. [docs index](docs/README.md) lists every specialized feature and QA procedure. `sprite-gen --help` derives the command map from the package catalog. Never replace an engine stage — extraction, the loop cut, set alignment, loop repair — with a script of your own while presenting the result as a pipeline output. Where a stage's result is wrong, use the engine's own options first (another cut with `video-loop --max-len` or `--cycle fixed`, `video-cycle-align --length`, `--between nearest`, or `--cycles <loop>=<k>` once you have counted a suspect loop's strides), keep the engine's result as the comparison, report the defect against the engine, and name in the delivery each stage done by hand and why. A new clip is for what no stage can reach: the drawing, the motion itself, a clip that holds no whole cycle ([loop-review](docs/loop-review.md)).diff --git a/docs/loop-repair.md b/docs/loop-repair.mdindex 6f98dc8..6280cae 100644--- a/docs/loop-repair.md+++ b/docs/loop-repair.md@@ -258,9 +258,42 @@ same number of frames, starting on the same step.```bashsprite-gen video-cycle-align --loop-dir set/front-walk/loop --loop-dir set/side-walk/loop \--loop-dir set/back-walk/loop [--view front --view side@right --view back] [--start-foot right] \- [--between rife|nearest] [--length N] [--report set/walk.cycle-align.json]+ [--between rife|nearest] [--length N] [--cycles back-walk=2] [--multi-cycle fail|warn] \+ [--state walk] [--report set/walk.cycle-align.json]```+- **Two cycles in one loop are stopped, and counted by whoever looks**: one length for the set is+ one beat only if every loop holds one cycle. A loop that holds two strides, resampled to the+ set's length, walks twice as fast as the rest, arms and legs alike — and pixels cannot tell it+ from a loop of one stride whose two steps look alike ([video pipeline](video-pipeline.md)+ section 4, "The fundamental period"). So before anything is resampled each loop is screened as a+ ring (`align.cycle_screen`, the rule `video-loop` records by, `period.verdict`): a half or a+ third of it that repeats and is no shorter than the state's gait floor makes the loop a+ **suspect** — whatever its pose, which is recorded as evidence. A run set stops nearly every+ time. The state is the one `video-loop` writes in+ `strip.json` (`state`); `--state` gives it for loops cut before.+ - A set with a suspect is **stopped before anything is rewritten** (`--multi-cycle fail`, the+ default): the message and the report name each loop, where it returns (frames and seconds),+ the evidence (`pose`, `steps`), the arguments that settle it, and the command to run once+ they are counted (`command`: the same alignment with `--cycles <loop>=<1|2>` for each, to+ fill in). With no vision call to ask, the agent looks at the loop's frames and gives the count. The report is written with+ `applied: false`, `refused: "cycle-suspects"` and `suspects` (per loop: `dir`, `name`,+ `length`, `status`, `candidates`, `settle`); `align.CycleSuspects` carries the same list.+ - **`--cycles <loop>=k`** is the count that comes back (repeatable; `<loop>` is the+ `--loop-dir`, its strip's name, its directory's name, or for a `video-set` item's `loop`+ directory the item's name). `1`: it holds one cycle, aligned as it is. `2` or `3`: one cycle is+ taken out of the loop as filmed (`cycle.source/`) — round(L/k) frames, from the start whose+ frame one cycle on is the most like it, read as a ring (`align.take_cycle`) — and that is what+ is resampled; the loop row records `cycles_given` and `cycle_taken` (`from`, `start`,+ `length`, `exact`, `repeat_over_step`, `seam_ratio`). `video-loop` is not run again, and a+ later alignment reads the same filmed frames. A count given where the screen found nothing at+ 1/k is still honoured, with a warning.+ - Nothing else changes how many cycles a loop holds: without `--cycles` every loop is resampled+ from all its filmed frames.+ - `--multi-cycle warn` aligns a suspect set as it is, a warning per suspect.+ - Who counts: a person looking at the loop, or a vision call asked how often each foot lands.+ A loop counted once is not remembered — the next alignment needs the same `--cycles`.+- **Length**: the median of the set's own lengths (`--length` overrides). The median is thelength that needs the fewest made frames across the set; a loop already that long is nottouched.@@ -345,6 +378,8 @@ directions (`--align-cycles auto`, default; `off` keeps each loop's own length).carries `cycle_align` per state and `<state>.cycle-align.json`; a failed alignment is listed as`cycle-align:<state>` and the loops stay as cut. Without RIFE the alignment is skipped, notfailed (section 1, "Without RIFE"); install it and run `video-cycle-align` on the set's loops.+A set stopped on a suspect is skipped the same way (`reason: "cycle-suspects"`, the loops under+`suspects`, a warning naming them): count their cycles and run `video-cycle-align --cycles`.Cutting a loop again with `video-loop` removes its `cycle.source/`, so the next alignment readsthe new cut. An alignment also clears a follow-through (`video-follow`, which moved the oldcells): `follow.source.png` and the strip's `follow` record are removed and the loop's row saysdiff --git a/docs/loop-review.md b/docs/loop-review.mdindex cfc51e3..40ed4e6 100644--- a/docs/loop-review.md+++ b/docs/loop-review.md@@ -21,6 +21,10 @@ request remains 3 seconds; it does not determine the playback speed.when it fits the window and passes the periodicity gate. Keeping two real repetitionsis preferable to discarding a potentially distinct phase. This may produce a two-cycleloop of a genuine short gait; frames keep their original timing.+- Nothing is cut shorter than the period found. A half or a third of it that repeats is+ recorded as a suspect (`cycle.fundamental.suspects`); look at+ whether the loop shows one stride or two, and tell `video-cycle-align` with `--cycles`+ ([loop repair](loop-repair.md) section 4).- Near-exact short repeats, implausible longer repeats, and non-gait states are notextended by that ambiguity policy. There is no character-specific frame count.- Alpha, frame counts and seam metrics are checked before the output is accepted.diff --git a/docs/video-pipeline.md b/docs/video-pipeline.mdindex c43cd55..4c7d8ee 100644--- a/docs/video-pipeline.md+++ b/docs/video-pipeline.md@@ -659,6 +659,49 @@ anatomical left/right contacts. The report records `half_period_guard.reason ="ambiguous-harmonic"` and `cycle.review_recommended = true`. See [loop review](loop-review.md)for the visual review contract and manual overrides.+**The fundamental period: recorded, never cut on the pixels' word.** A motion that repeats every+P frames repeats every 2P as well, and 2P can be the better repeat: a clip drawn on twos (a new+drawing every other frame) whose cycle is an odd number of frames shows each cycle half a drawing+off the one before, so the profile dips deeper two cycles on than one, and the minimum taken above+is two cycles. Played alone that loop is clean; resampled to the length of a set whose other loops+hold one cycle ([loop repair](loop-repair.md) section 4) it walks at twice their speed.++The engine does not cut it shorter. Half a gait cycle on, the legs are back in place with near and+far swapped; where the two legs are drawn alike (one colour of trousers, white fur) that one step+and a true cycle half a drawing late are **the same picture**. Every rule tried that took the half+as a cycle — an absolute pixel distance, the legs' step count, the pose on the motion's path — cut+some one-stride walk or run to its half step, and the leg signal fails both ways (a heel kick+swings the stride twice a step; a diagonal view's two steps open the feet unequally). So+`video-loop` cuts the period it always cut, and only **records** what a half or a third of it shows+(`cycle.fundamental`, `sprite_gen/video/period.py`):++- each candidate is the profile's own minimum within a frame of P/2 and P/3 (`checked`: `period`,+ `of`, `divisor`, `cycles`), no shorter than the gait floor (walk 0.6 s, run 0.35 s; other states+ the window's floor — under the floor a repeat is one step, the half-period guard's case);+- it is measured: `periodicity` (its dip below the profile's mean), `pose` (how far the frame one+ candidate on lies off the motion's own path — over the short spans (a, b) around a frame, the+ least `D[a][x] + D[x][b] − D[a][b]` — over that frame's own distance, both in playback steps;+ `off_path`, `distance`), and, for the record only, the legs' `steps` and `follow`+ (`sprite_gen/video/legs.py`, the signal the foot-strike turn reads);+- one rule, `period.verdict`, decides (`verdict`, `why`): a candidate that repeats — dips 0.15 or+ more below the profile's mean — is a `suspect`, and the suspects are listed (`suspects`). That is+ the whole rule. Nothing says "this is a cycle", and nothing says "this is not one": the pose and+ the legs are evidence for whoever looks, never a reason to refuse. A rule that refused "another+ pose" (pose 0.8 or over) missed most two-stride loops whose second stride was redrawn a little+ differently — moved a pixel, a few per cent lighter, the foot kicked higher — because in pixels+ that is off the motion's path just as a step with the legs swapped is.++`review_recommended` keeps its meaning (the ambiguous-harmonic retention above). The record is for+the set stage: `video-cycle-align` screens every loop by the same rule, stops a set on a suspect,+and takes one cycle out of a loop only when told how many it holds (`--cycles`, [loop+repair](loop-repair.md) section 4). The local search of `--anchor motion-auto` records the same.+The rule leans one way on purpose: a suspect costs a look, a miss a loop that plays twice as fast.+A run's half step repeats as well as most of its strides do, so a run set is suspected nearly+every time and stops until its loops are counted; a walk's half step is under its floor more+often. What still escapes it is a second stride that drifts across the picture in steps of four+pixels or more without the body anchor's ramp, and any loop whose half is under the gait floor+(a walk faster than 0.6 s a step).+**The size is held before the search** (`--anchor motion-auto`, `--size-hold auto`, the default).A walk or run filmed from its first frame only (no end frame) often grows or shrinks as it plays:a front walk comes a little closer with every step, a back walk goes away. The loop is then cut on@@ -840,9 +883,10 @@ auto`, the default; `off` keeps each loop's own length). The same step stands al`sprite-gen video-cycle-align --loop-dir … --view …`. `set.report.json` carries `cycle_align`per state (with `start_foot` per item), a failed alignment is listed as `cycle-align:<state>`,and a made frame with a smear or a loop whose foot could not be named is a line under-`warnings`. Without RIFE the alignment-is skipped with a warning (`applied: false`, and a line under the report's `warnings`), not failed. See-[loop repair](loop-repair.md) section 4.+`warnings`. Two cases skip the alignment with a warning instead of failing it (`applied: false`,+`reason`, and a line under the report's `warnings`): no RIFE (`rife-not-installed`), and a loop+that may hold more than one cycle (`cycle-suspects`, the loops under `suspects`; count them, then+`video-cycle-align --cycles <loop>=<k>`). See [loop repair](loop-repair.md) section 4.## 6. Follow-through — `video-follow`