Documentation
¶
Overview ¶
Package userenv gives the processes Caprock starts the environment the user's own terminal would give them.
The daemon's environment is the wrong one to hand down. Started at login by launchd it holds ten variables and PATH=/usr/bin:/bin:/usr/sbin:/sbin — no Homebrew, no gcloud, nothing the user exports from their shell profile — and started from a terminal it is a snapshot of that terminal, frozen for as long as the daemon runs. A session spawned from either one fails in ways a session typed into a terminal does not: `gcloud` is not found, a project variable is unset, a credential helper is missing. The user reads that as "Caprock can't reach BigQuery" when plain `claude` can.
So, the way VS Code resolves its shell environment, the user's login shell is run once, interactively, and asked to print its environment; that is what a spawned process inherits. It is cached briefly, bounded by a timeout, and falls back to the daemon's own environment on any failure — a slow or broken profile must never stop a session from starting.
Index ¶
Constants ¶
const ( // Timeout bounds one resolution. An interactive zsh with a framework on // top starts in well under a second; anything slower is a profile doing // something we should not wait for. Timeout = 5 * time.Second // TTL is how long a resolved environment is served before a background // refresh. An export added to the profile reaches sessions started a // minute later, without restarting the daemon. TTL = time.Minute // ResolvingVar is set in the shell while it is being asked for its // environment, so a profile can skip work that only makes sense for a // person (a tmux attach, a greeting, an update check). ResolvingVar = "CAPROCK_RESOLVING_ENVIRONMENT" )
Variables ¶
This section is empty.
Functions ¶
func Environ ¶
Environ returns the environment for a process Caprock starts on the user's behalf: their login shell's, or the daemon's own when that cannot be had. The caller owns the returned slice.
Only the first call ever waits for the shell (Warm makes even that one free). After that a stale copy is returned at once and refreshed in the background: an interactive zsh with a framework takes one to two seconds, which is not a cost to put in front of every session start.
Types ¶
This section is empty.