diff --git a/packages/core/src/config/compaction.ts b/packages/core/src/config/compaction.ts index eef67ee26a06..3c5960c83556 100644 --- a/packages/core/src/config/compaction.ts +++ b/packages/core/src/config/compaction.ts @@ -4,7 +4,6 @@ import { Schema } from "effect" import { NonNegativeInt } from "../schema" export class Keep extends Schema.Class("ConfigV2.Compaction.Keep")({ - turns: NonNegativeInt.pipe(Schema.optional), tokens: NonNegativeInt.pipe(Schema.optional), }) {} diff --git a/packages/core/src/session/compaction.ts b/packages/core/src/session/compaction.ts new file mode 100644 index 000000000000..77058b729669 --- /dev/null +++ b/packages/core/src/session/compaction.ts @@ -0,0 +1,224 @@ +export * as SessionCompaction from "./compaction" + +import { LLM, LLMError, LLMEvent, Message, type LLMRequest, type Model } from "@opencode-ai/llm" +import { DateTime, Effect, Stream } from "effect" +import type { Config } from "../config" +import type { EventV2 } from "../event" +import { SessionEvent } from "./event" +import { SessionMessage } from "./message" +import { SessionSchema } from "./schema" +import { Token } from "../util/token" + +const DEFAULT_BUFFER = 20_000 +const DEFAULT_KEEP_TOKENS = 8_000 +const TOOL_OUTPUT_MAX_CHARS = 2_000 +const SUMMARY_OUTPUT_TOKENS = 4_096 +const SUMMARY_TEMPLATE = `Output exactly the Markdown structure shown inside