Skip to content

fix: use dynamic bash lookup and stdin message passing for Telegram scripts#158

Merged
frostming merged 2 commits intobubbuild:mainfrom
suselee:fix/stdin-message-for-telegram-scripts
Apr 11, 2026
Merged

fix: use dynamic bash lookup and stdin message passing for Telegram scripts#158
frostming merged 2 commits intobubbuild:mainfrom
suselee:fix/stdin-message-for-telegram-scripts

Conversation

@suselee
Copy link
Copy Markdown
Contributor

@suselee suselee commented Apr 11, 2026

Problem

When the agent sends Telegram messages via bash tool, the message content is embedded directly in shell command arguments. This causes two issues:

  1. Shell escaping failures: Special characters (', ", $, !, backticks) in message content are interpreted by the shell, resulting in truncated messages, variable substitution, or syntax errors like Syntax error: word unexpected (expecting ")").

  2. Hardcoded /bin/bash path: shell_manager.py assumed bash lives at /bin/bash, which fails on FreeBSD where bash is installed at /usr/local/bin/bash.

The core problem is architectural: arbitrary text content should never pass through shell interpretation. This is especially problematic with smaller models (e.g. Gemma 31B) that tend to add redundant /bin/sh -c '...' wrappers, creating nested shell layers that make correct escaping nearly impossible.

Changes

src/bub/builtin/shell_manager.py

  • Replace hardcoded /bin/bash with shutil.which("bash") or shutil.which("sh") for cross-platform compatibility (Linux, FreeBSD, macOS).

src/skills/telegram/scripts/telegram_send.py

  • Support --message - to read message content from stdin, bypassing shell interpretation entirely.
  • Backward compatible — --message 'text' still works as before.

src/skills/telegram/scripts/telegram_edit.py

  • Support --text - to read message content from stdin (same approach as telegram_send.py).

src/skills/telegram/SKILL.md

  • Update all command templates to use heredoc stdin piping (cat << 'EOF' | ... --message -).
  • Add explicit execution policy rule: always pass message content via stdin, never inline in shell arguments.
  • This lowers the barrier for smaller models that struggle with shell escaping, while remaining fully compatible with stronger models.

Test plan

  • uv run ruff check . passes
  • uv run pytest -q — all tests pass
  • Verified on FreeBSD jail: shutil.which("bash") correctly resolves /usr/local/bin/bash
  • Backward compatible — existing --message 'text' / --text 'text' usage still works
  • Deployed and tested on FreeBSD jail with Telegram gateway

suselee and others added 2 commits April 11, 2026 10:06
…cripts

- shell_manager.py: replace hardcoded /bin/bash with shutil.which() lookup
  so it works on FreeBSD (/usr/local/bin/bash) and other non-Linux systems
- telegram_send.py / telegram_edit.py: support --message - / --text - to
  read content from stdin, avoiding shell escaping issues with backticks,
  $variables, and quotes
- SKILL.md: update command templates to prefer stdin piping via heredoc

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@frostming frostming left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@frostming frostming merged commit ccb0c3e into bubbuild:main Apr 11, 2026
5 checks passed
@suselee suselee deleted the fix/stdin-message-for-telegram-scripts branch April 11, 2026 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants