Skip to content

Paint the Ren'Py scene's pictures with fal, under a cap - #403

Merged
calebl merged 1 commit into
mainfrom
fm/ta-renpy-s2-art
Dec 4, 2026
Merged

calebl merged 1 commit into
mainfrom
fm/ta-renpy-s2-art

Conversation

@calebl

@calebl calebl commented Dec 4, 2026

Copy link
Copy Markdown
Collaborator

Stage 2 of the Ren'Py proof: the pictures, from fal. This PR spends nothing. The paid run comes later, on the private copy, after this lands.

What it adds

  • FalImageAgent (app/agents/FalImageAgent.rb): a third named door for model calls, beside BaseAgent and SystemOneAgent. It is a plain Net::HTTP client for fal's queue API and adds no new gem. It submits a request, polls the status URL, reads the result, then downloads the picture without the key.

    • The key comes from 1Password at run time (op read op://Mate/fal/credential, using the service account token in ~/.config/op/service-account-token). Only rake art:generate reads it.
    • The key is sent only to the queue's own host. It is never printed, logged or stored, and #inspect hides it.
    • In the test environment, the real fal address is refused.
  • Models and sizes, as approved:

    • fal-ai/bytedance/seedream/v4/text-to-image for portraits and backgrounds: 1024×1536 standing, 1024×1024 side image, 1920×1080 background.
    • fal-ai/bria/background/remove for cut-outs.
    • fal-ai/bytedance/seedream/v4/edit for the second expression, with the first portrait sent inline as a reference.
    • The safety checker stays at fal's default.
  • artworks table: one row per picture of a Location or Character. Each row records:

    • kind and expression;
    • endpoint;
    • the full prompt as sent;
    • seed;
    • request ids;
    • the list price of each call;
    • the picture file and the cut-out file.

    Files live under TA_ART_ROOT (default storage/art, which is git-ignored). A row is written as soon as fal answers, so every paid call is recorded even if its download fails.

  • Artwork::Prompt: the approved prompt templates. For The Lunar Cartographer's opening they produce all four approved prompts byte for byte. The expected text is stored in test/fixtures/files/art/ and tested.

  • Artwork::Plan: works out the pictures from the export, keyed by Ren'Py image tag (c<id>, l<id>, c<id>-stern), and prices them. For the opening: $0.126 for the scene, $0.174 with the second expression, $0.048 for the trial (ONLY=c<grenn>).

  • rake 'art:prompts[story]': prints every prompt and the bill. It is free: no key is read and nothing is sent.

  • CAP=… ONLY=… [AGAIN=1] rake 'art:generate[story]': makes the pictures.

    • It will not start without CAP.
    • It refuses a bill over CAP before it reads the key.
    • The painter checks the cap again before every call.
  • Exporter: Renpy::Export uses a stored picture when one exists on this machine's disk (the cut-out, for a person) and copies it into game/art/. Otherwise it keeps the placeholder. A retake changes the script and therefore the build's digest.

  • Docs: AGENTS.md gains a line naming the third door, plus README, docs/local-deploy.md, deploy.env.example (TA_ART_ROOT) and the ignore rule. artworks is skipped in the engine's row dumps (Playthrough::Requests, EngineVectors::Records) because no request builder reads it.

Post-update action

None. The new migration runs through bin/update's existing migrate step.

Tests

No network and no spend:

  • a fake fal server on 127.0.0.1 (test/support/fake_fal.rb) for the agent and the painter;
  • the cap refusals, for both the painter and the rake task, with no key read;
  • the approved prompts against their stored text;
  • the exporter preferring a stored picture.

bin/rails test (5571 runs, 0 failures, 1 skip: the Ren'Py SDK lint), bundle exec rubocop, bin/rails zeitwerk:check and bin/brakeman --no-pager all pass. Every check ran with OPENROUTER_API_KEY and TYPESAFE_API_KEY unset.

The migration version came from bin/rails generate migration (20261204143219). It is newer than the latest migration on main (20261031180000).

FalImageAgent is a third named door for a model call beside BaseAgent and
SystemOneAgent: a plain Net::HTTP client for fal's queue API (submit, poll
the status URL, read the result, fetch the picture without the key). The
key is read from 1Password at run time by `rake art:generate` alone, sent
only to the queue's own host, and never printed, logged or stored. In the
test environment the real queue address is refused outright.

Artwork rows hold one picture each of a Location (background) or a
Character (standing portrait, the protagonist's side image, or a second
expression edited from the portrait): kind, endpoint, the full prompt as
sent, seed, request ids, the list price booked for each call, and the
picture and cut-out files under TA_ART_ROOT (default storage/art, ignored).
A row is written as soon as fal answers, so a paid call is always on record.

Artwork::Prompt holds the approved wording; for The Lunar Cartographer's
opening it makes the four approved prompts byte for byte, stored under
test/fixtures/files/art/ and tested. Artwork::Plan derives the pictures
from the export, keyed by their Ren'Py image tags, and prices them
($0.174 for the opening with the second expression).

`rake art:prompts[story]` prints every prompt and the bill, free.
`rake art:generate[story] CAP=... ONLY=...` refuses to start, before the
key is read, when the bill exceeds CAP; the painter checks the cap again
before every call. Renpy::Export shows a kept picture (the cut-out for a
person) instead of its placeholder and copies it into game/art/.

No fal request or model call was made building or testing this.
@calebl
calebl merged commit 4f7ec7e into main Dec 4, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant