config

package
v0.0.32 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package config defines the klausctl configuration types and handles loading from the user's config file.

Index

Constants

View Source
const (
	// DefaultSourceName is the built-in source that cannot be removed.
	DefaultSourceName = "giantswarm"
	// DefaultSourceRegistry is the registry base for the built-in source.
	DefaultSourceRegistry = "gsoci.azurecr.io/giantswarm"

	// ClearOverride is a sentinel value for Update that resets an override
	// field back to the convention-based default (i.e. clears it to "").
	ClearOverride = "-"
)

Variables

This section is empty.

Functions

func AggregateFromSources added in v0.0.23

func AggregateFromSources[T any](registries []SourceRegistry, artifactType string, fetchFn func(sr SourceRegistry) ([]T, error)) ([]T, []string, error)

AggregateFromSources calls fetchFn for each registry and aggregates results. On multi-source queries, individual source failures are collected as warnings rather than aborting. If all sources fail, an error is returned.

func EnsureDir

func EnsureDir(path string) error

EnsureDir creates a directory and all parents if they don't exist.

func ExpandPath

func ExpandPath(path string) string

ExpandPath expands ~ to the user's home directory and resolves the path. Note: only ~/... and bare ~ are supported; ~user syntax is not handled.

func MigrateLayout added in v0.0.11

func MigrateLayout(paths *Paths) error

MigrateLayout migrates legacy single-instance layout into instances/default. It is safe to call repeatedly.

func NextAvailablePort added in v0.0.11

func NextAvailablePort(paths *Paths, start int) (int, error)

NextAvailablePort returns the lowest free port >= start.

func UsedPorts added in v0.0.11

func UsedPorts(paths *Paths) (map[int]bool, error)

UsedPorts returns ports currently known in config or instance state files.

func ValidateInstanceName added in v0.0.11

func ValidateInstanceName(name string) error

ValidateInstanceName validates a named instance using DNS-label rules.

func ValidateSourceName added in v0.0.23

func ValidateSourceName(name string) error

ValidateSourceName checks that a source name is valid.

Types

type AgentConfig

type AgentConfig struct {
	Description     string         `yaml:"description" json:"description"`
	Prompt          string         `yaml:"prompt" json:"prompt"`
	Tools           []string       `yaml:"tools,omitempty" json:"tools,omitempty"`
	DisallowedTools []string       `yaml:"disallowedTools,omitempty" json:"disallowedTools,omitempty"`
	Model           string         `yaml:"model,omitempty" json:"model,omitempty"`
	PermissionMode  string         `yaml:"permissionMode,omitempty" json:"permissionMode,omitempty"`
	MaxTurns        int            `yaml:"maxTurns,omitempty" json:"maxTurns,omitempty"`
	Skills          []string       `yaml:"skills,omitempty" json:"skills,omitempty"`
	McpServers      map[string]any `yaml:"mcpServers,omitempty" json:"mcpServers,omitempty"`
	Hooks           map[string]any `yaml:"hooks,omitempty" json:"hooks,omitempty"`
	Memory          string         `yaml:"memory,omitempty" json:"memory,omitempty"`
}

AgentConfig defines a JSON-format subagent (highest priority). This mirrors the klaus AgentConfig type.

type AgentFile

type AgentFile struct {
	// Content is the raw markdown content for the agent file.
	Content string `yaml:"content"`
}

AgentFile defines a markdown-format subagent file.

type ClaudeConfig

type ClaudeConfig struct {
	// Model is the Claude model (e.g. "sonnet", "opus", "claude-sonnet-4-20250514").
	Model string `yaml:"model,omitempty"`
	// SystemPrompt overrides the default system prompt.
	SystemPrompt string `yaml:"systemPrompt,omitempty"`
	// AppendSystemPrompt appends to the default system prompt.
	AppendSystemPrompt string `yaml:"appendSystemPrompt,omitempty"`
	// MaxTurns limits agentic turns per prompt; 0 means unlimited.
	MaxTurns int `yaml:"maxTurns,omitempty"`
	// PermissionMode controls tool permissions: "default", "acceptEdits",
	// "bypassPermissions", "dontAsk", "plan", "delegate".
	PermissionMode string `yaml:"permissionMode,omitempty"`
	// MaxBudgetUSD caps the maximum dollar spend per invocation; 0 means no limit.
	MaxBudgetUSD float64 `yaml:"maxBudgetUsd,omitempty"`
	// Effort controls effort level: "low", "medium", "high".
	Effort string `yaml:"effort,omitempty"`
	// FallbackModel specifies a model to use when the primary is overloaded.
	FallbackModel string `yaml:"fallbackModel,omitempty"`
	// Tools controls the base set of built-in tools.
	Tools []string `yaml:"tools,omitempty"`
	// AllowedTools restricts tool access with patterns.
	AllowedTools []string `yaml:"allowedTools,omitempty"`
	// DisallowedTools blocks specific tools.
	DisallowedTools []string `yaml:"disallowedTools,omitempty"`
	// StrictMcpConfig when true only uses MCP servers from config.
	StrictMcpConfig bool `yaml:"strictMcpConfig,omitempty"`
	// McpTimeout sets the MCP call timeout in milliseconds.
	McpTimeout int `yaml:"mcpTimeout,omitempty"`
	// MaxMcpOutputTokens limits MCP server output token count.
	MaxMcpOutputTokens int `yaml:"maxMcpOutputTokens,omitempty"`
	// ActiveAgent selects which agent runs as the top-level agent.
	ActiveAgent string `yaml:"activeAgent,omitempty"`
	// PersistentMode enables bidirectional stream-json mode.
	PersistentMode bool `yaml:"persistentMode,omitempty"`
	// NoSessionPersistence disables saving sessions to disk.
	NoSessionPersistence *bool `yaml:"noSessionPersistence,omitempty"`
	// IncludePartialMessages enables streaming of partial messages.
	IncludePartialMessages bool `yaml:"includePartialMessages,omitempty"`
	// JsonSchema provides a JSON schema for structured output.
	JsonSchema string `yaml:"jsonSchema,omitempty"`
	// SettingsFile is an alternative to inline hooks -- a path to a settings.json.
	// Mutually exclusive with Hooks.
	SettingsFile string `yaml:"settingsFile,omitempty"`
	// SettingSources controls setting source precedence.
	SettingSources string `yaml:"settingSources,omitempty"`
	// LoadAdditionalDirsMemory enables loading CLAUDE.md memory files from
	// additional directories. Defaults to true, matching the Helm chart default.
	LoadAdditionalDirsMemory *bool `yaml:"loadAdditionalDirsMemory,omitempty"`
	// AddDirs are additional directories for skills and agents.
	AddDirs []string `yaml:"addDirs,omitempty"`
	// PluginDirs are directories to load plugins from.
	PluginDirs []string `yaml:"pluginDirs,omitempty"`
}

ClaudeConfig contains Claude Code agent configuration, mirroring the Helm values.claude section.

type Config

type Config struct {
	// Runtime is the container runtime: "docker" or "podman".
	// Auto-detected if empty.
	Runtime string `yaml:"runtime,omitempty"`

	// Personality is an OCI reference to a personality artifact that defines
	// the AI's identity (SOUL.md) and a curated set of plugins. Instance-level
	// config (image, plugins) composes with and can override personality values.
	Personality string `yaml:"personality,omitempty"`

	// Image is the klaus container image reference.
	Image string `yaml:"image"`

	// Toolchain is the configured toolchain reference used to resolve Image.
	// This preserves the user's intent in per-instance config metadata.
	Toolchain string `yaml:"toolchain,omitempty"`

	// Workspace is the host directory to mount into the container at /workspace.
	Workspace string `yaml:"workspace"`

	// Port is the host port mapped to the container's MCP endpoint (8080).
	Port int `yaml:"port"`

	// Claude contains Claude Code agent configuration.
	Claude ClaudeConfig `yaml:"claude,omitempty"`

	// Skills defines inline skills rendered as SKILL.md files.
	Skills map[string]Skill `yaml:"skills,omitempty"`

	// AgentFiles defines markdown-format subagent definitions rendered as .claude/agents/<name>.md.
	AgentFiles map[string]AgentFile `yaml:"agentFiles,omitempty"`

	// Agents defines JSON-format subagents passed via CLAUDE_AGENTS env var (highest priority).
	Agents map[string]AgentConfig `yaml:"agents,omitempty"`

	// Hooks defines lifecycle hooks rendered to settings.json.
	Hooks map[string][]HookMatcher `yaml:"hooks,omitempty"`

	// HookScripts defines hook script contents mounted at /etc/klaus/hooks/<name>.
	HookScripts map[string]string `yaml:"hookScripts,omitempty"`

	// McpServers defines MCP server entries rendered to .mcp.json format.
	McpServers map[string]any `yaml:"mcpServers,omitempty"`

	// Plugins references OCI plugins pulled before container start.
	Plugins []Plugin `yaml:"plugins,omitempty"`

	// EnvForward lists host environment variable names to forward to the container.
	// ANTHROPIC_API_KEY is always forwarded if set.
	EnvForward []string `yaml:"envForward,omitempty"`

	// EnvVars sets explicit environment variable key-value pairs in the container.
	EnvVars map[string]string `yaml:"envVars,omitempty"`

	// SecretEnvVars maps container env var names to secret store names.
	// At start time each secret is resolved and injected as an env var.
	SecretEnvVars map[string]string `yaml:"secretEnvVars,omitempty"`

	// SecretFiles maps container file paths to secret store names.
	// At start time each secret is resolved, written to rendered/secrets/,
	// and mounted read-only into the container at the specified path.
	SecretFiles map[string]string `yaml:"secretFiles,omitempty"`

	// McpServerRefs lists managed MCP server names to include.
	// At start time each reference is resolved from the global mcpservers.yaml
	// and merged into McpServers with a Bearer token header.
	McpServerRefs []string `yaml:"mcpServerRefs,omitempty"`
	// contains filtered or unexported fields
}

Config represents the klausctl configuration file at ~/.config/klausctl/config.yaml. The structure intentionally mirrors the Helm chart values so that knowledge transfers between local, standalone, and operator-managed modes.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a minimal default configuration with all defaults applied. Note: Workspace must be set by the caller before the config can pass Validate().

func GenerateInstanceConfig added in v0.0.11

func GenerateInstanceConfig(paths *Paths, opts CreateOptions) (*Config, error)

GenerateInstanceConfig builds a per-instance configuration from create options.

func Load

func Load(path string) (*Config, error)

Load reads and parses the configuration file. If path is empty, the default path (~/.config/klausctl/config.yaml) is used.

func (*Config) ImageExplicitlySet added in v0.0.10

func (c *Config) ImageExplicitlySet() bool

ImageExplicitlySet reports whether the Image field was explicitly set in the config file (before defaults were applied). When false, a personality's image takes precedence.

func (*Config) Marshal

func (c *Config) Marshal() ([]byte, error)

Marshal serializes the config to YAML.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks the configuration for errors.

type CreateOptions added in v0.0.11

type CreateOptions struct {
	Name        string
	Workspace   string
	Personality string
	Toolchain   string
	Plugins     []string
	Port        int

	// Override fields applied after personality resolution.
	EnvVars        map[string]string
	EnvForward     []string
	McpServers     map[string]any
	SecretEnvVars  map[string]string
	SecretFiles    map[string]string
	McpServerRefs  []string
	MaxBudgetUSD   *float64
	PermissionMode string
	Model          string
	SystemPrompt   string

	// SourceResolver provides multi-source artifact resolution.
	// When nil, the default built-in source is used.
	SourceResolver *SourceResolver

	// Context and Output are passed to ResolvePersonality when provided.
	Context context.Context
	Output  io.Writer

	// ResolvePersonality optionally resolves and pulls a personality reference.
	// Keeping this as a callback avoids package cycles while allowing
	// GenerateInstanceConfig to encapsulate create-time merge behavior.
	ResolvePersonality func(ctx context.Context, ref string, w io.Writer) (*ResolvedPersonality, error)
}

CreateOptions defines user-facing parameters for klausctl create.

type Hook

type Hook struct {
	Type    string `yaml:"type" json:"type"`
	Command string `yaml:"command" json:"command"`
	Timeout int    `yaml:"timeout,omitempty" json:"timeout,omitempty"`
}

Hook defines a single hook action.

type HookMatcher

type HookMatcher struct {
	Matcher string `yaml:"matcher" json:"matcher"`
	Hooks   []Hook `yaml:"hooks" json:"hooks"`
}

HookMatcher defines a hook matcher entry for settings.json.

type Paths

type Paths struct {
	// ConfigDir is the base config directory (~/.config/klausctl).
	ConfigDir string
	// ConfigFile is the path to the config file.
	ConfigFile string
	// InstancesDir is the directory containing all named instances.
	InstancesDir string
	// InstanceDir is the directory for the selected instance.
	InstanceDir string
	// RenderedDir is where rendered config files are written.
	RenderedDir string
	// ExtensionsDir is the rendered extensions directory (skills, agents).
	ExtensionsDir string
	// PluginsDir is where OCI plugins are stored.
	PluginsDir string
	// PersonalitiesDir is where OCI personalities are stored.
	PersonalitiesDir string
	// InstanceFile is the path to the instance state file.
	InstanceFile string
	// SecretsFile is the path to the secrets store (~/.config/klausctl/secrets.yaml).
	SecretsFile string
	// McpServersFile is the path to the managed MCP servers file (~/.config/klausctl/mcpservers.yaml).
	McpServersFile string
	// SourcesFile is the path to the sources configuration file (~/.config/klausctl/sources.yaml).
	SourcesFile string
}

Paths holds the filesystem paths used by klausctl.

func DefaultPaths

func DefaultPaths() (*Paths, error)

DefaultPaths returns the default paths using XDG conventions. It returns an error if the user home directory cannot be determined and XDG_CONFIG_HOME is not set.

func (*Paths) ForInstance added in v0.0.11

func (p *Paths) ForInstance(name string) *Paths

ForInstance returns a copy of paths scoped to one instance directory.

type Plugin

type Plugin struct {
	Repository string `yaml:"repository"`
	Tag        string `yaml:"tag,omitempty"`
	Digest     string `yaml:"digest,omitempty"`
}

Plugin references an OCI plugin artifact.

func ParsePluginRef added in v0.0.11

func ParsePluginRef(ref string) Plugin

ParsePluginRef resolves a plugin reference into config.Plugin fields using the default built-in source.

func ParsePluginRefWith added in v0.0.23

func ParsePluginRefWith(ref string, resolver *SourceResolver) Plugin

ParsePluginRefWith resolves a plugin reference into config.Plugin fields using the provided SourceResolver.

type ResolvedPersonality added in v0.0.11

type ResolvedPersonality struct {
	Plugins []Plugin
	Image   string
}

ResolvedPersonality contains personality-derived values merged into config.

type Skill

type Skill struct {
	// Description is a short description of the skill.
	Description string `yaml:"description,omitempty"`
	// Content is the skill's markdown body.
	Content string `yaml:"content"`
	// DisableModelInvocation prevents the model from invoking this skill automatically.
	DisableModelInvocation bool `yaml:"disableModelInvocation,omitempty"`
	// UserInvocable marks the skill as invocable by the user.
	UserInvocable bool `yaml:"userInvocable,omitempty"`
	// AllowedTools restricts which tools the skill can use.
	AllowedTools string `yaml:"allowedTools,omitempty"`
	// Model overrides the model for this skill.
	Model string `yaml:"model,omitempty"`
	// Context provides additional context for the skill.
	Context any `yaml:"context,omitempty"`
	// Agent associates the skill with a specific agent.
	Agent string `yaml:"agent,omitempty"`
	// ArgumentHint provides a hint for the skill's argument.
	ArgumentHint string `yaml:"argumentHint,omitempty"`
}

Skill defines an inline Claude Code skill rendered as a SKILL.md file.

type Source added in v0.0.23

type Source struct {
	Name          string `yaml:"name"`
	Registry      string `yaml:"registry"`
	Default       bool   `yaml:"default,omitempty"`
	Toolchains    string `yaml:"toolchains,omitempty"`
	Personalities string `yaml:"personalities,omitempty"`
	Plugins       string `yaml:"plugins,omitempty"`
}

Source is a named OCI registry providing toolchains, personalities, and/or plugins.

func (Source) PersonalityRegistry added in v0.0.23

func (s Source) PersonalityRegistry() string

PersonalityRegistry returns the personality base path for this source. Falls back to convention: <registry>/klaus-personalities

func (Source) PluginRegistry added in v0.0.23

func (s Source) PluginRegistry() string

PluginRegistry returns the plugin base path for this source. Falls back to convention: <registry>/klaus-plugins

func (Source) ToolchainRegistry added in v0.0.23

func (s Source) ToolchainRegistry() string

ToolchainRegistry returns the toolchain base path for this source. Falls back to convention: <registry>/klaus-toolchains

type SourceConfig added in v0.0.23

type SourceConfig struct {
	Sources []Source `yaml:"sources"`
	// contains filtered or unexported fields
}

SourceConfig holds the list of configured sources.

func DefaultSourceConfig added in v0.0.23

func DefaultSourceConfig() *SourceConfig

DefaultSourceConfig returns a source config with only the built-in source.

func LoadSourceConfig added in v0.0.23

func LoadSourceConfig(path string) (*SourceConfig, error)

LoadSourceConfig reads and parses the sources configuration file. If the file does not exist, the default config (built-in source only) is returned.

func (*SourceConfig) Add added in v0.0.23

func (sc *SourceConfig) Add(s Source) error

Add adds a new source. Returns an error if a source with the same name already exists.

func (*SourceConfig) Get added in v0.0.23

func (sc *SourceConfig) Get(name string) *Source

Get returns the source with the given name, or nil if not found.

func (*SourceConfig) Remove added in v0.0.23

func (sc *SourceConfig) Remove(name string) error

Remove removes a source by name. The built-in source cannot be removed.

func (*SourceConfig) Save added in v0.0.23

func (sc *SourceConfig) Save() error

Save writes the source config to disk.

func (*SourceConfig) SaveTo added in v0.0.23

func (sc *SourceConfig) SaveTo(path string) error

SaveTo writes the source config to the specified path.

func (*SourceConfig) SetDefault added in v0.0.23

func (sc *SourceConfig) SetDefault(name string) error

SetDefault marks the named source as default (and clears default on all others).

func (*SourceConfig) Update added in v0.0.23

func (sc *SourceConfig) Update(name string, patch Source) error

Update modifies an existing source. Only non-empty fields in the provided Source are applied (registry, toolchains, personalities, plugins). Use ClearOverride ("-") as a field value to reset an override back to the convention-based default. Returns an error if the source is not found.

func (*SourceConfig) Validate added in v0.0.23

func (sc *SourceConfig) Validate() error

Validate checks the source configuration for errors.

type SourceRegistry added in v0.0.23

type SourceRegistry struct {
	Source   string
	Registry string
}

SourceRegistry pairs a source name with a registry base path.

type SourceResolver added in v0.0.23

type SourceResolver struct {
	// contains filtered or unexported fields
}

SourceResolver wraps a list of sources and provides artifact reference resolution. The default source (if any) is placed first for short-name resolution priority.

func DefaultSourceResolver added in v0.0.23

func DefaultSourceResolver() *SourceResolver

DefaultSourceResolver returns a resolver with only the built-in source.

func NewSourceResolver added in v0.0.23

func NewSourceResolver(sources []Source) *SourceResolver

NewSourceResolver creates a resolver from the given sources. If sources is empty, the built-in default source is used. Sources are reordered so the one marked Default comes first.

func (*SourceResolver) DefaultOnly added in v0.0.23

func (r *SourceResolver) DefaultOnly() *SourceResolver

DefaultOnly returns a resolver restricted to the default source (the first source after default-first ordering). The SourceResolver constructor guarantees at least one source is always present, so this is safe; the guard is purely defensive.

func (*SourceResolver) ForSource added in v0.0.23

func (r *SourceResolver) ForSource(name string) (*SourceResolver, error)

ForSource returns a resolver restricted to a single named source. Returns an error if the source is not found.

func (*SourceResolver) PersonalityRegistries added in v0.0.23

func (r *SourceResolver) PersonalityRegistries() []SourceRegistry

PersonalityRegistries returns all personality registry bases with source annotations.

func (*SourceResolver) PluginRegistries added in v0.0.23

func (r *SourceResolver) PluginRegistries() []SourceRegistry

PluginRegistries returns all plugin registry bases with source annotations.

func (*SourceResolver) ResolvePersonalityRef added in v0.0.23

func (r *SourceResolver) ResolvePersonalityRef(ref string) string

ResolvePersonalityRef expands a short personality name using the default source.

func (*SourceResolver) ResolvePluginRef added in v0.0.23

func (r *SourceResolver) ResolvePluginRef(ref string) string

ResolvePluginRef expands a short plugin name using the default source.

func (*SourceResolver) ResolveToolchainRef added in v0.0.23

func (r *SourceResolver) ResolveToolchainRef(ref string) string

ResolveToolchainRef expands a short toolchain name using the default source.

func (*SourceResolver) Sources added in v0.0.23

func (r *SourceResolver) Sources() []Source

Sources returns a copy of the underlying list of sources.

func (*SourceResolver) ToolchainRegistries added in v0.0.23

func (r *SourceResolver) ToolchainRegistries() []SourceRegistry

ToolchainRegistries returns all toolchain registry bases with source annotations.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL