agent

package
v0.0.20 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2025 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadConfig

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

LoadConfig reads and unmarshals the .devloop.yaml configuration file, resolving all relative watch paths to be absolute from the config file's location.

Types

type LogManager

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

LogManager manages log files and provides streaming capabilities.

func NewLogManager

func NewLogManager(logDir string) (*LogManager, error)

NewLogManager creates a new LogManager instance.

func (*LogManager) Close

func (lm *LogManager) Close() error

Close closes all open file handles managed by the LogManager.

func (*LogManager) GetWriter

func (lm *LogManager) GetWriter(ruleName string) (io.Writer, error)

GetWriter returns an io.Writer for a specific rule's log file. It also signals that the rule's execution has started.

func (*LogManager) SignalFinished

func (lm *LogManager) SignalFinished(ruleName string)

SignalFinished signals that a rule's execution has finished.

func (*LogManager) StreamLogs

func (lm *LogManager) StreamLogs(ruleName, filter string, stream pb.GatewayClientService_StreamLogsClientServer) error

StreamLogs streams logs for a given rule to the provided gRPC stream.

type Orchestrator

type Orchestrator struct {
	ConfigPath string
	Config     *gateway.Config
	Verbose    bool
	Watcher    *fsnotify.Watcher
	LogManager *LogManager // New field for log management
	// contains filtered or unexported fields
}

Orchestrator manages file watching and rule execution.

func NewOrchestrator

func NewOrchestrator(configPath string, gatewayAddr string) (*Orchestrator, error)

NewOrchestrator creates a new Orchestrator instance.

func (*Orchestrator) GetConfig

func (o *Orchestrator) GetConfig() *gateway.Config

GetConfig returns the orchestrator's configuration.

func (*Orchestrator) GetRuleStatus

func (o *Orchestrator) GetRuleStatus(ruleName string) (*gateway.RuleStatus, bool)

GetRuleStatus returns the current status of a specific rule.

func (*Orchestrator) GetWatchedPaths

func (o *Orchestrator) GetWatchedPaths() []string

GetWatchedPaths returns a unique list of all paths being watched by any rule.

func (*Orchestrator) ProjectRoot

func (o *Orchestrator) ProjectRoot() string

func (*Orchestrator) ReadFileContent

func (o *Orchestrator) ReadFileContent(path string) ([]byte, error)

ReadFileContent reads and returns the content of a specified file.

func (*Orchestrator) SetGlobalDebounceDelay

func (o *Orchestrator) SetGlobalDebounceDelay(duration time.Duration)

SetGlobalDebounceDelay sets the default debounce delay for all rules

func (*Orchestrator) SetRuleDebounceDelay

func (o *Orchestrator) SetRuleDebounceDelay(ruleName string, duration time.Duration) error

SetRuleDebounceDelay sets the debounce delay for a specific rule

func (*Orchestrator) SetRuleVerbose

func (o *Orchestrator) SetRuleVerbose(ruleName string, verbose bool) error

SetRuleVerbose sets the verbose flag for a specific rule

func (*Orchestrator) SetVerbose

func (o *Orchestrator) SetVerbose(verbose bool)

SetVerbose sets the global verbose flag

func (*Orchestrator) Start

func (o *Orchestrator) Start() error

Start begins the file watching and command execution loop.

func (*Orchestrator) Stop

func (o *Orchestrator) Stop() error

Stop gracefully shuts down the orchestrator.

func (*Orchestrator) StreamLogs

func (o *Orchestrator) StreamLogs(ruleName string, filter string, stream pb.GatewayClientService_StreamLogsClientServer) error

StreamLogs streams the logs for a given rule to the provided gRPC stream.

func (*Orchestrator) TriggerRule

func (o *Orchestrator) TriggerRule(ruleName string) error

TriggerRule manually triggers the execution of a specific rule.

type OrchestratorInterface

type OrchestratorInterface interface {
	Start() error
	Stop() error
	GetConfig() *gateway.Config
	GetRuleStatus(ruleName string) (*gateway.RuleStatus, bool)
	TriggerRule(ruleName string) error
	GetWatchedPaths() []string
	ReadFileContent(path string) ([]byte, error)
	StreamLogs(ruleName string, filter string, stream pb.GatewayClientService_StreamLogsClientServer) error
	ProjectRoot() string

	// Configuration methods
	SetGlobalDebounceDelay(duration time.Duration)
	SetRuleDebounceDelay(ruleName string, duration time.Duration) error
	SetVerbose(verbose bool)
	SetRuleVerbose(ruleName string, verbose bool) error
}

OrchestratorInterface defines the common interface for both orchestrator implementations. This allows tests to work with either version.

func NewOrchestratorForTesting

func NewOrchestratorForTesting(configPath string, gatewayAddr string) (OrchestratorInterface, error)

NewOrchestratorForTesting creates an orchestrator based on the DEVLOOP_ORCHESTRATOR_VERSION environment variable. If DEVLOOP_ORCHESTRATOR_VERSION=v1, it returns the original Orchestrator, otherwise it returns OrchestratorV2. This is used by tests to verify both implementations work correctly.

type OrchestratorV2

type OrchestratorV2 struct {
	ConfigPath string
	Config     *gateway.Config
	Verbose    bool
	Watcher    *fsnotify.Watcher
	LogManager *LogManager
	// 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 using RuleRunners

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.

func (*PrefixWriter) Write

func (pw *PrefixWriter) Write(p []byte) (n int, err error)

Write implements the io.Writer interface.

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 *Orchestrator) RuleRunner

NewRuleRunner creates a new RuleRunner for the given rule

Jump to

Keyboard shortcuts

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