home

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 39 Imported by: 1 module, 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

Resolves the icebath home directory, its named profiles and the files inside them

Index

Constants

View Source
const (
	OpenRouterBaseURL   = "https://openrouter.ai/api/v1"
	OpenRouterModelsURL = OpenRouterBaseURL + "/models"
	AIGatewayBaseURL    = "https://ai-gateway.vercel.sh/v1"
)
View Source
const (
	FileAttributeDirectory    = 0x10
	FileAttributeReparsePoint = 0x400
)
View Source
const (
	// Env var holding the scratch dir icebath itself exported into the temp vars
	ScratchDirMarkerEnv = "ICEBATH_SCRATCH_DIR"
	// Hours without a write anywhere in a scratch entry before the prune removes it
	ScratchMaxIdleHours = 24
)
View Source
const (
	// Scratch file remembering entries this user cannot delete
	StuckStateName = ".prune_stuck.json"
	// Lock file serializing read merge write of the stuck state
	StuckLockName = StuckStateName + ".lock"
)
View Source
const AttachmentMaxBytes = 16 * 1024 * 1024

Size ceiling for an attachment staged on the host before the base64 read back

View Source
const DefaultIndicatorStyle = "unicode"
View Source
const DirName = dirName

DirName is the dot directory name of a default home

View Source
const EnvHome = "ICEBATH_HOME"

Environment variable naming the home directory of the running process

View Source
const EnvSuffix = "ICEBATH_DATA_DIR_SUFFIX"

Environment variable appending a suffix to the platform default directory name

View Source
const FinishReasonLength = "length"

Provider finish reason for an output length stop

View Source
const PartialStreamStubID = "partial-stream-stub"

Request id of the synthetic response a stream cut short by the length limit leaves behind

View Source
const ProfilesDir = "profiles"

Directory holding named profiles under the root home

View Source
const RecordKey = "icebath_home"

Key of the home directory in pid, lock, identity and runtime records

View Source
const ScratchPruneEntry = "__icebath_scratch_prune__"

Hidden first argument a main or TestMain routes to RunScratchPrune through DispatchScratchPruneEntry before any other parsing

View Source
const SocketTmpdirMaxLen = 50

Longest temp root that leaves room for Chrome and code kernel AF_UNIX socket names

Variables

View Source
var ConnectorDownloadsSubdir = filepath.Join("downloads", "connectors")

Where connector tool results save the files they return, under each profile home

View Source
var IndicatorStyles = []string{"ascii", "emoji", "unicode"}

Busy indicator styles the TUI accepts and the one it starts with

View Source
var LocalRuntimeRootDirs = map[string]bool{"models": true, "runtimes": true, "node": true}

Root directories of the default home that hold local models and runtimes

View Source
var OpenRouterVariantSuffixes = map[string]bool{"nitro": true, "floor": true, "exacto": true, "online": true}

OpenRouter request time routing suffixes valid on any model id and never separate catalog entries

View Source
var ProfileIDRe = regexp.MustCompile(`^[a-z0-9][a-z0-9_-]{0,63}$`)

Profile id grammar every profile directory gate shares

View Source
var ScratchTmpEnvVars = []string{"TMPDIR", "TMP", "TEMP"}

Temp vars pointed at the scratch dir for every icebath process and child

Functions

func AccountDefault

func AccountDefault(ctx context.Context) string

Default home of the OS account, the process platform default when the user home resolves to the account home

func AdoptRecordKey

func AdoptRecordKey(record *jsonutil.Object)

Moves the home of a record an older icebath wrote to the current key in place, so the next write carries it

func ApplyIPv4Preference

func ApplyIPv4Preference(force bool)

Makes the process resolve unspecified address families as IPv4 first, the network.force_ipv4 setting

func ApplyScratchTmpEnv

func ApplyScratchTmpEnv(ctx context.Context, env map[string]string) bool

Points TMPDIR, TMP and TEMP in env at the scratch dir of its ICEBATH_HOME unless the user set them

func ApplySecureDirPolicy

func ApplySecureDirPolicy(ctx context.Context, path, h string)

Owner only directory unless the home is managed, a container keeps its modes, or ICEBATH_HOME_MODE names one

func ApplySubprocessHomeEnv

func ApplySubprocessHomeEnv(ctx context.Context, env map[string]string)

Sets HOME and ICEBATH_REAL_HOME per the home mode and points the temp variables at the scratch dir

func AssertProfileLive

func AssertProfileLive(path string) error

Fails when path lies under a home this process erased or under a deleted or missing named profile

func AuthPath

func AuthPath(h string) string

OAuth credential store of a home

func BundlesDir

func BundlesDir(h string) string

Skill bundles directory of a home

func CacheDir

func CacheDir(h string) string

Cache directory of a home

func CandidateNodeCommandNames

func CandidateNodeCommandNames(command string) []string

File names a Node tool command may carry on this platform, the cmd shim first on Windows

func CaptureProfileFallbackWarning

func CaptureProfileFallbackWarning(w io.Writer) func()

Routes the profile fallback warning to w with its once latch rearmed, returning the function that restores both

func CaptureScratchPruneSpawns

func CaptureScratchPruneSpawns() (*[]string, func())

Records detached prune launches instead of starting them with the once latch rearmed, returning the record and its restore

func ClearProfileDeleted

func ClearProfileDeleted(profileHome string) error

Unlinks the tombstone file of a profile, a missing one ignored and a directory in its place refused and kept

func ConfigPath

func ConfigPath(h string) string

Config file of a home

func ContainerOrChmodSkipped

func ContainerOrChmodSkipped() bool

Operator chmod skip or container signal that leaves directory modes to the deployment

func CronDir

func CronDir(h string) string

Cron directory of a home

func DetachAttr

func DetachAttr(breakaway bool) *syscall.SysProcAttr

DetachAttr is the detached child attribute set, a new session outside Windows

func Dir

func Dir(ctx context.Context) string

Home directory in effect, a context override winning over the process home

func DispatchScratchPruneEntry

func DispatchScratchPruneEntry(ctx context.Context)

Runs the prune and exits when argv carries the entry, otherwise records that this binary handles it

func Display

func Display(path string) string

Path relative to the user home as a tilde posix path, the path itself when outside the user home or when no user home is known

func EnsureScratchDir

func EnsureScratchDir(ctx context.Context, h string) string

Creates and secures the scratch dir of h or the active home and starts its hourly detached prune

func EnvPath

func EnvPath(h string) string

Secrets file of a home

func ExportScratchTmpEnv

func ExportScratchTmpEnv(ctx context.Context) bool

Boot hook pointing this process temp vars at its scratch dir, rerun after anything re-homes the process

func GrantUserAccess

func GrantUserAccess(ctx context.Context, path string, elevated, repairChildren bool) bool

Gives the user an inheriting full control ACE on path when elevated, true when the grant took

func IcebathDir

func IcebathDir(h, newSubpath, oldName string) string

Home subdirectory, a populated legacy directory winning over the new subpath

func InstallRoot

func InstallRoot() string

Directory of the resolved running binary, the install tree secure parent hardening never chmods

func IsReparsePoint

func IsReparsePoint(path string) bool

True when path itself is a symlink, junction or other reparse point, or cannot be lstat-ed

func IterTreeWithoutReparsePoints

func IterTreeWithoutReparsePoints(root string, skipped *[]string) iter.Seq2[string, bool]

Yields root and everything under it, never entering or yielding a link, which lands in skipped

func Key

func Key(path string) string

Stable key of a home directory, the resolved path, cached once the directory exists; a leading ~ whose home is unknown is kept as written, and a path that cannot be resolved is keyed as it is spelled

func LineageWithStartTimes

func LineageWithStartTimes() ([]lineageEntry, bool)

This process and its ancestors with start stamps, false when any link cannot be read

func ListProfiles

func ListProfiles(root string) []string

Names of every live named profile under root, sorted

func LoadStuckSkips

func LoadStuckSkips(root string, persist bool) (map[string]bool, error)

Names to skip this pass, dropping records that no longer hold and persisting that unless persist is false

func LocalesDir

func LocalesDir(h string) string

Locales directory of a home

func LogsDir

func LogsDir(h string) string

Logs directory of a home

func MakeUserDir

func MakeUserDir(ctx context.Context, path string, mode os.FileMode, parents, existOK bool) (string, error)

pathlib mkdir that keeps a directory an elevated Windows process creates usable by the same user unelevated

func ManagedNodeTreePresent

func ManagedNodeTreePresent(ctx context.Context, h string) bool

Reports whether a legacy managed Node tree with node, npm or npx sits in the home

func ManagedSystem

func ManagedSystem(ctx context.Context, h string) string

Package manager owning the install from ICEBATH_MANAGED or the home marker, empty when unmanaged

func MarkHomeErased

func MarkHomeErased(h string)

Records that this process erased the home h, refusing every later directory it would create under h

func MarkProfileDeleted

func MarkProfileDeleted(profileHome string) error

Writes the tombstone of a profile, its directory and missing parents created first

func MemoriesDir

func MemoriesDir(h string) string

Memory directory of a home

func Mkdir

func Mkdir(ctx context.Context, path string) (string, error)

Creates path and its parents through MakeUserDir, refusing to materialize a dead profile

func NamedProfileHome

func NamedProfileHome(path string) string

Profile home that path is or passes through on its way down, dot-dot elements kept as steps through the directory before them, empty when path is not a named profile

func NodeDirs

func NodeDirs(ctx context.Context, h string) []string

Historical managed Node directories of a home, bin first on POSIX and the node dir first on Windows

func NormHomePath

func NormHomePath(path string) string

Comparable absolute and case normalized form of a home path, empty for blank input

func NormalizeScope

func NormalizeScope(scope string) string

Registry write scope key, empty staying empty for the process global layer and anything else keyed like Key

func OpenRouterVariantBase

func OpenRouterVariantBase(modelID string) string

Base model id when the id carries a routing variant suffix, empty otherwise

func OptionalSkillsDir

func OptionalSkillsDir(ctx context.Context, def string) string

Optional skills directory honoring package manager wrappers

func Override

func Override(ctx context.Context) string

Home override carried by ctx, empty when none was set

func PackagedDir

func PackagedDir(ctx context.Context, envVar, def, subdir string) string

Package manager relocatable directory from envVar, then def, then the subdir of the active home

func PatchPlatformDefault

func PatchPlatformDefault(dir string) (restore func())

Serves the platform default home under dir keeping its name, as test isolation does, returning the restore

func PatchUserHome

func PatchUserHome(dir string) (restore func())

Serves dir as the user home until the returned restore runs

func PathMkdir

func PathMkdir(p string, mode os.FileMode, parents, existOK bool) error

pathlib Path.mkdir with its parents and exist_ok handling

func PendingDir

func PendingDir(h string) string

Pending approval directory of a home

func PinProcess

func PinProcess(path string, unpin bool)

Pins the home this process serves as its own profile for routed profile decisions, unpin clears it

func PlatformDefault

func PlatformDefault() string

Platform default home of the running process; without a user home there is no folder for the data, and it panics with the noDataHome error

func PluginDataDir

func PluginDataDir(h string) string

Plugin data directory of a home

func PluginsDir

func PluginsDir(h string) string

Plugins directory of a home

func Process

func Process() string

Home directory of the process from the environment variable or the platform default

func ProcessIsElevated

func ProcessIsElevated() bool

True for an elevated Windows process, false on every other host or on any probe error

func ProcessPinned

func ProcessPinned() bool

Reports whether a host pinned the process home

func ProfileCLISelector

func ProfileCLISelector(h string) string

Returns the -p name selector with a trailing space for a named profile home, empty for default or custom homes

func ProfileDeleted

func ProfileDeleted(profileHome string) bool

Reports whether the profile was deleted

func ProfileHasIdentity

func ProfileHasIdentity(profileHome string) bool

Reports whether a profile directory carries a file that identifies it as a profile

func ProfileHome

func ProfileHome(root, name string) string

Home directory of the named profile under the root, the root for default

func ProfileIdentityMarkers

func ProfileIdentityMarkers() []string

Files whose presence marks a directory as a real profile home, the identity markers

func ProfileLive

func ProfileLive(profileHome string) bool

Reports whether the profile exists, has identity and is not deleted

func ProfileNameFor

func ProfileNameFor(path string) string

Profile id owning path, default for the root home, empty when path is no home or starts with a ~ whose home is unknown

func PruneIdleEntries

func PruneIdleEntries(root string, maxIdleHours float64, skipNames map[string]bool, logFile string) (int, error)

Deletes entries of root idle for maxIdleHours after reaping processes and worktrees rooted in them, returns the count

func PruneScratchDir

func PruneScratchDir(ctx context.Context, scratch string, maxIdleHours float64) (int, error)

Removes scratch entries idle for maxIdleHours after reaping what runs in them, logging to logs/scratch-prune.log

func RealHome

func RealHome(ctx context.Context, env map[string]string) string

The OS user's real home, never the profile home, the temp root when no candidate fits

func RecordValue

func RecordValue(lookup func(string) (any, bool), key string) (any, bool)

Value of a home record key, the older spelling read from a record written before the rename

func ReleaseGitWorktrees

func ReleaseGitWorktrees(repos map[string]bool)

Runs git worktree prune in each repo so registrations of deleted trees are dropped

func RemovalHint

func RemovalHint(entry string) string

Command that clears entry, with a sudo free docker variant when docker is installed

func RepairWindowsHomeACL

func RepairWindowsHomeACL(ctx context.Context, elevated *bool) error

Grants the user back the home tree an elevated update left Administrators only, an error when nothing took

func ResetKeyCache

func ResetKeyCache()

Forgets every cached home key

func ResetScratchPruneLatch

func ResetScratchPruneLatch()

Rearms the once per process prune latch the way a fresh process starts

func RetiredRecordKey

func RetiredRecordKey(key string) string

Same record key in the spelling records of an older icebath carry

func Root

func Root() string

Root home that owns the profile tree, derived from the process home; panics with the noDataHome error when no user home is known

func RootForEnvironment

func RootForEnvironment(environ map[string]string) string

Root another process started with environ resolves, empty when the answer depends on anything outside environ

func RootOf

func RootOf(home string) string

Root home that owns the given home

func RoutingProcess

func RoutingProcess() string

Launch home for routed profile decisions, the expanded pinned home else the process home

func RunScratchPrune

func RunScratchPrune(ctx context.Context, args []string) int

Detached child entry running one prune of the scratch dir while sparing the launcher ancestry

func ScratchDir

func ScratchDir(h string) string

Scratch directory a home hands to child processes as their temp dir

func ScratchDirUsageBytes

func ScratchDirUsageBytes(ctx context.Context, scratch string) int64

Total lstat bytes of every non directory os.walk lists under the scratch dir, zero when unreadable

func ScratchDirWithoutPrune

func ScratchDirWithoutPrune(ctx context.Context, h string) string

Scratch dir of h, created and permissioned with no prune handed to a child

func SecureParentDir

func SecureParentDir(path string)

Restricts the resolved parent of path to 0700, never the root, a top level dir or the install tree; a parent that cannot be resolved is left as it is with a warning

func SessionsDir

func SessionsDir(h string) string

Sessions export directory of a home

func SetWSLProbe

func SetWSLProbe(probe func() bool) (previous func() bool)

Replaces the WSL probe of the cwd translation and returns the probe it replaced

func SkillsDir

func SkillsDir(h string) string

Skills directory of a home

func SocketSafeTmpdir

func SocketSafeTmpdir() (string, error)

Temp root short enough for AF_UNIX sockets, the system root when the default one is too long

func SoulPath

func SoulPath(h string) string

Identity file of a home

func StatePath

func StatePath(h string) string

Session database of a home

func StuckEntries

func StuckEntries(root string) ([]string, error)

Entries the prune currently skips as not removable, for the doctor report

func SubprocessHome

func SubprocessHome(ctx context.Context, env map[string]string) string

HOME a subprocess gets under TERMINAL_HOME_MODE, empty when it keeps its own

func SubtreeTouchState

func SubtreeTouchState(path string, cutoff float64) string

Touched, scan-failed or idle for the subtree at path against cutoff, hardlinked files never counting as writes

func SudoInvokerDefaultHome

func SudoInvokerDefaultHome() string

Invoking user's native home when this process is root under sudo, empty otherwise

func TombstonePath

func TombstonePath(profileHome string) string

Tombstone file marking a profile as deleted

func TranslateCwdForWSLBackend

func TranslateCwdForWSLBackend(cwd string) string

A Windows host cwd mapped to POSIX when icebath runs inside WSL, unchanged elsewhere or when already POSIX

func UnusableDirRemedy

func UnusableDirRemedy(path string) string

One line repair for a directory this process may not use

func UserHome

func UserHome() (string, error)

Home directory of the current user, an error wrapping pathutil.ErrNoHome when none is known; the replacement lookup when a test installed one

func WSLUNCPathToPosix

func WSLUNCPathToPosix(path string) (string, bool)

The POSIX path inside a wsl.localhost or wsl$ UNC path, false when path is not one

func WindowsPathToWSL

func WindowsPathToWSL(path string) (string, bool)

The /mnt drive form of a Windows drive path, false when path is not one

func WithOverride

func WithOverride(ctx context.Context, path string) context.Context

Returns a context whose home resolution answers path instead of the process home

Types

type ErrHomeErased

type ErrHomeErased struct {
	Home string
}

Error of a path under a home this process erased

func (*ErrHomeErased) Error

func (e *ErrHomeErased) Error() string

func (*ErrHomeErased) Is

func (e *ErrHomeErased) Is(target error) bool

Matches fs.ErrNotExist, the home data no longer exists

type ErrProfileMissing

type ErrProfileMissing struct {
	Home string
}

Error of a path under a named profile that was deleted or never created

func (*ErrProfileMissing) Error

func (e *ErrProfileMissing) Error() string

func (*ErrProfileMissing) Is

func (e *ErrProfileMissing) Is(target error) bool

Matches fs.ErrNotExist, the profile home does not exist

type GrantFailure

type GrantFailure struct {
	Path   string
	Reason string
}

Outcome of one failed grant in a tree walk, the path and the error text

func GrantTreeUserAccess

func GrantTreeUserAccess(root string, pinRoot, elevated bool) (int, []string, []GrantFailure, error)

Elevated recursive grant over root and everything under it, never through a link

type ReparsePointRefused

type ReparsePointRefused struct{ Msg string }

Refusal to grant through a junction, symlink, other reparse point or hard link

func (*ReparsePointRefused) Error

func (e *ReparsePointRefused) Error() string

Jump to

Keyboard shortcuts

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