fix: render search snippets on one row and align columns by character width#42
Merged
Conversation
… 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: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/cmdfield,clean_snippetleft 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 sharedcollapse_whitespacehelper, applied on both the command-extraction path and the JSON-stripping fallback, before the result is written.Column widths were computed from byte length. Rust's formatter pads
&strby 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 withchars().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):Same result, after (one row):
Line counts, before vs after, same queries:
output48→20,text28→20,tools24→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