cli

package
v0.0.0-...-8d4c08b Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 27 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 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

Constants

This section is empty.

Variables

View Source
var ErrNoToken = errors.New("no stored token")

ErrNoToken means nothing is stored for the server.

Functions

func ConfigDir

func ConfigDir(getenv func(string) string) string

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

func NormalizeServer(s string) (string, error)

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 Run

func Run(ctx context.Context, env *Env, args []string) int

Run executes one command line and returns the exit code.

func SaveConfig

func SaveConfig(dir string, c Config) error

SaveConfig writes the config atomically, readable by its owner only.

Types

type APIError

type APIError struct {
	Status  int
	Message string
	Code    string
}

APIError is an answer outside 2xx, with the server's own message.

func (*APIError) Error

func (e *APIError) Error() string

type AuthConfig

type AuthConfig struct {
	OIDC     bool   `json:"oidc"`
	Provider string `json:"provider"`
}

AuthConfig says whether the server offers sign-in through a provider, and which.

type Check

type Check struct {
	Name   string `json:"name"`
	Source string `json:"source"`
	Status string `json:"status"`
	Detail string `json:"detail,omitempty"`
}

type Client

type Client struct {
	Base  string
	Token string
	HTTP  *http.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) Advance

func (c *Client) Advance(ctx context.Context, id, reason string) (Task, error)

func (*Client) Approve

func (c *Client) Approve(ctx context.Context, id string) (Task, error)

func (*Client) AuthConfig

func (c *Client) AuthConfig(ctx context.Context) (AuthConfig, error)

func (*Client) CreateJob

func (c *Client) CreateJob(ctx context.Context, taskID string, in NewJob) (Job, error)

func (*Client) CreateProject

func (c *Client) CreateProject(ctx context.Context, in NewProject) (Project, error)

func (*Client) CreateTask

func (c *Client) CreateTask(ctx context.Context, projectID string, in NewTask) (Task, error)

func (*Client) ExchangeCode

func (c *Client) ExchangeCode(ctx context.Context, in tokenRequest) (tokenResponse, error)

func (*Client) Job

func (c *Client) Job(ctx context.Context, id string) (Job, error)

func (*Client) JobEvents

func (c *Client) JobEvents(ctx context.Context, jobID string, after int64) ([]JobEvent, error)

JobEvents returns stored output after seq, at most 1000 at a time (the contract's limit).

func (*Client) Logout

func (c *Client) Logout(ctx context.Context) error

func (*Client) Me

func (c *Client) Me(ctx context.Context) (Me, error)

func (*Client) Projects

func (c *Client) Projects(ctx context.Context) ([]Project, error)

func (*Client) Task

func (c *Client) Task(ctx context.Context, id string) (TaskDetail, error)

func (*Client) TaskJobs

func (c *Client) TaskJobs(ctx context.Context, taskID string) ([]Job, error)

func (*Client) Tasks

func (c *Client) Tasks(ctx context.Context, projectID string) ([]Task, error)

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

func LoadConfig(dir string) (Config, error)

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).

func (FileStore) Delete

func (f FileStore) Delete(server string) error

func (FileStore) Get

func (f FileStore) Get(server string) (string, error)

func (FileStore) Set

func (f FileStore) Set(server, token string) error

func (FileStore) Where

func (f FileStore) Where() string

type Gate

type Gate struct {
	Phase         string  `json:"phase"`
	Kind          string  `json:"kind"`
	Checks        []Check `json:"checks"`
	HumanApproved bool    `json:"humanApproved"`
	BlockedReason string  `json:"blockedReason,omitempty"`
	BlockedBy     string  `json:"blockedBy,omitempty"`
}

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"`
}

func (Job) Finished

func (j Job) Finished() bool

Finished reports whether the job will produce no more output.

type JobEvent

type JobEvent struct {
	Seq     int64          `json:"seq"`
	Type    string         `json:"type"`
	At      time.Time      `json:"at"`
	Payload map[string]any `json:"payload"`
}

type Me

type Me struct {
	Kind          string `json:"kind"`
	UserID        string `json:"userId,omitempty"`
	Name          string `json:"name"`
	WorkspaceRole string `json:"workspaceRole"`
	Scope         string `json:"scope,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 NewProject struct {
	Slug          string  `json:"slug"`
	Name          string  `json:"name"`
	RepoURL       *string `json:"repoUrl,omitempty"`
	DefaultBranch *string `json:"defaultBranch,omitempty"`
}

type NewTask

type NewTask struct {
	Kind        string `json:"kind"`
	Title       string `json:"title"`
	Description string `json:"description,omitempty"`
	Urgency     int    `json:"urgency,omitempty"`
}

type Project

type Project struct {
	ID         string     `json:"id"`
	Slug       string     `json:"slug"`
	Name       string     `json:"name"`
	Tags       []string   `json:"tags"`
	CreatedAt  time.Time  `json:"createdAt"`
	ArchivedAt *time.Time `json:"archivedAt,omitempty"`
	Role       string     `json:"role,omitempty"`
}

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

func DefaultStore(dir string) Store

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"`
}

type TaskDetail

type TaskDetail struct {
	Task
	Gate   Gate     `json:"gate"`
	Phases []string `json:"phases"`
}

Jump to

Keyboard shortcuts

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