store

package
v0.3.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateName added in v0.3.0

func ValidateName(name string) error

ValidateName reports whether name can be used as a profile name.

Types

type Check

type Check struct {
	Message string
	Warning bool
}

type DaemonState added in v0.2.1

type DaemonState struct {
	daemon.Status
	// Stale means the daemon is running and started before codexctl last
	// changed auth.json, so it still uses the credentials it loaded then.
	Stale bool
	// Profile is the profile that change activated, or "" if it signed Codex
	// out. It is only set when Stale is true.
	Profile string
}

DaemonState describes the Codex app-server daemon relative to the active auth.json.

type Identity added in v0.2.0

type Identity struct {
	AuthMode    string `json:"auth_mode,omitempty"`
	AccountID   string `json:"account_id,omitempty"`
	Email       string `json:"email,omitempty"`
	Plan        string `json:"plan,omitempty"`
	LastRefresh string `json:"last_refresh,omitempty"`
}

Identity is the non-secret description of a credential file. It never carries tokens or API keys, so it is safe to print.

type Profile added in v0.2.0

type Profile struct {
	Name     string `json:"name"`
	Selected bool   `json:"selected"`
	Valid    bool   `json:"valid"`
	Identity
}

Profile describes a saved profile without exposing its credentials.

type Store

type Store struct {
	CodexHome string
	StateHome string
	// DetectDaemon inspects the app-server daemon of a Codex home. Nil means
	// daemon.Detect; tests substitute a fake.
	DetectDaemon func(codexHome string) daemon.Status
	// contains filtered or unexported fields
}

func NewFromEnvironment

func NewFromEnvironment() (*Store, error)

func (*Store) AuthChanged added in v0.2.1

func (s *Store) AuthChanged() bool

AuthChanged reports whether this Store changed the active auth.json, including by finishing an interrupted switch.

func (*Store) AuthPath added in v0.3.0

func (s *Store) AuthPath() string

AuthPath is the active Codex credential file.

func (*Store) Current

func (s *Store) Current() (string, bool, error)

func (*Store) Daemon added in v0.2.1

func (s *Store) Daemon() DaemonState

Daemon reports the app-server daemon of this Codex home and whether it predates the last account switch.

func (*Store) Doctor

func (s *Store) Doctor() []Check

func (*Store) Import added in v0.2.0

func (s *Store) Import(name string) error

Import saves the active auth.json as a new profile and selects it. It is meant for accounts that were logged in with plain `codex login` before codexctl was installed.

func (*Store) List

func (s *Store) List() ([]string, string, error)

List returns the saved profile names in sorted order and the selected one.

func (*Store) Login

func (s *Store) Login(name string, runLogin func(home string) error) (string, error)

func (*Store) Logout added in v0.2.0

func (s *Store) Logout(name string, runLogout func(home string) error) (string, error)

Logout runs `codex logout` for a saved profile inside an isolated home, so the session is revoked without touching the real Codex home, then deletes the profile. If the profile was selected and the active auth.json holds the same account, that file is removed as well, since its tokens are no longer usable.

func (*Store) Profiles added in v0.2.0

func (s *Store) Profiles() ([]Profile, error)

Profiles returns every saved profile with its identity, sorted by name.

func (*Store) Purge added in v0.3.0

func (s *Store) Purge(before func() error) error

Purge deletes codexctl's state directory: every saved profile, the selection, and the switch records. The Codex home, including the active auth.json and config.toml, is left alone, so Codex stays logged in.

before, when not nil, runs while the lock is held and before anything is deleted; if it fails nothing is removed.

func (*Store) Remove added in v0.2.0

func (s *Store) Remove(name string) (string, error)

Remove deletes a saved profile. Removing the selected profile clears the selection but leaves the active auth.json in place, so Codex stays logged in; use `codex logout` to sign out of the account itself.

func (*Store) Rename added in v0.2.0

func (s *Store) Rename(oldName, newName string) (string, error)

Rename gives a saved profile a new name. If the profile is the selected one, its refreshed credentials are saved first and the selection follows the new name. The active auth.json is not touched.

func (*Store) Show added in v0.2.0

func (s *Store) Show(name string) (Profile, error)

Show returns the identity of one saved profile.

func (*Store) Sync added in v0.2.0

func (s *Store) Sync() (string, error)

Sync saves credential refreshes from the active auth.json into the selected profile and returns that profile's name.

func (*Store) Use

func (s *Store) Use(name string) (string, error)

Jump to

Keyboard shortcuts

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