Documentation
¶
Index ¶
- Constants
- Variables
- func ApprovalsPath(cwd string) string
- func AuditLogPath() string
- func BuildAutoMemoryInstructions(memoryDir string) string
- func BuildReminders(ctx ContextFiles, skills []skill.Spec) []string
- func BuildSystemBlockTexts(cwd string, ctx ContextFiles, tools []ToolInfo) (identity, instructions string)
- func CoderSubAgentPrompt(cwd string) string
- func CollectGitSnapshot(cwd string) string
- func CommandsDir(cwd string) string
- func DefaultModelName(prov string) string
- func DetectEnvProvider() (provider, envKey string)
- func EnsureMemoryDir(cwd string)
- func EnvCredentials(prov string) (apiKey, baseURL string)
- func ExpandHome(path string) string
- func ExploreSubAgentPrompt(cwd string) string
- func FormatModelID(provider, model string) string
- func GlobalConfigExists() bool
- func GlobalSettingsPath() string
- func LoadMemory(cwd string) (content, dir string)
- func MemoryDir(cwd string) string
- func MemoryFilePath(cwd string) string
- func PatchGlobalSettings(patch Settings) error
- func PatchProjectSettings(cwd string, patch Settings) error
- func PlanSubAgentPrompt(cwd string) string
- func PlansDir(cwd string) string
- func ProjectConfigExists(cwd string) bool
- func ProviderEnvKey(prov string) string
- func ResolveConfiguredProviderType(providers map[string]ProviderConfig, name string) (string, error)
- func ResolveProviderType(name, explicitType string) (string, error)
- func RunSetup(settings Resolved) error
- func SaveSettings(s Settings) error
- func SessionsDir(cwd string) string
- func SettingsPath(cwd string) string
- func SkillsDir(cwd string) string
- func TasksDir() string
- func UserConfigDir() string
- type ContextFiles
- type ExtraCommandSource
- type FileCommand
- type HookEntry
- type HooksConfig
- type PermissionsConfig
- type ProviderConfig
- type Resolved
- type Settings
- type ToolInfo
Constants ¶
const ConfigDir = ".codebot"
ConfigDir is the project-level config directory name.
const SuggestionPrompt = `` /* 1132-byte string literal not displayed */
SuggestionPrompt is the instruction appended as a user message to generate a prompt suggestion after the agent completes a turn. Aligned with Claude Code's Prompt Suggestion Generator v2.
Variables ¶
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 ApprovalsPath ¶ added in v0.0.4
ApprovalsPath returns ~/.codebot/approvals/<projectID>.json.
func AuditLogPath ¶ added in v0.0.2
func AuditLogPath() string
AuditLogPath returns ~/.codebot/audit.log.
func BuildAutoMemoryInstructions ¶ added in v0.0.4
BuildAutoMemoryInstructions returns the system prompt instructions that teach the LLM how to use auto memory. Returns empty string when memoryDir is empty (e.g. no user config dir).
func BuildReminders ¶ added in v0.0.2
func BuildReminders(ctx ContextFiles, skills []skill.Spec) []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 ¶
CoderSubAgentPrompt returns the system prompt for the coder sub-agent.
func CollectGitSnapshot ¶ added in v0.0.4
CollectGitSnapshot runs git commands in cwd and returns a formatted snapshot suitable for LLM system prompt injection. Returns empty string when cwd is not a git repository.
func CommandsDir ¶ added in v0.0.2
CommandsDir returns <cwd>/.codebot/commands/.
func DefaultModelName ¶
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 EnsureMemoryDir ¶ added in v0.0.4
func EnsureMemoryDir(cwd string)
EnsureMemoryDir creates the memory directory if it doesn't exist.
func EnvCredentials ¶
EnvCredentials returns API key and base URL from standard environment variables for the given provider (e.g. ANTHROPIC_API_KEY, OPENAI_API_KEY).
func ExpandHome ¶ added in v0.0.4
func ExploreSubAgentPrompt ¶
ExploreSubAgentPrompt returns the system prompt for the explore sub-agent.
func FormatModelID ¶
FormatModelID combines provider and model into "provider/model". If model already contains "/", it is returned as-is.
func GlobalConfigExists ¶ added in v0.1.0
func GlobalConfigExists() bool
GlobalConfigExists reports whether ~/.codebot/settings.json exists.
func GlobalSettingsPath ¶ added in v0.1.0
func GlobalSettingsPath() string
GlobalSettingsPath returns ~/.codebot/settings.json.
func LoadMemory ¶ added in v0.0.4
LoadMemory reads MEMORY.md (first 200 lines) and returns the content along with the memory directory path. Returns empty strings when no memory file exists.
func MemoryFilePath ¶ added in v0.0.4
MemoryFilePath returns the path to MEMORY.md.
func PatchGlobalSettings ¶ added in v0.0.2
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
PatchProjectSettings loads project-level settings, applies the patch, and saves back.
func PlanSubAgentPrompt ¶
PlanSubAgentPrompt returns the system prompt for the plan sub-agent.
func ProjectConfigExists ¶ added in v0.0.2
ProjectConfigExists reports whether <cwd>/.codebot/settings.json exists.
func ProviderEnvKey ¶
ProviderEnvKey returns the standard environment variable name for a provider's API key.
func ResolveConfiguredProviderType ¶ added in v0.1.0
func ResolveConfiguredProviderType(providers map[string]ProviderConfig, name string) (string, error)
ResolveConfiguredProviderType resolves the protocol type for a configured provider.
func ResolveProviderType ¶ added in v0.1.0
ResolveProviderType resolves a provider's protocol type. The type value maps directly to the underlying LiteLLM provider name.
func SaveSettings ¶
SaveSettings writes settings to ~/.codebot/settings.json (global).
func SessionsDir ¶
SessionsDir returns ~/.codebot/projects/<projectID>/. Sessions are stored globally but scoped by project.
func SettingsPath ¶
SettingsPath returns <cwd>/.codebot/settings.json.
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
// GitSnapshot is the git status snapshot collected at session start.
// Injected as a separate system block so the LLM knows the repo state.
GitSnapshot string
// Memory is the auto memory content (first 200 lines of MEMORY.md).
Memory string
// MemoryDir is the absolute path to the memory directory.
// Used by auto memory instructions to tell the LLM where to write.
MemoryDir 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):
- ~/.codebot/AGENTS.md (global user-level, auto-created if missing)
- 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 ExtraCommandSource ¶ added in v0.1.0
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
Category string // prompt/info/session/config/plan/exit
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 LoadCommandsFromDir ¶ added in v0.1.0
func LoadCommandsFromDir(dir, source string) []FileCommand
func LoadFileCommands ¶ added in v0.0.2
func LoadFileCommands(cwd string, extraPaths ...string) []FileCommand
LoadFileCommands discovers and loads Markdown-backed slash commands from user, project, and extra paths (e.g. skill-declared command files). Project commands override user commands; extra paths have lowest priority.
func LoadFileCommandsWithSources ¶ added in v0.1.0
func LoadFileCommandsWithSources(cwd string, extraSources ...ExtraCommandSource) []FileCommand
LoadFileCommandsWithSources discovers Markdown-backed slash commands from user, project, and extra plugin/skill paths. Project commands override user commands; extra paths have lowest priority.
func ValidateCommandsDir ¶ added in v0.1.0
func ValidateCommandsDir(dir, source string) ([]FileCommand, []error)
type HookEntry ¶ added in v0.0.2
type HookEntry struct {
Type string `json:"type"` // "command", "prompt", or "http"
Command string `json:"command,omitempty"` // type=command: shell command
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: request headers
Matcher string `json:"matcher,omitempty"` // tool name filter: exact or /regex/
If string `json:"if,omitempty"` // argument content filter: substring or /regex/
Blocking *bool `json:"blocking,omitempty"` // can block execution
Timeout *int `json:"timeout,omitempty"` // seconds (default 60)
}
HookEntry describes a single hook. Supported types: "command" (shell), "prompt" (LLM evaluation), "http" (POST).
type HooksConfig ¶ added in v0.0.2
HooksConfig maps event names to their hook entries.
type PermissionsConfig ¶ added in v0.0.4
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"`
}
PermissionsConfig holds user-defined permission rules.
type ProviderConfig ¶
type ProviderConfig struct {
Type string `json:"type,omitempty"` // LiteLLM provider type: openai/anthropic/gemini/openrouter; required for custom providers
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, error)
ProviderType resolves the protocol type for this provider. Built-in providers infer their type from the provider name. Custom providers must declare providers.<name>.type explicitly.
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
Hooks HooksConfig // lifecycle hooks
Permissions PermissionsConfig // user-defined permission rules
}
Resolved holds settings resolved to concrete values (no pointers).
func LoadSettings ¶
LoadSettings loads and merges settings from global (~/.codebot/settings.json) and project (<cwd>/.codebot/settings.json). Project-level values override global.
func LoadSettingsStrict ¶ added in v0.1.0
LoadSettingsStrict loads and merges settings like LoadSettings, but returns an error when either settings file exists and cannot be parsed.
func ResolveAll ¶
ResolveAll merges global and project settings, applies defaults, and returns a fully resolved configuration.
func ResolveAllStrict ¶ added in v0.1.0
ResolveAllStrict resolves settings like ResolveAll, but refuses to continue when an existing settings file is malformed.
func (Resolved) ProviderCredentials ¶
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"`
ContextWindow *int `json:"context_window,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"`
Hooks HooksConfig `json:"hooks,omitempty"` // lifecycle hooks
Permissions *PermissionsConfig `json:"permissions,omitempty"`
}
Settings holds application-level configuration. Fields use pointer types so unset fields fall back to defaults.