summaryrefslogtreecommitdiff
path: root/internal/llm
AgeCommit message (Collapse)Author
2026-06-19ok0 document LSP and LLM exportsPaul Buetow
2026-06-11llm: add compile-time interface checks for all providersPaul Buetow
Add the missing var _ Client / var _ Streamer compile-time satisfaction check to anthropicClient, and clarify the existing assertion comments for openAIClient, openRouterClient, ollamaClient (all Client+Streamer) and youSearchClient (Client only; the You.com research API is non-streaming). All providers use value receivers, so assertions use zero-value structs. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-11Consolidate LLM timeout/retry/breaker values into policy packagePaul Buetow
The per-request HTTP timeouts (30s chat, 120s research), retry policy (attempts, backoff, jitter), and circuit-breaker tuning (threshold, cooldown) were previously scattered as bare literals across each provider constructor and resilience.go/circuitbreaker.go, making the operational policy hard to discover and prone to drift. Introduce internal/llm/policy with documented named constants as the single source of truth, and reference them from all provider constructors, the default retry policy, and the shared circuit breaker. Update comments to explain the policy and reasoning. Add tests validating the values and their internal consistency. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-11llm: return concrete client types from provider constructorsPaul Buetow
Follow the Go idiom "return concrete types, accept interfaces": the provider constructors newOpenAI, newAnthropic, newOpenRouter, newOllama and their *WithTimeout variants now return their concrete *Client value types instead of the Client interface. The provider factories registered in the registry still return Client, so NewFromConfig and the registry keep working unchanged. Updated comments to explain the reasoning, dropped the now-redundant type assertions in tests, and switched the anthropic Streamer-capability tests to assert via an explicit Client interface value. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-11Add retry and circuit-breaker resilience around LLM HTTP calls (ak0)Paul Buetow
Wrap the shared provider HTTP choke point (doJSONRequest in llm/util.go, used by openai, openrouter, anthropic and ollama) with two resilience patterns implemented with the standard library only: - Retry with exponential backoff + jitter (resilience.go): 3 attempts by default, retrying transient network errors and retryable HTTP statuses (429 and 5xx). Client errors (4xx) and successes are returned immediately and never retried. Backoff waits are context-aware so cancellation and deadlines are respected; retried response bodies are drained and closed for connection reuse. - Circuit breaker (circuitbreaker.go, own file as it has >3 methods): classic closed/open/half-open breaker that trips after 5 consecutive transient failures and stays open for a 30s cooldown, then allows a single trial probe. Only transient failures count; 4xx never trips it. A nil breaker is a valid no-op. doJSONRequest now delegates to doJSONRequestResilient; the single-attempt primitive is preserved as doJSONRequestOnce. Adds httptest-based unit tests for retry/backoff/breaker logic with no real network calls; new code coverage is >80%. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-10Replace panics with returned errors in llm.RegisterProviderPaul Buetow
RegisterProvider now returns an error for an empty name, a nil factory, or a duplicate registration instead of panicking, making registration composable and testable without recover(). RegisterAllProviders caches the one-time registration error (sync.Once cannot return a value) and returns it to every caller. Updated all call sites: hexailsp, hexaicli and hexaiaction propagate the error with context; test TestMains fail fast via panic. Added unit tests covering empty name, nil factory, duplicate, success and idempotent re-registration. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-05-20test(yousearch): add unit tests; allow base URL override for testsPaul Buetow
Amp-Thread-ID: https://ampcode.com/threads/T-019e45ff-4976-750c-b2e6-121d0e5991ef Co-authored-by: Amp <amp@ampcode.com>
2026-05-20Add YouSearch (You.com Research API) provider integrationPaul Buetow
Amp-Thread-ID: https://ampcode.com/threads/T-019e45ff-4976-750c-b2e6-121d0e5991ef Co-authored-by: Amp <amp@ampcode.com>
2026-05-01Bump version to 0.38.3v0.38.3Paul Buetow
Correct default Ollama Cloud model to gemma4:31b-cloud (bare gemma4 tag returns 404 on Ollama Cloud; the hosted cloud model requires the explicit :31b-cloud tag). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-01Bump version to 0.38.2v0.38.2Paul Buetow
Switch default Ollama Cloud model from kimi-k2.6 to gemma4. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26feat: default to Ollama Cloud (kimi-k2.6) when no provider configuredPaul Buetow
Switches the in-code defaults so that hexai talks to Ollama Cloud (https://ollama.com) with model kimi-k2.6 when no provider is configured, instead of OpenAI. The example config, README, and configuration guide all reflect the new recommended setup; previous OpenAI / local-Ollama options are still documented as alternatives. Tests that depended on the implicit "openai" default now pin the provider explicitly so they continue to exercise the OpenAI / gpt-5 code paths they were designed to cover. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-26feat: optional API key for Ollama provider (Ollama Cloud)Paul Buetow
Adds an optional HEXAI_OLLAMA_API_KEY (with OLLAMA_API_KEY fallback) so the existing Ollama provider can target Ollama Cloud (ollama.ai) in addition to a local server. When the key is empty the request is unauthenticated, preserving local-server behavior byte-for-byte; when set, an Authorization: Bearer header is attached for both Chat and ChatStream. Documented cloud usage in config.toml.example. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-03-23chore: bump version to v0.25.9v0.25.9Paul Buetow
Code quality fixes from audit: - Log silently discarded errors in status sinks and stats.Update call sites - Fix json.Marshal errors silently ignored in LSP handlers - Replace time.Sleep in tests with channel signaling (mcp) and fake clock (stats) - Make context cancellation work in production time.Sleep sites (handlers_document, cmdentry) - Remove init()-based provider registration from llm package; use explicit RegisterAllProviders() - Add WaitGroup goroutine tracking to MCP server Run() Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23refactor: split oversized functions, fix double logging, add %w wrappingPaul Buetow
- lsp/handlers_completion.go: extract buildNativeCompletionCacheKey and postProcessNativeCompletion; track collectFirstCompletion in inflight; remove redundant logLLMStats("") on error path - lsp/handlers.go: extract checkTriggerFromContext and checkTriggerFromCursorChar; isTriggerEvent reduced from 63→10 lines - lsp/transport.go: use %w for error wrapping in Content-Length parse - llm/ollama.go: extract parseOllamaStream; ChatStream reduced to ~35 lines - appconfig/config_load.go: extract decodeModelEntryFromMap; rename 'any' to 'found'; decodeModelEntry reduced to ~18 lines - llm/provider.go: document why providerRegistry is package-level - integrationtests/ask_test.go: add //go:build integration; move repoRoot init from init() to TestMain with diagnostic message Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23fix: code quality improvements across lsp, askcli, appconfig, integrationtestsPaul Buetow
- lsp/handlers_completion.go: track collectFirstCompletion goroutine in inflight WaitGroup (goroutine leak fix) - lsp/transport.go: use %w instead of %v for error wrapping - askcli/command_list.go: extract handleListWithFilters shared helper; handleList/handleAll/handleReady are now single-liners - askcli/command_list.go, urgency.go, dep.go: log ParseTaskExport errors to stderr instead of returning 1 silently - appconfig/config_load.go: rename 'any' variable to 'found' to avoid shadowing the built-in identifier - llm/provider.go: add explanatory comment for package-level registry - integrationtests/ask_test.go: add //go:build integration tag; move repoRoot init from init() to TestMain with diagnostic error message Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23fix: address all HIGH-severity code quality audit findingsPaul Buetow
- lsp/server.go: track request goroutines in inflight WaitGroup to prevent use-after-close writes on shutdown - lsp/llm_client_registry.go: acquire write lock before calling build() to eliminate TOCTOU race on cache population - lsp/handlers_codeaction.go: resolveSimplifyCodeAction now uses PromptCodeActionSimplify{System,User} (was wrongly using rewrite prompts) - askcli/taskexport.go: remove exported MustParseTaskExport to prevent panic on malformed external input; move to unexported test helper - cmd/ask/main.go: print error to stderr before os.Exit - llm/{openai,ollama,openrouter}.go: add interface satisfaction assertions - integrationtests/ask_test.go: replace type assertions with errors.As for robust exec.ExitError unwrapping Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-19Improve actionable error guidancePaul Buetow
2026-03-16Replace Summary: prefixes with standard Go package doc commentsPaul Buetow
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-16Add doc comments to exported types and functionsPaul Buetow
Document ~30 exported types in lsp/types.go and exported functions in llm/provider.go, lsp/server.go, and hexailsp/run.go. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02llm: extract shared doJSON and logStart helpers (task 409)Paul Buetow
2026-03-02llm: add provider registry and self-registration factories (task 410)Paul Buetow
2026-02-06Remove GitHub Copilot provider supportpaul@buetow.org
Remove all GitHub Copilot integration from the codebase to streamline the supported provider set to OpenAI, OpenRouter, Anthropic, and Ollama. Changes: - Delete core Copilot implementation (copilot.go) and all related tests - Remove Copilot configuration fields from App struct and Config - Remove Copilot from provider factory and API key handling - Update all test files to replace Copilot references with other providers - Remove Copilot documentation from README, configuration guide, and examples - Remove Copilot section from config.toml.example All tests pass successfully after removal. Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-06fix: add missing Anthropic and OpenRouter provider support in config and LSPpaul@buetow.org
- Add Anthropic field merging in config.mergeProviderFields() to properly load AnthropicModel/BaseURL/Temperature from config.toml - Add anthropic and openrouter cases in lsp.resolveDefaultModel() to prevent fallback to OpenAI defaults - Update default Anthropic model to valid claude-3-5-sonnet-20240620 (previous 20241022 doesn't exist) - Update test expectation to match new default model This fixes the issue where Anthropic provider configuration was ignored, causing LSP to return dummy completions instead of real LLM responses. Co-authored-by: Cursor <cursoragent@cursor.com>
2026-01-31feat: add configurable request timeout for LLM callsFlorian
Local LLMs (LM Studio, Ollama, etc.) often need more than the default 30-second timeout. Added request_timeout config option (in seconds) to [general] section and HEXAI_REQUEST_TIMEOUT env var. Original constructor signatures preserved via *WithTimeout variants, so no test changes required.
2026-01-30feat: add completion_wait_all config and fix Anthropic system messagesPaul Buetow
- Add completion_wait_all config option (default true) to wait for all backends before returning results, or return first result immediately - Fix Anthropic API: extract system messages to top-level system field as required by Messages API (was causing 400 errors) - Add anthropic case to server.go clientFor() for model overrides
2026-01-29refactor: apply code style best practices to Anthropic implementationPaul Buetow
- Reorganize anthropic.go: types, interface checks, constructor, public methods, private methods - Extract helper methods from Chat() and ChatStream() to keep functions under 50 lines - Add resolveOptions(), sendRequest(), extractContent() private methods - Add explicit interface satisfaction check for Client and Streamer - Add documentation comments to all public methods (Chat, Name, DefaultModel, ChatStream) - Apply gofmt and gofumpt formatting - Apply goimports for import ordering All 51 tests in llm package pass All code adheres to best practices from go-projects.md: - Value semantics (value receivers only) - Constructors before methods - Public before private - Functions under 50 lines - Explicit interface satisfaction - Documentation on all public identifiers - Proper error handling - Context as first parameter for I/O functions Amp-Thread-ID: https://ampcode.com/threads/T-019c0af1-f215-72cf-9940-b014b1a9576b Co-authored-by: Amp <amp@ampcode.com>
2026-01-29feat: add native Anthropic API provider supportPaul Buetow
- Implement new anthropicClient with full Client interface - Add Streamer interface for token-by-token streaming via SSE - Add Anthropic Messages API v1 integration with proper headers - Support claude-3-5-sonnet-20241022 as default model - Add configuration via [anthropic] TOML section - Add environment variable overrides (HEXAI_ANTHROPIC_*) - Support both HEXAI_ANTHROPIC_API_KEY and ANTHROPIC_API_KEY fallback - Integrate Anthropic key handling in LSP, CLI, and llmutils - Update provider factory to support 'anthropic' provider name - Add 11 comprehensive unit tests for Anthropic client - Update config.toml.example with [anthropic] section - Update NewFromConfig() signature to accept anthropicAPIKey parameter - All 51 internal LLM tests pass (11 new Anthropic tests + 40 existing) Anthropic models can be accessed via: [anthropic] model = "claude-3-5-sonnet-20241022" base_url = "https://api.anthropic.com/v1" temperature = 0.2 or environment: export HEXAI_PROVIDER="anthropic" export HEXAI_ANTHROPIC_API_KEY="your-key" Amp-Thread-ID: https://ampcode.com/threads/T-019c0af1-f215-72cf-9940-b014b1a9576b Co-authored-by: Amp <amp@ampcode.com>
2025-11-03Fix: Address lint warnings and bump patch version to 0.15.3v0.15.3Paul Buetow
2025-11-02some linter fixesPaul Buetow
2025-10-02feat: add OpenRouter providerv0.15.0Paul Buetow
2025-09-24Add runtime config store and reload commandPaul Buetow
2025-09-19fixPaul Buetow
2025-09-17chore(openai): revert default model to gpt-4.1Paul Buetow
2025-09-17feat(openai): set default model to gpt-4oPaul Buetow
2025-09-17chore: commit uncommitted changes before version bumpPaul Buetow
2025-09-17chore(version): bump to v0.11.1 (gpt-5 defaults, timeouts, global stats, ↵v0.11.1Paul Buetow
editor fix)
2025-09-08docs: move tmux documentation to its own filePaul Buetow
2025-09-06more testsPaul Buetow
2025-09-06use gofumptPaul Buetow
2025-09-06feat(lsp): configurable inline/chat triggers; switch inline markers to ↵Paul Buetow
>text>/>>text>; update docs and example config; tests updated to new triggers and raise LSP coverage to >=85%; chore: remove semicolon legacy; chore(mage): auto-refresh coverage daily if docs/coverage.out is older than 24h
2025-09-05tests: add more negative provider cases and table-driven LSP coverage; ↵Paul Buetow
assert headers; add indent postprocess test
2025-09-04tests: add more table-driven cases and negative provider tests; update reportPaul Buetow
2025-09-04tests: expand negative SSE and table-driven coverage; add docs/testing.md; ↵Paul Buetow
use shared fixtures
2025-09-04tests: add negative SSE test, table-driven refactors, and use shared ↵Paul Buetow
fixtures across tests; update REPORT.md progress
2025-09-04tests: add shared test fixtures, expand provider breadth (multi-choice, ↵Paul Buetow
error bodies), add LSP rewrite/diagnostics realism and table-driven tests
2025-09-04tests(llm): raise coverage to >=80%\n- Add OpenAI/Copilot HTTP success + ↵Paul Buetow
stream + token tests\n- Cover With* options and NewFromConfig success paths\n- llm package now ~80.3%
2025-09-04tests(llm): add OpenAI and Copilot HTTP tests (success + token/error paths); ↵Paul Buetow
llm coverage ~61%
2025-09-04tests(lsp,llm): add helper and factory tests to raise coverage modestly; ↵Paul Buetow
continue toward 80% target
2025-09-04llm/ollama: add comprehensive tests (Chat, ChatStream, errors) to reach >80% ↵Paul Buetow
coverage for ollama.go
2025-08-31module: set module path to codeberg.org/snonux/hexai; update imports; docs: ↵v0.3.4Paul Buetow
add go install instructions