fix(prompt): persist cursor command replay context

This commit is contained in:
leokun
2026-07-30 20:28:20 +08:00
parent 4451a6df3b
commit 3349b13a2b
6 changed files with 62 additions and 261 deletions
+15 -4
View File
@@ -26,13 +26,10 @@ func BuildUserMessageReplayMessage(userMessage *agentv1.UserMessage) (Message, b
func buildUserReplayMessage(text string, selectedContext *agentv1.SelectedContext) (Message, bool) {
images := buildSelectedImageContentParts(selectedContext)
sections := make([]string, 0, 5)
sections := make([]string, 0, 4)
if text != "" {
sections = append(sections, formatMessageText(fmt.Sprintf("<user_query>\n%s\n</user_query>", text)))
}
if cursorCommands := buildSelectedCursorCommandsPromptSection(selectedContext); cursorCommands != "" {
sections = append(sections, cursorCommands)
}
if ideState := buildSelectedIDEStatePromptSection(selectedContext); ideState != "" {
sections = append(sections, ideState)
}
@@ -65,6 +62,20 @@ func buildUserReplayMessage(text string, selectedContext *agentv1.SelectedContex
}, true
}
// BuildSelectedCursorCommandsReplayMessage renders command content for new history entries.
// Keeping this separate from BuildUserMessageReplayMessage prevents old user_message entries
// from changing their model-visible meaning after a backend upgrade.
func BuildSelectedCursorCommandsReplayMessage(userMessage *agentv1.UserMessage) (Message, bool) {
if userMessage == nil {
return Message{}, false
}
content := buildSelectedCursorCommandsPromptSection(userMessage.GetSelectedContext())
if content == "" {
return Message{}, false
}
return Message{Role: "user", Content: content}, true
}
func buildSelectedCursorCommandsPromptSection(selectedContext *agentv1.SelectedContext) string {
if selectedContext == nil || len(selectedContext.GetCursorCommands()) == 0 {
return ""