|
1 | 1 | import { ToolParameterEntry } from "../state" |
2 | | - |
3 | | -/** |
4 | | - * Extracts a human-readable key from tool metadata for display purposes. |
5 | | - * Used by both deduplication and AI analysis to show what was pruned. |
6 | | - */ |
7 | | -export function extractParameterKey(metadata: { tool: string, parameters?: any }): string { |
8 | | - if (!metadata.parameters) return '' |
9 | | - |
10 | | - const { tool, parameters } = metadata |
11 | | - |
12 | | - if (tool === "read" && parameters.filePath) { |
13 | | - return parameters.filePath |
14 | | - } |
15 | | - if (tool === "write" && parameters.filePath) { |
16 | | - return parameters.filePath |
17 | | - } |
18 | | - if (tool === "edit" && parameters.filePath) { |
19 | | - return parameters.filePath |
20 | | - } |
21 | | - |
22 | | - if (tool === "list") { |
23 | | - return parameters.path || '(current directory)' |
24 | | - } |
25 | | - if (tool === "glob") { |
26 | | - if (parameters.pattern) { |
27 | | - const pathInfo = parameters.path ? ` in ${parameters.path}` : "" |
28 | | - return `"${parameters.pattern}"${pathInfo}` |
29 | | - } |
30 | | - return '(unknown pattern)' |
31 | | - } |
32 | | - if (tool === "grep") { |
33 | | - if (parameters.pattern) { |
34 | | - const pathInfo = parameters.path ? ` in ${parameters.path}` : "" |
35 | | - return `"${parameters.pattern}"${pathInfo}` |
36 | | - } |
37 | | - return '(unknown pattern)' |
38 | | - } |
39 | | - |
40 | | - if (tool === "bash") { |
41 | | - if (parameters.description) return parameters.description |
42 | | - if (parameters.command) { |
43 | | - return parameters.command.length > 50 |
44 | | - ? parameters.command.substring(0, 50) + "..." |
45 | | - : parameters.command |
46 | | - } |
47 | | - } |
48 | | - |
49 | | - if (tool === "webfetch" && parameters.url) { |
50 | | - return parameters.url |
51 | | - } |
52 | | - if (tool === "websearch" && parameters.query) { |
53 | | - return `"${parameters.query}"` |
54 | | - } |
55 | | - if (tool === "codesearch" && parameters.query) { |
56 | | - return `"${parameters.query}"` |
57 | | - } |
58 | | - |
59 | | - if (tool === "todowrite") { |
60 | | - return `${parameters.todos?.length || 0} todos` |
61 | | - } |
62 | | - if (tool === "todoread") { |
63 | | - return "read todo list" |
64 | | - } |
65 | | - |
66 | | - if (tool === "task" && parameters.description) { |
67 | | - return parameters.description |
68 | | - } |
69 | | - |
70 | | - const paramStr = JSON.stringify(parameters) |
71 | | - if (paramStr === '{}' || paramStr === '[]' || paramStr === 'null') { |
72 | | - return '' |
73 | | - } |
74 | | - return paramStr.substring(0, 50) |
75 | | -} |
| 2 | +import { extractParameterKey } from "../messages/utils" |
76 | 3 |
|
77 | 4 | export function truncate(str: string, maxLen: number = 60): string { |
78 | 5 | if (str.length <= maxLen) return str |
@@ -118,7 +45,7 @@ export function formatPrunedItemsList( |
118 | 45 | const metadata = toolMetadata.get(id) |
119 | 46 |
|
120 | 47 | if (metadata) { |
121 | | - const paramKey = extractParameterKey(metadata) |
| 48 | + const paramKey = extractParameterKey(metadata.tool, metadata.parameters) |
122 | 49 | if (paramKey) { |
123 | 50 | // Use 60 char limit to match notification style |
124 | 51 | const displayKey = truncate(shortenPath(paramKey, workingDirectory), 60) |
|
0 commit comments