Documentation
¶
Overview ¶
Package config loads TOML configuration and environment-backed runtime overrides for the kb CLI.
Index ¶
- Constants
- Variables
- func ApplyEnvOverrides(cfg *Config)
- func DiscoverProjectConfigPath(cwd string) (string, bool, error)
- func LoadDotEnvIfPresent(path string) error
- func ResolveVaultRoot(configPath string, cfg VaultConfig) (string, error)
- func ValidateThresholds(field string, thresholds map[string]float64) error
- type AppConfig
- type Config
- type DecisionsConfig
- type FirecrawlConfig
- type GenerationConfig
- type InstagramConfig
- type LogConfig
- type OKFConfig
- type OpenRouterConfig
- type STTConfig
- type VaultConfig
- type YouTubeConfig
Constants ¶
const ( // DecisionModeShadow records would-be outcomes without moving, skipping or // inserting anything. DecisionModeShadow = "shadow" // DecisionModeApply lets decisions change files. DecisionModeApply = "apply" )
Decision modes accepted by `[decisions].mode`.
const ( // DefaultDotEnvPath is the local dotenv file loaded by the CLI entrypoint. DefaultDotEnvPath = ".env" // ProjectConfigFileName is the default repository-local kb config file. ProjectConfigFileName = "kb.toml" // EnvConfigPath overrides the config file path. EnvConfigPath = "APP_CONFIG" // EnvFirecrawlAPIKey stores the Firecrawl API key override. EnvFirecrawlAPIKey = "FIRECRAWL_API_KEY" // EnvFirecrawlAPIURL stores the Firecrawl API URL override. EnvFirecrawlAPIURL = "FIRECRAWL_API_URL" // EnvOpenRouterAPIKey stores the OpenRouter API key override. EnvOpenRouterAPIKey = "OPENROUTER_API_KEY" // EnvOpenRouterAPIURL stores the OpenRouter API URL override. EnvOpenRouterAPIURL = "OPENROUTER_API_URL" // EnvDecisionsModel overrides `[decisions].model`. EnvDecisionsModel = "KB_DECISIONS_MODEL" // EnvGenerationModel overrides `[generation].model`. EnvGenerationModel = "KB_GENERATION_MODEL" // EnvOpenAIAPIKey stores the OpenAI API key override for STT. EnvOpenAIAPIKey = "OPENAI_API_KEY" // EnvOpenAIAPIURL stores the OpenAI API URL override for STT. EnvOpenAIAPIURL = "OPENAI_API_URL" // EnvSTTProvider stores the STT provider override. EnvSTTProvider = "STT_PROVIDER" // EnvSTTModel stores the STT model override. EnvSTTModel = "STT_MODEL" // EnvYouTubeProxy stores the YouTube proxy URL override. EnvYouTubeProxy = "YOUTUBE_PROXY" // EnvYouTubeYTDLPPath stores the yt-dlp executable path override. EnvYouTubeYTDLPPath = "YOUTUBE_YT_DLP_PATH" // EnvYouTubeCookiesFile stores the YouTube cookies file override. EnvYouTubeCookiesFile = "YOUTUBE_COOKIES_FILE" // EnvYouTubeUserAgent stores the YouTube user agent override. EnvYouTubeUserAgent = "YOUTUBE_USER_AGENT" // EnvYouTubeCaptionLanguages stores the caption language preference override. EnvYouTubeCaptionLanguages = "YOUTUBE_CAPTION_LANGUAGES" )
Variables ¶
var KnownThresholdNames = []string{
"link_apply",
"link_review",
"mention_sense",
"affects",
"relevance_quarantine",
"relevance_review",
"relevance_fetch",
"quality_apply",
"quality_review",
"duplicate",
"primary_concept",
"concept_noul",
"find_keep",
"find_window",
"okf_type",
"contract_conflict",
}
KnownThresholdNames lists every threshold name accepted by `[decisions.thresholds]` (spec §12.3). internal/decisions.DefaultThresholds carries one default per name and a test there keeps both lists identical. The list lives here because internal/decisions imports internal/config.
Functions ¶
func ApplyEnvOverrides ¶
func ApplyEnvOverrides(cfg *Config)
ApplyEnvOverrides overlays config values that are sourced from environment variables at runtime.
func DiscoverProjectConfigPath ¶ added in v0.0.6
DiscoverProjectConfigPath walks up from cwd looking for kb.toml.
func LoadDotEnvIfPresent ¶
LoadDotEnvIfPresent loads a local dotenv file without overriding env vars already supplied by the shell or process manager.
func ResolveVaultRoot ¶ added in v0.0.6
func ResolveVaultRoot(configPath string, cfg VaultConfig) (string, error)
ResolveVaultRoot resolves cfg.Root relative to the directory containing configPath when cfg.Root is relative.
func ValidateThresholds ¶ added in v0.0.11
ValidateThresholds checks that every name is in KnownThresholdNames and every value is within [0, 1]. field prefixes error messages (for example "decisions.thresholds" or a topic.yaml path).
Types ¶
type Config ¶
type Config struct {
App AppConfig `toml:"app"`
Log LogConfig `toml:"log"`
Vault VaultConfig `toml:"vault"`
OKF OKFConfig `toml:"okf"`
Firecrawl FirecrawlConfig `toml:"firecrawl"`
OpenRouter OpenRouterConfig `toml:"openrouter"`
STT STTConfig `toml:"stt"`
YouTube YouTubeConfig `toml:"youtube"`
Instagram InstagramConfig `toml:"instagram"`
Decisions DecisionsConfig `toml:"decisions"`
Generation GenerationConfig `toml:"generation"`
}
Config contains the complete TOML-backed runtime configuration.
type DecisionsConfig ¶ added in v0.0.11
type DecisionsConfig struct {
// Model is the pinned decision model slug.
Model string `toml:"model"`
// Deadline is the total deadline of one attempt, body read included.
Deadline string `toml:"deadline"`
// Retries is the number of retries after the first attempt on transient
// failures (408/429/5xx, network errors, timeouts). Zero disables retries.
Retries int `toml:"retries"`
// Concurrency is the number of decision requests in flight per run.
Concurrency int `toml:"concurrency"`
// MaxStateBytes caps the canonical JSON size of one decision state.
MaxStateBytes int `toml:"max_state_bytes"`
// BudgetUSD is the default per-run spend ceiling shared with generation.
BudgetUSD float64 `toml:"budget_usd"`
// Mode is the default decision mode: shadow or apply.
Mode string `toml:"mode"`
// Thresholds overrides named thresholds (see KnownThresholdNames).
Thresholds map[string]float64 `toml:"thresholds"`
}
DecisionsConfig controls the decision model (Jev over OpenRouter Decisions). The API key and URL are shared with [openrouter].
func (DecisionsConfig) DeadlineDuration ¶ added in v0.0.11
func (c DecisionsConfig) DeadlineDuration() (time.Duration, error)
DeadlineDuration parses the per-attempt decision deadline.
func (DecisionsConfig) Validate ¶ added in v0.0.11
func (c DecisionsConfig) Validate() error
Validate ensures decision-model settings are usable.
type FirecrawlConfig ¶
type FirecrawlConfig struct {
APIKey string `toml:"api_key"`
APIURL string `toml:"api_url"`
// RefetchWaitMS is the `waitFor` sent on the fresh refetch that runs before
// a quality gate judges a thin or broken capture (spec §7 stage 4).
RefetchWaitMS int `toml:"refetch_wait_ms"`
// RefetchOnlyMainContent is the `onlyMainContent` sent on that refetch;
// false keeps tables and pricing grids the main-content filter drops.
RefetchOnlyMainContent bool `toml:"refetch_only_main_content"`
}
FirecrawlConfig controls URL scraping API access.
func (FirecrawlConfig) Validate ¶ added in v0.0.11
func (c FirecrawlConfig) Validate() error
Validate ensures Firecrawl refetch settings are usable.
type GenerationConfig ¶ added in v0.0.11
type GenerationConfig struct {
// Model is the primary chat-completions model.
Model string `toml:"model"`
// FallbackModel is tried once after the primary model fails; empty
// disables the fallback.
FallbackModel string `toml:"fallback_model"`
// Deadline is the total deadline of one attempt.
Deadline string `toml:"deadline"`
// Retries is the number of retries per model after the first attempt.
Retries int `toml:"retries"`
// SummaryLanguage is the language generated summaries are written in.
SummaryLanguage string `toml:"summary_language"`
}
GenerationConfig controls the generation model used for short literals (summaries, aliases, criteria, drafts).
func (GenerationConfig) DeadlineDuration ¶ added in v0.0.11
func (c GenerationConfig) DeadlineDuration() (time.Duration, error)
DeadlineDuration parses the per-attempt generation deadline.
func (GenerationConfig) Validate ¶ added in v0.0.11
func (c GenerationConfig) Validate() error
Validate ensures generation-model settings are usable.
type InstagramConfig ¶ added in v0.0.10
type InstagramConfig struct {
YTDLPPath string `toml:"yt_dlp_path"`
Proxy string `toml:"proxy"`
CookiesFile string `toml:"cookies_file"`
UserAgent string `toml:"user_agent"`
Transcription string `toml:"transcription"`
RetryAttempts int `toml:"retry_attempts"`
RetryBackoff string `toml:"retry_backoff"`
}
InstagramConfig controls Instagram network access and retry behavior for `kb ingest instagram`. Cookies are kept separate from YouTube because the two platforms require distinct authenticated sessions.
func (InstagramConfig) RetryBackoffDuration ¶ added in v0.0.10
func (c InstagramConfig) RetryBackoffDuration() (time.Duration, error)
RetryBackoffDuration parses the configured Instagram retry backoff.
func (InstagramConfig) Validate ¶ added in v0.0.10
func (c InstagramConfig) Validate() error
Validate ensures Instagram runtime settings are usable.
type LogConfig ¶
type LogConfig struct {
Level string `toml:"level"`
}
LogConfig controls structured logging output.
type OKFConfig ¶ added in v0.0.11
type OKFConfig struct {
Types []string `toml:"types"`
// TypeDescriptions maps a type name to the description used as its option
// text when the decision model suggests a type (`kb promote` without
// --type, `kb okf check`). Types without a description use their name.
TypeDescriptions map[string]string `toml:"type_descriptions"`
}
OKFConfig controls local Open Knowledge Format producer standards.
func (OKFConfig) TypeDescription ¶ added in v0.0.11
TypeDescription returns the configured description of an OKF type, or the type name itself when none is configured.
type OpenRouterConfig ¶
type OpenRouterConfig struct {
APIKey string `toml:"api_key"`
APIURL string `toml:"api_url"`
STTModel string `toml:"stt_model"`
}
OpenRouterConfig controls OpenRouter access: the optional STT provider plus the API key and URL shared by the decision and generation clients.
type STTConfig ¶ added in v0.0.8
type STTConfig struct {
Provider string `toml:"provider"`
APIKey string `toml:"api_key"`
APIURL string `toml:"api_url"`
Model string `toml:"model"`
Language string `toml:"language"`
Prompt string `toml:"prompt"`
AudioFormat string `toml:"audio_format"`
ChunkDuration string `toml:"chunk_duration"`
MaxChunkBytes int64 `toml:"max_chunk_bytes"`
Concurrency int `toml:"concurrency"`
FFmpegPath string `toml:"ffmpeg_path"`
}
STTConfig controls speech-to-text provider selection and audio chunking.
func (STTConfig) ChunkDurationValue ¶ added in v0.0.8
ChunkDurationValue parses the configured STT chunk duration.
type VaultConfig ¶ added in v0.0.6
VaultConfig controls vault root discovery and topic enumeration.
func (VaultConfig) Validate ¶ added in v0.0.6
func (c VaultConfig) Validate() error
Validate ensures vault discovery settings are usable.
type YouTubeConfig ¶ added in v0.0.6
type YouTubeConfig struct {
YTDLPPath string `toml:"yt_dlp_path"`
Proxy string `toml:"proxy"`
CookiesFile string `toml:"cookies_file"`
UserAgent string `toml:"user_agent"`
Transcription string `toml:"transcription"`
RetryAttempts int `toml:"retry_attempts"`
RetryBackoff string `toml:"retry_backoff"`
// CaptionLanguages controls caption track selection. "orig" means the
// video's original language as reported by yt-dlp metadata.
CaptionLanguages []string `toml:"caption_languages"`
AllowTranslatedCaptions bool `toml:"allow_translated_captions"`
// Bulk* control the kb ingest channel worker pool, inter-request throttle,
// and adaptive backoff used when ingesting an entire channel or playlist.
BulkConcurrency int `toml:"bulk_concurrency"`
BulkThrottle string `toml:"bulk_throttle"`
BulkBackoffMax string `toml:"bulk_backoff_max"`
BulkRetries int `toml:"bulk_retries"`
}
YouTubeConfig controls YouTube network access and retry behavior.
func (YouTubeConfig) BulkBackoffMaxDuration ¶ added in v0.0.10
func (c YouTubeConfig) BulkBackoffMaxDuration() (time.Duration, error)
BulkBackoffMaxDuration parses the configured adaptive backoff ceiling for bulk channel ingestion.
func (YouTubeConfig) BulkThrottleDuration ¶ added in v0.0.10
func (c YouTubeConfig) BulkThrottleDuration() (time.Duration, error)
BulkThrottleDuration parses the configured inter-request throttle for bulk channel ingestion.
func (YouTubeConfig) RetryBackoffDuration ¶ added in v0.0.6
func (c YouTubeConfig) RetryBackoffDuration() (time.Duration, error)
RetryBackoffDuration parses the configured retry backoff.
func (YouTubeConfig) Validate ¶ added in v0.0.6
func (c YouTubeConfig) Validate() error
Validate ensures YouTube runtime settings are usable.