agent

package
v0.0.0-...-381f291 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SaveConfig

func SaveConfig(config *Config, configPath string) error

func SaveIndividualAgentConfig

func SaveIndividualAgentConfig(config *IndividualAgentConfig, agentsDir string) error

Types

type Action

type Action string
const (
	ActionFileWrite    Action = "file_write"
	ActionFileDelete   Action = "file_delete"
	ActionGitCommit    Action = "git_commit"
	ActionGitPush      Action = "git_push"
	ActionStatusChange Action = "status_change"
	ActionTaskCreate   Action = "task_create"
)

type Agent

type Agent struct {
	ID           string         `yaml:"id"`
	Name         string         `yaml:"name"`
	Type         string         `yaml:"type"`
	Process      string         `yaml:"process"` // The process this agent handles
	Description  string         `yaml:"description,omitempty"`
	Version      string         `yaml:"version,omitempty"`
	Instructions string         `yaml:"instructions,omitempty"`
	Scaling      *ScalingConfig `yaml:"scaling,omitempty"`
	Status       Status         `yaml:"status"`
	TaskID       string         `yaml:"task_id,omitempty"`
	ProcessName  string         `yaml:"process_name,omitempty"` // Currently executing process
	WorktreePath string         `yaml:"worktree_path,omitempty"`
	CreatedAt    time.Time      `yaml:"created_at"`
	UpdatedAt    time.Time      `yaml:"updated_at"`
	// contains filtered or unexported fields
}

func NewAgent

func NewAgent(id string, config *AgentConfig, factory ExecutorFactory) (*Agent, error)

func (*Agent) GetPermissionRequestChan

func (a *Agent) GetPermissionRequestChan() <-chan PermissionRequest

GetPermissionRequestChan returns the channel for receiving permission requests This can be used by UI/CLI to handle permission requests from the executor

func (*Agent) GetStatus

func (a *Agent) GetStatus() Status

func (*Agent) InitializeWithDependencies

func (a *Agent) InitializeWithDependencies(taskService task.Service, eventBus *event.EventBus, worktreeManager *worktree.Manager) error

InitializeWithDependencies injects dependencies and initializes the executor

func (*Agent) IsAvailable

func (a *Agent) IsAvailable() bool

func (*Agent) SendPermissionResponse

func (a *Agent) SendPermissionResponse(response PermissionResponse)

SendPermissionResponse sends a permission response to the executor

func (*Agent) Start

func (a *Agent) Start(ctx context.Context) error

func (*Agent) Stop

func (a *Agent) Stop() error

func (*Agent) UpdateStatus

func (a *Agent) UpdateStatus(status Status)

type AgentConfig

type AgentConfig struct {
	Name         string         `yaml:"name"`
	Type         string         `yaml:"type"`
	Process      string         `yaml:"process"` // The process this agent handles (e.g., "implement", "review", "qa")
	Instructions string         `yaml:"instructions,omitempty"`
	Scaling      *ScalingConfig `yaml:"scaling,omitempty"`
}

type AgentRegistry

type AgentRegistry interface {
	GetAgentsByName(name string) []*Agent
	CreateAgent(config *AgentConfig) (*Agent, error)
	RemoveAgent(agentID string) error
	ListAgents() []*Agent
}

AgentRegistry defines the interface for agent registry operations

type ApprovalRequest

type ApprovalRequest struct {
	AgentID   string
	Action    Action
	Target    string
	Details   map[string]interface{}
	Response  chan bool
	Timestamp time.Time
}

type AutoScaler

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

AutoScaler manages automatic scaling of agents

func NewAutoScaler

func NewAutoScaler(config *Config, factory ExecutorFactory, registry AgentRegistry) *AutoScaler

NewAutoScaler creates a new auto scaler

func (*AutoScaler) SetMonitorInterval

func (s *AutoScaler) SetMonitorInterval(interval time.Duration)

SetMonitorInterval sets the monitoring interval

func (*AutoScaler) Start

func (s *AutoScaler) Start(ctx context.Context) error

Start starts the auto scaling monitor

func (*AutoScaler) Stop

func (s *AutoScaler) Stop() error

Stop stops the auto scaling monitor

type BaseExecutor

type BaseExecutor struct {
	Config ExecutorConfig
	// contains filtered or unexported fields
}

BaseExecutor provides common functionality for all executors

func (*BaseExecutor) Connect

func (e *BaseExecutor) Connect(ctx context.Context) error

Connect is a no-op for base executor (override in streaming executors)

func (*BaseExecutor) Disconnect

func (e *BaseExecutor) Disconnect() error

Disconnect is a no-op for base executor (override in streaming executors)

func (*BaseExecutor) Initialize

func (e *BaseExecutor) Initialize(ctx context.Context, config ExecutorConfig) error

Initialize sets up the base executor

func (*BaseExecutor) IsConnected

func (e *BaseExecutor) IsConnected() bool

IsConnected returns false for base executor (override in streaming executors)

type ClaudeCodeExecutor

type ClaudeCodeExecutor struct {
	BaseExecutor
	// contains filtered or unexported fields
}

ClaudeCodeExecutor implements the Executor interface for Claude Code using persistent streaming connection for interactive communication

func NewClaudeCodeExecutor

func NewClaudeCodeExecutor() *ClaudeCodeExecutor

NewClaudeCodeExecutor creates a new Claude Code executor

func (*ClaudeCodeExecutor) CanExecute

func (e *ClaudeCodeExecutor) CanExecute(work *WorkItem) bool

CanExecute checks if this executor can handle the work item

func (*ClaudeCodeExecutor) Cleanup

func (e *ClaudeCodeExecutor) Cleanup() error

Cleanup releases resources

func (*ClaudeCodeExecutor) Connect

func (e *ClaudeCodeExecutor) Connect(ctx context.Context) error

Connect establishes a persistent connection to Claude Code

func (*ClaudeCodeExecutor) Disconnect

func (e *ClaudeCodeExecutor) Disconnect() error

Disconnect closes the persistent connection

func (*ClaudeCodeExecutor) Execute

func (e *ClaudeCodeExecutor) Execute(ctx context.Context, work *WorkItem) (*ExecutionResult, error)

Execute executes a work item using Claude Code

func (*ClaudeCodeExecutor) Initialize

func (e *ClaudeCodeExecutor) Initialize(ctx context.Context, config ExecutorConfig) error

Initialize initializes the executor with configuration

func (*ClaudeCodeExecutor) IsConnected

func (e *ClaudeCodeExecutor) IsConnected() bool

IsConnected returns true if the executor has an active connection

type Config

type Config struct {
	Agents []*AgentConfig `yaml:"agents"`
}

func LoadConfig

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

func (*Config) GetAgentConfig

func (c *Config) GetAgentConfig(name string) (*AgentConfig, bool)

func (*Config) GetScalableAgents

func (c *Config) GetScalableAgents() []*AgentConfig

type DefaultExecutorFactory

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

DefaultExecutorFactory implements ExecutorFactory

func NewDefaultExecutorFactory

func NewDefaultExecutorFactory(taskService task.Service, eventBus *event.EventBus, worktreeManager *worktree.Manager) *DefaultExecutorFactory

NewDefaultExecutorFactory creates a new default executor factory

func (*DefaultExecutorFactory) CreateExecutor

func (f *DefaultExecutorFactory) CreateExecutor(executorType string) (Executor, error)

CreateExecutor creates the appropriate executor based on type

type ExecutionResult

type ExecutionResult struct {
	Success    bool
	NextStatus string
	Message    string
	Artifacts  []string
	Error      error
}

ExecutionResult represents the result of work execution

type Executor

type Executor interface {
	// Initialize the executor with configuration
	Initialize(ctx context.Context, config ExecutorConfig) error

	// Connect establishes a persistent connection (for streaming executors)
	Connect(ctx context.Context) error

	// Disconnect closes the persistent connection
	Disconnect() error

	// IsConnected returns true if the executor has an active connection
	IsConnected() bool

	// Execute a work item (task or event)
	Execute(ctx context.Context, work *WorkItem) (*ExecutionResult, error)

	// Check if the executor can handle this work item
	CanExecute(work *WorkItem) bool

	// Cleanup resources
	Cleanup() error
}

Executor defines the interface for executing agent-specific logic

type ExecutorConfig

type ExecutorConfig struct {
	AgentID      string
	Name         string
	Process      string // The process type this executor handles
	Instructions string
	WorktreePath string

	// Permission handling
	PermissionRequestChan  chan<- PermissionRequest  // Channel to send permission requests
	PermissionResponseChan <-chan PermissionResponse // Channel to receive permission responses

	// Dependency injection
	TaskService     task.Service
	EventBus        *event.EventBus
	WorktreeManager *worktree.Manager
}

ExecutorConfig holds configuration for executor initialization

type ExecutorFactory

type ExecutorFactory interface {
	CreateExecutor(executorType string) (Executor, error)
}

ExecutorFactory creates executors

type IndividualAgentConfig

type IndividualAgentConfig struct {
	Name         string         `yaml:"name"`
	Type         string         `yaml:"type"`
	Process      string         `yaml:"process"` // The process this agent handles
	Scaling      *ScalingConfig `yaml:"scaling,omitempty"`
	Description  string         `yaml:"description,omitempty"`
	Version      string         `yaml:"version,omitempty"`
	Instructions string         `yaml:"instructions,omitempty"`
}

IndividualAgentConfig represents a single agent's configuration file

type Manager

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

func NewManager

func NewManager(config *Config, eventBus *event.EventBus, taskService task.Service, worktreeManager *worktree.Manager) *Manager

func (*Manager) CreateAgent

func (m *Manager) CreateAgent(config *AgentConfig) (*Agent, error)

CreateAgent creates a new agent and starts it (implements AgentRegistry)

func (*Manager) GetAgent

func (m *Manager) GetAgent(agentID string) (*Agent, bool)

func (*Manager) GetAgentsByName

func (m *Manager) GetAgentsByName(name string) []*Agent

func (*Manager) GetAvailableAgents

func (m *Manager) GetAvailableAgents() []*Agent

func (*Manager) ListAgents

func (m *Manager) ListAgents() []*Agent

func (*Manager) RemoveAgent

func (m *Manager) RemoveAgent(agentID string) error

RemoveAgent removes an agent and stops it (implements AgentRegistry)

func (*Manager) Start

func (m *Manager) Start(ctx context.Context) error

type PermissionRequest

type PermissionRequest struct {
	ID        string                 // Unique request ID
	ToolName  string                 // Tool being requested (e.g., "Bash", "Write", "Edit")
	Input     map[string]interface{} // Tool input parameters
	TaskID    string                 // Associated task ID
	AgentID   string                 // Agent making the request
	Timestamp int64                  // Request timestamp
}

PermissionRequest represents a tool permission request from Claude

type PermissionResponse

type PermissionResponse struct {
	RequestID    string                 // Matching request ID
	Allowed      bool                   // Whether the action is allowed
	Message      string                 // Optional message (e.g., reason for denial)
	UpdatedInput map[string]interface{} // Optional: modified input parameters
}

PermissionResponse represents the user's response to a permission request

type ScalingConfig

type ScalingConfig struct {
	Min  int  `yaml:"min"`
	Max  int  `yaml:"max"`
	Auto bool `yaml:"auto"`
}

type Status

type Status string
const (
	StatusIdle    Status = "IDLE"
	StatusBusy    Status = "BUSY"
	StatusWaiting Status = "WAITING"
	StatusError   Status = "ERROR"
	StatusStopped Status = "STOPPED"
)

type WorkItem

type WorkItem struct {
	ID          string
	Task        *task.Task
	ProcessName string // The process being executed (e.g., "implement", "review", "qa")
	Context     map[string]interface{}
}

WorkItem represents a unified work item (task process to execute)

Jump to

Keyboard shortcuts

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