mirror of
https://wget.la/https://github.com/leookun/cursor-byok
synced 2026-08-18 03:57:06 +08:00
fix(prompt): replay selected Cursor commands
Include client-resolved command content in model-visible user history so slash commands such as /init retain their actual instructions.
This commit is contained in:
@@ -26,10 +26,13 @@ func BuildUserMessageReplayMessage(userMessage *agentv1.UserMessage) (Message, b
|
||||
|
||||
func buildUserReplayMessage(text string, selectedContext *agentv1.SelectedContext) (Message, bool) {
|
||||
images := buildSelectedImageContentParts(selectedContext)
|
||||
sections := make([]string, 0, 4)
|
||||
sections := make([]string, 0, 5)
|
||||
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)
|
||||
}
|
||||
@@ -62,6 +65,32 @@ func buildUserReplayMessage(text string, selectedContext *agentv1.SelectedContex
|
||||
}, true
|
||||
}
|
||||
|
||||
func buildSelectedCursorCommandsPromptSection(selectedContext *agentv1.SelectedContext) string {
|
||||
if selectedContext == nil || len(selectedContext.GetCursorCommands()) == 0 {
|
||||
return ""
|
||||
}
|
||||
entries := make([]string, 0, len(selectedContext.GetCursorCommands()))
|
||||
for _, command := range selectedContext.GetCursorCommands() {
|
||||
if command == nil {
|
||||
continue
|
||||
}
|
||||
content := strings.TrimSpace(command.GetContent())
|
||||
if content == "" {
|
||||
continue
|
||||
}
|
||||
name := strings.TrimSpace(command.GetName())
|
||||
if name == "" {
|
||||
entries = append(entries, "<cursor_command>\n"+content+"\n</cursor_command>")
|
||||
continue
|
||||
}
|
||||
entries = append(entries, fmt.Sprintf("<cursor_command name=\"%s\">\n%s\n</cursor_command>", escapePromptXML(name), content))
|
||||
}
|
||||
if len(entries) == 0 {
|
||||
return ""
|
||||
}
|
||||
return "<cursor_commands>\n" + strings.Join(entries, "\n\n") + "\n</cursor_commands>"
|
||||
}
|
||||
|
||||
func buildSelectedIDEStatePromptSection(selectedContext *agentv1.SelectedContext) string {
|
||||
if selectedContext == nil || selectedContext.GetInvocationContext() == nil {
|
||||
return ""
|
||||
|
||||
Reference in New Issue
Block a user