Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/tui/internal/app/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
9 changes: 8 additions & 1 deletion packages/tui/internal/components/chat/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand All @@ -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)
Expand Down Expand Up @@ -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))
Expand Down
Loading