agent-cache-optimizer 0.5.2 → 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 +7 -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,26 +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
|
-
((!db.contentIndex || Object.keys(db.contentIndex).length === 0) ||
|
|
47
|
-
db.contentObservations === undefined)
|
|
48
|
-
) {
|
|
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
|
|
49
46
|
db.contentIndex = {}
|
|
50
|
-
for (const fps of Object.values(db.positions)) {
|
|
51
|
-
for (const fp of fps) {
|
|
52
|
-
const existing = db.contentIndex[fp.hash]
|
|
53
|
-
if (existing) {
|
|
54
|
-
existing.count = Math.max(existing.count, fp.count)
|
|
55
|
-
if (fp.lastSeen > existing.lastSeen) existing.lastSeen = fp.lastSeen
|
|
56
|
-
} else {
|
|
57
|
-
db.contentIndex[fp.hash] = { ...fp }
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
47
|
db.contentScores = {}
|
|
62
|
-
db.contentObservations = 0
|
|
48
|
+
db.contentObservations = 0
|
|
63
49
|
saveDB(agent, db)
|
|
64
50
|
}
|
|
65
51
|
return db
|
|
@@ -215,7 +201,7 @@ export const CacheOptimizerPlugin: Plugin = async () => {
|
|
|
215
201
|
const warmCount = warmHashes?.size ?? 0
|
|
216
202
|
diag(
|
|
217
203
|
agent,
|
|
218
|
-
`
|
|
204
|
+
`v${VERSION} loaded agent=${agent} model=${input.model?.id ?? "?"} ` +
|
|
219
205
|
`warm=${warmCount}`,
|
|
220
206
|
)
|
|
221
207
|
}
|