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

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 (101) hide show
  1. package/bootstrap.json +31 -31
  2. package/dist/admin/extensions.controller.d.ts +5 -2
  3. package/dist/admin/extensions.controller.js +10 -1
  4. package/dist/admin/extensions.schemas.d.ts +4 -0
  5. package/dist/admin/extensions.schemas.js +9 -0
  6. package/dist/admin/health.service.d.ts +1 -1
  7. package/dist/admin/health.service.js +3 -3
  8. package/dist/catalog/catalog-content.d.ts +5 -7
  9. package/dist/catalog/catalog-items.js +1 -1
  10. package/dist/catalog/catalog-scope.service.js +5 -5
  11. package/dist/catalog/catalog.module.js +5 -4
  12. package/dist/catalog/catalog.service.d.ts +7 -1
  13. package/dist/catalog/catalog.service.js +19 -2
  14. package/dist/catalog/effect-work.d.ts +27 -0
  15. package/dist/catalog/effect-work.js +151 -0
  16. package/dist/catalog/jobs.d.ts +4 -1
  17. package/dist/catalog/jobs.js +14 -4
  18. package/dist/catalog/org-catalog.service.d.ts +2 -0
  19. package/dist/catalog/org-catalog.service.js +68 -12
  20. package/dist/catalog/org-intent.d.ts +4 -2
  21. package/dist/catalog/org-intent.js +25 -4
  22. package/dist/catalog/owned-items.d.ts +5 -1
  23. package/dist/catalog/owned-items.js +18 -3
  24. package/dist/catalog/plugin-import.d.ts +4 -2
  25. package/dist/catalog/plugin-import.js +10 -5
  26. package/dist/catalog/plugin-install.d.ts +17 -51
  27. package/dist/catalog/plugin-install.js +209 -235
  28. package/dist/catalog/plugin-upgrade.d.ts +8 -3
  29. package/dist/catalog/plugin-upgrade.js +63 -34
  30. package/dist/catalog/scope-sync-workers.d.ts +7 -11
  31. package/dist/catalog/scope-sync-workers.js +10 -26
  32. package/dist/catalog/scope-sync.d.ts +19 -114
  33. package/dist/catalog/scope-sync.js +220 -239
  34. package/dist/catalog/scope-writer.d.ts +10 -1
  35. package/dist/catalog/scope-writer.js +62 -4
  36. package/dist/catalog/template-connector-ensure.js +1 -1
  37. package/dist/catalog/unshare.js +1 -2
  38. package/dist/config/schema.d.ts +1 -1
  39. package/dist/config/schema.js +7 -4
  40. package/dist/db/kernel-schema.d.ts +18 -17
  41. package/dist/erasure/org-catalog.js +2 -2
  42. package/dist/erasure/org-rules.js +2 -2
  43. package/dist/extensions/admin-ops.d.ts +1 -1
  44. package/dist/extensions/admin-ops.js +1 -1
  45. package/dist/extensions/admin-view.d.ts +4 -1
  46. package/dist/extensions/admin-view.js +27 -11
  47. package/dist/extensions/bootstrap.d.ts +1 -1
  48. package/dist/extensions/bootstrap.js +2 -3
  49. package/dist/extensions/enabled.d.ts +159 -0
  50. package/dist/extensions/enabled.js +7 -0
  51. package/dist/extensions/host.d.ts +1 -0
  52. package/dist/extensions/host.js +5 -2
  53. package/dist/extensions/isolated/authorization.d.ts +8 -0
  54. package/dist/extensions/isolated/authorization.js +56 -11
  55. package/dist/extensions/isolated/broker.js +30 -11
  56. package/dist/extensions/isolated/engine-binds.d.ts +9 -0
  57. package/dist/extensions/isolated/engine-binds.js +82 -0
  58. package/dist/extensions/isolated/engine-policy.d.ts +85 -0
  59. package/dist/extensions/isolated/engine-policy.js +75 -0
  60. package/dist/extensions/isolated/engine-proxy-main.d.ts +1 -0
  61. package/dist/extensions/isolated/engine-proxy-main.js +20 -0
  62. package/dist/extensions/isolated/engine-proxy.d.ts +7 -0
  63. package/dist/extensions/isolated/engine-proxy.js +408 -0
  64. package/dist/extensions/isolated/engine-vaults.d.ts +12 -0
  65. package/dist/extensions/isolated/engine-vaults.js +93 -0
  66. package/dist/extensions/isolated/lanes.d.ts +11 -3
  67. package/dist/extensions/isolated/lanes.js +43 -16
  68. package/dist/extensions/isolated/postgres-gate.d.ts +1 -0
  69. package/dist/extensions/isolated/postgres-gate.js +6 -6
  70. package/dist/extensions/isolated/revision.d.ts +1 -1
  71. package/dist/extensions/isolated/revision.js +3 -2
  72. package/dist/extensions/isolated/sandbox.d.ts +10 -6
  73. package/dist/extensions/isolated/sandbox.js +101 -117
  74. package/dist/extensions/lifecycle-topics.d.ts +1 -0
  75. package/dist/extensions/lifecycle-topics.js +1 -0
  76. package/dist/extensions/lifecycle.js +23 -2
  77. package/dist/extensions/permission-view.d.ts +6 -1
  78. package/dist/inbox/platform-inbox.service.js +16 -27
  79. package/dist/infra/events/kernel-events.d.ts +4 -0
  80. package/dist/infra/outbox/registry.d.ts +3 -36
  81. package/dist/infra/outbox/registry.js +4 -49
  82. package/dist/infra/queue/queue-names.d.ts +1 -1
  83. package/dist/infra/queue/queue-names.js +1 -1
  84. package/dist/orgs/org-lock.d.ts +3 -1
  85. package/dist/orgs/org-lock.js +3 -1
  86. package/dist/orgs/orgs.service.d.ts +3 -1
  87. package/dist/orgs/orgs.service.js +15 -8
  88. package/dist/overrides.d.ts +0 -3
  89. package/dist/overrides.js +0 -2
  90. package/dist/platform/ops/extensions-admin.ops.js +20 -3
  91. package/dist/platform/ops/org-plugins.ops.js +5 -2
  92. package/dist/platform/ops/plugins.ops.js +11 -10
  93. package/dist/tools/registry.d.ts +1 -1
  94. package/dist/tools/registry.js +6 -2
  95. package/package.json +2 -2
  96. package/src/migrations/0231_plugin_effect_work.sql +171 -0
  97. package/src/migrations/0232_contract_plugin_effect_schema.sql +49 -0
  98. package/dist/catalog/install-status.d.ts +0 -5
  99. package/dist/catalog/install-status.js +0 -5
  100. package/dist/catalog/scope-jobs.d.ts +0 -59
  101. package/dist/catalog/scope-jobs.js +0 -78
@@ -34,6 +34,7 @@ import { KernelDb } from "../infra/database/kernel-db.js";
34
34
  import { asPlatform } from "../infra/database/org-scope.js";
35
35
  import { TransactionHost } from "../infra/database/transaction-host.js";
36
36
  import { Transactional } from "../infra/database/transactional.decorator.js";
37
+ import { XactLock } from "../infra/database/xact-lock.js";
37
38
  import { OutboxService } from "../infra/outbox/outbox.service.js";
38
39
  import { KERNEL_LOGGER } from "../infra/tokens.js";
39
40
  import { OrgLock } from "../orgs/org-lock.js";
@@ -51,6 +52,7 @@ import { CLAUDE_MCP_CONNECTOR } from "./claude/mcp.js";
51
52
  import { item as reportItem, sortItems, } from "./claude/report.js";
52
53
  import { isClaudePluginTree, translateClaudePlugin } from "./claude/translate.js";
53
54
  import { refreshCatalogDependencyEdges } from "./dependency-edges.js";
55
+ import { EFFECT_CANDIDATES_LOCK, oweEffectWork } from "./effect-work.js";
54
56
  import { CatalogItemLock } from "./locks.js";
55
57
  import { requireMarketplacePublisher } from "./marketplace-fetch.js";
56
58
  import { assertNameFree, assertPackageFree, assertShareable, packageOwner, shareGate, usableBy, } from "./ownership.js";
@@ -59,7 +61,6 @@ import { assertDeclarativeUpload, PluginPackageError, readPluginFiles, readPlugi
59
61
  import { OFFICIAL_MARKETPLACE_ID, officialPublisherProofMode } from "./publisher-policy.js";
60
62
  import { hasImportRequests, importRequestOf, resolveImportRequests } from "./request-rules.js";
61
63
  import { assertNameNotReserved } from "./reserved-names.js";
62
- import { oweScopeItem } from "./scope-jobs.js";
63
64
  import { addScopeOrg } from "./scope-orgs.js";
64
65
  import { writeScope } from "./scope-writer.js";
65
66
  import { templateDescriptionText } from "./template-description.js";
@@ -164,6 +165,7 @@ let PluginImport = class PluginImport {
164
165
  registry;
165
166
  log;
166
167
  txHost;
168
+ xactLock;
167
169
  platform;
168
170
  outbox;
169
171
  /** Where plugin files go (the kernel's object storage; the CLI's own, see {@link useCliStorage}). */
@@ -182,7 +184,7 @@ let PluginImport = class PluginImport {
182
184
  /** Reads a package from the package store (confirm recomputes the permission set). */
183
185
  blobs,
184
186
  /** Config-declared names, loaded connectors and extension versions (the extension registry). */
185
- registry, log, txHost,
187
+ registry, log, txHost, xactLock,
186
188
  /** The platform rows of a new item's components, written in the confirm's transaction. */
187
189
  platform,
188
190
  /** The item's scope sync, owed by the confirm's commit when it deploys no extension. */
@@ -202,6 +204,7 @@ let PluginImport = class PluginImport {
202
204
  this.registry = registry;
203
205
  this.log = log;
204
206
  this.txHost = txHost;
207
+ this.xactLock = xactLock;
205
208
  this.platform = platform;
206
209
  this.outbox = outbox;
207
210
  this.files = storage;
@@ -834,6 +837,7 @@ let PluginImport = class PluginImport {
834
837
  const reviewed = review.extension;
835
838
  const stale = () => reviewStale(review);
836
839
  const { owner } = scope;
840
+ await this.xactLock.lock(EFFECT_CANDIDATES_LOCK);
837
841
  await this.authorizeActor(actor, owner);
838
842
  const t = this.db;
839
843
  // The settings writer takes the same super-admin lock. A staged pin-only import
@@ -1049,7 +1053,7 @@ let PluginImport = class PluginImport {
1049
1053
  .where("id", "=", itemId)
1050
1054
  .executeTakeFirstOrThrow();
1051
1055
  if (item.scope !== "optional" || owner !== undefined) {
1052
- await oweScopeItem(this.outbox, t, itemId);
1056
+ await oweEffectWork(this.outbox, t, { itemIds: [itemId] });
1053
1057
  }
1054
1058
  }
1055
1059
  if (selectedVersionChanged)
@@ -1641,8 +1645,9 @@ PluginImport = __decorate([
1641
1645
  __param(13, Inject(ExtensionRegistry)),
1642
1646
  __param(14, Inject(KERNEL_LOGGER)),
1643
1647
  __param(15, Inject(TransactionHost)),
1644
- __param(16, Inject(PlatformComponents)),
1645
- __param(17, Inject(OutboxService))
1648
+ __param(16, Inject(XactLock)),
1649
+ __param(17, Inject(PlatformComponents)),
1650
+ __param(18, Inject(OutboxService))
1646
1651
  ], PluginImport);
1647
1652
  export { PluginImport };
1648
1653
  /**
@@ -1,12 +1,10 @@
1
1
  import { type AgentTemplate, type ConnectorTemplateFile, type PluginManifest } from "@capybara-hq/plugin-sdk";
2
- import type { KernelSchemaDb, PluginInstallStatus, SourceFormat } from "../db/kernel-schema.js";
2
+ import type { KernelSchemaDb, PluginEffectError, PluginInstallStatus, SourceFormat } from "../db/kernel-schema.js";
3
3
  import { OrgExtensionConfigs, type OrgExtensionInput, type OrgExtensionPutOptions } from "../extensions/org-config.js";
4
4
  import { ExtensionRegistry } from "../extensions/registry.js";
5
- import { KernelConfigService } from "../infra/config/kernel-config.service.js";
6
5
  import { KernelDb } from "../infra/database/kernel-db.js";
7
6
  import { TransactionHost } from "../infra/database/transaction-host.js";
8
7
  import { OutboxService } from "../infra/outbox/outbox.service.js";
9
- import type { KernelLogger } from "../log.js";
10
8
  import { OrgLock } from "../orgs/org-lock.js";
11
9
  import type { OrgAction } from "../orgs/roles.js";
12
10
  import { type SkillConflict, SkillsService } from "../skills/skills.service.js";
@@ -79,9 +77,9 @@ export interface UninstallReport {
79
77
  * plugin's skills, connectors or agent templates.
80
78
  */
81
79
  export interface UninstallPreview {
82
- installId: string;
80
+ installId: string | null;
83
81
  name: string;
84
- version: string;
82
+ version: string | null;
85
83
  components: {
86
84
  kind: ComponentKind;
87
85
  ref: string;
@@ -109,15 +107,11 @@ export interface PluginInstallView {
109
107
  id: string;
110
108
  itemId: string;
111
109
  name: string;
112
- version: string;
110
+ version: string | null;
113
111
  status: PluginInstallStatus;
114
112
  installedBy: string | null;
115
113
  installedAt: string;
116
- /** The failed install's step and code, or the last failed upgrade's (the install stays installed). */
117
- error: {
118
- step: string;
119
- code: string;
120
- } | null;
114
+ error: PluginEffectError | null;
121
115
  /**
122
116
  * `dropped`: an upgrade removed it from the plugin but kept it because an agent uses it ("no
123
117
  * longer in the plugin"); uninstalling still removes it once nothing uses it.
@@ -268,10 +262,8 @@ export declare class PluginInstaller {
268
262
  private readonly skills;
269
263
  private readonly orgConfigs;
270
264
  private readonly scopeWriter;
271
- private readonly config;
272
265
  /** Org connectors: installs create, upgrade and remove them. */
273
266
  private readonly connectors;
274
- private readonly log;
275
267
  /** Owes the template connector ensure of an install's commit (`markInstalled`). */
276
268
  private readonly outbox;
277
269
  readonly txHost: TransactionHost;
@@ -279,15 +271,13 @@ export declare class PluginInstaller {
279
271
  /** The org row lock (orgs/org-lock.ts): joins the caller's transaction. */
280
272
  orgLock: OrgLock, storage: StorageService,
281
273
  /** The loaded extensions and connectors of this replica (the extension registry). */
282
- registry: ExtensionRegistry, skills: SkillsService, orgConfigs: OrgExtensionConfigs, scopeWriter: ScopeWriter, config: KernelConfigService,
274
+ registry: ExtensionRegistry, skills: SkillsService, orgConfigs: OrgExtensionConfigs, scopeWriter: ScopeWriter,
283
275
  /** Org connectors: installs create, upgrade and remove them. */
284
- connectors: ConnectorsService, log: KernelLogger,
276
+ connectors: ConnectorsService,
285
277
  /** Owes the template connector ensure of an install's commit (`markInstalled`). */
286
278
  outbox: Pick<OutboxService, "add">, txHost: TransactionHost);
287
279
  /** The kernel-schema handle of the current context (the transaction, else the pool). */
288
280
  private get db();
289
- /** `catalog.staleInstallMinutes`: an install `installing` for longer can be cleaned up by uninstalling it. */
290
- staleInstallMinutes(): number;
291
281
  /**
292
282
  * The checks an install runs before it creates anything, without the org's input (for the org
293
283
  * catalog to run before a request is created): dependency resolution, the extensions deployed and
@@ -301,7 +291,9 @@ export declare class PluginInstaller {
301
291
  auditDetail?: AuditDetail;
302
292
  switchOn?: boolean;
303
293
  via?: "scope";
304
- }): Promise<PluginInstallView>;
294
+ }): Promise<PluginInstallView | null>;
295
+ private effectGeneration;
296
+ private recordInstallFailure;
305
297
  /**
306
298
  * Refuses a plan whose skills would overwrite a skill of other provenance (spec §9.2, Decision
307
299
  * 8) with 409 `plugin.skill_conflict`, before anything is written: for the plugin and each
@@ -395,27 +387,12 @@ export declare class PluginInstaller {
395
387
  switchOn?: boolean;
396
388
  /** Installed by the plugin scope sync (recorded in the audits). */
397
389
  via?: "scope";
398
- }): Promise<string>;
399
- /**
400
- * The install row (role and item policy re-checked under the lock; one live install per org and
401
- * item). A step of the install: committed on its own.
402
- */
403
- /**
404
- * Enables a plugin's extension for the org and records it as a component of the install, in one
405
- * transaction (`put` joins it): "enabled before" is decided under the org row lock (already
406
- * enabled: `put` writes nothing, the config is untouched, the component is recorded as not
407
- * created), and the ledger row is written before the COMMIT, so no concurrent uninstall fits
408
- * between enabling and recording. Used only by a fresh install (and a dependency the install or a
409
- * platform update adds): a platform update of an installed plugin and switching an installed
410
- * plugin on again never call it, so an extension the org switched off stays off (extension switch
411
- * spec 2026-12-02 §3.2).
412
- */
413
- enableExtension(orgId: string, name: string, input: OrgExtensionInput, actor: string | null, actorTokenId: string | undefined, opts: Pick<OrgExtensionPutOptions, "viaItem" | "approvedBy">, record: (c: Component) => Promise<void>): Promise<void>;
390
+ }): Promise<string | null>;
391
+ /** Validates extension setup and owes connector discovery in the caller's transaction. */
392
+ enableExtension(orgId: string, name: string, input: OrgExtensionInput, actor: string | null, actorTokenId: string | undefined, opts: Pick<OrgExtensionPutOptions, "viaItem" | "approvedBy">): Promise<void>;
414
393
  private createInstallRow;
415
394
  /** The install `installed` and its `plugin.org_installed` audit, under the org row lock (its own transaction). */
416
395
  private markInstalled;
417
- /** The install `failed` with `{ step, code }` and its `plugin.org_install_failed` audit (its own transaction). */
418
- private markFailed;
419
396
  /**
420
397
  * The extension to enable: the plugin's own, when it has one. Not loaded on this replica ->
421
398
  * `catalog.not_deployed`; not yet enabled in this org while its own catalog item is disabled ->
@@ -423,20 +400,6 @@ export declare class PluginInstaller {
423
400
  * unaffected.
424
401
  */
425
402
  planExtension(orgId: string, manifest: PluginManifest): Promise<string | null>;
426
- /**
427
- * Undoes the components this install created, in reverse order (the role is not re-checked: it
428
- * undoes this install's own changes); returns the ones that failed. The component rows of undone
429
- * (or already gone) components are deleted in the same transaction, so cleaning up the failed
430
- * install later only handles what failed to undo or was kept, and does not undo again an extension
431
- * an org admin re-enabled by hand or a skill version a user uploaded since.
432
- */
433
- private rollback;
434
- /**
435
- * Undoes one component of a failed install and deletes its component row, under the org row lock,
436
- * in a transaction of its own (committed when it returns); returns the extensions it disabled
437
- * (the caller notifies them).
438
- */
439
- private rollbackOne;
440
403
  /** Removes one component (one already gone is no error); returns whether anything changed. */
441
404
  removeComponent(orgId: string, actor: string | null, c: Component, reason: string): Promise<boolean>;
442
405
  /**
@@ -588,7 +551,7 @@ export declare class PluginInstaller {
588
551
  * the item whose status is one of `statuses` (`created`: the plugin made it, so an uninstall and
589
552
  * upgrades see it), in the caller's transaction. True when such an install exists.
590
553
  */
591
- recordTemplateConnectorIn(orgId: string, itemId: string, connectorId: string, templateId: string, statuses: readonly PluginInstallStatus[]): Promise<boolean>;
554
+ recordTemplateConnectorIn(orgId: string, itemId: string, connectorId: string, templateId: string): Promise<boolean>;
592
555
  /**
593
556
  * Records a connector made from a plugin's template on the org's live install of that plugin,
594
557
  * when there is one, under the org lock (so an uninstall in between is seen).
@@ -613,6 +576,9 @@ export declare class PluginInstaller {
613
576
  * update keeps copies of removed components).
614
577
  */
615
578
  previewUninstall(orgId: string, installId: string): Promise<UninstallPreview>;
579
+ /** A pure content plugin can take components away without an org install row. */
580
+ previewContentOff(orgId: string, itemId: string): Promise<UninstallPreview | null>;
581
+ private previewRemoval;
616
582
  /**
617
583
  * The connectors, skills (selected, pinned, or in an inline sub-agent template) and agent
618
584
  * templates (`subagents.templates`) referenced by the current definitions of the org's live