userenv

package
v0.59.2 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: Apache-2.0 Imports: 11 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 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

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

func Environ(log *slog.Logger) []string

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.

func Warm

func Warm(log *slog.Logger)

Warm resolves the environment in the background, so the first session the user starts does not wait for their shell.

Types

This section is empty.

Jump to

Keyboard shortcuts

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