Skip to content

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

feat(image-gen): add custom (arbitrary) output dimensions to the resolution picker

Adam Eivyfc4d8ed62f4c
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 18277a5504..018def0cf2 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -12,6 +12,8 @@
- **Code Review Defaults can now gate merges on arbitrary GitHub reviewer usernames (e.g. `@CodeReviewbot`).** The Review Loop was limited to a fixed set of reviewer kinds (Copilot, the Claude/Antigravity/Codex CLIs, and the local LM Studio/Ollama backends); there was no way to require a specific GitHub bot or teammate as a PR reviewer. The reviewer picker (AI Providers → Code Review Defaults, plus per-task in the task form and per-task-type in the Schedule config) grows a **"GitHub reviewers (gate merge)"** row where you type any GitHub username or `org/team` slug. Those usernames are appended to slashdo's `--review-with` as `@user` tokens after the keyed reviewers, and the review-loop follow-up agent is instructed to request each as a PR reviewer (`gh pr edit … --add-reviewer`), wait for their review, and treat their approval as a merge gate — end to end through the original-agent completion prompt, the follow-up loop, and the `/do:next` claim flow. Usernames are stored without the `@`, validated against a shell-safe GitHub-username charset (1–39 chars, alphanumeric/hyphen, optional `/team`), case-insensitively deduped, and capped at 20, so a hand-edited `settings.json` can't smuggle in an unsafe or oversized token. They're a distinct class from the behavior reviewers — external PR reviewers that gate the merge, not CLIs that apply fixes — so `--reviewer-applies` never turns on for a username-only addition, and a username reviewer is forge-agnostic (kept even when Copilot is stripped on a non-GitHub forge, and able to drive the loop on its own). New config key: `settings.codeReview.usernames` (+ per-task `metadata.usernames`); no migration needed (absent = none).
+- **Image Gen now supports arbitrary (larger) output dimensions, not just the fixed preset list.** The resolution dropdown gained a **Custom…** entry that reveals Width and Height number inputs, so sizes the presets never covered — e.g. 704×1280 (9:16 portrait) for Z-Image — no longer require adding a new preset. Any edge in 64–3840px is accepted as long as the total stays ≤ 8,294,400px (the same `imageEdgeSchema` + pixel cap the server already enforced); a below-minimum edge snaps up to 64 on blur, and an over-cap total shows an inline warning before you submit. Custom mode also auto-engages whenever the current size matches no preset (a remix, an uploaded init image, or a stale off-backend size), so the exact dimensions stay visible and editable instead of collapsing to a read-only "(custom)" label. The inputs live in the shared `ImageGenControls`, so the Image Gen page, Universe Builder batch render, and the pipeline image-gen drawers all get custom dimensions at once.
+
- **Layered Intelligence now learns from its own results — the feedback loop is closed (#2428).** The LI reasoner used to file improvement proposals as tracker issues and then never read back whether they were merged, rejected, or abandoned, so it proposed in a vacuum (re-suggesting scopes with a 0% adoption rate). LI now records every filed proposal in a lightweight per-app outcome store (`data/cos/li-outcomes/`, a `createCollectionStore` collection with per-slug records and 30-day auto-GC), reconciles each proposal's outcome from the live tracker state on the next run (GitHub `stateReason` maps *not-planned* → rejected, any other close → merged; still-open stays unresolved), and folds a merge-rate report — totals, per-scope adoption, common rejection reasons — back into the reasoning prompt with guidance to prefer higher-merge scopes and justify low-merge ones. Gated behind a new `Proposal outcomes` telemetry source toggle in the per-app LI config (default **on** for the PortOS install, **off** for managed apps). No migration needed — the store is created on first use and existing LI behavior is unchanged when the toggle is off.
- **Audio → MIDI transcription now installs its runtime automatically on first use.** Clicking *Transcribe MIDI* (Rounds reference audio) or *MIDI* (Music Video source track) used to dead-end on a toast telling you to run `INSTALL_MUSCRIPTOR=1 bash scripts/setup-image-video.sh` in a terminal. Now, when the MuScriptor venv isn't provisioned yet, PortOS opens an in-app installer that streams the setup line-by-line — the same experience as the image and video model runtimes — and, on completion, automatically runs the transcription you originally asked for. A new `GET /api/midi-runtime/install` endpoint reuses the shared `RuntimeInstallModal`/SSE-install path (in-flight singleton, detached process group so a cancel kills pip/git children, post-install venv re-probe); `useMidiTranscription` catches the `503 MIDI_RUNTIME_MISSING` kickoff, gates the modal, and retries once installed (with a loop guard so a genuinely-failed install surfaces its error instead of relooping).
diff --git a/client/src/components/imageGen/ImageGenControls.jsx b/client/src/components/imageGen/ImageGenControls.jsx
index 1bfe9a06d2..e2c7834788 100644
--- a/client/src/components/imageGen/ImageGenControls.jsx
+++ b/client/src/components/imageGen/ImageGenControls.jsx
@@ -8,8 +8,12 @@
// reshaping. `mode` drives which knobs are visible: codex hides everything except
// resolution; external swaps guidance for cfgScale; local shows guidance + quantize.
+import { useState } from 'react';
import { Dice5 } from 'lucide-react';
-import { filterResolutions, resolveResolutionLabel } from '../../lib/imageGenResolutions';
+import {
+ filterResolutions, resolveResolutionLabel, clampImageEdge,
+ CUSTOM_RESOLUTION_VALUE, MAX_IMAGE_EDGE, MAX_IMAGE_PIXELS,
+} from '../../lib/imageGenResolutions';
import { randomSeed } from '../../lib/genUtils';
import { RUNNER_FAMILIES } from '../../lib/runnerFamilies';
import { IMAGE_GEN_MODE } from '../../lib/imageGenBackends';
@@ -57,14 +61,38 @@ export default function ImageGenControls({
const isFlux2 = currentModel?.runner === RUNNER_FAMILIES.FLUX2;
// Filter by backend; a stale w/h (e.g. Flux 2 → Flux 1 with 1536 still set)
- // falls through to the (custom) <option> below so the value stays visible
- // until the user picks a supported one.
+ // falls through to the custom inputs below so the value stays visible and
+ // editable until the user picks a supported preset.
const availableResolutions = filterResolutions(mode, currentModel?.runner);
- const { matched, label: resolutionLabel } = resolveResolutionLabel(availableResolutions, width, height);
+ const { matched } = resolveResolutionLabel(availableResolutions, width, height);
+ // Custom mode is sticky once opened (so a preset-matching size the user is
+ // mid-edit doesn't snap the dropdown back to a preset) but also auto-engages
+ // whenever the current dimensions match no preset (remix, uploaded photo, a
+ // stale off-backend size) so the inputs appear without an extra click.
+ const [customOpen, setCustomOpen] = useState(false);
+ const isCustom = customOpen || (!matched && !!width && !!height);
+ const selectValue = isCustom ? CUSTOM_RESOLUTION_VALUE : (matched?.label ?? '');
const handleResolution = (e) => {
+ if (e.target.value === CUSTOM_RESOLUTION_VALUE) { setCustomOpen(true); return; }
const r = availableResolutions.find((opt) => opt.label === e.target.value);
- if (r) onResolutionChange?.(r.w, r.h);
+ if (r) { setCustomOpen(false); onResolutionChange?.(r.w, r.h); }
};
+ // Live edits pass through raw so typing feels natural (0 = mid-edit/empty);
+ // the blur handler clamps to the server's [64, MAX_IMAGE_EDGE] per-edge bounds.
+ const handleCustomDim = (axis, raw) => {
+ const n = Math.floor(Number(raw));
+ // n > 0 already excludes NaN; Infinity can't come from a number input and
+ // would clamp to MAX_IMAGE_EDGE anyway. 0 = mid-edit/empty.
+ const v = n > 0 ? Math.min(MAX_IMAGE_EDGE, n) : 0;
+ if (axis === 'w') onResolutionChange?.(v, height || 0);
+ else onResolutionChange?.(width || 0, v);
+ };
+ const snapCustomDim = (axis) => {
+ if (axis === 'w') onResolutionChange?.(clampImageEdge(width), height || 0);
+ else onResolutionChange?.(width || 0, clampImageEdge(height));
+ };
+ const pixelCount = (width || 0) * (height || 0);
+ const overPixelCap = pixelCount > MAX_IMAGE_PIXELS;
const inputCls = 'w-full bg-port-bg border border-port-border rounded-lg px-2 py-2 text-sm text-white focus:outline-none focus:border-port-accent disabled:opacity-50';
@@ -93,16 +121,50 @@ export default function ImageGenControls({
<FormField label="Resolution" labelClassName="block text-xs font-medium text-gray-400 mb-1">
<select
- value={resolutionLabel}
+ value={selectValue}
onChange={handleResolution}
disabled={disabled}
className={inputCls}
>
{availableResolutions.map((r) => <option key={r.label} value={r.label}>{r.label}</option>)}
- {!matched && resolutionLabel && <option value={resolutionLabel}>{resolutionLabel} (custom)</option>}
+ <option value={CUSTOM_RESOLUTION_VALUE}>Custom…</option>
</select>
</FormField>
+ {/* Arbitrary width/height. The server accepts any edge in [64, 3840] with
+ total pixels ≤ 8.29M (imageEdgeSchema + refineImagePixelCap), so custom
+ sizes like 704×1280 (9:16 portrait) work without a new preset. Step 8
+ keeps values latent-friendly for the local diffusion runners. */}
+ {isCustom && (
+ <>
+ <FormField label="Width" labelClassName="block text-xs font-medium text-gray-400 mb-1">
+ <input
+ type="number" min={64} max={MAX_IMAGE_EDGE} step={8}
+ value={width || ''}
+ onChange={(e) => handleCustomDim('w', e.target.value)}
+ onBlur={() => snapCustomDim('w')}
+ disabled={disabled}
+ className={inputCls}
+ />
+ </FormField>
+ <FormField label="Height" labelClassName="block text-xs font-medium text-gray-400 mb-1">
+ <input
+ type="number" min={64} max={MAX_IMAGE_EDGE} step={8}
+ value={height || ''}
+ onChange={(e) => handleCustomDim('h', e.target.value)}
+ onBlur={() => snapCustomDim('h')}
+ disabled={disabled}
+ className={inputCls}
+ />
+ </FormField>
+ <p className={`col-span-full text-[10px] -mt-1 ${overPixelCap ? 'text-port-error' : 'text-gray-500'}`}>
+ {overPixelCap
+ ? `Too large — ${pixelCount.toLocaleString()} px exceeds the ${MAX_IMAGE_PIXELS.toLocaleString()} px cap. Reduce width or height.`
+ : `Each edge 64–${MAX_IMAGE_EDGE}px, total ≤ ${MAX_IMAGE_PIXELS.toLocaleString()} px. Multiples of 8 render best on local models.`}
+ </p>
+ </>
+ )}
+
{/* Codex's image_gen tool ignores seed/steps/guidance — only resolution
is honored, so the rest of the knobs are hidden in that mode. */}
{!isCodex && showSeed && (
diff --git a/client/src/components/imageGen/ImageGenControls.test.jsx b/client/src/components/imageGen/ImageGenControls.test.jsx
new file mode 100644
index 0000000000..59a56273fc
--- /dev/null
+++ b/client/src/components/imageGen/ImageGenControls.test.jsx
@@ -0,0 +1,55 @@
+import { describe, it, expect, vi } from 'vitest';
+import { render, screen, fireEvent } from '@testing-library/react';
+import ImageGenControls from './ImageGenControls';
+import { IMAGE_GEN_MODE } from '../../lib/imageGenBackends';
+
+const MODELS = [{ id: 'z-image-turbo', name: 'Z-Image-Turbo', runner: 'z_image' }];
+
+// Minimal shared props — every consumer routes resolution through onResolutionChange.
+const baseProps = (overrides = {}) => ({
+ mode: IMAGE_GEN_MODE.LOCAL,
+ models: MODELS,
+ modelId: 'z-image-turbo',
+ onResolutionChange: vi.fn(),
+ ...overrides,
+});
+
+describe('ImageGenControls — custom dimensions', () => {
+ it('hides the width/height inputs when the size matches a preset', () => {
+ render(<ImageGenControls {...baseProps({ width: 1024, height: 1024 })} />);
+ expect(screen.queryByLabelText('Width')).toBeNull();
+ expect(screen.queryByLabelText('Height')).toBeNull();
+ });
+
+ it('reveals width/height inputs when "Custom…" is selected', () => {
+ render(<ImageGenControls {...baseProps({ width: 1024, height: 1024 })} />);
+ fireEvent.change(screen.getByLabelText('Resolution'), { target: { value: '__custom__' } });
+ expect(screen.getByLabelText('Width')).toBeTruthy();
+ expect(screen.getByLabelText('Height')).toBeTruthy();
+ });
+
+ it('auto-shows the inputs when the current size matches no preset (e.g. 704×1280)', () => {
+ render(<ImageGenControls {...baseProps({ width: 704, height: 1280 })} />);
+ expect(screen.getByLabelText('Width').value).toBe('704');
+ expect(screen.getByLabelText('Height').value).toBe('1280');
+ });
+
+ it('emits the new width while preserving height', () => {
+ const onResolutionChange = vi.fn();
+ render(<ImageGenControls {...baseProps({ width: 704, height: 1280, onResolutionChange })} />);
+ fireEvent.change(screen.getByLabelText('Width'), { target: { value: '832' } });
+ expect(onResolutionChange).toHaveBeenLastCalledWith(832, 1280);
+ });
+
+ it('clamps a below-minimum edge up to 64 on blur', () => {
+ const onResolutionChange = vi.fn();
+ render(<ImageGenControls {...baseProps({ width: 10, height: 1280, onResolutionChange })} />);
+ fireEvent.blur(screen.getByLabelText('Width'));
+ expect(onResolutionChange).toHaveBeenLastCalledWith(64, 1280);
+ });
+
+ it('warns when the total pixel count exceeds the cap', () => {
+ render(<ImageGenControls {...baseProps({ width: 3840, height: 3840 })} />);
+ expect(screen.getByText(/exceeds the .* px cap/i)).toBeTruthy();
+ });
+});
diff --git a/client/src/lib/imageGenResolutions.js b/client/src/lib/imageGenResolutions.js
index 95e59c70ac..5f5273ed0d 100644
--- a/client/src/lib/imageGenResolutions.js
+++ b/client/src/lib/imageGenResolutions.js
@@ -70,6 +70,20 @@ export function clampImageDimensions(width, height) {
return { width: snap(w), height: snap(h) };
}
+// Clamp a single hand-typed edge (width or height) to the server's per-edge
+// bounds [64, MAX_IMAGE_EDGE] — mirrors imageEdgeSchema so the custom-dimension
+// inputs can't submit a value that 400s. Non-finite / ≤0 input snaps to the 64
+// floor. Fractional input floors (diffusion runners want integer pixels).
+export function clampImageEdge(value) {
+ const n = Math.floor(Number(value));
+ if (!Number.isFinite(n) || n < 64) return 64;
+ return Math.min(MAX_IMAGE_EDGE, n);
+}
+
+// Sentinel dropdown value for "enter arbitrary width/height" — distinct from
+// any preset label so the resolution <select> can toggle the custom inputs.
+export const CUSTOM_RESOLUTION_VALUE = '__custom__';
+
// Flux 1 (mflux/diffusers, `dev` / `schnell`) has no `runner` field — it's
// the fallback for local mode when nothing more specific matches.
const NATIVE_RUNNER_KEYS = new Set([
diff --git a/client/src/lib/imageGenResolutions.test.js b/client/src/lib/imageGenResolutions.test.js
index 547df33155..104b7b7e3c 100644
--- a/client/src/lib/imageGenResolutions.test.js
+++ b/client/src/lib/imageGenResolutions.test.js
@@ -1,5 +1,33 @@
import { describe, it, expect } from 'vitest';
-import { clampImageDimensions, MAX_IMAGE_EDGE, MAX_IMAGE_PIXELS } from './imageGenResolutions';
+import { clampImageDimensions, clampImageEdge, MAX_IMAGE_EDGE, MAX_IMAGE_PIXELS } from './imageGenResolutions';
+
+describe('clampImageEdge', () => {
+ it('passes valid edges through unchanged', () => {
+ expect(clampImageEdge(704)).toBe(704);
+ expect(clampImageEdge(1280)).toBe(1280);
+ expect(clampImageEdge(64)).toBe(64);
+ expect(clampImageEdge(MAX_IMAGE_EDGE)).toBe(MAX_IMAGE_EDGE);
+ });
+
+ it('snaps below-minimum / non-finite / non-positive input up to the 64 floor', () => {
+ expect(clampImageEdge(0)).toBe(64);
+ expect(clampImageEdge(10)).toBe(64);
+ expect(clampImageEdge(-5)).toBe(64);
+ expect(clampImageEdge(NaN)).toBe(64);
+ expect(clampImageEdge('')).toBe(64);
+ expect(clampImageEdge(undefined)).toBe(64);
+ });
+
+ it('caps oversized edges at MAX_IMAGE_EDGE', () => {
+ expect(clampImageEdge(9999)).toBe(MAX_IMAGE_EDGE);
+ expect(clampImageEdge(MAX_IMAGE_EDGE + 1)).toBe(MAX_IMAGE_EDGE);
+ });
+
+ it('floors fractional input (runners want integer pixels)', () => {
+ expect(clampImageEdge(704.9)).toBe(704);
+ expect(clampImageEdge('1280px'.replace('px', ''))).toBe(1280);
+ });
+});
describe('clampImageDimensions', () => {
const underCaps = (d) =>