@capybara-hq/kernel 0.1.0-rc.146 → 0.1.0-rc.147

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 (168) hide show
  1. package/dist/admin/extensions.controller.d.ts +0 -11
  2. package/dist/admin/extensions.controller.js +0 -28
  3. package/dist/admin/health.service.d.ts +25 -1
  4. package/dist/admin/health.service.js +50 -18
  5. package/dist/audit/full-access.d.ts +78 -0
  6. package/dist/audit/full-access.js +283 -0
  7. package/dist/automations/automations.service.d.ts +1 -0
  8. package/dist/automations/automations.service.js +3 -1
  9. package/dist/automations/calendar.js +3 -1
  10. package/dist/automations/grant-rules.d.ts +2 -1
  11. package/dist/automations/grant-rules.js +8 -1
  12. package/dist/automations/unattended.d.ts +13 -1
  13. package/dist/automations/unattended.js +13 -1
  14. package/dist/catalog/admin-catalog.controller.d.ts +8 -0
  15. package/dist/catalog/admin-catalog.controller.js +8 -2
  16. package/dist/catalog/admin-catalog.schemas.d.ts +10 -0
  17. package/dist/catalog/admin-catalog.schemas.js +8 -1
  18. package/dist/catalog/catalog-content.d.ts +6 -0
  19. package/dist/catalog/catalog-scope.service.d.ts +22 -2
  20. package/dist/catalog/catalog-scope.service.js +27 -3
  21. package/dist/catalog/catalog.service.js +19 -2
  22. package/dist/catalog/marketplaces.service.d.ts +1 -1
  23. package/dist/catalog/org-catalog.service.d.ts +8 -1
  24. package/dist/catalog/org-catalog.service.js +36 -3
  25. package/dist/catalog/platform-components.js +3 -2
  26. package/dist/catalog/platform-import-update.d.ts +2 -0
  27. package/dist/catalog/platform-import-update.js +8 -1
  28. package/dist/catalog/plugin-connectors.d.ts +11 -0
  29. package/dist/catalog/plugin-connectors.js +33 -0
  30. package/dist/catalog/plugin-import.d.ts +35 -15
  31. package/dist/catalog/plugin-import.js +110 -35
  32. package/dist/catalog/plugin-install.js +6 -0
  33. package/dist/catalog/provenance.d.ts +2 -0
  34. package/dist/catalog/provenance.js +5 -1
  35. package/dist/config/auto-approve.d.ts +16 -0
  36. package/dist/config/auto-approve.js +24 -0
  37. package/dist/config/capacity-presets.d.ts +243 -0
  38. package/dist/config/capacity-presets.js +195 -0
  39. package/dist/config/env.d.ts +2 -1
  40. package/dist/config/env.js +6 -1
  41. package/dist/config/load.js +15 -0
  42. package/dist/config/schema.d.ts +46 -9
  43. package/dist/config/schema.js +154 -30
  44. package/dist/ctx/net.d.ts +5 -1
  45. package/dist/ctx/net.js +62 -12
  46. package/dist/db/kernel-schema.d.ts +31 -0
  47. package/dist/db/migrator.js +0 -36
  48. package/dist/dial-in/routes.js +1 -1
  49. package/dist/erasure/org-batches.js +1 -6
  50. package/dist/erasure/org-catalog.js +6 -2
  51. package/dist/erasure/org-rules.js +1 -0
  52. package/dist/erasure/org-worker.js +0 -13
  53. package/dist/errors.d.ts +6 -0
  54. package/dist/errors.js +6 -0
  55. package/dist/extensions/admin-ops.d.ts +14 -1
  56. package/dist/extensions/admin-ops.js +30 -3
  57. package/dist/extensions/admin-view.d.ts +21 -1
  58. package/dist/extensions/admin-view.js +43 -0
  59. package/dist/extensions/bootstrap-packages.d.ts +5 -0
  60. package/dist/extensions/bootstrap-packages.js +1 -1
  61. package/dist/extensions/bootstrap-review.d.ts +251 -0
  62. package/dist/extensions/bootstrap-review.js +676 -0
  63. package/dist/extensions/bootstrap.d.ts +21 -1
  64. package/dist/extensions/bootstrap.js +72 -2
  65. package/dist/extensions/cli.d.ts +6 -0
  66. package/dist/extensions/cli.js +4 -0
  67. package/dist/extensions/enabled.d.ts +3 -0
  68. package/dist/extensions/extensions.module.js +9 -0
  69. package/dist/extensions/full-access-disclosure.d.ts +15 -0
  70. package/dist/extensions/full-access-disclosure.js +57 -0
  71. package/dist/extensions/grant-epoch.d.ts +5 -0
  72. package/dist/extensions/grant-epoch.js +9 -0
  73. package/dist/extensions/host.d.ts +71 -2
  74. package/dist/extensions/host.js +293 -27
  75. package/dist/extensions/installs.d.ts +18 -0
  76. package/dist/extensions/installs.js +28 -0
  77. package/dist/extensions/isolated/admission.d.ts +17 -2
  78. package/dist/extensions/isolated/admission.js +15 -7
  79. package/dist/extensions/isolated/authorization.d.ts +8 -2
  80. package/dist/extensions/isolated/authorization.js +11 -3
  81. package/dist/extensions/isolated/broker.d.ts +3 -0
  82. package/dist/extensions/isolated/broker.js +50 -14
  83. package/dist/extensions/isolated/configured-package.d.ts +5 -0
  84. package/dist/extensions/isolated/configured-package.js +2 -0
  85. package/dist/extensions/isolated/lanes.d.ts +44 -3
  86. package/dist/extensions/isolated/lanes.js +263 -80
  87. package/dist/extensions/isolated/metrics.d.ts +146 -0
  88. package/dist/extensions/isolated/metrics.js +304 -0
  89. package/dist/extensions/isolated/revision.d.ts +7 -1
  90. package/dist/extensions/isolated/revision.js +26 -5
  91. package/dist/extensions/isolated/rpc.d.ts +5 -0
  92. package/dist/extensions/isolated/rpc.js +7 -2
  93. package/dist/extensions/isolated/sandbox.d.ts +23 -0
  94. package/dist/extensions/isolated/sandbox.js +50 -0
  95. package/dist/extensions/isolated/status.d.ts +79 -0
  96. package/dist/extensions/isolated/status.js +216 -0
  97. package/dist/extensions/isolated/tier.d.ts +127 -2
  98. package/dist/extensions/isolated/tier.js +266 -7
  99. package/dist/extensions/isolated/usage.d.ts +134 -0
  100. package/dist/extensions/isolated/usage.js +322 -0
  101. package/dist/extensions/lifecycle.d.ts +42 -2
  102. package/dist/extensions/lifecycle.js +100 -4
  103. package/dist/extensions/org-config.js +11 -0
  104. package/dist/extensions/package.d.ts +14 -0
  105. package/dist/extensions/package.js +23 -0
  106. package/dist/extensions/permissions.controller.d.ts +35 -0
  107. package/dist/extensions/permissions.controller.js +98 -0
  108. package/dist/extensions/permissions.schemas.d.ts +288 -0
  109. package/dist/extensions/permissions.schemas.js +96 -0
  110. package/dist/extensions/permissions.service.d.ts +116 -0
  111. package/dist/extensions/permissions.service.js +428 -0
  112. package/dist/extensions/realm-retirement.d.ts +65 -0
  113. package/dist/extensions/realm-retirement.js +150 -0
  114. package/dist/extensions/revision-approvals.d.ts +58 -3
  115. package/dist/extensions/revision-approvals.js +135 -14
  116. package/dist/extensions/revision-review.d.ts +144 -0
  117. package/dist/extensions/revision-review.js +297 -0
  118. package/dist/extensions/revocation.js +3 -0
  119. package/dist/extensions/state.module.js +12 -0
  120. package/dist/git/run-end.d.ts +35 -7
  121. package/dist/git/run-end.js +87 -38
  122. package/dist/http/api.module.js +2 -0
  123. package/dist/identity/audit.d.ts +2 -1
  124. package/dist/identity/audit.js +4 -17
  125. package/dist/index.d.ts +4 -0
  126. package/dist/index.js +4 -0
  127. package/dist/infra/config/kernel-config.service.d.ts +6 -0
  128. package/dist/infra/config/kernel-config.service.js +21 -0
  129. package/dist/infra/outbox/registry.d.ts +13 -0
  130. package/dist/infra/outbox/registry.js +8 -0
  131. package/dist/lifecycle/kernel-lifecycle.d.ts +25 -1
  132. package/dist/lifecycle/kernel-lifecycle.js +73 -18
  133. package/dist/net/private-endpoint-preflight.d.ts +159 -0
  134. package/dist/net/private-endpoint-preflight.js +417 -0
  135. package/dist/net/private-endpoints.d.ts +68 -0
  136. package/dist/net/private-endpoints.js +164 -0
  137. package/dist/net/public-address.d.ts +14 -0
  138. package/dist/net/public-address.js +15 -1
  139. package/dist/net/safe-fetch.d.ts +2 -1
  140. package/dist/net/safe-fetch.js +10 -3
  141. package/dist/overrides.d.ts +4 -0
  142. package/dist/overrides.js +2 -0
  143. package/dist/packages/official-publisher.d.ts +26 -1
  144. package/dist/packages/official-publisher.js +48 -1
  145. package/dist/packages/provenance.d.ts +11 -0
  146. package/dist/packages/provenance.js +24 -0
  147. package/dist/platform/exclusions.js +4 -4
  148. package/dist/platform/ops/automations.ops.js +1 -1
  149. package/dist/platform/ops/catalog-admin.ops.js +25 -4
  150. package/dist/platform/ops/extension-permissions.ops.d.ts +11 -0
  151. package/dist/platform/ops/extension-permissions.ops.js +159 -0
  152. package/dist/platform/platform-ops.module.d.ts +2 -1
  153. package/dist/platform/platform-ops.module.js +2 -0
  154. package/dist/platform/route-schemas.js +2 -0
  155. package/dist/retention/purge-batch.js +10 -14
  156. package/dist/runtime/maintenance.d.ts +4 -2
  157. package/dist/runtime/maintenance.js +16 -3
  158. package/dist/runtime/run-finish.d.ts +3 -3
  159. package/dist/runtime/run-finish.js +7 -3
  160. package/dist/sandbox/permission-availability.d.ts +17 -2
  161. package/dist/sandbox/permission-availability.js +22 -1
  162. package/dist/sandbox/permission-facts.js +7 -1
  163. package/dist/tools/builtins/sandbox/common.js +2 -0
  164. package/dist/tools/pipeline.d.ts +2 -1
  165. package/dist/tools/pipeline.js +7 -2
  166. package/package.json +4 -3
  167. package/src/migrations/0238_extension_usage.sql +40 -0
  168. package/src/migrations/0239_extension_replica_isolation.sql +28 -0
@@ -38,9 +38,10 @@ import { ExtensionBlobs } from "./blobs.js";
38
38
  import { ExtensionLifecycle, PLUGINS_CHANGED_TOPIC } from "./lifecycle.js";
39
39
  import { PluginInstallLock } from "./locks.js";
40
40
  import { unrunMigrations } from "./migrate-lock.js";
41
- import { ExtensionPackageError, extensionPackageApiError, readExtensionPackage, } from "./package.js";
41
+ import { ExtensionPackageError, extensionPackageApiError, permissionSetOfSection, readExtensionPackage, } from "./package.js";
42
42
  import { extensionSourcesQuery } from "./plugin-items.js";
43
43
  import { ExtensionRegistry } from "./registry.js";
44
+ import { ExtensionRevisionApprovals } from "./revision-approvals.js";
44
45
  import { isSingleProviderCode, SingleProviderGuard, singleProviderNote, } from "./single-provider.js";
45
46
  import { captureSourceIntent, restoreSourceIntent } from "./source-intent.js";
46
47
  let ExtensionAdminOps = class ExtensionAdminOps {
@@ -60,6 +61,7 @@ let ExtensionAdminOps = class ExtensionAdminOps {
60
61
  singleProvider;
61
62
  outbox;
62
63
  hints;
64
+ revisions;
63
65
  constructor(kdb, txHost,
64
66
  /** The super admin lock (identity/super-admin.ts): joins the transaction. */
65
67
  adminLock,
@@ -88,7 +90,9 @@ let ExtensionAdminOps = class ExtensionAdminOps {
88
90
  /** The plugin scope sync a deploy owes (`oweDeployedExtensionSync`). */
89
91
  outbox,
90
92
  /** A platform enable, disable or new version publishes `platform-caps` after the commit. */
91
- hints) {
93
+ hints,
94
+ /** The install's approved / candidate revision (shadow mode, plan task 1.3a). */
95
+ revisions) {
92
96
  this.kdb = kdb;
93
97
  this.txHost = txHost;
94
98
  this.adminLock = adminLock;
@@ -105,10 +109,28 @@ let ExtensionAdminOps = class ExtensionAdminOps {
105
109
  this.singleProvider = singleProvider;
106
110
  this.outbox = outbox;
107
111
  this.hints = hints;
112
+ this.revisions = revisions;
108
113
  }
109
114
  get db() {
110
115
  return this.kdb.db;
111
116
  }
117
+ /**
118
+ * The install now runs `sha256`: it becomes the approved revision under its own grant, or a
119
+ * continuation, else the candidate waiting for review (shadow mode until plan task 1.5a: the
120
+ * legacy snapshot keeps governing admission). A downgrade is a rollback, served only under the
121
+ * selected revision's own grant. A package whose sha512 is not recorded yet is left to the
122
+ * backfill; the shadow decision reports it.
123
+ */
124
+ async promoteRevision(name, sha256, version, target, previous) {
125
+ const pkg = await this.db
126
+ .selectFrom("extension_packages")
127
+ .select("sha512")
128
+ .where("sha256", "=", sha256)
129
+ .executeTakeFirst();
130
+ if (!pkg?.sha512)
131
+ return;
132
+ await this.revisions.promoteInstalled({ plugin: name, version, sha512: pkg.sha512 }, permissionSetOfSection(target.section, target.migrationSql), previous && isDowngrade(version, previous.version) ? "rollback" : "upgrade");
133
+ }
112
134
  /**
113
135
  * New install or version change (upgrade / downgrade): the install record points at package
114
136
  * `sha256`; the desired state is unchanged (a new install is disabled). Audit `extension.installed`.
@@ -334,6 +356,7 @@ let ExtensionAdminOps = class ExtensionAdminOps {
334
356
  .execute();
335
357
  if (sourceIntent)
336
358
  await restoreSourceIntent(db, name, sourceIntent, actor);
359
+ await this.promoteRevision(name, sha256, pkg.version, target, row ?? undefined);
337
360
  if (leftDisabled !== undefined ||
338
361
  staticPermissionDeclarations(target.section.manifest).permissions.deviceAccess?.siteAccess !==
339
362
  true) {
@@ -558,6 +581,9 @@ let ExtensionAdminOps = class ExtensionAdminOps {
558
581
  }
559
582
  }
560
583
  };
584
+ __decorate([
585
+ Transactional({ propagation: "mandatory" })
586
+ ], ExtensionAdminOps.prototype, "promoteRevision", null);
561
587
  __decorate([
562
588
  Transactional()
563
589
  ], ExtensionAdminOps.prototype, "writeInstall", null);
@@ -590,7 +616,8 @@ ExtensionAdminOps = __decorate([
590
616
  __param(12, Inject(KERNEL_LOGGER)),
591
617
  __param(13, Inject(SingleProviderGuard)),
592
618
  __param(14, Inject(OutboxService)),
593
- __param(15, Inject(InvalidationHints))
619
+ __param(15, Inject(InvalidationHints)),
620
+ __param(16, Inject(ExtensionRevisionApprovals))
594
621
  ], ExtensionAdminOps);
595
622
  export { ExtensionAdminOps };
596
623
  /**
@@ -1,3 +1,4 @@
1
+ import { ApiError } from "../errors.js";
1
2
  import { SuperAdminLock } from "../identity/super-admin.js";
2
3
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
3
4
  import { KernelDb } from "../infra/database/kernel-db.js";
@@ -18,7 +19,7 @@ import { type AdminExtensionView } from "./permission-view.js";
18
19
  import { PluginIcons } from "./plugin-icons.js";
19
20
  import { SingleProviderGuard } from "./single-provider.js";
20
21
  export { PLUGINS_CHANGED_TOPIC };
21
- /** The web approval request body (`POST /api/v1/admin/extensions/:name/approve`). */
22
+ /** Legacy snapshot input used while revision grant enforcement is in shadow mode. */
22
23
  export interface ApproveBody {
23
24
  /** 安装记录的包;配置声明的插件为 null。 */
24
25
  sha256: string | null;
@@ -28,6 +29,11 @@ export interface ApproveBody {
28
29
  export interface PublishBus {
29
30
  publish(topic: string, payload: unknown): Promise<void>;
30
31
  }
32
+ /** An install's legacy approval subject (opaque outside this file). */
33
+ export type LegacyApprovalSubject = {
34
+ readonly name: string;
35
+ readonly version: string;
36
+ };
31
37
  /**
32
38
  * 部署级插件后台(超级管理员):列表 / 详情与网页批准权限(D8)。无状态,多副本共用;
33
39
  * 状态由 PG(安装记录、快照、各副本状态行)与本副本宿主(配置声明插件的清单)推出。
@@ -114,6 +120,20 @@ export declare class ExtensionAdmin {
114
120
  approve(actor: string, name: string, body: ApproveBody, opts?: {
115
121
  actorTokenId?: string;
116
122
  }): Promise<AdminExtensionView>;
123
+ /**
124
+ * The legacy approval of an install, for the permission approve route (plan task 1.4a): read
125
+ * outside any transaction (the package), then {@link writeLegacyApproval} inside the caller's,
126
+ * then {@link notifyApproved} after its commit. Undefined for an unknown or unreadable install.
127
+ */
128
+ legacySubject(name: string): Promise<LegacyApprovalSubject | undefined>;
129
+ /**
130
+ * Writes the legacy snapshot in the caller's transaction (the permission approve route, which
131
+ * records the revision grant in the same one), under the same locks and checks as
132
+ * {@link approve}. Returns false when the snapshot already covers the permissions.
133
+ */
134
+ writeLegacyApproval(actor: string, name: string, subject: LegacyApprovalSubject, actorTokenId: string | undefined, stale: () => ApiError): Promise<boolean>;
135
+ /** After an approval committed: other replicas are told, this one reconciles. */
136
+ notifyApproved(name: string): Promise<void>;
117
137
  private writeApproval;
118
138
  /** 配置声明 → 安装记录(与配置声明重名的安装记录不生效,不单列)。`only` 给出时只取这一个。 */
119
139
  private subjects;
@@ -200,6 +200,46 @@ let ExtensionAdmin = class ExtensionAdmin {
200
200
  }
201
201
  return this.get(name);
202
202
  }
203
+ /**
204
+ * The legacy approval of an install, for the permission approve route (plan task 1.4a): read
205
+ * outside any transaction (the package), then {@link writeLegacyApproval} inside the caller's,
206
+ * then {@link notifyApproved} after its commit. Undefined for an unknown or unreadable install.
207
+ */
208
+ async legacySubject(name) {
209
+ const s = (await this.subjects(name))[0];
210
+ return s && s.broken === undefined && s.install !== null ? s : undefined;
211
+ }
212
+ /**
213
+ * Writes the legacy snapshot in the caller's transaction (the permission approve route, which
214
+ * records the revision grant in the same one), under the same locks and checks as
215
+ * {@link approve}. Returns false when the snapshot already covers the permissions.
216
+ */
217
+ async writeLegacyApproval(actor, name, subject, actorTokenId, stale) {
218
+ try {
219
+ await this.writeApproval(actor, name, subject, actorTokenId, stale);
220
+ return true;
221
+ }
222
+ catch (err) {
223
+ if (err instanceof ApiError && err.code === "extension.not_pending")
224
+ return false;
225
+ throw err;
226
+ }
227
+ }
228
+ /** After an approval committed: other replicas are told, this one reconciles. */
229
+ async notifyApproved(name) {
230
+ try {
231
+ await this.bus.publish(PLUGINS_CHANGED_TOPIC, { plugin: name });
232
+ }
233
+ catch (err) {
234
+ this.log.warn("cannot publish plugins.changed after approval", { plugin: name, err });
235
+ }
236
+ try {
237
+ await this.lifecycle.reconcile(`approved:${name}`);
238
+ }
239
+ catch (err) {
240
+ this.log.error("loading approved plugins on this replica failed", { plugin: name, err });
241
+ }
242
+ }
203
243
  async writeApproval(actor, name, s, actorTokenId, stale) {
204
244
  const db = this.db;
205
245
  await this.adminLock.lockAndAuthorize(actor);
@@ -595,6 +635,9 @@ let ExtensionAdmin = class ExtensionAdmin {
595
635
  return { clients, reports };
596
636
  }
597
637
  };
638
+ __decorate([
639
+ Transactional({ propagation: "mandatory" })
640
+ ], ExtensionAdmin.prototype, "writeLegacyApproval", null);
598
641
  __decorate([
599
642
  Transactional()
600
643
  ], ExtensionAdmin.prototype, "writeApproval", null);
@@ -70,6 +70,11 @@ export declare function bootstrapGitMarketplace(manifest: Pick<MergedBootstrapMa
70
70
  * for the `soft` entries (recorded in `failed`, left out of the result).
71
71
  */
72
72
  export declare function resolveBootstrapPackages(manifest: MergedBootstrapManifest, o: BootstrapResolveOptions): Promise<Map<string, Uint8Array>>;
73
+ /**
74
+ * The `*.tgz` files directly in `dir` by their sha512 integrity. A missing directory is an empty
75
+ * one; a file larger than `maxBytes` is skipped with a warning.
76
+ */
77
+ export declare function scanOfflineDir(dir: string, maxBytes: number, log: Pick<Logger, "warn"> | undefined): Promise<Map<string, Uint8Array>>;
73
78
  /** What a git entry's tree is, as the bootstrap import reads it ({@link readBootstrapGitPlugin}). */
74
79
  export interface BootstrapGitPlugin {
75
80
  /** `capybara`: `.capybara-plugin/plugin.json`; `claude`: a Claude Code plugin; `skills`: skills only. */
@@ -207,7 +207,7 @@ function registryOrigin(registry) {
207
207
  * The `*.tgz` files directly in `dir` by their sha512 integrity. A missing directory is an empty
208
208
  * one; a file larger than `maxBytes` is skipped with a warning.
209
209
  */
210
- async function scanOfflineDir(dir, maxBytes, log) {
210
+ export async function scanOfflineDir(dir, maxBytes, log) {
211
211
  const out = new Map();
212
212
  let names;
213
213
  try {
@@ -0,0 +1,251 @@
1
+ import { KernelConfigService } from "../infra/config/kernel-config.service.js";
2
+ import { KernelDb } from "../infra/database/kernel-db.js";
3
+ import { TransactionHost } from "../infra/database/transaction-host.js";
4
+ import { XactLock } from "../infra/database/xact-lock.js";
5
+ import type { KernelLogger } from "../log.js";
6
+ import { ExtensionBlobs } from "./blobs.js";
7
+ import type { MergedBootstrapEntry, MergedBootstrapManifest } from "./bootstrap-extra.js";
8
+ import type { HostIsolation } from "./execution-realm.js";
9
+ import { type ExtensionPackage } from "./package.js";
10
+ import { type ReviewDisplay } from "./review-hash.js";
11
+ import { ExtensionRevisionApprovals } from "./revision-approvals.js";
12
+ import { type ApprovalScope, ExtensionRevisionGrants, type GrantAuthority, type RevisionGrant } from "./revision-grants.js";
13
+ /**
14
+ * The bootstrap review (extension permission model spec, "Bootstrap and offline installs"; plan
15
+ * task 1.3c). One batch covers every bootstrap pin of the merged manifest (built-in and extra
16
+ * entries, required, builtin and optional) and every config-declared extension (the archive the
17
+ * `extensions` config list captures). Each revision with an extension gets the same reviewed
18
+ * display as a catalog review (`review-hash.ts`: rows, purposes, realms and forcing keys, scope,
19
+ * operator authority, pin-only publisher evidence, the previous approval), and the batch hash binds
20
+ * the exact ordered batch, each revision's identity and display hash, and the host profile.
21
+ *
22
+ * - `capybara bootstrap review` shows it; `--print-review` prints the hash and the
23
+ * `bootstrap.approvedReviews` entry an operator can preseed.
24
+ * - `capybara bootstrap approve --review-hash <hash>` exchanges the hash for the revision grants in
25
+ * one transaction (source `operator_cli`, a fresh human review: it may reopen a revoked or retired
26
+ * revision). A hash that no longer matches the recomputed review is refused as stale.
27
+ * - A matching `bootstrap.approvedReviews` preseed does the same with source `operator_config`
28
+ * (never reviving a revoked or retired revision), from `capybara bootstrap approve` without a hash
29
+ * and from the kernel start; audited as operator (config).
30
+ * - `extensionPermissions.autoApprove` (outside production only, `config/auto-approve.ts`) grants
31
+ * the batch at start with source `auto`, logging a banner that names the revisions and realms.
32
+ * - The start gate computes "missing required approval" (a required pin, a config-declared
33
+ * extension or a required install without a live grant of its own). Shadow mode until plan task
34
+ * 1.5a: it is logged with the batch hash and the approve command, and never refuses.
35
+ *
36
+ * The batch hash is deployment-specific where approvals exist: each display binds its previous
37
+ * approval (the live grant of the install's approved revision, else of another revision of the
38
+ * plugin). A preseed hash published
39
+ * for a release (plan task 1.3f) therefore matches deployments without such a grant (fresh
40
+ * installs); an existing deployment recomputes it (`--print-review`, the P1.4 runbook).
41
+ *
42
+ * The review reads static archives only: the package store in PostgreSQL, the offline directory,
43
+ * then (the CLI only) npm or git, so it works without an object store and offline.
44
+ */
45
+ /** Bump when the batch's shape or the meaning of a field changes. */
46
+ export declare const BOOTSTRAP_REVIEW_CONTRACT = 1;
47
+ /** Where a reviewed revision comes from. */
48
+ export type BootstrapRevisionOrigin = "manifest" | "extra" | "config";
49
+ /** A revision's archive as the review read it. */
50
+ export type BootstrapArtifact = {
51
+ kind: "extension";
52
+ pkg: ExtensionPackage;
53
+ } | {
54
+ kind: "declarative";
55
+ } | {
56
+ kind: "unavailable";
57
+ problem: string;
58
+ };
59
+ /** One revision of the batch before the grants are consulted. */
60
+ export interface BootstrapRevisionInput {
61
+ name: string;
62
+ version: string;
63
+ origin: BootstrapRevisionOrigin;
64
+ required: boolean;
65
+ builtin: boolean;
66
+ /** The org scope its grant is bounded by: `all` for required, builtin and config-declared. */
67
+ scope: "all" | "optional";
68
+ /** Lowercase hex sha512 of the archive (the pin's integrity for a pin). */
69
+ sha512: string;
70
+ artifact: BootstrapArtifact;
71
+ }
72
+ export type BootstrapEntryStatus =
73
+ /** A live grant of its own. */
74
+ "granted"
75
+ /** Approving the batch grants it. */
76
+ | "approvable"
77
+ /** Its grant was revoked or retired: only a fresh operator review (the CLI) restores it. */
78
+ | "revoked"
79
+ /** Declared keys without bilingual purposes: Republish with purposes. */
80
+ | "missing_purposes"
81
+ /** A key no catalog row matches: the review cannot be confirmed. */
82
+ | "unconfirmable"
83
+ /** No extension: nothing to grant. */
84
+ | "declarative"
85
+ /** The archive could not be read here. */
86
+ | "unavailable";
87
+ export interface BootstrapReviewEntry {
88
+ name: string;
89
+ version: string;
90
+ sha512: string;
91
+ origin: BootstrapRevisionOrigin;
92
+ required: boolean;
93
+ builtin: boolean;
94
+ scope: "all" | "optional";
95
+ status: BootstrapEntryStatus;
96
+ display?: ReviewDisplay;
97
+ reviewHash?: string;
98
+ /** The live grant's generation, when granted. */
99
+ generation?: number;
100
+ /**
101
+ * The newest grant when it is no longer live (revoked or retired): bound by the batch hash, so a
102
+ * hash taken before a revocation cannot reopen the revision without a new review.
103
+ */
104
+ terminal?: {
105
+ generation: number;
106
+ state: string;
107
+ };
108
+ problem?: string;
109
+ }
110
+ export interface BootstrapReview {
111
+ /** `bootstrap:v<contract>:<sha256 hex>`. */
112
+ hash: string;
113
+ host: HostIsolation;
114
+ entries: BootstrapReviewEntry[];
115
+ /** Every archive was read: only a complete review can be approved. */
116
+ complete: boolean;
117
+ }
118
+ /** The kernel's start gate in shadow mode: computed and logged, never refused. */
119
+ export interface BootstrapStartGate {
120
+ /** Required pins, config-declared extensions and required installs without a live grant. */
121
+ missingRequired: string[];
122
+ /** The batch hash to approve, when the review is complete. */
123
+ hash?: string;
124
+ /** The command that clears it. */
125
+ command: string;
126
+ }
127
+ export type ApprovalVia = "cli" | "config" | "auto";
128
+ export interface BootstrapApproval {
129
+ hash: string;
130
+ /** Revisions granted now. */
131
+ granted: {
132
+ name: string;
133
+ version: string;
134
+ generation: number;
135
+ }[];
136
+ /** Revisions left without a grant, with why. */
137
+ skipped: {
138
+ name: string;
139
+ version: string;
140
+ reason: string;
141
+ }[];
142
+ }
143
+ export declare class BootstrapReviewError extends Error {
144
+ readonly code: "stale" | "incomplete";
145
+ constructor(code: "stale" | "incomplete", message: string);
146
+ }
147
+ /** `sha512-<base64>` (a pin's integrity) as lowercase hex. */
148
+ export declare function integrityHex(integrity: string): string;
149
+ /** The reviewed display of one revision with an extension, under the given authority. */
150
+ export declare function bootstrapRevisionDisplay(input: BootstrapRevisionInput & {
151
+ artifact: {
152
+ kind: "extension";
153
+ };
154
+ }, o: {
155
+ host: HostIsolation;
156
+ authority: GrantAuthority;
157
+ previous: RevisionGrant | undefined;
158
+ /** The scope the grant records, when narrower than the entry's (a `named` grant). */
159
+ approvalScope?: ApprovalScope;
160
+ }): ReviewDisplay;
161
+ /**
162
+ * The batch inputs of a manifest's pins from their archives (by entry name), without a database:
163
+ * what a fresh deployment's review reads (plan task 1.3f, the release-time preseed). An archive
164
+ * whose sha512 is not its pin's is refused like a missing one.
165
+ */
166
+ export declare function bootstrapPinInputs(manifest: MergedBootstrapManifest, archives: ReadonlyMap<string, Uint8Array>, maxBytes: number): Promise<BootstrapRevisionInput[]>;
167
+ /**
168
+ * The review of a fresh deployment (no grants, no previous approval), without a database: its
169
+ * hash is the one {@link BootstrapReviewService.review} computes for the same inputs and host on
170
+ * a deployment where no pinned plugin has a live grant on another revision. The
171
+ * release publishes it as the quickstart's `bootstrap.approvedReviews` preseed (plan task 1.3f).
172
+ */
173
+ export declare function freshBootstrapReview(inputs: readonly BootstrapRevisionInput[], host: HostIsolation): BootstrapReview;
174
+ /** The batch hash: the ordered batch, each revision's identity and display hash, the host. */
175
+ export declare function bootstrapBatchHash(host: HostIsolation, entries: readonly Pick<BootstrapReviewEntry, "name" | "version" | "sha512" | "origin" | "required" | "builtin" | "scope" | "status" | "reviewHash" | "terminal">[]): string;
176
+ /** The pin's archive read as an extension, a declarative plugin, or unavailable. */
177
+ export declare function classifyBootstrapArchive(e: Pick<MergedBootstrapEntry, "source">, bytes: Uint8Array, maxBytes: number): Promise<BootstrapArtifact>;
178
+ export declare class BootstrapReviewService {
179
+ private readonly kdb;
180
+ readonly txHost: TransactionHost;
181
+ private readonly xactLock;
182
+ private readonly grants;
183
+ private readonly approvals;
184
+ private readonly blobs;
185
+ private readonly config;
186
+ private readonly log;
187
+ constructor(kdb: KernelDb, txHost: TransactionHost, xactLock: XactLock, grants: ExtensionRevisionGrants, approvals: Pick<ExtensionRevisionApprovals, "startGate">, blobs: Pick<ExtensionBlobs, "get">, config: KernelConfigService, log: KernelLogger);
188
+ /** The host profile the review is computed for: whether the isolation supervisor is configured. */
189
+ host(): HostIsolation;
190
+ /**
191
+ * Reads the batch's archives: the bootstrap pins (the package store, then the offline `dir`,
192
+ * then npm or git when `network`) and the config-declared archives (`declared`; resolved against
193
+ * `resolveFrom`). Nothing is written; an archive that cannot be read is `unavailable`.
194
+ */
195
+ collect(o: {
196
+ manifest?: MergedBootstrapManifest | undefined;
197
+ dir?: string | undefined;
198
+ network: boolean;
199
+ declared: boolean;
200
+ resolveFrom?: string | undefined;
201
+ signal?: AbortSignal | undefined;
202
+ }): Promise<BootstrapRevisionInput[]>;
203
+ /**
204
+ * A pin already in PostgreSQL: an extension package stored with this sha512 (its bytes from the
205
+ * package store), or a declarative catalog version imported with this integrity.
206
+ */
207
+ private storedArtifact;
208
+ /** The review of the collected batch against the grants as they are now (reads only). */
209
+ review(inputs: readonly BootstrapRevisionInput[]): Promise<BootstrapReview>;
210
+ private entry;
211
+ /** The live grant of the install's approved revision when that is another revision. */
212
+ /**
213
+ * The previous approval a revision's display binds: the live grant of the install's approved
214
+ * revision when that is another revision, else the newest live grant of another revision of the
215
+ * plugin. Bootstrap pins are granted without being promoted (and installs from before the grant
216
+ * store have no approved revision), so without the fallback an upgraded pin would review like a
217
+ * fresh one and match the release's fresh-deployment preseed (plan task 1.3f).
218
+ */
219
+ private previous;
220
+ /**
221
+ * Exchanges the batch hash for the revision grants, in one transaction: the review is computed
222
+ * again inside it (the grants and previous approvals as they are now), a hash that differs is
223
+ * refused as stale, and every approvable revision is granted and audited
224
+ * (`extension.permissions_approved`, actor operator). `cli` may reopen a revoked or retired
225
+ * revision (a fresh human review); `config` (a preseed) never does.
226
+ */
227
+ approve(inputs: readonly BootstrapRevisionInput[], hash: string, via: "cli" | "config"): Promise<BootstrapApproval>;
228
+ /**
229
+ * `extensionPermissions.autoApprove` (outside production only): grants every grantable revision
230
+ * of the batch with source `auto`, each with its own display under the `auto` authority, in one
231
+ * transaction.
232
+ */
233
+ autoApprove(inputs: readonly BootstrapRevisionInput[]): Promise<BootstrapApproval>;
234
+ private grantAll;
235
+ /**
236
+ * The kernel start's step (shadow mode until plan task 1.5a). Reads the batch without network,
237
+ * applies a matching `bootstrap.approvedReviews` preseed (operator config), grants the batch when
238
+ * `autoApprove` is on (with the banner), then computes the start gate and logs a missing required
239
+ * approval with the batch hash and the command. Never throws and never refuses the start.
240
+ */
241
+ atStart(o: {
242
+ manifest?: MergedBootstrapManifest | undefined;
243
+ dir?: string | undefined;
244
+ declared: boolean;
245
+ resolveFrom?: string | undefined;
246
+ }): Promise<(BootstrapStartGate & {
247
+ granted: number;
248
+ }) | undefined>;
249
+ /** The start gate's facts (shadow mode: shown and logged, never refused). */
250
+ gate(review: BootstrapReview): Promise<BootstrapStartGate>;
251
+ }