appdir

package
v0.1.4315 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 16 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 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

View Source
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"
)
View Source
const (
	DownloadsFolder = "Downloads"
	DesktopFolder   = "Desktop"
	DocumentsFolder = "Documents"
)

A user folder: Downloads, Desktop or Documents, as the system keeps it.

View Source
const MoveName = "magpie"

MoveName is the folder made in the one the user picks: config and cache go into it.

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

This section is empty.

Functions

func AskMove

func AskMove(dir string) (string, error)

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

func Beside(exe string) string

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 CancelMove

func CancelMove() error

CancelMove forgets a move asked for.

func CheckEnv added in v0.1.874

func CheckEnv() (ignored []string, err error)

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

func ClaudeDirIn(home string) string

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

func ClaudeHomesIn(home string) []string

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

func CodexHomeIn(home string) string

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

func CodexHomesIn(home string) []string

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

func DirStat(path string) (mod time.Time, size int64, dir bool, err error)

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 Getenv added in v0.1.874

func Getenv(name string) string

Getenv is LookupEnv's value, "" for a variable unset or ignored.

func Gone added in v0.1.2469

func Gone(dir string) error

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

func HermesDefaultIn(home string) string

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

func HermesHomeIn(home string) string

HermesHomeIn is HermesHome with home as the user's home folder.

func Home added in v0.1.874

func Home() (string, error)

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

func Join(dir, name string) string

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

func JoinFile(dir, name, ext string) string

JoinFile is filepath.Join(dir, name+ext), made once for each, as Join: a provider's list is models/<id>.json.

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

func LookupEnv(name string) (string, bool)

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

func Mine(p string) bool

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

func MiniMaxDirIn(home string) string

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

func Move(root string) error

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

func MovePending() (bool, error)

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

func Own(p string) bool

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

func Passed(exe string) string

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 Resolve

func Resolve(exe string) string

Resolve is the data folder of a magpie run from exe, or "" when it isn't portable.

func SystemCache

func SystemCache() (string, error)

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 Target

func Target(dir string) (string, error)

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

func UserFolder(kind string) string

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

func ZCodeDataIn(home string) string

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

func ZCodeHome(home string) string

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

func ZCodeHomeOn(goos, home string) string

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.

func (*GoneError) Error added in v0.1.2469

func (e *GoneError) Error() string

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.

func Where

func Where() Place

Where says 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

Jump to

Keyboard shortcuts

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