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
Merge remote-tracking branch 'origin/main' into next/issue-1309
Adam Eivy98a811f42480
diff --cc .changelog/NEXT.mdindex 6eee63781b,0d80ff1215..6f0f4ee2f6--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@@ -2,8 -2,8 +2,10 @@@## Added+ - **[issue-1300] Editorial checks flag five prose anti-patterns (weak openings, mirror self-description, empty pleasantries, italic thoughts, darlings).** A bundle of line/scene-level checks (Create → Editorial Checks) for the well-known tells that pull readers out. Four are LLM checks over the drafted manuscript: **Weak opening** flags clichéd or mis-placed openers — "he wakes up" / alarm-clock / dream starts, weather-and-scenery preambles, and scenes that begin before the interesting moment; **Mirror self-description** catches the tired trick of a character studying their reflection so the prose can catalog their looks, while leaving reflections that do real story work alone; **Empty greeting / small-talk openings** flags scenes that open on greeting rituals or logistical filler that carry no tension or information, while sparing pleasantries laced with subtext; **Kill your darlings** surfaces precious, self-indulgent passages — showpiece descriptions, digressions, over-explaining, favorite lines that stop the scene — as cut candidates, judged by story need rather than quality (complementing the dead-metaphor check, which targets stock rather than precious prose). The fifth, **Italicized internal thoughts**, is a deterministic, high-precision scan that flags multi-word `*…*` / `_…_` italic thought runs (the prose is already in the character's perspective, so italicizing a thought is a tell) while leaving single-word emphasis, bold, and `snake_case` alone, with a configurable word threshold. All findings anchor a verbatim quote + issue number; the LLM checks ship four new stage prompts (`pipeline-editorial-{opening-start,mirror-description,dialogue-pleasantries,kill-your-darlings}`) that migrate for existing installs (103–106), the deterministic check needs no model. (`server/lib/editorial/{italicThoughts,checkRegistry}.js`) (#1300)++- **[issue-1309] Editorial checks flag thin sensory writing and ungrounded "white-room" scenes.** Two new prose checks (Create → Editorial Checks) target two of the most common reader gripes about flat scene writing. **Sensory balance** reads your drafted manuscript and flags scenes that lean almost entirely on sight while sound, smell, touch, and taste go neglected, plus sensory-bare scenes with almost no concrete grounding at all — naming exactly which sense is missing and suggesting a grounding detail to add. **White-room / ungrounded scene** flags "talking heads in a void": dialogue and action playing out with no setting, no physical blocking, and no spatial grounding the reader can stand in — distinct from sensory balance (which is about *senses*) and scene-component balance (narrative/action/dialogue mix) in that the gap here is specifically *place*. Both read your reverse-outline scene segmentation as context (using each scene's recorded setting as a white-room signal) and **degrade gracefully** to a whole-issue manuscript scan when no outline has been generated yet. Each finding anchors a verbatim quote + issue number so you can jump straight to the spot. Two new stage prompts (`pipeline-editorial-sensory-balance`, `pipeline-editorial-white-room`) ship + migrate for existing installs. (#1309)+- **[issue-1407] The LoRA-training form now exposes the per-run base-quant and low-RAM overrides.** The `baseQuant` (bf16 / 8-bit / 4-bit) and `lowRam` request params landed server-side under #1321 — schema, route threading, and the `LORA_TRAIN_MAX_QUANT_BITS` cap — but the training form had no controls for them, so opting a single run into a heavier or lighter frozen base than its memory-derived tier still meant a code change. The Train-LoRA panel now has two **Base quant** and **Low RAM spill** selects (both defaulting to **Auto**); an explicit pick overrides the tier — still clamped by the install's `LORA_TRAIN_MAX_QUANT_BITS` ceiling — while "Auto" sends an explicit `null` that forces the memory-derived tier. (The `null` is a deliberate clear, not an omitted key: the server re-merges `settings.loraTraining.defaults` into every run, so an omitted key would silently keep a *saved* default — `null` lets "Auto" actually beat one.) The controls only show when the mflux engine is the one that'll run; the torch/FLUX2 path trains the bf16 base and ignores them. (`client/src/components/loraTraining/TrainingPanel.jsx`, `server/lib/validation.js`, #1407)- **Each managed app now declares where its autonomous work items live — PLAN.md, GitHub issues, GitLab issues, or JIRA.** Previously the CoS could only claim work from PLAN.md (`plan-task`) or GitHub issues (`claim-issue`) via separate per-app toggles. A new per-app **Work Tracker** setting (App settings → Edit) makes the work *source* a single explicit choice. It defaults to **Auto**, which resolves from the app's git `origin` host: a github.com remote → GitHub issues, a gitlab.* remote (incl. self-hosted) → GitLab issues, anything else → PLAN.md (JIRA is always an explicit opt-in). A new **`claim-work`** scheduled task is the single-source router: one toggle that, at dispatch, resolves the app's tracker and delegates to the matching claim flow — so the same agent still creates its own `claim/<slug>` worktree, opens its own PR/MR, and cleans up. **GitLab issue claiming is genuinely new**: a `claim-issue-gitlab` prompt drives the full 7-phase `/claim --issues` flow over `glab` issues + merge requests (the GitHub `claim-issue` flow is untouched). The legacy `plan-task` / `claim-issue` / `jira-sprint-manager` task types remain for backward compatibility. New `GET /api/apps/:id/work-tracker` resolves the effective tracker for the UI. (`server/lib/workTracker.js`, `server/services/{cosTaskGenerator,taskSchedule,apps}.js`, `server/services/taskPromptDefaults/prompts.js`, `server/routes/apps.js`, `client/src/components/apps/EditAppModal.jsx`)diff --cc scripts/migrations/107-editorial-sensory-grounding-stages.jsindex 777831b7fe,0000000000..8a625c40d6mode 100644,000000..100644--- a/scripts/migrations/107-editorial-sensory-grounding-stages.js+++ b/scripts/migrations/107-editorial-sensory-grounding-stages.js@@@ -1,93 -1,0 +1,93 @@@+/**+ * Seed the two scene-grounding editorial-check stages into existing installs+ * (#1309).+ *+ * Mirrors `094-object-attachment-check-stages.js`: seeds BOTH new stages in one+ * pass — copies each `.md` template from `data.reference/prompts/stages/` and+ * merges its stage-config entry into `data/prompts/stage-config.json`. Boot runs+ * migrations (server/index.js) but NOT `setup-data.js`, so an upgrade that pulls+ * + `pm2 restart`s (rather than running `update.sh`) would otherwise leave these+ * stages unseeded and the `sensory.balance` / `scene.white-room` editorial checks+ * would throw "Stage not found" the first time they run.+ */++import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';+import { dirname, join } from 'path';++const STAGES = [+ 'pipeline-editorial-sensory-balance',+ 'pipeline-editorial-white-room',+];++export default {+ async up({ rootDir }) {+ const stagesDir = join(rootDir, 'data', 'prompts', 'stages');+ await mkdir(stagesDir, { recursive: true });++ // 1) Copy each prompt template if it isn't already present.+ for (const stageKey of STAGES) {+ const filename = `${stageKey}.md`;+ const dataPath = join(stagesDir, filename);+ const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', filename);++ const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);+ if (exists) {+ console.log(`📝 ${stageKey} prompt: already present`);+ continue;+ }+ const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);+ if (!sampleExists) {+ console.warn(`⚠️ ${stageKey}: sample missing for ${filename} — skipping copy`);+ continue;+ }+ try {+ await copyFile(samplePath, dataPath);+ console.log(`✅ seeded ${filename}`);+ } catch (err) {+ console.warn(`⚠️ ${stageKey}: copy failed for ${filename}: ${err.message}`);+ }+ }++ // 2) Merge each stage-config entry (skip any already present).+ const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');+ const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');+ const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);+ if (!sampleConfigExists) {- console.warn('⚠️ 103-editorial-sensory-grounding-stages: data.reference stage-config.json missing — cannot resolve entries; skipping config write');++ console.warn('⚠️ 107-editorial-sensory-grounding-stages: data.reference stage-config.json missing — cannot resolve entries; skipping config write');+ return;+ }+ try {+ const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));+ const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);+ const installed = installedExists+ ? JSON.parse(await readFile(installedConfigPath, 'utf8'))+ : { stages: {} };+ installed.stages = installed.stages || {};++ let added = 0;+ for (const stageKey of STAGES) {+ if (installed.stages[stageKey]) {+ console.log(`📝 ${stageKey} stage-config: already present`);+ continue;+ }+ if (!sample?.stages?.[stageKey]) {- console.warn(`⚠️ 103-editorial-sensory-grounding-stages: sample stage-config missing ${stageKey} — skipping`);++ console.warn(`⚠️ 107-editorial-sensory-grounding-stages: sample stage-config missing ${stageKey} — skipping`);+ continue;+ }+ installed.stages[stageKey] = sample.stages[stageKey];+ added += 1;+ }++ if (added === 0) {- console.log('📝 103-editorial-sensory-grounding-stages: no stage-config entries to add');++ console.log('📝 107-editorial-sensory-grounding-stages: no stage-config entries to add');+ return;+ }+ await mkdir(dirname(installedConfigPath), { recursive: true });+ await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');+ const action = installedExists ? 'merged' : 'created';- console.log(`📝 103-editorial-sensory-grounding-stages stage-config (${action}): ${added} added`);++ console.log(`📝 107-editorial-sensory-grounding-stages stage-config (${action}): ${added} added`);+ } catch (err) {- console.warn(`⚠️ 103-editorial-sensory-grounding-stages: stage-config merge failed: ${err.message}`);++ console.warn(`⚠️ 107-editorial-sensory-grounding-stages: stage-config merge failed: ${err.message}`);+ }+ },+};diff --cc scripts/migrations/107-editorial-sensory-grounding-stages.test.jsindex ce09292ca2,0000000000..f7c951cba3mode 100644,000000..100644--- a/scripts/migrations/107-editorial-sensory-grounding-stages.test.js+++ b/scripts/migrations/107-editorial-sensory-grounding-stages.test.js@@@ -1,104 -1,0 +1,104 @@@+import { describe, it, expect, beforeEach, afterEach } from 'vitest';+import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';+import { tmpdir } from 'os';+import { join, dirname } from 'path';+import { fileURLToPath } from 'url';+- import migration from './103-editorial-sensory-grounding-stages.js';++import migration from './107-editorial-sensory-grounding-stages.js';++// scripts/migrations/<this> → ../.. is the repo root (matches _testHelpers.js).+const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');++// First-shipment seed migration (mirrors 094/095's two-file seed test) — no MD5+// bookkeeping, so the seed/no-clobber behavior is asserted directly.++const FILES = [+ { filename: 'pipeline-editorial-sensory-balance.md', stageKey: 'pipeline-editorial-sensory-balance', body: '# Sensory balance\n\nshipped body\n', returnsJson: true },+ { filename: 'pipeline-editorial-white-room.md', stageKey: 'pipeline-editorial-white-room', body: '# White room\n\nshipped body\n', returnsJson: true },+];+- describe('migration 103 — seed scene-grounding editorial stages', () => {++describe('migration 107 — seed scene-grounding editorial stages', () => {+ let rootDir;+ let stagesDir;+ let refStagesDir;+ let installedConfigPath;++ const seedReference = ({ withConfig = true } = {}) => {+ for (const { filename, body } of FILES) {+ writeFileSync(join(refStagesDir, filename), body);+ }+ if (withConfig) {+ const refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');+ const stages = {};+ for (const { stageKey, returnsJson } of FILES) {+ stages[stageKey] = { name: stageKey, description: `${stageKey} desc`, model: 'default', returnsJson, variables: [] };+ }+ writeFileSync(refConfigPath, JSON.stringify({ stages }, null, 2) + '\n');+ }+ };++ beforeEach(() => {- rootDir = mkdtempSync(join(tmpdir(), 'migration-103-'));++ rootDir = mkdtempSync(join(tmpdir(), 'migration-107-'));+ stagesDir = join(rootDir, 'data', 'prompts', 'stages');+ refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');+ installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');+ mkdirSync(stagesDir, { recursive: true });+ mkdirSync(refStagesDir, { recursive: true });+ });++ afterEach(() => {+ rmSync(rootDir, { recursive: true, force: true });+ });++ it('seeds both .md templates and merges both stage-config entries on a fresh install', async () => {+ seedReference();++ await expect(migration.up({ rootDir })).resolves.not.toThrow();++ for (const { filename, body } of FILES) {+ expect(readFileSync(join(stagesDir, filename), 'utf8')).toBe(body);+ }+ const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));+ expect(installed.stages['pipeline-editorial-sensory-balance']).toMatchObject({ returnsJson: true });+ expect(installed.stages['pipeline-editorial-white-room']).toMatchObject({ returnsJson: true });+ });++ it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {+ seedReference();+ const customBody = '# CUSTOMIZED — do not overwrite\n';+ for (const { filename } of FILES) {+ writeFileSync(join(stagesDir, filename), customBody);+ }+ writeFileSync(+ installedConfigPath,+ JSON.stringify({ stages: { [FILES[0].stageKey]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',+ );++ await migration.up({ rootDir });++ for (const { filename } of FILES) {+ expect(readFileSync(join(stagesDir, filename), 'utf8')).toBe(customBody);+ }+ const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));+ expect(installed.stages[FILES[0].stageKey]).toEqual({ name: 'user-tuned', model: 'custom' });+ expect(installed.stages[FILES[1].stageKey]).toMatchObject({ name: FILES[1].stageKey });+ });++ it('does not throw when the data.reference samples are missing', async () => {+ await expect(migration.up({ rootDir })).resolves.not.toThrow();+ for (const { filename } of FILES) {+ expect(existsSync(join(stagesDir, filename))).toBe(false);+ }+ });++ it('matches the live shipped stage-config keys + prompt files (drift catch)', () => {+ const refConfig = JSON.parse(+ readFileSync(join(repoRoot, 'data.reference', 'prompts', 'stage-config.json'), 'utf8'),+ );+ for (const { stageKey, filename, returnsJson } of FILES) {+ expect(refConfig.stages[stageKey], `stage-config missing ${stageKey}`).toBeTruthy();+ expect(refConfig.stages[stageKey].returnsJson).toBe(returnsJson);+ expect(existsSync(join(repoRoot, 'data.reference', 'prompts', 'stages', filename))).toBe(true);+ }+ });+});diff --cc server/lib/editorial/checkRegistry.jsindex 0b1ee147da,a29054a67d..211bd86fa0--- a/server/lib/editorial/checkRegistry.js+++ b/server/lib/editorial/checkRegistry.js@@@ -159,16 -160,17 +160,27 @@@ export function authoredSetupPayoffSumm// deterministic siblings (prose.cliches, prose.modifier-stacking) need no stage.export const DEAD_METAPHOR_STAGE = 'pipeline-editorial-dead-metaphor';+ // Stage names for the four LLM prose anti-pattern checks (#1300). Each prompt+ // ships in data.reference/prompts/stages/ + stage-config.json (fresh installs via+ // setup-data.js) and migrates to existing installs via migrations 103–106 (boot+ // runs migrations but NOT setup-data, so the migration is required — see+ // scripts/migrations/103-…js … 106-…js). The deterministic sibling+ // (prose.italic-thoughts) needs no stage.+ export const OPENING_START_STAGE = 'pipeline-editorial-opening-start';+ export const MIRROR_DESCRIPTION_STAGE = 'pipeline-editorial-mirror-description';+ export const DIALOGUE_PLEASANTRIES_STAGE = 'pipeline-editorial-dialogue-pleasantries';+ export const KILL_YOUR_DARLINGS_STAGE = 'pipeline-editorial-kill-your-darlings';++// Stage names for the two scene-grounding LLM checks (#1309): sensory balance+// (all-visual / sensory-bare scenes) and white-room (ungrounded, setting-less+// scenes). Each prompt ships in data.reference/prompts/stages/ + stage-config.json+// (fresh installs via setup-data.js) and migrates to existing installs via- // migration 103 (boot runs migrations but NOT setup-data, so the migration is++// migration 107 (boot runs migrations but NOT setup-data, so the migration is+// required). Both consume the reverse-outline scene segmentation as context and+// degrade to a whole-issue manuscript scan when no outline exists.+export const SENSORY_BALANCE_STAGE = 'pipeline-editorial-sensory-balance';+export const WHITE_ROOM_STAGE = 'pipeline-editorial-white-room';+// Render the authored reader-map cliffhangers (#1298) into a compact text block// the chapter-ending check passes alongside the manuscript so the model// reconciles its DETECTED endings against the issue-boundary tugs the writer