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
fix([issue-746]): break scheduler/crud/store import cycle and correct execution.js error-handling comment
[._.]/ Adam Eivy2fbc83f32fa6
diff --git a/server/services/autonomousJobs.js b/server/services/autonomousJobs.jsindex de67b1f6d2..f0b5041080 100644--- a/server/services/autonomousJobs.js+++ b/server/services/autonomousJobs.js@@ -27,7 +27,7 @@import { validateCommand } from '../lib/commandSecurity.js'import { agentDataCleanup } from './autonomousJobs/scriptHandlers.js'-import { JOB_SKILL_MAP } from './autonomousJobs/constants.js'+import { JOB_SKILL_MAP, INTERVAL_OPTIONS } from './autonomousJobs/constants.js'import { initJobs, syncSkillTemplatesFromSample } from './autonomousJobs/store.js'import {getAllJobs,@@ -44,8 +44,7 @@ import {import {isWeekday,getDueJobs,- getNextDueJob,- INTERVAL_OPTIONS+ getNextDueJob} from './autonomousJobs/scheduler.js'import {loadJobSkillTemplate,diff --git a/server/services/autonomousJobs/constants.js b/server/services/autonomousJobs/constants.jsindex 1f02beb4df..0dea6b1bf7 100644--- a/server/services/autonomousJobs/constants.js+++ b/server/services/autonomousJobs/constants.js@@ -23,6 +23,40 @@ export const WEEK = 7 * DAY// Re-export the time units used across submodules so callers import from one place.export { DAY, HOUR }+/**+ * Resolve interval string to milliseconds. Pure (depends only on the time+ * units above), so it lives in this leaf module — keeping it out of scheduler.js+ * avoids the store→scheduler and crud→scheduler import cycles.+ */+export function resolveIntervalMs(interval, customMs) {+ switch (interval) {+ case 'hourly': return HOUR+ case 'every-2-hours': return 2 * HOUR+ case 'every-4-hours': return 4 * HOUR+ case 'every-8-hours': return 8 * HOUR+ case 'daily': return DAY+ case 'weekly': return WEEK+ case 'biweekly': return 2 * WEEK+ case 'monthly': return 30 * DAY+ case 'custom': return customMs || DAY+ default: return DAY+ }+}++/**+ * Available interval options for UI+ */+export const INTERVAL_OPTIONS = [+ { value: 'hourly', label: 'Every Hour', ms: HOUR },+ { value: 'every-2-hours', label: 'Every 2 Hours', ms: 2 * HOUR },+ { value: 'every-4-hours', label: 'Every 4 Hours', ms: 4 * HOUR },+ { value: 'every-8-hours', label: 'Every 8 Hours', ms: 8 * HOUR },+ { value: 'daily', label: 'Daily', ms: DAY },+ { value: 'weekly', label: 'Weekly', ms: WEEK },+ { value: 'biweekly', label: 'Every 2 Weeks', ms: 2 * WEEK },+ { value: 'monthly', label: 'Monthly', ms: 30 * DAY }+]+// Fields that are code contracts — always overwrite on restart so runtime// stays consistent with the shipped implementation.export const JOB_STRUCTURAL_FIELDS = ['type', 'scriptHandler']diff --git a/server/services/autonomousJobs/crud.js b/server/services/autonomousJobs/crud.jsindex 02d1b6792a..74b554afbc 100644--- a/server/services/autonomousJobs/crud.js+++ b/server/services/autonomousJobs/crud.js@@ -10,9 +10,9 @@import { v4 as uuidv4 } from '../../lib/uuid.js'import { validateCommand } from '../../lib/commandSecurity.js'import { cosEvents } from '../cosEvents.js'-import { withLock } from './constants.js'+import { withLock, resolveIntervalMs } from './constants.js'import { loadJobs, saveJobs } from './store.js'-import { resolveIntervalMs, getNextDueJob } from './scheduler.js'+import { getNextDueJob } from './scheduler.js'/*** Get all jobsdiff --git a/server/services/autonomousJobs/execution.js b/server/services/autonomousJobs/execution.jsindex d1970bc854..e66fc38aec 100644--- a/server/services/autonomousJobs/execution.js+++ b/server/services/autonomousJobs/execution.js@@ -3,9 +3,10 @@** Runs `type: 'script'` and `type: 'shell'` jobs directly (no AI agent).* `executeShellJob` spawns the validated command with a timeout + output cap and- * persists the result. NOTE: the child-process / setTimeout callbacks here run- * outside the Express request lifecycle, so their inline try/catch + emoji- * `console.error` handling is intentional (an uncaught throw would crash Node).+ * persists the result. The child-process / setTimeout callbacks here run outside+ * the Express request lifecycle; their async persist calls carry `.catch()`+ * handlers that log via emoji-prefixed `console.error` so a persist failure can't+ * reject into the void. Behavior is preserved verbatim from the pre-split module.*/import { spawn } from 'child_process'diff --git a/server/services/autonomousJobs/scheduler.js b/server/services/autonomousJobs/scheduler.jsindex acd5548457..a714bec12f 100644--- a/server/services/autonomousJobs/scheduler.js+++ b/server/services/autonomousJobs/scheduler.js@@ -8,8 +8,15 @@import { getUserTimezone, getLocalParts, nextLocalTime } from '../../lib/timezone.js'import { parseCronToNextRun } from '../eventScheduler.js'-import { DAY, HOUR, WEEK } from './constants.js'-import { getEnabledJobs } from './crud.js'+import { DAY } from './constants.js'+import { loadJobs } from './store.js'++// Reads enabled jobs straight from the store. Scheduler intentionally does NOT+// import from crud.js — doing so created a scheduler→crud→scheduler cycle.+async function getEnabledJobs() {+ const data = await loadJobs()+ return data.jobs.filter(j => j.enabled)+}/*** Check if today is a weekday (Monday-Friday) in the user's timezone.@@ -141,36 +148,4 @@ async function getNextDueJob() {return earliest}-/**- * Resolve interval string to milliseconds- */-function resolveIntervalMs(interval, customMs) {- switch (interval) {- case 'hourly': return HOUR- case 'every-2-hours': return 2 * HOUR- case 'every-4-hours': return 4 * HOUR- case 'every-8-hours': return 8 * HOUR- case 'daily': return DAY- case 'weekly': return WEEK- case 'biweekly': return 2 * WEEK- case 'monthly': return 30 * DAY- case 'custom': return customMs || DAY- default: return DAY- }-}--/**- * Available interval options for UI- */-const INTERVAL_OPTIONS = [- { value: 'hourly', label: 'Every Hour', ms: HOUR },- { value: 'every-2-hours', label: 'Every 2 Hours', ms: 2 * HOUR },- { value: 'every-4-hours', label: 'Every 4 Hours', ms: 4 * HOUR },- { value: 'every-8-hours', label: 'Every 8 Hours', ms: 8 * HOUR },- { value: 'daily', label: 'Daily', ms: DAY },- { value: 'weekly', label: 'Weekly', ms: WEEK },- { value: 'biweekly', label: 'Every 2 Weeks', ms: 2 * WEEK },- { value: 'monthly', label: 'Monthly', ms: 30 * DAY }-]--export { isWeekday, getDueJobs, getNextDueJob, resolveIntervalMs, INTERVAL_OPTIONS }+export { isWeekday, getDueJobs, getNextDueJob }diff --git a/server/services/autonomousJobs/scriptHandlers.js b/server/services/autonomousJobs/scriptHandlers.jsindex 2bce14a8da..7ab0c0f862 100644--- a/server/services/autonomousJobs/scriptHandlers.js+++ b/server/services/autonomousJobs/scriptHandlers.js@@ -11,7 +11,7 @@ import { join, dirname } from 'path'import { fileURLToPath } from 'url'import { existsSync } from 'fs'import { spawn } from 'child_process'-import { DAY, ensureDir, PATHS, readJSONFile } from '../../lib/fileUtils.js'+import { DAY, PATHS, readJSONFile } from '../../lib/fileUtils.js'import { checkAndPrompt as autobiographyCheckAndPrompt } from '../autobiography.js'import { runGoalCheckIn } from '../goalCheckIn.js'import { cleanupOrphanedWorktrees, reapMergedWorktrees } from '../worktreeManager.js'diff --git a/server/services/autonomousJobs/store.js b/server/services/autonomousJobs/store.jsindex 1a0e1a9322..0e4b13b5be 100644--- a/server/services/autonomousJobs/store.js+++ b/server/services/autonomousJobs/store.js@@ -13,9 +13,8 @@ import { join } from 'path'import { existsSync } from 'fs'import { ensureDir, PATHS, readJSONFile, atomicWrite, tryReadFile } from '../../lib/fileUtils.js'import { validateCommand } from '../../lib/commandSecurity.js'-import { DATA_DIR, JOBS_FILE, JOBS_SKILLS_DIR } from './constants.js'+import { DATA_DIR, JOBS_FILE, JOBS_SKILLS_DIR, resolveIntervalMs } from './constants.js'import { createDefaultJobsData, mergeWithDefaults } from './defaults.js'-import { resolveIntervalMs } from './scheduler.js'let initPromise = null