config

package
v0.7.9 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package config contains configuration types for agnt.

Package config provides port detection for auto-started scripts.

Index

Constants

View Source
const (
	GlobalConfigFile  = "config.kdl"
	ProjectConfigFile = ".agnt.kdl"
)

KDL configuration file names

View Source
const AgntConfigFileName = ".agnt.kdl"

AgntConfigFileName is the name of the agnt configuration file.

Variables

This section is empty.

Functions

func FindAgntConfigFile added in v0.7.8

func FindAgntConfigFile(dir string) string

FindAgntConfigFile searches for .agnt.kdl starting from dir and walking up.

func GlobalConfigPath

func GlobalConfigPath() string

GlobalConfigPath returns the path to the global config file.

func WriteDefaultAgntConfig added in v0.7.8

func WriteDefaultAgntConfig(path string) error

WriteDefaultAgntConfig writes a default configuration file with documentation.

func WriteDefaultConfig

func WriteDefaultConfig(path string) error

WriteDefaultConfig writes a default config file with documentation.

Types

type AgntConfig added in v0.7.8

type AgntConfig struct {
	// Scripts to manage
	Scripts map[string]*ScriptConfig `kdl:"scripts"`

	// Proxies to manage
	Proxies map[string]*ProxyConfig `kdl:"proxies"`

	// Hooks configuration
	Hooks *HooksConfig `kdl:"hooks"`

	// Toast notification settings
	Toast *ToastConfig `kdl:"toast"`
}

AgntConfig represents the agnt configuration.

func DefaultAgntConfig added in v0.7.8

func DefaultAgntConfig() *AgntConfig

DefaultAgntConfig returns a config with sensible defaults.

func LoadAgntConfig added in v0.7.8

func LoadAgntConfig(dir string) (*AgntConfig, error)

LoadAgntConfig loads configuration from the specified directory. It looks for .agnt.kdl in the directory and its parents.

func LoadAgntConfigFile added in v0.7.8

func LoadAgntConfigFile(path string) (*AgntConfig, error)

LoadAgntConfigFile loads configuration from a specific file.

func ParseAgntConfig added in v0.7.8

func ParseAgntConfig(data string) (*AgntConfig, error)

ParseAgntConfig parses KDL configuration data. It tries kdl-go first, then falls back to a simpler regex parser for formats like: scripts { dev auto-start=true } proxy "dev" { script "dev" }

func (*AgntConfig) GetAutostartProxies added in v0.7.8

func (c *AgntConfig) GetAutostartProxies() map[string]*ProxyConfig

GetAutostartProxies returns proxies configured for autostart.

func (*AgntConfig) GetAutostartScripts added in v0.7.8

func (c *AgntConfig) GetAutostartScripts() map[string]*ScriptConfig

GetAutostartScripts returns scripts configured for autostart.

type CommandConfig

type CommandConfig struct {
	// Command is the executable name.
	Command string `json:"command"`
	// Args are the default arguments.
	Args []string `json:"args"`
	// Description is a human-readable description.
	Description string `json:"description,omitempty"`
	// Timeout is the command timeout in seconds.
	Timeout int `json:"timeout,omitempty"`
	// Persistent indicates this is a long-running process.
	Persistent bool `json:"persistent,omitempty"`
	// Env holds environment variables to set.
	Env map[string]string `json:"env,omitempty"`
}

CommandConfig holds configuration for a single command.

func (*CommandConfig) ToCommandDef

func (c *CommandConfig) ToCommandDef(name string) project.CommandDef

ToCommandDef converts a CommandConfig to a project.CommandDef.

type Config

type Config struct {
	// Version is the config file version.
	Version string `json:"version"`

	// Settings are global server settings.
	Settings Settings `json:"settings"`

	// Languages holds language-specific configurations.
	Languages map[string]LanguageConfig `json:"languages"`
}

Config holds the complete server configuration.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default configuration.

func LoadConfigFile

func LoadConfigFile(path string) (*Config, error)

LoadConfigFile loads configuration from a specific file path.

func LoadGlobalConfig

func LoadGlobalConfig() (*Config, error)

LoadGlobalConfig loads the global configuration from the default location.

func ParseKDLConfig

func ParseKDLConfig(data string) (*Config, error)

ParseKDLConfig parses KDL configuration data.

func (*Config) GetLanguageCommands

func (c *Config) GetLanguageCommands(lang string) []project.CommandDef

GetLanguageCommands returns command definitions for a language.

func (*Config) MergeProjectConfig

func (c *Config) MergeProjectConfig(projConfig *ProjectConfig) *Config

MergeProjectConfig merges per-project config with global config.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks the configuration for errors.

type HooksConfig added in v0.7.8

type HooksConfig struct {
	// OnResponse controls what happens when Claude responds
	OnResponse *ResponseHookConfig `kdl:"on-response"`
}

HooksConfig defines hook behavior.

type KDLCommand

type KDLCommand struct {
	Command    string            `kdl:"cmd"`
	Args       []string          `kdl:"args"`
	Timeout    int               `kdl:"timeout"`
	Persistent bool              `kdl:"persistent"`
	Env        map[string]string `kdl:"env"`
}

KDLCommand holds a command configuration.

type KDLConfig

type KDLConfig struct {
	Version   string       `kdl:"version"`
	Settings  KDLSettings  `kdl:"settings"`
	Languages KDLLanguages `kdl:"languages"`
}

KDLConfig represents the KDL configuration structure. Uses kdl struct tags for unmarshaling.

type KDLLanguage

type KDLLanguage struct {
	Markers              []string               `kdl:"markers"`
	Priority             int                    `kdl:"priority"`
	PackageManagerDetect bool                   `kdl:"package-manager-detect"`
	Commands             map[string]*KDLCommand `kdl:"commands"`
}

KDLLanguage holds configuration for a specific language.

type KDLLanguages

type KDLLanguages struct {
	Go     *KDLLanguage `kdl:"go"`
	Node   *KDLLanguage `kdl:"node"`
	Python *KDLLanguage `kdl:"python"`
}

KDLLanguages holds language configurations.

type KDLProjectConfig

type KDLProjectConfig struct {
	Language       string                 `kdl:"language"`
	PackageManager string                 `kdl:"package-manager"`
	Commands       map[string]*KDLCommand `kdl:"commands"`
}

KDLProjectConfig holds per-project configuration.

type KDLSettings

type KDLSettings struct {
	DefaultTimeout  int `kdl:"default-timeout"`
	MaxOutputBuffer int `kdl:"max-output-buffer"`
	GracefulTimeout int `kdl:"graceful-timeout"`
}

KDLSettings holds global settings from KDL.

type LanguageConfig

type LanguageConfig struct {
	// Markers are files that identify this project type.
	Markers []string `json:"markers"`
	// Priority determines detection order (higher = first).
	Priority int `json:"priority"`
	// Commands are the available commands for this language.
	Commands map[string]CommandConfig `json:"commands"`
	// PackageManagerDetect enables automatic package manager detection (Node.js).
	PackageManagerDetect bool `json:"package_manager_detect,omitempty"`
}

LanguageConfig holds configuration for a specific language.

type PortDetector added in v0.7.8

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

PortDetector detects listening ports from processes.

func NewPortDetector added in v0.7.8

func NewPortDetector() *PortDetector

NewPortDetector creates a new port detector with common patterns.

func (*PortDetector) DetectFromOutput added in v0.7.8

func (pd *PortDetector) DetectFromOutput(output string) int

DetectFromOutput scans output text for port patterns. Returns the first port found, or 0 if none detected.

func (*PortDetector) DetectFromPID added in v0.7.8

func (pd *PortDetector) DetectFromPID(ctx context.Context, pid int) []int

DetectFromPID finds listening TCP ports for a process using ss or lsof. Returns all detected ports.

func (*PortDetector) WaitForPort added in v0.7.8

func (pd *PortDetector) WaitForPort(ctx context.Context, pid int, getOutput func() string, timeout time.Duration) int

WaitForPort waits for a port to be detected, either from output or PID. Returns the detected port or 0 if timeout expires.

type ProjectConfig

type ProjectConfig struct {
	// Language overrides the detected language.
	Language string `json:"language,omitempty"`
	// PackageManager overrides the detected package manager.
	PackageManager string `json:"package_manager,omitempty"`
	// Commands override default commands.
	Commands map[string]CommandConfig `json:"commands,omitempty"`
}

ProjectConfig holds per-project configuration from .agnt.kdl.

func LoadProjectConfig

func LoadProjectConfig(projectPath string) (*ProjectConfig, error)

LoadProjectConfig loads per-project configuration from .agnt.kdl.

func ParseProjectConfig

func ParseProjectConfig(data string) (*ProjectConfig, error)

ParseProjectConfig parses per-project KDL configuration.

type ProxyConfig added in v0.7.8

type ProxyConfig struct {
	// Target is the explicit target URL (e.g., "http://localhost:3000")
	Target string `kdl:"target"`
	// Port is the proxy listen port (0 = auto-assign)
	Port int `kdl:"port"`
	// Autostart indicates whether to start on session open
	Autostart bool `kdl:"autostart"`
	// MaxLogSize is the max number of log entries to keep
	MaxLogSize int `kdl:"max-log-size"`

	// Script links this proxy to a script for port detection
	Script string `kdl:"script"`
	// PortDetect is the detection mode: "auto", "output", "pid", or a regex pattern
	PortDetect string `kdl:"port-detect"`
	// FallbackPort is used if port detection fails
	FallbackPort int `kdl:"fallback-port"`
	// Host is the target host (default: localhost)
	Host string `kdl:"host"`
}

ProxyConfig defines a reverse proxy to start.

type ResponseHookConfig added in v0.7.8

type ResponseHookConfig struct {
	// Toast shows a toast notification in the browser
	Toast bool `kdl:"toast"`
	// Indicator updates the bug indicator
	Indicator bool `kdl:"indicator"`
	// Sound plays a notification sound
	Sound bool `kdl:"sound"`
}

ResponseHookConfig controls response notification behavior.

type ScriptConfig added in v0.7.8

type ScriptConfig struct {
	Command   string            `kdl:"command"`
	Args      []string          `kdl:"args"`
	Autostart bool              `kdl:"autostart"`
	Env       map[string]string `kdl:"env"`
	Cwd       string            `kdl:"cwd"`
}

ScriptConfig defines a script to run.

type Settings

type Settings struct {
	// DefaultTimeout is the default process timeout.
	DefaultTimeout time.Duration `json:"default_timeout"`
	// MaxOutputBuffer is the per-stream output buffer size.
	MaxOutputBuffer int `json:"max_output_buffer"`
	// GracefulTimeout is the graceful shutdown timeout.
	GracefulTimeout time.Duration `json:"graceful_timeout"`
}

Settings holds global configuration settings.

type ToastConfig added in v0.7.8

type ToastConfig struct {
	// Duration in milliseconds (default 4000)
	Duration int `kdl:"duration"`
	// Position: "top-right", "top-left", "bottom-right", "bottom-left"
	Position string `kdl:"position"`
	// MaxVisible is the max number of visible toasts (default 3)
	MaxVisible int `kdl:"max-visible"`
}

ToastConfig configures toast notifications.

Jump to

Keyboard shortcuts

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