@@ -29,6 +29,12 @@ const COMPACTABLE_TOOLS = new Set([
2929 'edit_file' ,
3030] ) ;
3131
32+ const MICRO_COMPACT_THRESHOLD = 0.25 ;
33+ const MICRO_COMPACT_MIN_CHARS = 120 ;
34+ const COMPACTION_THRESHOLD = 0.9 ;
35+ const KEEP_RECENT_TURNS = 1 ;
36+ const REACTIVE_COMPACT_MAX_RETRIES = 3 ;
37+
3238export class ContextService extends Effect . Service < ContextService > ( ) ( 'Context' , {
3339 effect : Effect . gen ( function * ( ) {
3440 const session = yield * SessionService ;
@@ -107,7 +113,7 @@ export class ContextService extends Effect.Service<ContextService>()('Context',
107113 contextWindow : number ,
108114 jsonlPath : string
109115 ) : boolean {
110- if ( promptEstimate <= contextWindow * config . microCompactThreshold ) return false ;
116+ if ( promptEstimate <= contextWindow * MICRO_COMPACT_THRESHOLD ) return false ;
111117
112118 const compactedTurnIds = new Set < number > ( ) ;
113119 for ( const ev of events ) {
@@ -124,7 +130,7 @@ export class ContextService extends Effect.Service<ContextService>()('Context',
124130 if ( ev . turnId >= currentTurnId - 1 ) continue ;
125131 if ( compactedTurnIds . has ( ev . turnId ) ) continue ;
126132 if ( ! COMPACTABLE_TOOLS . has ( ev . toolName . toLowerCase ( ) ) ) continue ;
127- if ( ev . output . length <= config . microCompactMinChars ) continue ;
133+ if ( ev . output . length <= MICRO_COMPACT_MIN_CHARS ) continue ;
128134 oldResults . push ( ev ) ;
129135 }
130136
@@ -165,7 +171,7 @@ export class ContextService extends Effect.Service<ContextService>()('Context',
165171 return { didCompress : false , released : 0 , promptEstimate } ;
166172 }
167173
168- const threshold = modelMaxTokens * config . compactionThreshold ;
174+ const threshold = modelMaxTokens * COMPACTION_THRESHOLD ;
169175 if ( promptEstimate <= threshold ) {
170176 return { didCompress : false , released : 0 , promptEstimate } ;
171177 }
@@ -208,7 +214,7 @@ export class ContextService extends Effect.Service<ContextService>()('Context',
208214
209215 let released = 0 ;
210216
211- const threshold = modelMaxTokens ? modelMaxTokens * config . compactionThreshold : Infinity ;
217+ const threshold = modelMaxTokens ? modelMaxTokens * COMPACTION_THRESHOLD : Infinity ;
212218 if ( usage === undefined || usage - released > threshold ) {
213219 released += await tryCompaction (
214220 sessionId ,
@@ -236,7 +242,7 @@ export class ContextService extends Effect.Service<ContextService>()('Context',
236242 currentTurnId : number ,
237243 compactedTurnIds : Set < number >
238244 ) : Promise < number > {
239- const endTurn = currentTurnId - config . keepRecentTurns - 1 ;
245+ const endTurn = currentTurnId - KEEP_RECENT_TURNS - 1 ;
240246 if ( endTurn < 1 ) return 0 ;
241247
242248 const inRange = compactedEvents . filter ( ( ev ) => {
0 commit comments