From 1cf5b1460d023457180fa6d6f5372ddeb33cd72b Mon Sep 17 00:00:00 2001 From: Dasemu Date: Mon, 19 Oct 2026 04:09:00 +0200 Subject: [PATCH] feat(assets): manifest v2 with per-style renditions, --style CLI and automatic checks Co-Authored-By: Claude Opus 5.5 --- src/vnpipe/assets.py | 350 +++++++++++++++++++---- src/vnpipe/schemas/manifest.schema.json | 162 ++++++----- tests/test_assets.py | 355 ++++++++++++++++++++++++ 3 files changed, 748 insertions(+), 119 deletions(-) create mode 100644 tests/test_assets.py diff --git a/src/vnpipe/assets.py b/src/vnpipe/assets.py index da6d22f..4833354 100644 --- a/src/vnpipe/assets.py +++ b/src/vnpipe/assets.py @@ -1,15 +1,18 @@ """Asset manifest management: import generated images, key out sprite backgrounds, fall back to placeholders, and build contact sheets for visual review. -The manifest (``/assets/assets.json``) is the single source of truth for every -image: prompt, origin, hash and review status. Image generation itself happens +The manifest (``/assets/assets.json``, v2) is the single source of truth for every +image. Art *styles* (prompt base + templates) are declared once; each asset has one +*rendition* per style (origin, hash, review status). Image generation itself happens outside this module (an MCP tool driven by an agent); ``import`` ingests its result. """ import argparse import base64 import hashlib +import io import json +import shutil from pathlib import Path from typing import Any @@ -27,6 +30,11 @@ USABLE = {"processed", "approved"} KEY_FULL = 60 # at or above: fully transparent KEY_NONE = 20 # at or below: fully opaque +# Sprite sanity bounds (checked on the keyed, untrimmed image when the raw file exists). +COVERAGE_MIN = 0.15 +COVERAGE_MAX = 0.85 +ALPHA_VISIBLE = 16 + def sha256_file(path: Path) -> str: return hashlib.sha256(path.read_bytes()).hexdigest() @@ -35,6 +43,13 @@ def sha256_file(path: Path) -> str: def load_manifest(work_root: Path) -> dict[str, Any]: data = json.loads((work_root / MANIFEST).read_text(encoding="utf-8")) validate(data, "manifest") + styles = data["styles"] + if data["default_style"] not in styles: + raise ValueError(f"default_style {data['default_style']!r} is not in styles") + for asset in data["assets"]: + unknown = set(asset["renditions"]) - set(styles) + if unknown: + raise ValueError(f"{asset['id']}: renditions for unknown styles {sorted(unknown)}") return data @@ -51,11 +66,157 @@ def find_asset(manifest: dict[str, Any], asset_id: str) -> dict[str, Any]: raise KeyError(f"unknown asset id: {asset_id}") -def full_prompt(manifest: dict[str, Any], asset: dict[str, Any]) -> str: - """Prompt actually sent to the generator: base + kind template + asset prompt.""" +def resolve_style(manifest: dict[str, Any], style: str | None) -> str: + """``style`` or the manifest default; raises ``ValueError`` for an unknown style.""" + style = style or manifest["default_style"] + if style not in manifest["styles"]: + raise ValueError(f"unknown style {style!r}; known: {sorted(manifest['styles'])}") + return style + + +def asset_name(asset: dict[str, Any]) -> str: + """File stem: the id without its ``bg_`` / ``sprite_`` prefix.""" + return asset["id"].split("_", 1)[1] + + +def style_file(asset: dict[str, Any], style: str) -> str: + """Final image path (relative to the assets dir): ``/