@capybara-hq/device 0.1.0-rc.14 → 0.1.0-rc.16

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 (109) hide show
  1. package/README.md +101 -157
  2. package/dist/api.d.ts +2 -2
  3. package/dist/args.d.ts +2 -8
  4. package/dist/args.js +2 -25
  5. package/dist/cli.d.ts +2 -11
  6. package/dist/cli.js +6 -61
  7. package/dist/client.d.ts +8 -45
  8. package/dist/client.js +25 -424
  9. package/dist/command-log.d.ts +14 -4
  10. package/dist/command-log.js +37 -1
  11. package/dist/commands/ceiling.d.ts +0 -2
  12. package/dist/commands/ceiling.js +3 -4
  13. package/dist/commands/login.d.ts +25 -1
  14. package/dist/commands/login.js +75 -61
  15. package/dist/commands/policy.d.ts +6 -8
  16. package/dist/commands/policy.js +30 -49
  17. package/dist/commands/start.d.ts +2 -17
  18. package/dist/commands/start.js +13 -53
  19. package/dist/exec/docker-operations.d.ts +2 -2
  20. package/dist/exec/docker-operations.js +4 -2
  21. package/dist/exec/docker.d.ts +37 -122
  22. package/dist/exec/docker.js +72 -717
  23. package/dist/exec/instance-binding.d.ts +4 -4
  24. package/dist/exec/linux-agent.js +30 -0
  25. package/dist/exec/linux-operation-backend.d.ts +5 -0
  26. package/dist/exec/linux-operation-backend.js +3 -1
  27. package/dist/exec/linux-operation-worker.d.ts +9 -0
  28. package/dist/exec/linux-operation-worker.js +11 -2
  29. package/dist/exec/mac-read-policy.d.ts +58 -0
  30. package/dist/exec/mac-read-policy.js +104 -0
  31. package/dist/exec/mac-self-check.d.ts +6 -3
  32. package/dist/exec/mac-self-check.js +28 -5
  33. package/dist/exec/operation-worker.d.ts +21 -2
  34. package/dist/exec/operation-worker.js +164 -43
  35. package/dist/exec/sandbox-check.d.ts +10 -0
  36. package/dist/exec/sandbox-check.js +18 -0
  37. package/dist/exec/sandbox-messages.d.ts +3 -11
  38. package/dist/exec/sandbox-messages.js +3 -18
  39. package/dist/exec/shared.d.ts +24 -47
  40. package/dist/exec/shared.js +53 -165
  41. package/dist/exec/types.d.ts +2 -66
  42. package/dist/exec/types.js +1 -1
  43. package/dist/node_modules/@anthropic-ai/sandbox-runtime/CAPYBARA-MODIFICATIONS.patch +71 -12
  44. package/dist/node_modules/@anthropic-ai/sandbox-runtime/dist/sandbox/macos-sandbox-utils.js +18 -4
  45. package/dist/node_modules/@anthropic-ai/sandbox-runtime/dist/sandbox/sandbox-config.js +6 -0
  46. package/dist/node_modules/@anthropic-ai/sandbox-runtime/dist/sandbox/sandbox-manager.js +4 -0
  47. package/dist/node_modules/@capybara-hq/plugin-sdk/agent-docs/concepts.md +9 -4
  48. package/dist/node_modules/@capybara-hq/plugin-sdk/agent-docs/extension-points/channel.md +1 -1
  49. package/dist/node_modules/@capybara-hq/plugin-sdk/agent-docs/extension-points/file-preview.md +2 -0
  50. package/dist/node_modules/@capybara-hq/plugin-sdk/agent-docs/extension-points/sandbox.md +1 -1
  51. package/dist/node_modules/@capybara-hq/plugin-sdk/agent-docs/plugin-format.md +1 -1
  52. package/dist/node_modules/@capybara-hq/plugin-sdk/dist/cards.d.ts +11 -0
  53. package/dist/node_modules/@capybara-hq/plugin-sdk/dist/cards.js +1 -1
  54. package/dist/node_modules/@capybara-hq/plugin-sdk/dist/channel.d.ts +37 -0
  55. package/dist/node_modules/@capybara-hq/plugin-sdk/dist/ctx.d.ts +47 -3
  56. package/dist/node_modules/@capybara-hq/plugin-sdk/dist/device-denied-paths.d.ts +14 -0
  57. package/dist/node_modules/@capybara-hq/plugin-sdk/dist/device-denied-paths.js +41 -0
  58. package/dist/node_modules/@capybara-hq/plugin-sdk/dist/device-protocol.d.ts +140 -20
  59. package/dist/node_modules/@capybara-hq/plugin-sdk/dist/device-protocol.js +419 -14
  60. package/dist/node_modules/@capybara-hq/plugin-sdk/dist/file-preview.d.ts +22 -5
  61. package/dist/node_modules/@capybara-hq/plugin-sdk/dist/hooks.d.ts +77 -13
  62. package/dist/node_modules/@capybara-hq/plugin-sdk/dist/http-access.d.ts +10 -0
  63. package/dist/node_modules/@capybara-hq/plugin-sdk/dist/index.d.ts +2 -2
  64. package/dist/node_modules/@capybara-hq/plugin-sdk/dist/index.js +2 -3
  65. package/dist/node_modules/@capybara-hq/plugin-sdk/dist/model.d.ts +89 -5
  66. package/dist/node_modules/@capybara-hq/plugin-sdk/dist/model.js +103 -0
  67. package/dist/node_modules/@capybara-hq/plugin-sdk/dist/permissions.d.ts +3 -2
  68. package/dist/node_modules/@capybara-hq/plugin-sdk/dist/permissions.js +2 -2
  69. package/dist/node_modules/@capybara-hq/plugin-sdk/dist/sandbox-operation.d.ts +4 -0
  70. package/dist/node_modules/@capybara-hq/plugin-sdk/dist/ui-parts.d.ts +1 -1
  71. package/dist/node_modules/@capybara-hq/plugin-sdk/dist/ui-parts.js +11 -0
  72. package/dist/node_modules/@capybara-hq/plugin-sdk/dist/ui.d.ts +25 -6
  73. package/dist/node_modules/@capybara-hq/plugin-sdk/package.json +1 -1
  74. package/dist/owner-report.d.ts +2 -2
  75. package/dist/owner-report.js +2 -2
  76. package/dist/policy-store.d.ts +6 -10
  77. package/dist/policy-store.js +9 -23
  78. package/dist/policy.d.ts +3 -32
  79. package/dist/policy.js +4 -74
  80. package/dist/runtime-manifest.json +1 -1
  81. package/dist/server-ops.d.ts +18 -46
  82. package/dist/server-ops.js +134 -269
  83. package/dist/staged-connect.js +44 -7
  84. package/dist/staged-device.d.ts +4 -4
  85. package/dist/staged-device.js +3 -0
  86. package/dist/staged-session.d.ts +5 -5
  87. package/dist/staged-session.js +4 -4
  88. package/dist/state.js +3 -2
  89. package/package.json +2 -2
  90. package/dist/commands/mode.d.ts +0 -69
  91. package/dist/commands/mode.js +0 -133
  92. package/dist/exec/fs-helper.d.ts +0 -21
  93. package/dist/exec/fs-helper.js +0 -171
  94. package/dist/exec/host.d.ts +0 -61
  95. package/dist/exec/host.js +0 -203
  96. package/dist/exec/listing.d.ts +0 -35
  97. package/dist/exec/listing.js +0 -157
  98. package/dist/exec/os.d.ts +0 -162
  99. package/dist/exec/os.js +0 -616
  100. package/dist/exec/procs.d.ts +0 -11
  101. package/dist/exec/procs.js +0 -67
  102. package/dist/exec/reap.d.ts +0 -41
  103. package/dist/exec/reap.js +0 -89
  104. package/dist/exec/switch.d.ts +0 -107
  105. package/dist/exec/switch.js +0 -204
  106. package/dist/network.d.ts +0 -45
  107. package/dist/network.js +0 -154
  108. package/dist/node_modules/@capybara-hq/plugin-sdk/dist/device-protocol-v3.d.ts +0 -117
  109. package/dist/node_modules/@capybara-hq/plugin-sdk/dist/device-protocol-v3.js +0 -409
@@ -1,6 +1,30 @@
1
1
  import { type FetchFn } from "../api.js";
2
2
  import type { Command } from "../args.js";
3
- import { type SandboxCheck } from "./mode.js";
3
+ /**
4
+ * Shown once at login when the owner ceiling allows Full access in an organization that allows
5
+ * it: the trust model of Full access is command review, not the OS sandbox.
6
+ */
7
+ export declare const FULL_ACCESS_RISK_TEXT: string;
8
+ /** The OS sandbox check `login` uses (default: the runtime's, loaded on demand). */
9
+ export type SandboxCheck = () => {
10
+ ok: true;
11
+ } | {
12
+ ok: false;
13
+ reason: string;
14
+ };
15
+ /** How the owner widens the ceiling, on this machine only (the deployment may only narrow it). */
16
+ export declare const WIDEN_CEILING_HINT: string;
17
+ /**
18
+ * The line `login` prints for a restricted owner ceiling (the default of a new setup, B-14): no
19
+ * Full access, restricted work in the device's workspace only.
20
+ */
21
+ export declare const RESTRICTED_CEILING_LOGIN_LINE: string;
22
+ /** The line `login` prints when the owner ceiling allows Full access. */
23
+ export declare const FULL_CEILING_LOGIN_LINE: string;
24
+ /** Added when the organization does not allow Full access while the owner ceiling does. */
25
+ export declare const FULL_ACCESS_NOT_ALLOWED_LOGIN_LINE = "This organization does not allow Full access, so agents use the restricted profiles here.";
26
+ /** The line `login` prints when restricted work cannot run here (no OS sandbox). */
27
+ export declare function restrictedUnavailableLoginLine(reason: string): string;
4
28
  export interface LoginDeps {
5
29
  stateDir: string;
6
30
  home: string;
@@ -3,11 +3,47 @@ import { existsSync } from "node:fs";
3
3
  import { hostname } from "node:os";
4
4
  import { isAbsolute, resolve } from "node:path";
5
5
  import { ApiError, authorize, programVersion, token } from "../api.js";
6
+ import { SANDBOX_INSTALL_HINT } from "../exec/sandbox-messages.js";
6
7
  import { prepareDeviceDir } from "../exec/shared.js";
7
8
  import { resetOwnerReport } from "../owner-report.js";
8
9
  import { hasLoginService } from "../service/installed.js";
9
- import { DEFAULT_MAX_FRAME_BYTES, DEFAULT_POLICY, defaultWorkDir, ownerCeilingOfMode, policyMode, policyPath, readCredential, readPolicy, withPolicyLock, writeCredential, writePolicy, } from "../state.js";
10
- import { AUTO_MODE_LOGIN_LINE, AUTO_MODE_RISK_TEXT, AUTO_POLICY_REFUSED_LOGIN_LINE, checkSandbox, DOCKER_AUTO_MODE_LOGIN_LINE, DOCKER_SANDBOX_MODE_LOGIN_LINE, SANDBOX_MODE_LOGIN_LINE, SANDBOX_POLICY_LOGIN_LINE, sandboxUnavailableLoginLine, } from "./mode.js";
10
+ import { DEFAULT_MAX_FRAME_BYTES, DEFAULT_POLICY, defaultWorkDir, policyPath, readCredential, readPolicy, withPolicyLock, writeCredential, writePolicy, } from "../state.js";
11
+ /**
12
+ * Shown once at login when the owner ceiling allows Full access in an organization that allows
13
+ * it: the trust model of Full access is command review, not the OS sandbox.
14
+ */
15
+ export const FULL_ACCESS_RISK_TEXT = "With Full access, agent commands run on this computer as you: they can read and write all " +
16
+ "your files, use your credentials (SSH keys, cloud accounts, keychain), Docker and any network, " +
17
+ "and the deployment reviews every command before it runs. Prompt injection can make an agent " +
18
+ "try to delete files or send your credentials away; the review blocks or asks about the " +
19
+ "dangerous ones. Such commands can also read this program's own credential: if you suspect " +
20
+ "misuse, run capybara-device logout and log in again.";
21
+ async function checkSandbox(check) {
22
+ if (check !== undefined)
23
+ return check();
24
+ const { sandboxAvailability } = await import("../exec/sandbox-check.js");
25
+ return sandboxAvailability();
26
+ }
27
+ /** How the owner widens the ceiling, on this machine only (the deployment may only narrow it). */
28
+ export const WIDEN_CEILING_HINT = "Only you can widen it, on this machine: `capybara-device ceiling set --full-access allow " +
29
+ "--project-reach os-user` (see `capybara-device ceiling show`).";
30
+ /**
31
+ * The line `login` prints for a restricted owner ceiling (the default of a new setup, B-14): no
32
+ * Full access, restricted work in the device's workspace only.
33
+ */
34
+ export const RESTRICTED_CEILING_LOGIN_LINE = "This machine's owner ceiling allows restricted work only: Full access is off, and restricted " +
35
+ `work reaches the device's workspace. ${WIDEN_CEILING_HINT}`;
36
+ /** The line `login` prints when the owner ceiling allows Full access. */
37
+ export const FULL_CEILING_LOGIN_LINE = "This machine's owner ceiling allows Full access: a conversation set to Full access runs agent " +
38
+ "commands as you. Narrow it with `capybara-device ceiling set --full-access deny " +
39
+ "--project-reach workspace`.";
40
+ /** Added when the organization does not allow Full access while the owner ceiling does. */
41
+ export const FULL_ACCESS_NOT_ALLOWED_LOGIN_LINE = "This organization does not allow Full access, so agents use the restricted profiles here.";
42
+ /** The line `login` prints when restricted work cannot run here (no OS sandbox). */
43
+ export function restrictedUnavailableLoginLine(reason) {
44
+ return (`The OS sandbox is unavailable on this machine (${reason}), so restricted work cannot run ` +
45
+ `here yet: ${SANDBOX_INSTALL_HINT}; or log in again with --mode docker. ${WIDEN_CEILING_HINT}`);
46
+ }
11
47
  const SLOW_DOWN_STEP_SECONDS = 5;
12
48
  function defaultOpen(platform) {
13
49
  return (url) => {
@@ -23,20 +59,19 @@ function defaultOpen(platform) {
23
59
  };
24
60
  }
25
61
  /**
26
- * A fresh device in an organization that forbids auto mode starts in sandbox mode (auto mode
27
- * spec §4.1): the default policy is auto, which the kernel refuses at every exec, so the login
28
- * line would otherwise describe a mode the machine does not run. Written under the policy lock,
29
- * and only while no policy file exists: an existing policy is the owner's choice and is never
30
- * changed here. Returns whether this call created the file.
62
+ * A new setup writes the default policy (B-14): a restricted owner ceiling, no Full access and the
63
+ * workspace as the restricted reach. Written under the policy lock, and only while no policy file
64
+ * exists: an existing policy is the owner's choice and is never changed here (an old format still
65
+ * converts exactly at start). Returns whether this call created the file.
31
66
  */
32
- function persistSandboxPolicy(stateDir) {
67
+ function persistDefaultPolicy(stateDir) {
33
68
  const file = policyPath(stateDir);
34
69
  if (existsSync(file))
35
70
  return false;
36
71
  return withPolicyLock(stateDir, () => {
37
72
  if (existsSync(file))
38
73
  return false;
39
- writePolicy(stateDir, { ...DEFAULT_POLICY, ownerCeiling: ownerCeilingOfMode("sandbox") });
74
+ writePolicy(stateDir, { ...DEFAULT_POLICY, ownerCeiling: { ...DEFAULT_POLICY.ownerCeiling } });
40
75
  return true;
41
76
  });
42
77
  }
@@ -108,41 +143,27 @@ export async function login(cmd, deps) {
108
143
  : resolve(cmd.dir);
109
144
  // Recreates a lost directory, marker or root: the device starts afresh.
110
145
  prepareDeviceDir(dir);
111
- // The printed line follows this machine's persisted policy in both branches, not the
112
- // organization's allowance: sandbox mode is also the state an earlier login in an
113
- // auto-forbidden organization left behind. The default mode is auto; an organization that
114
- // forbids it gets sandbox mode written as this device's policy before the credential makes
115
- // the login final. An existing policy is the owner's choice: the kernel refuses auto mode
116
- // at every command if the organization forbids it and the owner keeps auto.
117
- let mode = "auto";
118
- /** Why no sandbox policy was written: the OS sandbox cannot run here (OS mode only). */
119
- let noSandbox;
120
- if (granted.autoMode === "off") {
121
- try {
122
- // A sandbox policy on a machine without the OS sandbox could not run a command either:
123
- // it is not written, and the line says what to install (Docker needs no OS sandbox).
124
- if (cmd.mode !== "docker" && !existsSync(policyPath(deps.stateDir))) {
125
- const available = await checkSandbox(deps.sandboxAvailable);
126
- if (!available.ok)
127
- noSandbox = available.reason;
128
- }
129
- if (noSandbox === undefined) {
130
- mode = persistSandboxPolicy(deps.stateDir)
131
- ? "sandbox"
132
- : policyMode(readPolicy(deps.stateDir));
133
- }
134
- }
135
- catch (e) {
136
- err(`Cannot set the local policy in ${deps.stateDir}: ${e.message}`);
137
- }
146
+ // A new setup gets the restricted default written before the credential makes the login
147
+ // final; the printed lines follow the policy this machine actually has.
148
+ let ceiling = { ...DEFAULT_POLICY.ownerCeiling };
149
+ try {
150
+ persistDefaultPolicy(deps.stateDir);
138
151
  }
139
- else {
140
- try {
141
- mode = policyMode(readPolicy(deps.stateDir));
142
- }
143
- catch (e) {
144
- err(`Cannot read the local policy in ${deps.stateDir}: ${e.message}`);
145
- }
152
+ catch (e) {
153
+ err(`Cannot set the local policy in ${deps.stateDir}: ${e.message}`);
154
+ }
155
+ try {
156
+ ceiling = readPolicy(deps.stateDir).ownerCeiling;
157
+ }
158
+ catch (e) {
159
+ err(`Cannot read the local policy in ${deps.stateDir}: ${e.message}`);
160
+ }
161
+ /** Why restricted work cannot run here: the OS sandbox is missing (OS mode only). */
162
+ let noSandbox;
163
+ if (cmd.mode !== "docker") {
164
+ const available = await checkSandbox(deps.sandboxAvailable);
165
+ if (!available.ok)
166
+ noSandbox = available.reason;
146
167
  }
147
168
  // a new credential is a new machine at the deployment: its owner reports start a new
148
169
  // sequence (also repairs a lost or corrupt sidecar)
@@ -169,27 +190,20 @@ export async function login(cmd, deps) {
169
190
  maxFrameBytes: granted.maxFrameBytes ?? DEFAULT_MAX_FRAME_BYTES,
170
191
  });
171
192
  out(`Logged in. Device ${granted.deviceId}, working directory ${dir}`);
172
- // The risk text is shown once at login (spec §8), and only when commands run on this
173
- // machine as the owner (auto mode outside Docker).
174
- if (cmd.mode === "docker") {
175
- if (granted.autoMode === "off" && mode !== "sandbox")
176
- out(AUTO_POLICY_REFUSED_LOGIN_LINE);
177
- else
178
- out(mode === "sandbox" ? DOCKER_SANDBOX_MODE_LOGIN_LINE : DOCKER_AUTO_MODE_LOGIN_LINE);
179
- }
180
- else if (noSandbox !== undefined) {
181
- out(sandboxUnavailableLoginLine(noSandbox));
182
- }
183
- else if (granted.autoMode === "off") {
184
- out(mode === "sandbox" ? SANDBOX_MODE_LOGIN_LINE : AUTO_POLICY_REFUSED_LOGIN_LINE);
185
- }
186
- else if (mode === "sandbox") {
187
- out(SANDBOX_POLICY_LOGIN_LINE);
193
+ if (ceiling.fullAccess) {
194
+ out(FULL_CEILING_LOGIN_LINE);
195
+ if (granted.fullAccess === "off")
196
+ out(FULL_ACCESS_NOT_ALLOWED_LOGIN_LINE);
197
+ // the risk text is shown once at login, and only when Full access runs as the owner on
198
+ // this machine (outside Docker)
199
+ else if (cmd.mode !== "docker")
200
+ out(FULL_ACCESS_RISK_TEXT);
188
201
  }
189
202
  else {
190
- out(AUTO_MODE_LOGIN_LINE);
191
- out(AUTO_MODE_RISK_TEXT);
203
+ out(RESTRICTED_CEILING_LOGIN_LINE);
192
204
  }
205
+ if (noSandbox !== undefined)
206
+ out(restrictedUnavailableLoginLine(noSandbox));
193
207
  // An installed service stays stopped after a deliberate exit (not logged in, logged out):
194
208
  // it needs starting again, not a second program.
195
209
  out(hasLoginService(deps.home, platform)
@@ -7,17 +7,15 @@ export interface PolicyDeps {
7
7
  }
8
8
  /** What OS mode does not enforce yet, shown with `show` and with a limits change. */
9
9
  export declare const NOT_ENFORCED_NOTE: string;
10
- /** Shown when a Docker-mode device's policy is shown or given allowed domains. */
11
- export declare const DOCKER_DOMAIN_NOTE: string;
12
- /** What `policy show` says the mode gives on this machine (English, one line each). */
13
- export declare function describeMode(policy: Policy, runMode?: "os" | "docker"): string[];
10
+ /** What `policy show` says the owner ceiling gives on this machine (English, one line each). */
11
+ export declare function describeCeiling(policy: Policy, runMode?: "os" | "docker"): string[];
14
12
  /**
15
13
  * `policy show` prints the local policy and what its mode gives on this machine;
16
14
  * `policy set <key> <value>` replaces one field; `policy add|remove <key> <value>` adds or removes
17
- * entries of a list field. The mode is set with `capybara-device mode`. The machine's user edits
18
- * this file; the deployment changes it only through the `policy` op (narrowing only: hosts and
19
- * `mode: "sandbox"`, never auto). Writes take policy.json.lock, and a running program applies the
20
- * change at its next command.
15
+ * entries of a list field. The owner ceiling is set with `capybara-device ceiling set`. The
16
+ * machine's user edits this file; the deployment changes it only through the `policy` op
17
+ * (narrowing only). Writes take policy.json.lock, and a running program applies the change at its
18
+ * next operation.
21
19
  */
22
20
  export declare function policyCommand(cmd: Extract<Command, {
23
21
  command: "policy";
@@ -1,15 +1,14 @@
1
1
  import { validateAllowHost } from "@capybara-hq/plugin-sdk";
2
+ import { noteCliPolicyChange } from "../command-log.js";
2
3
  import { PolicyStore } from "../policy-store.js";
3
- import { policyMode, policyPath, readCredential } from "../state.js";
4
+ import { policyPath, readCredential } from "../state.js";
4
5
  /** The fields `show` prints and `set` may replace. */
5
- const KEYS = ["allowedDomains", "allowCredentials", "cpu", "memoryMb", "mode"];
6
+ const KEYS = ["allowedDomains", "allowCredentials", "cpu", "memoryMb"];
6
7
  /** What OS mode does not enforce yet, shown with `show` and with a limits change. */
7
- export const NOT_ENFORCED_NOTE = "Note: in OS mode cpu and memoryMb are not enforced yet; allowCredentials is ignored (auto " +
8
- "mode already has the owner's credentials, sandbox mode gets none).";
9
- /** Shown when a Docker-mode device's policy is shown or given allowed domains. */
10
- export const DOCKER_DOMAIN_NOTE = "Note: this device runs commands in Docker mode, where the mode alone decides network " +
11
- "access (auto: the default bridge; sandbox: no network). Allowed domains apply in OS mode's " +
12
- "sandbox only.";
8
+ export const NOT_ENFORCED_NOTE = "Note: in OS mode cpu and memoryMb are not enforced yet; allowCredentials is ignored (Full " +
9
+ "access already has the owner's credentials, restricted work gets none).";
10
+ /** Where the owner ceiling is changed (the policy command never changes it). */
11
+ const CEILING_COMMAND = "capybara-device ceiling set --full-access allow|deny --project-reach workspace|os-user";
13
12
  function list(value) {
14
13
  return value
15
14
  .split(",")
@@ -67,40 +66,27 @@ function edit(current, action, key, values, out) {
67
66
  out(has(current, v) ? `Removed ${v} from ${key}.` : `${v} is not in ${key}.`);
68
67
  return current.filter((x) => !has(values, x));
69
68
  }
70
- /** What `policy show` says the mode gives on this machine (English, one line each). */
71
- export function describeMode(policy, runMode = "os") {
72
- if (policyMode(policy) === "auto") {
73
- if (runMode === "docker") {
74
- return [
75
- "Mode: auto. Commands run in the device's container on its default bridge, and the " +
76
- "platform's file tools reach any path in the container; the deployment reviews every " +
77
- "command and blocks or asks about dangerous ones.",
78
- ];
79
- }
80
- return [
81
- "Mode: auto. Commands run as you on this machine, with their files, credentials and " +
82
- "network; the deployment reviews every command and blocks or asks about dangerous ones.",
83
- "Allowed domains apply in sandbox mode only (capybara-device mode sandbox).",
84
- ];
85
- }
86
- if (runMode === "docker") {
87
- return [
88
- "Mode: sandbox. Commands run in the device's container with no network; only the " +
89
- "workspace, skills and temporary files are writable.",
90
- ];
91
- }
69
+ /** What `policy show` says the owner ceiling gives on this machine (English, one line each). */
70
+ export function describeCeiling(policy, runMode = "os") {
71
+ const { fullAccess, restrictedProjectReach } = policy.ownerCeiling;
72
+ const where = runMode === "docker" ? "in the device's container" : "as you on this machine";
92
73
  return [
93
- "Mode: sandbox. Only the workspace, skills and temporary files are writable; the network " +
94
- "reaches the allowed hosts.",
74
+ fullAccess
75
+ ? `Owner ceiling: Full access allowed: a conversation set to Full access runs commands ${where}.`
76
+ : "Owner ceiling: Full access denied: conversations here use the restricted profiles only.",
77
+ restrictedProjectReach === "os-user"
78
+ ? "Restricted work and project browsing may read projects outside the device's workspace."
79
+ : "Restricted work and project browsing stay in the device's workspace.",
80
+ `Change the owner ceiling with: ${CEILING_COMMAND}`,
95
81
  ];
96
82
  }
97
83
  /**
98
84
  * `policy show` prints the local policy and what its mode gives on this machine;
99
85
  * `policy set <key> <value>` replaces one field; `policy add|remove <key> <value>` adds or removes
100
- * entries of a list field. The mode is set with `capybara-device mode`. The machine's user edits
101
- * this file; the deployment changes it only through the `policy` op (narrowing only: hosts and
102
- * `mode: "sandbox"`, never auto). Writes take policy.json.lock, and a running program applies the
103
- * change at its next command.
86
+ * entries of a list field. The owner ceiling is set with `capybara-device ceiling set`. The
87
+ * machine's user edits this file; the deployment changes it only through the `policy` op
88
+ * (narrowing only). Writes take policy.json.lock, and a running program applies the change at its
89
+ * next operation.
104
90
  */
105
91
  export async function policyCommand(cmd, deps) {
106
92
  const { stateDir, out, err } = deps;
@@ -116,10 +102,8 @@ export async function policyCommand(cmd, deps) {
116
102
  if (cmd.action === "show") {
117
103
  const policy = store.current();
118
104
  out(JSON.stringify(policy, null, 2));
119
- for (const l of describeMode(policy, docker ? "docker" : "os"))
105
+ for (const l of describeCeiling(policy, docker ? "docker" : "os"))
120
106
  out(l);
121
- if (docker)
122
- out(DOCKER_DOMAIN_NOTE);
123
107
  out(NOT_ENFORCED_NOTE);
124
108
  return 0;
125
109
  }
@@ -146,13 +130,13 @@ export async function policyCommand(cmd, deps) {
146
130
  break;
147
131
  }
148
132
  case "mode":
149
- throw new Error("the mode is set with: capybara-device mode auto|sandbox");
133
+ throw new Error(`the mode is gone: set the owner ceiling with ${CEILING_COMMAND}`);
150
134
  case "network":
151
135
  case "tier":
152
136
  case "isolation":
153
137
  case "localhost":
154
138
  case "remoteGrants":
155
- throw new Error(`"${key}" is gone: the mode is set with capybara-device mode auto|sandbox; ` +
139
+ throw new Error(`"${key}" is gone: set the owner ceiling with ${CEILING_COMMAND}; ` +
156
140
  `allowedDomains with capybara-device policy add allowedDomains <host>`);
157
141
  default:
158
142
  throw new Error(`unknown policy key "${key}"; one of ${KEYS.join(", ")}`);
@@ -179,23 +163,20 @@ export async function policyCommand(cmd, deps) {
179
163
  return 2;
180
164
  }
181
165
  const lines = [];
182
- let next;
183
166
  try {
184
- next = store.update((p) => change(p, (l) => lines.push(l)));
167
+ store.update((p) => change(p, (l) => lines.push(l)));
185
168
  }
186
169
  catch (e) {
187
170
  err(`Cannot change ${policyPath(stateDir)}: ${e.message}`);
188
171
  return 1;
189
172
  }
173
+ // the audit line names the key and the values given, never more (no secret is a policy value)
174
+ noteCliPolicyChange(stateDir, `policy ${action} ${key} ${list(value).join(", ")}`);
190
175
  for (const l of lines)
191
176
  out(l);
192
- out(`Saved ${policyPath(stateDir)}. A running capybara-device applies it at the next command.`);
177
+ out(`Saved ${policyPath(stateDir)}. A running capybara-device applies it at the next operation.`);
193
178
  if (key === "allowedDomains") {
194
- out(docker
195
- ? DOCKER_DOMAIN_NOTE
196
- : policyMode(next) === "auto"
197
- ? "Allowed domains apply in sandbox mode only; switch with: capybara-device mode sandbox"
198
- : "Sandboxed commands may reach these domains when the organization allows them too.");
179
+ out("Restricted work may reach these domains when the organization allows them too.");
199
180
  }
200
181
  if (key === "cpu" || key === "memoryMb" || key === "allowCredentials")
201
182
  out(NOT_ENFORCED_NOTE);
@@ -1,5 +1,3 @@
1
- import { connect } from "../client.js";
2
- import type { Executor } from "../exec/types.js";
3
1
  import { type ProcessLookup } from "../pid.js";
4
2
  import { PolicyStore } from "../policy-store.js";
5
3
  import { connectStaged } from "../staged-connect.js";
@@ -7,11 +5,6 @@ import type { StagedDevice } from "../staged-device.js";
7
5
  import { type Credential } from "../state.js";
8
6
  export interface StartDeps {
9
7
  stateDir: string;
10
- /**
11
- * Builds the executor for the credential's mode (the OS and Docker executors). The store
12
- * follows policy.json, so executors read the policy at each command.
13
- */
14
- createExecutor?: (cred: Credential, policy: PolicyStore) => Promise<Executor> | Executor;
15
8
  out: (line: string) => void;
16
9
  err: (line: string) => void;
17
10
  /** Where the login service would be installed, and on which platform (default: this machine). */
@@ -25,20 +18,12 @@ export interface StartDeps {
25
18
  ps?: ProcessLookup;
26
19
  /** The environment (default: process.env): tells whether the service manager started this. */
27
20
  env?: Record<string, string | undefined>;
28
- connect?: typeof connect;
29
21
  /**
30
- * Builds the staged (protocol 3) program's parts for the credential: the binder, one operation
31
- * backend per bound generation, the per-credential session states and the owner policy. Used
32
- * only when the protocol is the staged one.
22
+ * Builds the program's parts for the credential: the binder, one operation backend per bound
23
+ * generation, the per-credential session states and the owner policy.
33
24
  */
34
25
  createStaged?: (cred: Credential, policy: PolicyStore) => Promise<StagedDevice> | StagedDevice;
35
26
  connectStaged?: typeof connectStaged;
36
- /**
37
- * Test seam: the device protocol this program speaks (default: the SDK's
38
- * `DEVICE_PROTOCOL_VERSION`). Production never sets it: the staged path is selected only by
39
- * that constant.
40
- */
41
- protocol?: number;
42
27
  }
43
28
  /** Printed once when start converted an old-format policy.json to version 2. */
44
29
  export declare function legacyPolicyNotice(mode: "auto" | "sandbox"): string;
@@ -1,8 +1,4 @@
1
1
  import { homedir } from "node:os";
2
- import { DEVICE_PROTOCOL_VERSION, STAGED_DEVICE_PROTOCOL_VERSION } from "@capybara-hq/plugin-sdk";
3
- import { connect } from "../client.js";
4
- import { CommandLog } from "../command-log.js";
5
- import { sandboxUnavailableMessage } from "../exec/sandbox-messages.js";
6
2
  import { readRunningPid, removePid, writePid } from "../pid.js";
7
3
  import { PolicyStore } from "../policy-store.js";
8
4
  import { hasLoginService } from "../service/installed.js";
@@ -35,9 +31,7 @@ export async function start(deps) {
35
31
  err("Not logged in. Run capybara-device login --url <url> first.");
36
32
  return 0;
37
33
  }
38
- // the staged (protocol 3) path is selected only by the protocol constant
39
- const staged = (deps.protocol ?? DEVICE_PROTOCOL_VERSION) === STAGED_DEVICE_PROTOCOL_VERSION;
40
- if (staged ? deps.createStaged === undefined : deps.createExecutor === undefined) {
34
+ if (deps.createStaged === undefined) {
41
35
  err("capybara-device start: no execution backend is available in this build");
42
36
  return 1;
43
37
  }
@@ -57,7 +51,7 @@ export async function start(deps) {
57
51
  err(`capybara-device is already running (pid ${running}). Stop it first: capybara-device stop`);
58
52
  return 1;
59
53
  }
60
- // Signals arriving while the executor is still being prepared are applied once connected.
54
+ // Signals arriving while the program is still being prepared are applied once connected.
61
55
  let conn;
62
56
  let stopRequested = false;
63
57
  let drainRequested = false;
@@ -75,47 +69,13 @@ export async function start(deps) {
75
69
  proc.on("SIGUSR2", onDrain);
76
70
  writePid(stateDir, proc.pid, PROGRAM_VERSION);
77
71
  try {
78
- if (staged)
79
- return await serveStaged(deps, cred, {
80
- stopRequested: () => stopRequested,
81
- drainRequested: () => drainRequested,
82
- connected: (c) => {
83
- conn = c;
84
- },
85
- });
86
- let executor;
87
- let policy;
88
- try {
89
- // An invalid policy.json stops the start; later, a broken edit keeps the last good policy.
90
- // The one-time explicit conversion to the version 2 format (locked, atomic, exact).
91
- const converted = convertPolicyFile(stateDir) === "converted";
92
- policy = new PolicyStore(stateDir, { err });
93
- if (converted)
94
- out(legacyPolicyNotice(policyMode(policy.current())));
95
- executor = await deps.createExecutor(cred, policy);
96
- // Without the OS sandbox the device keeps serving: auto mode works, and sandbox mode
97
- // refuses every command with this reason. A policy set to sandbox says so at start.
98
- const sandbox = executor;
99
- if (sandbox.available === false && policyMode(policy.current()) === "sandbox") {
100
- err(sandboxUnavailableMessage(sandbox.unavailableReason ?? ""));
101
- }
102
- }
103
- catch (e) {
104
- err(`Cannot start: ${e.message}`);
105
- return 1;
106
- }
107
- if (stopRequested)
108
- return 0;
109
- // One store: the executor's commands, the hello summary and the policy op see the same policy.
110
- conn = (deps.connect ?? connect)(cred, executor, {
111
- log: new CommandLog(stateDir),
112
- err,
113
- policy,
72
+ return await serveStaged(deps, cred, {
73
+ stopRequested: () => stopRequested,
74
+ drainRequested: () => drainRequested,
75
+ connected: (c) => {
76
+ conn = c;
77
+ },
114
78
  });
115
- if (drainRequested)
116
- conn.drain();
117
- out(`capybara-device: serving device ${cred.deviceId} (${cred.mode} mode)`);
118
- return await conn.done;
119
79
  }
120
80
  finally {
121
81
  proc.off("SIGTERM", onStop);
@@ -125,16 +85,16 @@ export async function start(deps) {
125
85
  }
126
86
  }
127
87
  /**
128
- * The staged (protocol 3) start (permission activation W3-M): the policy store, the staged parts
129
- * (binder, per-generation backends, per-credential session state), recovery of a persisted
130
- * binding, then {@link connectStaged}. Dormant until the protocol constant selects it.
88
+ * The start proper (device protocol 3): the policy store, the program's parts (binder,
89
+ * per-generation backends, per-credential session state), recovery of a persisted binding, then
90
+ * {@link connectStaged}.
131
91
  */
132
92
  async function serveStaged(deps, cred, signals) {
133
93
  const { stateDir, out, err } = deps;
134
94
  let device;
135
95
  try {
136
96
  const converted = convertPolicyFile(stateDir) === "converted";
137
- const policy = new PolicyStore(stateDir, { err });
97
+ const policy = new PolicyStore(stateDir);
138
98
  if (converted)
139
99
  out(legacyPolicyNotice(policyMode(policy.current())));
140
100
  device = await deps.createStaged(cred, policy);
@@ -152,7 +112,7 @@ async function serveStaged(deps, cred, signals) {
152
112
  err(`The instance binding was not recovered: ${e.message}`);
153
113
  }
154
114
  if (signals.stopRequested()) {
155
- // stopped before it connected: release what construction acquired (the Docker executor)
115
+ // stopped before it connected: release what construction acquired
156
116
  await device.dispose().catch((e) => err(`Cleanup failed: ${e.message}`));
157
117
  return 0;
158
118
  }
@@ -3,7 +3,7 @@ import { type LinuxBackendDependencies, type LocalOperationBackend } from "./lin
3
3
  import { type LinuxAgentTransport } from "./linux-runtime.js";
4
4
  import { type MacOperationBackendOptions } from "./mac-operation-backend.js";
5
5
  import { type DeviceOwnerCeiling } from "./operation-types.js";
6
- /** What the Docker executor lends one operation: its running container, held until release. */
6
+ /** What the device container lends one operation: its running container, held until release. */
7
7
  export interface OperationContainerHost {
8
8
  operationContainer(signal: AbortSignal): Promise<{
9
9
  name: string;
@@ -41,4 +41,4 @@ export interface DockerOperationBackendOptions extends Omit<MacOperationBackendO
41
41
  * the container's paths. Background artifacts are written by the trusted supervisor to the host
42
42
  * directories behind the bind mounts; skill preparation writes the host skills directory.
43
43
  */
44
- export declare function createDockerOperationBackend(options: DockerOperationBackendOptions, dependencies?: Omit<LinuxBackendDependencies, "transport" | "baseEnv">): Promise<LocalOperationBackend>;
44
+ export declare function createDockerOperationBackend(options: DockerOperationBackendOptions, dependencies?: Omit<LinuxBackendDependencies, "transport" | "baseEnv" | "toolHome">): Promise<LocalOperationBackend>;
@@ -31,7 +31,7 @@ export function containerBaseEnv(full) {
31
31
  * (PID plus start time, checked again before each signal) gets SIGTERM, then SIGKILL, and this
32
32
  * returns once it is gone.
33
33
  */
34
- const END_AGENT = String.raw `
34
+ const END_AGENT = `
35
35
  import os, sys, time
36
36
  pid, start = int(sys.argv[1]), int(sys.argv[2])
37
37
  def same():
@@ -222,7 +222,9 @@ function hostSkillsPreparation(request, hostRoots, pythonPath, stateDir, acquire
222
222
  * the container's paths. Background artifacts are written by the trusted supervisor to the host
223
223
  * directories behind the bind mounts; skill preparation writes the host skills directory.
224
224
  */
225
- export async function createDockerOperationBackend(options, dependencies = {}) {
225
+ export async function createDockerOperationBackend(options,
226
+ // no toolHome: a command in the container has the image's home, not the host user's
227
+ dependencies = {}) {
226
228
  const transport = dockerLinuxTransport(options.container);
227
229
  let probe = await (dependencies.probe ?? (() => probeLinuxRuntime(transport)))();
228
230
  if (probe.restricted !== null && !dependencies.probe) {