M4: map import CLI (pulled forward from M6) #79

Closed
opened 2026-11-21 15:09:46 +01:00 by SirStone · 1 comment
Owner

Part of #63

Goal

Build the DESIGN §11.1 map import CLI now, in M4, not as a throwaway seeder. The M4 gate needs a real map: #77's phone playtest requires a 16384 px tiled scene with 50 tokens, and today neither the scene dimensions nor the art can be set — scene.set explicitly refuses w, h, tile_size, cell, art_version (§6.1 "import is M6 CLI"), and the seeded scene is 4096 px, 32 px tiles, art_version 1.

DESIGN §11.1 specifies it: "offline CLI that slices an image into tile_size PNG/WebP tiles into <state>/tiles/<scene>/v<art_version>/ and registers/updates the scene". #63's Out of Scope currently lists "map import CLI (M6)"; the owner-delegated decision of 2026-11-21 (orchestrator) pulls it forward into M4 as the designed CLI. Record that decision in #63 and in DESIGN §13 (M6 → M4 plus a note in §11.1) and DESIGN-history §C.

Acceptance criteria

  • A CLI (devbox-run, offline, no browser) takes a source image plus the target scene and a tile_size, and writes tiles to <state>/tiles/<scene>/v<art_version>/ in the layout §3.3 and §11.1 fix (origin at world origin, filenames exactly as the tile gate parses them).
  • The CLI registers/updates the scene row: w, h (from the image), tile_size, art_version; it grows art_version when art is re-imported for an existing scene so browsers do not hit stale caches (§3.3), and it refuses combinations the server would reject (tile_size % cell == 0, tile-size fallback 64 allowed).
  • The server picks the result up per DESIGN: a restarted server serves the new scene dimensions in hello.scene and the new tiles through the tile gate without any code change; no server-side import path is added.
  • The CLI is tested: a small fixture image produces the expected tile count/geometry/filenames, the scene row is correct, a re-import bumps art_version, and the tile gate answers 200 for an allowed new tile (black-box, same harness style as tools/*.test.mjs).
  • Errors are handled: nonexistent input, unsupported format, unreadable/absent state dir, scene id not the v1 scene, and a locked instance (the state-dir lock of §3.2/§11.1) each exit non-zero with a clear message and change nothing.
  • A 16384 px scene with 50 tokens can be produced for #77 using this CLI plus the existing token intents; the steps are written down.
  • README's "Not in this build yet" no longer claims no import command; the usage section documents the CLI (invocation, args, where tiles land, re-import/art_version).
  • The decision is recorded: a comment/note on #63, DESIGN §13 (map import CLI moved from M6 to M4) and a DESIGN-history §C entry.
  • Standing gate: devbox run test, devbox run client-test, devbox run e2e green on a clean checkout, no test weakened or skipped.

Proven at

New offline CLI plus its black-box Node harness alongside tools/*.test.mjs (fixture image → tile tree + scene row + tile-gate 200); existing tools/tiles.test.mjs and tools/scene.test.mjs stay green.

Notes

  • Size: M (about one agent session). Lane: I/O (independent of the client lanes).
  • Do not reuse tools/genmap.mjs: it is the prototype's deterministic hand-authored fixture generator, not an image importer (§11.1 says so explicitly).
  • Do not add an upload path or a wire intent; browser upload stays post-v1 (Q5).
  • Not the NixOS deployment (M6); this is a devbox/offline tool that happens to be production-shaped.
  • Blocks #77 (the 16384 px scene).
Part of #63 ## Goal Build the DESIGN §11.1 map import CLI **now**, in M4, not as a throwaway seeder. The M4 gate needs a real map: #77's phone playtest requires a 16384 px tiled scene with 50 tokens, and today neither the scene dimensions nor the art can be set — `scene.set` explicitly refuses `w, h, tile_size, cell, art_version` (§6.1 "import is M6 CLI"), and the seeded scene is 4096 px, 32 px tiles, `art_version` 1. DESIGN §11.1 specifies it: "offline CLI that slices an image into `tile_size` PNG/WebP tiles into `<state>/tiles/<scene>/v<art_version>/` and registers/updates the scene". #63's Out of Scope currently lists "map import CLI (M6)"; the owner-delegated decision of 2026-11-21 (orchestrator) pulls it forward into M4 as the designed CLI. Record that decision in #63 and in DESIGN §13 (M6 → M4 plus a note in §11.1) and DESIGN-history §C. ## Acceptance criteria - [ ] A CLI (devbox-run, offline, no browser) takes a source image plus the target scene and a `tile_size`, and writes tiles to `<state>/tiles/<scene>/v<art_version>/` in the layout §3.3 and §11.1 fix (origin at world origin, filenames exactly as the tile gate parses them). - [ ] The CLI registers/updates the scene row: `w`, `h` (from the image), `tile_size`, `art_version`; it grows `art_version` when art is re-imported for an existing scene so browsers do not hit stale caches (§3.3), and it refuses combinations the server would reject (`tile_size % cell == 0`, tile-size fallback 64 allowed). - [ ] The server picks the result up per DESIGN: a restarted server serves the new scene dimensions in `hello.scene` and the new tiles through the tile gate without any code change; no server-side import path is added. - [ ] The CLI is tested: a small fixture image produces the expected tile count/geometry/filenames, the scene row is correct, a re-import bumps `art_version`, and the tile gate answers 200 for an allowed new tile (black-box, same harness style as `tools/*.test.mjs`). - [ ] Errors are handled: nonexistent input, unsupported format, unreadable/absent state dir, scene id not the v1 scene, and a locked instance (the state-dir lock of §3.2/§11.1) each exit non-zero with a clear message and change nothing. - [ ] A 16384 px scene with 50 tokens can be produced for #77 using this CLI plus the existing token intents; the steps are written down. - [ ] README's "Not in this build yet" no longer claims no import command; the usage section documents the CLI (invocation, args, where tiles land, re-import/art_version). - [ ] The decision is recorded: a comment/note on #63, DESIGN §13 (map import CLI moved from M6 to M4) and a DESIGN-history §C entry. - [ ] Standing gate: `devbox run test`, `devbox run client-test`, `devbox run e2e` green on a clean checkout, no test weakened or skipped. ## Proven at New offline CLI plus its black-box Node harness alongside `tools/*.test.mjs` (fixture image → tile tree + scene row + tile-gate 200); existing `tools/tiles.test.mjs` and `tools/scene.test.mjs` stay green. ## Notes - Size: M (about one agent session). Lane: I/O (independent of the client lanes). - Do not reuse `tools/genmap.mjs`: it is the prototype's deterministic hand-authored fixture generator, not an image importer (§11.1 says so explicitly). - Do not add an upload path or a wire intent; browser upload stays post-v1 (Q5). - Not the NixOS deployment (M6); this is a devbox/offline tool that happens to be production-shaped. - Blocks #77 (the 16384 px scene).
SirStone added the ready-for-agentenhancement labels 2026-11-21 15:09:46 +01:00
SirStone added a new dependency 2026-11-21 15:09:52 +01:00
Author
Owner

Implemented and merged as ad610ab (main).

CLI: fff-vtt import --image=<png|webp> [--scene=1] [--tile-size=<px>] [--state-dir=<path>] slices at the world origin into <state>/tiles/<scene>/v<art_version>/<x>_<y>.png and updates the scene row w, h, tile_size, art_version. Re-import grows art_version; older v dirs stay (M6 cleanup). It takes the state-dir lock (live server refuses, exit 3), so stop/import/restart; --tile-size defaults to the current tile size and must be a multiple of the 32 px cell (64 fallback).

Decoding: ImageMagick via the root devbox (imagemagick), run with -limit memory 256MiB -limit map 512MiB so its pixel cache is disk-backed and a 16384 px source is memory-sane. No Nim/npm image dependency; FIXED stack unchanged; archived genmap.mjs not reused.

Proof: tools/import.test.mjs (Tiles evidence in tools/groups.mjs) covers exact tile set/geometry, the scene row via hello.scene, a player with explored cells getting 200 through nginx+server (unexplored 403, stale version 404), the re-import bump + restart pickup, and every refusal (missing/unsupported/corrupt image, scene != 1, bad tile_size, absent state dir/DB, unreadable DB, held lock). README documents the CLI and the 16384 px / 50-token recipe; DESIGN 3.3/6.1/11.1/13 and DESIGN-history record the M6→M4 move.

Gates on rebased main (bacf2e1): devbox run test 161 Node + Nim green, devbox run client-test 173 green, devbox run e2e 27 green on a clean checkout; kernel log clean (oops|bug:|soft lockup|rcu stall|list_del|general protection|segfault = 0 lines).

Implemented and merged as ad610ab (main). **CLI:** `fff-vtt import --image=<png|webp> [--scene=1] [--tile-size=<px>] [--state-dir=<path>]` slices at the world origin into `<state>/tiles/<scene>/v<art_version>/<x>_<y>.png` and updates the scene row `w, h, tile_size, art_version`. Re-import grows `art_version`; older v dirs stay (M6 cleanup). It takes the state-dir lock (live server refuses, exit 3), so stop/import/restart; `--tile-size` defaults to the current tile size and must be a multiple of the 32 px cell (64 fallback). **Decoding:** ImageMagick via the root devbox (`imagemagick`), run with `-limit memory 256MiB -limit map 512MiB` so its pixel cache is disk-backed and a 16384 px source is memory-sane. No Nim/npm image dependency; FIXED stack unchanged; archived `genmap.mjs` not reused. **Proof:** `tools/import.test.mjs` (Tiles evidence in `tools/groups.mjs`) covers exact tile set/geometry, the scene row via `hello.scene`, a player with explored cells getting 200 through nginx+server (unexplored 403, stale version 404), the re-import bump + restart pickup, and every refusal (missing/unsupported/corrupt image, scene != 1, bad tile_size, absent state dir/DB, unreadable DB, held lock). README documents the CLI and the 16384 px / 50-token recipe; DESIGN 3.3/6.1/11.1/13 and DESIGN-history record the M6→M4 move. **Gates on rebased main (bacf2e1):** `devbox run test` 161 Node + Nim green, `devbox run client-test` 173 green, `devbox run e2e` 27 green on a clean checkout; kernel log clean (`oops|bug:|soft lockup|rcu stall|list_del|general protection|segfault` = 0 lines).
Sign in to join this conversation.