Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

feat(diagnostic): surface pager/terminal env vars in the -vv report (#3328)

Worktrunk Bota38481bf31f3
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b92e6e719..659a82b8e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,11 @@
# Changelog
+## Unreleased
+
+### Improved
+
+- **`-vv` diagnostics surface pager and terminal environment**: The diagnostic report (`.git/wt/logs/diagnostic.md`, written on every `-vv` run) gained an "Environment variables" section listing a curated, non-secret allowlist of the pager / terminal / locale knobs (`PAGER`, `GIT_PAGER`, `TERM`, `COLUMNS`, `NO_COLOR`, `LANG`, …) plus git's resolved `core.pager`. These are the inputs that most often explain a rendering bug — like a pager interaction suspending `wt config show` ([#3322](https://github.com/max-sixty/worktrunk/issues/3322)) — and they were previously invisible in the report. The list is a strict allowlist, never a blanket `env` dump, so no credential-bearing variable can leak into an uploaded report.
+
## 0.66.0
### Improved
diff --git a/src/diagnostic.rs b/src/diagnostic.rs
index 881a87669..ef3e437e8 100644
--- a/src/diagnostic.rs
+++ b/src/diagnostic.rs
@@ -21,18 +21,25 @@
//! first as the at-a-glance summary, expanded by default; the raw dumps
//! below stay collapsed.
//! 3. **Environment** — wt version, OS, git version, shell integration
-//! 4. **Worktrees** — Raw `git worktree list --porcelain` output
-//! 5. **Config** — User and project config contents
-//! 6. **Verbose log** — Debug log output, truncated to ~50KB if large
+//! 4. **Environment variables** — a curated, non-secret allowlist of the
+//! pager / terminal / locale knobs (`PAGER`, `GIT_PAGER`, `TERM`, …) plus
+//! git's resolved `core.pager`, since these most often explain a rendering
+//! bug (issue #3322: `wt config show` suspending on a pager write)
+//! 5. **Worktrees** — Raw `git worktree list --porcelain` output
+//! 6. **Config** — User and project config contents
+//! 7. **Verbose log** — Debug log output, truncated to ~50KB if large
//!
//! # Privacy
//!
//! The report explicitly documents what IS and ISN'T included:
//!
//! **Included:** worktree paths, branch names, worktree status (prunable, locked),
-//! config files, trace/output logs, commit messages (in trace logs)
+//! config files, trace/output logs, commit messages (in trace logs), and a
+//! fixed allowlist of pager / terminal / locale environment variables
//!
-//! **Not included:** file contents, credentials
+//! **Not included:** file contents, credentials, any environment variable
+//! outside the curated allowlist (the report never does a blanket `env` dump,
+//! so a credential-bearing variable can't leak in)
//!
//! # File Location
//!
@@ -95,6 +102,14 @@ Shell integration: {{ shell_integration }}
```
</details>
+<details>
+<summary>Environment variables</summary>
+
+```
+{{ env_vars }}
+```
+</details>
+
<details>
<summary>Worktrees</summary>
@@ -132,6 +147,40 @@ Full captured stdout/stderr is in `{{ subprocess_log_path }}`.
{%- endif %}
"#;
+/// The curated, non-secret environment variables surfaced in the diagnostic
+/// report, in display order. This is a strict allowlist — the report never does
+/// a blanket `env` dump — so a credential-bearing variable (a token, a password)
+/// can never reach the uploaded report. Every entry is a knob that shapes
+/// rendering, output, or worktrunk's own behaviour, which is the class of bug a
+/// diagnostic most often needs (issue #3322: a pager interaction suspending
+/// `wt config show`). To surface a new variable, add its name here.
+const DIAGNOSTIC_ENV_VARS: &[&str] = &[
+ // Pager selection — the class behind issue #3322. `core.pager` (git config)
+ // is appended separately by `environment_vars`.
+ "PAGER",
+ "GIT_PAGER",
+ "LESS",
+ // Terminal & colour capability — drives width detection and ANSI output.
+ "TERM",
+ "COLORTERM",
+ "COLUMNS",
+ "LINES",
+ "NO_COLOR",
+ "CLICOLOR",
+ "CLICOLOR_FORCE",
+ // Shell & locale — affect interactive probes, escaping, and date rendering.
+ "SHELL",
+ "LANG",
+ "LC_ALL",
+ "LC_TIME",
+ // Worktrunk's own runtime knobs and logging.
+ "RUST_LOG",
+ "WORKTRUNK_VERBOSE",
+ "WORKTRUNK_SHELL",
+ "WORKTRUNK_FOREGROUND",
+ "WORKTRUNK_MAX_CONCURRENT_COMMANDS",
+];
+
/// Collected diagnostic information for issue reporting.
pub(crate) struct DiagnosticReport {
/// Formatted markdown content
@@ -183,6 +232,10 @@ impl DiagnosticReport {
.map(|s| s.trim_end().to_string())
.unwrap_or_else(|_| "(failed to get worktree list)".to_string());
+ // Curated, non-secret env vars (pager / terminal / locale knobs) plus
+ // git's resolved `core.pager` — the inputs a rendering bug report needs.
+ let env_vars = environment_vars(repo);
+
// Get config show output (if available)
let config_show = config_show_output(repo);
@@ -217,6 +270,7 @@ impl DiagnosticReport {
arch,
git_version,
shell_integration,
+ env_vars,
worktree_list,
config_show,
performance_profile,
@@ -403,6 +457,37 @@ fn git_version() -> anyhow::Result<String> {
Ok(version)
}
+/// Render the curated environment variables ([`DIAGNOSTIC_ENV_VARS`]) plus git's
+/// resolved `core.pager` as `KEY=value` lines for the diagnostic report.
+///
+/// Every name comes from the explicit allowlist — never a blanket `env` dump —
+/// so no credential-bearing variable can reach the report. An unset variable is
+/// rendered as `(unset)` so an absent `PAGER` is as visible as a set one, which
+/// is exactly the distinction a pager-suspension report (issue #3322) turns on.
+fn environment_vars(repo: &Repository) -> String {
+ let mut lines: Vec<String> = DIAGNOSTIC_ENV_VARS
+ .iter()
+ .map(|name| {
+ let value = std::env::var(name).unwrap_or_else(|_| "(unset)".to_string());
+ format!("{name}={value}")
+ })
+ .collect();
+
+ // git's `core.pager` is the pager source `PAGER`/`GIT_PAGER` don't capture.
+ // Read the raw config value (not `pager::git_config_pager`, which folds an
+ // explicit `cat`/empty into "unset") so the report shows what git actually
+ // sees.
+ let core_pager = repo
+ .config_value("core.pager")
+ .ok()
+ .flatten()
+ .filter(|v| !v.trim().is_empty())
+ .unwrap_or_else(|| "(unset)".to_string());
+ lines.push(format!("core.pager={core_pager}"));
+
+ lines.join("\n")
+}
+
/// Get config show output for diagnostic.
///
/// Returns a summary of user and project config files.
diff --git a/tests/integration_tests/diagnostic.rs b/tests/integration_tests/diagnostic.rs
index 2bfcf9f6d..38012a4ef 100644
--- a/tests/integration_tests/diagnostic.rs
+++ b/tests/integration_tests/diagnostic.rs
@@ -201,6 +201,49 @@ fn test_diagnostic_contains_required_sections(mut repo: TestRepo) {
);
}
+/// The diagnostic surfaces the curated pager/terminal env vars and git's
+/// resolved `core.pager`, so a rendering bug like #3322 (a pager interaction
+/// suspending `wt config show`) can be diagnosed from the report alone. A set
+/// `PAGER` is echoed verbatim; an unset allowlisted var shows `(unset)`.
+#[rstest]
+fn test_diagnostic_includes_environment_variables(mut repo: TestRepo) {
+ repo.add_worktree("feature");
+ // Configure git's core.pager so its resolved value appears in the report.
+ repo.run_git(&["config", "core.pager", "my-test-pager --opt"]);
+
+ repo.wt_command()
+ .args(["list", "-vv"])
+ .env("PAGER", "my-test-pager")
+ .env_remove("GIT_PAGER")
+ .output()
+ .unwrap();
+
+ let content = fs::read_to_string(
+ repo.root_path()
+ .join(".git")
+ .join("wt/logs")
+ .join("diagnostic.md"),
+ )
+ .unwrap();
+
+ assert!(
+ content.contains("<summary>Environment variables</summary>"),
+ "Should have an environment-variables section. content: {content}"
+ );
+ assert!(
+ content.contains("PAGER=my-test-pager"),
+ "A set PAGER should be echoed verbatim. content: {content}"
+ );
+ assert!(
+ content.contains("GIT_PAGER=(unset)"),
+ "An unset allowlisted var should read (unset). content: {content}"
+ );
+ assert!(
+ content.contains("core.pager=my-test-pager --opt"),
+ "git's resolved core.pager should be surfaced. content: {content}"
+ );
+}
+
/// The context field should have ANSI codes stripped for clean GitHub display.
#[rstest]
fn test_diagnostic_context_has_no_ansi_codes(mut repo: TestRepo) {
@@ -1052,6 +1095,22 @@ fn normalize_report(content: &str) -> String {
.replace_all(&result, "$1 $2")
.to_string();
+ // Truncate the environment-variables section - its values (TERM, SHELL,
+ // LANG, PAGER, …) are inherited from the host and differ per machine, so
+ // exact comparison is non-deterministic. We assert specific lines appear in
+ // a dedicated test instead.
+ if let Some(start) = result.find("<summary>Environment variables</summary>")
+ && let Some(end_offset) = result[start..].find("</details>")
+ {
+ let end = start + end_offset + "</details>".len();
+ let before = &result[..start];
+ let after = &result[end..];
+ result = format!(
+ "{}<summary>Environment variables</summary>\n\n[ENV_VARS_CONTENT]\n</details>{}",
+ before, after
+ );
+ }
+
// Truncate performance profile section - its durations and by-type/slowest
// ordering depend on the run's real timing, so exact comparison is flaky.
// We verify the section exists separately in the test.
diff --git a/tests/snapshots/integration__integration_tests__diagnostic__diagnostic_file_format.snap b/tests/snapshots/integration__integration_tests__diagnostic__diagnostic_file_format.snap
index d965a9b05..d4c0b6cf9 100644
--- a/tests/snapshots/integration__integration_tests__diagnostic__diagnostic_file_format.snap
+++ b/tests/snapshots/integration__integration_tests__diagnostic__diagnostic_file_format.snap
@@ -24,6 +24,12 @@ Shell integration: inactive
```
</details>
+<details>
+<summary>Environment variables</summary>
+
+[ENV_VARS_CONTENT]
+</details>
+
<details>
<summary>Worktrees</summary>