Documentation
¶
Overview ¶
Package storage provides run storage infrastructure for Moat. It handles persisting and loading run metadata, logs, and traces.
Index ¶
- func DefaultBaseDir() string
- func ListRunDirs(baseDir string) ([]string, error)
- type ExecEvent
- type LogEntry
- type LogWriter
- type Metadata
- type NetworkRequest
- type RunStore
- func (s *RunStore) Dir() string
- func (s *RunStore) LoadMetadata() (Metadata, error)
- func (s *RunStore) LogWriter() (*LogWriter, error)
- func (s *RunStore) ReadDockerfile() (string, error)
- func (s *RunStore) ReadExecEvents() ([]ExecEvent, error)
- func (s *RunStore) ReadLogs(offset, limit int) ([]LogEntry, error)
- func (s *RunStore) ReadNetworkRequests() ([]NetworkRequest, error)
- func (s *RunStore) ReadSecretResolutions() ([]SecretResolution, error)
- func (s *RunStore) ReadSpans() ([]Span, error)
- func (s *RunStore) Remove() error
- func (s *RunStore) RunID() string
- func (s *RunStore) SaveDockerfile(dockerfile string) error
- func (s *RunStore) SaveMetadata(m Metadata) error
- func (s *RunStore) WriteExecEvent(event ExecEvent) error
- func (s *RunStore) WriteNetworkRequest(req NetworkRequest) error
- func (s *RunStore) WriteSecretResolution(res SecretResolution) error
- func (s *RunStore) WriteSpan(span Span) error
- type SecretResolution
- type Span
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultBaseDir ¶
func DefaultBaseDir() string
DefaultBaseDir returns the default base directory for run storage. This is ~/.moat/runs.
func ListRunDirs ¶
ListRunDirs returns all run IDs that have stored metadata. It scans baseDir for directories containing metadata.json.
Types ¶
type ExecEvent ¶
type ExecEvent struct {
Timestamp time.Time `json:"timestamp"`
PID int `json:"pid"`
PPID int `json:"ppid"`
Command string `json:"command"`
Args []string `json:"args"`
WorkingDir string `json:"working_dir,omitempty"`
ExitCode *int `json:"exit_code,omitempty"`
Duration *time.Duration `json:"duration,omitempty"`
}
ExecEvent represents a command execution captured by the tracer. This is a duplicate of trace.ExecEvent to avoid circular imports.
type LogWriter ¶
type LogWriter struct {
// contains filtered or unexported fields
}
LogWriter wraps writes to add timestamps.
type Metadata ¶
type Metadata struct {
Name string `json:"name"`
Workspace string `json:"workspace"`
Grants []string `json:"grants,omitempty"`
Agent string `json:"agent,omitempty"` // Agent type from config (e.g., "claude-code")
Image string `json:"image,omitempty"` // Container image used
Ports map[string]int `json:"ports,omitempty"`
ContainerID string `json:"container_id,omitempty"`
State string `json:"state,omitempty"`
Interactive bool `json:"interactive,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`
StartedAt time.Time `json:"started_at,omitempty"`
StoppedAt time.Time `json:"stopped_at,omitempty"`
Error string `json:"error,omitempty"`
// Worktree fields (set when run was created via moat wt or --wt)
WorktreeBranch string `json:"worktree_branch,omitempty"`
WorktreePath string `json:"worktree_path,omitempty"`
WorktreeRepoID string `json:"worktree_repo_id,omitempty"`
// Service dependency fields
ServiceContainers map[string]string `json:"service_containers,omitempty"` // service name -> container ID
// BuildKit sidecar fields (docker:dind only)
BuildkitContainerID string `json:"buildkit_container_id,omitempty"`
NetworkID string `json:"network_id,omitempty"`
}
Metadata holds information about an agent run.
type NetworkRequest ¶
type NetworkRequest struct {
Timestamp time.Time `json:"ts"`
Method string `json:"method"`
URL string `json:"url"`
StatusCode int `json:"status_code"`
Duration int64 `json:"duration_ms"`
Error string `json:"error,omitempty"`
RequestHeaders map[string]string `json:"req_headers,omitempty"`
ResponseHeaders map[string]string `json:"resp_headers,omitempty"`
RequestBody string `json:"req_body,omitempty"`
ResponseBody string `json:"resp_body,omitempty"`
BodyTruncated bool `json:"truncated,omitempty"`
}
NetworkRequest represents a logged HTTP request.
type RunStore ¶
type RunStore struct {
// contains filtered or unexported fields
}
RunStore manages storage for a single agent run.
func NewRunStore ¶
NewRunStore creates a new RunStore for the given run ID. It creates the run directory under baseDir if it doesn't exist.
func (*RunStore) LoadMetadata ¶
LoadMetadata reads the metadata from metadata.json in the run directory.
func (*RunStore) ReadDockerfile ¶
ReadDockerfile reads the Dockerfile from the run directory.
func (*RunStore) ReadExecEvents ¶
ReadExecEvents reads all execution events from exec.jsonl.
func (*RunStore) ReadNetworkRequests ¶
func (s *RunStore) ReadNetworkRequests() ([]NetworkRequest, error)
ReadNetworkRequests reads all network requests.
func (*RunStore) ReadSecretResolutions ¶
func (s *RunStore) ReadSecretResolutions() ([]SecretResolution, error)
ReadSecretResolutions reads all secret resolutions.
func (*RunStore) Remove ¶
Remove deletes the run's storage directory and all its contents. Returns an error if the run ID is empty to prevent accidental deletion of the base directory.
func (*RunStore) SaveDockerfile ¶
SaveDockerfile saves the Dockerfile used to build the container image.
func (*RunStore) SaveMetadata ¶
SaveMetadata writes the metadata to metadata.json in the run directory.
func (*RunStore) WriteExecEvent ¶
WriteExecEvent writes an execution event to exec.jsonl.
func (*RunStore) WriteNetworkRequest ¶
func (s *RunStore) WriteNetworkRequest(req NetworkRequest) error
WriteNetworkRequest appends a network request to the log.
func (*RunStore) WriteSecretResolution ¶
func (s *RunStore) WriteSecretResolution(res SecretResolution) error
WriteSecretResolution records that a secret was resolved.
type SecretResolution ¶
type SecretResolution struct {
Timestamp time.Time `json:"ts"`
Name string `json:"name"` // env var name
Backend string `json:"backend"` // e.g., "1password"
}
SecretResolution records a resolved secret (without the value).
type Span ¶
type Span struct {
TraceID string `json:"trace_id"`
SpanID string `json:"span_id"`
ParentID string `json:"parent_id,omitempty"`
Name string `json:"name"`
Kind string `json:"kind,omitempty"` // client, server, internal
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
Attributes map[string]interface{} `json:"attributes,omitempty"`
Status string `json:"status,omitempty"` // ok, error
StatusMsg string `json:"status_msg,omitempty"`
}
Span represents a trace span (OpenTelemetry-compatible).