@e4779/shell-gate0.3.0
pi extension: shell command valve — bash parse check + ShellCheck + the gate's own rules before bash runs
Untested on omp
This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.
Reports 0
No reports yet.
Readme
shell-gate
Pre-execution shell hygiene gate for agent shell commands and .sh writes.
Why
Agents write shell fast and sloppy, then burn turns debugging quotes character by character. The gate blocks the sloppy command BEFORE execution and hands diagnostics back to the model as the block reason — the fix loop is one turn, with SC codes in hand.
Layers
bash --norc -n— parse check, always available: unbalanced quotes, broken heredocs, parse errors. The "unexpected EOF" class.- ShellCheck — semantic layer (word splitting, quoting,
rm -rfon empty variables). Hostshellcheckbinary first (BSD hosts ship it at /usr/local/bin); on a machine without it,shellcheck-wasm(this package's npm dependency), run bywasm-lint.tsin a child process, one per lint. In-process that runtime crashed after a run of back-to-back lints and its crash could end the agent process; in its own process every crash dies with the lint that caused it, which alone is skipped, silently. - The gate's own rules — ESLint with the
@eslint/shelllanguage, in process (eslint-lint.ts). ShellCheck takes no rule from us; a real shell parser does, and a rule on the syntax tree never trips over a quoted mention. One rule today: a tmux command names its socket (-L <name>,-S <path>or aTMUX_TMPDIR=prefix), on commands and.shwrites alike. A baretmuxlands on whichever server the environment picks, and-L defaultis that same socket. Blind spots: a wrapper (command tmux, a function defined elsewhere,eval) and a script-wideexport TMUX_TMPDIR=— name the socket per command instead.
Every layer fails open: any internal error passes the command through.
Bash commands start from a wider suppression list than .sh writes: the
notes that fire on correct one-off commands (unused variables, bare globs,
ls | grep, single-quoted $x, a && b || c) do not block a command,
while word splitting, rm -rf on an unquoted variable and cd x; … (a
failed cd runs the next command in the wrong directory) still do. The list is
DEFAULT_CMD_SUPPRESSED in index.ts; commandSuppressedCodes in the
config replaces it.
What it does NOT catch
Syntactically clean but operationally dangerous commands (git clean -fd,
pkill -f self-matches, blind send-keys). Shell hygiene is not operational
safety — that is a different gate.
Escape hatches
- The model may prepend
# shellcheck disable=SCxxxxdirective lines to confirm an intentional pattern (plain bash comments; ShellCheck respects them). The block reason lists the exact codes to use, and a byte-identical retry passes. The gate's own rules have neither way round: their switches are"eslint": falsein the config and, for tmux, aTMUX_TMPDIRalready set in the agent's environment. PI_SHELL_GATE=offdisables the gate for a session.~/.pi/agent/shell-gate.jsontunes thresholds — see the header ofindex.tsfor every key.
User !-bash (the user_bash event) is never gated.