diff --git a/packages/tui/internal/app/prompt.go b/packages/tui/internal/app/prompt.go index 81c4b6a7d047..23142933e3d2 100644 --- a/packages/tui/internal/app/prompt.go +++ b/packages/tui/internal/app/prompt.go @@ -9,9 +9,31 @@ import ( "github.com/sst/opencode/internal/id" ) +const ( + PromptTypeChat = "chat" + PromptTypeShell = "shell" +) + type Prompt struct { Text string `toml:"text"` Attachments []*attachment.Attachment `toml:"attachments"` + Type string `toml:"type"` +} + +func NewChatPrompt(text string, attachments []*attachment.Attachment) Prompt { + return Prompt{Text: text, Attachments: attachments, Type: PromptTypeChat} +} + +func NewShellPrompt(command string) Prompt { + return Prompt{Text: command, Type: PromptTypeShell} +} + +func (p Prompt) IsShell() bool { + return p.Type == PromptTypeShell +} + +func (p Prompt) IsChat() bool { + return p.Type == PromptTypeChat } func (p Prompt) ToMessage( diff --git a/packages/tui/internal/components/chat/editor.go b/packages/tui/internal/components/chat/editor.go index 38a57905796f..1c485ca04c53 100644 --- a/packages/tui/internal/components/chat/editor.go +++ b/packages/tui/internal/components/chat/editor.go @@ -482,7 +482,7 @@ func (m *editorComponent) Submit() (tea.Model, tea.Cmd) { var cmds []tea.Cmd attachments := m.textarea.GetAttachments() - prompt := app.Prompt{Text: value, Attachments: attachments} + prompt := app.NewChatPrompt(value, attachments) m.app.State.AddPromptToHistory(prompt) cmds = append(cmds, m.app.SaveState()) @@ -497,6 +497,11 @@ func (m *editorComponent) Submit() (tea.Model, tea.Cmd) { func (m *editorComponent) SubmitBash() (tea.Model, tea.Cmd) { command := m.textarea.Value() var cmds []tea.Cmd + + prompt := app.NewShellPrompt(command) + m.app.State.AddPromptToHistory(prompt) + cmds = append(cmds, m.app.SaveState()) + updated, cmd := m.Clear() m = updated.(*editorComponent) cmds = append(cmds, cmd) @@ -733,6 +738,8 @@ func (m *editorComponent) RestoreFromPrompt(prompt app.Prompt) { m.textarea.Reset() m.textarea.SetValue(prompt.Text) + m.app.IsBashMode = prompt.IsShell() + // Sort attachments by start index in reverse order (process from end to beginning) // This prevents index shifting issues attachmentsCopy := make([]*attachment.Attachment, len(prompt.Attachments))