Skip to content

Commit 21ebf60

Browse files
author
Eric Wheeler
committed
broken: hook in
1 parent 3506261 commit 21ebf60

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/core/sliding-window/index.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,33 @@ export async function truncateConversationIfNeeded({
9595
// Truncate if we're within TOKEN_BUFFER_PERCENTAGE of the context window
9696
const allowedTokens = contextWindow * (1 - TOKEN_BUFFER_PERCENTAGE) - reservedTokens
9797

98+
// Apply compression to reduce token usage while preserving information
99+
// Generate filenames with timestamp
100+
const timestamp = Date.now()
101+
const dateStr = new Date(timestamp)
102+
.toLocaleString("en-US", {
103+
month: "short",
104+
day: "2-digit",
105+
year: "numeric",
106+
hour: "2-digit",
107+
minute: "2-digit",
108+
second: "2-digit",
109+
hour12: false,
110+
})
111+
.toLowerCase()
112+
.replace(/[,:]/g, "-")
113+
.replace(/\s+/g, "-")
114+
115+
const debugDir = path.join(this.providerRef.deref()?.context.extensionUri.fsPath || "", "debug")
116+
const beforeName = path.join(debugDir, `conversation_before_compression_${timestamp}_${dateStr}.json`)
117+
const afterName = path.join(debugDir, `conversation_after_compression_${timestamp}_${dateStr}.json`)
118+
119+
await compressConversationHistory(messages, this.taskId, beforeName, afterName)
120+
98121
// Determine if truncation is needed and apply if necessary
99-
return effectiveTokens > allowedTokens ? truncateConversation(messages, 0.5) : messages
122+
if (effectiveTokens > allowedTokens) {
123+
messages = truncateConversation(messages, 0.5)
124+
}
125+
126+
return messages
100127
}

0 commit comments

Comments
 (0)