Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.
refactor(workflow): the journeys' and fields' names written once in catalog and the two access readings guide acts on written once in access, and guide reads all of them by name
Soohong Kimb065315a3101
diff --git a/sprite_gen/workflow/access.py b/sprite_gen/workflow/access.pyindex c25ac57..9842498 100644--- a/sprite_gen/workflow/access.py+++ b/sprite_gen/workflow/access.py@@ -8,6 +8,10 @@ from sprite_gen.gen.openai_provider import AUTH_ENV as OPENAI_AUTH_ENVfrom sprite_gen.gen.openai_provider import resolve_credential as resolve_openai_credentialfrom sprite_gen.gen.xai import AUTH_SOURCE_API_KEY, resolve_credential+# The readings `guide` acts on, each written once: a login that cannot be used, and a route billed per call.+LOGIN_UNAVAILABLE = "unavailable"+BILLING_API_CREDIT = "api-credit"+def probe_access(provider: str) -> dict:"""One probe per provider: images and videos of a provider share its credential precedence."""@@ -17,9 +21,9 @@ def probe_access(provider: str) -> dict:# The one reading of how codex is signed in; it never repeats what the CLI said.login = codex_provider.codex_login()if login.source is None:- return {**result, "login": "unavailable", "reason": f"{login.reason}; sign in and check again"}+ return {**result, "login": LOGIN_UNAVAILABLE, "reason": f"{login.reason}; sign in and check again"}if login.source == codex_provider.AUTH_SOURCE_API_KEY:- return {**result, "login": "ready", "billing": "api-credit",+ return {**result, "login": "ready", "billing": BILLING_API_CREDIT,"reason": "codex is signed in with an API key and bills it per call; confirm this billing choice ""or sign in with ChatGPT (`codex login`)."}return {**result, "login": "ready"}@@ -30,9 +34,9 @@ def probe_access(provider: str) -> dict:try:resolve_openai_credential()except (SystemExit, OSError, ValueError):- return {**result, "login": "unavailable",+ return {**result, "login": LOGIN_UNAVAILABLE,"reason": f"{OPENAI_AUTH_ENV} is not set; export the key or choose another provider"}- return {**result, "login": "ready", "billing": "api-credit",+ return {**result, "login": "ready", "billing": BILLING_API_CREDIT,"reason": f"OpenAI images will use {OPENAI_AUTH_ENV} and separate API credit; confirm this billing choice."}if provider != PROVIDER_GROK:raise ValueError(f"unknown provider: {provider}")@@ -40,8 +44,8 @@ def probe_access(provider: str) -> dict:# Images and videos use the same direct API credential precedence.credential = resolve_credential()except (SystemExit, OSError, ValueError):- return {**result, "login": "unavailable", "reason": "grok credential missing, expired or unreadable; check grok login"}+ return {**result, "login": LOGIN_UNAVAILABLE, "reason": "grok credential missing, expired or unreadable; check grok login"}if credential.source == AUTH_SOURCE_API_KEY:- return {**result, "login": "ready", "billing": "api-credit",+ return {**result, "login": "ready", "billing": BILLING_API_CREDIT,"reason": "Grok media will use XAI_API_KEY and separate API credit; confirm this billing choice."}return {**result, "login": "ready"}diff --git a/sprite_gen/workflow/catalog.py b/sprite_gen/workflow/catalog.pyindex 8a0ad8e..cf89994 100644--- a/sprite_gen/workflow/catalog.py+++ b/sprite_gen/workflow/catalog.py@@ -29,13 +29,16 @@ _unregistered = [provider for provider in GUIDED_PROVIDERS if provider not in PRif _unregistered:raise RuntimeError(f"workflow catalog: guided provider(s) not registered: {', '.join(_unregistered)}")+# The journeys' and fields' names, each written once: the keys of FLOWS and FIELDS, which `guide` reads by them.+SPRITE, IMAGE = "sprite", "image"+IMAGE_PROVIDER, MOTION_METHOD, CURATION = "image_provider", "motion_method", "curation"FIELDS = {- "image_provider": {"options": {provider: PROVIDER_LABELS[provider] for provider in GUIDED_PROVIDERS},- "question": "이미지를 지피티로 만들까요, 그록으로 만들까요?"},- "motion_method": {"options": {k: v["label"] for k, v in MOTION_METHODS.items()},- "question": "동작을 그록 영상으로 만들까요, 지피티 이미지 스프라이트로 만들까요?"},- "curation": {"options": {"open": "열기", "skip": "열지 않기"},- "question": "큐레이션뷰에서 결과를 확인하고 골라볼까요?"},+ IMAGE_PROVIDER: {"options": {provider: PROVIDER_LABELS[provider] for provider in GUIDED_PROVIDERS},+ "question": "이미지를 지피티로 만들까요, 그록으로 만들까요?"},+ MOTION_METHOD: {"options": {k: v["label"] for k, v in MOTION_METHODS.items()},+ "question": "동작을 그록 영상으로 만들까요, 지피티 이미지 스프라이트로 만들까요?"},+ CURATION: {"options": {"open": "열기", "skip": "열지 않기"},+ "question": "큐레이션뷰에서 결과를 확인하고 골라볼까요?"},}# Settings every profile shares, asked once and saved beside the profiles (`preferences`, `general`). The one so# far: what a call that names no provider does when codex cannot run here (not signed in, or its usage used up) —@@ -51,8 +54,8 @@ if list(GENERAL_FIELDS[CODEX_UNAVAILABLE_SETTING]["options"]) != list(CODEX_UNAVraise RuntimeError("workflow catalog: the codex-unavailable options must be gen.CODEX_UNAVAILABLE_CHOICES")FLOWS = {- "sprite": {"label": "스프라이트 만들기", "fields": ("image_provider", "motion_method", "curation")},- "image": {"label": "이미지 만들기", "fields": ("image_provider", "curation")},+ SPRITE: {"label": "스프라이트 만들기", "fields": (IMAGE_PROVIDER, MOTION_METHOD, CURATION)},+ IMAGE: {"label": "이미지 만들기", "fields": (IMAGE_PROVIDER, CURATION)},}diff --git a/sprite_gen/workflow/guide.py b/sprite_gen/workflow/guide.pyindex 47eaebc..3183bcd 100644--- a/sprite_gen/workflow/guide.py+++ b/sprite_gen/workflow/guide.py@@ -8,8 +8,9 @@ from pathlib import Pathfrom sprite_gen.gen import CODEX_UNAVAILABLE_SETTING, codex_unavailable_choice-from .access import probe_access-from .catalog import FIELDS, FLOWS, GENERAL_FIELDS, MOTION_METHODS, validate_choices+from .access import BILLING_API_CREDIT, LOGIN_UNAVAILABLE, probe_access+from .catalog import (CURATION, FIELDS, FLOWS, GENERAL_FIELDS, IMAGE_PROVIDER, MOTION_METHOD, MOTION_METHODS, SPRITE,+ validate_choices)from .preferences import read_settings@@ -18,7 +19,7 @@ def guide(kind: str, *, stage: str = "start", base_image: Path | None = None, reexplicit = validate_choices(kind, choices or {})if stage not in ("start", "finish"):raise ValueError("stage must be start or finish")- if base_image is not None and (kind != "sprite" or not Path(base_image).is_file()):+ if base_image is not None and (kind != SPRITE or not Path(base_image).is_file()):raise ValueError("--base-image must name an existing sprite reference image")if stage == "finish" and (result is None or not Path(result).exists()):raise ValueError("finish requires an existing --result file or run directory, after generation and QA")@@ -26,9 +27,9 @@ def guide(kind: str, *, stage: str = "start", base_image: Path | None = None, restored = snapshot["profiles"].get(kind, {})selected = {**stored, **explicit}sources = {key: "request" if key in explicit else "saved" for key in selected}- active_fields = [key for key in FLOWS[kind]["fields"] if key != "curation"]+ active_fields = [key for key in FLOWS[kind]["fields"] if key != CURATION]if base_image is not None:- active_fields.remove("image_provider")+ active_fields.remove(IMAGE_PROVIDER)questions, blocked, access = [], [], []# Asked once, before the first generation, and saved: what a call that names no provider does when codex cannot# run. The environment answers it as well; it is never asked over a saved or given answer.@@ -43,21 +44,21 @@ def guide(kind: str, *, stage: str = "start", base_image: Path | None = None, re# Report both candidates while choosing, then only the services actually# used. One probe per provider: its images and videos share one credential.required = set()- if "image_provider" in active_fields and selected.get("image_provider"):- required.add(selected["image_provider"])- motion = MOTION_METHODS.get(selected.get("motion_method", ""))+ if IMAGE_PROVIDER in active_fields and selected.get(IMAGE_PROVIDER):+ required.add(selected[IMAGE_PROVIDER])+ motion = MOTION_METHODS.get(selected.get(MOTION_METHOD, ""))if motion:required.add(motion["provider"])- candidates = required or set(FIELDS["image_provider"]["options"])+ candidates = required or set(FIELDS[IMAGE_PROVIDER]["options"])for provider in sorted(candidates):state = probe_access(provider)access.append(state)if provider not in required:continue- label = FIELDS["image_provider"]["options"].get(provider, provider)- if state["login"] == "unavailable":+ label = FIELDS[IMAGE_PROVIDER]["options"].get(provider, provider)+ if state["login"] == LOGIN_UNAVAILABLE:blocked.append({"provider": provider, "reason": state["reason"]})- elif state["billing"] == "api-credit":+ elif state["billing"] == BILLING_API_CREDIT:if not confirm_api_billing and not any(q["field"] == "confirm_api_billing" for q in questions):questions.append({"field": "confirm_api_billing", "question": f"{label} 호출에 별도 API 크레딧을 사용할까요?","options": {"yes": "사용", "no": "구독 로그인으로 변경"}})@@ -68,17 +69,17 @@ def guide(kind: str, *, stage: str = "start", base_image: Path | None = None, remissing = [field for field in active_fields if field not in selected]if missing:raise ValueError("finish requires the actual generation choices: " + ", ".join(missing))- if "curation" not in selected:- questions.append({"field": "curation", **FIELDS["curation"]})+ if CURATION not in selected:+ questions.append({"field": CURATION, **FIELDS[CURATION]})elif not stored:questions.append({"field": "save_defaults", "question": "이번 선택을 다음 작업에도 기본으로 사용할까요?","options": {"yes": "기본 설정으로 저장", "no": "이번에만 사용"}})pipeline = Noneif not any(field not in selected for field in active_fields):- motion = MOTION_METHODS.get(selected.get("motion_method", ""))+ motion = MOTION_METHODS.get(selected.get(MOTION_METHOD, ""))pipeline = {"base_image": str(base_image) if base_image else None,- "image_provider": selected.get("image_provider") if "image_provider" in active_fields else None,- "generation_provider": motion["provider"] if motion else selected.get("image_provider"),+ IMAGE_PROVIDER: selected.get(IMAGE_PROVIDER) if IMAGE_PROVIDER in active_fields else None,+ "generation_provider": motion["provider"] if motion else selected.get(IMAGE_PROVIDER),"steps": motion["steps"] if motion else ["gen"],"doc": motion["doc"] if motion else "docs/gen.md"}labels = [FIELDS[key]["options"][selected[key]] for key in active_fields if key in selected]@@ -87,8 +88,8 @@ def guide(kind: str, *, stage: str = "start", base_image: Path | None = None, re"settings_revision": snapshot["revision"], "settings_path": snapshot["path"],"codex_unavailable": {"choice": codex_choice, "source": codex_choice_source},"access": access, "blocked": blocked, "questions": questions, "pipeline": pipeline,- "curation": selected.get("curation", "ask") if stage == "finish" else "after-result",- "save_candidate": selected if stage == "finish" and "curation" in selected else None}+ CURATION: selected.get(CURATION, "ask") if stage == "finish" else "after-result",+ "save_candidate": selected if stage == "finish" and CURATION in selected else None}def add_arguments(parser: argparse.ArgumentParser) -> None:@@ -96,7 +97,7 @@ def add_arguments(parser: argparse.ArgumentParser) -> None:parser.add_argument("--stage", choices=("start", "finish"), default="start")parser.add_argument("--base-image", type=Path)parser.add_argument("--result", type=Path)- parser.add_argument("--confirmed-access", action="append", choices=FIELDS["image_provider"]["options"], default=[])+ parser.add_argument("--confirmed-access", action="append", choices=FIELDS[IMAGE_PROVIDER]["options"], default=[])parser.add_argument("--confirm-api-billing", action="store_true")for key, field in FIELDS.items():parser.add_argument("--" + key.replace("_", "-"), choices=field["options"])