Skip to content

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

feat: convert autobiography job to script type (no LLM needed)

Adam Eivye543dd1affea
diff --git a/.changelog/v0.24.x.md b/.changelog/v0.24.x.md
index ccb1316e30..6d38741f2f 100644
--- a/.changelog/v0.24.x.md
+++ b/.changelog/v0.24.x.md
@@ -14,3 +14,10 @@ Bidirectional peer registration — adding a peer on one instance now automatica
- **Deduplication** — peers are matched by `instanceId` (primary) or `address:port` (fallback) to prevent duplicate entries
- **New endpoint** `POST /api/instances/peers/announce` — receives peer announcements with Zod-validated `instanceId`, `port`, and optional `name`
- **instanceId tracking** — peer records now store the remote's `instanceId` from health responses for reliable identity matching
+
+## Improvements
+
+### Script jobs for autonomous job system
+- **Script job type** — autonomous jobs can now be marked as `type: 'script'` to execute directly without spawning an AI agent
+- **Autobiography prompt converted** — the autobiography story prompt job now runs as a simple cron-like script instead of invoking an LLM, saving resources for jobs that don't need AI processing
+- **Handler registry** — script jobs reference registered handler functions via `scriptHandler` field, enabling easy addition of more scripted jobs
diff --git a/server/services/autonomousJobs.js b/server/services/autonomousJobs.js
index 7736b576a9..3f29aecb17 100644
--- a/server/services/autonomousJobs.js
+++ b/server/services/autonomousJobs.js
@@ -20,6 +20,15 @@ import { fileURLToPath } from 'url'
import { v4 as uuidv4 } from 'uuid'
import { cosEvents } from './cosEvents.js'
import { ensureDir, PATHS, readJSONFile } from '../lib/fileUtils.js'
+import { checkAndPrompt as autobiographyCheckAndPrompt } from './autobiography.js'
+
+/**
+ * Registry of script handlers for jobs that execute functions directly
+ * instead of spawning AI agents. Key is the scriptHandler name, value is the function.
+ */
+const SCRIPT_HANDLERS = {
+ 'autobiography-prompt': autobiographyCheckAndPrompt
+}
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
@@ -243,14 +252,8 @@ Focus on moving tickets forward. Don't just report - take action by improving ti
intervalMs: DAY,
enabled: true,
priority: 'LOW',
- autonomyLevel: 'assistant',
- promptTemplate: `[Autonomous Job] Autobiography Story Prompt
-
-This job triggers a notification asking the user to write a short autobiographical story.
-
-Call POST /api/digital-twin/autobiography/trigger to check if a prompt is due and send a notification.
-
-This is a lightweight job — it simply checks timing and sends a notification if due. No AI processing needed.`,
+ type: 'script',
+ scriptHandler: 'autobiography-prompt',
lastRun: null,
runCount: 0,
createdAt: null,
@@ -796,6 +799,39 @@ const INTERVAL_OPTIONS = [
{ value: 'monthly', label: 'Monthly', ms: 30 * DAY }
]
+/**
+ * Check if a job is a script job (executes directly, no AI agent needed)
+ * @param {Object} job - The job object
+ * @returns {boolean}
+ */
+function isScriptJob(job) {
+ return !!(job.type === 'script' && job.scriptHandler && SCRIPT_HANDLERS[job.scriptHandler])
+}
+
+/**
+ * Execute a script job directly without spawning an AI agent
+ * @param {Object} job - The script job to execute
+ * @returns {Promise<Object>} Result of the script execution
+ */
+async function executeScriptJob(job) {
+ if (!isScriptJob(job)) {
+ throw new Error(`Job ${job.id} is not a script job`)
+ }
+
+ const handler = SCRIPT_HANDLERS[job.scriptHandler]
+ console.log(`📜 Executing script job: ${job.name}`)
+
+ const result = await handler()
+
+ // Record the job execution
+ await recordJobExecution(job.id)
+
+ console.log(`✅ Script job completed: ${job.name}`)
+ cosEvents.emit('jobs:script-executed', { id: job.id, result })
+
+ return result
+}
+
export {
getAllJobs,
getJob,
@@ -816,5 +852,7 @@ export {
saveJobSkillTemplate,
listJobSkillTemplates,
getJobEffectivePrompt,
- JOB_SKILL_MAP
+ JOB_SKILL_MAP,
+ isScriptJob,
+ executeScriptJob
}
diff --git a/server/services/autonomousJobs.test.js b/server/services/autonomousJobs.test.js
index 63030df9f2..407eb11a7c 100644
--- a/server/services/autonomousJobs.test.js
+++ b/server/services/autonomousJobs.test.js
@@ -8,11 +8,16 @@ vi.mock('./cosEvents.js', () => ({
vi.mock('../lib/fileUtils.js', () => ({
readJSONFile: vi.fn(),
ensureDir: vi.fn().mockResolvedValue(),
- PATHS: { cos: '/mock/data/cos' }
+ PATHS: { cos: '/mock/data/cos', digitalTwin: '/mock/data/digital-twin', data: '/mock/data' }
}))
vi.mock('fs/promises', () => ({
- writeFile: vi.fn().mockResolvedValue()
+ writeFile: vi.fn().mockResolvedValue(),
+ readFile: vi.fn().mockResolvedValue('{}')
+}))
+
+vi.mock('./autobiography.js', () => ({
+ checkAndPrompt: vi.fn().mockResolvedValue({ prompted: true, prompt: { id: 'test-1', text: 'test' } })
}))
// Import after mocks
@@ -27,10 +32,13 @@ import {
toggleJob,
generateTaskFromJob,
getJobStats,
- INTERVAL_OPTIONS
+ INTERVAL_OPTIONS,
+ isScriptJob,
+ executeScriptJob
} from './autonomousJobs.js'
import { readJSONFile } from '../lib/fileUtils.js'
import { cosEvents } from './cosEvents.js'
+import { checkAndPrompt } from './autobiography.js'
describe('autonomousJobs', () => {
const mockJobsData = {
@@ -451,4 +459,78 @@ describe('autonomousJobs', () => {
expect(stats.totalRuns).toBeGreaterThanOrEqual(8)
})
})
+
+ describe('script jobs', () => {
+ it('isScriptJob returns true for script-type jobs', () => {
+ const scriptJob = {
+ id: 'job-test',
+ type: 'script',
+ scriptHandler: 'autobiography-prompt'
+ }
+ expect(isScriptJob(scriptJob)).toBe(true)
+ })
+
+ it('isScriptJob returns false for regular jobs', () => {
+ const regularJob = {
+ id: 'job-test',
+ name: 'Regular Job',
+ promptTemplate: 'Do something'
+ }
+ expect(isScriptJob(regularJob)).toBe(false)
+ })
+
+ it('isScriptJob returns false if handler not registered', () => {
+ const invalidJob = {
+ id: 'job-test',
+ type: 'script',
+ scriptHandler: 'nonexistent-handler'
+ }
+ expect(isScriptJob(invalidJob)).toBe(false)
+ })
+
+ it('executeScriptJob calls the handler and records execution', async () => {
+ readJSONFile.mockResolvedValueOnce({
+ version: 1,
+ lastUpdated: '2025-01-01T00:00:00.000Z',
+ jobs: [
+ {
+ id: 'job-autobiography-prompt',
+ name: 'Autobiography Story Prompt',
+ type: 'script',
+ scriptHandler: 'autobiography-prompt',
+ enabled: true,
+ intervalMs: 86400000,
+ lastRun: null,
+ runCount: 0
+ }
+ ]
+ })
+
+ const scriptJob = {
+ id: 'job-autobiography-prompt',
+ name: 'Autobiography Story Prompt',
+ type: 'script',
+ scriptHandler: 'autobiography-prompt'
+ }
+
+ const result = await executeScriptJob(scriptJob)
+
+ expect(checkAndPrompt).toHaveBeenCalled()
+ expect(result).toEqual({ prompted: true, prompt: { id: 'test-1', text: 'test' } })
+ expect(cosEvents.emit).toHaveBeenCalledWith('jobs:script-executed', {
+ id: 'job-autobiography-prompt',
+ result: { prompted: true, prompt: { id: 'test-1', text: 'test' } }
+ })
+ })
+
+ it('executeScriptJob throws for non-script jobs', async () => {
+ const regularJob = {
+ id: 'job-test',
+ name: 'Regular Job',
+ promptTemplate: 'Do something'
+ }
+
+ await expect(executeScriptJob(regularJob)).rejects.toThrow('not a script job')
+ })
+ })
})
diff --git a/server/services/cos.js b/server/services/cos.js
index 734300e157..d40c518947 100644
--- a/server/services/cos.js
+++ b/server/services/cos.js
@@ -20,7 +20,7 @@ import { getAdaptiveCooldownMultiplier, getSkippedTaskTypes, getPerformanceSumma
import { schedule as scheduleEvent, cancel as cancelEvent, getStats as getSchedulerStats } from './eventScheduler.js';
import { createMutex } from '../lib/asyncMutex.js';
import { generateProactiveTasks as generateMissionTasks, getStats as getMissionStats } from './missions.js';
-import { getDueJobs, generateTaskFromJob, recordJobExecution } from './autonomousJobs.js';
+import { getDueJobs, generateTaskFromJob, recordJobExecution, isScriptJob, executeScriptJob } from './autonomousJobs.js';
import { formatDuration, safeJSONParse } from '../lib/fileUtils.js';
import { addNotification, NOTIFICATION_TYPES } from './notifications.js';
import { recordDecision, DECISION_TYPES } from './decisionLog.js';
@@ -844,6 +844,15 @@ export async function evaluateTasks() {
});
for (const job of dueJobs) {
+ // Script jobs execute directly without spawning an AI agent
+ if (isScriptJob(job)) {
+ await executeScriptJob(job).catch(err => {
+ emitLog('error', `Script job failed: ${job.name} - ${err.message}`, { jobId: job.id });
+ });
+ emitLog('info', `Script job executed: ${job.name}`, { jobId: job.id });
+ continue;
+ }
+
if (tasksToSpawn.length >= availableSlots) break;
const task = await generateTaskFromJob(job);
if (!canSpawnTask(task)) continue;