refactor: unify all command functions as async generators#413
refactor: unify all command functions as async generators#413
Conversation
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Init
Issue List
Other
Bug Fixes 🐛Init
Other
Internal Changes 🔧Init
Other
Other
🤖 This preview updates automatically when you update the PR. |
Codecov Results 📊✅ 104 passed | Total: 104 | Pass Rate: 100% | Execution Time: 0ms 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ✅ Patch coverage is 100.00%. Project has 697 uncovered lines. Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 96.66% 96.67% +0.01%
==========================================
Files 159 160 +1
Lines 20855 20914 +59
Branches 0 0 —
==========================================
+ Hits 20158 20217 +59
- Misses 697 697 —
- Partials 0 0 —Generated by Codecov Action |
e7ea4be to
f81ed82
Compare
f81ed82 to
1eb34eb
Compare
There was a problem hiding this comment.
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.
| if (fields && fields.length > 0) { | ||
| return logs.map((log) => filterFields(log, fields)); | ||
| } | ||
| return logs; |
There was a problem hiding this comment.
JSONL follow-mode outputs array-wrapped log entries
High Severity
In follow mode with --json, each JSONL line is emitted as a one-element array [{...}] instead of a bare object {...}. yieldStreamChunks wraps each individual log in { kind: "data", logs: [log] }, and jsonTransformLogOutput returns logs (the single-element array) directly. writeTransformedJson then serializes that array as-is. The old writeLogs called writeJson(stdout, log, fields) per log, emitting bare objects. This breaks the JSONL output contract for existing consumers.
Additional Locations (1)
c648183 to
f53bc98
Compare
All command functions now use async generator signatures. The framework iterates each yielded value through the existing OutputConfig rendering pipeline. Non-streaming commands yield once and return; streaming commands (log list --follow) yield multiple times. Key changes: - buildCommand: func returns AsyncGenerator, wrapper uses for-await-of - All ~27 command files: async func → async *func, return → yield - log/list follow mode: drainStreamingOutput replaced by yield delegation - Delete streaming-command.ts (151 lines) — absorbed into buildCommand - output.ts: extracted applyJsonExclude/writeTransformedJson helpers, support undefined suppression for streaming text-only chunks No new dependencies. Net -131 lines.
ee063a5 to
ff35175
Compare


Summary
All command functions now use async generator signatures (
async *func). The framework iterates each yielded value through the existing OutputConfig rendering pipeline.Key insight
Every command function becomes an async generator. No detection, no branching, no special cases. The framework always does
for await (const value of generator):Changes
Framework (
command.ts)SentryCommandFunction→ returnsAsyncGenerator<unknown, void, undefined>for await...ofto iterate and render each yielded valueOutput rendering (
output.ts)applyJsonExclude()andwriteTransformedJson()helpers (reduced complexity)jsonTransformreturningundefinednow suppresses the chunk (streaming text-only chunks)human()returning empty string suppresses output (streaming data-only chunks in human mode)All ~27 command files
async func→async *funcreturn { data, hint }→yield { data, hint }useYieldlog/list follow mode
drainStreamingOutputreplaced byyield*delegation toyieldStreamChunks()generatorDeleted:
streaming-command.ts(151 lines)drainStreamingOutput()andStreamingOutputConfig— no longer neededStats