@capybara-hq/kernel 0.1.0-rc.143 → 0.1.0-rc.145
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.
- package/dist/admin/admin-agents.controller.d.ts +3 -5
- package/dist/admin/admin-agents.controller.js +1 -1
- package/dist/admin/admin-connectors.controller.d.ts +3 -5
- package/dist/admin/admin-connectors.controller.js +1 -1
- package/dist/admin/admin-items.schemas.d.ts +6 -6
- package/dist/admin/admin-items.schemas.js +5 -9
- package/dist/admin/admin.controller.d.ts +18 -12
- package/dist/admin/admin.controller.js +29 -15
- package/dist/admin/admin.schemas.d.ts +12 -3
- package/dist/admin/admin.schemas.js +17 -6
- package/dist/agents/admin-agents.d.ts +30 -11
- package/dist/agents/admin-agents.js +51 -16
- package/dist/automations/automations.controller.d.ts +9 -5
- package/dist/automations/automations.controller.js +21 -4
- package/dist/automations/automations.schemas.d.ts +19 -0
- package/dist/automations/automations.schemas.js +9 -0
- package/dist/automations/automations.service.d.ts +25 -8
- package/dist/automations/automations.service.js +40 -34
- package/dist/automations/store.d.ts +17 -0
- package/dist/automations/store.js +35 -0
- package/dist/catalog/admin-catalog.controller.d.ts +64 -2
- package/dist/catalog/admin-catalog.controller.js +17 -0
- package/dist/catalog/cli.js +2 -2
- package/dist/catalog/marketplace-fetch.d.ts +2 -0
- package/dist/catalog/marketplace-fetch.js +7 -2
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/plugin-package.js +2 -1
- package/dist/client/client-access.service.js +29 -1
- package/dist/config/schema.d.ts +9 -0
- package/dist/config/schema.js +26 -0
- package/dist/ctx/create-ctx.d.ts +2 -19
- package/dist/ctx/create-ctx.js +3 -93
- package/dist/ctx/durable-relay.d.ts +2 -5
- package/dist/ctx/durable-relay.js +56 -29
- package/dist/db/extension-handoff-schema.js +5 -0
- package/dist/db/kernel-schema.d.ts +74 -0
- package/dist/erasure/account-batches.js +2 -0
- package/dist/erasure/account-residual.js +1 -0
- package/dist/erasure/org-catalog.js +8 -3
- package/dist/erasure/org-rules.js +1 -0
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +2 -2
- package/dist/evals/evals.schemas.d.ts +15 -5
- package/dist/evals/evals.schemas.js +17 -10
- package/dist/evals/runs.controller.d.ts +4 -12
- package/dist/evals/runs.controller.js +14 -11
- package/dist/evals/runs.service.d.ts +29 -25
- package/dist/evals/runs.service.js +73 -61
- package/dist/evals/trajectory.controller.d.ts +10 -6
- package/dist/evals/trajectory.controller.js +11 -4
- package/dist/evals/trajectory.service.d.ts +17 -9
- package/dist/evals/trajectory.service.js +52 -35
- package/dist/extensions/admin-ops.js +4 -3
- package/dist/extensions/blobs.d.ts +2 -0
- package/dist/extensions/blobs.js +11 -0
- package/dist/extensions/enabled.d.ts +5 -0
- package/dist/extensions/grant-epoch.d.ts +108 -0
- package/dist/extensions/grant-epoch.js +214 -0
- package/dist/extensions/host.d.ts +30 -10
- package/dist/extensions/host.js +162 -43
- package/dist/extensions/instance.d.ts +3 -3
- package/dist/extensions/instance.js +1 -1
- package/dist/extensions/isolated/authorization.d.ts +54 -2
- package/dist/extensions/isolated/authorization.js +148 -35
- package/dist/extensions/isolated/child-session.js +0 -1
- package/dist/extensions/isolated/revision.js +1 -1
- package/dist/extensions/isolated/tier.d.ts +14 -0
- package/dist/extensions/isolated/tier.js +27 -0
- package/dist/extensions/package-digest.job.d.ts +34 -0
- package/dist/extensions/package-digest.job.js +121 -0
- package/dist/extensions/package.js +10 -6
- package/dist/extensions/permission-set.d.ts +14 -78
- package/dist/extensions/permission-set.js +17 -143
- package/dist/extensions/permission-view.d.ts +13 -1
- package/dist/extensions/permission-view.js +20 -0
- package/dist/extensions/publisher-proof.job.d.ts +39 -0
- package/dist/extensions/publisher-proof.job.js +160 -0
- package/dist/extensions/registry.js +4 -1
- package/dist/extensions/resolve.d.ts +7 -8
- package/dist/extensions/resolve.js +7 -8
- package/dist/extensions/revision-approvals.d.ts +167 -0
- package/dist/extensions/revision-approvals.js +353 -0
- package/dist/extensions/revision-grants.d.ts +197 -0
- package/dist/extensions/revision-grants.js +584 -0
- package/dist/extensions/state.module.js +12 -1
- package/dist/identity/accounts.d.ts +10 -4
- package/dist/identity/accounts.js +18 -5
- package/dist/infra/database/extension-effect-key-lock.js +7 -0
- package/dist/infra/paging/paged-read.d.ts +34 -4
- package/dist/infra/paging/paged-read.js +38 -1
- package/dist/orgs/invitations.controller.d.ts +4 -7
- package/dist/orgs/invitations.controller.js +8 -5
- package/dist/orgs/invitations.service.d.ts +17 -3
- package/dist/orgs/invitations.service.js +35 -13
- package/dist/orgs/members.service.d.ts +35 -0
- package/dist/orgs/members.service.js +52 -3
- package/dist/orgs/orgs.controller.d.ts +11 -4
- package/dist/orgs/orgs.controller.js +25 -5
- package/dist/orgs/orgs.schemas.d.ts +14 -0
- package/dist/orgs/orgs.schemas.js +19 -2
- package/dist/orgs/orgs.service.d.ts +21 -1
- package/dist/orgs/orgs.service.js +40 -1
- package/dist/orgs/security-settings.service.d.ts +14 -6
- package/dist/orgs/security-settings.service.js +18 -13
- package/dist/orgs/settings.controller.d.ts +7 -4
- package/dist/packages/official-publisher.d.ts +5 -0
- package/dist/packages/official-publisher.js +24 -3
- package/dist/packages/provenance.d.ts +6 -0
- package/dist/packages/provenance.js +26 -9
- package/dist/platform/exclusions.js +15 -0
- package/dist/platform/ops/accounts.ops.js +7 -16
- package/dist/platform/ops/admin-items.ops.js +8 -8
- package/dist/platform/ops/automations.ops.js +6 -4
- package/dist/platform/ops/evals.ops.js +30 -15
- package/dist/platform/ops/org-settings.ops.js +2 -2
- package/dist/platform/ops/orgs.ops.js +44 -27
- package/dist/roles/worker.module.js +6 -0
- package/dist/runtime/step-log.d.ts +1 -1
- package/dist/runtime/step-log.js +5 -4
- package/dist/setup/kernel-checks.d.ts +3 -3
- package/dist/setup/kernel-checks.js +4 -4
- package/dist/setup/setup-check-registry.d.ts +16 -5
- package/dist/setup/setup-check-registry.js +11 -3
- package/dist/setup/setup-checks.service.d.ts +1 -2
- package/dist/setup/setup-checks.service.js +7 -6
- package/dist/tools/admin-connectors.d.ts +10 -8
- package/dist/tools/admin-connectors.js +12 -10
- package/dist/tools/builtins/automations.d.ts +1 -1
- package/dist/tools/builtins/automations.js +1 -1
- package/package.json +3 -3
- package/src/migrations/0234_extension_grant_epoch.sql +141 -0
- package/src/migrations/0235_extension_revision_grants.sql +166 -0
- package/src/migrations/0236_paged_table_idx.sql +33 -0
- package/src/migrations/0237_extension_handoff_health.sql +18 -0
package/dist/extensions/host.js
CHANGED
|
@@ -11,11 +11,13 @@ import { readFile } from "node:fs/promises";
|
|
|
11
11
|
import { createRequire } from "node:module";
|
|
12
12
|
import { dirname, isAbsolute, join, resolve as resolvePath } from "node:path";
|
|
13
13
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
14
|
-
import { EXTENSION_POINT_CARDINALITY, parseExtensionPoint, SDK_VERSION, } from "@capybara-hq/plugin-sdk";
|
|
14
|
+
import { EXTENSION_POINT_CARDINALITY, extensionPointRefs, OBJECT_STORE_EXTENSION_POINT, parseExtensionPoint, SDK_VERSION, staticPermissionDeclarations, } from "@capybara-hq/plugin-sdk";
|
|
15
15
|
import { Inject, Injectable, Optional } from "@nestjs/common";
|
|
16
16
|
import { ModuleRef } from "@nestjs/core";
|
|
17
17
|
import { TRIGGER_EVENTS_BACKEND } from "../automations/events/token.js";
|
|
18
|
+
import { officialPublisherProofMode } from "../catalog/publisher-policy.js";
|
|
18
19
|
import { changedPaths, configFields, getPath, secretValues, unreachableSecrets, } from "../config/fields.js";
|
|
20
|
+
import { EXTENSION_CAPACITY_DEFAULTS } from "../config/schema.js";
|
|
19
21
|
import { EXTERNAL_CONVERSATIONS_BACKEND } from "../conversations/external/token.js";
|
|
20
22
|
import { pluginSchemaName, queryEnabledPlugins, } from "../ctx/create-ctx.js";
|
|
21
23
|
import { ExtensionEffects } from "../ctx/durable-effects.service.js";
|
|
@@ -51,6 +53,7 @@ import { deploymentConfigHash } from "./config-hash.js";
|
|
|
51
53
|
import { toIssues } from "./config-issues.js";
|
|
52
54
|
import { configFormSchema, describeConfigUiProblems } from "./config-json-schema.js";
|
|
53
55
|
import { EffectiveConfigs } from "./effective-config.js";
|
|
56
|
+
import { GrantEpoch, grantEpochReader, grantEpochReadTimeoutMs } from "./grant-epoch.js";
|
|
54
57
|
import { HookRegistry } from "./hooks.js";
|
|
55
58
|
import { ExtensionInstalls } from "./installs.js";
|
|
56
59
|
import { ImportTracker, importExtensionModule, ManifestMismatchError, matchesSection, setupInstance, warnUpgrades, } from "./instance.js";
|
|
@@ -60,11 +63,13 @@ import { readConfiguredExtensionPackage, stageConfiguredExtensionPackage, } from
|
|
|
60
63
|
import { IsolatedExtensionQuota } from "./isolated/lanes.js";
|
|
61
64
|
import { isolatedRevision } from "./isolated/revision.js";
|
|
62
65
|
import { sweepExtensionSandboxOrphans } from "./isolated/sandbox.js";
|
|
66
|
+
import { publisherProofMissing, publisherProofRefusal, } from "./isolated/tier.js";
|
|
63
67
|
import { parseLoadGate } from "./org-levels.js";
|
|
64
68
|
import { declaredDisplayName, permissionSetOfSection, readMigrationSql } from "./package.js";
|
|
65
69
|
import { blockingKeys, computePermissionSet, SETUP_CHECK_KEY_PREFIX, UI_VIEW_KEY_PREFIX, } from "./permission-set.js";
|
|
66
70
|
import { ExtensionRegistry } from "./registry.js";
|
|
67
71
|
import { ExtensionResolveError, electSingleProviders, PROVIDER_CONFLICT, providerConflictMessage, resolveExtensions, } from "./resolve.js";
|
|
72
|
+
import { ExtensionRevisionApprovals } from "./revision-approvals.js";
|
|
68
73
|
import { ReplicaStatusStore, } from "./sources.js";
|
|
69
74
|
import { PackageShaMismatchError, packageRootOf } from "./sync.js";
|
|
70
75
|
export { deploymentConfigHash };
|
|
@@ -257,14 +262,15 @@ const migrationsDirOf = (m, dir) => m.migrations ? resolvePath(dir, m.migrations
|
|
|
257
262
|
* 闸门放行后导入的真实模块必须与静态清单一致({@link matchesSection}),两者在依赖解析上等价。
|
|
258
263
|
*/
|
|
259
264
|
function manifestOfSection(m) {
|
|
265
|
+
const declaration = staticPermissionDeclarations(m);
|
|
260
266
|
return {
|
|
261
267
|
name: m.name,
|
|
262
268
|
version: m.version,
|
|
263
269
|
sdk: m.sdk,
|
|
264
|
-
provides:
|
|
265
|
-
requires:
|
|
266
|
-
optional:
|
|
267
|
-
permissions:
|
|
270
|
+
provides: declaration.provides,
|
|
271
|
+
requires: declaration.requires,
|
|
272
|
+
optional: declaration.optional,
|
|
273
|
+
permissions: declaration.permissions,
|
|
268
274
|
...(m.ui !== undefined && { ui: m.ui }),
|
|
269
275
|
setup() {
|
|
270
276
|
throw new Error(`plugin ${m.name}: static manifest cannot be set up`);
|
|
@@ -295,6 +301,7 @@ let ExtensionHost = class ExtensionHost {
|
|
|
295
301
|
allowances;
|
|
296
302
|
modules;
|
|
297
303
|
dbIdentity;
|
|
304
|
+
revisionApprovals;
|
|
298
305
|
/**
|
|
299
306
|
* Only resolves extensions and runs migrations in dependency order: no deployment config check, no
|
|
300
307
|
* setup, no Redis (for `capybara migrate`). Like `load()` it checks secret markers first
|
|
@@ -405,7 +412,10 @@ let ExtensionHost = class ExtensionHost {
|
|
|
405
412
|
quota = new Map();
|
|
406
413
|
isolatedAuthority = new WeakMap();
|
|
407
414
|
isolatedLanes = new WeakMap();
|
|
408
|
-
isolatedGrants
|
|
415
|
+
isolatedGrants;
|
|
416
|
+
/** This replica's view of the deployment grant epoch; polls only once an isolated grant was issued. */
|
|
417
|
+
grantEpoch;
|
|
418
|
+
epochReader;
|
|
409
419
|
executionTier = new Map();
|
|
410
420
|
policyExpected = new Map();
|
|
411
421
|
/**
|
|
@@ -535,7 +545,12 @@ let ExtensionHost = class ExtensionHost {
|
|
|
535
545
|
*/
|
|
536
546
|
modules,
|
|
537
547
|
/** Tests only: `ctx.net`'s DNS and dispatcher seams (`EXTENSION_NET_SEAMS`). */
|
|
538
|
-
netSeams, dbIdentity = extensionDbIdentity(config.get().db)
|
|
548
|
+
netSeams, dbIdentity = extensionDbIdentity(config.get().db),
|
|
549
|
+
/**
|
|
550
|
+
* Shadow revision approvals (plan task 1.2b): reported at start, never refusing. Absent in a
|
|
551
|
+
* hand-built host, which then reports nothing.
|
|
552
|
+
*/
|
|
553
|
+
revisionApprovals) {
|
|
539
554
|
this.registry = registry;
|
|
540
555
|
this.installs = installs;
|
|
541
556
|
this.approvals = approvals;
|
|
@@ -547,6 +562,7 @@ let ExtensionHost = class ExtensionHost {
|
|
|
547
562
|
this.allowances = allowances;
|
|
548
563
|
this.modules = modules;
|
|
549
564
|
this.dbIdentity = dbIdentity;
|
|
565
|
+
this.revisionApprovals = revisionApprovals;
|
|
550
566
|
const c = config.get();
|
|
551
567
|
this.hooks = new HookRegistry({
|
|
552
568
|
instances: () => this.registry.all(),
|
|
@@ -558,6 +574,30 @@ let ExtensionHost = class ExtensionHost {
|
|
|
558
574
|
config: () => ({ hooks: { timeoutMs: this.config.get().hooks.timeoutMs } }),
|
|
559
575
|
log,
|
|
560
576
|
});
|
|
577
|
+
// Hand-built configs (tests, embedders) may leave the capacity object out.
|
|
578
|
+
const capacity = { ...EXTENSION_CAPACITY_DEFAULTS, ...c.extensionHost.capacity };
|
|
579
|
+
this.epochReader = grantEpochReader({
|
|
580
|
+
url: c.db.url,
|
|
581
|
+
readTimeoutMs: grantEpochReadTimeoutMs(capacity.grantEpochMaxAgeMs),
|
|
582
|
+
connectTimeoutMs: c.db.connectTimeoutMs,
|
|
583
|
+
onError: (err) => this.log.warn("grant epoch connection error", { err }),
|
|
584
|
+
});
|
|
585
|
+
this.grantEpoch = new GrantEpoch({
|
|
586
|
+
read: this.epochReader.read,
|
|
587
|
+
maxAgeMs: capacity.grantEpochMaxAgeMs,
|
|
588
|
+
onChange: () => {
|
|
589
|
+
void this.isolatedGrants
|
|
590
|
+
.epochChanged()
|
|
591
|
+
.catch((err) => this.log.warn("isolated extension grant revalidation failed", { err }));
|
|
592
|
+
},
|
|
593
|
+
onSettleDeadline: () => this.isolatedGrants.fenceStale(),
|
|
594
|
+
onExpired: () => {
|
|
595
|
+
this.log.warn("isolated extension grants fenced: the grant epoch could not be read");
|
|
596
|
+
this.isolatedGrants.fenceAll();
|
|
597
|
+
},
|
|
598
|
+
onFault: (err) => this.log.warn("reading the extension grant epoch failed", { err }),
|
|
599
|
+
});
|
|
600
|
+
this.isolatedGrants = new IsolatedInvocationGrants(this.grantEpoch, capacity.grantCacheEntries);
|
|
561
601
|
this.deps = {
|
|
562
602
|
db: kdb.pool,
|
|
563
603
|
dbUrl: c.db.url,
|
|
@@ -741,6 +781,7 @@ let ExtensionHost = class ExtensionHost {
|
|
|
741
781
|
assertIsolatedSection(isolated.section);
|
|
742
782
|
}
|
|
743
783
|
catch (cause) {
|
|
784
|
+
await this.reportAdmissionRefusal(manifest.name, isolated.digest, errMsg(cause), "Install a revision that declares supported isolated capabilities and configuration.");
|
|
744
785
|
throw new Error(`Configured extension ${manifest.name} was refused: ${errMsg(cause)}`, {
|
|
745
786
|
cause,
|
|
746
787
|
});
|
|
@@ -810,6 +851,8 @@ let ExtensionHost = class ExtensionHost {
|
|
|
810
851
|
await this.loadDeferred(deferred, dirs, urls, snapshots, approvals, installProviders);
|
|
811
852
|
}
|
|
812
853
|
await this.refreshPolicyExpectations(desired ?? []);
|
|
854
|
+
if (p.installs)
|
|
855
|
+
void this.reportShadowStartGate();
|
|
813
856
|
const orphans = Object.keys(this.extensionConfig).filter((k) => !this.sources.has(k));
|
|
814
857
|
if (orphans.length > 0) {
|
|
815
858
|
this.log.warn("extensionConfig has keys for extensions that are not loaded", {
|
|
@@ -817,6 +860,43 @@ let ExtensionHost = class ExtensionHost {
|
|
|
817
860
|
});
|
|
818
861
|
}
|
|
819
862
|
}
|
|
863
|
+
/** The last shadow report logged by this replica (a log de-duplication, not state). */
|
|
864
|
+
lastShadowReport;
|
|
865
|
+
/**
|
|
866
|
+
* Shadow mode (plan task 1.2b, rollout fence until 1.5a): what the enforcing start gate would
|
|
867
|
+
* decide from revision grants, reported in the log after the start and after each install
|
|
868
|
+
* convergence, when it changes. The legacy snapshots govern; this never refuses, never blocks
|
|
869
|
+
* the start (it runs after it, reading packages in the background) and its failures only warn.
|
|
870
|
+
* An info line, not a warning: until the first reviews (plan tasks 1.3a and 1.3c) every install
|
|
871
|
+
* is listed. Config-declared extensions have no stored package digest and are left to the
|
|
872
|
+
* bootstrap review (1.3c) and the cutover preflight (1.5a).
|
|
873
|
+
*/
|
|
874
|
+
async reportShadowStartGate() {
|
|
875
|
+
try {
|
|
876
|
+
if (!this.revisionApprovals)
|
|
877
|
+
return;
|
|
878
|
+
const gate = await this.revisionApprovals.startGate();
|
|
879
|
+
if (this.closed)
|
|
880
|
+
return;
|
|
881
|
+
const name = (d) => `${d.revision.plugin}@${d.revision.version} (${d.status}, legacy ${d.legacy})`;
|
|
882
|
+
const report = {
|
|
883
|
+
missingRequired: gate.missingRequired.map(name),
|
|
884
|
+
pending: gate.pending.map(name),
|
|
885
|
+
diverging: gate.diverging.length,
|
|
886
|
+
};
|
|
887
|
+
const digest = JSON.stringify(report);
|
|
888
|
+
if (digest === this.lastShadowReport)
|
|
889
|
+
return;
|
|
890
|
+
this.lastShadowReport = digest;
|
|
891
|
+
if (report.missingRequired.length > 0 || report.pending.length > 0) {
|
|
892
|
+
this.log.info("shadow revision grants: the enforcing start gate would hold these back", report);
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
catch (err) {
|
|
896
|
+
if (!this.closed)
|
|
897
|
+
this.log.warn("shadow revision grant decisions failed", { err });
|
|
898
|
+
}
|
|
899
|
+
}
|
|
820
900
|
/**
|
|
821
901
|
* Records each config-declared extension's display name from its plugin directory's plugin.json
|
|
822
902
|
* (spec §2.2); an invalid plugin.json only warns (no display name).
|
|
@@ -946,13 +1026,23 @@ let ExtensionHost = class ExtensionHost {
|
|
|
946
1026
|
const wanted = new Map();
|
|
947
1027
|
const tiers = new Map();
|
|
948
1028
|
const rejected = new Map();
|
|
1029
|
+
const rejectedActions = new Map();
|
|
1030
|
+
let proofMode;
|
|
949
1031
|
for (const d of electAmong) {
|
|
950
1032
|
if (declared.has(d.name))
|
|
951
1033
|
continue;
|
|
952
1034
|
try {
|
|
953
1035
|
const tier = await this.tierOf(loader, d, false);
|
|
954
1036
|
if (tier === "refused") {
|
|
955
|
-
|
|
1037
|
+
if (publisherProofMissing(d)) {
|
|
1038
|
+
proofMode ??= await officialPublisherProofMode(kernelDb(this.deps.db));
|
|
1039
|
+
const refusal = publisherProofRefusal(proofMode);
|
|
1040
|
+
rejected.set(d.name, refusal.detail);
|
|
1041
|
+
rejectedActions.set(d.name, refusal.action);
|
|
1042
|
+
}
|
|
1043
|
+
else {
|
|
1044
|
+
rejected.set(d.name, "The extension revision did not pass trust admission");
|
|
1045
|
+
}
|
|
956
1046
|
continue;
|
|
957
1047
|
}
|
|
958
1048
|
if (tier === "isolated")
|
|
@@ -985,7 +1075,7 @@ let ExtensionHost = class ExtensionHost {
|
|
|
985
1075
|
continue;
|
|
986
1076
|
wanted.set(d.name, d);
|
|
987
1077
|
// 按审阅过的静态清单(不论随后加载成败)
|
|
988
|
-
for (const cap of d.section.manifest.provides) {
|
|
1078
|
+
for (const cap of extensionPointRefs(d.section.manifest.provides)) {
|
|
989
1079
|
installProviders.set(cap, [...(installProviders.get(cap) ?? []), d.name]);
|
|
990
1080
|
}
|
|
991
1081
|
}
|
|
@@ -1024,16 +1114,19 @@ let ExtensionHost = class ExtensionHost {
|
|
|
1024
1114
|
}
|
|
1025
1115
|
for (const d of desired) {
|
|
1026
1116
|
const detail = rejected.get(d.name);
|
|
1027
|
-
if (detail)
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1117
|
+
if (!detail)
|
|
1118
|
+
continue;
|
|
1119
|
+
await this.reportAdmissionRefusal(d.name, d.sha256, detail, rejectedActions.get(d.name) ??
|
|
1120
|
+
"Review the plugin revision and install a package eligible for this deployment.");
|
|
1121
|
+
await this.writeStatus({
|
|
1122
|
+
plugin: d.name,
|
|
1123
|
+
version: d.version,
|
|
1124
|
+
sha256: d.sha256,
|
|
1125
|
+
source: "install",
|
|
1126
|
+
state: "failed",
|
|
1127
|
+
reason: "import_failed",
|
|
1128
|
+
detail,
|
|
1129
|
+
});
|
|
1037
1130
|
}
|
|
1038
1131
|
const candidates = [];
|
|
1039
1132
|
for (const d of wanted.values()) {
|
|
@@ -1055,9 +1148,11 @@ let ExtensionHost = class ExtensionHost {
|
|
|
1055
1148
|
verified = await this.tierOf(loader, d, true);
|
|
1056
1149
|
}
|
|
1057
1150
|
catch {
|
|
1058
|
-
|
|
1151
|
+
// The refusal below reports the failed integrity check without logging verifier internals.
|
|
1059
1152
|
}
|
|
1060
1153
|
if (verified !== "trusted") {
|
|
1154
|
+
const detail = "The trusted extension package did not match its verified integrity";
|
|
1155
|
+
await this.reportAdmissionRefusal(d.name, d.sha256, detail, "Check publisher verification and reimport the verified package.");
|
|
1061
1156
|
await this.writeStatus({
|
|
1062
1157
|
plugin: d.name,
|
|
1063
1158
|
version: d.version,
|
|
@@ -1065,7 +1160,7 @@ let ExtensionHost = class ExtensionHost {
|
|
|
1065
1160
|
source: "install",
|
|
1066
1161
|
state: "failed",
|
|
1067
1162
|
reason: "sha_mismatch",
|
|
1068
|
-
detail
|
|
1163
|
+
detail,
|
|
1069
1164
|
});
|
|
1070
1165
|
continue;
|
|
1071
1166
|
}
|
|
@@ -1303,6 +1398,22 @@ let ExtensionHost = class ExtensionHost {
|
|
|
1303
1398
|
/**
|
|
1304
1399
|
* 安装记录加载失败的 error 日志:每个周期都会重试,同一个包、同一个原因只记一次(状态行每次照写)。
|
|
1305
1400
|
*/
|
|
1401
|
+
async reportAdmissionRefusal(plugin, sha256, detail, action) {
|
|
1402
|
+
const recorded = await kernelDb(this.deps.db)
|
|
1403
|
+
.insertInto("extension_admission_refusals")
|
|
1404
|
+
.values({ plugin, sha256 })
|
|
1405
|
+
.onConflict((conflict) => conflict.doNothing())
|
|
1406
|
+
.returning("plugin")
|
|
1407
|
+
.executeTakeFirst();
|
|
1408
|
+
if (recorded) {
|
|
1409
|
+
this.log.error("Extension revision refused", {
|
|
1410
|
+
plugin,
|
|
1411
|
+
sha256,
|
|
1412
|
+
detail: this.log.redact(detail).slice(0, 500),
|
|
1413
|
+
action,
|
|
1414
|
+
});
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1306
1417
|
logFailure(plugin, sha256, reason, err, fields) {
|
|
1307
1418
|
const key = `${sha256}:${reason}`;
|
|
1308
1419
|
if (this.loggedFailures.get(plugin) === key)
|
|
@@ -1510,10 +1621,16 @@ let ExtensionHost = class ExtensionHost {
|
|
|
1510
1621
|
if (a.source !== "install")
|
|
1511
1622
|
this.pendingActivations.set(name, a);
|
|
1512
1623
|
};
|
|
1513
|
-
const failSoft = async (reason, e,
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1624
|
+
const failSoft = async (reason, e, admission) => {
|
|
1625
|
+
const detail = errMsg(e);
|
|
1626
|
+
if (admission && a.sha256) {
|
|
1627
|
+
await this.reportAdmissionRefusal(name, a.sha256, detail, admission.action);
|
|
1628
|
+
}
|
|
1629
|
+
else {
|
|
1630
|
+
this.logFailure(name, a.sha256, reason, e, { version: manifest.version });
|
|
1631
|
+
}
|
|
1632
|
+
await this.writeStatus({ ...base, state: "failed", reason, detail });
|
|
1633
|
+
if (a.fatal && a.isolated && admission?.refuseDeclaration) {
|
|
1517
1634
|
throw new Error(`Configured extension ${name} was refused: ${errMsg(e)}`, { cause: e });
|
|
1518
1635
|
}
|
|
1519
1636
|
if (a.isolated)
|
|
@@ -1537,7 +1654,10 @@ let ExtensionHost = class ExtensionHost {
|
|
|
1537
1654
|
manifest = isolatedManifestOf(a.isolated.section);
|
|
1538
1655
|
}
|
|
1539
1656
|
catch (error) {
|
|
1540
|
-
return failSoft("import_failed", error,
|
|
1657
|
+
return failSoft("import_failed", error, {
|
|
1658
|
+
action: "Install a revision that declares supported isolated capabilities and configuration.",
|
|
1659
|
+
refuseDeclaration: true,
|
|
1660
|
+
});
|
|
1541
1661
|
}
|
|
1542
1662
|
}
|
|
1543
1663
|
const schema = manifest.config?.deployment;
|
|
@@ -1642,7 +1762,10 @@ let ExtensionHost = class ExtensionHost {
|
|
|
1642
1762
|
throw new Error(CLOSED_DURING_LOAD);
|
|
1643
1763
|
// The isolated runner must be available before an isolated revision can migrate or activate.
|
|
1644
1764
|
if (a.isolated && !this.config.get().extensionHost.isolation) {
|
|
1645
|
-
return failSoft("setup_failed", new Error("The isolated extension supervisor is not configured"),
|
|
1765
|
+
return failSoft("setup_failed", new Error("The isolated extension supervisor is not configured"), {
|
|
1766
|
+
action: "Configure extensionHost.isolation and restart the replica.",
|
|
1767
|
+
refuseDeclaration: true,
|
|
1768
|
+
});
|
|
1646
1769
|
}
|
|
1647
1770
|
if (a.isolated) {
|
|
1648
1771
|
try {
|
|
@@ -1652,7 +1775,7 @@ let ExtensionHost = class ExtensionHost {
|
|
|
1652
1775
|
}
|
|
1653
1776
|
}
|
|
1654
1777
|
catch {
|
|
1655
|
-
return failSoft("migration_failed", new Error("The isolated extension has no dedicated database identity"));
|
|
1778
|
+
return failSoft("migration_failed", new Error("The isolated extension has no dedicated database identity"), { action: "Provision the extension database login with capybara migrate." });
|
|
1656
1779
|
}
|
|
1657
1780
|
}
|
|
1658
1781
|
const migrating = a.migrate
|
|
@@ -1814,6 +1937,7 @@ let ExtensionHost = class ExtensionHost {
|
|
|
1814
1937
|
await this.applyInstalls(loader, desired, false);
|
|
1815
1938
|
if (this.pendingActivations.size > 0)
|
|
1816
1939
|
await this.activatePendingNow();
|
|
1940
|
+
void this.reportShadowStartGate();
|
|
1817
1941
|
}
|
|
1818
1942
|
await this.refreshPolicyExpectations(desired);
|
|
1819
1943
|
});
|
|
@@ -1984,23 +2108,12 @@ let ExtensionHost = class ExtensionHost {
|
|
|
1984
2108
|
async enabledPlugins(orgId) {
|
|
1985
2109
|
return queryEnabledPlugins(this.deps.db, orgId);
|
|
1986
2110
|
}
|
|
1987
|
-
/**
|
|
1988
|
-
* The access behind an extension's `ctx.extensionPoints`: only active instances in the registry
|
|
1989
|
-
* (dependencies load in topological order, so the depended-on are ready first); org enablement is
|
|
1990
|
-
* read from PostgreSQL every time, not cached. Resolved live on every call: once a
|
|
1991
|
-
* provider is revoked it is no longer returned.
|
|
1992
|
-
*/
|
|
1993
|
-
extensionPointAccess = {
|
|
1994
|
-
providers: (ref) => this.registry
|
|
1995
|
-
.all()
|
|
1996
|
-
.flatMap((i) => i.provided.has(ref) ? [{ plugin: i.name, impl: i.provided.get(ref) }] : []),
|
|
1997
|
-
enabledPlugins: (orgId) => this.enabledPlugins(orgId),
|
|
1998
|
-
configOk: async (orgId, plugin) => (await this.effective.get(orgId, plugin)).ok,
|
|
1999
|
-
};
|
|
2000
2111
|
get loadDeps() {
|
|
2001
2112
|
return {
|
|
2002
2113
|
kernel: this.deps,
|
|
2003
|
-
|
|
2114
|
+
objectStore: () => this.registry
|
|
2115
|
+
.list("object-store")
|
|
2116
|
+
.find((entry) => entry.capability === OBJECT_STORE_EXTENSION_POINT)?.impl,
|
|
2004
2117
|
nextGeneration: (name) => {
|
|
2005
2118
|
const g = (this.generations.get(name) ?? 0) + 1;
|
|
2006
2119
|
this.generations.set(name, g);
|
|
@@ -2791,6 +2904,10 @@ let ExtensionHost = class ExtensionHost {
|
|
|
2791
2904
|
*/
|
|
2792
2905
|
async close(opts = {}) {
|
|
2793
2906
|
this.closed = true;
|
|
2907
|
+
this.grantEpoch.stop();
|
|
2908
|
+
await this.epochReader
|
|
2909
|
+
.close()
|
|
2910
|
+
.catch((err) => this.log.warn("closing the grant epoch connection failed", { err }));
|
|
2794
2911
|
this.abort.abort();
|
|
2795
2912
|
this.revokeIsolatedInvocations({});
|
|
2796
2913
|
await this.migrating?.catch(() => { });
|
|
@@ -2851,6 +2968,8 @@ ExtensionHost = __decorate([
|
|
|
2851
2968
|
__param(20, Inject(ModuleRef)),
|
|
2852
2969
|
__param(21, Optional()),
|
|
2853
2970
|
__param(21, Inject(EXTENSION_NET_SEAMS)),
|
|
2854
|
-
__param(22, Inject(ConfiguredExtensionDbIdentity))
|
|
2971
|
+
__param(22, Inject(ConfiguredExtensionDbIdentity)),
|
|
2972
|
+
__param(23, Optional()),
|
|
2973
|
+
__param(23, Inject(ExtensionRevisionApprovals))
|
|
2855
2974
|
], ExtensionHost);
|
|
2856
2975
|
export { ExtensionHost };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type DroppedUiContribution, type ExtensionManifest, type ExtensionPointRef, type ResolvedUiContribution, type StaticExtensionManifest } from "@capybara-hq/plugin-sdk";
|
|
2
|
-
import { type
|
|
1
|
+
import { type DroppedUiContribution, type ExtensionManifest, type ExtensionPointRef, type ObjectStore, type ResolvedUiContribution, type StaticExtensionManifest } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import { type KernelDeps, type KernelExtensionContext, LiveConfig, type RegisteredSetupCheck, type RegisteredTool, type Route } from "../ctx/create-ctx.js";
|
|
3
3
|
import type { extensionDbPool } from "../db/extension-db.js";
|
|
4
4
|
import type { ServiceEventHandler } from "../device-access/service-events.js";
|
|
5
5
|
import type { UiActionHandler, UiQueryHandler, UiRender } from "../ui/registry.js";
|
|
@@ -149,7 +149,7 @@ export declare function warnUpgrades(log: KernelDeps["log"], imports: ImportTrac
|
|
|
149
149
|
/** {@link setupInstance} / {@link loadInstance} 的依赖。 */
|
|
150
150
|
export interface LoadDeps {
|
|
151
151
|
kernel: KernelDeps;
|
|
152
|
-
|
|
152
|
+
objectStore: () => ObjectStore | undefined;
|
|
153
153
|
/** 该插件下一代的编号(宿主按插件名递增)。 */
|
|
154
154
|
nextGeneration(name: string): number;
|
|
155
155
|
/** 本进程导入过的模块入口({@link loadInstance} 每次导入都记一笔,超过阈值时告警)。 */
|
|
@@ -308,7 +308,7 @@ export function warnUpgrades(log, imports) {
|
|
|
308
308
|
/** 在已导入、已核对的清单上建 ctx(记账)并 setup;setup 抛错时撤销已登记的再抛。 */
|
|
309
309
|
export async function setupInstance(deps, manifest, input) {
|
|
310
310
|
const live = new LiveConfig(input.config);
|
|
311
|
-
const ctx = createExtensionContext(deps.kernel, manifest, live, deps.
|
|
311
|
+
const ctx = createExtensionContext(deps.kernel, manifest, live, deps.objectStore, {
|
|
312
312
|
sha256: input.sha256,
|
|
313
313
|
...(input.extensionDb && { db: input.extensionDb }),
|
|
314
314
|
});
|
|
@@ -20,14 +20,43 @@ interface CachedGrant {
|
|
|
20
20
|
check: () => Promise<boolean>;
|
|
21
21
|
onRevoked: () => void;
|
|
22
22
|
pending?: Promise<boolean>;
|
|
23
|
-
|
|
23
|
+
/** The grant epoch known when the last successful check started; undefined until checked. */
|
|
24
|
+
epoch: string | undefined;
|
|
25
|
+
/** When the last successful check started, for the periodic full revalidation backstop. */
|
|
26
|
+
checkedAt: number;
|
|
24
27
|
calls: number;
|
|
28
|
+
/** Admissions waiting in {@link IsolatedInvocationGrants.issue}: the entry is not idle. */
|
|
29
|
+
admitting: number;
|
|
25
30
|
}
|
|
26
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* The epoch source the cache depends on ({@link GrantEpoch} in production). `fresh` answers only
|
|
33
|
+
* while the last successful epoch read is younger than the configured maximum age.
|
|
34
|
+
*/
|
|
35
|
+
export interface GrantEpochView {
|
|
36
|
+
start(): void;
|
|
37
|
+
fresh(): string | undefined;
|
|
38
|
+
ensureFresh(): Promise<string | undefined>;
|
|
39
|
+
}
|
|
40
|
+
/** A grant checked at the current epoch is still rechecked after this long (backstop only). */
|
|
41
|
+
export declare const GRANT_FULL_REVALIDATION_MS: number;
|
|
42
|
+
/**
|
|
43
|
+
* Replica-local cache of authority checked against deployment and org state.
|
|
44
|
+
*
|
|
45
|
+
* A cached grant is valid only while it was checked at the current grant epoch and the epoch was
|
|
46
|
+
* read successfully within its maximum age. When the epoch cannot be confirmed, new admissions
|
|
47
|
+
* wait for a fresh read and are refused if it fails (fail closed). Bus hints still fence affected
|
|
48
|
+
* grants at once; the epoch covers hints that never arrive.
|
|
49
|
+
*/
|
|
27
50
|
export declare class IsolatedInvocationGrants {
|
|
51
|
+
private readonly epochs;
|
|
52
|
+
private readonly capacity;
|
|
53
|
+
private readonly now;
|
|
28
54
|
private readonly instances;
|
|
29
55
|
private readonly rechecks;
|
|
56
|
+
/** Every cached grant across instances, least recently used first. */
|
|
57
|
+
private readonly lru;
|
|
30
58
|
private revalidating;
|
|
59
|
+
constructor(epochs: GrantEpochView, capacity: number, now?: () => number);
|
|
31
60
|
issue({ plugin, orgId }: IsolatedRevocation, check: CachedGrant["check"], onRevoked: CachedGrant["onRevoked"] | undefined, instance: AbortSignal): Promise<IsolatedInvocationGrant | undefined>;
|
|
32
61
|
revoke({ plugin, orgId }: IsolatedRevocation): void;
|
|
33
62
|
/**
|
|
@@ -37,6 +66,29 @@ export declare class IsolatedInvocationGrants {
|
|
|
37
66
|
refreshOrgIntent(orgId?: string): Promise<void>;
|
|
38
67
|
/** Recheck retained grants, including idle lanes, when periodic reconciliation fires. */
|
|
39
68
|
revalidate(): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* The grant epoch advanced: some committed change may have revoked any cached grant. Every
|
|
71
|
+
* entry is stale for admission already ({@link valid} compares epochs), so idle entries are
|
|
72
|
+
* rechecked lazily by their next admission or the periodic reconcile. Entries with calls in
|
|
73
|
+
* flight are rechecked now, all together, so a call whose grant is gone is aborted quickly;
|
|
74
|
+
* {@link fenceStale} aborts the ones still unconfirmed at the settle deadline.
|
|
75
|
+
*/
|
|
76
|
+
epochChanged(): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* The settle deadline after an epoch change: abort calls whose grant was not confirmed at the
|
|
79
|
+
* current epoch, so no call outlives a revocation by more than the bound. Lanes stay up; the
|
|
80
|
+
* next admission checks PostgreSQL again.
|
|
81
|
+
*/
|
|
82
|
+
fenceStale(): void;
|
|
83
|
+
/**
|
|
84
|
+
* The epoch has not been confirmed for the whole revocation bound. Fence every cached grant:
|
|
85
|
+
* in-flight calls are cancelled and the next admission checks PostgreSQL again. Lanes stay up,
|
|
86
|
+
* because nothing is known to be revoked.
|
|
87
|
+
*/
|
|
88
|
+
fenceAll(): void;
|
|
89
|
+
private valid;
|
|
90
|
+
private evictIdle;
|
|
91
|
+
private drop;
|
|
40
92
|
private retained;
|
|
41
93
|
private runRechecks;
|
|
42
94
|
private revalidateRetained;
|