Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/easy-stamps-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"kilo-code": patch
---

fix: treat maxReadFileLine=0 as unlimited (same as -1)
16 changes: 11 additions & 5 deletions src/integrations/misc/__tests__/extract-text-large-files.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,22 @@ describe("extractTextFromFile - Large File Handling", () => {
expect(result).toContain("[File truncated: showing 500 of 10000 total lines")
})

it("should handle maxReadFileLine of 0 by throwing an error", async () => {
// kilocode_change start - 0 is treated as unlimited for backward compatibility
it("should handle maxReadFileLine of 0 by treating as unlimited", async () => {
const fileContent = "Line 1\nLine 2\nLine 3"

mockedFs.readFile.mockResolvedValue(fileContent as any)

// maxReadFileLine of 0 should throw an error
await expect(extractTextFromFile("/test/file.ts", 0)).rejects.toThrow(
"Invalid maxReadFileLine: 0. Must be a positive integer or -1 for unlimited.",
)
// maxReadFileLine of 0 should be treated as unlimited (same as -1)
const result = await extractTextFromFile("/test/file.ts", 0)

// Should include all content with line numbers
expect(result).toContain("1 | Line 1")
expect(result).toContain("2 | Line 2")
expect(result).toContain("3 | Line 3")
expect(result).not.toContain("[File truncated:")
})
// kilocode_change end

it("should handle negative maxReadFileLine by treating as undefined", async () => {
const fileContent = "Line 1\nLine 2\nLine 3"
Expand Down
9 changes: 6 additions & 3 deletions src/integrations/misc/extract-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,15 @@ export function getSupportedBinaryFormats(): string[] {
*/
export async function extractTextFromFile(filePath: string, maxReadFileLine?: number): Promise<string> {
// Validate maxReadFileLine parameter
if (maxReadFileLine !== undefined && maxReadFileLine !== -1) {
// kilocode_change start - 0 is treated as unlimited (same as -1) for backward compatibility
if (maxReadFileLine !== undefined && maxReadFileLine !== -1 && maxReadFileLine !== 0) {
if (!Number.isInteger(maxReadFileLine) || maxReadFileLine < 1) {
throw new Error(
`Invalid maxReadFileLine: ${maxReadFileLine}. Must be a positive integer or -1 for unlimited.`,
`Invalid maxReadFileLine: ${maxReadFileLine}. Must be a positive integer, 0, or -1 for unlimited.`,
)
}
}
// kilocode_change end

try {
await fs.access(filePath)
Expand All @@ -90,7 +92,8 @@ export async function extractTextFromFile(filePath: string, maxReadFileLine?: nu

if (!isBinary) {
// Check if we need to apply line limit
if (maxReadFileLine !== undefined && maxReadFileLine !== -1) {
// kilocode_change - 0 is treated as unlimited (same as -1) for backward compatibility
if (maxReadFileLine !== undefined && maxReadFileLine !== -1 && maxReadFileLine !== 0) {
const totalLines = await countFileLines(filePath)
if (totalLines > maxReadFileLine) {
// Read only up to maxReadFileLine (endLine is 0-based and inclusive)
Expand Down
Loading