daggercmd

package
v1.0.0-beta.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 18, 2026 License: Apache-2.0 Imports: 126 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GPUSupportEnv = "_EXPERIMENTAL_DAGGER_GPU_SUPPORT"

	RunnerHostEnv = "_EXPERIMENTAL_DAGGER_RUNNER_HOST"

	RunnerImageLoaderEnv = "_EXPERIMENTAL_DAGGER_RUNNER_IMAGESTORE"
	TraceNameEnv         = "DAGGER_TRACE_NAME"
)
View Source
const (
	Directory     string = "Directory"
	Changeset     string = "Changeset"
	Container     string = "Container"
	File          string = "File"
	Secret        string = "Secret"
	Service       string = "Service"
	PortForward   string = "PortForward"
	CacheVolume   string = "CacheVolume"
	Volume        string = "Volume"
	LLM           string = "LLM"
	ModuleSource  string = "ModuleSource"
	Module        string = "Module"
	Platform      string = "Platform"
	BuildArg      string = "BuildArg"
	Socket        string = "Socket"
	GitRepository string = "GitRepository"
	GitRef        string = "GitRef"
	Workspace     string = "Workspace"
)
View Source
const InstrumentationLibrary = "dagger.io/cli"

Variables

View Source
var (
	// RunnerHost holds the host to connect to.
	//
	// Note: this is filled at link-time.
	RunnerHost string

	// RunnerImageLoader holds the image store for the client.
	RunnerImageLoader string
)
View Source
var (
	Frontend idtui.Frontend
)

Functions

func EngineSession

func EngineSession(cmd *cobra.Command, args []string) error

func FindStateKeys

func FindStateKeys(s string) iter.Seq[string]

FindStateKeys returns an iterator over all state keys in the input string.

func FindStateTokens

func FindStateTokens(s string) []string

FindStateTokens returns all state tokens in the input string, if any.

func FlagAvailableForCommand

func FlagAvailableForCommand(cmd *cobra.Command, flag *pflag.Flag) bool

FlagAvailableForCommand reports whether a flag's required capabilities are available on cmd. It is exported for CLI reference generation.

func GetStateKey

func GetStateKey(in string) string

GetStateKey returns the state key from a token.

If input is not exactly a token, returns an empty string.

func GetSupportedFunction

func GetSupportedFunction(md *moduleDef, fp functionProvider, name string) (*modFunction, error)

func GetSupportedFunctions

func GetSupportedFunctions(fp functionProvider) ([]*modFunction, []string, error)

func HandlerCtx

func HandlerCtx(ctx context.Context) (ret *interp.HandlerContext)

HandlerCtx returns interp.HandlerContext value stored in ctx, or nil if it doesn't have one.

func HasState

func HasState(s string) bool

HasState returns true if the input string contains a state token.

func IsExperimental

func IsExperimental(cmd *cobra.Command) bool

IsExperimental reports whether cmd (or any ancestor) is marked experimental.

func ListSessions

func ListSessions() ([]sessionMetadata, error)

ListSessions returns saved sessions sorted by creation time (newest first, via UUIDv7 ordering). The returned metadata's LLMID field carries the file UUID (for loading), not the full LLM ID.

func Listen

func Listen(ctx context.Context, engineClient *client.Client, _ *dagger.Module, cmd *cobra.Command, _ []string) error

func Main

func Main()

func NoArgs

func NoArgs(args []string) error

func NormalizeWorkdir

func NormalizeWorkdir(workdir string) (string, error)

func Query

func Query(ctx context.Context, engineClient *client.Client, _ *dagger.Module, cmd *cobra.Command, args []string) (rerr error)

func Resource

func Resource(ctx context.Context) *resource.Resource

func RootCommand

func RootCommand() *cobra.Command

RootCommand returns the fully-assembled CLI command tree, ready for documentation generation. It installs global flags so the reference includes them, matching what Main does before Execute.

func Run

func Run(cmd *cobra.Command, args []string) error

func Sorted2

func Sorted2[K cmp.Ordered, V any](x iter.Seq2[K, V]) iter.Seq2[K, V]

Sorted2 returns a new Seq2 iterator ordered by the first element.

func Tracer

func Tracer() trace.Tracer

func WorkspaceActivity

func WorkspaceActivity(cmd *cobra.Command, _ []string) error

func WorkspaceRemote

func WorkspaceRemote(cmd *cobra.Command, _ []string) error

func WorkspaceRemotes

func WorkspaceRemotes(cmd *cobra.Command, _ []string) error

Types

type CheckGroupInfo

type CheckGroupInfo struct {
	Checks []*CheckInfo
}

type CheckInfo

type CheckInfo struct {
	Name        string
	Description string
	Type        string
}

type CloudCLI

type CloudCLI struct{}

func (*CloudCLI) BillingManage

func (cli *CloudCLI) BillingManage(cmd *cobra.Command, args []string) error

func (*CloudCLI) BillingPlans

func (cli *CloudCLI) BillingPlans(cmd *cobra.Command, args []string) error

func (*CloudCLI) CloudLogs

func (cli *CloudCLI) CloudLogs(cmd *cobra.Command, args []string) error

func (*CloudCLI) IntegrationList

func (cli *CloudCLI) IntegrationList(cmd *cobra.Command, args []string) error

IntegrationList lists configured integrations. With no arg, all are listed; with one arg, results are filtered by provider type (e.g., "github").

func (*CloudCLI) IntegrationSetup

func (cli *CloudCLI) IntegrationSetup(cmd *cobra.Command, args []string) error

func (*CloudCLI) Login

func (cli *CloudCLI) Login(cmd *cobra.Command, args []string) error

func (*CloudCLI) Logout

func (cli *CloudCLI) Logout(cmd *cobra.Command, args []string) error

func (*CloudCLI) OrgInfo

func (cli *CloudCLI) OrgInfo(cmd *cobra.Command, args []string) error

func (*CloudCLI) OrgList

func (cli *CloudCLI) OrgList(cmd *cobra.Command, args []string) error

func (*CloudCLI) OrgUse

func (cli *CloudCLI) OrgUse(cmd *cobra.Command, args []string) error

func (*CloudCLI) Rerun

func (cli *CloudCLI) Rerun(cmd *cobra.Command, _ []string) error

func (*CloudCLI) Signup

func (cli *CloudCLI) Signup(cmd *cobra.Command, args []string) error

func (*CloudCLI) Usage

func (cli *CloudCLI) Usage(cmd *cobra.Command, args []string) error

type CompletionContext

type CompletionContext struct {
	Completer *shellAutoComplete

	// ModType indicates the completions should be performed on an
	// object/interface/etc.
	ModType functionProvider
	// ModFunc indicates the completions should be performed on the arguments
	// for a function call.
	ModFunction *modFunction
	// contains filtered or unexported fields
}

CompletionContext provides completions for a specific point in a command chain. Each point is represented by one of `Mod` prefixed fields being set at a time.

type DaggerValue

type DaggerValue interface {
	pflag.Value

	// Get returns the final value for the query builder.
	Get(context.Context, *dagger.Client, *dagger.ModuleSource, *modFunctionArg) (any, error)
}

DaggerValue is a pflag.Value that requires a dagger.Client for producing the final value.

func GetCustomFlagValue

func GetCustomFlagValue(name string) DaggerValue

GetCustomFlagValue returns a pflag.Value instance for a dagger.ObjectTypeDef name.

func GetCustomFlagValueSlice

func GetCustomFlagValueSlice(name string, defVal []string) (DaggerValue, error)

GetCustomFlagValueSlice returns a pflag.Value instance for a dagger.ObjectTypeDef name.

type FlagGroup

type FlagGroup struct {
	Title string
	Flags *pflag.FlagSet
}

type FuncCommand

type FuncCommand struct {
	// The name of the command (or verb), as shown in usage.
	Name string

	// Aliases is an array of aliases that can be used instead of the first word in Use.
	Aliases []string

	// Short is the short description shown in the 'help' output.
	Short string

	// Hidden hides the command from help output.
	Hidden bool

	// Deprecated marks the command as deprecated.
	Deprecated string

	// Long is the long message shown in the 'help <this-command>' output.
	Long string

	// Example is examples of how to use the command.
	Example string

	// Annotations are key/value pairs that can be used to identify or
	// group commands or set special options.
	Annotations map[string]string

	// DisableModuleLoad skips adding a flag for loading a user Dagger Module.
	DisableModuleLoad bool
	// contains filtered or unexported fields
}

FuncCommand is a config object used to create a dynamic set of commands for querying a module's functions.

func (*FuncCommand) Command

func (fc *FuncCommand) Command() *cobra.Command

func (*FuncCommand) Help

func (fc *FuncCommand) Help(cmd *cobra.Command) error

func (*FuncCommand) RunE

func (fc *FuncCommand) RunE(ctx context.Context, fn *modFunction) func(*cobra.Command, []string) error

RunE is the final command in the function chain, where the API request is made.

type FunctionCall

type FunctionCall struct {
	Object         string         `json:"object"`
	Name           string         `json:"name"`
	Arguments      map[string]any `json:"arguments"`
	ReturnObject   string         `json:"returnObject"`
	InlineFragment string         `json:"inlineFragment,omitempty"`
}

FunctionCall represents a querybyilder.Selection

The query builder only cares about the name of the function and its arguments, but we also keep track of its object's name and return type to make it easy to get the right definition from the introspection data.

func (FunctionCall) GetDef

func (f FunctionCall) GetDef(modDef *moduleDef) (*modFunction, error)

GetDef returns the introspection definition for this function call

func (FunctionCall) GetNextDef

func (f FunctionCall) GetNextDef(modDef *moduleDef, name string) (*modFunction, error)

GetNextDef returns the introspection definition for the next function call, based on the current return type and name of the next function

type GeneratorGroupInfo

type GeneratorGroupInfo struct {
	Generators []*GeneratorInfo
}

type GeneratorInfo

type GeneratorInfo struct {
	Name        string
	Description string
}

type HandlerError

type HandlerError struct {
	// Err is the original error
	Err error
	// ExitCode is the exit status code
	ExitCode int
}

HandlerError attatches an exit code to an error returned by the handler.

Could be replaced with `errors.Join(err, interp.ExitStatus(exit))` but it always adds a "exit status X" message to the error, so this allows printing only the original but still have `errors.As()` work with `interp.ExitStatus`, which is necessary for the interpreter.

We want fatal errors but adding `interp.ExitStatus` makes it non-fatal so we always add it to get a consistent behavior and rely on `set -eo pipefail` to make it fatal.

The discrepancy is due to the interpreter library considering errors without `interp.ExitStatus" to be unexpected and thus fatal by default (opt-out, not opt-in), to avoid going unnoticed.

func NewHandlerError

func NewHandlerError(err error) *HandlerError

func (*HandlerError) Error

func (e *HandlerError) Error() string

func (*HandlerError) Unwrap

func (e *HandlerError) Unwrap() []error

type LLMSession

type LLMSession struct {
	// contains filtered or unexported fields
}

LLMSession owns an interactive session's conversations (hack/designs/async-agents.md §5.1). It holds the session-wide plumbing -- the dagger client, the shell handler, the frontend, the plumbing span -- plus the conversations themselves and which one the prompt addresses.

Routing resolves in exactly one place: Target. Nothing else may infer a destination from what happens to be running, because with a roster the busy agent and the focused agent are routinely different agents.

func NewLLMSession

func NewLLMSession(
	ctx context.Context,
	dag *dagger.Client,
	llmModel string,
	shellHandler *shellCallHandler,
	frontend idtui.Frontend,
	initialLLM *dagger.LLM,
) (*LLMSession, error)

func (*LLMSession) AgentStepped

func (s *LLMSession) AgentStepped(agentHandle string)

AgentStepped notifies the session that the trace reported a step boundary (a conversation commit) for the runtime with the given runtime handle. When that runtime backs the TARGET conversation, the conversation-scoped surfaces -- status line, changes preview -- are refreshed from its latest snapshot, so they track the agent step by step instead of turn by turn.

Cheap by design: it is invoked from the frontend's telemetry ingestion, so everything that talks to the engine happens on the refresh goroutine (scheduleUIRefresh), never here.

func (*LLMSession) Attach

func (s *LLMSession) Attach(ctx context.Context, agentHandle, name, encodedID string) (*sessionAgent, error)

Attach adopts an agent this session did not spawn as a conversation of its own, rooted on the runtime's last committed snapshot -- the honest chain, pinned by ID. The runtime is not owned: this session may prompt and interrupt it, but clearing the conversation must never stop somebody else's worker.

Re-attaching to the same agent returns the existing conversation rather than forking a second view of one runtime.

func (*LLMSession) AttachRestored

func (s *LLMSession) AttachRestored(ctx context.Context, agentHandle, name, encodedID string) (*sessionAgent, error)

AttachRestored adopts an agent this session RE-HYDRATED from a trace (hack/designs/resume-from-trace.md §5.3). Same adoption, opposite ownership: a restored agent has no other driver -- the session that published it is gone -- so this session is the one whose business it is to stop it, and .clear stopping the runtime is right.

func (*LLMSession) ContextVizURL

func (s *LLMSession) ContextVizURL() (string, error)

ContextVizURL starts the visualizer's local web server on first use and returns its URL. The server lives for the rest of the session, bound to localhost on a random port, and always renders the conversation the session currently focuses.

func (*LLMSession) Focus

func (s *LLMSession) Focus(ctx context.Context, agentHandle, name, encodedID string) error

Focus points the prompt at the agent with the given runtime handle, attaching to it first when the session is not already driving it. encodedID is a handle the client rebuilt from the trace (design §9: telemetry is the directory); it is only consulted when attaching.

A failed attach leaves focus where it was: an agent the client cannot address is one it can watch, not one it can talk to.

func (*LLMSession) InterruptTarget

func (s *LLMSession) InterruptTarget() bool

InterruptTarget preempts the target conversation, reporting whether there was anything to preempt. This is Ctrl-C with a roster: it acts on the focused agent's runtime, not on whichever turn holds the client.

func (*LLMSession) SetTarget

func (s *LLMSession) SetTarget(a *sessionAgent)

SetTarget points the prompt at a conversation the session already holds. Focus moves only by keypress, so nothing calls this from an event path.

func (*LLMSession) ShowContextViz

func (s *LLMSession) ShowContextViz()

ShowContextViz makes the visualizer reachable: it starts the server if needed, surfaces the URL in the sidebar (the browser may be unreachable, e.g. over SSH), and tries to open the user's browser.

func (*LLMSession) SubmitToTarget

func (s *LLMSession) SubmitToTarget(msg string) bool

SubmitToTarget offers a message to the target conversation's in-flight turn, reporting whether there was one to absorb it. Nothing else routes messages: a message submitted while some OTHER agent is mid-turn must not be delivered to that agent just because it happens to be the busy one.

func (*LLMSession) Target

func (s *LLMSession) Target() *sessionAgent

Target is the conversation the prompt addresses -- the single place message routing resolves. It is never nil: the session's own conversation exists from construction.

func (*LLMSession) TargetAgentID

func (s *LLMSession) TargetAgentID() string

TargetAgentID is the runtime handle of the runtime the prompt currently addresses, or "" when the target has not spawned (or attached to) one yet. The roster marks its entry with it.

type PositionalArgs

type PositionalArgs func(args []string) error

func ExactArgs

func ExactArgs(n int) PositionalArgs

func MaximumArgs

func MaximumArgs(n int) PositionalArgs

func MinimumArgs

func MinimumArgs(n int) PositionalArgs

type RecommendFn

type RecommendFn func(context.Context, *dagger.Workspace) ([]string, error)

RecommendFn returns the workspace-root-relative paths that recommend a module. An empty result means no recommendation. A nil function is never called.

func SimpleRecommend

func SimpleRecommend(patterns ...string) RecommendFn

SimpleRecommend recommends a module when any file path pattern matches.

type Result

type Result struct {
	Value any
	// contains filtered or unexported fields
}

Result is a resolved state

func (*Result) IsObject

func (r *Result) IsObject() bool

func (*Result) IsVoid

func (r *Result) IsVoid() bool

func (*Result) String

func (r *Result) String() (string, error)

type ShellCommand

type ShellCommand struct {
	// Use is the one-line usage message
	Use string

	// Description is the short description shown in the '.help' output
	Description string

	// Expected arguments
	Args PositionalArgs

	// Expected state
	State StateArg

	// Run is the function that will be executed.
	Run func(ctx context.Context, cmd *ShellCommand, args []string, st *ShellState) error

	// Complete provides builtin completions
	Complete func(ctx *CompletionContext, args []string) *CompletionContext

	// HelpFunc is a custom function for customizing the help output
	HelpFunc func(cmd *ShellCommand) string

	// The group id under which this command is grouped in the '.help' output
	GroupID string

	// Hidden hides the command from `.help`
	Hidden bool

	// NoResolveStateArgs indicates that the command should not resolve state
	// values in arguments, before passing them to Run.
	NoResolveStateArgs bool
}

ShellCommand is a Dagger Shell builtin or stdlib command

func (*ShellCommand) Execute

func (c *ShellCommand) Execute(ctx context.Context, h *shellCallHandler, args []string, st *ShellState) error

Execute is the main dispatcher function for shell builtin commands

func (*ShellCommand) Help

func (c *ShellCommand) Help() string

func (*ShellCommand) Name

func (c *ShellCommand) Name() string

Name is the command name.

func (*ShellCommand) Short

func (c *ShellCommand) Short() string

Short is the summary for the command

type ShellDoc

type ShellDoc struct {
	Groups []ShellDocSection
}

func (*ShellDoc) Add

func (d *ShellDoc) Add(title, body string)

func (*ShellDoc) AddSection

func (d *ShellDoc) AddSection(title, body string)

func (ShellDoc) String

func (d ShellDoc) String() string

type ShellDocSection

type ShellDocSection struct {
	Title  string
	Body   string
	Indent uint
}

type ShellState

type ShellState struct {
	// Key is the state store key
	Key string `json:"key"`

	// ModDigest is the module source digest for the current state
	//
	// If empty, it must fall back to the default context.
	// It matches a key in the modDefs map in the handler.
	ModDigest string `json:"digest"`

	// Cmd is non-empty if next command comes from a builtin instead of an API object
	Cmd string `json:"cmd"`

	// Calls is the list of functions for building an API query
	Calls []FunctionCall `json:"calls,omitempty"`

	// Error is non-nil if the previous command failed
	Error error `json:"error,omitempty"`
}

ShellState is an intermediate representation of a query

The query builder serializes to a GraphQL query but not back from it so we use this data structure to keep track of the command chain in order to make it easy to create a querybuilder.Selection from it, when needed.

We could alternatively encode this in the querybuilder itself, except that this state also includes key pieces of information from introspection that make it very easy to validate and get the next function's definition.

This state is passed around from the stdout of an exec handler to then next one's stdin. Each handler in the chain should add a corresponding FunctionCall to the state and write it to stdout for the next handler to read.

func (ShellState) Function

func (st ShellState) Function() FunctionCall

Function returns the last function in the chain, if not empty

func (*ShellState) GetDef

func (st *ShellState) GetDef(modDef *moduleDef) (*modFunction, error)

GetDef returns the introspection definition for the last function call

func (*ShellState) GetTypeDef

func (st *ShellState) GetTypeDef(modDef *moduleDef) (*modTypeDef, error)

GetTypeDef returns the introspection definition for the return type of the last function call

func (ShellState) IsEmpty

func (st ShellState) IsEmpty() bool

IsEmpty returns true if there's no function calls in the chain

func (ShellState) IsError

func (st ShellState) IsError() bool

func (ShellState) IsHandlerError

func (st ShellState) IsHandlerError() bool

func (ShellState) QueryBuilder

func (st ShellState) QueryBuilder(dag *dagger.Client) *querybuilder.Selection

QueryBuilder returns a querybuilder.Selection from the shell state

func (ShellState) WithCall

func (st ShellState) WithCall(fn *modFunction, argValues map[string]any) ShellState

WithCall returns a new state with the given function call added to the chain

type ShellStateStore

type ShellStateStore struct {
	// contains filtered or unexported fields
}

ShellStateStore manages state instances in memory concurrently.

func NewStateStore

func NewStateStore(runner *interp.Runner) *ShellStateStore

func (*ShellStateStore) Delete

func (s *ShellStateStore) Delete(ctx context.Context, key string)

Delete removes a state instance by key.

The state won't be deleted if in use by a variable.

func (*ShellStateStore) Extract

func (s *ShellStateStore) Extract(ctx context.Context, key string) (*ShellState, error)

Extract is like [Load] but also deletes the state from memory.

This is expected to be used when the state is being resolved rather than just passed around.

func (*ShellStateStore) Get

func (s *ShellStateStore) Get(key string) (ShellState, bool)

Get returns a state instance by key.

func (*ShellStateStore) Load

func (s *ShellStateStore) Load(key string) (*ShellState, error)

Load is like [Get] but returns an error if the key is not found or if the state represents an error.

func (*ShellStateStore) Prune

func (s *ShellStateStore) Prune(ctx context.Context) int

Prune removes all state instances that are not in use by a variable.

func (*ShellStateStore) Store

func (s *ShellStateStore) Store(st ShellState) string

Store saves a state instance and returns its key.

This always generates a new key for immutability.

type StateArg

type StateArg uint
const (
	AnyState StateArg = iota
	RequiredState
	NoState
)

type UnsupportedFlagError

type UnsupportedFlagError struct {
	Name string
	Type string
}

func (*UnsupportedFlagError) Error

func (e *UnsupportedFlagError) Error() string

type UpGroupInfo

type UpGroupInfo struct {
	Ups []*UpInfo
}

type UpInfo

type UpInfo struct {
	Name        string
	Description string
}

Directories

Path Synopsis
Command docsgen renders the Dagger CLI reference Markdown from the assembled Cobra command tree.
Command docsgen renders the Dagger CLI reference Markdown from the assembled Cobra command tree.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL