@capybara-hq/kernel 0.1.0-rc.62 → 0.1.0-rc.64

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 (120) hide show
  1. package/bootstrap.json +3 -3
  2. package/dist/app.d.ts +2 -0
  3. package/dist/catalog/catalog.service.d.ts +13 -0
  4. package/dist/catalog/catalog.service.js +17 -8
  5. package/dist/catalog/git-source.d.ts +8 -0
  6. package/dist/catalog/git-source.js +14 -6
  7. package/dist/catalog/marketplaces.controller.d.ts +3 -2
  8. package/dist/catalog/marketplaces.controller.js +5 -2
  9. package/dist/catalog/marketplaces.schemas.d.ts +7 -0
  10. package/dist/catalog/marketplaces.schemas.js +13 -0
  11. package/dist/catalog/marketplaces.service.d.ts +65 -11
  12. package/dist/catalog/marketplaces.service.js +208 -30
  13. package/dist/catalog/org-catalog.schemas.d.ts +1 -1
  14. package/dist/catalog/org-catalog.schemas.js +1 -1
  15. package/dist/channels/actions.d.ts +2 -5
  16. package/dist/channels/actions.js +20 -8
  17. package/dist/channels/cards.d.ts +4 -3
  18. package/dist/channels/cards.js +6 -4
  19. package/dist/channels/outbound.js +3 -2
  20. package/dist/config/schema.d.ts +2 -0
  21. package/dist/config/schema.js +22 -2
  22. package/dist/conversations/approval-profile.d.ts +30 -0
  23. package/dist/conversations/approval-profile.js +62 -0
  24. package/dist/conversations/conversations.service.js +0 -2
  25. package/dist/conversations/events.d.ts +43 -0
  26. package/dist/conversations/events.js +52 -0
  27. package/dist/conversations/permission-profiles.controller.d.ts +3 -2
  28. package/dist/conversations/permission-profiles.service.d.ts +3 -2
  29. package/dist/conversations/permission-profiles.service.js +12 -8
  30. package/dist/db/kernel-schema.d.ts +8 -2
  31. package/dist/errors.d.ts +7 -0
  32. package/dist/errors.js +7 -0
  33. package/dist/extensions/bootstrap-defaults.d.ts +24 -0
  34. package/dist/extensions/bootstrap-defaults.js +78 -0
  35. package/dist/extensions/bootstrap-extra.d.ts +74 -0
  36. package/dist/extensions/bootstrap-extra.js +131 -0
  37. package/dist/extensions/bootstrap.d.ts +77 -13
  38. package/dist/extensions/bootstrap.js +282 -48
  39. package/dist/identity/initial-passwords.controller.d.ts +8 -6
  40. package/dist/identity/initial-passwords.controller.js +13 -7
  41. package/dist/identity/initial-passwords.d.ts +22 -13
  42. package/dist/identity/initial-passwords.js +25 -29
  43. package/dist/identity/settings.d.ts +10 -0
  44. package/dist/identity/settings.js +46 -0
  45. package/dist/index.d.ts +2 -0
  46. package/dist/index.js +3 -0
  47. package/dist/kernel.module.js +3 -0
  48. package/dist/lifecycle/kernel-lifecycle.d.ts +7 -1
  49. package/dist/lifecycle/kernel-lifecycle.js +69 -16
  50. package/dist/local-devices/relay.js +3 -1
  51. package/dist/models/images.js +5 -4
  52. package/dist/platform/connector-person-fields.js +2 -2
  53. package/dist/platform/exclusions.js +4 -4
  54. package/dist/platform/method.js +1 -1
  55. package/dist/platform/operation.d.ts +9 -7
  56. package/dist/platform/operation.js +1 -1
  57. package/dist/platform/ops/accounts.ops.d.ts +1 -1
  58. package/dist/platform/ops/accounts.ops.js +3 -3
  59. package/dist/platform/ops/channels.ops.d.ts +1 -1
  60. package/dist/platform/ops/channels.ops.js +2 -2
  61. package/dist/platform/ops/connectors.ops.d.ts +2 -2
  62. package/dist/platform/ops/connectors.ops.js +8 -8
  63. package/dist/platform/ops/extensions-admin.ops.d.ts +1 -1
  64. package/dist/platform/ops/extensions-admin.ops.js +3 -3
  65. package/dist/platform/ops/extensions.ops.d.ts +1 -1
  66. package/dist/platform/ops/extensions.ops.js +4 -4
  67. package/dist/platform/ops/marketplaces.ops.js +27 -4
  68. package/dist/platform/ops/org-plugins.ops.js +2 -2
  69. package/dist/platform/ops/orgs.ops.d.ts +1 -1
  70. package/dist/platform/ops/orgs.ops.js +3 -3
  71. package/dist/platform/ops/plugins.ops.d.ts +1 -1
  72. package/dist/platform/ops/plugins.ops.js +2 -2
  73. package/dist/platform/person-fields.d.ts +4 -3
  74. package/dist/platform/person-fields.js +6 -5
  75. package/dist/platform/sealed-inputs.d.ts +2 -2
  76. package/dist/platform/sealed-inputs.js +2 -2
  77. package/dist/platform/sealed-reveals.controller.d.ts +5 -8
  78. package/dist/platform/sealed-reveals.controller.js +8 -8
  79. package/dist/platform/sealed-reveals.d.ts +19 -17
  80. package/dist/platform/sealed-reveals.js +30 -33
  81. package/dist/runtime/context/build.js +3 -0
  82. package/dist/runtime/context/compaction.js +2 -0
  83. package/dist/runtime/waits.js +3 -2
  84. package/dist/sandbox/operation-authority.js +16 -15
  85. package/dist/sandbox/operation-intents.js +2 -2
  86. package/dist/sandbox/permission-availability.d.ts +49 -3
  87. package/dist/sandbox/permission-availability.js +61 -6
  88. package/dist/sandbox/permission-call-types.d.ts +3 -0
  89. package/dist/sandbox/permission-facts.d.ts +29 -1
  90. package/dist/sandbox/permission-facts.js +29 -6
  91. package/dist/sandbox/review/classifier.d.ts +72 -2
  92. package/dist/sandbox/review/classifier.js +113 -38
  93. package/dist/sandbox/review/index.d.ts +2 -2
  94. package/dist/sandbox/review/index.js +1 -1
  95. package/dist/sandbox/review/review.service.d.ts +1 -4
  96. package/dist/sandbox/review/review.service.js +4 -33
  97. package/dist/setup/setup-guides.service.js +1 -1
  98. package/dist/tools/approvals.service.d.ts +71 -16
  99. package/dist/tools/approvals.service.js +139 -13
  100. package/dist/tools/builtins/builtin-tools.d.ts +1 -1
  101. package/dist/tools/builtins/builtin-tools.js +12 -6
  102. package/dist/tools/builtins/platform.d.ts +15 -11
  103. package/dist/tools/builtins/platform.js +49 -39
  104. package/dist/tools/builtins/sandbox/bash.d.ts +1 -1
  105. package/dist/tools/builtins/sandbox/bash.js +32 -14
  106. package/dist/tools/builtins/sandbox/common.d.ts +12 -3
  107. package/dist/tools/builtins/sandbox/common.js +29 -5
  108. package/dist/tools/connectors.schemas.d.ts +1 -1
  109. package/dist/tools/connectors.schemas.js +1 -1
  110. package/dist/tools/pipeline.d.ts +70 -10
  111. package/dist/tools/pipeline.js +356 -48
  112. package/dist/tools/policy.d.ts +4 -3
  113. package/dist/tools/policy.js +6 -6
  114. package/dist/tools/registry.d.ts +25 -9
  115. package/dist/tools/tool-review.d.ts +113 -0
  116. package/dist/tools/tool-review.js +303 -0
  117. package/dist/tools/tools.module.js +6 -0
  118. package/package.json +4 -4
  119. package/src/migrations/0174_marketplace_managed_username.sql +4 -0
  120. package/src/migrations/0175_secure_input_kind.sql +8 -0
@@ -1,11 +1,11 @@
1
- import { classifyAddress, DEFAULT_SANDBOX_ROOTS, isSandboxOperationOutcomeUnknownError, isSandboxPermissionUnsupportedError, isSandboxScopeDeniedError, ToolError, } from "@capybara-hq/plugin-sdk";
1
+ import { classifyAddress, DEFAULT_SANDBOX_ROOTS, isSandboxOperationOutcomeUnknownError, isSandboxPermissionUnsupportedError, isSandboxScopeDeniedError, isSandboxWorkUnsettledError, ToolError, } from "@capybara-hq/plugin-sdk";
2
2
  import { backgroundMaxSeconds, LAUNCH_EXEC_TIMEOUT_MS, managedStartedText, managedTaskArtifactPath, newTaskId, } from "../../../background/launch.js";
3
3
  import { taskReasonText } from "../../../background/render.js";
4
4
  import { isDeviceRequestNotSent } from "../../../local-devices/relay.js";
5
5
  import { isEscalationGrantMissing } from "../../../sandbox/operation-authority-types.js";
6
6
  import { launchRefusedText, operationIdFor } from "../../../sandbox/operation-intents.js";
7
7
  import { ESCALATION_JUSTIFICATION_MAX_CHARS, ESCALATION_RETRY_HINT, SANDBOX_ESCALATED, } from "../../../sandbox/review/permission-candidate.js";
8
- import { clip, display, ESCALATION_GRANT_MISSING_LAUNCH_WHY, inSandboxOperations, inToolSandbox, runBudgetNote, runTimeLeftMs, SCOPE_DENIED_TOOL_TEXT, sandboxBaseTimeoutMs, sandboxConversationOf, unavailableWhenNoSandbox, withNotices, } from "./common.js";
8
+ import { admissionUnavailableText, clip, display, ESCALATION_GRANT_MISSING_LAUNCH_WHY, inSandboxOperations, inToolSandbox, PermissionAdmissionUnavailable, runBudgetNote, runTimeLeftMs, SCOPE_DENIED_TOOL_TEXT, sandboxBaseTimeoutMs, sandboxConversationOf, unavailableWhenNoSandbox, WORK_UNSETTLED_TOOL_TEXT, withNotices, } from "./common.js";
9
9
  import { parseDeviceCode } from "./device-code.js";
10
10
  /** The command timeout in seconds when `timeout` is not given, at most `sandbox.limits.maxCommandSeconds`. */
11
11
  export const BASH_DEFAULT_TIMEOUT_SECONDS = 120;
@@ -227,7 +227,7 @@ export async function runInBackgroundManaged(deps, ctx, input) {
227
227
  }
228
228
  catch (e) {
229
229
  // kernel-written text only: the provider's message is logged, never shown to the model
230
- const why = launchRefusedWhy(e);
230
+ const { why, text } = launchRefusedWhy(e);
231
231
  deps.log?.warn("managed background start failed", { taskId: task.id, err: e });
232
232
  // a reservation that never dispatched is settled; a dispatched one never is here
233
233
  if (await failManagedPreEffect(task.id, `launch refused: ${why}`, claim.executionId)) {
@@ -235,6 +235,7 @@ export async function runInBackgroundManaged(deps, ctx, input) {
235
235
  kind: "refused",
236
236
  task: (await background.get(task.id)) ?? task,
237
237
  why,
238
+ text,
238
239
  };
239
240
  }
240
241
  const now = (await background.get(task.id)) ?? task;
@@ -242,7 +243,7 @@ export async function runInBackgroundManaged(deps, ctx, input) {
242
243
  return { kind: "unknown", task: now };
243
244
  // a dispatched start the provider refused was settled with it: the kernel's reason
244
245
  if (now.launchState === "terminal" && isRefusal(e))
245
- return { kind: "refused", task: now, why };
246
+ return { kind: "refused", task: now, why, text };
246
247
  return { kind: "launched", task: now };
247
248
  }
248
249
  return {
@@ -270,6 +271,10 @@ export async function runInBackgroundManaged(deps, ctx, input) {
270
271
  const how = task.lostReason === "launch_unknown" ? "given up" : "revoked";
271
272
  throw new ToolError(`Background task ${task.id} ("${description}") may have started before its launch was ${how} (${taskReasonText(task)}); any process it started is being stopped and will not keep running, but it may already have had effects. Check them before calling Bash again as a new call.`);
272
273
  }
274
+ // the device cannot run any work (admission's cause, unsettled earlier work): its own sentence,
275
+ // since running the command without run_in_background is refused the same way
276
+ if (!started && launch.kind === "refused" && launch.text)
277
+ throw new ToolError(`The background task was not started. Calling Bash without run_in_background is refused the same way, so do not retry it that way. ${launch.text}`);
273
278
  if (!started && (launch.kind === "refused" || task.launchState === "terminal")) {
274
279
  // the recorded reason may hold a provider's words: the model gets kernel text only
275
280
  const why = launch.kind === "refused" ? launch.why : "it was stopped or refused before it started";
@@ -307,17 +312,30 @@ export async function runInBackgroundManaged(deps, ctx, input) {
307
312
  display: display(`后台运行命令:${shown}`, `Started in the background: ${shown}`),
308
313
  };
309
314
  }
310
- /** Why a managed start was refused, in the kernel's own words (never the provider's message). */
315
+ /**
316
+ * Why a managed start was refused, in the kernel's own words (never the provider's message):
317
+ * `why` is the clause recorded after `launch refused: `; `text`, the complete sentence for the
318
+ * model when the device cannot run any work, whatever the call (admission's cause, unsettled
319
+ * earlier work).
320
+ */
311
321
  function launchRefusedWhy(e) {
312
322
  if (isEscalationGrantMissing(e))
313
- return ESCALATION_GRANT_MISSING_LAUNCH_WHY;
314
- return launchRefusedText(isDeviceRequestNotSent(e)
315
- ? "not_sent"
316
- : isSandboxScopeDeniedError(e)
317
- ? "denied"
318
- : isSandboxPermissionUnsupportedError(e)
319
- ? "unsupported"
320
- : undefined);
323
+ return { why: ESCALATION_GRANT_MISSING_LAUNCH_WHY };
324
+ if (e instanceof PermissionAdmissionUnavailable) {
325
+ const text = admissionUnavailableText(e.cause);
326
+ return { why: text, text };
327
+ }
328
+ if (isSandboxWorkUnsettledError(e))
329
+ return { why: WORK_UNSETTLED_TOOL_TEXT, text: WORK_UNSETTLED_TOOL_TEXT };
330
+ return {
331
+ why: launchRefusedText(isDeviceRequestNotSent(e)
332
+ ? "not_sent"
333
+ : isSandboxScopeDeniedError(e)
334
+ ? "denied"
335
+ : isSandboxPermissionUnsupportedError(e)
336
+ ? "unsupported"
337
+ : undefined),
338
+ };
321
339
  }
322
340
  /** A typed refusal: the provider or admission proved the start had no effect. */
323
341
  const isRefusal = (e) => !isSandboxOperationOutcomeUnknownError(e) &&
@@ -394,7 +412,7 @@ export function sandboxDenialHint(r, escalation) {
394
412
  * {@link SCOPE_DENIED_TOOL_TEXT} followed by {@link ESCALATION_RETRY_HINT}, written out as a literal
395
413
  * for the tool design check (a unit test keeps the two copies equal).
396
414
  */
397
- export const SCOPE_DENIED_ESCALATION_TEXT = "This operation reaches outside what this conversation's permission profile allows on the device (a path outside the directories it may read or write, or a host it may not reach), so it did not run. Keep the call inside the working directory and the directories already granted, or ask the user to grant the directory or choose a broader permission profile, then retry. If this command must reach outside the sandbox, retry the same Bash call with sandbox: \"escalated\" and justification: one sentence saying why; this conversation's permission profile decides whether it may run outside the sandbox for this call only (the user, the review model, or Full access within this device's limits).";
415
+ export const SCOPE_DENIED_ESCALATION_TEXT = "This operation reaches outside the scope this conversation has on the device (a path outside the directories it may read or write, or a host it may not reach), so it did not run. Keep the call inside the working directory and the directories already granted, or ask the user to grant the directory, then retry. If this command must reach outside the sandbox, retry the same Bash call with sandbox: \"escalated\" and justification: one sentence saying why; this conversation's permission profile decides whether it may run outside the sandbox for this call only (the user, the review model, or Full access within this device's limits).";
398
416
  /**
399
417
  * A restricted call the scope refused ({@link SCOPE_DENIED_TOOL_TEXT}) where running outside the
400
418
  * sandbox is allowed: the refusal also says the call may be retried escalated.
@@ -11,6 +11,7 @@ import type { KernelConfigService } from "../../../infra/config/kernel-config.se
11
11
  import { ATTACHMENTS_ROOT, attachmentsDir, attachmentsRoot } from "../../../sandbox/attachments-path.js";
12
12
  import { type ManagedDeviceContextPort } from "../../../sandbox/managed-device-context.js";
13
13
  import type { SandboxMode } from "../../../sandbox/modes.js";
14
+ import { PermissionAdmissionUnavailable, type PermissionAvailabilityCause } from "../../../sandbox/permission-availability.js";
14
15
  import type { HeldDeviceContextEvidence } from "../../../sandbox/permission-context-types.js";
15
16
  import { type HeldProvider, type SandboxService } from "../../../sandbox/sandbox.service.js";
16
17
  import type { StorageService } from "../../../storage/storage.service.js";
@@ -263,15 +264,23 @@ export declare const RETIREMENT_REPLACE_TOOL_TEXT = "Background work started by
263
264
  * A managed operation outside the admitted scope (`SandboxScopeDeniedError`): fixed text, never
264
265
  * the refusal's own message (a provider may write it).
265
266
  */
266
- export declare const SCOPE_DENIED_TOOL_TEXT = "This operation reaches outside what this conversation's permission profile allows on the device (a path outside the directories it may read or write, or a host it may not reach), so it did not run. Keep the call inside the working directory and the directories already granted, or ask the user to grant the directory or choose a broader permission profile, then retry.";
267
+ export declare const SCOPE_DENIED_TOOL_TEXT = "This operation reaches outside the scope this conversation has on the device (a path outside the directories it may read or write, or a host it may not reach), so it did not run. Keep the call inside the working directory and the directories already granted, or ask the user to grant the directory, then retry.";
267
268
  /** An approved sandbox escalation whose grant no longer matches at admission (nothing ran). */
268
269
  export declare const ESCALATION_GRANT_MISSING_TEXT = "This Bash call was approved to run outside the sandbox, but the approval no longer matches: the device, its outside-sandbox setting or this conversation's permission scope changed since it was approved, so it did not run. Call Bash again with sandbox: \"escalated\" and a justification to ask again, or call it without sandbox to run it inside the sandbox.";
269
270
  /** {@link ESCALATION_GRANT_MISSING_TEXT} as the reason of a refused background start. */
270
271
  export declare const ESCALATION_GRANT_MISSING_LAUNCH_WHY = "its approval to run outside the sandbox no longer matches (the device, its outside-sandbox setting or the permission scope changed since it was approved); call Bash again with sandbox: \"escalated\" and a justification to ask again";
271
272
  /** A staged request the machine never got: it reconnected before the request was sent. */
272
273
  export declare const DEVICE_REQUEST_NOT_SENT_TOOL_TEXT = "The device's machine reconnected before this operation was sent, so nothing ran. Retry the tool call.";
273
- /** The device cannot enforce the conversation's profile (`SandboxPermissionUnsupportedError`). */
274
- export declare const PERMISSION_UNSUPPORTED_TOOL_TEXT = "This device cannot enforce this conversation's permission profile, so nothing ran. Ask the user to choose another permission profile for the conversation, or to start a new conversation on a device that supports it.";
274
+ /** The device itself refused: it cannot enforce its sandbox (`SandboxPermissionUnsupportedError`). */
275
+ export declare const PERMISSION_UNSUPPORTED_TOOL_TEXT = "This device refused to run the operation because it cannot enforce its sandbox limits, so nothing ran. Ask the device's owner to update capybara-device (or a super admin to update the device's sandbox plugin), or continue without the device.";
276
+ /** Earlier work on the device blocks a new operation (`SandboxWorkUnsettledError`). */
277
+ export declare const WORK_UNSETTLED_TOOL_TEXT = "Earlier work on this device has not settled yet, so nothing ran. Retry in a moment; if it keeps happening, ask the device's owner to stop the device's background tasks or restart capybara-device on that machine.";
278
+ export { PermissionAdmissionUnavailable };
279
+ /**
280
+ * Admission's refusal on a device without permission-scoped operations
281
+ * ({@link PermissionAdmissionUnavailable}): rendered from the cause, never from a provider's text.
282
+ */
283
+ export declare function admissionUnavailableText(cause: PermissionAvailabilityCause): string;
275
284
  /**
276
285
  * A device refused an operation scope as invalid (`SandboxScopeValidationError`): the kernel only
277
286
  * sends scopes it validated, so this is a kernel invariant break (or a skewed device), never the
@@ -1,4 +1,4 @@
1
- import { DEFAULT_SANDBOX_ROOTS, DeviceProtocolError, isFileSystemGoneError, isSandboxOperationOutcomeUnknownError, isSandboxPermissionUnsupportedError, isSandboxScopeDeniedError, isSandboxScopeValidationError, SandboxScopeDeniedError, ToolError, validateSandboxPath, validateSandboxPathShape, } from "@capybara-hq/plugin-sdk";
1
+ import { DEFAULT_SANDBOX_ROOTS, DeviceProtocolError, isFileSystemGoneError, isSandboxOperationOutcomeUnknownError, isSandboxPermissionUnsupportedError, isSandboxScopeDeniedError, isSandboxScopeValidationError, isSandboxWorkUnsettledError, SandboxScopeDeniedError, ToolError, validateSandboxPath, validateSandboxPathShape, } from "@capybara-hq/plugin-sdk";
2
2
  import { ANONYMOUS_NO_DEVICE, } from "../../../devices/conversation-devices.js";
3
3
  import { canonicalRoot, workingRootOf } from "../../../devices/working-root.js";
4
4
  import { ApiError } from "../../../errors.js";
@@ -9,6 +9,7 @@ import { ATTACHMENTS_ROOT, attachmentsDir, attachmentsRoot, } from "../../../san
9
9
  import { SandboxPathBusyError } from "../../../sandbox/leases.js";
10
10
  import { MANAGED_DEVICE_CONTEXT_FAILED_TEXT, MANAGED_DEVICE_CONTEXT_STALE_TEXT, MANAGED_DEVICE_CONTEXT_UNAVAILABLE_TEXT, ManagedDeviceContextFailed, ManagedDeviceContextStale, ManagedDeviceContextUnavailable, } from "../../../sandbox/managed-device-context.js";
11
11
  import { isEscalationGrantMissing } from "../../../sandbox/operation-authority-types.js";
12
+ import { PermissionAdmissionUnavailable, } from "../../../sandbox/permission-availability.js";
12
13
  import { isDeviceProgramRestarted } from "../../../sandbox/request-not-sent.js";
13
14
  import { RetirementPendingError, SandboxLockLostError, } from "../../../sandbox/sandbox.service.js";
14
15
  import { providerConnectionFailure, SandboxProviderUnreachableError, } from "../../../sandbox/unreachable.js";
@@ -305,15 +306,27 @@ function retirementToolText(code) {
305
306
  * A managed operation outside the admitted scope (`SandboxScopeDeniedError`): fixed text, never
306
307
  * the refusal's own message (a provider may write it).
307
308
  */
308
- export const SCOPE_DENIED_TOOL_TEXT = "This operation reaches outside what this conversation's permission profile allows on the device (a path outside the directories it may read or write, or a host it may not reach), so it did not run. Keep the call inside the working directory and the directories already granted, or ask the user to grant the directory or choose a broader permission profile, then retry.";
309
+ export const SCOPE_DENIED_TOOL_TEXT = "This operation reaches outside the scope this conversation has on the device (a path outside the directories it may read or write, or a host it may not reach), so it did not run. Keep the call inside the working directory and the directories already granted, or ask the user to grant the directory, then retry.";
309
310
  /** An approved sandbox escalation whose grant no longer matches at admission (nothing ran). */
310
311
  export const ESCALATION_GRANT_MISSING_TEXT = 'This Bash call was approved to run outside the sandbox, but the approval no longer matches: the device, its outside-sandbox setting or this conversation\'s permission scope changed since it was approved, so it did not run. Call Bash again with sandbox: "escalated" and a justification to ask again, or call it without sandbox to run it inside the sandbox.';
311
312
  /** {@link ESCALATION_GRANT_MISSING_TEXT} as the reason of a refused background start. */
312
313
  export const ESCALATION_GRANT_MISSING_LAUNCH_WHY = 'its approval to run outside the sandbox no longer matches (the device, its outside-sandbox setting or the permission scope changed since it was approved); call Bash again with sandbox: "escalated" and a justification to ask again';
313
314
  /** A staged request the machine never got: it reconnected before the request was sent. */
314
315
  export const DEVICE_REQUEST_NOT_SENT_TOOL_TEXT = "The device's machine reconnected before this operation was sent, so nothing ran. Retry the tool call.";
315
- /** The device cannot enforce the conversation's profile (`SandboxPermissionUnsupportedError`). */
316
- export const PERMISSION_UNSUPPORTED_TOOL_TEXT = "This device cannot enforce this conversation's permission profile, so nothing ran. Ask the user to choose another permission profile for the conversation, or to start a new conversation on a device that supports it.";
316
+ /** The device itself refused: it cannot enforce its sandbox (`SandboxPermissionUnsupportedError`). */
317
+ export const PERMISSION_UNSUPPORTED_TOOL_TEXT = "This device refused to run the operation because it cannot enforce its sandbox limits, so nothing ran. Ask the device's owner to update capybara-device (or a super admin to update the device's sandbox plugin), or continue without the device.";
318
+ /** Earlier work on the device blocks a new operation (`SandboxWorkUnsettledError`). */
319
+ export const WORK_UNSETTLED_TOOL_TEXT = "Earlier work on this device has not settled yet, so nothing ran. Retry in a moment; if it keeps happening, ask the device's owner to stop the device's background tasks or restart capybara-device on that machine.";
320
+ export { PermissionAdmissionUnavailable };
321
+ /**
322
+ * Admission's refusal on a device without permission-scoped operations
323
+ * ({@link PermissionAdmissionUnavailable}): rendered from the cause, never from a provider's text.
324
+ */
325
+ export function admissionUnavailableText(cause) {
326
+ if (cause.kind === "provider-outdated")
327
+ return `This device's sandbox plugin (${cause.plugin} ${cause.version}) cannot run device tools under a permission profile, so nothing ran. A super admin updates the plugin on the Plugins page; until then, continue without the device, or ask the user to start a new conversation on another device.`;
328
+ return "This device's runtime cannot enforce its sandbox, so nothing ran. Ask the device's owner to update capybara-device on that machine (for a cloud device, a super admin updates its sandbox plugin), or continue without the device.";
329
+ }
317
330
  /**
318
331
  * A device refused an operation scope as invalid (`SandboxScopeValidationError`): the kernel only
319
332
  * sends scopes it validated, so this is a kernel invariant break (or a skewed device), never the
@@ -388,8 +401,19 @@ export function mapSandboxError(e, log) {
388
401
  log?.warn("sandbox operation outside its scope", { err: e });
389
402
  return new ToolError(SCOPE_DENIED_TOOL_TEXT);
390
403
  }
404
+ // admission's own refusal and the unsettled refusal before the device's refusal they extend
405
+ if (e instanceof PermissionAdmissionUnavailable) {
406
+ log?.warn("device work refused: the device cannot run permission-scoped operations", {
407
+ err: e,
408
+ });
409
+ return new ToolError(admissionUnavailableText(e.cause));
410
+ }
411
+ if (isSandboxWorkUnsettledError(e)) {
412
+ log?.warn("device refused: earlier work is not settled", { err: e });
413
+ return new ToolError(WORK_UNSETTLED_TOOL_TEXT);
414
+ }
391
415
  if (isSandboxPermissionUnsupportedError(e)) {
392
- log?.warn("sandbox permission profile unsupported", { err: e });
416
+ log?.warn("device refused: it cannot enforce its sandbox", { err: e });
393
417
  return new ToolError(PERMISSION_UNSUPPORTED_TOOL_TEXT);
394
418
  }
395
419
  if (e instanceof SandboxProviderUnreachableError) {
@@ -3,7 +3,7 @@ import type { RouteSchemas } from "../platform/route-schemas.js";
3
3
  /**
4
4
  * A credential value: `Credentials.validate` checks its shape by auth method (values are never
5
5
  * echoed); this only bounds its size. A secret (`secret()` meta, ruling R2): a Platform operation
6
- * never takes it as a param; the person enters it on the confirmation card.
6
+ * never takes it as a param; the person enters it in a secure input request.
7
7
  */
8
8
  export declare const CredentialValue: z.ZodRecord<z.ZodString, z.ZodUnknown>;
9
9
  /** 「我已更新应用」: the admin drift hash of the connector template guide the person was shown. */
@@ -3,7 +3,7 @@ import { z } from "zod";
3
3
  /**
4
4
  * A credential value: `Credentials.validate` checks its shape by auth method (values are never
5
5
  * echoed); this only bounds its size. A secret (`secret()` meta, ruling R2): a Platform operation
6
- * never takes it as a param; the person enters it on the confirmation card.
6
+ * never takes it as a param; the person enters it in a secure input request.
7
7
  */
8
8
  export const CredentialValue = secret(z
9
9
  .record(z.string().max(100), z.unknown())
@@ -1,5 +1,6 @@
1
1
  import { type ConversationSource, type FormAnswer, type InputForm, type Logger } from "@capybara-hq/plugin-sdk";
2
2
  import type { AgentDefinition } from "../agents/definition.js";
3
+ import { ConversationApprovalProfile } from "../conversations/approval-profile.js";
3
4
  import { EventLog } from "../conversations/event-log.js";
4
5
  import type { KernelSchemaDb } from "../db/kernel-schema.js";
5
6
  import { ConversationDevices } from "../devices/conversation-devices.js";
@@ -32,7 +33,8 @@ import { OrgToolSwitches } from "./org-tool-switches.js";
32
33
  import { ToolOutputs } from "./outputs.js";
33
34
  import { type GrantKind } from "./policy.js";
34
35
  import { QuestionsService } from "./questions.service.js";
35
- import { type CallPolicy, type ResolvedTool, ToolRegistry } from "./registry.js";
36
+ import { type BuiltinCallContext, type CallPolicy, type ResolvedTool, ToolRegistry } from "./registry.js";
37
+ import { type ToolAskReviewer } from "./tool-review.js";
36
38
  /** 审批被拒绝。 */
37
39
  export declare const APPROVAL_DENIED_TEXT = "The user denied this tool call.";
38
40
  /**
@@ -97,11 +99,22 @@ export declare const PERSON_FIELDS_UNATTENDED_TEXT = "This write needs the perso
97
99
  export declare const PERSON_FIELDS_ROLE_TEXT = "This write needs the person you work for to enter values; they lack the role. Ask an admin to do it on the web.";
98
100
  /**
99
101
  * A call only the person may confirm (`CallPolicy.personOnly`: its result is shown once to the
100
- * approver) in an unattended run: nobody is there to approve and read it.
102
+ * run's person) in an unattended run: nobody is there to read it.
101
103
  */
102
- export declare const PERSON_ONLY_UNATTENDED_TEXT = "This write shows its result once, on the web, to the person who approves it; it cannot run unattended.";
104
+ export declare const PERSON_ONLY_UNATTENDED_TEXT = "This write shows its result once, on the web, to the person you work for, and no one is there to read it; it cannot run unattended.";
103
105
  /** A call only the person may confirm whose ask would go to a role instead of the person. */
104
- export declare const PERSON_ONLY_ROLE_TEXT = "This write shows its result once to the person you work for, who must approve it; they lack the role. Ask an admin to do it on the web.";
106
+ export declare const PERSON_ONLY_ROLE_TEXT = "This write shows its result once to the person you work for, so it runs only for them, and they lack the role. Ask an admin to do it on the web.";
107
+ /**
108
+ * The review model declined, under Approve for me, a call whose approval would have gone to the
109
+ * person (profiles govern every approval, R3): nothing ran.
110
+ */
111
+ export declare const toolReviewDeniedText: (reason: string) => string;
112
+ /** The reason recorded when Auto runs an approval addressed to the person (R2). */
113
+ export declare const TOOL_AUTO_REASON = "Auto runs approvals addressed to the person without asking.";
114
+ /** The person cancelled the secure input request of a call with person fields (R4): nothing ran. */
115
+ export declare const secureInputCancelledText: (id: string) => string;
116
+ /** A secure input request expired unanswered (R4): nothing ran. */
117
+ export declare const secureInputExpiredText: (id: string, hours: number) => string;
105
118
  /** 调用执行中 run 被中止 / 到达截止时间。 */
106
119
  export declare const RUN_STOPPED_DURING_TEXT = "The run was stopped while this tool call was running; its outcome is unknown. Verify before retrying.";
107
120
  /**
@@ -209,7 +222,7 @@ interface PipelineDeps {
209
222
  readonly breaker: Pick<Breaker, "check" | "failure" | "success">;
210
223
  readonly outputs: Pick<ToolOutputs, "save" | "load">;
211
224
  /** 策略为 `ask` 时建审批;续跑时读该调用的审批结果。 A refused network host: a network ask. */
212
- readonly approvals: Pick<ApprovalsService, "request" | "forCall" | "networkForCall" | "requestNetwork" | "commandForCall" | "requestCommand">;
225
+ readonly approvals: Pick<ApprovalsService, "request" | "forCall" | "networkForCall" | "requestNetwork" | "commandForCall" | "requestCommand" | "requestSecureInput" | "secureInputForCall">;
213
226
  /** 处理函数返回 `input_required` 时建输入请求;续跑时读该调用的各轮输入请求。 */
214
227
  readonly questions: Pick<QuestionsService, "ask" | "forCall">;
215
228
  readonly log: Logger;
@@ -377,13 +390,20 @@ export declare class ToolPipeline {
377
390
  private readonly permissionLocks?;
378
391
  /** Starts a cloud device before its first managed call is reviewed (absent: never). */
379
392
  private readonly sandboxes?;
393
+ /**
394
+ * The profile of an ask addressed to the conversation's person (profiles govern every
395
+ * approval, R1); absent with {@link toolReview} (hand-built pipelines): every ask asks.
396
+ */
397
+ private readonly approvalProfile?;
398
+ /** The review model's judgment of an ask under Approve for me (R3); absent: every ask asks. */
399
+ private readonly toolReview?;
380
400
  private readonly decide;
381
401
  private readonly deps;
382
402
  constructor(kdb: KernelDb, eventLog: EventLog,
383
403
  /** The `Agent` tool's sub-agent dispatch; absent (tests): `Agent` calls are refused. */
384
404
  subagents: Pick<SubagentsService, "dispatch"> | undefined,
385
405
  /** The message tools between agents; absent (tests): their calls are refused. */
386
- messages: Pick<SubagentMessages, "toChild" | "toParent"> | undefined, registry: Pick<ToolRegistry, "forAgent" | "findConnector" | "handler">, credentials: Pick<Credentials, "injection" | "onUnauthorized">, breaker: Pick<Breaker, "check" | "failure" | "success">, outputs: Pick<ToolOutputs, "save" | "load">, approvals: Pick<ApprovalsService, "request" | "forCall" | "networkForCall" | "requestNetwork" | "commandForCall" | "requestCommand">, questions: Pick<QuestionsService, "ask" | "forCall">, config: Pick<KernelConfigService, "get">, log: Logger & Partial<Pick<KernelLogger, "debug">>,
406
+ messages: Pick<SubagentMessages, "toChild" | "toParent"> | undefined, registry: Pick<ToolRegistry, "forAgent" | "findConnector" | "handler">, credentials: Pick<Credentials, "injection" | "onUnauthorized">, breaker: Pick<Breaker, "check" | "failure" | "success">, outputs: Pick<ToolOutputs, "save" | "load">, approvals: Pick<ApprovalsService, "request" | "forCall" | "networkForCall" | "requestNetwork" | "commandForCall" | "requestCommand" | "requestSecureInput" | "secureInputForCall">, questions: Pick<QuestionsService, "ask" | "forCall">, config: Pick<KernelConfigService, "get">, log: Logger & Partial<Pick<KernelLogger, "debug">>,
387
407
  /** Plugin hooks and inline ui contributions; absent (tests): no hooks, cards dropped. */
388
408
  host: Pick<ExtensionHost, "hooks" | "current"> | undefined, drift: Pick<ToolDrift, "onToolsChanged"> | undefined, effective: Pick<EffectiveConfigs, "get">, switches: Pick<OrgToolSwitches, "isToolOff">, txHost: TransactionHost, hooks?: ToolPipelineHooks, networkGrants?: {
389
409
  runState(runId: string, deviceId?: string): Promise<NetworkRunState>;
@@ -397,7 +417,14 @@ export declare class ToolPipeline {
397
417
  /** The paired activation gate: on, the managed builtins take the permission review. */
398
418
  activation?: boolean,
399
419
  /** Starts a cloud device before its first managed call is reviewed (absent: never). */
400
- sandboxes?: Pick<SandboxService, "ensureRunning" | "hostRefusal"> | undefined);
420
+ sandboxes?: Pick<SandboxService, "ensureRunning" | "hostRefusal"> | undefined,
421
+ /**
422
+ * The profile of an ask addressed to the conversation's person (profiles govern every
423
+ * approval, R1); absent with {@link toolReview} (hand-built pipelines): every ask asks.
424
+ */
425
+ approvalProfile?: Pick<ConversationApprovalProfile, "resolve"> | undefined,
426
+ /** The review model's judgment of an ask under Approve for me (R3); absent: every ask asks. */
427
+ toolReview?: ToolAskReviewer | undefined);
401
428
  /**
402
429
  * tools 节点:按顺序处理本步 assistant 消息里的全部 `tool_call`,每个调用都以一条 `tool_result` 结束
403
430
  * (之后才回到 prepare 构建下一次请求,保持「已记录调用、未记录结果之间不构建请求」的不变式)。
@@ -427,6 +454,25 @@ export declare class ToolPipeline {
427
454
  */
428
455
  private processCall;
429
456
  private runCall;
457
+ /**
458
+ * The profile step (profiles govern every approval, R1-R3) of an ask `decide` returned for a call
459
+ * no approval governs yet. It applies only to an ask addressed to the person (no role, the root
460
+ * conversation's own owner), in an attended interactive chat, and for a tool that does not
461
+ * itself require the person's interaction (D3); a call's secret fields are asked afterwards in a
462
+ * secure input request whatever it decides (R4). Request approval asks; Auto allows; Approve for
463
+ * me asks the review model, whose unsure answer asks the person. An `allow` or `deny` is recorded
464
+ * once (`tool_ask_decided` and its audit row); a resumed call reads that record before the profile
465
+ * and never calls the review model again. Anything that cannot be read asks the person (fail closed).
466
+ */
467
+ private profileStep;
468
+ /** Records an automatic decision once (R2) and announces it after the commit. */
469
+ private recordAskDecision;
470
+ /**
471
+ * The `tool_ask_decided` event and, when this call wrote it, its audit row
472
+ * `tool.ask_auto_decided`, in one transaction: a retry or another replica returns the recorded
473
+ * event and audits nothing (every automatic decision is audited exactly once).
474
+ */
475
+ private recordAskDecisionIn;
430
476
  /**
431
477
  * The command review of one call (auto mode spec §5.1, §5.4), after argument validation and the
432
478
  * tool policy (and its approval), before the plugin hooks and execution. The device facts come
@@ -483,8 +529,18 @@ export declare class ToolPipeline {
483
529
  */
484
530
  private sentTools;
485
531
  /**
486
- * A decided approval other than approved → the model's text; still pending → null (wait). A
487
- * person field refused on the card as leaked is named, so the agent has the key rotated.
532
+ * The secure input of a call with person fields (R4): the latest request of the call, bound like
533
+ * an approval to the definition and the raw input it was made for. None, or a submitted one made
534
+ * for another definition or input, asks again; a pending one waits. A cancel, an expiry or a
535
+ * stopped run ends the call with nothing run; a submitted one returns its id, which the tool
536
+ * reads the sealed values by. The request goes to the run's person, who alone may submit it.
537
+ */
538
+ private secureInput;
539
+ /** The highest attempt of any approval of the call, of every kind (0: none yet). */
540
+ private lastAttempt;
541
+ /**
542
+ * A decided tool approval other than approved → the model's text; still pending → null (wait).
543
+ * A tool approval takes no values (a secure input does), so it never names leaked fields.
488
544
  */
489
545
  private refusalText;
490
546
  /**
@@ -505,7 +561,11 @@ export declare class ToolPipeline {
505
561
  escalationRefusal?: string | undefined;
506
562
  },
507
563
  /** The approved approval of this call, matching its definition and input (builtins only). */
508
- approvalId?: string): Promise<ExecOutcome>;
564
+ approvalId?: string,
565
+ /** The automatic decision the call runs under instead of an approval (builtins only, R2). */
566
+ decision?: BuiltinCallContext["decision"],
567
+ /** The submitted secure input request of this call (builtins only, R4). */
568
+ secureInputId?: string): Promise<ExecOutcome>;
509
569
  private executeConnector;
510
570
  /** 抛出的错误 → 给模型的结果:ToolError 的消息原样(插件约定为英文、可操作),其他只给错误类名。 */
511
571
  private thrown;