EnvValidationResult Result of env var validation.
Uses discriminated union for better type narrowing:
- ok: true, missing: null — all vars present
- ok: false, missing: EnvVarRef[] — some vars missing
Environment variable $$VAR$$ resolution suite.
Resolves $$VAR$$ references in strings and object trees,
scans configs for references, and validates/formats missing vars.
The double-dollar bookending syntax is:
- Visually distinct from shell $VAR syntax
- Unambiguous about variable boundaries
- Easy to grep: grep '\$\$'
- Fails loud if accidentally shell-processed ($$=PID in shell)
11 declarations
EnvValidationResult Result of env var validation.
Uses discriminated union for better type narrowing:
- ok: true, missing: null — all vars present
- ok: false, missing: EnvVarRef[] — some vars missing
EnvVarRef An env var reference found in a config.
nameVariable name (without $$ delimiters).
stringpathPath where the reference was found (e.g., "target.host", "resources[3].path").
string(missing: EnvVarRef[], options?: FormatMissingEnvVarsOptions | undefined): string Format missing env vars error message.
Groups refs by variable name so each missing var is shown once with all paths where it's referenced.
missingmissing env var references (may contain duplicate names)
EnvVarRef[]options?formatting options
FormatMissingEnvVarsOptions | undefinedstring formatted error message for display
FormatMissingEnvVarsOptions Options for format_missing_env_vars.
env_filePath to env file if one was loaded.
stringsetup_hintHint text for how to set up the environment.
string(value: string): string[] Get list of env var names referenced in a string.
valuestring to scan
stringstring[] array of variable names (without $$ delimiters)
(value: string): boolean Check if a string contains unresolved env var references.
valuestring to check
stringboolean true if string contains $$VAR$$ patterns
(runtime: Pick<EnvDeps, "env_get">, value: string): string Resolve environment variable references in a string.
Uses $$VAR$$ syntax (bookended double-dollar signs).
Only resolves variables that are actually set in the environment.
Unset variables are left as-is for clear error messages.
runtimeruntime with env_get capability
Pick<EnvDeps, "env_get">valuestring that may contain $$VAR$$ references
stringstring string with env vars resolved
<T extends Record<string, unknown>>(runtime: Pick<EnvDeps, "env_get">, obj: T): T Resolve env vars in an object's string values (shallow).
runtimeruntime with env_get capability
Pick<EnvDeps, "env_get">objobject with string values
TT new object with env vars resolved
(runtime: Pick<EnvDeps, "env_get">, value: string, context: string): string Resolve env vars and throw if any are missing/empty.
Use this for values that must be present.
runtimeruntime with env_get capability
Pick<EnvDeps, "env_get">valuestring with $$VAR$$ references
stringcontextdescription for error message (e.g., "target.host")
stringstring resolved string
error - if any referenced env var is missing or empty(obj: unknown): EnvVarRef[] Recursively scan an object for $$VAR$$ env var references.
Walks all string values in the object tree and extracts env var names with their path context for error reporting.
objobject to scan (typically a config)
unknownEnvVarRef[] array of env var references with paths
(runtime: Pick<EnvDeps, "env_get">, refs: EnvVarRef[]): EnvValidationResult Validate that all referenced env vars exist in the environment.
Returns all missing refs (including duplicates by name). Grouping and deduplication is handled by format_missing_env_vars at display time.
runtimeruntime with env_get capability
Pick<EnvDeps, "env_get">refsenv var references from scan_env_vars
EnvVarRef[]EnvValidationResult validation result with any missing vars