Documentation
¶
Overview ¶
Package migrate owns the on-disk YAML schema for LeanProxy's user-server configuration. It re-exports the canonical transport enum used throughout the codebase so callers can refer to it without depending on pkg/registry (which already depends on this package for ServerConfig).
Index ¶
- Constants
- func ExecutableExists(cmd string) bool
- func FormatValidationSummary(imported int, result *ValidationResult) string
- func IsAlreadyInstalled(err error) bool
- func IsUnknownServer(err error) bool
- func MarshalConfig(cfg *Config) ([]byte, error)
- func SaveConfig(path string, cfg *Config) error
- func SuggestSimilar(needle string, entries []CacheEntry, limit int) []string
- type AuthConfig
- type CacheConfig
- type CacheEntry
- type CacheSettings
- type CacheSnapshot
- type ClaudeScanner
- type Config
- type CursorScanner
- type DiscoveredServer
- type ErrAlreadyInstalled
- type ErrUnknownServer
- type FederationConfig
- type GenericScanner
- type HTTPConfig
- type ImportResult
- type InstallOptions
- type InstallResult
- type Installer
- type LazyLoadingSettings
- type LifecycleStopper
- type MigrationSummary
- type Migrator
- func (m *Migrator) Import(ctx context.Context, servers []DiscoveredServer, targetPath string, yes bool) (*ImportResult, error)
- func (m *Migrator) ImportAll(ctx context.Context, servers []DiscoveredServer, yes bool) (*ImportResult, error)
- func (m *Migrator) Scan(ctx context.Context) (*ScanResult, error)
- func (m *Migrator) Summarize(servers []DiscoveredServer) *MigrationSummary
- func (m *Migrator) Validate(servers []DiscoveredServer) *ValidationResult
- type OpenCodeScanner
- type OptimizationConfig
- type PeerConfig
- type PineconeVectorConfig
- type QdrantVectorConfig
- type ReconnectConfig
- type ResolvedReconnect
- type SQLiteVectorConfig
- type ScanResult
- type Scanner
- type ServerConfig
- type ServerSource
- type StdioConfig
- type SummarizeSettings
- type TransportType
- type VSCodeScanner
- type ValidationError
- type ValidationResult
- type Validator
- type VectorStoreConfig
Constants ¶
const SimilarityLimit = 5
SimilarityLimit bounds the number of "did you mean" suggestions returned by Install when the requested server id is not in the registry cache.
Variables ¶
This section is empty.
Functions ¶
func ExecutableExists ¶
func FormatValidationSummary ¶
func FormatValidationSummary(imported int, result *ValidationResult) string
func IsAlreadyInstalled ¶ added in v0.8.0
IsAlreadyInstalled reports whether err (or any wrapped error) is an ErrAlreadyInstalled.
func IsUnknownServer ¶ added in v0.8.0
IsUnknownServer reports whether err (or any wrapped error) is an ErrUnknownServer.
func MarshalConfig ¶ added in v0.2.0
func SaveConfig ¶ added in v0.8.0
SaveConfig writes cfg to path with 0600 permissions, creating the parent directory if needed. The write is atomic: a temp file in the same directory is created, fsynced, then renamed over the target.
func SuggestSimilar ¶ added in v0.8.0
func SuggestSimilar(needle string, entries []CacheEntry, limit int) []string
SuggestSimilar ranks entries by Levenshtein distance to needle and returns the top-n closest names. Identical matches are excluded (Resolve handles the exact case before calling this helper).
Types ¶
type AuthConfig ¶ added in v0.7.0
type CacheConfig ¶ added in v0.8.0
type CacheConfig struct {
VectorStore *VectorStoreConfig `yaml:"vector_store,omitempty"`
}
type CacheEntry ¶ added in v0.8.0
type CacheEntry struct {
Name string
Transport string
Command string
Args []string
Env map[string]string
URL string
TokensPerTurn int64
}
CacheEntry is the subset of a registry feed record the installer cares about. Defining it here keeps the installer decoupled from the registry package's concrete types.
type CacheSettings ¶
type CacheSnapshot ¶ added in v0.8.0
type CacheSnapshot struct {
Entries []CacheEntry
}
CacheSnapshot is the materialized view of the registry cache. It is returned by ServerSource.LookupCache.
type ClaudeScanner ¶
type ClaudeScanner struct{}
func (*ClaudeScanner) Name ¶
func (s *ClaudeScanner) Name() string
func (*ClaudeScanner) Scan ¶
func (s *ClaudeScanner) Scan(ctx context.Context) ([]DiscoveredServer, error)
type Config ¶
type Config struct {
Version string `yaml:"version"`
Servers []*ServerConfig `yaml:"servers"`
Reconnect *ReconnectConfig `yaml:"reconnect,omitempty"`
Optimization *OptimizationConfig `yaml:"optimization,omitempty"`
Cache *CacheConfig `yaml:"cache,omitempty"`
Federation *FederationConfig `yaml:"federation,omitempty"`
Injection *injection.Config `yaml:"injection,omitempty"`
}
func (*Config) EffectiveReconnect ¶ added in v0.9.0
func (c *Config) EffectiveReconnect() ResolvedReconnect
type CursorScanner ¶
type CursorScanner struct{}
func (*CursorScanner) Name ¶
func (s *CursorScanner) Name() string
func (*CursorScanner) Scan ¶
func (s *CursorScanner) Scan(ctx context.Context) ([]DiscoveredServer, error)
type DiscoveredServer ¶
type DiscoveredServer struct {
Name string
Source string
Transport TransportType
Stdio *StdioConfig
HTTP *HTTPConfig
Enabled *bool
}
type ErrAlreadyInstalled ¶ added in v0.8.0
type ErrAlreadyInstalled struct {
ServerID string
}
ErrAlreadyInstalled is returned when the server name already exists in the user config and neither Force nor an interactive confirmation has been supplied.
func (*ErrAlreadyInstalled) Error ¶ added in v0.8.0
func (e *ErrAlreadyInstalled) Error() string
type ErrUnknownServer ¶ added in v0.8.0
ErrUnknownServer is returned by Install when the requested server id is not present in the local registry cache. It carries suggested similar names so callers can present a "did you mean" hint without re-running the search.
func (*ErrUnknownServer) Error ¶ added in v0.8.0
func (e *ErrUnknownServer) Error() string
type FederationConfig ¶ added in v0.7.0
type FederationConfig struct {
Enabled bool `yaml:"enabled"`
Peers []*PeerConfig `yaml:"peers"`
}
type GenericScanner ¶
type GenericScanner struct{}
func (*GenericScanner) Name ¶
func (s *GenericScanner) Name() string
func (*GenericScanner) Scan ¶
func (s *GenericScanner) Scan(ctx context.Context) ([]DiscoveredServer, error)
type HTTPConfig ¶
type HTTPConfig struct {
URL string `yaml:"url"`
Headers map[string]string `yaml:"headers"`
Auth *AuthConfig `yaml:"auth,omitempty"`
}
type ImportResult ¶
type ImportResult struct {
Imported int
Duplicates int
Errors []error
Validation *ValidationResult
}
type InstallOptions ¶ added in v0.8.0
type InstallOptions struct {
// Force, when true, allows overwriting an existing server definition.
Force bool
// StopExisting, when true, asks the stopper to gracefully stop any
// running instance that shares the target name before the new definition
// is written.
StopExisting bool
// GracefulTimeout is the budget for the graceful stop before the caller
// proceeds with the install regardless. Zero means use the stop call's
// default context.
GracefulTimeout time.Duration
// Stopper, when set, is invoked to stop existing instances when
// StopExisting is true. It may be nil for offline (config-only) installs.
Stopper LifecycleStopper
// Logger is used for operational logs. Defaults to slog.Default().
Logger *slog.Logger
// DryRun, when true, prevents any filesystem writes and any stopper
// calls. The result still reflects what would have happened.
DryRun bool
}
InstallOptions controls Install behavior. The zero value performs an additive install with no graceful stop and no lifecycle manager.
type InstallResult ¶ added in v0.8.0
type InstallResult struct {
ServerID string
ServerName string
Transport string
Replaced bool
Stopped bool
ConfigPath string
DryRun bool
EstimatedTools int
SnapshotSummary string
}
InstallResult captures the outcome of a successful Install call. It is always non-nil when err is nil.
type Installer ¶ added in v0.8.0
type Installer struct {
Source ServerSource
ConfigPath string
Logger *slog.Logger
}
Installer is the top-level facade used by cmd/add. It composes a cache source and a config path.
func NewInstaller ¶ added in v0.8.0
func NewInstaller(source ServerSource, configPath string, logger *slog.Logger) *Installer
NewInstaller wires an Installer with the given cache source and config path. Either may be overridden after construction by setting the fields directly.
func (*Installer) Install ¶ added in v0.8.0
func (i *Installer) Install(ctx context.Context, entry CacheEntry, opts InstallOptions) (*InstallResult, error)
Install builds a ServerConfig from the cache entry, merges it into the user config at i.ConfigPath (writing through MarshalConfig), and — if StopExisting is true — gracefully stops any running instance that shares the target name via the provided Stopper.
The returned result is always non-nil when err is nil.
func (*Installer) Resolve ¶ added in v0.8.0
Resolve returns the registry entry for serverID (case-insensitive). If no exact match is found, it returns an *ErrUnknownServer populated with up to SimilarityLimit suggestions ranked by edit distance.
Resolve never triggers a Sync; callers are expected to have a fresh cache.
type LazyLoadingSettings ¶ added in v0.7.0
type LifecycleStopper ¶ added in v0.8.0
LifecycleStopper is the narrow surface the installer needs from a server lifecycle manager. The concrete *registry.LifecycleManager satisfies it via its Stop method, but the installer accepts the interface so callers can pass a fake in tests.
type MigrationSummary ¶
type MigrationSummary struct {
OpenCodeCount int
ClaudeCount int
VSCodeCount int
CursorCount int
GenericCount int
TotalServers int
}
func (*MigrationSummary) Total ¶
func (s *MigrationSummary) Total() int
type Migrator ¶
type Migrator struct {
// contains filtered or unexported fields
}
func NewMigrator ¶
func NewMigrator() *Migrator
func (*Migrator) Import ¶
func (m *Migrator) Import(ctx context.Context, servers []DiscoveredServer, targetPath string, yes bool) (*ImportResult, error)
func (*Migrator) ImportAll ¶
func (m *Migrator) ImportAll(ctx context.Context, servers []DiscoveredServer, yes bool) (*ImportResult, error)
func (*Migrator) Summarize ¶
func (m *Migrator) Summarize(servers []DiscoveredServer) *MigrationSummary
func (*Migrator) Validate ¶
func (m *Migrator) Validate(servers []DiscoveredServer) *ValidationResult
type OpenCodeScanner ¶
type OpenCodeScanner struct{}
func (*OpenCodeScanner) Name ¶
func (s *OpenCodeScanner) Name() string
func (*OpenCodeScanner) Scan ¶
func (s *OpenCodeScanner) Scan(ctx context.Context) ([]DiscoveredServer, error)
type OptimizationConfig ¶ added in v0.7.0
type OptimizationConfig struct {
LazyLoading *LazyLoadingSettings `yaml:"lazy_loading,omitempty"`
}
type PeerConfig ¶ added in v0.7.0
type PineconeVectorConfig ¶ added in v0.8.0
type QdrantVectorConfig ¶ added in v0.8.0
type ReconnectConfig ¶ added in v0.9.0
type ReconnectConfig struct {
Enabled *bool `yaml:"enabled"`
HealthInterval string `yaml:"health_check_interval"`
HealthIntervalValue time.Duration `yaml:"-"`
MaxFailures int `yaml:"health_check_failures"`
MaxRestartAttempts int `yaml:"max_restart_attempts"`
RestartBackoff string `yaml:"restart_backoff"`
RestartBackoffValue time.Duration `yaml:"-"`
StableWindow string `yaml:"stable_window"`
StableWindowValue time.Duration `yaml:"-"`
}
type ResolvedReconnect ¶ added in v0.9.0
type SQLiteVectorConfig ¶ added in v0.8.0
type SQLiteVectorConfig struct {
Path string `yaml:"path"`
}
type ScanResult ¶
type ScanResult struct {
Scanners []string
Servers []DiscoveredServer
}
type Scanner ¶
type Scanner interface {
Name() string
Scan(ctx context.Context) ([]DiscoveredServer, error)
}
type ServerConfig ¶
type ServerConfig struct {
Name string `yaml:"name"`
Enabled *bool `yaml:"enabled"`
Transport TransportType `yaml:"transport"`
ComplexityTier string `yaml:"complexity_tier,omitempty"`
Stdio *StdioConfig `yaml:"stdio,omitempty"`
HTTP *HTTPConfig `yaml:"http,omitempty"`
Timeout string `yaml:"timeout"`
TimeoutValue time.Duration `yaml:"-"`
ConnectTimeout string `yaml:"connect_timeout"`
ConnectTimeoutValue time.Duration `yaml:"-"`
IdleTimeout string `yaml:"idle_timeout"`
IdleTimeoutValue time.Duration `yaml:"-"`
CacheSettings *CacheSettings `yaml:"cache_settings,omitempty"`
SummarizeSettings *SummarizeSettings `yaml:"summarize_settings,omitempty"`
}
func (*ServerConfig) Validate ¶
func (c *ServerConfig) Validate() error
type ServerSource ¶ added in v0.8.0
type ServerSource interface {
// LookupCache returns the list of (name, transport, command, url,
// tokens-per-turn) records available locally. The bool reports whether
// any cache was present; an empty slice with bool == true means "cache
// exists but is empty".
LookupCache(ctx context.Context) (CacheSnapshot, error)
}
ServerSource is the minimal interface the installer needs from a registry cache. It is satisfied by *registry.FeedFetcher (which returns a *registry.FeedIndex) but defined here to avoid an import cycle with the registry package, which in turn depends on this package for the ServerConfig schema.
type StdioConfig ¶
type SummarizeSettings ¶
type TransportType ¶ added in v0.8.0
type TransportType string
TransportType enumerates the wire transports a server may speak. The string values are part of the public YAML schema and must not change without a migration step.
const ( TransportStdio TransportType = "stdio" TransportHTTP TransportType = "http" TransportSSE TransportType = "sse" )
type VSCodeScanner ¶
type VSCodeScanner struct{}
func (*VSCodeScanner) Name ¶
func (s *VSCodeScanner) Name() string
func (*VSCodeScanner) Scan ¶
func (s *VSCodeScanner) Scan(ctx context.Context) ([]DiscoveredServer, error)
type ValidationError ¶
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
type ValidationResult ¶
type ValidationResult struct {
Errors []ValidationError
Warnings []ValidationError
}
func (*ValidationResult) ErrorCount ¶
func (r *ValidationResult) ErrorCount() int
func (*ValidationResult) HasErrors ¶
func (r *ValidationResult) HasErrors() bool
func (*ValidationResult) HasWarnings ¶
func (r *ValidationResult) HasWarnings() bool
func (*ValidationResult) WarningCount ¶
func (r *ValidationResult) WarningCount() int
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
func NewValidator ¶
func NewValidator() *Validator
func NewValidatorWithoutExecutableCheck ¶
func NewValidatorWithoutExecutableCheck() *Validator
func (*Validator) ValidateServers ¶
func (v *Validator) ValidateServers(servers []DiscoveredServer) *ValidationResult
type VectorStoreConfig ¶ added in v0.8.0
type VectorStoreConfig struct {
Backend string `yaml:"backend"`
Dimension int `yaml:"dimension"`
SQLite *SQLiteVectorConfig `yaml:"sqlite,omitempty"`
Qdrant *QdrantVectorConfig `yaml:"qdrant,omitempty"`
Pinecone *PineconeVectorConfig `yaml:"pinecone,omitempty"`
}