feat: 添加 prompt 缓存命中率检测与警告功能

每次 API 请求后自动计算缓存命中率,低于阈值(默认 80%)时在对话流中显示黄色警告消息。
同时更新 /context 命令输出中显示缓存命中率。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
claude-code-best
2026-05-07 10:49:06 +08:00
parent e8759f3402
commit e3c0699f5b
5 changed files with 191 additions and 0 deletions

View File

@@ -115,6 +115,8 @@ export function ContextVisualization({ data }: Props): React.ReactNode {
agents,
skills,
messageBreakdown,
cacheHitRate,
cacheThreshold,
} = data;
// Filter out categories with 0 tokens for the legend, and exclude Free space, Autocompact buffer, and deferred
@@ -166,6 +168,12 @@ export function ContextVisualization({ data }: Props): React.ReactNode {
{model} · {formatTokens(totalTokens)}/{formatTokens(rawMaxTokens)} tokens ({percentage}%)
</Text>
<CollapseStatus />
{cacheHitRate !== undefined && cacheThreshold !== undefined && (
<Text color={cacheHitRate < cacheThreshold ? 'warning' : undefined}>
Cache hit rate: {cacheHitRate.toFixed(0)}%
{cacheHitRate < cacheThreshold ? ` (below ${cacheThreshold}% threshold)` : ''}
</Text>
)}
<Text> </Text>
<Text dimColor italic>
Estimated usage by category