Skip to content

Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.

fix(prompt): without --handed every prompt is 2.22.0's, byte for byte; the arm sentences go on only for a wrist item

Soohong Kimc77b5bc69638
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ef485af..a531da5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,21 +2,16 @@
All notable public changes to `sprite-gen` are recorded here. Versions track the `version:` field in `SKILL.md` and `pyproject.toml`.
-## v2.23.0 - Every prompt part is said once, and a walking side view shows the far arm's item each time that arm swings forward
-
-- **Every engine sentence goes on a prompt through one place, and none is said twice** (`sprite_gen/gen/prompt_parts.py`, `Prompt.add`). A prompt is the caller's text and then the engine's pieces — the view, the turn over a reference, a handed item, the key background, the layout guide; for a clip the hold, the frame and camera rules, a Lite model's sentences and the side view's hold. Each piece was attached where it was made, so some were said twice and some disagreed. A sentence the prompt already has is now dropped, a piece whose topic the prompt covers is left out, and one the prompt rules out is refused. `gen.still_prompt`, `batch.clip_prompt_parts`, `walk_start_prompt` and `video.side_view_prompt` build on it. [docs/prompt-assembly.md](docs/prompt-assembly.md).
-- **Fix: a reference still with `--direction` said the turn twice, the second time as a full profile.** After the view sentence, the reference piece said "The subject must be facing left (toward the left edge of the image)", which asked a three-quarter view for a side view's turn. With `--direction` it now says only what the view sentence does not: "Left here means toward the left edge of the image, regardless of the reference image's orientation. Preserve the subject's design." A reference run with `--facing` alone is unchanged.
-- **Fix: a facing correction's regeneration carried the facing sentence twice** (`--facing-fix regen`): the correction now replaces the sentence it corrects.
-- **Fix: a key background is read however it is worded, and not when ruled out** (`chroma.named_key_background`). "A background of pure magenta" and "magenta-colored background" were not read, so the key line went on a second time. "No green screen" and "holding a green key" were read as asking for green, so a reference run got no key line and came back on a light ground. The name before or after "background" / "backdrop", "keyed on magenta" and "on a green key" are read now; a negation right before the key's name rules it out (`chroma.ruled_out_key_backgrounds`). A prompt that rules out the key `--chroma-key` chose is refused before the model runs.
-- **Fix: `video --direction side` added its side-view hold after a clip prompt that already had it.** A `video-prompt` or `video-set` prompt is sent as it is, and one that faces the other way than `--facing` is refused before the facing inspection.
-- **A walk or run says "in place" and its view once.** The side and diagonal gait sentences ended "without moving across the screen" and the frame sentence said "does not move across the screen"; the gait sentences and holds no longer add it. A walk or run seen from the front, from behind or at a diagonal said its view in the gait sentence ("facing the viewer", "keeps the exact three-quarter back angle of the image") and again in the view sentence ("The character is seen from the front, facing the viewer directly."); its prompt now leaves the view sentence out (`batch.GAIT_SAYS_VIEW`). With a caller's own motion paragraph (`--motion`), `--character` was named only on that view sentence; it is now named on the gait hold that says the view ("A small fox adventurer in a green cloak stays in place as if on a treadmill, without coming any closer, and keeps facing the viewer the whole time."), and a clip prompt that would leave the character out is an error. A side gait keeps the view sentence, and a caller's own side gait is held with "It stays in place as if on a treadmill." (its facing is the view sentence's). Other states are unchanged. A cached `video-set` clip made with the old wording is refused as before ("cached clip prompt differs"); pass `--force` to film it again.
-- **The caller's own words are reported, not edited.** Text that turns the subject another way than `--facing` (or to a side in a front or back view), or puts a `--handed` item on its other side, is sent as written with a warning; text that repeats an option gets a note. `gen` prints them and records `extra.prompt_notes`; `video-prompt --json` lists conflicts in `warnings` and all of them in `notes`; `video-set` records `prompt_notes` per item.
-- **Fix: a watch on the far wrist was in no frame of a side walk.** 2.22.0 said every item on the far side of a side view hidden, and never named it in the clip ("the wrist in front of the body stays bare"). A walking character's far arm comes forward of the body with every step, and what it wears shows then. An item on a far arm or leg (`handedness.limb` reads the body part) is now said to show wherever that limb is out in front of the body: in the still ("wherever the far arm reaches out in front of the body, clear of its outline, the black smartwatch shows whole on it; where the body covers that arm, it is hidden") and in a walk or run ("stays on the wrist that wears it in the image, on the arm on the far side of the body, and shows each time that arm swings forward; the arm nearer the viewer stays bare, exactly as in the image"). On the near arm the walk says the other arm stays bare "both where it shows behind the body and where it swings out in front of it". Both start "Both arms swing back and forth with each step, opposite to the legs.", and no sentence holds an arm still. A far part that does not swing (a pin on the far side of the head) and a state that does not step (idle, attack) keep the 2.22.0 sentences. [docs/video-pipeline.md](docs/video-pipeline.md#handedness--an-item-on-one-side).
+## v2.23.0 - A walking side view shows the far wrist's item each time that arm swings forward; without `--handed` every prompt is 2.22.0's
+
+- **Without `--handed`, every prompt is 2.22.0's, byte for byte.** Clips (built-in or `--motion`, every model and pin), `video-prompt`, stills (view, facing, reference, key line, layout guide, the `--facing-fix regen` regeneration), `video --direction side` and the mid-step redraw send what 2.22.0 sent. `tests/gen/test_prompt_freeze.py` holds every prompt string in that table to `tests/fixtures/prompts-v2.22.0.json.gz`, drawn from the 2.22.0 tag's source. The engine's pieces go on through one place (`sprite_gen/gen/prompt_parts.py`, `Prompt.add`), which puts them on as 2.22.0 did; with `--handed` the prompt is that same prompt with the handed sentences put in, and nothing else changes. [docs/prompt-assembly.md](docs/prompt-assembly.md) lists the faults of the 2.22.0 prompts kept until a before-and-after comparison says to change them.
+- **Fix: a watch on the far wrist was in no frame of a side walk.** 2.22.0 said every item on the far side of a side view hidden, and never named it in the clip ("the wrist in front of the body stays bare"). A walking character's far arm comes forward of the body with every step, and what its wrist or hand wears shows then. An item on a wrist, a hand, a forearm or an elbow (`handedness.limb`, one table: `SWINGING_ARM_PARTS`) on the far arm is now said to show wherever that arm is out in front of the body: in the still ("wherever the far arm reaches out in front of the body, clear of its outline, the black smartwatch shows whole on it; where the body covers that arm, it is hidden") and in a walk or run ("stays on the wrist that wears it in the image, on the arm on the far side of the body, and shows each time that arm swings forward; the arm nearer the viewer stays bare, exactly as in the image"). On the near arm the walk says the other arm stays bare "both where it shows behind the body and where it swings out in front of it". Both start "Both arms swing back and forth with each step, opposite to the legs." (`handedness.ARMS_SWING_TEXT`, the one place that sentence lives), and no sentence holds an arm still. An item anywhere else — an ear, the head, a tail, the body, a leg, a shoulder, the upper arm — gets no arm sentence and keeps the 2.22.0 sentences, as does a state that does not step (idle, attack). [docs/video-pipeline.md](docs/video-pipeline.md#handedness--an-item-on-one-side).
- **A side view names the near part "nearer the viewer", not "in front of the body"** (still and clip sentences): in a mid-stride still the far arm is the one in front of the body, so "the wrist in front of the body stays bare" named the wrist with the watch.
-- **A clip keeps what its first frame shows**: for a walk or run with an item on the far limb of a side view, `video-prompt --json` (`still_needs`, and stderr) and `video-set` (each item's `still_needs`) say the still must be drawn mid-stride with that limb out in front of the body and the item in view. The docs give the pose sentence for the prompt.
-- **One handed sentence per wrist, not per item**: with an item on each wrist a side clip said "the wrist in front of the body stays bare" and "the red ribbon stays on the wrist in front of the body" together, and with two items on one wrist it said the same sentence twice. Items on one part share a sentence, a part another item is on is not called bare, and a still says "none of it" there. A diagonal's clip sentence also reads "…, nearer the viewer, for the whole clip" (the comma was missing).
-- **`handed-check` passes a far arm's item in view and fails the near arm's** (side views): 2.22.0 failed every frame that showed the far item whole ("in full view on the far side"). An item on a far arm or leg must now be out in front of the body in every frame it shows — on the facing side of the body's centre by at least a tenth of the body's height (`far_in_front`); at or behind the centre it is on the near limb. With the new `--state walk|run` it must also show in at least a quarter of the frames (`far_shown`; unchecked without `--state` or for a state that does not step). A side view's near item must show in three quarters of the frames, not half: a far item turned over to face the other way shows in about half. A far part that does not swing keeps the hidden-or-a-sliver rule (`far_hidden`), and a diagonal's near side keeps half.
-- **`tests/gen/test_prompt_assembly.py`** draws every prompt in the option table as text — views, facings, items, what the caller's text already says, states, clip models, the correction, the start still and the hand-offs between verbs — and checks each for a sentence said twice, words that turn the subject both ways, more than one key background, a limb called bare and dressed at once, and a swinging arm in a state that does not step.
+- **A clip keeps what its first frame shows**: for a walk or run with an item on the far wrist or hand of a side view, `video-prompt --json` (`still_needs`, and stderr) and `video-set` (each item's `still_needs`) say the still must be drawn mid-stride with that arm out in front of the body and the item in view. The docs give the pose sentence for the prompt.
+- **One handed sentence per wrist, not per item**: with an item on each wrist a side clip said "the wrist in front of the body stays bare" and "the red ribbon stays on the wrist in front of the body" together, and with two items on one wrist it said the same sentence twice. Items on one part share a sentence, a part another item is on is not called bare, and a still says "none of it" there. A diagonal's clip sentence also reads "…, nearer the viewer, for the whole clip" (the comma was missing). A start still's prompt handed back to `gen --direction --handed` carries the handed sentences once.
+- **`handed-check` passes a far wrist's item in view and fails the near arm's** (side views): 2.22.0 failed every frame that showed the far item whole ("in full view on the far side"). An item on a far wrist, hand, forearm or elbow must now be out in front of the body in every frame it shows — on the facing side of the body's centre by at least a tenth of the body's height (`far_in_front`); at or behind the centre it is on the near arm. With the new `--state walk|run` it must also show in at least a quarter of the frames (`far_shown`; unchecked without `--state` or for a state that does not step). A side view's near item must show in three quarters of the frames, not half: a far item turned over to face the other way shows in about half. Any other far item keeps the hidden-or-a-sliver rule (`far_hidden`), and a diagonal's near side keeps half.
+- **The caller's own words are reported, not edited.** Text that turns the subject another way than `--facing` (or to a side in a front or back view), or puts a `--handed` item on its other side, is sent as written with a warning; text that repeats an option gets a note. `gen` prints them and records `extra.prompt_notes`; `video-prompt --json` lists conflicts in `warnings` and all of them in `notes`; `video-set` records `prompt_notes` per item. The prompt is the same with or without them.
+- **`tests/gen/test_prompt_assembly.py`** draws every prompt in the option table as text — views, facings, items on a wrist or an ear, what the caller's text already says, states, clip models, the start still and the hand-offs between verbs — and checks each for the prompt without `--handed` plus the handed piece and nothing else, a handed sentence said twice, a limb called bare and dressed at once, an arm sentence where no wrist item is or no step swings it, and the notes.
## v2.22.0 - A character with an item on one side has its left-facing views drawn, not mirrored, and an attack is filmed with less room above
diff --git a/SKILL.md b/SKILL.md
index a3f972f..486dccb 100644
--- a/SKILL.md
+++ b/SKILL.md
@@ -70,9 +70,9 @@ it never changes the requested direction. Image correction requires explicit opt
| Command option | Values and default | Behavior |
|---|---|---|
-| `gen --facing` | `preserve` (default), `right`, `left` | With `--ref`, an explicit direction adds a prompt requirement and checks the generated still. With `--direction` the view sentence says the turn and this piece only pins the image edge ([prompt-assembly](docs/prompt-assembly.md)). |
+| `gen --facing` | `preserve` (default), `right`, `left` | With `--ref`, an explicit direction adds a prompt requirement and checks the generated still. |
| `gen --facing-fix` | `none` (default), `mirror`, `regen` | Record without correction; opt into mirroring an observed opposite or regenerating once and rechecking. A still-opposite regeneration is mirrored. |
-| `video --direction` | `side`, `front`, `back`, `front_diagonal`, `back_diagonal`; unset by default | `side` opts into facing inspection and a matching prompt requirement (not repeated on a `video-prompt` prompt, which already says it; refused when that prompt faces the other way); the others skip it. The two diagonals are three-quarter views turned right (`VIEW_TEXT`); a walk or run in one is filmed pinned (`pins_last_frame`). |
+| `video --direction` | `side`, `front`, `back`, `front_diagonal`, `back_diagonal`; unset by default | `side` opts into facing inspection and a matching prompt requirement; the others skip it. The two diagonals are three-quarter views turned right (`VIEW_TEXT`); a walk or run in one is filmed pinned (`pins_last_frame`). |
| `video --facing`, `video-set --facing` | `right` (default), `left`; `video-set` also `right,left` | Required side direction. `right,left` films every side and diagonal view both ways, each from its own still (`--base side@left=…`); none is mirrored. |
| `gen --direction`, `--handed`; `video-prompt` / `video-set --handed` | a view; `"<item>=<left\|right> [part]"` | An item on one of the character's own sides: the still and clip prompts say where it is in each view, and mirroring is refused. |
| `video --facing-fix`, `video-set --facing-fix` | `none` (default), `mirror` | Record the observation; opt into mirroring an observed opposite in a copy. Batch side inspection is enabled by default. |
@@ -87,8 +87,8 @@ front-facing observations also remain unchanged. Mirroring does not preserve lef
It stays the default, since drawing the left-facing views costs as much again; for a character with a watch on
one wrist or a pin on one side, offer to draw them instead with `--handed` and check them with `handed-check`
(a colour-marked item, frame by frame; `--board` for the eye) —
-[handedness](docs/video-pipeline.md#handedness--an-item-on-one-side). In a side view an item on the far arm
-shows each time that arm swings forward, never hidden for the whole walk: draw that side still mid-stride with
+[handedness](docs/video-pipeline.md#handedness--an-item-on-one-side). In a side view an item on the far wrist
+or hand shows each time that arm swings forward, never hidden for the whole walk: draw that side still mid-stride with
the far arm out in front of the body and the item in view (`video-prompt` says so under `still_needs`), do not
hold the arms still, and check the loop with `handed-check --state walk`.
@@ -116,7 +116,7 @@ hold the arms still, and check the loop with `handed-check --state walk`.
| Optional scene placement, lighting, camera and render | `scene-render`, `scene-inspect` | [scene](docs/scene.md) |
| Defaults | `defaults show`, `defaults save`, `defaults clear` | [user-workflow](docs/user-workflow.md#one-settings-owner) |
-Say a thing once: what an option says, leave out of the prompt. `--direction`, `--facing`, `--handed`, the key background and `video --direction side` each add their own sentence, in one place that drops what the prompt already has. Your prompt carries the subject, its design and its pose. Text that says the opposite of an option ("facing left" with `--facing right`, the item on the other wrist) is sent as written with a warning (`extra.prompt_notes`, `video-prompt`'s `warnings`): fix the prompt, do not send it — [prompt-assembly](docs/prompt-assembly.md).
+Say a thing once: what an option says, leave out of the prompt. `--direction`, `--facing`, `--handed`, the key background and `video --direction side` each add their own sentence after your text, in one place; without `--handed` every prompt is 2.22.0's, byte for byte, and only the handed sentences are left out where your text already has them. Your prompt carries the subject, its design and its pose. Text that says the opposite of an option ("facing left" with `--facing right`, the item on the other wrist) is sent as written with a warning (`extra.prompt_notes`, `video-prompt`'s `warnings`): fix the prompt, do not send it — [prompt-assembly](docs/prompt-assembly.md).
`gen --transparent` with `--ref` plans a chroma key (adding the key's background line to a prompt that names none), and publishes a result that already came back transparent on its own alpha instead of keying its outline away; `alpha.strategy_source` in the report says which (`refs-attached` keyed, `refs-attached-raw-alpha` not) — [gen](docs/gen.md#transparent-output--strategy-per-provider).
diff --git a/docs/README.md b/docs/README.md
index 7be3d1b..5ceef7a 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -75,7 +75,7 @@ grouping is derived from `sprite_gen/_modules.py`, the one taxonomy table.
| Doc | Owns |
|---|---|
| [gen.md](gen.md) | `sprite-gen gen` / `gen-set`: providers, default resolution, transparency strategy per provider, row usage |
-| [prompt-assembly.md](prompt-assembly.md) | What the engine adds to a still or clip prompt, each piece once: the pieces, what counts as already said, what is refused, and the notes on the caller's own words |
+| [prompt-assembly.md](prompt-assembly.md) | What the engine adds to a still or clip prompt and when: the pieces, the 2.22.0 freeze without `--handed`, what counts as already said, and the notes on the caller's own words |
| [video.md](video.md) | `sprite-gen video` / `video-extend` / `video-edit`: stills and clips to mp4 through Grok Imagine (image-to-video, last-frame pin, references, extension, editing) with the user's own credential |
| [video-pipeline.md](video-pipeline.md) | Pipeline B engine contract: state canvas, keyed frames, true-period and one-shot cycles, strip/GIF/WebP, the batch |
| [loop-review.md](loop-review.md) | Automatic loop decisions, ambiguous gait review, visual evidence and explicit cut/alignment overrides |
diff --git a/docs/gen.md b/docs/gen.md
index 54a1fb0..b7c7e3c 100644
--- a/docs/gen.md
+++ b/docs/gen.md
@@ -220,12 +220,11 @@ Backward-compatible wrapper: `$SPRITE_GEN_ROOT/.venv/bin/python $SPRITE_GEN_ROOT
**`--handed`** adds, per item, which of the character's own sides it is on and where that side is in
the view; with it, `--facing-fix mirror` is refused and `regen` never mirrors. See
[video-pipeline](video-pipeline.md#handedness--an-item-on-one-side).
-- **Each engine sentence is said once.** The view, the turn over a reference, the handed item, the
- key background and the layout guide are attached in one place, which leaves out what the prompt
- already says: with `--direction` the reference piece no longer repeats the turn, a facing correction
- replaces the sentence it corrects, and a key background the prompt names gets no second line. Where
- your own text says the opposite of an option ("facing left" with `--facing right`) it is left as
- written and stderr warns; the report lists it under `extra.prompt_notes`. See
+- **The engine's sentences go on after yours, as written.** The view, the turn over a reference, the
+ handed item, the key background and the layout guide are attached in one place; without `--handed`
+ the prompt is 2.22.0's, byte for byte. Leave out of your text what an option says. Where your own
+ text says the opposite of an option ("facing left" with `--facing right`) it is left as written and
+ stderr warns; the report lists it under `extra.prompt_notes`. See
[prompt-assembly](prompt-assembly.md).
## `--quality` and `--resolution` — the two billed knobs
@@ -282,15 +281,14 @@ strategy it can execute, and `--alpha-mode auto` (the default) follows it:
prompt, so the engine adds the `--chroma-key` key's line
(`chroma.KEY_BACKGROUND_TEXT`, the sentence a clip's mid-step redraw also ends on)
to a prompt that names no key, and leaves a prompt that does as it is — no second
- line. A prompt names a key with the key's hex code (`#FF00FF`, `00ff00`), the key's
- name before "background", "backdrop", "screen" or "chroma key" ("a green screen",
- "magenta-colored background"), the name after one ("a background of pure magenta"),
- or "keyed on magenta" / "on a green key" (`chroma.named_key_background`). A colour in
- the subject ("a green frog", "holding a green key") is not a key, and neither is one
- the prompt rules out ("no green screen"): that prompt gets the line. A prompt that
- rules out the very key `--chroma-key` chose is refused before the model runs — pass
- the other key. A prompt that names the other key is left on it: the matte reads the
- key off the borders. `alpha.key_background` records `{"injected": true|false, "key": …}`,
+ line. A prompt names a key with the key's hex code (`#FF00FF`, `00ff00`) or the
+ key's name right before "background", "backdrop", "chroma key", "key" or "screen"
+ (`chroma.named_key_background`); a colour in the subject ("a green frog") is not a
+ key. A prompt that names the other key is left on it: the matte reads the key off
+ the borders. Write the key as "a magenta background" or "#FF00FF": "no green screen"
+ reads as naming green, and "a background of pure magenta" is not read
+ ([prompt-assembly](prompt-assembly.md#known-faults-kept-for-now)).
+ `alpha.key_background` records `{"injected": true|false, "key": …}`,
stderr says which, and the report's `prompt` is the prompt sent. Without the line a
reference on white came back on opaque white (3/3, 2026-10-04) and keying white took
the outline and the cream fills with it. With it (the same prompt otherwise, three
diff --git a/docs/prompt-assembly.md b/docs/prompt-assembly.md
index 7571bd8..00d5706 100644
--- a/docs/prompt-assembly.md
+++ b/docs/prompt-assembly.md
@@ -1,9 +1,25 @@
-# Prompt assembly — the caller's text, then the engine's pieces, each said once
+# Prompt assembly — the caller's text, then the engine's pieces
A prompt the engine sends is the caller's own text and then the engine's sentences. Every engine
sentence is a **piece** with a topic, and every piece goes on through one place
-(`sprite_gen/gen/prompt_parts.py`, `Prompt.add`). That place checks what the prompt already says, so
-a piece is not said twice and two pieces do not disagree. The caller's text is never edited.
+(`sprite_gen/gen/prompt_parts.py`, `Prompt.add`). The caller's text is never edited.
+
+**A piece goes on only where its condition holds.** The arm sentences go on only for a `--handed`
+item on a wrist, a hand, a forearm or an elbow (`handedness.limb`, one table).
+
+## Without `--handed`, 2.22.0's prompts
+
+The prompts a character with no handed item is drawn and filmed from are 2.22.0's, byte for byte:
+clips (built-in or `--motion`, every model and pin), `video-prompt`, stills (view, facing,
+reference, key line, layout guide, the `--facing-fix regen` regeneration), `video --direction side`
+and the mid-step redraw. `tests/gen/test_prompt_freeze.py` compares every prompt string in that table
+with `tests/fixtures/prompts-v2.22.0.json.gz`, drawn from the 2.22.0 tag's source by
+`tests/gen/prompt_freeze_table.py`. The notes and warnings printed beside a prompt are not part of
+that comparison. A change to these prompts is made only after a before-and-after comparison on the
+app's default clip model shows it is better.
+
+`--handed` adds its piece and changes nothing else: the prompt is the one without it, with the handed
+sentences put in (`tests/gen/test_prompt_assembly.py`).
## The pieces
@@ -18,66 +34,39 @@ a piece is not said twice and two pieces do not disagree. The caller's text is n
| key background | `--transparent --ref` when `auto` plans a key | `chroma.KEY_BACKGROUND_TEXT` |
| layout guide | `--layout-guide` | `gen.layout_guide_text` |
-With `--direction`, the view sentence says the turn, so the facing piece says only what it does not:
-"Left here means toward the left edge of the image, regardless of the reference image's
-orientation. Preserve the subject's design." Without `--direction` it says the turn itself ("The
-subject must be facing left (toward the left edge of the image), …"). Said after a three-quarter
-view sentence, that full-profile wording asked for a different turn than the view's 45 degrees.
-
-A facing correction (`--facing-fix regen`) regenerates with the facing piece **replaced** by its
-correction ("CORRECTION REQUIRED: …"), said last. It is not added after the sentence it corrects.
+A facing correction (`--facing-fix regen`) regenerates with the correction ("CORRECTION REQUIRED: …")
+said after the first prompt (`facing.prepare_correction`).
-**A clip** (`video-prompt`, `video-set`, `batch.clip_prompt_parts`):
-
-| Piece | When | Sentence from |
-|---|---|---|
-| motion | always | the state's own (`MOTION_TEXT`, `VIEW_MOTION_TEXT`), or the caller's `--motion` |
-| hold, gait hold, repeat | a caller's `--motion` | `HOLD_TEXT`, `GAIT_HOLD_TEXT`, `REPEAT_TEXT` |
-| view, frame, camera, background, design, rhythm | always | `VIEW_TEXT` in `COMMON_TEXT` / `PINNED_LOOP_TEXT` / `ACTION_COMMON_TEXT` |
-| Lite walk, Lite head | a Lite model's walk | `LITE_WALK_TEXT`, `LITE_HEAD_TEXT` |
-| handed | `--handed` | `handedness.text(clip=True)` |
-| side view | `sprite-gen video --direction side` | `video.side_view_prompt` |
-
-The walk paragraph says a thing once too. That a gait does not move across the screen is the frame
-sentence's ("does not move across the screen"); the side and diagonal gait sentences and holds no
-longer add "without moving across the screen". A walk or run seen from the front, from behind or at
-a diagonal says its view in the gait sentence or hold ("facing the viewer", "keeps the exact
-three-quarter back angle of the image"), so the view sentence is left out of its prompt
-(`batch.GAIT_SAYS_VIEW`); a side gait keeps the view sentence, which carries the facing. With a
-caller's own motion paragraph, `--character` is named on the sentence that says the view: the view
-sentence, or where that is left out, the gait hold ("A small fox adventurer in a green cloak stays in
-place as if on a treadmill, without coming any closer, and keeps facing the viewer the whole time.").
-A clip prompt that would go out without the character is an error, not a prompt.
-
-`video --direction side` holds the side view ("The subject stays in exact side view, facing left. No
-turning around.") only for a prompt that does not say it already: a `video-prompt` or `video-set`
-prompt does ("seen from the exact side, facing left") and is sent as it is.
+**A clip** (`video-prompt`, `video-set`, `batch.clip_prompt_parts`): the motion paragraph (the state's
+own, `MOTION_TEXT` / `VIEW_MOTION_TEXT`, or the caller's `--motion` with `HOLD_TEXT`, `GAIT_HOLD_TEXT`
+and `REPEAT_TEXT`), the view, frame, camera, background, design and rhythm rules (`VIEW_TEXT` in
+`COMMON_TEXT` / `PINNED_LOOP_TEXT` / `ACTION_COMMON_TEXT`) and a Lite model's walk sentences
+(`LITE_WALK_TEXT`, `LITE_HEAD_TEXT`), as 2.22.0 put them together; then the handed piece
+(`handedness.text(clip=True)`). `sprite-gen video --direction side` adds the side view's hold after
+the prompt (`video.side_view_prompt`).
The handed piece of a clip is one sentence per wrist (or other part), not per item: two items on one
wrist share it, and with an item on each wrist neither sentence calls the other wrist bare. In a
-side view's walk or run it says the far arm's item shows each time that arm swings forward
-([handedness](video-pipeline.md#handedness--an-item-on-one-side)).
+side view's walk or run with an item on a wrist, a hand, a forearm or an elbow it says the arms swing
+(`handedness.ARMS_SWING_TEXT`, the one place that sentence lives) and that the far arm's item shows
+each time that arm swings forward
+([handedness](video-pipeline.md#handedness--an-item-on-one-side)). An item anywhere else — an ear,
+the head, a tail, the body, a leg, a shoulder — gets only where it is, and no arm sentence.
**A front or back walk's start still** (`batch.walk_start_prompt`): the mid-step redraw sentence,
the key background line, then the still's handed sentences.
## What "already said" means
-- **The same sentence.** A sentence the prompt already carries, word for word, is dropped from the
- piece. A start-still prompt handed back to `gen --direction --handed` keeps one copy of the handed
- sentences; a `--motion` paragraph that quotes an engine rule ("Camera completely locked, …") is
- not followed by the rule again.
-- **The same topic** (`prompt_parts.ALREADY_SAID`). A key background the prompt names leaves the key
- line out. It is read from the hex code (`#FF00FF`, `00ff00`), the key's name before "background",
- "backdrop", "screen" or "chroma key" ("a green screen", "magenta-colored background"), the name
- after one ("a background of pure magenta", "background: solid green"), or "keyed on magenta" /
- "on a green key" (`chroma.named_key_background`). A colour in the subject is not a key ("a green
- frog", "holding a green key"), and neither is one the prompt rules out ("no green screen",
- "without a magenta background").
-- **The opposite, in the engine's own words, is refused** before anything is generated: a prompt
- that rules out the key the engine would ask for ("no green screen" with `--chroma-key green`), and
- a clip prompt that says the side view faces one way sent to `video --direction side --facing` the
- other.
+- **A key background** (`prompt_parts.ALREADY_SAID`): a still's prompt that names one leaves the key
+ line out. It is read from the hex code (`#FF00FF`, `00ff00`) or the key's name right before
+ "background", "backdrop", "chroma key", "key" or "screen" (`chroma.named_key_background`), as
+ in 2.22.0.
+- **The handed piece** (`prompt_parts.ONCE_ONLY`): a sentence the prompt already carries, word for
+ word, is dropped from it. A start-still prompt handed back to `gen --direction --handed` keeps one
+ copy of the handed sentences.
+
+Every other piece is said as 2.22.0 said it, even where the prompt already says it.
## The caller's own words
@@ -92,13 +81,37 @@ The engine cannot tell which of two statements the caller meant, so it reports a
`gen` prints them as `[gen] warning: …` / `[gen] note: …` and records them in the report's
`extra.prompt_notes`. `video-prompt --json` puts conflicts in `warnings` and all of them in `notes`.
-`video-set` records them per item as `prompt_notes`.
-
-## The check
-
+`video-set` records them per item as `prompt_notes`. The prompt itself is the same with or without
+them.
+
+## Known faults kept for now
+
+2.22.0's prompts have faults the freeze keeps until a before-and-after comparison says to change
+them, most urgent first:
+
+1. A key background is read only as above: "no green screen" reads as asking for green (a
+ `--transparent --ref` run then gets no key line and may come back on a light ground), and "a
+ background of pure magenta" or "magenta-colored background" is not read (the key line goes on a
+ second time).
+2. With `--ref --direction --facing` the facing piece says the turn again after the view sentence,
+ as a full profile ("The subject must be facing left (toward the left edge of the image)"),
+ against a three-quarter view's 45 degrees.
+3. A `--motion` paragraph that quotes an engine rule is followed by the rule again.
+4. A `--facing-fix regen` regeneration carries the facing sentence twice: the first and the
+ correction.
+5. `video --direction side` adds its hold to a prompt that already has it, and to one that faces the
+ other way.
+6. A walk or run says "in place" and its view twice: the side and diagonal gait sentences end
+ "without moving across the screen" as the frame sentence does, and a front, back or diagonal one
+ says its view in the gait sentence and again in the view sentence.
+
+## The checks
+
+`tests/gen/test_prompt_freeze.py` holds every prompt string without `--handed` to 2.22.0's.
`tests/gen/test_prompt_assembly.py` draws every prompt in the option table as text, with no
-generation: five views, both facings, no item / one / two on one wrist / one on each wrist, a
-caller's text that names the key, the turn or the item's side or does not, every state, both clip
-models, a caller's own motion, the facing correction, the start still and the hand-offs between
-verbs. Each prompt is checked for a sentence said twice, words that turn the subject both ways, and
-more than one key background. A new option is a new row in that file's tables.
+generation: five views, both facings, no item / one / two on one wrist / one on each wrist / one on an
+ear, a caller's text that names the key, the turn or the item's side or does not, every state, both
+clip models, a caller's own motion, the start still and the hand-offs between verbs. Each is checked
+for the prompt without `--handed` plus the handed piece and nothing else, a handed sentence said
+twice, a part called bare and dressed at once, an arm sentence where no wrist item is or no step
+swings it, and the notes. A new option is a new row in that file's tables.
diff --git a/docs/video-pipeline.md b/docs/video-pipeline.md
index f9987ac..af99bab 100644
--- a/docs/video-pipeline.md
+++ b/docs/video-pipeline.md
@@ -131,10 +131,8 @@ the default is generic on purpose, because how a character walks (high steps, a
march) is the caller's to say. The front run keeps its sentence.
Since 2.16.0 every walk and run takes that form, from every view: the side walk "walks
-naturally in place, as if on a treadmill" (it said "moves in place on a treadmill" as a place
-and asked for "an even left-right or front-back rhythm"; until 2.22.0 it also ended "without
-moving across the screen", which the frame sentence says — "does not move across the screen" —
-so a side or diagonal gait no longer says it a second time), the
+naturally in place, as if on a treadmill, without moving across the screen" (it said "moves in
+place on a treadmill" as a place and asked for "an even left-right or front-back rhythm"), the
side run "runs naturally in place …", and the front and back runs "runs naturally in place,
facing (away from) the viewer, as if on a treadmill …" (the front run spelled its strides out
and said "toward the viewer" and "without coming any closer" in one clause). On one character,
@@ -146,17 +144,12 @@ right, the way an isometric game's character walks down and up to the right (tur
left; a character with an item on one side has them drawn facing left instead, see
[handedness](#handedness--an-item-on-one-side)). A walk or run in one says where it heads on the screen in those words: "walks naturally in
place, as if on a treadmill, heading diagonally away from the viewer toward the upper right, like a
-character walking up and to the right in an isometric game. It
+character walking up and to the right in an isometric game, without moving across the screen. It
keeps the exact three-quarter back angle of the image the whole time: its back stays turned toward
the viewer at that angle and its face stays hidden. It never turns into a side view." (and "toward
the viewer and to the right … three-quarter front angle" for the front one). It is filmed pinned to
its first frame (`PINNED_GAIT_VIEWS`, `pins_last_frame`) with the return sentence, and cut as any
-walk (`--anchor motion-auto`). The view is said once: a walk or run seen from the front, from behind
-or at a diagonal says it in the gait sentence ("facing the viewer", "keeps the exact three-quarter
-back angle of the image"), so its prompt leaves the view sentence out (`GAIT_SAYS_VIEW`) and, with
-`--motion`, names `--character` on the gait hold instead ("The knight stays in place as if on a
-treadmill …"); a side gait keeps it ("The character is seen from the exact side, facing right."), and so does every other state,
-whose view sentence points at the image ("seen from a
+walk (`--anchor motion-auto`). The clip's view sentence points at the image ("seen from a
three-quarter back angle, turned exactly as in the image"); a still drawn at a diagonal from another
picture takes `STILL_VIEW_TEXT` instead (`still_view_text`), which says the whole body and head turn
about 45 degrees and which way the feet point — told less, a three-quarter back view came out as a
@@ -219,8 +212,7 @@ paragraph — whole sentences about the subject, such as a request interpreter w
request — in place of the built-in state sentence. The frame, camera, background and design
rules stay the engine's, and an attack keeps its `HOLD_TEXT` sentence after the paragraph. A
walk or run gets `GAIT_HOLD_TEXT` for its view after the paragraph instead: it stays in place as
-if on a treadmill and keeps facing the viewer or away from the viewer the whole time (a diagonal
-keeps the image's angle; a side view's facing is its view sentence's, said once),
+if on a treadmill and keeps facing the viewer, away from the viewer or `{facing}` the whole time,
so a caller describes the gait (a sneak, a march, a lazy stroll) and the engine keeps it on the
spot. On one character, one clip each: a march lifted the knees high as asked and stayed in
place, a lazy stroll seen from behind kept facing away, and a tiptoe sneak kept facing the viewer
@@ -278,10 +270,9 @@ sprite-gen video-frames --clip item/clip.mp4 --out-dir item/frames --spill auto
sprite-gen video-loop --frames-dir item/frames/keyed --out-dir item/loop --fps 24 --state walk --cycle auto --facing right --name side-walk
```
-The prompt is sent as printed. `sprite-gen video --direction side` does not add its side-view hold to
-it (it already says "seen from the exact side, facing right"), and refuses it when `--facing` is the
-other way. `--character` or `--motion` words that turn the subject another way than `--facing`, or put
-a `--handed` item on its other side, come back in `warnings` ([prompt-assembly](prompt-assembly.md)).
+`--character` or `--motion` words that turn the subject another way than `--facing`, or put a
+`--handed` item on its other side, come back in `warnings`; the prompt is the same either way
+([prompt-assembly](prompt-assembly.md)).
`video-prompt --json` also gives the duration (the state's own, as `video-set`), whether the clip
ends on the canvas (`last_frame`), the loop cut (`cycle`) and these commands with placeholders; a
@@ -338,12 +329,14 @@ item is on the other side — a mirrored still, or a side picture drawn the wron
`handed-check` first. A front or back picture, where the item's side is plain, is the safe reference.
**The far arm of a side view.** A side view hides the far side behind the body, except for what swings
-out from behind it: an arm or a leg (`handedness.limb` reads the body part — wrist, hand, arm, ankle,
-foot, …). A walking character's far arm comes forward of the body with every step, and what it wears
-shows then. So an item on a far limb is said to show wherever that limb is out in front of the body
-and to be hidden where the body covers it; a far part that does not swing (a pin on the far side of
-the head) is still said hidden. 2.22.0 said every far item hidden and never named it in the clip, and
-a watch on the far wrist was then in no frame of the side walk.
+out from behind it. A walking character's far arm comes forward of the body with every step, and what
+its wrist or hand wears shows then. So an item on a wrist, a hand, a forearm or an elbow
+(`handedness.limb`, the one table: `SWINGING_ARM_PARTS`) is said, on the far arm, to show wherever that
+arm is out in front of the body and to be hidden where the body covers it. Every other far item — on an
+ear, the head, a tail, the body, a leg, a shoulder, the upper arm — is said hidden, as in 2.22.0, and
+gets no arm sentence: a far shoulder stays behind the body as the character walks, and a leg's item
+showing as it steps forward was never filmed. 2.22.0 said every far item hidden and never named it in
+the clip, and a watch on the far wrist was then in no frame of the side walk.
A clip keeps what its first frame shows and makes up what it hides. For a walk or run with an item on
the far arm, draw the side still **mid-stride with both arms in view**, and say the pose in your
@@ -354,14 +347,15 @@ prompt — the engine's sentence says where the item shows, not how the characte
> near arm swings back past the body and shows whole
`video-prompt --json` names this under `still_needs` (and on stderr), and `video-set` under each
-item's `still_needs`, whenever a walk or run has an item on the far limb of a side view.
+item's `still_needs`, whenever a walk or run has an item on the far wrist or hand of a side view.
**The clip.** `video-prompt --handed …` and `video-set --handed …` end the clip prompt with where the
item stays (`build_prompt(handed=...)`). The clip starts from a still already drawn with the item in
place, so the sentence anchors to the image and names the item once, positively, where it shows: "The
black smartwatch stays on the wrist at the right of the picture, nearer the viewer, for the whole clip,
-exactly as in the image, and on no other wrist." In a side view's walk or run the arms are said to
-swing ("Both arms swing back and forth with each step, opposite to the legs."), and then:
+exactly as in the image, and on no other wrist." In a side view's walk or run with an item on a wrist,
+a hand, a forearm or an elbow, the arms are said to swing (`handedness.ARMS_SWING_TEXT`: "Both arms
+swing back and forth with each step, opposite to the legs."), and then:
- on the far arm: "The black smartwatch stays on the wrist that wears it in the image, on the arm on
the far side of the body, and shows each time that arm swings forward; the arm nearer the viewer
@@ -372,7 +366,7 @@ swing ("Both arms swing back and forth with each step, opposite to the legs."),
No sentence holds an arm still: the arms swing with the walk. The other arm is said bare, never as a
list of what it must not wear — a clip prompt that lists that draws it there. Where nothing brings the
-far side into view — a part that does not swing, or a state that does not step (idle, attack) — the
+far side into view — any other part, or a state that does not step (idle, attack) — the
item is not named at all: "The wrist nearer the viewer stays bare, exactly as in the image, for the
whole clip." A side view names the near part "nearer the viewer", not "in front of the body": in a
mid-stride still the far arm is the one in front of the body. Items on the same wrist share one sentence, and with an item on each wrist neither is
@@ -405,14 +399,15 @@ nothing else on the character has — a watch's screen — and checks every fram
arm is forward, and in a side view that share is what tells the two apart. Against `--reference` a
frame counts only when the item is more than a sliver (its largest blob larger than half the item
seen whole);
-- the far side of a side view, an item on an arm or a leg: every blob is out in front of the body —
- on the facing side of the body's centre by at least a tenth of the body's height (`far_in_front`).
- An item that shows at or behind the centre is on the near limb, the wrong one. With `--state walk`
- or `run` it must also show in at least a quarter of the frames (`far_shown`); without `--state`, or
- for a state that does not step, that is reported unchecked. Against `--reference` a sliver is not
- judged for where it is;
-- the far side of a side view, an item that does not swing: no blob larger than half the item seen
- whole on `--reference` (a keyed front or back picture; `far_hidden`).
+- the far side of a side view, an item on a wrist, a hand, a forearm or an elbow (`handedness.limb`):
+ every blob is out in front of the body — on the facing side of the body's centre by at least a tenth
+ of the body's height (`far_in_front`). An item that shows at or behind the centre is on the near arm,
+ the wrong one. With `--state walk` or `run` it must also show in at least a quarter of the frames
+ (`far_shown`); without `--state`, or for a state that does not step, that is reported unchecked.
+ Against `--reference` a sliver is not judged for where it is;
+- the far side of a side view, any other item (an anklet, a shoulder piece, a pin on the head): no
+ blob larger than half the item seen whole on `--reference` (a keyed front or back picture;
+ `far_hidden`).
Without `--reference` the size rules are not checked; the report says so (`far_hidden` /
`near_whole`: `checked: false`) and a frame counts as shown by any blob.
diff --git a/sprite_gen/gen/__init__.py b/sprite_gen/gen/__init__.py
index 4138ae8..9dba236 100644
--- a/sprite_gen/gen/__init__.py
+++ b/sprite_gen/gen/__init__.py
@@ -448,10 +448,8 @@ def generate_image(
verify_png(raw)
facing_report = None
if refs and facing is not None:
- retry = parts.replaced("facing", facing_mod.prompt_suffix(facing, retry=True, view=view is not None))
request, run, facing_report = facing_mod.prepare_correction(
- backend, request, run, workdir, facing=facing, fix=facing_fix, retry_prompt=retry.text,
- mirror_ok=not handed)
+ backend, request, run, workdir, facing=facing, fix=facing_fix, mirror_ok=not handed)
raw = request.raw
raw_bytes = verify_png(raw)
@@ -567,13 +565,12 @@ def _check_view(view: str | None, facing: str | None, facing_fix: str, handed: l
def still_prompt(prompt: str, *, view: str | None = None, facing: str | None = None,
handed: list[handed_mod.Handed] | None = None, refs: bool = False, key: str | None = None,
layout: dict[str, Any] | None = None) -> prompt_parts.Prompt:
- """The prompt a still is drawn from: the caller's text, then the engine's pieces, each said once
- (`prompt_parts.Prompt.add`). In order:
+ """The prompt a still is drawn from: the caller's text, then the engine's pieces (`prompt_parts.Prompt.add`;
+ without `handed`, 2.22.0's prompt to the byte). In order:
- `view` (`--direction`): the sentence for drawing the still at that view, turned to `facing` (the side and
diagonal views), then where each `handed` item is in it (`handedness.text`);
- - with `refs` and a `facing`: the turn over the reference (`facing.prompt_suffix`) — only which edge of the
- image the side is when the view sentence already said the turn;
+ - with `refs` and a `facing`: the turn over the reference (`facing.prompt_suffix`);
- `key` (green / magenta, a ref run `auto` planned to key): the key background line, unless the prompt
names a key background already;
- `layout` (the `--layout-guide` cell): where the guide's lines are.
@@ -588,7 +585,7 @@ def still_prompt(prompt: str, *, view: str | None = None, facing: str | None = N
if handed:
parts.add("handed", handed_mod.text(handed, view, facing), sep=" ", handed=handed)
if refs and facing is not None:
- parts.add("facing", facing_mod.prompt_suffix(facing, view=view is not None), facing=facing)
+ parts.add("facing", facing_mod.prompt_suffix(facing), facing=facing)
if key is not None:
parts.add("key-background", chroma_mod.KEY_BACKGROUND_TEXT[key], key=key)
if layout is not None:
diff --git a/sprite_gen/gen/chroma.py b/sprite_gen/gen/chroma.py
index 9d94beb..21af241 100644
--- a/sprite_gen/gen/chroma.py
+++ b/sprite_gen/gen/chroma.py
@@ -41,61 +41,23 @@ KEY_BACKGROUND_TEXT = {
}
-# Words a prompt puts between a key's name and "background", either way round: "a pure magenta flat
-# background", "a background of solid green".
-_KEY_FILLER = r"(?:(?:an?|the|one|single|pure|solid|flat|plain|uniform|bright|vivid|perfectly|completely|entirely|fully)[\s,]+)*"
-_KEY_GROUND = r"(?:background|backdrop|screen|chroma[- ]?key)"
-# What rules a key out: a negation right before the key's name, with nothing between them but small
-# words ("no green screen", "without a magenta background", "never on #00FF00"). A negation of
-# something else in the same clause does not ("no shadow, on a magenta background").
-_KEY_NEGATION = re.compile(
- r"\b(?:no|not|never|without|avoid(?:ing|s)?|instead of|rather than|\w+n't)\s+"
- r"(?:(?:an?|the|any|on|in|against|over|with|use|using|be|to|pure|solid|flat|plain|uniform|bright)\s+){0,4}$",
- re.IGNORECASE)
-
-
def _key_background_pattern(key: str) -> re.Pattern[str]:
hex_code = "".join(f"{channel:02x}" for channel in KEYS[key]["target"])
- name = rf"{key}(?:[- ]colou?red)?"
- return re.compile(
- rf"(?<![0-9a-z])#?{hex_code}(?![0-9a-z])"
- # the name, then the ground: "green screen", "magenta-colored background", "magenta chroma-key fill"
- rf"|\b{name}[\s,]+(?:(?:flat|solid|plain|uniform|pure|key)[\s,]+)*{_KEY_GROUND}\b(?!-)"
- # the ground, then the name: "background of pure magenta", "backdrop: solid green"
- rf"|\b(?:background|backdrop)\s*(?:is|of|in|as|[:=])?\s+{_KEY_FILLER}{name}\b"
- # "keyed on magenta", "on a green key"
- rf"|\bkeyed\s+(?:on|to|against)\s+{_KEY_FILLER}{name}\b"
- rf"|\b(?:on|against|over)\s+{_KEY_FILLER}{name}\s+key\b",
- re.IGNORECASE)
-
-
-def _key_backgrounds(prompt: str) -> list[tuple[int, str, bool]]:
- """(where, key, ruled out) for every place `prompt` names a key as its background."""
- found = []
- for key in KEYS:
- for match in _key_background_pattern(key).finditer(prompt):
- found.append((match.start(), key, bool(_KEY_NEGATION.search(prompt[:match.start()]))))
- return sorted(found)
+ return re.compile(rf"(?<![0-9a-z])#?{hex_code}(?![0-9a-z])"
+ rf"|\b{key}\s+(?:chroma[- ]?key|key|screen|background|backdrop)\b", re.IGNORECASE)
def named_key_background(prompt: str) -> str | None:
"""The key a prompt already asks for as its background, or None.
- A prompt names a key when it carries the key's hex code (`#FF00FF`, `00ff00`), the key's name
- before "background", "backdrop", "screen" or "chroma key" ("a green screen", "a magenta-colored
- background", "magenta chroma-key fill"), the name after one ("a background of pure magenta"), or
- "keyed on magenta" / "on a green key". A colour in the subject ("a green frog on white", "holding
- a green key") is not a key, and neither is one the prompt rules out ("no green screen", "without
- a magenta background": `ruled_out_key_backgrounds`). The first key asked for wins; the matte
- reads the key off the borders, so a prompt naming the other key than `--chroma-key` is keyed on
- the one drawn.
+ A prompt names a key when it carries the key's hex code (`#FF00FF`, `00ff00`) or the key's
+ name right before "background", "backdrop", "chroma key", "key" or "screen" ("a green
+ screen", "magenta chroma-key background"). A colour in the subject ("a green frog on
+ white") is not a key. The first key named wins; the matte reads the key off the borders,
+ so a prompt naming the other key than `--chroma-key` is keyed on the one drawn.
"""
- return next((key for _, key, ruled_out in _key_backgrounds(prompt) if not ruled_out), None)
-
-
-def ruled_out_key_backgrounds(prompt: str) -> set[str]:
- """The keys a prompt says its background is not ("no green screen")."""
- return {key for _, key, ruled_out in _key_backgrounds(prompt) if ruled_out}
+ found = [(match.start(), key) for key in KEYS if (match := _key_background_pattern(key).search(prompt))]
+ return min(found)[1] if found else None
# What a generated raw is, before a planned chroma key runs on it (`classify_raw_alpha`).
diff --git a/sprite_gen/gen/facing.py b/sprite_gen/gen/facing.py
index 0846c81..c58453e 100644
--- a/sprite_gen/gen/facing.py
+++ b/sprite_gen/gen/facing.py
@@ -44,22 +44,10 @@ def validate(facing: str, fix: str = "none") -> None:
raise SystemExit(f"facing: expected mirror, regen or none, got {fix!r}")
-def prompt_suffix(facing: str, *, retry: bool = False, view: bool = False) -> str:
- """The sentence that turns a subject drawn from a reference: which way, whatever way the reference is turned.
-
- `view`: the prompt already carries a view sentence that says the turn (`gen --direction`). The piece then
- says only what that sentence does not — which edge of the image the side is, over the reference — instead
- of the turn a second time; "facing left (toward the left edge)" after a three-quarter view sentence also
- asked for a full profile. `retry` is the correction after a drawing that came out turned the other way:
- it takes the first sentence's place in the prompt (`prompt_parts.Prompt.replaced`), not a line after it.
- """
+def prompt_suffix(facing: str, *, retry: bool = False) -> str:
validate(facing)
- lead = "CORRECTION REQUIRED: redraw the subject's orientation. " if retry else ""
- if view:
- return (lead + f"{facing.capitalize()} here means toward the {facing} edge of the image, regardless of the "
- "reference image's orientation. Preserve the subject's design.")
return (
- lead
+ ("CORRECTION REQUIRED: redraw the subject's orientation. " if retry else "")
+ f"The subject must be facing {facing} (toward the {facing} edge of the image), "
"regardless of the reference image's orientation. Preserve the subject's design."
)
@@ -113,13 +101,9 @@ def inspect(backend, path: Path, workdir: Path) -> dict:
return observation
-def prepare_correction(backend, request, run, workdir: Path, *, facing: str, fix: str, retry_prompt: str,
- mirror_ok: bool = True):
+def prepare_correction(backend, request, run, workdir: Path, *, facing: str, fix: str, mirror_ok: bool = True):
"""Observe raw; recheck one regeneration and mirror a remaining opposite.
- `retry_prompt` is the whole prompt of the regeneration: the request's, with its facing sentence
- replaced by the correction (`prompt_suffix(retry=True)`).
-
A non-lateral or failed recheck preserves the regenerated image with an
explicit reason. At most two vision calls and one regeneration are made.
`mirror_ok=False` (a character with a handed item) never mirrors: a still-opposite
@@ -138,7 +122,8 @@ def prepare_correction(backend, request, run, workdir: Path, *, facing: str, fix
else:
regenerated = workdir / "facing-regen.png"
regenerated.unlink(missing_ok=True)
- retry_request = replace(request, raw=regenerated, prompt=retry_prompt)
+ retry_request = replace(request, raw=regenerated,
+ prompt=request.prompt + "\n\n" + prompt_suffix(facing, retry=True))
retry_run = backend.generate(retry_request, workdir)
verify_png(regenerated)
# Keep both calls' billing evidence; top-level usage still describes the
diff --git a/sprite_gen/gen/handedness.py b/sprite_gen/gen/handedness.py
index 25d3469..babcfa7 100644
--- a/sprite_gen/gen/handedness.py
+++ b/sprite_gen/gen/handedness.py
@@ -22,11 +22,14 @@ A view turned to the right shows the character's right side; turned to the left,
own right side is the mirror of every row. A side view puts both arms over the middle of the body,
so it has no picture side, only near and far.
-The far side of a side view is hidden behind the body, except for what swings out from behind it:
-an arm or a leg (`limb`). A walking character's far arm comes forward of the body with every step,
-and what it wears shows then. An item on a far limb is therefore drawn and filmed as showing
-whenever that limb is out in front of the body, and the near limb stays bare. Said as hidden, and
-never named in the clip, a watch on the far wrist was in no frame of a walk at all (2.22.0).
+The far side of a side view is hidden behind the body, except for what swings out from behind it.
+A walking character's far arm comes forward of the body with every step, and what its wrist or hand
+wears shows then. An item there (`limb`: `SWINGING_ARM_PARTS`) is therefore drawn and filmed as
+showing whenever that arm is out in front of the body, and the near arm stays bare; a walk or run
+with one also says the arms swing (`ARMS_SWING_TEXT`). Said as hidden, and never named in the clip,
+a watch on the far wrist was in no frame of a walk at all (2.22.0). Every other part (an ear, the
+head, a tail, the body, a leg, a shoulder, the upper arm) keeps the 2.22.0 sentences: hidden on the far
+side, and no arm sentence for it.
"""
from __future__ import annotations
@@ -37,9 +40,11 @@ VIEWS = ("side", "front", "back", "front_diagonal", "back_diagonal")
# Views turned toward a side of the picture: each is drawn facing right or left.
LATERAL_VIEWS = frozenset({"side", "front_diagonal", "back_diagonal"})
SIDES = ("left", "right")
-# Body parts on a limb that swings with a step: in a side view the far one comes out in front of the body.
-ARM_WORDS = frozenset({"wrist", "hand", "arm", "forearm", "elbow", "palm", "finger", "fingers", "thumb", "knuckles"})
-LEG_WORDS = frozenset({"ankle", "foot", "leg", "knee", "shin", "calf", "thigh", "heel", "toes"})
+# The one table of which parts get the arm sentences: the wrist and the parts around it, which a walking
+# side view's far arm carries out in front of the body (the case filmed: a watch on the far wrist). A
+# shoulder or an upper arm stays behind the body, and a leg's item showing as it steps forward was never
+# filmed, so those keep the 2.22.0 sentences.
+SWINGING_ARM_PARTS = frozenset({"wrist", "hand", "forearm", "elbow", "palm", "finger", "fingers", "thumb", "knuckles"})
# A side walk or run with an item on an arm: the arms are said to swing, never held still. An arm held at
# the body keeps the item off the other arm but walks stiffly, and a far arm that does not swing never
# brings its item into view.
@@ -65,10 +70,10 @@ class Handed:
def limb(part: str) -> str | None:
- """"arm" or "leg" when `part` is on a limb that swings with a step ("wrist", "upper arm", "ankle"), else None
- (a side of the head, a shoulder, a hip: on the far side these stay behind the body)."""
- words = set(part.lower().split())
- return "arm" if words & ARM_WORDS else "leg" if words & LEG_WORDS else None
+ """"arm" when `part` is on the swinging end of an arm (`SWINGING_ARM_PARTS`: "wrist", "left hand"), else None
+ (an ear, the head, a tail, a leg, a shoulder: on the far side these stay behind the body, and an item there
+ gets no arm sentence)."""
+ return "arm" if set(part.lower().split()) & SWINGING_ARM_PARTS else None
def parse(spec: str) -> Handed:
@@ -150,11 +155,11 @@ def _clip_clause(group: list[Handed], view: str, facing: str | None, *, gait: bo
"""The items on one part of one side (`group`), in a clip. The clip starts from a still already drawn with
them in place, so the sentence anchors to the image and says them positively, once, where they show.
- A side view's far limb in a walk or run (`gait`) shows what it wears each time it swings forward, and the
- sentence says so: left unnamed, a watch on the far wrist was in no frame of the walk. The near limb is said
- bare (`other_bare`: nothing of the caller's is on it), never as a list of what it must not wear — a clip
- prompt that lists that draws it there. Where nothing brings the far side into view (a part that does not
- swing, a state that does not step) the items are not named at all, only that the near part stays bare.
+ A side view's far arm in a walk or run (`gait`) shows what its wrist or hand wears each time it swings forward
+ (`limb`), and the sentence says so: left unnamed, a watch on the far wrist was in no frame of the walk. The
+ near arm is said bare (`other_bare`: nothing of the caller's is on it), never as a list of what it must not
+ wear — a clip prompt that lists that draws it there. Where nothing brings the far side into view (any other part, a state
+ that does not step) the items are not named at all, only that the near part stays bare.
"""
h = group[0]
at = placement(h.side, view, facing)
@@ -208,7 +213,7 @@ def text(items: list[Handed], view: str, facing: str | None = None, *, clip: boo
groups.setdefault((h.side, h.part), []).append(h)
clauses = [_clip_clause(group, view, facing, gait=gait, other_bare=(group[0].other, part) not in groups)
for (_, part), group in groups.items()]
- if gait and view == "side" and any(limb(h.part) == "arm" for h in items):
+ if gait and view == "side" and any(limb(h.part) for h in items):
# the far arm's item shows only if the arms swing: said outright, once, before where the items are
clauses.insert(0, ARMS_SWING_TEXT)
return " ".join(clause for clause in clauses if clause)
diff --git a/sprite_gen/gen/prompt_parts.py b/sprite_gen/gen/prompt_parts.py
index 8bf4b5f..fcc8369 100644
--- a/sprite_gen/gen/prompt_parts.py
+++ b/sprite_gen/gen/prompt_parts.py
@@ -1,16 +1,19 @@
# SPDX-License-Identifier: Apache-2.0
-"""Attaching the engine's sentences to a prompt: the one place that checks what is already said.
+"""Attaching the engine's sentences to a prompt: the one place pieces go on.
A prompt is the caller's own text and then the engine's pieces: the view sentence, the turn over a
-reference, where a handed item is, the key background line, the layout guide; for a clip the hold, the
-frame and camera rules, a Lite model's sentences and the side view's hold. Every piece goes on through
-`Prompt.add`, and a piece the prompt already says is not said again:
-
-- a sentence the prompt already carries, word for word, is dropped from the piece (a start still's prompt
- handed back to `gen --direction --handed`, a caller's motion paragraph that quotes an engine rule, two
- items whose sentences come out the same);
-- a piece whose topic the prompt already covers is left out whole (`ALREADY_SAID`: a key background the
- caller named, a side view the clip prompt already holds), and one the prompt rules out is refused.
+reference, where a handed item is, the key background line, the layout guide; for a clip the side view's
+hold. Every piece goes on through `Prompt.add`, and each goes on only where its condition holds:
+
+- every piece but the handed one goes on as 2.22.0 attached it. The prompts a character with no handed
+ item is drawn and filmed from are frozen at 2.22.0, to the byte (`tests/gen/test_prompt_freeze.py`); a
+ change to them waits for a before-and-after comparison on the app's default clip model;
+- the key background line is left out when the prompt already names a key background (`ALREADY_SAID`), as
+ 2.22.0 did;
+- the handed piece (`ONCE_ONLY`) drops a sentence the prompt already carries, word for word: a start still's
+ prompt handed back to `gen --direction --handed` already has it. Its arm sentences (the arms swing, the far
+ arm's item shows when that arm comes forward) are there only for an item on an arm
+ (`handedness.limb`).
The caller's text is never edited. Where it and a piece disagree (`facing left` in the text, `--facing
right` on the command) or it repeats what a piece says, `Prompt.notes` says which words, and the verb
@@ -20,10 +23,10 @@ prints them: the engine cannot tell which of the two the caller meant.
from __future__ import annotations
import re
-from dataclasses import dataclass, field
+from dataclasses import dataclass
from typing import Any, Callable
-from .chroma import named_key_background, ruled_out_key_backgrounds
+from .chroma import named_key_background
_SENTENCE_END = re.compile(r"(?<=[.!?])\s+")
@@ -56,42 +59,24 @@ def turns_said(text: str) -> list[tuple[str, str]]:
return [(match.group(0), match.group(1).lower()) for match in _TURN.finditer(text)]
-def _key_said(prompt: "Prompt", *, key: str | None = None, **_: Any) -> tuple[str, str] | None:
+def _key_said(prompt: "Prompt", **_: Any) -> tuple[str, str] | None:
named = named_key_background(prompt.text)
- if named:
- return f"the prompt already asks for a {named} key background", named
- if key is not None and key in ruled_out_key_backgrounds(prompt.text):
- raise SystemExit(f"prompt: the text rules out a {key} key background and the engine would ask for one; "
- "choose the other key or drop the line from the prompt")
- return None
-
-
-_SIDE_VIEW = re.compile(r"\bseen from the exact side, facing (left|right)\b", re.IGNORECASE)
-
-
-def _side_view_said(prompt: "Prompt", *, facing: str | None = None, **_: Any) -> tuple[str, str] | None:
- held = {match.group(1).lower() for match in _SIDE_VIEW.finditer(prompt.text)}
- if not held:
- return None
- if facing in ("left", "right") and held != {facing}:
- raise SystemExit(f"prompt: the text says the side view faces {' and '.join(sorted(held))} and the engine "
- f"would hold it facing {facing}; ask for the prompt and the clip with the same facing")
- return "the prompt already says the side view and its facing", facing or ""
+ return (f"the prompt already asks for a {named} key background", named) if named else None
# topic -> what in the prompt makes a piece on that topic unnecessary: (why, what was found), or None.
-# A check raises SystemExit where the prompt says the opposite of the piece in the engine's own words.
ALREADY_SAID: dict[str, Callable[..., tuple[str, str] | None]] = {
"key-background": _key_said,
- "side-view": _side_view_said,
}
+# Topics whose sentences the prompt already carries are dropped from the piece. Only the handed piece: every
+# other piece is said as 2.22.0 said it, a repeat included.
+ONCE_ONLY = frozenset({"handed"})
@dataclass(frozen=True)
class Piece:
"""One engine piece and what became of it: attached whole, attached without the sentences the prompt
- already had (`why`), or left out (`added` False, `why`, and `found` — the key the prompt named). `asked`
- and `params` are what `add` was given, so `Prompt.replaced` can put the piece on again."""
+ already had (`why`), or left out (`added` False, `why`, and `found` — the key the prompt named)."""
topic: str
text: str
@@ -99,8 +84,6 @@ class Piece:
added: bool
why: str = ""
found: str = ""
- asked: str = ""
- params: dict[str, Any] = field(default_factory=dict, compare=False)
class Prompt:
@@ -122,16 +105,16 @@ class Prompt:
return next((piece for piece in self.pieces if piece.topic == topic), None)
def add(self, topic: str, text: str, *, sep: str | None = None, **params: Any) -> Piece:
- """Attach `text` as the piece on `topic` unless the prompt already says it. `params` are what the piece
- claims (`facing`, `key`, `handed`): they feed `ALREADY_SAID` and the notes on the caller's text."""
+ """Attach `text` as the piece on `topic`: left out where `ALREADY_SAID` finds it said, without the sentences
+ the prompt already has for a `ONCE_ONLY` topic, else as given. `params` are what the piece claims
+ (`facing`, `key`, `handed`): they feed `ALREADY_SAID` and the notes on the caller's text."""
sep = self.sep if sep is None else sep
- asked = text
why = found = ""
said = ALREADY_SAID[topic](self, **params) if topic in ALREADY_SAID else None
if said:
why, found = said
text = ""
- elif text:
+ elif text and topic in ONCE_ONLY:
have = {_same(sentence) for sentence in sentences(self.text)}
kept = []
for sentence in sentences(text):
@@ -141,23 +124,12 @@ class Prompt:
if len(kept) != len(sentences(text)):
why = "the prompt already has " + ("these sentences" if not kept else "some of these sentences")
text = " ".join(kept)
- piece = Piece(topic=topic, text=text, sep=sep, added=bool(text), why=why, found=found, asked=asked, params=params)
+ piece = Piece(topic=topic, text=text, sep=sep, added=bool(text), why=why, found=found)
self.pieces.append(piece)
if piece.added:
self.note(**params)
return piece
- def replaced(self, topic: str, text: str, **params: Any) -> "Prompt":
- """The same prompt with the piece on `topic` taken out and `text` said last in its place (a correction
- of a sentence replaces it; said after it, the prompt would carry the sentence twice)."""
- out = Prompt(self.own, caller=self.caller, sep=self.sep)
- old = self.piece(topic)
- for piece in self.pieces:
- if piece.topic != topic:
- out.add(piece.topic, piece.asked, sep=piece.sep, **piece.params)
- out.add(topic, text, **{**(old.params if old else {}), **params})
- return out
-
def note(self, *, facing: str | None = None, handed: list[Any] | None = None, **_: Any) -> None:
"""Note what the caller's text says against, or again after, a piece that turns the subject to `facing`
(right, left, or `NO_TURN` for a front or back view) or puts the `handed` items on their sides. `add`
diff --git a/sprite_gen/gen/video.py b/sprite_gen/gen/video.py
index 9aa3f68..10d3c30 100644
--- a/sprite_gen/gen/video.py
+++ b/sprite_gen/gen/video.py
@@ -483,9 +483,8 @@ def _submit_poll_publish(
def side_view_prompt(prompt: str, facing: str) -> prompt_parts.Prompt:
- """`--direction side`: the prompt with the side view held for the whole clip. A prompt that already says
- the side view and this facing (`video-prompt`'s, `video-set`'s) is left as it is; one that says the other
- facing is refused."""
+ """`--direction side`: the prompt with the side view held for the whole clip, after whatever the prompt
+ already says (2.22.0's prompt to the byte). Words in the prompt that turn the subject are noted."""
parts = prompt_parts.Prompt(prompt)
parts.add("side-view", f"The subject stays in exact side view, facing {facing}. No turning around.", facing=facing)
return parts
@@ -515,7 +514,6 @@ def generate_video(
facing_report = None
if request.direction == "side":
- # before the facing inspection: a prompt that holds the other facing is refused unpaid
parts = side_view_prompt(request.prompt, request.facing)
for line in prompt_parts.note_lines(parts):
print(f"[video] {line}", file=sys.stderr)
diff --git a/sprite_gen/qa/handed.py b/sprite_gen/qa/handed.py
index aa5482e..a5f634a 100644
--- a/sprite_gen/qa/handed.py
+++ b/sprite_gen/qa/handed.py
@@ -12,12 +12,12 @@ each blob's centre is compared with the body's own centre (the mean x of its opa
of the larger; smaller ones are specks of compression tint) fails in every view;
- the near side of a diagonal view: the item must show in at least half the frames; of a side view, in at
least three quarters (a near arm is in view the whole walk; a far arm's item shows about half of it);
-- the far side of a side view, an item on an arm or a leg (`handedness.limb`): the limb swings out in front
- of the body with each step and the item shows then, whole. Every blob must be in front of the body —
- on the facing side of its centre by at least a tenth of the body's height — and with `--state walk` or
- `run` it must show in at least a quarter of the frames. An item that also shows at or behind the body's
- centre is on the near limb, the wrong one;
-- the far side of a side view, an item that does not swing (a pin on the far side of the head): hidden or a
+- the far side of a side view, an item on the swinging end of an arm (a wrist, a hand: `handedness.limb`):
+ the arm swings out in front of the body with each step and the item shows then, whole. Every blob must
+ be in front of the body — on the facing side of its centre by at least a tenth of the body's height — and
+ with `--state walk` or `run` it must show in at least a quarter of the frames. An item that also shows at
+ or behind the body's centre is on the near arm, the wrong one;
+- the far side of a side view, any other item (a pin on the far side of the head, an anklet): hidden or a
sliver — no blob may be larger than half the item seen whole, measured on `--reference` pictures of the
same character (front or back, the item in full view);
- the near side of a side view, against `--reference`: a frame shows the item only when it is more than
@@ -377,7 +377,7 @@ def add_arguments(parser: argparse.ArgumentParser) -> None:
parser.add_argument("--marker", required=True, help="#RRGGBB: a saturated colour of the item that nothing else on the character has")
parser.add_argument("--strap", help="#RRGGBB: the item's band colour (a watch strap, usually dark); a band of it with no marker on it, away from the marker, counts as another place the item shows. Use with --zone")
parser.add_argument("--zone", default="0,1", help="TOP,BOTTOM: the rows the item sits in, as fractions of the body's height from its top (default 0,1, the whole body); e.g. 0.5,0.9 for a wrist")
- parser.add_argument("--state", help="the loop's motion state (walk, run, idle, ...): in a walk or run of a side view, an item on the far arm or leg must show while that limb swings forward")
+ parser.add_argument("--state", help="the loop's motion state (walk, run, idle, ...): in a walk or run of a side view, an item on the far wrist or hand must show while that arm swings forward")
parser.add_argument("--reference", action="append", type=Path, default=[], help="a keyed front or back picture of the same character with the item in full view (repeatable): in a side view the far item must stay smaller than half of it, and the near item counts as shown only when larger")
parser.add_argument("--report", type=Path, help="write the report JSON here")
parser.add_argument("--board", type=Path, help="write the review board PNG here")
diff --git a/sprite_gen/video/batch.py b/sprite_gen/video/batch.py
index 9de2564..3da4240 100644
--- a/sprite_gen/video/batch.py
+++ b/sprite_gen/video/batch.py
@@ -121,8 +121,7 @@ HOLD_TEXT = {
}
# What stays put while a caller's own walk or run moves, by view: in place, and facing the way the image
# faces. A request interpreter may ask for any gait (a sneak, a march, a stroll); the engine keeps it on the
-# spot and turned the right way, as the built-in gait sentences do. That it does not move across the screen
-# is the frame sentence's to say (`COMMON_TEXT`), and a side view's facing the view sentence's.
+# spot and turned the right way, as the built-in gait sentences do. `{facing}` is the side view's.
GAIT_STATES = frozenset({"walk", "run"})
GAIT_HOLD_TEXT = {
"front": "It stays in place as if on a treadmill, without coming any closer, and keeps facing the viewer the whole time.",
@@ -130,27 +129,16 @@ GAIT_HOLD_TEXT = {
"It stays in place as if on a treadmill, without moving any farther away, and keeps facing away from the viewer "
"the whole time."
),
- "side": "It stays in place as if on a treadmill.",
+ "side": "It stays in place as if on a treadmill, without moving across the screen, and keeps facing {facing} the whole time.",
"front_diagonal": (
- "It stays in place as if on a treadmill and keeps the exact three-quarter front angle of the image the whole time, "
- "never turning into a side view."
+ "It stays in place as if on a treadmill, without moving across the screen, and keeps the exact three-quarter front "
+ "angle of the image the whole time, never turning into a side view."
),
"back_diagonal": (
- "It stays in place as if on a treadmill and keeps the exact three-quarter back angle of the image the whole time, "
- "its face hidden, never turning into a side view."
+ "It stays in place as if on a treadmill, without moving across the screen, and keeps the exact three-quarter back "
+ "angle of the image the whole time, its face hidden, never turning into a side view."
),
}
-# Views whose walk or run says the view itself, in the gait sentence (`VIEW_MOTION_TEXT`) or the gait hold above:
-# "facing the viewer", "keeps the exact three-quarter back angle of the image". Their clip prompt leaves the
-# view sentence ("The character is seen from ...") out, which said the same thing a second time. A side
-# view's gait says only that it stays in place, so its view sentence stays and carries the facing.
-GAIT_SAYS_VIEW = frozenset({"front", "back", "front_diagonal", "back_diagonal"})
-VIEW_SENTENCE = " The character is {view}."
-# With a caller's own motion paragraph, `--character` is named on the engine sentence that says the view: the
-# view sentence, or where that is left out, the gait hold ("A small fox ... stays in place ..." for "It stays").
-# Every view that leaves its view sentence out has a gait hold to name it on.
-GAIT_HOLD_SUBJECT = "It "
-assert GAIT_SAYS_VIEW <= GAIT_HOLD_TEXT.keys() and all(text.startswith(GAIT_HOLD_SUBJECT) for text in GAIT_HOLD_TEXT.values())
MOTION_TEXT = {
# A side-view full body asked for "a subtle weight sway" and an evenly paced loop steps in place
# more often than not, so the feet are held and walking is named as what not to do.
@@ -160,8 +148,8 @@ MOTION_TEXT = {
"hair and loose cloth, and one natural blink if the face has eyes. The feet never lift, step, shuffle or slide "
"— no walking, no marching in place, no turning."
),
- "walk": "walks naturally in place, as if on a treadmill.",
- "run": "runs naturally in place, as if on a treadmill.",
+ "walk": "walks naturally in place, as if on a treadmill, without moving across the screen.",
+ "run": "runs naturally in place, as if on a treadmill, without moving across the screen.",
"jump": "performs a modest vertical hop in place over and over: compress, spring up about half the body height, land softly, return to the exact starting stance, repeat at an even rhythm. Same height every time.",
"attack": (
"performs one melee attack with what it is already holding (bare hands only if it holds nothing), keeping "
@@ -180,8 +168,7 @@ MOTION_TEXT = {
# "walks naturally" swung the arms and kept the knees low (2.15). 2.16 gives the run and the side view the
# same form. How a character walks is the caller's to say (`build_prompt(motion=...)`, held in place by
# `GAIT_HOLD_TEXT`); the engine's default stays generic. "as if on a treadmill" keeps the treadmill a
-# comparison: said as a place, it was sometimes drawn under the feet. A side or diagonal gait no longer adds
-# "without moving across the screen": the frame sentence says it ("does not move across the screen").
+# comparison: said as a place, it was sometimes drawn under the feet.
VIEW_MOTION_TEXT = {
("walk", "front"): "walks naturally in place, facing the viewer, as if on a treadmill, without coming any closer.",
("walk", "back"): (
@@ -198,23 +185,23 @@ VIEW_MOTION_TEXT = {
# view drawn facing left heads down or up and to the left (it said "to the right" whatever the facing).
("walk", "front_diagonal"): (
"walks naturally in place, as if on a treadmill, heading diagonally toward the viewer and to the {facing}, like a "
- "character walking down and to the {facing} in an isometric game. It keeps the "
+ "character walking down and to the {facing} in an isometric game, without moving across the screen. It keeps the "
"exact three-quarter front angle of the image the whole time and never turns into a side view."
),
("walk", "back_diagonal"): (
"walks naturally in place, as if on a treadmill, heading diagonally away from the viewer toward the upper {facing}, "
- "like a character walking up and to the {facing} in an isometric game. It keeps "
+ "like a character walking up and to the {facing} in an isometric game, without moving across the screen. It keeps "
"the exact three-quarter back angle of the image the whole time: its back stays turned toward the viewer at that "
"angle and its face stays hidden. It never turns into a side view."
),
("run", "front_diagonal"): (
"runs naturally in place, as if on a treadmill, heading diagonally toward the viewer and to the {facing}, like a "
- "character running down and to the {facing} in an isometric game. It keeps the "
+ "character running down and to the {facing} in an isometric game, without moving across the screen. It keeps the "
"exact three-quarter front angle of the image the whole time and never turns into a side view."
),
("run", "back_diagonal"): (
"runs naturally in place, as if on a treadmill, heading diagonally away from the viewer toward the upper {facing}, "
- "like a character running up and to the {facing} in an isometric game. It keeps "
+ "like a character running up and to the {facing} in an isometric game, without moving across the screen. It keeps "
"the exact three-quarter back angle of the image the whole time: its back stays turned toward the viewer at that "
"angle and its face stays hidden. It never turns into a side view."
),
@@ -307,7 +294,7 @@ def clip_prompt_parts(direction: str, state: str, character: str | None, facing:
motion, written as whole sentences about the subject (a request interpreter's output, for
instance). What stays put (`HOLD_TEXT`; for a walk or run, in place and facing the image's way,
`GAIT_HOLD_TEXT`), the repeat count (`REPEAT_TEXT`) and the frame, camera, background and
- design rules stay the engine's, and a rule the paragraph already quotes is not said again.
+ design rules stay the engine's.
`pinned` says the clip is pinned to end on its first frame (`video --last-frame`): it then asks
for the return to the first pose instead of an evenly paced repeat (`PINNED_LOOP_TEXT`). None
@@ -318,8 +305,9 @@ def clip_prompt_parts(direction: str, state: str, character: str | None, facing:
clause after the built-in walk sentence (`LITE_WALK_TEXT`; a caller's own motion is left as
written), and a Lite walk in a view where its head sways gets `LITE_HEAD_TEXT`.
- `handed` lists the character's asymmetric items (`handedness.parse`): the prompt ends with where each
- one stays, anchored to the first frame (`handedness.text(clip=True)`).
+ Without `handed` the prompt is 2.22.0's, to the byte (`tests/gen/test_prompt_freeze.py`). `handed` lists
+ the character's asymmetric items (`handedness.parse`): the prompt ends with where each one stays, anchored
+ to the first frame (`handedness.text(clip=True)`), the one piece `prompt_parts.Prompt.add` checks.
"""
validate_facing(facing)
view = VIEW_TEXT.get(direction, f"seen from the {direction}").format(facing=facing)
@@ -330,49 +318,42 @@ def clip_prompt_parts(direction: str, state: str, character: str | None, facing:
template = PINNED_LOOP_TEXT
else:
template = COMMON_TEXT
- says_view = state in GAIT_STATES and direction in GAIT_SAYS_VIEW
- if says_view:
- template = template.replace(VIEW_SENTENCE, "")
if motion is not None:
motion = " ".join(motion.split())
if not motion:
raise SystemExit("video: motion description is empty")
- head = "2D game sprite animation. The character {motion}"
- subject = character.strip().rstrip(".") if character else None
- parts = prompt_parts.Prompt(f"2D game sprite animation. {motion}", caller=f"{motion} {character or ''}", sep=" ")
- if state in HOLD_TEXT:
- parts.add("hold", HOLD_TEXT[state])
+ head = "2D game sprite animation. The character {motion} The character is {view}."
+ hold = f" {HOLD_TEXT[state]}" if state in HOLD_TEXT else ""
if state in GAIT_STATES and direction in GAIT_HOLD_TEXT:
- hold = GAIT_HOLD_TEXT[direction].format(facing=facing)
- if says_view and subject: # the hold says the view: it names the character (`GAIT_HOLD_SUBJECT`)
- hold = f"{subject} {hold[len(GAIT_HOLD_SUBJECT):]}"
- parts.add("gait-hold", hold)
- if state in REPEAT_TEXT:
- parts.add("repeat", REPEAT_TEXT[state])
- frame = template[len(head):].replace(VIEW_SENTENCE, f" {subject or 'The character'} is {view}.", 1)
- parts.add("frame", frame.strip(), facing=turned or prompt_parts.NO_TURN)
+ hold += f" {GAIT_HOLD_TEXT[direction].format(facing=facing)}"
+ repeat = f" {REPEAT_TEXT[state]}" if state in REPEAT_TEXT else ""
+ subject = character.strip().rstrip(".") if character else "The character"
+ text = (f"2D game sprite animation. {motion}{hold}{repeat} {subject} is {view}." + template[len(head):]
+ + _lite_text(state, direction, model, built_in=False))
+ caller = f"{motion} {character or ''}"
else:
built_in = (VIEW_MOTION_TEXT[(state, direction)].format(facing=facing) if (state, direction) in VIEW_MOTION_TEXT
else MOTION_TEXT.get(state, f"performs the '{state}' action in place, repeating at an even rhythm."))
text = template.format(motion=built_in, view=view)
- parts = prompt_parts.Prompt(text.replace("The character", character, 1) if character else text,
- caller=character or "", sep=" ")
- parts.note(facing=turned or prompt_parts.NO_TURN)
- if character and character.strip().rstrip(".") not in parts.text:
- raise AssertionError(f"video: the {state} {direction} clip prompt lost the character ({character!r})")
- for topic, text in _lite_pieces(state, direction, model, built_in=motion is None):
- parts.add(topic, text)
+ text = ((text.replace("The character", character, 1) if character else text)
+ + _lite_text(state, direction, model, built_in=True))
+ caller = character or ""
+ parts = prompt_parts.Prompt(text, caller=caller, sep=" ")
+ # the caller's words against the view the engine's sentence turns the clip to (a note, never an edit)
+ parts.note(facing=turned or prompt_parts.NO_TURN)
if handed:
parts.add("handed", handed_mod.text(handed, direction, turned, clip=True, gait=state in GAIT_STATES), handed=handed)
return parts
-def _lite_pieces(state: str, direction: str, model: str | None, *, built_in: bool) -> list[tuple[str, str]]:
+def _lite_text(state: str, direction: str, model: str | None, *, built_in: bool) -> str:
"""What a Lite walk adds after the prompt, in the order it was measured: the calm walk, then the head."""
if state != "walk" or not is_lite(model):
- return []
- return ([("lite-walk", LITE_WALK_TEXT)] if built_in else []) + (
- [("lite-head", LITE_HEAD_TEXT[direction])] if direction in LITE_HEAD_TEXT else [])
+ return ""
+ text = f" {LITE_WALK_TEXT}" if built_in else ""
+ if direction in LITE_HEAD_TEXT:
+ text += f" {LITE_HEAD_TEXT[direction]}"
+ return text
# A walk seen from the front or from behind starts from a still redrawn mid-step. From a standing
@@ -414,11 +395,12 @@ def walk_start_prompt(direction: str, key: str | None = None, handed: list[Hande
then with `handed` where each asymmetric item is in this view (`handedness.text`, the still's sentences)."""
if direction not in WALK_START_TEXT:
raise SystemExit(f"video: no mid-step start still for the {direction} view (only {', '.join(WALK_START_TEXT)})")
- parts = prompt_parts.Prompt(WALK_START_TEXT[direction], caller="", sep=" ")
+ text = WALK_START_TEXT[direction]
if key is not None:
if key not in KEY_BACKGROUND_TEXT:
raise SystemExit(f"video: a mid-step start still is drawn on a green or magenta key, not {key!r}")
- parts.add("key-background", KEY_BACKGROUND_TEXT[key], key=key)
+ text += f" {KEY_BACKGROUND_TEXT[key]}"
+ parts = prompt_parts.Prompt(text, caller="", sep=" ")
if handed:
parts.add("handed", handed_mod.text(handed, direction), handed=handed)
return parts.text
diff --git a/tests/fixtures/prompts-v2.22.0.json.gz b/tests/fixtures/prompts-v2.22.0.json.gz
new file mode 100644
index 0000000..3fc6d99
Binary files /dev/null and b/tests/fixtures/prompts-v2.22.0.json.gz differ
diff --git a/tests/gen/prompt_freeze_table.py b/tests/gen/prompt_freeze_table.py
new file mode 100644
index 0000000..a69354a
--- /dev/null
+++ b/tests/gen/prompt_freeze_table.py
@@ -0,0 +1,264 @@
+# SPDX-License-Identifier: Apache-2.0
+"""Every prompt the engine sends without `--handed`, drawn through the verbs' own entry points.
+
+The prompts a character with no handed item is drawn and filmed from are frozen at 2.22.0 (tag
+`013355b`): a change to them is made only after a before-and-after comparison on the app's default
+clip model shows it is better, never as a side effect of the handed sentences. This table is that
+freeze's evidence. It draws every prompt with entry points 2.22.0 already had — `batch.build_prompt`
+(a clip, built-in or `--motion`, every model and pin), `clip_prompt.plan_prompt` (`video-prompt`),
+`gen.generate_image` (a still: view, facing, reference, key line, layout guide, and the
+`--facing-fix regen` regeneration), `video.generate_video` (`--direction side`) and
+`batch.walk_start_prompt` (the mid-step redraw) — so the same code runs against the tag's source and
+records what it sent.
+
+Only the prompt strings are recorded: the notes and warnings a verb prints beside a prompt are not
+part of the freeze.
+
+Record (from the repo root, the tag's source unpacked somewhere):
+
+ git archive 013355b | tar -x -C /tmp/sprite-gen-2.22.0
+ python tests/gen/prompt_freeze_table.py /tmp/sprite-gen-2.22.0 tests/fixtures/prompts-v2.22.0.json.gz
+
+`tests/gen/test_prompt_freeze.py` draws the table again against this tree and compares.
+"""
+
+from __future__ import annotations
+
+import contextlib
+import gzip
+import io
+import itertools
+import json
+import sys
+import tempfile
+from pathlib import Path
+from typing import Any, Callable, Iterator
+
+DIRECTIONS = ("side", "front", "back", "front_diagonal", "back_diagonal")
+LATERAL = ("side", "front_diagonal", "back_diagonal")
+FACINGS = ("right", "left")
+# the built-in states, and one the engine has no sentence for
+STATES = ("idle", "walk", "run", "jump", "attack", "cheer")
+CHARACTER = "A small fox adventurer in a green cloak"
+MOTIONS = {
+ "built-in": None,
+ "own": "The fox walks with a cheerful bounce, swinging both arms.",
+ "quotes-engine": "The fox walks with a cheerful bounce. Camera completely locked, no zoom, no pan, no reframing.",
+ "says-turn": "The fox walks to the right with a cheerful bounce.",
+}
+CLIP_MODELS = {"default": None, "pro": "grok-imagine-video-1.5", "lite": "grok-imagine-video-1.5-lite"}
+SUBJECT = "A small fox adventurer, 2D game sprite, full body"
+# the caller's still text: plain, and what it may already say about the key or the turn
+STILL_TEXTS = {
+ "plain": f"{SUBJECT}.",
+ "names-key": f"{SUBJECT}, magenta chroma-key background.",
+ "names-key-green": f"{SUBJECT} on a green screen.",
+ "names-key-hex": f"{SUBJECT} on a flat #FF00FF background.",
+ "names-key-of": f"{SUBJECT}, on a background of pure magenta.",
+ "names-key-coloured": f"{SUBJECT}, magenta-colored background.",
+ "rules-out-key": f"{SUBJECT}, no green screen.",
+ "says-turn": f"{SUBJECT}, facing right.",
+ # the engine's own view and reference sentences, already in the text (a prompt handed on): said again
+ "quotes-engine": (f"{SUBJECT}. Seen from the exact side, facing right. The subject must be facing right (toward "
+ "the right edge of the image), regardless of the reference image's orientation. Preserve the "
+ "subject's design."),
+}
+FAKE_PNG_SIZE = (8, 8)
+
+
+def _error(exc: BaseException) -> str:
+ return f"!{type(exc).__name__}: {exc}"
+
+
+def clip_cases() -> Iterator[tuple[str, Callable[[], str]]]:
+ """`batch.build_prompt`: every view, facing, state, motion paragraph, clip model, pin and `--character`."""
+ from sprite_gen.video import batch
+
+ for direction, facing, state, motion, model, pinned, character in itertools.product(
+ DIRECTIONS, FACINGS, STATES, MOTIONS, CLIP_MODELS, (None, True, False), (None, CHARACTER)):
+ name = (f"clip/{direction}@{facing}/{state}/{motion}/{model}/pinned={pinned}/"
+ f"{'character' if character else 'no-character'}")
+ yield name, lambda d=direction, f=facing, s=state, m=MOTIONS[motion], mo=CLIP_MODELS[model], p=pinned, c=character: (
+ batch.build_prompt(d, s, c, facing=f, motion=m, pinned=p, model=mo))
+
+
+def video_prompt_cases() -> Iterator[tuple[str, Callable[[], str]]]:
+ """`video-prompt` (`clip_prompt.plan_prompt`): its `prompt`, with and without an end-frame pin."""
+ from sprite_gen.video import clip_prompt
+
+ for direction, facing, state, motion, model, pin, character in itertools.product(
+ DIRECTIONS, FACINGS, STATES, ("built-in", "own"), ("pro", "lite"), ("last-frame", "unpinned"),
+ (None, CHARACTER)):
+ name = f"video-prompt/{direction}@{facing}/{state}/{motion}/{model}/{pin}/{'character' if character else 'no-character'}"
+ yield name, lambda d=direction, f=facing, s=state, m=MOTIONS[motion], mo=CLIP_MODELS[model], p=pin, c=character: (
+ clip_prompt.plan_prompt(direction=d, state=s, facing=f, character=c, motion=m, model=mo,
+ last_frame=p == "last-frame", unpinned=p == "unpinned")["prompt"])
+
+
+def walk_start_cases() -> Iterator[tuple[str, Callable[[], str]]]:
+ """The mid-step start still's redraw prompt, with each key line."""
+ from sprite_gen.video import batch
+
+ for direction, key in itertools.product(batch.WALK_START_TEXT, (None, "green", "magenta")):
+ yield f"start-still/{direction}/{key}", lambda d=direction, k=key: batch.walk_start_prompt(d, k)
+
+
+class _Sent(Exception):
+ """Raised by the fake model once the prompt under test was sent: nothing after it is drawn."""
+
+
+def _png(path: Path) -> None:
+ from PIL import Image
+
+ Image.new("RGB", FAKE_PNG_SIZE, (255, 0, 255)).save(path)
+
+
+def _patched(obj: Any, name: str, value: Any) -> Iterator[None]:
+ old = getattr(obj, name)
+ setattr(obj, name, value)
+ try:
+ yield
+ finally:
+ setattr(obj, name, old)
+
+
+def _still(text: str, *, view: str | None, facing: str | None, refs: bool, transparent: bool, key: str,
+ layout: bool, regen: bool) -> str:
+ """The prompt(s) `gen` sends for one still: the first, and with `regen` the facing regeneration's after it."""
+ from sprite_gen import gen
+ from sprite_gen.gen import facing as facing_mod
+
+ sent: list[str] = []
+
+ class Backend:
+ name = "fake"
+ transparency = "native"
+
+ def generate(self, request, workdir):
+ sent.append(request.prompt)
+ if not regen or len(sent) > 1:
+ raise _Sent
+ _png(request.raw)
+ from sprite_gen.gen.base import ProviderRun
+
+ return ProviderRun(self.name, 1, model="fake-image", extra={})
+
+ opposite = "left" if facing == "right" else "right"
+ with tempfile.TemporaryDirectory() as tmp, \
+ _patched(gen, "_make_provider", lambda *a, **kw: Backend()), \
+ _patched(facing_mod, "inspect", lambda *a, **kw: {"direction": opposite, "confidence": 1.0}), \
+ contextlib.redirect_stderr(io.StringIO()):
+ ref = Path(tmp) / "ref.png"
+ _png(ref)
+ try:
+ gen.generate_image("fake", text, Path(tmp) / "out.png", refs=[ref] if refs else None, facing=facing,
+ facing_fix="regen" if regen else "none", view=view, transparent=transparent,
+ chroma_key=key, layout_guide=layout, aspect_ratio="3:4" if layout else None,
+ workdir=Path(tmp) / "work")
+ except _Sent:
+ pass
+ except SystemExit as exc:
+ return _error(exc)
+ return "\n\n=== regeneration ===\n\n".join(sent)
+
+
+def still_cases() -> Iterator[tuple[str, Callable[[], str]]]:
+ """`gen`: the caller's text with every view, facing, reference, key line and layout guide, and the facing
+ correction's regeneration."""
+ views = (None, *DIRECTIONS)
+ for user, view, facing, refs, transparent, layout in itertools.product(
+ STILL_TEXTS, views, (None, *FACINGS), (False, True), (False, True), (False, True)):
+ if facing is not None and view is not None and view not in LATERAL:
+ continue # refused for a front or back view: one row below says so
+ # the key line goes on only for a reference run `auto` keys; the other key only matters there
+ keys = ("magenta", "green") if refs and transparent else ("magenta",)
+ for key in keys:
+ for regen in ((False, True) if refs and facing else (False,)):
+ name = (f"still/{user}/{view}@{facing}/{'ref' if refs else 'text'}/"
+ f"{'transparent-' + key if transparent else 'opaque'}/{'layout' if layout else 'no-layout'}"
+ f"{'/regen' if regen else ''}")
+ yield name, lambda u=STILL_TEXTS[user], v=view, f=facing, r=refs, t=transparent, k=key, l=layout, g=regen: (
+ _still(u, view=v, facing=f, refs=r, transparent=t, key=k, layout=l, regen=g))
+ yield "still/plain/front@right/refused", lambda: _still(STILL_TEXTS["plain"], view="front", facing="right", refs=False,
+ transparent=False, key="magenta", layout=False, regen=False)
+
+
+def _side_video(prompt: str, facing: str) -> str:
+ from sprite_gen.gen import video as video_mod
+
+ sent: list[str] = []
+
+ def body(request, *_a, **_kw):
+ sent.append(request.prompt)
+ raise _Sent
+
+ with tempfile.TemporaryDirectory() as tmp, \
+ _patched(video_mod, "_build_generation_body", body), \
+ _patched(video_mod.facing_mod, "prepare_still", lambda image, corrected, **kw: _png(corrected) or {}), \
+ contextlib.redirect_stderr(io.StringIO()):
+ image = Path(tmp) / "still.png"
+ _png(image)
+ request = video_mod.VideoRequest(image=image, prompt=prompt, out=Path(tmp) / "clip.mp4", direction="side",
+ facing=facing)
+ try:
+ video_mod.generate_video(request, credential=object(), call=lambda *a, **kw: None)
+ except _Sent:
+ pass
+ except SystemExit as exc:
+ return _error(exc)
+ return sent[0]
+
+
+def side_video_cases() -> Iterator[tuple[str, Callable[[], str]]]:
+ """`video --direction side`: the caller's prompt, a `video-prompt` side walk handed on, and one turned the
+ other way."""
+ from sprite_gen.video import batch
+
+ for facing in FACINGS:
+ other = "left" if facing == "right" else "right"
+ prompts = {
+ "own": "The fox trots in place.",
+ "own-with-hold": f"The fox trots in place. The subject stays in exact side view, facing {facing}. No turning around.",
+ "video-prompt-walk": batch.build_prompt("side", "walk", CHARACTER, facing=facing),
+ "video-prompt-walk-other-facing": batch.build_prompt("side", "walk", CHARACTER, facing=other),
+ }
+ for label, prompt in prompts.items():
+ yield f"video-side/{facing}/{label}", lambda p=prompt, f=facing: _side_video(p, f)
+
+
+def cases() -> Iterator[tuple[str, Callable[[], str]]]:
+ for group in (clip_cases, video_prompt_cases, walk_start_cases, still_cases, side_video_cases):
+ yield from group()
+
+
+def draw() -> dict[str, str]:
+ """Every case's prompt, or `!Error: ...` where the verb refuses it."""
+ out = {}
+ for name, make in cases():
+ try:
+ out[name] = make()
+ except SystemExit as exc:
+ out[name] = _error(exc)
+ return out
+
+
+def write(path: Path, table: dict[str, str]) -> None:
+ data = json.dumps(table, ensure_ascii=False, indent=1, sort_keys=True).encode() + b"\n"
+ with open(path, "wb") as raw, gzip.GzipFile(fileobj=raw, mode="wb", mtime=0, filename="") as out:
+ out.write(data)
+
+
+def read(path: Path) -> dict[str, str]:
+ with gzip.open(path, "rb") as file:
+ return json.loads(file.read())
+
+
+if __name__ == "__main__":
+ source, target = Path(sys.argv[1]).resolve(), Path(sys.argv[2])
+ sys.path.insert(0, str(source))
+ import sprite_gen
+
+ assert Path(sprite_gen.__file__).resolve().is_relative_to(source), sprite_gen.__file__
+ write(target, draw())
+ print(f"{target}: {len(read(target))} prompts from {source}")
diff --git a/tests/gen/test_handedness.py b/tests/gen/test_handedness.py
index 5dc314c..3bb4f78 100644
--- a/tests/gen/test_handedness.py
+++ b/tests/gen/test_handedness.py
@@ -99,14 +99,57 @@ def test_the_clip_sentence_anchors_to_the_image_and_never_names_a_hidden_item(vi
def test_a_far_part_that_does_not_swing_stays_hidden() -> None:
"""A pin on the far side of the head has nothing to bring it into view: drawn hidden, never named in a clip."""
pin = [h.parse("the star pin=left side of the head")]
- assert h.limb("wrist") == "arm" and h.limb("upper arm") == "arm" and h.limb("ankle") == "leg"
- assert h.limb("side of the head") is None and h.limb("shoulder") is None and h.limb("") is None
+ assert h.limb("wrist") == "arm" and h.limb("hand") == "arm" and h.limb("forearm") == "arm" and h.limb("elbow") == "arm"
+ for part in ("side of the head", "ear", "side of the tail", "ankle", "leg", "shoulder", "upper arm", "arm", ""):
+ assert h.limb(part) is None, part
assert "on the far side, behind the body, so the star pin is hidden or at most a sliver of it shows" in h.text(pin, "side", "right")
for gait in (False, True):
clip = h.text(pin, "side", "right", clip=True, gait=gait)
assert clip == "The side of the head nearer the viewer stays bare, exactly as in the image, for the whole clip."
+# The arm sentences: the arms swing, and the far arm's item shows when that arm comes forward.
+ARM_WORDS_SAID = ("swing", "the far arm", "the arm nearer the viewer", "the arm on the far side", "the other arm",
+ "in front of the body", "reaches out")
+
+
+ "the red ribbon=left ear", "the gold bell=left side of the tail", "the star pin=left side of the head",
+ "the red anklet=left ankle", "the brass pauldron=left shoulder", "the cloth band=left upper arm",
+])
+def test_an_item_off_the_wrist_gets_no_arm_sentence(spec) -> None:
+ """Only an item on a wrist, a hand, a forearm or an elbow gets the arm sentences (`handedness.limb`, one
+ table). A ribbon on an ear, a bell on a tail, an anklet: the prompt is the one without --handed, then only
+ where that part's item is — in every view and state, walking or not, still or clip."""
+ item = [h.parse(spec)]
+ for (view, facing), state in ((pair, state) for pair in OWN_LEFT for state in ("walk", "run", "idle")):
+ clip = h.text(item, view, facing, clip=True, gait=state in batch_mod.GAIT_STATES)
+ still = h.text(item, view, facing)
+ assert not any(word in clip for word in ARM_WORDS_SAID), clip
+ assert not any(word in still for word in ARM_WORDS_SAID), still
+ assert h.first_frame_needs(item, view, facing, gait=state in batch_mod.GAIT_STATES) == []
+ plain = batch_mod.build_prompt(view, state, None, facing=facing or "right")
+ handed = batch_mod.build_prompt(view, state, None, facing=facing or "right", handed=item)
+ assert handed == (plain + " " + clip if clip else plain)
+ # on the far side of a side view it is hidden, and the clip names only the bare near part
+ assert "is hidden or at most a sliver of it shows" in h.text(item, "side", "right")
+ assert h.text(item, "side", "right", clip=True, gait=True).endswith("nearer the viewer stays bare, exactly as in the image, "
+ "for the whole clip.")
+
+
+def test_an_item_on_the_wrist_gets_the_arm_sentences_and_nothing_else_changes() -> None:
+ """The watch on the left wrist: a side walk or run says the arms swing and the far arm's item shows as it comes
+ forward; the rest of the prompt is the one without --handed, byte for byte."""
+ watch = [h.parse(WATCH)]
+ for facing, state in ((facing, state) for facing in ("right", "left") for state in ("walk", "run")):
+ plain = batch_mod.build_prompt("side", state, None, facing=facing)
+ handed = batch_mod.build_prompt("side", state, None, facing=facing, handed=watch)
+ assert handed.startswith(plain + " " + h.ARMS_SWING_TEXT + " ")
+ assert handed == plain + " " + h.text(watch, "side", facing, clip=True, gait=True)
+ assert "Wherever the far arm reaches out in front of the body" in h.text(watch, "side", "right")
+ assert h.ARMS_SWING_TEXT not in batch_mod.build_prompt("front", "walk", None, handed=watch)
+
+
def test_a_walk_shows_the_far_arms_item_when_that_arm_swings_forward() -> None:
"""2.22.0 never named a hidden item, and the far wrist's watch was in no frame of a side walk. A walk's far
arm comes forward with every step: the sentence says the item shows then, and that the near arm is bare."""
diff --git a/tests/gen/test_prompt_assembly.py b/tests/gen/test_prompt_assembly.py
index 82ae614..0658a3a 100644
--- a/tests/gen/test_prompt_assembly.py
+++ b/tests/gen/test_prompt_assembly.py
@@ -1,10 +1,13 @@
# SPDX-License-Identifier: Apache-2.0
-"""Every prompt the engine puts together, over the whole option table, drawn as text only.
-
-A prompt is the caller's text plus the engine's pieces (`sprite_gen.gen.prompt_parts`). The table below
-is every still, clip, start-still and correction prompt the options can make; each one is checked for a
-sentence said twice, for words that turn the subject both ways, for more than one key background, and
-for anything asked for (the caller's text, `--character`, a handed item, the key line) that never reached it.
+"""Every prompt the engine puts together with `--handed`, over the whole option table, drawn as text only.
+
+A prompt is the caller's text plus the engine's pieces (`sprite_gen.gen.prompt_parts`). Without `--handed`
+every prompt string is 2.22.0's, byte for byte (`test_prompt_freeze.py`). With it, the prompt is that same
+prompt with the handed piece put in: nothing else changes. The table below is every still, clip, start-still
+and correction prompt the options can make; each one is checked for that, for a handed sentence said twice,
+for a part called bare and dressed at once, for an arm said to swing in a state that does not step, for
+anything asked for (the caller's text, `--character`, a handed item, the key line) that never reached it, and
+for the notes on the caller's words.
A new option is a new row in a table here, not a new test.
The checks are written here, apart from the engine's own (`prompt_parts`), so they do not agree with it
@@ -24,22 +27,21 @@ from sprite_gen.gen import video as video_mod
from sprite_gen.video import batch, clip_prompt
FACINGS = ("right", "left")
-# --handed: none, one item, two on one wrist, one on each wrist
+# --handed: none, one item, two on one wrist, one on each wrist, one on an ear (no arm sentence)
HANDED = {
"none": None,
"watch": ["the black smartwatch=left wrist"],
"watch+bracelet": ["the black smartwatch=left wrist", "the gold bracelet=left wrist"],
"watch+ribbon": ["the black smartwatch=left wrist", "the red ribbon=right wrist"],
+ "ear-ribbon": ["the red ribbon=left ear"],
}
SUBJECT = "A small fox adventurer, 2D game sprite, full body"
# The caller's own text: what it already says about the key, the turn and the item. `turn` / `item` is
# the side its words name, to tell an agreeing repeat from a conflict with the options.
USER_TEXT = {
"plain": {"text": f"{SUBJECT}."},
- "names-key": {"text": f"{SUBJECT}, on a background of pure magenta.", "key": "magenta"},
- "names-key-coloured": {"text": f"{SUBJECT}, magenta-colored background.", "key": "magenta"},
+ "names-key": {"text": f"{SUBJECT}, magenta chroma-key background.", "key": "magenta"},
"names-key-hex": {"text": f"{SUBJECT} on a flat #FF00FF background.", "key": "magenta"},
- "rules-out-other-key": {"text": f"{SUBJECT}, no green screen."},
"says-turn": {"text": f"{SUBJECT}, facing right.", "turn": "right"},
"says-item-side": {"text": f"{SUBJECT}, wearing a black smartwatch on its left wrist.", "item": "left"},
"says-other-item-side": {"text": f"{SUBJECT}, wearing a black smartwatch on its right wrist.", "item": "right"},
@@ -55,6 +57,7 @@ MOTION = {
"quotes-engine": {"text": "The fox walks with a cheerful bounce. Camera completely locked, no zoom, no pan, no reframing."},
"says-turn": {"text": "The fox walks to the right with a cheerful bounce.", "turn": "right"},
}
+SIDE_HOLD = "\n\nThe subject stays in exact side view, facing {facing}. No turning around."
def _items(key: str) -> list[h.Handed] | None:
@@ -68,55 +71,50 @@ def _views() -> list[tuple[str, str | None]]:
def _still_rows():
for user, (view, facing), handed, refs in itertools.product(USER_TEXT, _views(), HANDED, (False, True)):
- parts = gen.still_prompt(USER_TEXT[user]["text"], view=view, facing=facing, handed=_items(handed), refs=refs,
- key="magenta" if refs else None)
- row = {"user": user, "facing": facing, "handed": handed}
- yield f"still/{user}/{view}@{facing}/{handed}/{'refs' if refs else 'text'}", parts, row
- if refs and facing: # the facing correction's regeneration
- retry = parts.replaced("facing", facing_mod.prompt_suffix(facing, retry=True, view=True))
- yield f"still-retry/{user}/{view}@{facing}/{handed}", retry, row
- # a reference run turned with --facing alone, no --direction, and its correction
+ make = lambda items, u=USER_TEXT[user]["text"], v=view, f=facing, r=refs: gen.still_prompt(
+ u, view=v, facing=f, handed=items, refs=r, key="magenta" if r else None)
+ row = {"user": user, "facing": facing, "handed": handed, "plain": make(None).text}
+ yield f"still/{user}/{view}@{facing}/{handed}/{'refs' if refs else 'text'}", make(_items(handed)), row
+ # a reference run turned with --facing alone, no --direction
for user, facing in itertools.product(USER_TEXT, FACINGS):
parts = gen.still_prompt(USER_TEXT[user]["text"], facing=facing, refs=True, key="magenta")
- row = {"user": user, "facing": facing, "handed": "none"}
- yield f"still/{user}/ref@{facing}", parts, row
- yield f"still-retry/{user}/ref@{facing}", parts.replaced("facing", facing_mod.prompt_suffix(facing, retry=True)), row
+ yield f"still/{user}/ref@{facing}", parts, {"user": user, "facing": facing, "handed": "none", "plain": parts.text}
def _clip_rows():
for (view, facing), handed, state, model, motion in itertools.product(_views(), HANDED, STATES, MODELS, MOTION):
if MOTION[motion]["text"] and state != "walk":
continue
- parts = batch.clip_prompt_parts(view, state, CHARACTER, facing=facing or "right",
- motion=MOTION[motion]["text"], model=MODELS[model], handed=_items(handed))
- row = {"user": None, "motion": motion, "facing": facing, "handed": handed, "state": state, "character": CHARACTER}
+ make = lambda items, v=view, s=state, f=facing or "right", m=MOTION[motion]["text"], mo=MODELS[model]: (
+ batch.clip_prompt_parts(v, s, CHARACTER, facing=f, motion=m, model=mo, handed=items))
+ parts = make(_items(handed))
+ row = {"user": None, "motion": motion, "facing": facing, "handed": handed, "state": state, "character": CHARACTER,
+ "plain": make(None).text}
yield f"clip/{view}@{facing}/{state}/{model}/{motion}/{handed}", parts, row
if view == "side": # handed on to `sprite-gen video --direction side`
yield (f"clip+video/{view}@{facing}/{state}/{model}/{motion}/{handed}",
- video_mod.side_view_prompt(parts.text, facing), row)
+ video_mod.side_view_prompt(parts.text, facing), {**row, "clip": parts})
def _start_still_rows():
for view, key, handed in itertools.product(batch.WALK_START_TEXT, chroma.KEY_BACKGROUND_TEXT, HANDED):
text = batch.walk_start_prompt(view, key, _items(handed))
- row = {"user": None, "facing": None, "handed": handed, "key": key}
+ row = {"user": None, "facing": None, "handed": handed, "key": key, "plain": batch.walk_start_prompt(view, key)}
yield f"start-still/{view}/{key}/{handed}", prompt_parts.Prompt(text, caller=""), row
# handed back to `gen --ref --transparent --direction --handed`, as an agent reading `video-prompt` may
again = gen.still_prompt(text, view=view, handed=_items(handed), refs=True, key=key)
- yield f"start-still+gen/{view}/{key}/{handed}", again, {**row, "own": text}
+ plain_again = gen.still_prompt(text, view=view, refs=True, key=key).text
+ yield f"start-still+gen/{view}/{key}/{handed}", again, {**row, "own": text, "plain": plain_again}
ROWS = [*_still_rows(), *_clip_rows(), *_start_still_rows()]
+_HANDED_ROWS = [r for r in ROWS if r[2]["handed"] != "none"]
# -- the checks ------------------------------------------------------------------------------------
_TURN_WORDS = re.compile(
r"\bfac(?:ing|es?) (right|left)\b|\bto the (right|left)\b|\btoward the (?:upper |lower )?(right|left)\b"
r"|\bthe (right|left) edge\b|\b(right|left) here means\b", re.IGNORECASE)
-_KEY_ASK = re.compile(
- r"#(?:ff00ff|00ff00)\b|\b(?:magenta|green)(?:[- ]colou?red)? (?:chroma-key )?(?:background|backdrop|screen)\b"
- r"|\bbackground of pure (?:magenta|green)\b", re.IGNORECASE)
-_KEY_RULED_OUT = re.compile(r"\bno (?:magenta|green) (?:background|screen)\b", re.IGNORECASE)
def _sentences(text: str) -> list[str]:
@@ -127,93 +125,109 @@ def _turns(text: str) -> set[str]:
return {next(side for side in match.groups() if side).lower() for match in _TURN_WORDS.finditer(text)}
-def _key_asks(text: str) -> int:
- return len(_KEY_ASK.findall(_KEY_RULED_OUT.sub(" ", text)))
+def _handed_text(parts: prompt_parts.Prompt) -> str:
+ piece = parts.piece("handed")
+ return piece.text if piece is not None and piece.added else ""
+
+
+def _without_handed(parts: prompt_parts.Prompt) -> str:
+ """The prompt with its handed piece taken out: the caller's text and every other piece, as put together."""
+ return parts.own + "".join(piece.sep + piece.text for piece in parts.pieces if piece.added and piece.topic != "handed")
def test_the_table_covers_every_place_a_prompt_is_put_together() -> None:
kinds = {name.split("/")[0] for name, _, _ in ROWS}
- assert kinds == {"still", "still-retry", "clip", "clip+video", "start-still", "start-still+gen"}
- assert len(ROWS) > 1000
+ assert kinds == {"still", "clip", "clip+video", "start-still", "start-still+gen"}
+ assert len(_HANDED_ROWS) > 1000
@pytest.mark.parametrize("name,parts,row", ROWS, ids=[name for name, _, _ in ROWS])
-def test_no_prompt_says_a_sentence_twice_turns_both_ways_or_asks_for_two_keys(name, parts, row) -> None:
- text = parts.text
- said = _sentences(text)
- assert len(said) == len(set(said)), sorted({s for s in said if said.count(s) > 1})
+def test_handed_puts_in_its_piece_and_changes_nothing_else(name, parts, row) -> None:
+ """With --handed the prompt is the one without it (2.22.0's) and the handed piece; without it, there is none."""
+ if name.startswith("clip+video"):
+ assert parts.text == row["clip"].text + SIDE_HOLD.format(facing=row["facing"])
+ return
+ if name.startswith("start-still/"):
+ handed = row["handed"] != "none"
+ assert parts.text == row["plain"] + (" " + h.text(_items(row["handed"]), name.split("/")[1]) if handed else "")
+ return
+ assert _without_handed(parts) == row["plain"], name
+ if row["handed"] == "none":
+ assert parts.piece("handed") is None and parts.text == row["plain"]
+
+
[email protected]("name,parts,row", _HANDED_ROWS, ids=[name for name, _, _ in _HANDED_ROWS])
+def test_no_handed_sentence_is_said_twice(name, parts, row) -> None:
+ said = _sentences(parts.text)
+ for sentence in _sentences(_handed_text(parts)):
+ assert said.count(sentence) == 1, (sentence, parts.text)
- assert _key_asks(text) <= 1, text
[email protected]("name,parts,row", ROWS, ids=[name for name, _, _ in ROWS])
+def test_the_notes_say_where_the_callers_words_turn_or_place_the_item_the_other_way(name, parts, row) -> None:
caller = {**USER_TEXT.get(row["user"] or "", {}), **MOTION.get(row.get("motion") or "", {})}
facing = row["facing"]
conflicts = {note["about"] for note in parts.notes if note["kind"] == "conflict"}
- if name.startswith("clip+video"):
- # the clip prompt handed on: its notes were the clip row's, and the side view is not held a second time
- assert parts.piece("side-view").added is False and parts.notes == []
- return
+ if name.startswith("clip+video") or name.startswith("start-still"):
+ return # the engine's own words handed on: the notes are the first verb's
if caller.get("turn") not in (None, facing):
# the caller's own words turn another way than the view: they are left as written, and the notes say so
assert "facing" in conflicts, name
- assert _turns(text.replace(caller["text"], "")) <= ({facing} if facing else set())
+ assert _turns(parts.text.replace(caller["text"], "")) <= ({facing} if facing else set())
else:
- assert _turns(text) <= ({facing} if facing else set()), (name, _turns(text))
+ assert _turns(parts.text) <= ({facing} if facing else set()), (name, _turns(parts.text))
assert "facing" not in conflicts
- if row["handed"] != "none" and caller.get("item") == "right":
+ if row["handed"] not in ("none", "ear-ribbon") and caller.get("item") == "right":
assert "handed" in conflicts, name # the smartwatch is --handed left
else:
assert "handed" not in conflicts, parts.notes
-_CLIP_ROWS = [r for r in ROWS if r[0].startswith("clip")]
+_CLIP_ROWS = [r for r in _HANDED_ROWS if r[0].startswith("clip/")]
# (a part or limb said bare, the same one said to wear an item): never both in one prompt
_BARE_AND_WORN = [
(r"\bThe (\w[\w ]*?) nearer the viewer stays bare\b", "stays? on the {0} nearer the viewer"),
- (r"\bthe (arm|leg) nearer the viewer stays bare\b", "on the {0} nearer the viewer"),
- (r"\bthe other (arm|leg), on the far side of the body, stays bare\b", "on the {0} on the far side of the body"),
+ (r"\bthe (arm) nearer the viewer stays bare\b", "on the {0} nearer the viewer"),
+ (r"\bthe other (arm), on the far side of the body, stays bare\b", "on the {0} on the far side of the body"),
]
@pytest.mark.parametrize("name,parts,row", _CLIP_ROWS, ids=[r[0] for r in _CLIP_ROWS])
def test_no_clip_calls_a_limb_bare_and_dressed_or_swings_an_arm_that_stands_still(name, parts, row) -> None:
- text = parts.text
+ text, handed = parts.text, _handed_text(parts)
for bare, worn in _BARE_AND_WORN:
for match in re.finditer(bare, text):
assert not re.search(worn.format(re.escape(match.group(1))), text), text
- # what the walk paragraph and the frame rules both said: in place across the screen, and the view
- assert len(re.findall(r"\bmov(?:e|ing) across the screen\b", text)) == 1, text
- for view_words in ("facing the viewer", "facing away from the viewer", "three-quarter front angle", "three-quarter back angle",
- "exact side"):
- assert text.count(view_words) <= 1, (view_words, text)
side = "/side@" in name
walks = row["state"] in batch.GAIT_STATES
- if not walks:
- # only a step swings a limb: an idle, a jump or an attack is never told that an arm swings
- assert "swing" not in text, text
- if row["handed"] != "none" and side and walks:
+ on_wrist = row["handed"] != "ear-ribbon"
+ # the arm sentences: only a stepping side view with an item on a wrist
+ assert (h.ARMS_SWING_TEXT in handed) is (side and walks and on_wrist), handed
+ assert ("swing" in handed) is (side and walks and on_wrist), handed
+ if side and walks and on_wrist:
# every item is on a wrist here: the far one is named and shows when its arm comes forward
far = "the red ribbon" if (row["handed"] == "watch+ribbon" and row["facing"] == "left") else "the black smartwatch"
if row["facing"] == "right" or row["handed"] == "watch+ribbon":
- assert "each time that arm swings forward" in text and far[4:] in text, text
- assert "The wrist nearer the viewer stays bare" not in text and "wrist in front of the body" not in text
- assert text.count("Both arms swing back and forth with each step") == 1
+ assert "each time that arm swings forward" in handed and far[4:] in handed, handed
+ assert "The wrist nearer the viewer stays bare" not in handed and "wrist in front of the body" not in handed
+ assert text.count(h.ARMS_SWING_TEXT) == 1
@pytest.mark.parametrize("name,parts,row", ROWS, ids=[name for name, _, _ in ROWS])
def test_every_part_asked_for_reaches_the_prompt(name, parts, row) -> None:
- """What the caller wrote and what the options ask for is in the prompt, whatever the engine left out as said
- twice. Since f899101 a front, back or diagonal walk with a caller's motion paragraph dropped its view sentence,
- and with it the only place `--character` was said."""
+ """What the caller wrote and what the options ask for is in the prompt."""
text = " ".join(parts.text.split())
asked = [USER_TEXT[row["user"]]["text"]] if row["user"] else []
asked += [MOTION[row["motion"]]["text"]] if row.get("motion") and MOTION[row["motion"]]["text"] else []
asked += [row["character"]] if row.get("character") else []
asked += [row["own"]] if row.get("own") else []
for item in _items(row["handed"]) or []:
- # the one item left unnamed on purpose: on the far side of a side view where nothing steps it into sight,
- # since a clip prompt that names a hidden item draws it on the near arm (docs/video-pipeline.md)
- hidden = (name.startswith("clip") and "/side@" in name and row["state"] not in batch.GAIT_STATES
+ # the one item left unnamed on purpose: on the far side of a side view where nothing steps it into sight
+ # (a state that does not step, a part off the wrist), since a clip prompt that names a hidden item draws
+ # it on the near arm (docs/video-pipeline.md)
+ hidden = (name.startswith("clip") and "/side@" in name
+ and (row["state"] not in batch.GAIT_STATES or not h.limb(item.part))
and h.placement(item.side, "side", row["facing"])["depth"] == "far")
if hidden:
assert _ARTICLE.sub("", item.item) not in text, text
@@ -231,90 +245,16 @@ def test_every_part_asked_for_reaches_the_prompt(name, parts, row) -> None:
_ARTICLE = re.compile(r"^(?:the|a|an)\s+", re.IGNORECASE)
[email protected]("name,parts,row", [r for r in ROWS if r[0].startswith("still")], ids=[r[0] for r in ROWS if r[0].startswith("still")])
-def test_a_still_carries_the_key_line_unless_its_text_names_a_key(name, parts, row) -> None:
- piece = parts.piece("key-background")
- if piece is None:
- return
- named = USER_TEXT[row["user"]].get("key")
- assert piece.added is (named is None) and piece.found == (named or "")
- assert (chroma.KEY_BACKGROUND_TEXT["magenta"] in parts.text) is (named is None)
-
-
# -- the known cases ---------------------------------------------------------------------------------
[email protected]("prompt,named", [
- ("a fox on a background of pure magenta", "magenta"),
- ("a fox, magenta-colored background", "magenta"),
- ("a fox, magenta coloured backdrop", "magenta"),
- ("background: solid green", "green"),
- ("a fox keyed on pure magenta", "magenta"),
- ("a fox drawn on a green key", "green"),
- ("a fox, no green screen", None),
- ("a fox without a green background", None),
- ("a fox, not on a magenta background", None),
- ("no green screen; use a magenta background", "magenta"),
- ("a fox with no shadow, on a magenta background", "magenta"),
- ("a knight holding a green key", None),
- ("a background of trees with green leaves", None),
- ("a hero in a green screen-printed shirt", None),
-])
-def test_a_key_background_is_read_however_it_is_worded_and_not_when_ruled_out(prompt: str, named: str | None) -> None:
- """2.22.0 missed "background of pure magenta" and "magenta-colored background", so the key line went on a
- second time, and read "no green screen" as asking for green, so no line went on at all."""
- assert chroma.named_key_background(prompt) == named
- key = "green" if "magenta" in chroma.ruled_out_key_backgrounds(prompt) else "magenta"
- parts = gen.still_prompt(prompt, refs=True, key=key)
- assert parts.piece("key-background").added is (named is None)
- assert parts.text.count("chroma-key fill (#") == (1 if named is None else 0)
-
-
-def test_a_key_the_text_rules_out_is_not_the_one_the_engine_asks_for() -> None:
- assert chroma.ruled_out_key_backgrounds("a fox, no green screen") == {"green"}
- with pytest.raises(SystemExit, match="rules out a green key background"):
- gen.still_prompt("a fox, no green screen", refs=True, key="green")
- # the text names the other key itself: nothing is added, so nothing is refused
- named = gen.still_prompt("no green screen; use a magenta background", refs=True, key="green")
- assert named.piece("key-background").found == "magenta" and not named.piece("key-background").added
-
-
-def test_a_turned_view_says_the_turn_once_and_the_reference_piece_only_pins_the_edge() -> None:
- """With --direction the view sentence says the turn. The reference piece said it again as a full profile
- ("facing left (toward the left edge of the image)"), against a three-quarter view's 45 degrees."""
- plain = gen.still_prompt("a fox", facing="left", refs=True)
- assert plain.text.endswith(facing_mod.prompt_suffix("left")) and "must be facing left" in plain.text
- for view in sorted(h.LATERAL_VIEWS):
- text = gen.still_prompt("a fox", view=view, facing="left", refs=True).text
- assert "must be facing" not in text
- assert text.endswith("Left here means toward the left edge of the image, regardless of the reference image's "
- "orientation. Preserve the subject's design.")
- front = gen.still_prompt("a fox", view="front", refs=True)
- assert front.piece("facing") is None
-
-
-def test_a_correction_takes_the_place_of_the_sentence_it_corrects() -> None:
- """The regeneration's prompt was the first prompt plus the correction: the facing sentence twice."""
- parts = gen.still_prompt("a fox", facing="right", refs=True, key="magenta")
- retry = parts.replaced("facing", facing_mod.prompt_suffix("right", retry=True)).text
- assert retry.count("The subject must be facing right") == 1 and retry.count("Preserve the subject's design.") == 1
- assert retry.endswith(facing_mod.prompt_suffix("right", retry=True))
- assert chroma.KEY_BACKGROUND_TEXT["magenta"] in retry
-
-
-def test_a_side_clip_is_held_once_and_a_prompt_turned_the_other_way_is_refused() -> None:
- prompt = batch.build_prompt("side", "walk", None, facing="left")
- assert video_mod.side_view_prompt(prompt, "left").text == prompt
- own = video_mod.side_view_prompt("The fox trots in place.", "left").text
- assert own == "The fox trots in place.\n\nThe subject stays in exact side view, facing left. No turning around."
- with pytest.raises(SystemExit, match="faces left .* facing right"):
- video_mod.side_view_prompt(prompt, "right")
-
-
-def test_an_engine_rule_the_motion_paragraph_quotes_is_not_said_again() -> None:
- rule = "Camera completely locked, no zoom, no pan, no reframing."
- text = batch.build_prompt("side", "walk", None, motion=f"The fox trots in place. {rule}")
- assert text.count(rule) == 1
- assert "Keep the design, colors and proportions exactly as in the image." in text
+def test_a_start_still_handed_back_to_gen_says_its_handed_sentences_once() -> None:
+ """The start still's prompt already carries the handed sentences; `gen --direction --handed` does not add
+ them a second time (the one piece `prompt_parts` checks for what is already said)."""
+ watch = h.parse_all(HANDED["watch"])
+ text = batch.walk_start_prompt("front", "green", watch)
+ again = gen.still_prompt(text, view="front", handed=watch, refs=True, key="green")
+ assert again.piece("handed").added is False
+ assert again.text.count(h.text(watch, "front")) == 1
def test_video_prompt_warns_when_the_callers_words_turn_the_other_way() -> None:
@@ -350,9 +290,13 @@ def test_gen_reports_what_the_callers_text_says_against_the_options(tmp_path, mo
def test_video_prompt_names_the_character_in_every_view_of_a_callers_walk() -> None:
- """f899101: a front, back or diagonal walk or run with --motion left its view sentence out, and with it
- --character; the prompt went out without the character and no warning said so."""
for view, state in itertools.product(h.VIEWS, batch.GAIT_STATES):
record = clip_prompt.plan_prompt(direction=view, state=state, character=CHARACTER, facing="right",
motion=MOTION["own"]["text"])
assert record["prompt"].count(CHARACTER) == 1, record["prompt"]
+
+
+def test_the_facing_correction_is_said_after_the_prompt_as_2_22_0_did() -> None:
+ """`--facing-fix regen` sends the first prompt and the correction after it (`facing.prepare_correction`)."""
+ assert facing_mod.prompt_suffix("left", retry=True).startswith("CORRECTION REQUIRED: redraw the subject's orientation. "
+ "The subject must be facing left")
diff --git a/tests/gen/test_prompt_freeze.py b/tests/gen/test_prompt_freeze.py
new file mode 100644
index 0000000..224077d
--- /dev/null
+++ b/tests/gen/test_prompt_freeze.py
@@ -0,0 +1,68 @@
+# SPDX-License-Identifier: Apache-2.0
+"""Without `--handed`, every prompt string the engine sends is 2.22.0's, to the byte.
+
+`prompt_freeze_table.py` draws each prompt a character with no handed item is drawn or filmed from — a clip
+(built-in or `--motion`, every model and pin), `video-prompt`, a still (view, facing, reference, key line,
+layout guide, the `--facing-fix regen` regeneration), `video --direction side` and the mid-step redraw — and
+`tests/fixtures/prompts-v2.22.0.json.gz` is that table drawn from the 2.22.0 tag's source (`013355b`). These
+tests draw it again against this tree.
+
+What is compared is the prompt strings only. The notes and warnings a verb prints beside a prompt (`gen`
+stderr and `extra.prompt_notes`, `video-prompt` `warnings` and `notes`, `video-set` `prompt_notes`) are not
+part of the freeze and may differ.
+"""
+
+from __future__ import annotations
+
+import difflib
+from pathlib import Path
+
+import pytest
+
+import prompt_freeze_table as table
+
+FIXTURE = Path(__file__).resolve().parents[1] / "fixtures" / "prompts-v2.22.0.json.gz"
+GROUPS = ("clip", "video-prompt", "start-still", "still", "video-side")
+
+
[email protected](scope="module")
+def frozen() -> dict[str, str]:
+ return table.read(FIXTURE)
+
+
[email protected](scope="module")
+def drawn() -> dict[str, str]:
+ return table.draw()
+
+
+def _first_difference(name: str, was: str, now: str) -> str:
+ diff = difflib.unified_diff(was.splitlines(), now.splitlines(), "2.22.0", "now", lineterm="", n=0)
+ return f"{name}:\n" + "\n".join(diff)
+
+
+def test_the_table_is_the_one_the_fixture_was_drawn_from(frozen, drawn) -> None:
+ assert sorted(drawn) == sorted(frozen)
+ assert {name.split("/")[0] for name in frozen} == set(GROUPS)
+ assert len(frozen) > 6000
+
+
[email protected]("group", GROUPS)
+def test_every_prompt_string_without_handed_is_2_22_0s_byte_for_byte(group, frozen, drawn) -> None:
+ names = [name for name in frozen if name.split("/")[0] == group]
+ changed = [name for name in names if drawn[name] != frozen[name]]
+ assert not changed, (f"{len(changed)} of {len(names)} {group} prompts differ from 2.22.0; first:\n"
+ + _first_difference(changed[0], frozen[changed[0]], drawn[changed[0]]))
+
+
+def test_the_default_walk_keeps_its_treadmill_and_screen_sentences(frozen, drawn) -> None:
+ """The built-in walk and run paragraphs are frozen with everything else: "as if on a treadmill" (kept in
+ place for a body without legs to read, a slime's bounce included), "without moving across the screen" in
+ the gait sentence as well as the frame sentence, and the view sentence after the gait sentence."""
+ for name, prompt in frozen.items():
+ if name.startswith("clip/") and name.split("/")[2] in ("walk", "run") and "/built-in/" in name:
+ assert "as if on a treadmill" in prompt and drawn[name] == prompt, name
+ side = drawn["clip/side@right/walk/built-in/default/pinned=None/no-character"]
+ assert "walks naturally in place, as if on a treadmill, without moving across the screen." in side
+ assert "The character is seen from the exact side, facing right." in side
+ front = drawn["clip/front@right/walk/built-in/default/pinned=None/no-character"]
+ assert "The character is seen from the front" in front
diff --git a/tests/qa/test_handed_check.py b/tests/qa/test_handed_check.py
index cbce530..8c8c061 100644
--- a/tests/qa/test_handed_check.py
+++ b/tests/qa/test_handed_check.py
@@ -134,6 +134,18 @@ def test_a_far_part_that_does_not_swing_keeps_the_hidden_rule() -> None:
assert not caught["ok"] and "on the far side" in caught["fails"][0]["why"][0]
[email protected]("spec", ["the red anklet=left ankle", "the brass pauldron=left shoulder", "the red ribbon=left ear"])
+def test_a_far_item_off_the_wrist_keeps_the_hidden_rule(spec) -> None:
+ """Only a wrist, hand, forearm or elbow swings its item into view (`handedness.limb`, the table the prompts
+ read): an anklet, a shoulder piece or an ear ribbon on the far side stays hidden or a sliver, as in 2.22.0."""
+ item = h.parse(spec)
+ frames = loop("near")
+ report = handed.check(frames, item=item, view="side", facing="right", marker=BLUE, state="walk",
+ references=[figure("right")])
+ assert "far_hidden" in report["rules"] and "far_in_front" not in report["rules"] and "far_shown" not in report["rules"]
+ assert not report["ok"] and "on the far side" in report["fails"][0]["why"][0]
+
+
def test_a_far_sliver_turned_over_is_not_the_near_item_shown() -> None:
"""Facing right, the far wrist's watch may show as a sliver as the arm swings. Turned over to face left,
that sliver is on the arm behind the body — the own right wrist, the wrong one — and the near wrist is
diff --git a/tests/video/test_video_pipeline.py b/tests/video/test_video_pipeline.py
index 58e0d1c..17fc224 100644
--- a/tests/video/test_video_pipeline.py
+++ b/tests/video/test_video_pipeline.py
@@ -500,13 +500,8 @@ def test_every_gait_walks_or_runs_naturally_in_place() -> None:
):
sentence = batch_mod.VIEW_MOTION_TEXT.get((state, direction)) or batch_mod.MOTION_TEXT[state]
p = batch_mod.build_prompt(direction, state, None)
- # a front or back gait says which way it faces itself, so the view sentence is not said after it
- template = batch_mod.COMMON_TEXT if direction == "side" else batch_mod.COMMON_TEXT.replace(batch_mod.VIEW_SENTENCE, "")
- assert p == template.format(motion=sentence, view=batch_mod.VIEW_TEXT[direction].format(facing="right"))
- assert ("The character is seen from" in p) is (direction == "side")
+ assert p == batch_mod.COMMON_TEXT.format(motion=sentence, view=batch_mod.VIEW_TEXT[direction].format(facing="right"))
assert sentence.startswith(opening) and sentence.count(".") == 1
- # that it does not move across the screen is the frame sentence's, once
- assert p.count("move across the screen") + p.count("moving across the screen") == 1
assert ", as if on a treadmill" in p
for gone in ("left-right", "on a treadmill:", "lifts and lands", "never turns to the side"):
assert gone not in p
@@ -523,16 +518,9 @@ def test_a_callers_gait_is_held_in_place_and_facing_the_images_way() -> None:
for state in ("walk", "run"):
p = batch_mod.build_prompt(direction, state, "The knight", "left", motion=sneak)
hold = batch_mod.GAIT_HOLD_TEXT[direction].format(facing="left")
- # the side view's facing is its view sentence's; a front or back hold says the view itself, and so
- # names the character in place of "It"
- view = f" The knight is {batch_mod.VIEW_TEXT[direction].format(facing='left')}." if direction == "side" else ""
- if direction != "side":
- hold = hold.replace("It ", "The knight ", 1)
- assert p.startswith(f"2D game sprite animation. {sneak} {hold}{view} Stays centered in the frame")
+ assert p.startswith(f"2D game sprite animation. {sneak} {hold} The knight is {batch_mod.VIEW_TEXT[direction].format(facing='left')}.")
assert batch_mod.MOTION_TEXT[state] not in p
- assert p.count("move across the screen") + p.count("moving across the screen") == 1
- assert batch_mod.GAIT_HOLD_TEXT["side"] == "It stays in place as if on a treadmill."
- assert "keeps facing the viewer the whole time" in batch_mod.GAIT_HOLD_TEXT["front"]
+ assert "keeps facing left the whole time" in batch_mod.GAIT_HOLD_TEXT["side"].format(facing="left")
jump = batch_mod.build_prompt("front", "jump", None, motion="The knight hops twice.")
assert all(text.split(",")[0] not in jump for text in batch_mod.GAIT_HOLD_TEXT.values())
@@ -558,9 +546,7 @@ def test_a_diagonal_walk_is_pinned_and_named_as_an_isometric_heading() -> None:
for state in ("walk", "run"):
sentence = batch_mod.VIEW_MOTION_TEXT[(state, direction)].format(facing="right")
p = batch_mod.build_prompt(direction, state, None)
- # the gait sentence keeps the image's angle itself: the view sentence is not said after it
- assert p == batch_mod.PINNED_LOOP_TEXT.replace(batch_mod.VIEW_SENTENCE, "").format(motion=sentence)
- assert "The character is seen from" not in p and p.count("three-quarter") == 1
+ assert p == batch_mod.PINNED_LOOP_TEXT.format(motion=sentence, view=batch_mod.VIEW_TEXT[direction])
assert heading in sentence and "never turns into a side view" in sentence
assert batch_mod.pins_last_frame(state, direction)
assert "turned exactly as in the image" in batch_mod.VIEW_TEXT[direction]