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

improve LoRA caption workbench: VLM suggestions, re-caption-all, auto-sizing fields

[._.]/ Adam Eivyee6c0869f9c0
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 7ab20dbaea..94bb2e9e5f 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -6,12 +6,18 @@
- **Add canon characters / places / objects by hand** — Each canon section in the Universe editor (Cast, Places, Objects) now has an **Add** button next to "Pick from Catalog" — the same manual-add affordance the variation buckets already had. Click it, type a name (and optionally a description), and Save mints a new canon entry you can immediately render, refine, and fill in. The entry lands unlocked (so its inline editors are usable right away), dedupes case-insensitively against existing names, and persists through the same optimistic-append path as the catalog picker — so you no longer have to extract from prose, pick from the catalog, or promote a variation just to start a character. (`client/src/components/universe/UniverseCanonSection.jsx`)
+- **More suggested vision models for LoRA captioning** — Settings → Local LLM's "Image Analysis" category only suggested **LLaVA 7B**, so a user looking for a captioner had nothing better to install and could end up pointing the captioner at a reasoning model (which then burns its whole token budget thinking and returns an empty caption). The catalog now ships the VLMs actually recommended for dataset captioning: **Qwen2.5-VL 7B** (the recommended default) and **32B** (best detail on high-memory machines), **Llama 3.2 Vision 11B**, **MiniCPM-V 2.6 8B**, and **Moondream 1.8B** (tiny/fast) — each installable in one click on Ollama (and LM Studio where a well-known GGUF build exists). (`server/lib/localLlmCatalog.js`)
+
- **Character LoRA training — train consistent character adapters from your universe canon** — Create → Media Gen gains a **Training** tab (`/media/training`) that closes the loop from "character exists in a universe" to "every render of that character looks the same." Per character, a **dataset workbench** builds reference material three ways: batch-generate single-subject training renders from the character's canon descriptors (deterministic view/pose/expression/outfit variation matrix, queued through the normal image lane), upload your own images (normalized to PNG via sharp), or slice the character's existing reference-sheet turnaround into grid crops. A **vision-LLM captioner** (same provider pathway as the voice agent's visual describe) auto-captions every image prefixed with the character's trigger word, with per-image caption editing and re-captioning. Once ≥10 captioned images are ready, **train a FLUX.2 Klein LoRA locally** through one of two engines, picked automatically: mflux's MLX-native trainer (`mflux-train`, mflux ≥0.17 — wrapped by `scripts/train_mflux_lora.py`, preferred on Apple Silicon; the dataset stages in mflux's `NNNN.png`+`NNNN.txt` auto-discovery layout, and quantize/low-ram knobs derive from total RAM so a 48 GB machine trains QLoRA-style instead of OOMing) or a vendored torch/diffusers+peft trainer (`scripts/train_flux2_lora.py` — bf16 bases only, precompute-then-free text/VAE encoding, gradient checkpointing) as the fallback. Either engine exports diffusers-format adapters. Training runs ride the media-job GPU lane (serialized with renders, SSE progress with per-step loss, mid-training sample previews, 30-min idle watchdog, cancel saves a checkpoint). The finished adapter lands in `data/loras/` with a sidecar carrying the character link + trigger word + size-variant compat key (`flux2-4b`/`flux2-9b`), so it appears in the existing LoRA library and picker with the right base-model gating immediately. **Auto-apply:** pipeline comic-page and storyboard renders that match a character with a trained LoRA automatically attach the adapter and weave its trigger word into the prompt (local mode; per-stage opt-out in Generation settings). Character cards in the universe editor and catalog detail pages show a trained-LoRA chip + dataset entry point; trained LoRAs in the library link back to their dataset. Datasets are machine-local (like the LoRA files themselves — never federated) and fully backed up; training checkpoints/caches are excluded as regenerable. Run records live in PostgreSQL (`lora_training_runs`). (`server/services/loraTraining/`, `server/services/loraDatasets.js`, `server/services/loraDatasetGenerate.js`, `server/services/loraDatasetCaption.js`, `server/services/characterLoraResolver.js`, `client/src/pages/LoraTraining.jsx`, `client/src/pages/LoraDatasetDetail.jsx`)
- **Video LoRAs — install LTX-2 LoRAs from HuggingFace and fuse them into Video Gen renders** — LoRA support now extends past image models to the **dgrauet `ltx2` video runtime**. A new **"Install video LoRA from HuggingFace"** box on the LoRA Manager (`/media/loras`) takes any HF repo URL or `org/name` id (e.g. `fal/ltx2.3-audio-reactive-lora`), fetches the repo metadata, picks the `.safetensors`, auto-detects the video family from the repo id / tags / `base_model` (LTX-Video → `ltx-video`), and writes a sidecar — the HuggingFace analogue of the existing Civitai installer (gated repos use your HuggingFace token from Image Gen settings). Video Gen (`/media/video`) gains a **LoRA picker** that appears only on an LTX-2 (`ltx2`) model, filtered to the `ltx-video` family, with per-LoRA strength and a trigger-word append button — the same component the Image Gen page uses. Selected LoRAs fuse into the transformer via the pipeline's `_pending_loras` hook (the exact mechanism upstream's `ltx-2-mlx generate --lora` CLI uses), so they apply across **every** mode — text, image, FFLF, extend, and audio-to-video — including multi-chunk chains. Applied LoRAs are stamped into the video-history entry and round-trip through the resume/Remix flow. Only the `ltx2` runtime can fuse LoRAs today; the route and service reject LoRAs on the legacy `mlx_video` / `wan22` / `hunyuan` runtimes with a clear error. (`server/lib/huggingfaceLora.js`, `server/services/loras.js`, `server/routes/loras.js`, `server/services/videoGen/local.js`, `server/routes/videoGen.js`, `scripts/generate_ltx2.py`, `server/lib/runners.js`, `client/src/lib/runnerFamilies.js`, `client/src/pages/VideoGen.jsx`, `client/src/pages/Loras.jsx`)
## Changed
+- **LoRA dataset caption fields auto-size to their content** — Each image card's caption box was a fixed 3-row textarea, so anything longer than ~3 lines was clipped behind an internal scrollbar (and you had to drag the corner to read it). The caption field now grows to fit its full caption by default — no scrolling, no manual resize — with a comfortable minimum height for short/empty captions. Factored into a reusable `useAutoSizeTextarea` hook + `AutoSizeTextarea` component for any future auto-growing field. (`client/src/components/loraTraining/DatasetImageGrid.jsx`, `client/src/components/ui/AutoSizeTextarea.jsx`, `client/src/hooks/useAutoSizeTextarea.js`)
+
+- **LoRA dataset workbench gains a "Re-caption all" button — re-run every caption through a new model** — "Caption all" already skips images that already have a caption (it only fills in the uncaptioned ones), so there was no one-click way to re-run a whole dataset through a freshly-picked vision model. A new **Re-caption all** button next to it sends `overwrite: true`, re-captioning every ready image with the model chosen in the caption-model picker (overwriting existing captions, including manual edits — the button's tooltip says so). The single-image "Re-caption" button already overwrote one image; this extends the same intent to the whole set. (`client/src/pages/LoraDatasetDetail.jsx`)
+
- **CoS system jobs can now pin their own AI provider + model** — Each autonomous "System Task" (Chief of Staff → Jobs) gains an optional **AI Provider & Model** picker in its create and edit forms, so a heavy refactor job can run on Opus while a lightweight triage job runs on a cheaper/local model — independently, per job, instead of every job inheriting the single active provider. The override is forwarded into the generated task's metadata on both the scheduled and manual-trigger paths, where the agent runner already honors `metadata.provider`/`metadata.model`. Leaving the picker on its defaults preserves the prior behavior (active provider, per-task model selection). Only AI-agent jobs show the picker; shell/script jobs never reach the AI runner. A pinned provider is now resolved *before* the active-provider availability gate, so a job pinned to a healthy provider runs even when the globally active provider is down or unset. (`client/src/components/cos/tabs/JobsTab.jsx`, `server/services/autonomousJobs/crud.js`, `server/services/autonomousJobs/skillTemplates.js`, `server/services/agentProviderResolution.js`, `server/routes/cosJobRoutes.js`, `server/lib/validation.js`)
- **LoRA captioning now guarantees a vision model, lets you pick it, and can pull from your gallery** — Auto-captioning a training dataset used to silently send images to whatever model the local backend defaulted to; a text-only model would fail every image with a cryptic `Model does not support images` 400. The captioner now resolves (and validates) a **vision-capable** model up front: it auto-picks the first installed vision model across Ollama + LM Studio, and fails the whole run with one actionable message if none is installed — instead of N per-image errors. A new **caption-model picker** on the dataset workbench lists your installed vision models (each tagged with its backend) and persists the choice to `settings.loraTraining`, so "Caption all" and per-image re-caption both use it; "Auto" defers to the auto-pick. Vision capability is detected from explicit backend metadata when available (LM Studio's `type: 'vlm'`, Ollama's `vision` capability) and an id heuristic otherwise (`isVisionModel`, mirrored client-side). And a new **"From gallery"** button imports images you've already generated/saved straight into the dataset (multi-select, copied independently so deleting the gallery original won't strand the dataset). (`server/lib/localModelHeuristics.js`, `server/services/loraDatasetCaption.js`, `server/services/loraDatasets.js`, `server/services/localLlm.js`, `client/src/components/loraTraining/CaptionModelPicker.jsx`, `client/src/components/loraTraining/ImportGalleryDialog.jsx`)
diff --git a/client/src/components/loraTraining/DatasetImageGrid.jsx b/client/src/components/loraTraining/DatasetImageGrid.jsx
index d527789a50..7740818305 100644
--- a/client/src/components/loraTraining/DatasetImageGrid.jsx
+++ b/client/src/components/loraTraining/DatasetImageGrid.jsx
@@ -7,6 +7,7 @@ import { useState } from 'react';
import { Loader2, RefreshCw, AlertTriangle } from 'lucide-react';
import toast from '../ui/Toast';
import ConfirmButtonPair from '../ui/ConfirmButtonPair';
+import AutoSizeTextarea from '../ui/AutoSizeTextarea';
import {
updateLoraDatasetImageCaption,
deleteLoraDatasetImage,
@@ -108,18 +109,17 @@ export default function DatasetImageGrid({ dataset, onImagesChange, onCaptionRun
)}
</div>
<div className="p-2 flex flex-col gap-2 flex-1">
- <textarea
+ <AutoSizeTextarea
value={drafts[img.id] ?? img.caption}
onChange={(e) => setDrafts((prev) => ({ ...prev, [img.id]: e.target.value }))}
onBlur={() => saveCaption(img)}
placeholder={img.status === 'ready' ? 'Caption (must include the trigger word)…' : ''}
disabled={img.status !== 'ready'}
- rows={3}
// Per-grid-cell field — a visible label would be noise, so the
// accessible name comes from aria-label (the source + view give
// a screen-reader user enough to tell cells apart).
aria-label={`Caption for ${img.source}${img.variation?.view ? ` ${img.variation.view}` : ''} image`}
- className="w-full bg-port-bg border border-port-border rounded p-2 text-xs text-gray-200 resize-y disabled:opacity-50"
+ className="w-full min-h-[4.5rem] bg-port-bg border border-port-border rounded p-2 text-xs text-gray-200 disabled:opacity-50"
/>
<div className="flex items-center justify-between text-xs">
<button
diff --git a/client/src/components/ui/AutoSizeTextarea.jsx b/client/src/components/ui/AutoSizeTextarea.jsx
new file mode 100644
index 0000000000..a41be42923
--- /dev/null
+++ b/client/src/components/ui/AutoSizeTextarea.jsx
@@ -0,0 +1,20 @@
+import useAutoSizeTextarea from '../../hooks/useAutoSizeTextarea';
+
+/**
+ * Controlled <textarea> that auto-grows to fit its content (no internal scroll,
+ * no hand-resize). Pass a `min-h-*` class for the empty/short floor; the hook
+ * sets the inline height to the content height above that. Forwards every other
+ * textarea prop (value, onChange, onBlur, disabled, placeholder, aria-label…).
+ */
+export default function AutoSizeTextarea({ value, onChange, className = '', ...rest }) {
+ const [ref, resize] = useAutoSizeTextarea(value);
+ return (
+ <textarea
+ ref={ref}
+ value={value}
+ onChange={(e) => { onChange?.(e); resize(); }}
+ className={`resize-none overflow-hidden ${className}`}
+ {...rest}
+ />
+ );
+}
diff --git a/client/src/hooks/README.md b/client/src/hooks/README.md
index 2ed3a87360..77f2059955 100644
--- a/client/src/hooks/README.md
+++ b/client/src/hooks/README.md
@@ -77,6 +77,7 @@ grep -i "what you want to do" client/src/hooks/README.md
|---|---|---|
| `useArmedAction` | Two-click-arm `[armed, fire]` confirmation. | Destructive button needing a confirm tap. (Project memory: user finds this less discoverable — prefer inline confirm rows for new UI.) |
| `useAutoRefetch` | Poll-based refetch on an interval. `{ pollOnly: true }` skips internal data/loading state for side-effect-only callers (returns `{ refetch }` only). | Data needs periodic refresh (no socket / SSE available). |
+| `useAutoSizeTextarea` | `[ref, resize]` — grows a `<textarea>` to fit its content (no scroll / hand-resize); recomputes before paint on value change. | A textarea that should auto-fit content. Prefer the `AutoSizeTextarea` UI component, which wraps this. |
| `useClickOutside` | Fire `onOutside` on mousedown outside a ref. | Popovers, menus, drawers. |
| `useEscapeKey` | `useEscapeKey(active, handler)` — call `handler` on Escape while `active`. | Non-modal dismissables (in-context popovers/cards); Modal owns Esc for true modals. |
| `useCmdKSearch` | `⌘K` open/close state. | Anywhere that needs to toggle the palette. |
diff --git a/client/src/hooks/index.js b/client/src/hooks/index.js
index 0913f8b351..18c4b4fce5 100644
--- a/client/src/hooks/index.js
+++ b/client/src/hooks/index.js
@@ -9,6 +9,7 @@
// === Default-exporting hooks (re-exported as named) ===
export { default as useCityAudio } from './useCityAudio.js';
+export { default as useAutoSizeTextarea } from './useAutoSizeTextarea.js';
export { default as useClickOutside } from './useClickOutside.js';
export { default as useColorMatch } from './useColorMatch.js';
export { default as useContainerWidth } from './useContainerWidth.js';
diff --git a/client/src/hooks/useAutoSizeTextarea.js b/client/src/hooks/useAutoSizeTextarea.js
new file mode 100644
index 0000000000..5000af18ba
--- /dev/null
+++ b/client/src/hooks/useAutoSizeTextarea.js
@@ -0,0 +1,24 @@
+import { useCallback, useLayoutEffect, useRef } from 'react';
+
+/**
+ * Grow a <textarea> to fit its content so the field never scrolls or has to be
+ * hand-resized. Attach the returned `ref` to the textarea; the height is
+ * recomputed before paint whenever `value` changes. `resize` is returned for
+ * the rare case the content changes without `value` (e.g. a font/width reflow)
+ * — call it from a ResizeObserver or after a programmatic mutation.
+ *
+ * Set a floor with a `min-h-*` class on the textarea (CSS `min-height` floors
+ * the inline height this hook sets), and pair it with `resize-none` /
+ * `overflow-hidden` so the browser scrollbar never appears.
+ */
+export default function useAutoSizeTextarea(value) {
+ const ref = useRef(null);
+ const resize = useCallback(() => {
+ const el = ref.current;
+ if (!el) return;
+ el.style.height = 'auto';
+ el.style.height = `${el.scrollHeight}px`;
+ }, []);
+ useLayoutEffect(() => { resize(); }, [value, resize]);
+ return [ref, resize];
+}
diff --git a/client/src/pages/LoraDatasetDetail.jsx b/client/src/pages/LoraDatasetDetail.jsx
index 137d2bfd10..dc7eb3c753 100644
--- a/client/src/pages/LoraDatasetDetail.jsx
+++ b/client/src/pages/LoraDatasetDetail.jsx
@@ -10,7 +10,7 @@
import { useState, useEffect, useMemo, useRef, useCallback } from 'react';
import { useParams, Link } from 'react-router-dom';
import {
- ArrowLeft, Loader2, Upload, Wand2, Scissors, Tags, AlertTriangle, Images,
+ ArrowLeft, Loader2, Upload, Wand2, Scissors, Tags, RefreshCw, AlertTriangle, Images,
} from 'lucide-react';
import toast from '../components/ui/Toast';
import Modal from '../components/ui/Modal';
@@ -259,15 +259,20 @@ export default function LoraDatasetDetail() {
...(captionModel.model ? { model: captionModel.model } : {}),
});
- const captionAll = async () => {
+ // Caption only images that have no caption yet (overwrite: false). Re-caption
+ // all overwrites every ready image's caption with the picked model — the way
+ // to re-run the whole dataset through a newer/better VLM.
+ const startCaption = async (overwrite) => {
setCaptionStarting(true);
try {
- const run = await startLoraCaptionRun(datasetId, captionOptions({ overwrite: false }));
+ const run = await startLoraCaptionRun(datasetId, captionOptions({ overwrite }));
setCaptionRun(run);
} finally {
setCaptionStarting(false);
}
};
+ const captionAll = () => startCaption(false);
+ const recaptionAll = () => startCaption(true);
const expressionOptions = useMemo(
() => (character?.expressions || []).map((e) => e?.name).filter(Boolean),
@@ -381,6 +386,15 @@ export default function LoraDatasetDetail() {
? `Captioning ${captionSse.latest?.done ?? 0}/${captionSse.latest?.total ?? '…'}`
: 'Caption all'}
</button>
+ <button
+ type="button"
+ onClick={recaptionAll}
+ disabled={captionStarting || !!captionRun || !readiness.ready}
+ title="Re-caption every ready image with the selected model — overwrites all existing captions, including manual edits"
+ className="px-3 py-2 text-sm rounded bg-port-card border border-port-border text-gray-300 hover:text-white flex items-center gap-2 disabled:opacity-50"
+ >
+ <RefreshCw className="w-4 h-4" /> Re-caption all
+ </button>
<CaptionModelPicker onChange={onCaptionModelChange} />
</div>
diff --git a/server/lib/localLlmCatalog.js b/server/lib/localLlmCatalog.js
index da2fa60314..4ff1efa1d6 100644
--- a/server/lib/localLlmCatalog.js
+++ b/server/lib/localLlmCatalog.js
@@ -228,6 +228,64 @@ export const LOCAL_LLM_CATALOG = [
ollama: 'gpt-oss:20b',
lmstudio: 'lmstudio-community/gpt-oss-20b-GGUF'
},
+ {
+ key: 'qwen2.5-vl-7b',
+ name: 'Qwen2.5-VL 7B (vision)',
+ category: 'vision',
+ params: '7B',
+ size: '6.0 GB',
+ family: 'qwen',
+ description: 'Strong vision-language model — the recommended default for LoRA dataset captioning.',
+ capabilities: ['chat', 'vision'],
+ ollama: 'qwen2.5vl',
+ lmstudio: 'lmstudio-community/Qwen2.5-VL-7B-Instruct-GGUF'
+ },
+ {
+ key: 'qwen2.5-vl-32b',
+ name: 'Qwen2.5-VL 32B (vision)',
+ category: 'vision',
+ params: '32B',
+ size: '21 GB',
+ family: 'qwen',
+ description: 'Larger Qwen2.5-VL for the most detailed image captions — best on high-memory machines.',
+ capabilities: ['chat', 'vision'],
+ ollama: 'qwen2.5vl:32b',
+ lmstudio: 'lmstudio-community/Qwen2.5-VL-32B-Instruct-GGUF'
+ },
+ {
+ key: 'llama3.2-vision',
+ name: 'Llama 3.2 Vision 11B',
+ category: 'vision',
+ params: '11B',
+ size: '7.9 GB',
+ family: 'llama',
+ description: "Meta's vision-language model for image description and captioning.",
+ capabilities: ['chat', 'vision'],
+ ollama: 'llama3.2-vision'
+ },
+ {
+ key: 'minicpm-v',
+ name: 'MiniCPM-V 2.6 8B (vision)',
+ category: 'vision',
+ params: '8B',
+ size: '5.5 GB',
+ family: 'minicpm',
+ description: 'Efficient vision-language model with strong single-image captioning.',
+ capabilities: ['chat', 'vision'],
+ ollama: 'minicpm-v',
+ lmstudio: 'openbmb/MiniCPM-V-2_6-gguf'
+ },
+ {
+ key: 'moondream',
+ name: 'Moondream 1.8B (vision)',
+ category: 'vision',
+ params: '1.8B',
+ size: '1.7 GB',
+ family: 'moondream',
+ description: 'Tiny, fast vision model for quick captions on modest hardware.',
+ capabilities: ['chat', 'vision'],
+ ollama: 'moondream'
+ },
{
key: 'llava',
name: 'LLaVA 7B (vision)',