Skip to content

tri-bot Phase 2: Streaming via sendMessageDraft + /stop #55

@gHashTag

Description

@gHashTag

Overview

Add real-time streaming to tri-bot so Claude responses appear progressively in Telegram instead of waiting for the full response.

Requirements

Streaming (sendMessageDraft)

  • Spawn claude -p with --output-format stream-json
  • Set .stdout_behavior = .Pipe on std.process.Child
  • Read NDJSON lines from stdout: type: "stream_event", event.delta.type: "text_delta"
  • Accumulate text, call sendMessageDraft every 500ms
  • Final sendMessage when Claude finishes

/stop command

  • Track active std.process.Child in SharedState
  • /stop sends SIGTERM to the child process
  • Send confirmation: "⛔ Claude process stopped"

Two-thread architecture

  • Main thread: Telegram polling (getUpdates → dispatch)
  • Worker thread: Claude process + streaming
  • Shared state via std.atomic.Value(bool) for is_busy
const SharedState = struct {
    active_child: ?*std.process.Child = null,
    is_busy: std.atomic.Value(bool) = std.atomic.Value(bool).init(false),
};

Files to modify

File Change
NEW claude_stream.zig Spawn + pipe + NDJSON parse + sendMessageDraft
MODIFY bot_loop.zig std.Thread.spawn() for /ask, SharedState
MODIFY handlers.zig /stop kills active_child

Acceptance criteria

  • /ask shows progressive text in Telegram (streaming)
  • /stop kills running Claude process
  • Bot remains responsive during long Claude runs
  • No race conditions in SharedState

Depends on: #54

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions