Repository navigation
feat(cloud): Stream all container logs to Telegram in realtime #131
Copy link
Copy link
Closed
Labels
Description
Context
Currently only status messages (AWAKENING, CODING, DONE) go to Telegram. Need all Claude Code output streamed to Telegram in realtime — every line, every file, every command.
What to do
1. deploy/agent-entrypoint.sh — Add Telegram streaming functions
Add batch streaming (every 5 seconds) to avoid Telegram rate limits:
TELEGRAM_BUFFER=""
TELEGRAM_LAST_SEND=0
TELEGRAM_STREAM=${TELEGRAM_STREAM:-"true"}
TELEGRAM_BATCH_INTERVAL=${TELEGRAM_BATCH_INTERVAL:-5}
stream_to_telegram() {
[ "$TELEGRAM_STREAM" != "true" ] && return
local line="$1"
TELEGRAM_BUFFER="${TELEGRAM_BUFFER}${line}\n"
local now=$(date +%s)
local diff=$((now - TELEGRAM_LAST_SEND))
if [ $diff -ge $TELEGRAM_BATCH_INTERVAL ] || [ ${#TELEGRAM_BUFFER} -gt 3000 ]; then
if [ -n "$TELEGRAM_BUFFER" ] && [ -n "$TELEGRAM_BOT_TOKEN" ]; then
local msg=$(echo -e "$TELEGRAM_BUFFER" | head -c 3900)
curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
-d "chat_id=${TELEGRAM_CHAT_ID}" \
-d "parse_mode=HTML" \
-d "text=<pre>🤖 #${ISSUE} LOG\n${msg}</pre>" \
--max-time 5 || true
TELEGRAM_BUFFER=""
TELEGRAM_LAST_SEND=$now
fi
fi
}
flush_telegram() {
if [ -n "$TELEGRAM_BUFFER" ] && [ -n "$TELEGRAM_BOT_TOKEN" ]; then
local msg=$(echo -e "$TELEGRAM_BUFFER" | head -c 3900)
curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
-d "chat_id=${TELEGRAM_CHAT_ID}" \
-d "parse_mode=HTML" \
-d "text=<pre>🤖 #${ISSUE} LOG\n${msg}</pre>" \
--max-time 5 || true
TELEGRAM_BUFFER=""
fi
}2. Replace Claude Code launch with streaming pipe
timeout ${AGENT_TIMEOUT:-3600} claude -p "${PROMPT}" \
--allowedTools "Bash(*)" "Read(*)" "Write(*)" "Edit(*)" 2>&1 | \
while IFS= read -r line; do
echo "$line"
stream_to_telegram "$line"
echo "{\"type\":\"log\",\"issue\":${ISSUE},\"line\":\"$(echo "$line" | sed 's/"/\\"/g' | head -c 500)\",\"ts\":\"$(date -u +%Y-%m-%dT%H:%M:%SZ)\"}" >> /tmp/agent_events.jsonl
case "$line" in
*"Read("*|*"cat "*) report_status "READING" "$line" ;;
*"Write("*|*"Edit("*) report_status "CODING" "$(echo $line | head -c 100)" ;;
*"Bash("*|*"zig build"*) report_status "TESTING" "$(echo $line | head -c 100)" ;;
*"error"*|*"Error"*) report_status "ERROR" "$(echo $line | head -c 200)" ;;
esac
done
flush_telegram3. Stream other steps too (clone, self-review, push, PR create)
All steps should pipe through stream_to_telegram so every line appears in Telegram.
4. Add TELEGRAM_STREAM env var to cloud_orchestrator.zig
In spawnAgent() add TELEGRAM_STREAM=true to the upsertVariable calls.
Rate limiting
Telegram: 20 msgs/min to private chat. Batch every 5s = max 12 msgs/min per container. 3 containers = 36 msgs/min — safe.
Verification
After deploy, every agent run should produce Telegram messages every ~5 seconds with full Claude Code output wrapped in <pre> blocks.
Reactions are currently unavailable
Activity
github-actions commentedon Mar 11, 2026
🚀 Agent container spawned! Deploying on Railway. Tracking in this issue.
github-actions commentedon Mar 11, 2026
🚀 Agent container spawned! Deploying on Railway. Tracking in this issue.
gHashTag commentedon Mar 11, 2026
📖 Trinity Agent | 2026-03-11T15:02:00Z
📋 Step: 3/8 — Reading issue #131
🔄 Status: READING
⏱️ Elapsed: 13s
gHashTag commentedon Mar 11, 2026
📖 Trinity Agent Dashboard — Issue #131
gHashTag commentedon Mar 11, 2026
☠️ Trinity Agent | 2026-03-11T15:02:03Z
📋 Step: 4/8 — Container terminated by signal
🔄 Status: KILLED
⏱️ Elapsed: 16s
gHashTag commentedon Mar 11, 2026
☠️ Trinity Agent Dashboard — Issue #131
gHashTag commentedon Mar 11, 2026
📖 Trinity Agent | 2026-03-11T15:02:05Z
📋 Step: 3/8 — Reading issue #131
🔄 Status: READING
⏱️ Elapsed: 8s
gHashTag commentedon Mar 11, 2026
⚡ Trinity Agent Dashboard — Issue #131
gHashTag commentedon Mar 11, 2026
⚡ Trinity Agent | 2026-03-11T15:02:09Z
📋 Step: 4/8 — Claude Code running (timeout: 3600s)
🔄 Status: CODING
⏱️ Elapsed: 12s
gHashTag commentedon Mar 11, 2026
📖 Trinity Agent | 2026-03-11T15:02:27Z
📋 Step: 3/8 — Reading issue #131
🔄 Status: READING
⏱️ Elapsed: 15s
gHashTag commentedon Mar 11, 2026
❌ Trinity Agent Dashboard — Issue #131
gHashTag commentedon Mar 11, 2026
⚡ Trinity Agent | 2026-03-11T15:02:31Z
📋 Step: 4/8 — Claude Code running (timeout: 3600s)
🔄 Status: CODING
⏱️ Elapsed: 19s
gHashTag commentedon Mar 11, 2026
🔄 Agent: trinity | 2026-03-11T15:03:01Z
📋 Step: 1/4 — Reading current implementation
🔄 Status: THINKING
Thought: Reading agent-entrypoint.sh and cloud_orchestrator.zig to understand current Telegram integration
Action: Read files and identified current status-only Telegram flow
Next: Add batch streaming functions to agent-entrypoint.sh
2 remaining items
gHashTag commentedon Mar 11, 2026
🔄 Agent: trinity | 2026-03-11T15:07:26Z
📋 Step: 4/4 — Finalizing
🔄 Status: DONE
Thought: All changes implemented and PR created
Action: Created PR #133 with changes:
Result: PR feat(cloud): Stream all container logs to Telegram in realtime #133 created
Next: CI verification and merge
PR Summary
gHashTag commentedon Mar 11, 2026
🧪 Trinity Agent | 2026-03-11T15:07:40Z
📋 Step: 5/8 — Running zig build test
🔄 Status: TESTING
⏱️ Elapsed: 328s
gHashTag commentedon Mar 11, 2026
🔄 Trinity Agent | 2026-03-11T15:09:38Z
📋 Step: 6/8 — Self-review before PR
🔄 Status: REVIEWING
⏱️ Elapsed: 446s
gHashTag commentedon Mar 11, 2026
💥 Trinity Agent | 2026-03-11T15:10:11Z
📋 Step: 7/8 — zig build failed
🔄 Status: ERROR
⏱️ Elapsed: 479s
gHashTag commentedon Mar 11, 2026
⏰ Trinity Agent | 2026-03-11T15:10:20Z
📋 Step: 8/8 — 1 self-review error(s) — needs human help
🔄 Status: STUCK
⏱️ Elapsed: 488s
gHashTag commentedon Mar 11, 2026
gHashTag commentedon Mar 11, 2026
🧪 Trinity Agent | 2026-03-11T15:10:24Z
📋 Step: 9/8 — Checking/creating PR
🔄 Status: TESTING
⏱️ Elapsed: 492s
gHashTag commentedon Mar 11, 2026
❌ Trinity Agent | 2026-03-11T15:10:28Z
📋 Step: 10/8 — Exit code: 0, Commits: 0
🔄 Status: FAILED
⏱️ Elapsed: 496s
feat(cloud): Stream all container logs to Telegram in realtime (#131)
feat(golden-chain): Level 11.21 Deployment Prototype — Massive KG 50/…
feat(cloud): Stream all container logs to Telegram in realtime (#131)
queen: the catalog map reads every page of a supported world's issues (…