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

fix(media): raise prompt-length cap to 8k and read HF CLI token cache

Adam Eivyc22d9e04e168
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index cd95c5e1a2..20de46f31d 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -39,9 +39,12 @@ A page-level run dock now slides up from the bottom of the Writers Room while im
- `STORYBOARD_TAB` enum now includes `OBJECTS` between `WORLD` and `SCENES`.
- `ANALYSIS_KINDS` server enum now includes `'objects'`.
- App selectors throughout the UI (task add form, OpenClaw) now list apps alphabetically by name via the shared `AppContextPicker`, instead of preserving the underlying storage order.
+- Image, video, and SD-API prompt/negative-prompt max length bumped from 2,000 → 8,000 chars across `imageGen`, `videoGen`, `sdapi`, and the Creative Director scene schemas. Long Writers Room scene prompts (extracted setting + character + object detail + camera/lighting direction) were hitting the 2k ceiling and getting rejected at the validation layer before reaching the dispatcher.
## Fixed
+- HF token resolution now falls back to `~/.cache/huggingface/token` (written by `hf auth login`) after settings and env vars come up empty, so users who already authenticated through the Hugging Face CLI no longer see the "FLUX.2 access requires Hugging Face token" banner. Resolution order is unchanged otherwise: Settings → `HF_TOKEN` / `HUGGINGFACE_HUB_TOKEN` / `HUGGINGFACEHUB_API_TOKEN` → CLI cache.
+
- Media Gen cards no longer overflow their action button row at narrow widths (6-column `lg:` grid in Image/Video Gen recent-renders). The button strip now uses `flex-wrap` so excess icon buttons spill cleanly onto a second row instead of bleeding past the card border, and the Remix/Continue label truncates instead of forcing the row wider.
- Media Gen "Add to collection" popover is now portalled into `<body>` with viewport-aware fixed positioning, so it stacks above the sidebar and is no longer clipped by the gallery grid's `overflow-auto` parent (previously the menu was getting visually cut off and ducking under the nav). Once a user has 6+ collections, a search filter appears at the top of the menu so big collection lists are addressable by typing instead of scrolling.
- Stale-chunk auto-reload now covers Safari ("Importing a module script failed") and Firefox ("error loading dynamically imported module") in addition to Chrome — previously iOS Safari users hit a "Something went wrong" error after a rebuild and had to tap Refresh manually. Detection is shared between `lazyWithReload` (the primary path) and `ErrorBoundary` (safety net), with a one-reload-per-session guard against infinite loops.
diff --git a/server/lib/hfToken.js b/server/lib/hfToken.js
index 0af63157a5..9b97bd2631 100644
--- a/server/lib/hfToken.js
+++ b/server/lib/hfToken.js
@@ -2,19 +2,34 @@
// over env vars so the user can update from the UI without restarting PortOS.
// huggingface_hub reads HF_TOKEN / HUGGINGFACE_HUB_TOKEN /
// HUGGINGFACEHUB_API_TOKEN — surface all three when injecting into spawn env.
+// Final fallback reads ~/.cache/huggingface/token (written by `hf auth login`)
+// so the FLUX.2 banner doesn't nag users who already authenticated via the CLI.
+import { readFile } from 'node:fs/promises';
+import { homedir } from 'node:os';
+import { join } from 'node:path';
import { getSettings } from '../services/settings.js';
+const HF_CLI_TOKEN_PATH = join(homedir(), '.cache', 'huggingface', 'token');
+
+async function readHfCliToken() {
+ const buf = await readFile(HF_CLI_TOKEN_PATH, 'utf8').catch(() => null);
+ const trimmed = buf?.trim();
+ return trimmed || null;
+}
+
export async function getHfToken() {
const settings = await getSettings();
const stored = settings?.imageGen?.hfToken?.trim?.();
if (stored) return stored;
- return (
+ const envToken = (
process.env.HF_TOKEN ||
process.env.HUGGINGFACE_HUB_TOKEN ||
process.env.HUGGINGFACEHUB_API_TOKEN ||
null
);
+ if (envToken) return envToken;
+ return await readHfCliToken();
}
// Spread into a child_process spawn `env` to give the Python child whichever
diff --git a/server/lib/validation.js b/server/lib/validation.js
index 2912c46cf1..4e75a7efca 100644
--- a/server/lib/validation.js
+++ b/server/lib/validation.js
@@ -867,8 +867,8 @@ export const creativeDirectorSceneSchema = z.object({
sceneId: z.string().min(1).max(64),
order: z.number().int().min(0),
intent: z.string().min(1).max(1000),
- prompt: z.string().min(1).max(2000),
- negativePrompt: z.string().max(2000).optional().default(''),
+ prompt: z.string().min(1).max(8000),
+ negativePrompt: z.string().max(8000).optional().default(''),
durationSeconds: z.number().min(1).max(10),
useContinuationFromPrior: z.boolean().default(false),
sourceImageFile: safeBasename.nullable().optional(),
@@ -898,7 +898,7 @@ export const creativeDirectorSceneUpdateSchema = z.object({
status: z.enum(SCENE_STATUSES).optional(),
retryCount: z.number().int().min(0).max(10).optional(),
renderedJobId: z.string().max(64).nullable().optional(),
- prompt: z.string().min(1).max(2000).optional(),
+ prompt: z.string().min(1).max(8000).optional(),
evaluation: z.object({
score: z.number().min(0).max(1).optional(),
notes: z.string().max(2000).optional(),
diff --git a/server/routes/imageGen.js b/server/routes/imageGen.js
index 57a63d44be..7273d3539f 100644
--- a/server/routes/imageGen.js
+++ b/server/routes/imageGen.js
@@ -37,8 +37,8 @@ const router = Router();
router.get('/style-presets', (_req, res) => res.json(STYLE_PRESETS));
const generateSchema = z.object({
- prompt: z.string().min(1).max(2000),
- negativePrompt: z.string().max(2000).optional(),
+ prompt: z.string().min(1).max(8000),
+ negativePrompt: z.string().max(8000).optional(),
// Per-request backend override. If omitted, the dispatcher uses
// `imageGen.mode` from settings.json.
mode: z.enum(IMAGE_GEN_MODES).optional(),
diff --git a/server/routes/sdapi.js b/server/routes/sdapi.js
index 4999c682ad..97f3a00064 100644
--- a/server/routes/sdapi.js
+++ b/server/routes/sdapi.js
@@ -149,8 +149,8 @@ router.get('/progress', asyncHandler(async (_req, res) => {
// (e.g. defaulting steps=999 from a preset) and we want a clear 400 instead
// of letting bad values through to the dispatcher.
const txt2imgSchema = z.object({
- prompt: z.string().min(1).max(2000),
- negative_prompt: z.string().max(2000).optional().nullable(),
+ prompt: z.string().min(1).max(8000),
+ negative_prompt: z.string().max(8000).optional().nullable(),
width: z.number().int().min(64).max(2048).optional(),
height: z.number().int().min(64).max(2048).optional(),
steps: z.number().int().min(1).max(150).optional(),
diff --git a/server/routes/videoGen.js b/server/routes/videoGen.js
index 588bfa6aa2..36fb14ac9d 100644
--- a/server/routes/videoGen.js
+++ b/server/routes/videoGen.js
@@ -89,8 +89,8 @@ const optionalInt = (min, max, label) => z.preprocess(
z.number().int().refine((n) => n >= min && n <= max, `${label} ${min}..${max}`).optional(),
);
const generateBodySchema = z.object({
- prompt: z.string().min(1).max(2000),
- negativePrompt: z.string().max(2000).optional(),
+ prompt: z.string().min(1).max(8000),
+ negativePrompt: z.string().max(8000).optional(),
modelId: z.string().max(64).optional(),
width: optionalNum(64, 2048, 'width'),
height: optionalNum(64, 2048, 'height'),