feat: add Workspace class — persistent virtual filesystem for Agents#1069
Merged
threepointone merged 9 commits intomainfrom Mar 5, 2026
Merged
feat: add Workspace class — persistent virtual filesystem for Agents#1069threepointone merged 9 commits intomainfrom
threepointone merged 9 commits intomainfrom
Conversation
Add just-bash as a dependency in packages/agents and refine the fiber mixin typings. Introduce a FiberAgentClass generic constructor return type so consumers extending the mixin retain FiberMethods on `this`, broaden spawnFiber's methodName to string, export FiberMethods for external use, and add several internal tracking properties to the interface. Update a test to pass a string methodName accordingly.
Introduce a new Workspace class that provides durable hybrid file storage (SQLite inline + optional R2 for large files) and optional bash execution. Replaces the previous withWorkspace mixin pattern with a class-based API (usage: new Workspace(this, { namespace, r2, r2Prefix, inlineThreshold, bashLimits })). The Workspace includes namespace validation, per-host registration to avoid duplicate namespaces, a scoped SQL helper, lazy table initialization, and R2 key prefixing.
Add TestWorkspaceAgent exposing workspace operations, a comprehensive vitest suite (workspace.test.ts) covering file I/O, dirs, rm, listing, path normalization and bash integration, and wire the agent into the test worker and wrangler config. Add just-bash as a dependency in package.json and include it in the test runtime config. Update changelog (.changeset) to document the new Workspace class.
Introduce a new Workspace class providing durable file storage for Agents with a hybrid SQLite+R2 backend and optional just-bash execution (usage: new Workspace(this, { r2, r2Prefix })). Update package exports, tests, and workspace implementation to use the new API (idPrefix renamed to r2Prefix). Also update package metadata and regenerate package-lock.json to reflect dependency changes and added example entries.
Introduce an experimental Workspace virtual filesystem (hybrid SQLite+R2) under agents/experimental/workspace with BashSession, persistent cwd/env sessions, streaming I/O, symlinks, change events, and diagnostics/observability hooks. Add design documentation (design/workspace.md) and register it in design indices. Add a workspace-chat example (frontend, server, configs, vite/wrangler, types) demonstrating AIChatAgent integration and tools (read/write/list/mkdir/bash/glob). Expose the workspace API under the package exports as ./experimental/workspace, add observability helpers and tests updates, and make a small example model comment tweak in the OpenAI SDK sample.
🦋 Changeset detectedLatest commit: 6157447 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Add a STORAGE_KEY and getUserId() helper that retrieves a persisted UUID from localStorage (or generates one with crypto.randomUUID() and stores it). Fall back to "default" when window is undefined. Use the returned ID as the agent name when initializing the WorkspaceChatAgent so the client retains a stable identifier across sessions.
commit: |
Introduce a minimal TurndownService stub (remove and turndown methods) at experimental/workspace-chat/src/turndown-stub.ts and update vite.config.ts to import node:path and alias 'turndown' to the stub. This avoids pulling in the real turndown package for the workspace-chat experiment during bundling.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds the Workspace class to
agents/experimental/workspace— a persistent virtual filesystem backed by Durable Object SQLite with optional R2 spillover for large files.This PR includes the full implementation, comprehensive tests, a design document, and an interactive demo.
What is included
1. Workspace class (
packages/agents/src/experimental/workspace.ts)A complete virtual filesystem that any Agent can attach:
Filesystem operations:
readFile,writeFile,deleteFile,renamereadDir,mkdir,stat,lstat,existsglob(picomatch-based pattern matching)symlink,readlinkgetWorkspaceInfo(aggregate stats)Storage model:
Bash execution:
bash(command, { cwd })— run shell commands viajust-bash(pure JS bash interpreter)workspace:bash) emitted for every execution2. BashSession — persistent shell sessions
cwdandenvpersist acrossexec()callsisClosedgetter,Symbol.disposesupport3. Tests (
packages/agents/src/tests/workspace.test.ts)29 tests covering:
4. Design document (
design/workspace.md)Covers: storage model, namespace isolation, symlinks, change events, observability, bash execution, bash sessions, streaming I/O, security boundaries, key decisions, tradeoffs, and testing strategy.
5. Experimental demo (
experimental/workspace-chat/)An interactive AIChatAgent + Workspace example:
@cf/zai-org/glm-4.7-flashvia Workers AIAPI surface
New export:
agents/experimental/workspaceWorkspaceBashSessionBashOptionsBashResultFileInfoFileStatWorkspaceChangeEventWorkspaceOptionsWorkspaceHostdefineCommandChangeset
Included in
.changeset/workspace-class.md— minor bump foragentspackage.