paths

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package paths centralizes filesystem path resolution honoring AGENTSYNC_HOME and AGENTSYNC_TARGET_ROOT. Production code MUST use this package; lint forbids os.UserHomeDir in *_test.go files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AgentsyncHome

func AgentsyncHome(e Env) string

AgentsyncHome returns the directory where agentsync stores its source repo. Resolution order:

  1. $AGENTSYNC_HOME (explicit override; absolute path)
  2. <HomeDir>/.agentsync

func FromHomeRelative

func FromHomeRelative(userHome, stored string) string

FromHomeRelative is the inverse of HomeRelative: it expands a leading "${HOME}" / "${HOME}/" in a stored state path back to an absolute path rooted at userHome. Paths stored absolute (because they were outside home when recorded) are returned unchanged. Callers that turn a stored state key back into a real filesystem path (e.g. `agent disable --purge`) MUST route through this so they don't operate on the literal "${HOME}/..." string.

func HomeDir

func HomeDir(e Env) string

HomeDir returns the effective home dir. AGENTSYNC_TARGET_ROOT takes precedence (used by tests to redirect away from the real $HOME); otherwise falls back to $HOME.

func HomeRelative

func HomeRelative(home, abs string) string

HomeRelative converts an absolute destination path into the portable form stored in state files: "${HOME}/.claude.json" instead of the machine-specific absolute "/Users/alice/.claude.json". Paths that do not live under home are returned unchanged.

Without this normalization, state.Files / state.Keys keys would embed the absolute path that existed on the machine that wrote them, so a state file synced via chezmoi from /Users/alice/ to /home/alice/ would have every key prefix change and every native file would reclassify as ForeignCollision on the next apply.

HomeRelative uses forward-slash separators in the stored form so the same key is produced on POSIX and Windows when home is the equivalent path.

Types

type Env

type Env interface {
	Get(key string) string
}

Env abstracts environment-variable lookup so tests can inject a fake.

type MapEnv

type MapEnv map[string]string

MapEnv is a fake Env backed by a map (for tests).

func (MapEnv) Get

func (m MapEnv) Get(key string) string

type OSEnv

type OSEnv struct{}

OSEnv reads the live process environment.

func (OSEnv) Get

func (OSEnv) Get(key string) string

Jump to

Keyboard shortcuts

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