Documentation
¶
Index ¶
- Constants
- Variables
- func DecodeFrame(frame []byte) (kind byte, tunnelID string, payload []byte, ok bool)
- func EncodeFrame(kind byte, tunnelID string, payload []byte) []byte
- func IsClusterOwnedName(name string) bool
- func IsLayoutStateName(name string) bool
- func Log(level, msg string, fields ...F)
- func SessionExpiry(secret []byte, token string, now time.Time) (float64, bool)
- func SessionSubject(secret []byte, token string, now time.Time) (string, bool)
- func SignHS256(secret []byte, sub, aud string, ttl time.Duration) string
- func SignPayload(secret []byte, aud string, fields map[string]any, ttl time.Duration) string
- func VerifiedAudience(secret []byte, token, audience string, now time.Time) (map[string]any, bool)
- func VerifiedPayload(secret []byte, token string, now time.Time) (map[string]any, bool)
- func VerifyHS256(secret []byte, token, audience string, now time.Time) error
- func VerifySession(secret []byte, token string, now time.Time) error
- type Agent
- type Appended
- type Claims
- type Config
- type DocBinding
- type F
- type Hello
- type ReadChunk
- type Roots
- type StateFile
- type StateResult
- type TranscriptFile
- type TunnelOpen
Constants ¶
const ( ListenPath = "/v1" DialPath = "/agent/v1" Protocol = 1 )
const ( FrameData byte = 1 FrameClose byte = 2 )
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 ¶
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.
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 IsClusterOwnedName ¶
IsClusterOwnedName: files nothing on the machine writes but the cluster's own routes.
func IsLayoutStateName ¶
IsLayoutStateName: the files the cluster keeps the truth of as versioned documents.
func Log ¶
Log writes one JSON line: level, msg, the extra fields, time. Info goes to stdout, warn and error to stderr.
func SessionExpiry ¶
SessionExpiry is the expiry (epoch seconds) of a valid page session token; false for any other token or one without an expiry.
func SessionSubject ¶
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 SignPayload ¶
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 ¶
VerifiedAudience is the payload of a token signed with secret, valid now and naming audience; false otherwise.
func VerifiedPayload ¶
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 ¶
VerifyHS256 accepts a compact HS256 token signed with secret, naming audience, not expired and already valid.
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent is the machine end of the cluster link for one Unix account.
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 (Config) LoadSecret ¶
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 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.
type Roots ¶
Roots are where the two CLIs keep a Unix account's transcripts.
func TranscriptRoots ¶
func (Roots) IsTranscriptPath ¶
IsTranscriptPath says the request names a transcript this agent serves, not an arbitrary file.
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 ¶
TunnelOpen is the request to open one.