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
- type CountingWriter
- type Files
- func (f *Files) Close() error
- func (f *Files) Read(path string) ([]byte, sftpsvc.Version, error)
- func (f *Files) ReadContext(ctx context.Context, p string, maxBytes int64) ([]byte, sftpsvc.Version, error)
- func (f *Files) ResolvePath(ctx context.Context, p string) (string, error)
- func (f *Files) Write(path string, data []byte, was sftpsvc.Version) (sftpsvc.Version, error)
- func (f *Files) WriteContext(ctx context.Context, path string, data []byte, was sftpsvc.Version) (sftpsvc.Version, error)
- type Options
- type Runner
Constants ¶
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 ¶
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.
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 ¶
OpenFiles starts SFTP on the host's pooled connection. Closing Files does not close the connection.
func OpenFilesContext ¶
OpenFilesContext cancels subsystem negotiation without closing shared SSH.
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 ¶
ResolvePath checks every component before policy authorization.
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 (*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 ¶
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.