Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/core/condense/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,32 @@ describe("summarizeConversation", () => {
const mockCallArgs = (maybeRemoveImageBlocks as Mock).mock.calls[0][0] as any[]
expect(mockCallArgs[mockCallArgs.length - 1]).toEqual(expectedFinalMessage)
})
it("should include the original first user message in summarization input", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a complementary test where an earlier summary exists to assert the original first ask remains present in the summarization input across both manual and automatic condense flows.

const messages: ApiMessage[] = [
{ role: "user", content: "Initial ask", ts: 1 },
{ role: "assistant", content: "Ack", ts: 2 },
{ role: "user", content: "Follow-up", ts: 3 },
{ role: "assistant", content: "Response", ts: 4 },
{ role: "user", content: "More", ts: 5 },
{ role: "assistant", content: "Later", ts: 6 },
{ role: "user", content: "Newest", ts: 7 },
]

await summarizeConversation(messages, mockApiHandler, defaultSystemPrompt, taskId, DEFAULT_PREV_CONTEXT_TOKENS)

const mockCallArgs = (maybeRemoveImageBlocks as Mock).mock.calls[0][0] as any[]

// Expect the original first user message to be present in the messages sent to the summarizer
const hasInitialAsk = mockCallArgs.some(
(m) =>
m.role === "user" &&
(typeof m.content === "string"
? m.content === "Initial ask"
: Array.isArray(m.content) &&
m.content.some((b: any) => b.type === "text" && b.text === "Initial ask")),
)
expect(hasInitialAsk).toBe(true)
})

it("should calculate newContextTokens correctly with systemPrompt", async () => {
const messages: ApiMessage[] = [
Expand Down
7 changes: 3 additions & 4 deletions src/core/condense/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ This summary should be thorough in capturing technical details, code patterns, a

Your summary should be structured as follows:
Context: The context to continue the conversation with. If applicable based on the current task, this should include:
1. Previous Conversation: High level details about what was discussed throughout the entire conversation with the user. This should be written to allow someone to be able to follow the general overarching conversation flow.
2. Current Work: Describe in detail what was being worked on prior to this request to summarize the conversation. Pay special attention to the more recent messages in the conversation.
1. Previous Conversation: High level details about what was discussed throughout the entire conversation with the user. This should be written to allow someone to be able to follow the general overarching conversation flow. 2. Current Work: Describe in detail what was being worked on prior to this request to summarize the conversation. Pay special attention to the more recent messages in the conversation.
3. Key Technical Concepts: List all important technical concepts, technologies, coding conventions, and frameworks discussed, which might be relevant for continuing with this work.
4. Relevant Files and Code: If applicable, enumerate specific files and code sections examined, modified, or created for the task continuation. Pay special attention to the most recent messages and changes.
5. Problem Solving: Document problems solved thus far and any ongoing troubleshooting efforts.
Expand Down Expand Up @@ -103,8 +102,8 @@ export async function summarizeConversation(

// Always preserve the first message (which may contain slash command content)
const firstMessage = messages[0]
// Get messages to summarize, excluding the first message and last N messages
const messagesToSummarize = getMessagesSinceLastSummary(messages.slice(1, -N_MESSAGES_TO_KEEP))
// Get messages to summarize, including the first message and excluding the last N messages
const messagesToSummarize = getMessagesSinceLastSummary(messages.slice(0, -N_MESSAGES_TO_KEEP))

if (messagesToSummarize.length <= 1) {
const error =
Expand Down
Loading