Dagger.Workspace (dagger v1.0.0-beta.19)

Copy Markdown View Source

A Dagger workspace detected from the current working directory or constructed from a Directory.

Summary

Functions

Canonical Dagger address of the workspace location, or an opaque identity for synthetic workspaces.

Discover static object artifacts from workspace modules without evaluating their values.

Return this workspace's changes, with paths relative to its working directory.

Preview which source commits withCommitsFrom would apply, skip, or report as conflicting.

Selected native workspace config file relative to the workspace cwd, if any.

Read a configuration value from dagger.toml.

Current location within the workspace root.

Return the selected SDK module's current scope at this workspace location.

Returns a Directory from the workspace.

Installed name of the module selected as the workspace entrypoint, or an empty string when none is selected.

List named environments defined in the workspace configuration.

Write this workspace's commits and pending changes to a checkout on the calling client.

Returns a File from the workspace.

Find project roots marked by any of the given filenames, starting from a path relative to the workspace cwd.

Search for a file or directory by walking up from the start path within the workspace.

Git state for this workspace. Errors if the workspace is not in a git repository.

Returns a list of files and directories that match the given pattern.

A unique identifier for this Workspace.

Plan the explicit migration needed for the current workspace.

Plan migration of one local module without migrating its dependencies or creating a workspace configuration.

Return a module defined in the workspace configuration.

Load a module source from a path within the workspace.

List modules defined in the workspace configuration.

Resolve an address in this workspace.

An installed SDK, by name.

Installed SDKs.

Searches for content matching the given regular expression or literal string.

Return a snapshot of this workspace as a stable value.

Return this workspace with a changeset applied, without mutating the source.

Return this workspace with a generated module client added to one SDK scope.

Create a Git commit from a changeset and return a stable workspace with HEAD advanced.

Integrate source commits into this workspace and return the result, preserving this workspace's uncommitted changes and metadata.

Return this workspace with a named config environment created.

Select the config environment carried by this workspace.

Select workspace-root-relative config and lockfile paths. Empty paths clear the selection.

Return this workspace with a configuration value written.

Return this workspace with a directory merged into the given path, without mutating the source.

Return this workspace with an installed module selected as its entrypoint.

Return this workspace with a file added or replaced, without mutating the source.

Return this workspace with a location initialized as a module scope.

Return this workspace with a native configuration, without changing an existing configuration.

Return this workspace with a module installed in its config.

Return this workspace with a directory mounted read-only at the given path, without mutating the source.

Return this workspace with a file mounted read-only at the given path, without mutating the source.

Return this workspace with the given path replaced by a directory, without mutating the source.

Return this workspace with a new or replaced file, without mutating the source.

Return this workspace with the given Git-compatible patch file applied, without mutating the source.

Move this workspace's Git HEAD to a commit and return the resulting stable workspace.

Return this workspace with an SDK installed in its config.

Return this workspace with the selected module clients updated.

Return this workspace with refreshed lockfile state.

Return this workspace with updated module sources, versions and lockfile state.

Return this workspace with the calling client's user-level config re-read and applied.

Return this workspace with its working directory pointed at the given workspace-relative path.

Return this workspace with a module client removed from the deepest matching recorded scope.

Return this workspace with a named config environment removed.

Return this workspace with a configuration value removed.

Return this workspace with a directory removed, without mutating the source.

Return this workspace with no module selected as its entrypoint.

Return this workspace with a file removed, without mutating the source.

Return this workspace with files removed, without mutating the source.

Return this workspace with a module removed from its config.

Return this workspace with the content mounted at the given path unmounted.

Return this workspace with an SDK removed from its config.

Types

t()

@type t() :: %Dagger.Workspace{client: term(), query_builder: term()}

Functions

address(workspace)

@spec address(t()) :: {:ok, String.t()} | {:error, term()}

Canonical Dagger address of the workspace location, or an opaque identity for synthetic workspaces.

artifacts(workspace, optional_args \\ [])

@spec artifacts(t(), [{:include, [String.t()]}]) :: Dagger.Artifacts.t()

Discover static object artifacts from workspace modules without evaluating their values.

changes(workspace, optional_args \\ [])

@spec changes(t(), [{:from, t() | nil}]) :: Dagger.Changeset.t()

Return this workspace's changes, with paths relative to its working directory.

Pass from to compare against an earlier workspace state. Omitting it preserves the cumulative behavior used by clients from before this argument was added.

compare_commits_from(workspace, source, optional_args \\ [])

@spec compare_commits_from(t(), t(),
  commits: [String.t()],
  max_commits: integer() | nil
) ::
  {:ok, [Dagger.WorkspaceCommitPick.t()]} | {:error, term()}

Preview which source commits withCommitsFrom would apply, skip, or report as conflicting.

Results are ordered oldest first and account for earlier applicable commits in the same preview. The preview does not apply commits or write to the checkout.

A local receiver is snapshotted automatically; untracked files require interactive approval. Source uncommitted changes are ignored. Exceeding maxCommits fails rather than returning a partial preview. Divergent merge commits require manual integration.

config_file(workspace)

@spec config_file(t()) :: {:ok, String.t()} | {:error, term()}

Selected native workspace config file relative to the workspace cwd, if any.

config_read(workspace, optional_args \\ [])

@spec config_read(t(), key: String.t() | nil, effective: boolean() | nil) ::
  {:ok, String.t()} | {:error, term()}

Read a configuration value from dagger.toml.

If key is empty, returns the full config.

If key points to a scalar, returns the value.

If key points to a table, returns flattened dotted-key output.

cwd(workspace)

@spec cwd(t()) :: {:ok, String.t()} | {:error, term()}

Current location within the workspace root.

The workspace root is returned as "/".

Relative paths in workspace APIs resolve from here.

detect_scope(workspace, sdk)

@spec detect_scope(t(), String.t()) :: {:ok, String.t()} | {:error, term()}

Return the selected SDK module's current scope at this workspace location.

directory(workspace, path, optional_args \\ [])

@spec directory(t(), String.t(),
  exclude: [String.t()],
  include: [String.t()],
  gitignore: boolean() | nil
) :: Dagger.Directory.t()

Returns a Directory from the workspace.

Relative paths resolve from the workspace cwd. Absolute paths resolve from the workspace root.

entrypoint(workspace)

@spec entrypoint(t()) :: {:ok, String.t()} | {:error, term()}

Installed name of the module selected as the workspace entrypoint, or an empty string when none is selected.

Reflects the selected env's effective view. Fails if several modules are selected.

env_list(workspace)

@spec env_list(t()) :: {:ok, [String.t()]} | {:error, term()}

List named environments defined in the workspace configuration.

export(workspace, optional_args \\ [])

@spec export(t(), path: String.t() | nil, from: t() | nil) :: :ok | {:error, term()}

Write this workspace's commits and pending changes to a checkout on the calling client.

Path selects the destination; omitting it uses the calling client's current local workspace root, including when exporting a snapshot or committed workspace. Exported file paths are relative to the workspace root regardless of its working directory. This writes only to the client making the call, never the source's client.

A live workspace exported to its own checkout applies only its overlay edits, without capturing the whole checkout. This also applies with an explicit path. Pass from with the same live base to apply only changes since that overlay state.

Other exports integrate divergent commits by cherry-picking, preserve unrelated checkout edits, and refuse conflicts. Live inputs are snapshotted automatically; capturing untracked source files requires interactive approval. Stable inputs retain their baseline. Pass from to save only work since an earlier source value, including previously saved pending edits that are now committed.

file(workspace, path)

@spec file(t(), String.t()) :: Dagger.File.t()

Returns a File from the workspace.

Relative paths resolve from the workspace cwd. Absolute paths resolve from the workspace root.

find_roots(workspace, markers, optional_args \\ [])

@spec find_roots(t(), [String.t()], start: String.t() | nil, exclude: [String.t()]) ::
  {:ok, [String.t()]} | {:error, term()}

Find project roots marked by any of the given filenames, starting from a path relative to the workspace cwd.

Returns cwd-relative directory paths for every marked directory at or below start, plus the nearest marked ancestor when start itself is not marked.

Each returned path is usable as-is with other workspace APIs, e.g. directory(path).

find_up(workspace, name, optional_args \\ [])

@spec find_up(t(), String.t(), [{:from, String.t() | nil}]) ::
  {:ok, String.t() | nil} | {:error, term()}

Search for a file or directory by walking up from the start path within the workspace.

Returns the absolute workspace path if found, or null if not found.

Relative start paths resolve from the workspace cwd.

The search stops at the workspace root and will not traverse above it.

git(workspace)

@spec git(t()) :: Dagger.WorkspaceGit.t()

Git state for this workspace. Errors if the workspace is not in a git repository.

glob(workspace, pattern)

@spec glob(t(), String.t()) :: {:ok, [String.t()]} | {:error, term()}

Returns a list of files and directories that match the given pattern.

Patterns match paths relative to the workspace root.

id(workspace)

@spec id(t()) :: {:ok, String.t()} | {:error, term()}

A unique identifier for this Workspace.

migrate(workspace, optional_args \\ [])

@spec migrate(t(), [{:modules, [String.t()]}]) :: Dagger.WorkspaceMigration.t()

Plan the explicit migration needed for the current workspace.

Include installed local modules and their local dependencies. Other module candidates remain unchanged unless selected.

The returned plan has an empty changeset and no steps when no migration is needed.

migrate_module(workspace, optional_args \\ [])

@spec migrate_module(t(), [{:path, String.t() | nil}]) ::
  Dagger.WorkspaceMigration.t()

Plan migration of one local module without migrating its dependencies or creating a workspace configuration.

Include SDK registration when a workspace configuration exists and remove obsolete generated-file ignore rules.

module(workspace, name)

@spec module(t(), String.t()) :: Dagger.WorkspaceModule.t()

Return a module defined in the workspace configuration.

Reflects the selected env's effective view.

module_source(workspace, path)

@spec module_source(t(), String.t()) :: Dagger.ModuleSource.t()

Load a module source from a path within the workspace.

Relative paths (e.g., "foo") resolve from the workspace cwd; absolute paths (e.g., "/foo") resolve from the workspace root.

Fails if the path does not point to an initialized module.

modules(workspace)

@spec modules(t()) :: {:ok, [Dagger.WorkspaceModule.t()]} | {:error, term()}

List modules defined in the workspace configuration.

Reflects the selected env's effective view.

resolve(workspace, value)

@spec resolve(t(), String.t()) :: Dagger.Address.t()

Resolve an address in this workspace.

A DAG address (dag://<path>) selects exactly one workspace artifact: artifacts.filterUri(value).one(). Its typed loaders use that artifact and never fall back to external resolution.

A value without the dag:// scheme keeps its external meaning, such as a container image reference.

The Address retains this workspace across module calls and ID reloads.

sdk(workspace, name)

@spec sdk(t(), String.t()) :: Dagger.WorkspaceSDK.t()

An installed SDK, by name.

sdks(workspace)

@spec sdks(t()) :: {:ok, [Dagger.WorkspaceSDK.t()]} | {:error, term()}

Installed SDKs.

search(workspace, pattern, optional_args \\ [])

@spec search(t(), String.t(),
  paths: [String.t()],
  globs: [String.t()],
  literal: boolean() | nil,
  multiline: boolean() | nil,
  dotall: boolean() | nil,
  insensitive: boolean() | nil,
  skip_ignored: boolean() | nil,
  skip_hidden: boolean() | nil,
  files_only: boolean() | nil,
  limit: integer() | nil
) :: {:ok, [Dagger.SearchResult.t()]} | {:error, term()}

Searches for content matching the given regular expression or literal string.

Uses Rust regex syntax; escape literal ., [, ], {, }, | with backslashes.

Runs ripgrep on the client host, falling back to grep if unavailable.

snapshot(workspace)

@spec snapshot(t()) :: t()

Return a snapshot of this workspace as a stable value.

Git capture is a progressive enhancement: if the workspace has no Git repository or commits, or the client cannot capture Git, return this workspace unchanged. Approval rejections and capture failures remain errors.

Use the returned workspace for subsequent reads, edits, and module loading against the captured baseline. Snapshotting an existing stable value preserves its baseline; snapshot currentWorkspace again to capture later checkout changes.

Only the owning client can capture a local checkout. Tracked changes are captured automatically; untracked files require interactive approval. Remote Git refs are pinned to their resolved commits. Capturing leaves the checkout unchanged.

The recipe is portable when a remote can serve its base; otherwise it is frozen for this session only.

Experimental

"Best-effort capture for resumable sessions; capture and fallback behavior may change."

with_changes(workspace, changes)

@spec with_changes(t(), Dagger.Changeset.t()) :: t()

Return this workspace with a changeset applied, without mutating the source.

with_client(workspace, module, optional_args \\ [])

@spec with_client(t(), String.t(),
  sdk: String.t() | nil,
  settings: Dagger.JSON.t() | nil
) :: t()

Return this workspace with a generated module client added to one SDK scope.

Select the deepest detected or registered scope. Fail if several SDKs have that deepest scope.

with_commit(workspace, changes, message, date, optional_args \\ [])

@spec with_commit(t(), Dagger.Changeset.t(), String.t(), String.t(),
  author_name: String.t() | nil,
  author_email: String.t() | nil,
  signoff: boolean() | nil
) :: t()

Create a Git commit from a changeset and return a stable workspace with HEAD advanced.

The changeset is three-way merged into both HEAD and the frozen working tree. Compatible unselected edits remain uncommitted; incoming changes need not already be in the working tree. Conflicts with either tree fail without modifying the workspace. Empty changesets, or changes already present in HEAD, fail with nothing to commit.

A local workspace is snapshotted automatically before committing; untracked files require interactive approval. The host checkout is not modified.

Missing author fields are resolved from Git config in the calling client's working directory at commit time, then recorded explicitly for reproducible commits. Unconfigured fields default to Dagger and dagger@localhost.

with_commits_from(workspace, source, optional_args \\ [])

@spec with_commits_from(t(), t(), commits: [String.t()], max_commits: integer() | nil) ::
  t()

Integrate source commits into this workspace and return the result, preserving this workspace's uncommitted changes and metadata.

Fast-forward when the selected commits include all new ancestors of their tip; otherwise cherry-pick them oldest first. Already integrated commits and patches already present are skipped. Any conflict fails the operation. Source uncommitted changes are not transferred; merge them explicitly if needed. Use compareCommitsFrom to preview the integration.

A local receiver is snapshotted automatically; untracked files require interactive approval. The checkout is not modified. Export the result with an explicit path to write it to a checkout.

Cherry-picks preserve the source author and author date, use the calling client's Git config for committer identity, and reuse the source committer date for reproducible hashes. Origin trailers track cherry-picked commits. Divergent merge commits require manual integration.

with_config_env(workspace, name, optional_args \\ [])

@spec with_config_env(t(), String.t(), [{:here, boolean() | nil}]) :: t()

Return this workspace with a named config environment created.

with_config_environment(workspace, name)

@spec with_config_environment(t(), String.t()) :: t()

Select the config environment carried by this workspace.

with_config_paths(workspace, config_file, lock_file)

@spec with_config_paths(t(), String.t(), String.t()) :: t()

Select workspace-root-relative config and lockfile paths. Empty paths clear the selection.

with_config_value(workspace, key, value, optional_args \\ [])

@spec with_config_value(t(), String.t(), String.t(),
  values: [String.t()],
  here: boolean() | nil
) :: t()

Return this workspace with a configuration value written.

When the session selects an env, the key is scoped to that env's overlay and the env is created if missing.

with_directory(workspace, path, source)

@spec with_directory(t(), String.t(), Dagger.Directory.t()) :: t()

Return this workspace with a directory merged into the given path, without mutating the source.

Anything already at the path stays, and files the source carries win, as with Directory.withDirectory. Use withNewDirectory to replace the path instead.

with_entrypoint(workspace, name)

@spec with_entrypoint(t(), String.t()) :: t()

Return this workspace with an installed module selected as its entrypoint.

Every other entrypoint selection is cleared. Entrypoints live in the base workspace config.

with_file(workspace, path, source, optional_args \\ [])

@spec with_file(t(), String.t(), Dagger.File.t(), [{:permissions, integer() | nil}]) ::
  t()

Return this workspace with a file added or replaced, without mutating the source.

with_init_module(workspace, sdk, optional_args \\ [])

@spec with_init_module(t(), String.t(),
  name: String.t() | nil,
  path: String.t() | nil,
  install: boolean() | nil,
  entrypoint: boolean() | nil,
  settings: Dagger.JSON.t() | nil
) :: t()

Return this workspace with a location initialized as a module scope.

The selected SDK module records the scope and generates the module source.

with_initialized(workspace)

@spec with_initialized(t()) :: t()

Return this workspace with a native configuration, without changing an existing configuration.

Fail if legacy configuration needs workspace migration.

with_module(workspace, ref, optional_args \\ [])

@spec with_module(t(), String.t(), name: String.t() | nil, here: boolean() | nil) ::
  t()

Return this workspace with a module installed in its config.

When the session selects an env, the module is recorded in that env's overlay and the env is created if missing.

with_mounted_directory(workspace, path, source)

@spec with_mounted_directory(t(), String.t(), Dagger.Directory.t()) :: t()

Return this workspace with a directory mounted read-only at the given path, without mutating the source.

Mounted content is readable through the normal workspace file tools but shadows the source at the mount path and stays out of the pending changeset: it never appears in changes, is never exported, and cannot be modified.

with_mounted_file(workspace, path, source)

@spec with_mounted_file(t(), String.t(), Dagger.File.t()) :: t()

Return this workspace with a file mounted read-only at the given path, without mutating the source.

Mounted content is readable through the normal workspace file tools but shadows the source at the mount path and stays out of the pending changeset: it never appears in changes, is never exported, and cannot be modified.

with_new_directory(workspace, path, source)

@spec with_new_directory(t(), String.t(), Dagger.Directory.t()) :: t()

Return this workspace with the given path replaced by a directory, without mutating the source.

The source becomes the entire contents of the path: anything already there that the source does not carry is removed. Use withDirectory to keep it instead.

with_new_file(workspace, path, contents, optional_args \\ [])

@spec with_new_file(t(), String.t(), String.t(), [{:permissions, integer() | nil}]) ::
  t()

Return this workspace with a new or replaced file, without mutating the source.

with_patch_file(workspace, patch, optional_args \\ [])

@spec with_patch_file(t(), Dagger.File.t(), [
  {:on_conflict, Dagger.PatchConflict.t() | nil}
]) :: t()

Return this workspace with the given Git-compatible patch file applied, without mutating the source.

Paths in the patch are relative to the workspace root, whatever its cwd, as git diff writes them. Patching a path at or under a mount is an error.

Experimental

"This API is highly experimental and may be removed or replaced entirely."

with_reset(workspace, commit, optional_args \\ [])

@spec with_reset(t(), String.t(), [{:hard, boolean() | nil}]) :: t()

Move this workspace's Git HEAD to a commit and return the resulting stable workspace.

A local workspace is snapshotted automatically before resetting; untracked files require interactive approval. The host checkout is not modified. By default the difference between the previous working tree and the target commit stays uncommitted, as with git reset --mixed, so history can be reworked and reapplied with withCommit — e.g. to amend the latest commit message, reset to its parent and commit again.

With hard, the working tree is reset to the commit and every uncommitted change is discarded.

Commits orphaned by the reset are not preserved: the frozen repository keeps reachable history only, so a reset cannot be undone by resetting forward again.

with_sdk(workspace, ref, optional_args \\ [])

@spec with_sdk(t(), String.t(),
  name: String.t() | nil,
  here: boolean() | nil,
  as_sdk_name: String.t() | nil
) :: t()

Return this workspace with an SDK installed in its config.

with_updated_clients(workspace, optional_args \\ [])

@spec with_updated_clients(t(),
  modules: [String.t()],
  all: boolean() | nil,
  sdk: String.t() | nil
) ::
  t()

Return this workspace with the selected module clients updated.

The engine re-reads the source of each selected client target and writes the lock entries that those targets reach.

The selected SDK module then regenerates every scope that owns one of the targets.

with_updated_lock(workspace, optional_args \\ [])

@spec with_updated_lock(t(), [{:no_generate, boolean() | nil}]) :: t()

Return this workspace with refreshed lockfile state.

SDK client scopes are regenerated unless noGenerate is true.

with_updated_modules(workspace, optional_args \\ [])

@spec with_updated_modules(t(),
  names: [String.t()],
  version: String.t() | nil,
  source: String.t() | nil
) :: t()

Return this workspace with updated module sources, versions and lockfile state.

An SDK client scope is regenerated when it targets an updated module.

with_user_config(workspace)

@spec with_user_config(t()) :: t()

Return this workspace with the calling client's user-level config re-read and applied.

User-level config (the [workspaces.*] section of the Dagger config file) is read when a session loads its workspace, and snapshots keep that configuration. Call this to pick up edits made since, for example when an agent reloads its modules.

The entry is matched by the workspace's git origin remote. A workspace without one, or without a matching entry, gets no user-level config.

with_workdir(workspace, path)

@spec with_workdir(t(), String.t()) :: t()

Return this workspace with its working directory pointed at the given workspace-relative path.

without_client(workspace, module, optional_args \\ [])

@spec without_client(t(), String.t(), [{:sdk, String.t() | nil}]) :: t()

Return this workspace with a module client removed from the deepest matching recorded scope.

Fail if several SDKs have that deepest scope. The selected SDK module regenerates the complete scope.

If invalid client targets remain, save the removal and skip generation until those targets are corrected or removed.

without_config_env(workspace, name, optional_args \\ [])

@spec without_config_env(t(), String.t(), [{:here, boolean() | nil}]) :: t()

Return this workspace with a named config environment removed.

without_config_value(workspace, key, optional_args \\ [])

@spec without_config_value(t(), String.t(), [{:here, boolean() | nil}]) :: t()

Return this workspace with a configuration value removed.

Errors when the key is not currently set.

When the session selects an env, the key is scoped to that env's overlay.

without_directory(workspace, path)

@spec without_directory(t(), String.t()) :: t()

Return this workspace with a directory removed, without mutating the source.

without_entrypoint(workspace)

@spec without_entrypoint(t()) :: t()

Return this workspace with no module selected as its entrypoint.

without_file(workspace, path)

@spec without_file(t(), String.t()) :: t()

Return this workspace with a file removed, without mutating the source.

without_files(workspace, paths)

@spec without_files(t(), [String.t()]) :: t()

Return this workspace with files removed, without mutating the source.

without_module(workspace, name, optional_args \\ [])

@spec without_module(t(), String.t(), [{:here, boolean() | nil}]) :: t()

Return this workspace with a module removed from its config.

When the session selects an env, only that env's overlay entry is removed.

without_mount(workspace, path)

@spec without_mount(t(), String.t()) :: t()

Return this workspace with the content mounted at the given path unmounted.

Removes directory and file mounts at or below the path, revealing the underlying workspace content. Other mounts and pending changes are preserved.

without_sdk(workspace, name, optional_args \\ [])

@spec without_sdk(t(), String.t(), [{:here, boolean() | nil}]) :: t()

Return this workspace with an SDK removed from its config.