feat(acp): supervisor skeleton + AcpConfig wiring

This commit is contained in:
2026-05-07 12:12:05 +08:00
parent dee20bb618
commit bd95fd33d6
3 changed files with 176 additions and 0 deletions
+33
View File
@@ -41,6 +41,7 @@ type Config struct {
Storage Storage `mapstructure:"storage"`
Jobs JobsConfig `mapstructure:"jobs"`
Notify NotifyConfig `mapstructure:"notify"`
Acp AcpConfig `mapstructure:"acp"`
}
// HTTPConfig 描述 HTTP 服务监听参数。
@@ -165,6 +166,24 @@ type WebhookCfg struct {
Topics []string `mapstructure:"topics"`
}
// AcpConfig 控制 ACP 模块的并发限流、子进程超时、WS 心跳与事件保留。
type AcpConfig struct {
Enabled bool `mapstructure:"enabled"`
MaxActiveGlobal int `mapstructure:"max_active_global"`
MaxActivePerUser int `mapstructure:"max_active_per_user"`
SpawnTimeout time.Duration `mapstructure:"spawn_timeout"`
KillGrace time.Duration `mapstructure:"kill_grace"`
StderrBufferLines int `mapstructure:"stderr_buffer_lines"`
StderrTailBytes int `mapstructure:"stderr_tail_bytes"`
WSPingInterval time.Duration `mapstructure:"ws_ping_interval"`
WSPongTimeout time.Duration `mapstructure:"ws_pong_timeout"`
WSSendBuffer int `mapstructure:"ws_send_buffer"`
EventMaxPayload int `mapstructure:"event_max_payload_bytes"`
EventTruncateField int `mapstructure:"event_truncate_field_bytes"`
EventRetentionDays int `mapstructure:"event_retention_days"`
ShutdownGrace time.Duration `mapstructure:"shutdown_grace"`
}
// Load 从(按优先级递增)默认值 → 配置文件(如有)→ 环境变量 加载配置。
// configFile 可为空字符串,仅用环境变量。
func Load(configFile string) (*Config, error) {
@@ -210,6 +229,20 @@ func Load(configFile string) (*Config, error) {
v.SetDefault("jobs.job_purge.completed_retention", "168h")
v.SetDefault("notify.webhook.enabled", false)
v.SetDefault("notify.webhook.timeout", "10s")
v.SetDefault("acp.enabled", true)
v.SetDefault("acp.max_active_global", 20)
v.SetDefault("acp.max_active_per_user", 3)
v.SetDefault("acp.spawn_timeout", "30s")
v.SetDefault("acp.kill_grace", "5s")
v.SetDefault("acp.stderr_buffer_lines", 100)
v.SetDefault("acp.stderr_tail_bytes", 2000)
v.SetDefault("acp.ws_ping_interval", "30s")
v.SetDefault("acp.ws_pong_timeout", "60s")
v.SetDefault("acp.ws_send_buffer", 256)
v.SetDefault("acp.event_max_payload_bytes", 65536)
v.SetDefault("acp.event_truncate_field_bytes", 4096)
v.SetDefault("acp.event_retention_days", 7)
v.SetDefault("acp.shutdown_grace", "30s")
if configFile != "" {
v.SetConfigFile(configFile)