config

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package config implements RoleMux's layered, non-secret TOML configuration. Credentials remain in provider stores or are reacquired from validated environment-variable references; they are never serialized.

Index

Constants

View Source
const (
	RolePlanner      = "planner"
	RoleImplementer  = "implementer"
	RoleReviewer     = "reviewer"
	RolePlanReviewer = "plan_reviewer"
	RoleCodeReviewer = "code_reviewer"
)

Variables

View Source
var (
	ErrUnknownRole      = errors.New("unknown role")
	ErrConfigConflict   = errors.New("configuration changed while it was being edited")
	ErrUnsafeConfig     = errors.New("unsafe configuration")
	ErrUnknownProvider  = errors.New("unknown provider")
	ErrMissingModel     = errors.New("profile has no model")
	ErrUnavailableModel = errors.New("configured model is unavailable")
)

Functions

func CanonicalRole

func CanonicalRole(role string) (string, error)

func ConfigPaths

func ConfigPaths(repoRoot string, environ []string) (global, project string)

func ConfigureProfile

func ConfigureProfile(name, role string, profile Profile, beforeHash string) error

ConfigureProfile applies one named profile while preserving unrelated raw TOML tables. beforeHash must be the hash observed before the caller read the file. The compare is performed immediately before the atomic rename.

func ConfigureProfilesAtomic

func ConfigureProfilesAtomic(name string, profilesToSet map[string]Profile, beforeHash string) error

ConfigureProfilesAtomic updates a set of profiles in one compare-and-swap write while preserving all unrelated TOML keys.

func FileHash

func FileHash(name string) (string, error)

FileHash returns the hash used for read/check/write conflict detection. Missing files have an empty hash; existence alone is not a conflict.

func ImportConfigAtomic

func ImportConfigAtomic(name string, data []byte, beforeHash string) error

ImportConfigAtomic imports only RoleMux-owned tables from a TOML fragment. Unrelated destination keys are preserved, while unknown keys nested inside RoleMux-owned tables are discarded by re-encoding the validated typed form.

func ProfileRoles

func ProfileRoles() []string

func ReadAll

func ReadAll(r io.Reader) ([]byte, error)

func SnapshotEnvironment

func SnapshotEnvironment(refs []string, environ []string) (map[string]string, error)

SnapshotEnvironment returns only values for validated references. It is intentionally generic so runner packages can use it without persisting the returned values.

func Validate

func Validate(c Config) error

func ValidateAuthCommand

func ValidateAuthCommand(auth AuthCommand) error

func ValidateCustomModel

func ValidateCustomModel(provider, name string, m CustomModel) error

func ValidateEnvRef

func ValidateEnvRef(name string) error

func ValidateEnvRefOptional

func ValidateEnvRefOptional(value string) error

func ValidateProfile

func ValidateProfile(p Profile) error

func ValidateProvider

func ValidateProvider(name string, p Provider) error

func WriteConfigAtomic

func WriteConfigAtomic(name string, cfg Config, beforeHash string) error

WriteConfigAtomic serializes known config deterministically. Raw keys are preserved if present and the compare-and-swap happens before rename.

func WriteRawAtomic

func WriteRawAtomic(name string, raw map[string]any, beforeHash string) error

Types

type AuthCommand

type AuthCommand struct {
	Command           string   `toml:"command,omitempty" json:"command,omitempty"`
	Args              []string `toml:"args,omitempty" json:"args,omitempty"`
	TimeoutMS         int      `toml:"timeout_ms,omitempty" json:"timeout_ms,omitempty"`
	RefreshIntervalMS int      `toml:"refresh_interval_ms,omitempty" json:"refresh_interval_ms,omitempty"`
}

type Config

type Config struct {
	Profiles                   map[string]Profile                `toml:"profiles" json:"profiles"`
	Providers                  map[string]Provider               `toml:"providers" json:"providers"`
	Models                     map[string]map[string]CustomModel `toml:"models" json:"models"`
	CatalogTTLSeconds          int                               `toml:"catalog_ttl_seconds,omitempty" json:"catalog_ttl_seconds,omitempty"`
	ProviderTurnTimeoutSeconds int                               `toml:"provider_turn_timeout_seconds,omitempty" json:"provider_turn_timeout_seconds,omitempty"`
	Raw                        map[string]any                    `toml:"-" json:"-"`
}

Config is the merged representation. Raw preserves unknown, unrelated TOML keys during an atomic profile update; it is never sent to a provider.

func Default

func Default() Config

func Load

func Load(repoRoot string) (Config, error)

func LoadWithEnv

func LoadWithEnv(repoRoot string, environ []string) (Config, error)

func (Config) EffectiveProfiles

func (c Config) EffectiveProfiles() (map[string]Profile, error)

EffectiveProfiles expands the shared reviewer profile into the two review roles, returning independent values suitable for task snapshots.

func (Config) Profile

func (c Config) Profile(role string) (Profile, error)

func (Config) Provider

func (c Config) Provider(name string) Provider

func (Config) ResolveProfile

func (c Config) ResolveProfile(profile Profile) (Profile, Provider)

ResolveProfile canonicalizes a configured custom-model alias and overlays that model's safe route onto its provider route for task snapshotting.

type CustomModel

type CustomModel struct {
	ID            string   `toml:"id" json:"id"`
	Label         string   `toml:"label,omitempty" json:"label,omitempty"`
	Aliases       []string `toml:"aliases,omitempty" json:"aliases,omitempty"`
	Efforts       []string `toml:"efforts,omitempty" json:"efforts,omitempty"`
	DefaultEffort string   `toml:"default_effort,omitempty" json:"default_effort,omitempty"`
	Availability  string   `toml:"availability" json:"availability"`

	// Codex custom routing fields.
	Name                        string            `toml:"name,omitempty" json:"name,omitempty"`
	BaseURL                     string            `toml:"base_url,omitempty" json:"base_url,omitempty"`
	WireAPI                     string            `toml:"wire_api,omitempty" json:"wire_api,omitempty"`
	EnvKey                      string            `toml:"env_key,omitempty" json:"env_key,omitempty"`
	EnvHTTPHeaders              map[string]string `toml:"env_http_headers,omitempty" json:"env_http_headers,omitempty"`
	QueryParams                 map[string]string `toml:"query_params,omitempty" json:"query_params,omitempty"`
	RequestMaxRetries           int               `toml:"request_max_retries,omitempty" json:"request_max_retries,omitempty"`
	StreamMaxRetries            int               `toml:"stream_max_retries,omitempty" json:"stream_max_retries,omitempty"`
	StreamIdleTimeoutMS         int               `toml:"stream_idle_timeout_ms,omitempty" json:"stream_idle_timeout_ms,omitempty"`
	SupportsStandaloneWebSearch bool              `toml:"supports_standalone_web_search,omitempty" json:"supports_standalone_web_search,omitempty"`
	RequiresOpenAIAuth          bool              `toml:"requires_openai_auth,omitempty" json:"requires_openai_auth,omitempty"`
	Auth                        AuthCommand       `toml:"auth,omitempty" json:"auth,omitempty"`

	// Copilot named-provider model fields. Statically configured Copilot
	// models remain fail-closed until live SDK discovery verifies them.
	Provider               string         `toml:"provider,omitempty" json:"provider,omitempty"`
	WireModel              string         `toml:"wire_model,omitempty" json:"wire_model,omitempty"`
	ModelID                string         `toml:"model_id,omitempty" json:"model_id,omitempty"`
	MaxPromptTokens        int            `toml:"max_prompt_tokens,omitempty" json:"max_prompt_tokens,omitempty"`
	MaxContextWindowTokens int            `toml:"max_context_window_tokens,omitempty" json:"max_context_window_tokens,omitempty"`
	MaxOutputTokens        int            `toml:"max_output_tokens,omitempty" json:"max_output_tokens,omitempty"`
	Capabilities           map[string]any `toml:"capabilities,omitempty" json:"capabilities,omitempty"`
}

type Profile

type Profile struct {
	Provider string `toml:"provider" json:"provider"`
	Model    string `toml:"model" json:"model"`
	Effort   string `toml:"effort,omitempty" json:"effort,omitempty"`
	Speed    string `toml:"speed,omitempty" json:"speed,omitempty"`
}

type Provider

type Provider struct {
	Name      string `toml:"name,omitempty" json:"name,omitempty"`
	Type      string `toml:"type,omitempty" json:"type,omitempty"`
	WireAPI   string `toml:"wire_api,omitempty" json:"wire_api,omitempty"`
	Transport string `toml:"transport,omitempty" json:"transport,omitempty"`
	CLIPath   string `toml:"cli_path,omitempty" json:"cli_path,omitempty"`

	BaseURL                     string            `toml:"base_url,omitempty" json:"base_url,omitempty"`
	GatewayURL                  string            `toml:"gateway_url,omitempty" json:"gateway_url,omitempty"`
	Headers                     map[string]string `toml:"headers,omitempty" json:"headers,omitempty"`
	ModelID                     string            `toml:"model_id,omitempty" json:"model_id,omitempty"`
	WireModel                   string            `toml:"wire_model,omitempty" json:"wire_model,omitempty"`
	EnvKey                      string            `toml:"env_key,omitempty" json:"env_key,omitempty"`
	BearerTokenEnv              string            `toml:"bearer_token_env,omitempty" json:"bearer_token_env,omitempty"`
	EnvHTTPHeaders              map[string]string `toml:"env_http_headers,omitempty" json:"env_http_headers,omitempty"`
	QueryParams                 map[string]string `toml:"query_params,omitempty" json:"query_params,omitempty"`
	RequestMaxRetries           int               `toml:"request_max_retries,omitempty" json:"request_max_retries,omitempty"`
	StreamMaxRetries            int               `toml:"stream_max_retries,omitempty" json:"stream_max_retries,omitempty"`
	StreamIdleTimeoutMS         int               `toml:"stream_idle_timeout_ms,omitempty" json:"stream_idle_timeout_ms,omitempty"`
	SupportsStandaloneWebSearch bool              `toml:"supports_standalone_web_search,omitempty" json:"supports_standalone_web_search,omitempty"`
	RequiresOpenAIAuth          bool              `toml:"requires_openai_auth,omitempty" json:"requires_openai_auth,omitempty"`
	Auth                        AuthCommand       `toml:"auth,omitempty" json:"auth,omitempty"`

	// Claude's recognized gateway/BYOK references.
	APIKeyEnv          string            `toml:"api_key_env,omitempty" json:"api_key_env,omitempty"`
	AuthTokenEnv       string            `toml:"auth_token_env,omitempty" json:"auth_token_env,omitempty"`
	BedrockProfileEnv  string            `toml:"bedrock_profile_env,omitempty" json:"bedrock_profile_env,omitempty"`
	BedrockRegionEnv   string            `toml:"bedrock_region_env,omitempty" json:"bedrock_region_env,omitempty"`
	VertexProjectEnv   string            `toml:"vertex_project_env,omitempty" json:"vertex_project_env,omitempty"`
	VertexRegionEnv    string            `toml:"vertex_region_env,omitempty" json:"vertex_region_env,omitempty"`
	FoundryEndpointEnv string            `toml:"foundry_endpoint_env,omitempty" json:"foundry_endpoint_env,omitempty"`
	FoundryAPIKeyEnv   string            `toml:"foundry_api_key_env,omitempty" json:"foundry_api_key_env,omitempty"`
	EnvRefs            map[string]string `toml:"env_refs,omitempty" json:"env_refs,omitempty"`

	// Copilot SDK-safe settings. Static bearer/API values are rejected.
	MaxPromptTokens int               `toml:"max_prompt_tokens,omitempty" json:"max_prompt_tokens,omitempty"`
	MaxOutputTokens int               `toml:"max_output_tokens,omitempty" json:"max_output_tokens,omitempty"`
	APIVersion      string            `toml:"api_version,omitempty" json:"api_version,omitempty"`
	SDKSettings     map[string]string `toml:"sdk_settings,omitempty" json:"sdk_settings,omitempty"`
}

Provider contains only fixed, documented routing fields. The *Env fields are names, not values. Any map is validated before being sent to a provider.

Jump to

Keyboard shortcuts

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