From 75190d53edf05ba50b4d430ac353576644fb07a4 Mon Sep 17 00:00:00 2001 From: Rodin Date: Fri, 1 May 2026 20:02:35 -0700 Subject: [PATCH] fix: address review findings (comment, marker budget, naming) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - UserMeta comment: "never trimmed" → "truncated only if base exceeds budget" - Skip diff truncation marker when diffBudget < markerBudget (prevents marker itself from pushing EstTokens over the limit) - Rename filepath → filePath to avoid shadowing stdlib package name --- budget/budget.go | 8 ++++++-- cmd/review-bot/main.go | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/budget/budget.go b/budget/budget.go index 9d30f00..3624efe 100644 --- a/budget/budget.go +++ b/budget/budget.go @@ -65,7 +65,7 @@ type Sections struct { Conventions string // Repo conventions (trimmed second) FileContext string // Full file content (trimmed third) Diff string // The actual diff (trimmed last, only truncated) - UserMeta string // PR title, description, CI status (never trimmed) + UserMeta string // PR title, description, CI status (truncated only if base exceeds budget) } // Result holds the trimmed content and metadata about what was dropped. @@ -154,7 +154,11 @@ func Fit(model string, sections Sections) Result { removed := EstimateTokens(sections.Diff) - diffBudget trimmed = append(trimmed, fmt.Sprintf("diff truncated (~%dK tokens removed)", removed/1000)) if maxChars > 0 { - sections.Diff = truncateUTF8(sections.Diff, maxChars) + diffTruncMarker + if diffBudget >= markerBudget { + sections.Diff = truncateUTF8(sections.Diff, maxChars) + diffTruncMarker + } else { + sections.Diff = truncateUTF8(sections.Diff, maxChars) + } } else { sections.Diff = diffTooLargeMarker } diff --git a/cmd/review-bot/main.go b/cmd/review-bot/main.go index 0c52a87..8b93751 100644 --- a/cmd/review-bot/main.go +++ b/cmd/review-bot/main.go @@ -255,12 +255,12 @@ func fetchPatterns(ctx context.Context, client *gitea.Client, patternsRepo, patt continue } - for filepath, content := range files { + for filePath, content := range files { // Only include markdown and text files as patterns - if !isPatternFile(filepath) { + if !isPatternFile(filePath) { continue } - sb.WriteString(fmt.Sprintf("### %s/%s\n\n%s\n\n", repoRef, filepath, content)) + sb.WriteString(fmt.Sprintf("### %s/%s\n\n%s\n\n", repoRef, filePath, content)) } } }