@jeevanand/agent-browserbox-sdk 0.1.1 → 0.3.0

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.
package/README.md CHANGED
@@ -78,6 +78,25 @@ Commands run in BrowserBox's shell (`help` lists them): files and text (`ls`,
78
78
  load from esm.sh) and `pkg install python|git|sqlite|zip|esbuild` for more.
79
79
  It is not bash, and there is no Node.js.
80
80
 
81
+ ### Shell sessions
82
+
83
+ ```ts
84
+ const sh = await box.openShell({ cwd: 'project' });
85
+ await sh.exec('cd src && export MODE=dev');
86
+ await sh.exec('pwd && echo $MODE'); // "…/project/src", "dev"; sh.cwd follows
87
+ ```
88
+
89
+ `sh.run(command)` streams like `box.spawn()`. One command at a time per session.
90
+
91
+ ### More
92
+
93
+ - `box.fs.glob('**/*.ts', { cwd })` → absolute paths · `box.fs.appendFile(path, data)`
94
+ - `box.dev.start('site')` → `{ port, url, root }` · `box.dev.logs(port)` · `box.dev.list()` · `box.dev.stop(port)`
95
+ - `box.processes()` → the process table · `box.killProcess(pid)`
96
+ - `box.share()` → a port for a worker, which calls `BrowserBox.attach(port)` (its own shells, processes and permission answers)
97
+ - `BrowserBox.boot({ site: true })` → the site's own kernel (the one a BrowserBox app on this site uses) instead of a box; `{ site: true, profile: id }` → one of the site's profiles
98
+ - `box.kernelPort()` → a channel to the kernel's full internal protocol, for app UIs; versioned with the runtime
99
+
81
100
  ### `box.teardown()`
82
101
 
83
102
  Removes the frame and fails any call still pending.
package/dist/index.d.ts CHANGED
@@ -1,14 +1,14 @@
1
- import { PROTOCOL_VERSION, type ExecOptions, type ExecResult, type FileStat, type Method, type Methods, type PermissionDecision, type PermissionRequest } from './protocol.js';
2
- export type { ExecOptions, ExecResult, FileStat, PermissionDecision, PermissionRequest };
1
+ import { PROTOCOL_VERSION, type DevLogEntry, type DevServer, type ExecOptions, type ExecResult, type FileStat, type ProcessInfo, type KernelChannel, type Method, type Methods, type PermissionDecision, type PermissionRequest } from './protocol.js';
2
+ export type { DevLogEntry, DevServer, ExecOptions, ExecResult, FileStat, KernelChannel, PermissionDecision, PermissionRequest, ProcessInfo };
3
3
  export { PROTOCOL_VERSION };
4
4
  /** This SDK's version. Always released together with the runtime of the same version. */
5
- export declare const VERSION = "0.1.1";
5
+ export declare const VERSION = "0.3.0";
6
6
  /**
7
7
  * The hosted runtime of exactly this SDK's version. Released runtimes never
8
8
  * change, so a newer runtime can never break an app on this SDK. Self-host it
9
9
  * with @jeevanand/agent-browserbox-runtime.
10
10
  */
11
- export declare const DEFAULT_RUNTIME_URL = "https://jeevanandmaurya.github.io/agent-browserbox/runtime/0.1.1/";
11
+ export declare const DEFAULT_RUNTIME_URL = "https://jeevanandmaurya.github.io/agent-browserbox/runtime/0.3.0/";
12
12
  export type PermissionHandler = (request: PermissionRequest) => PermissionDecision | Promise<PermissionDecision>;
13
13
  export interface BootOptions {
14
14
  /** Base URL of the runtime (the folder holding embed/, kernel/, assets/). Default: the hosted runtime. */
@@ -22,6 +22,18 @@ export interface BootOptions {
22
22
  id?: string;
23
23
  /** 'persistent' (default): files survive reloads. 'memory': everything is gone when the box is torn down. */
24
24
  storage?: 'persistent' | 'memory';
25
+ /**
26
+ * Drive the site's own kernel instead of a box of its own: the one a
27
+ * BrowserBox app hosted on the same site uses, with its files, settings and
28
+ * keys. `id` and `storage` are ignored. (Other sites always get their own,
29
+ * separate storage: browsers partition it by the top-level site.)
30
+ */
31
+ site?: boolean;
32
+ /**
33
+ * With `site`: which profile of the site to drive. Each profile has its own
34
+ * files, settings and keys; omitted or 'default' is the first one.
35
+ */
36
+ profile?: string;
25
37
  /** Element the hidden runtime frame is added to. Default: document.body. */
26
38
  container?: HTMLElement;
27
39
  /**
@@ -41,7 +53,7 @@ interface Sink {
41
53
  out: ReadableStreamDefaultController<string>[];
42
54
  stdout: ReadableStreamDefaultController<string>[];
43
55
  stderr: ReadableStreamDefaultController<string>[];
44
- exit(code: number): void;
56
+ exit(code: number, cwd?: string): void;
45
57
  }
46
58
  /** A running command in the box. */
47
59
  export declare class BoxProcess {
@@ -54,10 +66,31 @@ export declare class BoxProcess {
54
66
  /** Resolves with the exit code (124: timed out, 130: killed). */
55
67
  readonly exit: Promise<number>;
56
68
  /** @internal */
57
- constructor(pid: number, box: BrowserBox, attach: (sink: Sink) => void);
69
+ constructor(pid: number, box: BrowserBox, attach: (sink: Sink) => void, onExit?: (code: number, cwd?: string) => void);
58
70
  /** Stops the command. Resolves false if it had already finished. */
59
71
  kill(): Promise<boolean>;
60
72
  }
73
+ /**
74
+ * A shell session in the box: like a terminal, it keeps its working folder
75
+ * and variables between commands (`cd`, `export`).
76
+ */
77
+ export declare class BoxShell {
78
+ readonly id: number;
79
+ private box;
80
+ /** The working folder, as of the last command. */
81
+ cwd: string;
82
+ /** @internal */
83
+ constructor(id: number, cwd: string, box: BrowserBox);
84
+ /** Starts a command line and streams its output. One command at a time per session. */
85
+ run(command: string, opts?: {
86
+ timeoutMs?: number;
87
+ }): Promise<BoxProcess>;
88
+ /** Runs a command line to completion and returns its output. */
89
+ exec(command: string, opts?: {
90
+ timeoutMs?: number;
91
+ }): Promise<ExecResult>;
92
+ close(): Promise<void>;
93
+ }
61
94
  /** The box's filesystem. Paths are absolute, or relative to the box's home. */
62
95
  export declare class BoxFs {
63
96
  #private;
@@ -79,6 +112,35 @@ export declare class BoxFs {
79
112
  }): Promise<void>;
80
113
  rename(from: string, to: string): Promise<void>;
81
114
  cp(from: string, to: string): Promise<void>;
115
+ /** Creates the file if needed. */
116
+ appendFile(path: string, data: string | Uint8Array): Promise<void>;
117
+ /** Absolute paths of the files under `cwd` (default: home) that match a glob ('**', '*', '?', '{a,b}'). */
118
+ glob(pattern: string, opts?: {
119
+ cwd?: string;
120
+ limit?: number;
121
+ }): Promise<string[]>;
122
+ }
123
+ /**
124
+ * Dev servers for project folders: bundling TS/JSX, reloading on save, and a
125
+ * backend (server.ts) when the project has one. Nothing listens on a real
126
+ * port; the app shows a server's pages through the runtime.
127
+ */
128
+ export declare class BoxDev {
129
+ private box;
130
+ /** @internal */
131
+ constructor(box: BrowserBox);
132
+ /** Starts a server for a project folder, or returns the one already serving it. */
133
+ start(root: string, opts?: {
134
+ port?: number;
135
+ network?: boolean;
136
+ }): Promise<DevServer>;
137
+ stop(port: number): Promise<boolean>;
138
+ list(): Promise<DevServer[]>;
139
+ /** Console output, server logs, build errors and failed requests, oldest first. */
140
+ logs(port: number, opts?: {
141
+ after?: number;
142
+ limit?: number;
143
+ }): Promise<DevLogEntry[]>;
82
144
  }
83
145
  /**
84
146
  * A sandboxed computer in the browser: a filesystem, a shell, and JavaScript,
@@ -92,6 +154,7 @@ export declare class BoxFs {
92
154
  export declare class BrowserBox {
93
155
  #private;
94
156
  readonly fs: BoxFs;
157
+ readonly dev: BoxDev;
95
158
  /** Runtime version. */
96
159
  readonly version: string;
97
160
  /** This box's id. */
@@ -109,6 +172,34 @@ export declare class BrowserBox {
109
172
  exec(command: string, opts?: ExecOptions): Promise<ExecResult>;
110
173
  /** Starts a shell command line and streams its output. */
111
174
  spawn(command: string, opts?: ExecOptions): Promise<BoxProcess>;
175
+ /**
176
+ * Connects to a box shared with you (`box.share()`), e.g. from a worker,
177
+ * which cannot create the runtime's frame itself. `teardown()` then closes
178
+ * only this connection.
179
+ */
180
+ static attach(port: MessagePort, opts?: Pick<BootOptions, 'permissions' | 'timeoutMs'>): Promise<BrowserBox>;
181
+ /**
182
+ * A second connection to this box, with its own shells and processes, to
183
+ * hand to a worker (transfer the port, then `BrowserBox.attach(port)` there).
184
+ */
185
+ share(): Promise<MessagePort>;
186
+ /**
187
+ * A port to the box's kernel itself, speaking its full internal protocol,
188
+ * for app UIs that need more than this API (the BrowserBox app uses it).
189
+ * The protocol is versioned with the runtime: pin the runtime version.
190
+ */
191
+ kernelPort(): Promise<KernelChannel>;
192
+ /** Opens a shell session that keeps its working folder and variables between commands. */
193
+ openShell(opts?: {
194
+ cwd?: string;
195
+ env?: Record<string, string>;
196
+ }): Promise<BoxShell>;
197
+ /** The box's process table: shells, sandboxes, dev servers and so on. */
198
+ processes(): Promise<ProcessInfo[]>;
199
+ /** Stops a process from `processes()`. Resolves false if there was none with that id. */
200
+ killProcess(pid: number): Promise<boolean>;
201
+ /** @internal Wraps a runtime process id whose events are routed here. */
202
+ _process(pid: number, onExit?: (code: number, cwd?: string) => void): BoxProcess;
112
203
  /** Shuts the box down: removes its frame and fails anything still pending. */
113
204
  teardown(): void;
114
205
  /** @internal Low-level call into the runtime. */
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { PROTOCOL_VERSION, } from './protocol.js';
2
2
  export { PROTOCOL_VERSION };
3
3
  /** This SDK's version. Always released together with the runtime of the same version. */
4
- export const VERSION = '0.1.1';
4
+ export const VERSION = '0.3.0';
5
5
  /**
6
6
  * The hosted runtime of exactly this SDK's version. Released runtimes never
7
7
  * change, so a newer runtime can never break an app on this SDK. Self-host it
@@ -28,7 +28,7 @@ export class BoxProcess {
28
28
  /** Resolves with the exit code (124: timed out, 130: killed). */
29
29
  exit;
30
30
  /** @internal */
31
- constructor(pid, box, attach) {
31
+ constructor(pid, box, attach, onExit) {
32
32
  this.pid = pid;
33
33
  this.box = box;
34
34
  const sink = { out: [], stdout: [], stderr: [], exit: () => undefined };
@@ -36,7 +36,7 @@ export class BoxProcess {
36
36
  this.output = stream(sink.out);
37
37
  this.stdout = stream(sink.stdout);
38
38
  this.stderr = stream(sink.stderr);
39
- this.exit = new Promise((resolve) => (sink.exit = resolve));
39
+ this.exit = new Promise((resolve) => (sink.exit = (code, cwd) => (onExit?.(code, cwd), resolve(code))));
40
40
  attach(sink);
41
41
  }
42
42
  /** Stops the command. Resolves false if it had already finished. */
@@ -44,6 +44,55 @@ export class BoxProcess {
44
44
  return this.box.call('kill', this.pid);
45
45
  }
46
46
  }
47
+ /** Reads a stream to the end. */
48
+ async function readAll(stream) {
49
+ let text = '';
50
+ const reader = stream.getReader();
51
+ for (;;) {
52
+ const { value, done } = await reader.read();
53
+ if (done)
54
+ return text;
55
+ text += value;
56
+ }
57
+ }
58
+ /** Collapses progress bars redrawn with \r to their final state, as exec() does. */
59
+ const settle = (text) => text
60
+ .split('\n')
61
+ .map((l) => l.slice(l.lastIndexOf('\r') + 1))
62
+ .join('\n');
63
+ /**
64
+ * A shell session in the box: like a terminal, it keeps its working folder
65
+ * and variables between commands (`cd`, `export`).
66
+ */
67
+ export class BoxShell {
68
+ id;
69
+ box;
70
+ /** The working folder, as of the last command. */
71
+ cwd;
72
+ /** @internal */
73
+ constructor(id, cwd, box) {
74
+ this.id = id;
75
+ this.box = box;
76
+ this.cwd = cwd;
77
+ }
78
+ /** Starts a command line and streams its output. One command at a time per session. */
79
+ async run(command, opts = {}) {
80
+ const pid = await this.box.call('shell.run', this.id, command, opts);
81
+ return this.box._process(pid, (_code, cwd) => {
82
+ if (cwd)
83
+ this.cwd = cwd;
84
+ });
85
+ }
86
+ /** Runs a command line to completion and returns its output. */
87
+ async exec(command, opts = {}) {
88
+ const p = await this.run(command, opts);
89
+ const [stdout, stderr, exitCode] = await Promise.all([readAll(p.stdout), readAll(p.stderr), p.exit]);
90
+ return { exitCode, stdout: settle(stdout), stderr: settle(stderr) };
91
+ }
92
+ close() {
93
+ return this.box.call('shell.close', this.id);
94
+ }
95
+ }
47
96
  /** The box's filesystem. Paths are absolute, or relative to the box's home. */
48
97
  export class BoxFs {
49
98
  box;
@@ -87,6 +136,40 @@ export class BoxFs {
87
136
  cp(from, to) {
88
137
  return this.box.call('fs.cp', this.#abs(from), this.#abs(to));
89
138
  }
139
+ /** Creates the file if needed. */
140
+ appendFile(path, data) {
141
+ return this.box.call('fs.appendFile', this.#abs(path), data);
142
+ }
143
+ /** Absolute paths of the files under `cwd` (default: home) that match a glob ('**', '*', '?', '{a,b}'). */
144
+ glob(pattern, opts = {}) {
145
+ return this.box.call('fs.glob', pattern, this.#abs(opts.cwd ?? '.'), opts.limit);
146
+ }
147
+ }
148
+ /**
149
+ * Dev servers for project folders: bundling TS/JSX, reloading on save, and a
150
+ * backend (server.ts) when the project has one. Nothing listens on a real
151
+ * port; the app shows a server's pages through the runtime.
152
+ */
153
+ export class BoxDev {
154
+ box;
155
+ /** @internal */
156
+ constructor(box) {
157
+ this.box = box;
158
+ }
159
+ /** Starts a server for a project folder, or returns the one already serving it. */
160
+ start(root, opts = {}) {
161
+ return this.box.call('dev.start', { root: root.startsWith('/') ? root : `${this.box.home.replace(/\/$/, '')}/${root}`, ...opts });
162
+ }
163
+ stop(port) {
164
+ return this.box.call('dev.stop', port);
165
+ }
166
+ list() {
167
+ return this.box.call('dev.list');
168
+ }
169
+ /** Console output, server logs, build errors and failed requests, oldest first. */
170
+ logs(port, opts = {}) {
171
+ return this.box.call('dev.logs', port, opts);
172
+ }
90
173
  }
91
174
  /**
92
175
  * A sandboxed computer in the browser: a filesystem, a shell, and JavaScript,
@@ -99,6 +182,7 @@ export class BoxFs {
99
182
  */
100
183
  export class BrowserBox {
101
184
  fs = new BoxFs(this);
185
+ dev = new BoxDev(this);
102
186
  /** Runtime version. */
103
187
  version;
104
188
  /** This box's id. */
@@ -138,7 +222,10 @@ export class BrowserBox {
138
222
  const id = opts.id ?? (memory ? `mem-${crypto.randomUUID()}` : 'default');
139
223
  if (!/^[A-Za-z0-9_-]{1,64}$/.test(id))
140
224
  return Promise.reject(new BoxError(`invalid box id "${id}": use letters, digits, '-' and '_' (at most 64)`));
141
- const src = new URL(`embed/?box=${encodeURIComponent(id)}&storage=${memory ? 'memory' : 'opfs'}`, base);
225
+ if (opts.profile !== undefined && !/^[A-Za-z0-9_-]{1,64}$/.test(opts.profile))
226
+ return Promise.reject(new BoxError(`invalid profile id "${opts.profile}"`));
227
+ const profile = opts.profile && opts.profile !== 'default' ? `&profile=${encodeURIComponent(opts.profile)}` : '';
228
+ const src = new URL(opts.site ? `embed/?site=1${profile}` : `embed/?box=${encodeURIComponent(id)}&storage=${memory ? 'memory' : 'opfs'}`, base);
142
229
  const permissions = typeof opts.permissions === 'function' ? opts.permissions : opts.permissions === 'allow' ? () => 'once' : () => 'deny';
143
230
  const frame = document.createElement('iframe');
144
231
  frame.src = src.href;
@@ -181,13 +268,67 @@ export class BrowserBox {
181
268
  }
182
269
  /** Starts a shell command line and streams its output. */
183
270
  async spawn(command, opts) {
184
- const pid = await this.call('spawn', command, opts);
271
+ return this._process(await this.call('spawn', command, opts));
272
+ }
273
+ /**
274
+ * Connects to a box shared with you (`box.share()`), e.g. from a worker,
275
+ * which cannot create the runtime's frame itself. `teardown()` then closes
276
+ * only this connection.
277
+ */
278
+ static attach(port, opts = {}) {
279
+ const permissions = typeof opts.permissions === 'function' ? opts.permissions : opts.permissions === 'allow' ? () => 'once' : () => 'deny';
280
+ return new Promise((resolve, reject) => {
281
+ const timer = setTimeout(() => reject(new BoxError(`the shared box did not respond within ${opts.timeoutMs ?? 30000} ms`)), opts.timeoutMs ?? 30000);
282
+ port.onmessage = (m) => {
283
+ const msg = m.data;
284
+ if (msg.t === 'refused') {
285
+ clearTimeout(timer);
286
+ reject(new BoxError(`the shared box refused: ${msg.error}`));
287
+ }
288
+ else if (msg.t === 'hello') {
289
+ clearTimeout(timer);
290
+ resolve(new BrowserBox(port, null, msg, permissions));
291
+ }
292
+ };
293
+ port.start();
294
+ });
295
+ }
296
+ /**
297
+ * A second connection to this box, with its own shells and processes, to
298
+ * hand to a worker (transfer the port, then `BrowserBox.attach(port)` there).
299
+ */
300
+ share() {
301
+ return this.call('share');
302
+ }
303
+ /**
304
+ * A port to the box's kernel itself, speaking its full internal protocol,
305
+ * for app UIs that need more than this API (the BrowserBox app uses it).
306
+ * The protocol is versioned with the runtime: pin the runtime version.
307
+ */
308
+ kernelPort() {
309
+ return this.call('kernel.connect');
310
+ }
311
+ /** Opens a shell session that keeps its working folder and variables between commands. */
312
+ async openShell(opts = {}) {
313
+ const { id, cwd } = await this.call('shell.open', opts);
314
+ return new BoxShell(id, cwd, this);
315
+ }
316
+ /** The box's process table: shells, sandboxes, dev servers and so on. */
317
+ processes() {
318
+ return this.call('procs.list');
319
+ }
320
+ /** Stops a process from `processes()`. Resolves false if there was none with that id. */
321
+ killProcess(pid) {
322
+ return this.call('procs.kill', pid);
323
+ }
324
+ /** @internal Wraps a runtime process id whose events are routed here. */
325
+ _process(pid, onExit) {
185
326
  return new BoxProcess(pid, this, (sink) => {
186
327
  this.#sinks.set(pid, sink);
187
328
  for (const ev of this.#early.get(pid) ?? [])
188
329
  this.#deliver(pid, ev);
189
330
  this.#early.delete(pid);
190
- });
331
+ }, onExit);
191
332
  }
192
333
  /** Shuts the box down: removes its frame and fails anything still pending. */
193
334
  teardown() {
@@ -200,7 +341,7 @@ export class BrowserBox {
200
341
  for (const pid of [...this.#sinks.keys()])
201
342
  this.#deliver(pid, { t: 'exit', exitCode: 130 });
202
343
  this.#port.close();
203
- this.#frame.remove();
344
+ this.#frame?.remove();
204
345
  }
205
346
  /** @internal Low-level call into the runtime. */
206
347
  call(method, ...args) {
@@ -226,7 +367,7 @@ export class BrowserBox {
226
367
  case 'output':
227
368
  return this.#route(msg.pid, { t: 'output', stream: msg.stream, data: msg.data });
228
369
  case 'exit':
229
- return this.#route(msg.pid, { t: 'exit', exitCode: msg.exitCode });
370
+ return this.#route(msg.pid, { t: 'exit', exitCode: msg.exitCode, cwd: msg.cwd });
230
371
  case 'permission':
231
372
  void Promise.resolve()
232
373
  .then(() => this.#permissions(msg.request))
@@ -261,7 +402,7 @@ export class BrowserBox {
261
402
  return each([...sink.out, ...sink[ev.stream]], (c) => c.enqueue(ev.data));
262
403
  each([...sink.out, ...sink.stdout, ...sink.stderr], (c) => c.close());
263
404
  this.#sinks.delete(pid);
264
- sink.exit(ev.exitCode);
405
+ sink.exit(ev.exitCode, ev.cwd);
265
406
  }
266
407
  }
267
408
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,GAWjB,MAAM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;QACH,CAAC,CAAC;QACF,IAAI,EAAE,CAAC,CAAC,KAAK,QAAQ;YAAE,OAAO,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;QACjG,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;QACtE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;CACF"}
@@ -15,7 +15,7 @@ export interface Hello {
15
15
  protocol: number;
16
16
  /** Runtime version. */
17
17
  version: string;
18
- /** The box's id. */
18
+ /** The box's id ('site' for the site's own kernel). */
19
19
  id: string;
20
20
  /** The default working directory for commands. */
21
21
  home: string;
@@ -60,6 +60,51 @@ export interface PermissionRequest {
60
60
  /** The exact thing being approved (command, path, URL). */
61
61
  detail: string;
62
62
  }
63
+ /** A shell session: keeps its working folder and variables between commands. */
64
+ export interface ShellInfo {
65
+ id: number;
66
+ cwd: string;
67
+ }
68
+ /** A process in the box's process table (shells, sandboxes, dev servers, …). */
69
+ export interface ProcessInfo {
70
+ pid: number;
71
+ ppid?: number;
72
+ name: string;
73
+ kind: string;
74
+ /** 'running', 'idle', … */
75
+ state: string;
76
+ detail: string;
77
+ /** When it started, ms since the epoch. */
78
+ started: number;
79
+ cpuMs: number;
80
+ memBytes: number;
81
+ }
82
+ /** A dev server the box runs for a project folder. Nothing listens on a real port: `url` is virtual. */
83
+ export interface DevServer {
84
+ port: number;
85
+ root: string;
86
+ url: string;
87
+ /** The project's request handler (server.ts, …), if it has one. */
88
+ backend: string | null;
89
+ network: boolean;
90
+ }
91
+ export interface DevLogEntry {
92
+ /** Increasing per server; pass the last one as `after` to get newer entries. */
93
+ seq: number;
94
+ t: number;
95
+ level: 'log' | 'info' | 'warn' | 'error' | 'debug';
96
+ /** page: the app's console · server: the backend · build: bundling · network: failed requests. */
97
+ source: 'page' | 'server' | 'build' | 'network';
98
+ text: string;
99
+ }
100
+ /** A port to the kernel, and what its client needs to know. */
101
+ export interface KernelChannel {
102
+ port: MessagePort;
103
+ /** The Web Lock the runtime holds while this connection lives. */
104
+ lock: string;
105
+ /** False when the browser has no SharedWorker (one kernel per page). */
106
+ shared: boolean;
107
+ }
63
108
  /** Calls the SDK can make, with their arguments and results. */
64
109
  export interface Methods {
65
110
  info(): Hello;
@@ -75,6 +120,38 @@ export interface Methods {
75
120
  }): void;
76
121
  'fs.rename'(from: string, to: string): void;
77
122
  'fs.cp'(from: string, to: string): void;
123
+ 'fs.appendFile'(path: string, data: string | Uint8Array): void;
124
+ /** Absolute paths of the files under `cwd` that match a glob ('**', '*', '?', '{a,b}'). */
125
+ 'fs.glob'(pattern: string, cwd?: string, limit?: number): string[];
126
+ 'shell.open'(opts?: {
127
+ cwd?: string;
128
+ env?: Record<string, string>;
129
+ }): ShellInfo;
130
+ /** Runs a command line in a shell session; output and exit (with the new cwd) arrive as events. Returns its process id. */
131
+ 'shell.run'(id: number, command: string, opts?: {
132
+ timeoutMs?: number;
133
+ }): number;
134
+ 'shell.close'(id: number): void;
135
+ 'dev.start'(opts: {
136
+ root: string;
137
+ port?: number;
138
+ network?: boolean;
139
+ }): DevServer;
140
+ 'dev.stop'(port: number): boolean;
141
+ 'dev.list'(): DevServer[];
142
+ 'dev.logs'(port: number, opts?: {
143
+ after?: number;
144
+ limit?: number;
145
+ }): DevLogEntry[];
146
+ 'procs.list'(): ProcessInfo[];
147
+ 'procs.kill'(pid: number): boolean;
148
+ /**
149
+ * A port to the box's kernel itself, speaking its full internal protocol:
150
+ * for app UIs that need more than this API. Versioned with the runtime.
151
+ */
152
+ 'kernel.connect'(): KernelChannel;
153
+ /** A second connection to this box (its own shells and processes), e.g. for a worker. */
154
+ share(): MessagePort;
78
155
  exec(command: string, opts?: ExecOptions): ExecResult;
79
156
  /** Starts a command; its output and exit arrive as events. Returns its process id. */
80
157
  spawn(command: string, opts?: ExecOptions): number;
@@ -109,10 +186,13 @@ export type FromRuntime = Hello | Refused | {
109
186
  pid: number;
110
187
  stream: 'stdout' | 'stderr';
111
188
  data: string;
112
- } | {
189
+ }
190
+ /** `cwd`: for commands run in a shell session, its working folder afterwards. */
191
+ | {
113
192
  t: 'exit';
114
193
  pid: number;
115
194
  exitCode: number;
195
+ cwd?: string;
116
196
  } | {
117
197
  t: 'permission';
118
198
  id: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jeevanand/agent-browserbox-sdk",
3
- "version": "0.1.1",
3
+ "version": "0.3.0",
4
4
  "description": "A sandboxed computer in the browser for AI agents: filesystem, shell, JavaScript, Python and WebAssembly, isolated in its own origin. No backend.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/src/index.ts CHANGED
@@ -1,10 +1,14 @@
1
1
  import {
2
2
  PROTOCOL_VERSION,
3
+ type DevLogEntry,
4
+ type DevServer,
3
5
  type ExecOptions,
4
6
  type ExecResult,
5
7
  type FileStat,
8
+ type ProcessInfo,
6
9
  type FromRuntime,
7
10
  type Hello,
11
+ type KernelChannel,
8
12
  type Method,
9
13
  type Methods,
10
14
  type PermissionDecision,
@@ -12,11 +16,11 @@ import {
12
16
  type ToRuntime,
13
17
  } from './protocol.js';
14
18
 
15
- export type { ExecOptions, ExecResult, FileStat, PermissionDecision, PermissionRequest };
19
+ export type { DevLogEntry, DevServer, ExecOptions, ExecResult, FileStat, KernelChannel, PermissionDecision, PermissionRequest, ProcessInfo };
16
20
  export { PROTOCOL_VERSION };
17
21
 
18
22
  /** This SDK's version. Always released together with the runtime of the same version. */
19
- export const VERSION = '0.1.1';
23
+ export const VERSION = '0.3.0';
20
24
 
21
25
  /**
22
26
  * The hosted runtime of exactly this SDK's version. Released runtimes never
@@ -39,6 +43,18 @@ export interface BootOptions {
39
43
  id?: string;
40
44
  /** 'persistent' (default): files survive reloads. 'memory': everything is gone when the box is torn down. */
41
45
  storage?: 'persistent' | 'memory';
46
+ /**
47
+ * Drive the site's own kernel instead of a box of its own: the one a
48
+ * BrowserBox app hosted on the same site uses, with its files, settings and
49
+ * keys. `id` and `storage` are ignored. (Other sites always get their own,
50
+ * separate storage: browsers partition it by the top-level site.)
51
+ */
52
+ site?: boolean;
53
+ /**
54
+ * With `site`: which profile of the site to drive. Each profile has its own
55
+ * files, settings and keys; omitted or 'default' is the first one.
56
+ */
57
+ profile?: string;
42
58
  /** Element the hidden runtime frame is added to. Default: document.body. */
43
59
  container?: HTMLElement;
44
60
  /**
@@ -65,10 +81,10 @@ interface Sink {
65
81
  out: ReadableStreamDefaultController<string>[];
66
82
  stdout: ReadableStreamDefaultController<string>[];
67
83
  stderr: ReadableStreamDefaultController<string>[];
68
- exit(code: number): void;
84
+ exit(code: number, cwd?: string): void;
69
85
  }
70
86
 
71
- type ProcEvent = { t: 'output'; stream: 'stdout' | 'stderr'; data: string } | { t: 'exit'; exitCode: number };
87
+ type ProcEvent = { t: 'output'; stream: 'stdout' | 'stderr'; data: string } | { t: 'exit'; exitCode: number; cwd?: string };
72
88
 
73
89
  /** A running command in the box. */
74
90
  export class BoxProcess {
@@ -84,13 +100,14 @@ export class BoxProcess {
84
100
  readonly pid: number,
85
101
  private box: BrowserBox,
86
102
  attach: (sink: Sink) => void,
103
+ onExit?: (code: number, cwd?: string) => void,
87
104
  ) {
88
105
  const sink: Sink = { out: [], stdout: [], stderr: [], exit: () => undefined };
89
106
  const stream = (list: ReadableStreamDefaultController<string>[]) => new ReadableStream<string>({ start: (c) => void list.push(c) });
90
107
  this.output = stream(sink.out);
91
108
  this.stdout = stream(sink.stdout);
92
109
  this.stderr = stream(sink.stderr);
93
- this.exit = new Promise((resolve) => (sink.exit = resolve));
110
+ this.exit = new Promise((resolve) => (sink.exit = (code, cwd) => (onExit?.(code, cwd), resolve(code))));
94
111
  attach(sink);
95
112
  }
96
113
 
@@ -100,6 +117,61 @@ export class BoxProcess {
100
117
  }
101
118
  }
102
119
 
120
+ /** Reads a stream to the end. */
121
+ async function readAll(stream: ReadableStream<string>): Promise<string> {
122
+ let text = '';
123
+ const reader = stream.getReader();
124
+ for (;;) {
125
+ const { value, done } = await reader.read();
126
+ if (done) return text;
127
+ text += value;
128
+ }
129
+ }
130
+
131
+ /** Collapses progress bars redrawn with \r to their final state, as exec() does. */
132
+ const settle = (text: string) =>
133
+ text
134
+ .split('\n')
135
+ .map((l) => l.slice(l.lastIndexOf('\r') + 1))
136
+ .join('\n');
137
+
138
+ /**
139
+ * A shell session in the box: like a terminal, it keeps its working folder
140
+ * and variables between commands (`cd`, `export`).
141
+ */
142
+ export class BoxShell {
143
+ /** The working folder, as of the last command. */
144
+ cwd: string;
145
+
146
+ /** @internal */
147
+ constructor(
148
+ readonly id: number,
149
+ cwd: string,
150
+ private box: BrowserBox,
151
+ ) {
152
+ this.cwd = cwd;
153
+ }
154
+
155
+ /** Starts a command line and streams its output. One command at a time per session. */
156
+ async run(command: string, opts: { timeoutMs?: number } = {}): Promise<BoxProcess> {
157
+ const pid = await this.box.call('shell.run', this.id, command, opts);
158
+ return this.box._process(pid, (_code, cwd) => {
159
+ if (cwd) this.cwd = cwd;
160
+ });
161
+ }
162
+
163
+ /** Runs a command line to completion and returns its output. */
164
+ async exec(command: string, opts: { timeoutMs?: number } = {}): Promise<ExecResult> {
165
+ const p = await this.run(command, opts);
166
+ const [stdout, stderr, exitCode] = await Promise.all([readAll(p.stdout), readAll(p.stderr), p.exit]);
167
+ return { exitCode, stdout: settle(stdout), stderr: settle(stderr) };
168
+ }
169
+
170
+ close(): Promise<void> {
171
+ return this.box.call('shell.close', this.id);
172
+ }
173
+ }
174
+
103
175
  /** The box's filesystem. Paths are absolute, or relative to the box's home. */
104
176
  export class BoxFs {
105
177
  /** @internal */
@@ -142,6 +214,39 @@ export class BoxFs {
142
214
  cp(from: string, to: string): Promise<void> {
143
215
  return this.box.call('fs.cp', this.#abs(from), this.#abs(to));
144
216
  }
217
+ /** Creates the file if needed. */
218
+ appendFile(path: string, data: string | Uint8Array): Promise<void> {
219
+ return this.box.call('fs.appendFile', this.#abs(path), data);
220
+ }
221
+ /** Absolute paths of the files under `cwd` (default: home) that match a glob ('**', '*', '?', '{a,b}'). */
222
+ glob(pattern: string, opts: { cwd?: string; limit?: number } = {}): Promise<string[]> {
223
+ return this.box.call('fs.glob', pattern, this.#abs(opts.cwd ?? '.'), opts.limit);
224
+ }
225
+ }
226
+
227
+ /**
228
+ * Dev servers for project folders: bundling TS/JSX, reloading on save, and a
229
+ * backend (server.ts) when the project has one. Nothing listens on a real
230
+ * port; the app shows a server's pages through the runtime.
231
+ */
232
+ export class BoxDev {
233
+ /** @internal */
234
+ constructor(private box: BrowserBox) {}
235
+
236
+ /** Starts a server for a project folder, or returns the one already serving it. */
237
+ start(root: string, opts: { port?: number; network?: boolean } = {}): Promise<DevServer> {
238
+ return this.box.call('dev.start', { root: root.startsWith('/') ? root : `${this.box.home.replace(/\/$/, '')}/${root}`, ...opts });
239
+ }
240
+ stop(port: number): Promise<boolean> {
241
+ return this.box.call('dev.stop', port);
242
+ }
243
+ list(): Promise<DevServer[]> {
244
+ return this.box.call('dev.list');
245
+ }
246
+ /** Console output, server logs, build errors and failed requests, oldest first. */
247
+ logs(port: number, opts: { after?: number; limit?: number } = {}): Promise<DevLogEntry[]> {
248
+ return this.box.call('dev.logs', port, opts);
249
+ }
145
250
  }
146
251
 
147
252
  /**
@@ -155,6 +260,7 @@ export class BoxFs {
155
260
  */
156
261
  export class BrowserBox {
157
262
  readonly fs = new BoxFs(this);
263
+ readonly dev = new BoxDev(this);
158
264
  /** Runtime version. */
159
265
  readonly version: string;
160
266
  /** This box's id. */
@@ -167,7 +273,7 @@ export class BrowserBox {
167
273
  readonly storage: 'opfs' | 'memory';
168
274
 
169
275
  #port: MessagePort;
170
- #frame: HTMLIFrameElement;
276
+ #frame: HTMLIFrameElement | null;
171
277
  #permissions: PermissionHandler;
172
278
  #nextId = 1;
173
279
  #calls = new Map<number, { resolve(v: unknown): void; reject(e: Error): void }>();
@@ -176,7 +282,7 @@ export class BrowserBox {
176
282
  #early = new Map<number, ProcEvent[]>();
177
283
  #closed: BoxError | null = null;
178
284
 
179
- private constructor(port: MessagePort, frame: HTMLIFrameElement, hello: Hello, permissions: PermissionHandler) {
285
+ private constructor(port: MessagePort, frame: HTMLIFrameElement | null, hello: Hello, permissions: PermissionHandler) {
180
286
  this.#port = port;
181
287
  this.#frame = frame;
182
288
  this.#permissions = permissions;
@@ -195,7 +301,9 @@ export class BrowserBox {
195
301
  const memory = opts.storage === 'memory';
196
302
  const id = opts.id ?? (memory ? `mem-${crypto.randomUUID()}` : 'default');
197
303
  if (!/^[A-Za-z0-9_-]{1,64}$/.test(id)) return Promise.reject(new BoxError(`invalid box id "${id}": use letters, digits, '-' and '_' (at most 64)`));
198
- const src = new URL(`embed/?box=${encodeURIComponent(id)}&storage=${memory ? 'memory' : 'opfs'}`, base);
304
+ if (opts.profile !== undefined && !/^[A-Za-z0-9_-]{1,64}$/.test(opts.profile)) return Promise.reject(new BoxError(`invalid profile id "${opts.profile}"`));
305
+ const profile = opts.profile && opts.profile !== 'default' ? `&profile=${encodeURIComponent(opts.profile)}` : '';
306
+ const src = new URL(opts.site ? `embed/?site=1${profile}` : `embed/?box=${encodeURIComponent(id)}&storage=${memory ? 'memory' : 'opfs'}`, base);
199
307
  const permissions: PermissionHandler = typeof opts.permissions === 'function' ? opts.permissions : opts.permissions === 'allow' ? () => 'once' : () => 'deny';
200
308
 
201
309
  const frame = document.createElement('iframe');
@@ -239,14 +347,79 @@ export class BrowserBox {
239
347
 
240
348
  /** Starts a shell command line and streams its output. */
241
349
  async spawn(command: string, opts?: ExecOptions): Promise<BoxProcess> {
242
- const pid = await this.call('spawn', command, opts);
243
- return new BoxProcess(pid, this, (sink) => {
244
- this.#sinks.set(pid, sink);
245
- for (const ev of this.#early.get(pid) ?? []) this.#deliver(pid, ev);
246
- this.#early.delete(pid);
350
+ return this._process(await this.call('spawn', command, opts));
351
+ }
352
+
353
+ /**
354
+ * Connects to a box shared with you (`box.share()`), e.g. from a worker,
355
+ * which cannot create the runtime's frame itself. `teardown()` then closes
356
+ * only this connection.
357
+ */
358
+ static attach(port: MessagePort, opts: Pick<BootOptions, 'permissions' | 'timeoutMs'> = {}): Promise<BrowserBox> {
359
+ const permissions: PermissionHandler = typeof opts.permissions === 'function' ? opts.permissions : opts.permissions === 'allow' ? () => 'once' : () => 'deny';
360
+ return new Promise((resolve, reject) => {
361
+ const timer = setTimeout(() => reject(new BoxError(`the shared box did not respond within ${opts.timeoutMs ?? 30000} ms`)), opts.timeoutMs ?? 30000);
362
+ port.onmessage = (m: MessageEvent<FromRuntime>) => {
363
+ const msg = m.data;
364
+ if (msg.t === 'refused') {
365
+ clearTimeout(timer);
366
+ reject(new BoxError(`the shared box refused: ${msg.error}`));
367
+ } else if (msg.t === 'hello') {
368
+ clearTimeout(timer);
369
+ resolve(new BrowserBox(port, null, msg, permissions));
370
+ }
371
+ };
372
+ port.start();
247
373
  });
248
374
  }
249
375
 
376
+ /**
377
+ * A second connection to this box, with its own shells and processes, to
378
+ * hand to a worker (transfer the port, then `BrowserBox.attach(port)` there).
379
+ */
380
+ share(): Promise<MessagePort> {
381
+ return this.call('share');
382
+ }
383
+
384
+ /**
385
+ * A port to the box's kernel itself, speaking its full internal protocol,
386
+ * for app UIs that need more than this API (the BrowserBox app uses it).
387
+ * The protocol is versioned with the runtime: pin the runtime version.
388
+ */
389
+ kernelPort(): Promise<KernelChannel> {
390
+ return this.call('kernel.connect');
391
+ }
392
+
393
+ /** Opens a shell session that keeps its working folder and variables between commands. */
394
+ async openShell(opts: { cwd?: string; env?: Record<string, string> } = {}): Promise<BoxShell> {
395
+ const { id, cwd } = await this.call('shell.open', opts);
396
+ return new BoxShell(id, cwd, this);
397
+ }
398
+
399
+ /** The box's process table: shells, sandboxes, dev servers and so on. */
400
+ processes(): Promise<ProcessInfo[]> {
401
+ return this.call('procs.list');
402
+ }
403
+
404
+ /** Stops a process from `processes()`. Resolves false if there was none with that id. */
405
+ killProcess(pid: number): Promise<boolean> {
406
+ return this.call('procs.kill', pid);
407
+ }
408
+
409
+ /** @internal Wraps a runtime process id whose events are routed here. */
410
+ _process(pid: number, onExit?: (code: number, cwd?: string) => void): BoxProcess {
411
+ return new BoxProcess(
412
+ pid,
413
+ this,
414
+ (sink) => {
415
+ this.#sinks.set(pid, sink);
416
+ for (const ev of this.#early.get(pid) ?? []) this.#deliver(pid, ev);
417
+ this.#early.delete(pid);
418
+ },
419
+ onExit,
420
+ );
421
+ }
422
+
250
423
  /** Shuts the box down: removes its frame and fails anything still pending. */
251
424
  teardown(): void {
252
425
  if (this.#closed) return;
@@ -255,7 +428,7 @@ export class BrowserBox {
255
428
  this.#calls.clear();
256
429
  for (const pid of [...this.#sinks.keys()]) this.#deliver(pid, { t: 'exit', exitCode: 130 });
257
430
  this.#port.close();
258
- this.#frame.remove();
431
+ this.#frame?.remove();
259
432
  }
260
433
 
261
434
  /** @internal Low-level call into the runtime. */
@@ -280,7 +453,7 @@ export class BrowserBox {
280
453
  case 'output':
281
454
  return this.#route(msg.pid, { t: 'output', stream: msg.stream, data: msg.data });
282
455
  case 'exit':
283
- return this.#route(msg.pid, { t: 'exit', exitCode: msg.exitCode });
456
+ return this.#route(msg.pid, { t: 'exit', exitCode: msg.exitCode, cwd: msg.cwd });
284
457
  case 'permission':
285
458
  void Promise.resolve()
286
459
  .then(() => this.#permissions(msg.request))
@@ -313,6 +486,6 @@ export class BrowserBox {
313
486
  if (ev.t === 'output') return each([...sink.out, ...sink[ev.stream]], (c) => c.enqueue(ev.data));
314
487
  each([...sink.out, ...sink.stdout, ...sink.stderr], (c) => c.close());
315
488
  this.#sinks.delete(pid);
316
- sink.exit(ev.exitCode);
489
+ sink.exit(ev.exitCode, ev.cwd);
317
490
  }
318
491
  }
package/src/protocol.ts CHANGED
@@ -16,7 +16,7 @@ export interface Hello {
16
16
  protocol: number;
17
17
  /** Runtime version. */
18
18
  version: string;
19
- /** The box's id. */
19
+ /** The box's id ('site' for the site's own kernel). */
20
20
  id: string;
21
21
  /** The default working directory for commands. */
22
22
  home: string;
@@ -68,6 +68,56 @@ export interface PermissionRequest {
68
68
  detail: string;
69
69
  }
70
70
 
71
+ /** A shell session: keeps its working folder and variables between commands. */
72
+ export interface ShellInfo {
73
+ id: number;
74
+ cwd: string;
75
+ }
76
+
77
+ /** A process in the box's process table (shells, sandboxes, dev servers, …). */
78
+ export interface ProcessInfo {
79
+ pid: number;
80
+ ppid?: number;
81
+ name: string;
82
+ kind: string;
83
+ /** 'running', 'idle', … */
84
+ state: string;
85
+ detail: string;
86
+ /** When it started, ms since the epoch. */
87
+ started: number;
88
+ cpuMs: number;
89
+ memBytes: number;
90
+ }
91
+
92
+ /** A dev server the box runs for a project folder. Nothing listens on a real port: `url` is virtual. */
93
+ export interface DevServer {
94
+ port: number;
95
+ root: string;
96
+ url: string;
97
+ /** The project's request handler (server.ts, …), if it has one. */
98
+ backend: string | null;
99
+ network: boolean;
100
+ }
101
+
102
+ export interface DevLogEntry {
103
+ /** Increasing per server; pass the last one as `after` to get newer entries. */
104
+ seq: number;
105
+ t: number;
106
+ level: 'log' | 'info' | 'warn' | 'error' | 'debug';
107
+ /** page: the app's console · server: the backend · build: bundling · network: failed requests. */
108
+ source: 'page' | 'server' | 'build' | 'network';
109
+ text: string;
110
+ }
111
+
112
+ /** A port to the kernel, and what its client needs to know. */
113
+ export interface KernelChannel {
114
+ port: MessagePort;
115
+ /** The Web Lock the runtime holds while this connection lives. */
116
+ lock: string;
117
+ /** False when the browser has no SharedWorker (one kernel per page). */
118
+ shared: boolean;
119
+ }
120
+
71
121
  /** Calls the SDK can make, with their arguments and results. */
72
122
  export interface Methods {
73
123
  info(): Hello;
@@ -81,6 +131,26 @@ export interface Methods {
81
131
  'fs.rm'(path: string, opts?: { recursive?: boolean }): void;
82
132
  'fs.rename'(from: string, to: string): void;
83
133
  'fs.cp'(from: string, to: string): void;
134
+ 'fs.appendFile'(path: string, data: string | Uint8Array): void;
135
+ /** Absolute paths of the files under `cwd` that match a glob ('**', '*', '?', '{a,b}'). */
136
+ 'fs.glob'(pattern: string, cwd?: string, limit?: number): string[];
137
+ 'shell.open'(opts?: { cwd?: string; env?: Record<string, string> }): ShellInfo;
138
+ /** Runs a command line in a shell session; output and exit (with the new cwd) arrive as events. Returns its process id. */
139
+ 'shell.run'(id: number, command: string, opts?: { timeoutMs?: number }): number;
140
+ 'shell.close'(id: number): void;
141
+ 'dev.start'(opts: { root: string; port?: number; network?: boolean }): DevServer;
142
+ 'dev.stop'(port: number): boolean;
143
+ 'dev.list'(): DevServer[];
144
+ 'dev.logs'(port: number, opts?: { after?: number; limit?: number }): DevLogEntry[];
145
+ 'procs.list'(): ProcessInfo[];
146
+ 'procs.kill'(pid: number): boolean;
147
+ /**
148
+ * A port to the box's kernel itself, speaking its full internal protocol:
149
+ * for app UIs that need more than this API. Versioned with the runtime.
150
+ */
151
+ 'kernel.connect'(): KernelChannel;
152
+ /** A second connection to this box (its own shells and processes), e.g. for a worker. */
153
+ share(): MessagePort;
84
154
  exec(command: string, opts?: ExecOptions): ExecResult;
85
155
  /** Starts a command; its output and exit arrive as events. Returns its process id. */
86
156
  spawn(command: string, opts?: ExecOptions): number;
@@ -101,5 +171,6 @@ export type FromRuntime =
101
171
  | { t: 'result'; id: number; ok: true; value: unknown }
102
172
  | { t: 'result'; id: number; ok: false; error: string; code?: string }
103
173
  | { t: 'output'; pid: number; stream: 'stdout' | 'stderr'; data: string }
104
- | { t: 'exit'; pid: number; exitCode: number }
174
+ /** `cwd`: for commands run in a shell session, its working folder afterwards. */
175
+ | { t: 'exit'; pid: number; exitCode: number; cwd?: string }
105
176
  | { t: 'permission'; id: number; request: PermissionRequest };