Skip to main content
M

dsh-peak-cost-mode

moon09300731/dsh-peak-cost-mode

DeepSeek peak-pricing cost guard for DSH: during peak hours (Beijing 09:00–12:00 / 14:00–18:00, ×2) the agent automatically switches to ultra-compressed caveman-style output to save tokens, and a header badge + toast keep you posted on every peak/valley t

Install

dsh plugin --profile web add github:moon09300731/dsh-peak-cost-mode

README

dsh-peak-cost-mode

DeepSeek peak-pricing cost guard for DeepSeek Harness (DSH): during DeepSeek peak-pricing hours (Beijing time 09:00–12:00 and 14:00–18:00, price ×2) the agent automatically switches to ultra-compressed caveman-style output to cut output tokens, and a header badge + toast keep you posted on every peak/valley transition.

Features

  • Automatic peak detection — Beijing time (UTC+8, no DST) is checked every 30 s against the DeepSeek V4 peak-pricing schedule:
    Window (Beijing)TierPrice
    09:00–12:00Peak×2
    12:00–14:00Valley×1
    14:00–18:00Peak×2
    18:00–next 09:00Valley×1
  • Peak-hour cost saving — while in a peak window, a "Peak Cost Mode" prompt section is injected, instructing the model to reply in ultra-compressed caveman style (drop filler/pleasantries/hedging, keep all technical content verbatim: code, commands, API names, file paths, exact error strings, numbers; safety warnings and irreversible-action confirmations are never compressed).
  • Transition reminders — toasts on every tier switch:
    • valley → peak: 「梁文锋来了,少说话多做事。」(Liang Wenfeng is here — talk less, do more.)
    • peak → valley: 「梁文谷来了,一切正常。」(back to normal)
  • Persistent status badge — right side of the session header (left of the session-log button): red 高峰 ×2 · 省流中 during peak, green 低谷 ×1 otherwise, with full details (windows / multiplier / Beijing time / next switch) on hover. Clicking the badge opens the savings report.
  • Savings metering (0.2.0) — during peak hours the plugin intercepts every streaming model call (llm/stream) and records real token usage per model (input miss / cache hit / output, disjoint counts from the DeepSeek adapter). It then estimates how much the cave-man compression saved you and converts it to RMB at DeepSeek peak prices:
    • saved tokens ≈ peak output tokens × r/(1−r) where r = compression ratio, default 0.6 (conservative; configurable 0–0.9).
    • saved RMB = saved tokens × model peak output price / 1M (peak price = valley ×2; e.g. V4-Flash output ¥9.0/M, V4-Pro output ¥27.0/M).
    • Cache-hit awareness — input is invoiced separately by cache hit vs. miss (hit ¥0.05 vs miss ¥1.5 per M for Flash → 30×; ±for Pro), a cache hit rate health metric is shown, and a cache delta line reports whether a different hit rate helped (+¥) or cost (−¥) extra; net saved = output saved + cache delta.
    • Totals are saved per peak window to ${DSH_HOME:-~/.dsh}/dsh-peak-cost-mode/stats.json and survive restarts (falls back to in-memory if the file cannot be written).
    • Good to know: the “saved” figure is an estimate (a counterfactual — the exact uncompressed output is unknowable). It is clearly labelled as such in the UI.
  • Where savings are shown — the header badge (peak live counter), an ambient readout above the composer (conversation.composer.dock), the peak→valley toast (this peak's summary), and a savings report panel (click the badge): this peak / today / total in tokens + RMB, per-model breakdown, cache hit rate vs. baseline, invoice vs. counterfactual, and a “reset” button (POST /api/peak-cost/reset).

Install

dsh plugin --profile web add dsh-peak-cost-mode
# or from GitHub
dsh plugin --profile web add github:moon09300731/dsh-peak-cost-mode

Then restart dsh web and hard-refresh the browser page.

Configuration

Optional JSON file at ${DSH_HOME:-~/.dsh}/dsh-peak-cost-mode/config.json:

{
  "saveRatio": 0.6,
  "baseCacheHitRate": 0.5,
  "multiplier": 2,
  "prices": {
    "deepseek-v4-flash": { "hit": 0.05, "miss": 1.5, "output": 4.5 },
    "deepseek-v4-pro": { "hit": 0.15, "miss": 4.5, "output": 13.5 }
  }
}
  • saveRatio — assumed output-compression ratio of the cave-man mode (default 0.6; bounds 0–0.9).
  • baseCacheHitRate — assumed input cache-hit rate for the “without plugin” counterfactual input invoice when no valley-time measurement exists (default 0.5).
  • multiplier — peak multiplier used for the RMB conversion (default 2).
  • prices — per-model valley prices in ¥ per million tokens; exact model keys override the built-in flash/pro defaults. Prices go stale — verify against the official DeepSeek pricing page; displayed savings are estimates, not an invoice.

How it works

  • Host (src/index.mjs): a 30 s timer computes the Beijing wall-clock time; on entering a peak window it registers a systemPrompt section (peak-cost-mode, order 60) that makes the next and subsequent model steps reply compressed; on leaving it disposes the section. Since 0.2.0 it also subscribes to the llm/stream waterfall, wrapping each call to capture usage (input/cacheRead/output tokens) + model id at completion time when the Beijing clock is inside a peak window, accumulates a per-window ledger, and exposes GET /api/peak-cost/state, GET /api/peak-cost/stats and POST /api/peak-cost/reset.
  • Client (client.js): polls /api/peak-cost/state every 30 s (mirroring a snapshot to localStorage key dsh.peakCost.v1) and renders the badge, toasts, the composer readout and the report panel.

Note: the prompt section is registered in the host scope, so during peak hours it applies to all sessions of the deployment (that is the cost-saving point). If you want peak compression for one session only, use the dynamic-plugin variant instead.

Development

npm test   # node --check src/index.mjs && node --check client.js

License

MIT © moon09300731

Related plugins