Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
/** Severity of a single cache finding. Rendered as a codicon + color. */
export
const
enum
{
/** Expected, healthy behavior (e.g. new turn appended). */
=
'ok'
,
/** Context that helps interpretation but isn't actionable. */
=
'info'
,
/** Suspicious but not definitively avoidable (e.g. likely expiration). */
=
'warning'
,
/** An avoidable cache break the user should investigate. */
=
'critical'
,
}
/**
* Coarse classification of what broke (or didn't break) the cache for one
* request pair. Used for rail chips and cross-turn aggregation.
*/
export
const
enum
{
/** Pure append or fully stable prefix — the cache behaved as designed. */
=
'healthy'
,
/** Prefix byte-identical but the cache still missed — TTL/eviction. */
=
'expiration'
,
=
'model'
,
=
'tools'
,
=
'system'
,
=
'options'
,
/** Conversation history rewritten or truncated in place. */
=
'history'
,
/** Continuations and other pairs we can't classify. */
=
'unknown'
,
}
/** One human-readable finding about the cache behavior of the current request. */
export
interface
ICacheInsight
{
readonly
:
;
/** Short, scannable summary — doubles as the headline verdict for the first non-OK finding. */
readonly
:
string
;
/** Evidence: what exactly differs and by how much. */
readonly
?
:
string
;
/** Actionable guidance derived from how prefix caches work. */
readonly
?
:
string
;
/** Name of the Components entry this finding refers to (e.g. `system`, `tools`, `messages[7]`). */
readonly
?
:
string
;
/** Break category this finding contributes to, for cross-turn aggregation. */
readonly
?
:
;
}
/** A request-option change, pre-formatted by the caller for display. */
export
interface
ICacheInsightOptionDelta
{
readonly
:
string
;
readonly
:
string
;
readonly
:
string
;
}
export
interface
ICacheInsightsInput
{
readonly
:
string
|
undefined
;
readonly
:
string
|
undefined
;
readonly
:
string
|
undefined
;
readonly
:
string
|
undefined
;
readonly
:
string
|
undefined
;
readonly
:
string
|
undefined
;
readonly
:
readonly
[
]
;
readonly
:
readonly
[
]
;
readonly
:
;
readonly
:
readonly
[
]
;
/** Cache hit percentage (0-100) reported for the current request. */
readonly
:
number
;
/** Total input tokens reported for the current request (0 when unknown). */
readonly
:
number
;
/** Minutes elapsed between the start of the previous and the current request. */
readonly
:
number
|
undefined
;
/** True when the current request is a Responses API continuation (delta-only wire input). */
readonly
:
boolean
;
/** True when the previous request is a Responses API continuation. */
readonly
:
boolean
;
/** False when message-level positional diffing is suppressed (either side is a continuation). */
readonly
:
boolean
;
}
/** How two unequal strings relate to each other structurally. */
export
const
enum
{
/** B is a strict suffix of A — leading bytes were removed. */
=
'leadingRemoved'
,
/** A is a strict suffix of B — bytes were prepended. */
=
'leadingAdded'
,
/** B is a strict prefix of A — trailing bytes were removed. */
=
'trailingRemoved'
,
/** A is a strict prefix of B — bytes were appended. */
=
'trailingAdded'
,
/** The change happens somewhere in the middle. */
=
'innerEdit'
,
}
/** Maximum excerpt length captured for the changed region on each side. */
const
CHANGED_EXCERPT_CAP
=
120
;
export
interface
IStringDivergence
{
readonly
:
;
/** Number of leading chars shared by both sides. */
readonly
:
number
;
/** Number of trailing chars shared by both sides (disjoint from the prefix). */
readonly
:
number
;
readonly
:
number
;
readonly
:
number
;
/** Excerpt of the changed region on the A side (capped). */
readonly
:
string
;
/** Excerpt of the changed region on the B side (capped). */
readonly
:
string
;
}
/**
* Locate where two strings diverge: the shared leading/trailing spans and
* the changed region in between. Returns `undefined` when the strings are
* equal. The common prefix and suffix never overlap, so
* `commonPrefix + commonSuffix <= min(aLength, bLength)`.
*/
export
function
analyzeStringDivergence
(
:
string
,
:
string
)
:
|
undefined
{
if
(
===
)
{
return
undefined
;
}
const
=
.
;
const
=
.
;
const
=
.
min
(
,
)
;
let
=
0
;
while
(
<
&&
.
charCodeAt
(
)
===
.
charCodeAt
(
)
)
{
++
;
}
let
=
0
;
while
(
<
-
&&
.
charCodeAt
(
-
1
-
)
===
.
charCodeAt
(
-
1
-
)
)
{
++
;
}
let
:
;
if
(
===
&&
<
)
{
=
.
;
}
else
if
(
===
&&
<
)
{
=
.
;
}
else
if
(
===
&&
<
)
{
=
.
;
}
else
if
(
===
&&
<
)
{
=
.
;
}
else
{
=
.
;
}
return
{
,
,
,
,
,
:
.
substring
(
,
-
)
.
slice
(
0
,
CHANGED_EXCERPT_CAP
)
,
:
.
substring
(
,
-
)
.
slice
(
0
,
CHANGED_EXCERPT_CAP
)
,
}
;
}
/** One-line human-readable description of a string divergence. */
export
function
describeStringDivergence
(
:
)
:
string
{
switch
(
.
)
{
case
.
:
return
localize
(
'chatDebug.cache.div.appended'
,
"{0} chars appended — the previous content survives as a shared prefix"
,
fmt
(
.
-
.
)
)
;
case
.
:
return
localize
(
'chatDebug.cache.div.truncated'
,
"last {0} chars removed — the remaining content still matches the previous bytes"
,
fmt
(
.
-
.
)
)
;
case
.
:
return
localize
(
'chatDebug.cache.div.prepended'
,
"{0} chars prepended — this block no longer starts with the same bytes"
,
fmt
(
.
-
.
)
)
;
case
.
:
return
localize
(
'chatDebug.cache.div.leadingRemoved'
,
"first {0} chars removed — this block no longer starts with the same bytes"
,
fmt
(
.
-
.
)
)
;
case
.
:
return
localize
(
'chatDebug.cache.div.innerEdit'
,
"edited in place — first difference at char {0} ({1} leading and {2} trailing chars unchanged)"
,
fmt
(
.
)
,
fmt
(
.
)
,
fmt
(
.
)
)
;
}
}
/** Categories of volatile values that classically break prompt caches. */
/**
* Detect whether the changed region on both sides carries the *same kind* of
* volatile value (timestamp, UUID, epoch-like counter) with *different*
* contents — the classic silent cache invalidator: `datetime.now()` or a
* request id interpolated into the prompt.
*/
export
function
detectVolatileValue
(
:
string
,
:
string
)
:
|
undefined
{
for
(
const
{
,
}
of
VOLATILE_PATTERNS
)
{
const
=
.
exec
(
)
?.
[
0
]
;
const
=
.
exec
(
)
?.
[
0
]
;
if
(
!==
undefined
&&
!==
undefined
&&
!==
)
{
return
;
}
}
return
undefined
;
}
/** Context kept around the changed region when scanning for volatile values. */
const
VOLATILE_CONTEXT
=
24
;
/** Cap on the scanned window so huge edits stay cheap to regex. */
const
VOLATILE_WINDOW_CAP
=
240
;
/**
* Run volatile-value detection on a window *around* the changed region of
* each side. The shared prefix often eats the head of a volatile value
* (`09:15:00` vs `09:21:42` diverges after `09:`), so matching only the
* changed bytes would miss the pattern; the surrounding context restores it.
* Identical values inside the context (e.g. the same date on both sides)
* are ignored because {@link detectVolatileValue} requires the matched
* values to differ.
*/
function
detectVolatileValueAround
(
:
string
,
:
string
,
:
)
:
|
undefined
{
const
=
.
max
(
0
,
.
-
VOLATILE_CONTEXT
)
;
const
=
.
substring
(
,
.
min
(
.
-
.
+
VOLATILE_CONTEXT
,
+
VOLATILE_WINDOW_CAP
)
)
;
const
=
.
substring
(
,
.
min
(
.
-
.
+
VOLATILE_CONTEXT
,
+
VOLATILE_WINDOW_CAP
)
)
;
return
detectVolatileValue
(
,
)
;
}
function
volatileValueLabel
(
:
)
:
string
{
switch
(
)
{
case
.
:
return
localize
(
'chatDebug.cache.volatile.timestamp'
,
"timestamp"
)
;
case
.
:
return
localize
(
'chatDebug.cache.volatile.uuid'
,
"unique id (UUID)"
)
;
case
.
:
return
localize
(
'chatDebug.cache.volatile.counter'
,
"large changing number"
)
;
}
}
/** Structured comparison of two JSON tool catalogs. */
export
interface
IToolCatalogDelta
{
readonly
:
readonly
string
[
]
;
readonly
:
readonly
string
[
]
;
/** Tools present on both sides whose definition bytes differ. */
readonly
:
readonly
string
[
]
;
/** True when the set and every definition match — only the order differs. */
readonly
:
boolean
;
readonly
:
number
;
readonly
:
number
;
}
function
parseToolList
(
:
string
|
undefined
)
:
<
string
,
string
>
|
undefined
{
if
(
!
)
{
return
undefined
;
}
let
:
unknown
;
try
{
=
JSON
.
parse
(
)
;
}
catch
{
return
undefined
;
}
if
(
!
Array
.
isArray
(
)
)
{
return
undefined
;
}
const
=
new
Map<string,string>
(
)
;
for
(
let
=
0
;
<
.
;
++
)
{
const
=
[
]
as
{
?
:
unknown
;
?
:
unknown
;
function
?
:
{
?
:
unknown
}
}
|
null
;
const
=
(
&&
typeof
.
===
'string'
&&
.
)
||
(
&&
.
&&
typeof
.
.
===
'string'
&&
.
.
)
||
(
&&
typeof
.
===
'string'
&&
.
)
||
`#${i}`
;
let
:
string
;
try
{
=
JSON
.
stringify
(
)
;
}
catch
{
=
String
(
)
;
}
// Collisions (duplicate names) concatenate so a duplicated entry still
// reads as a modification rather than silently matching.
.
set
(
,
(
.
get
(
)
??
''
)
+
)
;
}
return
;
}
/**
* Compare two tool catalogs at the tool level: which tools were added,
* removed, or had their definition change — or whether the catalog was
* merely reordered (same tools, same bytes, different order). Returns
* `undefined` when either side isn't a parseable JSON array, in which case
* callers should fall back to byte-level divergence.
*/
export
function
analyzeToolCatalog
(
:
string
|
undefined
,
:
string
|
undefined
)
:
|
undefined
{
const
=
parseToolList
(
)
;
const
=
parseToolList
(
)
;
if
(
!
||
!
)
{
return
undefined
;
}
const
:
string
[
]
=
[
]
;
const
:
string
[
]
=
[
]
;
const
:
string
[
]
=
[
]
;
for
(
const
[
,
]
of
)
{
const
=
.
get
(
)
;
if
(
===
undefined
)
{
.
push
(
)
;
}
else
if
(
!==
)
{
.
push
(
)
;
}
}
for
(
const
of
.
keys
(
)
)
{
if
(
!
.
has
(
)
)
{
.
push
(
)
;
}
}
return
{
,
,
,
:
.
===
0
&&
.
===
0
&&
.
===
0
,
:
.
,
:
.
,
}
;
}
const
:
<
,
number
>
=
{
[
.
]
:
0
,
[
.
]
:
1
,
[
.
]
:
2
,
[
.
]
:
3
,
}
;
/** The highest severity present in a findings list (Ok when empty). */
export
function
maxInsightSeverity
(
:
readonly
[
]
)
:
{
let
=
.
;
for
(
const
of
)
{
if
(
[
.
]
>
[
]
)
{
=
.
;
}
}
return
;
}
/** The first warning-or-worse finding — the headline verdict. */
export
function
primaryInsight
(
:
readonly
[
]
)
:
|
undefined
{
return
.
find
(
=>
.
===
.
)
??
.
find
(
=>
.
===
.
)
;
}
/** Cache hit below this is treated as "the cache effectively missed". */
const
EFFECTIVE_MISS_PCT
=
1
;
/** Typical provider prompt-cache TTL, used in the expiration hint. */
const
TYPICAL_TTL_MINUTES
=
5
;
/**
* Most providers only walk back a bounded number of content blocks to find
* a prior cache entry (~20 on Anthropic); appending more than this in one
* turn can silently miss the cache.
*/
const
LOOKBACK_WINDOW_BLOCKS
=
20
;
/**
* Upper bound of the per-model minimum cacheable prefix size (1,024-4,096
* tokens depending on model). Prompts below this may silently never cache.
*/
const
MIN_CACHEABLE_TOKENS
=
4096
;
/**
* Produce the ordered findings list for an A→B request comparison.
*
* Findings are emitted in provider cache-key order (model, tools, system,
* options, messages) so the first critical finding is the earliest byte
* change — the one that actually broke the cache; later changes are
* recomputed regardless.
*/
export
function
computeCacheInsights
(
:
)
:
[
]
{
const
:
[
]
=
[
]
;
const
=
.
!==
.
;
const
=
(
.
??
''
)
!==
(
.
??
''
)
;
const
=
(
.
??
''
)
!==
(
.
??
''
)
;
if
(
)
{
.
push
(
{
:
.
,
:
localize
(
'chatDebug.cache.insight.model.title'
,
"Model changed"
)
,
:
localize
(
'chatDebug.cache.insight.model.detail'
,
"{0} → {1}"
,
.
??
'—'
,
.
??
'—'
)
,
:
localize
(
'chatDebug.cache.insight.model.hint'
,
"Prompt caches are scoped to a model — switching models recomputes the entire prompt. Route sub-tasks that need a different model through a separate request chain so the main loop keeps its cache."
"Options are part of the cache key on most providers. Keep per-request options stable when cache reuse matters."
)
,
:
.
,
}
)
;
}
if
(
.
)
{
.
push
(
...
messageInsights
(
,
||
||
)
)
;
if
(
!
&&
!
&&
!
&&
.
.
===
0
&&
!
.
.
)
{
.
push
(
stablePrefixInsight
(
)
)
;
}
}
else
if
(
.
)
{
.
push
(
{
:
.
,
:
localize
(
'chatDebug.cache.insight.continuation.title'
,
"Responses API continuation"
)
,
:
localize
(
'chatDebug.cache.insight.continuation.detail'
,
"Only the wire delta is captured for this request; prior context is referenced by previous_response_id and reconstructed provider-side. Analysis is limited to system, tools, and request options."
)
,
:
.
,
}
)
;
}
else
if
(
.
)
{
.
push
(
{
:
.
,
:
localize
(
'chatDebug.cache.insight.prevContinuation.title'
,
"Message comparison suppressed"
)
,
:
localize
(
'chatDebug.cache.insight.prevContinuation.detail'
,
"The previous request was a Responses API continuation (delta-only wire input); positionally diffing this full request against it would be misleading."
)
,
:
.
,
}
)
;
}
return
;
}
function
toolsInsight
(
:
string
|
undefined
,
:
string
|
undefined
)
:
{
const
=
analyzeToolCatalog
(
,
)
;
const
=
'tools'
;
if
(
?.
)
{
return
{
:
.
,
:
localize
(
'chatDebug.cache.insight.toolsReorder.title'
,
"Tool definitions reordered"
)
,
:
localize
(
'chatDebug.cache.insight.toolsReorder.detail'
,
"Same {0} tools with identical definitions, sent in a different order."
,
fmt
(
.
)
)
,
:
localize
(
'chatDebug.cache.insight.toolsReorder.hint'
,
"Tools render at the very start of the prompt — a pure reorder still changes the bytes and invalidates the entire cache. Serialize the tool list deterministically (e.g. sort by name)."
)
,
,
:
.
,
}
;
}
if
(
&&
(
.
.
>
0
||
.
.
>
0
)
)
{
const
:
string
[
]
=
[
]
;
if
(
.
.
>
0
)
{
.
push
(
localize
(
'chatDebug.cache.insight.toolsAdded'
,
"added: {0}"
,
.
.
join
(
', '
)
)
)
;
}
if
(
.
.
>
0
)
{
.
push
(
localize
(
'chatDebug.cache.insight.toolsRemoved'
,
"removed: {0}"
,
.
.
join
(
', '
)
)
)
;
}
if
(
.
.
>
0
)
{
.
push
(
localize
(
'chatDebug.cache.insight.toolsModified'
,
"modified: {0}"
,
.
.
join
(
', '
)
)
)
;
}
return
{
:
.
,
:
localize
(
'chatDebug.cache.insight.toolsSet.title'
,
"Tool catalog changed ({0} → {1} tools)"
,
fmt
(
.
)
,
fmt
(
.
)
)
,
:
.
join
(
' · '
)
,
:
localize
(
'chatDebug.cache.insight.toolsSet.hint'
,
"Tool definitions render before everything else, so adding or removing a tool mid-session invalidates the whole prompt. Keep the tool set stable for the life of a session, or use deferred/appended tool loading instead of swapping the catalog."
)
,
,
:
.
,
}
;
}
if
(
&&
.
.
>
0
)
{
return
{
:
.
,
:
localize
(
'chatDebug.cache.insight.toolsDef.title'
,
"Tool definitions modified"
)
,
:
localize
(
'chatDebug.cache.insight.toolsDef.detail'
,
"changed: {0}"
,
.
.
join
(
', '
)
)
,
:
localize
(
'chatDebug.cache.insight.toolsDef.hint'
,
"A changed tool description or schema rewrites the prompt from the tools block onward. Check for dynamic content (counts, paths, timestamps) inside tool descriptions."
)
,
,
:
.
,
}
;
}
// Not parseable as JSON arrays — fall back to byte-level divergence.
const
=
analyzeStringDivergence
(
??
''
,
??
''
)
;
return
{
:
.
,
:
localize
(
'chatDebug.cache.insight.tools.title'
,
"Tool catalog changed"
)
,
:
?
describeStringDivergence
(
)
:
undefined
,
:
localize
(
'chatDebug.cache.insight.tools.hint'
,
"The tool catalog is the first block of the prompt — any byte change here invalidates the entire cache."
)
,
,
:
.
,
}
;
}
function
systemInsight
(
:
string
|
undefined
,
:
string
|
undefined
)
:
{
const
=
analyzeStringDivergence
(
??
''
,
??
''
)
;
const
=
?
detectVolatileValueAround
(
??
''
,
??
''
,
)
:
undefined
;
return
{
:
.
,
:
localize
(
'chatDebug.cache.insight.system.title'
,
"System prompt changed"
)
,
:
?
localize
(
'chatDebug.cache.insight.system.detail'
,
"{0} → {1} chars · {2}"
,
fmt
(
.
)
,
fmt
(
.
)
,
describeStringDivergence
(
)
)
:
undefined
,
:
?
localize
(
'chatDebug.cache.insight.system.volatileHint'
,
"The changed region looks like a {0} — volatile values interpolated into the system prompt break the cache on every request. Move dynamic content after the conversation history or drop it."
,
volatileValueLabel
(
)
)
:
localize
(
'chatDebug.cache.insight.system.hint'
,
"A system prompt change invalidates everything after the tools block. Keep the system prompt byte-stable for the life of a session and inject per-turn context into the newest message instead."
)
,
:
'system'
,
:
.
,
}
;
}
function
messageInsights
(
:
,
:
boolean
)
:
[
]
{
const
{
}
=
;
if
(
!
.
)
{
return
[
]
;
}
const
:
[
]
=
[
]
;
const
=
.
.
;
const
=
`messages[${idx}]`
;
const
=
.
;
if
(
.
.
===
.
)
{
// The first divergence is a message appended past the end of the
// previous request — the healthy growth pattern. (A positional zip
// can only report OnlyInB as the *first* divergence when everything
// before it was identical.)
.
push
(
{
// Downgrade to Info when an earlier tier already broke the cache:
// the append is still fine, but it isn't the story of this request.
:
?
.
:
.
,
:
localize
(
'chatDebug.cache.insight.append.title'
,
"New messages appended — expected growth"
)
,
:
localize
(
'chatDebug.cache.insight.append.detail'
,
"{0} new message(s) after {1} unchanged — the shared prefix was extended, not broken. The uncached tokens are the new suffix being written to the cache for the next request."
,
fmt
(
.
)
,
fmt
(
.
)
)
,
,
:
.
,
}
)
;
// Cache lookback window: providers walk back a bounded number of
// content blocks (~20) to find a prior cache entry. A single turn
// that appends more than that can miss the previous entry even
// though the prefix is byte-identical.
if
(
.
>
LOOKBACK_WINDOW_BLOCKS
)
{
.
push
(
{
:
.
,
:
localize
(
'chatDebug.cache.insight.lookback.title'
,
"{0} blocks appended — beyond the typical cache lookback window"
,
fmt
(
.
)
)
,
:
localize
(
'chatDebug.cache.insight.lookback.detail'
,
"Providers typically look back ~{0} content blocks for a prior cache entry; a turn that appends more can silently miss it even though the prefix matches."
,
LOOKBACK_WINDOW_BLOCKS
)
,
:
localize
(
'chatDebug.cache.insight.lookback.hint'
,
"During long tool loops, place intermediate cache breakpoints every ~15 blocks so the next request can still find a cache entry."
)
,
}
)
;
}
return
;
}
if
(
.
.
===
.
)
{
.
push
(
{
:
.
,
:
localize
(
'chatDebug.cache.insight.truncated.title'
,
"History truncated at messages[{0}]"
,
)
,
:
localize
(
'chatDebug.cache.insight.truncated.detail'
,
"{0} message(s) present in the previous request are missing from this one."
,
fmt
(
.
)
)
,
:
localize
(
'chatDebug.cache.insight.truncated.hint'
,
"History slicing or compaction shortens the prefix — the cache can only match up to the cut, and everything after it is recomputed."
)
,
,
:
.
,
}
)
;
return
;
}
// In-place change (content drift or length change) inside shared history.
const
=
.
.
find
(
=>
.
===
)
;
const
=
?.
??
?.
??
'message'
;
const
=
.
[
]
;
const
=
.
[
]
;
const
=
&&
?
analyzeStringDivergence
(
.
,
.
)
:
undefined
;
const
=
&&
&&
?
detectVolatileValueAround
(
.
,
.
,
)
:
undefined
;
const
:
string
[
]
=
[
]
;
if
(
&&
)
{
.
push
(
localize
(
'chatDebug.cache.insight.drift.sizes'
,
"{0} message, {1} → {2} chars"
,
,
fmt
(
.
)
,
fmt
(
.
)
)
)
;
}
if
(
)
{
.
push
(
describeStringDivergence
(
)
)
;
}
.
push
(
{
:
.
,
:
localize
(
'chatDebug.cache.insight.drift.title'
,
"History rewritten at messages[{0}]"
,
)
,
:
.
join
(
' · '
)
,
:
?
localize
(
'chatDebug.cache.insight.drift.volatileHint'
,
"The changed region looks like a {0} — a volatile value re-rendered into the conversation history breaks the prefix on every request."
,
volatileValueLabel
(
)
)
:
localize
(
'chatDebug.cache.insight.drift.hint'
,
"Conversation history must be byte-identical between requests to reuse the cached prefix. A re-serialized {0} turn — trimmed whitespace, dropped reasoning or preamble text, reformatted tool calls — silently invalidates everything after it."
,
)
,
,
:
.
,
}
)
;
const
=
.
+
.
+
.
+
.
-
1
;
if
(
>
0
)
{
.
push
(
{
:
.
,
:
localize
(
'chatDebug.cache.insight.afterBreak.title'
,
"{0} more changed position(s) after the break"
,
fmt
(
)
)
,
:
localize
(
'chatDebug.cache.insight.afterBreak.detail'
,
"Once the prefix breaks at messages[{0}], everything after it is recomputed regardless — fix the first break first."
,
)
,
}
)
;
}
return
;
}
function
stablePrefixInsight
(
:
)
:
{
if
(
.
<
EFFECTIVE_MISS_PCT
)
{
// Byte-identical prefix, nothing changed, yet ~0% served from cache.
// Two candidate explanations we can tell apart from the data we have:
// a prompt below the provider's minimum cacheable prefix size never
// caches at all; otherwise the entry almost certainly expired or was
// evicted. We can't observe the provider cache directly, so both
// stay "likely"/"may".
if
(
.
>
0
&&
.
<
MIN_CACHEABLE_TOKENS
)
{
return
{
:
.
,
:
localize
(
'chatDebug.cache.insight.tooSmall.title'
,
"Prompt may be below the minimum cacheable size"
)
,
:
localize
(
'chatDebug.cache.insight.tooSmall.detail'
,
"{0} input tokens — providers only cache prompts above a minimum prefix size (roughly 1,024-4,096 tokens depending on model), and smaller prompts silently never cache."
,
fmt
(
.
)
)
,
:
localize
(
'chatDebug.cache.insight.tooSmall.hint'
,
"Small utility requests (titles, summaries) often sit below the threshold; a 0% hit on them is normal and not worth optimizing."
)
,
:
.
,
}
;
}
const
=
.
;
const
=
!==
undefined
&&
>=
1
?
localize
(
'chatDebug.cache.insight.expired.gap'
,
" {0} minute(s) elapsed since the previous request."
,
fmt
(
.
round
(
)
)
)
:
''
;
return
{
:
.
,
:
localize
(
'chatDebug.cache.insight.expired.title'
,
"Likely cache expiration"
)
,
:
localize
(
'chatDebug.cache.insight.expired.detail'
,
"The prompt is byte-identical to the previous request but only {0}% was served from cache.{1}"
,
.
.
toFixed
(
2
)
,
)
,
:
localize
(
'chatDebug.cache.insight.expired.hint'
,
"Provider prompt caches expire after a few minutes of inactivity (typically ~{0} min). Long gaps between requests recompute the full prompt even when nothing changed."
,
TYPICAL_TTL_MINUTES
)
,
:
.
,
}
;
}
return
{
:
.
,
:
localize
(
'chatDebug.cache.insight.stable.title'
,
"Prompt prefix fully stable"
)
,
:
localize
(
'chatDebug.cache.insight.stable.detail'
,
"No divergence detected — {0}% of input tokens were served from cache."
,
.
.
toFixed
(
2
)
)
,
:
.
,
}
;
}
/** Resolve the break category for one request pair from its findings. */
export
function
categorizeCacheBreak
(
:
readonly
[
]
)
:
{
const
=
primaryInsight
(
)
;
if
(
?.
)
{
return
.
;
}
for
(
const
of
)
{
if
(
.
)
{
return
.
;
}
}
return
.
;
}
/** Human-readable label for a break category. */
export
function
cacheBreakCategoryLabel
(
:
)
:
string
{
switch
(
)
{
case
.
:
return
localize
(
'chatDebug.cache.category.healthy'
,
"healthy growth"
)
;
case
.
:
return
localize
(
'chatDebug.cache.category.expiration'
,
"expiration / not cacheable"
)
;
case
.
:
return
localize
(
'chatDebug.cache.category.model'
,
"model changed"
)
;
case
.
:
return
localize
(
'chatDebug.cache.category.tools'
,
"tool catalog changed"
)
;
case
.
:
return
localize
(
'chatDebug.cache.category.system'
,
"system prompt changed"
)
;
case
.
:
return
localize
(
'chatDebug.cache.category.options'
,
"request options changed"
)
;
case
.
:
return
localize
(
'chatDebug.cache.category.history'
,
"history rewritten"
)
;
case
.
:
return
localize
(
'chatDebug.cache.category.unknown'
,
"not classified"
)
;
}
}
/** Break categories that are avoidable on the client side. */
const
AVOIDABLE_CATEGORIES
:
readonly
[
]
=
[
.
,
.
,
.
,
.
,
.
,
]
;
/** The outcome of analyzing one consecutive request pair in a session. */
export
interface
ISessionPairOutcome
{
/** Index of the current (B) turn in the session's turn list. */
readonly
:
number
;
readonly
:
;
/** Input tokens of the B request that were not served from cache. */
readonly
:
number
;
}
/** Aggregate stats for one break category across a session. */
export
interface
ISessionCategoryStat
{
readonly
:
;
readonly
:
number
;
readonly
:
number
;
}
/** Token counts for one turn, used for the token-weighted overall hit rate. */
export
interface
ISessionTurnTokens
{
readonly
:
number
;
readonly
:
number
;
}
/**
* Token-weighted cache hit across a whole session. Per-request percentages
* overweight small utility calls; weighting by input tokens shows the real
* cost picture.
*/
export
interface
ISessionOverallHit
{
readonly
:
number
;
readonly
:
number
;
/** `cachedTokens / inputTokens` as a percentage (0-100). */
readonly
:
number
;
/** Number of turns that reported token usage. */
readonly
:
number
;
}
/** Cross-turn cache health report for a whole session. */
export
interface
ISessionCacheReport
{
readonly
:
number
;
readonly
:
number
;
/** Uncached tokens across pairs whose break was avoidable. */
readonly
:
number
;
/** Token-weighted overall hit rate; undefined when no turn reported usage. */
readonly
:
|
undefined
;
/** Per-category stats, sorted by lost tokens descending (healthy excluded). */
readonly
:
readonly
[
]
;
/** Per-turn category, for rail decoration. */
readonly
:
<
number
,
>
;
/** Session-level findings: recurring invalidators and the overall verdict. */
readonly
:
readonly
[
]
;
}
/** A recurring break category needs at least this many occurrences. */
const
RECURRING_THRESHOLD
=
2
;
/**
* Aggregate per-pair outcomes into a session-level report: which break
* categories recur (a one-off break is a curiosity; a recurring one is a
* bug), how many tokens each cost, and the token-weighted overall hit rate
* across all turns (`turnTokens` covers every turn, including the first,
* which has no pair).
*/