-
Notifications
You must be signed in to change notification settings - Fork 54
feat: include todo list in summarization output #225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…odule Split monolithic file into focused modules: - constants.ts: configuration values - prompts.ts: AI summarization prompts - helpers.ts: utility functions - index.ts: main checkAndSummarizeIfNeeded export Added integration tests following testing trophy philosophy.
Move token threshold check, message splitting, summary generation, message building, and persistence into helpers.ts. Remove dead re-exports and unreachable guard. 100% test coverage.
Preserve active tasks across conversation summarization by appending the current todo list as a <current_todos> XML block alongside the <context_summary> in the summary message.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughRefactors chat summarization into a new Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Client
participant ChatHandler as Chat Handler
participant TodoMgr as Todo Manager
participant Summarizer as Summarization Module
participant LM as Language Model
participant DB as Database
participant Writer as UI Writer
Client->>ChatHandler: new message / step
ChatHandler->>TodoMgr: getAllTodos()
ChatHandler->>Summarizer: checkAndSummarizeIfNeeded(uiMessages, sub, LM, mode, Writer, chatId, fileTokens, todos, abortSignal)
Summarizer->>Writer: signal summarization start
Summarizer->>LM: generate summary (prompt + messages, abortable)
LM-->>Summarizer: summary text / error
Summarizer->>DB: persist summary (chatId, cutoffMessageId)
DB-->>Summarizer: persist result / error
Summarizer->>Writer: signal summarization complete (summary or fallback)
Summarizer-->>ChatHandler: SummarizationResult
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@lib/chat/summarization/helpers.ts`:
- Around line 90-108: The buildSummaryMessage function currently interpolates
summaryText and each todo.content directly into XML-like tags; to prevent
tag-breaking when content contains XML-like strings, HTML-escape special
characters (at least &, <, >, " and ') before interpolation. Add or use a helper
like escapeXml and apply it to summaryText and todo.content (used in the
todos.map) so the generated <context_summary> and <current_todos> blocks remain
well-formed; keep the rest of buildSummaryMessage (id, role, parts) unchanged.
🧹 Nitpick comments (1)
lib/chat/summarization/__tests__/index.test.ts (1)
304-328: LGTM — correctly validates absence of todo block for empty array.Minor style note: this test uses a type assertion on Line 323–324 (
as { type: string; text: string }) while the preceding test (Line 281) accesses the same property without one. Harmless but slightly inconsistent.
…rized content Previously, deleteLastAssistantMessage and regenerateWithNewContent unconditionally nuked the summary on every delete/edit. The existing checkAndInvalidateSummary helper was never called (dead code) and also had a bug comparing by exact message ID — which fails when the cutoff is a user message but we're deleting an assistant message. Now both mutations call checkAndInvalidateSummary before deleting, comparing by creation time to correctly detect overlap regardless of message role. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The summarization LLM call was not receiving the abort signal, so when a user clicked "Stop" the generateText call would continue to completion, wasting tokens and ignoring timeouts. Now the signal propagates through checkAndSummarizeIfNeeded → generateSummaryText → generateText, and abort errors skip persist/completion instead of falling back silently. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…y degradation - Separate synthetic summary messages from real messages before splitting so cutoff ID always references a DB message (Bug 1) - Use incremental summarization with previous_summary context instead of summarizing-a-summary (Bug 2) - Add try-catch around summary deletion in !cutoffMessage branch (Bug 3) - Re-truncate after summary injection reserving summary token budget first to prevent exceeding token limits (Bug 4) - Add isSummaryMessage and extractSummaryText helpers - Add 6 new test cases covering re-summarization scenarios
Summary
buildSummaryMessagenow accepts an optionalTodo[]and appends a<current_todos>XML block when todos are non-emptycheckAndSummarizeIfNeededpasses todos through from the call site inchat-handler.tsviagetTodoManager().getAllTodos()Test plan
npx tsc --noEmit --skipLibCheckpasses<current_todos>block with formatted todo lines when todos exist<current_todos>block when todos are emptySummary by CodeRabbit
New Features
Bug Fixes
Tests