config

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: Apache-2.0 Imports: 10 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 (
	// DefaultPluginRegistry is the default base reference for plugin short names.
	DefaultPluginRegistry = "gsoci.azurecr.io/giantswarm/klaus-plugins"
	// DefaultPersonalityRegistry is the default base reference for personality short names.
	DefaultPersonalityRegistry = "gsoci.azurecr.io/giantswarm/klaus-personalities"
	// DefaultToolchainRegistry is the default base reference for toolchain short names.
	DefaultToolchainRegistry = "gsoci.azurecr.io/giantswarm"
)

Variables

This section is empty.

Functions

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 ResolvePersonalityRef added in v0.0.11

func ResolvePersonalityRef(ref string) string

ResolvePersonalityRef resolves full references and short names to OCI refs.

func ResolvePluginRef added in v0.0.11

func ResolvePluginRef(ref string) string

ResolvePluginRef resolves full references and short names to OCI refs.

func ResolveToolchainRef added in v0.0.11

func ResolveToolchainRef(ref string) string

ResolveToolchainRef resolves full references and short names to OCI refs.

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.

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"`
	// 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

	// 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
}

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.

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.

Jump to

Keyboard shortcuts

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