strix icon indicating copy to clipboard operation
strix copied to clipboard

fix(tui): don't double-render finish_scan section headings

Open seanturner83 opened this issue 4 months ago • 2 comments

What

The finish_scan renderer shows each section heading twice — once as its own styled label, once from the field's markdown body.

Why

FinishScanRenderer.render() prints a styled label above each field:

text.append("Executive Summary", style=FIELD_STYLE)
text.append("\n")
text.append(executive_summary)

But the finish_scan tool prompts the model to "use markdown in every field", and its own docstring example opens executive_summary with # Executive Summary. So the models reliably start each field with a # <Section> heading — and it renders on top of the styled label:

Executive Summary        ← styled label
# Executive Summary      ← the field's own markdown heading
<body>

Every section (Executive Summary / Methodology / Technical Analysis / Recommendations) doubles. Cosmetic (TUI/log only — SARIF/report artifacts are unaffected), but consistently noisy.

Fix

Strip a leading markdown heading from a field value only when it repeats that field's section label (case-insensitive), so the label shows once. Deliberately conservative:

  • a leading heading that says something else → kept (real content),
  • a value with no heading → unchanged,
  • a lone heading with no body → kept (don't strip a section to empty).

Tests

tests/test_finish_renderer.py (7): the strip helper's match / case-insensitivity / different-heading-kept / no-heading-kept / lone-heading-kept cases, plus an end-to-end assert that "Executive Summary" renders exactly once and the body survives.

🤖 Generated with Claude Code

seanturner83 avatar Jul 17 '26 07:07 seanturner83

Greptile Summary

This PR removes repeated Markdown headings from finish-scan sections in the TUI. The main changes are:

  • Adds a helper for matching section headings.
  • Applies heading removal to all four finish-scan fields.
  • Adds helper and end-to-end renderer tests.

Confidence Score: 4/5

The heading-removal helper needs fixes for two reachable Markdown forms before merging.

  • A heading-only field ending with a newline is rendered as empty.
  • A heading with a closing ATX marker remains duplicated.
  • Persisted reports are unaffected because the change is limited to TUI rendering.

strix/interface/tui/renderers/finish_renderer.py

Important Files Changed

Filename Overview
strix/interface/tui/renderers/finish_renderer.py Adds heading deduplication for all finish-scan fields, with edge cases around empty remainders and closing ATX markers.
tests/test_finish_renderer.py Adds focused helper and rendering tests but omits heading-only values with trailing newlines and headings with closing markers.
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 2
strix/interface/tui/renderers/finish_renderer.py:27-28
**Trailing Newline Erases Lone Heading**

When a field contains only `# Recommendations\n`, it passes the upstream non-empty check and matches this pattern, but the helper returns an empty string. The TUI then hides the field's only supplied content, contrary to the stated rule that a lone heading should be preserved.

```suggestion
    m = re.match(pattern, stripped, flags=re.IGNORECASE)
    remainder = stripped[m.end() :] if m else ""
    return remainder if remainder.strip() else value
```

### Issue 2 of 2
strix/interface/tui/renderers/finish_renderer.py:26
**Closing ATX Marker Defeats Deduplication**

A valid Markdown heading such as `# Executive Summary #\n\nBody` does not match because of its closing `#`. The original heading remains below the styled section label, so the duplicate heading this change targets is still displayed for that common Markdown form.

```suggestion
    pattern = rf"^#{{1,6}}\s+{re.escape(section)}(?:\s+#+)?\s*\n+"
```


Reviews (1): Last reviewed commit: "fix(tui): don't double-render finish_sca..." | Re-trigger Greptile

greptile-apps avatar Jul 17 '26 07:07 greptile-apps

Both fixed in the latest push — good catches:

  • P1 (heading-only field blanked): a field that's just # Recommendations\n matched the pattern and stripped to empty, hiding its only content. Now if stripping would leave nothing non-whitespace, the original value is kept.
  • P2 (closing-ATX): the pattern now accepts an optional trailing #+ run, so # Executive Summary # also dedupes.

Added tests for both (heading-only-with-newline preserved; closing-ATX stripped).

seanturner83 avatar Jul 17 '26 08:07 seanturner83