Documentation
¶
Overview ¶
Package agent is SSHYard's built-in assistant: one host, one tool loop, every call checked by a policy.Gate. A Session is not safe for concurrent Turn and Continue; cancel with the context instead.
Index ¶
- Constants
- Variables
- func OnlyChanges(diff string) string
- func ToolDefs() []llm.Tool
- func ToolDefsFor(t Target) []llm.Tool
- func Unified(path, oldText, newText string) string
- func WrapUntrusted(source, body string) string
- type Config
- type Event
- type HostMeta
- type Kind
- type Session
- func (s *Session) AbandonPause()
- func (s *Session) CanRetry() bool
- func (s *Session) Configure(gate policy.Gate, redact bool, maxToolCalls *int)
- func (s *Session) Continue(ctx context.Context, emit func(Event)) error
- func (s *Session) History() []llm.Message
- func (s *Session) InterruptTurn()
- func (s *Session) Paused() bool
- func (s *Session) Retry(ctx context.Context, emit func(Event)) error
- func (s *Session) Turn(ctx context.Context, user string, meta HostMeta, terminal string, ...) error
- func (s *Session) TurnWith(ctx context.Context, user string, parts []llm.Part, meta HostMeta, ...) error
- type Streamer
- type Target
- type ToolCard
- type Tools
- type Unavailable
Constants ¶
const DevicePrompt = "You are SSHYard's built-in assistant for exactly one network device or console, reached over Telnet or a serial port. " +
"You help the user operate that device and no other. It has no shell and no file access for you: only its own command line." +
terminalRules +
"Find the vendor and mode from the prompt in pane_output, or with show version or display version, and use that vendor's syntax. " +
"\"--More--\" pages are turned for you; for long output you may first turn paging off for this session only " +
"(terminal length 0, screen-length 0 temporary, or set cli screen-length 0). " +
"Do not save the configuration unless the user asked. " + rules
DevicePrompt is the instruction for a network device or console reached over Telnet or a serial port.
const MaxPartBytes = 30 << 20
MaxPartBytes is the most the files attached to a conversation weigh together in one request; older ones give way to newer ones.
const MaxToolCalls = 25
MaxToolCalls is how many tool calls one turn runs before it pauses, for a Config that names none.
const SSHTerminalPrompt = "You are SSHYard's built-in assistant for exactly one SSH host. " +
"You help the user operate that host and no other. You work in the user's own terminal on it, " +
"so what you type runs as whoever that terminal is now, after su or sudo -i too." +
terminalRules +
"Prefer commands that finish by themselves and print plain text: avoid pagers and full-screen programs (use --no-pager or | cat). " +
"Leave the terminal's user and directory as they were unless the task needs them changed. " + rules
SSHTerminalPrompt is the instruction for an SSH host worked on through the user's terminal on it rather than channels of the assistant's own.
const ShellPrompt = "You are SSHYard's built-in assistant for exactly one terminal: a shell on the user's own computer. " +
"You help the user with that terminal and no other; commands run in the user's shell, with its environment and working directory." +
terminalRules +
"Prefer commands that finish by themselves and print plain text: avoid pagers and full-screen programs (use --no-pager or | cat). " + rules
ShellPrompt is the instruction for a terminal on the user's own computer.
const SystemPrompt = "You are SSHYard's built-in assistant for exactly one SSH host. " +
"You help the user operate that host and no other. " + rules
SystemPrompt is the built-in assistant's instruction. It names one host and tells the model that marked data is not the user's intent.
Variables ¶
var ErrPaused = errors.New("agent: paused at the tool call limit")
ErrPaused is returned when a turn stops after its tool-call limit. Continue resumes it.
Functions ¶
func OnlyChanges ¶
OnlyChanges drops the unchanged context lines of a unified diff.
func ToolDefs ¶
ToolDefs is the built-in assistant function set. Host metadata is already attached to the session; the remaining names match sshyard-remote MCP tools.
func ToolDefsFor ¶ added in v0.0.26
ToolDefsFor is the function set of target t. The terminal targets type into the linked terminal: they have no files and no command channel.
func Unified ¶
Unified is a unified diff of oldText and newText for path. A new file (oldText empty) is the full new text. Identical text is empty. Unchanged runs are collapsed to diffContext lines around each change.
func WrapUntrusted ¶
WrapUntrusted marks body as data from source. A closing marker inside the body is escaped so the boundary stays intact.
Types ¶
type Config ¶
type Config struct {
Model Streamer
Gate policy.Gate
Tools Tools
Redact bool
MaxChars int
// Target is what the tools reach; zero is an SSH host.
Target Target
// MaxToolCalls caps the tool calls one turn runs before it pauses.
// Nil keeps MaxToolCalls; a pointer to 0 runs without a limit.
MaxToolCalls *int
}
Config builds a Session. A nil Tools uses Unavailable.
type Event ¶
Event is one thing the UI timeline shows. Tool is set for EventTool; Calls, for EventPause, is the tool calls the turn has run.
type HostMeta ¶
type HostMeta struct {
Name string
Address string
User string
Uname string
Distro string
Cwd string
// Protocol says how a terminal target is reached, as "Telnet", "serial
// port COM3" or "local shell zsh"; unused for SSH.
Protocol string
// Provider, Renewal and Note are what the user keeps of the host:
// who rents it out, its subscription as a line ("renews every 1
// months since 2026-10-01; next renewal 2026-11-01, in 3 days") and
// their note, which is sent as untrusted data.
Provider string
Renewal string
Note string
// TermUser is who an SSH host's linked terminal switched to with su
// or sudo -i: a name, else "uid N"; empty while it runs as the login.
TermUser string
}
HostMeta is the host context attached once per session.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is one built-in agent conversation. History lives in memory.
func New ¶
New starts a session with the system prompt. The host context is added on the first Turn.
func Restore ¶
Restore is a session that carries on msgs, as History gave them. A tool call left without its result, as at a pause, is answered "cancelled"; a result without its call is dropped. The host context is sent again with the next Turn.
func (*Session) AbandonPause ¶ added in v1.5.0
func (s *Session) AbandonPause()
AbandonPause ends an idle paused turn without running its remaining calls.
func (*Session) CanRetry ¶ added in v1.6.0
CanRetry reports whether the last turn stopped short of the model's reply, as when the provider failed or could not be reached: the conversation ends with the question or a tool's result.
func (*Session) Configure ¶
Configure updates an idle session after its previous turn has stopped: the gate it asks, whether it redacts, and the tool calls its next turn runs before pausing. A nil maxToolCalls keeps MaxToolCalls.
func (*Session) Continue ¶
Continue runs the tool calls that were held at the pause, then keeps going. It grants another stretch of tool calls. It does nothing when the session is not paused.
func (*Session) History ¶
History is the conversation so far without its system messages, to be kept and given back to Restore. Attached files keep only their names.
func (*Session) InterruptTurn ¶ added in v1.5.0
func (s *Session) InterruptTurn()
InterruptTurn removes the interrupted reply from an idle session, keeping tool calls and results paired along with any required provider state.
func (*Session) Retry ¶ added in v1.6.0
Retry carries on a turn that failed (CanRetry): the tool calls left over run, then the model is asked again. It does nothing otherwise.
type Streamer ¶
type Streamer interface {
Stream(ctx context.Context, req llm.Request, emit func(llm.Event)) (llm.Message, error)
}
Streamer is the model client: one streamed completion in any of its formats.
type Target ¶ added in v0.0.26
type Target int
Target is what a session's tools reach.
const ( // TargetSSH is an SSH host: its files, and commands on their own // channels. TargetSSH Target = iota // TargetDevice is a Telnet or serial terminal: a device's command line. TargetDevice // TargetShell is a terminal on this computer: the user's shell. TargetShell // TargetSSHTerminal is an SSH host worked on by typing into its // linked terminal, as whoever that terminal is now. TargetSSHTerminal )
type ToolCard ¶
type ToolCard struct {
Phase string // "open" while it runs, "done" when it has a result
Status string // "cancel" or "timeout" overrides execution status; Verdict retains the approval source
ID string
Name string
Category string
Risk string
Where string
Command string
Path string
Dir string
Verdict string // full, auto, reviewer, user, reject, timeout, cancel
Review string // the review model's note, when one was asked
Refusal string
Output string
Diff string
Exit int
DurMS int64
Run bool
}
ToolCard is one tool call on the timeline. Output is truncated to 1 MB. Exit is -1 when no exit code is available.
type Tools ¶
type Tools interface {
Call(ctx context.Context, name string, args json.RawMessage) (output string, exit int, err error)
// ReadFile reads a remote file so write_file can build a diff.
// ok is false when the file does not exist.
ReadFile(ctx context.Context, path string) (text string, ok bool, err error)
}
Tools is the remote tool layer. Call's output is the tool result the model sees.
type Unavailable ¶
type Unavailable struct{}
Unavailable is the tool layer before it is connected.