Documentation
¶
Index ¶
- Variables
- func BuiltinPluginNames() []string
- func DefaultCommands() []string
- func MarshalSnapshot(snap *Snapshot) ([]byte, error)
- func RestoreSnapshot(snap *Snapshot) (afero.Fs, string, error)
- type BuiltinFunc
- type CompleteResult
- type Option
- func WithAliases(aliases map[string]string) Option
- func WithAllowExternalCommands(allow bool) Option
- func WithBuiltin(name string, fn BuiltinFunc) Option
- func WithCwd(cwd string) Option
- func WithDisabledPlugins(names ...string) Option
- func WithEnv(env map[string]string) Option
- func WithFS(fs afero.Fs) Option
- func WithInheritEnv(inherit bool) Option
- func WithPlugin(p plugins.Plugin) Option
- func WithPluginBytes(name string, wasm []byte) Option
- func WithPluginFilter(names []string) Option
- func WithStdIO(in io.Reader, out, err io.Writer) Option
- func WithWASMEnabled(enabled bool) Option
- type Shell
- func (s *Shell) Close() error
- func (s *Shell) Commands() []string
- func (s *Shell) Cwd() string
- func (s *Shell) FS() afero.Fs
- func (s *Shell) ListDir(path string) ([]string, error)
- func (s *Shell) LoadMemshrc(ctx context.Context) error
- func (s *Shell) Register(p plugins.Plugin)
- func (s *Shell) RegisteredPlugins() []string
- func (s *Shell) Run(ctx context.Context, script string) error
- type Snapshot
- type SnapshotFile
Constants ¶
This section is empty.
Variables ¶
var ErrExit = errors.New("exit")
Functions ¶
func BuiltinPluginNames ¶
func BuiltinPluginNames() []string
BuiltinPluginNames returns the names of built-in commands available without external plugins (native Go implementations registered at startup).
func DefaultCommands ¶
func DefaultCommands() []string
DefaultCommands returns all command names available in a default shell (static builtins + default native plugins) without creating a Shell instance.
func MarshalSnapshot ¶
MarshalSnapshot serialises snap to JSON.
Types ¶
type BuiltinFunc ¶
BuiltinFunc is a native Go command implementation. ctx carries the interp.HandlerContext — use interp.HandlerCtx(ctx) for per-command I/O. For virtual FS access use shell.ShellCtx(ctx).
type CompleteResult ¶
type CompleteResult struct {
Completions []string `json:"completions"`
Prefix string `json:"prefix"` // input text before the completing token
Token string `json:"token"` // the partial token being completed
}
CompleteResult holds the tab-completion results for a given input.
type Option ¶
type Option func(*Shell)
Option is a configuration function for the Shell.
func WithAliases ¶
WithAliases pre-seeds the alias table (e.g. loaded from a config file).
func WithAllowExternalCommands ¶
WithAllowExternalCommands permits falling back to real OS executables when a command is not found among builtins or plugins. By default this is false, which keeps all execution inside the virtual sandbox.
func WithBuiltin ¶
func WithBuiltin(name string, fn BuiltinFunc) Option
WithBuiltin registers a raw function as a native shell command. Prefer WithPlugin when you want to attach metadata (description, usage).
func WithDisabledPlugins ¶
WithDisabledPlugins removes the named plugins from the shell. Works for both native (builtin) and WASM plugins. Applied after defaults, so it can suppress defaultNativePlugins entries.
func WithInheritEnv ¶
WithInheritEnv controls whether the shell inherits the parent process's environment variables. When false, only explicitly set variables (via WithEnv) are available. Defaults to true for CLI use; should be false in server mode to prevent leaking host secrets to remote users.
func WithPlugin ¶
WithPlugin registers a Plugin as a native shell command. Native plugins take priority over WASM plugins with the same name.
func WithPluginBytes ¶
WithPluginBytes registers a WASM plugin directly from bytes, without needing a file in /memsh/plugins/. The plugin must export command_name() and run().
func WithPluginFilter ¶
WithPluginFilter sets an allowlist of WASM plugin names to load during discovery (/memsh/plugins/ and ~/.memsh/plugins/). When the list is non-empty, only plugins whose names appear in it are loaded. Plugins registered explicitly via WithPlugin or WithPluginBytes are unaffected.
func WithWASMEnabled ¶
WithWASMEnabled controls whether the wazero WASM plugin runtime is started. Pass false to skip all WASM plugin loading (faster startup, no wazero overhead).
type Shell ¶
type Shell struct {
// contains filtered or unexported fields
}
func (*Shell) Commands ¶
Commands returns all command names known to this shell instance: the static builtin list, registered native plugins, and loaded WASM plugins.
func (*Shell) LoadMemshrc ¶
LoadMemshrc sources /.memshrc from the virtual filesystem if it exists. Errors are non-fatal — a missing file is silently ignored.
func (*Shell) RegisteredPlugins ¶
type Snapshot ¶
type Snapshot struct {
Version int `json:"version"`
Cwd string `json:"cwd"`
Files []SnapshotFile `json:"files"`
}
Snapshot is a portable, JSON-serialisable representation of a memsh session: the complete virtual filesystem plus the working directory. File content is stored as raw bytes; the standard encoding/json package encodes []byte as base64 automatically.
func TakeSnapshot ¶
TakeSnapshot walks fs and returns a Snapshot containing every file and directory, together with cwd. It never follows symbolic links.
func UnmarshalSnapshot ¶
UnmarshalSnapshot parses JSON produced by MarshalSnapshot.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package plugins defines the Plugin interface and shell context helpers shared by the shell runtime and all native plugin implementations.
|
Package plugins defines the Plugin interface and shell context helpers shared by the shell runtime and all native plugin implementations. |
|
native
Package native contains the built-in native Go plugins shipped with memsh.
|
Package native contains the built-in native Go plugins shipped with memsh. |