[repository-quality] Repository Quality Improvement Report — Console Print Wrapper Gap #47087
Closed
Replies: 1 comment
|
This discussion was automatically closed because it expired on 2026-07-22T13:25:30.250Z.
|
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
🎯 Repository Quality Improvement Report — Console Print Wrapper Gap
Analysis Date: 2026-07-21
Focus Area: Console Print Wrapper Gap — Two-Step
fmt.Fprintln(os.Stderr, console.Format*(...))Anti-patternStrategy Type: Custom
Custom Area: Yes — discovered by profiling raw stderr call sites; the console package exposes
Format*functions but no correspondingPrint*wrappers, forcing all 185 consumer files to re-implement a boilerplate two-step write on every call.Executive Summary
The
pkg/consolepackage exposes rich styled-output formatters (FormatSuccessMessageStderr,FormatWarningMessage,FormatInfoMessageStderr, etc.) but deliberately stops short of writing toos.Stderr. As a result every caller must combinefmt.Fprintln(os.Stderr, console.FormatXxx(...))themselves — a two-step idiom repeated 1,640 times across the codebase, with an additional 239 rawfmt.Fprintf(os.Stderr, ...)calls that bypass console styling entirely.This creates three concrete problems: (1) accidental stdout/stderr routing errors (callers could easily write
os.Stdoutinstead ofos.Stderr); (2) inconsistent newline handling (fmt.Fprintvsfmt.Fprintlnvsfmt.Fprintfwith\n); (3) no single place to intercept output for testing, WASM/non-TTY environments, or future observability hooks. The console package already has a WASM build-tag split (console_wasm.go) that handles environment differences — a pattern thatPrint*wrappers could extend effortlessly.The fix is to add thin
Print*wrappers that callfmt.Fprintln(os.Stderr, Format*(...))internally, then migrate the highest-density call sites. A companion linter enforcing the new helpers would lock in the improvement permanently.Full Analysis Report
Focus Area: Console Print Wrapper Gap
Current State Assessment
The
pkg/consolepackage (console.go + WASM variants) providesFormat*functions that return styled strings but does not providePrint*helper functions that write directly toos.Stderr. Every consumer file must therefore compose the two steps manually.Metrics Collected:
fmt.Fprintln(os.Stderr, console.Format*(...))two-step callsfmt.Fprintf(os.Stderr, console.Format*(...))variantfmt.Fprintf(os.Stderr, "...")(no console styling)console.Print*wrappers that write directlyPrintBanner)banner_wasm.go)pkg/cli/mcp_inspect_mcp.gopkg/cli/engine_secrets.goFindings
Strengths
pkg/consolealready has a WASM build-tag split proving the pattern for environment-aware wrappers.PrintBanner()is a successful precedent showing the Print-wrapper style.Format*functions are well-named and cover all semantic message types (success, info, warning, error, progress, command, list item, section header, table header).Areas for Improvement
Print*wrappers:PrintSuccessMessageStderr,PrintWarningMessage,PrintInfoMessageStderr,PrintErrorMessage,PrintProgressMessage,PrintCommandMessage,PrintListItemStderr,PrintSectionHeaderStderr,PrintTableHeaderStderr— all absent.fmt.Fprintln+console.Format*.fmt.Fprintf(os.Stderr, "...")with no styling — inconsistent visual output.Detailed Analysis
Two-step idiom example (from
pkg/cli/engine_secrets.go):Raw bypass example (from
pkg/cli/engine_secrets.go:437):Top-5 highest-density files:
pkg/cli/mcp_inspect_mcp.gopkg/cli/engine_secrets.gopkg/cli/logs_metrics.gopkg/cli/trial_repository.gopkg/cli/shell_completion.go🤖 Tasks for Copilot Agent
NOTE TO PLANNER AGENT: Split the following tasks into individual work items.
Improvement Tasks
Task 1: Add
Print*wrappers topkg/console/console.goPriority: High
Estimated Effort: Small
Focus Area: Console Print Wrapper Gap
Description: Add
PrintXxxthin-wrapper functions alongside eachFormatXxxfunction inpkg/console/console.go(and matching no-op stubs inpkg/console/banner_wasm.go/ other WASM split files where applicable). Each wrapper should callfmt.Fprintln(os.Stderr, FormatXxx(...)). Functions to add:PrintSuccessMessageStderr,PrintInfoMessageStderr,PrintWarningMessage,PrintErrorMessage,PrintProgressMessage,PrintCommandMessage,PrintListItemStderr,PrintSectionHeaderStderr,PrintTableHeaderStderr,PrintErrorTextStderr,PrintErrorChain.Acceptance Criteria:
FormatXxxStderrfunction inconsole.gohas a matchingPrintXxxStderrwrapper.PrintWarningMessage,PrintErrorMessage,PrintProgressMessage,PrintCommandMessageadded for non-Stderr variants.fmt.Fprintln(os.Stderr, FormatXxx(...))internally.spinner_wasm.goorbanner_wasm.go) does not need changes (wrappers naturally useos.Stderrwhich WASM stubs already handle).make test-unit).Code Region:
pkg/console/console.goTask 2: Migrate
pkg/cli/engine_secrets.gotoPrint*wrappersPriority: High
Estimated Effort: Small
Focus Area: Console Print Wrapper Gap
Description: Replace all
fmt.Fprintln(os.Stderr, console.FormatXxx(...))andfmt.Fprintf(os.Stderr, ...)inpkg/cli/engine_secrets.go(63 raw stderr calls) with the newconsole.PrintXxx(...)wrappers added in Task 1. Where the rawfmt.Fprintfuses a format string without a console styling function, wrap the message in the appropriate semanticconsole.PrintInfoMessageStderr(...)orconsole.PrintWarningMessage(...)call.Acceptance Criteria:
fmt.Fprintln(os.Stderrcalls remain inengine_secrets.go.fmt.Fprintf(os.Stderrcalls remain inengine_secrets.go.fmtimport is removed if no longer needed, or only used for non-stderr formatting.make test-unitpasses.Code Region:
pkg/cli/engine_secrets.goTask 3: Migrate
pkg/cli/mcp_inspect_mcp.gotoPrint*wrappersPriority: High
Estimated Effort: Small
Focus Area: Console Print Wrapper Gap
Description: Replace all 70 raw stderr call sites in
pkg/cli/mcp_inspect_mcp.gousing the same approach as Task 2. This is the highest-density file in the codebase.Acceptance Criteria:
fmt.Fprintln(os.Stderrcalls remain inmcp_inspect_mcp.go.fmt.Fprintf(os.Stderrcalls remain inmcp_inspect_mcp.go.make test-unitpasses.Code Region:
pkg/cli/mcp_inspect_mcp.goTask 4: Add
fmtfprintlnstderrlinter to enforceconsole.Print*usagePriority: Medium
Estimated Effort: Medium
Focus Area: Console Print Wrapper Gap
Description: Add a new linter
pkg/linters/fmtfprintlnstderr/fmtfprintlnstderr.gothat flagsfmt.Fprintln(os.Stderr, ...)andfmt.Fprintf(os.Stderr, ...)calls inpkg/library code and suggests usingconsole.PrintXxx(...)instead. Register it inpkg/linters/registry.goandpkg/linters/doc.go. Add testdata with at least 3 want-annotated violations and 2 allowed patterns (//nolint:fmtfprintlnstderrandos.Stdoutvariant).Acceptance Criteria:
pkg/linters/fmtfprintlnstderr/fmtfprintlnstderr.gowithAnalyzervar.pkg/linters/registry.goalongside other linters.pkg/linters/doc.golist.pkg/linters/fmtfprintlnstderr/testdata/src/fmtfprintlnstderr/fmtfprintlnstderr.gowith// wantannotations.pkg/linters/spec_test.goupdated to include the new analyzer inContainsExpectedAnalyzers.make test-unitpasses.Code Region:
pkg/linters/fmtfprintlnstderr/Task 5: Migrate
pkg/workflow/raw stderr calls toconsole.Print*Priority: Medium
Estimated Effort: Medium
Focus Area: Console Print Wrapper Gap
Description: Replace the 134 raw
fmt.Fprintf(os.Stderr, ...)calls acrosspkg/workflow/(top files:dependabot.go:19,compiler_validators.go:12,compiler.go:10,pip_validation.go:7,lock_validation.go:6,claude_logs.go:6) withconsole.Print*wrappers. Becausepkg/workflowis a library package, it should not write toos.Stderrdirectly — it should either return errors or use the console package, which already handles TTY/WASM differences.Acceptance Criteria:
fmt.Fprintf(os.Stderrcalls inpkg/workflow/dependabot.go,compiler_validators.go,compiler.go,pip_validation.go,lock_validation.go,claude_logs.go.console.PrintWarningMessage/console.PrintInfoMessageStderr/console.PrintErrorMessagewrappers.make test-unitpasses.Code Region:
pkg/workflow/dependabot.go,pkg/workflow/compiler_validators.go,pkg/workflow/compiler.go,pkg/workflow/pip_validation.go,pkg/workflow/lock_validation.go,pkg/workflow/claude_logs.go📊 Historical Context
Previous Focus Areas
var _ Interface = (*Type)(nil)guards in 21 interfaces🎯 Recommendations
Immediate Actions (This Week)
Print*wrappers topkg/console/console.go(Task 1) — Priority: Highengine_secrets.goandmcp_inspect_mcp.goas pilot files (Tasks 2 & 3) — Priority: HighShort-term Actions (This Month)
fmtfprintlnstderrlinter (Task 4) to prevent regression — Priority: Mediumpkg/workflow/raw stderr calls (Task 5) — Priority: MediumLong-term Actions (This Quarter)
pkg/cli/files using the newPrint*wrappers — Priority: Low📈 Success Metrics
fmt.Fprintf(os.Stderr)calls: 239 → 0console.Print*wrappers: 1 (PrintBanner) → 12+Next Steps
References:
All reactions