agent-cache-optimizer 0.5.1 → 0.5.3
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.
- package/package.json +1 -1
- package/src/index.ts +8 -21
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-cache-optimizer",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"description": "Content-agnostic KV cache optimizer for LLM CLI agents — boosts prompt cache hit rate by 40-88% through automatic stability tracking and block reordering",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kv-cache",
|
package/src/index.ts
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
* that stable content comes FIRST and dynamic content comes LAST,
|
|
6
6
|
* maximizing prefix-match cache reuse across sessions.
|
|
7
7
|
*
|
|
8
|
-
* v0.4: cache warming, savings estimates, conversation log awareness
|
|
9
|
-
*
|
|
10
8
|
* @license MIT
|
|
11
9
|
*/
|
|
12
10
|
|
|
11
|
+
const VERSION = "0.5.3"
|
|
12
|
+
|
|
13
13
|
import type { Plugin } from "@opencode-ai/plugin"
|
|
14
14
|
import { join } from "node:path"
|
|
15
15
|
import { homedir } from "node:os"
|
|
@@ -40,25 +40,12 @@ function loadDB(agent: string): StabilityDB {
|
|
|
40
40
|
const raw = readFileSync(dbPath(agent), "utf-8")
|
|
41
41
|
const db = JSON.parse(raw) as StabilityDB
|
|
42
42
|
// Migrate from pre-0.5.0: rebuild contentIndex from position data
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
Object.keys(db.positions).length > 0
|
|
47
|
-
) {
|
|
43
|
+
// Migrate from pre-0.5.x: ensure contentObservations exists
|
|
44
|
+
if (db.contentObservations === undefined || db.contentObservations === null) {
|
|
45
|
+
// Reset contentIndex — old position-based counts don't map cleanly
|
|
48
46
|
db.contentIndex = {}
|
|
49
|
-
for (const fps of Object.values(db.positions)) {
|
|
50
|
-
for (const fp of fps) {
|
|
51
|
-
const existing = db.contentIndex[fp.hash]
|
|
52
|
-
if (existing) {
|
|
53
|
-
existing.count = Math.max(existing.count, fp.count)
|
|
54
|
-
if (fp.lastSeen > existing.lastSeen) existing.lastSeen = fp.lastSeen
|
|
55
|
-
} else {
|
|
56
|
-
db.contentIndex[fp.hash] = { ...fp }
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
47
|
db.contentScores = {}
|
|
61
|
-
db.contentObservations = 0
|
|
48
|
+
db.contentObservations = 0
|
|
62
49
|
saveDB(agent, db)
|
|
63
50
|
}
|
|
64
51
|
return db
|
|
@@ -214,8 +201,8 @@ export const CacheOptimizerPlugin: Plugin = async () => {
|
|
|
214
201
|
const warmCount = warmHashes?.size ?? 0
|
|
215
202
|
diag(
|
|
216
203
|
agent,
|
|
217
|
-
`
|
|
218
|
-
`warm
|
|
204
|
+
`v${VERSION} loaded agent=${agent} model=${input.model?.id ?? "?"} ` +
|
|
205
|
+
`warm=${warmCount}`,
|
|
219
206
|
)
|
|
220
207
|
}
|
|
221
208
|
},
|