Documentation
¶
Overview ¶
Package cli is the person's command-line tool, gator: sign in with Google, look at projects and tasks, start a task, run it and watch its log. It speaks the same /api/v1 as Gator.app, with a user token of its own.
The agent's tool, gator-cli, stays a separate binary on purpose. It speaks with a job's identity, answers only in JSON, and the runner looks for it by name beside itself; a person's tool that can read their stored sign-in has no business on an agent's PATH.
Index ¶
- Variables
- func ConfigDir(getenv func(string) string) string
- func NormalizeServer(s string) (string, error)
- func Run(ctx context.Context, env *Env, args []string) int
- func SaveConfig(dir string, c Config) error
- type APIError
- type AuthConfig
- type Check
- type Client
- func (c *Client) Advance(ctx context.Context, id, reason string) (Task, error)
- func (c *Client) Approve(ctx context.Context, id string) (Task, error)
- func (c *Client) AuthConfig(ctx context.Context) (AuthConfig, error)
- func (c *Client) CreateJob(ctx context.Context, taskID string, in NewJob) (Job, error)
- func (c *Client) CreateProject(ctx context.Context, in NewProject) (Project, error)
- func (c *Client) CreateTask(ctx context.Context, projectID string, in NewTask) (Task, error)
- func (c *Client) ExchangeCode(ctx context.Context, in tokenRequest) (tokenResponse, error)
- func (c *Client) Job(ctx context.Context, id string) (Job, error)
- func (c *Client) JobEvents(ctx context.Context, jobID string, after int64) ([]JobEvent, error)
- func (c *Client) Logout(ctx context.Context) error
- func (c *Client) Me(ctx context.Context) (Me, error)
- func (c *Client) Projects(ctx context.Context) ([]Project, error)
- func (c *Client) Task(ctx context.Context, id string) (TaskDetail, error)
- func (c *Client) TaskJobs(ctx context.Context, taskID string) ([]Job, error)
- func (c *Client) Tasks(ctx context.Context, projectID string) ([]Task, error)
- type Config
- type Env
- type FileStore
- type Gate
- type Job
- type JobEvent
- type Me
- type NewJob
- type NewProject
- type NewTask
- type Project
- type Store
- type Task
- type TaskDetail
Constants ¶
This section is empty.
Variables ¶
var ErrNoToken = errors.New("no stored token")
ErrNoToken means nothing is stored for the server.
Functions ¶
func ConfigDir ¶
ConfigDir is $XDG_CONFIG_HOME/gator, else ~/.config/gator — on macOS too, where a terminal user looks for dotfiles rather than in ~/Library/Application Support.
func NormalizeServer ¶
NormalizeServer turns what a person types into the base URL the CLI keys its token by: "gator.example.com" and "https://gator.example.com/" are the same server.
func SaveConfig ¶
SaveConfig writes the config atomically, readable by its owner only.
Types ¶
type AuthConfig ¶
AuthConfig says whether the server offers sign-in through a provider, and which.
type Client ¶
Client is a small hand-written client for the part of /api/v1 a person uses from a terminal.
Not generated from docs/openapi.yaml like the server is: oapi-codegen's client for the whole contract is tens of thousands of lines of which this tool needs a dozen calls, and its pointer-heavy types make table output clumsy. The contract still binds it — client_test.go validates every request it sends against docs/openapi.yaml.
func (*Client) AuthConfig ¶
func (c *Client) AuthConfig(ctx context.Context) (AuthConfig, error)
func (*Client) CreateProject ¶
func (*Client) CreateTask ¶
func (*Client) ExchangeCode ¶
func (*Client) JobEvents ¶
JobEvents returns stored output after seq, at most 1000 at a time (the contract's limit).
type Config ¶
type Config struct {
// Server is the one `gator login` signed in to.
Server string `json:"server,omitempty"`
// Project is the slug `gator use` chose, the default for --project.
Project string `json:"project,omitempty"`
}
Config is what the CLI remembers between runs. The token is not here: it lives in the keychain (see Store), so this file can be read, copied or shown without leaking anything.
func LoadConfig ¶
LoadConfig reads the config; a missing file is an empty config.
type Env ¶
type Env struct {
Stdin io.Reader
Stdout, Stderr io.Writer
Getenv func(string) string
// ConfigDir holds config.json (and, without a keychain, credentials.json).
ConfigDir string
Store Store
HTTP *http.Client
// OpenBrowser shows the sign-in page. Failing is fine: the URL is printed as well.
OpenBrowser func(url string) error
Hostname string
// LoginTimeout bounds the wait for the browser to come back.
LoginTimeout time.Duration
// PollInterval paces log following when the WebSocket is not available.
PollInterval time.Duration
}
Env is everything a command touches outside itself, so tests can stand in for the world.
func DefaultEnv ¶
func DefaultEnv() *Env
DefaultEnv is the real terminal, the real config directory and the real keychain.
type FileStore ¶
type FileStore struct{ Path string }
FileStore keeps tokens in a JSON file readable by its owner only, for machines without a keychain (Linux servers, CI).
type Job ¶
type Job struct {
ID string `json:"id"`
TaskID string `json:"taskId"`
ProjectID string `json:"projectId"`
Phase string `json:"phase"`
Role string `json:"role"`
Backend string `json:"backend"`
Model string `json:"model,omitempty"`
Instruction string `json:"instruction"`
Status string `json:"status"`
Placement string `json:"placement,omitempty"`
RunnerID string `json:"runnerId,omitempty"`
Attempts int `json:"attempts"`
MaxAttempts int `json:"maxAttempts"`
StopReason string `json:"stopReason,omitempty"`
Receipt map[string]any `json:"receipt,omitempty"`
CreatedAt time.Time `json:"createdAt"`
StartedAt *time.Time `json:"startedAt,omitempty"`
FinishedAt *time.Time `json:"finishedAt,omitempty"`
}
type NewJob ¶
type NewJob struct {
Backend string `json:"backend,omitempty"`
Instruction string `json:"instruction,omitempty"`
Placement string `json:"placement,omitempty"`
AllowAgents bool `json:"allowAgents,omitempty"`
}
NewJob carries placement only when the person asked for the cloud, so a server that has not learned the field yet still runs local jobs from this CLI.
type NewProject ¶
type Store ¶
type Store interface {
Get(server string) (string, error)
Set(server, token string) error
Delete(server string) error
// Where says where the token lives, for the person reading `gator login`'s answer.
Where() string
}
Store keeps one token per server.
func DefaultStore ¶
DefaultStore is the macOS login keychain where there is one, else a 0600 file beside the config.
type Task ¶
type Task struct {
ID string `json:"id"`
ProjectID string `json:"projectId"`
Kind string `json:"kind"`
Title string `json:"title"`
Description string `json:"description,omitempty"`
Origin string `json:"origin,omitempty"`
OriginSource string `json:"originSource,omitempty"`
AdmittedAt *time.Time `json:"admittedAt,omitempty"`
Phase string `json:"phase"`
Urgency int `json:"urgency"`
OwnerKind string `json:"ownerKind,omitempty"`
OwnerID string `json:"ownerId,omitempty"`
RequirementsChanged bool `json:"requirementsChanged"`
BlockedReason string `json:"blockedReason,omitempty"`
PhaseEnteredAt time.Time `json:"phaseEnteredAt"`
CreatedAt time.Time `json:"createdAt"`
ClosedAt *time.Time `json:"closedAt,omitempty"`
}