pi-cache-optimizer 2.6.24 → 2.7.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.
Files changed (4) hide show
  1. package/README.md +36 -12
  2. package/README.zh-CN.md +36 -12
  3. package/index.ts +676 -170
  4. package/package.json +16 -1
package/README.md CHANGED
@@ -16,6 +16,7 @@ Pi extension for improving provider-side KV / prompt cache hit rates. It keeps s
16
16
  - [Install](#install)
17
17
  - [Commands](#commands)
18
18
  - [Persistent opt-out](#persistent-opt-out)
19
+ - [Footer cache stats mode](#footer-cache-stats-mode)
19
20
  - [OpenAI-compatible proxy setup](#openai-compatible-proxy-setup)
20
21
  - [Adaptive thinking models](#adaptive-thinking-models)
21
22
  - [Auto-repair with `/cache-optimizer fix`](#auto-repair-with-cache-optimizer-fix)
@@ -27,13 +28,13 @@ Pi extension for improving provider-side KV / prompt cache hit rates. It keeps s
27
28
 
28
29
  ## What it does
29
30
 
30
- - Reorders stable system-prompt content before dynamic context.
31
+ - Reorders uniquely identifiable stable system-prompt content before dynamic context. If the same candidate appears more than once (for example, quoted inside dynamic context), it is left unchanged to avoid removing the wrong occurrence.
31
32
  - Compresses Pi skill listings and strips session-overview churn.
32
33
  - Requests long cache retention when Pi/provider compat supports it.
33
- - Adds a session-id `prompt_cache_key` fallback for `openai-completions` / `openai-responses` payloads when no effective key exists, including Pi's built-in `llama.cpp` provider as Pi 0.82 core does.
34
+ - Adds a session-id `prompt_cache_key` fallback for `openai-completions` / `openai-responses` payloads when no effective key exists, including Pi's built-in `llama.cpp` provider as Pi 0.82+ core does.
34
35
  - Warns once for third-party OpenAI-compatible proxies missing cache/session-affinity compat flags.
35
- - Detects adaptive-thinking compat for Claude (opus-4.6+, sonnet-4.6+ including Sonnet 5, fable-5+) and Kimi Coding K3 / `kimi-for-coding` custom channels.
36
- - Shows restart-persistent provider/model footer stats for supported model families.
36
+ - Detects adaptive-thinking compat for Claude (opus-4.6+ including Opus 5, sonnet-4.6+ including Sonnet 5, fable-5+) and Kimi Coding K3 / `kimi-for-coding` custom channels.
37
+ - Shows daily cumulative provider/model footer stats by default, with an opt-in current-session display mode.
37
38
  - Supports optional router-extension integration through versioned global protocols (`Symbol.for("pi.routing.registry.v1")` and `Symbol.for("pi.cache.hints.v1")`) without importing router packages.
38
39
 
39
40
  Caching is provider-side and best-effort. Third-party proxies and router extensions can still hide cache usage, reject unsupported parameters, or route requests across multiple upstreams.
@@ -54,6 +55,8 @@ Run `/reload` in Pi after install/update/remove so extension hooks refresh.
54
55
 
55
56
  On Pi 0.79.7 and newer, `pi update` updates Pi itself only. To update installed Pi packages such as this extension, run `pi update --extensions` (packages only) or `pi update --all` (Pi + packages).
56
57
 
58
+ This extension is validated against Pi 0.83.0 and remains designed for Pi 0.82+. It uses the existing extension hooks, `getAgentDir()`, and prompt options shared by those versions; it does not depend on Pi 0.83-only APIs such as `ctx.scopedModels` or the bundled TypeBox 1.3 aliases.
59
+
57
60
  ## Commands
58
61
 
59
62
  | Command | Effect |
@@ -65,6 +68,7 @@ On Pi 0.79.7 and newer, `pi update` updates Pi itself only. To update installed
65
68
  | `/cache-optimizer compat` | Shows copyable compat advice for the active model, if applicable. |
66
69
  | `/cache-optimizer stats` | Shows today's local provider/model counters and recent trend for the active model. |
67
70
  | `/cache-optimizer reset` | Resets local footer stats for the active provider/model; upstream provider cache is not modified. |
71
+ | `/cache-optimizer config footer-mode session\|total` | Persist the footer stats mode. Persistent command configuration overrides the environment variable. |
68
72
  | `/cache-optimizer fix` | Auto-repairs safe compat issues for the active model (adaptive thinking, DeepSeek reasoning, OpenAI proxy session affinity). Shows preview + risk warning, requires confirmation. **Only modifies `models.json` after explicit user approval.** |
69
73
 
70
74
  `enable` / `disable` are current-process switches. For a persistent opt-out, use environment variables below.
@@ -78,11 +82,29 @@ On Pi 0.79.7 and newer, `pi update` updates Pi itself only. To update installed
78
82
  | `PI_CACHE_OPTIMIZER_NO_OPENAI_CACHE_KEY=1` | Disable the OpenAI-compatible `prompt_cache_key` fallback. Preferred explicit opt-out. |
79
83
  | `PI_CACHE_OPTIMIZER_OPENAI_CACHE_KEY=0` | Disable the same fallback via the legacy inverse switch. Values `0`, `false`, `no`, or `off` disable it. |
80
84
 
85
+ ## Footer cache stats mode
86
+
87
+ **v2.7.0+** supports both daily cumulative and current-session footer scopes. The footer defaults to `total`, which shows the provider/model's local counters for the current day across Pi sessions and process restarts. Use either the command or environment variable to select the scope:
88
+
89
+ | Value | Effect |
90
+ |---|---|
91
+ | `total` (default) | Show today's restart-persistent provider/model totals across sessions. Local day rollover resets the counters. |
92
+ | `session` | Show only the current hashed Pi session's counters. A fresh session starts at `0/0`; `/reload` in the same session restores that session bucket. |
93
+
94
+ Persistent command configuration takes precedence over the environment variable:
95
+
96
+ ```text
97
+ /cache-optimizer config footer-mode session
98
+ /cache-optimizer config footer-mode total
99
+ ```
100
+
101
+ The explicit setting is stored in `pi-cache-optimizer-config.json` under Pi's agent directory. If no command override exists, `PI_CACHE_OPTIMIZER_FOOTER_MODE=session|total` is used; values are case-insensitive, and missing or invalid values fall back to `total`. To return an existing installation to environment-controlled behavior, manually delete `pi-cache-optimizer-config.json` and run `/reload`.
102
+
81
103
  ## OpenAI-compatible proxy setup
82
104
 
83
105
  Third-party `openai-completions` proxies (LiteLLM / OneAPI / NewAPI / OpenRouter-like channels) often route one session across multiple upstream backends. That splits provider-side prompt caches.
84
106
 
85
- Pi 0.81+ also has a built-in `llama.cpp` provider using an OpenAI-shaped transport. Pi 0.82 core generates a session `prompt_cache_key` for it when cache retention is enabled, so this extension preserves that key and may add the same conservative fallback when missing. The built-in provider's explicit compat fingerprint is excluded from generic proxy routing/session-affinity advice, but a custom or overridden provider that merely reuses the id `llama.cpp` is treated like any other OpenAI-compatible channel. `prompt_cache_retention` remains subject to the normal safety rule: keep it only for official OpenAI or an explicit `supportsLongCacheRetention: true` opt-in in `models.json`; otherwise strip it before sending.
107
+ Pi 0.81+ also has a built-in `llama.cpp` provider using an OpenAI-shaped transport. Pi 0.82+ core generates a session `prompt_cache_key` for it when cache retention is enabled, so this extension preserves that key and may add the same conservative fallback when missing. The built-in provider's explicit compat fingerprint is excluded from generic proxy routing/session-affinity advice, but a custom or overridden provider that merely reuses the id `llama.cpp` is treated like any other OpenAI-compatible channel. `prompt_cache_retention` remains subject to the normal safety rule: keep it only for official OpenAI or an explicit effective `supportsLongCacheRetention: true` opt-in in `models.json`; otherwise strip it before sending. Effective values follow Pi's precedence: `modelOverrides[modelId].compat` first, then the matching `models[].compat`, then provider-level `compat`. An explicit `false` at a higher layer overrides `true` below it.
86
108
 
87
109
  For real proxies, start with session affinity:
88
110
 
@@ -123,7 +145,7 @@ Some proxies rewrite or insert hidden 5-minute breakpoints after Pi's request ho
123
145
 
124
146
  ## Adaptive thinking models
125
147
 
126
- Claude models from opus-4.6 / sonnet-4.6 (including Sonnet 5) / fable-5 onwards require `forceAdaptiveThinking: true` in compat. Kimi Coding K3 (`k3`) and `kimi-for-coding` also use adaptive thinking and need `allowEmptySignature: true` so replayed empty-signature thinking blocks remain valid. Without the required compat, Pi may send a legacy thinking payload or replay thinking incorrectly.
148
+ Claude models from opus-4.6 / sonnet-4.6 (including Opus 5 and Sonnet 5) / fable-5 onwards require `forceAdaptiveThinking: true` in compat. Kimi Coding K3 (`k3`) and `kimi-for-coding` also use adaptive thinking and need `allowEmptySignature: true` so replayed empty-signature thinking blocks remain valid. Without the required compat, Pi may send a legacy thinking payload or replay thinking incorrectly. Pi 0.83.0's native Opus 5 catalog is covered by the same adaptive-thinking detection; custom `anthropic-messages` channels still need the compat flag when Pi does not provide it.
127
149
 
128
150
  Pi's built-in catalog already sets this flag for official models. Custom channels in `models.json` that override these models must include the flag:
129
151
 
@@ -205,6 +227,8 @@ Pi 0.80.9+ already includes Kimi K3 in built-in Kimi Coding, Moonshot AI / China
205
227
  5. Writes atomically (temp + rename); self-validates after write
206
228
  6. Falls back to manual guidance if JSONC scanner cannot confidently locate the target
207
229
 
230
+ Existing `modelOverrides[modelId]` entries have Pi's highest precedence, so `fix` repairs them directly. For built-in or API-login models without a custom `models[]` entry, `fix` creates a compat-only `modelOverrides` entry instead of inventing a custom model definition. Self-validation checks the effective three-layer compat result, so a lower-level edit shadowed by an override is rejected.
231
+
208
232
  **Non-interactive mode:** refuses to write; shows manual edit guidance instead.
209
233
 
210
234
  **Run:** `/cache-optimizer fix` when the active model has detected compat issues. The command shows "nothing to fix" when compat is already complete.
@@ -247,7 +271,7 @@ If only one model should change, use `modelOverrides`:
247
271
 
248
272
  ## Footer stats
249
273
 
250
- Stats are read-only local counters stored in Pi's agent directory (default: `~/.pi/agent/pi-cache-optimizer-stats.json`; custom agent dirs use `PI_CODING_AGENT_DIR`) and keyed by provider/model, so the same channel/model keeps today's footer counters after a Pi process or terminal restart. The file also keeps hashed session buckets for migration/reload bookkeeping. It contains only dates and numeric counters — no API keys, prompts, payloads, headers, responses, or model output.
274
+ Stats are read-only local counters stored in Pi's agent directory (default: `~/.pi/agent/pi-cache-optimizer-stats.json`; custom agent dirs use `PI_CODING_AGENT_DIR`). Both today's provider/model totals and hashed session buckets are maintained. The footer shows daily totals by default, or the current session bucket when `session` mode is selected. The stats file contains only dates and numeric counters — no API keys, prompts, payloads, headers, responses, or model output. Footer mode configuration is stored separately in `pi-cache-optimizer-config.json`.
251
275
 
252
276
  Pi 0.79+ also includes a built-in footer `CH` marker for the latest prompt cache hit rate. This extension complements that marker with persisted provider/model counters plus proxy compat diagnostics.
253
277
 
@@ -376,13 +400,13 @@ When the query matches the current session/route, `hints` may contain `systemPro
376
400
  pi remove npm:pi-cache-optimizer
377
401
  ```
378
402
 
379
- Then run `/reload` or restart Pi. Optional local stats cleanup (if you use `PI_CODING_AGENT_DIR`, delete the same files from that directory instead):
403
+ Then run `/reload` or restart Pi. Optional local state cleanup (if you use `PI_CODING_AGENT_DIR`, delete the same files from that directory instead):
380
404
 
381
- | Platform | Delete local stats files |
405
+ | Platform | Delete local state files |
382
406
  |---|---|
383
- | Linux / macOS / WSL | `rm -f ~/.pi/agent/pi-cache-optimizer-stats.json ~/.pi/agent/deepseek-cache-optimizer-stats.json` |
384
- | Windows PowerShell | `Remove-Item -Force "$env:USERPROFILE\.pi\agent\pi-cache-optimizer-stats.json", "$env:USERPROFILE\.pi\agent\deepseek-cache-optimizer-stats.json" -ErrorAction SilentlyContinue` |
385
- | Windows Command Prompt | `del /f /q "%USERPROFILE%\.pi\agent\pi-cache-optimizer-stats.json" "%USERPROFILE%\.pi\agent\deepseek-cache-optimizer-stats.json" 2>nul` |
407
+ | Linux / macOS / WSL | `rm -f ~/.pi/agent/pi-cache-optimizer-stats.json ~/.pi/agent/pi-cache-optimizer-config.json ~/.pi/agent/deepseek-cache-optimizer-stats.json` |
408
+ | Windows PowerShell | `Remove-Item -Force "$env:USERPROFILE\.pi\agent\pi-cache-optimizer-stats.json", "$env:USERPROFILE\.pi\agent\pi-cache-optimizer-config.json", "$env:USERPROFILE\.pi\agent\deepseek-cache-optimizer-stats.json" -ErrorAction SilentlyContinue` |
409
+ | Windows Command Prompt | `del /f /q "%USERPROFILE%\.pi\agent\pi-cache-optimizer-stats.json" "%USERPROFILE%\.pi\agent\pi-cache-optimizer-config.json" "%USERPROFILE%\.pi\agent\deepseek-cache-optimizer-stats.json" 2>nul` |
386
410
 
387
411
  Do not delete `models.json` during cleanup; it contains your Pi model/provider configuration and is not owned by this package.
388
412
 
package/README.zh-CN.md CHANGED
@@ -16,6 +16,7 @@
16
16
  - [安装](#安装)
17
17
  - [命令](#命令)
18
18
  - [持久 Opt-out](#持久-opt-out)
19
+ - [Footer 缓存统计模式](#footer-缓存统计模式)
19
20
  - [OpenAI-compatible 代理配置](#openai-compatible-代理配置)
20
21
  - [Adaptive thinking 模型](#adaptive-thinking-模型)
21
22
  - [使用 `/cache-optimizer fix` 自动修复](#使用-cache-optimizer-fix-自动修复)
@@ -27,13 +28,13 @@
27
28
 
28
29
  ## 功能
29
30
 
30
- - 将稳定的 system prompt 内容移动到动态上下文之前。
31
+ - 将能唯一定位的稳定 system prompt 内容移动到动态上下文之前。如果同一候选出现多次(例如动态上下文引用了它),则保持原样,避免删除错误的那一处。
31
32
  - 压缩 Pi skill 列表,并移除 session-overview 中的易变字段。
32
33
  - 在 Pi / provider compat 支持时请求长缓存保留。
33
- - 对 `openai-completions` / `openai-responses` 请求,在没有有效 key 时使用 Pi session id 补 `prompt_cache_key`;Pi 0.82 core 对内置 `llama.cpp` 也使用这一语义。
34
+ - 对 `openai-completions` / `openai-responses` 请求,在没有有效 key 时使用 Pi session id 补 `prompt_cache_key`;Pi 0.82+ core 对内置 `llama.cpp` 也使用这一语义。
34
35
  - 对缺少缓存 / session-affinity compat 的第三方 OpenAI-compatible 代理给出一次性提醒。
35
- - 检测 Claude(opus-4.6+、sonnet-4.6+ 含 Sonnet 5、fable-5+)以及 Kimi Coding K3 / `kimi-for-coding` 自定义渠道的 adaptive-thinking compat。
36
- - 为支持的模型家族显示可跨 Pi 进程 / 终端重启延续的 provider/model footer 缓存统计。
36
+ - 检测 Claude(opus-4.6+ 含 Opus 5、sonnet-4.6+ 含 Sonnet 5、fable-5+)以及 Kimi Coding K3 / `kimi-for-coding` 自定义渠道的 adaptive-thinking compat。
37
+ - 默认显示按本地日期累计的 provider/model footer 缓存统计,也可切换为仅显示当前 session。
37
38
  - 通过版本化全局协议(`Symbol.for("pi.routing.registry.v1")` 与 `Symbol.for("pi.cache.hints.v1")`)支持可选的 router extension 集成,而不导入任何 router 包。
38
39
 
39
40
  缓存是 provider 侧的 best-effort 行为。第三方代理和 router extension 仍可能隐藏缓存 usage、拒绝不支持的参数,或把请求路由到多个上游。
@@ -54,6 +55,8 @@ pi remove npm:pi-deepseek-cache-optimizer && pi install npm:pi-cache-optimizer
54
55
 
55
56
  Pi 0.79.7 及之后,`pi update` 默认只更新 Pi 本体。若要更新已安装的 Pi package(包括本扩展),请运行 `pi update --extensions`(只更新 packages)或 `pi update --all`(Pi 与 packages 一起更新)。
56
57
 
58
+ 本扩展已使用 Pi 0.83.0 验证,并继续面向 Pi 0.82+ 设计。它使用这些版本共有的 extension hooks、`getAgentDir()` 和 prompt options,不依赖 Pi 0.83 专有 API(例如 `ctx.scopedModels` 或 bundled TypeBox 1.3 aliases)。
59
+
57
60
  ## 命令
58
61
 
59
62
  | 命令 | 作用 |
@@ -65,6 +68,7 @@ Pi 0.79.7 及之后,`pi update` 默认只更新 Pi 本体。若要更新已安
65
68
  | `/cache-optimizer compat` | 对当前模型显示可复制的 compat 建议(如适用)。 |
66
69
  | `/cache-optimizer stats` | 显示当前模型今天的本地 provider/model 统计和近期趋势。 |
67
70
  | `/cache-optimizer reset` | 重置当前 provider/model 的本地 footer 统计;不会修改上游 provider 缓存。 |
71
+ | `/cache-optimizer config footer-mode session\|total` | 持久设置 footer 统计模式;持久命令配置优先于环境变量。 |
68
72
  | `/cache-optimizer fix` | 为当前模型自动修复安全的 compat 问题(adaptive thinking、DeepSeek reasoning、OpenAI proxy session affinity)。展示预览 + 风险提示,需要用户确认。**仅在用户明确批准后才修改 `models.json`。** |
69
73
 
70
74
  `enable` / `disable` 是当前进程内开关。若要持久关闭某些能力,请使用下面的环境变量。
@@ -78,11 +82,29 @@ Pi 0.79.7 及之后,`pi update` 默认只更新 Pi 本体。若要更新已安
78
82
  | `PI_CACHE_OPTIMIZER_NO_OPENAI_CACHE_KEY=1` | 关闭 OpenAI-compatible `prompt_cache_key` fallback。推荐使用这个显式 opt-out。 |
79
83
  | `PI_CACHE_OPTIMIZER_OPENAI_CACHE_KEY=0` | 通过旧的反向开关关闭同一个 fallback。取值 `0`、`false`、`no`、`off` 时关闭。 |
80
84
 
85
+ ## Footer 缓存统计模式
86
+
87
+ **v2.7.0+** 同时支持每日累计与当前 session 两种 footer 统计范围。Footer 默认使用 `total`,显示当前本地日期内、跨 Pi session 和进程重启延续的 provider/model 统计。可以通过命令或环境变量切换显示范围:
88
+
89
+ | 值 | 作用 |
90
+ |---|---|
91
+ | `total`(默认) | 显示今天跨 session 持久延续的 provider/model 累计统计;本地日期切换时重置。 |
92
+ | `session` | 仅显示当前 hashed Pi session 的统计。新 session 从 `0/0` 开始;同一 session 内 `/reload` 会恢复该 session 桶。 |
93
+
94
+ 持久命令配置优先于环境变量:
95
+
96
+ ```text
97
+ /cache-optimizer config footer-mode session
98
+ /cache-optimizer config footer-mode total
99
+ ```
100
+
101
+ 显式设置保存在 Pi agent 目录下的 `pi-cache-optimizer-config.json`。没有命令覆盖时,读取 `PI_CACHE_OPTIMIZER_FOOTER_MODE=session|total`;值不区分大小写,缺失或非法值均回退到 `total`。如需让已有安装重新由环境变量控制,请手动删除 `pi-cache-optimizer-config.json`,然后运行 `/reload`。
102
+
81
103
  ## OpenAI-compatible 代理配置
82
104
 
83
105
  LiteLLM / OneAPI / NewAPI / 类 OpenRouter 渠道等第三方 `openai-completions` 代理,常会把同一个 session 分散到多个上游后端,导致 provider 侧 prompt cache 被拆散。
84
106
 
85
- Pi 0.81+ 也内置了使用 OpenAI-shaped transport 的 `llama.cpp` provider。Pi 0.82 core 在启用 cache retention 时会为它生成 session `prompt_cache_key`,因此本扩展会保留该 key,并在缺失时使用同样的保守 fallback。只有符合 Pi 内置 provider 明确 compat 指纹的模型会跳过通用 proxy 路由 / session-affinity 建议;仅复用 `llama.cpp` id 的自定义或覆盖 provider 仍按普通 OpenAI-compatible 渠道处理。`prompt_cache_retention` 继续遵循统一安全规则:仅官方 OpenAI 或在 `models.json` 中显式设置 `supportsLongCacheRetention: true` 时保留,否则发送前移除。
107
+ Pi 0.81+ 也内置了使用 OpenAI-shaped transport 的 `llama.cpp` provider。Pi 0.82+ core 在启用 cache retention 时会为它生成 session `prompt_cache_key`,因此本扩展会保留该 key,并在缺失时使用同样的保守 fallback。只有符合 Pi 内置 provider 明确 compat 指纹的模型会跳过通用 proxy 路由 / session-affinity 建议;仅复用 `llama.cpp` id 的自定义或覆盖 provider 仍按普通 OpenAI-compatible 渠道处理。`prompt_cache_retention` 继续遵循统一安全规则:仅官方 OpenAI 或 `models.json` 中有效配置为 `supportsLongCacheRetention: true` 时保留,否则发送前移除。有效值遵循 Pi 的优先级:先看 `modelOverrides[modelId].compat`,再看匹配的 `models[].compat`,最后看 provider 级 `compat`;高层显式 `false` 会覆盖低层的 `true`。
86
108
 
87
109
  对真正的代理,建议先启用 session affinity:
88
110
 
@@ -123,7 +145,7 @@ Anthropic 按 `tools → system → messages` 顺序处理 cache breakpoint,
123
145
 
124
146
  ## Adaptive thinking 模型
125
147
 
126
- Claude 从 opus-4.6 / sonnet-4.6(含 Sonnet 5)/ fable-5 开始需要在 compat 中设置 `forceAdaptiveThinking: true`。Kimi Coding K3(`k3`)和 `kimi-for-coding` 也使用 adaptive thinking,并需要 `allowEmptySignature: true`,以正确重放空 signature 的 thinking block。缺少这些 compat 时,Pi 可能发送旧版 thinking payload 或错误重放 thinking。
148
+ Claude 从 opus-4.6 / sonnet-4.6(含 Opus 5、Sonnet 5)/ fable-5 开始需要在 compat 中设置 `forceAdaptiveThinking: true`。Kimi Coding K3(`k3`)和 `kimi-for-coding` 也使用 adaptive thinking,并需要 `allowEmptySignature: true`,以正确重放空 signature 的 thinking block。缺少这些 compat 时,Pi 可能发送旧版 thinking payload 或错误重放 thinking。Pi 0.83.0 的原生 Opus 5 catalog 已覆盖在同一 adaptive-thinking 检测中;如果自定义 `anthropic-messages` 渠道没有继承该 compat,仍需手动设置。
127
149
 
128
150
  Pi 内置 catalog 已为官方模型设置此 flag。`models.json` 中覆盖这些模型的自定义渠道必须包含该 flag:
129
151
 
@@ -205,6 +227,8 @@ Pi 0.80.9+ 已在内置 Kimi Coding、Moonshot AI / 中国区、OpenRouter 和 V
205
227
  5. 原子写入(temp + rename);写入后自我验证
206
228
  6. 如果 JSONC 扫描器无法置信定位目标,回退到手动修改指引
207
229
 
230
+ 已有的 `modelOverrides[modelId]` 具有 Pi 的最高优先级,因此 `fix` 会直接修复该 entry。对于没有自定义 `models[]` entry 的内置模型或 API-login 模型,`fix` 会创建仅含 compat 的 `modelOverrides` entry,而不会凭空添加自定义模型定义。自检会验证三层合并后的有效 compat,因此被更高层 override 遮蔽的低层修改会被拒绝。
231
+
208
232
  **非交互模式:** 拒绝写入,显示手动编辑指引。
209
233
 
210
234
  **运行:** 当 active model 检测到 compat 问题时执行 `/cache-optimizer fix`。compat 已完整时,命令显示"无需修复"。
@@ -247,7 +271,7 @@ Provider 级最小 override:
247
271
 
248
272
  ## Footer 统计
249
273
 
250
- 统计是只读本地计数,保存在 Pi agent 目录(默认 `~/.pi/agent/pi-cache-optimizer-stats.json`;自定义 agent 目录使用 `PI_CODING_AGENT_DIR`),按 provider/model 作为 footer 展示维度,因此同一个渠道/模型在 Pi 进程或终端重启后会延续今天的统计。文件也保留 hashed session buckets,用于迁移和 reload 记录。文件只包含日期和数字计数,不包含 API key、prompt、payload、headers、响应或模型输出。
274
+ 统计是只读本地计数,保存在 Pi agent 目录(默认 `~/.pi/agent/pi-cache-optimizer-stats.json`;自定义 agent 目录使用 `PI_CODING_AGENT_DIR`)。扩展同时维护当天的 provider/model totals 和 hashed session buckets。Footer 默认显示每日 totals;选择 `session` 模式后显示当前 session 桶。统计文件只包含日期和数字计数,不包含 API key、prompt、payload、headers、响应或模型输出。Footer 模式配置单独保存在 `pi-cache-optimizer-config.json`。
251
275
 
252
276
  Pi 0.79+ 已内置 footer `CH` 标记,用于显示最近一次 prompt cache hit rate。本扩展在此基础上补充持久化的 provider/model 计数,以及代理 compat 诊断。
253
277
 
@@ -376,13 +400,13 @@ const hints = (globalThis as Record<symbol, any>)[CACHE_HINTS]?.getHints?.({
376
400
  pi remove npm:pi-cache-optimizer
377
401
  ```
378
402
 
379
- 然后运行 `/reload` 或重启 Pi。可选:删除本地统计文件(如果使用 `PI_CODING_AGENT_DIR`,请删除该目录中的同名文件):
403
+ 然后运行 `/reload` 或重启 Pi。可选:删除本地状态文件(如果使用 `PI_CODING_AGENT_DIR`,请删除该目录中的同名文件):
380
404
 
381
- | 平台 | 删除本地统计文件 |
405
+ | 平台 | 删除本地状态文件 |
382
406
  |---|---|
383
- | Linux / macOS / WSL | `rm -f ~/.pi/agent/pi-cache-optimizer-stats.json ~/.pi/agent/deepseek-cache-optimizer-stats.json` |
384
- | Windows PowerShell | `Remove-Item -Force "$env:USERPROFILE\.pi\agent\pi-cache-optimizer-stats.json", "$env:USERPROFILE\.pi\agent\deepseek-cache-optimizer-stats.json" -ErrorAction SilentlyContinue` |
385
- | Windows 命令提示符 | `del /f /q "%USERPROFILE%\.pi\agent\pi-cache-optimizer-stats.json" "%USERPROFILE%\.pi\agent\deepseek-cache-optimizer-stats.json" 2>nul` |
407
+ | Linux / macOS / WSL | `rm -f ~/.pi/agent/pi-cache-optimizer-stats.json ~/.pi/agent/pi-cache-optimizer-config.json ~/.pi/agent/deepseek-cache-optimizer-stats.json` |
408
+ | Windows PowerShell | `Remove-Item -Force "$env:USERPROFILE\.pi\agent\pi-cache-optimizer-stats.json", "$env:USERPROFILE\.pi\agent\pi-cache-optimizer-config.json", "$env:USERPROFILE\.pi\agent\deepseek-cache-optimizer-stats.json" -ErrorAction SilentlyContinue` |
409
+ | Windows 命令提示符 | `del /f /q "%USERPROFILE%\.pi\agent\pi-cache-optimizer-stats.json" "%USERPROFILE%\.pi\agent\pi-cache-optimizer-config.json" "%USERPROFILE%\.pi\agent\deepseek-cache-optimizer-stats.json" 2>nul` |
386
410
 
387
411
  清理时不要删除 `models.json`;它保存你的 Pi 模型 / provider 配置,不属于本包。
388
412