Skip to content

fix(cli): escape control characters in human output - #697

Closed
luvs01 wants to merge 3 commits into
devfrom
codex/fix-terminal-escape-sequences-in-suggestions
Closed

luvs01 wants to merge 3 commits into
devfrom
codex/fix-terminal-escape-sequences-in-suggestions

Conversation

@luvs01

@luvs01 luvs01 commented Oct 1, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Escape terminal control characters once at the shared printData human-output boundary. Role and injection suggestions both use this implementation; the injection path does not need a second terminalSafeText call.
  • Test role and injection suggestions with terminal-control payloads. Each --json invocation is parsed and compared with the original response before the capture is cleared for the separate human-output assertions.
  • Preserve native export documents as individual output lines. The export regression parses the multiline human document and compares it with the structured JSON result.
  • The complete PR changes five files: src/cli/runtime-api.ts, src/cli/export-command.ts, tests/cli/cli-headless-parity.test.ts, tests/cli/cli-export-command.test.ts, and structure/runtime.md.

Verification

Linux / Bun 1.4.0, exact tree 69c91240532fc669df5b518eed57a6624c600939:

  • bun test tests/cli/cli-headless-parity.test.ts tests/cli/cli-export-command.test.ts: 124 pass, 0 fail, 499 assertions.
  • Negative control: temporarily removing only the shared human-output escaping makes both suggestion regressions fail; restoring it passes. Original JSON response comparisons pass independently.
  • bun node_modules/typescript/bin/tsc --noEmit, bun scripts/structure-ssot.ts, bun scripts/privacy-scan.ts, bun scripts/file-size-ratchet.ts, and git diff --cached --check: pass.
  • Focused validation was used instead of a full local suite because concurrent worktrees make the broad run disproportionate. test:changed was not run against this exact-tree snapshot, which does not have the remote branch ancestry locally; source-as-data and subprocess behavior was covered explicitly. No full-suite or native Windows pass is claimed.
  • Exact-head hosted checks for 2a351b98e8209e6f7c9c72d25a7c775bdf949e3b completed successfully: Cross-platform CI, React Doctor, and CodeQL. Relevant Windows/macOS test matrices were skipped; the successful workflow does not establish that native coverage.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Runtime documentation and regression coverage match the implementation.
  • Terminal-control handling and exact structured-data preservation were checked.
  • Focused local validation passed with its scope documented.

Original Codex Task

Summary by CodeRabbit

  • Bug Fixes
    • Human-readable CLI output now safely escapes terminal control characters and Unicode line separators in displayed values, preventing unexpected formatting or terminal behavior.
    • Multiline export output is preserved as separate lines.
    • JSON output remains unchanged and retains the original values.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Oct 1, 2026
@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: luvs01/opencodex/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 7996bede-7483-4c84-acb9-ea0b76dfa84f

📥 Commits

Reviewing files that changed from the base of the PR and between 17d6e84 and 2a351b9.

📒 Files selected for processing (5)
  • src/cli/export-command.ts
  • src/cli/runtime-api.ts
  • structure/runtime.md
  • tests/cli/cli-export-command.test.ts
  • tests/cli/cli-headless-parity.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The CLI now escapes terminal-control characters and Unicode line separators in human-readable output. Native serialized exports pass to printData one line at a time. JSON output remains unchanged.

Changes

CLI output handling

Layer / File(s) Summary
Human-readable output framing and escaping
src/cli/runtime-api.ts, src/cli/export-command.ts, tests/cli/cli-headless-parity.test.ts, tests/cli/cli-export-command.test.ts, structure/runtime.md
printData escapes terminal-control characters and Unicode line separators in human-readable output. Native serialized exports pass to printData one line at a time. Tests check escaping and compare the human-readable export document with structured JSON output. Documentation describes the output behavior.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: lidge-jun

Merge Risk: ⚪ Minimal · up to 2a351

Human-readable CLI output escapes terminal controls while structured JSON preserves the original values. No concrete behavior or operational failure requiring a pre-merge fix is established.

Architecture Summary

Architecture risk: 🟡 Medium · up to 2a351

The change affects 3 systems.

Changed systems: src, tests, structure

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — src (service) was modified; 2 changed files map to changed impact.
  • observed — tests (service) was modified; 2 changed files map to changed impact.
  • observed — structure (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in src/cli/export-command.ts: The serialized document is split on newlines into individual printData entries instead of being passed as one multiline string.
  • observed — Modified behavior in src/cli/runtime-api.ts: Human-readable output now escapes terminal control characters and Unicode line separators with terminalSafeText instead of printing the original line directly; JSON output is unchanged.
  • observed — Modified behavior in structure/runtime.md: The readiness diagnostics description now includes escaping for shared printData human output, exact-value preservation in JSON, and line-based framing for native serialized exports, with corresponding suggestion-path and export test coverage. Existing refusal escaping and readiness classification details remain.
  • observed — Modified behavior in tests/cli/cli-export-command.test.ts: The test now resets captured logs, obtains a structured OpenCode export, checks its exit code, and compares its parsed JSON with the JSON portion of the human-readable output.

Reliability and maintainability

  • inferred — Risk-relevant change factors for src: blast_radius_1; direct_dependents_1
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 4 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the primary change: escaping terminal control characters in CLI human-readable output.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 4 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

devin-ai-integration Bot and others added 2 commits October 2, 2026 00:01
printData control-escapes each human-output line as one console line, so
passing the serialized client config as a single entry rendered its
newlines as literal \xNN text and the human output no longer led with
the JSON document. Hand it the document's individual lines instead.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@luvs01

luvs01 commented Oct 2, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Oct 2, 2026

Copy link
Copy Markdown

Autopilot could not be updated. Open Coding to check access and billing.

luvs01 commented Oct 2, 2026

Copy link
Copy Markdown
Owner Author

Preserved upstream in lidge-jun#6459 at db774c7da4e45c26555c141b7260ef225aca08c0. The implementation and regression-test changes are carried exactly, with newer upstream documentation retained. The 126 focused tests pass, and exact-head main CI passed. Upstream remains Draft because its metadata enforcement check was cancelled; review readiness is still separate. Closing this duplicate fork PR while keeping its branch and commits.

@luvs01 luvs01 closed this Oct 2, 2026
lidge-jun pushed a commit to lidge-jun/opencodex that referenced this pull request Oct 3, 2026
)

Carry luvs01#697 onto current dev, preserving its implementation and regression coverage.

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@github-actions
github-actions Bot deleted the codex/fix-terminal-escape-sequences-in-suggestions branch October 17, 2026 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aardvark bug Something isn't working codex

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant