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
- func CLIStatus(ctx context.Context, sh agents.LoginRunner, envDir string, c CLI) hubproto.AgentStatus
- func ClaudeLoginURL(screen string) string
- func CodexDevice(screen string) (url, code string)
- func LastLines(screen string, n int) string
- func Reserved(id string) bool
- func StripANSI(s string) string
- type CLI
- type Config
- type Manager
- func (m *Manager) Busy() (string, bool)
- func (m *Manager) Cancel(loginID string) error
- func (m *Manager) Code(loginID, code string) error
- func (m *Manager) Get(loginID string) (hubproto.Login, bool)
- func (m *Manager) Start(loginID, provider, method string) (hubproto.Login, error)
- func (m *Manager) Wait()
- type Shell
- type Timing
Constants ¶
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 ¶
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 ¶
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 ¶
LastLines is the end of a screen, for a message about why a login stopped: blank lines dropped, at most n lines.
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 LoadCLIs ¶
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.
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.
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.