Documentation
¶
Overview ¶
Package codexprofile keeps more than one Codex login on one machine, the way internal/claudeprofile does for Claude Code. A profile is a state directory of its own (CODEX_HOME) holding its own `codex login`, so every account runs with its full login. The default profile, Personal, is whatever Codex reads without lich's help: CODEX_HOME from lich's environment, else ~/.codex.
A profile directory is never moved once it exists, and renaming a profile changes its display name only: the slug names the directory, and Codex may key a login on the directory string (its keyring store does).
Index ¶
- Constants
- Variables
- func ConfigDir(slug string) (string, error)
- func Delete(slug string) error
- func Dir(slug string) (string, error)
- func EnablePlugin(dir, key string) (bool, error)
- func EnsureShared(slug string) error
- func Env(base []string, dir string) []string
- func IsPersonal(slug string) bool
- func MoveConversation(conversationID, toSlug string) error
- func PersonalDir() (string, error)
- func RolloutIn(dir, conversationID string) (string, bool)
- func Root() (string, error)
- type BinResolver
- type Info
- type LoginEvent
- type Plugin
- type PluginResult
- type Profile
- type Service
- func (s *Service) CancelLogin(_ context.Context, opts api.ProfileSlugOptions) (api.None, error)
- func (s *Service) CreateProfile(_ context.Context, opts api.CreateProfileOptions) (Profile, error)
- func (s *Service) DeleteProfile(ctx context.Context, opts api.ProfileSlugOptions) (api.None, error)
- func (s *Service) InstallPlugins(_ context.Context, opts api.InstallPluginsOptions) ([]PluginResult, error)
- func (s *Service) Login(_ context.Context, opts api.ProfileSlugOptions) (api.None, error)
- func (s *Service) LoginCommand(_ context.Context, opts api.ProfileSlugOptions) (string, error)
- func (s *Service) Plugins(_ context.Context, opts api.ProfileSlugOptions) ([]Plugin, error)
- func (s *Service) Profiles(_ context.Context, _ api.None) ([]Info, error)
- func (s *Service) SetAccount(account func(slug string) (email, plan string))
- func (s *Service) SetLichPlugin(install func(slug string) error, key string)
- func (s *Service) SetSessions(inUse func(slug string) int, forget func(slug string) error)
- func (s *Service) UpdateProfile(_ context.Context, opts api.UpdateProfileOptions) (Profile, error)
Constants ¶
const HomeVar = "CODEX_HOME"
HomeVar is the variable Codex reads its state directory from.
const Personal = profilestore.Personal
Personal is the slug of the default profile. It is reserved: no profile lich creates can take it, which is what lets a project setting name Personal explicitly where an empty value means "inherit the global one".
Variables ¶
var ErrProfileGone = profilestore.ErrGone
ErrProfileGone is the error a spawn returns for a session born in a profile that was deleted since. The window matches it to offer a new session in the project's own profile instead.
Functions ¶
func ConfigDir ¶
ConfigDir is a profile's state directory, Personal's included. A profile that does not exist answers ErrProfileGone.
func Delete ¶
Delete removes a profile's directory and its login with it. Personal cannot be deleted.
func Dir ¶
Dir is the CODEX_HOME of a profile lich created. It does not check that the profile exists; ConfigDir does.
func EnablePlugin ¶
EnablePlugin turns back on a plugin the config.toml in dir has turned off, the `enabled = false` Codex writes under `[plugins."<key>"]` (measured on 0.170.0). It reports whether it changed the file. A plugin with no table, or one not turned off, is left as written: this switches, it never installs.
func EnsureShared ¶
EnsureShared links into a profile the shared entries Personal gained since the profile was made and rebuilds its config.toml from Personal's, which runs before every spawn into it.
func Env ¶
Env is base with a profile's directory as CODEX_HOME and the variables that would override its login removed.
func IsPersonal ¶
IsPersonal reports whether slug names the default profile. Empty does too: it is what every session row born before profiles carries.
func MoveConversation ¶
MoveConversation moves a Codex conversation from the profile that holds it to another: its rollout, and the images it generated (generated_images/<id>). The target's own thread database learns the conversation from the rollout the next time Codex reads it (measured on 0.162.1: a rollout alone in an empty home was found by id and indexed there).
What stays behind is what is not keyed by the id: the prompt history (history.jsonl), and the source's thread database row: that database is Codex's, and lich leaves it alone.
func PersonalDir ¶
PersonalDir is the default profile's state directory: what Codex resolves from lich's own environment.
Types ¶
type BinResolver ¶
BinResolver supplies the Codex binary: the configured one, or "" for the default name on PATH. The store implements it.
type Info ¶
type Info = api.ProfileInfo
type LoginEvent ¶
type LoginEvent = api.ProfileLogin
type Plugin ¶
type Plugin = api.ProfilePlugin
type PluginResult ¶
type PluginResult = api.ProfilePluginResult
type Profile ¶
type Profile = profilestore.Profile
Profile is one Codex login lich knows about.
func ConfigDirs ¶
func ConfigDirs() []Profile
ConfigDirs is every profile, Personal first. Every reader of Codex's rollouts scans all of them: a conversation lives in exactly one, and which one is what says the profile it belongs to.
func Create ¶
Create makes a profile named name: its directory, laid out against Personal (layout.go), and its sidecar. It does not log in.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the window's door to the Codex profiles: listing them with their login state, creating, renaming and deleting them, logging one in, and porting plugins between them.
func New ¶
func New(bins BinResolver, emit func(name string, data any)) *Service
New returns a Service that runs the Codex binary bins resolves and reports a login's progress through emit.
func (*Service) CancelLogin ¶
CancelLogin answers cancelLogin over RPC.
func (*Service) CreateProfile ¶
CreateProfile makes a profile and lays it out against Personal. The window logs it in next (Login).
func (*Service) DeleteProfile ¶
DeleteProfile removes a profile and its login, and clears every setting that named it, so a project set to it falls back to the global profile. It refuses while a session runs in it. A parked session born in it fails to resume with ErrProfileGone.
func (*Service) InstallPlugins ¶
func (s *Service) InstallPlugins(_ context.Context, opts api.InstallPluginsOptions) ([]PluginResult, error)
InstallPlugins installs each plugin@marketplace into a profile through Codex's own `plugin add`, run as that profile so Codex writes its own paths. A marketplace the profile has not declared is declared as Personal declares it, its ref included, and fetched first. One result per key, in order; one failure does not stop the rest.
func (*Service) Login ¶
Login runs `codex login` as a profile. The CLI opens the browser itself and waits for the sign-in page's callback on localhost:1455; what it prints, the fallback address included, arrives as LoginEvent output. When the CLI exits, `codex login status` decides whether the login took. It returns once the CLI is started.
The callback port is fixed, so two logins cannot run at once, in lich or outside it: the second CLI says the port is taken, in its own words.
func (*Service) LoginCommand ¶
LoginCommand is the command line that logs a profile in from a terminal, for a user who would rather run it in a shell card than through Login.
func (*Service) Plugins ¶
Plugins lists the plugins a profile has installed, the ones a port can carry to another profile, in its config.toml's order. The lich plugin is not among them.
func (*Service) Profiles ¶
Profiles lists every profile with its login state. The statuses are asked for at once, one CLI each.
func (*Service) SetAccount ¶
SetAccount wires the question of whose login a profile holds and on which plan: the quota service's reading of the profile's own directory (quota.CodexProfilePlan), which asks upstream and is cached there. Startup wiring; without it a logged-in profile carries no account.
func (*Service) SetLichPlugin ¶
SetLichPlugin wires the lich plugin: install puts it into a profile and key is the plugin@marketplace it installs. Startup wiring.
func (*Service) SetSessions ¶
SetSessions wires the two questions a delete asks: how many live sessions run in a profile, and how to forget the settings that name it. Startup wiring.
func (*Service) UpdateProfile ¶ added in v0.75.0
UpdateProfile changes a profile's name, color or image and returns it; its directory never moves.