From 1764e3e5dff836255d121a933dd92542368346f9 Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Fri, 12 Jun 2026 18:26:00 +0900 Subject: feat(chat): chat limit — bulk quarter-unload, 75% fresh-load window, show-earlier page-in MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Long transcripts no longer grow unbounded: past the chat limit (default 256 chunks, localStorage dispatch.chatLimit) the oldest ceil(limit/4) committed chunks are unloaded in ONE bulk pass — never one-per-delta (old Dispatch's scroll-jump-per-step bug) — and only while the reader is stuck to the bottom (scrolled-up readers defer the trim; it catches up in whole quarters). A fresh page load windows to the newest floor(0.75*limit). Unloading is purely local (IndexedDB cache + server keep everything); a hiddenBeforeSeq watermark keeps history merges from resurrecting unloaded chunks, and a 'Show earlier messages' affordance pages a quarter back in from the cache with scroll-anchor preservation. Thinking-collapse render keys stay stable across trims via a hiddenThinkingCount ordinal base. - core/chunks/trim.ts: pure policy (trim/window/restore/normalize) + tests - chat store: chatLimit + canUnload deps, windowed load, showEarlier() - composition root: dispatch.chatLimit localStorage knob + unload gate wired to smart-scroll isAtBottom() - backend CR-5 OPENED (not a blocker): ?limit=/?beforeSeq= on GET /conversations/:id (courier backend-handoff-chat-limit.md) - scripts/live-probe.ts: fix pre-existing stale TurnMetricsEntry reads (m1.usage -> total.usage) that crashed the probe; 17/17 live checks pass --- src/app/App.svelte | 34 ++- src/app/store.svelte.ts | 32 +++ src/core/chunks/index.ts | 12 + src/core/chunks/reducer.ts | 11 +- src/core/chunks/trim.test.ts | 218 ++++++++++++++++ src/core/chunks/trim.ts | 149 +++++++++++ src/core/chunks/types.ts | 17 ++ src/features/chat/store.svelte.ts | 75 +++++- src/features/chat/store.test.ts | 289 ++++++++++++++++++++++ src/features/chat/ui.test.ts | 39 +++ src/features/chat/ui/ChatView.svelte | 46 +++- src/features/smart-scroll/ui/controller.svelte.ts | 10 + 12 files changed, 926 insertions(+), 6 deletions(-) create mode 100644 src/core/chunks/trim.test.ts create mode 100644 src/core/chunks/trim.ts (limited to 'src') diff --git a/src/app/App.svelte b/src/app/App.svelte index 50f24e7..4c5a82b 100644 --- a/src/app/App.svelte +++ b/src/app/App.svelte @@ -1,5 +1,6 @@