Documentation
¶
Index ¶
- Constants
- Variables
- func AutoCompleteJSON(input string) string
- func DeleteFilePath(path string) error
- func ExpandGlobs(args []string) []string
- func GlobCompletion(prefix string) []string
- func HistorySearch(prefix string) []string
- func JSONResult(r CmdResult) string
- func ListDirEntryJSON(path string) (string, error)
- func ParseRedirects(line string) (string, []string, string, string, string, bool, bool)
- func ReadDirCompat(dir string) ([]os.DirEntry, error)
- func ReadFileContent(path string) (string, error)
- func RecursiveSync(dir string)
- func RegisterGitExecutor(fn GitExecutor)
- func ResetHistory()
- func ResolvePath(p string) string
- func SetShellEnv(e *Env)
- func SetStoreWriter(s StoreWriter)
- func SplitChains(input string) []chainSegment
- func SplitPipeline(input string) []string
- func SyncDeleteFile(path string) error
- func SyncWriteFile(path, content string) error
- func Tokenize(line string, keepQuotes bool) []string
- func WalkCompat(root string, fn func(path string, info os.FileInfo, err error) error) error
- func WriteFileContent(path, content string) error
- type AutoCompleteResult
- type CmdResult
- type CommandFunc
- type DirEntry
- type Env
- type GitExecutor
- type OutSeg
- type StoreWriter
Constants ¶
const ExitCommandNotFound = 127
ExitCommandNotFound is the exit code for a command (or subcommand/flag) the browser shell can't run. Callers treat it as "needs a real environment" — the signal the escalation path acts on.
Variables ¶
var CmdRegistry = map[string]CommandFunc{}
CmdRegistry maps command names to their implementations.
var ReadOnlyGitSubcommands = map[string]bool{ "status": true, "diff": true, "log": true, "show": true, "branch": true, "remote": true, "ls-files": true, "rev-list": true, "rev-parse": true, "blame": true, "describe": true, "shortlog": true, "tag": true, "symbolic-ref": true, "config": true, "cat-file": true, }
ReadOnlyGitSubcommands is the allowlist of git subcommands the WASM shell answers in-browser. Anything else (add/commit/push/…) stays a 127 so the transactional escalation path can take it to a container.
Functions ¶
func AutoCompleteJSON ¶
AutoCompleteJSON returns completions as a JSON string.
func ExpandGlobs ¶
ExpandGlobs expands glob patterns in arguments.
func GlobCompletion ¶
GlobCompletion returns files matching a glob prefix for tab completion.
func HistorySearch ¶
HistorySearch searches command history for a prefix.
func JSONResult ¶
JSONResult marshals a CmdResult to JSON string.
func ListDirEntryJSON ¶
ListDirEntryJSON returns the JSON representation of directory entries.
func ParseRedirects ¶
ParseRedirects extracts command name, args, and redirect operators from a line. Returns: name, args, stdinFile, stdoutFile, stderrFile, appendStdout, appendStderr
func ReadFileContent ¶
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 RegisterGitExecutor ¶ added in v0.17.20
func RegisterGitExecutor(fn GitExecutor)
RegisterGitExecutor installs the executor backing the shell's "git" command. Passing nil uninstalls it.
func ResetHistory ¶
func ResetHistory()
ResetHistory clears the command history (useful for testing).
func ResolvePath ¶
ResolvePath expands ~ and makes relative paths absolute against cwd.
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 SplitChains ¶ added in v0.17.20
func SplitChains(input string) []chainSegment
SplitChains splits a command line by unquoted && / || / ; separators. Quotes and escapes suppress splitting, and separator characters inside quotes are preserved in the segment text. The first segment carries an empty op; later ones carry the operator that joins them to the previous segment.
func SplitPipeline ¶
SplitPipeline splits a command line by unquoted pipe characters.
func SyncDeleteFile ¶
SyncDeleteFile removes a file from the filesystem (MEMFS) and syncs to the StoreWriter.
func SyncWriteFile ¶
SyncWriteFile writes content to the filesystem (MEMFS) and syncs to the StoreWriter.
func WalkCompat ¶ added in v0.16.25
func WriteFileContent ¶
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"`
Output []OutSeg `json:"output"`
}
CmdResult holds the result of a command execution. Output, when set, is Stdout and Stderr interleaved in the order they were written; a result without it wrote its stdout before its stderr.
func ParseAndExecute ¶
ParseAndExecute runs a shell command line or script: lists, pipelines, redirections, control flow, functions and expansions, over the built-in commands.
type CommandFunc ¶
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 Env ¶
Env holds the shell environment variables.
var ShellEnv *Env
ShellEnv holds the global shell environment.
type GitExecutor ¶ added in v0.17.20
GitExecutor runs a read-only git subcommand ("status", "diff", "log", …) with the raw subcommand args and returns its result. The browser build installs an implementation backed by isomorphic-git; without one, the shell reports git as unavailable (exit 127) — the same signal a WASM shell gives for commands it cannot run, which the escalation surface treats as "run in container".
type StoreWriter ¶
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.
Source Files
¶
- arith.go
- awk_builtins.go
- awk_eval.go
- awk_expr.go
- awk_lex.go
- awk_parse.go
- awk_run.go
- braces.go
- builtins_exec.go
- builtins_shell.go
- commands.go
- commands_diff.go
- commands_fields.go
- commands_file.go
- commands_fileops.go
- commands_find.go
- commands_fsinfo.go
- commands_git.go
- commands_grep.go
- commands_jq.go
- commands_lines.go
- commands_rg.go
- commands_search.go
- commands_sed.go
- commands_shell.go
- commands_sort.go
- commands_text.go
- commands_xargs.go
- completions.go
- expand.go
- find_expr.go
- glob.go
- grep_opts.go
- interp.go
- interp_control.go
- jq_arrays.go
- jq_builtins.go
- jq_eval.go
- jq_json.go
- jq_lex.go
- jq_ops.go
- jq_parse.go
- jq_strings.go
- lexer.go
- output.go
- params.go
- parser.go
- parser_compound.go
- printf.go
- redirect.go
- sed_exec.go
- sed_parse.go
- shell.go
- store.go
- testexpr.go
- wasm_fs_compat_stub.go