Problem
When truncating large content to fit context windows, naive truncation (cut at character/line limit) breaks code understanding:
- Functions get cut mid-body
- Import statements separated from usage
- Class definitions incomplete
Concrete example from foreman: When a 2000-line file is truncated to 500 lines, it often cuts in the middle of a function, making the code unusable for analysis.
Proposal
Add language-aware truncation that respects code structure:
// Truncation options
type TruncateOptions struct {
MaxLines int
MaxTokens int
Language string // "typescript", "go", "python", etc.
PreserveTop bool // Keep imports/headers
PreserveFunc bool // Don't cut mid-function
}
// Usage
content := sdk.TruncateCode(fileContent, TruncateOptions{
MaxLines: 500,
Language: "typescript",
PreserveTop: true,
PreserveFunc: true,
})
General Utility
- Code review agents - Summarizing large files intelligently
- Documentation generators - Extracting relevant code sections
- Refactoring tools - Understanding code structure before changes
Acceptance Criteria
Priority
Medium - Improves agent effectiveness but not blocking.
Labels
enhancement, sdk, priority:medium
Problem
When truncating large content to fit context windows, naive truncation (cut at character/line limit) breaks code understanding:
Concrete example from foreman: When a 2000-line file is truncated to 500 lines, it often cuts in the middle of a function, making the code unusable for analysis.
Proposal
Add language-aware truncation that respects code structure:
General Utility
Acceptance Criteria
TruncateCodefunction with language awarenessPreserveTopenabledPreserveFuncenabledPriority
Medium - Improves agent effectiveness but not blocking.
Labels
enhancement, sdk, priority:medium