configvalue

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package configvalue mirrors upstream pi's packages/coding-agent/src/core/resolve-config-value.ts (v0.78.1).

A configuration string value is one of:

  1. A "!cmd" prefix → strip the "!", run the rest as a shell command, return the trimmed stdout. Cached for the process lifetime.
  2. A template that may reference environment variables with "$VAR" or "${VAR}". "$$" escapes a literal "$" and "$!" escapes a literal "!". Any other text is literal. A template resolves to undefined (empty) if any referenced env var is unset or empty.
  3. A plain string with no "$" → a literal that resolves to itself.

IMPORTANT: unlike the pre-v0.78.1 contract, a bare identifier is NO LONGER implicitly matched against the environment. {"apiKey":"OPENAI_API_KEY"} now resolves to the literal string "OPENAI_API_KEY". Environment references require an explicit "$" sigil: {"apiKey":"$OPENAI_API_KEY"}.

Lives in its own package (rather than internal/codingagent/ where the plan named it) because ai/auth.go is a consumer and internal/codingagent already imports ai. A neutral package sidesteps the cycle while preserving the public API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearCache

func ClearCache()

ClearCache wipes the !cmd cache. Test-only.

func GetConfigValueEnvVarName

func GetConfigValueEnvVarName(config string) string

GetConfigValueEnvVarName returns the single env-var name a config value references, or "" if it is a command, a literal, or a multi-part template.

func GetConfigValueEnvVarNames

func GetConfigValueEnvVarNames(config string) []string

GetConfigValueEnvVarNames returns every distinct env-var name a config value references (empty for commands and literals).

func GetMissingConfigValueEnvVarNames

func GetMissingConfigValueEnvVarNames(config string, env map[string]string) []string

GetMissingConfigValueEnvVarNames returns the referenced env-var names that are currently unset/empty. Provider-scoped overrides in env are consulted before the process environment.

func IsCommandConfigValue

func IsCommandConfigValue(config string) bool

IsCommandConfigValue reports whether a config value is a "!cmd" command.

func IsConfigValueConfigured

func IsConfigValueConfigured(config string, env map[string]string) bool

IsConfigValueConfigured reports whether all referenced env vars are set. Provider-scoped overrides in env are consulted before the process environment.

func Resolve

func Resolve(s string, env map[string]string) string

Resolve returns the runtime value for a config string, or "" when a command fails or a referenced env var is unset. Mirrors upstream resolveConfigValue (string | undefined), collapsing undefined to "". Provider-scoped overrides in env take precedence over the process environment.

func ResolveHeaders

func ResolveHeaders(in map[string]string, env map[string]string) map[string]string

ResolveHeaders maps each header value through Resolve and drops entries that resolve to empty strings. Returns nil if every entry drops out. Provider-scoped overrides in env take precedence over the process environment.

func ResolveOrError

func ResolveOrError(s, description string, env map[string]string) (string, error)

ResolveOrError mirrors upstream resolveConfigValueOrThrow: it errors when a command fails or a referenced env var is unset, with the same messages. A pure literal never errors (it resolves to itself). Provider-scoped overrides in env take precedence over the process environment.

func ResolveUncached

func ResolveUncached(s string, env map[string]string) string

ResolveUncached is Resolve but skips the !cmd cache.

func SetExecutorForTest

func SetExecutorForTest(fn func(ctx context.Context, payload string) (string, bool)) func()

SetExecutorForTest swaps the shell-out implementation. Test-only. The returned function restores the previous executor.

Types

This section is empty.

Jump to

Keyboard shortcuts

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