AGENTS.md¶
Guidance for AI coding agents (Claude Code, Copilot, Cursor) working in zer0-image-generator.
AI preview/social-image generation for any Jekyll site. It ships in three forms that share ONE behavior: the jekyll preview-images gem/CLI, the standalone Python engine (lib/zer0_image_generator/preview_generator.py), and a Dockerized Rails web app (web/). The web app drives a pure-Ruby port of the engine under lib/zer0_image_generator/*.rb; that port is pinned byte-for-byte against the Python original (see below). "Done" means all three stay in lockstep and the byte-identity tests stay green.
Stack & commands¶
# engine port (pure-Ruby) tests — byte-identity vs the Python oracle:
ruby -Ilib test/ruby/test_*.rb # 327 tests / 9.6k assertions
# original Python engine tests:
python3 test/test_preview_generator.py # zero network
python3 test/test_illustration_loop.py # the claude provider's loop (zero network)
# the gem's CLI translation layer:
ruby test/test_command.rb
# the web app:
cd web && bin/rails test # models, services, requests, jobs
SITES_DIR=.. docker compose up --build # run the app → localhost:3000
# end-to-end smoke harness (drives the real CLI against the fixture site):
.claude/skills/run-zer0-image-generator/smoke.sh
# build the gem:
gem build zer0-image-generator.gemspec
macOS gotcha: the system Ruby 2.6 can gem build but cannot run the CLI or the smoke harness — put Homebrew Ruby first with export PATH="/opt/homebrew/opt/ruby/bin:$PATH". The deep run guide is the run-zer0-image-generator skill (.claude/skills/run-zer0-image-generator/).
The pure-Ruby port (lib/zer0_image_generator/*.rb)¶
- The Python file
preview_generator.pyis the oracle, not scratch — never edit it as part of a port change; port TO Ruby and diff against it. - Determinism is a hard contract: the generators reproduce every committed
sample in
docs/samples/exactly. Ruby's built-inRandomdoes NOT match CPython — always route seeded randomness throughZer0ImageGenerator::Support::PyRandom(a bit-exact MT19937 + CPython seeding). Draw values in the same order as the Python. - The engine is stdlib-only by policy (no Nokogiri/ActiveSupport in
lib/). - The web app loads the engine via
lib/zer0_image_generator/all.rband drives the sameRunnerthe CLI drives, through the single seamweb/app/services/engine_bridge.rb. Keep engine-coupling in that one file. - Art direction/review is Claude or Grok:
--prompt-engine xai/--review xai(and the matching web form).GrokClientduck-typesAnthropicClient. Same Grok OAuth token as the xAI renderer (XAI_OAUTH_TOKEN,~/.grok/auth.json, or Kilo's~/.local/share/kilo/auth.jsonaccesskey; an expired token whose store holds a refresh token is refreshed and written back — every request goes throughXAIAuth.ready_credential/xai_ready_credential). Jobs take credentials fromAiEnv.snapshot, never ad-hocENV.merge.
Conventions¶
- Conventional Commits:
type(scope): description(feat/fix/docs/refactor/test/chore/ci). - Default branch is
main— branch from it and open a PR; never push to it directly. - README-First, README-Last: read the nearest
README.mdbefore changing a directory, and update it after. - Don't suppress type errors (
as any,@ts-ignore,# type: ignore) or leave empty exception handlers. - The
claudeprovider is an illustration LOOP (plan → author → shape → look → critique → edit;docs/ILLUSTRATION-LOOP.md), Python-only like the provider itself. Its deterministic pieces are ported:svg/text_to_paths.rbis byte-pinned to the oracle's TrueType reader + glyph geometry bytest/ruby/test_text_to_paths.rb, and the loop's settings/flags live insettings.rb/cli.rbso the differential tests stay clean.lint_svg()in the engine is the ONE Python lint —tools/svg/svg-check.pyis a CLI over it. - SVG work (banner template, sanitizer, any
.svg): use the authoring loop intools/svg/— the PostToolUse hook lints + renders every.svgwrite; read the PNG before editing further. Playbook:.claude/skills/svg-art.
Fleet context¶
This repo is one of ~40 managed by the bamr87/bamr87 dash (registry: _data/projects.yml; tiered baseline: docs/STANDARDS.md). It is vendored there as a git submodule: commit and push changes here first — the hub only bumps its pointer afterwards. Shared CI, release, schema, and agent kits are seeded from the hub's templates/; prefer adopting those over hand-rolling equivalents.
Standard deviations¶
UPS-REPO-02— tests live undertest/(Ruby-gem convention, grandfathered).