api

package
v0.0.0-...-a60c815 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: Apache-2.0 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 api is the gateway's local API: a Unix socket (a named pipe on Windows) that only the current user can reach. Each connection starts with a one-line hello that picks its role:

  • "mcp": the rest of the connection is an MCP session (newline-delimited JSON-RPC), served by the gateway's MCP server. `pinky mcp` is a thin stdio shim that forwards to it. It must present the agent token.
  • "control": JSON-RPC 2.0 for clients such as `pinky devices`. It can read devices, tasks, needs and history, and stop. Approving, handing back and unlocking need the in-process UI or a client that proves user presence, so the socket refuses them (except for a gateway that runs only fake devices, for tests).

A lock file in the data folder keeps a second gateway for the same user from starting.

Index

Constants

View Source
const (
	CodeParse      = -32700
	CodeMethod     = -32601
	CodeParams     = -32602
	CodeFailed     = -32000
	CodeNotTrusted = -32001
)

Error codes.

View Source
const (
	RoleMCP     = "mcp"
	RoleControl = "control"
)

Roles a connection can take.

View Source
const (
	KindApp    = "app"
	KindDaemon = "daemon"
)

What can host a gateway (Server.Kind).

View Source
const HomeEnv = "PINKY_HOME"

HomeEnv overrides every directory with one base folder, for tests and side-by-side gateways: $PINKY_HOME/config, /data and /run.

View Source
const Protocol = 1

Protocol is the version in the hello line.

Variables

This section is empty.

Functions

func Dial

func Dial(d Dirs) (net.Conn, error)

Dial connects to the gateway's socket.

func EnsureToken

func EnsureToken(path string) (string, error)

EnsureToken returns the agent token, creating it (mode 0600) when missing. The gateway and agents' `pinky mcp` may call it at the same time on a first run, so the file appears with its whole token at once, and every caller gets the same one.

Types

type Control

type Control struct {
	Reply HelloReply
	// contains filtered or unexported fields
}

Control is a control client.

func DialControl

func DialControl(d Dirs) (*Control, error)

DialControl connects as a control client.

func (*Control) Call

func (c *Control) Call(method string, params, out any) error

Call runs one method and decodes its result into out, which may be nil. Notifications that arrive meanwhile are skipped.

func (*Control) Close

func (c *Control) Close() error

Close closes the connection.

type DecideParams

type DecideParams struct {
	Need     string           `json:"need"`
	Decision gateway.Decision `json:"decision"`
	Note     string           `json:"note,omitempty"`
}

DecideParams answer a need.

type DeviceParams

type DeviceParams struct {
	Device string `json:"device"`
	Note   string `json:"note,omitempty"`
}

DeviceParams name a device.

type Dirs

type Dirs struct {
	Config string // rules, app table, agent token
	Data   string // history database, media, daemon log
	Run    string // socket
}

Dirs are Pinky's per-user directories.

func DefaultDirs

func DefaultDirs() (Dirs, error)

DefaultDirs returns the directories for the current user.

func (Dirs) Apps

func (d Dirs) Apps() string

Apps is the app category overrides file.

func (Dirs) DaemonLog

func (d Dirs) DaemonLog() string

DaemonLog is where a daemon started by `pinky mcp` writes.

func (Dirs) Ensure

func (d Dirs) Ensure() error

Ensure creates the directories, private to the user.

func (Dirs) LockFile

func (d Dirs) LockFile() string

LockFile keeps one gateway per data folder. It lives with the data, not with the socket: a runtime folder can differ between starts (logind removes /run/user/<uid> at logout; a service may not have XDG_RUNTIME_DIR), and two gateways must not share one history and the same phones.

func (Dirs) Rules

func (d Dirs) Rules() string

Rules is the policy rules file.

func (Dirs) Socket

func (d Dirs) Socket() string

Socket is where the gateway listens: a Unix socket in the runtime folder, or on Windows a named pipe named after that folder. Packaged (MSIX) apps on Windows, such as the Claude and Codex desktop apps, see a virtualized copy of AppData, so the agents they start cannot reach a socket file there; named pipes are not virtualized.

func (Dirs) TokenFile

func (d Dirs) TokenFile() string

TokenFile holds the agent token, readable only by the user.

type Hello

type Hello struct {
	Pinky int    `json:"pinky"`
	Role  string `json:"role"`
	Token string `json:"token,omitempty"`
}

Hello is the first line a client sends.

type HelloReply

type HelloReply struct {
	OK      bool   `json:"ok"`
	Error   string `json:"error,omitempty"`
	Version string `json:"version,omitempty"`
	Trusted bool   `json:"trusted,omitempty"`
}

HelloReply is the server's answer to Hello.

func Greet

func Greet(c net.Conn, h Hello) (*bufio.Reader, HelloReply, error)

Greet sends the hello line and reads the reply. It returns a reader that holds whatever the server sent after the reply.

type HistoryParams

type HistoryParams struct {
	Search string    `json:"search,omitempty"`
	Before time.Time `json:"before,omitempty"`
	Limit  int       `json:"limit,omitempty"`
}

HistoryParams filter Activity.

type Listener

type Listener struct {
	net.Listener
	// contains filtered or unexported fields
}

Listener is the gateway's socket, held together with its lock.

func Listen

func Listen(d Dirs) (*Listener, error)

Listen takes the per-user lock and listens on the socket.

func (*Listener) Close

func (l *Listener) Close() error

Close stops listening, removes the socket and releases the lock.

type NeedInfo

type NeedInfo struct {
	ID            string
	Kind          gateway.NeedKind
	DeviceID      string
	DeviceName    string
	App           string
	Agent         string
	TaskID        string
	Title         string
	Detail        string
	Rule          string
	Created       time.Time
	Deadline      time.Time
	HasScreenshot bool
	Target        screen.Rect
}

NeedInfo is a NeedView without its screenshot, for the socket.

type PathTooLongError

type PathTooLongError struct {
	Path  string
	Limit int
}

PathTooLongError means the socket path does not fit in a Unix socket address, which the system reports only as "invalid argument".

func (*PathTooLongError) Error

func (e *PathTooLongError) Error() string

type RPCError

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

RPCError is a JSON-RPC error.

func (*RPCError) Error

func (e *RPCError) Error() string

type RunningError

type RunningError struct{ PID string }

RunningError means another gateway already runs for this user.

func (*RunningError) Error

func (e *RunningError) Error() string

type Server

type Server struct {
	Gateway *gateway.Gateway
	MCP     *mcp.Server
	// Token is the agent token MCP connections must present.
	Token string
	// Trusted lets control clients approve, hand back and unlock. Set it only
	// when every device is fake: a process on the socket cannot prove that a
	// person is there.
	Trusted bool
	Version string
	Log     *slog.Logger
	// Quit, when set, ends the process that hosts the gateway: `pinky quit`
	// calls it over the socket. Windows has no signal to end a daemon, and
	// scripts use it to end the app.
	Quit func()
	// Kind says what hosts the gateway, KindApp or KindDaemon; the version
	// method reports it, so that the app can take over from a daemon.
	Kind string
	// Show, when set, brings the app's window to the front: the show method
	// calls it when the person opens Pinky while it already runs.
	Show func()
	// contains filtered or unexported fields
}

Server answers connections on the socket.

func (*Server) Serve

func (s *Server) Serve(ctx context.Context, ln net.Listener) error

Serve accepts connections until ctx ends, then waits for them to finish. It closes ln, and ln is closed by the time Serve returns: for a Listener the socket is gone and the lock is free, so a gateway can start again at once.

type VirtualParams

type VirtualParams struct {
	Platform driver.Platform `json:"platform"`
	ID       string          `json:"id"`
}

VirtualParams name a virtual phone: its platform and the id virtual_phones gave it (a Simulator's UDID, an emulator's AVD name).

Jump to

Keyboard shortcuts

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