Introducing a new way to review your PRs.

Read the announcement

jdx / fnox

encrypted/remote secret manager

View on GitHub

27 documents · Updated Nov 23, 2026

docs / environment-inspection-and-serialization

Environment inspection and serialization

fnox env --json builds the environment that a command or shell may receive and renders it as one machine-readable document. It gives process managers the same selection, secret resolution, lease, and filtering rules as fnox exec without starting the final process. See execution and environment integration for the wider model and command execution and environment injection for the child-process boundary.

Environment plan

The home/…/env.rs command turns the active profile into an environment plan. A plan separates values to set, values that need a file, inherited names to remove, unresolved names, and leases that ran. This lets a caller apply the result without depending on fnox's process model.

Scope selection

The scope defines which configuration entries may become environment values. exec matches the environment available to a command and can run leases. shell matches the interactive shell and excludes command-only secrets and all leases.

ScopeSecret modes includedLease behavior
execenv = true or unset, and env = "exec"Selected leases may produce values
shellenv = true or unsetNo leases are selected

Without --keys, the command selects every secret allowed by the scope. It also selects every lease for exec. With --keys, it selects only the named keys and keeps the first copy of a repeated key. A key produced by a lease is valid for exec, and the lease value takes priority over a same-name secret.

An env = false secret is not an injectable root. A secret with env = "exec" is not valid for shell. Unknown keys and keys outside the selected scope are rejected before provider work begins. The error can include close-name suggestions so a machine consumer can report a useful correction.

References: src/…/env.rs• L34-50 src/child_env.rs• L26-32 src/child_env.rs• L109-230 docs/…/env-json.md• L28-54

Dependency resolution

The plan resolves selected roots and the secrets needed to produce them. Dependencies can come from default interpolation, provider environment inputs, or the inputs of a selected lease. A dependency may be resolved without being emitted when its environment mode forbids injection.

The command does not resolve unrelated hidden secrets. This filtering avoids unnecessary provider access and keeps values such as an env = false lease input out of the result. A command lease has no fixed output names, so selecting one may require resolution of the whole profile; its produced keys appear only after the lease runs.

Resolution can use the daemon when the project enables it. The daemon and direct path produce the same document, while --describe skips resolution and daemon access. Temporary values used to create leases exist only during that internal step and do not become inherited values for the eventual consumer.

The following flow shows how selection becomes a child-environment document.

flowchart LR
    A[Active profile and scope] --> B[Select roots and leases]
    B --> C[Resolve roots and dependencies]
    C --> D[Run selected exec leases]
    D --> E[Assemble set files remove missing]
    E --> F[Render schema 1 JSON]

References: src/child_env.rs• L233-276 src/child_env.rs• L395-492 src/daemon.rs• L1013-1098 docs/…/env-json.md• L56-62

Environment assembly

Assembly converts resolved values into instructions for a caller that already has an inherited environment. Ordinary values enter set. An as_file value enters files as raw content, so the caller can create a file and set the variable to that file path. The command itself does not leave those files behind.

The remove list protects the boundary in two ways. It removes credentials that fnox uses internally, such as ambient decryption inputs, and removes configured secrets that are outside the selected scope. A name is not removed when the plan also sets it or supplies it through files. Missing values are reported for requested or in-scope keys that resolve to no value when the missing-value policy permits the command to continue.

Consumers apply the plan in this order:

  1. Remove names in remove from the inherited environment.
  2. Set values in set.
  3. Write each files value and set its key to the new file path.

References: src/child_env.rs• L278-391 crates/…/document.rs• L113-134 docs/…/env-json.md• L68-99

JSON contract

The JSON output is a versioned interface for tools that start processes themselves. The command writes one compact JSON document followed by a newline. Secret values are present in plain text in successful set and files documents, so callers must keep standard output out of logs.

Success document

The success document identifies the schema, fnox version, scope, and active profile. Its environment fields describe actions rather than a complete replacement environment.

FieldMeaning
schemaBreaking-contract version. The current value is 1.
fnox_versionVersion that created the document.
scopeexec or shell.
profileOrdered active profiles used to resolve values.
setPlain values to add to the inherited environment.
filesRaw contents for as_file values.
removeInherited names to delete before adding values.
missingIn-scope or requested names with no value under a non-error policy.
leasesLease names that actually ran.

Map order follows the environment plan: configured secret values come in configuration order, and lease credentials follow them. A lease credential replaces a same-name ordinary secret. Consumers must ignore unknown fields within schema 1. A breaking change requires a new schema value.

References: crates/…/document.rs• L13-14 crates/…/document.rs• L113-159 src/child_env.rs• L495-514 docs/…/env-json.md• L64-99

Describe document

--describe provides an inspection view without resolving any secret. It shows each known key, whether it is a secret or lease result, its environment mode, file form, description, and whether exec or shell may inject it.

The describe result also names dynamic command leases whose output keys are not known before execution. It reports whether the project would use the daemon. Since this path performs no provider lookup and runs no lease, it is the safe interface for checking available keys without exposing values.

References: src/…/env.rs• L97-115 src/child_env.rs• L516-577 crates/…/document.rs• L162-247 docs/…/env-json.md• L101-145

Error document

Failures after --json produce a schema 1 error document on stdout and exit with status 1. The error kind identifies the stage that failed: configuration loading, key validation, or resolution. Key validation errors can include unknown keys, suggestions, and keys that are not injectable for the chosen scope.

Argument parsing errors occur before the JSON contract and use status 2 without a JSON document. Omitting --json is also a command error without JSON. Warnings, authentication prompts, and the human error report use stderr so stdout remains parseable.

References: src/…/env.rs• L52-80 crates/…/document.rs• L250-320 docs/…/env-json.md• L147-177

Consumer boundary

The output is an instruction set for a process manager such as mise. It is not a dotenv file and it is not the same contract as fnox export --format json: env preserves scope, missing keys, lease activity, and the caller-owned file step.

Consumers should treat the document as sensitive input. They should parse the schema, preserve the apply order, keep stdout private, and keep any files created from files alive for the process that uses them. A caller that needs shell state can request --for shell, but it still applies the result as environment changes rather than as a full environment replacement.

References: src/…/env.rs• L28-32 crates/…/document.rs• L80-116 docs/…/env-json.md• L5-18

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep scope filtering aligned with EnvMode in configuration, fnox exec, shell hooks, and the JSON describe result.
  • Preserve lease precedence when a lease output key matches a configured secret key.
  • Keep dependency selection separate from output selection so hidden inputs can support resolution without entering set or files.
  • Keep the remove, set, and files apply order stable for every machine consumer.
  • Update the schema contract and client document types together if a breaking field or meaning changes.
  • Keep direct resolution and daemon cache hits on the same document shape and filtering rules.

Important failure modes

TriggerConsequenceGuard
A caller logs stdout from a successful documentSecret values in set or files become exposedKeep stdout private and send only the parsed plan to the process manager.
A caller applies set before removeAn out-of-scope inherited value can remain or override the intended stateApply remove, then set, then files.
A caller treats files values as pathsThe target receives content where it expects a file nameWrite each file value and set the key to the created path.
--keys names an env = false or shell-incompatible secretThe command returns an invalid_keys document instead of resolving itUse an injectable scope or use fnox get for non-injectable values.
A required provider value is missing under if_missing = "error"The command returns a resolution error and no success planUse an intentional missing-value policy and fix the provider input.
A consumer rejects unknown schema fields or requires an exact field setA compatible schema 1 document may fail to loadIgnore unknown fields and reject only unsupported schema versions.

Key files

FileWhy to read it
src/…/env.rsCommand entry point, scope flags, phase errors, and JSON output selection.
src/child_env.rsShared selection, dependency planning, environment assembly, and document creation used by env and exec.
crates/…/document.rsVersioned success, describe, and error document types for machine consumers.
src/daemon.rsDaemon cache path and its equivalence with direct environment document creation.
src/…/exec.rsThe process consumer that applies the same environment plan to a child command.
docs/…/env-json.mdUser-facing JSON fields, filtering rules, streams, and compatibility contract.
test/env_json.batsEnd-to-end guarantees for filtering, dependencies, files, errors, leases, and daemon reuse.