@vite-hub/sandbox 0.0.4 → 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.
Files changed (67) hide show
  1. package/README.md +395 -37
  2. package/dist/abortable-CR01hzfi.js +57 -0
  3. package/dist/cloudflare-Cog_r2Me.js +910 -0
  4. package/dist/cloudflare-env-lookup-DzI6Xv1Y.js +16 -0
  5. package/dist/cloudflare-failure-CFQhalfh.js +50 -0
  6. package/dist/container-CqfD8yuE.js +868 -0
  7. package/dist/crabbox-sbV3Zjuo.js +1110 -0
  8. package/dist/error-diagnostics-5QT_BjbQ.js +354 -0
  9. package/dist/error-diagnostics-BJtLRL9w.js +536 -0
  10. package/dist/file-listing-CHtRrfo1.js +26 -0
  11. package/dist/file-lock-D0-XPogS.js +74 -0
  12. package/dist/index-DsoQAUb7.d.ts +594 -0
  13. package/dist/index.d.ts +2 -69
  14. package/dist/index.js +281 -1182
  15. package/dist/internal/cloudflare.d.ts +176 -0
  16. package/dist/internal/cloudflare.js +8 -0
  17. package/dist/internal/host-toolchain.d.ts +22 -0
  18. package/dist/internal/host-toolchain.js +96 -0
  19. package/dist/internal/vercel.d.ts +4 -0
  20. package/dist/internal/vercel.js +8 -0
  21. package/dist/invariant-DolT9EEx.js +22 -0
  22. package/dist/module-types-B0LQ5H2S.js +7 -0
  23. package/dist/module-types-DCeJbS9Z.d.ts +110 -0
  24. package/dist/process-sweep-CMaujWE5.js +33 -0
  25. package/dist/provider-resolution-C6AQzuFG.js +133 -0
  26. package/dist/remote-70ZVZZlq.js +265 -0
  27. package/dist/rolldown-runtime-8H4AJuhK.js +14 -0
  28. package/dist/runtime-DHp6ImeP.js +32 -0
  29. package/dist/runtime-type-Deo4qzxN.js +9 -0
  30. package/dist/session-e0lyzjJ3.js +338 -0
  31. package/dist/shell-quote-Q3u3plif.js +6 -0
  32. package/dist/size-7AkVwGZb.js +118 -0
  33. package/dist/ssh.d.ts +63 -0
  34. package/dist/ssh.js +286 -0
  35. package/dist/task/index.d.ts +69 -0
  36. package/dist/task/index.js +1414 -0
  37. package/dist/task/runtime/empty-registry.d.ts +6 -0
  38. package/dist/{runtime → task/runtime}/empty-registry.js +2 -2
  39. package/dist/task/runtime/provider-loader.d.ts +18 -0
  40. package/dist/task/runtime/provider-loader.js +16 -0
  41. package/dist/task/runtime/providers/cloudflare.d.ts +14 -0
  42. package/dist/task/runtime/providers/cloudflare.js +27 -0
  43. package/dist/task/runtime/providers/vercel.d.ts +12 -0
  44. package/dist/task/runtime/providers/vercel.js +85 -0
  45. package/dist/task/runtime/state.d.ts +27 -0
  46. package/dist/task/runtime/state.js +82 -0
  47. package/dist/task/vite.d.ts +486 -0
  48. package/dist/task/vite.js +3966 -0
  49. package/dist/toolchain-BIVGMRty.js +528 -0
  50. package/dist/trusted-host-kxkpaQcs.js +714 -0
  51. package/dist/vercel-BGGrNpza.js +352 -0
  52. package/package.json +105 -51
  53. package/dist/cloudflare-env-QQV4uzCT.js +0 -14
  54. package/dist/module-types-DKYItiOu.d.ts +0 -93
  55. package/dist/module-types-Dj1MFmHT.js +0 -7
  56. package/dist/provider-loader-D0UihePq.d.ts +0 -21
  57. package/dist/runtime/empty-registry.d.ts +0 -6
  58. package/dist/runtime/provider-loader.d.ts +0 -2
  59. package/dist/runtime/provider-loader.js +0 -15
  60. package/dist/runtime/providers/cloudflare.d.ts +0 -29
  61. package/dist/runtime/providers/cloudflare.js +0 -25
  62. package/dist/runtime/providers/vercel.d.ts +0 -121
  63. package/dist/runtime/providers/vercel.js +0 -51
  64. package/dist/runtime/state.d.ts +0 -26
  65. package/dist/runtime/state.js +0 -72
  66. package/dist/vite.d.ts +0 -48
  67. package/dist/vite.js +0 -3324
@@ -0,0 +1,536 @@
1
+ import { defineDiagnostics } from "nostics";
2
+ //#region src/error-diagnostics.ts
3
+ const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
4
+ const sandboxErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
5
+ docsBase: "https://vitehub.dev/docs/sandbox/diagnostics",
6
+ codes: {
7
+ SANDBOX_R0020: {
8
+ ...dynamicError,
9
+ fix: "Pass the Durable Object binding of the Worker as `namespace`, for example `runtime: { kind: \"cloudflare\", namespace: env.SANDBOX }`."
10
+ },
11
+ SANDBOX_R0022: {
12
+ ...dynamicError,
13
+ fix: "Check that the Container user can write the parent of the path that the message names. To create missing parents, pass `{ recursive: true }` to `session.files.mkdir()`."
14
+ },
15
+ SANDBOX_R0023: {
16
+ ...dynamicError,
17
+ fix: "Read the `mkdir` error in the message. Check that the Container user can write the parent directory, or pass `{ recursive: true }` to `session.files.mkdir()` to create missing parents."
18
+ },
19
+ SANDBOX_R0024: {
20
+ ...dynamicError,
21
+ fix: "Check that the source that the message names exists, and that the Container user can write the destination directory of `session.files.move()`."
22
+ },
23
+ SANDBOX_R0025: {
24
+ ...dynamicError,
25
+ fix: "The file exists, but Cloudflare could not read it. Check that the Container user can read the path that the message names, then call `session.files.read()` again."
26
+ },
27
+ SANDBOX_R0026: {
28
+ ...dynamicError,
29
+ fix: "Check that the path that the message names is a file and that the Container user can write its directory. To remove a directory and its contents, pass `{ recursive: true }` to `session.files.remove()`."
30
+ },
31
+ SANDBOX_R0027: {
32
+ ...dynamicError,
33
+ fix: "Read the `rm` error in the message. To remove a directory that is not empty, pass `{ recursive: true }` to `session.files.remove()`. Check that the Container user can write the parent directory."
34
+ },
35
+ SANDBOX_R0028: {
36
+ ...dynamicError,
37
+ fix: "Check that the path that the message names is not a directory, and that the Container user can write its parent directory."
38
+ },
39
+ SANDBOX_R0029: {
40
+ ...dynamicError,
41
+ fix: "Read the `find` error in the message. Pass a directory that exists to `session.files.list()`, and use a Container image that has GNU `find`."
42
+ },
43
+ SANDBOX_R0030: {
44
+ ...dynamicError,
45
+ fix: "Give the custom runtime a `name` other than `cloudflare`, `container`, `crabbox`, `trusted-host`, or `vercel`. To use a built-in runtime, pass its name or tagged object, such as `runtime: { kind: \"crabbox\" }`."
46
+ },
47
+ SANDBOX_R0031: {
48
+ ...dynamicError,
49
+ fix: "Set `runtime` to `\"crabbox\"`, `\"trusted-host\"`, or `\"vercel\"`, or to a tagged object such as `{ kind: \"cloudflare\", namespace }`. Check the spelling."
50
+ },
51
+ SANDBOX_R0032: {
52
+ ...dynamicError,
53
+ fix: "Set `runtime` in the Sandbox definition, for example `runtime: \"trusted-host\"`, `runtime: { kind: \"cloudflare\", namespace }`, or a custom runtime object with `name`, `prepare`, and `open`."
54
+ },
55
+ SANDBOX_R0033: {
56
+ ...dynamicError,
57
+ fix: "Set `runtime.kind` to `\"crabbox\"`, `\"trusted-host\"`, `\"cloudflare\"`, `\"container\"`, or `\"vercel\"`. Check the spelling."
58
+ },
59
+ SANDBOX_R0034: {
60
+ ...dynamicError,
61
+ fix: "Pass a Sandbox definition object with a `runtime` to `resolveSandbox()`, for example `resolveSandbox({ runtime: \"trusted-host\" }, context)`."
62
+ },
63
+ SANDBOX_R0035: {
64
+ ...dynamicError,
65
+ fix: "Remove `cwd` or `checkout` from the Sandbox definition. Use `cwd` for a directory that you own, or `checkout` for a disposable Git checkout."
66
+ },
67
+ SANDBOX_R0036: {
68
+ ...dynamicError,
69
+ fix: "Return an `executionAuthority` object from the `prepare()` method of the custom runtime that the message names, with `credentials`, `environment`, `filesystem`, `isolation`, `network`, and `processes`."
70
+ },
71
+ SANDBOX_R0037: {
72
+ ...dynamicError,
73
+ fix: "Return `home.state` from the `prepare()` method of the custom runtime that the message names, with a non-empty `identity` for each `home.state` path of the Sandbox definition."
74
+ },
75
+ SANDBOX_R0038: {
76
+ ...dynamicError,
77
+ fix: "Set `home` in the Sandbox definition to an object with `files` or `state`, for example `home: { files: { \".gitconfig\": { from: \".vitehub/sandbox/gitconfig\" } } }`."
78
+ },
79
+ SANDBOX_R0039: {
80
+ ...dynamicError,
81
+ fix: "Rename the `env` key that the message names. A name starts with a letter or `_` and has only letters, digits, and `_`, for example `GH_TOKEN`."
82
+ },
83
+ SANDBOX_R0040: {
84
+ ...dynamicError,
85
+ fix: "Remove the variable that the message names from `env` in the Sandbox definition. The runtime sets `HOME`, `PWD`, `OLDPWD`, `INIT_CWD`, `CODEX_HOME`, and the `XDG_*` directories. Put Home files in `home.files`."
86
+ },
87
+ SANDBOX_R0041: {
88
+ ...dynamicError,
89
+ fix: "Make the `env` value that the message names return a string, not `undefined`. If it reads a secret or an env variable, set that value in the runtime environment."
90
+ },
91
+ SANDBOX_R0042: {
92
+ ...dynamicError,
93
+ fix: "Give the `home.state` entry that the message names a non-empty `key`, for example `home: { state: { \".codex\": { key: \"codex\" } } }`."
94
+ },
95
+ SANDBOX_R0043: {
96
+ ...dynamicError,
97
+ fix: "Give each `home.state` entry its own `key`. Two entries of the Sandbox definition use the key that the message names."
98
+ },
99
+ SANDBOX_R0044: {
100
+ ...dynamicError,
101
+ fix: "Set the `home.files` or `seed` entry that the message names to an object with `from` or `contents`, for example `{ from: \".vitehub/sandbox/gitconfig\" }`."
102
+ },
103
+ SANDBOX_R0045: {
104
+ ...dynamicError,
105
+ fix: "Give the file entry that the message names one key only: `from` with a string path, or `contents`. Do not set both."
106
+ },
107
+ SANDBOX_R0046: {
108
+ ...dynamicError,
109
+ fix: "Give the file entry that the message names exactly one own key, `from` or `contents`. Do not set both, and do not use an object that inherits them."
110
+ },
111
+ SANDBOX_R0047: {
112
+ ...dynamicError,
113
+ fix: "Make the `contents` of the file that the message names return text or bytes, not `undefined`. If it reads a secret, set that value in the runtime environment."
114
+ },
115
+ SANDBOX_R0048: {
116
+ ...dynamicError,
117
+ fix: "Make the `contents` of the file that the message names return a string or a `Uint8Array`."
118
+ },
119
+ SANDBOX_R0049: {
120
+ ...dynamicError,
121
+ fix: "Create the `from` file that the message names, or correct its path. The path is relative to `cwd`, or to the ViteHub process directory when there is no `cwd`, and must stay inside that directory."
122
+ },
123
+ SANDBOX_R0050: {
124
+ ...dynamicError,
125
+ fix: "Change one of the two targets that the message names. A target in `home.files` or in a state `seed` cannot be the same as another target or be inside it."
126
+ },
127
+ SANDBOX_R0051: {
128
+ ...dynamicError,
129
+ fix: "Use `home.state` paths that do not contain each other, for example `.codex` and `.config/gh`, not `.config` and `.config/gh`."
130
+ },
131
+ SANDBOX_R0052: {
132
+ ...dynamicError,
133
+ fix: "Change the `home.files` target that the message names, so that it is not a `home.state` path or a parent of one. A file can be inside a state path."
134
+ },
135
+ SANDBOX_R0053: {
136
+ ...dynamicError,
137
+ fix: "Set the option that the message names (`env`, `home.files`, `home.state`, or a state `seed`) to an object, not an array."
138
+ },
139
+ SANDBOX_R0054: {
140
+ ...dynamicError,
141
+ fix: "Write the path that the message names as a relative POSIX path, such as `.config/gh/hosts.yml`. Do not start it with `/`, and do not use `\\`."
142
+ },
143
+ SANDBOX_R0055: {
144
+ ...dynamicError,
145
+ fix: "Write the path that the message names in normal form below its root, such as `.config/gh/hosts.yml`. Remove `./`, `..`, and double slashes."
146
+ },
147
+ SANDBOX_R0056: {
148
+ ...dynamicError,
149
+ fix: "Remove the empty entry from `requires`, or write the command to check, for example `requires: [\"git\"]`."
150
+ },
151
+ SANDBOX_R0057: {
152
+ ...dynamicError,
153
+ fix: "Remove the NUL character from the command in `requires`."
154
+ },
155
+ SANDBOX_R0058: {
156
+ ...dynamicError,
157
+ fix: "Write each `requires` entry as a command name, such as `\"git\"`, or as an object with a non-empty `command`, such as `{ command: \"node\", args: [\"-v\"] }`."
158
+ },
159
+ SANDBOX_R0059: {
160
+ ...dynamicError,
161
+ fix: "Set `args` of the `requires` entry to an array of strings, for example `{ command: \"node\", args: [\"-v\"] }`."
162
+ },
163
+ SANDBOX_R0060: {
164
+ ...dynamicError,
165
+ fix: "Remove the NUL character from `command` and `args` of the `requires` entry."
166
+ },
167
+ SANDBOX_R0061: {
168
+ ...dynamicError,
169
+ fix: "Set `timeout` of the `requires` entry to a whole number of milliseconds from 1 to 2147483647, or remove it."
170
+ },
171
+ SANDBOX_R0062: {
172
+ ...dynamicError,
173
+ fix: "Make the value that the message names (`cwd`, a `checkout` field, or an `env` value) resolve to a non-empty string."
174
+ },
175
+ SANDBOX_R0063: {
176
+ ...dynamicError,
177
+ fix: "Remove the NUL character from the value that the message names."
178
+ },
179
+ SANDBOX_R0064: {
180
+ ...dynamicError,
181
+ fix: "Set `checkout.sha` to the full commit id of 40 or 64 hex characters, for example the output of `git rev-parse HEAD`. A short sha does not work."
182
+ },
183
+ SANDBOX_R0088: {
184
+ why: ({ message }) => message,
185
+ data: ({ retryable }) => ({ retryable }),
186
+ fix: "Read `error.cause` for the Cloudflare error. If `error.data.retryable` is `true` and the call can safely run twice, retry it. Otherwise, check the Sandbox Durable Object binding and the Container logs in the Cloudflare dashboard."
187
+ },
188
+ SANDBOX_R0090: {
189
+ ...dynamicError,
190
+ fix: "Check the Container logs in the Cloudflare dashboard to find why the Sandbox did not answer in time, then retry the call."
191
+ },
192
+ SANDBOX_R0091: {
193
+ ...dynamicError,
194
+ fix: "Add `cwd` or `checkout` to the Sandbox definition. The `crabbox` runtime needs a working directory."
195
+ },
196
+ SANDBOX_R0092: {
197
+ ...dynamicError,
198
+ fix: "Set `runtime.stateRoot` to an absolute path on the Crabbox target, for example `/var/lib/vitehub/sandboxes`, or remove `home.state`."
199
+ },
200
+ SANDBOX_R0093: {
201
+ ...dynamicError,
202
+ fix: "Set `runtime.stateRoot` to a dedicated directory, for example `/var/lib/vitehub/sandboxes`, not `/`."
203
+ },
204
+ SANDBOX_R0094: {
205
+ ...dynamicError,
206
+ fix: "Set `cwd` of the Sandbox definition to a directory that exists on the ViteHub host."
207
+ },
208
+ SANDBOX_R0095: {
209
+ ...dynamicError,
210
+ fix: "Check that the Crabbox target is a Linux host with a POSIX `sh`, `mktemp`, and a writable `/tmp`."
211
+ },
212
+ SANDBOX_R0096: {
213
+ ...dynamicError,
214
+ fix: "Check that the Crabbox target is a Linux host with a POSIX `sh`, and that the SSH user can create directories in `/tmp`."
215
+ },
216
+ SANDBOX_R0097: {
217
+ ...dynamicError,
218
+ fix: "Set `runtime.stateRoot` to a path that resolves to a directory other than `/` on the Crabbox target. Check where its symbolic links point."
219
+ },
220
+ SANDBOX_R0098: {
221
+ ...dynamicError,
222
+ fix: "Move `runtime.stateRoot` outside the synced `cwd` on the Crabbox target, for example to `/var/lib/vitehub/sandboxes`."
223
+ },
224
+ SANDBOX_R0100: {
225
+ ...dynamicError,
226
+ fix: "Check that the shell of the SSH user on the Crabbox target sets `PATH`."
227
+ },
228
+ SANDBOX_R0101: {
229
+ ...dynamicError,
230
+ fix: "Check that `id -un` prints the user name on the Crabbox target. The SSH user must have an entry in `/etc/passwd`."
231
+ },
232
+ SANDBOX_R0102: {
233
+ ...dynamicError,
234
+ fix: "Check the SSH connection to the Crabbox target and read `error.cause`. Then open a new Sandbox session, because a session stops when it loses its state lease."
235
+ },
236
+ SANDBOX_R0103: {
237
+ ...dynamicError,
238
+ fix: "Read the target error in the message. Check that the SSH user can create and link files below `runtime.stateRoot` on the Crabbox target, and that the target has `ln`, `sed`, and `stat`."
239
+ },
240
+ SANDBOX_R0104: {
241
+ ...dynamicError,
242
+ fix: "Check the SSH connection to the Crabbox target. Then open a new Sandbox session, because a session stops when it loses its state lease."
243
+ },
244
+ SANDBOX_R0105: {
245
+ ...dynamicError,
246
+ fix: "The `signal` that you passed to `sandbox.open()` aborted while the session waited for its Crabbox state lease. Do not abort it while the session opens, or pass a reason to `abort(reason)` to see why it stopped."
247
+ },
248
+ SANDBOX_R0106: {
249
+ ...dynamicError,
250
+ fix: "Check the SSH connection to the Crabbox target, then call `session.close()` again to release the state lease."
251
+ },
252
+ SANDBOX_R0107: {
253
+ ...dynamicError,
254
+ fix: "Rename the files below the listed path whose names contain a tab or a line break, then call `session.files.list()` again."
255
+ },
256
+ SANDBOX_R0108: {
257
+ ...dynamicError,
258
+ fix: "Update the `crabbox` CLI on the ViteHub host. `crabbox warmup --timing-json` must print a JSON line with `leaseId`."
259
+ },
260
+ SANDBOX_R0109: {
261
+ ...dynamicError,
262
+ fix: "Update the `crabbox` CLI on the ViteHub host. `crabbox tunnel` must print a URL such as `http://127.0.0.1:<port>` on its first line."
263
+ },
264
+ SANDBOX_R0110: {
265
+ ...dynamicError,
266
+ fix: "Read the Crabbox error in the message and `error.cause`. Check that a process in the Sandbox listens on the port, and that `crabbox tunnel` works for the Crabbox target."
267
+ },
268
+ SANDBOX_R0111: {
269
+ ...dynamicError,
270
+ fix: "The `signal` that you passed to the command aborted. Do not abort it while the command must run, or pass a reason to `abort(reason)` to see why it stopped."
271
+ },
272
+ SANDBOX_R0112: {
273
+ ...dynamicError,
274
+ fix: "Rename the `env` key that the message names in the options of `session.exec()` or `session.spawn()`. A name starts with a letter or `_` and has only letters, digits, and `_`."
275
+ },
276
+ SANDBOX_R0113: {
277
+ ...dynamicError,
278
+ fix: "Remove the variable that the message names from the `env` option of `session.exec()` or `session.spawn()`. The Crabbox runtime sets `HOME`, `PWD`, `OLDPWD`, `INIT_CWD`, `CODEX_HOME`, the `XDG_*` directories, and `VITEHUB_SANDBOX_SESSION`."
279
+ },
280
+ SANDBOX_R0114: {
281
+ ...dynamicError,
282
+ fix: "Pass a path inside the Sandbox session to the file method or `cwd` option. Remove the `..` segments that leave the session directory."
283
+ },
284
+ SANDBOX_R0115: {
285
+ ...dynamicError,
286
+ fix: "Replace the symbolic link that the message names in `cwd` with a real directory, or remove it, so that ViteHub can copy the Crabbox workspace back."
287
+ },
288
+ SANDBOX_R0116: {
289
+ ...dynamicError,
290
+ fix: "Rename the file in the Crabbox workspace whose name contains a line break, or whose path starts with `/` or `..`. ViteHub cannot copy that name back to `cwd`."
291
+ },
292
+ SANDBOX_R0117: {
293
+ ...dynamicError,
294
+ fix: "Read the Crabbox error in the message. Check that the `crabbox` CLI is installed on the ViteHub host, that `runtime.profile` names a Crabbox profile, and that the SSH target is a Linux host that you can reach."
295
+ },
296
+ SANDBOX_R0118: {
297
+ ...dynamicError,
298
+ fix: "Run `crabbox tunnel` for the Crabbox target by hand to see why it stops. Check that the SSH target is reachable and that the `crabbox` CLI is up to date."
299
+ },
300
+ SANDBOX_R0119: {
301
+ ...dynamicError,
302
+ fix: "Make `checkout.sha` the commit that `checkout.ref` points to on `checkout.remote`. Push the commit, or pass the sha of the current `ref`."
303
+ },
304
+ SANDBOX_R0120: {
305
+ ...dynamicError,
306
+ fix: "Check that `checkout.remote` is a Git URL that the Sandbox can reach, that `checkout.ref` exists there, and that `env` gives Git the credentials for a private remote."
307
+ },
308
+ SANDBOX_R0121: {
309
+ ...dynamicError,
310
+ fix: "Read the Git error in the message. Check that `checkout.remote` is a Git URL that the Sandbox can reach, that `checkout.ref` exists there, and that `env` gives Git the credentials for a private remote."
311
+ },
312
+ SANDBOX_R0122: {
313
+ ...dynamicError,
314
+ fix: "Remove `cwd` from the Sandbox definition. Use `checkout`, or copy the files into the Sandbox with `session.files.write()`, because this runtime cannot mount a host directory."
315
+ },
316
+ SANDBOX_R0123: {
317
+ ...dynamicError,
318
+ fix: "Remove `home.state` from the Sandbox definition, or use the `trusted-host` or `crabbox` runtime with a `stateRoot`. Use `home.files` for files that the Sandbox only reads."
319
+ },
320
+ SANDBOX_R0124: {
321
+ ...dynamicError,
322
+ fix: "Install the command that the requirement names in the Sandbox image or on the target, or remove it from `requires`. `git` is required for `checkout`, and `node` and the package manager for `toolchain`."
323
+ },
324
+ SANDBOX_R0125: {
325
+ ...dynamicError,
326
+ fix: "Open a new session with `sandbox.open()`. Do not use a session after you call `session.close()`."
327
+ },
328
+ SANDBOX_R0126: {
329
+ ...dynamicError,
330
+ fix: "Set `timeout` of `session.exec()` or `session.spawn()` to a positive number of milliseconds, or remove it."
331
+ },
332
+ SANDBOX_R0127: {
333
+ ...dynamicError,
334
+ fix: "Pass a non-empty command without NUL characters to `session.exec()` or `session.spawn()`."
335
+ },
336
+ SANDBOX_R0128: {
337
+ ...dynamicError,
338
+ fix: "Remove the NUL characters from the arguments of `session.exec()` or `session.spawn()`."
339
+ },
340
+ SANDBOX_R0129: {
341
+ ...dynamicError,
342
+ fix: "Pass a whole port number from 1 to 65535 to `session.ports.expose()`."
343
+ },
344
+ SANDBOX_R0130: {
345
+ ...dynamicError,
346
+ fix: "Set `runtime.stateRoot` to an absolute path, for example `runtime: { kind: \"trusted-host\", stateRoot: \"/var/lib/vitehub/sandboxes\" }`, or remove `home.state`."
347
+ },
348
+ SANDBOX_R0131: {
349
+ ...dynamicError,
350
+ fix: "Set `runtime.stateRoot` to a dedicated directory, for example `/var/lib/vitehub/sandboxes`, not `/`."
351
+ },
352
+ SANDBOX_R0132: {
353
+ ...dynamicError,
354
+ fix: "Move `runtime.stateRoot` outside `cwd`, for example to `/var/lib/vitehub/sandboxes`."
355
+ },
356
+ SANDBOX_R0133: {
357
+ ...dynamicError,
358
+ fix: "A file is where the state directory of the key that the message names must be, below `runtime.stateRoot`. Remove that file, or give the `home.state` entry another `key`."
359
+ },
360
+ SANDBOX_R0134: {
361
+ ...dynamicError,
362
+ fix: "Delete the `.projections` file of the state that the message names, below `runtime.stateRoot`. The next boot writes it again."
363
+ },
364
+ SANDBOX_R0135: {
365
+ ...dynamicError,
366
+ fix: "Remove the symbolic link in the writable state that the message names. A `home.files` target below a `home.state` path cannot go through a link that points outside that state."
367
+ },
368
+ SANDBOX_R0136: {
369
+ ...dynamicError,
370
+ fix: "Remove the symbolic link in the writable state that the message names. A file that an earlier boot put below a `home.state` path cannot go through a link that points outside that state."
371
+ },
372
+ SANDBOX_R0137: {
373
+ ...dynamicError,
374
+ fix: "Remove the variable that the message names from the `env` option of `session.exec()` or `session.spawn()`. The runtime sets `HOME`, `PWD`, `OLDPWD`, `INIT_CWD`, `CODEX_HOME`, and the `XDG_*` directories."
375
+ },
376
+ SANDBOX_R0138: {
377
+ ...dynamicError,
378
+ fix: "Create the directory that the message names, or set `cwd` or `runtime.stateRoot` to a directory that exists."
379
+ },
380
+ SANDBOX_R0139: {
381
+ ...dynamicError,
382
+ fix: "Set `runtime.stateRoot` to its real path, without symbolic links, for example the output of `realpath`. Do not move or replace the directory while a Sandbox opens."
383
+ },
384
+ SANDBOX_R0140: {
385
+ ...dynamicError,
386
+ fix: "Pass a path inside the Sandbox session to the file method or `cwd` option. Remove the `..` segments that leave the session directory."
387
+ },
388
+ SANDBOX_R0141: {
389
+ ...dynamicError,
390
+ fix: "The `signal` that you passed to the command aborted. Do not abort it while the command must run, or pass a reason to `abort(reason)` to see why it stopped."
391
+ },
392
+ SANDBOX_R0142: {
393
+ ...dynamicError,
394
+ fix: "Install `@vercel/sandbox` in the app, for example `pnpm add @vercel/sandbox`."
395
+ },
396
+ SANDBOX_R0143: {
397
+ ...dynamicError,
398
+ fix: "Add the port to `runtime.ports`, for example `runtime: { kind: \"vercel\", ports: [3000] }`. Vercel exposes only the ports that you declare when it creates the Sandbox."
399
+ },
400
+ SANDBOX_R0144: {
401
+ ...dynamicError,
402
+ fix: "Read the `rm` error in the message. To remove a directory that is not empty, pass `{ recursive: true }` to `session.files.remove()`."
403
+ },
404
+ SANDBOX_R0145: {
405
+ ...dynamicError,
406
+ fix: "Read the `find` error in the message. Pass a directory that exists in the Vercel Sandbox to `session.files.list()`."
407
+ },
408
+ SANDBOX_R0146: {
409
+ ...dynamicError,
410
+ fix: "Set the `toolchain` option that the message names to `\"project\"` or to an object with only `node`, `packageManager`, or `fallbackNode`, for example `{ node: \"22\", packageManager: \"pnpm@10.2.0\" }`."
411
+ },
412
+ SANDBOX_R0147: {
413
+ ...dynamicError,
414
+ fix: "Add `.node-version`, `.nvmrc`, `devEngines.runtime`, `volta.node`, or `engines.node` to the project, or set `toolchain.node` or `toolchain.fallbackNode`."
415
+ },
416
+ SANDBOX_R0148: {
417
+ ...dynamicError,
418
+ fix: "Make `package.json` of the project valid JSON, and set its `packageManager` or `devEngines.packageManager` to `name@version`, such as `pnpm@10.2.0`."
419
+ },
420
+ SANDBOX_R0149: {
421
+ ...dynamicError,
422
+ fix: "Use npm, pnpm, or yarn in `packageManager` of `package.json`. For bun, set `toolchain.packageManager` to `false` and install bun in the Sandbox image."
423
+ },
424
+ SANDBOX_R0150: {
425
+ ...dynamicError,
426
+ fix: "Use `toolchain` only with a Linux or macOS host and target. Otherwise remove `toolchain` and install Node.js in the Sandbox image."
427
+ },
428
+ SANDBOX_R0151: {
429
+ ...dynamicError,
430
+ fix: "Pin a Node.js or package manager version that exists, such as `22.12.0` or `pnpm@10.2.0`, in the source that the message names."
431
+ },
432
+ SANDBOX_R0152: {
433
+ ...dynamicError,
434
+ fix: "Pin another version of the package manager. The registry metadata of this version has no sha512 integrity or no usable `bin` entries."
435
+ },
436
+ SANDBOX_R0153: {
437
+ ...dynamicError,
438
+ fix: "Check the hash in `packageManager` of `package.json`, and check that no proxy or mirror changes the download. Then provision the toolchain again."
439
+ },
440
+ SANDBOX_R0154: {
441
+ ...dynamicError,
442
+ fix: "Read the toolchain error in the message. Make the toolchain cache a directory that only the current user owns and can write, and check that the target has `sh`, `tar` with gzip, `mktemp`, and `base64`."
443
+ },
444
+ SANDBOX_R0155: {
445
+ ...dynamicError,
446
+ fix: "Check that the ViteHub process can reach the URL in the message, and read `error.cause` for the network error. Then retry, or pin a version that is already in the toolchain cache."
447
+ },
448
+ SANDBOX_R0156: {
449
+ ...dynamicError,
450
+ fix: "Remove `toolchain` from the Sandbox definition, or use a built-in runtime. Custom runtimes do not provision toolchains."
451
+ },
452
+ SANDBOX_R0159: {
453
+ ...dynamicError,
454
+ fix: "Read `stdout` and `stderr` of the process at the same time, or cancel the stream that you do not read. Each stream keeps at most 1 MiB of output that is not read."
455
+ },
456
+ SANDBOX_R0160: {
457
+ ...dynamicError,
458
+ fix: "Correct the option of `runtime: { kind: \"container\" }` that the message names. If the message names Docker, use rootful Docker Engine 28 or newer on native Linux."
459
+ },
460
+ SANDBOX_R0161: {
461
+ ...dynamicError,
462
+ fix: "Read the Docker error in the message. Check that `docker` can pull and start the image, and that the image runs as root or that `user` names a user of the image."
463
+ },
464
+ SANDBOX_R0162: {
465
+ ...dynamicError,
466
+ fix: "Call `session.close()` again. If it fails again, remove the containers and network that the message names with `docker rm -f` and `docker network rm`."
467
+ },
468
+ SANDBOX_R0163: {
469
+ ...dynamicError,
470
+ fix: "Read the error in the message. Check that the path is inside the Sandbox, that the image `user` can read or write it, and that the image has `sh`, coreutils, and GNU `find`."
471
+ },
472
+ SANDBOX_R0164: {
473
+ ...dynamicError,
474
+ fix: "Pass a signal name such as `SIGTERM` or `SIGKILL` to `child.kill()`. If the message says that the PID registration timed out, call `child.kill()` again."
475
+ },
476
+ SANDBOX_R0165: {
477
+ why: ({ runtime, signal }) => `${runtime} Sandbox cannot send the signal ${signal}.`,
478
+ fix: "On Crabbox, use SIGTERM. On Vercel, use SIGHUP, SIGINT, SIGQUIT, SIGKILL, SIGTERM, SIGCONT, SIGSTOP, or a signal number. On Cloudflare, use SIGALRM, SIGHUP, SIGINT, SIGKILL, SIGQUIT, SIGTERM, SIGUSR1, SIGUSR2, or a signal number."
479
+ },
480
+ SANDBOX_CLOUDFLARE_COMMAND_TIMED_OUT: {
481
+ why: ({ timeout }) => `Command timed out after ${timeout}ms.`,
482
+ fix: "Give `exec()` a larger `timeout`, or make the command finish sooner. The Sandbox and its other processes keep running."
483
+ },
484
+ SANDBOX_CLOUDFLARE_CONTAINER_MISSING: {
485
+ why: "The Sandbox Durable Object has no Container. Add a containers entry for its class in wrangler.json.",
486
+ fix: "Add a `containers` entry with the Sandbox Durable Object class name to the Wrangler config, then deploy again."
487
+ },
488
+ SANDBOX_CLOUDFLARE_LOG_STREAM_FAILED: {
489
+ why: ({ detail }) => `[vitehub] Cloudflare process log stream failed: ${detail}`,
490
+ fix: "Read the Container error in the message, and check the Container logs of the Sandbox Durable Object in the Cloudflare dashboard. Start the process again to retry."
491
+ },
492
+ SANDBOX_CLOUDFLARE_PROCESS_NOT_FOUND: {
493
+ why: ({ processId }) => `Process ${processId} is not running in this Sandbox.`,
494
+ fix: "Read the logs of a process from the Sandbox that started it, before you close or reset that Sandbox. Start the process again to get new logs."
495
+ },
496
+ SANDBOX_CLOUDFLARE_SLEEP_AFTER_INVALID: {
497
+ why: ({ value }) => `[vitehub] Invalid Cloudflare sleepAfter ${value}. Use seconds or a value such as "30s", "5m" or "1h".`,
498
+ fix: "Set `sleepAfter` of the Cloudflare Sandbox to a number of seconds or a string such as `\"30s\"`, `\"5m\"`, or `\"1h\"`."
499
+ },
500
+ SANDBOX_NETWORK_POLICY_INVALID: {
501
+ why: ({ problem }) => `[vitehub] Invalid Sandbox networkPolicy. ${problem}`,
502
+ fix: "Set `networkPolicy` to \"allow-all\", \"deny-all\", or `{ allow: [\"api.example.com\", \"*.example.com\"] }` with at most 64 hostnames. Only Vercel supports `subnets`. With a custom Cloudflare `getSandbox`, apply the network policy in your own Durable Object and omit `networkPolicy`."
503
+ },
504
+ SANDBOX_SSH_DRAIN_TIMEOUT_INVALID: {
505
+ why: "[vitehub] drainTimeoutMs must be a non-negative integer of milliseconds.",
506
+ fix: "Pass `close({ drainTimeoutMs })` a whole number of milliseconds from 0 to 2147483647, or omit it to close at once."
507
+ },
508
+ SANDBOX_SSH_LAUNCH_INVALID: {
509
+ why: ({ problem }) => ({
510
+ command: "[vitehub] SSH command and cwd are required and cannot contain NUL.",
511
+ connectRetryMs: "[vitehub] SSH connectRetryMs must be a non-negative integer of milliseconds.",
512
+ environment: "[vitehub] SSH environment names must be uppercase shell identifiers.",
513
+ host: "[vitehub] SSH host is invalid.",
514
+ hostKey: "[vitehub] Select hostKeyFile or knownHostsFile.",
515
+ identityFile: "[vitehub] SSH identityFile is required.",
516
+ port: "[vitehub] SSH port must be between 1 and 65535.",
517
+ user: "[vitehub] SSH user is invalid."
518
+ })[problem],
519
+ fix: "Fix the `sshLaunch()` option that the message names: a `host` and `user` without spaces, an `identityFile` path, a `port` from 1 to 65535, only one of `hostKeyFile` and `knownHostsFile`, and uppercase names such as `API_TOKEN` in `forwardEnvironment`."
520
+ },
521
+ SANDBOX_SSH_POSIX_REQUIRED: {
522
+ why: "[vitehub] SSH command supervision requires a POSIX host.",
523
+ fix: "Run `serveSsh()` or `vitehub sandbox serve` on Linux or macOS, or in WSL on Windows."
524
+ },
525
+ SANDBOX_TRUSTED_HOST_CLOSING: {
526
+ why: "Trusted host Sandbox session is closing.",
527
+ fix: "Await every command of the trusted-host Sandbox before you close it, and open a new Sandbox for more commands."
528
+ },
529
+ SANDBOX_TRUSTED_HOST_KILL_TIMED_OUT: {
530
+ why: "Timed out waiting for trusted-host processes to exit after SIGKILL.",
531
+ fix: "Find the processes of the trusted-host Sandbox that still run, for example with `ps -ef`, end them, and open a new Sandbox."
532
+ }
533
+ }
534
+ });
535
+ //#endregion
536
+ export { sandboxErrorDiagnostics as t };
@@ -0,0 +1,26 @@
1
+ import { t as sandboxErrorDiagnostics } from "./error-diagnostics-BJtLRL9w.js";
2
+ import { t as shellQuote } from "./shell-quote-Q3u3plif.js";
3
+ //#region src/internal/file-listing.ts
4
+ async function listCommandFiles(run, options, failure) {
5
+ options.abortSignal?.throwIfAborted();
6
+ const result = await run({
7
+ abortSignal: options.abortSignal,
8
+ command: `find ${shellQuote(options.path)} -mindepth 1 ${options.recursive ? "" : "-maxdepth 1 "}-printf '%y\\t%s\\t%p\\0'`
9
+ });
10
+ if (result.exitCode !== 0) throw failure(result);
11
+ return result.stdout.split("\0").filter(Boolean).map((entry) => {
12
+ const kindSeparator = entry.indexOf(" ");
13
+ const sizeSeparator = entry.indexOf(" ", kindSeparator + 1);
14
+ const kind = entry.slice(0, kindSeparator);
15
+ const size = entry.slice(kindSeparator + 1, sizeSeparator);
16
+ const path = entry.slice(sizeSeparator + 1);
17
+ if (kindSeparator < 1 || sizeSeparator < 0 || !path) throw sandboxErrorDiagnostics.SANDBOX_R0107({ message: `[vitehub] Sandbox returned an invalid file entry for ${options.path}.` });
18
+ return {
19
+ path,
20
+ size: kind === "f" ? Number(size) : void 0,
21
+ type: kind === "d" ? "directory" : kind === "l" ? "symlink" : "file"
22
+ };
23
+ }).sort((left, right) => left.path.localeCompare(right.path));
24
+ }
25
+ //#endregion
26
+ export { listCommandFiles as t };
@@ -0,0 +1,74 @@
1
+ import { t as abortable } from "./abortable-CR01hzfi.js";
2
+ import { t as runtimeRecord } from "./runtime-type-Deo4qzxN.js";
3
+ import { randomUUID } from "node:crypto";
4
+ import { mkdir, readFile, rename, rm, stat, writeFile } from "node:fs/promises";
5
+ import { join } from "node:path";
6
+ import { hostname } from "node:os";
7
+ //#region src/internal/file-lock.ts
8
+ /**
9
+ * Acquire a cross-process lock directory. A lock whose owner process is gone
10
+ * on this host, or whose owner record stays unreadable, is treated as stale.
11
+ */
12
+ async function acquireFileLock(path, abortSignal) {
13
+ const token = randomUUID();
14
+ while (true) {
15
+ abortSignal?.throwIfAborted();
16
+ if (await mkdir(path, { mode: 448 }).then(() => true, async (error) => {
17
+ if (error.code !== "EEXIST") throw error;
18
+ const staleToken = await staleLock(path);
19
+ if (staleToken) {
20
+ const tombstone = `${path}.stale-${staleToken}`;
21
+ await rename(path, tombstone).then(() => true, () => false);
22
+ return false;
23
+ }
24
+ return false;
25
+ })) {
26
+ try {
27
+ await writeFile(join(path, "owner.json"), JSON.stringify({
28
+ host: hostname(),
29
+ pid: process.pid,
30
+ token
31
+ }), { mode: 384 });
32
+ } catch (error) {
33
+ await rm(path, {
34
+ force: true,
35
+ recursive: true
36
+ }).catch(() => void 0);
37
+ throw error;
38
+ }
39
+ let released = false;
40
+ return async () => {
41
+ if (released) return;
42
+ await rm(path, {
43
+ force: true,
44
+ recursive: true
45
+ });
46
+ released = true;
47
+ };
48
+ }
49
+ await abortable(new Promise((resolvePromise) => setTimeout(resolvePromise, 25)), abortSignal);
50
+ }
51
+ }
52
+ async function staleLock(path) {
53
+ const owner = await readFile(join(path, "owner.json"), "utf8").then((value) => {
54
+ try {
55
+ return runtimeRecord(JSON.parse(value));
56
+ } catch {
57
+ return;
58
+ }
59
+ }, () => void 0);
60
+ if (!owner) {
61
+ const item = await stat(path).catch(() => void 0);
62
+ return item && Date.now() - item.mtimeMs > 5e3 ? `invalid-${item.dev}-${item.ino}-${Math.floor(item.mtimeMs)}` : void 0;
63
+ }
64
+ const { host, pid, token } = owner;
65
+ if (host !== hostname() || typeof pid !== "number" || typeof token !== "string") return void 0;
66
+ try {
67
+ process.kill(pid, 0);
68
+ return;
69
+ } catch (error) {
70
+ return error instanceof Error && "code" in error && error.code === "ESRCH" ? token : void 0;
71
+ }
72
+ }
73
+ //#endregion
74
+ export { acquireFileLock as t };