@capybara-hq/kernel 0.1.0-rc.132 → 0.1.0-rc.134

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 (173) hide show
  1. package/bootstrap.json +5 -5
  2. package/dist/admin/admin.module.js +3 -0
  3. package/dist/admin/admin.schemas.d.ts +4 -0
  4. package/dist/admin/health.service.d.ts +2 -2
  5. package/dist/admin/health.service.js +6 -2
  6. package/dist/admin/setup.service.js +6 -1
  7. package/dist/agents/agents.controller.js +3 -2
  8. package/dist/agents/agents.service.d.ts +2 -0
  9. package/dist/agents/agents.service.js +7 -0
  10. package/dist/automations/events/trigger-events.service.d.ts +13 -1
  11. package/dist/automations/events/trigger-events.service.js +27 -14
  12. package/dist/catalog/catalog.service.d.ts +2 -0
  13. package/dist/catalog/catalog.service.js +28 -5
  14. package/dist/catalog/marketplace-fetch.d.ts +2 -0
  15. package/dist/catalog/marketplace-fetch.js +15 -0
  16. package/dist/catalog/marketplaces.service.d.ts +4 -4
  17. package/dist/catalog/marketplaces.service.js +3 -2
  18. package/dist/catalog/owned-items.d.ts +2 -0
  19. package/dist/catalog/owned-items.js +30 -31
  20. package/dist/catalog/ownership.js +40 -38
  21. package/dist/catalog/plugin-import.d.ts +3 -4
  22. package/dist/catalog/plugin-import.js +50 -1
  23. package/dist/catalog/plugin-upgrade.d.ts +8 -0
  24. package/dist/catalog/plugin-upgrade.js +95 -7
  25. package/dist/catalog/publisher-policy.d.ts +9 -0
  26. package/dist/catalog/publisher-policy.js +12 -0
  27. package/dist/catalog/unshare.js +66 -58
  28. package/dist/client/client-access.service.js +5 -3
  29. package/dist/config/schema.d.ts +1 -0
  30. package/dist/config/schema.js +8 -1
  31. package/dist/conversations/conversations.controller.js +4 -14
  32. package/dist/conversations/conversations.service.d.ts +14 -0
  33. package/dist/conversations/conversations.service.js +20 -2
  34. package/dist/ctx/create-ctx.d.ts +15 -2
  35. package/dist/ctx/create-ctx.js +195 -79
  36. package/dist/ctx/durable-cancellation.d.ts +3 -0
  37. package/dist/ctx/durable-cancellation.js +8 -0
  38. package/dist/ctx/durable-effects.service.d.ts +81 -0
  39. package/dist/ctx/durable-effects.service.js +316 -0
  40. package/dist/ctx/durable-envelope.d.ts +24 -0
  41. package/dist/ctx/durable-envelope.js +80 -0
  42. package/dist/ctx/durable-failure.d.ts +7 -0
  43. package/dist/ctx/durable-failure.js +32 -0
  44. package/dist/ctx/durable-job.d.ts +9 -0
  45. package/dist/ctx/durable-job.js +2 -0
  46. package/dist/ctx/durable-keys.d.ts +27 -0
  47. package/dist/ctx/durable-keys.js +138 -0
  48. package/dist/ctx/durable-relay.d.ts +29 -0
  49. package/dist/ctx/durable-relay.js +250 -0
  50. package/dist/ctx/queue.d.ts +2 -0
  51. package/dist/ctx/queue.js +25 -15
  52. package/dist/db/extension-db.js +2 -0
  53. package/dist/db/extension-handoff-schema.d.ts +6 -0
  54. package/dist/db/extension-handoff-schema.js +72 -0
  55. package/dist/db/extension-rls-predicate.d.ts +1 -0
  56. package/dist/db/extension-rls-predicate.js +8 -0
  57. package/dist/db/extension-schema-transfer.d.ts +1 -1
  58. package/dist/db/extension-schema-transfer.js +18 -6
  59. package/dist/db/kernel-schema.d.ts +64 -0
  60. package/dist/db/migrator.js +6 -13
  61. package/dist/db/pool.d.ts +2 -2
  62. package/dist/db/pool.js +2 -2
  63. package/dist/db/sql-statements.d.ts +3 -0
  64. package/dist/db/sql-statements.js +15 -5
  65. package/dist/device-access/device-access.module.js +12 -2
  66. package/dist/device-access/device-access.service.d.ts +30 -2
  67. package/dist/device-access/device-access.service.js +38 -4
  68. package/dist/device-access/host-gate.d.ts +45 -0
  69. package/dist/device-access/host-gate.js +92 -0
  70. package/dist/device-access/host-service-stop-sweep.d.ts +33 -0
  71. package/dist/device-access/host-service-stop-sweep.js +112 -0
  72. package/dist/device-access/host-service-stop.d.ts +78 -0
  73. package/dist/device-access/host-service-stop.js +144 -0
  74. package/dist/device-access/host-services.d.ts +211 -0
  75. package/dist/device-access/host-services.js +803 -0
  76. package/dist/device-access/person-handles.d.ts +10 -0
  77. package/dist/device-access/person-handles.js +25 -0
  78. package/dist/device-access/service-events.d.ts +199 -0
  79. package/dist/device-access/service-events.js +704 -0
  80. package/dist/device-access/token.d.ts +5 -0
  81. package/dist/device-access/token.js +5 -0
  82. package/dist/devices/devices.service.js +3 -0
  83. package/dist/dial-in/access.d.ts +5 -5
  84. package/dist/dial-in/access.js +19 -12
  85. package/dist/dial-in/gateway.js +6 -2
  86. package/dist/dial-in/machines.d.ts +9 -2
  87. package/dist/dial-in/machines.js +27 -4
  88. package/dist/erasure/device-cleanup.js +12 -0
  89. package/dist/erasure/org-catalog.js +2 -2
  90. package/dist/erasure/org-rules.js +10 -0
  91. package/dist/errors.d.ts +2 -0
  92. package/dist/errors.js +2 -0
  93. package/dist/extensions/admin-ops.js +8 -2
  94. package/dist/extensions/deployed-snapshots.d.ts +4 -1
  95. package/dist/extensions/deployed-snapshots.js +7 -2
  96. package/dist/extensions/extensions.module.js +10 -0
  97. package/dist/extensions/host.d.ts +12 -2
  98. package/dist/extensions/host.js +44 -22
  99. package/dist/extensions/instance.d.ts +5 -0
  100. package/dist/extensions/instance.js +10 -0
  101. package/dist/extensions/ledger.d.ts +1 -1
  102. package/dist/extensions/lifecycle-hooks.js +3 -3
  103. package/dist/extensions/org-config.js +6 -1
  104. package/dist/extensions/permission-set.d.ts +7 -0
  105. package/dist/extensions/permission-set.js +10 -0
  106. package/dist/extensions/permission-view.d.ts +1 -1
  107. package/dist/extensions/permission-view.js +10 -1
  108. package/dist/extensions/sources.d.ts +1 -0
  109. package/dist/extensions/sources.js +9 -0
  110. package/dist/git/tickets.js +32 -27
  111. package/dist/http/app.js +5 -3
  112. package/dist/identity/accounts.d.ts +6 -1
  113. package/dist/identity/accounts.js +11 -2
  114. package/dist/identity/api-tokens.js +7 -6
  115. package/dist/identity/settings.d.ts +9 -1
  116. package/dist/identity/settings.js +16 -1
  117. package/dist/inbox/inbox-items.service.d.ts +5 -0
  118. package/dist/inbox/inbox-items.service.js +57 -33
  119. package/dist/inbox/org-notices.js +3 -2
  120. package/dist/index.d.ts +1 -0
  121. package/dist/index.js +1 -0
  122. package/dist/infra/database/extension-effect-key-lock.d.ts +10 -0
  123. package/dist/infra/database/extension-effect-key-lock.js +69 -0
  124. package/dist/infra/database/extension-handoff.d.ts +27 -0
  125. package/dist/infra/database/extension-handoff.js +113 -0
  126. package/dist/infra/database/scoped-dialect.d.ts +3 -2
  127. package/dist/infra/database/scoped-dialect.js +260 -72
  128. package/dist/infra/database/startup-activation-transaction.d.ts +2 -0
  129. package/dist/infra/database/startup-activation-transaction.js +3 -2
  130. package/dist/infra/outbox/outbox.dispatcher.d.ts +6 -1
  131. package/dist/infra/outbox/outbox.dispatcher.js +64 -4
  132. package/dist/infra/outbox/outbox.module.js +2 -0
  133. package/dist/infra/outbox/registry.d.ts +40 -0
  134. package/dist/infra/outbox/registry.js +42 -0
  135. package/dist/infra/queue/queue-names.d.ts +1 -1
  136. package/dist/infra/queue/queue-names.js +1 -0
  137. package/dist/infra/queue/run-job.d.ts +4 -1
  138. package/dist/infra/queue/run-job.js +10 -2
  139. package/dist/kernel.js +1 -0
  140. package/dist/kernel.module.js +3 -0
  141. package/dist/orgs/offboarding.js +18 -9
  142. package/dist/orgs/orgs.service.js +16 -0
  143. package/dist/orgs/settings.service.js +3 -0
  144. package/dist/packages/npm-publish-keys.json +27 -0
  145. package/dist/packages/official-publisher.d.ts +19 -0
  146. package/dist/packages/official-publisher.js +152 -0
  147. package/dist/packages/provenance.d.ts +7 -0
  148. package/dist/packages/provenance.js +22 -19
  149. package/dist/packages/sigstore-trusted-root.json +126 -0
  150. package/dist/platform/ops/admin.ops.js +2 -1
  151. package/dist/platform/ops/orgs.ops.js +1 -0
  152. package/dist/roles/worker-role.d.ts +6 -3
  153. package/dist/roles/worker-role.js +12 -4
  154. package/dist/roles/worker.module.js +9 -0
  155. package/dist/runtime/maintenance.d.ts +5 -2
  156. package/dist/runtime/maintenance.js +18 -4
  157. package/dist/sandbox/device-reports.d.ts +4 -4
  158. package/dist/sandbox/device-reports.js +40 -30
  159. package/dist/sandbox/device-services.d.ts +2 -1
  160. package/dist/sandbox/device-services.js +5 -1
  161. package/dist/sandbox/permission-ceiling-writes.d.ts +8 -0
  162. package/dist/sandbox/permission-ceiling-writes.js +21 -0
  163. package/dist/sandbox/permission-config-publication.js +5 -1
  164. package/dist/themes/theme-state.js +24 -13
  165. package/dist/tools/call-scope.d.ts +6 -0
  166. package/dist/tools/call-scope.js +22 -0
  167. package/dist/tools/registry.js +20 -2
  168. package/dist/ui/views.js +36 -8
  169. package/package.json +9 -4
  170. package/src/migrations/0222_device_host_services.sql +27 -0
  171. package/src/migrations/0223_device_service_events.sql +54 -0
  172. package/src/migrations/0224_cache_conversation_rls_settings.sql +33 -0
  173. package/src/migrations/0225_extension_effect_receipts.sql +25 -0
package/bootstrap.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "schemaVersion": 1,
4
4
  "marketplace": {
5
5
  "url": "https://github.com/capybara-hq/plugins.git",
6
- "commit": "28d1cfdacc69af3ed2020622d973c681e9f7fc10"
6
+ "commit": "51e2cc85e7d660867500f23259d883459bd2609f"
7
7
  },
8
8
  "plugins": [
9
9
  {
@@ -98,8 +98,8 @@
98
98
  "name": "device-local",
99
99
  "source": "npm",
100
100
  "npm": "@capybara-hq/plugin-device-local",
101
- "version": "0.1.0-rc.19",
102
- "integrity": "sha512-2v2iT3YWZJs42PYXSDZQ9lrU7vALnb7aYRHlYLvWw+kFmrDb51ZlyXKWPjgi1WhzUTk3Zcp5f2WNcnbjiTm97Q==",
101
+ "version": "0.1.0-rc.20",
102
+ "integrity": "sha512-oMR3xqkG2x+eX2XCSHmdO6yMHRQxD4oqFVZzGc56vvaUcESPl0Sz9JleMRl+RSa3EQQWcqSgtaP2z6TUcJfKzw==",
103
103
  "required": false,
104
104
  "scope": "all"
105
105
  },
@@ -107,8 +107,8 @@
107
107
  "name": "todo",
108
108
  "source": "npm",
109
109
  "npm": "@capybara-hq/plugin-todo",
110
- "version": "0.1.0-rc.16",
111
- "integrity": "sha512-4jJ8uJ96d9Z1s30j9gDi+EKxgLyOctRw0rZXd20eSRW80/a+obmuSYPoZStuBxB7O+4SqF+dzGZxmBDlYRjWmA==",
110
+ "version": "0.1.0-rc.17",
111
+ "integrity": "sha512-LsvKWz3LD+XJNqiXj0RgG6JGT3mPI5ZF2VYuWE93ns0usKzkbiJZ9JlYF4sHsNzHfVhwqCi8uhfY/EOe6vA8gQ==",
112
112
  "required": false
113
113
  },
114
114
  {
@@ -10,6 +10,7 @@ import { TemplateConnectorsQueueModule } from "../catalog/template-connector-job
10
10
  import { ChannelsModule } from "../channels/channels.module.js";
11
11
  import { PromptSuggestionsModule } from "../conversations/prompt-suggestions.js";
12
12
  import { TitlesModule } from "../conversations/titles.js";
13
+ import { DeviceServiceEventsModule } from "../device-access/service-events.js";
13
14
  import { ErasureModule } from "../erasure/erasure.module.js";
14
15
  import { EvalsModule } from "../evals/evals.module.js";
15
16
  import { ExtensionsModule } from "../extensions/extensions.module.js";
@@ -72,6 +73,8 @@ AdminModule = __decorate([
72
73
  ConnectorToolsQueueModule,
73
74
  ToolWatchQueueModule,
74
75
  TemplateConnectorsQueueModule,
76
+ // the device service events queue the overview counts
77
+ DeviceServiceEventsModule,
75
78
  // the price table of the usage aggregate
76
79
  ModelsModule,
77
80
  ],
@@ -81,6 +81,10 @@ export declare const DeploymentSettingsBody: z.ZodObject<{
81
81
  }, z.core.$strict>>;
82
82
  }, z.core.$strict>>;
83
83
  }, z.core.$strict>>>;
84
+ officialPublisherProof: z.ZodOptional<z.ZodEnum<{
85
+ "pin-only": "pin-only";
86
+ require: "require";
87
+ }>>;
84
88
  priceCurrency: z.ZodOptional<z.ZodString>;
85
89
  sandboxLimitOverrides: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNullable<z.ZodObject<{
86
90
  cpu: z.ZodOptional<z.ZodNumber>;
@@ -5,7 +5,7 @@ import { type LiveReplica, ReplicaPresence } from "../infra/presence/replica-pre
5
5
  import type { KernelLogger } from "../log.js";
6
6
  import { DeviceProviders } from "../sandbox/providers.js";
7
7
  /** The kernel's own queues, in the order the overview lists them (extension queues are not read). */
8
- export declare const KERNEL_QUEUE_NAMES: readonly ["cap-kernel-runs", "cap-kernel-subagent-runs", "cap-kernel-channels", "cap-kernel-maintenance", "cap-kernel-tool-watch", "cap-kernel-plugin-scope", "cap-kernel-titles", "cap-kernel-suggestions", "cap-kernel-usage-report", "cap-kernel-evals", "cap-kernel-lifecycle", "cap-push-deliver", "cap-connector-tools", "cap-template-connectors"];
8
+ export declare const KERNEL_QUEUE_NAMES: readonly ["cap-kernel-runs", "cap-kernel-subagent-runs", "cap-kernel-channels", "cap-kernel-maintenance", "cap-kernel-tool-watch", "cap-kernel-plugin-scope", "cap-kernel-titles", "cap-kernel-suggestions", "cap-kernel-usage-report", "cap-kernel-evals", "cap-kernel-lifecycle", "cap-push-deliver", "cap-connector-tools", "cap-template-connectors", "cap-device-service-events"];
9
9
  /** How long each source's reads may take before the answer marks it unavailable. */
10
10
  export declare const HEALTH_READ_TIMEOUT_MS = 3000;
11
11
  /** A live replica as the overview shows it. */
@@ -110,7 +110,7 @@ export declare class AdminHealthService {
110
110
  private readonly log;
111
111
  private readonly providers;
112
112
  private readonly queues;
113
- constructor(presence: Pick<ReplicaPresence, "live">, db: KernelDb, redis: Pick<Redis, "zcount" | "status">, log: Pick<KernelLogger, "warn">, providers: Pick<DeviceProviders, "forDevice">, runs: Queue, subagentRuns: Queue, channels: Queue, maintenance: Queue, toolWatch: Queue, pluginScope: Queue, titles: Queue, suggestions: Queue, usageReport: Queue, evals: Queue, lifecycle: Queue, push: Queue, connectorTools: Queue, templateConnectors: Queue);
113
+ constructor(presence: Pick<ReplicaPresence, "live">, db: KernelDb, redis: Pick<Redis, "zcount" | "status">, log: Pick<KernelLogger, "warn">, providers: Pick<DeviceProviders, "forDevice">, runs: Queue, subagentRuns: Queue, channels: Queue, maintenance: Queue, toolWatch: Queue, pluginScope: Queue, titles: Queue, suggestions: Queue, usageReport: Queue, evals: Queue, lifecycle: Queue, push: Queue, connectorTools: Queue, templateConnectors: Queue, serviceEvents: Queue);
114
114
  read(): Promise<AdminHealth>;
115
115
  private readRedis;
116
116
  private readDb;
@@ -15,6 +15,7 @@ import { TEMPLATE_CONNECTORS_QUEUE } from "../catalog/template-connector-jobs.js
15
15
  import { CHANNEL_QUEUE_NAME } from "../channels/jobs.js";
16
16
  import { PROMPT_SUGGESTION_QUEUE } from "../conversations/prompt-suggestions.js";
17
17
  import { TITLE_QUEUE } from "../conversations/titles.js";
18
+ import { SERVICE_EVENTS_QUEUE } from "../device-access/service-events.js";
18
19
  import { EVAL_QUEUE_NAME } from "../evals/jobs.js";
19
20
  import { LIFECYCLE_QUEUE } from "../extensions/lifecycle-hooks.js";
20
21
  import { KernelDb } from "../infra/database/kernel-db.js";
@@ -45,6 +46,7 @@ export const KERNEL_QUEUE_NAMES = [
45
46
  PUSH_QUEUE,
46
47
  CONNECTOR_TOOLS_QUEUE,
47
48
  TEMPLATE_CONNECTORS_QUEUE,
49
+ SERVICE_EVENTS_QUEUE,
48
50
  ];
49
51
  /** How long each source's reads may take before the answer marks it unavailable. */
50
52
  export const HEALTH_READ_TIMEOUT_MS = 3_000;
@@ -73,7 +75,7 @@ let AdminHealthService = class AdminHealthService {
73
75
  log;
74
76
  providers;
75
77
  queues;
76
- constructor(presence, db, redis, log, providers, runs, subagentRuns, channels, maintenance, toolWatch, pluginScope, titles, suggestions, usageReport, evals, lifecycle, push, connectorTools, templateConnectors) {
78
+ constructor(presence, db, redis, log, providers, runs, subagentRuns, channels, maintenance, toolWatch, pluginScope, titles, suggestions, usageReport, evals, lifecycle, push, connectorTools, templateConnectors, serviceEvents) {
77
79
  this.presence = presence;
78
80
  this.db = db;
79
81
  this.redis = redis;
@@ -95,6 +97,7 @@ let AdminHealthService = class AdminHealthService {
95
97
  push,
96
98
  connectorTools,
97
99
  templateConnectors,
100
+ serviceEvents,
98
101
  ];
99
102
  }
100
103
  async read() {
@@ -307,6 +310,7 @@ AdminHealthService = __decorate([
307
310
  __param(15, Inject(getQueueToken(LIFECYCLE_QUEUE))),
308
311
  __param(16, Inject(getQueueToken(PUSH_QUEUE))),
309
312
  __param(17, Inject(getQueueToken(CONNECTOR_TOOLS_QUEUE))),
310
- __param(18, Inject(getQueueToken(TEMPLATE_CONNECTORS_QUEUE)))
313
+ __param(18, Inject(getQueueToken(TEMPLATE_CONNECTORS_QUEUE))),
314
+ __param(19, Inject(getQueueToken(SERVICE_EVENTS_QUEUE)))
311
315
  ], AdminHealthService);
312
316
  export { AdminHealthService };
@@ -12,6 +12,7 @@ import { ApiError } from "../errors.js";
12
12
  import { AccountsService } from "../identity/accounts.js";
13
13
  import { audit } from "../identity/audit.js";
14
14
  import { KernelDb } from "../infra/database/kernel-db.js";
15
+ import { withOrgScope } from "../infra/database/org-scope.js";
15
16
  import { TransactionHost } from "../infra/database/transaction-host.js";
16
17
  import { Transactional } from "../infra/database/transactional.decorator.js";
17
18
  import { OrgsService } from "../orgs/orgs.service.js";
@@ -66,12 +67,16 @@ let SetupService = class SetupService {
66
67
  const org = input.orgName !== undefined
67
68
  ? await this.orgs.create({ name: input.orgName }, account)
68
69
  : undefined;
69
- await audit(this.db.db, {
70
+ const recordSetup = () => audit(this.db.db, {
70
71
  actorAccountId: account.id,
71
72
  action: "deployment.setup_completed",
72
73
  target: account.id,
73
74
  ...(org && { orgId: org.id, detail: { orgId: org.id } }),
74
75
  });
76
+ if (org)
77
+ await withOrgScope(org.id, recordSetup);
78
+ else
79
+ await recordSetup();
75
80
  const extra = inTx ? await inTx(account) : undefined;
76
81
  return { account, ...(org && { org }), extra };
77
82
  }
@@ -96,8 +96,9 @@ let AgentsController = class AgentsController {
96
96
  }, patTokenId(p));
97
97
  }
98
98
  async list(principal, org) {
99
- const agents = await this.agents.listVisible(org.orgId, viewerOf(principal));
100
- return { agents: await this.agents.withTemplateLinks(org.orgId, agents) };
99
+ return {
100
+ agents: await this.agents.listVisibleWithTemplateLinks(org.orgId, viewerOf(principal)),
101
+ };
101
102
  }
102
103
  async get(principal, org, agentId) {
103
104
  return {
@@ -263,6 +263,8 @@ export declare class AgentsService {
263
263
  get(orgId: string, agentId: string, viewerAccountId: string | null): Promise<AgentView>;
264
264
  /** 组织内对 viewer 可见的全部 agent(按创建时间)。 */
265
265
  listVisible(orgId: string, viewerAccountId: string | null): Promise<AgentView[]>;
266
+ /** One read transaction for the HTTP list and its template availability. */
267
+ listVisibleWithTemplateLinks(orgId: string, viewerAccountId: string | null): Promise<AgentView[]>;
266
268
  /** 读某个版本(不做可见性判定,调用方负责);不存在 → `agent.not_found`。 */
267
269
  getVersion(agentId: string, version: number): Promise<AgentVersion>;
268
270
  /** 版本列表,新的在前(不做可见性判定,调用方负责)。 */
@@ -890,6 +890,10 @@ let AgentsService = class AgentsService {
890
890
  listVisible(orgId, viewerAccountId) {
891
891
  return this.lookup.listVisible(orgId, viewerAccountId);
892
892
  }
893
+ /** One read transaction for the HTTP list and its template availability. */
894
+ async listVisibleWithTemplateLinks(orgId, viewerAccountId) {
895
+ return this.withTemplateLinks(orgId, await this.listVisible(orgId, viewerAccountId));
896
+ }
893
897
  /** 读某个版本(不做可见性判定,调用方负责);不存在 → `agent.not_found`。 */
894
898
  async getVersion(agentId, version) {
895
899
  const r = await this.db
@@ -955,6 +959,9 @@ __decorate([
955
959
  __decorate([
956
960
  Transactional({ propagation: "mandatory" })
957
961
  ], AgentsService.prototype, "reassignOwnerLocked", null);
962
+ __decorate([
963
+ Transactional({ accessMode: "read only" })
964
+ ], AgentsService.prototype, "listVisibleWithTemplateLinks", null);
958
965
  AgentsService = __decorate([
959
966
  Injectable(),
960
967
  __param(0, Inject(KernelDb)),
@@ -16,6 +16,16 @@ export declare const TRIGGER_URL_MAX_BYTES = 2048;
16
16
  export declare const TRIGGER_FACT_LIST_MAX_ITEMS = 64;
17
17
  /** How long a cause handle (`ctx.triggers.causeOf`) is accepted. */
18
18
  export declare const TRIGGER_CAUSE_HANDLE_TTL_MS: number;
19
+ /** Who caused an event, as the kernel verified it. */
20
+ export interface VerifiedCause {
21
+ runId: string | null;
22
+ accountId: string | null;
23
+ depth: number;
24
+ causeWindow?: {
25
+ createdAt: number;
26
+ expiresAt: number;
27
+ };
28
+ }
19
29
  /**
20
30
  * Stores the events extensions emit (`ctx.triggers.emit`, collaboration spec §4.2) and owes their
21
31
  * dispatch. The emitting extension, the event types it may emit (its approved manifest's
@@ -45,10 +55,12 @@ export declare class TriggerEventsService {
45
55
  * Throws `TriggerError`: `type_not_declared`, `invalid_event` (a missing or malformed field, a
46
56
  * forged or foreign cause), `org_disabled` (the plugin is not enabled in the org).
47
57
  */
48
- emit(plugin: string, declared: readonly string[], e: TriggerEvent): Promise<{
58
+ emit(plugin: string, declared: readonly string[], e: TriggerEvent, preparedCause?: VerifiedCause): Promise<{
49
59
  eventId: string;
50
60
  duplicate: boolean;
51
61
  }>;
62
+ /** Validates an intent before the extension records it in its own transaction. */
63
+ prepare(plugin: string, declared: readonly string[], e: TriggerEvent, preparedCause?: VerifiedCause): Promise<VerifiedCause>;
52
64
  /**
53
65
  * A handle for the cause `call` (`ctx.triggers.causeOf`, collaboration spec §4.2) that `plugin`
54
66
  * may pass later as `cause: { handle }`: `call` is verified as `emit` verifies `cause.call` (a
@@ -138,19 +138,9 @@ let TriggerEventsService = class TriggerEventsService {
138
138
  * Throws `TriggerError`: `type_not_declared`, `invalid_event` (a missing or malformed field, a
139
139
  * forged or foreign cause), `org_disabled` (the plugin is not enabled in the org).
140
140
  */
141
- async emit(plugin, declared, e) {
142
- if (!isPlainObject(e))
143
- throw invalid("the event must be an object");
144
- const errs = validateTriggerEvent(e, declared);
145
- if (errs.includes("type_not_declared"))
146
- throw new TriggerError("type_not_declared", `event type "${e.type}" is not declared in permissions.triggers.emit of ${plugin}`);
147
- if (errs.length > 0)
148
- throw invalid(`invalid event: ${errs.join(", ")}`);
149
- checkShape(e);
141
+ async emit(plugin, declared, e, preparedCause) {
142
+ const cause = await this.prepare(plugin, declared, e, preparedCause);
150
143
  const db = this.kdb.db;
151
- if (!(await isExtensionEnabled(db, e.orgId, plugin)))
152
- throw new TriggerError("org_disabled", `${plugin} is not enabled in org ${e.orgId}`);
153
- const cause = await this.verifyCause(plugin, e);
154
144
  const subject = {
155
145
  kind: e.subject.kind,
156
146
  id: e.subject.id,
@@ -199,6 +189,21 @@ let TriggerEventsService = class TriggerEventsService {
199
189
  });
200
190
  return { eventId: id, duplicate: false };
201
191
  }
192
+ /** Validates an intent before the extension records it in its own transaction. */
193
+ async prepare(plugin, declared, e, preparedCause) {
194
+ if (!isPlainObject(e))
195
+ throw invalid("the event must be an object");
196
+ const errs = validateTriggerEvent(e, declared);
197
+ if (errs.includes("type_not_declared"))
198
+ throw new TriggerError("type_not_declared", `event type "${e.type}" is not declared in permissions.triggers.emit of ${plugin}`);
199
+ if (errs.length > 0)
200
+ throw invalid(`invalid event: ${errs.join(", ")}`);
201
+ checkShape(e);
202
+ const db = this.kdb.db;
203
+ if (!(await isExtensionEnabled(db, e.orgId, plugin)))
204
+ throw new TriggerError("org_disabled", `${plugin} is not enabled in org ${e.orgId}`);
205
+ return preparedCause ?? this.verifyCause(plugin, e);
206
+ }
202
207
  /**
203
208
  * A handle for the cause `call` (`ctx.triggers.causeOf`, collaboration spec §4.2) that `plugin`
204
209
  * may pass later as `cause: { handle }`: `call` is verified as `emit` verifies `cause.call` (a
@@ -253,7 +258,7 @@ let TriggerEventsService = class TriggerEventsService {
253
258
  const row = nonEmpty(cause.handle)
254
259
  ? await db
255
260
  .selectFrom("trigger_cause_handles")
256
- .select(["run_id", "depth", "cause_account_id"])
261
+ .select(["run_id", "depth", "cause_account_id", "created_at", "expires_at"])
257
262
  .where("id", "=", cause.handle)
258
263
  .where("org_id", "=", e.orgId)
259
264
  .where("plugin", "=", plugin)
@@ -272,7 +277,15 @@ let TriggerEventsService = class TriggerEventsService {
272
277
  .executeTakeFirst();
273
278
  if (run === undefined)
274
279
  throw invalid("the cause's run is not one of the event's org");
275
- return { runId: run.id, accountId: row.cause_account_id, depth: row.depth };
280
+ return {
281
+ runId: run.id,
282
+ accountId: row.cause_account_id,
283
+ depth: row.depth,
284
+ causeWindow: {
285
+ createdAt: row.created_at.getTime(),
286
+ expiresAt: row.expires_at.getTime(),
287
+ },
288
+ };
276
289
  }
277
290
  if (!nonEmpty(cause.accountId))
278
291
  throw invalid("cause.accountId must be an account id");
@@ -8,6 +8,7 @@ import { KernelConfigService } from "../infra/config/kernel-config.service.js";
8
8
  import { KernelDb } from "../infra/database/kernel-db.js";
9
9
  import { TransactionHost } from "../infra/database/transaction-host.js";
10
10
  import { OrgLock } from "../orgs/org-lock.js";
11
+ import type { OfficialPublisherProof } from "../packages/official-publisher.js";
11
12
  import type { TranslationReport } from "./claude/report.js";
12
13
  import { type GitLocation } from "./git-source.js";
13
14
  import { MarketplacesService } from "./marketplaces.service.js";
@@ -133,6 +134,7 @@ export type SourceDetail = GitSourceDetail | {
133
134
  url: string;
134
135
  } | {
135
136
  registry: string;
137
+ publisherProof?: OfficialPublisherProof;
136
138
  };
137
139
  /** The source kinds of a catalog version. */
138
140
  export type CatalogVersionSource = "file" | "npm" | "marketplace" | "git" | "bootstrap";
@@ -25,10 +25,11 @@ import { sameRepository } from "../packages/provenance.js";
25
25
  import { assertNotPlatformDefault } from "../themes/theme-usage.js";
26
26
  import { countInstalls, inAuthorOrder, itemConfirmations, itemScopeFacts, itemView, marketplaceLatest, versionUsable, } from "./catalog-items.js";
27
27
  import { expandGitUrl, GitSourceError, gitErrorDetails, normalGitPath, readGitTreeAndOids, resolveGitCommit, } from "./git-source.js";
28
- import { fetchMarketplaceArchive, marketplaceNetPolicy, marketplaceUrlProblem, } from "./marketplace-fetch.js";
28
+ import { fetchMarketplaceArchive, marketplaceNetPolicy, marketplaceUrlProblem, requireMarketplacePublisher, } from "./marketplace-fetch.js";
29
29
  import { assertEntryNotDeprecated, entryCompatible, entrySourceHost, HOST_VERSIONS, hostAllowed, loadMarketplaceEntry, MarketplacesService, pluginNameFrom, } from "./marketplaces.service.js";
30
30
  import { switchOffItemConnectors } from "./plugin-connectors.js";
31
31
  import { PluginImport } from "./plugin-import.js";
32
+ import { OFFICIAL_MARKETPLACE_ID, officialPublisherProofMode } from "./publisher-policy.js";
32
33
  import { cancelPendingRequests } from "./request-rules.js";
33
34
  import { newestFirst } from "./versions.js";
34
35
  const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
@@ -168,6 +169,10 @@ let CatalogService = class CatalogService {
168
169
  }
169
170
  assertEntryNotDeprecated(entry);
170
171
  const src = entry.source;
172
+ const official = marketplace.builtin && input.marketplaceId === OFFICIAL_MARKETPLACE_ID;
173
+ if (official && !("npm" in src)) {
174
+ throw new ApiError("marketplace.publisher_unverified", "Official marketplace entries must name a published npm revision with publisher proof");
175
+ }
171
176
  const host = entrySourceHost(entry);
172
177
  if (host !== undefined && !hostAllowed(host, config)) {
173
178
  throw new ApiError("marketplace.host_not_allowed", `Marketplace entry ${entry.name} downloads from ${host}, which is not in marketplaces.allowedHosts`, [{ host, entry: entry.name }]);
@@ -194,10 +199,28 @@ let CatalogService = class CatalogService {
194
199
  got = await this.installs.fetchMarketplacePackage({ package: src.npm.package, version: src.npm.version, integrity: src.npm.integrity }, opts.signal);
195
200
  ref = `${input.marketplaceId}:${src.npm.package}@${src.npm.version}`;
196
201
  detail = { registry: new URL(config.packages.npmRegistry).origin };
197
- const p = await this.installs.fetchProvenance({ package: src.npm.package, version: src.npm.version, integrity: got.integrity }, opts.signal);
198
- // a git marketplace declares its repository: an attestation from another one is a warning
199
- const mismatch = p.checked && marketplace.form === "git" && !sameRepository(p.repository, marketplace.url);
200
- provenance = { provenance: p, ...(mismatch && { warning: "repository_mismatch" }) };
202
+ if (official && (await officialPublisherProofMode(this.db)) === "require") {
203
+ const publisherProof = await requireMarketplacePublisher(config, { name: src.npm.package, version: src.npm.version, integrity: got.integrity }, opts.signal);
204
+ detail.publisherProof = publisherProof;
205
+ provenance = { provenance: publisherProof };
206
+ }
207
+ else if (official) {
208
+ provenance = {
209
+ provenance: {
210
+ checked: false,
211
+ reason: "The platform uses SHA-512 pins for the official marketplace",
212
+ reasonCode: "official_pin_only",
213
+ },
214
+ };
215
+ }
216
+ else {
217
+ const p = await this.installs.fetchProvenance({ package: src.npm.package, version: src.npm.version, integrity: got.integrity }, opts.signal);
218
+ // A git marketplace may point to packages built in a different repository.
219
+ const mismatch = p.checked &&
220
+ marketplace.form === "git" &&
221
+ !sameRepository(p.repository, marketplace.url);
222
+ provenance = { provenance: p, ...(mismatch && { warning: "repository_mismatch" }) };
223
+ }
201
224
  }
202
225
  else {
203
226
  got = await this.fetchArchive(src.archive, opts.signal);
@@ -1,6 +1,8 @@
1
1
  import { type MarketplaceManifest } from "@capybara-hq/plugin-sdk";
2
2
  import type { KernelConfig } from "../config/schema.js";
3
3
  import { type LookupFn, NetDeniedError, type NetPolicy } from "../net/public-address.js";
4
+ import { type OfficialNpmRevision, type OfficialPublisherProof } from "../packages/official-publisher.js";
5
+ export declare function requireMarketplacePublisher(config: Pick<KernelConfig, "packages" | "marketplaces" | "net">, revision: OfficialNpmRevision, signal?: AbortSignal): Promise<OfficialPublisherProof>;
4
6
  /**
5
7
  * Fetching a marketplace manifest `marketplace.json` (C26, spec §5.2) and a marketplace's archive
6
8
  * sources. The URLs come from a super admin or the config, but responses are always hostile
@@ -4,6 +4,21 @@ import { ApiError } from "../errors.js";
4
4
  import { NetDeniedError } from "../net/public-address.js";
5
5
  import { describeFetchError, safeFetch } from "../net/safe-fetch.js";
6
6
  import { isLoopback, readCapped } from "../packages/npm.js";
7
+ import { fetchOfficialPublisher, } from "../packages/official-publisher.js";
8
+ export async function requireMarketplacePublisher(config, revision, signal) {
9
+ try {
10
+ return await fetchOfficialPublisher({
11
+ registry: config.packages.npmRegistry,
12
+ maxBytes: config.packages.maxBytes,
13
+ net: marketplaceNetPolicy(config),
14
+ ...(config.packages.npmToken !== undefined && { token: config.packages.npmToken }),
15
+ }, revision, signal);
16
+ }
17
+ catch (error) {
18
+ const reason = error instanceof Error ? error.message : String(error);
19
+ throw new ApiError("marketplace.publisher_unverified", `Cannot verify the official publisher for ${revision.name}@${revision.version}: ${reason}`);
20
+ }
21
+ }
7
22
  /**
8
23
  * The API error for a refused download, or undefined when the refusal is not one of the two
9
24
  * marketplace codes (an invalid URL or a DNS failure is an ordinary fetch failure).
@@ -10,8 +10,9 @@ import type { KernelLogger } from "../log.js";
10
10
  import { type ClaudeEntryOverlay } from "./claude/manifest.js";
11
11
  import { type MarketplaceSkipReason } from "./claude/marketplace.js";
12
12
  import { CatalogSourceLock } from "./locks.js";
13
- /** 官方清单来源的 id。 */
14
- export declare const OFFICIAL_MARKETPLACE_ID = "official";
13
+ import { OFFICIAL_MARKETPLACE_ID } from "./publisher-policy.js";
14
+ /** The built-in official marketplace ID. */
15
+ export { OFFICIAL_MARKETPLACE_ID };
15
16
  /** The id prefix of a marketplace the deployment config owns (`config:<name>`). */
16
17
  export declare const CONFIG_MARKETPLACE_PREFIX = "config:";
17
18
  /** 拉取一份清单的超时。 */
@@ -208,7 +209,7 @@ export declare function headsToResolve(entries: readonly MarketplaceEntry[], imp
208
209
  /** The host versions (an entry's `minKernel` is judged against them). */
209
210
  export declare const HOST_VERSIONS: {
210
211
  readonly kernel: string;
211
- readonly sdk: "0.1.0-rc.97";
212
+ readonly sdk: "0.1.0-rc.99";
212
213
  };
213
214
  /** Whether this deployment satisfies the entry's `minKernel`. */
214
215
  export declare const entryCompatible: (e: Pick<MarketplaceEntry, "minKernel">) => boolean;
@@ -506,4 +507,3 @@ export declare class MarketplacesService {
506
507
  private checkUsername;
507
508
  private checkToken;
508
509
  }
509
- export {};
@@ -32,9 +32,10 @@ import { CatalogSourceLock } from "./locks.js";
32
32
  import { fetchMarketplaceManifest, MarketplaceFetchError, MarketplaceInvalidError, marketplaceNetPolicy, marketplaceUrlProblem, } from "./marketplace-fetch.js";
33
33
  import { checkMarketplaceIcon, fetchMarketplaceIcon, gitIconPaths, MARKETPLACE_ICON_CONCURRENCY, MARKETPLACE_ICON_FETCHES_MAX, MARKETPLACE_ICON_MAX_BYTES, MARKETPLACE_ICON_RETRY_MS, marketplaceIconUrl, wantedIcons, } from "./marketplace-icons.js";
34
34
  import { withoutRemovedManifestFields } from "./plugin-package.js";
35
+ import { OFFICIAL_MARKETPLACE_ID } from "./publisher-policy.js";
35
36
  import { compareVersions, newestFirst, sameRelease } from "./versions.js";
36
- /** 官方清单来源的 id。 */
37
- export const OFFICIAL_MARKETPLACE_ID = "official";
37
+ /** The built-in official marketplace ID. */
38
+ export { OFFICIAL_MARKETPLACE_ID };
38
39
  /**
39
40
  * The official marketplace lists the upstream project's plugins, so it carries the project's name
40
41
  * under any platform name.
@@ -163,6 +163,8 @@ export declare class OwnedItems {
163
163
  private transferOrRemoveComponent;
164
164
  /** The live orgs other than `except` where component `c` is on now ({@link componentOn}). */
165
165
  private componentOrgsOn;
166
+ /** Replaces a transferred component's named list in the transfer's transaction. */
167
+ private replaceComponentScope;
166
168
  /**
167
169
  * The owner org's live install of a removed plugin, uninstalled in the caller's transaction
168
170
  * through the normal uninstall (ruling P3-41): `via: "scope"` (the item is gone, so no scope
@@ -21,6 +21,7 @@ import { ApiError } from "../errors.js";
21
21
  import { audit } from "../identity/audit.js";
22
22
  import { addPlatformNotice } from "../inbox/platform-notices.js";
23
23
  import { KernelDb } from "../infra/database/kernel-db.js";
24
+ import { asPlatform } from "../infra/database/org-scope.js";
24
25
  import { TransactionHost } from "../infra/database/transaction-host.js";
25
26
  import { Transactional } from "../infra/database/transactional.decorator.js";
26
27
  import { KERNEL_LOGGER } from "../infra/tokens.js";
@@ -427,12 +428,14 @@ let OwnedItems = class OwnedItems {
427
428
  .where("id", "=", item.id)
428
429
  .execute();
429
430
  if (item.scope === "all") {
430
- // org-filter: the ownership transfer rewrites the item's whole named list (every org using it)
431
- await t.deleteFrom("catalog_item_scope_orgs").where("item_id", "=", item.id).execute();
432
- await t
433
- .insertInto("catalog_item_scope_orgs")
434
- .values(others.map((o) => ({ item_id: item.id, org_id: o.id })))
435
- .execute();
431
+ // org-filter: deployment-wide rewrite of the transferred item's named list.
432
+ await asPlatform("replace the transferred plugin's named scope", async () => {
433
+ await t.deleteFrom("catalog_item_scope_orgs").where("item_id", "=", item.id).execute();
434
+ await t
435
+ .insertInto("catalog_item_scope_orgs")
436
+ .values(others.map((o) => ({ item_id: item.id, org_id: o.id })))
437
+ .execute();
438
+ });
436
439
  }
437
440
  else {
438
441
  await t
@@ -472,18 +475,7 @@ let OwnedItems = class OwnedItems {
472
475
  .set({ scope: "named", updated_at: now })
473
476
  .where("id", "=", c.id)
474
477
  .execute();
475
- // org-filter: the ownership transfer narrows the component's whole named list to the orgs on
476
- await t
477
- .deleteFrom("component_scope_orgs")
478
- .where("kind", "=", c.kind)
479
- .where("component_id", "=", c.id)
480
- .execute();
481
- if (orgs.length > 0) {
482
- await t
483
- .insertInto("component_scope_orgs")
484
- .values(orgs.map((org_id) => ({ kind: c.kind, component_id: c.id, org_id })))
485
- .execute();
486
- }
478
+ await this.replaceComponentScope(c.kind, c.id, orgs);
487
479
  await audit(t, {
488
480
  actorAccountId: actor,
489
481
  action: "component.scope_changed",
@@ -625,18 +617,7 @@ let OwnedItems = class OwnedItems {
625
617
  .where("id", "=", id)
626
618
  .execute();
627
619
  if (narrowTo !== null) {
628
- // org-filter: the ownership transfer narrows the component's whole named list to the orgs on
629
- await t
630
- .deleteFrom("component_scope_orgs")
631
- .where("kind", "=", kind)
632
- .where("component_id", "=", id)
633
- .execute();
634
- if (narrowTo.length > 0) {
635
- await t
636
- .insertInto("component_scope_orgs")
637
- .values(narrowTo.map((org_id) => ({ kind, component_id: id, org_id })))
638
- .execute();
639
- }
620
+ await this.replaceComponentScope(kind, id, narrowTo);
640
621
  }
641
622
  for (const list of ["component_scope_orgs", "component_org_switches"]) {
642
623
  await t
@@ -677,7 +658,7 @@ let OwnedItems = class OwnedItems {
677
658
  }
678
659
  /** The live orgs other than `except` where component `c` is on now ({@link componentOn}). */
679
660
  async componentOrgsOn(c, except) {
680
- const st = await loadScopeState(this.db, c.kind, [c]);
661
+ const st = await asPlatform("read the transferring component's scope in every org", () => loadScopeState(this.db, c.kind, [c]));
681
662
  const orgs = await this.db
682
663
  .selectFrom("orgs")
683
664
  .select("id")
@@ -689,6 +670,24 @@ let OwnedItems = class OwnedItems {
689
670
  .map((o) => o.id)
690
671
  .filter((o) => componentOn(c, pluginFactsOf(st, c.itemId, o), listedIn(st, c.id, o), switchOf(st, c.id, o)));
691
672
  }
673
+ /** Replaces a transferred component's named list in the transfer's transaction. */
674
+ async replaceComponentScope(kind, id, orgs) {
675
+ // org-filter: deployment-wide rewrite of the transferred component's named list.
676
+ await asPlatform("replace the transferred component's named scope", async () => {
677
+ const t = this.db;
678
+ await t
679
+ .deleteFrom("component_scope_orgs")
680
+ .where("kind", "=", kind)
681
+ .where("component_id", "=", id)
682
+ .execute();
683
+ if (orgs.length > 0) {
684
+ await t
685
+ .insertInto("component_scope_orgs")
686
+ .values(orgs.map((org_id) => ({ kind, component_id: id, org_id })))
687
+ .execute();
688
+ }
689
+ });
690
+ }
692
691
  /**
693
692
  * The owner org's live install of a removed plugin, uninstalled in the caller's transaction
694
693
  * through the normal uninstall (ruling P3-41): `via: "scope"` (the item is gone, so no scope