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: table-ize route/label/lister dispatch and share fixed-interval evaluation
[._.]/ Adam Eivy2391569c363d
diff --git a/client/src/components/Layout.jsx b/client/src/components/Layout.jsxindex 0d907259bb..65066ce71f 100644--- a/client/src/components/Layout.jsx+++ b/client/src/components/Layout.jsx@@ -468,6 +468,110 @@ export function SingleNavRow({ item, collapsed, active, badgeCount, pinned, onTo);}+// Routes whose main content owns its own internal scroll region and needs the+// bare full-width `<main>` (relative overflow-hidden) instead of the default+// padded+scrolling one. Checked in order: exact path, then prefix, then+// regex — see `isFullWidthRoute` below.+const EXACT_FULL_WIDTH_PATHS = [+ '/character',+ '/ai',+ '/devtools/flows',+ '/ask',+ // OpenClaw lives under the Settings nav group; it's a full-bleed+ // chat surface (sidebar + message pane) that owns its own internal+ // scroll, so it needs the bare full-width main like the other+ // Settings pages (/ai, /prompts, /settings/*).+ '/openclaw',+ '/prompts',+ '/review',+ '/shell',+ // Tribe is a full-bleed two-pane page that owns its own internal+ // scroll (PageHeader + a `flex-1 overflow-auto` main); keep it out+ // of the default padded+scrolling main or it double-pads and clips.+ '/tribe',+ // Rapid Reader is a full-bleed brain sub-page: full-width PageHeader+ // over an internal `flex-1 overflow-auto` scroll region.+ '/rapid-reader',+ // Timeline (/timeline and /timeline/:date) is a full-bleed brain+ // sub-page: full-width PageHeader over an internal `flex-1+ // overflow-auto` scroll region that wraps the centered max-w-4xl+ // content — keep it out of the default padded main or it double-pads.+ '/timeline',+];++const FULL_WIDTH_PATH_PREFIXES = [+ '/ask/',+ '/calendar',+ // Only the Catalog DETAIL editor (/catalog/{type}/{id}) and the+ // Ingest page (/catalog/ingest) are full-width — they own their+ // own scroll. The /catalog list/index page stays scrolling-default.+ '/catalog/',+ '/cos',+ // Both the Creative Director index and its detail editor manage+ // their own internal scroll (flex-col h-full + overflow-auto body),+ // so they need the bare full-width main — same as when they lived+ // under the /media tabs.+ '/creative-director',+ '/brain',+ '/digital-twin',+ '/feature-agents',+ '/goals',+ '/insights',+ '/meatspace',+ '/media',+ '/messages',+ '/local-llm/',+ '/pipeline/issues/',+ '/pipeline/series/',+ '/post',+ '/settings',+ // Round EDITOR (/rounds/:id) and the Learning Guide (/rounds/guide)+ // are full-width and own their own scroll; the bare /rounds index+ // (list + create form) takes the normal padded+scrolling main.+ '/rounds/',+ '/wiki',+ // Only the universe EDITOR (/universes/:id, /universes/new) is+ // full-width — it manages its own scroll. The /universes index+ // (list/table) takes the normal padded+scrolling main, mirroring+ // the Series Pipeline index (/pipeline is not full-width either).+ '/universes/',+ // Story Builder DETAIL (/story-builder/:id/:step) is a full-width+ // stepper that owns its own scroll; the bare /story-builder index+ // (list + create form) takes the normal padded+scrolling main.+ '/story-builder/',+ '/writers-room',+ '/agents',+ '/shell/',+ '/city',+ '/timeline/',+ // Every SongBook route — index (/songbook), import (/songbook/import),+ // and viewer (/songbook/:id) — is full-bleed and owns its own scroll+ // (flex-col h-full + an internal overflow-auto region; the viewer adds+ // its autoscroll container). They share the standard bordered+ // PageHeader bar over that scroll region.+ '/songbook',+];++const FULL_WIDTH_PATH_REGEXES = [+ // Only Game DETAIL workspaces own an internal scroll region; the+ // bare /game index stays on the normal padded page layout.+ /^\/game\/[^/]+\/?$/,+ // Only the App DETAIL editor (/apps/:id, /apps/:id/:tab) is+ // full-width and owns its own scroll; the Add App form+ // (/apps/create) is a plain scrolling page and must stay OUT of+ // full-width, or its content clips below the fold (it has no+ // internal overflow-y-auto container). The trailing (?:\/|$) ++ // create(?:\/|$) lookahead also excludes the trailing-slash URL+ // /apps/create/ (React Router treats it as the same route).+ /^\/apps\/(?!create(?:\/|$))[^/]+(?:\/|$)/,+];++function isFullWidthRoute(pathname) {+ return EXACT_FULL_WIDTH_PATHS.includes(pathname) ||+ FULL_WIDTH_PATH_PREFIXES.some((prefix) => pathname.startsWith(prefix)) ||+ FULL_WIDTH_PATH_REGEXES.some((re) => re.test(pathname));+}+export default function Layout() {const location = useLocation();const navigate = useNavigate();@@ -1199,91 +1303,7 @@ export default function Layout() {{/* Main content */}{(() => {- const isFullWidth = location.pathname === '/character' ||- location.pathname === '/ai' ||- location.pathname === '/devtools/flows' ||- location.pathname === '/ask' ||- location.pathname.startsWith('/ask/') ||- location.pathname.startsWith('/calendar') ||- // Only the Catalog DETAIL editor (/catalog/{type}/{id}) and the- // Ingest page (/catalog/ingest) are full-width — they own their- // own scroll. The /catalog list/index page stays scrolling-default.- location.pathname.startsWith('/catalog/') ||- location.pathname.startsWith('/cos') ||- // Both the Creative Director index and its detail editor manage- // their own internal scroll (flex-col h-full + overflow-auto body),- // so they need the bare full-width main — same as when they lived- // under the /media tabs.- location.pathname.startsWith('/creative-director') ||- location.pathname.startsWith('/brain') ||- location.pathname.startsWith('/digital-twin') ||- location.pathname.startsWith('/feature-agents') ||- // Only Game DETAIL workspaces own an internal scroll region; the- // bare /game index stays on the normal padded page layout.- /^\/game\/[^/]+\/?$/.test(location.pathname) ||- location.pathname.startsWith('/goals') ||- location.pathname.startsWith('/insights') ||- location.pathname.startsWith('/meatspace') ||- location.pathname.startsWith('/media') ||- location.pathname.startsWith('/messages') ||- location.pathname.startsWith('/local-llm/') ||- // OpenClaw lives under the Settings nav group; it's a full-bleed- // chat surface (sidebar + message pane) that owns its own internal- // scroll, so it needs the bare full-width main like the other- // Settings pages (/ai, /prompts, /settings/*).- location.pathname === '/openclaw' ||- location.pathname.startsWith('/pipeline/issues/') ||- location.pathname.startsWith('/pipeline/series/') ||- location.pathname.startsWith('/post') ||- location.pathname === '/prompts' ||- location.pathname === '/review' ||- location.pathname.startsWith('/settings') ||- // Round EDITOR (/rounds/:id) and the Learning Guide (/rounds/guide)- // are full-width and own their own scroll; the bare /rounds index- // (list + create form) takes the normal padded+scrolling main.- location.pathname.startsWith('/rounds/') ||- location.pathname.startsWith('/wiki') ||- // Only the universe EDITOR (/universes/:id, /universes/new) is- // full-width — it manages its own scroll. The /universes index- // (list/table) takes the normal padded+scrolling main, mirroring- // the Series Pipeline index (/pipeline is not full-width either).- location.pathname.startsWith('/universes/') ||- // Story Builder DETAIL (/story-builder/:id/:step) is a full-width- // stepper that owns its own scroll; the bare /story-builder index- // (list + create form) takes the normal padded+scrolling main.- location.pathname.startsWith('/story-builder/') ||- location.pathname.startsWith('/writers-room') ||- location.pathname.startsWith('/agents') ||- location.pathname === '/shell' ||- location.pathname.startsWith('/shell/') ||- location.pathname.startsWith('/city') ||- // Tribe is a full-bleed two-pane page that owns its own internal- // scroll (PageHeader + a `flex-1 overflow-auto` main); keep it out- // of the default padded+scrolling main or it double-pads and clips.- location.pathname === '/tribe' ||- // Rapid Reader is a full-bleed brain sub-page: full-width PageHeader- // over an internal `flex-1 overflow-auto` scroll region.- location.pathname === '/rapid-reader' ||- // Timeline (/timeline and /timeline/:date) is a full-bleed brain- // sub-page: full-width PageHeader over an internal `flex-1- // overflow-auto` scroll region that wraps the centered max-w-4xl- // content — keep it out of the default padded main or it double-pads.- location.pathname === '/timeline' ||- location.pathname.startsWith('/timeline/') ||- // Only the App DETAIL editor (/apps/:id, /apps/:id/:tab) is- // full-width and owns its own scroll; the Add App form- // (/apps/create) is a plain scrolling page and must stay OUT of- // full-width, or its content clips below the fold (it has no- // internal overflow-y-auto container). The trailing (?:\/|$) +- // create(?:\/|$) lookahead also excludes the trailing-slash URL- // /apps/create/ (React Router treats it as the same route).- /^\/apps\/(?!create(?:\/|$))[^/]+(?:\/|$)/.test(location.pathname) ||- // Every SongBook route — index (/songbook), import (/songbook/import),- // and viewer (/songbook/:id) — is full-bleed and owns its own scroll- // (flex-col h-full + an internal overflow-auto region; the viewer adds- // its autoscroll container). They share the standard bordered- // PageHeader bar over that scroll region.- location.pathname.startsWith('/songbook');+ const isFullWidth = isFullWidthRoute(location.pathname);return (<main id="main-content" className={`flex-1 min-h-0 print:overflow-visible print:min-h-0 ${isFullWidth ? 'relative overflow-hidden' : 'overflow-auto p-4 md:p-6'}`}><Outlet />diff --git a/client/src/pages/ImageGen.jsx b/client/src/pages/ImageGen.jsxindex 968e712b26..4b96e58d51 100644--- a/client/src/pages/ImageGen.jsx+++ b/client/src/pages/ImageGen.jsx@@ -115,6 +115,16 @@ const ERROR_HEADINGS = {repo_not_found: 'Model repo not found',};+// Labels for the connected-status pill when no model name is reported.+// Deliberately worded differently from `modeLabel()` (imageGenBackends.js) —+// do not unify the two.+const CONNECTED_MODE_LABELS = {+ [IMAGE_GEN_MODE.LOCAL]: 'mflux/local',+ [IMAGE_GEN_MODE.CODEX]: 'codex CLI',+ [IMAGE_GEN_MODE.GROK]: 'grok CLI',+ [IMAGE_GEN_MODE.AGY]: 'agy CLI',+};+export default function ImageGen() {const navigate = useNavigate();const [searchParams, setSearchParams] = useSearchParams();@@ -1124,7 +1134,7 @@ export default function ImageGen() {: 'border-port-error/40 bg-port-error/10 text-port-error'}`}>{status.connected ? (- <><span className="w-2 h-2 rounded-full bg-port-success" /> {status.model || (status.mode === IMAGE_GEN_MODE.LOCAL ? 'mflux/local' : status.mode === IMAGE_GEN_MODE.CODEX ? 'codex CLI' : status.mode === IMAGE_GEN_MODE.GROK ? 'grok CLI' : status.mode === IMAGE_GEN_MODE.AGY ? 'agy CLI' : 'external SD API')}</>+ <><span className="w-2 h-2 rounded-full bg-port-success" /> {status.model || CONNECTED_MODE_LABELS[status.mode] || 'external SD API'}</>) : (<><AlertTriangle className="w-3 h-3" />diff --git a/server/services/sharing/peerSync.js b/server/services/sharing/peerSync.jsindex 28862987b8..43cf0fd2ca 100644--- a/server/services/sharing/peerSync.js+++ b/server/services/sharing/peerSync.js@@ -365,61 +365,70 @@ export async function autoSubscribeRecordToAllPeers(recordKind, recordId) {* Dynamic imports for the listers avoid a static cycle (peerSync already* imports merge entry points from universeBuilder / pipeline.series).*/+/**+ * Per-kind lister thunks for `listRecordsForKind` below. Each entry mirrors the+ * exact error handling the kind had before this was table-ized — every lister+ * here still swallows its own failure with `.catch(() => [])`. Universe/series+ * are wrapped so their `import()` stays lazy, invoked only when that kind is+ * actually requested — the map's own construction imports nothing.+ *+ * Null-prototype so a lookup can only ever hit a kind defined here. The+ * if/else chain this replaced matched nothing for a name like `toString` or+ * `constructor` and fell through to an empty list; a plain object literal would+ * instead resolve the inherited Object.prototype method and call it, so the+ * `?? []` fallback below would never fire and the caller's `.filter` would+ * throw. Keeps an unrecognized kind behaving exactly as it did before.+ */+const RECORD_KIND_LISTERS = {+ __proto__: null,+ // Dynamic-imported to avoid a static cycle (peerSync already imports its+ // merge entry point).+ universe: async () => {+ const { listUniverses } = await import('../universeBuilder.js');+ return listUniverses({ includeDeleted: false }).catch(() => []);+ },+ // Dynamic-imported to avoid a static cycle (peerSync already imports its+ // merge entry point).+ series: async () => {+ const { listSeries } = await import('../pipeline/series.js');+ return listSeries({ includeDeleted: false }).catch(() => []);+ },+ mediaCollection: () => listCollections({ includeDeleted: false }).catch(() => []),+ author: () => listAuthors({ includeDeleted: false }).catch(() => []),+ artist: () => listArtists({ includeDeleted: false }).catch(() => []),+ album: () => listAlbums({ includeDeleted: false }).catch(() => []),+ track: () => listTracks({ includeDeleted: false }).catch(() => []),+ creativeDirectorProject: () => listProjects({ includeDeleted: false }).catch(() => []),+ moodBoard: () => listBoards({ includeDeleted: false }).catch(() => []),+ // Live works as { id, updatedAt } (full-sync coverage compares updatedAt to+ // detect a stale confirmed push; bare {id} stubs would report a changed+ // manuscript as fully mirrored). Without this branch, enabling the+ // writersRoomWorks category (or full-sync) would backfill nothing.+ writersRoomWork: () => listWorksForSync().catch(() => []),+ // Live folders as { id, updatedAt } (#1645) — same coverage-compare reason+ // as works. Body-less, so no asset/body manifest backfill.+ writersRoomFolder: () => listFoldersForSync().catch(() => []),+ // Live exercises as { id, updatedAt } (#1645). updatedAt is derived from+ // finishedAt ?? startedAt in the facade so coverage keys on the wire value.+ writersRoomExercise: () => listExercisesForSync().catch(() => []),+ musicVideoProject: () => listMusicVideoProjects({ includeDeleted: false }).catch(() => []),+ // Live feedback reactions as { id, updatedAt } (#2686) — same coverage-compare+ // reason as folders. Body-less, so no asset manifest backfill.+ commissionFeedback: () => listCommissionFeedbackForSync().catch(() => []),+ // Live commission briefs as { id, updatedAt } (#2686). Body-less on the wire+ // (schedule/runs/assignment stripped), so no asset manifest backfill.+ creativeCommission: () => listCommissionsForSync().catch(() => []),+};+/*** List the local, non-deleted, non-ephemeral records of a subscribable kind —* the candidate set for both the back-subscribe sweep and full-sync coverage* diffing. Ephemeral records are dropped because they can never push (the wire* sanitizer short-circuits them) and a sub for one would leave an orphan row.- * Universe/series listers are dynamic-imported to avoid a static cycle- * (peerSync already imports their merge entry points).+ * An unrecognized recordKind yields no records, same as before table-izing.*/async function listRecordsForKind(recordKind) {- let records = [];- if (recordKind === 'universe') {- const { listUniverses } = await import('../universeBuilder.js');- records = await listUniverses({ includeDeleted: false }).catch(() => []);- } else if (recordKind === 'series') {- const { listSeries } = await import('../pipeline/series.js');- records = await listSeries({ includeDeleted: false }).catch(() => []);- } else if (recordKind === 'mediaCollection') {- records = await listCollections({ includeDeleted: false }).catch(() => []);- } else if (recordKind === 'author') {- records = await listAuthors({ includeDeleted: false }).catch(() => []);- } else if (recordKind === 'artist') {- records = await listArtists({ includeDeleted: false }).catch(() => []);- } else if (recordKind === 'album') {- records = await listAlbums({ includeDeleted: false }).catch(() => []);- } else if (recordKind === 'track') {- records = await listTracks({ includeDeleted: false }).catch(() => []);- } else if (recordKind === 'creativeDirectorProject') {- records = await listProjects({ includeDeleted: false }).catch(() => []);- } else if (recordKind === 'moodBoard') {- records = await listBoards({ includeDeleted: false }).catch(() => []);- } else if (recordKind === 'writersRoomWork') {- // Live works as { id, updatedAt } (full-sync coverage compares updatedAt to- // detect a stale confirmed push; bare {id} stubs would report a changed- // manuscript as fully mirrored). Without this branch, enabling the- // writersRoomWorks category (or full-sync) would backfill nothing.- records = await listWorksForSync().catch(() => []);- } else if (recordKind === 'writersRoomFolder') {- // Live folders as { id, updatedAt } (#1645) — same coverage-compare reason- // as works. Body-less, so no asset/body manifest backfill.- records = await listFoldersForSync().catch(() => []);- } else if (recordKind === 'writersRoomExercise') {- // Live exercises as { id, updatedAt } (#1645). updatedAt is derived from- // finishedAt ?? startedAt in the facade so coverage keys on the wire value.- records = await listExercisesForSync().catch(() => []);- } else if (recordKind === 'musicVideoProject') {- records = await listMusicVideoProjects({ includeDeleted: false }).catch(() => []);- } else if (recordKind === 'commissionFeedback') {- // Live feedback reactions as { id, updatedAt } (#2686) — same coverage-compare- // reason as folders. Body-less, so no asset manifest backfill.- records = await listCommissionFeedbackForSync().catch(() => []);- } else if (recordKind === 'creativeCommission') {- // Live commission briefs as { id, updatedAt } (#2686). Body-less on the wire- // (schedule/runs/assignment stripped), so no asset manifest backfill.- records = await listCommissionsForSync().catch(() => []);- }+ const records = await (RECORD_KIND_LISTERS[recordKind]?.() ?? []);return records.filter(r => r?.ephemeral !== true && isNonEmptyStr(r?.id));}diff --git a/server/services/taskSchedule.js b/server/services/taskSchedule.jsindex b6c2730e05..4f08cd6884 100644--- a/server/services/taskSchedule.js+++ b/server/services/taskSchedule.js@@ -1435,6 +1435,26 @@ async function checkRunAfterDeps(schedule, taskType, appId = null) {return { satisfied: pending.length === 0, pending };}+/**+ * Shared due/cooldown evaluation for the fixed-cadence interval types+ * (DAILY, WEEKLY, CUSTOM), which differ only in their base interval and the+ * reason-string prefix (`label`). Reason strings are persisted and compared+ * elsewhere, so they must come out byte-identical to what each case produced+ * before this was extracted (e.g. `'daily-due'`, `'weekly-cooldown-adjusted'`).+ */+async function evaluateFixedInterval(taskType, baseIntervalMs, label, timeSinceLastRun, lastRun, buildResult) {+ const learningAdjustment = await getPerformanceAdjustedInterval(taskType, baseIntervalMs);+ const adjustedInterval = learningAdjustment.adjustedIntervalMs;+ if (timeSinceLastRun >= adjustedInterval) {+ return buildResult(true, learningAdjustment.adjusted ? `${label}-due-adjusted` : `${label}-due`, baseIntervalMs, { learningAdjustment });+ }+ return buildResult(false, learningAdjustment.adjusted ? `${label}-cooldown-adjusted` : `${label}-cooldown`, baseIntervalMs, {+ learningAdjustment, nextRunIn: adjustedInterval - timeSinceLastRun,+ nextRunAt: new Date(lastRun + adjustedInterval).toISOString(),+ baseIntervalMs, adjustedIntervalMs: adjustedInterval+ });+}+/*** Check if a task type should run for a specific app (or globally)*/@@ -1520,35 +1540,13 @@ export async function shouldRunTask(taskType, appId = null) {result = { shouldRun: true, reason: 'rotation' };break;- case INTERVAL_TYPES.DAILY: {- const learningAdjustment = await getPerformanceAdjustedInterval(taskType, DAY);- const adjustedInterval = learningAdjustment.adjustedIntervalMs;- if (timeSinceLastRun >= adjustedInterval) {- result = buildResult(true, learningAdjustment.adjusted ? 'daily-due-adjusted' : 'daily-due', DAY, { learningAdjustment });- } else {- result = buildResult(false, learningAdjustment.adjusted ? 'daily-cooldown-adjusted' : 'daily-cooldown', DAY, {- learningAdjustment, nextRunIn: adjustedInterval - timeSinceLastRun,- nextRunAt: new Date(lastRun + adjustedInterval).toISOString(),- baseIntervalMs: DAY, adjustedIntervalMs: adjustedInterval- });- }+ case INTERVAL_TYPES.DAILY:+ result = await evaluateFixedInterval(taskType, DAY, 'daily', timeSinceLastRun, lastRun, buildResult);break;- }- case INTERVAL_TYPES.WEEKLY: {- const learningAdjustment = await getPerformanceAdjustedInterval(taskType, WEEK);- const adjustedInterval = learningAdjustment.adjustedIntervalMs;- if (timeSinceLastRun >= adjustedInterval) {- result = buildResult(true, learningAdjustment.adjusted ? 'weekly-due-adjusted' : 'weekly-due', WEEK, { learningAdjustment });- } else {- result = buildResult(false, learningAdjustment.adjusted ? 'weekly-cooldown-adjusted' : 'weekly-cooldown', WEEK, {- learningAdjustment, nextRunIn: adjustedInterval - timeSinceLastRun,- nextRunAt: new Date(lastRun + adjustedInterval).toISOString(),- baseIntervalMs: WEEK, adjustedIntervalMs: adjustedInterval- });- }+ case INTERVAL_TYPES.WEEKLY:+ result = await evaluateFixedInterval(taskType, WEEK, 'weekly', timeSinceLastRun, lastRun, buildResult);break;- }case INTERVAL_TYPES.ONCE:result = appExecution.count === 0@@ -1564,17 +1562,7 @@ export async function shouldRunTask(taskType, appId = null) {// A per-app numeric intervalMs override wins over the global custom interval// (handler-backed tasks store their per-app cadence there).const baseInterval = (hasCustomIntervalMs ? perAppIntervalMs : interval.intervalMs) || DAY;- const learningAdjustment = await getPerformanceAdjustedInterval(taskType, baseInterval);- const adjustedInterval = learningAdjustment.adjustedIntervalMs;- if (timeSinceLastRun >= adjustedInterval) {- result = buildResult(true, learningAdjustment.adjusted ? 'custom-due-adjusted' : 'custom-due', baseInterval, { learningAdjustment });- } else {- result = buildResult(false, learningAdjustment.adjusted ? 'custom-cooldown-adjusted' : 'custom-cooldown', baseInterval, {- learningAdjustment, nextRunIn: adjustedInterval - timeSinceLastRun,- nextRunAt: new Date(lastRun + adjustedInterval).toISOString(),- baseIntervalMs: baseInterval, adjustedIntervalMs: adjustedInterval- });- }+ result = await evaluateFixedInterval(taskType, baseInterval, 'custom', timeSinceLastRun, lastRun, buildResult);break;}