@mulmoclaude/core 0.2.8 → 0.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/assets/skills-preset/mc-manage-automations/SKILL.md +1 -1
  2. package/dist/collection/server/index.js +1 -1
  3. package/dist/collection-watchers/index.js +1 -1
  4. package/dist/feeds/server/index.js +1 -1
  5. package/dist/{server-B2YkcCwl.js → server-q4WPXtbU.js} +22 -14
  6. package/dist/{server-B2YkcCwl.js.map → server-q4WPXtbU.js.map} +1 -1
  7. package/package.json +1 -1
  8. package/dist/collection/core/actionVisible.d.ts +0 -34
  9. package/dist/collection/core/calendarGrid.d.ts +0 -120
  10. package/dist/collection/core/deriveAll.d.ts +0 -38
  11. package/dist/collection/core/derivedFormula.d.ts +0 -18
  12. package/dist/collection/core/draft.d.ts +0 -18
  13. package/dist/collection/core/enumColors.d.ts +0 -33
  14. package/dist/collection/core/errorMessage.d.ts +0 -4
  15. package/dist/collection/core/itemLabel.d.ts +0 -12
  16. package/dist/collection/core/presentCollection.d.ts +0 -13
  17. package/dist/collection/core/promptSafety.d.ts +0 -1
  18. package/dist/collection/core/schema.d.ts +0 -382
  19. package/dist/collection/core/shortHexId.d.ts +0 -8
  20. package/dist/collection/core/sortItems.d.ts +0 -29
  21. package/dist/collection/core/uiTypes.d.ts +0 -106
  22. package/dist/collection/index.cjs +0 -794
  23. package/dist/collection/index.cjs.map +0 -1
  24. package/dist/collection/index.d.ts +0 -14
  25. package/dist/collection/paths.cjs +0 -44
  26. package/dist/collection/paths.cjs.map +0 -1
  27. package/dist/collection/server/atomic.d.ts +0 -1
  28. package/dist/collection/server/delete.d.ts +0 -38
  29. package/dist/collection/server/derive.d.ts +0 -8
  30. package/dist/collection/server/discoveredCollection.d.ts +0 -18
  31. package/dist/collection/server/discovery.d.ts +0 -239
  32. package/dist/collection/server/host.d.ts +0 -77
  33. package/dist/collection/server/index.cjs +0 -51
  34. package/dist/collection/server/io.d.ts +0 -120
  35. package/dist/collection/server/paths.d.ts +0 -52
  36. package/dist/collection/server/spawn.d.ts +0 -55
  37. package/dist/collection/server/util.d.ts +0 -3
  38. package/dist/collection/server/validate.d.ts +0 -19
  39. package/dist/collection/server/views.d.ts +0 -20
  40. package/dist/collection-watchers/config.d.ts +0 -49
  41. package/dist/collection-watchers/index.cjs +0 -553
  42. package/dist/collection-watchers/index.cjs.map +0 -1
  43. package/dist/collection-watchers/index.d.ts +0 -3
  44. package/dist/collection-watchers/reconciler.d.ts +0 -33
  45. package/dist/collection-watchers/watcher.d.ts +0 -34
  46. package/dist/deriveAll-VRWrs3SF.cjs +0 -413
  47. package/dist/deriveAll-VRWrs3SF.cjs.map +0 -1
  48. package/dist/feeds/index.cjs +0 -8
  49. package/dist/feeds/index.d.ts +0 -1
  50. package/dist/feeds/ingestTypes.d.ts +0 -57
  51. package/dist/feeds/paths.cjs +0 -48
  52. package/dist/feeds/paths.cjs.map +0 -1
  53. package/dist/feeds/paths.d.ts +0 -22
  54. package/dist/feeds/server/fetch/httpClient.d.ts +0 -8
  55. package/dist/feeds/server/fetch/rssParser.d.ts +0 -12
  56. package/dist/feeds/server/index.cjs +0 -840
  57. package/dist/feeds/server/index.cjs.map +0 -1
  58. package/dist/feeds/server/pathResolver.d.ts +0 -6
  59. package/dist/feeds/server/projectItem.d.ts +0 -8
  60. package/dist/feeds/server/refreshResult.d.ts +0 -17
  61. package/dist/feeds/server/retrievers/httpJson.d.ts +0 -3
  62. package/dist/feeds/server/retrievers/index.d.ts +0 -12
  63. package/dist/feeds/server/retrievers/registerAll.d.ts +0 -0
  64. package/dist/feeds/server/retrievers/rss.d.ts +0 -3
  65. package/dist/file-change/index.cjs +0 -72
  66. package/dist/file-change/index.cjs.map +0 -1
  67. package/dist/file-change/index.d.ts +0 -43
  68. package/dist/ingestTypes-DDOVhOYC.cjs +0 -32
  69. package/dist/ingestTypes-DDOVhOYC.cjs.map +0 -1
  70. package/dist/notifier/engine.d.ts +0 -72
  71. package/dist/notifier/index.cjs +0 -21
  72. package/dist/notifier/index.d.ts +0 -3
  73. package/dist/notifier/store.d.ts +0 -18
  74. package/dist/notifier/types.d.ts +0 -118
  75. package/dist/notifier/validate.d.ts +0 -17
  76. package/dist/notifier-bS8IEeLA.cjs +0 -577
  77. package/dist/notifier-bS8IEeLA.cjs.map +0 -1
  78. package/dist/rolldown-runtime-D6vf50IK.cjs +0 -28
  79. package/dist/scheduler/adapter.d.ts +0 -48
  80. package/dist/scheduler/index.cjs +0 -352
  81. package/dist/scheduler/index.cjs.map +0 -1
  82. package/dist/scheduler/index.d.ts +0 -2
  83. package/dist/scheduler/task-manager.d.ts +0 -51
  84. package/dist/server-D27UzXug.cjs +0 -1985
  85. package/dist/server-D27UzXug.cjs.map +0 -1
  86. package/dist/skill-bridge/index.cjs +0 -88
  87. package/dist/skill-bridge/index.cjs.map +0 -1
  88. package/dist/skill-bridge/index.d.ts +0 -30
  89. package/dist/whisper/client.cjs +0 -241
  90. package/dist/whisper/client.cjs.map +0 -1
  91. package/dist/whisper/client.d.ts +0 -35
  92. package/dist/whisper/ffmpeg.d.ts +0 -6
  93. package/dist/whisper/index.cjs +0 -433
  94. package/dist/whisper/index.cjs.map +0 -1
  95. package/dist/whisper/index.d.ts +0 -5
  96. package/dist/whisper/internal.d.ts +0 -11
  97. package/dist/whisper/models.d.ts +0 -49
  98. package/dist/whisper/sidecar.d.ts +0 -8
  99. package/dist/whisper/whisper.d.ts +0 -28
  100. package/dist/workspace-setup/assets.d.ts +0 -10
  101. package/dist/workspace-setup/index.d.ts +0 -3
  102. package/dist/workspace-setup/index.js +0 -560
  103. package/dist/workspace-setup/index.js.map +0 -1
  104. package/dist/workspace-setup/slug.d.ts +0 -6
  105. package/dist/workspace-setup/slug.js +0 -13
  106. package/dist/workspace-setup/slug.js.map +0 -1
  107. package/dist/workspace-setup/sync.d.ts +0 -94
@@ -1 +0,0 @@
1
- {"version":3,"file":"notifier-bS8IEeLA.cjs","names":[],"sources":["../src/notifier/types.ts","../src/notifier/store.ts","../src/notifier/validate.ts","../src/notifier/engine.ts"],"sourcesContent":["// Notifier value types. Kept dependency-free (no node, no fs, no\n// pubsub) so the host's API-route layer and any future browser\n// consumer can validate inbound payloads against the same enum\n// constants the engine accepts without pulling in the engine's I/O.\n\n/** Two notification shapes, distinguished by who fires the close call:\n *\n * `fyi` — informational. The host (bell panel) clears it when the\n * user dismisses the row. No deep-link target.\n * `action` — pending obligation. The plugin clears it when the\n * underlying domain state changes (the user paid the tax,\n * viewed the digest, etc.). The bell row navigates to\n * `navigateTarget` on click.\n *\n * The engine reads `lifecycle` only to enforce two publish-time rules\n * (everything downstream — pubsub fan-out, persistence, history — is\n * lifecycle-blind):\n *\n * 1. `action` requires a non-empty `navigateTarget`. Without one,\n * clicking the row does nothing and the entry is a degraded fyi.\n * 2. `action` cannot use `info` severity. A low-priority obligation\n * is incoherent — fyi if it's a ping, `nudge`/`urgent` if it's a\n * real obligation worth a landing page.\n *\n * Both rules are mirrored in the HTTP layer so plugin-runtime callers\n * and HTTP callers hit the same wall. */\nexport const NOTIFIER_LIFECYCLES = [\"fyi\", \"action\"] as const;\nexport type NotifierLifecycle = (typeof NOTIFIER_LIFECYCLES)[number];\n\n/** Severity drives badge color (gray / amber / red, worst-wins) and\n * in a future iteration channel routing. Mostly stored verbatim by\n * the engine; the one engine-visible interaction is the rule that\n * `action` lifecycle cannot pair with `info` severity (see\n * `NotifierLifecycle` above). */\nexport const NOTIFIER_SEVERITIES = [\"info\", \"nudge\", \"urgent\"] as const;\nexport type NotifierSeverity = (typeof NOTIFIER_SEVERITIES)[number];\n\nexport interface NotifierEntry<TPluginData = unknown> {\n /** Engine-assigned UUID. Generated synchronously inside `publish()`\n * so the caller can use it before persistence completes. */\n id: string;\n /** Plugin namespace (e.g. `\"encore\"`, `\"debug__system\"`). The\n * engine never inspects it — used only for `listFor()` filtering\n * and as a UI grouping key. */\n pluginPkg: string;\n severity: NotifierSeverity;\n lifecycle?: NotifierLifecycle;\n title: string;\n body?: string;\n /** Optional in-app deep-link target (relative URL). The bell popup\n * routes here on row click, with `&notificationId=<id>` appended\n * so the landing page can identify which entry to clear. The\n * engine doesn't read this — it's a UI hint stored on the entry. */\n navigateTarget?: string;\n /** Opaque to the engine. Round-trips through JSON unchanged; only\n * the originating plugin's UI knows the shape. */\n pluginData?: TPluginData;\n /** ISO-8601 timestamp set at `publish()` time. */\n createdAt: string;\n}\n\n/** A history entry — a `NotifierEntry` after it has been cleared or\n * cancelled, with the terminal type and timestamp recorded. The\n * bell popup's \"History\" section renders these read-only. */\nexport interface NotifierHistoryEntry<TPluginData = unknown> extends NotifierEntry<TPluginData> {\n terminalType: \"cleared\" | \"cancelled\";\n terminalAt: string;\n}\n\n/** Caller-supplied input for `publish()`. The engine fills in `id`\n * and `createdAt`; everything else flows through verbatim.\n *\n * Two publish-time rules apply to `action` lifecycle (see\n * `NotifierLifecycle`):\n *\n * - `navigateTarget` MUST be a non-empty string.\n * - `severity` MUST NOT be `\"info\"`.\n *\n * Violations cause `publish()` to throw. Currently expressed as\n * runtime validation rather than a discriminated-union type, so the\n * fields below are all individually optional / loose at the\n * type-level. */\nexport interface PublishInput<TPluginData = unknown> {\n pluginPkg: string;\n severity: NotifierSeverity;\n title: string;\n body?: string;\n lifecycle?: NotifierLifecycle;\n navigateTarget?: string;\n pluginData?: TPluginData;\n}\n\n/** On-disk shape of `~/mulmoclaude/data/notifier/active.json`. Holds\n * only entries that haven't been cleared or cancelled — the file is\n * a snapshot, not an event log. */\nexport interface NotifierFile {\n entries: Record<string, NotifierEntry>;\n}\n\n/** On-disk shape of `~/mulmoclaude/data/notifier/history.json`. Array\n * of terminated entries newest-first, capped at `HISTORY_CAP` with\n * FIFO eviction (push at index 0, slice from the tail). */\nexport interface NotifierHistoryFile {\n entries: NotifierHistoryEntry[];\n}\n\n/** History size cap. The bell popup's History section renders this\n * many entries; older ones fall off when new terminations land. */\nexport const HISTORY_CAP = 50;\n\n/** Pub-sub event published on the host's notifier channel after every\n * successful state change. Discriminated union — subscribers switch\n * on `type` to keep TypeScript narrowing the rest of the payload.\n *\n * `updated` carries the post-mutation entry — the receiver swaps\n * the matching `id` in their local active set. Reserved for in-\n * place edits via `updateForPlugin`; no history record is written\n * because the entry is still active, just with refreshed content. */\nexport type NotifierEvent =\n | { type: \"published\"; entry: NotifierEntry }\n | { type: \"cleared\"; id: string }\n | { type: \"cancelled\"; id: string }\n | { type: \"updated\"; entry: NotifierEntry };\n","// Low-level file I/O for the notifier. Reads use node:fs directly;\n// writes go through an injected atomic-JSON writer (the host owns the\n// rename-based atomic write so it stays single-sourced with its other\n// writers). Kept separate from `engine.ts` so the path can be\n// overridden in tests without monkey-patching.\n\nimport { promises as fsPromises } from \"node:fs\";\nimport type { NotifierFile, NotifierHistoryFile } from \"./types.js\";\n\n/** Injected atomic JSON writer — the host's `writeJsonAtomic`. */\nexport type WriteJson = (filePath: string, data: unknown) => Promise<void>;\n\nfunction isNotFoundError(err: unknown): boolean {\n return typeof err === \"object\" && err !== null && (err as { code?: unknown }).code === \"ENOENT\";\n}\n\n/** Read the active-entries file. Returns an empty store when the file\n * doesn't exist yet (first ever call on a fresh workspace). Any other\n * read or parse failure throws — the caller has to decide whether to\n * surface or recover, since silently treating \"malformed file\" as\n * \"no entries\" would lose data. */\nexport async function loadActive(filePath: string): Promise<NotifierFile> {\n let text: string;\n try {\n text = await fsPromises.readFile(filePath, \"utf-8\");\n } catch (err) {\n if (isNotFoundError(err)) return { entries: {} };\n throw err;\n }\n const parsed: unknown = JSON.parse(text);\n // `typeof null === \"object\"` and `Array.isArray([])` is also true,\n // so a naive `typeof entries !== \"object\"` check would let\n // `{ entries: null }` and `{ entries: [] }` through, which then\n // crash downstream `engine.get` / `list*` mutations. Reject both\n // shapes here at load time so the failure surfaces as a clear\n // \"malformed file\" error.\n if (typeof parsed !== \"object\" || parsed === null || !(\"entries\" in parsed)) {\n throw new Error(`notifier: malformed active.json at ${filePath}`);\n }\n const { entries } = parsed as { entries: unknown };\n if (typeof entries !== \"object\" || entries === null || Array.isArray(entries)) {\n throw new Error(`notifier: malformed active.json at ${filePath}`);\n }\n return parsed as NotifierFile;\n}\n\n/** Write the active-entries file via the injected atomic writer so a\n * half-written file is never visible to readers. The caller serialises\n * writes (engine.ts queues mutations) — this function makes no\n * concurrency guarantees of its own. */\nexport async function saveActive(writeJson: WriteJson, filePath: string, state: NotifierFile): Promise<void> {\n await writeJson(filePath, state);\n}\n\n/** Read the history file. Empty array on first run. Same parse-error\n * policy as `loadActive`. */\nexport async function loadHistory(filePath: string): Promise<NotifierHistoryFile> {\n let text: string;\n try {\n text = await fsPromises.readFile(filePath, \"utf-8\");\n } catch (err) {\n if (isNotFoundError(err)) return { entries: [] };\n throw err;\n }\n const parsed: unknown = JSON.parse(text);\n if (typeof parsed !== \"object\" || parsed === null || !(\"entries\" in parsed) || !Array.isArray((parsed as { entries: unknown }).entries)) {\n throw new Error(`notifier: malformed history.json at ${filePath}`);\n }\n return parsed as NotifierHistoryFile;\n}\n\nexport async function saveHistory(writeJson: WriteJson, filePath: string, state: NotifierHistoryFile): Promise<void> {\n await writeJson(filePath, state);\n}\n","// Publish-input validation — pure, dependency-free. Shared by\n// `engine.publish` (throws on error) and the host's HTTP route\n// (returns 400 on error). Single source of truth so plugin-runtime\n// callers and HTTP callers can't drift.\n\nimport type { PublishInput } from \"./types.js\";\n\n/** Hard caps on publish-input fields. The engine reads each entry on\n * every list/get call (no in-memory cache), so unbounded fields hurt\n * every reader. Caps chosen to be generous for legitimate UX copy\n * while bounding active.json growth: a notification fundamentally is\n * a short blurb, not a document. */\nexport const NOTIFIER_LIMITS = {\n titleMax: 200,\n bodyMax: 4000,\n navigateTargetMax: 1000,\n pluginDataMaxBytes: 16 * 1024,\n} as const;\n\nfunction validateTitle(title: string): string | null {\n if (typeof title !== \"string\" || title.length === 0) return \"title must be a non-empty string\";\n if (title.length > NOTIFIER_LIMITS.titleMax) return `title exceeds max length of ${NOTIFIER_LIMITS.titleMax} chars`;\n return null;\n}\n\nfunction validateBody(body: string | undefined): string | null {\n if (body === undefined) return null;\n if (body.length > NOTIFIER_LIMITS.bodyMax) return `body exceeds max length of ${NOTIFIER_LIMITS.bodyMax} chars`;\n return null;\n}\n\nfunction validateNavigateTarget(target: string | undefined): string | null {\n if (target === undefined) return null;\n if (target.length === 0) return \"navigateTarget must be a non-empty relative path when set\";\n if (target.length > NOTIFIER_LIMITS.navigateTargetMax) {\n return `navigateTarget exceeds max length of ${NOTIFIER_LIMITS.navigateTargetMax} chars`;\n }\n // Must be a same-origin relative path. Reject schemes\n // (`javascript:`, `https://...`) and scheme-relative URLs\n // (`//evil.com/...`, which an `<a href>` would resolve to the\n // attacker's origin). One leading \"/\" only.\n if (!target.startsWith(\"/\") || target.startsWith(\"//\")) {\n return \"navigateTarget must be a relative path beginning with a single '/' (no scheme, no '//')\";\n }\n return null;\n}\n\nfunction validatePluginData(pluginData: unknown): string | null {\n if (pluginData === undefined) return null;\n let serialized: string | undefined;\n try {\n serialized = JSON.stringify(pluginData);\n } catch (err) {\n return `pluginData is not JSON-serialisable: ${String(err)}`;\n }\n // `JSON.stringify` returns `undefined` for non-serialisable roots\n // (e.g. a bare function or symbol). Treat that as a serialisation\n // failure so it doesn't slip through as an empty-string size.\n if (typeof serialized !== \"string\") return \"pluginData is not JSON-serialisable\";\n if (serialized.length > NOTIFIER_LIMITS.pluginDataMaxBytes) {\n return `pluginData JSON exceeds ${NOTIFIER_LIMITS.pluginDataMaxBytes} bytes`;\n }\n return null;\n}\n\nfunction validateActionCoherence(input: PublishInput): string | null {\n if (input.lifecycle !== \"action\") return null;\n if (input.severity === \"info\") {\n return \"action lifecycle is incompatible with info severity (use fyi for low-priority pings)\";\n }\n if (typeof input.navigateTarget !== \"string\" || input.navigateTarget.length === 0) {\n return \"action lifecycle requires a non-empty navigateTarget\";\n }\n return null;\n}\n\n/** Validate a `PublishInput`. Returns `null` if OK, or a\n * human-readable error string. Order matters — shape/size errors are\n * reported before lifecycle/severity coherence errors so the message\n * the caller sees points at the most fundamental problem first. */\nexport function validatePublishInput(input: PublishInput): string | null {\n return (\n validateTitle(input.title) ??\n validateBody(input.body) ??\n validateNavigateTarget(input.navigateTarget) ??\n validatePluginData(input.pluginData) ??\n validateActionCoherence(input)\n );\n}\n","// Notifier engine — single-process, two-file (active + history),\n// single-channel. Host-agnostic: file paths, the atomic JSON writer,\n// the pub-sub event sink, and the logger are all injected via\n// `configureNotifier` + `setNotifierFilePaths` so MulmoClaude and\n// MulmoTerminal share one notification engine over their own\n// workspaces and pub-sub fabrics.\n//\n// API surface: publish / clear / cancel / get / listFor / listAll /\n// listHistory (+ plugin-scoped variants). Mutations queue through a\n// writing-flag + waiter-queue coordinator so concurrent callers can't\n// race on the atomic write's rename. Reads bypass the queue (rename\n// atomicity makes half-reads impossible) and trade strict\n// linearisability for simpler code: the contract is \"after\n// `await publish(x)` resolves, subsequent reads see x\" — which holds\n// because `publish` awaits the persist before returning.\n//\n// `clear` / `cancel` push to history *before* removing from active.\n// History persistence is best-effort: if it fails, the active write\n// still wins and the failure is logged. Active is the source of\n// truth; history is an audit aid.\n\nimport { randomUUID } from \"node:crypto\";\nimport { loadActive, loadHistory, saveActive, saveHistory, type WriteJson } from \"./store.js\";\nimport { validatePublishInput } from \"./validate.js\";\nimport {\n HISTORY_CAP,\n type NotifierEntry,\n type NotifierEvent,\n type NotifierFile,\n type NotifierHistoryEntry,\n type NotifierSeverity,\n type PublishInput,\n} from \"./types.js\";\n\nexport { NOTIFIER_LIMITS, validatePublishInput } from \"./validate.js\";\n\n// ── Dependency injection ──────────────────────────────────────────\n\n/** Minimal logger the engine needs. The host passes its structured\n * logger; absent one, failures are swallowed (the engine never throws\n * on a fan-out/persist-best-effort path). */\nexport interface NotifierLogger {\n warn: (message: string, data?: Record<string, unknown>) => void;\n error: (message: string, data?: Record<string, unknown>) => void;\n}\n\nexport interface NotifierConfig {\n /** Atomic JSON writer (the host's `writeJsonAtomic`). */\n writeJson: WriteJson;\n /** Fan-out sink — the host binds this to `pubsub.publish(channel, event)`. */\n publishEvent: (event: NotifierEvent) => void;\n /** Optional logger. */\n log?: NotifierLogger;\n}\n\nconst NOOP_LOG: NotifierLogger = { warn: () => {}, error: () => {} };\n\nlet config: NotifierConfig | null = null;\nlet activeFilePath = \"\";\nlet historyFilePath = \"\";\n\nfunction logger(): NotifierLogger {\n return config?.log ?? NOOP_LOG;\n}\n\n/** Wire the engine's I/O deps. Call once at startup, before the first\n * mutation. Does NOT set file paths — those are set independently via\n * `setNotifierFilePaths` so a host can bind production paths at module\n * load and a test can override them without re-supplying the deps. */\nexport function configureNotifier(injected: NotifierConfig): void {\n config = injected;\n}\n\n// ── In-process event listeners ────────────────────────────────────\n//\n// Separate from the socket.io pubsub so server-side adapters (macOS\n// push, future Encore) can react to state changes without going\n// through a websocket round-trip. The host's pubsub is fan-out-only\n// with no server-side subscribe, so this listener registry is the\n// in-process equivalent. Listeners run synchronously inside `emit`,\n// before the pubsub fan-out.\n\ntype NotifierEventListener = (event: NotifierEvent) => void;\nconst listeners: NotifierEventListener[] = [];\n\n/** Register an in-process listener for engine events. Returns an\n * unsubscribe function the caller can use during teardown. */\nexport function onEvent(listener: NotifierEventListener): () => void {\n listeners.push(listener);\n return () => {\n const idx = listeners.indexOf(listener);\n if (idx >= 0) listeners.splice(idx, 1);\n };\n}\n\nfunction emit(event: NotifierEvent): void {\n // In-process fan-out first. Each listener is wrapped: a throwing\n // listener must not poison the rest, and must not propagate out of\n // `processBatch` and strand the still-unsettled waiters (their\n // resolve/reject is called *after* this emit loop). Fan-out is\n // best-effort by contract — losing one subscriber must not lose\n // the write that already committed.\n for (const listener of listeners) {\n try {\n listener(event);\n } catch (err) {\n logger().error(\"in-process listener failed\", { type: event.type, error: String(err) });\n }\n }\n if (!config) {\n logger().warn(\"emit before init\", { type: event.type });\n return;\n }\n try {\n config.publishEvent(event);\n } catch (err) {\n logger().error(\"emit failed\", { type: event.type, error: String(err) });\n }\n}\n\n// ── Write coordinator ─────────────────────────────────────────────\n\n/** A mutation function applied to the in-memory state object during\n * drain. Returns either:\n *\n * - `null` — no state change (e.g., `clear` on an unknown id).\n * The drainer skips the disk write and the emit if every\n * mutation in a batch returned `null`.\n * - `{ event, historyEntry? }` — state changed. The drainer emits\n * the event after the active write succeeds, and prepends\n * `historyEntry` to history (best-effort) when present.\n *\n * Mutations MUST NOT modify state when returning `null`. Violating\n * this invariant produces a write skip with stale on-disk state. */\ntype MutationOutcome = { event: NotifierEvent; historyEntry?: NotifierHistoryEntry } | null;\ntype Mutation = (state: NotifierFile) => MutationOutcome;\n\ninterface Waiter {\n mutate: Mutation;\n resolve: () => void;\n reject: (err: unknown) => void;\n}\n\ntype MutationResult = { ok: true; outcome: MutationOutcome } | { ok: false; error: unknown };\n\nlet writing = false;\nlet waiters: Waiter[] = [];\n\n/** Point the engine at its active/history files. Resets the write\n * queue, so callers must not have in-flight mutations. The host calls\n * this once with the workspace paths; tests call it per-case with temp\n * files. */\nexport function setNotifierFilePaths(paths: { active: string; history: string }): void {\n activeFilePath = paths.active;\n historyFilePath = paths.history;\n writing = false;\n waiters = [];\n}\n\n/** Test-only: clear config + queue so each suite starts clean. */\nexport function resetNotifier(): void {\n config = null;\n activeFilePath = \"\";\n historyFilePath = \"\";\n writing = false;\n waiters = [];\n listeners.length = 0;\n}\n\nfunction requireWriteJson(): WriteJson {\n if (!config) throw new Error(\"notifier: configureNotifier() not called\");\n return config.writeJson;\n}\n\nfunction applyBatchMutations(batch: Waiter[], state: NotifierFile): MutationResult[] {\n return batch.map((waiter) => {\n try {\n return { ok: true, outcome: waiter.mutate(state) };\n } catch (err) {\n return { ok: false, error: err };\n }\n });\n}\n\nfunction collectEvents(results: MutationResult[]): NotifierEvent[] {\n const events: NotifierEvent[] = [];\n for (const result of results) {\n if (result.ok && result.outcome !== null) events.push(result.outcome.event);\n }\n return events;\n}\n\nfunction collectHistoryEntries(results: MutationResult[]): NotifierHistoryEntry[] {\n const entries: NotifierHistoryEntry[] = [];\n for (const result of results) {\n if (result.ok && result.outcome !== null && result.outcome.historyEntry) {\n entries.push(result.outcome.historyEntry);\n }\n }\n return entries;\n}\n\nfunction settleBatch(batch: Waiter[], results: MutationResult[]): void {\n // Resolves come AFTER any emits so subscribers see the event\n // before the caller's `await` returns.\n for (let index = 0; index < batch.length; index += 1) {\n const result = results[index];\n if (result.ok) batch[index].resolve();\n else batch[index].reject(result.error);\n }\n}\n\nfunction rejectBatch(batch: Waiter[], err: unknown): void {\n for (const waiter of batch) waiter.reject(err);\n}\n\nasync function persistHistory(newEntries: NotifierHistoryEntry[]): Promise<void> {\n const existing = await loadHistory(historyFilePath);\n // Newest-first ordering: a batch contains terminations in arrival\n // order; we want the last one to land at index 0 of history.\n const merged = [...newEntries.slice().reverse(), ...existing.entries].slice(0, HISTORY_CAP);\n await saveHistory(requireWriteJson(), historyFilePath, { entries: merged });\n}\n\nasync function processBatch(batch: Waiter[]): Promise<void> {\n let state: NotifierFile;\n try {\n state = await loadActive(activeFilePath);\n } catch (err) {\n logger().error(\"load failed\", { error: String(err) });\n rejectBatch(batch, err);\n return;\n }\n const results = applyBatchMutations(batch, state);\n const events = collectEvents(results);\n const historyEntries = collectHistoryEntries(results);\n\n if (events.length > 0) {\n try {\n await saveActive(requireWriteJson(), activeFilePath, state);\n } catch (err) {\n logger().error(\"active write failed\", { error: String(err) });\n rejectBatch(batch, err);\n return;\n }\n if (historyEntries.length > 0) {\n // Best-effort: active is the source of truth, history is an\n // audit aid. A failed history write is logged but doesn't\n // unwind the active commit.\n try {\n await persistHistory(historyEntries);\n } catch (err) {\n logger().error(\"history write failed\", { error: String(err) });\n }\n }\n for (const event of events) emit(event);\n }\n settleBatch(batch, results);\n}\n\nasync function drain(): Promise<void> {\n writing = true;\n try {\n while (waiters.length > 0) {\n const batch = waiters;\n waiters = [];\n await processBatch(batch);\n }\n } finally {\n writing = false;\n }\n}\n\nfunction enqueue(mutate: Mutation): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n waiters.push({ mutate, resolve, reject });\n if (!writing) void drain();\n });\n}\n\nfunction removeEntry(state: NotifierFile, entryId: string): NotifierFile[\"entries\"] {\n // Object-rest excludes the key without invoking `delete`.\n const { [entryId]: __removed, ...remaining } = state.entries;\n return remaining;\n}\n\nfunction buildHistoryEntry(entry: NotifierEntry, terminalType: \"cleared\" | \"cancelled\"): NotifierHistoryEntry {\n return { ...entry, terminalType, terminalAt: new Date().toISOString() };\n}\n\n// ── Public API ────────────────────────────────────────────────────\n\nexport async function publish<TPluginData = unknown>(input: PublishInput<TPluginData>): Promise<{ id: string }> {\n // Validate at the engine boundary so plugin-runtime callers and\n // HTTP callers hit the same wall.\n const validationError = validatePublishInput(input as PublishInput);\n if (validationError) {\n throw new Error(`notifier.publish: ${validationError}`);\n }\n const entryId = randomUUID();\n const entry: NotifierEntry<TPluginData> = {\n id: entryId,\n pluginPkg: input.pluginPkg,\n severity: input.severity,\n lifecycle: input.lifecycle,\n title: input.title,\n body: input.body,\n navigateTarget: input.navigateTarget,\n pluginData: input.pluginData,\n createdAt: new Date().toISOString(),\n };\n await enqueue((state) => {\n state.entries[entryId] = entry as NotifierEntry;\n return { event: { type: \"published\", entry: entry as NotifierEntry } };\n });\n return { id: entryId };\n}\n\nexport async function clear(entryId: string): Promise<void> {\n await enqueue((state) => {\n const entry = state.entries[entryId];\n if (!entry) return null;\n state.entries = removeEntry(state, entryId);\n return {\n event: { type: \"cleared\", id: entryId },\n historyEntry: buildHistoryEntry(entry, \"cleared\"),\n };\n });\n}\n\nexport async function cancel(entryId: string): Promise<void> {\n await enqueue((state) => {\n const entry = state.entries[entryId];\n if (!entry) return null;\n state.entries = removeEntry(state, entryId);\n return {\n event: { type: \"cancelled\", id: entryId },\n historyEntry: buildHistoryEntry(entry, \"cancelled\"),\n };\n });\n}\n\n/** In-place update for an active entry. Only the fields present on\n * `patch` are rewritten; `id`, `pluginPkg`, `lifecycle`, and\n * `createdAt` stay fixed. Emits a single `\"updated\"` event with the\n * post-mutation entry — no history record is written because the\n * entry is still active, just with refreshed content.\n *\n * No-ops (no throw) when the id is unknown, the entry belongs to a\n * different plugin, or the merged shape would violate\n * `validatePublishInput`. The silent skip matches `clearForPlugin`'s\n * isolation semantics; validation failures are logged for diagnosis. */\nexport async function updateForPlugin<TPluginData = unknown>(\n pluginPkg: string,\n entryId: string,\n patch: {\n severity?: NotifierSeverity;\n title?: string;\n body?: string;\n navigateTarget?: string;\n pluginData?: TPluginData;\n },\n): Promise<void> {\n await enqueue((state) => {\n const entry = state.entries[entryId];\n if (!entry) return null;\n if (entry.pluginPkg !== pluginPkg) return null;\n const next: NotifierEntry = {\n ...entry,\n ...(patch.severity !== undefined ? { severity: patch.severity } : {}),\n ...(patch.title !== undefined ? { title: patch.title } : {}),\n ...(patch.body !== undefined ? { body: patch.body } : {}),\n ...(patch.navigateTarget !== undefined ? { navigateTarget: patch.navigateTarget } : {}),\n ...(patch.pluginData !== undefined ? { pluginData: patch.pluginData } : {}),\n };\n // Re-validate the merged shape so an update can't degrade the\n // entry below publish-time invariants.\n const validationError = validatePublishInput({\n pluginPkg: next.pluginPkg,\n severity: next.severity,\n title: next.title,\n body: next.body,\n lifecycle: next.lifecycle,\n navigateTarget: next.navigateTarget,\n pluginData: next.pluginData,\n });\n if (validationError) {\n logger().warn(\"update rejected by validation\", { entryId, pluginPkg, error: validationError });\n return null;\n }\n state.entries[entryId] = next;\n return { event: { type: \"updated\", entry: next } };\n });\n}\n\n/** Plugin-scoped point lookup. Returns the entry by id, but only if it\n * belongs to the caller's plugin; otherwise undefined. Cross-plugin\n * reads return undefined for isolation — same property as\n * `clearForPlugin` / `updateForPlugin`. */\nexport async function getForPlugin(pluginPkg: string, entryId: string): Promise<NotifierEntry | undefined> {\n const state = await loadActive(activeFilePath);\n const entry = state.entries[entryId];\n if (!entry) return undefined;\n if (entry.pluginPkg !== pluginPkg) return undefined;\n return entry;\n}\n\n/** Plugin-scoped clear. Same as `clear` but no-ops if the entry's\n * `pluginPkg` doesn't match the caller's, so a plugin can't dismiss\n * another plugin's notification by guessing or scraping its id. */\nexport async function clearForPlugin(pluginPkg: string, entryId: string): Promise<void> {\n await enqueue((state) => {\n const entry = state.entries[entryId];\n if (!entry) return null;\n if (entry.pluginPkg !== pluginPkg) return null;\n state.entries = removeEntry(state, entryId);\n return {\n event: { type: \"cleared\", id: entryId },\n historyEntry: buildHistoryEntry(entry, \"cleared\"),\n };\n });\n}\n\nexport async function get(entryId: string): Promise<NotifierEntry | undefined> {\n const state = await loadActive(activeFilePath);\n return state.entries[entryId];\n}\n\nexport async function listFor(pluginPkg: string): Promise<NotifierEntry[]> {\n const state = await loadActive(activeFilePath);\n return Object.values(state.entries).filter((entry) => entry.pluginPkg === pluginPkg);\n}\n\nexport async function listAll(): Promise<NotifierEntry[]> {\n const state = await loadActive(activeFilePath);\n return Object.values(state.entries);\n}\n\nexport async function listHistory(): Promise<NotifierHistoryEntry[]> {\n const state = await loadHistory(historyFilePath);\n return state.entries;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA0BA,IAAa,sBAAsB,CAAC,OAAO,QAAQ;;;;;;AAQnD,IAAa,sBAAsB;CAAC;CAAQ;CAAS;AAAQ;;;AA0E7D,IAAa,cAAc;;;AChG3B,SAAS,gBAAgB,KAAuB;CAC9C,OAAO,OAAO,QAAQ,YAAY,QAAQ,QAAS,IAA2B,SAAS;AACzF;;;;;;AAOA,eAAsB,WAAW,UAAyC;CACxE,IAAI;CACJ,IAAI;EACF,OAAO,MAAM,QAAA,SAAW,SAAS,UAAU,OAAO;CACpD,SAAS,KAAK;EACZ,IAAI,gBAAgB,GAAG,GAAG,OAAO,EAAE,SAAS,CAAC,EAAE;EAC/C,MAAM;CACR;CACA,MAAM,SAAkB,KAAK,MAAM,IAAI;CAOvC,IAAI,OAAO,WAAW,YAAY,WAAW,QAAQ,EAAE,aAAa,SAClE,MAAM,IAAI,MAAM,sCAAsC,UAAU;CAElE,MAAM,EAAE,YAAY;CACpB,IAA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
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
- key = keys[i];
11
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
- get: ((k) => from[k]).bind(null, key),
13
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
- });
15
- }
16
- return to;
17
- };
18
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
- value: mod,
20
- enumerable: true
21
- }) : target, mod));
22
- //#endregion
23
- Object.defineProperty(exports, "__toESM", {
24
- enumerable: true,
25
- get: function() {
26
- return __toESM;
27
- }
28
- });
@@ -1,48 +0,0 @@
1
- import { TaskExecutionState, TaskLogEntry, MISSED_RUN_POLICIES } from '@receptron/task-scheduler';
2
- import { ITaskManager, TaskDefinition, SchedulerLogger } from './task-manager.js';
3
- export interface SchedulerConfig {
4
- /** Absolute workspace root — state.json + logs hang off it. */
5
- workspaceRoot: string;
6
- /** Host atomic file writer (used with `uniqueTmp` for the state file). */
7
- writeFileAtomic: (filePath: string, content: string, opts: {
8
- uniqueTmp: boolean;
9
- }) => Promise<void>;
10
- /** Optional logger. */
11
- log?: SchedulerLogger;
12
- }
13
- /** Wire the adapter to a host. Call once at startup, before `initScheduler`. */
14
- export declare function configureScheduler(injected: SchedulerConfig): void;
15
- export interface SystemTaskDef {
16
- id: string;
17
- name: string;
18
- description: string;
19
- schedule: TaskDefinition["schedule"];
20
- missedRunPolicy: typeof MISSED_RUN_POLICIES.skip | typeof MISSED_RUN_POLICIES.runOnce | typeof MISSED_RUN_POLICIES.runAll;
21
- run: () => Promise<void>;
22
- }
23
- /**
24
- * Initialize the scheduler adapter. Call once at server startup AFTER the
25
- * task-manager is created but BEFORE `taskManager.start()`.
26
- */
27
- export declare function initScheduler(taskManager: ITaskManager, tasks: SystemTaskDef[]): Promise<void>;
28
- /** Apply a schedule override to a running system task. Updates the
29
- * in-memory task definition, the task-manager, and recalculates
30
- * nextScheduledAt in persisted state. */
31
- export declare function applyScheduleOverride(taskId: string, schedule: SystemTaskDef["schedule"]): Promise<boolean>;
32
- /** Query execution logs — used by API routes. */
33
- export declare function getSchedulerLogs(opts: {
34
- since?: string;
35
- taskId?: string;
36
- limit?: number;
37
- }): Promise<TaskLogEntry[]>;
38
- /** Get all task states — used by API routes. */
39
- export declare function getSchedulerTasks(): {
40
- id: string;
41
- name: string;
42
- description: string;
43
- schedule: TaskDefinition["schedule"];
44
- missedRunPolicy: string;
45
- state: TaskExecutionState;
46
- }[];
47
- /** Test-only: clear config + in-memory state. */
48
- export declare function resetSchedulerForTesting(): void;
@@ -1,352 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_rolldown_runtime = require("../rolldown-runtime-D6vf50IK.cjs");
3
- let node_path = require("node:path");
4
- node_path = require_rolldown_runtime.__toESM(node_path, 1);
5
- let node_fs = require("node:fs");
6
- let node_fs_promises = require("node:fs/promises");
7
- let _receptron_task_scheduler = require("@receptron/task-scheduler");
8
- //#region src/scheduler/task-manager.ts
9
- var ONE_SECOND_MS$1 = 1e3;
10
- var ONE_MINUTE_MS = 60 * ONE_SECOND_MS$1;
11
- var ONE_HOUR_MS = 60 * ONE_MINUTE_MS;
12
- var NOOP_LOG$1 = {
13
- info: () => {},
14
- warn: () => {},
15
- error: () => {}
16
- };
17
- function isDue(now, schedule, tickMs) {
18
- if (schedule.type === _receptron_task_scheduler.SCHEDULE_TYPES.interval) {
19
- const msSinceMidnight = now.getUTCHours() * ONE_HOUR_MS + now.getUTCMinutes() * ONE_MINUTE_MS + now.getUTCSeconds() * ONE_SECOND_MS$1;
20
- return Math.floor(msSinceMidnight / tickMs) * tickMs % schedule.intervalMs === 0;
21
- }
22
- if (schedule.type === _receptron_task_scheduler.SCHEDULE_TYPES.daily) {
23
- const [hours, minutes] = schedule.time.split(":").map(Number);
24
- const targetMs = hours * ONE_HOUR_MS + minutes * ONE_MINUTE_MS;
25
- const msSinceMidnight = now.getUTCHours() * ONE_HOUR_MS + now.getUTCMinutes() * ONE_MINUTE_MS + now.getUTCSeconds() * ONE_SECOND_MS$1;
26
- return Math.floor(msSinceMidnight / tickMs) * tickMs === targetMs;
27
- }
28
- return false;
29
- }
30
- function createTaskManager(options) {
31
- const tickMs = options?.tickMs ?? ONE_MINUTE_MS;
32
- const now = options?.now ?? (() => /* @__PURE__ */ new Date());
33
- const log = options?.log ?? NOOP_LOG$1;
34
- const registry = /* @__PURE__ */ new Map();
35
- let timer = null;
36
- function collectDueTasks(currentTime) {
37
- const independent = [];
38
- const dependent = [];
39
- for (const def of registry.values()) {
40
- if (def.enabled === false) continue;
41
- if (!isDue(currentTime, def.schedule, tickMs)) continue;
42
- if (def.dependsOn) dependent.push(def);
43
- else independent.push(def);
44
- }
45
- return {
46
- independent,
47
- dependent
48
- };
49
- }
50
- async function runAndTrack(def, currentTime, succeeded) {
51
- try {
52
- await def.run({
53
- taskId: def.id,
54
- now: currentTime
55
- });
56
- succeeded.add(def.id);
57
- } catch (err) {
58
- log.error("task failed", {
59
- id: def.id,
60
- error: String(err)
61
- });
62
- }
63
- }
64
- async function runDependentChain(dependent, currentTime, succeeded) {
65
- let remaining = [...dependent];
66
- let progress = true;
67
- while (remaining.length > 0 && progress) {
68
- progress = false;
69
- const next = [];
70
- for (const def of remaining) {
71
- const dep = def.dependsOn;
72
- if (!dep || !succeeded.has(dep)) {
73
- next.push(def);
74
- continue;
75
- }
76
- await runAndTrack(def, currentTime, succeeded);
77
- progress = true;
78
- }
79
- remaining = next;
80
- }
81
- }
82
- async function onTick() {
83
- const currentTime = now();
84
- const { independent, dependent } = collectDueTasks(currentTime);
85
- const succeeded = /* @__PURE__ */ new Set();
86
- await Promise.all(independent.map((def) => runAndTrack(def, currentTime, succeeded)));
87
- await runDependentChain(dependent, currentTime, succeeded);
88
- }
89
- return {
90
- async tick() {
91
- await onTick();
92
- },
93
- registerTask(def) {
94
- if (registry.has(def.id)) throw new Error(`[task-manager] Task "${def.id}" is already registered`);
95
- registry.set(def.id, def);
96
- log.info("registered", { id: def.id });
97
- },
98
- updateSchedule(taskId, schedule) {
99
- const def = registry.get(taskId);
100
- if (!def) return false;
101
- def.schedule = schedule;
102
- log.info("schedule updated", { id: taskId });
103
- return true;
104
- },
105
- removeTask(taskId) {
106
- if (registry.delete(taskId)) log.info("removed", { id: taskId });
107
- },
108
- start() {
109
- if (timer) return;
110
- timer = setInterval(onTick, tickMs);
111
- log.info("started", { tickMs });
112
- },
113
- stop() {
114
- if (timer) {
115
- clearInterval(timer);
116
- timer = null;
117
- log.info("stopped");
118
- }
119
- },
120
- listTasks() {
121
- return [...registry.values()].map((taskDef) => ({
122
- id: taskDef.id,
123
- description: taskDef.description,
124
- schedule: taskDef.schedule,
125
- dependsOn: taskDef.dependsOn
126
- }));
127
- }
128
- };
129
- }
130
- //#endregion
131
- //#region src/scheduler/adapter.ts
132
- var ONE_SECOND_MS = 1e3;
133
- var SCHEDULER_CONFIG_DIR = "config/scheduler";
134
- var SCHEDULER_DATA_DIR = "data/scheduler/logs";
135
- var NOOP_LOG = {
136
- info: () => {},
137
- warn: () => {},
138
- error: () => {}
139
- };
140
- var config = null;
141
- /** Wire the adapter to a host. Call once at startup, before `initScheduler`. */
142
- function configureScheduler(injected) {
143
- config = injected;
144
- }
145
- function requireConfig() {
146
- if (!config) throw new Error("scheduler: configureScheduler() not called");
147
- return config;
148
- }
149
- function logger() {
150
- return config?.log ?? NOOP_LOG;
151
- }
152
- function errorMessage(err) {
153
- return err instanceof Error ? err.message : String(err);
154
- }
155
- function stateFilePath() {
156
- return node_path.default.join(requireConfig().workspaceRoot, SCHEDULER_CONFIG_DIR, "state.json");
157
- }
158
- function logsDir() {
159
- return node_path.default.join(requireConfig().workspaceRoot, SCHEDULER_DATA_DIR);
160
- }
161
- function stateDeps() {
162
- return {
163
- readFile: (filePath) => (0, node_fs_promises.readFile)(filePath, "utf-8"),
164
- writeFileAtomic: (filePath, content) => requireConfig().writeFileAtomic(filePath, content, { uniqueTmp: true }),
165
- exists: node_fs.existsSync
166
- };
167
- }
168
- var logDeps = {
169
- appendFile: (filePath, content) => (0, node_fs_promises.appendFile)(filePath, content),
170
- readFile: (filePath) => (0, node_fs_promises.readFile)(filePath, "utf-8"),
171
- exists: node_fs.existsSync,
172
- ensureDir: (directoryPath) => (0, node_fs_promises.mkdir)(directoryPath, { recursive: true }).then(() => {})
173
- };
174
- var stateMap = /* @__PURE__ */ new Map();
175
- var systemTasks = [];
176
- var taskManagerRef = null;
177
- /**
178
- * Initialize the scheduler adapter. Call once at server startup AFTER the
179
- * task-manager is created but BEFORE `taskManager.start()`.
180
- */
181
- async function initScheduler(taskManager, tasks) {
182
- await (0, node_fs_promises.mkdir)(node_path.default.dirname(stateFilePath()), { recursive: true });
183
- await (0, node_fs_promises.mkdir)(logsDir(), { recursive: true });
184
- stateMap = await (0, _receptron_task_scheduler.loadState)(stateFilePath(), stateDeps());
185
- systemTasks.length = 0;
186
- systemTasks.push(...tasks);
187
- taskManagerRef = taskManager;
188
- const plan = (0, _receptron_task_scheduler.computeCatchUpPlan)(tasks.map((taskDef) => ({
189
- id: taskDef.id,
190
- name: taskDef.name,
191
- schedule: toCoreSchedule(taskDef.schedule),
192
- missedRunPolicy: taskDef.missedRunPolicy,
193
- enabled: true
194
- })), stateMap, Date.now());
195
- for (const skip of plan.skipped) {
196
- logger().info("catch-up skipped", {
197
- taskId: skip.taskId,
198
- windows: skip.windowCount
199
- });
200
- await safeUpdateState(skip.taskId, { lastRunAt: skip.lastWindow });
201
- }
202
- if (plan.runs.length > 0) {
203
- logger().info("catch-up enqueued", { runs: plan.runs.length });
204
- for (const run of plan.runs) {
205
- const task = tasks.find((taskDef) => taskDef.id === run.taskId);
206
- if (!task) continue;
207
- await executeAndLog(task, run.context.scheduledFor, _receptron_task_scheduler.TASK_TRIGGERS.catchUp);
208
- }
209
- }
210
- for (const task of tasks) taskManager.registerTask({
211
- id: task.id,
212
- description: task.description,
213
- schedule: task.schedule,
214
- run: async () => {
215
- await executeAndLog(task, computeCurrentWindow(task), _receptron_task_scheduler.TASK_TRIGGERS.scheduled);
216
- }
217
- });
218
- logger().info("initialized", {
219
- tasks: tasks.map((taskDef) => taskDef.id),
220
- stateEntries: stateMap.size
221
- });
222
- }
223
- /** Apply a schedule override to a running system task. Updates the
224
- * in-memory task definition, the task-manager, and recalculates
225
- * nextScheduledAt in persisted state. */
226
- async function applyScheduleOverride(taskId, schedule) {
227
- const task = systemTasks.find((taskDef) => taskDef.id === taskId);
228
- if (!task || !taskManagerRef) return false;
229
- if (!taskManagerRef.updateSchedule(taskId, schedule)) return false;
230
- task.schedule = schedule;
231
- await safeUpdateState(taskId, { nextScheduledAt: computeNextScheduled(task) });
232
- return true;
233
- }
234
- /** Query execution logs — used by API routes. */
235
- async function getSchedulerLogs(opts) {
236
- return (0, _receptron_task_scheduler.queryLog)(logsDir(), opts, logDeps);
237
- }
238
- /** Get all task states — used by API routes. */
239
- function getSchedulerTasks() {
240
- return systemTasks.map((taskDef) => ({
241
- id: taskDef.id,
242
- name: taskDef.name,
243
- description: taskDef.description,
244
- schedule: taskDef.schedule,
245
- missedRunPolicy: taskDef.missedRunPolicy,
246
- state: stateMap.get(taskDef.id) ?? (0, _receptron_task_scheduler.emptyState)(taskDef.id)
247
- }));
248
- }
249
- /** Test-only: clear config + in-memory state. */
250
- function resetSchedulerForTesting() {
251
- config = null;
252
- stateMap = /* @__PURE__ */ new Map();
253
- systemTasks.length = 0;
254
- taskManagerRef = null;
255
- }
256
- async function executeAndLog(task, scheduledFor, trigger) {
257
- const startedAt = (/* @__PURE__ */ new Date()).toISOString();
258
- const startMs = Date.now();
259
- let errMsg = null;
260
- try {
261
- await task.run();
262
- } catch (err) {
263
- errMsg = errorMessage(err);
264
- logger().error("task failed", {
265
- taskId: task.id,
266
- error: errMsg
267
- });
268
- }
269
- await safePersist(task, scheduledFor, startedAt, Date.now() - startMs, trigger, errMsg);
270
- }
271
- /** Best-effort persistence — state and log are independent. A failure in
272
- * one does not block the other, and neither propagates upward. */
273
- async function safePersist(task, scheduledFor, startedAt, durationMs, trigger, errMsg) {
274
- const isSuccess = errMsg === null;
275
- const currentState = stateMap.get(task.id);
276
- try {
277
- await (0, _receptron_task_scheduler.updateAndSave)(stateFilePath(), stateMap, task.id, {
278
- lastRunAt: scheduledFor,
279
- lastRunResult: isSuccess ? _receptron_task_scheduler.TASK_RESULTS.success : _receptron_task_scheduler.TASK_RESULTS.error,
280
- lastRunDurationMs: durationMs,
281
- lastErrorMessage: errMsg,
282
- consecutiveFailures: isSuccess ? 0 : (currentState?.consecutiveFailures ?? 0) + 1,
283
- totalRuns: (currentState?.totalRuns ?? 0) + 1,
284
- nextScheduledAt: computeNextScheduled(task)
285
- }, stateDeps());
286
- } catch (err) {
287
- logger().warn("state persistence failed", {
288
- taskId: task.id,
289
- error: String(err)
290
- });
291
- }
292
- try {
293
- await (0, _receptron_task_scheduler.appendLogEntry)(logsDir(), {
294
- taskId: task.id,
295
- taskName: task.name,
296
- scheduledFor,
297
- startedAt,
298
- completedAt: (/* @__PURE__ */ new Date()).toISOString(),
299
- result: isSuccess ? _receptron_task_scheduler.TASK_RESULTS.success : _receptron_task_scheduler.TASK_RESULTS.error,
300
- durationMs,
301
- trigger,
302
- ...errMsg !== null && { errorMessage: errMsg }
303
- }, logDeps);
304
- } catch (err) {
305
- logger().warn("log persistence failed", {
306
- taskId: task.id,
307
- error: String(err)
308
- });
309
- }
310
- }
311
- /** Safe state update — swallows errors. */
312
- async function safeUpdateState(taskId, patch) {
313
- try {
314
- await (0, _receptron_task_scheduler.updateAndSave)(stateFilePath(), stateMap, taskId, patch, stateDeps());
315
- } catch (err) {
316
- logger().warn("state update failed", {
317
- taskId,
318
- error: String(err)
319
- });
320
- }
321
- }
322
- /** Compute the window boundary that the current tick belongs to. For
323
- * scheduled runs, this is the epoch-aligned window — not the wall-clock
324
- * time of execution. This keeps lastRunAt consistent with catch-up's
325
- * window-based accounting. */
326
- function computeCurrentWindow(task) {
327
- const coreSchedule = toCoreSchedule(task.schedule);
328
- const nowMs = Date.now();
329
- const windowMs = (0, _receptron_task_scheduler.nextWindowAfter)(coreSchedule, nowMs - (coreSchedule.type === _receptron_task_scheduler.SCHEDULE_TYPES.interval ? coreSchedule.intervalSec * ONE_SECOND_MS : 0));
330
- return windowMs !== null && windowMs <= nowMs ? new Date(windowMs).toISOString() : new Date(nowMs).toISOString();
331
- }
332
- function computeNextScheduled(task) {
333
- const next = (0, _receptron_task_scheduler.nextWindowAfter)(toCoreSchedule(task.schedule), Date.now() + 1);
334
- return next !== null ? new Date(next).toISOString() : null;
335
- }
336
- function toCoreSchedule(schedule) {
337
- if (schedule.type === _receptron_task_scheduler.SCHEDULE_TYPES.interval) return {
338
- type: _receptron_task_scheduler.SCHEDULE_TYPES.interval,
339
- intervalSec: Math.round(schedule.intervalMs / ONE_SECOND_MS)
340
- };
341
- return schedule;
342
- }
343
- //#endregion
344
- exports.applyScheduleOverride = applyScheduleOverride;
345
- exports.configureScheduler = configureScheduler;
346
- exports.createTaskManager = createTaskManager;
347
- exports.getSchedulerLogs = getSchedulerLogs;
348
- exports.getSchedulerTasks = getSchedulerTasks;
349
- exports.initScheduler = initScheduler;
350
- exports.resetSchedulerForTesting = resetSchedulerForTesting;
351
-
352
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","names":[],"sources":["../../src/scheduler/task-manager.ts","../../src/scheduler/adapter.ts"],"sourcesContent":["// Generic dependency-ordered cron tick engine. Host-agnostic: the only\n// host coupling (a logger) is injected via options. Schedules are either\n// fixed intervals or a daily UTC time; tasks may declare a `dependsOn`\n// edge so an ordering like \"news fetch → journal → memory extraction\"\n// runs in sequence within one tick.\n\nimport { SCHEDULE_TYPES } from \"@receptron/task-scheduler\";\n\nconst ONE_SECOND_MS = 1000;\nconst ONE_MINUTE_MS = 60 * ONE_SECOND_MS;\nconst ONE_HOUR_MS = 60 * ONE_MINUTE_MS;\n\n/** Minimal logger the engine logs through. Absent one, runs silent. */\nexport interface SchedulerLogger {\n info: (message: string, data?: Record<string, unknown>) => void;\n warn: (message: string, data?: Record<string, unknown>) => void;\n error: (message: string, data?: Record<string, unknown>) => void;\n}\n\nconst NOOP_LOG: SchedulerLogger = { info: () => {}, warn: () => {}, error: () => {} };\n\nexport type TaskSchedule = { type: typeof SCHEDULE_TYPES.interval; intervalMs: number } | { type: typeof SCHEDULE_TYPES.daily; time: string }; // time: \"HH:MM\" in UTC\n\nexport interface TaskRunContext {\n taskId: string;\n now: Date;\n}\n\nexport interface TaskDefinition {\n id: string;\n description?: string;\n schedule: TaskSchedule;\n enabled?: boolean; // default: true\n /** If set, this task only fires after the named task has completed\n * successfully in the current tick cycle. Enforces ordering like\n * \"news fetch → journal → memory extraction\". */\n dependsOn?: string;\n run: (ctx: TaskRunContext) => Promise<void>;\n}\n\nexport interface ITaskManager {\n registerTask: (def: TaskDefinition) => void;\n removeTask: (taskId: string) => void;\n /** Update the schedule of an existing task. Returns false if not found. */\n updateSchedule: (taskId: string, schedule: TaskSchedule) => boolean;\n start: () => void;\n stop: () => void;\n /** Run one tick manually (for testing). */\n tick: () => Promise<void>;\n listTasks: () => {\n id: string;\n description?: string;\n schedule: TaskSchedule;\n dependsOn?: string;\n }[];\n}\n\nexport interface TaskManagerOptions {\n tickMs?: number; // default: ONE_MINUTE_MS\n now?: () => Date; // default: () => new Date()\n log?: SchedulerLogger; // default: noop\n}\n\nfunction isDue(now: Date, schedule: TaskSchedule, tickMs: number): boolean {\n if (schedule.type === SCHEDULE_TYPES.interval) {\n const msSinceMidnight = now.getUTCHours() * ONE_HOUR_MS + now.getUTCMinutes() * ONE_MINUTE_MS + now.getUTCSeconds() * ONE_SECOND_MS;\n // Round down to tick boundary, then check if it aligns with the interval\n const rounded = Math.floor(msSinceMidnight / tickMs) * tickMs;\n return rounded % schedule.intervalMs === 0;\n }\n\n if (schedule.type === SCHEDULE_TYPES.daily) {\n const [hours, minutes] = schedule.time.split(\":\").map(Number);\n const targetMs = hours * ONE_HOUR_MS + minutes * ONE_MINUTE_MS;\n const msSinceMidnight = now.getUTCHours() * ONE_HOUR_MS + now.getUTCMinutes() * ONE_MINUTE_MS + now.getUTCSeconds() * ONE_SECOND_MS;\n const rounded = Math.floor(msSinceMidnight / tickMs) * tickMs;\n return rounded === targetMs;\n }\n\n return false;\n}\n\nexport function createTaskManager(options?: TaskManagerOptions): ITaskManager {\n const tickMs = options?.tickMs ?? ONE_MINUTE_MS;\n const now = options?.now ?? (() => new Date());\n const log = options?.log ?? NOOP_LOG;\n const registry = new Map<string, TaskDefinition>();\n let timer: ReturnType<typeof setInterval> | null = null;\n\n function collectDueTasks(currentTime: Date): {\n independent: TaskDefinition[];\n dependent: TaskDefinition[];\n } {\n const independent: TaskDefinition[] = [];\n const dependent: TaskDefinition[] = [];\n for (const def of registry.values()) {\n if (def.enabled === false) continue;\n if (!isDue(currentTime, def.schedule, tickMs)) continue;\n if (def.dependsOn) {\n dependent.push(def);\n } else {\n independent.push(def);\n }\n }\n return { independent, dependent };\n }\n\n async function runAndTrack(def: TaskDefinition, currentTime: Date, succeeded: Set<string>): Promise<void> {\n try {\n await def.run({ taskId: def.id, now: currentTime });\n succeeded.add(def.id);\n } catch (err) {\n log.error(\"task failed\", {\n id: def.id,\n error: String(err),\n });\n }\n }\n\n async function runDependentChain(dependent: TaskDefinition[], currentTime: Date, succeeded: Set<string>): Promise<void> {\n let remaining = [...dependent];\n let progress = true;\n while (remaining.length > 0 && progress) {\n progress = false;\n const next: TaskDefinition[] = [];\n for (const def of remaining) {\n const dep = def.dependsOn;\n if (!dep || !succeeded.has(dep)) {\n next.push(def);\n continue;\n }\n await runAndTrack(def, currentTime, succeeded);\n progress = true;\n }\n remaining = next;\n }\n }\n\n async function onTick(): Promise<void> {\n const currentTime = now();\n const { independent, dependent } = collectDueTasks(currentTime);\n\n // Per-invocation set — success does not leak across tick() calls.\n const succeeded = new Set<string>();\n\n await Promise.all(independent.map((def) => runAndTrack(def, currentTime, succeeded)));\n\n await runDependentChain(dependent, currentTime, succeeded);\n }\n\n return {\n async tick() {\n await onTick();\n },\n\n registerTask(def: TaskDefinition) {\n if (registry.has(def.id)) {\n throw new Error(`[task-manager] Task \"${def.id}\" is already registered`);\n }\n registry.set(def.id, def);\n log.info(\"registered\", { id: def.id });\n },\n\n updateSchedule(taskId: string, schedule: TaskSchedule): boolean {\n const def = registry.get(taskId);\n if (!def) return false;\n def.schedule = schedule;\n log.info(\"schedule updated\", { id: taskId });\n return true;\n },\n\n removeTask(taskId: string) {\n if (registry.delete(taskId)) {\n log.info(\"removed\", { id: taskId });\n }\n },\n\n start() {\n if (timer) return;\n timer = setInterval(onTick, tickMs);\n log.info(\"started\", { tickMs });\n },\n\n stop() {\n if (timer) {\n clearInterval(timer);\n timer = null;\n log.info(\"stopped\");\n }\n },\n\n listTasks() {\n return [...registry.values()].map((taskDef) => ({\n id: taskDef.id,\n description: taskDef.description,\n schedule: taskDef.schedule,\n dependsOn: taskDef.dependsOn,\n }));\n },\n };\n}\n","// Adapter that wires the pure scheduler library (@receptron/task-scheduler)\n// to a host's task-manager + workspace. Registers system tasks, runs\n// catch-up on startup, and persists execution state + logs.\n//\n// Host-agnostic: the workspace root, the atomic file writer, and the\n// logger are injected via `configureScheduler`. The host supplies its OWN\n// system tasks (journal / feeds / user-cron in MulmoClaude) to\n// `initScheduler` — the package owns no task definitions. Deliberately\n// thin: all complex scheduling logic lives in @receptron/task-scheduler.\n\nimport { existsSync } from \"node:fs\";\nimport { readFile, appendFile, mkdir } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport {\n type TaskSchedule,\n type TaskExecutionState,\n type TaskLogEntry,\n type CatchUpTask,\n type TaskTrigger,\n emptyState,\n computeCatchUpPlan,\n nextWindowAfter,\n loadState,\n updateAndSave,\n appendLogEntry,\n queryLog,\n SCHEDULE_TYPES,\n TASK_RESULTS,\n TASK_TRIGGERS,\n type MISSED_RUN_POLICIES,\n type StateMap,\n type StateDeps,\n type LogDeps,\n} from \"@receptron/task-scheduler\";\nimport type { ITaskManager, TaskDefinition, SchedulerLogger } from \"./task-manager.js\";\n\nconst ONE_SECOND_MS = 1000;\nconst SCHEDULER_CONFIG_DIR = \"config/scheduler\";\nconst SCHEDULER_DATA_DIR = \"data/scheduler/logs\";\n\n// ── Host injection ────────────────────────────────────────────────\n\nexport interface SchedulerConfig {\n /** Absolute workspace root — state.json + logs hang off it. */\n workspaceRoot: string;\n /** Host atomic file writer (used with `uniqueTmp` for the state file). */\n writeFileAtomic: (filePath: string, content: string, opts: { uniqueTmp: boolean }) => Promise<void>;\n /** Optional logger. */\n log?: SchedulerLogger;\n}\n\nconst NOOP_LOG: SchedulerLogger = { info: () => {}, warn: () => {}, error: () => {} };\n\nlet config: SchedulerConfig | null = null;\n\n/** Wire the adapter to a host. Call once at startup, before `initScheduler`. */\nexport function configureScheduler(injected: SchedulerConfig): void {\n config = injected;\n}\n\nfunction requireConfig(): SchedulerConfig {\n if (!config) throw new Error(\"scheduler: configureScheduler() not called\");\n return config;\n}\n\nfunction logger(): SchedulerLogger {\n return config?.log ?? NOOP_LOG;\n}\n\nfunction errorMessage(err: unknown): string {\n return err instanceof Error ? err.message : String(err);\n}\n\n// ── Paths ─────────────────────────────────────────────────────────\n\nfunction stateFilePath(): string {\n return path.join(requireConfig().workspaceRoot, SCHEDULER_CONFIG_DIR, \"state.json\");\n}\n\nfunction logsDir(): string {\n return path.join(requireConfig().workspaceRoot, SCHEDULER_DATA_DIR);\n}\n\n// ── I/O deps (real filesystem) ────────────────────────────────────\n\nfunction stateDeps(): StateDeps {\n return {\n readFile: (filePath: string) => readFile(filePath, \"utf-8\"),\n writeFileAtomic: (filePath: string, content: string) => requireConfig().writeFileAtomic(filePath, content, { uniqueTmp: true }),\n exists: existsSync,\n };\n}\n\nconst logDeps: LogDeps = {\n appendFile: (filePath: string, content: string) => appendFile(filePath, content),\n readFile: (filePath: string) => readFile(filePath, \"utf-8\"),\n exists: existsSync,\n ensureDir: (directoryPath: string) => mkdir(directoryPath, { recursive: true }).then(() => {}),\n};\n\n// ── System task registry ──────────────────────────────────────────\n\nexport interface SystemTaskDef {\n id: string;\n name: string;\n description: string;\n schedule: TaskDefinition[\"schedule\"];\n missedRunPolicy: typeof MISSED_RUN_POLICIES.skip | typeof MISSED_RUN_POLICIES.runOnce | typeof MISSED_RUN_POLICIES.runAll;\n run: () => Promise<void>;\n}\n\n// ── Public API ────────────────────────────────────────────────────\n\nlet stateMap: StateMap = new Map();\nconst systemTasks: SystemTaskDef[] = [];\nlet taskManagerRef: ITaskManager | null = null;\n\n/**\n * Initialize the scheduler adapter. Call once at server startup AFTER the\n * task-manager is created but BEFORE `taskManager.start()`.\n */\nexport async function initScheduler(taskManager: ITaskManager, tasks: SystemTaskDef[]): Promise<void> {\n await mkdir(path.dirname(stateFilePath()), { recursive: true });\n await mkdir(logsDir(), { recursive: true });\n\n stateMap = await loadState(stateFilePath(), stateDeps());\n systemTasks.length = 0;\n systemTasks.push(...tasks);\n taskManagerRef = taskManager;\n\n // Run catch-up\n const catchUpTasks: CatchUpTask[] = tasks.map((taskDef) => ({\n id: taskDef.id,\n name: taskDef.name,\n schedule: toCoreSchedule(taskDef.schedule),\n missedRunPolicy: taskDef.missedRunPolicy,\n enabled: true,\n }));\n const plan = computeCatchUpPlan(catchUpTasks, stateMap, Date.now());\n\n for (const skip of plan.skipped) {\n logger().info(\"catch-up skipped\", { taskId: skip.taskId, windows: skip.windowCount });\n await safeUpdateState(skip.taskId, { lastRunAt: skip.lastWindow });\n }\n\n if (plan.runs.length > 0) {\n logger().info(\"catch-up enqueued\", { runs: plan.runs.length });\n for (const run of plan.runs) {\n const task = tasks.find((taskDef) => taskDef.id === run.taskId);\n if (!task) continue;\n await executeAndLog(task, run.context.scheduledFor, TASK_TRIGGERS.catchUp);\n }\n }\n\n // Register with task-manager for ongoing ticks\n for (const task of tasks) {\n taskManager.registerTask({\n id: task.id,\n description: task.description,\n schedule: task.schedule,\n run: async () => {\n const windowIso = computeCurrentWindow(task);\n await executeAndLog(task, windowIso, TASK_TRIGGERS.scheduled);\n },\n });\n }\n\n logger().info(\"initialized\", { tasks: tasks.map((taskDef) => taskDef.id), stateEntries: stateMap.size });\n}\n\n/** Apply a schedule override to a running system task. Updates the\n * in-memory task definition, the task-manager, and recalculates\n * nextScheduledAt in persisted state. */\nexport async function applyScheduleOverride(taskId: string, schedule: SystemTaskDef[\"schedule\"]): Promise<boolean> {\n const task = systemTasks.find((taskDef) => taskDef.id === taskId);\n if (!task || !taskManagerRef) return false;\n if (!taskManagerRef.updateSchedule(taskId, schedule)) return false;\n task.schedule = schedule;\n\n // Recalculate next window so the UI reflects the new schedule\n const nextScheduledAt = computeNextScheduled(task);\n await safeUpdateState(taskId, { nextScheduledAt });\n\n return true;\n}\n\n/** Query execution logs — used by API routes. */\nexport async function getSchedulerLogs(opts: { since?: string; taskId?: string; limit?: number }): Promise<TaskLogEntry[]> {\n return queryLog(logsDir(), opts, logDeps);\n}\n\n/** Get all task states — used by API routes. */\nexport function getSchedulerTasks(): {\n id: string;\n name: string;\n description: string;\n schedule: TaskDefinition[\"schedule\"];\n missedRunPolicy: string;\n state: TaskExecutionState;\n}[] {\n return systemTasks.map((taskDef) => ({\n id: taskDef.id,\n name: taskDef.name,\n description: taskDef.description,\n schedule: taskDef.schedule,\n missedRunPolicy: taskDef.missedRunPolicy,\n state: stateMap.get(taskDef.id) ?? emptyState(taskDef.id),\n }));\n}\n\n/** Test-only: clear config + in-memory state. */\nexport function resetSchedulerForTesting(): void {\n config = null;\n stateMap = new Map();\n systemTasks.length = 0;\n taskManagerRef = null;\n}\n\n// ── Internal ──────────────────────────────────────────────────────\n\nasync function executeAndLog(task: SystemTaskDef, scheduledFor: string, trigger: TaskTrigger): Promise<void> {\n const startedAt = new Date().toISOString();\n const startMs = Date.now();\n let errMsg: string | null = null;\n try {\n await task.run();\n } catch (err) {\n errMsg = errorMessage(err);\n logger().error(\"task failed\", { taskId: task.id, error: errMsg });\n }\n const durationMs = Date.now() - startMs;\n // Persistence is best-effort — never let disk failures propagate to the\n // tick loop or abort startup catch-up.\n await safePersist(task, scheduledFor, startedAt, durationMs, trigger, errMsg);\n}\n\n/** Best-effort persistence — state and log are independent. A failure in\n * one does not block the other, and neither propagates upward. */\nasync function safePersist(\n task: SystemTaskDef,\n scheduledFor: string,\n startedAt: string,\n durationMs: number,\n trigger: TaskTrigger,\n errMsg: string | null,\n): Promise<void> {\n const isSuccess = errMsg === null;\n const currentState = stateMap.get(task.id);\n try {\n await updateAndSave(\n stateFilePath(),\n stateMap,\n task.id,\n {\n lastRunAt: scheduledFor,\n lastRunResult: isSuccess ? TASK_RESULTS.success : TASK_RESULTS.error,\n lastRunDurationMs: durationMs,\n lastErrorMessage: errMsg,\n consecutiveFailures: isSuccess ? 0 : (currentState?.consecutiveFailures ?? 0) + 1,\n totalRuns: (currentState?.totalRuns ?? 0) + 1,\n nextScheduledAt: computeNextScheduled(task),\n },\n stateDeps(),\n );\n } catch (err) {\n logger().warn(\"state persistence failed\", { taskId: task.id, error: String(err) });\n }\n try {\n await appendLogEntry(\n logsDir(),\n {\n taskId: task.id,\n taskName: task.name,\n scheduledFor,\n startedAt,\n completedAt: new Date().toISOString(),\n result: isSuccess ? TASK_RESULTS.success : TASK_RESULTS.error,\n durationMs,\n trigger,\n ...(errMsg !== null && { errorMessage: errMsg }),\n },\n logDeps,\n );\n } catch (err) {\n logger().warn(\"log persistence failed\", { taskId: task.id, error: String(err) });\n }\n}\n\n/** Safe state update — swallows errors. */\nasync function safeUpdateState(taskId: string, patch: Partial<TaskExecutionState>): Promise<void> {\n try {\n await updateAndSave(stateFilePath(), stateMap, taskId, patch, stateDeps());\n } catch (err) {\n logger().warn(\"state update failed\", { taskId, error: String(err) });\n }\n}\n\n/** Compute the window boundary that the current tick belongs to. For\n * scheduled runs, this is the epoch-aligned window — not the wall-clock\n * time of execution. This keeps lastRunAt consistent with catch-up's\n * window-based accounting. */\nfunction computeCurrentWindow(task: SystemTaskDef): string {\n const coreSchedule = toCoreSchedule(task.schedule);\n // The window that just fired is the latest one at or before now.\n const nowMs = Date.now();\n const windowMs = nextWindowAfter(coreSchedule, nowMs - (coreSchedule.type === SCHEDULE_TYPES.interval ? coreSchedule.intervalSec * ONE_SECOND_MS : 0));\n return windowMs !== null && windowMs <= nowMs ? new Date(windowMs).toISOString() : new Date(nowMs).toISOString();\n}\n\nfunction computeNextScheduled(task: SystemTaskDef): string | null {\n const coreSchedule = toCoreSchedule(task.schedule);\n const next = nextWindowAfter(coreSchedule, Date.now() + 1);\n return next !== null ? new Date(next).toISOString() : null;\n}\n\nfunction toCoreSchedule(schedule: TaskDefinition[\"schedule\"]): TaskSchedule {\n if (schedule.type === SCHEDULE_TYPES.interval) {\n return {\n type: SCHEDULE_TYPES.interval,\n intervalSec: Math.round(schedule.intervalMs / ONE_SECOND_MS),\n };\n }\n return schedule;\n}\n"],"mappings":";;;;;;;;AAQA,IAAM,kBAAgB;AACtB,IAAM,gBAAgB,KAAK;AAC3B,IAAM,cAAc,KAAK;AASzB,IAAM,aAA4B;CAAE,YAAY,CAAC;CAAG,YAAY,CAAC;CAAG,aAAa,CAAC;AAAE;AA4CpF,SAAS,MAAM,KAAW,UAAwB,QAAyB;CACzE,IAAI,SAAS,SAAS,0BAAA,eAAe,UAAU;EAC7C,MAAM,kBAAkB,IAAI,YAAY,IAAI,cAAc,IAAI,cAAc,IAAI,gBAAgB,IAAI,cAAc,IAAI;EAGtH,OADgB,KAAK,MAAM,kBAAkB,MAAM,IAAI,SACtC,SAAS,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SAAS,KAAK;EACZ,OAAO,CAAC,CAAC,KAAK,uBAAuB;GAAE;GAAQ,OAAO,OAAO,GAAG;EAAE,CAAC;CACrE;AACF;;;;;AAMA,SAAS,qBAAqB,MAA6B;CACzD,MAAM,eAAe,eAAe,KAAK,QAAQ;CAEjD,MAAM,QAAQ,KAAK,IAAI;CACvB,MAAM,YAAA,GAAA,0BAAA,gBAAA,CAA2B,cAAc,SAAS,aAAa,SAAS,0BAAA,eAAe,WAAW,aAAa,cAAc,gBAAgB,EAAE;CACrJ,OAAO,aAAa,QAAQ,YAAY,QAAQ,IAAI,KAAK,QAAQ,CAAC,CAAC,YAAY,IAAI,IAAI,KAAK,KAAK,CAAC,CAAC,YAAY;AACjH;AAEA,SAAS,qBAAqB,MAAoC;CAEhE,MAAM,QAAA,GAAA,0BAAA,gBAAA,CADe,eAAe,KAAK,QACZ,GAAc,KAAK,IAAI,IAAI,CAAC;CACzD,OAAO,SAAS,OAAO,IAAI,KAAK,IAAI,CAAC,CAAC,YAAY,IAAI;AACxD;AAEA,SAAS,eAAe,UAAoD;CAC1E,IAAI,SAAS,SAAS,0BAAA,eAAe,UACnC,OAAO;EACL,MAAM,0BAAA,eAAe;EACrB,aAAa,KAAK,MAAM,SAAS,aAAa,aAAa;CAC7D;CAEF,OAAO;AACT"}
@@ -1,2 +0,0 @@
1
- export { createTaskManager, type ITaskManager, type TaskDefinition, type TaskSchedule, type TaskRunContext, type TaskManagerOptions, type SchedulerLogger, } from './task-manager.js';
2
- export { configureScheduler, initScheduler, applyScheduleOverride, getSchedulerLogs, getSchedulerTasks, resetSchedulerForTesting, type SchedulerConfig, type SystemTaskDef, } from './adapter.js';
@@ -1,51 +0,0 @@
1
- import { SCHEDULE_TYPES } from '@receptron/task-scheduler';
2
- /** Minimal logger the engine logs through. Absent one, runs silent. */
3
- export interface SchedulerLogger {
4
- info: (message: string, data?: Record<string, unknown>) => void;
5
- warn: (message: string, data?: Record<string, unknown>) => void;
6
- error: (message: string, data?: Record<string, unknown>) => void;
7
- }
8
- export type TaskSchedule = {
9
- type: typeof SCHEDULE_TYPES.interval;
10
- intervalMs: number;
11
- } | {
12
- type: typeof SCHEDULE_TYPES.daily;
13
- time: string;
14
- };
15
- export interface TaskRunContext {
16
- taskId: string;
17
- now: Date;
18
- }
19
- export interface TaskDefinition {
20
- id: string;
21
- description?: string;
22
- schedule: TaskSchedule;
23
- enabled?: boolean;
24
- /** If set, this task only fires after the named task has completed
25
- * successfully in the current tick cycle. Enforces ordering like
26
- * "news fetch → journal → memory extraction". */
27
- dependsOn?: string;
28
- run: (ctx: TaskRunContext) => Promise<void>;
29
- }
30
- export interface ITaskManager {
31
- registerTask: (def: TaskDefinition) => void;
32
- removeTask: (taskId: string) => void;
33
- /** Update the schedule of an existing task. Returns false if not found. */
34
- updateSchedule: (taskId: string, schedule: TaskSchedule) => boolean;
35
- start: () => void;
36
- stop: () => void;
37
- /** Run one tick manually (for testing). */
38
- tick: () => Promise<void>;
39
- listTasks: () => {
40
- id: string;
41
- description?: string;
42
- schedule: TaskSchedule;
43
- dependsOn?: string;
44
- }[];
45
- }
46
- export interface TaskManagerOptions {
47
- tickMs?: number;
48
- now?: () => Date;
49
- log?: SchedulerLogger;
50
- }
51
- export declare function createTaskManager(options?: TaskManagerOptions): ITaskManager;