Filesystem and process commands

Four namespaces that touch disk or spawn: fs (text files, directories, and the scope that bounds them), store (a JSON key-value file), shell (an allowlisted program), stronghold (an encrypted store). Each is registered by the runtime, so no plugin has to be named.

fs and shell are bounded by config: fs.scope sets the prefixes a path must resolve inside, shell.allow names the programs a page may run. With neither section the filesystem is unbounded and every shell.spawn is refused by name.

fs

commandargumentsanswer
readTextFile{ path }the file's text, as a string
writeTextFile{ path, contents }{ bytes }
readBinary{ path }the file's bytes, as a Uint8Array
writeBinary{ path, bytes }{ bytes }
mkdir{ path }{ path, created }
list{ path }{ entries: [{ name, path, directory, size }] }
stat{ path }{ path, directory, size, modified }
remove{ path, recursive? }{ removed: true, path }
rename{ from, to }{ path } — the destination
scopeListnone{ ok: true, paths, scoped, reason? }
scopeAllow{ path }{ ok: true, paths }
scopeRevoke{ path }{ ok: true, paths }

list answers entries sorted by name, each with a basename and an absolute path, so a page never joins strings. stat reports modified in milliseconds since the epoch. remove deletes a directory only with recursive: true; a non-empty directory without it is refused by the OS. rename checks both ends against the scope: a rename out of a prefix leaks the file as surely as a read. The binary commands bound the same scope: readBinary returns real bytes (the bridge tags them so the page client revives them), writeBinary accepts bytes or a numeric-key object, and mkdir is recursive, answering created: false when the whole chain already existed.

scopeAllow is host-gated. A page may not widen its own boundary, so the command answers outside-scope — before its argument is even read — unless the host built the plugin with grants: "page". The runtime builds it with the default grants: "runtime", so in a running app fs.scopeAllow always refuses; the host grants a prefix through fs.scope in the config, or by constructing createFsPlugin({ allow, grants: "page" }) itself. scopeRevoke stays reachable from a page because it can only take a grant away. scopeList reports scoped: false with a reason when no fs.scope is configured — the boundary is absent, not empty.

Failure codes: bad-request (a path or contents that is not a non-empty string; a scope path that is not absolute), not-found (nothing at that path), outside-scope (the path resolves outside every prefix, through .. or a symlink, or a page asked to widen the scope), handler-error (any other filesystem error, unwrapped).

store

commandargumentsanswer
get{ key }{ ok, path, value, recovered? }
set{ key, value }{ ok, path, key }
delete{ key }{ ok, path, key, existed }
keysnone{ ok, path, keys }
clearnone{ ok, path, cleared }
savenone{ ok, path, keys }

One JSON object under the app's data directory, written atomically on every change. get answers null for a key that was never set, which is also what a stored null reads as. keys is sorted by code unit, so the list is the same on every machine. recovered appears once, on the first answer after a corrupt file was moved aside to store.json.corrupt — it says data was lost rather than leaving a page to mistake the empty store for a missing key.

Failure codes: bad-request (a key that is not a non-empty string, or a value JSON cannot hold unchanged — undefined, a function, a cycle), handler-error (the file could not be written).

shell

commandargumentsanswer
spawn{ program, args?, cwd?, stdin? }{ ok: true, id }
output{ id }{ ok, stdout, stderr, exitCode, signal }
write{ id, data }{ ok: true, bytes }
close{ id }{ ok, closed, id }
kill{ id }{ ok, killed, id }
listnone{ ok: true, ids }

No shell is ever invoked: a page's args reach the program as argv, so nothing is re-parsed as a command line. allow is a set of real paths, resolved once — a basename no longer satisfies it, so a /tmp/echo a page planted is not echo, and a symlink cannot move a program or a cwd out of cwdRoot. stdin: "pipe" gives write something to feed; the default "ignore" reads as immediate EOF. output answers the ring of lines (500 per stream) and still answers after the process exits; records of finished processes are kept for the last 256 ids. close ends stdin, kill sends the signal, and list names only live processes.

spawn has no env in a running app. The argument exists on the plugin, but the shell config section carries only allow and cwdRoot, so the runtime never opts in and a page-supplied env answers env-not-allowed. The opt-in is createShellPlugin({ env: true }) for a host that builds its own plugin; even then the loader and shell names (NODE_OPTIONS, BASH_ENV, ENV, GIT_EXEC_PATH, PYTHONSTARTUP, PERL5OPT, RUBYOPT, LD_PRELOAD, LD_LIBRARY_PATH, every DYLD_*) stay refused one by one, because each turns any allowlisted program into an execution primitive.

Failure codes, all { ok: false, code, message }: invalid-args (a malformed payload, or a program with a null byte), program-not-allowed (not in allow), program-outside-root (a path-form program resolving outside cwdRoot), cwd-not-allowed (a cwd outside cwdRoot or not existing), env-not-allowed, spawn-failed (not on PATH, or the spawn threw), unknown-process (no live or remembered id), no-stdin (the pipe was never opened, or was already closed).

Events: shell-output carries { id, stream, line } for every line, with stream "stdout" or "stderr".

stronghold

commandargumentsanswer
open{ password }{ ok: true, opened: true }
closenone{ ok: true, closed: true }
set{ key, value }{ ok: true, key }
get{ key }{ ok: true, key, value }
delete{ key }{ ok: true, key, deleted }
keysnone{ ok: true, keys }

One JSON file under the app's data directory with every key name and value sealed by AES-256-GCM under a key PBKDF2 derives from the password. Before open every command answers locked. A wrong password on an existing file is bad-password, never a fresh empty store — an empty store reads as "you had nothing saved", which a locked vault must not say. set and delete take a cross-instance lock and re-read the file inside it, so two plugin instances over one vault cannot drop each other's keys. Values are strings only.

Upgrading: the vault used to live at ~/Library/Application Support/crust/stronghold.json for every crust app on the machine. It is now at <app data dir>/stronghold.json, keyed by app id. The legacy shared file is not migrated — its entries are keyed by service and account with no app identity, so copying one into an app root would preserve the cross-app leak this change closes. Secrets stored before this version must be set again; the first launch that creates a per-app vault while the legacy file still exists writes one warn line naming both paths.

Failure codes: locked (no open yet, or a close landed), bad-password, bad-request (a password, key or value of the wrong type), not-found (no entry for that key), corrupt (a value or key name that does not decrypt), io-error.