@capybara-hq/kernel 0.1.0-rc.63 → 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 (91) hide show
  1. package/dist/catalog/marketplaces.service.d.ts +1 -1
  2. package/dist/catalog/org-catalog.schemas.d.ts +1 -1
  3. package/dist/catalog/org-catalog.schemas.js +1 -1
  4. package/dist/channels/actions.d.ts +2 -5
  5. package/dist/channels/actions.js +20 -8
  6. package/dist/channels/cards.d.ts +4 -3
  7. package/dist/channels/cards.js +6 -4
  8. package/dist/channels/outbound.js +3 -2
  9. package/dist/config/schema.js +1 -1
  10. package/dist/conversations/approval-profile.d.ts +30 -0
  11. package/dist/conversations/approval-profile.js +62 -0
  12. package/dist/conversations/conversations.service.js +0 -2
  13. package/dist/conversations/events.d.ts +43 -0
  14. package/dist/conversations/events.js +52 -0
  15. package/dist/conversations/permission-profiles.controller.d.ts +3 -2
  16. package/dist/conversations/permission-profiles.service.d.ts +3 -2
  17. package/dist/conversations/permission-profiles.service.js +12 -8
  18. package/dist/db/kernel-schema.d.ts +4 -2
  19. package/dist/identity/initial-passwords.controller.d.ts +8 -6
  20. package/dist/identity/initial-passwords.controller.js +13 -7
  21. package/dist/identity/initial-passwords.d.ts +22 -13
  22. package/dist/identity/initial-passwords.js +25 -29
  23. package/dist/local-devices/relay.js +3 -1
  24. package/dist/models/images.js +5 -4
  25. package/dist/platform/connector-person-fields.js +2 -2
  26. package/dist/platform/exclusions.js +4 -4
  27. package/dist/platform/method.js +1 -1
  28. package/dist/platform/operation.d.ts +9 -7
  29. package/dist/platform/operation.js +1 -1
  30. package/dist/platform/ops/accounts.ops.d.ts +1 -1
  31. package/dist/platform/ops/accounts.ops.js +3 -3
  32. package/dist/platform/ops/channels.ops.d.ts +1 -1
  33. package/dist/platform/ops/channels.ops.js +2 -2
  34. package/dist/platform/ops/connectors.ops.d.ts +2 -2
  35. package/dist/platform/ops/connectors.ops.js +8 -8
  36. package/dist/platform/ops/extensions-admin.ops.d.ts +1 -1
  37. package/dist/platform/ops/extensions-admin.ops.js +3 -3
  38. package/dist/platform/ops/extensions.ops.d.ts +1 -1
  39. package/dist/platform/ops/extensions.ops.js +4 -4
  40. package/dist/platform/ops/org-plugins.ops.js +2 -2
  41. package/dist/platform/ops/orgs.ops.d.ts +1 -1
  42. package/dist/platform/ops/orgs.ops.js +3 -3
  43. package/dist/platform/ops/plugins.ops.d.ts +1 -1
  44. package/dist/platform/ops/plugins.ops.js +2 -2
  45. package/dist/platform/person-fields.d.ts +4 -3
  46. package/dist/platform/person-fields.js +6 -5
  47. package/dist/platform/sealed-inputs.d.ts +2 -2
  48. package/dist/platform/sealed-inputs.js +2 -2
  49. package/dist/platform/sealed-reveals.controller.d.ts +5 -8
  50. package/dist/platform/sealed-reveals.controller.js +8 -8
  51. package/dist/platform/sealed-reveals.d.ts +19 -17
  52. package/dist/platform/sealed-reveals.js +30 -33
  53. package/dist/runtime/context/build.js +3 -0
  54. package/dist/runtime/context/compaction.js +2 -0
  55. package/dist/runtime/waits.js +3 -2
  56. package/dist/sandbox/operation-authority.js +16 -15
  57. package/dist/sandbox/operation-intents.js +2 -2
  58. package/dist/sandbox/permission-availability.d.ts +49 -3
  59. package/dist/sandbox/permission-availability.js +61 -6
  60. package/dist/sandbox/permission-call-types.d.ts +3 -0
  61. package/dist/sandbox/permission-facts.d.ts +29 -1
  62. package/dist/sandbox/permission-facts.js +29 -6
  63. package/dist/sandbox/review/classifier.d.ts +72 -2
  64. package/dist/sandbox/review/classifier.js +113 -38
  65. package/dist/sandbox/review/index.d.ts +2 -2
  66. package/dist/sandbox/review/index.js +1 -1
  67. package/dist/sandbox/review/review.service.d.ts +1 -4
  68. package/dist/sandbox/review/review.service.js +4 -33
  69. package/dist/setup/setup-guides.service.js +1 -1
  70. package/dist/tools/approvals.service.d.ts +71 -16
  71. package/dist/tools/approvals.service.js +139 -13
  72. package/dist/tools/builtins/builtin-tools.d.ts +1 -1
  73. package/dist/tools/builtins/builtin-tools.js +12 -6
  74. package/dist/tools/builtins/platform.d.ts +15 -11
  75. package/dist/tools/builtins/platform.js +49 -39
  76. package/dist/tools/builtins/sandbox/bash.d.ts +1 -1
  77. package/dist/tools/builtins/sandbox/bash.js +32 -14
  78. package/dist/tools/builtins/sandbox/common.d.ts +12 -3
  79. package/dist/tools/builtins/sandbox/common.js +29 -5
  80. package/dist/tools/connectors.schemas.d.ts +1 -1
  81. package/dist/tools/connectors.schemas.js +1 -1
  82. package/dist/tools/pipeline.d.ts +70 -10
  83. package/dist/tools/pipeline.js +356 -48
  84. package/dist/tools/policy.d.ts +4 -3
  85. package/dist/tools/policy.js +6 -6
  86. package/dist/tools/registry.d.ts +25 -9
  87. package/dist/tools/tool-review.d.ts +113 -0
  88. package/dist/tools/tool-review.js +303 -0
  89. package/dist/tools/tools.module.js +6 -0
  90. package/package.json +4 -4
  91. package/src/migrations/0175_secure_input_kind.sql +8 -0
@@ -23,14 +23,18 @@ import { BUILTIN } from "../builtin-names.js";
23
23
  * - An `ApiError` gets the next step the operation declares for its code and the actor's role.
24
24
  * - The actor, the agent and the conversation come from the runtime context, never from input.
25
25
  * - A write with person fields (platform web parity spec §4: `op.personFields`) is planned at the
26
- * policy step: a secret in `values` is denied before the card, and the asked fields go to the
27
- * card through {@link CallPolicy.personFields} (never remembered). The approved call reads the
28
- * person's sealed values through `personInputs` and its result names each entered path, never a
29
- * value.
26
+ * policy step: a secret in `values` is denied before any card, and the asked fields go to the
27
+ * pipeline through {@link CallPolicy.personFields}, which asks for them in a secure input request
28
+ * after the consent (profiles govern every approval, R4). The call reads the person's sealed
29
+ * values by that request (`BuiltinCallContext.secureInputId`) through `personInputs`, and its
30
+ * result names the request and each entered path, never a value.
30
31
  * - A write that takes a file in place of an upload (spec §5: `op.fileRef`) resolves it at the
31
32
  * policy step: a file over the limit or of another type is denied before the card; the card
32
- * shows it (`CallPolicy.file`, never remembered) and the approval binds its sha256. Right before
33
- * `op.run` the file is read again, and bytes with another sha256 are refused.
33
+ * shows it (`CallPolicy.file`, never remembered) and the approval binds its sha256, or, with no
34
+ * approval, the automatic decision does (R7). Right before `op.run` the file is read again, and
35
+ * bytes with another sha256 are refused.
36
+ * - A write whose result is shown once to the run's person (`op.revealsOnce`) carries the
37
+ * reveal view, which the web reads by the call (R6).
34
38
  * - Results are JSON text; a list an operation returns is capped at {@link LIST_MAX} entries.
35
39
  */
36
40
  /** The most entries of a list in one result (operations that page return `next`). */
@@ -231,11 +235,11 @@ const missingText = (action, field, what) => `Action ${action} needs "${field}":
231
235
  const invalidParamsText = (id, problems) => `Invalid params for ${id}: ${problems}. Call describe with operation "${id}" for its input schema and an example, then call again.`;
232
236
  const unavailableOpText = (id, reason) => `Operation ${id} is unavailable, so do not call it again as is: ${reason}`;
233
237
  const precheckText = (id, code, message, next) => `Operation ${id} cannot run now: ${code}: ${sentence(message)} ${next ?? OPERATION_ERROR_NEXT}`;
234
- const secretRecordText = (id, path, target) => `Operation ${id} cannot run now: platform.secret_record_web_only: \`${path}\` is a secret record, which the confirmation card cannot ask for. Tell the person to enter it on the web page of ${target}.`;
238
+ const secretRecordText = (id, path, target) => `Operation ${id} cannot run now: platform.secret_record_web_only: \`${path}\` is a secret record, which a secure input request cannot ask for. Tell the person to enter it on the web page of ${target}.`;
235
239
  /** Model-visible: the person's values expired before the approved call ran (spec §4.3). */
236
240
  export const PERSON_INPUTS_EXPIRED_TEXT = "The values the person entered expired before they were applied; call the operation again.";
237
241
  /** Model-visible: an approved call with person fields that has no approval to read them by. */
238
- const personInputsMissingText = (id) => `Operation ${id} needs values the person enters on the confirmation card, and this call ran without one; call the operation again.`;
242
+ const personInputsMissingText = (id) => `Operation ${id} needs values the person enters in a secure input request, and this call ran without one; call the operation again.`;
239
243
  /**
240
244
  * Model-visible: the person-field plan refused an approved call when it resumed (the target's
241
245
  * secret fields changed while the card waited); `message` is the plan's English refusal.
@@ -248,6 +252,8 @@ const personRefusedText = (id, message) => `Operation ${id} cannot run as approv
248
252
  const PERSON_FIELDS_CHANGED_TEXT = "The target changed after the person confirmed (the fields to enter differ); call the operation again.";
249
253
  /** Model-visible result line: the approved call's operation never applied the person's values. */
250
254
  const unusedValuesText = (id) => `The values the person entered were not used by ${id}.`;
255
+ /** The result line naming the submitted secure input request (never a value). */
256
+ const submittedLine = (id) => `Secure input ${id}: submitted.`;
251
257
  /** The result line of one field the person entered (never its value). */
252
258
  const enteredLine = (path) => `\`${path}\`: entered by the person`;
253
259
  /** Model-visible: an operation takes a file, and this kernel has no resolver wired (a bug). */
@@ -391,15 +397,14 @@ export function platformTool(deps) {
391
397
  return {
392
398
  key,
393
399
  policy: "ask",
394
- // org / platform writes are confirmed every time (spec §6.2); so is a write with person
395
- // fields, whatever its class (spec §4.2, R6), and one whose card shows a file (§5: the
396
- // person confirms these bytes)
397
- remember: personFields === null && card === null && cls === "personal" && op.rememberable !== false,
400
+ // org / platform writes are confirmed every time (spec §6.2); so is one whose card shows a
401
+ // file (§5: the person confirms these bytes). Person fields do not decide the consent (R5)
402
+ remember: card === null && cls === "personal" && op.rememberable !== false,
398
403
  summary,
399
404
  ...(personFields !== null && { personFields }),
400
405
  ...(card !== null && { file: card }),
401
- // its result is shown once to the approver: only the person may confirm it
402
- ...(op.revealsToApprover === true && { personOnly: true }),
406
+ // its result is shown once to the run's person: only they may consent to it
407
+ ...(op.revealsOnce !== undefined && { personOnly: true }),
403
408
  };
404
409
  }
405
410
  async function run(raw, ctx) {
@@ -499,30 +504,31 @@ export function platformTool(deps) {
499
504
  // the file is read again, and must be the bytes the person confirmed (Review Focus 5)
500
505
  const file = await fileOf(op, params, deps, octx, ctx.signal);
501
506
  if (file !== null) {
502
- // fails closed: bytes run only under this call's approval whose card showed them (no
503
- // approval, one whose card showed no file or another one does not cover these bytes)
504
- const bound = ctx.approvalId === undefined ||
505
- ctx.runId === undefined ||
506
- deps.approvalFileSha256 === undefined
507
- ? null
508
- : await deps.approvalFileSha256(ctx.approvalId, {
509
- orgId: ctx.orgId,
510
- runId: ctx.runId,
511
- callId: ctx.callId,
512
- });
507
+ // fails closed: bytes run only under this call's approval whose card showed them or,
508
+ // with no approval, the automatic decision that was bound to them (R7); a grant, an
509
+ // approval whose card showed no file or another one does not cover these bytes
510
+ const bound = ctx.approvalId !== undefined
511
+ ? ctx.runId === undefined || deps.approvalFileSha256 === undefined
512
+ ? null
513
+ : await deps.approvalFileSha256(ctx.approvalId, {
514
+ orgId: ctx.orgId,
515
+ runId: ctx.runId,
516
+ callId: ctx.callId,
517
+ })
518
+ : (ctx.decision?.fileSha256 ?? null);
513
519
  if (bound === null || bound !== file.sha256)
514
520
  throw new ToolError(FILE_CHANGED_TEXT);
515
521
  octx.file = file;
516
522
  }
517
523
  const person = await personFieldsOf(op, params, octx);
518
- // what the card showed (the approval's stored specs) binds what runs: the run-time plan
519
- // must ask exactly those fields, and the sealed values must carry exactly them
520
- const approvalId = ctx.approvalId;
521
- const shown = approvalId === undefined ||
522
- deps.approvalPersonPaths === undefined ||
524
+ // what the secure input asked (its stored specs) binds what runs: the run-time plan must
525
+ // ask exactly those fields, and the sealed values must carry exactly them
526
+ const secureInputId = ctx.secureInputId;
527
+ const shown = secureInputId === undefined ||
528
+ deps.secureInputPaths === undefined ||
523
529
  ctx.runId === undefined
524
530
  ? null
525
- : await deps.approvalPersonPaths(approvalId, {
531
+ : await deps.secureInputPaths(secureInputId, {
526
532
  orgId: ctx.orgId,
527
533
  runId: ctx.runId,
528
534
  callId: ctx.callId,
@@ -531,10 +537,10 @@ export function platformTool(deps) {
531
537
  throw new PersonFieldsChanged();
532
538
  if (person !== null) {
533
539
  const sealed = deps.sealed;
534
- if (approvalId === undefined || sealed === undefined) {
540
+ if (secureInputId === undefined || sealed === undefined) {
535
541
  throw new ToolError(personInputsMissingText(op.id));
536
542
  }
537
- // an approval made before the call had person fields (the target changed since)
543
+ // a request that is not this call's submitted one, or asked before the target changed
538
544
  if (shown === null)
539
545
  throw new PersonFieldsChanged();
540
546
  const asked = person.fields.map((p) => p.path);
@@ -546,9 +552,9 @@ export function platformTool(deps) {
546
552
  if (applied)
547
553
  throw new Error("personInputs.apply called twice");
548
554
  applied = true;
549
- // the person who typed the values is the run's trigger account, the approval's
550
- // `requested_for` (a role escalation is refused before the card, R5)
551
- return sealed.consume(approvalId, ctx.accountId, async (values) => {
555
+ // the person who typed the values is the run's trigger account, the secure input's
556
+ // `requested_for` (a role escalation is refused before any card, R5)
557
+ return sealed.consume(secureInputId, ctx.accountId, async (values) => {
552
558
  // a throw here rolls the row's delete back: nothing is applied
553
559
  if (!sameSet(Object.keys(values), shown) || !sameSet(asked, shown)) {
554
560
  throw new PersonFieldsChanged();
@@ -574,14 +580,18 @@ export function platformTool(deps) {
574
580
  throw toToolError(e, (code) => nextStepFor(op.errors, code, role));
575
581
  }
576
582
  const summary = { zh: `调用平台操作 ${op.id}`, en: `Called ${op.id}` };
577
- const lines = entered.map(enteredLine);
583
+ const lines = octx.personInputs !== undefined && ctx.secureInputId !== undefined
584
+ ? [submittedLine(ctx.secureInputId), ...entered.map(enteredLine)]
585
+ : entered.map(enteredLine);
578
586
  if (octx.personInputs !== undefined && !applied) {
579
587
  // an operation bug: the person typed values the write never used (they expire unread)
580
588
  deps.log?.warn("platform operation did not use the person's values", { operation: op.id });
581
589
  lines.push(unusedValuesText(op.id));
582
590
  }
583
- const view = handoffOf(op, params, result, octx, deps.log);
584
- const out = withReviewUrl(asResult(withoutPersonAvatars(result)), view);
591
+ const handoff = handoffOf(op, params, result, octx, deps.log);
592
+ const out = withReviewUrl(asResult(withoutPersonAvatars(result)), handoff);
593
+ // a result shown once to the run's person: the web reads it by this call (R6)
594
+ const view = op.revealsOnce !== undefined ? { kind: "reveal", reveal: op.revealsOnce } : handoff;
585
595
  return {
586
596
  content: [
587
597
  { type: "text", text: JSON.stringify(out) },
@@ -60,7 +60,7 @@ export declare function sandboxDenialHint(r: ExecResult, escalation: {
60
60
  * {@link SCOPE_DENIED_TOOL_TEXT} followed by {@link ESCALATION_RETRY_HINT}, written out as a literal
61
61
  * for the tool design check (a unit test keeps the two copies equal).
62
62
  */
63
- export declare 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).";
63
+ export declare 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).";
64
64
  /** 内置工具 `Bash`:在本对话的沙箱里执行命令。 */
65
65
  export declare function sandboxBashTool(deps: SandboxToolDeps): BuiltinTool;
66
66
  export {};
@@ -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;