Skip to content

Workspace overlay and export #13566

Closed

Description

@shykes

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/-m context 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

  1. Add the rootless local source; detection returns it (not an error) when there's
    no .git and no dagger.json.
  2. Let the overlay materialize a local checkout's directory; drop the
    synthetic-only restriction.
  3. Make the overlay flat: one accumulated root, cumulative changes, no nesting.
  4. Add changes and export, with source-derived errors on export.
  5. Convert the eager mutations to overlays through the comment-preserving writer;
    delete the local-only and synthetic-only guards.
  6. Convert the changeset mutations to overlay builders (keep migrate's wrapper);
    re-host moduleInit / clientInit as withInitModule / withInitClient.
    Drop clientGenerate; regeneration runs through the SDK's generators via
    dagger generate.
  7. Rename builders to with… / without…; split the SDK install into withSDK /
    withoutSDK.
  8. Add modules / module and the read-only WorkspaceSDK (sdks / sdk).
  9. Point the CLI's apply step at export.
  10. 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.
  • export writes every staged edit at once; a chain (e.g. withModule then
    withConfigValue) persists in a single export.
  • What changes reports matches what export writes (preview equals apply).
  • Overlays work on every workspace kind: local checkout, remote Git ref, and
    synthetic.
  • export leaves untouched files alone; it writes only the staged edits.

Export failure by source

  • export succeeds on a local checkout with a Git root.
  • export fails 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; only export fails.

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 core and -m run with no Git repo.

Config, modules, SDKs

  • Config edits preserve hand-written comments in dagger.toml after export.
  • withConfigValue sets a nested dotted key; withConfigEnv / withoutConfigEnv
    add and remove a named environment.
  • withModule installs and withoutModule removes a module entry; export
    persists both.
  • withSDK marks the entry as an SDK; sdks / sdk list it and withoutSDK
    removes it.
  • withInitModule scaffolds a module with an installed SDK, passes args
    through, and errors when the named SDK isn't installed.
  • The first config edit creates dagger.toml on demand (there is no init field).

Lockfile

  • A module install carries dagger.toml and the dagger.lock pin in one export.
  • withUpdatedLock re-resolves pins and produces a lockfile-only overlay.

Migration and gating

  • migrate still returns a WorkspaceMigration.
  • An older API view doesn't see the new fields.
  • dagger install and dagger sdk install work end to end through the new
    export apply path, with no change to the CLI experience.

Activity

  1. changed the title [-]Design: Unified Workspace Writes via Overlay + Export[/-] [+]Workspace overlay and export[/+] on Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions