The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
Sign in without tearing down the setup screen
shukieshah1e5becdff6a5
diff --git a/cli/beacon/cmd/endpoint.go b/cli/beacon/cmd/endpoint.goindex 350075a0..b0ba7d95 100644--- a/cli/beacon/cmd/endpoint.go+++ b/cli/beacon/cmd/endpoint.go@@ -38,6 +38,7 @@ var endpointOpts struct {onboardingReset boolonboardingResend boolconnect bool+ noBrowser boolfix boolallTargets boolcoworkHeaders string@@ -421,6 +422,7 @@ func init() {endpointInstallCmd.Flags().BoolVar(&endpointOpts.includeRuntimeMetrics, "include-runtime-metrics", false, "Include generic process/runtime OTLP metrics and harness operational metrics (OpenClaw, Copilot CLI) in the runtime JSONL log")endpointInstallCmd.Flags().BoolVar(&endpointOpts.includeCodexSpans, "include-codex-spans", false, "Include high-volume Codex OTLP spans for troubleshooting")endpointInstallCmd.Flags().BoolVar(&endpointOpts.noStart, "no-start", false, "Write files without starting the collector service")+ endpointInstallCmd.Flags().BoolVar(&endpointOpts.noBrowser, "no-browser", false, "During interactive setup, print the sign-in URL instead of opening a browser")endpointInstallCmd.Flags().StringVar(&endpointOpts.serviceKind, "service", "", "Service manager to use: auto (default), launchd, systemd, or none for a supervised collector process")endpointInstallCmd.Flags().BoolVar(&endpointOpts.dryRun, "dry-run", false, "Print planned actions without changing endpoint files or services")endpointInstallCmd.Flags().BoolVar(&endpointOpts.connect, "connect", false, "After installing, attempt to connect this endpoint to Beacon Managed (user mode uses the signed-in account; system mode opens browser approval)")diff --git a/cli/beacon/cmd/endpoint_onboarding.go b/cli/beacon/cmd/endpoint_onboarding.goindex 42d906ac..db90098d 100644--- a/cli/beacon/cmd/endpoint_onboarding.go+++ b/cli/beacon/cmd/endpoint_onboarding.go@@ -161,6 +161,35 @@ func runAccountOnboarding(cmd *cobra.Command, profile *onboarding.Profile, destiDestinationOnly: destinationOnly,PresetDestination: preset,PresetPrivacyMode: profile.Onboarding.PrivacyMode,+ NoBrowser: endpointOpts.noBrowser,+ Now: onboardingClock,+ SignInTimeout: account.LoginWait,+ // Signing in happens inside the wizard so the full-screen UI is never torn+ // down around it. The wizard itself stays free of network code: this is the+ // only place onboarding reaches beacon.sh, and it hands back an email, never+ // a token.+ SignIn: func(ctx context.Context, req onboarding.SignInRequest, reporter onboarding.Reporter) (onboarding.Account, error) {+ session, err := onboardingAccountLogin(ctx, account.LoginOptions{+ Version: version.GetVersion(),+ NoBrowser: req.NoBrowser,+ Timeout: account.LoginWait,+ Now: onboardingClock,+ OnPrompt: func(prompt account.LoginPrompt) {+ reporter.Prompt(onboarding.SignInPrompt{+ URL: prompt.URL,+ WillOpen: prompt.WillOpen,+ BrowserErr: prompt.BrowserErr,+ })+ },+ })+ if err != nil {+ return onboarding.Account{}, err+ }+ if err := onboardingAccountSave(*session); err != nil {+ return onboarding.Account{}, fmt.Errorf("store Beacon session: %w", err)+ }+ return onboarding.Account{Email: session.User.Email}, nil+ },}result, err := onboardingRunWizard(onboardingStdin, cmd.OutOrStdout(), options)if err != nil {@@ -190,6 +219,9 @@ func runAccountOnboarding(cmd *cobra.Command, profile *onboarding.Profile, destiif !result.Completed {return onboardingOutcome{}, onboarding.ErrWizardCancelled}+ if result.SignedInEmail != "" {+ status = account.Status{SignedIn: true, User: account.User{Email: result.SignedInEmail}}+ }privacyMode := ""if result.Destination == onboarding.DestinationAsymptote {diff --git a/cli/beacon/internal/account/login.go b/cli/beacon/internal/account/login.goindex e49ebf4b..366cee97 100644--- a/cli/beacon/internal/account/login.go+++ b/cli/beacon/internal/account/login.go@@ -19,14 +19,16 @@ import ()const (- DefaultBaseURL = "https://beacon.sh"- BaseURLEnv = "BEACON_AUTH_URL"- LoginPagePath = "/cli/auth"- LoginInitPath = "/api/cli/auth/init"- ExchangePath = "/api/cli/auth/exchange"- RevokePath = "/api/cli/auth/revoke"- defaultTimeout = 30 * time.Second- loginWait = 5 * time.Minute+ DefaultBaseURL = "https://beacon.sh"+ BaseURLEnv = "BEACON_AUTH_URL"+ LoginPagePath = "/cli/auth"+ LoginInitPath = "/api/cli/auth/init"+ ExchangePath = "/api/cli/auth/exchange"+ RevokePath = "/api/cli/auth/revoke"+ defaultTimeout = 30 * time.Second+ // LoginWait bounds how long Login waits for the browser. Exported so a caller+ // rendering its own waiting state can show the same deadline.+ LoginWait = 5 * time.MinuteCLIClientName = "beacon-cli"CLIGrantVersion = "2026-09-01"ScopeProfileRead = "profile:read"@@ -42,6 +44,31 @@ type LoginOptions struct {Out io.WriterTimeout time.DurationNow func() time.Time+ // OnPrompt receives the sign-in URL once the callback server is listening and+ // the session is registered, and again if opening a browser then failed.+ //+ // When it is set, Login writes nothing to Out: a caller rendering its own UI+ // owns the screen, and stray writes would corrupt an alternate-screen frame.+ OnPrompt func(LoginPrompt)+}++// LoginPrompt is everything a user needs in order to finish signing in.+//+// It is reported before the browser is opened rather than after, so the URL is on+// screen even when the open fails or the terminal cannot open one at all. The+// callback server is already listening by then, so waiting never depends on the+// user having acknowledged anything -- the failure mode where a CLI only starts+// listening after a keypress is what this ordering avoids.+type LoginPrompt struct {+ // URL is the sign-in page, carrying the loopback port this process listens on.+ URL string+ // WillOpen is true when Login is about to try opening a browser itself.+ WillOpen bool+ // BrowserErr is set on the second call when that attempt failed; the URL is then+ // the only way through.+ BrowserErr error+ // Timeout is how long Login will wait before giving up.+ Timeout time.Duration}type clientInfo struct {@@ -96,7 +123,7 @@ func Login(ctx context.Context, opts LoginOptions) (*Session, error) {}timeout := opts.Timeoutif timeout == 0 {- timeout = loginWait+ timeout = LoginWait}now := opts.Nowif now == nil {@@ -150,18 +177,26 @@ func Login(ctx context.Context, opts LoginOptions) (*Session, error) {}loginURL := buildLoginURL(baseURL, pkce.State, callback.Port())+ report := opts.OnPrompt+ if report != nil {+ out = io.Discard+ } else {+ report = func(LoginPrompt) {}+ }+ report(LoginPrompt{URL: loginURL, WillOpen: !opts.NoBrowser, Timeout: timeout})if opts.NoBrowser {fmt.Fprintf(out, "Open this URL to sign in to Beacon:\n%s\n", loginURL)} else {fmt.Fprintf(out, "Opening %s in your browser...\n", baseURL)if err := openBrowser(loginURL); err != nil {+ report(LoginPrompt{URL: loginURL, BrowserErr: err, Timeout: timeout})fmt.Fprintln(out, "Could not open a browser automatically.")fmt.Fprintf(out, "Open this URL to sign in to Beacon:\n%s\n", loginURL)}}fmt.Fprintln(out, "Waiting for Beacon sign-in...")- result, err := callback.Wait(timeout)+ result, err := callback.WaitContext(ctx, timeout)if err != nil {return nil, err}diff --git a/cli/beacon/internal/auth/server.go b/cli/beacon/internal/auth/server.goindex c6c4ee56..6b267c71 100644--- a/cli/beacon/internal/auth/server.go+++ b/cli/beacon/internal/auth/server.go@@ -106,10 +106,27 @@ func (cs *CallbackServer) Start() {// Wait blocks for the first completed callback or the timeout.func (cs *CallbackServer) Wait(timeout time.Duration) (*CallbackResult, error) {+ return cs.WaitContext(context.Background(), timeout)+}++// WaitContext is Wait that also returns when ctx is done.+//+// A caller rendering a cancellable waiting state needs to stop waiting without+// killing the command: onboarding lets the user abandon a browser sign-in and+// return to the wizard. The caller's deferred Shutdown releases the loopback+// listener either way.+func (cs *CallbackServer) WaitContext(ctx context.Context, timeout time.Duration) (*CallbackResult, error) {+ if ctx == nil {+ ctx = context.Background()+ }+ timer := time.NewTimer(timeout)+ defer timer.Stop()select {case result := <-cs.resultCh:return result, nil- case <-time.After(timeout):+ case <-ctx.Done():+ return nil, ctx.Err()+ case <-timer.C:return nil, fmt.Errorf("timeout waiting for the browser to finish")}}diff --git a/cli/beacon/internal/onboarding/wizard.go b/cli/beacon/internal/onboarding/wizard.goindex d85786a4..0e500101 100644--- a/cli/beacon/internal/onboarding/wizard.go+++ b/cli/beacon/internal/onboarding/wizard.go@@ -1,9 +1,12 @@package onboardingimport (+ "context""errors"+ "fmt""io""strings"+ "time"tea "github.com/charmbracelet/bubbletea""github.com/charmbracelet/lipgloss"@@ -13,6 +16,40 @@ import (var ErrWizardCancelled = errors.New("onboarding cancelled")+// Account is what a completed sign-in tells the wizard.+//+// It carries no token. This package draws a terminal and holds no credential, and+// the sign-in itself is injected precisely so that stays true.+type Account struct {+ Email string+}++// SignInPrompt is what the user needs in order to finish signing in elsewhere.+type SignInPrompt struct {+ URL string+ WillOpen bool+ BrowserErr error+}++// Reporter is how a sign-in in progress tells the wizard what is happening. It is+// called from the goroutine running the sign-in; the wizard funnels every call onto+// its own event channel.+type Reporter interface {+ Prompt(SignInPrompt)+}++// SignInRequest is how the wizard asks for this particular attempt. It exists so a+// retry can change its mind about the browser: the recovery screen lets a user who+// has no usable browser switch to opening the URL themselves.+type SignInRequest struct {+ NoBrowser bool+}++// SignInFunc signs in without the wizard leaving the screen. It runs off the UI+// goroutine and must return when ctx is cancelled. An error moves the wizard to its+// recovery screen; it never fails the install by itself.+type SignInFunc func(ctx context.Context, req SignInRequest, r Reporter) (Account, error)+type WizardOptions struct {SignedIn boolEmail string@@ -20,6 +57,16 @@ type WizardOptions struct {DestinationOnly boolPresetDestination stringPresetPrivacyMode string++ // SignIn signs in in place. When nil the wizard keeps its original contract:+ // it exits with NeedLogin and the caller signs in and runs it again.+ SignIn SignInFunc+ // NoBrowser presents the URL to open rather than claiming one will open.+ NoBrowser bool+ // Now is injectable so elapsed time renders deterministically in tests.+ Now func() time.Time+ // SignInTimeout is rendered as a countdown. The real deadline lives in SignIn.+ SignInTimeout time.Duration}type WizardResult struct {@@ -27,6 +74,14 @@ type WizardResult struct {Completed boolDestination stringPrivacyMode string++ // SignedInEmail is set when the in-wizard sign-in succeeded, so the caller can+ // record who completed setup without inspecting the session again.+ SignedInEmail string+ // WithoutAccount is true when the user finished setup without an account after+ // a sign-in failure. Destination is then always local: managed forwarding has+ // nothing to authorize it.+ WithoutAccount bool}type wizardScreen int@@ -34,6 +89,8 @@ type wizardScreen intconst (welcomeScreen wizardScreen = iotasignInScreen+ signInWaitScreen+ signInFailedScreendestinationScreenmanagedDisclosureScreenprivacyScreen@@ -47,6 +104,54 @@ type wizardModel struct {selected intwidth intheight int++ // events carries everything a background sign-in reports. It is buffered so a+ // reporter never blocks on a UI that has stopped reading.+ events chan tea.Msg+ // cancelSignIn stops the sign-in in flight, on esc or on quit.+ cancelSignIn context.CancelFunc+ prompt SignInPrompt+ signInErr error+ startedAt time.Time+ now time.Time+ frame int+}++// spinnerFrames animate the wait. Braille is what every terminal capable of the+// alternate screen this wizard already requires can draw.+var spinnerFrames = []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}++type tickMsg time.Time++type signInPromptMsg SignInPrompt++type signInDoneMsg struct {+ account Account+ err error+}++type chanReporter struct{ events chan<- tea.Msg }++func (r chanReporter) Prompt(p SignInPrompt) {+ select {+ case r.events <- signInPromptMsg(p):+ default:+ }+}++func waitForEvent(events <-chan tea.Msg) tea.Cmd {+ return func() tea.Msg { return <-events }+}++func tickCmd() tea.Cmd {+ return tea.Tick(120*time.Millisecond, func(t time.Time) tea.Msg { return tickMsg(t) })+}++func (m wizardModel) clock() time.Time {+ if m.options.Now != nil {+ return m.options.Now()+ }+ return time.Now()}var (@@ -76,6 +181,7 @@ func newWizardModel(options WizardOptions) wizardModel {func RunWizard(in io.Reader, out io.Writer, options WizardOptions) (WizardResult, error) {model := newWizardModel(options)+ model.events = make(chan tea.Msg, 8)program := tea.NewProgram(model, tea.WithAltScreen(), tea.WithInput(in), tea.WithOutput(out))final, err := program.Run()if err != nil {@@ -96,20 +202,42 @@ func (m wizardModel) Update(message tea.Msg) (tea.Model, tea.Cmd) {switch msg := message.(type) {case tea.WindowSizeMsg:m.width, m.height = msg.Width, msg.Height+ case tickMsg:+ // Only the waiting screen animates, and only it keeps the ticker alive.+ if m.screen != signInWaitScreen {+ return m, nil+ }+ m.now = time.Time(msg)+ m.frame+++ return m, tickCmd()+ case signInPromptMsg:+ m.prompt = SignInPrompt(msg)+ return m, waitForEvent(m.events)+ case signInDoneMsg:+ return m.signInFinished(msg)case tea.KeyMsg:switch msg.String() {// esc and ctrl+c cancel; "q" deliberately does not. It used to, on every// screen, so a user typing q at the destination list killed the install --// and no screen could ever take free text while a bare letter meant quit.- case "ctrl+c", "esc":- return m, tea.Quit+ case "ctrl+c":+ return m.cancelAndQuit()+ case "esc":+ // Abandoning a browser sign-in returns to the sign-in screen rather than+ // ending the install: the browser may simply not have opened.+ if m.screen == signInWaitScreen {+ m.stopSignIn()+ m.screen = signInScreen+ return m, nil+ }+ return m.cancelAndQuit()case "up", "k":- if m.screen == destinationScreen || m.screen == privacyScreen {- m.selected = (m.selected - 1 + m.choiceCount()) % m.choiceCount()+ if n := m.choiceCount(); m.isPicker() && n > 0 {+ m.selected = (m.selected - 1 + n) % n}case "down", "j":- if m.screen == destinationScreen || m.screen == privacyScreen {- m.selected = (m.selected + 1) % m.choiceCount()+ if n := m.choiceCount(); m.isPicker() && n > 0 {+ m.selected = (m.selected + 1) % n}case "enter":return m.advance()@@ -118,6 +246,77 @@ func (m wizardModel) Update(message tea.Msg) (tea.Model, tea.Cmd) {return m, nil}+func (m wizardModel) isPicker() bool {+ return m.screen == destinationScreen || m.screen == privacyScreen || m.screen == signInFailedScreen+}++func (m *wizardModel) stopSignIn() {+ if m.cancelSignIn != nil {+ m.cancelSignIn()+ m.cancelSignIn = nil+ }+}++func (m wizardModel) cancelAndQuit() (tea.Model, tea.Cmd) {+ m.stopSignIn()+ return m, tea.Quit+}++// startSignIn runs the injected sign-in off the UI goroutine and shows the waiting+// screen. Waiting begins immediately: the URL is reported by the sign-in itself+// once its callback server is listening, never gated on the user pressing anything.+func (m wizardModel) startSignIn() (tea.Model, tea.Cmd) {+ ctx, cancel := context.WithCancel(context.Background())+ m.cancelSignIn = cancel+ m.signInErr = nil+ m.prompt = SignInPrompt{}+ m.startedAt = m.clock()+ m.now = m.startedAt+ m.frame = 0+ m.screen = signInWaitScreen++ events, signIn := m.events, m.options.SignIn+ req := SignInRequest{NoBrowser: m.options.NoBrowser}+ go func() {+ account, err := signIn(ctx, req, chanReporter{events: events})+ events <- signInDoneMsg{account: account, err: err}+ }()+ return m, tea.Batch(waitForEvent(m.events), tickCmd())+}++func (m wizardModel) signInFinished(msg signInDoneMsg) (tea.Model, tea.Cmd) {+ m.stopSignIn()+ if msg.err != nil {+ // A cancel the user asked for has already moved the screen; do not overwrite+ // it with a failure they did not cause.+ if m.screen != signInWaitScreen {+ return m, nil+ }+ m.signInErr = msg.err+ m.selected = 0+ m.screen = signInFailedScreen+ return m, nil+ }+ m.options.SignedIn = true+ m.options.Email = msg.account.Email+ m.result.SignedInEmail = msg.account.Email+ m.selected = 0+ m.screen = m.afterSignIn()+ return m, nil+}++// afterSignIn is where the wizard resumes once an account exists.+func (m wizardModel) afterSignIn() wizardScreen {+ switch {+ case m.options.PresetDestination == DestinationAsymptote:+ return managedDisclosureScreen+ case m.options.PresetDestination != "":+ return confirmScreen+ default:+ return destinationScreen+ }+}+func (m wizardModel) advance() (tea.Model, tea.Cmd) {switch m.screen {case welcomeScreen:@@ -132,8 +331,18 @@ func (m wizardModel) advance() (tea.Model, tea.Cmd) {m.screen = destinationScreen}case signInScreen:+ if m.options.SignIn != nil {+ return m.startSignIn()+ }+ // No sign-in was injected: keep the original contract, where the caller+ // signs in and runs the wizard again.m.result.NeedLogin = truereturn m, tea.Quit+ case signInWaitScreen:+ // Enter does nothing while the browser has the floor.+ return m, nil+ case signInFailedScreen:+ return m.recover()case destinationScreen:m.result.Destination = m.destinations()[m.selected]if m.result.Destination == DestinationAsymptote {@@ -162,10 +371,71 @@ func (m wizardModel) destinations() []string {}func (m wizardModel) choiceCount() int {- if m.screen == privacyScreen {+ switch m.screen {+ case privacyScreen:return len(managedprivacy.Modes)+ case signInFailedScreen:+ return len(m.recoveryChoices())+ default:+ return len(m.destinations())+ }+}++// recoveryChoice is one way out of a sign-in that did not finish.+type recoveryChoice struct {+ id string+ label string+ detail string+}++// recoveryChoices exist only here, after an attempt has actually failed.+//+// Signing in is the expected path, so the sign-in screen offers nothing else; a+// visible "skip" there would read as a suggestion. But a machine that is offline,+// has no browser, or cannot receive the loopback redirect still has to be able to+// finish, or a local-first tool becomes uninstallable without tribal knowledge of+// an environment variable.+func (m wizardModel) recoveryChoices() []recoveryChoice {+ choices := []recoveryChoice{+ {id: "retry", label: "Try signing in again", detail: "Open beacon.sh and wait for the browser again."},+ }+ if m.prompt.WillOpen || m.prompt.BrowserErr != nil {+ choices = append(choices, recoveryChoice{+ id: "manual",+ label: "Show the URL instead of opening a browser",+ detail: "Open the address yourself, in a browser on this machine.",+ })+ }+ return append(choices,+ recoveryChoice{+ id: "local",+ label: "Finish setup without an account",+ detail: "Install Beacon with telemetry kept on this machine. Connect later with `beacon endpoint connect`.",+ },+ recoveryChoice{id: "cancel", label: "Cancel setup", detail: "Stop without installing."},+ )+}++func (m wizardModel) recover() (tea.Model, tea.Cmd) {+ choices := m.recoveryChoices()+ if m.selected < 0 || m.selected >= len(choices) {+ return m, nil+ }+ switch choices[m.selected].id {+ case "retry":+ return m.startSignIn()+ case "manual":+ m.options.NoBrowser = true+ return m.startSignIn()+ case "local":+ m.result.WithoutAccount = true+ m.result.Destination = DestinationLocal+ m.result.PrivacyMode = ""+ m.screen = confirmScreen+ return m, nil+ default:+ return m, tea.Quit}- return len(m.destinations())}func (m wizardModel) View() string {@@ -174,7 +444,7 @@ func (m wizardModel) View() string {width = 80}contentWidth := min(76, max(30, width-8))- var title, body string+ var title, body, raw stringswitch m.screen {case welcomeScreen:title = "Welcome to Beacon"@@ -185,6 +455,37 @@ func (m wizardModel) View() string {case signInScreen:title = "Sign in to continue"body = "Beacon will open beacon.sh in your browser using a secure PKCE flow.\n\nSigning in does not send telemetry, register a managed endpoint, or enable forwarding."+ case signInWaitScreen:+ title = "Waiting for you to finish signing in"+ switch {+ case m.prompt.URL == "":+ body = "Starting sign-in..."+ case m.prompt.BrowserErr != nil:+ body = "A browser could not be opened here. Open this URL on this machine:"+ case m.prompt.WillOpen:+ body = "Your browser should have opened. If it did not, open this URL:"+ default:+ body = "Open this URL to sign in:"+ }+ raw = m.prompt.URL+ if m.prompt.URL != "" {+ raw += "\n\n" + wizardDim.Render(m.waitStatus()) ++ "\n\n" + wizardDim.Render("Signing in does not send telemetry or connect this machine.")+ }+ case signInFailedScreen:+ title = "Sign-in did not finish"+ if m.signInErr != nil {+ body = wizardWarn.Render(m.signInErr.Error()) + "\n\n"+ }+ var rows []string+ for index, choice := range m.recoveryChoices() {+ line := " " + choice.label+ if index == m.selected {+ line = wizardChoice.Render(" ❯ " + choice.label)+ }+ rows = append(rows, line, choiceDetail(choice.detail, contentWidth))+ }+ body += strings.Join(rows, "\n")case destinationScreen:title = "Where should this machine's telemetry go?"var rows []string@@ -219,20 +520,31 @@ func (m wizardModel) View() string {case confirmScreen:title = "Ready to set up Beacon"label, _ := destinationCopy(m.result.Destination)- body = "Account: " + m.options.Email + "\nDestination: " + label+ if m.options.Email != "" {+ body = "Account: " + m.options.Email + "\n"+ }+ body += "Destination: " + labelif m.result.Destination == DestinationAsymptote {body += "\nPrivacy: " + managedprivacy.Label(m.result.PrivacyMode) +"\n\n" + wizardWarn.Render("Confirming installs Beacon and starts forwarding new events to beacon.sh.") +"\n\n" + privacySends(m.result.PrivacyMode)} else {body += "\n\nYour telemetry stays on this machine."+ if m.result.WithoutAccount {+ body += " You are not signed in; connect later with `beacon endpoint connect`."+ }}}card := wizardAccent.Render("B E A C O N") + "\n\n" +wizardAccent.Render(title) + "\n\n" +- lipgloss.NewStyle().Width(contentWidth).Render(body) + "\n\n" +- wizardDim.Render(m.hint())+ lipgloss.NewStyle().Width(contentWidth).Render(body)+ if raw != "" {+ // Deliberately not width-constrained: a soft-wrapped URL is one a user+ // cannot copy, and copying it is the whole point of showing it.+ card += "\n\n" + raw+ }+ card += "\n\n" + wizardDim.Render(m.hint())return lipgloss.NewStyle().Padding(1, 3).Render(card)}@@ -292,6 +604,28 @@ func privacySends(mode string) string {return "Standard: the locally sanitized event, including prompts and tool activity."}+// waitStatus renders the spinner, how long this has been going, and how long is+// left, so a wait with no visible progress is not mistaken for a hang.+func (m wizardModel) waitStatus() string {+ frame := spinnerFrames[m.frame%len(spinnerFrames)]+ elapsed := m.now.Sub(m.startedAt)+ if elapsed < 0 {+ elapsed = 0+ }+ status := fmt.Sprintf("%s %s elapsed", frame, clockFormat(elapsed))+ if m.options.SignInTimeout > 0 {+ if remaining := m.options.SignInTimeout - elapsed; remaining > 0 {+ status += fmt.Sprintf(" · times out in %s", clockFormat(remaining))+ }+ }+ return status+}++func clockFormat(d time.Duration) string {+ total := int(d.Round(time.Second).Seconds())+ return fmt.Sprintf("%d:%02d", total/60, total%60)+}+func (m wizardModel) hint() string {if m.screen == confirmScreen && m.result.Destination == DestinationAsymptote {return "enter install and connect · esc cancel"@@ -307,6 +641,10 @@ func wizardHint(screen wizardScreen) string {return "↑/↓ choose · enter continue · esc cancel"case signInScreen:return "enter open beacon.sh · esc cancel"+ case signInWaitScreen:+ return "esc go back · ctrl+c cancel setup"+ case signInFailedScreen:+ return "↑/↓ choose · enter continue · esc cancel"case confirmScreen:return "enter install · esc cancel"default:diff --git a/cli/beacon/internal/onboarding/wizard_test.go b/cli/beacon/internal/onboarding/wizard_test.goindex 77eb637b..f06faf50 100644--- a/cli/beacon/internal/onboarding/wizard_test.go+++ b/cli/beacon/internal/onboarding/wizard_test.go@@ -1,8 +1,11 @@package onboardingimport (+ "context"+ "errors""strings""testing"+ "time"tea "github.com/charmbracelet/bubbletea")@@ -293,3 +296,249 @@ func TestConfirmScreenNamesWhatConfirmingStarts(t *testing.T) {t.Fatalf("local confirm screen must not offer to connect: %s", view)}}++// signInWizard builds a wizard whose sign-in runs in place, the way RunWizard does.+func signInWizard(t *testing.T, signIn SignInFunc) wizardModel {+ t.Helper()+ model := newWizardModel(WizardOptions{+ OfferManaged: true,+ SignIn: signIn,+ SignInTimeout: 5 * time.Minute,+ Now: func() time.Time { return time.Date(2026, 9, 21, 8, 0, 0, 0, time.UTC) },+ })+ model.events = make(chan tea.Msg, 8)+ model.width, model.height = 100, 30+ return model+}++func neverReturns(ctx context.Context, _ SignInRequest, _ Reporter) (Account, error) {+ <-ctx.Done()+ return Account{}, ctx.Err()+}++// Sign-in used to quit the wizard so the caller could run it, print to plain+// stdout, block for up to five minutes, and then start a second wizard -- which+// wiped what had just been printed. It now runs without the screen going away.+func TestSignInRunsInsideTheWizard(t *testing.T) {+ model := signInWizard(t, neverReturns)+ model.screen = signInScreen++ model, cmd := advanceWizard(t, model, "enter")+ if model.screen != signInWaitScreen {+ t.Fatalf("screen = %v, want the waiting screen", model.screen)+ }+ if model.result.NeedLogin {+ t.Fatal("an injected sign-in must not fall back to the caller")+ }+ if cmd == nil {+ t.Fatal("expected the wait to be armed")+ }+ t.Cleanup(func() { model.stopSignIn() })+}++// The URL has to be on screen before any browser is claimed to have opened, and it+// has to survive rendering intact: a soft-wrapped URL is one nobody can copy.+func TestSignInWaitShowsAnUnwrappedURLAndAClock(t *testing.T) {+ model := signInWizard(t, neverReturns)+ model.screen = signInScreen+ model, _ = advanceWizard(t, model, "enter")+ t.Cleanup(func() { model.stopSignIn() })++ url := "https://beacon.sh/cli/auth?port=54123&state=" + strings.Repeat("a", 43)+ next, _ := model.Update(signInPromptMsg{URL: url, WillOpen: true})+ model = next.(wizardModel)++ // Seven seconds later.+ later := model.startedAt.Add(7 * time.Second)+ next, _ = model.Update(tickMsg(later))+ model = next.(wizardModel)++ view := model.View()+ if !strings.Contains(view, url) {+ t.Fatalf("the sign-in URL must render on one unbroken line:\n%s", view)+ }+ flat := strings.Join(strings.Fields(view), " ")+ for _, want := range []string{"0:07 elapsed", "times out in 4:53", "does not send telemetry"} {+ if !strings.Contains(flat, want) {+ t.Fatalf("waiting screen missing %q:\n%s", want, view)+ }+ }+}++// Abandoning the browser must not end the install. It used to: the wait was+// uncancellable, so ctrl+c during it killed the whole command.+func TestEscDuringSignInGoesBackWithoutEndingTheInstall(t *testing.T) {+ model := signInWizard(t, neverReturns)+ model.screen = signInScreen+ model, _ = advanceWizard(t, model, "enter")++ model, cmd := advanceWizard(t, model, "esc")+ if cmd != nil {+ t.Fatal("esc while waiting must not quit the wizard")+ }+ if model.screen != signInScreen {+ t.Fatalf("screen = %v, want the sign-in screen", model.screen)+ }+ if model.result.Completed || model.result.NeedLogin {+ t.Fatalf("result = %#v", model.result)+ }+}++// Signing in is the expected path, so the sign-in screen offers nothing else. A+// visible "skip" there would read as a suggestion.+func TestSignInScreenOffersNoAlternative(t *testing.T) {+ model := signInWizard(t, neverReturns)+ model.screen = signInScreen+ flat := strings.Join(strings.Fields(model.View()), " ")+ for _, unwanted := range []string{"without an account", "Local only", "skip"} {+ if strings.Contains(strings.ToLower(flat), strings.ToLower(unwanted)) {+ t.Fatalf("the sign-in screen must not advertise %q:\n%s", unwanted, flat)+ }+ }+}++// But a sign-in that genuinely failed has to leave a way forward, or an offline or+// browserless machine cannot install a local-first tool at all.+func TestSignInFailureOffersRecoveryAndALocalFinish(t *testing.T) {+ model := signInWizard(t, neverReturns)+ model.screen = signInScreen+ model, _ = advanceWizard(t, model, "enter")+ next, _ := model.Update(signInPromptMsg{URL: "https://beacon.sh/cli/auth?port=1&state=x", WillOpen: true})+ model = next.(wizardModel)+ next, _ = model.Update(signInDoneMsg{err: errors.New("connection refused")})+ model = next.(wizardModel)++ if model.screen != signInFailedScreen {+ t.Fatalf("screen = %v, want the recovery screen", model.screen)+ }+ flat := strings.Join(strings.Fields(model.View()), " ")+ for _, want := range []string{"connection refused", "Try signing in again", "Show the URL", "Finish setup without an account"} {+ if !strings.Contains(flat, want) {+ t.Fatalf("recovery screen missing %q:\n%s", want, flat)+ }+ }++ // Retry is first, so the default action is to try again rather than give up.+ if model.recoveryChoices()[0].id != "retry" {+ t.Fatalf("recovery choices = %#v, want retry first", model.recoveryChoices())+ }++ // Choosing to finish without an account lands on local, never managed.+ ids := map[string]int{}+ for i, choice := range model.recoveryChoices() {+ ids[choice.id] = i+ }+ model.selected = ids["local"]+ model, _ = advanceWizard(t, model, "enter")+ if !model.result.WithoutAccount || model.result.Destination != DestinationLocal {+ t.Fatalf("result = %#v, want a local finish without an account", model.result)+ }+ if model.screen != confirmScreen {+ t.Fatalf("screen = %v, want confirmation", model.screen)+ }+ if flat := strings.Join(strings.Fields(model.View()), " "); !strings.Contains(flat, "not signed in") {+ t.Fatalf("the confirm screen should say no account is attached:\n%s", flat)+ }+}++// Picking the manual option retries with the browser suppressed.+func TestRecoveryCanRetryWithoutABrowser(t *testing.T) {+ requests := make(chan SignInRequest, 4)+ model := signInWizard(t, func(ctx context.Context, req SignInRequest, _ Reporter) (Account, error) {+ requests <- req+ <-ctx.Done()+ return Account{}, ctx.Err()+ })+ model.screen = signInFailedScreen+ model.prompt = SignInPrompt{URL: "https://beacon.sh/cli/auth", WillOpen: true}+ for i, choice := range model.recoveryChoices() {+ if choice.id == "manual" {+ model.selected = i+ }+ }+ model, _ = advanceWizard(t, model, "enter")+ t.Cleanup(func() { model.stopSignIn() })++ if model.screen != signInWaitScreen {+ t.Fatalf("screen = %v, want the waiting screen", model.screen)+ }+ select {+ case req := <-requests:+ if !req.NoBrowser {+ t.Fatalf("retry request = %#v, want the browser suppressed", req)+ }+ case <-time.After(2 * time.Second):+ t.Fatal("the retry never reached the sign-in function")+ }+}++// A successful sign-in continues to the next question in the same screen session.+func TestSignInSuccessContinuesToTheDestinationQuestion(t *testing.T) {+ model := signInWizard(t, neverReturns)+ model.screen = signInScreen+ model, _ = advanceWizard(t, model, "enter")+ next, _ := model.Update(signInDoneMsg{account: Account{Email: "[email protected]"}})+ model = next.(wizardModel)++ if model.screen != destinationScreen {+ t.Fatalf("screen = %v, want the destination question", model.screen)+ }+ if model.result.SignedInEmail != "[email protected]" || !model.options.SignedIn {+ t.Fatalf("result = %#v options.SignedIn = %t", model.result, model.options.SignedIn)+ }+}++// With no sign-in injected the wizard keeps its original contract, which is what+// the command-level tests drive.+func TestWizardWithoutAnInjectedSignInStillReportsNeedLogin(t *testing.T) {+ model := newWizardModel(WizardOptions{OfferManaged: true})+ model.screen = signInScreen+ model, cmd := advanceWizard(t, model, "enter")+ if !model.result.NeedLogin || cmd == nil {+ t.Fatalf("result = %#v cmd = %v", model.result, cmd)+ }+}++// The whole first run, in one screen session: welcome, sign in, wait for the+// browser, answer the destination question, confirm. This is the sequence that+// used to require quitting the program and starting a second one around a blocking+// five-minute login.+func TestWholeFirstRunHappensInOneScreenSession(t *testing.T) {+ model := signInWizard(t, neverReturns)+ model.options.OfferManaged = false+ model.screen = welcomeScreen++ model, _ = advanceWizard(t, model, "enter")+ if model.screen != signInScreen {+ t.Fatalf("after welcome: screen = %v", model.screen)+ }+ model, quitCmd := advanceWizard(t, model, "enter")+ t.Cleanup(func() { model.stopSignIn() })+ if model.screen != signInWaitScreen {+ t.Fatalf("after sign-in: screen = %v", model.screen)+ }+ if model.result.NeedLogin {+ t.Fatal("the program must not exit to sign in")+ }+ _ = quitCmd++ next, _ := model.Update(signInPromptMsg{URL: "https://beacon.sh/cli/auth?port=1&state=x", WillOpen: true})+ model = next.(wizardModel)+ next, _ = model.Update(signInDoneMsg{account: Account{Email: "[email protected]"}})+ model = next.(wizardModel)+ if model.screen != destinationScreen {+ t.Fatalf("after sign-in completed: screen = %v", model.screen)+ }++ model, _ = advanceWizard(t, model, "enter")+ if model.screen != confirmScreen || model.result.Destination != DestinationLocal {+ t.Fatalf("after destination: screen = %v destination = %q", model.screen, model.result.Destination)+ }+ model, cmd := advanceWizard(t, model, "enter")+ if !model.result.Completed || cmd == nil {+ t.Fatalf("result = %#v", model.result)+ }+ if model.result.SignedInEmail != "[email protected]" {+ t.Fatalf("the signed-in account should reach the caller: %#v", model.result)+ }+}diff --git a/docs/changelog/cli.mdx b/docs/changelog/cli.mdxindex 676ff5c0..2c80ff8a 100644--- a/docs/changelog/cli.mdx+++ b/docs/changelog/cli.mdx@@ -13,6 +13,17 @@ Stay up to date with the latest changes to the Agent Beacon CLI.### Unreleased+- **Sign-in no longer tears down the setup screen** · The wizard used to quit to+ sign you in, print to plain output, block for up to five minutes, then start a+ second wizard that wiped what it had just printed. Sign-in now runs inside the+ same full-screen view, which shows the URL, a spinner, and the remaining time.+ The URL is printed before any browser opens, so it works when none can, and+ <kbd>esc</kbd> during the wait goes back instead of killing the install.+- **A sign-in that cannot finish no longer blocks the install** · Offline, without+ a browser, or after the wait expires, the wizard offers to retry, to show the URL+ to open yourself, or to finish setup without an account with telemetry kept+ locally. `beacon endpoint install --no-browser` starts in URL mode.+- **Choosing Beacon Managed now connects the endpoint** · Confirming Managed in theinstall wizard installs Beacon and then enrolls the device and starts theforwarder, instead of printing `beacon endpoint connect` for you to run yourself.diff --git a/docs/cli/endpoint-onboarding.mdx b/docs/cli/endpoint-onboarding.mdxindex 1fff76df..80a6df88 100644--- a/docs/cli/endpoint-onboarding.mdx+++ b/docs/cli/endpoint-onboarding.mdx@@ -30,6 +30,17 @@ The first interactive `beacon endpoint install` opens a full-screen terminal wizMove between choices with the arrow keys, continue with <kbd>enter</kbd>, and cancelwith <kbd>esc</kbd>.+Signing in happens inside the wizard. The full-screen view stays up while your+browser is open, showing the sign-in URL, a spinner, and how long is left before the+attempt times out. The URL is printed before any browser is opened, so it is usable+even when none can be, and <kbd>esc</kbd> during the wait returns to the sign-in+screen rather than ending the install.++If sign-in cannot finish -- an offline machine, no browser, or the wait expiring --+the wizard offers to try again, to show the URL for you to open yourself, or to+finish setup without an account and keep telemetry on this machine. Pass+`--no-browser` to `beacon endpoint install` to start in that mode.+Signing in establishes account identity only. It does not register a managed endpoint,start Vector, or send telemetry. Beacon Managed is preselected; choose Local explicitlyto opt out of managed forwarding.