Skip to content

Commit fa38d86

Browse files
authored
Merge pull request #386 from rumpl/feat-command-palette
Add a command palette to the TUI
2 parents cbceb12 + 9c7e1f6 commit fa38d86

6 files changed

Lines changed: 549 additions & 52 deletions

File tree

pkg/app/app.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type App struct {
2222
firstMessage *string
2323
events chan tea.Msg
2424
throttleDuration time.Duration
25+
cancel context.CancelFunc
2526
}
2627

2728
func New(title, agentFilename string, rt runtime.Runtime, agents *team.Team, sess *session.Session, firstMessage *string) *App {
@@ -50,7 +51,8 @@ func (a *App) Title() string {
5051
}
5152

5253
// Run one agent loop
53-
func (a *App) Run(ctx context.Context, message string) {
54+
func (a *App) Run(ctx context.Context, cancel context.CancelFunc, message string) {
55+
a.cancel = cancel
5456
go func() {
5557
// Special shell command
5658
if strings.HasPrefix(message, "!") {
@@ -62,6 +64,9 @@ func (a *App) Run(ctx context.Context, message string) {
6264
// User message
6365
a.session.AddMessage(session.UserMessage(a.agentFilename, message))
6466
for event := range a.runtime.RunStream(ctx, a.session) {
67+
if ctx.Err() != nil {
68+
return
69+
}
6570
a.events <- event
6671
}
6772
}()
@@ -89,6 +94,24 @@ func (a *App) Resume(confirmationType string) {
8994
}
9095
}
9196

97+
func (a *App) NewSession() {
98+
if a.cancel != nil {
99+
a.cancel()
100+
a.cancel = nil
101+
}
102+
a.session = session.New()
103+
}
104+
105+
func (a *App) CompactSession() {
106+
if a.runtime != nil && a.session != nil {
107+
events := make(chan runtime.Event, 100)
108+
a.runtime.Summarize(context.Background(), a.session, events)
109+
for event := range events {
110+
a.events <- event
111+
}
112+
}
113+
}
114+
92115
// ResumeStartOAuth resumes the runtime with OAuth authorization confirmation
93116
func (a *App) ResumeStartOAuth(confirmation bool) {
94117
if a.runtime != nil {

pkg/tui/components/messages/messages.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ type Model interface {
3535
AddOrUpdateToolCall(agentName string, toolCall tools.ToolCall, toolDef tools.Tool, status types.ToolStatus) tea.Cmd
3636
AddToolResult(msg *runtime.ToolCallResponseEvent, status types.ToolStatus) tea.Cmd
3737
AppendToLastMessage(agentName string, messageType types.MessageType, content string) tea.Cmd
38-
ClearMessages()
3938
ScrollToBottom() tea.Cmd
4039
AddShellOutputMessage(content string) tea.Cmd
4140
AddSystemMessage(content string) tea.Cmd
@@ -73,7 +72,7 @@ type model struct {
7372
// New creates a new message list component
7473
func New(a *app.App) Model {
7574
return &model{
76-
width: 80,
75+
width: 120,
7776
height: 24,
7877
app: a,
7978
renderedItems: make(map[int]renderedItem),
@@ -603,16 +602,6 @@ func (m *model) AppendToLastMessage(agentName string, messageType types.MessageT
603602
}
604603
}
605604

606-
// ClearMessages clears all messages
607-
func (m *model) ClearMessages() {
608-
m.messages = nil
609-
m.views = nil
610-
m.scrollOffset = 0
611-
m.rendered = ""
612-
m.totalHeight = 0
613-
m.renderedItems = make(map[int]renderedItem)
614-
}
615-
616605
// ScrollToBottom scrolls to the bottom of the chat
617606
func (m *model) ScrollToBottom() tea.Cmd {
618607
return func() tea.Msg {

0 commit comments

Comments
 (0)