config

package
v0.0.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const ConfigDir = ".codebot"

ConfigDir is the project-level config directory name.

Variables

View Source
var KnownProviderTypes = map[string]string{
	"anthropic":  "anthropic",
	"openai":     "openai",
	"openrouter": "openrouter",
	"gemini":     "gemini",
}

KnownProviderTypes maps well-known provider names to their protocol type.

Functions

func AddAllowedCommand added in v0.0.2

func AddAllowedCommand(cwd, cmd string) error

AddAllowedCommand appends a command to the project-level allowed_commands list (deduplicated).

func AuditLogPath added in v0.0.2

func AuditLogPath() string

AuditLogPath returns ~/.codebot/audit.log.

func BuildReminders added in v0.0.2

func BuildReminders(ctx ContextFiles, skills []Skill) []string

BuildReminders extracts skills and context files into <system-reminder> wrapped text fragments for injection into user messages. Returns nil when there are no reminders to inject.

func BuildSystemBlockTexts added in v0.0.2

func BuildSystemBlockTexts(cwd string, ctx ContextFiles, tools []ToolInfo) (identity, instructions string)

BuildSystemBlockTexts returns the system prompt split into two stable segments:

  • identity: role description + environment info
  • instructions: tool descriptions + guidelines

Skills and context files are NOT included — they go into user-message reminders via BuildReminders for better cache stability.

When ctx.SystemOverride is set (SYSTEM.md), it replaces the default prompt entirely. In this case identity is empty and instructions contains the full override.

func CoderSubAgentPrompt

func CoderSubAgentPrompt(cwd string) string

CoderSubAgentPrompt returns the system prompt for the coder sub-agent.

func CommandsDir added in v0.0.2

func CommandsDir(cwd string) string

CommandsDir returns <cwd>/.codebot/commands/.

func DefaultModelName

func DefaultModelName(prov string) string

DefaultModelName returns the default model name for a given provider.

func DetectEnvProvider added in v0.0.2

func DetectEnvProvider() (provider, envKey string)

DetectEnvProvider scans known providers for available environment variable credentials. Returns the provider name and env var key of the first match, or empty if none found.

func EnvCredentials

func EnvCredentials(prov string) (apiKey, baseURL string)

EnvCredentials returns API key and base URL from standard environment variables for the given provider (e.g. ANTHROPIC_API_KEY, OPENAI_API_KEY).

func ExploreSubAgentPrompt

func ExploreSubAgentPrompt(cwd string) string

ExploreSubAgentPrompt returns the system prompt for the explore sub-agent.

func FormatModelID

func FormatModelID(provider, model string) string

FormatModelID combines provider and model into "provider/model". If model already contains "/", it is returned as-is.

func FormatSkillsForPrompt

func FormatSkillsForPrompt(skills []Skill) string

FormatSkillsForPrompt generates the XML block injected into the system prompt. Skills with DisableModelInvocation=true are excluded.

func PatchGlobalSettings added in v0.0.2

func PatchGlobalSettings(patch Settings) error

PatchGlobalSettings loads the global settings, applies the patch, and saves back. Only non-nil fields in patch are updated.

func PatchProjectSettings added in v0.0.2

func PatchProjectSettings(cwd string, patch Settings) error

PatchProjectSettings loads project-level settings, applies the patch, and saves back.

func PlanSubAgentPrompt

func PlanSubAgentPrompt(cwd string) string

PlanSubAgentPrompt returns the system prompt for the plan sub-agent.

func PlansDir

func PlansDir(cwd string) string

PlansDir returns ~/.codebot/plans/<projectID>/.

func ProjectConfigExists added in v0.0.2

func ProjectConfigExists(cwd string) bool

ProjectConfigExists reports whether <cwd>/.codebot/settings.json exists.

func ProviderEnvKey

func ProviderEnvKey(prov string) string

ProviderEnvKey returns the standard environment variable name for a provider's API key.

func RunSetup

func RunSetup(settings Resolved) error

RunSetup runs an interactive first-time configuration wizard.

func SaveSettings

func SaveSettings(s Settings) error

SaveSettings writes settings to ~/.codebot/settings.json (global).

func SessionsDir

func SessionsDir(cwd string) string

SessionsDir returns ~/.codebot/projects/<projectID>/. Sessions are stored globally but scoped by project.

func SettingsPath

func SettingsPath(cwd string) string

SettingsPath returns <cwd>/.codebot/settings.json.

func SkillsDir

func SkillsDir(cwd string) string

SkillsDir returns <cwd>/.codebot/skills/.

func StripFrontmatter

func StripFrontmatter(content string) string

StripFrontmatter removes a leading YAML frontmatter block (--- delimited) from content.

func TasksDir

func TasksDir() string

TasksDir returns ~/.codebot/tasks/.

func UserConfigDir

func UserConfigDir() string

UserConfigDir returns ~/.codebot/.

Types

type ContextFiles

type ContextFiles struct {
	// Agents is the concatenated content of all AGENTS.md files found
	// from filesystem root down to cwd, separated by newlines.
	Agents string

	// SystemOverride is the content of SYSTEM.md if found in cwd.
	// When non-empty, it replaces the default system prompt entirely.
	SystemOverride string

	// SystemAppend is the content of APPEND_SYSTEM.md if found in cwd.
	// When non-empty, it is appended to the system prompt.
	SystemAppend string
}

ContextFiles holds the loaded context file contents.

func LoadContextFiles

func LoadContextFiles(cwd string) ContextFiles

LoadContextFiles searches for context files from cwd upward to the filesystem root.

Loading order (lowest to highest specificity):

  1. ~/.codebot/AGENTS.md (global user-level)
  2. AGENTS.md in each ancestor from root down to cwd

CLAUDE.md is used as fallback when AGENTS.md is not found in a directory. SYSTEM.md and APPEND_SYSTEM.md are only looked for in cwd.

type FileCommand added in v0.0.2

type FileCommand struct {
	Name        string
	Aliases     []string
	Description string
	Usage       string
	Content     string
	Source      string // "user" or "project"
	FilePath    string
	Risk        policy.CommandRisk
	NeedsIdle   bool
	Hidden      bool
}

FileCommand is a user-defined slash command loaded from a Markdown file. Its body is treated as a prompt template with optional frontmatter metadata.

func LoadFileCommands added in v0.0.2

func LoadFileCommands(cwd string) []FileCommand

LoadFileCommands discovers and loads Markdown-backed slash commands from user and project command directories. Project commands override user commands with the same name.

type HookEntry added in v0.0.2

type HookEntry struct {
	Type     string `json:"type"`               // "command" (only type for now)
	Command  string `json:"command"`            // shell command to execute
	Matcher  string `json:"matcher,omitempty"`  // tool name filter: exact or /regex/
	Blocking *bool  `json:"blocking,omitempty"` // PreToolUse: can block execution
	Timeout  *int   `json:"timeout,omitempty"`  // seconds (default 60)
}

HookEntry describes a single hook command.

type HooksConfig added in v0.0.2

type HooksConfig map[string][]HookEntry

HooksConfig maps event names to their hook entries.

type ProviderConfig

type ProviderConfig struct {
	Type       string   `json:"type,omitempty"` // protocol: openai/anthropic/gemini; inferred from name if empty
	APIKey     string   `json:"api_key,omitempty"`
	BaseURL    string   `json:"base_url,omitempty"`
	Models     []string `json:"models,omitempty"`      // available model list for this provider
	SmallModel string   `json:"small_model,omitempty"` // lightweight model for sub-agents
}

ProviderConfig holds credentials and model configuration for a single provider.

func (ProviderConfig) ProviderType added in v0.0.2

func (pc ProviderConfig) ProviderType(name string) string

ProviderType returns the protocol type for this provider. Uses explicit Type field first, then infers from the provider name, defaulting to "openai" for unknown providers.

type Resolved

type Resolved struct {
	Provider   string                    // active provider name
	Model      string                    // model name sent to API as-is
	SmallModel string                    // sub-agent model; equals Model when not configured
	Providers  map[string]ProviderConfig // per-provider credentials

	ContextWindow  int // auto-detected from model registry at boot
	AutoCompaction bool
	ThinkingLevel  string
	MaxTurns       int
	SearchProvider string
	SearchAPIKey   string

	AllowedCommands []string // project-level always-allow list for dangerous commands

	Hooks HooksConfig // lifecycle hooks
}

Resolved holds settings resolved to concrete values (no pointers).

func LoadSettings

func LoadSettings(cwd string) Resolved

LoadSettings loads and merges settings from global (~/.codebot/settings.json) and project (<cwd>/.codebot/settings.json). Project-level values override global.

func ResolveAll

func ResolveAll(cwd string) Resolved

ResolveAll merges global and project settings, applies defaults, and returns a fully resolved configuration.

func (Resolved) ProviderCredentials

func (r Resolved) ProviderCredentials(prov string) (apiKey, baseURL string)

ProviderCredentials returns API key and base URL for the given provider. It checks the providers map first, then falls back to standard environment variables.

type Settings

type Settings struct {
	Provider   *string                    `json:"provider,omitempty"`    // provider name (matches key in providers map)
	Model      *string                    `json:"model,omitempty"`       // model name sent to API as-is
	SmallModel *string                    `json:"small_model,omitempty"` // sub-agent model; defaults to Model if empty
	Providers  map[string]*ProviderConfig `json:"providers,omitempty"`

	AutoCompaction *bool `json:"auto_compaction,omitempty"`

	ThinkingLevel *string `json:"thinking_level,omitempty"`

	MaxTurns *int `json:"max_turns,omitempty"`

	SearchProvider *string `json:"search_provider,omitempty"`
	SearchAPIKey   *string `json:"search_api_key,omitempty"`

	AllowedCommands []string `json:"allowed_commands,omitempty"` // project-level always-allow list for dangerous commands

	Hooks HooksConfig `json:"hooks,omitempty"` // lifecycle hooks
}

Settings holds application-level configuration. Fields use pointer types so unset fields fall back to defaults.

func (Settings) Resolve

func (s Settings) Resolve() Resolved

Resolve converts Settings to Resolved using defaults for unset fields.

type Skill

type Skill struct {
	Name                   string // validated skill name (stored lowercase)
	Description            string // from frontmatter or first line
	FilePath               string // absolute path to the .md file
	BaseDir                string // parent directory (for relative path resolution)
	Source                 string // "user" or "project"
	DisableModelInvocation bool   // when true, excluded from system prompt
}

Skill represents a loadable skill file.

func LoadSkills

func LoadSkills(cwd string) []Skill

LoadSkills discovers and loads skills from user and project directories. Project skills override user skills with the same name.

type ToolInfo

type ToolInfo struct {
	Name        string
	Description string
}

ToolInfo describes a tool for system prompt generation. Decoupled from agentcore.Tool to avoid package dependency.

Jump to

Keyboard shortcuts

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