diff options
| author | Dax <[email protected]> | 2025-08-22 17:04:28 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-08-22 17:04:28 -0400 |
| commit | 133fe41cd5fb0ec3dc03a90e58526408297878fd (patch) | |
| tree | 82aac357a61fe9e7a6802974f6c7cf169a9f22a8 /packages/tui/internal/app | |
| parent | 74c1085103e130cb07522e3ad725f17eca3e5832 (diff) | |
| download | opencode-133fe41cd5fb0ec3dc03a90e58526408297878fd.tar.gz opencode-133fe41cd5fb0ec3dc03a90e58526408297878fd.zip | |
slash commands (#2157)
Co-authored-by: adamdotdevin <[email protected]>
Diffstat (limited to 'packages/tui/internal/app')
| -rw-r--r-- | packages/tui/internal/app/app.go | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/packages/tui/internal/app/app.go b/packages/tui/internal/app/app.go index 0c703c959..ecf95ff98 100644 --- a/packages/tui/internal/app/app.go +++ b/packages/tui/internal/app/app.go @@ -84,6 +84,10 @@ type SendPrompt = Prompt type SendShell = struct { Command string } +type SendCommand = struct { + Command string + Args string +} type SetEditorContentMsg struct { Text string } @@ -183,6 +187,11 @@ func New( slog.Debug("Loaded config", "config", configInfo) + customCommands, err := httpClient.Command.List(ctx) + if err != nil { + return nil, err + } + app := &App{ Info: appInfo, Agents: agents, @@ -194,7 +203,7 @@ func New( AgentIndex: agentIndex, Session: &opencode.Session{}, Messages: []Message{}, - Commands: commands.LoadFromConfig(configInfo), + Commands: commands.LoadFromConfig(configInfo, *customCommands), InitialModel: initialModel, InitialPrompt: initialPrompt, InitialAgent: initialAgent, @@ -793,6 +802,38 @@ func (a *App) SendPrompt(ctx context.Context, prompt Prompt) (*App, tea.Cmd) { return a, tea.Batch(cmds...) } +func (a *App) SendCommand(ctx context.Context, command string, args string) (*App, tea.Cmd) { + var cmds []tea.Cmd + if a.Session.ID == "" { + session, err := a.CreateSession(ctx) + if err != nil { + return a, toast.NewErrorToast(err.Error()) + } + a.Session = session + cmds = append(cmds, util.CmdHandler(SessionCreatedMsg{Session: session})) + } + + cmds = append(cmds, func() tea.Msg { + _, err := a.Client.Session.Command( + context.Background(), + a.Session.ID, + opencode.SessionCommandParams{ + Command: opencode.F(command), + Arguments: opencode.F(args), + }, + ) + if err != nil { + slog.Error("Failed to execute command", "error", err) + return toast.NewErrorToast("Failed to execute command") + } + return nil + }) + + // The actual response will come through SSE + // For now, just return success + return a, tea.Batch(cmds...) +} + func (a *App) SendShell(ctx context.Context, command string) (*App, tea.Cmd) { var cmds []tea.Cmd if a.Session.ID == "" { |
