@capybara-hq/kernel 0.1.0-rc.20 → 0.1.0-rc.22

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 (247) hide show
  1. package/bootstrap.json +10 -1
  2. package/dist/agents/admin-agents.d.ts +16 -3
  3. package/dist/agents/admin-agents.js +65 -7
  4. package/dist/agents/agents.schemas.d.ts +24 -6
  5. package/dist/agents/agents.service.d.ts +4 -3
  6. package/dist/agents/agents.service.js +39 -26
  7. package/dist/agents/definition.d.ts +44 -6
  8. package/dist/agents/definition.js +86 -18
  9. package/dist/agents/from-template.d.ts +6 -3
  10. package/dist/agents/from-template.js +57 -44
  11. package/dist/agents/org-templates.js +97 -41
  12. package/dist/agents/templates.d.ts +6 -0
  13. package/dist/agents/templates.js +15 -1
  14. package/dist/catalog/admin-catalog.controller.d.ts +2 -4
  15. package/dist/catalog/admin-catalog.controller.js +2 -6
  16. package/dist/catalog/catalog.module.js +3 -0
  17. package/dist/catalog/claude/report.d.ts +9 -2
  18. package/dist/catalog/claude/report.js +1 -0
  19. package/dist/catalog/claude/translate.js +1 -1
  20. package/dist/catalog/component-promotion.js +1 -2
  21. package/dist/catalog/component-state.d.ts +13 -1
  22. package/dist/catalog/component-state.js +14 -5
  23. package/dist/catalog/marketplaces.service.d.ts +1 -1
  24. package/dist/catalog/marketplaces.service.js +2 -1
  25. package/dist/catalog/org-catalog.controller.d.ts +13 -3
  26. package/dist/catalog/org-catalog.controller.js +26 -4
  27. package/dist/catalog/org-catalog.schemas.d.ts +13 -0
  28. package/dist/catalog/org-catalog.schemas.js +34 -0
  29. package/dist/catalog/org-plugin-uploads.controller.js +0 -1
  30. package/dist/catalog/org-plugin-uploads.d.ts +0 -1
  31. package/dist/catalog/org-plugin-uploads.js +0 -3
  32. package/dist/catalog/org-plugin-uploads.schemas.d.ts +0 -1
  33. package/dist/catalog/org-plugin-uploads.schemas.js +0 -2
  34. package/dist/catalog/platform-components.d.ts +0 -1
  35. package/dist/catalog/platform-components.js +3 -8
  36. package/dist/catalog/plugin-import.d.ts +0 -8
  37. package/dist/catalog/plugin-import.js +4 -35
  38. package/dist/catalog/plugin-install.d.ts +2 -2
  39. package/dist/catalog/plugin-install.js +2 -2
  40. package/dist/catalog/plugin-package.d.ts +7 -0
  41. package/dist/catalog/plugin-package.js +27 -1
  42. package/dist/catalog/plugin-upgrade.d.ts +5 -6
  43. package/dist/catalog/plugin-upgrade.js +5 -23
  44. package/dist/catalog/requests.service.d.ts +66 -10
  45. package/dist/catalog/requests.service.js +196 -15
  46. package/dist/channels/actions.d.ts +2 -0
  47. package/dist/channels/actions.js +19 -4
  48. package/dist/channels/cards.d.ts +16 -2
  49. package/dist/channels/cards.js +40 -7
  50. package/dist/channels/channels.module.js +3 -0
  51. package/dist/channels/outbound.d.ts +22 -1
  52. package/dist/channels/outbound.js +116 -7
  53. package/dist/channels/phrases.d.ts +25 -0
  54. package/dist/channels/phrases.js +19 -0
  55. package/dist/channels/threads.d.ts +12 -0
  56. package/dist/channels/threads.js +34 -0
  57. package/dist/config/schema.d.ts +23 -1
  58. package/dist/config/schema.js +105 -5
  59. package/dist/conversations/conversations.service.d.ts +42 -9
  60. package/dist/conversations/conversations.service.js +57 -25
  61. package/dist/conversations/events.d.ts +106 -11
  62. package/dist/conversations/events.js +121 -18
  63. package/dist/conversations/message-context.d.ts +6 -3
  64. package/dist/conversations/message-context.js +14 -10
  65. package/dist/conversations/queue.d.ts +15 -2
  66. package/dist/conversations/queue.js +22 -3
  67. package/dist/conversations/queue.service.d.ts +12 -6
  68. package/dist/conversations/queue.service.js +36 -13
  69. package/dist/db/kernel-schema.d.ts +105 -3
  70. package/dist/devices/conversation-devices.d.ts +8 -1
  71. package/dist/devices/conversation-devices.js +8 -0
  72. package/dist/devices/devices.controller.d.ts +21 -4
  73. package/dist/devices/devices.controller.js +46 -8
  74. package/dist/devices/devices.schemas.d.ts +9 -1
  75. package/dist/devices/devices.schemas.js +11 -3
  76. package/dist/devices/devices.service.d.ts +176 -4
  77. package/dist/devices/devices.service.js +341 -6
  78. package/dist/devices/dto.d.ts +56 -3
  79. package/dist/devices/dto.js +51 -1
  80. package/dist/devices/public-suffix.d.ts +6 -0
  81. package/dist/devices/public-suffix.js +79 -0
  82. package/dist/errors.d.ts +46 -5
  83. package/dist/errors.js +46 -5
  84. package/dist/evals/reconstruct.d.ts +18 -13
  85. package/dist/evals/reconstruct.js +50 -36
  86. package/dist/evals/recorded-tools.d.ts +7 -7
  87. package/dist/evals/recorded-tools.js +4 -3
  88. package/dist/evals/trajectory.d.ts +6 -1
  89. package/dist/evals/trajectory.js +7 -0
  90. package/dist/extensions/bootstrap.d.ts +49 -10
  91. package/dist/extensions/bootstrap.js +104 -27
  92. package/dist/extensions/package.js +2 -2
  93. package/dist/http/api.module.js +5 -0
  94. package/dist/inbox/inbox.module.js +2 -1
  95. package/dist/inbox/inbox.service.d.ts +19 -4
  96. package/dist/inbox/inbox.service.js +14 -3
  97. package/dist/infra/config/kernel-config.service.js +11 -0
  98. package/dist/infra/events/kernel-events.d.ts +2 -1
  99. package/dist/lifecycle/kernel-lifecycle.d.ts +5 -1
  100. package/dist/lifecycle/kernel-lifecycle.js +16 -4
  101. package/dist/local-devices/device-policy.service.d.ts +65 -0
  102. package/dist/local-devices/device-policy.service.js +217 -0
  103. package/dist/local-devices/local-device-gateway.js +4 -1
  104. package/dist/local-devices/local-device-provider.d.ts +40 -3
  105. package/dist/local-devices/local-device-provider.js +109 -7
  106. package/dist/local-devices/local-devices.module.d.ts +2 -1
  107. package/dist/local-devices/local-devices.module.js +19 -3
  108. package/dist/local-devices/machines.d.ts +14 -3
  109. package/dist/local-devices/machines.js +41 -3
  110. package/dist/local-devices/network-grants.d.ts +104 -0
  111. package/dist/local-devices/network-grants.js +288 -0
  112. package/dist/local-devices/policy-summary.d.ts +20 -0
  113. package/dist/local-devices/policy-summary.js +63 -0
  114. package/dist/orgs/orgs.module.js +4 -10
  115. package/dist/orgs/roles.d.ts +1 -1
  116. package/dist/orgs/roles.js +4 -0
  117. package/dist/orgs/settings.controller.js +2 -1
  118. package/dist/orgs/settings.service.d.ts +164 -12
  119. package/dist/orgs/settings.service.js +212 -24
  120. package/dist/platform/exclusions.js +11 -1
  121. package/dist/platform/operation.js +4 -0
  122. package/dist/platform/ops/admin-items.ops.js +1 -1
  123. package/dist/platform/ops/agent-skills.ops.js +2 -2
  124. package/dist/platform/ops/agent-templates.ops.js +2 -2
  125. package/dist/platform/ops/agents.ops.js +11 -15
  126. package/dist/platform/ops/devices.ops.js +3 -1
  127. package/dist/platform/ops/inbox.ops.js +19 -0
  128. package/dist/platform/ops/org-settings.ops.js +14 -5
  129. package/dist/platform/ops/platform.ops.d.ts +9 -1
  130. package/dist/platform/ops/platform.ops.js +34 -12
  131. package/dist/platform/ops/requests.ops.js +3 -2
  132. package/dist/platform/ops/schedules.ops.d.ts +21 -0
  133. package/dist/platform/ops/schedules.ops.js +470 -0
  134. package/dist/platform/ops/skills.ops.js +3 -3
  135. package/dist/platform/platform-ops.module.d.ts +2 -1
  136. package/dist/platform/platform-ops.module.js +5 -0
  137. package/dist/platform/route-schemas.js +3 -0
  138. package/dist/roles/worker.module.js +3 -0
  139. package/dist/runtime/context/build.js +13 -4
  140. package/dist/runtime/context/compaction.js +6 -3
  141. package/dist/runtime/context/device-paths.d.ts +43 -21
  142. package/dist/runtime/context/device-paths.js +104 -21
  143. package/dist/runtime/context/run-context.d.ts +9 -0
  144. package/dist/runtime/context/run-context.js +8 -0
  145. package/dist/runtime/context/skills.d.ts +14 -1
  146. package/dist/runtime/context/skills.js +36 -5
  147. package/dist/runtime/maintenance.d.ts +4 -2
  148. package/dist/runtime/maintenance.js +16 -5
  149. package/dist/runtime/run-finish.d.ts +6 -1
  150. package/dist/runtime/run-finish.js +16 -2
  151. package/dist/runtime/run-queue.js +21 -2
  152. package/dist/runtime/run-worker.js +14 -33
  153. package/dist/runtime/runtime.module.js +3 -0
  154. package/dist/runtime/subagents/definition.d.ts +32 -14
  155. package/dist/runtime/subagents/definition.js +106 -109
  156. package/dist/runtime/subagents/dispatch.js +4 -3
  157. package/dist/runtime/subagents/preamble.d.ts +2 -1
  158. package/dist/runtime/subagents/preamble.js +2 -1
  159. package/dist/runtime/waits.js +14 -4
  160. package/dist/sandbox/sandbox.service.d.ts +120 -10
  161. package/dist/sandbox/sandbox.service.js +335 -28
  162. package/dist/sandbox/tiers.d.ts +86 -0
  163. package/dist/sandbox/tiers.js +96 -0
  164. package/dist/schedules/effective-settings.d.ts +16 -0
  165. package/dist/schedules/effective-settings.js +17 -0
  166. package/dist/schedules/errors.d.ts +8 -0
  167. package/dist/schedules/errors.js +8 -0
  168. package/dist/schedules/fire.d.ts +118 -0
  169. package/dist/schedules/fire.js +625 -0
  170. package/dist/schedules/grant-rules.d.ts +94 -0
  171. package/dist/schedules/grant-rules.js +126 -0
  172. package/dist/schedules/job-ids.d.ts +32 -0
  173. package/dist/schedules/job-ids.js +27 -0
  174. package/dist/schedules/pause.d.ts +9 -0
  175. package/dist/schedules/pause.js +33 -0
  176. package/dist/schedules/run-tracker.d.ts +81 -0
  177. package/dist/schedules/run-tracker.js +333 -0
  178. package/dist/schedules/scan.job.d.ts +64 -0
  179. package/dist/schedules/scan.job.js +303 -0
  180. package/dist/schedules/schedule-math.d.ts +31 -0
  181. package/dist/schedules/schedule-math.js +223 -0
  182. package/dist/schedules/scheduled-tasks.service.d.ts +351 -0
  183. package/dist/schedules/scheduled-tasks.service.js +1193 -0
  184. package/dist/schedules/schedules.controller.d.ts +68 -0
  185. package/dist/schedules/schedules.controller.js +242 -0
  186. package/dist/schedules/schedules.module.d.ts +16 -0
  187. package/dist/schedules/schedules.module.js +65 -0
  188. package/dist/schedules/schedules.schemas.d.ts +316 -0
  189. package/dist/schedules/schedules.schemas.js +186 -0
  190. package/dist/schedules/store.d.ts +81 -0
  191. package/dist/schedules/store.js +390 -0
  192. package/dist/schedules/store.module.d.ts +6 -0
  193. package/dist/schedules/store.module.js +21 -0
  194. package/dist/schedules/types.d.ts +108 -0
  195. package/dist/schedules/types.js +1 -0
  196. package/dist/schedules/unattended.d.ts +117 -0
  197. package/dist/schedules/unattended.js +228 -0
  198. package/dist/setup/oauth-token-probe.js +8 -4
  199. package/dist/skills/agent-skills.service.d.ts +4 -8
  200. package/dist/skills/agent-skills.service.js +18 -53
  201. package/dist/skills/catalog.d.ts +65 -62
  202. package/dist/skills/catalog.js +109 -206
  203. package/dist/skills/conversation-catalog.d.ts +3 -3
  204. package/dist/skills/conversation-catalog.js +5 -12
  205. package/dist/skills/invoke.d.ts +2 -2
  206. package/dist/skills/skills.controller.d.ts +3 -1
  207. package/dist/skills/skills.service.d.ts +38 -37
  208. package/dist/skills/skills.service.js +168 -107
  209. package/dist/skills/usable.d.ts +57 -8
  210. package/dist/skills/usable.js +172 -38
  211. package/dist/tools/approvals.controller.d.ts +4 -2
  212. package/dist/tools/approvals.controller.js +17 -2
  213. package/dist/tools/approvals.schemas.d.ts +1 -0
  214. package/dist/tools/approvals.schemas.js +3 -1
  215. package/dist/tools/approvals.service.d.ts +182 -7
  216. package/dist/tools/approvals.service.js +597 -13
  217. package/dist/tools/builtin-names.d.ts +25 -4
  218. package/dist/tools/builtin-names.js +45 -4
  219. package/dist/tools/builtins/builtin-tools.d.ts +8 -0
  220. package/dist/tools/builtins/builtin-tools.js +23 -2
  221. package/dist/tools/builtins/sandbox/bash.js +16 -7
  222. package/dist/tools/builtins/sandbox/common.d.ts +1 -1
  223. package/dist/tools/builtins/sandbox/common.js +33 -10
  224. package/dist/tools/builtins/sandbox/edit.js +7 -3
  225. package/dist/tools/builtins/sandbox/file-state.d.ts +31 -1
  226. package/dist/tools/builtins/sandbox/file-state.js +33 -3
  227. package/dist/tools/builtins/sandbox/write.js +8 -4
  228. package/dist/tools/builtins/schedules.d.ts +107 -0
  229. package/dist/tools/builtins/schedules.js +789 -0
  230. package/dist/tools/elicitation.d.ts +2 -0
  231. package/dist/tools/elicitation.js +1 -1
  232. package/dist/tools/fixed-ask.d.ts +7 -0
  233. package/dist/tools/fixed-ask.js +9 -0
  234. package/dist/tools/network-asks.d.ts +109 -0
  235. package/dist/tools/network-asks.js +221 -0
  236. package/dist/tools/pipeline.d.ts +53 -6
  237. package/dist/tools/pipeline.js +202 -13
  238. package/dist/tools/policy.d.ts +21 -8
  239. package/dist/tools/policy.js +63 -9
  240. package/dist/tools/registry.d.ts +10 -1
  241. package/dist/tools/tools.module.js +12 -0
  242. package/package.json +2 -2
  243. package/src/migrations/0113_scheduled_tasks.sql +108 -0
  244. package/src/migrations/0114_network_asks.sql +23 -0
  245. package/src/migrations/0115_network_requests.sql +28 -0
  246. package/src/migrations/0116_skills_default_on.sql +37 -0
  247. package/src/migrations/0117_sandbox_tiers.sql +11 -0
@@ -0,0 +1,351 @@
1
+ import type { Queue } from "bullmq";
2
+ import { AgentLookup } from "../agents/agent-lookup.js";
3
+ import type { ModelRef } from "../agents/definition.js";
4
+ import { ConversationAccess } from "../conversations/access.js";
5
+ import type { KernelSchemaDb } from "../db/kernel-schema.js";
6
+ import { ExtensionRegistry } from "../extensions/registry.js";
7
+ import { KernelConfigService } from "../infra/config/kernel-config.service.js";
8
+ import { KernelDb } from "../infra/database/kernel-db.js";
9
+ import { TransactionHost } from "../infra/database/transaction-host.js";
10
+ import { DevicePolicyService } from "../local-devices/device-policy.service.js";
11
+ import type { KernelLogger } from "../log.js";
12
+ import { OrgLock } from "../orgs/org-lock.js";
13
+ import { ProviderRegistry } from "../runtime/providers.js";
14
+ import { SandboxService } from "../sandbox/sandbox.service.js";
15
+ import { ToolRegistry } from "../tools/registry.js";
16
+ import { type GrantContext, type GrantRefusalCode, grantRefusal, grantRefusalOf, networkGrantRefusal } from "./grant-rules.js";
17
+ import { ScheduledTaskStore } from "./store.js";
18
+ import type { ScheduleChat, ScheduledTask, ScheduledTaskGrant, ScheduleMode, SchedulePauseReason, TaskRun } from "./types.js";
19
+ export { type GrantContext, type GrantRefusalCode, grantRefusal, grantRefusalOf, networkGrantRefusal, };
20
+ /** When a task fires, before the zone is fixed (spec §5). */
21
+ export type TriggerInput = {
22
+ kind: "cron";
23
+ expr: string;
24
+ } | {
25
+ kind: "once";
26
+ at: string;
27
+ };
28
+ /** A scheduled task that needs its creator's attention (spec §8): the inbox item's payload. */
29
+ export interface ScheduleAttention {
30
+ taskId: string;
31
+ name: string;
32
+ /**
33
+ * `missing_grants`: the latest run was refused tools or connections the task lacks; `failed`:
34
+ * the latest settled run of an active task failed (its start included); else the pause reason.
35
+ */
36
+ reason: SchedulePauseReason | "missing_grants" | "failed";
37
+ /** The person who paused the task (`reason: "admin"` names the admin); else null. */
38
+ pausedBy: {
39
+ id: string;
40
+ name: string;
41
+ } | null;
42
+ /**
43
+ * `missing_grants` only: tool keys the latest run was refused and the task has no grant for now,
44
+ * `connection:<slug>` (connect that connector), or `network:<host>` (a domain the run was
45
+ * refused: the task has no grant for it, or the org's network allowlist no longer admits it).
46
+ */
47
+ missing: string[];
48
+ /** The subset of `missing` the creator cannot pre-approve (the tool needs a higher role). */
49
+ needsRole: string[];
50
+ /**
51
+ * The `network:<host>` keys of `missing` outside the org's network allowlist: only an org admin
52
+ * can add the host (network ask-to-allow spec §8.3); the creator cannot pre-approve them.
53
+ */
54
+ needsAdmin: string[];
55
+ /**
56
+ * `missing` holds `network:` keys and the task's device reports it takes no network grants from
57
+ * the deployment (`remoteGrants` off): a task grant would not reach it; its owner allows the
58
+ * domains locally (`capybara-device policy add allowedDomains <host>`).
59
+ */
60
+ deviceRefuses: boolean;
61
+ /** `failed` only: the run's error; else null. */
62
+ error: string | null;
63
+ /** When the pause happened, or when the refused or failed run was due. */
64
+ at: Date;
65
+ }
66
+ /**
67
+ * A tool the creator pre-approves for the task; the service resolves its current `spec_hash`. Or a
68
+ * domain (`toolKey: "network:<host>"`, network ask-to-allow spec §8.1): one exact host the task's
69
+ * unattended runs may reach on the task's device, checked by `networkGrantRefusal`.
70
+ */
71
+ export interface GrantInput {
72
+ toolKey: string;
73
+ /** The connector the tool comes from; when given it must be the tool's own. */
74
+ connectorId?: string;
75
+ }
76
+ export interface CreateTaskInput {
77
+ agentId: string;
78
+ name: string;
79
+ prompt: string;
80
+ trigger: TriggerInput;
81
+ /** Absent: the creator's effective zone (account, browser, org, UTC). */
82
+ timeZone?: string;
83
+ mode: ScheduleMode;
84
+ /** `conversation` mode only. */
85
+ conversationId?: string;
86
+ /** `chat` mode only. */
87
+ chat?: ScheduleChat;
88
+ /**
89
+ * `new` mode only (a conversation or chat task runs with that conversation's selection and
90
+ * device): the model, which must resolve for the org, and an effort it declares.
91
+ */
92
+ model?: ModelRef;
93
+ effort?: string;
94
+ deviceId?: string;
95
+ /**
96
+ * When the task ends; it must lie in the future. Absent or null: for a cron task, now + the
97
+ * org's `defaultExpiryDays` when set; otherwise never.
98
+ */
99
+ expiresAt?: Date | null;
100
+ grants?: GrantInput[];
101
+ }
102
+ /**
103
+ * Fields to change; `null` clears an optional one (`expiresAt: null` is the org's default expiry
104
+ * for a cron task, as on create). Grants change through their own methods.
105
+ */
106
+ export interface UpdateTaskInput {
107
+ agentId?: string;
108
+ name?: string;
109
+ prompt?: string;
110
+ trigger?: TriggerInput;
111
+ timeZone?: string;
112
+ mode?: ScheduleMode;
113
+ conversationId?: string | null;
114
+ chat?: ScheduleChat | null;
115
+ model?: ModelRef | null;
116
+ effort?: string | null;
117
+ deviceId?: string | null;
118
+ expiresAt?: Date | null;
119
+ }
120
+ /**
121
+ * Where a grant write comes from: `fromSession` only for a person in a signed-in web session (not a
122
+ * personal access token, the Platform tool or the schedule tools). Network domains are approved
123
+ * only there (network ask-to-allow spec §8.1): an agent must never pre-approve a domain for itself.
124
+ */
125
+ export interface GrantWriteSource {
126
+ fromSession?: boolean;
127
+ }
128
+ /** Who acts on a task: the service reads their live role itself and decides by that one. */
129
+ export interface ScheduleActor {
130
+ accountId: string;
131
+ }
132
+ /** One of the agent's tools as the task form offers it (`GET …/schedules/grantable-tools`). */
133
+ export interface GrantableTool {
134
+ key: string;
135
+ /** The tool's display title, when it declares one. */
136
+ title: string | null;
137
+ source: "builtin" | "plugin" | "connector";
138
+ connectorId: string | null;
139
+ grantable: boolean;
140
+ /** Why not, when not grantable. */
141
+ reason: GrantRefusalCode | null;
142
+ }
143
+ /**
144
+ * A grant as the task page shows it: `stale` when the tool's definition changed or the tool left
145
+ * (spec §7); null when the agent's tools cannot be read now.
146
+ */
147
+ export interface ScheduledTaskGrantView extends ScheduledTaskGrant {
148
+ stale: boolean | null;
149
+ }
150
+ /** The latest settled (completed, failed or skipped) non-trial run of a task. */
151
+ export interface TaskLastRun {
152
+ status: "completed" | "failed" | "skipped";
153
+ skipReason: TaskRun["skipReason"];
154
+ /** When it fired; its tick for a skipped one. */
155
+ at: Date;
156
+ }
157
+ /** A task in a list, with its latest settled run. */
158
+ export type ScheduledTaskListItem = ScheduledTask & {
159
+ lastRun: TaskLastRun | null;
160
+ };
161
+ /**
162
+ * A chat the creator can point a `chat` task at (spec §8): their DM with a connection's bot
163
+ * (a thread row of theirs, archived included), or a group they have talked in when the channel
164
+ * has threads.
165
+ */
166
+ export interface ChatTarget {
167
+ connectionId: string;
168
+ connectionName: string;
169
+ plugin: string;
170
+ /** The connection's agent: a chat task's agent. */
171
+ agentId: string;
172
+ chatId: string;
173
+ chatType: "dm" | "group";
174
+ /** A name for people: the connection's name (and the group's chat id). */
175
+ label: string;
176
+ }
177
+ /**
178
+ * Scheduled tasks for people (spec §5, §7–§10): create, edit, pause, resume, delete, their runs
179
+ * and grants. Every write runs in one transaction under the org row lock (`OrgLock`), which also
180
+ * serializes the per-member and per-org caps, re-reads the actor's role there, and holds the task
181
+ * row (`FOR UPDATE`) so the scanner skips it until the write commits.
182
+ *
183
+ * Roles: `schedules.use` (member) creates and edits one's own tasks; `schedules.manage` (admin)
184
+ * lists, pauses, resumes and deletes any task of the org, never edits another person's (the task
185
+ * runs as its creator). A task the caller may not see is `schedule.not_found`.
186
+ */
187
+ export declare class ScheduledTasksService {
188
+ private readonly db;
189
+ readonly txHost: TransactionHost;
190
+ private readonly config;
191
+ private readonly store;
192
+ private readonly orgLock;
193
+ private readonly agents;
194
+ private readonly access;
195
+ private readonly tools;
196
+ private readonly extensions;
197
+ /** A task's model must resolve for the org and declare its effort (as a message's switch). */
198
+ private readonly providers;
199
+ private readonly log;
200
+ /** "Run now" enqueues the fire job (consumed by the worker role). */
201
+ private readonly maintenance;
202
+ /** Network grants: the org's effective egress (network ask-to-allow spec §8.1). */
203
+ private readonly sandbox;
204
+ /** Network grants: the task's device's local policy summary (`remoteGrants`). */
205
+ private readonly devicePolicy;
206
+ constructor(db: KernelDb, txHost: TransactionHost, config: Pick<KernelConfigService, "get">, store: ScheduledTaskStore, orgLock: Pick<OrgLock, "lockAndAuthorize">, agents: Pick<AgentLookup, "get">, access: Pick<ConversationAccess, "isAccessible">, tools: Pick<ToolRegistry, "forAgent">, extensions: Pick<ExtensionRegistry, "list">,
207
+ /** A task's model must resolve for the org and declare its effort (as a message's switch). */
208
+ providers: Pick<ProviderRegistry, "resolve">, log: Pick<KernelLogger, "warn">,
209
+ /** "Run now" enqueues the fire job (consumed by the worker role). */
210
+ maintenance: Pick<Queue, "add">,
211
+ /** Network grants: the org's effective egress (network ask-to-allow spec §8.1). */
212
+ sandbox: Pick<SandboxService, "ceilingLimits" | "devicePolicy">,
213
+ /** Network grants: the task's device's local policy summary (`remoteGrants`). */
214
+ devicePolicy: Pick<DevicePolicyService, "summary">);
215
+ create(orgId: string, accountId: string, input: CreateTaskInput, browserTimeZone?: string, source?: GrantWriteSource): Promise<ScheduledTask>;
216
+ /** Creator only: an org admin gets `schedule.forbidden`, anyone else `schedule.not_found`. */
217
+ update(orgId: string, accountId: string, id: string, patch: UpdateTaskInput): Promise<ScheduledTask>;
218
+ /** The creator, or an org admin (`schedules.manage`); a task not active is returned as is. */
219
+ pause(orgId: string, actor: ScheduleActor, id: string): Promise<ScheduledTask>;
220
+ /**
221
+ * The creator (`schedules.use`), or an org admin. The next run is computed from now (missed ticks
222
+ * are not caught up) and the failure count starts over. An ended task cannot be resumed.
223
+ */
224
+ resume(orgId: string, actor: ScheduleActor, id: string): Promise<ScheduledTask>;
225
+ /** The creator, or an org admin. */
226
+ remove(orgId: string, actor: ScheduleActor, id: string): Promise<void>;
227
+ /** The creator, or an org admin. */
228
+ get(orgId: string, actor: ScheduleActor, id: string): Promise<ScheduledTask>;
229
+ /** The actor's own tasks; `all` (org admins only, else `forbidden`): every task of the org. */
230
+ list(orgId: string, actor: ScheduleActor, opts?: {
231
+ all?: boolean;
232
+ conversationId?: string;
233
+ }): Promise<ScheduledTaskListItem[]>;
234
+ /**
235
+ * The tasks of `tasks` that post into the conversation: a `conversation` task naming it, or a
236
+ * `chat` task whose chat the conversation is a thread of (spec §10 side panel).
237
+ */
238
+ private postingInto;
239
+ /** Each task with its latest settled non-trial run, in one query. */
240
+ private withLastRuns;
241
+ /**
242
+ * The chats the caller can point a `chat` task at (spec §8): per active connection of the org,
243
+ * their DM threads (archived included) and, on a channel with threads, the groups they have a
244
+ * thread in. Members up (`schedules.use`, the route's).
245
+ */
246
+ chatTargets(orgId: string, accountId: string): Promise<ChatTarget[]>;
247
+ /**
248
+ * The agent's tools (connector tools included) as a task's grant picker offers them, each
249
+ * grantable or why not by {@link grantRefusalOf}, the rule {@link addGrants} applies.
250
+ * `agent.not_found` when the caller can't use the agent.
251
+ */
252
+ grantableTools(orgId: string, accountId: string, agentId: string): Promise<GrantableTool[]>;
253
+ /** The task's runs, latest first (default 50, at most 200); visible as {@link get}. */
254
+ runs(orgId: string, actor: ScheduleActor, id: string, limit?: number): Promise<TaskRun[]>;
255
+ /** The task's grants; visible as {@link get}. */
256
+ grants(orgId: string, actor: ScheduleActor, id: string): Promise<ScheduledTaskGrantView[]>;
257
+ /**
258
+ * Creator only; each grant is checked as at create (spec §7); network domains only from a web
259
+ * session (`source.fromSession`).
260
+ */
261
+ addGrants(orgId: string, accountId: string, id: string, grants: GrantInput[], source?: GrantWriteSource): Promise<ScheduledTaskGrant[]>;
262
+ /** Creator only; removing a grant the task does not have is a no-op. */
263
+ removeGrant(orgId: string, accountId: string, id: string, toolKey: string): Promise<void>;
264
+ /**
265
+ * The creator's scheduled tasks that need attention (spec §8), derived live: a paused task whose
266
+ * reason is not `creator` (resuming clears it), an active task whose latest settled non-trial
267
+ * run failed (the next good run clears it), and a task whose latest settled non-trial run was
268
+ * refused tools, connections or domains (a tool granted since drops out, a domain too while the
269
+ * org's network allowlist admits it; the next clean run clears the rest). Newest first.
270
+ */
271
+ attentionFor(orgId: string, accountId: string): Promise<ScheduleAttention[]>;
272
+ private roleOrNull;
273
+ /**
274
+ * The agent's tools by key (their `requiredRole` and definition hash) as the creator sees them;
275
+ * empty when the agent is gone or hidden (the task is paused for that anyway); null when they
276
+ * cannot be read now (logged: the caller then cannot tell what is stale or needs a role).
277
+ */
278
+ private agentToolFacts;
279
+ /**
280
+ * Pauses an active live task for `reason` in the caller's transaction `t` (the fire job, the
281
+ * delivery path); `by` is the account that caused it, null for the kernel. A task already
282
+ * paused or ended keeps its state and reason.
283
+ */
284
+ pauseFor(t: KernelSchemaDb, taskId: string, reason: SchedulePauseReason, by: string | null): Promise<void>;
285
+ /**
286
+ * "Run now" (spec §6), creator only: a task run for the request time, outside the schedule (no
287
+ * unique-key conflict with a tick, and `next_run_at` does not move), fired at once through the
288
+ * fire job after the commit. `trial`: an attended trial run whose approvals become the task's
289
+ * grants (§7). Counted in the rate limit like any run. An ended task cannot run; a paused one
290
+ * can (only its creator gets here: the run is `manual`, which the fire's paused check lets by).
291
+ */
292
+ runNow(orgId: string, accountId: string, id: string, opts: {
293
+ trial: boolean;
294
+ }): Promise<TaskRun>;
295
+ /** The live role of a member of the org; not a member → `schedule.not_found`. */
296
+ private liveRole;
297
+ /** The actor's own task, row-locked; another's: `schedule.forbidden` for an admin, else 404. */
298
+ private lockOwn;
299
+ /**
300
+ * A task the actor may pause, resume or delete, row-locked under the org lock: their own (with
301
+ * `creatorAction`), or any as an org admin (`schedules.manage`); otherwise `schedule.not_found`.
302
+ */
303
+ private lockManaged;
304
+ /**
305
+ * Where runs go (spec §3, §8), checked against the creator:
306
+ * - the mode and its fields agree (`conversation`: a conversation and no chat; `chat`: a chat
307
+ * and no conversation; `new`: neither);
308
+ * - `conversation`: the creator's live chat conversation with this agent, still accessible;
309
+ * - `chat`: the connection is active and bound to this agent; a DM needs a thread row (archived
310
+ * allowed) of the creator in that chat; a group needs the creator's thread row in the group
311
+ * and a channel with threads.
312
+ */
313
+ private checkTarget;
314
+ /** The channel's declared features; undefined when its extension is not loaded here. */
315
+ private channelFeatures;
316
+ /**
317
+ * A task's model, effort and device (spec §4): `new` mode only, since a conversation or chat
318
+ * task runs with that conversation's selection and device (a task must not switch a person's
319
+ * conversation for their later turns), so another mode refuses them (`validation_failed`).
320
+ * The model must resolve for the org (`agent.model_unavailable`, as a message's switch) and
321
+ * declare the effort (`validation_failed`); the device must be one of the creator's
322
+ * (`checkDevice`, when `deviceChanged`).
323
+ */
324
+ private checkPick;
325
+ /** The device is one of the creator's live personal devices in the org. */
326
+ private checkDevice;
327
+ /**
328
+ * The grants as stored: each tool resolved among the agent's tools now (its `spec_hash` and
329
+ * source connector), refused by {@link grantRefusal}; each `network:<host>` key (lower-cased)
330
+ * refused by {@link networkGrantRefusal} against the org's effective egress and the summary of
331
+ * `deviceId`, the task's device (null: none can be determined, the device rule is skipped),
332
+ * stored with `spec_hash` `network` and no connector (plan P-D7), and only when
333
+ * `source.fromSession` (a person on the task page; never a token, the Platform tool or the
334
+ * schedule tools). Duplicates keep the last.
335
+ */
336
+ private resolveGrants;
337
+ /**
338
+ * What a network grant is checked against (network ask-to-allow spec §8.1): the network of the
339
+ * org's sandbox ceiling now (sandbox dev tiers spec §4.2) and the local policy summary of the
340
+ * task's device (null without a device or a connected machine).
341
+ */
342
+ private networkGrantContext;
343
+ /**
344
+ * The device a task's runs use, as far as the task tells: a `new` task's own device, a
345
+ * `conversation` task's conversation's device (in the org); null when none is chosen, and for a
346
+ * chat task: its IM conversation's device is not known until it runs, so the device rule of a
347
+ * network grant is skipped there (the device still refuses grants at the command when its owner
348
+ * turned them off, and the run notes it).
349
+ */
350
+ private taskDeviceOf;
351
+ }