@@ -7,13 +7,13 @@ import { Provider } from "../provider/provider"
77import { MessageV2 } from "./message-v2"
88import z from "zod"
99import { SessionPrompt } from "./prompt"
10+ import { Flag } from "../flag/flag"
1011import { Token } from "../util/token"
1112import { Log } from "../util/log"
1213import { SessionProcessor } from "./processor"
1314import { fn } from "@/util/fn"
1415import { Agent } from "@/agent/agent"
1516import { Plugin } from "@/plugin"
16- import { Config } from "@/config/config"
1717
1818export namespace SessionCompaction {
1919 const log = Log . create ( { service : "session.compaction" } )
@@ -27,14 +27,15 @@ export namespace SessionCompaction {
2727 ) ,
2828 }
2929
30- export async function isOverflow ( input : { tokens : MessageV2 . Assistant [ "tokens" ] ; model : Provider . Model } ) {
31- const config = await Config . get ( )
32- if ( config . compaction ?. auto === false ) return false
30+ export const NEXT_INPUT_TOKEN_MAX = 20_000
31+
32+ export function isOverflow ( input : { tokens : MessageV2 . Assistant [ "tokens" ] ; model : Provider . Model } ) {
33+ if ( Flag . OPENCODE_DISABLE_AUTOCOMPACT ) return false
3334 const context = input . model . limit . context
3435 if ( context === 0 ) return false
3536 const count = input . tokens . input + input . tokens . cache . read + input . tokens . output
3637 const output = Math . min ( input . model . limit . output , SessionPrompt . OUTPUT_TOKEN_MAX ) || SessionPrompt . OUTPUT_TOKEN_MAX
37- const usable = context - output
38+ const usable = input . model . limit . input ? input . model . limit . input - NEXT_INPUT_TOKEN_MAX : context - output
3839 return count > usable
3940 }
4041
@@ -47,8 +48,7 @@ export namespace SessionCompaction {
4748 // calls. then erases output of previous tool calls. idea is to throw away old
4849 // tool calls that are no longer relevant.
4950 export async function prune ( input : { sessionID : string } ) {
50- const config = await Config . get ( )
51- if ( config . compaction ?. prune === false ) return
51+ if ( Flag . OPENCODE_DISABLE_PRUNE ) return
5252 log . info ( "pruning" )
5353 const msgs = await Session . messages ( { sessionID : input . sessionID } )
5454 let total = 0
0 commit comments