@capybara-hq/kernel 0.1.0-rc.145 → 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 (185) 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 +71 -0
  34. package/dist/catalog/provenance.js +112 -0
  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/create-ctx.d.ts +16 -0
  45. package/dist/ctx/create-ctx.js +269 -34
  46. package/dist/ctx/net.d.ts +5 -1
  47. package/dist/ctx/net.js +62 -12
  48. package/dist/db/kernel-schema.d.ts +31 -0
  49. package/dist/db/migrator.js +0 -36
  50. package/dist/dial-in/routes.js +1 -1
  51. package/dist/erasure/org-batches.js +1 -6
  52. package/dist/erasure/org-catalog.js +6 -2
  53. package/dist/erasure/org-rules.js +1 -0
  54. package/dist/erasure/org-worker.js +0 -13
  55. package/dist/errors.d.ts +6 -0
  56. package/dist/errors.js +6 -0
  57. package/dist/extensions/admin-ops.d.ts +14 -1
  58. package/dist/extensions/admin-ops.js +30 -3
  59. package/dist/extensions/admin-view.d.ts +21 -1
  60. package/dist/extensions/admin-view.js +43 -0
  61. package/dist/extensions/bootstrap-packages.d.ts +5 -0
  62. package/dist/extensions/bootstrap-packages.js +1 -1
  63. package/dist/extensions/bootstrap-review.d.ts +251 -0
  64. package/dist/extensions/bootstrap-review.js +676 -0
  65. package/dist/extensions/bootstrap.d.ts +21 -1
  66. package/dist/extensions/bootstrap.js +72 -2
  67. package/dist/extensions/cli.d.ts +6 -0
  68. package/dist/extensions/cli.js +4 -0
  69. package/dist/extensions/enabled.d.ts +3 -0
  70. package/dist/extensions/execution-realm.d.ts +96 -0
  71. package/dist/extensions/execution-realm.js +141 -0
  72. package/dist/extensions/extensions.module.js +12 -0
  73. package/dist/extensions/full-access-disclosure.d.ts +15 -0
  74. package/dist/extensions/full-access-disclosure.js +57 -0
  75. package/dist/extensions/grant-epoch.d.ts +9 -2
  76. package/dist/extensions/grant-epoch.js +13 -2
  77. package/dist/extensions/host.d.ts +96 -4
  78. package/dist/extensions/host.js +411 -33
  79. package/dist/extensions/installs.d.ts +18 -0
  80. package/dist/extensions/installs.js +28 -0
  81. package/dist/extensions/instance.d.ts +2 -0
  82. package/dist/extensions/instance.js +1 -0
  83. package/dist/extensions/isolated/admission.d.ts +23 -2
  84. package/dist/extensions/isolated/admission.js +32 -7
  85. package/dist/extensions/isolated/authorization.d.ts +8 -2
  86. package/dist/extensions/isolated/authorization.js +11 -3
  87. package/dist/extensions/isolated/broker.d.ts +3 -0
  88. package/dist/extensions/isolated/broker.js +50 -14
  89. package/dist/extensions/isolated/configured-package.d.ts +5 -0
  90. package/dist/extensions/isolated/configured-package.js +2 -0
  91. package/dist/extensions/isolated/lanes.d.ts +44 -3
  92. package/dist/extensions/isolated/lanes.js +263 -80
  93. package/dist/extensions/isolated/metrics.d.ts +146 -0
  94. package/dist/extensions/isolated/metrics.js +304 -0
  95. package/dist/extensions/isolated/revision.d.ts +7 -1
  96. package/dist/extensions/isolated/revision.js +26 -5
  97. package/dist/extensions/isolated/rpc.d.ts +5 -0
  98. package/dist/extensions/isolated/rpc.js +7 -2
  99. package/dist/extensions/isolated/sandbox.d.ts +23 -0
  100. package/dist/extensions/isolated/sandbox.js +50 -0
  101. package/dist/extensions/isolated/status.d.ts +79 -0
  102. package/dist/extensions/isolated/status.js +216 -0
  103. package/dist/extensions/isolated/tier.d.ts +127 -2
  104. package/dist/extensions/isolated/tier.js +266 -7
  105. package/dist/extensions/isolated/usage.d.ts +134 -0
  106. package/dist/extensions/isolated/usage.js +322 -0
  107. package/dist/extensions/ledger.d.ts +5 -0
  108. package/dist/extensions/ledger.js +16 -0
  109. package/dist/extensions/lifecycle.d.ts +42 -2
  110. package/dist/extensions/lifecycle.js +100 -4
  111. package/dist/extensions/org-config.js +11 -0
  112. package/dist/extensions/package.d.ts +14 -0
  113. package/dist/extensions/package.js +23 -0
  114. package/dist/extensions/permission-view.d.ts +2 -2
  115. package/dist/extensions/permissions.controller.d.ts +35 -0
  116. package/dist/extensions/permissions.controller.js +98 -0
  117. package/dist/extensions/permissions.schemas.d.ts +288 -0
  118. package/dist/extensions/permissions.schemas.js +96 -0
  119. package/dist/extensions/permissions.service.d.ts +116 -0
  120. package/dist/extensions/permissions.service.js +428 -0
  121. package/dist/extensions/realm-retirement.d.ts +65 -0
  122. package/dist/extensions/realm-retirement.js +150 -0
  123. package/dist/extensions/registry.d.ts +6 -0
  124. package/dist/extensions/registry.js +8 -0
  125. package/dist/extensions/review-hash.d.ts +114 -0
  126. package/dist/extensions/review-hash.js +145 -0
  127. package/dist/extensions/revision-approvals.d.ts +58 -3
  128. package/dist/extensions/revision-approvals.js +135 -14
  129. package/dist/extensions/revision-grants.d.ts +10 -0
  130. package/dist/extensions/revision-review.d.ts +144 -0
  131. package/dist/extensions/revision-review.js +297 -0
  132. package/dist/extensions/revocation-leases.d.ts +273 -0
  133. package/dist/extensions/revocation-leases.js +533 -0
  134. package/dist/extensions/revocation.d.ts +78 -0
  135. package/dist/extensions/revocation.js +205 -0
  136. package/dist/extensions/state.module.js +12 -0
  137. package/dist/git/run-end.d.ts +35 -7
  138. package/dist/git/run-end.js +87 -38
  139. package/dist/http/api.module.js +2 -0
  140. package/dist/identity/audit.d.ts +2 -1
  141. package/dist/identity/audit.js +4 -17
  142. package/dist/index.d.ts +10 -2
  143. package/dist/index.js +10 -2
  144. package/dist/infra/config/kernel-config.service.d.ts +6 -0
  145. package/dist/infra/config/kernel-config.service.js +21 -0
  146. package/dist/infra/outbox/registry.d.ts +13 -0
  147. package/dist/infra/outbox/registry.js +8 -0
  148. package/dist/lifecycle/kernel-lifecycle.d.ts +27 -1
  149. package/dist/lifecycle/kernel-lifecycle.js +83 -22
  150. package/dist/net/private-endpoint-preflight.d.ts +159 -0
  151. package/dist/net/private-endpoint-preflight.js +417 -0
  152. package/dist/net/private-endpoints.d.ts +68 -0
  153. package/dist/net/private-endpoints.js +164 -0
  154. package/dist/net/public-address.d.ts +14 -0
  155. package/dist/net/public-address.js +15 -1
  156. package/dist/net/safe-fetch.d.ts +2 -1
  157. package/dist/net/safe-fetch.js +10 -3
  158. package/dist/overrides.d.ts +9 -1
  159. package/dist/overrides.js +4 -0
  160. package/dist/packages/official-publisher.d.ts +65 -1
  161. package/dist/packages/official-publisher.js +171 -46
  162. package/dist/packages/provenance.d.ts +11 -0
  163. package/dist/packages/provenance.js +24 -0
  164. package/dist/platform/exclusions.js +4 -4
  165. package/dist/platform/ops/automations.ops.js +1 -1
  166. package/dist/platform/ops/catalog-admin.ops.js +25 -4
  167. package/dist/platform/ops/extension-permissions.ops.d.ts +11 -0
  168. package/dist/platform/ops/extension-permissions.ops.js +159 -0
  169. package/dist/platform/platform-ops.module.d.ts +2 -1
  170. package/dist/platform/platform-ops.module.js +2 -0
  171. package/dist/platform/route-schemas.js +2 -0
  172. package/dist/retention/purge-batch.js +10 -14
  173. package/dist/runtime/maintenance.d.ts +4 -2
  174. package/dist/runtime/maintenance.js +16 -3
  175. package/dist/runtime/run-finish.d.ts +3 -3
  176. package/dist/runtime/run-finish.js +7 -3
  177. package/dist/sandbox/permission-availability.d.ts +17 -2
  178. package/dist/sandbox/permission-availability.js +22 -1
  179. package/dist/sandbox/permission-facts.js +7 -1
  180. package/dist/tools/builtins/sandbox/common.js +2 -0
  181. package/dist/tools/pipeline.d.ts +2 -1
  182. package/dist/tools/pipeline.js +7 -2
  183. package/package.json +4 -3
  184. package/src/migrations/0238_extension_usage.sql +40 -0
  185. package/src/migrations/0239_extension_replica_isolation.sql +28 -0
@@ -0,0 +1,150 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ };
10
+ import { Inject, Injectable } from "@nestjs/common";
11
+ import { sql } from "kysely";
12
+ import { audit } from "../identity/audit.js";
13
+ import { afterCommit } from "../infra/database/after-commit.js";
14
+ import { KernelDb } from "../infra/database/kernel-db.js";
15
+ import { TransactionHost } from "../infra/database/transaction-host.js";
16
+ import { Transactional } from "../infra/database/transactional.decorator.js";
17
+ import { KERNEL_BUS, KERNEL_LOGGER } from "../infra/tokens.js";
18
+ import { HOST_NO_ISOLATION_KEY } from "./execution-realm.js";
19
+ import { ExtensionHost } from "./host.js";
20
+ import { ExtensionRevisionGrants, fullAccessKey, } from "./revision-grants.js";
21
+ import { GRANT_REVOKED_TOPIC } from "./revocation.js";
22
+ let HostReasonRetirement = class HostReasonRetirement {
23
+ kdb;
24
+ txHost;
25
+ grants;
26
+ host;
27
+ bus;
28
+ log;
29
+ constructor(kdb, txHost, grants, host, bus, log) {
30
+ this.kdb = kdb;
31
+ this.txHost = txHost;
32
+ this.grants = grants;
33
+ this.host = host;
34
+ this.bus = bus;
35
+ this.log = log;
36
+ }
37
+ /**
38
+ * Retires `host.no-isolation` from every live grant that still carries it in its server realm.
39
+ * Call only on a positive readiness signal of the isolation supervisor. One failing grant is
40
+ * logged and never stops the others.
41
+ */
42
+ async retireAll() {
43
+ const out = [];
44
+ for (const candidate of await this.candidates()) {
45
+ try {
46
+ const retired = await this.retire(candidate, candidate.generation);
47
+ if (retired)
48
+ out.push(retired);
49
+ }
50
+ catch (err) {
51
+ this.log.warn("retiring host.no-isolation from a revision grant failed", {
52
+ plugin: candidate.plugin,
53
+ version: candidate.version,
54
+ err,
55
+ });
56
+ }
57
+ }
58
+ return out;
59
+ }
60
+ /**
61
+ * Retires the host reason of one grant generation. Returns undefined when that generation is no
62
+ * longer live or no longer carries an unretired host reason (another replica got there first).
63
+ */
64
+ async retire(revision, generation) {
65
+ const locked = await this.kdb.db
66
+ .selectFrom("extension_revision_grants")
67
+ .select("generation")
68
+ .where("plugin", "=", revision.plugin)
69
+ .where("version", "=", revision.version)
70
+ .where("sha512", "=", revision.sha512)
71
+ .where("generation", "=", generation)
72
+ .where("state", "in", ["approved", "partially_revoked"])
73
+ .forNoKeyUpdate()
74
+ .executeTakeFirst();
75
+ if (!locked)
76
+ return undefined;
77
+ const before = await this.grants.live(revision);
78
+ if (!before || before.generation !== generation || !carriesHostReason(before)) {
79
+ return undefined;
80
+ }
81
+ const after = await this.grants.retireForcing(revision, "server", HOST_NO_ISOLATION_KEY, null);
82
+ const retiredForcing = new Set(after.retiredForcing.server ?? []);
83
+ const remaining = (after.realms.server ?? []).filter((key) => !retiredForcing.has(key));
84
+ const realmRetired = after.retiredKeys.includes(fullAccessKey("server"));
85
+ await audit(this.kdb.db, {
86
+ actorAccountId: null,
87
+ action: "extension.full_access_retired",
88
+ target: revision.plugin,
89
+ detail: {
90
+ plugin: revision.plugin,
91
+ version: revision.version,
92
+ sha512: revision.sha512,
93
+ generation,
94
+ realm: "server",
95
+ forcingKey: HOST_NO_ISOLATION_KEY,
96
+ reason: "isolation supervisor available",
97
+ realmRetired,
98
+ remaining,
99
+ state: after.state,
100
+ reviewHash: after.reviewHash,
101
+ publisherEvidence: after.publisherEvidence,
102
+ },
103
+ });
104
+ const { plugin } = revision;
105
+ afterCommit(async () => {
106
+ await this.host
107
+ .fenceRevocation(plugin)
108
+ .catch((err) => this.log.warn("host reason retirement fence failed", { plugin, err }));
109
+ try {
110
+ await this.bus.publish(GRANT_REVOKED_TOPIC, { plugin });
111
+ }
112
+ catch (err) {
113
+ this.log.warn("cannot publish a grant change hint; the grant epoch fences replicas", {
114
+ plugin,
115
+ err,
116
+ });
117
+ }
118
+ });
119
+ return { revision, generation, realmRetired, remaining };
120
+ }
121
+ /** Live grants whose server realm still carries an unretired `host.no-isolation`. */
122
+ async candidates() {
123
+ const key = JSON.stringify([HOST_NO_ISOLATION_KEY]);
124
+ return this.kdb.db
125
+ .selectFrom("extension_revision_grants")
126
+ .select(["plugin", "version", "sha512", "generation"])
127
+ .where("state", "in", ["approved", "partially_revoked"])
128
+ .where(sql `coalesce(realms -> 'server', '[]'::jsonb) @> ${key}::jsonb`)
129
+ .where(sql `NOT coalesce(retired_forcing -> 'server', '[]'::jsonb) @> ${key}::jsonb`)
130
+ .orderBy("plugin")
131
+ .execute();
132
+ }
133
+ };
134
+ __decorate([
135
+ Transactional()
136
+ ], HostReasonRetirement.prototype, "retire", null);
137
+ HostReasonRetirement = __decorate([
138
+ Injectable(),
139
+ __param(0, Inject(KernelDb)),
140
+ __param(1, Inject(TransactionHost)),
141
+ __param(2, Inject(ExtensionRevisionGrants)),
142
+ __param(3, Inject(ExtensionHost)),
143
+ __param(4, Inject(KERNEL_BUS)),
144
+ __param(5, Inject(KERNEL_LOGGER))
145
+ ], HostReasonRetirement);
146
+ export { HostReasonRetirement };
147
+ function carriesHostReason(grant) {
148
+ return ((grant.realms.server ?? []).includes(HOST_NO_ISOLATION_KEY) &&
149
+ !(grant.retiredForcing.server ?? []).includes(HOST_NO_ISOLATION_KEY));
150
+ }
@@ -60,6 +60,12 @@ export declare class ExtensionRegistry {
60
60
  manifests(): ExtensionManifest[];
61
61
  /** 每次激活 / 摘下加一(给按版本缓存的派生视图用,如插件路由表)。 */
62
62
  revision(): number;
63
+ /**
64
+ * An active instance withdrew registrations (a revoked permission, plan task 1.3e): derived views
65
+ * cached by {@link revision} rebuild and the change listeners refresh (the HTTP dispatcher, the
66
+ * gateway's channel supervisor and webhook cache), as for a replaced instance.
67
+ */
68
+ registrationsChanged(name: string): void;
63
69
  /**
64
70
  * 订阅变化(激活 / 替换 / 摘下,参数为插件名)。只通知本进程的消费方(渠道 supervisor、界面等),不跨副本。
65
71
  * 监听函数同步调用,抛错被吞掉(不影响注册表与其他监听方)。返回取消订阅函数。
@@ -112,6 +112,14 @@ let ExtensionRegistry = class ExtensionRegistry {
112
112
  revision() {
113
113
  return this.rev;
114
114
  }
115
+ /**
116
+ * An active instance withdrew registrations (a revoked permission, plan task 1.3e): derived views
117
+ * cached by {@link revision} rebuild and the change listeners refresh (the HTTP dispatcher, the
118
+ * gateway's channel supervisor and webhook cache), as for a replaced instance.
119
+ */
120
+ registrationsChanged(name) {
121
+ this.changed(name);
122
+ }
115
123
  /**
116
124
  * 订阅变化(激活 / 替换 / 摘下,参数为插件名)。只通知本进程的消费方(渠道 supervisor、界面等),不跨副本。
117
125
  * 监听函数同步调用,抛错被吞掉(不影响注册表与其他监听方)。返回取消订阅函数。
@@ -0,0 +1,114 @@
1
+ import { type PermissionRisk } from "@capybara-hq/plugin-sdk";
2
+ import type { PublisherEvidence } from "../catalog/provenance.js";
3
+ import { type ExecutionDecision, type ExecutionInput, type HostIsolation } from "./execution-realm.js";
4
+ import { type PermissionSet } from "./permission-set.js";
5
+ import { type ApprovalScope, type ExecutionRealm, type GrantAuthority, type PurposeRow, type RevisionGrant, type RevisionIdentity } from "./revision-grants.js";
6
+ /**
7
+ * The reviewed display and its hash (extension permission model spec, "Review, updates and
8
+ * provenance" step 1; plan task 1.2e). Pure. A review binds everything the approver is shown: the
9
+ * exact revision, every permission row with its risk and bilingual purpose (the kernel-written rows
10
+ * of migration warnings and full access included), the execution realms and their forcing keys,
11
+ * the org scope, the approver authority, the publisher evidence, the previous approval and the diff
12
+ * against it, and the risk-contract version. Any change to one of them changes the hash, so a
13
+ * confirmation made against an older display is refused (1.3a) and a bootstrap batch hash (1.3c)
14
+ * covers each revision's display.
15
+ */
16
+ /** Bump when the display's shape or the meaning of a field changes. */
17
+ export declare const REVIEW_CONTRACT_VERSION = 1;
18
+ /**
19
+ * The kernel-written purpose of full access in one realm: one fixed sentence per realm. The forcing
20
+ * keys are bound separately (the grant's `realms`, the display's `execution.realms`), so a
21
+ * continuation whose forcing keys shrink keeps an identical purpose row.
22
+ */
23
+ export declare function fullAccessPurpose(realm: ExecutionRealm): PurposeRow;
24
+ /**
25
+ * The purpose rows a grant for this revision records: the declared purposes, the kernel's rows of
26
+ * migration warnings ({@link purposeRowsOf}) and one full-access row per realm of the decision.
27
+ * `missing` lists declared keys without a purpose (the revision must be republished with them).
28
+ */
29
+ export declare function grantPurposeRows(set: PermissionSet, decision: Pick<ExecutionDecision, "fullAccess">): {
30
+ rows: PurposeRow[];
31
+ missing: string[];
32
+ };
33
+ /**
34
+ * Against the previous approval: `added` (new, or no previous approval), `retained` (served by the
35
+ * previous grant with the same purpose), `purpose_changed`, `regranted` (the previous grant had
36
+ * the key but revoked or retired it: confirming grants it again), or `broadened` (a full-access
37
+ * realm the previous grant still serves, now forced by a key it does not cover, such as a retired
38
+ * `host.no-isolation` coming back).
39
+ */
40
+ export type RowChange = "added" | "retained" | "purpose_changed" | "regranted" | "broadened";
41
+ export interface ReviewRow extends PurposeRow {
42
+ family: string | null;
43
+ risk: PermissionRisk | null;
44
+ /** The kernel's risk sentence for the family. */
45
+ reason: string | null;
46
+ /** Against the previous approval; `added` without one. */
47
+ change: RowChange;
48
+ }
49
+ export interface ReviewInput {
50
+ revision: RevisionIdentity;
51
+ set: PermissionSet;
52
+ /** Where the revision runs: computed here from the set, so it cannot disagree with it. */
53
+ host: HostIsolation;
54
+ server: boolean;
55
+ client?: ExecutionInput["client"];
56
+ configSchemaIsolatable?: boolean;
57
+ approvalScope: ApprovalScope;
58
+ authority: GrantAuthority;
59
+ publisher: PublisherEvidence;
60
+ /** The digest of the verified attestations, when there are some. */
61
+ evidenceDigest?: string | undefined;
62
+ /** The live grant of the install's approved revision, if any. */
63
+ previous?: RevisionGrant | undefined;
64
+ }
65
+ export interface ReviewDisplay {
66
+ contract: number;
67
+ catalog: number;
68
+ revision: RevisionIdentity;
69
+ rows: ReviewRow[];
70
+ /** Declared keys without a purpose: the review cannot be confirmed until republished. */
71
+ missingPurposes: string[];
72
+ /** Keys of the previous approval this revision no longer has. */
73
+ removed: string[];
74
+ execution: {
75
+ kind: ExecutionDecision["kind"];
76
+ server: ExecutionDecision["server"]["mode"];
77
+ browser: ExecutionDecision["browser"]["mode"];
78
+ device: ExecutionDecision["device"]["mode"];
79
+ realms: Partial<Record<ExecutionRealm, string[]>>;
80
+ /** False when a key matched no catalog row: the review cannot be confirmed. */
81
+ confirmable: boolean;
82
+ };
83
+ unknownKeys: string[];
84
+ approvalScope: {
85
+ mode: ApprovalScope["mode"];
86
+ orgs: string[];
87
+ };
88
+ authority: GrantAuthority;
89
+ publisher: PublisherEvidence;
90
+ evidenceDigest: string | null;
91
+ previous: {
92
+ revision: RevisionIdentity;
93
+ generation: number;
94
+ reviewHash: string;
95
+ state: RevisionGrant["state"];
96
+ disabledKeys: string[];
97
+ retiredKeys: string[];
98
+ retiredForcing: Partial<Record<ExecutionRealm, string[]>>;
99
+ /** The full-access realms the previous grant still covers, net of revocation and retirement. */
100
+ realms: Partial<Record<ExecutionRealm, string[]>>;
101
+ approvalScope: {
102
+ mode: ApprovalScope["mode"];
103
+ orgs: string[];
104
+ };
105
+ publisher: {
106
+ evidence: RevisionGrant["publisherEvidence"];
107
+ identity: RevisionGrant["publisher"];
108
+ };
109
+ } | null;
110
+ }
111
+ /** The canonical display of a review: what the approver sees, in a stable order. */
112
+ export declare function reviewDisplay(input: ReviewInput): ReviewDisplay;
113
+ /** `review:v<contract>:<sha256 hex of the canonical display>`. */
114
+ export declare function revisionReviewHash(display: ReviewDisplay): string;
@@ -0,0 +1,145 @@
1
+ import { createHash } from "node:crypto";
2
+ import { PERMISSION_CATALOG_VERSION, permissionCatalogMatches, } from "@capybara-hq/plugin-sdk";
3
+ import { canonicalJson } from "../tools/canonical-json.js";
4
+ import { executionDecision, } from "./execution-realm.js";
5
+ import { permissionKeys } from "./permission-set.js";
6
+ import { purposeRowsOf } from "./revision-approvals.js";
7
+ import { EXECUTION_REALMS, effectiveKeys, effectiveRealms, fullAccessKey, } from "./revision-grants.js";
8
+ /**
9
+ * The reviewed display and its hash (extension permission model spec, "Review, updates and
10
+ * provenance" step 1; plan task 1.2e). Pure. A review binds everything the approver is shown: the
11
+ * exact revision, every permission row with its risk and bilingual purpose (the kernel-written rows
12
+ * of migration warnings and full access included), the execution realms and their forcing keys,
13
+ * the org scope, the approver authority, the publisher evidence, the previous approval and the diff
14
+ * against it, and the risk-contract version. Any change to one of them changes the hash, so a
15
+ * confirmation made against an older display is refused (1.3a) and a bootstrap batch hash (1.3c)
16
+ * covers each revision's display.
17
+ */
18
+ /** Bump when the display's shape or the meaning of a field changes. */
19
+ export const REVIEW_CONTRACT_VERSION = 1;
20
+ /**
21
+ * The kernel-written purpose of full access in one realm: one fixed sentence per realm. The forcing
22
+ * keys are bound separately (the grant's `realms`, the display's `execution.realms`), so a
23
+ * continuation whose forcing keys shrink keeps an identical purpose row.
24
+ */
25
+ export function fullAccessPurpose(realm) {
26
+ const zh = {
27
+ server: "在内核进程中运行,拥有内核的权限",
28
+ browser: "在应用页面中运行,拥有查看者的浏览器会话",
29
+ device: "在设备沙箱之外运行,拥有设备用户的权限",
30
+ }[realm];
31
+ const en = {
32
+ server: "Runs in the kernel process with the kernel's privileges",
33
+ browser: "Runs in the app page with the viewer's browser session",
34
+ device: "Runs outside the device sandbox as the device user",
35
+ }[realm];
36
+ return { key: fullAccessKey(realm), zh, en };
37
+ }
38
+ /**
39
+ * The purpose rows a grant for this revision records: the declared purposes, the kernel's rows of
40
+ * migration warnings ({@link purposeRowsOf}) and one full-access row per realm of the decision.
41
+ * `missing` lists declared keys without a purpose (the revision must be republished with them).
42
+ */
43
+ export function grantPurposeRows(set, decision) {
44
+ const { rows, missing } = purposeRowsOf(set);
45
+ const realms = Object.entries(decision.fullAccess);
46
+ const full = realms.map(([realm]) => fullAccessPurpose(realm));
47
+ return {
48
+ rows: [...rows, ...full].sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0)),
49
+ missing,
50
+ };
51
+ }
52
+ const sortedRealms = (realms) => Object.fromEntries(EXECUTION_REALMS.filter((realm) => realms[realm] !== undefined).map((realm) => [
53
+ realm,
54
+ [...(realms[realm] ?? [])].sort(),
55
+ ]));
56
+ /** The canonical display of a review: what the approver sees, in a stable order. */
57
+ export function reviewDisplay(input) {
58
+ const execution = executionDecision({
59
+ keys: permissionKeys(input.set),
60
+ server: input.server,
61
+ client: input.client,
62
+ host: input.host,
63
+ ...(input.configSchemaIsolatable !== undefined && {
64
+ configSchemaIsolatable: input.configSchemaIsolatable,
65
+ }),
66
+ });
67
+ const { rows, missing } = grantPurposeRows(input.set, execution);
68
+ const previous = input.previous;
69
+ const before = new Map(previous?.purposes.map((row) => [row.key, row]) ?? []);
70
+ const serving = new Set(previous ? effectiveKeys(previous) : []);
71
+ const previousRealms = previous ? effectiveRealms(previous) : {};
72
+ const fullAccessRealm = new Map(EXECUTION_REALMS.map((realm) => [fullAccessKey(realm), realm]));
73
+ const reviewRows = rows.map((row) => {
74
+ const [match] = permissionCatalogMatches(row.key);
75
+ const old = before.get(row.key);
76
+ const realm = fullAccessRealm.get(row.key);
77
+ const covered = new Set(realm ? (previousRealms[realm] ?? []) : []);
78
+ const broadened = realm !== undefined &&
79
+ (execution.fullAccess[realm] ?? []).some((forcing) => !covered.has(forcing));
80
+ const change = !old
81
+ ? "added"
82
+ : !serving.has(row.key)
83
+ ? "regranted"
84
+ : broadened
85
+ ? "broadened"
86
+ : old.zh === row.zh && old.en === row.en
87
+ ? "retained"
88
+ : "purpose_changed";
89
+ return {
90
+ ...row,
91
+ family: match?.family ?? null,
92
+ risk: match?.risk ?? null,
93
+ reason: match?.reason ?? null,
94
+ change,
95
+ };
96
+ });
97
+ const current = new Set(rows.map((row) => row.key));
98
+ return {
99
+ contract: REVIEW_CONTRACT_VERSION,
100
+ catalog: PERMISSION_CATALOG_VERSION,
101
+ revision: { ...input.revision },
102
+ rows: reviewRows,
103
+ missingPurposes: [...missing].sort(),
104
+ removed: (previous?.keys ?? []).filter((key) => !current.has(key)).sort(),
105
+ execution: {
106
+ kind: execution.kind,
107
+ server: execution.server.mode,
108
+ browser: execution.browser.mode,
109
+ device: execution.device.mode,
110
+ realms: execution.fullAccess,
111
+ confirmable: execution.confirmable,
112
+ },
113
+ unknownKeys: [...execution.unknownKeys],
114
+ approvalScope: {
115
+ mode: input.approvalScope.mode,
116
+ orgs: input.approvalScope.mode === "named" ? [...new Set(input.approvalScope.orgs)].sort() : [],
117
+ },
118
+ authority: input.authority,
119
+ publisher: input.publisher,
120
+ evidenceDigest: input.evidenceDigest ?? null,
121
+ previous: previous
122
+ ? {
123
+ revision: { ...previous.revision },
124
+ generation: previous.generation,
125
+ reviewHash: previous.reviewHash,
126
+ state: previous.state,
127
+ disabledKeys: [...previous.disabledKeys].sort(),
128
+ retiredKeys: [...previous.retiredKeys].sort(),
129
+ retiredForcing: sortedRealms(previous.retiredForcing),
130
+ realms: sortedRealms(previousRealms),
131
+ approvalScope: {
132
+ mode: previous.approvalScope.mode,
133
+ orgs: previous.approvalScope.mode === "named"
134
+ ? [...new Set(previous.approvalScope.orgs)].sort()
135
+ : [],
136
+ },
137
+ publisher: { evidence: previous.publisherEvidence, identity: previous.publisher },
138
+ }
139
+ : null,
140
+ };
141
+ }
142
+ /** `review:v<contract>:<sha256 hex of the canonical display>`. */
143
+ export function revisionReviewHash(display) {
144
+ return `review:v${display.contract}:${createHash("sha256").update(canonicalJson(display)).digest("hex")}`;
145
+ }
@@ -3,8 +3,10 @@ import { KernelDb } from "../infra/database/kernel-db.js";
3
3
  import { TransactionHost } from "../infra/database/transaction-host.js";
4
4
  import { ExtensionApprovals } from "./approvals.js";
5
5
  import { ExtensionBlobs } from "./blobs.js";
6
+ import { IsolationStatusReader } from "./isolated/status.js";
7
+ import { type ReviewedGrants } from "./isolated/tier.js";
6
8
  import { type PermissionSet } from "./permission-set.js";
7
- import { ExtensionRevisionGrants, type NewRevisionGrant, type PurposeRow, type RevisionGrant, type RevisionIdentity } from "./revision-grants.js";
9
+ import { type ApprovalScope, type ExecutionRealm, ExtensionRevisionGrants, type NewRevisionGrant, type PurposeRow, type RevisionGrant, type RevisionIdentity } from "./revision-grants.js";
8
10
  /**
9
11
  * Revision approvals in shadow mode (extension permission model plan task 1.2b; the rollout fence
10
12
  * "shadow mode until 1.5a"). Every installed revision is resolved against its own revision grant,
@@ -24,6 +26,24 @@ export type ShadowGrantStatus =
24
26
  | "partially_revoked"
25
27
  /** No live grant of its own; it waits for review. */
26
28
  | "missing_grant"
29
+ /**
30
+ * No live grant of its own, and its review needs full access acknowledged per realm: a
31
+ * confirmation without the acknowledgement (plan task 1.3d) records none. A prediction: a
32
+ * revision that continues its approved grant at promotion (verified publisher evidence, which
33
+ * this report does not have) needs no acknowledgement; `continuity` says why it would not.
34
+ */
35
+ | "awaiting_acknowledgement"
36
+ /**
37
+ * Its own live grant covers its keys, but its catalog item's org scope is wider than the grant's
38
+ * approval scope: widening the scope needs a new review (enforced by plan task 1.5a).
39
+ */
40
+ | "scope_exceeds_grant"
41
+ /**
42
+ * Its own live grant does not cover full access in a realm its execution decision needs (a
43
+ * forcing key not reviewed, or retired, or the realm's key revoked): it would not serve until a
44
+ * new review (`uncoveredForcing` lists the keys).
45
+ */
46
+ | "realm_uncovered"
27
47
  /** No live grant, and the manifest lacks bilingual purposes: Republish with purposes. */
28
48
  | "missing_purposes"
29
49
  /** The package sha512 is not recorded yet (the backfill job fills it); no grant can match. */
@@ -47,6 +67,8 @@ export interface ShadowRevisionDecision {
47
67
  ungrantedKeys: string[];
48
68
  /** Keys without a bilingual purpose. */
49
69
  missingPurposes: string[];
70
+ /** Per realm, the forcing keys its own grant does not cover (`realm_uncovered`). */
71
+ uncoveredForcing?: Partial<Record<ExecutionRealm, string[]>>;
50
72
  /** Why the approved revision's grant does not carry over as continuity, when there is one. */
51
73
  continuity?: string;
52
74
  /** A required bootstrap install (the start gate). */
@@ -107,7 +129,18 @@ export declare function resolveRevisionGrant(input: {
107
129
  own: RevisionGrant | undefined;
108
130
  approved: RevisionGrant | undefined;
109
131
  legacy: LegacyDecision;
132
+ /** Its review needs full access acknowledged (the realms of its execution decision). */
133
+ fullAccess?: boolean;
134
+ /** Its catalog item's current org scope, when it is installed from a catalog item. */
135
+ itemScope?: ApprovalScope | undefined;
136
+ /**
137
+ * Per realm of its execution decision, the forcing keys its own grant does not cover
138
+ * (`isolated/tier.ts` `uncoveredForcing`, plan task 1.3b); empty or absent: covered.
139
+ */
140
+ uncovered?: Partial<Record<ExecutionRealm, string[]>> | undefined;
110
141
  }): ShadowRevisionDecision;
142
+ /** Whether `scope` reaches orgs `granted` does not (`all` ⊇ `optional` ⊇ `named`, named subsets). */
143
+ export declare function scopeWider(scope: ApprovalScope, granted: ApprovalScope): boolean;
111
144
  /** What a reviewed promotion carries besides the revision: its verified publisher evidence. */
112
145
  export interface PromotionEvidence {
113
146
  publisher: NewRevisionGrant["publisher"];
@@ -126,21 +159,39 @@ export type PromotionOutcome = {
126
159
  reason: string;
127
160
  };
128
161
  /** The installed revisions' shadow decisions, and promotion with continuity. */
129
- export declare class ExtensionRevisionApprovals {
162
+ export declare class ExtensionRevisionApprovals implements ReviewedGrants {
130
163
  private readonly kdb;
131
164
  readonly txHost: TransactionHost;
132
165
  private readonly grants;
133
166
  private readonly approvals;
134
167
  private readonly blobs;
135
168
  private readonly config;
169
+ /** The deployment-wide isolation state the shadow decisions are computed for (1.4j). */
170
+ private readonly isolation?;
136
171
  /** Permission sets by package sha256: content-addressed, so a cached set never goes stale. */
137
172
  private readonly sets;
138
- constructor(kdb: KernelDb, txHost: TransactionHost, grants: ExtensionRevisionGrants, approvals: Pick<ExtensionApprovals, "all">, blobs: Pick<ExtensionBlobs, "get">, config: KernelConfigService);
173
+ constructor(kdb: KernelDb, txHost: TransactionHost, grants: ExtensionRevisionGrants, approvals: Pick<ExtensionApprovals, "all">, blobs: Pick<ExtensionBlobs, "get">, config: KernelConfigService,
174
+ /** The deployment-wide isolation state the shadow decisions are computed for (1.4j). */
175
+ isolation?: Pick<IsolationStatusReader, "hostIsolation"> | undefined);
139
176
  /**
140
177
  * The shadow decision of every install record. A package that cannot be read is reported as
141
178
  * `unreadable` and never hides the others.
142
179
  */
143
180
  decisions(): Promise<ShadowRevisionDecision[]>;
181
+ /**
182
+ * The live grant (approved or partially_revoked) of exactly this revision when a person made it:
183
+ * source review, operator_cli or operator_config, whatever its publisher evidence (pin_only and
184
+ * none included). Undefined otherwise: no grant, a revoked or retired one, a continuity or auto
185
+ * grant. Admission (plan task 1.3b, `isolated/tier.ts`) accepts an official revision without a
186
+ * publisher proof when this returns a grant (#1368). A plain read; safe on every replica.
187
+ */
188
+ reviewedGrant(revision: RevisionIdentity): Promise<RevisionGrant | undefined>;
189
+ /**
190
+ * {@link promote} for an install that has just moved to `candidate` in the caller's transaction
191
+ * (`ExtensionAdminOps.install`): the package was read before it, so its permission set is given
192
+ * and no object storage call holds the transaction. A downgrade is a rollback.
193
+ */
194
+ promoteInstalled(candidate: RevisionIdentity, set: PermissionSet, kind: PromotionKind): Promise<PromotionOutcome>;
144
195
  /** The facts the enforcing start gate would act on; computed and reported, never refused. */
145
196
  startGate(): Promise<ShadowStartGate>;
146
197
  /**
@@ -159,6 +210,10 @@ export declare class ExtensionRevisionApprovals {
159
210
  /** The stored package of a revision, or undefined while its sha512 is not recorded. */
160
211
  private sha256Of;
161
212
  private setOf;
213
+ /** A package's permission set and section, cached by sha256 (content-addressed, never stale). */
214
+ private packageOf;
215
+ /** The current org scope of the catalog item an install comes from, if any. */
216
+ private itemScope;
162
217
  }
163
218
  /**
164
219
  * The review hash of a continuity grant: the kernel reviewed it against its source, so the hash