Documentation
¶
Overview ¶
Package router routes a command to drop/host/container and executes it, independent of any transport (MCP, CLI). Output is written to the caller's io.Writers.
Index ¶
- Variables
- func Route(cmd string, allow, drop []string) (decision, matched string)
- func Run(ctx context.Context, req Request) (int, error)
- func RunHost(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error)
- func RunHostShell(ctx context.Context, raw string, stdin io.Reader, stdout, stderr io.Writer) (int, error)
- type Config
- type ContainerRunner
- type Line
- type PipelineNode
- type Request
- type Result
- type Router
- type Segment
Constants ¶
This section is empty.
Variables ¶
var ErrSandboxNotRunning = errors.New("sandbox is not running")
ErrSandboxNotRunning signals that a command was routed to the sandbox container but the container is not running. A ContainerRunner returns it (possibly wrapped) so the router can print an actionable message instead of a raw Docker/Compose error. Detect it with errors.Is.
var ErrUnterminatedQuote = errors.New("unterminated quote")
ErrUnterminatedQuote is returned by ParseLine when a quote is never closed.
Functions ¶
func Run ¶ added in v0.9.2
Run routes req.Command per segment and executes the resulting pipelines in sequence, honoring && / || / ; operators between pipelines.
Types ¶
type Config ¶ added in v0.9.2
type Config struct {
AllowPatterns []string
DropPatterns []string
ContainerEnvPassthrough []string
ContainerRunner ContainerRunner // nil allowed (host/drop-only lines)
}
Config holds routing patterns and the optional container runner.
type ContainerRunner ¶ added in v0.9.2
type ContainerRunner interface {
RunContainer(ctx context.Context, argv []string, env []string, stdin io.Reader, stdout, stderr io.Writer) (int, error)
}
ContainerRunner executes an argv inside the sandbox container.
type Line ¶ added in v0.9.2
type Line struct {
Raw string
Pipelines []PipelineNode
Seps []string // "&&" | "||" | ";" (len == len(Pipelines)-1)
Fallback bool
}
Line is a parsed command line: a sequence of pipelines joined by sequential operators. When Fallback is true the line contains a construct we do not split (command substitution or background &) and must run whole.
type PipelineNode ¶ added in v0.9.2
PipelineNode is a sequence of segments joined by "|".
type Request ¶ added in v0.9.2
type Request struct {
Command string
AllowPatterns []string
DropPatterns []string
ContainerRunner ContainerRunner
ContainerEnvPassthrough []string
Stdout io.Writer
Stderr io.Writer
}
Request carries everything Run needs for a single command.
type Router ¶ added in v0.9.2
type Router struct {
// contains filtered or unexported fields
}
Router routes and runs command lines.
func (*Router) NeedsContainer ¶ added in v0.9.2
NeedsContainer reports whether running command requires a container runner. It uses ParseLine to check each segment individually, so a pipeline with any container-routed segment returns true, and a Fallback line always returns true.