The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(compact): say so when a short chat no longer fits the window
purple39c9ead5b884
diff --git a/src/lib/__tests__/run-compact-command.test.ts b/src/lib/__tests__/run-compact-command.test.tsindex 932faaac..63b51c90 100644--- a/src/lib/__tests__/run-compact-command.test.ts+++ b/src/lib/__tests__/run-compact-command.test.ts@@ -426,3 +426,44 @@ describe('nothing-to-compact sagt, WELCHER der beiden Faelle vorliegt', () => {expect(schon).toMatch(/already covered/i)})})++// ── Jaeger A, A3: zu wenige Zuege, aber zu lang fuer das Fenster ──────────+describe('nothing-to-compact over a chat that does not fit the window', () => {+ // 16K window, one answer of about 20K tokens, two short turns after it.+ const RIESIG = 'x'.repeat(82_500)+ const kurzerChatMitRiesenantwort = () => chatMit([+ nachricht('m0', 'Frage'),+ nachricht('m1', RIESIG, 'assistant'),+ nachricht('m2', 'Weiter'),+ nachricht('m3', 'Gut', 'assistant'),+ ])++ it('says that one message alone is longer than the window, not "short enough"', async () => {+ kurzerChatMitRiesenantwort()+ const r = await lauf({ window: 16_384 })+ expect(r).toEqual({ ok: false, reason: 'nothing-to-compact', detail: 'message-over-window' })+ expect(zusammenfasser).not.toHaveBeenCalled()+ const text = compactOutcomeMessage(r)+ expect(text).not.toMatch(/short enough/i)+ expect(text).toMatch(/too few turns/i)+ expect(text).toMatch(/one message alone is longer than the model's context window/i)+ })++ it('names the case where only the few turns together overflow', async () => {+ const viertel = 'y'.repeat(18_000)+ chatMit([+ nachricht('m0', viertel), nachricht('m1', viertel, 'assistant'),+ nachricht('m2', viertel), nachricht('m3', viertel, 'assistant'),+ ])+ const r = await lauf({ window: 16_384 })+ expect(r).toEqual({ ok: false, reason: 'nothing-to-compact', detail: 'over-window' })+ expect(compactOutcomeMessage(r)).toMatch(/no longer fit the model's context window/i)+ })++ it('NEGATIVE CONTROL: the same short chat inside a large window is still "short enough"', async () => {+ kurzerChatMitRiesenantwort()+ const r = await lauf({ window: 131_072 })+ expect(r).toEqual({ ok: false, reason: 'nothing-to-compact' })+ expect(compactOutcomeMessage(r)).toMatch(/short enough/i)+ })+})diff --git a/src/lib/run-compact-command.ts b/src/lib/run-compact-command.tsindex f0ffeb49..e7a1cda5 100644--- a/src/lib/run-compact-command.ts+++ b/src/lib/run-compact-command.ts@@ -121,6 +121,21 @@ function contextFillOf(conv: { id: string; messages: Message[] }) {)}+/**+ * Why a chat with too few turns to cut still does not fit: undefined when it+ * fits (or the window is unknown), 'message-over-window' when one message is+ * longer than the whole window, 'over-window' when the few turns together are.+ */+function overWindowDetail(+ visible: ReadonlyArray<{ content: string }>,+ windowTokens: number,+): 'message-over-window' | 'over-window' | undefined {+ if (!(Number.isFinite(windowTokens) && windowTokens > 0)) return undefined+ const sizes = visible.map((m) => estimateTokens(m.content) + MESSAGE_OVERHEAD_TOKENS)+ if (sizes.some((t) => t > windowTokens)) return 'message-over-window'+ return sizes.reduce((a, b) => a + b, 0) > windowTokens ? 'over-window' : undefined+}+/** A stored message the model actually saw. App notices never reach a model. */export function isModelVisible(m: Message): boolean {return m.role !== 'system' && typeof m.content === 'string' && m.content.trim() !== ''@@ -163,7 +178,12 @@ export async function runCompactForConversation(opts: {const window = opts.window?? (await resolveSendWindow(opts.activeModel).catch(() => ({ window: 0 }))).windowconst cutAt = visible.length - keepRecentCount(visible, window)- if (cutAt <= 0) return { ok: false, reason: 'nothing-to-compact' }+ if (cutAt <= 0) {+ // Too few turns to cut anything is not the same as "short enough to send+ // whole": one huge answer in a short chat fills the window on its own+ // (Jaeger A, A3). Say which of the two it is.+ return { ok: false, reason: 'nothing-to-compact', detail: overWindowDetail(visible, window) }+ }// Do not re-summarise material an earlier summary already covers: that is// the summary-of-a-summary decay this feature is designed to avoid. The cut@@ -318,6 +338,12 @@ export function compactOutcomeMessage(outcome: CompactOutcome): string {if (outcome.detail === 'already-compacted') {return 'Nothing new to summarise — everything before the last summary is already covered, and the turns since then are the ones being kept.'}+ if (outcome.detail === 'message-over-window') {+ return 'Nothing to summarise: this conversation has too few turns to cut, and one message alone is longer than the model\'s context window. It gets shortened when it is sent; the full text stays here.'+ }+ if (outcome.detail === 'over-window') {+ return 'Nothing to summarise: this conversation has too few turns to cut, but together they no longer fit the model\'s context window. The oldest part gets shortened when it is sent; the full text stays here.'+ }return 'Nothing to summarise yet — this conversation is still short enough to send whole.'case 'no-conversation':return 'That chat is gone, so there was nothing to summarise.'