agent

package
v0.0.0-...-8198c06 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidSignature   = &AgentError{Code: "INVALID_SIGNATURE", Message: "Invalid job signature"}
	ErrJobExpired         = &AgentError{Code: "JOB_EXPIRED", Message: "Job has expired (TTL exceeded)"}
	ErrJobTooOld          = &AgentError{Code: "JOB_TOO_OLD", Message: "Job timestamp too old (possible replay attack)"}
	ErrInsufficientScopes = &AgentError{Code: "INSUFFICIENT_SCOPES", Message: "Insufficient scopes for job execution"}
)

Errors

Functions

func SaveConfig

func SaveConfig(config *Config, path string) error

SaveConfig saves configuration to a YAML file

func SignPayload

func SignPayload(payload *JobPayload, secret string) (string, error)

SignPayload creates an HMAC signature for a job payload

func ValidateSignature

func ValidateSignature(job *SignedJob, secret string) error

ValidateSignature verifies the HMAC signature of a job

func ValidateTTL

func ValidateTTL(payload *JobPayload) error

ValidateTTL checks if the job has expired

Types

type AgentError

type AgentError struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

AgentError represents an agent-specific error

func (*AgentError) Error

func (e *AgentError) Error() string

type Config

type Config struct {
	// Server settings
	Port        int    `yaml:"port"`
	TLSCertFile string `yaml:"tls_cert_file"`
	TLSKeyFile  string `yaml:"tls_key_file"`

	// Authentication
	HMACSecret         string   `yaml:"hmac_secret"`
	AllowedControllers []string `yaml:"allowed_controllers"`

	// Execution settings
	MaxConcurrentJobs int      `yaml:"max_concurrent_jobs"`
	AllowedImages     []string `yaml:"allowed_images"`
	DefaultImage      string   `yaml:"default_image"`

	// Security
	RunAsUser  string `yaml:"run_as_user"`
	RunAsGroup string `yaml:"run_as_group"`

	// Sandbox defaults
	DefaultCPULimit    float64 `yaml:"default_cpu_limit"`
	DefaultMemoryLimit int64   `yaml:"default_memory_limit"`
	DefaultTimeout     int     `yaml:"default_timeout_seconds"`

	// Audit
	AuditDBPath string `yaml:"audit_db_path"`
}

Config represents the agent configuration

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a default configuration

func LoadConfig

func LoadConfig(path string) (*Config, error)

LoadConfig loads configuration from a YAML file

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the configuration

type Job

type Job struct {
	Payload    *JobPayload
	Status     JobStatus
	Result     *JobResult
	LogChan    chan *LogFrame
	CancelFunc context.CancelFunc
	CreatedAt  time.Time
}

Job represents a job being executed

type JobExecutor

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

JobExecutor executes jobs using the sandbox runner

func NewJobExecutor

func NewJobExecutor(config *Config) (*JobExecutor, error)

NewJobExecutor creates a new job executor

func (*JobExecutor) Close

func (e *JobExecutor) Close() error

Close closes the executor resources

func (*JobExecutor) Execute

func (e *JobExecutor) Execute(ctx context.Context, payload *JobPayload, logChan chan<- *LogFrame) (*JobResult, error)

Execute executes a job and streams logs

type JobPayload

type JobPayload struct {
	JobID             string                 `json:"job_id"`
	Prompt            string                 `json:"prompt"`
	Command           string                 `json:"command"`
	CandidateMetadata map[string]interface{} `json:"candidate_metadata"`
	PluginMetadata    map[string]interface{} `json:"plugin_metadata"`
	RequiredScopes    []string               `json:"required_scopes"`
	SnapshotMetadata  string                 `json:"snapshot_metadata"` // JSON-encoded
	TTL               int64                  `json:"ttl"`               // Unix timestamp
	Timestamp         int64                  `json:"timestamp"`         // Unix timestamp
	ControllerID      string                 `json:"controller_id"`
}

JobPayload represents a signed job request from the controller

type JobResult

type JobResult struct {
	JobID      string    `json:"job_id"`
	Status     JobStatus `json:"status"`
	SandboxID  string    `json:"sandbox_id"`
	ExitCode   int       `json:"exit_code"`
	Stdout     string    `json:"stdout"`
	Stderr     string    `json:"stderr"`
	StartTime  time.Time `json:"start_time"`
	EndTime    time.Time `json:"end_time"`
	DurationMs int64     `json:"duration_ms"`
	Error      string    `json:"error,omitempty"`
	Snapshot   string    `json:"snapshot,omitempty"` // JSON-encoded snapshot metadata
}

JobResult contains the execution result

type JobSignature

type JobSignature struct {
	Signature string `json:"signature"`
	Algorithm string `json:"algorithm"` // "HMAC-SHA256"
}

JobSignature contains the HMAC signature for a job payload

type JobStatus

type JobStatus string

JobStatus represents the current status of a job

const (
	JobStatusPending   JobStatus = "pending"
	JobStatusRunning   JobStatus = "running"
	JobStatusCompleted JobStatus = "completed"
	JobStatusFailed    JobStatus = "failed"
	JobStatusRejected  JobStatus = "rejected"
)

type LogFrame

type LogFrame struct {
	JobID     string    `json:"job_id"`
	Timestamp time.Time `json:"timestamp"`
	Stream    string    `json:"stream"` // "stdout" or "stderr"
	Data      string    `json:"data"`
	Final     bool      `json:"final"` // True for the last frame
}

LogFrame represents a single log message during streaming

type Server

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

Server represents the agent HTTP server

func NewServer

func NewServer(config *Config) (*Server, error)

NewServer creates a new agent server

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down the server

func (*Server) Start

func (s *Server) Start() error

Start starts the HTTPS server

type SignedJob

type SignedJob struct {
	Payload   JobPayload   `json:"payload"`
	Signature JobSignature `json:"signature"`
}

SignedJob combines payload and signature

Jump to

Keyboard shortcuts

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