agent

package
v0.0.37 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2025 License: Apache-2.0 Imports: 23 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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 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.

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 *OrchestratorV2) 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