config

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultPollInterval is the default interval for polling the token endpoint
	DefaultPollInterval = 5 * time.Second

	// OAuthClientID is the well-known client ID for the Skills CLI
	OAuthClientID = "sleuth-skills-claude-code"
)
View Source
const DefaultProfileName = "default"

DefaultProfileName is the name used for the default profile

Variables

This section is empty.

Functions

func Exists

func Exists() bool

Exists checks if a configuration file exists

func GetActiveProfileName added in v0.7.0

func GetActiveProfileName(mpc *MultiProfileConfig) string

GetActiveProfileName returns the name of the profile that owns single- profile actions (mutations, --profile flag overrides, --profile=NAME). For the read-side set used by sx install, see GetActiveProfileNames.

func GetActiveProfileNames added in v1.2.0

func GetActiveProfileNames(mpc *MultiProfileConfig) []string

GetActiveProfileNames returns every profile that should be loaded by read-side commands (sx install, sx list). When --profile or SX_PROFILE is set, the override list wins and its order is preserved (treating the user's explicit input as authoritative precedence). Otherwise ActiveProfiles is returned, with the default profile bubbled to the front so conflict resolution favors it.

func GetActiveProfileOverride added in v0.7.0

func GetActiveProfileOverride() string

GetActiveProfileOverride returns the current profile override, if any

func IsSilent

func IsSilent() bool

IsSilent checks if silent mode is enabled via environment variable

func LoadActive added in v1.2.0

func LoadActive() ([]*Config, *MultiProfileConfig, error)

LoadActive returns one Config per active profile. The default profile (if it is in the active set) is always first so callers can use slice order as conflict precedence. Used by read-side commands that must span every active profile (sx install, sx list).

func OpenBrowser

func OpenBrowser(verificationURI string) error

OpenBrowser opens the verification URI in the user's default browser

func Save

func Save(cfg *Config) error

Save saves the configuration to the config file This updates the active profile while preserving other profiles

func SaveMultiProfile added in v0.7.0

func SaveMultiProfile(mpc *MultiProfileConfig) error

SaveMultiProfile saves the full multi-profile configuration

func SaveToProfile added in v0.7.0

func SaveToProfile(cfg *Config, profileName string) error

SaveToProfile saves the configuration to a specific profile If profileName is empty, uses the active profile

func SetActiveProfile added in v0.7.0

func SetActiveProfile(name string)

SetActiveProfile sets the active profile for the current session This is typically set from a --profile flag or SX_PROFILE env var

Types

type Config

type Config struct {
	// Type of repository: "sleuth", "git", or "path"
	Type RepositoryType `json:"type"`

	// ServerURL is the Sleuth server URL (only for type=sleuth)
	ServerURL string `json:"serverUrl,omitempty"`

	// AuthToken is the OAuth token for Sleuth server or an HTTP(S) git token.
	AuthToken string `json:"authToken,omitempty"`

	// AuthUsername is the HTTP(S) basic-auth username used with AuthToken for
	// git repositories. Empty uses a host-specific default.
	AuthUsername string `json:"authUsername,omitempty"`

	// RepositoryURL is the repository URL
	// - For git: git repository URL (https://github.com/org/repo.git)
	// - For path: file:// URL pointing to local directory (file:///path/to/repo)
	RepositoryURL string `json:"repositoryUrl,omitempty"`

	// Identity is the email used to resolve team and user scopes when
	// this Config is the active profile. Empty falls back to git config.
	Identity string `json:"identity,omitempty"`

	// ProfileName is the active profile name this Config was loaded from.
	// Populated by Load(); not serialized.
	ProfileName string `json:"-"`

	// ForceEnabledClients is the list of client IDs that should always be enabled,
	// even if not detected.
	ForceEnabledClients []string `json:"forceEnabledClients,omitempty"`

	// ForceDisabledClients is the list of client IDs that should always be disabled,
	// even if detected.
	ForceDisabledClients []string `json:"forceDisabledClients,omitempty"`
}

Config represents the configuration for the skills CLI

func Load

func Load() (*Config, error)

Load loads the configuration from the config file Uses the multi-profile system and returns the active profile as a Config

func (*Config) GetAuthToken

func (c *Config) GetAuthToken() string

GetAuthToken returns the auth token

func (*Config) GetAuthUsername added in v1.3.0

func (c *Config) GetAuthUsername() string

GetAuthUsername returns the git HTTP(S) basic-auth username.

func (*Config) GetIdentity added in v1.2.0

func (c *Config) GetIdentity() string

GetIdentity returns the configured identity email for this profile, or empty when not set (callers fall back to git config user.email).

func (*Config) GetProfileName added in v1.2.0

func (c *Config) GetProfileName() string

GetProfileName returns the profile name this Config was loaded from.

func (*Config) GetRepositoryURL

func (c *Config) GetRepositoryURL() string

GetRepositoryURL returns the repository URL

func (*Config) GetServerURL

func (c *Config) GetServerURL() string

GetServerURL returns the Sleuth server URL, with environment override For backwards compatibility, falls back to ServerURL if RepositoryURL is empty

func (*Config) GetType

func (c *Config) GetType() string

GetType returns the repository type

func (*Config) HasExplicitClientConfig added in v0.11.0

func (c *Config) HasExplicitClientConfig() bool

HasExplicitClientConfig returns true if any force enable/disable settings exist.

func (*Config) IsClientEnabled added in v0.5.4

func (c *Config) IsClientEnabled(clientID string) bool

IsClientEnabled checks if a specific client ID is enabled. ForceDisabled takes precedence over ForceEnabled. If neither, the client is enabled by default (relies on detection).

func (*Config) IsClientForceDisabled added in v0.11.0

func (c *Config) IsClientForceDisabled(clientID string) bool

IsClientForceDisabled checks if a client is explicitly force-disabled.

func (*Config) IsClientForceEnabled added in v0.11.0

func (c *Config) IsClientForceEnabled(clientID string) bool

IsClientForceEnabled checks if a client is explicitly force-enabled.

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the configuration

func (*Config) VaultIdentifier added in v1.2.0

func (c *Config) VaultIdentifier() string

VaultIdentifier returns a stable string that uniquely identifies the vault this Config points at, suitable for use as a cache partition key. Prefers RepositoryURL when set (the canonical field for git and path vaults, and modern Sleuth configs) and falls back to ServerURL for legacy Sleuth configs that predate the RepositoryURL field. Returns empty only when both are missing — which Validate would have already rejected.

type MultiProfileConfig added in v0.7.0

type MultiProfileConfig struct {
	// DefaultProfile is the profile that owns "write" actions when no
	// --profile flag is given (sx add, sx role, sx team ...). It is also
	// the conflict tiebreaker when multiple active profiles publish an
	// asset with the same name. Always a member of ActiveProfiles.
	DefaultProfile string `json:"defaultProfile"`

	// ActiveProfiles is the set of profiles considered "on" for read
	// operations (sx install, sx list). When more than one is active,
	// install merges applicable assets from every active profile's vault.
	// Order is precedence for conflict resolution when DefaultProfile
	// isn't in the active set.
	ActiveProfiles []string `json:"activeProfiles,omitempty"`

	// Profiles is a map of profile name to profile configuration
	Profiles map[string]*Profile `json:"profiles"`

	// EnabledClients is DEPRECATED - use ForceEnabledClients/ForceDisabledClients instead.
	// Kept for migration purposes only.
	EnabledClients []string `json:"enabledClients,omitempty"`

	// ForceEnabledClients is the list of client IDs that should always be enabled,
	// even if not detected. This is global across all profiles.
	ForceEnabledClients []string `json:"forceEnabledClients,omitempty"`

	// ForceDisabledClients is the list of client IDs that should always be disabled,
	// even if detected. This is global across all profiles.
	ForceDisabledClients []string `json:"forceDisabledClients,omitempty"`

	// BootstrapOptions stores user consent for bootstrap items (hooks, MCP servers).
	// Keyed by option key, nil/missing = yes (backwards compatible).
	BootstrapOptions map[string]*bool `json:"bootstrapOptions,omitempty"`
}

MultiProfileConfig represents the full configuration file with multiple profiles

func LoadMultiProfile added in v0.7.0

func LoadMultiProfile() (*MultiProfileConfig, error)

LoadMultiProfile loads the full multi-profile configuration

func (*MultiProfileConfig) Activate added in v1.2.0

func (mpc *MultiProfileConfig) Activate(name string) error

Activate adds name to ActiveProfiles. Returns an error if the profile does not exist. A no-op when already active.

func (*MultiProfileConfig) Deactivate added in v1.2.0

func (mpc *MultiProfileConfig) Deactivate(name string) error

Deactivate removes name from ActiveProfiles. Refuses to remove the last active profile. If the deactivated profile was also the default, the first remaining active profile takes over as the new default so the invariant "DefaultProfile is always active" still holds.

func (*MultiProfileConfig) DeleteProfile added in v0.7.0

func (mpc *MultiProfileConfig) DeleteProfile(name string) error

DeleteProfile removes a profile by name

func (*MultiProfileConfig) GetBootstrapOption added in v0.9.2

func (mpc *MultiProfileConfig) GetBootstrapOption(key string) bool

GetBootstrapOption returns whether a bootstrap option is enabled. Returns true if the option is missing/nil (backwards compatible - existing users get everything).

func (*MultiProfileConfig) GetProfile added in v0.7.0

func (mpc *MultiProfileConfig) GetProfile(name string) (*Profile, bool)

GetProfile returns a profile by name

func (*MultiProfileConfig) IsProfileActive added in v1.2.0

func (mpc *MultiProfileConfig) IsProfileActive(name string) bool

IsProfileActive reports whether the named profile is in ActiveProfiles.

func (*MultiProfileConfig) ListProfiles added in v0.7.0

func (mpc *MultiProfileConfig) ListProfiles() []string

ListProfiles returns a sorted list of profile names

func (*MultiProfileConfig) MigrateEnabledClients added in v0.11.0

func (mpc *MultiProfileConfig) MigrateEnabledClients(allClientIDs []string) (bool, error)

MigrateEnabledClients migrates the deprecated EnabledClients field to the new ForceEnabledClients/ForceDisabledClients fields. Call this with all known client IDs. Returns true if migration was performed and config was saved.

func (*MultiProfileConfig) NeedsMigration added in v0.11.0

func (mpc *MultiProfileConfig) NeedsMigration() bool

NeedsMigration returns true if the config has deprecated EnabledClients field

func (*MultiProfileConfig) SetBootstrapOption added in v0.9.2

func (mpc *MultiProfileConfig) SetBootstrapOption(key string, enabled bool)

SetBootstrapOption sets a bootstrap option value.

func (*MultiProfileConfig) SetDefaultProfile added in v0.7.0

func (mpc *MultiProfileConfig) SetDefaultProfile(name string) error

SetDefaultProfile sets the default profile, activating it if needed.

func (*MultiProfileConfig) SetProfile added in v0.7.0

func (mpc *MultiProfileConfig) SetProfile(name string, profile *Profile)

SetProfile adds or updates a profile

type OAuthClient

type OAuthClient struct {
	// contains filtered or unexported fields
}

OAuthClient handles OAuth device code flow

func NewOAuthClient

func NewOAuthClient(serverURL string) *OAuthClient

NewOAuthClient creates a new OAuth client

func (*OAuthClient) PollForToken

func (o *OAuthClient) PollForToken(ctx context.Context, deviceCode string) (*OAuthTokenResponse, error)

PollForToken polls the token endpoint until the user completes authorization

func (*OAuthClient) StartDeviceFlow

func (o *OAuthClient) StartDeviceFlow(ctx context.Context) (*OAuthDeviceCodeResponse, error)

StartDeviceFlow initiates the OAuth device code flow

type OAuthDeviceCodeResponse

type OAuthDeviceCodeResponse struct {
	DeviceCode              string `json:"device_code"`
	UserCode                string `json:"user_code"`
	VerificationURI         string `json:"verification_uri"`
	VerificationURIComplete string `json:"verification_uri_complete,omitempty"`
	ExpiresIn               int    `json:"expires_in"`
	Interval                int    `json:"interval,omitempty"`
}

OAuthDeviceCodeResponse represents the response from the device authorization endpoint

type OAuthTokenResponse

type OAuthTokenResponse struct {
	AccessToken  string `json:"access_token"`
	TokenType    string `json:"token_type"`
	ExpiresIn    int    `json:"expires_in,omitempty"`
	RefreshToken string `json:"refresh_token,omitempty"`
	Error        string `json:"error,omitempty"`
	ErrorDesc    string `json:"error_description,omitempty"`
}

OAuthTokenResponse represents the response from the token endpoint

type Profile added in v0.7.0

type Profile struct {
	// Type of repository: "sleuth", "git", or "path"
	Type RepositoryType `json:"type"`

	// ServerURL is the Sleuth server URL (only for type=sleuth)
	ServerURL string `json:"serverUrl,omitempty"`

	// AuthToken is the OAuth token for Sleuth server or an HTTP(S) git token.
	AuthToken string `json:"authToken,omitempty"`

	// AuthUsername is the HTTP(S) basic-auth username used with AuthToken for
	// git repositories. Empty uses a host-specific default.
	AuthUsername string `json:"authUsername,omitempty"`

	// RepositoryURL is the repository URL
	// - For git: git repository URL (https://github.com/org/repo.git)
	// - For path: file:// URL pointing to local directory (file:///path/to/repo)
	RepositoryURL string `json:"repositoryUrl,omitempty"`

	// Identity is the email used to resolve team and user scopes for this
	// profile. When empty, sx falls back to `git config user.email`. Set
	// per-profile so a single machine can use different identities for
	// different vaults (e.g. work vs personal email).
	Identity string `json:"identity,omitempty"`
}

Profile represents a single configuration profile

func ProfileFromConfig added in v0.7.0

func ProfileFromConfig(cfg *Config) *Profile

ProfileFromConfig creates a Profile from a Config

func (*Profile) ToConfig added in v0.7.0

func (p *Profile) ToConfig(forceEnabled, forceDisabled []string) *Config

ToConfig converts a Profile to a Config with the given client settings

type RepositoryType

type RepositoryType string

RepositoryType represents the type of repository (sleuth, git, or path)

const (
	RepositoryTypeSleuth RepositoryType = "sleuth"
	RepositoryTypeGit    RepositoryType = "git"
	RepositoryTypePath   RepositoryType = "path"
)

Jump to

Keyboard shortcuts

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