Documentation
¶
Overview ¶
Package agent provides the core orchestration engine for devloop.
The agent package contains the orchestrator implementations that handle: - File system watching and event processing - Rule execution and process management - Gateway communication for distributed setups - Logging and output management
Key Components ¶
The main orchestrator interface provides methods for:
type Orchestrator interface {
Start() error
Stop() error
GetConfig() *gateway.Config
TriggerRule(ruleName string) error
GetRuleStatus(ruleName string) (*gateway.RuleStatus, bool)
GetWatchedPaths() []string
ReadFileContent(path string) ([]byte, error)
StreamLogs(ruleName string, filter string, stream pb.GatewayClientService_StreamLogsClientServer) error
SetGlobalDebounceDelay(duration time.Duration)
SetVerbose(verbose bool)
}
Usage ¶
Create and start an orchestrator:
orchestrator := agent.NewOrchestratorV2("config.yaml", "")
if err := orchestrator.Start(); err != nil {
log.Fatal(err)
}
defer orchestrator.Stop()
Configuration ¶
The orchestrator is configured via YAML files with rules that define: - File patterns to watch - Commands to execute when files change - Debounce settings and execution options
Example configuration:
settings:
project_id: "my-project"
prefix_logs: true
rules:
- name: "build"
watch:
- action: include
patterns: ["**/*.go"]
commands:
- "go build ."
Index ¶
- func LoadConfig(configPath string) (*gateway.Config, error)
- type Orchestrator
- type OrchestratorV2
- func (o *OrchestratorV2) GetConfig() *gateway.Config
- func (o *OrchestratorV2) GetRuleStatus(ruleName string) (*gateway.RuleStatus, bool)
- func (o *OrchestratorV2) GetWatchedPaths() []string
- func (o *OrchestratorV2) ProjectRoot() string
- func (o *OrchestratorV2) ReadFileContent(path string) ([]byte, error)
- func (o *OrchestratorV2) SetGlobalDebounceDelay(duration time.Duration)
- func (o *OrchestratorV2) SetRuleDebounceDelay(ruleName string, duration time.Duration) error
- func (o *OrchestratorV2) SetRuleVerbose(ruleName string, verbose bool) error
- func (o *OrchestratorV2) SetVerbose(verbose bool)
- func (o *OrchestratorV2) Start() error
- func (o *OrchestratorV2) Stop() error
- func (o *OrchestratorV2) StreamLogs(ruleName string, filter string, ...) error
- func (o *OrchestratorV2) TriggerRule(ruleName string) error
- type PrefixWriter
- type RuleRunner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Orchestrator ¶
type Orchestrator interface {
Start() error
Stop() error
GetConfig() *gateway.Config
TriggerRule(ruleName string) error
GetRuleStatus(ruleName string) (*gateway.RuleStatus, bool)
GetWatchedPaths() []string
ReadFileContent(path string) ([]byte, error)
StreamLogs(ruleName string, filter string, stream pb.GatewayClientService_StreamLogsClientServer) error
SetGlobalDebounceDelay(duration time.Duration)
SetVerbose(verbose bool)
}
Orchestrator interface defines the common methods for orchestrator implementations
func NewOrchestratorForTesting ¶
func NewOrchestratorForTesting(configPath, gatewayAddr string) (Orchestrator, error)
NewOrchestratorForTesting creates a new V2 orchestrator for testing
type OrchestratorV2 ¶
type OrchestratorV2 struct {
ConfigPath string
Config *gateway.Config
Verbose bool
Watcher *fsnotify.Watcher
LogManager *utils.LogManager
ColorManager *utils.ColorManager
// contains filtered or unexported fields
}
OrchestratorV2 manages file watching and delegates execution to RuleRunners
func NewOrchestratorV2 ¶
func NewOrchestratorV2(configPath string, gatewayAddr string) (*OrchestratorV2, error)
NewOrchestratorV2 creates a new orchestrator instance for managing file watching and rule execution.
The orchestrator handles: - Loading and validating configuration from configPath - Setting up file system watching for specified patterns - Managing rule execution and process lifecycle - Optional gateway communication if gatewayAddr is provided
Parameters:
- configPath: Path to the .devloop.yaml configuration file
- gatewayAddr: Optional gateway address for distributed mode (empty for standalone)
Returns an orchestrator instance ready to be started, or an error if configuration loading or initialization fails.
Example:
// Standalone mode
orchestrator, err := NewOrchestratorV2(".devloop.yaml", "")
// Agent mode (connect to gateway)
orchestrator, err := NewOrchestratorV2(".devloop.yaml", "localhost:50051")
func (*OrchestratorV2) GetConfig ¶
func (o *OrchestratorV2) GetConfig() *gateway.Config
GetConfig returns the orchestrator's configuration.
func (*OrchestratorV2) GetRuleStatus ¶
func (o *OrchestratorV2) GetRuleStatus(ruleName string) (*gateway.RuleStatus, bool)
GetRuleStatus returns the status of a specific rule
func (*OrchestratorV2) GetWatchedPaths ¶
func (o *OrchestratorV2) GetWatchedPaths() []string
GetWatchedPaths returns a unique list of all paths being watched by any rule
func (*OrchestratorV2) ProjectRoot ¶
func (o *OrchestratorV2) ProjectRoot() string
ProjectRoot returns the project root directory
func (*OrchestratorV2) ReadFileContent ¶
func (o *OrchestratorV2) ReadFileContent(path string) ([]byte, error)
ReadFileContent reads and returns the content of a specified file
func (*OrchestratorV2) SetGlobalDebounceDelay ¶
func (o *OrchestratorV2) SetGlobalDebounceDelay(duration time.Duration)
SetGlobalDebounceDelay sets the default debounce delay for all rules
func (*OrchestratorV2) SetRuleDebounceDelay ¶
func (o *OrchestratorV2) SetRuleDebounceDelay(ruleName string, duration time.Duration) error
SetRuleDebounceDelay sets the debounce delay for a specific rule
func (*OrchestratorV2) SetRuleVerbose ¶
func (o *OrchestratorV2) SetRuleVerbose(ruleName string, verbose bool) error
SetRuleVerbose sets the verbose flag for a specific rule
func (*OrchestratorV2) SetVerbose ¶
func (o *OrchestratorV2) SetVerbose(verbose bool)
SetVerbose sets the global verbose flag
func (*OrchestratorV2) Start ¶
func (o *OrchestratorV2) Start() error
Start begins file watching and initializes all RuleRunners
func (*OrchestratorV2) Stop ¶
func (o *OrchestratorV2) Stop() error
Stop gracefully shuts down the orchestrator
func (*OrchestratorV2) StreamLogs ¶
func (o *OrchestratorV2) StreamLogs(ruleName string, filter string, stream pb.GatewayClientService_StreamLogsClientServer) error
StreamLogs streams the logs for a given rule to the provided gRPC stream
func (*OrchestratorV2) TriggerRule ¶
func (o *OrchestratorV2) TriggerRule(ruleName string) error
TriggerRule manually triggers the execution of a specific rule
type PrefixWriter ¶
type PrefixWriter struct {
// contains filtered or unexported fields
}
PrefixWriter is an io.Writer that adds a prefix to each line of output.
type RuleRunner ¶
type RuleRunner interface {
// Lifecycle management
Start() error // Start monitoring and execution
Stop() error // Stop all processes and cleanup
Restart() error // Restart all processes
Execute() error // Execute the rule's commands
// Status and state
IsRunning() bool
GetStatus() *gateway.RuleStatus
GetRule() gateway.Rule
// Debouncing
TriggerDebounced() // Called when a file change is detected
// Process management
TerminateProcesses() error
// Configuration
SetDebounceDelay(duration time.Duration)
SetVerbose(verbose bool)
}
RuleRunner manages the execution lifecycle of a single rule
func NewRuleRunner ¶
func NewRuleRunner(rule gateway.Rule, orchestrator *OrchestratorV2) RuleRunner
NewRuleRunner creates a new RuleRunner for the given rule