@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
@@ -2,7 +2,7 @@ import { type SandboxLimits } from "@capybara-hq/plugin-sdk";
2
2
  import { type OrgRole } from "../orgs/roles.js";
3
3
  import type { ResolvedTool } from "../tools/registry.js";
4
4
  /**
5
- * The one rule for what can be a scheduled task's grant (spec §7): the task form and
5
+ * The one rule for what can be an automation's grant (spec §7): the task form and
6
6
  * `addGrants`, a trial run's kept approvals and the unattended policy's `missing_grants` all ask
7
7
  * it. A plain module (no provider): the tool policy imports it.
8
8
  */
@@ -26,7 +26,7 @@ export function grantRefusalOf(toolKey, tool, ctx) {
26
26
  if (changesAgentSkills(toolKey)) {
27
27
  return {
28
28
  code: "not_grantable",
29
- message: `${toolKey} cannot be approved for a scheduled task: an unattended run never changes the agent's skills`,
29
+ message: `${toolKey} cannot be approved for an automation: an unattended run never changes the agent's skills`,
30
30
  };
31
31
  }
32
32
  if (!tool) {
@@ -35,7 +35,7 @@ export function grantRefusalOf(toolKey, tool, ctx) {
35
35
  if (toolKey !== tool.key) {
36
36
  return {
37
37
  code: "not_grantable",
38
- message: `${toolKey} is decided per call and cannot be approved in advance for a scheduled task`,
38
+ message: `${toolKey} is decided per call and cannot be approved in advance for an automation`,
39
39
  };
40
40
  }
41
41
  if (tool.requiredRole !== undefined && !roleAtLeast(ctx.role, tool.requiredRole)) {
@@ -74,7 +74,7 @@ export function networkGrantRefusal(host, ctx) {
74
74
  if (host.startsWith("*.") || validateAllowHost(host).length > 0) {
75
75
  return {
76
76
  code: "not_grantable",
77
- message: `${host} cannot be approved for a scheduled task: give one exact domain name (no wildcard, no IP address or local name)`,
77
+ message: `${host} cannot be approved for an automation: give one exact domain name (no wildcard, no IP address or local name)`,
78
78
  };
79
79
  }
80
80
  if (!orgAllows(host, ctx.limits)) {
@@ -137,7 +137,7 @@ export function gitGrantRefusal(key, ctx) {
137
137
  if (normalizeGitRepo(repo) !== repo) {
138
138
  return {
139
139
  code: "not_grantable",
140
- message: `${key} cannot be approved for a scheduled task: name one repository as git:push:<owner>/<repo>`,
140
+ message: `${key} cannot be approved for an automation: name one repository as git:push:<owner>/<repo>`,
141
141
  };
142
142
  }
143
143
  return null;
@@ -157,7 +157,7 @@ export function tierGrantRefusal(key) {
157
157
  return null;
158
158
  return {
159
159
  code: "not_grantable",
160
- message: `${key} cannot be approved for a scheduled task: sandbox levels are no longer task grants`,
160
+ message: `${key} cannot be approved for an automation: sandbox levels are no longer task grants`,
161
161
  };
162
162
  }
163
163
  /**
@@ -0,0 +1,113 @@
1
+ import type { OutboxService } from "../infra/outbox/outbox.service.js";
2
+ /** The automations' jobs (a leaf module: type imports only). */
3
+ /**
4
+ * The once-a-minute `@LockedCron` that turns due tasks into task runs (spec §6); its name enqueued
5
+ * on the maintenance queue runs one scan (`ScheduledRuns.runNow`).
6
+ */
7
+ export declare const AUTOMATION_SCAN_JOB = "automation-scan";
8
+ /**
9
+ * The `@LockedCron` that deletes old trigger events (`automations.eventRetentionDays`) and owes
10
+ * the coalesce job of a window whose own job was lost (collaboration spec §4.7).
11
+ */
12
+ export declare const TRIGGER_EVENT_SWEEP_JOB = "trigger-event-sweep";
13
+ /** The one-off job that checks and starts one task run, on `cap-kernel-maintenance`. */
14
+ export declare const AUTOMATION_FIRE_JOB = "automation-fire";
15
+ /** The data of a {@link AUTOMATION_FIRE_JOB}. */
16
+ export interface AutomationFireJobData {
17
+ taskRunId: string;
18
+ }
19
+ /** The fire job's id: `automation-fire-<taskRunId>` (no `:`, task run ids are UUIDs). */
20
+ export declare const automationFireJobId: (taskRunId: string) => string;
21
+ /**
22
+ * Owes the fire job of task run `taskRunId` in the transaction in context (transactional outbox
23
+ * spec §8.1): the transaction that writes a pending task run (the scan's tick, a person's "run
24
+ * now") owes its fire, so a tick is never left unfired. The job's options are its outbox registry
25
+ * entry's; the fire is idempotent on the task run's status.
26
+ */
27
+ export declare function oweAutomationFire(outbox: Pick<OutboxService, "add">, taskRunId: string, orgId: string): Promise<boolean>;
28
+ /**
29
+ * The delayed job that settles a task run left pending (ruling R26, fix round 1), on
30
+ * `cap-kernel-maintenance`. Two kinds:
31
+ * - the claimed check, owed by the fire job's claim: the run tracker links, settles or releases a
32
+ * run claimed but never started (`automation-settle-<taskRunId>`, then `-<check>`);
33
+ * - the unfired check, owed with the task run itself (the scan's tick, "run now"): a run its fire
34
+ * job never claimed (the job failed for good before its claim) is skipped, `missed` for a tick,
35
+ * `removed` for a "run now", so it never blocks the task's later ticks as an overlap
36
+ * (`automation-settle-<taskRunId>-unfired`).
37
+ */
38
+ export declare const AUTOMATION_SETTLE_JOB = "automation-settle";
39
+ /**
40
+ * The data of a {@link AUTOMATION_SETTLE_JOB}: the claimed check (`check` counts the checks before this
41
+ * one) or the unfired check.
42
+ */
43
+ export type AutomationSettleJobData = {
44
+ taskRunId: string;
45
+ check: number;
46
+ } | {
47
+ taskRunId: string;
48
+ unfired: true;
49
+ };
50
+ /**
51
+ * The first claimed check: 10 minutes after the claim, when the start's retries (seconds) are long
52
+ * over and the run tracker's start grace (`START_GRACE_MS`, 5 minutes) has passed, so a run that
53
+ * left no trace is released at once. Also the unfired check's delay after a "run now".
54
+ */
55
+ export declare const AUTOMATION_SETTLE_AFTER_MS: number;
56
+ /**
57
+ * A claimed run still in flight at a check (its item queued, its message posted and not yet taken
58
+ * by a run) is checked again hourly. The chain ends with the first check that finds the run
59
+ * started, ended or released: the queued item is consumed or removed, the message taken by a run.
60
+ * A chain past {@link AUTOMATION_SETTLE_LONG_CHECKS} checks (a week) is logged as a warning, once.
61
+ */
62
+ export declare const AUTOMATION_SETTLE_RECHECK_MS: number;
63
+ /** A week of hourly checks: the claimed check warns at this one (a run in flight that long). */
64
+ export declare const AUTOMATION_SETTLE_LONG_CHECKS = 168;
65
+ /**
66
+ * How long past the org's catch-up window a tick's fire may come before the tick is missed (the
67
+ * fire job's own rule, and when a tick's unfired check runs): the scan fires a tick still inside
68
+ * the window, and its fire job follows within seconds.
69
+ */
70
+ export declare const AUTOMATION_LATE_FIRE_SLACK_MS: number;
71
+ /** The claimed check's id: `automation-settle-<taskRunId>`, then `-<check>` for the later checks. */
72
+ export declare const automationSettleJobId: (taskRunId: string, check: number) => string;
73
+ /** The unfired check's id: `automation-settle-<taskRunId>-unfired`. */
74
+ export declare const automationSettleUnfiredJobId: (taskRunId: string) => string;
75
+ /**
76
+ * Owes claimed check number `check` of task run `taskRunId` in the transaction in context, due
77
+ * `after` milliseconds from now.
78
+ */
79
+ export declare function oweAutomationSettle(outbox: Pick<OutboxService, "add">, taskRunId: string, orgId: string, check: number, after: number): Promise<boolean>;
80
+ /**
81
+ * Owes the unfired check of task run `taskRunId` in the transaction that writes the run: for a
82
+ * tick of the schedule (`catchUpWindowMinutes` given) when the fire job would itself call the
83
+ * tick missed (its tick plus the window plus {@link AUTOMATION_LATE_FIRE_SLACK_MS}, at least
84
+ * {@link AUTOMATION_SETTLE_AFTER_MS} on); for a "run now" (null) {@link AUTOMATION_SETTLE_AFTER_MS} on.
85
+ */
86
+ export declare function oweAutomationSettleUnfired(outbox: Pick<OutboxService, "add">, taskRunId: string, orgId: string,
87
+ /** The run's tick; null for an event run (no tick: settled like a "run now"). */
88
+ scheduledFor: Date | null, catchUpWindowMinutes: number | null): Promise<boolean>;
89
+ /**
90
+ * The one-off job that routes one trigger event to the automations it fires (collaboration spec
91
+ * §4.2), on `cap-kernel-maintenance`, owed by the transaction that stores the event.
92
+ */
93
+ export declare const TRIGGER_DISPATCH_JOB = "trigger-dispatch";
94
+ /** The data of a {@link TRIGGER_DISPATCH_JOB}. */
95
+ export interface TriggerDispatchJobData {
96
+ orgId: string;
97
+ eventId: string;
98
+ }
99
+ /** The dispatch job's id: `trigger-dispatch-<eventId>` (no `:`, event ids are UUIDs). */
100
+ export declare const triggerDispatchJobId: (eventId: string) => string;
101
+ /**
102
+ * The delayed job that turns one window of an event automation's events for one subject into one
103
+ * run (collaboration spec §4.7), on `cap-kernel-maintenance`, owed by the dispatch that opens the
104
+ * window: the first event delivered to the (automation, subject) pair while none waits for a run.
105
+ */
106
+ export declare const AUTOMATION_COALESCE_JOB = "automation-coalesce";
107
+ /** The data of a {@link AUTOMATION_COALESCE_JOB}. */
108
+ export interface AutomationCoalesceJobData {
109
+ orgId: string;
110
+ automationId: string;
111
+ /** `subjectKey(subject)` of the events (`automation_event_deliveries.subject_key`). */
112
+ subjectKey: string;
113
+ }
@@ -0,0 +1,117 @@
1
+ /** The automations' jobs (a leaf module: type imports only). */
2
+ /**
3
+ * The once-a-minute `@LockedCron` that turns due tasks into task runs (spec §6); its name enqueued
4
+ * on the maintenance queue runs one scan (`ScheduledRuns.runNow`).
5
+ */
6
+ export const AUTOMATION_SCAN_JOB = "automation-scan";
7
+ /**
8
+ * The `@LockedCron` that deletes old trigger events (`automations.eventRetentionDays`) and owes
9
+ * the coalesce job of a window whose own job was lost (collaboration spec §4.7).
10
+ */
11
+ export const TRIGGER_EVENT_SWEEP_JOB = "trigger-event-sweep";
12
+ /** The one-off job that checks and starts one task run, on `cap-kernel-maintenance`. */
13
+ export const AUTOMATION_FIRE_JOB = "automation-fire";
14
+ /** The fire job's id: `automation-fire-<taskRunId>` (no `:`, task run ids are UUIDs). */
15
+ export const automationFireJobId = (taskRunId) => `${AUTOMATION_FIRE_JOB}-${taskRunId}`;
16
+ /**
17
+ * Owes the fire job of task run `taskRunId` in the transaction in context (transactional outbox
18
+ * spec §8.1): the transaction that writes a pending task run (the scan's tick, a person's "run
19
+ * now") owes its fire, so a tick is never left unfired. The job's options are its outbox registry
20
+ * entry's; the fire is idempotent on the task run's status.
21
+ */
22
+ export function oweAutomationFire(outbox, taskRunId, orgId) {
23
+ return outbox.add({
24
+ queue: "cap-kernel-maintenance",
25
+ name: AUTOMATION_FIRE_JOB,
26
+ jobId: automationFireJobId(taskRunId),
27
+ data: { taskRunId },
28
+ orgId,
29
+ });
30
+ }
31
+ /**
32
+ * The delayed job that settles a task run left pending (ruling R26, fix round 1), on
33
+ * `cap-kernel-maintenance`. Two kinds:
34
+ * - the claimed check, owed by the fire job's claim: the run tracker links, settles or releases a
35
+ * run claimed but never started (`automation-settle-<taskRunId>`, then `-<check>`);
36
+ * - the unfired check, owed with the task run itself (the scan's tick, "run now"): a run its fire
37
+ * job never claimed (the job failed for good before its claim) is skipped, `missed` for a tick,
38
+ * `removed` for a "run now", so it never blocks the task's later ticks as an overlap
39
+ * (`automation-settle-<taskRunId>-unfired`).
40
+ */
41
+ export const AUTOMATION_SETTLE_JOB = "automation-settle";
42
+ /**
43
+ * The first claimed check: 10 minutes after the claim, when the start's retries (seconds) are long
44
+ * over and the run tracker's start grace (`START_GRACE_MS`, 5 minutes) has passed, so a run that
45
+ * left no trace is released at once. Also the unfired check's delay after a "run now".
46
+ */
47
+ export const AUTOMATION_SETTLE_AFTER_MS = 10 * 60_000;
48
+ /**
49
+ * A claimed run still in flight at a check (its item queued, its message posted and not yet taken
50
+ * by a run) is checked again hourly. The chain ends with the first check that finds the run
51
+ * started, ended or released: the queued item is consumed or removed, the message taken by a run.
52
+ * A chain past {@link AUTOMATION_SETTLE_LONG_CHECKS} checks (a week) is logged as a warning, once.
53
+ */
54
+ export const AUTOMATION_SETTLE_RECHECK_MS = 60 * 60_000;
55
+ /** A week of hourly checks: the claimed check warns at this one (a run in flight that long). */
56
+ export const AUTOMATION_SETTLE_LONG_CHECKS = 168;
57
+ /**
58
+ * How long past the org's catch-up window a tick's fire may come before the tick is missed (the
59
+ * fire job's own rule, and when a tick's unfired check runs): the scan fires a tick still inside
60
+ * the window, and its fire job follows within seconds.
61
+ */
62
+ export const AUTOMATION_LATE_FIRE_SLACK_MS = 10 * 60_000;
63
+ /** The claimed check's id: `automation-settle-<taskRunId>`, then `-<check>` for the later checks. */
64
+ export const automationSettleJobId = (taskRunId, check) => check === 0
65
+ ? `${AUTOMATION_SETTLE_JOB}-${taskRunId}`
66
+ : `${AUTOMATION_SETTLE_JOB}-${taskRunId}-${check}`;
67
+ /** The unfired check's id: `automation-settle-<taskRunId>-unfired`. */
68
+ export const automationSettleUnfiredJobId = (taskRunId) => `${AUTOMATION_SETTLE_JOB}-${taskRunId}-unfired`;
69
+ /**
70
+ * Owes claimed check number `check` of task run `taskRunId` in the transaction in context, due
71
+ * `after` milliseconds from now.
72
+ */
73
+ export function oweAutomationSettle(outbox, taskRunId, orgId, check, after) {
74
+ return outbox.add({
75
+ queue: "cap-kernel-maintenance",
76
+ name: AUTOMATION_SETTLE_JOB,
77
+ jobId: automationSettleJobId(taskRunId, check),
78
+ data: { taskRunId, check },
79
+ runAt: new Date(Date.now() + after),
80
+ orgId,
81
+ });
82
+ }
83
+ /**
84
+ * Owes the unfired check of task run `taskRunId` in the transaction that writes the run: for a
85
+ * tick of the schedule (`catchUpWindowMinutes` given) when the fire job would itself call the
86
+ * tick missed (its tick plus the window plus {@link AUTOMATION_LATE_FIRE_SLACK_MS}, at least
87
+ * {@link AUTOMATION_SETTLE_AFTER_MS} on); for a "run now" (null) {@link AUTOMATION_SETTLE_AFTER_MS} on.
88
+ */
89
+ export function oweAutomationSettleUnfired(outbox, taskRunId, orgId,
90
+ /** The run's tick; null for an event run (no tick: settled like a "run now"). */
91
+ scheduledFor, catchUpWindowMinutes) {
92
+ const soonest = Date.now() + AUTOMATION_SETTLE_AFTER_MS;
93
+ const at = catchUpWindowMinutes === null || scheduledFor === null
94
+ ? soonest
95
+ : Math.max(soonest, scheduledFor.getTime() + catchUpWindowMinutes * 60_000 + AUTOMATION_LATE_FIRE_SLACK_MS);
96
+ return outbox.add({
97
+ queue: "cap-kernel-maintenance",
98
+ name: AUTOMATION_SETTLE_JOB,
99
+ jobId: automationSettleUnfiredJobId(taskRunId),
100
+ data: { taskRunId, unfired: true },
101
+ runAt: new Date(at),
102
+ orgId,
103
+ });
104
+ }
105
+ /**
106
+ * The one-off job that routes one trigger event to the automations it fires (collaboration spec
107
+ * §4.2), on `cap-kernel-maintenance`, owed by the transaction that stores the event.
108
+ */
109
+ export const TRIGGER_DISPATCH_JOB = "trigger-dispatch";
110
+ /** The dispatch job's id: `trigger-dispatch-<eventId>` (no `:`, event ids are UUIDs). */
111
+ export const triggerDispatchJobId = (eventId) => `${TRIGGER_DISPATCH_JOB}-${eventId}`;
112
+ /**
113
+ * The delayed job that turns one window of an event automation's events for one subject into one
114
+ * run (collaboration spec §4.7), on `cap-kernel-maintenance`, owed by the dispatch that opens the
115
+ * window: the first event delivered to the (automation, subject) pair while none waits for a run.
116
+ */
117
+ export const AUTOMATION_COALESCE_JOB = "automation-coalesce";
@@ -1,9 +1,9 @@
1
1
  import type { KernelSchemaDb } from "../db/kernel-schema.js";
2
- import type { SchedulePauseReason } from "./types.js";
2
+ import type { AutomationPauseReason } from "./types.js";
3
3
  /**
4
4
  * Pauses an active live task for `reason` in the caller's transaction `t` (the fire job, the run
5
5
  * tracker, the delivery path); `by` is the account that caused it, null for the kernel. A task
6
6
  * already paused or ended keeps its state and reason. A plain function so the run tracker, which
7
- * the runtime imports, needs no service of the schedules domain.
7
+ * the runtime imports, needs no service of the automations domain.
8
8
  */
9
- export declare function pauseTaskIn(t: KernelSchemaDb, taskId: string, reason: SchedulePauseReason, by: string | null): Promise<void>;
9
+ export declare function pauseTaskIn(t: KernelSchemaDb, taskId: string, reason: AutomationPauseReason, by: string | null): Promise<void>;
@@ -4,13 +4,13 @@ import { audit } from "../identity/audit.js";
4
4
  * Pauses an active live task for `reason` in the caller's transaction `t` (the fire job, the run
5
5
  * tracker, the delivery path); `by` is the account that caused it, null for the kernel. A task
6
6
  * already paused or ended keeps its state and reason. A plain function so the run tracker, which
7
- * the runtime imports, needs no service of the schedules domain.
7
+ * the runtime imports, needs no service of the automations domain.
8
8
  */
9
9
  // org-filter: only kernel paths call it (fire job, run tracker, scan job, channel outbound), each
10
10
  // with the task id of a task row or task run row it already holds, never a caller-supplied id
11
11
  export async function pauseTaskIn(t, taskId, reason, by) {
12
12
  const row = await t
13
- .updateTable("scheduled_tasks")
13
+ .updateTable("automations")
14
14
  .set({
15
15
  status: "paused",
16
16
  pause_reason: reason,
@@ -28,7 +28,7 @@ export async function pauseTaskIn(t, taskId, reason, by) {
28
28
  await audit(t, {
29
29
  actorAccountId: by,
30
30
  orgId: row.org_id,
31
- action: "schedule.paused",
31
+ action: "automation.paused",
32
32
  target: taskId,
33
33
  detail: { reason, creator: row.account_id },
34
34
  });
@@ -21,19 +21,19 @@ export declare const START_GRACE_MS: number;
21
21
  * {@link inFlightIn} is the overlap check's view of the task's previous run: it settles a run whose
22
22
  * end was missed and releases one whose queued message is gone.
23
23
  */
24
- export declare class ScheduledTaskRunTracker {
24
+ export declare class AutomationRunTracker {
25
25
  private readonly kdb;
26
26
  readonly txHost: TransactionHost;
27
27
  private readonly config;
28
- /** Owes the task owner's push (`schedules`) with every settle. */
28
+ /** Owes the task owner's push (`automations`) with every settle. */
29
29
  private readonly push;
30
30
  constructor(kdb: KernelDb, txHost: TransactionHost, config: Pick<KernelConfigService, "get">,
31
- /** Owes the task owner's push (`schedules`) with every settle. */
32
- push: Pick<PushOwed, "oweScheduleRun">);
31
+ /** Owes the task owner's push (`automations`) with every settle. */
32
+ push: Pick<PushOwed, "oweAutomationRun">);
33
33
  private get db();
34
34
  /**
35
35
  * The kernel run `runId` ended with `outcome`: the task run it was started for (the run its
36
- * message triggered, `scheduled_task_runs.run_id`) takes the outcome. A sub-agent or wake run
36
+ * message triggered, `automation_runs.run_id`) takes the outcome. A sub-agent or wake run
37
37
  * that inherited the marker is not the task run's own and changes nothing.
38
38
  */
39
39
  onRunFinished(runId: string, outcome: RunOutcome, error?: string): Promise<void>;
@@ -68,17 +68,28 @@ export declare class ScheduledTaskRunTracker {
68
68
  */
69
69
  export declare function linkStartedRunIn(t: KernelSchemaDb, taskRunId: string, runId: string, conversationId: string): Promise<void>;
70
70
  /**
71
- * A person removed, edited or sent the queued item that carried `schedule` (the item's stored
72
- * marker, or null): its task run will never run as the task's, so it becomes `skipped`
71
+ * The automation run a queued item's stored marker names: its schedule marker's `taskRunId`, or
72
+ * its event marker's `automationRunId` (collaboration spec §4.6); undefined for a person's item.
73
+ */
74
+ export declare function queuedAutomationRunId(item: {
75
+ schedule: unknown;
76
+ automation_event: unknown;
77
+ }): string | undefined;
78
+ /**
79
+ * A person removed, edited or sent the queued item that carried a schedule or event marker (the
80
+ * item's stored columns): its task run will never run as the task's, so it becomes `skipped`
73
81
  * (`removed`) in the caller's transaction, and the next tick is not held by the overlap check.
74
82
  */
75
- export declare function releaseQueuedTaskRunIn(t: KernelSchemaDb, schedule: unknown): Promise<void>;
83
+ export declare function releaseQueuedTaskRunIn(t: KernelSchemaDb, item: {
84
+ schedule: unknown;
85
+ automation_event: unknown;
86
+ }): Promise<void>;
76
87
  /**
77
88
  * Locks a task's row (deleted or not) in the caller's transaction. Every path that locks a task
78
89
  * run and the task takes the task row first: the fire job's claim, the run tracker, the scan's
79
90
  * repair (a run finishing while the next tick's claim checks overlap must not deadlock).
80
91
  */
81
92
  export declare function lockTaskRow(t: KernelSchemaDb, taskId: string): Promise<void>;
82
- /** The run tracker alone: the runtime (`RunFinish`) imports it without the schedules service. */
83
- export declare class ScheduledTaskTrackerModule {
93
+ /** The run tracker alone: the runtime (`RunFinish`) imports it without the automations service. */
94
+ export declare class AutomationTrackerModule {
84
95
  }