From 96d464a2c03d9252ea333fb2931a0598b3f2de0f Mon Sep 17 00:00:00 2001 From: teernisse Date: Mon, 23 Feb 2026 09:37:05 -0500 Subject: [PATCH] docs: add architectural insights for ANSI width and JSON type detection Document two hard-won patterns in CLAUDE.md's new Architectural Insights section: - ANSI Width Calculation: lipgloss.Width() must be used instead of len() for styled strings, since ANSI escape codes add ~20 bytes per color code. fmt.Sprintf padding is similarly affected. - JSON Top-Level Type Detection: bytes.Contains matches nested strings in JSONL with embedded JSON. Correct approach tracks brace depth and skips quoted strings to find actual top-level fields. Co-Authored-By: Claude Opus 4.6 --- CLAUDE.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CLAUDE.md b/CLAUDE.md index dab2ccd..0560399 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -83,3 +83,13 @@ Run `cburn setup` for interactive configuration. - `components.CardInnerWidth(w)` computes usable width inside a card border. - `components.LayoutRow(w, n)` splits width into n columns accounting for gaps. - When rendering inline bars (like Activity panel), dynamically compute column widths from actual data to prevent line wrapping. + +--- + +## Architectural Insights (Learned Patterns) + +### ANSI Width Calculation +**Always use `lipgloss.Width()`, never `len()`** for styled strings. `len()` counts raw bytes including ANSI escape sequences (~20 bytes per color code). A 20-char bar with two color codes becomes ~60+ bytes, breaking column layouts. For padding, use custom width-aware padding since `fmt.Sprintf("%*s")` also pads by byte count. + +### JSON Top-Level Type Detection +When parsing JSONL with nested JSON content (like Claude Code sessions), `bytes.Contains(line, pattern)` matches nested strings too. For top-level field detection, track brace depth and skip quoted strings to find the actual top-level `"type"` field.