Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.
fix(logo): the text check keeps every mark written on a letter
Soohong Kim198c027beadf
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex d9e8d6d..0201304 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,10 +10,10 @@ All notable public changes to `sprite-gen` are recorded here. Versions track the- **Tests** — synthetic sheets cover the change: the two-way ambiguous sheet (512 × 768 px, seven 20 × 8 px frames, one dot on `pip_on` and squeezed `pip_off`) with an 18 px and a 60 px dot, refused by `split_ui_kit` and the CLI; the control sheet cut as `pip_off`; 512 sheets of small drawings and 256 sheets of full-size frames with small band drawings cut as drawn or refused as ambiguous, with three sheets previously refused as drifted now cut as drawn; each of the 256 sets of missing band elements under random accepted drifts; squeezes from the top by 0.90 to 0.99; a 17-sheet counterexample search; sheets refused as drifted further (20 % shorter), off-centre (dot in the gap), and required (each frame left out); a 2:3 sheet drawn on its guide with a mark 4 px wide and 20 px tall centred in the gap between the boxes of the two dots (`pip_on` above, `pip_off` below), refused as ambiguous (`pip_on, pip_off`); and 4 px scattered squares proved off the layout within 10 seconds. A square sheet and a 2:3 sheet drawn on their guide are cut byte for byte as before, with no `layout_fit`.- **Fix: the test suite runs on Windows.** `pyproject.toml` named pytest-timeout's `signal` method, and Windows has no SIGALRM, so pytest stopped with an internal error before its first test unless `-o timeout_method=thread` was given. The method is now left to pytest-timeout, which takes `signal` where SIGALRM exists (Linux, macOS: unchanged) and `thread` on Windows. Test: `tests/packaging/test_project_metadata.py`. `tests/video/test_one_step_cut.py` skips where img2webp is missing, as the other loop tests do, instead of failing all twelve of its tests.- **Fix: `sprite-gen prepare --request` keeps the request's `style`.** The subcommand declared its own copy of prepare's options, with `--style` defaulting to the default style sentence and `--cell-size` to 256, so a flag nobody gave counted as given: the request's `style` was replaced by the default sentence under a note that `--style, --cell-size` were given both ways (`scripts/prepare_sprite_run.py` and `prepare.run` were right). The subcommand now takes prepare's own declaration (`prepare.add_arguments`), which also gives it `--directions` and `--mirror`, missing until now. A request with no style and no cell still gets the default sentence and 256. Test: `tests/gen/test_flags_over_spec.py` (through `sprite-gen prepare`: a request alone keeps its style and cell with no note, a given `--style` wins and says so, the subcommand takes every option prepare declares).-- **New verb: `logo` makes a transparent typography logo from a mood image.** Lettering asked for alone comes back as a font with an effect; drawn into the picture it belongs to, it takes the scene's materials and light. `sprite-gen logo --text … --style …` letters the title (and an optional `--subtitle`, in an optional `--language`) into a 16:9 title screen or a 2:3 poster (`gen`), has the provider read its text back and refuses a title it dropped or misspelt before buying the next image, redraws only the lettering from that picture as an image edit on a chroma key (`gen --ref`), and cuts it out with the new logo matte, trimmed with a 2 px margin; the logo's text is read again and a logo whose letters differ is refused and kept aside as `logo.rejected.png`. Files: `mood.png`, `lettering.png`, `logo.png`, `logo.preview.png` (the logo on a dark and a light backdrop) and `logo.report.json` (status, every step's prompt and numbers, the alpha coverage, the key hue left, both text checks, and every call with its `route`: `subscription` or `per-call`). `--mood` starts from a picture you have; `--lettering` cuts a lettering image again with nothing generated. `--chroma-key auto` scores both keys on the colours in the title's box (the mood check returns it): a letter in a key's hue counts against it, and a key wins by how long a glow's mix with it keeps its hue. Nothing in the path draws a font ([logo](docs/logo.md)).+- **New verb: `logo` makes a transparent typography logo from a mood image.** Lettering asked for alone comes back as a font with an effect; drawn into the picture it belongs to, it takes the scene's materials and light. `sprite-gen logo --text … --style …` letters the title (and an optional `--subtitle`, in an optional `--language`) into a 16:9 title screen or a 2:3 poster (`gen`), has the provider read its text back and refuses a title it dropped or misspelt before buying the next image, redraws only the lettering from that picture as an image edit on a chroma key (`gen --ref`), and cuts it out with the new logo matte, trimmed with a 2 px margin; the logo's text is read again and a logo whose letters differ is refused and kept aside as `logo.rejected.png`. Both checks compare what the text spells: every letter and digit and every mark written on one (an accent, a vowel sign, a virama), with case, compatibility forms, the characters drawn as nothing, enclosing marks, spaces, punctuation and symbols folded away. Files: `mood.png`, `lettering.png`, `logo.png`, `logo.preview.png` (the logo on a dark and a light backdrop) and `logo.report.json` (status, every step's prompt and numbers, the alpha coverage, the key hue left, both text checks, and every call with its `route`: `subscription` or `per-call`). `--mood` starts from a picture you have; `--lettering` cuts a lettering image again with nothing generated. `--chroma-key auto` scores both keys on the colours in the title's box (the mood check returns it): a letter in a key's hue counts against it, and a key wins by how long a glow's mix with it keeps its hue. Nothing in the path draws a font ([logo](docs/logo.md)).- **New: the logo matte (`frames.logo_matte`) keeps a glow's fade and leaves no key hue.** The sprite matte ramps coverage over a short chroma distance, so on a white glow it is opaque half way to white with the pink mix of glow and key as its colour, and cuts the fade's last fifth to nothing. The logo matte measures the key as a quadratic surface with its noise, keeps material (far from the key, without its hue, minus rim pixels that are a mix of the key with the colour just inside) as drawn, gives a letter's antialiased edge its coverage on the letter's own colour, takes every other mix at the least coverage any colour could have, measures a glow's last trace on its faint neighbours, clears the faint seam a generated picture often has on its outer rows and columns, and writes each colour with the key's share taken out. Known limit: a glow carrying none of the key's hue, pooled dense and flat in a counter, is kept opaque; on the key whose hue it shares more it keeps its fade ([logo](docs/logo.md#known-limit)).- **New: every provider's vision call takes the question asked (`inspect_image`).** The facing check's question and request body are unchanged; `logo` asks what the lettering spells, on the provider and credential that drew it.-- **Tests** — `tests/frames/test_logo_matte.py` (synthetic lettering with a known coverage and colour, no font drawn: solid letters opaque in their colour; a white glow's fade within 0.04 of the truth, never opaque short of 80 %, and its faint trace kept; no key hue on a dark or a light backdrop; a shaded key; an outlined letter with a cyan glow; a pooled cyan glow on green, and the known limit on magenta; the green key; pixel lettering hard-edged; a seam on the picture's edge; refusals of a border that is not the key and of an empty key; the trim, the coverage and the key choice), `tests/gen/test_logo.py` (the three steps through a stand-in provider: prompts, references, files and report; the text check on a plain backdrop; empty text refused before any call; a dropped title refused before the lettering; differing letters and no text refused with the cut kept aside; a check that could not run said, not passed; subtitle and language; `--mood`, `--lettering` in place, the key from the title box, an explicit key; no font drawn; a failed lettering leaves nothing in its place; a painted checkerboard refused; per-call routes; the letter-for-letter comparison) and `tests/gen/test_vision_read.py` (the question and detail carried on codex, grok and openai; the facing body unchanged).+- **Tests** — `tests/frames/test_logo_matte.py` (synthetic lettering with a known coverage and colour, no font drawn: solid letters opaque in their colour; a white glow's fade within 0.04 of the truth, never opaque short of 80 %, and its faint trace kept; no key hue on a dark or a light backdrop; a shaded key; an outlined letter with a cyan glow; a pooled cyan glow on green, and the known limit on magenta; the green key; pixel lettering hard-edged; a seam on the picture's edge; refusals of a border that is not the key and of an empty key; the trim, the coverage and the key choice), `tests/gen/test_logo.py` (the three steps through a stand-in provider: prompts, references, files and report; the text check on a plain backdrop; empty text refused before any call; a dropped title refused before the lettering; differing letters and no text refused with the cut kept aside; a check that could not run said, not passed; subtitle and language; `--mood`, `--lettering` in place, the key from the title box, an explicit key; no font drawn; a failed lettering leaves nothing in its place; a painted checkerboard refused; per-call routes; the comparison across scripts: a Devanagari vowel sign, virama or nukta, a Thai tone mark or a Latin accent dropped, or Arabic vowel marks changed, is a mismatch, and a vowel sign dropped is refused at both checks; Hangul as jamo or syllables, half-width katakana, a Roman numeral form, a variation selector, a keycap and a zero-width joiner are the same spelling) and `tests/gen/test_vision_read.py` (the question and detail carried on codex, grok and openai; the facing body unchanged).- **Behavior change: `pixel-draw` runs on your Claude subscription first, and on `ANTHROPIC_API_KEY` only without one** — the order `codex` and `grok` keep. When `claude auth status` says Claude Code is signed in with a subscription (`claude.ai` or `oauth_token`), every call — the drawings, the row repairs, the pick — goes through the unmodified `claude` binary in print mode, from an empty directory, with no tool, no session written and no CLAUDE.md, hook, skill, plugin or MCP server loaded, and costs nothing per call: `report.json` says `auth_source: claude-login`, each call's `mode` is `subscription` and its `cost_usd` `0`, its usage kept. The child never sees `ANTHROPIC_API_KEY`, which print mode would use instead of the login. Without a subscription login the run uses the key as before, billed per call and said on stderr; with neither it is refused naming both, before the run folder is made. A login that refuses a call, has expired or has reached its usage limit fails the call; the run never switches to the key on its own. `--batch` is the API's Message Batches and runs on the key even when signed in. An answer the binary continues past the output cap is read whole from every message, not from its `result`, which holds only the last part; one it cannot finish is read as `stop_reason: max_tokens`, so the one redraw one effort lower happens on either route. One call may take up to `SPRITE_GEN_CLAUDE_CALL_TIMEOUT_SECONDS` (1800). When candidates ask at once, none of their requests leaves before the billing line has been printed. `report.json`'s `auth_source` is what the calls ran on by their records, `mixed` (with `auth_sources`) for a run resumed under the other credential. A `--resume` that reads every call back no longer prints the billing line ([pixel-draw](docs/pixel-draw.md#which-credential-a-call-runs-on)).- **Behavior change: every metered call says so on the terminal, and every report names what a call ran on.** How codex is signed in is one reading, `codex_provider.codex_login` (`codex login status`), for the default provider resolution, `gen --provider codex`, the codex facing check and `workflow`: a codex signed in with an API key used to run with no word about it and the workflow called it a subscription; it now prints the per-call charge line before `codex exec` runs, its report records `extra.auth_source: codex-api-key` (`codex-login` on ChatGPT), and `workflow` asks to confirm the API credit. A codex that is not signed in is refused with the reason before it runs. `gen-set` and `video-set` keep each item's output in its log, but a child's billing line and a default provider switch now also print on the terminal as they happen (`base.run_logged`), each `gen-set` row records `auth_source`, and each `video-set` clip result too. `sound` prints the same billing line as every other metered route (it printed its own) and its receipt records `auth_source`. One function reads a provider key from the environment (`base.env_api_key`: a key, none, or a refusal of an empty one) for Anthropic, OpenAI, xAI and ElevenLabs; one function says what to do when xAI rejects a credential (`xai.rejected_fix`), so `gen --provider grok` now gives the same `grok models` refresh as `video`. `workflow` probes a provider once for its images and videos (they share one credential) and asks the API-credit question by that provider's name rather than always about Grok video. Docs: the credential table in the README, grok's `XAI_API_KEY` route in the help and SKILL.md, the sound billing line, `SPRITE_GEN_GEN_TIMEOUT_SECONDS` and `SPRITE_GEN_CLAUDE_READ_TIMEOUT_SECONDS`, and `gen-set --provider` (`codex` or `grok`).diff --git a/docs/logo.md b/docs/logo.mdindex c355043..c770aed 100644--- a/docs/logo.md+++ b/docs/logo.md@@ -82,10 +82,20 @@ its text could not be checked); `refused` (with `refused_at`: `mood-check`, `matThe provider that drew the images reads them back, once each, through the same vision callthe facing check uses (`inspect_image`; codex `exec` read-only and ephemeral, or the xAI orOpenAI Responses API on the same credential). It is asked to return the lines of text as-spelled, without being told what they should say. The comparison folds case and-compatibility forms and keeps only letters and digits, so `Hero's Quest` matches-`HERO’S QUEST!` and `I O N` matches `ION`; the subtitle may be read before or after the-title. The verdict is one of:+spelled, without being told what they should say. Both checks compare by one rule+(`logo.normalize`), what the text spells:++- **kept** — every letter and digit, and every mark written on one: an accent, a vowel+ sign, a virama, a nukta, a tone mark, a voiced mark. `किला` read as `कला` (the vowel sign+ `ि` gone) is a mismatch, and so is `Café` read as `CAFE`. An accent counts on a capital+ too: for lettering in capitals that go without their accents (as Greek capitals do), give+ the title that way. Hangul is compared by its syllables, so `별` written as jamo is `별`;+- **folded away** — case, compatibility forms (full-width letters, ligatures, `Ⅳ` and+ `IV`), the characters drawn as nothing (joiners, variation selectors), enclosing marks (a+ keycap), and spaces, punctuation and symbols, with any mark written on them. So `Hero's+ Quest` matches `HERO’S QUEST!` and `I O N` matches `ION`.++The subtitle may be read before or after the title. The verdict is one of:| Verdict | At the mood image | At the logo ||---|---|---|diff --git a/sprite_gen/gen/logo.py b/sprite_gen/gen/logo.pyindex 54524a0..499b82b 100644--- a/sprite_gen/gen/logo.py+++ b/sprite_gen/gen/logo.py@@ -116,16 +116,49 @@ def lettering_prompt(text: str, *, subtitle: str | None = None, composition: strreturn " ".join(parts)+# Unicode's Default_Ignorable_Code_Point (DerivedCoreProperties.txt 16.0.0, adjacent ranges joined): the+# characters drawn as nothing — joiners, variation selectors, fillers, bidi and tag controls.+DEFAULT_IGNORABLE = (+ (0x00AD, 0x00AD), (0x034F, 0x034F), (0x061C, 0x061C), (0x115F, 0x1160), (0x17B4, 0x17B5), (0x180B, 0x180F),+ (0x200B, 0x200F), (0x202A, 0x202E), (0x2060, 0x206F), (0x3164, 0x3164), (0xFE00, 0xFE0F), (0xFEFF, 0xFEFF),+ (0xFFA0, 0xFFA0), (0xFFF0, 0xFFF8), (0x1BCA0, 0x1BCA3), (0x1D173, 0x1D17A), (0xE0000, 0xE0FFF),+)++def normalize(text: str) -> str:- """Letters and digits only, compatibility-folded and case-folded: what a reader of the logo spells."""- folded = unicodedata.normalize("NFKC", text).casefold()- return "".join(ch for ch in folded if unicodedata.category(ch)[0] in "LN")+ """What the text spells, the one rule both text checks compare by (docs/logo.md, the text check).++ Kept, in order: every letter and digit, and every mark written on one — an accent, a vowel sign, a virama,+ a nukta, a tone mark, a voiced mark — so किला is not कला; Hangul by its syllables, so 별 written as jamo is+ 별. Folded away, where readings of the same letters differ: case (full case folding), compatibility forms+ (NFKC: width, ligatures, circled and styled letters, Ⅳ as IV), the characters drawn as nothing, enclosing+ marks (a keycap, a circle), and every other character — spaces, punctuation, symbols — with the marks+ written on it.+ """+ folded = unicodedata.normalize("NFKC", unicodedata.normalize("NFKC", text).casefold())+ kept: list[str] = []+ on_kept = False # whether the character a mark is written on was kept+ for ch in folded:+ point = ord(ch)+ if any(low <= point <= high for low, high in DEFAULT_IGNORABLE):+ continue+ kind = unicodedata.category(ch)+ if kind[0] in "LN":+ kept.append(ch)+ on_kept = True+ elif kind[0] == "M":+ if on_kept and kind != "Me":+ kept.append(ch)+ else:+ on_kept = False+ return unicodedata.normalize("NFC", "".join(kept)) # a mark a dropped joiner held apart joins its letterdef compare_text(lines: list[str], text: str, subtitle: str | None) -> dict[str, Any]:- """The lines read off an image against the text asked, letter for letter (the subtitle before or after)."""+ """The lines read off an image against the text asked, by what each spells (`normalize`), the subtitle+ before or after the title: the verdict of both text checks."""asked_title, asked_subtitle = normalize(text), normalize(subtitle or "")- read = normalize("".join(lines))+ read = normalize("\n".join(lines)) # a mark that starts a line is not written on the line aboveif not read:verdict = "no-text"elif read in (asked_title + asked_subtitle, asked_subtitle + asked_title):