agentremote

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: MIT Imports: 9 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 agentremote runs Sidecar's agent and session verbs on a registered remote host, as one-shot `sidecar <verb> --json` invocations over the ssh ControlMaster the remote-hosts plan already ships (hosts.RunSidecar).

The adapter is at the *verb* level, not at agentcontrol.Terminal level, and that is the whole design. A Terminal-level remote adapter would tunnel Inspect/Capture/Submit across the link and re-run the occupant pin, the readiness contract and the refusal rules on the viewer — over a connection that can stall between the pin and the write. Running the verb on the host instead puts every rule on the machine that owns the pane, and leaves exactly one implementation of them. The viewer composes argv, waits, and decodes.

The consequence worth stating: a remote refusal is the host's own refusal. `sidecar agent` writes the frozen agentcontrol error envelope to stderr, so this package decodes that envelope and returns the *agentcontrol.Error the host produced, with its code, sentence and target intact. Parity with the local path is therefore a property of the transport rather than of a translation table somebody has to keep in step.

Session references stay on the host that owns the provider store. Nothing here writes anything: there is no store, no manifest and no shellstate import, so a remote conversation identifier cannot reach the viewer's shells.json even by mistake. The value crosses only when the caller asks for it explicitly, because the host redacts it by default and this package adds --include-session-ref only when told to.

Index

Constants

View Source
const WaitSlack = 15 * time.Second

WaitSlack is added to a caller's requested agent timeout to produce the deadline of the invocation carrying it.

A wait is the one verb whose useful duration is chosen by the caller rather than bounded by the work, and hosts.RunSidecar replaces an absent deadline with its own 30s default. Without this, `agent wait --timeout 2m` would be killed by the transport at 30 seconds and report a transport timeout for a wait that was proceeding correctly. The slack covers the ssh round trip and the host's own process start, so the *host's* timeout is what expires first and the caller gets the agent-level `timeout` refusal it asked for rather than a severed connection.

Variables

View Source
var ErrNoRunner = errors.New("agentremote: no runner is configured")

ErrNoRunner is returned when a Client was built without a transport. It is a programming error rather than a host condition, so it is not a RunError.

Functions

func TranslateError

func TranslateError(hostID string, err error) error

TranslateError turns a transport failure into the agent error vocabulary.

The first thing it tries is the host's own answer. `sidecar agent` writes an agentcontrol.ErrorEnvelope to stderr for every refusal, and hosts.RunError carries that stderr, so a remote `agent_blocked` can be returned as `agent_blocked` — same code, same sentence, same exit status as if the caller had run it locally. Only when there is no envelope to read does the transport's own classification decide, and then it says so in the host's vocabulary rather than pretending an unreachable machine is a busy pane.

Types

type Client

type Client struct {
	HostID string
	Run    Runner
	// Project scopes every verb to one project on the host. It is the host's
	// own project reference, not a scoped key: the host resolves it against
	// its own registry, and a viewer-side key would be meaningless there.
	Project string
}

Client addresses one registered host.

func (Client) Get

func (c Client) Get(ctx context.Context, session string, includeSessionRef bool) (agentcontrol.Agent, error)

Get reports one agent.

func (Client) GetArgs

func (c Client) GetArgs(session string, includeSessionRef bool) []string

GetArgs builds `sidecar agent get`.

func (Client) List

func (c Client) List(ctx context.Context) ([]agentcontrol.Agent, error)

List reports the host's live managed agents.

func (Client) ListArgs

func (c Client) ListArgs() []string

ListArgs builds `sidecar agent list`.

func (Client) Prompt

func (c Client) Prompt(ctx context.Context, session, text string, wait bool, until []agentcontrol.Status, timeout time.Duration) (agentcontrol.PromptResult, error)

Prompt submits prompt text, optionally waiting for the host to settle.

func (Client) PromptArgs

func (c Client) PromptArgs(session, text string, wait bool, until []agentcontrol.Status, timeout time.Duration) []string

PromptArgs builds `sidecar agent prompt`.

func (Client) Read

func (c Client) Read(ctx context.Context, session string, source agentcontrol.ReadSource, lines int, ansi bool) (agentcontrol.ReadResult, error)

Read passively captures the remote pane or its bound transcript.

Its result carries a Target too, so it is stamped for the same reason every other verb's is: a caller holding reads from two machines has nothing else to tell them apart by, and the host describes itself as "local". This was missed on the first pass — Read was the one verb that returned the host's own view unstamped — and the parity suite caught it.

func (Client) ReadArgs

func (c Client) ReadArgs(session string, source agentcontrol.ReadSource, lines int, ansi bool) []string

ReadArgs builds `sidecar agent read`.

func (Client) SendKeys

func (c Client) SendKeys(ctx context.Context, session string, keys []string) (agentcontrol.Agent, error)

SendKeys writes validated logical keys to the remote agent's UI.

func (Client) SendKeysArgs

func (c Client) SendKeysArgs(session string, keys []string) []string

SendKeysArgs builds `sidecar agent send-keys`.

func (Client) SessionRestore

func (c Client) SessionRestore(ctx context.Context, dryRun, agents, yes bool, shell string) (SessionDocument, error)

SessionRestore performs, or previews, a restore on the host.

func (Client) SessionRestoreArgs

func (c Client) SessionRestoreArgs(dryRun, agents, yes bool, shell string) []string

SessionRestoreArgs builds `sidecar session restore`.

The viewer requests and observes; the host executes. --yes is forwarded only when the caller supplied it, so the host's own `ask` policy still refuses an unconfirmed remote resume rather than the viewer deciding on its behalf.

func (Client) SessionRestoreArgsWithPrefill added in v1.15.0

func (c Client) SessionRestoreArgsWithPrefill(dryRun, agents, yes, prefill bool, shell string) []string

SessionRestoreArgsWithPrefill includes the reviewable no-Enter action.

func (Client) SessionStatus

func (c Client) SessionStatus(ctx context.Context) (SessionDocument, error)

SessionStatus reads the host's ordered restore plan. It is read-only and runs on the host: a viewer never reconstructs another machine's state locally, it asks the machine that owns it.

func (Client) SessionStatusArgs

func (c Client) SessionStatusArgs() []string

SessionStatusArgs builds `sidecar session status`.

func (Client) Start

func (c Client) Start(ctx context.Context, session, kind string, timeout time.Duration, providerArgs []string) (agentcontrol.Agent, error)

Start launches a provider in an existing remote managed shell. It returns only when the host's own readiness contract is satisfied.

func (Client) StartArgs

func (c Client) StartArgs(session, kind string, timeout time.Duration, providerArgs []string) []string

StartArgs builds `sidecar agent start`. Provider arguments stay separate argv entries after `--`, exactly as the local path keeps them.

func (Client) Wait

func (c Client) Wait(ctx context.Context, session string, until []agentcontrol.Status, timeout time.Duration) (agentcontrol.Agent, error)

Wait blocks until the host reports a settled state or its own timeout expires.

func (Client) WaitArgs

func (c Client) WaitArgs(session string, until []agentcontrol.Status, timeout time.Duration) []string

WaitArgs builds `sidecar agent wait`.

type Runner

type Runner func(ctx context.Context, hostID string, args []string, out any) error

Runner is the one-shot remote CLI seam. Production binds hosts.Registry.RunSidecar; tests bind a recorder.

It is a function rather than an interface so a test can be three lines, and so this package needs no knowledge of how a host was registered or dialled.

type SessionDocument

type SessionDocument map[string]any

SessionDocument is a host's restore plan or restore result, relayed whole.

It is a map rather than a struct because the viewer has no decision to make about the contents — it is relaying, not interpreting, and re-modelling the host's schema here would create a second copy of it that drifts. It is a named type rather than a bare map so it can carry ValidRemoteResult.

func (SessionDocument) ValidRemoteResult

func (d SessionDocument) ValidRemoteResult() bool

ValidRemoteResult tells the transport's decoder which JSON object on stdout is the document.

This is not defensive: without it the relay returns the wrong object, and the loopback suite caught it doing so. `session status --json` is *indented*, and hosts.decodeRemoteResult scans stdout for lines that begin an object and tries them last-first — correct for a result printed after banner noise, and exactly wrong for a pretty-printed document whose every nested object starts its own line. The last such line is the final element of "steps", which decodes perfectly well, so the viewer received one step of the plan wearing the whole document's place.

resumePolicy is the discriminator because both document shapes carry it without omitempty (planDocument and resultDocument in internal/cli/session.go) and no individual step or outcome has the field, so a fragment can never satisfy it.

Jump to

Keyboard shortcuts

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