@vite-hub/workspace 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 (137) hide show
  1. package/README.md +339 -115
  2. package/dist/abort-BCwpdrN0.js +32 -0
  3. package/dist/{asset-registry-8QI3ML3K.js → asset-registry-DfBV5kmw.js} +3 -2
  4. package/dist/blob-database.d.ts +474 -0
  5. package/dist/blob-database.js +608 -0
  6. package/dist/checkout.d.ts +128 -0
  7. package/dist/checkout.js +849 -0
  8. package/dist/cloudflare.d.ts +6 -7
  9. package/dist/cloudflare.js +1 -1
  10. package/dist/config-B-863EgC.js +15 -0
  11. package/dist/config-BAgL2dtB.js +1076 -0
  12. package/dist/{config-DE9xlaIw.d.ts → config-BQKcPawI.d.ts} +1 -2
  13. package/dist/discard-CNNtCozM.js +8 -0
  14. package/dist/durability.d.ts +22 -0
  15. package/dist/durability.js +70 -0
  16. package/dist/error-diagnostics-CtKjGtGb.js +188 -0
  17. package/dist/error-diagnostics-DSkCJC_L.js +266 -0
  18. package/dist/file-2pFYNtsU.js +22 -0
  19. package/dist/{files-Q6xZjDHA.js → files-BOo4SbwE.js} +3 -3
  20. package/dist/files.d.ts +38 -0
  21. package/dist/files.js +6 -0
  22. package/dist/{github-DHnjxQIX.js → github-CrYp4v8k.js} +44 -24
  23. package/dist/glob-B8YGvTrZ.js +21 -0
  24. package/dist/glob-Cjxms1t7.js +30 -0
  25. package/dist/{host-DJH8cuoU.js → host-BFBpXn0N.js} +144 -77
  26. package/dist/{hosted-RPeJOCFz.js → hosted-KcUR_jPv.js} +303 -97
  27. package/dist/hosted-vercel-blob-B3-wRdUm.js +410 -0
  28. package/dist/hosted-vercel-blob.d.ts +6 -7
  29. package/dist/hosted-vercel-blob.js +1 -1
  30. package/dist/hosted.d.ts +10 -9
  31. package/dist/hosted.js +2 -2
  32. package/dist/index.d.ts +26 -47
  33. package/dist/index.js +30 -100
  34. package/dist/internal/path.d.ts +2 -0
  35. package/dist/internal/path.js +2 -0
  36. package/dist/lifecycle-B-enk_4A.js +596 -0
  37. package/dist/lineage.d.ts +26 -0
  38. package/dist/lineage.js +76 -0
  39. package/dist/loader.d.ts +5 -6
  40. package/dist/loader.js +3 -2
  41. package/dist/mcp-resources-DF0F5rcL.js +39 -0
  42. package/dist/memory-BOexthyW.js +247 -0
  43. package/dist/metadata-target-CWz6KHKq.js +1589 -0
  44. package/dist/object-Da1zyPCR.js +11 -0
  45. package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
  46. package/dist/operations-C6FpR8Rr.js +389 -0
  47. package/dist/operations-CE2drFih.js +1234 -0
  48. package/dist/operations.d.ts +90 -0
  49. package/dist/operations.js +3 -0
  50. package/dist/path--wrT_Azm.js +113 -0
  51. package/dist/path-AxMho1wo.d.ts +7 -0
  52. package/dist/path-DrSIenjj.js +59 -0
  53. package/dist/path-zHxQUbqa.d.ts +9 -0
  54. package/dist/plugins-C8C0auoW.d.ts +10 -0
  55. package/dist/provider-9s4Ufkm5.js +1479 -0
  56. package/dist/providers/github/store.d.ts +3 -5
  57. package/dist/providers/github/store.js +1 -1
  58. package/dist/registry-B3BBm4Ts.d.ts +19 -0
  59. package/dist/{registry-D3yzt8HQ.js → registry-CNphafBx.js} +60 -23
  60. package/dist/registry-CYNN623b.d.ts +9 -0
  61. package/dist/request-scope-Dw5n8bMC.js +83 -0
  62. package/dist/results-DgkZUmTL.js +8 -0
  63. package/dist/{chunk-2rV9d50f.js → rolldown-runtime-rQ84J-ij.js} +3 -4
  64. package/dist/runtime/assets.d.ts +3 -5
  65. package/dist/runtime/assets.js +7 -6
  66. package/dist/runtime/empty-assets-registry.d.ts +1 -2
  67. package/dist/runtime/empty-registry.d.ts +2 -2
  68. package/dist/runtime/registry.d.ts +2 -0
  69. package/dist/runtime/registry.js +23 -0
  70. package/dist/runtime/request.d.ts +4 -0
  71. package/dist/runtime/request.js +8 -0
  72. package/dist/runtime/state.d.ts +5 -4
  73. package/dist/runtime/state.js +8 -18
  74. package/dist/runtime/workspace.d.ts +1 -1
  75. package/dist/runtime/workspace.js +1 -1
  76. package/dist/runtime.d.ts +52 -17
  77. package/dist/runtime.js +324 -67
  78. package/dist/{search-BpiCF2Tw.js → search-C_RfoM2j.js} +10 -9
  79. package/dist/server-8tGltlGz.js +303 -0
  80. package/dist/server.d.ts +36 -39
  81. package/dist/server.js +2 -328
  82. package/dist/shared-B3_EUk89.js +848 -0
  83. package/dist/source-metadata.d.ts +10 -7
  84. package/dist/source-metadata.js +12 -12
  85. package/dist/state-BISnUf1s.d.ts +35 -0
  86. package/dist/{ai-BqCC8BpY.js → state-DbrW-njQ.js} +237 -114
  87. package/dist/store-ybhyD38Z.js +1873 -0
  88. package/dist/{sync-DnTQwt8r.js → sync-CCD_VYC8.js} +61 -41
  89. package/dist/target-jWhTdIuF.js +89 -0
  90. package/dist/test.d.ts +1 -1
  91. package/dist/test.js +1 -1
  92. package/dist/{types-CYuwjJ4V.d.ts → types-BbtwmBZ5.d.ts} +321 -35
  93. package/dist/use-C6lV3-wC.d.ts +321 -0
  94. package/dist/{use-BTNDR5Rd.js → use-CSpT5W87.js} +141 -107
  95. package/dist/utils-CgMZCHsX.js +616 -0
  96. package/dist/vite.d.ts +585 -2
  97. package/dist/vite.js +21369 -2
  98. package/dist/workspace-CYB2xZ1T.d.ts +7 -0
  99. package/dist/{workspace-Dq08Yn72.js → workspace-sPWn2Jxj.js} +441 -225
  100. package/package.json +97 -72
  101. package/dist/ai-CjxvGqM0.d.ts +0 -162
  102. package/dist/ai.d.ts +0 -3
  103. package/dist/ai.js +0 -2
  104. package/dist/collections/client.d.ts +0 -39
  105. package/dist/collections/client.js +0 -137
  106. package/dist/collections.d.ts +0 -59
  107. package/dist/collections.js +0 -159
  108. package/dist/config-Bc3c4Su1.js +0 -7904
  109. package/dist/config-CHLLWklZ.js +0 -36
  110. package/dist/file-Bc1X7pco.js +0 -23
  111. package/dist/glob-CEZKeZFC.js +0 -18
  112. package/dist/hosted-vercel-blob-d6C8ND5j.js +0 -23580
  113. package/dist/lifecycle-LrL3sA4n.js +0 -316
  114. package/dist/metadata-target-B0tOmVW7.js +0 -717
  115. package/dist/mountx.d.ts +0 -10
  116. package/dist/mountx.js +0 -143
  117. package/dist/nitro.d.ts +0 -2
  118. package/dist/nitro.js +0 -2
  119. package/dist/nuxt.d.ts +0 -26
  120. package/dist/nuxt.js +0 -42
  121. package/dist/path-Cp59koVz.js +0 -139
  122. package/dist/provider-B1yLjCJJ.js +0 -746
  123. package/dist/publish.d.ts +0 -35
  124. package/dist/publish.js +0 -112
  125. package/dist/registry-Uj6IVxes.d.ts +0 -11
  126. package/dist/request-execution-B-dSFlGB.js +0 -84
  127. package/dist/runtime-options-BsPSv5O7.js +0 -13
  128. package/dist/runtime-type-iEE6BjQJ.js +0 -34
  129. package/dist/shared-DTR1Hhma.js +0 -331
  130. package/dist/state-tYcRWEh2.d.ts +0 -26
  131. package/dist/store-Dt_Jyys3.js +0 -608
  132. package/dist/target-D4Bqb1eH.js +0 -11
  133. package/dist/token-CVzURBxC.js +0 -61
  134. package/dist/use-BiHzt0xA.d.ts +0 -103
  135. package/dist/vite-BptCrpv2.js +0 -4526
  136. package/dist/vite-CtA9guIM.d.ts +0 -66
  137. package/dist/workspace-Xddf4G1B.d.ts +0 -6
@@ -1,9 +1,12 @@
1
- import { jt as WorkspaceSourceMaterializationStatus, z as WorkspaceEntry } from "./types-CYuwjJ4V.js";
2
- import { i as workspaceSourceGrantPaths, n as normalizeWorkspaceSourceMetadata, r as normalizeWorkspaceSourcesMetadata, t as WorkspaceSourceMetadata } from "./config-DE9xlaIw.js";
3
-
1
+ import { $t as WorkspaceSourceMaterializationStatus, B as WorkspaceEntry, Pt as WorkspaceRules } from "./types-BbtwmBZ5.js";
2
+ import { i as workspaceSourceGrantPaths, n as normalizeWorkspaceSourceMetadata, r as normalizeWorkspaceSourcesMetadata, t as WorkspaceSourceMetadata } from "./config-BQKcPawI.js";
3
+ //#region src/core/rule-keys.d.ts
4
+ /** Rejects rule keys that ViteHub does not enforce, such as `read`, so that a rule never looks like a protection it is not. */
5
+ export declare function assertWorkspaceRules(rules: WorkspaceRules | undefined): void;
6
+ //#endregion
4
7
  //#region src/source-metadata.d.ts
5
- declare function listMaterializedWorkspaceEntries(workspace: unknown): Promise<WorkspaceEntry[] | undefined>;
6
- declare function listMaterializedWorkspaceSourceEntries(workspace: unknown, source: WorkspaceSourceMetadata): Promise<WorkspaceEntry[] | undefined>;
7
- declare function readWorkspaceSourceMaterializationStatus(workspace: unknown, source: WorkspaceSourceMetadata): Promise<WorkspaceSourceMaterializationStatus | undefined>;
8
+ export declare function listMaterializedWorkspaceEntries(workspace: unknown): Promise<WorkspaceEntry[] | undefined>;
9
+ export declare function listMaterializedWorkspaceSourceEntries(workspace: unknown, source: WorkspaceSourceMetadata): Promise<WorkspaceEntry[] | undefined>;
10
+ export declare function readWorkspaceSourceMaterializationStatus(workspace: unknown, source: WorkspaceSourceMetadata): Promise<WorkspaceSourceMaterializationStatus | undefined>;
8
11
  //#endregion
9
- export { type WorkspaceSourceMetadata, listMaterializedWorkspaceEntries, listMaterializedWorkspaceSourceEntries, normalizeWorkspaceSourceMetadata, normalizeWorkspaceSourcesMetadata, readWorkspaceSourceMaterializationStatus, workspaceSourceGrantPaths };
12
+ export { type WorkspaceSourceMetadata, normalizeWorkspaceSourceMetadata, normalizeWorkspaceSourcesMetadata, workspaceSourceGrantPaths };
@@ -1,14 +1,14 @@
1
- import { i as normalizeWorkspaceSourceMetadata, l as workspaceSourceGrantPaths, o as normalizeWorkspaceSourcesMetadata } from "./config-Bc3c4Su1.js";
2
- import { t as hasRuntimeType } from "./runtime-type-iEE6BjQJ.js";
3
- import { c as readCurrentSourceSnapshot, n as resolveWorkspaceMetadataTarget } from "./metadata-target-B0tOmVW7.js";
1
+ import { i as assertWorkspaceRules } from "./target-jWhTdIuF.js";
2
+ import { i as normalizeWorkspaceSourceMetadata, l as workspaceSourceGrantPaths, o as normalizeWorkspaceSourcesMetadata } from "./config-BAgL2dtB.js";
3
+ import { m as readCurrentSourceSnapshot, o as resolveWorkspaceMetadataTarget } from "./metadata-target-CWz6KHKq.js";
4
4
  //#region src/source-metadata.ts
5
5
  async function listMaterializedWorkspaceEntries(workspace) {
6
6
  return await (await resolveWorkspaceMetadataTarget(workspace))?.list?.("", { recursive: true });
7
7
  }
8
8
  async function listMaterializedWorkspaceSourceEntries(workspace, source) {
9
9
  const metadata = await resolveWorkspaceMetadataTarget(workspace);
10
- if (!metadata?.list) return;
11
- const snapshot = await readCurrentSourceSnapshot(metadata, source);
10
+ if (!metadata?.list || metadata.workspaceName === void 0) return;
11
+ const snapshot = await readCurrentSourceSnapshot(metadata, metadata.workspaceName, source);
12
12
  if (!snapshot) return [];
13
13
  const ownedPaths = new Set(Object.keys(snapshot.items || {}));
14
14
  return (await metadata.list("", { recursive: true })).filter((entry) => {
@@ -18,17 +18,17 @@ async function listMaterializedWorkspaceSourceEntries(workspace, source) {
18
18
  }
19
19
  async function readWorkspaceSourceMaterializationStatus(workspace, source) {
20
20
  const metadata = await resolveWorkspaceMetadataTarget(workspace);
21
- if (!metadata) return;
22
- const snapshot = await readCurrentSourceSnapshot(metadata, source);
23
- if (!hasRuntimeType(snapshot, "object") || snapshot === null) return;
21
+ if (metadata?.workspaceName === void 0) return;
22
+ const snapshot = await readCurrentSourceSnapshot(metadata, metadata.workspaceName, source);
23
+ if (typeof snapshot !== "object" || snapshot === null) return;
24
24
  const status = snapshot.status;
25
25
  if (status !== "lazy" && status !== "updating" && status !== "ready" && status !== "error") return;
26
26
  return {
27
- materializedAt: hasRuntimeType(snapshot.materializedAt, "string") ? snapshot.materializedAt : void 0,
28
- mountPath: hasRuntimeType(snapshot.mountPath, "string") ? snapshot.mountPath : "",
29
- source: hasRuntimeType(snapshot.source, "string") ? snapshot.source : source.key,
27
+ materializedAt: typeof snapshot.materializedAt === "string" ? snapshot.materializedAt : void 0,
28
+ mountPath: typeof snapshot.mountPath === "string" ? snapshot.mountPath : "",
29
+ source: typeof snapshot.source === "string" ? snapshot.source : source.key,
30
30
  status
31
31
  };
32
32
  }
33
33
  //#endregion
34
- export { listMaterializedWorkspaceEntries, listMaterializedWorkspaceSourceEntries, normalizeWorkspaceSourceMetadata, normalizeWorkspaceSourcesMetadata, readWorkspaceSourceMaterializationStatus, workspaceSourceGrantPaths };
34
+ export { assertWorkspaceRules, listMaterializedWorkspaceEntries, listMaterializedWorkspaceSourceEntries, normalizeWorkspaceSourceMetadata, normalizeWorkspaceSourcesMetadata, readWorkspaceSourceMaterializationStatus, workspaceSourceGrantPaths };
@@ -0,0 +1,35 @@
1
+ import { O as WorkspaceAssetsRegistry, St as WorkspaceName, s as GitHubWorkspaceStoreOptions, t as CloudflareArtifactsWorkspaceStoreOptions, w as VercelBlobWorkspaceStoreOptions, xn as WorkspaceStore } from "./types-BbtwmBZ5.js";
2
+ import { h as WritableWorkspaceFacade, i as ReadonlyWorkspaceFacade, s as UseWorkspaceOptions } from "./use-C6lV3-wC.js";
3
+ import { t as WorkspaceRegistry } from "./registry-B3BBm4Ts.js";
4
+ import "./registry-CYNN623b.js";
5
+ //#region ../internal/src/runtime/cloudflare-env-lookup.d.ts
6
+ type CloudflareWorkerEnv = Record<string, unknown>;
7
+ //#endregion
8
+ //#region ../internal/src/runtime/cloudflare-env.d.ts
9
+ declare function setActiveCloudflareEnv(env: CloudflareWorkerEnv | undefined): void;
10
+ //#endregion
11
+ //#region src/core/use-tools.d.ts
12
+ declare function useWorkspace<Name extends WorkspaceName>(name: Name): ReadonlyWorkspaceFacade<Name>;
13
+ declare function useWorkspace<Name extends WorkspaceName>(name: Name, options: UseWorkspaceOptions & {
14
+ mode?: "read";
15
+ }): ReadonlyWorkspaceFacade<Name>;
16
+ declare function useWorkspace<Name extends WorkspaceName>(name: Name, options: UseWorkspaceOptions & {
17
+ mode: "write";
18
+ }): WritableWorkspaceFacade<Name>;
19
+ //#endregion
20
+ //#region src/core/workspace-cache.d.ts
21
+ declare function resetWorkspaceStoreCache(): void;
22
+ //#endregion
23
+ //#region src/runtime/hosted-store-loader.d.ts
24
+ type HostedWorkspaceStoreOptions = CloudflareArtifactsWorkspaceStoreOptions | GitHubWorkspaceStoreOptions | VercelBlobWorkspaceStoreOptions;
25
+ /** Returns `undefined` when no installed hosted store handles `options.provider`. */
26
+ type WorkspaceHostedStoreLoader = (options: HostedWorkspaceStoreOptions, workspaceName: string) => WorkspaceStore | undefined;
27
+ declare function setWorkspaceHostedStoreLoader(loader: WorkspaceHostedStoreLoader | undefined): void;
28
+ declare function getWorkspaceHostedStoreLoader(): WorkspaceHostedStoreLoader | undefined;
29
+ //#endregion
30
+ //#region src/runtime/state.d.ts
31
+ declare function invalidateWorkspaceStore(name: string): Promise<void>;
32
+ declare function setWorkspaceRuntimeRegistry(registry: WorkspaceRegistry): void;
33
+ declare function setWorkspaceRuntimeAssetsRegistry(registry: WorkspaceAssetsRegistry): void;
34
+ //#endregion
35
+ export { WorkspaceHostedStoreLoader as a, resetWorkspaceStoreCache as c, HostedWorkspaceStoreOptions as i, useWorkspace as l, setWorkspaceRuntimeAssetsRegistry as n, getWorkspaceHostedStoreLoader as o, setWorkspaceRuntimeRegistry as r, setWorkspaceHostedStoreLoader as s, invalidateWorkspaceStore as t, setActiveCloudflareEnv as u };
@@ -1,44 +1,10 @@
1
- import { _ as workspaceError, h as isWorkspaceError, s as normalizeSafeWorkspacePath } from "./path-Cp59koVz.js";
2
- import { r as getWorkspaceSourceRequestExecution } from "./request-execution-B-dSFlGB.js";
3
- import { posix } from "node:path";
4
- //#region src/fs-ops.ts
5
- async function ensureMissingOrReplaceable(workspace, path, overwrite = false) {
6
- if (!await workspace.exists(path)) return;
7
- if (!overwrite) throw workspaceError(`[vitehub] Workspace path already exists: ${path}.`);
8
- await workspace.rm(path, {
9
- recursive: true,
10
- force: true
11
- });
12
- }
13
- async function copyWorkspacePath(workspace, from, to, overwrite = false) {
14
- if (from === to) throw workspaceError("[vitehub] Source and destination must be different.");
15
- const source = await workspace.stat(from);
16
- if (source.type === "directory" && to.startsWith(`${from}/`)) throw workspaceError("[vitehub] Destination cannot be nested inside the source directory.");
17
- await ensureMissingOrReplaceable(workspace, to, overwrite);
18
- if (source.type === "file") {
19
- const content = await workspace.readFile(from, { encoding: "binary" });
20
- await workspace.writeFile(to, content, { mediaType: source.mediaType });
21
- return;
22
- }
23
- const entries = await workspace.list(from, { recursive: true });
24
- await workspace.mkdir(to, { recursive: true });
25
- const directories = entries.filter((entry) => entry.type === "directory").sort((left, right) => left.path.length - right.path.length);
26
- for (const entry of directories) await workspace.mkdir(posix.join(to, posix.relative(from, entry.path)), { recursive: true });
27
- await Promise.all(entries.filter((entry) => entry.type === "file").map(async (entry) => {
28
- const content = await workspace.readFile(entry.path, { encoding: "binary" });
29
- await workspace.writeFile(posix.join(to, posix.relative(from, entry.path)), content, { mediaType: entry.mediaType });
30
- }));
31
- }
32
- async function appendWorkspaceFile(workspace, path, content) {
33
- let current = "";
34
- try {
35
- current = String(await workspace.readFile(path));
36
- } catch (error) {
37
- if (!isWorkspaceError(error)) throw error;
38
- }
39
- await workspace.writeFile(path, `${current}${content}`);
40
- }
41
- //#endregion
1
+ import { s as workspaceError, t as normalizeSafeWorkspacePath } from "./path-DrSIenjj.js";
2
+ import { t as workspaceErrorDiagnostics } from "./error-diagnostics-CtKjGtGb.js";
3
+ import { g as getWorkspaceSourceRequestExecution, n as invalidateCachedWorkspaceStore } from "./workspace-sPWn2Jxj.js";
4
+ import { i as setWorkspaceRegistry, r as resolveRegisteredWorkspaceDefinition } from "./registry-CNphafBx.js";
5
+ import { t as setWorkspaceAssetsRegistry } from "./asset-registry-DfBV5kmw.js";
6
+ import { a as copyWorkspacePath, i as appendWorkspaceFile, n as createWorkspaceFileRuntime, t as createReadonlyFs } from "./use-CSpT5W87.js";
7
+ import { executionBudgetCharged, executionBudgetOverride, markExecutionBudgetHandled } from "@vite-hub/runtime/internal/execution-budget";
42
8
  //#region src/runtime/dependency-loaders.ts
43
9
  const shellWorkspaceSpecifier = "@vite-hub/shell/workspace";
44
10
  const defaultWorkspaceDependencyRuntimeLoaders = { shellWorkspace: () => import(
@@ -95,12 +61,30 @@ function tool(definition) {
95
61
  return definition;
96
62
  }
97
63
  function isWorkspace(input) {
98
- return "sync" in input;
64
+ return hasOwnMethod(input, "sync");
65
+ }
66
+ function hasWriteCapabilities(workspace, enabled) {
67
+ const required = /* @__PURE__ */ new Set();
68
+ if (enabled.writeFile || enabled.appendFile) required.add("writeFile");
69
+ if (enabled.appendFile) required.add("readFile");
70
+ if (enabled.deletePath || enabled.movePath) required.add("rm");
71
+ if (enabled.makeDir || enabled.copyPath || enabled.movePath) required.add("mkdir");
72
+ if (enabled.copyPath || enabled.movePath) {
73
+ required.add("writeFile");
74
+ required.add("stat");
75
+ required.add("exists");
76
+ required.add("readFile");
77
+ required.add("list");
78
+ }
79
+ return [...required].every((key) => hasOwnMethod(workspace, key));
99
80
  }
100
81
  function getWorkspaceSessionStarter(input) {
101
- return typeof input.startSession === "function" ? input : void 0;
82
+ return hasOwnMethod(input, "startSession") ? input : void 0;
102
83
  }
103
- function createWorkspaceSessionShellProvider(starter) {
84
+ function hasOwnMethod(value, key) {
85
+ return Object.hasOwn(value, key) && typeof Reflect.get(value, key) === "function";
86
+ }
87
+ function createWorkspaceSessionShellDriver(starter) {
104
88
  return {
105
89
  boundary: {
106
90
  cwd: true,
@@ -121,12 +105,16 @@ function createWorkspaceSessionShellProvider(starter) {
121
105
  }
122
106
  },
123
107
  async exec(command, execOptions = {}) {
124
- const session = await starter.startSession({ paths: execOptions.workspacePaths });
108
+ const session = await starter.startSession({
109
+ ...execOptions.signal ? { abortSignal: execOptions.signal } : {},
110
+ paths: execOptions.workspacePaths
111
+ });
125
112
  let observation;
126
113
  try {
127
- const result = await session.exec("sh", ["-lc", command], {
114
+ const result = await session.exec("sh", ["-c", command], {
128
115
  cwd: execOptions.cwd || workspaceMountPoint,
129
116
  env: execOptions.env,
117
+ ...execOptions.signal ? { abortSignal: execOptions.signal } : {},
130
118
  timeout: execOptions.timeout
131
119
  });
132
120
  execOptions.onStdout?.(result.stdout);
@@ -154,19 +142,19 @@ function createWorkspaceSessionShellProvider(starter) {
154
142
  }
155
143
  };
156
144
  }
157
- async function resolveExecutionProvider(provider) {
158
- return typeof provider === "function" ? await provider() : provider;
145
+ async function resolveShellDriver(driver) {
146
+ return typeof driver === "function" ? await driver() : driver;
159
147
  }
160
148
  function isUnavailableWorkspaceSession(error) {
161
149
  const message = error instanceof Error ? error.message : String(error);
162
- return message.includes("Workspace exec requires an executable runtime") || message.includes("Workspace exec requires a Box session host") || message.includes("Workspace") && message.includes("is not registered");
150
+ return message.includes("Workspace exec requires an executable runtime") || message.includes("Workspace exec requires a Sandbox session host") || message.includes("Workspace") && message.includes("is not registered");
163
151
  }
164
152
  function cleanWorkspaceShellPath(path) {
165
153
  return normalizeSafeWorkspacePath(path.replace(/^\/workspace(?:\/|$)/, ""), { allowEmpty: true });
166
154
  }
167
155
  function cleanMutationPath(path) {
168
156
  const normalized = cleanWorkspaceShellPath(path);
169
- if (!normalized) throw new Error("[vitehub] Workspace root is not a valid mutation target.");
157
+ if (!normalized) throw workspaceErrorDiagnostics.WORKSPACE_R0001({ message: "[vitehub] Workspace root is not a valid mutation target." });
170
158
  return normalized;
171
159
  }
172
160
  function resolveReadOperations(operations) {
@@ -236,34 +224,41 @@ async function runShellCommand(input, command, options) {
236
224
  const networkGrants = getWorkspaceSourceRequestExecution(input);
237
225
  const { createReadonlyWorkspaceFs, runWorkspaceInspectionCommand } = await loadWorkspaceShellModule();
238
226
  const inspectionOptions = {
227
+ budget: options.budget,
228
+ budgetCharged: options.budgetCharged,
239
229
  broadSearchPaths: options.broadSearchPaths,
240
- commands: networkGrants ? [...options.commands, "curl"] : options.commands,
230
+ commands: options.commands,
241
231
  cwd: options.cwd,
242
232
  fs: createReadonlyWorkspaceFs(input),
243
233
  maxOutputLength: options.maxOutputLength,
244
234
  networkGrants,
235
+ signal: options.budget ? options.signal ? AbortSignal.any([options.signal, options.budget.signal]) : options.budget.signal : options.signal,
245
236
  timeout: options.timeout
246
237
  };
247
238
  const starter = getWorkspaceSessionStarter(input);
248
239
  if (starter) try {
249
- return await runWorkspaceInspectionCommand(input, command, {
240
+ const result = await runWorkspaceInspectionCommand(input, command, {
250
241
  ...inspectionOptions,
251
- provider: createWorkspaceSessionShellProvider(starter)
242
+ driver: createWorkspaceSessionShellDriver(starter)
252
243
  });
244
+ if (options.budget?.signal.aborted) throw options.budget.signal.reason;
245
+ return result;
253
246
  } catch (error) {
254
247
  if (!isUnavailableWorkspaceSession(error)) throw error;
255
248
  }
256
- const provider = await resolveExecutionProvider(options.executionProvider);
257
- return await runWorkspaceInspectionCommand(input, command, {
249
+ const driver = await resolveShellDriver(options.shellDriver);
250
+ const result = await runWorkspaceInspectionCommand(input, command, {
258
251
  ...inspectionOptions,
259
- ...provider ? { provider } : {}
252
+ ...driver ? { driver } : {}
260
253
  });
254
+ if (options.budget?.signal.aborted) throw options.budget.signal.reason;
255
+ return result;
261
256
  }
262
257
  function sizeOf(content) {
263
258
  return typeof content === "string" ? new TextEncoder().encode(content).byteLength : content.byteLength;
264
259
  }
265
260
  async function materializeWorkspaceSourcesTool(input, options) {
266
- if ("materializeSources" in input && typeof input.materializeSources === "function") return await input.materializeSources(options);
261
+ if (hasOwnMethod(input, "materializeSources") && typeof input.materializeSources === "function") return await input.materializeSources(options);
267
262
  const started = Date.now();
268
263
  const path = cleanWorkspaceShellPath(options.path || "") || "";
269
264
  const entries = await input.list(path, { recursive: true });
@@ -288,7 +283,15 @@ async function materializeWorkspaceSourcesTool(input, options) {
288
283
  sources: []
289
284
  };
290
285
  }
291
- function createWriteTools(workspace, enabled) {
286
+ function createWriteTools(workspace, enabled, budget) {
287
+ const charge = (executionOptions, inputBytes = 0) => {
288
+ if (!Boolean(executionOptions?.[executionBudgetCharged])) try {
289
+ budget?.recordToolCall(inputBytes);
290
+ } catch (error) {
291
+ budget?.cancel(error);
292
+ throw error;
293
+ }
294
+ };
292
295
  const result = {};
293
296
  if (enabled.writeFile) result.writeFile = tool({
294
297
  description: "Write a text file to the workspace.",
@@ -302,7 +305,8 @@ function createWriteTools(workspace, enabled) {
302
305
  required: ["path", "content"],
303
306
  type: "object"
304
307
  }),
305
- execute: async ({ content, mediaType, path }) => {
308
+ execute: async ({ content, mediaType, path }, executionOptions) => {
309
+ charge(executionOptions, sizeOf(content));
306
310
  const normalized = cleanMutationPath(path);
307
311
  await workspace.writeFile(normalized, content, { mediaType });
308
312
  return { path: normalized };
@@ -319,7 +323,8 @@ function createWriteTools(workspace, enabled) {
319
323
  required: ["path", "content"],
320
324
  type: "object"
321
325
  }),
322
- execute: async ({ content, path }) => {
326
+ execute: async ({ content, path }, executionOptions) => {
327
+ charge(executionOptions, sizeOf(content));
323
328
  const normalized = cleanMutationPath(path);
324
329
  await appendWorkspaceFile(workspace, normalized, content);
325
330
  return { path: normalized };
@@ -337,7 +342,8 @@ function createWriteTools(workspace, enabled) {
337
342
  required: ["path"],
338
343
  type: "object"
339
344
  }),
340
- execute: async ({ force, path, recursive }) => {
345
+ execute: async ({ force, path, recursive }, executionOptions) => {
346
+ charge(executionOptions);
341
347
  const normalized = cleanMutationPath(path);
342
348
  await workspace.rm(normalized, {
343
349
  force,
@@ -357,7 +363,8 @@ function createWriteTools(workspace, enabled) {
357
363
  required: ["path"],
358
364
  type: "object"
359
365
  }),
360
- execute: async ({ path, recursive }) => {
366
+ execute: async ({ path, recursive }, executionOptions) => {
367
+ charge(executionOptions);
361
368
  const normalized = cleanMutationPath(path);
362
369
  await workspace.mkdir(normalized, { recursive });
363
370
  return { path: normalized };
@@ -375,7 +382,8 @@ function createWriteTools(workspace, enabled) {
375
382
  required: ["from", "to"],
376
383
  type: "object"
377
384
  }),
378
- execute: async ({ from, overwrite = false, to }) => {
385
+ execute: async ({ from, overwrite = false, to }, executionOptions) => {
386
+ charge(executionOptions);
379
387
  const source = cleanMutationPath(from);
380
388
  const target = cleanMutationPath(to);
381
389
  await copyWorkspacePath(workspace, source, target, overwrite);
@@ -397,7 +405,8 @@ function createWriteTools(workspace, enabled) {
397
405
  required: ["from", "to"],
398
406
  type: "object"
399
407
  }),
400
- execute: async ({ from, overwrite = false, to }) => {
408
+ execute: async ({ from, overwrite = false, to }, executionOptions) => {
409
+ charge(executionOptions);
401
410
  const source = cleanMutationPath(from);
402
411
  const target = cleanMutationPath(to);
403
412
  await copyWorkspacePath(workspace, source, target, overwrite);
@@ -418,66 +427,180 @@ function createWorkspaceTools(input, options = {}) {
418
427
  broadSearchPaths: options.broadSearchPaths || [],
419
428
  commands: shellCommandsFor(resolveReadOperations(options.operations)),
420
429
  cwd: options.cwd || workspaceMountPoint,
421
- executionProvider: options.executionProvider,
430
+ shellDriver: options.shellDriver,
431
+ budget: options.executionBudget,
422
432
  materialize: resolveReadOperations(options.operations).materialize,
423
433
  maxShellCalls: options.maxShellCalls,
424
- maxOutputLength: options.maxOutputLength || defaultMaxOutputLength,
434
+ maxOutputLength: options.maxOutputLength ?? defaultMaxOutputLength,
425
435
  timeout: options.timeout,
426
436
  write: resolveWriteOperations(options.operations?.write)
427
437
  };
438
+ if (options.sourceRequests && getWorkspaceSourceRequestExecution(input)) resolved.commands.push("curl");
428
439
  let shellCalls = 0;
429
440
  const writeEnabled = Object.values(resolved.write).some(Boolean);
430
- if (!resolved.commands.length && !resolved.materialize && !writeEnabled) throw new TypeError("[vitehub] createWorkspaceTools requires at least one enabled workspace operation.");
431
- if (writeEnabled && !isWorkspace(input)) throw new TypeError("[vitehub] Write operations require a mutable Workspace. A useWorkspace(name, { mode: \"write\" }).tools.write() call provides one.");
441
+ if (!resolved.commands.length && !resolved.materialize && !writeEnabled) throw workspaceErrorDiagnostics.WORKSPACE_R0002({ message: "[vitehub] createWorkspaceTools requires at least one enabled workspace operation." });
442
+ if (writeEnabled && (!isWorkspace(input) || !hasWriteCapabilities(input, resolved.write))) throw workspaceErrorDiagnostics.WORKSPACE_R0003({ message: "[vitehub] Write operations require a mutable Workspace. A useWorkspace(name, { mode: \"write\" }).tools.write() call provides one." });
432
443
  const result = {};
433
- if (resolved.commands.length) result.shell = tool({
434
- description: describeShellCommands(resolved.commands, { sourceRequests: Boolean(getWorkspaceSourceRequestExecution(input)) }),
435
- inputSchema: jsonSchema({
436
- additionalProperties: false,
437
- properties: { command: {
438
- description: "A Bash-compatible workspace shell command. Use pipes, redirects, chaining, and quoted patterns as needed.",
439
- type: "string"
440
- } },
441
- required: ["command"],
442
- type: "object"
443
- }),
444
- execute: async ({ command }) => {
445
- if (typeof resolved.maxShellCalls === "number" && shellCalls >= resolved.maxShellCalls) return {
446
- command,
447
- cwd: resolved.cwd,
448
- event: "policy_denied",
449
- exitCode: 126,
450
- stderr: `[vitehub] Workspace shell command budget exhausted after ${resolved.maxShellCalls} calls. The Workspace Tools shell call budget is exhausted for this run.\n`,
451
- stdout: ""
452
- };
453
- shellCalls += 1;
454
- return await runShellCommand(input, command, resolved);
455
- }
456
- });
457
- if (resolved.materialize) result.materialize_sources = tool({
458
- description: ["Materialize complete workspace source snapshots as an explicit tool step before shell inspection.", "This prepares whole sources, not individual files or partial limits."].join(" "),
459
- inputSchema: jsonSchema({
460
- additionalProperties: false,
461
- properties: {
462
- path: {
463
- description: "Workspace path prefix to materialize. Defaults to the workspace root.",
444
+ if (resolved.commands.length) {
445
+ result.shell = Object.assign(tool({
446
+ description: describeShellCommands(resolved.commands, { sourceRequests: resolved.commands.includes("curl") }),
447
+ inputSchema: jsonSchema({
448
+ additionalProperties: false,
449
+ properties: { command: {
450
+ description: "A Bash-compatible workspace shell command. Use pipes, redirects, chaining, and quoted patterns as needed.",
464
451
  type: "string"
465
- },
466
- sources: {
467
- description: "Optional source names to materialize.",
468
- items: { type: "string" },
469
- type: "array"
452
+ } },
453
+ required: ["command"],
454
+ type: "object"
455
+ }),
456
+ execute: async ({ command }, executionOptions) => {
457
+ const abortSignal = executionOptions?.abortSignal;
458
+ const executionBudget = executionOptions?.[executionBudgetOverride] ?? resolved.budget;
459
+ if (typeof resolved.maxShellCalls === "number" && shellCalls >= resolved.maxShellCalls) return {
460
+ command,
461
+ cwd: resolved.cwd,
462
+ event: "policy_denied",
463
+ exitCode: 126,
464
+ stderr: `[vitehub] Workspace shell command budget exhausted after ${resolved.maxShellCalls} calls. The Workspace Tools shell call budget is exhausted for this run.\n`,
465
+ stdout: ""
466
+ };
467
+ shellCalls += 1;
468
+ if (!Boolean(executionOptions?.[executionBudgetCharged])) try {
469
+ executionBudget?.recordToolCall();
470
+ } catch (error) {
471
+ executionBudget?.cancel(error);
472
+ throw error;
470
473
  }
471
- },
472
- type: "object"
473
- }),
474
- execute: async ({ path, sources }) => await materializeWorkspaceSourcesTool(input, {
475
- path,
476
- sources
477
- })
478
- });
479
- if (writeEnabled) Object.assign(result, createWriteTools(input, resolved.write));
474
+ return await runShellCommand(input, command, {
475
+ ...resolved,
476
+ budget: executionBudget,
477
+ budgetCharged: Boolean(executionBudget),
478
+ signal: abortSignal
479
+ });
480
+ }
481
+ }));
482
+ if (resolved.budget) markExecutionBudgetHandled(result.shell, resolved.budget);
483
+ }
484
+ if (resolved.materialize) {
485
+ result.materialize_sources = Object.assign(tool({
486
+ description: ["Materialize complete workspace source snapshots as an explicit tool step before shell inspection.", "This prepares whole sources, not individual files or partial limits."].join(" "),
487
+ inputSchema: jsonSchema({
488
+ additionalProperties: false,
489
+ properties: {
490
+ path: {
491
+ description: "Workspace path prefix to materialize. Defaults to the workspace root.",
492
+ type: "string"
493
+ },
494
+ sources: {
495
+ description: "Optional source names to materialize.",
496
+ items: { type: "string" },
497
+ type: "array"
498
+ }
499
+ },
500
+ type: "object"
501
+ }),
502
+ execute: async ({ path, sources }, executionOptions) => {
503
+ if (!executionOptions?.[executionBudgetCharged]) resolved.budget?.recordToolCall();
504
+ return await materializeWorkspaceSourcesTool(input, {
505
+ path,
506
+ sources
507
+ });
508
+ }
509
+ }), {
510
+ icon: "i-lucide-folder-sync",
511
+ title: "Materialized Workspace sources"
512
+ });
513
+ if (resolved.budget) markExecutionBudgetHandled(result.materialize_sources, resolved.budget);
514
+ }
515
+ if (writeEnabled) {
516
+ const writeTools = createWriteTools(input, resolved.write, resolved.budget);
517
+ Object.assign(result, writeTools);
518
+ if (resolved.budget) {
519
+ for (const writeTool of Object.values(writeTools)) if (writeTool) markExecutionBudgetHandled(writeTool, resolved.budget);
520
+ }
521
+ }
480
522
  return result;
481
523
  }
482
524
  //#endregion
483
- export { copyWorkspacePath as a, appendWorkspaceFile as i, getWorkspaceDependencyRuntimeLoaders as n, setWorkspaceDependencyRuntimeLoaders as r, createWorkspaceTools as t };
525
+ //#region src/core/use-tools.ts
526
+ function toReadOperations(options) {
527
+ return {
528
+ list: options?.list,
529
+ materialize: options?.materialize ?? true,
530
+ read: options?.read,
531
+ search: options?.search
532
+ };
533
+ }
534
+ function toWriteOperations(options) {
535
+ return {
536
+ ...toReadOperations(options),
537
+ write: {
538
+ appendFile: options?.appendFile !== false,
539
+ copyPath: options?.copyPath !== false,
540
+ deletePath: options?.deletePath !== false,
541
+ makeDir: options?.makeDir !== false,
542
+ movePath: options?.movePath !== false,
543
+ writeFile: options?.writeFile !== false
544
+ }
545
+ };
546
+ }
547
+ function createDefaultToolSet(createTools) {
548
+ return createTools();
549
+ }
550
+ function emptyTools() {
551
+ return {};
552
+ }
553
+ function useWorkspace(name, options) {
554
+ const runtime = createWorkspaceFileRuntime(name, options);
555
+ if (runtime.mode === "write") {
556
+ const createTools = (opts) => createWorkspaceTools(runtime.workspace, {
557
+ broadSearchPaths: opts?.broadSearchPaths,
558
+ cwd: opts?.cwd,
559
+ maxShellCalls: opts?.maxShellCalls,
560
+ maxOutputLength: opts?.maxOutputLength,
561
+ operations: toWriteOperations(opts),
562
+ sourceRequests: opts?.sourceRequests,
563
+ timeout: opts?.timeout
564
+ });
565
+ const createReadTools = (opts) => createWorkspaceTools(createReadonlyFs(name, runtime.workspace), {
566
+ broadSearchPaths: opts?.broadSearchPaths,
567
+ cwd: opts?.cwd,
568
+ maxShellCalls: opts?.maxShellCalls,
569
+ maxOutputLength: opts?.maxOutputLength,
570
+ operations: toReadOperations(opts),
571
+ sourceRequests: opts?.sourceRequests,
572
+ timeout: opts?.timeout
573
+ });
574
+ const tools = createDefaultToolSet(createTools);
575
+ tools.inspect = createReadTools;
576
+ tools.write = createTools;
577
+ tools.none = emptyTools;
578
+ return Object.assign(runtime.facade, { tools });
579
+ }
580
+ const createTools = (opts) => createWorkspaceTools(runtime.facade.fs, {
581
+ broadSearchPaths: opts?.broadSearchPaths,
582
+ cwd: opts?.cwd,
583
+ maxShellCalls: opts?.maxShellCalls,
584
+ maxOutputLength: opts?.maxOutputLength,
585
+ operations: toReadOperations(opts),
586
+ sourceRequests: opts?.sourceRequests,
587
+ timeout: opts?.timeout
588
+ });
589
+ const tools = createDefaultToolSet(createTools);
590
+ tools.inspect = createTools;
591
+ tools.none = emptyTools;
592
+ return Object.assign(runtime.facade, { tools });
593
+ }
594
+ //#endregion
595
+ //#region src/runtime/state.ts
596
+ async function invalidateWorkspaceStore(name) {
597
+ invalidateCachedWorkspaceStore(await resolveRegisteredWorkspaceDefinition(name));
598
+ }
599
+ function setWorkspaceRuntimeRegistry(registry) {
600
+ setWorkspaceRegistry(registry);
601
+ }
602
+ function setWorkspaceRuntimeAssetsRegistry(registry) {
603
+ setWorkspaceAssetsRegistry(registry);
604
+ }
605
+ //#endregion
606
+ export { createWorkspaceTools as a, useWorkspace as i, setWorkspaceRuntimeAssetsRegistry as n, getWorkspaceDependencyRuntimeLoaders as o, setWorkspaceRuntimeRegistry as r, setWorkspaceDependencyRuntimeLoaders as s, invalidateWorkspaceStore as t };