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
- func Dial(d Dirs) (net.Conn, error)
- func EnsureToken(path string) (string, error)
- type Control
- type DecideParams
- type DeviceParams
- type Dirs
- type Hello
- type HelloReply
- type HistoryParams
- type Listener
- type NeedInfo
- type PathTooLongError
- type RPCError
- type RunningError
- type Server
- type VirtualParams
Constants ¶
const ( CodeParse = -32700 CodeMethod = -32601 CodeParams = -32602 CodeFailed = -32000 CodeNotTrusted = -32001 )
Error codes.
const ( RoleMCP = "mcp" RoleControl = "control" )
Roles a connection can take.
const ( KindApp = "app" KindDaemon = "daemon" )
What can host a gateway (Server.Kind).
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.
const Protocol = 1
Protocol is the version in the hello line.
Variables ¶
This section is empty.
Functions ¶
func EnsureToken ¶
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 ¶
DialControl connects as a control client.
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 ¶
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 ¶
DefaultDirs returns the directories for the current user.
func (Dirs) LockFile ¶
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) Socket ¶
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.
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.
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 ¶
Listener is the gateway's socket, held together with its 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 ¶
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 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.
type VirtualParams ¶
VirtualParams name a virtual phone: its platform and the id virtual_phones gave it (a Simulator's UDID, an emulator's AVD name).