@vite-hub/sandbox 0.3.0 → 0.4.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.
@@ -1,8 +1,8 @@
1
1
  import { n as loadVercelSandbox } from "../../../vercel-BGGrNpza.js";
2
2
  import { resolveVercelSandbox } from "../../../internal/vercel.js";
3
- import { t as sandboxTaskErrorDiagnostics } from "../../../error-diagnostics-5QT_BjbQ.js";
4
- import "../../../provider-resolution-C6AQzuFG.js";
5
- import { a as resolveVercelSandboxTaskVcpus } from "../../../size-7AkVwGZb.js";
3
+ import { t as sandboxTaskErrorDiagnostics } from "../../../error-diagnostics-BNQwU9yq.js";
4
+ import "../../../provider-resolution-BrQfEQo0.js";
5
+ import { a as resolveVercelSandboxTaskVcpus } from "../../../size-DJNpXeAt.js";
6
6
  //#region ../internal/src/env.ts
7
7
  function trimmed(value) {
8
8
  return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
@@ -1,4 +1,5 @@
1
- import { a as SandboxTaskDefinitionBundle, t as AgentSandboxTaskConfig, u as SandboxTaskDefinitionOptions } from "../../module-types-DCeJbS9Z.js";
1
+ import { a as SandboxTaskDefinitionBundle, t as AgentSandboxTaskConfig, u as SandboxTaskDefinitionOptions } from "../../module-types-BoOZiNN4.js";
2
+ import { t as ResolvedTaskSandbox } from "../../provider-loader-BDgDJ6bX.js";
2
3
  //#region src/task/runtime/state.d.ts
3
4
  export type SandboxTaskRegistryEntry = {
4
5
  bundle: SandboxTaskDefinitionBundle;
@@ -19,9 +20,9 @@ export declare function createGeneratedSandboxTaskRuntimeRegistry(scope: string,
19
20
  export declare function getSandboxTaskRuntimeConfig(): false | AgentSandboxTaskConfig | undefined;
20
21
  export declare function getSandboxTaskRuntimeRegistry(): SandboxTaskRuntimeRegistry | undefined;
21
22
  export declare function setSandboxTaskRuntimeConfig(config: false | AgentSandboxTaskConfig | undefined): void;
22
- /** `vite dev` sets this. Task error Responses then keep the stack and process output. */
23
- export declare function isSandboxTaskRuntimeDevelopment(): boolean;
24
- export declare function setSandboxTaskRuntimeDevelopment(development: boolean): void;
23
+ /** The provider that runs Sandbox Tasks on this machine. Only the `vite dev` facade sets it. */
24
+ export declare function getSandboxTaskRuntimeLocalProvider(): (() => Promise<ResolvedTaskSandbox>) | undefined;
25
+ export declare function setSandboxTaskRuntimeLocalProvider(provider: (() => Promise<ResolvedTaskSandbox>) | undefined): void;
25
26
  export declare function setSandboxTaskRuntimeRegistry(registry: SandboxTaskRuntimeRegistry | undefined): void;
26
27
  export declare function resetSandboxTaskRuntimeState(): void;
27
28
  //#endregion
@@ -1,8 +1,8 @@
1
- import { t as sandboxTaskErrorDiagnostics } from "../../error-diagnostics-5QT_BjbQ.js";
1
+ import { t as sandboxTaskErrorDiagnostics } from "../../error-diagnostics-BNQwU9yq.js";
2
2
  import { pathToFileURL } from "node:url";
3
3
  //#region src/task/runtime/state.ts
4
4
  let sandboxTaskConfig;
5
- let sandboxTaskDevelopment = false;
5
+ let sandboxTaskLocalProvider;
6
6
  let sandboxTaskRegistry;
7
7
  const generatedRegistries = /* @__PURE__ */ new Map();
8
8
  const generatedRegistryOwnership = /* @__PURE__ */ new WeakMap();
@@ -60,12 +60,12 @@ function getSandboxTaskRuntimeRegistry() {
60
60
  function setSandboxTaskRuntimeConfig(config) {
61
61
  sandboxTaskConfig = config;
62
62
  }
63
- /** `vite dev` sets this. Task error Responses then keep the stack and process output. */
64
- function isSandboxTaskRuntimeDevelopment() {
65
- return sandboxTaskDevelopment;
63
+ /** The provider that runs Sandbox Tasks on this machine. Only the `vite dev` facade sets it. */
64
+ function getSandboxTaskRuntimeLocalProvider() {
65
+ return sandboxTaskLocalProvider;
66
66
  }
67
- function setSandboxTaskRuntimeDevelopment(development) {
68
- sandboxTaskDevelopment = development;
67
+ function setSandboxTaskRuntimeLocalProvider(provider) {
68
+ sandboxTaskLocalProvider = provider;
69
69
  }
70
70
  function setSandboxTaskRuntimeRegistry(registry) {
71
71
  sandboxTaskRegistry = registry;
@@ -74,9 +74,9 @@ function setSandboxTaskRuntimeRegistry(registry) {
74
74
  }
75
75
  function resetSandboxTaskRuntimeState() {
76
76
  sandboxTaskConfig = void 0;
77
- sandboxTaskDevelopment = false;
77
+ sandboxTaskLocalProvider = void 0;
78
78
  sandboxTaskRegistry = void 0;
79
79
  generatedRegistries.clear();
80
80
  }
81
81
  //#endregion
82
- export { createGeneratedSandboxTaskModuleSpecifier, createGeneratedSandboxTaskRuntimeRegistry, getSandboxTaskRuntimeConfig, getSandboxTaskRuntimeRegistry, isSandboxTaskRuntimeDevelopment, resetSandboxTaskRuntimeState, setSandboxTaskRuntimeConfig, setSandboxTaskRuntimeDevelopment, setSandboxTaskRuntimeRegistry };
82
+ export { createGeneratedSandboxTaskModuleSpecifier, createGeneratedSandboxTaskRuntimeRegistry, getSandboxTaskRuntimeConfig, getSandboxTaskRuntimeLocalProvider, getSandboxTaskRuntimeRegistry, resetSandboxTaskRuntimeState, setSandboxTaskRuntimeConfig, setSandboxTaskRuntimeLocalProvider, setSandboxTaskRuntimeRegistry };
@@ -1,4 +1,4 @@
1
- import { t as AgentSandboxTaskConfig } from "../module-types-DCeJbS9Z.js";
1
+ import { t as AgentSandboxTaskConfig } from "../module-types-BoOZiNN4.js";
2
2
  import { Plugin } from "vite";
3
3
  //#region ../internal/src/deployment.d.ts
4
4
  /** The host that ViteHub builds for: the `host` option of `vitehub()` and the value of `VITEHUB_HOST`. */
@@ -433,6 +433,8 @@ interface ViteHubConsoleDocumentHint {
433
433
  * failing without a reason.
434
434
  */
435
435
  interface ViteHubConsoleDocumentSetup {
436
+ /** The project has GitHub Sources but no document collections. */
437
+ sourceHeadsOnly?: true;
436
438
  /** Present when no user can read anything because the owner has no access policy. */
437
439
  access?: ViteHubConsoleDocumentHint;
438
440
  /**
package/dist/task/vite.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { n as invariantError, t as invariant } from "../invariant-DolT9EEx.js";
2
- import { t as sandboxTaskErrorDiagnostics } from "../error-diagnostics-5QT_BjbQ.js";
2
+ import { t as sandboxTaskErrorDiagnostics } from "../error-diagnostics-BNQwU9yq.js";
3
3
  import { t as getSandboxTaskFeatureDriver } from "../module-types-B0LQ5H2S.js";
4
- import { a as resolveVercelSandboxTaskVcpus, i as resolveCloudflareSandboxTaskInstanceType, n as describeCloudflareInstanceType, r as readSandboxTaskSize, t as assertCloudflareInstanceTypeFits } from "../size-7AkVwGZb.js";
4
+ import { a as resolveVercelSandboxTaskVcpus, i as resolveCloudflareSandboxTaskInstanceType, n as describeCloudflareInstanceType, r as readSandboxTaskSize, t as assertCloudflareInstanceTypeFits } from "../size-DJNpXeAt.js";
5
5
  import { builtinModules, createRequire, isBuiltin } from "node:module";
6
6
  import { createHash, randomUUID } from "node:crypto";
7
7
  import { copyFile, glob, lstat, mkdir, mkdtemp, open, readFile, readdir, readlink, realpath, rename, rm, stat, symlink, writeFile } from "node:fs/promises";
@@ -37,100 +37,13 @@ function realpathIfExists(path) {
37
37
  }
38
38
  }
39
39
  //#endregion
40
- //#region ../internal/src/build/vite.ts
41
- const projectRootDirectoryMarkers = [
42
- ["server", "agents"],
43
- ["server", "channels"],
44
- ["server", "connections"],
45
- ["server", "browsers"],
46
- ["server", "emails"],
47
- ["server", "schedules"],
48
- ["server", "workspaces"]
49
- ];
50
- const projectRootFileMarkers = [
51
- ["package.json"],
52
- ["nuxt.config.ts"],
53
- ["nuxt.config.mts"],
54
- ["nuxt.config.js"],
55
- ["nuxt.config.mjs"]
56
- ];
57
- function createNoExternalAddition(...packageNames) {
58
- return (current) => {
59
- if (current === true) return;
60
- const values = Array.isArray(current) ? current : [current];
61
- const missing = packageNames.filter((packageName) => !values.includes(packageName));
62
- return missing.length ? missing : void 0;
63
- };
64
- }
65
- function isServerEnvironment(name, config) {
66
- return name === "ssr" || config.consumer === "server";
67
- }
68
- const VITEHUB_PROJECT_ROOT = "__vitehubProjectRoot";
69
- /**
70
- * Feature options that `vitehub()` and `vite-hub/nuxt` resolve for owner plugins during config hooks, such as the Queue
71
- * provider of the host. Apps set features only in `vitehub()`, so this key is private.
72
- */
73
- const VITEHUB_FEATURES = "__vitehubFeatures";
74
- /** The options that ViteHub resolved for a feature on this Vite config. The owner plugin names their type. */
75
- function getResolvedFeatureOptions(config, feature) {
76
- const features = Reflect.get(config, VITEHUB_FEATURES);
77
- if (!features || typeof features !== "object") return void 0;
78
- return Reflect.get(features, feature);
79
- }
80
- function includesNitroVitePlugin(value) {
81
- if (Array.isArray(value)) return value.some(includesNitroVitePlugin);
82
- if (!value || typeof value !== "object") return false;
83
- return "name" in value && value.name === "nitro:main";
84
- }
85
- function hasNitroConfigContext(config) {
86
- return config["__vitehubNitroConfigContext"] === true || includesNitroVitePlugin(config.plugins);
87
- }
88
- function resolveViteHubProjectRoot(root, options = {}) {
89
- const resolvedRoot = resolve(root);
90
- const temporaryRoot = resolve(tmpdir());
91
- const sharedTemporaryRoot = dirname(temporaryRoot) === parse(temporaryRoot).root ? temporaryRoot : void 0;
92
- if (options.projectRoot) return resolve(resolvedRoot, options.projectRoot);
93
- if (basename(resolvedRoot) === "app") {
94
- const parent = dirname(resolvedRoot);
95
- if (parent !== sharedTemporaryRoot && (hasProjectRootDirectoryMarker(parent) || hasProjectRootFileMarker(parent, [
96
- "nuxt.config.ts",
97
- "nuxt.config.mts",
98
- "nuxt.config.js",
99
- "nuxt.config.mjs"
100
- ]))) return parent;
101
- }
102
- let current = resolvedRoot;
103
- while (true) {
104
- if (current === sharedTemporaryRoot && resolvedRoot !== current) return resolvedRoot;
105
- if (hasProjectRootMarker(current)) return current;
106
- const parent = dirname(current);
107
- if (parent === current) return resolvedRoot;
108
- current = parent;
109
- }
110
- }
111
- function hasProjectRootDirectoryMarker(root) {
112
- for (const marker of projectRootDirectoryMarkers) try {
113
- if (statSync(resolve(root, ...marker)).isDirectory()) return true;
114
- } catch (error) {
115
- if (error.code !== "ENOENT") throw error;
116
- }
117
- return false;
118
- }
119
- function hasProjectRootMarker(root) {
120
- if (hasProjectRootDirectoryMarker(root)) return true;
121
- return hasProjectRootFileMarker(root, projectRootFileMarkers.flat());
122
- }
123
- function hasProjectRootFileMarker(root, markers) {
124
- for (const marker of markers) {
125
- const path = Array.isArray(marker) ? marker : [marker];
126
- try {
127
- if (statSync(resolve(root, ...path)).isFile()) return true;
128
- } catch (error) {
129
- if (error.code !== "ENOENT") throw error;
130
- }
131
- }
132
- return false;
40
+ //#region ../internal/src/inspect.ts
41
+ function relativeDefinitionFile(projectRoot, file) {
42
+ return relative$1(projectRoot, file).replaceAll("\\", "/");
133
43
  }
44
+ const secretKeyPattern = /secret|token|passw(?:or)?d|credential|api[-_\s]?key|private[-_\s]?key|authorization|cookie|signature|dsn|connection[-_\s]?string/i;
45
+ new RegExp(String.raw`\b([\w-]*authorization[\w-]*["']?\s*[:=]\s*)(?!\[redacted\](?=$|[\s,;}&]))(?:"(?:\\[^\r\n]|[^"\\\r\n])*"|'(?:\\[^\r\n]|[^'\\\r\n])*'|[^\r\n]+?(?=\s*(?:[,;])?\s*(?:${secretKeyPattern.source})[\w-]*\s*[:=]|\s+rejected\b|$))`, "gi");
46
+ new RegExp(String.raw`\b([\w-]*(?:${secretKeyPattern.source})[\w-]*["']?\s*[:=]\s*)(?!\[redacted\](?=$|[\s,;}&]))(?:"(?:\\[^\r\n]|[^"\\\r\n])*"|'(?:\\[^\r\n]|[^'\\\r\n])*'|[^\s,;&#&]+)`, "gi");
134
47
  //#endregion
135
48
  //#region ../internal/src/error-diagnostics.ts
136
49
  const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
@@ -303,7 +216,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
303
216
  },
304
217
  INTERNAL_R0004: {
305
218
  ...dynamicError,
306
- fix: "Set a larger `maxResponseBytes` on the HTTP request, such as the `fetch()` Source options, or ask the server for a smaller response."
219
+ fix: "Set a larger `maxResponseBytes` on the HTTP request, such as the `url()` Source options, or ask the server for a smaller response."
307
220
  },
308
221
  INTERNAL_R0005: {
309
222
  ...dynamicError,
@@ -349,6 +262,10 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
349
262
  why: ({ variable }) => `[vitehub] ${variable} must be the 43-character private key that \`vitehub secret console-key\` prints, and its name 1 to 64 of A-Z, 0-9, and _.`,
350
263
  fix: "Set the variable that the message names to the private key that `vitehub secret console-key` prints, and name it `VITEHUB_CONSOLE_PRIVATE_KEY_<NAME>` with A-Z, 0-9, and _ in `<NAME>`."
351
264
  },
265
+ INTERNAL_DEV_SERVER_NOT_FOUND: {
266
+ why: ({ command }) => `[vitehub] No dev server of this project is running, and --url is not set, so \`vitehub ${command}\` has no app to call.`,
267
+ fix: "Start the dev server of this project, such as with `pnpm dev`, or pass --url with the app URL, such as --url http://localhost:3000."
268
+ },
352
269
  INTERNAL_FORGE_NOT_INSTALLED: {
353
270
  why: ({ feature }) => `${feature} needs @vite-hub/forge, and the app did not install it.`,
354
271
  fix: "Install Forge in your app with `pnpm add @vite-hub/forge`, then build again."
@@ -395,6 +312,113 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
395
312
  }
396
313
  }
397
314
  });
315
+ //#endregion
316
+ //#region ../internal/src/object.ts
317
+ /** A non-null object that is not an array. Functions do not pass. */
318
+ function isRecord(value) {
319
+ return typeof value === "object" && value !== null && !Array.isArray(value);
320
+ }
321
+ function isPlainRecord(value) {
322
+ if (!isRecord(value)) return false;
323
+ const prototype = Object.getPrototypeOf(value);
324
+ if (prototype === null) return true;
325
+ return Object.getPrototypeOf(prototype) === null && Object.hasOwn(prototype, "constructor") && prototype.constructor?.name === "Object";
326
+ }
327
+ //#endregion
328
+ //#region ../internal/src/build/vite.ts
329
+ const projectRootDirectoryMarkers = [
330
+ ["server", "agents"],
331
+ ["server", "channels"],
332
+ ["server", "connections"],
333
+ ["server", "browsers"],
334
+ ["server", "emails"],
335
+ ["server", "schedules"],
336
+ ["server", "workspaces"]
337
+ ];
338
+ const projectRootFileMarkers = [
339
+ ["package.json"],
340
+ ["nuxt.config.ts"],
341
+ ["nuxt.config.mts"],
342
+ ["nuxt.config.js"],
343
+ ["nuxt.config.mjs"]
344
+ ];
345
+ function createNoExternalAddition(...packageNames) {
346
+ return (current) => {
347
+ if (current === true) return;
348
+ const values = Array.isArray(current) ? current : [current];
349
+ const missing = packageNames.filter((packageName) => !values.includes(packageName));
350
+ return missing.length ? missing : void 0;
351
+ };
352
+ }
353
+ function isServerEnvironment(name, config) {
354
+ return name === "ssr" || config.consumer === "server";
355
+ }
356
+ const VITEHUB_PROJECT_ROOT = "__vitehubProjectRoot";
357
+ /**
358
+ * Feature options that `vitehub()` and `vite-hub/nuxt` resolve for owner plugins during config hooks, such as the Queue
359
+ * provider of the host. Apps set features only in `vitehub()`, so this key is private.
360
+ */
361
+ const VITEHUB_FEATURES = "__vitehubFeatures";
362
+ /** The options that ViteHub resolved for a feature on this Vite config. The owner plugin names their type. */
363
+ function getResolvedFeatureOptions(config, feature) {
364
+ const features = Reflect.get(config, VITEHUB_FEATURES);
365
+ if (!features || typeof features !== "object") return void 0;
366
+ return Reflect.get(features, feature);
367
+ }
368
+ function includesNitroVitePlugin(value) {
369
+ if (Array.isArray(value)) return value.some(includesNitroVitePlugin);
370
+ if (!value || typeof value !== "object") return false;
371
+ return "name" in value && value.name === "nitro:main";
372
+ }
373
+ function hasNitroConfigContext(config) {
374
+ return config["__vitehubNitroConfigContext"] === true || includesNitroVitePlugin(config.plugins);
375
+ }
376
+ function resolveViteHubProjectRoot(root, options = {}) {
377
+ const resolvedRoot = resolve(root);
378
+ const temporaryRoot = resolve(tmpdir());
379
+ const sharedTemporaryRoot = dirname(temporaryRoot) === parse(temporaryRoot).root ? temporaryRoot : void 0;
380
+ if (options.projectRoot) return resolve(resolvedRoot, options.projectRoot);
381
+ if (basename(resolvedRoot) === "app") {
382
+ const parent = dirname(resolvedRoot);
383
+ if (parent !== sharedTemporaryRoot && (hasProjectRootDirectoryMarker(parent) || hasProjectRootFileMarker(parent, [
384
+ "nuxt.config.ts",
385
+ "nuxt.config.mts",
386
+ "nuxt.config.js",
387
+ "nuxt.config.mjs"
388
+ ]))) return parent;
389
+ }
390
+ let current = resolvedRoot;
391
+ while (true) {
392
+ if (current === sharedTemporaryRoot && resolvedRoot !== current) return resolvedRoot;
393
+ if (hasProjectRootMarker(current)) return current;
394
+ const parent = dirname(current);
395
+ if (parent === current) return resolvedRoot;
396
+ current = parent;
397
+ }
398
+ }
399
+ function hasProjectRootDirectoryMarker(root) {
400
+ for (const marker of projectRootDirectoryMarkers) try {
401
+ if (statSync(resolve(root, ...marker)).isDirectory()) return true;
402
+ } catch (error) {
403
+ if (error.code !== "ENOENT") throw error;
404
+ }
405
+ return false;
406
+ }
407
+ function hasProjectRootMarker(root) {
408
+ if (hasProjectRootDirectoryMarker(root)) return true;
409
+ return hasProjectRootFileMarker(root, projectRootFileMarkers.flat());
410
+ }
411
+ function hasProjectRootFileMarker(root, markers) {
412
+ for (const marker of markers) {
413
+ const path = Array.isArray(marker) ? marker : [marker];
414
+ try {
415
+ if (statSync(resolve(root, ...path)).isFile()) return true;
416
+ } catch (error) {
417
+ if (error.code !== "ENOENT") throw error;
418
+ }
419
+ }
420
+ return false;
421
+ }
398
422
  /** Maps a host name or a Nitro preset name, such as `cloudflare-module` or `node-server`, to its ViteHub host. */
399
423
  function hostFromNitroPreset(value) {
400
424
  const normalized = value?.trim().toLowerCase().replaceAll("_", "-");
@@ -439,18 +463,6 @@ function getSupportedHostingProvider(hosting, supportedProviders) {
439
463
  return provider;
440
464
  }
441
465
  //#endregion
442
- //#region ../internal/src/object.ts
443
- /** A non-null object that is not an array. Functions do not pass. */
444
- function isRecord(value) {
445
- return typeof value === "object" && value !== null && !Array.isArray(value);
446
- }
447
- function isPlainRecord(value) {
448
- if (!isRecord(value)) return false;
449
- const prototype = Object.getPrototypeOf(value);
450
- if (prototype === null) return true;
451
- return Object.getPrototypeOf(prototype) === null && Object.hasOwn(prototype, "constructor") && prototype.constructor?.name === "Object";
452
- }
453
- //#endregion
454
466
  //#region ../internal/src/definition-catalog.ts
455
467
  const sourceFilePattern = /\.(?:c|m)?[jt]sx?$/i;
456
468
  const declarationFilePattern = /\.d\.(?:c|m)?[jt]sx?$/i;
@@ -700,7 +712,7 @@ const defaultCloudflareSandboxClassName = "Sandbox";
700
712
  const defaultCloudflareSandboxMaxInstances = 12;
701
713
  const cloudflareSandboxNodeImage = "24-bookworm-slim";
702
714
  const cloudflareSandboxPackages = "ca-certificates curl file git jq procps tini unzip wget zip";
703
- const durableObjectModule = "@vite-hub/sandbox/_internal/cloudflare";
715
+ const durableObjectModule = "@vite-hub/sandbox/internal/cloudflare";
704
716
  function resolveModule$1(id) {
705
717
  return resolvePathSync(id, {
706
718
  conditions: [
@@ -804,7 +816,7 @@ function createCloudflareSandboxRollupPlugin(options = {}) {
804
816
  });
805
817
  },
806
818
  resolveId: {
807
- filter: { id: /^(?:virtual:vitehub-sandbox-task-cloudflare-exports|@cloudflare\/sandbox|@vite-hub\/sandbox\/_internal\/cloudflare)$/ },
819
+ filter: { id: /^(?:virtual:vitehub-sandbox-task-cloudflare-exports|@cloudflare\/sandbox|@vite-hub\/sandbox\/internal\/cloudflare)$/ },
808
820
  handler(id) {
809
821
  if (id === moduleId) return resolvedModuleId;
810
822
  if (id === "@cloudflare/sandbox") return cloudflareSandboxEntrypoint;
@@ -2560,11 +2572,13 @@ function createSandboxTaskTypeTemplateContents(definitions) {
2560
2572
  //#endregion
2561
2573
  //#region src/task/feature.ts
2562
2574
  const sandboxTaskRuntimeStateSpecifier = "@vite-hub/sandbox/task/runtime/state";
2563
- const sandboxTaskRuntimeSpecifier = "@vite-hub/sandbox/_internal/task/runtime";
2575
+ const sandboxTaskRuntimeSpecifier = "@vite-hub/sandbox/internal/task/runtime";
2564
2576
  const sandboxTaskRuntimeProviderSpecifiers = {
2565
2577
  cloudflare: `${sandboxTaskRuntimeSpecifier}/providers/cloudflare`,
2566
2578
  vercel: `${sandboxTaskRuntimeSpecifier}/providers/vercel`
2567
2579
  };
2580
+ /** Only the `vite dev` facade imports the local provider, so builds do not bundle it. */
2581
+ const sandboxTaskRuntimeLocalProviderSpecifier = `${sandboxTaskRuntimeSpecifier}/providers/local`;
2568
2582
  const sandboxTaskRuntimeDependencyByProvider = {
2569
2583
  cloudflare: "@cloudflare/sandbox",
2570
2584
  vercel: "@vercel/sandbox"
@@ -3326,14 +3340,14 @@ function readResolveOptions(config) {
3326
3340
  const resolveOptions = config.resolve;
3327
3341
  return resolveOptions && typeof resolveOptions === "object" ? resolveOptions : {};
3328
3342
  }
3329
- function createSandboxTaskRuntimeFacadeContents(file, runtimeConfig, registryFile, development, providerLoaderImport) {
3343
+ function createSandboxTaskRuntimeFacadeContents(file, runtimeConfig, registryFile, localDev, providerLoaderImport) {
3330
3344
  return [
3331
3345
  `import sandboxTaskRegistry from ${JSON.stringify(createImportPath(file, registryFile))}`,
3332
3346
  ...providerLoaderImport ? [`export { loadSandboxTaskRuntimeProvider } from ${JSON.stringify(providerLoaderImport)}`] : [],
3333
- `import { setSandboxTaskRuntimeConfig, setSandboxTaskRuntimeDevelopment, setSandboxTaskRuntimeRegistry } from ${JSON.stringify(sandboxTaskRuntimeStateSpecifier)}`,
3347
+ `import { setSandboxTaskRuntimeConfig, ${localDev ? "setSandboxTaskRuntimeLocalProvider, " : ""}setSandboxTaskRuntimeRegistry } from ${JSON.stringify(sandboxTaskRuntimeStateSpecifier)}`,
3334
3348
  "",
3335
3349
  `setSandboxTaskRuntimeConfig(${JSON.stringify(runtimeConfig, null, 2)})`,
3336
- `setSandboxTaskRuntimeDevelopment(${development})`,
3350
+ ...localDev ? [`setSandboxTaskRuntimeLocalProvider(async () => (await import(${JSON.stringify(sandboxTaskRuntimeLocalProviderSpecifier)})).resolveLocalTaskSandbox())`] : [],
3337
3351
  "setSandboxTaskRuntimeRegistry(sandboxTaskRegistry)",
3338
3352
  "",
3339
3353
  "export default sandboxTaskRegistry",
@@ -3513,11 +3527,14 @@ async function prepareSandboxTaskRuntime(options) {
3513
3527
  definitions: [],
3514
3528
  files: [],
3515
3529
  hosting: context.hosting,
3530
+ localDev: false,
3516
3531
  provider: void 0,
3517
3532
  rootDir,
3518
3533
  stateModule,
3519
3534
  watchFiles: []
3520
3535
  };
3536
+ const localDev = context.command === "serve" && !context.config.remote;
3537
+ if (localDev && process.platform === "win32") throw sandboxTaskErrorDiagnostics.SANDBOX_TASK_LOCAL_WINDOWS();
3521
3538
  const facadeFile = resolve$1(ensureGeneratedDir(rootDir, "sandbox-task"), "runtime/sandbox-task.mjs");
3522
3539
  const plan = await createSandboxTaskFeaturePlan(context.config, definitions, { aliasPath: facadeFile }, context.deps, context.hosting, {
3523
3540
  bundleAlias: resolveStringAliases(options.resolvedConfig?.resolve.alias ?? readResolveOptions(options.userConfig).alias),
@@ -3532,12 +3549,13 @@ async function prepareSandboxTaskRuntime(options) {
3532
3549
  definitions,
3533
3550
  files: [],
3534
3551
  hosting: context.hosting,
3552
+ localDev,
3535
3553
  provider: getSandboxTaskFeatureDriver(context.config)?.driver,
3536
3554
  rootDir,
3537
3555
  stateModule,
3538
3556
  watchFiles: plan.watchFiles || []
3539
3557
  };
3540
- const emitted = await writeSandboxTaskArtifacts(rootDir, plan, (file, registryFile, providerLoaderImport) => createSandboxTaskRuntimeFacadeContents(file, context.runtimeConfig.sandboxTask, registryFile, context.command === "serve", providerLoaderImport), options.platform);
3558
+ const emitted = await writeSandboxTaskArtifacts(rootDir, plan, (file, registryFile, providerLoaderImport) => createSandboxTaskRuntimeFacadeContents(file, context.runtimeConfig.sandboxTask, registryFile, localDev, providerLoaderImport), options.platform);
3541
3559
  return {
3542
3560
  aliases,
3543
3561
  cloudflare: plan.cloudflare,
@@ -3548,6 +3566,7 @@ async function prepareSandboxTaskRuntime(options) {
3548
3566
  ...(plan.artifacts || []).map((artifact) => resolve$1(ensureGeneratedDir(rootDir, "sandbox-task"), artifact.filename))
3549
3567
  ],
3550
3568
  hosting: context.hosting,
3569
+ localDev,
3551
3570
  provider: getSandboxTaskFeatureDriver(context.config)?.driver,
3552
3571
  rootDir,
3553
3572
  stateModule,
@@ -3555,14 +3574,6 @@ async function prepareSandboxTaskRuntime(options) {
3555
3574
  };
3556
3575
  }
3557
3576
  //#endregion
3558
- //#region ../internal/src/inspect.ts
3559
- function relativeDefinitionFile(projectRoot, file) {
3560
- return relative$1(projectRoot, file).replaceAll("\\", "/");
3561
- }
3562
- const secretKeyPattern = /secret|token|passw(?:or)?d|credential|api[-_\s]?key|private[-_\s]?key|authorization|cookie|signature|dsn|connection[-_\s]?string/i;
3563
- new RegExp(String.raw`\b([\w-]*authorization[\w-]*["']?\s*[:=]\s*)(?!\[redacted\](?=$|[\s,;}&]))(?:"(?:\\[^\r\n]|[^"\\\r\n])*"|'(?:\\[^\r\n]|[^'\\\r\n])*'|[^\r\n]+?(?=\s*(?:[,;])?\s*(?:${secretKeyPattern.source})[\w-]*\s*[:=]|\s+rejected\b|$))`, "gi");
3564
- new RegExp(String.raw`\b([\w-]*(?:${secretKeyPattern.source})[\w-]*["']?\s*[:=]\s*)(?!\[redacted\](?=$|[\s,;}&]))(?:"(?:\\[^\r\n]|[^"\\\r\n])*"|'(?:\\[^\r\n]|[^'\\\r\n])*'|[^\s,;&#&]+)`, "gi");
3565
- //#endregion
3566
3577
  //#region src/task/inspect.ts
3567
3578
  /** Lists Sandbox Task Definitions and package entries as serializable inspection summaries. */
3568
3579
  function inspectSandboxTaskDefinitions(options) {
@@ -3690,6 +3701,7 @@ const sandboxTaskRuntimeStateModule = resolveFeatureRuntimePath(import.meta.url,
3690
3701
  const sandboxTaskRuntimePackageAliases = {
3691
3702
  [sandboxTaskRuntimeProviderSpecifiers.cloudflare]: resolveFeatureRuntimePath(import.meta.url, SANDBOX_PACKAGE_ID, "./runtime/providers/cloudflare", "runtime/providers/cloudflare.js"),
3692
3703
  [sandboxTaskRuntimeProviderSpecifiers.vercel]: resolveFeatureRuntimePath(import.meta.url, SANDBOX_PACKAGE_ID, "./runtime/providers/vercel", "runtime/providers/vercel.js"),
3704
+ [sandboxTaskRuntimeLocalProviderSpecifier]: resolveFeatureRuntimePath(import.meta.url, SANDBOX_PACKAGE_ID, "./runtime/providers/local", "runtime/providers/local.js"),
3693
3705
  [sandboxTaskRuntimeSpecifier]: resolveFeatureRuntimePath(import.meta.url, SANDBOX_PACKAGE_ID, "./index", "index.js"),
3694
3706
  [sandboxTaskRuntimeStateSpecifier]: sandboxTaskRuntimeStateModule
3695
3707
  };
@@ -3782,14 +3794,23 @@ function hubSandboxTask(options) {
3782
3794
  };
3783
3795
  let resolvedConfig;
3784
3796
  let sandboxTaskEnabled = integrationOptions !== false;
3797
+ let localDev = false;
3798
+ let nitroOptions;
3785
3799
  let selectedProvider;
3786
3800
  let earlyNitroTarget;
3787
3801
  let earlyNitroSnapshot;
3788
3802
  let composedCloudflareEarly = false;
3789
3803
  let cloudflareSandbox;
3790
3804
  let sandboxTaskRuntimeRefresh = Promise.resolve();
3805
+ function assertLocalDevRunner() {
3806
+ const devServer = nitroOptions?.devServer;
3807
+ const runner = isPlainRecord(devServer) && devServer.runner || process.env.NITRO_DEV_RUNNER;
3808
+ if (localDev && nitroOptions?.dev && runner === "miniflare") throw sandboxTaskErrorDiagnostics.SANDBOX_TASK_LOCAL_NITRO_RUNNER();
3809
+ }
3791
3810
  const sandboxTaskNitroModule = (nitro) => {
3792
3811
  const options = nitro.options;
3812
+ nitroOptions = options;
3813
+ assertLocalDevRunner();
3793
3814
  mergeSandboxTaskNitroNoExternals(options, selectedProvider);
3794
3815
  if (selectedProvider) mergeSandboxTaskNitroProviderAliases(options, generatedAliases);
3795
3816
  nitro.hooks.hook("build:before", () => {
@@ -3811,6 +3832,8 @@ function hubSandboxTask(options) {
3811
3832
  writeArtifacts
3812
3833
  });
3813
3834
  sandboxTaskStateModule = prepared.stateModule;
3835
+ localDev = prepared.localDev;
3836
+ assertLocalDevRunner();
3814
3837
  return prepared;
3815
3838
  }
3816
3839
  async function activateCurrentSandboxTaskRuntime() {
@@ -1,8 +1,10 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
1
2
  import { r as markBuiltInSandboxRuntime } from "./runtime-DHp6ImeP.js";
2
3
  import { t as sandboxErrorDiagnostics } from "./error-diagnostics-BJtLRL9w.js";
3
4
  import { t as stopMarkedProcesses } from "./process-sweep-CMaujWE5.js";
4
5
  import { a as sandboxRequirementSecrets, i as sandboxRequirementPlan, n as collectSandboxRequirementOutput, o as sandboxRequirementSignal, r as sandboxRequirementError, s as materializeGitCheckout, t as createSandboxSession } from "./session-e0lyzjJ3.js";
5
6
  import { t as acquireFileLock } from "./file-lock-D0-XPogS.js";
7
+ import { t as isTrustedHostReservedCommandEnvironmentKey } from "./trusted-host-environment-CWKJ7DD_.js";
6
8
  import { createHash, randomUUID } from "node:crypto";
7
9
  import { access, chmod, lstat, mkdir, mkdtemp, readFile, readdir, realpath, rename, rm, rmdir, stat, symlink, writeFile } from "node:fs/promises";
8
10
  import { basename, delimiter, dirname, isAbsolute, join, posix, relative, resolve, sep } from "node:path";
@@ -12,6 +14,7 @@ import { tmpdir } from "node:os";
12
14
  import { constants } from "node:fs";
13
15
  import { Readable, Writable } from "node:stream";
14
16
  //#region src/internal/trusted-host.ts
17
+ var trusted_host_exports = /* @__PURE__ */ __exportAll({ createTrustedHostRuntime: () => createTrustedHostRuntime });
15
18
  const baseEnvironmentKeys = [
16
19
  "ComSpec",
17
20
  "LANG",
@@ -28,16 +31,6 @@ const baseEnvironmentKeys = [
28
31
  "TMPDIR",
29
32
  "USER"
30
33
  ];
31
- const runtimeEnvironmentKeys = /* @__PURE__ */ new Set([
32
- "CODEX_HOME",
33
- "HOME",
34
- "INIT_CWD",
35
- "OLDPWD",
36
- "PWD",
37
- "XDG_CACHE_HOME",
38
- "XDG_CONFIG_HOME",
39
- "XDG_STATE_HOME"
40
- ]);
41
34
  const trustedHostExecutionAuthority = {
42
35
  credentials: "unknown",
43
36
  environment: "selected",
@@ -510,7 +503,7 @@ async function createTrustedHostSession(options) {
510
503
  function assertCommandEnvironment(env) {
511
504
  const name = Object.keys(env || {}).find((name) => !/^[A-Za-z_][A-Za-z0-9_]*$/.test(name));
512
505
  if (name) throw sandboxErrorDiagnostics.SANDBOX_R0112({ message: `[vitehub] Invalid Sandbox environment variable: ${name}` });
513
- const reservedName = Object.keys(env || {}).find((name) => runtimeEnvironmentKeys.has(name));
506
+ const reservedName = Object.keys(env || {}).find(isTrustedHostReservedCommandEnvironmentKey);
514
507
  if (reservedName) throw sandboxErrorDiagnostics.SANDBOX_R0137({ message: `[vitehub] Sandbox commands cannot override ${reservedName}.` });
515
508
  }
516
509
  async function validateRequirements(requirements, env, cwd, abortSignal, secrets, includeDiagnosticOutput) {
@@ -711,4 +704,4 @@ function waitForExit(child) {
711
704
  return new Promise((resolvePromise) => child.once("close", () => resolvePromise()));
712
705
  }
713
706
  //#endregion
714
- export { createTrustedHostRuntime };
707
+ export { trusted_host_exports as n, createTrustedHostRuntime as t };
@@ -0,0 +1,16 @@
1
+ //#region src/internal/trusted-host-environment.ts
2
+ const reservedCommandEnvironmentKeys = /* @__PURE__ */ new Set([
3
+ "CODEX_HOME",
4
+ "HOME",
5
+ "INIT_CWD",
6
+ "OLDPWD",
7
+ "PWD",
8
+ "XDG_CACHE_HOME",
9
+ "XDG_CONFIG_HOME",
10
+ "XDG_STATE_HOME"
11
+ ]);
12
+ function isTrustedHostReservedCommandEnvironmentKey(name) {
13
+ return reservedCommandEnvironmentKeys.has(name);
14
+ }
15
+ //#endregion
16
+ export { isTrustedHostReservedCommandEnvironmentKey as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vite-hub/sandbox",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Portable, isolated Sandboxes for ViteHub Agents, and Sandbox Tasks that run named package projects in them.",
5
5
  "keywords": [
6
6
  "agent",
@@ -46,17 +46,17 @@
46
46
  "import": "./dist/index.js",
47
47
  "default": "./dist/index.js"
48
48
  },
49
- "./_internal/cloudflare": {
49
+ "./internal/cloudflare": {
50
50
  "types": "./dist/internal/cloudflare.d.ts",
51
51
  "import": "./dist/internal/cloudflare.js",
52
52
  "default": "./dist/internal/cloudflare.js"
53
53
  },
54
- "./_internal/toolchain": {
54
+ "./internal/toolchain": {
55
55
  "types": "./dist/internal/host-toolchain.d.ts",
56
56
  "import": "./dist/internal/host-toolchain.js",
57
57
  "default": "./dist/internal/host-toolchain.js"
58
58
  },
59
- "./_internal/vercel": {
59
+ "./internal/vercel": {
60
60
  "types": "./dist/internal/vercel.d.ts",
61
61
  "import": "./dist/internal/vercel.js",
62
62
  "default": "./dist/internal/vercel.js"
@@ -92,24 +92,29 @@
92
92
  "default": "./dist/task/vite.js"
93
93
  },
94
94
  "./package.json": "./package.json",
95
- "./_internal/task/runtime": {
95
+ "./internal/task/runtime": {
96
96
  "types": "./dist/task/index.d.ts",
97
97
  "import": "./dist/task/index.js",
98
98
  "default": "./dist/task/index.js"
99
99
  },
100
- "./_internal/task/runtime/providers/cloudflare": {
100
+ "./internal/task/runtime/providers/cloudflare": {
101
101
  "types": "./dist/task/runtime/providers/cloudflare.d.ts",
102
102
  "import": "./dist/task/runtime/providers/cloudflare.js",
103
103
  "default": "./dist/task/runtime/providers/cloudflare.js"
104
104
  },
105
- "./_internal/task/runtime/providers/vercel": {
105
+ "./internal/task/runtime/providers/local": {
106
+ "types": "./dist/task/runtime/providers/local.d.ts",
107
+ "import": "./dist/task/runtime/providers/local.js",
108
+ "default": "./dist/task/runtime/providers/local.js"
109
+ },
110
+ "./internal/task/runtime/providers/vercel": {
106
111
  "types": "./dist/task/runtime/providers/vercel.d.ts",
107
112
  "import": "./dist/task/runtime/providers/vercel.js",
108
113
  "default": "./dist/task/runtime/providers/vercel.js"
109
114
  }
110
115
  },
111
116
  "dependencies": {
112
- "@vite-hub/runtime": "0.3.0",
117
+ "@vite-hub/runtime": "0.4.0",
113
118
  "local-pkg": "^1.2.1",
114
119
  "mlly": "^1.8.2",
115
120
  "nostics": "1.4.0",
@@ -164,7 +169,7 @@
164
169
  }
165
170
  },
166
171
  "engines": {
167
- "node": ">=22.18.0"
172
+ "node": ">=24.15.0"
168
173
  },
169
174
  "scripts": {
170
175
  "build": "vp pack",