@capybara-hq/kernel 0.1.0-rc.36 → 0.1.0-rc.37

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 (309) hide show
  1. package/bootstrap.json +5 -5
  2. package/dist/admin/admin.module.d.ts +3 -3
  3. package/dist/admin/admin.module.js +6 -6
  4. package/dist/admin/audit-log.service.d.ts +51 -0
  5. package/dist/admin/{platform-audit.service.js → audit-log.service.js} +20 -12
  6. package/dist/admin/audit.controller.d.ts +18 -6
  7. package/dist/admin/audit.controller.js +36 -6
  8. package/dist/admin/audit.schemas.d.ts +9 -1
  9. package/dist/admin/audit.schemas.js +22 -2
  10. package/dist/admin/outbox-dead.controller.d.ts +4 -6
  11. package/dist/admin/outbox-dead.controller.js +9 -6
  12. package/dist/admin/outbox-dead.schemas.d.ts +16 -0
  13. package/dist/admin/outbox-dead.schemas.js +25 -1
  14. package/dist/admin/outbox-dead.service.d.ts +16 -7
  15. package/dist/admin/outbox-dead.service.js +34 -10
  16. package/dist/admin/overview.service.d.ts +3 -3
  17. package/dist/admin/overview.service.js +0 -1
  18. package/dist/agents/agent-lookup.js +2 -10
  19. package/dist/agents/agents.service.js +9 -20
  20. package/dist/agents/definition.d.ts +3 -51
  21. package/dist/agents/definition.js +4 -254
  22. package/dist/agents/org-templates.js +2 -6
  23. package/dist/agents/readiness.controller.d.ts +4 -12
  24. package/dist/agents/readiness.controller.js +4 -12
  25. package/dist/agents/readiness.service.d.ts +23 -11
  26. package/dist/agents/readiness.service.js +31 -14
  27. package/dist/agents/templates.d.ts +0 -6
  28. package/dist/agents/templates.js +8 -34
  29. package/dist/background/store.d.ts +2 -0
  30. package/dist/background/store.js +3 -1
  31. package/dist/background/wake-rules.js +2 -1
  32. package/dist/catalog/admin-catalog.controller.d.ts +1 -2
  33. package/dist/catalog/admin-catalog.controller.js +1 -2
  34. package/dist/catalog/appearance.service.js +1 -3
  35. package/dist/catalog/catalog-content.d.ts +1 -1
  36. package/dist/catalog/catalog-content.js +1 -4
  37. package/dist/catalog/catalog-items.js +3 -3
  38. package/dist/catalog/catalog-scope.service.d.ts +10 -28
  39. package/dist/catalog/catalog-scope.service.js +22 -73
  40. package/dist/catalog/cli.d.ts +0 -11
  41. package/dist/catalog/cli.js +0 -20
  42. package/dist/catalog/component-scope.service.js +0 -2
  43. package/dist/catalog/component-state.js +2 -2
  44. package/dist/catalog/install-status.d.ts +6 -0
  45. package/dist/catalog/install-status.js +6 -0
  46. package/dist/catalog/job-ids.d.ts +0 -4
  47. package/dist/catalog/job-ids.js +0 -4
  48. package/dist/catalog/marketplaces.service.d.ts +1 -1
  49. package/dist/catalog/org-catalog.service.d.ts +2 -0
  50. package/dist/catalog/org-catalog.service.js +8 -3
  51. package/dist/catalog/org-extension-switch.d.ts +7 -2
  52. package/dist/catalog/org-extension-switch.js +56 -9
  53. package/dist/catalog/org-plugin-uploads.d.ts +6 -15
  54. package/dist/catalog/org-plugin-uploads.js +9 -27
  55. package/dist/catalog/owned-items.js +1 -3
  56. package/dist/catalog/platform-import-update.js +1 -1
  57. package/dist/catalog/plugin-import.d.ts +15 -13
  58. package/dist/catalog/plugin-import.js +21 -30
  59. package/dist/catalog/plugin-install.d.ts +3 -43
  60. package/dist/catalog/plugin-install.js +8 -150
  61. package/dist/catalog/plugin-package.d.ts +5 -10
  62. package/dist/catalog/plugin-package.js +12 -33
  63. package/dist/catalog/plugin-upgrade.js +5 -4
  64. package/dist/catalog/scope-jobs.d.ts +34 -34
  65. package/dist/catalog/scope-jobs.js +50 -37
  66. package/dist/catalog/scope-orgs.d.ts +1 -1
  67. package/dist/catalog/scope-orgs.js +1 -2
  68. package/dist/catalog/scope-sync-workers.d.ts +4 -3
  69. package/dist/catalog/scope-sync-workers.js +18 -6
  70. package/dist/catalog/scope-sync.d.ts +56 -59
  71. package/dist/catalog/scope-sync.js +96 -166
  72. package/dist/catalog/unshare.d.ts +3 -4
  73. package/dist/catalog/unshare.js +5 -8
  74. package/dist/channels/job-ids.d.ts +2 -6
  75. package/dist/channels/job-ids.js +2 -6
  76. package/dist/channels/outbound.d.ts +1 -1
  77. package/dist/channels/outbound.js +1 -1
  78. package/dist/channels/supervisor.d.ts +2 -3
  79. package/dist/channels/supervisor.js +2 -3
  80. package/dist/client/client-access.service.js +1 -1
  81. package/dist/config/env.js +19 -1
  82. package/dist/config/load.d.ts +0 -6
  83. package/dist/config/load.js +8 -27
  84. package/dist/config/schema.d.ts +53 -47
  85. package/dist/config/schema.js +190 -40
  86. package/dist/conversations/attachments.service.d.ts +10 -3
  87. package/dist/conversations/attachments.service.js +49 -16
  88. package/dist/conversations/conversations.controller.d.ts +0 -39
  89. package/dist/conversations/conversations.controller.js +0 -39
  90. package/dist/conversations/events.d.ts +71 -46
  91. package/dist/conversations/events.js +124 -112
  92. package/dist/conversations/media-types.d.ts +25 -0
  93. package/dist/conversations/media-types.js +38 -0
  94. package/dist/conversations/queue.d.ts +3 -1
  95. package/dist/conversations/queue.service.js +9 -2
  96. package/dist/conversations/titles.js +6 -0
  97. package/dist/ctx/create-ctx.js +1 -2
  98. package/dist/ctx/secrets.d.ts +24 -7
  99. package/dist/ctx/secrets.js +97 -30
  100. package/dist/db/kernel-schema.d.ts +17 -6
  101. package/dist/errors.d.ts +5 -2
  102. package/dist/errors.js +5 -2
  103. package/dist/evals/reconstruct.d.ts +4 -17
  104. package/dist/evals/reconstruct.js +13 -53
  105. package/dist/evals/recorded-tools.d.ts +0 -27
  106. package/dist/evals/recorded-tools.js +2 -92
  107. package/dist/evals/run-replay.d.ts +1 -6
  108. package/dist/evals/run-replay.js +10 -17
  109. package/dist/evals/sets.service.d.ts +17 -5
  110. package/dist/evals/sets.service.js +33 -12
  111. package/dist/evals/snapshot.d.ts +1 -2
  112. package/dist/evals/snapshot.js +4 -17
  113. package/dist/extensions/admin-ops.d.ts +6 -1
  114. package/dist/extensions/admin-ops.js +17 -4
  115. package/dist/extensions/admin-view.d.ts +7 -4
  116. package/dist/extensions/admin-view.js +27 -21
  117. package/dist/extensions/bootstrap.js +0 -1
  118. package/dist/extensions/cli.js +0 -1
  119. package/dist/extensions/host.d.ts +2 -3
  120. package/dist/extensions/host.js +1 -5
  121. package/dist/extensions/installs.d.ts +1 -3
  122. package/dist/extensions/instance.d.ts +0 -2
  123. package/dist/extensions/instance.js +0 -3
  124. package/dist/extensions/org-config.d.ts +4 -4
  125. package/dist/extensions/org-config.js +13 -22
  126. package/dist/extensions/package.d.ts +6 -6
  127. package/dist/extensions/package.js +3 -7
  128. package/dist/extensions/permission-view.d.ts +2 -4
  129. package/dist/extensions/plugin-items.d.ts +21 -1
  130. package/dist/extensions/plugin-items.js +28 -0
  131. package/dist/extensions/sync.js +5 -10
  132. package/dist/extensions/unavailable.js +0 -1
  133. package/dist/http/api.module.js +2 -1
  134. package/dist/identity/audit.d.ts +0 -12
  135. package/dist/identity/audit.js +0 -27
  136. package/dist/identity/auth.controller.js +5 -9
  137. package/dist/identity/cookies.d.ts +4 -9
  138. package/dist/identity/cookies.js +8 -32
  139. package/dist/identity/initial-passwords.d.ts +1 -1
  140. package/dist/identity/initial-passwords.js +1 -2
  141. package/dist/identity/sessions.d.ts +0 -6
  142. package/dist/identity/sessions.js +0 -18
  143. package/dist/inbox/platform-inbox.service.d.ts +33 -1
  144. package/dist/inbox/platform-inbox.service.js +56 -6
  145. package/dist/index.d.ts +4 -2
  146. package/dist/index.js +4 -2
  147. package/dist/infra/cli/master-key-rewrap.d.ts +15 -0
  148. package/dist/infra/cli/master-key-rewrap.js +24 -0
  149. package/dist/infra/config/kernel-config.service.js +0 -17
  150. package/dist/infra/health/health.controller.js +8 -0
  151. package/dist/infra/health/process-fault.d.ts +16 -0
  152. package/dist/infra/health/process-fault.js +49 -0
  153. package/dist/infra/lifecycle/process-guards.d.ts +8 -2
  154. package/dist/infra/lifecycle/process-guards.js +12 -3
  155. package/dist/infra/lifecycle/shutdown-signals.d.ts +10 -1
  156. package/dist/infra/lifecycle/shutdown-signals.js +28 -13
  157. package/dist/infra/outbox/outbox.service.d.ts +12 -9
  158. package/dist/infra/outbox/outbox.service.js +22 -26
  159. package/dist/infra/outbox/registry.d.ts +15 -7
  160. package/dist/infra/outbox/registry.js +39 -23
  161. package/dist/lifecycle/kernel-lifecycle.js +1 -7
  162. package/dist/models/enablement.d.ts +5 -6
  163. package/dist/models/enablement.js +7 -14
  164. package/dist/orgs/orgs.module.d.ts +2 -2
  165. package/dist/orgs/orgs.module.js +2 -2
  166. package/dist/orgs/settings.controller.d.ts +3 -2
  167. package/dist/orgs/settings.service.d.ts +59 -14
  168. package/dist/orgs/settings.service.js +102 -20
  169. package/dist/overrides.d.ts +3 -7
  170. package/dist/overrides.js +2 -4
  171. package/dist/packages/tgz.d.ts +0 -2
  172. package/dist/packages/tgz.js +0 -2
  173. package/dist/platform/exclusions.js +0 -5
  174. package/dist/platform/operation.js +1 -1
  175. package/dist/platform/ops/admin.ops.d.ts +2 -2
  176. package/dist/platform/ops/admin.ops.js +9 -6
  177. package/dist/platform/ops/agents.ops.js +1 -1
  178. package/dist/platform/ops/connectors.ops.js +46 -1
  179. package/dist/platform/ops/evals.ops.js +1 -64
  180. package/dist/platform/ops/extensions-admin.ops.js +1 -1
  181. package/dist/platform/ops/inbox.ops.js +16 -3
  182. package/dist/platform/ops/org-plugins.ops.js +1 -1
  183. package/dist/platform/ops/orgs.ops.d.ts +5 -3
  184. package/dist/platform/ops/orgs.ops.js +19 -4
  185. package/dist/platform/ops/outbox.ops.js +5 -5
  186. package/dist/roles/worker-role.d.ts +2 -3
  187. package/dist/roles/worker-role.js +3 -13
  188. package/dist/runtime/context/build.d.ts +56 -18
  189. package/dist/runtime/context/build.js +143 -50
  190. package/dist/runtime/context/compaction.d.ts +1 -3
  191. package/dist/runtime/context/compaction.js +42 -8
  192. package/dist/runtime/context/run-context.js +1 -2
  193. package/dist/runtime/context/skills.d.ts +27 -56
  194. package/dist/runtime/context/skills.js +42 -114
  195. package/dist/runtime/context/tool-changes.d.ts +3 -3
  196. package/dist/runtime/context/tool-changes.js +6 -16
  197. package/dist/runtime/hook-calls.d.ts +6 -6
  198. package/dist/runtime/hook-calls.js +7 -7
  199. package/dist/runtime/langgraph-loop.js +1 -0
  200. package/dist/runtime/maintenance.d.ts +3 -11
  201. package/dist/runtime/maintenance.js +5 -20
  202. package/dist/runtime/model-call.d.ts +5 -0
  203. package/dist/runtime/model-call.js +48 -36
  204. package/dist/runtime/providers.d.ts +33 -35
  205. package/dist/runtime/providers.js +64 -109
  206. package/dist/runtime/run-context.service.js +7 -22
  207. package/dist/runtime/run-deletion.d.ts +6 -0
  208. package/dist/runtime/run-deletion.js +39 -16
  209. package/dist/runtime/run-execution.js +4 -3
  210. package/dist/runtime/run-finish.js +2 -1
  211. package/dist/runtime/run-liveness.d.ts +11 -0
  212. package/dist/runtime/run-liveness.js +19 -0
  213. package/dist/runtime/run-orphan-check.job.js +2 -1
  214. package/dist/runtime/run-queue.js +8 -16
  215. package/dist/runtime/run-worker.d.ts +2 -2
  216. package/dist/runtime/run-worker.js +8 -6
  217. package/dist/runtime/subagents/definition.d.ts +16 -20
  218. package/dist/runtime/subagents/definition.js +27 -27
  219. package/dist/runtime/subagents/dispatch.d.ts +6 -2
  220. package/dist/runtime/subagents/dispatch.js +17 -3
  221. package/dist/runtime/subagents/org-agents.js +1 -2
  222. package/dist/runtime/subagents/preamble.d.ts +3 -2
  223. package/dist/runtime/subagents/preamble.js +3 -2
  224. package/dist/runtime/subagents/render.d.ts +1 -2
  225. package/dist/runtime/subagents/render.js +1 -2
  226. package/dist/runtime/subagents/skill-fork.d.ts +2 -4
  227. package/dist/runtime/subagents/template-skills.d.ts +47 -0
  228. package/dist/runtime/subagents/template-skills.js +76 -0
  229. package/dist/schedules/effective-settings.d.ts +9 -3
  230. package/dist/schedules/effective-settings.js +5 -4
  231. package/dist/schedules/fire.js +11 -0
  232. package/dist/schedules/scheduled-tasks.service.js +5 -0
  233. package/dist/schedules/unattended.d.ts +2 -0
  234. package/dist/schedules/unattended.js +6 -1
  235. package/dist/skills/agent-skills.service.js +1 -2
  236. package/dist/skills/catalog.d.ts +1 -3
  237. package/dist/skills/catalog.js +1 -3
  238. package/dist/skills/conversation-catalog.d.ts +1 -2
  239. package/dist/skills/conversation-catalog.js +1 -2
  240. package/dist/skills/usable.js +2 -3
  241. package/dist/storage/storage.service.js +9 -1
  242. package/dist/tools/approvals.service.js +2 -4
  243. package/dist/tools/builtin-names.d.ts +2 -9
  244. package/dist/tools/builtin-names.js +4 -13
  245. package/dist/tools/builtins/sandbox/bash.js +3 -3
  246. package/dist/tools/builtins/sandbox/common.d.ts +7 -13
  247. package/dist/tools/builtins/sandbox/common.js +8 -115
  248. package/dist/tools/builtins/sandbox/fetch-attachment.d.ts +10 -0
  249. package/dist/tools/builtins/sandbox/fetch-attachment.js +119 -0
  250. package/dist/tools/builtins/sandbox/glob.js +1 -3
  251. package/dist/tools/builtins/sandbox/grep.js +3 -5
  252. package/dist/tools/builtins/sandbox/index.d.ts +8 -5
  253. package/dist/tools/builtins/sandbox/index.js +10 -5
  254. package/dist/tools/builtins/sandbox/read.js +3 -2
  255. package/dist/tools/builtins/tool-search.d.ts +4 -7
  256. package/dist/tools/builtins/tool-search.js +6 -10
  257. package/dist/tools/connector-account-policies.d.ts +30 -3
  258. package/dist/tools/connector-account-policies.js +54 -7
  259. package/dist/tools/connectors.controller.d.ts +24 -11
  260. package/dist/tools/connectors.controller.js +35 -6
  261. package/dist/tools/connectors.schemas.d.ts +14 -1
  262. package/dist/tools/connectors.schemas.js +14 -2
  263. package/dist/tools/connectors.service.d.ts +22 -0
  264. package/dist/tools/connectors.service.js +56 -0
  265. package/dist/tools/drift.d.ts +1 -1
  266. package/dist/tools/drift.js +1 -1
  267. package/dist/tools/git-push-policy.d.ts +4 -1
  268. package/dist/tools/git-push-policy.js +3 -1
  269. package/dist/tools/info.d.ts +1 -7
  270. package/dist/tools/info.js +5 -18
  271. package/dist/tools/job-ids.d.ts +0 -4
  272. package/dist/tools/job-ids.js +1 -6
  273. package/dist/tools/pipeline.d.ts +4 -10
  274. package/dist/tools/pipeline.js +16 -62
  275. package/dist/tools/policy.d.ts +6 -2
  276. package/dist/tools/policy.js +14 -12
  277. package/dist/tools/registry.js +1 -5
  278. package/dist/ui/views.d.ts +5 -5
  279. package/dist/ui/views.js +10 -16
  280. package/package.json +3 -3
  281. package/src/migrations/0137_audit_org_idx.sql +5 -0
  282. package/src/migrations/0138_plugin_install_status_no_upgrading.sql +18 -0
  283. package/src/migrations/0139_retire_legacy_forms.sql +183 -0
  284. package/src/migrations/0140_retire_history_forms.sql +148 -0
  285. package/src/migrations/0141_install_ledger_promoted_rows.sql +36 -0
  286. package/src/migrations/0142_backfill_event_fields.sql +74 -0
  287. package/src/migrations/0143_backfill_model_call_fields.sql +105 -0
  288. package/src/migrations/0144_retire_frozen_definition_keys.sql +163 -0
  289. package/dist/admin/platform-audit.service.d.ts +0 -41
  290. package/dist/conversations/job-ids.d.ts +0 -6
  291. package/dist/conversations/job-ids.js +0 -6
  292. package/dist/extensions/job-ids.d.ts +0 -6
  293. package/dist/extensions/job-ids.js +0 -6
  294. package/dist/infra/queue/retired-schedulers.d.ts +0 -7
  295. package/dist/infra/queue/retired-schedulers.js +0 -9
  296. package/dist/orgs/job-ids.d.ts +0 -8
  297. package/dist/orgs/job-ids.js +0 -8
  298. package/dist/runtime/context/legacy-text.d.ts +0 -22
  299. package/dist/runtime/context/legacy-text.js +0 -37
  300. package/dist/runtime/job-ids.d.ts +0 -10
  301. package/dist/runtime/job-ids.js +0 -10
  302. package/dist/runtime/retired-schedulers.d.ts +0 -7
  303. package/dist/runtime/retired-schedulers.js +0 -31
  304. package/dist/storage/job-ids.d.ts +0 -6
  305. package/dist/storage/job-ids.js +0 -6
  306. package/dist/tools/legacy-data.d.ts +0 -34
  307. package/dist/tools/legacy-data.js +0 -76
  308. package/dist/tools/legacy-keys.d.ts +0 -51
  309. package/dist/tools/legacy-keys.js +0 -114
@@ -10,6 +10,14 @@ export interface ShutdownSignalOptions {
10
10
  * Default `process.exit`.
11
11
  */
12
12
  exit?: (code: number) => void;
13
+ /**
14
+ * Subscribes to this process's fault (a swallowed fatal event, `onProcessFault`); returns the
15
+ * unsubscribe. A fault runs the same graceful stop as a signal, then exits with 1 either way, so
16
+ * any restart policy replaces the process (readiness alone restarts nothing: Kubernetes only
17
+ * takes the pod out of its endpoints, a worker serves no traffic, compose does not restart an
18
+ * unhealthy container). `capybara start` passes it; default: none (tests, library use).
19
+ */
20
+ faults?: (onFault: (kind: string) => void) => () => void;
13
21
  }
14
22
  export interface ShutdownSignalHandle {
15
23
  /** The shutdown a signal started, settled once `exit` was called; undefined before any signal. */
@@ -25,6 +33,7 @@ export interface ShutdownSignalHandle {
25
33
  * flushing the logs. A second signal while that runs exits with 1 at once, so an operator's second
26
34
  * Ctrl-C (or an orchestrator's repeated SIGTERM) never waits on a stuck shutdown. Nest's handlers
27
35
  * would begin the shutdown only after every module's `onModuleDestroy`, ignore a second signal,
28
- * flush nothing and end the process by re-raising the signal.
36
+ * flush nothing and end the process by re-raising the signal. With `faults`, a swallowed fatal
37
+ * event starts the same stop and exits with 1.
29
38
  */
30
39
  export declare function handleShutdownSignals(close: () => Promise<void>, log: KernelLogger, opts?: ShutdownSignalOptions): ShutdownSignalHandle;
@@ -8,7 +8,8 @@ export const SHUTDOWN_SIGNALS = ["SIGTERM", "SIGINT"];
8
8
  * flushing the logs. A second signal while that runs exits with 1 at once, so an operator's second
9
9
  * Ctrl-C (or an orchestrator's repeated SIGTERM) never waits on a stuck shutdown. Nest's handlers
10
10
  * would begin the shutdown only after every module's `onModuleDestroy`, ignore a second signal,
11
- * flush nothing and end the process by re-raising the signal.
11
+ * flush nothing and end the process by re-raising the signal. With `faults`, a swallowed fatal
12
+ * event starts the same stop and exits with 1.
12
13
  */
13
14
  export function handleShutdownSignals(close, log, opts = {}) {
14
15
  const signals = opts.signals ?? process;
@@ -16,33 +17,47 @@ export function handleShutdownSignals(close, log, opts = {}) {
16
17
  let exiting;
17
18
  // Set by a second signal: the forced exit(1) stays the process's code
18
19
  let forced = false;
20
+ let unsubscribe = () => { };
19
21
  const dispose = () => {
20
22
  for (const s of SHUTDOWN_SIGNALS)
21
23
  signals.off(s, onSignal);
24
+ unsubscribe();
22
25
  };
23
- function onSignal(signal) {
24
- if (exiting) {
25
- log.warn("second signal received; exiting immediately", { signal });
26
- dispose();
27
- forced = true;
28
- exit(1);
29
- return;
30
- }
31
- log.info("signal received; shutting down", { signal });
32
- const end = (code) => log
26
+ /** Runs `close` once, then exits with `code` (1 when the stop failed). */
27
+ function stop(code) {
28
+ const end = (c) => log
33
29
  .flush()
34
30
  .catch(() => { })
35
31
  .then(() => {
36
32
  dispose();
37
33
  if (!forced)
38
- exit(code);
34
+ exit(c);
39
35
  });
40
- exiting = close().then(() => end(0), (err) => {
36
+ exiting = close().then(() => end(code), (err) => {
41
37
  log.error("shutdown failed", { err });
42
38
  return end(1);
43
39
  });
44
40
  }
41
+ function onSignal(signal) {
42
+ if (exiting) {
43
+ log.warn("second signal received; exiting immediately", { signal });
44
+ dispose();
45
+ forced = true;
46
+ exit(1);
47
+ return;
48
+ }
49
+ log.info("signal received; shutting down", { signal });
50
+ stop(0);
51
+ }
45
52
  for (const s of SHUTDOWN_SIGNALS)
46
53
  signals.on(s, onSignal);
54
+ if (opts.faults) {
55
+ unsubscribe = opts.faults((kind) => {
56
+ if (exiting)
57
+ return;
58
+ log.error("fatal event swallowed; shutting down so the process is replaced", { kind });
59
+ stop(1);
60
+ });
61
+ }
47
62
  return { exiting: () => exiting, dispose };
48
63
  }
@@ -1,4 +1,3 @@
1
- import type { KernelLogger } from "../../log.js";
2
1
  import { KernelDb } from "../database/kernel-db.js";
3
2
  import { TransactionHost } from "../database/transaction-host.js";
4
3
  import type { KernelQueueName } from "../queue/queue-names.js";
@@ -23,10 +22,16 @@ export type OutboxFastPath = (ids: readonly string[]) => Promise<void>;
23
22
  /** The fast path `add` hands each committed transaction's rows to (`OutboxModule` provides it). */
24
23
  export declare const OUTBOX_FAST_PATH: unique symbol;
25
24
  /**
26
- * Test seam (`KernelOverride`): `true` makes a reused job id with different data throw instead of
27
- * logging an error (spec §4, designer's call: "throws in tests, logs in production").
25
+ * A job id reused with different data: the id is wrong (two pieces of work share it), so the
26
+ * caller's transaction fails in every environment instead of silently running one of them.
28
27
  */
29
- export declare const OUTBOX_STRICT_CONFLICTS: unique symbol;
28
+ export declare class OutboxConflictError extends Error {
29
+ readonly queue: string;
30
+ readonly jobId: string;
31
+ readonly job: string;
32
+ readonly owedJob: string;
33
+ constructor(queue: string, jobId: string, job: string, owedJob: string);
34
+ }
30
35
  /**
31
36
  * Writes owed work as a row in the caller's transaction (spec §3.2): the row commits or rolls back
32
37
  * with the business write, and after the commit the fast path delivers it when it is due now (a
@@ -35,15 +40,13 @@ export declare const OUTBOX_STRICT_CONFLICTS: unique symbol;
35
40
  export declare class OutboxService {
36
41
  readonly txHost: TransactionHost;
37
42
  private readonly db;
38
- private readonly log;
39
43
  private readonly fastPath;
40
- private readonly strictConflicts;
41
- constructor(txHost: TransactionHost, db: KernelDb, log: KernelLogger, fastPath: OutboxFastPath, strictConflicts?: boolean);
44
+ constructor(txHost: TransactionHost, db: KernelDb, fastPath: OutboxFastPath);
42
45
  /**
43
46
  * Adds the job to the outbox in the transaction in context (throws outside one). Returns true when
44
47
  * it inserted a row, false when the same (queue, jobId) is already owed (a no-op; a dead row is
45
- * not owed). A conflict whose stored data differs is a bug in the job id: it throws under strict
46
- * conflicts, else logs an error. Undefined data is stored as JSON null.
48
+ * not owed). A conflict whose stored data differs is a bug in the job id: it throws
49
+ * {@link OutboxConflictError}, so the caller's transaction fails. Undefined data is stored as JSON null.
47
50
  */
48
51
  add<T>(job: OutboxJob<T>): Promise<boolean>;
49
52
  /**
@@ -8,19 +8,31 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
8
  return function (target, key) { decorator(target, key, paramIndex); }
9
9
  };
10
10
  import { isDeepStrictEqual } from "node:util";
11
- import { Inject, Injectable, Optional } from "@nestjs/common";
11
+ import { Inject, Injectable } from "@nestjs/common";
12
12
  import { afterCommit } from "../database/after-commit.js";
13
13
  import { KernelDb } from "../database/kernel-db.js";
14
14
  import { currentStore, TransactionHost } from "../database/transaction-host.js";
15
15
  import { Transactional } from "../database/transactional.decorator.js";
16
- import { KERNEL_LOGGER } from "../tokens.js";
17
16
  /** The fast path `add` hands each committed transaction's rows to (`OutboxModule` provides it). */
18
17
  export const OUTBOX_FAST_PATH = Symbol("OUTBOX_FAST_PATH");
19
18
  /**
20
- * Test seam (`KernelOverride`): `true` makes a reused job id with different data throw instead of
21
- * logging an error (spec §4, designer's call: "throws in tests, logs in production").
19
+ * A job id reused with different data: the id is wrong (two pieces of work share it), so the
20
+ * caller's transaction fails in every environment instead of silently running one of them.
22
21
  */
23
- export const OUTBOX_STRICT_CONFLICTS = Symbol("OUTBOX_STRICT_CONFLICTS");
22
+ export class OutboxConflictError extends Error {
23
+ queue;
24
+ jobId;
25
+ job;
26
+ owedJob;
27
+ constructor(queue, jobId, job, owedJob) {
28
+ super(`outbox job id reused with different data: ${JSON.stringify({ queue, jobId, job, owedJob })}`);
29
+ this.queue = queue;
30
+ this.jobId = jobId;
31
+ this.job = job;
32
+ this.owedJob = owedJob;
33
+ this.name = "OutboxConflictError";
34
+ }
35
+ }
24
36
  /** Jobs per insert statement of {@link OutboxService.addMany} (6 parameters each). */
25
37
  const ADD_MANY_CHUNK = 1000;
26
38
  /** The row of `job` (throws on a job id with `:`). */
@@ -57,21 +69,17 @@ const pendingIds = new WeakMap();
57
69
  let OutboxService = class OutboxService {
58
70
  txHost;
59
71
  db;
60
- log;
61
72
  fastPath;
62
- strictConflicts;
63
- constructor(txHost, db, log, fastPath, strictConflicts = false) {
73
+ constructor(txHost, db, fastPath) {
64
74
  this.txHost = txHost;
65
75
  this.db = db;
66
- this.log = log;
67
76
  this.fastPath = fastPath;
68
- this.strictConflicts = strictConflicts;
69
77
  }
70
78
  /**
71
79
  * Adds the job to the outbox in the transaction in context (throws outside one). Returns true when
72
80
  * it inserted a row, false when the same (queue, jobId) is already owed (a no-op; a dead row is
73
- * not owed). A conflict whose stored data differs is a bug in the job id: it throws under strict
74
- * conflicts, else logs an error. Undefined data is stored as JSON null.
81
+ * not owed). A conflict whose stored data differs is a bug in the job id: it throws
82
+ * {@link OutboxConflictError}, so the caller's transaction fails. Undefined data is stored as JSON null.
75
83
  */
76
84
  async add(job) {
77
85
  const json = JSON.stringify(job.data ?? null);
@@ -95,16 +103,7 @@ let OutboxService = class OutboxService {
95
103
  .executeTakeFirst();
96
104
  // no row: the owed one was delivered (and deleted) since the conflict; BullMQ dedupes the id
97
105
  if (stored && !isDeepStrictEqual(stored.data, JSON.parse(json))) {
98
- const msg = "outbox job id reused with different data";
99
- const fields = {
100
- queue: job.queue,
101
- jobId: job.jobId,
102
- job: job.name,
103
- owedJob: stored.job_name,
104
- };
105
- if (this.strictConflicts)
106
- throw new Error(`${msg}: ${JSON.stringify(fields)}`);
107
- this.log.error(msg, fields);
106
+ throw new OutboxConflictError(job.queue, job.jobId, job.name, stored.job_name);
108
107
  }
109
108
  return false;
110
109
  }
@@ -157,9 +156,6 @@ OutboxService = __decorate([
157
156
  Injectable(),
158
157
  __param(0, Inject(TransactionHost)),
159
158
  __param(1, Inject(KernelDb)),
160
- __param(2, Inject(KERNEL_LOGGER)),
161
- __param(3, Inject(OUTBOX_FAST_PATH)),
162
- __param(4, Optional()),
163
- __param(4, Inject(OUTBOX_STRICT_CONFLICTS))
159
+ __param(2, Inject(OUTBOX_FAST_PATH))
164
160
  ], OutboxService);
165
161
  export { OutboxService };
@@ -179,23 +179,27 @@ export declare const OUTBOX_JOBS: {
179
179
  };
180
180
  readonly "scope-item": {
181
181
  readonly queue: "cap-kernel-plugin-scope";
182
- readonly idempotent: "the sync converges each (item, org) from the scope, switches and installs it reads under the org's lock, and the installer re-checks under the org row lock, so a second run changes nothing";
182
+ readonly idempotent: "the fan-out owes the same chunk job ids again (`<item job id>-c<n>`), which the outbox and BullMQ dedupe, and each chunk converges from what it reads";
183
183
  readonly processedIn: "packages/kernel/src/catalog/scope-sync-workers.ts";
184
184
  readonly opts: {
185
- readonly attempts: 1;
185
+ readonly attempts: 7;
186
+ readonly backoff: {
187
+ readonly type: "exponential";
188
+ readonly delay: 5000;
189
+ };
186
190
  readonly removeOnComplete: true;
187
191
  readonly removeOnFail: true;
188
192
  };
189
193
  };
190
- readonly "scope-item-backstop": {
194
+ readonly "scope-item-chunk": {
191
195
  readonly queue: "cap-kernel-plugin-scope";
192
- readonly idempotent: "the sync converges each (item, org) from what it reads, as a scope-item job does, so a run after the immediate job changes nothing";
196
+ readonly idempotent: "the sync converges each (item, org) from the scope, switches and installs it reads under the org's lock, and the installer re-checks under the org row lock, so a second run changes nothing";
193
197
  readonly processedIn: "packages/kernel/src/catalog/scope-sync-workers.ts";
194
198
  readonly opts: {
195
- readonly attempts: 5;
199
+ readonly attempts: 7;
196
200
  readonly backoff: {
197
201
  readonly type: "exponential";
198
- readonly delay: 60000;
202
+ readonly delay: 5000;
199
203
  };
200
204
  readonly removeOnComplete: true;
201
205
  readonly removeOnFail: true;
@@ -206,7 +210,11 @@ export declare const OUTBOX_JOBS: {
206
210
  readonly idempotent: "the sync converges each (item, org) of the org from what it reads, so a second run changes nothing";
207
211
  readonly processedIn: "packages/kernel/src/catalog/scope-sync-workers.ts";
208
212
  readonly opts: {
209
- readonly attempts: 1;
213
+ readonly attempts: 7;
214
+ readonly backoff: {
215
+ readonly type: "exponential";
216
+ readonly delay: 5000;
217
+ };
210
218
  readonly removeOnComplete: true;
211
219
  readonly removeOnFail: true;
212
220
  };
@@ -1,3 +1,21 @@
1
+ /**
2
+ * The plugin scope queue's one retry policy (`scope-item`, `scope-item-chunk`, `scope-org`): 7
3
+ * attempts, 5 s doubling, so the retries wait 5 + 10 + 20 + 40 + 80 + 160 = 315 s (about five
4
+ * minutes) before the last attempt. That is the window a replica has to load an extension its
5
+ * deploy enabled: the enable's `kernel.plugins.changed` message reconciles every replica at once,
6
+ * and if a replica misses it, its periodic reconcile does within
7
+ * `extensionHost.reconcileIntervalSeconds` (default 60 s). An interval longer than the window (it
8
+ * is not capped: tests set an hour to keep the periodic reconcile out of the way) leaves such a
9
+ * replica's chunk to its last attempt, which records `catalog.not_deployed` for the pair until the
10
+ * next sync of the item.
11
+ * Removed once done, so the next add of the same id is not swallowed.
12
+ */
13
+ const SCOPE_JOB_OPTS = {
14
+ attempts: 7,
15
+ backoff: { type: "exponential", delay: 5_000 },
16
+ removeOnComplete: true,
17
+ removeOnFail: true,
18
+ };
1
19
  /**
2
20
  * Every job name added through the outbox. The task that introduces a job name adds its entry; a
3
21
  * name without one does not type-check as an `OutboxJobName` (`add` does not check it at runtime).
@@ -157,40 +175,38 @@ export const OUTBOX_JOBS = {
157
175
  removeOnFail: true,
158
176
  },
159
177
  },
160
- // `catalog/scope-sync.ts` SCOPE_ITEM_JOB: owed by every transaction that changes an item's
161
- // scope, disabled flag, list, owner or platform version, under `scopeItemJobId` (one per scope
162
- // version), and by a sync deferred on a replica that had not loaded the extension yet, under
163
- // `scopeRetryJobId` with `runAt` (spec §8.1)
178
+ // `catalog/scope-jobs.ts` SCOPE_ITEM_JOB: owed by every transaction that changes what an item's
179
+ // sync converges to (its scope, disabled flag, list, owner or platform version, an import's
180
+ // commit deploying no extension) and by the deploy of its extension (enable, a new version of an
181
+ // enabled one, an approval), under `scopeItemJobId` (one per owing transaction, spec §8.1)
164
182
  "scope-item": {
165
183
  queue: "cap-kernel-plugin-scope",
166
- idempotent: "the sync converges each (item, org) from the scope, switches and installs it reads under the org's lock, and the installer re-checks under the org row lock, so a second run changes nothing",
184
+ idempotent: "the fan-out owes the same chunk job ids again (`<item job id>-c<n>`), which the outbox and BullMQ dedupe, and each chunk converges from what it reads",
167
185
  processedIn: "packages/kernel/src/catalog/scope-sync-workers.ts",
168
- // one attempt (a pair's failure is recorded, not retried); removed once done, so the next
169
- // add of the same id is not swallowed
170
- opts: { attempts: 1, removeOnComplete: true, removeOnFail: true },
186
+ // the plugin scope queue's one retry policy (a PG or Redis blip); removed once done, so the
187
+ // next add of the same id is not swallowed
188
+ opts: SCOPE_JOB_OPTS,
171
189
  },
172
- // `catalog/scope-jobs.ts` SCOPE_BACKSTOP_JOB: owed by a confirmation's commit (an import, a
173
- // permissions confirm, an org upload's first version) with `runAt` 5 min on, under
174
- // `scopeBackstopJobId`, so a crash before the post-deploy add still converges (ruling R24)
175
- "scope-item-backstop": {
190
+ // `catalog/scope-jobs.ts` SCOPE_CHUNK_JOB: owed by a scope-item job, one per chunk of orgs, under
191
+ // `scopeChunkJobId`
192
+ "scope-item-chunk": {
176
193
  queue: "cap-kernel-plugin-scope",
177
- idempotent: "the sync converges each (item, org) from what it reads, as a scope-item job does, so a run after the immediate job changes nothing",
194
+ idempotent: "the sync converges each (item, org) from the scope, switches and installs it reads under the org's lock, and the installer re-checks under the org row lock, so a second run changes nothing",
178
195
  processedIn: "packages/kernel/src/catalog/scope-sync-workers.ts",
179
- // retried while the item's extension is not enabled on the deployment yet (the job throws):
180
- // 1, 2, 4, 8 min; removed once done
181
- opts: {
182
- attempts: 5,
183
- backoff: { type: "exponential", delay: 60_000 },
184
- removeOnComplete: true,
185
- removeOnFail: true,
186
- },
196
+ // retried while the item's extension is enabled but not loaded on the replica (the job throws
197
+ // after its other pairs, P3-38): 5 s doubling, about five minutes in all; the last attempt
198
+ // installs anyway and records what fails. A pair's own failure is recorded and does not fail
199
+ // the job; a retry of a deferred chunk attempts every pair again, a failed one included
200
+ // (idempotent: it converges from what it reads)
201
+ opts: SCOPE_JOB_OPTS,
187
202
  },
188
- // `catalog/scope-sync.ts` SCOPE_ORG_JOB: owed by an org's creation, under `scopeOrgJobId`
203
+ // `catalog/scope-jobs.ts` SCOPE_ORG_JOB: owed by an org's creation, under `scopeOrgJobId`
189
204
  "scope-org": {
190
205
  queue: "cap-kernel-plugin-scope",
191
206
  idempotent: "the sync converges each (item, org) of the org from what it reads, so a second run changes nothing",
192
207
  processedIn: "packages/kernel/src/catalog/scope-sync-workers.ts",
193
- opts: { attempts: 1, removeOnComplete: true, removeOnFail: true },
208
+ // as a chunk job: retried while one of its items' extensions is not loaded on the replica
209
+ opts: SCOPE_JOB_OPTS,
194
210
  },
195
211
  // `catalog/job-ids.ts` OWNED_PLUGIN_CLEANUP_JOB: owed by the removal of an org-owned plugin
196
212
  // (and by a confirmation that took out the extension of an item removed meanwhile), under
@@ -38,7 +38,6 @@ import { GatewayRole } from "../roles/gateway-role.js";
38
38
  import { WorkerRole } from "../roles/worker-role.js";
39
39
  import { UsageReporter } from "../runtime/usage-report.js";
40
40
  import { sandboxConfigWarnings } from "../sandbox/sandbox.service.js";
41
- import { warnLegacyToolKeys } from "../tools/legacy-data.js";
42
41
  import { KERNEL_APP_OPTIONS } from "./tokens.js";
43
42
  /**
44
43
  * The stop phase budgets. Each phase waits `min(its budget, what is left of the total)`, where the
@@ -204,10 +203,6 @@ let KernelLifecycle = class KernelLifecycle {
204
203
  // In flight for the stop: aborted when the shutdown begins, which then waits for its session to end
205
204
  await this.shutdown.trackInFlight(migrate(config.db.url, { schema: KERNEL_SCHEMA, dir: KERNEL_MIGRATIONS_DIR }, { connectTimeoutMs: config.db.connectTimeoutMs, signal: this.shutdown.signal }));
206
205
  this.checkpoint();
207
- // Rows still holding a release-candidate tool key that migration 0063 could not map: one
208
- // read-only count, a WARN when there are any (tool naming spec §8.2); never blocks the start
209
- await warnLegacyToolKeys(this.kdb.db, this.log).catch((e) => this.log.warn("tools.legacy_key_count_failed", { error: errMsg(e) }));
210
- this.checkpoint();
211
206
  // official 清单来源按配置同步(幂等;每个副本启动时都做)
212
207
  await this.marketplaces.syncOfficialFromConfig();
213
208
  // The bootstrap plugins (spec §7), once per manifest across replicas (the Redis lock
@@ -255,8 +250,7 @@ let KernelLifecycle = class KernelLifecycle {
255
250
  // start gate: their timers are armed at application bootstrap, but no tick runs before the
256
251
  // worker role opens the start gate here; the runOnStart jobs run then), the gateway role's
257
252
  // supervisor and webhook inbound
258
- if (worker)
259
- await worker.start(() => this.checkpoint());
253
+ worker?.start();
260
254
  if (gateway)
261
255
  await gateway.start(() => this.checkpoint());
262
256
  // Routes stay mounted and are resolved live: 503 extension.unavailable after an extension is revoked, back after it reloads (C17)
@@ -64,13 +64,12 @@ export declare class ModelEnablement {
64
64
  private disabledKeys;
65
65
  private rowsOf;
66
66
  /**
67
- * The extensions `orgId` explicitly turned off: a row of the org's own switch
68
- * (`extension_org_configs.enabled = false`, what the org's extension or plugin switch writes when
69
- * an org admin turns it off), never a required bootstrap plugin. An extension with no row for the
70
- * org is not in the set (it keeps working as before: spec A §8 with B's no-breakage anti-goal).
71
- * Read from PG on every call (one small query; the switch has its own writers, nothing to evict).
67
+ * The extensions enabled in `orgId` ({@link enabledExtensionsQuery}: the org's own switch on, or
68
+ * a required bootstrap plugin): a model provider is on in an org only then, like every other
69
+ * extension. Read from PG on every call (one small query; the switch has its own writers, nothing
70
+ * to evict).
72
71
  */
73
- switchedOff(orgId: string): Promise<Set<string>>;
72
+ enabledIn(orgId: string): Promise<Set<string>>;
74
73
  /** Whether neither the platform nor `orgId` disabled the model (the lists only; see the class). */
75
74
  isEnabled(orgId: string, provider: string, model: string): Promise<boolean>;
76
75
  /**
@@ -9,6 +9,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
9
9
  };
10
10
  import { Inject, Injectable, Module } from "@nestjs/common";
11
11
  import { ApiError } from "../errors.js";
12
+ import { enabledExtensionsQuery } from "../extensions/enabled.js";
12
13
  import { ExtensionRegistry, ExtensionRegistryModule } from "../extensions/registry.js";
13
14
  import { audit } from "../identity/audit.js";
14
15
  import { SuperAdminLock, SuperAdminLockModule } from "../identity/super-admin.js";
@@ -73,21 +74,13 @@ let ModelEnablement = class ModelEnablement {
73
74
  return q.execute();
74
75
  }
75
76
  /**
76
- * The extensions `orgId` explicitly turned off: a row of the org's own switch
77
- * (`extension_org_configs.enabled = false`, what the org's extension or plugin switch writes when
78
- * an org admin turns it off), never a required bootstrap plugin. An extension with no row for the
79
- * org is not in the set (it keeps working as before: spec A §8 with B's no-breakage anti-goal).
80
- * Read from PG on every call (one small query; the switch has its own writers, nothing to evict).
77
+ * The extensions enabled in `orgId` ({@link enabledExtensionsQuery}: the org's own switch on, or
78
+ * a required bootstrap plugin): a model provider is on in an org only then, like every other
79
+ * extension. Read from PG on every call (one small query; the switch has its own writers, nothing
80
+ * to evict).
81
81
  */
82
- async switchedOff(orgId) {
83
- const rows = await this.db
84
- .selectFrom("extension_org_configs as eoc")
85
- .leftJoin("extension_installs as ri", (j) => j.onRef("ri.name", "=", "eoc.plugin").on("ri.required", "=", true))
86
- .select("eoc.plugin")
87
- .where("eoc.org_id", "=", orgId)
88
- .where("eoc.enabled", "=", false)
89
- .where("ri.name", "is", null)
90
- .execute();
82
+ async enabledIn(orgId) {
83
+ const rows = await enabledExtensionsQuery(this.db, orgId).execute();
91
84
  return new Set(rows.map((r) => r.plugin));
92
85
  }
93
86
  /** Whether neither the platform nor `orgId` disabled the model (the lists only; see the class). */
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Organizations: orgs, org settings, members, invitations, offboarding (with its sweep cron) and
3
- * directory sync (the hourly scan cron, one-off syncs on the maintenance queue).
2
+ * Organizations: orgs, org settings, members, invitations, offboarding (its owed work goes through
3
+ * the outbox) and directory sync (the hourly scan cron, one-off syncs on the maintenance queue).
4
4
  */
5
5
  export declare class OrgsModule {
6
6
  }
@@ -24,8 +24,8 @@ import { OrgLockModule } from "./org-lock.js";
24
24
  import { OrgsService } from "./orgs.service.js";
25
25
  import { OrgSettingsModule } from "./settings.service.js";
26
26
  /**
27
- * Organizations: orgs, org settings, members, invitations, offboarding (with its sweep cron) and
28
- * directory sync (the hourly scan cron, one-off syncs on the maintenance queue).
27
+ * Organizations: orgs, org settings, members, invitations, offboarding (its owed work goes through
28
+ * the outbox) and directory sync (the hourly scan cron, one-off syncs on the maintenance queue).
29
29
  */
30
30
  let OrgsModule = class OrgsModule {
31
31
  };
@@ -1,13 +1,14 @@
1
1
  import { type Principal } from "../identity/principal.js";
2
2
  import { type OrgContext } from "./org.guard.js";
3
- import { type OrgEffectiveNetwork, type OrgSandboxLimits, type OrgSettings, type OrgSettingsDeployment, type OrgSettingsPatch, OrgSettingsService } from "./settings.service.js";
3
+ import { type OrgEffectiveNetwork, type OrgSandboxLimits, type OrgSettingsDeployment, type OrgSettingsPatch, OrgSettingsService, type OrgSettingsView } from "./settings.service.js";
4
4
  /**
5
5
  * 组织设置(`/api/v1/orgs/:orgId/settings`):成员可读,修改需 `org.update`(admin)。
6
6
  * 响应带 `deployment`(部署默认值,如沙箱出站),设置页据此展示「跟随部署」时的实际取值;
7
7
  * 以及只读的 `sandboxLimits`(组织实际生效的沙箱 cpu / 内存与来源,超级管理员在部署设置里覆盖,C19)。
8
8
  */
9
9
  type SettingsResponse = {
10
- settings: OrgSettings;
10
+ /** `scheduledTasks.forbiddenToolsUnreadable: true` when the stored list cannot be read. */
11
+ settings: OrgSettingsView;
11
12
  deployment: OrgSettingsDeployment;
12
13
  /** The org's effective sandbox-mode network (org egress ceiling spec §D4). */
13
14
  effectiveNetwork: OrgEffectiveNetwork;
@@ -10,13 +10,18 @@ import type { KernelLogger } from "../log.js";
10
10
  import { type DevicesAutoModeView } from "../sandbox/platform-auto-mode.js";
11
11
  import { OrgLock } from "./org-lock.js";
12
12
  /**
13
- * 组织设置(`capybara.orgs.settings` jsonb)。读取宽松:缺失或非法的字段按默认值,未知键保留不动
14
- * (更新时与存量合并),新版本加字段不需要迁移。
15
- * - `toolSearch`:工具超过阈值时是否改用目录 + `ToolSearch`(D11,默认 on)。
16
- * - `locale`:组织默认语言(`zh` / `en`,默认 en),机器人在 IM 里说的固定话术按它选择。
17
- * - `sandboxToolPolicy`:沙箱工具的默认策略(M5 T8,默认 allow)。为 `ask` 时除只读的
18
- * `Read` / `Glob` / `Grep` 外都需要审批(执行时实时读取)。
19
- * - `wakeOnBackgroundTask`:组织对 `runtime.wakeOnBackgroundTask` 的覆盖(缺省跟随部署),见 {@link effectiveWakeOnBackgroundTask}。
13
+ * Org settings (`capybara.orgs.settings` jsonb). Read leniently: a missing or invalid field reads
14
+ * as its default and unknown keys are kept (merged with the stored value on update), so a new
15
+ * field needs no migration.
16
+ * - `toolSearch`: whether to switch to a catalog + `ToolSearch` once the tools pass the threshold
17
+ * (D11, default on).
18
+ * - `locale`: the org's default language (`zh` / `en`, default en); the bot's fixed phrases in IM
19
+ * follow it.
20
+ * - `sandboxToolPolicy`: the default policy of the sandbox tools (M5 T8, default allow). With
21
+ * `ask`, every tool but the read-only `Read` / `Glob` / `Grep` needs approval (read live at
22
+ * execution). An invalid stored value reads as `ask` (narrower, never wider) and is logged.
23
+ * - `wakeOnBackgroundTask`: the org's override of `runtime.wakeOnBackgroundTask` (absent follows
24
+ * the deployment), see {@link effectiveWakeOnBackgroundTask}.
20
25
  * - `autoMode`: whether devices of the org may run in auto mode (auto mode spec §4.3); absent
21
26
  * follows the platform's `devices.autoMode`, and an invalid stored value reads as `off`
22
27
  * (narrower, never wider). Setting `allowed` while the platform is `off` is refused.
@@ -91,7 +96,9 @@ export type OrgThemeSetting = z.infer<typeof OrgThemeSettingSchema>;
91
96
  export declare const DEFAULT_ORG_THEME: OrgThemeSetting;
92
97
  /**
93
98
  * Org settings of scheduled tasks (spec §9); every field reads leniently (invalid = default,
94
- * except `forbiddenTools`, which keeps its valid entries).
99
+ * except `forbiddenTools`, which keeps its valid entries). A stored `forbiddenTools` that is not a
100
+ * list (or a group that is not an object) reads as `[]` here, for display; enforcement checks
101
+ * {@link invalidStoredForbiddenTools} and fails unattended runs instead (never wider).
95
102
  */
96
103
  export declare const ScheduledTasksSettingsSchema: z.ZodObject<{
97
104
  enabled: z.ZodCatch<z.ZodDefault<z.ZodBoolean>>;
@@ -215,6 +222,17 @@ export declare const OrgSettingsSchema: z.ZodObject<{
215
222
  }, z.core.$strip>>>;
216
223
  }, z.core.$strip>;
217
224
  export type OrgSettings = z.infer<typeof OrgSettingsSchema>;
225
+ /**
226
+ * The settings as the responses carry them: {@link OrgSettings} plus
227
+ * `scheduledTasks.forbiddenToolsUnreadable: true` when the stored list cannot be read
228
+ * ({@link invalidStoredForbiddenTools}; `forbiddenTools` then reads `[]`), so the settings page
229
+ * says so and saves the list. Never stored.
230
+ */
231
+ export type OrgSettingsView = OrgSettings & {
232
+ scheduledTasks: OrgSettings["scheduledTasks"] & {
233
+ forbiddenToolsUnreadable?: true;
234
+ };
235
+ };
218
236
  /** PATCH 体:只改给出的字段;未知字段 → 400。 */
219
237
  export declare const OrgSettingsPatchSchema: z.ZodObject<{
220
238
  toolSearch: z.ZodOptional<z.ZodEnum<{
@@ -332,8 +350,34 @@ export interface OrgSettingsDeployment {
332
350
  }
333
351
  /** 把存储的 jsonb 解析为设置(宽松,见 {@link OrgSettingsSchema})。 */
334
352
  export declare function parseOrgSettings(raw: unknown): OrgSettings;
335
- /** 读组织设置(每次实时读 PG,多副本下改动立即生效);组织不存在或已删除按默认值。 */
336
- export declare function readOrgSettings(db: KernelSchemaDb, orgId: string): Promise<OrgSettings>;
353
+ /** The org's stored settings jsonb, read live; undefined when the org is missing or deleted. */
354
+ export declare function readStoredOrgSettings(db: KernelSchemaDb, orgId: string): Promise<unknown>;
355
+ /**
356
+ * Reads the org settings (live from PG every time, so a change applies at once across replicas);
357
+ * a missing or deleted org reads as the defaults. With `log`, an
358
+ * unreadable security setting ({@link logUnreadableSecuritySettings}) is logged.
359
+ */
360
+ export declare function readOrgSettings(db: KernelSchemaDb, orgId: string,
361
+ /** Per-call paths (the tool policy) log at debug; the settings reads and the fire warn. */
362
+ log?: Pick<KernelLogger, "debug">): Promise<OrgSettings>;
363
+ /** Whether a stored settings object holds a `sandboxToolPolicy` this version reads as `ask`. */
364
+ export declare function invalidStoredSandboxToolPolicy(raw: unknown): boolean;
365
+ /**
366
+ * Whether the stored scheduled-task `forbiddenTools` cannot be read: the group or the field is
367
+ * present but not an object / a list. Unattended runs of such an org fail
368
+ * ({@link FORBIDDEN_TOOLS_UNREADABLE_ERROR}) rather than run with nothing forbidden. Invalid
369
+ * entries inside a list are dropped instead (the valid ones stay forbidden).
370
+ */
371
+ export declare function invalidStoredForbiddenTools(raw: unknown): boolean;
372
+ /** The refusal of an unattended run of an org whose `forbiddenTools` cannot be read. */
373
+ export declare const FORBIDDEN_TOOLS_UNREADABLE_ERROR = "The organization's forbidden tool list for scheduled tasks is unreadable, so this scheduled run cannot continue; an org admin must save the list again in the organization's scheduled task settings.";
374
+ /** The refusal of a new task grant while the org's `forbiddenTools` cannot be read. */
375
+ export declare const FORBIDDEN_TOOLS_UNREADABLE_GRANT_ERROR = "The organization's forbidden tool list for scheduled tasks is unreadable, so no tool can be approved for a task now; an org admin must save the list again in the organization's scheduled task settings.";
376
+ /**
377
+ * Logs (through `log`, at the caller's level) the security settings a stored value reads narrower
378
+ * than written, with the org id.
379
+ */
380
+ export declare function logUnreadableSecuritySettings(log: (msg: string, fields: Record<string, unknown>) => void, orgId: string, raw: unknown): void;
337
381
  /** Whether a stored settings object holds an `autoMode` this version reads as `off`. */
338
382
  export declare function invalidStoredAutoMode(raw: unknown): boolean;
339
383
  /** Whether a stored settings object holds a `cloudNetwork` this version reads as an empty allowlist. */
@@ -363,8 +407,9 @@ export declare class OrgSettingsService {
363
407
  * (`devices.autoMode`; the org may follow it, never exceed it).
364
408
  */
365
409
  config: Pick<KernelConfigService, "get" | "fieldSource">, log?: KernelLogger | undefined);
366
- /** Parses stored settings, warning when an invalid `autoMode` narrows to `off` or an invalid
367
- * `cloudNetwork` to an empty allowlist. */
410
+ /** Parses stored settings, warning when an invalid `autoMode` narrows to `off`, an invalid
411
+ * `cloudNetwork` to an empty allowlist, or a security setting reads narrower
412
+ * ({@link logUnreadableSecuritySettings}, warn). */
368
413
  private parseStored;
369
414
  /** 部署默认值(设置页展示「跟随部署」时的实际取值)。 */
370
415
  deployment(): Promise<OrgSettingsDeployment>;
@@ -375,7 +420,7 @@ export declare class OrgSettingsService {
375
420
  effectiveNetwork(settings: Pick<OrgSettings, "cloudNetwork">): OrgEffectiveNetwork;
376
421
  /** 组织实际生效的沙箱 cpu / 内存(只读;由超级管理员在部署设置里覆盖)。 */
377
422
  sandboxLimits(orgId: string): Promise<OrgSandboxLimits>;
378
- get(orgId: string): Promise<OrgSettings>;
423
+ get(orgId: string): Promise<OrgSettingsView>;
379
424
  /**
380
425
  * The refusals of {@link update} that need no read of the org (the Platform tool's precheck):
381
426
  * auto mode where the platform turned it off.
@@ -398,7 +443,7 @@ export declare class OrgSettingsService {
398
443
  */
399
444
  opts?: {
400
445
  onlyNarrows?: boolean;
401
- }): Promise<OrgSettings>;
446
+ }): Promise<OrgSettingsView>;
402
447
  /**
403
448
  * Refuses a patch that widens the org's sandbox (auto mode spec §4.3: only a person widens it,
404
449
  * never the Platform tool or an API token):