Skip to content

About

bb plugin: type !command in a thread to run it on the session's host and send the output to the agent

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

bb-plugin-bang-shell

Run a message as a shell command in the thread's environment, on the host where the session runs, and send the command and its output to the agent. See PLUGIN_OVERVIEW.md. Release notes: CHANGELOG.md.

Why

Keep the agent away from secrets and production access without losing its help. When the agent's sandbox or permission mode blocks a command — it needs credentials from .env, a database or cluster the agent must not reach, or a tool that runs as you — the agent proposes the command, you read it and run it with one click, and the agent continues from the output. The agent never gets the credentials or the access, only the result you chose to run.

Commands run as typed, so keep secrets out of what they print: the output goes to the agent and its provider.

Usage

Type the command in a thread's composer, then send it with Mod+Alt+Enter (rebindable in keyboard settings) or Send menu → Run in terminal. The leading ! is optional with these actions: !git status and git status both run git status. Pressing plain Enter on a message that starts with ! is refused with a hint, so nothing runs by accident.

To run text from an agent's answer, highlight it and pick Run in terminal in the selection menu, next to Add to chat. The same action sits in each message's action bar; without a selection it runs the message's first shell code block (sh, bash, console, … or unlabelled; $ prompts are dropped). It sends the text through the thread's composer like Mod+Alt+Enter, then puts back whatever you were typing. Closed code blocks in assistant messages also get a Run in terminal button in the block header that does the same for that block. By default this covers blocks labelled sh, bash, zsh, shell, console and terminal; python/py/python3 blocks opt in with runPythonBlocks (run as python3 - with the code as a heredoc). Unlabelled blocks never get the button, because bb does not route them to plugins. Change the languages with runButtonLanguages; settings changes need bb plugin reload bang-shell.

Markdown wrapped around a command is removed before it runs, so text that Add to chat inserts (`cmd`, > cmd``) or a pasted fenced block runs as the bare command. The same applies to$ prompts. A command that itself starts with>(for example> file.logto truncate a file) is therefore read as a quote; write it as: > file.log`.

The message waits in the queue (card "Running: …") while the command runs, then goes to the agent as two blocks:

```sh
git status
```

```output
<last outputTailChars characters of the output>
```

A zero exit code is implied; a non-zero one, a still-running command, a lost terminal or a start failure is the last line of the output block. Multi-line messages run as a script.

If a running command shows a recognizable input prompt or choice, Bang Shell opens that command's existing tab in the current thread's Terminal panel. Type your answer there; the queued card then reads "Waiting for your input…". Bang Shell gives you up to threadShellWaitSeconds to answer and finish, while keeping at least the original waitSeconds deadline. For a silent read or an unrecognized prompt, the tab opens at waitSeconds if the command is still running, and the message is sent with the output captured so far. This fallback can also open a long-running command that needs no input.

Thread shell

Each Run in terminal command normally gets a fresh terminal, so nothing carries over between commands. To run several steps in one shell, Alt-click a code block's Run button, or pick Send menu → Run in thread shell for the text in the composer. The command is pasted into one persistent interactive shell per thread, in a terminal tab named "Thread shell" in the thread's environment. Exported variables, the working folder and shell options carry over to the next command. The first use starts the shell; a small green dot on the Run button shows that the thread has a live one. Sending a command this way also opens the Thread shell tab in the terminal panel, so you can type into it right away.

The message waits until the command finishes, up to threadShellWaitSeconds (default 600; waitSeconds does not apply here), so there is time to answer a prompt. Ctrl-C in the terminal ends the wait. After the cap the message is sent with the output so far and the command keeps running. Result delivery and outputTailChars work as for a normal run.

To use credentials without showing them to the agent, ask the agent for blocks like these, then Alt-click each in turn:

read -r DB_USER
read -rs DB_PASS
export DB_USER DB_PASS
PGPASSWORD="$DB_PASS" psql -h db.internal -U "$DB_USER" -c 'select 1'

read takes what you type in the Terminal panel. Type the value there, and the variable stays in that shell for later blocks. The command text and output go to the agent, so never put a secret in the command text; read -s keeps it off the screen too.

While a command runs, a second Alt-click is refused with "The thread shell is still running a command; finish it or press Ctrl-C in the Terminal panel." If you close the Thread shell terminal, the next Alt-click starts a fresh shell, and the variables are gone.

Install

npm install --include=dev
bb plugin install .
bb plugin config bang-shell
bb plugin reload bang-shell   # settings are read at load

Settings

Key Default Range Meaning
enabled true Run commands at all
requireRunAction true Only run messages sent with the Run in terminal action (see Security)
prefix ! 1–4 chars Command marker; no spaces, must not start with ` / $ @ #
waitSeconds 30 0–3600 Wait for output, then show a still-running terminal and send output so far; recognized input prompts extend the wait using threadShellWaitSeconds
threadShellWaitSeconds 600 0–3600 Wait for thread shell completion, or this long after revealing a normal run's input prompt; then send output so far
outputTailChars 3000 1–30000 Last N output characters sent
pollIntervalMs 200 50–10000 Terminal poll interval while waiting
terminalCols 120 20–500 Terminal width
terminalRows 32 5–200 Terminal height
titleMaxChars 60 1–200 Terminal tab title length
runButtonLanguages sh, bash, zsh, shell, console, terminal sh, bash, zsh, shell, console, terminal, fish Code block languages with a Run button (comma or space separated); none turns the shell button off; unknown entries are dropped, an empty result falls back to the default
runPythonBlocks false Also add the Run button to python, py, python3 blocks
disablePager true Run with PAGER=cat GIT_PAGER=cat so git log and man do not wait in a pager

Out-of-range numbers are clamped; non-numbers and invalid prefixes fall back to the default.

Security

  • Who can run a command. By default only a message submitted with this plugin's Run in terminal action, typed by a person: messages that bb marks as coming from an agent, from core or from another plugin's bb.sdk.threads.send never run, and bb thread tell cannot attach the action's marker, so !… sent that way is refused.
  • What the marker does not stop. bb accepts the action's marker (pluginSubmission) from any client of its local HTTP API and does not verify that the composer set it. A process on this machine that can reach the bb API — including an agent's shell, which has BB_SERVER_URL — can forge it with a hand-written request and run a command; so can another plugin that posts to bb's loopback API directly. The gate stops accidents, prompt-injected bb thread tell calls and bb.sdk.threads.send; it is not a boundary against code already running as you. Closing that gap needs bb itself to authenticate the marker.
  • Legacy mode. With requireRunAction off, any human-looking message starting with the prefix runs, and bb marks messages sent with bb thread tell as human-typed: any agent can then run commands with one CLI call. Leave it on unless you accept that.
  • What runs. The command runs with your account's full rights in the thread's environment, outside the agent's permission mode — like typing it into that thread's terminal.
  • At most once. Nothing runs while the dispatch hooks are still deciding: the command starts only after bb has queued the held message. It runs once; the job is tied to that queued message, and a failed message update, a re-check or a plugin reload never starts it again. If the plugin restarts between queueing and starting the terminal, the message reports "not re-run" instead of guessing. If the output cannot be attached after five tries, the message stays held with an explanation. If you edit the held message while the command runs, your edit is kept and sent as typed, without the output. Cancelling the held message, or sending it by hand, stops the plugin from touching it; the command itself keeps running in the thread's Terminal panel.
  • The thread shell holds secrets in a long-running shell. Variables you enter there live as long as the shell does. Any client of the bb API on this machine, including an agent whose shell reaches BB_SERVER_URL, can send input to that terminal with bb terminal send; this is the limit described under "What the marker does not stop" (code already running as you is not stopped), and more serious because the shell is long-lived and holds your credentials. A plain read (without -s) echoes what you type into the terminal, and that echo is part of the output sent to the agent; use read -s for anything secret. Never put a secret in the command text (it goes to the agent), and close the Thread shell terminal when you are done.
  • Output is untrusted. The agent receives the output as part of your message, in a block labelled output. Output from untrusted sources (web pages, files) can contain text that looks like instructions; the bundled skill tells agents to treat that block as data.
  • Where data goes. The command and up to outputTailChars characters of output become a message in the thread (sent to the agent's provider). While held, the command is also shown on the queued card ("Running: …") and kept in the plugin's storage until the message is sent or cancelled (24 h at most). The plugin log records thread ids, command lengths and error types, never the command text or output.

Limits

  • The first message of a new thread cannot be a command: the environment does not exist yet.
  • Commands longer than 8000 characters are refused; run a script file instead.
  • If bb or another plugin refuses a Run in terminal submission, sending the same command again with the action is refused for up to a minute.
  • If you group a held command with other queued messages, the group is sent when the command's message is.
  • Thread shell: zsh is the supported shell and is tested live. bash 4.4 or newer is untested live, and a multi-line block in bash may be reported after its first line only (the rest of its output missing). Other shells (fish, bash older than 4.4) never report ready, and the message says "[not run: the thread shell did not report ready (zsh and bash 4.4+ only); see the Thread shell tab]".
  • The thread shell's setup line is typed with a leading space, so it stays out of shell history only with HIST_IGNORE_SPACE (zsh) or HISTCONTROL=ignorespace (bash) set.
  • Typing in the Thread shell panel by hand is not detected: a half-typed line or an unfinished block typed by hand can make the next paste part of it.
  • If more than about 64 KB of output with no end-of-command mark follows the last command (for example a background job logging into the shell), the shell reads busy and both Alt-click and Send menu → Run in thread shell are refused. Once the output stops, press Enter (or Ctrl-C) in the terminal to clear it. Run long-lived servers in a normal terminal.
  • The green dot means a terminal titled "Thread shell" is running in the thread. An abandoned one (for example after an "unsupported shell" note) can keep it lit.

Development

npm run typecheck
npm test
bb plugin build

About

bb plugin: type !command in a thread to run it on the session's host and send the output to the agent

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages