Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ Roundhouse is a chat-gateway between chat platforms (via Vercel Chat SDK) and a
- `turn_end` / `agent_end` → flush so the next turn starts a fresh message
If `promptStream` is missing, `agent.prompt()` is called and the full text is split/posted via `postWithFallback` (markdown-first, plaintext fallback).

**Telegram answers are sent by roundhouse, not by the Chat SDK** (`src/transports/telegram/html.ts` and `format.ts`; the SDK's posting uses Telegram's legacy Markdown mode). What holds there:
- **Nothing is truncated.** A long answer is cut in its markdown source (`splitMarkdownForTelegram`, `takeMarkdownChunk`) so that each chunk's HTML fits one message; a code block or table that spans chunks is reopened in the next one. `scanLines` is the one place that decides where code blocks and tables are, and the converter and the splitter both read it. No chunk is without visible text: Telegram refuses an empty message, and the refusal sends the plain-text fallback, which shows raw fences.
- **Telegram is never called inside a wait it asked for** (`RateLimiter`). A 429 is waited out, up to `MAX_RATE_LIMIT_WAIT_MS` per answer; a wait longer than what is left is not started and the loss is logged. Sends and edits have separate waits, because Telegram refuses edits of one message for minutes while it still takes a new message. After a chunk that is held back, later chunks are not sent.
- **Streaming** edits one message at most every `STREAM_EDIT_INTERVAL_MS` (longer in groups). An edit in the middle may be skipped; a timer makes up for it when the stream goes quiet (a tool is running). The last edit of a message must arrive: if it cannot, the text the message does not show is posted as a new message.
- **The fake in `test/telegram-test-helpers.ts` refuses what Telegram refuses** (empty text, HTML it cannot parse, more than 4096 visible characters, an edit that changes nothing). Keep it that strict: a lenient fake is how an empty code block and raw table rows got through. The generated-document tests are seeded; a failure names the seed.

**Pi adapter nuance — wait for idle, not for `prompt()`.** `src/agents/pi/pi-adapter.ts` targets pi 1.x (`@earendil-works/pi-coding-agent`, pinned to the exact version in `package.json`). Since pi 1.0, `session.prompt()` resolves only after the run has settled: retries, compaction, follow-ups queued by `agent_end` handlers and the `agent_settled` handlers are all inside it. A run an extension starts *after* that (`pi.sendMessage(..., { triggerTurn: true })` while idle) is not, so `runPromptAndFollowUps` then loops on the public `session.isIdle` / `session.waitForIdle()` before the caller unsubscribes. Unsubscribe earlier and Telegram shows a review bubble followed by silence. Do not reintroduce the pre-1.0 workarounds (awaiting the private `_agentEventQueue`, calling `agent.continue()` by hand): that field is gone and the session drains its own queues.

**Pi adapter nuance — "still working" notices come from events.** `promptStream` emits `draining` when a new low-level run (`agent_start`) begins after one already ended (`agent_end` with `willRetry: false`) inside the same prompt, and `drain_complete` on `agent_settled`. A retry is not a new run for this purpose.
Expand Down
8 changes: 8 additions & 0 deletions futureplans/next-phase.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ Belongs with A1.
- **A turn whose answer was delivered but which is still in post-turn work** (memory finalize, flush) when the gateway stops is reported as unfinished at the next start.
- **Expired OAuth credentials** produce pi's "Run '/login x'" text in chat, which is not a roundhouse command.
- **Hard cuts** of a single line longer than Telegram's limit can land inside inline markup, so both halves show the markers literally. Nothing is lost.
- **Telegram delivery, left from the review of the rendering fix:**
- A message with more than 100 formatted spans may exceed Telegram's entity limit (recalled, not verified); the splitter counts characters only.
- A line of several thousand `>` or `-` characters loses a few of them or turns into rules, and a table header of about 4,090 characters produces one chunk over the limit.
- An edit that Telegram applied but whose response was lost is posted again as a new message.
- A stream of one-character pieces costs more per piece as the answer grows; a 1M-character answer streamed that way is slow.
- A rate limit longer than 90 s per answer drops the rest of that answer with a log line; the owner is not told in chat.
- Tilde fences (`~~~`) are not read as code blocks, and a closing fence followed by text on the same line does not close the block (as in CommonMark).
- `telegramFetch` is called without a timeout of its own.
- **Slack pairing** has no one-time code: the first user whose display name matches is paired. Slack users are admitted by id only, but the pairing step is the weak link.
- **`roundhouse setup` and `roundhouse update`** install unpinned software: latest npm packages, a skills repository at its default branch, and the uv installer piped to a shell.
- **The CI workflow does not run the typecheck.** Adding it needs a token with the `workflow` scope.
Expand Down
Loading
Loading