Repository navigation
feat(messages): add tg messages wait and watch - #166
Merged
Merged
Conversation
wait blocks until the daemon stores a new message and returns the new
messages oldest first, or { messages: [], timedOut: true } after
--timeout; watch streams them as NDJSON until SIGINT or SIGTERM. Both
poll only the account's cache (PRAGMA data_version, then the rows past
the last rowid seen) and fail with DAEMON_NOT_RUNNING without a daemon.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
neoromantic
force-pushed
the
feat/messages-wait
branch
from
November 17, 2026 20:34
48fc448 to
fc67c0b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
An agent in a conversation has to block until someone replies; until now it could only poll
tg sql. This adds two read-only commands over what the daemon stores in the account's cache:tg messages wait [--chat <peer>] [--after <id>] [--timeout 60] [--settle 0]returns the new messages oldest first, in the same item shape astg messages list(deleted ones left out):{ success: true, data: { messages, timedOut } }. On timeout it is{ messages: [], timedOut: true }with exit 0.tg messages watch [--chat <peer>]prints one item per line (NDJSON) as each message is stored, until SIGINT or SIGTERM, then exits 0 through the normal exit path.How it works: the command reads
PRAGMA data_versionevery 200 ms and, when another connection committed, reads themessages_cacherows past the last rowid it saw (an upsert keeps a row's rowid, so edits are not new). No Telegram connection, no second session; the daemon stays read-only. Only resolving a--chatthe cache doesn't know asks Telegram, astg messages listdoes.Rules:
--after, only messages stored after the command started count, and only when newer than every message of their chat already in the cache, so history the daemon backfills meanwhile doesn't count.--after <id>needs--chat(INVALID_ARGSotherwise) and returns the chat's cached messages newer than it at once, else waits for them.--settle N: after the first new message, keep collecting until N quiet seconds, never past--timeout.daemon.pidnames a live process and the account's daemon rows are that process's, astg statuschecks), both fail at once with the existingDAEMON_NOT_RUNNING(exit 1),details: { account_id }and a suggestion to runtg daemon start.Docs:
docs/cli-commands.md(new section with the timeout result),docs/real-time.md(what the daemon stores live, so how fresh it is),docs/api-design.md(error code), README (comparison row, usage and agent line), CHANGELOG.Before / After
Before:
tg messages wait→ unknown command.After:
Testing
bun run checksrc/__e2e__/messages-wait.e2e.test.ts(9 tests): the test process writes messages into the cache while the CLI runs, with a simulated running daemon (daemon.pid with a live PID and daemon rows for it). Covers the return within 1 s of the write (backfilled older message not counted), the timeout result,--afterat once (deleted left out) and waiting after it,--afterwithout--chat,--settlewith another chat's message filtered out, both daemon-not-running cases, andwatchprinting NDJSON lines and exiting 0 on SIGTERM.src/__tests__/new-messages.test.ts: the feed over two connections (backfill, a chat new to the cache, edits, deleted rows,--chat,--after).bun run test(2246 pass) andbun run test:e2e(5 unrelated timeouts under parallel load; those files pass alone).Fixes #24
🤖 Generated with Claude Code