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

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 (37) hide show
  1. package/dist/catalog/marketplaces.service.d.ts +1 -1
  2. package/dist/catalog/provenance.d.ts +69 -0
  3. package/dist/catalog/provenance.js +108 -0
  4. package/dist/ctx/create-ctx.d.ts +16 -0
  5. package/dist/ctx/create-ctx.js +269 -34
  6. package/dist/extensions/execution-realm.d.ts +96 -0
  7. package/dist/extensions/execution-realm.js +141 -0
  8. package/dist/extensions/extensions.module.js +3 -0
  9. package/dist/extensions/grant-epoch.d.ts +4 -2
  10. package/dist/extensions/grant-epoch.js +4 -2
  11. package/dist/extensions/host.d.ts +25 -2
  12. package/dist/extensions/host.js +120 -8
  13. package/dist/extensions/instance.d.ts +2 -0
  14. package/dist/extensions/instance.js +1 -0
  15. package/dist/extensions/isolated/admission.d.ts +6 -0
  16. package/dist/extensions/isolated/admission.js +17 -0
  17. package/dist/extensions/ledger.d.ts +5 -0
  18. package/dist/extensions/ledger.js +16 -0
  19. package/dist/extensions/permission-view.d.ts +2 -2
  20. package/dist/extensions/registry.d.ts +6 -0
  21. package/dist/extensions/registry.js +8 -0
  22. package/dist/extensions/review-hash.d.ts +114 -0
  23. package/dist/extensions/review-hash.js +145 -0
  24. package/dist/extensions/revision-grants.d.ts +10 -0
  25. package/dist/extensions/revocation-leases.d.ts +273 -0
  26. package/dist/extensions/revocation-leases.js +533 -0
  27. package/dist/extensions/revocation.d.ts +78 -0
  28. package/dist/extensions/revocation.js +202 -0
  29. package/dist/index.d.ts +6 -2
  30. package/dist/index.js +6 -2
  31. package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
  32. package/dist/lifecycle/kernel-lifecycle.js +24 -18
  33. package/dist/overrides.d.ts +5 -1
  34. package/dist/overrides.js +2 -0
  35. package/dist/packages/official-publisher.d.ts +39 -0
  36. package/dist/packages/official-publisher.js +125 -47
  37. package/package.json +2 -2
@@ -0,0 +1,141 @@
1
+ import { CLIENT_KEY, ISOLATED_CLIENT_REALM_AVAILABLE, ISOLATED_EXTENSION_POINTS, PERMISSION_REALM_FIT, PROVIDER_CONTRACTS, permissionCatalogMatches, } from "@capybara-hq/plugin-sdk";
2
+ import { fullAccessKey } from "./revision-grants.js";
3
+ export const HOST_NO_ISOLATION_KEY = "host.no-isolation";
4
+ const sorted = (keys) => [...new Set(keys)].sort();
5
+ /** The realm a key forces, or `undefined` when it fits isolation (or is the kernel's own). */
6
+ function forcedRealm(key) {
7
+ const matches = permissionCatalogMatches(key);
8
+ const [match] = matches;
9
+ if (!match || matches.length !== 1)
10
+ return "unknown";
11
+ const fit = PERMISSION_REALM_FIT[match.family];
12
+ switch (fit) {
13
+ case "isolated":
14
+ case "kernel":
15
+ return undefined;
16
+ case "server":
17
+ case "browser":
18
+ case "device":
19
+ return { realm: fit, forcingKey: key };
20
+ case "point": {
21
+ const point = match.declaration;
22
+ if (ISOLATED_EXTENSION_POINTS.includes(point))
23
+ return undefined;
24
+ const provided = match.family === "provides" || match.family === "provides.standard";
25
+ const contract = PROVIDER_CONTRACTS[point];
26
+ return {
27
+ realm: "server",
28
+ forcingKey: provided && contract ? contract.forcingKey : key,
29
+ };
30
+ }
31
+ }
32
+ }
33
+ /**
34
+ * The kernel's forcing key of a deployment config schema outside the isolated subset. The config
35
+ * field keys stay what they are (each fits isolation); the schema itself is what forces.
36
+ */
37
+ export const CONFIG_SCHEMA_UNSUPPORTED_KEY = "execution.config.unsupported";
38
+ export function executionDecision(input) {
39
+ const forcing = { server: [], browser: [], device: [] };
40
+ const unknownKeys = [];
41
+ // a schema outside the subset forces full access, whether or not it declares a field
42
+ if (input.configSchemaIsolatable === false)
43
+ forcing.server.push(CONFIG_SCHEMA_UNSUPPORTED_KEY);
44
+ for (const key of input.keys) {
45
+ const forced = forcedRealm(key);
46
+ if (forced === "unknown") {
47
+ unknownKeys.push(key);
48
+ forcing.server.push(key);
49
+ }
50
+ else if (forced) {
51
+ forcing[forced.realm].push(forced.forcingKey);
52
+ }
53
+ }
54
+ if (!input.server && input.client === undefined) {
55
+ return {
56
+ kind: "declarative",
57
+ server: { mode: "none" },
58
+ browser: { mode: "none" },
59
+ device: { mode: "none" },
60
+ fullAccess: {},
61
+ unknownKeys: sorted(unknownKeys),
62
+ confirmable: unknownKeys.length === 0,
63
+ };
64
+ }
65
+ let server = { mode: "none" };
66
+ if (input.server) {
67
+ const keys = sorted(forcing.server);
68
+ if (input.host === "not_configured") {
69
+ server = { mode: "full-access", forcingKeys: sorted([...keys, HOST_NO_ISOLATION_KEY]) };
70
+ }
71
+ else if (keys.length > 0) {
72
+ server = { mode: "full-access", forcingKeys: keys };
73
+ }
74
+ else if (input.host === "failing") {
75
+ server = { mode: "unavailable", reason: "isolation_unavailable" };
76
+ }
77
+ else {
78
+ server = { mode: "isolated" };
79
+ }
80
+ }
81
+ let browser = { mode: "none" };
82
+ if (input.client !== undefined) {
83
+ browser =
84
+ input.client.realm === "isolated" && ISOLATED_CLIENT_REALM_AVAILABLE
85
+ ? { mode: "isolated" }
86
+ : {
87
+ mode: "full-access",
88
+ forcingKeys: sorted(forcing.browser.length > 0 ? forcing.browser : [CLIENT_KEY]),
89
+ };
90
+ }
91
+ else if (forcing.browser.length > 0) {
92
+ // client declarations without a client entry still need the page's privileges to mean anything
93
+ browser = { mode: "full-access", forcingKeys: sorted(forcing.browser) };
94
+ }
95
+ const device = forcing.device.length > 0
96
+ ? { mode: "full-access", forcingKeys: sorted(forcing.device) }
97
+ : { mode: "none" };
98
+ const fullAccess = {};
99
+ for (const [realm, placement] of [
100
+ ["server", server],
101
+ ["browser", browser],
102
+ ["device", device],
103
+ ]) {
104
+ if (placement.mode === "full-access")
105
+ fullAccess[realm] = placement.forcingKeys;
106
+ }
107
+ return {
108
+ kind: "code",
109
+ server,
110
+ browser,
111
+ device,
112
+ fullAccess,
113
+ unknownKeys: sorted(unknownKeys),
114
+ confirmable: unknownKeys.length === 0,
115
+ };
116
+ }
117
+ /** The kernel-generated `execution.full-access:<realm>` keys a decision's grant must carry. */
118
+ export function fullAccessKeys(decision) {
119
+ return Object.keys(decision.fullAccess).map(fullAccessKey).sort();
120
+ }
121
+ /** A one-line summary for review lists and `capybara-plugin check`. */
122
+ export function describeExecution(decision) {
123
+ const unknown = decision.confirmable
124
+ ? ""
125
+ : `; unconfirmable: unknown ${decision.unknownKeys.join(", ")}`;
126
+ if (decision.kind === "declarative")
127
+ return `declarative only: no extension process${unknown}`;
128
+ const parts = [];
129
+ for (const realm of ["server", "browser", "device"]) {
130
+ const placement = decision[realm];
131
+ if (placement.mode === "none")
132
+ continue;
133
+ if (placement.mode === "isolated")
134
+ parts.push(`${realm}: isolated`);
135
+ else if (placement.mode === "unavailable")
136
+ parts.push(`${realm}: isolation unavailable`);
137
+ else
138
+ parts.push(`${realm}: full access (forced by ${placement.forcingKeys.join(", ")})`);
139
+ }
140
+ return `${parts.join("; ")}${unknown}`;
141
+ }
@@ -35,6 +35,7 @@ import { PluginIcons } from "./plugin-icons.js";
35
35
  import { ExtensionPointDefaults } from "./point-defaults.js";
36
36
  import { ExtensionPointServingModule } from "./point-serving.js";
37
37
  import { ExtensionRegistryModule } from "./registry.js";
38
+ import { ExtensionRevocations } from "./revocation.js";
38
39
  import { SingleProviderGuard } from "./single-provider.js";
39
40
  import { ReplicaStatusStore } from "./sources.js";
40
41
  import { ExtensionStateModule } from "./state.module.js";
@@ -89,6 +90,7 @@ ExtensionsModule = __decorate([
89
90
  ExtensionEffects,
90
91
  ExtensionEffectKeys,
91
92
  ExtensionLifecycle,
93
+ ExtensionRevocations,
92
94
  ExtensionAdmin,
93
95
  ExtensionAdminOps,
94
96
  ExtensionDisplayNames,
@@ -112,6 +114,7 @@ ExtensionsModule = __decorate([
112
114
  ExtensionEffects,
113
115
  ExtensionEffectKeys,
114
116
  ExtensionLifecycle,
117
+ ExtensionRevocations,
115
118
  ExtensionAdmin,
116
119
  ExtensionAdminOps,
117
120
  ExtensionDisplayNames,
@@ -22,8 +22,10 @@
22
22
  * across all replicas, on a worker, but the epoch guards each replica's own in-memory cache, so
23
23
  * every replica (api, worker and gateway alike) must read it itself. The read is a one-row
24
24
  * primary-key lookup and writes nothing, so a timer per replica carries no cross-replica state;
25
- * the source of truth stays in PostgreSQL. It runs only after an isolated grant was requested on
26
- * this replica and stops when the extension host closes.
25
+ * the source of truth stays in PostgreSQL. It runs once an isolated grant was requested on this
26
+ * replica or an instance with a package opened its permission lease (revocation, plan task 1.3e),
27
+ * and stops when the extension host closes. Each change revalidates the cached isolated grants
28
+ * with calls in flight and every permission lease (one grant read for all leases).
27
29
  */
28
30
  /** #1373: stale kernel admission or broker access ends at most 5 s after a revocation commits. */
29
31
  export declare const REVOCATION_BOUND_MS = 5000;
@@ -25,8 +25,10 @@ import { KERNEL_APPLICATION_NAME } from "../db/pool.js";
25
25
  * across all replicas, on a worker, but the epoch guards each replica's own in-memory cache, so
26
26
  * every replica (api, worker and gateway alike) must read it itself. The read is a one-row
27
27
  * primary-key lookup and writes nothing, so a timer per replica carries no cross-replica state;
28
- * the source of truth stays in PostgreSQL. It runs only after an isolated grant was requested on
29
- * this replica and stops when the extension host closes.
28
+ * the source of truth stays in PostgreSQL. It runs once an isolated grant was requested on this
29
+ * replica or an instance with a package opened its permission lease (revocation, plan task 1.3e),
30
+ * and stops when the extension host closes. Each change revalidates the cached isolated grants
31
+ * with calls in flight and every permission lease (one grant read for all leases).
30
32
  */
31
33
  /** #1373: stale kernel admission or broker access ends at most 5 s after a revocation commits. */
32
34
  export const REVOCATION_BOUND_MS = 5_000;
@@ -43,6 +43,7 @@ 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
45
  import { ExtensionRevisionApprovals } from "./revision-approvals.js";
46
+ import { type LeaseState } from "./revocation-leases.js";
46
47
  import { type ExtensionSource, ReplicaStatusStore } from "./sources.js";
47
48
  export { deploymentConfigHash };
48
49
  /**
@@ -216,7 +217,12 @@ export declare class ExtensionHost {
216
217
  private readonly isolatedAuthority;
217
218
  private readonly isolatedLanes;
218
219
  private readonly isolatedGrants;
219
- /** This replica's view of the deployment grant epoch; polls only once an isolated grant was issued. */
220
+ /** The permission leases of this replica's instances (revocation, plan task 1.3e). */
221
+ private readonly revisionLeases;
222
+ /**
223
+ * This replica's view of the deployment grant epoch; polls once an isolated grant was issued or
224
+ * an instance with a package opened its permission lease.
225
+ */
220
226
  private readonly grantEpoch;
221
227
  private readonly epochReader;
222
228
  private readonly executionTier;
@@ -378,7 +384,9 @@ export declare class ExtensionHost {
378
384
  * Shadow revision approvals (plan task 1.2b): reported at start, never refusing. Absent in a
379
385
  * hand-built host, which then reports nothing.
380
386
  */
381
- revisionApprovals?: Pick<ExtensionRevisionApprovals, "startGate"> | undefined);
387
+ revisionApprovals?: Pick<ExtensionRevisionApprovals, "startGate"> | undefined,
388
+ /** Kernel tests only: enforce revocation before plan task 1.5a (`REVOCATION_ENFORCEMENT`). */
389
+ revocationEnforcement?: boolean);
382
390
  /** The startup config's `extensionConfig` (file / Nacos merged with env). */
383
391
  private get extensionConfig();
384
392
  /** `extensionPermissions.autoApprove` (development and trials only; see `planApprovals`). */
@@ -471,6 +479,14 @@ export declare class ExtensionHost {
471
479
  /** 把一份已校验部署配置里的密钥值登记到日志打码。 */
472
480
  private reportSecrets;
473
481
  private tierOf;
482
+ /**
483
+ * The tier after a revocation (plan task 1.3e; enforced from task 1.5a, until then the leases
484
+ * only report it). A revision whose whole grant is revoked waits for a new review. A trusted
485
+ * (in-process) revision whose grant no longer serves server full access runs isolated when the
486
+ * remaining grant fits the sandbox and the package has an isolated form, and otherwise waits for
487
+ * a new review ({@link RevocationPendingError}: reported pending, not failed).
488
+ */
489
+ private afterRevocation;
474
490
  /**
475
491
  * Reconciles enabled installs from PostgreSQL at startup and during convergence. It removes
476
492
  * withdrawn revisions, verifies the tier, and prepares replacements in dependency order.
@@ -565,6 +581,13 @@ export declare class ExtensionHost {
565
581
  */
566
582
  activatePending(): Promise<string[]>;
567
583
  revokeIsolatedInvocations(scope: IsolatedRevocation): void;
584
+ /**
585
+ * A committed grant revocation (the local fence after the commit, or a sibling's hint): this
586
+ * replica's leases of the plugin revalidate now (plan task 1.3e).
587
+ */
588
+ fenceRevocation(plugin: string): Promise<void>;
589
+ /** The revocation decisions this replica's leases computed for a plugin's instances. */
590
+ revocationDecisions(plugin: string): LeaseState[];
568
591
  refreshIsolatedOrgIntent(orgId?: string): Promise<void>;
569
592
  revalidateIsolatedInvocations(): Promise<void>;
570
593
  /**
@@ -70,6 +70,7 @@ import { blockingKeys, computePermissionSet, SETUP_CHECK_KEY_PREFIX, UI_VIEW_KEY
70
70
  import { ExtensionRegistry } from "./registry.js";
71
71
  import { ExtensionResolveError, electSingleProviders, PROVIDER_CONFLICT, providerConflictMessage, resolveExtensions, } from "./resolve.js";
72
72
  import { ExtensionRevisionApprovals } from "./revision-approvals.js";
73
+ import { leaseStateOf, REVOCATION_ENFORCEMENT, RevisionLeases, RevocationPendingError, readGrantSurfaceBySha256, readGrantSurfacesBySha256, realmAfterRevocation, } from "./revocation-leases.js";
73
74
  import { ReplicaStatusStore, } from "./sources.js";
74
75
  import { PackageShaMismatchError, packageRootOf } from "./sync.js";
75
76
  export { deploymentConfigHash };
@@ -413,7 +414,12 @@ let ExtensionHost = class ExtensionHost {
413
414
  isolatedAuthority = new WeakMap();
414
415
  isolatedLanes = new WeakMap();
415
416
  isolatedGrants;
416
- /** This replica's view of the deployment grant epoch; polls only once an isolated grant was issued. */
417
+ /** The permission leases of this replica's instances (revocation, plan task 1.3e). */
418
+ revisionLeases;
419
+ /**
420
+ * This replica's view of the deployment grant epoch; polls once an isolated grant was issued or
421
+ * an instance with a package opened its permission lease.
422
+ */
417
423
  grantEpoch;
418
424
  epochReader;
419
425
  executionTier = new Map();
@@ -550,7 +556,9 @@ let ExtensionHost = class ExtensionHost {
550
556
  * Shadow revision approvals (plan task 1.2b): reported at start, never refusing. Absent in a
551
557
  * hand-built host, which then reports nothing.
552
558
  */
553
- revisionApprovals) {
559
+ revisionApprovals,
560
+ /** Kernel tests only: enforce revocation before plan task 1.5a (`REVOCATION_ENFORCEMENT`). */
561
+ revocationEnforcement) {
554
562
  this.registry = registry;
555
563
  this.installs = installs;
556
564
  this.approvals = approvals;
@@ -589,15 +597,54 @@ let ExtensionHost = class ExtensionHost {
589
597
  void this.isolatedGrants
590
598
  .epochChanged()
591
599
  .catch((err) => this.log.warn("isolated extension grant revalidation failed", { err }));
600
+ void this.revisionLeases
601
+ .epochChanged()
602
+ .catch((err) => this.log.warn("extension permission lease revalidation failed", { err }));
603
+ },
604
+ onSettleDeadline: () => {
605
+ this.isolatedGrants.fenceStale();
606
+ this.revisionLeases.fenceStale();
592
607
  },
593
- onSettleDeadline: () => this.isolatedGrants.fenceStale(),
594
608
  onExpired: () => {
595
609
  this.log.warn("isolated extension grants fenced: the grant epoch could not be read");
596
610
  this.isolatedGrants.fenceAll();
611
+ this.revisionLeases.fenceAll();
597
612
  },
598
613
  onFault: (err) => this.log.warn("reading the extension grant epoch failed", { err }),
599
614
  });
600
615
  this.isolatedGrants = new IsolatedInvocationGrants(this.grantEpoch, capacity.grantCacheEntries);
616
+ const grantReads = kernelDb(kdb.pool);
617
+ this.revisionLeases = new RevisionLeases({
618
+ epochs: this.grantEpoch,
619
+ // one query for every lease of a fence or epoch change
620
+ read: async (sha256s) => {
621
+ const grants = await readGrantSurfacesBySha256(grantReads, sha256s);
622
+ return new Map(sha256s.map((sha256) => [sha256, leaseStateOf(grants.get(sha256))]));
623
+ },
624
+ ...(revocationEnforcement === true && { enforce: true }),
625
+ onUnload: (plugin) => {
626
+ this.log.warn("extension grant revoked: unloading its generation", { plugin });
627
+ void this.converge().catch((err) => this.log.error("converging after a grant revocation failed", { plugin, err }));
628
+ },
629
+ onRestored: (plugin) => {
630
+ // withdrawn registrations come back only with a new setup
631
+ this.log.info("extension grant restored withdrawn keys: reloading it", { plugin });
632
+ void this.reload(plugin).catch((err) => this.log.error("reloading after a restored grant failed", { plugin, err }));
633
+ },
634
+ onFault: (plugin, err) => this.log.warn("reading an extension's revision grant failed", { plugin, err }),
635
+ // shadow mode until plan task 1.5a: what enforcement would do, logged and never enforced
636
+ onShadow: (plugin, decision) => this.log.warn("extension revocation computed (shadow mode, not enforced)", {
637
+ plugin,
638
+ ...("refusedCall" in decision
639
+ ? { wouldRefuseCall: decision.refusedCall }
640
+ : {
641
+ wouldWithdrawOrRefuse: decision.refused,
642
+ wouldUnloadInProcess: decision.lostServerFullAccess,
643
+ wouldUnload: decision.revoked,
644
+ status: decision.state.status,
645
+ }),
646
+ }),
647
+ });
601
648
  this.deps = {
602
649
  db: kdb.pool,
603
650
  dbUrl: c.db.url,
@@ -671,6 +718,8 @@ let ExtensionHost = class ExtensionHost {
671
718
  }
672
719
  },
673
720
  locks,
721
+ leases: this.revisionLeases,
722
+ registrationsChanged: (plugin) => this.registry.registrationsChanged(plugin),
674
723
  runWorkers: c.roles.includes("worker"),
675
724
  log,
676
725
  };
@@ -1002,10 +1051,39 @@ let ExtensionHost = class ExtensionHost {
1002
1051
  }
1003
1052
  tierOf(loader, revision, verifyBytes) {
1004
1053
  const fixtures = this.options[KERNEL_FIXTURE_TRUST];
1005
- if (fixtures === true || fixtures?.installDigests.includes(revision.sha256)) {
1006
- return Promise.resolve("trusted");
1054
+ const tier = fixtures === true || fixtures?.installDigests.includes(revision.sha256)
1055
+ ? Promise.resolve("trusted")
1056
+ : (loader.tier?.(revision, verifyBytes) ?? Promise.resolve("isolated"));
1057
+ return tier.then((t) => (t === "refused" ? t : this.afterRevocation(revision, t)));
1058
+ }
1059
+ /**
1060
+ * The tier after a revocation (plan task 1.3e; enforced from task 1.5a, until then the leases
1061
+ * only report it). A revision whose whole grant is revoked waits for a new review. A trusted
1062
+ * (in-process) revision whose grant no longer serves server full access runs isolated when the
1063
+ * remaining grant fits the sandbox and the package has an isolated form, and otherwise waits for
1064
+ * a new review ({@link RevocationPendingError}: reported pending, not failed).
1065
+ */
1066
+ async afterRevocation(revision, tier) {
1067
+ if (!this.revisionLeases.enforced)
1068
+ return tier;
1069
+ const grant = await readGrantSurfaceBySha256(kernelDb(this.deps.db), revision.sha256);
1070
+ if (!grant)
1071
+ return tier;
1072
+ if (grant.state === "revoked") {
1073
+ throw new RevocationPendingError("The revision's grant was revoked; it waits for a new review");
1074
+ }
1075
+ if (tier !== "trusted" || !leaseStateOf(grant).realmsRevoked.includes("server"))
1076
+ return tier;
1077
+ if (realmAfterRevocation(grant, "server") === "isolated") {
1078
+ try {
1079
+ assertIsolatedSection(revision.section);
1080
+ return "isolated";
1081
+ }
1082
+ catch {
1083
+ throw new RevocationPendingError("Full access for the server realm was revoked and the package has no isolated form; it waits for a new review");
1084
+ }
1007
1085
  }
1008
- return loader.tier?.(revision, verifyBytes) ?? Promise.resolve("isolated");
1086
+ throw new RevocationPendingError("Full access for the server realm was revoked and the remaining grant still needs it; it waits for a new review");
1009
1087
  }
1010
1088
  /**
1011
1089
  * Reconciles enabled installs from PostgreSQL at startup and during convergence. It removes
@@ -1028,6 +1106,8 @@ let ExtensionHost = class ExtensionHost {
1028
1106
  const rejected = new Map();
1029
1107
  const rejectedActions = new Map();
1030
1108
  let proofMode;
1109
+ /** Revisions a revocation sends back to review: pending, not failed (plan task 1.3e). */
1110
+ const awaitingReview = new Map();
1031
1111
  for (const d of electAmong) {
1032
1112
  if (declared.has(d.name))
1033
1113
  continue;
@@ -1050,7 +1130,10 @@ let ExtensionHost = class ExtensionHost {
1050
1130
  tiers.set(d.name, tier);
1051
1131
  }
1052
1132
  catch (error) {
1053
- rejected.set(d.name, errMsg(error));
1133
+ if (error instanceof RevocationPendingError)
1134
+ awaitingReview.set(d.name, error.message);
1135
+ else
1136
+ rejected.set(d.name, errMsg(error));
1054
1137
  }
1055
1138
  }
1056
1139
  // Single-provider election: of the enabled install records providing one single-provider
@@ -1112,6 +1195,20 @@ let ExtensionHost = class ExtensionHost {
1112
1195
  detail: null,
1113
1196
  });
1114
1197
  }
1198
+ for (const d of desired) {
1199
+ const waiting = awaitingReview.get(d.name);
1200
+ if (waiting === undefined)
1201
+ continue;
1202
+ await this.writeStatus({
1203
+ plugin: d.name,
1204
+ version: d.version,
1205
+ sha256: d.sha256,
1206
+ source: "install",
1207
+ state: "pending",
1208
+ reason: "approval",
1209
+ detail: waiting,
1210
+ });
1211
+ }
1115
1212
  for (const d of desired) {
1116
1213
  const detail = rejected.get(d.name);
1117
1214
  if (!detail)
@@ -1917,6 +2014,18 @@ let ExtensionHost = class ExtensionHost {
1917
2014
  this.isolatedLanes.get(instance)?.revokeOrg(scope.orgId);
1918
2015
  }
1919
2016
  }
2017
+ /**
2018
+ * A committed grant revocation (the local fence after the commit, or a sibling's hint): this
2019
+ * replica's leases of the plugin revalidate now (plan task 1.3e).
2020
+ */
2021
+ fenceRevocation(plugin) {
2022
+ return this.revisionLeases.fence(plugin);
2023
+ }
2024
+ /** The revocation decisions this replica's leases computed for a plugin's instances. */
2025
+ revocationDecisions(plugin) {
2026
+ // the computed decisions of every instance of the plugin on this replica
2027
+ return this.revisionLeases.statesOf(plugin);
2028
+ }
1920
2029
  refreshIsolatedOrgIntent(orgId) {
1921
2030
  return this.isolatedGrants.refreshOrgIntent(orgId);
1922
2031
  }
@@ -2244,6 +2353,7 @@ let ExtensionHost = class ExtensionHost {
2244
2353
  configHash: spec.configHash,
2245
2354
  permissions: spec.permissions,
2246
2355
  extensionDb,
2356
+ inProcess: !spec.isolated,
2247
2357
  onCtx: (c) => {
2248
2358
  if (c)
2249
2359
  ctx = c;
@@ -2970,6 +3080,8 @@ ExtensionHost = __decorate([
2970
3080
  __param(21, Inject(EXTENSION_NET_SEAMS)),
2971
3081
  __param(22, Inject(ConfiguredExtensionDbIdentity)),
2972
3082
  __param(23, Optional()),
2973
- __param(23, Inject(ExtensionRevisionApprovals))
3083
+ __param(23, Inject(ExtensionRevisionApprovals)),
3084
+ __param(24, Optional()),
3085
+ __param(24, Inject(REVOCATION_ENFORCEMENT))
2974
3086
  ], ExtensionHost);
2975
3087
  export { ExtensionHost };
@@ -166,6 +166,8 @@ export declare function setupInstance(deps: LoadDeps, manifest: ExtensionManifes
166
166
  /** 已建好 ctx、setup 进行中时回调(宿主据此在 close() 时立即关闭它)。 */
167
167
  onCtx?: (ctx: KernelExtensionContext | undefined) => void;
168
168
  extensionDb?: ReturnType<typeof extensionDbPool>;
169
+ /** The instance runs in the kernel process (default); false for an isolated instance. */
170
+ inProcess?: boolean;
169
171
  }): Promise<ExtensionInstance>;
170
172
  /**
171
173
  * 加载一个插件实例:import → defineExtension → 有包内静态清单(`section`)时与 {@link staticManifestOf} 核对
@@ -311,6 +311,7 @@ export async function setupInstance(deps, manifest, input) {
311
311
  const ctx = createExtensionContext(deps.kernel, manifest, live, deps.objectStore, {
312
312
  sha256: input.sha256,
313
313
  ...(input.extensionDb && { db: input.extensionDb }),
314
+ ...(input.inProcess !== undefined && { inProcess: input.inProcess }),
314
315
  });
315
316
  input.onCtx?.(ctx);
316
317
  try {
@@ -7,4 +7,10 @@ export declare function isTrustedPublisherRevision(proof: unknown, expected: Off
7
7
  export declare function isolatedDeploymentSchema(input: unknown): z.ZodType;
8
8
  /** The kernel must never compile executable or unbounded schema features from a child. */
9
9
  export declare function assertIsolatedToolSchema(input: unknown): void;
10
+ /**
11
+ * Whether the section's deployment config fits the isolated tier: the same rule
12
+ * {@link assertIsolatedSection} applies (a declarative schema in the bounded subset, or no config
13
+ * fields at all). The execution decision reads it as `configSchemaIsolatable`.
14
+ */
15
+ export declare function deploymentConfigIsolatable(section: PluginExtensionSection): boolean;
10
16
  export declare function assertIsolatedSection(section: PluginExtensionSection): void;
@@ -181,6 +181,23 @@ export function assertIsolatedToolSchema(input) {
181
181
  throw new Error("Unsupported isolated extension tool schema");
182
182
  }
183
183
  }
184
+ /**
185
+ * Whether the section's deployment config fits the isolated tier: the same rule
186
+ * {@link assertIsolatedSection} applies (a declarative schema in the bounded subset, or no config
187
+ * fields at all). The execution decision reads it as `configSchemaIsolatable`.
188
+ */
189
+ export function deploymentConfigIsolatable(section) {
190
+ const schema = section.configSchemas?.deployment;
191
+ if (schema === undefined)
192
+ return section.manifest.config.deployment.length === 0;
193
+ try {
194
+ isolatedDeploymentSchema(schema);
195
+ return true;
196
+ }
197
+ catch {
198
+ return false;
199
+ }
200
+ }
184
201
  export function assertIsolatedSection(section) {
185
202
  const { manifest, client } = section;
186
203
  const permissions = manifest.permissions;
@@ -25,6 +25,11 @@ export declare class RegistrationLedger {
25
25
  get sealed(): boolean;
26
26
  /** 封账:此后的登记立即撤销并抛错。 */
27
27
  seal(): void;
28
+ /**
29
+ * Takes every entry of one kind off the ledger and disposes it (newest first): the handles held
30
+ * under a revoked permission (plan task 1.3e). A failure goes to `onError`; the rest continue.
31
+ */
32
+ disposeKind(kind: RegistrationKind, onError: (r: Registration, e: unknown) => void): Promise<void>;
28
33
  /** 封账并按登记的倒序逐项撤销;单项失败交给 `onError`,继续其余各项。 */
29
34
  disposeAll(onError: (r: Registration, e: unknown) => void): Promise<void>;
30
35
  }
@@ -34,6 +34,22 @@ export class RegistrationLedger {
34
34
  seal() {
35
35
  this.closed = true;
36
36
  }
37
+ /**
38
+ * Takes every entry of one kind off the ledger and disposes it (newest first): the handles held
39
+ * under a revoked permission (plan task 1.3e). A failure goes to `onError`; the rest continue.
40
+ */
41
+ async disposeKind(kind, onError) {
42
+ const taken = this.items.filter((r) => r.kind === kind).reverse();
43
+ this.items = this.items.filter((r) => r.kind !== kind);
44
+ for (const r of taken) {
45
+ try {
46
+ await r.dispose();
47
+ }
48
+ catch (e) {
49
+ onError(r, e);
50
+ }
51
+ }
52
+ }
37
53
  /** 封账并按登记的倒序逐项撤销;单项失败交给 `onError`,继续其余各项。 */
38
54
  async disposeAll(onError) {
39
55
  this.seal();
@@ -7,9 +7,9 @@ import type { ExtensionSource } from "./sources.js";
7
7
  export declare function reviewPermissionRows(set: PermissionSet): {
8
8
  rows: {
9
9
  key: string;
10
- family: "config.deployment" | "config.deployment.secret" | "execution.full-access" | "execution.provider.unsupported" | "host.no-isolation" | "migration.warnings" | "optional" | "optional.custodian" | "permissions.agents" | "permissions.bus" | "permissions.client" | "permissions.conversations" | "permissions.deviceaccess" | "permissions.deviceaccess.host" | "permissions.deviceaccess.loopbackports" | "permissions.deviceaccess.siteaccess" | "permissions.dialin" | "permissions.fullaccess.rawegress" | "permissions.hooks.observe" | "permissions.hooks.policy" | "permissions.hooks.sensitive" | "permissions.http" | "permissions.inbox" | "permissions.kv" | "permissions.lock" | "permissions.models" | "permissions.network" | "permissions.outbox" | "permissions.people" | "permissions.queue" | "permissions.secrets" | "permissions.storage" | "permissions.tools" | "permissions.triggers" | "provides" | "provides.standard" | "requires" | "requires.custodian" | "setup.check" | "table" | "ui.action" | "ui.component" | "ui.embed" | "ui.query" | "ui.view";
10
+ family: "config.deployment" | "config.deployment.secret" | "execution.config.unsupported" | "execution.full-access" | "execution.provider.unsupported" | "host.no-isolation" | "migration.warnings" | "optional" | "optional.custodian" | "permissions.agents" | "permissions.bus" | "permissions.client" | "permissions.conversations" | "permissions.deviceaccess" | "permissions.deviceaccess.host" | "permissions.deviceaccess.loopbackports" | "permissions.deviceaccess.siteaccess" | "permissions.dialin" | "permissions.fullaccess.rawegress" | "permissions.hooks.observe" | "permissions.hooks.policy" | "permissions.hooks.sensitive" | "permissions.http" | "permissions.inbox" | "permissions.kv" | "permissions.lock" | "permissions.models" | "permissions.network" | "permissions.outbox" | "permissions.people" | "permissions.queue" | "permissions.secrets" | "permissions.storage" | "permissions.tools" | "permissions.triggers" | "provides" | "provides.standard" | "requires" | "requires.custodian" | "setup.check" | "table" | "ui.action" | "ui.component" | "ui.embed" | "ui.query" | "ui.view";
11
11
  risk: "custodian" | "fullAccess" | "informational" | "sensitive" | "standard";
12
- reason: "Accepts connections from devices that use this protocol." | "Calls the model mapped to this declared purpose." | "Can deny the protected action at this mount." | "Can request a grant for a device loopback port." | "Can request approved actions on websites from the person's device." | "Contains migration statements that require review." | "Coordinates work using locks in the extension namespace." | "Creates a table in the extension database schema." | "Depends on a provider that handles a protected resource." | "Emits durable events of this type." | "Handles this named action for its extension UI." | "Handles this named query for its extension UI." | "Implements a kernel capability and sees the resource it serves." | "Implements this kernel capability." | "Makes network requests outside the kernel egress broker." | "Observes bounded metadata at this mount." | "Observes model or tool data at this mount." | "Orders startup after this extension point when present." | "Posts to the inbox of members of enabled orgs." | "Publishes and receives events in the extension namespace." | "Reads and writes keys in the extension namespace." | "Reads metadata for conversations about its own subjects." | "Reads or stores secrets in its approved namespace." | "Reads or writes objects in its scoped storage prefix." | "Reads the names and avatars of org members." | "Reads which agents a member can use." | "Receives requests and data for this route and audience." | "Receives this field from effective configuration." | "Renders this named component in the app." | "Renders this named view through the kernel." | "Requires this extension point at startup." | "Runs this named tool with its input and scoped call context." | "Runs this read-only setup check." | "Runs this service outside the device sandbox." | "Runs with the privileges of the approved execution realm." | "Runs without a host isolation supervisor." | "Schedules work in the extension namespace." | "Sends requests and data to this destination." | "Serves an embedded page for this view." | "Stages durable effects in the extension namespace." | "Supplies client code for the app." | "This provider contract does not yet have an isolated execution form." | "Uses this confidential configuration field." | "Uses this service on a person's device.";
12
+ reason: "Accepts connections from devices that use this protocol." | "Calls the model mapped to this declared purpose." | "Can deny the protected action at this mount." | "Can request a grant for a device loopback port." | "Can request approved actions on websites from the person's device." | "Contains migration statements that require review." | "Coordinates work using locks in the extension namespace." | "Creates a table in the extension database schema." | "Depends on a provider that handles a protected resource." | "Emits durable events of this type." | "Handles this named action for its extension UI." | "Handles this named query for its extension UI." | "Implements a kernel capability and sees the resource it serves." | "Implements this kernel capability." | "Makes network requests outside the kernel egress broker." | "Observes bounded metadata at this mount." | "Observes model or tool data at this mount." | "Orders startup after this extension point when present." | "Posts to the inbox of members of enabled orgs." | "Publishes and receives events in the extension namespace." | "Reads and writes keys in the extension namespace." | "Reads metadata for conversations about its own subjects." | "Reads or stores secrets in its approved namespace." | "Reads or writes objects in its scoped storage prefix." | "Reads the names and avatars of org members." | "Reads which agents a member can use." | "Receives requests and data for this route and audience." | "Receives this field from effective configuration." | "Renders this named component in the app." | "Renders this named view through the kernel." | "Requires this extension point at startup." | "Runs this named tool with its input and scoped call context." | "Runs this read-only setup check." | "Runs this service outside the device sandbox." | "Runs with the privileges of the approved execution realm." | "Runs without a host isolation supervisor." | "Schedules work in the extension namespace." | "Sends requests and data to this destination." | "Serves an embedded page for this view." | "Stages durable effects in the extension namespace." | "Supplies client code for the app." | "The deployment config schema is outside the isolated tier's declarative subset." | "This provider contract does not yet have an isolated execution form." | "Uses this confidential configuration field." | "Uses this service on a person's device.";
13
13
  purpose: import("@capybara-hq/plugin-sdk").PermissionPurpose | undefined;
14
14
  }[];
15
15
  errors: string[];
@@ -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
  * 监听函数同步调用,抛错被吞掉(不影响注册表与其他监听方)。返回取消订阅函数。