Skip to content

fix: render search snippets on one row and align columns by character width#42

Merged
karngyan merged 1 commit into
mainfrom
fix/search-output-rendering
Jul 18, 2026
Merged

fix: render search snippets on one row and align columns by character width#42
karngyan merged 1 commit into
mainfrom
fix/search-output-rendering

Conversation

@karngyan

Copy link
Copy Markdown
Contributor

Claim

Two display-only defects in the human-readable output of autophagy search (crates/autophagy-cli) are fixed, so every result renders as exactly one aligned row:

  1. Multiline snippets broke the single-row table layout. Codex-adapter events carry tool input with real embedded newlines/tabs. When an FTS snippet window fell outside the extracted command/cmd field, clean_snippet left those control characters in place, spilling one result across several physical lines. It now collapses every run of whitespace (newlines, tabs, spaces) into a single space via a shared collapse_whitespace helper, applied on both the command-extraction path and the JSON-stripping fallback, before the result is written.

  2. Column widths were computed from byte length. Rust's formatter pads &str by character count ({:<w$} counts chars), so a byte-length budget over-counts multibyte cells and pads the column wider than its displayed content. Width is now measured with chars().count() to match the formatter's own measure.

Both are strictly cosmetic. JSON output is untouched — raw snippets and full ranking detail remain available under --output json.

Evidence

Verified against a 69k-event real-data DB copy (adapters: claude-code, codex, pi), config isolated with AUTOPHAGY_CONFIG_DIR, real DB never modified.

Defect 1 — search "output" --project <autophagy> returned 48 physical lines for 20 results before, and exactly 20 after. One result, before (spilled across 3 lines):

evt_codex_0b430bcf…    2d ago  autophagy  text  50.0%  … Error(r.[output]);
const body=r.[output].endsWith(\n)?r.[output]:r.[output]+\n;
const patch …

Same result, after (one row):

evt_codex_0b430bcf…  2d ago  autophagy  text  50.0%  … Error(r.[output]); const body=r.[output].endsWith(\n)?r.[output]:r.[output]+\n; const patch …

Line counts, before vs after, same queries: output 48→20, text 28→20, tools 24→20.

Defect 2 — covered by a deterministic unit test (column_width_counts_characters_not_bytes): a byte-length budget injects spurious trailing spaces on a multibyte cell (café—münchen); a character-count budget equal to the cell's own width adds none.

New/updated unit tests (no DB needed): clean_snippet_collapses_multiline_content_to_one_row, clean_snippet_collapses_newlines_inside_command_value, collapse_whitespace_trims_and_squeezes_runs, column_width_counts_characters_not_bytes.

mise run check (fmt + clippy pedantic -D warnings + tests + docs + actionlint) passes fully (exit 0).

Privacy

None. Display-only changes to human-readable output; no new persistence, no change to what is indexed or stored, JSON output byte-for-byte unchanged.

Scope

Single file: crates/autophagy-cli/src/main.rs. No spec, schema, or migration changes.

🤖 Generated with Claude Code

… width

Two display-only defects in `autophagy search` human output:

- Multiline snippets (codex-adapter events carry real embedded newlines/tabs
  outside the extracted command field) spilled a single result across several
  physical lines, breaking the aligned one-row-per-result table. clean_snippet
  now collapses every run of whitespace into a single space via a shared
  collapse_whitespace helper, on both the command-extraction and JSON-stripping
  paths. JSON output is untouched — raw snippets remain under --output json.

- Column widths were computed from byte length. Rust's formatter pads &str by
  character count, so a byte-length budget over-counts multibyte cells and pads
  the column wider than its displayed content. Width is now measured with
  chars().count() to match the formatter's own measure.

Adds unit tests for snippet whitespace collapsing and the width computation.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@karngyan
karngyan merged commit dc3d36e into main Jul 18, 2026
1 check failed
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.

1 participant