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([issue-4901]): move generation mode vocabulary below services
[._.]/ Adam Eivyebbbba4d1a15
diff --git a/server/lib/README.md b/server/lib/README.mdindex ba2b88614c..a0ffa716ec 100644--- a/server/lib/README.md+++ b/server/lib/README.md@@ -27,6 +27,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub| `agentContextValidation.js` | Shared settings, MCP request/tool input/output schemas, result + approximate-token bounds, source-freshness status, and `advertiseAgentContextTools(scopes)` for the opt-in read-only agent-context surface. || `validation.js` | Catch-all Zod schemas (app/process/provider, social accounts, GitHub, backup/sharing, document/legacy-export) + the `validateRequest` middleware + shared helpers (`optionalBooleanMap`, `isSafeRecordId`, `parseIndexParam`, `parsePagination`). Re-exports the per-domain validation files below so existing deep imports keep working. || `sharedSchemas.js` | Cross-domain Zod fragments that `validation.js` and the per-domain `*Validation.js` files both need, kept in a leaf module so the domain files never import back through `validation.js` (its hoisted `export * from` lines would TDZ). `grokVideoDurationSchema` (grok clip-length union), `cloudModelIdString(message)` (cloud-CLI model-id charset/bounds), `recordRenderPinFields` (the `imageMode`/`imageModelId` per-record render pin pair), and `isSafeSubdirFilter(v)` (relative path with no wildcard, `..` segment, or leading `/`), and `csvIdsParam({ max, maxIdLength, truncate })` (the `?ids=a,b,c` batch-by-id query param: trims, drops empties, reads all-blank as absent, and either 400s or silently slices an over-cap batch). |+| `generationModes.js` | Shared immutable image/video render-backend alphabets (`IMAGE_GEN_MODE[S]`, `QUEUEABLE_IMAGE_MODES`, `VIDEO_GEN_MODE[S]`, and cloud subsets), kept below both validation and generation services so schemas never import orchestration modules. || `agentOutputMarkers.js` | Status lines PortOS itself appends to an agent's output buffer: `SENTINEL_COMPLETION_MARKER` (the line `ingestDoneSentinel` writes just before the agent's `.agent-done` summary) plus `isAgentLifecycleLine(line)`/`stripLifecycleLines(lines)`, which match PortOS's telemetry on its actual message shapes rather than on a leading emoji (an agent's own summary may well start a line with `✅`). Pure — shared by the emitter (`services/agentTuiSpawning.js`) and by readers that must show only the agent's own words (notably the generated PR description). || `agentRunEvents.js` | CoS run lifecycle-event envelope (#4540) — pure half of the append-only ledger in `services/agentRunEventLog.js`. `AGENT_RUN_EVENT_KINDS` (closed vocabulary: spawned, handoff, output, reconnected, paused, resumed, interrupted, pr-verified, orphan-recovered, runner-recovered, finalized), `agentRunEventSchema` (Zod, `.strict()`), `buildRunEvent()` which redacts then mints a CONTENT-derived `eventId` (sha256 of the canonicalized envelope) so a redelivered lifecycle transition dedupes instead of double-counting, `redactRunEventData()` (drops prompt/description/output/result-class keys to a `{ redacted, chars }` stub, scrubs the home-dir prefix out of every remaining string via `scrubHomePath`, runs `redactOutput`, and caps string/array/key/depth per `RUN_EVENT_LIMITS`), and `projectRunStates()` — the clock-free fold that derives current run status from the ordered stream, so replay-after-restart and read-current-status are one code path. Unknown kinds fold as no-ops so a newer install's ledger replays on an older one. || `agentRunReconcile.js` | CoS run reconciliation (#4540) — pure diff between a ledger projection (`projectRunStates`) and the durable run record. Closed finding vocabulary `RUN_RECONCILE_FINDINGS` (`record-open`, `record-missing`, `verdict-mismatch`, `ledger-open`), `diffRunRecord()`, `reconcileRunRecords()` with a zero-filled per-kind summary, and `planRunRecordRepair()` — the metadata patch that closes a record the ledger proves is finished. Repairs are one-directional (ledger → record) by design: a record closed while the ledger missed the close is reported, never back-filled, so the stream stays an audit of the record rather than a copy of it. I/O half: `services/agentRunReconciler.js`. |diff --git a/server/lib/creativeCommissionValidation.js b/server/lib/creativeCommissionValidation.jsindex 308a3327aa..1b0fc4f7fc 100644--- a/server/lib/creativeCommissionValidation.js+++ b/server/lib/creativeCommissionValidation.js@@ -1,6 +1,5 @@import { z } from 'zod';-import { QUEUEABLE_IMAGE_MODES } from '../services/imageGen/modes.js';-import { VIDEO_GEN_MODES } from '../services/videoGen/modes.js';+import { QUEUEABLE_IMAGE_MODES, VIDEO_GEN_MODES } from './generationModes.js';import { RENDER_TARGET_BACKEND_AUTO } from './renderTargets.js';import { recurrenceRuleSchema } from './recurrenceValidation.js';diff --git a/server/lib/generationModes.js b/server/lib/generationModes.jsnew file mode 100644index 0000000000..c448e9085b--- /dev/null+++ b/server/lib/generationModes.js@@ -0,0 +1,42 @@+/**+ * Shared image/video render-backend alphabets.+ *+ * These constants sit below both validation and the generation services so a+ * schema can enumerate a backend without importing service-layer orchestration.+ * The service mode modules re-export the same bindings for compatibility.+ */++export const IMAGE_GEN_MODE = Object.freeze({+ EXTERNAL: 'external',+ LOCAL: 'local',+ CODEX: 'codex',+ GROK: 'grok',+ AGY: 'agy',+});++export const IMAGE_GEN_MODES = Object.freeze(Object.values(IMAGE_GEN_MODE));++// Cloud-CLI image backends spend remote quota and run through the media queue's+// parallel cloud lane rather than the local accelerator lane.+export const CLOUD_IMAGE_GEN_MODES = Object.freeze([+ IMAGE_GEN_MODE.CODEX,+ IMAGE_GEN_MODE.GROK,+ IMAGE_GEN_MODE.AGY,+]);++// The external SD-API backend remains synchronous; every other image backend+// can be queued through mediaJobQueue.+export const QUEUEABLE_IMAGE_MODES = Object.freeze([+ IMAGE_GEN_MODE.LOCAL,+ ...CLOUD_IMAGE_GEN_MODES,+]);++// Video deliberately shares the image backend discriminator namespace. Local+// video's text/image/fflf modes are a separate semantic value carried elsewhere.+export const VIDEO_GEN_MODE = Object.freeze({+ LOCAL: IMAGE_GEN_MODE.LOCAL,+ GROK: IMAGE_GEN_MODE.GROK,+});++export const VIDEO_GEN_MODES = Object.freeze(Object.values(VIDEO_GEN_MODE));+export const CLOUD_VIDEO_GEN_MODES = Object.freeze([VIDEO_GEN_MODE.GROK]);diff --git a/server/lib/generationModes.test.js b/server/lib/generationModes.test.jsnew file mode 100644index 0000000000..ab0fe1267e--- /dev/null+++ b/server/lib/generationModes.test.js@@ -0,0 +1,31 @@+import { describe, expect, it } from 'vitest';+import {+ CLOUD_IMAGE_GEN_MODES,+ CLOUD_VIDEO_GEN_MODES,+ IMAGE_GEN_MODE,+ IMAGE_GEN_MODES,+ QUEUEABLE_IMAGE_MODES,+ VIDEO_GEN_MODE,+ VIDEO_GEN_MODES,+} from './generationModes.js';++describe('generation mode alphabets', () => {+ it('derives immutable image mode lists from the shared discriminator', () => {+ expect(IMAGE_GEN_MODES).toEqual(['external', 'local', 'codex', 'grok', 'agy']);+ expect(CLOUD_IMAGE_GEN_MODES).toEqual(['codex', 'grok', 'agy']);+ expect(QUEUEABLE_IMAGE_MODES).toEqual(['local', 'codex', 'grok', 'agy']);+ expect([+ IMAGE_GEN_MODE,+ IMAGE_GEN_MODES,+ CLOUD_IMAGE_GEN_MODES,+ QUEUEABLE_IMAGE_MODES,+ ].every(Object.isFrozen)).toBe(true);+ });++ it('keeps the video backend alphabet in the image discriminator namespace', () => {+ expect(VIDEO_GEN_MODE).toEqual({ LOCAL: IMAGE_GEN_MODE.LOCAL, GROK: IMAGE_GEN_MODE.GROK });+ expect(VIDEO_GEN_MODES).toEqual(['local', 'grok']);+ expect(CLOUD_VIDEO_GEN_MODES).toEqual(['grok']);+ expect([VIDEO_GEN_MODE, VIDEO_GEN_MODES, CLOUD_VIDEO_GEN_MODES].every(Object.isFrozen)).toBe(true);+ });+});diff --git a/server/lib/index.js b/server/lib/index.jsindex e6869a6d23..4a060f2609 100644--- a/server/lib/index.js+++ b/server/lib/index.js@@ -348,6 +348,7 @@ export * from './planIds.js';export * from './markdownText.js';export * from './renderSlot.js';export * from './renderTargets.js';+export * from './generationModes.js';export * from './telegramClient.js';export * from './tempPathGuard.js';export * from './textUtils.js';diff --git a/server/lib/renderTargets.parity.test.js b/server/lib/renderTargets.parity.test.jsindex 2768043b1f..d20944742c 100644--- a/server/lib/renderTargets.parity.test.js+++ b/server/lib/renderTargets.parity.test.js@@ -16,9 +16,8 @@import { describe, it, expect } from 'vitest';import { RENDER_TARGET, RENDER_TARGETS, RENDER_TARGET_BACKEND_AUTO } from './renderTargets.js';-import {- CLOUD_IMAGE_GEN_MODES, EDIT_INCAPABLE_IMAGE_MODES, IMAGE_GEN_MODES,-} from '../services/imageGen/modes.js';+import { CLOUD_IMAGE_GEN_MODES, IMAGE_GEN_MODES } from './generationModes.js';+import { EDIT_INCAPABLE_IMAGE_MODES } from '../services/imageGen/modes.js';import { cloudPromptRequired, maxInputImages } from '../services/imageGen/cloudProviderConfig.js';// Import the node-safe leaf, NOT imageGenBackends.js — that module imports// lucide-react, which is not installed in the server CI job (this exact importdiff --git a/server/lib/sharedSchemas.js b/server/lib/sharedSchemas.jsindex ad5bef6df5..b29dd5b670 100644--- a/server/lib/sharedSchemas.js+++ b/server/lib/sharedSchemas.js@@ -1,6 +1,6 @@import { z } from 'zod';import { RENDER_TARGET_BACKEND_AUTO, RECORD_RENDER_MODEL_MAX } from './renderTargets.js';-import { QUEUEABLE_IMAGE_MODES } from '../services/imageGen/modes.js';+import { QUEUEABLE_IMAGE_MODES } from './generationModes.js';import { GROK_VIDEO_DURATIONS } from './grokVideoClip.js';/**diff --git a/server/lib/validation.js b/server/lib/validation.jsindex fac3cf526c..ccd151c2e7 100644--- a/server/lib/validation.js+++ b/server/lib/validation.js@@ -4,8 +4,7 @@ import { partialWithoutDefaults, emptyToUndefined, emptyToNull, optionalBooleanMimport { WORK_TRACKERS } from './workTracker.js';import { PROVIDER_FAMILY_IDS } from './providerFamilies.js';import { MAX_MONTHLY_COST } from './subscriptionSavings.js';-import { QUEUEABLE_IMAGE_MODES } from '../services/imageGen/modes.js';-import { VIDEO_GEN_MODES } from '../services/videoGen/modes.js';+import { QUEUEABLE_IMAGE_MODES, VIDEO_GEN_MODES } from './generationModes.js';import { RENDER_TARGETS, RENDER_TARGET_BACKEND_AUTO } from './renderTargets.js';import {grokVideoDurationSchema, cloudModelIdString, recordRenderPinFields, isSafeSubdirFilter,diff --git a/server/services/imageGen/modes.js b/server/services/imageGen/modes.jsindex 4923330308..be772a65f5 100644--- a/server/services/imageGen/modes.js+++ b/server/services/imageGen/modes.js@@ -9,33 +9,19 @@* `IMAGE_GEN_MODES` is the alphabet for Zod / OpenAI tool-spec enums.* Single source of truth: derive the array from `Object.values(...)`.*- * The lone import is the error type — `errorHandler.js` pulls in nothing but- * node's `events`, so it cannot reintroduce the provider cycle this module was- * split out to avoid.+ * The backend alphabets live in `lib/generationModes.js`, below both validation+ * and this service module. They are re-exported here so existing generation+ * callers keep the same service-local import path.*/import { ServerError } from '../../lib/errorHandler.js';+import {+ CLOUD_IMAGE_GEN_MODES, IMAGE_GEN_MODE, IMAGE_GEN_MODES, QUEUEABLE_IMAGE_MODES,+} from '../../lib/generationModes.js';-export const IMAGE_GEN_MODE = Object.freeze({- EXTERNAL: 'external',- LOCAL: 'local',- CODEX: 'codex',- GROK: 'grok',- AGY: 'agy',-});--export const IMAGE_GEN_MODES = Object.freeze(Object.values(IMAGE_GEN_MODE));--// Cloud-CLI backends (codex `$imagegen`, grok `image_gen`) — each render-// shells out to an external child that spends remote quota, not local GPU.-// The mediaJobQueue routes these through its parallel cloud lane (they don't-// serialize on the MLX runtime) and async callers treat them like local:-// generateImage returns a job descriptor before the file lands.-export const CLOUD_IMAGE_GEN_MODES = Object.freeze([- IMAGE_GEN_MODE.CODEX,- IMAGE_GEN_MODE.GROK,- IMAGE_GEN_MODE.AGY,-]);+export {+ CLOUD_IMAGE_GEN_MODES, IMAGE_GEN_MODE, IMAGE_GEN_MODES, QUEUEABLE_IMAGE_MODES,+};// The provider-side image tool each cloud CLI is directed to call. Single// source: the prompt builders name it, the fabrication guard names it when it@@ -74,12 +60,6 @@ export const visualReferenceRole = (count) => (count === 1export const enabledCloudImageModes = (settings) =>CLOUD_IMAGE_GEN_MODES.filter((mode) => settings?.imageGen?.[mode]?.enabled === true);-// Modes the mediaJobQueue can run (external SD-API stays synchronous — a-// remote HTTP call with no local single-flight constraint to absorb). Single-// source for the pipeline routes' Zod enums and batch-render guards, so a-// future backend is one edit here instead of a sweep of enum literals.-export const QUEUEABLE_IMAGE_MODES = Object.freeze([IMAGE_GEN_MODE.LOCAL, ...CLOUD_IMAGE_GEN_MODES]);-// Backends that cannot take an input image at all (#3243). Every *queueable*// backend now can: local (mflux/diffusers `--image-path` + FLUX.2 references),// codex (`image_gen.referenced_image_paths`), grok (`image_edit.image`) and agydiff --git a/server/services/videoGen/modes.js b/server/services/videoGen/modes.jsindex d127caa5e2..769da8fd56 100644--- a/server/services/videoGen/modes.js+++ b/server/services/videoGen/modes.js@@ -10,9 +10,9 @@* no enumerable alphabet — so a Zod schema, a UI picker, or a resolver had* nothing to derive from and had to hand-copy `['local', 'grok']`.*- * This module is that alphabet. The values are DERIVED from `IMAGE_GEN_MODE`- * rather than re-typed, so the queue's discriminator can never drift from what a- * schema validates.+ * The alphabet lives in `lib/generationModes.js`, below both validation and the+ * generation services. This module re-exports it beside the service-owned+ * usability and resolution helpers for compatibility.** Careful: local video renders ALSO use a `params.mode` for the t2v/i2v semantic* ('text' | 'image' | 'fflf' | 'a2v' | 'extend' | an IC-LoRA remix id — see@@ -20,25 +20,16 @@* literal 'grok', which is exactly why the cloud discriminator can share the* key; a grok job carries the semantic separately as `videoMode`.*- * Dependency-free apart from the image enum and the render-target leaf (both- * leaves themselves), so `lib/validation.js` and the commission validation- * leaf can both import it.+ * Validation imports the leaf directly, so this service module can retain the+ * settings-aware backend resolver without inverting the dependency graph.*/-import { IMAGE_GEN_MODE } from '../imageGen/modes.js';+import {+ CLOUD_VIDEO_GEN_MODES, VIDEO_GEN_MODE, VIDEO_GEN_MODES,+} from '../../lib/generationModes.js';import { normalizeRenderPinValue } from '../../lib/renderTargets.js';-export const VIDEO_GEN_MODE = Object.freeze({- LOCAL: IMAGE_GEN_MODE.LOCAL,- GROK: IMAGE_GEN_MODE.GROK,-});--export const VIDEO_GEN_MODES = Object.freeze(Object.values(VIDEO_GEN_MODE));--// Cloud-CLI video backends — each render shells out to an external child that-// spends remote quota, so the queue routes them through its parallel cloud lane-// instead of serializing on the MLX runtime.-export const CLOUD_VIDEO_GEN_MODES = Object.freeze([VIDEO_GEN_MODE.GROK]);+export { CLOUD_VIDEO_GEN_MODES, VIDEO_GEN_MODE, VIDEO_GEN_MODES };/*** Is `mode` a video backend this install can actually render on right now?