Skip to content

Commit 29eadbb

Browse files
committed
cli: Tweak code_search / list directory tool components
1 parent d65f52a commit 29eadbb

File tree

3 files changed

+45
-31
lines changed

3 files changed

+45
-31
lines changed

cli/src/components/tools/code-search.tsx

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,54 +12,61 @@ import type { ToolRenderConfig } from './types'
1212
*/
1313
export const CodeSearchComponent = defineToolComponent({
1414
toolName: 'code_search',
15-
15+
1616
render(toolBlock, theme, options): ToolRenderConfig | null {
1717
const input = toolBlock.input as any
1818
const pattern = input?.pattern ?? ''
1919
const flags = input?.flags ?? ''
20-
20+
const cwd = input?.cwd ?? ''
21+
2122
// Count results from output
2223
let totalResults = 0
2324
let fileCount = 0
24-
25+
2526
if (toolBlock.output && typeof toolBlock.output === 'string') {
2627
const lines = toolBlock.output.split('\n')
2728
const files = new Set<string>()
28-
29+
2930
for (const line of lines) {
3031
const trimmed = line.trim()
31-
32+
3233
// File paths end with a colon and typically start with ./ or /
33-
if (trimmed.endsWith(':') && (trimmed.startsWith('./') || trimmed.startsWith('/'))) {
34+
if (
35+
trimmed.endsWith(':') &&
36+
(trimmed.startsWith('./') || trimmed.startsWith('/'))
37+
) {
3438
files.add(trimmed.slice(0, -1)) // Remove trailing colon
3539
}
3640
// Result lines start with a number followed by a colon
3741
else if (/^\d+:/.test(trimmed)) {
3842
totalResults++
3943
}
4044
}
41-
45+
4246
fileCount = files.size
4347
}
44-
48+
4549
// Build single-line summary
46-
let summary = `"${pattern}"`
47-
48-
if (flags) {
49-
summary += ` ${flags}`
50-
}
51-
52-
summary += ` → ${totalResults} result${totalResults === 1 ? '' : 's'}`
53-
54-
if (fileCount > 0) {
55-
summary += ` across ${fileCount} file${fileCount === 1 ? '' : 's'}`
50+
let summary = ''
51+
52+
summary += `${pattern}`
53+
54+
if (cwd) {
55+
summary += ` in ${cwd}`
5656
}
57-
57+
58+
// Disable showing flags since they are noisy.
59+
// if (flags) {
60+
// summary += ` ${flags}`
61+
// }
62+
63+
summary += ` (${totalResults} result${totalResults === 1 ? '' : 's'})`
64+
5865
// Return as content using SimpleToolCallItem
5966
return {
6067
content: (
6168
<SimpleToolCallItem
62-
name="Code Search"
69+
name="Search"
6370
description={summary}
6471
branchChar={options.branchChar}
6572
/>

cli/src/components/tools/list-directory.tsx

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,39 @@ import type { ToolRenderConfig } from './types'
1212
*/
1313
export const ListDirectoryComponent = defineToolComponent({
1414
toolName: 'list_directory',
15-
15+
1616
render(toolBlock, theme, options): ToolRenderConfig | null {
1717
const input = toolBlock.input as any
18-
18+
1919
// Extract directories from input
2020
let directories: string[] = []
21-
21+
2222
if (Array.isArray(input?.directories)) {
2323
directories = input.directories
24-
.map((dir: any) => typeof dir === 'object' && dir.path ? dir.path : dir)
25-
.filter((path: any) => typeof path === 'string' && path.trim().length > 0)
26-
} else if (typeof input?.path === 'string' && input.path.trim().length > 0) {
24+
.map((dir: any) =>
25+
typeof dir === 'object' && dir.path ? dir.path : dir,
26+
)
27+
.filter(
28+
(path: any) => typeof path === 'string' && path.trim().length > 0,
29+
)
30+
} else if (
31+
typeof input?.path === 'string' &&
32+
input.path.trim().length > 0
33+
) {
2734
directories = [input.path.trim()]
2835
}
29-
36+
3037
if (directories.length === 0) {
3138
return null
3239
}
33-
40+
3441
// Format directory list
3542
const description = directories.join(', ')
36-
43+
3744
return {
3845
content: (
3946
<SimpleToolCallItem
40-
name="List Directories"
47+
name="List"
4148
description={description}
4249
branchChar={options.branchChar}
4350
/>

cli/src/components/tools/tool-call-item.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export const SimpleToolCallItem = ({
135135

136136
return (
137137
<box style={{ flexDirection: 'row', alignItems: 'center', width: '100%' }}>
138-
<text style={{ wrapMode: 'none' }}>
138+
<text style={{ wrapMode: 'word' }}>
139139
<span fg={theme.foreground}>{branchChar || bulletChar}</span>
140140
<span fg={theme.foreground} attributes={TextAttributes.BOLD}>
141141
{name}

0 commit comments

Comments
 (0)