Documentation
¶
Overview ¶
Package profilestore keeps more than one login of a provider on one machine. A profile is a state directory of its own holding its own login, so every account runs with its full login rather than an inference-only token. The providers that have profiles (internal/claudeprofile, internal/codexprofile, internal/ompprofile, internal/xdgprofile) describe themselves with a Spec; this package is the rest: the slug and the sidecar a profile is listed from, the layout of its directory against the default profile (Personal), and the move of a conversation between two of them.
A profile directory is never moved once it exists, and renaming a profile changes its display name only: the slug names the directory, and a provider may key a login on the directory string (Claude Code's macOS Keychain entry and Codex's keyring store do).
Index ¶
- Constants
- Variables
- func IsLink(path string) bool
- func IsPersonal(slug string) bool
- func LinkDir(target, path string) error
- func WriteFileAtomic(path string, data []byte, perm os.FileMode) error
- type Pair
- type PinnedVar
- type Profile
- type Spec
- func (s Spec) All() []Profile
- func (s Spec) ConfigDir(slug string) (string, error)
- func (s Spec) Create(name string) (Profile, error)
- func (s Spec) Delete(slug string) error
- func (s Spec) Dir(slug string) (string, error)
- func (s Spec) EnsureShared(slug string) error
- func (s Spec) Env(base []string, value string) []string
- func (s Spec) List() ([]Profile, error)
- func (s Spec) LoginLine(bin, args, value string) string
- func (s Spec) MoveConversation(conversationID, toSlug string, ...) error
- func (s Spec) Owner(conversationID string, locate func(dir, conversationID string) (string, bool)) (Profile, string, bool)
- func (s Spec) Rename(slug, name string) error
- func (s Spec) Root() (string, error)
- func (s Spec) Unset() []string
Constants ¶
const Personal = "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 ErrGone = errors.New("profile no longer exists")
ErrGone 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.
var ErrNoConversation = errors.New("conversation not found in any profile")
ErrNoConversation is MoveConversation finding the conversation in no profile: a session that has its id but has not written a transcript yet.
Functions ¶
func IsPersonal ¶
IsPersonal reports whether slug names the default profile. Empty does too: it is what every session row born before profiles carries.
func WriteFileAtomic ¶
WriteFileAtomic writes data to path through a temporary file and a rename, so a reader never sees it half written. Each call has a temporary file of its own: two spawns into one profile write the same files at once.
Types ¶
type Pair ¶
type Pair struct{ From, To string }
Pair is one entry of a conversation moving between profiles: where it is and where it goes.
type PinnedVar ¶
type PinnedVar struct{ Name, Rel string }
PinnedVar is one of Spec.Pinned: Name set to Rel under the profile's directory.
type Profile ¶
type Profile struct {
Slug string `json:"slug"`
Name string `json:"name"`
Dir string `json:"dir"`
Personal bool `json:"personal"`
// Copied names the shared entries (a settings file, say) this profile holds
// as a copy, so edits made in one account no longer reach the other.
Copied []string `json:"copied,omitempty"`
}
Profile is one login lich knows about.
type Spec ¶
type Spec struct {
// Provider names the provider in messages and is the subdirectory of lich's
// profiles root its sidecars live in ("claude").
Provider string
// Label is the provider as a person calls it ("Claude Code").
Label string
// HomeVar is the environment variable the provider reads its state from.
HomeVar string
// PersonalDir is the default profile's state directory: what the provider
// resolves from lich's own environment.
PersonalDir func() (string, error)
// DirOf is where a profile's state directory is. Nil puts it beside its
// sidecar, under lich's profiles root. It is given a slug that already
// matched slugPattern.
DirOf func(slug string) (string, error)
Spec is what differs between providers. Everything else about a profile is the same, so a Spec is a value rather than an interface.
func (Spec) All ¶
All is every profile with its state directory, Personal first. Every reader of a provider's transcripts scans all of them: a conversation lives in exactly one, and which one is what says the profile it belongs to.
func (Spec) ConfigDir ¶
ConfigDir is a profile's state directory, Personal's included. A profile that does not exist answers ErrGone.
func (Spec) Create ¶
Create makes a profile named name: its directory, laid out against Personal, and its sidecar, written last so a half-built directory is never listed. It does not log in.
func (Spec) Delete ¶
Delete removes a profile's directory and its login with it. Personal cannot be deleted.
func (Spec) Dir ¶
Dir is the state directory of a profile lich created. It does not check that the profile exists; ConfigDir does.
func (Spec) EnsureShared ¶
EnsureShared links into a profile the shared entries Personal gained since the profile was made (a CLAUDE.md written after it, say), records any it had to copy and runs Sync. It runs before every spawn into the profile, so an entry appears on the next session. Personal needs nothing.
func (Spec) Env ¶
Env is base with HomeVar set to value and the variables that would override the profile's login removed. What value is depends on the provider: the directory itself, or the profile's name.
func (Spec) List ¶
List is every profile, Personal first and the rest in the order they were created. A sidecar that does not parse is skipped rather than failing the list: one broken profile must not hide the others.
func (Spec) LoginLine ¶
LoginLine is the POSIX shell line that runs `bin args` as a profile: the variables that would override its login unset and HomeVar (and Pinned) exported as value, or the bare command for Personal (value empty).
func (Spec) MoveConversation ¶
func (s Spec) MoveConversation( conversationID, toSlug string, locate func(dir, conversationID string) (string, bool), entries func(conversationID, transcript, fromDir, toDir string) ([]Pair, error), ) error
MoveConversation moves a conversation from the profile that holds it to toSlug, and back by calling it again. locate finds its transcript under one state directory; entries lists everything the provider keyed by the conversation's id, given that transcript and the two directories. The move refuses a target that already holds any entry.
A failure part way moves back whatever had already moved, so the conversation is never split across two profiles.
func (Spec) Owner ¶
func (s Spec) Owner(conversationID string, locate func(dir, conversationID string) (string, bool)) (Profile, string, bool)
Owner is the profile holding a conversation, and the path of its transcript there. locate finds the transcript under one state directory. A conversation id is unique to its provider and lives in exactly one profile, so the first match is the only one.