on main help sign in
Merge branch 'main' into ui
commit3b018543dbc6bab682e599b755f209d043cb49a7 authorAyman Bagabas <ayman.bagabas@gmail.com> dateTue 16 Dec 2025, 13:59 (1 year ago) parent7b191427fd14ff
3 files changed+29−13
internal/agent/coordinator.go+7 internal/tui/util/shell.go+2−13 internal/uiutil/uiutil.go+20
internal/agent/coordinator.go+7
@@ -132,6 +132,13 @@ func (c *coordinator) Run(ctx context.Context, sessionID string, prompt string,
132132
133133 mergedOptions, temp, topP, topK, freqPenalty, presPenalty := mergeCallOptions(model, providerCfg)
134134
135+ if providerCfg.OAuthToken != nil && providerCfg.OAuthToken.IsExpired() {
136+ slog.Info("Token needs to be refreshed", "provider", providerCfg.ID)
137+ if err := c.refreshOAuth2Token(ctx, providerCfg); err != nil {
138+ return nil, err
139+ }
140+ }
141+
135142 run := func() (*fantasy.AgentResult, error) {
136143 return c.currentAgent.Run(ctx, SessionAgentCall{
137144 SessionID: sessionID,
internal/tui/util/shell.go+2−13
@@ -2,25 +2,14 @@ package util
22
33import (
44 "context"
5− "errors"
6− "os/exec"
75
86 tea "charm.land/bubbletea/v2"
9− "mvdan.cc/sh/v3/shell"
7+ "github.com/charmbracelet/crush/internal/uiutil"
108)
119
1210// ExecShell parses a shell command string and executes it with exec.Command.
1311// Uses shell.Fields for proper handling of shell syntax like quotes and
1412// arguments while preserving TTY handling for terminal editors.
1513func ExecShell(ctx context.Context, cmdStr string, callback tea.ExecCallback) tea.Cmd {
16− fields, err := shell.Fields(cmdStr, nil)
17− if err != nil {
18− return ReportError(err)
19− }
20− if len(fields) == 0 {
21− return ReportError(errors.New("empty command"))
22− }
23−
24− cmd := exec.CommandContext(ctx, fields[0], fields[1:]...)
25− return tea.ExecProcess(cmd, callback)
14+ return uiutil.ExecShell(ctx, cmdStr, callback)
2615}
internal/uiutil/uiutil.go+20
@@ -4,10 +4,14 @@
44package uiutil
55
66import (
7+ "context"
8+ "errors"
79 "log/slog"
10+ "os/exec"
811 "time"
912
1013 tea "charm.land/bubbletea/v2"
14+ "mvdan.cc/sh/v3/shell"
1115)
1216
1317type Cursor interface {
@@ -60,3 +64,19 @@ type (
6064 }
6165 ClearStatusMsg struct{}
6266)
67+
68+// ExecShell parses a shell command string and executes it with exec.Command.
69+// Uses shell.Fields for proper handling of shell syntax like quotes and
70+// arguments while preserving TTY handling for terminal editors.
71+func ExecShell(ctx context.Context, cmdStr string, callback tea.ExecCallback) tea.Cmd {
72+ fields, err := shell.Fields(cmdStr, nil)
73+ if err != nil {
74+ return ReportError(err)
75+ }
76+ if len(fields) == 0 {
77+ return ReportError(errors.New("empty command"))
78+ }
79+
80+ cmd := exec.CommandContext(ctx, fields[0], fields[1:]...)
81+ return tea.ExecProcess(cmd, callback)
82+}