@capybara-hq/kernel 0.1.0-rc.75 → 0.1.0-rc.77

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 (76) hide show
  1. package/bootstrap.json +5 -5
  2. package/dist/agents/readiness.controller.d.ts +4 -3
  3. package/dist/agents/readiness.controller.js +4 -3
  4. package/dist/agents/readiness.service.d.ts +44 -11
  5. package/dist/agents/readiness.service.js +59 -16
  6. package/dist/catalog/catalog-import.module.d.ts +1 -1
  7. package/dist/catalog/catalog-import.module.js +1 -1
  8. package/dist/catalog/cli.d.ts +9 -2
  9. package/dist/catalog/cli.js +10 -4
  10. package/dist/catalog/marketplaces.service.d.ts +1 -1
  11. package/dist/catalog/plugin-upgrade.d.ts +4 -2
  12. package/dist/catalog/plugin-upgrade.js +9 -3
  13. package/dist/db/kernel-schema.d.ts +5 -0
  14. package/dist/devices/device-projects.service.d.ts +3 -12
  15. package/dist/devices/device-projects.service.js +16 -59
  16. package/dist/extensions/bootstrap.d.ts +34 -3
  17. package/dist/extensions/bootstrap.js +111 -14
  18. package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
  19. package/dist/lifecycle/kernel-lifecycle.js +16 -11
  20. package/dist/overrides.d.ts +0 -5
  21. package/dist/overrides.js +0 -2
  22. package/dist/platform/file-ref.d.ts +6 -5
  23. package/dist/platform/ops/agent-skills.ops.js +1 -1
  24. package/dist/platform/ops/agents.ops.js +1 -1
  25. package/dist/runtime/model-call.d.ts +2 -2
  26. package/dist/runtime/project/knowledge.d.ts +1 -1
  27. package/dist/runtime/project/knowledge.js +1 -1
  28. package/dist/runtime/project/knowledge.service.d.ts +5 -11
  29. package/dist/runtime/project/knowledge.service.js +12 -23
  30. package/dist/runtime/providers.d.ts +34 -1
  31. package/dist/runtime/providers.js +56 -7
  32. package/dist/runtime/run-steps.d.ts +4 -6
  33. package/dist/runtime/run-steps.js +7 -15
  34. package/dist/runtime/runtime.module.js +1 -1
  35. package/dist/sandbox/held-operations.d.ts +2 -5
  36. package/dist/sandbox/held-operations.js +0 -14
  37. package/dist/sandbox/managed-device-context.d.ts +1 -1
  38. package/dist/sandbox/managed-device-context.js +1 -1
  39. package/dist/sandbox/permission-context-types.d.ts +0 -11
  40. package/dist/sandbox/permission-context-types.js +0 -13
  41. package/dist/sandbox/providers.d.ts +5 -0
  42. package/dist/sandbox/providers.js +1 -1
  43. package/dist/sandbox/sandbox-file-reader.d.ts +7 -12
  44. package/dist/sandbox/sandbox-file-reader.js +12 -29
  45. package/dist/sandbox/sandbox.service.d.ts +53 -32
  46. package/dist/sandbox/sandbox.service.js +217 -141
  47. package/dist/sandbox/use-context.d.ts +4 -1
  48. package/dist/skills/invoke.d.ts +13 -35
  49. package/dist/skills/invoke.js +23 -162
  50. package/dist/tools/builtins/builtin-tools.d.ts +2 -11
  51. package/dist/tools/builtins/builtin-tools.js +5 -23
  52. package/dist/tools/builtins/image/generate.js +2 -2
  53. package/dist/tools/builtins/sandbox/common.d.ts +32 -80
  54. package/dist/tools/builtins/sandbox/common.js +61 -173
  55. package/dist/tools/builtins/sandbox/deliver.js +2 -2
  56. package/dist/tools/builtins/sandbox/device-owner.d.ts +4 -5
  57. package/dist/tools/builtins/sandbox/device-owner.js +5 -6
  58. package/dist/tools/builtins/sandbox/fetch-attachment.js +2 -2
  59. package/dist/tools/builtins/sandbox/glob.js +1 -1
  60. package/dist/tools/builtins/sandbox/grep.js +1 -1
  61. package/dist/tools/builtins/sandbox/index.d.ts +2 -2
  62. package/dist/tools/builtins/sandbox/index.js +2 -2
  63. package/dist/tools/builtins/sandbox/read.js +1 -1
  64. package/dist/tools/builtins/sandbox/task-output.d.ts +3 -3
  65. package/dist/tools/builtins/sandbox/task-output.js +4 -4
  66. package/dist/tools/builtins/sandbox/task-stop.js +1 -1
  67. package/dist/tools/builtins/skill-load.d.ts +10 -9
  68. package/dist/tools/builtins/skill-load.js +15 -19
  69. package/dist/tools/connectors.service.d.ts +4 -2
  70. package/dist/tools/connectors.service.js +15 -3
  71. package/dist/tools/pipeline.d.ts +0 -2
  72. package/dist/tools/pipeline.js +7 -14
  73. package/dist/tools/tools.module.js +1 -1
  74. package/package.json +2 -2
  75. package/src/migrations/0179_device_report_limit_text.sql +28 -0
  76. package/src/migrations/0180_device_instance_abandoned.sql +6 -0
package/bootstrap.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "schemaVersion": 1,
4
4
  "marketplace": {
5
5
  "url": "https://github.com/capybara-hq/plugins.git",
6
- "commit": "1c9b0dd4ae64d1f199afa3a17d35de4810ab08e5"
6
+ "commit": "a9c5d9c9328a855162c2bbaf758f261add863fa2"
7
7
  },
8
8
  "plugins": [
9
9
  {
@@ -90,16 +90,16 @@
90
90
  "name": "device-docker",
91
91
  "source": "npm",
92
92
  "npm": "@capybara-hq/plugin-device-docker",
93
- "version": "0.1.0-rc.23",
94
- "integrity": "sha512-xR28dC3NPIsRaG4jprsvWa7nFZkc7aURbl7o16TTP7j0oNBEhkkZcj2EQRRfz3/XpRMKSxqVT2tdK3KMK3y0AQ==",
93
+ "version": "0.1.0-rc.24",
94
+ "integrity": "sha512-M+XP8iLgbQe8K27u29Ta2O5Pg+1pCHT4lFZPN9VxyP9+FrtqBcYG0Uf0tC9/f1MUWBdN4fesyeqHXUpoObUg+w==",
95
95
  "required": false
96
96
  },
97
97
  {
98
98
  "name": "device-local",
99
99
  "source": "npm",
100
100
  "npm": "@capybara-hq/plugin-device-local",
101
- "version": "0.1.0-rc.5",
102
- "integrity": "sha512-HaR5VFeK2AqMy4EM6glwGd0cZtgjMMS8AsOqimUCYPMT/eubrP/VuxB3eAFpR007xvommVIv5jd5XnXLbiYanw==",
101
+ "version": "0.1.0-rc.6",
102
+ "integrity": "sha512-wB9147kTphsBKwtvcgd6fylqECDqtqeZfkqiDY2jBAcErjrOL19alogWYIstof9les4CSi6tO8VgBgdfSYN97A==",
103
103
  "required": false,
104
104
  "scope": "all"
105
105
  },
@@ -4,9 +4,10 @@ import { type OrgReadiness, ReadinessService } from "./readiness.service.js";
4
4
  /**
5
5
  * Whether the org can run (`/api/v1/orgs/:orgId/readiness`, web-order spec §3.8): the web app
6
6
  * decides between the shell and the setup layout with it ({@link OrgReadiness}: `ready`,
7
- * `org_fixable` with the providers an org admin can switch on or configure, or `none`; and the
8
- * agents the caller can see). Computed by {@link ReadinessService}, from extension state only,
9
- * never a vendor call. Humans and service tokens (`org.read`).
7
+ * `no_models` with the providers that are on but give no chat model and why, `org_fixable` with
8
+ * the providers an org admin can switch on or configure, or `none`; and the agents the caller can
9
+ * see). Computed by {@link ReadinessService}: extension state first, then the cached model lists
10
+ * of the providers past that gate. Humans and service tokens (`org.read`).
10
11
  */
11
12
  export declare class ReadinessController {
12
13
  private readonly readiness;
@@ -16,9 +16,10 @@ const viewerOf = (p) => (p.kind === "user" ? p.account.id : null);
16
16
  /**
17
17
  * Whether the org can run (`/api/v1/orgs/:orgId/readiness`, web-order spec §3.8): the web app
18
18
  * decides between the shell and the setup layout with it ({@link OrgReadiness}: `ready`,
19
- * `org_fixable` with the providers an org admin can switch on or configure, or `none`; and the
20
- * agents the caller can see). Computed by {@link ReadinessService}, from extension state only,
21
- * never a vendor call. Humans and service tokens (`org.read`).
19
+ * `no_models` with the providers that are on but give no chat model and why, `org_fixable` with
20
+ * the providers an org admin can switch on or configure, or `none`; and the agents the caller can
21
+ * see). Computed by {@link ReadinessService}: extension state first, then the cached model lists
22
+ * of the providers past that gate. Humans and service tokens (`org.read`).
22
23
  */
23
24
  let ReadinessController = class ReadinessController {
24
25
  readiness;
@@ -1,5 +1,7 @@
1
+ import { type LocalizedName } from "@capybara-hq/plugin-sdk";
2
+ import { ExtensionDisplayNames } from "../extensions/display-name.js";
1
3
  import { OrgExtensionConfigs } from "../extensions/org-config.js";
2
- import { ProviderRegistry } from "../runtime/providers.js";
4
+ import { type ListErrorKind, ProviderRegistry } from "../runtime/providers.js";
3
5
  import { AgentsService } from "./agents.service.js";
4
6
  /**
5
7
  * A model provider an org admin can make usable on `/settings/models`, and what it waits for:
@@ -11,16 +13,43 @@ export interface OrgFixableProvider {
11
13
  provider: string;
12
14
  reason: "not_enabled" | "needs_config";
13
15
  }
16
+ /**
17
+ * A model provider that is on in the org with a valid config but gives an agent no model to pick
18
+ * (readiness `no_models`): `list_failed`, its model list failed (`errorKind`, the provider's
19
+ * `ModelError` kind, `timeout` when the kernel's list time limit passed, else `unknown`);
20
+ * `no_chat_models`, it lists but no chat model is on in the org. `orgCanFix`: an org admin can fix
21
+ * it on `/settings/models` (`list_failed`: the org can hold its own copy of the provider's config,
22
+ * a key among it; `no_chat_models`: a chat model the platform left on is off in the org); else
23
+ * only the super admin can (`/admin/models`).
24
+ */
25
+ export type UnusableProvider = {
26
+ provider: string;
27
+ /** The provider extension's display name; null when it has none (show the id). */
28
+ displayName: LocalizedName | null;
29
+ orgCanFix: boolean;
30
+ } & ({
31
+ reason: "list_failed";
32
+ errorKind: ListErrorKind;
33
+ } | {
34
+ reason: "no_chat_models";
35
+ });
14
36
  /** What `GET /orgs/:orgId/readiness` and the `agents.readiness` operation answer. */
15
37
  export interface OrgReadiness {
16
38
  /**
17
- * `ready`: a model provider is usable in the org (extension state only, never a vendor call);
18
- * `org_fixable`: none is, but an org admin can make one usable (`orgFixableProviders`); `none`:
19
- * only the super admin can help (no provider loaded on the deployment that the org may use).
39
+ * `ready`: the org has a chat model an agent can pick (the agent form's list:
40
+ * `GET /orgs/:orgId/models?kind=chat`); `no_models`: providers are on with a valid config but
41
+ * none gives one (`unusableProviders` says why for each); `org_fixable`: no provider is on with a
42
+ * valid config, but an org admin can make one so (`orgFixableProviders`); `none`: only the super
43
+ * admin can help (no provider loaded on the deployment that the org may use).
44
+ */
45
+ modelProvider: "ready" | "no_models" | "org_fixable" | "none";
46
+ /**
47
+ * With `org_fixable`, the providers an org admin can fix here; with `no_models`, the other
48
+ * providers an org admin could switch on or configure (empty otherwise).
20
49
  */
21
- modelProvider: "ready" | "org_fixable" | "none";
22
- /** With `org_fixable`, the providers an org admin can fix here (empty otherwise). */
23
50
  orgFixableProviders: OrgFixableProvider[];
51
+ /** With `no_models`, the providers that are on but give no model, and why (empty otherwise). */
52
+ unusableProviders: UnusableProvider[];
24
53
  /** The agents the caller can see (the agent list's visibility). */
25
54
  agents: number;
26
55
  }
@@ -28,15 +57,19 @@ export interface OrgReadiness {
28
57
  * Whether the org can run (web-order spec §3.8), the one place it is computed (the readiness
29
58
  * route and the `agents.readiness` operation): the web app decides between the shell and the setup
30
59
  * layout with it, and the setup checklist sends the org's admins to `/settings/models` while the
31
- * model step is `org_fixable`. `ready` reads this replica's provider registry (a replica that has
32
- * not reconciled a just-enabled provider answers otherwise for a moment); the fixable providers
33
- * come from the org's extension list.
60
+ * model step is `org_fixable` (or `no_models` that the org can fix). First the cheap gate, this
61
+ * replica's provider registry (`hasProvider`: extension state, switches and config, no vendor
62
+ * call; a replica that has not reconciled a just-enabled provider answers otherwise for a
63
+ * moment); past it, the providers' model lists as the agent form reads them
64
+ * (`ProviderRegistry.chatUsability`: the shared list cache, the list time limit and the failure
65
+ * markers bound the call). The fixable providers come from the org's extension list.
34
66
  */
35
67
  export declare class ReadinessService {
36
68
  private readonly registry;
37
69
  private readonly configs;
38
70
  private readonly agents;
39
- constructor(registry: ProviderRegistry, configs: OrgExtensionConfigs, agents: AgentsService);
71
+ private readonly displayNames;
72
+ constructor(registry: ProviderRegistry, configs: OrgExtensionConfigs, agents: AgentsService, displayNames: ExtensionDisplayNames);
40
73
  get(orgId: string, viewer: string | null): Promise<OrgReadiness>;
41
- private orgFixable;
74
+ private unusable;
42
75
  }
@@ -7,8 +7,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __param = (this && this.__param) || function (paramIndex, decorator) {
8
8
  return function (target, key) { decorator(target, key, paramIndex); }
9
9
  };
10
- import { MODEL_PROVIDER_EXTENSION_POINT_V2, parseExtensionPoint } from "@capybara-hq/plugin-sdk";
10
+ import { MODEL_PROVIDER_EXTENSION_POINT_V2, parseExtensionPoint, } from "@capybara-hq/plugin-sdk";
11
11
  import { Inject, Injectable } from "@nestjs/common";
12
+ import { ExtensionDisplayNames } from "../extensions/display-name.js";
12
13
  import { OrgExtensionConfigs, providesOf, } from "../extensions/org-config.js";
13
14
  import { ProviderRegistry } from "../runtime/providers.js";
14
15
  import { AgentsService } from "./agents.service.js";
@@ -32,39 +33,69 @@ function fixOf(v) {
32
33
  * Whether the org can run (web-order spec §3.8), the one place it is computed (the readiness
33
34
  * route and the `agents.readiness` operation): the web app decides between the shell and the setup
34
35
  * layout with it, and the setup checklist sends the org's admins to `/settings/models` while the
35
- * model step is `org_fixable`. `ready` reads this replica's provider registry (a replica that has
36
- * not reconciled a just-enabled provider answers otherwise for a moment); the fixable providers
37
- * come from the org's extension list.
36
+ * model step is `org_fixable` (or `no_models` that the org can fix). First the cheap gate, this
37
+ * replica's provider registry (`hasProvider`: extension state, switches and config, no vendor
38
+ * call; a replica that has not reconciled a just-enabled provider answers otherwise for a
39
+ * moment); past it, the providers' model lists as the agent form reads them
40
+ * (`ProviderRegistry.chatUsability`: the shared list cache, the list time limit and the failure
41
+ * markers bound the call). The fixable providers come from the org's extension list.
38
42
  */
39
43
  let ReadinessService = class ReadinessService {
40
44
  registry;
41
45
  configs;
42
46
  agents;
43
- constructor(registry, configs, agents) {
47
+ displayNames;
48
+ constructor(registry, configs, agents, displayNames) {
44
49
  this.registry = registry;
45
50
  this.configs = configs;
46
51
  this.agents = agents;
52
+ this.displayNames = displayNames;
47
53
  }
48
54
  async get(orgId, viewer) {
49
- const [ready, visible] = await Promise.all([
55
+ const [gate, visible] = await Promise.all([
50
56
  this.registry.hasProvider(orgId),
51
57
  this.agents.listVisible(orgId, viewer),
52
58
  ]);
53
- const fixable = ready ? [] : await this.orgFixable(orgId);
59
+ const usability = gate ? await this.registry.chatUsability(orgId) : [];
60
+ if (usability.some((u) => u.state === "usable")) {
61
+ return {
62
+ modelProvider: "ready",
63
+ orgFixableProviders: [],
64
+ unusableProviders: [],
65
+ agents: visible.length,
66
+ };
67
+ }
68
+ const views = await this.configs.list(orgId);
69
+ const fixable = orgFixableOf(views);
70
+ if (gate) {
71
+ return {
72
+ modelProvider: "no_models",
73
+ orgFixableProviders: fixable,
74
+ unusableProviders: await this.unusable(usability, views),
75
+ agents: visible.length,
76
+ };
77
+ }
54
78
  return {
55
- modelProvider: ready ? "ready" : fixable.length > 0 ? "org_fixable" : "none",
79
+ modelProvider: fixable.length > 0 ? "org_fixable" : "none",
56
80
  orgFixableProviders: fixable,
81
+ unusableProviders: [],
57
82
  agents: visible.length,
58
83
  };
59
84
  }
60
- async orgFixable(orgId) {
85
+ async unusable(usability, views) {
86
+ const byPlugin = new Map(views.map((v) => [v.plugin, v]));
87
+ const names = await this.displayNames.many(usability.map((u) => u.provider));
61
88
  const out = [];
62
- for (const v of await this.configs.list(orgId)) {
63
- if (!isModelProvider(v))
64
- continue;
65
- const reason = fixOf(v);
66
- if (reason !== null)
67
- out.push({ provider: v.plugin, reason });
89
+ for (const u of usability) {
90
+ const base = { provider: u.provider, displayName: names.get(u.provider) ?? null };
91
+ if (u.state === "list_failed") {
92
+ const v = byPlugin.get(u.provider);
93
+ const orgCanFix = v !== undefined && orgCanConfigure(v);
94
+ out.push({ ...base, orgCanFix, reason: "list_failed", errorKind: u.errorKind });
95
+ }
96
+ else if (u.state === "no_chat_models") {
97
+ out.push({ ...base, orgCanFix: u.orgCanEnable, reason: "no_chat_models" });
98
+ }
68
99
  }
69
100
  return out;
70
101
  }
@@ -73,6 +104,18 @@ ReadinessService = __decorate([
73
104
  Injectable(),
74
105
  __param(0, Inject(ProviderRegistry)),
75
106
  __param(1, Inject(OrgExtensionConfigs)),
76
- __param(2, Inject(AgentsService))
107
+ __param(2, Inject(AgentsService)),
108
+ __param(3, Inject(ExtensionDisplayNames))
77
109
  ], ReadinessService);
78
110
  export { ReadinessService };
111
+ function orgFixableOf(views) {
112
+ const out = [];
113
+ for (const v of views) {
114
+ if (!isModelProvider(v))
115
+ continue;
116
+ const reason = fixOf(v);
117
+ if (reason !== null)
118
+ out.push({ provider: v.plugin, reason });
119
+ }
120
+ return out;
121
+ }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * The platform side of the catalog: marketplaces, the one import review (prepare -> confirm), the
3
3
  * items and their platform components. The CLI's `capybara plugins *` and `capybara bootstrap` run on this
4
- * part alone.
4
+ * part and `CatalogModule` (the platform plugin update a raised bootstrap pin goes through).
5
5
  */
6
6
  export declare class CatalogImportModule {
7
7
  }
@@ -21,7 +21,7 @@ import { PluginImport } from "./plugin-import.js";
21
21
  /**
22
22
  * The platform side of the catalog: marketplaces, the one import review (prepare -> confirm), the
23
23
  * items and their platform components. The CLI's `capybara plugins *` and `capybara bootstrap` run on this
24
- * part alone.
24
+ * part and `CatalogModule` (the platform plugin update a raised bootstrap pin goes through).
25
25
  */
26
26
  let CatalogImportModule = class CatalogImportModule {
27
27
  };
@@ -4,11 +4,17 @@ import { type ExtensionCli } from "../extensions/cli.js";
4
4
  import type { KernelLogger } from "../log.js";
5
5
  import { CatalogService } from "./catalog.service.js";
6
6
  import { PluginImport } from "./plugin-import.js";
7
+ import { PlatformPluginUpdater } from "./plugin-upgrade.js";
7
8
  /** {@link openCatalogCli}'s result: the extension CLI context plus the catalog services. */
8
9
  export interface CatalogCli extends ExtensionCli {
9
10
  catalog: CatalogService;
10
11
  /** Plugin import (prepare / confirm). The CLI acts without an account (actor `null`). */
11
12
  imports: PluginImport;
13
+ /**
14
+ * The platform plugin update (`capybara bootstrap` raises a pinned plugin without an extension
15
+ * with it), acting without an account (actor `null`).
16
+ */
17
+ updater: PlatformPluginUpdater;
12
18
  }
13
19
  /** What the CLI can do with the deployment's object store, and why not when it cannot. */
14
20
  export type CliObjectStore = {
@@ -33,8 +39,9 @@ export type CliObjectStore = {
33
39
  export declare function loadCliObjectStore(cli: Pick<ExtensionCli, "inspected" | "deploymentConfigs" | "deploymentConfigOf" | "approvals" | "config" | "configIssues" | "installs" | "packageSet" | "readPackage">, log: Pick<KernelLogger, "warn">, syncDir: string): Promise<CliObjectStore>;
34
40
  /**
35
41
  * The CLI's plugin catalog context (`capybara plugins *`): {@link openExtensionCli} with the
36
- * catalog's {@link CatalogImportModule}, so {@link PluginImport} and {@link CatalogService} are the
37
- * kernel's providers. Imports run with actor `null` (the operator of the
42
+ * catalog's {@link CatalogImportModule} and {@link CatalogModule} (whose platform plugin update
43
+ * `capybara bootstrap` raises a pinned plugin without an extension with), so {@link PluginImport},
44
+ * {@link CatalogService} and {@link PlatformPluginUpdater} are the kernel's providers. Imports run with actor `null` (the operator of the
38
45
  * deployment, like `capybara extensions install`: no super-admin re-check, audits without an
39
46
  * actor, permission snapshots written with source `cli`). Files of the plugin (skills, connector
40
47
  * templates, icons) go to the deployment's object store, set up in-process from the declared or
@@ -11,9 +11,10 @@ import { importExtensionModule, matchesSection } from "../extensions/instance.js
11
11
  import { packageRootOf, syncPackage } from "../extensions/sync.js";
12
12
  import { packagePath } from "../packages/tgz.js";
13
13
  import { PrefixedStorage } from "../storage/storage.service.js";
14
- import { CatalogImportModule } from "./catalog.module.js";
14
+ import { CatalogImportModule, CatalogModule } from "./catalog.module.js";
15
15
  import { CatalogService } from "./catalog.service.js";
16
16
  import { PluginImport } from "./plugin-import.js";
17
+ import { PlatformPluginUpdater } from "./plugin-upgrade.js";
17
18
  /**
18
19
  * Sets up the deployment's object-store extension inside the CLI process. The CLI hosts no
19
20
  * extensions, so this runs only the provider's `setup` with a context that offers `config` and
@@ -147,8 +148,9 @@ class CliStorage extends PrefixedStorage {
147
148
  }
148
149
  /**
149
150
  * The CLI's plugin catalog context (`capybara plugins *`): {@link openExtensionCli} with the
150
- * catalog's {@link CatalogImportModule}, so {@link PluginImport} and {@link CatalogService} are the
151
- * kernel's providers. Imports run with actor `null` (the operator of the
151
+ * catalog's {@link CatalogImportModule} and {@link CatalogModule} (whose platform plugin update
152
+ * `capybara bootstrap` raises a pinned plugin without an extension with), so {@link PluginImport},
153
+ * {@link CatalogService} and {@link PlatformPluginUpdater} are the kernel's providers. Imports run with actor `null` (the operator of the
152
154
  * deployment, like `capybara extensions install`: no super-admin re-check, audits without an
153
155
  * actor, permission snapshots written with source `cli`). Files of the plugin (skills, connector
154
156
  * templates, icons) go to the deployment's object store, set up in-process from the declared or
@@ -157,7 +159,10 @@ class CliStorage extends PrefixedStorage {
157
159
  * plugin does not bring are checked statically only (the CLI loads no connector).
158
160
  */
159
161
  export async function openCatalogCli(config, log, opts = {}) {
160
- const cli = await openExtensionCli(config, log, { ...opts, modules: [CatalogImportModule] });
162
+ const cli = await openExtensionCli(config, log, {
163
+ ...opts,
164
+ modules: [CatalogImportModule, CatalogModule],
165
+ });
161
166
  let syncDir;
162
167
  const removeSyncDir = async () => {
163
168
  if (syncDir !== undefined)
@@ -182,6 +187,7 @@ export async function openCatalogCli(config, log, opts = {}) {
182
187
  ...cli,
183
188
  catalog,
184
189
  imports,
190
+ updater: cli.app.get(PlatformPluginUpdater),
185
191
  async close() {
186
192
  await cli.close();
187
193
  await removeSyncDir();
@@ -203,7 +203,7 @@ export declare function headsToResolve(entries: readonly MarketplaceEntry[], imp
203
203
  /** The host versions (an entry's `minKernel` is judged against them). */
204
204
  export declare const HOST_VERSIONS: {
205
205
  readonly kernel: string;
206
- readonly sdk: "0.1.0-rc.60";
206
+ readonly sdk: "0.1.0-rc.62";
207
207
  };
208
208
  /** Whether this deployment satisfies the entry's `minKernel`. */
209
209
  export declare const entryCompatible: (e: Pick<MarketplaceEntry, "minKernel">) => boolean;
@@ -313,9 +313,11 @@ export declare class PlatformPluginUpdater {
313
313
  /**
314
314
  * Runs an update confirmed with the preview's `diffHash` (see the class comment). A version an
315
315
  * org upload waits with, or an item whose first version waits, -> 409 `catalog.item_pending`
316
- * (confirmed in 待确认 instead, pre-flight F8).
316
+ * (confirmed in the admin console's pending confirmations instead, pre-flight F8). `actor`
317
+ * null: the kernel itself (the bootstrap step raising a pinned plugin without an extension): no
318
+ * super admin is re-checked and the audits name no account.
317
319
  */
318
- update(actor: string, itemId: string, input: {
320
+ update(actor: string | null, itemId: string, input: {
319
321
  version: string;
320
322
  diffHash: string;
321
323
  }, opts?: {
@@ -339,7 +339,9 @@ let PlatformPluginUpdater = class PlatformPluginUpdater {
339
339
  /**
340
340
  * Runs an update confirmed with the preview's `diffHash` (see the class comment). A version an
341
341
  * org upload waits with, or an item whose first version waits, -> 409 `catalog.item_pending`
342
- * (confirmed in 待确认 instead, pre-flight F8).
342
+ * (confirmed in the admin console's pending confirmations instead, pre-flight F8). `actor`
343
+ * null: the kernel itself (the bootstrap step raising a pinned plugin without an extension): no
344
+ * super admin is re-checked and the audits name no account.
343
345
  */
344
346
  async update(actor, itemId, input, opts = {}) {
345
347
  if (!UUID_RE.test(itemId))
@@ -477,12 +479,16 @@ let PlatformPluginUpdater = class PlatformPluginUpdater {
477
479
  * recomputed under the item name's lock, then every write. Returns the diff it applied.
478
480
  */
479
481
  async commit(actor, itemId, input, opts, pre, prepared, owner, confirmPending) {
480
- if (owner === undefined)
482
+ if (owner !== undefined && actor === null) {
483
+ throw new Error("an owner update needs the acting account");
484
+ }
485
+ // null: the kernel itself (the bootstrap step), no super admin to re-check
486
+ if (owner === undefined && actor !== null)
481
487
  await this.adminLock.lockAndAuthorize(actor);
482
488
  // The global lock order (ruling P3-50): the orgs (sorted; the acting owner org's admin
483
489
  // re-checked at its place), then the item, then its components; an org deletion locks its org
484
490
  // row, then the items it owns
485
- const liveOrgs = await this.lockUpdateOrgs(itemId, owner && { orgId: owner.orgId, actor });
491
+ const liveOrgs = await this.lockUpdateOrgs(itemId, owner && actor !== null ? { orgId: owner.orgId, actor } : undefined);
486
492
  const named = await this.db
487
493
  .selectFrom("catalog_items")
488
494
  .select("name")
@@ -1177,6 +1177,11 @@ export interface DeviceInstancesTable {
1177
1177
  prev_provider: ColumnType<string | null, string | null | undefined, string | null>;
1178
1178
  prev_handle: InstanceHandle;
1179
1179
  sweep_failed_at: TsNullable;
1180
+ /**
1181
+ * 0180 (#675): when the device was deleted while its provider plugin was no longer installed
1182
+ * (`SandboxService.destroyDevice`); the row is kept as the record of the provider-side names.
1183
+ */
1184
+ abandoned_at: TsNullable;
1180
1185
  /**
1181
1186
  * 0117: the limits in force on the instance, `{ mode, network }`, plus `unapplied` when the
1182
1187
  * provider could not apply a newer value without a file reset; null = unknown (made before
@@ -60,11 +60,7 @@ export declare class DeviceProjectsService {
60
60
  private readonly facts;
61
61
  private readonly ceilings;
62
62
  private readonly log;
63
- /** The paired activation gate: once on, every device read is an owner browse. */
64
- private readonly activation?;
65
- constructor(db: KernelDb, txHost: TransactionHost, sandbox: Pick<SandboxService, "withSandbox" | "withBrowse" | "ensureRunningForOwner">, access: Pick<DeviceAccess, "usable">, facts: Pick<PermissionFacts, "resolveProjectForBinding" | "projectMatches" | "projectScope">, ceilings: PermissionCeilingWrites, log: Pick<KernelLogger, "warn">,
66
- /** The paired activation gate: once on, every device read is an owner browse. */
67
- activation?: boolean | undefined);
63
+ constructor(db: KernelDb, txHost: TransactionHost, sandbox: Pick<SandboxService, "withBrowse" | "ensureRunningForOwner">, access: Pick<DeviceAccess, "usable">, facts: Pick<PermissionFacts, "resolveProjectForBinding" | "projectMatches" | "projectScope">, ceilings: PermissionCeilingWrites, log: Pick<KernelLogger, "warn">);
68
64
  /** Every stored project; see {@link DeviceProjectList}. */
69
65
  list(orgId: string, accountId: string, deviceId: string): Promise<DeviceProjectList>;
70
66
  /**
@@ -137,9 +133,7 @@ export declare class DeviceProjectsService {
137
133
  */
138
134
  private scope;
139
135
  /**
140
- * Runs `fn` on the device with a {@link ProjectReader}. While the activation gate is off:
141
- * `SandboxService.withSandbox` (its instance made or resumed as for a tool call) with the
142
- * workspace root its instance reports. Once it is on: the device started for its owner
136
+ * Runs `fn` on the device with a {@link ProjectReader}: the device started for its owner
143
137
  * (`SandboxService.ensureRunningForOwner`), then the owner browse (`SandboxService.withBrowse`,
144
138
  * as the device's owner, on the instance that runs) with the last known workspace; an instance
145
139
  * that stopped in between is `device.not_running`. Kernel refusals (offline, files lost, busy,
@@ -150,8 +144,5 @@ export declare class DeviceProjectsService {
150
144
  /** Locks the owner's live device row (serializes its project writes); else `not_found`. */
151
145
  private lockOwn;
152
146
  }
153
- /**
154
- * A project read on a device whose sandbox provider cannot be reached (the projects routes, a
155
- * person's project skill invocation).
156
- */
147
+ /** A project read on a device whose sandbox provider cannot be reached (the projects routes). */
157
148
  export declare const providerUnreachable: () => ApiError;
@@ -10,7 +10,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
10
10
  import { posix } from "node:path";
11
11
  import { isDeviceOfflineError, isDeviceProjectName, isFileSystemGoneError, isProjectPathRefusedError, isSandboxGoneError, isSandboxScopeDeniedError, MAX_DEVICE_SCAN_RESULTS, ToolError, validateSandboxPathShape, } from "@capybara-hq/plugin-sdk";
12
12
  import { DeviceProtocolError } from "@capybara-hq/plugin-sdk/device-protocol";
13
- import { Inject, Injectable, Optional } from "@nestjs/common";
13
+ import { Inject, Injectable } from "@nestjs/common";
14
14
  import { sql } from "kysely";
15
15
  import { deviceOffline } from "../dial-in/relay.js";
16
16
  import { ApiError } from "../errors.js";
@@ -20,7 +20,6 @@ import { TransactionHost, withOrderedLocks } from "../infra/database/transaction
20
20
  import { Transactional } from "../infra/database/transactional.decorator.js";
21
21
  import { KERNEL_LOGGER } from "../infra/tokens.js";
22
22
  import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
23
- import { PERMISSION_CONTEXT_ACTIVATION, permissionContextActive, } from "../sandbox/permission-context-types.js";
24
23
  import { PermissionFacts } from "../sandbox/permission-facts.js";
25
24
  import { SandboxService } from "../sandbox/sandbox.service.js";
26
25
  import { SandboxProviderUnreachableError } from "../sandbox/unreachable.js";
@@ -32,33 +31,10 @@ import { baseOf, clipped, nameInvalid, nameTaken, outsideMode, tooBroad, } from
32
31
  import { aboveHome } from "./working-root.js";
33
32
  /** The most projects one device keeps (project root §4.1). */
34
33
  export const MAX_DEVICE_PROJECTS = 100;
35
- /**
36
- * The holder name the projects service enters a device's sandbox under (`SandboxService`
37
- * `withSandbox`) while the activation gate is off: it only lists directories, never runs a
38
- * command, so no conversation holds it. Once the gate is on the owner browse route has no holder.
39
- */
40
- const PROJECTS_HOLDER = "device-projects";
41
- /** The raw route's reader over a held provider (gate off): the protocol 2 calls, unchanged. */
42
- function heldReader(h, p, workspace) {
43
- const list = p.list;
44
- const scan = p.scan;
45
- return {
46
- workspace,
47
- browse: false,
48
- ...(list !== undefined && {
49
- list: (path, limit, signal) => list.call(p, h, path, { limit, signal }),
50
- }),
51
- ...(scan !== undefined && {
52
- scan: (base, signal) => scan.call(p, h, base, { signal }),
53
- }),
54
- stat: (path, signal) => p.stat(h, path, signal),
55
- };
56
- }
57
- /** The owner browse route's reader (gate on): the browse scope's stat / list / scan only. */
34
+ /** The owner browse route's reader: the browse scope's stat / list / scan only. */
58
35
  function browseReader(b, workspace) {
59
36
  return {
60
37
  workspace,
61
- browse: true,
62
38
  list: (path, limit, signal) => b.list(path, { limit, signal }),
63
39
  scan: (base, signal) => b.scan(base, { signal }),
64
40
  stat: (path, signal) => b.stat(path, signal),
@@ -81,10 +57,7 @@ let DeviceProjectsService = class DeviceProjectsService {
81
57
  facts;
82
58
  ceilings;
83
59
  log;
84
- activation;
85
- constructor(db, txHost, sandbox, access, facts, ceilings, log,
86
- /** The paired activation gate: once on, every device read is an owner browse. */
87
- activation) {
60
+ constructor(db, txHost, sandbox, access, facts, ceilings, log) {
88
61
  this.db = db;
89
62
  this.txHost = txHost;
90
63
  this.sandbox = sandbox;
@@ -92,7 +65,6 @@ let DeviceProjectsService = class DeviceProjectsService {
92
65
  this.facts = facts;
93
66
  this.ceilings = ceilings;
94
67
  this.log = log;
95
- this.activation = activation;
96
68
  }
97
69
  /** Every stored project; see {@link DeviceProjectList}. */
98
70
  async list(orgId, accountId, deviceId) {
@@ -120,7 +92,7 @@ let DeviceProjectsService = class DeviceProjectsService {
120
92
  * no projects suggests none.
121
93
  */
122
94
  async candidates(orgId, accountId, deviceId, signal = new AbortController().signal) {
123
- // ownership is the scope's; whether the provider can serve the device is withSandbox's
95
+ // ownership is the scope's; whether the provider can serve the device is the browse's
124
96
  const scope = await this.scope(orgId, accountId, deviceId);
125
97
  if (!scope.supported) {
126
98
  return { candidates: [], base: baseOf(scope), supported: false };
@@ -347,9 +319,7 @@ let DeviceProjectsService = class DeviceProjectsService {
347
319
  return this.facts.projectScope(orgId, accountId, deviceId);
348
320
  }
349
321
  /**
350
- * Runs `fn` on the device with a {@link ProjectReader}. While the activation gate is off:
351
- * `SandboxService.withSandbox` (its instance made or resumed as for a tool call) with the
352
- * workspace root its instance reports. Once it is on: the device started for its owner
322
+ * Runs `fn` on the device with a {@link ProjectReader}: the device started for its owner
353
323
  * (`SandboxService.ensureRunningForOwner`), then the owner browse (`SandboxService.withBrowse`,
354
324
  * as the device's owner, on the instance that runs) with the last known workspace; an instance
355
325
  * that stopped in between is `device.not_running`. Kernel refusals (offline, files lost, busy,
@@ -358,17 +328,9 @@ let DeviceProjectsService = class DeviceProjectsService {
358
328
  */
359
329
  async onDevice(orgId, accountId, deviceId, scope, signal, fn) {
360
330
  try {
361
- if (permissionContextActive(this.activation)) {
362
- // a stopped device is started for its owner first, as the raw route's use did
363
- await this.sandbox.ensureRunningForOwner({ orgId, deviceId, accountId }, signal);
364
- return await this.sandbox.withBrowse({ orgId, deviceId, accountId }, (b, sig) => fn(browseReader(b, scope.workspace), sig), signal);
365
- }
366
- return await this.sandbox.withSandbox({
367
- orgId,
368
- deviceId,
369
- holderConversationId: PROJECTS_HOLDER,
370
- actor: { accountId, conversationId: PROJECTS_HOLDER },
371
- }, (h, p, info, sig) => fn(heldReader(h, p, info.roots.workspace), sig), signal);
331
+ // a stopped device is started for its owner first
332
+ await this.sandbox.ensureRunningForOwner({ orgId, deviceId, accountId }, signal);
333
+ return await this.sandbox.withBrowse({ orgId, deviceId, accountId }, (b, sig) => fn(browseReader(b, scope.workspace), sig), signal);
372
334
  }
373
335
  catch (e) {
374
336
  if (e instanceof ApiError)
@@ -416,15 +378,10 @@ DeviceProjectsService = __decorate([
416
378
  __param(3, Inject(DeviceAccess)),
417
379
  __param(4, Inject(PermissionFacts)),
418
380
  __param(5, Inject(PermissionCeilingWrites)),
419
- __param(6, Inject(KERNEL_LOGGER)),
420
- __param(7, Optional()),
421
- __param(7, Inject(PERMISSION_CONTEXT_ACTIVATION))
381
+ __param(6, Inject(KERNEL_LOGGER))
422
382
  ], DeviceProjectsService);
423
383
  export { DeviceProjectsService };
424
- /**
425
- * A project read on a device whose sandbox provider cannot be reached (the projects routes, a
426
- * person's project skill invocation).
427
- */
384
+ /** A project read on a device whose sandbox provider cannot be reached (the projects routes). */
428
385
  export const providerUnreachable = () => new ApiError("device.projects_unavailable", "The device's sandbox provider cannot be reached now; try again shortly");
429
386
  const limitReached = () => new ApiError("device.project_limit_reached", `This device already has ${MAX_DEVICE_PROJECTS} projects, the most allowed; remove one first`);
430
387
  /** `path` without a trailing `/` (except `/` itself). */
@@ -444,10 +401,10 @@ function resolve(scope, workspace, relative) {
444
401
  return path;
445
402
  }
446
403
  /**
447
- * An error the projects service passes on as it is: a lost instance or file system (for
448
- * `withSandbox` to handle), a kernel refusal (offline, busy, unavailable), an unreachable provider;
449
- * a malformed device answer becomes `device.projects_unavailable` (the program's fault). Undefined
450
- * for anything else.
404
+ * An error the projects service passes on as it is: a lost instance or file system (for the
405
+ * sandbox service to handle), a kernel refusal (offline, busy, unavailable), an unreachable
406
+ * provider; a malformed device answer becomes `device.projects_unavailable` (the program's fault).
407
+ * Undefined for anything else.
451
408
  */
452
409
  function passThrough(e) {
453
410
  if (isSandboxGoneError(e) || isFileSystemGoneError(e) || e instanceof ApiError)
@@ -488,8 +445,8 @@ async function listFailure(e, r, path, signal, logUnavailable) {
488
445
  if (isProjectPathRefusedError(e)) {
489
446
  return new ApiError("device.project_refused", e.reason.en, [{ reason: e.reason }]);
490
447
  }
491
- // the owner browse scope refusing the path is the device refusing it (gate on only)
492
- if (r.browse && isSandboxScopeDeniedError(e)) {
448
+ // the owner browse scope refusing the path is the device refusing it
449
+ if (isSandboxScopeDeniedError(e)) {
493
450
  return new ApiError("device.project_outside_mode", `The device refused ${clipped(path)}: it is outside what the device lets a project reach`);
494
451
  }
495
452
  let st;