attribution: extract shared blame-table rendering scaffolding · Entire

attribution: extract shared blame-table rendering scaffolding

b71641e→main·

Soph·1mo ago·1 file·+63 added/-62 removed

renderAttributionBlameCompact and renderAttributionBlameLong each repeated the same header print, empty-file short-circuit, and trailing summary call around their column layouts. Pull that scaffolding into renderAttributionBlameTable and pass each variant's table body as a callback. Output is unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com

Sessions

5fc3dec002a5View transcript

Changes

1

762 unmodified lines

763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
767
768
783
784
785
786
787
788
789
790
791
792
793
794
795
770
771
772
773
796
797
798
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
808
809
816
817
818
819
820
821
822
811
812
813
814
823
824
825
826
827
828
829
830
831
832
833
834
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
835
836
837
838
839

762 unmodified lines

}

// renderAttributionBlameTable renders the scaffolding shared by every blame
// table — the file header, the empty-file short-circuit, and the trailing
// summary — and delegates the column layout to body.
func renderAttributionBlameTable(w io.Writer, result *fileAttributionResult, lineFlag string, body func(statusStyles)) {
    sty := newStatusStyles(w)
    fmt.Fprintf(w, "\n  %s\n\n", sty.render(sty.bold, result.File))

if len(result.Lines) == 0 {
        fmt.Fprintln(w, sty.render(sty.dim, "  No lines to display."))
        return
    }

body(sty)
    renderAttributionSummary(w, sty, result.Summary, lineFlag)
}

func renderAttributionBlameCompact(w io.Writer, result *fileAttributionResult, lineFlag string) {
    sty := newStatusStyles(w)
    fmt.Fprintf(w, "\n  %s\n\n", sty.render(sty.bold, result.File))
    renderAttributionBlameTable(w, result, lineFlag, func(sty statusStyles) {
        lineWidth := attributionLineColumnWidth(result.Lines)
        const agentWidth = 6
        const authorWidth = 6
        const checkpointWidth = 12
        const minContentWidth = 12
        fixedWidth := 2 + lineWidth + 2 + len("[AI]") + 2 + agentWidth + 2 + authorWidth + 2 + checkpointWidth + 2
        contentWidth := sty.width - fixedWidth
        if contentWidth < minContentWidth {
            contentWidth = minContentWidth
        }
        tableWidth := fixedWidth + contentWidth - 2

if len(result.Lines) == 0 {
            fmt.Fprintln(w, sty.render(sty.dim, "  No lines to display."))
            return
        }
        fmt.Fprintf(w, "  %*s  Tag   %-*s  %-*s  %-*s  Content\n", lineWidth, "Line", agentWidth, "Agent", authorWidth, "Author", checkpointWidth, "Checkpoint")
        fmt.Fprintf(w, "  %s\n", sty.render(sty.dim, strings.Repeat("─", tableWidth)))

for _, line := range result.Lines {
            fmt.Fprintf(w, "  %s  %s  %-*s  %-*s  %-*s  %s\n",
                sty.render(sty.dim, fmt.Sprintf("%*d", lineWidth, line.LineNumber)),
                renderAttributionTag(sty, line.Authorship),
                agentWidth,
                stringutil.TruncateRunes(compactAttributionAgent(line), agentWidth, ""),
                authorWidth,
                stringutil.TruncateRunes(shortAuthorName(line.Author), authorWidth, ""),
                checkpointWidth,
                stringutil.TruncateRunes(compactAttributionCheckpoint(line), checkpointWidth, ""),
                renderAttributionContentCompact(sty, line, contentWidth),
            )
        }
        renderAttributionSummary(w, sty, result.Summary, lineFlag)
    })
}

func renderAttributionBlameLong(w io.Writer, result *fileAttributionResult, lineFlag string) {
    sty := newStatusStyles(w)
    fmt.Fprintf(w, "\n  %s\n\n", sty.render(sty.bold, result.File))
    renderAttributionBlameTable(w, result, lineFlag, func(sty statusStyles) {
        lineWidth := attributionLineColumnWidth(result.Lines)
        const checkpointColumnWidth = 21
        fmt.Fprintf(w, "  %*s  Tag   %-12s  %-18s  %-16s  %-21s  Content\n",
            lineWidth, "Line", "Agent", "Model", "Author", "Checkpoint/Session")
        fmt.Fprintf(w, "  %s\n", sty.render(sty.dim, strings.Repeat("─", lineWidth+92)))

if len(result.Lines) == 0 {
            fmt.Fprintln(w, sty.render(sty.dim, "  No lines to display."))
            return
        }
        for _, line := range result.Lines {
            fmt.Fprintf(w, "  %s  %s  %-12s  %-18s  %-16s  %-21s  %s\n",
                sty.render(sty.dim, fmt.Sprintf("%*d", lineWidth, line.LineNumber)),
                renderAttributionTag(sty, line.Authorship),
                stringutil.TruncateRunes(line.Agent, 12, ""),
                stringutil.TruncateRunes(line.Model, 18, ""),
                stringutil.TruncateRunes(shortAuthorName(line.Author), 16, ""),
                stringutil.TruncateRunes(shortCheckpointSession(line), checkpointColumnWidth, ""),
                renderAttributionContent(sty, line),
            )
        }

fmt.Fprintf(w, "  %s\n", sty.render(sty.dim, strings.Repeat("─", lineWidth+92)))
        renderAttributionSummary(w, sty, result.Summary, lineFlag)
    })
}

func renderAttributionSummary(w io.Writer, sty statusStyles, summary attributionSummary, lineFlag string) {