config

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

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.

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

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

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

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 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) 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 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
	// 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
	// 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.

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.

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