gateway

package
v0.0.35 Latest Latest
Warning

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

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

Documentation

Overview

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 ConvertAirToml added in v0.0.30

func ConvertAirToml(inputPath string) error

Types

type AirConfig added in v0.0.30

type AirConfig struct {
	Root   string      `toml:"root"`
	TmpDir string      `toml:"tmp_dir"`
	Build  BuildConfig `toml:"build"`
	Log    LogConfig   `toml:"log"`
	Misc   MiscConfig  `toml:"misc"`
	Color  ColorConfig `toml:"color"`
}

AirConfig represents the structure of a .air.toml file.

type BuildConfig added in v0.0.30

type BuildConfig struct {
	Cmd          string   `toml:"cmd"`
	Bin          string   `toml:"bin"`
	PreCmd       []string `toml:"pre_cmd"`
	PostCmd      []string `toml:"post_cmd"`
	IncludeExt   []string `toml:"include_ext"`
	ExcludeDir   []string `toml:"exclude_dir"`
	ExcludeFile  []string `toml:"exclude_file"`
	IncludeDir   []string `toml:"include_dir"`
	ExcludeRegex []string `toml:"exclude_regex"`
	StopOnError  bool     `toml:"stop_on_error"`
	Delay        int      `toml:"delay"`
}

type ColorConfig added in v0.0.30

type ColorConfig struct {
	Main    string `toml:"main"`
	Watcher string `toml:"watcher"`
	Build   string `toml:"build"`
	Runner  string `toml:"runner"`
}

type Config

type Config struct {
	Settings Settings `yaml:"settings"`
	Rules    []Rule   `yaml:"rules"`
}

Config represents the top-level structure of the .devloop.yaml file.

type GatewayService

type GatewayService struct {
	pb.UnimplementedDevloopGatewayServiceServer // Embed for forward compatibility
	pb.UnimplementedGatewayClientServiceServer  // Embed for forward compatibility
	// contains filtered or unexported fields
}

GatewayService manages registered devloop instances and proxies requests.

func NewGatewayService

func NewGatewayService(orchestrator Orchestrator) *GatewayService

NewGatewayService creates a new gateway service for managing multiple devloop agents.

The gateway service acts as a central hub that: - Accepts connections from multiple devloop agents - Provides unified gRPC and HTTP APIs for external clients - Manages project registration and status tracking - Handles real-time communication with connected agents

The orchestrator parameter is used for the gateway's own configuration and logging, while connected agents provide their own orchestration.

Example:

orchestrator := agent.NewOrchestratorV2("gateway.yaml", "")
gateway := NewGatewayService(orchestrator)
err := gateway.Start(50051, 8080)  // gRPC on 50051, HTTP on 8080

func (*GatewayService) Communicate

Communicate implements pb.DevloopGatewayServiceServer.

func (*GatewayService) GetConfig

GetConfig implements pb.GatewayClientServiceServer.

func (*GatewayService) GetHistoricalLogsClient

GetHistoricalLogsClient implements pb.GatewayClientServiceServer.

func (*GatewayService) GetRuleStatus

GetRuleStatus implements pb.GatewayClientServiceServer.

func (*GatewayService) ListProjects added in v0.0.32

ListProjects implements pb.GatewayClientServiceServer.

func (*GatewayService) ListWatchedPaths

ListWatchedPaths implements pb.GatewayClientServiceServer.

func (*GatewayService) MountMCPHandlers added in v0.0.34

func (gs *GatewayService) MountMCPHandlers(mcpHandler http.Handler)

MountMCPHandlers mounts MCP handlers at /mcp prefix

func (*GatewayService) ReadFileContent

ReadFileContent implements pb.GatewayClientServiceServer.

func (*GatewayService) Start

func (gs *GatewayService) Start(grpcPort int, httpPort int) error

func (*GatewayService) Stop

func (gs *GatewayService) Stop()

func (*GatewayService) StreamLogsClient

StreamLogsClient implements pb.GatewayClientServiceServer.

func (*GatewayService) TriggerRuleClient

TriggerRuleClient implements pb.GatewayClientServiceServer.

type LogConfig added in v0.0.30

type LogConfig struct {
	LogName        string `toml:"log_name"`
	RedirectOutput bool   `toml:"redirect_output"`
}

type Matcher

type Matcher struct {
	Action   string   `yaml:"action"` // Should be "include" or "exclude"
	Patterns []string `yaml:"patterns"`
}

Matcher defines a single include or exclude directive using glob patterns.

func (*Matcher) Matches

func (m *Matcher) Matches(filePath string) bool

type MiscConfig added in v0.0.30

type MiscConfig struct {
	CleanOnExit bool `toml:"clean_on_exit"`
}

type Orchestrator

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

Orchestrator is an interface that defines the methods that the gateway service needs to interact with the orchestrator.

type ProjectInstance

type ProjectInstance struct {
	ProjectID   string `json:"project_id"`
	ProjectRoot string `json:"project_root"`
	// contains filtered or unexported fields
}

ProjectInstance represents a registered devloop instance.

type Rule

type Rule struct {
	Name          string            `yaml:"name"`
	Prefix        string            `yaml:"prefix,omitempty"`
	Commands      []string          `yaml:"commands"`
	Watch         []*Matcher        `yaml:"watch"`
	Env           map[string]string `yaml:"env,omitempty"`
	WorkDir       string            `yaml:"workdir,omitempty"`
	RunOnInit     *bool             `yaml:"run_on_init,omitempty"`
	DebounceDelay *time.Duration    `yaml:"debounce_delay,omitempty"`
	Verbose       *bool             `yaml:"verbose,omitempty"`
	Color         string            `yaml:"color,omitempty"`
	DefaultAction string            `yaml:"default_action,omitempty"` // "include" or "exclude"
}

Rule defines a single watch-and-run rule.

func (*Rule) GetColor added in v0.0.30

func (r *Rule) GetColor() string

GetColor returns the rule color (implements ColorRule interface)

func (*Rule) GetName added in v0.0.30

func (r *Rule) GetName() string

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

func (*Rule) GetPrefix added in v0.0.30

func (r *Rule) GetPrefix() string

GetPrefix returns the rule prefix (implements ColorRule interface)

func (*Rule) Matches

func (r *Rule) Matches(filePath string) *Matcher

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

type RuleStatus

type RuleStatus struct {
	ProjectID       string    `json:"project_id"`
	RuleName        string    `json:"rule_name"`
	IsRunning       bool      `json:"is_running"`
	StartTime       time.Time `json:"start_time,omitempty"`
	LastBuildTime   time.Time `json:"last_build_time,omitempty"`
	LastBuildStatus string    `json:"last_build_status,omitempty"` // e.g., "SUCCESS", "FAILED", "IDLE"
}

RuleStatus defines the status of a rule.

type Settings

type Settings struct {
	ProjectID            string            `yaml:"project_id,omitempty"`
	PrefixLogs           bool              `yaml:"prefix_logs"`
	PrefixMaxLength      int               `yaml:"prefix_max_length"`
	DefaultDebounceDelay *time.Duration    `yaml:"default_debounce_delay,omitempty"`
	Verbose              bool              `yaml:"verbose,omitempty"`
	ColorLogs            bool              `yaml:"color_logs,omitempty"`
	ColorScheme          string            `yaml:"color_scheme,omitempty"`
	CustomColors         map[string]string `yaml:"custom_colors,omitempty"`
	DefaultWatchAction   string            `yaml:"default_watch_action,omitempty"` // "include" or "exclude"
}

Settings defines global settings for devloop.

func (*Settings) GetColorLogs added in v0.0.30

func (s *Settings) GetColorLogs() bool

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

func (*Settings) GetColorScheme added in v0.0.30

func (s *Settings) GetColorScheme() string

GetColorScheme returns the color scheme (implements ColorSettings interface)

func (*Settings) GetCustomColors added in v0.0.30

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