phone

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 50 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 phone is the gateway `conch web` runs: HTTP and a WebSocket for a phone, in front of the local conch server, which it talks to as a client like the TUI does.

The types in this file mirror the contract in docs/plans/phone-api.md one to one; change that file first when a shape here has to change.

Index

Constants

View Source
const (
	MachineOnline     = "online"
	MachineConnecting = "connecting"
	MachineOffline    = "offline"
)

Machine states, as the phone sees them.

View Source
const (
	PermView  = "view"
	PermReply = "reply"
	PermFull  = "full"
)

Permissions, lowest first. A device with a higher one can do everything a lower one can.

View Source
const (
	CodeBadRequest        = "bad_request"
	CodeUnauthorized      = "unauthorized"
	CodeForbidden         = "forbidden"
	CodeNotFound          = "not_found"
	CodeAgentBlocked      = "agent_blocked"
	CodeNotWaiting        = "not_waiting"
	CodeQuestionChanged   = "question_changed"
	CodeNoChoices         = "no_choices"
	CodePairExpired       = "pair_expired"
	CodeRateLimited       = "rate_limited"
	CodeServerUnavailable = "server_unavailable"
)

Error codes. Clients act on the code; the message is for people.

View Source
const (
	StateWorking = "working"
	StateWaiting = "waiting"
	StateDone    = "done"
	StateIdle    = "idle"
)

Agent states as the phone sees them: the server's "blocked" is sent as "waiting", the word the TUI uses.

View Source
const (
	KindAgent    = "agent"
	KindTerminal = "terminal"
)

Kinds of pane.

View Source
const (
	MsgAgentsWatch = "agents.watch"
	MsgFrameOpen   = "frame.open"
	MsgFrameClose  = "frame.close"
	MsgKeys        = "keys"
	MsgPing        = "ping"
	MsgPanesWatch  = "panes.watch"
	MsgText        = "text"
	MsgScroll      = "scroll"
	MsgResize      = "resize"
	MsgWheel       = "wheel"

	MsgAgents    = "agents"
	MsgAgent     = "agent"
	MsgAgentGone = "agent.gone"
	MsgFrame     = "frame"
	MsgError     = "error"
	MsgPong      = "pong"
	MsgBye       = "bye"

	MsgMachines    = "machines"
	MsgPanes       = "panes"
	MsgPaneChanged = "pane.changed"
	MsgPaneGone    = "pane.gone"
)

Socket message types.

View Source
const (
	ByeRevoked      = "revoked"
	ByeServerGone   = "server_gone"
	ByeShuttingDown = "shutting_down"
)

Reasons a socket is closed for.

View Source
const (
	MinPaneCols, MaxPaneCols = 20, 500
	MinPaneRows, MaxPaneRows = 5, 200
)

Resize bounds. A pane may be made as small as a phone and as large as a wide screen, and no further: a program given a thousand columns draws a thousand columns, and every client watching pays for them.

View Source
const (
	RouteRelay  = "relay"
	RouteDirect = "direct"
)

The routes a phone comes by.

View Source
const APIVersion = 2

APIVersion is what hello reports, so a UI cached from an older build can see that it is out of date. 2 is machines: a pane ID is machine:pane, which is not something an older app can read.

View Source
const CSRFHeader = "X-CSRF-Token"

CSRFHeader carries hello's csrf_token on state-changing requests.

View Source
const CookieName = "conch_device"

CookieName carries the device token.

View Source
const DefaultPort = 8722

DefaultPort is where the gateway listens unless told otherwise.

View Source
const LocalMachine = "local"

LocalMachine is this computer, which is always listed and always first.

View Source
const MaxTries = 3

MaxTries is the most tries a task may be started with from a phone.

View Source
const (
	PairTTL = 5 * time.Minute
)

Pairing codes: how long one lasts, and how many wrong guesses the codes outstanding survive. A code is six digits, so the guesses are what keeps it from being found by trying.

View Source
const PushOverhead = 16 + 4 + 1 + 65 + 1 + 16

PushOverhead is what EncryptPush adds to a payload: the salt, record size and key in the header, the record's delimiter and its tag.

View Source
const SocketPath = "/api/socket"

SocketPath is where the WebSocket is opened.

View Source
const StoreFile = "phone.json"

StoreFile is the file in conch's directory that holds the paired devices.

Variables

View Source
var ErrNoTailscale = errors.New("this machine has no Tailscale address. conch web listens only there, " +
	"so the phone reaches it over your tailnet and nobody else can: start Tailscale, " +
	"or name an address yourself with -listen ADDR")

ErrNoTailscale is a machine with no Tailscale address to listen on.

View Source
var ErrPairExpired = errors.New("that pairing code has expired or was already used; run `conch web pair` for a new one")

ErrPairExpired is a code that is wrong, used, or past its time. Which is not said: a guesser learns nothing from the difference.

Functions

func AppHandler added in v0.2.0

func AppHandler() http.Handler

AppHandler is the phone's app alone, for a relay to serve: the same pages and the same headers as the gateway's, with nothing behind them — a phone opened at a relay reaches its computer through the tunnel.

func ChoiceKeys added in v0.1.9

func ChoiceKeys(screen []string, choice string) ([]string, bool)

ChoiceKeys is choiceKeys for conch's own commands (see ReadQuestion).

func EncryptPush added in v0.2.0

func EncryptPush(payload []byte, keys PushKeys) ([]byte, error)

EncryptPush encrypts payload for one subscription (RFC 8291 aes128gcm, one record) with a key and salt of its own: what the gateway sends a push service, and what a Conch Cloud machine hands the control plane to deliver (cloudagent; PROTOCOL §8). The body is 103 bytes longer than payload.

func GatewayArgs added in v0.1.9

func GatewayArgs(settingsURL string, s *Store) (args []string, ok bool)

GatewayArgs is how conch web is started again: with no flags when the settings say where (it reads them), else as it was last started. ok is false when neither says anything — it has never run here, and nothing says where it should listen.

func Icon added in v0.1.9

func Icon() []byte

Icon is conch's own mark as an SVG, and IconPNG the same at 512 pixels: the app's icon here, the one the settings page draws, and the one `conch app install` puts in the desktop's icon theme. They are read from the files above rather than copied, so conch has one mark and not three that drift apart. A build without them is a build that could not have embedded the app at all, so the error is a panic at first use rather than something every caller has to carry.

func IconPNG added in v0.1.9

func IconPNG() []byte

IconPNG is the icon as a 512-pixel PNG, for the places that cannot draw an SVG (a macOS .icns, built by rescaling it).

func ListenAddr

func ListenAddr(listen string, port int, addrs []net.Addr) (addr, warning string, err error)

ListenAddr decides where the gateway listens. With nothing asked for it is the Tailscale address and only that; listen names another, and comes back with a warning to show, since that is remote access to the machine offered to whoever can reach the address.

func PairLink(base, code string) string

PairLink is where a pairing code is opened: the gateway's page with the code in the fragment, which the browser keeps to itself — it is in no request, so in no log along the way.

func QRLines

func QRLines(text string) ([]string, error)

QRLines draws text as a QR code for a terminal, two modules to a character cell (the upper and lower halves), margin included. Every line is the same width: the code's size plus the margin on each side.

func RelayPairLink(relayPage, code, room string, pub []byte) string

RelayPairLink is where a code is opened when phones reach this computer through a relay: the relay's page, with the room and this computer's key beside the code in the fragment — which the relay never sees, as no browser sends one. The key arriving this way, through the camera, is what keeps the relay out of the session.

func SeenWords added in v0.2.0

func SeenWords(p Presence, now time.Time) string

SeenWords says, short enough for a column, whether a device is on now and how, or when it last was.

func StartGateway added in v0.1.9

func StartGateway(exe string, args []string, start func(*exec.Cmd) error) error

StartGateway starts conch web (exe) with args in the background: its own session, so it outlives whatever started it — the TUI, Conch.app, a shell — and its output in web.log beside the server's. start runs the command; the TUI and tests pass their own. `conch web stop` ends it.

func TailscaleAddr

func TailscaleAddr(addrs []net.Addr) (netip.Addr, bool)

TailscaleAddr picks the machine's Tailscale address out of its interface addresses, IPv4 before IPv6.

func ValidPermission

func ValidPermission(p string) bool

ValidPermission reports whether p names a permission.

Types

type APIError

type APIError struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

APIError is the one shape every error has, over HTTP and the socket.

func (*APIError) Error

func (e *APIError) Error() string

type Agent

type Agent struct {
	Machine   string      `json:"machine"`
	Pane      string      `json:"pane"`
	Name      string      `json:"name"`
	Project   *ProjectRef `json:"project,omitempty"`
	Branch    string      `json:"branch,omitempty"`
	Agent     string      `json:"agent"`
	State     string      `json:"state"`
	Since     time.Time   `json:"since"`
	Title     string      `json:"title,omitempty"`
	CreatedBy string      `json:"created_by,omitempty"`
	CostUSD   float64     `json:"cost_usd,omitempty"`
	Failed    bool        `json:"failed"`
	// Question is there only while State is waiting.
	Question *Question `json:"question,omitempty"`
	// Review is what was said about its branch's diff and not yet handed
	// to it, oldest first: POST /api/review/send hands it over.
	Review []ReviewNote `json:"review,omitempty"`
	// Background is what the agent left running while it is not working
	// — a dev server, a watcher — from a server with agent.background.v1.
	Background []BackgroundJob `json:"background,omitempty"`
}

Agent is one agent, as the list and its updates carry it.

type AgentList

type AgentList struct {
	Agents []Agent `json:"agents"`
}

AgentList is GET /api/agents and the socket's "agents".

type AnswerRequest

type AnswerRequest struct {
	Pane       string `json:"pane"`
	QuestionID string `json:"question_id"`
	Choice     string `json:"choice"`
}

AnswerRequest is POST /api/answer: a choice, and the question it answers.

type AnswerResponse

type AnswerResponse struct {
	Pane string `json:"pane"`
	Sent bool   `json:"sent"`
}

AnswerResponse says the choice's keys went in.

type BackgroundJob added in v0.2.1

type BackgroundJob struct {
	PID     int       `json:"pid,omitempty"`
	Command string    `json:"command,omitempty"`
	Since   time.Time `json:"since,omitzero"`
	Ports   []int     `json:"ports,omitempty"`
}

BackgroundJob is one program an agent left running. A server that counted it without saying what it is leaves all but the count empty.

type Choice

type Choice struct {
	Choice  string `json:"choice"`
	Label   string `json:"label"`
	Default bool   `json:"default,omitempty"`
}

Choice is one answer to a question.

type ClientMessage

type ClientMessage struct {
	Type string   `json:"type"`
	ID   string   `json:"id,omitempty"`
	Pane string   `json:"pane,omitempty"`
	Keys []string `json:"keys,omitempty"`
	Text string   `json:"text,omitempty"`
	// Offset is how many lines back into history a scroll goes; 0 is live.
	Offset int `json:"offset,omitempty"`
	// Direction and Count are a wheel's: up or down, that many steps.
	Direction string `json:"direction,omitempty"`
	Count     int    `json:"count,omitempty"`
	// Cols and Rows resize the pane itself, for a window that can show
	// more than the laptop gave it.
	Cols int `json:"cols,omitempty"`
	Rows int `json:"rows,omitempty"`
}

ClientMessage is what the phone sends on the socket. ID, when given, is repeated by the answer.

type CloseRequest

type CloseRequest struct {
	Pane string `json:"pane"`
}

CloseRequest is POST /api/close.

type CloseResponse

type CloseResponse struct {
	Pane   string `json:"pane"`
	Closed bool   `json:"closed"`
}

CloseResponse says the pane is closed.

type Device

type Device struct {
	ID         string             `json:"id"`
	Name       string             `json:"name"`
	Permission string             `json:"permission"`
	TokenHash  string             `json:"token_hash"`
	Created    time.Time          `json:"created"`
	Push       []PushSubscription `json:"push,omitempty"`
	// Machines are the other machines this device reaches, by catalog ID.
	// Empty means this computer alone, which is what every device paired
	// before the gateway could reach machines has — and what a file
	// written by an older conch loads as. The permission says what a
	// device may do; this says where, and the two are checked together.
	//
	// It is not a convenience. A machine is reached with the person's own
	// credentials and conch cannot tell a test box from a production one,
	// so nobody's phone gains reach because they updated conch: a machine
	// is added to a device on purpose, one at a time.
	Machines []string `json:"machines,omitempty"`
	// Relay is set for a device that paired through a relay: its token
	// was handed over inside the relay's tunnel, and a new relay key
	// (`conch web relay reset`) revokes it along with that key.
	Relay bool `json:"relay,omitempty"`
}

Device is a paired phone. Its token is kept only as a hash: the file alone doesn't let anyone in.

func (Device) Reaches added in v0.1.7

func (d Device) Reaches(machine string) bool

Reaches reports whether this device may be shown, and act on, a machine. This computer is always included; anything else has to have been given.

type ErrorBody

type ErrorBody struct {
	Error *APIError `json:"error"`
}

ErrorBody wraps an APIError as it is sent.

type Frame

type Frame struct {
	Pane      string   `json:"pane"`
	Cols      int      `json:"cols"`
	Rows      int      `json:"rows"`
	Lines     []string `json:"lines"`
	Offset    int      `json:"offset"`
	History   int      `json:"history"`
	AltScreen bool     `json:"alt_screen"`
	// Mouse says the program asked for mouse input: the wheel scrolls its
	// own view (an agent's conversation) rather than the pane's history.
	Mouse bool `json:"mouse"`
}

Frame is a pane's screen as the server renders it: a snapshot, drawn whole each time.

type Gateway

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

Gateway serves a phone: it checks who is asking and what they may do, and turns each request into calls on the local conch server. It connects to that server's socket from outside any pane, so the server doesn't scope it — it acts as the person, and the device's permission is its only limit. Every route and every socket message is checked against it.

func New

func New(store *Store, dial func() (*client.Client, error), logf func(format string, args ...any)) *Gateway

New makes a gateway over the devices in store, reaching the conch server through dial and logging through logf (nil for none). Close it when done.

func (*Gateway) AllowOrigin

func (g *Gateway) AllowOrigin(publicURL string) error

AllowOrigin names the address phones open the gateway at when it isn't the one the gateway sees in Host: `tailscale serve` in front, with its https://….ts.net name. Pages from there are the gateway's own. Call it before serving.

func (*Gateway) Close

func (g *Gateway) Close()

Close says goodbye to every socket and stops the gateway.

func (*Gateway) Handler

func (g *Gateway) Handler() http.Handler

Handler is the gateway's HTTP handler.

type GatewayRun

type GatewayRun struct {
	PID     int       `json:"pid,omitempty"`
	Args    []string  `json:"args"`
	Started time.Time `json:"started"`
}

GatewayRun is a conch web as it was started. PID is 0 once it stopped.

type Hello

type Hello struct {
	APIVersion   int    `json:"api_version"`
	ConchVersion string `json:"conch_version"`
	DeviceID     string `json:"device_id"`
	Permission   string `json:"permission"`
	CSRFToken    string `json:"csrf_token"`
	// Machines is every machine the gateway reaches, local first, so the
	// app can draw them before asking for anything else.
	Machines []Machine `json:"machines"`
}

Hello is GET /api/hello.

type Machine

type Machine struct {
	ID     string `json:"id"`
	Label  string `json:"label"`
	State  string `json:"state"`
	Agents int    `json:"agents"`
	Detail string `json:"detail,omitempty"`
	// Behind says this machine's conch is older than what the app needs,
	// in words for a person: "replies need a newer conch there". A phone
	// shows it beside the machine rather than offering something that
	// will be refused when it is tried. Empty for a machine that can do
	// everything — which is every machine on the same build.
	Behind string `json:"behind,omitempty"`
	// Missing names the capabilities it lacks, for a report rather than
	// for a person (internal/report's rule: facts, not contents).
	Missing []string `json:"missing,omitempty"`
	// Ref is what conch's commands call it in front of a pane — the
	// busybox of `conch read busybox:p3` — which is its label only when
	// no other machine answers to that name, disabled ones and those this
	// device was not given included (remote.RefName); its ID otherwise.
	// Empty for this computer, whose panes need no machine.
	Ref string `json:"ref,omitempty"`
}

Machine is one machine the gateway reaches. Agents counts what the list carries for it, so the app can show a machine with none without counting them itself; Detail says why an offline one is offline, for people.

type MachineList added in v0.1.7

type MachineList struct {
	Machines []Machine `json:"machines"`
}

MachineList is GET /api/machines and the socket's "machines".

type NewPaneRequest

type NewPaneRequest struct {
	Kind string `json:"kind"`
	// Machine is where to start it; "" is this computer. A project ID is
	// that machine's own.
	Machine string `json:"machine,omitempty"`
	Project string `json:"project,omitempty"`
	Agent   string `json:"agent,omitempty"`
	Name    string `json:"name,omitempty"`
	Prompt  string `json:"prompt,omitempty"`
}

NewPaneRequest is POST /api/panes: a terminal, or an agent with an optional first message, in a project's folder or the home folder.

type NewPaneResponse

type NewPaneResponse struct {
	Pane string `json:"pane"`
}

NewPaneResponse is the pane started.

type PairRequest

type PairRequest struct {
	Code       string `json:"code"`
	DeviceName string `json:"device_name"`
	// Name is taken for DeviceName when that is not given: a client
	// written by hand sends "name", and was listed as "phone" (#199).
	Name string `json:"name,omitempty"`
}

PairRequest is POST /pair.

type PairResponse

type PairResponse struct {
	DeviceID   string `json:"device_id"`
	Permission string `json:"permission"`
}

PairResponse answers it, along with the cookie.

type Pane

type Pane struct {
	Agent
	Kind string `json:"kind"`
	Cwd  string `json:"cwd,omitempty"`
}

Pane is any pane, an agent's or a plain terminal's: the Agent object with its kind and directory. A terminal's agent is "", its state idle, and since is when it started.

type PaneList

type PaneList struct {
	Panes []Pane `json:"panes"`
}

PaneList is GET /api/panes and the socket's "panes".

type Presence added in v0.2.0

type Presence struct {
	Connected bool
	Route     string
	Since     time.Time
	LastSeen  time.Time
}

Presence is a device as it is now: connected only while the conch web that said so still runs.

type Project

type Project struct {
	ID   string `json:"id"`
	Name string `json:"name"`
	Path string `json:"path"`
	Base string `json:"base,omitempty"`
}

Project is a project a task can be started in.

type ProjectList

type ProjectList struct {
	Projects []Project `json:"projects"`
}

ProjectList is GET /api/projects.

type ProjectRef

type ProjectRef struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

ProjectRef is the project an agent works in.

type PushKey

type PushKey struct {
	VAPIDPublicKey string `json:"vapid_public_key"`
}

PushKey is GET /api/push/key.

type PushKeys

type PushKeys struct {
	P256dh string `json:"p256dh"`
	Auth   string `json:"auth"`
}

PushKeys are a push subscription's keys, as the browser gives them.

type PushMessage

type PushMessage struct {
	Type    string `json:"type"` // waiting or done
	Pane    string `json:"pane"`
	Name    string `json:"name"`
	Project string `json:"project,omitempty"`
	URL     string `json:"url"`
	// Running is how many things the agent left running, never what.
	Running int `json:"running,omitempty"`
}

PushMessage is what a notification carries: deliberately little, since it passes through Apple's or Google's servers and a question can quote a command. No screen text and no question text.

type PushSubscription

type PushSubscription struct {
	Endpoint string   `json:"endpoint"`
	Keys     PushKeys `json:"keys"`
	On       []string `json:"on,omitempty"`
}

PushSubscription is POST /api/push/subscribe; DELETE names the endpoint alone.

type Question

type Question struct {
	ID      string   `json:"id"`
	Text    string   `json:"text"`
	Choices []Choice `json:"choices"`
}

Question is what a waiting agent asks. Choices is empty when they couldn't be read off the screen; the phone then offers only the terminal.

func ReadQuestion added in v0.1.9

func ReadQuestion(p proto.PaneInfo, screen []string) *Question

ReadQuestion is readQuestion for conch's own commands: the Mac app answers a waiting agent from its card through `conch agent question` and `conch agent answer`, and reads a menu exactly as the phone does.

type RelayKeys added in v0.2.0

type RelayKeys struct {
	Secret string `json:"secret"`
	Key    string `json:"key"`
}

RelayKeys are a gateway's on a relay: the room's secret, and the private half of the key phones check it by.

type RelayPair added in v0.2.0

type RelayPair struct {
	Link, Page, Words string
	Connected         bool
}

RelayPair is what pairing through a relay needs said: the link the QR code carries, the relay's page it opens, the key's words, and whether conch web is connected to that relay with this key now.

type RelayState added in v0.2.0

type RelayState struct {
	URL string `json:"url"`
	// Room is the room it holds, which says which key it was started with.
	Room      string    `json:"room,omitempty"`
	PID       int       `json:"pid"`
	Connected bool      `json:"connected"`
	Error     string    `json:"error,omitempty"`
	Since     time.Time `json:"since"`
}

RelayState is a gateway's link to its relay as it last was.

type RenameRequest

type RenameRequest struct {
	Pane string `json:"pane"`
	Name string `json:"name"`
}

RenameRequest is POST /api/rename, and its response.

type ReplyRequest

type ReplyRequest struct {
	Pane string `json:"pane"`
	Text string `json:"text"`
}

ReplyRequest is POST /api/reply.

type ReplyResponse

type ReplyResponse struct {
	Pane  string `json:"pane"`
	Agent string `json:"agent"`
	Turn  int    `json:"turn"`
}

ReplyResponse says which turn of the agent answers the reply.

type ReviewNote added in v0.1.9

type ReviewNote struct {
	ID       string        `json:"id"`
	Where    string        `json:"where"`
	Note     string        `json:"note"`
	By       string        `json:"by,omitempty"`
	GitHub   bool          `json:"github,omitempty"`
	URL      string        `json:"url,omitempty"`
	Outdated bool          `json:"outdated,omitempty"`
	Replies  []ReviewReply `json:"replies,omitempty"`
}

ReviewNote is one comment on an agent's branch, written in the TUI's changes view, from the command line or by a reviewing agent, or on the branch's pull request (GitHub: By is the reviewer, URL the comment, Replies the rest of its thread, Outdated that its lines have changed). Where is the file and the line or hunk it is about, for people.

type ReviewReply added in v0.1.9

type ReviewReply struct {
	By   string `json:"by,omitempty"`
	Note string `json:"note"`
}

ReviewReply is a later comment in a pull request's thread.

type ReviewSendRequest added in v0.1.9

type ReviewSendRequest struct {
	Pane string `json:"pane"`
}

ReviewSendRequest is POST /api/review/send: hand the comments on the pane's branch to the agent in it.

type ReviewSendResponse added in v0.1.9

type ReviewSendResponse struct {
	Pane  string `json:"pane"`
	Agent string `json:"agent"`
	Sent  int    `json:"sent"`
	Turn  int    `json:"turn"`
}

ReviewSendResponse says how many went, and which turn answers them.

type Seen added in v0.2.0

type Seen struct {
	Sockets  int       `json:"sockets,omitempty"`
	Route    string    `json:"route,omitempty"`
	Since    time.Time `json:"since,omitempty"`
	LastSeen time.Time `json:"last_seen"`
}

Seen is a device's presence: its open sockets, the route the last came by, and when it was last there.

type ServerMessage

type ServerMessage struct {
	Type     string     `json:"type"`
	ID       string     `json:"id,omitempty"`
	Agents   *[]Agent   `json:"agents,omitempty"`
	Machines *[]Machine `json:"machines,omitempty"`
	Panes    *[]Pane    `json:"panes,omitempty"`
	Info     *Pane      `json:"info,omitempty"`
	Agent    *Agent     `json:"agent,omitempty"`
	Pane     string     `json:"pane,omitempty"`
	Frame    *Frame     `json:"frame,omitempty"`
	Error    *APIError  `json:"error,omitempty"`
	Reason   string     `json:"reason,omitempty"`
}

ServerMessage is what the gateway sends on the socket; Type says which of the other fields are there.

type Store

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

Store reads and writes the devices file.

func OpenStore

func OpenStore(dir string) *Store

OpenStore is the store in conch's directory dir. Nothing is read or created until it is used.

func (*Store) Called added in v0.2.1

func (s *Store) Called(pid int, id, route string, now time.Time) error

Called records a device's call: it was there now, though no socket of its may be open.

func (*Store) Devices

func (s *Store) Devices() ([]Device, error)

Devices lists the paired devices, oldest first.

func (*Store) Gateway

func (s *Store) Gateway() (GatewayRun, bool)

Gateway is the last conch web's record, and whether its process is still there.

func (*Store) GatewayStarted

func (s *Store) GatewayStarted(pid int, args []string, now time.Time) error

GatewayStarted records a conch web now serving, as process pid with args.

func (*Store) GatewayStopped

func (s *Store) GatewayStopped(pid int) error

GatewayStopped records that conch web pid has stopped, keeping how it was started. A newer gateway's record is left alone.

func (*Store) NewCode

func (s *Store) NewCode(permission string, now time.Time, machines ...string) (string, error)

NewCode issues a one-time pairing code for a device with permission, good for PairTTL. It replaces any code still outstanding: one pairing at a time.

func (*Store) Path

func (s *Store) Path() string

Path is the file the store keeps.

func (*Store) Presence added in v0.2.0

func (s *Store) Presence() map[string]Presence

Presence is every paired device's presence, by device ID. A device never seen is absent; one is connected only while its socket is open in a conch web that still runs.

func (*Store) Redeem

func (s *Store) Redeem(code, name string, now time.Time) (Device, string, error)

Redeem exchanges a pairing code for a new device and its token. The code is spent whether or not anything after it goes wrong, and a wrong one counts against every code outstanding.

func (*Store) RedeemVia added in v0.2.0

func (s *Store) RedeemVia(code, name string, now time.Time, viaRelay bool) (Device, string, error)

RedeemVia is Redeem, saying whether the device paired through a relay.

func (*Store) Relay added in v0.2.0

func (s *Store) Relay() (secret string, key noise.DHKey, err error)

Relay is this computer's relay room and key, made and kept the first time it is asked for.

func (*Store) RelayPairing added in v0.2.0

func (s *Store) RelayPairing(relayURL, code string) (RelayPair, error)

RelayPairing is the pairing for code through relayURL ("" gives none).

func (*Store) RelayState added in v0.2.0

func (s *Store) RelayState() (RelayState, bool)

RelayState is conch web's link to its relay as last recorded, if that conch web is still running.

func (*Store) RelayURL added in v0.2.0

func (s *Store) RelayURL(configured string) string

RelayURL is the relay phones reach this computer through: the one in the settings, else the one a running conch web was started with (`conch web -relay`). "" is none.

func (*Store) Rename added in v0.2.0

func (s *Store) Rename(id, name string) (string, bool, error)

SetPermission changes what a paired device may do, and reports whether there was one. A running gateway reads it on the device's next request or socket message; nothing has to be paired again. Rename gives a device a name of its own: every phone pairs as what its browser says it is ("iPhone"), so two of them could not be told apart in a list. The name is cleaned as a paired one is; one with nothing left is refused rather than quietly called "phone".

func (*Store) ResetRelay added in v0.2.0

func (s *Store) ResetRelay() (revoked int, err error)

ResetRelay forgets the relay room and key and revokes every device that paired through a relay, which it says how many of: those phones pair again, and nothing that saw the old key, the room or a token handed over in it can use them.

func (*Store) Revoke

func (s *Store) Revoke(id string) (bool, error)

Revoke removes a device and reports whether there was one. Its token stops working at once, and a running gateway closes its sockets.

func (*Store) SetMachines added in v0.1.7

func (s *Store) SetMachines(id string, machines []string) (bool, error)

SetMachines says which other machines a device reaches, replacing what it had; none leaves it with this computer alone. A running gateway takes it from the device's next request or socket message, so a machine taken away stops being served at once rather than at the end of a session.

An ID is checked for the shape the catalog gives one, not for being in the catalog: a machine may be added after the device that is to reach it, and a machine the catalog has lost is refused by the gateway anyway — as a machine that is merely off is.

func (*Store) SetPermission

func (s *Store) SetPermission(id, permission string) (bool, error)

func (*Store) SetRelayState added in v0.2.0

func (s *Store) SetRelayState(rs *RelayState) error

SetRelayState records conch web's link to its relay.

func (*Store) SetURL

func (s *Store) SetURL(url string) error

SetURL records where the gateway listens.

func (*Store) SocketClosed added in v0.2.0

func (s *Store) SocketClosed(pid int, id string, now time.Time) error

SocketClosed records a device's socket closing.

func (*Store) SocketOpened added in v0.2.0

func (s *Store) SocketOpened(pid int, id, route string, now time.Time) error

SocketOpened records a device's socket opening, by route, for conch web running as pid.

func (*Store) Subscribe

func (s *Store) Subscribe(deviceID string, sub PushSubscription) error

Subscribe keeps a device's push subscription, replacing the one it had for the same endpoint.

func (*Store) URL

func (s *Store) URL() string

URL is where the gateway last listened, or "".

func (*Store) Unsubscribe

func (s *Store) Unsubscribe(deviceID, endpoint string) error

Unsubscribe drops a device's subscription for endpoint, if it has one.

func (*Store) VAPIDKey

func (s *Store) VAPIDKey() (*ecdh.PrivateKey, error)

VAPIDKey is the key pushes are signed with. It is made the first time it is asked for and kept, so subscriptions made against it go on working.

func (*Store) VAPIDPublicKey

func (s *Store) VAPIDPublicKey() (string, error)

VAPIDPublicKey is the key a phone subscribes to pushes with, as browsers want it: the uncompressed P-256 point, base64url.

type TaskRequest

type TaskRequest struct {
	Machine string `json:"machine,omitempty"`
	Project string `json:"project"`
	Agent   string `json:"agent,omitempty"`
	Name    string `json:"name,omitempty"`
	Prompt  string `json:"prompt"`
	// Tries starts the same task more than once, each on a branch of its
	// own, to keep the best: what `conch task -n` does. 0 and 1 are one.
	Tries int `json:"tries,omitempty"`
}

TaskRequest is POST /api/task. Machine is where to start it; "" is this computer, and the project is that machine's own..

type TaskResponse

type TaskResponse struct {
	Pane     string   `json:"pane"`
	Worktree string   `json:"worktree,omitempty"`
	Branch   string   `json:"branch,omitempty"`
	Panes    []string `json:"panes,omitempty"`
	Failed   string   `json:"failed,omitempty"`
}

TaskResponse is the pane the task started in. With tries, Pane is the first, and Panes every one in order. Failed says why a later try did not start, when an earlier one did: those run on, so the answer is what started rather than an error that would leave them unseen.

Jump to

Keyboard shortcuts

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