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(dashboard): add quick image prompt widget (#449)

[._.]/ Adam Eivy4e2a0b679da8
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 5b4a01b443..5b15fe84e9 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -9,6 +9,7 @@
- **`peerSync` listener** now also subscribes to `recordEvents.deleted` (not just `'updated'`) so soft-deletes propagate via the per-record push pipeline — previously they were stranded for any peer that had a per-record sub (which is most peers under the new auto-subscribe). `retryPendingPushesForPeer` walks every sub (not just unpushed ones) on `peer:online`; the `lastPushedHash` short-circuit inside `pushRecordToPeer` skips the network call for unchanged records, so out-of-band file edits (cleanup scripts, hand-edits) re-propagate on the next reconnect.
New `scripts/cleanup-test-data.js` one-shot soft-deletes records matching a conservative test-fixture name roster (`Test Work`, `Commit U`, `Commit S`, etc. — generic names like `'A'`/`'B'`/`'Live'`/`'Hidden'` deliberately excluded to avoid clobbering real user records), cascading the delete to child issues of each tombstoned series so the orphan-zombie state never materializes. Default is dry-run; `--apply` writes; users restart PM2 afterward to trigger propagation.
+- `quick-image` dashboard widget — a textarea + Generate button that hands the typed prompt off to the Image Gen page via `?prompt=…` (the same query-param the Media History remix flow already consumes). Registered in `widgetRegistry.jsx` and seeded into the default Everything layout in `server/services/dashboardLayouts.js`. Existing installs pick it up via migration `033-seed-quick-image-widget.js`, which inserts the widget at its preferred grid slot below quick-brain when free and appends below the existing grid otherwise; only the built-in `default` layout is touched. `Cmd+Enter` in the textarea submits.
- Federated peer-sync tombstone GC (Stage 5 of 5). New `server/services/sharing/tombstoneGc.js` runs once per 60s sync tick and prunes tombstoned universes / series / issues that every subscribed peer has acked + a 24h grace buffer. The cutoff is `min(now, minAckedAcrossPeers) - 24h`, which collapses the "no peers subscribed" and "peers behind" cases into one formula (Infinity from an empty peer list clamps via `Math.min` to `now`). Issue tombstones use the series ack horizon since issues ride series pushes. Three new exports (`pruneTombstonedUniverses`, `pruneTombstonedSeries`, `pruneTombstonedIssues`) on the record services are mechanical-prune helpers — the GC module owns the policy. `syncOrchestrator` dynamically imports `sweepTombstones` to keep the GC's universe / pipeline / sharing graph off the orchestrator's boot path. Logs only when prune count > 0.
- Federated peer-sync UI + receiver-side asset pull (Stage 4 of 5). New `SyncToPeerButton` (`client/src/components/sharing/SyncToPeerButton.jsx`) appears next to the existing `ShareToButton` on Universe and Series pages — a dropdown of every enabled peer with a check/circle toggle to subscribe/unsubscribe. New `MediaImage` component (`client/src/components/MediaImage.jsx`) wraps `<img>` and renders a "Syncing" placeholder when the asset 404s (peer-pushed records reference UUIDs that haven't been pulled yet); a `peerSync:asset-arrived` socket event swaps the placeholder for the live bytes the moment the receiver's worker lands them. The Instances page now shows a per-peer "Live-pushed records" section listing every active sync subscription with a one-click unsubscribe and a `↩ reverse` badge for subs that were auto-created by an inbound push. New receiver-side `pullMissingAssetsFromPeer` worker in `server/services/sharing/peerSync.js` background-fetches each missing asset from the sender's `/data/{kind-dir}/<filename>` static mount and writes it locally (capped at 100MB per asset, filenames re-validated against path traversal even after the diff already sanitized them). `peerSyncEvents` is wired through `sharing/index.js` to socket clients so the UI updates in real time.
- Federated peer-sync HTTP routes and orchestrator wiring (Stage 3 of 5). New `server/routes/peerSync.js` mounts at `/api/peer-sync` with `POST /push` (receiver-side; wraps `applyIncomingPush` with Zod-validated payload + asset-manifest size cap of 2000), `GET/POST /subscriptions` (list + create local outgoing subs), and `DELETE /subscriptions/:id`. `installPeerSyncListener()` now runs alongside `installSubscriptionListener` in `initSharing` so one `recordEvents 'updated'` fan-out drives both the share-bucket and peer-sync transports. `syncOrchestrator` now consults `listPeerSubscriptions(peerId)` per cycle and skips the snapshot category for any `(peer, kind)` pair where a per-record peer subscription exists (universe-sub → skip 'universe' snapshot; series-sub → skip 'pipeline' snapshot) so the push pipeline owns the wire for subscribed pairs and the 60s loop stops re-applying the same records. Asset static mounts under `/data/{images,image-refs,videos,video-thumbnails}` now pass `acceptRanges: true` explicitly so the receiver's background asset-pull can resume partial downloads over flaky Tailnet links (default of serve-static, now encoded as a contract so it can't accidentally regress).
diff --git a/client/src/components/QuickImagePrompt.jsx b/client/src/components/QuickImagePrompt.jsx
new file mode 100644
index 0000000000..376ae6da25
--- /dev/null
+++ b/client/src/components/QuickImagePrompt.jsx
@@ -0,0 +1,58 @@
+import { useState, useRef } from 'react';
+import { Link, useNavigate } from 'react-router-dom';
+import { Sparkles } from 'lucide-react';
+
+export default function QuickImagePrompt() {
+ const [prompt, setPrompt] = useState('');
+ const [isSubmitting, setIsSubmitting] = useState(false);
+ const submittingRef = useRef(false);
+ const navigate = useNavigate();
+
+ const handleSubmit = (e) => {
+ e?.preventDefault();
+ const text = prompt.trim();
+ if (!text || submittingRef.current) return;
+
+ submittingRef.current = true;
+ setIsSubmitting(true);
+ setPrompt('');
+
+ // ImageGen page's remix-param effect reads ?prompt=… on mount and
+ // strips it from the URL, so the widget can hand off a one-shot
+ // prompt without us coupling to its internal form state.
+ navigate(`/media/image?prompt=${encodeURIComponent(text)}`);
+ };
+
+ return (
+ <div className="bg-port-card border border-port-border rounded-xl p-4 h-full flex flex-col min-h-0">
+ <div className="flex items-center justify-between mb-3 shrink-0">
+ <h3 className="text-sm font-semibold text-white">Quick Image</h3>
+ <Link to="/media/image" className="text-xs text-gray-500 hover:text-port-accent transition-colors">
+ Image Gen &rarr;
+ </Link>
+ </div>
+ <form onSubmit={handleSubmit} className="flex flex-col gap-2 flex-1 min-h-0">
+ <label htmlFor="quick-image-prompt" className="sr-only">Image prompt</label>
+ <textarea
+ id="quick-image-prompt"
+ placeholder="A neon-lit alley at dusk, cinematic, 50mm..."
+ value={prompt}
+ onChange={(e) => setPrompt(e.target.value)}
+ onKeyDown={(e) => {
+ if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) handleSubmit(e);
+ }}
+ rows={3}
+ className="flex-1 min-h-0 px-3 py-2 bg-port-bg border border-port-border rounded-lg text-white text-sm resize-none"
+ />
+ <button
+ type="submit"
+ disabled={!prompt.trim() || isSubmitting}
+ className="flex items-center justify-center gap-2 px-3 py-2 bg-port-accent/20 hover:bg-port-accent/30 text-port-accent rounded-lg text-sm transition-colors disabled:opacity-50 min-h-[40px]"
+ >
+ <Sparkles size={14} />
+ Generate
+ </button>
+ </form>
+ </div>
+ );
+}
diff --git a/client/src/components/dashboard/widgetRegistry.jsx b/client/src/components/dashboard/widgetRegistry.jsx
index 326e4e437c..4a9d0c3128 100644
--- a/client/src/components/dashboard/widgetRegistry.jsx
+++ b/client/src/components/dashboard/widgetRegistry.jsx
@@ -13,6 +13,7 @@ const DecisionLogWidget = lazyWithReload(() => import('../DecisionLogWidget'
const DeathClockWidget = lazyWithReload(() => import('../DeathClockWidget'));
const ProactiveAlertsWidget = lazyWithReload(() => import('../ProactiveAlertsWidget'));
const QuickBrainCapture = lazyWithReload(() => import('../QuickBrainCapture'));
+const QuickImagePrompt = lazyWithReload(() => import('../QuickImagePrompt'));
const QuickTaskWidget = lazyWithReload(() => import('../QuickTaskWidget'));
const ReviewHubCard = lazyWithReload(() => import('../ReviewHubCard'));
const AppsGridWidget = lazyWithReload(() => import('./builtins/AppsGridWidget'));
@@ -37,6 +38,7 @@ const HourlyActivityWidget = lazyWithReload(() => import('./builtins/HourlyActi
// label-free so the dashboard doesn't turn into a wall of HUD chrome.
export const WIDGETS = [
{ id: 'quick-brain', label: 'Quick Brain Capture', Component: QuickBrainCapture, width: 'half', defaultH: 3 },
+ { id: 'quick-image', label: 'Quick Image Prompt', Component: QuickImagePrompt, width: 'half', defaultH: 4 },
{ id: 'quick-task', label: 'Quick Task', Component: QuickTaskWidget, width: 'half', defaultH: 5 },
{ id: 'apps', label: 'Apps Grid', Component: AppsGridWidget, width: 'full', defaultH: 5, module: { id: '03', status: 'APPS', glyph: 'matrix' } },
{ id: 'cos', label: 'Chief of Staff', Component: CosDashboardWidget, width: 'third', defaultH: 6, module: { id: '02', status: 'STAFF', glyph: 'orbit' } },
diff --git a/scripts/migrations/033-seed-quick-image-widget.js b/scripts/migrations/033-seed-quick-image-widget.js
new file mode 100644
index 0000000000..ae6023c0a5
--- /dev/null
+++ b/scripts/migrations/033-seed-quick-image-widget.js
@@ -0,0 +1,97 @@
+/**
+ * Seed the new `quick-image` dashboard widget into the built-in `default`
+ * (Everything) layout for installs that already have a persisted
+ * `data/dashboard-layouts.json`.
+ *
+ * Background:
+ * `server/services/dashboardLayouts.js#DEFAULT_LAYOUTS` only seeds when
+ * the file is missing. Adding a widget to the default layout in code
+ * alone won't reach existing users — this migration walks the file,
+ * finds the built-in `default` layout, and inserts `quick-image` into
+ * its `widgets` list + `grid` if missing. User-renamed copies and
+ * non-default layouts are not touched. Re-runs detect the widget is
+ * already present and skip.
+ */
+
+import { readFile, writeFile } from 'fs/promises';
+import { join } from 'path';
+
+const WIDGET_ID = 'quick-image';
+const WIDGET_W = 3;
+const WIDGET_H = 3;
+
+// Mirror of the geometry in `server/services/dashboardLayouts.js`
+// DEFAULT_LAYOUTS — slot below quick-brain in the capture row. Edits here
+// must match that file or fresh installs + migrated installs diverge.
+const PREFERRED_SLOTS = {
+ default: { x: 0, y: 2 },
+};
+
+function rectsOverlap(a, b) {
+ return a.x < b.x + b.w && b.x < a.x + a.w && a.y < b.y + b.h && b.y < a.y + a.h;
+}
+
+function collidesWith(grid, candidate) {
+ for (const item of grid) {
+ if (rectsOverlap(item, candidate)) return true;
+ }
+ return false;
+}
+
+function pickGridEntry(grid, layoutId) {
+ const preferred = PREFERRED_SLOTS[layoutId];
+ if (preferred) {
+ const candidate = { id: WIDGET_ID, x: preferred.x, y: preferred.y, w: WIDGET_W, h: WIDGET_H };
+ if (!collidesWith(grid, candidate)) return candidate;
+ }
+ const bottom = grid.reduce((max, it) => Math.max(max, (it.y ?? 0) + (it.h ?? 0)), 0);
+ return { id: WIDGET_ID, x: 0, y: bottom, w: WIDGET_W, h: WIDGET_H };
+}
+
+function applyToLayout(layout) {
+ if (!layout || typeof layout !== 'object') return false;
+ if (!Array.isArray(layout.widgets)) return false;
+ if (layout.widgets.includes(WIDGET_ID)) return false;
+ layout.widgets = [...layout.widgets, WIDGET_ID];
+ if (Array.isArray(layout.grid)) {
+ layout.grid = [...layout.grid, pickGridEntry(layout.grid, layout.id)];
+ }
+ return true;
+}
+
+export default {
+ async up({ rootDir }) {
+ const path = join(rootDir, 'data', 'dashboard-layouts.json');
+ const raw = await readFile(path, 'utf-8').catch((err) => {
+ if (err.code === 'ENOENT') return null;
+ throw err;
+ });
+ if (raw == null) {
+ console.log(`📦 migration 033: no dashboard-layouts.json yet — fresh install will seed from defaults.`);
+ return { updated: 0, reason: 'no-state' };
+ }
+ let doc;
+ try { doc = JSON.parse(raw); } catch {
+ console.log(`📦 migration 033: dashboard-layouts.json unreadable — skipping.`);
+ return { updated: 0, reason: 'unreadable' };
+ }
+ if (!doc || !Array.isArray(doc.layouts)) {
+ return { updated: 0, reason: 'no-layouts-array' };
+ }
+
+ let touched = 0;
+ for (const layout of doc.layouts) {
+ if (!layout || layout.id !== 'default') continue;
+ if (applyToLayout(layout)) touched += 1;
+ }
+
+ if (touched === 0) {
+ console.log(`📦 migration 033: quick-image already present in default layout.`);
+ return { updated: 0, reason: 'already-applied' };
+ }
+
+ await writeFile(path, JSON.stringify(doc, null, 2));
+ console.log(`📦 migration 033: seeded quick-image widget into ${touched} built-in layout(s).`);
+ return { updated: touched };
+ },
+};
diff --git a/scripts/migrations/033-seed-quick-image-widget.test.js b/scripts/migrations/033-seed-quick-image-widget.test.js
new file mode 100644
index 0000000000..39d7671c35
--- /dev/null
+++ b/scripts/migrations/033-seed-quick-image-widget.test.js
@@ -0,0 +1,114 @@
+import { describe, it, expect, beforeEach, afterEach } from 'vitest';
+import { mkdtempSync, rmSync, writeFileSync, readFileSync, mkdirSync, existsSync } from 'fs';
+import { tmpdir } from 'os';
+import { join } from 'path';
+
+import migration from './033-seed-quick-image-widget.js';
+
+const writeJson = (path, value) => writeFileSync(path, JSON.stringify(value, null, 2) + '\n');
+const readJson = (path) => JSON.parse(readFileSync(path, 'utf-8'));
+
+describe('migration 033 — seed quick-image widget into default layout', () => {
+ let rootDir;
+ let layoutsPath;
+
+ beforeEach(() => {
+ rootDir = mkdtempSync(join(tmpdir(), 'migration-033-'));
+ mkdirSync(join(rootDir, 'data'), { recursive: true });
+ layoutsPath = join(rootDir, 'data', 'dashboard-layouts.json');
+ });
+
+ afterEach(() => {
+ rmSync(rootDir, { recursive: true, force: true });
+ });
+
+ it('no-ops cleanly when dashboard-layouts.json is missing (fresh install)', async () => {
+ const result = await migration.up({ rootDir });
+ expect(result.updated).toBe(0);
+ expect(result.reason).toBe('no-state');
+ expect(existsSync(layoutsPath)).toBe(false);
+ });
+
+ it('inserts quick-image into the default layout at the preferred slot', async () => {
+ writeJson(layoutsPath, {
+ activeLayoutId: 'default',
+ layouts: [
+ {
+ id: 'default',
+ name: 'Everything',
+ builtIn: true,
+ widgets: ['quick-brain', 'quick-task'],
+ grid: [
+ { id: 'quick-brain', x: 0, y: 0, w: 3, h: 2 },
+ { id: 'quick-task', x: 3, y: 0, w: 5, h: 5 },
+ ],
+ },
+ ],
+ });
+ const result = await migration.up({ rootDir });
+ expect(result.updated).toBe(1);
+ const after = readJson(layoutsPath);
+ const defaultLayout = after.layouts.find((l) => l.id === 'default');
+ expect(defaultLayout.widgets).toContain('quick-image');
+ expect(defaultLayout.grid.find((g) => g.id === 'quick-image')).toEqual({ id: 'quick-image', x: 0, y: 2, w: 3, h: 3 });
+ });
+
+ it('is idempotent — second run is a no-op', async () => {
+ writeJson(layoutsPath, {
+ activeLayoutId: 'default',
+ layouts: [
+ { id: 'default', name: 'Everything', builtIn: true, widgets: ['quick-image'], grid: [{ id: 'quick-image', x: 0, y: 2, w: 3, h: 3 }] },
+ ],
+ });
+ const result = await migration.up({ rootDir });
+ expect(result.updated).toBe(0);
+ expect(result.reason).toBe('already-applied');
+ });
+
+ it('preserves user-renamed layout copies — only touches default id', async () => {
+ writeJson(layoutsPath, {
+ activeLayoutId: 'my-default',
+ layouts: [
+ { id: 'my-default', name: 'My Everything', builtIn: false, widgets: ['quick-task'], grid: [] },
+ { id: 'default', name: 'Everything', builtIn: true, widgets: ['quick-task'], grid: [] },
+ ],
+ });
+ const result = await migration.up({ rootDir });
+ expect(result.updated).toBe(1);
+ const after = readJson(layoutsPath);
+ expect(after.layouts.find((l) => l.id === 'my-default').widgets).toEqual(['quick-task']);
+ expect(after.layouts.find((l) => l.id === 'default').widgets).toContain('quick-image');
+ });
+
+ it('survives an unreadable JSON file', async () => {
+ writeFileSync(layoutsPath, 'not json');
+ const result = await migration.up({ rootDir });
+ expect(result.updated).toBe(0);
+ expect(result.reason).toBe('unreadable');
+ });
+
+ it('appends below existing items when the preferred slot is occupied by user rearrangement', async () => {
+ writeJson(layoutsPath, {
+ activeLayoutId: 'default',
+ layouts: [
+ {
+ id: 'default',
+ name: 'Everything',
+ builtIn: true,
+ widgets: ['quick-brain'],
+ // User dragged quick-brain into the preferred slot.
+ grid: [{ id: 'quick-brain', x: 0, y: 2, w: 3, h: 3 }],
+ },
+ ],
+ });
+ const result = await migration.up({ rootDir });
+ expect(result.updated).toBe(1);
+ const after = readJson(layoutsPath);
+ const newEntry = after.layouts[0].grid.find((g) => g.id === 'quick-image');
+ expect(newEntry).toBeDefined();
+ expect(newEntry.y).toBeGreaterThanOrEqual(5);
+ expect(newEntry.x).toBe(0);
+ expect(newEntry.w).toBe(3);
+ expect(newEntry.h).toBe(3);
+ });
+});
diff --git a/server/services/dashboardLayouts.js b/server/services/dashboardLayouts.js
index 4aa65ecf3a..450742f2e6 100644
--- a/server/services/dashboardLayouts.js
+++ b/server/services/dashboardLayouts.js
@@ -79,7 +79,7 @@ const DEFAULT_LAYOUTS = [
name: 'Everything',
builtIn: true,
widgets: [
- 'quick-brain', 'quick-task',
+ 'quick-brain', 'quick-image', 'quick-task',
'apps',
'cos', 'goal-progress', 'upcoming-tasks',
'proactive-alerts', 'review-hub', 'system-health', 'network-exposure', 'backup', 'death-clock', 'quick-stats', 'decision-log',
@@ -92,6 +92,7 @@ const DEFAULT_LAYOUTS = [
grid: [
// Row 0–4: capture row + tasks
{ id: 'quick-brain', x: 0, y: 0, w: 3, h: 2 },
+ { id: 'quick-image', x: 0, y: 2, w: 3, h: 3 },
{ id: 'quick-task', x: 3, y: 0, w: 5, h: 5 },
{ id: 'upcoming-tasks', x: 8, y: 0, w: 4, h: 5 },
// Row 5–9: primary monitoring + alerts