@capybara-hq/kernel 0.1.0-rc.136 → 0.1.0-rc.137

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 (158) hide show
  1. package/dist/admin/audit-log.service.d.ts +96 -12
  2. package/dist/admin/audit-log.service.js +508 -44
  3. package/dist/admin/audit-targets.d.ts +17 -0
  4. package/dist/admin/audit-targets.js +84 -0
  5. package/dist/admin/audit.controller.d.ts +12 -9
  6. package/dist/admin/audit.controller.js +29 -8
  7. package/dist/admin/audit.schemas.d.ts +20 -4
  8. package/dist/admin/audit.schemas.js +42 -17
  9. package/dist/agents/templates.js +3 -10
  10. package/dist/app.d.ts +3 -1
  11. package/dist/app.js +1 -0
  12. package/dist/automations/automations.service.js +4 -5
  13. package/dist/catalog/catalog-content.d.ts +1 -1
  14. package/dist/catalog/catalog-content.js +17 -22
  15. package/dist/catalog/catalog-items.d.ts +5 -10
  16. package/dist/catalog/catalog-items.js +27 -51
  17. package/dist/catalog/catalog-scope.service.d.ts +4 -2
  18. package/dist/catalog/catalog-scope.service.js +105 -141
  19. package/dist/catalog/catalog.module.js +2 -0
  20. package/dist/catalog/catalog.service.d.ts +3 -3
  21. package/dist/catalog/catalog.service.js +33 -8
  22. package/dist/catalog/cli.js +17 -0
  23. package/dist/catalog/component-promotion.js +8 -4
  24. package/dist/catalog/component-scope.service.d.ts +3 -1
  25. package/dist/catalog/component-scope.service.js +101 -140
  26. package/dist/catalog/component-state.d.ts +10 -8
  27. package/dist/catalog/component-state.js +42 -30
  28. package/dist/catalog/dependency-edges.d.ts +25 -0
  29. package/dist/catalog/dependency-edges.js +125 -0
  30. package/dist/catalog/install-status.d.ts +2 -3
  31. package/dist/catalog/install-status.js +2 -3
  32. package/dist/catalog/org-catalog.service.d.ts +3 -1
  33. package/dist/catalog/org-catalog.service.js +33 -94
  34. package/dist/catalog/org-intent.d.ts +43 -0
  35. package/dist/catalog/org-intent.js +184 -0
  36. package/dist/catalog/owned-items.d.ts +1 -1
  37. package/dist/catalog/owned-items.js +9 -29
  38. package/dist/catalog/ownership.d.ts +2 -3
  39. package/dist/catalog/ownership.js +10 -28
  40. package/dist/catalog/platform-components.d.ts +3 -1
  41. package/dist/catalog/platform-components.js +9 -1
  42. package/dist/catalog/plugin-import.js +12 -16
  43. package/dist/catalog/plugin-install.d.ts +3 -4
  44. package/dist/catalog/plugin-install.js +25 -49
  45. package/dist/catalog/plugin-upgrade.d.ts +2 -2
  46. package/dist/catalog/plugin-upgrade.js +18 -34
  47. package/dist/catalog/request-rules.js +20 -8
  48. package/dist/catalog/scope-orgs.js +2 -7
  49. package/dist/catalog/scope-state.d.ts +6 -6
  50. package/dist/catalog/scope-state.js +24 -43
  51. package/dist/catalog/scope-sync.d.ts +0 -2
  52. package/dist/catalog/scope-sync.js +11 -39
  53. package/dist/catalog/scope-writer.d.ts +78 -0
  54. package/dist/catalog/scope-writer.js +181 -0
  55. package/dist/catalog/unshare.js +8 -41
  56. package/dist/channels/connections.service.js +6 -6
  57. package/dist/channels/supervisor.js +3 -7
  58. package/dist/client/client-access.service.js +2 -12
  59. package/dist/config/schema.d.ts +6 -0
  60. package/dist/config/schema.js +29 -1
  61. package/dist/ctx/create-ctx.d.ts +2 -2
  62. package/dist/ctx/create-ctx.js +2 -60
  63. package/dist/ctx/guard-db.d.ts +6 -0
  64. package/dist/ctx/guard-db.js +55 -0
  65. package/dist/db/extension-handoff-schema.d.ts +1 -1
  66. package/dist/db/extension-handoff-schema.js +48 -10
  67. package/dist/db/extension-schema-transfer.js +5 -2
  68. package/dist/db/kernel-schema.d.ts +11 -1
  69. package/dist/device-access/host-services.d.ts +2 -2
  70. package/dist/device-access/host-services.js +5 -6
  71. package/dist/erasure/org-catalog.js +2 -2
  72. package/dist/erasure/org-rules.js +5 -0
  73. package/dist/extensions/admin-ops.d.ts +9 -5
  74. package/dist/extensions/admin-ops.js +52 -8
  75. package/dist/extensions/admin-view.js +1 -4
  76. package/dist/extensions/bootstrap.js +4 -1
  77. package/dist/extensions/cli.js +1 -0
  78. package/dist/extensions/effective-config.js +1 -4
  79. package/dist/extensions/enabled.d.ts +23 -29
  80. package/dist/extensions/enabled.js +141 -62
  81. package/dist/extensions/host.d.ts +64 -45
  82. package/dist/extensions/host.js +443 -128
  83. package/dist/extensions/installs.d.ts +9 -0
  84. package/dist/extensions/installs.js +23 -0
  85. package/dist/extensions/isolated/admission.d.ts +10 -0
  86. package/dist/extensions/isolated/admission.js +206 -0
  87. package/dist/extensions/isolated/authorization.d.ts +37 -0
  88. package/dist/extensions/isolated/authorization.js +146 -0
  89. package/dist/extensions/isolated/broker.d.ts +15 -0
  90. package/dist/extensions/isolated/broker.js +452 -0
  91. package/dist/extensions/isolated/child-protocol.d.ts +84 -0
  92. package/dist/extensions/isolated/child-protocol.js +21 -0
  93. package/dist/extensions/isolated/child-registration.d.ts +22 -0
  94. package/dist/extensions/isolated/child-registration.js +152 -0
  95. package/dist/extensions/isolated/child-session.d.ts +6 -0
  96. package/dist/extensions/isolated/child-session.js +343 -0
  97. package/dist/extensions/isolated/child-streams.d.ts +4 -0
  98. package/dist/extensions/isolated/child-streams.js +142 -0
  99. package/dist/extensions/isolated/child.d.ts +1 -0
  100. package/dist/extensions/isolated/child.js +10 -0
  101. package/dist/extensions/isolated/configured-package.d.ts +15 -0
  102. package/dist/extensions/isolated/configured-package.js +73 -0
  103. package/dist/extensions/isolated/lanes.d.ts +100 -0
  104. package/dist/extensions/isolated/lanes.js +699 -0
  105. package/dist/extensions/isolated/postgres-gate.d.ts +14 -0
  106. package/dist/extensions/isolated/postgres-gate.js +255 -0
  107. package/dist/extensions/isolated/revision.d.ts +32 -0
  108. package/dist/extensions/isolated/revision.js +358 -0
  109. package/dist/extensions/isolated/rpc-frame.d.ts +50 -0
  110. package/dist/extensions/isolated/rpc-frame.js +193 -0
  111. package/dist/extensions/isolated/rpc.d.ts +66 -0
  112. package/dist/extensions/isolated/rpc.js +314 -0
  113. package/dist/extensions/isolated/sandbox.d.ts +35 -0
  114. package/dist/extensions/isolated/sandbox.js +372 -0
  115. package/dist/extensions/isolated/tier.d.ts +6 -0
  116. package/dist/extensions/isolated/tier.js +45 -0
  117. package/dist/extensions/ledger.d.ts +1 -1
  118. package/dist/extensions/lifecycle-topics.d.ts +1 -0
  119. package/dist/extensions/lifecycle-topics.js +1 -0
  120. package/dist/extensions/lifecycle.d.ts +3 -1
  121. package/dist/extensions/lifecycle.js +32 -5
  122. package/dist/extensions/locks.d.ts +2 -0
  123. package/dist/extensions/locks.js +7 -0
  124. package/dist/extensions/org-config.d.ts +17 -27
  125. package/dist/extensions/org-config.js +114 -129
  126. package/dist/extensions/plugin-guides.d.ts +5 -10
  127. package/dist/extensions/plugin-guides.js +18 -37
  128. package/dist/extensions/plugin-icons.d.ts +3 -21
  129. package/dist/extensions/plugin-icons.js +9 -44
  130. package/dist/extensions/plugin-items.d.ts +10 -30
  131. package/dist/extensions/plugin-items.js +32 -73
  132. package/dist/extensions/source-intent.d.ts +14 -0
  133. package/dist/extensions/source-intent.js +77 -0
  134. package/dist/index.d.ts +2 -1
  135. package/dist/index.js +2 -1
  136. package/dist/infra/database/database.module.js +6 -1
  137. package/dist/infra/database/kernel-db.d.ts +3 -1
  138. package/dist/infra/database/kernel-db.js +4 -0
  139. package/dist/infra/paging/paged-read.d.ts +56 -0
  140. package/dist/infra/paging/paged-read.js +78 -0
  141. package/dist/kernel.d.ts +3 -2
  142. package/dist/kernel.js +21 -2
  143. package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
  144. package/dist/lifecycle/kernel-lifecycle.js +22 -12
  145. package/dist/lifecycle/tokens.d.ts +8 -0
  146. package/dist/lifecycle/tokens.js +2 -0
  147. package/dist/orgs/directory-sync.js +1 -4
  148. package/dist/platform/ops/admin.ops.js +14 -3
  149. package/dist/platform/ops/orgs.ops.js +13 -3
  150. package/dist/setup/setup-checks.service.js +3 -2
  151. package/dist/skills/usable.js +41 -30
  152. package/dist/themes/theme-state.js +3 -3
  153. package/dist/tools/registry.d.ts +1 -1
  154. package/dist/tools/registry.js +1 -1
  155. package/package.json +2 -2
  156. package/src/migrations/0228_extension_org_switches.sql +56 -0
  157. package/src/migrations/0229_catalog_dependency_edges.sql +17 -0
  158. package/src/migrations/0230_audit_filter_idx.sql +18 -0
@@ -1,78 +1,157 @@
1
1
  import { sql } from "kysely";
2
- /**
3
- * Which extensions an organization has enabled. Two sources, and every reader goes through these
4
- * helpers so none of them misses one:
5
- * - `extension_org_configs.enabled` (the org's own switch);
6
- * - every always-on extension ({@link alwaysOnExtensionsQuery}): enabled in every org, existing and
7
- * future, without an org config row, whatever such a row says. That is a required bootstrap
8
- * plugin (`extension_installs.required`, package ecosystem spec §7) and an extension shipped in a
9
- * builtin platform plugin (a live `catalog_items` row with `builtin`, recorded on its install or in
10
- * `extension_catalog_sources`; a `builtin: true` bootstrap entry is builtin without being
11
- * required). A builtin plugin is on in every org and its org switch is locked (`wantedOn`,
12
- * `itemLocked`), so its extension must be on too: the scope sync leaves builtin items alone.
13
- * Neither checks that the extension is loaded on this replica or enabled on the deployment; callers
14
- * that need that check it themselves, as before. Plain SQL read on every call (no cache), so every
15
- * replica sees a change at once. `db` may be a transaction.
16
- */
2
+ import { orgUsable } from "../catalog/org-intent.js";
3
+ import { extensionSourcesQuery } from "./plugin-items.js";
17
4
  /**
18
5
  * The names of the always-on extensions (a subquery with one column, `plugin`): required bootstrap
19
6
  * plugins and the extensions of live builtin platform plugins (see the file header).
20
7
  */
21
- export function alwaysOnExtensionsQuery(db) {
22
- return db
8
+ export function alwaysOnExtensionsQuery(db, plugin) {
9
+ const required = db
23
10
  .selectFrom("extension_installs as ri")
24
11
  .select("ri.name as plugin")
25
- .where("ri.required", "=", true)
26
- .union(db
27
- .selectFrom("extension_installs as ei")
28
- .innerJoin("catalog_items as ci", "ci.id", "ei.catalog_item_id")
29
- .select("ei.name as plugin")
30
- .where("ci.builtin", "=", true)
31
- .where("ci.disabled", "=", false)
32
- .where("ci.deleted_at", "is", null)
33
- .where("ci.owner_org_id", "is", null))
34
- .union(db
35
- .selectFrom("extension_catalog_sources as cs")
36
- .innerJoin("catalog_items as si", "si.id", "cs.item_id")
37
- .select("cs.plugin as plugin")
38
- .where("si.builtin", "=", true)
39
- .where("si.disabled", "=", false)
40
- .where("si.deleted_at", "is", null)
41
- .where("si.owner_org_id", "is", null));
12
+ .where("ri.required", "=", true);
13
+ const builtin = db
14
+ .selectFrom(extensionSourcesQuery(db, plugin).as("source"))
15
+ .innerJoin("catalog_items as item", "item.id", "source.item_id")
16
+ .select("source.plugin")
17
+ .where("item.builtin", "=", true)
18
+ .where("item.disabled", "=", false)
19
+ .where("item.deleted_at", "is", null)
20
+ .where("item.owner_org_id", "is", null);
21
+ return (plugin === undefined ? required : required.where("ri.name", "=", plugin)).union(builtin);
42
22
  }
43
- /** The names of the extensions enabled in `orgId` (a subquery with one column, `plugin`). */
44
- export function enabledExtensionsQuery(db, orgId) {
23
+ /** The stored choice for this extension. An absent choice follows its source or default. */
24
+ export function extensionSwitch(db, orgId, plugin) {
45
25
  return db
46
- .selectFrom("extension_org_configs as eoc")
47
- .select("eoc.plugin as plugin")
48
- .where("eoc.org_id", "=", orgId)
49
- .where("eoc.enabled", "=", true)
50
- .union(db.selectFrom(alwaysOnExtensionsQuery(db).as("ao")).select("ao.plugin as plugin"));
26
+ .selectFrom("component_org_switches as extension_switch")
27
+ .select("extension_switch.enabled")
28
+ .where("extension_switch.kind", "=", "extension")
29
+ .where("extension_switch.org_id", "=", orgId)
30
+ .where("extension_switch.component_id", "=", plugin);
51
31
  }
52
- /**
53
- * Every (org, extension) pair that is enabled, for queries that join it (columns `org_id`,
54
- * `plugin`): `.innerJoin(enabledExtensionsByOrg(db).as("en"), (j) => j.onRef("en.org_id", …)…)`.
55
- * Soft-deleted orgs are included, as their org config rows are; callers filter `orgs.deleted_at`.
56
- */
57
- // org-filter: every (org, extension) pair by design; callers join it on their own org column
58
- export function enabledExtensionsByOrg(db) {
32
+ /** The same intent predicate for point, org-list and membership-correlated reads. */
33
+ export function extensionIntent(db, orgId, plugin, proposedChoice) {
34
+ const org = db
35
+ .selectFrom("orgs")
36
+ .select("id")
37
+ .where("id", "=", orgId)
38
+ .where("deleted_at", "is", null);
39
+ const required = db
40
+ .selectFrom("extension_installs")
41
+ .select("name")
42
+ .where("name", "=", plugin)
43
+ .where("required", "=", true);
44
+ const sources = db
45
+ .selectFrom(extensionSourcesQuery(db, plugin).as("source"))
46
+ .crossJoinLateral((eb) => db
47
+ .selectFrom("catalog_items")
48
+ .select([
49
+ "id",
50
+ "deleted_at",
51
+ "disabled",
52
+ "owner_org_id",
53
+ "shareable",
54
+ "scope",
55
+ "builtin",
56
+ "latest_version",
57
+ ])
58
+ .where("id", "=", eb.ref("source.item_id"))
59
+ .limit(1)
60
+ .as("source_item"))
61
+ .leftJoin("catalog_item_scope_orgs as source_org", (join) => join.onRef("source_org.item_id", "=", "source.item_id").on("source_org.org_id", "=", orgId))
62
+ .select((eb) => [
63
+ eb("source_item.deleted_at", "is", null).as("live"),
64
+ eb
65
+ .and([
66
+ eb("source_item.builtin", "=", true),
67
+ eb("source_item.disabled", "=", false),
68
+ eb("source_item.owner_org_id", "is", null),
69
+ ])
70
+ .as("builtin"),
71
+ eb
72
+ .and([
73
+ eb("source_item.disabled", "=", false),
74
+ eb.or([
75
+ eb("source_item.owner_org_id", "is", null),
76
+ eb("source_item.owner_org_id", "=", orgId),
77
+ eb.and([
78
+ eb("source_item.shareable", "=", true),
79
+ eb.exists(eb
80
+ .selectFrom("catalog_item_versions as published")
81
+ .select("published.item_id")
82
+ .whereRef("published.item_id", "=", "source_item.id")
83
+ .whereRef("published.version", "=", "source_item.latest_version")
84
+ .where("published.applied_at", "is not", null)),
85
+ ]),
86
+ ]),
87
+ eb.or([eb("source_item.scope", "!=", "named"), eb("source_org.item_id", "is not", null)]),
88
+ ])
89
+ .as("authorized"),
90
+ orgUsable(db, orgId, eb.ref("source.item_id")).as("follows"),
91
+ ]);
92
+ const choice = proposedChoice === undefined
93
+ ? extensionSwitch(db, orgId, plugin)
94
+ : db.selectNoFrom(sql `${proposedChoice}::boolean`.as("enabled"));
95
+ return sql `
96
+ exists (${org}) AND (
97
+ exists (${required})
98
+ OR (
99
+ SELECT CASE
100
+ WHEN summary.builtin THEN true
101
+ WHEN summary.all_sources = 0 THEN choice.enabled IS TRUE
102
+ WHEN summary.live_sources = 1 THEN summary.follows AND choice.enabled IS NOT FALSE
103
+ WHEN summary.live_sources > 1 THEN summary.authorized AND choice.enabled IS TRUE
104
+ ELSE false
105
+ END
106
+ FROM (
107
+ SELECT count(*) AS all_sources,
108
+ count(*) FILTER (WHERE live) AS live_sources,
109
+ bool_or(builtin) FILTER (WHERE live) AS builtin,
110
+ bool_or(follows) FILTER (WHERE live) AS follows,
111
+ bool_and(authorized) FILTER (WHERE live) AS authorized
112
+ FROM (${sources}) AS source_intent
113
+ ) AS summary
114
+ LEFT JOIN (${choice}) AS choice ON true
115
+ )
116
+ )`;
117
+ }
118
+ /** The names enabled in an org, optionally narrowed to one extension in the outer query. */
119
+ export function enabledExtensionsQuery(db, orgId, plugin) {
120
+ if (plugin !== undefined) {
121
+ return db
122
+ .selectNoFrom(sql `${plugin}`.as("plugin"))
123
+ .where(extensionIntent(db, orgId, plugin));
124
+ }
125
+ const installed = db.selectFrom("extension_installs").select("name as plugin");
126
+ const sources = db.selectFrom("extension_catalog_sources").select("plugin");
127
+ const switches = db
128
+ .selectFrom("component_org_switches")
129
+ .select("component_id as plugin")
130
+ .where("kind", "=", "extension")
131
+ .where("org_id", "=", orgId);
132
+ return db
133
+ .selectFrom(installed.union(sources).union(switches).as("candidate"))
134
+ .select("candidate.plugin")
135
+ .where((eb) => extensionIntent(db, orgId, eb.ref("candidate.plugin")));
136
+ }
137
+ /** Test only the requested extension names when a deployment-wide reader needs org pairs. */
138
+ export function enabledExtensionsByOrg(db, plugins) {
139
+ const requested = db
140
+ .selectNoFrom(sql `unnest(${[...new Set(plugins)]}::text[])`.as("plugin"))
141
+ .as("requested");
59
142
  return db
60
- .selectFrom("extension_org_configs as eoc")
61
- .select(["eoc.org_id as org_id", "eoc.plugin as plugin"])
62
- .where("eoc.enabled", "=", true)
63
- .union(db
64
- .selectFrom("orgs as ro")
65
- .innerJoin(alwaysOnExtensionsQuery(db).as("ao"), (j) => j.onTrue())
66
- .select(["ro.id as org_id", "ao.plugin as plugin"]));
143
+ .selectFrom("orgs as enabled_org")
144
+ .crossJoin(requested)
145
+ .select(["enabled_org.id as org_id", "requested.plugin"])
146
+ .where("enabled_org.deleted_at", "is", null)
147
+ .where(({ exists, ref }) => exists(enabledExtensionsQuery(db, ref("enabled_org.id"), ref("requested.plugin"))));
67
148
  }
68
- /** Whether `plugin` is enabled in `orgId` (see the file header). */
149
+ /** Whether the extension has committed intent in the org. Execution checks remain at the caller. */
69
150
  export async function isExtensionEnabled(db, orgId, plugin) {
70
- const row = await db
71
- .selectFrom(enabledExtensionsQuery(db, orgId).as("en"))
72
- .select(sql `1`.as("one"))
73
- .where("en.plugin", "=", plugin)
74
- .executeTakeFirst();
75
- return row !== undefined;
151
+ const { enabled } = await db
152
+ .selectNoFrom(extensionIntent(db, orgId, plugin).as("enabled"))
153
+ .executeTakeFirstOrThrow();
154
+ return enabled;
76
155
  }
77
156
  /**
78
157
  * The names of the required bootstrap plugins (installed with `required`): the ones that refuse
@@ -9,6 +9,7 @@ import { EXTERNAL_CONVERSATIONS_BACKEND } from "../conversations/external/token.
9
9
  import type { BusSubscriber } from "../ctx/bus.js";
10
10
  import { type DeviceAccessBackend, type InboxBackend, type PluginReadsBackend, type Route, type TriggersBackend } from "../ctx/create-ctx.js";
11
11
  import { ExtensionEffects } from "../ctx/durable-effects.service.js";
12
+ import { ExtensionEffectKeys } from "../ctx/durable-keys.js";
12
13
  import { type ExtensionNetSeams } from "../ctx/net.js";
13
14
  import type { Keyring } from "../ctx/secrets.js";
14
15
  import { type ExtensionDbIdentity } from "../db/extension-db.js";
@@ -20,6 +21,7 @@ import { INBOX_ITEMS_BACKEND } from "../inbox/token.js";
20
21
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
21
22
  import { KernelDb } from "../infra/database/kernel-db.js";
22
23
  import { LockService } from "../infra/lock/lock.service.js";
24
+ import { KERNEL_FIXTURE_TRUST, type KernelFixtureTrust } from "../lifecycle/tokens.js";
23
25
  import type { KernelLogger } from "../log.js";
24
26
  import { ModelEmbeddings } from "../models/embeddings.js";
25
27
  import { ModelImages } from "../models/images.js";
@@ -36,6 +38,8 @@ import { HookRegistry } from "./hooks.js";
36
38
  import type { InflightTracker } from "./inflight.js";
37
39
  import { type DesiredExtension, ExtensionInstalls } from "./installs.js";
38
40
  import { type ExtensionInstance } from "./instance.js";
41
+ import { type IsolatedRevocation } from "./isolated/authorization.js";
42
+ import type { ExtensionTier } from "./isolated/tier.js";
39
43
  import { type PermissionSet } from "./permission-set.js";
40
44
  import { type ExtensionPointEntry, ExtensionRegistry } from "./registry.js";
41
45
  import { type ExtensionSource, ReplicaStatusStore } from "./sources.js";
@@ -60,6 +64,7 @@ export interface LoadedUiContribution {
60
64
  export type { ExtensionPointEntry } from "./registry.js";
61
65
  /** One item of {@link ExtensionHost.inspect}. */
62
66
  export interface InspectedExtension {
67
+ isolated?: true;
63
68
  /** Always `config`: the startup config `extensions` list. */
64
69
  source: "config";
65
70
  manifest: ExtensionManifest;
@@ -84,6 +89,7 @@ export declare function assertSecretsReachable(manifest: ExtensionManifest): voi
84
89
  * extension must be ready).
85
90
  */
86
91
  export interface InstalledExtensionLoader {
92
+ tier?(d: DesiredExtension, verifyBytes: boolean): Promise<ExtensionTier>;
87
93
  desired(): Promise<DesiredExtension[]>;
88
94
  sync(d: DesiredExtension): Promise<string>;
89
95
  /**
@@ -118,7 +124,7 @@ export interface ExtensionLoadPlan {
118
124
  /** 安装记录。 */
119
125
  installs?: InstalledExtensionLoader;
120
126
  }
121
- /** 插件宿主:解析、校验配置、迁移、setup,并登记插件提供的能力与路由。 */
127
+ /** Resolves extensions and their configuration, runs migrations and registers capabilities. */
122
128
  export declare class ExtensionHost {
123
129
  /** The process's extension registry (one provider, shared with other domains). */
124
130
  private readonly registry;
@@ -134,11 +140,27 @@ export declare class ExtensionHost {
134
140
  private readonly status;
135
141
  private readonly config;
136
142
  private readonly log;
143
+ private readonly options;
137
144
  /**
138
145
  * Each hook call's effective config for its organization, and the providers excluded from an
139
146
  * org's point resolution (layering spec A §6).
140
147
  */
141
148
  private readonly effective;
149
+ /** `ctx.net`: the internal endpoints each org's extension requests may reach (read per call). */
150
+ private readonly allowances;
151
+ /**
152
+ * Finds `DeviceAccessService` (`ctx.deviceAccess`, {@link DEVICE_ACCESS_BACKEND}) at the time
153
+ * of use: its module imports the sandbox, devices and tools modules, which import this one (a
154
+ * module cycle otherwise).
155
+ * Absent (a hand-built host) or not found (the CLI): `ctx.deviceAccess` calls are refused.
156
+ * `TriggerEventsService` (`ctx.triggers`, {@link TRIGGER_EVENTS_BACKEND}) and
157
+ * `InboxItemsService` (`ctx.inbox`, {@link INBOX_ITEMS_BACKEND}) and `PluginReadsService`
158
+ * (`ctx.agents`, `ctx.conversations`, `ctx.people`, {@link PLUGIN_READS_BACKEND}) and
159
+ * `ExternalConversationsService` (`ctx.conversations`' external methods,
160
+ * {@link EXTERNAL_CONVERSATIONS_BACKEND}) and
161
+ * `ServiceEvents` (`ctx.devices.serviceEvent`, {@link SERVICE_EVENTS_BACKEND}) likewise.
162
+ */
163
+ private readonly modules?;
142
164
  private readonly dbIdentity;
143
165
  /**
144
166
  * Only resolves extensions and runs migrations in dependency order: no deployment config check, no
@@ -150,12 +172,15 @@ export declare class ExtensionHost {
150
172
  * kernel migrations to have run (reads `extension_permission_snapshots`). With `autoApprove` all are
151
173
  * migrated and no snapshot is written (`load()` writes snapshots).
152
174
  */
153
- static migrateOnly(specifiers: string[], opts: {
175
+ static migrateOnly(specifiers: string[], opts: KernelFixtureTrust & {
154
176
  dbUrl: string;
155
177
  extensionIdentity?: ExtensionDbIdentity;
156
178
  extensionProvisioning?: KernelConfig["db"];
157
179
  resolveFrom?: string;
158
180
  connectTimeoutMs?: number;
181
+ migrationTimeoutMs?: number;
182
+ packageCacheDir?: string;
183
+ maxPackageBytes?: number;
159
184
  autoApprove?: boolean;
160
185
  onPending?: (pending: PendingExtension[]) => void;
161
186
  }): Promise<{
@@ -163,26 +188,29 @@ export declare class ExtensionHost {
163
188
  schema: string;
164
189
  applied: string[];
165
190
  }[]>;
166
- /**
167
- * The names of the config-declared extensions (`specifiers`, the startup config `extensions`
168
- * list): imports their modules only (the same modules `load()` imports next, from Node's module
169
- * cache). The kernel passes them to the bootstrap step before loading, so a bootstrap entry of
170
- * the same name is kept and gets no install record (config wins, C15).
171
- */
172
- static declaredNames(specifiers: string[], opts?: {
191
+ /** Reads configured package identities for bootstrap without starting extension code. */
192
+ static declaredNames(specifiers: string[], opts?: KernelFixtureTrust & {
173
193
  resolveFrom?: string;
194
+ maxPackageBytes?: number;
174
195
  }): Promise<Set<string>>;
175
196
  /**
176
197
  * 只导入、校验并按依赖排序插件,计算各自的权限集合;不迁移、不调用 setup、不连数据库与 Redis
177
198
  * (供 `capybara extensions review / approve`)。返回依赖拓扑序。
178
199
  */
179
- static inspect(specifiers: string[], opts?: {
200
+ static inspect(specifiers: string[], opts?: KernelFixtureTrust & {
180
201
  resolveFrom?: string;
202
+ maxPackageBytes?: number;
181
203
  }): Promise<InspectedExtension[]>;
182
204
  /**
183
205
  * M-1: plugin → mount points where deployment state expects `policy` hooks. A per-replica copy of PG
184
206
  * deployment state (like the registry), rebuilt on every load / converge, never written elsewhere.
185
207
  */
208
+ private readonly declaredIsolation;
209
+ private readonly quota;
210
+ private readonly isolatedAuthority;
211
+ private readonly isolatedLanes;
212
+ private readonly isolatedGrants;
213
+ private readonly executionTier;
186
214
  private policyExpected;
187
215
  /**
188
216
  * Runs the hooks of this process's active plugin instances (resolved from the registry on every
@@ -281,7 +309,7 @@ export declare class ExtensionHost {
281
309
  /** This replica's load status table (`extension_replica_status`): every load result writes a row. */
282
310
  status: ReplicaStatusStore, config: KernelConfigService, kdb: KernelDb, redis: Redis, busSubscriber: BusSubscriber, keyring: Keyring, embedTokens: EmbedTokens,
283
311
  /** `ctx.ui.verifyEmbedToken`: the live check of a share-scoped token (file sharing spec §7). */
284
- shares: ShareLiveness, locks: LockService, log: KernelLogger, options: Pick<KernelAppOptions, "resolveFrom">,
312
+ shares: ShareLiveness, locks: LockService, log: KernelLogger, options: Pick<KernelAppOptions, "resolveFrom" | typeof KERNEL_FIXTURE_TRUST>,
285
313
  /**
286
314
  * Each hook call's effective config for its organization, and the providers excluded from an
287
315
  * org's point resolution (layering spec A §6).
@@ -319,6 +347,9 @@ export declare class ExtensionHost {
319
347
  get(token: typeof ExtensionEffects, opts: {
320
348
  strict: false;
321
349
  }): ExtensionEffects;
350
+ get(token: typeof ExtensionEffectKeys, opts: {
351
+ strict: false;
352
+ }): ExtensionEffectKeys;
322
353
  get(token: typeof TRIGGER_EVENTS_BACKEND, opts: {
323
354
  strict: false;
324
355
  }): TriggersBackend;
@@ -331,7 +362,7 @@ export declare class ExtensionHost {
331
362
  get(token: typeof EXTERNAL_CONVERSATIONS_BACKEND, opts: {
332
363
  strict: false;
333
364
  }): ExternalConversationsBackend;
334
- },
365
+ } | undefined,
335
366
  /** Tests only: `ctx.net`'s DNS and dispatcher seams (`EXTENSION_NET_SEAMS`). */
336
367
  netSeams?: ExtensionNetSeams, dbIdentity?: ExtensionDbIdentity);
337
368
  /** The startup config's `extensionConfig` (file / Nacos merged with env). */
@@ -413,18 +444,13 @@ export declare class ExtensionHost {
413
444
  private rawConfigOf;
414
445
  /** 把一份已校验部署配置里的密钥值登记到日志打码。 */
415
446
  private reportSecrets;
447
+ private tierOf;
416
448
  /**
417
- * 安装记录收敛到 PG 期望状态(启动第 3 步与运行中的 {@link converge} 共用,C16);`desired` 为期望启用的记录。
418
- * 1. 不再期望启用的(停用 / 卸载):卸下(排空在途调用),未加载但写过状态行的标为 unloaded;
419
- * 2. 期望启用、本副本已在目标包上的:不动;
420
- * 3. 其余:准备候选(同步 → 按静态清单与迁移 SQL 算权限集合;失败记 failed:`sync_failed` / `sha_mismatch`),
421
- * 与生效的插件一起按依赖拓扑序逐个处理:权限闸门(新增权限待批准 → pending / approval,旧实例照常)、
422
- * 必需能力(此刻没有生效的提供方 → pending / dependency)、导入模块并核对静态清单(`import_failed` /
423
- * `manifest_mismatch`;闸门放行之前不导入)、部署配置、
424
- * 持锁迁移(busy → pending / migration)、setup,成功后登记新实例(先加载新、再撤销旧:旧实例在后台排空后撤销);
425
- * 任何一步失败旧实例保留,记 failed(`migration_failed` / `setup_failed`)。
426
- * 4. 运行中(非启动):对变了的能力做依赖方连锁(本轮刚加载的除外),此前因依赖卸下的插件随之补回。
427
- * 返回启用的安装记录在静态清单里声明提供的能力(启动第 4 步据此判断待定还是缺提供方)。
449
+ * Reconciles enabled installs from PostgreSQL at startup and during convergence. It removes
450
+ * withdrawn revisions, verifies the tier, and prepares replacements in dependency order.
451
+ * Permission or dependency waits keep the same-tier serving revision. Import, migration and
452
+ * setup failures report the stage that failed. Successful replacements drain the old instance
453
+ * and changed providers trigger dependency reconciliation.
428
454
  */
429
455
  private applyInstalls;
430
456
  /**
@@ -457,7 +483,7 @@ export declare class ExtensionHost {
457
483
  private logFailure;
458
484
  /** 记下(替换同名的)待定插件,供 {@link pending} 列出。 */
459
485
  private notePending;
460
- /** 从待定清单里去掉。 */
486
+ /** Removes an extension from the pending list. */
461
487
  private dropPending;
462
488
  /**
463
489
  * 第 4 步:第 2 步挑出来的配置声明插件(`requires` 只能由安装记录满足)。与已加载的插件一起解析依赖:
@@ -466,6 +492,7 @@ export declare class ExtensionHost {
466
492
  * 与「配置声明插件依赖待批准的配置声明插件」一致,内核照常启动;
467
493
  * - 缺的能力没有任何提供方 → 与此前一样抛错(内核启动失败)。
468
494
  */
495
+ private declaredMigrationDirectory;
469
496
  private loadDeferred;
470
497
  /**
471
498
  * Checks the config UI hints of a loaded module's deployment schema (spec §4.1). Invalid
@@ -488,10 +515,9 @@ export declare class ExtensionHost {
488
515
  */
489
516
  private writeStatus;
490
517
  /**
491
- * 加载一个插件:权限闸门结论、部署配置、迁移、setup、登记。`fatal` 时(配置声明)出错直接抛;
492
- * 否则(安装记录)记 failed 后返回。部署配置不合法时(任何来源)只记 pending(reason config),不抛(C10)。
493
- * 已有同名实例时(升级):新实例登记后旧实例才撤销(后台排空在途调用);新实例没加载成时旧实例保持不变。
494
- * 返回新登记的实例(没有加载时返回 undefined)。
518
+ * Admit a reviewed revision, resolve deployment config, migrate, and register it. Ineligible
519
+ * config leaves the extension pending. A same-tier replacement keeps the previous instance
520
+ * available until the new instance registers. Tier transitions drain before replacement.
495
521
  */
496
522
  private activate;
497
523
  /**
@@ -511,21 +537,14 @@ export declare class ExtensionHost {
511
537
  * 与 unload / reload 串行。返回本次加载的插件名。
512
538
  */
513
539
  activatePending(): Promise<string[]>;
540
+ revokeIsolatedInvocations(scope: IsolatedRevocation): void;
541
+ revalidateIsolatedInvocations(): Promise<void>;
514
542
  /**
515
- * 本副本收敛到部署的期望状态(T14 reconcile 的一步,与 unload / reload 串行):
516
- * 1. 待定的配置声明插件(批准后、或运行中加载失败的)按此刻的快照与生效的提供方重试;
517
- * 2. 安装记录按 PG 期望状态收敛(见 {@link applyInstalls}:停用 / 卸载的卸下,换包的先加载新再撤销旧,
518
- * 失败的每次重试),之后做依赖方连锁;
519
- * 3. 再试一次第 1 步(安装记录提供的能力可能放行了依赖它的配置声明插件)。
520
- * 读不到安装记录时只做第 1 步并抛错(调用方记日志,下一个周期再来)。
543
+ * Publish approved policy expectations before doing work that might leave a handler temporarily
544
+ * unavailable. Re-read after activation, which may have persisted new permission approvals.
521
545
  */
522
546
  converge(): Promise<void>;
523
- /**
524
- * Refreshes {@link policyExpected} from deployment state (M-1):
525
- * config-declared plugins and enabled installs (`desired`) from their approved permission snapshot.
526
- * `desired` undefined (install records unreadable) keeps the previous install entries.
527
- * `shrinkOnly`: only remove entries (a plugin no longer desired or approved), never add new ones.
528
- */
547
+ /** Policy expectations follow approval and deployment state for every execution tier. */
529
548
  private refreshPolicyExpectations;
530
549
  /**
531
550
  * Plugins that deployment state expects to run `policy` hooks on the mount point (M-1): enabled and
@@ -553,7 +572,7 @@ export declare class ExtensionHost {
553
572
  /** 配置声明的插件名 → 来源(安装包不能与它们重名)。 */
554
573
  declared(): Map<string, ExtensionSource>;
555
574
  /**
556
- * Extensions enabled in the org: `extension_org_configs.enabled` plus every always-on extension
575
+ * Extensions enabled in the org: the org intent projection
557
576
  * (required bootstrap plugins, builtin plugins' extensions; see `enabled.ts`); queried every
558
577
  * time, not cached.
559
578
  * Cost (M-4): hooks call this on every run, so one PG query per model attempt and per tool call.
@@ -564,15 +583,14 @@ export declare class ExtensionHost {
564
583
  /**
565
584
  * The access behind an extension's `ctx.extensionPoints`: only active instances in the registry
566
585
  * (dependencies load in topological order, so the depended-on are ready first); org enablement is
567
- * read from `extension_org_configs` every time, not cached. Resolved live on every call: once a
586
+ * read from PostgreSQL every time, not cached. Resolved live on every call: once a
568
587
  * provider is revoked it is no longer returned.
569
588
  */
570
589
  private readonly extensionPointAccess;
571
590
  private get loadDeps();
572
591
  /**
573
- * 按加载参数建一个新实例(setup 期间的 ctx 记在 `settingUp`,close() 时立即关闭)。
574
- * `timeoutMs`(运行中重新加载):setup 超时或宿主被关闭时关闭这个 ctx 并抛错;迟到完成的实例随即撤销。
575
- * 配置声明的插件启动时不设时限(见 {@link load})。
592
+ * Build a new generation. Track its context during setup so shutdown can close it immediately.
593
+ * A reload deadline closes incomplete setup and any late instance that reaches registration.
576
594
  */
577
595
  private setup;
578
596
  /** Logs once per load what slot resolution left out or flagged (UI slots spec §3.2). */
@@ -719,6 +737,7 @@ export declare class ExtensionHost {
719
737
  }): Promise<ExtensionInstance>;
720
738
  /** 摘下并撤销一个实例(不做连锁);不在注册表时返回 undefined。 */
721
739
  private doUnload;
740
+ private assertCurrentInstall;
722
741
  /** 新建实例并原子替换、撤销旧实例(不做连锁)。 */
723
742
  private doReload;
724
743
  /** 生效实例按依赖拓扑排序(解析不了时退回注册表顺序)。 */