agentlogin

package
v0.16.521 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package agentlogin signs the agent CLIs in on the machine, for the hub's «Войти» buttons.

Three ways, one login per machine at a time:

  • Claude by link: `claude auth login` runs in a pane of the agent's own tmux server, wide enough that its sign-in address is one line. The address goes to the person, who signs in on Anthropic's page and pastes the code that page shows; the code is typed into the pane, and the login is proved by `claude auth status`.
  • Codex by link: a device-code login. `codex app-server` starts it and says when the person has confirmed; where it cannot be used, the screen of `codex login --device-auth` gives the same address and code.
  • By console: a terminal tab of the runtime runs the CLI's own login, the person works in it, and the status is polled. Other CLIs the machine's cli-logins.json describes (#58) sign in this way only, see CLI.

A login ends in done, failed, expired or cancelled, and says so through Config.Emit each time its state changes.

Index

Constants

View Source
const CLIsFile = "cli-logins.json"

CLIsFile is the name of the file in the agent's data folder that describes the machine's other CLIs to sign in (#58).

Variables

This section is empty.

Functions

func CLIStatus

func CLIStatus(ctx context.Context, sh agents.LoginRunner, envDir string, c CLI) hubproto.AgentStatus

CLIStatus asks the CLI whether this account is signed in. Neither its output nor its errors are kept: a status command may print a token.

func ClaudeLoginURL

func ClaudeLoginURL(screen string) string

ClaudeLoginURL is the sign-in address on the screen of `claude auth login`: the first address that is an OAuth authorize page of Anthropic. "" when there is none yet.

func CodexDevice

func CodexDevice(screen string) (url, code string)

CodexDevice is the page and the one-time code on the screen of `codex login --device-auth`. The code is the first one after the address; both are "" until the screen has them.

func LastLines

func LastLines(screen string, n int) string

LastLines is the end of a screen, for a message about why a login stopped: blank lines dropped, at most n lines.

func Reserved

func Reserved(id string) bool

Reserved says the id belongs to an agent, which has its own sign-in.

func StripANSI

func StripANSI(s string) string

StripANSI removes colours, cursor moves and hyperlink escapes, and carriage returns.

Types

type CLI

type CLI struct {
	// ID names the CLI in the hub's routes: lower-case letters, digits and dashes, not an agent's name.
	ID string `json:"id"`
	// Label is what the page shows.
	Label string `json:"label"`
	// Login is the sign-in command, as arguments; it runs as it is, nothing from the browser is added to it.
	Login []string `json:"login"`
	// Status is a command that exits 0 when this account is signed in. Its output is not read and not kept.
	Status []string `json:"status"`
	// Timeout is how long a sign-in may take, in seconds: 900 when 0, at most 3600.
	Timeout int `json:"timeout,omitempty"`
}

CLI is one command-line tool the machine's owner signs in from the hub's page, the way the agents are signed in by console: a terminal of the runtime runs Login, the person follows it, and Status says when it worked.

The file is a JSON array of these. An organization's extension pack writes it; the hub learns of the CLIs only from what the agent reports, so no core change and no hub setting is needed.

func FindCLI

func FindCLI(path, id string) (CLI, bool)

FindCLI is the CLI the file describes under id.

func LoadCLIs

func LoadCLIs(path string) ([]CLI, []error)

LoadCLIs reads the file: the entries that are right, and what is wrong with the others. A missing file is no CLIs. It is read on each use, so a pack that changes it needs no restart of the agent.

func (CLI) LoginLine

func (c CLI) LoginLine(envDir string) string

LoginLine is the line the console runs for the CLI's sign-in, with the machine's shared env file (a proxy).

func (CLI) TTL

func (c CLI) TTL(def time.Duration) time.Duration

TTL is how long a sign-in of this CLI may take.

type Config

type Config struct {
	Shell Shell
	// Status is how the provider stands now; a login is done when it says logged_in.
	Status func(ctx context.Context, provider string) hubproto.AgentStatus
	// Console opens a terminal tab of the runtime that runs command, and gives the path that shows it under the
	// runtime's base path. nil makes the console method fail.
	Console func(ctx context.Context, provider, command string) (string, error)
	// ConsoleNote tells the console page where its attempt stands ("waiting", "connected", "failed", "expired",
	// "cancelled"; expiresAt is Unix milliseconds, 0 when unknown) and answers whether the person cancelled the attempt
	// on that page. It carries states only, never anything the CLI printed. nil is no notes.
	ConsoleNote func(ctx context.Context, consoleURL, provider, state string, expiresAt int64) (cancelled bool)
	// Emit hands a login's new state to the hub.
	Emit func(hubproto.Login)
	// Finished is told when a login has ended, so what the agent reports about its CLIs can be refreshed.
	Finished func(provider string)
	// CLI finds a CLI of the machine's cli-logins.json; such a CLI signs in by console only, with its own status. nil
	// is no such CLIs.
	CLI func(id string) (CLI, bool)

	// EnvDir holds the agent's env files, which the login's commands source (a proxy is how the provider is reached).
	EnvDir string
	// Dir is where the launcher files of a pane are made.
	Dir string
	// Tmux is the tmux program ("" — tmux on the PATH); Socket the name of the agent's own server.
	Tmux   string
	Socket string
	// Version is shown to Codex's app-server as the client's version.
	Version string
	Timing  Timing
	Now     func() time.Time
}

Config is what a Manager works with.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager runs the logins of one machine.

func New

func New(ctx context.Context, cfg Config) *Manager

New is a Manager whose logins end with ctx.

func (*Manager) Busy

func (m *Manager) Busy() (string, bool)

Busy says a login is running, and for which provider.

func (*Manager) Cancel

func (m *Manager) Cancel(loginID string) error

Cancel ends a login. One that has ended already stays as it ended.

func (*Manager) Code

func (m *Manager) Code(loginID, code string) error

Code hands the Claude login the code the person got on Anthropic's page.

func (*Manager) Get

func (m *Manager) Get(loginID string) (hubproto.Login, bool)

Get is a login as it stands.

func (*Manager) Start

func (m *Manager) Start(loginID, provider, method string) (hubproto.Login, error)

Start begins a login. The Login it returns is in state starting; the rest is told through Emit.

func (*Manager) Wait

func (m *Manager) Wait()

Wait returns when no login is running.

type Shell

type Shell interface {
	LoginCmd(ctx context.Context, script string, extraEnv ...string) (*exec.Cmd, error)
}

Shell makes the commands of the account's login shell; preflight.Checker is one.

type Timing

type Timing struct {
	URLWait     time.Duration // the address on the screen: 10 s
	AppServer   time.Duration // Codex's app-server to start the login: 12 s
	VerifyWait  time.Duration // Claude to take the code: 60 s
	ScreenEvery time.Duration // how often the screen is read: 250 ms
	StatusEvery time.Duration // how often the status is asked while waiting: 3 s
	ClaudeTTL   time.Duration // 10 min
	CodexTTL    time.Duration // 15 min
	ConsoleTTL  time.Duration // 15 min
}

Timing is how long the login waits for each thing. Zero values are the contract's numbers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL