Skip to content

Commit 7109561

Browse files
committed
Compact with optional message
1 parent 24054c2 commit 7109561

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

src/repl/repl.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2261,9 +2261,11 @@ func (r *REPL) getCurrentModelForProvider() string {
22612261

22622262
// handleCompactCommand processes the /compact command
22632263
// It loads the compact.txt prompt and submits the entire conversation history
2264-
// to the AI, then replaces all messages with the AI's response
2264+
// to the AI, then replaces all messages with the AI's response.
2265+
// The optional extra argument is appended to the compact prompt to let the
2266+
// caller steer the summarization (e.g. "focus on the API changes").
22652267

2266-
func (r *REPL) handleCompactCommand() error {
2268+
func (r *REPL) handleCompactCommand(extra ...string) error {
22672269
// Check if there are enough messages to compact
22682270
if len(r.messages) < 2 {
22692271
fmt.Print("Not enough messages to compact. Need at least one exchange.\r\n")
@@ -2282,6 +2284,11 @@ func (r *REPL) handleCompactCommand() error {
22822284
return fmt.Errorf("failed to read compact prompt: %v", err)
22832285
}
22842286

2287+
promptText := string(compactPrompt)
2288+
if extraText := strings.TrimSpace(strings.Join(extra, " ")); extraText != "" {
2289+
promptText = strings.TrimRight(promptText, "\n") + "\n\n" + extraText
2290+
}
2291+
22852292
// Create a serialized version of the conversation for the AI
22862293
var conversationText strings.Builder
22872294
conversationText.WriteString("# Conversation History\n\n")
@@ -2294,7 +2301,7 @@ func (r *REPL) handleCompactCommand() error {
22942301
// Create a new message with the compact prompt and conversation history
22952302
compactMessage := llm.Message{
22962303
Role: "user",
2297-
Content: string(compactPrompt) + "\n\n" + conversationText.String(),
2304+
Content: promptText + "\n\n" + conversationText.String(),
22982305
}
22992306

23002307
// Save original messages for recovery if needed

src/repl/repl_chat.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (r *REPL) handleChatCommand(args []string) (string, error) {
9292
output.WriteString(" /chat list - Display conversation messages (truncated)\r\n")
9393
output.WriteString(" /chat log - Display full conversation with preserved formatting\r\n")
9494
output.WriteString(" /chat undo [N] - Remove last or Nth message\r\n")
95-
output.WriteString(" /chat compact - Compact conversation into a single message\r\n")
95+
output.WriteString(" /chat compact [text] - Compact conversation; optional text is appended to the compact prompt\r\n")
9696
return output.String(), nil
9797
}
9898

@@ -137,7 +137,11 @@ func (r *REPL) handleChatCommand(args []string) (string, error) {
137137
}
138138
return "", nil
139139
case "compact":
140-
return "", r.handleCompactCommand()
140+
extra := ""
141+
if len(args) > 2 {
142+
extra = strings.Join(args[2:], " ")
143+
}
144+
return "", r.handleCompactCommand(extra)
141145
case "memory":
142146
// Generate or manage consolidated memory file
143147
if len(args) < 3 || args[2] == "generate" {

0 commit comments

Comments
 (0)