pi-kimi-keepalive 0.3.4 → 0.3.6

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +23 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-kimi-keepalive",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "description": "Prompt-cache keepalive for Kimi (kimi-coding) sessions in the Pi coding agent. Replays the last real provider request while idle so the automatic prefix cache never expires.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/index.ts CHANGED
@@ -51,6 +51,27 @@ import {
51
51
 
52
52
  const STATE_DIR = join(homedir(), ".pi", "cache-keepalive");
53
53
  const STATE_FILE = join(STATE_DIR, "state.json");
54
+
55
+ /** Version of record; kept in sync with package.json (enforced by a test). */
56
+ export const FALLBACK_VERSION = "0.3.6";
57
+
58
+ /**
59
+ * Package version. The relative import.meta.url read works when the extension
60
+ * is loaded from its package directory (npm / repo); some host loaders copy or
61
+ * transpile the .ts elsewhere, losing the relative anchor — then the constant
62
+ * above is the source of truth.
63
+ */
64
+ function ownVersion(): string {
65
+ try {
66
+ const pkg = JSON.parse(
67
+ readFileSync(new URL("../../package.json", import.meta.url), "utf8"),
68
+ ) as { version?: unknown };
69
+ if (typeof pkg.version === "string") return pkg.version;
70
+ } catch {
71
+ // fall through to the in-source constant
72
+ }
73
+ return FALLBACK_VERSION;
74
+ }
54
75
  /** Live OAuth state; resolved lazily so tests can redirect it via PI_AGENT_DIR. */
55
76
  function authFile(): string {
56
77
  return join(process.env.PI_AGENT_DIR ?? join(homedir(), ".pi", "agent"), "auth.json");
@@ -717,7 +738,7 @@ export default function (pi: ExtensionAPI) {
717
738
  const savings = hasPricing(capture?.cost) ? formatUsd(stats.savedUsd) : "n/a (no price data)";
718
739
  ctx.ui.setStatus("cache-keepalive", `♥ ${state}`);
719
740
  ctx.ui.setWidget("cache-keepalive", [
720
- "pi-kimi-keepalive",
741
+ `pi-kimi-keepalive v${ownVersion()}`,
721
742
  ` state: ${state}`,
722
743
  ` probes: ${stats.probes} sent · ${stats.hits} hits · ${stats.misses} misses · ${stats.errors} errors`,
723
744
  ` est.: saved ${savings} · probe spend ${formatUsd(stats.spendUsd)} · cap ${config.spendCapUsd === null ? "none" : formatUsd(config.spendCapUsd)}`,
@@ -740,7 +761,7 @@ export default function (pi: ExtensionAPI) {
740
761
  ? `${capture.provider} (${capture.api ?? "unknown api"}) @ ${capture.baseUrl}`
741
762
  : "none yet — probes start after your first real turn";
742
763
  return [
743
- "pi-kimi-keepalive",
764
+ `pi-kimi-keepalive v${ownVersion()}`,
744
765
  ` state: ${config.enabled ? "on" : "off"}${pausedReason ? ` (paused: ${pausedReason})` : ""}`,
745
766
  ` capture: ${route}`,
746
767
  ` mode: ${config.mode}${config.mode === "smart" ? ` · cadence ${formatDuration(config.intervalMs)}${lastProbeInputTokens > SMART_MAX_CONTEXT_TOKENS ? ` · context ${lastProbeInputTokens.toLocaleString()} > cap, frozen at floor` : ""}` : " (fixed via interval=)"}`,