diff --git a/packages/core/src/plugin/agent.ts b/packages/core/src/plugin/agent.ts index 5d0246742d7..ee4101f8bbd 100644 --- a/packages/core/src/plugin/agent.ts +++ b/packages/core/src/plugin/agent.ts @@ -23,16 +23,6 @@ Guidelines: Complete the user's search request efficiently and report your findings clearly.` -const PROMPT_COMPACTION = `You are an anchored context summarization assistant for coding sessions. - -Summarize only the conversation history you are given. The newest turns may be kept verbatim outside your summary, so focus on the older context that still matters for continuing the work. - -If the prompt includes a block, treat it as the current anchored summary. Update it with the new history by preserving still-true details, removing stale details, and merging in new facts. - -Always follow the exact output structure requested by the user prompt. Keep every section, preserve exact file paths and identifiers when known, and prefer terse bullets over paragraphs. - -Do not answer the conversation itself. Do not mention that you are summarizing, compacting, or merging context. Respond in the same language as the conversation.` - const PROMPT_TITLE = `You are a title generator. You output ONLY a thread title. Nothing else. @@ -144,8 +134,6 @@ export const Plugin = define({ item.name = Agent.Name.make("Compaction") item.mode = "primary" item.hidden = true - item.system = PROMPT_COMPACTION - item.permissions.push({ action: "*", resource: "*", effect: "deny" }) }) draft.update(Agent.ID.make("title"), (item) => { diff --git a/packages/core/src/session/compaction.ts b/packages/core/src/session/compaction.ts index 91a48e32ba9..d8abd943b05 100644 --- a/packages/core/src/session/compaction.ts +++ b/packages/core/src/session/compaction.ts @@ -1,6 +1,6 @@ export * as SessionCompaction from "./compaction.js" -import { LLMClient, LLMEvent, Message, type ContentPart } from "@opencode-ai/ai" +import { LLMClient, LLMEvent, LLMRequest, Message, type ContentPart } from "@opencode-ai/ai" import { Agent } from "@opencode-ai/schema/agent" import { SessionError } from "@opencode-ai/schema/session-error" import { Context, Effect, Layer, Stream } from "effect" @@ -18,6 +18,8 @@ import { Token } from "../util/token.js" import { SessionUsage } from "./usage.js" import { State } from "../state.js" import { toLLMMessages } from "./runner/to-llm-message.js" +import type { AgentNotFoundError } from "./error.js" +import type { Instructions } from "../instructions/index.js" const DEFAULT_BUFFER = 20_000 const DEFAULT_KEEP_TOKENS = 15_000 @@ -25,13 +27,16 @@ const OUTPUT_TOKEN_MAX = 32_000 const TOOL_OUTPUT_MAX_CHARS = 2_000 const IMAGE_TOKEN_ESTIMATE = 1_500 const PDF_TOKEN_ESTIMATE = 2_000 -const SUMMARY_TEMPLATE = `Output exactly the Markdown structure shown inside