@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.
- package/README.md +339 -115
- package/dist/abort-BCwpdrN0.js +32 -0
- package/dist/{asset-registry-8QI3ML3K.js → asset-registry-DfBV5kmw.js} +3 -2
- package/dist/blob-database.d.ts +474 -0
- package/dist/blob-database.js +608 -0
- package/dist/checkout.d.ts +128 -0
- package/dist/checkout.js +849 -0
- package/dist/cloudflare.d.ts +6 -7
- package/dist/cloudflare.js +1 -1
- package/dist/config-B-863EgC.js +15 -0
- package/dist/config-BAgL2dtB.js +1076 -0
- package/dist/{config-DE9xlaIw.d.ts → config-BQKcPawI.d.ts} +1 -2
- package/dist/discard-CNNtCozM.js +8 -0
- package/dist/durability.d.ts +22 -0
- package/dist/durability.js +70 -0
- package/dist/error-diagnostics-CtKjGtGb.js +188 -0
- package/dist/error-diagnostics-DSkCJC_L.js +266 -0
- package/dist/file-2pFYNtsU.js +22 -0
- package/dist/{files-Q6xZjDHA.js → files-BOo4SbwE.js} +3 -3
- package/dist/files.d.ts +38 -0
- package/dist/files.js +6 -0
- package/dist/{github-DHnjxQIX.js → github-CrYp4v8k.js} +44 -24
- package/dist/glob-B8YGvTrZ.js +21 -0
- package/dist/glob-Cjxms1t7.js +30 -0
- package/dist/{host-DJH8cuoU.js → host-BFBpXn0N.js} +144 -77
- package/dist/{hosted-RPeJOCFz.js → hosted-KcUR_jPv.js} +303 -97
- package/dist/hosted-vercel-blob-B3-wRdUm.js +410 -0
- package/dist/hosted-vercel-blob.d.ts +6 -7
- package/dist/hosted-vercel-blob.js +1 -1
- package/dist/hosted.d.ts +10 -9
- package/dist/hosted.js +2 -2
- package/dist/index.d.ts +26 -47
- package/dist/index.js +30 -100
- package/dist/internal/path.d.ts +2 -0
- package/dist/internal/path.js +2 -0
- package/dist/lifecycle-B-enk_4A.js +596 -0
- package/dist/lineage.d.ts +26 -0
- package/dist/lineage.js +76 -0
- package/dist/loader.d.ts +5 -6
- package/dist/loader.js +3 -2
- package/dist/mcp-resources-DF0F5rcL.js +39 -0
- package/dist/memory-BOexthyW.js +247 -0
- package/dist/metadata-target-CWz6KHKq.js +1589 -0
- package/dist/object-Da1zyPCR.js +11 -0
- package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
- package/dist/operations-C6FpR8Rr.js +389 -0
- package/dist/operations-CE2drFih.js +1234 -0
- package/dist/operations.d.ts +90 -0
- package/dist/operations.js +3 -0
- package/dist/path--wrT_Azm.js +113 -0
- package/dist/path-AxMho1wo.d.ts +7 -0
- package/dist/path-DrSIenjj.js +59 -0
- package/dist/path-zHxQUbqa.d.ts +9 -0
- package/dist/plugins-C8C0auoW.d.ts +10 -0
- package/dist/provider-9s4Ufkm5.js +1479 -0
- package/dist/providers/github/store.d.ts +3 -5
- package/dist/providers/github/store.js +1 -1
- package/dist/registry-B3BBm4Ts.d.ts +19 -0
- package/dist/{registry-D3yzt8HQ.js → registry-CNphafBx.js} +60 -23
- package/dist/registry-CYNN623b.d.ts +9 -0
- package/dist/request-scope-Dw5n8bMC.js +83 -0
- package/dist/results-DgkZUmTL.js +8 -0
- package/dist/{chunk-2rV9d50f.js → rolldown-runtime-rQ84J-ij.js} +3 -4
- package/dist/runtime/assets.d.ts +3 -5
- package/dist/runtime/assets.js +7 -6
- package/dist/runtime/empty-assets-registry.d.ts +1 -2
- package/dist/runtime/empty-registry.d.ts +2 -2
- package/dist/runtime/registry.d.ts +2 -0
- package/dist/runtime/registry.js +23 -0
- package/dist/runtime/request.d.ts +4 -0
- package/dist/runtime/request.js +8 -0
- package/dist/runtime/state.d.ts +5 -4
- package/dist/runtime/state.js +8 -18
- package/dist/runtime/workspace.d.ts +1 -1
- package/dist/runtime/workspace.js +1 -1
- package/dist/runtime.d.ts +52 -17
- package/dist/runtime.js +324 -67
- package/dist/{search-BpiCF2Tw.js → search-C_RfoM2j.js} +10 -9
- package/dist/server-8tGltlGz.js +303 -0
- package/dist/server.d.ts +36 -39
- package/dist/server.js +2 -328
- package/dist/shared-B3_EUk89.js +848 -0
- package/dist/source-metadata.d.ts +10 -7
- package/dist/source-metadata.js +12 -12
- package/dist/state-BISnUf1s.d.ts +35 -0
- package/dist/{ai-BqCC8BpY.js → state-DbrW-njQ.js} +237 -114
- package/dist/store-ybhyD38Z.js +1873 -0
- package/dist/{sync-DnTQwt8r.js → sync-CCD_VYC8.js} +61 -41
- package/dist/target-jWhTdIuF.js +89 -0
- package/dist/test.d.ts +1 -1
- package/dist/test.js +1 -1
- package/dist/{types-CYuwjJ4V.d.ts → types-BbtwmBZ5.d.ts} +321 -35
- package/dist/use-C6lV3-wC.d.ts +321 -0
- package/dist/{use-BTNDR5Rd.js → use-CSpT5W87.js} +141 -107
- package/dist/utils-CgMZCHsX.js +616 -0
- package/dist/vite.d.ts +585 -2
- package/dist/vite.js +21369 -2
- package/dist/workspace-CYB2xZ1T.d.ts +7 -0
- package/dist/{workspace-Dq08Yn72.js → workspace-sPWn2Jxj.js} +441 -225
- package/package.json +97 -72
- package/dist/ai-CjxvGqM0.d.ts +0 -162
- package/dist/ai.d.ts +0 -3
- package/dist/ai.js +0 -2
- package/dist/collections/client.d.ts +0 -39
- package/dist/collections/client.js +0 -137
- package/dist/collections.d.ts +0 -59
- package/dist/collections.js +0 -159
- package/dist/config-Bc3c4Su1.js +0 -7904
- package/dist/config-CHLLWklZ.js +0 -36
- package/dist/file-Bc1X7pco.js +0 -23
- package/dist/glob-CEZKeZFC.js +0 -18
- package/dist/hosted-vercel-blob-d6C8ND5j.js +0 -23580
- package/dist/lifecycle-LrL3sA4n.js +0 -316
- package/dist/metadata-target-B0tOmVW7.js +0 -717
- package/dist/mountx.d.ts +0 -10
- package/dist/mountx.js +0 -143
- package/dist/nitro.d.ts +0 -2
- package/dist/nitro.js +0 -2
- package/dist/nuxt.d.ts +0 -26
- package/dist/nuxt.js +0 -42
- package/dist/path-Cp59koVz.js +0 -139
- package/dist/provider-B1yLjCJJ.js +0 -746
- package/dist/publish.d.ts +0 -35
- package/dist/publish.js +0 -112
- package/dist/registry-Uj6IVxes.d.ts +0 -11
- package/dist/request-execution-B-dSFlGB.js +0 -84
- package/dist/runtime-options-BsPSv5O7.js +0 -13
- package/dist/runtime-type-iEE6BjQJ.js +0 -34
- package/dist/shared-DTR1Hhma.js +0 -331
- package/dist/state-tYcRWEh2.d.ts +0 -26
- package/dist/store-Dt_Jyys3.js +0 -608
- package/dist/target-D4Bqb1eH.js +0 -11
- package/dist/token-CVzURBxC.js +0 -61
- package/dist/use-BiHzt0xA.d.ts +0 -103
- package/dist/vite-BptCrpv2.js +0 -4526
- package/dist/vite-CtA9guIM.d.ts +0 -66
- package/dist/workspace-Xddf4G1B.d.ts +0 -6
package/README.md
CHANGED
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
# @vite-hub/workspace
|
|
2
2
|
|
|
3
3
|
<p>
|
|
4
|
-
<a href="https://vitehub.dev"><img alt="ViteHub" src="https://
|
|
5
|
-
<img alt="TypeScript" src="https://
|
|
6
|
-
<img alt="Vite" src="https://
|
|
4
|
+
<a href="https://vitehub.dev"><img alt="ViteHub" src="https://comark-ui.onmax.me/badge.svg?label=ViteHub&value=vitehub.dev"></a>
|
|
5
|
+
<img alt="TypeScript" src="https://comark-ui.onmax.me/badge.svg?label=TypeScript&value=ready">
|
|
6
|
+
<img alt="Vite" src="https://comark-ui.onmax.me/badge.svg?label=Vite&value=discovery">
|
|
7
7
|
</p>
|
|
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
|
|
@@ -19,6 +33,14 @@ Use `skipLibCheck: true` in app TypeScript configs while ViteHub depends on runt
|
|
|
19
33
|
|
|
20
34
|
## Minimal API
|
|
21
35
|
|
|
36
|
+
The local Store persists file metadata inside `.vitehub` under the Workspace root. If file removal stops before metadata cleanup completes, reads reject with `Interrupted Workspace removal` so a restored file cannot reuse deleted ownership. Retry removal of the reported path with `force: true` and, for directories, `recursive: true` before restoring files.
|
|
37
|
+
|
|
38
|
+
Lock markers are not reclaimed based on age because a slow operation or failed heartbeat may still own them. If a process crashes and operations report `Timed out waiting to read Workspace` or `Timed out waiting to write Workspace`, stop every process using that Workspace. Call `recoverLocalWorkspaceLocks({ root, offline: true })` from `@vite-hub/workspace/runtime` with the Local Store's root, then restart the processes after recovery succeeds. Prevent changes to the Store and its ancestor directories throughout recovery. The `offline: true` flag confirms exclusive offline access; it does not stop other processes. See [Local Store recovery](../../docs/content/docs/workspace/limits-and-errors.md#recover-a-local-store-after-a-crash) for the procedure.
|
|
39
|
+
|
|
40
|
+
Set `locks: "process"` on a local Store when one process owns its root, for example a disposable checkout that one worker uses. The Store then keeps the same per-path read and write locks in memory. It creates no `.vitehub/locks` directory, does not poll lock markers, and lists entries in parallel. Keep the default `locks: "filesystem"` when more than one process can access the root.
|
|
41
|
+
|
|
42
|
+
Set `ignore: "git"` when the local Store root is a Git checkout. Listings, snapshots, and diffs skip `.git` and the paths that Git ignores, such as dependencies and build output.
|
|
43
|
+
|
|
22
44
|
```text
|
|
23
45
|
server/
|
|
24
46
|
workspaces/
|
|
@@ -37,7 +59,7 @@ import { defineWorkspace, file, github } from "@vite-hub/workspace"
|
|
|
37
59
|
|
|
38
60
|
export default defineWorkspace({
|
|
39
61
|
store: {
|
|
40
|
-
|
|
62
|
+
driver: "local",
|
|
41
63
|
root: ".vitehub/workspaces/docs",
|
|
42
64
|
},
|
|
43
65
|
sources: {
|
|
@@ -45,12 +67,10 @@ export default defineWorkspace({
|
|
|
45
67
|
vitehubDocs: github({
|
|
46
68
|
repo: "vite-hub/vitehub",
|
|
47
69
|
root: "docs/content/docs",
|
|
48
|
-
instructions: "Use this source for public ViteHub documentation.",
|
|
49
70
|
}),
|
|
50
71
|
guide: file({
|
|
51
72
|
workspacePath: "guide.md",
|
|
52
73
|
content: "# Guide\n",
|
|
53
|
-
instructions: "Use this source for local guide notes.",
|
|
54
74
|
}),
|
|
55
75
|
},
|
|
56
76
|
})
|
|
@@ -73,6 +93,24 @@ export default defineEventHandler(async () => {
|
|
|
73
93
|
})
|
|
74
94
|
```
|
|
75
95
|
|
|
96
|
+
`workspace.fs.glob("*.md", { cwd: "guides" })` matches Markdown files directly inside `guides`. It returns Workspace-relative paths such as `guides/start.md`. Pattern arrays and recursive patterns use the same directory.
|
|
97
|
+
|
|
98
|
+
`useWorkspace(name)` returns read access. For read-only inspection of an existing Workspace, use `useWorkspace("docs", { refresh: false })` to reuse current persisted snapshots of Sources with `materialize: "startup"`. Snapshots are reused when they are ready and match the current Source configuration, even if upstream content has changed. Missing snapshots or snapshots that no longer match the configuration still materialize. Omitting `refresh`, or setting it to `true`, keeps normal startup Source refresh behavior. Custom Stores that omit `getMeta` or `setMeta` retain ownership and Source snapshots only for the lifetime of the Store instance.
|
|
99
|
+
|
|
100
|
+
Workspace shell tools exclude controlled `curl` by default. Set `sourceRequests: true` in `createWorkspaceTools(workspace, { sourceRequests: true })` or `workspace.tools.inspect({ sourceRequests: true })` to permit requests to visible Source targets. This does not grant access to other network targets. The Agent `workspaceShell()` Capability enables these scoped Source requests explicitly.
|
|
101
|
+
|
|
102
|
+
Local Store metadata reads use the persisted state. Metadata writes serialize their read and atomic replacement across Store instances that share the same root, so updates to different keys do not overwrite each other. A failed read or write can be retried on the same Store instance.
|
|
103
|
+
|
|
104
|
+
Local Stores reject symbolic links in file reads, writes, file metadata reads, directory creation, and explicit listing paths. Listings omit symbolic links. Removal can unlink a symbolic link itself, but cannot follow a linked parent directory. To expose another directory, configure a Source instead of creating a symbolic link. These checks protect against existing links, including aliases to `.vitehub` metadata. They do not isolate the filesystem from another process that can replace paths during an operation. Use an OS or container boundary when untrusted processes share the host.
|
|
105
|
+
|
|
106
|
+
Public Workspace paths reserve `.git` at any depth and `.vitehub` at the root, regardless of case. This restriction also covers NTFS stream suffixes such as `.vitehub::$INDEX_ALLOCATION` and spellings with trailing ASCII periods or spaces such as `.vitehub.`. These spellings are rejected on every host.
|
|
107
|
+
|
|
108
|
+
Build and startup overwrites persist a pending checkpoint before changing existing files. Cleanup accepts the new owner only after checkpoint completion, so failed rollback metadata cannot grant ownership of restored files after a Store reopen. If publishing completion fails after the file and owner were committed, the operation reports the error and keeps the generated output. Cleanup preserves that output unless completion was persisted. Retry the Source operation to establish ownership again.
|
|
109
|
+
|
|
110
|
+
Stores can return `revision` from `stat()` to identify a stored file version. This opaque value must change when the file is modified or recreated, even with identical bytes. A write that makes no change to the stored file can keep its revision. Memory and local Stores provide it. Cleanup uses the revision and content digest to retry interrupted file removal. If the Store cannot identify the surviving file, cleanup preserves it and reports the ambiguous removal for inspection. After inspection, remove the file explicitly if it is still generated output, then retry cleanup.
|
|
111
|
+
|
|
112
|
+
`refresh: false` applies only to read mode. It does not disable refreshes for other Sources or change explicit `sync()` and `materializeSources()` calls on a writable facade. `useWorkspace(name, { mode: "write" })` keeps normal refresh behavior.
|
|
113
|
+
|
|
76
114
|
Serve a constrained Workspace subtree without custom route plumbing:
|
|
77
115
|
|
|
78
116
|
```ts
|
|
@@ -80,6 +118,7 @@ Serve a constrained Workspace subtree without custom route plumbing:
|
|
|
80
118
|
import { defineWorkspaceFileHandler } from "@vite-hub/workspace/server"
|
|
81
119
|
|
|
82
120
|
export default defineWorkspaceFileHandler({
|
|
121
|
+
base: "/api/data/",
|
|
83
122
|
workspace: "docs",
|
|
84
123
|
root: "data",
|
|
85
124
|
allow: ["data/**/*.json", "data/**/*.md"],
|
|
@@ -87,116 +126,265 @@ export default defineWorkspaceFileHandler({
|
|
|
87
126
|
})
|
|
88
127
|
```
|
|
89
128
|
|
|
90
|
-
|
|
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
|
+
|
|
142
|
+
## Retained folder history
|
|
143
|
+
|
|
144
|
+
Use `@vite-hub/workspace/blob-database` for immutable folder versions backed by
|
|
145
|
+
ViteHub Blob and Database. Include `workspaceHistorySchema` in a Database
|
|
146
|
+
Definition, apply its migrations, and pass
|
|
147
|
+
`createBlobDatabaseWorkspaceStore({ blob, database, workspace })` as the
|
|
148
|
+
Workspace Definition's `store`. The framework also exports
|
|
149
|
+
`vite-hub/workspace/blob-database`.
|
|
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
|
+
```
|
|
91
164
|
|
|
92
|
-
|
|
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"
|
|
93
170
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
filters: ["category", "authors.name"],
|
|
101
|
-
item: { key: "slug" },
|
|
102
|
-
maxLimit: 100,
|
|
103
|
-
path: "data/articles.json",
|
|
104
|
-
searchFields: ["title", "summary"],
|
|
105
|
-
select: ["slug", "title", "category"],
|
|
106
|
-
sort: { field: "title", direction: "asc" },
|
|
107
|
-
workspace: "content",
|
|
171
|
+
export default defineWorkspace({
|
|
172
|
+
store: createBlobDatabaseWorkspaceStore({
|
|
173
|
+
blob: blob.store("workspace-history"),
|
|
174
|
+
database: () => useDatabase("history").db,
|
|
175
|
+
workspace: "drop-123",
|
|
176
|
+
}),
|
|
108
177
|
})
|
|
109
178
|
```
|
|
110
179
|
|
|
111
|
-
Nuxt auto-imports the Vue composables when this module is installed. Plain Vue apps can import them directly from `@vite-hub/workspace/collections/client`.
|
|
112
|
-
Default immediate requests start during browser setup so relative endpoints do not escape Nuxt's server request context. Inject `request` and call `refresh()` when an application needs SSR loading.
|
|
113
|
-
|
|
114
180
|
```ts
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
181
|
+
import { useWorkspace } from "@vite-hub/workspace"
|
|
182
|
+
|
|
183
|
+
const workspace = useWorkspace("drop", { mode: "write" })
|
|
184
|
+
const revision = await workspace.history.commit({
|
|
185
|
+
ifHead: (await workspace.history.head())?.id ?? null,
|
|
186
|
+
files: { "index.html": "<h1>Hello</h1>" },
|
|
187
|
+
message: "Publish",
|
|
188
|
+
metadata: { author: "maxi" },
|
|
121
189
|
})
|
|
190
|
+
const version = await workspace.history.open(revision.id)
|
|
191
|
+
await version.readFile("index.html")
|
|
192
|
+
await workspace.history.list({ limit: 20 })
|
|
193
|
+
await workspace.history.usage()
|
|
194
|
+
```
|
|
122
195
|
|
|
123
|
-
|
|
196
|
+
Commits publish the complete desired file set with an atomic head comparison.
|
|
197
|
+
Catch `isWorkspaceConflict(error)` for a stale `ifHead`. Omitted paths disappear
|
|
198
|
+
from the new revision; earlier versions retain their bytes. Read mode exposes
|
|
199
|
+
`head`, `list`, `refs`, `open`, and `usage`. Stores without retained history
|
|
200
|
+
throw `WORKSPACE_R0069`. Existing checkpoint and rebase behavior is unchanged.
|
|
201
|
+
|
|
202
|
+
History has named refs. Calls without `ref` use `main`. Each ref has its own head
|
|
203
|
+
and timeline, and revisions and bytes are shared across refs. A `changes` commit
|
|
204
|
+
patches the ref head, so saving one draft file does not resend the folder:
|
|
205
|
+
|
|
206
|
+
```ts fragment
|
|
207
|
+
const draft = await workspace.history.head({ ref: "draft" })
|
|
208
|
+
await workspace.history.commit({
|
|
209
|
+
ref: "draft",
|
|
210
|
+
ifHead: draft?.id ?? null,
|
|
211
|
+
changes: { put: { "posts/hello.md": markdown }, delete: ["posts/old.md"] },
|
|
212
|
+
})
|
|
213
|
+
await workspace.history.refs() // [{ name: "draft", head }, { name: "main", head }]
|
|
124
214
|
```
|
|
125
215
|
|
|
126
|
-
|
|
216
|
+
Rules, validators, hooks, and Source ownership run on every changed path in both
|
|
217
|
+
forms. Use `registerWorkspacePlugin(name, plugin)` to add rules and hooks to a
|
|
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"`.
|
|
222
|
+
|
|
223
|
+
File objects use `_vitehub/workspace-history[/<prefix>]/<sha256(workspace)>/sha256/<digest>` Blob keys.
|
|
224
|
+
The optional `prefix` nests below `_vitehub/workspace-history/`, so ViteHub owns every
|
|
225
|
+
history object.
|
|
226
|
+
Identical bytes share one object within a workspace. Database stores immutable
|
|
227
|
+
manifests, refs, an upload catalog, and Workspace metadata. Usage counts unique
|
|
228
|
+
uncompressed file bytes across committed revisions on every ref. Workspaces have separate
|
|
229
|
+
namespaces, so deletion needs no cross-workspace reference counts.
|
|
230
|
+
|
|
231
|
+
Normal file writes stage changes in instance memory until checkpoint or snapshot,
|
|
232
|
+
which commit to `main`. Only committed history is durable; keep drafts on a ref. `store.delete()` permanently tombstones the
|
|
233
|
+
identity and removes its history and objects. Retry deletion after storage errors
|
|
234
|
+
or after stopping abandoned uploads. Failed publications can leave reusable
|
|
235
|
+
objects outside retained usage accounting until deletion. Pruning is not supported.
|
|
236
|
+
Use a strongly consistent Blob backend and small folders. See
|
|
237
|
+
[configuration](https://vitehub.dev/docs/workspace/configure#blob-database-store)
|
|
238
|
+
and [server API](https://vitehub.dev/docs/workspace/server-api#retained-folder-history).
|
|
239
|
+
|
|
240
|
+
Read history from the CLI. The commands are operations that run in the Nitro
|
|
241
|
+
runtime of the dev server, or of a deployed app with `--url`, and never write:
|
|
127
242
|
|
|
128
|
-
|
|
243
|
+
```sh
|
|
244
|
+
vitehub workspace history content # revisions on every ref, newest first
|
|
245
|
+
vitehub workspace history content --ref draft
|
|
246
|
+
vitehub workspace refs content # each ref and its head revision
|
|
247
|
+
vitehub workspace show content draft # one revision and its files
|
|
248
|
+
vitehub workspace show content draft posts/hello.md
|
|
249
|
+
```
|
|
129
250
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
import { createWorkspaceNitroConfig } from "@vite-hub/workspace/nitro"
|
|
251
|
+
Add `--json` for machine-readable output. A Store without retained history
|
|
252
|
+
fails with `WORKSPACE_R0069`.
|
|
133
253
|
|
|
134
|
-
|
|
254
|
+
Work on one ref in a local folder, as with `git pull` and `git push`:
|
|
255
|
+
|
|
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`
|
|
135
260
|
```
|
|
136
261
|
|
|
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).
|
|
322
|
+
|
|
323
|
+
## Reuse a Source definition
|
|
324
|
+
|
|
325
|
+
Bind a standalone Source definition when direct reads, Content, and Workspace
|
|
326
|
+
need the same origin:
|
|
327
|
+
|
|
137
328
|
```ts
|
|
138
|
-
|
|
139
|
-
import {
|
|
140
|
-
import { defineConfig } from "vite"
|
|
329
|
+
import { createSource, glob } from "@vite-hub/source"
|
|
330
|
+
import { defineWorkspace } from "@vite-hub/workspace"
|
|
141
331
|
|
|
142
|
-
|
|
143
|
-
|
|
332
|
+
const docs = glob({ cwd: "docs", include: "**/*.md" })
|
|
333
|
+
const reader = createSource(docs)
|
|
334
|
+
await reader.read("intro.md")
|
|
335
|
+
|
|
336
|
+
export default defineWorkspace({
|
|
337
|
+
sources: {
|
|
338
|
+
docs: { source: docs, mount: "docs", materialize: "lazy" },
|
|
339
|
+
},
|
|
144
340
|
})
|
|
145
341
|
```
|
|
146
342
|
|
|
147
|
-
|
|
343
|
+
The key `intro.md` appears at `docs/intro.md` in the Workspace. The binding owns
|
|
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`.
|
|
353
|
+
Content also accepts the definition with `defineContent({ source: docs })` and
|
|
354
|
+
opens a new reader for each refresh.
|
|
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
|
+
|
|
361
|
+
Use Workspace helpers such as `file()` and `github()` when a definition only
|
|
362
|
+
needs Workspace binding options. Existing bindings remain valid. For standalone
|
|
363
|
+
custom loaders, replace the Source `custom()` helper with `defineSource()`.
|
|
364
|
+
Workspace's `custom()` helper remains available.
|
|
148
365
|
|
|
149
366
|
Workspace resolves a Source revision once before preparation and materialization.
|
|
150
367
|
`materializeSources()` reports that generic revision in each Source status, and
|
|
151
368
|
every key and item read in the lifecycle observes the same identity. Workspace
|
|
152
369
|
search remains literal or regular-expression filesystem search over the visible
|
|
153
|
-
tree; use Comark Content through `@vite-hub/
|
|
370
|
+
tree; use Comark Content through `@vite-hub/content` for parsed-document
|
|
154
371
|
navigation, query, cache, and ranked full-text search.
|
|
155
372
|
|
|
156
|
-
##
|
|
373
|
+
## Sandbox sessions
|
|
157
374
|
|
|
158
|
-
Workspace definitions are runtime-free. To run generated code, open a [`@vite-hub/
|
|
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.
|
|
159
376
|
|
|
160
|
-
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.
|
|
161
378
|
|
|
162
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.
|
|
163
380
|
|
|
164
381
|
Use `startSession({ host, writeBack: false })` for a private writable runtime that must never publish its changes. `diff()` and `commit()` are unavailable in this mode, and `close()` restores the authoritative Workspace without first scanning the runtime tree. Agent Definitions select this mode automatically for read-only Workspaces.
|
|
165
382
|
|
|
166
|
-
|
|
383
|
+
Use `startSession({ disposableTarget: true, host, target })` only when the caller owns `target` and deletes it after `close()`. `close()` and failed setup then leave the target as it is instead of restoring the Workspace tree there. `commit()` is unchanged. This option cannot be combined with `attach`. The Provider Agent Driver sets it for its temporary root.
|
|
167
384
|
|
|
168
|
-
|
|
385
|
+
Basic Sessions started without a host also honor `writeBack: false`. Their private overlay remains writable, while `diff()` and `commit()` are unavailable.
|
|
169
386
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
```bash
|
|
173
|
-
pnpm add mountx@0.0.2
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
```ts
|
|
177
|
-
import { createWorkspaceDriver } from "@vite-hub/workspace/mountx"
|
|
178
|
-
import { mount } from "mountx/auto"
|
|
179
|
-
|
|
180
|
-
const session = await workspace.startSession()
|
|
181
|
-
|
|
182
|
-
try {
|
|
183
|
-
const mounted = await mount(createWorkspaceDriver(session), "/tmp/vitehub-docs")
|
|
184
|
-
|
|
185
|
-
try {
|
|
186
|
-
// Programs can now use /tmp/vitehub-docs as an ordinary directory.
|
|
187
|
-
}
|
|
188
|
-
finally {
|
|
189
|
-
await mounted.unmount()
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
await session.commit({ message: "accept projected changes" })
|
|
193
|
-
}
|
|
194
|
-
finally {
|
|
195
|
-
await session.close()
|
|
196
|
-
}
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
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.
|
|
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`.
|
|
200
388
|
|
|
201
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.
|
|
202
390
|
|
|
@@ -204,31 +392,34 @@ Built-in coding Agent Drivers use Workspace Sessions to materialize the selected
|
|
|
204
392
|
|
|
205
393
|
Use `hubWorkspace()` in Vite to discover workspace definitions, emit the workspace manifest for local development, and make the runtime store available to server code.
|
|
206
394
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
`workspace.snapshot()` creates a durable Store snapshot, then runs every configured Workspace publisher. Use `workspace.publish()` when the current Store contents should be published without advancing the Store's snapshot history:
|
|
395
|
+
Packages can contribute a Workspace Definition from their own Vite plugin with `vitehub.workspaces`. Each entry has the shared contribution shape `{ name, definition: { module, export }, reason? }`. `module` is an absolute path, a `file:` URL, or a package specifier. `export` defaults to `default`:
|
|
210
396
|
|
|
211
397
|
```ts
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
|
|
398
|
+
const plugin = {
|
|
399
|
+
name: "my-package/vite",
|
|
400
|
+
vitehub: {
|
|
401
|
+
workspaces: () => [{
|
|
402
|
+
name: "content",
|
|
403
|
+
definition: { module: "my-package/workspace", export: "contentWorkspace" },
|
|
404
|
+
reason: "Stores CMS documents.",
|
|
405
|
+
}],
|
|
406
|
+
},
|
|
407
|
+
}
|
|
215
408
|
```
|
|
216
409
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
A GitHub publisher cannot publish directly to the repository and branch backing the active GitHub Store because that would move the Store branch behind its loaded baseline. Use `workspace.snapshot()` for that branch, or configure the publisher with a different repository or branch.
|
|
410
|
+
Contributed Workspaces appear in the generated registry, `WorkspaceName` types, `vitehub inspect`, and the Console, like discovered files. A name used by both a discovered file and a contribution fails the build with `WORKSPACE_B0003`.
|
|
220
411
|
|
|
221
412
|
## Hosted Cloudflare runtime
|
|
222
413
|
|
|
223
|
-
Nuxt apps
|
|
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:
|
|
224
415
|
|
|
225
416
|
```ts
|
|
226
417
|
export default defineNuxtConfig({
|
|
227
|
-
modules: ["
|
|
228
|
-
|
|
418
|
+
modules: ["vite-hub/nuxt"],
|
|
419
|
+
vitehub: {
|
|
229
420
|
workspace: {
|
|
230
421
|
store: {
|
|
231
|
-
|
|
422
|
+
driver: "github",
|
|
232
423
|
repository: "owner/repo",
|
|
233
424
|
branch: "main",
|
|
234
425
|
root: ".vitehub/workspaces/docs",
|
|
@@ -246,7 +437,7 @@ import { configureCloudflareWorkspaceRuntime } from "@vite-hub/workspace/cloudfl
|
|
|
246
437
|
configureCloudflareWorkspaceRuntime()
|
|
247
438
|
```
|
|
248
439
|
|
|
249
|
-
`useWorkspace()` will then resolve `cloudflare
|
|
440
|
+
`useWorkspace()` will then resolve `cloudflare` Workspace Stores from the configured runtime store or the Workspace Definition's `store` option.
|
|
250
441
|
|
|
251
442
|
Select Cloudflare Artifacts explicitly when a Cloudflare Worker needs durable, versioned Workspace state:
|
|
252
443
|
|
|
@@ -256,29 +447,43 @@ import { hubWorkspace } from "@vite-hub/workspace/vite"
|
|
|
256
447
|
import { defineConfig } from "vite"
|
|
257
448
|
|
|
258
449
|
export default defineConfig({
|
|
259
|
-
plugins: [hubWorkspace(
|
|
260
|
-
workspace: {
|
|
450
|
+
plugins: [hubWorkspace({
|
|
261
451
|
store: {
|
|
262
|
-
|
|
452
|
+
driver: "cloudflare",
|
|
263
453
|
binding: "WORKSPACE_ARTIFACTS",
|
|
264
454
|
namespace: "vitehub",
|
|
265
455
|
},
|
|
266
|
-
},
|
|
456
|
+
})],
|
|
267
457
|
})
|
|
268
458
|
```
|
|
269
459
|
|
|
270
|
-
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
|
|
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.
|
|
271
461
|
|
|
272
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.
|
|
273
463
|
|
|
464
|
+
## Vercel Blob persistence
|
|
465
|
+
|
|
466
|
+
The `vercel` Store keeps Workspace files under `_vitehub/workspaces/<workspace>/`.
|
|
467
|
+
The optional `prefix`, or `VITEHUB_WORKSPACE_BLOB_PREFIX`, nests below
|
|
468
|
+
`_vitehub/workspaces/`, so ViteHub owns every Workspace object. A prefix accepts
|
|
469
|
+
letters, numbers, underscores, dashes, and single slashes.
|
|
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
|
+
|
|
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.
|
|
476
|
+
|
|
274
477
|
## GitHub-backed persistence
|
|
275
478
|
|
|
276
479
|
Use the GitHub Workspace Store when a hosted runtime needs durable Workspace file-tree state without a provider-specific artifact store:
|
|
277
480
|
|
|
278
481
|
```ts
|
|
482
|
+
import { defineWorkspace } from "@vite-hub/workspace"
|
|
483
|
+
|
|
279
484
|
export default defineWorkspace({
|
|
280
485
|
store: {
|
|
281
|
-
|
|
486
|
+
driver: "github",
|
|
282
487
|
repository: "owner/repo",
|
|
283
488
|
branch: "main",
|
|
284
489
|
root: ".vitehub/workspaces/<workspace>",
|
|
@@ -286,25 +491,44 @@ export default defineWorkspace({
|
|
|
286
491
|
})
|
|
287
492
|
```
|
|
288
493
|
|
|
289
|
-
|
|
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.
|
|
290
495
|
|
|
291
|
-
|
|
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.
|
|
292
497
|
|
|
293
|
-
|
|
294
|
-
|
|
498
|
+
GitHub-backed Stores also expose the retained history reader. Repository branches are
|
|
499
|
+
history refs, and GitHub commits are immutable Workspace revisions. Revision metadata
|
|
500
|
+
includes the commit author and a `url` that opens the commit on GitHub. Revision file
|
|
501
|
+
views read the configured Workspace root from the commit tree and fetch file bytes from
|
|
502
|
+
that commit. The `vitehub workspace history`, `refs`, and `show` CLI commands
|
|
503
|
+
inspect this data; the Console Workspace/files view does not yet provide a history
|
|
504
|
+
navigator.
|
|
295
505
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
By default, the publisher treats `root` as an exact mirror and deletes remote paths that are absent from the Workspace snapshot. Set `deleteUntracked: false` when the publisher owns only part of `root`; Workspace files are still created and updated, while every remote-only path remains on GitHub, including files from earlier snapshots.
|
|
506
|
+
The GitHub Store also writes history. `history.commit()` creates one commit, checks `ifHead` and
|
|
507
|
+
`ifHeads` against the branch heads, and starts a missing branch from the `refs.published` branch when it is set, else from the default branch. `startFrom` names the revision a missing ref starts from. Options:
|
|
508
|
+
`root: ""` is the repository root. `refs: { published?: string, draft?: string }` names the branches
|
|
509
|
+
of the `published` and `draft` history refs and reports revisions with those names. `database` is
|
|
510
|
+
carried on the store target and not used by the Store. `history.digest(bytes)` and every revision
|
|
511
|
+
view use Git blob shas as digests. Commit `metadata` is kept in the commit message as a
|
|
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
|
|
513
|
+
path. `history.head()` keeps a branch head for 5 seconds. The Store reads the repository and token on
|
|
514
|
+
first use, so a missing one throws `WORKSPACE_R0072` then, not when the definition loads.
|
|
307
515
|
|
|
308
516
|
Built on [`@vite-hub/source`](../source/README.md) and [isomorphic-git](https://isomorphic-git.org/). Shell-backed Workspace tools load `@vite-hub/shell` only when the shell tool executes.
|
|
309
517
|
|
|
310
518
|
Learn more at [vitehub.dev](https://vitehub.dev).
|
|
519
|
+
|
|
520
|
+
Startup and build Source cleanup track ownership by Workspace name. When definitions share a Store, removing or refreshing one definition does not remove files last materialized by another definition. Cleanup also preserves files without a recorded Workspace owner, including files from legacy snapshots. Shared paths still contain the most recent write.
|
|
521
|
+
|
|
522
|
+
Source Sync and runtime Source materialization change files only inside the mount of the Source that they process. A Source with an empty mount owns the Workspace root. Source Sync with `stale: "remove"` removes only stale paths inside the current mount. If you move a Source mount, the files in the old mount stay. Remove them yourself if you do not need them. When mounts for the same Source key share an output path, sync retains their claims separately. Each mount can update the file, and every claim tracks the digest of the latest Source write to that shared path. Stale cleanup removes the file only after the other mounts release their claims and its content still matches that digest. Releasing a claim preserves this digest without adopting current file content, including user edits that restore an older Source version.
|
|
523
|
+
|
|
524
|
+
`history.rebase({ takeRemote })` replaces local content at each listed path, so each path must be writable. A Source-backed path fails with a read-only error before the Store rebases.
|
|
525
|
+
|
|
526
|
+
Workspace internals keep Source Sync state, Source snapshots, startup and build indexes, and file owner records in Store metadata. Cleanup uses these records to decide which files to remove. Metadata keys that start with `source:`, `workspace:`, `workspace-file-`, or `loader:` are reserved for this, and public `setMeta` rejects them. Use your own prefix for application metadata.
|
|
527
|
+
|
|
528
|
+
`metadata.source` is reserved for internal Source materialization. Public Workspace writes and write validators cannot assign this ownership marker. Write validators and `write:before` hooks can change the write path. ViteHub checks the final path again, so a changed path cannot write into a Source mount or a Source-backed file. Explicit loaders write through `ctx.store`; when multiple build Sources share a mount, these writes must preserve the input item's `metadata.source` or set it to the owning Source key for derived output within that Source's mount. Ambiguous writes fail before storing the file.
|
|
529
|
+
|
|
530
|
+
File metadata must be a JSON-safe plain object containing only plain objects, dense arrays, strings, booleans, null, and finite numbers except negative zero. Omit optional properties instead of assigning `undefined`. Bigints, cycles, class instances, accessors, symbols, and functions are rejected. Workspace writes validate this contract before provider dispatch; direct local and memory Store writes also validate before changing file content. This keeps accepted metadata values consistent after a local Store restart.
|
|
531
|
+
|
|
532
|
+
Custom Stores can implement `removeEmptyDirectory(path)` to support build directory cleanup. The operation must check the path inside the Store mutation boundary, preserve files and missing paths, and reject nonempty directories. Stores without this method retain generated directories. The local, memory, and Cloudflare Artifacts Stores implement it.
|
|
533
|
+
|
|
534
|
+
Writable facade wrappers that replace `fs` and omit symbol properties must forward internal Source Sync routing explicitly. After creating a wrapper, call `forwardWorkspaceFacade(base, wrapped)` from `@vite-hub/workspace/runtime`. This preserves durable sync metadata and enclosing Source guards without exposing internal setters or passing capabilities to the wrapper's public `setMeta` method. Public metadata writes still reject reserved keys.
|