@capybara-hq/kernel 0.1.0-rc.104 → 0.1.0-rc.106

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 (250) hide show
  1. package/dist/agents/agents.schemas.d.ts +9 -9
  2. package/dist/{schedules/schedules.controller.d.ts → automations/automations.controller.d.ts} +37 -32
  3. package/dist/{schedules/schedules.controller.js → automations/automations.controller.js} +68 -57
  4. package/dist/automations/automations.module.d.ts +16 -0
  5. package/dist/{schedules/schedules.module.js → automations/automations.module.js} +18 -15
  6. package/dist/{schedules/schedules.schemas.d.ts → automations/automations.schemas.d.ts} +151 -50
  7. package/dist/automations/automations.schemas.js +253 -0
  8. package/dist/{schedules/scheduled-tasks.service.d.ts → automations/automations.service.d.ts} +99 -52
  9. package/dist/{schedules/scheduled-tasks.service.js → automations/automations.service.js} +303 -134
  10. package/dist/{schedules → automations}/calendar.d.ts +8 -8
  11. package/dist/{schedules → automations}/calendar.js +2 -2
  12. package/dist/automations/effective-settings.d.ts +28 -0
  13. package/dist/automations/effective-settings.js +25 -0
  14. package/dist/automations/errors.d.ts +19 -0
  15. package/dist/automations/errors.js +19 -0
  16. package/dist/automations/events/coalesce.d.ts +28 -0
  17. package/dist/automations/events/coalesce.js +131 -0
  18. package/dist/automations/events/deadline.d.ts +10 -0
  19. package/dist/automations/events/deadline.js +24 -0
  20. package/dist/automations/events/dispatcher.d.ts +74 -0
  21. package/dist/automations/events/dispatcher.js +353 -0
  22. package/dist/automations/events/events.module.d.ts +7 -0
  23. package/dist/automations/events/events.module.js +26 -0
  24. package/dist/automations/events/guards.d.ts +32 -0
  25. package/dist/automations/events/guards.js +87 -0
  26. package/dist/automations/events/sweep.job.d.ts +49 -0
  27. package/dist/automations/events/sweep.job.js +202 -0
  28. package/dist/automations/events/token.d.ts +5 -0
  29. package/dist/automations/events/token.js +5 -0
  30. package/dist/automations/events/trigger-events.service.d.ts +47 -0
  31. package/dist/automations/events/trigger-events.service.js +254 -0
  32. package/dist/{schedules → automations}/fire.d.ts +57 -17
  33. package/dist/{schedules → automations}/fire.js +311 -79
  34. package/dist/{schedules → automations}/grant-rules.d.ts +1 -1
  35. package/dist/{schedules → automations}/grant-rules.js +5 -5
  36. package/dist/automations/job-ids.d.ts +113 -0
  37. package/dist/automations/job-ids.js +117 -0
  38. package/dist/{schedules → automations}/pause.d.ts +3 -3
  39. package/dist/{schedules → automations}/pause.js +3 -3
  40. package/dist/{schedules → automations}/run-tracker.d.ts +21 -10
  41. package/dist/{schedules → automations}/run-tracker.js +68 -56
  42. package/dist/{schedules → automations}/scan.job.d.ts +12 -8
  43. package/dist/{schedules → automations}/scan.job.js +39 -23
  44. package/dist/{schedules → automations}/schedule-math.d.ts +19 -12
  45. package/dist/{schedules → automations}/schedule-math.js +17 -7
  46. package/dist/{schedules → automations}/store.d.ts +57 -27
  47. package/dist/{schedules → automations}/store.js +102 -52
  48. package/dist/automations/store.module.d.ts +6 -0
  49. package/dist/{schedules → automations}/store.module.js +9 -9
  50. package/dist/automations/types.d.ts +178 -0
  51. package/dist/{schedules → automations}/unattended.d.ts +22 -11
  52. package/dist/{schedules → automations}/unattended.js +53 -30
  53. package/dist/catalog/marketplaces.service.d.ts +1 -1
  54. package/dist/channels/channels.module.js +3 -3
  55. package/dist/channels/outbound.d.ts +5 -5
  56. package/dist/channels/outbound.js +17 -17
  57. package/dist/channels/threads.d.ts +1 -1
  58. package/dist/channels/threads.js +1 -1
  59. package/dist/config/schema.d.ts +5 -1
  60. package/dist/config/schema.js +44 -6
  61. package/dist/conversations/approval-profile.d.ts +2 -2
  62. package/dist/conversations/approval-profile.js +3 -3
  63. package/dist/conversations/conversations.controller.d.ts +7 -1
  64. package/dist/conversations/conversations.controller.js +26 -10
  65. package/dist/conversations/conversations.service.d.ts +103 -25
  66. package/dist/conversations/conversations.service.js +138 -33
  67. package/dist/conversations/events.d.ts +48 -1
  68. package/dist/conversations/events.js +61 -9
  69. package/dist/conversations/message-context.d.ts +2 -2
  70. package/dist/conversations/message-context.js +1 -1
  71. package/dist/conversations/permission-profile-store.d.ts +2 -1
  72. package/dist/conversations/permission-profiles.controller.d.ts +3 -0
  73. package/dist/conversations/permission-profiles.service.js +1 -1
  74. package/dist/conversations/prompt-suggestion-request.d.ts +1 -1
  75. package/dist/conversations/prompt-suggestion-request.js +2 -1
  76. package/dist/conversations/queue.d.ts +7 -4
  77. package/dist/conversations/queue.js +6 -2
  78. package/dist/conversations/queue.service.d.ts +5 -5
  79. package/dist/conversations/queue.service.js +20 -14
  80. package/dist/ctx/create-ctx.d.ts +20 -1
  81. package/dist/ctx/create-ctx.js +59 -2
  82. package/dist/db/kernel-schema.d.ts +104 -25
  83. package/dist/devices/device-project-files.service.d.ts +88 -0
  84. package/dist/devices/device-project-files.service.js +249 -0
  85. package/dist/devices/device-projects.service.d.ts +40 -0
  86. package/dist/devices/device-projects.service.js +16 -13
  87. package/dist/devices/devices.controller.d.ts +9 -3
  88. package/dist/devices/devices.controller.js +27 -5
  89. package/dist/devices/devices.module.js +9 -1
  90. package/dist/devices/devices.schemas.js +6 -1
  91. package/dist/devices/dto.d.ts +15 -0
  92. package/dist/devices/dto.js +11 -0
  93. package/dist/devices/project-paths.d.ts +29 -0
  94. package/dist/devices/project-paths.js +66 -0
  95. package/dist/devices/project-rules.d.ts +5 -1
  96. package/dist/devices/project-rules.js +5 -1
  97. package/dist/errors.d.ts +47 -13
  98. package/dist/errors.js +47 -13
  99. package/dist/evals/reconstruct.d.ts +10 -1
  100. package/dist/evals/reconstruct.js +7 -0
  101. package/dist/extensions/host.d.ts +6 -1
  102. package/dist/extensions/host.js +10 -0
  103. package/dist/extensions/permission-set.d.ts +17 -1
  104. package/dist/extensions/permission-set.js +13 -1
  105. package/dist/extensions/permission-view.d.ts +1 -1
  106. package/dist/extensions/permission-view.js +4 -1
  107. package/dist/git/gateway.js +2 -2
  108. package/dist/handoff/app-schemes.d.ts +28 -0
  109. package/dist/handoff/app-schemes.js +41 -0
  110. package/dist/handoff/handoff-paths.d.ts +26 -0
  111. package/dist/handoff/handoff-paths.js +25 -0
  112. package/dist/handoff/handoff-tickets.d.ts +28 -0
  113. package/dist/handoff/handoff-tickets.js +111 -0
  114. package/dist/handoff/handoff.controller.d.ts +24 -0
  115. package/dist/handoff/handoff.controller.js +74 -0
  116. package/dist/handoff/handoff.module.d.ts +7 -0
  117. package/dist/handoff/handoff.module.js +26 -0
  118. package/dist/handoff/handoff.schemas.d.ts +13 -0
  119. package/dist/handoff/handoff.schemas.js +3 -0
  120. package/dist/handoff/handoff.service.d.ts +49 -0
  121. package/dist/handoff/handoff.service.js +96 -0
  122. package/dist/http/api.module.js +13 -5
  123. package/dist/http/meta.controller.d.ts +1 -0
  124. package/dist/http/meta.controller.js +7 -0
  125. package/dist/http/request-signal.d.ts +8 -0
  126. package/dist/http/request-signal.js +14 -0
  127. package/dist/identity/sso.controller.d.ts +30 -6
  128. package/dist/identity/sso.controller.js +51 -17
  129. package/dist/identity/sso.d.ts +10 -2
  130. package/dist/identity/sso.js +15 -3
  131. package/dist/inbox/inbox.module.js +2 -2
  132. package/dist/inbox/inbox.service.d.ts +8 -8
  133. package/dist/inbox/inbox.service.js +7 -7
  134. package/dist/infra/config/kernel-config.service.js +10 -5
  135. package/dist/infra/outbox/registry.d.ts +29 -2
  136. package/dist/infra/outbox/registry.js +30 -7
  137. package/dist/kernel.module.js +3 -0
  138. package/dist/orgs/roles.d.ts +1 -1
  139. package/dist/orgs/roles.js +3 -3
  140. package/dist/orgs/settings.controller.d.ts +1 -1
  141. package/dist/orgs/settings.service.d.ts +27 -11
  142. package/dist/orgs/settings.service.js +42 -24
  143. package/dist/overrides.d.ts +4 -4
  144. package/dist/overrides.js +1 -1
  145. package/dist/platform/exclusions.js +5 -0
  146. package/dist/platform/operation.js +2 -2
  147. package/dist/platform/ops/{schedules.ops.d.ts → automations.ops.d.ts} +4 -4
  148. package/dist/platform/ops/automations.ops.js +560 -0
  149. package/dist/platform/ops/connectors.ops.js +4 -2
  150. package/dist/platform/ops/devices.ops.d.ts +3 -1
  151. package/dist/platform/ops/devices.ops.js +77 -3
  152. package/dist/platform/ops/inbox.ops.js +4 -4
  153. package/dist/platform/ops/orgs.ops.js +1 -1
  154. package/dist/platform/ops/platform.ops.js +4 -4
  155. package/dist/platform/platform-ops.module.d.ts +2 -2
  156. package/dist/platform/platform-ops.module.js +5 -5
  157. package/dist/platform/route-schemas.js +3 -3
  158. package/dist/push/jobs.d.ts +3 -3
  159. package/dist/push/jobs.js +2 -2
  160. package/dist/push/preferences.service.js +1 -1
  161. package/dist/push/push-owed.d.ts +3 -3
  162. package/dist/push/push-owed.js +6 -6
  163. package/dist/push/push.schemas.d.ts +4 -4
  164. package/dist/push/push.schemas.js +3 -3
  165. package/dist/push/recipients.d.ts +4 -4
  166. package/dist/push/recipients.js +23 -23
  167. package/dist/push/texts.d.ts +3 -3
  168. package/dist/push/texts.js +2 -2
  169. package/dist/push/triggers.d.ts +1 -1
  170. package/dist/roles/worker.module.js +3 -3
  171. package/dist/runtime/compaction.service.d.ts +3 -1
  172. package/dist/runtime/compaction.service.js +3 -1
  173. package/dist/runtime/context/build.d.ts +6 -0
  174. package/dist/runtime/context/build.js +14 -3
  175. package/dist/runtime/context/compaction.d.ts +27 -1
  176. package/dist/runtime/context/compaction.js +102 -37
  177. package/dist/runtime/context/run-context.d.ts +38 -0
  178. package/dist/runtime/context/run-context.js +54 -0
  179. package/dist/runtime/maintenance.d.ts +8 -4
  180. package/dist/runtime/maintenance.js +37 -16
  181. package/dist/runtime/model-call.d.ts +6 -4
  182. package/dist/runtime/model-call.js +17 -7
  183. package/dist/runtime/project/knowledge.service.d.ts +16 -7
  184. package/dist/runtime/project/knowledge.service.js +31 -13
  185. package/dist/runtime/run-finish.d.ts +4 -4
  186. package/dist/runtime/run-finish.js +3 -3
  187. package/dist/runtime/run-queue.js +12 -7
  188. package/dist/runtime/run-worker.js +7 -1
  189. package/dist/runtime/runtime.module.js +3 -3
  190. package/dist/runtime/subagents/dispatch.js +11 -3
  191. package/dist/sandbox/browse-roots.d.ts +8 -0
  192. package/dist/sandbox/browse-roots.js +22 -0
  193. package/dist/sandbox/network-grants.d.ts +4 -4
  194. package/dist/sandbox/network-grants.js +7 -7
  195. package/dist/sandbox/operation-authority.d.ts +10 -3
  196. package/dist/sandbox/operation-authority.js +20 -10
  197. package/dist/sandbox/operation-intents.d.ts +3 -1
  198. package/dist/sandbox/operation-intents.js +11 -4
  199. package/dist/sandbox/permission-call-grants.js +2 -2
  200. package/dist/sandbox/permission-facts.js +1 -1
  201. package/dist/sandbox/review/classifier.d.ts +2 -2
  202. package/dist/sandbox/review/classifier.js +22 -11
  203. package/dist/sandbox/review/permission-candidate.d.ts +1 -1
  204. package/dist/sandbox/review/permission-candidate.js +1 -1
  205. package/dist/sandbox/sandbox.service.d.ts +15 -5
  206. package/dist/sandbox/sandbox.service.js +14 -8
  207. package/dist/storage/purge.d.ts +1 -1
  208. package/dist/storage/purge.js +2 -2
  209. package/dist/tools/approvals.service.d.ts +6 -6
  210. package/dist/tools/approvals.service.js +19 -19
  211. package/dist/tools/builtin-names.d.ts +12 -12
  212. package/dist/tools/builtin-names.js +29 -29
  213. package/dist/tools/builtins/{schedules.d.ts → automations.d.ts} +35 -33
  214. package/dist/tools/builtins/{schedules.js → automations.js} +236 -105
  215. package/dist/tools/builtins/builtin-tools.d.ts +8 -8
  216. package/dist/tools/builtins/builtin-tools.js +16 -16
  217. package/dist/tools/call-scope.d.ts +1 -1
  218. package/dist/tools/connectors.service.d.ts +4 -13
  219. package/dist/tools/connectors.service.js +12 -21
  220. package/dist/tools/git-asks.js +1 -1
  221. package/dist/tools/git-push-policy.d.ts +3 -3
  222. package/dist/tools/git-push-policy.js +6 -6
  223. package/dist/tools/network-asks.d.ts +3 -3
  224. package/dist/tools/network-asks.js +3 -3
  225. package/dist/tools/oauth/flow.d.ts +16 -2
  226. package/dist/tools/oauth/flow.js +23 -4
  227. package/dist/tools/oauth/oauth.controller.d.ts +19 -7
  228. package/dist/tools/oauth/oauth.controller.js +42 -12
  229. package/dist/tools/oauth/oauth.schemas.d.ts +14 -1
  230. package/dist/tools/oauth/oauth.schemas.js +4 -1
  231. package/dist/tools/pipeline.d.ts +4 -4
  232. package/dist/tools/pipeline.js +2 -2
  233. package/dist/tools/policy.d.ts +3 -3
  234. package/dist/tools/policy.js +3 -3
  235. package/dist/tools/tools.module.js +9 -9
  236. package/package.json +3 -3
  237. package/src/migrations/0188_automations_rename.sql +309 -0
  238. package/src/migrations/0189_event_automations.sql +136 -0
  239. package/dist/platform/ops/schedules.ops.js +0 -509
  240. package/dist/schedules/effective-settings.d.ts +0 -22
  241. package/dist/schedules/effective-settings.js +0 -18
  242. package/dist/schedules/errors.d.ts +0 -8
  243. package/dist/schedules/errors.js +0 -8
  244. package/dist/schedules/job-ids.d.ts +0 -81
  245. package/dist/schedules/job-ids.js +0 -95
  246. package/dist/schedules/schedules.module.d.ts +0 -16
  247. package/dist/schedules/schedules.schemas.js +0 -213
  248. package/dist/schedules/store.module.d.ts +0 -6
  249. package/dist/schedules/types.d.ts +0 -110
  250. /package/dist/{schedules → automations}/types.js +0 -0
@@ -14,7 +14,7 @@ import { KernelDb } from "../infra/database/kernel-db.js";
14
14
  import { TransactionHost } from "../infra/database/transaction-host.js";
15
15
  import { Transactional } from "../infra/database/transactional.decorator.js";
16
16
  import { PushOwed, PushOwedModule } from "../push/push-owed.js";
17
- import { readScheduleSettings } from "./effective-settings.js";
17
+ import { readAutomationSettings } from "./effective-settings.js";
18
18
  import { pauseTaskIn } from "./pause.js";
19
19
  /** The kernel run statuses that are terminal (`runtime/run-finish.ts`, not imported: a cycle). */
20
20
  const RUN_TERMINAL = new Set(["completed", "failed", "aborted"]);
@@ -33,13 +33,13 @@ export const START_GRACE_MS = 5 * 60_000;
33
33
  * {@link inFlightIn} is the overlap check's view of the task's previous run: it settles a run whose
34
34
  * end was missed and releases one whose queued message is gone.
35
35
  */
36
- let ScheduledTaskRunTracker = class ScheduledTaskRunTracker {
36
+ let AutomationRunTracker = class AutomationRunTracker {
37
37
  kdb;
38
38
  txHost;
39
39
  config;
40
40
  push;
41
41
  constructor(kdb, txHost, config,
42
- /** Owes the task owner's push (`schedules`) with every settle. */
42
+ /** Owes the task owner's push (`automations`) with every settle. */
43
43
  push) {
44
44
  this.kdb = kdb;
45
45
  this.txHost = txHost;
@@ -51,30 +51,30 @@ let ScheduledTaskRunTracker = class ScheduledTaskRunTracker {
51
51
  }
52
52
  /**
53
53
  * The kernel run `runId` ended with `outcome`: the task run it was started for (the run its
54
- * message triggered, `scheduled_task_runs.run_id`) takes the outcome. A sub-agent or wake run
54
+ * message triggered, `automation_runs.run_id`) takes the outcome. A sub-agent or wake run
55
55
  * that inherited the marker is not the task run's own and changes nothing.
56
56
  */
57
57
  async onRunFinished(runId, outcome, error) {
58
58
  const run = await this.db
59
59
  .selectFrom("runs")
60
- .select("scheduled_task_run_id")
60
+ .select("automation_run_id")
61
61
  .where("id", "=", runId)
62
62
  .executeTakeFirst();
63
- const taskRunId = run?.scheduled_task_run_id;
63
+ const taskRunId = run?.automation_run_id;
64
64
  if (taskRunId == null)
65
65
  return;
66
66
  const owner = await this.db
67
- .selectFrom("scheduled_task_runs")
68
- .select("task_id")
67
+ .selectFrom("automation_runs")
68
+ .select("automation_id")
69
69
  .where("id", "=", taskRunId)
70
70
  .executeTakeFirst();
71
71
  if (!owner)
72
72
  return;
73
73
  // lock order task row → task run, as the fire job's claim takes them (no lock cycle)
74
- await lockTaskRow(this.db, owner.task_id);
74
+ await lockTaskRow(this.db, owner.automation_id);
75
75
  const tr = await this.db
76
- .selectFrom("scheduled_task_runs")
77
- .select(["id", "task_id", "org_id", "trial", "status", "run_id"])
76
+ .selectFrom("automation_runs")
77
+ .select(["id", "automation_id", "org_id", "trial", "status", "run_id"])
78
78
  .where("id", "=", taskRunId)
79
79
  .forUpdate()
80
80
  .executeTakeFirst();
@@ -95,7 +95,7 @@ let ScheduledTaskRunTracker = class ScheduledTaskRunTracker {
95
95
  const t = this.db;
96
96
  await lockTaskRow(t, prev.taskId);
97
97
  const tr = await t
98
- .selectFrom("scheduled_task_runs")
98
+ .selectFrom("automation_runs")
99
99
  .selectAll()
100
100
  .where("id", "=", prev.id)
101
101
  .forUpdate()
@@ -123,15 +123,15 @@ let ScheduledTaskRunTracker = class ScheduledTaskRunTracker {
123
123
  // when the job failed for good before its claim)
124
124
  if (tr.fired_at === null)
125
125
  return true;
126
- // only a run with a target conversation is ever queued (`conversation`, `chat`): no scan of
127
- // every queue's markers for the others
126
+ // only a run with a target conversation is ever queued (`conversation`, `chat`, `subject`):
127
+ // no scan of every queue's markers for the others
128
128
  const queued = tr.conversation_id === null
129
129
  ? undefined
130
130
  : await t
131
131
  .selectFrom("conversation_queue")
132
132
  .select("id")
133
133
  .where("conversation_id", "=", tr.conversation_id)
134
- .where(sql `schedule ->> 'taskRunId'`, "=", tr.id)
134
+ .where(sql `coalesce(schedule ->> 'taskRunId', automation_event ->> 'automationRunId')`, "=", tr.id)
135
135
  .limit(1)
136
136
  .executeTakeFirst();
137
137
  if (queued)
@@ -141,7 +141,7 @@ let ScheduledTaskRunTracker = class ScheduledTaskRunTracker {
141
141
  .selectFrom("conversations")
142
142
  .select("id")
143
143
  .where("org_id", "=", tr.org_id)
144
- .where("scheduled_task_id", "=", tr.task_id)
144
+ .where("automation_id", "=", tr.automation_id)
145
145
  .where("create_request_id", "=", tr.id)
146
146
  .executeTakeFirst())?.id;
147
147
  if (conv !== undefined) {
@@ -149,13 +149,13 @@ let ScheduledTaskRunTracker = class ScheduledTaskRunTracker {
149
149
  .selectFrom("runs")
150
150
  .select(["id", "status"])
151
151
  .where("conversation_id", "=", conv)
152
- .where("scheduled_task_run_id", "=", tr.id)
152
+ .where("automation_run_id", "=", tr.id)
153
153
  .orderBy("created_at")
154
154
  .limit(1)
155
155
  .executeTakeFirst();
156
156
  if (run) {
157
157
  await t
158
- .updateTable("scheduled_task_runs")
158
+ .updateTable("automation_runs")
159
159
  .set({ status: "running", run_id: run.id, conversation_id: conv })
160
160
  .where("id", "=", tr.id)
161
161
  .where("org_id", "=", tr.org_id)
@@ -170,7 +170,7 @@ let ScheduledTaskRunTracker = class ScheduledTaskRunTracker {
170
170
  .select("seq")
171
171
  .where("conversation_id", "=", conv)
172
172
  .where("type", "=", "user_message")
173
- .where(sql `payload -> 'schedule' ->> 'taskRunId'`, "=", tr.id)
173
+ .where(sql `coalesce(payload -> 'schedule' ->> 'taskRunId', payload -> 'automationEvent' ->> 'automationRunId')`, "=", tr.id)
174
174
  .limit(1)
175
175
  .executeTakeFirst();
176
176
  if (message) {
@@ -193,7 +193,7 @@ let ScheduledTaskRunTracker = class ScheduledTaskRunTracker {
193
193
  if (now.getTime() - firedAt.getTime() < START_GRACE_MS)
194
194
  return true;
195
195
  await t
196
- .updateTable("scheduled_task_runs")
196
+ .updateTable("automation_runs")
197
197
  .set({ status: "skipped", skip_reason: "removed", fired_at: null })
198
198
  .where("id", "=", tr.id)
199
199
  .where("org_id", "=", tr.org_id)
@@ -209,8 +209,8 @@ let ScheduledTaskRunTracker = class ScheduledTaskRunTracker {
209
209
  */
210
210
  async failStartIn(taskRunId, error) {
211
211
  const tr = await this.db
212
- .selectFrom("scheduled_task_runs")
213
- .select(["id", "task_id", "org_id", "trial", "status"])
212
+ .selectFrom("automation_runs")
213
+ .select(["id", "automation_id", "org_id", "trial", "status"])
214
214
  .where("id", "=", taskRunId)
215
215
  .forUpdate()
216
216
  .executeTakeFirst();
@@ -226,7 +226,7 @@ let ScheduledTaskRunTracker = class ScheduledTaskRunTracker {
226
226
  const t = this.db;
227
227
  const failed = outcome === "failed";
228
228
  await t
229
- .updateTable("scheduled_task_runs")
229
+ .updateTable("automation_runs")
230
230
  .set({
231
231
  status: failed ? "failed" : "completed",
232
232
  ...(failed && { error: error ?? "The run failed" }),
@@ -234,66 +234,66 @@ let ScheduledTaskRunTracker = class ScheduledTaskRunTracker {
234
234
  .where("id", "=", tr.id)
235
235
  .where("org_id", "=", tr.org_id)
236
236
  .execute();
237
- await this.push.oweScheduleRun(tr.id, tr.org_id);
237
+ await this.push.oweAutomationRun(tr.id, tr.org_id);
238
238
  if (tr.trial)
239
239
  return;
240
240
  if (!failed) {
241
241
  await t
242
- .updateTable("scheduled_tasks")
242
+ .updateTable("automations")
243
243
  .set({ consecutive_failures: 0 })
244
- .where("id", "=", tr.task_id)
244
+ .where("id", "=", tr.automation_id)
245
245
  .where("org_id", "=", tr.org_id)
246
246
  .where("consecutive_failures", "!=", 0)
247
247
  .execute();
248
248
  return;
249
249
  }
250
250
  const row = await t
251
- .updateTable("scheduled_tasks")
251
+ .updateTable("automations")
252
252
  .set({ consecutive_failures: sql `consecutive_failures + 1` })
253
- .where("id", "=", tr.task_id)
253
+ .where("id", "=", tr.automation_id)
254
254
  .where("org_id", "=", tr.org_id)
255
255
  .where("deleted_at", "is", null)
256
256
  .returning("consecutive_failures")
257
257
  .executeTakeFirst();
258
258
  if (!row)
259
259
  return;
260
- const settings = await readScheduleSettings(t, this.config, tr.org_id);
260
+ const settings = await readAutomationSettings(t, this.config, tr.org_id);
261
261
  if (row.consecutive_failures >= settings.pauseAfterFailures) {
262
- await pauseTaskIn(t, tr.task_id, "failures", null);
262
+ await pauseTaskIn(t, tr.automation_id, "failures", null);
263
263
  }
264
264
  }
265
265
  };
266
266
  __decorate([
267
267
  Transactional()
268
- ], ScheduledTaskRunTracker.prototype, "onRunFinished", null);
268
+ ], AutomationRunTracker.prototype, "onRunFinished", null);
269
269
  __decorate([
270
270
  Transactional({ propagation: "mandatory" })
271
- ], ScheduledTaskRunTracker.prototype, "inFlightIn", null);
271
+ ], AutomationRunTracker.prototype, "inFlightIn", null);
272
272
  __decorate([
273
273
  Transactional({ propagation: "mandatory" })
274
- ], ScheduledTaskRunTracker.prototype, "failStartIn", null);
275
- ScheduledTaskRunTracker = __decorate([
274
+ ], AutomationRunTracker.prototype, "failStartIn", null);
275
+ AutomationRunTracker = __decorate([
276
276
  Injectable()
277
277
  // org-filter: kernel-internal (run finish, fire job, settle job): task run ids come from a kernel
278
- // run's scheduled_task_run_id or from a task run row the caller already holds, never from input
278
+ // run's automation_run_id or from a task run row the caller already holds, never from input
279
279
  ,
280
280
  __param(0, Inject(KernelDb)),
281
281
  __param(1, Inject(TransactionHost)),
282
282
  __param(2, Inject(KernelConfigService)),
283
283
  __param(3, Inject(PushOwed))
284
- ], ScheduledTaskRunTracker);
285
- export { ScheduledTaskRunTracker };
284
+ ], AutomationRunTracker);
285
+ export { AutomationRunTracker };
286
286
  /**
287
287
  * A kernel run was created for task run `taskRunId` (its message is the run's trigger, or it
288
288
  * inherited the marker): a task run still `pending` takes the run (`running`), in the caller's
289
289
  * transaction (`RunQueue.ensureRunIn`, which inserts the run). A task run already linked (a
290
290
  * sub-agent or wake run inheriting the marker) is left alone.
291
291
  */
292
- // org-filter: the task run id is the kernel-written schedule marker of the run's trigger message
293
- // (scheduledTaskRunAt), set only through the kernel-internal schedule option, never by a person
292
+ // org-filter: the task run id is the kernel-written schedule or event marker of the run's trigger
293
+ // message (automationRunAt), set only through the kernel-internal options, never by a person
294
294
  export async function linkStartedRunIn(t, taskRunId, runId, conversationId) {
295
295
  await t
296
- .updateTable("scheduled_task_runs")
296
+ .updateTable("automation_runs")
297
297
  .set({
298
298
  status: "running",
299
299
  run_id: runId,
@@ -305,18 +305,30 @@ export async function linkStartedRunIn(t, taskRunId, runId, conversationId) {
305
305
  .execute();
306
306
  }
307
307
  /**
308
- * A person removed, edited or sent the queued item that carried `schedule` (the item's stored
309
- * marker, or null): its task run will never run as the task's, so it becomes `skipped`
308
+ * The automation run a queued item's stored marker names: its schedule marker's `taskRunId`, or
309
+ * its event marker's `automationRunId` (collaboration spec §4.6); undefined for a person's item.
310
+ */
311
+ export function queuedAutomationRunId(item) {
312
+ const fromSchedule = item.schedule?.taskRunId;
313
+ if (typeof fromSchedule === "string")
314
+ return fromSchedule;
315
+ const fromEvent = item.automation_event
316
+ ?.automationRunId;
317
+ return typeof fromEvent === "string" ? fromEvent : undefined;
318
+ }
319
+ /**
320
+ * A person removed, edited or sent the queued item that carried a schedule or event marker (the
321
+ * item's stored columns): its task run will never run as the task's, so it becomes `skipped`
310
322
  * (`removed`) in the caller's transaction, and the next tick is not held by the overlap check.
311
323
  */
312
- // org-filter: the marker is the queued item's stored schedule column, written only through the
313
- // kernel-internal schedule option of the queue (never from a request body)
314
- export async function releaseQueuedTaskRunIn(t, schedule) {
315
- const taskRunId = schedule?.taskRunId;
316
- if (typeof taskRunId !== "string")
324
+ // org-filter: the marker is the queued item's stored schedule / automation_event column, written
325
+ // only through the kernel-internal options of the queue (never from a request body)
326
+ export async function releaseQueuedTaskRunIn(t, item) {
327
+ const taskRunId = queuedAutomationRunId(item);
328
+ if (taskRunId === undefined)
317
329
  return;
318
330
  await t
319
- .updateTable("scheduled_task_runs")
331
+ .updateTable("automation_runs")
320
332
  .set({ status: "skipped", skip_reason: "removed", fired_at: null })
321
333
  .where("id", "=", taskRunId)
322
334
  .where("status", "=", "pending")
@@ -331,20 +343,20 @@ export async function releaseQueuedTaskRunIn(t, schedule) {
331
343
  // org-filter: a row lock by the task id of a task or task run row the kernel caller already holds
332
344
  export async function lockTaskRow(t, taskId) {
333
345
  await t
334
- .selectFrom("scheduled_tasks")
346
+ .selectFrom("automations")
335
347
  .select("id")
336
348
  .where("id", "=", taskId)
337
349
  .forUpdate()
338
350
  .executeTakeFirst();
339
351
  }
340
- /** The run tracker alone: the runtime (`RunFinish`) imports it without the schedules service. */
341
- let ScheduledTaskTrackerModule = class ScheduledTaskTrackerModule {
352
+ /** The run tracker alone: the runtime (`RunFinish`) imports it without the automations service. */
353
+ let AutomationTrackerModule = class AutomationTrackerModule {
342
354
  };
343
- ScheduledTaskTrackerModule = __decorate([
355
+ AutomationTrackerModule = __decorate([
344
356
  Module({
345
357
  imports: [PushOwedModule],
346
- providers: [ScheduledTaskRunTracker],
347
- exports: [ScheduledTaskRunTracker],
358
+ providers: [AutomationRunTracker],
359
+ exports: [AutomationRunTracker],
348
360
  })
349
- ], ScheduledTaskTrackerModule);
350
- export { ScheduledTaskTrackerModule };
361
+ ], AutomationTrackerModule);
362
+ export { AutomationTrackerModule };
@@ -4,22 +4,24 @@ import { TransactionHost } from "../infra/database/transaction-host.js";
4
4
  import { LockService } from "../infra/lock/lock.service.js";
5
5
  import { OutboxService } from "../infra/outbox/outbox.service.js";
6
6
  import type { KernelLogger } from "../log.js";
7
- import { ScheduledTaskStore } from "./store.js";
7
+ import { AutomationStore } from "./store.js";
8
8
  /**
9
- * The scheduled task scanner (spec §6), once a minute across replicas. Each due task in its own
9
+ * The automation scanner (spec §6), once a minute across replicas. Each due task in its own
10
10
  * transaction, locked with `FOR UPDATE SKIP LOCKED` (replicas share the work and never take the
11
11
  * same task): the ticks missed outside the org's `catchUpWindowMinutes` become one `skipped` run
12
12
  * (`missed`, at the first missed tick), the latest tick in the window gets its run (the unique
13
- * `(task_id, scheduled_for)` key makes a second insert a no-op), `next_run_at` moves to the next
13
+ * `(automation_id, scheduled_for)` key makes a second insert a no-op), `next_run_at` moves to the next
14
14
  * tick plus the task's jitter (or a `once` task ends, or one past its `expires_at`), and the same
15
- * transaction owes `sched-fire-<taskRunId>` (transactional outbox spec §8.1), so a written tick is
15
+ * transaction owes `automation-fire-<taskRunId>` (transactional outbox spec §8.1), so a written tick is
16
16
  * never left unfired and the scan needs no repair of lost fire jobs (a fire delivered too late
17
- * marks its tick missed itself, `ScheduledTaskFirer`), and the run's unfired settle check (a fire
17
+ * marks its tick missed itself, `AutomationFirer`), and the run's unfired settle check (a fire
18
18
  * job that failed for good before its claim: the tick is missed, `job-ids.ts`). A task whose stored
19
19
  * trigger the schedule math cannot evaluate is paused (`invalid_schedule`) instead of failing the
20
- * scan; a database error fails the pass (the next minute retries) and pauses nothing.
20
+ * scan; a database error fails the pass (the next minute retries) and pauses nothing. An event
21
+ * automation past its `expires_at` (it has no tick to be due at) ends the same way, `expired`, in
22
+ * one transaction per scan (the dispatcher already passes it over).
21
23
  */
22
- export declare class ScheduledTaskScanJob {
24
+ export declare class AutomationScanJob {
23
25
  private readonly kdb;
24
26
  readonly txHost: TransactionHost;
25
27
  private readonly config;
@@ -27,11 +29,13 @@ export declare class ScheduledTaskScanJob {
27
29
  private readonly outbox;
28
30
  readonly lockService: LockService;
29
31
  readonly log: KernelLogger;
30
- constructor(kdb: KernelDb, txHost: TransactionHost, config: Pick<KernelConfigService, "get">, store: ScheduledTaskStore, outbox: Pick<OutboxService, "add">, lockService: LockService, log: KernelLogger);
32
+ constructor(kdb: KernelDb, txHost: TransactionHost, config: Pick<KernelConfigService, "get">, store: AutomationStore, outbox: Pick<OutboxService, "add">, lockService: LockService, log: KernelLogger);
31
33
  private get db();
32
34
  scan(): Promise<void>;
33
35
  /** One scan as of `now` (tests pass their own); returns how many due tasks it handled. */
34
36
  scanAt(now: Date): Promise<number>;
37
+ /** Ends the event automations past their expiry (see the class); returns how many. */
38
+ endExpiredEvents(now: Date): Promise<number>;
35
39
  /**
36
40
  * One due task in its own transaction (a task whose trigger cannot be evaluated rolls back alone
37
41
  * and is paused, so it cannot block the others): locked with `SKIP LOCKED`, so replicas take
@@ -17,13 +17,15 @@ import { LockService } from "../infra/lock/lock.service.js";
17
17
  import { OutboxService } from "../infra/outbox/outbox.service.js";
18
18
  import { LockedCron } from "../infra/schedule/locked-cron.decorator.js";
19
19
  import { KERNEL_LOGGER } from "../infra/tokens.js";
20
- import { readScheduleSettings } from "./effective-settings.js";
21
- import { oweSchedFire, oweSchedSettleUnfired, SCHED_SCAN_JOB } from "./job-ids.js";
20
+ import { readAutomationSettings } from "./effective-settings.js";
21
+ import { AUTOMATION_SCAN_JOB, oweAutomationFire, oweAutomationSettleUnfired } from "./job-ids.js";
22
22
  import { pauseTaskIn } from "./pause.js";
23
23
  import { scanStep } from "./schedule-math.js";
24
- import { ScheduledTaskStore } from "./store.js";
24
+ import { AutomationStore } from "./store.js";
25
25
  /** Due tasks per scan; what is left waits for the next minute. */
26
26
  const MAX_TASKS = 2000;
27
+ /** How a task past its `expires_at` ends (a time task when due, an event task in the scan). */
28
+ const EXPIRED = { status: "ended", pauseReason: "expired", nextRunAt: null };
27
29
  /**
28
30
  * The schedule math could not evaluate a due task's stored trigger (its transaction rolled back);
29
31
  * the scan pauses it. Only the math raises it: a database error fails the scan pass instead (the
@@ -32,25 +34,27 @@ const MAX_TASKS = 2000;
32
34
  class TaskScanFailed extends Error {
33
35
  taskId;
34
36
  constructor(taskId, cause) {
35
- super(`scheduled task ${taskId} cannot be advanced`, { cause });
37
+ super(`automation ${taskId} cannot be advanced`, { cause });
36
38
  this.taskId = taskId;
37
39
  }
38
40
  }
39
41
  /**
40
- * The scheduled task scanner (spec §6), once a minute across replicas. Each due task in its own
42
+ * The automation scanner (spec §6), once a minute across replicas. Each due task in its own
41
43
  * transaction, locked with `FOR UPDATE SKIP LOCKED` (replicas share the work and never take the
42
44
  * same task): the ticks missed outside the org's `catchUpWindowMinutes` become one `skipped` run
43
45
  * (`missed`, at the first missed tick), the latest tick in the window gets its run (the unique
44
- * `(task_id, scheduled_for)` key makes a second insert a no-op), `next_run_at` moves to the next
46
+ * `(automation_id, scheduled_for)` key makes a second insert a no-op), `next_run_at` moves to the next
45
47
  * tick plus the task's jitter (or a `once` task ends, or one past its `expires_at`), and the same
46
- * transaction owes `sched-fire-<taskRunId>` (transactional outbox spec §8.1), so a written tick is
48
+ * transaction owes `automation-fire-<taskRunId>` (transactional outbox spec §8.1), so a written tick is
47
49
  * never left unfired and the scan needs no repair of lost fire jobs (a fire delivered too late
48
- * marks its tick missed itself, `ScheduledTaskFirer`), and the run's unfired settle check (a fire
50
+ * marks its tick missed itself, `AutomationFirer`), and the run's unfired settle check (a fire
49
51
  * job that failed for good before its claim: the tick is missed, `job-ids.ts`). A task whose stored
50
52
  * trigger the schedule math cannot evaluate is paused (`invalid_schedule`) instead of failing the
51
- * scan; a database error fails the pass (the next minute retries) and pauses nothing.
53
+ * scan; a database error fails the pass (the next minute retries) and pauses nothing. An event
54
+ * automation past its `expires_at` (it has no tick to be due at) ends the same way, `expired`, in
55
+ * one transaction per scan (the dispatcher already passes it over).
52
56
  */
53
- let ScheduledTaskScanJob = class ScheduledTaskScanJob {
57
+ let AutomationScanJob = class AutomationScanJob {
54
58
  kdb;
55
59
  txHost;
56
60
  config;
@@ -86,15 +90,24 @@ let ScheduledTaskScanJob = class ScheduledTaskScanJob {
86
90
  if (!(err instanceof TaskScanFailed))
87
91
  throw err;
88
92
  // one task that cannot be advanced must not hold the others back every minute
89
- this.log.error("scheduled task cannot be advanced; paused", {
93
+ this.log.error("automation cannot be advanced; paused", {
90
94
  taskId: err.taskId,
91
95
  err: err.cause,
92
96
  });
93
97
  await this.quarantine(err.taskId);
94
98
  }
95
99
  }
100
+ await this.endExpiredEvents(now);
96
101
  return total;
97
102
  }
103
+ /** Ends the event automations past their expiry (see the class); returns how many. */
104
+ async endExpiredEvents(now) {
105
+ const t = this.db;
106
+ const expired = await this.store.lockExpiredEvent(t, now, MAX_TASKS);
107
+ for (const task of expired)
108
+ await this.store.updateTask(t, task.id, EXPIRED);
109
+ return expired.length;
110
+ }
98
111
  /**
99
112
  * One due task in its own transaction (a task whose trigger cannot be evaluated rolls back alone
100
113
  * and is paused, so it cannot block the others): locked with `SKIP LOCKED`, so replicas take
@@ -107,13 +120,13 @@ let ScheduledTaskScanJob = class ScheduledTaskScanJob {
107
120
  return false;
108
121
  let s = settings.get(task.orgId);
109
122
  if (s === undefined) {
110
- s = await readScheduleSettings(t, this.config, task.orgId);
123
+ s = await readAutomationSettings(t, this.config, task.orgId);
111
124
  settings.set(task.orgId, s);
112
125
  }
113
126
  const fired = await this.advance(t, task, now, s.catchUpWindowMinutes);
114
127
  if (fired !== null) {
115
- await oweSchedFire(this.outbox, fired.id, task.orgId);
116
- await oweSchedSettleUnfired(this.outbox, fired.id, task.orgId, fired.scheduledFor, s.catchUpWindowMinutes);
128
+ await oweAutomationFire(this.outbox, fired.id, task.orgId);
129
+ await oweAutomationSettleUnfired(this.outbox, fired.id, task.orgId, fired.scheduledFor, s.catchUpWindowMinutes);
117
130
  }
118
131
  return true;
119
132
  }
@@ -161,29 +174,32 @@ let ScheduledTaskScanJob = class ScheduledTaskScanJob {
161
174
  const patch = step.end === "done"
162
175
  ? { status: "ended", nextRunAt: null }
163
176
  : step.end === "expired"
164
- ? { status: "ended", pauseReason: "expired", nextRunAt: null }
177
+ ? EXPIRED
165
178
  : { nextRunAt: step.nextRunAt };
166
179
  await this.store.updateTask(t, task.id, patch);
167
180
  return fired;
168
181
  }
169
182
  };
170
183
  __decorate([
171
- LockedCron("* * * * *", { name: SCHED_SCAN_JOB })
172
- ], ScheduledTaskScanJob.prototype, "scan", null);
184
+ LockedCron("* * * * *", { name: AUTOMATION_SCAN_JOB })
185
+ ], AutomationScanJob.prototype, "scan", null);
186
+ __decorate([
187
+ Transactional()
188
+ ], AutomationScanJob.prototype, "endExpiredEvents", null);
173
189
  __decorate([
174
190
  Transactional()
175
- ], ScheduledTaskScanJob.prototype, "scanOne", null);
191
+ ], AutomationScanJob.prototype, "scanOne", null);
176
192
  __decorate([
177
193
  Transactional()
178
- ], ScheduledTaskScanJob.prototype, "quarantine", null);
179
- ScheduledTaskScanJob = __decorate([
194
+ ], AutomationScanJob.prototype, "quarantine", null);
195
+ AutomationScanJob = __decorate([
180
196
  Injectable(),
181
197
  __param(0, Inject(KernelDb)),
182
198
  __param(1, Inject(TransactionHost)),
183
199
  __param(2, Inject(KernelConfigService)),
184
- __param(3, Inject(ScheduledTaskStore)),
200
+ __param(3, Inject(AutomationStore)),
185
201
  __param(4, Inject(OutboxService)),
186
202
  __param(5, Inject(LockService)),
187
203
  __param(6, Inject(KERNEL_LOGGER))
188
- ], ScheduledTaskScanJob);
189
- export { ScheduledTaskScanJob };
204
+ ], AutomationScanJob);
205
+ export { AutomationScanJob };
@@ -1,20 +1,24 @@
1
- import type { ScheduleTrigger } from "./types.js";
2
- export type TriggerError = "schedule.invalid_cron" | "schedule.invalid_time_zone" | "schedule.invalid_once_time" | "schedule.once_in_past";
3
- export declare function validateTrigger(t: ScheduleTrigger, now: Date): {
1
+ import type { AutomationTimeTrigger, AutomationTrigger } from "./types.js";
2
+ export type TriggerError = "automation.invalid_cron" | "automation.invalid_time_zone" | "automation.invalid_once_time" | "automation.once_in_past";
3
+ /** A person's time trigger is valid (spec §5); event triggers are validated elsewhere. */
4
+ export declare function validateTrigger(t: AutomationTimeTrigger, now: Date): {
4
5
  ok: true;
5
6
  } | {
6
7
  ok: false;
7
8
  code: TriggerError;
8
9
  };
9
- /** The first tick strictly after `after` (before jitter); null for a past once task. */
10
- export declare function nextTick(t: ScheduleTrigger, after: Date): Date | null;
10
+ /**
11
+ * The first tick strictly after `after` (before jitter); null for a past once task and for an event
12
+ * trigger (it has no next run time, collaboration spec §4.1).
13
+ */
14
+ export declare function nextTick(t: AutomationTrigger, after: Date): Date | null;
11
15
  /** The first tick strictly after `after` (before jitter) of one trigger; null when none. */
12
16
  export type Ticker = (after: Date) => Date | null;
13
17
  /**
14
18
  * The scanner's ticker for one trigger ({@link nextTick} without rebuilding its `CronTime`s per
15
19
  * call), for callers that walk the same trigger many times ({@link ticksIn}).
16
20
  */
17
- export declare function tickerOf(t: ScheduleTrigger): Ticker;
21
+ export declare function tickerOf(t: AutomationTrigger): Ticker;
18
22
  /**
19
23
  * The ticks in `(after, until]` (before jitter), at most `max`, from the same ticker
20
24
  * {@link nextTick} and {@link dueTicks} use, so a list of planned runs equals what the scanner
@@ -23,7 +27,7 @@ export declare function tickerOf(t: ScheduleTrigger): Ticker;
23
27
  * Costs one tick evaluation per tick returned, plus one when the walk reaches `until`. A caller
24
28
  * that walks one trigger in many windows passes a {@link tickerOf} it built once.
25
29
  */
26
- export declare function ticksIn(t: ScheduleTrigger | Ticker, after: Date, until: Date, max: number): {
30
+ export declare function ticksIn(t: AutomationTrigger | Ticker, after: Date, until: Date, max: number): {
27
31
  ticks: Date[];
28
32
  exhausted: boolean;
29
33
  };
@@ -45,15 +49,18 @@ export interface ScanStep {
45
49
  * Throws when the trigger cannot be evaluated.
46
50
  */
47
51
  export declare function scanStep(task: {
48
- trigger: ScheduleTrigger;
52
+ trigger: AutomationTrigger;
49
53
  nextRunAt: Date;
50
54
  jitterSeconds: number;
51
55
  expiresAt: Date | null;
52
56
  }, now: Date, catchUpWindowMinutes: number): ScanStep;
53
- /** The smallest gap, in minutes, among the next 50 fire times after `from`; null for once. */
54
- export declare function minGapMinutes(t: ScheduleTrigger, from: Date): number | null;
57
+ /**
58
+ * The smallest gap, in minutes, among the next 50 fire times after `from`; null for once and for
59
+ * an event trigger (no ticks).
60
+ */
61
+ export declare function minGapMinutes(t: AutomationTrigger, from: Date): number | null;
55
62
  /** A fixed per-task offset: `fnv1a32(id) mod min(floor(10 % of the interval), 300 s)`; once is 0. */
56
- export declare function jitterSeconds(taskId: string, t: ScheduleTrigger, from: Date): number;
63
+ export declare function jitterSeconds(taskId: string, t: AutomationTrigger, from: Date): number;
57
64
  /**
58
65
  * {@link jitterSeconds} from a gap already sampled ({@link minGapMinutes} of the same trigger and
59
66
  * time), so a caller that checked the interval does not walk the 50 ticks again; null gap is 0.
@@ -67,7 +74,7 @@ export declare function jitterForGap(taskId: string, gap: number | null): number
67
74
  * it holds a tick, then stepping forward inside it, so a month-long outage costs a handful of tick
68
75
  * computations, not thousands.
69
76
  */
70
- export declare function dueTicks(t: ScheduleTrigger, lastTick: Date, now: Date, catchUpWindowMinutes: number): {
77
+ export declare function dueTicks(t: AutomationTrigger, lastTick: Date, now: Date, catchUpWindowMinutes: number): {
71
78
  fire: Date | null;
72
79
  firstMissed: Date | null;
73
80
  };
@@ -85,22 +85,26 @@ function onceInstant(at, timeZone) {
85
85
  }
86
86
  return new Date(lo * 1000);
87
87
  }
88
+ /** A person's time trigger is valid (spec §5); event triggers are validated elsewhere. */
88
89
  export function validateTrigger(t, now) {
89
90
  if (!isTimeZone(t.timeZone))
90
- return { ok: false, code: "schedule.invalid_time_zone" };
91
+ return { ok: false, code: "automation.invalid_time_zone" };
91
92
  if (t.kind === "cron") {
92
93
  return cronTime(t.expr, t.timeZone)
93
94
  ? { ok: true }
94
- : { ok: false, code: "schedule.invalid_cron" };
95
+ : { ok: false, code: "automation.invalid_cron" };
95
96
  }
96
97
  const at = onceInstant(t.at, t.timeZone);
97
98
  if (!at)
98
- return { ok: false, code: "schedule.invalid_once_time" };
99
+ return { ok: false, code: "automation.invalid_once_time" };
99
100
  if (at.getTime() <= now.getTime())
100
- return { ok: false, code: "schedule.once_in_past" };
101
+ return { ok: false, code: "automation.once_in_past" };
101
102
  return { ok: true };
102
103
  }
103
- /** The first tick strictly after `after` (before jitter); null for a past once task. */
104
+ /**
105
+ * The first tick strictly after `after` (before jitter); null for a past once task and for an event
106
+ * trigger (it has no next run time, collaboration spec §4.1).
107
+ */
104
108
  export function nextTick(t, after) {
105
109
  return ticker(t)(after);
106
110
  }
@@ -134,6 +138,9 @@ function nextOrNull(search) {
134
138
  * (the gap sample, the catch-up enumeration) reuse one ticker instead of rebuilding per tick.
135
139
  */
136
140
  function ticker(t) {
141
+ // an event automation has no ticks: the time scanner never fires it
142
+ if (t.kind === "event")
143
+ return () => null;
137
144
  if (t.kind === "once") {
138
145
  const at = onceInstant(t.at, t.timeZone);
139
146
  return (after) => (at && at.getTime() > after.getTime() ? at : null);
@@ -213,9 +220,12 @@ export function scanStep(task, now, catchUpWindowMinutes) {
213
220
  function localWallClock(at, timeZone) {
214
221
  return Math.floor(wallOf(at.getTime(), timeZone) / 60000) * 60000;
215
222
  }
216
- /** The smallest gap, in minutes, among the next 50 fire times after `from`; null for once. */
223
+ /**
224
+ * The smallest gap, in minutes, among the next 50 fire times after `from`; null for once and for
225
+ * an event trigger (no ticks).
226
+ */
217
227
  export function minGapMinutes(t, from) {
218
- if (t.kind === "once")
228
+ if (t.kind !== "cron")
219
229
  return null;
220
230
  const next = ticker(t);
221
231
  let prev = next(from);