agent

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 31 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

Index

Constants

View Source
const (
	ListenPath = "/v1"
	DialPath   = "/agent/v1"
	Protocol   = 1
)
View Source
const (
	FrameData  byte = 1
	FrameClose byte = 2
)
View Source
const MaxPayload = 32 * 1024 * 1024

MaxPayload bounds one frame: a page's own socket message (a long paste into the terminal) travels whole inside one tunnel frame.

Variables

View Source
var (
	RootStateFiles      = []string{"workspaces.json", "quick-prompts.json", "sidebar-items.json", "keybindings.json"}
	WorkspaceStateFiles = []string{"layout.json", "message-history.json"}
)

Files of the runtime's data directory the cluster keeps a copy of.

View Source
var BuildVersion = "dev"

BuildVersion is set at link time: -ldflags "-X github.com/ly-solutions/harnessly/internal/agent.BuildVersion=1.2.3".

Functions

func DecodeFrame

func DecodeFrame(frame []byte) (kind byte, tunnelID string, payload []byte, ok bool)

func EncodeFrame

func EncodeFrame(kind byte, tunnelID string, payload []byte) []byte

func IsClusterOwnedName

func IsClusterOwnedName(name string) bool

IsClusterOwnedName: files nothing on the machine writes but the cluster's own routes.

func IsLayoutStateName

func IsLayoutStateName(name string) bool

IsLayoutStateName: the files the cluster keeps the truth of as versioned documents.

func Log

func Log(level, msg string, fields ...F)

Log writes one JSON line: level, msg, the extra fields, time. Info goes to stdout, warn and error to stderr.

func SessionExpiry

func SessionExpiry(secret []byte, token string, now time.Time) (float64, bool)

SessionExpiry is the expiry (epoch seconds) of a valid page session token; false for any other token or one without an expiry.

func SessionSubject

func SessionSubject(secret []byte, token string, now time.Time) (string, bool)

SessionSubject is the `sub` of a valid page session token (the machine agent signs its own with its name); false for any other token.

func SignHS256

func SignHS256(secret []byte, sub, aud string, ttl time.Duration) string

SignHS256 signs claims valid from now for ttl.

func SignPayload

func SignPayload(secret []byte, aud string, fields map[string]any, ttl time.Duration) string

SignPayload signs fields of its own with aud, iat and exp set: valid from now for ttl. A token with an audience is never a page session.

func VerifiedAudience

func VerifiedAudience(secret []byte, token, audience string, now time.Time) (map[string]any, bool)

VerifiedAudience is the payload of a token signed with secret, valid now and naming audience; false otherwise.

func VerifiedPayload

func VerifiedPayload(secret []byte, token string, now time.Time) (map[string]any, bool)

VerifiedPayload is the payload of any token signed with the pair's secret and valid now, audience or not (what the previous runtime's verifySessionToken returned); false otherwise.

func VerifyHS256

func VerifyHS256(secret []byte, token, audience string, now time.Time) error

VerifyHS256 accepts a compact HS256 token signed with secret, naming audience, not expired and already valid.

func VerifySession

func VerifySession(secret []byte, token string, now time.Time) error

VerifySession accepts a page session token: signed with the pair's secret, valid now, and naming no audience — a token with one belongs to the agent's link, never to a page.

Types

type Agent

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

Agent is the machine end of the cluster link for one Unix account.

func New

func New(cfg Config) (*Agent, error)

New prepares the agent; Run starts it.

func (*Agent) Run

func (a *Agent) Run(ctx context.Context) error

Run starts the loops, the loopback server and, when configured, the call to the cluster. It returns when ctx ends.

type Appended

type Appended struct {
	From int64  `json:"from"`
	Next int64  `json:"next"`
	Data string `json:"data"`
}

type Claims

type Claims struct {
	Sub string `json:"sub,omitempty"`
	Aud string `json:"aud,omitempty"`
	Iat int64  `json:"iat"`
	Exp int64  `json:"exp"`
}

Claims of the tokens the agent signs. Empty fields are left out.

type Config

type Config struct {
	Home    string
	Host    string
	Port    int
	Version string
	// ScanInterval is the full transcript scan: a safety net for events the watcher missed.
	ScanInterval time.Duration

	// DataDir is the runtime's data directory: state files, agent.json, eval runs.
	DataDir string
	// ConfigFile holds the runtime's authSecret when SecretFile is not given.
	ConfigFile string
	SecretFile string

	// RuntimePort is the runtime's own HTTP API on loopback; FilesPort the disk service next to it. Zero: not here.
	RuntimePort int
	FilesPort   int

	// ClusterURL and RuntimeID make the agent dial the cluster itself; without both it only listens.
	ClusterURL string
	RuntimeID  string

	// ListenAudience is the audience of a token the cluster presents on /v1; DialAudience the one this agent signs
	// when it dials. They differ so a token for one direction is never accepted in the other.
	ListenAudience string
	DialAudience   string

	// RuntimeAPI is the prefix of the runtime routes the agent calls: <prefix>/machines, <prefix>/automations/start…
	RuntimeAPI       string
	StateChangedPath string
	StatusPath       string
	SyncPath         string
	RuntimeCookie    string
	// CLITokenHeaders carry the runtime's cli-token when the agent tells it a state file changed.
	CLITokenHeaders []string

	// LocalTokenHeader carries the token from agent.json on the loopback routes the CLIs call.
	LocalTokenHeader string
	// ReportPortEnv is the variable a launched automation conversation finds this agent's port in.
	ReportPortEnv string
	// ExtraStateFiles are files of the data directory's root the platform also keeps a copy of.
	ExtraStateFiles []string
}

Config is everything the agent takes from its environment. Names a particular platform gives its routes, headers and directories are settings with neutral defaults, so one binary serves any deployment.

func LoadConfig

func LoadConfig() (Config, error)

LoadConfig reads the environment.

func (Config) LoadSecret

func (c Config) LoadSecret() ([]byte, error)

LoadSecret is the pair's session secret: an explicit file wins, else the runtime config's authSecret.

type DocBinding

type DocBinding struct {
	Slug           string  `json:"slug"`
	Kind           string  `json:"kind"`
	Key            *string `json:"key"`
	Title          string  `json:"title"`
	TabID          *string `json:"tabId"`
	SessionName    *string `json:"sessionName"`
	AgentSessionID *string `json:"agentSessionId"`
	Provider       string  `json:"provider"`
	SourcePath     *string `json:"sourcePath"`
	Cwd            *string `json:"cwd"`
}

type F

type F struct {
	K string
	V any
}

F is one extra field of a log line, kept in the order given.

type Hello

type Hello struct {
	Protocol     int      `json:"protocol"`
	AgentVersion string   `json:"agentVersion"`
	User         string   `json:"user"`
	Home         string   `json:"home"`
	Hostname     string   `json:"hostname"`
	Features     []string `json:"features"`
}

Hello is the answer to `hello`.

type ReadChunk

type ReadChunk struct {
	Offset      int64  `json:"offset"`
	Size        int64  `json:"size"`
	Inode       uint64 `json:"inode"`
	Data        string `json:"data"`
	Next        int64  `json:"next"`
	LineTooLong bool   `json:"lineTooLong"`
}

ReadChunk answers `transcripts.read`: complete lines only, base64 of the raw bytes.

func ReadLines

func ReadLines(file string, offset, maxBytes int64) (ReadChunk, error)

ReadLines reads whole lines from offset. A trailing line without its newline is still being written and is left for the next read, so the caller's offset only ever advances over complete lines.

type Roots

type Roots struct {
	Claude string
	Codex  string
}

Roots are where the two CLIs keep a Unix account's transcripts.

func TranscriptRoots

func TranscriptRoots(home string) Roots

func (Roots) IsTranscriptPath

func (r Roots) IsTranscriptPath(file string) bool

IsTranscriptPath says the request names a transcript this agent serves, not an arbitrary file.

type StateFile

type StateFile struct {
	Name    string `json:"name"`
	Content string `json:"content"`
}

StateFile is a file of the runtime's data directory, named relative to it.

type StateResult

type StateResult struct {
	OK      bool            `json:"ok"`
	Version *float64        `json:"version,omitempty"`
	Content json.RawMessage `json:"content,omitempty"`
	Error   *string         `json:"error,omitempty"`
}

StateResult is the cluster's answer to a state commit or patch.

type TranscriptFile

type TranscriptFile struct {
	Provider string  `json:"provider"`
	Path     string  `json:"path"`
	Size     int64   `json:"size"`
	Inode    uint64  `json:"inode"`
	MtimeMs  float64 `json:"mtimeMs"`
	// SeenAt is when the agent noticed the change (events only), to measure delivery latency.
	SeenAt *int64 `json:"seenAt,omitempty"`
	// Appended carries the complete lines the change added, valid only if the reader's offset equals From.
	Appended *Appended `json:"appended,omitempty"`
}

TranscriptFile is one transcript as the agent sees it.

func ListTranscripts

func ListTranscripts(r Roots) ([]TranscriptFile, error)

ListTranscripts is every transcript of the account: Claude — projects/<project>/<session>.jsonl and the subagent transcripts under projects/<project>/<session>/subagents/; Codex — sessions/YYYY/MM/DD/*.jsonl.

type TunnelOpen

type TunnelOpen struct {
	TunnelID string `json:"tunnelId"`
	Target   string `json:"target"`
}

TunnelOpen is the request to open one.

Jump to

Keyboard shortcuts

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