@capybara-hq/kernel 0.1.0-rc.136 → 0.1.0-rc.138
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/audit-log.service.d.ts +96 -12
- package/dist/admin/audit-log.service.js +508 -44
- package/dist/admin/audit-targets.d.ts +17 -0
- package/dist/admin/audit-targets.js +84 -0
- package/dist/admin/audit.controller.d.ts +12 -9
- package/dist/admin/audit.controller.js +29 -8
- package/dist/admin/audit.schemas.d.ts +20 -4
- package/dist/admin/audit.schemas.js +42 -17
- package/dist/admin/extensions.controller.d.ts +5 -2
- package/dist/admin/extensions.controller.js +10 -1
- package/dist/admin/extensions.schemas.d.ts +4 -0
- package/dist/admin/extensions.schemas.js +9 -0
- package/dist/admin/health.service.d.ts +1 -1
- package/dist/admin/health.service.js +3 -3
- package/dist/agents/templates.js +3 -10
- package/dist/app.d.ts +3 -1
- package/dist/app.js +1 -0
- package/dist/automations/automations.service.js +4 -5
- package/dist/catalog/catalog-content.d.ts +6 -8
- package/dist/catalog/catalog-content.js +17 -22
- package/dist/catalog/catalog-items.d.ts +5 -10
- package/dist/catalog/catalog-items.js +27 -51
- package/dist/catalog/catalog-scope.service.d.ts +4 -2
- package/dist/catalog/catalog-scope.service.js +109 -145
- package/dist/catalog/catalog.module.js +7 -4
- package/dist/catalog/catalog.service.d.ts +10 -4
- package/dist/catalog/catalog.service.js +52 -10
- package/dist/catalog/cli.js +17 -0
- package/dist/catalog/component-promotion.js +8 -4
- package/dist/catalog/component-scope.service.d.ts +3 -1
- package/dist/catalog/component-scope.service.js +101 -140
- package/dist/catalog/component-state.d.ts +10 -8
- package/dist/catalog/component-state.js +42 -30
- package/dist/catalog/dependency-edges.d.ts +25 -0
- package/dist/catalog/dependency-edges.js +125 -0
- package/dist/catalog/effect-work.d.ts +27 -0
- package/dist/catalog/effect-work.js +151 -0
- package/dist/catalog/jobs.d.ts +4 -1
- package/dist/catalog/jobs.js +14 -4
- package/dist/catalog/org-catalog.service.d.ts +5 -1
- package/dist/catalog/org-catalog.service.js +101 -106
- package/dist/catalog/org-intent.d.ts +45 -0
- package/dist/catalog/org-intent.js +205 -0
- package/dist/catalog/owned-items.d.ts +6 -2
- package/dist/catalog/owned-items.js +27 -32
- package/dist/catalog/ownership.d.ts +2 -3
- package/dist/catalog/ownership.js +10 -28
- package/dist/catalog/platform-components.d.ts +3 -1
- package/dist/catalog/platform-components.js +9 -1
- package/dist/catalog/plugin-import.d.ts +4 -2
- package/dist/catalog/plugin-import.js +22 -21
- package/dist/catalog/plugin-install.d.ts +19 -54
- package/dist/catalog/plugin-install.js +221 -271
- package/dist/catalog/plugin-upgrade.d.ts +10 -5
- package/dist/catalog/plugin-upgrade.js +80 -67
- package/dist/catalog/request-rules.js +20 -8
- package/dist/catalog/scope-orgs.js +2 -7
- package/dist/catalog/scope-state.d.ts +6 -6
- package/dist/catalog/scope-state.js +24 -43
- package/dist/catalog/scope-sync-workers.d.ts +7 -11
- package/dist/catalog/scope-sync-workers.js +10 -26
- package/dist/catalog/scope-sync.d.ts +19 -116
- package/dist/catalog/scope-sync.js +228 -275
- package/dist/catalog/scope-writer.d.ts +87 -0
- package/dist/catalog/scope-writer.js +239 -0
- package/dist/catalog/template-connector-ensure.js +1 -1
- package/dist/catalog/unshare.js +9 -43
- package/dist/channels/connections.service.js +6 -6
- package/dist/channels/supervisor.js +3 -7
- package/dist/client/client-access.service.js +2 -12
- package/dist/config/schema.d.ts +6 -0
- package/dist/config/schema.js +32 -1
- package/dist/ctx/create-ctx.d.ts +2 -2
- package/dist/ctx/create-ctx.js +2 -60
- package/dist/ctx/guard-db.d.ts +6 -0
- package/dist/ctx/guard-db.js +55 -0
- package/dist/db/extension-handoff-schema.d.ts +1 -1
- package/dist/db/extension-handoff-schema.js +48 -10
- package/dist/db/extension-schema-transfer.js +5 -2
- package/dist/db/kernel-schema.d.ts +32 -6
- package/dist/device-access/host-services.d.ts +2 -2
- package/dist/device-access/host-services.js +5 -6
- package/dist/erasure/org-catalog.js +2 -2
- package/dist/erasure/org-rules.js +7 -0
- package/dist/extensions/admin-ops.d.ts +10 -6
- package/dist/extensions/admin-ops.js +53 -9
- package/dist/extensions/admin-view.d.ts +4 -1
- package/dist/extensions/admin-view.js +27 -14
- package/dist/extensions/bootstrap.d.ts +1 -1
- package/dist/extensions/bootstrap.js +6 -4
- package/dist/extensions/cli.js +1 -0
- package/dist/extensions/effective-config.js +1 -4
- package/dist/extensions/enabled.d.ts +183 -29
- package/dist/extensions/enabled.js +148 -62
- package/dist/extensions/host.d.ts +65 -45
- package/dist/extensions/host.js +446 -128
- package/dist/extensions/installs.d.ts +9 -0
- package/dist/extensions/installs.js +23 -0
- package/dist/extensions/isolated/admission.d.ts +10 -0
- package/dist/extensions/isolated/admission.js +206 -0
- package/dist/extensions/isolated/authorization.d.ts +45 -0
- package/dist/extensions/isolated/authorization.js +191 -0
- package/dist/extensions/isolated/broker.d.ts +15 -0
- package/dist/extensions/isolated/broker.js +471 -0
- package/dist/extensions/isolated/child-protocol.d.ts +84 -0
- package/dist/extensions/isolated/child-protocol.js +21 -0
- package/dist/extensions/isolated/child-registration.d.ts +22 -0
- package/dist/extensions/isolated/child-registration.js +152 -0
- package/dist/extensions/isolated/child-session.d.ts +6 -0
- package/dist/extensions/isolated/child-session.js +343 -0
- package/dist/extensions/isolated/child-streams.d.ts +4 -0
- package/dist/extensions/isolated/child-streams.js +142 -0
- package/dist/extensions/isolated/child.d.ts +1 -0
- package/dist/extensions/isolated/child.js +10 -0
- package/dist/extensions/isolated/configured-package.d.ts +15 -0
- package/dist/extensions/isolated/configured-package.js +73 -0
- package/dist/extensions/isolated/engine-binds.d.ts +9 -0
- package/dist/extensions/isolated/engine-binds.js +82 -0
- package/dist/extensions/isolated/engine-policy.d.ts +85 -0
- package/dist/extensions/isolated/engine-policy.js +75 -0
- package/dist/extensions/isolated/engine-proxy-main.d.ts +1 -0
- package/dist/extensions/isolated/engine-proxy-main.js +20 -0
- package/dist/extensions/isolated/engine-proxy.d.ts +7 -0
- package/dist/extensions/isolated/engine-proxy.js +408 -0
- package/dist/extensions/isolated/engine-vaults.d.ts +12 -0
- package/dist/extensions/isolated/engine-vaults.js +93 -0
- package/dist/extensions/isolated/lanes.d.ts +108 -0
- package/dist/extensions/isolated/lanes.js +726 -0
- package/dist/extensions/isolated/postgres-gate.d.ts +15 -0
- package/dist/extensions/isolated/postgres-gate.js +255 -0
- package/dist/extensions/isolated/revision.d.ts +32 -0
- package/dist/extensions/isolated/revision.js +359 -0
- package/dist/extensions/isolated/rpc-frame.d.ts +50 -0
- package/dist/extensions/isolated/rpc-frame.js +193 -0
- package/dist/extensions/isolated/rpc.d.ts +66 -0
- package/dist/extensions/isolated/rpc.js +314 -0
- package/dist/extensions/isolated/sandbox.d.ts +39 -0
- package/dist/extensions/isolated/sandbox.js +356 -0
- package/dist/extensions/isolated/tier.d.ts +6 -0
- package/dist/extensions/isolated/tier.js +45 -0
- package/dist/extensions/ledger.d.ts +1 -1
- package/dist/extensions/lifecycle-topics.d.ts +2 -0
- package/dist/extensions/lifecycle-topics.js +2 -0
- package/dist/extensions/lifecycle.d.ts +3 -1
- package/dist/extensions/lifecycle.js +53 -5
- package/dist/extensions/locks.d.ts +2 -0
- package/dist/extensions/locks.js +7 -0
- package/dist/extensions/org-config.d.ts +17 -27
- package/dist/extensions/org-config.js +114 -129
- package/dist/extensions/permission-view.d.ts +6 -1
- package/dist/extensions/plugin-guides.d.ts +5 -10
- package/dist/extensions/plugin-guides.js +18 -37
- package/dist/extensions/plugin-icons.d.ts +3 -21
- package/dist/extensions/plugin-icons.js +9 -44
- package/dist/extensions/plugin-items.d.ts +10 -30
- package/dist/extensions/plugin-items.js +32 -73
- package/dist/extensions/source-intent.d.ts +14 -0
- package/dist/extensions/source-intent.js +77 -0
- package/dist/inbox/platform-inbox.service.js +16 -27
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/infra/database/database.module.js +6 -1
- package/dist/infra/database/kernel-db.d.ts +3 -1
- package/dist/infra/database/kernel-db.js +4 -0
- package/dist/infra/events/kernel-events.d.ts +4 -0
- package/dist/infra/outbox/registry.d.ts +3 -36
- package/dist/infra/outbox/registry.js +4 -49
- package/dist/infra/paging/paged-read.d.ts +56 -0
- package/dist/infra/paging/paged-read.js +78 -0
- package/dist/infra/queue/queue-names.d.ts +1 -1
- package/dist/infra/queue/queue-names.js +1 -1
- package/dist/kernel.d.ts +3 -2
- package/dist/kernel.js +21 -2
- package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
- package/dist/lifecycle/kernel-lifecycle.js +22 -12
- package/dist/lifecycle/tokens.d.ts +8 -0
- package/dist/lifecycle/tokens.js +2 -0
- package/dist/orgs/directory-sync.js +1 -4
- package/dist/orgs/org-lock.d.ts +3 -1
- package/dist/orgs/org-lock.js +3 -1
- package/dist/orgs/orgs.service.d.ts +3 -1
- package/dist/orgs/orgs.service.js +15 -8
- package/dist/overrides.d.ts +0 -3
- package/dist/overrides.js +0 -2
- package/dist/platform/ops/admin.ops.js +14 -3
- package/dist/platform/ops/extensions-admin.ops.js +20 -3
- package/dist/platform/ops/org-plugins.ops.js +5 -2
- package/dist/platform/ops/orgs.ops.js +13 -3
- package/dist/platform/ops/plugins.ops.js +11 -10
- package/dist/setup/setup-checks.service.js +3 -2
- package/dist/skills/usable.js +41 -30
- package/dist/themes/theme-state.js +3 -3
- package/dist/tools/registry.d.ts +2 -2
- package/dist/tools/registry.js +7 -3
- package/package.json +2 -2
- package/src/migrations/0228_extension_org_switches.sql +56 -0
- package/src/migrations/0229_catalog_dependency_edges.sql +17 -0
- package/src/migrations/0230_audit_filter_idx.sql +18 -0
- package/src/migrations/0231_plugin_effect_work.sql +171 -0
- package/dist/catalog/install-status.d.ts +0 -6
- package/dist/catalog/install-status.js +0 -6
- package/dist/catalog/scope-jobs.d.ts +0 -59
- package/dist/catalog/scope-jobs.js +0 -78
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { SetupService } from "./admin/setup.service.js";
|
|
2
|
-
export { closeKernelApp, createKernelApp, type KernelAppOptions, kernelAppHttp, kernelAppPort, startKernelApp, } from "./app.js";
|
|
2
|
+
export { closeKernelApp, createKernelApp, KERNEL_FIXTURE_TRUST, type KernelAppOptions, kernelAppHttp, kernelAppPort, startKernelApp, } from "./app.js";
|
|
3
3
|
export { type CatalogCli, openCatalogCli } from "./catalog/cli.js";
|
|
4
4
|
export { GitSourceError, type ReadGitTreeOptions, readGitTree, } from "./catalog/git-source.js";
|
|
5
5
|
export type { PluginConfirmResult, PluginReview } from "./catalog/plugin-import.js";
|
|
@@ -21,6 +21,7 @@ export { createLock } from "./ctx/lock.js";
|
|
|
21
21
|
export { createQueue } from "./ctx/queue.js";
|
|
22
22
|
export { createKeyring, createSecrets, type DerivedKeys, type Keyring, REWRAP_BATCH_SIZE, type RewrapResult, rewrapToCurrentMasterKey, } from "./ctx/secrets.js";
|
|
23
23
|
export { extensionDbIdentity } from "./db/extension-db.js";
|
|
24
|
+
export { provisionExtensionHandoff } from "./db/extension-handoff-schema.js";
|
|
24
25
|
export { createProvisionedExtensionSchema, provisionExtensionRole, } from "./db/extension-role-provision.js";
|
|
25
26
|
export { type KernelDatabase, type KernelSchemaDb, kernelDb } from "./db/kernel-schema.js";
|
|
26
27
|
export { type MigrationOwner, migrate } from "./db/migrator.js";
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { SetupService } from "./admin/setup.service.js";
|
|
2
|
-
export { closeKernelApp, createKernelApp, kernelAppHttp, kernelAppPort, startKernelApp, } from "./app.js";
|
|
2
|
+
export { closeKernelApp, createKernelApp, KERNEL_FIXTURE_TRUST, kernelAppHttp, kernelAppPort, startKernelApp, } from "./app.js";
|
|
3
3
|
export { openCatalogCli } from "./catalog/cli.js";
|
|
4
4
|
// The git reader marketplaces use; core's check:bootstrap reads the official marketplace with it.
|
|
5
5
|
export { GitSourceError, readGitTree, } from "./catalog/git-source.js";
|
|
@@ -20,6 +20,7 @@ export { createLock } from "./ctx/lock.js";
|
|
|
20
20
|
export { createQueue } from "./ctx/queue.js";
|
|
21
21
|
export { createKeyring, createSecrets, REWRAP_BATCH_SIZE, rewrapToCurrentMasterKey, } from "./ctx/secrets.js";
|
|
22
22
|
export { extensionDbIdentity } from "./db/extension-db.js";
|
|
23
|
+
export { provisionExtensionHandoff } from "./db/extension-handoff-schema.js";
|
|
23
24
|
export { createProvisionedExtensionSchema, provisionExtensionRole, } from "./db/extension-role-provision.js";
|
|
24
25
|
export { kernelDb } from "./db/kernel-schema.js";
|
|
25
26
|
export { migrate } from "./db/migrator.js";
|
|
@@ -65,7 +65,12 @@ let DatabaseModule = class DatabaseModule {
|
|
|
65
65
|
inject: [KernelConfigService, KERNEL_LOGGER],
|
|
66
66
|
useFactory: (config, log) => {
|
|
67
67
|
const { db } = config.get();
|
|
68
|
-
|
|
68
|
+
// Set the runtime planner option in the startup packet. JIT compilation can dominate
|
|
69
|
+
// short queries with correlated permission checks.
|
|
70
|
+
const url = new URL(db.url);
|
|
71
|
+
const options = url.searchParams.get("options") ?? process.env.PGOPTIONS;
|
|
72
|
+
url.searchParams.set("options", options ? `${options} -c jit=off` : "-c jit=off");
|
|
73
|
+
return createDb(url.toString(), db.poolMax, (err) => log.error("pg idle client error", { err }), {
|
|
69
74
|
connectTimeoutMs: db.connectTimeoutMs,
|
|
70
75
|
idleTimeoutMs: db.idleTimeoutMs,
|
|
71
76
|
onClientError: (err) => log.warn("pg client error", { err }),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Kysely, Transaction } from "kysely";
|
|
2
|
-
import { type KernelDatabase } from "../../db/kernel-schema.js";
|
|
2
|
+
import { type KernelDatabase, type KernelSchemaDb } from "../../db/kernel-schema.js";
|
|
3
3
|
import { TransactionHost } from "./transaction-host.js";
|
|
4
4
|
type View = Kysely<KernelDatabase>;
|
|
5
5
|
/** The Kysely query entry points services use; each resolves to the context transaction or the pool. */
|
|
@@ -19,4 +19,6 @@ export declare class KernelDb {
|
|
|
19
19
|
/** The kernel-schema handle of the current context (transaction or pool). */
|
|
20
20
|
get db(): View | Transaction<KernelDatabase>;
|
|
21
21
|
}
|
|
22
|
+
/** Run a CLI migration backfill before the application and its transaction provider exist. */
|
|
23
|
+
export declare function runMigrationBackfill(pool: View, backfill: (db: KernelSchemaDb) => Promise<void>): Promise<void>;
|
|
22
24
|
export {};
|
|
@@ -63,3 +63,7 @@ Object.defineProperty(KernelDb.prototype, "fn", {
|
|
|
63
63
|
return this.db.fn;
|
|
64
64
|
},
|
|
65
65
|
});
|
|
66
|
+
/** Run a CLI migration backfill before the application and its transaction provider exist. */
|
|
67
|
+
export async function runMigrationBackfill(pool, backfill) {
|
|
68
|
+
await pool.transaction().execute((trx) => backfill(kernelDb(trx)));
|
|
69
|
+
}
|
|
@@ -21,6 +21,10 @@ export interface KernelEventMap {
|
|
|
21
21
|
orgId: string;
|
|
22
22
|
plugin: string;
|
|
23
23
|
};
|
|
24
|
+
/** A committed catalog write may have removed access through an org's dependency graph. */
|
|
25
|
+
"catalog.org-intent-changed": {
|
|
26
|
+
orgId?: string;
|
|
27
|
+
};
|
|
24
28
|
/**
|
|
25
29
|
* A person decided a tool call approval (after the commit, exactly once: only the decision that
|
|
26
30
|
* changed it from pending). The decision's transaction resumed the run and, for a conversation
|
|
@@ -401,44 +401,11 @@ export declare const OUTBOX_JOBS: {
|
|
|
401
401
|
readonly removeOnFail: true;
|
|
402
402
|
};
|
|
403
403
|
};
|
|
404
|
-
readonly "
|
|
405
|
-
readonly queue: "cap-kernel-plugin-
|
|
406
|
-
readonly idempotent: "
|
|
404
|
+
readonly "plugin-effect": {
|
|
405
|
+
readonly queue: "cap-kernel-plugin-effects";
|
|
406
|
+
readonly idempotent: "one organization lock and a pending generation check fence each effect; the recovery tick re-owes that generation";
|
|
407
407
|
readonly processedIn: "packages/kernel/src/catalog/scope-sync-workers.ts";
|
|
408
408
|
readonly opts: {
|
|
409
|
-
readonly attempts: 7;
|
|
410
|
-
readonly backoff: {
|
|
411
|
-
readonly type: "exponential";
|
|
412
|
-
readonly delay: 5000;
|
|
413
|
-
};
|
|
414
|
-
readonly removeOnComplete: true;
|
|
415
|
-
readonly removeOnFail: true;
|
|
416
|
-
};
|
|
417
|
-
};
|
|
418
|
-
readonly "scope-item-chunk": {
|
|
419
|
-
readonly queue: "cap-kernel-plugin-scope";
|
|
420
|
-
readonly idempotent: "the sync converges each (item, org) from the scope, switches and installs it reads under the org's lock, and the installer re-checks under the org row lock, so a second run changes nothing";
|
|
421
|
-
readonly processedIn: "packages/kernel/src/catalog/scope-sync-workers.ts";
|
|
422
|
-
readonly opts: {
|
|
423
|
-
readonly attempts: 7;
|
|
424
|
-
readonly backoff: {
|
|
425
|
-
readonly type: "exponential";
|
|
426
|
-
readonly delay: 5000;
|
|
427
|
-
};
|
|
428
|
-
readonly removeOnComplete: true;
|
|
429
|
-
readonly removeOnFail: true;
|
|
430
|
-
};
|
|
431
|
-
};
|
|
432
|
-
readonly "scope-org": {
|
|
433
|
-
readonly queue: "cap-kernel-plugin-scope";
|
|
434
|
-
readonly idempotent: "the sync converges each (item, org) of the org from what it reads, so a second run changes nothing";
|
|
435
|
-
readonly processedIn: "packages/kernel/src/catalog/scope-sync-workers.ts";
|
|
436
|
-
readonly opts: {
|
|
437
|
-
readonly attempts: 7;
|
|
438
|
-
readonly backoff: {
|
|
439
|
-
readonly type: "exponential";
|
|
440
|
-
readonly delay: 5000;
|
|
441
|
-
};
|
|
442
409
|
readonly removeOnComplete: true;
|
|
443
410
|
readonly removeOnFail: true;
|
|
444
411
|
};
|
|
@@ -1,21 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The plugin scope queue's one retry policy (`scope-item`, `scope-item-chunk`, `scope-org`): 7
|
|
3
|
-
* attempts, 5 s doubling, so the retries wait 5 + 10 + 20 + 40 + 80 + 160 = 315 s (about five
|
|
4
|
-
* minutes) before the last attempt. That is the window a replica has to load an extension its
|
|
5
|
-
* deploy enabled: the enable's `kernel.plugins.changed` message reconciles every replica at once,
|
|
6
|
-
* and if a replica misses it, its periodic reconcile does within
|
|
7
|
-
* `extensionHost.reconcileIntervalSeconds` (default 60 s). An interval longer than the window (it
|
|
8
|
-
* is not capped: tests set an hour to keep the periodic reconcile out of the way) leaves such a
|
|
9
|
-
* replica's chunk to its last attempt, which records `catalog.not_deployed` for the pair until the
|
|
10
|
-
* next sync of the item.
|
|
11
|
-
* Removed once done, so the next add of the same id is not swallowed.
|
|
12
|
-
*/
|
|
13
|
-
const SCOPE_JOB_OPTS = {
|
|
14
|
-
attempts: 7,
|
|
15
|
-
backoff: { type: "exponential", delay: 5_000 },
|
|
16
|
-
removeOnComplete: true,
|
|
17
|
-
removeOnFail: true,
|
|
18
|
-
};
|
|
19
1
|
/**
|
|
20
2
|
* The external conversation calls' retry policy: 10 attempts from 2 s, doubling (about 17 min in
|
|
21
3
|
* all) before the call is dropped with a failed turn; removed once done, so the same id owed again
|
|
@@ -361,38 +343,11 @@ export const OUTBOX_JOBS = {
|
|
|
361
343
|
removeOnFail: true,
|
|
362
344
|
},
|
|
363
345
|
},
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
// enabled one, an approval), under `scopeItemJobId` (one per owing transaction, spec §8.1)
|
|
368
|
-
"scope-item": {
|
|
369
|
-
queue: "cap-kernel-plugin-scope",
|
|
370
|
-
idempotent: "the fan-out owes the same chunk job ids again (`<item job id>-c<n>`), which the outbox and BullMQ dedupe, and each chunk converges from what it reads",
|
|
371
|
-
processedIn: "packages/kernel/src/catalog/scope-sync-workers.ts",
|
|
372
|
-
// the plugin scope queue's one retry policy (a PG or Redis blip); removed once done, so the
|
|
373
|
-
// next add of the same id is not swallowed
|
|
374
|
-
opts: SCOPE_JOB_OPTS,
|
|
375
|
-
},
|
|
376
|
-
// `catalog/scope-jobs.ts` SCOPE_CHUNK_JOB: owed by a scope-item job, one per chunk of orgs, under
|
|
377
|
-
// `scopeChunkJobId`
|
|
378
|
-
"scope-item-chunk": {
|
|
379
|
-
queue: "cap-kernel-plugin-scope",
|
|
380
|
-
idempotent: "the sync converges each (item, org) from the scope, switches and installs it reads under the org's lock, and the installer re-checks under the org row lock, so a second run changes nothing",
|
|
346
|
+
"plugin-effect": {
|
|
347
|
+
queue: "cap-kernel-plugin-effects",
|
|
348
|
+
idempotent: "one organization lock and a pending generation check fence each effect; the recovery tick re-owes that generation",
|
|
381
349
|
processedIn: "packages/kernel/src/catalog/scope-sync-workers.ts",
|
|
382
|
-
|
|
383
|
-
// after its other pairs, P3-38): 5 s doubling, about five minutes in all; the last attempt
|
|
384
|
-
// installs anyway and records what fails. A pair's own failure is recorded and does not fail
|
|
385
|
-
// the job; a retry of a deferred chunk attempts every pair again, a failed one included
|
|
386
|
-
// (idempotent: it converges from what it reads)
|
|
387
|
-
opts: SCOPE_JOB_OPTS,
|
|
388
|
-
},
|
|
389
|
-
// `catalog/scope-jobs.ts` SCOPE_ORG_JOB: owed by an org's creation, under `scopeOrgJobId`
|
|
390
|
-
"scope-org": {
|
|
391
|
-
queue: "cap-kernel-plugin-scope",
|
|
392
|
-
idempotent: "the sync converges each (item, org) of the org from what it reads, so a second run changes nothing",
|
|
393
|
-
processedIn: "packages/kernel/src/catalog/scope-sync-workers.ts",
|
|
394
|
-
// as a chunk job: retried while one of its items' extensions is not loaded on the replica
|
|
395
|
-
opts: SCOPE_JOB_OPTS,
|
|
350
|
+
opts: { removeOnComplete: true, removeOnFail: true },
|
|
396
351
|
},
|
|
397
352
|
// `automations/job-ids.ts` AUTOMATION_FIRE_JOB: owed by the transaction that writes a pending task run
|
|
398
353
|
// (the scan's tick, a person's "run now"), under `automationFireJobId` (spec §8.1)
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type SelectQueryBuilder } from "kysely";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import type { KernelSchemaDb } from "../../db/kernel-schema.js";
|
|
4
|
+
/**
|
|
5
|
+
* Page-number reads on a snapshot (table pagination spec §2.3): a paged route takes `page`,
|
|
6
|
+
* `size`, its filters and an optional `asOf`, and answers {@link Paged}. Shared by every route a
|
|
7
|
+
* DataTable pages on the server; the snapshot key (`asOf`) is the route's own (an append-only
|
|
8
|
+
* table uses its id, a sortable table its `(sort column, id)`).
|
|
9
|
+
*/
|
|
10
|
+
/** The page sizes a table offers (the Pagination select). */
|
|
11
|
+
export declare const PAGE_SIZES: readonly [20, 50, 100];
|
|
12
|
+
/** `total` stops counting here; above it `totalCapped` is true and pages past it are refused. */
|
|
13
|
+
export declare const PAGED_TOTAL_CAP = 10000;
|
|
14
|
+
/** `newer` stops counting here. */
|
|
15
|
+
export declare const PAGED_NEWER_CAP = 1000;
|
|
16
|
+
/** One page of a paged route (spec §2.3). */
|
|
17
|
+
export interface Paged<T> {
|
|
18
|
+
items: T[];
|
|
19
|
+
/** The page read, 1-based. */
|
|
20
|
+
page: number;
|
|
21
|
+
/** Rows per page: 20, 50 or 100. */
|
|
22
|
+
size: number;
|
|
23
|
+
/** The matching rows under the snapshot, at most {@link PAGED_TOTAL_CAP}. */
|
|
24
|
+
total: number;
|
|
25
|
+
/** More rows match than `total` says. */
|
|
26
|
+
totalCapped: boolean;
|
|
27
|
+
/** The snapshot key: pass it back to read the other pages of the same snapshot. */
|
|
28
|
+
asOf: string;
|
|
29
|
+
/** Rows above `asOf` matching the filters, at most {@link PAGED_NEWER_CAP}; 0 without `asOf`. */
|
|
30
|
+
newer: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The query fields every paged route takes (spec §2.3), to `extend` a route's filters with. `asOf`
|
|
34
|
+
* is the route's own (its snapshot key format), e.g. {@link bigserialAsOf}.
|
|
35
|
+
*/
|
|
36
|
+
export declare const PageQueryFields: {
|
|
37
|
+
page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
38
|
+
size: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
39
|
+
};
|
|
40
|
+
/** An `asOf` that is a bigserial id (a decimal string), for append-only tables keyed by id. */
|
|
41
|
+
export declare function bigserialAsOf(what: string): z.ZodOptional<z.ZodString>;
|
|
42
|
+
/** The last page a size may read: pages past the counting cap are refused. */
|
|
43
|
+
export declare const lastReadablePage: (size: number) => number;
|
|
44
|
+
/** Refuses a page past {@link lastReadablePage} (400 `validation_failed`, spec §2.3). */
|
|
45
|
+
export declare function assertReadablePage(page: number, size: number): void;
|
|
46
|
+
/** `OFFSET` of a page. */
|
|
47
|
+
export declare const pageOffset: (page: number, size: number) => number;
|
|
48
|
+
/**
|
|
49
|
+
* `count(*)` of the rows `query` matches, stopped after `cap` (`SELECT count(*) FROM (… LIMIT
|
|
50
|
+
* cap + 1)`): above `cap` it answers `cap` and `capped` true. `query` is a filtered select whose
|
|
51
|
+
* selection and order are replaced.
|
|
52
|
+
*/
|
|
53
|
+
export declare function cappedCount(db: KernelSchemaDb, query: SelectQueryBuilder<any, any, any>, cap: number): Promise<{
|
|
54
|
+
count: number;
|
|
55
|
+
capped: boolean;
|
|
56
|
+
}>;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { sql } from "kysely";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { ApiError } from "../../errors.js";
|
|
4
|
+
/**
|
|
5
|
+
* Page-number reads on a snapshot (table pagination spec §2.3): a paged route takes `page`,
|
|
6
|
+
* `size`, its filters and an optional `asOf`, and answers {@link Paged}. Shared by every route a
|
|
7
|
+
* DataTable pages on the server; the snapshot key (`asOf`) is the route's own (an append-only
|
|
8
|
+
* table uses its id, a sortable table its `(sort column, id)`).
|
|
9
|
+
*/
|
|
10
|
+
/** The page sizes a table offers (the Pagination select). */
|
|
11
|
+
export const PAGE_SIZES = [20, 50, 100];
|
|
12
|
+
/** `total` stops counting here; above it `totalCapped` is true and pages past it are refused. */
|
|
13
|
+
export const PAGED_TOTAL_CAP = 10_000;
|
|
14
|
+
/** `newer` stops counting here. */
|
|
15
|
+
export const PAGED_NEWER_CAP = 1_000;
|
|
16
|
+
/**
|
|
17
|
+
* The query fields every paged route takes (spec §2.3), to `extend` a route's filters with. `asOf`
|
|
18
|
+
* is the route's own (its snapshot key format), e.g. {@link bigserialAsOf}.
|
|
19
|
+
*/
|
|
20
|
+
export const PageQueryFields = {
|
|
21
|
+
page: z.coerce
|
|
22
|
+
.number()
|
|
23
|
+
.int()
|
|
24
|
+
.min(1)
|
|
25
|
+
// the upper bound depends on size: assertReadablePage refuses it with the one message
|
|
26
|
+
.default(1)
|
|
27
|
+
.describe("The page to read, 1-based (default 1)."),
|
|
28
|
+
size: z.coerce
|
|
29
|
+
.number()
|
|
30
|
+
.int()
|
|
31
|
+
.refine((v) => PAGE_SIZES.includes(v), "size must be 20, 50 or 100")
|
|
32
|
+
.default(PAGE_SIZES[0])
|
|
33
|
+
.describe("Rows per page: 20, 50 or 100 (default 20)."),
|
|
34
|
+
};
|
|
35
|
+
/** The largest `bigserial` id; a larger key would make PG refuse the comparison. */
|
|
36
|
+
const MAX_BIGINT = 9223372036854775807n;
|
|
37
|
+
/** An `asOf` that is a bigserial id (a decimal string), for append-only tables keyed by id. */
|
|
38
|
+
export function bigserialAsOf(what) {
|
|
39
|
+
return (z
|
|
40
|
+
.string()
|
|
41
|
+
.regex(/^\d{1,19}$/, `asOf must be ${what} (digits)`)
|
|
42
|
+
// checks do not abort: only digits reach BigInt
|
|
43
|
+
.refine((v) => !/^\d{1,19}$/.test(v) || BigInt(v) <= MAX_BIGINT, `asOf must be ${what}`)
|
|
44
|
+
.optional()
|
|
45
|
+
.describe(`The snapshot: the asOf an earlier page returned (${what}); absent: a new snapshot of the newest rows.`));
|
|
46
|
+
}
|
|
47
|
+
/** The last page a size may read: pages past the counting cap are refused. */
|
|
48
|
+
export const lastReadablePage = (size) => Math.ceil(PAGED_TOTAL_CAP / size);
|
|
49
|
+
/** Refuses a page past {@link lastReadablePage} (400 `validation_failed`, spec §2.3). */
|
|
50
|
+
export function assertReadablePage(page, size) {
|
|
51
|
+
const last = lastReadablePage(size);
|
|
52
|
+
if (page > last) {
|
|
53
|
+
throw new ApiError("validation_failed", `Page ${page} is past the last readable page (${last} at size ${size}, the first ${PAGED_TOTAL_CAP} rows); narrow the filters to reach older rows`, [{ path: "page", message: `page must be at most ${last} for size ${size}` }]);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** `OFFSET` of a page. */
|
|
57
|
+
export const pageOffset = (page, size) => (page - 1) * size;
|
|
58
|
+
/**
|
|
59
|
+
* `count(*)` of the rows `query` matches, stopped after `cap` (`SELECT count(*) FROM (… LIMIT
|
|
60
|
+
* cap + 1)`): above `cap` it answers `cap` and `capped` true. `query` is a filtered select whose
|
|
61
|
+
* selection and order are replaced.
|
|
62
|
+
*/
|
|
63
|
+
export async function cappedCount(db,
|
|
64
|
+
// biome-ignore lint/suspicious/noExplicitAny: any table, any filters
|
|
65
|
+
query, cap) {
|
|
66
|
+
const limited = query
|
|
67
|
+
.clearSelect()
|
|
68
|
+
.clearOrderBy()
|
|
69
|
+
.select(sql `1`.as("one"))
|
|
70
|
+
.limit(cap + 1)
|
|
71
|
+
.as("capped");
|
|
72
|
+
const row = await db
|
|
73
|
+
.selectFrom(limited)
|
|
74
|
+
.select(sql `count(*)`.as("n"))
|
|
75
|
+
.executeTakeFirstOrThrow();
|
|
76
|
+
const n = Number(row.n);
|
|
77
|
+
return n > cap ? { count: cap, capped: true } : { count: n, capped: false };
|
|
78
|
+
}
|
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
* (admin/health.service.ts) lists the same names from the feature constants;
|
|
5
5
|
* test/infra/queue-names.test.ts keeps the two equal.
|
|
6
6
|
*/
|
|
7
|
-
export declare const KERNEL_QUEUES: readonly ["cap-kernel-runs", "cap-kernel-subagent-runs", "cap-kernel-channels", "cap-kernel-maintenance", "cap-kernel-tool-watch", "cap-kernel-plugin-
|
|
7
|
+
export declare const KERNEL_QUEUES: readonly ["cap-kernel-runs", "cap-kernel-subagent-runs", "cap-kernel-channels", "cap-kernel-maintenance", "cap-kernel-tool-watch", "cap-kernel-plugin-effects", "cap-kernel-titles", "cap-kernel-suggestions", "cap-kernel-usage-report", "cap-kernel-evals", "cap-kernel-lifecycle", "cap-push-deliver", "cap-connector-tools", "cap-template-connectors", "cap-device-service-events", "cap-external-calls"];
|
|
8
8
|
export type KernelQueueName = (typeof KERNEL_QUEUES)[number];
|
package/dist/kernel.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { QueryExecutorProvider } from "kysely";
|
|
2
2
|
import type { KernelConfig } from "./config/schema.js";
|
|
3
3
|
import type { PendingExtension } from "./extensions/approvals.js";
|
|
4
|
+
import { type KernelFixtureTrust } from "./lifecycle/tokens.js";
|
|
4
5
|
/**
|
|
5
6
|
* The kernel migrations directory. `src/` and `dist/` are both one level below the package root,
|
|
6
7
|
* so this always points at `<package root>/src/migrations`: running from source with tsx and
|
|
@@ -11,7 +12,7 @@ export declare const KERNEL_MIGRATIONS_DIR: string;
|
|
|
11
12
|
/** The kernel's PG schema. */
|
|
12
13
|
export declare const KERNEL_SCHEMA = "capybara";
|
|
13
14
|
/** Static names of config-declared extensions, for deployment and fixture provisioning. */
|
|
14
|
-
export declare function declaredExtensionNames(specifiers: string[], resolveFrom?: string): Promise<Set<string>>;
|
|
15
|
+
export declare function declaredExtensionNames(specifiers: string[], resolveFrom?: string, fixtures?: KernelFixtureTrust): Promise<Set<string>>;
|
|
15
16
|
/** Only a login with migration privileges can initialize the kernel schema at startup. */
|
|
16
17
|
export declare function prepareKernelDatabase(db: KernelConfig["db"], opts?: {
|
|
17
18
|
pool?: QueryExecutorProvider;
|
|
@@ -22,7 +23,7 @@ export declare function prepareKernelDatabase(db: KernelConfig["db"], opts?: {
|
|
|
22
23
|
* Redis connection). Extensions whose permissions await approval are not migrated (unless
|
|
23
24
|
* `extensionPermissions.autoApprove`); they are reported through `opts.onPending`.
|
|
24
25
|
*/
|
|
25
|
-
export declare function migrateAll(config: KernelConfig, opts?: {
|
|
26
|
+
export declare function migrateAll(config: KernelConfig, opts?: KernelFixtureTrust & {
|
|
26
27
|
resolveFrom?: string;
|
|
27
28
|
onPending?: (pending: PendingExtension[]) => void;
|
|
28
29
|
}): Promise<{
|
package/dist/kernel.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { fileURLToPath } from "node:url";
|
|
2
|
+
import { initializeCatalogDependencyEdges } from "./catalog/dependency-edges.js";
|
|
2
3
|
import { extensionDbIdentity, validateExtensionCredentials } from "./db/extension-db.js";
|
|
3
4
|
import { canMigrateKernel, migrate, verifyMigrations } from "./db/migrator.js";
|
|
4
5
|
import { createDb } from "./db/pool.js";
|
|
5
6
|
import { ExtensionHost } from "./extensions/host.js";
|
|
7
|
+
import { runMigrationBackfill } from "./infra/database/kernel-db.js";
|
|
8
|
+
import { KERNEL_FIXTURE_TRUST } from "./lifecycle/tokens.js";
|
|
6
9
|
/**
|
|
7
10
|
* The kernel migrations directory. `src/` and `dist/` are both one level below the package root,
|
|
8
11
|
* so this always points at `<package root>/src/migrations`: running from source with tsx and
|
|
@@ -13,8 +16,11 @@ export const KERNEL_MIGRATIONS_DIR = fileURLToPath(new URL("../src/migrations/",
|
|
|
13
16
|
/** The kernel's PG schema. */
|
|
14
17
|
export const KERNEL_SCHEMA = "capybara";
|
|
15
18
|
/** Static names of config-declared extensions, for deployment and fixture provisioning. */
|
|
16
|
-
export function declaredExtensionNames(specifiers, resolveFrom) {
|
|
17
|
-
return ExtensionHost.declaredNames(specifiers,
|
|
19
|
+
export function declaredExtensionNames(specifiers, resolveFrom, fixtures = {}) {
|
|
20
|
+
return ExtensionHost.declaredNames(specifiers, {
|
|
21
|
+
...(resolveFrom !== undefined && { resolveFrom }),
|
|
22
|
+
...fixtures,
|
|
23
|
+
});
|
|
18
24
|
}
|
|
19
25
|
const coreMigrations = { schema: KERNEL_SCHEMA, dir: KERNEL_MIGRATIONS_DIR };
|
|
20
26
|
/** Only a login with migration privileges can initialize the kernel schema at startup. */
|
|
@@ -58,13 +64,26 @@ export async function migrateAll(config, opts = {}) {
|
|
|
58
64
|
const kernel = await migrate(config.db.migrationUrl ?? config.db.url, coreMigrations, {
|
|
59
65
|
connectTimeoutMs,
|
|
60
66
|
});
|
|
67
|
+
const pool = createDb(config.db.migrationUrl ?? config.db.url, 1, undefined, {
|
|
68
|
+
connectTimeoutMs,
|
|
69
|
+
});
|
|
70
|
+
try {
|
|
71
|
+
await runMigrationBackfill(pool, initializeCatalogDependencyEdges);
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
await pool.destroy();
|
|
75
|
+
}
|
|
61
76
|
const plugins = await ExtensionHost.migrateOnly(config.extensions, {
|
|
77
|
+
...(opts[KERNEL_FIXTURE_TRUST] && { [KERNEL_FIXTURE_TRUST]: true }),
|
|
62
78
|
dbUrl: config.db.url,
|
|
63
79
|
...(config.db.extensionsUrl !== undefined && {
|
|
64
80
|
extensionIdentity: extensionDbIdentity(config.db),
|
|
65
81
|
extensionProvisioning: config.db,
|
|
66
82
|
}),
|
|
67
83
|
connectTimeoutMs,
|
|
84
|
+
migrationTimeoutMs: config.extensionHost.migrationTimeoutSeconds * 1000,
|
|
85
|
+
packageCacheDir: config.extensionHost.dir,
|
|
86
|
+
maxPackageBytes: config.packages.maxBytes,
|
|
68
87
|
autoApprove: config.extensionPermissions.autoApprove,
|
|
69
88
|
...(opts.resolveFrom !== undefined && { resolveFrom: opts.resolveFrom }),
|
|
70
89
|
...(opts.onPending !== undefined && { onPending: opts.onPending }),
|
|
@@ -4,6 +4,7 @@ import type { Redis } from "ioredis";
|
|
|
4
4
|
import { type Kysely } from "kysely";
|
|
5
5
|
import type { KernelAppOptions } from "../app.js";
|
|
6
6
|
import { MarketplacesService } from "../catalog/marketplaces.service.js";
|
|
7
|
+
import { PlatformComponents } from "../catalog/platform-components.js";
|
|
7
8
|
import { PluginImport } from "../catalog/plugin-import.js";
|
|
8
9
|
import { PlatformPluginUpdater } from "../catalog/plugin-upgrade.js";
|
|
9
10
|
import { ChannelJobs } from "../channels/jobs.js";
|
|
@@ -88,6 +89,7 @@ export declare class KernelLifecycle implements OnApplicationBootstrap, BeforeAp
|
|
|
88
89
|
private readonly marketplaces;
|
|
89
90
|
private readonly pluginImport;
|
|
90
91
|
private readonly pluginUpdater;
|
|
92
|
+
private readonly platformComponents;
|
|
91
93
|
private readonly bus;
|
|
92
94
|
private readonly usageReport;
|
|
93
95
|
private readonly titles;
|
|
@@ -113,7 +115,7 @@ export declare class KernelLifecycle implements OnApplicationBootstrap, BeforeAp
|
|
|
113
115
|
private bootstrapPackages;
|
|
114
116
|
/** The merged bootstrap manifest, read once per start. */
|
|
115
117
|
private mergedManifest;
|
|
116
|
-
constructor(permissionConfig: PermissionConfigPublication, accounts: AccountsService, configService: KernelConfigService, log: KernelLogger, options: KernelAppOptions, pool: Kysely<any>, redis: Redis, kdb: KernelDb, shutdown: GracefulShutdown, host: ExtensionHost, extensionDbIdentity: ExtensionDbIdentity, registry: ExtensionRegistry, installs: ExtensionInstalls, blobs: ExtensionBlobs, extensionLifecycle: ExtensionLifecycle, replicaStatus: ReplicaStatusStore, bootstrap: BootstrapService, bootstrapDefaults: BootstrapDefaultsService, marketplaces: MarketplacesService, pluginImport: PluginImport, pluginUpdater: PlatformPluginUpdater, bus: Pick<ExtensionContext["bus"], "publish" | "subscribe">, usageReport: UsageReporter, titles: TitleQueue, suggestions: PromptSuggestionQueue, channelJobs: ChannelJobs, channelOutbound: ChannelOutbound, presence: ReplicaPresence, worker?: WorkerRole | undefined, gateway?: GatewayRole | undefined);
|
|
118
|
+
constructor(permissionConfig: PermissionConfigPublication, accounts: AccountsService, configService: KernelConfigService, log: KernelLogger, options: KernelAppOptions, pool: Kysely<any>, redis: Redis, kdb: KernelDb, shutdown: GracefulShutdown, host: ExtensionHost, extensionDbIdentity: ExtensionDbIdentity, registry: ExtensionRegistry, installs: ExtensionInstalls, blobs: ExtensionBlobs, extensionLifecycle: ExtensionLifecycle, replicaStatus: ReplicaStatusStore, bootstrap: BootstrapService, bootstrapDefaults: BootstrapDefaultsService, marketplaces: MarketplacesService, pluginImport: PluginImport, pluginUpdater: PlatformPluginUpdater, platformComponents: PlatformComponents, bus: Pick<ExtensionContext["bus"], "publish" | "subscribe">, usageReport: UsageReporter, titles: TitleQueue, suggestions: PromptSuggestionQueue, channelJobs: ChannelJobs, channelOutbound: ChannelOutbound, presence: ReplicaPresence, worker?: WorkerRole | undefined, gateway?: GatewayRole | undefined);
|
|
117
119
|
/** The kernel HTTP application (set up by `buildKernelApp` before `init()`). */
|
|
118
120
|
get http(): KernelHttpApp;
|
|
119
121
|
attachHttp(http: KernelHttpApp): void;
|
|
@@ -11,6 +11,7 @@ import { DEVICE_PROVIDER_EXTENSION_POINT } from "@capybara-hq/plugin-sdk";
|
|
|
11
11
|
import { Inject, Injectable, Optional, } from "@nestjs/common";
|
|
12
12
|
import { sql } from "kysely";
|
|
13
13
|
import { MarketplacesService } from "../catalog/marketplaces.service.js";
|
|
14
|
+
import { PlatformComponents } from "../catalog/platform-components.js";
|
|
14
15
|
import { PluginImport } from "../catalog/plugin-import.js";
|
|
15
16
|
import { PlatformPluginUpdater } from "../catalog/plugin-upgrade.js";
|
|
16
17
|
import { ChannelJobs } from "../channels/jobs.js";
|
|
@@ -24,6 +25,7 @@ import { BootstrapDefaultsService } from "../extensions/bootstrap-defaults.js";
|
|
|
24
25
|
import { BootstrapExtraMismatchError, hasExtraManifestTraces, loadBootstrapManifest, missingExtraManifestMessage, syncExtraMarketplaces, } from "../extensions/bootstrap-extra.js";
|
|
25
26
|
import { ExtensionHost } from "../extensions/host.js";
|
|
26
27
|
import { ExtensionInstalls } from "../extensions/installs.js";
|
|
28
|
+
import { installedExtensionTier } from "../extensions/isolated/tier.js";
|
|
27
29
|
import { ExtensionLifecycle } from "../extensions/lifecycle.js";
|
|
28
30
|
import { ensureMigrated } from "../extensions/migrate-lock.js";
|
|
29
31
|
import { ExtensionRegistry } from "../extensions/registry.js";
|
|
@@ -45,7 +47,7 @@ import { WorkerRole } from "../roles/worker-role.js";
|
|
|
45
47
|
import { UsageReporter } from "../runtime/usage-report.js";
|
|
46
48
|
import { PermissionConfigPublication } from "../sandbox/permission-config-publication.js";
|
|
47
49
|
import { sandboxConfigWarnings } from "../sandbox/sandbox.service.js";
|
|
48
|
-
import { KERNEL_APP_OPTIONS } from "./tokens.js";
|
|
50
|
+
import { KERNEL_APP_OPTIONS, KERNEL_FIXTURE_TRUST } from "./tokens.js";
|
|
49
51
|
/**
|
|
50
52
|
* The stop phase budgets. Each phase waits `min(its budget, what is left of the total)`, where the
|
|
51
53
|
* total is `STOP_TIMEOUT_MS` (30 s, `GracefulShutdown`) counted from the moment the shutdown
|
|
@@ -110,6 +112,7 @@ let KernelLifecycle = class KernelLifecycle {
|
|
|
110
112
|
marketplaces;
|
|
111
113
|
pluginImport;
|
|
112
114
|
pluginUpdater;
|
|
115
|
+
platformComponents;
|
|
113
116
|
bus;
|
|
114
117
|
usageReport;
|
|
115
118
|
titles;
|
|
@@ -137,7 +140,7 @@ let KernelLifecycle = class KernelLifecycle {
|
|
|
137
140
|
mergedManifest;
|
|
138
141
|
constructor(permissionConfig, accounts, configService, log, options,
|
|
139
142
|
// biome-ignore lint/suspicious/noExplicitAny: the pool carries no schema types
|
|
140
|
-
pool, redis, kdb, shutdown, host, extensionDbIdentity, registry, installs, blobs, extensionLifecycle, replicaStatus, bootstrap, bootstrapDefaults, marketplaces, pluginImport, pluginUpdater, bus,
|
|
143
|
+
pool, redis, kdb, shutdown, host, extensionDbIdentity, registry, installs, blobs, extensionLifecycle, replicaStatus, bootstrap, bootstrapDefaults, marketplaces, pluginImport, pluginUpdater, platformComponents, bus,
|
|
141
144
|
// the producers closed on every role (their consumers are the worker role's)
|
|
142
145
|
usageReport, titles, suggestions, channelJobs, channelOutbound,
|
|
143
146
|
// this process's presence beat, on every role (admin overview spec §5.1)
|
|
@@ -166,6 +169,7 @@ let KernelLifecycle = class KernelLifecycle {
|
|
|
166
169
|
this.marketplaces = marketplaces;
|
|
167
170
|
this.pluginImport = pluginImport;
|
|
168
171
|
this.pluginUpdater = pluginUpdater;
|
|
172
|
+
this.platformComponents = platformComponents;
|
|
169
173
|
this.bus = bus;
|
|
170
174
|
this.usageReport = usageReport;
|
|
171
175
|
this.titles = titles;
|
|
@@ -234,6 +238,8 @@ let KernelLifecycle = class KernelLifecycle {
|
|
|
234
238
|
// In flight for the stop: aborted when the shutdown begins, which then waits for its session to end
|
|
235
239
|
await this.shutdown.trackInFlight(prepareKernelDatabase(config.db, { pool: this.pool, signal: this.shutdown.signal }));
|
|
236
240
|
this.checkpoint();
|
|
241
|
+
await this.shutdown.trackInFlight(this.platformComponents.initializeDependencyEdges());
|
|
242
|
+
this.checkpoint();
|
|
237
243
|
const publication = await this.shutdown.trackInFlight(this.permissionConfig.initialize({
|
|
238
244
|
...(opts.permissionConfigActivation !== undefined && {
|
|
239
245
|
activation: opts.permissionConfigActivation,
|
|
@@ -277,6 +283,8 @@ let KernelLifecycle = class KernelLifecycle {
|
|
|
277
283
|
// `lock:bootstrap`); a bootstrap entry named like a config-declared extension is kept
|
|
278
284
|
if (opts.bootstrap !== undefined) {
|
|
279
285
|
this.registry.declare(await ExtensionHost.declaredNames(config.extensions, {
|
|
286
|
+
maxPackageBytes: config.packages.maxBytes,
|
|
287
|
+
...(opts[KERNEL_FIXTURE_TRUST] && { [KERNEL_FIXTURE_TRUST]: true }),
|
|
280
288
|
...(opts.resolveFrom !== undefined && { resolveFrom: opts.resolveFrom }),
|
|
281
289
|
}));
|
|
282
290
|
}
|
|
@@ -288,6 +296,7 @@ let KernelLifecycle = class KernelLifecycle {
|
|
|
288
296
|
config: config.extensions,
|
|
289
297
|
installs: {
|
|
290
298
|
desired: () => this.installs.desired(),
|
|
299
|
+
tier: (d, verifyBytes) => installedExtensionTier(d, () => this.manifest(), this.blobs, verifyBytes),
|
|
291
300
|
sync: (d) => syncPackage(cfg().extensionHost.dir, d.name, d.sha256, this.blobs, {
|
|
292
301
|
maxBytes: cfg().packages.maxBytes,
|
|
293
302
|
}),
|
|
@@ -586,16 +595,17 @@ KernelLifecycle = __decorate([
|
|
|
586
595
|
__param(18, Inject(MarketplacesService)),
|
|
587
596
|
__param(19, Inject(PluginImport)),
|
|
588
597
|
__param(20, Inject(PlatformPluginUpdater)),
|
|
589
|
-
__param(21, Inject(
|
|
590
|
-
__param(22, Inject(
|
|
591
|
-
__param(23, Inject(
|
|
592
|
-
__param(24, Inject(
|
|
593
|
-
__param(25, Inject(
|
|
594
|
-
__param(26, Inject(
|
|
595
|
-
__param(27, Inject(
|
|
596
|
-
__param(28,
|
|
597
|
-
__param(28, Inject(WorkerRole)),
|
|
598
|
+
__param(21, Inject(PlatformComponents)),
|
|
599
|
+
__param(22, Inject(KERNEL_BUS)),
|
|
600
|
+
__param(23, Inject(UsageReporter)),
|
|
601
|
+
__param(24, Inject(TitleQueue)),
|
|
602
|
+
__param(25, Inject(PromptSuggestionQueue)),
|
|
603
|
+
__param(26, Inject(ChannelJobs)),
|
|
604
|
+
__param(27, Inject(ChannelOutbound)),
|
|
605
|
+
__param(28, Inject(ReplicaPresence)),
|
|
598
606
|
__param(29, Optional()),
|
|
599
|
-
__param(29, Inject(
|
|
607
|
+
__param(29, Inject(WorkerRole)),
|
|
608
|
+
__param(30, Optional()),
|
|
609
|
+
__param(30, Inject(GatewayRole))
|
|
600
610
|
], KernelLifecycle);
|
|
601
611
|
export { KernelLifecycle };
|
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
/** Injection tokens of the kernel application (`KernelModule`) itself. */
|
|
2
2
|
/** The `KernelAppOptions` the application was built with. */
|
|
3
3
|
export declare const KERNEL_APP_OPTIONS: unique symbol;
|
|
4
|
+
/** Internal switch for vetted repository test fixtures. It has no config or CLI representation. */
|
|
5
|
+
export declare const KERNEL_FIXTURE_TRUST: unique symbol;
|
|
6
|
+
export type KernelFixtureTrust = {
|
|
7
|
+
readonly [KERNEL_FIXTURE_TRUST]?: true | {
|
|
8
|
+
config: true;
|
|
9
|
+
installDigests: readonly string[];
|
|
10
|
+
};
|
|
11
|
+
};
|
package/dist/lifecycle/tokens.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
/** Injection tokens of the kernel application (`KernelModule`) itself. */
|
|
2
2
|
/** The `KernelAppOptions` the application was built with. */
|
|
3
3
|
export const KERNEL_APP_OPTIONS = Symbol("KERNEL_APP_OPTIONS");
|
|
4
|
+
/** Internal switch for vetted repository test fixtures. It has no config or CLI representation. */
|
|
5
|
+
export const KERNEL_FIXTURE_TRUST = Symbol("KERNEL_FIXTURE_TRUST");
|
|
@@ -299,11 +299,8 @@ let DirectorySync = class DirectorySync {
|
|
|
299
299
|
return [];
|
|
300
300
|
// org-filter: deployment-wide discovery of enabled directories, with each target checked in its org
|
|
301
301
|
const rows = await asPlatform("find the orgs with an enabled directory", () => this.db
|
|
302
|
-
.selectFrom(enabledExtensionsByOrg(this.db.db).as("en"))
|
|
303
|
-
.innerJoin("orgs", "orgs.id", "en.org_id")
|
|
302
|
+
.selectFrom(enabledExtensionsByOrg(this.db.db, plugins).as("en"))
|
|
304
303
|
.select(["en.org_id", "en.plugin"])
|
|
305
|
-
.where("orgs.deleted_at", "is", null)
|
|
306
|
-
.where("en.plugin", "in", plugins)
|
|
307
304
|
.orderBy("en.org_id")
|
|
308
305
|
.orderBy("en.plugin")
|
|
309
306
|
.execute());
|
package/dist/orgs/org-lock.d.ts
CHANGED
|
@@ -19,7 +19,9 @@ export interface LockedOrg {
|
|
|
19
19
|
* log append (a conversation row, then the org foreign key check). Nothing takes the org row
|
|
20
20
|
* `FOR UPDATE`: org deletion's `deleted_at` update is a no-key update too.
|
|
21
21
|
*
|
|
22
|
-
* The global lock order
|
|
22
|
+
* The global lock order starts with `EFFECT_CANDIDATES_LOCK` when needed. It serializes org
|
|
23
|
+
* creation and deletion with plugin import commits and other writes that change effect
|
|
24
|
+
* candidates. Then take the org admission lock ({@link lockForRemoval}; the run fence's shared
|
|
23
25
|
* admission, `RunExecution`) → this org row lock (also the run fence's exclusive admission) → a
|
|
24
26
|
* membership row → a device row (`DevicesService.lockOwn`, the device project writes, the cloud
|
|
25
27
|
* permission snapshot) → the super admin advisory lock (`SuperAdminLock`) → the permission
|
package/dist/orgs/org-lock.js
CHANGED
|
@@ -26,7 +26,9 @@ import { can } from "./roles.js";
|
|
|
26
26
|
* log append (a conversation row, then the org foreign key check). Nothing takes the org row
|
|
27
27
|
* `FOR UPDATE`: org deletion's `deleted_at` update is a no-key update too.
|
|
28
28
|
*
|
|
29
|
-
* The global lock order
|
|
29
|
+
* The global lock order starts with `EFFECT_CANDIDATES_LOCK` when needed. It serializes org
|
|
30
|
+
* creation and deletion with plugin import commits and other writes that change effect
|
|
31
|
+
* candidates. Then take the org admission lock ({@link lockForRemoval}; the run fence's shared
|
|
30
32
|
* admission, `RunExecution`) → this org row lock (also the run fence's exclusive admission) → a
|
|
31
33
|
* membership row → a device row (`DevicesService.lockOwn`, the device project writes, the cloud
|
|
32
34
|
* permission snapshot) → the super admin advisory lock (`SuperAdminLock`) → the permission
|