opencode-visual-cache 1.2.8 → 1.2.9-beta.0

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.
@@ -1 +1 @@
1
- export declare const PLUGIN_VERSION = "1.2.8";
1
+ export declare const PLUGIN_VERSION = "1.2.9-beta.0";
package/dist/_version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // auto-generated
2
- export const PLUGIN_VERSION = "1.2.8";
2
+ export const PLUGIN_VERSION = "1.2.9-beta.0";
package/dist/index.js CHANGED
@@ -574,8 +574,17 @@ function TokenCachePanel(props) {
574
574
  doRestore();
575
575
  }
576
576
  else {
577
+ // Poll kv.ready with a 1-second timeout to avoid infinite busy-wait
578
+ // on platforms where kv initialisation may be delayed (Linux single-thread
579
+ // mode, session switch storms, etc.).
580
+ const MAX_POLL = 100;
581
+ let tries = 0;
577
582
  const pollRestore = () => {
578
583
  if (!props.api.kv.ready) {
584
+ if (++tries > MAX_POLL) {
585
+ doRestore();
586
+ return;
587
+ }
579
588
  setTimeout(pollRestore, 10);
580
589
  return;
581
590
  }
@@ -583,13 +592,17 @@ function TokenCachePanel(props) {
583
592
  };
584
593
  pollRestore();
585
594
  }
586
- const unsubPart = props.api.event.on("message.part.updated", () => {
587
- setPartVersion((v) => v + 1);
588
- });
589
- const unsubMsg = props.api.event.on("message.updated", () => {
590
- setPartVersion((v) => v + 1);
591
- });
592
- onCleanup(() => { unsubPart(); unsubMsg(); });
595
+ // Debounce partVersion updates so that event bursts during session
596
+ // switching / streaming don't cause data() to re-compute on every
597
+ // single event (up to hundreds per second on Linux single-thread).
598
+ let partTimer;
599
+ const bumpPartVersion = () => {
600
+ clearTimeout(partTimer);
601
+ partTimer = setTimeout(() => setPartVersion((v) => v + 1), 100);
602
+ };
603
+ const unsubPart = props.api.event.on("message.part.updated", bumpPartVersion);
604
+ const unsubMsg = props.api.event.on("message.updated", bumpPartVersion);
605
+ onCleanup(() => { clearTimeout(partTimer); unsubPart(); unsubMsg(); });
593
606
  });
594
607
  // ── colours ──
595
608
  // Pull from the current theme, auto-desaturate if too punchy,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-visual-cache",
3
- "version": "1.2.8",
3
+ "version": "1.2.9-beta.0",
4
4
  "description": "OpenCode TUI plugin displaying real-time token cache hit rate in the sidebar",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/src/_version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // auto-generated
2
- export const PLUGIN_VERSION="1.2.8";
2
+ export const PLUGIN_VERSION="1.2.9-beta.0";
package/src/index.tsx CHANGED
@@ -633,8 +633,14 @@ function TokenCachePanel(props: {
633
633
  if (props.api.kv.ready) {
634
634
  doRestore()
635
635
  } else {
636
+ // Poll kv.ready with a 1-second timeout to avoid infinite busy-wait
637
+ // on platforms where kv initialisation may be delayed (Linux single-thread
638
+ // mode, session switch storms, etc.).
639
+ const MAX_POLL = 100
640
+ let tries = 0
636
641
  const pollRestore = () => {
637
642
  if (!props.api.kv.ready) {
643
+ if (++tries > MAX_POLL) { doRestore(); return }
638
644
  setTimeout(pollRestore, 10)
639
645
  return
640
646
  }
@@ -643,13 +649,17 @@ function TokenCachePanel(props: {
643
649
  pollRestore()
644
650
  }
645
651
 
646
- const unsubPart = props.api.event.on("message.part.updated", () => {
647
- setPartVersion((v) => v + 1)
648
- })
649
- const unsubMsg = props.api.event.on("message.updated", () => {
650
- setPartVersion((v) => v + 1)
651
- })
652
- onCleanup(() => { unsubPart(); unsubMsg() })
652
+ // Debounce partVersion updates so that event bursts during session
653
+ // switching / streaming don't cause data() to re-compute on every
654
+ // single event (up to hundreds per second on Linux single-thread).
655
+ let partTimer: ReturnType<typeof setTimeout> | undefined
656
+ const bumpPartVersion = () => {
657
+ clearTimeout(partTimer)
658
+ partTimer = setTimeout(() => setPartVersion((v) => v + 1), 100)
659
+ }
660
+ const unsubPart = props.api.event.on("message.part.updated", bumpPartVersion)
661
+ const unsubMsg = props.api.event.on("message.updated", bumpPartVersion)
662
+ onCleanup(() => { clearTimeout(partTimer); unsubPart(); unsubMsg() })
653
663
  })
654
664
 
655
665
  // ── colours ──