Skip to content

CLI: Add Reporter for structured CLI output with VT color and level routing#40798

Merged
dkbennett merged 19 commits into
masterfrom
user/dkbennett/reporter
Jun 17, 2026
Merged

CLI: Add Reporter for structured CLI output with VT color and level routing#40798
dkbennett merged 19 commits into
masterfrom
user/dkbennett/reporter

Conversation

@dkbennett

@dkbennett dkbennett commented Jun 13, 2026

Copy link
Copy Markdown
Member

Summary of the Pull Request

Adds a Reporter class for structured, level-aware console output in wslc. Reporter provides a std::format-style API that routes Output to stdout and Info/Warning/Error to stderr, with automatic SGR color wrapping (yellow for warnings, red for errors) and VT sequence stripping when the destination is redirected or color is disabled.

Reporter is backed by OutputChannel, a byte-sink class that owns VT enablement (RAII) on console handles and falls back to fwprintf for redirected output. Each write is a single kernel call (WriteConsoleW or fwprintf) so concurrent threads cannot interleave.

Main.cpp error handling and cancellation output now use Reporter. Other wslc commands can be converted in follow-up PRs.

PR Checklist

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

New files:

  • OutputChannel.h/.cpp — Byte sink: WriteConsoleW for consoles, fwprintf for redirected output. Owns EnableVirtualTerminal RAII. Provides GetConsoleWidth() (minus one column as an autowrap guard).
  • Reporter.h/.cppstd::format-style write API with Output/Info/Warn/Error convenience methods. VT Sequence arguments are automatically stripped when VT is off; color Sequence arguments are additionally stripped when color is disabled. Level-based SGR prefix/reset wrapping for warnings (yellow) and errors (red).
  • WSLCCLIReporterUnitTests.cpp — 20 unit tests covering OutputChannel writes, Reporter formatting, Sequence stripping, color/no-color behavior, level routing, VT state queries, and console width.
  • WSLCCLITestHelpers.hCapturePipe (RAII pipe pair for capturing FILE* output) and CaptureReporter/SplitCaptureReporter test helpers.

Modified files:

  • CLIExecutionContext.h — Holds Reporter as a value member. NON_MOVABLE (Reporter owns non-movable OutputChannels).
  • Main.cpp — Error and cancellation output routed through context.Reporter. Removed standalone EnableVirtualTerminal RAII (now owned by OutputChannel).

Validation Steps Performed

  • 128/128 WSLCCLI unit tests pass (20 Reporter + 108 existing)
  • Manual validation of colored output, redirected output, cancellation, and error formatting
  • Multiple automated code review passes

Copilot AI review requested due to automatic review settings June 13, 2026 01:31
@dkbennett dkbennett requested a review from a team as a code owner June 13, 2026 01:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a new structured output pipeline for the wslc CLI by adding a Reporter abstraction (level-aware output) backed by an OutputWriter/OutputChannel implementation (buffered, atomic flush, optional VT color handling). It integrates the reporter into the CLI execution context and updates Main.cpp error/cancellation reporting to use it, along with unit tests and a new localized cancellation string.

Changes:

  • Added Reporter for level-gated output (Info/Warn/Error/Debug) with VT-aware formatting behavior.
  • Added OutputChannel/OutputWriter for buffered output accumulation and atomic flush semantics with optional color filtering and SGR reset.
  • Integrated reporter into the CLI execution context, updated main cancellation/error paths, added unit tests, and added a new en-US localization string.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/windows/wslc/WSLCCLIReporterUnitTests.cpp Adds unit tests covering routing, VT/color filtering, flush lifecycle, clone semantics, and level gating.
src/windows/wslc/core/Reporter.h Declares the Reporter interface (levels, routing, cloning, console width).
src/windows/wslc/core/Reporter.cpp Implements level gating, formatting selection, and stdout/stderr routing behavior.
src/windows/wslc/core/OutputWriter.h Declares OutputChannel and OutputWriter (buffering + VT/color controls).
src/windows/wslc/core/OutputWriter.cpp Implements buffered flush, VT sequence handling, and OutputChannel console/FILE* backends.
src/windows/wslc/core/Main.cpp Enables VT mode on stdout and switches cancellation/error reporting to use context.Output.
src/windows/wslc/core/CLIExecutionContext.h Adds Reporter Output to the execution context for shared CLI output.
localization/strings/en-US/Resources.resw Adds WSLCCLI_OperationCancelled string for localized cancellation messaging.

Comment thread src/windows/wslc/core/OutputWriter.h Outdated
Comment thread src/windows/wslc/core/OutputWriter.cpp Outdated
Comment thread src/windows/wslc/core/Reporter.cpp Outdated
@dkbennett dkbennett marked this pull request as draft June 13, 2026 01:46
Copilot AI review requested due to automatic review settings June 13, 2026 05:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Comment thread src/windows/wslc/core/Main.cpp Outdated
Comment thread src/windows/wslc/core/Reporter.h Outdated
Comment thread src/windows/wslc/core/Reporter.cpp Outdated
Copilot AI review requested due to automatic review settings June 13, 2026 06:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Comment thread src/windows/wslc/core/OutputWriter.h Outdated
Comment thread src/windows/wslc/core/OutputWriter.cpp Outdated
Copilot AI review requested due to automatic review settings June 13, 2026 06:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Comment thread src/windows/wslc/core/Reporter.h Outdated
Comment thread src/windows/wslc/core/OutputWriter.cpp Outdated
Comment thread src/windows/wslc/core/Reporter.cpp Outdated
Copilot AI review requested due to automatic review settings June 13, 2026 07:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Comment thread src/windows/wslc/core/Reporter.h Outdated
Comment thread src/windows/wslc/core/Reporter.h Outdated
Comment thread test/windows/wslc/WSLCCLIReporterUnitTests.cpp Outdated
Comment thread src/windows/wslc/core/Reporter.cpp Outdated
Comment thread src/windows/wslc/core/OutputWriter.h Outdated
@dkbennett dkbennett force-pushed the user/dkbennett/reporter branch from ff1bee9 to 2d1a14f Compare June 13, 2026 07:32
Copilot AI review requested due to automatic review settings June 13, 2026 08:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

@dkbennett dkbennett marked this pull request as ready for review June 13, 2026 09:35
dkbennett and others added 3 commits June 14, 2026 12:58
- Rename Reporter::GetOutputWriter to GetWriter for brevity; matches
  the level-targeted call sites that follow it.
- Move CapturePipe and CaptureReporter from WSLCCLIReporterUnitTests.cpp
  into WSLCCLITestHelpers.h so other CLI unit test suites can capture
  Reporter output without duplicating the pipe plumbing.
- Fix the read-pipe handle leak in CapturePipe: hold the read end in a
  wil::unique_hfile member (declared before m_reader so destruction order
  joins the reader thread first, then closes the handle).
- Open the read pipe with ReadPipeOverlapped=true so PartialHandleRead's
  InterruptableRead can be interrupted by its exit event during teardown
  rather than relying on writer-side fclose ordering.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 15, 2026 09:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Comment thread test/windows/wslc/WSLCCLITestHelpers.h Outdated
Comment thread src/windows/wslc/core/Reporter.cpp Outdated
Comment thread src/windows/wslc/core/Reporter.cpp Outdated
Comment thread src/windows/wslc/core/Reporter.cpp Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Comment thread src/windows/wslc/core/Reporter.h Outdated
Comment thread test/windows/wslc/WSLCCLIReporterUnitTests.cpp Outdated
@dkbennett dkbennett marked this pull request as ready for review June 16, 2026 10:22
Copilot AI review requested due to automatic review settings June 16, 2026 10:22
@dkbennett dkbennett requested a review from OneBlue June 16, 2026 10:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Comment thread src/windows/wslc/core/Reporter.h
Comment thread src/windows/wslc/core/Main.cpp Outdated
Copilot AI review requested due to automatic review settings June 16, 2026 11:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Comment thread test/windows/wslc/WSLCCLIReporterUnitTests.cpp Outdated
Comment thread src/windows/wslc/core/Reporter.cpp Outdated
Comment thread src/windows/wslc/core/OutputChannel.cpp
Copilot AI review requested due to automatic review settings June 16, 2026 18:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Comment thread test/windows/wslc/WSLCCLIReporterUnitTests.cpp Outdated
Comment thread test/windows/wslc/WSLCCLIReporterUnitTests.cpp Outdated

@OneBlue OneBlue 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.

Change looks good, couple minor comments

Comment thread src/windows/wslc/core/Reporter.h
Comment thread test/windows/wslc/WSLCCLITestHelpers.h Outdated
Copilot AI review requested due to automatic review settings June 17, 2026 06:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.

@dkbennett dkbennett requested a review from OneBlue June 17, 2026 17:16

@OneBlue OneBlue 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.

Approving to unblock, one outstanding comment on how we can simplify / explicit the std::format logic, but this is not blocking

@dkbennett dkbennett merged commit 8e3c0ad into master Jun 17, 2026
11 checks passed
@dkbennett dkbennett deleted the user/dkbennett/reporter branch June 17, 2026 19:24
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.

3 participants