Skip to content

Get up and running with Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.

cmd: remove account step from CLI onboarding (#18826)

Eva H468e7e500842
diff --git a/cmd/cmd.go b/cmd/cmd.go
index f316a430d..9cd618613 100644
--- a/cmd/cmd.go
+++ b/cmd/cmd.go
@@ -2526,7 +2526,7 @@ func NewCLI() *cobra.Command {
return
}
- if err := runWelcome(cmd.Context()); err != nil {
+ if err := runWelcome(); err != nil {
if !errors.Is(err, launch.ErrCancelled) {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
}
diff --git a/cmd/tui/welcome.go b/cmd/tui/welcome.go
index b08e5447a..071133969 100644
--- a/cmd/tui/welcome.go
+++ b/cmd/tui/welcome.go
@@ -2,7 +2,6 @@ package tui
import (
"fmt"
- "net/url"
"strings"
"time"
@@ -10,43 +9,18 @@ import (
"github.com/charmbracelet/lipgloss"
)
-type WelcomeAccount struct {
- CloudDisabled bool
- SignedIn bool
- SigninURL string
- Err error
-}
-
type WelcomeOptions struct {
- CheckAccount func() WelcomeAccount
- OpenBrowser func(string)
- IsCompleted func() bool
+ IsCompleted func() bool
}
-type welcomeStep int
-
-const (
- welcomeIntro welcomeStep = iota
- welcomeAccount
- welcomeSignIn
-)
-
type welcomeModel struct {
options WelcomeOptions
- step welcomeStep
- checking bool
- account WelcomeAccount
- signIn signInModel
- cursor int
continued bool
cancelled bool
width int
}
-type (
- welcomeCompletedMsg bool
- welcomeAccountMsg WelcomeAccount
-)
+type welcomeCompletedMsg bool
func (m welcomeModel) Init() tea.Cmd {
if m.options.IsCompleted == nil {
@@ -57,19 +31,6 @@ func (m welcomeModel) Init() tea.Cmd {
})
}
-func (m welcomeModel) checkAccount() (tea.Model, tea.Cmd) {
- if m.checking {
- return m, nil
- }
- m.checking = true
- return m, func() tea.Msg {
- if m.options.CheckAccount == nil {
- return welcomeAccountMsg{Err: fmt.Errorf("account check unavailable")}
- }
- return welcomeAccountMsg(m.options.CheckAccount())
- }
-}
-
func (m welcomeModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if m.continued || m.cancelled {
return m, nil
@@ -81,81 +42,16 @@ func (m welcomeModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, tea.Quit
}
return m, m.Init()
- case welcomeAccountMsg:
- m.account, m.checking = WelcomeAccount(msg), false
- m.cursor = 0
- if m.account.SignedIn || m.account.CloudDisabled {
- m.continued = true
- return m, tea.Quit
- }
- m.step = welcomeAccount
case tea.WindowSizeMsg:
m.width = msg.Width
- m.signIn.width = msg.Width
case tea.KeyMsg:
- if msg.Type == tea.KeyCtrlC || (msg.Type == tea.KeyEsc && m.step != welcomeSignIn) {
- m.cancelled = true
- return m, tea.Quit
- }
- }
-
- if m.step == welcomeSignIn {
- updated, cmd := m.signIn.Update(msg)
- m.signIn = updated.(signInModel)
- if m.signIn.cancelled {
- m.step = welcomeAccount
- return m, nil // Esc returns to the account choices, not out of onboarding.
- }
- if m.signIn.userName != "" {
+ switch msg.Type {
+ case tea.KeyEnter:
m.continued = true
return m, tea.Quit
- }
- return m, cmd
- }
-
- if key, ok := msg.(tea.KeyMsg); ok {
- switch key.String() {
- case "up", "k":
- if m.step == welcomeAccount && !m.checking {
- m.cursor = max(0, m.cursor-1)
- }
- case "down", "j":
- if m.step == welcomeAccount && !m.checking {
- m.cursor = min(len(m.accountChoices())-1, m.cursor+1)
- }
- case "enter":
- if m.step == welcomeIntro {
- return m.checkAccount()
- }
- if m.checking {
- return m, nil
- }
- choices := m.accountChoices()
- if m.cursor == len(choices)-1 {
- m.continued = true
- return m, tea.Quit
- }
- if m.account.Err != nil || m.account.SigninURL == "" {
- return m.checkAccount()
- }
- signInURL := m.account.SigninURL
- u, err := url.Parse(signInURL)
- if err != nil || u.Host == "" || (u.Scheme != "https" && u.Scheme != "http") || m.options.OpenBrowser == nil {
- m.account.Err = fmt.Errorf("sign-in link unavailable")
- m.cursor = 0
- return m, nil
- }
- query := u.Query()
- query.Del("launch")
- query.Del("signup")
- u.RawQuery = query.Encode()
- signInURL = u.String()
- m.step = welcomeSignIn
- m.signIn = signInModel{modelName: "Ollama Cloud", signInURL: signInURL, width: m.width}
- return m, tea.Batch(
- func() tea.Msg { m.options.OpenBrowser(signInURL); return nil },
- m.signIn.Init(),
- )
+ case tea.KeyCtrlC, tea.KeyEsc:
+ m.cancelled = true
+ return m, tea.Quit
}
}
return m, nil
@@ -165,15 +61,11 @@ func (m welcomeModel) View() string {
if m.continued || m.cancelled {
return ""
}
- content := m.introView()
- if m.step == welcomeAccount || m.step == welcomeSignIn {
- content = m.accountView()
- }
style := lipgloss.NewStyle().Padding(1, 2)
if m.width > 0 {
style = style.Width(min(m.width, 80))
}
- return style.Render(content)
+ return style.Render(m.introView())
}
func (m welcomeModel) introView() string {
@@ -186,54 +78,11 @@ func (m welcomeModel) introView() string {
s.WriteString("\nSwap between frontier models in one click.\n\n")
s.WriteString(selectorTitleStyle.Render("Your data stays yours"))
s.WriteString("\nYour prompt data is never logged or trained on.\n\n")
- if m.checking {
- s.WriteString(selectorDescStyle.Render("Checking your account…"))
- } else {
- s.WriteString(selectorTitleStyle.Render("Press Enter to continue"))
- }
- return s.String()
-}
-
-func (m welcomeModel) accountChoices() []string {
- if m.account.Err != nil || m.account.SigninURL == "" {
- return []string{"Try again", "No thanks, I'll use Ollama locally"}
- }
- return []string{"Sign up / sign in", "No thanks, I'll use Ollama locally"}
-}
-
-func (m welcomeModel) accountView() string {
- var s strings.Builder
- s.WriteString(selectorTitleStyle.Render("Create an account"))
- s.WriteString("\n\nCreate your account for access to faster, larger open models.\n")
- s.WriteString("Your data is never logged or trained on.\n\n")
- if m.step == welcomeSignIn {
- s.WriteString(selectorDescStyle.Render("Finish in your browser…"))
- s.WriteString("\n\n" + m.signIn.signInURL)
- s.WriteString("\n\n" + selectorHelpStyle.Render("esc back"))
- return s.String()
- }
- if m.checking {
- s.WriteString("Checking your account…\n\n")
- s.WriteString(selectorHelpStyle.Render("esc quit"))
- return s.String()
- }
- if m.account.Err != nil || m.account.SigninURL == "" {
- s.WriteString("Unable to check your account. Please try again.\n\n")
- }
- for i, choice := range m.accountChoices() {
- if i == m.cursor {
- s.WriteString(menuSelectedItemStyle.Render("▸ " + choice))
- } else {
- s.WriteString(" " + choice)
- }
- s.WriteString("\n")
- }
- s.WriteString("\n\n" + selectorHelpStyle.Render("↑/↓ navigate • enter select • esc quit"))
+ s.WriteString(selectorTitleStyle.Render("Press Enter to continue"))
return s.String()
}
-// RunWelcome introduces Ollama, then offers account setup if needed. Returning
-// successfully leads to the regular launcher (or an explicitly requested app).
+// RunWelcome introduces Ollama. Returning successfully leads to the regular launcher.
func RunWelcome(options WelcomeOptions) error {
finalModel, err := tea.NewProgram(welcomeModel{options: options}).Run()
if err != nil {
diff --git a/cmd/tui/welcome_test.go b/cmd/tui/welcome_test.go
index 38e3fdce5..63160c560 100644
--- a/cmd/tui/welcome_test.go
+++ b/cmd/tui/welcome_test.go
@@ -1,8 +1,6 @@
package tui
import (
- "errors"
- "net/url"
"testing"
tea "github.com/charmbracelet/bubbletea"
@@ -14,111 +12,33 @@ func updateWelcome(m *welcomeModel, msg tea.Msg) tea.Cmd {
return cmd
}
-func TestWelcomeAccountRouting(t *testing.T) {
- for _, account := range []WelcomeAccount{
- {SignedIn: true},
- {CloudDisabled: true},
- {SigninURL: "https://ollama.com/connect?key=test"},
- {Err: errors.New("offline")},
- } {
- checks := 0
- m := welcomeModel{options: WelcomeOptions{
- CheckAccount: func() WelcomeAccount { checks++; return account },
- OpenBrowser: func(string) { t.Fatal("Continue must not open the browser") },
- }}
- check := updateWelcome(&m, tea.KeyMsg{Type: tea.KeyEnter})
- if check == nil || m.step != welcomeIntro || m.continued {
- t.Fatal("Continue must check the account before advancing")
- }
- if updateWelcome(&m, tea.KeyMsg{Type: tea.KeyEnter}) != nil {
- t.Fatal("repeated Enter started another check")
- }
- updateWelcome(&m, check())
- if checks != 1 || m.continued != (account.SignedIn || account.CloudDisabled) {
- t.Fatalf("incorrect account routing: %+v", m)
- }
- if !account.SignedIn && !account.CloudDisabled {
- if m.step != welcomeAccount {
- t.Fatal("signed-out users must reach account choices")
- }
- for range len(m.accountChoices()) - 1 {
- updateWelcome(&m, tea.KeyMsg{Type: tea.KeyDown})
- }
- updateWelcome(&m, tea.KeyMsg{Type: tea.KeyEnter})
- if !m.continued {
- t.Fatal("continuing without an account must finish onboarding, even offline")
- }
- }
- }
-}
-
-func TestWelcomeWaitsForSignIn(t *testing.T) {
- opened := ""
- m := welcomeModel{
- step: welcomeAccount, account: WelcomeAccount{SigninURL: "https://ollama.com/connect?key=test"},
- options: WelcomeOptions{OpenBrowser: func(raw string) { opened = raw }},
- }
- start := updateWelcome(&m, tea.KeyMsg{Type: tea.KeyEnter})
- start().(tea.BatchMsg)[0]() // Open the browser without starting real account polling.
- updateWelcome(&m, signInCheckMsg{})
- if opened != m.signIn.signInURL || opened == "" || m.step != welcomeSignIn || m.continued {
- t.Fatal("opening the browser alone must not complete onboarding")
- }
- updateWelcome(&m, signInCheckMsg{signedIn: true, userName: "test-user"})
- if !m.continued {
- t.Fatal("confirmed sign-in must complete onboarding")
- }
-}
-
-func TestWelcomeAccountDestination(t *testing.T) {
- opened := ""
- m := welcomeModel{
- step: welcomeAccount,
- account: WelcomeAccount{SigninURL: "https://ollama.com/connect?key=test&launch=claude&signup=true"},
- options: WelcomeOptions{OpenBrowser: func(raw string) { opened = raw }},
- }
- start := updateWelcome(&m, tea.KeyMsg{Type: tea.KeyEnter})
- start().(tea.BatchMsg)[0]()
- u, err := url.Parse(opened)
- if err != nil {
- t.Fatal(err)
+func TestWelcomeContinue(t *testing.T) {
+ m := welcomeModel{}
+ quit := updateWelcome(&m, tea.KeyMsg{Type: tea.KeyEnter})
+ if !m.continued || m.cancelled || quit == nil {
+ t.Fatal("Enter must complete welcome and continue to the launcher")
}
- if u.Path != "/connect" || u.Query().Has("signup") || u.Query().Has("launch") || u.Query().Get("key") != "test" {
- t.Fatalf("incorrect account destination: %s", opened)
+ if _, ok := quit().(tea.QuitMsg); !ok {
+ t.Fatal("completed welcome must exit the program")
}
}
func TestWelcomeCancellation(t *testing.T) {
- for _, step := range []welcomeStep{welcomeIntro, welcomeAccount, welcomeSignIn} {
- for _, key := range []tea.KeyType{tea.KeyEsc, tea.KeyCtrlC} {
- m := welcomeModel{step: step}
- quit := updateWelcome(&m, tea.KeyMsg{Type: key})
- back := step == welcomeSignIn && key == tea.KeyEsc
- if m.continued || m.cancelled == back || (quit == nil) != back || (back && m.step != welcomeAccount) {
- t.Fatalf("cancellation incorrectly completed onboarding: %+v", m)
- }
+ for _, key := range []tea.KeyType{tea.KeyEsc, tea.KeyCtrlC} {
+ m := welcomeModel{}
+ quit := updateWelcome(&m, tea.KeyMsg{Type: key})
+ if m.continued || !m.cancelled || quit == nil {
+ t.Fatalf("cancellation incorrectly completed onboarding: %+v", m)
}
}
}
-func TestWelcomeInvalidSignInLink(t *testing.T) {
- m := welcomeModel{
- step: welcomeAccount, account: WelcomeAccount{SigninURL: "file:///tmp/connect"},
- options: WelcomeOptions{OpenBrowser: func(string) { t.Fatal("invalid sign-in link opened") }},
- }
- if cmd := updateWelcome(&m, tea.KeyMsg{Type: tea.KeyEnter}); cmd != nil || m.account.Err == nil || m.continued {
- t.Fatal("invalid sign-in link must leave onboarding pending")
- }
-}
-
func TestWelcomeCompletedInApp(t *testing.T) {
- for _, step := range []welcomeStep{welcomeIntro, welcomeAccount, welcomeSignIn} {
- m := welcomeModel{step: step, options: WelcomeOptions{IsCompleted: func() bool { return true }}}
- if m.Init() == nil {
- t.Fatal("welcome must watch shared completion")
- }
- if quit := updateWelcome(&m, welcomeCompletedMsg(true)); !m.continued || quit == nil {
- t.Fatal("app completion must dismiss CLI onboarding")
- }
+ m := welcomeModel{options: WelcomeOptions{IsCompleted: func() bool { return true }}}
+ if m.Init() == nil {
+ t.Fatal("welcome must watch shared completion")
+ }
+ if quit := updateWelcome(&m, welcomeCompletedMsg(true)); !m.continued || quit == nil {
+ t.Fatal("app completion must dismiss CLI onboarding")
}
}
diff --git a/cmd/welcome.go b/cmd/welcome.go
index 4c015de38..4d7a8296b 100644
--- a/cmd/welcome.go
+++ b/cmd/welcome.go
@@ -1,30 +1,19 @@
package cmd
import (
- "context"
- "errors"
- "fmt"
- "net/http"
"os"
- "strings"
- "time"
- "github.com/ollama/ollama/api"
"github.com/ollama/ollama/cmd/config"
- "github.com/ollama/ollama/cmd/launch"
"github.com/ollama/ollama/cmd/tui"
- "github.com/spf13/cobra"
"golang.org/x/term"
)
-func runWelcome(ctx context.Context) error {
+func runWelcome() error {
if !term.IsTerminal(int(os.Stdin.Fd())) || !term.IsTerminal(int(os.Stdout.Fd())) {
return nil
}
return ensureWelcome(func() error {
return tui.RunWelcome(tui.WelcomeOptions{
- CheckAccount: func() tui.WelcomeAccount { return checkWelcomeAccount(ctx) },
- OpenBrowser: launch.OpenBrowser,
IsCompleted: func() bool {
needed, err := config.NeedsWelcome()
return err == nil && !needed
@@ -33,35 +22,6 @@ func runWelcome(ctx context.Context) error {
})
}
-func checkWelcomeAccount(ctx context.Context) tui.WelcomeAccount {
- ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
- defer cancel()
- cmd := &cobra.Command{}
- cmd.SetContext(ctx)
- if err := checkServerHeartbeat(cmd, nil); err != nil {
- return tui.WelcomeAccount{Err: err}
- }
- client, err := api.ClientFromEnvironment()
- if err != nil {
- return tui.WelcomeAccount{Err: err}
- }
- if status, err := client.CloudStatusExperimental(ctx); err == nil && status.Cloud.Disabled {
- return tui.WelcomeAccount{CloudDisabled: true}
- }
- user, err := client.Whoami(ctx)
- if err != nil {
- var authErr api.AuthorizationError
- if errors.As(err, &authErr) && authErr.StatusCode == http.StatusUnauthorized && authErr.SigninURL != "" {
- return tui.WelcomeAccount{SigninURL: authErr.SigninURL}
- }
- return tui.WelcomeAccount{Err: err}
- }
- if user != nil && strings.TrimSpace(user.Name) != "" {
- return tui.WelcomeAccount{SignedIn: true}
- }
- return tui.WelcomeAccount{Err: fmt.Errorf("could not verify the Ollama account")}
-}
-
func ensureWelcome(show func() error) error {
needed, err := config.NeedsWelcome()
if err != nil {
diff --git a/cmd/welcome_test.go b/cmd/welcome_test.go
index 641d58526..540db6343 100644
--- a/cmd/welcome_test.go
+++ b/cmd/welcome_test.go
@@ -1,56 +1,13 @@
package cmd
import (
- "context"
"errors"
- "fmt"
- "net/http"
- "net/http/httptest"
"testing"
"github.com/ollama/ollama/cmd/config"
"github.com/ollama/ollama/cmd/launch"
)
-func TestWelcomeCloudStatus(t *testing.T) {
- for _, status := range []string{`{"cloud":{"disabled":true}}`, `{"cloud":{"disabled":false}}`, "unavailable"} {
- t.Run(status, func(t *testing.T) {
- accountRequests := 0
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- switch r.URL.Path {
- case "/":
- case "/api/status":
- if status == "unavailable" {
- w.WriteHeader(http.StatusNotFound)
- return
- }
- fmt.Fprint(w, status)
- case "/api/me":
- accountRequests++
- fmt.Fprint(w, `{"name":"test-user"}`)
- default:
- t.Errorf("unexpected request: %s", r.URL.Path)
- w.WriteHeader(http.StatusNotFound)
- }
- }))
- defer server.Close()
- t.Setenv("OLLAMA_HOST", server.URL)
- account := checkWelcomeAccount(context.Background())
- disabled := status == `{"cloud":{"disabled":true}}`
- if account.Err != nil || account.CloudDisabled != disabled || account.SignedIn == disabled {
- t.Fatalf("unexpected account state: %+v", account)
- }
- wantRequests := 1
- if disabled {
- wantRequests = 0
- }
- if accountRequests != wantRequests {
- t.Fatalf("account requests = %d, want %d", accountRequests, wantRequests)
- }
- })
- }
-}
-
func TestWelcomeOnceAfterCompletion(t *testing.T) {
setCmdTestHome(t, t.TempDir())
t.Setenv("LOCALAPPDATA", t.TempDir())