Documentation
¶
Overview ¶
Package config handles moat.yaml manifest parsing.
Index ¶
- Constants
- func CheckVolumeRuntimeSupport(vols []VolumeConfig, appleRuntime bool) error
- func DockerVolumeName(agentName, volumeName string) string
- func GlobalConfigDir() string
- func IsVolumeMode(mode string) bool
- func ValidateExcludes(excludes []string, target string) ([]string, error)
- func ValidateNoGitExclude(excludes []string) error
- func VolumeDir(agentName, volumeName string) string
- type ClaudeConfig
- type CodexConfig
- type Config
- type ContainerConfig
- type CopilotConfig
- type DebugConfig
- type GeminiConfig
- type GlobalConfig
- type HooksConfig
- type LLMGatewayConfig
- type MCPAuthConfig
- type MCPServerConfig
- type MCPServerSpec
- type MarketplaceSpec
- type MountEntry
- type NetworkConfig
- type PiConfig
- type ProxyConfig
- type ServiceSpec
- type SnapshotConfig
- type SnapshotExcludeConfig
- type SnapshotRetentionConfig
- type SnapshotTriggerConfig
- type TracingConfig
- type UlimitSpec
- type VolumeConfig
- type WorkspaceConfig
- type WorkspaceMode
Constants ¶
const ConfigFilename = "moat.yaml"
ConfigFilename is the preferred config file name.
const LegacyConfigFilename = "agent.yaml"
LegacyConfigFilename is the legacy config file name, supported as a fallback.
Variables ¶
This section is empty.
Functions ¶
func CheckVolumeRuntimeSupport ¶ added in v0.7.0
func CheckVolumeRuntimeSupport(vols []VolumeConfig, appleRuntime bool) error
CheckVolumeRuntimeSupport rejects `type: volume` entries when the effective container runtime is Apple's `container` CLI, which has no named-volume support.
It is called from both config load (when `runtime: apple` is explicit) and run setup (when the runtime is auto-detected) so the two validation points share one rule and error message and cannot drift.
func DockerVolumeName ¶ added in v0.3.0
DockerVolumeName returns the Docker volume name for an agent volume. Format: moat_<agentName>_<volumeName>
func GlobalConfigDir ¶
func GlobalConfigDir() string
GlobalConfigDir returns the path to the moat configuration directory.
By default this is ~/.moat, but the MOAT_HOME environment variable may override it to an absolute path. MOAT_HOME is the complete moat directory, not a parent containing .moat — set it to e.g. /tmp/moat-test, not /tmp. Primarily used for hermetic test runs and rare multi-version setups where one daemon must not see another's state.
func IsVolumeMode ¶ added in v0.7.0
IsVolumeMode reports whether a stored/serialized workspace-mode string (e.g. run.Run.WorkspaceMode or storage.Metadata.WorkspaceMode, both plain strings) is volume mode. Centralizing the comparison avoids repeating the string(WorkspaceModeVolume) cast at every call site, where a single typo would silently diverge.
func ValidateExcludes ¶ added in v0.4.0
ValidateExcludes validates exclude paths on a MountEntry. Paths are normalized with filepath.Clean before validation. Returns the cleaned exclude list or an error.
func ValidateNoGitExclude ¶ added in v0.7.0
ValidateNoGitExclude rejects excluding .git (or any subpath) in volume mode. A partial .git is a broken repository, so volume-mode copy-in must always include the full .git directory.
func VolumeDir ¶ added in v0.3.0
VolumeDir returns the host directory for an agent volume. Path: ~/.moat/volumes/<agentName>/<volumeName>/
Callers must create the directory before mounting:
volDir := config.VolumeDir(agentName, volumeName)
if err := os.MkdirAll(volDir, 0755); err != nil { ... }
See internal/run/manager.go for usage.
Types ¶
type ClaudeConfig ¶
type ClaudeConfig struct {
// BaseURL sets ANTHROPIC_BASE_URL inside the container, redirecting Claude
// Code API traffic through a host-side LLM proxy (e.g., Headroom).
// Traffic is routed through a relay endpoint on the Moat proxy, which
// forwards to the configured URL with credentials injected. Localhost
// URLs work because the relay runs on the host.
BaseURL string `yaml:"base_url,omitempty"`
// SyncLogs enables mounting Claude's session logs directory so logs from
// inside the container appear on the host at the correct project location.
// Default: false, unless the "anthropic" grant is configured (then true).
SyncLogs *bool `yaml:"sync_logs,omitempty"`
// Plugins enables or disables specific plugins for this run.
// Keys are in format "plugin-name@marketplace", values are true/false.
Plugins map[string]bool `yaml:"plugins,omitempty"`
// Marketplaces defines additional plugin marketplaces for this run.
Marketplaces map[string]MarketplaceSpec `yaml:"marketplaces,omitempty"`
// MCP defines MCP (Model Context Protocol) server configurations.
MCP map[string]MCPServerSpec `yaml:"mcp,omitempty"`
// SubscriptionType overrides the subscriptionType written to Claude Code's
// .credentials.json (e.g. "pro", "max"). Setup-token and pasted-token grants
// don't carry the plan, so moat defaults to "max"; set this to match your
// plan. Imported grants use the real value unless this is set.
SubscriptionType string `yaml:"subscription_type,omitempty"`
// RateLimitTier overrides the rateLimitTier written to Claude Code's
// .credentials.json (e.g. "default_claude_max_20x"). Optional; mainly affects
// Claude Code's local rate-limit hints. Real plan limits are enforced
// server-side via the proxy-injected token.
RateLimitTier string `yaml:"rate_limit_tier,omitempty"`
// LLMGateway configures a Keep LLM gateway sidecar inside the container.
// Mutually exclusive with BaseURL.
LLMGateway *LLMGatewayConfig `yaml:"llm-gateway,omitempty"`
// SkipPermissionsPrompt controls whether to suppress the bypass-permissions
// warning in Claude Code. Set automatically by moat when
// --dangerously-skip-permissions is being passed. Not a moat.yaml field.
SkipPermissionsPrompt bool `yaml:"-"`
}
ClaudeConfig configures Claude Code integration options.
type CodexConfig ¶
type CodexConfig struct {
// SyncLogs enables mounting Codex's session logs directory so logs from
// inside the container appear on the host at the correct project location.
// Default: false, unless the "openai" grant is configured (then true).
SyncLogs *bool `yaml:"sync_logs,omitempty"`
// MCP defines MCP (Model Context Protocol) server configurations.
MCP map[string]MCPServerSpec `yaml:"mcp,omitempty"`
}
CodexConfig configures OpenAI Codex CLI integration options.
type Config ¶
type Config struct {
Name string `yaml:"name,omitempty"`
Agent string `yaml:"agent"`
Version string `yaml:"version,omitempty"`
Dependencies []string `yaml:"dependencies,omitempty"`
Grants []string `yaml:"grants,omitempty"`
Env map[string]string `yaml:"env,omitempty"`
Secrets map[string]string `yaml:"secrets,omitempty"`
Mounts []MountEntry `yaml:"mounts,omitempty"`
Ports map[string]int `yaml:"ports,omitempty"`
Network NetworkConfig `yaml:"network,omitempty"`
Command []string `yaml:"command,omitempty"`
Claude ClaudeConfig `yaml:"claude,omitempty"`
Copilot CopilotConfig `yaml:"copilot,omitempty"`
Codex CodexConfig `yaml:"codex,omitempty"`
Gemini GeminiConfig `yaml:"gemini,omitempty"`
Pi PiConfig `yaml:"pi,omitempty"`
Interactive bool `yaml:"interactive,omitempty"`
// Clipboard enables host clipboard bridging. Default true when nil.
Clipboard *bool `yaml:"clipboard,omitempty"`
Snapshots SnapshotConfig `yaml:"snapshots,omitempty"`
Tracing TracingConfig `yaml:"tracing,omitempty"`
Hooks HooksConfig `yaml:"hooks,omitempty"`
Workspace WorkspaceConfig `yaml:"workspace,omitempty"`
// Sandbox configures container sandboxing.
// "none" disables gVisor sandbox (Docker only).
// Empty string or omitted uses default (gVisor enabled).
Sandbox string `yaml:"sandbox,omitempty"`
// Runtime forces a specific container runtime ("docker" or "apple").
// If not set, moat auto-detects the best available runtime.
// Useful when agent needs docker:dind on macOS (Apple containers can't run dind).
Runtime string `yaml:"runtime,omitempty"`
Volumes []VolumeConfig `yaml:"volumes,omitempty"`
Container ContainerConfig `yaml:"container,omitempty"`
MCP []MCPServerConfig `yaml:"mcp,omitempty"`
Services map[string]ServiceSpec `yaml:"services,omitempty"`
LanguageServers []string `yaml:"language_servers,omitempty"`
// BaseImage specifies a custom base image for the container.
// Moat layers its infrastructure (user, entrypoint, etc.) on top.
// Must be Debian-based (Ubuntu, Debian) since moat uses apt-get.
BaseImage string `yaml:"base_image,omitempty"`
// Deprecated: old runtime field for language versions
DeprecatedRuntime *deprecatedRuntime `yaml:"-"`
}
Config represents a moat.yaml manifest.
func Load ¶
Load reads moat.yaml (or agent.yaml as fallback) from the given directory. Returns nil, nil if neither file exists.
func (*Config) ShouldSyncClaudeLogs ¶
ShouldSyncClaudeLogs returns true if Claude session logs should be synced. The logic is: - If claude.sync_logs is explicitly set, use that value - Otherwise, enable sync_logs if "anthropic" is in grants (Claude Code integration)
func (*Config) ShouldSyncCodexLogs ¶
ShouldSyncCodexLogs returns true if Codex session logs should be synced. The logic is: - If codex.sync_logs is explicitly set, use that value - Otherwise, enable sync_logs if "openai" is in grants (Codex integration)
func (*Config) ShouldSyncGeminiLogs ¶
ShouldSyncGeminiLogs returns true if Gemini session logs should be synced. The logic is: - If gemini.sync_logs is explicitly set, use that value - Otherwise, enable sync_logs if "gemini" is in grants (Gemini integration)
func (*Config) ValidateServices ¶
ValidateServices checks that services: keys correspond to declared service dependencies.
type ContainerConfig ¶
type ContainerConfig struct {
// Memory specifies the memory limit in megabytes.
// Applies to both Docker and Apple containers.
// If not set, Apple containers default to 8192 MB (8 GB) for AI agent
// runs (claude/codex/gemini), or 4096 MB (4 GB) otherwise.
// Docker containers have no default limit.
//
// Example:
// container:
// memory: 8192 # 8 GB
Memory int `yaml:"memory,omitempty"`
// CPUs specifies the number of CPUs.
// Applies to both Docker and Apple containers.
// If not set, uses runtime defaults.
//
// Example:
// container:
// cpus: 8
CPUs int `yaml:"cpus,omitempty"`
// DNS specifies DNS servers for both runtime containers and builders.
// Applies to both Docker and Apple containers.
// If not set, defaults to ["8.8.8.8", "8.8.4.4"] (Google DNS).
//
// Example:
// container:
// dns: ["192.168.1.1", "1.1.1.1"]
//
// Note: Using public DNS will send queries to that provider,
// potentially leaking information about your dependencies and internal services.
DNS []string `yaml:"dns,omitempty"`
// Ulimits specifies resource limits (ulimits) for the container.
// Applies to both Docker and Apple containers.
// Keys are ulimit names (e.g., "nofile", "nproc", "memlock").
// Values specify soft and hard limits. Use -1 for unlimited.
//
// Example:
// container:
// ulimits:
// nofile:
// soft: 1024
// hard: 65536
Ulimits map[string]UlimitSpec `yaml:"ulimits,omitempty"`
}
ContainerConfig configures container resource limits and settings. These settings apply to both Docker and Apple container runtimes.
type CopilotConfig ¶ added in v0.7.0
type CopilotConfig struct {
// Model optionally selects the model passed to `copilot --model`.
Model string `yaml:"model,omitempty"`
// Context sets the context window tier passed to `copilot --context`.
// Valid values: "default", "long_context".
Context string `yaml:"context,omitempty"`
// ReasoningEffort sets the reasoning effort level passed to `copilot --reasoning-effort`.
// Valid values: "none", "minimal", "low", "medium", "high", "xhigh", "max".
ReasoningEffort string `yaml:"reasoning_effort,omitempty"`
// Experimental starts Copilot CLI with --experimental.
Experimental bool `yaml:"experimental,omitempty"`
// Autopilot starts Copilot CLI in autopilot mode.
Autopilot bool `yaml:"autopilot,omitempty"`
}
CopilotConfig configures GitHub Copilot CLI integration options.
type DebugConfig ¶
type DebugConfig struct {
RetentionDays int `yaml:"retention_days"`
}
DebugConfig holds debug logging settings.
type GeminiConfig ¶
type GeminiConfig struct {
// SyncLogs enables mounting Gemini's session logs directory so logs from
// inside the container appear on the host at the correct project location.
// Default: false, unless the "gemini" grant is configured (then true).
SyncLogs *bool `yaml:"sync_logs,omitempty"`
// MCP defines MCP (Model Context Protocol) server configurations.
MCP map[string]MCPServerSpec `yaml:"mcp,omitempty"`
}
GeminiConfig configures Google Gemini CLI integration options.
type GlobalConfig ¶
type GlobalConfig struct {
Proxy ProxyConfig `yaml:"proxy"`
Debug DebugConfig `yaml:"debug"`
Mounts []MountEntry `yaml:"mounts,omitempty"`
}
GlobalConfig holds global Moat settings from ~/.moat/config.yaml.
func DefaultGlobalConfig ¶
func DefaultGlobalConfig() *GlobalConfig
DefaultGlobalConfig returns the default global configuration.
func LoadGlobal ¶
func LoadGlobal() (*GlobalConfig, error)
LoadGlobal reads the moat global config file and applies environment overrides. The config path is <GlobalConfigDir>/config.yaml — by default ~/.moat/config.yaml, or $MOAT_HOME/config.yaml when MOAT_HOME is set.
type HooksConfig ¶
type HooksConfig struct {
// PostBuild runs as the container user (moatuser) during image build,
// after all dependencies are installed. Baked into image layers and cached.
// Use for user-level image setup like configuring git defaults.
PostBuild string `yaml:"post_build,omitempty"`
// PostBuildRoot runs as root during image build, after all dependencies
// are installed. Baked into image layers and cached.
// Use for system-level setup like installing packages or kernel tuning.
PostBuildRoot string `yaml:"post_build_root,omitempty"`
// PreRun runs as the container user (moatuser) in /workspace on every
// container start, before the main command. Use for workspace-level
// setup that needs project files (e.g., "npm install").
PreRun string `yaml:"pre_run,omitempty"`
}
HooksConfig configures lifecycle hooks that run at different stages.
type LLMGatewayConfig ¶ added in v0.5.0
type LLMGatewayConfig struct {
Policy *keep.PolicyConfig `yaml:"policy,omitempty"`
}
LLMGatewayConfig configures Keep LLM policy evaluation in the proxy. When configured, the proxy evaluates tool_use blocks in Anthropic API responses against Keep rules before forwarding to the container.
type MCPAuthConfig ¶
MCPAuthConfig defines authentication for an MCP server. It specifies which grant credential to use and which HTTP header to inject it into when proxying requests to the MCP server.
type MCPServerConfig ¶
type MCPServerConfig struct {
Name string `yaml:"name"`
URL string `yaml:"url"`
Auth *MCPAuthConfig `yaml:"auth,omitempty"`
Policy *keep.PolicyConfig `yaml:"policy,omitempty"`
}
MCPServerConfig defines an MCP server configuration for top-level MCP servers in moat.yaml. It specifies the server name, URL endpoint, and optional authentication settings for credential injection.
Supports both remote HTTPS servers and host-local HTTP servers. Host-local servers (http://localhost, http://127.0.0.1, or http://[::1]) are reached through the proxy relay, which runs on the host and can connect to host-local services that the container cannot reach directly.
func (*MCPServerConfig) UnmarshalYAML ¶ added in v0.6.0
func (m *MCPServerConfig) UnmarshalYAML(node *yaml.Node) error
UnmarshalYAML lets an mcp[] entry be either a bare service name (string) or a full mapping. A bare string resolves its url/auth from the well-known catalog during config load (see resolveMCPShorthand).
type MCPServerSpec ¶
type MCPServerSpec struct {
// Command is the executable to run
Command string `yaml:"command"`
// Args are command-line arguments
Args []string `yaml:"args,omitempty"`
// Env are environment variables for the server
Env map[string]string `yaml:"env,omitempty"`
// Grant specifies a credential grant to inject (e.g., "github", "anthropic")
Grant string `yaml:"grant,omitempty"`
// Cwd is the working directory for the server
Cwd string `yaml:"cwd,omitempty"`
}
MCPServerSpec defines an MCP server configuration.
type MarketplaceSpec ¶
type MarketplaceSpec struct {
// Source is the type of marketplace: "github", "git", or "directory"
Source string `yaml:"source"`
// Repo is the GitHub repository in "owner/repo" format (for source: github)
Repo string `yaml:"repo,omitempty"`
// URL is the git URL (for source: git)
// Supports both HTTPS (https://github.com/org/repo.git) and
// SSH (git@github.com:org/repo.git) URLs
URL string `yaml:"url,omitempty"`
// Path is the local directory path (for source: directory)
Path string `yaml:"path,omitempty"`
}
MarketplaceSpec defines a plugin marketplace source.
type MountEntry ¶ added in v0.4.0
type MountEntry struct {
Source string `yaml:"source"`
Target string `yaml:"target"`
Mode string `yaml:"mode,omitempty"`
ReadOnly bool `yaml:"-"`
Exclude []string `yaml:"exclude,omitempty"`
}
MountEntry represents a mount configuration. It supports two YAML forms: - String: "source:target[:mode]" (existing format) - Object: {source, target, mode, exclude} (new format with exclude support)
func ParseMount ¶
func ParseMount(s string) (*MountEntry, error)
ParseMount parses a mount string like "./data:/data:ro". This is the public API used by the run manager for --mount CLI flags.
func (*MountEntry) UnmarshalYAML ¶ added in v0.4.0
func (m *MountEntry) UnmarshalYAML(value *yaml.Node) error
UnmarshalYAML handles both string and object forms in a mixed-type YAML array.
type NetworkConfig ¶
type NetworkConfig struct {
Policy string `yaml:"policy,omitempty"` // "permissive" or "strict", default "permissive"
Allow []string `yaml:"allow,omitempty"` // deprecated: hard error
Rules []netrules.NetworkRuleEntry `yaml:"rules,omitempty"`
KeepPolicy *keep.PolicyConfig `yaml:"keep_policy,omitempty"`
Host []int `yaml:"host,omitempty"` // TCP ports on the host the container may access
}
NetworkConfig configures network access policies for the agent.
type PiConfig ¶ added in v0.7.0
type PiConfig struct {
Provider string `yaml:"provider,omitempty"`
Model string `yaml:"model,omitempty"`
Packages []string `yaml:"packages,omitempty"`
}
PiConfig configures the Pi coding agent integration.
Pi has no credential of its own; it runs against the anthropic or openai grant. Provider selects the backend (must be "anthropic" or "openai" in v1); when unset it is inferred from the single configured grant. Model optionally pins a model pattern (Pi's per-provider default is used when empty).
type ProxyConfig ¶
type ProxyConfig struct {
Port int `yaml:"port"`
}
ProxyConfig holds reverse proxy settings.
type ServiceSpec ¶
type ServiceSpec struct {
Env map[string]string `yaml:"env,omitempty"`
Image string `yaml:"image,omitempty"`
Wait *bool `yaml:"wait,omitempty"`
Memory int `yaml:"memory,omitempty"` // Memory limit in MB for the service container (0 = runtime default)
// Extra holds unknown list-valued keys (e.g., "models" for ollama).
// Populated by UnmarshalYAML. The run layer maps these to provisions
// using the registry's provisions_key.
Extra map[string][]string `yaml:"-"`
}
ServiceSpec allows customizing service behavior.
func (ServiceSpec) ServiceWait ¶
func (s ServiceSpec) ServiceWait() bool
ServiceWait returns whether to wait for this service to be ready (default: true).
func (*ServiceSpec) UnmarshalYAML ¶ added in v0.4.0
func (s *ServiceSpec) UnmarshalYAML(value *yaml.Node) error
UnmarshalYAML implements custom unmarshaling to capture unknown list-valued keys into Extra. Known keys (env, image, wait) are parsed normally.
type SnapshotConfig ¶
type SnapshotConfig struct {
Disabled bool `yaml:"disabled,omitempty"`
Triggers SnapshotTriggerConfig `yaml:"triggers,omitempty"`
Exclude SnapshotExcludeConfig `yaml:"exclude,omitempty"`
Retention SnapshotRetentionConfig `yaml:"retention,omitempty"`
}
SnapshotConfig configures workspace snapshots.
type SnapshotExcludeConfig ¶
type SnapshotExcludeConfig struct {
IgnoreGitignore bool `yaml:"ignore_gitignore,omitempty"`
Additional []string `yaml:"additional,omitempty"`
}
SnapshotExcludeConfig configures what to exclude from snapshots.
type SnapshotRetentionConfig ¶
type SnapshotRetentionConfig struct {
MaxCount int `yaml:"max_count,omitempty"`
DeleteInitial bool `yaml:"delete_initial,omitempty"`
}
SnapshotRetentionConfig configures snapshot retention.
type SnapshotTriggerConfig ¶
type SnapshotTriggerConfig struct {
DisablePreRun bool `yaml:"disable_pre_run,omitempty"`
DisableGitCommits bool `yaml:"disable_git_commits,omitempty"`
DisableBuilds bool `yaml:"disable_builds,omitempty"`
DisableIdle bool `yaml:"disable_idle,omitempty"`
IdleThresholdSeconds int `yaml:"idle_threshold_seconds,omitempty"`
}
SnapshotTriggerConfig configures when snapshots are created.
type TracingConfig ¶
type TracingConfig struct {
DisableExec bool `yaml:"disable_exec,omitempty"`
}
TracingConfig configures execution tracing.
type UlimitSpec ¶ added in v0.3.2
UlimitSpec defines a resource limit with soft and hard values. Use -1 for unlimited.
type VolumeConfig ¶ added in v0.3.0
type VolumeConfig struct {
Name string `yaml:"name"`
Target string `yaml:"target"`
ReadOnly bool `yaml:"readonly,omitempty"`
// Type selects the backing store: "bind" (default) is a host bind mount at
// ~/.moat/volumes/<agent>/<name> (visible on the host; crosses the host↔VM
// filesystem-sharing layer on VM-based runtimes). "volume" is a Docker named
// volume on the engine's native filesystem (not host-visible; bypasses that
// layer). Docker runtime only.
Type string `yaml:"type,omitempty"`
}
VolumeConfig defines a named volume to mount inside the container. Volumes are managed by moat and persist across runs for the same agent name.
func (VolumeConfig) IsNamedVolume ¶ added in v0.7.0
func (v VolumeConfig) IsNamedVolume() bool
IsNamedVolume reports whether the entry is backed by a native Docker named volume (type: volume) rather than the default host bind mount (type: bind or ""). This is the single source of truth for the predicate — validation, image-init gating, and mount construction all route through it so they cannot drift.
type WorkspaceConfig ¶ added in v0.7.0
type WorkspaceConfig struct {
// Mode is "bind" (default) or "volume". Empty means bind.
Mode WorkspaceMode `yaml:"mode,omitempty"`
}
WorkspaceConfig is the moat.yaml `workspace:` block.
func (WorkspaceConfig) Validate ¶ added in v0.7.0
func (w WorkspaceConfig) Validate() error
Validate rejects any mode other than "", "bind", or "volume".
type WorkspaceMode ¶ added in v0.7.0
type WorkspaceMode string
WorkspaceMode selects how the host working tree is presented to the container.
const ( // WorkspaceModeBind bind-mounts the host tree at /workspace (default, current behavior). WorkspaceModeBind WorkspaceMode = "bind" // WorkspaceModeVolume copies the host tree into an ephemeral Docker named volume. WorkspaceModeVolume WorkspaceMode = "volume" )
func ResolveWorkspaceMode ¶ added in v0.7.0
func ResolveWorkspaceMode(w WorkspaceConfig, override string) (WorkspaceMode, error)
ResolveWorkspaceMode applies precedence: CLI override > yaml > default(bind). override is the raw --workspace-mode flag value ("" when unset). It also validates w.Mode, so it is safe to call without a prior Load().