fix: address review findings (comment, marker budget, naming)
- 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
This commit is contained in:
+6
-2
@@ -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
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user