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

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 (135) 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/catalog/catalog.service.d.ts +2 -0
  11. package/dist/catalog/catalog.service.js +28 -5
  12. package/dist/catalog/marketplace-fetch.d.ts +2 -0
  13. package/dist/catalog/marketplace-fetch.js +15 -0
  14. package/dist/catalog/marketplaces.service.d.ts +4 -4
  15. package/dist/catalog/marketplaces.service.js +3 -2
  16. package/dist/catalog/owned-items.d.ts +2 -0
  17. package/dist/catalog/owned-items.js +30 -31
  18. package/dist/catalog/ownership.js +40 -38
  19. package/dist/catalog/plugin-import.d.ts +3 -4
  20. package/dist/catalog/plugin-import.js +50 -1
  21. package/dist/catalog/plugin-upgrade.d.ts +8 -0
  22. package/dist/catalog/plugin-upgrade.js +95 -7
  23. package/dist/catalog/publisher-policy.d.ts +9 -0
  24. package/dist/catalog/publisher-policy.js +12 -0
  25. package/dist/catalog/unshare.js +66 -58
  26. package/dist/client/client-access.service.js +5 -3
  27. package/dist/config/schema.js +1 -1
  28. package/dist/conversations/conversations.controller.js +4 -14
  29. package/dist/conversations/conversations.service.d.ts +14 -0
  30. package/dist/conversations/conversations.service.js +20 -2
  31. package/dist/ctx/create-ctx.d.ts +11 -2
  32. package/dist/ctx/create-ctx.js +121 -52
  33. package/dist/ctx/queue.js +7 -4
  34. package/dist/db/extension-rls-predicate.d.ts +1 -0
  35. package/dist/db/extension-rls-predicate.js +8 -0
  36. package/dist/db/kernel-schema.d.ts +48 -0
  37. package/dist/db/migrator.js +6 -13
  38. package/dist/db/pool.d.ts +2 -2
  39. package/dist/db/pool.js +2 -2
  40. package/dist/db/sql-statements.d.ts +3 -0
  41. package/dist/db/sql-statements.js +15 -5
  42. package/dist/device-access/device-access.module.js +12 -2
  43. package/dist/device-access/device-access.service.d.ts +30 -2
  44. package/dist/device-access/device-access.service.js +38 -4
  45. package/dist/device-access/host-gate.d.ts +45 -0
  46. package/dist/device-access/host-gate.js +92 -0
  47. package/dist/device-access/host-service-stop-sweep.d.ts +33 -0
  48. package/dist/device-access/host-service-stop-sweep.js +112 -0
  49. package/dist/device-access/host-service-stop.d.ts +78 -0
  50. package/dist/device-access/host-service-stop.js +144 -0
  51. package/dist/device-access/host-services.d.ts +211 -0
  52. package/dist/device-access/host-services.js +803 -0
  53. package/dist/device-access/person-handles.d.ts +10 -0
  54. package/dist/device-access/person-handles.js +25 -0
  55. package/dist/device-access/service-events.d.ts +199 -0
  56. package/dist/device-access/service-events.js +704 -0
  57. package/dist/device-access/token.d.ts +5 -0
  58. package/dist/device-access/token.js +5 -0
  59. package/dist/devices/devices.service.js +3 -0
  60. package/dist/dial-in/access.d.ts +5 -5
  61. package/dist/dial-in/access.js +19 -12
  62. package/dist/dial-in/gateway.js +6 -2
  63. package/dist/dial-in/machines.d.ts +9 -2
  64. package/dist/dial-in/machines.js +27 -4
  65. package/dist/erasure/device-cleanup.js +12 -0
  66. package/dist/erasure/org-catalog.js +2 -2
  67. package/dist/erasure/org-rules.js +9 -0
  68. package/dist/errors.d.ts +2 -0
  69. package/dist/errors.js +2 -0
  70. package/dist/extensions/admin-ops.js +8 -2
  71. package/dist/extensions/deployed-snapshots.d.ts +4 -1
  72. package/dist/extensions/deployed-snapshots.js +7 -2
  73. package/dist/extensions/host.d.ts +7 -2
  74. package/dist/extensions/host.js +11 -2
  75. package/dist/extensions/instance.d.ts +3 -0
  76. package/dist/extensions/instance.js +4 -0
  77. package/dist/extensions/ledger.d.ts +1 -1
  78. package/dist/extensions/lifecycle-hooks.js +3 -3
  79. package/dist/extensions/org-config.js +6 -1
  80. package/dist/extensions/permission-set.d.ts +7 -0
  81. package/dist/extensions/permission-set.js +10 -0
  82. package/dist/extensions/permission-view.d.ts +1 -1
  83. package/dist/extensions/permission-view.js +10 -1
  84. package/dist/git/tickets.js +32 -27
  85. package/dist/http/app.js +5 -3
  86. package/dist/identity/accounts.d.ts +6 -1
  87. package/dist/identity/accounts.js +11 -2
  88. package/dist/identity/api-tokens.js +7 -6
  89. package/dist/identity/settings.d.ts +9 -1
  90. package/dist/identity/settings.js +16 -1
  91. package/dist/inbox/org-notices.js +3 -2
  92. package/dist/index.d.ts +1 -0
  93. package/dist/index.js +1 -0
  94. package/dist/infra/database/scoped-dialect.d.ts +3 -2
  95. package/dist/infra/database/scoped-dialect.js +260 -72
  96. package/dist/infra/database/startup-activation-transaction.d.ts +2 -0
  97. package/dist/infra/database/startup-activation-transaction.js +3 -2
  98. package/dist/infra/outbox/registry.d.ts +28 -0
  99. package/dist/infra/outbox/registry.js +30 -0
  100. package/dist/infra/queue/queue-names.d.ts +1 -1
  101. package/dist/infra/queue/queue-names.js +1 -0
  102. package/dist/infra/queue/run-job.d.ts +4 -1
  103. package/dist/infra/queue/run-job.js +10 -2
  104. package/dist/kernel.module.js +3 -0
  105. package/dist/orgs/offboarding.js +18 -9
  106. package/dist/orgs/settings.service.js +3 -0
  107. package/dist/packages/npm-publish-keys.json +27 -0
  108. package/dist/packages/official-publisher.d.ts +19 -0
  109. package/dist/packages/official-publisher.js +152 -0
  110. package/dist/packages/provenance.d.ts +7 -0
  111. package/dist/packages/provenance.js +22 -19
  112. package/dist/packages/sigstore-trusted-root.json +126 -0
  113. package/dist/platform/ops/admin.ops.js +2 -1
  114. package/dist/platform/ops/orgs.ops.js +1 -0
  115. package/dist/roles/worker-role.d.ts +6 -3
  116. package/dist/roles/worker-role.js +12 -4
  117. package/dist/roles/worker.module.js +7 -0
  118. package/dist/runtime/maintenance.d.ts +5 -2
  119. package/dist/runtime/maintenance.js +18 -4
  120. package/dist/sandbox/device-reports.d.ts +4 -4
  121. package/dist/sandbox/device-reports.js +40 -30
  122. package/dist/sandbox/device-services.d.ts +2 -1
  123. package/dist/sandbox/device-services.js +5 -1
  124. package/dist/sandbox/permission-ceiling-writes.d.ts +8 -0
  125. package/dist/sandbox/permission-ceiling-writes.js +21 -0
  126. package/dist/sandbox/permission-config-publication.js +5 -1
  127. package/dist/themes/theme-state.js +24 -13
  128. package/dist/tools/call-scope.d.ts +6 -0
  129. package/dist/tools/call-scope.js +22 -0
  130. package/dist/tools/registry.js +20 -2
  131. package/dist/ui/views.js +36 -8
  132. package/package.json +9 -4
  133. package/src/migrations/0222_device_host_services.sql +27 -0
  134. package/src/migrations/0223_device_service_events.sql +54 -0
  135. package/src/migrations/0224_cache_conversation_rls_settings.sql +33 -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)),
@@ -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.98";
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
@@ -5,6 +5,7 @@
5
5
  // gate on the row it writes, read `FOR UPDATE` in its transaction.
6
6
  import { sql } from "kysely";
7
7
  import { ApiError } from "../errors.js";
8
+ import { asPlatform } from "../infra/database/org-scope.js";
8
9
  import { componentOn, listedIn, loadComponents, loadScopeState, pluginFactsOf, switchOf, } from "./component-state.js";
9
10
  import { wantedOn } from "./scope.js";
10
11
  export const PLATFORM_OWNER = { kind: "platform" };
@@ -221,46 +222,47 @@ export function ownerOf(ownerOrgId, owners) {
221
222
  * `except` (usually the owner), by name. One definition for the update notices and the
222
223
  * "used by another org" check of deletes. An item that is gone or disabled is on nowhere.
223
224
  */
224
- // org-filter: answers which orgs an item is on in, so it reads the item's named list and switches
225
- // of every org on purpose (keyed by the item id)
226
- export async function orgsUsing(db, ref, opts = {}) {
227
- const orgs = await db
228
- .selectFrom("orgs")
229
- .select(["id", "name"])
230
- .where("deleted_at", "is", null)
231
- .orderBy("name")
232
- .orderBy("id")
233
- .execute();
234
- const others = orgs.filter((o) => o.id !== opts.except);
235
- if (others.length === 0)
236
- return [];
237
- if (ref.kind === "plugin") {
238
- const item = await db
239
- .selectFrom("catalog_items")
240
- .select(["scope", "builtin", "disabled"])
241
- .where("id", "=", ref.id)
225
+ export function orgsUsing(db, ref, opts = {}) {
226
+ // org-filter: deployment-wide subscriber lookup, keyed by the shared item id.
227
+ return asPlatform("find the live organizations using this shared item", async () => {
228
+ const orgs = await db
229
+ .selectFrom("orgs")
230
+ .select(["id", "name"])
242
231
  .where("deleted_at", "is", null)
243
- .executeTakeFirst();
244
- if (!item)
232
+ .orderBy("name")
233
+ .orderBy("id")
234
+ .execute();
235
+ const others = orgs.filter((o) => o.id !== opts.except);
236
+ if (others.length === 0)
245
237
  return [];
246
- const listed = new Set((await db
247
- .selectFrom("catalog_item_scope_orgs")
248
- .select("org_id")
249
- .where("item_id", "=", ref.id)
250
- .execute()).map((r) => r.org_id));
251
- const switches = new Map((await db
252
- .selectFrom("catalog_item_org_switches")
253
- .select(["org_id", "enabled"])
254
- .where("item_id", "=", ref.id)
255
- .execute()).map((r) => [r.org_id, r.enabled]));
256
- return others.filter((o) => wantedOn(item, listed.has(o.id), switches.get(o.id) ?? null));
257
- }
258
- const kind = ref.kind;
259
- const [c] = await loadComponents(db, kind, { ids: [ref.id] });
260
- if (!c)
261
- return [];
262
- const st = await loadScopeState(db, kind, [c]);
263
- return others.filter((o) => componentOn(c, pluginFactsOf(st, c.itemId, o.id), listedIn(st, c.id, o.id), switchOf(st, c.id, o.id)));
238
+ if (ref.kind === "plugin") {
239
+ const item = await db
240
+ .selectFrom("catalog_items")
241
+ .select(["scope", "builtin", "disabled"])
242
+ .where("id", "=", ref.id)
243
+ .where("deleted_at", "is", null)
244
+ .executeTakeFirst();
245
+ if (!item)
246
+ return [];
247
+ const listed = new Set((await db
248
+ .selectFrom("catalog_item_scope_orgs")
249
+ .select("org_id")
250
+ .where("item_id", "=", ref.id)
251
+ .execute()).map((r) => r.org_id));
252
+ const switches = new Map((await db
253
+ .selectFrom("catalog_item_org_switches")
254
+ .select(["org_id", "enabled"])
255
+ .where("item_id", "=", ref.id)
256
+ .execute()).map((r) => [r.org_id, r.enabled]));
257
+ return others.filter((o) => wantedOn(item, listed.has(o.id), switches.get(o.id) ?? null));
258
+ }
259
+ const kind = ref.kind;
260
+ const [c] = await loadComponents(db, kind, { ids: [ref.id] });
261
+ if (!c)
262
+ return [];
263
+ const st = await loadScopeState(db, kind, [c]);
264
+ return others.filter((o) => componentOn(c, pluginFactsOf(st, c.itemId, o.id), listedIn(st, c.id, o.id), switchOf(st, c.id, o.id)));
265
+ });
264
266
  }
265
267
  /**
266
268
  * Who a scope change newly shows an org-owned item to (the `item_shared` notice, P3-22): the orgs
@@ -284,9 +284,8 @@ export interface PluginReview {
284
284
  }[];
285
285
  source: PluginImportSource;
286
286
  /**
287
- * npm provenance (spec §5.5, display only): "built from `repository`@`commit` by `workflow`" for
288
- * npm and npm-backed marketplace imports when the registry has it; otherwise not checked, with
289
- * the reason ("not an npm package" for every other source).
287
+ * npm provenance names the build repository, commit and workflow. Official marketplace reviews
288
+ * carry verified publisher proof in the source detail; other npm provenance is display only.
290
289
  */
291
290
  provenance: ProvenanceResult;
292
291
  /** A git marketplace's repository differs from the attested one (a warning, never a refusal). */
@@ -695,7 +694,7 @@ export declare class PluginImport {
695
694
  * themes when there are any.
696
695
  * Exported for tests. `repository` is display only.
697
696
  */
698
- export declare function pluginReviewHash(r: Pick<PluginReview, "name" | "version" | "contentDigest" | "extension" | "connectorTemplates" | "agentTemplates" | "themes" | "skills" | "dependencies" | "format" | "translation" | "licenseText" | "claudeManifestIgnored" | "licenseTruncated">, files: {
697
+ export declare function pluginReviewHash(r: Pick<PluginReview, "name" | "version" | "contentDigest" | "extension" | "connectorTemplates" | "agentTemplates" | "themes" | "skills" | "dependencies" | "source" | "format" | "translation" | "licenseText" | "claudeManifestIgnored" | "licenseTruncated">, files: {
699
698
  path: string;
700
699
  sha256: string;
701
700
  }[]): string;