@vite-hub/workspace 0.1.0 → 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 (134) hide show
  1. package/README.md +164 -107
  2. package/dist/abort-BCwpdrN0.js +32 -0
  3. package/dist/blob-database.d.ts +70 -117
  4. package/dist/blob-database.js +48 -41
  5. package/dist/checkout.d.ts +128 -0
  6. package/dist/checkout.js +849 -0
  7. package/dist/cloudflare.d.ts +2 -2
  8. package/dist/cloudflare.js +1 -1
  9. package/dist/config-B-863EgC.js +15 -0
  10. package/dist/{config-B7dmzDX3.js → config-BAgL2dtB.js} +48 -84
  11. package/dist/{config-DLKdaFWN.d.ts → config-BQKcPawI.d.ts} +1 -1
  12. package/dist/discard-CNNtCozM.js +8 -0
  13. package/dist/durability.d.ts +22 -0
  14. package/dist/durability.js +70 -0
  15. package/dist/error-diagnostics-CtKjGtGb.js +188 -0
  16. package/dist/error-diagnostics-DSkCJC_L.js +266 -0
  17. package/dist/file-2pFYNtsU.js +22 -0
  18. package/dist/{files-C7Px8uaC.js → files-BOo4SbwE.js} +2 -2
  19. package/dist/files.d.ts +38 -0
  20. package/dist/files.js +6 -0
  21. package/dist/{github-CPxHtFB7.js → github-CrYp4v8k.js} +32 -5
  22. package/dist/{glob--XcLlcml.js → glob-B8YGvTrZ.js} +4 -5
  23. package/dist/{glob--kNYDbfU.js → glob-Cjxms1t7.js} +1 -1
  24. package/dist/{host-CFnrTXTK.js → host-BFBpXn0N.js} +58 -47
  25. package/dist/{hosted-acMA5XyL.js → hosted-KcUR_jPv.js} +216 -93
  26. package/dist/hosted-vercel-blob-B3-wRdUm.js +410 -0
  27. package/dist/hosted-vercel-blob.d.ts +2 -2
  28. package/dist/hosted-vercel-blob.js +1 -1
  29. package/dist/hosted.d.ts +5 -3
  30. package/dist/hosted.js +2 -2
  31. package/dist/index.d.ts +9 -51
  32. package/dist/index.js +21 -91
  33. package/dist/{lifecycle-BwZ7c9hb.js → lifecycle-B-enk_4A.js} +8 -8
  34. package/dist/lineage.d.ts +26 -0
  35. package/dist/lineage.js +76 -0
  36. package/dist/loader.d.ts +1 -1
  37. package/dist/loader.js +2 -2
  38. package/dist/{mcp-resources-BREFCmtn.js → mcp-resources-DF0F5rcL.js} +2 -2
  39. package/dist/{memory-BbwOqDXl.js → memory-BOexthyW.js} +3 -4
  40. package/dist/{metadata-target-DZEZQGHA.js → metadata-target-CWz6KHKq.js} +17 -16
  41. package/dist/object-Da1zyPCR.js +11 -0
  42. package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
  43. package/dist/operations-C6FpR8Rr.js +389 -0
  44. package/dist/operations-CE2drFih.js +1234 -0
  45. package/dist/operations.d.ts +41 -4
  46. package/dist/operations.js +3 -2
  47. package/dist/{path-CNAwN7pw.js → path--wrT_Azm.js} +2 -3
  48. package/dist/path-AxMho1wo.d.ts +7 -0
  49. package/dist/{plugins-DqQ8b4T5.d.ts → plugins-C8C0auoW.d.ts} +1 -1
  50. package/dist/{provider-kXjfli9u.js → provider-9s4Ufkm5.js} +104 -82
  51. package/dist/providers/github/store.d.ts +1 -1
  52. package/dist/providers/github/store.js +1 -1
  53. package/dist/registry-B3BBm4Ts.d.ts +19 -0
  54. package/dist/{registry-Bp-8UUfG.js → registry-CNphafBx.js} +55 -20
  55. package/dist/registry-CYNN623b.d.ts +9 -0
  56. package/dist/request-scope-Dw5n8bMC.js +83 -0
  57. package/dist/results-DgkZUmTL.js +8 -0
  58. package/dist/{rolldown-runtime-B4iAMlE-.js → rolldown-runtime-rQ84J-ij.js} +2 -3
  59. package/dist/runtime/assets.d.ts +1 -1
  60. package/dist/runtime/assets.js +3 -3
  61. package/dist/runtime/empty-assets-registry.d.ts +1 -1
  62. package/dist/runtime/empty-registry.d.ts +2 -1
  63. package/dist/runtime/registry.d.ts +2 -0
  64. package/dist/runtime/registry.js +23 -0
  65. package/dist/runtime/request.d.ts +4 -0
  66. package/dist/runtime/request.js +8 -0
  67. package/dist/runtime/state.d.ts +5 -4
  68. package/dist/runtime/state.js +8 -18
  69. package/dist/runtime/workspace.d.ts +1 -1
  70. package/dist/runtime/workspace.js +1 -1
  71. package/dist/runtime.d.ts +9 -8
  72. package/dist/runtime.js +23 -26
  73. package/dist/{search-CrTmXj5h.js → search-C_RfoM2j.js} +2 -2
  74. package/dist/{server-BNQ-Nbjj.js → server-8tGltlGz.js} +53 -40
  75. package/dist/server.d.ts +17 -8
  76. package/dist/server.js +1 -1
  77. package/dist/shared-B3_EUk89.js +848 -0
  78. package/dist/source-metadata.d.ts +6 -2
  79. package/dist/source-metadata.js +8 -8
  80. package/dist/state-BISnUf1s.d.ts +35 -0
  81. package/dist/{ai-BZyLwULx.js → state-DbrW-njQ.js} +96 -54
  82. package/dist/{store-CXgmu-uw.js → store-ybhyD38Z.js} +250 -106
  83. package/dist/{sync-CN6ec-5M.js → sync-CCD_VYC8.js} +4 -4
  84. package/dist/target-jWhTdIuF.js +89 -0
  85. package/dist/test.d.ts +1 -1
  86. package/dist/test.js +1 -1
  87. package/dist/{types-DeK9GIxy.d.ts → types-BbtwmBZ5.d.ts} +68 -14
  88. package/dist/use-C6lV3-wC.d.ts +321 -0
  89. package/dist/{use-BQj7nSz6.js → use-CSpT5W87.js} +75 -82
  90. package/dist/{utils-Blrh4N2n.js → utils-CgMZCHsX.js} +112 -41
  91. package/dist/vite.d.ts +585 -2
  92. package/dist/vite.js +21368 -1
  93. package/dist/{workspace-BWJQBK1u.d.ts → workspace-CYB2xZ1T.d.ts} +1 -1
  94. package/dist/{workspace-6pxkOuxr.js → workspace-sPWn2Jxj.js} +125 -40
  95. package/package.json +46 -55
  96. package/dist/ai-BW2ZhizI.d.ts +0 -177
  97. package/dist/ai.d.ts +0 -3
  98. package/dist/ai.js +0 -2
  99. package/dist/association-Cm0dUTDU-CDDhJnIh-Cv3bWnVb.js +0 -19
  100. package/dist/error-diagnostics-A_8Kp-48.js +0 -116
  101. package/dist/error-diagnostics-DY5GP47p.js +0 -96
  102. package/dist/events-7EBoeIPd-A2RUkJi5-BxrICQ17.js +0 -354
  103. package/dist/events-CRaLy7U3-3PNNp5WZ-Gv9nd0cH.js +0 -214
  104. package/dist/events-CeChclTf-CX-gD8oy-4aL2j6V-.js +0 -527
  105. package/dist/feed-DsC7Vws1-M_de2nSK-tKc0Pwo8.js +0 -248
  106. package/dist/feed-Dyf730Ys-D0HgBba6-BUnCa5gS.js +0 -179
  107. package/dist/file-C0_aPWSS.js +0 -26
  108. package/dist/file-metadata-CxDy-E2H.js +0 -58
  109. package/dist/forgejo-BN8ItCfl-Bbn4vhDd.js +0 -2278
  110. package/dist/github-DtncTfmv-Du2S8lGF.js +0 -4159
  111. package/dist/gitlab-BoDm8-BC-xzZsW9eW.js +0 -2530
  112. package/dist/graphql-DG5aJBT3-DceyFYdM-C4saqX37.js +0 -489
  113. package/dist/hosted-vercel-blob-DKntsHaf.js +0 -12603
  114. package/dist/inspect-BoObD2cJ.js +0 -167
  115. package/dist/mountx.d.ts +0 -8
  116. package/dist/mountx.js +0 -145
  117. package/dist/nitro.d.ts +0 -2
  118. package/dist/nitro.js +0 -2
  119. package/dist/nuxt.d.ts +0 -27
  120. package/dist/nuxt.js +0 -38
  121. package/dist/operations-BcpWr41m.js +0 -159
  122. package/dist/operations-CGqY1XeG.js +0 -965
  123. package/dist/operations-DnOwKsJT.d.ts +0 -136
  124. package/dist/registry-Cg1TJVVZ.d.ts +0 -10
  125. package/dist/request-execution-Dk9rY-Yh.js +0 -84
  126. package/dist/shared-DalXdP0i.js +0 -2158
  127. package/dist/state-B8zbLi5t.d.ts +0 -26
  128. package/dist/target-D4Bqb1eH.js +0 -11
  129. package/dist/templates-Bn8a-pd2-D9DhJEVD-CBfXNRzz.js +0 -125
  130. package/dist/token-CO62GglH.js +0 -61
  131. package/dist/use-DhwhbAVV.d.ts +0 -108
  132. package/dist/vite-BEvgU2GY.js +0 -20909
  133. package/dist/vite-CcZmMQ7S.d.ts +0 -476
  134. package/dist/webhooks-DgHwxxYz-D1V2LOr1-azofFOiP.js +0 -1565
package/README.md CHANGED
@@ -8,6 +8,20 @@
8
8
 
9
9
  `@vite-hub/workspace` gives agents and server code a file-system context they can read, diff, and, when opened in write mode, update.
10
10
 
11
+ ## File access without Agent tools
12
+
13
+ Use `useWorkspaceFiles()` from `@vite-hub/workspace/files` for file, history, and Content operations that do not need Agent tools. It accepts the same name, mode, and definition options as `useWorkspace()`, and returns the same facade without `tools`. This entry skips constructing and loading Agent tools, including when Workspace is external to a consumer bundle.
14
+
15
+ ```ts
16
+ import { useWorkspaceFiles } from "@vite-hub/workspace/files"
17
+
18
+ const workspace = useWorkspaceFiles("docs", { mode: "write" })
19
+ await workspace.fs.writeFile("guide.md", "# Guide\n")
20
+ await workspace.history.checkpoint({ message: "Update guide" })
21
+ ```
22
+
23
+ Use `useWorkspace()` when you need `workspace.tools`.
24
+
11
25
  ## Install
12
26
 
13
27
  ```sh
@@ -45,7 +59,7 @@ import { defineWorkspace, file, github } from "@vite-hub/workspace"
45
59
 
46
60
  export default defineWorkspace({
47
61
  store: {
48
- provider: "local",
62
+ driver: "local",
49
63
  root: ".vitehub/workspaces/docs",
50
64
  },
51
65
  sources: {
@@ -53,12 +67,10 @@ export default defineWorkspace({
53
67
  vitehubDocs: github({
54
68
  repo: "vite-hub/vitehub",
55
69
  root: "docs/content/docs",
56
- instructions: "Use this source for public ViteHub documentation.",
57
70
  }),
58
71
  guide: file({
59
72
  workspacePath: "guide.md",
60
73
  content: "# Guide\n",
61
- instructions: "Use this source for local guide notes.",
62
74
  }),
63
75
  },
64
76
  })
@@ -106,6 +118,7 @@ Serve a constrained Workspace subtree without custom route plumbing:
106
118
  import { defineWorkspaceFileHandler } from "@vite-hub/workspace/server"
107
119
 
108
120
  export default defineWorkspaceFileHandler({
121
+ base: "/api/data/",
109
122
  workspace: "docs",
110
123
  root: "data",
111
124
  allow: ["data/**/*.json", "data/**/*.md"],
@@ -113,6 +126,19 @@ export default defineWorkspaceFileHandler({
113
126
  })
114
127
  ```
115
128
 
129
+ The handler is a Fetchable route, `{ fetch(request) }`. `base` is the route path. The
130
+ rest of the URL path is the file path, percent-decoded: `/api/data/my%20file.json`
131
+ serves `my file.json`. A missing file, a
132
+ path outside `root` or `allow`, or a path with `..` gets a `404` JSON Response. A path
133
+ that is not valid percent-encoding gets a `400` JSON Response. `readWorkspaceFileResponse({ workspace,
134
+ path })` returns the same Responses for a route that finds the path itself.
135
+
136
+ When Nitro has a non-root `baseURL`, pass the same value as the handler's `baseURL`.
137
+ For example, `{ baseURL: "/api/data/", base: "/api/data/", workspace: "docs" }`
138
+ serves `a.json` at `/api/data/api/data/a.json`. This also works with `base: "/"`.
139
+ With `baseURL` set, the full prefix must match the start of the request path.
140
+ The Request alone cannot distinguish overlapping application and route bases.
141
+
116
142
  ## Retained folder history
117
143
 
118
144
  Use `@vite-hub/workspace/blob-database` for immutable folder versions backed by
@@ -122,7 +148,38 @@ Definition, apply its migrations, and pass
122
148
  Workspace Definition's `store`. The framework also exports
123
149
  `vite-hub/workspace/blob-database`.
124
150
 
151
+ `database` is a Drizzle database, or a function that returns one. In a
152
+ Workspace Definition, pass `() => useDatabase("history").db`. The Store calls
153
+ the function on first use, because the build loads the Workspace Definition
154
+ without the app's Databases. Do not pass the Database Definition: it holds
155
+ options only, and `useDatabase()` gives the database with the migrations and
156
+ relations of the build.
157
+
158
+ ```ts [server/databases/history/index.ts]
159
+ import { defineDatabase } from "@vite-hub/database"
160
+ import { workspaceHistorySchema } from "@vite-hub/workspace/blob-database"
161
+
162
+ export default defineDatabase({ name: "history", schema: workspaceHistorySchema })
163
+ ```
164
+
165
+ ```ts [server/workspaces/drop.ts]
166
+ import { blob } from "@vite-hub/blob"
167
+ import { useDatabase } from "@vite-hub/database"
168
+ import { defineWorkspace } from "@vite-hub/workspace"
169
+ import { createBlobDatabaseWorkspaceStore } from "@vite-hub/workspace/blob-database"
170
+
171
+ export default defineWorkspace({
172
+ store: createBlobDatabaseWorkspaceStore({
173
+ blob: blob.store("workspace-history"),
174
+ database: () => useDatabase("history").db,
175
+ workspace: "drop-123",
176
+ }),
177
+ })
178
+ ```
179
+
125
180
  ```ts
181
+ import { useWorkspace } from "@vite-hub/workspace"
182
+
126
183
  const workspace = useWorkspace("drop", { mode: "write" })
127
184
  const revision = await workspace.history.commit({
128
185
  ifHead: (await workspace.history.head())?.id ?? null,
@@ -146,7 +203,7 @@ History has named refs. Calls without `ref` use `main`. Each ref has its own hea
146
203
  and timeline, and revisions and bytes are shared across refs. A `changes` commit
147
204
  patches the ref head, so saving one draft file does not resend the folder:
148
205
 
149
- ```ts
206
+ ```ts fragment
150
207
  const draft = await workspace.history.head({ ref: "draft" })
151
208
  await workspace.history.commit({
152
209
  ref: "draft",
@@ -158,7 +215,10 @@ await workspace.history.refs() // [{ name: "draft", head }, { name: "main", head
158
215
 
159
216
  Rules, validators, hooks, and Source ownership run on every changed path in both
160
217
  forms. Use `registerWorkspacePlugin(name, plugin)` to add rules and hooks to a
161
- Workspace your package does not define.
218
+ Workspace your package does not define. In a history commit, each hook gets
219
+ `input.commit`: the read-only `message`, revision `metadata`, and the sorted `paths`
220
+ that the commit changes. A hook can check all paths at once, and read the intent of
221
+ the caller from the metadata, as Content reads `lease: "override"`.
162
222
 
163
223
  File objects use `_vitehub/workspace-history[/<prefix>]/<sha256(workspace)>/sha256/<digest>` Blob keys.
164
224
  The optional `prefix` nests below `_vitehub/workspace-history/`, so ViteHub owns every
@@ -191,59 +251,74 @@ vitehub workspace show content draft posts/hello.md
191
251
  Add `--json` for machine-readable output. A Store without retained history
192
252
  fails with `WORKSPACE_R0069`.
193
253
 
194
- ## JSON Collections
195
-
196
- Expose a JSON array stored in a Workspace file as a [Source Collection](https://vitehub.dev/docs/source/server-api#collections-over-an-array). `workspaceFile()` reads the file on every request and queries it in memory with `array()` from `@vite-hub/source`, so the browser gets bounded pages, `total`, and `facets` instead of the whole file.
197
-
198
- ```ts
199
- // server/collections/articles.ts
200
- import { defineCollection } from "@vite-hub/source"
201
- import { workspaceFile } from "@vite-hub/workspace"
202
- import * as v from "valibot"
203
-
204
- export const articles = defineCollection({
205
- source: workspaceFile({
206
- facets: ["category"],
207
- filters: ["category", "authors.name"],
208
- key: "slug",
209
- maxLimit: 100,
210
- path: "data/articles.json",
211
- schema: v.object({ category: v.string(), slug: v.string(), title: v.string() }),
212
- search: ["title", "summary"],
213
- sort: { field: "title", direction: "asc" },
214
- workspace: "content",
215
- }),
216
- transform: article => ({ category: article.category, slug: article.slug, title: article.title }),
217
- })
218
- ```
219
-
220
- ViteHub generates `GET /api/articles`, and `useCollection("articles")` from `@vite-hub/source/client` reads it with typed filters:
254
+ Work on one ref in a local folder, as with `git pull` and `git push`:
221
255
 
222
- ```ts
223
- const { items, total, facets, loadMore } = useCollection("articles", {
224
- limit: 25,
225
- filter: computed(() => ({ category: selectedCategory.value, search: search.value })),
226
- })
227
- ```
228
-
229
- Use `?empty=<field>` to match records without a scalar value at a declared filter. The file's Workspace digest binds every cursor, so a write to the file makes older cursors stale (`409`). Use this for deliberately small generated indexes; use a database when the server cannot reasonably hold and query the full array in memory.
230
-
231
- ```ts
232
- // nitro.config.ts
233
- import { createWorkspaceNitroConfig } from "@vite-hub/workspace/nitro"
234
-
235
- export default createWorkspaceNitroConfig()
256
+ ```bash
257
+ vitehub pull content --dir content --ref draft --url https://docs.example.com
258
+ vitehub pull --dry-run # local changes, and remote changes since the last pull
259
+ vitehub push # pull, then commit the local changes to `draft`
236
260
  ```
237
261
 
238
- ```ts
239
- // vite.config.ts
240
- import { hubWorkspace } from "@vite-hub/workspace/vite"
241
- import { defineConfig } from "vite"
242
-
243
- export default defineConfig({
244
- plugins: [hubWorkspace()],
245
- })
246
- ```
262
+ The first pull writes `vitehub.lock`: commit it. Pull merges text by line and writes
263
+ Git conflict markers where both sides changed the same lines; push refuses until they
264
+ are gone. The commands call the `workspace.changes` and `workspace.commit` operations.
265
+ A push keeps the media type and metadata of the files that it replaces, and records
266
+ the signed-in user as `author` of the revision. When a Store starts a new ref from
267
+ another ref, the first push also pulls the files of that ref. Unknown flags and extra
268
+ positional arguments to pull or push fail before any call, so `vitehub push --dry-run` commits nothing.
269
+ A push that writes a file that someone else holds an edit lease on, such as a Content
270
+ document open in the Console, fails and saves nothing; the error names who edits which
271
+ documents. `vitehub push --override-lease` writes anyway and records `lease: "override"`
272
+ in the revision metadata. An Agent or an MCP client can pass `lease: "override"` to
273
+ `workspace.commit` only with `operations({ overrideLeases: true })`.
274
+ Checkout folders must be separate: they cannot share a folder or contain one another.
275
+ On Windows and macOS, folder names that differ only in case are one folder.
276
+ Paths with `.git`, `.vitehub`, `node_modules`, or `.DS_Store` components, in any letter
277
+ case and with any trailing dots or spaces, are excluded from pulls, status, and pushes;
278
+ their remote files stay unchanged.
279
+ Checkout paths must use portable names on every platform. Different spellings of a
280
+ file or directory that differ only in case or Unicode normalization fail with
281
+ `WORKSPACE_CHECKOUT_PATH` before remote changes are written. Names with trailing dots
282
+ or spaces, Windows device names, and Windows-invalid characters also fail. A pull does
283
+ not replace a file with a directory or a directory with a file. For these transitions,
284
+ keep local edits elsewhere, remove the lock entry, and pull into a new empty folder.
285
+ Top-level files named `__proto__`, `constructor`, or `prototype` fail with the same
286
+ error because the operation input map cannot carry these keys. Workspace names have no such restriction.
287
+ One push is one `workspace.commit` call of at most 4 MiB, which fits the request body
288
+ limit of every host (Vercel Functions: 4.5 MB). A larger push fails with
289
+ `WORKSPACE_CHECKOUT_TOO_LARGE` before the call and names the largest files. A pull reads
290
+ all changes in one response; on Vercel, keep it below 4.5 MB.
291
+ Pulls replace files through a rename, so a hard link to an old file keeps its content. A file that ends in `.vitehub-tmp` is the leftover of a stopped write and is never pulled or pushed.
292
+ A symbolic link at `vitehub.lock` fails. Commands in one project can run at the same time:
293
+ each one rewrites only its own Workspace entries of `vitehub.lock`, under a short
294
+ `vitehub.lock.lock` file. A command waits up to 10 seconds, then fails with
295
+ `WORKSPACE_LOCK_BUSY`. Lock age does not allow takeover. If a command stopped, check
296
+ that no command is running before you delete this file.
297
+ An existing checkout rejects a different `--url`; remove its lock entry and pull into
298
+ a new folder to change the remote. A push records the committed bytes after write
299
+ validation and updates the local file if it still contains the submitted bytes.
300
+ Commands reject existing symbolic links in the checkout folder and its ancestors
301
+ inside the project. These checks do not isolate files from another process that can
302
+ replace paths during an operation. Use an OS or container boundary for that isolation.
303
+ On the GitHub Store, revision ids are commit shas. An instance keeps a ref head for up to
304
+ 5 seconds, so a pull can miss a newer commit for that time. The signed-in user is the Git
305
+ author of the commit when the user has a name and an email; the account of the token is
306
+ the committer. Without them, the account of the token is the author. Files
307
+ keep only their Git mode. The first push to a new ref starts it from the published or
308
+ default branch and then pulls the copied files. A pull reads one blob per changed file
309
+ (two when it also needs the old version), which counts against the GitHub rate limit.
310
+
311
+ `vitehub hooks install` adds a pre-commit hook that checks the staged files and working
312
+ tree for conflicts, and a pre-push hook
313
+ that runs `vitehub push` when Git pushes the default branch. When that push changes
314
+ `vitehub.lock` or pulls files, the hook fails: commit the changes and push again.
315
+ See [Work on a ref in a local folder](https://vitehub.dev/docs/workspace/server-api#work-on-a-ref-in-a-local-folder).
316
+
317
+ A derived file, such as a translation, can record its source as `derivedFrom: { path, digest }`
318
+ in Markdown frontmatter (`.md`, `.markdown`, `.mdx`), YAML, or JSON. `vitehub status` and
319
+ `vitehub workspace stale <workspace>` list the derived files whose source changed. `workspace stale`
320
+ also prints the source digest to write back as `derivedFrom.digest`. `@vite-hub/workspace/lineage` has the same checks.
321
+ See [Derived files](https://vitehub.dev/docs/workspace/server-api#derived-files).
247
322
 
248
323
  ## Reuse a Source definition
249
324
 
@@ -251,8 +326,7 @@ Bind a standalone Source definition when direct reads, Content, and Workspace
251
326
  need the same origin:
252
327
 
253
328
  ```ts
254
- import { createSource } from "@vite-hub/source"
255
- import { glob } from "@vite-hub/source/glob"
329
+ import { createSource, glob } from "@vite-hub/source"
256
330
  import { defineWorkspace } from "@vite-hub/workspace"
257
331
 
258
332
  const docs = glob({ cwd: "docs", include: "**/*.md" })
@@ -268,9 +342,22 @@ export default defineWorkspace({
268
342
 
269
343
  The key `intro.md` appears at `docs/intro.md` in the Workspace. The binding owns
270
344
  placement, materialization, sync, and access rules. Source owns retrieval.
345
+
346
+ Without a `mount` path, the Source kind picks the mount, not the import. A file
347
+ Source (`file()` or `markdown()` from either package, or the `"README.md"` and
348
+ `{ path }` shorthands) puts its one file at its own key, so
349
+ `readme: file("README.md")` appears at `README.md`. `fetch()` also puts its one
350
+ file at its own path. Every other Source mounts under its binding key. Set `mount` to move a file:
351
+ `readme: { source: file("README.md"), mount: "docs" }` appears at
352
+ `docs/README.md`.
271
353
  Content also accepts the definition with `defineContent({ source: docs })` and
272
354
  opens a new reader for each refresh.
273
355
 
356
+ In application `server/workspaces/<name>.ts` files, local Sources read from the
357
+ resolved project root. Flat files supplied by Nuxt layers keep their colocated
358
+ Source root: the file's folder, or its `workspace/` folder when present.
359
+ An explicit `sourceRootDir` overrides these defaults.
360
+
274
361
  Use Workspace helpers such as `file()` and `github()` when a definition only
275
362
  needs Workspace binding options. Existing bindings remain valid. For standalone
276
363
  custom loaders, replace the Source `custom()` helper with `defineSource()`.
@@ -287,7 +374,7 @@ navigation, query, cache, and ranked full-text search.
287
374
 
288
375
  Workspace definitions are runtime-free. To run generated code, open a [`@vite-hub/sandbox`](../sandbox/README.md) session and pass it to `workspace.startSession({ host: sandboxSession })`. Workspace materializes files into the host and still owns diff, commit, and rollback; closing without commit restores the host tree from authoritative Workspace state. Sandbox owns execution and the host lifecycle.
289
376
 
290
- GitHub-backed Workspaces pin the branch head before a hosted Session starts and materialize a full-tree Session from one revision archive. Repeated Sessions reuse that immutable archive while the revision is unchanged; scoped Sessions and stores without revision archives use the normal Workspace file API.
377
+ GitHub-backed Workspaces pin the branch head before a hosted Session starts and materialize a full-tree Session from one revision archive. Repeated Sessions reuse that immutable archive while the revision is unchanged; scoped Sessions and stores without revision archives use the normal Workspace file API. A hosted Session exposes that initial retained revision as `session.revision` when its Store provides one. Stores with retained history but no revision materializer, such as Blob Database, expose the retained head only when its file manifest matches the files copied to the host. Draft changes or unavailable history leave the revision unset and do not prevent the Session from opening.
291
378
 
292
379
  Use `startSession({ attach: true, host })` only when another integration already owns the live materialized tree. Attached Sessions preserve that baseline without rematerializing the tree and roll back only their own uncommitted changes on close.
293
380
 
@@ -299,41 +386,6 @@ Basic Sessions started without a host also honor `writeBack: false`. Their priva
299
386
 
300
387
  Custom `WorkspaceSessionHost` implementations copy Workspace files serially by default. A host can set `materializationConcurrency` to a positive integer when it supports that many independent file reads and writes safely. ViteHub's local Node host uses `8`.
301
388
 
302
- ## MountX projection
303
-
304
- Use the `@vite-hub/workspace/mountx` integration when an Agent, editor, CLI, or VM needs a real filesystem instead of Workspace methods. The adapter keeps Workspace Session diff and commit semantics in ViteHub while MountX owns the host transport.
305
-
306
- Install MountX directly before importing its transport entry points:
307
-
308
- ```bash
309
- pnpm add mountx@0.0.2
310
- ```
311
-
312
- ```ts
313
- import { createWorkspaceDriver } from "@vite-hub/workspace/mountx"
314
- import { mount } from "mountx/auto"
315
-
316
- const session = await workspace.startSession()
317
-
318
- try {
319
- const mounted = await mount(createWorkspaceDriver(session), "/tmp/vitehub-docs")
320
-
321
- try {
322
- // Programs can now use /tmp/vitehub-docs as an ordinary directory.
323
- }
324
- finally {
325
- await mounted.unmount()
326
- }
327
-
328
- await session.commit({ message: "accept projected changes" })
329
- }
330
- finally {
331
- await session.close()
332
- }
333
- ```
334
-
335
- The same driver works with MountX's 9P and NFSv4.1 servers for Linux guests, or its S3 gateway for S3-compatible clients. Use `{ readOnly: true }` when the consumer only needs inspection. The adapter uses MountX's unstorage driver, so it does not project or persist empty directories, and filenames cannot contain `:`, `?`, or end in `$`. Renames use copy then delete and are not atomic. Executable Git files retain their execute bits; Git symlinks are rejected because the unstorage driver cannot preserve symlink semantics. MountX is still alpha and unaudited, so keep network transports loopback-only unless the surrounding sandbox or network is the explicit security boundary.
336
-
337
389
  Built-in coding Agent Drivers use Workspace Sessions to materialize the selected Workspace Scope into their provider working directory. Workspace owns source materialization and write-mode sync through Workspace rules; the Agent Package owns provider execution and lifecycle events.
338
390
 
339
391
  ## Vite Integration
@@ -359,15 +411,15 @@ Contributed Workspaces appear in the generated registry, `WorkspaceName` types,
359
411
 
360
412
  ## Hosted Cloudflare runtime
361
413
 
362
- Nuxt apps can install the Workspace Nuxt module so hosted Workspace runtime setup is generated by the Vite Integration and merged into Nuxt's top-level Nitro config:
414
+ Nuxt apps enable Workspace through `vite-hub/nuxt`. It generates the hosted Workspace runtime setup with the Vite Integration and merges it into Nuxt's top-level Nitro config:
363
415
 
364
416
  ```ts
365
417
  export default defineNuxtConfig({
366
- modules: ["@vite-hub/workspace/nuxt"],
367
- vite: {
418
+ modules: ["vite-hub/nuxt"],
419
+ vitehub: {
368
420
  workspace: {
369
421
  store: {
370
- provider: "github",
422
+ driver: "github",
371
423
  repository: "owner/repo",
372
424
  branch: "main",
373
425
  root: ".vitehub/workspaces/docs",
@@ -385,7 +437,7 @@ import { configureCloudflareWorkspaceRuntime } from "@vite-hub/workspace/cloudfl
385
437
  configureCloudflareWorkspaceRuntime()
386
438
  ```
387
439
 
388
- `useWorkspace()` will then resolve `cloudflare-artifacts` Workspace Stores from the configured runtime store or the Workspace Definition's `store` option.
440
+ `useWorkspace()` will then resolve `cloudflare` Workspace Stores from the configured runtime store or the Workspace Definition's `store` option.
389
441
 
390
442
  Select Cloudflare Artifacts explicitly when a Cloudflare Worker needs durable, versioned Workspace state:
391
443
 
@@ -395,28 +447,31 @@ import { hubWorkspace } from "@vite-hub/workspace/vite"
395
447
  import { defineConfig } from "vite"
396
448
 
397
449
  export default defineConfig({
398
- plugins: [hubWorkspace()],
399
- workspace: {
450
+ plugins: [hubWorkspace({
400
451
  store: {
401
- provider: "cloudflare-artifacts",
452
+ driver: "cloudflare",
402
453
  binding: "WORKSPACE_ARTIFACTS",
403
454
  namespace: "vitehub",
404
455
  },
405
- },
456
+ })],
406
457
  })
407
458
  ```
408
459
 
409
- The Vite Integration writes matching module-level and discovered definition-level Artifacts bindings into generated Cloudflare Provider Output. Each named Workspace uses its own repository by default, and a successful `workspace.snapshot()` pushes a Git commit whose SHA is the snapshot id. The Worker adapter keeps its checkout in isolate memory, so use it for deliberately small Workspaces. Cloudflare Artifacts is in open beta and is not available on Workers Free; Cloudflare hosting therefore continues to default to the `memory` Store.
460
+ The Vite Integration writes matching module-level and discovered definition-level Artifacts bindings into generated Cloudflare Provider Output. It reads a definition's `store` by loading the definition at build time. If the build cannot load a definition, it fails with `WORKSPACE_B0005`, unless the source shows a literal object with no `store` or with a literal store whose `driver` is not `cloudflare`; set the store in the `workspace` config then. Each named Workspace uses its own repository by default, and a successful `workspace.snapshot()` pushes a Git commit whose SHA is the snapshot id. The Worker adapter keeps its checkout in isolate memory, so use it for deliberately small Workspaces. Cloudflare Artifacts is in open beta and is not available on Workers Free; Cloudflare hosting therefore continues to default to the `memory` Store.
410
461
 
411
462
  Artifacts repositories are private Git storage, not public attachment hosting. Use `@vite-hub/blob` with R2 or another Blob provider when an Agent needs a stable public delivery URL.
412
463
 
413
464
  ## Vercel Blob persistence
414
465
 
415
- The `vercel-blob` Store keeps Workspace files under `_vitehub/workspaces/<workspace>/`.
466
+ The `vercel` Store keeps Workspace files under `_vitehub/workspaces/<workspace>/`.
416
467
  The optional `prefix`, or `VITEHUB_WORKSPACE_BLOB_PREFIX`, nests below
417
468
  `_vitehub/workspaces/`, so ViteHub owns every Workspace object. A prefix accepts
418
469
  letters, numbers, underscores, dashes, and single slashes.
419
470
 
471
+ Without a `store`, a production build selects `vercel` when the project has
472
+ `BLOB_STORE_ID` or `BLOB_READ_WRITE_TOKEN`. With `BLOB_STORE_ID`, the store uses
473
+ Vercel OIDC, as `@vite-hub/blob` does. Off Vercel, it uses `BLOB_READ_WRITE_TOKEN`.
474
+
420
475
  Vercel Blob writes preserve file bytes and JSON attributes in separate objects. Same-path writes and removals are serialized across Store instances in one process, including failed-write recovery. Readers are not isolated from in-progress writes. Coordinate access across processes or hosts when they share a Workspace; this adapter does not provide distributed transactions. Use the Blob + Database Store when you need atomic publication across replicas.
421
476
 
422
477
  ## GitHub-backed persistence
@@ -424,9 +479,11 @@ Vercel Blob writes preserve file bytes and JSON attributes in separate objects.
424
479
  Use the GitHub Workspace Store when a hosted runtime needs durable Workspace file-tree state without a provider-specific artifact store:
425
480
 
426
481
  ```ts
482
+ import { defineWorkspace } from "@vite-hub/workspace"
483
+
427
484
  export default defineWorkspace({
428
485
  store: {
429
- provider: "github",
486
+ driver: "github",
430
487
  repository: "owner/repo",
431
488
  branch: "main",
432
489
  root: ".vitehub/workspaces/<workspace>",
@@ -434,7 +491,7 @@ export default defineWorkspace({
434
491
  })
435
492
  ```
436
493
 
437
- Set `VITEHUB_GITHUB_TOKEN` or `FORGES_GITHUB_TOKEN` in the process environment or as a runtime binding with permission to read and write the repository contents. Set `VITEHUB_WORKSPACE_GITHUB_REPOSITORY`, `VITEHUB_WORKSPACE_GITHUB_BRANCH`, and `VITEHUB_WORKSPACE_GITHUB_ROOT` to configure the Store location when you omit those options. Reads and snapshots call the GitHub API, so this Store trades provider independence for GitHub API latency and rate limits. `workspace.snapshot()` writes changed Workspace Store files as one GitHub commit. If the target branch moves after the Workspace Store loaded local changes, including during the final branch update, snapshot fails with a structured conflict so the caller can rebase from the current head and retry.
494
+ The GitHub Store talks to GitHub through `@vite-hub/forge`, an optional peer. Install it with `pnpm add @vite-hub/forge`. Without it, the first request fails with `INTERNAL_FORGE_NOT_INSTALLED`. Set `VITEHUB_GITHUB_TOKEN` or `FORGES_GITHUB_TOKEN` in the process environment or as a runtime binding with permission to read and write the repository contents. Set `VITEHUB_WORKSPACE_GITHUB_REPOSITORY`, `VITEHUB_WORKSPACE_GITHUB_BRANCH`, and `VITEHUB_WORKSPACE_GITHUB_ROOT` to configure the Store location when you omit those options. Reads and snapshots call the GitHub API, so this Store trades provider independence for GitHub API latency and rate limits. Branch heads are revalidated with their ETag, answers for a commit sha stay in memory, and with `registerWorkspaceKV()` (Content calls it with ViteHub KV) they also go to KV for 7 days. `history.list()` reads one request per page, and `history.open(id).preload(paths)` reads many files from one archive. `workspace.snapshot()` writes changed Workspace Store files as one GitHub commit. If the target branch moves after the Workspace Store loaded local changes, including during the final branch update, snapshot moves the changes onto the new head and commits once more. A path that changed on both sides, or a second move, fails with `WORKSPACE_CONFLICT`; `details.paths` names the paths. A Store without staged writes reads the branch head again when it loaded it more than 5 seconds ago, so one cached Store serves many requests without `resetWorkspaceStoreCache()`. The Cloudflare Artifacts Store does the same. Writes stay staged until `snapshot()`. When a request, a Schedule run, or a Queue job throws, a Store that holds only its staged writes drops them and loads the branch again on its next call, so a later snapshot cannot commit them. This holds for every writer of the Store, Source materialization included, and for Workspaces that live longer than one request. Requests that overlap in one instance share one Store, so their staged writes stay until one of them snapshots.
438
495
 
439
496
  GitHub file reads share a blob cache across Store instances and history views in one isolate. Immutable blob shas identify the bytes, including across repositories. Concurrent reads of the same blob share one request when the repository and credentials match, and failed reads can be retried. A failed request does not affect readers using another repository or token. The cache retains up to 32 MiB of bytes, evicts the oldest entries first, and skips blobs larger than 4 MiB. A cold isolate or an evicted blob still needs a GitHub request.
440
497
 
@@ -452,7 +509,7 @@ The GitHub Store also writes history. `history.commit()` creates one commit, che
452
509
  of the `published` and `draft` history refs and reports revisions with those names. `database` is
453
510
  carried on the store target and not used by the Store. `history.digest(bytes)` and every revision
454
511
  view use Git blob shas as digests. Commit `metadata` is kept in the commit message as a
455
- `Vitehub-Metadata: {...}` line, and `history.list({ path })` returns the commits that changed that
512
+ `Vitehub-Metadata: {...}` line, a `metadata.author` with a `name` and an `email` is the Git author of the commit, and `history.list({ path })` returns the commits that changed that
456
513
  path. `history.head()` keeps a branch head for 5 seconds. The Store reads the repository and token on
457
514
  first use, so a missing one throws `WORKSPACE_R0072` then, not when the definition loads.
458
515
 
@@ -0,0 +1,32 @@
1
+ //#region ../internal/src/abort.ts
2
+ /**
3
+ * Runs `task` and rejects as soon as `signal` aborts, without waiting for the task.
4
+ *
5
+ * The rejection is `signal.reason`. When the reason is absent, it is an `AbortError` with `message`.
6
+ * When `signal` is already aborted, `task` does not run. The task should stop its own work
7
+ * through the same signal.
8
+ */
9
+ function abortable(signal, message, task) {
10
+ return new Promise((resolve, reject) => {
11
+ if (signal?.aborted) {
12
+ reject(abortReason(signal, message));
13
+ return;
14
+ }
15
+ const onAbort = () => reject(abortReason(signal, message));
16
+ signal?.addEventListener("abort", onAbort, { once: true });
17
+ const settle = () => signal?.removeEventListener("abort", onAbort);
18
+ new Promise((resolveTask) => resolveTask(task())).then((value) => {
19
+ settle();
20
+ resolve(value);
21
+ }, (error) => {
22
+ settle();
23
+ reject(error);
24
+ });
25
+ });
26
+ }
27
+ function abortReason(signal, message) {
28
+ if (signal?.reason !== void 0) return signal.reason;
29
+ return new DOMException(message, "AbortError");
30
+ }
31
+ //#endregion
32
+ export { abortable as t };