Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/messages/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import type { WithParts } from "../state"
* Used by both deduplication and AI analysis to show what was pruned.
*/
export const extractParameterKey = (tool: string, parameters: any): string => {
if (!parameters) return ''

if (tool === "read" && parameters.filePath) {
return parameters.filePath
}
Expand Down
77 changes: 2 additions & 75 deletions lib/ui/display-utils.ts
Original file line number Diff line number Diff line change
@@ -1,78 +1,5 @@
import { ToolParameterEntry } from "../state"

/**
* Extracts a human-readable key from tool metadata for display purposes.
* Used by both deduplication and AI analysis to show what was pruned.
*/
export function extractParameterKey(metadata: { tool: string, parameters?: any }): string {
if (!metadata.parameters) return ''

const { tool, parameters } = metadata

if (tool === "read" && parameters.filePath) {
return parameters.filePath
}
if (tool === "write" && parameters.filePath) {
return parameters.filePath
}
if (tool === "edit" && parameters.filePath) {
return parameters.filePath
}

if (tool === "list") {
return parameters.path || '(current directory)'
}
if (tool === "glob") {
if (parameters.pattern) {
const pathInfo = parameters.path ? ` in ${parameters.path}` : ""
return `"${parameters.pattern}"${pathInfo}`
}
return '(unknown pattern)'
}
if (tool === "grep") {
if (parameters.pattern) {
const pathInfo = parameters.path ? ` in ${parameters.path}` : ""
return `"${parameters.pattern}"${pathInfo}`
}
return '(unknown pattern)'
}

if (tool === "bash") {
if (parameters.description) return parameters.description
if (parameters.command) {
return parameters.command.length > 50
? parameters.command.substring(0, 50) + "..."
: parameters.command
}
}

if (tool === "webfetch" && parameters.url) {
return parameters.url
}
if (tool === "websearch" && parameters.query) {
return `"${parameters.query}"`
}
if (tool === "codesearch" && parameters.query) {
return `"${parameters.query}"`
}

if (tool === "todowrite") {
return `${parameters.todos?.length || 0} todos`
}
if (tool === "todoread") {
return "read todo list"
}

if (tool === "task" && parameters.description) {
return parameters.description
}

const paramStr = JSON.stringify(parameters)
if (paramStr === '{}' || paramStr === '[]' || paramStr === 'null') {
return ''
}
return paramStr.substring(0, 50)
}
import { extractParameterKey } from "../messages/utils"

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

if (metadata) {
const paramKey = extractParameterKey(metadata)
const paramKey = extractParameterKey(metadata.tool, metadata.parameters)
if (paramKey) {
// Use 60 char limit to match notification style
const displayKey = truncate(shortenPath(paramKey, workingDirectory), 60)
Expand Down