Documentation
¶
Index ¶
- Constants
- Variables
- func AgentTools(commands []string, readOnly bool) []string
- func ApplyModelMemory(cfg *config.Config)
- func ClaudeListModels() ([]string, error)
- func ClaudeModelHint(model string) string
- func Clip(s string, n int) string
- func CodexListModels() ([]string, error)
- func ContextTokensForRAM(cfg config.AgentConfig, ramGB float64) int
- func ContextTokensForWeights(weightBytes int64, ramGB float64) int
- func CopilotListModels() ([]string, error)
- func DeepSeekFallbackModels() []string
- func EffectiveEffort(runnerName, effort string) string
- func EffectiveModel(runnerName, model string) string
- func EffortOptions(provider, model string) []string
- func IsLocalRunner(cfg config.AgentConfig) bool
- func IsPreset(name string) bool
- func KeySource(credName, envName string) string
- func LMStudioListInstalled() ([]string, error)
- func ListModels(baseURL, key string) ([]string, error)
- func ListProviderModels(name, baseURL string) ([]string, error)
- func MLXListInstalled() ([]string, error)
- func NormalizeEffort(effort string) string
- func OllamaInstalledWithSizes() (map[string]int64, error)
- func OllamaListInstalled() ([]string, error)
- func OllamaModelSizeBytes(model string) int64
- func OpenCodeListModels() ([]string, error)
- func Ping(provider, model string) error
- func PingAPI(credName, baseURL string) error
- func ProbeModels(ctx context.Context, client *http.Client, baseURL, key string) ([]string, error)
- func ProviderReachable(provider string) error
- func ResolveKey(credName, envName string) (key, source string, err error)
- func ResolveSkills(systemPrompt string, skillNames []string, loader *skills.Loader) string
- func UnloadFor(ctx context.Context, cfg config.AgentConfig) error
- type Activity
- type ActivityKind
- type ActivityState
- type BudgetRunner
- type ClaudeRunner
- type CodexRunner
- type CompletionRequest
- type ConvMessage
- type CopilotRunner
- type DshRunner
- type EffortRunner
- type KeyRejectedError
- type LLMRunner
- type LMStudioRunner
- type LocalModel
- type MLXRunner
- type MockRunner
- type OllamaRunner
- type OpenAIRunner
- type OpenCodeRunner
- type Preset
- type RateLimitError
- type SkillRunner
- type Token
- type TokenUsage
- type Unloader
Constants ¶
const ( ClaudeDefaultModel = "claude-opus-5-5" ClaudeDefaultEffort = "high" )
ClaudeDefaultModel and ClaudeDefaultEffort are what the claude runner uses when a role sets no model or effort.
const (
KeySourceSaved = "saved (" + credentials.DisplayPath + ")"
)
Key sources reported by KeySource.
const ProbeTimeout = 10 * time.Second
ProbeTimeout bounds one /models request made by ProbeModels.
Variables ¶
var ClaudeModels = []string{
"fable",
"opus",
"sonnet",
"haiku",
"claude-fable-5-2",
"claude-opus-5-5",
"claude-sonnet-5-5",
"claude-haiku-5-5",
}
ClaudeModels lists the values the Claude CLI --model flag is offered with: the aliases for the latest model of each family first, then full model names. Update this list when new models ship.
var CodexModels = []string{
"gpt-5.5",
"gpt-5.4",
"gpt-5.4-mini",
"gpt-5.3-codex",
"gpt-5.2-codex",
"gpt-5.2",
"gpt-5.1-codex-max",
"gpt-5.1-codex-mini",
}
CodexModels lists known Codex-compatible model names.
var CopilotModels = []string{
"claude-sonnet-4.6",
"claude-sonnet-4.5",
"claude-haiku-4.5",
"claude-opus-4.8",
"claude-opus-4.7",
"claude-opus-4.6",
"claude-opus-4.5",
"gpt-5.5",
"gpt-5.4",
"gpt-5.4-mini",
"gpt-5.3-codex",
"gpt-5.2-codex",
"gpt-5.2",
"gpt-5-mini",
"gpt-4.1",
}
CopilotModels is the curated fallback list of model IDs accepted by `copilot --model`. Mirrors the entries shown by the interactive `/model` picker. Kept in sync manually; the CLI does not expose a discovery command.
var ErrRateLimited = errors.New("rate limited")
ErrRateLimited is the sentinel returned (wrapped) by all runners when the underlying LLM provider rejects a request because of rate limiting, quota exhaustion, or session usage caps. Callers can detect any flavour with errors.Is(err, runner.ErrRateLimited) and stop the pipeline immediately — continuing would just burn more retries against the same exhausted limit.
var OllamaPopularModels = []string{
"kimi-k2.5:cloud",
"qwen2.5-coder:latest",
"deepseek-coder-v2:latest",
"codellama:latest",
"llama3.2:latest",
"mistral:latest",
"phi4:latest",
"gemma3:latest",
}
OllamaPopularModels is a curated list of models useful for coding tasks.
var OpenCodeAvailableModels = []string{
"qwen2.5-coder:3b",
"qwen2.5-coder:latest",
"llama3.2:latest",
"deepseek-coder-v2:latest",
"opencode/big-pickle",
"opencode/gpt-5-nano",
}
OpenCodeAvailableModels is a fallback list used when the CLI is unavailable.
Functions ¶
func AgentTools ¶ added in v0.7.0
AgentTools is the allow list of a Claude agent run: file tools (read-only for a read-only role), Bash limited to the given build and test commands (never for a read-only role) and read-only git.
func ApplyModelMemory ¶
ApplyModelMemory fills each agent's MaxContextTokens from the global ModelMemory setting. An explicit per-agent MaxContextTokens always wins and is left untouched. When ModelMemory is disabled (Mode "" or "off") nothing changes.
In "context" mode the configured token limit is applied verbatim to every agent. In "ram" mode the limit is derived per agent from its model via ContextTokensForRAM.
func ClaudeListModels ¶
ClaudeListModels returns the known Claude model aliases and names.
func ClaudeModelHint ¶ added in v0.7.0
ClaudeModelHint describes a model alias, such as "latest Opus". It is empty for a full model name.
func Clip ¶ added in v0.7.0
Clip shortens s to at most n runes, ending in "…" when it was cut. The result is never longer than n runes, and a cut never splits a rune.
func CodexListModels ¶
CodexListModels returns available models by merging the currently configured model from ~/.codex/config.toml with the known models list. No API keys or network calls required.
func ContextTokensForRAM ¶
func ContextTokensForRAM(cfg config.AgentConfig, ramGB float64) int
ContextTokensForRAM estimates the largest context window (in tokens) that the agent's model can run within ramGB gigabytes of memory. It prefers real model metadata (Ollama reports the on-disk weight size) and falls back to a heuristic when metadata is unavailable (LM Studio / oMLX). The result is clamped to a sane range and rounded down to a multiple of 1024.
The conversion is intentionally approximate: an exact figure depends on the model's layer count, head dimensions and KV quantisation, which are not generally exposed by the local backends. Under-estimating is the safe failure mode, so the heuristic errs low.
func ContextTokensForWeights ¶
ContextTokensForWeights estimates the largest context window (in tokens) a model of the given weight size can run within ramGB gigabytes of memory. It is the network-free core of ContextTokensForRAM, exposed so callers that already know a model's weight size (e.g. a UI listing several models) can compute estimates without re-fetching metadata per keystroke. weightBytes <= 0 falls back to the default estimate. The result is clamped and rounded down to a multiple of 1024.
func CopilotListModels ¶
CopilotListModels returns the models the local Copilot CLI accepts. It prefers CLI-reported models when a future release exposes them, otherwise falls back to CopilotModels with the user's currently configured model (from ~/.copilot/settings.json) moved to the front.
func DeepSeekFallbackModels ¶ added in v0.7.0
func DeepSeekFallbackModels() []string
DeepSeekFallbackModels returns the static DeepSeek model list.
func EffectiveEffort ¶ added in v0.7.0
EffectiveEffort is the effort the runner really uses: for claude an empty or "default" effort becomes ClaudeDefaultEffort; other runners keep their value.
func EffectiveModel ¶ added in v0.7.0
EffectiveModel is the model the runner really uses: for claude an empty model becomes ClaudeDefaultModel; other runners keep their value unchanged.
func EffortOptions ¶ added in v0.2.1
EffortOptions returns the reasoning-effort levels the given provider/model supports. An empty result means the model exposes no effort control.
func IsLocalRunner ¶
func IsLocalRunner(cfg config.AgentConfig) bool
IsLocalRunner returns true when the runner uses a local model (opencode with local Ollama model, or direct ollama runner). Local runners have no API cost so fix-attempt limits should not apply.
func KeySource ¶ added in v0.7.0
KeySource says where the key for a provider comes from: "env NAME", "saved (~/.decsr/credentials.json)", or "" when there is none.
func LMStudioListInstalled ¶
LMStudioListInstalled returns model IDs available in the running LM Studio server. It prefers the native /api/v0/models endpoint (which reports each model's load state, so loaded models are listed first) and falls back to the OpenAI-compatible /v1/models endpoint.
func ListModels ¶ added in v0.7.0
ListModels returns the model ids offered at baseURL for key.
func ListProviderModels ¶ added in v0.7.0
ListProviderModels lists the models of a preset (or of a saved custom provider when baseURL is given), resolving the key like a runner does. Only deepseek falls back to a static list when the key is missing or the request fails; other providers return nil and the error.
func MLXListInstalled ¶
MLXListInstalled returns model IDs reported by the running oMLX server.
func NormalizeEffort ¶ added in v0.2.1
NormalizeEffort trims and lowercases an effort value. The config sentinel "default" means "provider default" and normalizes to the empty string.
func OllamaInstalledWithSizes ¶
OllamaInstalledWithSizes returns installed Ollama models paired with their on-disk weight size in bytes, from a single /api/tags call.
func OllamaListInstalled ¶
OllamaListInstalled returns model names available in the local Ollama instance.
func OllamaModelSizeBytes ¶
OllamaModelSizeBytes returns the on-disk size (≈ weight size) of an installed model as reported by /api/tags, or 0 when unavailable. Ollama matches model names loosely (an empty tag means ":latest"), so both the exact name and a ":latest" variant are considered.
func OpenCodeListModels ¶
OpenCodeListModels returns available models from the OpenCode CLI.
func Ping ¶
Ping performs a lightweight reachability check for the given provider and model. For CLI providers it verifies the binary exists; for Ollama it also checks the model is available.
func PingAPI ¶ added in v0.7.0
PingAPI checks an OpenAI-compatible endpoint at baseURL with the key of the provider credName (a preset or a saved custom provider).
func ProbeModels ¶ added in v0.7.0
ProbeModels calls GET <baseURL>/models with the key and returns the model ids. client may be nil. A 401/403 gives a *KeyRejectedError. The key never appears in an error.
func ProviderReachable ¶
ProviderReachable performs a lightweight check that the given provider's backend is usable: the CLI binary is in PATH, or the local HTTP server responds. It deliberately does NOT verify a specific model so the result can be cached up-front (e.g. to gray out unavailable providers in the setup UI). Returns nil when reachable, otherwise a descriptive error.
func ResolveKey ¶ added in v0.7.0
ResolveKey finds the API key for a provider: the env var first, then the saved credential named credName. source says where it came from. The key is never part of an error.
func ResolveSkills ¶
ResolveSkills loads skill content and appends it to the system prompt. Returns the enriched system prompt. If loader is nil or no skills match, the original prompt is returned unchanged.
Types ¶
type Activity ¶ added in v0.7.0
type Activity struct {
ID string // stable per item so a later update (running → done) replaces the earlier one
Kind ActivityKind
State ActivityState
Title string // one line, ≤ 200 chars
Detail string // bounded excerpt (input/output), ≤ 2000 chars, may be ""
Added int
Removed int
ExitCode *int
At time.Time
Duration time.Duration // set when State != running, if known
}
Activity is one structured item of agent work. A later Activity with the same ID replaces the earlier one (for example running -> done). Activities never replace Token.Text: the final text of a run is parsed from Text only.
type ActivityKind ¶ added in v0.7.0
type ActivityKind string
ActivityKind classifies what an agent is doing.
const ( ActThinking ActivityKind = "thinking" // reasoning / thought text ActMessage ActivityKind = "message" // assistant prose (summarised) ActTool ActivityKind = "tool" // generic tool call (name in Title) ActCommand ActivityKind = "command" // shell command; Title = command line ActRead ActivityKind = "read" // file read; Title = path ActEdit ActivityKind = "edit" // file edited; Title = path; Added/Removed ActWrite ActivityKind = "write" // file created/overwritten; Title = path; Added/Removed ActSearch ActivityKind = "search" // grep/glob/web search; Title = query ActError ActivityKind = "error" ActWaiting ActivityKind = "waiting" // rate limited / retrying / waiting on something )
type ActivityState ¶ added in v0.7.0
type ActivityState string
ActivityState is the lifecycle state of an Activity.
const ( ActRunning ActivityState = "running" ActDone ActivityState = "done" ActFailed ActivityState = "failed" )
type BudgetRunner ¶
type BudgetRunner struct {
// contains filtered or unexported fields
}
BudgetRunner wraps an LLMRunner and truncates message content to stay within a token budget. Used for cloud runners where tokens have cost.
func (*BudgetRunner) Complete ¶
func (r *BudgetRunner) Complete(ctx context.Context, req CompletionRequest) (<-chan Token, error)
type ClaudeRunner ¶
ClaudeRunner executes the Claude CLI (claude) as an LLM backend.
func (ClaudeRunner) Complete ¶
func (r ClaudeRunner) Complete(ctx context.Context, req CompletionRequest) (<-chan Token, error)
Complete implements LLMRunner by streaming the Claude CLI output incrementally. Uses `--output-format stream-json --verbose` so the TUI shows progress live instead of a single burst at the end of generation.
type CodexRunner ¶
CodexRunner executes the OpenAI Codex CLI as an LLM backend. Uses `codex --quiet` for non-interactive text output.
func (CodexRunner) Complete ¶
func (r CodexRunner) Complete(ctx context.Context, req CompletionRequest) (<-chan Token, error)
Complete implements LLMRunner by running the Codex CLI with the given prompt. Stdout is streamed incrementally so the TUI shows progress live instead of a single burst at the end of generation.
type CompletionRequest ¶
type CompletionRequest struct {
SystemPrompt string
Skills []string
Messages []ConvMessage
Model string
// Effort overrides the agent's configured reasoning effort for this call.
// Empty leaves the decision to the configured EffortRunner or the provider.
Effort string
// Dir is the working directory for CLI runners that run an agent process.
// Empty keeps the process working directory; HTTP runners ignore it.
Dir string
// Agent asks a CLI runner to work as a coding agent that edits files in Dir
// with its own tools. False keeps it a text generator: decsr writes the
// files. HTTP runners ignore it.
Agent bool
// ReadOnly marks a role that reports only. Only the dsh runner uses it, to
// pick its read-only permission preset for an agent run.
ReadOnly bool
// MCP keeps the user's own MCP servers for a Claude run. False (the
// default) starts Claude with none. Only the Claude runner uses it.
MCP bool
// AllowedTools lists the tools an agent run may use, in Claude's
// --allowedTools syntax ("Read", "Bash(go test:*)"). Only the Claude runner
// uses it; empty with Agent set means no tools.
AllowedTools []string
}
CompletionRequest describes what to send to the LLM.
type ConvMessage ¶
ConvMessage is a single turn in a conversation.
type CopilotRunner ¶
CopilotRunner executes the GitHub Copilot CLI (`copilot`) as an LLM backend. Uses `copilot -p <prompt>` for non-interactive prompt mode with `--allow-all-tools` so the CLI does not pause on tool-permission prompts.
func (CopilotRunner) Complete ¶
func (r CopilotRunner) Complete(ctx context.Context, req CompletionRequest) (<-chan Token, error)
Complete implements LLMRunner by running the Copilot CLI with the given prompt. Stdout is streamed incrementally so the TUI shows progress live.
type DshRunner ¶ added in v0.7.0
type DshRunner struct {
Binary string
Model string // "provider/model"; empty keeps the profile default
}
DshRunner executes the DeepSeek Harness CLI (dsh) in its headless profile as an LLM backend: `dsh --profile headless --json -` reads the task from stdin and writes one JSON event per line to stdout.
type EffortRunner ¶ added in v0.2.1
type EffortRunner struct {
// contains filtered or unexported fields
}
EffortRunner injects a per-agent default effort into requests that do not already carry an explicit one. Explicit per-call effort always wins.
func (*EffortRunner) Complete ¶ added in v0.2.1
func (r *EffortRunner) Complete(ctx context.Context, req CompletionRequest) (<-chan Token, error)
type KeyRejectedError ¶ added in v0.7.0
type KeyRejectedError struct{ Status int }
KeyRejectedError is returned when the provider answers 401 or 403.
func (*KeyRejectedError) Error ¶ added in v0.7.0
func (e *KeyRejectedError) Error() string
type LLMRunner ¶
type LLMRunner interface {
Complete(ctx context.Context, req CompletionRequest) (<-chan Token, error)
}
LLMRunner is the common interface for all LLM backends.
func New ¶
func New(cfg config.AgentConfig, skillLoader *skills.Loader, promptLanguage string) (LLMRunner, error)
New creates an LLMRunner from agent config. skillLoader may be nil — skills will be silently skipped. promptLanguage is accepted for backwards compatibility but ignored: all agents always reply in English regardless of the user's language.
func NewEffortRunner ¶ added in v0.2.1
NewEffortRunner wraps inner with a default effort. An empty effort returns inner unchanged.
type LMStudioRunner ¶
LMStudioRunner calls the LM Studio OpenAI-compatible REST API directly. The local model receives the prompt verbatim and is expected to return plain text (no agentic loop, no tool use).
func NewLMStudioRunner ¶
func NewLMStudioRunner(model string) *LMStudioRunner
func (*LMStudioRunner) Complete ¶
func (r *LMStudioRunner) Complete(ctx context.Context, req CompletionRequest) (<-chan Token, error)
func (*LMStudioRunner) Unload ¶
func (r *LMStudioRunner) Unload(ctx context.Context, model string) error
Unload evicts the given model from LM Studio via the `lms` CLI (`lms unload <model>`). LM Studio's REST API has no documented unload endpoint, so this shells out best-effort: if the `lms` CLI is not on PATH the call is a no-op and returns nil.
type LocalModel ¶
type LocalModel struct {
Runner string // "ollama" | "lmstudio" | "mlx"
Model string
WeightBytes int64 // 0 when the backend does not report a size (heuristic used)
}
LocalModel describes a locally-hosted model discovered on one of the local backends, with its weight size when the backend reports it.
func ListLocalModels ¶
func ListLocalModels() []LocalModel
ListLocalModels enumerates models currently available across the local backends (Ollama, LM Studio, oMLX). Unreachable backends are skipped silently so the result reflects whatever is up right now. Ollama entries include their on-disk weight size; LM Studio and oMLX entries leave WeightBytes at 0 because those servers do not report a reliable size.
type MLXRunner ¶
MLXRunner calls the oMLX OpenAI-compatible REST API directly. The local model receives the prompt verbatim and is expected to return plain text (no agentic loop, no tool use).
func NewMLXRunner ¶
func (*MLXRunner) Unload ¶
Unload is a best-effort no-op for oMLX: the server exposes no documented model-eviction endpoint, so DECSR cannot force an unload. It is defined to satisfy the Unloader interface; callers treat a nil return as "unload attempted". oMLX typically holds a single model and swaps it on the next request anyway.
type MockRunner ¶
type MockRunner struct {
Responses []string
MockUsage *TokenUsage // if set, attached to the Done token of each response
// Requests captures every CompletionRequest passed to Complete, in order.
// Useful for asserting on prompt construction in tests.
Requests []CompletionRequest
// contains filtered or unexported fields
}
MockRunner returns pre-programmed responses for testing.
func (*MockRunner) Complete ¶
func (m *MockRunner) Complete(_ context.Context, req CompletionRequest) (<-chan Token, error)
func (*MockRunner) Reset ¶
func (m *MockRunner) Reset()
Reset resets the response index so the mock can be reused.
type OllamaRunner ¶
type OllamaRunner struct {
Model string
BaseURL string
// NumCtx, when > 0, sets Ollama's num_ctx option so the model loads with a
// bounded context window. This is the primary lever for capping a local
// model's RAM use (the KV cache grows with the context window).
NumCtx int
}
OllamaRunner calls the Ollama REST API directly (/api/chat) instead of shelling out through the Claude Code CLI.
func NewOllamaRunner ¶
func NewOllamaRunner(model string) *OllamaRunner
func (*OllamaRunner) Complete ¶
func (r *OllamaRunner) Complete(ctx context.Context, req CompletionRequest) (<-chan Token, error)
func (*OllamaRunner) Unload ¶
func (r *OllamaRunner) Unload(ctx context.Context, model string) error
Unload asks Ollama to evict the given model from memory immediately by issuing an empty /api/generate request with keep_alive=0. Best-effort: a nil return means the request was accepted, not that eviction is guaranteed.
type OpenAIRunner ¶ added in v0.7.0
type OpenAIRunner struct {
Provider string
Model string
BaseURL string
APIKeyEnv string
CredName string
}
OpenAIRunner calls any OpenAI-compatible chat completions API in text mode: the prompt goes in as-is and plain text comes back (no tools, no agent loop). Provider names the runner in errors. The API key comes from the environment variable named APIKeyEnv, else from the saved credential CredName (default: Provider); it is never part of the config. When BaseURL is empty, a saved custom provider's base URL is used.
func (*OpenAIRunner) Complete ¶ added in v0.7.0
func (r *OpenAIRunner) Complete(ctx context.Context, req CompletionRequest) (<-chan Token, error)
type OpenCodeRunner ¶
OpenCodeRunner executes the OpenCode CLI in non-interactive mode as an LLM backend. Uses `opencode run` with --format json for structured output.
func (OpenCodeRunner) Complete ¶
func (r OpenCodeRunner) Complete(ctx context.Context, req CompletionRequest) (<-chan Token, error)
Complete implements LLMRunner by running the OpenCode CLI with `opencode run`.
type Preset ¶ added in v0.7.0
type Preset struct {
Name string
Label string
BaseURL string
KeyEnv string
DefaultModel string // "" = no default; the user picks one
}
Preset is a hosted OpenAI-compatible provider. Its Name is also a valid `runner:` value; base_url and api_key_env in the config still override it.
func PresetByName ¶ added in v0.7.0
PresetByName finds a preset by its name.
type RateLimitError ¶
type RateLimitError struct {
Provider string
Detail string
// ResetAt is when the provider says the limit lifts. The zero value
// means the response carried no usable reset time.
ResetAt time.Time
}
RateLimitError carries provider-specific context about a rate-limit hit while still satisfying errors.Is(err, ErrRateLimited).
func ClassifyRateLimit ¶
func ClassifyRateLimit(provider string, fragments ...string) *RateLimitError
ClassifyRateLimit returns a non-nil *RateLimitError when any of the given text fragments contains a known rate-limit marker. Returns nil otherwise.
func (*RateLimitError) Error ¶
func (e *RateLimitError) Error() string
func (*RateLimitError) Is ¶
func (e *RateLimitError) Is(target error) bool
type SkillRunner ¶
type SkillRunner struct {
// contains filtered or unexported fields
}
SkillRunner wraps an LLMRunner and injects skill content into system prompts. Agent responses are always English; the user-language directive has been removed to keep agent output uniform across locales.
func (*SkillRunner) Complete ¶
func (r *SkillRunner) Complete(ctx context.Context, req CompletionRequest) (<-chan Token, error)
type Token ¶
type Token struct {
Text string
// Reasoning is display-only chain-of-thought from reasoning models. It is
// shown live in the UI but NOT included in the returned/parsed result.
Reasoning string
// Activity is a structured item of agent work (thinking, a command, a file
// edit, ...). A token carries Text or an Activity, never relied on for both.
// An Activity with the same ID as an earlier one replaces it.
Activity *Activity
Done bool
Error error
Usage *TokenUsage // non-nil only on the Done token
}
Token is a single streaming chunk from an LLM.
type TokenUsage ¶
TokenUsage holds token counts for a single LLM completion. Estimated is true when the count was derived from a heuristic (chars÷4) rather than actual API data.