Documentation
¶
Overview ¶
Package wire is the Go binding of the silkd wire protocol, shared by the SDK and sandboxd: newline-delimited JSON frames over one connection per RPC, requests tagged by "op", responses by "type", binary payloads base64 in data fields. The authoritative contract is the shared corpus in protocol/wire/fixtures/v1 — silkd's Rust tests and this package's tests round-trip the same files.
Index ¶
- Constants
- func AppendBulkRequest(buf []byte, op string, data []byte) []byte
- func EncodeRequest(r Request) ([]byte, error)
- func EncodeResponse(r Response) ([]byte, error)
- func NewFrameScanner(r io.Reader) *bufio.Scanner
- type Attach
- type B64
- type Data
- type DataEnd
- type DataResp
- type DirEntry
- type Done
- type Entries
- type ErrorResp
- type Event
- type Exec
- type Exit
- type FileInfo
- type FsFind
- type FsList
- type FsMkdir
- type FsPull
- type FsPush
- type FsRead
- type FsRename
- type FsReplace
- type FsRm
- type FsStat
- type FsWatch
- type FsWrite
- type GitAdd
- type GitBranch
- type GitBranches
- type GitClone
- type GitCommit
- type GitCommitResult
- type GitFileStatus
- type GitPull
- type GitPush
- type GitStatus
- type GitStatusResult
- type Info
- type InfoResp
- type Kill
- type Logs
- type LspRequest
- type LspStart
- type LspStarted
- type LspStop
- type Match
- type PortForward
- type ProcInfo
- type Procs
- type Ps
- type PtyOpen
- type PtyResize
- type Ready
- type Replaced
- type Request
- type Response
- type SessionCreate
- type SessionCreated
- type SessionList
- type SessionRm
- type Sessions
- type Started
- type Stat
- type Stderr
- type Stdin
- type StdinClose
- type Stdout
Constants ¶
const ( // ProtoVersion is stamped into every request as "v"; silkd ignores // unknown fields, which is the forward-compatibility story. ProtoVersion = 1 // MaxFrame mirrors silkd's frame cap. MaxFrame = 8 << 20 // GitBranch.Action values (silkd's GitBranchOp). BranchList = "list" BranchCreate = "create" BranchDelete = "delete" BranchCheckout = "checkout" // ErrorResp.Kind values (silkd's ErrorKind). KindBadRequest = "bad_request" KindNotFound = "not_found" KindUnimplemented = "unimplemented" KindInternal = "internal" // Event.Kind values (silkd's EventKind). EventCreated = "created" EventModified = "modified" EventDeleted = "deleted" EventRenamed = "renamed" // DirEntry.Kind and FileInfo.Kind values (silkd's FileKind). FileKindFile = "file" FileKindDir = "dir" FileKindSymlink = "symlink" FileKindOther = "other" )
Variables ¶
This section is empty.
Functions ¶
func AppendBulkRequest ¶
AppendBulkRequest renders a data-carrying request frame — {"v":1,"op":<op>,"data":"<base64>"} plus newline — into buf, reused across calls on the bulk send paths (base64's alphabet needs no JSON escaping).
func EncodeRequest ¶
EncodeRequest renders {"v":1,"op":...,fields} without a trailing newline.
func EncodeResponse ¶
EncodeResponse renders {"type":...,fields} without a trailing newline.
Types ¶
type Attach ¶
type Attach struct {
PID uint32 `json:"pid"`
}
Attach streams a running process's buffered and live output.
type B64 ¶
type B64 []byte
B64 carries request payload bytes. It exists because silkd's deserializer requires a base64 string and rejects null — which is exactly what encoding/json emits for a nil []byte. Decoding needs no counterpart: []byte-kinded types already base64-decode by default.
func (B64) MarshalJSON ¶
type Data ¶
type Data struct {
Data B64 `json:"data"`
}
Data carries one chunk of an upload stream (FsWrite/FsPush payloads).
type DataResp ¶
type DataResp struct {
Data []byte `json:"data"`
}
DataResp carries one chunk of a download stream (FsRead/FsPull payloads).
type DirEntry ¶
type DirEntry struct {
Name string `json:"name"`
Kind string `json:"kind"`
Size uint64 `json:"size"`
}
DirEntry is one entry of Entries; Kind is one of the FileKind* consts.
type Exec ¶
type Exec struct {
Argv []string `json:"argv"`
Cwd string `json:"cwd,omitempty"`
Env map[string]string `json:"env,omitempty"`
User string `json:"user,omitempty"`
Detach bool `json:"detach"`
Session string `json:"session,omitempty"`
}
Exec starts a process; with Session set it runs inside that persistent shell instead. Detach is emitted even when false — it is part of the fixture corpus shape.
type Exit ¶
type Exit struct {
Code int32 `json:"code"`
}
Exit is the terminal frame of a foreground exec; -1 means killed or unknown.
type FileInfo ¶
type FileInfo struct {
Kind string `json:"kind"`
Size uint64 `json:"size"`
Mode uint32 `json:"mode"`
MtimeEpochSecs uint64 `json:"mtime_epoch_secs"`
}
FileInfo is the Stat payload; Mode carries permission bits only.
type FsFind ¶
type FsFind struct {
Path string `json:"path"`
Pattern string `json:"pattern"`
Glob string `json:"glob,omitempty"`
}
FsFind streams Match frames for lines under Path matching Pattern; Glob narrows the walk to file names matching it (`*` and `?` wildcards).
type FsList ¶
type FsList struct {
Path string `json:"path"`
}
FsList streams a directory as batched Entries frames terminated by Done.
type FsPull ¶
type FsPull struct {
Path string `json:"path"`
}
FsPull streams a path back as a tar stream (Data frames, then Done).
type FsPush ¶
type FsPush struct {
Dest string `json:"dest"`
}
FsPush extracts a client tar stream (Data frames) under dest.
type FsRead ¶
type FsRead struct {
Path string `json:"path"`
}
FsRead streams a file back as Data frames terminated by Done.
type FsReplace ¶
type FsReplace struct {
Files []string `json:"files"`
Pattern string `json:"pattern"`
Replacement string `json:"replacement"`
}
FsReplace rewrites Pattern to Replacement in each file, streaming one Replaced frame per file then Done.
type GitBranch ¶
type GitBranch struct {
Path string `json:"path"`
Action string `json:"action"`
Name string `json:"name,omitempty"`
}
GitBranch lists, creates, deletes, or checks out a branch. Action is list|create|delete|checkout ("op" is reserved by the frame tag).
type GitBranches ¶
GitBranches answers GitBranch list.
func (GitBranches) RespType ¶
func (GitBranches) RespType() string
type GitClone ¶
type GitClone struct {
URL string `json:"url"`
Path string `json:"path"`
Branch string `json:"branch,omitempty"`
Depth uint32 `json:"depth,omitempty"`
Auth string `json:"auth,omitempty"`
}
GitClone clones a repo; network-lane only. Auth is a token passed as an in-memory Authorization header, never written to guest disk.
type GitCommit ¶
type GitCommit struct {
Path string `json:"path"`
Message string `json:"message"`
Author string `json:"author"`
}
GitCommit commits staged changes; Author is "Name <email>".
type GitCommitResult ¶
type GitCommitResult struct {
Hash string `json:"hash"`
}
GitCommitResult answers GitCommit with the new commit hash.
func (GitCommitResult) RespType ¶
func (GitCommitResult) RespType() string
type GitFileStatus ¶
type GitFileStatus struct {
Path string `json:"path"`
Staged string `json:"staged"`
Unstaged string `json:"unstaged"`
}
GitFileStatus is one porcelain-v2 entry; Staged/Unstaged are XY status codes.
type GitStatus ¶
type GitStatus struct {
Path string `json:"path"`
}
GitStatus asks for a repo's structured status.
type GitStatusResult ¶
type GitStatusResult struct {
Branch string `json:"branch"`
Ahead uint32 `json:"ahead"`
Behind uint32 `json:"behind"`
Files []GitFileStatus `json:"files"`
}
GitStatusResult answers GitStatus.
func (GitStatusResult) RespType ¶
func (GitStatusResult) RespType() string
type Info ¶
type Info struct{}
Info asks for the daemon's identity and counters — the readiness probe.
type InfoResp ¶
type InfoResp struct {
Version string `json:"version"`
Proto uint32 `json:"proto"`
UptimeSecs uint64 `json:"uptime_secs"`
Procs int `json:"procs"`
Sessions int `json:"sessions"`
}
InfoResp answers Info.
type Logs ¶
type Logs struct {
PID uint32 `json:"pid"`
}
Logs returns a process's ring-buffered output.
type LspRequest ¶
type LspRequest struct {
ServerID string `json:"server_id"`
}
LspRequest opens the JSON-RPC byte stream to a started language server.
func (LspRequest) Op ¶
func (LspRequest) Op() string
type LspStarted ¶
type LspStarted struct {
ServerID string `json:"server_id"`
}
LspStarted answers LspStart.
func (LspStarted) RespType ¶
func (LspStarted) RespType() string
type LspStop ¶
type LspStop struct {
ServerID string `json:"server_id"`
}
LspStop kills a started language server.
type Match ¶
type Match struct {
File string `json:"file"`
Line uint64 `json:"line"`
Content string `json:"content"`
}
Match is one FsFind hit; Line is 1-based.
type PortForward ¶
type PortForward struct {
Port uint16 `json:"port"`
}
PortForward relays a guest TCP port over this connection: Ready once connected, then Data both ways (DataEnd half-closes the guest socket); the guest server closing ends the stream with Done.
func (PortForward) Op ¶
func (PortForward) Op() string
type ProcInfo ¶
type ProcInfo struct {
PID uint32 `json:"pid"`
Argv []string `json:"argv"`
Detached bool `json:"detached"`
State string `json:"state"`
ExitCode *int32 `json:"exit_code,omitempty"`
StartedAtEpochSecs uint64 `json:"started_at_epoch_secs"`
}
ProcInfo is one entry of Procs; ExitCode is absent while running.
type PtyOpen ¶
type PtyOpen struct {
Cols uint16 `json:"cols"`
Rows uint16 `json:"rows"`
Cwd string `json:"cwd,omitempty"`
Env map[string]string `json:"env,omitempty"`
User string `json:"user,omitempty"`
}
PtyOpen runs the guest shell under a pseudo-terminal: Started, then Stdout frames out and Stdin frames in, until the shell exits (Exit).
type PtyResize ¶
type PtyResize struct {
PID uint32 `json:"pid"`
Cols uint16 `json:"cols"`
Rows uint16 `json:"rows"`
}
PtyResize resizes a live pty's window by pid.
type Ready ¶
type Ready struct{}
Ready acknowledges an armed watch (events after it are guaranteed captured) or a connected port_forward.
type Request ¶
type Request interface{ Op() string }
Request is a client→server frame; Op is its wire tag.
func DecodeRequest ¶
DecodeRequest parses one frame into its op's concrete type.
type Response ¶
type Response interface{ RespType() string }
Response is a server→client frame; RespType is its wire tag.
func DecodeResponse ¶
DecodeResponse parses one frame into its type's concrete Go type. Byte fields are freshly allocated per frame, so callers may retain them.
type SessionCreate ¶
type SessionCreate struct {
ID string `json:"id,omitempty"`
Cwd string `json:"cwd,omitempty"`
Env map[string]string `json:"env,omitempty"`
}
SessionCreate opens a persistent shell; empty ID lets silkd name it.
func (SessionCreate) Op ¶
func (SessionCreate) Op() string
type SessionCreated ¶
type SessionCreated struct {
ID string `json:"id"`
}
SessionCreated answers SessionCreate.
func (SessionCreated) RespType ¶
func (SessionCreated) RespType() string
type SessionList ¶
type SessionList struct{}
SessionList lists live session ids.
func (SessionList) Op ¶
func (SessionList) Op() string
type SessionRm ¶
type SessionRm struct {
ID string `json:"id"`
}
SessionRm kills a session's shell and process group.
type Sessions ¶
type Sessions struct {
Sessions []string `json:"sessions"`
}
Sessions answers SessionList.
type Started ¶
type Started struct {
PID uint32 `json:"pid"`
}
Started reports the spawned pid (synthetic when the OS pid is unknown).
type Stderr ¶
type Stderr struct {
Data []byte `json:"data"`
}
Stderr carries a chunk of process stderr.
type StdinClose ¶
type StdinClose struct{}
StdinClose signals stdin EOF to the running exec.
func (StdinClose) Op ¶
func (StdinClose) Op() string