Documentation
¶
Overview ¶
Package executor abstracts "run a command / move a file on a machine". Everything above this layer is target-kind agnostic.
Index ¶
- Constants
- Variables
- func Probe(ctx context.Context, ex Executor) (map[string]any, error)
- func ShellQuote(s string) string
- func Wrap(vmid, cmd, cwd string) string
- type Dialer
- type Error
- type Executor
- type Local
- func (l *Local) Close() error
- func (l *Local) DialTarget(ctx context.Context, addr string) (net.Conn, error)
- func (l *Local) ReadFile(_ context.Context, path string, offset int64) ([]byte, error)
- func (l *Local) Run(ctx context.Context, cmd string, opts RunOpts) (Result, error)
- func (l *Local) WriteFile(_ context.Context, path string, data []byte) error
- type Mock
- func (m *Mock) Close() error
- func (m *Mock) CmdLog() []string
- func (m *Mock) ExitPaneAgent(sess string)
- func (m *Mock) Files() map[string][]byte
- func (m *Mock) PaneText(sess string) string
- func (m *Mock) Probe() map[string]any
- func (m *Mock) ReadFile(_ context.Context, path string, offset int64) ([]byte, error)
- func (m *Mock) Run(ctx context.Context, cmd string, opts RunOpts) (Result, error)
- func (m *Mock) SetPaneLimit(sess, message string) bool
- func (m *Mock) WriteFile(_ context.Context, path string, data []byte) error
- type Pct
- type Registry
- type Result
- type RunOpts
- type SSH
- func (s *SSH) Close() error
- func (s *SSH) DialTarget(ctx context.Context, addr string) (net.Conn, error)
- func (s *SSH) ReadFile(ctx context.Context, path string, offset int64) ([]byte, error)
- func (s *SSH) Run(ctx context.Context, cmd string, opts RunOpts) (Result, error)
- func (s *SSH) WriteFile(ctx context.Context, path string, data []byte) error
Constants ¶
const ( MockPollEnd = "ADK-POLL-END-v2" MockPaneDelimiter = "\x1e---LECTERN-PANE---\x1e" MockDiscoverDelimiter = "\x1e---LECTERN-PS---\x1e" // MockAgentProbeMarker must match sessions.AgentProbeMarker. MockAgentProbeMarker = ": LECTERN-AGENT-PROBE;" )
The mock's half of the interactive-session protocol.
These two literals must match `sessions.PollDelimiter` and `sessions.DiscoverDelimiter`. They are duplicated rather than imported because the sessions package depends on this one; TestMockDelimitersMatchSessions asserts they have not drifted.
const MockDiff = `` /* 205-byte string literal not displayed */
MockDiff is the patch every mock attempt "produces".
const MockNumstat = "4\t1\tapp.py\n"
MockNumstat is the matching --numstat output.
Variables ¶
var ErrNoDial = errors.New("this kind of target cannot forward ports")
ErrNoDial is returned by targets whose loopback cannot be reached this way.
Functions ¶
Types ¶
type Dialer ¶
Dialer is an executor that can open a TCP connection as the target sees it, so "127.0.0.1" means the target's loopback and not the control plane's. It is what lets the control plane carry a connection to a service that only listens on the target's own localhost.
type Error ¶
type Error struct{ Msg string }
Error marks a target that could not be reached at all, as opposed to a command that ran and failed.
type Executor ¶
type Executor interface {
// Run executes a shell command, optionally in cwd, bounded by timeout.
Run(ctx context.Context, cmd string, opts RunOpts) (Result, error)
// ReadFile returns bytes from offset to EOF; empty (not an error) if missing.
ReadFile(ctx context.Context, path string, offset int64) ([]byte, error)
// WriteFile writes data, creating parent directories.
WriteFile(ctx context.Context, path string, data []byte) error
// Close releases any pooled connection.
Close() error
}
Executor is one machine lectern can drive. One instance per target.
type Local ¶
type Local struct{}
Local runs commands on the control-plane host itself.
func (*Local) DialTarget ¶
DialTarget on the control-plane host is an ordinary dial.
func (*Local) ReadFile ¶
ReadFile reads from offset to EOF, treating a missing file as empty — the scheduler polls for an agent log that does not exist yet on every tick.
type Mock ¶
type Mock struct {
// Delay paces the fake agent between events.
Delay time.Duration
// HTTP is the client the fake agent uses for hook callbacks. Tests point it
// at their httptest server's transport; production demo mode uses the default.
HTTP *http.Client
// Intercept, when set, runs synchronously at the top of every Run call.
// It exists purely as a test seam for controlling timing — e.g. blocking
// on a specific command to deterministically create the overlap a
// coalescing test needs — and is never set in production code.
Intercept func(cmd string)
// contains filtered or unexported fields
}
Mock is a scripted fake target. It powers the whole hermetic test suite and LECTERN_MOCK=1 demo mode, and emits REAL claude stream-json shapes so the parser is exercised end to end rather than stubbed out.
Scenario markers in the prompt:
[mock:approval] agent requests a hook approval mid-run (real HTTP) [mock:fail] agent exits non-zero [mock:limit] agent is stopped by its usage limit (Claude's real rejected rate_limit_event + limit result) [mock:slow] agent takes ~3x longer [mock:subtask] agent files a follow-up card through the task hook [mock:note] agent leaves a project note [mock:approve-verdict] agent ends with VERDICT: APPROVE [mock:reject-verdict] agent ends with VERDICT: REQUEST_CHANGES [mock:judge:N] agent ends with JUDGE: attempt N (for judge-task tests) [mock:eval-judge:match|no-match] agent ends with EVAL_JUDGE: MATCH|NO_MATCH (replay eval judge tests)
func (*Mock) ExitPaneAgent ¶ added in v2.4.0
ExitPaneAgent makes a scripted pane's agent quit, leaving a shell prompt.
func (*Mock) Files ¶
Files returns a copy of the fake filesystem, for assertions about what was actually staged onto the target.
func (*Mock) SetPaneLimit ¶ added in v2.4.0
SetPaneLimit scripts a usage limit for an interactive session: the message is printed now, and every message sent while it is set is answered with it again. An empty message lifts the limit, so the next message is worked on.
type Pct ¶
type Pct struct {
VMID string
// contains filtered or unexported fields
}
Pct drives an LXC on this Proxmox node through `pct exec` — no SSH and no per-container keys. The control-plane user needs passwordless sudo for pct. Target kind 'pct', with host holding the vmid.
type Registry ¶
type Registry struct {
// Mock forces every target onto the scripted MockExecutor.
Mock bool
MockDelay time.Duration
// MockHTTP is the client fake agents use for hook callbacks. Tests point it
// at their own server.
MockHTTP *http.Client
// contains filtered or unexported fields
}
Registry hands out one cached executor per target id.
func NewRegistry ¶
NewRegistry builds an executor registry.
func (*Registry) Any ¶
Any returns one cached executor. Tests use it to inspect what reached "the target" without knowing which target id won the race.
type SSH ¶
type SSH struct {
Host string
User string
Port int
KeyPath string
// Wrapper, when set, transforms every command before it is sent. It is how a
// host whose SSH lands somewhere other than the work becomes an ordinary
// target. Two placeholders:
//
// {cmd} the command, POSIX shell-quoted
// {b64} the command, base64-encoded
//
// {b64} is the one to reach for on a Windows host: its SSH server hands the
// line to cmd.exe, which does not understand POSIX quoting, and anything
// that survives that still gets $-expanded by the outer bash. Base64 is
// alphanumeric, so it passes through both untouched:
//
// wsl -e bash -lc "echo {b64} | base64 -d | bash"
//
// A wrapper with no placeholder is treated as a prefix and given the
// shell-quoted command, which is what a POSIX host wants.
Wrapper string
// contains filtered or unexported fields
}
SSH is a remote target reached over SSH. Key auth only, one reused connection with bounded setup and command execution.
func (*SSH) DialTarget ¶
DialTarget rides the SSH connection the executor already holds, which is the same thing `ssh -L` does, without a second process to supervise.
A wrapped target runs its commands somewhere else again — inside a container on the SSH host, say — so the SSH host's loopback is not the loopback the session sees, and forwarding to it would reach the wrong machine's services.
func (*SSH) ReadFile ¶
ReadFile tails from a byte offset.
`tail -c +N` is 1-indexed and streams in big blocks. The obvious `dd bs=1` spelling costs one syscall per byte, which is pathological when a growing agent log is re-read on every poll.