source dump of claude code
at main 43 lines 1.8 kB view raw
1import { getFeatureValue_CACHED_MAY_BE_STALE } from '../analytics/growthbook.js' 2 3/** 4 * GrowthBook config for time-based microcompact. 5 * 6 * Triggers content-clearing microcompact when the gap since the last main-loop 7 * assistant message exceeds a threshold — the server-side prompt cache has 8 * almost certainly expired, so the full prefix will be rewritten anyway. 9 * Clearing old tool results before the request shrinks what gets rewritten. 10 * 11 * Runs BEFORE the API call (in microcompactMessages, upstream of callModel) 12 * so the shrunk prompt is what actually gets sent. Running after the first 13 * miss would only help subsequent turns. 14 * 15 * Main thread only — subagents have short lifetimes where gap-based eviction 16 * doesn't apply. 17 */ 18export type TimeBasedMCConfig = { 19 /** Master switch. When false, time-based microcompact is a no-op. */ 20 enabled: boolean 21 /** Trigger when (now − last assistant timestamp) exceeds this many minutes. 22 * 60 is the safe choice: the server's 1h cache TTL is guaranteed expired 23 * for all users, so we never force a miss that wouldn't have happened. */ 24 gapThresholdMinutes: number 25 /** Keep this many most-recent compactable tool results. 26 * When set, takes priority over any default; older results are cleared. */ 27 keepRecent: number 28} 29 30const TIME_BASED_MC_CONFIG_DEFAULTS: TimeBasedMCConfig = { 31 enabled: false, 32 gapThresholdMinutes: 60, 33 keepRecent: 5, 34} 35 36export function getTimeBasedMCConfig(): TimeBasedMCConfig { 37 // Hoist the GB read so exposure fires on every eval path, not just when 38 // the caller's other conditions (querySource, messages.length) pass. 39 return getFeatureValue_CACHED_MAY_BE_STALE<TimeBasedMCConfig>( 40 'tengu_slate_heron', 41 TIME_BASED_MC_CONFIG_DEFAULTS, 42 ) 43}