config

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const ConfigDir = ".codebot"

Variables

This section is empty.

Functions

func ApprovalsPath

func ApprovalsPath(cwd string) string

func AuditLogPath

func AuditLogPath() string

func EditProjectSettings

func EditProjectSettings(root string, edit func(*Settings)) error

EditProjectSettings refuses a settings file or directory that resolves outside the project.

func EditUserSettings

func EditUserSettings(edit func(*Settings)) error

func EnsureMemoryDir

func EnsureMemoryDir(cwd string)

func FormatModelID

func FormatModelID(provider, model string) string

func LockFile

func LockFile(path string) (unlock func(), err error)

LockFile serializes edits to path across codebot processes. Lock files live in the user's config directory, never in a project.

func MemoryDir

func MemoryDir(cwd string) string

func MemoryFilePath

func MemoryFilePath(cwd string) string

func ModelSpec

func ModelSpec(providers map[string]ProviderConfig, name, model string) (provider.ModelSpec, error)

ModelSpec accepts a name missing from providers only if it is a built-in provider type.

func NeedsSetup

func NeedsSetup() bool

NeedsSetup reports whether the user settings file is missing. Credentials come only from it, never from a project, so onboarding must run first.

func PatchUserSettings

func PatchUserSettings(patch Settings) error

PatchUserSettings writes the user's settings, never the project's: choices made while codebot runs must not land in a shared repository.

func ProjectRoot

func ProjectRoot(cwd string) string

ProjectRoot returns the top of the git repository holding cwd, else cwd. It returns "" for the home directory, whose .codebot belongs to the user.

func ProjectSettingsPath

func ProjectSettingsPath(root string) string

func SessionsDir

func SessionsDir(cwd string) string

func SnapshotDir

func SnapshotDir(cwd string) string

func UndoStatePath

func UndoStatePath(cwd, sessionID string) string

func UserConfigDir

func UserConfigDir() string

func UserSettingsPath

func UserSettingsPath() string

func WriteFileAtomic

func WriteFileAtomic(path string, data []byte, perm os.FileMode) error

Types

type HookEntry

type HookEntry struct {
	Type           string            `json:"type"`                      // "command", "prompt", or "http"
	Command        string            `json:"command,omitempty"`         // type=command: sh command
	CommandWindows string            `json:"command_windows,omitempty"` // type=command: PowerShell command run on Windows instead
	Prompt         string            `json:"prompt,omitempty"`          // type=prompt: LLM prompt ($ARGUMENTS = payload)
	URL            string            `json:"url,omitempty"`             // type=http: POST endpoint
	Headers        map[string]string `json:"headers,omitempty"`         // type=http
	Matcher        string            `json:"matcher,omitempty"`         // tool name filter: exact (case-insensitive) or /regex/
	If             string            `json:"if,omitempty"`              // tool arguments JSON filter: /regex/, or the exact JSON
	Blocking       *bool             `json:"blocking,omitempty"`        // can block execution
	Timeout        *int              `json:"timeout,omitempty"`         // seconds (default 60)
	// Env is set by codebot, never read from settings: plugin hooks get
	// PLUGIN_ROOT and PLUGIN_DATA.
	Env map[string]string `json:"-"`
}

type HooksConfig

type HooksConfig map[string][]HookEntry

HooksConfig is keyed by event name.

type Layers

type Layers struct {
	Root    string // "" when there is no project
	User    Settings
	Project Settings
}

Layers are the raw user and project settings. A project may come from anyone, so it can set only some fields, and some only once trusted; see ForProject.

func Load

func Load(cwd string) (Layers, error)

func (Layers) Resolve

func (l Layers) Resolve(cwd string, granted Settings) (Resolved, error)

Resolve lays the project's settings over the user's. Of the project's grants, only granted (those the user agreed to, see extension.Load) apply. Hooks, MCP servers and plugins are left to the extension package. Model has no default because hardcoded model names go stale.

type MCPOAuth

type MCPOAuth struct {
	ClientID     string `json:"client_id"`
	ClientSecret string `json:"client_secret,omitempty"`
}

MCPOAuth is a client registered beforehand with the authorization server of an http server, for one that takes no client metadata document.

type MCPServer

type MCPServer struct {
	Type    string            `json:"type,omitempty"` // "stdio" (default) or "http"
	Command string            `json:"command,omitempty"`
	Args    []string          `json:"args,omitempty"`
	Env     map[string]string `json:"env,omitempty"`
	Cwd     string            `json:"cwd,omitempty"`
	URL     string            `json:"url,omitempty"`
	Headers map[string]string `json:"headers,omitempty"`
	OAuth   *MCPOAuth         `json:"oauth,omitempty"`
}

func (MCPServer) Check

func (s MCPServer) Check() error

type PermissionsConfig

type PermissionsConfig struct {
	Allow      []string `json:"allow,omitempty"`
	Deny       []string `json:"deny,omitempty"`
	ReadRoots  []string `json:"read_roots,omitempty"`
	WriteRoots []string `json:"write_roots,omitempty"`
}

type ProviderConfig

type ProviderConfig struct {
	Type       string         `json:"type,omitempty"` // a litellm provider or "gateway"; required when the name is not a known provider
	API        string         `json:"api,omitempty"`  // OpenAI protocol endpoint: chat (default) or responses
	APIKey     string         `json:"api_key,omitempty"`
	BaseURL    string         `json:"base_url,omitempty"`
	Models     []string       `json:"models,omitempty"`
	SmallModel string         `json:"small_model,omitempty"` // lightweight model for sub-agents
	Extra      *ProviderExtra `json:"extra,omitempty"`
}

func (ProviderConfig) HasCredentials

func (pc ProviderConfig) HasCredentials() bool

type ProviderExtra

type ProviderExtra struct {
	UserAgent string            `json:"user_agent,omitempty"`
	Headers   map[string]string `json:"headers,omitempty"`
	// AnthropicBeta sets the anthropic-beta header unless Headers sets it.
	AnthropicBeta string `json:"anthropic_beta,omitempty"`
	// Region and the AWS keys authenticate bedrock, which takes no API key.
	Region          string `json:"region,omitempty"`
	AccessKeyID     string `json:"access_key_id,omitempty"`
	SecretAccessKey string `json:"secret_access_key,omitempty"`
	SessionToken    string `json:"session_token,omitempty"`
}

ProviderExtra configures the HTTP client, never the request body.

type Resolved

type Resolved struct {
	Provider  string
	Model     string
	Providers map[string]ProviderConfig

	CompactWindow   int     // 0 = no cap
	CompactRatio    float64 // 0 = unset
	ReasoningEffort string
	MaxTurns        int
	SearchProvider  string
	SearchAPIKey    string

	Permissions PermissionsConfig

	Telemetry TelemetryConfig

	Snapshot bool
}

type Settings

type Settings struct {
	Provider        *string                    `json:"provider,omitempty"`         // a key of Providers
	Model           *string                    `json:"model,omitempty"`            // model name sent to API as-is
	ReasoningEffort *string                    `json:"reasoning_effort,omitempty"` // "" = provider default; off | low | medium | high | xhigh | max
	Providers       map[string]*ProviderConfig `json:"providers,omitempty"`

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

	// CompactWindow caps the model's context window for compaction; 0 means
	// no cap.
	CompactWindow *int `json:"compact_window,omitempty"`
	// CompactRatio, in (0, 1), compacts when usage reaches window * ratio.
	// Unset reserves room for the model's reply instead.
	CompactRatio *float64 `json:"compact_ratio,omitempty"`

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

	Hooks HooksConfig `json:"hooks,omitempty"`

	// A project entry replaces the user's entry of the same name.
	MCPServers map[string]MCPServer `json:"mcp_servers,omitempty"`

	// Plugins are git repositories ("host/owner/repo" or an https or ssh URL,
	// with "#ref" pinning a tag, branch or commit) or local directories
	// relative to the settings file that declares them.
	Plugins []string `json:"plugins,omitempty"`

	Permissions *PermissionsConfig `json:"permissions,omitempty"`

	Telemetry *TelemetryConfig `json:"telemetry,omitempty"`

	// Snapshot enables the checkpoints behind /undo; unset means on. Large
	// repos may turn it off because every turn scans the workspace.
	Snapshot *bool `json:"snapshot,omitempty"`
}

Settings uses pointers so that unset fields fall back to defaults.

func ForProject

func ForProject(s Settings) (open, grants Settings, refused []string)

ForProject splits a project's settings by what a project may do:

  • open fields only shape how codebot works (deny rules included) and apply as they are;
  • grants run code or let calls through without asking (hooks, MCP servers, plugins, allow rules, roots) and apply only once the user agrees;
  • fields that decide where calls go and whose credentials they carry (providers, search provider and key, telemetry) belong to the user alone, so they are dropped and listed in refused.

type SetupChoice

type SetupChoice struct {
	Provider string // a known provider such as "anthropic", or a custom name
	Type     string // protocol type for custom providers; "" = derive from name
	BaseURL  string
	APIKey   string
	Model    string // required: hardcoded defaults go stale
}

type SetupOutcome

type SetupOutcome struct {
	Provider string
	Model    string
	Path     string
}

func ApplySetup

func ApplySetup(c SetupChoice) (SetupOutcome, error)

ApplySetup patches the user settings rather than overwriting them, so a re-run (codebot -setup) keeps unrelated fields.

type TelemetryConfig

type TelemetryConfig struct {
	Enabled   bool   `json:"enabled,omitempty"`
	Endpoint  string `json:"endpoint,omitempty"`   // OTLP/HTTP endpoint URL
	PublicKey string `json:"public_key,omitempty"` // basic-auth username
	SecretKey string `json:"secret_key,omitempty"` // basic-auth password
}

Jump to

Keyboard shortcuts

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