profile

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package profile manages named provider/model configuration profiles stored globally in ~/.cloop/profiles.yaml.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(p Profile, cfg *config.Config)

Apply overlays the non-empty fields from p onto cfg. Provider and Model override the top-level config fields. BaseURL and APIKey are applied to the matching provider sub-config.

func Delete

func Delete(name string) error

Delete removes the named profile. Returns nil if it does not exist.

func GetActive

func GetActive() string

GetActive returns the name of the active profile, or "" if none is set.

func SaveProfiles

func SaveProfiles(profiles []Profile) error

SaveProfiles writes the profiles slice to ~/.cloop/profiles.yaml.

The write is atomic — data is staged in a sibling .tmp file, fsynced, then renamed into place. profiles.yaml may contain API keys, so a torn write (crash, ENOSPC, or two cloop instances saving simultaneously) would silently drop credentials and break every profile-driven run until the user re-pasted them.

func SetActive

func SetActive(name string) error

SetActive writes the active profile name to ~/.cloop/active_profile. Pass "" to clear the active profile.

The write is atomic and serialised — a partial write here would resolve to the wrong profile (or none) on the next run, silently swapping which API key/model gets used.

func Upsert

func Upsert(p Profile) error

Upsert adds a new profile or replaces an existing one with the same name.

The load → modify → save cycle runs under profilesMu so two concurrent Upsert calls in the same process can't read the same baseline and drop one of the writes. Cross-process safety still relies on the atomic rename in saveProfilesLocked.

Types

type Profile

type Profile struct {
	Name        string `yaml:"name"`
	Provider    string `yaml:"provider,omitempty"`
	Model       string `yaml:"model,omitempty"`
	BaseURL     string `yaml:"base_url,omitempty"`
	APIKey      string `yaml:"api_key,omitempty"`
	Description string `yaml:"description,omitempty"`
}

Profile is a named set of provider/model configuration overrides.

func Get

func Get(name string) (*Profile, error)

Get returns the named profile, or an error if it does not exist.

func LoadProfiles

func LoadProfiles() ([]Profile, error)

LoadProfiles reads all profiles from ~/.cloop/profiles.yaml. Returns an empty slice (not an error) if the file does not exist.

Reads don't take profilesMu — the atomic-rename writers always present a complete file, so a concurrent reader sees either the previous version or the new one, never a torn one.

Jump to

Keyboard shortcuts

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