feat(scheduler): add cron-style scheduled jobs (backend)

Adds a saved/named scheduling layer on top of Codeman's existing session
primitives. Distinct from the legacy run-now ScheduledRun concept.

- types/scheduler.ts: ScheduledJob + ScheduledJobRun
- state-store: persist scheduledJobs/scheduledJobRuns in ~/.codeman/state.json
- scheduler/scheduler-time.ts: pure once/interval/daily/weekly next-run math
- scheduler/scheduler-service.ts: CRUD, Run Now, due-checker tick, run history;
  reuses SessionPort (create -> start -> writeViaMux) for launches
- web/routes/scheduler-routes.ts: /api/scheduler/jobs CRUD + run + history
- web/schemas.ts: zod validation with schedule-type-aware refinements
- web/sse-events.ts: scheduler:* events
- server.ts: wire service into route context + 30s background tick loop
- test/scheduler-time.test.ts: 14 unit tests for next-run calculations

Phase 1 discovery recorded in SCHEDULER_DISCOVERY.md.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Rp7JhmQXcYJhmxFMdZuuah
This commit is contained in:
Kris
2026-06-27 08:10:40 +05:30
co-authored by Claude Opus 4.8
parent abb6447f66
commit 6ae86b53f6
16 changed files with 1087 additions and 0 deletions
+17
View File
@@ -240,6 +240,17 @@ export const ScheduledLog = 'scheduled:log' as const;
/** Scheduled run deleted. */
export const ScheduledDeleted = 'scheduled:deleted' as const;
// ─── Scheduled Jobs (cron-style scheduler) ───────────────────────────────────
/** The scheduled-jobs list changed (created/updated/enabled/run-status). Payload: { jobs }. */
export const SchedulerJobsChanged = 'scheduler:jobsChanged' as const;
/** A scheduled job was deleted. Payload: { id }. */
export const SchedulerJobDeleted = 'scheduler:jobDeleted' as const;
/** A scheduled-job run (history record) was created. Payload: ScheduledJobRun. */
export const SchedulerRunCreated = 'scheduler:runCreated' as const;
/** A scheduled-job run (history record) was updated. Payload: ScheduledJobRun. */
export const SchedulerRunUpdated = 'scheduler:runUpdated' as const;
// ─── Teams ───────────────────────────────────────────────────────────────────
/** Agent team created. */
@@ -469,6 +480,12 @@ export const SseEvent = {
ScheduledLog,
ScheduledDeleted,
// Scheduled jobs (cron-style scheduler)
SchedulerJobsChanged,
SchedulerJobDeleted,
SchedulerRunCreated,
SchedulerRunUpdated,
// Teams
TeamCreated,
TeamUpdated,