Skip to content

Check a command before an agent runs it

An agent in a loop runs whatever shell command it decides on. Here you put decide in front of it, so a command that could do lasting harm waits for a person. decide is a second check, and it can miss things.

You need decide installed and an API key.

command-risk asks whether a command could destroy work, leak a secret, publish something, or cause severe harm. Try it on two commands that delete things:

~
printf '%s\n' 'git reset --hard HEAD~3' 'rm -rf ~/' | decide run command-risk
Output as text
$ printf '%s\n' 'git reset --hard HEAD~3' 'rm -rf ~/' | decide run command-risk
Running command-risk on 2 lines · typesafe jev-latest

stdin:1  git reset --hard HEAD~3
! destructive  yes     96%
  leak         no      95%
  publish      no      93%
  severe       no      96%

stdin:2  rm -rf ~/
! destructive  yes     98%
  leak         no      90%
  publish      no      70%
! severe       yes     98%

✓ 2 answered  ! 2 flagged  100ms
Flagged: stdin:1, stdin:2
See these results again with: decide runs view 20261112-165747-87ff

Both are flagged as destructive. Only rm -rf ~/ is severe. A hard reset loses local work, but it stays inside your checkout.

decide only reads the command. It never runs it.

Save this as checked.sh, and make it executable with chmod +x checked.sh:

checked.sh
#!/bin/sh
# Usage: ./checked.sh 'git reset --hard HEAD~3'
printf '%s\n' "$1" | decide run command-risk --fail-on flagged
case $? in
0) sh -c "$1" ;;
2) echo "decide flagged this command; not running it" >&2; exit 2 ;;
*) echo "decide could not check this command; not running it" >&2; exit 1 ;;
esac

The script runs the command only when decide flags nothing.

Run a harmless command, then a force push:

~
./checked.sh 'echo it ran'
./checked.sh 'git push --force origin main'
echo $?
Output as text
$ ./checked.sh 'echo it ran'
Running command-risk on 1 line · typesafe jev-latest

stdin:1  echo it ran
  destructive  no      99%
  leak         no      97%
  publish      no      97%
  severe       no      99%

✓ 1 answered  nothing flagged  100ms
See these results again with: decide runs view 20261112-165809-95f4
it ran

$ ./checked.sh 'git push --force origin main'
Running command-risk on 1 line · typesafe jev-latest

stdin:1  git push --force origin main
! destructive  yes     96%
  leak         unsure  48% yes
  publish      no      76%
! severe       yes     93%

✓ 1 answered  ! 1 flagged  100ms
See these results again with: decide runs view 20261112-165815-6e9d
Exiting with code 2 because 1 item was flagged (--fail-on flagged)
decide flagged this command; not running it
$ echo $?
2

The force push is refused, with exit code 2. The echo before it ran.

An agent or a script can now call checked.sh in place of sh -c.

decide is Apache 2.0. Made by Deep Noodle, after some very hard thinking.