opencode-context-indicator 1.8.1 → 1.8.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/lib/v2.js CHANGED
@@ -29,6 +29,7 @@ import {
29
29
  import {
30
30
  BREAKDOWN_THROTTLE_MS,
31
31
  breakdownCache,
32
+ breakdownForModel,
32
33
  clearChildSubagentTracking,
33
34
  clearSessionTracking,
34
35
  ERROR_TOAST_DEDUP_MS,
@@ -65,6 +66,7 @@ import { locationDirectory } from "./config.js";
65
66
  import {
66
67
  debugEvent,
67
68
  logErr,
69
+ pruneSessionState,
68
70
  pushFinalSummary,
69
71
  readStateSnapshot,
70
72
  writeLog,
@@ -376,10 +378,21 @@ function onV2Context(context, ctx) {
376
378
  if (!sid) return;
377
379
 
378
380
  const parts = estimateBreakdownFromContext(context, sid);
381
+ // Tag the entry with the model whose payload was measured: a later in-session
382
+ // model switch must not keep showing this split (see breakdownForModel).
383
+ const reqModel = context.model;
384
+ const reqModelID =
385
+ reqModel &&
386
+ typeof reqModel === "object" &&
387
+ typeof reqModel.id === "string" &&
388
+ reqModel.id
389
+ ? reqModel.id
390
+ : "unknown";
379
391
  breakdownCache.set(sid, {
380
392
  ...parts,
381
393
  capturedAt: Date.now(),
382
394
  source: "context-hook",
395
+ model: reqModelID,
383
396
  });
384
397
  pruneMap(breakdownCache, MAX_TRACKED_SESSIONS);
385
398
 
@@ -417,10 +430,20 @@ function onV2Compaction(context, ctx) {
417
430
  const directory = locationDirectory(ctx);
418
431
 
419
432
  const parts = estimateBreakdownFromContext(context, sid);
433
+ // Same model tag as the context hook (see onV2Context / breakdownForModel).
434
+ const reqModel = context.model;
435
+ const reqModelID =
436
+ reqModel &&
437
+ typeof reqModel === "object" &&
438
+ typeof reqModel.id === "string" &&
439
+ reqModel.id
440
+ ? reqModel.id
441
+ : "unknown";
420
442
  breakdownCache.set(sid, {
421
443
  ...parts,
422
444
  capturedAt: Date.now(),
423
445
  source: "compaction-hook",
446
+ model: reqModelID,
424
447
  });
425
448
  pruneMap(breakdownCache, MAX_TRACKED_SESSIONS);
426
449
 
@@ -628,6 +651,7 @@ async function ensureV2Breakdown(ctx, sessionID) {
628
651
  ...estimateBreakdownFromClientMessages(msgs),
629
652
  capturedAt: Date.now(),
630
653
  source: "client-context",
654
+ model: lastKnownModel(sessionID),
631
655
  });
632
656
  pruneMap(breakdownCache, MAX_TRACKED_SESSIONS);
633
657
  }
@@ -746,7 +770,10 @@ function buildLiveLinesV2(sessionID, modelID, providerID, inputTokens, ctxTokens
746
770
  // input/ctx belong to ITS view (a mirror that only saw the trailing event has
747
771
  // 0), and mixing them with the hook's categories made the header contradict
748
772
  // the "other = input - sum of estimates" line right below it.
749
- let bd = breakdownCache.get(sessionID);
773
+ let bd = breakdownForModel(sessionID, modelID);
774
+ // A breakdown measured for a DIFFERENT model is not this session's split any
775
+ // more: dropping it falls through to the state.json snapshot path below (which
776
+ // is model-consistent) or to the header-only path.
750
777
  let snapInputTokens = null;
751
778
  let snapCtxTokens = null;
752
779
  let snapAt = null;
@@ -969,10 +996,11 @@ async function handleV2Event(ctx, event) {
969
996
  if (event.type === "session.deleted") {
970
997
  const sid = event.data?.sessionID;
971
998
  if (!sid) return;
972
- // Discovery reads the persisted parentID chain, so a deleted session drops
973
- // out of the table as soon as its state.json entry is gone (or, while the
974
- // stale entry lingers, via the phantom filter — a deleted session has no
975
- // step). No dedicated in-memory index to clean up.
999
+ // Discovery reads the persisted parentID chain, so the entry has to go too:
1000
+ // clearing the in-memory caches alone leaves the row in state.json until the
1001
+ // tombstone (7 days) or the LRU cap drops it, and there is no step event left
1002
+ // to filter it out as a phantom.
1003
+ pruneSessionState(sid);
976
1004
  clearSessionTracking(sid);
977
1005
  // Whatever this session was, its own descendants must go too: a deleted
978
1006
  // parent takes the whole subtree, and a deleted child takes its own
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-context-indicator",
3
- "version": "1.8.1",
3
+ "version": "1.8.3",
4
4
  "description": "Real-time context-window usage for OpenCode: per-category token breakdown, /context-diff, a zero-LLM /cx panel with per-session cost and a searchable family-session picker, a TUI sidebar, and an experimental Desktop panel. Dual V1 + V2 plugin entry.",
5
5
  "type": "module",
6
6
  "license": "MIT",