1// SPDX-FileCopyrightText: Amolith <amolith@secluded.site>
2//
3// SPDX-License-Identifier: AGPL-3.0-or-later
4
5package config
6
7import (
8 "fmt"
9)
10
11// Config represents the server configuration
12type Config struct {
13 // Server settings
14 Server ServerConfig `mapstructure:"server" toml:"server"`
15
16 // Logging configuration
17 Logging LoggingConfig `mapstructure:"logging" toml:"logging"`
18
19 // Planning limits
20 Planning PlanningConfig `mapstructure:"planning" toml:"planning"`
21}
22
23// ServerConfig contains server-related settings
24type ServerConfig struct {
25 Mode string `mapstructure:"mode" toml:"mode"`
26 Host string `mapstructure:"host" toml:"host"`
27 Port int `mapstructure:"port" toml:"port"`
28}
29
30// LoggingConfig contains logging settings
31type LoggingConfig struct {
32 Level string `mapstructure:"level" toml:"level"`
33 Format string `mapstructure:"format" toml:"format"`
34}
35
36// PlanningConfig contains planning-related limits
37type PlanningConfig struct {
38 MaxTasks int `mapstructure:"max_tasks" toml:"max_tasks"`
39 MaxGoalLength int `mapstructure:"max_goal_length" toml:"max_goal_length"`
40 MaxTaskLength int `mapstructure:"max_task_length" toml:"max_task_length"`
41 HistoryEnabled bool `mapstructure:"history_enabled" toml:"history_enabled"`
42}
43
44// Default returns a Config with sensible defaults
45func Default() *Config {
46 return &Config{
47 Server: ServerConfig{
48 Mode: "stdio",
49 Host: "localhost",
50 Port: 8080,
51 },
52 Logging: LoggingConfig{
53 Level: "info",
54 Format: "text",
55 },
56 Planning: PlanningConfig{
57 MaxTasks: 100,
58 MaxGoalLength: 1000,
59 MaxTaskLength: 500,
60 HistoryEnabled: true,
61 },
62 }
63}
64
65// Validate validates the configuration
66func (c *Config) Validate() error {
67 if c.Server.Mode != "stdio" && c.Server.Mode != "http" {
68 return fmt.Errorf("server mode must be 'stdio' or 'http'")
69 }
70
71 if c.Server.Mode == "http" && (c.Server.Port <= 0 || c.Server.Port > 65535) {
72 return fmt.Errorf("server port must be between 1 and 65535")
73 }
74
75 if c.Planning.MaxTasks <= 0 {
76 return fmt.Errorf("max tasks must be positive")
77 }
78
79 if c.Planning.MaxGoalLength <= 0 {
80 return fmt.Errorf("max goal length must be positive")
81 }
82
83 if c.Planning.MaxTaskLength <= 0 {
84 return fmt.Errorf("max task length must be positive")
85 }
86
87 return nil
88}