profilestore

package
v0.94.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: AGPL-3.0 Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

View Source
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.

View Source
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 CopyFile added in v0.81.0

func CopyFile(src, dst string) error

CopyFile copies src to dst, which it creates and never overwrites.

func CrossDevice added in v0.81.0

func CrossDevice(err error) bool

CrossDevice reports a rename refused for crossing filesystems.

func IsLink(path string) bool

IsLink reports whether path is a link this package made.

func IsPersonal

func IsPersonal(slug string) bool

IsPersonal reports whether slug names the default profile. Empty does too: it is what every session row born before profiles carries.

func LinkDir

func LinkDir(target, path string) error

LinkDir links path to the directory target.

func WriteFileAtomic

func WriteFileAtomic(path string, data []byte, perm os.FileMode) error

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 Changed added in v0.75.0

type Changed = api.ProfileChanged

type Pair

type Pair struct {
	From, To string
	Replaces bool
}

Pair is one entry of a conversation moving between profiles: where it is and where it goes. Replaces marks an entry a process outside the provider's own may file again after the conversation left, such as an async hook that outlives it: a copy of it in the target is that leftover, and the move replaces it instead of refusing.

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 = api.Profile

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)
	// SharedFiles and Shared are the user's own content, linked from every
	// profile to Personal so an edit made under one account is there under all
	// of them: files, which Windows can only link with Developer Mode and
	// otherwise copies, and directories. Only entries Personal has are linked;
	// EnsureShared links one created later.
	SharedFiles, Shared []string
	// Own, when set, makes the profile directory a link home (linkhome.go):
	// a mirror of Personal's directory in which every entry is a link except
	// these paths, relative to it, which are the profile's own. SharedFiles and
	// Shared are then unused: everything else is shared.
	Own []string
	// Downloads are directories Personal keeps its plugin downloads in, created
	// there when absent and linked, so a profile does not fetch them again.
	Downloads []string
	// PersonalPath is where Personal keeps a linked entry, given its state
	// directory and the entry's path relative to a profile's. Nil is the same
	// relative path under Personal's: it differs only where the provider reads a
	// variable that moves part of its state elsewhere.
	PersonalPath func(personal, name string) string
	// Override are the variables, besides HomeVar, that would override a
	// profile's own login: a spawn into a profile drops them, or the account in
	// its directory is never the one spent.
	Override []string
	// Pinned are variables besides HomeVar that a spawn into a profile sets,
	// each to a path under the profile's directory: state HomeVar alone does
	// not move (Cursor CLI's config dir on Windows). Only for a provider whose
	// HomeVar value is that directory.
	Pinned []PinnedVar
	// Reserved are slugs a profile cannot take because the provider reads them
	// as something else ("default" selects oh-my-pi's default profile).
	Reserved []string
	// Seed runs once a profile is linked, for what is not a link: Claude Code's
	// global config and plugin state are files of their own.
	Seed func(personal, dir string) error
	// Sync runs after Seed and again before every spawn into the profile
	// (EnsureShared), for a file the profile holds as its own but rebuilds from
	// Personal's: Codex's config.toml, whose plugin set is the profile's.
	Sync func(personal, dir 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

func (s Spec) All() []Profile

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

func (s Spec) ConfigDir(slug string) (string, error)

ConfigDir is a profile's state directory, Personal's included. A profile that does not exist answers ErrGone.

func (Spec) Create

func (s Spec) Create(name string) (Profile, error)

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

func (s Spec) Delete(slug string) error

Delete removes a profile's directory and its login with it. Personal cannot be deleted.

func (Spec) Dir

func (s Spec) Dir(slug string) (string, error)

Dir is the state directory of a profile lich created. It does not check that the profile exists; ConfigDir does.

func (Spec) EnsureShared

func (s Spec) EnsureShared(slug string) error

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

func (s Spec) Env(base []string, value string) []string

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

func (s Spec) List() ([]Profile, error)

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

func (s Spec) LoginLine(bin, args, value string) string

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, but for one that Replaces.

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.

func (Spec) Root

func (s Spec) Root() (string, error)

Root is where lich keeps a provider's profile sidecars. A `task dev` rig gets its own, the split the workspace database makes, so a dev build never deletes a real account.

func (Spec) Unset

func (s Spec) Unset() []string

Unset is every variable a spawn into a profile drops, HomeVar last.

func (Spec) Update added in v0.75.0

func (s Spec) Update(slug string, u Update) (Profile, error)

Update applies u to a profile, Personal's included, and returns it as List shows it. A file that is not an image fails it before anything is written.

type Update added in v0.75.0

type Update = api.ProfileUpdate

Jump to

Keyboard shortcuts

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