@webpodjs/sdk 0.1.3 → 0.2.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.
Files changed (66) hide show
  1. package/README.md +12 -0
  2. package/dist/agent/backend.d.ts +13 -0
  3. package/dist/agent/backend.js +63 -0
  4. package/dist/agent/backend.js.map +1 -1
  5. package/dist/agent/protocol.d.ts +104 -1
  6. package/dist/agent/protocol.js +90 -0
  7. package/dist/agent/protocol.js.map +1 -1
  8. package/dist/exec/client.d.ts +41 -0
  9. package/dist/exec/client.js +401 -0
  10. package/dist/exec/client.js.map +1 -0
  11. package/dist/exec/frame.d.ts +1 -0
  12. package/dist/exec/frame.js +236 -0
  13. package/dist/exec/frame.js.map +1 -0
  14. package/dist/exec/options.d.ts +39 -0
  15. package/dist/exec/options.js +113 -0
  16. package/dist/exec/options.js.map +1 -0
  17. package/dist/exec/protocol.d.ts +2 -0
  18. package/dist/exec/protocol.js +3 -0
  19. package/dist/exec/protocol.js.map +1 -0
  20. package/dist/exec/wire.d.ts +49 -0
  21. package/dist/exec/wire.js +333 -0
  22. package/dist/exec/wire.js.map +1 -0
  23. package/dist/exec-frame.html +10 -0
  24. package/dist/fs/workspace.js +32 -7
  25. package/dist/fs/workspace.js.map +1 -1
  26. package/dist/host/backend.d.ts +14 -2
  27. package/dist/host/backend.js +69 -15
  28. package/dist/host/backend.js.map +1 -1
  29. package/dist/host/controller.d.ts +9 -0
  30. package/dist/host/controller.js +13 -3
  31. package/dist/host/controller.js.map +1 -1
  32. package/dist/host/devices.d.ts +29 -0
  33. package/dist/host/devices.js +102 -4
  34. package/dist/host/devices.js.map +1 -1
  35. package/dist/host-exec/controller.d.ts +255 -0
  36. package/dist/host-exec/controller.js +1176 -0
  37. package/dist/host-exec/controller.js.map +1 -0
  38. package/dist/host-exec/pipe.d.ts +21 -0
  39. package/dist/host-exec/pipe.js +83 -0
  40. package/dist/host-exec/pipe.js.map +1 -0
  41. package/dist/host-exec/preflight.d.ts +6 -0
  42. package/dist/host-exec/preflight.js +15 -0
  43. package/dist/host-exec/preflight.js.map +1 -0
  44. package/dist/host-exec/protocol.d.ts +340 -0
  45. package/dist/host-exec/protocol.js +16 -0
  46. package/dist/host-exec/protocol.js.map +1 -0
  47. package/dist/host-exec/route.d.ts +22 -0
  48. package/dist/host-exec/route.js +37 -0
  49. package/dist/host-exec/route.js.map +1 -0
  50. package/dist/host-exec/shim.d.ts +28 -0
  51. package/dist/host-exec/shim.js +456 -0
  52. package/dist/host-exec/shim.js.map +1 -0
  53. package/dist/index.d.ts +7 -2
  54. package/dist/index.js +3 -2
  55. package/dist/index.js.map +1 -1
  56. package/dist/net/preview.d.ts +10 -2
  57. package/dist/net/preview.js +8 -0
  58. package/dist/net/preview.js.map +1 -1
  59. package/dist/pod.d.ts +22 -0
  60. package/dist/pod.js +129 -11
  61. package/dist/pod.js.map +1 -1
  62. package/dist/types.d.ts +35 -2
  63. package/dist/version.d.ts +1 -0
  64. package/dist/version.js +4 -0
  65. package/dist/version.js.map +1 -0
  66. package/package.json +6 -4
@@ -0,0 +1,37 @@
1
+ /** node options the host cannot honour (design §11.1): such a process runs in the guest. */
2
+ const GUEST_OPTIONS = /^--(?:inspect|debug|prof|cpu-prof|heap-prof|build-snapshot|experimental-sea-config|perf-|jitless|interpreted-frames-native-stack)/;
3
+ const inside = (path, dir) => path === dir || path.startsWith(dir.endsWith("/") ? dir : `${dir}/`);
4
+ /**
5
+ * Where a process the app starts (`pod.spawn`) runs, once at its start (e4-integration.md §3.1);
6
+ * null when it is not a host program at all (no fallback to report).
7
+ */
8
+ export function routeTopLevel(req, ctx) {
9
+ const name = req.command.includes("/") ? (req.command === ctx.execPath ? "node" : null) : req.command;
10
+ const prefix = name === null ? undefined : ctx.commands[name];
11
+ if (prefix === undefined)
12
+ return null;
13
+ const guest = (reason) => ({ runner: "guest", reason });
14
+ const mode = req.env?.WEBPOD_NODE;
15
+ if (mode === "guest")
16
+ return guest("WEBPOD_NODE=guest");
17
+ if (req.pty)
18
+ return guest("pty");
19
+ if (req.user !== undefined)
20
+ return guest("user");
21
+ const cwd = req.cwd ?? ctx.workspace;
22
+ if (!cwd.startsWith("/") || ![ctx.workspace, ...(ctx.shares ?? [])].some((d) => inside(cwd, d)))
23
+ return guest(`cwd outside ${ctx.workspace}`);
24
+ // node's own options come before the script (or -e / -p); npm's argv has none of node's.
25
+ if (name === "node") {
26
+ for (const a of req.args) {
27
+ if (!a.startsWith("-"))
28
+ break;
29
+ if (GUEST_OPTIONS.test(a))
30
+ return guest(`node option ${a.split("=")[0]}`);
31
+ if (a === "-e" || a === "-p" || a === "--eval" || a === "--print" || a === "-r" || a === "--require" || a === "--")
32
+ break;
33
+ }
34
+ }
35
+ return { runner: "host", argv: [ctx.execPath, ...prefix, ...req.args], cwd };
36
+ }
37
+ //# sourceMappingURL=route.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.js","sourceRoot":"","sources":["../../src/host-exec/route.ts"],"names":[],"mappings":"AAEA,4FAA4F;AAC5F,MAAM,aAAa,GAAG,mIAAmI,CAAC;AAa1J,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,GAAW,EAAE,EAAE,CAAC,IAAI,KAAK,GAAG,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC;AAEnH;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,GAAwB,EAAE,GAAiB;IACvE,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,KAAK,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC;IACtG,MAAM,MAAM,GAAG,IAAI,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G,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YAC1E,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,WAAW,IAAI,CAAC,KAAK,IAAI;gBAAE,MAAM;QAC5H,CAAC;IACH,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,MAAM,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;AAC/E,CAAC"}
@@ -0,0 +1,28 @@
1
+ import type { HostModeChannel } from "../agent/backend.js";
2
+ import { type HostModeMsg, type HostSpawnMsg } from "../agent/protocol.js";
3
+ import type { HostExecController } from "./controller.js";
4
+ export interface HostExecInfo {
5
+ runners: string[];
6
+ mounts: string[];
7
+ excludes: string[];
8
+ }
9
+ /** HostExecInfo and the HostSpawn processes of one agent connection. */
10
+ export declare class ShimBridge {
11
+ #private;
12
+ constructor(c: HostExecController, ch: HostModeChannel);
13
+ /** Sends HostExecInfo when it changed (and the first time). */
14
+ update(info: HostExecInfo): void;
15
+ /** The connection is over: host processes end (the agent ends their shims as by SIGHUP). */
16
+ close(): void;
17
+ /** @internal */
18
+ _send(msg: HostModeMsg): void;
19
+ /** @internal */
20
+ _done(id: number): void;
21
+ /** @internal Records the entry in $HOME/.cache/webpod/host-exec-fallback.json, which the shim reads. */
22
+ _learn(m: HostSpawnMsg, pattern: string): void;
23
+ }
24
+ /**
25
+ * The directories the read-only tree serves, for HostExecInfo's mounts: each package it holds (a node_modules
26
+ * entry), else each file's directory. execPath (always there, empty) is not one.
27
+ */
28
+ export declare function treeRoots(tree: SharedArrayBuffer | ArrayBuffer | undefined, execPath: string): string[];
@@ -0,0 +1,456 @@
1
+ import { DEFAULT_WINDOW, MAX_CHUNK } from "../agent/protocol.js";
2
+ import { SIGNAL_NUMBERS } from "../types.js";
3
+ import { PipeWriter, createPipe } from "./pipe.js";
4
+ /**
5
+ * The guest's node shim (docs/agent-protocol.md "Host mode", e4-integration.md §1.1): node started anywhere in the
6
+ * guest (a terminal, an npm script, a shebang) reaches the host as HostSpawn; it runs in a host node Worker of the
7
+ * controller, with the shim's stdio, signals and terminal, or falls back to the guest's node.
8
+ */
9
+ const SIGKILL = 9;
10
+ /** Signals whose default action is to do nothing: SIGCHLD, SIGCONT, SIGURG, SIGWINCH. */
11
+ const IGNORED = new Set([17, 18, 23, 28]);
12
+ const EXIT_FALLBACK = 70;
13
+ const te = new TextEncoder();
14
+ /** HostExecInfo and the HostSpawn processes of one agent connection. */
15
+ export class ShimBridge {
16
+ #c;
17
+ #ch;
18
+ #procs = new Map();
19
+ #info = "";
20
+ /** Fallback tables being written, one at a time. */
21
+ #learning = Promise.resolve();
22
+ constructor(c, ch) {
23
+ this.#c = c;
24
+ this.#ch = ch;
25
+ ch.listen((m) => this.#on(m));
26
+ void ch.closed.then(() => this.close());
27
+ }
28
+ /** Sends HostExecInfo when it changed (and the first time). */
29
+ update(info) {
30
+ const key = JSON.stringify(info);
31
+ if (key === this.#info)
32
+ return;
33
+ this.#info = key;
34
+ void this.#ch.send({ type: "hostExecInfo", ...info }).catch(() => { });
35
+ }
36
+ /** The connection is over: host processes end (the agent ends their shims as by SIGHUP). */
37
+ close() {
38
+ this.#ch.listen(null);
39
+ for (const p of [...this.#procs.values()])
40
+ p.gone();
41
+ this.#procs.clear();
42
+ }
43
+ /** @internal */
44
+ _send(msg) {
45
+ void this.#ch.send(msg).catch(() => { });
46
+ }
47
+ /** @internal */
48
+ _done(id) {
49
+ this.#procs.delete(id);
50
+ }
51
+ /** @internal Records the entry in $HOME/.cache/webpod/host-exec-fallback.json, which the shim reads. */
52
+ _learn(m, pattern) {
53
+ this.#learning = this.#learning.then(() => learn(this.#c, m, pattern)).then(() => this.#c._reloadTables()).catch((e) => this.#c._log("warn", `host-exec: fallback table: ${e.message}`));
54
+ }
55
+ #on(m) {
56
+ if (m.type === "hostSpawn") {
57
+ if (this.#procs.has(m.id))
58
+ return;
59
+ this.#procs.set(m.id, new ShimProcess(this.#c, this, m));
60
+ return;
61
+ }
62
+ this.#procs.get(m.id)?.handle(m);
63
+ }
64
+ }
65
+ /** One HostSpawn: a host node Worker with the shim's stdio. */
66
+ class ShimProcess {
67
+ #c;
68
+ #b;
69
+ #m;
70
+ #id;
71
+ #state = "starting";
72
+ /** HostStarted sent: from then on there is no HostFallback. Sent lazily, before what the shim must see. */
73
+ #started = false;
74
+ #worker = null;
75
+ #slot = false;
76
+ #size;
77
+ /** Output not sent yet, per stream; bytes sent and not acknowledged. */
78
+ #out = [[], []];
79
+ #unacked = [0, 0];
80
+ #closed = [false, false];
81
+ #exit = null;
82
+ #pipe;
83
+ #stdin;
84
+ #cap;
85
+ #granted = 0;
86
+ #received = 0;
87
+ #writes = Promise.resolve();
88
+ #handled = new Set();
89
+ #entry;
90
+ constructor(c, b, m) {
91
+ this.#c = c;
92
+ this.#b = b;
93
+ this.#m = m;
94
+ this.#id = m.id;
95
+ this.#size = m.size;
96
+ this.#cap = c._options().stdinBytes ?? 1 << 16;
97
+ this.#pipe = createPipe(this.#cap);
98
+ this.#stdin = new PipeWriter(this.#pipe);
99
+ this.#entry = entryOf(m.argv, m.cwd);
100
+ void this.#start();
101
+ }
102
+ async #start() {
103
+ const c = this.#c;
104
+ const m = this.#m;
105
+ if (!c._on())
106
+ return this.#fallback("host mode is off");
107
+ const argv = await this.#argv();
108
+ if (this.#exit)
109
+ return;
110
+ if (typeof argv === "string")
111
+ return this.#fallback(argv);
112
+ try {
113
+ await c._acquire();
114
+ this.#slot = true;
115
+ if (this.#state !== "starting" || this.#exit)
116
+ return this.#end();
117
+ const w = await c._worker({ uid: m.uid, gid: m.gid, groups: m.groups });
118
+ if (this.#state !== "starting" || this.#exit) {
119
+ c._retire(w);
120
+ return this.#end();
121
+ }
122
+ this.#worker = w;
123
+ }
124
+ catch (e) {
125
+ if (this.#state === "starting" && !this.#exit)
126
+ this.#fallback(`host start failed: ${e.message}`);
127
+ else
128
+ this.#end();
129
+ return;
130
+ }
131
+ const w = this.#worker;
132
+ w.pid = m.pid;
133
+ w.ppid = m.ppid;
134
+ w.report = (x) => this.#onReport(x);
135
+ c._register({ pid: m.pid, ppid: m.ppid, kill: (sig) => this.#signal(SIGNAL_NUMBERS[sig] ?? SIGKILL) });
136
+ this.#state = "running";
137
+ w.w.postMessage({
138
+ type: "start",
139
+ argv,
140
+ env: Object.fromEntries(m.env),
141
+ cwd: m.cwd,
142
+ pid: m.pid,
143
+ ppid: m.ppid,
144
+ uid: m.uid,
145
+ gid: m.gid,
146
+ umask: m.umask,
147
+ stdin: this.#pipe,
148
+ tty: m.tty,
149
+ size: this.#size,
150
+ stdinDemand: true,
151
+ guest: c._guestTable(),
152
+ });
153
+ }
154
+ /**
155
+ * The Worker's argv: node's path, then the shim's arguments. A script outside the workspace must be in the
156
+ * read-only tree; a command of the image's bin directory (npm, npx: symlinks the tree does not have) is its
157
+ * script there (hostExec.commands). A string: why it cannot run on the host.
158
+ */
159
+ async #argv() {
160
+ const c = this.#c;
161
+ const exec = c._execPath();
162
+ const argv = [exec, ...this.#m.argv.slice(1)];
163
+ const entry = this.#entry;
164
+ const ws = c._backend().hostSessions?.workspace ?? "/workspace";
165
+ if (entry === null || [ws, ...c._sharePrefixes()].some((d) => inside(entry, d)))
166
+ return argv;
167
+ const tree = await c._tree().catch(() => undefined);
168
+ if (treeHas(tree, entry))
169
+ return argv;
170
+ const bin = exec.slice(0, exec.lastIndexOf("/") + 1);
171
+ const prefix = entry.startsWith(bin) ? c._options().commands?.[entry.slice(bin.length)] ?? DEFAULT_COMMANDS[entry.slice(bin.length)] : undefined;
172
+ if (prefix && prefix.length > 0 && treeHas(tree, prefix[0])) {
173
+ const i = argIndex(this.#m.argv);
174
+ return [...argv.slice(0, i), ...prefix, ...argv.slice(i + 1)];
175
+ }
176
+ return `${entry} is not on the host`;
177
+ }
178
+ handle(m) {
179
+ switch (m.type) {
180
+ case "hostStdin":
181
+ this.#received += m.data.length;
182
+ if (this.#state === "done")
183
+ return;
184
+ this.#writes = this.#writes.then(() => this.#stdin.write(m.data)).catch(() => { });
185
+ return;
186
+ case "hostCloseStdin":
187
+ this.#writes = this.#writes.then(() => this.#stdin.close());
188
+ return;
189
+ case "hostSignal":
190
+ return this.#signal(m.signal);
191
+ case "hostResize":
192
+ this.#size = m.size;
193
+ if (this.#state === "running")
194
+ this.#worker?.w.postMessage({ type: "resize", cols: m.size.cols, rows: m.size.rows });
195
+ return;
196
+ case "hostOutputAck":
197
+ this.#unacked[m.stream - 1] -= m.bytes;
198
+ return this.#pump();
199
+ case "hostOutputClosed": {
200
+ const i = m.stream - 1;
201
+ this.#closed[i] = true;
202
+ this.#out[i] = [];
203
+ if (this.#state === "running")
204
+ this.#worker?.w.postMessage({ type: "out-closed", fd: m.stream });
205
+ return this.#pump();
206
+ }
207
+ }
208
+ }
209
+ /** The agent connection is gone. */
210
+ gone() {
211
+ if (this.#state === "done")
212
+ return;
213
+ this.#state = "done";
214
+ this.#end();
215
+ this.#c._unregister(this.#m.pid);
216
+ }
217
+ #signal(sig) {
218
+ if (this.#state === "done" || this.#exit)
219
+ return;
220
+ if (sig !== SIGKILL && this.#handled.has(sig) && this.#state === "running") {
221
+ this.#worker?.w.postMessage({ type: "signal", signal: sig });
222
+ return;
223
+ }
224
+ if (IGNORED.has(sig))
225
+ return;
226
+ // The default action: the process is gone, killed by sig.
227
+ this.#ended({ code: null, signal: sig });
228
+ }
229
+ #onReport(x) {
230
+ if (this.#state !== "running" || this.#exit)
231
+ return;
232
+ switch (x.type) {
233
+ case "out":
234
+ if (this.#closed[x.fd - 1])
235
+ return;
236
+ this.#begin();
237
+ this.#out[x.fd - 1].push(x.data);
238
+ return this.#pump();
239
+ case "exit":
240
+ // Killed by a signal of its own (process.kill(process.pid)): the shim dies by it too.
241
+ return this.#ended(x.signal ? { code: null, signal: SIGNAL_NUMBERS[x.signal] ?? 15 } : { code: x.code ?? 0, signal: null });
242
+ case "stdin-want":
243
+ return this.#want(x.bytes);
244
+ case "tty":
245
+ this.#begin();
246
+ return this.#b._send({ type: "hostTty", id: this.#id, fd: x.fd, raw: x.raw });
247
+ case "signals":
248
+ this.#handled = new Set(x.signals);
249
+ return;
250
+ case "fallback":
251
+ if (this.#entry)
252
+ this.#b._learn(this.#m, fallbackPattern(this.#entry));
253
+ if (x.rerun && !this.#started)
254
+ return this.#fallback(x.reason);
255
+ return this.#fail(x.reason);
256
+ case "error":
257
+ return this.#fail(`host process failed: ${x.message}`);
258
+ }
259
+ }
260
+ /** stdin credit: what the process waits for, as far as the pipe has room, less what is already granted. */
261
+ #want(bytes) {
262
+ this.#begin();
263
+ const target = Math.min(bytes, this.#cap - this.#stdin.available());
264
+ const outstanding = this.#granted - this.#received;
265
+ if (target <= outstanding)
266
+ return;
267
+ this.#granted += target - outstanding;
268
+ this.#b._send({ type: "hostStdinAck", id: this.#id, bytes: target - outstanding });
269
+ }
270
+ #begin() {
271
+ if (this.#started)
272
+ return;
273
+ this.#started = true;
274
+ this.#b._send({ type: "hostStarted", id: this.#id });
275
+ }
276
+ /** Before HostStarted only: the shim runs the guest's node, which finds stdin untouched. */
277
+ #fallback(reason) {
278
+ this.#c._emit({ pid: this.#m.pid, argv: this.#m.argv, reason, rerun: true });
279
+ this.#state = "done";
280
+ this.#end();
281
+ this.#c._unregister(this.#m.pid);
282
+ this.#b._send({ type: "hostFallback", id: this.#id, reason });
283
+ this.#b._done(this.#id);
284
+ }
285
+ /** A runtime fallback after visible effects: cannot run again (e4-integration.md §3.2). */
286
+ #fail(reason) {
287
+ this.#c._emit({ pid: this.#m.pid, argv: this.#m.argv, reason, rerun: false });
288
+ this.#begin();
289
+ if (!this.#closed[1])
290
+ this.#out[1].push(te.encode(`webpod: ${reason}; this program needs regular node (WEBPOD_NODE=guest, or list it in .webpod/host-exec.json)\n`));
291
+ this.#ended({ code: EXIT_FALLBACK, signal: null });
292
+ }
293
+ /** The process is over: its output still goes out, then HostExited. */
294
+ #ended(status) {
295
+ this.#exit = status;
296
+ this.#begin();
297
+ this.#end();
298
+ this.#c._unregister(this.#m.pid);
299
+ this.#pump();
300
+ }
301
+ /** The host side is over: Worker, slot, children. */
302
+ #end() {
303
+ const c = this.#c;
304
+ c._killChildren(this.#m.pid, "SIGKILL");
305
+ if (this.#worker) {
306
+ c._retire(this.#worker);
307
+ this.#worker = null;
308
+ }
309
+ if (this.#slot) {
310
+ this.#slot = false;
311
+ c._release();
312
+ }
313
+ this.#stdin.close();
314
+ }
315
+ /** Output within each stream's window; HostExited once all of it is sent. */
316
+ #pump() {
317
+ if (this.#state === "done")
318
+ return;
319
+ for (const i of [0, 1]) {
320
+ const q = this.#out[i];
321
+ while (q.length > 0) {
322
+ const n = Math.min(MAX_CHUNK, q[0].length);
323
+ if (this.#unacked[i] + n > DEFAULT_WINDOW)
324
+ break;
325
+ const data = q[0].subarray(0, n);
326
+ if (n === q[0].length)
327
+ q.shift();
328
+ else
329
+ q[0] = q[0].subarray(n);
330
+ this.#unacked[i] += n;
331
+ this.#b._send({ type: "hostOutput", id: this.#id, stream: (i + 1), data });
332
+ }
333
+ }
334
+ const st = this.#exit;
335
+ if (st && this.#out[0].length === 0 && this.#out[1].length === 0) {
336
+ this.#state = "done";
337
+ this.#b._send({ type: "hostExited", id: this.#id, code: st.signal === null ? st.code : null, signal: st.signal });
338
+ this.#b._done(this.#id);
339
+ }
340
+ }
341
+ }
342
+ const NPM = "/usr/local/lib/node_modules/npm/bin";
343
+ const DEFAULT_COMMANDS = { npm: [`${NPM}/npm-cli.js`], npx: [`${NPM}/npx-cli.js`] };
344
+ const inside = (path, dir) => path === dir || path.startsWith(dir.endsWith("/") ? dir : `${dir}/`);
345
+ /** node options that take the next argument as their value (when not written --opt=value). */
346
+ const WITH_VALUE = new Set(["-r", "--require", "--import", "--loader", "--experimental-loader", "-C", "--conditions", "--input-type", "--title", "--env-file", "--stack-size", "--max-old-space-size", "--watch-path", "--redirect-warnings", "--disable-warning", "--openssl-config", "--icu-data-dir"]);
347
+ /** Index in argv of the script, or -1 (-e / -p, or none). */
348
+ function argIndex(argv) {
349
+ for (let i = 1; i < argv.length; i++) {
350
+ const a = argv[i];
351
+ if (a === "-e" || a === "--eval" || a === "-p" || a === "--print")
352
+ return -1;
353
+ if (a === "--")
354
+ return i + 1 < argv.length ? i + 1 : -1;
355
+ if (!a.startsWith("-") || a === "-")
356
+ return a === "-" ? -1 : i;
357
+ if (WITH_VALUE.has(a))
358
+ i++;
359
+ }
360
+ return -1;
361
+ }
362
+ /** The script node would run, absolute; null for -e / -p. */
363
+ function entryOf(argv, cwd) {
364
+ const i = argIndex(argv);
365
+ if (i < 0)
366
+ return null;
367
+ const p = argv[i];
368
+ const parts = [];
369
+ for (const c of (p.startsWith("/") ? p : `${cwd}/${p}`).split("/")) {
370
+ if (c === "..")
371
+ parts.pop();
372
+ else if (c && c !== ".")
373
+ parts.push(c);
374
+ }
375
+ return `/${parts.join("/")}`;
376
+ }
377
+ /**
378
+ * What the fallback table records: the package a script in node_modules is in (the innermost, as the shim's
379
+ * package_of), else the script's path (a glob without wildcards).
380
+ */
381
+ function fallbackPattern(entry) {
382
+ const i = entry.lastIndexOf("/node_modules/");
383
+ if (i < 0)
384
+ return entry;
385
+ const [first, second] = entry.slice(i + "/node_modules/".length).split("/");
386
+ return first.startsWith("@") && second ? `${first}/${second}` : first;
387
+ }
388
+ /** Paths of the read-only tree (src/ro-tree.js format), parsed once per buffer. */
389
+ const TREES = new WeakMap();
390
+ function treePaths(tree) {
391
+ if (!tree)
392
+ return new Set();
393
+ let paths = TREES.get(tree);
394
+ if (paths)
395
+ return paths;
396
+ paths = new Set();
397
+ const dv = new DataView(tree);
398
+ const u8 = new Uint8Array(tree);
399
+ const td = new TextDecoder();
400
+ for (let o = 0; o + 4 <= u8.length;) {
401
+ const pl = dv.getUint32(o, true);
402
+ paths.add(td.decode(u8.slice(o + 4, o + 4 + pl)));
403
+ o += 4 + pl;
404
+ const dl = dv.getUint32(o + 4, true);
405
+ o += 8 + dl;
406
+ }
407
+ TREES.set(tree, paths);
408
+ return paths;
409
+ }
410
+ function treeHas(tree, path) {
411
+ return treePaths(tree).has(path);
412
+ }
413
+ /**
414
+ * The directories the read-only tree serves, for HostExecInfo's mounts: each package it holds (a node_modules
415
+ * entry), else each file's directory. execPath (always there, empty) is not one.
416
+ */
417
+ export function treeRoots(tree, execPath) {
418
+ const roots = new Set();
419
+ for (const p of treePaths(tree)) {
420
+ if (p === execPath)
421
+ continue;
422
+ const m = /^(.*?\/node_modules\/(?:@[^/]+\/)?[^/]+)\//.exec(p);
423
+ roots.add(m ? m[1] : p.slice(0, p.lastIndexOf("/")) || "/");
424
+ }
425
+ const sorted = [...roots].sort();
426
+ return sorted.filter((r) => !sorted.some((o) => o !== r && inside(r, o)));
427
+ }
428
+ /** Adds pattern to the shim user's learned fallback table (written by that user in the guest, not the agent's root). */
429
+ async function learn(c, m, pattern) {
430
+ const home = m.env.find(([k]) => k === "HOME")?.[1];
431
+ if (!home?.startsWith("/"))
432
+ return;
433
+ const file = `${home}/.cache/webpod/host-exec-fallback.json`;
434
+ const backend = c._backend();
435
+ let table = {};
436
+ try {
437
+ table = JSON.parse(await backend.fs.readFile(file, "utf8"));
438
+ }
439
+ catch {
440
+ // none yet, or not JSON: started again
441
+ }
442
+ const guest = Array.isArray(table.guest) ? table.guest.filter((g) => typeof g === "string") : [];
443
+ if (guest.includes(pattern))
444
+ return;
445
+ const text = JSON.stringify({ ...table, guest: [...guest, pattern] }, null, 2) + "\n";
446
+ const p = backend.spawn({ command: "sh", args: ["-c", 'mkdir -p "${1%/*}" && cat > "$1.$$" && mv -f "$1.$$" "$1"', "sh", file], cwd: "/", user: `${m.uid}:${m.gid}` });
447
+ const w = p.stdin.getWriter();
448
+ await w.write(te.encode(text));
449
+ await w.close();
450
+ void p.stdout.cancel().catch(() => { });
451
+ const err = await new Response(p.stderr).text();
452
+ const st = await p.exit;
453
+ if (st.code !== 0)
454
+ throw new Error(`writing ${file}: exit ${st.code ?? st.signal}${err ? `: ${err.trim()}` : ""}`);
455
+ }
456
+ //# sourceMappingURL=shim.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shim.js","sourceRoot":"","sources":["../../src/host-exec/shim.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAA8D,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAC7H,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAGnD;;;;GAIG;AAEH,MAAM,OAAO,GAAG,CAAC,CAAC;AAClB,yFAAyF;AACzF,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;AAC1C,MAAM,aAAa,GAAG,EAAE,CAAC;AACzB,MAAM,EAAE,GAAG,IAAI,WAAW,EAAE,CAAC;AAQ7B,wEAAwE;AACxE,MAAM,OAAO,UAAU;IACZ,EAAE,CAAqB;IACvB,GAAG,CAAkB;IACrB,MAAM,GAAG,IAAI,GAAG,EAAuB,CAAC;IACjD,KAAK,GAAG,EAAE,CAAC;IACX,oDAAoD;IACpD,SAAS,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;IAE7C,YAAY,CAAqB,EAAE,EAAmB;QACpD,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;QACZ,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;QACd,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAC9B,KAAK,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;IAC1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,IAAI,EAAE,CAAC,IAAI,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,WAAW,IAAI,UAAU,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACrH,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- export { Pod } from "./pod.js";
1
+ export { DEFAULT_EXECUTION_ORIGIN, Pod } from "./pod.js";
2
2
  export type { PodNet } from "./pod.js";
3
3
  export type { PodSocket } from "./net/client.js";
4
4
  export type { ExposeOptions } from "./net/preview.js";
5
+ export { DEFAULT_PREVIEW_RELAY } from "./net/preview.js";
5
6
  export type { NetworkOptions, NetworkRoute, NetworkVia } from "./net/options.js";
6
7
  export type { InboundCommand, InboundReply } from "./net/protocol.js";
7
8
  export { WebPodError } from "./errors.js";
@@ -19,6 +20,10 @@ export { exportTar, importTar } from "./fs/tar.js";
19
20
  export type { TarImportResult } from "./fs/tar.js";
20
21
  export type { WorkspaceFs, WorkspaceFsOptions } from "./fs/workspace.js";
21
22
  export { createEngineBackend } from "./host/backend.js";
23
+ export type { RemoteBackend } from "./exec/client.js";
24
+ export type { ExecutionEngineOptions, FsWorkerSpec, NetWorkerSpec } from "./exec/options.js";
25
+ export type { HostExecFallback, HostExecOptions, HostNet, HostExecStatus, HostRunner, HostSessions, HostWorkerLike, PodHostExec } from "./host-exec/controller.js";
26
+ export type { HostSession, HostSessionRef } from "./host-exec/protocol.js";
22
27
  export type { EngineBackend, EngineOptions, PodSnapshots } from "./host/backend.js";
23
28
  export { PodHost, PreparedEngine } from "./host/controller.js";
24
29
  export type { BlockAttachment, BootEvent, ChannelInfo, DeviceSpec, DeviceRings, EngineExit, EngineManifest, EngineWorker, NetAttachment, PodHostOptions, PrepareOptions, ShareAttachment, } from "./host/controller.js";
@@ -30,4 +35,4 @@ export { RingConsumer, RingError, RingProducer, createRing, initRing, waitReadab
30
35
  export type { AgentBackend, AgentBackendOptions, AgentTransport, CaInstallResult } from "./agent/backend.js";
31
36
  export { SIGNAL_NUMBERS } from "./types.js";
32
37
  export type * from "./types.js";
33
- export declare const VERSION = "0.1.3";
38
+ export { VERSION } from "./version.js";
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // @webpodjs/sdk: high-level JS API (Pod.boot / spawn / fs / net).
2
- export { Pod } from "./pod.js";
2
+ export { DEFAULT_EXECUTION_ORIGIN, Pod } from "./pod.js";
3
+ export { DEFAULT_PREVIEW_RELAY } from "./net/preview.js";
3
4
  export { WebPodError } from "./errors.js";
4
5
  export { detectFeatures } from "./features.js";
5
6
  export { ensureCrossOriginIsolation } from "./coi.js";
@@ -15,5 +16,5 @@ export { DeviceWorker, fsWorker, lanIndex, netWorker } from "./host/devices.js";
15
16
  export { ringByteChannel } from "./host/channel.js";
16
17
  export { RingConsumer, RingError, RingProducer, createRing, initRing, waitReadable, waitWritable } from "./host/ring.js";
17
18
  export { SIGNAL_NUMBERS } from "./types.js";
18
- export const VERSION = "0.1.3";
19
+ export { VERSION } from "./version.js";
19
20
  //# 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,kEAAkE;AAClE,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAM/B,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC;AAEtD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;A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,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAMxD,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAe/D,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEhF,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEzH,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAG5C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
@@ -1,4 +1,11 @@
1
1
  import type { NetPortSink } from "./protocol.js";
2
+ /**
3
+ * The SDK's own preview origins for this version (deploy/webpodsandbox-top): an origin per preview,
4
+ * on a site of its own, which any app may embed (docs/deploy.md, "Previews and isolation").
5
+ * Unreleased builds (VERSION 0.0.0, which webpodsandbox.top does not serve) keep previews on the
6
+ * app's origin.
7
+ */
8
+ export declare const DEFAULT_PREVIEW_RELAY: string | false;
2
9
  export interface ExposeOptions {
3
10
  /**
4
11
  * URL of the preview service worker (dist/preview-serviceworker.js, or a combined worker that
@@ -16,8 +23,9 @@ export interface ExposeOptions {
16
23
  * Without `{id}`, previews of all pods share that origin
17
24
  * (`http://localhost:5174/preview-relay.html` next to an app on `http://localhost:5173`).
18
25
  * That origin serves the relay, its preview service worker and a `webpod-preview.json` listing
19
- * the app origins that may use it (`{ "hosts": [...] }`). Without `relay` (or `false`), previews
20
- * are served from this origin: only preview code you trust (docs/deploy.md).
26
+ * the app origins that may use it (`{ "hosts": [...] }`). Default `Pod.defaultPreviewRelay`: the
27
+ * SDK's own preview origins, one per preview (`DEFAULT_PREVIEW_RELAY`). `false`: previews are served
28
+ * from this origin (`serviceWorker`, `scope`): only preview code you trust (docs/deploy.md).
21
29
  */
22
30
  relay?: string | false;
23
31
  }
@@ -1,5 +1,13 @@
1
1
  import { WebPodError } from "../errors.js";
2
+ import { VERSION } from "../version.js";
2
3
  import { PREVIEW_SEGMENT } from "./protocol.js";
4
+ /**
5
+ * The SDK's own preview origins for this version (deploy/webpodsandbox-top): an origin per preview,
6
+ * on a site of its own, which any app may embed (docs/deploy.md, "Previews and isolation").
7
+ * Unreleased builds (VERSION 0.0.0, which webpodsandbox.top does not serve) keep previews on the
8
+ * app's origin.
9
+ */
10
+ export const DEFAULT_PREVIEW_RELAY = VERSION === "0.0.0" ? false : `https://{id}.webpodsandbox.top/v${VERSION}/preview-relay.html`;
3
11
  /** Per-page registry of pods whose previews this page serves on its own origin. */
4
12
  const owned = new Map();
5
13
  let listening = false;