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
feat([issue-1326]): snap I2V default W×H to the source image's aspect ratio
[._.]/ Adam Eivy2e09c741b576
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex d7095577e1..7dd379a3f6 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -40,6 +40,8 @@## Changed+- **[issue-1326] Picking a source image for image-to-video now snaps the default size to that image's shape.** When you select (or upload) a source image on the Video Gen page, the width × height defaults jump to the closest preset matching the image's aspect ratio — so a vertical photo defaults to a vertical frame and a widescreen still to a widescreen one, instead of getting silently cover-cropped into a mismatched default that cut the subject out of frame. The size fields stay fully editable: once you choose a size yourself (or it arrives from Continue/Remix), the snap steps aside.+- **Deleting a Memory Builder item now reloads the full list from the server instead of splicing it out locally.** `MemoryBuilder`'s delete handler previously dropped just the deleted row optimistically (`setItems(prev => prev.filter(...))`), so the displayed list could drift from server truth whenever the delete had server-side effects beyond removing that one id (re-seeding, ordering, or normalization). It now re-fetches via the existing `loadItems()` after the delete resolves, so the list always reflects what the server actually returns. (`client/src/components/meatspace/post/MemoryBuilder.jsx`)- **Destructive deletes across the app now ask for confirmation, consistently.** Many delete actions — brain memories/people/projects/ideas/admin items, CoS memories/tasks/jobs/agents, digital-twin accounts/goals/stories, life-tracking entries (alcohol, nicotine, eye exams, epigenetic interventions, genome markers, post memories), goals (todos, progress, whole-goal), email/calendar accounts, message drafts, custom CoS jobs, media-queue rows, comic pages, uploaded files — previously deleted immediately on a single trash-icon click, an easy way to lose data with no undo. Each now arms an inline confirm before running, using the discoverable inline-confirm UI (`<InlineConfirmRow>` / `<ConfirmButtonPair>`) PortOS already prefers over a bare two-click-arm. Bulk/"delete everything" surfaces get explicit, strongly-worded confirms too: the **Data Manager** category *Purge* moved off the easy-to-miss two-click banner onto an inline confirm row, and backup-archive deletion, *Clear all completed agents*, and *Delete All* uploads are now gated. A new shared `useConfirmDelete` hook standardizes the "arm one row at a time → confirm → run" pattern so future delete buttons stay consistent. Low-stakes, trivially-reversible clears (notifications, the ignored-version list, draft-only dashboard-widget removal) are intentionally left un-gated to avoid confirmation fatigue. (`client/src/hooks/useConfirmDelete.js`, `client/src/pages/DataManager.jsx`, `client/src/pages/Uploads.jsx`, and the brain / cos / digital-twin / meatspace / goals / messages / calendar / apps / media / pipeline delete call sites)diff --git a/client/src/lib/README.md b/client/src/lib/README.mdindex e5a4c07e1a..b3c2864536 100644--- a/client/src/lib/README.md+++ b/client/src/lib/README.md@@ -50,7 +50,7 @@ grep -i "what you want to do" client/src/lib/README.md| `imageGenDefaults.js` | Shared `DEFAULT_NEGATIVE_PROMPT` used by the Image Gen form and quick-submit entry points. Mirrors server-side default. || `imageGenResolutions.js` | Shared resolution presets for image generation. || `importerDeepLink.js` | The Importer deep-link contract both ways: `buildImporterLink({ universeId, seriesId, seriesName })` builds the `/importer?…` URL a Series Pipeline page navigates to; `resolveImporterDeepLink(...)` reads those params back into the universe + series names the importer matches on. |-| `videoGenResolutions.js` | Shared resolution presets for video generation (companion to image side; LTX-2 latent-friendly sizes). |+| `videoGenResolutions.js` | Shared resolution presets for video generation (companion to image side; LTX-2 latent-friendly sizes) + `snapAspectToImage()` to pick the closest-aspect preset for an I2V source. || `videoTilingOptions.js` | `VIDEO_TILING_OPTIONS` (the `<select>` rows) + `VIDEO_TILING_ENUM_SET` (the value-only Set). Single source consumed by `VideoGen.jsx` and the Remix URL builder in `useMediaPreviewActions`. Mirrors the server's `z.enum` in `server/routes/videoGen.js`. |## Graph & simdiff --git a/client/src/lib/videoGenResolutions.js b/client/src/lib/videoGenResolutions.jsindex 81ad1bcc08..96dfa54a40 100644--- a/client/src/lib/videoGenResolutions.js+++ b/client/src/lib/videoGenResolutions.js@@ -16,3 +16,26 @@ export const VIDEO_RESOLUTIONS = [{ label: '512×512 (1:1)', w: 512, h: 512 },{ label: '768×768 (1:1)', w: 768, h: 768 },];++// Pick the preset whose aspect ratio is closest to a source image's, so an I2V+// default doesn't cover-crop the subject out of a mismatched frame (the server+// resizes the source with force_original_aspect_ratio=increase,crop). Every+// preset is already 64-aligned, so the nearest-aspect preset IS the nearest+// 64-aligned size that matches the image — no rounding needed here. Aspect+// error is compared in log space so a too-wide and an equally-too-tall preset+// are penalised symmetrically. Returns `{ w, h }`, or null when the inputs are+// unusable (non-positive dims / empty preset list) so the caller can no-op.+export const snapAspectToImage = (presets, imgW, imgH) => {+ const w = Number(imgW);+ const h = Number(imgH);+ if (!(w > 0) || !(h > 0) || !Array.isArray(presets) || presets.length === 0) return null;+ const target = w / h;+ let best = null;+ let bestErr = Infinity;+ for (const p of presets) {+ if (!(p?.w > 0) || !(p?.h > 0)) continue;+ const err = Math.abs(Math.log((p.w / p.h) / target));+ if (err < bestErr) { bestErr = err; best = p; }+ }+ return best ? { w: best.w, h: best.h } : null;+};diff --git a/client/src/lib/videoGenResolutions.test.js b/client/src/lib/videoGenResolutions.test.jsnew file mode 100644index 0000000000..56014e2ce1--- /dev/null+++ b/client/src/lib/videoGenResolutions.test.js@@ -0,0 +1,49 @@+import { describe, it, expect } from 'vitest';+import { VIDEO_RESOLUTIONS, snapAspectToImage } from './videoGenResolutions.js';++describe('snapAspectToImage', () => {+ it('snaps a 16:9 landscape source to the 16:9 preset', () => {+ expect(snapAspectToImage(VIDEO_RESOLUTIONS, 1920, 1080)).toEqual({ w: 1024, h: 576 });+ });++ it('snaps a 9:16 vertical source to the 9:16 preset', () => {+ expect(snapAspectToImage(VIDEO_RESOLUTIONS, 1080, 1920)).toEqual({ w: 576, h: 1024 });+ });++ it('snaps a square source to a 1:1 preset', () => {+ const r = snapAspectToImage(VIDEO_RESOLUTIONS, 1000, 1000);+ expect(r.w).toBe(r.h); // 512×512 or 768×768 — both are exact 1:1 matches+ });++ it('snaps a tall portrait source to the portrait preset over a square one', () => {+ // 2:3 photo (e.g. 800×1200) is closer to 512×768 than to 512×512.+ expect(snapAspectToImage(VIDEO_RESOLUTIONS, 800, 1200)).toEqual({ w: 512, h: 768 });+ });++ it('penalises too-wide and too-tall symmetrically (log-space metric)', () => {+ // A 2:1 source and a 1:2 source should not both collapse to the same preset:+ // the wide one lands on a landscape preset, the tall one on a portrait preset.+ const wide = snapAspectToImage(VIDEO_RESOLUTIONS, 2000, 1000);+ const tall = snapAspectToImage(VIDEO_RESOLUTIONS, 1000, 2000);+ expect(wide.w).toBeGreaterThan(wide.h);+ expect(tall.h).toBeGreaterThan(tall.w);+ });++ it('returns null for non-positive or non-finite dimensions', () => {+ expect(snapAspectToImage(VIDEO_RESOLUTIONS, 0, 1080)).toBeNull();+ expect(snapAspectToImage(VIDEO_RESOLUTIONS, 1920, 0)).toBeNull();+ expect(snapAspectToImage(VIDEO_RESOLUTIONS, -10, 10)).toBeNull();+ expect(snapAspectToImage(VIDEO_RESOLUTIONS, NaN, 100)).toBeNull();+ expect(snapAspectToImage(VIDEO_RESOLUTIONS, undefined, undefined)).toBeNull();+ });++ it('returns null for an empty or invalid preset list', () => {+ expect(snapAspectToImage([], 1920, 1080)).toBeNull();+ expect(snapAspectToImage(null, 1920, 1080)).toBeNull();+ });++ it('ignores malformed presets without crashing', () => {+ const presets = [{ w: 0, h: 0 }, { label: 'bad' }, { w: 1024, h: 576 }];+ expect(snapAspectToImage(presets, 1920, 1080)).toEqual({ w: 1024, h: 576 });+ });+});diff --git a/client/src/pages/VideoGen.jsx b/client/src/pages/VideoGen.jsxindex 8ab58c195a..3dda1d65e5 100644--- a/client/src/pages/VideoGen.jsx+++ b/client/src/pages/VideoGen.jsx@@ -67,7 +67,7 @@ import {import LoraPicker from '../components/imageGen/LoraPicker';import { videoLoraFamily, VIDEO_LORA_FAMILIES } from '../lib/runnerFamilies';import { randomSeed } from '../lib/genUtils';-import { VIDEO_RESOLUTIONS } from '../lib/videoGenResolutions';+import { VIDEO_RESOLUTIONS, snapAspectToImage } from '../lib/videoGenResolutions';import { VIDEO_TILING_OPTIONS, VIDEO_TILING_ENUM_SET } from '../lib/videoTilingOptions';import { resolveResolutionLabel } from '../lib/imageGenResolutions';@@ -153,6 +153,13 @@ export default function VideoGen() {const [modelId, setModelId] = useState('');const [width, setWidth] = useState(768);const [height, setHeight] = useState(512);+ // Set once the size has been chosen deliberately — the user picking a preset,+ // or an explicit size arriving via Continue/Remix/restore. While it's false,+ // selecting an I2V source image auto-snaps W×H to the source's aspect ratio+ // (so the default frame doesn't cover-crop the subject). The snap itself does+ // NOT set this, so re-picking a different source still re-snaps until the user+ // takes the size into their own hands.+ const sizeManuallySetRef = useRef(false);const [numFrames, setNumFrames] = useState(121);const [fps, setFps] = useState(24);const [chunks, setChunks] = useState(1);@@ -225,8 +232,8 @@ export default function VideoGen() {useEffect(() => {const w = Number(incomingWidth);const h = Number(incomingHeight);- if (Number.isFinite(w) && w > 0) setWidth(w);- if (Number.isFinite(h) && h > 0) setHeight(h);+ if (Number.isFinite(w) && w > 0) { setWidth(w); sizeManuallySetRef.current = true; }+ if (Number.isFinite(h) && h > 0) { setHeight(h); sizeManuallySetRef.current = true; }}, [incomingWidth, incomingHeight]);// Remix payload from MediaPreview (?modelId=…&numFrames=…&seed=…). Populate@@ -302,6 +309,30 @@ export default function VideoGen() {return () => URL.revokeObjectURL(url);}, [lastImageUpload]);+ // Auto-snap the default W×H to a selected I2V source image's aspect ratio so+ // the server's cover-crop (force_original_aspect_ratio=increase,crop in+ // local.js#resizeImage) doesn't silently cut the subject out of a mismatched+ // frame. Only fires while the user hasn't taken the size into their own hands+ // (sizeManuallySetRef) — the inputs stay fully editable for power users, and+ // the server keeps its own 64-grid clamp. Gallery picks resolve to+ // /data/images/<file>; uploads reuse the object URL built above. The load is+ // async, so guard the apply against a newer pick (cancelled) and a late-+ // arriving manual size change (the ref re-check).+ useEffect(() => {+ if (sizeManuallySetRef.current) return;+ const src = sourceImageFile ? `/data/images/${sourceImageFile}` : sourceUploadUrl;+ if (!src) return;+ let cancelled = false;+ const img = new Image();+ img.onload = () => {+ if (cancelled || sizeManuallySetRef.current) return;+ const snapped = snapAspectToImage(VIDEO_RESOLUTIONS, img.naturalWidth, img.naturalHeight);+ if (snapped) { setWidth(snapped.w); setHeight(snapped.h); }+ };+ img.src = src;+ return () => { cancelled = true; };+ }, [sourceImageFile, sourceUploadUrl]);+const refreshHistory = useCallback(() => {listVideoHistory().then((items) => setHistory(Array.isArray(items) ? items : [])).catch(() => {});}, []);@@ -443,8 +474,8 @@ export default function VideoGen() {// post-load validation effect (`Validate modelId once models are loaded`)// will fall back to defaultModel if the id doesn't end up in the catalog.if (item.modelId) setModelId(item.modelId);- if (item.width) setWidth(item.width);- if (item.height) setHeight(item.height);+ if (item.width) { setWidth(item.width); sizeManuallySetRef.current = true; }+ if (item.height) { setHeight(item.height); sizeManuallySetRef.current = true; }if (item.numFrames) setNumFrames(item.numFrames);if (item.fps) setFps(item.fps);if (item.seed != null) setSeed(String(item.seed));@@ -604,8 +635,8 @@ export default function VideoGen() {if (p.prompt) setPrompt(p.prompt);if (p.negativePrompt) setNegativePrompt(p.negativePrompt);if (p.modelId) setModelId(p.modelId);- if (p.width) setWidth(p.width);- if (p.height) setHeight(p.height);+ if (p.width) { setWidth(p.width); sizeManuallySetRef.current = true; }+ if (p.height) { setHeight(p.height); sizeManuallySetRef.current = true; }if (p.numFrames) setNumFrames(p.numFrames);if (p.fps) setFps(p.fps);if (p.steps != null) setSteps(String(p.steps));@@ -855,7 +886,7 @@ export default function VideoGen() {const handleResolutionChange = (e) => {const r = VIDEO_RESOLUTIONS.find((r) => r.label === e.target.value);- if (r) { setWidth(r.w); setHeight(r.h); }+ if (r) { setWidth(r.w); setHeight(r.h); sizeManuallySetRef.current = true; }};const handleRandomSeed = () => setSeed(randomSeed());