@vite-hub/workspace 0.0.4 → 0.1.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 +225 -58
- package/dist/{ai-CjxvGqM0.d.ts → ai-BW2ZhizI.d.ts} +22 -7
- package/dist/{ai-BqCC8BpY.js → ai-BZyLwULx.js} +147 -66
- package/dist/ai.d.ts +2 -2
- package/dist/ai.js +1 -1
- package/dist/{asset-registry-8QI3ML3K.js → asset-registry-DfBV5kmw.js} +3 -2
- package/dist/association-Cm0dUTDU-CDDhJnIh-Cv3bWnVb.js +19 -0
- package/dist/blob-database.d.ts +521 -0
- package/dist/blob-database.js +601 -0
- package/dist/cloudflare.d.ts +5 -6
- package/dist/cloudflare.js +1 -1
- package/dist/config-B7dmzDX3.js +1112 -0
- package/dist/{config-DE9xlaIw.d.ts → config-DLKdaFWN.d.ts} +1 -2
- package/dist/error-diagnostics-A_8Kp-48.js +116 -0
- package/dist/error-diagnostics-DY5GP47p.js +96 -0
- package/dist/events-7EBoeIPd-A2RUkJi5-BxrICQ17.js +354 -0
- package/dist/events-CRaLy7U3-3PNNp5WZ-Gv9nd0cH.js +214 -0
- package/dist/events-CeChclTf-CX-gD8oy-4aL2j6V-.js +527 -0
- package/dist/feed-DsC7Vws1-M_de2nSK-tKc0Pwo8.js +248 -0
- package/dist/feed-Dyf730Ys-D0HgBba6-BUnCa5gS.js +179 -0
- package/dist/file-C0_aPWSS.js +26 -0
- package/dist/file-metadata-CxDy-E2H.js +58 -0
- package/dist/{files-Q6xZjDHA.js → files-C7Px8uaC.js} +3 -3
- package/dist/forgejo-BN8ItCfl-Bbn4vhDd.js +2278 -0
- package/dist/{github-DHnjxQIX.js → github-CPxHtFB7.js} +16 -23
- package/dist/github-DtncTfmv-Du2S8lGF.js +4159 -0
- package/dist/gitlab-BoDm8-BC-xzZsW9eW.js +2530 -0
- package/dist/glob--XcLlcml.js +22 -0
- package/dist/glob--kNYDbfU.js +30 -0
- package/dist/graphql-DG5aJBT3-DceyFYdM-C4saqX37.js +489 -0
- package/dist/{host-DJH8cuoU.js → host-CFnrTXTK.js} +97 -41
- package/dist/{hosted-RPeJOCFz.js → hosted-acMA5XyL.js} +102 -19
- package/dist/hosted-vercel-blob-DKntsHaf.js +12603 -0
- package/dist/hosted-vercel-blob.d.ts +5 -6
- package/dist/hosted-vercel-blob.js +1 -1
- package/dist/hosted.d.ts +6 -7
- package/dist/hosted.js +1 -1
- package/dist/index.d.ts +57 -36
- package/dist/index.js +56 -56
- package/dist/inspect-BoObD2cJ.js +167 -0
- package/dist/internal/path.d.ts +2 -0
- package/dist/internal/path.js +2 -0
- package/dist/lifecycle-BwZ7c9hb.js +596 -0
- package/dist/loader.d.ts +5 -6
- package/dist/loader.js +3 -2
- package/dist/mcp-resources-BREFCmtn.js +39 -0
- package/dist/memory-BbwOqDXl.js +248 -0
- package/dist/metadata-target-DZEZQGHA.js +1588 -0
- package/dist/mountx.d.ts +4 -6
- package/dist/mountx.js +10 -8
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +1 -1
- package/dist/nuxt.d.ts +13 -12
- package/dist/nuxt.js +4 -8
- package/dist/operations-BcpWr41m.js +159 -0
- package/dist/operations-CGqY1XeG.js +965 -0
- package/dist/operations-DnOwKsJT.d.ts +136 -0
- package/dist/operations.d.ts +53 -0
- package/dist/operations.js +2 -0
- package/dist/path-CNAwN7pw.js +114 -0
- package/dist/path-DrSIenjj.js +59 -0
- package/dist/path-zHxQUbqa.d.ts +9 -0
- package/dist/plugins-DqQ8b4T5.d.ts +10 -0
- package/dist/provider-kXjfli9u.js +1457 -0
- package/dist/providers/github/store.d.ts +3 -5
- package/dist/providers/github/store.js +1 -1
- package/dist/{registry-D3yzt8HQ.js → registry-Bp-8UUfG.js} +9 -7
- package/dist/{registry-Uj6IVxes.d.ts → registry-Cg1TJVVZ.d.ts} +1 -2
- package/dist/{request-execution-B-dSFlGB.js → request-execution-Dk9rY-Yh.js} +19 -19
- package/dist/{chunk-2rV9d50f.js → rolldown-runtime-B4iAMlE-.js} +2 -2
- 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 +1 -2
- package/dist/runtime/state.d.ts +3 -3
- package/dist/runtime/state.js +6 -6
- package/dist/runtime/workspace.d.ts +1 -1
- package/dist/runtime/workspace.js +1 -1
- package/dist/runtime.d.ts +51 -17
- package/dist/runtime.js +320 -60
- package/dist/{search-BpiCF2Tw.js → search-CrTmXj5h.js} +10 -9
- package/dist/server-BNQ-Nbjj.js +290 -0
- package/dist/server.d.ts +22 -34
- package/dist/server.js +2 -328
- package/dist/shared-DalXdP0i.js +2158 -0
- package/dist/source-metadata.d.ts +6 -7
- package/dist/source-metadata.js +7 -7
- package/dist/{state-tYcRWEh2.d.ts → state-B8zbLi5t.d.ts} +3 -3
- package/dist/store-CXgmu-uw.js +1729 -0
- package/dist/{sync-DnTQwt8r.js → sync-CN6ec-5M.js} +61 -41
- package/dist/templates-Bn8a-pd2-D9DhJEVD-CBfXNRzz.js +125 -0
- package/dist/test.d.ts +1 -1
- package/dist/test.js +1 -1
- package/dist/{token-CVzURBxC.js → token-CO62GglH.js} +3 -3
- package/dist/{types-CYuwjJ4V.d.ts → types-DeK9GIxy.d.ts} +256 -24
- package/dist/{use-BTNDR5Rd.js → use-BQj7nSz6.js} +82 -41
- package/dist/{use-BiHzt0xA.d.ts → use-DhwhbAVV.d.ts} +16 -11
- package/dist/utils-Blrh4N2n.js +545 -0
- package/dist/vite-BEvgU2GY.js +20909 -0
- package/dist/vite-CcZmMQ7S.d.ts +476 -0
- package/dist/vite.d.ts +2 -2
- package/dist/vite.js +2 -2
- package/dist/webhooks-DgHwxxYz-D1V2LOr1-azofFOiP.js +1565 -0
- package/dist/{workspace-Dq08Yn72.js → workspace-6pxkOuxr.js} +361 -230
- package/dist/{workspace-Xddf4G1B.d.ts → workspace-BWJQBK1u.d.ts} +4 -3
- package/package.json +89 -55
- 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/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/runtime-options-BsPSv5O7.js +0 -13
- package/dist/runtime-type-iEE6BjQJ.js +0 -34
- package/dist/shared-DTR1Hhma.js +0 -331
- package/dist/store-Dt_Jyys3.js +0 -608
- package/dist/vite-BptCrpv2.js +0 -4526
- package/dist/vite-CtA9guIM.d.ts +0 -66
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
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.
|
|
@@ -19,6 +19,14 @@ Use `skipLibCheck: true` in app TypeScript configs while ViteHub depends on runt
|
|
|
19
19
|
|
|
20
20
|
## Minimal API
|
|
21
21
|
|
|
22
|
+
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.
|
|
23
|
+
|
|
24
|
+
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.
|
|
25
|
+
|
|
26
|
+
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.
|
|
27
|
+
|
|
28
|
+
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.
|
|
29
|
+
|
|
22
30
|
```text
|
|
23
31
|
server/
|
|
24
32
|
workspaces/
|
|
@@ -73,6 +81,24 @@ export default defineEventHandler(async () => {
|
|
|
73
81
|
})
|
|
74
82
|
```
|
|
75
83
|
|
|
84
|
+
`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.
|
|
85
|
+
|
|
86
|
+
`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.
|
|
87
|
+
|
|
88
|
+
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.
|
|
89
|
+
|
|
90
|
+
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.
|
|
91
|
+
|
|
92
|
+
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.
|
|
93
|
+
|
|
94
|
+
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.
|
|
95
|
+
|
|
96
|
+
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.
|
|
97
|
+
|
|
98
|
+
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.
|
|
99
|
+
|
|
100
|
+
`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.
|
|
101
|
+
|
|
76
102
|
Serve a constrained Workspace subtree without custom route plumbing:
|
|
77
103
|
|
|
78
104
|
```ts
|
|
@@ -87,45 +113,120 @@ export default defineWorkspaceFileHandler({
|
|
|
87
113
|
})
|
|
88
114
|
```
|
|
89
115
|
|
|
90
|
-
##
|
|
116
|
+
## Retained folder history
|
|
91
117
|
|
|
92
|
-
|
|
118
|
+
Use `@vite-hub/workspace/blob-database` for immutable folder versions backed by
|
|
119
|
+
ViteHub Blob and Database. Include `workspaceHistorySchema` in a Database
|
|
120
|
+
Definition, apply its migrations, and pass
|
|
121
|
+
`createBlobDatabaseWorkspaceStore({ blob, database, workspace })` as the
|
|
122
|
+
Workspace Definition's `store`. The framework also exports
|
|
123
|
+
`vite-hub/workspace/blob-database`.
|
|
93
124
|
|
|
94
125
|
```ts
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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",
|
|
126
|
+
const workspace = useWorkspace("drop", { mode: "write" })
|
|
127
|
+
const revision = await workspace.history.commit({
|
|
128
|
+
ifHead: (await workspace.history.head())?.id ?? null,
|
|
129
|
+
files: { "index.html": "<h1>Hello</h1>" },
|
|
130
|
+
message: "Publish",
|
|
131
|
+
metadata: { author: "maxi" },
|
|
108
132
|
})
|
|
133
|
+
const version = await workspace.history.open(revision.id)
|
|
134
|
+
await version.readFile("index.html")
|
|
135
|
+
await workspace.history.list({ limit: 20 })
|
|
136
|
+
await workspace.history.usage()
|
|
109
137
|
```
|
|
110
138
|
|
|
111
|
-
|
|
112
|
-
|
|
139
|
+
Commits publish the complete desired file set with an atomic head comparison.
|
|
140
|
+
Catch `isWorkspaceConflict(error)` for a stale `ifHead`. Omitted paths disappear
|
|
141
|
+
from the new revision; earlier versions retain their bytes. Read mode exposes
|
|
142
|
+
`head`, `list`, `refs`, `open`, and `usage`. Stores without retained history
|
|
143
|
+
throw `WORKSPACE_R0069`. Existing checkpoint and rebase behavior is unchanged.
|
|
144
|
+
|
|
145
|
+
History has named refs. Calls without `ref` use `main`. Each ref has its own head
|
|
146
|
+
and timeline, and revisions and bytes are shared across refs. A `changes` commit
|
|
147
|
+
patches the ref head, so saving one draft file does not resend the folder:
|
|
113
148
|
|
|
114
149
|
```ts
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
})),
|
|
150
|
+
const draft = await workspace.history.head({ ref: "draft" })
|
|
151
|
+
await workspace.history.commit({
|
|
152
|
+
ref: "draft",
|
|
153
|
+
ifHead: draft?.id ?? null,
|
|
154
|
+
changes: { put: { "posts/hello.md": markdown }, delete: ["posts/old.md"] },
|
|
121
155
|
})
|
|
156
|
+
await workspace.history.refs() // [{ name: "draft", head }, { name: "main", head }]
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Rules, validators, hooks, and Source ownership run on every changed path in both
|
|
160
|
+
forms. Use `registerWorkspacePlugin(name, plugin)` to add rules and hooks to a
|
|
161
|
+
Workspace your package does not define.
|
|
162
|
+
|
|
163
|
+
File objects use `_vitehub/workspace-history[/<prefix>]/<sha256(workspace)>/sha256/<digest>` Blob keys.
|
|
164
|
+
The optional `prefix` nests below `_vitehub/workspace-history/`, so ViteHub owns every
|
|
165
|
+
history object.
|
|
166
|
+
Identical bytes share one object within a workspace. Database stores immutable
|
|
167
|
+
manifests, refs, an upload catalog, and Workspace metadata. Usage counts unique
|
|
168
|
+
uncompressed file bytes across committed revisions on every ref. Workspaces have separate
|
|
169
|
+
namespaces, so deletion needs no cross-workspace reference counts.
|
|
170
|
+
|
|
171
|
+
Normal file writes stage changes in instance memory until checkpoint or snapshot,
|
|
172
|
+
which commit to `main`. Only committed history is durable; keep drafts on a ref. `store.delete()` permanently tombstones the
|
|
173
|
+
identity and removes its history and objects. Retry deletion after storage errors
|
|
174
|
+
or after stopping abandoned uploads. Failed publications can leave reusable
|
|
175
|
+
objects outside retained usage accounting until deletion. Pruning is not supported.
|
|
176
|
+
Use a strongly consistent Blob backend and small folders. See
|
|
177
|
+
[configuration](https://vitehub.dev/docs/workspace/configure#blob-database-store)
|
|
178
|
+
and [server API](https://vitehub.dev/docs/workspace/server-api#retained-folder-history).
|
|
179
|
+
|
|
180
|
+
Read history from the CLI. The commands are operations that run in the Nitro
|
|
181
|
+
runtime of the dev server, or of a deployed app with `--url`, and never write:
|
|
122
182
|
|
|
123
|
-
|
|
183
|
+
```sh
|
|
184
|
+
vitehub workspace history content # revisions on every ref, newest first
|
|
185
|
+
vitehub workspace history content --ref draft
|
|
186
|
+
vitehub workspace refs content # each ref and its head revision
|
|
187
|
+
vitehub workspace show content draft # one revision and its files
|
|
188
|
+
vitehub workspace show content draft posts/hello.md
|
|
124
189
|
```
|
|
125
190
|
|
|
126
|
-
|
|
191
|
+
Add `--json` for machine-readable output. A Store without retained history
|
|
192
|
+
fails with `WORKSPACE_R0069`.
|
|
193
|
+
|
|
194
|
+
## JSON Collections
|
|
127
195
|
|
|
128
|
-
|
|
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:
|
|
221
|
+
|
|
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.
|
|
129
230
|
|
|
130
231
|
```ts
|
|
131
232
|
// nitro.config.ts
|
|
@@ -144,18 +245,47 @@ export default defineConfig({
|
|
|
144
245
|
})
|
|
145
246
|
```
|
|
146
247
|
|
|
147
|
-
|
|
248
|
+
## Reuse a Source definition
|
|
249
|
+
|
|
250
|
+
Bind a standalone Source definition when direct reads, Content, and Workspace
|
|
251
|
+
need the same origin:
|
|
252
|
+
|
|
253
|
+
```ts
|
|
254
|
+
import { createSource } from "@vite-hub/source"
|
|
255
|
+
import { glob } from "@vite-hub/source/glob"
|
|
256
|
+
import { defineWorkspace } from "@vite-hub/workspace"
|
|
257
|
+
|
|
258
|
+
const docs = glob({ cwd: "docs", include: "**/*.md" })
|
|
259
|
+
const reader = createSource(docs)
|
|
260
|
+
await reader.read("intro.md")
|
|
261
|
+
|
|
262
|
+
export default defineWorkspace({
|
|
263
|
+
sources: {
|
|
264
|
+
docs: { source: docs, mount: "docs", materialize: "lazy" },
|
|
265
|
+
},
|
|
266
|
+
})
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
The key `intro.md` appears at `docs/intro.md` in the Workspace. The binding owns
|
|
270
|
+
placement, materialization, sync, and access rules. Source owns retrieval.
|
|
271
|
+
Content also accepts the definition with `defineContent({ source: docs })` and
|
|
272
|
+
opens a new reader for each refresh.
|
|
273
|
+
|
|
274
|
+
Use Workspace helpers such as `file()` and `github()` when a definition only
|
|
275
|
+
needs Workspace binding options. Existing bindings remain valid. For standalone
|
|
276
|
+
custom loaders, replace the Source `custom()` helper with `defineSource()`.
|
|
277
|
+
Workspace's `custom()` helper remains available.
|
|
148
278
|
|
|
149
279
|
Workspace resolves a Source revision once before preparation and materialization.
|
|
150
280
|
`materializeSources()` reports that generic revision in each Source status, and
|
|
151
281
|
every key and item read in the lifecycle observes the same identity. Workspace
|
|
152
282
|
search remains literal or regular-expression filesystem search over the visible
|
|
153
|
-
tree; use Comark Content through `@vite-hub/
|
|
283
|
+
tree; use Comark Content through `@vite-hub/content` for parsed-document
|
|
154
284
|
navigation, query, cache, and ranked full-text search.
|
|
155
285
|
|
|
156
|
-
##
|
|
286
|
+
## Sandbox sessions
|
|
157
287
|
|
|
158
|
-
Workspace definitions are runtime-free. To run generated code, open a [`@vite-hub/
|
|
288
|
+
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
289
|
|
|
160
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.
|
|
161
291
|
|
|
@@ -163,6 +293,12 @@ Use `startSession({ attach: true, host })` only when another integration already
|
|
|
163
293
|
|
|
164
294
|
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
295
|
|
|
296
|
+
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.
|
|
297
|
+
|
|
298
|
+
Basic Sessions started without a host also honor `writeBack: false`. Their private overlay remains writable, while `diff()` and `commit()` are unavailable.
|
|
299
|
+
|
|
300
|
+
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
|
+
|
|
166
302
|
## MountX projection
|
|
167
303
|
|
|
168
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.
|
|
@@ -204,19 +340,22 @@ Built-in coding Agent Drivers use Workspace Sessions to materialize the selected
|
|
|
204
340
|
|
|
205
341
|
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
342
|
|
|
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:
|
|
343
|
+
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
344
|
|
|
211
345
|
```ts
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
|
|
346
|
+
const plugin = {
|
|
347
|
+
name: "my-package/vite",
|
|
348
|
+
vitehub: {
|
|
349
|
+
workspaces: () => [{
|
|
350
|
+
name: "content",
|
|
351
|
+
definition: { module: "my-package/workspace", export: "contentWorkspace" },
|
|
352
|
+
reason: "Stores CMS documents.",
|
|
353
|
+
}],
|
|
354
|
+
},
|
|
355
|
+
}
|
|
215
356
|
```
|
|
216
357
|
|
|
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.
|
|
358
|
+
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
359
|
|
|
221
360
|
## Hosted Cloudflare runtime
|
|
222
361
|
|
|
@@ -267,10 +406,19 @@ export default defineConfig({
|
|
|
267
406
|
})
|
|
268
407
|
```
|
|
269
408
|
|
|
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
|
|
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.
|
|
271
410
|
|
|
272
411
|
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
412
|
|
|
413
|
+
## Vercel Blob persistence
|
|
414
|
+
|
|
415
|
+
The `vercel-blob` Store keeps Workspace files under `_vitehub/workspaces/<workspace>/`.
|
|
416
|
+
The optional `prefix`, or `VITEHUB_WORKSPACE_BLOB_PREFIX`, nests below
|
|
417
|
+
`_vitehub/workspaces/`, so ViteHub owns every Workspace object. A prefix accepts
|
|
418
|
+
letters, numbers, underscores, dashes, and single slashes.
|
|
419
|
+
|
|
420
|
+
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
|
+
|
|
274
422
|
## GitHub-backed persistence
|
|
275
423
|
|
|
276
424
|
Use the GitHub Workspace Store when a hosted runtime needs durable Workspace file-tree state without a provider-specific artifact store:
|
|
@@ -286,25 +434,44 @@ export default defineWorkspace({
|
|
|
286
434
|
})
|
|
287
435
|
```
|
|
288
436
|
|
|
289
|
-
Set `
|
|
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.
|
|
290
438
|
|
|
291
|
-
|
|
439
|
+
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
440
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
root: "generated/docs",
|
|
301
|
-
deleteUntracked: false,
|
|
302
|
-
})],
|
|
303
|
-
})
|
|
304
|
-
```
|
|
441
|
+
GitHub-backed Stores also expose the retained history reader. Repository branches are
|
|
442
|
+
history refs, and GitHub commits are immutable Workspace revisions. Revision metadata
|
|
443
|
+
includes the commit author and a `url` that opens the commit on GitHub. Revision file
|
|
444
|
+
views read the configured Workspace root from the commit tree and fetch file bytes from
|
|
445
|
+
that commit. The `vitehub workspace history`, `refs`, and `show` CLI commands
|
|
446
|
+
inspect this data; the Console Workspace/files view does not yet provide a history
|
|
447
|
+
navigator.
|
|
305
448
|
|
|
306
|
-
|
|
449
|
+
The GitHub Store also writes history. `history.commit()` creates one commit, checks `ifHead` and
|
|
450
|
+
`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:
|
|
451
|
+
`root: ""` is the repository root. `refs: { published?: string, draft?: string }` names the branches
|
|
452
|
+
of the `published` and `draft` history refs and reports revisions with those names. `database` is
|
|
453
|
+
carried on the store target and not used by the Store. `history.digest(bytes)` and every revision
|
|
454
|
+
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
|
|
456
|
+
path. `history.head()` keeps a branch head for 5 seconds. The Store reads the repository and token on
|
|
457
|
+
first use, so a missing one throws `WORKSPACE_R0072` then, not when the definition loads.
|
|
307
458
|
|
|
308
459
|
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
460
|
|
|
310
461
|
Learn more at [vitehub.dev](https://vitehub.dev).
|
|
462
|
+
|
|
463
|
+
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.
|
|
464
|
+
|
|
465
|
+
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.
|
|
466
|
+
|
|
467
|
+
`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.
|
|
468
|
+
|
|
469
|
+
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.
|
|
470
|
+
|
|
471
|
+
`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.
|
|
472
|
+
|
|
473
|
+
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.
|
|
474
|
+
|
|
475
|
+
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.
|
|
476
|
+
|
|
477
|
+
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.
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import { D as WorkspaceAssets, T as Workspace,
|
|
1
|
+
import { D as WorkspaceAssets, T as Workspace, mt as WorkspaceMaterializeSourcesResult } from "./types-DeK9GIxy.js";
|
|
2
|
+
import { ExecutionBudget } from "@vite-hub/runtime";
|
|
2
3
|
import { Tool, ToolSet } from "ai";
|
|
3
|
-
|
|
4
4
|
//#region src/ai.d.ts
|
|
5
5
|
type ShellObservationEvent = "command_finished" | "command_timed_out" | "policy_denied" | "session_disposed";
|
|
6
6
|
interface ShellRuntimeExecOptions {
|
|
7
|
+
budget?: ExecutionBudget;
|
|
7
8
|
cwd?: string;
|
|
8
9
|
env?: Record<string, string>;
|
|
10
|
+
maxOutputLength?: number;
|
|
9
11
|
onStderr?: (chunk: string) => void;
|
|
10
12
|
onStdout?: (chunk: string) => void;
|
|
13
|
+
signal?: AbortSignal;
|
|
11
14
|
stdin?: string;
|
|
12
15
|
timeout?: number;
|
|
13
16
|
workspacePaths?: string[];
|
|
@@ -65,6 +68,16 @@ interface ShellBoundary {
|
|
|
65
68
|
enforcedBy: "provider" | "runtime" | "unsupported";
|
|
66
69
|
supported: boolean;
|
|
67
70
|
};
|
|
71
|
+
execution?: {
|
|
72
|
+
isolation: "in_process" | "process" | "provider_managed" | "unknown";
|
|
73
|
+
model: "virtual" | "host" | "unknown";
|
|
74
|
+
};
|
|
75
|
+
resources?: {
|
|
76
|
+
output: {
|
|
77
|
+
enforcedBy: "provider" | "runtime" | "unsupported";
|
|
78
|
+
unit: "characters";
|
|
79
|
+
};
|
|
80
|
+
};
|
|
68
81
|
}
|
|
69
82
|
interface ShellExecutionProvider {
|
|
70
83
|
analyze?: (command: string, options?: ShellAnalyzeOptions) => Promise<ShellAnalyzeResult>;
|
|
@@ -102,14 +115,16 @@ interface WorkspaceWriteOperations {
|
|
|
102
115
|
type WorkspaceToolOperations = WorkspaceReadOperations & {
|
|
103
116
|
write?: true | WorkspaceWriteOperations;
|
|
104
117
|
};
|
|
105
|
-
interface WorkspaceToolOptions<Operations extends WorkspaceToolOperations | undefined = undefined> extends Pick<ShellSessionPolicy, "maxOutputLength" | "maxShellCalls" | "timeout"> {
|
|
118
|
+
interface WorkspaceToolOptions<Operations extends WorkspaceToolOperations | undefined = undefined, SourceRequests extends boolean = boolean> extends Pick<ShellSessionPolicy, "maxOutputLength" | "maxShellCalls" | "timeout"> {
|
|
106
119
|
broadSearchPaths?: string[];
|
|
107
120
|
cwd?: string;
|
|
121
|
+
executionBudget?: ExecutionBudget;
|
|
108
122
|
executionProvider?: ShellExecutionProvider | (() => MaybePromise<ShellExecutionProvider | undefined>);
|
|
109
123
|
operations?: Operations;
|
|
124
|
+
sourceRequests?: SourceRequests;
|
|
110
125
|
}
|
|
111
126
|
type EnabledReadCapability<Operations, Key extends keyof WorkspaceReadOperations> = Operations extends Record<Key, infer Value> ? Value extends false ? false : true : true;
|
|
112
|
-
type ShellEnabled<Operations> = true extends EnabledReadCapability<Operations, "list"> | EnabledReadCapability<Operations, "read"> | EnabledReadCapability<Operations, "search"> ? true : false;
|
|
127
|
+
type ShellEnabled<Operations, SourceRequests extends boolean = false> = true extends SourceRequests | EnabledReadCapability<Operations, "list"> | EnabledReadCapability<Operations, "read"> | EnabledReadCapability<Operations, "search"> ? true : false;
|
|
113
128
|
type ResolvedWriteOperations<Operations> = Operations extends {
|
|
114
129
|
write: infer Write;
|
|
115
130
|
} ? Write : false;
|
|
@@ -143,8 +158,8 @@ type WorkspaceWriteToolMap = {
|
|
|
143
158
|
path: string;
|
|
144
159
|
}, WorkspacePathResult>;
|
|
145
160
|
};
|
|
146
|
-
type EnabledWriteTools<Selection> = Selection extends true ? WorkspaceWriteToolMap : Selection extends WorkspaceWriteOperations ? { [Key in keyof WorkspaceWriteToolMap as Key extends keyof Selection ? Selection[Key] extends true ? Key : never : never]: WorkspaceWriteToolMap[Key] } : {};
|
|
147
|
-
type WorkspaceTools<Operations = undefined> = ((ShellEnabled<Operations> extends true ? {
|
|
161
|
+
type EnabledWriteTools<Selection> = Selection extends true ? WorkspaceWriteToolMap : Selection extends WorkspaceWriteOperations ? { [Key in keyof WorkspaceWriteToolMap as Key extends keyof Selection ? Selection[Key] extends true ? Key : never : never]: WorkspaceWriteToolMap[Key]; } : {};
|
|
162
|
+
type WorkspaceTools<Operations = undefined, SourceRequests extends boolean = false> = ((ShellEnabled<Operations, SourceRequests> extends true ? {
|
|
148
163
|
shell: Tool<{
|
|
149
164
|
command: string;
|
|
150
165
|
}, WorkspaceShellResult>;
|
|
@@ -157,6 +172,6 @@ type WorkspaceTools<Operations = undefined> = ((ShellEnabled<Operations> extends
|
|
|
157
172
|
}, WorkspaceMaterializeSourcesResult>;
|
|
158
173
|
} : {})) & ToolSet;
|
|
159
174
|
type MaybePromise<T> = T | Promise<T>;
|
|
160
|
-
declare function createWorkspaceTools<Operations extends WorkspaceToolOperations | undefined = undefined>(input: Workspace | WorkspaceAssets, options?: WorkspaceToolOptions<Operations>): WorkspaceTools<Operations>;
|
|
175
|
+
declare function createWorkspaceTools<Operations extends WorkspaceToolOperations | undefined = undefined, SourceRequests extends boolean = false>(input: Workspace | WorkspaceAssets, options?: WorkspaceToolOptions<Operations, SourceRequests>): WorkspaceTools<Operations, SourceRequests>;
|
|
161
176
|
//#endregion
|
|
162
177
|
export { WorkspaceReadOperations as a, WorkspaceToolOptions as c, WorkspaceWriteToolMap as d, createWorkspaceTools as f, WorkspacePathResult as i, WorkspaceTools as l, ShellEnabled as n, WorkspaceShellResult as o, WorkspaceMoveResult as r, WorkspaceToolOperations as s, EnabledReadCapability as t, WorkspaceWriteOperations as u };
|