Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: direct an AspectRatio to agy so renders stop coming back square
[._.]/ Adam Eivy6fd9e31b85a8
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex b2d394d9b2..1d3d995363 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -2,6 +2,8 @@## Image generation+- **Agy renders now come out the shape you asked for.** Every image generated through the Agy backend came back square — a 1024×1536 comic page, a 16:9 storyboard frame, a portrait character sheet — all of it 1024×1024, silently ignoring the resolution set on the page. Agy's image tool takes an aspect ratio as a separate setting and defaults it to square, and PortOS was only describing the pixel size in the request, which the tool doesn't read. Renders now translate the requested resolution into the closest shape Agy supports and ask for it explicitly, so wide pages come out wide and tall pages come out tall. A size with no exact match snaps to the nearest available shape, and a render that specifies no size at all is left alone. Unrelated: the Agy model field in Settings still selects the *agent* that drives the tool — the image model itself remains fixed on Antigravity's side and is not selectable, no matter what Agy claims when asked.+- **[issue-3231] Each creative surface can now have its own default image backend and model.** A new Defaults tab in Settings → Image Gen lets you pin, per surface — Universe Bible batch renders, character sheets, Series first-pass portraits, sprite references, pipeline visuals, LoRA datasets, and creative-agent renders — which backend (Local, Codex, Grok, or Agy) and, where the backend accepts one, which model that surface renders with. Anything left on Auto keeps following the install-wide default exactly as before, a pinned backend that's disabled safely falls back instead of breaking the surface, and an explicit choice made on a page still wins over the pin. Pinned models now actually reach the renderer on every one of these surfaces — previously they all silently used the provider's own default.- **[issue-3231] Universes, series, and sprites can now each carry their own render backend and model.** A Universe can say "my bible and character-sheet renders go to Codex on this model," a Series can pin the backend its storyboards, comic pages, and covers render on, and a sprite's backend picker now saves onto the sprite itself (with a model field for Codex/Agy) so re-rolls and future sessions keep rendering where you chose. The pin is edited right on each record's page — the Universe Builder's Render tab, the series bible sidebar, and the sprite reference workflow — and layers naturally: an explicit per-batch choice still wins, an unpinned record follows the per-surface default from Settings, and a pinned backend that's since been disabled falls back safely instead of breaking renders. Creative Director first-pass portraits and scene frames now honor the project's existing render-backend pin too. Because a pinned backend is a per-machine capability choice, pins stay on the machine that set them rather than syncing to federated peers that may not have that backend configured.- **[issue-3231] Video renders now follow the same defaults system as images.** Settings → Image Gen → Defaults gains a "Default video backend" pin (Local or Grok) plus per-surface video pins for Music Video and creative-agent renders, so you can say "my music-video clips render on Grok" without touching anything else. Pins are safety-first: a video render never silently upgrades to the paid Grok backend unless you pinned it, a pinned backend that's disabled falls back to Local, and a render that uses Local-only machinery (keyframes, audio-reactive, remix modes) stays Local even under a Grok pin. Grok clips still render only at 6s or 10s with no model choice — so no model picker is offered where none exists.diff --git a/PLAN.md b/PLAN.mdindex 9f7f10a656..f359783b3e 100644--- a/PLAN.md+++ b/PLAN.md@@ -319,6 +319,10 @@ is not reliably announced.- [ ] `client/src/components/imageGen/GalleryImagePicker.jsx` gained an `allowUpload` prop (#2953) that encapsulates the file → `readFileAsBase64` → `uploadGalleryImage` → normalize → select flow inside the shared picker. Three existing callers still roll their own upload path with a separate file `<input>` + `toast` alongside the picker: `client/src/components/music/AlbumsManager.jsx:177`, `client/src/components/music/ArtistsManager.jsx:147`, and `client/src/pages/Authors.jsx:167`. Migrate each to `<GalleryImagePicker allowUpload>` and delete the bespoke upload handlers so the duplication the prop was designed to end actually collapses. Deferred from #2953 (adjacent files outside that issue's scope). Surfaced by the /simplify altitude review.+### Let Agy renders take reference images (it is not text-to-image-only)++- [ ] PortOS treats the Agy backend as text-to-image-only: `server/services/imageGen/prepareParams.js` and `agy.js#generateImage` both hard-400 with `AGY_IMAGE_EDIT_UNSUPPORTED` when an `initImagePath`/`referenceImagePaths` is present, and `I2I_CAPABLE_MODES` (`client/src/lib/imageGenModes.js`) omits agy. That is wrong — dumping `generate_image`'s schema from a live agy 1.1.8 session shows an `ImagePaths` parameter: *"Optional absolute paths to the images to use in generation. You can pass in images here if you would like to edit, combine, or use as references… you cannot pass in more than 3 images."* So agy supports i2i, reference conditioning, and multi-image combination, and PortOS is declining all three. Wire it the way `AspectRatio` was: direct the absolute staging paths in `buildAgyPrompt` (they must be absolute — agy ignores relative paths with no active workspace), cap at 3, drop the 400s, and add agy to `I2I_CAPABLE_MODES` + `pickI2iMode`'s ladder. Note grok's `describeFidelity` phrasing is the precedent for mapping the local runner's numeric `strength` onto words for a CLI with no denoise knob. Verify against pixels, not agy's self-report — it will confidently claim it honored requests it ignored (see `AGY_IMAGEGEN_IMAGE_MODEL` in `services/imageGen/modes.js`). Surfaced while re-probing agy's model-selection channels on 2026-07-30.+### Let the Image Gen "Test Render" panel pick its provider- [ ] `client/src/components/settings/ImageGenTab.jsx` — Test Connection now probes the provider whose sub-tab is open, but the Test tab's `handleRenderTest` still renders with `saved.mode` (the saved default backend). So a user who wants to smoke-test an Agy or Grok render must first make it their default, which is the same friction the Test Connection fix just removed. Add a provider `<select>` to the Test Render panel (default: the saved backend, options limited to enabled backends via `isModeUsable`/`pickUsableMode`'s client mirror), thread the chosen mode into `generateImage({ mode })`, and update the panel copy from "the active backend" to name the selected one. Out of scope for the Test Connection fix (needs new UI, not a re-target of an existing call). Surfaced by the /simplify altitude review.diff --git a/client/src/components/imageGen/ImageGenSettingsForm.jsx b/client/src/components/imageGen/ImageGenSettingsForm.jsxindex 46f0903ddc..a10563e37d 100644--- a/client/src/components/imageGen/ImageGenSettingsForm.jsx+++ b/client/src/components/imageGen/ImageGenSettingsForm.jsx@@ -92,7 +92,7 @@ export default function ImageGenSettingsForm({<p className="text-[10px] text-gray-500 mt-1">Agy's <code className="text-gray-400">generate_image</code> picks the image model internallyand supports text-to-image only. The model in Settings is the <em>agent</em> that drives the- tool. Resolution and style fields apply.+ tool. Style fields apply; resolution maps to the nearest supported aspect ratio.</p>) : null}</div>diff --git a/client/src/components/settings/ImageGenTab.jsx b/client/src/components/settings/ImageGenTab.jsxindex 1cb58267d7..968ce064e5 100644--- a/client/src/components/settings/ImageGenTab.jsx+++ b/client/src/components/settings/ImageGenTab.jsx@@ -1086,11 +1086,12 @@ export function ImageGenTab() {{/* This is the model `agy --model` runs the SESSION on — the agent thatcalls the built-in generate_image tool. Agy exposes no knob for theunderlying image model (generate_image takes Prompt / ImageName /- AspectRatio / ImagePaths and nothing else), so there is no imagen-*- option to pick here — the image model is fixed server-side (see the- read-only row below and AGY_IMAGEGEN_IMAGE_MODEL). An id outside- `agy models` makes agy exit non-zero before generating, which is why- the list is a live probe. */}+ AspectRatio / ImagePaths and nothing else — schema re-dumped from a+ live session 2026-07-30, agy 1.1.8), so there is no imagen-* option to+ pick here — the image model is fixed server-side (see the read-only+ row below and AGY_IMAGEGEN_IMAGE_MODEL). An id outside `agy models`+ makes agy exit non-zero before generating, which is why the list is a+ live probe. */}{!agyModelsError && (<p className="text-xs text-gray-500 mt-1">The agent model Agy runs the session on — it drives the built-in{' '}@@ -1106,7 +1107,8 @@ export function ImageGenTab() {<code className="text-gray-300">{AGY_IMAGEGEN_IMAGE_MODEL}</code>{' '}<span className="text-xs text-gray-500">— chosen by Antigravity server-side; not selectable through the CLI- (no tool parameter, no <code>--model</code> id, prompt requests are ignored).+ (no tool parameter, no <code>--model</code> id, prompt requests are ignored —+ agy will claim it honored one, but the pixels come out identical).</span></p></div>diff --git a/server/services/imageGen/agy.js b/server/services/imageGen/agy.jsindex f6df1eb8b6..fee39e5d0f 100644--- a/server/services/imageGen/agy.js+++ b/server/services/imageGen/agy.js@@ -25,7 +25,7 @@ import { killWithEscalation } from '../../lib/killWithEscalation.js';import { broadcastSse, attachSseClient as attachSse, closeJobAfterDelay } from '../../lib/sseUtils.js';import { imageGenEvents } from '../imageGenEvents.js';import { buildNoImageReason } from './noImageReason.js';-import { AGY_IMAGEGEN_IMAGE_MODEL, IMAGE_GEN_MODE } from './modes.js';+import { AGY_IMAGEGEN_IMAGE_MODEL, IMAGE_GEN_MODE, nearestAgyAspectRatio } from './modes.js';import { withSpawnCwdEnv } from '../../lib/spawnCwd.js';const AGY_TIMEOUT_MS = (() => {@@ -140,11 +140,19 @@ export const noImageReason = (stdoutTail = '') => buildNoImageReason(stdoutTail,export function buildAgyPrompt({ prompt, negativePrompt, width, height, stagingPath }) {const avoid = negativePrompt?.trim() ? `\nAvoid: ${negativePrompt.trim()}` : '';+ // `AspectRatio` is a real generate_image parameter and it defaults to '1:1'.+ // Naming the pixel dimensions alone is not enough — the agent has to be told+ // which ratio to pass, or every render comes back square regardless of the+ // requested size. Directed on its own line so it reads as an instruction to+ // the agent rather than as image content: anything that lands inside the+ // tool's `Prompt` becomes part of what gets drawn.+ const ratio = nearestAgyAspectRatio(width, height);const dimensions = Number(width) > 0 && Number(height) > 0- ? `\nTarget dimensions/aspect: ${Number(width)}×${Number(height)} pixels.`+ ? `\nTarget dimensions: ${Number(width)}×${Number(height)} pixels.`: '';+ const aspect = ratio ? `\nPass AspectRatio "${ratio}" to the tool.` : '';return `Use your built-in generate_image tool to generate exactly one image.-Image prompt: ${prompt.trim()}${avoid}${dimensions}+Image prompt: ${prompt.trim()}${avoid}${dimensions}${aspect}Save the generated image as a PNG file at exactly this path: ${stagingPath}Do not create any other files, do not modify any code or workspace content, and do not run unrelated tools. When the file is written, you are done.`;}diff --git a/server/services/imageGen/agy.test.js b/server/services/imageGen/agy.test.jsindex e894354956..9c3e59518b 100644--- a/server/services/imageGen/agy.test.js+++ b/server/services/imageGen/agy.test.js@@ -143,6 +143,46 @@ describe('agy image provider', () => {expect(sidecar.imageModel).toBe('imagen-3.0-generate-002');});+ // The tool's AspectRatio parameter defaults to '1:1', so a render that names+ // only pixel dimensions comes back square no matter what was asked for —+ // measured against agy 1.1.8 (1024×1024 with no ratio, 1376×768 with 16:9).+ // These lock the directive in place; without it, wide comic pages silently+ // render square.+ describe('buildAgyPrompt aspect ratio', () => {+ const build = (width, height) => agy._internals.buildAgyPrompt({+ prompt: 'a fox', stagingPath: '/tmp/out.png', width, height,+ });++ it.each([+ [1024, 1024, '1:1'],+ [1920, 1080, '16:9'],+ [1080, 1920, '9:16'],+ [1024, 768, '4:3'],+ [768, 1024, '3:4'],+ [1500, 1000, '3:2'],+ [1000, 1500, '2:3'],+ ])('directs the nearest supported ratio for %ix%i', (width, height, ratio) => {+ expect(build(width, height)).toContain(`Pass AspectRatio "${ratio}" to the tool.`);+ });++ it('snaps an unsupported ratio to the closest supported one', () => {+ // 21:9 ultrawide has no exact match — 16:9 is nearest.+ expect(build(2560, 1080)).toContain('Pass AspectRatio "16:9" to the tool.');+ });++ it('omits the directive entirely when dimensions are absent', () => {+ const prompt = agy._internals.buildAgyPrompt({ prompt: 'a fox', stagingPath: '/tmp/out.png' });+ expect(prompt).not.toContain('AspectRatio');+ });++ it('keeps the ratio directive out of the image prompt line', () => {+ // Anything on the "Image prompt:" line becomes part of what gets drawn —+ // a directive that leaks in there is rendered as content.+ const promptLine = build(1920, 1080).split('\n').find((l) => l.startsWith('Image prompt:'));+ expect(promptLine).toBe('Image prompt: a fox');+ });+ });+it('fails closed when the directed output is not an image', async () => {const failed = vi.fn();imageGenEvents.on('failed', failed);diff --git a/server/services/imageGen/grok.js b/server/services/imageGen/grok.jsindex a7a685363b..4523cc88b3 100644--- a/server/services/imageGen/grok.js+++ b/server/services/imageGen/grok.js@@ -45,7 +45,7 @@ import { buildNoImageReason } from './noImageReason.js';import sharp from 'sharp';import { bufferedSpawn, killProcessTree, prepareCliSpawn } from '../../lib/bufferedSpawn.js';import { ensureGrokHeadlessArgs, prepareGrokPromptFile } from '../../lib/grok.js';-import { IMAGE_GEN_MODE, describeFidelity } from './modes.js';+import { IMAGE_GEN_MODE, describeFidelity, nearestAspectRatio } from './modes.js';import { withSpawnCwdEnv } from '../../lib/spawnCwd.js';// 20 minutes — grok's image_gen typically returns in well under a minute, but@@ -68,29 +68,11 @@ let harvestTimeoutMs = DEFAULT_HARVEST_TIMEOUT_MS;// PortOS callers are mapped to the closest of these; a configured default// (`imageGen.grok.aspectRatio`) applies when the caller sent no dimensions.export const GROK_ASPECT_RATIOS = Object.freeze(['1:1', '16:9', '9:16', '4:3', '3:4', '3:2', '2:3']);-const RATIO_VALUES = GROK_ASPECT_RATIOS.map((ratio) => {- const [rw, rh] = ratio.split(':').map(Number);- return { ratio, value: rw / rh };-});// Map a width/height pair to the closest supported grok aspect ratio, or null// when dimensions are absent/invalid (the tool then uses its own default).-export function deriveAspectRatio(width, height) {- const w = Number(width);- const h = Number(height);- if (!Number.isFinite(w) || !Number.isFinite(h) || w <= 0 || h <= 0) return null;- const target = w / h;- let best = null;- let bestDelta = Infinity;- for (const { ratio, value } of RATIO_VALUES) {- const delta = Math.abs(value - target);- if (delta < bestDelta) {- best = ratio;- bestDelta = delta;- }- }- return best;-}+// The mapping itself is shared with agy — see nearestAspectRatio in modes.js.+export const deriveAspectRatio = (width, height) => nearestAspectRatio(width, height, GROK_ASPECT_RATIOS);// Per-job state — keyed by jobId so multiple grok renders can run in parallel// under the mediaJobQueue's cloud lane. Same client shape as imageGen/codex.jsdiff --git a/server/services/imageGen/modes.js b/server/services/imageGen/modes.jsindex 1e75de52e2..933364d807 100644--- a/server/services/imageGen/modes.js+++ b/server/services/imageGen/modes.js@@ -78,18 +78,67 @@ export const CODEX_IMAGEGEN_DEFAULT_EFFORT = 'low';export const AGY_IMAGEGEN_DEFAULT_MODEL = 'gemini-3.5-flash-low';// The image model behind agy's generate_image tool — fixed server-side by-// Antigravity and NOT selectable by PortOS. All three channels were probed and-// closed (2026-07-29, #3231): the tool schema has no model parameter-// (Prompt/ImageName/toolSummary/toolAction/AspectRatio/ImagePaths only);-// `agy --model imagen-3-fast` errors pre-generation ("invalid model-// selection"); and a prompt directive naming imagen-3-fast rendered anyway on-// the default backend, with agy reporting it was "not able to honor" the-// request. Beware: agy itself CLAIMS the --model and prompt-directive routes-// work — it is wrong about both, so do not re-probe on its word. Exported so-// sidecars can record the image model that actually rendered (distinct from-// the agent/session model above) without hardcoding a second copy.+// Antigravity and NOT selectable by PortOS. Re-probed 2026-07-30 against agy+// 1.1.8 and still closed; the decisive evidence is now the tool's own schema,+// dumped from a live session:+//+// { Prompt, ImageName, AspectRatio, ImagePaths, toolAction, toolSummary }+//+// There is no model parameter, so the driving agent has nothing to route a+// model choice through. `agy --model imagen-3-fast` selects the AGENT/session+// model and rejects image-model ids ("invalid model selection"). A prompt+// directive naming a model is worse than a no-op: three runs directing+// imagen-3-fast / gemini-3.5-flash / gemini-2.0-flash all produced identical+// 1376×768 output from the same backend, and the directive text got+// concatenated into the tool's `Prompt` ("…spider web (macro lens) using the+// imagen-3-fast model"), polluting the image prompt itself.+//+// Beware: agy CONFIDENTLY names whichever model you asked for when questioned+// afterward — it reported "gemini-2.0-flash" for a render that came out at+// Imagen's 16:9 geometry. Do not re-probe on its word; probe the pixels.+// Exported so sidecars can record the image model that actually rendered+// (distinct from the agent/session model above) without a second copy.export const AGY_IMAGEGEN_IMAGE_MODEL = 'imagen-3.0-generate-002';+// Aspect ratios agy's generate_image tool accepts via its `AspectRatio`+// parameter — verbatim from the tool schema above. This IS a real knob: a run+// that names no ratio renders at the tool's documented '1:1' default (measured+// 1024×1024) no matter what pixel dimensions the prompt asks for, so a PortOS+// render requesting a wide comic page silently came back square before the+// directive below started naming a ratio.+export const AGY_ASPECT_RATIOS = Object.freeze(['1:1', '2:3', '3:2', '3:4', '4:3', '9:16', '16:9']);++/**+ * Map a pixel width/height onto the closest ratio in `ratios` ('W:H' strings).+ * Returns null when either dimension is missing or non-positive, so the caller+ * omits its ratio directive entirely rather than asserting one the user never+ * chose (each tool then applies its own documented default).+ *+ * Lives here rather than in a provider module because every cloud CLI needs the+ * same mapping against its own alphabet — grok's `deriveAspectRatio` delegates+ * to it, and agy's prompt builder calls it with AGY_ASPECT_RATIOS.+ */+export function nearestAspectRatio(width, height, ratios) {+ const w = Number(width);+ const h = Number(height);+ if (!Number.isFinite(w) || !Number.isFinite(h) || w <= 0 || h <= 0) return null;+ const target = w / h;+ let best = null;+ let bestDelta = Infinity;+ for (const ratio of ratios) {+ const [rw, rh] = ratio.split(':').map(Number);+ const delta = Math.abs((rw / rh) - target);+ if (delta < bestDelta) {+ bestDelta = delta;+ best = ratio;+ }+ }+ return best;+}++/** `nearestAspectRatio` bound to agy's alphabet. */+export const nearestAgyAspectRatio = (width, height) => nearestAspectRatio(width, height, AGY_ASPECT_RATIOS);+// The local runner's fallback model id when neither the request nor// settings.imageGen.local.modelId names one (local.js's parameter default).// Exported so provenance writers (sprite candidate sidecars, #2896) can