diff options
| author | Paul Buetow <paul@buetow.org> | 2025-09-06 11:14:27 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-09-06 11:14:27 +0300 |
| commit | fb267966f7840df222338f57023273a993a73c9a (patch) | |
| tree | d10066412f08b386a6f9fe9289f27124c6ebe9d6 | |
| parent | 1bf4251a7edbd00902f22db77031d0f998569614 (diff) | |
use TOML not JSON for configuration
| -rw-r--r-- | AGENTS.md | 2 | ||||
| -rw-r--r-- | PROJECTSTATUS.md | 16 | ||||
| -rw-r--r-- | config.json.example | 30 | ||||
| -rw-r--r-- | config.toml.example | 34 | ||||
| -rw-r--r-- | docs/configuration.md | 75 | ||||
| -rw-r--r-- | docs/coverage.html | 2838 | ||||
| -rw-r--r-- | docs/coverage.out | 11632 | ||||
| -rw-r--r-- | go.mod | 6 | ||||
| -rw-r--r-- | go.sum | 2 | ||||
| -rw-r--r-- | internal/appconfig/config.go | 70 | ||||
| -rw-r--r-- | internal/appconfig/config_test.go | 72 | ||||
| -rw-r--r-- | internal/hexaicli/run_test.go | 2 | ||||
| -rw-r--r-- | internal/hexaicli/testhelpers_test.go | 11 |
13 files changed, 7486 insertions, 7304 deletions
@@ -10,7 +10,7 @@ - If possible, construct individual methods so that they can be unit tested. But only if it doesn't add too much boilerplate to the code base. - Aim for at least 85% unit test coverage of all source code. -- Ensure that all unit tests pass before merging any changes. +- Ensure that all unit tests pass before commiting any changes. - Always run the gofumpt code reformatter on all go files modified. - There should be no source code file larger than 1000 lines. If so, split it up into multiple. - There should be no function larger then 50 lines. If so, refactor or split up into multiple smaller functions. diff --git a/PROJECTSTATUS.md b/PROJECTSTATUS.md index cc87928..4114df6 100644 --- a/PROJECTSTATUS.md +++ b/PROJECTSTATUS.md @@ -4,26 +4,22 @@ ### New features -* [X] Create "generate unit test" code action for selected code block => write test to FILE_test.go file +* [ ] Have all text LLM prompts be configurable. With defaults as of now. * [ ] implement a code action for selected code block the way via a unix pipe as faster access in helix + - pipe selected code to external command and replace selection with output + - the external command should open a menu to select an action (e.g. "format", "refactor", "explain", "test", etc.) and then apply it to the selected code + - the external menu can be opened in a separate tmux pane +* [ ] Fish and zsh and bash shell integration for command completion? Have access to the current shell history (N last commands), current directory content, and current directory name. +* [X] Create "generate unit test" code action for selected code block => write test to FILE_test.go file * [X] Use hexai as a gh copilot... CLI replacemant for command line questions * [X] Resolve diagnostics code action feature * [X] LSP server to be used with the Helix text editor * [X] Code completion using LLMs -* [ ] Have all text LLM prompts be configurable. With defaults as of now. * [X] Text completion in general * [/] Be a replacement for 'github copilot cli' * [X] Be able to perform inline chats (keeping history in the document) -* [ ] Be able to switch the underlying model via a prompt * [X] Fine tune when Large Language Model (LLM) completions trigger, as it seems that there are some cases where the Large Language Model (LLM) receives a request but Helix isn't suggesting any completions. There seems to be something odd with the in logic. Investigate the TriggerChar logic and make sure it matches Helix's expectations. * [X] Can anything else can be done with LSP? -* [ ] Fish and zsh and bash shell integration for command completion? Have access to the current shell history (N last commands), current directory content, and current directory name. - -Be able to select code blocks and perform code actions on them - -* [X] Commenting exiting code -* [X] Add unit test (for Go) -* [X] Code refactoring (via comment instruction) Be able to switch LLMs. diff --git a/config.json.example b/config.json.example deleted file mode 100644 index 7a4298c..0000000 --- a/config.json.example +++ /dev/null @@ -1,30 +0,0 @@ -{ - "max_tokens": 4000, - "context_mode": "file-on-new-func", - "context_window_lines": 120, - "max_context_tokens": 4000, - "log_preview_limit": 100, - "completion_debounce_ms": 200, - "completion_throttle_ms": 0, - "no_disk_io": true, - "trigger_characters": [".", ":", "/", "_", " "], - "inline_open": ">", - "inline_close": ">", - "chat_suffix": ">", - "chat_prefixes": ["?", "!", ":", ";"], - "coding_temperature": 0.2, - - "provider": "openai", - - "openai_model": "gpt-4.1", - "openai_base_url": "https://api.openai.com/v1", - "openai_temperature": 0.2, - - "ollama_model": "qwen3-coder:30b-a3b-q4_K_M", - "ollama_base_url": "http://localhost:11434", - "ollama_temperature": 0.2, - - "copilot_model": "gpt-4o-mini", - "copilot_base_url": "https://api.githubcopilot.com", - "copilot_temperature": 0.2 -} diff --git a/config.toml.example b/config.toml.example new file mode 100644 index 0000000..70b4442 --- /dev/null +++ b/config.toml.example @@ -0,0 +1,34 @@ +max_tokens = 4000 +context_mode = "file-on-new-func" +context_window_lines = 120 +max_context_tokens = 4000 +log_preview_limit = 100 +completion_debounce_ms = 200 +completion_throttle_ms = 0 +# Optional: disable disk IO while building context (reserved) +# no_disk_io = true +trigger_characters = [".", ":", "/", "_", " "] +inline_open = ">" +inline_close = ">" +chat_suffix = ">" +chat_prefixes = ["?", "!", ":", ";"] +coding_temperature = 0.2 + +# Provider: openai | copilot | ollama +provider = "openai" + +# OpenAI +openai_model = "gpt-4.1" +openai_base_url = "https://api.openai.com/v1" +openai_temperature = 0.2 + +# Ollama +ollama_model = "qwen3-coder:30b-a3b-q4_K_M" +ollama_base_url = "http://localhost:11434" +ollama_temperature = 0.2 + +# GitHub Copilot +copilot_model = "gpt-4o-mini" +copilot_base_url = "https://api.githubcopilot.com" +copilot_temperature = 0.2 + diff --git a/docs/configuration.md b/docs/configuration.md index 3b862af..d52323c 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -7,36 +7,39 @@ environment overrides, provider selection, and temperature behavior. The config file is optional. -- Location: `$XDG_CONFIG_HOME/hexai/config.json` (usually `~/.config/hexai/config.json`). +- Location: `$XDG_CONFIG_HOME/hexai/config.toml` (usually `~/.config/hexai/config.toml`). - Example: -```json -{ - "max_tokens": 4000, - "context_mode": "always-full", - "context_window_lines": 120, - "max_context_tokens": 4000, - "log_preview_limit": 100, - "completion_debounce_ms": 200, - "completion_throttle_ms": 0, - "no_disk_io": true, - "trigger_characters": [".", ":", "/", "_", " " ], - "inline_open": ">", - "inline_close": ">", - "chat_suffix": ">", - "chat_prefixes": ["?", "!", ":", ";"], - "coding_temperature": 0.2, - "provider": "ollama", - "copilot_model": "gpt-4o-mini", - "copilot_base_url": "https://api.githubcopilot.com", - "copilot_temperature": 0.2, - "openai_model": "gpt-4.1", - "openai_base_url": "https://api.openai.com/v1", - "openai_temperature": 0.2, - "ollama_model": "qwen3-coder:30b-a3b-q4_K_M", - "ollama_base_url": "http://localhost:11434", - "ollama_temperature": 0.2 -} +```toml +max_tokens = 4000 +context_mode = "always-full" +context_window_lines = 120 +max_context_tokens = 4000 +log_preview_limit = 100 +completion_debounce_ms = 200 +completion_throttle_ms = 0 +# no_disk_io is reserved for future use +trigger_characters = [".", ":", "/", "_", " "] +inline_open = ">" +inline_close = ">" +chat_suffix = ">" +chat_prefixes = ["?", "!", ":", ";"] +coding_temperature = 0.2 + +# choose one provider: openai | copilot | ollama +provider = "ollama" + +copilot_model = "gpt-4o-mini" +copilot_base_url = "https://api.githubcopilot.com" +copilot_temperature = 0.2 + +openai_model = "gpt-4.1" +openai_base_url = "https://api.openai.com/v1" +openai_temperature = 0.2 + +ollama_model = "qwen3-coder:30b-a3b-q4_K_M" +ollama_base_url = "http://localhost:11434" +ollama_temperature = 0.2 ``` Key fields: @@ -60,14 +63,12 @@ Key fields: Defaults use `>` for inline prompts and chat suffix. You can change them, e.g.: -```json -{ - "inline_open": "<", - "inline_close": ">", - "chat_suffix": "/", - "chat_prefixes": ["?", "!"], - "trigger_characters": [".", ":", "/", "_", " "] -} +```toml +inline_open = "<" +inline_close = ">" +chat_suffix = "/" +chat_prefixes = ["?", "!"] +trigger_characters = [".", ":", "/", "_", " "] ``` Notes: @@ -77,7 +78,7 @@ Notes: ## Environment overrides - All config-file options can be overridden by environment variables prefixed with `HEXAI_`. -- Env values take precedence over `config.json`. +- Env values take precedence over `config.toml`. - Examples: - `HEXAI_PROVIDER`, `HEXAI_MAX_TOKENS`, `HEXAI_CONTEXT_MODE`, `HEXAI_CONTEXT_WINDOW_LINES`, `HEXAI_MAX_CONTEXT_TOKENS`, `HEXAI_LOG_PREVIEW_LIMIT` - `HEXAI_CODING_TEMPERATURE` diff --git a/docs/coverage.html b/docs/coverage.html index d940029..49b89df 100644 --- a/docs/coverage.html +++ b/docs/coverage.html @@ -59,7 +59,7 @@ <option value="file1">codeberg.org/snonux/hexai/cmd/hexai/main.go (0.0%)</option> - <option value="file2">codeberg.org/snonux/hexai/internal/appconfig/config.go (86.9%)</option> + <option value="file2">codeberg.org/snonux/hexai/internal/appconfig/config.go (87.0%)</option> <option value="file3">codeberg.org/snonux/hexai/internal/hexaicli/run.go (91.4%)</option> @@ -83,19 +83,19 @@ <option value="file13">codeberg.org/snonux/hexai/internal/lsp/document.go (90.1%)</option> - <option value="file14">codeberg.org/snonux/hexai/internal/lsp/handlers.go (90.5%)</option> + <option value="file14">codeberg.org/snonux/hexai/internal/lsp/handlers.go (92.1%)</option> <option value="file15">codeberg.org/snonux/hexai/internal/lsp/handlers_codeaction.go (81.2%)</option> - <option value="file16">codeberg.org/snonux/hexai/internal/lsp/handlers_completion.go (86.1%)</option> + <option value="file16">codeberg.org/snonux/hexai/internal/lsp/handlers_completion.go (87.5%)</option> - <option value="file17">codeberg.org/snonux/hexai/internal/lsp/handlers_document.go (87.4%)</option> + <option value="file17">codeberg.org/snonux/hexai/internal/lsp/handlers_document.go (88.9%)</option> <option value="file18">codeberg.org/snonux/hexai/internal/lsp/handlers_execute.go (75.0%)</option> <option value="file19">codeberg.org/snonux/hexai/internal/lsp/handlers_init.go (55.6%)</option> - <option value="file20">codeberg.org/snonux/hexai/internal/lsp/handlers_utils.go (88.2%)</option> + <option value="file20">codeberg.org/snonux/hexai/internal/lsp/handlers_utils.go (88.5%)</option> <option value="file21">codeberg.org/snonux/hexai/internal/lsp/server.go (77.9%)</option> @@ -178,117 +178,118 @@ func main() <span class="cov0" title="0">{ } </pre> - <pre class="file" id="file2" style="display: none">// Summary: Application configuration model and loader; reads ~/.config/hexai/config.json and merges defaults. + <pre class="file" id="file2" style="display: none">// Summary: Application configuration model and loader; reads ~/.config/hexai/config.toml and merges defaults. package appconfig import ( - "encoding/json" - "fmt" - "log" - "os" - "path/filepath" - "slices" - "strconv" - "strings" + "fmt" + "log" + "os" + "path/filepath" + "slices" + "strconv" + "strings" + + "github.com/pelletier/go-toml/v2" ) -// App holds user-configurable settings read from ~/.config/hexai/config.json. +// App holds user-configurable settings read from ~/.config/hexai/config.toml. type App struct { - MaxTokens int `json:"max_tokens"` - ContextMode string `json:"context_mode"` - ContextWindowLines int `json:"context_window_lines"` - MaxContextTokens int `json:"max_context_tokens"` - LogPreviewLimit int `json:"log_preview_limit"` + MaxTokens int `json:"max_tokens" toml:"max_tokens"` + ContextMode string `json:"context_mode" toml:"context_mode"` + ContextWindowLines int `json:"context_window_lines" toml:"context_window_lines"` + MaxContextTokens int `json:"max_context_tokens" toml:"max_context_tokens"` + LogPreviewLimit int `json:"log_preview_limit" toml:"log_preview_limit"` // Single knob for LSP requests; if set, overrides hardcoded temps in LSP. - CodingTemperature *float64 `json:"coding_temperature"` - // Minimum identifier characters required for manual (TriggerKind=1) invoke - // to proceed without structural triggers. 0 means always allow. - ManualInvokeMinPrefix int `json:"manual_invoke_min_prefix"` - - // Completion debounce in milliseconds. When > 0, the server waits until - // there has been no text change for at least this duration before sending - // an LLM completion request. - CompletionDebounceMs int `json:"completion_debounce_ms"` - // Completion throttle in milliseconds. When > 0, caps the minimum spacing - // between LLM requests (both chat and code-completer paths). - CompletionThrottleMs int `json:"completion_throttle_ms"` - - TriggerCharacters []string `json:"trigger_characters"` - Provider string `json:"provider"` + CodingTemperature *float64 `json:"coding_temperature" toml:"coding_temperature"` + // Minimum identifier characters required for manual (TriggerKind=1) invoke + // to proceed without structural triggers. 0 means always allow. + ManualInvokeMinPrefix int `json:"manual_invoke_min_prefix" toml:"manual_invoke_min_prefix"` + + // Completion debounce in milliseconds. When > 0, the server waits until + // there has been no text change for at least this duration before sending + // an LLM completion request. + CompletionDebounceMs int `json:"completion_debounce_ms" toml:"completion_debounce_ms"` + // Completion throttle in milliseconds. When > 0, caps the minimum spacing + // between LLM requests (both chat and code-completer paths). + CompletionThrottleMs int `json:"completion_throttle_ms" toml:"completion_throttle_ms"` + + TriggerCharacters []string `json:"trigger_characters" toml:"trigger_characters"` + Provider string `json:"provider" toml:"provider"` // Inline prompt trigger characters (default: >text> and >>text>) - InlineOpen string `json:"inline_open"` - InlineClose string `json:"inline_close"` + InlineOpen string `json:"inline_open" toml:"inline_open"` + InlineClose string `json:"inline_close" toml:"inline_close"` // In-editor chat triggers (default: suffix ">" after one of [?, !, :, ;]) - ChatSuffix string `json:"chat_suffix"` - ChatPrefixes []string `json:"chat_prefixes"` + ChatSuffix string `json:"chat_suffix" toml:"chat_suffix"` + ChatPrefixes []string `json:"chat_prefixes" toml:"chat_prefixes"` // Provider-specific options - OpenAIBaseURL string `json:"openai_base_url"` - OpenAIModel string `json:"openai_model"` + OpenAIBaseURL string `json:"openai_base_url" toml:"openai_base_url"` + OpenAIModel string `json:"openai_model" toml:"openai_model"` // Default temperature for OpenAI requests (nil means use provider default) - OpenAITemperature *float64 `json:"openai_temperature"` - OllamaBaseURL string `json:"ollama_base_url"` - OllamaModel string `json:"ollama_model"` + OpenAITemperature *float64 `json:"openai_temperature" toml:"openai_temperature"` + OllamaBaseURL string `json:"ollama_base_url" toml:"ollama_base_url"` + OllamaModel string `json:"ollama_model" toml:"ollama_model"` // Default temperature for Ollama requests (nil means use provider default) - OllamaTemperature *float64 `json:"ollama_temperature"` - CopilotBaseURL string `json:"copilot_base_url"` - CopilotModel string `json:"copilot_model"` + OllamaTemperature *float64 `json:"ollama_temperature" toml:"ollama_temperature"` + CopilotBaseURL string `json:"copilot_base_url" toml:"copilot_base_url"` + CopilotModel string `json:"copilot_model" toml:"copilot_model"` // Default temperature for Copilot requests (nil means use provider default) - CopilotTemperature *float64 `json:"copilot_temperature"` + CopilotTemperature *float64 `json:"copilot_temperature" toml:"copilot_temperature"` } // Constructor: defaults for App (kept first among functions) func newDefaultConfig() App <span class="cov5" title="9">{ // Coding-friendly default temperature across providers - // Users can override per provider in config.json (including 0.0). + // Users can override per provider in config.toml (including 0.0). t := 0.2 return App{ - MaxTokens: 4000, - ContextMode: "always-full", - ContextWindowLines: 120, - MaxContextTokens: 4000, - LogPreviewLimit: 100, - CodingTemperature: &t, - OpenAITemperature: &t, - OllamaTemperature: &t, - CopilotTemperature: &t, - ManualInvokeMinPrefix: 0, - CompletionDebounceMs: 200, - CompletionThrottleMs: 0, - // Inline/chat trigger defaults - InlineOpen: ">", - InlineClose: ">", - ChatSuffix: ">", - ChatPrefixes: []string{"?", "!", ":", ";"}, - } + MaxTokens: 4000, + ContextMode: "always-full", + ContextWindowLines: 120, + MaxContextTokens: 4000, + LogPreviewLimit: 100, + CodingTemperature: &t, + OpenAITemperature: &t, + OllamaTemperature: &t, + CopilotTemperature: &t, + ManualInvokeMinPrefix: 0, + CompletionDebounceMs: 200, + CompletionThrottleMs: 0, + // Inline/chat trigger defaults + InlineOpen: ">", + InlineClose: ">", + ChatSuffix: ">", + ChatPrefixes: []string{"?", "!", ":", ";"}, + } }</span> // Load reads configuration from a file and merges with defaults. // It respects the XDG Base Directory Specification. func Load(logger *log.Logger) App <span class="cov4" title="8">{ - cfg := newDefaultConfig() - if logger == nil </span><span class="cov3" title="3">{ - return cfg // Return defaults if no logger is provided (e.g. in tests) - }</span> - - <span class="cov4" title="5">configPath, err := getConfigPath() - if err != nil </span><span class="cov0" title="0">{ - logger.Printf("%v", err) - // Even if config path cannot be resolved, still allow env overrides below. - }</span> else<span class="cov4" title="5"> { - if fileCfg, err := loadFromFile(configPath, logger); err == nil && fileCfg != nil </span><span class="cov3" title="3">{ - cfg.mergeWith(fileCfg) - }</span> - // When the config file is missing or invalid, we keep defaults and still - // apply any environment overrides below. - } - - // Environment overrides (take precedence over file) - <span class="cov4" title="5">if envCfg := loadFromEnv(logger); envCfg != nil </span><span class="cov1" title="1">{ - cfg.mergeWith(envCfg) - }</span> - <span class="cov4" title="5">return cfg</span> + cfg := newDefaultConfig() + if logger == nil </span><span class="cov3" title="3">{ + return cfg // Return defaults if no logger is provided (e.g. in tests) + }</span> + + <span class="cov4" title="5">configPath, err := getConfigPath() + if err != nil </span><span class="cov0" title="0">{ + logger.Printf("%v", err) + // Even if config path cannot be resolved, still allow env overrides below. + }</span> else<span class="cov4" title="5"> { + if fileCfg, err := loadFromFile(configPath, logger); err == nil && fileCfg != nil </span><span class="cov3" title="3">{ + cfg.mergeWith(fileCfg) + }</span> + // When the config file is missing or invalid, we keep defaults and still + // apply any environment overrides below. + } + + // Environment overrides (take precedence over file) + <span class="cov4" title="5">if envCfg := loadFromEnv(logger); envCfg != nil </span><span class="cov1" title="1">{ + cfg.mergeWith(envCfg) + }</span> + <span class="cov4" title="5">return cfg</span> } // Private helpers @@ -296,26 +297,29 @@ func loadFromFile(path string, logger *log.Logger) (*App, error) <span class="co f, err := os.Open(path) if err != nil </span><span class="cov2" title="2">{ if !os.IsNotExist(err) && logger != nil </span><span class="cov0" title="0">{ - logger.Printf("cannot open config file %s: %v", path, err) + logger.Printf("cannot open TOML config file %s: %v", path, err) }</span> <span class="cov2" title="2">return nil, err</span> } <span class="cov3" title="4">defer f.Close() - dec := json.NewDecoder(f) + dec := toml.NewDecoder(f) var fileCfg App if err := dec.Decode(&fileCfg); err != nil </span><span class="cov1" title="1">{ if logger != nil </span><span class="cov1" title="1">{ - logger.Printf("invalid config file %s: %v", path, err) + logger.Printf("invalid TOML config file %s: %v", path, err) }</span> <span class="cov1" title="1">return nil, err</span> } + <span class="cov3" title="3">if logger != nil </span><span class="cov3" title="3">{ + logger.Printf("loaded configuration from %s (TOML)", path) + }</span> <span class="cov3" title="3">return &fileCfg, nil</span> } func (a *App) mergeWith(other *App) <span class="cov3" title="4">{ - a.mergeBasics(other) - a.mergeProviderFields(other) + a.mergeBasics(other) + a.mergeProviderFields(other) }</span> // mergeBasics merges general (non-provider) fields. @@ -335,32 +339,36 @@ func (a *App) mergeBasics(other *App) <span class="cov3" title="4">{ <span class="cov3" title="4">if other.LogPreviewLimit >= 0 </span><span class="cov3" title="4">{ a.LogPreviewLimit = other.LogPreviewLimit }</span> - <span class="cov3" title="4">if other.CodingTemperature != nil </span><span class="cov3" title="3">{ // allow explicit 0.0 - a.CodingTemperature = other.CodingTemperature - }</span> - <span class="cov3" title="4">if other.ManualInvokeMinPrefix >= 0 </span><span class="cov3" title="4">{ - a.ManualInvokeMinPrefix = other.ManualInvokeMinPrefix - }</span> - <span class="cov3" title="4">if other.CompletionDebounceMs > 0 </span><span class="cov3" title="3">{ a.CompletionDebounceMs = other.CompletionDebounceMs }</span> - <span class="cov3" title="4">if other.CompletionThrottleMs > 0 </span><span class="cov3" title="3">{ a.CompletionThrottleMs = other.CompletionThrottleMs }</span> - <span class="cov3" title="4">if len(other.TriggerCharacters) > 0 </span><span class="cov3" title="3">{ - a.TriggerCharacters = slices.Clone(other.TriggerCharacters) - }</span> - <span class="cov3" title="4">if s := strings.TrimSpace(other.InlineOpen); s != "" </span><span class="cov0" title="0">{ - a.InlineOpen = s - }</span> - <span class="cov3" title="4">if s := strings.TrimSpace(other.InlineClose); s != "" </span><span class="cov0" title="0">{ - a.InlineClose = s - }</span> - <span class="cov3" title="4">if s := strings.TrimSpace(other.ChatSuffix); s != "" </span><span class="cov0" title="0">{ - a.ChatSuffix = s - }</span> - <span class="cov3" title="4">if len(other.ChatPrefixes) > 0 </span><span class="cov0" title="0">{ - a.ChatPrefixes = slices.Clone(other.ChatPrefixes) - }</span> - <span class="cov3" title="4">if s := strings.TrimSpace(other.Provider); s != "" </span><span class="cov3" title="4">{ - a.Provider = s - }</span> + <span class="cov3" title="4">if other.CodingTemperature != nil </span><span class="cov3" title="3">{ // allow explicit 0.0 + a.CodingTemperature = other.CodingTemperature + }</span> + <span class="cov3" title="4">if other.ManualInvokeMinPrefix >= 0 </span><span class="cov3" title="4">{ + a.ManualInvokeMinPrefix = other.ManualInvokeMinPrefix + }</span> + <span class="cov3" title="4">if other.CompletionDebounceMs > 0 </span><span class="cov3" title="3">{ + a.CompletionDebounceMs = other.CompletionDebounceMs + }</span> + <span class="cov3" title="4">if other.CompletionThrottleMs > 0 </span><span class="cov3" title="3">{ + a.CompletionThrottleMs = other.CompletionThrottleMs + }</span> + <span class="cov3" title="4">if len(other.TriggerCharacters) > 0 </span><span class="cov3" title="3">{ + a.TriggerCharacters = slices.Clone(other.TriggerCharacters) + }</span> + <span class="cov3" title="4">if s := strings.TrimSpace(other.InlineOpen); s != "" </span><span class="cov0" title="0">{ + a.InlineOpen = s + }</span> + <span class="cov3" title="4">if s := strings.TrimSpace(other.InlineClose); s != "" </span><span class="cov0" title="0">{ + a.InlineClose = s + }</span> + <span class="cov3" title="4">if s := strings.TrimSpace(other.ChatSuffix); s != "" </span><span class="cov0" title="0">{ + a.ChatSuffix = s + }</span> + <span class="cov3" title="4">if len(other.ChatPrefixes) > 0 </span><span class="cov0" title="0">{ + a.ChatPrefixes = slices.Clone(other.ChatPrefixes) + }</span> + <span class="cov3" title="4">if s := strings.TrimSpace(other.Provider); s != "" </span><span class="cov3" title="4">{ + a.Provider = s + }</span> } // mergeProviderFields merges per-provider configuration. @@ -397,15 +405,15 @@ func (a *App) mergeProviderFields(other *App) <span class="cov3" title="4">{ func getConfigPath() (string, error) <span class="cov4" title="6">{ var configPath string if xdgConfigHome := os.Getenv("XDG_CONFIG_HOME"); xdgConfigHome != "" </span><span class="cov4" title="5">{ - configPath = filepath.Join(xdgConfigHome, "hexai", "config.json") + configPath = filepath.Join(xdgConfigHome, "hexai", "config.toml") }</span> else<span class="cov1" title="1"> { home, err := os.UserHomeDir() if err != nil </span><span class="cov0" title="0">{ return "", fmt.Errorf("cannot find user home directory: %v", err) }</span> - <span class="cov1" title="1">configPath = filepath.Join(home, ".config", "hexai", "config.json")</span> + <span class="cov1" title="1">configPath = filepath.Join(home, ".config", "hexai", "config.toml")</span> } - <span class="cov4" title="6">return configPath, nil</span> + <span class="cov4" title="6">return configPath, nil</span> } // --- Environment overrides --- @@ -413,100 +421,157 @@ func getConfigPath() (string, error) <span class="cov4" title="6">{ // loadFromEnv constructs an App containing only fields set via HEXAI_* env vars. // These values should take precedence over file config when merged. func loadFromEnv(logger *log.Logger) *App <span class="cov4" title="5">{ - var out App - var any bool - - // helpers - getenv := func(k string) string </span><span class="cov10" title="120">{ return strings.TrimSpace(os.Getenv(k)) }</span> - <span class="cov4" title="5">parseInt := func(k string) (int, bool) </span><span class="cov7" title="35">{ - v := getenv(k) - if v == "" </span><span class="cov7" title="28">{ return 0, false }</span> - <span class="cov4" title="7">n, err := strconv.Atoi(v) - if err != nil </span><span class="cov0" title="0">{ if logger != nil </span><span class="cov0" title="0">{ logger.Printf("invalid %s: %v", k, err) }</span> ; <span class="cov0" title="0">return 0, false</span> } - <span class="cov4" title="7">return n, true</span> - } - <span class="cov4" title="5">parseFloatPtr := func(k string) (*float64, bool) </span><span class="cov6" title="20">{ - v := getenv(k) - if v == "" </span><span class="cov6" title="16">{ return nil, false }</span> - <span class="cov3" title="4">f, err := strconv.ParseFloat(v, 64) - if err != nil </span><span class="cov0" title="0">{ - if logger != nil </span><span class="cov0" title="0">{ logger.Printf("invalid %s: %v", k, err) }</span> - <span class="cov0" title="0">return nil, false</span> + var out App + var any bool + + // helpers + getenv := func(k string) string </span><span class="cov10" title="120">{ return strings.TrimSpace(os.Getenv(k)) }</span> + <span class="cov4" title="5">parseInt := func(k string) (int, bool) </span><span class="cov7" title="35">{ + v := getenv(k) + if v == "" </span><span class="cov7" title="28">{ + return 0, false + }</span> + <span class="cov4" title="7">n, err := strconv.Atoi(v) + if err != nil </span><span class="cov0" title="0">{ + if logger != nil </span><span class="cov0" title="0">{ + logger.Printf("invalid %s: %v", k, err) + }</span> + <span class="cov0" title="0">return 0, false</span> + } + <span class="cov4" title="7">return n, true</span> } - <span class="cov3" title="4">return &f, true</span> - } - - <span class="cov4" title="5">if n, ok := parseInt("HEXAI_MAX_TOKENS"); ok </span><span class="cov1" title="1">{ - out.MaxTokens = n; any = true - }</span> - <span class="cov4" title="5">if s := getenv("HEXAI_CONTEXT_MODE"); s != "" </span><span class="cov1" title="1">{ - out.ContextMode = s; any = true - }</span> - <span class="cov4" title="5">if n, ok := parseInt("HEXAI_CONTEXT_WINDOW_LINES"); ok </span><span class="cov1" title="1">{ - out.ContextWindowLines = n; any = true - }</span> - <span class="cov4" title="5">if n, ok := parseInt("HEXAI_MAX_CONTEXT_TOKENS"); ok </span><span class="cov1" title="1">{ - out.MaxContextTokens = n; any = true - }</span> - <span class="cov4" title="5">if n, ok := parseInt("HEXAI_LOG_PREVIEW_LIMIT"); ok </span><span class="cov1" title="1">{ - out.LogPreviewLimit = n; any = true - }</span> - <span class="cov4" title="5">if n, ok := parseInt("HEXAI_MANUAL_INVOKE_MIN_PREFIX"); ok </span><span class="cov1" title="1">{ - out.ManualInvokeMinPrefix = n; any = true - }</span> - <span class="cov4" title="5">if n, ok := parseInt("HEXAI_COMPLETION_DEBOUNCE_MS"); ok </span><span class="cov1" title="1">{ - out.CompletionDebounceMs = n; any = true - }</span> - <span class="cov4" title="5">if n, ok := parseInt("HEXAI_COMPLETION_THROTTLE_MS"); ok </span><span class="cov1" title="1">{ - out.CompletionThrottleMs = n; any = true - }</span> - <span class="cov4" title="5">if f, ok := parseFloatPtr("HEXAI_CODING_TEMPERATURE"); ok </span><span class="cov1" title="1">{ - out.CodingTemperature = f; any = true - }</span> - <span class="cov4" title="5">if s := getenv("HEXAI_TRIGGER_CHARACTERS"); s != "" </span><span class="cov1" title="1">{ - parts := strings.Split(s, ",") - out.TriggerCharacters = nil - for _, p := range parts </span><span class="cov3" title="3">{ - if t := strings.TrimSpace(p); t != "" </span><span class="cov3" title="3">{ - out.TriggerCharacters = append(out.TriggerCharacters, t) - }</span> + <span class="cov4" title="5">parseFloatPtr := func(k string) (*float64, bool) </span><span class="cov6" title="20">{ + v := getenv(k) + if v == "" </span><span class="cov6" title="16">{ + return nil, false + }</span> + <span class="cov3" title="4">f, err := strconv.ParseFloat(v, 64) + if err != nil </span><span class="cov0" title="0">{ + if logger != nil </span><span class="cov0" title="0">{ + logger.Printf("invalid %s: %v", k, err) + }</span> + <span class="cov0" title="0">return nil, false</span> + } + <span class="cov3" title="4">return &f, true</span> + } + + <span class="cov4" title="5">if n, ok := parseInt("HEXAI_MAX_TOKENS"); ok </span><span class="cov1" title="1">{ + out.MaxTokens = n + any = true + }</span> + <span class="cov4" title="5">if s := getenv("HEXAI_CONTEXT_MODE"); s != "" </span><span class="cov1" title="1">{ + out.ContextMode = s + any = true + }</span> + <span class="cov4" title="5">if n, ok := parseInt("HEXAI_CONTEXT_WINDOW_LINES"); ok </span><span class="cov1" title="1">{ + out.ContextWindowLines = n + any = true + }</span> + <span class="cov4" title="5">if n, ok := parseInt("HEXAI_MAX_CONTEXT_TOKENS"); ok </span><span class="cov1" title="1">{ + out.MaxContextTokens = n + any = true + }</span> + <span class="cov4" title="5">if n, ok := parseInt("HEXAI_LOG_PREVIEW_LIMIT"); ok </span><span class="cov1" title="1">{ + out.LogPreviewLimit = n + any = true + }</span> + <span class="cov4" title="5">if n, ok := parseInt("HEXAI_MANUAL_INVOKE_MIN_PREFIX"); ok </span><span class="cov1" title="1">{ + out.ManualInvokeMinPrefix = n + any = true + }</span> + <span class="cov4" title="5">if n, ok := parseInt("HEXAI_COMPLETION_DEBOUNCE_MS"); ok </span><span class="cov1" title="1">{ + out.CompletionDebounceMs = n + any = true + }</span> + <span class="cov4" title="5">if n, ok := parseInt("HEXAI_COMPLETION_THROTTLE_MS"); ok </span><span class="cov1" title="1">{ + out.CompletionThrottleMs = n + any = true + }</span> + <span class="cov4" title="5">if f, ok := parseFloatPtr("HEXAI_CODING_TEMPERATURE"); ok </span><span class="cov1" title="1">{ + out.CodingTemperature = f + any = true + }</span> + <span class="cov4" title="5">if s := getenv("HEXAI_TRIGGER_CHARACTERS"); s != "" </span><span class="cov1" title="1">{ + parts := strings.Split(s, ",") + out.TriggerCharacters = nil + for _, p := range parts </span><span class="cov3" title="3">{ + if t := strings.TrimSpace(p); t != "" </span><span class="cov3" title="3">{ + out.TriggerCharacters = append(out.TriggerCharacters, t) + }</span> + } + <span class="cov1" title="1">any = true</span> } - <span class="cov1" title="1">any = true</span> - } - <span class="cov4" title="5">if s := getenv("HEXAI_INLINE_OPEN"); s != "" </span><span class="cov0" title="0">{ out.InlineOpen = s; any = true }</span> - <span class="cov4" title= |
