Repository navigation
feat: read-only mode and a chat allowlist for agents - #168
Merged
Merged
Conversation
neoromantic
force-pushed
the
feat/read-only-mode
branch
from
November 17, 2026 20:09
0d73c2e to
b908202
Compare
Tests can import the tree and walk it without running the CLI. Co-Authored-By: Claude Opus 5.5 <[email protected]>
readOnly in config.json or TELEGRAM_SYNC_CLI_READ_ONLY refuses every command that changes Telegram with READ_ONLY before it connects: tg send, tg api methods not named get/search/resolve/check, and tg auth login, login-qr and logout. allowedChats or TELEGRAM_SYNC_CLI_ALLOWED_CHATS limits commands to those chats: a command that names another chat fails with CHAT_NOT_ALLOWED, chats list, chats search and messages search show only allowed chats, and tg sql and tg api are off. tg status shows both. Every command of the tree is classified in COMMAND_ACCESS, and a command without an entry fails at start and in the tests. Fixes #26 Co-Authored-By: Claude Opus 5.5 <[email protected]>
tg messages read marks a chat read on Telegram, so read-only mode refuses it, and its --chat must be allowed. tg messages wait, watch and unread take an allowed --chat; without one they read every chat, so with allowedChats set the new-messages feed keeps only allowed chats in its SQL and unread keeps only allowed chats among its targets. chats list --unread keeps the allowlist filter. Co-Authored-By: Claude Opus 5.5 <[email protected]>
neoromantic
force-pushed
the
feat/read-only-mode
branch
from
November 17, 2026 20:48
b908202 to
dee7ed6
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 that can run
tgcould also send messages or make anytg apicall. This adds two opt-in guards, set inconfig.jsonor, for one process, in the environment:readOnly,TELEGRAM_SYNC_CLI_READ_ONLY=1). Every command that changes something on Telegram fails before it connects with the new codeREAD_ONLY(exit 1). That coverstg send,tg apimethods whose name after the namespace doesn't start withget,search,resolveorcheck, andtg auth login,login-qrandlogout(they add or end a session). Local commands and reads still run.allowedChats;TELEGRAM_SYNC_CLI_ALLOWED_CHATSreplaces it when set). A command that names a chat outside the list fails withCHAT_NOT_ALLOWED(exit 1,details: { chat, id }). The target and the list entries resolve the same way, cache-first, so@nameand its marked ID count as the same chat andmeis the account's own ID.tg chats list,tg chats searchandtg messages searchwithout--chatshow only allowed chats.tg sqlandtg apican't be scoped, so they are off while a list is set. Contacts,tg user,tg meandtg statusare not limited.tg statusshowsaccess: { read_only, allowed_chats }, so an agent that was refused can see why.These guard against mistakes. They are not a security boundary, and the docs say so.
Exhaustive by construction.
src/commands/access.tshas oneCOMMAND_ACCESStable with an entry for every command path in the citty tree (now insrc/cli.ts, so tests can walk it).guardCommandswraps every run, and a command without an entry throws at start and fails the unit test. Classifying a new command takes one line, for example'messages read': { write: true, chatArgs: ['chat'] }or'messages wait': { chatArgs: ['chat'] }.Before / After
Tests
src/__tests__/access.test.ts: the table and the tree match both ways, an unclassified command is refused, every command in the tree is refused in read-only mode if and only if it is a write, thetg apiread/write split, andsql/apirefused while an allowlist is set.src/__tests__/config.test.ts: key validation,tg config setparsing, env overrides (read-only can only be turned on; the list replaces config even when empty).src/__e2e__/access.e2e.test.ts, through the real CLI with no credentials: every write command from the tree refused, every chat-scoped command from the tree refusing an outside chat,@nameand the ID as one chat,meas the own ID, filteredchats list/chats search/messages search(with--count),sql/apirefused, the env list replacing config, andtg statusoutput.bun run check,bun run test(2258 pass),bun run test:e2e(395 pass).Fixes #26
🤖 Generated with Claude Code