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: wire Annotate entry points, route + nav for media images (#2036)

Adam Eivy47f7d28df38c
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 7c3f4b7b98..9588f1e7b1 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -1,5 +1,9 @@
# Unreleased Changes
+## Media
+
+- **Sketch & Annotation Canvas (phase 1): draw over any generated image, save, reload, and export a flattened PNG.** Media History and Collection image cards gained an "Annotate" action that opens a new deep-linkable `/media/annotate/:mediaKey` page — a plain `<canvas>` stroke layer over the image with draw/erase, per-stroke color + brush-size, undo, and clear. Pointer events cover mouse, pen, and touch (`touch-action: none`, so drawing works at 360px phone width without scrolling the page). Strokes persist as a per-image sidecar (`data/media-sketches/`, JSON vectors stored in natural-pixel space so they restore exactly at any display size) plus a flattened PNG export, via a new Zod-validated `GET/PUT /api/media/sketches/:key` (retrievable at `/png`). Reachable from ⌘K and voice ("annotate"/"sketch"). Phases 2 (feed the markup back into img2img re-render) and 3 (blank-canvas storyboard) remain open on #2036.
+
## Dev Tools
- **New interactive Integration Flows doc at `/devtools/flows`.** A single-page visual map of how PortOS packages talk to each other: ~60 components (client pages, client services, routes & sockets, server services, server lib, data stores, external systems) laid out in columns, with 10 documented end-to-end flows — Create Image, Start a Story, Voice Command, CoS Agent Run, Scheduled Task, Start/Stop App (PM2), Shell Session, Run Backup, Peer Sync, and Self-Update. Clicking a flow dims everything else, draws its numbered hops with transport-coded edges (HTTP / SSE / Socket.IO / EventEmitter / process spawn / file+DB I/O), and annotates what's passed at each hop; clicking a node shows its file, role, and the flows it participates in. The renderer (`client/public/flows.html`, dependency-free) is driven entirely by `client/public/flows.json`, so new flows are documented by editing JSON — an integrity test (`client/src/lib/flowsDoc.test.js`) verifies every referenced node/transport resolves and every referenced source file still exists, so refactors can't silently rot the doc. Launchable from the Dev Tools sidebar, ⌘K ("Flows"), and voice nav; selected flow is deep-linkable via `?flow=`, and "Open full screen" opens the standalone doc in a new tab.
diff --git a/client/src/App.jsx b/client/src/App.jsx
index 880f91123d..7c2547aae2 100644
--- a/client/src/App.jsx
+++ b/client/src/App.jsx
@@ -42,6 +42,7 @@ const MediaGen = lazyWithReload(() => import('./pages/MediaGen'));
const ImageGen = lazyWithReload(() => import('./pages/ImageGen'));
const VideoGen = lazyWithReload(() => import('./pages/VideoGen'));
const MediaHistory = lazyWithReload(() => import('./pages/MediaHistory'));
+const MediaAnnotate = lazyWithReload(() => import('./pages/MediaAnnotate'));
const MediaCollections = lazyWithReload(() => import('./pages/MediaCollections'));
const MediaCollectionDetail = lazyWithReload(() => import('./pages/MediaCollectionDetail'));
const MediaCollectionSyncView = lazyWithReload(() => import('./pages/MediaCollectionSyncView'));
@@ -273,6 +274,8 @@ export default function App() {
<Route path="image" element={<ImageGen />} />
<Route path="video" element={<VideoGen />} />
<Route path="history" element={<MediaHistory />} />
+ <Route path="annotate" element={<MediaAnnotate />} />
+ <Route path="annotate/:mediaKey" element={<MediaAnnotate />} />
<Route path="collections" element={<MediaCollections />} />
<Route path="collections/:id" element={<MediaCollectionDetail />} />
<Route path="collections/:id/sync" element={<MediaCollectionSyncView />} />
diff --git a/client/src/components/media/MediaCard.jsx b/client/src/components/media/MediaCard.jsx
index 18f413b63d..47c0dc69d9 100644
--- a/client/src/components/media/MediaCard.jsx
+++ b/client/src/components/media/MediaCard.jsx
@@ -1,5 +1,5 @@
import { useState } from 'react';
-import { Trash2, Download, Film, Image as ImageIcon, Sparkles, Eye, EyeOff, Maximize2, Wand2, Star, MessageSquare } from 'lucide-react';
+import { Trash2, Download, Film, Image as ImageIcon, Sparkles, Eye, EyeOff, Maximize2, Wand2, Star, MessageSquare, Pencil } from 'lucide-react';
import MediaImage from '../MediaImage';
import AddToCollectionMenu from './AddToCollectionMenu';
import PinToMoodBoardMenu from './PinToMoodBoardMenu';
@@ -31,6 +31,7 @@ export default function MediaCard({
starred = false,
hasNote = false,
onToggleStar,
+ onAnnotate,
}) {
const { kind, prompt, modelId, previewUrl, downloadUrl } = item;
const isVideo = kind === 'video';
@@ -146,6 +147,17 @@ export default function MediaCard({
<Wand2 className="w-3 h-3" />
</button>
)}
+ {!isVideo && onAnnotate && (
+ <button
+ type="button"
+ onClick={() => onAnnotate(item)}
+ className="shrink-0 px-1.5 py-1 bg-port-accent/20 hover:bg-port-accent/40 text-port-accent text-[10px] rounded flex items-center justify-center"
+ title="Annotate (draw over this image)"
+ aria-label="Annotate image"
+ >
+ <Pencil className="w-3 h-3" />
+ </button>
+ )}
{!isVideo && onSendToVideo && (
<button
type="button"
diff --git a/client/src/pages/MediaCollectionDetail.jsx b/client/src/pages/MediaCollectionDetail.jsx
index b66443b2d7..11ca1f3048 100644
--- a/client/src/pages/MediaCollectionDetail.jsx
+++ b/client/src/pages/MediaCollectionDetail.jsx
@@ -1,5 +1,5 @@
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
-import { useParams, Link } from 'react-router-dom';
+import { useParams, Link, useNavigate } from 'react-router-dom';
import { ArrowLeft, CheckSquare, Copy, DatabaseZap, FolderInput, Inbox, Lock, Pencil, Star, StarOff, Trash2, X } from 'lucide-react';
import ShareToButton from '../components/sharing/ShareToButton';
import toast from '../components/ui/Toast';
@@ -44,6 +44,7 @@ const hydrate = (collection, imagesByName, videosById) => {
export default function MediaCollectionDetail() {
const { id } = useParams();
+ const navigate = useNavigate();
const isUnsorted = id === UNSORTED_ID;
const [collection, setCollection] = useState(null);
// Full collections list — fetched once for the bulk move/copy picker so it
@@ -521,6 +522,7 @@ export default function MediaCollectionDetail() {
selected={isSelected}
{...getCardProps(key)}
onToggleStar={!selectMode ? toggleStar : undefined}
+ onAnnotate={!selectMode && item.kind === 'image' ? (m) => navigate(`/media/annotate/${encodeURIComponent(m.key)}`) : undefined}
/>
{!selectMode && !isUnsorted && (
<button
diff --git a/client/src/pages/MediaHistory.jsx b/client/src/pages/MediaHistory.jsx
index ad39c3c011..f8e4a1fd60 100644
--- a/client/src/pages/MediaHistory.jsx
+++ b/client/src/pages/MediaHistory.jsx
@@ -5,7 +5,7 @@
*/
import { useState, useEffect, useCallback, useMemo } from 'react';
-import { Link } from 'react-router-dom';
+import { Link, useNavigate } from 'react-router-dom';
import { Combine, Image as ImageIcon, Film, Search, X } from 'lucide-react';
import toast from '../components/ui/Toast';
import MediaCard from '../components/media/MediaCard';
@@ -30,6 +30,7 @@ const FILTERS = [
];
export default function MediaHistory() {
+ const navigate = useNavigate();
const [items, setItems] = useState([]);
const [loading, setLoading] = useState(true);
const [filter, setFilter] = useState('all');
@@ -262,6 +263,7 @@ export default function MediaHistory() {
hideActions={stitchMode}
{...getCardProps(it.key)}
onToggleStar={!stitchMode ? toggleStar : undefined}
+ onAnnotate={!stitchMode && it.kind === 'image' ? (m) => navigate(`/media/annotate/${encodeURIComponent(m.key)}`) : undefined}
/>
);
})}
diff --git a/client/src/services/apiImageVideo.js b/client/src/services/apiImageVideo.js
index fbe613d3aa..fa3fc8488e 100644
--- a/client/src/services/apiImageVideo.js
+++ b/client/src/services/apiImageVideo.js
@@ -218,6 +218,21 @@ export const setMediaAnnotation = (key, patch) => request(`/media/annotations/${
body: JSON.stringify(patch),
});
+// Media sketches — freehand annotation strokes drawn over a generated image,
+// keyed by "<kind>:<ref>" (only image:* is supported in phase 1 of #2036).
+// GET returns `{ key, sketch: { width, height, strokes, updatedAt, hasPng } | null }`.
+// PUT persists strokes + an optional flattened PNG data URL. The persisted PNG
+// is retrievable at GET /media/sketches/:key/png (consumed by phase 2's
+// img2img feedback; the UI's own Export button flattens client-side).
+export const getMediaSketch = (key, { silent = false } = {}) =>
+ request(`/media/sketches/${encodeURIComponent(key)}`, { silent });
+export const saveMediaSketch = (key, payload, { silent = false } = {}) =>
+ request(`/media/sketches/${encodeURIComponent(key)}`, {
+ method: 'PUT',
+ body: JSON.stringify(payload),
+ silent,
+ });
+
// Models management (HF cache + LoRAs)
export const listCachedModels = () => request('/image-video/models');
export const deleteCachedModel = (dirName) => request(`/image-video/models/hf/${encodeURIComponent(dirName)}`, { method: 'DELETE' });
diff --git a/server/lib/navManifest.js b/server/lib/navManifest.js
index 5050e0a206..1c1301175e 100644
--- a/server/lib/navManifest.js
+++ b/server/lib/navManifest.js
@@ -17,6 +17,7 @@ export const NAV_COMMANDS = [
{ id: 'nav.media.image', path: '/media/image', label: 'Image', section: 'Create', aliases: ['image-gen', 'imagegen', 'generate-image', 'sd', 'stable-diffusion'], keywords: ['stable diffusion', 'render', 'art', 'picture', 'photo', 'draw', 'flux', 'mflux'] },
{ id: 'nav.media.video', path: '/media/video', label: 'Video', section: 'Create', aliases: ['video-gen', 'videogen', 'generate-video', 'ltx'], keywords: ['video', 'animate', 'movie', 'clip', 'ltx'] },
{ id: 'nav.media.history', path: '/media/history', label: 'Media History', section: 'Create', aliases: ['media-history', 'video-history'], keywords: ['videos', 'gallery', 'stitch'] },
+ { id: 'nav.media.annotate', path: '/media/annotate', label: 'Annotate', section: 'Create', aliases: ['annotate', 'media-annotate', 'sketch', 'draw-over', 'markup'], keywords: ['annotation', 'sketch', 'draw', 'markup', 'scribble', 'label', 'canvas', 'overlay', 'stroke'] },
{ id: 'nav.media.collections', path: '/media/collections', label: 'Collections', section: 'Create', aliases: ['collections', 'media-collections', 'stacks', 'projects'], keywords: ['bucket', 'group', 'project', 'album', 'organize'] },
{ id: 'nav.media.creative-director', path: '/media/creative-director', label: 'Creative Director', section: 'Create', aliases: ['creative-director', 'creative', 'director', 'long-form', 'episode'], keywords: ['story', 'episode', 'narrative', 'agent', 'auto-video', 'long-form'] },
{ id: 'nav.media.music-video', path: '/media/music-video', label: 'Music Video', section: 'Create', aliases: ['music-video', 'musicvideo', 'music video', 'mv', 'sync-to-beat'], keywords: ['music', 'beat', 'sync', 'audio-reactive', 'director', 'scene board', 'tempo', 'choreography'] },