compaction improvements

This commit is contained in:
Dax Raad
2025-09-11 02:22:14 -04:00
parent c3a55c35bb
commit 4c94753eda
17 changed files with 406 additions and 145 deletions

View File

@@ -653,6 +653,9 @@ func getDefaultModel(
}
func (a *App) IsBusy() bool {
if a.Session.Time.Compacting > 0 {
return true
}
if len(a.Messages) == 0 {
return false
}

View File

@@ -385,6 +385,9 @@ func (m *editorComponent) Content() string {
} else if m.app.IsBusy() {
keyText := m.getInterruptKeyText()
status := "working"
if m.app.Session.Time.Compacting > 0 {
status = "compacting"
}
if m.app.CurrentPermission.ID != "" {
status = "waiting for permission"
}

View File

@@ -365,6 +365,9 @@ func (m *messagesComponent) renderView() tea.Cmd {
lastAssistantMessage := "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
for _, msg := range slices.Backward(m.app.Messages) {
if assistant, ok := msg.Info.(opencode.AssistantMessage); ok {
if assistant.Time.Completed > 0 {
break
}
lastAssistantMessage = assistant.ID
break
}
@@ -475,6 +478,9 @@ func (m *messagesComponent) renderView() tea.Cmd {
}
case opencode.AssistantMessage:
if casted.Summary {
continue
}
if casted.ID == m.app.Session.Revert.MessageID {
reverted = true
revertedMessageCount = 1

View File

@@ -592,10 +592,40 @@ func (a Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
if matchIndex == -1 {
a.app.Messages = append(a.app.Messages, app.Message{
// Extract the new message ID
var newMessageID string
switch casted := msg.Properties.Info.AsUnion().(type) {
case opencode.UserMessage:
newMessageID = casted.ID
case opencode.AssistantMessage:
newMessageID = casted.ID
}
// Find the correct insertion index by scanning backwards
// Most messages are added to the end, so start from the end
insertIndex := len(a.app.Messages)
for i := len(a.app.Messages) - 1; i >= 0; i-- {
var existingID string
switch casted := a.app.Messages[i].Info.(type) {
case opencode.UserMessage:
existingID = casted.ID
case opencode.AssistantMessage:
existingID = casted.ID
}
if existingID < newMessageID {
insertIndex = i + 1
break
}
}
// Create the new message
newMessage := app.Message{
Info: msg.Properties.Info.AsUnion(),
Parts: []opencode.PartUnion{},
})
}
// Insert at the correct position
a.app.Messages = append(a.app.Messages[:insertIndex], append([]app.Message{newMessage}, a.app.Messages[insertIndex:]...)...)
}
}
case opencode.EventListResponseEventPermissionUpdated:
@@ -627,6 +657,10 @@ func (a Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
slog.Error("Server error", "name", err.Name, "message", err.Data.Message)
return a, toast.NewErrorToast(err.Data.Message, toast.WithTitle(string(err.Name)))
}
case opencode.EventListResponseEventSessionCompacted:
if msg.Properties.SessionID == a.app.Session.ID {
return a, toast.NewSuccessToast("Session compacted successfully")
}
case tea.WindowSizeMsg:
msg.Height -= 2 // Make space for the status bar
a.width, a.height = msg.Width, msg.Height