@capybara-hq/kernel 0.1.0-rc.66 → 0.1.0-rc.67

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 (139) hide show
  1. package/bootstrap.json +0 -8
  2. package/dist/admin/admin.schemas.d.ts +3 -0
  3. package/dist/agents/admin-agents.d.ts +2 -2
  4. package/dist/agents/admin-agents.js +2 -1
  5. package/dist/agents/agent-lookup.js +2 -1
  6. package/dist/agents/agent-profile.service.d.ts +5 -2
  7. package/dist/agents/agent-profile.service.js +13 -2
  8. package/dist/agents/agents.controller.d.ts +4 -3
  9. package/dist/agents/agents.controller.js +7 -3
  10. package/dist/agents/agents.module.js +3 -0
  11. package/dist/agents/agents.schemas.d.ts +6 -6
  12. package/dist/agents/agents.service.d.ts +23 -2
  13. package/dist/agents/agents.service.js +61 -6
  14. package/dist/agents/avatar-view.d.ts +8 -0
  15. package/dist/agents/avatar-view.js +12 -0
  16. package/dist/agents/profile.d.ts +38 -13
  17. package/dist/agents/profile.js +31 -20
  18. package/dist/background/poll.job.d.ts +1 -1
  19. package/dist/background/poll.job.js +8 -6
  20. package/dist/background/tasks.service.js +1 -1
  21. package/dist/catalog/marketplaces.service.d.ts +1 -1
  22. package/dist/channels/inbound.d.ts +2 -3
  23. package/dist/channels/inbound.js +2 -3
  24. package/dist/channels/phrases.d.ts +3 -3
  25. package/dist/channels/phrases.js +3 -3
  26. package/dist/config/schema.d.ts +1 -0
  27. package/dist/config/schema.js +14 -1
  28. package/dist/conversations/conversations.service.d.ts +4 -3
  29. package/dist/conversations/conversations.service.js +4 -2
  30. package/dist/ctx/create-ctx.js +5 -2
  31. package/dist/ctx/device-provider-check.d.ts +7 -0
  32. package/dist/ctx/device-provider-check.js +21 -0
  33. package/dist/db/kernel-schema.d.ts +7 -0
  34. package/dist/devices/access.d.ts +16 -46
  35. package/dist/devices/access.js +26 -62
  36. package/dist/devices/access.module.js +2 -2
  37. package/dist/devices/conversation-devices.d.ts +38 -18
  38. package/dist/devices/conversation-devices.js +69 -51
  39. package/dist/devices/default-provider-setting.d.ts +45 -0
  40. package/dist/devices/default-provider-setting.js +59 -0
  41. package/dist/devices/device-projects.service.js +7 -2
  42. package/dist/devices/device-provider-selection.d.ts +37 -0
  43. package/dist/devices/device-provider-selection.js +86 -0
  44. package/dist/devices/device-provider-selection.module.d.ts +3 -0
  45. package/dist/devices/device-provider-selection.module.js +22 -0
  46. package/dist/devices/devices.controller.d.ts +8 -5
  47. package/dist/devices/devices.controller.js +7 -4
  48. package/dist/devices/devices.module.js +3 -1
  49. package/dist/devices/devices.schemas.js +2 -2
  50. package/dist/devices/devices.service.d.ts +72 -83
  51. package/dist/devices/devices.service.js +139 -248
  52. package/dist/devices/dto.d.ts +9 -0
  53. package/dist/devices/dto.js +15 -2
  54. package/dist/devices/label.d.ts +3 -5
  55. package/dist/devices/label.js +3 -14
  56. package/dist/devices/legacy-cleanup.job.d.ts +2 -2
  57. package/dist/devices/legacy-cleanup.job.js +6 -6
  58. package/dist/errors.d.ts +15 -1
  59. package/dist/errors.js +15 -1
  60. package/dist/extensions/guide-places.d.ts +2 -1
  61. package/dist/extensions/guide-places.js +8 -2
  62. package/dist/extensions/locks.d.ts +1 -1
  63. package/dist/extensions/locks.js +1 -1
  64. package/dist/extensions/org-config.d.ts +20 -4
  65. package/dist/extensions/org-config.js +23 -6
  66. package/dist/extensions/permission-view.d.ts +2 -2
  67. package/dist/extensions/permission-view.js +2 -2
  68. package/dist/extensions/plugin-guides.d.ts +1 -1
  69. package/dist/extensions/plugin-guides.js +11 -3
  70. package/dist/extensions/point-defaults.d.ts +14 -0
  71. package/dist/extensions/point-defaults.js +70 -47
  72. package/dist/extensions/resolve.js +7 -2
  73. package/dist/identity/settings.d.ts +8 -0
  74. package/dist/identity/settings.js +24 -1
  75. package/dist/infra/config/kernel-config.service.js +2 -0
  76. package/dist/lifecycle/kernel-lifecycle.js +7 -6
  77. package/dist/local-devices/device-routes.d.ts +1 -1
  78. package/dist/local-devices/device-routes.js +1 -1
  79. package/dist/local-devices/local-device-provider.d.ts +14 -11
  80. package/dist/local-devices/local-device-provider.js +14 -0
  81. package/dist/local-devices/local-devices.module.d.ts +4 -4
  82. package/dist/local-devices/local-devices.module.js +5 -3
  83. package/dist/local-devices/owner-report.js +2 -1
  84. package/dist/local-devices/targets.d.ts +2 -0
  85. package/dist/local-devices/targets.js +10 -0
  86. package/dist/orgs/settings.service.d.ts +26 -1
  87. package/dist/orgs/settings.service.js +44 -3
  88. package/dist/platform/ops/admin.ops.js +8 -3
  89. package/dist/platform/ops/agents.ops.d.ts +6 -1
  90. package/dist/platform/ops/agents.ops.js +38 -11
  91. package/dist/platform/ops/devices.ops.js +25 -20
  92. package/dist/platform/ops/orgs.ops.js +1 -0
  93. package/dist/platform/ops/themes.ops.js +1 -1
  94. package/dist/runtime/plugin-context.service.js +1 -12
  95. package/dist/sandbox/cloud-permission-snapshot.d.ts +2 -2
  96. package/dist/sandbox/cloud-permission-snapshot.js +3 -3
  97. package/dist/sandbox/device-reports.d.ts +50 -0
  98. package/dist/sandbox/device-reports.js +157 -0
  99. package/dist/sandbox/held-operations.d.ts +8 -8
  100. package/dist/sandbox/leases.d.ts +1 -1
  101. package/dist/sandbox/leases.js +1 -1
  102. package/dist/sandbox/operation-authority.d.ts +5 -2
  103. package/dist/sandbox/operation-authority.js +12 -11
  104. package/dist/sandbox/operation-reconcile.job.d.ts +2 -2
  105. package/dist/sandbox/operation-reconcile.job.js +5 -5
  106. package/dist/sandbox/permission-availability.d.ts +2 -2
  107. package/dist/sandbox/permission-call-types.d.ts +5 -0
  108. package/dist/sandbox/permission-facts.d.ts +2 -2
  109. package/dist/sandbox/permission-facts.js +5 -5
  110. package/dist/sandbox/providers.d.ts +23 -24
  111. package/dist/sandbox/providers.js +38 -46
  112. package/dist/sandbox/providers.module.js +3 -3
  113. package/dist/sandbox/sandbox.module.d.ts +1 -1
  114. package/dist/sandbox/sandbox.module.js +7 -2
  115. package/dist/sandbox/sandbox.service.d.ts +95 -68
  116. package/dist/sandbox/sandbox.service.js +212 -208
  117. package/dist/setup/setup-guides.service.d.ts +4 -1
  118. package/dist/setup/setup-guides.service.js +6 -1
  119. package/dist/themes/avatar-preset-key.d.ts +6 -0
  120. package/dist/themes/avatar-preset-key.js +9 -0
  121. package/dist/themes/theme-state.d.ts +29 -1
  122. package/dist/themes/theme-state.js +40 -1
  123. package/dist/themes/themes.service.d.ts +28 -1
  124. package/dist/themes/themes.service.js +36 -2
  125. package/dist/tools/builtins/image/generate.d.ts +3 -0
  126. package/dist/tools/builtins/image/generate.js +21 -11
  127. package/dist/tools/builtins/image/index.d.ts +1 -1
  128. package/dist/tools/builtins/image/index.js +1 -1
  129. package/dist/tools/builtins/sandbox/common.d.ts +36 -12
  130. package/dist/tools/builtins/sandbox/common.js +62 -18
  131. package/dist/tools/builtins/sandbox/read.d.ts +5 -2
  132. package/dist/tools/builtins/sandbox/read.js +9 -6
  133. package/dist/tools/builtins/sandbox/task-output.d.ts +2 -2
  134. package/dist/tools/builtins/sandbox/task-output.js +6 -5
  135. package/dist/tools/builtins/skill-load.js +13 -4
  136. package/dist/until-aborted.d.ts +5 -0
  137. package/dist/until-aborted.js +16 -0
  138. package/package.json +4 -4
  139. package/src/migrations/0176_device_report.sql +6 -0
@@ -168,64 +168,87 @@ let ExtensionPointDefaults = class ExtensionPointDefaults {
168
168
  const out = [];
169
169
  const failed = new Set();
170
170
  for (const [extension, impl] of providers) {
171
- let cfg;
172
- try {
173
- cfg = await this.orgConfigs.get(orgId, extension);
174
- }
175
- catch (err) {
176
- // a stored org config that no longer validates is a known state: the provider is off
177
- // (as for an invalid effective config below); only a read that failed is `failed`
178
- const invalid = err instanceof OrgConfigInvalidError;
179
- this.log.warn(invalid
180
- ? "extension point provider excluded, its stored org config is invalid"
181
- : "extension point provider excluded, cannot read its org config", { orgId, point, extension, err });
182
- if (!invalid)
183
- failed.add(extension);
184
- continue;
185
- }
186
- if (!cfg?.enabled)
187
- continue;
188
- // spec A §6: an org whose effective config is not valid gets no call from this extension
189
- let effective;
171
+ const c = await this.evaluate(orgId, point, extension, impl, failed);
172
+ if (c)
173
+ out.push(c);
174
+ }
175
+ out.sort((a, b) => (a.extension < b.extension ? -1 : a.extension > b.extension ? 1 : 0));
176
+ return { candidates: out, failed };
177
+ }
178
+ /**
179
+ * Whether the one provider `extension` of `point` evaluates as a candidate in `orgId`. The
180
+ * provider must be loaded on this replica and provide `point`; the org must have it enabled; its
181
+ * org config and effective config must be valid; and its `configured()` must not return false.
182
+ * These are exactly the criteria of {@link providersFor} / {@link resolve}, with only that one
183
+ * provider evaluated. A provider whose status cannot be read counts as not serving (logged).
184
+ */
185
+ async serves(orgId, point, extension) {
186
+ const entry = this.registry.list(point).find((e) => e.plugin === extension);
187
+ if (!entry || !(await isExtensionEnabled(this.kdb.db, orgId, extension)))
188
+ return false;
189
+ return (await this.evaluate(orgId, point, extension, entry.impl, new Set())) !== undefined;
190
+ }
191
+ /**
192
+ * One enabled provider's candidacy: valid org config, valid effective config and `configured()`
193
+ * not false. Undefined when it is off; a provider whose status could not be read is also added
194
+ * to `failed`.
195
+ */
196
+ async evaluate(orgId, point, extension, impl, failed) {
197
+ let cfg;
198
+ try {
199
+ cfg = await this.orgConfigs.get(orgId, extension);
200
+ }
201
+ catch (err) {
202
+ // a stored org config that no longer validates is a known state: the provider is off
203
+ // (as for an invalid effective config below); only a read that failed is `failed`
204
+ const invalid = err instanceof OrgConfigInvalidError;
205
+ this.log.warn(invalid
206
+ ? "extension point provider excluded, its stored org config is invalid"
207
+ : "extension point provider excluded, cannot read its org config", { orgId, point, extension, err });
208
+ if (!invalid)
209
+ failed.add(extension);
210
+ return undefined;
211
+ }
212
+ if (!cfg?.enabled)
213
+ return undefined;
214
+ // spec A §6: an org whose effective config is not valid gets no call from this extension
215
+ let effective;
216
+ try {
217
+ effective = await this.effective.get(orgId, extension);
218
+ }
219
+ catch (err) {
220
+ this.log.warn("extension point provider excluded, cannot read its effective config", {
221
+ orgId,
222
+ point,
223
+ extension,
224
+ err,
225
+ });
226
+ failed.add(extension);
227
+ return undefined;
228
+ }
229
+ if (!effective.ok)
230
+ return undefined;
231
+ const configured = impl
232
+ .configured;
233
+ if (typeof configured === "function") {
234
+ let ok;
190
235
  try {
191
- effective = await this.effective.get(orgId, extension);
236
+ ok = configured.call(impl, cfg.config, effective.config) !== false;
192
237
  }
193
238
  catch (err) {
194
- this.log.warn("extension point provider excluded, cannot read its effective config", {
239
+ this.log.warn("extension point provider excluded, configured() threw", {
195
240
  orgId,
196
241
  point,
197
242
  extension,
198
243
  err,
199
244
  });
200
245
  failed.add(extension);
201
- continue;
202
- }
203
- if (!effective.ok)
204
- continue;
205
- const configured = impl
206
- .configured;
207
- if (typeof configured === "function") {
208
- let ok;
209
- try {
210
- ok = configured.call(impl, cfg.config, effective.config) !== false;
211
- }
212
- catch (err) {
213
- this.log.warn("extension point provider excluded, configured() threw", {
214
- orgId,
215
- point,
216
- extension,
217
- err,
218
- });
219
- failed.add(extension);
220
- continue;
221
- }
222
- if (!ok)
223
- continue;
246
+ return undefined;
224
247
  }
225
- out.push({ extension, impl, orgConfig: cfg.config, config: effective.config });
248
+ if (!ok)
249
+ return undefined;
226
250
  }
227
- out.sort((a, b) => (a.extension < b.extension ? -1 : a.extension > b.extension ? 1 : 0));
228
- return { candidates: out, failed };
251
+ return { extension, impl, orgConfig: cfg.config, config: effective.config };
229
252
  }
230
253
  async choose(orgId, point, candidates) {
231
254
  if (candidates.length < 2)
@@ -99,8 +99,13 @@ export function resolveExtensions(manifests, sdkVersion) {
99
99
  for (const m of manifests) {
100
100
  for (const ref of m.provides) {
101
101
  const { name, major } = parseExtensionPoint(ref);
102
- const majors = EXTENSION_POINTS[name]?.majors;
103
- if (majors && !majors.includes(major)) {
102
+ const majors = Object.hasOwn(EXTENSION_POINTS, name)
103
+ ? EXTENSION_POINTS[name]?.majors
104
+ : undefined;
105
+ if (!majors) {
106
+ throw new ExtensionResolveError(`Plugin ${m.name} provides ${ref}, which this kernel does not know.`, "extension.unsupported_extension_point");
107
+ }
108
+ if (!majors.includes(major)) {
104
109
  throw new ExtensionResolveError(`Plugin ${m.name} provides ${ref}, which this kernel no longer supports; upgrade it to a version that provides ${name}@${Math.max(...majors)}.`, "extension.unsupported_extension_point");
105
110
  }
106
111
  }
@@ -1,6 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { type PlatformAttributionPatch, type PlatformAttributionStored, type PlatformAttributionView } from "../attribution/platform-attribution.js";
3
3
  import type { KernelSchemaDb } from "../db/kernel-schema.js";
4
+ import { type DevicesDefaultProviderPatch, type DevicesDefaultProviderView } from "../devices/default-provider-setting.js";
4
5
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
5
6
  import { KernelDb } from "../infra/database/kernel-db.js";
6
7
  import { TransactionHost } from "../infra/database/transaction-host.js";
@@ -173,6 +174,8 @@ export type DeploymentSettingsView = DeploymentSettings & {
173
174
  devicesOutsideSandbox: DevicesOutsideSandboxView;
174
175
  /** The sandbox network's default and ceiling (the default never above the ceiling). */
175
176
  devicesNetwork: DevicesNetworkView;
177
+ /** The device provider that makes a person's default device (null: none) and its source. */
178
+ devicesDefaultProvider: DevicesDefaultProviderView;
176
179
  attribution: PlatformAttributionView;
177
180
  /** The platform's external sharing switch in effect and where it comes from. */
178
181
  externalSharing: ExternalSharingView;
@@ -246,6 +249,9 @@ export declare const DEPLOYMENT_SETTINGS_PATCH: z.ZodObject<{
246
249
  open: "open";
247
250
  }>>>;
248
251
  }, z.core.$strict>>;
252
+ devicesDefaultProvider: z.ZodOptional<z.ZodObject<{
253
+ provider: z.ZodNullable<z.ZodString>;
254
+ }, z.core.$strict>>;
249
255
  attribution: z.ZodOptional<z.ZodObject<{
250
256
  commit: z.ZodOptional<z.ZodNullable<z.ZodString>>;
251
257
  pr: z.ZodOptional<z.ZodNullable<z.ZodString>>;
@@ -370,6 +376,8 @@ export declare class SettingsService {
370
376
  checkSharing(patch: Pick<DeploymentSettingsPatch, "externalSharing" | "shareMaxExpiryDays" | "htmlRenderCdnAllowlist">, opts?: {
371
377
  onlyNarrows?: boolean;
372
378
  }): Promise<void>;
379
+ /** Refuses a `devicesDefaultProvider` change while the startup config sets it. */
380
+ checkDefaultProvider(_patch: DevicesDefaultProviderPatch): void;
373
381
  /**
374
382
  * The refusals of an `attribution` change against the stored choice: a field set in the startup
375
383
  * config (`deployment.setting_readonly`). Returns the next stored choice.
@@ -12,6 +12,7 @@ import { Inject, Injectable } from "@nestjs/common";
12
12
  import { z } from "zod";
13
13
  import { applyPlatformAttributionPatch, PLATFORM_ATTRIBUTION_FIELDS, PLATFORM_ATTRIBUTION_PATCH, PLATFORM_ATTRIBUTION_SETTING, readStoredPlatformAttribution, resolvePlatformAttribution, } from "../attribution/platform-attribution.js";
14
14
  import { productName } from "../config/product-name.js";
15
+ import { DEVICES_DEFAULT_PROVIDER_PATCH, DEVICES_DEFAULT_PROVIDER_SETTING, readPlatformDefaultProvider, } from "../devices/default-provider-setting.js";
15
16
  import { ApiError } from "../errors.js";
16
17
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
17
18
  import { KernelDb } from "../infra/database/kernel-db.js";
@@ -305,6 +306,12 @@ export const DEPLOYMENT_SETTINGS_PATCH = z
305
306
  * startup config is read-only (409 `deployment.setting_readonly`).
306
307
  */
307
308
  devicesNetwork: DEVICES_NETWORK_PATCH.optional(),
309
+ /**
310
+ * The platform's default device provider (the `device-provider@1` extension that makes a
311
+ * person's default device): `provider` replaced, null clears it (back to none). A value set in
312
+ * the startup config is read-only (409 `deployment.setting_readonly`).
313
+ */
314
+ devicesDefaultProvider: DEVICES_DEFAULT_PROVIDER_PATCH.optional(),
308
315
  /**
309
316
  * The platform's attribution defaults for agent-created git commits and pull requests (spec
310
317
  * 2026-11-14-agent-attribution): each given field replaces the stored one, null clears it
@@ -516,18 +523,20 @@ let SettingsService = class SettingsService {
516
523
  }
517
524
  /** The settings with the platform's device sandbox settings and attribution defaults in effect. */
518
525
  async view() {
519
- const [settings, deviceSandbox, attribution, externalSharing, shareMaxExpiryDays, promptSuggestions,] = await Promise.all([
526
+ const [settings, deviceSandbox, attribution, externalSharing, shareMaxExpiryDays, promptSuggestions, devicesDefaultProvider,] = await Promise.all([
520
527
  this.get(),
521
528
  readDeviceSandboxSettingsView(this.db.db, this.config, this.log),
522
529
  readStoredPlatformAttribution(this.db.db, this.log),
523
530
  readExternalSharing(this.db.db, this.config, this.log),
524
531
  readShareMaxExpiry(this.db.db, this.config, this.log),
525
532
  readPromptSuggestions(this.db.db, this.log),
533
+ readPlatformDefaultProvider(this.config, this.db.db, this.log),
526
534
  ]);
527
535
  return {
528
536
  ...settings,
529
537
  devicesOutsideSandbox: deviceSandbox.outsideSandbox,
530
538
  devicesNetwork: deviceSandbox.network,
539
+ devicesDefaultProvider,
531
540
  attribution: this.attributionView(attribution),
532
541
  externalSharing,
533
542
  shareMaxExpiryDays,
@@ -658,6 +667,13 @@ let SettingsService = class SettingsService {
658
667
  throw sharingWidenRefused("htmlRenderCdnAllowlist", `Adding origins to the HTML CDN allowlist (${added.join(", ")}) needs a super admin in the admin console; an API token or the Platform tool may only remove origins.`);
659
668
  }
660
669
  }
670
+ /** Refuses a `devicesDefaultProvider` change while the startup config sets it. */
671
+ checkDefaultProvider(_patch) {
672
+ const source = this.config.fieldSource("devices.defaultProvider");
673
+ if (source === undefined)
674
+ return;
675
+ throw new ApiError("deployment.setting_readonly", "The default device provider is set in the startup config (file, Nacos or environment) and is read-only here: devicesDefaultProvider", [{ path: "devicesDefaultProvider.provider", source }]);
676
+ }
661
677
  /**
662
678
  * The refusals of an `attribution` change against the stored choice: a field set in the startup
663
679
  * config (`deployment.setting_readonly`). Returns the next stored choice.
@@ -918,6 +934,13 @@ let SettingsService = class SettingsService {
918
934
  writes.push([key, value]);
919
935
  }
920
936
  }
937
+ if (patch.devicesDefaultProvider !== undefined) {
938
+ this.checkDefaultProvider(patch.devicesDefaultProvider);
939
+ if (patch.devicesDefaultProvider.provider === null)
940
+ deletes.push(DEVICES_DEFAULT_PROVIDER_SETTING);
941
+ else
942
+ writes.push([DEVICES_DEFAULT_PROVIDER_SETTING, patch.devicesDefaultProvider]);
943
+ }
921
944
  if (patch.promptSuggestions === null)
922
945
  deletes.push(PROMPT_SUGGESTIONS_SETTING);
923
946
  else if (patch.promptSuggestions !== undefined) {
@@ -59,6 +59,8 @@ const HOT_APPLIERS = {
59
59
  "devices.outsideSandbox": () => { },
60
60
  "devices.network.default": () => { },
61
61
  "devices.network.ceiling": () => { },
62
+ // The default device provider is read live at every default device creation and settings read.
63
+ "devices.defaultProvider": () => { },
62
64
  // The devices service reads the personal limit at every create.
63
65
  "devices.maxPersonal": () => { },
64
66
  // The local device relay reads the reconnect grace at every disconnect and token response.
@@ -7,7 +7,7 @@ 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 { SANDBOX_EXTENSION_POINT } from "@capybara-hq/plugin-sdk";
10
+ 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";
@@ -287,11 +287,12 @@ let KernelLifecycle = class KernelLifecycle {
287
287
  },
288
288
  });
289
289
  this.checkpoint();
290
- const sandboxEntry = this.host
291
- .list("sandbox")
292
- .find((x) => x.capability === SANDBOX_EXTENSION_POINT);
293
- if (sandboxEntry !== undefined) {
294
- for (const w of sandboxConfigWarnings(cfg(), sandboxEntry.plugin)) {
290
+ const deviceProviders = this.host
291
+ .list("device-provider")
292
+ .filter((x) => x.capability === DEVICE_PROVIDER_EXTENSION_POINT)
293
+ .map((x) => x.plugin);
294
+ if (deviceProviders.length > 0) {
295
+ for (const w of sandboxConfigWarnings(cfg(), deviceProviders)) {
295
296
  this.log[w.level](w.message);
296
297
  }
297
298
  }
@@ -26,7 +26,7 @@ export declare function isWebSocketUpgrade(req: FastifyRequest): boolean;
26
26
  * `@fastify/websocket`: a raw Fastify route outside Nest, so neither the API's `AuthGuard` nor its
27
27
  * CSRF check applies; the route checks the machine credential itself, before the upgrade (401
28
28
  * `device.credential_invalid`), then the protocol header (426 `device.program_outdated`): only
29
- * {@link DEVICE_PROTOCOL_VERSION} (4) is served; an older program (protocol 3 among them) must
29
+ * {@link DEVICE_PROTOCOL_VERSION} (5) is served; an older program (protocol 4 among them) must
30
30
  * update. A newer program reads the kernel's protocol in the message and asks for the deployment
31
31
  * to be upgraded instead.
32
32
  * Must be called before Nest `app.init()`, on the root instance.
@@ -37,7 +37,7 @@ function bearer(req) {
37
37
  * `@fastify/websocket`: a raw Fastify route outside Nest, so neither the API's `AuthGuard` nor its
38
38
  * CSRF check applies; the route checks the machine credential itself, before the upgrade (401
39
39
  * `device.credential_invalid`), then the protocol header (426 `device.program_outdated`): only
40
- * {@link DEVICE_PROTOCOL_VERSION} (4) is served; an older program (protocol 3 among them) must
40
+ * {@link DEVICE_PROTOCOL_VERSION} (5) is served; an older program (protocol 4 among them) must
41
41
  * update. A newer program reads the kernel's protocol in the message and asks for the deployment
42
42
  * to be upgraded instead.
43
43
  * Must be called before Nest `app.init()`, on the root instance.
@@ -1,4 +1,4 @@
1
- import type { FileSystemHandle, SandboxHandle, SandboxLimits, SandboxProvider, SandboxRoots } from "@capybara-hq/plugin-sdk";
1
+ import type { DeviceProvider, DeviceRef, DeviceReport, FileSystemHandle, SandboxHandle, SandboxLimits, SandboxRoots } from "@capybara-hq/plugin-sdk";
2
2
  import { type DeviceOperation, type SandboxPermissionSupport } from "@capybara-hq/plugin-sdk";
3
3
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
4
4
  import { PermissionCallGrants } from "../sandbox/permission-call-grants.js";
@@ -52,15 +52,18 @@ export declare const deviceIdOfName: (name: string) => string | undefined;
52
52
  * The files on a machine are its owner's: `destroyFileSystem` (a files reset, the deletion sweep)
53
53
  * does nothing; the deletion's `stop` comes from `MachinesService.revokeActive` (ruling R24).
54
54
  */
55
- export declare class LocalDeviceProvider implements SandboxProvider {
55
+ export declare class LocalDeviceProvider implements DeviceProvider {
56
56
  private readonly relay;
57
57
  private readonly targets;
58
58
  private readonly sandbox;
59
59
  private readonly config;
60
60
  private readonly callGrants?;
61
61
  readonly concurrentExec: true;
62
+ readonly networkAllowlist: true;
62
63
  readonly sessionIsolation = false;
63
- constructor(relay: LocalDeviceRelay, targets: Pick<DeviceTargets, "orgOf" | "machineRoots">, sandbox: Pick<SandboxService, "devicePolicy" | "deviceLimits" | "hostGrantCeiling">, config: Pick<KernelConfigService, "get">, callGrants?: PermissionCallGrants | undefined);
64
+ /** What the kernel tells about a local device: fixed text, the machine's home, nothing to reset. */
65
+ report(device: DeviceRef, _signal: AbortSignal): Promise<DeviceReport>;
66
+ constructor(relay: LocalDeviceRelay, targets: Pick<DeviceTargets, "orgOf" | "machineRoots" | "machineHome">, sandbox: Pick<SandboxService, "devicePolicy" | "deviceLimits" | "hostGrantCeiling">, config: Pick<KernelConfigService, "get">, callGrants?: PermissionCallGrants | undefined);
64
67
  /**
65
68
  * The `@local` provider as the staged (protocol 4) registration hands it out
66
69
  * (`LocalDevicesModule`): the protocol 2 lifecycle methods that send no frame (file system,
@@ -80,9 +83,9 @@ export declare class LocalDeviceProvider implements SandboxProvider {
80
83
  * on an incarnation nobody else holds (a resume, a failed limits change, a quarantine), every
81
84
  * started-or-unknown intent of that generation; the owed revokes are delivered by operation id.
82
85
  */
83
- staged(transport: StagedDeviceTransport): SandboxProvider;
86
+ staged(transport: StagedDeviceTransport): DeviceProvider;
84
87
  /** Dormant v3 adapter. It is not installed on the active v2 registered provider. */
85
- stagedOperations(transport: StagedDeviceTransport): Required<Pick<SandboxProvider, "operation" | "prepare" | "browse" | "permissionSupport" | "revokeOperation" | "background">>;
88
+ stagedOperations(transport: StagedDeviceTransport): Required<Pick<DeviceProvider, "operation" | "prepare" | "browse" | "permissionSupport" | "revokeOperation" | "background">>;
86
89
  createFileSystem(args: {
87
90
  name: string;
88
91
  limits: SandboxLimits;
@@ -110,10 +113,10 @@ export declare class LocalDeviceProvider implements SandboxProvider {
110
113
  /** A v3 machine has no broad kill (permission runtime cutover B-1): nothing is queued. */
111
114
  killAll(_h: SandboxHandle, signal: AbortSignal): Promise<void>;
112
115
  killTagged(_h: SandboxHandle, _tags: string[], signal: AbortSignal): Promise<void>;
113
- readonly exec: SandboxProvider["exec"];
114
- readonly readFile: SandboxProvider["readFile"];
115
- readonly writeFile: SandboxProvider["writeFile"];
116
- readonly stat: SandboxProvider["stat"];
117
- readonly list: NonNullable<SandboxProvider["list"]>;
118
- readonly scan: NonNullable<SandboxProvider["scan"]>;
116
+ readonly exec: DeviceProvider["exec"];
117
+ readonly readFile: DeviceProvider["readFile"];
118
+ readonly writeFile: DeviceProvider["writeFile"];
119
+ readonly stat: DeviceProvider["stat"];
120
+ readonly list: NonNullable<DeviceProvider["list"]>;
121
+ readonly scan: NonNullable<DeviceProvider["scan"]>;
119
122
  }
@@ -61,7 +61,21 @@ let LocalDeviceProvider = class LocalDeviceProvider {
61
61
  config;
62
62
  callGrants;
63
63
  concurrentExec = true;
64
+ networkAllowlist = true;
64
65
  sessionIsolation = false;
66
+ /** What the kernel tells about a local device: fixed text, the machine's home, nothing to reset. */
67
+ async report(device, _signal) {
68
+ return {
69
+ revision: "local-1",
70
+ description: {
71
+ en: "Runs on a computer connected with capybara-device; the computer's owner limits it there.",
72
+ zh: "运行在用 capybara-device 连接的电脑上,电脑的主人在本机限制它。",
73
+ },
74
+ home: await this.targets.machineHome(device.deviceId),
75
+ limits: [],
76
+ reset: false,
77
+ };
78
+ }
65
79
  constructor(relay, targets, sandbox, config, callGrants) {
66
80
  this.relay = relay;
67
81
  this.targets = targets;
@@ -1,11 +1,11 @@
1
1
  import { type OnModuleInit } from "@nestjs/common";
2
- import { type SandboxProviderEntry, SandboxProviders } from "../sandbox/providers.js";
2
+ import { type DeviceProviderEntry, DeviceProviders } from "../sandbox/providers.js";
3
3
  import { LocalInstanceBindings } from "./instance-bindings.js";
4
4
  import { LocalDeviceProvider } from "./local-device-provider.js";
5
5
  import { LocalDeviceRelay } from "./relay.js";
6
6
  /**
7
7
  * Connected machines (environments spec §6, §13): the caller side of the device relay and the
8
- * kernel-internal `@local` sandbox provider, registered with {@link SandboxProviders} on init, and
8
+ * kernel-internal `@local` sandbox provider, registered with {@link DeviceProviders} on init, and
9
9
  * the machines and their credentials ({@link MachinesService}), changes to a device's network
10
10
  * policy ({@link DevicePolicyService}) and the run grants sent with each exec ({@link NetworkGrants}).
11
11
  * Imported on every role: any replica may run a sandbox operation on a local device
@@ -16,7 +16,7 @@ export declare class LocalDevicesModule implements OnModuleInit {
16
16
  private readonly provider;
17
17
  private readonly relay;
18
18
  private readonly bindings;
19
- constructor(providers: SandboxProviders, provider: LocalDeviceProvider, relay: LocalDeviceRelay, bindings: LocalInstanceBindings);
19
+ constructor(providers: DeviceProviders, provider: LocalDeviceProvider, relay: LocalDeviceRelay, bindings: LocalInstanceBindings);
20
20
  onModuleInit(): void;
21
21
  }
22
22
  /**
@@ -28,4 +28,4 @@ export declare function localProviderEntry(deps: {
28
28
  provider: LocalDeviceProvider;
29
29
  relay: LocalDeviceRelay;
30
30
  bindings: LocalInstanceBindings;
31
- }): SandboxProviderEntry;
31
+ }): DeviceProviderEntry;
@@ -9,9 +9,10 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
9
9
  };
10
10
  import { Inject, Module } from "@nestjs/common";
11
11
  import { PermissionCallGrantsModule } from "../sandbox/permission-call-grants.module.js";
12
- import { LOCAL_PROVIDER, SandboxProviders, } from "../sandbox/providers.js";
12
+ import { DeviceProviders, LOCAL_PROVIDER } from "../sandbox/providers.js";
13
13
  import { SandboxProviderRegistryModule } from "../sandbox/providers.module.js";
14
14
  import { SandboxModule } from "../sandbox/sandbox.module.js";
15
+ import { KERNEL_VERSION } from "../version.js";
15
16
  import { DevicePolicyService } from "./device-policy.service.js";
16
17
  import { LocalInstanceBindings } from "./instance-bindings.js";
17
18
  import { LocalDeviceProvider } from "./local-device-provider.js";
@@ -23,7 +24,7 @@ import { LocalDeviceRelay } from "./relay.js";
23
24
  import { DeviceTargets } from "./targets.js";
24
25
  /**
25
26
  * Connected machines (environments spec §6, §13): the caller side of the device relay and the
26
- * kernel-internal `@local` sandbox provider, registered with {@link SandboxProviders} on init, and
27
+ * kernel-internal `@local` sandbox provider, registered with {@link DeviceProviders} on init, and
27
28
  * the machines and their credentials ({@link MachinesService}), changes to a device's network
28
29
  * policy ({@link DevicePolicyService}) and the run grants sent with each exec ({@link NetworkGrants}).
29
30
  * Imported on every role: any replica may run a sandbox operation on a local device
@@ -75,7 +76,7 @@ LocalDevicesModule = __decorate([
75
76
  OwnerReports,
76
77
  ],
77
78
  }),
78
- __param(0, Inject(SandboxProviders)),
79
+ __param(0, Inject(DeviceProviders)),
79
80
  __param(1, Inject(LocalDeviceProvider)),
80
81
  __param(2, Inject(LocalDeviceRelay)),
81
82
  __param(3, Inject(LocalInstanceBindings))
@@ -89,6 +90,7 @@ export { LocalDevicesModule };
89
90
  export function localProviderEntry(deps) {
90
91
  return {
91
92
  plugin: LOCAL_PROVIDER,
93
+ version: KERNEL_VERSION,
92
94
  impl: deps.provider.staged({
93
95
  call: deps.relay.callV3.bind(deps.relay),
94
96
  permissionSupport: (deviceId) => deps.bindings.permissionSupport(deviceId),
@@ -131,7 +131,8 @@ export function ownerReportRevokes(next, scope, method, grantedHosts, machineRoo
131
131
  export function outsideMachineRoots(scope, machineRoots) {
132
132
  if (machineRoots === undefined || !("profile" in scope) || scope.filesystem.kind !== "scoped")
133
133
  return false;
134
- return [...scope.filesystem.readRoots, ...scope.filesystem.writeRoots].some((r) => !machineRoots.some((m) => within(r, m)));
134
+ const { projectRoot, writeRoots } = scope.filesystem;
135
+ return [...(projectRoot === null ? [] : [projectRoot]), ...writeRoots].some((r) => !machineRoots.some((m) => within(r, m)));
135
136
  }
136
137
  /** The machine's reported roots as a list (workspace, tmp, skills ...), or none. */
137
138
  export function machineRootList(roots) {
@@ -52,6 +52,8 @@ export declare class DeviceTargets {
52
52
  * active machine, or none reported yet).
53
53
  */
54
54
  machineRoots(deviceId: string): Promise<SandboxRoots | null>;
55
+ /** The owner's home directory the active machine reported in its hello, or null. */
56
+ machineHome(deviceId: string): Promise<string | null>;
55
57
  /**
56
58
  * The features the device's active machine announced in its last hello (known ones only);
57
59
  * empty without an active machine.
@@ -113,6 +113,16 @@ let DeviceTargets = class DeviceTargets {
113
113
  return null;
114
114
  return r;
115
115
  }
116
+ /** The owner's home directory the active machine reported in its hello, or null. */
117
+ async machineHome(deviceId) {
118
+ const row = await this.db
119
+ .selectFrom("device_machines")
120
+ .select("home")
121
+ .where("device_id", "=", deviceId)
122
+ .where("revoked_at", "is", null)
123
+ .executeTakeFirst();
124
+ return row?.home ?? null;
125
+ }
116
126
  /**
117
127
  * The features the device's active machine announced in its last hello (known ones only);
118
128
  * empty without an active machine.
@@ -2,6 +2,7 @@ import type { SandboxLimits } from "@capybara-hq/plugin-sdk";
2
2
  import { z } from "zod";
3
3
  import { type PlatformAttribution } from "../attribution/platform-attribution.js";
4
4
  import type { KernelSchemaDb } from "../db/kernel-schema.js";
5
+ import type { ExtensionPointDefaults } from "../extensions/point-defaults.js";
5
6
  import { type CompactionSettings } from "../identity/settings.js";
6
7
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
7
8
  import { KernelDb } from "../infra/database/kernel-db.js";
@@ -36,6 +37,10 @@ import { OrgLock } from "./org-lock.js";
36
37
  * a default or ceiling above the platform's ceiling is refused.
37
38
  * Old keys are read and kept in step until the permission configuration publication converts
38
39
  * them ({@link orgDeviceSandboxOf}).
40
+ * - `deviceDefaultProvider`: the org's override of the platform's default device provider (the
41
+ * `device-provider@1` extension that makes a member's default device); absent follows the
42
+ * platform, an invalid stored value reads as absent. Only a provider that is on in the org may
43
+ * be set (400 `org.device_provider_not_available`).
39
44
  * - `platformTool`: the `Platform` builtin for the whole org (Platform tool spec §3): `on`,
40
45
  * `read-only` (writes listed as unavailable) or `off` (default `on`).
41
46
  * - `timeZone`: the org's default time zone (IANA; absent = UTC) for senders without one of their
@@ -167,6 +172,7 @@ export declare const OrgSettingsSchema: z.ZodObject<{
167
172
  extraHosts: z.ZodOptional<z.ZodArray<z.ZodString>>;
168
173
  excludedHosts: z.ZodOptional<z.ZodArray<z.ZodString>>;
169
174
  }, z.core.$strict>>>;
175
+ deviceDefaultProvider: z.ZodCatch<z.ZodOptional<z.ZodString>>;
170
176
  wakeOnBackgroundTask: z.ZodCatch<z.ZodOptional<z.ZodBoolean>>;
171
177
  timeZone: z.ZodCatch<z.ZodOptional<z.ZodString>>;
172
178
  theme: z.ZodCatch<z.ZodOptional<z.ZodObject<{
@@ -243,6 +249,7 @@ export declare const OrgSettingsPatchSchema: z.ZodObject<{
243
249
  on: "on";
244
250
  "read-only": "read-only";
245
251
  }>>;
252
+ deviceDefaultProvider: z.ZodOptional<z.ZodNullable<z.ZodString>>;
246
253
  wakeOnBackgroundTask: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
247
254
  outsideSandbox: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
248
255
  allowed: "allowed";
@@ -440,12 +447,28 @@ export declare class OrgSettingsService {
440
447
  private readonly config;
441
448
  private readonly ceilings;
442
449
  private readonly log?;
450
+ /**
451
+ * Finds {@link ExtensionPointDefaults} (`deviceDefaultProvider` is checked against the
452
+ * providers on in the org) at the time of use: the extensions module cannot be imported here
453
+ * without a module cycle.
454
+ */
455
+ private readonly modules?;
443
456
  constructor(db: KernelDb, txHost: TransactionHost, orgLock: OrgLock,
444
457
  /**
445
458
  * The deployment config: `sandbox.limits` and the platform's device sandbox settings
446
459
  * (`devices.outsideSandbox`, `devices.network`; the org may follow them, never exceed them).
447
460
  */
448
- config: Pick<KernelConfigService, "get" | "fieldSource">, ceilings: PermissionCeilingWrites, log?: KernelLogger | undefined);
461
+ config: Pick<KernelConfigService, "get" | "fieldSource">, ceilings: PermissionCeilingWrites, log?: KernelLogger | undefined,
462
+ /**
463
+ * Finds {@link ExtensionPointDefaults} (`deviceDefaultProvider` is checked against the
464
+ * providers on in the org) at the time of use: the extensions module cannot be imported here
465
+ * without a module cycle.
466
+ */
467
+ modules?: {
468
+ get(token: typeof ExtensionPointDefaults, opts: {
469
+ strict: false;
470
+ }): Pick<ExtensionPointDefaults, "providersFor">;
471
+ } | undefined);
449
472
  /** Parses stored settings, warning when an invalid `outsideSandbox` narrows to `off`, an
450
473
  * invalid `deviceNetwork` to an empty allowlist, or a security setting reads narrower
451
474
  * ({@link logUnreadableSecuritySettings}, warn). */
@@ -487,6 +510,8 @@ export declare class OrgSettingsService {
487
510
  opts?: {
488
511
  onlyNarrows?: boolean;
489
512
  }): Promise<OrgSettingsView>;
513
+ /** Refuses a `deviceDefaultProvider` that is not a `device-provider@1` extension on in the org. */
514
+ private assertDeviceProviderOn;
490
515
  private lockFor;
491
516
  /**
492
517
  * Refuses a patch that widens the org's sandbox (only a person widens it, never the Platform tool