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
refactor: consolidate duplicate isStr/trimTo helpers
[._.]/ Adam Eivy4da8111581de
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 4170749506..76b4729aed 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -1049,6 +1049,17 @@## Changed+- **DRY: consolidate duplicate `isStr`/`trimTo` helpers.** Six server modules+ (`server/services/pipeline/issues.js`, `server/services/sharing/exporter.js`,+ `server/services/sharing/manifest.js`, `server/services/sharing/importer.js`,+ `server/services/universeBuilder.js`,+ `server/services/universeBuilderRefine.js`, `server/lib/comicScriptParser.js`)+ each redefined the same `isStr = v => typeof v === 'string'` and/or+ `trimTo = (v, max) => isStr(v) ? v.trim().slice(0, max) : ''` one-liners.+ All now import from the canonical exports in `server/lib/storyBible.js`+ (which already had a comment inviting reuse and which ~10 other modules+ already used). Net -10 lines; all 4917 server tests still pass.+- **CI test output is now quiet + fail-fast.** New `server/package.json``test:ci` script (`vitest run --bail=1 --silent=passed-only--reporter=default --reporter=github-actions`) used by `.github/workflows/ci.yml`.diff --git a/server/lib/comicScriptParser.js b/server/lib/comicScriptParser.jsindex b035be4f57..76f451eec7 100644--- a/server/lib/comicScriptParser.js+++ b/server/lib/comicScriptParser.js@@ -15,6 +15,8 @@* null) so downstream template renderers don't need null-guards.* Unexpected text between panels is ignored.*/+import { trimTo } from './storyBible.js';+const PAGE_RE = /^##\s+Page\s+([\dIVX]+)\b/i;// `## Cover concept` — the optional cover-art section the comic-script// template emits before the first `## Page 1` header. Also accepts the@@ -54,8 +56,6 @@ const PANEL_LIMITS = Object.freeze({PAGE_SCRIPT_MAX: 40_000,});-const trimTo = (s, max) => (typeof s === 'string' ? s.trim().slice(0, max) : '');-/*** Parse one panel body — the lines between this panel's header and the next* panel/page header. Combines multi-line field values (Description oftendiff --git a/server/services/pipeline/issues.js b/server/services/pipeline/issues.jsindex 181a92c70d..1a1106c9f7 100644--- a/server/services/pipeline/issues.js+++ b/server/services/pipeline/issues.js@@ -28,6 +28,7 @@ import {import { sanitizeOrigin } from '../../lib/sharingOrigin.js';import { sanitizeVisualStyleRef } from '../../lib/visualStyles.js';import { ARC_ROLES } from '../../lib/storyArc.js';+import { isStr, trimTo } from '../../lib/storyBible.js';import { emitRecordUpdated } from '../sharing/recordEvents.js';// Lazy resolution — see series.js for context.@@ -103,9 +104,6 @@ export function isStageReady(stage) {export const STAGE_STATUSES = Object.freeze(['empty', 'generating', 'ready', 'edited', 'needs-review', 'error']);export const ISSUE_STATUSES = Object.freeze(['draft', 'running', 'needs-review', 'shipped']);-const isStr = (v) => typeof v === 'string';-const trimTo = (v, max) => (isStr(v) ? v.trim().slice(0, max) : '');-const emptyStage = () => ({status: 'empty',input: '',diff --git a/server/services/sharing/exporter.js b/server/services/sharing/exporter.jsindex 2387b23133..3b6e66a463 100644--- a/server/services/sharing/exporter.js+++ b/server/services/sharing/exporter.js@@ -27,10 +27,9 @@ import { getJob } from '../mediaJobQueue/index.js';import { getInstanceId } from '../instances.js';import { getSettings } from '../settings.js';import { getProducedByVersion } from './version.js';+import { isStr } from '../../lib/storyBible.js';import * as os from 'os';-const isStr = (v) => typeof v === 'string';-/** Resolve the bucket-effective display name (per-bucket override → instance setting → OS user). */async function resolveSourceName(bucket) {if (bucket.displayNameOverride) return bucket.displayNameOverride;diff --git a/server/services/sharing/importer.js b/server/services/sharing/importer.jsindex 8187f80593..ec68110b65 100644--- a/server/services/sharing/importer.js+++ b/server/services/sharing/importer.js@@ -33,8 +33,7 @@ import { insertUniverseWithId, updateUniverse, getUniverse } from '../universeBuimport { findOrCreateCollectionByName, addItem as addCollectionItem, ERR_DUPLICATE as COLLECTION_ERR_DUPLICATE } from '../mediaCollections.js';import { adoptImportedSubscription, withReexportSuppressed } from './subscriptions.js';import { getInstanceId } from '../instances.js';--const isStr = (v) => typeof v === 'string';+import { isStr } from '../../lib/storyBible.js';const UNKNOWN_INSTANCE_ID = 'unknown';diff --git a/server/services/sharing/manifest.js b/server/services/sharing/manifest.jsindex 476324ff3b..fb28088ed5 100644--- a/server/services/sharing/manifest.js+++ b/server/services/sharing/manifest.js@@ -19,14 +19,13 @@ import { join } from 'path';import { readdir } from 'fs/promises';import { PATHS, atomicWrite, readJSONFile, ensureDir } from '../../lib/fileUtils.js';import { SHARING_SCHEMA_VERSION, getProducedByVersion } from './version.js';+import { isStr } from '../../lib/storyBible.js';export const MANIFEST_KIND = Object.freeze(['series', 'universe', 'media']);/** @deprecated Use SHARING_SCHEMA_VERSION from ./version.js. Kept exported for back-compat. */export const MANIFEST_SCHEMA_VERSION = SHARING_SCHEMA_VERSION;-const isStr = (v) => typeof v === 'string';-const cursorPath = (bucketId) => join(PATHS.data, 'sharing', 'cursors', `${bucketId}.json`);/**diff --git a/server/services/universeBuilder.js b/server/services/universeBuilder.jsindex a870590b0e..9de7651098 100644--- a/server/services/universeBuilder.js+++ b/server/services/universeBuilder.js@@ -28,7 +28,7 @@ import { PATHS, atomicWrite, readJSONFile, ensureDir } from '../lib/fileUtils.jsimport { composeStyledPrompt } from '../lib/composeStyledPrompt.js';import {sanitizeBibleList, BIBLE_KIND, BIBLE_FIELD, BIBLE_LIMITS, BIBLE_SOURCE,- normalizeBibleName,+ normalizeBibleName, isStr, trimTo,} from '../lib/storyBible.js';import { sanitizeOrigin } from '../lib/sharingOrigin.js';import { emitRecordUpdated, emitRecordDeleted } from './sharing/recordEvents.js';@@ -140,9 +140,6 @@ const resolveCanonForCategory = (categoryKey) =>const DEFAULT_STATE = { universes: [], runs: [] };-const isStr = (v) => typeof v === 'string';-const trimTo = (v, max) => (isStr(v) ? v.trim().slice(0, max) : '');-// Case-insensitive key for matching variation/composite labels across the// original + LLM-refined sets. Returning the same lowercase string ensures// "Lollipop Bureau" and "lollipop bureau" collapse to one identity.diff --git a/server/services/universeBuilderRefine.js b/server/services/universeBuilderRefine.jsindex 25454043de..fdaee1bae5 100644--- a/server/services/universeBuilderRefine.js+++ b/server/services/universeBuilderRefine.js@@ -41,14 +41,12 @@ import {sanitizeInfluences,sanitizeLocked,} from "./universeBuilder.js";+import { trimTo } from "../lib/storyBible.js";const MAX_FEEDBACK = 3000;const MAX_RATIONALE = 1200;const MAX_CHANGES = 8;-const trimTo = (value, max) =>- typeof value === "string" ? value.trim().slice(0, max) : "";-const cleanChanges = (changes) =>Array.isArray(changes)? changes