Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.
fix(xai): prescribe a non-agent grok refresh run outside the repo
Soohong Kimd27e14d69541
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex b48e7eb..e74377a 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -2,6 +2,10 @@All notable public changes to `sprite-gen` are recorded here. Versions track the `version:` field in `SKILL.md` and `pyproject.toml`.+## Unreleased (v2.2.1)++- The expired-login prescription for Grok video and images no longer names a bare prompt (`grok -p ok`): on the grok CLI that starts the coding agent in the current directory, which can read, write and spend on its own. The prescription is now a non-agent round-trip (`grok models`) run from an empty directory, with `grok login` as the fallback, and the message says so. A test pins the prescription to a non-agent command.+## v2.2.0 - Independent asset tools and optional scenes- Added standalone `background-tile`, `shadow` and `inspect-motion` commands. They accept existing artwork and report tile joins, anchor-preserving shadow projections, repeated poses and explicit foot-contact measurements without changing source animation.diff --git a/SKILL.md b/SKILL.mdindex 28f321f..c12060e 100644--- a/SKILL.md+++ b/SKILL.md@@ -1,6 +1,6 @@---name: sprite-gen-version: 2.2.0+version: 2.2.1description: "Generates images and game sprites through GPT or Grok with guided provider choices, separate saved defaults, automatic cleanup and optional curation. Handles sprite requests, ordinary image generation/editing, standalone image-to-video clips (i2v, animate this still, 그록 영상, 이매진 비디오, 스틸 움직여줘), chroma removal, animation atlases, video loops, 큐레이션뷰, image candidates, 팔레트 스왑, palette swap, recolor, rig layers, engine exports, repeating backgrounds, projected shadows, motion/contact inspection and optional scene composition from existing assets."license: Apache-2.0depends_on:diff --git a/docs/video.md b/docs/video.mdindex fef96b0..8d510f0 100644--- a/docs/video.md+++ b/docs/video.md@@ -28,18 +28,28 @@ with both setup paths spelled out.### The login token expires — and this tool does not refresh it-The grok CLI stores an OIDC access token that lasts about six hours-(2026-09-08 measurement: `expires_at` 10:56Z, refreshed to 18:26Z by the next grok-command). `sprite-gen video` reads `expires_at` **before uploading anything**; if-it has passed, the run fails with the refresh prescription instead of gambling on-a 403 mid-upload:+The grok CLI stores an OIDC access token that lasts about six hours. Any+long-lived grok session refreshes it proactively about five minutes before+`expires_at` (2026-09-13 measurement: a resident session rewrote `auth.json` at+00:15Z for a 00:20Z expiry), so the token only actually expires when no grok+process has run for hours. `sprite-gen video` reads `expires_at` **before+uploading anything**; if it has passed, the run fails with the refresh+prescription instead of gambling on a 403 mid-upload:```xai: the grok login token expired at 2026-09-08T10:56:34Z (now …); nothing was uploaded.- refresh it with any grok CLI command that reaches the API, e.g. `grok -p ok --output-format plain`,- or sign in again with `grok login`. This tool never rewrites ~/.grok/auth.json itself.+ refresh it with `grok models` run from an empty directory (e.g. `cd "$(mktemp -d)"`) — a non-agent round-trip; never a bare prompt like `grok -p …`, which starts the coding agent in your cwd — or sign in again with `grok login`. This tool never rewrites ~/.grok/auth.json itself.```+Why `grok models` and not a prompt: `grok -p ok` is not a ping. It starts the+coding agent in the current directory, which reads it, may write files and may+call paid APIs on its own (2026-09-13: run inside a worktree it overwrote a+script and spent a video generation). `grok models` only runs the CLI's startup+auth path (`auth: silent refresh` in `~/.grok/logs/unified.jsonl`), prints the+model list and exits, writing nothing outside `~/.grok`. Run it from an empty+directory anyway. If it prints a login error instead of the model list, the+refresh token is gone too: `grok login`.+Why not refresh it here: `auth.json` is the grok CLI's file, the refresh token init may rotate, and a second writer would break the login the user relies oneverywhere else. The same shape as `sprite-gen gen`'s `codex login status` gate.diff --git a/pyproject.toml b/pyproject.tomlindex 027734b..f579e7c 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -12,7 +12,7 @@ build-backend = "setuptools.build_meta"name = "sprite-gen"# Release discipline: keep this package metadata version synchronized with# SKILL.md's `version:` field in the same release commit.-version = "2.2.0"+version = "2.2.1"description = "Component-row pipeline for clean 2D game sprites and animation atlases"readme = "README.md"license = "Apache-2.0"diff --git a/sprite_gen/gen/video.py b/sprite_gen/gen/video.pyindex 3940e9b..89df4ad 100644--- a/sprite_gen/gen/video.py+++ b/sprite_gen/gen/video.py@@ -40,7 +40,7 @@ from typing import Any, Callablefrom sprite_gen.spec.runio import atomic_write_textfrom .xai import (API_BASE, AUTH_ENV, AUTH_SOURCE_API_KEY, AUTH_SOURCE_GROK_LOGIN,- HTTP_TIMEOUT_SECONDS, GROK_REFRESH_COMMAND, GROK_LOGIN_COMMAND,+ HTTP_TIMEOUT_SECONDS, GROK_REFRESH_COMMAND, GROK_REFRESH_WHERE, GROK_LOGIN_COMMAND,Credential, HttpCall, grok_home, resolve_credential, http_json,)@@ -205,7 +205,7 @@ def generate_video(raise SystemExit(f"video: xAI rejected the credential ({credential.source}) with HTTP {status}: {_error_detail(reply)}\n"+ (- f" the grok login token may have been revoked or rotated — run `{GROK_REFRESH_COMMAND}` or `{GROK_LOGIN_COMMAND}`."+ f" the grok login token may have been revoked or rotated — run `{GROK_REFRESH_COMMAND}` {GROK_REFRESH_WHERE} or `{GROK_LOGIN_COMMAND}`."if credential.source == AUTH_SOURCE_GROK_LOGINelse f" check the {AUTH_ENV} value.")diff --git a/sprite_gen/gen/xai.py b/sprite_gen/gen/xai.pyindex 923a43e..a857a56 100644--- a/sprite_gen/gen/xai.py+++ b/sprite_gen/gen/xai.py@@ -22,11 +22,17 @@ AUTH_SOURCE_API_KEY = "XAI_API_KEY"AUTH_SOURCE_GROK_LOGIN = "grok-login"HTTP_TIMEOUT_SECONDS = 120-# The refresh instruction for an expired login. The grok CLI rewrites the token-# the next time it talks to the API — measured 2026-09-08 with a one-line prompt-# (`grok -p ok`): expires_at moved from 10:56Z to 18:26Z. `grok login` is the-# full re-sign-in for a revoked or missing login.-GROK_REFRESH_COMMAND = "grok -p ok --output-format plain"+# The refresh instruction for an expired login. The grok CLI refreshes the token+# lazily, on its next API round-trip after `expires_at` has passed (2026-09-13+# measurement: while the token is still valid no command moves expires_at).+# The command must be a non-agent round-trip: a bare prompt (`grok -p ok`) starts+# the coding agent, which reads the cwd, may write files and may call paid APIs+# on its own (2026-09-13 incident, sprite-gen worktree). `grok models` only lists+# models and exits. Run it from an empty directory anyway so nothing of the+# user's is in reach. `grok login` is the full re-sign-in for a revoked, missing+# or non-refreshable login.+GROK_REFRESH_COMMAND = "grok models"+GROK_REFRESH_WHERE = "from an empty directory (e.g. `cd \"$(mktemp -d)\"`)"GROK_LOGIN_COMMAND = "grok login"@@ -86,7 +92,8 @@ def _load_grok_login(auth_path: Path, *, now: datetime) -> Credential:if expiry <= now:raise SystemExit(f"xai: the grok login token expired at {expires_at} (now {now.isoformat()}); nothing was uploaded.\n"- f" refresh it with any grok CLI command that reaches the API, e.g. `{GROK_REFRESH_COMMAND}`, "+ f" refresh it with `{GROK_REFRESH_COMMAND}` run {GROK_REFRESH_WHERE} — a non-agent round-trip; "+ f"never a bare prompt like `grok -p …`, which starts the coding agent in your cwd — "f"or sign in again with `{GROK_LOGIN_COMMAND}`. This tool never rewrites {auth_path} itself.")return Credential(token=token, source=AUTH_SOURCE_GROK_LOGIN, expires_at=expires_at if isinstance(expires_at, str) else None)diff --git a/tests/gen/test_video.py b/tests/gen/test_video.pyindex 654062d..4e131f8 100644--- a/tests/gen/test_video.py+++ b/tests/gen/test_video.py@@ -326,3 +326,19 @@ def test_video_uses_subscription_with_api_key_present(tmp_path, monkeypatch, staresult = video.generate_video(request, call=api.call, download=api.download, sleep=lambda _: None)assert result.auth_source == "grok-login"assert all(call[2] == "subscription-token" for call in api.calls)+++def test_refresh_prescription_is_a_non_agent_command_run_outside_the_repo(tmp_path: Path, monkeypatch) -> None:+ # 2026-09-13 incident: `grok -p ok` started the coding agent in the worker's cwd,+ # overwrote a script and spent a paid video call. The prescription must never be+ # a prompt, and must say where to run it.+ assert video.GROK_REFRESH_COMMAND == "grok models"+ assert " -p " not in f" {video.GROK_REFRESH_COMMAND} " and "--single" not in video.GROK_REFRESH_COMMAND+ assert "empty directory" in video.GROK_REFRESH_WHERE+ monkeypatch.setenv("GROK_HOME", str(_login_file(tmp_path, expires_at="2026-09-08T10:56:34.899829Z")))+ with pytest.raises(SystemExit) as excinfo:+ video.resolve_credential(env={}, now=NOW)+ message = str(excinfo.value)+ assert video.GROK_REFRESH_WHERE in message+ assert "grok -p ok" not in message.replace("`grok -p …`", "")+ assert "coding agent" in message