Skip to content

refactor(log): route -vv log pipeline to trace.log instead of stderr - #2892

Merged
max-sixty merged 5 commits into
mainfrom
wsw-v
May 25, 2026
Merged

max-sixty merged 5 commits into
mainfrom
wsw-v

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Motivation

wt … -vv produced ~15K lines of stderr per invocation — unreadable in scrollback, forced redirect to a file, at which point the parallel trace.log mirror introduced by #2201 was redundant noise. The earlier split (#2201) only file-routed the uncapped raw subprocess bodies (SUBPROCESS_FULL_TARGET); everything else — $ cmd headers, [wt-trace] spans, bounded subprocess previews — stayed on stderr.

Change

At -vv, the log::* pipeline routes to .git/wt/logs/trace.log instead of stderr. A one-line startup pointer on stderr tells the user where it went:

○ Tracing to ~/.../trace.log (raw subprocess output @ ~/.../output.log)

User-facing eprintln! output (status messages, template expansions, hints) is unaffected — it stays on stderr at every verbosity level. This change governs only the log::* macro pipeline.

-v is unchanged (Info on stderr, no file). RUST_LOG=debug without -vv is unchanged (Debug on stderr, no file — the documented fallback from #2201).

Result on wt list -vv: stderr 15K → 3 lines. trace.log gets the full ~1K-line debug trace as before.

Implementation notes for review

  • src/log_files.rs::route() is now the only place that picks the sink. Non-FULL targets go to File(&TRACE) when TRACE.is_active(), else Stderr. Format closure in src/main.rs simplified to a match route — no more "mirror to TRACE then write to stderr" branch.
  • Repository::current() is primed before env_logger.init() so the rev-parse fired by log_files::init is a memory-cache hit. Records emitted during priming go to a not-yet-installed logger and are dropped — robust against future Repository::current emissions. A Ctrl-C during the ~5ms priming window can leak one $ git rev-parse line; documented inline, cheaper than violating "all commands through Cmd".
  • announce_trace_destination() handles the rare split-init case where output.log open fails (path-type mismatch, fs quota) but trace.log succeeds — partial pointer + "output.log unavailable" hint. New regression test test_vv_pointer_handles_split_init reproduces the failure with a pre-existing directory at the output.log path.
  • SUBPROCESS_TERMINAL_TARGET → SUBPROCESS_BOUNDED_TARGET. The "terminal-safe" framing no longer fits now that the bounded preview lives in trace.log rather than stderr.
  • diagnostic.md doc cutover: three surfaces (src/diagnostic.rs, src/cli/config.rs, docs/content/faq.md) still claimed "written when warnings occur" — the code has no warning gate and writes on every -vv. Docs cut over to match reality.

Deferred follow-ups

Surfaced during review but out of scope here:

  • Unify trace.log + output.log — the bounded preview at -vv duplicates a subset of output.log's uncapped bytes. The dual-file design was explicitly approved for this PR; a follow-up could collapse them with diagnostic.md doing the bounding at extraction time.
  • RUST_LOG precedence at -v — pre-existing: -v 0 honors RUST_LOG, -v and -vv hardcode the level. Needs a policy decision (always-honor / always-ignore / merge) more than a cleanup.
  • tracing crate migration — deserves its own dedicated PR with [wt-trace] migration as the headline.

Tests

3822 tests pass (+1 regression). Notable changes:

  • test_vv_bounded_on_stderr_full_in_output_log → test_vv_log_pipeline_silent_on_stderr — inverted assertions (marker must NOT appear on stderr; must appear in trace.log). Added a stderr-pointer presence check.
  • test_vv_pointer_handles_split_init — new; reproduces the split-init asymmetry by creating a directory at output.log's path, asserts the partial pointer fires and trace.log still works.

This was written by Claude Code on behalf of max-sixty

max-sixty and others added 2 commits May 24, 2026 16:14
Debug logs written with `wt … -vv 2>x.log` contain branch names that
typos flags as misspellings (e.g. `2b8d8abd16` → "abd should be and/bad").
Excluding `*.log` keeps the working tree clean of those false positives.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
At -vv, the noisy `log::*` records ($ cmd headers, [wt-trace] spans,
bounded subprocess previews) now write to `.git/wt/logs/trace.log`
instead of stderr. A single startup line on stderr tells the user
where the trace went; user-facing `eprintln!` output (status, hints,
template expansions) is unaffected. -v and `RUST_LOG=debug` without
-vv are unchanged.

Result: stderr at -vv shrinks from ~15K lines to 3 for a typical
`wt list` — making the terminal usable while preserving the full
trace on disk for bug reports.

Implementation:
- `log_files::route()` returns `File(&TRACE)` for non-FULL targets when
  TRACE is active; format closure simplified to a `match route`, no
  more mirror branch.
- `Repository::current()` is primed before env_logger registers so the
  rev-parse fired by `log_files::init` is a cache hit (no leaking
  records).
- New `announce_trace_destination()` prints the pointer; handles the
  rare split-init case where `output.log` fails to open while
  `trace.log` succeeds (regression test added).
- `SUBPROCESS_TERMINAL_TARGET` renamed to `SUBPROCESS_BOUNDED_TARGET`
  now that the "terminal-safe" framing no longer fits.
- `diagnostic.md` is written on every -vv run (docs claimed "when
  warnings occur" but the code has no warning gate); doc cutover
  across 3 surfaces.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
worktrunk-bot
worktrunk-bot previously approved these changes May 24, 2026

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

codecov/patch failed — src/main.rs patch coverage is 88.23% (4 lines missed).

Two gaps:

1. init_logging format closure (lines 1322–1325) — the Route::Stderr arm's else branch when a $ cmd line has no [worktree-context] suffix. That happens under RUST_LOG=debug without -vv when a Cmd runs without .context() set (e.g. standalone gh / glab calls). Existing test_rust_log_debug_fallback_without_vv only exercises wt list, whose git calls all carry context, so the no-context branch never fires.

2. announce_trace_destination (line 1359, the body after let Some(trace_path) = … else { return; };) — the early-return when TRACE.path() is None. The docstring claims this is the "outside a git repo, permission error" path, but test_vv_outside_repo_no_crash runs wt --version -vv, and maybe_handle_help_with_pager exits the process before init_logging is ever called, so the early-return is never exercised. To cover it, a test would need a non-version/help command at -vv from a non-repo cwd — e.g. wt list -vv in a tempdir (where it errors but announce_trace_destination still gets a chance to run silently).

@worktrunk-bot
worktrunk-bot dismissed their stale review May 24, 2026 23:29

codecov/patch failed — see follow-up review for analysis

max-sixty and others added 3 commits May 24, 2026 16:33
Both arms of the match were nearly identical writeln! calls — pull the
split into a tuple-returning match so there's one writeln!, one cformat!.
Also closes patch coverage on the no-`[ctx]` case (standalone tools like
`gh` / `glab` emit `$ gh ...` with no worktree bracket).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
The existing `test_vv_outside_repo_no_crash` used `wt --version -vv`,
which clap short-circuits before `init_logging` runs — so the
`announce_trace_destination` early-return branch (TRACE.path() is None)
was never exercised. Switching to `wt list -vv` (which fails inside the
command but still runs init_logging) covers that path and adds an
explicit assertion that the startup pointer doesn't fire when trace.log
can't open.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
worktrunk-bot
worktrunk-bot previously approved these changes May 25, 2026

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

codecov/patch failed — one missed line in src/main.rs, line 1316 (the opening writeln!( token of the Stderr route's $ arm).

Looks like an LLVM macro-attribution artifact rather than a real gap:

line code state
1314 None => (rest, ""), (no-[ctx] arm) hit
1315 }; hit
1316 writeln!( miss
1318 "{}", hit
1319 cformat!("<dim>[{thread_num}]</> $ <bold>{command}</>{worktree}") hit
1323 writeln!(buf, "{}", cformat!("<dim>[{thread_num}]</> <red>{msg}</>")) (single line) hit

If the writeln! weren't reached, lines 1318–1319 (its arguments) couldn't be hit either. The same writeln! flattened to one line (1323) is hit. The miss is the opening multi-line macro token — codecov/llvm-cov can attribute multi-line macro invocations oddly.

Dismissing my approval per CLAUDE.md's "never merge with failing codecov/patch without explicit user approval" rule. If you read this as a false positive (I think it is), re-approve and merge — no code change is needed.

Separately, test (linux) failed at the GitHub Actions cache restore step (HTTP 502 retries before tests ran); test (macos) and test (windows) succeeded. Unrelated to the patch.

@worktrunk-bot
worktrunk-bot dismissed their stale review May 25, 2026 00:19

codecov/patch failed — see review comment for analysis

@max-sixty
max-sixty merged commit a50785f into main May 25, 2026
47 of 50 checks passed
@max-sixty
max-sixty deleted the wsw-v branch May 25, 2026 06:26
max-sixty added a commit that referenced this pull request May 26, 2026
… on stderr (#2913)

## Motivation

The `-v` / `-vv` UX had three small issues that compounded:

1. **`output.log` is misnamed.** It holds the *uncapped raw
stdout/stderr of every subprocess `wt` spawns* — multi-MB possible (`git
log -p`, patch-id pipelines, etc.). "output" reads as "stuff `wt`
printed" — the small thing — when it's actually the big thing. Easy to
misread.
2. **`-vv` went fully dark on stderr.** PR #2892 moved the noisy debug
pipeline to files at `-vv`; in the process, the stderr layer was
disabled entirely. Users running `-vv` to see hook output (info-level,
which `-v` shows on stderr) suddenly couldn't.
3. **`-v` help text was a 150-char one-liner** packed into a
parenthetical, and the surrounding docs leaned on a "stderr stays
readable / `log::*` pipeline" framing that was Rust-jargon-flavored and
implied stderr-quiet at `-vv` — which is no longer true after change #2.

## Change

- **Rename `output.log` → `subprocess.log`.** Filename now matches
content. `OUTPUT` static → `SUBPROCESS`, plus the related
`OutputMakeWriter` / `OutputFileFormat` / `build_output_layer` symbol
renames.
- **`-vv` keeps the Info baseline on stderr.** `build_stderr_layer` no
longer returns `None` at `-vv`; debug-level records still route to file
layers only, so the terminal stays readable while info-level status
(hook output, template variables, the `Tracing to ...` pointer) shows
the same as at `-v`.
- **`-v` help text rewritten** to describe both levels cleanly without a
wall of detail.
- **`docs/content/faq.md` gets a "What does -v / -vv do?" section** with
a three-level table.
- **Docs cleanup**: drop "stderr stays readable" / `log::*` jargon /
"but not subprocess.log" negative framing from user-facing prose.

## Notes for review

- The only `log::info!` site in the codebase is
`commands/picker/mod.rs:389` (a single picker error message), so making
`-vv` show info-level on stderr doesn't add meaningful noise.
- `test_vv_log_pipeline_silent_on_stderr` is renamed to
`test_vv_debug_pipeline_silent_on_stderr` — its assertions only check
debug-level records stay out of stderr (they do); the old name implied
the whole `log::*` pipeline was silent, which was never quite true
(direct `eprintln!` always showed) and is less true now (info-level
routes to stderr).
- 67 of the 69 changed files are snapshot updates (help text and one
diagnostic snapshot) and auto-synced doc/skill mirrors. `git diff --stat
-- 'tests/snapshots/*' 'docs/content/*' 'skills/worktrunk/reference/*' |
tail -1` separates them.
- CHANGELOG: not touched. The historical entry that introduced
`output.log` (`#2201`) stays accurate for its release; this rename gets
a new line in the next release.

## Tests

3870 tests pass. Re-snapshotted all `test_help_*` snapshots, three
`step_alias` snapshots that quote the global help, and the diagnostic
file format snapshot.

> _This was written by Claude Code on behalf of max-sixty_

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
@max-sixty max-sixty mentioned this pull request May 26, 2026
max-sixty added a commit that referenced this pull request May 26, 2026
v0.54.0.

`cargo semver-checks` reports 3 breaking library API changes
(`shell_exec::set_output_log_available` removed,
`SUBPROCESS_TERMINAL_TARGET` removed, `Deprecations::{pre_start,
post_start}` removed) — none of them intentional API, but they force
minor pre-1.0.

Headline user-visible changes:
- New rate-limit pace segment in the Claude Code statusline (#2899,
#2911).
- `wt step prune` streams removals and skips unapproved hooks instead of
prompting mid-scan; default `--min-age` raised 1h → 1d (#2908, #2910,
#2886).
- `-vv` no longer floods stderr — debug routes to `trace.log`, Info
stays on stderr; raw subprocess sink renamed `output.log` →
`subprocess.log`; `RUST_LOG` honored at every verbosity level (#2892,
#2901, #2913).
- Data-safety fixes across merge / remove / prune lifecycle (#2870).
- Legacy shell-wrapper deprecation warning (#2880).

Full CHANGELOG entry in this PR.
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
worktrunk 0.54.0

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## Release Notes

### Improved

- **Rate-limit pace segment in the Claude Code statusline**: `wt list statusline --format=claude-code` now surfaces a yellow `1.3×pace(10am–3pm)` segment when Claude Code's reported five-hour or seven-day rate-limit window is on track to be hit before its reset. The segment uses a Bayesian forecast on `P(final ≥ 100%)` so early-window bursts (e.g., 5% used at 3% elapsed) don't trigger spurious warnings — only the worse-projected of the two windows is shown, and the segment is hidden entirely when both are safe. The clock format inside the parentheses honors `LC_ALL` / `LC_TIME` / `LANG`: `en_US`/`en_PH`/`en_CA` get 12-hour (`10am–3pm`), everything else (including unset and `C`/`POSIX`) gets 24-hour (`10:00–15:00`). ([#2899](max-sixty/worktrunk#2899), [#2911](max-sixty/worktrunk#2911))

- **`wt step prune` streams removals and never prompts mid-scan**: Prune now bundles integration, removability, and age checks into a single parallel pass and starts removing candidates as soon as they qualify, instead of batching the scan and acting at the end. Dirty / locked / primary worktrees drop out before the age check, so a young + dirty + integrated worktree no longer surfaces as `Skipped (younger than 1d)` — the `(younger than X)` message now fires only when the worktree would actually have been pruned. With `--yes`, every project command is auto-approved as before; without `--yes`, a candidate whose hooks include an unapproved project command is SKIPPED with `(approval required)` rather than aborting the scan with an inline prompt the streaming structure couldn't accommodate. The end-of-run hint enumerates the unapproved hook templates from the invoking worktree's config and emits one copy-pasteable `wt -C <path> remove` line per skipped candidate, annotating candidates whose own `.config/wt.toml` differs from the invoking worktree's. ([#2908](max-sixty/worktrunk#2908), [#2910](max-sixty/worktrunk#2910))

- **`wt step prune` default `--min-age` raised from 1h to 1d**: A worktree just created from the default branch looks "merged" because its branch still points at the same commit; a one-day floor keeps an unattended prune from sweeping it up before its owner starts work. Explicit `--min-age=0s` or any other value is unchanged. ([#2886](max-sixty/worktrunk#2886))

- **Legacy shell-wrapper deprecation warning**: Users who upgrade `wt` without restarting their shell still run the previous release's wrapper, which sets only `WORKTRUNK_DIRECTIVE_FILE` instead of the new split `WORKTRUNK_DIRECTIVE_CD_FILE` / `WORKTRUNK_DIRECTIVE_EXEC_FILE` pair. That fallback used to be silent; `wt` now emits a one-shot per-process warning hinting at `wt config shell install`. bash, zsh, fish, and PowerShell pick up the new wrapper on the next shell restart; nushell is the one shell where users must rerun `wt config shell install nu` because its wrapper is a static file. ([#2880](max-sixty/worktrunk#2880))

- **`-vv` no longer floods stderr; raw subprocess sink renamed to `subprocess.log`**: A `-vv` invocation used to spray ~15K lines of stderr per command, forcing a redirect to a file even though `trace.log` already mirrored most of it. The debug-level `log::*` pipeline now writes to `.git/wt/logs/trace.log` at `-vv`; Info-level records (hook output, template expansions, the `Tracing to …` pointer) stay on stderr at every verbosity level. The companion raw-subprocess-bytes file is renamed from `output.log` to `subprocess.log` — the prior name read as "stuff `wt` printed" but actually held uncapped multi-MB subprocess bodies (`git log -p`, patch-id pipelines). `RUST_LOG` is now honored at every verbosity level: `wt -v` and `wt -vv` previously hardcoded Info / Debug and silently dropped any `RUST_LOG` directive (`RUST_LOG=trace wt -vv` was capped at Debug, `RUST_LOG=worktrunk=trace wt -v` was ignored); all three levels now flow through one builder shape with `RUST_LOG` layered on top of the flag baseline. ([#2892](max-sixty/worktrunk#2892), [#2901](max-sixty/worktrunk#2901), [#2913](max-sixty/worktrunk#2913))

### Fixed

- **Data-safety across the worktree merge / remove / prune lifecycle**: Five TOCTOU and scoping fixes. `wt merge` and `wt remove` revalidate cleanliness and branch integration *after* `pre-remove` hooks run, so a hook (or concurrent process) that dirties the worktree or advances the branch can no longer trash the directory or trigger `git branch -D` against the stale pre-hook decision. The background-removal path does the same revalidation and fails closed for submodule worktrees on the fallback path instead of forcing. `wt step prune` runs its rename-failure fallback `git branch -d` synchronously under the write guard for non-current worktrees (no more race against live integration readers on `.git/config`), scopes hook approval to the worktrees it will actually remove (an unrelated unapproved hook can no longer abort a non-interactive prune), and prunes the stale metadata of detached worktrees whose directory was deleted outside Worktrunk. ([#2870](max-sixty/worktrunk#2870))

### Documentation

- **`-v` / `-vv` help and FAQ**: The `-v` help text is split out from its 150-character parenthetical, and `docs/content/faq.md` gains a "What does `-v` / `-vv` do?" section with a three-level table. ([#2913](max-sixty/worktrunk#2913))

- **Hook docs and `pre-start` docstring**: The `pre_create` field docstring in `HooksConfig` (user-visible via generated JSON schema) read "Commands to execute before worktree creation"; `pre-start` actually runs *after* worktree creation, blocking. Restored the correct wording. The `docs/content/extending.md` overview is reworked to read more cleanly: parallel three-paragraph intro for hooks / aliases / custom subcommands, fewer em-dashes, and the Reference section's table no longer duplicates content covered in prose. ([#2879](max-sixty/worktrunk#2879), [#2912](max-sixty/worktrunk#2912))

### Internal

- **Migrated logging from `env_logger` to `tracing-subscriber`**: A layered subscriber routes records structurally by target and verbosity. Existing `log::*` callers are bridged into `tracing` via `tracing_log::LogTracer`. `[wt-trace]` records emit as typed structured fields with a single formatter rendering the wire shape, so the grammar lives in one place instead of being duplicated across every emit site.

- **`UncommittedChanges` error renders dirty files in the canonical gutter**, matching `ConflictingChanges` and the project's `format_with_gutter()` convention. ([#2887](max-sixty/worktrunk#2887))

## Install worktrunk 0.54.0

### Install prebuilt binaries via shell script

```sh
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/max-sixty/worktrunk/releases/download/v0.54.0/worktrunk-installer.sh | sh && wt config shell install
```

### Install prebuilt binaries via powershell script

```sh
powershell -ExecutionPolicy Bypass -c "irm https://github.com/max-sixty/worktrunk/releases/download/v0.54.0/worktrunk-installer.ps1 | iex"; git-wt config shell install
```

### Install prebuilt binaries via Homebrew

```sh
brew install worktrunk && wt config shell install
```

## Download worktrunk 0.54.0

|  File  | Platform | Checksum |
|--------|----------|----------|
| [worktrunk-aarch64-apple-darwin.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.54.0/worktrunk-aarch64-apple-darwin.tar.xz) | Apple Silicon macOS | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.54.0/worktrunk-aarch64-apple-darwin.tar.xz.sha256) |
| [worktrunk-x86_64-apple-darwin.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.54.0/worktrunk-x86_64-apple-darwin.tar.xz) | Intel macOS | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.54.0/worktrunk-x86_64-apple-darwin.tar.xz.sha256) |
| [worktrunk-x86_64-pc-windows-msvc.zip](https://github.com/max-sixty/worktrunk/releases/download/v0.54.0/worktrunk-x86_64-pc-windows-msvc.zip) | x64 Windows | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.54.0/worktrunk-x86_64-pc-windows-msvc.zip.sha256) |
| [worktrunk-aarch64-unknown-linux-musl.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.54.0/worktrunk-aarch64-unknown-linux-musl.tar.xz) | ARM64 MUSL Linux | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.54.0/worktrunk-aarch64-unknown-linux-musl.tar.xz.sha256) |
| [worktrunk-x86_64-unknown-linux-musl.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.54.0/worktrunk-x86_64-unknown-linux-musl.tar.xz) | x64 MUSL Linux | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.54.0/worktrunk-x86_64-unknown-linux-musl.tar.xz.sha256) |



### Install via Cargo

```sh
cargo install worktrunk && wt config shell install
```

### Install via Winget (Windows)

```sh
winget install max-sixty.worktrunk && git-wt config shell install
```

### Install via AUR (Arch Linux)

```sh
paru worktrunk-bin && wt config shell install
```
</pre>
  <p>View the full release notes at <a href="https://github.com/max-sixty/worktrunk/releases/tag/v0.54.0">https://github.com/max-sixty/worktrunk/releases/tag/v0.54.0</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!7938
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants