Documentation
¶
Overview ¶
Package config loads ogcode's optional file-based configuration: provider base URLs and API keys, and the skill sources and permissions, so they can live in a committed/shared file instead of only environment variables.
Index ¶
- func EnsureProjectFile(dir string) string
- func MCPScope(dir, name string) string
- func ProjectSkillPermissions(dir string) (map[string]string, string)
- func SetMCPDisabled(dir, name string, disabled bool) (string, error)
- func SetProjectSkillPermissions(dir string, perms map[string]string) (string, error)
- type Config
- type MCPAuthConfig
- type MCPConfig
- type MCPServerConfig
- type ProviderConfig
- type SkillsConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnsureProjectFile ¶
EnsureProjectFile creates a blank project-local ogcode.json in dir if no ogcode.json is found in dir or any of its ancestors (see findProjectFile). An existing file — found anywhere in that search — is left untouched, and so is dir itself if creation fails for any reason (e.g. a read-only filesystem): this is a best-effort convenience, never a requirement for startup. Returns the path that was created, or "" if nothing was created.
func MCPScope ¶ added in v0.34.0
MCPScope reports where the effective definition of MCP server name lives — "project" when the project-local ogcode.json defines it (which, under the wholesale per-name merge, is what the agent uses), otherwise "global" when only the global config does, or "" when neither does.
func ProjectSkillPermissions ¶ added in v0.34.0
ProjectSkillPermissions returns the skills.permissions map written in the project-local ogcode.json in effect for dir — the file findProjectFile locates, not merged with the global config — together with that file's path. When no project file exists it returns an empty (non-nil) map and an empty path; the caller can still hand the map to SetProjectSkillPermissions, which creates the file.
It reads only the project file on purpose. A toggle edits the project file, so it must start from the project file's own rules; folding in the global config here would copy every global rule into the project on the first save.
func SetMCPDisabled ¶ added in v0.34.0
SetMCPDisabled turns MCP server name on or off for this project by writing to the project-local ogcode.json, and returns the path written. The choice is always per-project: it never edits the global config, so disabling a server here leaves it enabled in other projects.
Because the config merge replaces a server wholesale per name, disabling a server that lives only in the global config means pinning its full definition into the project file alongside disabled:true — otherwise the merged view would lose the command/url and re-enabling could not reconnect. Enabling reverses this: a project entry that is nothing more than a pin of the global server (identical but for the disabled flag) is removed so the file falls back to the global definition and does not drift; a project-native server just has its disabled flag cleared.
func SetProjectSkillPermissions ¶ added in v0.34.0
SetProjectSkillPermissions writes perms as the skills.permissions object of the project-local ogcode.json for dir, preserving every other field already in the file, and creating the file from the standard template if none exists anywhere up the tree. Returns the path written.
The rewrite goes through the file as a free-form object rather than the typed Config, so fields ogcode does not model — a future key, or a user's own addition — survive untouched. Marshalling a map sorts its keys, so the top level settles into a fixed order (mcp, providers, skills); the content is unchanged and this package's readers do not depend on key order.
The write is atomic: it lands through a sibling temp file and a rename, so an interrupted write cannot leave a half-written config where the next Load would read one.
Types ¶
type Config ¶
type Config struct {
Providers map[string]ProviderConfig `json:"providers,omitempty"`
Skills SkillsConfig `json:"skills,omitempty"`
MCP MCPConfig `json:"mcp,omitempty"`
}
Config is ogcode's file-based configuration.
func Load ¶
Load reads the global config (~/.config/ogcode/config.json) and the project-local config (ogcode.json, found by searching dir and its parents, stopping once the repo root — the directory holding .git — has been checked), merging them provider-by-provider with project-local values taking precedence. Missing or unreadable files are silently skipped; Load always returns a usable, non-nil Config.
Skill sources merge differently from provider settings: paths and urls are unioned rather than overridden, so a project adds its own skill directories to the user's global ones instead of replacing them. Permissions merge key-by-key, project-local last, so a project can override one rule without restating the rest.
type MCPAuthConfig ¶ added in v0.29.0
type MCPAuthConfig struct {
// ClientID is a pre-registered OAuth client identifier. When set, Dynamic
// Client Registration is skipped and this client is used directly. Leave
// empty to use DCR (the default).
ClientID string `json:"clientId,omitempty"`
// ClientSecret is the secret for a pre-registered confidential client.
// Only meaningful when ClientID is set. Leave empty for a public client.
ClientSecret string `json:"clientSecret,omitempty"`
// Scopes are requested beyond what the server advertises. Empty = the
// server's scopes_supported plus offline_access (when refresh tokens are
// requested).
Scopes []string `json:"scopes,omitempty"`
// SkipOAuth disables the OAuth handler for this server even with no
// Headers — for a server that returns 401 but is not an OAuth server.
SkipOAuth bool `json:"skipOAuth,omitempty"`
}
MCPAuthConfig configures OAuth authorization for a URL-based MCP server. It only applies to streamable-http servers without static Headers. Leave the whole block nil (or empty) for the default: Dynamic Client Registration with a loopback redirect, which works against servers like Cal.com with no pre-registered client.
type MCPConfig ¶ added in v0.29.0
type MCPConfig map[string]MCPServerConfig
MCPConfig holds the named MCP servers ogcode connects to at startup.
type MCPServerConfig ¶ added in v0.29.0
type MCPServerConfig struct {
// Transport forces the transport; empty auto-detects from Command/URL.
Transport string `json:"transport,omitempty"`
// Command is the executable run as a stdio subprocess server.
Command string `json:"command,omitempty"`
// Args are passed to Command.
Args []string `json:"args,omitempty"`
// Env augments (not replaces) the parent process environment for Command.
Env map[string]string `json:"env,omitempty"`
// URL is the endpoint for a streamable-http or sse server.
URL string `json:"url,omitempty"`
// Headers are sent with HTTP requests to a URL-based server. When set, the
// server uses the static-token path and no OAuth handler is attached.
Headers map[string]string `json:"headers,omitempty"`
// Auth configures OAuth for a URL-based server. When nil (the default for a
// server with a URL and no Headers), Dynamic Client Registration is used
// with a localhost redirect — the "just works" path. Setting any field
// opts into an explicit client. Has no effect for stdio servers or when
// Headers is set.
Auth *MCPAuthConfig `json:"auth,omitempty"`
// Disabled turns the server off without deleting it: ogcode neither connects
// to it nor exposes its tools, so nothing about it reaches the agent's
// prompt (and no tokens are spent on its tool schemas). The server's config
// and any stored OAuth tokens are left untouched, so flipping this back to
// false reconnects it. Off by default — an unset field means enabled.
Disabled bool `json:"disabled,omitempty"`
}
MCPServerConfig configures a single Model Context Protocol server connection. A server is either a local subprocess (Command + Args + Env) or a remote HTTP endpoint (URL + Headers). Transport is one of "stdio", "streamable-http", or "sse" — when empty, it is inferred from whether Command or URL is set (stdio if Command, otherwise http).
Authorization: a server with a URL and no Headers gets an OAuth handler attached automatically — the first 401 triggers the authorization-code (with PKCE) flow, so servers like Cal.com connect with no extra config. A server with Headers keeps the static bearer-token path and no OAuth. The optional Auth block overrides the defaults (pre-registered client, custom scopes, or SkipOAuth to disable the handler entirely).
type ProviderConfig ¶
type ProviderConfig struct {
BaseURL string `json:"baseUrl,omitempty"`
APIKey string `json:"apiKey,omitempty"`
}
ProviderConfig holds per-provider connection overrides.
type SkillsConfig ¶ added in v0.27.0
type SkillsConfig struct {
// Paths are extra skill directories, relative to the project or absolute.
Paths []string `json:"paths,omitempty"`
// URLs are index.json manifests to fetch skills from.
URLs []string `json:"urls,omitempty"`
// Permissions maps a skill-name glob to "allow", "deny", or "ask".
Permissions map[string]string `json:"permissions,omitempty"`
}
SkillsConfig configures where skills come from and which of them an agent may use. Every field is optional: with none of them set, ogcode still scans the standard project and global skill directories.