@capybara-hq/kernel 0.1.0-rc.49 → 0.1.0-rc.50

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 (128) hide show
  1. package/dist/admin/admin.schemas.d.ts +0 -6
  2. package/dist/background/launch.d.ts +7 -61
  3. package/dist/background/launch.js +8 -133
  4. package/dist/background/poll.job.d.ts +19 -23
  5. package/dist/background/poll.job.js +30 -66
  6. package/dist/background/render.d.ts +9 -0
  7. package/dist/background/render.js +19 -0
  8. package/dist/background/session.d.ts +3 -66
  9. package/dist/background/session.js +3 -114
  10. package/dist/background/stop.d.ts +26 -33
  11. package/dist/background/stop.js +59 -90
  12. package/dist/background/store.d.ts +26 -60
  13. package/dist/background/store.js +23 -108
  14. package/dist/background/tasks.service.d.ts +9 -29
  15. package/dist/background/tasks.service.js +18 -115
  16. package/dist/catalog/marketplaces.service.d.ts +1 -1
  17. package/dist/channels/cards.d.ts +3 -0
  18. package/dist/channels/cards.js +29 -2
  19. package/dist/channels/phrases.d.ts +35 -0
  20. package/dist/channels/phrases.js +32 -0
  21. package/dist/config/load.d.ts +3 -10
  22. package/dist/config/load.js +26 -21
  23. package/dist/config/schema.js +3 -3
  24. package/dist/conversations/events.d.ts +45 -2
  25. package/dist/conversations/events.js +44 -4
  26. package/dist/db/kernel-schema.d.ts +9 -4
  27. package/dist/devices/devices.service.js +1 -1
  28. package/dist/devices/errors.d.ts +5 -0
  29. package/dist/devices/errors.js +5 -0
  30. package/dist/devices/project-rules.d.ts +2 -2
  31. package/dist/errors.d.ts +9 -11
  32. package/dist/errors.js +9 -11
  33. package/dist/identity/settings.d.ts +4 -17
  34. package/dist/identity/settings.js +9 -32
  35. package/dist/infra/config/kernel-config.service.js +2 -9
  36. package/dist/infra/outbox/registry.d.ts +13 -0
  37. package/dist/infra/outbox/registry.js +8 -0
  38. package/dist/local-devices/device-auth.controller.d.ts +1 -1
  39. package/dist/local-devices/device-auth.controller.js +1 -1
  40. package/dist/local-devices/device-auth.d.ts +4 -3
  41. package/dist/local-devices/device-auth.js +1 -1
  42. package/dist/local-devices/device-policy.service.d.ts +6 -6
  43. package/dist/local-devices/device-routes.d.ts +4 -2
  44. package/dist/local-devices/device-routes.js +7 -6
  45. package/dist/local-devices/instance-bindings.d.ts +4 -4
  46. package/dist/local-devices/instance-bindings.js +2 -2
  47. package/dist/local-devices/local-device-gateway.d.ts +12 -12
  48. package/dist/local-devices/local-device-gateway.js +94 -129
  49. package/dist/local-devices/local-device-provider.d.ts +19 -87
  50. package/dist/local-devices/local-device-provider.js +43 -158
  51. package/dist/local-devices/local-devices.module.d.ts +4 -5
  52. package/dist/local-devices/local-devices.module.js +6 -9
  53. package/dist/local-devices/machines.d.ts +6 -6
  54. package/dist/local-devices/machines.js +4 -4
  55. package/dist/local-devices/owner-report.d.ts +3 -3
  56. package/dist/local-devices/owner-report.js +4 -4
  57. package/dist/local-devices/owner-reports.js +2 -2
  58. package/dist/local-devices/policy-summary.js +2 -2
  59. package/dist/local-devices/relay.d.ts +12 -25
  60. package/dist/local-devices/relay.js +17 -31
  61. package/dist/orgs/settings.controller.d.ts +1 -4
  62. package/dist/orgs/settings.controller.js +3 -3
  63. package/dist/orgs/settings.service.d.ts +7 -21
  64. package/dist/orgs/settings.service.js +16 -40
  65. package/dist/overrides.d.ts +3 -3
  66. package/dist/platform/ops/admin.ops.js +6 -8
  67. package/dist/platform/ops/org-settings.ops.js +4 -4
  68. package/dist/platform/ops/orgs.ops.js +0 -1
  69. package/dist/runtime/maintenance.d.ts +1 -1
  70. package/dist/runtime/maintenance.js +7 -1
  71. package/dist/runtime/run-steps.js +2 -2
  72. package/dist/sandbox/held-operations.d.ts +7 -0
  73. package/dist/sandbox/held-operations.js +25 -1
  74. package/dist/sandbox/leases.d.ts +6 -3
  75. package/dist/sandbox/leases.js +16 -10
  76. package/dist/sandbox/legacy-retirement.d.ts +0 -19
  77. package/dist/sandbox/legacy-retirement.js +6 -37
  78. package/dist/sandbox/managed-device-context.d.ts +12 -0
  79. package/dist/sandbox/managed-device-context.js +49 -1
  80. package/dist/sandbox/modes.d.ts +9 -8
  81. package/dist/sandbox/modes.js +4 -15
  82. package/dist/sandbox/operation-authority-types.d.ts +18 -1
  83. package/dist/sandbox/operation-authority-types.js +20 -1
  84. package/dist/sandbox/operation-authority.d.ts +14 -0
  85. package/dist/sandbox/operation-authority.js +120 -18
  86. package/dist/sandbox/operation-intents.d.ts +43 -0
  87. package/dist/sandbox/operation-intents.js +107 -4
  88. package/dist/sandbox/operation-reconcile.job.d.ts +12 -1
  89. package/dist/sandbox/operation-reconcile.job.js +53 -6
  90. package/dist/sandbox/permission-call-grants.d.ts +4 -0
  91. package/dist/sandbox/permission-call-grants.js +32 -3
  92. package/dist/sandbox/permission-call-types.d.ts +27 -2
  93. package/dist/sandbox/permission-ceiling-writes.js +2 -1
  94. package/dist/sandbox/permission-context-types.d.ts +2 -2
  95. package/dist/sandbox/permission-context-types.js +2 -2
  96. package/dist/sandbox/permission-facts.js +10 -2
  97. package/dist/sandbox/platform-full-access.d.ts +8 -26
  98. package/dist/sandbox/platform-full-access.js +8 -20
  99. package/dist/sandbox/review/classifier.d.ts +2 -2
  100. package/dist/sandbox/review/classifier.js +18 -5
  101. package/dist/sandbox/review/permission-candidate.d.ts +59 -3
  102. package/dist/sandbox/review/permission-candidate.js +192 -25
  103. package/dist/sandbox/review/review.service.d.ts +18 -0
  104. package/dist/sandbox/review/review.service.js +158 -12
  105. package/dist/sandbox/sandbox.service.d.ts +71 -47
  106. package/dist/sandbox/sandbox.service.js +234 -133
  107. package/dist/tools/approvals.service.d.ts +6 -1
  108. package/dist/tools/approvals.service.js +10 -0
  109. package/dist/tools/builtins/builtin-tools.d.ts +1 -4
  110. package/dist/tools/builtins/builtin-tools.js +13 -18
  111. package/dist/tools/builtins/sandbox/bash.d.ts +16 -3
  112. package/dist/tools/builtins/sandbox/bash.js +92 -270
  113. package/dist/tools/builtins/sandbox/common.d.ts +15 -9
  114. package/dist/tools/builtins/sandbox/common.js +55 -19
  115. package/dist/tools/builtins/sandbox/device-owner.d.ts +13 -0
  116. package/dist/tools/builtins/sandbox/device-owner.js +14 -0
  117. package/dist/tools/builtins/sandbox/task-list.js +2 -2
  118. package/dist/tools/builtins/sandbox/task-output.d.ts +14 -57
  119. package/dist/tools/builtins/sandbox/task-output.js +88 -210
  120. package/dist/tools/builtins/sandbox/task-stop.d.ts +2 -2
  121. package/dist/tools/builtins/sandbox/task-stop.js +15 -26
  122. package/dist/tools/pipeline.d.ts +31 -2
  123. package/dist/tools/pipeline.js +273 -43
  124. package/dist/tools/registry.d.ts +7 -0
  125. package/package.json +4 -4
  126. package/src/migrations/0162_permission_call_escalation.sql +9 -0
  127. package/dist/background/status.d.ts +0 -35
  128. package/dist/background/status.js +0 -57
@@ -1,4 +1,5 @@
1
1
  import { parseToolKey, } from "@capybara-hq/plugin-sdk";
2
+ import { escalationAskReason, quotedJustification, } from "../sandbox/review/permission-candidate.js";
2
3
  import { toolInfo } from "../tools/info.js";
3
4
  import { phrase } from "./phrases.js";
4
5
  /** The longest call line of an approval card (characters, the ellipsis included). */
@@ -227,9 +228,35 @@ export function commandCardText(detail, scopes, locale, redact = (s) => s) {
227
228
  const text = write ? (detail.path ?? detail.command) : detail.command;
228
229
  const shown = cut(redact(text.trim()), CARD_SUMMARY_MAX);
229
230
  const reason = cut(redact(detail.reason.trim()), CARD_SUMMARY_MAX);
231
+ const escalation = write ? undefined : detail.escalation;
232
+ // an escalation states the crossing from its own facts, never from the reason alone (a review
233
+ // model's ask may word the reason any way); the reason follows only when it adds something
234
+ const lines = escalation
235
+ ? [
236
+ phrase("escalationLine", locale),
237
+ ...(escalation.background === true
238
+ ? [
239
+ escalation.maxSeconds !== undefined
240
+ ? phrase("escalationBackgroundLimit", locale).replace("{minutes}", String(Math.ceil(escalation.maxSeconds / 60)))
241
+ : phrase("escalationBackground", locale),
242
+ ]
243
+ : []),
244
+ ...(detail.workingRoot !== undefined
245
+ ? [phrase("escalationCwd", locale).replace("{dir}", redact(detail.workingRoot))]
246
+ : []),
247
+ phrase("escalationJustification", locale).replace("{text}", cut(redact(quotedJustification(escalation.justification)), CARD_SUMMARY_MAX)),
248
+ ...(detail.reason.trim() !== escalationAskReason(escalation) ? [reason] : []),
249
+ ]
250
+ : [reason];
230
251
  return {
231
- title: phrase(write ? "commandWriteTitle" : "commandTitle", locale),
232
- inputPreview: [reason, ...(shown !== "" ? ["", shown] : [])].join("\n"),
252
+ title: phrase(write
253
+ ? "commandWriteTitle"
254
+ : escalation?.background === true
255
+ ? "escalationBackgroundTitle"
256
+ : escalation
257
+ ? "escalationTitle"
258
+ : "commandTitle", locale),
259
+ inputPreview: [...lines, ...(shown !== "" ? ["", shown] : [])].join("\n"),
233
260
  scopeLabels: {
234
261
  ...(scopes.includes("once") ? { once: phrase("commandAllowOnce", locale) } : {}),
235
262
  ...(scopes.includes("session") ? { session: phrase("commandAllowSession", locale) } : {}),
@@ -141,6 +141,41 @@ export declare const CHANNEL_PHRASES: {
141
141
  readonly zh: "智能体想写入这个文件,允许吗?";
142
142
  readonly en: "The agent wants to write this file. Allow?";
143
143
  };
144
+ /** A per-call sandbox escalation ask's card title (approval profiles design). */
145
+ readonly escalationTitle: {
146
+ readonly zh: "智能体想在沙箱外运行这条命令,允许吗?";
147
+ readonly en: "The agent wants to run this command outside the sandbox. Allow?";
148
+ };
149
+ /** A background sandbox escalation ask's card title. */
150
+ readonly escalationBackgroundTitle: {
151
+ readonly zh: "智能体想在沙箱外后台启动这条命令,允许吗?";
152
+ readonly en: "The agent wants to start this command in the background outside the sandbox. Allow?";
153
+ };
154
+ /** An escalation card's first line: what approving allows. */
155
+ readonly escalationLine: {
156
+ readonly zh: "仅本次调用在沙箱外运行,可完整访问此设备的文件和网络。";
157
+ readonly en: "Runs outside the sandbox for this call only, with full access to this device's files and network.";
158
+ };
159
+ /** A background escalation's line (`{minutes}`: its deadline). */
160
+ readonly escalationBackgroundLimit: {
161
+ readonly zh: "启动一个后台进程,它在沙箱外持续运行,直到自行退出或被停止,最长 {minutes} 分钟。";
162
+ readonly en: "Starts a background process that keeps running outside the sandbox until it exits or is stopped, at most {minutes} minutes.";
163
+ };
164
+ /** A background escalation's line without a known deadline. */
165
+ readonly escalationBackground: {
166
+ readonly zh: "启动一个后台进程,它在沙箱外持续运行,直到自行退出或被停止。";
167
+ readonly en: "Starts a background process that keeps running outside the sandbox until it exits or is stopped.";
168
+ };
169
+ /** An escalation card's working directory line (`{dir}`). */
170
+ readonly escalationCwd: {
171
+ readonly zh: "运行目录:{dir}";
172
+ readonly en: "Runs in: {dir}";
173
+ };
174
+ /** An escalation card's justification line (`{text}`: the agent's words, quoted). */
175
+ readonly escalationJustification: {
176
+ readonly zh: "智能体给出的理由:{text}";
177
+ readonly en: "Justification (from the agent): {text}";
178
+ };
144
179
  /** A command review ask's 「once」 button. */
145
180
  readonly commandAllowOnce: {
146
181
  readonly zh: "允许一次";
@@ -115,6 +115,38 @@ export const CHANNEL_PHRASES = {
115
115
  zh: "智能体想写入这个文件,允许吗?",
116
116
  en: "The agent wants to write this file. Allow?",
117
117
  },
118
+ /** A per-call sandbox escalation ask's card title (approval profiles design). */
119
+ escalationTitle: {
120
+ zh: "智能体想在沙箱外运行这条命令,允许吗?",
121
+ en: "The agent wants to run this command outside the sandbox. Allow?",
122
+ },
123
+ /** A background sandbox escalation ask's card title. */
124
+ escalationBackgroundTitle: {
125
+ zh: "智能体想在沙箱外后台启动这条命令,允许吗?",
126
+ en: "The agent wants to start this command in the background outside the sandbox. Allow?",
127
+ },
128
+ /** An escalation card's first line: what approving allows. */
129
+ escalationLine: {
130
+ zh: "仅本次调用在沙箱外运行,可完整访问此设备的文件和网络。",
131
+ en: "Runs outside the sandbox for this call only, with full access to this device's files and network.",
132
+ },
133
+ /** A background escalation's line (`{minutes}`: its deadline). */
134
+ escalationBackgroundLimit: {
135
+ zh: "启动一个后台进程,它在沙箱外持续运行,直到自行退出或被停止,最长 {minutes} 分钟。",
136
+ en: "Starts a background process that keeps running outside the sandbox until it exits or is stopped, at most {minutes} minutes.",
137
+ },
138
+ /** A background escalation's line without a known deadline. */
139
+ escalationBackground: {
140
+ zh: "启动一个后台进程,它在沙箱外持续运行,直到自行退出或被停止。",
141
+ en: "Starts a background process that keeps running outside the sandbox until it exits or is stopped.",
142
+ },
143
+ /** An escalation card's working directory line (`{dir}`). */
144
+ escalationCwd: { zh: "运行目录:{dir}", en: "Runs in: {dir}" },
145
+ /** An escalation card's justification line (`{text}`: the agent's words, quoted). */
146
+ escalationJustification: {
147
+ zh: "智能体给出的理由:{text}",
148
+ en: "Justification (from the agent): {text}",
149
+ },
118
150
  /** A command review ask's 「once」 button. */
119
151
  commandAllowOnce: { zh: "允许一次", en: "Allow once" },
120
152
  /** A command review ask's 「session」 button: remembers the rule for the conversation. */
@@ -7,8 +7,9 @@ export declare function selectConfigSource(env: NodeJS.ProcessEnv): ConfigSource
7
7
  /** 深合并:对象递归合并,其余(含数组)由 override 整体替换。 */
8
8
  export declare function deepMerge(base: unknown, override: unknown): unknown;
9
9
  /**
10
- * The permission keys B1 replaced, each with its replacement. Until the old public inputs are
11
- * removed, {@link translateLegacyPermissionKeys} reads the old key of a source as the new one.
10
+ * The permission keys B1 replaced, each with its replacement. The old keys are no longer read:
11
+ * {@link refuseLegacyPermissionKeys} refuses them with the conversion message, and
12
+ * `capybara config migrate-permissions` (`permission-migration.ts`) converts a config file.
12
13
  */
13
14
  export declare const LEGACY_PERMISSION_KEYS: readonly [{
14
15
  readonly path: readonly ["devices", "autoMode"];
@@ -16,14 +17,6 @@ export declare const LEGACY_PERMISSION_KEYS: readonly [{
16
17
  readonly env: "CAPYBARA_DEVICES__AUTO_MODE";
17
18
  readonly replacementEnv: "CAPYBARA_DEVICES__FULL_ACCESS";
18
19
  }];
19
- /**
20
- * Translates the old permission keys of ONE config source (the file / Nacos document, or the
21
- * environment overrides) to their replacements, before the sources are merged: the old key keeps
22
- * its source's place in the precedence (env > file / Nacos), never its own. An old and a new key
23
- * in the same source must agree, else the config fails (never pick the wider one). The value is
24
- * not checked here: the schema refuses an invalid one under the new key.
25
- */
26
- export declare function translateLegacyPermissionKeys(source: Record<string, unknown>, label: "file" | "env"): Record<string, unknown>;
27
20
  /** 原始配置深合并环境变量覆盖(优先级最高)后校验;热更新与启动共用。错误只列路径不列值。 */
28
21
  export declare function resolveConfig(raw: unknown, env: NodeJS.ProcessEnv): KernelConfig;
29
22
  /** 选来源 → 深合并环境变量覆盖(优先级最高)→ 校验。 */
@@ -64,8 +64,9 @@ export function deepMerge(base, override) {
64
64
  return out;
65
65
  }
66
66
  /**
67
- * The permission keys B1 replaced, each with its replacement. Until the old public inputs are
68
- * removed, {@link translateLegacyPermissionKeys} reads the old key of a source as the new one.
67
+ * The permission keys B1 replaced, each with its replacement. The old keys are no longer read:
68
+ * {@link refuseLegacyPermissionKeys} refuses them with the conversion message, and
69
+ * `capybara config migrate-permissions` (`permission-migration.ts`) converts a config file.
69
70
  */
70
71
  export const LEGACY_PERMISSION_KEYS = [
71
72
  {
@@ -76,36 +77,40 @@ export const LEGACY_PERMISSION_KEYS = [
76
77
  },
77
78
  ];
78
79
  /**
79
- * Translates the old permission keys of ONE config source (the file / Nacos document, or the
80
- * environment overrides) to their replacements, before the sources are merged: the old key keeps
81
- * its source's place in the precedence (env > file / Nacos), never its own. An old and a new key
82
- * in the same source must agree, else the config fails (never pick the wider one). The value is
83
- * not checked here: the schema refuses an invalid one under the new key.
80
+ * The conversion message of every old permission key in ONE config source (the file / Nacos
81
+ * document, or the environment overrides), empty when it names none. The old key is refused even
82
+ * when it agrees with its replacement, so a source is converted once, never read under two names.
83
+ * The value is never echoed.
84
84
  */
85
- export function translateLegacyPermissionKeys(source, label) {
86
- let out = source;
85
+ function legacyPermissionKeyProblems(source, label) {
86
+ const problems = [];
87
87
  for (const key of LEGACY_PERMISSION_KEYS) {
88
88
  const [section, old] = key.path;
89
- const [, next] = key.replacement;
90
- const parent = out[section];
89
+ const parent = source[section];
91
90
  if (!isPlainObject(parent) || !(old in parent))
92
91
  continue;
93
- const { [old]: value, ...rest } = parent;
94
- if (next in rest && rest[next] !== value) {
95
- const [a, b] = label === "env"
96
- ? [key.env, key.replacementEnv]
97
- : [key.path.join("."), key.replacement.join(".")];
98
- throw new ConfigError(`invalid configuration:\n - ${a} and ${b} are both set and differ; remove ${a} (it is replaced by ${b})`);
99
- }
100
- out = { ...out, [section]: { ...rest, [next]: rest[next] ?? value } };
92
+ problems.push(label === "env"
93
+ ? ` - ${key.env} is no longer read: set ${key.replacementEnv} instead (the same values, allowed or off)`
94
+ : ` - ${key.path.join(".")} is no longer read: rename it to ${key.replacement.join(".")} (the same values, allowed or off); capybara config migrate-permissions --in <file> --out <file> converts a config file or Nacos document`);
101
95
  }
102
- return out;
96
+ return problems;
97
+ }
98
+ /** Refuses the old permission keys of the file / Nacos document and the environment. */
99
+ function refuseLegacyPermissionKeys(raw, env) {
100
+ const problems = [
101
+ ...legacyPermissionKeyProblems(raw, "file"),
102
+ ...legacyPermissionKeyProblems(env, "env"),
103
+ ];
104
+ if (problems.length > 0)
105
+ throw new ConfigError(`invalid configuration:\n${problems.join("\n")}`);
103
106
  }
104
107
  /** 原始配置深合并环境变量覆盖(优先级最高)后校验;热更新与启动共用。错误只列路径不列值。 */
105
108
  export function resolveConfig(raw, env) {
106
109
  if (!isPlainObject(raw))
107
110
  throw new ConfigError("config file root must be a mapping");
108
- const merged = deepMerge(translateLegacyPermissionKeys(raw, "file"), translateLegacyPermissionKeys(envOverrides(env), "env"));
111
+ const overrides = envOverrides(env);
112
+ refuseLegacyPermissionKeys(raw, overrides);
113
+ const merged = deepMerge(raw, overrides);
109
114
  const result = KernelConfigSchema.safeParse(merged);
110
115
  if (!result.success) {
111
116
  // The schema is strict: an unknown key (a typo, or a removed setting) is an error that names
@@ -1558,15 +1558,15 @@ export const KernelConfigSchema = z.strictObject({
1558
1558
  * in the admin console (`devicesFullAccess`); the startup config wins over it, so this field
1559
1559
  * is optional with no schema default (the default `allowed` is applied by
1560
1560
  * `readDevicesFullAccess`: a schema default would be indistinguishable from a value the config
1561
- * source set). The old key `devices.autoMode` (`CAPYBARA_DEVICES__AUTO_MODE`) is translated
1562
- * per source by `translateLegacyPermissionKeys` until it is removed.
1561
+ * source set). The old key `devices.autoMode` (`CAPYBARA_DEVICES__AUTO_MODE`) is refused with
1562
+ * the conversion message (`config/load.ts`).
1563
1563
  */
1564
1564
  fullAccess: z
1565
1565
  .enum(["allowed", "off"])
1566
1566
  .optional()
1567
1567
  .meta(meta({
1568
1568
  hot: true,
1569
- description: "Whether devices may run with Full permission (default allowed): a device whose owner allows Full may then run a conversation with Full permission; a cloud device on Full reaches the open public network (private and internal addresses blocked) unless sandbox.limits.egress is none. When off, devices run restricted: local devices on their allowlist, cloud devices on their organization's cloud network (cloudNetwork). An organization may turn it off and follow the platform. Set here, it is read-only in the admin console. Replaces devices.autoMode (CAPYBARA_DEVICES__AUTO_MODE), which is still read with the same values; capybara config migrate-permissions converts a config file",
1569
+ description: "Whether devices may run with Full permission (default allowed): a device whose owner allows Full may then run a conversation with Full permission; a cloud device on Full reaches the open public network (private and internal addresses blocked) unless sandbox.limits.egress is none. When off, devices run restricted: local devices on their allowlist, cloud devices on their organization's cloud network (cloudNetwork). An organization may turn it off and follow the platform. Set here, it is read-only in the admin console. Replaces devices.autoMode (CAPYBARA_DEVICES__AUTO_MODE), which is refused: rename it (the same values), or convert a config file with capybara config migrate-permissions",
1570
1570
  })),
1571
1571
  maxPersonal: z
1572
1572
  .number()
@@ -2,6 +2,13 @@ import { type ContentBlock, type MediaSource, type PermissionProfile } from "@ca
2
2
  import { z } from "zod";
3
3
  /** Code-point ordering is independent of the host locale and UTF-16 surrogate ordering. */
4
4
  export declare function permissionCodePointCompare(a: string, b: string): number;
5
+ /**
6
+ * The fixed reasons of an `actor-device-access` context: the actor cannot use the selected device
7
+ * at all, or the run's account is not the conversation's owner (a group-chat sender, a wake for
8
+ * another member), whose device is never used by another account.
9
+ */
10
+ export declare const ACTOR_DEVICE_ACCESS_REASON = "This run's actor cannot use the selected device";
11
+ export declare const ACTOR_NOT_DEVICE_OWNER_REASON = "The selected device belongs to the conversation's owner, and this run's account is not its owner, so this run continues without the device";
5
12
  /** Complete recorded facts, never a grant or a requested-but-unverified scope. */
6
13
  export declare const PermissionContextV1Schema: z.ZodObject<{
7
14
  version: z.ZodLiteral<1>;
@@ -139,6 +146,16 @@ export declare const PermissionCallBindingSchema: z.ZodObject<{
139
146
  scopeRevision: z.ZodString;
140
147
  authorityRevision: z.ZodString;
141
148
  }, z.core.$strict>;
149
+ /**
150
+ * A per-call sandbox escalation's justification, as the person and the review model saw it (at
151
+ * most 500 code points, as the tool schema counts), and for a background start that it keeps
152
+ * running outside the sandbox for at most `maxSeconds`.
153
+ */
154
+ export declare const PermissionEscalationSchema: z.ZodObject<{
155
+ justification: z.ZodString;
156
+ background: z.ZodOptional<z.ZodLiteral<true>>;
157
+ maxSeconds: z.ZodOptional<z.ZodNumber>;
158
+ }, z.core.$strict>;
142
159
  export declare const ReviewRecordSchema: z.ZodObject<{
143
160
  profile: z.ZodOptional<z.ZodEnum<{
144
161
  "approve-for-me": "approve-for-me";
@@ -170,6 +187,7 @@ export declare const ReviewRecordSchema: z.ZodObject<{
170
187
  session: "session";
171
188
  }>>;
172
189
  commandHash: z.ZodOptional<z.ZodString>;
190
+ sandbox: z.ZodOptional<z.ZodLiteral<"escalated">>;
173
191
  }, z.core.$strict>;
174
192
  /** The display-only `approval_requested.command` facts of a `command` ask (auto mode spec §5.4). */
175
193
  export declare const CommandAskSchema: z.ZodObject<{
@@ -180,6 +198,12 @@ export declare const CommandAskSchema: z.ZodObject<{
180
198
  }, z.core.$strict>>;
181
199
  targetPath: z.ZodOptional<z.ZodString>;
182
200
  candidateHash: z.ZodOptional<z.ZodString>;
201
+ escalation: z.ZodOptional<z.ZodObject<{
202
+ justification: z.ZodString;
203
+ background: z.ZodOptional<z.ZodLiteral<true>>;
204
+ maxSeconds: z.ZodOptional<z.ZodNumber>;
205
+ }, z.core.$strict>>;
206
+ workingRoot: z.ZodOptional<z.ZodString>;
183
207
  kind: z.ZodEnum<{
184
208
  command: "command";
185
209
  write: "write";
@@ -523,7 +547,15 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
523
547
  hosts: z.ZodArray<z.ZodString>;
524
548
  }, z.core.$strict>;
525
549
  targetPath: z.ZodOptional<z.ZodString>;
526
- scopeKind: z.ZodLiteral<"directories-and-hosts">;
550
+ scopeKind: z.ZodEnum<{
551
+ "directories-and-hosts": "directories-and-hosts";
552
+ "sandbox-escalation": "sandbox-escalation";
553
+ }>;
554
+ escalation: z.ZodOptional<z.ZodObject<{
555
+ justification: z.ZodString;
556
+ background: z.ZodOptional<z.ZodLiteral<true>>;
557
+ maxSeconds: z.ZodOptional<z.ZodNumber>;
558
+ }, z.core.$strict>>;
527
559
  candidateHash: z.ZodString;
528
560
  outcome: z.ZodEnum<{
529
561
  allow: "allow";
@@ -531,7 +563,10 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
531
563
  deny: "deny";
532
564
  }>;
533
565
  reason: z.ZodString;
534
- decisionSource: z.ZodLiteral<"review-model">;
566
+ decisionSource: z.ZodEnum<{
567
+ "review-model": "review-model";
568
+ rule: "rule";
569
+ }>;
535
570
  }, z.core.$strip>;
536
571
  }, z.core.$strip>, z.ZodObject<{
537
572
  type: z.ZodLiteral<"permission_profile_changed">;
@@ -1050,6 +1085,7 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
1050
1085
  permissionInput: z.ZodOptional<z.ZodObject<{
1051
1086
  callInputHash: z.ZodString;
1052
1087
  resolvedInputHash: z.ZodString;
1088
+ sandbox: z.ZodOptional<z.ZodLiteral<"escalated">>;
1053
1089
  }, z.core.$strip>>;
1054
1090
  }, z.core.$strip>;
1055
1091
  }, z.core.$strip>, z.ZodObject<{
@@ -1093,6 +1129,7 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
1093
1129
  session: "session";
1094
1130
  }>>;
1095
1131
  commandHash: z.ZodOptional<z.ZodString>;
1132
+ sandbox: z.ZodOptional<z.ZodLiteral<"escalated">>;
1096
1133
  }, z.core.$strict>>;
1097
1134
  loadedTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
1098
1135
  display: z.ZodOptional<z.ZodObject<{
@@ -1202,6 +1239,12 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
1202
1239
  }, z.core.$strict>>;
1203
1240
  targetPath: z.ZodOptional<z.ZodString>;
1204
1241
  candidateHash: z.ZodOptional<z.ZodString>;
1242
+ escalation: z.ZodOptional<z.ZodObject<{
1243
+ justification: z.ZodString;
1244
+ background: z.ZodOptional<z.ZodLiteral<true>>;
1245
+ maxSeconds: z.ZodOptional<z.ZodNumber>;
1246
+ }, z.core.$strict>>;
1247
+ workingRoot: z.ZodOptional<z.ZodString>;
1205
1248
  kind: z.ZodEnum<{
1206
1249
  command: "command";
1207
1250
  write: "write";
@@ -37,6 +37,17 @@ const PermissionDirectories = z
37
37
  .min(1)
38
38
  .max(64)
39
39
  .refine((values) => values.every((value, i) => i === 0 || permissionCodePointCompare(values[i - 1], value) < 0), "Directories must be unique and sorted by Unicode code point");
40
+ /**
41
+ * The fixed reasons of an `actor-device-access` context: the actor cannot use the selected device
42
+ * at all, or the run's account is not the conversation's owner (a group-chat sender, a wake for
43
+ * another member), whose device is never used by another account.
44
+ */
45
+ export const ACTOR_DEVICE_ACCESS_REASON = "This run's actor cannot use the selected device";
46
+ export const ACTOR_NOT_DEVICE_OWNER_REASON = "The selected device belongs to the conversation's owner, and this run's account is not its owner, so this run continues without the device";
47
+ const ACTOR_DEVICE_ACCESS_REASONS = [
48
+ ACTOR_DEVICE_ACCESS_REASON,
49
+ ACTOR_NOT_DEVICE_OWNER_REASON,
50
+ ];
40
51
  const PermissionRevision = z.string().min(1).max(256);
41
52
  const PermissionReason = z
42
53
  .string()
@@ -112,7 +123,7 @@ export const PermissionContextV1Schema = z
112
123
  if (p.availability.cause === "actor-device-access") {
113
124
  if (p.selectedProfile !== null || p.profileRevision !== null)
114
125
  reject("Device access refusal must redact the owner's profile");
115
- if (p.availability.reason !== "This run's actor cannot use the selected device")
126
+ if (!ACTOR_DEVICE_ACCESS_REASONS.includes(p.availability.reason))
116
127
  reject("Invalid device access reason");
117
128
  }
118
129
  else if (p.availability.reason !== "Choose a device to run device operations")
@@ -263,6 +274,21 @@ export const PermissionCallBindingSchema = z
263
274
  authorityRevision: z.string(),
264
275
  })
265
276
  .strict();
277
+ /**
278
+ * A per-call sandbox escalation's justification, as the person and the review model saw it (at
279
+ * most 500 code points, as the tool schema counts), and for a background start that it keeps
280
+ * running outside the sandbox for at most `maxSeconds`.
281
+ */
282
+ export const PermissionEscalationSchema = z
283
+ .object({
284
+ justification: z
285
+ .string()
286
+ .min(1)
287
+ .refine((s) => [...s].length <= 500, "justification must be at most 500 characters"),
288
+ background: z.literal(true).optional(),
289
+ maxSeconds: z.number().int().positive().optional(),
290
+ })
291
+ .strict();
266
292
  export const ReviewRecordSchema = z
267
293
  .object({
268
294
  profile: z.enum(["request-approval", "approve-for-me", "full-access"]).optional(),
@@ -280,6 +306,8 @@ export const ReviewRecordSchema = z
280
306
  .string()
281
307
  .regex(/^[a-f0-9]{64}$/)
282
308
  .optional(),
309
+ /** The call was allowed to run outside the OS sandbox (a per-call escalation). */
310
+ sandbox: z.literal("escalated").optional(),
283
311
  })
284
312
  .strict();
285
313
  /** The display-only `approval_requested.command` facts of a `command` ask (auto mode spec §5.4). */
@@ -288,6 +316,10 @@ export const CommandAskSchema = z
288
316
  permissionScope: PermissionExpansionSchema.optional(),
289
317
  targetPath: z.string().max(4096).optional(),
290
318
  candidateHash: z.string().optional(),
319
+ /** The command asks to run outside the OS sandbox for this call (its justification). */
320
+ escalation: PermissionEscalationSchema.optional(),
321
+ /** The directory the command runs in (an escalation shows it). */
322
+ workingRoot: z.string().max(4096).optional(),
291
323
  /** A shell command or a file write. */
292
324
  kind: z.enum(["command", "write"]),
293
325
  /** The command text, or the tool key of the write. */
@@ -557,11 +589,14 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
557
589
  binding: PermissionCallBindingSchema,
558
590
  permissionScope: PermissionExpansionSchema,
559
591
  targetPath: z.string().max(4096).optional(),
560
- scopeKind: z.literal("directories-and-hosts"),
592
+ scopeKind: z.enum(["directories-and-hosts", "sandbox-escalation"]),
593
+ /** A per-call sandbox escalation: the model's justification (its scope is empty). */
594
+ escalation: PermissionEscalationSchema.optional(),
561
595
  candidateHash: z.string(),
562
596
  outcome: z.enum(["allow", "ask", "deny"]),
563
597
  reason: z.string(),
564
- decisionSource: z.literal("review-model"),
598
+ /** Who decided: the review model, or the fixed rules (a deny, an ask, the fail-closed ask). */
599
+ decisionSource: z.enum(["review-model", "rule"]),
565
600
  })),
566
601
  ev("permission_profile_changed", z.object({
567
602
  oldProfile: z.enum(["request-approval", "approve-for-me", "full-access"]),
@@ -997,7 +1032,12 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
997
1032
  toolKey: z.string(),
998
1033
  specHash: z.string(),
999
1034
  permissionInput: z
1000
- .object({ callInputHash: z.string(), resolvedInputHash: z.string() })
1035
+ .object({
1036
+ callInputHash: z.string(),
1037
+ resolvedInputHash: z.string(),
1038
+ /** The call asked to run outside the sandbox: admission runs it escalated or refuses. */
1039
+ sandbox: z.literal("escalated").optional(),
1040
+ })
1001
1041
  .optional(),
1002
1042
  })),
1003
1043
  /**
@@ -4,7 +4,7 @@ import type { ModelRef } from "../agents/definition.js";
4
4
  import type { DeviceNetwork } from "../sandbox/modes.js";
5
5
  import type { StartingExecutionGrants } from "../sandbox/operation-authority-types.js";
6
6
  import type { AuthorityEpochVector } from "../sandbox/permission-authority-epochs.js";
7
- import type { PermissionExpansion } from "../sandbox/permission-call-types.js";
7
+ import type { PermissionEscalation, PermissionExpansion, PermissionScopeKind } from "../sandbox/permission-call-types.js";
8
8
  import type { PermissionConfigProjection } from "../sandbox/permission-config-publication.js";
9
9
  import type { PermissionRuntimeIdentity } from "../sandbox/permission-runtime-reports.js";
10
10
  import type { ScheduleChat, ScheduleMarker, ScheduleMode, SchedulePauseReason, ScheduleStatus, ScheduleTrigger, TaskRunSkipReason, TaskRunStatus } from "../schedules/types.js";
@@ -36,7 +36,9 @@ export interface PermissionCallGrantsTable {
36
36
  expansion_hash: string;
37
37
  candidate_hash: string;
38
38
  target_path: string | null;
39
- scope_kind: "directories-and-hosts";
39
+ scope_kind: PermissionScopeKind;
40
+ /** A per-call sandbox escalation's justification (`scope_kind = 'sandbox-escalation'` only). */
41
+ escalation: ColumnType<PermissionEscalation | null, string | null | undefined, string | null>;
40
42
  source: "human" | "review-model";
41
43
  approval_id: string | null;
42
44
  review_event_seq: number | null;
@@ -944,8 +946,11 @@ export interface BackgroundTasksTable {
944
946
  trigger_account_id: string;
945
947
  description: string;
946
948
  command: string;
947
- /** NULL while the launch is reserved but not started (0071). */
948
- sid: string | null;
949
+ /**
950
+ * A legacy row's session id (0071); NULL on every managed row. Never written after insert: no
951
+ * launch records a SID any more (permission activation W5-P2), so updates are refused by type.
952
+ */
953
+ sid: ColumnType<string | null, string | null | undefined, never>;
949
954
  output_path: string;
950
955
  status: ColumnType<"running" | "completed" | "failed" | "stopped" | "timed_out" | "lost", string | undefined, string>;
951
956
  lost_reason: ColumnType<string | null, string | null | undefined, string | null>;
@@ -271,7 +271,7 @@ let DevicesService = class DevicesService {
271
271
  // A cloud device's owner narrows it to sandbox or clears the choice to follow the org (auto
272
272
  // mode spec §4.3, hardening D2); a local device's mode lives on its machine.
273
273
  if (before.source !== "cloud") {
274
- throw new ApiError("device.mode_on_device", "This device's mode is kept on its connected machine: switch to sandbox mode from the device page (sent to the machine) or run capybara-device mode sandbox there.");
274
+ throw new ApiError("device.mode_on_device", "This device's owner ceiling is kept on its connected computer: narrow it from the device page, or run capybara-device ceiling set --full-access deny --project-reach workspace on that computer.");
275
275
  }
276
276
  if ((before.mode ?? null) !== patch.mode) {
277
277
  // `from` / `to` are the modes it runs at: the org may cap both at sandbox, and then the
@@ -1,6 +1,11 @@
1
1
  import { ApiError } from "../errors.js";
2
2
  /** The device is missing, deleted, or not in the caller's org (404; ids cannot be probed). */
3
3
  export declare const deviceNotFound: () => ApiError;
4
+ /**
5
+ * The device's machine was disconnected (revoked, signed out): 403 `device.forbidden`
6
+ * with `details: [{ reason: "machine_revoked" }]`, so the tools tell the model what to ask for.
7
+ */
8
+ export declare const machineRevoked: () => ApiError;
4
9
  /**
5
10
  * The device offers no projects (project root §4.1): a local machine whose `capybara-device`
6
11
  * does not announce `projects`, or a cloud provider without `list` / `scan`.
@@ -1,6 +1,11 @@
1
1
  import { ApiError } from "../errors.js";
2
2
  /** The device is missing, deleted, or not in the caller's org (404; ids cannot be probed). */
3
3
  export const deviceNotFound = () => new ApiError("device.not_found", "This device does not exist or was deleted.");
4
+ /**
5
+ * The device's machine was disconnected (revoked, signed out): 403 `device.forbidden`
6
+ * with `details: [{ reason: "machine_revoked" }]`, so the tools tell the model what to ask for.
7
+ */
8
+ export const machineRevoked = () => new ApiError("device.forbidden", "The machine of this local device was disconnected. Run capybara-device logout, then capybara-device login on it, or pick another device.", [{ reason: "machine_revoked" }]);
4
9
  /**
5
10
  * The device offers no projects (project root §4.1): a local machine whose `capybara-device`
6
11
  * does not announce `projects`, or a cloud provider without `list` / `scan`.
@@ -15,8 +15,8 @@ export interface DeviceProjectScope {
15
15
  home: string | null;
16
16
  supported: boolean;
17
17
  /**
18
- * A machine whose own policy is auto mode while the organization allows only sandbox mode: exec
19
- * refuses it (`device.auto_mode_not_allowed`), and the kernel reads nothing on it unasked.
18
+ * A machine without an authenticated owner report whose own policy is auto mode while the
19
+ * organization allows only sandbox mode: the kernel reads nothing on it unasked.
20
20
  */
21
21
  widerThanAllowed: boolean;
22
22
  }
package/dist/errors.d.ts CHANGED
@@ -35,8 +35,11 @@ export declare const ERROR_CODES: {
35
35
  readonly "org.last_owner": 409;
36
36
  readonly "org.owner_required": 403;
37
37
  readonly "org.sandbox_egress_not_allowed": 400;
38
- /** The org asked for auto mode where the platform turned it off, or widened it through a token. */
39
- readonly "org.auto_mode_not_allowed": 400;
38
+ /**
39
+ * The org asked for Full permission (`fullAccess: allowed`) where the platform turned it off, or
40
+ * widened it through an API token or the Platform tool.
41
+ */
42
+ readonly "org.full_access_not_allowed": 400;
40
43
  /** An org network allowance entry that is malformed, names a link-local address, or is over the cap. */
41
44
  readonly "org.network_allowance_invalid": 400;
42
45
  readonly "org.network_allowance_not_found": 404;
@@ -49,8 +52,8 @@ export declare const ERROR_CODES: {
49
52
  readonly "org.external_sharing_not_allowed": 400;
50
53
  /** A deployment setting set in the startup config (file, Nacos or env): read-only in the admin console. */
51
54
  readonly "deployment.setting_readonly": 409;
52
- /** Turning the platform's auto mode on through an API token or the Platform tool (only off). */
53
- readonly "deployment.auto_mode_not_allowed": 400;
55
+ /** Allowing the platform's Full permission through an API token or the Platform tool (only off). */
56
+ readonly "deployment.full_access_not_allowed": 400;
54
57
  /** Allowing external sharing at the platform level through an API token or the Platform tool. */
55
58
  readonly "deployment.external_sharing_not_allowed": 400;
56
59
  /**
@@ -405,12 +408,6 @@ export declare const ERROR_CODES: {
405
408
  readonly "device.policy_refused": 409;
406
409
  /** The device cannot change its network policy from the platform (cloud, or an older program). */
407
410
  readonly "device.policy_unsupported": 409;
408
- /**
409
- * The device's machine reports auto mode while the organization (or the platform) allows only
410
- * sandbox mode (auto mode spec §4.3); checked at each command. The message names
411
- * `capybara-device mode sandbox`.
412
- */
413
- readonly "device.auto_mode_not_allowed": 403;
414
411
  /**
415
412
  * B1: a cloud device's snapshot found applied limits it could not establish exactly; no operation
416
413
  * is admitted until a lifecycle action (a file reset) establishes them.
@@ -432,7 +429,8 @@ export declare const ERROR_CODES: {
432
429
  readonly "device.full_access_not_allowed": 409;
433
430
  /**
434
431
  * A device's mode is not a stored setting: a local device's mode lives on its machine
435
- * (`capybara-device mode` or the device page's policy op), and a cloud device has none to choose.
432
+ * (`capybara-device ceiling set` or the device page's policy op), and a cloud device has none to
433
+ * choose.
436
434
  */
437
435
  readonly "device.mode_on_device": 409;
438
436
  /**
package/dist/errors.js CHANGED
@@ -35,8 +35,11 @@ export const ERROR_CODES = {
35
35
  "org.last_owner": 409,
36
36
  "org.owner_required": 403,
37
37
  "org.sandbox_egress_not_allowed": 400,
38
- /** The org asked for auto mode where the platform turned it off, or widened it through a token. */
39
- "org.auto_mode_not_allowed": 400,
38
+ /**
39
+ * The org asked for Full permission (`fullAccess: allowed`) where the platform turned it off, or
40
+ * widened it through an API token or the Platform tool.
41
+ */
42
+ "org.full_access_not_allowed": 400,
40
43
  /** An org network allowance entry that is malformed, names a link-local address, or is over the cap. */
41
44
  "org.network_allowance_invalid": 400,
42
45
  "org.network_allowance_not_found": 404,
@@ -49,8 +52,8 @@ export const ERROR_CODES = {
49
52
  "org.external_sharing_not_allowed": 400,
50
53
  /** A deployment setting set in the startup config (file, Nacos or env): read-only in the admin console. */
51
54
  "deployment.setting_readonly": 409,
52
- /** Turning the platform's auto mode on through an API token or the Platform tool (only off). */
53
- "deployment.auto_mode_not_allowed": 400,
55
+ /** Allowing the platform's Full permission through an API token or the Platform tool (only off). */
56
+ "deployment.full_access_not_allowed": 400,
54
57
  /** Allowing external sharing at the platform level through an API token or the Platform tool. */
55
58
  "deployment.external_sharing_not_allowed": 400,
56
59
  /**
@@ -405,12 +408,6 @@ export const ERROR_CODES = {
405
408
  "device.policy_refused": 409,
406
409
  /** The device cannot change its network policy from the platform (cloud, or an older program). */
407
410
  "device.policy_unsupported": 409,
408
- /**
409
- * The device's machine reports auto mode while the organization (or the platform) allows only
410
- * sandbox mode (auto mode spec §4.3); checked at each command. The message names
411
- * `capybara-device mode sandbox`.
412
- */
413
- "device.auto_mode_not_allowed": 403,
414
411
  /**
415
412
  * B1: a cloud device's snapshot found applied limits it could not establish exactly; no operation
416
413
  * is admitted until a lifecycle action (a file reset) establishes them.
@@ -432,7 +429,8 @@ export const ERROR_CODES = {
432
429
  "device.full_access_not_allowed": 409,
433
430
  /**
434
431
  * A device's mode is not a stored setting: a local device's mode lives on its machine
435
- * (`capybara-device mode` or the device page's policy op), and a cloud device has none to choose.
432
+ * (`capybara-device ceiling set` or the device page's policy op), and a cloud device has none to
433
+ * choose.
436
434
  */
437
435
  "device.mode_on_device": 409,
438
436
  /**