Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.
Merged
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
8 changes: 6 additions & 2 deletions cmd/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,21 @@ Examples:
os.Exit(1)
}

authURL := fmt.Sprintf("%s/auth/cli", appUrl)

body := tui.Paragraph(
"Copy the following code:",
tui.Bold(otp),
"Then open the url in your browser and paste the code:",
tui.Link("%s/auth/cli", appUrl),
"Then open the url in your browser (or just press ENTER) and paste the code:",
tui.Link("%s", authURL),
tui.Muted("This code will expire in 60 seconds"),
)

tui.ShowBanner("Login to Agentuity", body, false)

tui.ShowSpinner("Waiting for login to complete...", func() {
go util.PromptBrowserOpen(logger, authURL)

authResult, err := auth.PollForLoginCompletion(ctx, logger, apiUrl, otp)
if err != nil {
if isCancelled(ctx) {
Expand Down
42 changes: 41 additions & 1 deletion internal/util/browser.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package util

import (
"bufio"
"context"
"errors"
"fmt"
Expand Down Expand Up @@ -164,7 +165,7 @@ func BrowserFlow(opts BrowserFlowOptions) error {
}
if !skip {
if berr := browser.OpenURL(u.String()); berr != nil {
returnErr = fmt.Errorf("failed to open browser: %s", err)
returnErr = fmt.Errorf("failed to open browser: %w", berr)
return
}
}
Expand All @@ -189,3 +190,42 @@ func BrowserFlow(opts BrowserFlowOptions) error {

return returnErr
}

// PromptBrowserOpen prompts the user to press Enter to open a browser to the given URL.
// It handles display detection on Linux and provides appropriate user feedback.
func PromptBrowserOpen(logger interface{ Error(string, ...interface{}) }, url string) {
var skipOpen bool
if runtime.GOOS == "linux" {
// if we don't have a display, we can't open a browser most likely
if _, ok := os.LookupEnv("DISPLAY"); !ok {
skipOpen = true
}
}

fmt.Println()
if skipOpen {
fmt.Print(tui.Secondary("Press Enter to continue, or Ctrl+C to skip: "))
} else {
fmt.Print(tui.Secondary("Press Enter to open browser, or Ctrl+C to skip: "))
}

reader := bufio.NewReader(os.Stdin)
reader.ReadLine()

if !skipOpen {
if err := browser.OpenURL(url); err != nil {
logger.Error("Failed to open browser: %v", err)
} else {
// Clear previous line and move cursor up to remove the "Press Enter..." prompt
fmt.Print("\r\033[K\033[A\r\033[K")
tui.ShowSuccess("Browser opened!")
fmt.Println()
}
} else {
// Clear the prompt and show the URL for manual opening (and the loading spinner)
fmt.Print("\r\033[K")
fmt.Println(tui.Muted("Please visit the URL manually:"))
fmt.Println(tui.Link("%s", url))
fmt.Println()
}
}
Loading