omp packages

pi-avoid-unnecessary-bash0.1.0

Pi extension that nudges the model off bash stand-ins for read, ls, grep, find and edit

developer380 Published 5 days 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

pi-avoid-unnecessary-bash

A Pi extension that nudges the model off bash calls which only reimplement a first-class tool. Fork of @xynogen/pix-nudge, cut down to the one nudge worth keeping.

What it does

Hooks tool_result for the built-in bash tool. When a command is a pure stand-in for read, ls, grep, find or edit, it appends one [bash-nudge] line to that bash result and shows a collapsed ➜ nudge card in the transcript.

[bash-nudge] Reading a file via bash cat/head/tail/sed -n. Use `read` (offset/limit pick lines) instead; bash is for real pipelines.

The line goes on the tool result because that is the channel the model actually reads; the card is for you and never reaches the model.

What counts as a stand-in:

shell idiom tool
cat, head, tail, less, more, bat, sed -n '10,40p' read
ls, tree, exa, eza ls
grep, rg, ag, ack grep
find, fd, fdfind find
sed -i, perl -i edit

Detection notes:

  • A trailing | head / | tail only trims output, which the tools' own limit/offset options already do, so grep -rn foo . | head still counts as a grep stand-in. The same goes for a chain of them.
  • A command that genuinely feeds a pipe or is fed by one (cat x | jq ., grep x a | sort | uniq -c) is real shell work and is left alone.
  • Chaining-dodges (cat x || ls y, ls; pwd) are still stand-ins; the clean segment is the one that gets nudged.
  • Environment prefixes (FOO=bar grep x), a leading backslash (\grep), and operators inside quotes (rg -n 'a|b' src) are all understood.
  • Commands that do more than the tool does stay in bash: tail -f (follows a growing file), find … -delete / -exec, piped sed, and anything with a redirect or subshell.
  • perl -i is recognised in every form that really edits — -pi, -i.bak, -0777i, -w -i, and with the file or script in any order. Perl's short options are parsed as clusters (so -Ilib, whose argument could otherwise pass for i, is not mistaken for in-place) and parsing stops at the script name, so a -i that is really an argument to -e is not counted.

What is not detected

Writing a file from bash is only caught for sed -i and perl -i. These run with no nudge:

  • python3 -c / python3 - <<PY snippets that write a file
  • heredocs and tee, such as cat > f <<EOF, cat <<EOF > f, tee f <<EOF
  • echo … >> f

Redirects (>/<) make a command real shell work as far as this extension is concerned, so nothing with a heredoc can match. That is a deliberate limit rather than an oversight, and the reason a write-shaped nudge is not offered here.

Context cost

Nothing is added to the system prompt, no tool is registered, and there is no first-prompt orientation, no periodic reminder and no prompt rewrite. The only thing that ever reaches the model is the one line appended to a bash result it was about to read anyway.

A nudge fires on a category's first use in a session, then on every 5th. A one-off warning was ignored in practice and a nudge on every call is noise, so the middle ground is a cheap reminder.

One deliberate exception

Stock Pi activates only read, bash, edit and write; ls, grep and find are registered but inactive until something loads them. Naming a tool the model cannot call would be useless advice, so when a nudge names an inactive tool, that tool is activated first, the way tool_search would. It is done once per tool per session, only on a command that already reimplemented it, and it is what makes the line actionable.

If a session genuinely lacks a tool, the nudge is skipped rather than said.

Steering, not guarding

Nothing is blocked. The command runs, and the line teaches the next call. Blocking a bash call costs the model a whole retry turn.

The line names only the one matching tool, never an inventory of them.

Install

pi install git:github.com/Dev380/pi-avoid-unnecessary-bash

Or for one invocation:

pi -e ./src/index.ts

Development

npm install
npm test     # node --test, plus fast-check properties over the matcher
npm run check

Credit

The nudge idea, the transcript card and most of the shell matcher come from @xynogen/pix-nudge (MIT). This fork drops pix-nudge's capability and loop nudges, its ast/graph/proc/python_run/powershell targets, its rtk prefix handling, and its @xynogen/pix-* dependencies. It adds perl -i detection, which upstream had no rule for.

License

MIT.