config

package
v0.12.13 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: Apache-2.0 Imports: 14 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.

View Source
const DefaultDependencyTimeout = 30 * time.Second

DefaultDependencyTimeout is the default timeout for script dependencies.

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 TopologicalSort added in v0.12.8

func TopologicalSort(scripts map[string]*ScriptConfig) ([][]string, error)

TopologicalSort sorts scripts into execution layers based on their dependencies. Returns layers where each layer's scripts can run in parallel, and all dependencies from prior layers are satisfied. Returns an error if a circular dependency is detected.

func ValidateDependencies added in v0.12.8

func ValidateDependencies(scripts map[string]*ScriptConfig) (warnings []string, err error)

ValidateDependencies checks dependency configuration for errors and warnings. Returns an error for fatal issues (unknown deps, cycles) and a list of warning messages for non-fatal issues (deps on non-autostart scripts).

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 AIConfig added in v0.11.4

type AIConfig struct {
	// Skill is a skill/persona name to use (e.g., "code-review", "debugging")
	Skill string `kdl:"skill"`
	// Env are environment variables to set for AI commands
	Env map[string]string `kdl:"env"`
	// SystemPrompt is a full system prompt that replaces the default
	SystemPrompt string `kdl:"system-prompt"`
	// AppendSystemPrompt is appended to the default system prompt
	AppendSystemPrompt string `kdl:"append-system-prompt"`
}

AIConfig configures AI agent behavior for run and ai commands.

type AgntConfig added in v0.7.8

type AgntConfig struct {
	// Project metadata (optional, for documentation/info only)
	Project *AgntProjectMeta `kdl:"project"`

	// Scripts to manage
	Scripts map[string]*ScriptConfig `kdl:"scripts"`

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

	// AI configuration for run and ai commands
	AI *AIConfig `kdl:"ai"`

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

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

	// Alerts configuration for process output monitoring
	Alerts *AlertsConfig `kdl:"alerts"`
}

AgntConfig represents the agnt configuration. All fields use standard KDL format with child nodes.

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 using the official kdl-go parser. Only standard KDL format is supported.

func (*AgntConfig) BuildSystemPrompt added in v0.11.4

func (c *AgntConfig) BuildSystemPrompt() string

BuildSystemPrompt generates the system prompt based on configuration. If SystemPrompt is set, it returns that directly. Otherwise, it builds a prompt describing agnt features and configured services, then appends AppendSystemPrompt if set.

func (*AgntConfig) GetAutostartProxies added in v0.7.8

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

GetAutostartProxies returns proxies that should auto-start.

func (*AgntConfig) GetAutostartScripts added in v0.7.8

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

GetAutostartScripts returns scripts configured for autostart.

type AgntProjectMeta added in v0.11.1

type AgntProjectMeta struct {
	Type string `kdl:"type"`
	Name string `kdl:"name"`
}

AgntProjectMeta contains optional project metadata in .agnt.kdl. This is informational only and doesn't affect behavior.

type AlertPatternConfig added in v0.11.5

type AlertPatternConfig struct {
	// Pattern is a regular expression to match against output lines.
	Pattern string `kdl:"pattern"`

	// Severity is "error", "warning", or "info".
	Severity string `kdl:"severity"`
}

AlertPatternConfig defines a custom alert pattern in configuration.

type AlertsConfig added in v0.11.5

type AlertsConfig struct {
	// Enabled controls whether alerts are active. Default: true.
	Enabled *bool `kdl:"enabled"`

	// Patterns defines custom alert patterns keyed by ID.
	Patterns map[string]*AlertPatternConfig `kdl:"patterns"`

	// Disable is a list of built-in pattern IDs to disable.
	Disable []string `kdl:"disable"`

	// BatchWindow is the batching window in seconds before delivering alerts.
	// Default: 3.
	BatchWindow int `kdl:"batch-window"`

	// DedupeWindow is the deduplication window in seconds.
	// Duplicate alerts within this window are suppressed. Default: 60.
	DedupeWindow int `kdl:"dedupe-window"`
}

AlertsConfig configures process output alert monitoring.

func (*AlertsConfig) IsEnabled added in v0.11.5

func (c *AlertsConfig) IsEnabled() bool

IsEnabled returns whether alerts are enabled (defaults to true).

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 DependsOnList added in v0.12.8

type DependsOnList []ScriptDependency

DependsOnList is a list of script dependencies with custom KDL unmarshaling. Supports two KDL formats:

Arguments format (all deps get default or node-level timeout):

depends-on "api" "redis"
depends-on "api" timeout=45

Child node format (per-dependency timeouts):

depends-on {
    api timeout=30
    redis timeout=60
}

func (*DependsOnList) UnmarshalKDL added in v0.12.8

func (d *DependsOnList) UnmarshalKDL(node *document.Node) error

UnmarshalKDL implements the kdl.Unmarshaler interface for custom parsing.

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 {
	// Autostart starts the proxy when session opens
	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 URL detection from output
	Script string `kdl:"script"`
	// URLPattern filters which detected URLs should trigger this proxy.
	// Regex pattern matched against detected URLs. Use to select specific ports
	// when a script outputs multiple URLs (e.g., ":34115" to match Wails backend).
	URLPattern string `kdl:"url-pattern"`

	// URL is the full target URL (e.g., "http://localhost:3000")
	URL string `kdl:"url"`
	// Target is the backend URL (deprecated, use URL instead)
	Target string `kdl:"target"`
	// Port is the target port - shorthand for http://localhost:PORT
	Port int `kdl:"port"`
	// FallbackPort is used when script URL detection fails
	FallbackPort int `kdl:"fallback-port"`
	// Host is the target host (default: localhost)
	Host string `kdl:"host"`

	// Bind is the address the proxy listens on
	// "127.0.0.1" (default) or "0.0.0.0" (all interfaces)
	Bind string `kdl:"bind"`

	// Websocket enables WebSocket proxying
	Websocket bool `kdl:"websocket"`
}

ProxyConfig defines a reverse proxy to start.

func (*ProxyConfig) HasExplicitTarget added in v0.11.5

func (p *ProxyConfig) HasExplicitTarget() bool

HasExplicitTarget returns true if the proxy has an explicitly configured target (URL, Target, or Port) rather than being linked to a script for URL detection.

func (*ProxyConfig) ShouldAutostart added in v0.11.5

func (p *ProxyConfig) ShouldAutostart() bool

ShouldAutostart returns true if this proxy should start automatically. A proxy auto-starts if Autostart is explicitly true, or if it has an explicit target (URL/Target/Port) without being script-linked (script-linked proxies are created automatically when URLs are detected in script output).

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 {
	// Run is a shell command string (executed via platform shell)
	// On Unix: sh -c "..."
	// On Windows: cmd.exe /c "..."
	// Override with Shell field
	Run string `kdl:"run"`
	// Command is the executable name (used with Args)
	Command string `kdl:"command"`
	// Args are command arguments (used with Command)
	Args []string `kdl:"args"`
	// Shell overrides the shell used for "run" commands.
	// Examples: "bash", "powershell", "cmd.exe", "sh"
	// If empty, uses platform default (sh on Unix, cmd.exe on Windows)
	Shell string `kdl:"shell"`
	// ShellArgs overrides the shell arguments. Default: ["-c"] for sh/bash, ["/c"] for cmd.exe
	ShellArgs []string `kdl:"shell-args"`
	// Autostart starts the script when session opens
	Autostart bool `kdl:"autostart"`
	// URLMatchers are patterns for URL detection in output
	URLMatchers []string `kdl:"url-matchers"`
	// Env are environment variables for the script
	Env map[string]string `kdl:"env"`
	// Cwd is the working directory for the script
	Cwd string `kdl:"cwd"`
	// DependsOn lists scripts that must be ready before this script starts.
	DependsOn DependsOnList `kdl:"depends-on"`
}

ScriptConfig defines a script to run.

func (*ScriptConfig) ResolveShell added in v0.12.1

func (s *ScriptConfig) ResolveShell() (shell string, shellArgs []string)

ResolveShell returns the shell command and arguments for executing a "run" command. Priority: explicit Shell/ShellArgs config > platform default.

type ScriptDependency added in v0.12.8

type ScriptDependency struct {
	// Name is the name of the script this depends on.
	Name string
	// Timeout is how long to wait for the dependency to become ready.
	Timeout time.Duration
}

ScriptDependency represents a dependency on another script.

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