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 WithNetworkLimits(limits network.Limits) Option
- func WithNetworkPolicy(policy network.Policy) Option
- func WithNetworkUsage(usage network.Usage) 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) NetworkUsage() network.Usage
- 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
- type WASMConfig
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 that are already registered at the time the option is applied (i.e. defaultNativePlugins entries).
Precedence note: WASM plugins loaded from the filesystem during discovery (which happens after all options are applied) are NOT suppressed by this option. To exclude a discovered WASM plugin, omit its name from the WithPluginFilter allowlist instead of relying on WithDisabledPlugins.
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 WithNetworkLimits ¶ added in v0.0.13
WithNetworkLimits sets per-shell network usage limits.
func WithNetworkPolicy ¶ added in v0.0.13
WithNetworkPolicy sets outbound networking policy used by builtins/plugins that issue network requests (for example curl and source URL).
func WithNetworkUsage ¶ added in v0.0.13
WithNetworkUsage seeds cumulative network usage for a shell session.
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.
Precedence note: WithPluginFilter only gates filesystem discovery, which runs after all options are applied. WithDisabledPlugins removes already-registered native plugins during option application but does not prevent a same-named WASM plugin from being loaded later by discovery. If both options name the same plugin and you need to suppress it entirely, use WithDisabledPlugins and do NOT include that name in the filter list (i.e. leave it out of the allowlist).
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) NetworkUsage ¶ added in v0.0.13
NetworkUsage returns cumulative network usage tracked by this shell.
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.
type SnapshotFile ¶
type SnapshotFile struct {
Path string `json:"path"`
Mode os.FileMode `json:"mode"`
IsDir bool `json:"is_dir,omitempty"`
Content []byte `json:"content,omitempty"` // nil/absent for directories
}
SnapshotFile represents one node (regular file or directory) in the snapshot.
type WASMConfig ¶ added in v0.0.13
type WASMConfig struct {
// Bytes is the raw WASM module.
Bytes []byte
// ExtraArgs are flags to prepend after the command name (e.g. ["-W0"]).
// Existing flags are checked before insertion to avoid duplicates.
ExtraArgs []string
// ExtraEnv are environment variables to set in the WASI module.
// Format: ["KEY=value", ...]
ExtraEnv []string
}
WASMConfig holds WASM plugin bytes and optional runtime tweaks.
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. |