Documentation
¶
Index ¶
- Constants
- func ApprovalsPath(cwd string) string
- func AuditLogPath() string
- func EditProjectSettings(root string, edit func(*Settings)) error
- func EditUserSettings(edit func(*Settings)) error
- func EnsureMemoryDir(cwd string)
- func FormatModelID(provider, model string) string
- func LockFile(path string) (unlock func(), err error)
- func MemoryDir(cwd string) string
- func MemoryFilePath(cwd string) string
- func ModelSpec(providers map[string]ProviderConfig, name, model string) (provider.ModelSpec, error)
- func NeedsSetup() bool
- func PatchUserSettings(patch Settings) error
- func ProjectRoot(cwd string) string
- func ProjectSettingsPath(root string) string
- func SessionsDir(cwd string) string
- func SnapshotDir(cwd string) string
- func UndoStatePath(cwd, sessionID string) string
- func UserConfigDir() string
- func UserSettingsPath() string
- func WriteFileAtomic(path string, data []byte, perm os.FileMode) error
- type HookEntry
- type HooksConfig
- type Layers
- type MCPOAuth
- type MCPServer
- type PermissionsConfig
- type ProviderConfig
- type ProviderExtra
- type Resolved
- type Settings
- type SetupChoice
- type SetupOutcome
- type TelemetryConfig
Constants ¶
const ConfigDir = ".codebot"
Variables ¶
This section is empty.
Functions ¶
func ApprovalsPath ¶
func AuditLogPath ¶
func AuditLogPath() string
func EditProjectSettings ¶
EditProjectSettings refuses a settings file or directory that resolves outside the project.
func EditUserSettings ¶
func EnsureMemoryDir ¶
func EnsureMemoryDir(cwd string)
func FormatModelID ¶
func LockFile ¶
LockFile serializes edits to path across codebot processes. Lock files live in the user's config directory, never in a project.
func MemoryFilePath ¶
func ModelSpec ¶
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 ¶
PatchUserSettings writes the user's settings, never the project's: choices made while codebot runs must not land in a shared repository.
func ProjectRoot ¶
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 SessionsDir ¶
func SnapshotDir ¶
func UndoStatePath ¶
func UserConfigDir ¶
func UserConfigDir() string
func UserSettingsPath ¶
func UserSettingsPath() string
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 Layers ¶
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.
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"`
}
type PermissionsConfig ¶
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 ¶
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 SetupOutcome ¶
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.