Repository navigation
Description
Problem
Three ways to mutate a workspace, each working on only some of them:
type Workspace {
# Eager: write to the host now, return a status string. Local checkout only.
install(ref: String!, name: String, asSdk: Boolean): String!
uninstall(name: String!): String!
configWrite(key: String!, value: String!): String!
init(here: Boolean): String!
envCreate(name: String!): String!
envRemove(name: String!): String!
# Lazy: return a diff (Changeset) the CLI applies later. Local checkout only.
moduleInit(name: String!, sdk: String!): Changeset!
clientInit(path: String!, sdk: String!): Changeset!
clientGenerate: Changeset!
update: Changeset!
migrate: WorkspaceMigration!
# Overlay: in-memory, no side effects. Synthetic workspaces only —
# but that's an accident: local checkouts just aren't materialized yet.
withNewFile(path: String!, contents: String): Workspace!
withNewDirectory(path: String!, source: Directory!): Workspace!
withChanges(changes: Changeset!): Workspace!
}Solution
One write path instead of three:
- Overlay: every mutation stages its change in memory and writes nothing to disk.
- Export: one call writes all the staged changes to disk. Only a local workspace with a Git boundary can export; anywhere else (remote, synthetic, or no Git repo) it fails with a clear error.
- Rootless workspace: with no Git repo,
currentWorkspace()returns a usable workspace instead of erroring; it has no files and can't be exported, but ssh/LLM/-mcontext still works. - Shift logic to the engine: the engine now decides where changes are written, while SDK name resolution and typed init arguments stay in the CLI for now.
API
type Workspace {
# Builders — no side effects, any workspace kind. All return Workspace!.
"Install a module. `name` overrides the config entry key."
withModule(ref: String!, name: String): Workspace!
"Remove an installed module."
withoutModule(name: String!): Workspace!
"Install a module and mark it as an SDK, usable by withInitModule / withInitClient."
withSDK(ref: String!, name: String): Workspace!
"Remove an installed SDK."
withoutSDK(name: String!): Workspace!
"Scaffold a new module with an installed SDK. Runs the SDK's initModule; `args` are SDK-specific."
withInitModule(name: String!, sdk: String!, args: JSON): Workspace!
"Scaffold a generated client bound to `module`, using an installed SDK."
withInitClient(path: String!, sdk: String!, module: String!, args: JSON): Workspace!
"Set a config value at a dotted key, e.g. \"modules.foo.pin\"."
withConfigValue(key: String!, value: String!): Workspace!
"Define a named config environment."
withConfigEnv(name: String!): Workspace!
"Remove a named config environment."
withoutConfigEnv(name: String!): Workspace!
"Add or replace a file."
withNewFile(path: String!, contents: String): Workspace!
"Add a directory."
withNewDirectory(path: String!, source: Directory!): Workspace!
"Apply a changeset."
withChanges(changes: Changeset!): Workspace!
"Re-resolve lockfile pins to their latest allowed versions."
withUpdatedLock: Workspace!
# No init field: the first config edit creates dagger.toml if it's missing.
"Installed modules."
modules: [WorkspaceModule!]!
"An installed module, by name."
module(name: String!): WorkspaceModule!
"Installed SDKs."
sdks: [WorkspaceSDK!]!
"An installed SDK, by name."
sdk(name: String!): WorkspaceSDK!
"Edits accumulated but not yet exported, for preview."
changes: Changeset!
"Write the pending edits to the workspace's own source. Errors when the source can't persist: a remote ref, a synthetic workspace, or a local dir with no Git root."
export: Void!
"Plan the migration from a legacy dagger.json to dagger.toml."
migrate: WorkspaceMigration!
}
"An installed SDK: a module marked for scaffolding other modules and clients."
type WorkspaceSDK {
name: String!
"The module reference this SDK was installed from."
ref: String!
"Modules authored with this SDK."
modules: [WorkspaceModule!]!
"Clients generated with this SDK."
clients: [WorkspaceModule!]!
}Nothing changes for CLI users: the same plan, preview, and apply flow, now applied
through export.
Migration
| Today | Becomes |
|---|---|
install, install(asSdk:true) |
withModule, withSDK |
uninstall |
withoutModule, withoutSDK |
configWrite |
withConfigValue |
envCreate, envRemove |
withConfigEnv, withoutConfigEnv |
moduleInit, clientInit |
withInitModule, withInitClient |
clientGenerate |
removed — SDKs expose generators, so dagger generate handles it |
update |
withUpdatedLock |
moduleList |
modules, module, plus new sdks, sdk |
init |
removed |
| — | changes, export |
Everything returns a workspace now instead of a status string or a changeset.
Design notes
Flat overlay. All edits go into one overlay, so changes is always the full
diff from the starting point. Today overlays can nest, so the chained-overlay test
will be rewritten.
Materialize on demand. For a local checkout, the host files are first loaded
into an immutable snapshot for the overlay to build on. The read path already does
this.
Comment preserving. Config edits use the existing TOML writer that keeps
comments, so hand-written comments in dagger.toml survive.
The lockfile is just another file. Some builders (withModule,
withUpdatedLock) write dagger.lock as well as dagger.toml. That is a normal
multi-file overlay: the lockfile rides along and export writes it like any other
file. Auto-pinning is the one exception; see Open questions.
Cost and concurrency. Building and diffing an overlay is heavier than today's
direct write for a single config key. That is fine, because filesync is
incremental, and we can keep a fast path for plain config edits if needed. Because
the overlay is a snapshot, a concurrent edit to the same file before export can
be lost. Other files are safe. This is the same risk the changeset commands
already accept.
Open questions
- Lockfile auto-pinning. Resolving a floating ref writes a pin as a side
effect, flushed and merged into dagger.lock at session end — outside the overlay
model. This is the only lockfile behavior that doesn't fit; the explicit ops
(withModule,withUpdatedLock) are ordinary overlays. Fold auto-pinning into
export, or keep it as the one exception to "nothing writes until export"?
Implementation
- Add the rootless local source; detection returns it (not an error) when there's
no.gitand no dagger.json. - Let the overlay materialize a local checkout's directory; drop the
synthetic-only restriction. - Make the overlay flat: one accumulated root, cumulative
changes, no nesting. - Add
changesandexport, with source-derived errors onexport. - Convert the eager mutations to overlays through the comment-preserving writer;
delete the local-only and synthetic-only guards. - Convert the changeset mutations to overlay builders (keep
migrate's wrapper);
re-hostmoduleInit/clientInitaswithInitModule/withInitClient.
DropclientGenerate; regeneration runs through the SDK's generators via
dagger generate. - Rename builders to
with…/without…; split the SDK install intowithSDK/
withoutSDK. - Add
modules/moduleand the read-onlyWorkspaceSDK(sdks/sdk). - Point the CLI's apply step at
export. - Version-gate the new fields and update the base-schema allowlist.
Tests
The behaviors the implementation must satisfy, grouped by area. These are
acceptance criteria, not an exhaustive unit list.
Overlay and export
- A builder returns a workspace but writes nothing to the host until
export. exportwrites every staged edit at once; a chain (e.g.withModulethen
withConfigValue) persists in a singleexport.- What
changesreports matches whatexportwrites (preview equals apply). - Overlays work on every workspace kind: local checkout, remote Git ref, and
synthetic. exportleaves untouched files alone; it writes only the staged edits.
Export failure by source
exportsucceeds on a local checkout with a Git root.exportfails with a distinct, actionable message for each of: no Git root,
remote Git ref, and synthetic workspace.- In a rootless or remote workspace you can still build an overlay and preview
changes; onlyexportfails.
Rootless workspace
- Outside a Git repo,
currentWorkspace()returns a workspace instead of erroring. - Its file reads and listings return empty; config reads return defaults and
overrides. dagger coreand-mrun with no Git repo.
Config, modules, SDKs
- Config edits preserve hand-written comments in dagger.toml after
export. withConfigValuesets a nested dotted key;withConfigEnv/withoutConfigEnv
add and remove a named environment.withModuleinstalls andwithoutModuleremoves a module entry;export
persists both.withSDKmarks the entry as an SDK;sdks/sdklist it andwithoutSDK
removes it.withInitModulescaffolds a module with an installed SDK, passesargs
through, and errors when the named SDK isn't installed.- The first config edit creates dagger.toml on demand (there is no
initfield).
Lockfile
- A module install carries dagger.toml and the dagger.lock pin in one
export. withUpdatedLockre-resolves pins and produces a lockfile-only overlay.
Migration and gating
migratestill returns aWorkspaceMigration.- An older API view doesn't see the new fields.
dagger installanddagger sdk installwork end to end through the new
exportapply path, with no change to the CLI experience.
Activity
[-]Design: Unified Workspace Writes via Overlay + Export[/-][+]Workspace overlay and export[/+]