@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
@@ -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;
@@ -136,6 +138,15 @@ export class GrantEpoch {
136
138
  fresh() {
137
139
  return this.now() - this.readAt < this.options.maxAgeMs ? this.epoch : undefined;
138
140
  }
141
+ /**
142
+ * Seconds since the start of the last successful read, while polling; undefined before the
143
+ * first read or when stopped (the `grant_epoch_lag` gauge).
144
+ */
145
+ lagSeconds() {
146
+ if (!this.running || this.readAt === Number.NEGATIVE_INFINITY)
147
+ return undefined;
148
+ return Math.max(0, this.now() - this.readAt) / 1000;
149
+ }
139
150
  /** The fresh epoch, reading PostgreSQL first when needed; undefined when that read fails. */
140
151
  async ensureFresh() {
141
152
  return this.fresh() ?? (await this.refresh());
@@ -3,7 +3,7 @@ import type { Redis } from "ioredis";
3
3
  import type { core } from "zod";
4
4
  import type { KernelAppOptions } from "../app.js";
5
5
  import { TRIGGER_EVENTS_BACKEND } from "../automations/events/token.js";
6
- import { type KernelConfig } from "../config/schema.js";
6
+ import type { KernelConfig } from "../config/schema.js";
7
7
  import type { ExternalConversationsBackend } from "../conversations/external/external-conversations.service.js";
8
8
  import { EXTERNAL_CONVERSATIONS_BACKEND } from "../conversations/external/token.js";
9
9
  import type { BusSubscriber } from "../ctx/bus.js";
@@ -34,15 +34,18 @@ import type { UiActionHandler, UiQueryHandler, UiRender } from "../ui/registry.j
34
34
  import { ExtensionApprovals, type PendingExtension } from "./approvals.js";
35
35
  import { deploymentConfigHash } from "./config-hash.js";
36
36
  import { EffectiveConfigs } from "./effective-config.js";
37
+ import type { HostIsolation } from "./execution-realm.js";
37
38
  import { HookRegistry } from "./hooks.js";
38
39
  import type { InflightTracker } from "./inflight.js";
39
40
  import { type DesiredExtension, ExtensionInstalls } from "./installs.js";
40
41
  import { type ExtensionInstance } from "./instance.js";
41
42
  import { type IsolatedRevocation } from "./isolated/authorization.js";
42
- import { type ExtensionTier } from "./isolated/tier.js";
43
+ import type { ReplicaIsolationRecord } from "./isolated/status.js";
44
+ import { type ExtensionTier, type ShadowExecution } from "./isolated/tier.js";
43
45
  import { type PermissionSet } from "./permission-set.js";
44
46
  import { type ExtensionPointEntry, ExtensionRegistry } from "./registry.js";
45
47
  import { ExtensionRevisionApprovals } from "./revision-approvals.js";
48
+ import { type LeaseState } from "./revocation-leases.js";
46
49
  import { type ExtensionSource, ReplicaStatusStore } from "./sources.js";
47
50
  export { deploymentConfigHash };
48
51
  /**
@@ -105,6 +108,11 @@ export interface InstalledExtensionLoader {
105
108
  * 导入失败、模块清单与审阅过的静态清单不符、setup 失败、迁移失败。
106
109
  */
107
110
  export type InstallFailureReason = "sync_failed" | "sha_mismatch" | "import_failed" | "manifest_mismatch" | "setup_failed" | "migration_failed";
111
+ /**
112
+ * A pending status reason: the revision's grant could not be read (plan task 1.3b). It is retried
113
+ * at the next convergence; a serving revision keeps its tier instead.
114
+ */
115
+ export declare const GRANT_UNAVAILABLE = "grant_unavailable";
108
116
  /** One item of {@link ExtensionHost.declaredPlugins}. */
109
117
  export interface DeclaredExtensionInfo {
110
118
  name: string;
@@ -216,9 +224,21 @@ export declare class ExtensionHost {
216
224
  private readonly isolatedAuthority;
217
225
  private readonly isolatedLanes;
218
226
  private readonly isolatedGrants;
219
- /** This replica's view of the deployment grant epoch; polls only once an isolated grant was issued. */
227
+ /** The permission leases of this replica's instances (revocation, plan task 1.3e). */
228
+ private readonly revisionLeases;
229
+ /**
230
+ * This replica's view of the deployment grant epoch; polls once an isolated grant was issued or
231
+ * an instance with a package opened its permission lease.
232
+ */
220
233
  private readonly grantEpoch;
221
234
  private readonly epochReader;
235
+ /** Which orgs get their own label on the isolation metrics (the largest few). */
236
+ private readonly orgLabels;
237
+ /** This replica's isolated usage increments, flushed every 10 s once isolated work started. */
238
+ private readonly usageCounters;
239
+ private readonly usageFlusher;
240
+ private readonly unobserveEpochLag;
241
+ private capacityCache;
222
242
  private readonly executionTier;
223
243
  private policyExpected;
224
244
  /**
@@ -378,7 +398,9 @@ export declare class ExtensionHost {
378
398
  * Shadow revision approvals (plan task 1.2b): reported at start, never refusing. Absent in a
379
399
  * hand-built host, which then reports nothing.
380
400
  */
381
- revisionApprovals?: Pick<ExtensionRevisionApprovals, "startGate"> | undefined);
401
+ revisionApprovals?: Pick<ExtensionRevisionApprovals, "startGate"> | undefined,
402
+ /** Kernel tests only: enforce revocation before plan task 1.5a (`REVOCATION_ENFORCEMENT`). */
403
+ revocationEnforcement?: boolean);
382
404
  /** The startup config's `extensionConfig` (file / Nacos merged with env). */
383
405
  private get extensionConfig();
384
406
  /** `extensionPermissions.autoApprove` (development and trials only; see `planApprovals`). */
@@ -435,6 +457,47 @@ export declare class ExtensionHost {
435
457
  * `plugin host closed during load` at the next checkpoint.
436
458
  */
437
459
  load(plan: string[] | ExtensionLoadPlan): Promise<void>;
460
+ /**
461
+ * This replica's isolation supervisor as last observed (plan task 1.3b): `not_configured`
462
+ * without `extensionHost.isolation`; otherwise `available` only after the Engine answered
463
+ * ({@link probeIsolation}), `failing` when it did not. Configuration alone is never readiness.
464
+ */
465
+ private isolationState;
466
+ hostIsolation(): HostIsolation;
467
+ /**
468
+ * Probes the isolation supervisor with the same read-only Engine and image checks a sandbox start
469
+ * runs (Linux, cgroup v2, the mandatory security options, the local runtime image): the positive
470
+ * readiness signal host-reason retirement waits for. Called at load and on each periodic
471
+ * convergence, so the reported state may lag a failure by one period (reporting only: a sandbox
472
+ * start runs the checks again and fails closed).
473
+ */
474
+ probeIsolation(): Promise<HostIsolation>;
475
+ /** The last probe with its named checks (plan task 1.4j), undefined before any or unconfigured. */
476
+ private lastProbe;
477
+ /**
478
+ * What this replica records for the isolation status projection (`ReplicaIsolationStore`): its
479
+ * last probe and the shadow placements of its last convergence.
480
+ */
481
+ isolationRecord(): ReplicaIsolationRecord;
482
+ /**
483
+ * The newest grant of each install's revision, or undefined when the read failed: a revision
484
+ * already serving then keeps its admission (a read error is never a refusal), and any other
485
+ * revision is admitted as without a grant (today's admission).
486
+ */
487
+ private grantSurfaces;
488
+ /** The last shadow execution report logged by this replica (log de-duplication, not state). */
489
+ private lastExecutionReport;
490
+ /** The shadow execution decisions of the last convergence on this replica (for the inventory). */
491
+ private executions;
492
+ /** This replica's shadow execution decisions of the installs it last converged. */
493
+ shadowExecutions(): ShadowExecution[];
494
+ /**
495
+ * Shadow mode (plan task 1.3b, rollout fence until 1.5a): where each admitted install would run
496
+ * under the execution-realm decision and whether its grant covers the forcing keys, including
497
+ * the kernel's `host.no-isolation` on a host without isolation. Logged when it changes; never
498
+ * refuses or moves a revision: the legacy tier governs.
499
+ */
500
+ private reportShadowExecution;
438
501
  /** The last shadow report logged by this replica (a log de-duplication, not state). */
439
502
  private lastShadowReport;
440
503
  /**
@@ -471,6 +534,22 @@ export declare class ExtensionHost {
471
534
  /** 把一份已校验部署配置里的密钥值登记到日志打码。 */
472
535
  private reportSecrets;
473
536
  private tierOf;
537
+ /**
538
+ * What the isolated admission of an instance start takes from its grant. In shadow mode the
539
+ * activation's decision (a reload reuses it; a grant change is reported, not enforced); once
540
+ * enforcing (task 1.5a) the grant is read again, so a reload follows a revoked browser realm.
541
+ */
542
+ private isolatedGrantFor;
543
+ /** The tier this replica serves the exact revision in, or undefined when it does not serve it. */
544
+ private servingTier;
545
+ /**
546
+ * The tier after a revocation (plan task 1.3e; enforced from task 1.5a, until then the leases
547
+ * only report it). A revision whose whole grant is revoked waits for a new review. A trusted
548
+ * (in-process) revision whose grant no longer serves server full access runs isolated when the
549
+ * remaining grant fits the sandbox and the package has an isolated form, and otherwise waits for
550
+ * a new review ({@link RevocationPendingError}: reported pending, not failed).
551
+ */
552
+ private afterRevocation;
474
553
  /**
475
554
  * Reconciles enabled installs from PostgreSQL at startup and during convergence. It removes
476
555
  * withdrawn revisions, verifies the tier, and prepares replacements in dependency order.
@@ -565,6 +644,13 @@ export declare class ExtensionHost {
565
644
  */
566
645
  activatePending(): Promise<string[]>;
567
646
  revokeIsolatedInvocations(scope: IsolatedRevocation): void;
647
+ /**
648
+ * A committed grant revocation (the local fence after the commit, or a sibling's hint): this
649
+ * replica's leases of the plugin revalidate now (plan task 1.3e).
650
+ */
651
+ fenceRevocation(plugin: string): Promise<void>;
652
+ /** The revocation decisions this replica's leases computed for a plugin's instances. */
653
+ revocationDecisions(plugin: string): LeaseState[];
568
654
  refreshIsolatedOrgIntent(orgId?: string): Promise<void>;
569
655
  revalidateIsolatedInvocations(): Promise<void>;
570
656
  /**
@@ -782,4 +868,10 @@ export declare class ExtensionHost {
782
868
  close(opts?: {
783
869
  lifecycleWaitMs?: number;
784
870
  }): Promise<void>;
871
+ /**
872
+ * The resolved `extensionHost.capacity` (preset plus explicit fields), read at every isolated
873
+ * admission and lane start so hot fields apply at once. Invalid fields fell back to the preset
874
+ * when the config was parsed; the config service logs them.
875
+ */
876
+ private capacity;
785
877
  }