Documentation
¶
Overview ¶
Package xdgprofile keeps more than one login of opencode, Cursor CLI and Kiro CLI on one machine, the way internal/claudeprofile does for Claude Code. None of the three has a variable of its own that moves its login: opencode keeps it in $XDG_DATA_HOME/opencode, Cursor CLI in $XDG_CONFIG_HOME/cursor (on Windows %APPDATA%\Cursor) and Kiro CLI in $XDG_DATA_HOME/kiro-cli/data.sqlite3, all measured (docs/ceilings.md). A profile is therefore a base directory of its own that the session's XDG_DATA_HOME, XDG_CONFIG_HOME or APPDATA points at, made of links to every entry of the real one but the provider's (profilestore's link home), so every other tool in the session (gh, git, mise) reads its own state where it always was.
Which of the three have profiles depends on the platform (Providers): on macOS Cursor CLI and Kiro CLI keep their logins in the Keychain, and on Windows Kiro CLI finds its data folder with no variable in the way.
Index ¶
- Constants
- Variables
- func CursorChat(stateDir, conversationID string) (string, bool)
- func IsPersonal(slug string) bool
- type BinResolver
- type Info
- type Profile
- type Provider
- func (p *Provider) ConfigDir(slug string) (string, error)
- func (p *Provider) Create(name string) (Profile, error)
- func (p *Provider) Delete(slug string) error
- func (p *Provider) EnsureShared(slug string) error
- func (p *Provider) Env(base []string, dir string) []string
- func (p *Provider) List() ([]Profile, error)
- func (p *Provider) MoveConversation(conversationID, toSlug string) error
- func (p *Provider) Owner(conversationID string, ...) (Profile, string, bool)
- func (p *Provider) Rename(slug, name string) error
- func (p *Provider) States() []State
- type Service
- func (s *Service) CreateProfile(name string) (Profile, error)
- func (s *Service) DeleteProfile(slug string) error
- func (s *Service) LoginCommand(slug string) (string, error)
- func (s *Service) Profiles() ([]Info, error)
- func (s *Service) RenameProfile(slug, name string) error
- func (s *Service) SetSessions(inUse func(slug string) int, forget func(slug string) error)
- type State
Constants ¶
const Personal = profilestore.Personal
Personal is the slug of the default profile.
Variables ¶
var Cursor = &Provider{ ID: providers.Cursor, store: profilestore.Spec{ Provider: providers.Cursor, Label: "Cursor CLI", HomeVar: cursorHomeVar, PersonalDir: cursorBase, Own: []string{cursorFolder}, Override: []string{cursorConfigDirVar, "CURSOR_API_KEY", "CURSOR_AUTH_TOKEN"}, Pinned: cursorPinned, }, folder: cursorFolder, personalState: func() (string, error) { home, err := os.UserHomeDir() if err != nil { return "", fmt.Errorf("resolve home directory: %w", err) } return providers.CursorConfigDir(home), nil }, status: cursorStatus, login: "login", }
Cursor is Cursor CLI's profiles. With XDG_CONFIG_HOME set and no CURSOR_CONFIG_DIR, the CLI keeps its login (auth.json), its config (cli-config.json, which names the account) and its chats in $XDG_CONFIG_HOME/cursor, so that folder is the profile's. On Windows the login is %APPDATA%\Cursor\auth.json and the config dir ~/.cursor, so there a profile moves APPDATA and pins CURSOR_CONFIG_DIR to that same folder (cursor_windows.go). Its mcp.json, hooks and skills hang off ~/.cursor whatever is set, and are every profile's. Dropped from a profile's spawn: CURSOR_CONFIG_DIR, which would put its chats back in Personal's, and the variables that stand in for a login.
var ErrNoMove = errors.New("this provider's conversations cannot move to another profile")
ErrNoMove is MoveConversation's answer for a provider whose conversations cannot change profile.
var ErrProfileGone = profilestore.ErrGone
ErrProfileGone is the error a spawn returns for a session born in a profile that was deleted since.
var Kiro = &Provider{ ID: providers.Kiro, store: profilestore.Spec{ Provider: providers.Kiro, Label: "Kiro CLI", HomeVar: dataHomeVar, PersonalDir: dataHome, Own: []string{ filepath.Join("kiro-cli", "data.sqlite3"), filepath.Join("kiro-cli", "data.sqlite3-wal"), filepath.Join("kiro-cli", "data.sqlite3-shm"), filepath.Join("kiro-cli", "data.sqlite3-journal"), filepath.Join("kiro-cli", ".refresh.lock"), }, Override: []string{"KIRO_API_KEY"}, }, folder: "kiro-cli", personalState: func() (string, error) { return under(dataHome, "kiro-cli") }, status: kiroStatus, login: "login", }
Kiro is Kiro CLI's profiles. Its `kiro-cli/` under the data home holds the TUI it runs (bun, node, tui.js, a few hundred MB) beside data.sqlite3, which holds the login with the CLI's history and state, so only the database (and the lock its token refresh takes) is the profile's and the rest is linked. Its conversations are under ~/.kiro, which no profile moves, so they are every profile's.
var OpenCode = &Provider{ ID: providers.OpenCode, store: profilestore.Spec{ Provider: providers.OpenCode, Label: "opencode", HomeVar: dataHomeVar, PersonalDir: dataHome, Own: []string{"opencode"}, Override: []string{"OPENCODE_DB", "OPENCODE_AUTH_CONTENT", "OPENCODE_CONSOLE_TOKEN", "OPENCODE_API_KEY"}, }, folder: "opencode", personalState: func() (string, error) { return under(dataHome, "opencode") }, status: opencodeStatus, login: "auth login", }
OpenCode is opencode's profiles. Its own folder, `opencode/` under the data home, holds the login (the `credential` and `account` tables of opencode.db, beside auth.json) together with every conversation, so the whole folder is the profile's, and a conversation cannot move between profiles. The config (`~/.config/opencode`, where lich's plugin is) is not under the data home and is every profile's. Dropped from a profile's spawn: the variables that hand opencode a database or a login of their own.
Functions ¶
func CursorChat ¶
CursorChat is the directory Cursor CLI keeps one chat in under a config dir: chats/<md5 of the cwd>/<id>/, found by its store.db.
func IsPersonal ¶
IsPersonal reports whether slug names the default profile. Empty does too.
Types ¶
type BinResolver ¶
BinResolver supplies the provider's binary: the configured one, or "" for the default name on PATH. The store implements it.
type Info ¶
type Info struct {
Profile
LoggedIn bool `json:"loggedIn"`
Email string `json:"email,omitempty"`
// StatusError is why the status call gave no answer, in its own words;
// LoggedIn is then false for want of one.
StatusError string `json:"statusError,omitempty"`
}
Info is a profile as the Settings screen shows it.
type Profile ¶
type Profile = profilestore.Profile
Profile is one login lich knows about. Its Dir is the profile's base directory, the link home; Personal's is the real one.
type Provider ¶
type Provider struct {
// ID is the provider's id (providers.OpenCode).
ID string
// contains filtered or unexported fields
}
Provider is one provider whose profiles are link homes.
func Providers ¶
func Providers() []*Provider
Providers is every provider with link-home profiles on this platform.
func (*Provider) ConfigDir ¶
ConfigDir is a profile's base directory, Personal's included. A profile that does not exist answers ErrProfileGone.
func (*Provider) Create ¶
Create makes a profile named name, its link home laid out against Personal's base directory. It does not log in.
func (*Provider) Delete ¶
Delete removes a profile's link home and the login in it. The links go and what they point at stays.
func (*Provider) EnsureShared ¶
EnsureShared brings a profile's link home in step with Personal's base directory before a spawn into it.
func (*Provider) Env ¶
Env is base with the provider's XDG variable naming the link home dir and the variables that would override the profile's login removed.
func (*Provider) List ¶
List is every profile, Personal first and the rest in the order they were created.
func (*Provider) MoveConversation ¶
MoveConversation carries a conversation to the profile toSlug, and back by calling it again, so a session can continue in another account.
Cursor CLI resumes a chat only from the active config dir, so its chat directory moves. Kiro CLI keeps its conversations under ~/.kiro, which is every profile's, so there is nothing to move. opencode keeps a conversation in the database that holds the login, so it cannot move and this answers ErrNoMove.
func (*Provider) Owner ¶
func (p *Provider) Owner(conversationID string, locate func(stateDir, conversationID string) (string, bool)) (Profile, string, bool)
Owner is the profile holding a conversation and where locate found it under that profile's state directory.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the window's door to one provider's profiles: listing them with their logins, creating, renaming and deleting them, and the command that logs one in. Every login of the three is an interactive picker or a browser flow that prints what to do, so a login is only ever offered in a terminal card, as oh-my-pi's is.
func New ¶
func New(provider *Provider, bins BinResolver) *Service
New returns a Service for provider that runs the binary bins resolves.
func (*Service) CreateProfile ¶
CreateProfile makes a profile and lays its link home out. The window logs it in next, in a terminal card (LoginCommand).
func (*Service) DeleteProfile ¶
DeleteProfile removes a profile and its login, and clears every setting that named it. It refuses while a session runs in it.
func (*Service) LoginCommand ¶
LoginCommand is the command line that logs a profile in from a terminal.
func (*Service) Profiles ¶
Profiles lists every profile with its login. The statuses are asked for at once, one CLI each.
func (*Service) RenameProfile ¶
RenameProfile changes a profile's display name; its directory never moves.