diff options
| author | adamdottv <[email protected]> | 2025-05-02 09:24:24 -0500 |
|---|---|---|
| committer | Adam <[email protected]> | 2025-05-02 15:24:47 -0500 |
| commit | 49423da081d6fdffb0bd7275e070a2edeb28e3b5 (patch) | |
| tree | 3119b731ecd46ff8ef3c26d779c0420c7dfe6c9e /internal/tui | |
| parent | 364cf5b429c3dd6952d45c3361765aa3898e6326 (diff) | |
| download | opencode-49423da081d6fdffb0bd7275e070a2edeb28e3b5.tar.gz opencode-49423da081d6fdffb0bd7275e070a2edeb28e3b5.zip | |
feat: compact command with auto-compact
Diffstat (limited to 'internal/tui')
| -rw-r--r-- | internal/tui/components/chat/chat.go | 2 | ||||
| -rw-r--r-- | internal/tui/components/chat/list.go | 8 | ||||
| -rw-r--r-- | internal/tui/page/chat.go | 18 | ||||
| -rw-r--r-- | internal/tui/tui.go | 18 |
4 files changed, 44 insertions, 2 deletions
diff --git a/internal/tui/components/chat/chat.go b/internal/tui/components/chat/chat.go index d6eaecec9..52c9a4f71 100644 --- a/internal/tui/components/chat/chat.go +++ b/internal/tui/components/chat/chat.go @@ -23,6 +23,8 @@ type SessionClearedMsg struct{} type EditorFocusMsg bool +type CompactSessionMsg struct{} + func header(width int) string { return lipgloss.JoinVertical( lipgloss.Top, diff --git a/internal/tui/components/chat/list.go b/internal/tui/components/chat/list.go index 1dfc3ab20..2bddb19da 100644 --- a/internal/tui/components/chat/list.go +++ b/internal/tui/components/chat/list.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "math" + "time" "github.com/charmbracelet/bubbles/key" "github.com/charmbracelet/bubbles/spinner" @@ -450,8 +451,11 @@ func (m *messagesCmp) BindingKeys() []key.Binding { } func NewMessagesCmp(app *app.App) tea.Model { - s := spinner.New() - s.Spinner = spinner.Pulse + customSpinner := spinner.Spinner{ + Frames: []string{" ", "┃"}, + FPS: time.Second / 2, //nolint:gomnd + } + s := spinner.New(spinner.WithSpinner(customSpinner)) vp := viewport.New(0, 0) vp.KeyMap.PageUp = messageKeys.PageUp vp.KeyMap.PageDown = messageKeys.PageDown diff --git a/internal/tui/page/chat.go b/internal/tui/page/chat.go index 62a5b9f4f..024974e5c 100644 --- a/internal/tui/page/chat.go +++ b/internal/tui/page/chat.go @@ -2,10 +2,12 @@ package page import ( "context" + "fmt" "github.com/charmbracelet/bubbles/key" tea "github.com/charmbracelet/bubbletea" "github.com/opencode-ai/opencode/internal/app" + "github.com/opencode-ai/opencode/internal/logging" "github.com/opencode-ai/opencode/internal/session" "github.com/opencode-ai/opencode/internal/tui/components/chat" "github.com/opencode-ai/opencode/internal/tui/layout" @@ -64,6 +66,22 @@ func (p *chatPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } } p.session = msg + case chat.CompactSessionMsg: + if p.session.ID == "" { + return p, util.ReportWarn("No active session to compact.") + } + + // Run compaction in background + go func(sessionID string) { + err := p.app.CoderAgent.CompactSession(context.Background(), sessionID) + if err != nil { + logging.ErrorPersist(fmt.Sprintf("Compaction failed: %v", err)) + } else { + logging.InfoPersist("Conversation compacted successfully.") + } + }(p.session.ID) + + return p, nil case tea.KeyMsg: switch { case key.Matches(msg, keyMap.NewSession): diff --git a/internal/tui/tui.go b/internal/tui/tui.go index 0db21f380..278252ab9 100644 --- a/internal/tui/tui.go +++ b/internal/tui/tui.go @@ -723,5 +723,23 @@ If there are Cursor rules (in .cursor/rules/ or .cursorrules) or Copilot rules ( ) }, }) + + model.RegisterCommand(dialog.Command{ + ID: "compact_conversation", + Title: "Compact Conversation", + Description: "Summarize the current session to save tokens", + Handler: func(cmd dialog.Command) tea.Cmd { + // Get the current session from the appModel + if model.currentPage != page.ChatPage { + return util.ReportWarn("Please navigate to a chat session first.") + } + + // Return a message that will be handled by the chat page + return tea.Batch( + util.CmdHandler(chat.CompactSessionMsg{}), + util.ReportInfo("Compacting conversation...")) + }, + }) + return model } |
