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
Custom Scheduled App Tasks
Context
The user wants to create custom scheduled tasks per managed app: provide a free-form prompt + a schedule (interval or cron), scoped to one app, running through the CoS (Chief of Staff) agent system — just like the built-in per-app scheduled tasks, but user-authored rather than chosen from the fixed catalog.
PortOS already has two relevant systems:
- Built-in task types (
DEFAULT_TASK_INTERVALSinserver/services/taskSchedule.js) — a fixed catalog (security, code-quality, plan-task, …) with per-app enable/interval overrides surfaced in/apps/{appId}/automation. These cannot host arbitrary user prompts. - Autonomous jobs (
server/services/autonomousJobs/,cosJobScheduler.js, the CoS "System Tasks" / Jobs tab) — already does exactly "custom prompt + schedule → spawn a CoS agent", with full interval+cron scheduling, autonomy levels, gates, and the spawning-guard machinery. It is just not app-scoped — a job has noappId, so its agent runs in the PortOS root instead of a target app's repo.
Approach (verified): Add an optional appId (and optional git-workflow taskMetadata)
to autonomous jobs. When appId is set, the generated CoS task carries metadata.app = appId,
which the existing spawn path (prepareAgentWorkspace → getAppWorkspace) already resolves
to app.repoPath. This reuses the entire built-in workspace/JIRA/worktree pipeline — no new
scheduler, no new store, no migration. Surface it as a "Custom Tasks" section in the per-app
Automation tab, with optional worktree/PR/simplify toggles so a custom task can do isolated
work and open a PR in the target app.
This is backward/forward compatible per the CLAUDE.md distribution model: appId absent =
global job = today's behavior. No on-disk migration required.
Verified payoff chain (no change needed here)
server/services/agentWorkspacePrep.js:50—prepareAgentWorkspacesetsworkspacePath = getAppWorkspace(task.metadata.app)when present, else ROOT_DIR.server/services/agentPromptBuilder.js:~955—getAppWorkspace(appName)resolves by id or name fromdata/apps.json, returnsapp.repoPath || ROOT_DIR.getAppDataForTask(task)(~977) readstask.metadata.appfor JIRA context.server/services/cosTaskStore.jsaddTaskmapstaskData.app → metadata.app, and alsouseWorktree/openPR/simplify/reviewLoopflags (lines ~159–179). So both the scheduled and manual-trigger paths can carry app + git-workflow options.agentWorkspacePrep.js:60-61—useWorktree/openPRontask.metadatadrive worktree isolation + PR. Setting these in the generated task is sufficient.
Server changes
1. Job model + CRUD — server/services/autonomousJobs/crud.js
createJobjob object: addappId: jobData.appId || nullandtaskMetadata: jobData.taskMetadata || null.updateJobupdatableFieldsallow-list: add'appId'and'taskMetadata'.
2. Task generation — server/services/autonomousJobs/skillTemplates.js (generateTaskFromJob, ~line 144)
Thread app + git options into the task metadata so the spawn path picks them up:
metadata: {
autonomousJob: true,
jobId: job.id, jobName: job.name, jobCategory: job.category,
autonomyLevel: job.autonomyLevel,
...(job.appId ? { app: job.appId } : {}),
...(job.taskMetadata?.useWorktree != null ? { useWorktree: job.taskMetadata.useWorktree } : {}),
...(job.taskMetadata?.openPR != null ? { openPR: job.taskMetadata.openPR } : {}),
...(job.taskMetadata?.simplify != null ? { simplify: job.taskMetadata.simplify } : {}),
}
3. Validation — server/lib/validation.js (createCosJobSchema, line 713)
Add (tolerating UI '' sentinels, mirroring the existing triggerAction preprocess):
appId: z.preprocess(v => v === '' ? undefined : v, z.string().optional()),
taskMetadata: z.object({
useWorktree: z.boolean().optional(),
openPR: z.boolean().optional(),
simplify: z.boolean().optional(),
}).optional(),
updateCosJobSchema inherits both via .partial().
4. Routes — server/routes/cosJobRoutes.js
- POST
/jobs(line 75) and PUTline 112): add/jobs/:id(appIdandtaskMetadatato the destructured fields and pass them intocreateJob/updateJob. - CRITICAL GOTCHA — manual trigger (
POST /jobs/:id/trigger, ~line 177): it currently callscos.addTask({ description, priority, context, approvalRequired }, 'internal')and dropstask.metadata, so a manually-triggered app-scoped job would run in ROOT_DIR. Forward the app + git options:
(The scheduled path is unaffected — it emits the full task object viaconst taskResult = await cos.addTask({ description: task.description, priority: task.priority, context: `Manually triggered autonomous job: ${job.name}`, approvalRequired: false, app: task.metadata?.app, useWorktree: task.metadata?.useWorktree, openPR: task.metadata?.openPR, simplify: task.metadata?.simplify, }, 'internal');task:ready.)
5. No migration / no JOB_ADDITIVE_FIELDS change
The defaults.js restart-merge only touches jobs whose IDs match shipped DEFAULT_JOBS; a
user job's appId/taskMetadata persists on its own through saveJobs. Absent appId =
global = current behavior, so no scripts/migrations/ entry is needed.
Client changes
Primary — per-app "Custom Tasks" section in client/src/components/apps/tabs/AutomationTab.jsx
Route already exists: /apps/{appId}/automation. Add a section below the existing
"Task Type Overrides":
- Fetch
api.getCosJobs()and filter tojobs.filter(j => j.appId === appId). - Render each as a compact card (name, schedule summary via
describeCron/interval label, enabled toggle, Run-now, edit, delete) — reuse the patterns already inclient/src/components/cos/tabs/JobsTab.jsx(JobCard,ScheduleFields,normalizeJobPayload,formatNextDue). Consider extracting the shared form bits intoclient/src/components/cos/JobForm.jsxto avoid duplication, or import the existing helpers. - Create/edit form fields: name, description, prompt template, schedule (interval/cron via
existing
ScheduleFields+cronHelpers), priority, autonomy level, and the new worktree/PR/simplify toggles (reuseAGENT_OPTIONS/agentOptionButtonClassfromclient/src/components/cos/constants.jsfor visual consistency with built-in overrides). - On save: force
type: 'agent'andappIdto this app; sendtaskMetadatafor the toggles.apiAgents.jscreateCosJob/updateCosJobalready accept arbitrary payloads — no signature change required, but confirm they forward the body verbatim.
Secondary — app badge/picker in the global JobsTab.jsx
- Add an optional app picker to the global create/edit forms (populate via
apiApps.getApps()fromclient/src/services/apiApps.js); blank = global job. - Show an app badge on each
JobCardwhenjob.appIdis set (resolve id → name). - This keeps every custom task centrally visible/manageable in CoS → System Tasks, while the per-app tab is the discovery surface.
API client — client/src/services/apiAgents.js
No new endpoints. Verify createCosJob/updateCosJob pass the full payload (including appId,
taskMetadata) through request(); add fields to any payload-whitelisting if present.
Prompt / app context note
A raw promptTemplate is not run through {appName}/{repoPath} templating, but correctness
holds: the agent's cwd is app.repoPath (so the CLI provider loads that repo's CLAUDE.md),
and buildTaskBlock already adds a **Target App** line from metadata.app. Optional polish:
resolve the app id to its display name in that line.
Gotchas / guardrails (already correct)
state.config.autonomousJobsEnabledand the per-domain CoS autonomy gate (cosJobScheduler.js:170,185) already apply to all scheduled jobs, including app-scoped — desired.- Duplicate-spawn guards (
spawningJobIds) and capacity checks already cover these jobs. metadata.appduplicate-detection inaddTaskis scoped per app, so two apps' custom tasks with similar prompts won't collide.
Tests
server/services/autonomousJobs.test.js:appId+taskMetadatapersisted on create; settable/clearable via update;generateTaskFromJobsetsmetadata.app(and worktree/PR flags) whenappId/taskMetadatapresent, omits them otherwise. Extend the existing describe block. Follow the project rule: record-creating tests mustmockNoPeers()+mockNoPeerSync()if they touch app create paths — but these tests operate on the jobs store, not universes/series, so verify whether peer mocking is needed (likely not; jobs store has no peer fan-out).server/routes/cosJobRoutes.test.js: POST/PUT acceptappId+taskMetadata;'' → undefined; manual trigger forwardsapp/useWorktree/openPRinto theaddTaskcall (assert via mock).- Client: a
JobsTab/AutomationTabVitest covering the app filter + create payload shape (type:'agent',appIdset) if a matching test harness exists.
Catalog / barrel / README
No new public module in server/lib/, client/src/lib/, client/src/hooks/,
client/src/utils/, or a new apiX.js — so no barrel/README maintenance is triggered. If a
shared JobForm.jsx component is extracted under client/src/components/cos/, that's a
component (not a catalogued lib), so no index/README update is required.
Verification (end-to-end)
cd server && npm test— new job appId/taskMetadata + route tests pass; existing job tests green.cd client && npm test— any new component test passes; build the client.- Manual:
npm run dev, open/apps/{appId}/automation, create a custom task (e.g. prompt "Update the README badges", cron0 9 * * 1, worktree+PR on), enable it, click Run now. Confirm in CoS → Agents that the spawned agent's workspace is the app'srepoPath(check the agent record'sworkspacePath/sourceWorkspace) and — with PR on — that an isolated worktree was created. Verify a scheduled fire also targets the app repo (temporarily set a near-future cron) and that toggling the globalautonomousJobsEnabledoff withholds it. - Confirm the task also appears (with an app badge) in the global CoS System Tasks tab.