Documentation
¶
Overview ¶
Package appdir decides where magpie keeps its own files: the one place every other package asks (#508).
Installed, that is ~/.config/magpie ($XDG_CONFIG_HOME/magpie) for what magpie keeps and ~/.cache/magpie ($XDG_CACHE_HOME/magpie) for what it can fetch again, as it always was. Portable, when a folder named "data" (or a file named ".portable") sits beside magpie, everything magpie keeps goes into that data folder, its caches into data/cache and the Windows webview's profile into data/webview2 (no Start-menu shortcut or App Paths entry is made either), and nothing of magpie's own is written to the user's profile, the way VS Code's portable mode works. "Beside magpie" is the folder holding the executable, with links followed; for a Mac app it is the folder holding Magpie.app (a file put inside the bundle would break its signature), and for an AppImage the folder holding the .AppImage file, not the folder it is mounted at while it runs.
What isn't magpie's own stays where its owner reads it: the agents' configs (~/.claude, ~/.codex…), the sign-ins they keep in the system keychain, the folders the OS reads for autostart and link handling, and temporary folders.
A data folder in a folder every app or download shares (/Applications on a Mac; the home folder, Downloads, Desktop and Documents everywhere) is taken for magpie's own only when it already holds magpie's files and the installed folder doesn't, or with a ".portable" marker: a "data" folder there is as likely another app's or the user's own. Taking one showed a user who had never asked for portable an empty magpie (#989), and wrote magpie's files into a Downloads\data folder a Windows user's archiver empties, so a provider just added was gone (tangle778 on X). Where the system keeps Downloads, Desktop or Documents off home (moved to D:\ or OneDrive on Windows, ~/下载 on Linux) only a data folder holding none of magpie's files is passed over: before v0.1.2648 those folders weren't judged at all, so a data folder there holding magpie's files is one this user's magpie has been keeping its files in, and an update never moves them back to an installed folder from long ago (jwaitq on Discord).
The decision is made once, from the executable as it was when magpie started: an update moving the running copy aside (into .magpie-update on a Mac, to magpie.exe.old on Windows) leaves it running from somewhere else, and its files must not move with it.
Index ¶
- Constants
- Variables
- func AskMove(dir string) (string, error)
- func Beside(exe string) string
- func Blocked() string
- func Cache() string
- func CancelMove() error
- func CheckEnv() (ignored []string, err error)
- func ClaudeDir() string
- func ClaudeDirIn(home string) string
- func ClaudeHomes() []string
- func ClaudeHomesIn(home string) []string
- func CodexHome() string
- func CodexHomeIn(home string) string
- func CodexHomes() []string
- func CodexHomesIn(home string) []string
- func Config() string
- func DirStat(path string) (mod time.Time, size int64, dir bool, err error)
- func Downloads() string
- func Getenv(name string) string
- func Gone(dir string) error
- func HermesDefaultIn(home string) string
- func HermesHome() string
- func HermesHomeIn(home string) string
- func Home() (string, error)
- func Join(dir, name string) string
- func JoinFile(dir, name, ext string) string
- func Launcher() string
- func Logs() string
- func LookupEnv(name string) (string, bool)
- func Mine(p string) bool
- func MiniMaxDir() string
- func MiniMaxDirIn(home string) string
- func Move(root string) error
- func MoveAsked() bool
- func MovePending() (bool, error)
- func Own(p string) bool
- func Passed(exe string) string
- func Portable() string
- func Redirected() string
- func Resolve(exe string) string
- func SystemCache() (string, error)
- func T3Code(home string) string
- func Target(dir string) (string, error)
- func Unreachable() error
- func UseExecutable(exe string)
- func UserFolder(kind string) string
- func WebView() string
- func ZCodeDataIn(home string) string
- func ZCodeHome(home string) string
- func ZCodeHomeOn(goos, home string) string
- type GoneError
- type HeldError
- type Holder
- type Place
- type Proc
- type UnreachableError
Constants ¶
const ( // DataName is the folder beside magpie that makes it portable and // holds its files. DataName = "data" // MarkerName is a file beside magpie that makes it portable too, its // files then going into a data folder made beside it. MarkerName = ".portable" )
const ( DownloadsFolder = "Downloads" DesktopFolder = "Desktop" DocumentsFolder = "Documents" )
A user folder: Downloads, Desktop or Documents, as the system keeps it.
const MoveName = "magpie"
MoveName is the folder made in the one the user picks: config and cache go into it.
const WebViewNote = "webview-profile"
WebViewNote is the file beside an installed Windows magpie naming the webview profile it keeps, the one it had where it was downloaded.
Variables ¶
var HeldBy func() ([]Proc, error)
HeldBy lists every running process, where a folder can't be renamed while one has a file in it open (Windows); nil elsewhere, where a rename never waits on them. The cli sets it (appdir can't import proc).
Functions ¶
func AskMove ¶
AskMove has magpie's folders moved into the folder named "magpie" in dir, or home for "", when magpie next starts. It checks the folder now, so the user hears what is wrong with it before magpie quits.
func Beside ¶
Beside is the folder a portable magpie run from exe keeps its data folder in: the executable's own, the one holding the .app on a Mac, the one holding the .AppImage on Linux. APPIMAGE counts only for the AppImage magpie runs from (exe under its mount, APPDIR): every program an AppImage starts inherits both, a magpie started from an AppImage terminal too.
func Blocked ¶ added in v0.1.2068
func Blocked() string
Blocked is the folder that keeps magpie from writing its own files, or "" when it can: magpie's config or cache folder that this user can't write, or, while one of them isn't there yet, the folder it would be made in. A ~/.config that a command run under sudo made belongs to root, so magpie couldn't make ~/.config/magpie and every save failed with "permission denied" (YouWhat on Discord). Only a folder inside the home folder is named: one outside it (an XDG_CONFIG_HOME on a shared disk) isn't the user's to take back.
func Cache ¶
func Cache() string
Cache is the folder for what magpie can fetch again (the models.dev catalog, exchange rates, market lists).
func CheckEnv ¶ added in v0.1.874
CheckEnv is what main checks before anything is read or written: an unusable home folder is the error, and ignored names the folder variables holding a relative path, which LookupEnv passes over.
func ClaudeDir ¶ added in v0.1.1178
func ClaudeDir() string
ClaudeDir is the folder Claude Code keeps its files in: settings.json, the credentials it keeps off a keychain, history, sessions, skills. It is $CLAUDE_CONFIG_DIR when that is set, as Claude Code reads it, else ~/.claude. Every place magpie reads or writes Claude Code's files goes through here: the Agents page's wiring once wrote ~/.claude/settings.json and looked for ~/.claude alone while the sessions, the library and the sign-in read $CLAUDE_CONFIG_DIR, so a Claude Code kept there wasn't listed and a model picked for it went to a file it never read (#1482). It is read through LookupEnv, so the value a login shell lends the desktop app (proc.UserPath) counts, and a relative one reads as unset.
func ClaudeDirIn ¶ added in v0.1.1178
ClaudeDirIn is ClaudeDir with home as the user's home folder.
func ClaudeHomes ¶
func ClaudeHomes() []string
ClaudeHomes are every Claude Code folder of the user's, ClaudeDir first. More than one Claude account is Claude Code run with CLAUDE_CONFIG_DIR set to a folder of each's (~/.claude-work beside ~/.claude), a session is written into the folder of the account it ran under, and magpie read only the one it runs with (@fivesmallq on X: sessions and token use counted one Claude folder). Nothing records those folders, so they are looked for as CodexHomes looks for Codex's: in the home folder, and beside ClaudeDir, a folder whose name starts with "claude" or ".claude", or one folder down in such a folder (~/.claude-profiles/work), that holds projects/; and the folders magpie runs a saved account's Claude Code in (claude-accounts).
func ClaudeHomesIn ¶
ClaudeHomesIn is ClaudeHomes with home as the user's home folder.
func CodexHome ¶ added in v0.1.1166
func CodexHome() string
CodexHome is the folder Codex CLI keeps its files in: config.toml, auth.json, the model catalog magpie writes, sessions, AGENTS.md and skills. It is $CODEX_HOME when that is set, as codex-rs's find_codex_home reads it, else ~/.codex. Every place magpie reads or writes Codex's files goes through here (Wakkana on Discord: with CODEX_HOME set, a model picked in magpie went to ~/.codex/config.toml, which Codex never read). CODEX_HOME is read through LookupEnv, so the value a login shell lends the desktop app (proc.UserPath) counts, and a relative one, which Codex would take from whatever folder it runs in, reads as unset.
func CodexHomeIn ¶ added in v0.1.1166
CodexHomeIn is CodexHome with home as the user's home folder.
func CodexHomes ¶ added in v0.1.1468
func CodexHomes() []string
CodexHomes are every Codex folder of the user's on this computer: CodexHome first, then the others. Codex keeps one ChatGPT sign-in a folder (codex-rs login/src/auth/storage.rs: auth.json, or the keychain item named by the folder, under CODEX_HOME) and writes its sessions there too (rollout/src/lib.rs: sessions/, archived_sessions/), and `--profile <name>` only lays $CODEX_HOME/<name>.config.toml over config.toml (config/src/loader/mod.rs), the sign-in shared. So more than one account is Codex run with CODEX_HOME set to a folder of each's, ~/.codex-work beside ~/.codex, and magpie read only the one it runs with (phantom3792 on X: only the default profile's sessions counted, and the others' accounts read no quota).
Nothing records those folders, so they are looked for where they are made: in the home folder, and beside CodexHome, a folder whose name starts with "codex" or ".codex", or one folder down in such a folder (~/.codex-profiles/work), that holds auth.json or sessions/.
func CodexHomesIn ¶ added in v0.1.1468
CodexHomesIn is CodexHomes with home as the user's home folder.
func Config ¶
func Config() string
Config is the folder magpie keeps its settings, providers, usage and the rest of its own state in.
func DirStat ¶
DirStat is os.Stat's mod time, size and whether path is a folder, read into a Stat_t on the stack: os.Stat made a FileInfo of each of the few hundred folders a Sessions poll looks at, ~4.5 MB of garbage per 40 polls on a real history (#2278). Its errors are the errno, which errors.Is matches to fs.ErrNotExist as os.Stat's are.
func Downloads ¶ added in v0.1.2648
func Downloads() string
Downloads is UserFolder(DownloadsFolder).
func Gone ¶ added in v0.1.2469
Gone is a GoneError when dir, about to be made, is the folder an agent's variable names, or in it, and neither that folder nor the one it sits in exists; nil otherwise. The named folder itself is made when its parent is there, as mkdir would (a CODEX_HOME set before the agent first ran), but not a tree of missing folders above it: that is a folder, or a whole drive's data, the user deleted or moved (F:\piData for bm_rabbit). An agent's default folder (~/.pi/agent, ~/.codex) is made as before.
func HermesDefaultIn ¶ added in v0.1.1214
HermesDefaultIn is Hermes's own default home on this machine, whatever HERMES_HOME says (hermes_constants._get_platform_default_hermes_home): the root a HERMES_HOME under it is a profile of.
func HermesHome ¶ added in v0.1.1214
func HermesHome() string
HermesHome is the folder Hermes Agent (Nous Research) keeps its files in: config.yaml, .env, plugins, skills, profiles and state.db. It is $HERMES_HOME when that is set, else the platform's default, as hermes_constants.get_hermes_home reads them: %LOCALAPPDATA%\hermes on Windows (AppData\Local\hermes under the home folder without LOCALAPPDATA), ~/.hermes everywhere else. Every place magpie reads or writes Hermes's files goes through here (新v学员 on Discord: on native Windows Hermes and rtk's hook were in %LOCALAPPDATA%\hermes, and magpie looked for them in ~/.hermes).
func HermesHomeIn ¶ added in v0.1.1214
HermesHomeIn is HermesHome with home as the user's home folder.
func Home ¶ added in v0.1.874
Home is the user's home folder, or an error when its variable is unset, empty or relative. os.UserHomeDir hands back "" there, which filepath.Join turns into a path under the folder magpie was started in, and on Android it falls back to the shared /sdcard.
func Join ¶ added in v0.1.2458
Join is filepath.Join(dir, name), made once for each pair and kept while the folders it is asked for stay the same.
func JoinFile ¶ added in v0.1.2458
JoinFile is filepath.Join(dir, name+ext), made once for each, as Join: a provider's list is models/<id>.json.
func Launcher ¶
func Launcher() string
Launcher is the path a record the system keeps — the autostart entry, the desktop entry that opens magpie:// links, the service, a link on the PATH — should start this magpie by, when the running file is not that path; "" when it is.
A package's wrapper names itself in MAGPIE_EXECUTABLE: a Nix or Guix wrapper sets up GTK's environment and runs the real binary, so os.Executable is a file that can't start magpie by itself (#1747, HoronLee's file chooser aborting with "No GSettings schemas"). A path in a Nix or Guix store changes with every upgrade and is collected after, so it is mapped to the profile's link that leads to the same file: the one on the PATH, a profile's bin, or on a Mac its Applications.
func Logs ¶ added in v0.1.2342
func Logs() string
Logs is the folder the desktop app writes its log in, where each system keeps an app's logs: ~/Library/Logs/magpie on a Mac (beside the launch agent's serve.log, `magpie daemon install`), %LOCALAPPDATA%\magpie\logs on Windows, and $XDG_STATE_HOME/magpie (~/.local/state/magpie) elsewhere; portable, data/logs. A user asked for magpie's log finds it there (rayem1w on X: the app opened from the Finder had written none).
func LookupEnv ¶ added in v0.1.874
LookupEnv is os.LookupEnv for what magpie itself reads: a folder variable (pathVars) holding a relative path reads as unset, as the XDG spec asks of one, so no file of magpie's or an agent's is written under the working folder. The environment is left as it is: the programs magpie starts get the variable as the user set it. The variables a login shell lends the desktop app (proc.UserPath) are read through here too. On Windows an agent's variable is the registry's now, not the one magpie started with (follow.go).
func Mine ¶ added in v0.1.2068
Mine says whether this user owns p, so its mode can be put right without an administrator.
func MiniMaxDir ¶
func MiniMaxDir() string
MiniMaxDir is the data folder MiniMax Code keeps config.yaml, its sessions and its skills in. Every place magpie reads or writes MiniMax Code's files goes through here.
func MiniMaxDirIn ¶
MiniMaxDirIn is MiniMaxDir with home as the user's home folder. It is found as MiniMax Code 3.1.13 finds it (the desktop app's local-runtime/data-dir.js resolveLocalRuntimeDataDirSelection, and @mavis/config's config.js for the mcode runtime): $MINIMAX_DATA_DIR, else $MAVIS_DATA_DIR, else the desktop app's own setting — Settings' data folder, which moves the folder to <parent>/.minimax and keeps the parent as config.localRuntimeDataParentDir in its electron-store file — else ~/.minimax. YujunT46308 on X (MiniMax Code 3.1.13 CN): with the folder moved, magpie wrote ~/.minimax/config.yaml, which the app no longer read. A desktop file that is missing, can't be read or doesn't parse is the default folder, as electron-store reads one it can't parse as its defaults.
func Move ¶
Move moves magpie's folders into root (root/config and root/cache), or home for "", now. Nothing of magpie's may be running.
func MoveAsked ¶
func MoveAsked() bool
MoveAsked says whether a move is asked for, to be made at the next start.
func MovePending ¶
MovePending makes the move AskMove asked for, if one was. It is made once: the request is taken away first, so a move that fails, or a magpie that dies in it, isn't tried at every start. Why it failed is kept for Settings to say. The caller makes sure no other magpie is running.
func Own ¶ added in v0.1.2068
Own says whether p is magpie's own folder or inside it: its config or cache folder. A repair may take back everything in it; anything above it is changed only by itself.
func Passed ¶ added in v0.1.1080
Passed is the data folder beside a magpie run from exe that holds magpie's files but that Resolve doesn't take for its own, because it is in a shared folder while the installed folder has magpie's files too, or "". A data folder holding none of them is someone else's and isn't named.
func Portable ¶
func Portable() string
Portable is the data folder magpie keeps everything in, or "" when it isn't portable.
func Redirected ¶ added in v0.1.939
func Redirected() string
Redirected is the folder magpie keeps its files in when it is opened from the Dock, the Start menu or a desktop launcher (~/.config/magpie), while this magpie reads them from another that XDG_CONFIG_HOME, set in the shell it was run from, names; "" when they are the same, or magpie is portable. A magpie run in such a shell sees none of what the app's window shows.
func SystemCache ¶
SystemCache is the cache folder the OS names for magpie (~/Library/Caches/magpie on a Mac, %LocalAppData%\magpie on Windows), which a few caches have always used; portable, it is Cache.
func T3Code ¶
T3Code is T3 Code's folder (pingdotgg/t3code) for home: $T3CODE_HOME, a leading ~ being home, else ~/.t3 (resolveBaseDir in its server's os-jank.ts). Its settings, and each provider instance's profile, are in userdata in it.
func Target ¶
Target is the folder magpie's folders go into when the user picks dir, checked: an absolute folder that is there and can be written in, whose "magpie" folder is empty or not there yet (or is where they are now), and that is neither in magpie's folders nor holds them. "" is home.
func Unreachable ¶
func Unreachable() error
Unreachable is an UnreachableError when magpie's folder, or its cache, is a link to a folder that isn't there; nil otherwise. main stops on it before anything is read or written: magpie started on an empty folder in its place would look like a setup lost.
func UseExecutable ¶
func UseExecutable(exe string)
UseExecutable decides again as if magpie ran from exe ("" for an installed magpie, whatever runs): for tests.
func UserFolder ¶ added in v0.1.2648
UserFolder is where the system keeps the user's folder kind (Downloads, Desktop or Documents), which the user or the system may have moved off home\kind: Windows' known folder (FOLDERID_Downloads, which OneDrive or the folder's Location tab moves to another drive), the XDG user folder on Linux and the BSDs ($XDG_CONFIG_HOME/user-dirs.dirs, written in the user's language, ~/下载 on a Chinese desktop), and ~/kind on a Mac, where it can't be moved. A failed lookup is home\kind, as before; "" with no usable home folder.
func WebView ¶ added in v0.1.637
func WebView() string
WebView is the folder the Windows webview (WebView2) keeps its profile in — its cache, cookies and the pages' storage — or "" for its own default. Installed, that default is %APPDATA%\<exe name>, as it always was, so nothing kept there is lost; portable, it is data\webview2, so a portable magpie leaves no magpie.exe folder in the user's AppData (#508). A Windows magpie installed from a download under another name (update.Settle) keeps the profile it had there: the WebViewNote beside it names that folder.
func ZCodeDataIn ¶ added in v0.1.1225
ZCodeDataIn is the folder ZCode (Zhipu's desktop app) keeps its .zcode data in, with home as the user's home folder: the home folder, unless the user moved it in ZCode's settings (数据存储路径, "data storage path"). ZCode then copies its .zcode/v2 there and reads it from there from its next start, providers (provider_config.json, config.json) and sign-in (credentials.json) included; the choice stays in the home folder's .zcode/v2/setting.json as dataBaseDir, which ZCode's main process reads before anything else (readBootstrapDataBaseDirFromDisk). A value that isn't an absolute path is ignored, as Getenv ignores one.
Skills, AGENTS.md and the CLI's config.json stay under the home folder whatever this says: ZCode reads those from HOME/USERPROFILE.
func ZCodeHome ¶ added in v0.1.1318
ZCodeHome is the home folder ZCode (Zhipu's desktop app) reads, given home, the user's home as Go reads it (os.UserHomeDir). ZCode, a Node app, takes $HOME before os.homedir() on every OS: its data folder (getDataBaseDir: process.env.HOME?.trim() || homedir()), its settings (resolveUserHomeDir: HOME, then USERPROFILE) and the skills and MCP servers it reads. On a Mac or Linux that is Go's home too. On Windows Go's is USERPROFILE and HOME is mostly unset, but one the user set (for Git Bash, MSYS2 or Emacs) is where ZCode keeps everything, and magpie wrote its provider under USERPROFILE, where ZCode never looked (Gearclickist on Discord: connected, no error, and no magpie in ZCode).
func ZCodeHomeOn ¶ added in v0.1.1318
ZCodeHomeOn is ZCodeHome on goos, so a test can ask for Windows'. A HOME that isn't rooted is left out. Only the user's own home is moved: a folder that isn't USERPROFILE (a test's, a WSL distro's) is ZCode's as given.
Types ¶
type GoneError ¶ added in v0.1.2469
type GoneError struct {
Var, Dir string
}
GoneError is a folder an agent's variable names that isn't there, so what magpie writes into it isn't written: making it again would put the agent's config where the agent no longer looks, as Pi's models.json and settings.json went back into the AgentDir bm_rabbit had moved and deleted. The variable is fixed, or the folder made, by the user.
type HeldError ¶
HeldError is why magpie's folder can't move now: what has files in it open, or the system's refusal when none was found.
type Holder ¶
type Holder struct {
PID int
Name string // what it runs: its package, else its program
By string // the program that started it, "" when not known
Ours bool // it runs under this magpie, and ends with it
}
A Holder is a process whose command line names one of magpie's folders.
type Place ¶
type Place struct {
Config string `json:"config"` // where magpie reaches its files (~/.config/magpie)
Cache string `json:"cache"` // and its cache (~/.cache/magpie)
ConfigAt string `json:"configAt,omitempty"` // the folder Config links to, "" when it is no link
CacheAt string `json:"cacheAt,omitempty"`
// Moved is the folder they were moved into (Dir(ConfigAt)), "" when
// they are where magpie keeps them by default
Moved string `json:"moved,omitempty"`
Portable bool `json:"portable,omitempty"` // a portable magpie, never moved
// Pending is the folder a move asked for goes into at the next start,
// "home" for back to the default; "" when none is asked for
Pending string `json:"pending,omitempty"`
Error string `json:"error,omitempty"` // why the last move wasn't made
}
Place is where magpie's folders are.
type UnreachableError ¶
type UnreachableError struct {
Link, Target string
}
UnreachableError is one of magpie's folders moved to a folder that isn't there now: the disk it is on isn't connected.
func (*UnreachableError) Error ¶
func (e *UnreachableError) Error() string