engine

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 4 Imported by: 1 module, 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 engine defines the seam between mcp-sh and the interpreter that runs scripts. Commands (host commands and in-process builtins) are plain values the engine dispatches to; the engine itself decides syntax, control flow, and sandboxing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	Name    string
	Summary string // one line, shown by list_commands
	Help    string // full help, shown by `help <name>`; falls back to HelpFunc, then Summary
	// HelpFunc fetches help lazily when Help is empty (e.g. from the host).
	HelpFunc func(ctx context.Context) (string, error)
	Source   string // where it comes from, e.g. "host" or "builtin"
	Run      func(ctx context.Context, inv *Invocation) int
	// Replaces is set by Registry.Add when this command took over a name from a
	// command of another source (e.g. a host command named like a builtin).
	Replaces *Command
}

Command is anything the shell can call by name: a host command forwarded to the program, or a builtin implemented in Go.

type Engine

type Engine interface {
	Run(ctx context.Context, script string, cmds Registry, stdio IO) (exitCode int, err error)
}

Engine runs one script to completion and returns its exit status. cmds is the full set of commands the script may call; anything else must fail as "command not found". A non-nil error means the script could not run (syntax error, rejected construct, timeout), not that it exited non-zero.

type IO

type IO struct {
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
}

IO is the standard streams for one script run. Nil Stdin reads as empty, and nil Stdout/Stderr discard.

type Invocation

type Invocation struct {
	Args   []string // arguments, without the command name
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
	Dir    string // shell's current directory, in the engine's virtual namespace
	// FS is the sandboxed filesystem the script may touch, or nil when file access is
	// disabled. Paths are relative to its root (fs.ValidPath form).
	FS fs.FS
	// Resolve turns a shell path (absolute or relative to Dir) into an FS path.
	Resolve func(path string) (string, error)
}

Invocation is one call of a Command.

type Registry

type Registry map[string]Command

Registry is a name-indexed command set. Later registrations win, so a host can override a builtin by registering the same name.

func (Registry) Add

func (r Registry) Add(cmds ...Command)

func (Registry) Lookup

func (r Registry) Lookup(name string) (Command, bool)

func (Registry) Sorted

func (r Registry) Sorted() []Command

Sorted returns the commands ordered by name.

type Reserver

type Reserver interface {
	Reserved(name string) bool
}

Reserver is implemented by engines whose own builtins and keywords take precedence over registry commands of the same name (bash's `test`, `read`, `type`, ...).

Directories

Path Synopsis
Package shengine is the default engine: a POSIX/bash interpreter (mvdan.cc/sh) with every side effect routed through handlers we control.
Package shengine is the default engine: a POSIX/bash interpreter (mvdan.cc/sh) with every side effect routed through handlers we control.

Jump to

Keyboard shortcuts

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