Work with agents / Local workspaces
Configure workspaces
An agent in a new workspace needs dependencies, its own ports and its .env values to run a test or a dev server. You change how src ws gives each workspace these things in one file in your repository, .source/workspace.yaml.
3 min read
Pick what to configure
| You want to | Read |
|---|---|
| Install dependencies once, and share build caches between workspaces | Install dependencies and share caches |
| Give each workspace its own ports, so that two dev servers never take the same port | Give each workspace its own ports |
Give your commands the .env values of the vault, or copy env files into each workspace | Give each workspace its env values |
| Run a command when a workspace is made, accepted or closed, and repair a workspace | Run hooks in workspaces |
| Keep agents from changing some files | Protect files with read-only paths |
How src reads the config
srcreads the file from your checkout, never from a workspace, so an agent cannot change it for its own workspace.- If the file is not correct,
createstops before it makes a workspace, and names the field. src ws preparereads the config from the commit that it prepares, not from your working tree. An uncommitted change of the config does not change what a prepare runs.
Trust the commands of the config
The config comes with the repository, so a git pull can change its commands. src runs a command or sets a variable from .source/workspace.yaml only after you allow it:
src ws trust
srcshows each command and variable of the config, for examplelayers.tools.install: node scripts/fetch-tools.mjs. The hooks and the variables of the named ports are in this list.- It also shows the vault files that
src ws execreads, with the names of their variables. It never shows a value. See Give each workspace its env values. - It asks you to trust them. In a script, add
--yes. srckeeps your approval in its data folder, never in the repository.
Each approval is bound to what it allowed:
- The approval of the commands is bound to their exact list. If a command changes,
srcasks again. - The approval of the vault is bound to the repository, the names of its vault files and the names of their variables. A new vault file or a new variable needs a new approval. A new value of a variable does not.
Until you trust the config, src skips its commands:
create,restore,prepare,syncandacceptprint a line that names the skipped commands and points atsrc ws trust.- A built-in recipe that the config changes uses its built-in command. A layer that only the config defines is marked
skipped, not trusted. - The hooks do not run, and
src ws execsets no variable of a named port. - A prepare that a git hook starts never runs an untrusted command, and never asks.
Note
The built-in recipes need no trust. src ws init turns on auto-prepare, and that is your consent: a prepare then runs the built-in install of your lockfile, for example pnpm install. That install runs the install scripts of your packages, the same as when you run it by hand.
Check your config
src ws trust
src ws create try-config
src ws exec try-config -- node -p "process.env.TURBO_CACHE_DIR"
src ws close try-config
create lists each layer with its strategy, and exec prints the ports of the workspace. A second create with the same lockfile says cloned from the cache, or says that the layers were ready in its folder from the pool.