Documentation
¶
Overview ¶
Package md manages isolated Docker development containers for AI coding agents.
It provides programmatic access to create, manage, and tear down containers that each get a full git clone of your repository with SSH access.
Index ¶
- Constants
- type Client
- type Container
- func (c *Container) Diff(ctx context.Context, stdout, stderr io.Writer, extraArgs []string) error
- func (c *Container) Fetch(ctx context.Context, provider, model string) error
- func (c *Container) GetHostPort(ctx context.Context, containerPort string) (string, error)
- func (c *Container) Kill(ctx context.Context) error
- func (c *Container) Pull(ctx context.Context, provider, model string) error
- func (c *Container) Push(ctx context.Context) error
- func (c *Container) Run(ctx context.Context, baseImage string, command []string) (_ int, retErr error)
- func (c *Container) Start(ctx context.Context, opts *StartOpts) (_ *StartResult, retErr error)
- func (c *Container) SyncDefaultBranch(ctx context.Context) error
- func (c *Container) TailscaleFQDN(ctx context.Context) string
- type StartOpts
- type StartResult
Constants ¶
const DefaultBaseImage = "ghcr.io/maruel/md"
DefaultBaseImage is the base image used when none is specified.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// W is the writer for progress and status messages.
W io.Writer
// Paths.
Home string
XDGConfigHome string
XDGDataHome string
XDGStateHome string
// SSH key paths.
HostKeyPath string // ~/.config/md/ssh_host_ed25519_key (generated)
UserKeyPath string // ~/.ssh/md
// Docker.
ImageName string
// Tokens.
GithubToken string // GitHub API token for Docker build secrets.
// TailscaleAPIKey is the Tailscale API key for auth key generation and device deletion.
//
// It is necessary to setup ephemeral nodes. The key must be rotated every 90 days.
//
// See https://tailscale.com/docs/reference/tailscale-api and
// https://tailscale.com/docs/features/ephemeral-nodes
TailscaleAPIKey string
// contains filtered or unexported fields
}
Client holds global MD tool state (paths, image config, SSH keys).
func (*Client) BuildImage ¶ added in v0.6.0
BuildImage builds the base Docker image locally.
func (*Client) Container ¶
Container returns a Container handle for the given git root and branch.
It doesn't start it, it is just a reference.
type Container ¶
type Container struct {
*Client
// GitRoot is the absolute path to the git repository root on the host.
// Label: md.git_root
GitRoot string
// RepoName is the basename of the repository directory.
// Label: md.repo_name
RepoName string
// Branch is the git branch checked out in the container.
// Label: md.branch
Branch string
// Name is the Docker container name (e.g. "md-myrepo-main").
Name string
// State is the Docker container state (e.g. "running", "exited").
State string
// CreatedAt is when the container was created.
CreatedAt time.Time
// Display indicates the container was started with X11/VNC enabled.
// Label: md.display
Display bool
// Tailscale indicates the container was started with Tailscale networking.
// Label: md.tailscale
Tailscale bool
// USB indicates the container was started with USB passthrough.
// Label: md.usb
USB bool
// DefaultRemote is the host's default git remote (resolved lazily).
DefaultRemote string
// DefaultBranch is the default branch for DefaultRemote (resolved lazily).
DefaultBranch string
}
Container holds state for a single container instance.
Fields marked with a label are persisted as Docker container labels and restored by [unmarshalContainer] when listing containers.
func (*Container) Diff ¶
Diff writes the diff between base and current in the container. When stdout is a terminal, a TTY is allocated so git's pager and colors work.
func (*Container) Fetch ¶
Fetch commits any uncommitted changes in the container and fetches them locally, updating the remote-tracking ref without integrating.
provider and model control AI commit message generation. See https://github.com/maruel/genai for valid names. If provider is empty, a default message is used.
func (*Container) GetHostPort ¶
GetHostPort returns the host port mapped to a container port (e.g. "5901/tcp"). Returns empty string if the port is not mapped.
func (*Container) Pull ¶
Pull fetches changes from the container and integrates them into the local branch.
provider and model control AI commit message generation. See https://github.com/maruel/genai for valid names. If provider is empty, a default message is used.
func (*Container) Run ¶
func (c *Container) Run(ctx context.Context, baseImage string, command []string) (_ int, retErr error)
Run starts a temporary container, runs a command, then cleans up. baseImage is the full Docker image reference; if empty, DefaultBaseImage is used.
func (*Container) SyncDefaultBranch ¶ added in v0.6.2
SyncDefaultBranch force-pushes the host's default branch (e.g. origin/main) into the container so agents can diff against it.
type StartOpts ¶
type StartOpts struct {
// BaseImage is the full Docker image reference (e.g.
// "ghcr.io/maruel/md:v1.0" or "myregistry/custom:tag"). When empty,
// DefaultBaseImage is used.
BaseImage string
// Display enables X11/VNC virtual display (port 5901).
Display bool
// Tailscale enables Tailscale networking inside the container.
//
// It is recommended to set Client.TailscaleAPIKey to enable ephemeral nodes. If Client.TailscaleAPIKey is
// not set, the node will not be ephemeral. Instead, an authentication URL will be printed back by md.
Tailscale bool
// TailscaleAuthKey is a pre-authorized Tailscale auth key.
//
// When empty and Tailscale is true, Client.TailscaleAPIKey is used to generate an authentication key.
//
// The tailnet policy must allow "tag:md".
//
// https://tailscale.com/docs/features/access-control/auth-keys
TailscaleAuthKey string
// USB enables USB device passthrough (Linux only).
USB bool
// Labels are additional Docker labels (key=value) applied to the container.
Labels []string
// Quiet suppresses informational output during startup.
Quiet bool
}
StartOpts configures container startup.
type StartResult ¶ added in v0.6.0
type StartResult struct {
// SSHPort is the host port mapped to the container's SSH port.
SSHPort string
// VNCPort is the host port mapped to the container's VNC port, if display is enabled.
VNCPort string
// TailscaleFQDN is the Tailscale FQDN assigned to the container, if any.
TailscaleFQDN string
// TailscaleAuthURL is the Tailscale auth URL when no pre-auth key was provided.
TailscaleAuthURL string
}
StartResult contains information about the started container.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
md
command
md (my devenv) manages isolated Docker development containers for AI coding agents.
|
md (my devenv) manages isolated Docker development containers for AI coding agents. |
|
Package gitutil provides git utility functions for repository introspection, branch management, and pushing.
|
Package gitutil provides git utility functions for repository introspection, branch management, and pushing. |