Documentation
¶
Overview ¶
Package config resolves runtime configuration from command-line flags, environment variables, and sensible defaults, in that order of precedence.
Index ¶
Examples ¶
Constants ¶
const ( // EngineAuto picks the first installed session provider and falls back to // Ollama if a call fails (offline). This is the default. EngineAuto = "auto" // EngineOllama forces the local Ollama backend and never touches a session // CLI or the network. EngineOllama = "ollama" )
Engine selection sentinels. Any other value names a specific session provider (claude, codex, agy, copilot, cursor-agent, amp, crush, goose, grok, ...).
const ( // DefaultReader is the fast plain-text reader; see internal/pdf.Readers. DefaultReader = "pdftotext" DefaultOllamaModel = "gemma3:4b" DefaultExtractModel = "gemma3:4b" DefaultEditModel = "gemma3:4b" DefaultContextLen = 8192 DefaultPredictLen = 6000 DefaultWriteRetries = 2 DefaultMaxContinue = 3 DefaultExtractConcurrency = 4 OllamaHost = "http://127.0.0.1:11434" FocusBlock = 25 * time.Minute // DefaultCallTimeout bounds a single generation call. Generation is slow — // a full article on a small local model can run for many minutes — so the // ceiling is generous; its job is only to stop a wedged provider CLI or a // black-holed HTTP connection from hanging the run forever. Set // DRAFT_CALL_TIMEOUT=0 to disable it. DefaultCallTimeout = 30 * time.Minute )
Defaults captured as constants so they are documented in one place.
All three Ollama stages default to gemma3:4b. On a memory-constrained machine a single shared model means the server never swaps a second 4B model in and out between extraction and writing. gemma also follows the writing brief far more closely than qwen3:4b, which tended to overshoot the word budget and leak its own planning text into the article.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Engine string // "auto", "ollama", or a session provider name
// Per-stage engine overrides. Empty means "use Engine". Extraction is a
// dozen cheap, mechanical calls per paper while writing is one
// quality-critical call, so routing them separately lets a local model do
// the bulk without spending session quota on it.
ExtractEngine string // DRAFT_EXTRACT_ENGINE
WriteEngine string // DRAFT_WRITE_ENGINE
EditEngine string // DRAFT_EDIT_ENGINE
// Reader names the document reader: "pdftotext" (default) or "docling".
// See internal/pdf for what each trades.
Reader string // DRAFT_READER
// Style is the editorial policy the writer follows and the validator
// enforces: word band, banned vocabulary, language variant. It defaults
// to draft's house style and is replaced by a --style / DRAFT_STYLE file.
Style rules.Style
// StylePath is the file the style was loaded from, for display and doctor.
StylePath string
Model string // session-provider model override ("" = provider default)
OllamaModel string // writing model for the Ollama backend
ExtractModel string // claim-extraction model for the Ollama backend
EditModel string // surgical-review model for the Ollama backend
ContextLength int
PredictLength int
WriteRetries int
MaxContinue int // max length-driven continuations for a single generation
ExtractConcurrency int // parallel claim-extraction workers (session engines only)
ForceNew bool
Merge bool // combine every input into one draft instead of queueing
Resume bool // reuse a verified claim ledger from an earlier attempt
KeepArtifacts bool // keep prompt/ledger files beside a successful draft
Experimental bool // let auto-selection consider experimental providers
// StrictNumbers blocks a save when the article carries a number that
// appears in no verified claim, instead of only warning.
StrictNumbers bool
OllamaHost string
// CallTimeout bounds a single generation call (0 = no timeout).
CallTimeout time.Duration
HomeDir string
SourcesDir string
DraftsDir string
// CacheDir holds cached claim extractions, addressed by content. Empty
// disables caching entirely.
CacheDir string
// Version is the release of draft that is running, set by the binary
// rather than read from the environment. It is written into every
// article's provenance, so a reader can tell which draft made it.
Version string
// Warnings records configuration problems that were recovered from rather
// than fatal: an unreadable home directory, an out-of-range tunable, a
// non-loopback Ollama host. The CLI prints them to stderr so a silent
// fallback is never mistaken for the configuration the user asked for.
Warnings []string
}
Config is the fully-resolved run configuration shared across packages.
func Load ¶
Load builds a Config from defaults, overlays environment variables, then overlays the already-parsed flag values passed in from the caller.
Example ¶
Flags win over environment variables, which win over defaults.
package main
import (
"fmt"
"github.com/sebastienrousseau/draft/config"
)
func main() {
cfg := config.Load(config.Flags{Engine: "ollama", ContextLength: 2048})
fmt.Println(cfg.Engine, cfg.ContextLength)
}
Output: ollama 2048
type Flags ¶
type Flags struct {
Engine string
ExtractEngine string
WriteEngine string
Reader string
Style string
Model string
ContextLength int
PredictLength int
// DraftsDir and SourcesDir override where finished drafts are written and
// where bare filenames are resolved from. Empty means the default.
DraftsDir string
SourcesDir string
ForceNew bool
Merge bool
Resume bool
KeepArtifacts bool
Experimental bool
StrictNumbers bool
NoCache bool
}
Flags holds the raw command-line values before they are merged into a Config.