xdgprofile

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: 18 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 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/providers/, Profiles). 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

View Source
const Personal = profilestore.Personal

Personal is the slug of the default profile.

Variables

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

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

View Source
var ErrProfileGone = profilestore.ErrGone

ErrProfileGone is the error a spawn returns for a session born in a profile that was deleted since.

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

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

func CursorChat(stateDir, conversationID string) (string, bool)

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

func IsPersonal(slug string) bool

IsPersonal reports whether slug names the default profile. Empty does too.

Types

type BinResolver

type BinResolver interface {
	ProviderBin(providerID, projectID string) string
}

BinResolver supplies the provider's binary: the configured one, or "" for the default name on PATH. The store implements it.

type Info

type Info = api.ProfileInfo

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 Of

func Of(id string) *Provider

Of is the provider with id, nil when it has no profiles here.

func Providers

func Providers() []*Provider

Providers is every provider with link-home profiles on this platform.

func (*Provider) ConfigDir

func (p *Provider) ConfigDir(slug string) (string, error)

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

func (*Provider) Create

func (p *Provider) Create(name string) (Profile, error)

Create makes a profile named name, its link home laid out against Personal's base directory. It does not log in.

func (*Provider) Delete

func (p *Provider) Delete(slug string) error

Delete removes a profile's link home and the login in it. The links go and what they point at stays.

func (*Provider) EnsureShared

func (p *Provider) EnsureShared(slug string) error

EnsureShared brings a profile's link home in step with Personal's base directory before a spawn into it.

func (*Provider) Env

func (p *Provider) Env(base []string, dir string) []string

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

func (p *Provider) List() ([]Profile, error)

List is every profile, Personal first and the rest in the order they were created.

func (*Provider) MoveConversation

func (p *Provider) MoveConversation(conversationID, toSlug string) error

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.

func (*Provider) States

func (p *Provider) States() []State

States is every profile with its state directory, Personal first. A reader of the provider's conversations scans all of them.

func (*Provider) Update added in v0.75.0

func (p *Provider) Update(slug string, u profilestore.Update) (Profile, error)

Update changes a profile's name, color or image. The slug and the directory stay.

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, emit func(name string, data any)) *Service

New returns a Service for provider that runs the binary bins resolves and reports a profile's update through emit.

func (*Service) CreateProfile

func (s *Service) CreateProfile(_ context.Context, opts api.CreateProfileOptions) (Profile, error)

CreateProfile makes a profile and lays its link home out. The window logs it in next, in a terminal card (LoginCommand).

func (*Service) DeleteProfile

func (s *Service) DeleteProfile(_ context.Context, opts api.ProfileSlugOptions) (api.None, error)

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

func (s *Service) LoginCommand(_ context.Context, opts api.ProfileSlugOptions) (string, error)

LoginCommand is the command line that logs a profile in from a terminal.

func (*Service) Profiles

func (s *Service) Profiles(_ context.Context, _ api.None) ([]Info, error)

Profiles lists every profile with its login. The statuses are asked for at once, one CLI each.

func (*Service) SetSessions

func (s *Service) SetSessions(inUse func(slug string) int, forget func(slug string) error)

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

func (s *Service) UpdateProfile(_ context.Context, opts api.UpdateProfileOptions) (Profile, error)

UpdateProfile changes a profile's name, color or image and returns it; its directory never moves.

type State

type State struct {
	Profile
	Dir string
}

State is a profile with the directory its provider keeps conversations in.

Jump to

Keyboard shortcuts

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