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 ¶
- func ConvertAirToml(inputPath string) error
- type AirConfig
- type BuildConfig
- type ColorConfig
- type Config
- type GatewayService
- func (gs *GatewayService) Communicate(stream pb.DevloopGatewayService_CommunicateServer) error
- func (gs *GatewayService) GetConfig(ctx context.Context, req *pb.GetConfigRequest) (*pb.GetConfigResponse, error)
- func (gs *GatewayService) GetHistoricalLogsClient(req *pb.GetHistoricalLogsClientRequest, ...) error
- func (gs *GatewayService) GetRuleStatus(ctx context.Context, req *pb.GetRuleStatusRequest) (*pb.GetRuleStatusResponse, error)
- func (gs *GatewayService) ListProjects(ctx context.Context, req *pb.ListProjectsRequest) (*pb.ListProjectsResponse, error)
- func (gs *GatewayService) ListWatchedPaths(ctx context.Context, req *pb.ListWatchedPathsRequest) (*pb.ListWatchedPathsResponse, error)
- func (gs *GatewayService) MountMCPHandlers(mcpHandler http.Handler)
- func (gs *GatewayService) ReadFileContent(ctx context.Context, req *pb.ReadFileContentRequest) (*pb.ReadFileContentResponse, error)
- func (gs *GatewayService) Start(grpcPort int, httpPort int) error
- func (gs *GatewayService) Stop()
- func (gs *GatewayService) StreamLogsClient(req *pb.StreamLogsClientRequest, ...) error
- func (gs *GatewayService) TriggerRuleClient(ctx context.Context, req *pb.TriggerRuleClientRequest) (*pb.TriggerRuleClientResponse, error)
- type LogConfig
- type Matcher
- type MiscConfig
- type Orchestrator
- type ProjectInstance
- type Rule
- type RuleStatus
- type Settings
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertAirToml ¶ added in v0.0.30
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 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 ¶
func (gs *GatewayService) Communicate(stream pb.DevloopGatewayService_CommunicateServer) error
Communicate implements pb.DevloopGatewayServiceServer.
func (*GatewayService) GetConfig ¶
func (gs *GatewayService) GetConfig(ctx context.Context, req *pb.GetConfigRequest) (*pb.GetConfigResponse, error)
GetConfig implements pb.GatewayClientServiceServer.
func (*GatewayService) GetHistoricalLogsClient ¶
func (gs *GatewayService) GetHistoricalLogsClient(req *pb.GetHistoricalLogsClientRequest, stream pb.GatewayClientService_GetHistoricalLogsClientServer) error
GetHistoricalLogsClient implements pb.GatewayClientServiceServer.
func (*GatewayService) GetRuleStatus ¶
func (gs *GatewayService) GetRuleStatus(ctx context.Context, req *pb.GetRuleStatusRequest) (*pb.GetRuleStatusResponse, error)
GetRuleStatus implements pb.GatewayClientServiceServer.
func (*GatewayService) ListProjects ¶ added in v0.0.32
func (gs *GatewayService) ListProjects(ctx context.Context, req *pb.ListProjectsRequest) (*pb.ListProjectsResponse, error)
ListProjects implements pb.GatewayClientServiceServer.
func (*GatewayService) ListWatchedPaths ¶
func (gs *GatewayService) ListWatchedPaths(ctx context.Context, req *pb.ListWatchedPathsRequest) (*pb.ListWatchedPathsResponse, error)
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 ¶
func (gs *GatewayService) ReadFileContent(ctx context.Context, req *pb.ReadFileContentRequest) (*pb.ReadFileContentResponse, error)
ReadFileContent implements pb.GatewayClientServiceServer.
func (*GatewayService) Stop ¶
func (gs *GatewayService) Stop()
func (*GatewayService) StreamLogsClient ¶
func (gs *GatewayService) StreamLogsClient(req *pb.StreamLogsClientRequest, stream pb.GatewayClientService_StreamLogsClientServer) error
StreamLogsClient implements pb.GatewayClientServiceServer.
func (*GatewayService) TriggerRuleClient ¶
func (gs *GatewayService) TriggerRuleClient(ctx context.Context, req *pb.TriggerRuleClientRequest) (*pb.TriggerRuleClientResponse, error)
TriggerRuleClient implements pb.GatewayClientServiceServer.
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.
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
GetColor returns the rule color (implements ColorRule interface)
func (*Rule) GetName ¶ added in v0.0.30
GetName returns the rule name (implements Nameable interface for color generation)
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
GetColorLogs returns whether color logs are enabled (implements ColorSettings interface)
func (*Settings) GetColorScheme ¶ added in v0.0.30
GetColorScheme returns the color scheme (implements ColorSettings interface)
func (*Settings) GetCustomColors ¶ added in v0.0.30
GetCustomColors returns the custom color mappings (implements ColorSettings interface)