clitg 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
clitg-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Leynier Gutiérrez González
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
clitg-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,359 @@
1
+ Metadata-Version: 2.4
2
+ Name: clitg
3
+ Version: 0.1.0
4
+ Summary: Agent-first Telegram CLI with structured JSON and skills for Claude Code, Codex, Copilot, Cursor, and more
5
+ Keywords: telegram,telegram-cli,ai-agents,agent-skills,claude-code,codex,antigravity,github-copilot,grok,cursor,amp,mtproto,telethon,typer
6
+ Author: Leynier Gutiérrez González
7
+ Author-email: Leynier Gutiérrez González <leynier41@gmail.com>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Environment :: Console
12
+ Classifier: Programming Language :: Python :: 3.14
13
+ Classifier: Topic :: Communications :: Chat
14
+ Requires-Dist: filelock>=3.31.1,<4.0.0
15
+ Requires-Dist: platformdirs>=4.10.1,<5.0.0
16
+ Requires-Dist: pydantic>=2.13.4,<3.0.0
17
+ Requires-Dist: telethon>=1.44.0,<2.0.0
18
+ Requires-Dist: typer>=0.27.0,<0.28.0
19
+ Requires-Python: >=3.14, <3.15
20
+ Project-URL: Homepage, https://github.com/leynier/telegram-cli
21
+ Project-URL: Repository, https://github.com/leynier/telegram-cli
22
+ Project-URL: Issues, https://github.com/leynier/telegram-cli/issues
23
+ Description-Content-Type: text/markdown
24
+
25
+ # clitg: Telegram CLI for AI agents
26
+
27
+ Give your AI agent a real, scriptable interface to your Telegram user account. `clitg` can read
28
+ conversations, find contacts, send and edit messages, transfer files, manage polls and scheduled
29
+ messages, inspect forum topics, and reach the wider MTProto API, all through deterministic commands
30
+ and structured JSON.
31
+
32
+ `clitg` is built for agent workflows powered by **Claude Code**, **OpenAI Codex**, **Google
33
+ Antigravity**, **GitHub Copilot**, **xAI Grok**, **Cursor**, **Amp**, and any other AI agent that can
34
+ execute shell commands and consume JSON or JSONL. It is an unofficial Telegram client for user
35
+ accounts, powered by Telethon; it is not a Bot API wrapper and does not require a BotFather token.
36
+
37
+ ## Turn Telegram into an agent tool
38
+
39
+ - **Agent-native I/O:** explicit arguments in, versioned JSON or streaming JSONL out, with no interactive
40
+ prompts to block an automation.
41
+ - **Your full user account:** work with private chats, Saved Messages, groups, channels, contacts,
42
+ media, reactions, polls, scheduled messages, and forum topics wherever Telegram permits it.
43
+ - **A large escape hatch:** use the schema-aware raw MTProto gateway when a dedicated command does
44
+ not exist, backed by a generated capability catalog.
45
+ - **Guardrails for real accounts:** preview mutations with dry-run, require explicit confirmation
46
+ for destructive actions, protect critical raw calls with short-lived tokens, and avoid duplicate
47
+ sends with idempotency keys.
48
+ - **Discoverable by agents:** ship `clitg` together with an installable Agent Skill and
49
+ machine-readable help, schemas, errors, cursors, and capability metadata.
50
+
51
+ Use it to build inbox assistants, Telegram research agents, notification and follow-up workflows,
52
+ message triage, personal knowledge capture, scheduled delivery, media pipelines, or your own
53
+ Telegram automation layer without designing another integration protocol.
54
+
55
+ > [!IMPORTANT]
56
+ > A Telethon session grants access to the associated Telegram account. Never commit, upload, or
57
+ > share session files. `clitg` stores them outside the repository using platform-specific user data
58
+ > directories and restrictive permissions.
59
+
60
+ ## What you get
61
+
62
+ - Multiple isolated user-account profiles.
63
+ - Phone, login-code, and optional 2FA authentication without prompts.
64
+ - Dialog, contact, group, channel, and message discovery.
65
+ - Text, replies, forwarding, editing, deletion, read acknowledgements, reactions, pins, files,
66
+ albums, voice notes, stickers, polls, scheduled messages, and forum topics.
67
+ - A schema-aware raw MTProto gateway for methods without dedicated commands.
68
+ - JSON Schema and capability catalogs designed for AI agents.
69
+ - Dry-run, explicit destructive confirmation, critical one-use tokens, and local idempotency.
70
+
71
+ Bots, QR/passkey login, live update streaming, calls, and secret-chat encryption are not supported
72
+ in v0.1.
73
+
74
+ ## Quick start
75
+
76
+ Install [uv](https://docs.astral.sh/uv/) and then install the published tool:
77
+
78
+ ```bash
79
+ uv tool install clitg
80
+ clitg --version
81
+ ```
82
+
83
+ `clitg` requires Python 3.14. uv downloads a compatible interpreter automatically unless managed
84
+ Python downloads have been disabled.
85
+
86
+ For development:
87
+
88
+ ```bash
89
+ git clone https://github.com/leynier/telegram-cli.git
90
+ cd telegram-cli
91
+ uv sync --all-groups
92
+ uv run clitg --version
93
+ ```
94
+
95
+ The project itself, dependencies, and lockfile are managed with `uv init`, `uv add`, `uv remove`,
96
+ and `uv lock`. Do not edit dependency arrays manually.
97
+
98
+ ## Install the Agent Skill
99
+
100
+ The repository includes a `clitg` skill for the open Agent Skills ecosystem. Install it with either
101
+ the npm or Bun runner:
102
+
103
+ ```bash
104
+ # npm / Node.js
105
+ npx skills add leynier/telegram-cli --skill clitg
106
+
107
+ # Bun
108
+ bunx skills add leynier/telegram-cli --skill clitg
109
+ ```
110
+
111
+ You can also target a specific supported agent and install globally without prompts:
112
+
113
+ ```bash
114
+ npx skills add leynier/telegram-cli --skill clitg --agent claude-code -g -y
115
+ bunx skills add leynier/telegram-cli --skill clitg --agent codex -g -y
116
+ ```
117
+
118
+ The open [`skills` CLI](https://github.com/vercel-labs/skills) supports Claude Code, Codex,
119
+ Antigravity, GitHub Copilot, Cursor, Amp, and many other agents. `clitg` itself remains
120
+ agent-agnostic, so Grok and other shell-capable agents can call the same structured CLI even when
121
+ they use a different skill-loading mechanism.
122
+
123
+ The skill teaches an agent the command contract and safety rules, but deliberately does not install
124
+ the executable. If `clitg` is missing, it reports `uv tool install clitg` and stops.
125
+
126
+ ## Get your Telegram App ID and API hash
127
+
128
+ Telegram user-account clients need an application identity. This is different from a Telegram bot
129
+ token. Obtain it from Telegram's official developer portal:
130
+
131
+ 1. Open [my.telegram.org/apps](https://my.telegram.org/apps).
132
+ 2. Enter your phone number in international format and select **Next**.
133
+ 3. Enter the confirmation code Telegram sends inside the Telegram app, not by SMS.
134
+ 4. Open **API development tools**.
135
+ 5. Complete the application form with an app title, short name, and platform.
136
+ 6. Copy **App api_id** into `CLITG_API_ID` and **App api_hash** into `CLITG_API_HASH`.
137
+
138
+ Treat the API hash like a password: never publish it, paste it into an issue, or commit it to Git.
139
+ Set the credentials locally:
140
+
141
+ ```bash
142
+ export CLITG_API_ID='12345678'
143
+ export CLITG_API_HASH='your-private-api-hash'
144
+ export CLITG_PHONE='+15551234567'
145
+ ```
146
+
147
+ Create a local profile without exposing the hash in shell arguments:
148
+
149
+ ```bash
150
+ clitg profiles create \
151
+ --name personal \
152
+ --default
153
+ ```
154
+
155
+ Credential values can come from explicit options, secret files, or `CLITG_API_ID`,
156
+ `CLITG_API_HASH`, `CLITG_PHONE`, `CLITG_CODE`, and `CLITG_PASSWORD`. Direct options take
157
+ precedence. Login codes and 2FA passwords are never persisted.
158
+
159
+ Request the login code and finish the resumable login flow. Telegram delivers the code inside your
160
+ Telegram app. Accounts with two-step verification also need `--password-file`:
161
+
162
+ ```bash
163
+ clitg --profile personal auth request-code --phone +15551234567
164
+ clitg --profile personal auth verify \
165
+ --login-id '<login-id-from-the-first-command>' \
166
+ --code-file ./telegram-code.txt \
167
+ --password-file ./telegram-2fa.txt
168
+ clitg --profile personal auth status
169
+ ```
170
+
171
+ After authentication, try a read-only command or send a controlled message to Saved Messages:
172
+
173
+ ```bash
174
+ clitg --profile personal dialogs list --limit 10
175
+ clitg --profile personal messages send --peer me --text 'Hello from my AI agent' --dry-run
176
+ ```
177
+
178
+ ## Structured output
179
+
180
+ Every operational command writes one envelope to stdout:
181
+
182
+ ```json
183
+ {
184
+ "schema_version": "0.1",
185
+ "ok": true,
186
+ "data": {},
187
+ "error": null,
188
+ "meta": {
189
+ "command": "messages.list",
190
+ "profile": "personal",
191
+ "request_id": "...",
192
+ "next_cursor": null
193
+ }
194
+ }
195
+ ```
196
+
197
+ Failures use the same envelope and a nonzero exit code. `--output jsonl` emits `item` records and
198
+ always ends with `summary` or `error`. Human help remains available with `--help`; agents can use
199
+ `--help-json`, `schema`, and `capabilities`.
200
+
201
+ `clitg help` is equivalent to `clitg --help`, and `clitg version` is equivalent to
202
+ `clitg --version`.
203
+
204
+ Global options must precede the command group:
205
+
206
+ ```bash
207
+ clitg --profile personal --output jsonl messages list --peer @example --limit 25
208
+ ```
209
+
210
+ Opaque cursors are returned in `meta.next_cursor` and can be passed back with `--cursor`. Listing or
211
+ searching messages never marks them read; use `messages read` explicitly.
212
+
213
+ Exit codes are stable within schema `0.1`:
214
+
215
+ | Code | Meaning |
216
+ | ---: | --- |
217
+ | 0 | Success |
218
+ | 1 | Internal error |
219
+ | 2 | Invalid input or CLI usage |
220
+ | 3 | Profile or authentication error |
221
+ | 4 | Missing or ambiguous entity |
222
+ | 5 | Conflict or missing confirmation |
223
+ | 6 | Telegram permission failure |
224
+ | 7 | Telegram rate limit |
225
+ | 8 | Telegram RPC or network failure |
226
+
227
+ ## Messaging
228
+
229
+ Read and search without changing read state:
230
+
231
+ ```bash
232
+ clitg --profile personal dialogs list --limit 50
233
+ clitg --profile personal messages list --peer @example --limit 50
234
+ clitg --profile personal messages search --peer @example --query invoice
235
+ clitg --profile personal messages get --peer @example --message-id 123
236
+ ```
237
+
238
+ Plain text is the default. Markdown or HTML must be explicit:
239
+
240
+ ```bash
241
+ clitg --profile personal messages send \
242
+ --peer @example \
243
+ --text '**Status:** complete' \
244
+ --parse-mode markdown \
245
+ --idempotency-key job-42 \
246
+ --dry-run
247
+
248
+ clitg --profile personal messages send \
249
+ --peer @example \
250
+ --text '**Status:** complete' \
251
+ --parse-mode markdown \
252
+ --idempotency-key job-42
253
+ ```
254
+
255
+ Text and raw JSON accept a literal option, a file, or stdin as mutually exclusive sources. Repeat
256
+ `--file` to send an album. Use `--media-kind voice`, `sticker`, or `document` when inference is not
257
+ appropriate. `--schedule-at` requires RFC 3339 with an offset.
258
+
259
+ Destructive operations require an exact intention:
260
+
261
+ ```bash
262
+ clitg --profile personal messages delete \
263
+ --peer @example \
264
+ --message-id 123 \
265
+ --scope everyone \
266
+ --dry-run
267
+
268
+ clitg --profile personal messages delete \
269
+ --peer @example \
270
+ --message-id 123 \
271
+ --scope everyone \
272
+ --confirm messages.delete
273
+ ```
274
+
275
+ Downloads require an explicit destination and never overwrite implicitly:
276
+
277
+ ```bash
278
+ clitg --profile personal media download \
279
+ --peer @example \
280
+ --message-id 123 \
281
+ --output ./downloads/document.pdf \
282
+ --create-dirs
283
+ ```
284
+
285
+ ## Raw MTProto gateway
286
+
287
+ Inspect support first:
288
+
289
+ ```bash
290
+ clitg capabilities get --method messages.getHistory
291
+ clitg --profile personal raw invoke \
292
+ --method help.getConfig \
293
+ --params '{}' \
294
+ --allow-raw \
295
+ --dry-run
296
+ ```
297
+
298
+ Nested TL constructors use an `_` discriminator. Special values include `$peer`, `$bytes`,
299
+ `$datetime`, and `$upload`:
300
+
301
+ ```json
302
+ {
303
+ "peer": {"$peer": "@example"},
304
+ "offset_id": 0,
305
+ "offset_date": null,
306
+ "add_offset": 0,
307
+ "limit": 10,
308
+ "max_id": 0,
309
+ "min_id": 0,
310
+ "hash": 0
311
+ }
312
+ ```
313
+
314
+ All raw calls require `--allow-raw`. Destructive calls additionally require
315
+ `--confirm <method>`. Critical or unclassified methods require a dry-run-generated
316
+ `--confirmation-token`; the token is payload-bound, single-use, and valid for five minutes.
317
+
318
+ The checked-in `schemas/capabilities.json` classifies every request in the installed Telethon
319
+ layer. `schemas/schemas.json` contains the public Pydantic schemas. CI rejects drift after a
320
+ Telethon or model update.
321
+
322
+ ## Local state
323
+
324
+ `clitg state get` reports counts only. No message-content audit log is created. Idempotency state is
325
+ retained until explicitly pruned:
326
+
327
+ ```bash
328
+ clitg state prune --kind idempotency --dry-run
329
+ clitg state prune --kind idempotency --confirm state.prune
330
+ ```
331
+
332
+ Pending logins expire with Telegram. Critical confirmation tokens expire after five minutes.
333
+
334
+ ## Development quality gates
335
+
336
+ ```bash
337
+ uv lock --check
338
+ uv run ruff format --check .
339
+ uv run ruff check .
340
+ uv run ty check
341
+ uv run pytest --cov=clitg --cov-branch --cov-fail-under=100
342
+ uv run python -m clitg.catalog
343
+ git diff --exit-code -- schemas
344
+ uv build --no-sources
345
+ ```
346
+
347
+ The normal suite uses fakes and never needs personal Telegram credentials. A separate manual,
348
+ secret-gated workflow targets Telegram Test DC.
349
+
350
+ ## Terms and privacy
351
+
352
+ `clitg` is an unofficial third-party client and is not affiliated with Telegram. Operators are
353
+ responsible for complying with the [Telegram API Terms of Service](https://core.telegram.org/api/terms),
354
+ including privacy, consent, branding, automation, and content/AI restrictions. The CLI does not
355
+ attempt to bypass read receipts, rate limits, permissions, or other platform behavior.
356
+
357
+ ## License
358
+
359
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,93 @@
1
+ [project]
2
+ name = "clitg"
3
+ version = "0.1.0"
4
+ description = "Agent-first Telegram CLI with structured JSON and skills for Claude Code, Codex, Copilot, Cursor, and more"
5
+ readme = "readme.md"
6
+ authors = [
7
+ { name = "Leynier Gutiérrez González", email = "leynier41@gmail.com" }
8
+ ]
9
+ requires-python = ">=3.14,<3.15"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ keywords = [
13
+ "telegram",
14
+ "telegram-cli",
15
+ "ai-agents",
16
+ "agent-skills",
17
+ "claude-code",
18
+ "codex",
19
+ "antigravity",
20
+ "github-copilot",
21
+ "grok",
22
+ "cursor",
23
+ "amp",
24
+ "mtproto",
25
+ "telethon",
26
+ "typer",
27
+ ]
28
+ classifiers = [
29
+ "Development Status :: 3 - Alpha",
30
+ "Environment :: Console",
31
+ "Programming Language :: Python :: 3.14",
32
+ "Topic :: Communications :: Chat",
33
+ ]
34
+
35
+ dependencies = [
36
+ "filelock>=3.31.1,<4.0.0",
37
+ "platformdirs>=4.10.1,<5.0.0",
38
+ "pydantic>=2.13.4,<3.0.0",
39
+ "telethon>=1.44.0,<2.0.0",
40
+ "typer>=0.27.0,<0.28.0",
41
+ ]
42
+
43
+ [dependency-groups]
44
+ dev = [
45
+ "pytest>=9.1.1,<10.0.0",
46
+ "pytest-asyncio>=1.4.0,<2.0.0",
47
+ "pytest-cov>=7.1.0,<8.0.0",
48
+ "pyyaml>=6.0.3,<7.0.0",
49
+ "ruff>=0.15.22,<0.16.0",
50
+ "ty>=0.0.61,<0.0.62",
51
+ ]
52
+
53
+ [project.scripts]
54
+ clitg = "clitg.cli:main"
55
+
56
+ [project.urls]
57
+ Homepage = "https://github.com/leynier/telegram-cli"
58
+ Repository = "https://github.com/leynier/telegram-cli"
59
+ Issues = "https://github.com/leynier/telegram-cli/issues"
60
+
61
+ [build-system]
62
+ requires = ["uv_build>=0.11.30,<0.12.0"]
63
+ build-backend = "uv_build"
64
+
65
+ [tool.ruff]
66
+ target-version = "py314"
67
+ line-length = 100
68
+
69
+ [tool.ruff.lint]
70
+ select = ["E", "F", "I", "UP", "B", "SIM", "RUF"]
71
+ ignore = ["COM812"]
72
+
73
+ [tool.ruff.lint.per-file-ignores]
74
+ "src/clitg/cli.py" = ["B008"]
75
+ "tests/**" = ["ARG", "PLR2004", "S101"]
76
+
77
+ [tool.ty.environment]
78
+ python-version = "3.14"
79
+
80
+ [tool.pytest.ini_options]
81
+ addopts = "--strict-config --strict-markers"
82
+ asyncio_mode = "auto"
83
+ markers = ["telegram_test_dc: requires explicit Telegram test DC credentials"]
84
+ testpaths = ["tests"]
85
+
86
+ [tool.coverage.run]
87
+ branch = true
88
+ source = ["clitg"]
89
+
90
+ [tool.coverage.report]
91
+ fail_under = 100
92
+ show_missing = true
93
+ skip_covered = false