feat(spec): declare environment variables a command reads with an env node #1689
All Vouch review confidence checks passed
Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 609 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.384
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1689"
general
weight: 0.35
jdx
A command often reads an environment variable that is not any flag's value. For example,
shellreadsSHELLto choose the program it opens, andrunreadsTOOL_HOMEto find files another tool writes. Until now a spec had only two ways to declare one. It could bind the variable to a flag (flag … env="X"), which invents a flag nobody asked for. Or it could use a rootconfigproperty, which documents the variable on every command, including the ones that never read it. Otherwise the variable lived only in prose, where generated docs, JSON output andunknown_envcould not see it.A new
envnode declares such a variable on the command that reads it, or at the top level for one the whole program reads:usage generate markdownnow renders:What a declaration does:
envgets anENVIRONMENTsection.usage generate jsonincludes it asenvson the command.unknown_env: it counts as declared, hidden ones included.usage lint: a newmissing-env-help(info) rule reports a variable without help, andduplicate-env(error) reports one declared twice on the same command.Supported properties are
help,long_help,default_note,deprecated(a message or#true) andhide. The declaration only documents the variable. usage never reads it or applies the default, and it is not inherited by subcommands. Library users get a newSpecEnvtype and aSpecCommand::envsfield.cargo-semver-checksreports no breaking change, becauseSpecCommandalready has crate-private fields and cannot be built with a struct literal.The Rust derives (
#[usage(...)]) do not emitenvnodes yet. A spec has to declare them in KDL.Proposed in https://github.com/jdx/usage/discussions/1688.
Validation:
cargo test --all --all-featuresandmise run lint(including semver checks) pass. New tests cover parsing, KDL round-trip, the JSON round-trip fixture, markdown in both themes, the man page,unknown_env, and the lint rules.AI-assisted — Tool: Claude Code; model: anthropic/claude-sonnet-5-5; version: unavailable.
🤖 Generated with Claude Code
<!-- CURSOR_SUMMARY -->
---
<!-- /CURSOR_SUMMARY -->
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->
Summary by CodeRabbit
New Features
Added command-level environment variable declarations with help text, default notes, deprecation notices, and visibility controls.
Added environment variable details to generated Markdown and man-page documentation, including for subcommands.
Updated unknown environment variable checks to recognize command-level declarations.
Bug Fixes
Linting now reports duplicate environment variable names and flags visible declarations without help text.
Documentation
Expanded the command reference to explain environment declarations and their behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->