Commands for agents: wait for a reply, read and mark unread messages, and keep an agent
read-only or to a few chats.
Added
tg db vacuumchecks the free disk before a full VACUUM (daemon stopped): it needs 2.2 times
the cache file plus 64 MB, as the storage benchmark measured. When the disk is short it fails
at once withGENERAL_ERROR,details.reason: "disk_full", the bytes needed and free, and
changes nothing, instead of failing after minutes of work.tg statusshows the same check
next to its vacuum hint (#119).tg messages waitblocks until the daemon stores a new message, then returns the new messages
oldest first, in the same shape astg messages list;tg messages watchprints each one as a
JSON line as it is stored, until Ctrl-C or SIGTERM. Both read only the cache (no second
Telegram session) and return within about a second of the daemon storing a message.
--chatkeeps one chat,--after <id>returns that chat's cached messages newer than it at
once,--settle Nkeeps collecting until N quiet seconds, and after--timeout(default
60 s) the result is{ "messages": [], "timedOut": true }with exit 0. Without a running
daemon they fail at once withDAEMON_NOT_RUNNING(#24).- Unread messages (#25).
tg chats list --unreadlists only chats with unread messages, and
every chat item hasunreadCount.tg messages unread [--chat <peer>] [--limit N]prints each
chat's oldest unread messages from the cache with its unread count andmissing, how many of
them the cache lacks;--freshreads the counts and those messages from Telegram.
tg messages read --chat <peer> [--max-id <id>]marks a chat read on Telegram
(messages.readHistory, orchannels.readHistoryfor supergroups and channels) and caches
its new count.chats_cachegetsunread_countandread_inbox_max_id, which dialog lists
set; the daemon raises the count for each new incoming message and takes reads on any device
from Telegram's read updates, so the counts stay current between dialog passes. A cache from
an older version has no counts until the daemon's next start ortg chats list --fresh. - Read-only mode and a chat allowlist for agents (#26).
readOnlyinconfig.jsonor
TELEGRAM_SYNC_CLI_READ_ONLY=1refuses, before connecting, every command that changes
something on Telegram with the new codeREAD_ONLY(exit 1):tg send,tg messages read,
tg apimethods not namedget…,search…,resolve…orcheck…, andtg auth login,
login-qrandlogout.allowedChats(orTELEGRAM_SYNC_CLI_ALLOWED_CHATS, which replaces
it for one process) limits commands to those chats: one that names another chat fails with
CHAT_NOT_ALLOWED(exit 1),tg chats list,tg chats search,tg messages search,wait,
watchandunreadshow only allowed chats, andtg sqlandtg apiare off.tg status
shows both underaccess. They guard against mistakes and are not a security boundary.
Changed
tg auth login-qrdraws its QR code with uqr instead of
qrcode-terminal, which has had no release since 2018. The code is black on white with the
standard four-module quiet zone, so it scans in dark and light terminal themes, and it goes to
stderr with its status lines, so they no longer mix with the JSON result on stdout (#10).- The daemon raises a chat's
last_message_idandlast_message_atwith each live message, so
tg chats listkeeps the order of recent activity between dialog passes.
Fixed
tg db migratewith the daemon stopped no longer locks othertgcommands out of the cache: it
ran its batches back to back, and on a big cache a command that wrote meanwhile (tg messages listcaching a page,tg sendcaching the sent message) could give up withdatabase is lockedafter 5 s. It now pauses 150 ms after each second of work, so such a write gets in
within about a second; the run takes up to 15% longer (#122).