Skip to content

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

Consolidate -vv notifications onto diagnostic.md, led by the performance profile (#3329)

Maximilian Roose74b4241bff8
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fa2b0406e..c55a2daf3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -32,6 +32,8 @@
- **Statusline width comes from `COLUMNS`, not a parent-process walk**: `wt list statusline` used to spawn up to 10 `ps` calls plus `stty` per render to recover a terminal width, because Claude Code piped the subprocess with no inherited TTY. Claude Code now sets `COLUMNS`/`LINES` to the terminal dimensions before running the script (since v2.1.153), so the width comes straight from there — less a fixed 5-column margin for Claude Code's own UI — and the `ps`/`stty` walk is gone. On an older Claude Code that doesn't set `COLUMNS`, the line renders untruncated rather than walking the process tree. ([#3286](https://github.com/max-sixty/worktrunk/pull/3286), closes [#2950](https://github.com/max-sixty/worktrunk/issues/2950))
+- **`-vv` diagnostics consolidate on `diagnostic.md`, led by the performance profile**: A `-vv` run now opens with a one-line pointer to the log directory (`○ Verbose logging to .git/wt/logs/`) and closes by naming what it captured — `○ Logs, performance profile, and diagnostics saved @ diagnostic.md` — with the raw `trace.jsonl` / `subprocess.log` companions listed beneath and the `gh gist create` bug-report hint. `diagnostic.md` now leads with the performance profile, expanded by default and promoted above the environment / worktree / config dumps; that profile reports the 20 slowest calls (was 8) and 10 same-context redundant-command offenders (was 3). There is no standalone `profile.txt` — the profile lives in the bundle, and `wt config state logs profile` re-renders it live from `trace.jsonl`. ([#3329](https://github.com/max-sixty/worktrunk/pull/3329))
+
### Fixed
- **`wt list` diff and ahead/behind columns use the upstream default tip**: The `main↕` (ahead/behind) and `main…±` (diff) columns measured every branch against the *local* default-branch tip, so in a fork whose local `main` lagged its upstream they reported inflated counts — one fork branch showed `↑44` and `+∞ / -5K` when it was ~2 commits past the real upstream tip. They now diff against the same upstream-aware base the integration column already uses. ([#3280](https://github.com/max-sixty/worktrunk/pull/3280))
diff --git a/docs/content/config.md b/docs/content/config.md
index 9b534f317..9aaaf61cc 100644
--- a/docs/content/config.md
+++ b/docs/content/config.md
@@ -1108,7 +1108,7 @@ All `post-*` hooks (post-start, post-switch, post-commit, post-merge) run in the
| `subprocess.log` | Running with `-vv` |
| `diagnostic.md` | Running with `-vv` |
-`trace.log` is the human-readable trace at `-vv` — each command's start (`$ …`) and completion (`✓`/`✗ … 12.3ms`), in-process spans, milestones, and bounded subprocess previews. `trace.jsonl` is the same event stream as one JSON object per line, for machines (`jq`, chrome://tracing); `wt config state logs profile` reads it to summarize a performance report (where time went, parallelism, redundant commands). `subprocess.log` holds the raw uncapped subprocess stdout/stderr bodies. `diagnostic.md` is a markdown bug-report bundle that inlines `trace.log` and a rendered performance profile; `wt` prints a `gh gist create` command pointing at it. All four are overwritten on each `-vv` run.
+`trace.log` is the human-readable trace at `-vv` — each command's start (`$ …`) and completion (`✓`/`✗ … 12.3ms`), in-process spans, milestones, and bounded subprocess previews. `trace.jsonl` is the same event stream as one JSON object per line, for machines (`jq`, chrome://tracing); `wt config state logs profile` reads it to summarize a performance report (where time went, parallelism, redundant commands). `subprocess.log` holds the raw uncapped subprocess stdout/stderr bodies. `diagnostic.md` is a markdown bug-report bundle that leads with that same performance profile and inlines `trace.log`; `wt` prints a `gh gist create` command pointing at it. All four are overwritten on each `-vv` run.
### Location
diff --git a/docs/content/faq.md b/docs/content/faq.md
index 0c05b6f6b..0346f5119 100644
--- a/docs/content/faq.md
+++ b/docs/content/faq.md
@@ -104,7 +104,7 @@ The `-vv` files have distinct audiences:
- **`trace.log`** — the human trace (bounded ~1K lines, gistable): each command's start (`$ git status`) and finish (`✓ git status [wt] 12.3ms`, `✗` on failure), spans, and milestones.
- **`trace.jsonl`** — the same records as one JSON object per line, for machines (`jq`, chrome://tracing). `wt config state logs profile` reads it.
- **`subprocess.log`** — raw uncapped stdout/stderr of every subprocess `wt` spawns (multi-MB possible, e.g. full `git log -p` output). The deep-dive escape hatch.
-- **`diagnostic.md`** — markdown bug-report bundle that inlines `trace.log` and a rendered performance profile (subprocess time by command type, slowest calls, repeated calls). `wt` prints a `gh gist create` command pointing at it.
+- **`diagnostic.md`** — markdown bug-report bundle that leads with the performance report (subprocess time by command type, slowest calls, repeated calls — the same rendering `wt config state logs profile` produces from `trace.jsonl`) and inlines `trace.log`. `wt` prints a `gh gist create` command pointing at it.
`RUST_LOG` overrides the flag baseline when set (`RUST_LOG=debug wt -v` lifts `-v` to debug-on-stderr).
@@ -160,7 +160,7 @@ Worktrunk stores small amounts of cache and log data in the repository's `.git/`
| `.git/wt/logs/trace.log` | Human debug trace for issue reporting | Running with `-vv` |
| `.git/wt/logs/trace.jsonl` | Machine trace (one JSON object per record) | Running with `-vv` |
| `.git/wt/logs/subprocess.log` | Raw uncapped subprocess stdout/stderr (may be multi-MB) | Running with `-vv` |
-| `.git/wt/logs/diagnostic.md` | Diagnostic report for issue reporting | Running with `-vv` |
+| `.git/wt/logs/diagnostic.md` | Diagnostic report for issue reporting (leads with the performance profile) | Running with `-vv` |
| `.git/wt/trash/<name>-<timestamp>` | Staged worktree contents pending background deletion | `wt remove` |
None of this is tracked by git or pushed to remotes.
diff --git a/skills/worktrunk/reference/config.md b/skills/worktrunk/reference/config.md
index f25f6d287..4550246f0 100644
--- a/skills/worktrunk/reference/config.md
+++ b/skills/worktrunk/reference/config.md
@@ -1143,7 +1143,7 @@ All `post-*` hooks (post-start, post-switch, post-commit, post-merge) run in the
| `subprocess.log` | Running with `-vv` |
| `diagnostic.md` | Running with `-vv` |
-`trace.log` is the human-readable trace at `-vv` — each command's start (`$ …`) and completion (`✓`/`✗ … 12.3ms`), in-process spans, milestones, and bounded subprocess previews. `trace.jsonl` is the same event stream as one JSON object per line, for machines (`jq`, chrome://tracing); `wt config state logs profile` reads it to summarize a performance report (where time went, parallelism, redundant commands). `subprocess.log` holds the raw uncapped subprocess stdout/stderr bodies. `diagnostic.md` is a markdown bug-report bundle that inlines `trace.log` and a rendered performance profile; `wt` prints a `gh gist create` command pointing at it. All four are overwritten on each `-vv` run.
+`trace.log` is the human-readable trace at `-vv` — each command's start (`$ …`) and completion (`✓`/`✗ … 12.3ms`), in-process spans, milestones, and bounded subprocess previews. `trace.jsonl` is the same event stream as one JSON object per line, for machines (`jq`, chrome://tracing); `wt config state logs profile` reads it to summarize a performance report (where time went, parallelism, redundant commands). `subprocess.log` holds the raw uncapped subprocess stdout/stderr bodies. `diagnostic.md` is a markdown bug-report bundle that leads with that same performance profile and inlines `trace.log`; `wt` prints a `gh gist create` command pointing at it. All four are overwritten on each `-vv` run.
### Location
diff --git a/skills/worktrunk/reference/faq.md b/skills/worktrunk/reference/faq.md
index 42d3f5043..070caf402 100644
--- a/skills/worktrunk/reference/faq.md
+++ b/skills/worktrunk/reference/faq.md
@@ -97,7 +97,7 @@ The `-vv` files have distinct audiences:
- **`trace.log`** — the human trace (bounded ~1K lines, gistable): each command's start (`$ git status`) and finish (`✓ git status [wt] 12.3ms`, `✗` on failure), spans, and milestones.
- **`trace.jsonl`** — the same records as one JSON object per line, for machines (`jq`, chrome://tracing). `wt config state logs profile` reads it.
- **`subprocess.log`** — raw uncapped stdout/stderr of every subprocess `wt` spawns (multi-MB possible, e.g. full `git log -p` output). The deep-dive escape hatch.
-- **`diagnostic.md`** — markdown bug-report bundle that inlines `trace.log` and a rendered performance profile (subprocess time by command type, slowest calls, repeated calls). `wt` prints a `gh gist create` command pointing at it.
+- **`diagnostic.md`** — markdown bug-report bundle that leads with the performance report (subprocess time by command type, slowest calls, repeated calls — the same rendering `wt config state logs profile` produces from `trace.jsonl`) and inlines `trace.log`. `wt` prints a `gh gist create` command pointing at it.
`RUST_LOG` overrides the flag baseline when set (`RUST_LOG=debug wt -v` lifts `-v` to debug-on-stderr).
@@ -153,7 +153,7 @@ Worktrunk stores small amounts of cache and log data in the repository's `.git/`
| `.git/wt/logs/trace.log` | Human debug trace for issue reporting | Running with `-vv` |
| `.git/wt/logs/trace.jsonl` | Machine trace (one JSON object per record) | Running with `-vv` |
| `.git/wt/logs/subprocess.log` | Raw uncapped subprocess stdout/stderr (may be multi-MB) | Running with `-vv` |
-| `.git/wt/logs/diagnostic.md` | Diagnostic report for issue reporting | Running with `-vv` |
+| `.git/wt/logs/diagnostic.md` | Diagnostic report for issue reporting (leads with the performance profile) | Running with `-vv` |
| `.git/wt/trash/<name>-<timestamp>` | Staged worktree contents pending background deletion | `wt remove` |
None of this is tracked by git or pushed to remotes.
diff --git a/src/cli/config.rs b/src/cli/config.rs
index 731ae85cc..53773269f 100644
--- a/src/cli/config.rs
+++ b/src/cli/config.rs
@@ -858,7 +858,7 @@ All `post-*` hooks (post-start, post-switch, post-commit, post-merge) run in the
| `subprocess.log` | Running with `-vv` |
| `diagnostic.md` | Running with `-vv` |
-`trace.log` is the human-readable trace at `-vv` — each command's start (`$ …`) and completion (`✓`/`✗ … 12.3ms`), in-process spans, milestones, and bounded subprocess previews. `trace.jsonl` is the same event stream as one JSON object per line, for machines (`jq`, chrome://tracing); `wt config state logs profile` reads it to summarize a performance report (where time went, parallelism, redundant commands). `subprocess.log` holds the raw uncapped subprocess stdout/stderr bodies. `diagnostic.md` is a markdown bug-report bundle that inlines `trace.log` and a rendered performance profile; `wt` prints a `gh gist create` command pointing at it. All four are overwritten on each `-vv` run.
+`trace.log` is the human-readable trace at `-vv` — each command's start (`$ …`) and completion (`✓`/`✗ … 12.3ms`), in-process spans, milestones, and bounded subprocess previews. `trace.jsonl` is the same event stream as one JSON object per line, for machines (`jq`, chrome://tracing); `wt config state logs profile` reads it to summarize a performance report (where time went, parallelism, redundant commands). `subprocess.log` holds the raw uncapped subprocess stdout/stderr bodies. `diagnostic.md` is a markdown bug-report bundle that leads with that same performance profile and inlines `trace.log`; `wt` prints a `gh gist create` command pointing at it. All four are overwritten on each `-vv` run.
## Location
diff --git a/src/diagnostic.rs b/src/diagnostic.rs
index 4a02b47c6..881a87669 100644
--- a/src/diagnostic.rs
+++ b/src/diagnostic.rs
@@ -6,21 +6,23 @@
//!
//! # When Diagnostics Are Generated
//!
-//! Diagnostic files are written on every `-vv` run (one file per command,
-//! overwritten each time). Without `-vv`, the hint simply tells users to
-//! rerun with `-vv`. This ensures the diagnostic file contains the trace
-//! the report inlines.
+//! A `diagnostic.md` bundle is written on every `-vv` run (one file per
+//! command, overwritten each time). Without `-vv`, the hint simply tells users
+//! to rerun with `-vv`. This ensures the diagnostic file contains the trace the
+//! report inlines.
//!
//! # Report Format
//!
//! The report is a markdown file designed for easy pasting into GitHub issues:
//!
//! 1. **Header** — Timestamp, command that was run, and result
-//! 2. **Environment** — wt version, OS, git version, shell integration
-//! 3. **Worktrees** — Raw `git worktree list --porcelain` output
-//! 4. **Config** — User and project config contents
-//! 5. **Performance profile** — Rendered view of `trace.jsonl`: where time went,
-//! parallelism, and same-context cache misses (omitted if no records)
+//! 2. **Performance profile** — Rendered view of `trace.jsonl`: where time went,
+//! parallelism, and same-context cache misses (omitted if no records). Shown
+//! 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
//!
//! # Privacy
@@ -35,7 +37,8 @@
//! # File Location
//!
//! Reports are written to `<git-common-dir>/wt/logs/diagnostic.md` (typically
-//! `.git/wt/logs/diagnostic.md`). Companion log files (`trace.log`, `trace.jsonl`, `subprocess.log`) live in the same directory.
+//! `.git/wt/logs/diagnostic.md`). Companion log files (`trace.log`,
+//! `trace.jsonl`, `subprocess.log`) live in the same directory.
//!
//! # Usage
//!
@@ -55,7 +58,9 @@ use minijinja::{Environment, context};
use worktrunk::git::Repository;
use worktrunk::path::format_path_for_display;
use worktrunk::shell_exec::Cmd;
-use worktrunk::styling::{eprintln, hint_message, success_message, warning_message};
+use worktrunk::styling::{
+ eprintln, format_with_gutter, hint_message, info_message, warning_message,
+};
use crate::cli::version_str;
use crate::output;
@@ -69,6 +74,16 @@ const REPORT_TEMPLATE: &str = r#"## Diagnostic Report
**Generated:** {{ timestamp }}
**Command:** `{{ command }}`
**Result:** {{ context }}
+{%- if performance_profile %}
+
+<details open>
+<summary>Performance profile</summary>
+
+```
+{{ performance_profile }}
+```
+</details>
+{%- endif %}
<details>
<summary>Environment</summary>
@@ -97,16 +112,6 @@ Shell integration: {{ shell_integration }}
```
</details>
{%- endif %}
-{%- if performance_profile %}
-
-<details>
-<summary>Performance profile</summary>
-
-```
-{{ performance_profile }}
-```
-</details>
-{%- endif %}
{%- if trace_log %}
<details>
@@ -141,12 +146,24 @@ impl DiagnosticReport {
/// * `command` - The command that was run (e.g., "wt list -vv")
/// * `context` - Context describing the result (error message or success)
pub fn collect(repo: &Repository, command: &str, context: String) -> Self {
- let content = Self::format_report(repo, command, &context);
+ // Render the profile once from `trace.jsonl`; the markdown bundle
+ // inlines it as its lead section.
+ let profile = crate::log_files::TRACE_JSONL
+ .path()
+ .and_then(|path| std::fs::read_to_string(&path).ok())
+ .as_deref()
+ .and_then(render_trace_profile);
+ let content = Self::format_report(repo, command, &context, profile.as_deref());
Self { content }
}
/// Format the complete diagnostic report as markdown using minijinja template.
- fn format_report(repo: &Repository, command: &str, context: &str) -> String {
+ fn format_report(
+ repo: &Repository,
+ command: &str,
+ context: &str,
+ performance_profile: Option<&str>,
+ ) -> String {
// Strip ANSI codes from context - the diagnostic is a markdown file for GitHub
let context = context.ansi_strip();
@@ -181,13 +198,6 @@ impl DiagnosticReport {
.as_deref()
.map(|content| truncate_log(content.trim()))
.filter(|s| !s.is_empty());
- // The profile is derived from the machine `trace.jsonl` (the human
- // `trace.log` inlined above is no longer parseable).
- let performance_profile = crate::log_files::TRACE_JSONL
- .path()
- .and_then(|path| std::fs::read_to_string(&path).ok())
- .as_deref()
- .and_then(render_trace_profile);
// Forward slashes on both platforms so the rendered markdown reads the
// same in bug reports regardless of where it was produced.
let subprocess_log_path = crate::log_files::SUBPROCESS
@@ -284,16 +294,38 @@ pub(crate) fn write_if_verbose(verbose: u8, command_line: &str, error_msg: Optio
None => "Command completed successfully".to_string(),
};
- // Collect and write diagnostic
+ // Collect and write the diagnostic bundle. It leads with the performance
+ // profile and inlines a (truncated) `trace.log`, so `diagnostic.md` is the
+ // human-facing doc — the headline names what it captured. The raw
+ // companions it doesn't carry in full (`trace.jsonl` machine source,
+ // `subprocess.log` uncapped bodies) are listed beneath it.
let report = DiagnosticReport::collect(&repo, command_line, context);
+
match report.write_diagnostic_file(&repo) {
Some(path) => {
let path_display = format_path_for_display(&path);
eprintln!(
"{}",
- success_message(format!("Diagnostic saved @ {path_display}"))
+ info_message(format!(
+ "Logs, performance profile, and diagnostics saved @ {path_display}"
+ ))
);
+ // The raw companions diagnostic.md doesn't carry in full, when their
+ // sinks opened; `trace.log` and the profile are omitted because the
+ // bundle already inlines them.
+ let companions: Vec<String> = [
+ crate::log_files::TRACE_JSONL.path(),
+ crate::log_files::SUBPROCESS.path(),
+ ]
+ .into_iter()
+ .flatten()
+ .map(|p| format_path_for_display(&p))
+ .collect();
+ if !companions.is_empty() {
+ eprintln!("{}", format_with_gutter(&companions.join("\n"), None));
+ }
+
// Only show gh command if gh is installed
if is_gh_installed() {
let path_str = format_path_for_display(&path);
diff --git a/src/logging.rs b/src/logging.rs
index 8d9276efd..b3a50d9fe 100644
--- a/src/logging.rs
+++ b/src/logging.rs
@@ -47,7 +47,7 @@ use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::registry::LookupSpan;
use tracing_subscriber::util::SubscriberInitExt;
use worktrunk::shell_exec::{SUBPROCESS_BOUNDED_TARGET, SUBPROCESS_FULL_TARGET};
-use worktrunk::styling::{eprintln, format_with_gutter, info_message};
+use worktrunk::styling::{eprintln, info_message};
use worktrunk::trace::{WT_TRACE_TARGET, now_us, thread_id};
use worktrunk::utils::escape_controls;
@@ -698,53 +698,31 @@ where
Some(layer)
}
-/// Print a stderr pointer at `-vv` so users know where the noisy log
-/// pipeline output went — an info header over a gutter that lists each
-/// file's full path on its own line, so any one can be copied without
-/// joining a shared root to a filename. Silent if `trace.log` couldn't be
-/// opened (outside a git repo, permission error) — there's nothing
+/// Print a one-line stderr pointer at `-vv` to the log directory, so users
+/// know where the noisy log pipeline output went. Silent if `trace.log`
+/// couldn't be opened (outside a git repo, permission error) — there's nothing
/// meaningful to point at.
+///
+/// Only the directory is named here, not the individual files: at init the
+/// streamed sinks (`trace.log`, `trace.jsonl`, `subprocess.log`) exist but the
+/// derived reports don't (`diagnostic.md` is written at exit), so the directory
+/// is the one stable anchor. The end-of-run announcement (`write_if_verbose`)
+/// owns the per-file story — it points at `diagnostic.md`, the single
+/// human-facing doc.
fn announce_trace_destination() {
- // TRACE and SUBPROCESS open independently — `LogSink::init` succeeds per
- // file. The (Some, None) case (trace.log open, subprocess.log failed) is
- // rare but real (path-type mismatch, fs quota); the reverse is possible
- // too, but the pointer is anchored on trace.log's path (we derive the logs
- // dir from it below) and subprocess.log's uncapped raw bodies aren't worth
- // surfacing on their own, so we stay silent there. `diagnostic.md` is named
- // even though it's written
- // at exit (not init) — by the time the user reads the pointer and looks
- // for files, all three will be there.
let Some(trace_path) = log_files::TRACE.path() else {
return;
};
// trace.log is always at `<git>/wt/logs/trace.log` (see `log_files::try_create`),
// so the parent is structurally guaranteed.
let dir = trace_path.parent().expect("trace.log path has a parent");
-
- // subprocess.log opening or not decides two things at once: whether it
- // joins the gutter list, and whether the header flags it as unavailable.
- // Keeping the "unavailable" note in the header leaves the gutter a clean
- // list of live, copy-pasteable paths.
- let mut paths = vec![dir.join("trace.log")];
- if log_files::TRACE_JSONL.path().is_some() {
- paths.push(dir.join("trace.jsonl"));
- }
- let header = match log_files::SUBPROCESS.path() {
- Some(_) => {
- paths.push(dir.join("subprocess.log"));
- "Writing to:"
- }
- None => "Writing to (subprocess.log unavailable):",
- };
- paths.push(dir.join("diagnostic.md"));
-
- let gutter = paths
- .iter()
- .map(|p| worktrunk::path::format_path_for_display(p))
- .collect::<Vec<_>>()
- .join("\n");
- eprintln!("{}", info_message(header));
- eprintln!("{}", format_with_gutter(&gutter, None));
+ // `format_path_for_display` emits forward slashes on every platform; the
+ // trailing slash marks the path as a directory.
+ let dir_display = worktrunk::path::format_path_for_display(dir);
+ eprintln!(
+ "{}",
+ info_message(format!("Verbose logging to {dir_display}/"))
+ );
}
#[cfg(test)]
diff --git a/src/trace/profile.rs b/src/trace/profile.rs
index ae4720d65..9abed8612 100644
--- a/src/trace/profile.rs
+++ b/src/trace/profile.rs
@@ -35,9 +35,9 @@ use crate::styling::format_heading;
use super::{TraceEntry, TraceEntryKind, TraceResult};
/// How many individual calls [`Profile::slowest`] retains.
-const SLOWEST_LIMIT: usize = 8;
+const SLOWEST_LIMIT: usize = 20;
/// How many cache offenders the text summary lists before collapsing the rest.
-const CACHE_OFFENDER_LIMIT: usize = 3;
+const CACHE_OFFENDER_LIMIT: usize = 10;
// Milestone event strings emitted by the `wt list` / picker collect pipeline
// (`src/commands/list/collect/mod.rs`). These literals must match the emit
@@ -1205,32 +1205,39 @@ mod tests {
start_time_us: None,
thread_id: None,
};
- // Four duplicated commands (waste aaa>bbb>ccc>ddd); ddd spans two
- // contexts. Ten calls total, so the eight-deep slowest list truncates.
- let entries = vec![
- dup("git aaa", "w1", 9_000),
- dup("git aaa", "w1", 8_000),
- dup("git bbb", "w1", 7_000),
- dup("git bbb", "w1", 6_000),
- dup("git ccc", "w1", 5_000),
- dup("git ccc", "w1", 4_000),
- dup("git ddd", "w1", 3_000),
- dup("git ddd", "w1", 2_000),
- dup("git ddd", "w2", 1_500),
- dup("git ddd", "w2", 1_000),
- ];
+ // More distinct commands than either limit, each run twice in one
+ // context so every command is both a slow call and a same-context
+ // duplicate: 24 single-context commands plus one (`git xctx`)
+ // duplicated across two contexts = 25 offenders. The 50 slow calls
+ // truncate to SLOWEST_LIMIT (20); the 25 offenders collapse to
+ // CACHE_OFFENDER_LIMIT (10) with "… and N more". Durations strictly
+ // decrease with index for deterministic ordering.
+ let mut entries = Vec::new();
+ for i in 0..24u64 {
+ let command = format!("git cmd{i:02}");
+ let base = (50 - i) * 1_000;
+ entries.push(dup(&command, "w1", base));
+ entries.push(dup(&command, "w1", base - 100));
+ }
+ // One command across two contexts exercises the per-context sort; its
+ // durations are the smallest, so it lands in the collapsed tail.
+ entries.push(dup("git xctx", "w1", 2_000));
+ entries.push(dup("git xctx", "w1", 1_800));
+ entries.push(dup("git xctx", "w2", 1_500));
+ entries.push(dup("git xctx", "w2", 1_000));
+
let profile = Profile::from_entries(&entries);
assert_eq!(profile.slowest.len(), SLOWEST_LIMIT);
- assert_eq!(profile.cache.same_context_duplicates.len(), 4);
- // ddd's contexts sort by total time: w1 (5ms) before w2 (2.5ms).
- let ddd = profile
+ assert_eq!(profile.cache.same_context_duplicates.len(), 25);
+ // xctx's contexts sort by total time: w1 (3.8ms) before w2 (2.5ms).
+ let xctx = profile
.cache
.same_context_duplicates
.iter()
- .find(|d| d.command == "git ddd")
+ .find(|d| d.command == "git xctx")
.unwrap();
assert_eq!(
- ddd.contexts
+ xctx.contexts
.iter()
.map(|c| c.context.as_str())
.collect::<Vec<_>>(),
diff --git a/src/trace/snapshots/worktrunk__trace__profile__tests__truncates_slowest_and_collapses_cache.snap b/src/trace/snapshots/worktrunk__trace__profile__tests__truncates_slowest_and_collapses_cache.snap
index 30784132e..b53da56f9 100644
--- a/src/trace/snapshots/worktrunk__trace__profile__tests__truncates_slowest_and_collapses_cache.snap
+++ b/src/trace/snapshots/worktrunk__trace__profile__tests__truncates_slowest_and_collapses_cache.snap
@@ -3,28 +3,45 @@ source: src/trace/profile.rs
expression: "plain(profile.render_text(\"trace.log\"))"
---
PERFORMANCE PROFILE @ trace.log
- 10 subprocesses · 46.50ms subprocess time · parallelism n/a · peak n/a
+ 52 subprocesses · 1851.90ms subprocess time · parallelism n/a · peak n/a
BY COMMAND TYPE
- command count total max avg
- git aaa 2 17.00ms 9.00ms 8.50ms
- git bbb 2 13.00ms 7.00ms 6.50ms
- git ccc 2 9.00ms 5.00ms 4.50ms
- git ddd 4 7.50ms 3.00ms 1.88ms
+ command count total max avg
+ git 48 1845.60ms 50.00ms 38.45ms
+ git xctx 4 6.30ms 2.00ms 1.57ms
SLOWEST CALLS
- 9.00ms git aaa [w1]
- 8.00ms git aaa [w1]
- 7.00ms git bbb [w1]
- 6.00ms git bbb [w1]
- 5.00ms git ccc [w1]
- 4.00ms git ccc [w1]
- 3.00ms git ddd [w1]
- 2.00ms git ddd [w1]
+ 50.00ms git cmd00 [w1]
+ 49.90ms git cmd00 [w1]
+ 49.00ms git cmd01 [w1]
+ 48.90ms git cmd01 [w1]
+ 48.00ms git cmd02 [w1]
+ 47.90ms git cmd02 [w1]
+ 47.00ms git cmd03 [w1]
+ 46.90ms git cmd03 [w1]
+ 46.00ms git cmd04 [w1]
+ 45.90ms git cmd04 [w1]
+ 45.00ms git cmd05 [w1]
+ 44.90ms git cmd05 [w1]
+ 44.00ms git cmd06 [w1]
+ 43.90ms git cmd06 [w1]
+ 43.00ms git cmd07 [w1]
+ 42.90ms git cmd07 [w1]
+ 42.00ms git cmd08 [w1]
+ 41.90ms git cmd08 [w1]
+ 41.00ms git cmd09 [w1]
+ 40.90ms git cmd09 [w1]
CACHE
- 5 duplicate calls wasting ~21.00ms (same context, slowest run kept)
- 8.00ms git aaa (×2)
- 6.00ms git bbb (×2)
- 4.00ms git ccc (×2)
- … and 1 more command
+ 26 duplicate calls wasting ~924.40ms (same context, slowest run kept)
+ 49.90ms git cmd00 (×2)
+ 48.90ms git cmd01 (×2)
+ 47.90ms git cmd02 (×2)
+ 46.90ms git cmd03 (×2)
+ 45.90ms git cmd04 (×2)
+ 44.90ms git cmd05 (×2)
+ 43.90ms git cmd06 (×2)
+ 42.90ms git cmd07 (×2)
+ 41.90ms git cmd08 (×2)
+ 40.90ms git cmd09 (×2)
+ … and 15 more commands
diff --git a/tests/integration_tests/config_state.rs b/tests/integration_tests/config_state.rs
index 52990cfe3..e49b17ab0 100644
--- a/tests/integration_tests/config_state.rs
+++ b/tests/integration_tests/config_state.rs
@@ -3070,7 +3070,7 @@ fn test_format_rejected_on_write_action_writes_verbose_diagnostic(repo: TestRepo
"stderr should include the clap conflict: {stderr}"
);
assert!(
- stderr.contains("Diagnostic saved"),
+ stderr.contains("performance profile, and diagnostics saved"),
"stderr should mention the verbose diagnostic: {stderr}"
);
diff --git a/tests/integration_tests/diagnostic.rs b/tests/integration_tests/diagnostic.rs
index 476635af9..2bfcf9f6d 100644
--- a/tests/integration_tests/diagnostic.rs
+++ b/tests/integration_tests/diagnostic.rs
@@ -11,7 +11,8 @@
//! - `test_diagnostic_contains_required_sections`: All sections present
//! - `test_diagnostic_context_has_no_ansi_codes`: ANSI stripped for GitHub
//! - `test_diagnostic_trace_log_contains_git_commands`: Log has useful data
-//! - `test_diagnostic_saved_message_with_vv`: Output shows "Diagnostic saved" with -vv
+//! - `test_diagnostic_saved_message_with_vv`: -vv announces the saved report and its raw companions
+//! - `test_diagnostic_leads_with_profile`: Profile is the bundle's first section
//! - `test_diagnostic_written_to_correct_location`: File in .git/wt/logs/
//! - `test_diagnostic_gh_hint_with_vv`: Hint shows gist and issue URL when gh installed
@@ -89,7 +90,7 @@ fn test_diagnostic_report_file_format(mut repo: TestRepo) {
// Verify the stderr mentions the diagnostic was saved
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
- stderr.contains("Diagnostic saved"),
+ stderr.contains("performance profile, and diagnostics saved"),
"Output should mention diagnostic was saved. stderr: {}",
stderr
);
@@ -268,7 +269,10 @@ fn test_diagnostic_trace_log_contains_git_commands(mut repo: TestRepo) {
);
}
-/// Diagnostic is saved with -vv and output mentions it.
+/// The `-vv` end block names what the run captured (headline mentions the
+/// performance profile) and lists the raw companions `diagnostic.md` doesn't
+/// inline — `trace.jsonl` and `subprocess.log` — while omitting the files it
+/// does carry (`trace.log`, and there's no `profile.txt`).
#[rstest]
fn test_diagnostic_saved_message_with_vv(mut repo: TestRepo) {
repo.add_worktree("feature");
@@ -278,11 +282,20 @@ fn test_diagnostic_saved_message_with_vv(mut repo: TestRepo) {
let stderr = String::from_utf8_lossy(&output.stderr);
- // Verify diagnostic was saved
+ // Headline names the profile and the diagnostic bundle.
assert!(
- stderr.contains("Diagnostic saved"),
- "Should mention diagnostic was saved. stderr: {}",
- stderr
+ stderr.contains("performance profile, and diagnostics saved"),
+ "end block should name what was captured. stderr: {stderr}"
+ );
+ // The non-duplicative raw companions are pointed at.
+ assert!(
+ stderr.contains("wt/logs/trace.jsonl") && stderr.contains("wt/logs/subprocess.log"),
+ "end block should list the raw companions diagnostic.md doesn't inline: {stderr}"
+ );
+ // Files whose content the bundle already carries are not re-listed.
+ assert!(
+ !stderr.contains("wt/logs/trace.log") && !stderr.contains("profile.txt"),
+ "end block should not list files inlined in the bundle: {stderr}"
);
}
@@ -337,6 +350,46 @@ fn test_log_files_created(mut repo: TestRepo) {
);
}
+/// At `-vv` the performance profile is the diagnostic bundle's lead section —
+/// promoted above the raw Environment/Worktrees/Config dumps — and there is no
+/// standalone `profile.txt` (the bundle is the single human-facing doc).
+#[rstest]
+fn test_diagnostic_leads_with_profile(repo: TestRepo) {
+ let output = repo.wt_command().args(["list", "-vv"]).output().unwrap();
+
+ let logs_dir = repo.root_path().join(".git").join("wt/logs");
+
+ // The standalone profile.txt is gone — the profile lives in the bundle.
+ assert!(
+ !logs_dir.join("profile.txt").exists(),
+ "profile.txt should not be written; the profile rides inside diagnostic.md"
+ );
+
+ // The bundle leads with the profile: its section precedes Environment.
+ let content = fs::read_to_string(logs_dir.join("diagnostic.md")).unwrap();
+ let profile_at = content
+ .find("<summary>Performance profile</summary>")
+ .expect("diagnostic.md should contain the performance profile section");
+ let env_at = content
+ .find("<summary>Environment</summary>")
+ .expect("diagnostic.md should contain the Environment section");
+ assert!(
+ profile_at < env_at,
+ "profile section should precede Environment in diagnostic.md: {content}"
+ );
+
+ // The profile is no longer announced separately — only diagnostic.md is.
+ let stderr = String::from_utf8_lossy(&output.stderr);
+ assert!(
+ !stderr.contains("Performance profile saved"),
+ "the profile is folded into diagnostic.md, not announced separately: {stderr}"
+ );
+ assert!(
+ stderr.contains("performance profile, and diagnostics saved"),
+ "stderr should announce the diagnostic bundle. stderr: {stderr}"
+ );
+}
+
/// At `-vv`, the full (uncapped) subprocess stdout/stderr should land in
/// `subprocess.log` via `shell_exec::SUBPROCESS_FULL_TARGET` — not in `trace.log`.
/// `trace.log` gets the bounded preview alongside trace records.
@@ -554,20 +607,12 @@ fn test_vv_debug_pipeline_silent_on_stderr(repo: TestRepo) {
"trace.log should contain humanized trace records at -vv"
);
- // Stderr at -vv should announce each file's full path on its own line, so
- // any one is copy-pasteable without joining a shared root to a filename.
- // The `wt/logs/<file>` tails only appear contiguously when the full path
- // is listed (the old root-plus-filenames form split them apart).
+ // Stderr at -vv opens with a one-line pointer to the log directory (the
+ // per-file rundown is deferred to the end-of-run diagnostic announcement).
assert!(
- stderr.contains("Writing to"),
- "missing pointer header: {stderr}"
+ stderr.contains("Verbose logging to") && stderr.contains("wt/logs"),
+ "stderr should point at the log directory at startup: {stderr}"
);
- for file in ["trace.log", "subprocess.log", "diagnostic.md"] {
- assert!(
- stderr.contains(&format!("wt/logs/{file}")),
- "stderr should list the full path to {file}: {stderr}"
- );
- }
}
/// `RUST_LOG` is honored at every verbosity level — including `-v` — and
@@ -751,7 +796,7 @@ fn test_vv_writes_diagnostic_on_success(repo: TestRepo) {
// stderr should mention diagnostic was saved
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
- stderr.contains("Diagnostic saved"),
+ stderr.contains("performance profile, and diagnostics saved"),
"stderr should mention diagnostic was saved. stderr: {}",
stderr
);
@@ -780,16 +825,16 @@ fn test_vv_writes_diagnostic_on_error(mut repo: TestRepo) {
// stderr should mention diagnostic was saved
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
- stderr.contains("Diagnostic saved"),
+ stderr.contains("performance profile, and diagnostics saved"),
"stderr should mention diagnostic was saved. stderr: {}",
stderr
);
}
-/// If one of the `-vv` log files can't be opened (here: pre-existing path
-/// of the wrong type), the user still gets a "Writing to ..." pointer for
-/// the one that opened, and the elision marker reflects the asymmetric
-/// state instead of telling a `-vv` user to "rerun with -vv".
+/// If one of the `-vv` log files can't be opened (here: subprocess.log's path
+/// is occupied by a directory), the startup pointer still appears — it's
+/// anchored on the log directory, which trace.log's open makes available — and
+/// trace.log is still written.
#[rstest]
fn test_vv_pointer_handles_split_init(repo: TestRepo) {
let logs_dir = repo.root_path().join(".git").join("wt/logs");
@@ -806,27 +851,25 @@ fn test_vv_pointer_handles_split_init(repo: TestRepo) {
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
- stderr.contains("Writing to") && stderr.contains("wt/logs/trace.log"),
- "stderr should list trace.log's full path even when subprocess.log can't open: {stderr}"
- );
- assert!(
- stderr.contains("subprocess.log unavailable"),
- "stderr should note subprocess.log is unavailable: {stderr}"
- );
- // subprocess.log didn't open, so it's named only in the unavailable note —
- // never listed as a live path in the gutter.
- assert!(
- !stderr.contains("wt/logs/subprocess.log"),
- "stderr should not list a path for the unavailable subprocess.log: {stderr}"
+ stderr.contains("Verbose logging to") && stderr.contains("wt/logs"),
+ "startup pointer should still name the log directory when subprocess.log can't open: {stderr}"
);
assert!(
logs_dir.join("trace.log").exists(),
"trace.log should still be created"
);
+ // The end-of-run companion list surfaces the surviving raw file and drops
+ // subprocess.log, whose sink failed to open (`SUBPROCESS.path()` → None,
+ // filtered out by the `.flatten()` in `write_if_verbose`).
+ assert!(
+ stderr.contains("wt/logs/trace.jsonl") && !stderr.contains("wt/logs/subprocess.log"),
+ "end block should list the surviving companion and omit the failed subprocess.log: {stderr}"
+ );
}
/// With just -v, info-level logging goes to stderr but no log files are written.
-/// `-vv` is the threshold for `trace.log`, `subprocess.log`, and `diagnostic.md`.
+/// `-vv` is the threshold for `trace.log`, `trace.jsonl`, `subprocess.log`, and
+/// `diagnostic.md`.
#[rstest]
fn test_v_does_not_write_log_files(repo: TestRepo) {
// Run a successful command with just -v
@@ -836,7 +879,12 @@ fn test_v_does_not_write_log_files(repo: TestRepo) {
// None of the -vv diagnostic files should exist with just -v
let wt_logs = repo.root_path().join(".git").join("wt/logs");
- for name in ["diagnostic.md", "trace.log", "subprocess.log"] {
+ for name in [
+ "diagnostic.md",
+ "trace.log",
+ "trace.jsonl",
+ "subprocess.log",
+ ] {
assert!(
!wt_logs.join(name).exists(),
"{name} should NOT be created with just -v (requires -vv)"
@@ -885,7 +933,7 @@ fn test_vv_outside_repo_no_crash() {
// announce_trace_destination took its early-return path.
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
- !stderr.contains("Writing to"),
+ !stderr.contains("Verbose logging to"),
"no startup pointer when trace.log can't open: {stderr}"
);
}
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 ab13625b6..d965a9b05 100644
--- a/tests/snapshots/integration__integration_tests__diagnostic__diagnostic_file_format.snap
+++ b/tests/snapshots/integration__integration_tests__diagnostic__diagnostic_file_format.snap
@@ -8,6 +8,12 @@ expression: normalize_report(&content)
**Command:** `[PROJECT_ROOT]/target/[BUILD_MODE]/wt list -vv`
**Result:** Command completed successfully
+<details open>
+<summary>Performance profile</summary>
+
+[PERFORMANCE_PROFILE_CONTENT]
+</details>
+
<details>
<summary>Environment</summary>
@@ -56,12 +62,6 @@ Project config: _REPO_/.config/wt.toml
```
</details>
-<details>
-<summary>Performance profile</summary>
-
-[PERFORMANCE_PROFILE_CONTENT]
-</details>
-
<details>
<summary>Trace log</summary>
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_state_logs.snap b/tests/snapshots/integration__integration_tests__help__help_config_state_logs.snap
index 566495777..3ee893970 100644
--- a/tests/snapshots/integration__integration_tests__help__help_config_state_logs.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_config_state_logs.snap
@@ -109,7 +109,7 @@ All post-* hooks (post-start, post-switch, post-commit, post-merge) run
diagnostic.md Running with -vv
trace.log is the human-readable trace at -vv — each command's start ($ …) and completion (✓/✗ … 12.3ms), in-process spans, milestones, and bounded subprocess previews. trace.jsonl is the same event stream as one JSON object per line, for machines (jq, chrome://tracing); wt config state logs profile reads it to summarize a performance report (where time went, parallelism, redundant commands). subprocess.log holds the raw uncapped subprocess stdout/stderr bodies. diagnostic.md is a markdown
-bug-report bundle that inlines trace.log and a rendered performance profile; wt prints a gh gist create command pointing at it. All four are overwritten on each -vv run.
+bug-report bundle that leads with that same performance profile and inlines trace.log; wt prints a gh gist create command pointing at it. All four are overwritten on each -vv run.
Location