wasmshell

package
v0.17.8 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BuiltinNames = map[string]bool{
	"ls": true, "cd": true, "pwd": true, "cat": true, "mkdir": true,
	"rm": true, "rmdir": true, "cp": true, "mv": true, "touch": true,
	"echo": true, "head": true, "tail": true, "wc": true, "grep": true,
	"sort": true, "find": true, "tree": true, "clear": true, "help": true,
	"date": true, "whoami": true, "env": true, "export": true, "which": true,
	"type": true, "history": true, "println": true, "basename": true,
	"dirname": true, "realpath": true, "tr": true, "uniq": true,
	"cut": true, "tee": true,
}

BuiltinNames lists all built-in command names.

View Source
var CmdRegistry = map[string]CommandFunc{}

CmdRegistry maps command names to their implementations.

View Source
var ErrEmbeddingDisabled = errors.New("embedding: disabled by mode=off")

ErrEmbeddingDisabled is returned when Mode=Off and Embed() is called.

View Source
var ErrEmbeddingUnavailable = errors.New("embedding: requested provider unavailable")

ErrEmbeddingUnavailable is returned when the requested mode's provider isn't available (e.g. Mode=ONNX but no JS bridge).

Functions

func AutoCompleteJSON

func AutoCompleteJSON(input string) string

AutoCompleteJSON returns completions as a JSON string.

func DeleteFilePath

func DeleteFilePath(path string) error

DeleteFilePath deletes a file.

func ExpandGlobs

func ExpandGlobs(args []string) []string

ExpandGlobs expands glob patterns in arguments.

func GlobCompletion

func GlobCompletion(prefix string) []string

GlobCompletion returns files matching a glob prefix for tab completion.

func HistorySearch

func HistorySearch(prefix string) []string

HistorySearch searches command history for a prefix.

func JSONResult

func JSONResult(r CmdResult) string

JSONResult marshals a CmdResult to JSON string.

func ListDirEntryJSON

func ListDirEntryJSON(path string) (string, error)

ListDirEntryJSON returns the JSON representation of directory entries.

func NewJSEmbeddingAPI added in v0.16.19

func NewJSEmbeddingAPI()

NewJSEmbeddingAPI is a no-op on native builds.

func ParseRedirects

func ParseRedirects(line string) (string, []string, string, string, string, bool, bool)

ParseRedirects extracts command name, args, and redirect operators from a line. Returns: name, args, stdinFile, stdoutFile, stderrFile, appendStdout, appendStderr

func ReadDirCompat added in v0.16.25

func ReadDirCompat(dir string) ([]os.DirEntry, error)

func ReadFileContent

func ReadFileContent(path string) (string, error)

ReadFileContent reads a file and returns its content as a string.

func RecursiveSync

func RecursiveSync(dir string)

RecursiveSync removes deleted files from the store by walking the filesystem. This is a best-effort reconciliation after operations like rm -rf.

func ResetHistory

func ResetHistory()

ResetHistory clears the command history (useful for testing).

func ResolvePath

func ResolvePath(p string) string

ResolvePath expands ~ and makes relative paths absolute against cwd.

func SetEmbeddingMode added in v0.16.19

func SetEmbeddingMode(m EmbeddingMode)

SetEmbeddingMode switches the mode at runtime.

func SetShellEnv

func SetShellEnv(e *Env)

SetShellEnv replaces the global shell environment (useful for testing).

func SetStoreWriter

func SetStoreWriter(s StoreWriter)

SetStoreWriter sets the StoreWriter used for persisting files.

func SplitPipeline

func SplitPipeline(input string) []string

SplitPipeline splits a command line by unquoted pipe characters.

func SyncDeleteFile

func SyncDeleteFile(path string) error

SyncDeleteFile removes a file from the filesystem (MEMFS) and syncs to the StoreWriter.

func SyncWriteFile

func SyncWriteFile(path, content string) error

SyncWriteFile writes content to the filesystem (MEMFS) and syncs to the StoreWriter.

func Tokenize

func Tokenize(line string, keepQuotes bool) []string

Tokenize splits a command line into tokens, respecting quotes and escapes.

func WalkCompat added in v0.16.25

func WalkCompat(root string, fn func(path string, info os.FileInfo, err error) error) error

func WriteFileContent

func WriteFileContent(path, content string) error

WriteFileContent writes content to a file.

Types

type AutoCompleteResult

type AutoCompleteResult struct {
	Completions []string `json:"completions"`
}

AutoCompleteResult holds the JSON response for tab completion.

func AutoComplete

func AutoComplete(input string) AutoCompleteResult

AutoComplete performs tab completion for the given input. It handles: - Command name completion (first token) - File/directory path completion (subsequent tokens) - History search (for empty input or ! commands)

type CmdResult

type CmdResult struct {
	Stdout   string `json:"stdout"`
	Stderr   string `json:"stderr"`
	ExitCode int    `json:"exitCode"`
}

CmdResult holds the result of a command execution.

func ParseAndExecute

func ParseAndExecute(input string) CmdResult

ParseAndExecute is the main entry point for executing a command string. It handles pipes, redirects, and dispatches to the appropriate command.

func RunCommandWithRedirects

func RunCommandWithRedirects(name string, args []string, stdin string, stdoutRedirect *string, stderrRedirect *string, appendStdout bool) CmdResult

RunCommandWithRedirects runs a command with optional redirect support.

type CommandFunc

type CommandFunc func(args []string, stdin string) CmdResult

CommandFunc is the type for all command implementations.

type DirEntry

type DirEntry struct {
	Name string `json:"name"`
	Type string `json:"type"` // "file" or "dir"
	Size int64  `json:"size"`
	Mode uint32 `json:"mode"`
}

DirEntry represents a directory listing entry.

type EmbeddingMode added in v0.16.19

type EmbeddingMode string

EmbeddingMode is the high-level switch for the WASM embedding pipeline. Defaults to ModeAuto: detect at first embed call.

const (
	ModeAuto   EmbeddingMode = "auto"   // detect ONNX bridge at first call; fall back to static if absent
	ModeOff    EmbeddingMode = "off"    // no embeddings; Embed() returns an error
	ModeONNX   EmbeddingMode = "onnx"   // require JS-side __sproutONNX bridge; error if absent
	ModeStatic EmbeddingMode = "static" // use the Go-side static provider only
)

func CurrentMode added in v0.16.19

func CurrentMode() EmbeddingMode

CurrentMode returns the active mode.

type EmbeddingProvider added in v0.16.19

type EmbeddingProvider struct {
	Mode EmbeddingMode
}

EmbeddingProvider is a no-op wrapper on native builds. The real implementation lives in embedding_funcs.go (wasm build tag).

func NewEmbeddingProvider added in v0.16.19

func NewEmbeddingProvider() *EmbeddingProvider

NewEmbeddingProvider returns a no-op wrapper on native builds.

func (*EmbeddingProvider) Embed added in v0.16.19

func (p *EmbeddingProvider) Embed(_ context.Context, _ string) ([]float32, error)

Embed is a no-op on native builds.

type EmbeddingStatus added in v0.16.19

type EmbeddingStatus struct {
	Mode           EmbeddingMode `json:"mode"`
	ONNXAvailable  bool          `json:"onnx_available"`
	ONNXModelName  string        `json:"onnx_model_name,omitempty"`
	ONNXDimensions int           `json:"onnx_dimensions,omitempty"`
	StaticProvider string        `json:"static_provider,omitempty"`
	LastError      string        `json:"last_error,omitempty"`
	InitAtUnixMS   int64         `json:"init_at_unix_ms,omitempty"`
}

EmbeddingStatus is the snapshot of the embedding pipeline's state queryable from both Go and JS.

func GetEmbeddingStatus added in v0.16.19

func GetEmbeddingStatus() EmbeddingStatus

GetEmbeddingStatus returns a snapshot of the current embedding status.

type Env

type Env struct {
	Vars map[string]string
}

Env holds the shell environment variables.

var ShellEnv *Env

ShellEnv holds the global shell environment.

func NewEnv

func NewEnv() *Env

NewEnv creates a new Env with default shell variables.

func (*Env) All

func (e *Env) All() map[string]string

All returns a copy of all environment variables.

func (*Env) Get

func (e *Env) Get(key string) string

Get returns the value of an environment variable, falling back to the OS environment.

func (*Env) Set

func (e *Env) Set(key, value string)

Set sets an environment variable in both the Env map and the OS environment.

type StoreWriter

type StoreWriter interface {
	SaveFile(path, content string)
	DeleteFile(path string)
}

StoreWriter is the interface for persisting file writes/deletes to external storage. In the WASM build, this is backed by IndexedDB. In tests, a no-op is used.

Jump to

Keyboard shortcuts

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