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: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Automatically reduces token usage in OpenCode by removing obsolete tool outputs from conversation history.

![DCP in action](dcp-demo.png)
![DCP in action](dcp-demo3.png)

## Installation

Expand Down
Binary file added dcp-demo2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dcp-demo3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 0 additions & 4 deletions lib/state/id-mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ export function getActualId(sessionId: string, numericId: number): string | unde
return mapping?.numericToActual.get(numericId)
}

export function clearSessionMapping(sessionId: string): void {
sessionMappings.delete(sessionId)
}

export function clearAllMappings(): void {
sessionMappings.clear()
}
68 changes: 1 addition & 67 deletions lib/ui/notification.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Logger } from "../logger"
import type { SessionStats, GCStats, PruningResult } from "../core/janitor"
import type { SessionStats, GCStats } from "../core/janitor"
import type { ToolMetadata } from "../fetch-wrapper/types"
import { formatTokenCount } from "../tokenizer"
import { extractParameterKey } from "./display-utils"
Expand Down Expand Up @@ -146,72 +146,6 @@ function buildDetailedMessage(data: NotificationData, workingDirectory?: string)
return message.trim()
}

export function formatPruningResultForTool(
result: PruningResult,
workingDirectory?: string
): string {
const lines: string[] = []
lines.push(`Context pruning complete. Pruned ${result.prunedCount} tool outputs.`)
lines.push('')

if (result.llmPrunedIds.length > 0) {
lines.push(`Semantically pruned (${result.llmPrunedIds.length}):`)
const toolsSummary = buildToolsSummary(result.llmPrunedIds, result.toolMetadata, workingDirectory)
lines.push(...formatToolSummaryLines(toolsSummary))
}

return lines.join('\n').trim()
}

export function buildToolsSummary(
prunedIds: string[],
toolMetadata: Map<string, ToolMetadata>,
workingDirectory?: string
): Map<string, string[]> {
const toolsSummary = new Map<string, string[]>()

for (const prunedId of prunedIds) {
const normalizedId = prunedId.toLowerCase()
const metadata = toolMetadata.get(normalizedId)
if (metadata) {
const toolName = metadata.tool
if (!toolsSummary.has(toolName)) {
toolsSummary.set(toolName, [])
}

const paramKey = extractParameterKey(metadata)
if (paramKey) {
const displayKey = truncate(shortenPath(paramKey, workingDirectory), 80)
toolsSummary.get(toolName)!.push(displayKey)
} else {
toolsSummary.get(toolName)!.push('(default)')
}
}
}

return toolsSummary
}

export function formatToolSummaryLines(
toolsSummary: Map<string, string[]>,
indent: string = ' '
): string[] {
const lines: string[] = []

for (const [toolName, params] of toolsSummary.entries()) {
if (params.length === 1) {
lines.push(`${indent}${toolName}: ${params[0]}`)
} else if (params.length > 1) {
lines.push(`${indent}${toolName} (${params.length}):`)
for (const param of params) {
lines.push(`${indent} ${param}`)
}
}
}

return lines
}

function truncate(str: string, maxLen: number = 60): string {
if (str.length <= maxLen) return str
return str.slice(0, maxLen - 3) + '...'
Expand Down