Skip to content

feat(cli): render Markdown summaries and style progress output - #1927

Merged
lizhengfeng101 merged 6 commits into
mainfrom
feat/terminal-rendering
Nov 14, 2026
Merged

lizhengfeng101 merged 6 commits into
mainfrom
feat/terminal-rendering

Conversation

@lizhengfeng101

@lizhengfeng101 lizhengfeng101 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Render existing ocr scan project summaries as terminal Markdown, including headings, emphasis, inline code, lists, and tables.
  • Style progress prefixes, tool names, and start/success/failure markers. Resolve automatic color separately for the actual stdout/stderr destination.
  • Keep JSON/SARIF and explicit result files unstyled, preserve the original Markdown data, and retain quiet-agent behavior.
  • Allow only ordinary SGR styling sequences after Markdown rendering, including entity decoding; reject private CSI commands and active hyperlinks.

This is a presentation-only PR. It does not include behavioral-analysis workflows, new model calls, prompt changes, or result-schema changes. Review comments keep their existing layout.

--color=always intentionally styles redirected console output for uses such as less -R; --output <file> keeps Markdown delimiters regardless of that flag. Text files retain the existing terminal-control sanitization; JSON preserves the original summary string. Markdown follows CommonMark emphasis rules; punctuation next to closing bold delimiters can affect rendering.

Validation

  • make license-add and make check
  • make test, plus focused race-enabled renderer/security tests
  • make coverage: 91.6% total
  • make build
  • Eleven local mock-backed runs of the built scan binary covering real PTYs, pipes, stdout/stderr routing, JSON, explicit text/JSON output files, quiet-agent mode, and TERM=dumb. These validate presentation and delivery, not model quality.
  • Pre-commit ocr review and a focused follow-up review. The private-CSI finding was fixed and covered by regression tests; suggestions about forced-color pipes and existing text-file control sanitization were checked against the documented contract and baseline behavior.

AI Assistance

Prepared with Codex CLI using gpt-6-astra. Automated pre-commit review used ocr with gpt-6-astra.

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

🔍 OpenCodeReview found 1 issue(s) in this PR.

  • ✅ Successfully posted inline: 1 comment(s)

Comment thread internal/stdout/style.go
Comment on lines +61 to +63
if written != len(styled) {
return 0, io.ErrShortWrite
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

bug · medium
When the underlying writer performs a partial write (returns written < len(styled) with no error), this method returns 0, io.ErrShortWrite. However, some styled bytes have already been irreversibly flushed to the destination. Returning 0 tells the caller that none of its input was consumed, which can cause duplicated/garbled output if the caller retries with the same buffer.

While current callers (fmt.Fprintf) don't retry on error, this violates the expected io.Writer semantics where n should reflect actual consumption. Consider tracking how many original input bytes map to the successfully written styled portion, or at minimum returning len(data) alongside the error to signal full consumption (since the transformation makes partial recovery impossible anyway).

@Walternater

Copy link
Copy Markdown
Contributor

Independent verification on macOS (Go 1.26.10), commit b7f3031 vs base 0e9060da (13 files, +605/−8):

Tests / build

  • go test ./cmd/opencodereview ./internal/stdout ./internal/telemetry ./internal/agent ./internal/session — all packages pass (18.4s / 0.4s / 41.7s / 5.7s / 3.5s).
  • go build ./... and go vet ./cmd/opencodereview ./internal/stdout clean.
  • I did not re-run make check / license targets; CI should cover those.

Terminal-safety probes (calling renderMarkdown with hostile/untrusted summary input)

  • OSC 8 hyperlink (\x1b]8;;https://…\x07click…) → stripped, plain click.
  • Private CSI (\x1b[2J, \x1b[?25l) and raw ANSI (\x1b[31mred) → stripped before rendering.
  • Raw HTML (<script>…) → dropped by the renderer.
  • Only numeric SGR (…m) survives the post-render allowlist, matching TestRenderedMarkdownRejectsPrivateCSI.
  • Code spans keep literal text: `a&b` renders a&b (entity double-escaping handled by escapeCodeSpanEntities); no panic on entity, backtick, newline or nested-emphasis code spans.
  • File destination (--output) keeps raw Markdown delimiters and emits no ANSI, as intended.

Non-blocking observations

  1. Table rows are padded to full terminal width, so a 2-column table at width 120 renders with very large gaps and a leading blank line. Cosmetic, but if the project summary commonly contains small tables, a cell-width-to-content option would read better.
  2. On the non-TTY path sanitizeTerminal strips ESC but leaves the bracket payload, so a summary containing raw \x1b[31m becomes [31m in piped output. This is pre-existing behavior (the old summary path used the same function), not a regression from this PR.
  3. styledProgressWriter styles per Write call; a progress line split across two writes would only style the fragment that starts with [ocr]. Current progress writers appear to emit whole lines, so no action needed now.

Overall: the security boundary (untrusted Markdown → terminal) looks sound, and the presentation-only scope is respected.


Verified with AI assistance (DeepSeek Harness, deepseek-v4.1-flash); all commands were run locally against the PR tree.

@lizhengfeng101
lizhengfeng101 force-pushed the feat/terminal-rendering branch from 5570267 to 51f6b35 Compare November 14, 2026 10:12

@MuoDoo MuoDoo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lgtm

@lizhengfeng101
lizhengfeng101 merged commit d77d70b into main Nov 14, 2026
12 checks passed
@lizhengfeng101
lizhengfeng101 deleted the feat/terminal-rendering branch November 14, 2026 12:41
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.

3 participants