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)) } } }