Skip to content

Commit 41189c5

Browse files
authored
Merge pull request #124 from Opencode-DCP/refactor/consolidate-extractParameterKey
refactor: consolidate duplicate extractParameterKey function
2 parents 760be9d + c8a5bbc commit 41189c5

File tree

2 files changed

+4
-75
lines changed

2 files changed

+4
-75
lines changed

lib/messages/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import type { WithParts } from "../state"
55
* Used by both deduplication and AI analysis to show what was pruned.
66
*/
77
export const extractParameterKey = (tool: string, parameters: any): string => {
8+
if (!parameters) return ''
9+
810
if (tool === "read" && parameters.filePath) {
911
return parameters.filePath
1012
}

lib/ui/display-utils.ts

Lines changed: 2 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,5 @@
11
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"
763

774
export function truncate(str: string, maxLen: number = 60): string {
785
if (str.length <= maxLen) return str
@@ -118,7 +45,7 @@ export function formatPrunedItemsList(
11845
const metadata = toolMetadata.get(id)
11946

12047
if (metadata) {
121-
const paramKey = extractParameterKey(metadata)
48+
const paramKey = extractParameterKey(metadata.tool, metadata.parameters)
12249
if (paramKey) {
12350
// Use 60 char limit to match notification style
12451
const displayKey = truncate(shortenPath(paramKey, workingDirectory), 60)

0 commit comments

Comments
 (0)