@capybara-hq/plugin-sdk 0.1.0-rc.37 → 0.1.0-rc.39

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.
@@ -5,8 +5,11 @@
5
5
  * from executing what a restricted command left behind.
6
6
  *
7
7
  * 1. {@link SANDBOX_MANDATORY_WRITE_DENIES}: component sequences denied wherever they appear (the
8
- * entry and everything beneath it): shell startup files, git's global files, direnv and npm
9
- * configuration, editor and agent configuration.
8
+ * entry and everything beneath it): shell startup and logout files, git's global files, direnv
9
+ * and npm configuration, editor and agent configuration, and the OS persistence locations
10
+ * (launchd, systemd, environment.d, XDG and KDE autostart, X session files, fish). Entries are
11
+ * written already folded. {@link SANDBOX_SYSTEM_WRITE_DENIES}: absolute system paths denied
12
+ * with everything beneath them (the crontab and at spools), anchored at `/`.
10
13
  * 2. Inside a `.git` directory (the first `.git` component of a path) only git's ordinary
11
14
  * internals are writable, an allowlist ({@link SANDBOX_GIT_ALLOWED_DIRECTORIES},
12
15
  * {@link SANDBOX_GIT_ALLOWED_FILES}, `info/exclude`). Everything else there is denied:
@@ -16,14 +19,23 @@
16
19
  * any reading of its name would make it a denied internal.
17
20
  * 3. Outside `.git`, a file named `HEAD` is denied: with `objects/` and `refs/` it would make a
18
21
  * bare-repository lookalike whose configuration git honours.
19
- * 4. Moves ({@link isSandboxMoveDenied}): nothing leaves a protected name (`.git`, `.claude`, …)
20
- * except within the same protected directory; a directory is not moved under a protected name
21
- * from outside it; no non-directory becomes `.git` (a `gitdir:` pointer).
22
+ * 4. Moves ({@link isSandboxMoveDenied}): neither end may be a denied write; nothing leaves a
23
+ * protected name ({@link SANDBOX_PROTECTED_PATH_NAMES}: `.git` and the single-component
24
+ * entries) except within the same protected directory; a directory is not moved under a
25
+ * protected name from outside it; no non-directory becomes `.git` (a `gitdir:` pointer). For a
26
+ * multi-component entry `[a, b, …]` (or an absolute system path) a destination ending in a
27
+ * proper prefix of it (`…/a`) takes no non-directory (a link there would redirect the entry)
28
+ * and no directory holding the entry's next component (`b`): a prepared directory never moves
29
+ * into place, while ordinary names (`library`, `.config`) stay movable. An ancestor of an
30
+ * anchored path (a system path, or a consumer's resolved target) never moves away.
22
31
  *
23
32
  * 5. Inside an allowlisted subtree nothing can make a repository: no `.git`, no `HEAD` except
24
33
  * where git keeps one (`logs/HEAD`, `refs/remotes/<r>/HEAD`, …), and no `objects`, `commondir`
25
34
  * or `gitdir` beside such a `HEAD`.
26
35
  *
36
+ * 6. A component starting with {@link SANDBOX_RESERVED_NAME_PREFIX} (the broker's staging and
37
+ * quarantine names) is denied with everything beneath it.
38
+ *
27
39
  * Names are compared after Unicode NFKC normalization and full case folding
28
40
  * ({@link sandboxFoldName}, identical to Python's `casefold`). Known limitations: a
29
41
  * restricted command cannot `git init`, add a submodule or worktree, or create a bare repository;
@@ -33,6 +45,17 @@
33
45
  * (its state directories are writable for git's own use) and continuing it runs its `exec` lines.
34
46
  * The macOS worker expresses this policy as ordered Seatbelt regex rules
35
47
  * (`packages/device/src/exec/mac-write-policy.ts`).
48
+ *
49
+ * Constraints on consumers:
50
+ *
51
+ * - The policy judges the path it is given. A protected home location reached through a symbolic
52
+ * link (`~/.config` or `~/Library` linked elsewhere, as dotfile managers do) is denied only at
53
+ * its resolved target: a device worker resolves the protected home locations at operation start
54
+ * and adds their resolved targets as absolute denies.
55
+ * - The move check needs the entries of a moved directory. A consumer passes them from the source
56
+ * descriptor; the Python `move_denied` otherwise lists the source path, refusing when it cannot.
57
+ * A listing is a snapshot: a concurrent writer could add the next component between the check
58
+ * and the rename, so a consumer that can re-checks the destination after the rename.
36
59
  */
37
60
  export const SANDBOX_MANDATORY_WRITE_DENIES = Object.freeze([
38
61
  [".gitconfig"],
@@ -89,7 +112,88 @@ export const SANDBOX_MANDATORY_WRITE_DENIES = Object.freeze([
89
112
  ["simple-git-hooks.cjs"],
90
113
  // the conventional core.hooksPath directory a repository's existing config may name
91
114
  [".githooks"],
115
+ // every other shell startup and logout file (the kernel review's persistence rules name them)
116
+ [".zshenv"],
117
+ [".zlogin"],
118
+ [".zlogout"],
119
+ [".bash_login"],
120
+ [".bash_logout"],
121
+ [".logout"],
122
+ [".tcshrc"],
123
+ [".cshrc"],
124
+ [".kshrc"],
125
+ [".config", "git", "config"],
126
+ [".config", "fish", "config.fish"],
127
+ [".config", "fish", "conf.d"],
128
+ // persistence locations the OS runs later (approval-only profiles design, "Fixed denies"):
129
+ // launchd agents and daemons, systemd units, drop-ins and session environment, XDG and KDE
130
+ // autostart, the X session files. The crontab spools are SANDBOX_SYSTEM_WRITE_DENIES.
131
+ ["library", "launchagents"],
132
+ ["library", "launchdaemons"],
133
+ [".config", "systemd"],
134
+ [".local", "share", "systemd"],
135
+ [".config", "environment.d"],
136
+ [".config", "autostart"],
137
+ [".config", "autostart-scripts"],
138
+ [".config", "plasma-workspace", "env"],
139
+ [".xprofile"],
140
+ [".xsessionrc"],
141
+ // PATH-shim persistence: programs placed here shadow system ones in the owner's later shells
142
+ // (`~/bin` is home-anchored: SANDBOX_HOME_WRITE_DENIES)
143
+ [".local", "bin"],
144
+ [".cargo", "bin"],
92
145
  ].map((entry) => Object.freeze(entry)));
146
+ /**
147
+ * Locations denied only directly under the device owner's home, with everything beneath them, never
148
+ * elsewhere: `~/bin`, a directory many shells put on `PATH`, where a planted program would shadow a
149
+ * system one in the owner's later unsandboxed shell (a project's own `bin/` stays writable).
150
+ * Consumers anchor each entry at the home they protect: the device workers add it, and the target
151
+ * of a link it is, as absolute denies; the kernel never proposes it as a write directory
152
+ * ({@link isSandboxHomeWriteDenied}). `~/.local/bin` and `~/.cargo/bin` are
153
+ * {@link SANDBOX_MANDATORY_WRITE_DENIES} entries.
154
+ */
155
+ export const SANDBOX_HOME_WRITE_DENIES = Object.freeze([
156
+ Object.freeze(["bin"]),
157
+ ]);
158
+ /**
159
+ * System runtime and socket directories (compared folded, anchored at `/`): other programs keep
160
+ * their UNIX sockets and device nodes there (`/run/user/<uid>/bus`, `/var/run/docker.sock`,
161
+ * `/dev`, `/proc`), so a restricted write root never is one, lies inside one or contains one
162
+ * ({@link sandboxRuntimeDirectoryOf}).
163
+ */
164
+ export const SANDBOX_RUNTIME_DIRECTORIES = Object.freeze([
165
+ "/run",
166
+ "/var/run",
167
+ "/private/var/run",
168
+ "/dev",
169
+ "/proc",
170
+ "/sys",
171
+ ]);
172
+ /** The shared temporary directories: never a write root themselves (sockets sit directly in them). */
173
+ const TEMP_DIRECTORIES = ["/tmp", "/private/tmp"];
174
+ /** Socket directories other programs create directly in a temporary directory (folded names). */
175
+ const TEMP_SOCKET_DIRECTORY = /^(?:\.x11-unix|\.ice-unix|\.xim-unix|\.font-unix|\.test-unix|tmux-.*|ssh-.*|com\.apple\.launchd\..*|dbus-.*|systemd-private-.*|zellij-.*|emacs[0-9]+|screen.*|vscode-.*|nvim.*)$/;
176
+ /**
177
+ * Absolute system paths denied with everything beneath them, compared folded and anchored at `/`:
178
+ * the crontab and at spools of Linux (`/var/spool/cron` in its `crontabs` and `tabs` layouts,
179
+ * `/var/spool/at`) and macOS (`/private/var/at`, also spelled `/var/at`; `/usr/lib/cron/tabs` is a
180
+ * link resolving there). Never protected move names: a project's own `at/` or `spool/` stays
181
+ * ordinary.
182
+ */
183
+ export const SANDBOX_SYSTEM_WRITE_DENIES = Object.freeze([
184
+ "/var/spool/cron",
185
+ "/var/spool/at",
186
+ "/private/var/at/tabs",
187
+ "/private/var/at/jobs",
188
+ "/var/at",
189
+ ]);
190
+ /**
191
+ * The name prefix the Linux broker reserves for its own staging (a directory checked before it
192
+ * moves into a guarded place) and quarantine names. Any path with a component starting with it
193
+ * (compared folded) is denied to every sandboxed write, so nothing sandboxed can create, write
194
+ * into, or move into or out of such a directory.
195
+ */
196
+ export const SANDBOX_RESERVED_NAME_PREFIX = ".capybara-staging-";
93
197
  /** Directories inside a gitdir whose whole subtree is writable (objects, refs, operation state). */
94
198
  export const SANDBOX_GIT_ALLOWED_DIRECTORIES = Object.freeze([
95
199
  "objects",
@@ -148,11 +252,26 @@ export const SANDBOX_GIT_DENIED_INTERNALS = Object.freeze([
148
252
  "hooks",
149
253
  "info/attributes",
150
254
  ]);
151
- /** Names nothing leaves, and no directory is moved under, from outside. */
255
+ /**
256
+ * Names nothing leaves, and no directory is moved under, from outside: `.git` and the
257
+ * single-component entries. A multi-component entry is guarded by its prefix rule instead (rule 4),
258
+ * so its first component (`library`, `.config`) stays an ordinary name.
259
+ */
152
260
  export const SANDBOX_PROTECTED_PATH_NAMES = Object.freeze([
153
261
  ".git",
154
- ...new Set(SANDBOX_MANDATORY_WRITE_DENIES.map((entry) => entry[0])),
262
+ ...new Set(SANDBOX_MANDATORY_WRITE_DENIES.filter((entry) => entry.length === 1).map((entry) => entry[0])),
155
263
  ]);
264
+ /** The multi-component entries and the anchored system paths, as folded name sequences. */
265
+ const PREFIX_GUARDED = [
266
+ ...SANDBOX_MANDATORY_WRITE_DENIES.filter((entry) => entry.length > 1).map((names) => ({
267
+ names,
268
+ anchored: false,
269
+ })),
270
+ ...SANDBOX_SYSTEM_WRITE_DENIES.map((path) => ({
271
+ names: path.split("/").filter((p) => p !== ""),
272
+ anchored: true,
273
+ })),
274
+ ];
156
275
  /**
157
276
  * Python's `str.casefold` where it differs from `toLowerCase` (full case folding, Unicode 15.1),
158
277
  * so both implementations fold identically: `ß`→`ss`, `ſ`→`s`, final sigma, Cherokee, ….
@@ -518,9 +637,57 @@ function gitInternalAllowed(rel) {
518
637
  }
519
638
  return (head === "info" && rel.length === 2 && ["exclude", "exclude.lock"].includes(rel[1]));
520
639
  }
640
+ /**
641
+ * The system runtime or socket directory a restricted write root `root` (absolute, normalized) is,
642
+ * lies inside or contains, or null: {@link SANDBOX_RUNTIME_DIRECTORIES} with everything beneath
643
+ * them; `/tmp` and `/private/tmp` themselves (a subdirectory is fine unless it is a known socket
644
+ * directory such as `/tmp/.X11-unix`, `/tmp/tmux-<uid>` or `/tmp/ssh-*`, or lies inside one); and
645
+ * every ancestor of one (`/var`, `/private`). The kernel's candidate builder and admission and the
646
+ * device's root check refuse such a root: a socket there may belong to a process outside the
647
+ * sandbox (the Linux broker also refuses every pathname UNIX connect to a socket the operation did
648
+ * not bind itself).
649
+ */
650
+ export function sandboxRuntimeDirectoryOf(root) {
651
+ const names = parts(root);
652
+ const within = (anchor) => anchor.length <= names.length && anchor.every((name, j) => names[j] === name);
653
+ const above = (anchor) => names.length < anchor.length && names.every((name, j) => anchor[j] === name);
654
+ for (const directory of SANDBOX_RUNTIME_DIRECTORIES) {
655
+ const anchor = parts(directory);
656
+ if (within(anchor) || above(anchor))
657
+ return directory;
658
+ }
659
+ for (const directory of TEMP_DIRECTORIES) {
660
+ const anchor = parts(directory);
661
+ if (above(anchor) || (within(anchor) && names.length === anchor.length))
662
+ return directory;
663
+ const next = names[anchor.length];
664
+ if (within(anchor) && next !== undefined && TEMP_SOCKET_DIRECTORY.test(next))
665
+ return `${directory}/${next}`;
666
+ }
667
+ return null;
668
+ }
669
+ /**
670
+ * Whether `path` (absolute, normalized) is a {@link SANDBOX_HOME_WRITE_DENIES} location under
671
+ * `home`, or beneath one (names compared folded).
672
+ */
673
+ export function isSandboxHomeWriteDenied(path, home) {
674
+ const names = parts(path);
675
+ const base = parts(home);
676
+ return SANDBOX_HOME_WRITE_DENIES.some((entry) => {
677
+ const anchor = [...base, ...entry.map(fold)];
678
+ return anchor.length <= names.length && anchor.every((name, j) => names[j] === name);
679
+ });
680
+ }
521
681
  /** Whether restricted execution may never write `path` (an absolute, normalized path). */
522
682
  export function isSandboxWriteDenied(path) {
523
683
  const names = parts(path);
684
+ if (names.some((name) => name.startsWith(SANDBOX_RESERVED_NAME_PREFIX)))
685
+ return true;
686
+ for (const system of SANDBOX_SYSTEM_WRITE_DENIES) {
687
+ const anchored = parts(system);
688
+ if (anchored.every((name, j) => names[j] === name))
689
+ return true;
690
+ }
524
691
  for (const entry of SANDBOX_MANDATORY_WRITE_DENIES)
525
692
  for (let i = 0; i + entry.length <= names.length; i++)
526
693
  if (entry.every((name, j) => names[i + j] === name))
@@ -530,10 +697,44 @@ export function isSandboxWriteDenied(path) {
530
697
  return !gitInternalAllowed(names.slice(git + 1));
531
698
  return names[names.length - 1] === "head";
532
699
  }
533
- /** Whether a restricted rename or link of `source` to `destination` is refused (rule 4). */
534
- export function isSandboxMoveDenied(source, destination, sourceIsDirectory) {
700
+ /**
701
+ * The next components a moved entry must not bring to `to`: for each guarded sequence whose proper
702
+ * prefix `to` ends in (anchored: equals), the component that follows. Empty when `to` is no prefix.
703
+ */
704
+ function prefixNext(to) {
705
+ const next = [];
706
+ for (const { names, anchored } of PREFIX_GUARDED)
707
+ for (let k = 1; k < names.length; k++) {
708
+ if (anchored && to.length !== k)
709
+ continue;
710
+ if (to.length < k)
711
+ continue;
712
+ if (names.slice(0, k).every((name, j) => to[to.length - k + j] === name))
713
+ next.push(names[k]);
714
+ }
715
+ return next;
716
+ }
717
+ /**
718
+ * Whether a restricted rename or link of `source` to `destination` is refused (rule 4).
719
+ * `sourceEntries` are the names directly in a moved directory; the check needs them only when the
720
+ * destination ends in a proper prefix of a guarded entry, and without them it refuses.
721
+ */
722
+ export function isSandboxMoveDenied(source, destination, sourceIsDirectory, sourceEntries) {
723
+ if (isSandboxWriteDenied(source) || isSandboxWriteDenied(destination))
724
+ return true;
535
725
  const from = parts(source);
536
726
  const to = parts(destination);
727
+ // an anchored deny's ancestor never moves away: a link resolved into it would dangle
728
+ for (const { names, anchored } of PREFIX_GUARDED)
729
+ if (anchored && from.length < names.length && from.every((name, k) => names[k] === name))
730
+ return true;
731
+ const next = prefixNext(to);
732
+ if (next.length > 0) {
733
+ if (!sourceIsDirectory || sourceEntries === undefined)
734
+ return true;
735
+ if (sourceEntries.some((name) => next.includes(fold(name))))
736
+ return true;
737
+ }
537
738
  const protectedAt = (names) => names.findIndex((n) => SANDBOX_PROTECTED_PATH_NAMES.includes(n));
538
739
  const i = protectedAt(from);
539
740
  const samePrefix = (n) => n >= 0 && to.length > n + 1 && from.slice(0, n + 1).every((name, k) => to[k] === name);
@@ -551,10 +752,13 @@ export function isSandboxMoveDenied(source, destination, sourceIsDirectory) {
551
752
  export const SANDBOX_WRITE_POLICY_PYTHON = `
552
753
  import unicodedata as _unicodedata
553
754
  WRITE_DENIES = [[_unicodedata.normalize("NFKC", n).casefold() for n in e] for e in ${JSON.stringify(SANDBOX_MANDATORY_WRITE_DENIES)}]
755
+ SYSTEM_WRITE_DENIES = [[_unicodedata.normalize("NFKC", n).casefold() for n in p.split("/") if n] for p in ${JSON.stringify(SANDBOX_SYSTEM_WRITE_DENIES)}]
756
+ PREFIX_GUARDED = [(e, False) for e in WRITE_DENIES if len(e) > 1] + [(e, True) for e in SYSTEM_WRITE_DENIES]
554
757
  GIT_ALLOWED_DIRECTORIES = set(${JSON.stringify(SANDBOX_GIT_ALLOWED_DIRECTORIES)})
555
758
  GIT_ALLOWED_FILES = set(${JSON.stringify(SANDBOX_GIT_ALLOWED_FILES)})
556
759
  GIT_DANGER = set(${JSON.stringify([...GIT_DANGER])})
557
760
  PROTECTED_PATH_NAMES = set(${JSON.stringify(SANDBOX_PROTECTED_PATH_NAMES)})
761
+ RESERVED_NAME_PREFIX = ${JSON.stringify(SANDBOX_RESERVED_NAME_PREFIX)}
558
762
 
559
763
 
560
764
  def _fold_parts(path):
@@ -603,6 +807,11 @@ def _git_internal_allowed(rel):
603
807
 
604
808
  def write_denied(path):
605
809
  names = _fold_parts(path)
810
+ if any(n.startswith(RESERVED_NAME_PREFIX) for n in names):
811
+ return True
812
+ for system in SYSTEM_WRITE_DENIES:
813
+ if names[:len(system)] == system:
814
+ return True
606
815
  for entry in WRITE_DENIES:
607
816
  for i in range(len(names) - len(entry) + 1):
608
817
  if names[i:i + len(entry)] == entry:
@@ -612,8 +821,38 @@ def write_denied(path):
612
821
  return bool(names) and names[-1] == "head"
613
822
 
614
823
 
615
- def move_denied(source, destination, is_dir):
824
+ def _prefix_next(dst):
825
+ nxt = []
826
+ for names, anchored in PREFIX_GUARDED:
827
+ for k in range(1, len(names)):
828
+ if (anchored and len(dst) != k) or len(dst) < k:
829
+ continue
830
+ if dst[len(dst) - k:] == names[:k]:
831
+ nxt.append(names[k])
832
+ return nxt
833
+
834
+
835
+ def move_denied(source, destination, is_dir, entries=None):
836
+ if write_denied(source) or write_denied(destination):
837
+ return True
616
838
  src, dst = _fold_parts(source), _fold_parts(destination)
839
+ # an anchored deny's ancestor never moves away: a link resolved into it would dangle
840
+ for names, anchored in PREFIX_GUARDED:
841
+ if anchored and len(src) < len(names) and names[:len(src)] == src:
842
+ return True
843
+ nxt = _prefix_next(dst)
844
+ if nxt:
845
+ if not is_dir:
846
+ return True
847
+ if entries is None:
848
+ # no entries given: list the source path itself, refusing what cannot be listed
849
+ try:
850
+ import os as _os
851
+ entries = _os.listdir(source)
852
+ except OSError:
853
+ return True
854
+ if any(_unicodedata.normalize("NFKC", n).casefold() in nxt for n in entries):
855
+ return True
617
856
 
618
857
  def protected_at(names):
619
858
  return next((k for k, n in enumerate(names) if n in PROTECTED_PATH_NAMES), -1)
package/dist/sandbox.d.ts CHANGED
@@ -14,24 +14,16 @@ export declare const SANDBOX_EXTENSION_POINT = "sandbox@2";
14
14
  /** The roots inside the sandbox the model may access. */
15
15
  export declare const SANDBOX_ROOTS: readonly ["/workspace", "/skills", "/tmp"];
16
16
  /**
17
- * Sandbox resource and network limits. A provider that ignores `mode` and `network` still runs:
18
- * it then behaves as an allowlisted sandbox (the safe direction).
17
+ * Sandbox resource and network limits: what lifecycle create and update carry (resources and the
18
+ * outer network only; each operation's scope says how it runs). A provider that ignores `network`
19
+ * still runs: it then behaves as an allowlisted sandbox (the safe direction).
19
20
  */
20
21
  export interface SandboxLimits {
21
22
  cpu: number;
22
23
  memoryMb: number;
23
24
  diskMb: number;
24
25
  /**
25
- * `auto`: no OS sandbox (local: the owner; cloud: the container is the boundary);
26
- * `sandbox`: the OS sandbox with the network limited by {@link SandboxLimits.network}.
27
- * For operation-capable providers this encodes the independent device ceiling: auto allows
28
- * Full access when separately authorized, sandbox permits restricted operations only.
29
- * It never selects a conversation profile or changes per operation. Legacy consumers retain
30
- * the current mode behavior until coordinated protocol activation.
31
- */
32
- mode: "auto" | "sandbox";
33
- /**
34
- * The network the instance (cloud) must enforce, or the allowlist a local device's sandbox mode
26
+ * The network the instance (cloud) must enforce, or the allowlist a local device's sandbox
35
27
  * intersects with its own list (`open-public` is for cloud instances only). Each entry of
36
28
  * `hosts` passes {@link validateAllowHost}.
37
29
  */
@@ -317,17 +309,15 @@ export interface SandboxProvider {
317
309
  * unit (locale-independent), at most `limit` of them; `truncated` is true when the directory has
318
310
  * more. Entries only: never file contents, never a recursive walk. A `name` is never `.` or `..`;
319
311
  * `isDir` follows symbolic links (stat semantics: a link to a directory is `true`, a dangling link
320
- * `false`, and so is a link whose target the request's mode cannot reach). `limits` is the kernel's current ceiling: read in the mode it gives, never in one an
321
- * earlier command saw. Returns null only when the path does not exist and that mode could reach
322
- * it; a path the mode cannot reach throws (a policy refusal), as does a path that is a file or a
323
- * directory that cannot be read.
312
+ * `false`, and so is a link whose target the device cannot reach). Returns null only when the
313
+ * path does not exist and the device could reach it; a path it cannot reach throws (a policy
314
+ * refusal), as does a path that is a file or a directory that cannot be read.
324
315
  *
325
316
  * Optional: a provider without it (or without {@link SandboxProvider.scan}) offers no projects,
326
317
  * and its conversations stay in free mode.
327
318
  */
328
319
  list?(h: SandboxHandle, path: string, opts: {
329
320
  limit: number;
330
- limits: Pick<SandboxLimits, "mode">;
331
321
  signal: AbortSignal;
332
322
  }): Promise<{
333
323
  entries: {
@@ -337,8 +327,7 @@ export interface SandboxProvider {
337
327
  truncated: boolean;
338
328
  } | null>;
339
329
  /**
340
- * Looks for project-like directories, read in the mode `limits` gives (as for
341
- * {@link SandboxProvider.list}). Every provider traverses the same way:
330
+ * Looks for project-like directories, read as for {@link SandboxProvider.list}. Every provider traverses the same way:
342
331
  *
343
332
  * - Candidates are `base` itself and the directories at most {@link MAX_DEVICE_SCAN_DEPTH}
344
333
  * levels below it that hold a `.git` entry (directory or file) or an `AGENTS.md` file.
@@ -346,7 +335,7 @@ export interface SandboxProvider {
346
335
  * starting with `.`); a candidate does not stop the descent (a monorepo's sub-projects are
347
336
  * candidates too). It never enters a directory named in {@link DEVICE_SCAN_SKIPPED_DIRS}, at
348
337
  * any depth, nor one named in {@link DEVICE_SCAN_SKIPPED_BASE_DIRS} directly under `base`;
349
- * every provider skips exactly these. Paths under `base` the mode cannot reach are skipped,
338
+ * every provider skips exactly these. Paths under `base` the device cannot reach are skipped,
350
339
  * never an error.
351
340
  * - A directory whose basename does not satisfy {@link isDeviceProjectName} is not returned as
352
341
  * a candidate (never with a changed name), but it is still traversed.
@@ -359,10 +348,10 @@ export interface SandboxProvider {
359
348
  * {@link MAX_DEVICE_SCAN_RESULTS}.
360
349
  *
361
350
  * Directory entries only, never file contents. A `base` that does not exist answers `[]`; a
362
- * `base` that is a file, cannot be read, or lies outside the mode throws. Optional, like `list`.
351
+ * `base` that is a file, cannot be read, or lies outside what the device reaches throws.
352
+ * Optional, like `list`.
363
353
  */
364
354
  scan?(h: SandboxHandle, base: string, opts: {
365
- limits: Pick<SandboxLimits, "mode">;
366
355
  signal: AbortSignal;
367
356
  }): Promise<{
368
357
  path: string;
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Desktop shell capabilities (desktop client spec §8): the shapes of the objects a desktop shell
3
+ * puts in `window.capybaraShell.capabilities` under the keys of `SHELL_CAPABILITY_KEYS`. Types and
4
+ * key constants only; `capybara-hq/clients` implements them. A rejected call carries
5
+ * `{ code: ShellCallError }`.
6
+ */
7
+ /** Capability keys, `name@major`; each value is a key of `SHELL_CAPABILITIES`. */
8
+ export declare const SHELL_CAPABILITY_KEYS: {
9
+ readonly device: "device@1";
10
+ readonly notify: "notify@1";
11
+ readonly openExternal: "openExternal@1";
12
+ readonly signIn: "signIn@1";
13
+ };
14
+ export type KeepAwakeMode = "off" | "while-busy" | "connected";
15
+ export type DeviceConnection = "starting" | "online" | "offline" | "draining" | "stopped";
16
+ /** What this machine is to the deployment the shell shows. */
17
+ export type ThisMachineStatus = {
18
+ state: "not_connected";
19
+ } | {
20
+ state: "connected_elsewhere";
21
+ origin: string;
22
+ } | {
23
+ state: "connected";
24
+ deviceId: string;
25
+ orgId: string;
26
+ mode: "os" | "docker";
27
+ connection: DeviceConnection;
28
+ offlineReason?: string;
29
+ serviceInstalled: boolean;
30
+ keepAwake: {
31
+ mode: KeepAwakeMode;
32
+ held: boolean;
33
+ unavailable?: string;
34
+ };
35
+ lastWakeAt?: string;
36
+ };
37
+ /** One operation running on this machine for the deployment. */
38
+ export interface RunningOperationView {
39
+ tag: string;
40
+ conversationId: string | null;
41
+ accountId: string | null;
42
+ isolation: "restricted" | "full";
43
+ startedAt: string;
44
+ }
45
+ /** The `code` of a rejected shell call. */
46
+ export type ShellCallError = "busy" | "no_activation" | "cancelled" | "failed";
47
+ /** `device@1`: connect this machine to the deployment as a device. */
48
+ export interface DeviceCapabilityV1 {
49
+ status(): Promise<ThisMachineStatus>;
50
+ onStatus(listener: (s: ThisMachineStatus) => void): () => void;
51
+ running(): Promise<RunningOperationView[]>;
52
+ connect(input: {
53
+ orgId: string;
54
+ deviceId?: string;
55
+ }): Promise<"connected" | "cancelled">;
56
+ pause(): Promise<void>;
57
+ resume(): Promise<"resumed" | "cancelled">;
58
+ disconnect(): Promise<void>;
59
+ requestCeiling(input: {
60
+ fullAccess: boolean;
61
+ projectReach: "workspace" | "os-user";
62
+ }): Promise<"applied" | "cancelled">;
63
+ setKeepAwake(mode: KeepAwakeMode): Promise<"applied" | "cancelled">;
64
+ }
65
+ /** `notify@1`: a native notification; `path` is the in-app path opened on click. */
66
+ export interface NotifyCapabilityV1 {
67
+ notify(input: {
68
+ title: string;
69
+ body: string;
70
+ path?: string;
71
+ }): Promise<void>;
72
+ }
73
+ /** `openExternal@1`: open a URL in the system browser. */
74
+ export interface OpenExternalCapabilityV1 {
75
+ open(url: string): Promise<void>;
76
+ }
77
+ /** `signIn@1`: sign in through the system browser (desktop client spec §6.5). */
78
+ export interface SignInCapabilityV1 {
79
+ start(): Promise<"signedIn" | "cancelled">;
80
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Desktop shell capabilities (desktop client spec §8): the shapes of the objects a desktop shell
3
+ * puts in `window.capybaraShell.capabilities` under the keys of `SHELL_CAPABILITY_KEYS`. Types and
4
+ * key constants only; `capybara-hq/clients` implements them. A rejected call carries
5
+ * `{ code: ShellCallError }`.
6
+ */
7
+ /** Capability keys, `name@major`; each value is a key of `SHELL_CAPABILITIES`. */
8
+ export const SHELL_CAPABILITY_KEYS = {
9
+ device: "device@1",
10
+ notify: "notify@1",
11
+ openExternal: "openExternal@1",
12
+ signIn: "signIn@1",
13
+ };
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Shell environment (mobile layout spec §9, desktop client spec): the contract of the global a
3
+ * native shell injects as `window.capybaraShell`, only into the top frame of the deployment's
4
+ * origin. Types and the capability registry only; `capybara-hq/clients` implements it.
5
+ */
6
+ export interface CapybaraShell {
7
+ /** The envelope version; bumped only on an incompatible change of this shape. */
8
+ readonly version: 1;
9
+ /** Which shell: drives nothing but the shell attributes. */
10
+ readonly kind: "desktop" | "mobile";
11
+ /** The operating system, for platform conventions only (traffic lights, back gesture). */
12
+ readonly platform: "macos" | "windows" | "linux" | "ios" | "android";
13
+ /** The shell's own version, for reports and diagnostics; never parsed for features. */
14
+ readonly shellVersion: string;
15
+ /**
16
+ * CSS px the shell's own chrome covers at each edge of the web view, beyond the OS safe areas
17
+ * (macOS traffic lights with `titleBarStyle: hiddenInset`, a native title bar overlay).
18
+ */
19
+ readonly insets: {
20
+ top: number;
21
+ right: number;
22
+ bottom: number;
23
+ left: number;
24
+ };
25
+ /**
26
+ * The rectangle the shell's window controls occupy over the web view, in CSS px from the web
27
+ * view's top-left corner (macOS traffic lights, a Windows caption-button overlay at the right);
28
+ * null when there are none or they are hidden (fullscreen). Modelled on Window Controls
29
+ * Overlay's `titlebar-area-*`. Optional: a shell without overlaid controls omits it.
30
+ */
31
+ readonly controls?: {
32
+ x: number;
33
+ y: number;
34
+ width: number;
35
+ height: number;
36
+ } | null;
37
+ /** Capabilities by `name@major` (as extension points are named, `channel@1`). */
38
+ readonly capabilities: Readonly<Record<string, object>>;
39
+ /**
40
+ * Insets, controls or capabilities changed (fullscreen hides the traffic lights; a capability
41
+ * appears after load). Returns unsubscribe.
42
+ */
43
+ on(event: "change", listener: () => void): () => void;
44
+ }
45
+ declare global {
46
+ interface Window {
47
+ capybaraShell?: CapybaraShell;
48
+ }
49
+ }
50
+ /**
51
+ * The registry of capability names (mobile layout spec §9.2). A new capability is added here
52
+ * (key, owner) by the spec that defines it; the owner names the spec holding its functions.
53
+ */
54
+ export declare const SHELL_CAPABILITIES: readonly {
55
+ key: string;
56
+ owner: string;
57
+ }[];
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Shell environment (mobile layout spec §9, desktop client spec): the contract of the global a
3
+ * native shell injects as `window.capybaraShell`, only into the top frame of the deployment's
4
+ * origin. Types and the capability registry only; `capybara-hq/clients` implements it.
5
+ */
6
+ /**
7
+ * The registry of capability names (mobile layout spec §9.2). A new capability is added here
8
+ * (key, owner) by the spec that defines it; the owner names the spec holding its functions.
9
+ */
10
+ export const SHELL_CAPABILITIES = [
11
+ { key: "device@1", owner: "desktop client spec (2026-11-07-desktop-client-design.md)" },
12
+ { key: "notify@1", owner: "desktop client spec (2026-11-07-desktop-client-design.md)" },
13
+ { key: "openExternal@1", owner: "desktop client spec (2026-11-07-desktop-client-design.md)" },
14
+ { key: "signIn@1", owner: "desktop client spec (2026-11-07-desktop-client-design.md), §6.5" },
15
+ { key: "chrome@1", owner: "mobile layout spec (2026-11-19-mobile-layout-design.md)" },
16
+ ];
@@ -3,6 +3,16 @@ export type UiSlotScope = "conversation" | "agent" | "org" | "platform" | "file"
3
3
  export type UiSlotRole = "guest" | "member" | "admin" | "superAdmin";
4
4
  /** Every slot id of the catalog, in catalog order (UI slots spec §3). */
5
5
  export declare const UI_SLOT_IDS: readonly ["conversation.panel", "conversation.properties.section", "conversation.tool-result.card", "org.page", "file.preview", "agent.detail.section", "org.settings.section", "platform.page", "shell.brand", "shell.overlay", "conversation.empty", "conversation.composer.frame"];
6
+ /**
7
+ * What a slot (or a contribution) becomes on a compact screen (mobile layout spec §5.6): `kept` =
8
+ * rendered in its place, `drawer` = moved into a sheet or pushed page, `hidden` = not rendered.
9
+ * Order of narrowing: `kept` < `drawer` < `hidden`.
10
+ */
11
+ export type CompactForm = "kept" | "drawer" | "hidden";
12
+ /** True when `v` is one of the three compact forms (used to validate manifests). */
13
+ export declare function isCompactForm(v: unknown): v is CompactForm;
14
+ /** A contribution may narrow its slot's compact form, never widen it. */
15
+ export declare function effectiveCompact(slot: CompactForm, contribution?: CompactForm): CompactForm;
6
16
  export type UiSlotId = (typeof UI_SLOT_IDS)[number];
7
17
  /** One slot of the catalog: where extension UI may go and what it receives (UI slots spec §3.1). */
8
18
  export interface UiSlotSpec {
@@ -27,6 +37,8 @@ export interface UiSlotSpec {
27
37
  args: readonly string[];
28
38
  density: "dense" | "regular";
29
39
  icon: "required" | "optional" | "none";
40
+ /** The slot's form on a compact screen (mobile layout spec §5.6). */
41
+ compact: CompactForm;
30
42
  /** Built-in parts a contribution may be placed after; the first is the default. */
31
43
  anchors?: readonly string[];
32
44
  limits?: {