Skip to content

fix(cli): keep line breaks in logs explain text output - #6704

Merged
lidge-jun merged 1 commit into
lidge-jun:devfrom
WOULDU-pres:fix/cli-logs-explain-newlines
Oct 7, 2026
Merged

lidge-jun merged 1 commit into
lidge-jun:devfrom
WOULDU-pres:fix/cli-logs-explain-newlines

Conversation

@WOULDU-pres

@WOULDU-pres WOULDU-pres commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • ocx logs explain <request-id> (text mode) printed the whole route decision on one line, with every line break shown as a literal \x0a. --json was not affected.
  • Cause: explain() in src/cli/observe.ts passed the pretty-printed JSON to printData as a single entry. printData runs terminalSafeText per entry, which escapes \n along with the other control characters.
  • Fix: pass one entry per line (JSON.stringify(result, null, 2).split("\n")). Values inside the decision keep the same terminal-safety escaping (e.g. C1 controls such as U+009B that JSON.stringify leaves raw), and --json output is unchanged. No other printData caller passes a multi-line single entry.

Before (2.79.0):

$ ocx logs explain ocx-…
{\x0a  "requestId": "ocx-…",\x0a  "routeDecision": {\x0a    "version": 1,\x0a ...

After:

$ ocx logs explain ocx-…
{
  "requestId": "ocx-…",
  "routeDecision": {
    "version": 1,
...

Verification

  • bun test tests/cli/route-explainability.test.ts: 15 pass, 0 fail (49 expect() calls). The new case CLI logs explain text output keeps line breaks and still escapes values checks that text mode prints one console line per JSON line, contains no literal \x0a, and still escapes a raw U+009B inside a value.
  • Same new case with the src/cli/observe.ts change reverted: 0 pass, 1 fail. The received output is the single {\x0a "requestId": ... string.
  • bun run test:changed: 662 pass, 1 skip, 0 fail across 29 files.
  • bun run typecheck: exit 0.
  • bun run privacy:scan: passed.
  • bun run structure:check: passed.
  • bun scripts/file-size-ratchet.ts: passed.
  • git diff --check: clean.
  • Not run: the full bun run test suite. This is a two-file change (one CLI rendering line plus one test case), and test:changed covers the import-connected tests. Full-suite coverage is left to CI.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed. (No doc describes the broken output, so no doc change was needed.)
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults. (Terminal-safety escaping of values is preserved and covered by the new test.)

Review readiness checklist

This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:

  • Required local validation passed; commands, results, and any full-suite exception are documented.

  • I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).

  • I resolved all correct Codex and CodeRabbit findings.

  • My PR is ready for review.

Summary by CodeRabbit

  • Bug Fixes
    • Human-readable logs explain output now preserves JSON line breaks and safely escapes terminal control characters. JSON output remains unchanged.

`ocx logs explain <id>` passed the pretty-printed route decision to
printData as a single entry. printData escapes control characters per
entry for terminal safety, so every line break was printed as a literal
`\x0a` and the whole decision came out on one line. Pass one entry per
line instead; values keep the same terminal-safety escaping, and --json
output is unchanged.
@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: lidge-jun/opencodex/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 42fe47eb-d5e9-4dca-8545-6bab09c40993
📥 Commits

Reviewing files that changed from the base of the PR and between c30b522 and 66037ae.

📒 Files selected for processing (2)
  • src/cli/observe.ts
  • tests/cli/route-explainability.test.ts

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


📝 Walkthrough

Walkthrough

The CLI’s human-readable logs explain output now passes pretty-printed JSON to printData as separate lines. JSON output is unchanged. A test checks line breaks and C1 CSI escaping.

Changes

Explain Output

Layer / File(s) Summary
Format and verify text output
src/cli/observe.ts, tests/cli/route-explainability.test.ts
Text output passes pretty-printed JSON to printData as separate lines. The test checks that line breaks remain intact, U+009B is escaped, and the console spy is restored.

Priority: ⬇️ Low

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

Change: Bug fix

Suggested reviewers: lidge-jun

Merge Risk: ⚪ Minimal · up to 66037

The change affects human-readable explain output; JSON output remains unchanged, and the added test covers the intended line-break and terminal-escaping behavior. No merge-blocking issue is identified.

🚥 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 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: preserving line breaks in the text output of logs explain.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

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

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

✅ READY

  • all PR quality gates passed; the review readiness checklist is complete.

Review readiness checklist

  • ✅ Required local validation passed; commands, results, and any full-suite exception are documented.
  • ✅ I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).
  • ✅ I resolved all correct Codex and CodeRabbit findings.
  • ✅ My PR is ready for review.

✅ 4/4 boxes ticked.

This pull request has been marked Ready for Review.
The review-ready label marks this PR as ready; review automation runs independently.
Maintainers notified: @lidge-jun @Ingwannu

@WOULDU-pres

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor
✅ 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.

@github-actions
github-actions Bot marked this pull request as ready for review October 7, 2026 08:07
@lidge-jun

Copy link
Copy Markdown
Owner

Maintainer integration into dev as part of the 2026-10-07 daily merge train (MAINTAINERS.md dev-only maintainer integration; not a self-approval or an independent review).

  • Exact head: 66037ae9cb090c471221875f162511f27270b659.
  • Owner instruction for this train: squash-merge without per-PR Cross-platform CI; one workflow_dispatch Cross-platform CI (lane=all) runs on the final dev tip, with fix-forward if red.
  • Local verification on the exact merge of this head into origin/dev: bun test ./tests/cli/route-explainability.test.ts 15 pass; layout/tooling/file-size-ratchet guards 27 pass; bun x tsc --noEmit 0; bun run structure:check pass.
  • Review: gpt-6.1-sol triage MERGE (pretty JSON split into console lines, terminal escaping and JSON mode preserved, C1-control regression covered). No unresolved threads, no change requests. No gui/ paths.
  • Checks present on the head: enforce-target:success hygiene:success label:success resolve-pr:success.

@lidge-jun
lidge-jun merged commit c48e46d into lidge-jun:dev Oct 7, 2026
12 of 13 checks passed
@lidge-jun lidge-jun mentioned this pull request Oct 8, 2026
3 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working review-ready

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants