pi-cache-optimizer 2.8.15 → 2.8.16

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/index.ts +36 -5
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -2089,14 +2089,20 @@ function isEnabledEnv(value: string | undefined): boolean {
2089
2089
  return normalized === "1" || normalized === "true" || normalized === "yes" || normalized === "on";
2090
2090
  }
2091
2091
 
2092
- function featureEnabled(feature: PersistedCacheOptimizerFeature, envName: string, defaultValue: boolean): boolean {
2093
- const configured = (persistedCacheOptimizerConfig as PersistedCacheOptimizerConfigV3).features?.[feature];
2092
+ function featureEnabled(
2093
+ feature: PersistedCacheOptimizerFeature,
2094
+ envName: string,
2095
+ defaultValue: boolean,
2096
+ env: MutableEnv = process.env,
2097
+ config: PersistedCacheOptimizerConfigV3 = persistedCacheOptimizerConfig,
2098
+ ): boolean {
2099
+ const configured = config.features?.[feature];
2094
2100
  if (configured !== undefined) return configured;
2095
- if (feature === "virtualRewrite") return isEnabledEnv(process.env[envName]);
2101
+ if (feature === "virtualRewrite") return isEnabledEnv(env[envName]);
2096
2102
  if (feature === "promptRewrite" || feature === "skillCompression" || feature === "openAICacheKey") {
2097
- return !isEnabledEnv(process.env[envName]);
2103
+ return !isEnabledEnv(env[envName]);
2098
2104
  }
2099
- return isEnabledEnv(process.env[envName]) || defaultValue;
2105
+ return isEnabledEnv(env[envName]) || defaultValue;
2100
2106
  }
2101
2107
 
2102
2108
  function isToolOrderEnabled(env: MutableEnv = process.env): boolean {
@@ -2784,6 +2790,7 @@ function getOptimizerRuntimeModeLines(): string[] {
2784
2790
  lines.push(`• Footer cache stats: on${runtimeOptimizerEnabled ? "" : " (comparison mode)"}`);
2785
2791
  lines.push(`• Compat warnings: ${runtimeOptimizerEnabled ? "on" : "off"}`);
2786
2792
  lines.push(`• ${PI_CACHE_RETENTION_ENV}: ${process.env[PI_CACHE_RETENTION_ENV] ?? "(unset)"}`);
2793
+ lines.push(`• Persistent feature overrides: ${Object.keys(persistedCacheOptimizerConfig.features ?? {}).length > 0 ? "configured" : "none"}`);
2787
2794
  if (!runtimeOptimizerEnabled) {
2788
2795
  lines.push("This is a current-process switch. Run /reload or restart Pi to return to startup behavior.");
2789
2796
  } else if (!featureEnabled("promptRewrite", NO_PROMPT_REWRITE_ENV, true) || !shouldInjectOpenAIPromptCacheKey()) {
@@ -2792,6 +2799,23 @@ function getOptimizerRuntimeModeLines(): string[] {
2792
2799
  return lines;
2793
2800
  }
2794
2801
 
2802
+ function formatPersistentFeatureConfig(): string {
2803
+ const features = persistedCacheOptimizerConfig.features ?? {};
2804
+ const lines = ["Persistent feature configuration:"];
2805
+ const entries: Array<[string, PersistedCacheOptimizerFeature, string, boolean]> = [
2806
+ ["Prompt rewrite", "promptRewrite", NO_PROMPT_REWRITE_ENV, true],
2807
+ ["Native virtual rewrite", "virtualRewrite", VIRTUAL_REWRITE_ENV, false],
2808
+ ["Skill compression", "skillCompression", NO_SKILL_COMPRESSION_ENV, true],
2809
+ ["OpenAI cache key", "openAICacheKey", NO_OPENAI_CACHE_KEY_ENV, true],
2810
+ ["Tool ordering", "toolOrder", TOOL_ORDER_ENV, false],
2811
+ ];
2812
+ for (const [label, feature, envName, defaultValue] of entries) {
2813
+ const source = features[feature] !== undefined ? "config" : process.env[envName] !== undefined ? "env" : "default";
2814
+ lines.push(`• ${label}: ${featureEnabled(feature, envName, defaultValue) ? "on" : "off"} (${source})`);
2815
+ }
2816
+ return lines.join("\n");
2817
+ }
2818
+
2795
2819
  function formatOptimizerRuntimeMode(): string {
2796
2820
  return getOptimizerRuntimeModeLines().join("\n");
2797
2821
  }
@@ -10233,6 +10257,8 @@ export const __internals_for_tests = {
10233
10257
  SKILL_COMPRESSION_MIN_COUNT,
10234
10258
  NO_PROMPT_REWRITE_ENV,
10235
10259
  isEnabledEnv,
10260
+ featureEnabled,
10261
+ writePersistedFeature,
10236
10262
  // OpenAI-family cache-key helpers
10237
10263
  addOpenAIPromptCacheKey,
10238
10264
  clampPromptCacheKey,
@@ -11896,6 +11922,11 @@ export default function (pi: ExtensionAPI) {
11896
11922
  }
11897
11923
  return;
11898
11924
  }
11925
+ if (!configKey) {
11926
+ cmdCtx.ui.notify(formatPersistentFeatureConfig() + `\n• Footer mode: ${resolveFooterStatsMode(persistedFooterStatsMode).mode}` + "\n\n" +
11927
+ "Usage: /cache-optimizer config <feature> on|off | footer-mode total|session|process | reset", "info");
11928
+ return;
11929
+ }
11899
11930
  if (configKey !== "footer-mode" || !requestedMode || !["session", "total", "process"].includes(requestedMode)) {
11900
11931
  const resolved = resolveFooterStatsMode(persistedFooterStatsMode);
11901
11932
  cmdCtx.ui.notify(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-cache-optimizer",
3
- "version": "2.8.15",
3
+ "version": "2.8.16",
4
4
  "description": "Improve Pi prompt/KV cache hit rates with stable prompts, OpenAI-compatible cache keys, proxy compat warnings, and footer cache stats.",
5
5
  "keywords": [
6
6
  "pi-package",