omp packages

@villavic/no-inline-edit1.0.3

Blocks bash calls whose inline interpreter program reads a file and writes content back to the same path, plus in-place editor flags, using tree-sitter AST checks.

villavic Published 8 hours ago MIT ~0 downloads/mo

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.

Did it work for you?

Result

One report per person. A new report replaces your old one.

Reports 0

No reports yet.

Readme

no-inline-edit

Rejects bash calls that read or modify a file by feeding source to an interpreter on the command line, when models intentionally avoid using the harness file tools. Motivation: python -c "open(p,'w').write(...)" carries the file content in the command itself, and no edit tool call is recorded, so the change is invisible to the harness diff and to checkpoints.

What it rejects

A bash call is blocked when an inline interpreter program bypasses the harness file tools in any of three ways:

  1. Read-modify-write: reads or seeks a path and writes content to the same path (regardless of statement order), or reads a path that the shell truncates with > / >|.
  2. Inline-content write: writes inline literal content (including variables holding hardcoded text/scripts, literal expressions, or raw unparsed stdin passthrough) directly to a file via a single-call or handle write API (fs.writeFileSync, File.write, Path.write_text, f.write, f.puts, f << ..., f:write, etc.).
  3. Open-for-write + write: opens a path in a write-permitting mode (w, a, x, r+, w+, a+, O_WRONLY/O_RDWR/O_CREAT, createWriteStream, io.output) and writes to it — unless the program is extracting non-literal data from a different source file.

Inline program flags: python -c, ruby -e/--eval, node -e/-p, lua -e, awk/gawk/mawk positional program or -e/--source, and the same shapes nested in bash -c, pipelines, $( ... ), and behind wrappers (env, nohup, timeout, nice, stdbuf, time, xargs).

Detection is structural. web-tree-sitter parses the command line and the language grammar parses the extracted program text, so a call is identified by its callee, open mode, and payload AST, not by a keyword in the string: print("open is a word") passes, open(p, "w").write(s) does not. Blocked responses steer the caller toward the harness file tools (read, replace, replace_match, insert, write), or writing a multi-step script to disk and executing that file.

What it does not reject

  • Data extraction: parsing another data source (e.g. reading raw.json or querying a database) and writing computed output to a different target path.
  • Pure reads and lone opens with no write (f = open("new.txt", "w"); f.close()).
  • Script files: python x.py, awk -f prog.awk data.
  • Bash and awk redirection alone (echo x > a.txt, gawk 'BEGIN { print "x" > "out.txt" }').
  • In-place editors (sed -i, gsed -i, perl -i): delegated to pi-permission-system.
  • Shell heredocs (<<): @villavic/no-heredoc rejects those.
  • Anything whose grammar is missing or whose parse fails (logged when DEBUG is enabled).

Configuration

None. What passes is decided by the parse alone. An exemption list would be a hole rather than a feature: a prefix pattern such as ^git commit exempts the whole command line, so an inline edit appended to it, or nested in $( ... ) inside it, runs unexamined. To stop blocking, remove the package (pi remove <source>) or launch Pi without -e ./extensions/no-inline-edit/index.ts.

Dependencies

web-tree-sitter is the only runtime dependency. The WASM grammars — bash, python, ruby, javascript, lua, awk — are vendored under extensions/no-inline-edit/grammars/ with their licence texts, because the grammar packages declare a native tree-sitter peer and tree-sitter-lua ships no WASM at all. Resolution order is the vendored file, then this package, then ~/.pi/agent/npm, so a plain pi -e ./extensions/no-inline-edit/index.ts works from a checkout.

Verify

npm run typecheck
node lab/probes/p98-inline-gate.mjs   # 97 shapes, PASS/FAIL, exit 1 on FAIL

The probe loads the extension through jiti, evaluates every shape in lab/probes/corpus-inline-edit.json, and prints the verdict with the read and write forms that triggered it. It needs no model and no sandbox.

Debug log

While DEBUG is true at the top of index.ts, every bash call the extension sees is appended to ~/.pi/agent/extensions/no-inline-edit/logs/gate-YYYY-MM-DD.jsonl, one JSON object per line. Calls it allows are recorded too — that is the point. A shape the gate does not catch looks exactly like an extension that never ran, and only a record tells those two apart.

The toggle is that constant, not an environment variable: the log belongs to the code under test, so a run and its log cannot disagree about which build produced them. It ships false: flip it to true to trace a session, then set it back before publishing, since an installed copy would write the log for every user.

field what it holds
event load once per process, then bash per call
stage no-command, no-candidate, or analyzed
command, cwd the call as typed
decision block or allow
note why nothing was analyzed at all
unanalyzed languages whose grammar did not load
steps per command: name, program after wrappers, > targets
steps[].bodies inline program: language, clipped source, parsed, bindings
steps[].bodies[].ops each read, seek, open-write (mode) or write (inlinePayload) found, and how it happened
run pid plus start time, separating processes sharing a day

stage: "no-candidate" means the cheap name test rejected the call before any parsing, which is the commonest reason nothing is blocked. A load record lists the wasm file each grammar resolved to; a null there means that language's programs are allowed without analysis.

LOG=~/.pi/agent/extensions/no-inline-edit/logs
tail -n 20 "$LOG/gate-$(date +%F).jsonl" \
  | jq -r '[.stage, .decision // "-", .command] | join("  ")'