|
@@ -7,13 +7,13 @@ import { Provider } from "../provider/provider"
|
|
|
import { MessageV2 } from "./message-v2"
|
|
import { MessageV2 } from "./message-v2"
|
|
|
import z from "zod"
|
|
import z from "zod"
|
|
|
import { SessionPrompt } from "./prompt"
|
|
import { SessionPrompt } from "./prompt"
|
|
|
-import { Flag } from "../flag/flag"
|
|
|
|
|
import { Token } from "../util/token"
|
|
import { Token } from "../util/token"
|
|
|
import { Log } from "../util/log"
|
|
import { Log } from "../util/log"
|
|
|
import { SessionProcessor } from "./processor"
|
|
import { SessionProcessor } from "./processor"
|
|
|
import { fn } from "@/util/fn"
|
|
import { fn } from "@/util/fn"
|
|
|
import { Agent } from "@/agent/agent"
|
|
import { Agent } from "@/agent/agent"
|
|
|
import { Plugin } from "@/plugin"
|
|
import { Plugin } from "@/plugin"
|
|
|
|
|
+import { Config } from "@/config/config"
|
|
|
|
|
|
|
|
export namespace SessionCompaction {
|
|
export namespace SessionCompaction {
|
|
|
const log = Log.create({ service: "session.compaction" })
|
|
const log = Log.create({ service: "session.compaction" })
|
|
@@ -27,8 +27,9 @@ export namespace SessionCompaction {
|
|
|
),
|
|
),
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- export function isOverflow(input: { tokens: MessageV2.Assistant["tokens"]; model: Provider.Model }) {
|
|
|
|
|
- if (Flag.OPENCODE_DISABLE_AUTOCOMPACT) return false
|
|
|
|
|
|
|
+ export async function isOverflow(input: { tokens: MessageV2.Assistant["tokens"]; model: Provider.Model }) {
|
|
|
|
|
+ const config = await Config.get()
|
|
|
|
|
+ if ((config.compaction?.auto ?? true) === false) return false
|
|
|
const context = input.model.limit.context
|
|
const context = input.model.limit.context
|
|
|
if (context === 0) return false
|
|
if (context === 0) return false
|
|
|
const count = input.tokens.input + input.tokens.cache.read + input.tokens.output
|
|
const count = input.tokens.input + input.tokens.cache.read + input.tokens.output
|
|
@@ -46,7 +47,8 @@ export namespace SessionCompaction {
|
|
|
// calls. then erases output of previous tool calls. idea is to throw away old
|
|
// calls. then erases output of previous tool calls. idea is to throw away old
|
|
|
// tool calls that are no longer relevant.
|
|
// tool calls that are no longer relevant.
|
|
|
export async function prune(input: { sessionID: string }) {
|
|
export async function prune(input: { sessionID: string }) {
|
|
|
- if (Flag.OPENCODE_DISABLE_PRUNE) return
|
|
|
|
|
|
|
+ const config = await Config.get()
|
|
|
|
|
+ if ((config.compaction?.prune ?? true) === false) return
|
|
|
log.info("pruning")
|
|
log.info("pruning")
|
|
|
const msgs = await Session.messages({ sessionID: input.sessionID })
|
|
const msgs = await Session.messages({ sessionID: input.sessionID })
|
|
|
let total = 0
|
|
let total = 0
|