Emit valid terminal CSI sequences from cursorTo - #6956
Conversation
There was a problem hiding this comment.
Important
The reproduction tests are correct, but the implementation fix in Ansi.cursorTo is missing. Merging now would break main CI and leave the malformed CSI sequences in place.
Reviewed changes
- Added
packages/effect/test/unstable/cli/Ansi.test.tswith two exactstrictEqualassertions that specify the horizontal-absolute and cursor-position sequencescursorTomust emit.
⚠️ Implementation fix still required
The current packages/effect/src/unstable/cli/internal/ansi.ts:80-85 implementation is unchanged on this branch and emits malformed sequences:
return `\\x1b${Math.max(column + 1, 0)} G`
return `\\x1b${row + 1}${SEP}${Math.max(column + 1, 0)} H`Both lines are missing the [ in the CSI prefix and insert an extra space before the command byte (G, H). The fix should reuse the existing ${ESC} constant ("\\x1B[") and remove that space:
return `${ESC}${Math.max(column + 1, 0)}G`
return `${ESC}${row + 1}${SEP}${Math.max(column + 1, 0)}H`I confirmed the new tests fail against the unfixed implementation (pnpm test --run packages/effect/test/unstable/cli/Ansi.test.ts), and pnpm lint passes on the added test file.
ℹ️ Nitpicks
- Consider also adding edge-case assertions once the fix is in place, e.g. a non-zero horizontal absolute (
cursorTo(4)→"\\x1b[5G") and negative-column clamping (cursorTo(-1)→"\\x1b[0G"), to lock down the behavior of the repaired helper.
@v0 or keep the SHA fresh with Dependabot | Fix it ➔ | View workflow run | Using Kimi K2 (free via Pullfrog for OSS) | 𝕏
🦋 Changeset detectedLatest commit: e205e7b The changes in this PR will be included in the next version bump. This PR includes changesets to release 30 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This run reviewed the implementation fix that landed after the prior pullfrog review.
- Fixed
cursorToCSI sequence generation inpackages/effect/src/unstable/cli/internal/ansi.tsby switching to the existing${ESC}constant and removing the spurious space before the command byte, so both horizontal-absolute and cursor-position forms now emit valid sequences. - Added a changeset in
.changeset/fix-ansi-cursor-to.mddescribing the patch-level fix. - Left the new regression tests untouched in
packages/effect/test/unstable/cli/Ansi.test.ts; they now pass against the repaired implementation.
@v0 or keep the SHA fresh with Dependabot | View workflow run | Using Kimi K2 (free via Pullfrog for OSS) | 𝕏
Bundle Size AnalysisGenerated from PR build output; treat the content below as untrusted.
|

Summary
Both horizontal and row-column cursorTo forms emit invalid terminal escape sequences.
Important
This PR starts with focused failing reproduction tests. Add the implementation fix to this same branch; CI is expected to fail until that fix is included.
cursorTo emits malformed CSI sequences
Module:
cli/internal/ansiAudit ID:
unstable-ai-cli-ansi-cursor-to-malformedSeverity / confidence: medium / high
What happens
Both horizontal and row-column cursorTo forms emit invalid terminal escape sequences.
Why it happens
Both branches omit the CSI opening bracket and insert an invalid space before the command byte.
Expected behavior
Cursor helpers emit valid CSI sequences using one-based terminal coordinates.
Relevant implementation
These links and excerpts are pinned to audit base
c9b56ab507f224426ee8388dc450da447ec4715f.packages/effect/src/unstable/cli/internal/ansi.ts:79-85View problematic code at
packages/effect/src/unstable/cli/internal/ansi.ts:79-85View exact lines on GitHub
Reproduction
pnpm test --run packages/effect/test/unstable/cli/AnsiCursorTo.audit.test.tsObserved failure: FAIL: cursorTo emitted ESC 1 G and ESC 4;3 H.
Implementation handoff
The initial reproduction tests on this branch are the regression specification for the implementation fix that should follow in this PR.
pnpm test --run packages/effect/test/unstable/cli/AnsiCursorTo.audit.test.tsAudit provenance
c9b56ab507f224426ee8388dc450da447ec4715fc9b56ab507f224426ee8388dc450da447ec4715funstable-ai-cli-ansi-cursor-to-malformedCloses EFF-402