diff --git a/public/src/content.js b/public/src/content.js index e74f2b1..18997b7 100644 --- a/public/src/content.js +++ b/public/src/content.js @@ -299,11 +299,10 @@ function collapseSidebarDebris(text) { // No summarization: content is real, just structurally compressed. // Stages run in order of aggressiveness, stopping when content fits. export function fitPageContent(pageContent, maxModelTokens) { - // Reserve tokens for everything except page content: - // system prompt ~300, computed intel ~200, analysis ~300, - // wrapper text ~100, chat history ~8000, output ~4000, safety ~2000 - const overhead = 15000; - const maxPageTokens = Math.max(0, maxModelTokens - overhead); + // Reserve 20% of context for overhead (system prompt, chat history, output) + // but never more than 15k and always leave at least 60% for page content + const overhead = Math.min(15000, Math.floor(maxModelTokens * 0.2)); + const maxPageTokens = Math.max(Math.floor(maxModelTokens * 0.6), maxModelTokens - overhead); const originalTokens = estimateTokens(pageContent); if (originalTokens <= maxPageTokens) {