Skip to content

refactor: migrate non-streaming commands to CommandOutput with markdown rendering#398

Merged
BYK merged 9 commits intomainfrom
feat/markdown-output
Mar 12, 2026
Merged

refactor: migrate non-streaming commands to CommandOutput with markdown rendering#398
BYK merged 9 commits intomainfrom
feat/markdown-output

Conversation

@BYK
Copy link
Member

@BYK BYK commented Mar 11, 2026

Summary

Migrate 5 commands from imperative log.info/log.success/log.warn output to the structured CommandOutput<T> return pattern with dedicated markdown formatters. This is a continuation of the output convergence work from PR #394.

Commands migrated

Command Data Type Key Change
auth status AuthStatusData Multi-section display (source, user, token, defaults, verification) → mdKvTable + colorTag
auth logout LogoutResult Not-authenticated / env-token cases now throw typed errors instead of log.warn
cli feedback FeedbackResult Telemetry-disabled case throws ConfigError with suggestion
cli fix FixResult / FixIssue 20+ diagnostic log calls → structured issues array. Uses OutputError for failures (renders data then exits 1)
cli upgrade UpgradeResult Discriminated ResolveResult union. Progress messages kept on stderr; final result returned as data

Pattern

Every migrated command follows the same structure:

// 1. Define data type
export type FooResult = { ... };

// 2. Add output config to buildCommand
output: { json: true, human: formatFooResult },

// 3. Return data from func()
return { data: result };

Human formatters in src/lib/formatters/human.ts use the shared markdown helpers (mdKvTable, colorTag, safeCodeSpan, renderMarkdown) for consistent terminal rendering. All commands now automatically support --json and --fields.

What's NOT in this PR

  • auth login — Has an interactive OAuth path that needs raw stdout/stderr Writers. Deferred to buildStreamingCommand().
  • List commands (issue list, project list, etc.) — Need streaming infrastructure.
  • api command — Intentionally raw (direct API proxy).
  • Progress log.info calls in cli/upgrade — These are transient status messages on stderr, which is the correct place for them.

Commands now on return-based CommandOutput (19 total)

api, auth/refresh, auth/whoami, auth/status, auth/logout, auth/token, cli/feedback, cli/fix, cli/upgrade, issue/explain, issue/plan, issue/view, event/view, log/view, trace/view, org/view, project/view, project/create, team/create

Test results

917 pass, 0 fail, 30 test files.

BYK added 4 commits March 11, 2026 20:45
Convert auth/status from imperative log.info/success/error calls to the
structured CommandOutput<T> return pattern with a dedicated markdown
formatter.

Changes:
- Define AuthStatusData type for structured status information
- Add formatAuthStatus() human formatter using mdKvTable, colorTag, and
  renderMarkdown for rich terminal output
- Command func() now returns { data } instead of writing to logger
- Verification errors captured in data rather than thrown
- JSON output includes all status fields in a consistent shape
- Tests updated to assert on stdout (rendered output) instead of stderr
auth/logout:
- Returns LogoutResult data with loggedOut and configPath fields
- Not-authenticated and env-token-active cases now throw typed errors
  (AuthError) instead of log.warn, matching auth/status pattern
- Human formatter renders success message with markdown

cli/feedback:
- Returns FeedbackResult data with sent and message fields
- Telemetry-disabled case throws ConfigError with suggestion instead
  of log.warn, so the central error handler formats it consistently
- Human formatter shows ✓ or ⚠ based on send success

Both commands now support --json and --fields via the output config.
Convert cli/fix from 20+ imperative log calls to structured FixResult
data returned via CommandOutput.

Changes:
- Define FixIssue and FixResult types for structured diagnostic output
- All handler functions (ownership, permissions, schema) now return
  arrays of FixIssue objects instead of logging directly
- Add formatFixResult() human formatter with per-category sections,
  status markers (✓/✗/•), and instructions blocks
- Use OutputError for failure cases (renders data then exits code 1)
- --json and --fields flags now supported automatically
- Tests updated to assert on rendered stdout instead of consola stderr
Convert cli/upgrade final-result messages to structured UpgradeResult
data returned via CommandOutput, while keeping transient progress
messages as log.info to stderr.

Changes:
- Define UpgradeResult type with action, versions, channel, method, and
  warnings fields
- resolveTargetVersion returns discriminated union ResolveResult instead
  of string|null, enabling early-return paths to carry structured data
- migrateToStandaloneForNightly returns warnings[] instead of logging
- formatUpgradeResult() human formatter with ✓/⚠ markers and exhaustive
  action switch
- All code paths return { data: UpgradeResult }
- --json and --fields flags now supported automatically
@github-actions
Copy link
Contributor

github-actions bot commented Mar 11, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

Init

  • Enforce canonical feature display order by betegon in #388
  • Accept multiple delimiter formats for --features flag by betegon in #386
  • Add git safety checks before wizard modifies files by betegon in #379
  • Add experimental warning before wizard runs by betegon in #378
  • Add init command for guided Sentry project setup by betegon in #283

Issue List

  • Auto-compact when table exceeds terminal height by BYK in #395
  • Redesign table to match Sentry web UI by BYK in #372

Other

  • Add --dry-run flag to mutating commands by BYK in #387
  • Return-based output with OutputConfig on buildCommand by BYK in #380
  • Add --fields flag for context-window-friendly JSON output by BYK in #373
  • Magic @ selectors (@latest, @most_frequent) for issue commands by BYK in #371
  • Input hardening against agent hallucinations by BYK in #370
  • Add response caching for read-only API calls by BYK in #330

Bug Fixes 🐛

Init

  • Remove implementation detail from help text by betegon in #385
  • Truncate uncommitted file list to first 5 entries by MathurAditya724 in #381

Other

  • (api) Convert --data to query params for GET requests by BYK in #383
  • (docs) Remove double borders and fix column alignment on landing page tables by betegon in #369
  • Add trace ID validation to trace view + UUID dash-stripping by BYK in #375

Internal Changes 🔧

Init

  • Remove --force flag by betegon in #377
  • Remove dead determine-pm step label by betegon in #374

Other

  • Migrate non-streaming commands to CommandOutput with markdown rendering by BYK in #398
  • Convert Tier 2-3 commands to return-based output and consola by BYK in #394
  • Convert remaining Tier 1 commands to return-based output by BYK in #382
  • Converge Tier 1 commands to writeOutput helper by BYK in #376

Other

  • Minify JSON on read and pretty-print on write in init local ops by MathurAditya724 in #396

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 11, 2026

Codecov Results 📊

104 passed | Total: 104 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

✅ Patch coverage is 98.13%. Project has 917 uncovered lines.
❌ Project coverage is 95.49%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
human.ts 96.40% ⚠️ 44 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    95.50%    95.49%    -0.01%
==========================================
  Files          142       142         —
  Lines        20037     20343      +306
  Branches         0         0         —
==========================================
+ Hits         19136     19426      +290
- Misses         901       917       +16
- Partials         0         0         —

Generated by Codecov Action

A no-op logout when not authenticated is more user-friendly than an
error. Matches the previous behavior where exit code was 0.

- Not-authenticated: returns { loggedOut: false, message } (exit 0)
- Env-token-active: still throws AuthError (can't proceed)
- Formatter handles both loggedOut:true and loggedOut:false cases
…ead code

1. cli/fix.ts: repairOwnership now returns RepairOutcome[] aligned by
   index with the input issues array, fixing the bug where mixed
   success/failure results were misaligned via separate fixed[]/failed[]
   arrays.

2. cli/upgrade.ts + human.ts: Remove unreachable 'channel-only' action
   variant from UpgradeResult.action union and formatter — no code path
   produces it. Can be re-added when the feature is implemented.
…/schema handlers

Permission handler:
- repairPermissions now returns RepairOutcome[] aligned by index
- Dir-first ordering preserved via index maps (original issue indices
  tracked through reorder)
- Remove dead collectResults function

Schema handler:
- Keep original fixIssues from getSchemaIssues instead of building new
  objects from repair strings
- Mark all issues based on overall repair success/failure (schema repair
  runs independently of detection, so 1:1 mapping isn't possible)
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Move RepairOutcome type above the JSDoc so it's no longer wedged between
the doc comment and the function. Update @returns to describe the new
RepairOutcome[] return shape.
@BYK BYK merged commit 4304ab8 into main Mar 12, 2026
22 checks passed
@BYK BYK deleted the feat/markdown-output branch March 12, 2026 06:58
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.

1 participant