remote

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: AGPL-3.0 Imports: 15 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 remote runs an AI command on a host's existing SSH connection. It implements policy.Exec. A2 keeps a Runner beside the gate: Authorize, then Run, then Done. Runner never dials and never takes a pool reference.

Index

Constants

View Source
const (
	// MaxConcurrent is how many AI commands one host runs at once.
	// A third Run waits. The wait is only a delay: the caller sees
	// it as Run taking longer, or as ctx.Err() if the context ends first.
	MaxConcurrent = 2
	// DefaultCommandTimeout is the limit for one Run when Options is zero.
	// Any other CommandTimeout is clamped to MinCommandTimeout..MaxCommandTimeout.
	// These are not settings: the settings page does not name them.
	DefaultCommandTimeout = 60 * time.Second
	MinCommandTimeout     = 5 * time.Second
	MaxCommandTimeout     = 30 * time.Minute
	// DefaultTurnTimeout is one agent turn, from BeginTurn or the first Run.
	// A positive Options.TurnTimeout is used as given and is not clamped.
	DefaultTurnTimeout = 10 * time.Minute
	// KillGrace is how long a cancel waits after SIGTERM before SIGKILL.
	KillGrace = 5 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CountingWriter

type CountingWriter struct {
	W io.Writer
	// contains filtered or unexported fields
}

CountingWriter counts bytes written through it. Wrap the stdout and stderr passed to Run and add Bytes for audit Done. The process-group marker is removed before it reaches the writers Run was given.

func (*CountingWriter) Bytes

func (c *CountingWriter) Bytes() int64

Bytes is how many bytes Write has accepted.

func (*CountingWriter) Write

func (c *CountingWriter) Write(p []byte) (int, error)

Write writes to W (a nil W discards) and counts the bytes accepted.

type Files

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

Files is the SFTP session a write tool uses. Write takes the Version Read returned and refuses with sftpsvc.ErrChanged when the file's size, mtime, or content sum changed. A zero Version overwrites; pass the Version from Read.

func OpenFiles

func OpenFiles(client *ssh.Client) (*Files, error)

OpenFiles starts SFTP on the host's pooled connection. Closing Files does not close the connection.

func OpenFilesContext

func OpenFilesContext(ctx context.Context, client *ssh.Client) (*Files, error)

OpenFilesContext cancels subsystem negotiation without closing shared SSH.

func (*Files) Close

func (f *Files) Close() error

Close ends the SFTP session.

func (*Files) Read

func (f *Files) Read(path string) ([]byte, sftpsvc.Version, error)

Read returns the file and the version a later Write must pass.

func (*Files) ReadContext

func (f *Files) ReadContext(ctx context.Context, p string, maxBytes int64) ([]byte, sftpsvc.Version, error)

ReadContext bounds allocations and interrupts only this read's SFTP session.

func (*Files) ResolvePath

func (f *Files) ResolvePath(ctx context.Context, p string) (string, error)

ResolvePath checks every component before policy authorization.

func (*Files) Write

func (f *Files) Write(path string, data []byte, was sftpsvc.Version) (sftpsvc.Version, error)

Write replaces path with data when it is still was.

func (*Files) WriteContext

func (f *Files) WriteContext(ctx context.Context, path string, data []byte, was sftpsvc.Version) (sftpsvc.Version, error)

WriteContext cancels only this write session; completed renames are not rolled back.

type Options

type Options struct {
	// CommandTimeout limits one Run. Zero means 60s. Any other value
	// is clamped to 5s–30min.
	CommandTimeout time.Duration
	// TurnTimeout limits one turn. Zero means 10 minutes. A positive
	// value is used as given so a test can be short.
	TurnTimeout time.Duration
}

Options sets the limits for a Runner. Zero uses the defaults.

type Runner

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

Runner runs commands for one host. Two Runners built on the same client share that host's concurrency cap. The turn clock is per Runner.

func New

func New(client *ssh.Client, opt Options) *Runner

New runs commands on client. client is the host's pooled connection.

func (*Runner) BeginTurn

func (r *Runner) BeginTurn()

BeginTurn starts a new turn. Run stops a command when the turn ends. The first Run starts a turn when BeginTurn was not called.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, cmd, dir string, stdout, stderr io.Writer) (int, error)

Run executes cmd with sh -c in its own process group. dir is the remote working directory (empty keeps the server's). A non-zero remote status is the exit code with a nil error. A cancelled context returns -1 and ctx.Err(). A command or turn timeout returns -1 and context.DeadlineExceeded. Cancel and timeout send SSH SIGTERM, then kill the process group, then SIGKILL after KillGrace, and return only once the group is gone.

func (*Runner) RunWithTimeout

func (r *Runner) RunWithTimeout(ctx context.Context, cmd, dir string, stdout, stderr io.Writer, timeout time.Duration) (int, error)

RunWithTimeout preserves this runner's turn clock and shared host quota.

Jump to

Keyboard shortcuts

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