@serkanalgur/opencodev2-slim 2.0.4 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +15 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serkanalgur/opencodev2-slim",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "Smart context management plugin for OpenCode v2 - semantic compression, cost-aware pruning, adaptive thresholds",
5
5
  "keywords": [
6
6
  "opencode",
package/src/index.ts CHANGED
@@ -308,17 +308,21 @@ export default Plugin.define({
308
308
 
309
309
  const state = getState(sessionId, config)
310
310
 
311
- // Apply pruning strategies
312
- const pruned = pruneMessages(
313
- event.messages.map((m: any) => wrapAsMessageWithParts(m)),
314
- config,
315
- event.messages.length,
316
- )
317
-
318
- // Replace messages in-place
319
- event.messages.length = 0
320
- for (const msg of pruned) {
321
- event.messages.push(msg as any)
311
+ // Apply pruning - work with original OpenCode message format
312
+ // event.messages contains { role, content: Part[], ... } objects
313
+ const wrapped = event.messages.map((m: any) => wrapAsMessageWithParts(m))
314
+ const pruned = pruneMessages(wrapped, config, event.messages.length)
315
+
316
+ // Build a Set of pruned message IDs to keep
317
+ const keepIds = new Set(pruned.map((m) => m.info.id))
318
+
319
+ // Remove duplicates in-place, preserving OpenCode's message format
320
+ for (let i = event.messages.length - 1; i >= 0; i--) {
321
+ const msg = event.messages[i] as any
322
+ const id = msg.id || msg.info?.id
323
+ if (id && !keepIds.has(id)) {
324
+ event.messages.splice(i, 1)
325
+ }
322
326
  }
323
327
 
324
328
  // Quick token estimate (sync, ~4 chars per token)