@capybara-hq/kernel 0.1.0-rc.142 → 0.1.0-rc.144

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 (238) hide show
  1. package/dist/admin/admin-agents.controller.d.ts +3 -5
  2. package/dist/admin/admin-agents.controller.js +1 -1
  3. package/dist/admin/admin-connectors.controller.d.ts +3 -5
  4. package/dist/admin/admin-connectors.controller.js +1 -1
  5. package/dist/admin/admin-items.schemas.d.ts +6 -6
  6. package/dist/admin/admin-items.schemas.js +5 -9
  7. package/dist/admin/admin.controller.d.ts +18 -12
  8. package/dist/admin/admin.controller.js +29 -15
  9. package/dist/admin/admin.schemas.d.ts +12 -3
  10. package/dist/admin/admin.schemas.js +17 -6
  11. package/dist/agents/admin-agents.d.ts +10 -8
  12. package/dist/agents/admin-agents.js +13 -9
  13. package/dist/agents/agents.module.js +3 -0
  14. package/dist/agents/agents.service.js +1 -1
  15. package/dist/agents/org-templates.d.ts +3 -1
  16. package/dist/agents/org-templates.js +7 -3
  17. package/dist/agents/pending-connector-requests.d.ts +10 -4
  18. package/dist/agents/pending-connector-requests.js +29 -7
  19. package/dist/automations/automations.controller.d.ts +9 -5
  20. package/dist/automations/automations.controller.js +21 -4
  21. package/dist/automations/automations.schemas.d.ts +19 -0
  22. package/dist/automations/automations.schemas.js +9 -0
  23. package/dist/automations/automations.service.d.ts +25 -8
  24. package/dist/automations/automations.service.js +40 -34
  25. package/dist/automations/events/acceptance.d.ts +6 -1
  26. package/dist/automations/events/acceptance.js +30 -11
  27. package/dist/automations/store.d.ts +17 -0
  28. package/dist/automations/store.js +35 -0
  29. package/dist/catalog/admin-catalog.controller.d.ts +64 -2
  30. package/dist/catalog/admin-catalog.controller.js +17 -0
  31. package/dist/catalog/catalog-import.module.js +3 -0
  32. package/dist/catalog/catalog-scope.service.d.ts +3 -1
  33. package/dist/catalog/catalog-scope.service.js +11 -7
  34. package/dist/catalog/catalog.module.js +3 -0
  35. package/dist/catalog/catalog.service.d.ts +3 -1
  36. package/dist/catalog/catalog.service.js +8 -4
  37. package/dist/catalog/cli.js +2 -2
  38. package/dist/catalog/component-promotion.d.ts +3 -1
  39. package/dist/catalog/component-promotion.js +7 -3
  40. package/dist/catalog/component-scope.service.d.ts +3 -1
  41. package/dist/catalog/component-scope.service.js +7 -3
  42. package/dist/catalog/enable-requests.d.ts +10 -8
  43. package/dist/catalog/enable-requests.js +40 -21
  44. package/dist/catalog/marketplaces.service.d.ts +1 -1
  45. package/dist/catalog/owned-items.d.ts +3 -1
  46. package/dist/catalog/owned-items.js +13 -9
  47. package/dist/catalog/platform-components.d.ts +6 -1
  48. package/dist/catalog/platform-components.js +9 -3
  49. package/dist/catalog/plugin-connectors.d.ts +8 -4
  50. package/dist/catalog/plugin-connectors.js +12 -6
  51. package/dist/catalog/plugin-import.d.ts +3 -1
  52. package/dist/catalog/plugin-import.js +14 -5
  53. package/dist/catalog/plugin-install.d.ts +3 -1
  54. package/dist/catalog/plugin-install.js +8 -4
  55. package/dist/catalog/plugin-package.js +2 -1
  56. package/dist/catalog/plugin-upgrade.d.ts +3 -1
  57. package/dist/catalog/plugin-upgrade.js +8 -4
  58. package/dist/catalog/request-hints.d.ts +19 -0
  59. package/dist/catalog/request-hints.js +34 -0
  60. package/dist/catalog/request-rules.d.ts +9 -5
  61. package/dist/catalog/request-rules.js +16 -9
  62. package/dist/catalog/requests.service.d.ts +3 -1
  63. package/dist/catalog/requests.service.js +28 -9
  64. package/dist/catalog/scope-orgs.d.ts +2 -1
  65. package/dist/catalog/scope-orgs.js +2 -2
  66. package/dist/catalog/scope-sync.d.ts +3 -1
  67. package/dist/catalog/scope-sync.js +12 -2
  68. package/dist/catalog/scope-writer.d.ts +6 -3
  69. package/dist/catalog/scope-writer.js +28 -10
  70. package/dist/catalog/unshare.d.ts +3 -2
  71. package/dist/catalog/unshare.js +4 -4
  72. package/dist/client/client-access.service.js +29 -1
  73. package/dist/config/schema.d.ts +12 -0
  74. package/dist/config/schema.js +56 -0
  75. package/dist/ctx/create-ctx.d.ts +2 -19
  76. package/dist/ctx/create-ctx.js +3 -93
  77. package/dist/ctx/durable-relay.d.ts +2 -5
  78. package/dist/ctx/durable-relay.js +56 -29
  79. package/dist/db/extension-handoff-schema.js +5 -0
  80. package/dist/db/kernel-schema.d.ts +74 -0
  81. package/dist/db/migrator.js +36 -0
  82. package/dist/erasure/account-batches.js +2 -0
  83. package/dist/erasure/account-residual.js +1 -0
  84. package/dist/erasure/org-catalog.js +8 -3
  85. package/dist/erasure/org-rules.js +1 -0
  86. package/dist/evals/evals.schemas.d.ts +15 -5
  87. package/dist/evals/evals.schemas.js +17 -10
  88. package/dist/evals/runs.controller.d.ts +4 -12
  89. package/dist/evals/runs.controller.js +14 -11
  90. package/dist/evals/runs.service.d.ts +29 -25
  91. package/dist/evals/runs.service.js +73 -61
  92. package/dist/evals/trajectory.controller.d.ts +10 -6
  93. package/dist/evals/trajectory.controller.js +11 -4
  94. package/dist/evals/trajectory.service.d.ts +17 -9
  95. package/dist/evals/trajectory.service.js +52 -35
  96. package/dist/extensions/admin-ops.d.ts +6 -1
  97. package/dist/extensions/admin-ops.js +21 -7
  98. package/dist/extensions/blobs.d.ts +2 -0
  99. package/dist/extensions/blobs.js +11 -0
  100. package/dist/extensions/deployment-config.d.ts +6 -1
  101. package/dist/extensions/deployment-config.js +13 -2
  102. package/dist/extensions/enabled.d.ts +5 -0
  103. package/dist/extensions/extensions.module.js +3 -0
  104. package/dist/extensions/grant-epoch.d.ts +108 -0
  105. package/dist/extensions/grant-epoch.js +214 -0
  106. package/dist/extensions/host.d.ts +29 -9
  107. package/dist/extensions/host.js +148 -42
  108. package/dist/extensions/instance.d.ts +3 -3
  109. package/dist/extensions/instance.js +1 -1
  110. package/dist/extensions/isolated/authorization.d.ts +54 -2
  111. package/dist/extensions/isolated/authorization.js +148 -35
  112. package/dist/extensions/isolated/child-session.js +0 -1
  113. package/dist/extensions/isolated/revision.js +1 -1
  114. package/dist/extensions/org-config.d.ts +3 -1
  115. package/dist/extensions/org-config.js +13 -4
  116. package/dist/extensions/org-overrides.d.ts +6 -1
  117. package/dist/extensions/org-overrides.js +13 -2
  118. package/dist/extensions/package-digest.job.d.ts +34 -0
  119. package/dist/extensions/package-digest.job.js +121 -0
  120. package/dist/extensions/package.js +10 -6
  121. package/dist/extensions/permission-set.d.ts +14 -78
  122. package/dist/extensions/permission-set.js +17 -143
  123. package/dist/extensions/permission-view.d.ts +13 -1
  124. package/dist/extensions/permission-view.js +20 -0
  125. package/dist/extensions/registry.js +4 -1
  126. package/dist/extensions/resolve.d.ts +7 -8
  127. package/dist/extensions/resolve.js +7 -8
  128. package/dist/extensions/revision-approvals.d.ts +167 -0
  129. package/dist/extensions/revision-approvals.js +353 -0
  130. package/dist/extensions/revision-grants.d.ts +197 -0
  131. package/dist/extensions/revision-grants.js +584 -0
  132. package/dist/extensions/state.module.js +12 -1
  133. package/dist/identity/accounts.d.ts +10 -4
  134. package/dist/identity/accounts.js +18 -5
  135. package/dist/inbox/inbox-items.service.d.ts +6 -1
  136. package/dist/inbox/inbox-items.service.js +29 -10
  137. package/dist/inbox/inbox.module.js +3 -0
  138. package/dist/inbox/inbox.service.d.ts +3 -1
  139. package/dist/inbox/inbox.service.js +9 -2
  140. package/dist/inbox/org-notices.d.ts +4 -3
  141. package/dist/inbox/org-notices.js +9 -6
  142. package/dist/inbox/platform-inbox.service.d.ts +3 -1
  143. package/dist/inbox/platform-inbox.service.js +11 -3
  144. package/dist/inbox/platform-notices.d.ts +3 -2
  145. package/dist/inbox/platform-notices.js +10 -4
  146. package/dist/infra/config/kernel-config.service.js +4 -1
  147. package/dist/infra/database/extension-effect-key-lock.js +7 -0
  148. package/dist/infra/paging/paged-read.d.ts +34 -4
  149. package/dist/infra/paging/paged-read.js +38 -1
  150. package/dist/invalidation/audiences.d.ts +32 -0
  151. package/dist/invalidation/audiences.js +43 -0
  152. package/dist/invalidation/hints.d.ts +6 -0
  153. package/dist/invalidation/hints.js +7 -1
  154. package/dist/invalidation/invalidation-hints.d.ts +12 -1
  155. package/dist/invalidation/invalidation-hints.js +46 -5
  156. package/dist/invalidation/invalidation-hints.module.d.ts +2 -0
  157. package/dist/invalidation/invalidation-hints.module.js +4 -1
  158. package/dist/invalidation/me-stream.d.ts +1 -11
  159. package/dist/invalidation/me-stream.js +12 -41
  160. package/dist/invalidation/org-intent-bridge.d.ts +18 -0
  161. package/dist/invalidation/org-intent-bridge.js +46 -0
  162. package/dist/models/enablement.d.ts +3 -1
  163. package/dist/models/enablement.js +25 -5
  164. package/dist/orgs/invitations.controller.d.ts +4 -7
  165. package/dist/orgs/invitations.controller.js +8 -5
  166. package/dist/orgs/invitations.service.d.ts +17 -3
  167. package/dist/orgs/invitations.service.js +35 -13
  168. package/dist/orgs/members.service.d.ts +35 -0
  169. package/dist/orgs/members.service.js +52 -3
  170. package/dist/orgs/offboarding.d.ts +3 -1
  171. package/dist/orgs/offboarding.js +7 -3
  172. package/dist/orgs/orgs.controller.d.ts +11 -4
  173. package/dist/orgs/orgs.controller.js +25 -5
  174. package/dist/orgs/orgs.module.js +3 -0
  175. package/dist/orgs/orgs.schemas.d.ts +14 -0
  176. package/dist/orgs/orgs.schemas.js +19 -2
  177. package/dist/orgs/orgs.service.d.ts +24 -2
  178. package/dist/orgs/orgs.service.js +47 -4
  179. package/dist/orgs/security-settings.service.d.ts +14 -6
  180. package/dist/orgs/security-settings.service.js +18 -13
  181. package/dist/orgs/settings.controller.d.ts +7 -4
  182. package/dist/platform/exclusions.js +15 -0
  183. package/dist/platform/ops/accounts.ops.js +7 -16
  184. package/dist/platform/ops/admin-items.ops.js +7 -7
  185. package/dist/platform/ops/automations.ops.js +6 -4
  186. package/dist/platform/ops/evals.ops.js +30 -15
  187. package/dist/platform/ops/org-settings.ops.js +2 -2
  188. package/dist/platform/ops/orgs.ops.js +44 -27
  189. package/dist/push/delivery.d.ts +3 -1
  190. package/dist/push/delivery.js +7 -3
  191. package/dist/push/push-processor.js +8 -1
  192. package/dist/roles/worker.module.js +3 -0
  193. package/dist/runtime/step-log.d.ts +1 -1
  194. package/dist/runtime/step-log.js +5 -4
  195. package/dist/runtime/stream-limit.d.ts +13 -0
  196. package/dist/runtime/stream-limit.js +40 -0
  197. package/dist/runtime/stream.controller.d.ts +2 -0
  198. package/dist/runtime/stream.controller.js +2 -0
  199. package/dist/runtime/stream.d.ts +1 -0
  200. package/dist/runtime/stream.js +15 -6
  201. package/dist/sandbox/permission-authority.module.js +6 -1
  202. package/dist/sandbox/permission-transitions.d.ts +3 -1
  203. package/dist/sandbox/permission-transitions.js +17 -2
  204. package/dist/setup/kernel-checks.d.ts +3 -3
  205. package/dist/setup/kernel-checks.js +4 -4
  206. package/dist/setup/setup-check-registry.d.ts +16 -5
  207. package/dist/setup/setup-check-registry.js +11 -3
  208. package/dist/setup/setup-checks.service.d.ts +1 -2
  209. package/dist/setup/setup-checks.service.js +7 -6
  210. package/dist/skills/agent-skills.service.d.ts +6 -1
  211. package/dist/skills/agent-skills.service.js +12 -3
  212. package/dist/skills/changes.service.d.ts +6 -1
  213. package/dist/skills/changes.service.js +11 -3
  214. package/dist/skills/conversation-catalog.d.ts +3 -0
  215. package/dist/skills/conversation-catalog.js +2 -0
  216. package/dist/skills/skills.module.js +3 -0
  217. package/dist/skills/skills.service.d.ts +3 -1
  218. package/dist/skills/skills.service.js +8 -4
  219. package/dist/tools/admin-connectors.d.ts +10 -8
  220. package/dist/tools/admin-connectors.js +12 -10
  221. package/dist/tools/approvals.service.d.ts +12 -1
  222. package/dist/tools/approvals.service.js +36 -9
  223. package/dist/tools/builtins/automations.d.ts +1 -1
  224. package/dist/tools/builtins/automations.js +1 -1
  225. package/dist/tools/connectors.service.d.ts +3 -1
  226. package/dist/tools/connectors.service.js +29 -7
  227. package/dist/tools/tools.module.js +3 -0
  228. package/dist/ui/admin-ui.controller.d.ts +3 -1
  229. package/dist/ui/admin-ui.controller.js +3 -1
  230. package/dist/ui/ui-stream.d.ts +2 -0
  231. package/dist/ui/ui-stream.js +20 -6
  232. package/dist/ui/views.controller.d.ts +4 -2
  233. package/dist/ui/views.controller.js +4 -2
  234. package/package.json +3 -3
  235. package/src/migrations/0234_extension_grant_epoch.sql +141 -0
  236. package/src/migrations/0235_extension_revision_grants.sql +166 -0
  237. package/src/migrations/0236_paged_table_idx.sql +33 -0
  238. package/src/migrations/0237_extension_handoff_health.sql +18 -0
@@ -3,7 +3,7 @@ import type { Redis } from "ioredis";
3
3
  import type { core } from "zod";
4
4
  import type { KernelAppOptions } from "../app.js";
5
5
  import { TRIGGER_EVENTS_BACKEND } from "../automations/events/token.js";
6
- import type { KernelConfig } from "../config/schema.js";
6
+ import { type KernelConfig } from "../config/schema.js";
7
7
  import type { ExternalConversationsBackend } from "../conversations/external/external-conversations.service.js";
8
8
  import { EXTERNAL_CONVERSATIONS_BACKEND } from "../conversations/external/token.js";
9
9
  import type { BusSubscriber } from "../ctx/bus.js";
@@ -42,6 +42,7 @@ import { type IsolatedRevocation } from "./isolated/authorization.js";
42
42
  import type { ExtensionTier } from "./isolated/tier.js";
43
43
  import { type PermissionSet } from "./permission-set.js";
44
44
  import { type ExtensionPointEntry, ExtensionRegistry } from "./registry.js";
45
+ import { ExtensionRevisionApprovals } from "./revision-approvals.js";
45
46
  import { type ExtensionSource, ReplicaStatusStore } from "./sources.js";
46
47
  export { deploymentConfigHash };
47
48
  /**
@@ -162,6 +163,11 @@ export declare class ExtensionHost {
162
163
  */
163
164
  private readonly modules?;
164
165
  private readonly dbIdentity;
166
+ /**
167
+ * Shadow revision approvals (plan task 1.2b): reported at start, never refusing. Absent in a
168
+ * hand-built host, which then reports nothing.
169
+ */
170
+ private readonly revisionApprovals?;
165
171
  /**
166
172
  * Only resolves extensions and runs migrations in dependency order: no deployment config check, no
167
173
  * setup, no Redis (for `capybara migrate`). Like `load()` it checks secret markers first
@@ -210,6 +216,9 @@ export declare class ExtensionHost {
210
216
  private readonly isolatedAuthority;
211
217
  private readonly isolatedLanes;
212
218
  private readonly isolatedGrants;
219
+ /** This replica's view of the deployment grant epoch; polls only once an isolated grant was issued. */
220
+ private readonly grantEpoch;
221
+ private readonly epochReader;
213
222
  private readonly executionTier;
214
223
  private policyExpected;
215
224
  /**
@@ -364,7 +373,12 @@ export declare class ExtensionHost {
364
373
  }): ExternalConversationsBackend;
365
374
  } | undefined,
366
375
  /** Tests only: `ctx.net`'s DNS and dispatcher seams (`EXTENSION_NET_SEAMS`). */
367
- netSeams?: ExtensionNetSeams, dbIdentity?: ExtensionDbIdentity);
376
+ netSeams?: ExtensionNetSeams, dbIdentity?: ExtensionDbIdentity,
377
+ /**
378
+ * Shadow revision approvals (plan task 1.2b): reported at start, never refusing. Absent in a
379
+ * hand-built host, which then reports nothing.
380
+ */
381
+ revisionApprovals?: Pick<ExtensionRevisionApprovals, "startGate"> | undefined);
368
382
  /** The startup config's `extensionConfig` (file / Nacos merged with env). */
369
383
  private get extensionConfig();
370
384
  /** `extensionPermissions.autoApprove` (development and trials only; see `planApprovals`). */
@@ -421,6 +435,18 @@ export declare class ExtensionHost {
421
435
  * `plugin host closed during load` at the next checkpoint.
422
436
  */
423
437
  load(plan: string[] | ExtensionLoadPlan): Promise<void>;
438
+ /** The last shadow report logged by this replica (a log de-duplication, not state). */
439
+ private lastShadowReport;
440
+ /**
441
+ * Shadow mode (plan task 1.2b, rollout fence until 1.5a): what the enforcing start gate would
442
+ * decide from revision grants, reported in the log after the start and after each install
443
+ * convergence, when it changes. The legacy snapshots govern; this never refuses, never blocks
444
+ * the start (it runs after it, reading packages in the background) and its failures only warn.
445
+ * An info line, not a warning: until the first reviews (plan tasks 1.3a and 1.3c) every install
446
+ * is listed. Config-declared extensions have no stored package digest and are left to the
447
+ * bootstrap review (1.3c) and the cutover preflight (1.5a).
448
+ */
449
+ private reportShadowStartGate;
424
450
  /**
425
451
  * Records each config-declared extension's display name from its plugin directory's plugin.json
426
452
  * (spec §2.2); an invalid plugin.json only warns (no display name).
@@ -480,6 +506,7 @@ export declare class ExtensionHost {
480
506
  /**
481
507
  * 安装记录加载失败的 error 日志:每个周期都会重试,同一个包、同一个原因只记一次(状态行每次照写)。
482
508
  */
509
+ private reportAdmissionRefusal;
483
510
  private logFailure;
484
511
  /** 记下(替换同名的)待定插件,供 {@link pending} 列出。 */
485
512
  private notePending;
@@ -581,13 +608,6 @@ export declare class ExtensionHost {
581
608
  * takes effect quickly.
582
609
  */
583
610
  enabledPlugins(orgId: string): Promise<Set<string>>;
584
- /**
585
- * The access behind an extension's `ctx.extensionPoints`: only active instances in the registry
586
- * (dependencies load in topological order, so the depended-on are ready first); org enablement is
587
- * read from PostgreSQL every time, not cached. Resolved live on every call: once a
588
- * provider is revoked it is no longer returned.
589
- */
590
- private readonly extensionPointAccess;
591
611
  private get loadDeps();
592
612
  /**
593
613
  * Build a new generation. Track its context during setup so shutdown can close it immediately.
@@ -11,11 +11,12 @@ import { readFile } from "node:fs/promises";
11
11
  import { createRequire } from "node:module";
12
12
  import { dirname, isAbsolute, join, resolve as resolvePath } from "node:path";
13
13
  import { fileURLToPath, pathToFileURL } from "node:url";
14
- import { EXTENSION_POINT_CARDINALITY, parseExtensionPoint, SDK_VERSION, } from "@capybara-hq/plugin-sdk";
14
+ import { EXTENSION_POINT_CARDINALITY, extensionPointRefs, OBJECT_STORE_EXTENSION_POINT, parseExtensionPoint, SDK_VERSION, staticPermissionDeclarations, } from "@capybara-hq/plugin-sdk";
15
15
  import { Inject, Injectable, Optional } from "@nestjs/common";
16
16
  import { ModuleRef } from "@nestjs/core";
17
17
  import { TRIGGER_EVENTS_BACKEND } from "../automations/events/token.js";
18
18
  import { changedPaths, configFields, getPath, secretValues, unreachableSecrets, } from "../config/fields.js";
19
+ import { EXTENSION_CAPACITY_DEFAULTS } from "../config/schema.js";
19
20
  import { EXTERNAL_CONVERSATIONS_BACKEND } from "../conversations/external/token.js";
20
21
  import { pluginSchemaName, queryEnabledPlugins, } from "../ctx/create-ctx.js";
21
22
  import { ExtensionEffects } from "../ctx/durable-effects.service.js";
@@ -51,6 +52,7 @@ import { deploymentConfigHash } from "./config-hash.js";
51
52
  import { toIssues } from "./config-issues.js";
52
53
  import { configFormSchema, describeConfigUiProblems } from "./config-json-schema.js";
53
54
  import { EffectiveConfigs } from "./effective-config.js";
55
+ import { GrantEpoch, grantEpochReader, grantEpochReadTimeoutMs } from "./grant-epoch.js";
54
56
  import { HookRegistry } from "./hooks.js";
55
57
  import { ExtensionInstalls } from "./installs.js";
56
58
  import { ImportTracker, importExtensionModule, ManifestMismatchError, matchesSection, setupInstance, warnUpgrades, } from "./instance.js";
@@ -65,6 +67,7 @@ import { declaredDisplayName, permissionSetOfSection, readMigrationSql } from ".
65
67
  import { blockingKeys, computePermissionSet, SETUP_CHECK_KEY_PREFIX, UI_VIEW_KEY_PREFIX, } from "./permission-set.js";
66
68
  import { ExtensionRegistry } from "./registry.js";
67
69
  import { ExtensionResolveError, electSingleProviders, PROVIDER_CONFLICT, providerConflictMessage, resolveExtensions, } from "./resolve.js";
70
+ import { ExtensionRevisionApprovals } from "./revision-approvals.js";
68
71
  import { ReplicaStatusStore, } from "./sources.js";
69
72
  import { PackageShaMismatchError, packageRootOf } from "./sync.js";
70
73
  export { deploymentConfigHash };
@@ -257,14 +260,15 @@ const migrationsDirOf = (m, dir) => m.migrations ? resolvePath(dir, m.migrations
257
260
  * 闸门放行后导入的真实模块必须与静态清单一致({@link matchesSection}),两者在依赖解析上等价。
258
261
  */
259
262
  function manifestOfSection(m) {
263
+ const declaration = staticPermissionDeclarations(m);
260
264
  return {
261
265
  name: m.name,
262
266
  version: m.version,
263
267
  sdk: m.sdk,
264
- provides: m.provides,
265
- requires: m.requires,
266
- optional: m.optional,
267
- permissions: m.permissions,
268
+ provides: declaration.provides,
269
+ requires: declaration.requires,
270
+ optional: declaration.optional,
271
+ permissions: declaration.permissions,
268
272
  ...(m.ui !== undefined && { ui: m.ui }),
269
273
  setup() {
270
274
  throw new Error(`plugin ${m.name}: static manifest cannot be set up`);
@@ -295,6 +299,7 @@ let ExtensionHost = class ExtensionHost {
295
299
  allowances;
296
300
  modules;
297
301
  dbIdentity;
302
+ revisionApprovals;
298
303
  /**
299
304
  * Only resolves extensions and runs migrations in dependency order: no deployment config check, no
300
305
  * setup, no Redis (for `capybara migrate`). Like `load()` it checks secret markers first
@@ -405,7 +410,10 @@ let ExtensionHost = class ExtensionHost {
405
410
  quota = new Map();
406
411
  isolatedAuthority = new WeakMap();
407
412
  isolatedLanes = new WeakMap();
408
- isolatedGrants = new IsolatedInvocationGrants();
413
+ isolatedGrants;
414
+ /** This replica's view of the deployment grant epoch; polls only once an isolated grant was issued. */
415
+ grantEpoch;
416
+ epochReader;
409
417
  executionTier = new Map();
410
418
  policyExpected = new Map();
411
419
  /**
@@ -535,7 +543,12 @@ let ExtensionHost = class ExtensionHost {
535
543
  */
536
544
  modules,
537
545
  /** Tests only: `ctx.net`'s DNS and dispatcher seams (`EXTENSION_NET_SEAMS`). */
538
- netSeams, dbIdentity = extensionDbIdentity(config.get().db)) {
546
+ netSeams, dbIdentity = extensionDbIdentity(config.get().db),
547
+ /**
548
+ * Shadow revision approvals (plan task 1.2b): reported at start, never refusing. Absent in a
549
+ * hand-built host, which then reports nothing.
550
+ */
551
+ revisionApprovals) {
539
552
  this.registry = registry;
540
553
  this.installs = installs;
541
554
  this.approvals = approvals;
@@ -547,6 +560,7 @@ let ExtensionHost = class ExtensionHost {
547
560
  this.allowances = allowances;
548
561
  this.modules = modules;
549
562
  this.dbIdentity = dbIdentity;
563
+ this.revisionApprovals = revisionApprovals;
550
564
  const c = config.get();
551
565
  this.hooks = new HookRegistry({
552
566
  instances: () => this.registry.all(),
@@ -558,6 +572,30 @@ let ExtensionHost = class ExtensionHost {
558
572
  config: () => ({ hooks: { timeoutMs: this.config.get().hooks.timeoutMs } }),
559
573
  log,
560
574
  });
575
+ // Hand-built configs (tests, embedders) may leave the capacity object out.
576
+ const capacity = { ...EXTENSION_CAPACITY_DEFAULTS, ...c.extensionHost.capacity };
577
+ this.epochReader = grantEpochReader({
578
+ url: c.db.url,
579
+ readTimeoutMs: grantEpochReadTimeoutMs(capacity.grantEpochMaxAgeMs),
580
+ connectTimeoutMs: c.db.connectTimeoutMs,
581
+ onError: (err) => this.log.warn("grant epoch connection error", { err }),
582
+ });
583
+ this.grantEpoch = new GrantEpoch({
584
+ read: this.epochReader.read,
585
+ maxAgeMs: capacity.grantEpochMaxAgeMs,
586
+ onChange: () => {
587
+ void this.isolatedGrants
588
+ .epochChanged()
589
+ .catch((err) => this.log.warn("isolated extension grant revalidation failed", { err }));
590
+ },
591
+ onSettleDeadline: () => this.isolatedGrants.fenceStale(),
592
+ onExpired: () => {
593
+ this.log.warn("isolated extension grants fenced: the grant epoch could not be read");
594
+ this.isolatedGrants.fenceAll();
595
+ },
596
+ onFault: (err) => this.log.warn("reading the extension grant epoch failed", { err }),
597
+ });
598
+ this.isolatedGrants = new IsolatedInvocationGrants(this.grantEpoch, capacity.grantCacheEntries);
561
599
  this.deps = {
562
600
  db: kdb.pool,
563
601
  dbUrl: c.db.url,
@@ -741,6 +779,7 @@ let ExtensionHost = class ExtensionHost {
741
779
  assertIsolatedSection(isolated.section);
742
780
  }
743
781
  catch (cause) {
782
+ await this.reportAdmissionRefusal(manifest.name, isolated.digest, errMsg(cause), "Install a revision that declares supported isolated capabilities and configuration.");
744
783
  throw new Error(`Configured extension ${manifest.name} was refused: ${errMsg(cause)}`, {
745
784
  cause,
746
785
  });
@@ -810,6 +849,8 @@ let ExtensionHost = class ExtensionHost {
810
849
  await this.loadDeferred(deferred, dirs, urls, snapshots, approvals, installProviders);
811
850
  }
812
851
  await this.refreshPolicyExpectations(desired ?? []);
852
+ if (p.installs)
853
+ void this.reportShadowStartGate();
813
854
  const orphans = Object.keys(this.extensionConfig).filter((k) => !this.sources.has(k));
814
855
  if (orphans.length > 0) {
815
856
  this.log.warn("extensionConfig has keys for extensions that are not loaded", {
@@ -817,6 +858,43 @@ let ExtensionHost = class ExtensionHost {
817
858
  });
818
859
  }
819
860
  }
861
+ /** The last shadow report logged by this replica (a log de-duplication, not state). */
862
+ lastShadowReport;
863
+ /**
864
+ * Shadow mode (plan task 1.2b, rollout fence until 1.5a): what the enforcing start gate would
865
+ * decide from revision grants, reported in the log after the start and after each install
866
+ * convergence, when it changes. The legacy snapshots govern; this never refuses, never blocks
867
+ * the start (it runs after it, reading packages in the background) and its failures only warn.
868
+ * An info line, not a warning: until the first reviews (plan tasks 1.3a and 1.3c) every install
869
+ * is listed. Config-declared extensions have no stored package digest and are left to the
870
+ * bootstrap review (1.3c) and the cutover preflight (1.5a).
871
+ */
872
+ async reportShadowStartGate() {
873
+ try {
874
+ if (!this.revisionApprovals)
875
+ return;
876
+ const gate = await this.revisionApprovals.startGate();
877
+ if (this.closed)
878
+ return;
879
+ const name = (d) => `${d.revision.plugin}@${d.revision.version} (${d.status}, legacy ${d.legacy})`;
880
+ const report = {
881
+ missingRequired: gate.missingRequired.map(name),
882
+ pending: gate.pending.map(name),
883
+ diverging: gate.diverging.length,
884
+ };
885
+ const digest = JSON.stringify(report);
886
+ if (digest === this.lastShadowReport)
887
+ return;
888
+ this.lastShadowReport = digest;
889
+ if (report.missingRequired.length > 0 || report.pending.length > 0) {
890
+ this.log.info("shadow revision grants: the enforcing start gate would hold these back", report);
891
+ }
892
+ }
893
+ catch (err) {
894
+ if (!this.closed)
895
+ this.log.warn("shadow revision grant decisions failed", { err });
896
+ }
897
+ }
820
898
  /**
821
899
  * Records each config-declared extension's display name from its plugin directory's plugin.json
822
900
  * (spec §2.2); an invalid plugin.json only warns (no display name).
@@ -985,7 +1063,7 @@ let ExtensionHost = class ExtensionHost {
985
1063
  continue;
986
1064
  wanted.set(d.name, d);
987
1065
  // 按审阅过的静态清单(不论随后加载成败)
988
- for (const cap of d.section.manifest.provides) {
1066
+ for (const cap of extensionPointRefs(d.section.manifest.provides)) {
989
1067
  installProviders.set(cap, [...(installProviders.get(cap) ?? []), d.name]);
990
1068
  }
991
1069
  }
@@ -1024,16 +1102,18 @@ let ExtensionHost = class ExtensionHost {
1024
1102
  }
1025
1103
  for (const d of desired) {
1026
1104
  const detail = rejected.get(d.name);
1027
- if (detail)
1028
- await this.writeStatus({
1029
- plugin: d.name,
1030
- version: d.version,
1031
- sha256: d.sha256,
1032
- source: "install",
1033
- state: "failed",
1034
- reason: "import_failed",
1035
- detail,
1036
- });
1105
+ if (!detail)
1106
+ continue;
1107
+ await this.reportAdmissionRefusal(d.name, d.sha256, detail, "Review the plugin revision and install a package eligible for this deployment.");
1108
+ await this.writeStatus({
1109
+ plugin: d.name,
1110
+ version: d.version,
1111
+ sha256: d.sha256,
1112
+ source: "install",
1113
+ state: "failed",
1114
+ reason: "import_failed",
1115
+ detail,
1116
+ });
1037
1117
  }
1038
1118
  const candidates = [];
1039
1119
  for (const d of wanted.values()) {
@@ -1055,9 +1135,11 @@ let ExtensionHost = class ExtensionHost {
1055
1135
  verified = await this.tierOf(loader, d, true);
1056
1136
  }
1057
1137
  catch {
1058
- this.log.warn("Extension revision integrity could not be verified", { plugin: d.name });
1138
+ // The refusal below reports the failed integrity check without logging verifier internals.
1059
1139
  }
1060
1140
  if (verified !== "trusted") {
1141
+ const detail = "The trusted extension package did not match its verified integrity";
1142
+ await this.reportAdmissionRefusal(d.name, d.sha256, detail, "Check publisher verification and reimport the verified package.");
1061
1143
  await this.writeStatus({
1062
1144
  plugin: d.name,
1063
1145
  version: d.version,
@@ -1065,7 +1147,7 @@ let ExtensionHost = class ExtensionHost {
1065
1147
  source: "install",
1066
1148
  state: "failed",
1067
1149
  reason: "sha_mismatch",
1068
- detail: "The trusted extension package did not match its verified integrity",
1150
+ detail,
1069
1151
  });
1070
1152
  continue;
1071
1153
  }
@@ -1303,6 +1385,22 @@ let ExtensionHost = class ExtensionHost {
1303
1385
  /**
1304
1386
  * 安装记录加载失败的 error 日志:每个周期都会重试,同一个包、同一个原因只记一次(状态行每次照写)。
1305
1387
  */
1388
+ async reportAdmissionRefusal(plugin, sha256, detail, action) {
1389
+ const recorded = await kernelDb(this.deps.db)
1390
+ .insertInto("extension_admission_refusals")
1391
+ .values({ plugin, sha256 })
1392
+ .onConflict((conflict) => conflict.doNothing())
1393
+ .returning("plugin")
1394
+ .executeTakeFirst();
1395
+ if (recorded) {
1396
+ this.log.error("Extension revision refused", {
1397
+ plugin,
1398
+ sha256,
1399
+ detail: this.log.redact(detail).slice(0, 500),
1400
+ action,
1401
+ });
1402
+ }
1403
+ }
1306
1404
  logFailure(plugin, sha256, reason, err, fields) {
1307
1405
  const key = `${sha256}:${reason}`;
1308
1406
  if (this.loggedFailures.get(plugin) === key)
@@ -1510,10 +1608,16 @@ let ExtensionHost = class ExtensionHost {
1510
1608
  if (a.source !== "install")
1511
1609
  this.pendingActivations.set(name, a);
1512
1610
  };
1513
- const failSoft = async (reason, e, refusedDeclaration = false) => {
1514
- this.logFailure(name, a.sha256, reason, e, { version: manifest.version });
1515
- await this.writeStatus({ ...base, state: "failed", reason, detail: errMsg(e) });
1516
- if (a.fatal && a.isolated && refusedDeclaration) {
1611
+ const failSoft = async (reason, e, admission) => {
1612
+ const detail = errMsg(e);
1613
+ if (admission && a.sha256) {
1614
+ await this.reportAdmissionRefusal(name, a.sha256, detail, admission.action);
1615
+ }
1616
+ else {
1617
+ this.logFailure(name, a.sha256, reason, e, { version: manifest.version });
1618
+ }
1619
+ await this.writeStatus({ ...base, state: "failed", reason, detail });
1620
+ if (a.fatal && a.isolated && admission?.refuseDeclaration) {
1517
1621
  throw new Error(`Configured extension ${name} was refused: ${errMsg(e)}`, { cause: e });
1518
1622
  }
1519
1623
  if (a.isolated)
@@ -1537,7 +1641,10 @@ let ExtensionHost = class ExtensionHost {
1537
1641
  manifest = isolatedManifestOf(a.isolated.section);
1538
1642
  }
1539
1643
  catch (error) {
1540
- return failSoft("import_failed", error, true);
1644
+ return failSoft("import_failed", error, {
1645
+ action: "Install a revision that declares supported isolated capabilities and configuration.",
1646
+ refuseDeclaration: true,
1647
+ });
1541
1648
  }
1542
1649
  }
1543
1650
  const schema = manifest.config?.deployment;
@@ -1642,7 +1749,10 @@ let ExtensionHost = class ExtensionHost {
1642
1749
  throw new Error(CLOSED_DURING_LOAD);
1643
1750
  // The isolated runner must be available before an isolated revision can migrate or activate.
1644
1751
  if (a.isolated && !this.config.get().extensionHost.isolation) {
1645
- return failSoft("setup_failed", new Error("The isolated extension supervisor is not configured"), true);
1752
+ return failSoft("setup_failed", new Error("The isolated extension supervisor is not configured"), {
1753
+ action: "Configure extensionHost.isolation and restart the replica.",
1754
+ refuseDeclaration: true,
1755
+ });
1646
1756
  }
1647
1757
  if (a.isolated) {
1648
1758
  try {
@@ -1652,7 +1762,7 @@ let ExtensionHost = class ExtensionHost {
1652
1762
  }
1653
1763
  }
1654
1764
  catch {
1655
- return failSoft("migration_failed", new Error("The isolated extension has no dedicated database identity"));
1765
+ return failSoft("migration_failed", new Error("The isolated extension has no dedicated database identity"), { action: "Provision the extension database login with capybara migrate." });
1656
1766
  }
1657
1767
  }
1658
1768
  const migrating = a.migrate
@@ -1814,6 +1924,7 @@ let ExtensionHost = class ExtensionHost {
1814
1924
  await this.applyInstalls(loader, desired, false);
1815
1925
  if (this.pendingActivations.size > 0)
1816
1926
  await this.activatePendingNow();
1927
+ void this.reportShadowStartGate();
1817
1928
  }
1818
1929
  await this.refreshPolicyExpectations(desired);
1819
1930
  });
@@ -1984,23 +2095,12 @@ let ExtensionHost = class ExtensionHost {
1984
2095
  async enabledPlugins(orgId) {
1985
2096
  return queryEnabledPlugins(this.deps.db, orgId);
1986
2097
  }
1987
- /**
1988
- * The access behind an extension's `ctx.extensionPoints`: only active instances in the registry
1989
- * (dependencies load in topological order, so the depended-on are ready first); org enablement is
1990
- * read from PostgreSQL every time, not cached. Resolved live on every call: once a
1991
- * provider is revoked it is no longer returned.
1992
- */
1993
- extensionPointAccess = {
1994
- providers: (ref) => this.registry
1995
- .all()
1996
- .flatMap((i) => i.provided.has(ref) ? [{ plugin: i.name, impl: i.provided.get(ref) }] : []),
1997
- enabledPlugins: (orgId) => this.enabledPlugins(orgId),
1998
- configOk: async (orgId, plugin) => (await this.effective.get(orgId, plugin)).ok,
1999
- };
2000
2098
  get loadDeps() {
2001
2099
  return {
2002
2100
  kernel: this.deps,
2003
- extensionPointAccess: this.extensionPointAccess,
2101
+ objectStore: () => this.registry
2102
+ .list("object-store")
2103
+ .find((entry) => entry.capability === OBJECT_STORE_EXTENSION_POINT)?.impl,
2004
2104
  nextGeneration: (name) => {
2005
2105
  const g = (this.generations.get(name) ?? 0) + 1;
2006
2106
  this.generations.set(name, g);
@@ -2791,6 +2891,10 @@ let ExtensionHost = class ExtensionHost {
2791
2891
  */
2792
2892
  async close(opts = {}) {
2793
2893
  this.closed = true;
2894
+ this.grantEpoch.stop();
2895
+ await this.epochReader
2896
+ .close()
2897
+ .catch((err) => this.log.warn("closing the grant epoch connection failed", { err }));
2794
2898
  this.abort.abort();
2795
2899
  this.revokeIsolatedInvocations({});
2796
2900
  await this.migrating?.catch(() => { });
@@ -2851,6 +2955,8 @@ ExtensionHost = __decorate([
2851
2955
  __param(20, Inject(ModuleRef)),
2852
2956
  __param(21, Optional()),
2853
2957
  __param(21, Inject(EXTENSION_NET_SEAMS)),
2854
- __param(22, Inject(ConfiguredExtensionDbIdentity))
2958
+ __param(22, Inject(ConfiguredExtensionDbIdentity)),
2959
+ __param(23, Optional()),
2960
+ __param(23, Inject(ExtensionRevisionApprovals))
2855
2961
  ], ExtensionHost);
2856
2962
  export { ExtensionHost };
@@ -1,5 +1,5 @@
1
- import { type DroppedUiContribution, type ExtensionManifest, type ExtensionPointRef, type ResolvedUiContribution, type StaticExtensionManifest } from "@capybara-hq/plugin-sdk";
2
- import { type ExtensionPointAccess, type KernelDeps, type KernelExtensionContext, LiveConfig, type RegisteredSetupCheck, type RegisteredTool, type Route } from "../ctx/create-ctx.js";
1
+ import { type DroppedUiContribution, type ExtensionManifest, type ExtensionPointRef, type ObjectStore, type ResolvedUiContribution, type StaticExtensionManifest } from "@capybara-hq/plugin-sdk";
2
+ import { type KernelDeps, type KernelExtensionContext, LiveConfig, type RegisteredSetupCheck, type RegisteredTool, type Route } from "../ctx/create-ctx.js";
3
3
  import type { extensionDbPool } from "../db/extension-db.js";
4
4
  import type { ServiceEventHandler } from "../device-access/service-events.js";
5
5
  import type { UiActionHandler, UiQueryHandler, UiRender } from "../ui/registry.js";
@@ -149,7 +149,7 @@ export declare function warnUpgrades(log: KernelDeps["log"], imports: ImportTrac
149
149
  /** {@link setupInstance} / {@link loadInstance} 的依赖。 */
150
150
  export interface LoadDeps {
151
151
  kernel: KernelDeps;
152
- extensionPointAccess: ExtensionPointAccess;
152
+ objectStore: () => ObjectStore | undefined;
153
153
  /** 该插件下一代的编号(宿主按插件名递增)。 */
154
154
  nextGeneration(name: string): number;
155
155
  /** 本进程导入过的模块入口({@link loadInstance} 每次导入都记一笔,超过阈值时告警)。 */
@@ -308,7 +308,7 @@ export function warnUpgrades(log, imports) {
308
308
  /** 在已导入、已核对的清单上建 ctx(记账)并 setup;setup 抛错时撤销已登记的再抛。 */
309
309
  export async function setupInstance(deps, manifest, input) {
310
310
  const live = new LiveConfig(input.config);
311
- const ctx = createExtensionContext(deps.kernel, manifest, live, deps.extensionPointAccess, {
311
+ const ctx = createExtensionContext(deps.kernel, manifest, live, deps.objectStore, {
312
312
  sha256: input.sha256,
313
313
  ...(input.extensionDb && { db: input.extensionDb }),
314
314
  });
@@ -20,14 +20,43 @@ interface CachedGrant {
20
20
  check: () => Promise<boolean>;
21
21
  onRevoked: () => void;
22
22
  pending?: Promise<boolean>;
23
- checkedUntil: number;
23
+ /** The grant epoch known when the last successful check started; undefined until checked. */
24
+ epoch: string | undefined;
25
+ /** When the last successful check started, for the periodic full revalidation backstop. */
26
+ checkedAt: number;
24
27
  calls: number;
28
+ /** Admissions waiting in {@link IsolatedInvocationGrants.issue}: the entry is not idle. */
29
+ admitting: number;
25
30
  }
26
- /** Replica-local cache of authority checked against deployment and org state. */
31
+ /**
32
+ * The epoch source the cache depends on ({@link GrantEpoch} in production). `fresh` answers only
33
+ * while the last successful epoch read is younger than the configured maximum age.
34
+ */
35
+ export interface GrantEpochView {
36
+ start(): void;
37
+ fresh(): string | undefined;
38
+ ensureFresh(): Promise<string | undefined>;
39
+ }
40
+ /** A grant checked at the current epoch is still rechecked after this long (backstop only). */
41
+ export declare const GRANT_FULL_REVALIDATION_MS: number;
42
+ /**
43
+ * Replica-local cache of authority checked against deployment and org state.
44
+ *
45
+ * A cached grant is valid only while it was checked at the current grant epoch and the epoch was
46
+ * read successfully within its maximum age. When the epoch cannot be confirmed, new admissions
47
+ * wait for a fresh read and are refused if it fails (fail closed). Bus hints still fence affected
48
+ * grants at once; the epoch covers hints that never arrive.
49
+ */
27
50
  export declare class IsolatedInvocationGrants {
51
+ private readonly epochs;
52
+ private readonly capacity;
53
+ private readonly now;
28
54
  private readonly instances;
29
55
  private readonly rechecks;
56
+ /** Every cached grant across instances, least recently used first. */
57
+ private readonly lru;
30
58
  private revalidating;
59
+ constructor(epochs: GrantEpochView, capacity: number, now?: () => number);
31
60
  issue({ plugin, orgId }: IsolatedRevocation, check: CachedGrant["check"], onRevoked: CachedGrant["onRevoked"] | undefined, instance: AbortSignal): Promise<IsolatedInvocationGrant | undefined>;
32
61
  revoke({ plugin, orgId }: IsolatedRevocation): void;
33
62
  /**
@@ -37,6 +66,29 @@ export declare class IsolatedInvocationGrants {
37
66
  refreshOrgIntent(orgId?: string): Promise<void>;
38
67
  /** Recheck retained grants, including idle lanes, when periodic reconciliation fires. */
39
68
  revalidate(): Promise<void>;
69
+ /**
70
+ * The grant epoch advanced: some committed change may have revoked any cached grant. Every
71
+ * entry is stale for admission already ({@link valid} compares epochs), so idle entries are
72
+ * rechecked lazily by their next admission or the periodic reconcile. Entries with calls in
73
+ * flight are rechecked now, all together, so a call whose grant is gone is aborted quickly;
74
+ * {@link fenceStale} aborts the ones still unconfirmed at the settle deadline.
75
+ */
76
+ epochChanged(): Promise<void>;
77
+ /**
78
+ * The settle deadline after an epoch change: abort calls whose grant was not confirmed at the
79
+ * current epoch, so no call outlives a revocation by more than the bound. Lanes stay up; the
80
+ * next admission checks PostgreSQL again.
81
+ */
82
+ fenceStale(): void;
83
+ /**
84
+ * The epoch has not been confirmed for the whole revocation bound. Fence every cached grant:
85
+ * in-flight calls are cancelled and the next admission checks PostgreSQL again. Lanes stay up,
86
+ * because nothing is known to be revoked.
87
+ */
88
+ fenceAll(): void;
89
+ private valid;
90
+ private evictIdle;
91
+ private drop;
40
92
  private retained;
41
93
  private runRechecks;
42
94
  private revalidateRetained;