agentproto

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package agentproto defines the wire protocol between the ForgeVM host and the guest agent running inside Firecracker VMs. Messages are framed as 4-byte big-endian length prefix + JSON payload.

Index

Constants

View Source
const (
	MethodPing       = "ping"
	MethodExec       = "exec"
	MethodExecStream = "exec_stream"
	MethodWriteFile  = "write_file"
	MethodReadFile   = "read_file"
	MethodListFiles  = "list_files"
	MethodDeleteFile = "delete_file"
	MethodMoveFile   = "move_file"
	MethodChmodFile  = "chmod_file"
	MethodStatFile   = "stat_file"
	MethodGlobFiles  = "glob_files"
	MethodShutdown   = "shutdown"
)

Method constants.

Variables

This section is empty.

Functions

func MarshalParams

func MarshalParams(v any) (json.RawMessage, error)

MarshalParams marshals v into json.RawMessage for use in Request.Params.

func MarshalResult

func MarshalResult(v any) (json.RawMessage, error)

MarshalResult marshals v into json.RawMessage for use in Response.Result.

func ReadMessage

func ReadMessage(r io.Reader) ([]byte, error)

ReadMessage reads a length-prefixed message from r into buf.

func SendRequest

func SendRequest(w io.Writer, req *Request) error

SendRequest writes a Request to w.

func SendResponse

func SendResponse(w io.Writer, resp *Response) error

SendResponse writes a Response to w.

func SendStreamResponse

func SendStreamResponse(w io.Writer, resp *StreamResponse) error

SendStreamResponse writes a StreamResponse to w.

func UnmarshalParams

func UnmarshalParams(raw json.RawMessage, v any) error

UnmarshalParams unmarshals Request.Params into v.

func UnmarshalResult

func UnmarshalResult(raw json.RawMessage, v any) error

UnmarshalResult unmarshals Response.Result into v.

func WriteMessage

func WriteMessage(w io.Writer, v any) error

WriteMessage writes a length-prefixed JSON message to w.

Types

type ChmodFileParams

type ChmodFileParams struct {
	Path string `json:"path"`
	Mode string `json:"mode"`
}

ChmodFileParams are parameters for chmod_file.

type DeleteFileParams

type DeleteFileParams struct {
	Path      string `json:"path"`
	Recursive bool   `json:"recursive"`
}

DeleteFileParams are parameters for delete_file.

type ExecParams

type ExecParams struct {
	Command string            `json:"command"`
	Args    []string          `json:"args,omitempty"`
	WorkDir string            `json:"work_dir,omitempty"`
	Env     map[string]string `json:"env,omitempty"`
}

ExecParams are parameters for exec and exec_stream methods.

type ExecResult

type ExecResult struct {
	ExitCode int    `json:"exit_code"`
	Stdout   string `json:"stdout"`
	Stderr   string `json:"stderr"`
}

ExecResult is returned by the exec method.

type FileInfoResult

type FileInfoResult struct {
	Path    string `json:"path"`
	Size    int64  `json:"size"`
	Mode    string `json:"mode"`
	IsDir   bool   `json:"is_dir"`
	ModTime string `json:"mod_time"`
}

FileInfoResult describes a single file entry.

type GlobFilesParams

type GlobFilesParams struct {
	Pattern string `json:"pattern"`
}

GlobFilesParams are parameters for glob_files.

type GlobFilesResult

type GlobFilesResult struct {
	Matches []string `json:"matches"`
}

GlobFilesResult is returned by glob_files.

type ListFilesParams

type ListFilesParams struct {
	Path string `json:"path"`
}

ListFilesParams are parameters for list_files.

type ListFilesResult

type ListFilesResult struct {
	Files []FileInfoResult `json:"files"`
}

ListFilesResult is returned by list_files.

type MoveFileParams

type MoveFileParams struct {
	OldPath string `json:"old_path"`
	NewPath string `json:"new_path"`
}

MoveFileParams are parameters for move_file.

type PingResult

type PingResult struct {
	Pong bool `json:"pong"`
}

PingResult is returned by the ping method.

type ReadFileParams

type ReadFileParams struct {
	Path string `json:"path"`
}

ReadFileParams are parameters for read_file.

type ReadFileResult

type ReadFileResult struct {
	Content []byte `json:"content"`
}

ReadFileResult is returned by read_file.

type Request

type Request struct {
	ID     string          `json:"id"`
	Method string          `json:"method"`
	Params json.RawMessage `json:"params,omitempty"`
}

Request is the envelope sent from host to agent.

func ReadRequest

func ReadRequest(r io.Reader) (*Request, error)

ReadRequest reads a Request from r.

type Response

type Response struct {
	ID     string          `json:"id"`
	Error  string          `json:"error,omitempty"`
	Result json.RawMessage `json:"result,omitempty"`
}

Response is the envelope sent from agent to host for non-streaming methods.

func ReadResponse

func ReadResponse(r io.Reader) (*Response, error)

ReadResponse reads a Response from r.

type StatFileParams

type StatFileParams struct {
	Path string `json:"path"`
}

StatFileParams are parameters for stat_file.

type StreamResponse

type StreamResponse struct {
	ID       string `json:"id"`
	Stream   string `json:"stream,omitempty"` // "stdout" or "stderr"
	Data     string `json:"data,omitempty"`
	Error    string `json:"error,omitempty"`
	Done     bool   `json:"done,omitempty"`
	ExitCode int    `json:"exit_code,omitempty"`
}

StreamResponse is sent from agent to host for exec_stream, one per chunk.

func ReadStreamResponse

func ReadStreamResponse(r io.Reader) (*StreamResponse, error)

ReadStreamResponse reads a StreamResponse from r.

type WriteFileParams

type WriteFileParams struct {
	Path    string `json:"path"`
	Content []byte `json:"content"`
	Mode    string `json:"mode,omitempty"`
}

WriteFileParams are parameters for write_file.

Jump to

Keyboard shortcuts

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