agent

package
v0.0.42 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2025 License: Apache-2.0 Imports: 24 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() *pb.Config
	TriggerRule(ruleName string) error
	GetRuleStatus(ruleName string) (*pb.RuleStatus, bool)
	GetWatchedPaths() []string
	ReadFileContent(path string) ([]byte, error)
	StreamLogs(ruleName string, filter string, stream pb.AgentService_StreamLogsClientServer) error
	SetGlobalDebounceDelay(duration time.Duration)
	SetVerbose(verbose bool)
}

Usage

Create and start an orchestrator:

orchestrator := agent.NewOrchestrator("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 ."

Package gateway provides the central hub for managing multiple devloop agents.

The gateway package implements a distributed architecture where multiple devloop agents can connect to a central gateway service. This enables: - Centralized monitoring of multiple projects - Unified API access to all connected agents - Cross-project coordination and management

Gateway Service

The gateway service provides both gRPC and HTTP endpoints for: - Agent registration and communication - Client API access for external tools - Real-time log streaming - Project status monitoring

Usage

Start a gateway service:

gateway := gateway.NewGatewayService(orchestrator)
if err := gateway.Start(grpcPort, httpPort); err != nil {
	log.Fatal(err)
}
defer gateway.Stop()

Connect agents to the gateway:

devloop --mode agent --gateway-addr localhost:50051 -c project-a/.devloop.yaml
devloop --mode agent --gateway-addr localhost:50051 -c project-b/.devloop.yaml

Configuration Types

The package defines configuration structures for devloop projects: - Config: Main configuration structure - Rule: Individual automation rules - WatchConfig: File watching patterns - Settings: Global project settings

Example Gateway Setup

// Start the central gateway
devloop --mode gateway --http-port 8080 --grpc-port 50051

// Connect individual project agents
cd project-a && devloop --mode agent --gateway-addr localhost:50051
cd project-b && devloop --mode agent --gateway-addr localhost:50051

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadConfig

func LoadConfig(configPath string) (*pb.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.

func MatcherMatches added in v0.0.42

func MatcherMatches(m *pb.RuleMatcher, filePath string) bool

func RuleMatches added in v0.0.42

func RuleMatches(r *pb.Rule, filePath string) *pb.RuleMatcher

Matches checks if the given file path matches the rule's watch criteria.

Types

type AgentService added in v0.0.42

type AgentService struct {
	protos.UnimplementedAgentServiceServer
	// contains filtered or unexported fields
}

func NewAgentService added in v0.0.42

func NewAgentService(orch *Orchestrator) *AgentService

func (*AgentService) GetConfig added in v0.0.42

func (s *AgentService) GetConfig(ctx context.Context, req *protos.GetConfigRequest) (resp *protos.GetConfigResponse, err error)

Get the configs of this agent

func (*AgentService) GetRule added in v0.0.42

func (s *AgentService) GetRule(ctx context.Context, req *protos.GetRuleRequest) (resp *protos.GetRuleResponse, err error)

func (*AgentService) ListWatchedPaths added in v0.0.42

func (s *AgentService) ListWatchedPaths(ctx context.Context, req *protos.ListWatchedPathsRequest) (resp *protos.ListWatchedPathsResponse, err error)

func (*AgentService) StreamLogs added in v0.0.42

func (*AgentService) TriggerRule added in v0.0.42

func (s *AgentService) TriggerRule(ctx context.Context, req *protos.TriggerRuleRequest) (resp *protos.TriggerRuleResponse, err error)

type Orchestrator

type Orchestrator struct {
	ConfigPath   string
	Config       *pb.Config
	Verbose      bool
	Watcher      *fsnotify.Watcher
	LogManager   *utils.LogManager
	ColorManager *utils.ColorManager
	// contains filtered or unexported fields
}

Orchestrator manages file watching and delegates execution to RuleRunners

func NewOrchestrator

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

NewOrchestrator 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 := NewOrchestrator(".devloop.yaml", "")

// Agent mode (connect to gateway)
orchestrator, err := NewOrchestrator(".devloop.yaml", "localhost:50051")

func NewOrchestratorForTesting

func NewOrchestratorForTesting(configPath string) (*Orchestrator, error)

NewOrchestratorForTesting creates a new V2 orchestrator for testing

func (*Orchestrator) GetConfig

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

GetConfig returns the orchestrator's configuration.

func (*Orchestrator) GetRuleStatus

func (o *Orchestrator) GetRuleStatus(ruleName string) (rule *pb.Rule, status *pb.RuleStatus, ok bool)

GetRuleStatus returns the 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

ProjectRoot returns the project root directory

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 file watching and initializes all RuleRunners

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) 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 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 Rule added in v0.0.42

type Rule struct {
	*pb.Rule
}

Rule defines a single watch-and-run rule.

func (*Rule) GetColor added in v0.0.42

func (r *Rule) GetColor() string

GetColor returns the rule color (implements ColorRule interface)

func (*Rule) GetName added in v0.0.42

func (r *Rule) GetName() string

GetName returns the rule name (implements Nameable interface for color generation)

func (*Rule) GetPrefix added in v0.0.42

func (r *Rule) GetPrefix() string

GetPrefix returns the rule prefix (implements ColorRule interface)

type RuleRunner

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

RuleRunner manages the execution lifecycle of a single rule

func NewRuleRunner

func NewRuleRunner(rule *pb.Rule, orchestrator *Orchestrator) *RuleRunner

NewRuleRunner creates a new RuleRunner for the given rule

func (*RuleRunner) Execute

func (r *RuleRunner) Execute() error

Execute runs the commands for this rule

func (*RuleRunner) GetRule

func (r *RuleRunner) GetRule() *pb.Rule

GetRule returns the rule configuration

func (*RuleRunner) GetStatus

func (r *RuleRunner) GetStatus() *pb.RuleStatus

GetStatus returns a copy of the current status

func (*RuleRunner) IsRunning

func (r *RuleRunner) IsRunning() bool

IsRunning returns true if any commands are currently running

func (*RuleRunner) Restart

func (r *RuleRunner) Restart() error

Restart stops and starts the rule

func (*RuleRunner) SetDebounceDelay

func (r *RuleRunner) SetDebounceDelay(duration time.Duration)

SetDebounceDelay sets the debounce delay for this rule

func (*RuleRunner) SetVerbose

func (r *RuleRunner) SetVerbose(verbose bool)

SetVerbose sets the verbose flag for this rule

func (*RuleRunner) Start

func (r *RuleRunner) Start() error

Start begins monitoring for this rule

func (*RuleRunner) Stop

func (r *RuleRunner) Stop() error

Stop terminates all processes and cleans up

func (*RuleRunner) TerminateProcesses

func (r *RuleRunner) TerminateProcesses() error

TerminateProcesses terminates all running processes for this rule

func (*RuleRunner) TriggerDebounced

func (r *RuleRunner) TriggerDebounced()

TriggerDebounced triggers execution after debounce period

type RuleStatus added in v0.0.42

type RuleStatus struct {
	*pb.RuleStatus
}

RuleStatus defines the status of a rule.

type Settings added in v0.0.42

type Settings struct {
	*pb.Settings
}

func (*Settings) GetColorLogs added in v0.0.42

func (s *Settings) GetColorLogs() bool

GetColorLogs returns whether color logs are enabled (implements ColorSettings interface)

func (*Settings) GetColorScheme added in v0.0.42

func (s *Settings) GetColorScheme() string

GetColorScheme returns the color scheme (implements ColorSettings interface)

func (*Settings) GetCustomColors added in v0.0.42

func (s *Settings) GetCustomColors() map[string]string

GetCustomColors returns the custom color mappings (implements ColorSettings interface)

Jump to

Keyboard shortcuts

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