@mono-agent/cron-adapter 0.13.0 → 0.14.0

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 (2) hide show
  1. package/README.md +114 -2
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,8 +1,18 @@
1
1
  # @mono-agent/cron-adapter
2
2
 
3
+ Schedule recurring agent work from host config, Markdown job files, or a custom
4
+ programmatic host without moving runtime or delivery ownership into the adapter.
5
+
3
6
  ## Category
4
7
 
8
+ <!-- package-metadata:start -->
9
+ <!-- Generated by scripts/generate-package-docs.mjs. Do not edit by hand. -->
10
+
5
11
  Category: `communication`
12
+ Tier: `core`
13
+ Catalog responsibility: Invokes agent responders from cron schedules with configurable skip, queue, or replace overlap policies.
14
+
15
+ <!-- package-metadata:end -->
6
16
 
7
17
  ## Responsibility
8
18
 
@@ -10,12 +20,58 @@ Cron-based scheduled invocation adapter for agent hosts. It parses configured cr
10
20
 
11
21
  ## Install / Usage
12
22
 
23
+ ### Config-first host
24
+
25
+ `@mono-agent/agent-app` already depends on this package. A normal agent folder
26
+ does not install the adapter separately; declare jobs in `mono-agent.config.json`
27
+ and let the host load and start them:
28
+
29
+ ```json
30
+ {
31
+ "cron": {
32
+ "jobs": [
33
+ {
34
+ "id": "daily-check",
35
+ "enabled": true,
36
+ "expression": "0 9 * * *",
37
+ "timezone": "UTC",
38
+ "prompt": "Run the daily check.",
39
+ "conversationId": "cron:daily-check"
40
+ }
41
+ ]
42
+ }
43
+ }
44
+ ```
45
+
13
46
  ```bash
14
- pnpm --filter @mono-agent/cron-adapter run build
47
+ mono-agent validate
48
+ mono-agent start --foreground
15
49
  ```
16
50
 
51
+ The config-first host pins every configured job to `overlap: "skip"`: a tick
52
+ that overlaps an active run of the same job is skipped. There is no cron config
53
+ field for queueing or replacing active runs.
54
+
55
+ ### Programmatic use
56
+
57
+ Install the adapter directly only when building a custom host:
58
+
59
+ ```bash
60
+ pnpm add @mono-agent/cron-adapter
61
+ ```
62
+
63
+ <!-- doc-test:typescript -->
17
64
  ```ts
18
- import { startCronAdapter } from "@mono-agent/cron-adapter";
65
+ import {
66
+ startCronAdapter,
67
+ type CronAdapterOptions,
68
+ } from "@mono-agent/cron-adapter";
69
+
70
+ const responder: CronAdapterOptions["responder"] = {
71
+ async respond(request) {
72
+ return { text: `Scheduled request received: ${request.text}` };
73
+ },
74
+ };
19
75
 
20
76
  const cron = startCronAdapter({
21
77
  responder,
@@ -29,6 +85,8 @@ const cron = startCronAdapter({
29
85
  },
30
86
  ],
31
87
  });
88
+
89
+ process.once("SIGINT", () => cron.stop());
32
90
  ```
33
91
 
34
92
  Only future ticks after startup are scheduled. Direct programmatic `startCronAdapter` callers can choose `overlap: "skip" | "queue" | "replace"` (default `"skip"`). In queue mode, `maxQueueDepth` is a soft overflow threshold: the default `overflow: "preserve"` warns but keeps every firing and can grow past it. Select `overflow: "coalesce"` or `"drop-oldest"` to bound pending memory.
@@ -70,8 +128,53 @@ Summarize yesterday across my channels and post a short digest.
70
128
  - The folder is resolved against the host working directory from `cron.dir` / `MONO_AGENT_CRON_DIR` (default `cron/`). A missing folder is not an error.
71
129
  - Folder jobs are merged with config jobs; a duplicate `id` across sources is a hard error.
72
130
 
131
+ The single-job environment form uses the fixed id `default`; it supports
132
+ `MONO_AGENT_CRON_ENABLED`, `MONO_AGENT_CRON_EXPRESSION`,
133
+ `MONO_AGENT_CRON_TIMEZONE`, `MONO_AGENT_CRON_PROMPT`,
134
+ `MONO_AGENT_CRON_CONVERSATION_ID`, notification fields, `MODEL`, and `EFFORT`.
135
+ There is no `MONO_AGENT_CRON_ID`. Use `cron.jobs[]`,
136
+ `MONO_AGENT_CRON_JOBS_JSON`, or a Markdown filename/frontmatter id when a stable
137
+ custom job id is required.
138
+
139
+ ## Architecture
140
+
141
+ ### Data flow
142
+
143
+ The request lifecycle is:
144
+
145
+ 1. `config.ts` loads inline, environment, and directory-backed jobs, rejects
146
+ duplicate ids, and projects enabled entries through `toCronJobs`.
147
+ 2. `cron-expression.ts` validates the five-field expression and resolves the
148
+ next timezone-aware firing; hashed fields use the job id as their seed.
149
+ 3. `scheduler.ts` admits the firing under the selected overlap policy, creates
150
+ an abortable `AgentRequestBase`, and invokes the host-owned responder.
151
+ 4. The scheduler emits a typed `CronJobResult`; the host decides whether to log,
152
+ persist, or deliver that result. `stop()` clears timers, queues, and active
153
+ runs.
154
+
155
+ ### Package structure
156
+
157
+ | Source module | Responsibility |
158
+ | --- | --- |
159
+ | [`config.ts`](https://github.com/robertsreberski/mono-agent/blob/main/packages/cron-adapter/src/config.ts) | Config/env layering, directory merge, redaction, and enabled-job projection. |
160
+ | [`jobs-dir.ts`](https://github.com/robertsreberski/mono-agent/blob/main/packages/cron-adapter/src/jobs-dir.ts) | Markdown frontmatter parsing and deterministic folder loading. |
161
+ | [`cron-expression.ts`](https://github.com/robertsreberski/mono-agent/blob/main/packages/cron-adapter/src/cron-expression.ts) | Shared expression and timezone validation. |
162
+ | [`scheduler.ts`](https://github.com/robertsreberski/mono-agent/blob/main/packages/cron-adapter/src/scheduler.ts) | Timers, overlap/overflow policy, cancellation, watchdogs, and results. |
163
+ | [`index.ts`](https://github.com/robertsreberski/mono-agent/blob/main/packages/cron-adapter/src/index.ts) | Supported public package surface. |
164
+
73
165
  ## Public API
74
166
 
167
+ ### Start here
168
+
169
+ | API | Use it for |
170
+ | --- | --- |
171
+ | `loadCronAdapterConfig` | Load and validate config, env, and optional `cron/*.md` jobs. |
172
+ | `toCronJobs` | Drop disabled config entries and produce scheduler-ready jobs. |
173
+ | `startCronAdapter` | Start future scheduling in a custom host and obtain `stop()`. |
174
+ | `validateCronExpression` | Validate user input with the scheduler's parser. |
175
+ | `loadCronJobsFromDirectory` / `parseCronJobMarkdown` | Build custom directory-backed authoring flows. |
176
+ | `CronJobResult` | Handle every terminal and overlap/queue result explicitly. |
177
+
75
178
  <!-- public-api-inventory:start -->
76
179
  <!-- Generated by scripts/generate-public-api-docs.mjs. Do not edit by hand. -->
77
180
 
@@ -117,8 +220,17 @@ This adapter depends on `cron-parser` plus shared `@mono-agent/agent-contracts`
117
220
 
118
221
  It does not build prompts, run models, persist missed runs or pending firings, catch up after restart, expose UI, or define core agent settings. Its programmatic overlap queue is in-memory only; durable scheduling state can be added later by a host-level persistence package.
119
222
 
223
+ ## Related Documentation
224
+
225
+ - [Cron channel guide](https://mono-agent-docs.vercel.app/channels/cron/)
226
+ - [Cron digest and proactive-notify playbook](https://mono-agent-docs.vercel.app/playbooks/cron-digest-proactive-notify/)
227
+ - [Sessions and concurrency](https://mono-agent-docs.vercel.app/runtime/sessions-concurrency/)
228
+ - [Environment-variable precedence](https://mono-agent-docs.vercel.app/config/env-vars/)
229
+
120
230
  ## Verification
121
231
 
232
+ Run the package-local build, typecheck, and behavior tests:
233
+
122
234
  ```bash
123
235
  pnpm --filter @mono-agent/cron-adapter run build
124
236
  pnpm --filter @mono-agent/cron-adapter run typecheck
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mono-agent/cron-adapter",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "Cron-based scheduled invocation adapter for agent responders.",
5
5
  "type": "module",
6
6
  "license": "GPL-3.0-only",
@@ -26,7 +26,7 @@
26
26
  "README.md"
27
27
  ],
28
28
  "dependencies": {
29
- "@mono-agent/agent-contracts": "0.13.0",
29
+ "@mono-agent/agent-contracts": "0.14.0",
30
30
  "cron-parser": "^5.5.0"
31
31
  },
32
32
  "publishConfig": {