@@ -195,12 +195,6 @@ func (p *chatPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
195195 return p , cmd
196196
197197 case editor.SendMsg :
198- // Persist every submitted command before handing it to the runtime.
199- if p .history != nil {
200- if err := p .history .Add (msg .Content ); err != nil {
201- fmt .Fprintf (os .Stderr , "failed to persist command history: %v\n " , err )
202- }
203- }
204198 cmd := p .processMessage (msg .Content )
205199 return p , cmd
206200
@@ -498,23 +492,33 @@ func (p *chatPage) processMessage(content string) tea.Cmd {
498492 var ctx context.Context
499493 ctx , p .msgCancel = context .WithCancel (context .Background ())
500494
501- switch {
502- case strings .HasPrefix (content , "!" ):
495+ if strings .HasPrefix (content , "!" ) {
503496 p .app .RunBangCommand (ctx , content [1 :])
504- case strings .HasPrefix (content , "/" ):
497+ return p .messages .ScrollToBottom ()
498+ }
499+
500+ // Handle /commands
501+ if strings .HasPrefix (content , "/" ) {
505502 // Try builtin session command first
506503 for _ , sessionCommand := range p .sessionCommands {
507504 if sessionCommand .SlashCommand == content && sessionCommand .Execute != nil {
508505 return sessionCommand .Execute ()
509506 }
510507 }
511508
512- // Then user-defined commands
513- p .app .Run (ctx , p .msgCancel , p .app .ResolveCommand (ctx , content ))
514- default :
515- p .app .Run (ctx , p .msgCancel , content )
509+ // Then try app-level commands
510+ content = p .app .ResolveCommand (ctx , content )
516511 }
517512
513+ // Persist to history
514+ if p .history != nil {
515+ if err := p .history .Add (content ); err != nil {
516+ fmt .Fprintf (os .Stderr , "failed to persist command history: %v\n " , err )
517+ }
518+ }
519+
520+ p .app .Run (ctx , p .msgCancel , content )
521+
518522 return p .messages .ScrollToBottom ()
519523}
520524
0 commit comments