Documentation
¶
Overview ¶
Package env provides pure, daemon-safe .env file parsing, merging, and atomic file updating into isolated in-memory maps.
Daemon-Safe Isolation ¶
Unlike traditional dotenv libraries that mutate process-global state via os.Setenv or read ambient variables via os.Getenv, this package operates exclusively on isolated map[string]string values. In the TaskSmith Brain daemon, multiple workspaces, worktrees, and subagents execute concurrently within a single OS process. By forbidding global environment reads and mutations, credentials and configuration variables loaded for one workspace can never leak into or overwrite another workspace's environment.
Precedence and Merging ¶
Environment maps can be layered deterministically using Merge, where later maps take precedence over earlier ones (for example, overlaying a workspace's local .tasksmith/.env on top of the global ~/.tasksmith/.env).
In-Place File Updates ¶
SetInFile updates or appends individual environment variables in a .env file while preserving existing comments, blank lines, key ordering, and file permissions, creating new files with restrictive 0600 permissions by default.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoadFile ¶
LoadFile reads and parses a .env file at path. If the file does not exist, LoadFile returns an empty non-nil map and a nil error.
func Merge ¶
Merge combines the provided environment maps in order and returns a new isolated map. Keys in later maps override keys in earlier maps.
func Parse ¶
Parse reads .env formatted content from r and returns an isolated map of key-value pairs. It never reads or mutates the process environment.
func SetInFile ¶
SetInFile sets key=value in the .env file at path. If key already exists in the file, its line is updated in-place while preserving all comments, blank lines, and key ordering. Otherwise, key=value is appended at the end.
Parent directories are created as needed. Newly created files are written with 0600 permissions; existing files preserve their current permissions.
Types ¶
This section is empty.