feat(background-file) Add the background-file CLI option#206
Conversation
68a516f to
2e81436
Compare
…cal business context file
2e81436 to
be6b2b1
Compare
lizhengfeng101
left a comment
There was a problem hiding this comment.
Code Review
Overall: Good quality PR with thorough test coverage. A few issues to address before merging.
Issue 1 (Bug): mergeBackground unconditionally changes existing --background behavior
In review_cmd.go, mergeBackground is called even when --background-file is not used:
opts.background = mergeBackground(opts.background, fileBackground)Since mergeBackground internally calls sanitizeMarkdown(inline), users who only use --background (without -B) will now have their content sanitized (control chars stripped, excess newlines collapsed, whitespace trimmed). This is an implicit behavioral change for existing users.
Suggestion: Only call mergeBackground when backgroundFile is actually set:
if opts.backgroundFile != "" {
fileBackground, err = loadBackgroundFile(opts.backgroundFile)
if err != nil {
return err
}
opts.background = mergeBackground(opts.background, fileBackground)
}Issue 2 (Bug): Localized README files not updated
The project requires all localized READMEs to be kept in sync when README.md is modified (README.zh-CN.md, README.ja-JP.md, README.ko-KR.md, README.ru-RU.md). The PR adds the --background-file row and usage examples to README.md but none of the four localized versions were updated.
Issue 3 (Design): Inconsistent wrapping between inline and file content
loadBackgroundFile wraps file content in <ocr_user_background> tags, but mergeBackground does not apply the same wrapping to inline content. After merging, opts.background looks like:
inline context here
<ocr_user_background>
file content here
</ocr_user_background>
If this asymmetry is intentional (e.g. inline content is short and trusted), it would be worth a brief code comment explaining why.
Issue 4 (Minor): Hard limit error message includes wrapper overhead
The character count check in loadBackgroundFile runs on the wrapped string (after adding <ocr_user_background> tags, ~40+ chars of overhead):
if n := len([]rune(wrapped)); n > backgroundHardLimit {The error message says "background content is X characters, exceeding the hard limit of 8000" but X includes wrapper overhead that the user cannot control. Consider either checking cleaned instead of wrapped, or adjusting the limit to account for the overhead internally.
Issue 5 (Minor): Redundant checks in isForbiddenChar
All characters listed in the switch (, , , , , , , ) belong to Unicode category Cf, which is already caught by the final unicode.Is(unicode.Cf, r) call. The explicit entries serve as documentation, so this is not a correctness issue — just noting the redundancy.
Issue 6 (Minor): Performance test has no assertion
TestLoadBackgroundFilePerformance runs 1000 iterations of sanitizeMarkdown but doesn't assert on timing. To actually guard against quadratic regressions, consider converting it to a func BenchmarkSanitizeMarkdown(b *testing.B) so go test -bench produces meaningful data.
Highlights
- Excellent test coverage: edge cases for empty files, directories, oversized files, multi-byte runes, delimiter injection, CRLF normalization, soft/hard limits
TestBackgroundFromCommitThenFileis a well-designed end-to-end test for the commit message + file merge path- Good security considerations: reserved delimiter injection check, file size limits, control character sanitization
- Help text alignment cleanup is a nice touch
| Category | Count |
|---|---|
| Bug / Must fix | 2 (behavioral change + README localization) |
| Design discussion | 1 (wrapping inconsistency) |
| Minor suggestions | 3 |
feat(background-file) Add the background-file CLI option to read a local business context file
Description
Following discussion in #176 add the new -B flag :
Type of Change
How Has This Been Tested?
make testpasses locallysoft limit
hard limit
I also checked I see the two prompts in the session file when using -b and -B flags.
Checklist
go fmt,go vet)Related Issues