wsproto

package
v0.154.2 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 1 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

Overview

Package wsproto defines the WebSocket message protocol shared by the hub (internal/wshub, serve-side) and the worker client (internal/worker). It is a pure leaf package: it has NO dependency on job/runner/config so both sides can import it without cycles (main plan §4, §5).

Wire model: a single multiplexed connection carries every job's frames. Each message is an Envelope discriminated by Type and demuxed by JobID on the hub. The full P1..P3 frame set is declared up front (main plan §5 / review #6: no breaking protocol churn later); P2/P3 frame BEHAVIOUR is not implemented in WP1, only the types exist.

Index

Constants

View Source
const (
	// MinProtocolVersion is the lowest version the hub still accepts at registration
	// (the compatibility floor). v2 is the floor because it is where the worker's
	// capability report (AgentCaps) became authoritative for validation and routing:
	// a worker below it (pre-federation workers report 0 — field absent) cannot be
	// trusted for that, so it is rejected with an upgrade prompt.
	MinProtocolVersion = 2

	// CurrentProtocolVersion is the version THIS build implements; a worker reports it
	// on register and the hub uses the reported value to negotiate OPTIONAL features
	// per peer (see ReloadMinProtocolVersion). It must never be used as the
	// registration gate — that is MinProtocolVersion's job.
	//
	// v4 adds the server-authoritative policy push frames (policy/applied). Bumping
	// Current (not Min) is the whole point of the two-constant split: a v3 worker
	// stays registered, it just cannot be sent a policy frame (negotiated per peer via
	// SupportsPolicy), so no already-deployed worker is evicted by shipping this frame.
	// v5 adds the TCP tunnel frames; v6 adds the resume/read-only dispatch fields
	// (session_id/resumed_from/read_only — see SessionLoadMinProtocolVersion); v7 adds
	// the priming dispatch fields (initial_input/initial_input_quiet_ms — see
	// InitialInputMinProtocolVersion); v8 adds the verify dispatch fields
	// (verify/verify_timeout_sec — see VerifyMinProtocolVersion) and the job_event
	// frame; v9 adds the file-transfer frames (file_xfer/file_xfer_result — see
	// FileXferMinProtocolVersion); v10 adds the skills-mount upload base field
	// (XferUpload.base — see SkillsMinProtocolVersion); v11 adds the job-credential
	// dispatch field (dispatch.job_token — see JobCredentialMinProtocolVersion).
	// v12 adds optional GIT-01 uncommitted result and project-policy fields.
	// v13 adds the remote ACP session command/status frames and recovery metadata.
	// v14 adds the optional resident messenger dispatch payload.
	// v16 adds the messenger list_agents dispatch op and the optional worker state
	// (messenger snapshot, workspace/roots) carried on the worker's heartbeat ping.
	// v17 adds the read-only transcript_tail request / result pair (see
	// TranscriptTailMinProtocolVersion).
	// v18 adds the optional dispatch.stdin (text fed to a non-interactive job's stdin;
	// see StdinMinProtocolVersion).
	// v19 adds the optional dispatch.model (see ModelMinProtocolVersion).
	// v20 adds the optional dispatch.budget (see BudgetMinProtocolVersion).
	// v21 adds the optional dispatch.from_session (see FromSessionMinProtocolVersion).
	// v22 adds the "acp" log stream (the worker mirrors a job's artifacts/acp.jsonl;
	// see ACPMirrorMinProtocolVersion).
	// v23 adds the optional dispatch.mcp (registry MCP servers, MCP-06; see
	// MCPMinProtocolVersion).
	CurrentProtocolVersion = 23
)

Protocol versioning. The wire version is NOT the gofer release version; it only describes worker↔hub capability-frame compatibility.

The floor and the implemented version are deliberately TWO constants. Collapsing them into one makes a rolling upgrade impossible: bumping the single constant to ship a new frame instantly turns every already-deployed worker into "too old", so the next reconnect (one network blip is enough) evicts a fleet that was working fine. Splitting them lets a hub say "I implement N, but I still register anyone at or above M": shipping a new frame only raises Current, and dropping support for an old fleet is then a separate, deliberate decision that raises Min.

View Source
const (
	DefaultUpgradeDrainSec = 600
	DefaultUpgradeReadySec = 60
)

Default budgets of a worker upgrade (Upgrade.DrainTimeoutSec / ReadyTimeoutSec).

View Source
const (
	UpgradePhaseAccepted   = "accepted"
	UpgradePhaseFailed     = "failed"
	UpgradePhaseRolledBack = "rolled_back"
)

Upgrade result phases. The first result of a request is "accepted" (the binary was downloaded, verified and runs) or a failure; "rolled_back" / "failed" may follow later on the same connection once the worker has tried the handover. A successful handover sends no result at all: the new process's registration (Register.UpgradeID) is the success signal.

View Source
const ACPMirrorMinProtocolVersion = 22

ACPMirrorMinProtocolVersion is the first protocol version whose peers speak the "acp" log stream (LogStreamACP, gofer-e2x7): a worker mirrors its local job's artifacts/acp.jsonl to the hub, which appends it to the HOST job's artifacts/acp.jsonl so the structured ACP stream (/v1/jobs/{id}/acp/stream) works for a worker job exactly as for a local one.

The negotiation runs in BOTH directions:

  • a worker sends the stream only to a server whose Registered.ProtocolVersion is at least this — an older hub writes every non-"stderr" log frame into stdout, so it would corrupt the job's stdout.log with JSON lines;
  • a hub that sees a worker below it knows no structured record will arrive and says so on the ACP stream instead of leaving the reader waiting.
View Source
const BudgetMinProtocolVersion = 20

BudgetMinProtocolVersion is the first protocol version whose Dispatch carries budget (N2 §B GATE-02, `job run --max-tokens/--max-cost/--max-turns`): the executing machine meters the agent's streamed usage against it and kills the job when a limit is crossed. A peer below it would ignore the field and run the job unlimited while the row claims a ceiling, so a budgeted job is refused at submit (and at dispatch) with the missing capability named; a job without a budget is never affected.

View Source
const FileXferMinProtocolVersion = 9

FileXferMinProtocolVersion is the first protocol version carrying the file-transfer instruction pair (file_xfer / file_xfer_result, XFER-01). Same refusal rule as the other floors (G032): a worker below it has no frame to answer with, so the hub REFUSES the transfer up front with the missing capability named. There is no honest downgrade to fall back on — the payload would simply never reach (or leave) the executing machine — and the operator would learn about it only as a transfer that sat there until its timeout.

View Source
const FromSessionMinProtocolVersion = 21

FromSessionMinProtocolVersion is the first protocol version whose Dispatch carries from_session (gofer-f4z8, `job run --from-session`): the executing machine renders ITS agent's from_session_args. A peer below it would ignore the field and open a plain new session without the inherited context while the job claims one, so the dispatch is refused with the missing capability named.

View Source
const InitialInputMinProtocolVersion = 7

InitialInputMinProtocolVersion is the first protocol version whose Dispatch carries initial_input/initial_input_quiet_ms — path B's priming text and quiet window (session relay §9.1 B). Same refusal rule as SessionLoadMinProtocolVersion: a peer below it would silently ignore the fields, so a dispatch that needs priming is refused with the missing capability named instead of handing a human a takeover session whose first message never arrives.

View Source
const JobCredentialMinProtocolVersion = 11

JobCredentialMinProtocolVersion is the first protocol version whose Dispatch carries the job's own credential (job_token, SEC-01). It follows the skills floor's rule rather than the refusal rule: nothing is REFUSED over it. A peer below it cannot receive the credential, so the scheduled job runs without one — which is exactly the pre-SEC-01 state for that job (it inherits nothing it could authenticate with either, because the denylist applies everywhere) and is reported as job.credential_skipped rather than silently. Refusing the dispatch would break every already-deployed worker the moment a hub upgraded, for a capability that only ADDS a credential to the job.

View Source
const LogStreamACP = "acp"

LogStreamACP is the Log.Stream value carrying the job's artifacts/acp.jsonl bytes (protocol v22, see ACPMirrorMinProtocolVersion). Each frame holds whole JSON lines unless one line alone exceeds a frame, in which case the line spans consecutive frames and the hub's append reassembles it.

View Source
const MCPMinProtocolVersion = 23

MCPMinProtocolVersion is the first protocol version whose Dispatch carries the job's registry MCP servers (MCP-06). Like the skills floor nothing is refused over it: an older worker gets the job without them and the hub records job.mcp_skipped.

View Source
const MaxTranscriptTailBytes = 512 * 1024

MaxTranscriptTailBytes is the hard cap of one transcript_tail answer. The worker clamps the requested size to it, so a hub cannot make a worker ship an unbounded file.

View Source
const MessengerListMinProtocolVersion = 16

MessengerListMinProtocolVersion is the first version whose worker understands MessengerDispatch.Op == "list_agents". An older worker would treat the dispatch as a plain send and forward the list prompt to a session as a message, so the server refuses to dispatch it (SupportsMessengerList).

View Source
const MessengerMinProtocolVersion = 14

MessengerMinProtocolVersion is the first version whose worker handles a resident stream-json messenger dispatch.

View Source
const ModelMinProtocolVersion = 19

ModelMinProtocolVersion is the first protocol version whose Dispatch carries model (N1 §B, `job run --model`): the executing machine renders ITS agent's model_args / selects the model over ACP. A peer below it would ignore the field and run the agent's default model while the job claims another, so the dispatch is refused with the missing capability named.

View Source
const PolicyMinProtocolVersion = 4

PolicyMinProtocolVersion is the first protocol version that carries the server-authoritative policy push frames (policy/applied). Same negotiation rule as ReloadMinProtocolVersion: a worker registered below it stays fully usable — it just never receives a policy frame, so a v3 worker keeps sourcing its projects from its own local config (LEGACY) and is never evicted for lacking the capability.

View Source
const ReloadMinProtocolVersion = 3

ReloadMinProtocolVersion is the first protocol version that carries the config hot-reload frames. A worker registered below it stays fully usable for everything else; it simply cannot be asked to reload, so the caller must check SupportsReload with the version the peer reported and surface an explicit "worker too old" error instead of sending a frame the peer will ignore.

View Source
const SessionJobMinProtocolVersion = 13

SessionJobMinProtocolVersion is the first protocol version that carries a long-lived ACP session dispatch and session_cmd/status metadata.

View Source
const SessionLoadMinProtocolVersion = 6

SessionLoadMinProtocolVersion is the first protocol version whose Dispatch carries session_id/resumed_from (an acp-agent continuation) and read_only. Since P2 the hub does NOT tolerate a peer below it for a job that needs those fields: the additive fields would be silently ignored, which costs exactly the S2 semantics (a resume opens a NEW session instead of loading the source one; a read-only job runs writable) — a job that quietly does the wrong thing. The dispatch is REFUSED instead (see runner/worker's capability gate), with the missing capability named so the operator upgrades that worker. G032: this replaced the earlier warn-only tolerance, which no longer exists.

View Source
const SkillsMinProtocolVersion = 10

SkillsMinProtocolVersion is the first protocol version whose XferUpload carries Base (the skills mount, JOB-10). It is a floor of a different kind from the ones above: nothing is REFUSED over it. A skill travels as an ordinary staged upload, but to a destination OUTSIDE the job's cwd (the job's result dir), and a worker that predates Base silently drops the field and would place the skill in the WORKING TREE — the one place the design forbids (a shared checkout git watches). So the hub does not send the mount at all to such a worker: it dispatches the job WITHOUT its skills and records job.skills_skipped, rather than gamble on a destination the peer cannot see. Hence the capability is negotiated per peer via SupportsSkills instead of gating the dispatch (G032: no silent degradation — the job still runs, and the omission is on the job's own timeline).

View Source
const StdinMinProtocolVersion = 18

StdinMinProtocolVersion is the first protocol version whose Dispatch carries stdin: text the executing machine writes to a NON-interactive job's standard input (the relay's `deliver_command` with deliver_stdin). A peer below it would ignore the field and run the command with an empty stdin, so such a dispatch is refused with the missing capability named.

View Source
const TranscriptTailMinProtocolVersion = 17

TranscriptTailMinProtocolVersion is the first protocol version whose worker answers a transcript_tail request (W2a: the work-item summarizer reads the end of a session transcript that lives on the worker's disk). A worker below it keeps working; the hub just cannot ask it, and the summarizer degrades to last_message + progress (SupportsTranscriptTail), exactly like the other optional floors.

View Source
const TunnelMinProtocolVersion = 5

TunnelMinProtocolVersion is the first protocol version carrying TCP tunnel frames.

View Source
const UpgradeMinProtocolVersion = 15

UpgradeMinProtocolVersion is the first protocol version that can receive a remote worker binary upgrade request and report its result.

View Source
const VerifyMinProtocolVersion = 8

VerifyMinProtocolVersion is the first protocol version whose Dispatch carries verify/verify_timeout_sec (SUP-01 B) and which can send the job_event frame (SUP-01 G). It is the version where a worker can be TRUSTED to run a job's verify step: a peer below it would ignore the argv and report a job as done with no verification performed, so the hub refuses such a dispatch up front (G032: no silent degradation) rather than shipping a step that will not run.

Variables

This section is empty.

Functions

func As

func As[T any](env Envelope) (T, error)

As decodes env.Payload into the typed payload T. A nil/empty payload yields the zero value of T (no error), so a body-less frame still round-trips.

func EncodeFrame

func EncodeFrame(t FrameType, jobID string, payload any) ([]byte, error)

EncodeFrame marshals a typed payload into an Envelope's JSON bytes. jobID is the demux key (may be empty for register/registered which are connection-level rather than per-job).

func SupportsACPMirror added in v0.136.0

func SupportsACPMirror(proto int) bool

SupportsACPMirror reports whether a peer that registered with protocol version proto speaks the "acp" log stream.

func SupportsBudget

func SupportsBudget(proto int) bool

SupportsBudget reports whether a peer that registered with protocol version proto understands dispatch.budget.

func SupportsFileXfer

func SupportsFileXfer(proto int) bool

SupportsFileXfer reports whether a peer that registered with protocol version proto implements the file-transfer frames.

func SupportsFromSession

func SupportsFromSession(proto int) bool

SupportsFromSession reports whether a peer that registered with protocol version proto understands dispatch.from_session.

func SupportsInitialInput

func SupportsInitialInput(proto int) bool

SupportsInitialInput reports whether a peer that registered with protocol version proto understands the priming dispatch fields.

func SupportsJobCredential

func SupportsJobCredential(proto int) bool

SupportsJobCredential reports whether a peer that registered with protocol version proto can receive a job's credential on its dispatch frame.

func SupportsMCP added in v0.144.0

func SupportsMCP(proto int) bool

SupportsMCP reports whether a peer at protocol proto takes dispatch.mcp.

func SupportsMessenger

func SupportsMessenger(proto int) bool

SupportsMessenger reports whether a worker supports resident messenger dispatch.

func SupportsMessengerList

func SupportsMessengerList(proto int) bool

SupportsMessengerList reports whether a worker can list the sessions its resident messenger sees.

func SupportsModel

func SupportsModel(proto int) bool

SupportsModel reports whether a peer that registered with protocol version proto understands dispatch.model.

func SupportsPolicy

func SupportsPolicy(proto int) bool

SupportsPolicy reports whether a peer that registered with protocol version proto implements the policy push frames. Like SupportsReload it is the single place that knows which version gained the capability — callers must not compare versions.

func SupportsReload

func SupportsReload(proto int) bool

SupportsReload reports whether a peer that registered with protocol version proto implements the hot-reload frames. It is the single place that knows which version gained the capability — callers must not compare version numbers themselves.

func SupportsSessionJob

func SupportsSessionJob(proto int) bool

SupportsSessionJob reports whether a worker understands remote ACP sessions.

func SupportsSessionLoad

func SupportsSessionLoad(proto int) bool

SupportsSessionLoad reports whether a peer that registered with protocol version proto understands the resume dispatch fields (session_id/resumed_from).

func SupportsSkills

func SupportsSkills(proto int) bool

SupportsSkills reports whether a peer that registered with protocol version proto understands the upload base field (and can therefore be handed a skills mount).

func SupportsStdin

func SupportsStdin(proto int) bool

SupportsStdin reports whether a peer that registered with protocol version proto understands dispatch.stdin.

func SupportsTranscriptTail

func SupportsTranscriptTail(proto int) bool

SupportsTranscriptTail reports whether a peer that registered with protocol version proto answers transcript_tail.

func SupportsTunnel

func SupportsTunnel(proto int) bool

SupportsTunnel reports whether a peer supports TCP tunnel frames.

func SupportsUpgrade

func SupportsUpgrade(proto int) bool

func SupportsVerify

func SupportsVerify(proto int) bool

SupportsVerify reports whether a peer that registered with protocol version proto understands the verify dispatch fields and sends job_event frames.

Types

type AgentBrief

type AgentBrief struct {
	Key         string `json:"key"`
	Type        string `json:"type,omitempty"`
	Interactive bool   `json:"interactive,omitempty"`
	Batch       bool   `json:"batch"`
	// Available is DISPLAY-ONLY. Never gate admission on it: a worker that predates
	// this field reports nothing (nil), and an operator-declared agent whose probe
	// failed reports false — BOTH OF THEM RUN FINE.
	//
	// That is also why it is a *bool and not a bool: a plain bool would decode the
	// absent field of a pre-P2 worker as false, making "never reported" (unknown)
	// indistinguishable from "reported unusable". Any consumer that filters or greys
	// out on it therefore hits both of those false negatives at once — every agent of
	// every old worker, plus every escape-hatch agent whose CLI the probe could not
	// see. nil = unknown; the agent list itself is the authority on what can run.
	Available *bool `json:"available,omitempty"`
	// Version is the best-effort CLI version string (empty = not probed, probe failed
	// or unavailable). Display-only, same rule as Available.
	Version string `json:"version,omitempty"`
}

AgentBrief is a worker-reported agent capability with the detail the UI cascade needs (type/interactive) beyond a bare key. Federation: the worker is the authority for ITS agents' type/interactive (the server may not have them in its own config).

Adding Available/Version does NOT bump the protocol: As[T] (envelope.go) is a plain json.Unmarshal with no DisallowUnknownFields, so an old peer silently ignores the new keys and a new peer decodes their absence as the zero value.

func (*AgentBrief) UnmarshalJSON

func (a *AgentBrief) UnmarshalJSON(data []byte) error

UnmarshalJSON derives batch capability for legacy workers that omitted it.

type Answer

type Answer struct {
	JobID         string `json:"job_id"`
	InteractionID string `json:"interaction_id"`
	Answer        string `json:"answer"`
}

Answer (s→w, P2): the host-side answer to a worker interaction.

type Applied

type Applied struct {
	Rev      int64              `json:"rev"`
	Caps     *Caps              `json:"caps,omitempty"`
	Rejected []AppliedRejection `json:"rejected,omitempty"`
	Degraded []AppliedDegrade   `json:"degraded,omitempty"`
}

Applied (w→s): the worker's report of what it actually applied for a Policy Rev. Caps is EMBEDDED (not a new capability channel): the hub routes it through the same reg.UpdateCaps path that reload/caps use. Rejected/Degraded are diagnostic only and never gate routing.

type AppliedDegrade

type AppliedDegrade struct {
	Key  string `json:"key"`
	Gate string `json:"gate"`
}

AppliedDegrade is one project the worker applied but with a capability gated off (e.g. a legacy local-projects worker that ignores the pushed policy). Diagnostic only, same as AppliedRejection.

type AppliedRejection

type AppliedRejection struct {
	Key    string `json:"key"`
	Reason string `json:"reason"`
}

AppliedRejection is one project the worker could NOT apply (e.g. host_path outside every local root). It is diagnostic only — surfaced on the Cluster page — and does NOT participate in routing.

type ApprovalPolicy

type ApprovalPolicy struct {
	Mode                string   `json:"mode"`
	AutoAllowKinds      []string `json:"auto_allow_kinds"`
	AskKinds            []string `json:"ask_kinds"`
	TimeoutSec          int      `json:"timeout_sec"`
	OnTimeout           string   `json:"on_timeout"`
	RememberAllowAlways bool     `json:"remember_allow_always"`
}

ApprovalPolicy is the wire form of a project's approval gate (config.ApprovalConfig). Every field is RESOLVED (the server applied the defaults) so the worker never re-derives them, and the type lives here because wsproto must not import internal/config.

type Budget

type Budget struct {
	MaxTokens  int64   `json:"max_tokens,omitempty"`
	MaxCostUSD float64 `json:"max_cost_usd,omitempty"`
	MaxTurns   int     `json:"max_turns,omitempty"`
}

Budget is the wire shape of a job's spend ceiling (Dispatch.Budget); it mirrors config.Budget field for field (0 = no limit on that dimension) — the wire package deliberately imports nothing from the rest of gofer.

type Cancel

type Cancel struct {
	JobID string `json:"job_id"`
}

Cancel (s→w, P2): cancel a running job on the worker.

type Caps

type Caps struct {
	Labels              []string     `json:"labels"`
	Projects            []string     `json:"projects"`
	InteractiveProjects []string     `json:"interactive_projects,omitempty"`
	Agents              []string     `json:"agents"`
	AgentCaps           []AgentBrief `json:"agent_caps"`
	MaxConc             int          `json:"max_concurrent"`
	// Tools (CFG-16) is part of the full snapshot like Labels. An absent key decodes
	// to nil, which the hub applies as "no tools" — the same thing an empty list says,
	// so omitempty loses nothing here (and keeps an old worker's frame unchanged).
	Tools []ToolBrief `json:"tools,omitempty"`
}

Caps (w→s): an UNSOLICITED re-report of the worker's capabilities, sent when they changed with no Reload request to answer — a SIGHUP-triggered reload is the case that forces this frame to exist (it originates on the worker, so there is no RequestID and nowhere to send a receipt).

It is a SEPARATE type from ReloadResult, never a substitute for it. Collapsing the two would let an unrelated broadcast (SIGHUP, a concurrent reload, a re-report after reconnect) be mistaken for the answer to a pending Reload — the caller would resolve its RPC against caps it never asked for, and the real reply would then look unsolicited. A Caps frame therefore MUST NOT complete a pending reload request; it only refreshes the hub's capability view.

Register cannot be reused for this: it is accepted only as the FIRST frame of a connection (the hub has no run-time branch for it), so re-reporting capabilities on a live connection is what this frame is for. It is a re-report, not a re-register: identity (worker_id/instance_id) and the immutable process facts (os/arch/gofer_version/started_at/protocol_version/pty_capable) are NOT resent — they cannot change without a restart, which brings a fresh Register anyway.

The payload is a FULL SNAPSHOT of every capability field that a config reload can change, i.e. exactly the config-derived subset of Register. No omitempty: a reload that empties a capability (all projects removed, say) must travel as an explicit empty list, not as an absent field indistinguishable from "unchanged".

type Commit

type Commit struct {
	SHA     string `json:"sha"`
	Subject string `json:"subject"`
}

Commit is one commit captured for a job (SUP-01 C): the abbreviated sha and the subject line. Declared here (like Outcome.Artifacts) so wsproto stays a leaf that does not import job.

type Dispatch

type Dispatch struct {
	JobID        string   `json:"job_id"`
	ProjectKey   string   `json:"project_key"`
	Agent        string   `json:"agent"`
	Runner       string   `json:"runner"`
	Prompt       string   `json:"prompt,omitempty"`
	AgentArgs    []string `json:"agent_args,omitempty"`
	Model        string   `json:"model,omitempty"`        // N1 §B; an old worker ignores it
	FromSession  string   `json:"from_session,omitempty"` // gofer-f4z8 v21: source session the new one inherits
	Budget       *Budget  `json:"budget,omitempty"`       // N2 §B v20: decided ceiling the worker meters; nil = unlimited
	SystemPrompt string   `json:"system_prompt,omitempty"`
	Cmd          []string `json:"cmd,omitempty"`
	Cwd          string   `json:"cwd,omitempty"`
	// Worktree/WorktreeBase (WT-01) ask the WORKER to run this job in a managed git
	// worktree of its own project checkout. The submitting service already resolved the
	// project-level worktree_default into Worktree, so the worker never re-derives it.
	// An OLD worker ignores the unknown fields and runs in the shared checkout.
	Worktree          bool   `json:"worktree,omitempty"`
	WorktreeBase      string `json:"worktree_base,omitempty"`
	TimeoutSec        int    `json:"timeout_sec,omitempty"`
	Interactive       bool   `json:"interactive,omitempty"`
	Cols              int    `json:"cols,omitempty"`
	Rows              int    `json:"rows,omitempty"`
	ResumeSourceAgent string `json:"resume_source_agent,omitempty"`
	// SessionID/ResumedFrom (ACP-01 S2) ask the worker to CONTINUE an existing agent
	// session instead of opening a fresh one: for an acp-agent the local job resolves
	// SessionID into the runner's session/load, and ResumedFrom is the lineage marker
	// that makes the session a LOAD rather than a plain binding. Both are set only for
	// a resume (the hub projects them from a Forward whose ResumedFrom is non-empty) —
	// a plain job's session_id never travels here. An OLD worker ignores the unknown
	// fields and starts a new session (see SessionLoadMinProtocolVersion).
	SessionID         string `json:"session_id,omitempty"`
	ResumedFrom       string `json:"resumed_from,omitempty"`
	AutoResumeAttempt int    `json:"auto_resume_attempt,omitempty"`
	// ReadOnly (bd h-aii-0ql3) asks the worker to run the job in its own read-only mode
	// (cli-agent argv sandbox / acp-agent session/set_mode). The worker validates it
	// against its OWN agent config. An OLD worker ignores the field and runs the job
	// writable (see SessionLoadMinProtocolVersion).
	ReadOnly bool `json:"read_only,omitempty"`
	// NoRules carries the caller's `--no-rules` ("no gofer-injected context"). The hub
	// already applied it to the rules it rendered into Prompt; the worker needs it only
	// to skip the section IT renders — its own declared tools (CFG-16). An old worker
	// ignores the key and lists its tools anyway.
	NoRules bool `json:"no_rules,omitempty"`
	// InitialInput / InitialInputQuietMs carry path B's priming text and quiet
	// window (session relay §9.1 B): the worker starts the pty, so the text the hub
	// wants typed and the window it resolved must arrive with the dispatch. A hub
	// that predates them omits the keys and the worker behaves as before (nothing
	// is primed).
	InitialInput string `json:"initial_input,omitempty"`
	// Stdin is text piped to a non-interactive job's stdin (protocol v18).
	Stdin               string `json:"stdin,omitempty"`
	InitialInputQuietMs int    `json:"initial_input_quiet_ms,omitempty"`
	RelayNonce          string `json:"relay_nonce,omitempty"`
	// PtySessionID is the host-minted relay session id the worker echoes back in
	// its pty-connect hello so the serve endpoint can strong-check it against the
	// binding (httpapi/pty_connect_handler; D-P2-4). Empty on non-interactive.
	PtySessionID string `json:"pty_session_id,omitempty"`
	// TodoID (SUP-01 C) is the hub's checklist item for this job, carried so the
	// worker's own job row can DISPLAY it. The todo lives in the hub's store, so the
	// worker neither resolves nor links it (JobRequest.TodoForeign). Empty on a plain
	// dispatch and on a hub that predates the field.
	TodoID string `json:"todo_id,omitempty"`
	// Verify / VerifyTimeoutSec are the job's验证步骤 (SUP-01 B): the argv run after
	// the agent finishes normally, and its own deadline in seconds. A hub that
	// predates them omits the keys; a worker that predates them never receives them,
	// because the hub refuses the dispatch instead (VerifyMinProtocolVersion).
	Verify           []string `json:"verify,omitempty"`
	VerifyTimeoutSec int      `json:"verify_timeout_sec,omitempty"`
	// Uploads / Collect are the job's file-transfer steps (XFER-01 X2): the staged
	// uploads the worker must place in ITS cwd before the agent starts, and the globs
	// it must match there after the job ends. Only the instruction travels here — the
	// bytes ride HTTP (§一.2). A hub that predates them omits the keys; a worker that
	// predates them never receives them, because the hub refuses the dispatch instead
	// (FileXferMinProtocolVersion, the same v9 floor as the transfer frames).
	Uploads []XferUpload `json:"uploads,omitempty"`
	Collect []string     `json:"collect,omitempty"`
	// Skills (JOB-10) is the RESOLVED skill binding the hub decided for this job —
	// never re-derived here, because the worker's own config may name a different
	// library. The files themselves ride Uploads with Base=result_dir, and the WORKER
	// renders the prompt list from these names after mounting them (决策 1,
	// 2026-09-23): the submitting hub never writes a skill path into the prompt, so a
	// peer that is not given the files is not given the names either (the hub drops
	// both — see SupportsSkills — and records job.skills_skipped for it).
	Skills []string `json:"skills,omitempty"`
	// MCP are the registry MCP servers the hub bound to this job (MCP-06, v23), in
	// binding order. The worker injects them with its own agent definition and reads
	// secret values from its own environment; it never re-derives the binding.
	MCP []MCPSpec `json:"mcp,omitempty"`
	// ExclusiveDir / StallTimeoutSec are the JOB-11 / AUTO-05 policies the hub
	// RESOLVED for this job: whether the worker must take the exclusive lock of the
	// job's working directory, and after how many silent seconds it must kill it.
	// Pointers, so an explicit false/0 (a DECISION) is distinguishable from "the hub
	// did not resolve one" (nil) — only then does the worker fall back to its own
	// config. Both are additive and optional: a worker that predates them ignores the
	// keys and runs the job exactly as before (no lock, no watchdog), which is why no
	// protocol floor refuses such a dispatch (unlike uploads/collect, whose absence
	// would silently run the job WITHOUT the caller's files).
	ExclusiveDir    *bool `json:"exclusive_dir,omitempty"`
	StallTimeoutSec *int  `json:"stall_timeout_sec,omitempty"`
	// DEPRECATED(v0.83): remove in v0.86. Keep this field while the existing
	// server-to-worker dispatch wire still uses dir_wait_max_sec; public job inputs
	// use lock_wait_sec.
	// DirWaitMaxSec (JOB-11, F12) is the same-directory-lock WAIT cap the hub resolved
	// (server.dir_lock_max_wait_sec): the lock is taken on the WORKER, so the policy
	// travels with the dispatch instead of being re-derived there. Same additive/optional
	// rule as the two above.
	DirWaitMaxSec *int     `json:"dir_wait_max_sec,omitempty"`
	EnvDenyExtra  []string `json:"env_deny_extra,omitempty"`
	// JobToken (SEC-01) is the job-scoped credential the hub minted for this job. The
	// worker injects it as GOFER_JOB_TOKEN, which is what lets the job reach the hub
	// after the inherited server token stopped travelling with it. An OLD worker
	// ignores the unknown key (its job runs without a credential — the hub does not
	// refuse the dispatch over it, it records job.credential_skipped), and a hub below
	// JobCredentialMinProtocolVersion never sets it.
	JobToken string `json:"job_token,omitempty"`
	// Session enables the resident ACP process on the worker. The worker owns the
	// per-turn idle/max clocks; the host mirrors status and does not start a whole
	// job timer for this mode.
	Session        bool `json:"session,omitempty"`
	IdleTimeoutSec int  `json:"idle_timeout_sec,omitempty"`
	MaxSessionSec  int  `json:"max_session_sec,omitempty"`
	// Messenger is additive. A v13 worker ignores it and executes Cmd.
	// DEPRECATED(v0.92): remove in v0.95; this is the one-shot messenger fallback
	// retained only for the rolling upgrade window.
	Messenger *MessengerDispatch `json:"messenger,omitempty"`
}

Dispatch (s→w, P1): a job assignment = JobRequest projection. Runner is always "local" (the worker executes locally with its own config). worker_id is NOT carried — the worker already knows it is itself.

type Envelope

type Envelope struct {
	Type    FrameType       `json:"type"`
	JobID   string          `json:"job_id,omitempty"`
	Payload json.RawMessage `json:"payload,omitempty"`
}

Envelope is the single-connection multiplexed message. Payload carries the type-specific body as raw JSON so the reader can demux on Type/JobID before decoding the body (double-stage decode keeps wsproto free of job/runner).

func DecodeEnvelope

func DecodeEnvelope(b []byte) (Envelope, error)

DecodeEnvelope unmarshals raw bytes into an Envelope (type + job_id + the raw payload). An unknown Type is NOT an error: the envelope decodes and the reader may ignore it (forward compatibility, review #6).

type FileXfer

type FileXfer struct {
	XferID     string `json:"xfer_id"`
	Op         string `json:"op"` // put | get
	ProjectKey string `json:"project_key"`
	// Path is the project-RELATIVE path on the executing machine; the worker resolves
	// it under its own project root and refuses anything that escapes it.
	Path    string `json:"path"`
	Size    int64  `json:"size"`
	SHA256  string `json:"sha256"`
	Force   bool   `json:"force"`
	URLPath string `json:"url_path"`
}

FileXfer (s→w, XFER-01, protocol v9) is ONE transfer instruction: the worker fetches (op=put) or uploads (op=get) the payload over HTTP itself, using the same hub origin and bearer token it registered with. URLPath is that payload's server-relative content URL; Size and SHA256 are what the worker must end up with, so the EXECUTING machine verifies the bytes it wrote or read instead of trusting the transfer. Force allows overwriting an existing destination (a put).

type FileXferResult

type FileXferResult struct {
	XferID     string `json:"xfer_id"`
	OK         bool   `json:"ok"`
	Size       int64  `json:"size"`
	SHA256     string `json:"sha256"`
	Error      string `json:"error"`
	DurationMS int64  `json:"duration_ms"`
}

FileXferResult (w→s, XFER-01, protocol v9) is the worker's report for exactly one FileXfer, correlated by XferID. It is ALWAYS sent, failures included — Error carries the reason verbatim (the literal "exists" is the one the caller matches on to distinguish a force-needed refusal from a real fault) — because the dispatch is parked on this frame: a report that never arrives would strand the transfer until its timeout. DurationMS is the worker's own wall time for the transfer (diagnostics; the hub adds nothing).

type FrameType

type FrameType string

FrameType is the envelope discriminator (main plan §5 frame table).

const (
	// P1 frames (端到端远程执行).
	TypeRegister   FrameType = "register"   // w→s
	TypeRegistered FrameType = "registered" // s→w
	TypeDispatch   FrameType = "dispatch"   // s→w
	TypeLog        FrameType = "log"        // w→s
	TypeStatus     FrameType = "status"     // w→s
	TypeResult     FrameType = "result"     // w→s
	// TypeOutcome (w→s, P4 产出与审计回传): sent just before the terminal result so
	// the host applies the worker-captured产出 before finishing the job. Optional —
	// an old worker never sends it (the read loop ignores an unknown opcode anyway).
	TypeOutcome FrameType = "outcome" // w→s
	// TypeJobEvent (w→s, SUP-01 G, protocol v8) mirrors a JOB life-cycle event the
	// worker raised while executing a dispatched job (its approval gate; its verify
	// step) onto the host job, which otherwise never sees them: the events live in
	// the EXECUTING machine's store. Only the whitelisted types are mirrored (the hub
	// records its own submitted/running/terminal events), and an old peer never sends
	// the frame — the host job then simply has no mirrored events, which is exactly
	// the pre-P2 behaviour.
	TypeJobEvent FrameType = "job_event" // w→s

	// P2 frames (declared as placeholders; behaviour implemented in P2).
	TypeCancel      FrameType = "cancel"      // s→w
	TypeInteraction FrameType = "interaction" // w→s
	TypeAnswer      FrameType = "answer"      // s→w
	TypeSessionCmd  FrameType = "session_cmd" // s→w, protocol v13

	// P3 frames (heartbeat; declared as placeholders).
	TypePing FrameType = "ping" // both
	TypePong FrameType = "pong" // both

	// Config hot-reload frames (protocol v3, see ReloadMinProtocolVersion).
	// reload/reload_result form an RPC PAIR correlated by request_id; caps is an
	// UNSOLICITED broadcast. They are deliberately distinct types: a broadcast must
	// never be able to pose as the response to a pending reload (see the Caps doc).
	TypeReload       FrameType = "reload"        // s→w
	TypeReloadResult FrameType = "reload_result" // w→s
	TypeCaps         FrameType = "caps"          // w→s

	// Policy push frames (protocol v4, see PolicyMinProtocolVersion). policy is the
	// server→worker authoritative project/guard set; applied is the worker→server
	// report of what it converged to. A policy may also ride on the Registered ack
	// (catch-up on register); the standalone frame carries later revisions.
	TypePolicy     FrameType = "policy"      // s→w
	TypeApplied    FrameType = "applied"     // w→s
	TypeTunnelOpen FrameType = "tunnel_open" // s→w

	// File-transfer frames (XFER-01, protocol v9, see FileXferMinProtocolVersion).
	// file_xfer is the INSTRUCTION (the worker fetches/uploads the payload itself,
	// over its own authenticated HTTP session — the bytes never ride this
	// connection, so the single-reader demux discipline and the frame-size budget are
	// untouched), file_xfer_result is the worker's report for exactly one of them.
	TypeFileXfer       FrameType = "file_xfer"        // s→w
	TypeFileXferResult FrameType = "file_xfer_result" // w→s
	TypeUpgrade        FrameType = "upgrade"          // s→w, protocol v15
	TypeUpgradeResult  FrameType = "upgrade_result"   // w→s, protocol v15

	// Read-only session transcript tail (W2a, protocol v17): the hub asks a worker for
	// the end of a session transcript file the session registered, for the work-item
	// summarizer. The reply is correlated by req_id (the frame carries no job id).
	TypeTranscriptTail       FrameType = "transcript_tail"        // s→w
	TypeTranscriptTailResult FrameType = "transcript_tail_result" // w→s
)

type InflightJob

type InflightJob struct {
	JobID string `json:"job_id"`
	// Status is the worker's local job status ("queued"/"running"/"pending_interaction"/
	// "done"/"failed"/"cancelled"/"timeout"/"recovering").
	Status string `json:"status,omitempty"`
	// TurnNo and SessionStatus prove the current resident-session state during a
	// reconnect. They are meaningful only for session jobs and are additive for
	// ordinary jobs.
	TurnNo         int    `json:"turn_no,omitempty"`
	SessionStatus  string `json:"session_status,omitempty"`
	IdleDeadlineAt int64  `json:"idle_deadline_at,omitempty"`
	// StdoutOff/StderrOff are the byte offsets the worker has successfully SENT for
	// this job's stdout/stderr log files (a frame that failed to write does NOT
	// advance them), so the hub can rewind the worker to what it actually persisted.
	StdoutOff int64 `json:"stdout_off,omitempty"`
	StderrOff int64 `json:"stderr_off,omitempty"`
	// Seq is the highest log-frame seq the worker has sent for this job.
	Seq int64 `json:"seq,omitempty"`
}

InflightJob is one entry of Register.Inflight: a job the worker still tracks on behalf of the hub (RECOV-01). Status is the WORKER-side local job status; the hub only needs to know whether it is terminal (job.IsTerminal lives in job, so the hub compares against the wire vocabulary below).

type Interaction

type Interaction struct {
	JobID       string          `json:"job_id"`
	Action      string          `json:"action"` // open|answered|cancelled
	Interaction json.RawMessage `json:"interaction"`
}

Interaction (w→s, P2): a worker-raised running-job interaction bridged onto the host job. The interaction body stays raw JSON so wsproto need not import job; P2 decodes it into job.Interaction on the hub side.

type JobEvent

type JobEvent struct {
	JobID string `json:"job_id"`
	// Type is the job-package event type ("job.permission_requested",
	// "job.verify_finished", …); the hub keeps its own whitelist of what it accepts.
	Type string `json:"type"`
	// Detail is the event's detail map as the worker recorded it (nil = none).
	Detail json.RawMessage `json:"detail,omitempty"`
	// TS is when the worker raised it (unix seconds) — part of the event's identity
	// for de-duplication, since a replayed frame carries the same TS and a genuinely
	// new event of the same type carries a later one.
	TS int64 `json:"ts"`
	// InteractionID is the interaction the event is about, when it has one (the
	// approval-gate events do; the verify events do not). It is lifted out of the
	// detail so de-duplication does not have to parse it.
	InteractionID string `json:"interaction_id,omitempty"`
}

JobEvent (w→s, SUP-01 G, protocol v8): one job life-cycle event the WORKER raised for a job the hub dispatched to it. It is a MIRROR, not a new source of truth: the event is already recorded in the worker's own store (that is where it happened); the hub records the same type/detail against the HOST job so its event log, notifications and audit trail answer "what did this job do on the worker".

Detail stays raw JSON: wsproto is a leaf (the job package owns the event vocabulary) and the hub needs the payload only to forward it.

type Log

type Log struct {
	JobID  string `json:"job_id"`
	Stream string `json:"stream"` // "stdout" | "stderr" | "acp" (v22, LogStreamACP)
	Seq    int    `json:"seq"`
	Text   string `json:"text"`
}

Log (w→s, P1): an incremental log frame. Seq is monotonic per job (the same notion as the C4 SSE seq), giving the hub an ordering baseline.

type MCPSpec added in v0.144.0

type MCPSpec struct {
	Name          string            `json:"name"`
	Type          string            `json:"type,omitempty"`
	Command       string            `json:"command,omitempty"`
	Args          []string          `json:"args,omitempty"`
	Env           map[string]string `json:"env,omitempty"`
	URL           string            `json:"url,omitempty"`
	Headers       map[string]string `json:"headers,omitempty"`
	SecretEnv     map[string]string `json:"secret_env,omitempty"`
	SecretHeaders map[string]string `json:"secret_headers,omitempty"`
	Tools         []string          `json:"tools,omitempty"`
}

MCPSpec is one registry MCP server as the hub resolved it for a dispatched job: the declaration with secret VARIABLE NAMES only — the worker reads the values from its own environment.

type MessengerDelivery

type MessengerDelivery struct {
	At         int64  `json:"at"`
	Op         string `json:"op,omitempty"`
	Target     string `json:"target,omitempty"`
	Message    string `json:"message,omitempty"`
	OK         bool   `json:"ok"`
	Error      string `json:"error,omitempty"`
	DurationMS int64  `json:"duration_ms,omitempty"`
}

MessengerDelivery is one entry of MessengerSnapshot.Deliveries (newest first).

type MessengerDispatch

type MessengerDispatch struct {
	// Op selects what the resident process does: "" / "send" forwards Command's
	// prompt to SessionName; "list_agents" (v16) lists the sessions it can message
	// and returns the raw ListAgents text on stdout.
	Op          string   `json:"op,omitempty"`
	SessionName string   `json:"session_name,omitempty"`
	Command     []string `json:"command,omitempty"`
	Cwd         string   `json:"cwd,omitempty"`
	TimeoutSec  int      `json:"timeout_sec,omitempty"`
	IdleSec     int      `json:"idle_sec,omitempty"`
}

MessengerDispatch is the worker-side resident messenger request.

type MessengerSnapshot

type MessengerSnapshot struct {
	Status       string              `json:"status"`
	StartedAt    int64               `json:"started_at,omitempty"`
	LastUsedAt   int64               `json:"last_used_at,omitempty"`
	IdleDeadline int64               `json:"idle_deadline,omitempty"`
	Deliveries   []MessengerDelivery `json:"deliveries,omitempty"`
	StderrTail   string              `json:"stderr_tail,omitempty"`
}

MessengerSnapshot is the worker's resident messenger state (mirrors messenger.Snapshot; wsproto stays free of that import).

type Outcome

type Outcome struct {
	JobID            string          `json:"job_id"`
	RenderedCommand  string          `json:"rendered_command,omitempty"`
	ResultJSON       string          `json:"result_json,omitempty"`
	DiffSummary      string          `json:"diff_summary,omitempty"`
	UncommittedFiles []string        `json:"uncommitted_files,omitempty"`
	UncommittedCount int             `json:"uncommitted_count,omitempty"`
	Artifacts        json.RawMessage `json:"artifacts,omitempty"`
	// SessionID 是 worker 侧本地 JobResult 捕获/注入得到的 agent 会话标识(P3),随
	// Outcome 帧回传 host,host 端 applyOutcome 落到 entry.result.SessionID。空=未捕获。
	SessionID string `json:"session_id,omitempty"`
	// WT-01:worker 侧受管 worktree 的位置与分支状态(该路径在那台机器上)。旧 worker
	// 不发这组字段 → host 行保持无 worktree(不伪造)。
	WorktreePath    string `json:"worktree_path,omitempty"`
	WorktreeBranch  string `json:"worktree_branch,omitempty"`
	WorktreeBaseSHA string `json:"worktree_base_sha,omitempty"`
	WorktreeHeadSHA string `json:"worktree_head_sha,omitempty"`
	CommitsAhead    int    `json:"commits_ahead,omitempty"`
	// BaseSHA / Commits are the SUP-01 C提交采集 captured on the worker (the host has
	// no checkout there): the commit the job started from and what it produced,
	// newest first. An old worker never sends them → the host row stays empty (the
	// capture is not faked).
	BaseSHA string   `json:"base_sha,omitempty"`
	Commits []Commit `json:"commits,omitempty"`
	// Verify (SUP-01 B) is the verification step's result: the worker ran it in ITS
	// checkout, so its structured outcome travels here. Nil = the job had no step
	// (the hub refuses a verify dispatch to a worker that cannot run it, so a nil
	// here never means "the step was dropped").
	Verify *VerifyResult `json:"verify,omitempty"`
	// Usage (SUP-01 E) is the token/cost accounting the worker captured for the job:
	// the agent's numbers live in the log stream / stderr tail on THAT machine, so
	// they travel with the outcome like the commits and the verify verdict. Nil = the
	// worker captured none.
	Usage *Usage `json:"usage,omitempty"`
	// Xfer is the job's file-transfer summary as the WORKER computed it (XFER-01 X2):
	// the uploads it placed before the agent ran and the files its collect globs
	// matched afterwards. Raw JSON so wsproto stays a leaf (job owns the summary type)
	// and so the hub forwards it verbatim into jobs.xfer_json. Nil = the job carried no
	// files (and an old worker never sends it at all).
	Xfer json.RawMessage `json:"xfer,omitempty"`
}

Outcome (w→s, P4): the产出与审计 payload the worker captured locally for a job, sent JUST BEFORE the terminal Result frame so the host can apply it before finishing the job (design §6.6 / D6). v1 carries only清单+小结果: rendered command / structured result.json / diff摘要 / artifacts清单 METADATA — the大 产物文件本身留 worker 侧(不进帧). Artifacts stays raw JSON so wsproto need not import job (job owns ArtifactItem). The frame is OPTIONAL: an old worker that never sends it leaves the host job outcome empty (回归红线, the hub's read loop safely ignores an unknown opcode regardless).

type Ping

type Ping struct {
	TS int64 `json:"ts"`
	// Messenger and Dirs are additive worker-state reports (v16): a worker attaches
	// them to its own heartbeat so the hub's view stays fresh without a new frame.
	// A hub or worker that does not know them ignores the keys; an older worker
	// never sends them, which the console shows as "unknown".
	Messenger *MessengerSnapshot `json:"messenger,omitempty"`
	Dirs      *WorkDirs          `json:"dirs,omitempty"`
}

Ping/Pong (both, P3): heartbeat / half-open detection.

type Policy

type Policy struct {
	Rev      int64           `json:"rev"`
	Projects []PolicyProject `json:"projects"`
}

Policy (s→w): the full set of projects a worker may run at revision Rev. Rev is the config generation (monotonic); the worker applies latest-wins and reports the Rev it converged to in Applied.

type PolicyProject

type PolicyProject struct {
	Key      string `json:"key"`
	HostPath string `json:"host_path"` // 逻辑路径; the worker maps it onto a local root
	// AllowedAgents: computePolicy guarantees a NON-nil value (T3). The wire form of an
	// empty list may still be null (a Go nil slice marshals to null even without
	// omitempty), so a DOWNSTREAM consumer must treat null and [] as equivalent — judge
	// by len, never by nil-ness (MEDIUM-1).
	AllowedAgents []string `json:"allowed_agents"`
	// AllowInteractive is the project's interactive-job switch (AGT-02 §2), sent as
	// the RESOLVED value (ProjectConfig.IsInteractiveAllowed). It stays a pointer only
	// for wire symmetry with CaptureDiff below: an absent field is read as "no
	// interactive jobs" — the pre-AGT-02 narrowing list that used to fill that gap
	// (interactive_allowed_agents) was removed in v0.47 (G032: that server/worker
	// pairing is no longer deployed).
	AllowInteractive *bool `json:"allow_interactive,omitempty"`
	AllowExec        bool  `json:"allow_exec"`
	// MaxConcurrentJobs uses omitempty (H2): "not sent" == 0 == unlimited concurrency.
	MaxConcurrentJobs int `json:"max_concurrent_jobs,omitempty"`
	// CaptureDiff is *bool (H2): "not sent" (nil) == default-on; only a present false
	// is an explicit opt-out. Same "unset ≠ explicit false" reason as AgentBrief.Available.
	CaptureDiff       *bool    `json:"capture_diff,omitempty"`
	OnUncommitted     string   `json:"on_uncommitted,omitempty"`
	UncommittedIgnore []string `json:"uncommitted_ignore,omitempty"`
	// MaxTimeoutSec is the RESOLVED job-timeout ceiling for this project
	// (config.Config.EffectiveMaxTimeoutSec: the project's max_timeout_sec, else the
	// server's max_job_timeout_sec, else 1h — bd h-aii-s9ck). The server already
	// clamped the dispatched timeout_sec, so the worker applies THIS value as its own
	// clamp ceiling and the second clamp becomes a no-op instead of silently
	// re-clamping an admitted timeout against a worker-local default. omitempty: a
	// pre-change server sends nothing (0) and the worker falls back to its own config.
	MaxTimeoutSec int `json:"max_timeout_sec,omitempty"`
	// Approval is the project's RESOLVED approval gate (GATE-01 §1) — the worker
	// needs it because the acp-agent job runs THERE and the gate is decided at
	// permission-request time. omitempty: a pre-GATE server sends nothing (nil) and
	// the worker falls back to its own default (off).
	Approval *ApprovalPolicy `json:"approval,omitempty"`
}

PolicyProject is one project entry in a pushed Policy: the server-side identity + guards for a project a worker may run.

type Pong

type Pong struct {
	TS int64 `json:"ts"`
}

type ProjectDir

type ProjectDir struct {
	Key    string `json:"key"`
	Path   string `json:"path"`
	Exists bool   `json:"exists"`
}

ProjectDir is the directory a served project resolved to on the worker.

type Register

type Register struct {
	WorkerID string `json:"worker_id"`
	// InstanceID is a per-PROCESS nonce minted once at worker start and reused
	// across reconnects. It lets the hub tell a transient network reconnect (same
	// instance → in-flight jobs survive, supersede exemption applies) from a worker
	// RESTART (new instance under the same worker_id → the old process's in-flight
	// jobs died with it and must be failed, not exempted). Empty on old workers →
	// the hub falls back to the legacy supersede-always behaviour (z8ow).
	InstanceID string `json:"instance_id,omitempty"`
	// ProtocolVersion is the worker's capability-frame version (0 = pre-federation
	// worker → below the floor, rejected by the hub gate). A worker sets it to
	// wsproto.CurrentProtocolVersion — the version IT implements, which the hub keeps
	// per connection to negotiate optional features (it may be older than the hub's).
	ProtocolVersion     int      `json:"protocol_version,omitempty"`
	PtyCapable          bool     `json:"pty_capable,omitempty"`
	OS                  string   `json:"os,omitempty"`
	Arch                string   `json:"arch,omitempty"`          // runtime.GOARCH
	Hostname            string   `json:"hostname,omitempty"`      // os.Hostname() — identifies the machine (NAT-safe, unlike the conn's remote addr)
	GoferVersion        string   `json:"gofer_version,omitempty"` // buildinfo.DisplayVersion
	StartedAt           int64    `json:"started_at,omitempty"`    // worker process start, unix sec
	Labels              []string `json:"labels,omitempty"`
	Projects            []string `json:"projects,omitempty"`
	InteractiveProjects []string `json:"interactive_projects,omitempty"`
	// Agents stays the bare key list (validation / selector, back-compat); AgentCaps
	// carries the typed detail (type/interactive) the UI cascade needs. A new worker
	// sends BOTH (the key redundancy is accepted; Agents is dropped once every
	// consumer reads AgentCaps).
	Agents        []string     `json:"agents,omitempty"`
	AgentCaps     []AgentBrief `json:"agent_caps,omitempty"`
	MaxConcurrent int          `json:"max_concurrent,omitempty"`
	// MessengerStatus is the worker's resident messenger state at registration.
	MessengerStatus string `json:"messenger_status,omitempty"`
	// Tools (CFG-16) are the external tools the worker declares as installed on its
	// machine — descriptive only (shown on the runners views; the worker itself lists
	// them in its jobs' prompts), never used for routing. Optional field, no protocol
	// bump: an old hub ignores the key, an old worker sends none.
	Tools []ToolBrief `json:"tools,omitempty"`
	// UpgradeID is set by a worker process that was started by a binary upgrade
	// handover (Upgrade.RequestID). Additive: the hub treats a register carrying it
	// as the upgrade's success signal.
	UpgradeID string `json:"upgrade_id,omitempty"`
	// Inflight (w→s, RECOV-01) is the worker's view of the jobs it currently
	// tracks for this hub: the remote job_id, its local status and the byte
	// offsets/seq it has ALREADY pushed on the wire. The hub uses it on a
	// same-instance reconnect to decide, per recovering job, whether the worker
	// still has the job (→ resume + replay from the server's offsets), has it but
	// already finished (→ wait for the replayed Result) or no longer has it
	// (→ fail at once, "worker no longer tracks job").
	//
	// NO omitempty on purpose: a nil slice means "a pre-RECOV-01 worker that cannot
	// prove anything" (the hub then falls back to the recovery-window timer), while
	// an EMPTY slice means "a new worker that tracks nothing" — and those two must
	// not be conflated, or a worker that dropped all its jobs would silently keep
	// the server waiting instead of failing them. Same absent≠empty reasoning as
	// AgentBrief.Available. The addition does NOT bump protocol_version: an old
	// server ignores the unknown key (As is a plain json.Unmarshal).
	Inflight []InflightJob `json:"inflight"`
}

Register (w→s, P1): the worker announces its identity + capability snapshot on connect. The hub validates worker_id against the token binding (review #1) AND rejects a worker whose ProtocolVersion < wsproto.MinProtocolVersion (hard incompatibility + upgrade prompt). AgentCaps/Projects are now AUTHORITATIVE for validation+routing (was display-only); the worker still re-validates locally on dispatch (review #8).

type Registered

type Registered struct {
	Accepted   bool   `json:"accepted"`
	Reason     string `json:"reason,omitempty"`
	ServerTime int64  `json:"server_time"`
	// ProtocolVersion is the protocol version the SERVER implements (Q7-b). A worker
	// reads it to negotiate optional server-side features. It is additive: an OLD
	// server never sets it, so As[Registered] decodes the absent key to 0 — a worker
	// must treat 0 as "server predates this field", never as a real version.
	ProtocolVersion int `json:"protocol_version,omitempty"`
	// Policy, when non-nil, is the authoritative policy the server pushes together
	// with the ack so a freshly registered worker converges without a second frame
	// (catch-up on register). Nil on old servers / when policy push is off. The frame
	// carrying + apply behaviour is implemented later (T4); T0 only declares the field
	// so the wire is stable.
	Policy *Policy `json:"policy,omitempty"`
	// Resume (s→w, RECOV-01) lists the jobs this hub is holding in `recovering` for
	// the registering worker process and has decided to resume from. It is carried on
	// the ack so the worker can rewind its log offsets BEFORE it resumes streaming —
	// a second frame would race the worker's own replay. Empty/nil on an old server
	// or when nothing is recovering (the fields are optional, no version bump).
	Resume []ResumeJob `json:"resume,omitempty"`
}

Registered (s→w, P1): handshake ack. ServerTime is in milliseconds (SR102, in line with the /v1 envelope convention).

type Reload

type Reload struct {
	RequestID string `json:"request_id"`
	Reason    string `json:"reason,omitempty"`
}

Reload (s→w): ask the worker to re-read its local config and re-report what it can do. It is an RPC REQUEST, not a fire-and-forget signal: RequestID is the only thing that ties the worker's ReloadResult back to this call, so the caller (which is blocking a synchronous HTTP request on the answer) can tell ITS reply apart from any other reload happening on the same connection. Reason is free text for logs/audit only.

type ReloadResult

type ReloadResult struct {
	RequestID string `json:"request_id"`
	OK        bool   `json:"ok"`
	Err       string `json:"err,omitempty"`
	Caps      *Caps  `json:"caps,omitempty"`
}

ReloadResult (w→s): the reply to exactly one Reload, echoing its RequestID.

OK=false means the worker REFUSED the new config (bad YAML, invalid agent, …) and is still running the OLD one unchanged — the reload failed, but the worker did not degrade; Err carries the reason so the caller can surface it instead of answering "accepted" and losing the error. OK=true carries the resulting Caps, so a successful reload updates the hub's view of the worker in the same frame (no separate broadcast needed, no window where the hub routes on stale caps).

ok has NO omitempty on purpose: false is the meaningful value here (a dropped "ok":false would decode as the zero value anyway, but the explicit key keeps the wire self-describing for logs and for any non-Go peer).

type Result

type Result struct {
	JobID     string `json:"job_id"`
	Status    string `json:"status"`
	ExitCode  int    `json:"exit_code"`
	Error     string `json:"error,omitempty"`
	StartedAt int64  `json:"started_at,omitempty"`
}

Result (w→s, P1): the authoritative terminal outcome for a job.

type ResumeJob

type ResumeJob struct {
	JobID     string `json:"job_id"`
	StdoutOff int64  `json:"stdout_off,omitempty"`
	StderrOff int64  `json:"stderr_off,omitempty"`
}

ResumeJob is one entry of Registered.Resume: a job the hub is holding in `recovering` and the worker must resume (RECOV-01). The offsets are the SERVER-side durably written byte counts — the authoritative source — so the worker rewinds its local read offsets to them and re-sends whatever was lost while the connection was down (no gaps, no duplicates beyond the rewind point).

type SessionCommand

type SessionCommand struct {
	JobID  string `json:"job_id"`
	CmdID  string `json:"cmd_id"`
	Action string `json:"action"` // say | end
	Prompt string `json:"prompt,omitempty"`
}

SessionCommand (s→w, protocol v13) asks the worker to continue or end a resident ACP session. CmdID is the idempotency key for reconnect retries.

type Status

type Status struct {
	JobID          string `json:"job_id"`
	Status         string `json:"status"`
	StartedAt      int64  `json:"started_at,omitempty"`
	TurnNo         int    `json:"turn_no,omitempty"`
	IdleDeadlineAt int64  `json:"idle_deadline_at,omitempty"`
	SessionStatus  string `json:"session_status,omitempty"`
	// SessionID is the agent's session id once the worker has opened it, so the
	// host can offer `job resume` even if the worker dies before its Result frame.
	SessionID string `json:"session_id,omitempty"`
}

Status (w→s, P1): an optional status hint. result is the authoritative terminal state; the hub records status but does not drive the terminal flip from it (WP1).

type ToolBrief added in v0.140.0

type ToolBrief struct {
	Name string `json:"name"`
	Desc string `json:"desc,omitempty"`
	Bin  string `json:"bin,omitempty"`
}

ToolBrief is one declared tool on the wire (CFG-16): the name the agent sees, an optional one-line description and the executable (empty = the name).

type TranscriptTail

type TranscriptTail struct {
	ReqID     string `json:"req_id"`
	SessionID string `json:"session_id,omitempty"`
	Path      string `json:"path"`
	MaxBytes  int64  `json:"max_bytes"`
}

TranscriptTail (s→w, protocol v17) asks for the end of one session transcript. Path is the transcript path the SESSION registered (the hub takes it from the session row and never from a caller); the worker still refuses anything that is not a regular .jsonl / .json file, so even a forged request cannot read an arbitrary file.

type TranscriptTailResult

type TranscriptTailResult struct {
	ReqID     string `json:"req_id"`
	OK        bool   `json:"ok"`
	Data      []byte `json:"data,omitempty"`
	Size      int64  `json:"size"`
	Truncated bool   `json:"truncated,omitempty"`
	Error     string `json:"error,omitempty"`
}

TranscriptTailResult (w→s, protocol v17) answers exactly one TranscriptTail. It is ALWAYS sent, failures included (Error carries the reason), because the hub is parked on it. Data starts on a line boundary; Truncated says the file was longer than Data.

type TunnelOpen

type TunnelOpen struct {
	TunnelID   string `json:"tunnel_id"`
	Target     string `json:"target"`
	RelayNonce string `json:"relay_nonce"`
	Network    string `json:"network,omitempty"`
}

TunnelOpen requests a worker to open a TCP tunnel (protocol v5).

type Upgrade

type Upgrade struct {
	RequestID       string `json:"request_id"`
	SHA256          string `json:"sha256"`
	Size            int64  `json:"size"`
	Version         string `json:"version"`
	URLPath         string `json:"url_path"`
	Force           bool   `json:"force,omitempty"`
	DrainTimeoutSec int    `json:"drain_timeout_sec,omitempty"`
	ReadyTimeoutSec int    `json:"ready_timeout_sec,omitempty"`
}

Upgrade asks a worker to fetch and activate a verified replacement binary. The URL is server-relative and is authenticated by the worker token; the worker still verifies Size/SHA256 before touching its current executable.

RequestID doubles as the upgrade id: the replacement process is started with it and echoes it in Register.UpgradeID, which is how the hub knows the handover succeeded. DrainTimeoutSec bounds how long the worker waits for in-flight jobs before it gives up (0 = worker default, 10 minutes); ReadyTimeoutSec bounds how long it waits for the new process to register (0 = default, 60 seconds). Force skips the drain: in-flight jobs are then handled like a worker restart.

type UpgradeResult

type UpgradeResult struct {
	RequestID string `json:"request_id"`
	OK        bool   `json:"ok"`
	Phase     string `json:"phase,omitempty"`
	Error     string `json:"error,omitempty"`
	Version   string `json:"version,omitempty"`
}

type Usage

type Usage struct {
	InputTokens      int64   `json:"input_tokens,omitempty"`
	OutputTokens     int64   `json:"output_tokens,omitempty"`
	CacheReadTokens  int64   `json:"cache_read_tokens,omitempty"`
	CacheWriteTokens int64   `json:"cache_write_tokens,omitempty"`
	TotalTokens      int64   `json:"total_tokens,omitempty"`
	CostUSD          float64 `json:"cost_usd,omitempty"`
	Source           string  `json:"source,omitempty"`
}

Usage is the wire form of a job's token/cost accounting (SUP-01 E). It is declared here (like Commit and VerifyResult) so wsproto stays a leaf that does not import runner/job.

type VerifyResult

type VerifyResult struct {
	// Command is the argv as submitted (element-wise).
	Command []string `json:"command,omitempty"`
	// Status is passed|failed|timeout|skipped.
	Status string `json:"status"`
	// ExitCode is the step's exit status (-1 when it did not end on its own).
	ExitCode int `json:"exit_code"`
	// DurationMs is how long the step ran, in milliseconds.
	DurationMs int64 `json:"duration_ms"`
	// Reason explains a non-obvious status (why it was skipped / timed out).
	Reason string `json:"reason,omitempty"`
}

VerifyResult is the wire form of one job's verify step outcome (SUP-01 B). It is declared here (like Commit) so wsproto stays a leaf that does not import job.

type WorkDir

type WorkDir struct {
	Path   string `json:"path"`
	Exists bool   `json:"exists"`
}

WorkDir is one directory and whether it exists on the worker right now.

type WorkDirs

type WorkDirs struct {
	Workspace *WorkDir     `json:"workspace,omitempty"`
	Roots     []WorkRoot   `json:"roots,omitempty"`
	Projects  []ProjectDir `json:"projects,omitempty"`
}

WorkDirs is where a worker runs things: its default workspace, its roots mapping (POLICY mode) and the directory every served project resolved to.

type WorkRoot

type WorkRoot struct {
	From   string `json:"from"`
	To     string `json:"to"`
	Exists bool   `json:"exists"`
}

WorkRoot is one roots entry (server-side logical prefix -> local path).

type XferUpload

type XferUpload struct {
	XferID string `json:"xfer_id"`
	Dest   string `json:"dest"`
	// Base is the directory Dest is relative to: "" (or "cwd") is the job's working
	// directory — the pre-v10 reading, so an old peer that drops the key behaves
	// exactly as before — and "result_dir" is the job's own result directory (JOB-10
	// mounts a skill there, never in the shared checkout). Additive: only a peer at
	// SkillsMinProtocolVersion or above understands it, which is why the hub sends no
	// base-carrying upload to anyone below (SupportsSkills).
	Base string `json:"base,omitempty"`
}

XferUpload is one staged file a job takes with it (XFER-01 X2): the transfer id the worker fetches the payload with (GET /v1/xfer/{id}/content, its own token) and the destination, relative to Base on THAT machine.

Jump to

Keyboard shortcuts

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