Metadata-Version: 2.5
Name: telegram-to-agent-skill-cli
Version: 0.8.0
Summary: Telegram context for coding agents: local sync, FTS5 search, attachments, links, threads — a tg-cli fork with an agent skill
Project-URL: Homepage, https://github.com/voftik/telegram-to-agent-skill-cli
Project-URL: Repository, https://github.com/voftik/telegram-to-agent-skill-cli
Project-URL: Issues, https://github.com/voftik/telegram-to-agent-skill-cli/issues
Project-URL: Upstream, https://github.com/jackwener/tg-cli
Author-email: jackwener <jakevingoo@gmail.com>
Maintainer: voftik
License: Apache License
        Version 2.0, January 2004
        http://www.apache.org/licenses/
        
        TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
        
        1. Definitions.
        
        "License" shall mean the terms and conditions for use, reproduction, and
        distribution as defined by Sections 1 through 9 of this document.
        
        "Licensor" shall mean the copyright owner or entity authorized by the copyright
        owner that is granting the License.
        
        "Legal Entity" shall mean the union of the acting entity and all other entities
        that control, are controlled by, or are under common control with that entity.
        For the purposes of this definition, "control" means (i) the power, direct or
        indirect, to cause the direction or management of such entity, whether by
        contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
        outstanding shares, or (iii) beneficial ownership of such entity.
        
        "You" (or "Your") shall mean an individual or Legal Entity exercising
        permissions granted by this License.
        
        "Source" form shall mean the preferred form for making modifications, including
        but not limited to software source code, documentation source, and configuration
        files.
        
        "Object" form shall mean any form resulting from mechanical transformation or
        translation of a Source form, including but not limited to compiled object code,
        generated documentation, and conversions to other media types.
        
        "Work" shall mean the work of authorship, whether in Source or Object form,
        made available under the License, as indicated by a copyright notice that is
        included in or attached to the work (an example is provided in the Appendix
        below).
        
        "Derivative Works" shall mean any work, whether in Source or Object form, that
        is based on (or derived from) the Work and for which the editorial revisions,
        annotations, elaborations, or other modifications represent, as a whole, an
        original work of authorship. For the purposes of this License, Derivative Works
        shall not include works that remain separable from, or merely link (or bind by
        name) to the interfaces of, the Work and Derivative Works thereof.
        
        "Contribution" shall mean any work of authorship, including the original version
        of the Work and any modifications or additions to that Work or Derivative Works
        thereof, that is intentionally submitted to Licensor for inclusion in the Work
        by the copyright owner or by an individual or Legal Entity authorized to submit
        on behalf of the copyright owner. For the purposes of this definition,
        "submitted" means any form of electronic, verbal, or written communication sent
        to the Licensor or its representatives, including but not limited to
        communication on electronic mailing lists, source code control systems, and
        issue tracking systems that are managed by, or on behalf of, the Licensor for
        the purpose of discussing and improving the Work, but excluding communication
        that is conspicuously marked or otherwise designated in writing by the copyright
        owner as "Not a Contribution."
        
        "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
        of whom a Contribution has been received by Licensor and subsequently
        incorporated within the Work.
        
        2. Grant of Copyright License. Subject to the terms and conditions of this
        License, each Contributor hereby grants to You a perpetual, worldwide,
        non-exclusive, no-charge, royalty-free, irrevocable copyright license to
        reproduce, prepare Derivative Works of, publicly display, publicly perform,
        sublicense, and distribute the Work and such Derivative Works in Source or
        Object form.
        
        3. Grant of Patent License. Subject to the terms and conditions of this License,
        each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
        no-charge, royalty-free, irrevocable (except as stated in this section) patent
        license to make, have made, use, offer to sell, sell, import, and otherwise
        transfer the Work, where such license applies only to those patent claims
        licensable by such Contributor that are necessarily infringed by their
        Contribution(s) alone or by combination of their Contribution(s) with the Work
        to which such Contribution(s) was submitted. If You institute patent litigation
        against any entity (including a cross-claim or counterclaim in a lawsuit)
        alleging that the Work or a Contribution incorporated within the Work constitutes
        direct or contributory patent infringement, then any patent licenses granted to
        You under this License for that Work shall terminate as of the date such
        litigation is filed.
        
        4. Redistribution. You may reproduce and distribute copies of the Work or
        Derivative Works thereof in any medium, with or without modifications, and in
        Source or Object form, provided that You meet the following conditions:
        
        (a) You must give any other recipients of the Work or Derivative Works a copy of
        this License; and
        
        (b) You must cause any modified files to carry prominent notices stating that
        You changed the files; and
        
        (c) You must retain, in the Source form of any Derivative Works that You
        distribute, all copyright, patent, trademark, and attribution notices from the
        Source form of the Work, excluding those notices that do not pertain to any part
        of the Derivative Works; and
        
        (d) If the Work includes a "NOTICE" text file as part of its distribution, then
        any Derivative Works that You distribute must include a readable copy of the
        attribution notices contained within such NOTICE file, excluding those notices
        that do not pertain to any part of the Derivative Works, in at least one of the
        following places: within a NOTICE text file distributed as part of the
        Derivative Works; within the Source form or documentation, if provided along
        with the Derivative Works; or, within a display generated by the Derivative
        Works, if and wherever such third-party notices normally appear. The contents of
        the NOTICE file are for informational purposes only and do not modify the
        License. You may add Your own attribution notices within Derivative Works that
        You distribute, alongside or as an addendum to the NOTICE text from the Work,
        provided that such additional attribution notices cannot be construed as
        modifying the License.
        
        You may add Your own copyright statement to Your modifications and may provide
        additional or different license terms and conditions for use, reproduction, or
        distribution of Your modifications, or for any such Derivative Works as a whole,
        provided Your use, reproduction, and distribution of the Work otherwise complies
        with the conditions stated in this License.
        
        5. Submission of Contributions. Unless You explicitly state otherwise, any
        Contribution intentionally submitted for inclusion in the Work by You to the
        Licensor shall be under the terms and conditions of this License, without any
        additional terms or conditions. Notwithstanding the above, nothing herein shall
        supersede or modify the terms of any separate license agreement you may have
        executed with Licensor regarding such Contributions.
        
        6. Trademarks. This License does not grant permission to use the trade names,
        trademarks, service marks, or product names of the Licensor, except as required
        for reasonable and customary use in describing the origin of the Work and
        reproducing the content of the NOTICE file.
        
        7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
        writing, Licensor provides the Work (and each Contributor provides its
        Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
        KIND, either express or implied, including, without limitation, any warranties
        or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
        PARTICULAR PURPOSE. You are solely responsible for determining the
        appropriateness of using or redistributing the Work and assume any risks
        associated with Your exercise of permissions under this License.
        
        8. Limitation of Liability. In no event and under no legal theory, whether in
        tort (including negligence), contract, or otherwise, unless required by
        applicable law (such as deliberate and grossly negligent acts) or agreed to in
        writing, shall any Contributor be liable to You for damages, including any
        direct, indirect, special, incidental, or consequential damages of any character
        arising as a result of this License or out of the use or inability to use the
        Work (including but not limited to damages for loss of goodwill, work stoppage,
        computer failure or malfunction, or any and all other commercial damages or
        losses), even if such Contributor has been advised of the possibility of such
        damages.
        
        9. Accepting Warranty or Additional Liability. While redistributing the Work or
        Derivative Works thereof, You may choose to offer, and charge a fee for,
        acceptance of support, warranty, indemnity, or other liability obligations
        and/or rights consistent with this License. However, in accepting such
        obligations, You may act only on Your own behalf and on Your sole responsibility,
        not on behalf of any other Contributor, and only if You agree to indemnify,
        defend, and hold each Contributor harmless for any liability incurred by, or
        claims asserted against, such Contributor by reason of your accepting any such
        warranty or additional liability.
        
        END OF TERMS AND CONDITIONS
License-File: LICENSE
Keywords: agent,cli,search,telegram,telethon,tg
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Communications :: Chat
Classifier: Topic :: Utilities
Requires-Python: >=3.10
Requires-Dist: click>=8.3.3
Requires-Dist: openpyxl>=3.1
Requires-Dist: packaging>=23
Requires-Dist: pyasn1>=0.6.4
Requires-Dist: pygments>=2.20.0
Requires-Dist: pypdf>=4.0
Requires-Dist: python-dotenv>=1.0
Requires-Dist: pyyaml>=6.0
Requires-Dist: rich>=13.0
Requires-Dist: telethon>=1.36
Description-Content-Type: text/markdown

<div align="center">

<img src="docs/assets/hero.svg" alt="telegram-to-agent-skill-cli" width="100%"/>

**English** · [Русский](README.ru.md)

[![CI](https://github.com/voftik/telegram-to-agent-skill-cli/actions/workflows/ci.yml/badge.svg)](https://github.com/voftik/telegram-to-agent-skill-cli/actions/workflows/ci.yml)
[![PyPI](https://img.shields.io/pypi/v/telegram-to-agent-skill-cli)](https://pypi.org/project/telegram-to-agent-skill-cli/)
[![npm](https://img.shields.io/npm/v/telegram-to-agent-skill-cli)](https://www.npmjs.com/package/telegram-to-agent-skill-cli)
[![License: Apache-2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)
![Python 3.10+](https://img.shields.io/badge/Python-3.10%2B-3776AB?logo=python&logoColor=white)

*Ask your coding agent "what did the team discuss this week?" and it actually knows.*

</div>

---

Half of every project's real context lives in Telegram: decisions made in group chats, specs shared as files, links that never made it to the wiki. This tool gives that context to Claude Code, Codex, or any agent that can run a CLI.

The `tg` CLI signs in as you (MTProto via [Telethon](https://github.com/LonamiWebs/Telethon)), syncs your chats into a local SQLite index with full-text search, and installs an agent skill that activates itself whenever you mention your chats. Agents read locally: instant, offline, no rate limits. The CLI touches Telegram only to sync, download files, or (after your explicit "yes") send a reply.

<div align="center">
<img src="docs/assets/demo.svg" alt="Agent session demo" width="80%"/>
</div>

## Install

Pick any of the three. Each one ends in the interactive setup wizard: sign-in, agent skill, desktop apps, initial sync. No API keys needed: press Enter and the built-in Telegram Desktop keys are used (your own from my.telegram.org stay recommended for heavy syncing).

```bash
# with uv (recommended)
uv tool install telegram-to-agent-skill-cli && tg setup
```

```bash
# one-shot, no prior install
uvx --from telegram-to-agent-skill-cli tg setup
```

```bash
# via npm, if Node is your home turf
npx telegram-to-agent-skill-cli
```

Developers clone the repo and run `./install.sh` (editable install, same wizard). Details: [docs/INSTALL.md](docs/INSTALL.md).

Claude Code users can also add the repo as a plugin marketplace, which installs the skill without touching the shell:

```
/plugin marketplace add voftik/telegram-to-agent-skill-cli
/plugin install telegram-context@telegram-to-agent-skill-cli
```

The CLI itself still comes from PyPI (the skill will tell you the install command if `tg` is missing).

## Update

```bash
tg update          # checks PyPI, upgrades, refreshes the agent skill
tg update --check  # just report; agents read update.update_available from `tg status --yaml`
```

The CLI never phones home on its own in data commands: the passive version hint reads a local cache and prints to stderr only in interactive sessions. Set `TG_UPDATE_CHECK=0` to silence it.

## Desktop chat apps

Claude Desktop, Perplexity and ChatGPT (chat mode) cannot run a CLI, but they can run local MCP servers. One command wires them to the same local index through `tg mcp`, a read-only bridge that never touches the Telegram session:

```bash
tg connect
```

It detects the apps, writes their configs, self-tests the bridge and offers `tg autosync` (a scheduled refresh that keeps the index fresh). Details per app: [docs/DESKTOP-APPS.md](docs/DESKTOP-APPS.md) (in Russian).

## Why skill-first (and where the MCP bridge fits)

- **Zero context tax.** MCP tool schemas eat tokens in every session. A skill loads on demand; the CLI costs nothing until used. Coding agents (Claude Code, Codex) get the full skill + CLI.
- **One integration, every agent.** The same `tg` commands work in Claude Code, Codex, and anything else with a shell.
- **No session juggling.** Sync is owned by one CLI process on the host; any number of agent sessions read the SQLite index. The bundled `tg mcp` bridge follows the same rule: it is a read-only adapter for hosts without a shell, six small tools, no Telegram session, no sends.

## How it works

```mermaid
flowchart LR
    TG[("Telegram<br/>(your account, MTProto)")]
    subgraph LOCAL["Your machine"]
        SYNC["tg sync / refresh<br/><i>on demand</i>"]
        DB[("SQLite + FTS5<br/>messages · attachments · links · threads")]
        FILES["files/ + extracted text<br/>pdf · docx · xlsx · pptx"]
        QUERY["tg brief · search · thread<br/>links · files · style"]
    end
    subgraph AGENTS["Agents"]
        CC["Claude Code<br/><i>skill auto-activates</i>"]
        CX["Codex<br/><i>via AGENTS.md</i>"]
    end
    TG -->|history| SYNC --> DB
    TG -->|lazy download| FILES
    DB --> QUERY
    QUERY --> CC & CX
    FILES --> CC & CX
    CC & CX -.->|"send only with --confirm<br/>after explicit user yes"| TG
```

## What agents can do with it

| Ask in plain language | What happens under the hood |
| --- | --- |
| "What did we discuss in the project chat?" | `sync`, then `brief` picks the depth, then `recent` and a summary with dates and authors |
| "Find where they shared the pricing doc" | `tg links --kind gdoc` returns the export URL (plain text, not a JS shell) |
| "Read the spec they sent as a file" | `tg files --download` extracts text next to the file |
| "Reconstruct that argument about the deadline" | `tg thread` rebuilds the reply chain, even when the root is a poll |
| "Draft a reply in my voice" | `tg style` gives the agent your own messages; drafts stay dry-run until you say yes |
| "Digest my work chats since yesterday" | the agent loops chats, collects highlights, flags what needs your reaction |

## Safety model

- The Telethon session file equals full account access. It lives in a private data dir (0700/0600), never in git, never in cloud-synced folders; every machine signs in separately.
- Every write to Telegram (`send`, `edit`, `delete`) is a dry-run without `--confirm`. Confirmed mutations land in a durable journal before the network call.
- Untrusted attachments face budgets: size checks before download, zip-bomb guards, streaming hashes, private file modes.
- Use your own `api_id` and `api_hash`. The tool syncs politely (delays, jitter, FloodWait handling) and reads locally.

## How it compares

Honest comparison with the other ways to give an agent your Telegram (state of the ecosystem, August 2026):

| | **tg (this project)** | Telegram MCP servers¹ | Upstream tg-cli | Telegram Desktop export |
| --- | --- | --- | --- | --- |
| Works in any CLI agent | yes, one install | per-agent MCP config | yes | manual copy-paste |
| Session context cost | zero until used | tool schemas eat tokens in every session | zero | zero |
| Search over all history | FTS5, milliseconds, offline | live API calls, rate-limited | `LIKE` scan | none (static files) |
| Attachments as readable text | pdf/docx/xlsx/pptx extracted | download at best | not stored | raw files |
| Google Docs links | ready-to-fetch export URLs | no | no | no |
| Thread reconstruction | yes, incl. t.me links | partial | no | no |
| Parallel agent sessions | any number of readers | session-file conflicts² | single user | n/a |
| Send safety | dry-run default, `--confirm`, journal | varies; several send immediately | sends immediately | n/a |
| Sync integrity | gap-safe cursors, `tg backfill` | n/a (live reads) | best effort | one-off snapshot |
| Data freshness | incremental sync in seconds | always live | incremental | frozen at export |
| Install and update | `npx`/`uv` one-liner, `tg update` | manual server config | pip | built into the app |

¹ chigwell/telegram-mcp, chaindead/telegram-mcp, overpod/mcp-telegram and similar. They still fit when your agent lives in claude.ai web, which cannot spawn local processes at all; chaindead's drafts-only design is a genuinely safe touch. Desktop hosts (Claude Desktop, Perplexity, ChatGPT desktop) are covered by the bundled read-only `tg mcp` bridge instead.
² Telethon/GramJS allow one process per session file; MCP servers spawn per agent session and collide (the shared-daemon setups that avoid this need extra configuration).

## What the fork adds over upstream tg-cli

| Area | [upstream](https://github.com/jackwener/tg-cli) | this fork |
| --- | --- | --- |
| Attachments | not stored | indexed at sync, lazy download, text extraction (pdf/docx/xlsx/pptx/csv) |
| Links | not extracted | `tg links` with agent-fetchable `fetch_url`, structural URL parsing |
| Threads | none | `tg thread`, resilient to unsynced roots, t.me link support |
| Search | `LIKE` scan | FTS5 with Unicode-correct fallback and gap-safe regex paging |
| Sync integrity | best effort | gap-safe cursors, `tg backfill`, honest per-chat reports |
| Identity | bare IDs collide | marked peer IDs end-to-end with lazy migration |
| First sync | manual | `tg bootstrap`: survives reboots, removes itself when done |
| Send safety | sends immediately | dry-run by default, `--confirm`, mutation journal |
| Agent integration | a doc file | packaged skill, setup wizard, self-update, auto-activation, MCP bridge for desktop chat apps |

## Credits

A fork of [jackwener/tg-cli](https://github.com/jackwener/tg-cli) (Apache-2.0): the clean local-first core is theirs. Built on [Telethon](https://github.com/LonamiWebs/Telethon). License: [Apache-2.0](LICENSE).
