opencode-context-indicator 1.1.3 → 1.1.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.
- package/README.md +60 -0
- package/index.js +710 -179
- package/lib/dedup.js +12 -3
- package/package.json +17 -4
- package/tui.tsx +3 -1
package/lib/dedup.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
// EXPORTS
|
|
19
19
|
// claimOnce(key, dedupDir) atomic cross-instance / cross-process claim
|
|
20
20
|
// pruneDedup(dedupDir) delete claim markers older than DEDUP_TTL_MS
|
|
21
|
-
// pruneMap(map, maxSize)
|
|
21
|
+
// pruneMap(map, maxSize) FIFO-trim an in-process Map (insertion order)
|
|
22
22
|
// DEDUP_TTL_MS marker lifetime (24h)
|
|
23
23
|
//
|
|
24
24
|
// The claim mechanism is the exact one proven in token-usage-logger.js:
|
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
statSync,
|
|
38
38
|
unlinkSync,
|
|
39
39
|
} from "node:fs";
|
|
40
|
+
import { createHash } from "node:crypto";
|
|
40
41
|
import { join } from "node:path";
|
|
41
42
|
|
|
42
43
|
export const DEDUP_TTL_MS = 24 * 60 * 60 * 1000; // prune claim markers after a day
|
|
@@ -59,7 +60,10 @@ function logErr(msg, err) {
|
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
62
|
|
|
62
|
-
// Trim an in-process Map to at most `maxSize` entries
|
|
63
|
+
// Trim an in-process Map to at most `maxSize` entries. This is FIFO, not LRU:
|
|
64
|
+
// it deletes the OLDEST INSERTED keys and `set()` on an existing key does NOT
|
|
65
|
+
// move it to the end, so a frequently-updated key can still be evicted once it
|
|
66
|
+
// ages out of the insertion order.
|
|
63
67
|
export function pruneMap(map, maxSize) {
|
|
64
68
|
if (!map || map.size <= maxSize) return;
|
|
65
69
|
const excess = map.size - maxSize;
|
|
@@ -77,8 +81,13 @@ export function pruneMap(map, maxSize) {
|
|
|
77
81
|
export function claimOnce(key, dedupDir) {
|
|
78
82
|
try {
|
|
79
83
|
mkdirSync(dedupDir, { recursive: true });
|
|
84
|
+
// The sanitised name alone collapses distinct keys (e.g. "a/b" and "a_b" both
|
|
85
|
+
// become "a_b") into the SAME marker -> a false "already claimed". Append a
|
|
86
|
+
// stable hash of the ORIGINAL key so distinct keys get distinct markers while
|
|
87
|
+
// an identical key maps to an identical name in every instance/process.
|
|
80
88
|
const safe = String(key).replace(/[^a-zA-Z0-9._-]/g, "_").slice(0, 200);
|
|
81
|
-
const
|
|
89
|
+
const hash = createHash("sha1").update(String(key)).digest("hex").slice(0, 12);
|
|
90
|
+
const fd = openSync(join(dedupDir, `${safe}.${hash}.seen`), "wx");
|
|
82
91
|
closeSync(fd);
|
|
83
92
|
const now = Date.now();
|
|
84
93
|
if (now - lastPruneAt >= PRUNE_MIN_INTERVAL_MS) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-context-indicator",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"description": "Real-time OpenCode context-window usage indicator: per-category token breakdown written to a log file, plus an optional TUI sidebar. Dual V1 + V2 plugin entry.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,9 +31,14 @@
|
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
33
33
|
"author": "VladSmr",
|
|
34
|
-
"repository": {
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git+https://github.com/VladSmr/opencode-context-indicator.git"
|
|
37
|
+
},
|
|
35
38
|
"homepage": "https://github.com/VladSmr/opencode-context-indicator#readme",
|
|
36
|
-
"bugs": {
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/VladSmr/opencode-context-indicator/issues"
|
|
41
|
+
},
|
|
37
42
|
"peerDependencies": {
|
|
38
43
|
"@opencode/plugin": ">=2.0.16",
|
|
39
44
|
"@opentui/core": ">=0.5.12",
|
|
@@ -56,6 +61,14 @@
|
|
|
56
61
|
"devDependencies": {
|
|
57
62
|
"@opencode/plugin": "^2.0.19",
|
|
58
63
|
"@opentui/core": "^0.5.12",
|
|
64
|
+
"esbuild": "^0.28.2",
|
|
65
|
+
"node-pty": "^1.1.0",
|
|
59
66
|
"solid-js": "^1.9.12"
|
|
60
|
-
}
|
|
67
|
+
},
|
|
68
|
+
"scripts": {
|
|
69
|
+
"test:prepublish": "node test/prepublish.mjs",
|
|
70
|
+
"test:e2e": "node test/e2e-tui.mjs --full",
|
|
71
|
+
"test:e2e:quick": "node test/e2e-tui.mjs --quick"
|
|
72
|
+
},
|
|
73
|
+
"prepublishOnly": "node test/prepublish.mjs && node test/e2e-tui.mjs --full"
|
|
61
74
|
}
|
package/tui.tsx
CHANGED
|
@@ -45,7 +45,9 @@ import {tmpdir} from "node:os"
|
|
|
45
45
|
import {join} from "node:path"
|
|
46
46
|
import {fileURLToPath} from "node:url"
|
|
47
47
|
|
|
48
|
-
const STATE_FILE =
|
|
48
|
+
const STATE_FILE =
|
|
49
|
+
process.env.OPENCODE_CONTEXT_INDICATOR_STATE_FILE ||
|
|
50
|
+
join(tmpdir(), "opencode-context-indicator-state.json")
|
|
49
51
|
const POLL_MS = 1000
|
|
50
52
|
const LABEL_WIDTH = 12
|
|
51
53
|
|