Elffuss BraidHub

kikocis/continue public

move to warning context item paradigm and update tests for ls tool
Changesetd40a7b9638b18d541fcd2f9ff490f59980018ff9f52c0f89cf142eabc40e7d4a
AuthorDallin Romney <dallinromney@gmail.com> · 2025-07-03 02:53 -07:00
CommitterDallin Romney <dallinromney@gmail.com> · 2025-07-03 15:03 -07:00
Parents5232d029f7d6

Browse the files at this changeset

2 files changed

modified core/tools/implementations/lsTool.ts +15 −8
@@ -36,18 +36,25 @@
3636 ? lines.join("\n")
3737 : `No files/folders found in ${dirPath}`;
3838
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 = [
4740 {
4841 name: "File/folder list",
4942 description: `Files/folders in ${dirPath}`,
5043 content,
5144 },
5245 ];
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;
5360 };
modified core/tools/implementations/lsTool.vitest.ts +11 −5
@@ -49,15 +49,19 @@
4949 );
5050
5151 // 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");
5357
5458 // Check that only MAX_LS_TOOL_LINES entries are included
5559 const contentLines = result[0].content.split("\n");
5660 // Account for the truncation message line
57- expect(contentLines.length).toBe(201);
61+ expect(contentLines.length).toBe(200);
5862
5963 // 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");
6165 });
6266
6367 test("lsToolImpl shows truncation message without suggestion for non-recursive search", async () => {
@@ -73,10 +77,11 @@
7377 );
7478
7579 // 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");
7782
7883 // 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");
8085 });
8186
8287 test("lsToolImpl shows message when no files are found", async () => {
@@ -86,5 +91,6 @@
8691 const result = await lsToolImpl({ dirPath: "emptyDir" }, mockExtras);
8792
8893 // Check that the result contains the "no files found" message
94+ expect(result.length).toBe(1);
8995 expect(result[0].content).toBe("No files/folders found in emptyDir");
9096 });