Repository navigation
Conversation
details is emitted as error.details only when an error sets it, so the existing error JSON is unchanged, and error_from_body carries it across the socket. PEER_NEEDS_USER (exit 2) is the error a contact alias miss raises.
A new PeerRef kind, name, covers name:<text> and any text no other form claims (non-ASCII, several words, ASCII that is not a username). A bare ASCII username-form word still means the username. PeerResolver.resolve looks the normalized wording up in a per-account aliases.json next to the peer cache; only an exact key resolves. A miss raises PEER_NEEDS_USER with lookalike aliases and contacts as candidates, and a bare word that is both a username and a saved alias is refused as ambiguous.
set takes an exact peer (id, @username, phone, link or an existing alias), refuses a wording that would shadow a real reference, and needs --replace to repoint. list is one row per peer with all its aliases; remove is exact only and suggests lookalikes on a miss. list and remove are local.
AGENT.md and the skill tell agents to pass the name instead of picking a contact search row, and what to do on PEER_NEEDS_USER. The chat reference list now includes +phone, links and aliases. DECISIONS records why name: and why a bare username keeps its meaning.
This branch has not been deployed
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.
Closes #64
What was wrong
tlgr/models/peer.py:348at 2f303da), sotlgr message send sara "hi"goes to the public @sara, who may be a stranger, when the agent meant the contact the user calls Sara.peer.py:351). There was no way to say "the person the user calls X", so agents rancontact search, picked a row and sent: the wrong-person failure mode.TlgrErrorhad no structured payload (tlgr/core/errors.py:111), so an error could not hand an agent machine-readable next steps.plugin/skills/tlgr/SKILL.md:39andAGENT.md:1449said phone numbers are not accepted as chats;parse_peer_refhas accepted+phonefor a while.Changes
PeerRefgets anamekind (tlgr/models/peer.py):name:<text>, or any text no other form claims (non-ASCII, several words, ASCII that is not a valid username). A bare ASCII username-form word still means the username. Malformed handles (@ab,+abc, a non-Telegram URL) stay parse errors.normalize_name()builds the lookup key: NFKC, casefold, ZWNJ/ZWJ and direction marks removed, Arabic ye/kaf to Persian, Arabic diacritics and tatweel dropped, whitespace collapsed. No stemming.tlgr/core/aliases.py):accounts/<alias>/aliases.jsonnext topeers.json, written withwrite_private(atomic, 0600) under an advisory lock. Each record keeps the wording, marked id, cache kind, access hash, username and the display name at save time. A corrupt file is never overwritten and makes name resolution refuse, naming the file.PeerResolver.resolve(tlgr/core/peers.py) handleskind == "name": exact key lookup, then the stored hash, then the stored id through the existing id strategy. CLI params and/v1/oppayloads already parse throughparse_peer_ref, so every chat/user argument, batch line and gateway job filter accepts a name with no per-op change.PEER_NEEDS_USER(exit 2,PeerNeedsUserError), witherror.details:reason(unknown,stale,ambiguous),reference,key,account,nothing_sent: true,candidates(near aliases, plus contacts whose name resembles the wording from onecontacts.getContactson the failure path; an exact contact-name match is still only a candidate),save_with,retry: once. The hint tells the agent to ask the user, save withcontact alias set, and retry once. A stored peer that is no longer reachable (NOT_FOUND) isstale; INDETERMINATE passes through.sara) is refused asambiguous, namingname:saraand@sara. This only triggers once the user saved such an alias. An unreadable alias file does not block bare-username sends.error.details(tlgr/core/errors.py,tlgr/models/error.py,tlgr/transport/client.py): optional, emitted only when set, and carried across the socket, so the existing error JSON is unchanged.tlgr/ops/contact.py):contact alias set <alias> <peer> [--replace](the peer must be an id, @username, +phone, link or an existing alias; an alias that looks like an id, phone,@handle, link,meorsavedis refused; repointing needs--replaceand the reply reportsreplaced),contact alias list(one row per peer with all its aliases),contact alias remove <alias>(exact only; a miss exits 5 with lookalikes in the hint). List/remove are local and need no Telegram connection. Taggedinfrastructure(no catalog id).user dialog-statusletsPEER_NEEDS_USERthrough instead of folding it into anunknownanswer.resolve peerreportssource: "alias".AGENT.md("Chat Resolution" and new "People by name" section, error shape),plugin/skills/tlgr/SKILL.md(rule 5, exit 2 row),docs/design/DECISIONS.md(syntax decision),CHANGELOG.md, regenerateddocs/reference.Tests
test_aliases.py::TestNormalization::test_spellings_of_one_wording_share_a_key(13 cases)TestNormalization::test_no_stemmingsara/saras,ali/alireza,مامان/ماماstay distinctTestParsing::test_free_text_is_a_namename:forms parse as namesTestParsing::test_a_bare_username_still_means_the_usernamesarais still a usernameTestParsing::test_malformed_handles_are_still_parse_errors!!!,@ab,+abc, URL, emptyname:name:forms)TestStore::*TestResolve::test_an_exact_alias_resolves_from_the_store_without_networkTestResolve::test_persian_spelling_variants_resolve_to_the_same_aliasTestResolve::test_an_unknown_name_sends_nothing_and_asks_the_userTestResolve::test_a_unique_exact_contact_name_is_still_only_a_candidateمامانcontact isexact_namecandidate, not resolvedTestResolve::test_a_stale_alias_asks_againstale,--replaceinsave_withTestResolve::test_a_bare_word_that_is_also_an_alias_is_refusedsararefused as ambiguous;name:saraand@saraeach workTestResolve::test_a_bare_word_without_an_alias_is_the_username_as_beforeTestResolve::test_aliases_are_per_accountworkdoes not resolve onhomeTestResolve::test_an_unreadable_store_refuses_rather_than_guessingtest_the_session_resolver_keeps_aliases_next_to_the_peer_cacheTestThroughTheDaemon::test_an_unknown_name_sends_nothingmessage.sendto an unsaved name: no SendMessageRequest, details over the socketTestThroughTheDaemon::test_a_gateway_job_resolves_an_aliasjob_client.resolve_chat("name:sara")TestThroughTheDaemon::test_dialog_status_asks_rather_than_answering_unknownTestOps::*(8 tests)--replacerequired,already, exact peer required, alias as peer, list grouped per person, remove exact onlytest_errors_map.py::TestErrorDetails::*detailsonly when set, v1errorkey kept, surviveserror_from_bodyNot changed, and why
forwardto:) store the destination string and resolve it when the item runs, so an alias repointed with--replacewhile items are queued sends them to the new peer. Gateway filters resolve once at start/reload. Storing the resolved id at enqueue time is a job-actions change, not part of this issue.new_peers_per_day(dead config noted in the report) and echoing the resolved name in every mutating result: out of scope.format_error_json(the legacy flat v1 formatter) does not carrydetails; it is a frozen compatibility shape. The envelope and--results-onlyinner object both do.Not verified
contacts.getContactsfor suggestions and stored access hashes are exercised only through the fake client.make check: pass (lint, mypy, 13756 tests, docs and parity regenerated with no diff).