feat(cli): implement compact tool output (#20974)

This commit is contained in:
Jarrod Whelan
2026-03-30 16:43:29 -07:00
committed by GitHub
parent 3e95b8ec59
commit 1df5c98b33
45 changed files with 2670 additions and 386 deletions
+19 -7
View File
@@ -6,7 +6,7 @@
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
import { GrepTool, type GrepToolParams } from './grep.js';
import type { ToolResult } from './tools.js';
import type { ToolResult, GrepResult } from './tools.js';
import path from 'node:path';
import { isSubpath } from '../utils/paths.js';
import fs from 'node:fs/promises';
@@ -187,7 +187,9 @@ describe('GrepTool', () => {
`File: ${path.join('sub', 'fileC.txt')}`,
);
expect(result.llmContent).toContain('L1: another world in sub dir');
expect(result.returnDisplay).toBe('Found 3 matches');
expect((result.returnDisplay as GrepResult)?.summary).toBe(
'Found 3 matches',
);
}, 30000);
it('should include files that start with ".." in JS fallback', async () => {
@@ -228,7 +230,9 @@ describe('GrepTool', () => {
);
expect(result.llmContent).toContain('File: fileC.txt'); // Path relative to 'sub'
expect(result.llmContent).toContain('L1: another world in sub dir');
expect(result.returnDisplay).toBe('Found 1 match');
expect((result.returnDisplay as GrepResult)?.summary).toBe(
'Found 1 match',
);
}, 30000);
it('should find matches with an include glob', async () => {
@@ -245,7 +249,9 @@ describe('GrepTool', () => {
expect(result.llmContent).toContain(
'L2: function baz() { return "hello"; }',
);
expect(result.returnDisplay).toBe('Found 1 match');
expect((result.returnDisplay as GrepResult)?.summary).toBe(
'Found 1 match',
);
}, 30000);
it('should find matches with an include glob and path', async () => {
@@ -265,7 +271,9 @@ describe('GrepTool', () => {
);
expect(result.llmContent).toContain('File: another.js');
expect(result.llmContent).toContain('L1: const greeting = "hello";');
expect(result.returnDisplay).toBe('Found 1 match');
expect((result.returnDisplay as GrepResult)?.summary).toBe(
'Found 1 match',
);
}, 30000);
it('should return "No matches found" when pattern does not exist', async () => {
@@ -275,7 +283,9 @@ describe('GrepTool', () => {
expect(result.llmContent).toContain(
'No matches found for pattern "nonexistentpattern" in the workspace directory.',
);
expect(result.returnDisplay).toBe('No matches found');
expect((result.returnDisplay as GrepResult)?.summary).toBe(
'No matches found',
);
}, 30000);
it('should handle regex special characters correctly', async () => {
@@ -501,7 +511,9 @@ describe('GrepTool', () => {
expect(result.llmContent).toContain('L2: second line with world');
// And sub/fileC.txt should be excluded because limit reached
expect(result.llmContent).not.toContain('File: sub/fileC.txt');
expect(result.returnDisplay).toBe('Found 2 matches (limited)');
expect((result.returnDisplay as GrepResult)?.summary).toBe(
'Found 2 matches (limited)',
);
});
it('should respect max_matches_per_file in JS fallback', async () => {