Changesets · Branches · Tags · Compare
| Changeset | d40a7b9638b18d541fcd2f9ff490f59980018ff9f52c0f89cf142eabc40e7d4a |
|---|---|
| Author | Dallin Romney <dallinromney@gmail.com> · 2025-07-03 02:53 -07:00 |
| Committer | Dallin Romney <dallinromney@gmail.com> · 2025-07-03 15:03 -07:00 |
| Parents | 5232d029f7d6 |
2 files changed
modified core/tools/implementations/lsTool.ts +15 −8
| @@ -36,18 +36,25 @@ | ||
| 36 | 36 | ? lines.join("\n") |
| 37 | 37 | : `No files/folders found in ${dirPath}`; |
| 38 | 38 | |
| 39 | - if (entries.length > MAX_LS_TOOL_LINES) { | |
| 40 | - content += `\n... ${entries.length - MAX_LS_TOOL_LINES} entries were truncated`; | |
| 41 | - if (args?.recursive) { | |
| 42 | - content += ". Try using a non-recursive search"; | |
| 43 | - } | |
| 44 | - } | |
| 45 | - | |
| 46 | - return [ | |
| 39 | + const contextItems = [ | |
| 47 | 40 | { |
| 48 | 41 | name: "File/folder list", |
| 49 | 42 | description: `Files/folders in ${dirPath}`, |
| 50 | 43 | content, |
| 51 | 44 | }, |
| 52 | 45 | ]; |
| 46 | + | |
| 47 | + if (entries.length > MAX_LS_TOOL_LINES) { | |
| 48 | + let warningContent = `${entries.length - MAX_LS_TOOL_LINES} ls entries were truncated`; | |
| 49 | + if (args?.recursive) { | |
| 50 | + warningContent += ". Try using a non-recursive search"; | |
| 51 | + } | |
| 52 | + contextItems.push({ | |
| 53 | + name: "ls truncation warning", | |
| 54 | + description: "Informs the model that ls results were truncated", | |
| 55 | + content: warningContent, | |
| 56 | + }); | |
| 57 | + } | |
| 58 | + | |
| 59 | + return contextItems; | |
| 53 | 60 | }; |
modified core/tools/implementations/lsTool.vitest.ts +11 −5
| @@ -49,15 +49,19 @@ | ||
| 49 | 49 | ); |
| 50 | 50 | |
| 51 | 51 | // Check that the result contains the truncation message |
| 52 | - expect(result[0].content).toContain("... 50 entries were truncated"); | |
| 52 | + expect(result.length).toBe(2); | |
| 53 | + expect(result[0].content).toContain("file1.txt"); | |
| 54 | + expect(result[0].content).toContain("file199.txt"); | |
| 55 | + expect(result[1].content).toContain("Try using a non-recursive search"); | |
| 56 | + expect(result[1].content).toContain("50 ls entries were truncated"); | |
| 53 | 57 | |
| 54 | 58 | // Check that only MAX_LS_TOOL_LINES entries are included |
| 55 | 59 | const contentLines = result[0].content.split("\n"); |
| 56 | 60 | // Account for the truncation message line |
| 57 | - expect(contentLines.length).toBe(201); | |
| 61 | + expect(contentLines.length).toBe(200); | |
| 58 | 62 | |
| 59 | 63 | // Check the suggestion to use non-recursive search is included |
| 60 | - expect(result[0].content).toContain("Try using a non-recursive search"); | |
| 64 | + expect(result[1].content).toContain("Try using a non-recursive search"); | |
| 61 | 65 | }); |
| 62 | 66 | |
| 63 | 67 | test("lsToolImpl shows truncation message without suggestion for non-recursive search", async () => { |
| @@ -73,10 +77,11 @@ | ||
| 73 | 77 | ); |
| 74 | 78 | |
| 75 | 79 | // Check that the result contains the truncation message |
| 76 | - expect(result[0].content).toContain("... 50 entries were truncated"); | |
| 80 | + expect(result.length).toBe(2); | |
| 81 | + expect(result[1].content).toContain("50 ls entries were truncated"); | |
| 77 | 82 | |
| 78 | 83 | // Check that the suggestion to use non-recursive search is NOT included |
| 79 | - expect(result[0].content).not.toContain("Try using a non-recursive search"); | |
| 84 | + expect(result[1].content).not.toContain("Try using a non-recursive search"); | |
| 80 | 85 | }); |
| 81 | 86 | |
| 82 | 87 | test("lsToolImpl shows message when no files are found", async () => { |
| @@ -86,5 +91,6 @@ | ||
| 86 | 91 | const result = await lsToolImpl({ dirPath: "emptyDir" }, mockExtras); |
| 87 | 92 | |
| 88 | 93 | // Check that the result contains the "no files found" message |
| 94 | + expect(result.length).toBe(1); | |
| 89 | 95 | expect(result[0].content).toBe("No files/folders found in emptyDir"); |
| 90 | 96 | }); |