@capybara-hq/kernel 0.1.0-rc.65 → 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 (177) 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/attribution/platform-attribution.d.ts +15 -6
  19. package/dist/attribution/platform-attribution.js +31 -14
  20. package/dist/background/poll.job.d.ts +1 -1
  21. package/dist/background/poll.job.js +8 -6
  22. package/dist/background/tasks.service.js +1 -1
  23. package/dist/catalog/catalog-content.d.ts +6 -3
  24. package/dist/catalog/catalog-content.js +7 -8
  25. package/dist/catalog/claude/translate.js +1 -1
  26. package/dist/catalog/marketplaces.service.d.ts +1 -1
  27. package/dist/catalog/marketplaces.service.js +2 -1
  28. package/dist/catalog/plugin-package.d.ts +3 -2
  29. package/dist/channels/file-delivery.d.ts +2 -0
  30. package/dist/channels/file-delivery.js +1 -1
  31. package/dist/channels/inbound.d.ts +8 -4
  32. package/dist/channels/inbound.js +14 -7
  33. package/dist/channels/outbound.js +11 -5
  34. package/dist/channels/phrases.d.ts +21 -13
  35. package/dist/channels/phrases.js +21 -14
  36. package/dist/client/client-files.js +1 -1
  37. package/dist/config/product-name.d.ts +8 -0
  38. package/dist/config/product-name.js +9 -0
  39. package/dist/config/schema.d.ts +1 -0
  40. package/dist/config/schema.js +17 -4
  41. package/dist/conversations/conversations.service.d.ts +4 -3
  42. package/dist/conversations/conversations.service.js +15 -2
  43. package/dist/ctx/create-ctx.js +5 -2
  44. package/dist/ctx/device-provider-check.d.ts +7 -0
  45. package/dist/ctx/device-provider-check.js +21 -0
  46. package/dist/db/kernel-schema.d.ts +7 -0
  47. package/dist/devices/access.d.ts +16 -46
  48. package/dist/devices/access.js +26 -62
  49. package/dist/devices/access.module.js +2 -2
  50. package/dist/devices/conversation-devices.d.ts +38 -18
  51. package/dist/devices/conversation-devices.js +69 -51
  52. package/dist/devices/default-provider-setting.d.ts +45 -0
  53. package/dist/devices/default-provider-setting.js +59 -0
  54. package/dist/devices/device-projects.service.js +7 -2
  55. package/dist/devices/device-provider-selection.d.ts +37 -0
  56. package/dist/devices/device-provider-selection.js +86 -0
  57. package/dist/devices/device-provider-selection.module.d.ts +3 -0
  58. package/dist/devices/device-provider-selection.module.js +22 -0
  59. package/dist/devices/devices.controller.d.ts +8 -5
  60. package/dist/devices/devices.controller.js +7 -4
  61. package/dist/devices/devices.module.js +3 -1
  62. package/dist/devices/devices.schemas.js +2 -2
  63. package/dist/devices/devices.service.d.ts +72 -83
  64. package/dist/devices/devices.service.js +139 -248
  65. package/dist/devices/dto.d.ts +9 -0
  66. package/dist/devices/dto.js +15 -2
  67. package/dist/devices/label.d.ts +3 -5
  68. package/dist/devices/label.js +3 -14
  69. package/dist/devices/legacy-cleanup.job.d.ts +2 -2
  70. package/dist/devices/legacy-cleanup.job.js +6 -6
  71. package/dist/errors.d.ts +15 -1
  72. package/dist/errors.js +15 -1
  73. package/dist/extensions/guide-places.d.ts +2 -1
  74. package/dist/extensions/guide-places.js +8 -2
  75. package/dist/extensions/locks.d.ts +1 -1
  76. package/dist/extensions/locks.js +1 -1
  77. package/dist/extensions/org-config.d.ts +20 -4
  78. package/dist/extensions/org-config.js +23 -6
  79. package/dist/extensions/permission-view.d.ts +2 -2
  80. package/dist/extensions/permission-view.js +2 -2
  81. package/dist/extensions/plugin-guides.d.ts +1 -1
  82. package/dist/extensions/plugin-guides.js +11 -3
  83. package/dist/extensions/point-defaults.d.ts +14 -0
  84. package/dist/extensions/point-defaults.js +70 -47
  85. package/dist/extensions/resolve.js +7 -2
  86. package/dist/git/gateway.d.ts +9 -0
  87. package/dist/git/gateway.js +36 -17
  88. package/dist/git/gateway.route.d.ts +1 -1
  89. package/dist/git/gateway.route.js +1 -3
  90. package/dist/http/app.d.ts +1 -1
  91. package/dist/identity/app-auth.d.ts +4 -3
  92. package/dist/identity/app-auth.js +7 -8
  93. package/dist/identity/settings.d.ts +8 -0
  94. package/dist/identity/settings.js +30 -3
  95. package/dist/identity/sso.d.ts +13 -7
  96. package/dist/identity/sso.js +21 -7
  97. package/dist/infra/config/kernel-config.service.js +3 -1
  98. package/dist/lifecycle/kernel-lifecycle.js +7 -6
  99. package/dist/local-devices/device-routes.d.ts +1 -1
  100. package/dist/local-devices/device-routes.js +2 -2
  101. package/dist/local-devices/local-device-provider.d.ts +14 -11
  102. package/dist/local-devices/local-device-provider.js +14 -0
  103. package/dist/local-devices/local-devices.module.d.ts +4 -4
  104. package/dist/local-devices/local-devices.module.js +5 -3
  105. package/dist/local-devices/owner-report.js +2 -1
  106. package/dist/local-devices/targets.d.ts +2 -0
  107. package/dist/local-devices/targets.js +10 -0
  108. package/dist/orgs/offboarding.js +9 -0
  109. package/dist/orgs/settings.service.d.ts +26 -1
  110. package/dist/orgs/settings.service.js +44 -3
  111. package/dist/platform/ops/admin.ops.js +8 -3
  112. package/dist/platform/ops/agents.ops.d.ts +6 -1
  113. package/dist/platform/ops/agents.ops.js +38 -11
  114. package/dist/platform/ops/devices.ops.js +25 -20
  115. package/dist/platform/ops/orgs.ops.js +1 -0
  116. package/dist/platform/ops/platform-icons.ops.js +4 -4
  117. package/dist/platform/ops/platform.ops.js +2 -1
  118. package/dist/platform/ops/themes.ops.js +1 -1
  119. package/dist/runtime/plugin-context.service.js +1 -12
  120. package/dist/sandbox/cloud-permission-snapshot.d.ts +2 -2
  121. package/dist/sandbox/cloud-permission-snapshot.js +3 -3
  122. package/dist/sandbox/device-reports.d.ts +50 -0
  123. package/dist/sandbox/device-reports.js +157 -0
  124. package/dist/sandbox/held-operations.d.ts +8 -8
  125. package/dist/sandbox/leases.d.ts +1 -1
  126. package/dist/sandbox/leases.js +1 -1
  127. package/dist/sandbox/operation-authority.d.ts +5 -2
  128. package/dist/sandbox/operation-authority.js +12 -11
  129. package/dist/sandbox/operation-reconcile.job.d.ts +2 -2
  130. package/dist/sandbox/operation-reconcile.job.js +5 -5
  131. package/dist/sandbox/permission-availability.d.ts +2 -2
  132. package/dist/sandbox/permission-call-types.d.ts +5 -0
  133. package/dist/sandbox/permission-facts.d.ts +2 -2
  134. package/dist/sandbox/permission-facts.js +5 -5
  135. package/dist/sandbox/providers.d.ts +23 -24
  136. package/dist/sandbox/providers.js +38 -46
  137. package/dist/sandbox/providers.module.js +3 -3
  138. package/dist/sandbox/review/classifier.d.ts +6 -0
  139. package/dist/sandbox/review/classifier.js +12 -1
  140. package/dist/sandbox/review/index.d.ts +1 -1
  141. package/dist/sandbox/review/index.js +1 -1
  142. package/dist/sandbox/sandbox.module.d.ts +1 -1
  143. package/dist/sandbox/sandbox.module.js +7 -2
  144. package/dist/sandbox/sandbox.service.d.ts +95 -68
  145. package/dist/sandbox/sandbox.service.js +212 -208
  146. package/dist/setup/setup-guides.service.d.ts +4 -1
  147. package/dist/setup/setup-guides.service.js +6 -1
  148. package/dist/themes/avatar-preset-key.d.ts +6 -0
  149. package/dist/themes/avatar-preset-key.js +9 -0
  150. package/dist/themes/platform-icon.service.js +1 -1
  151. package/dist/themes/theme-delivery.service.d.ts +10 -2
  152. package/dist/themes/theme-delivery.service.js +26 -11
  153. package/dist/themes/theme-state.d.ts +43 -2
  154. package/dist/themes/theme-state.js +61 -4
  155. package/dist/themes/themes-public.controller.d.ts +3 -3
  156. package/dist/themes/themes-public.controller.js +3 -3
  157. package/dist/themes/themes.service.d.ts +28 -1
  158. package/dist/themes/themes.service.js +36 -2
  159. package/dist/tools/builtins/image/generate.d.ts +3 -0
  160. package/dist/tools/builtins/image/generate.js +21 -11
  161. package/dist/tools/builtins/image/index.d.ts +1 -1
  162. package/dist/tools/builtins/image/index.js +1 -1
  163. package/dist/tools/builtins/platform.js +25 -17
  164. package/dist/tools/builtins/sandbox/common.d.ts +37 -13
  165. package/dist/tools/builtins/sandbox/common.js +63 -19
  166. package/dist/tools/builtins/sandbox/read.d.ts +5 -2
  167. package/dist/tools/builtins/sandbox/read.js +9 -6
  168. package/dist/tools/builtins/sandbox/task-output.d.ts +2 -2
  169. package/dist/tools/builtins/sandbox/task-output.js +6 -5
  170. package/dist/tools/builtins/skill-load.js +13 -4
  171. package/dist/tools/connectors.service.js +2 -1
  172. package/dist/tools/oauth/discovery.d.ts +2 -0
  173. package/dist/tools/oauth/discovery.js +3 -1
  174. package/dist/until-aborted.d.ts +5 -0
  175. package/dist/until-aborted.js +16 -0
  176. package/package.json +4 -4
  177. package/src/migrations/0176_device_report.sql +6 -0
@@ -6,7 +6,7 @@ import type { KernelConfig } from "../../../config/schema.js";
6
6
  import type { ChildAgent } from "../../../conversations/agent-tree.js";
7
7
  import type { AttachmentsService } from "../../../conversations/attachments.service.js";
8
8
  import type { EventLog } from "../../../conversations/event-log.js";
9
- import { type ConversationDevices, type WorkingFacts } from "../../../devices/conversation-devices.js";
9
+ import { type ConversationDevices, type DeviceUnusableReason, type WorkingFacts } from "../../../devices/conversation-devices.js";
10
10
  import type { KernelConfigService } from "../../../infra/config/kernel-config.service.js";
11
11
  import { ATTACHMENTS_ROOT, attachmentsDir, attachmentsRoot } from "../../../sandbox/attachments-path.js";
12
12
  import { type ManagedDeviceContextPort } from "../../../sandbox/managed-device-context.js";
@@ -24,14 +24,15 @@ export interface SandboxToolDeps {
24
24
  * `currentInstance` too: a background `Bash` launch records the instance it started in; and
25
25
  * `ifRunning`, which `TaskOutput` reads a task through.
26
26
  */
27
- sandbox: Pick<SandboxService, "cloudAvailable" | "availableFor" | "withSandbox"> & Partial<Pick<SandboxService, "pathLease" | "currentInstance" | "ifRunning" | "withOperations">>;
27
+ sandbox: Pick<SandboxService, "withSandbox"> & Partial<Pick<SandboxService, "pathLease" | "currentInstance" | "ifRunning" | "withOperations">>;
28
28
  /**
29
29
  * The device a call enters: the root conversation's, checked for its owner every call.
30
- * `usableNow` (absent in test stubs: only the cloud provider counts) tells a listing whether a
31
- * conversation's device can run without a cloud provider (ruling R8). `workingFacts` (absent
32
- * in test stubs: free mode) gives what decides the working root, read as the review reads it.
30
+ * `usableNow` (absent in test stubs: the device's provider serves the org) tells a listing
31
+ * whether a conversation's device has its provider on in the org (ruling R8). `workingFacts`
32
+ * (absent in test stubs: free mode) gives what decides the working root, read as the review
33
+ * reads it.
33
34
  */
34
- devices: Pick<ConversationDevices, "forTool"> & Partial<Pick<ConversationDevices, "usableNow" | "modeLevel" | "workingFacts" | "projectReach">>;
35
+ devices: Pick<ConversationDevices, "forTool"> & Partial<Pick<ConversationDevices, "usableNow" | "unusableReason" | "modeLevel" | "workingFacts" | "projectReach">>;
35
36
  /** Background `Bash` tasks; absent in test stubs, where `run_in_background` is refused. */
36
37
  background?: Pick<BackgroundTaskStore, "releaseStop" | "get" | "advanceOffset" | "runningOwnedBy" | "finishedOwnedBy"> & Partial<Pick<BackgroundTaskStore, "reserveManaged" | "failManagedPreEffect">>;
37
38
  /**
@@ -125,10 +126,17 @@ export declare const SANDBOX_RESTARTED_NOTICE = "The device's instance was resta
125
126
  export declare const sandboxFilesResetNotice: (roots: SandboxRoots) => string;
126
127
  /** {@link sandboxFilesResetNotice} of an instance with the default roots. */
127
128
  export declare const SANDBOX_FILES_RESET_NOTICE: string;
129
+ /**
130
+ * A conversation with no device while device providers are on in the org: its owner has no default
131
+ * device and the org has no default device provider to make one.
132
+ */
133
+ export declare const NO_DEVICE_TEXT = "This conversation has no device: its owner has no default device and the organization has no default device provider to make one. Ask the user to create a device on the devices page and start a new conversation on it, or ask an org admin to choose a default device provider; or do the task without the sandbox.";
128
134
  /** The message the kernel reports for a sandbox tool call with no provider, minus its final period. */
129
135
  export declare const SANDBOX_UNAVAILABLE_REASON: string;
130
- /** The error of a sandbox call in a deployment without a sandbox provider. */
136
+ /** The error of a sandbox call with no device provider on in the org. */
131
137
  export declare function noSandboxError(): ToolError;
138
+ /** A device whose provider does not serve its org now (`device.unavailable`): files kept. */
139
+ export declare const ENV_UNAVAILABLE_TEXT = "This conversation's device runs on a device provider that is off in this organization or not installed; its files are kept. Ask an org admin to switch the provider back on, or start a new conversation on another device.";
132
140
  /**
133
141
  * A provider call that never connected (refused, unknown host, unreachable network): the request
134
142
  * did not reach the provider, so the call did nothing in the sandbox.
@@ -286,7 +294,7 @@ export declare function admissionUnavailableText(cause: PermissionAvailabilityCa
286
294
  * sends scopes it validated, so this is a kernel invariant break (or a skewed device), never the
287
295
  * model's doing; whether anything ran is not proven.
288
296
  */
289
- export declare const SCOPE_INVALID_TOOL_TEXT = "The device refused this operation as malformed, which points to a problem in Capybara itself, not in the request. Tell the user the device rejected the operation and that it should be reported; do not retry it unchanged.";
297
+ export declare const SCOPE_INVALID_TOOL_TEXT = "The device refused this operation as malformed, which points to a problem in the platform itself, not in the request. Tell the user the device rejected the operation and that it should be reported; do not retry it unchanged.";
290
298
  /**
291
299
  * A device request whose machine came back as a new run of capybara-device before answering
292
300
  * (`DeviceProgramRestartedError`, also as the cause of an unknown outcome): its result is lost.
@@ -375,14 +383,30 @@ export declare const sandboxConversationOf: (ctx: BuiltinCallContext) => string;
375
383
  */
376
384
  export declare function withPathLease<T>(deps: Pick<SandboxToolDeps, "sandbox">, s: Pick<SandboxSession, "deviceId">, path: string, signal: AbortSignal, fn: (signal: AbortSignal) => Promise<T>): Promise<T>;
377
385
  /**
378
- * Whether a sandbox tool call of the conversation tree rooted at `conversationId` can run: a
379
- * cloud provider is loaded, or (ruling R8) the conversation's device runs on a registered
380
- * kernel provider (`@local`). Without a conversation only the cloud provider counts.
386
+ * Whether a sandbox tool call of the conversation tree rooted at `conversationId` can run
387
+ * (ruling R8): the conversation's device (an unbound one: the device it would bind to) has its
388
+ * provider on in the org. Without a conversation: some device provider is on in the org
389
+ * ({@link ConversationDevices.usableNow}).
390
+ */
391
+ export declare function sandboxUsable(deps: Pick<SandboxToolDeps, "devices">, orgId: string, conversationId: string | undefined): Promise<boolean>;
392
+ /**
393
+ * Why a sandbox tool call of the tree rooted at `conversationId` cannot run, as model-facing text,
394
+ * or null when it can ({@link ConversationDevices.unusableReason}): the conversation's device has
395
+ * its provider off ({@link ENV_UNAVAILABLE_TEXT}), it has no device while providers are on
396
+ * ({@link NO_DEVICE_TEXT}), or no device provider is on in the org ({@link NO_SANDBOX_TEXT}). A
397
+ * stub with only `usableNow` reads a false answer as the last.
398
+ */
399
+ export declare function sandboxUnusableText(deps: Pick<SandboxToolDeps, "devices">, orgId: string, conversationId: string | undefined): Promise<string | null>;
400
+ /**
401
+ * The tool error of a call whose conversation's device cannot run ({@link sandboxUnusableText}),
402
+ * or null when it can.
381
403
  */
382
- export declare function sandboxUsable(deps: Pick<SandboxToolDeps, "sandbox" | "devices">, orgId: string, conversationId: string | undefined): Promise<boolean>;
404
+ export declare function sandboxUnusableError(deps: Pick<SandboxToolDeps, "devices">, orgId: string, conversationId: string | undefined): Promise<ToolError | null>;
405
+ /** {@link ConversationDevices.unusableReason}, read from a stub's `usableNow` when it has only that. */
406
+ export declare function sandboxUnusableReason(deps: Pick<SandboxToolDeps, "devices">, orgId: string, conversationId: string | undefined): Promise<DeviceUnusableReason | null>;
383
407
  /**
384
408
  * The reason the registry reports the sandbox tools unavailable with, or null when they can run
385
- * ({@link sandboxUsable}; the listing passes the root conversation of the run). An eval replay
409
+ * ({@link sandboxUnusableText}; the listing passes the root conversation of the run). An eval replay
386
410
  * lists them as available (`replay`: its calls are never executed). `memo` (one per listing)
387
411
  * makes every sandbox tool of a listing share one answer.
388
412
  */
@@ -1,5 +1,5 @@
1
1
  import { DEFAULT_SANDBOX_ROOTS, DeviceProtocolError, isFileSystemGoneError, isSandboxOperationOutcomeUnknownError, isSandboxPermissionUnsupportedError, isSandboxScopeDeniedError, isSandboxScopeValidationError, isSandboxWorkUnsettledError, SandboxScopeDeniedError, ToolError, validateSandboxPath, validateSandboxPathShape, } from "@capybara-hq/plugin-sdk";
2
- import { ANONYMOUS_NO_DEVICE, } from "../../../devices/conversation-devices.js";
2
+ import { ANONYMOUS_NO_DEVICE, NO_DEVICE, } from "../../../devices/conversation-devices.js";
3
3
  import { canonicalRoot, workingRootOf } from "../../../devices/working-root.js";
4
4
  import { ApiError } from "../../../errors.js";
5
5
  import { InstanceBindingError } from "../../../local-devices/instance-bindings.js";
@@ -34,10 +34,15 @@ export const sandboxFilesResetNotice = (roots) => `The device's files were reset
34
34
  /** {@link sandboxFilesResetNotice} of an instance with the default roots. */
35
35
  export const SANDBOX_FILES_RESET_NOTICE = sandboxFilesResetNotice(DEFAULT_SANDBOX_ROOTS);
36
36
  const BUSY_TEXT = "The device is busy: all its command slots are taken by commands of this or another conversation sharing it; wait for one to finish and retry.";
37
- const NO_SANDBOX_TEXT = "No sandbox is configured in this deployment; ask an administrator to install a sandbox plugin, or do the task without the sandbox.";
37
+ const NO_SANDBOX_TEXT = "No device provider is on in this organization; ask an org admin to switch one on, or do the task without the sandbox.";
38
+ /**
39
+ * A conversation with no device while device providers are on in the org: its owner has no default
40
+ * device and the org has no default device provider to make one.
41
+ */
42
+ export const NO_DEVICE_TEXT = "This conversation has no device: its owner has no default device and the organization has no default device provider to make one. Ask the user to create a device on the devices page and start a new conversation on it, or ask an org admin to choose a default device provider; or do the task without the sandbox.";
38
43
  /** The message the kernel reports for a sandbox tool call with no provider, minus its final period. */
39
44
  export const SANDBOX_UNAVAILABLE_REASON = NO_SANDBOX_TEXT.slice(0, -1);
40
- /** The error of a sandbox call in a deployment without a sandbox provider. */
45
+ /** The error of a sandbox call with no device provider on in the org. */
41
46
  export function noSandboxError() {
42
47
  return new ToolError(NO_SANDBOX_TEXT);
43
48
  }
@@ -45,7 +50,8 @@ const PATH_BUSY_TEXT = "Another sub-agent or another conversation on this device
45
50
  const ANONYMOUS_TEXT = "The sandbox is not available to anonymous IM senders; do the task without the sandbox, or ask the person to link their account and start a new conversation.";
46
51
  const ENV_NOT_FOUND_TEXT = "This conversation's device was deleted or its owner can no longer use it; ask the user to start a new conversation on another device.";
47
52
  const ENV_FORBIDDEN_TEXT = "This conversation's owner may no longer use its device; ask the user to start a new conversation on a device they can use.";
48
- const ENV_UNAVAILABLE_TEXT = "This conversation's device is kept by a sandbox provider that is not active in this deployment; ask the user to start a new conversation on another device, or an administrator to re-enable that provider.";
53
+ /** A device whose provider does not serve its org now (`device.unavailable`): files kept. */
54
+ export const ENV_UNAVAILABLE_TEXT = "This conversation's device runs on a device provider that is off in this organization or not installed; its files are kept. Ask an org admin to switch the provider back on, or start a new conversation on another device.";
49
55
  const ENV_FILES_LOST_TEXT = "This device's files are gone. Ask the user to reset its files on the devices page, then retry.";
50
56
  /**
51
57
  * A provider call that never connected (refused, unknown host, unreachable network): the request
@@ -332,7 +338,7 @@ export function admissionUnavailableText(cause) {
332
338
  * sends scopes it validated, so this is a kernel invariant break (or a skewed device), never the
333
339
  * model's doing; whether anything ran is not proven.
334
340
  */
335
- export const SCOPE_INVALID_TOOL_TEXT = "The device refused this operation as malformed, which points to a problem in Capybara itself, not in the request. Tell the user the device rejected the operation and that it should be reported; do not retry it unchanged.";
341
+ export const SCOPE_INVALID_TOOL_TEXT = "The device refused this operation as malformed, which points to a problem in the platform itself, not in the request. Tell the user the device rejected the operation and that it should be reported; do not retry it unchanged.";
336
342
  /**
337
343
  * A device request whose machine came back as a new run of capybara-device before answering
338
344
  * (`DeviceProgramRestartedError`, also as the cause of an unknown outcome): its result is lost.
@@ -433,6 +439,8 @@ export function mapSandboxError(e, log) {
433
439
  const reason = e.details?.[0]?.reason;
434
440
  if (reason === ANONYMOUS_NO_DEVICE)
435
441
  return new ToolError(ANONYMOUS_TEXT);
442
+ if (reason === NO_DEVICE)
443
+ return new ToolError(NO_DEVICE_TEXT);
436
444
  return new ToolError(NO_SANDBOX_TEXT);
437
445
  }
438
446
  const detail = e.details?.[0];
@@ -714,20 +722,54 @@ export async function withPathLease(deps, s, path, signal, fn) {
714
722
  }
715
723
  }
716
724
  /**
717
- * Whether a sandbox tool call of the conversation tree rooted at `conversationId` can run: a
718
- * cloud provider is loaded, or (ruling R8) the conversation's device runs on a registered
719
- * kernel provider (`@local`). Without a conversation only the cloud provider counts.
725
+ * Whether a sandbox tool call of the conversation tree rooted at `conversationId` can run
726
+ * (ruling R8): the conversation's device (an unbound one: the device it would bind to) has its
727
+ * provider on in the org. Without a conversation: some device provider is on in the org
728
+ * ({@link ConversationDevices.usableNow}).
720
729
  */
721
730
  export async function sandboxUsable(deps, orgId, conversationId) {
722
- if (deps.sandbox.cloudAvailable)
723
- return true;
724
- if (conversationId === undefined || !deps.devices.usableNow)
725
- return false;
726
- return deps.devices.usableNow(orgId, conversationId);
731
+ return deps.devices.usableNow ? deps.devices.usableNow(orgId, conversationId) : true;
732
+ }
733
+ /** The model-facing text of each {@link DeviceUnusableReason}. */
734
+ const UNUSABLE_TEXT = {
735
+ "provider-off": ENV_UNAVAILABLE_TEXT,
736
+ "no-device": NO_DEVICE_TEXT,
737
+ none: NO_SANDBOX_TEXT,
738
+ };
739
+ /**
740
+ * Why a sandbox tool call of the tree rooted at `conversationId` cannot run, as model-facing text,
741
+ * or null when it can ({@link ConversationDevices.unusableReason}): the conversation's device has
742
+ * its provider off ({@link ENV_UNAVAILABLE_TEXT}), it has no device while providers are on
743
+ * ({@link NO_DEVICE_TEXT}), or no device provider is on in the org ({@link NO_SANDBOX_TEXT}). A
744
+ * stub with only `usableNow` reads a false answer as the last.
745
+ */
746
+ export async function sandboxUnusableText(deps, orgId, conversationId) {
747
+ const reason = await sandboxUnusableReason(deps, orgId, conversationId);
748
+ return reason === null ? null : UNUSABLE_TEXT[reason];
749
+ }
750
+ /**
751
+ * The tool error of a call whose conversation's device cannot run ({@link sandboxUnusableText}),
752
+ * or null when it can.
753
+ */
754
+ export async function sandboxUnusableError(deps, orgId, conversationId) {
755
+ const reason = await sandboxUnusableReason(deps, orgId, conversationId);
756
+ if (reason === null)
757
+ return null;
758
+ if (reason === "provider-off")
759
+ return new ToolError(ENV_UNAVAILABLE_TEXT);
760
+ if (reason === "no-device")
761
+ return new ToolError(NO_DEVICE_TEXT);
762
+ return noSandboxError();
763
+ }
764
+ /** {@link ConversationDevices.unusableReason}, read from a stub's `usableNow` when it has only that. */
765
+ export async function sandboxUnusableReason(deps, orgId, conversationId) {
766
+ if (deps.devices.unusableReason)
767
+ return deps.devices.unusableReason(orgId, conversationId);
768
+ return (await sandboxUsable(deps, orgId, conversationId)) ? null : "none";
727
769
  }
728
770
  /**
729
771
  * The reason the registry reports the sandbox tools unavailable with, or null when they can run
730
- * ({@link sandboxUsable}; the listing passes the root conversation of the run). An eval replay
772
+ * ({@link sandboxUnusableText}; the listing passes the root conversation of the run). An eval replay
731
773
  * lists them as available (`replay`: its calls are never executed). `memo` (one per listing)
732
774
  * makes every sandbox tool of a listing share one answer.
733
775
  */
@@ -735,12 +777,14 @@ export const unavailableWhenNoSandbox = (deps) => async (ctx) => {
735
777
  if (ctx.replay === true)
736
778
  return null;
737
779
  const key = "sandboxUsable";
738
- let usable = ctx.memo?.get(key);
739
- if (usable === undefined) {
740
- usable = sandboxUsable(deps, ctx.orgId, ctx.conversationId);
741
- ctx.memo?.set(key, usable);
780
+ let text = ctx.memo?.get(key);
781
+ if (text === undefined) {
782
+ text = sandboxUnusableText(deps, ctx.orgId, ctx.conversationId);
783
+ ctx.memo?.set(key, text);
742
784
  }
743
- return (await usable) ? null : SANDBOX_UNAVAILABLE_REASON;
785
+ const t = await text;
786
+ // the listing's reason has no final period
787
+ return t === null ? null : t.slice(0, -1);
744
788
  };
745
789
  /** 读出的字节是否像二进制(开头 8 KB 里有 NUL)。 */
746
790
  export function looksBinary(data) {
@@ -9,8 +9,11 @@ export declare const READ_MAX_BYTES: number;
9
9
  export declare const READ_DESCRIPTION: string;
10
10
  /** Neither or both of `file_path` and `file_id` (spec §1.1). */
11
11
  export declare const READ_ONE_SOURCE_TEXT = "Pass exactly one of file_path (a path on the device) and file_id (an attachment or artifact id).";
12
- /** A `file_path` read without a usable device (spec §1.1; verbatim). */
13
- export declare const READ_NO_DEVICE_TEXT = "This agent has no device; pass file_id to read an attachment or artifact.";
12
+ /**
13
+ * A `file_path` read without a usable device: why the device cannot be used
14
+ * ({@link sandboxUnusableText}), then the `file_id` way in.
15
+ */
16
+ export declare const readNoDeviceText: (unusable: string) => string;
14
17
  /** A `file_id` that is no file of this conversation or its root. */
15
18
  export declare const unknownFileIdText: (id: string) => string;
16
19
  /** A `file_id` read in a deployment without an object store. */
@@ -6,7 +6,7 @@ import { viewPath } from "../../view.js";
6
6
  import { findConversationFile, } from "../conversation-files.js";
7
7
  import { sizeText } from "../size-text.js";
8
8
  import { readImageWithVisionModel } from "../vision/read-image.js";
9
- import { checkFilePathShape, checkToolPath, clip, display, inToolSandbox, looksBinary, resolveToolPath, sandboxBaseTimeoutMs, sandboxConversationOf, sandboxUsable, unavailableWhenNoSandbox, withNotices, } from "./common.js";
9
+ import { checkFilePathShape, checkToolPath, clip, display, inToolSandbox, looksBinary, resolveToolPath, sandboxBaseTimeoutMs, sandboxConversationOf, sandboxUnusableText, unavailableWhenNoSandbox, withNotices, } from "./common.js";
10
10
  import { normalizeSandboxPath, recordedFile } from "./file-state.js";
11
11
  /** 不给 `limit` 时一次读的行数。 */
12
12
  const DEFAULT_LIMIT = 2000;
@@ -68,8 +68,11 @@ const isDirectory = (path) => `${clip(path, 200)} is a directory; use Glob to li
68
68
  const pastEnd = (offset, total) => `offset ${offset} is past the end of the file (${total} lines); pass an offset of at most ${total}.`;
69
69
  /** Neither or both of `file_path` and `file_id` (spec §1.1). */
70
70
  export const READ_ONE_SOURCE_TEXT = "Pass exactly one of file_path (a path on the device) and file_id (an attachment or artifact id).";
71
- /** A `file_path` read without a usable device (spec §1.1; verbatim). */
72
- export const READ_NO_DEVICE_TEXT = "This agent has no device; pass file_id to read an attachment or artifact.";
71
+ /**
72
+ * A `file_path` read without a usable device: why the device cannot be used
73
+ * ({@link sandboxUnusableText}), then the `file_id` way in.
74
+ */
75
+ export const readNoDeviceText = (unusable) => `${unusable} To read an attachment or artifact of this conversation, pass file_id instead.`;
73
76
  /** A `file_id` that is no file of this conversation or its root. */
74
77
  export const unknownFileIdText = (id) => `file_id ${clip(id, 100)} is not an attachment or artifact of this conversation; pass the id of one.`;
75
78
  /** A `file_id` read in a deployment without an object store. */
@@ -154,9 +157,9 @@ export function sandboxReadTool(deps) {
154
157
  return readById(deps, ctx, input, input.file_id);
155
158
  const filePath = input.file_path;
156
159
  checkFilePathShape(filePath);
157
- if (!(await sandboxUsable(deps, ctx.orgId, sandboxConversationOf(ctx)))) {
158
- throw new ToolError(READ_NO_DEVICE_TEXT);
159
- }
160
+ const unusable = await sandboxUnusableText(deps, ctx.orgId, sandboxConversationOf(ctx));
161
+ if (unusable !== null)
162
+ throw new ToolError(readNoDeviceText(unusable));
160
163
  let path = "";
161
164
  const { value, notices } = await inToolSandbox(deps, ctx, async (s) => {
162
165
  const { h, p, signal } = s;
@@ -19,8 +19,8 @@ export interface TaskEnv {
19
19
  }
20
20
  /**
21
21
  * The task tools' dependencies; throws the tool's error when they are missing, or when the
22
- * conversation's device cannot run (no cloud provider, and not a registered `@local` one:
23
- * ruling R8).
22
+ * conversation's device cannot run (its provider off in the org, or no provider on there: ruling
23
+ * R8, {@link sandboxUnusableError}).
24
24
  */
25
25
  export declare function taskEnv(deps: SandboxToolDeps, ctx: BuiltinCallContext): Promise<TaskEnv>;
26
26
  /**
@@ -8,7 +8,7 @@ import { formatElapsed, taskReasonText } from "../../../background/render.js";
8
8
  import { notRunningAs, RECREATED } from "../../../background/stop.js";
9
9
  import { isManagedTask } from "../../../background/store.js";
10
10
  import { RetirementPendingError, retirementPending, } from "../../../sandbox/sandbox.service.js";
11
- import { clip, display, mapSandboxError, noSandboxError, runTimeLeftMs, sandboxBaseTimeoutMs, sandboxConversationOf, sandboxUsable, unavailableWhenNoSandbox, } from "./common.js";
11
+ import { clip, display, mapSandboxError, runTimeLeftMs, sandboxBaseTimeoutMs, sandboxConversationOf, sandboxUnusableError, unavailableWhenNoSandbox, } from "./common.js";
12
12
  import { parseDeviceCode } from "./device-code.js";
13
13
  import { assertDeviceOfRunAccount } from "./device-owner.js";
14
14
  /** How long `TaskOutput` waits with `block` when `timeout` is not given (ms). */
@@ -57,12 +57,13 @@ const SPEC = {
57
57
  };
58
58
  /**
59
59
  * The task tools' dependencies; throws the tool's error when they are missing, or when the
60
- * conversation's device cannot run (no cloud provider, and not a registered `@local` one:
61
- * ruling R8).
60
+ * conversation's device cannot run (its provider off in the org, or no provider on there: ruling
61
+ * R8, {@link sandboxUnusableError}).
62
62
  */
63
63
  export async function taskEnv(deps, ctx) {
64
- if (!(await sandboxUsable(deps, ctx.orgId, sandboxConversationOf(ctx))))
65
- throw noSandboxError();
64
+ const unusable = await sandboxUnusableError(deps, ctx.orgId, sandboxConversationOf(ctx));
65
+ if (unusable !== null)
66
+ throw unusable;
66
67
  const { background, tasks } = deps;
67
68
  if (!background || !tasks || !deps.sandbox.ifRunning) {
68
69
  throw new ToolError("Background tasks are not available here; use Bash without run_in_background instead.");
@@ -11,7 +11,7 @@ import { resolveSkillForkType } from "../../runtime/subagents/roster.js";
11
11
  import { invocationOf, resolveSkills } from "../../skills/catalog.js";
12
12
  import { PLATFORM_SOURCE, skillFileStore } from "../../skills/usable.js";
13
13
  import { AGENT_TOOL, SANDBOX_TOOL_NAMES } from "../builtin-names.js";
14
- import { checkToolPath, clip, display, inSandboxPreparation, inToolSandbox, mapSandboxError, sandboxBaseTimeoutMs, sandboxConversationOf, sandboxUsable, withNotices, withPathLease, } from "./sandbox/common.js";
14
+ import { checkToolPath, clip, display, inSandboxPreparation, inToolSandbox, mapSandboxError, sandboxBaseTimeoutMs, sandboxConversationOf, sandboxUnusableReason, withNotices, withPathLease, } from "./sandbox/common.js";
15
15
  /**
16
16
  * Builtin tool `Skill` (M5 T14, ruling M17): resolves the name against the latest skills catalog
17
17
  * snapshot in the log to an id and version, and returns that version's SKILL.md body and file list
@@ -533,6 +533,12 @@ async function loadProjectSkill(deps, ctx, asked, bare, args) {
533
533
  display: display(`加载项目技能 ${asked}`, `Loaded project skill ${asked}`),
534
534
  };
535
535
  }
536
+ /** Why a skill's files cannot reach the device, per {@link DeviceUnusableReason}. */
537
+ const SKILL_NO_DEVICE_CAUSE = {
538
+ "provider-off": "This conversation's device runs on a device provider that is off in this organization or not installed",
539
+ "no-device": "This conversation has no device (its owner has no default device and the organization has no default device provider)",
540
+ none: "No device provider is on in this organization",
541
+ };
536
542
  /** 内置工具 `Skill`(见文件头)。 */
537
543
  export function skillLoadTool(deps) {
538
544
  return {
@@ -603,14 +609,17 @@ export function skillLoadTool(deps) {
603
609
  const others = manifest.files.filter((f) => f.path !== SKILL_ENTRY_FILE);
604
610
  let notices = [];
605
611
  let filesText;
612
+ const unusable = others.length === 0
613
+ ? null
614
+ : await sandboxUnusableReason(deps, ctx.orgId, sandboxConversationOf(ctx));
606
615
  if (others.length === 0) {
607
616
  filesText = "This skill has no files besides its instructions.";
608
617
  }
609
- else if (!(await sandboxUsable(deps, ctx.orgId, sandboxConversationOf(ctx)))) {
618
+ else if (unusable !== null) {
610
619
  filesText =
611
620
  `Skill files (for reference):\n${fileList(manifest.files)}\n` +
612
- "This deployment has no sandbox, so the skill's scripts and other files are not available; " +
613
- "follow the instructions without running them.";
621
+ SKILL_NO_DEVICE_CAUSE[unusable] +
622
+ ", so the skill's scripts and other files are not available; follow the instructions without running them.";
614
623
  }
615
624
  else if (!hasSandboxTools(ctx)) {
616
625
  // 模型跑不了脚本:不为它创建沙箱、不复制
@@ -14,6 +14,7 @@ import { sql } from "kysely";
14
14
  import { z } from "zod";
15
15
  import { connectorTemplateState } from "../catalog/component-state.js";
16
16
  import { assertItemInstallable } from "../catalog/request-rules.js";
17
+ import { productName } from "../config/product-name.js";
17
18
  import { ApiError } from "../errors.js";
18
19
  import { PluginGuides, } from "../extensions/plugin-guides.js";
19
20
  import { ExtensionRegistry } from "../extensions/registry.js";
@@ -289,7 +290,7 @@ let ConnectorsService = class ConnectorsService {
289
290
  if (!meta)
290
291
  throw fail("auth.client", "Dynamic client registration requires discovery mcp");
291
292
  try {
292
- const client = await registerClient({ ...meta, ...(scopes && { scopes }) }, callbackUrl(publicUrl), http, auth.tokenAuthMethod);
293
+ const client = await registerClient({ ...meta, ...(scopes && { scopes }) }, callbackUrl(publicUrl), http, productName(this.config.get()), auth.tokenAuthMethod);
293
294
  return { client };
294
295
  }
295
296
  catch (e) {
@@ -83,5 +83,7 @@ export declare function pickAuthMethod(supported: string[] | undefined, hasSecre
83
83
  * client)。注册失败只报 HTTP 状态,不带对方正文。
84
84
  */
85
85
  export declare function registerClient(meta: McpAuthMetadata, redirectUri: string, http: OAuthHttpOptions,
86
+ /** The client name the authorization server shows on its consent screen (`platform.name`). */
87
+ clientName: string,
86
88
  /** 管理员指定的客户端认证方式(`tokenAuthMethod`);不给则按授权服务器声明选择。 */
87
89
  preferred?: TokenAuthMethod): Promise<OAuthClientRecord>;
@@ -273,6 +273,8 @@ export function pickAuthMethod(supported, hasSecret) {
273
273
  * client)。注册失败只报 HTTP 状态,不带对方正文。
274
274
  */
275
275
  export async function registerClient(meta, redirectUri, http,
276
+ /** The client name the authorization server shows on its consent screen (`platform.name`). */
277
+ clientName,
276
278
  /** 管理员指定的客户端认证方式(`tokenAuthMethod`);不给则按授权服务器声明选择。 */
277
279
  preferred) {
278
280
  if (!meta.registrationEndpoint) {
@@ -286,7 +288,7 @@ preferred) {
286
288
  method: "POST",
287
289
  headers: { "content-type": "application/json", accept: "application/json" },
288
290
  body: JSON.stringify({
289
- client_name: "Capybara",
291
+ client_name: clientName,
290
292
  redirect_uris: [redirectUri],
291
293
  grant_types: ["authorization_code", "refresh_token"],
292
294
  response_types: ["code"],
@@ -0,0 +1,5 @@
1
+ /**
2
+ * `p`, or a rejection with `signal.reason` once `signal` aborts, whatever `p` does: an extension
3
+ * call that ignores its signal never holds the caller past it (a late settle of `p` is dropped).
4
+ */
5
+ export declare function untilAborted<T>(p: Promise<T>, signal: AbortSignal): Promise<T>;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * `p`, or a rejection with `signal.reason` once `signal` aborts, whatever `p` does: an extension
3
+ * call that ignores its signal never holds the caller past it (a late settle of `p` is dropped).
4
+ */
5
+ export function untilAborted(p, signal) {
6
+ return new Promise((resolve, reject) => {
7
+ const onAbort = () => reject(signal.reason);
8
+ if (signal.aborted) {
9
+ p.catch(() => { });
10
+ onAbort();
11
+ return;
12
+ }
13
+ signal.addEventListener("abort", onAbort, { once: true });
14
+ p.then(resolve, reject).finally(() => signal.removeEventListener("abort", onAbort));
15
+ });
16
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/kernel",
3
- "version": "0.1.0-rc.65",
3
+ "version": "0.1.0-rc.67",
4
4
  "description": "Capybara kernel: config, database, plugin host and HTTP API of the Capybara agent platform",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -66,7 +66,7 @@
66
66
  "yaml": "^2.9.1",
67
67
  "yauzl": "3.4.0",
68
68
  "zod": "^4.6.7",
69
- "@capybara-hq/plugin-sdk": "^0.1.0-rc.49"
69
+ "@capybara-hq/plugin-sdk": "^0.1.0-rc.51"
70
70
  },
71
71
  "devDependencies": {
72
72
  "@langchain/langgraph-checkpoint-validation": "^1.2.0",
@@ -75,8 +75,8 @@
75
75
  "@types/ws": "^8.18.2",
76
76
  "@types/yauzl": "3.4.0",
77
77
  "ws": "^8.22.0",
78
- "@capybara-hq/testing": "0.1.0-rc.31",
79
- "@capybara-hq/device": "0.1.0-rc.26"
78
+ "@capybara-hq/testing": "0.1.0-rc.33",
79
+ "@capybara-hq/device": "0.1.0-rc.27"
80
80
  },
81
81
  "scripts": {
82
82
  "build": "tsc -b"
@@ -0,0 +1,6 @@
1
+ -- Device providers (spec 2026-11-21-device-provider-design): what a device's provider last told
2
+ -- about it (`device-provider@1` `report()`, a DeviceReport as JSON) and when. Shown to people
3
+ -- only, never used for enforcement; request paths read this copy and never call the provider.
4
+ -- Expand-only, no backfill: null until the device's next create or resume refreshes it.
5
+ ALTER TABLE devices ADD COLUMN IF NOT EXISTS report jsonb;
6
+ ALTER TABLE devices ADD COLUMN IF NOT EXISTS report_at timestamptz;