|
| 1 | +# pilegram |
| 2 | + |
| 3 | +<p align="center"> |
| 4 | + <img src="assets/logo.png" alt="pilegram" width="200"> |
| 5 | +</p> |
| 6 | + |
| 7 | +A personal [pi](https://github.com/earendil-works/pi) coding agent, over Telegram. |
| 8 | + |
| 9 | +## Features |
| 10 | + |
| 11 | +- **Streaming replies** via an editable provisional message, so you can still send `/stop` or steer the agent mid-turn. |
| 12 | +- **Topics = sessions**: each Telegram topic is its own agent session with its own |
| 13 | + workspace and context. The agent can list known threads, create threads, and, |
| 14 | + after explicit confirmation, delete them; it also keeps each topic's **title and |
| 15 | + icon** relevant on its own. |
| 16 | +- **Markdown → Telegram HTML**: headings, code, lists, tables, links render properly. |
| 17 | +- **Images** in (vision) & out, **documents** in (path + inlined text) & out, **albums** both ways. |
| 18 | +- **Voice**, fully local: voice notes are transcribed with **whisper.cpp**; replies |
| 19 | + come back as voice notes synthesized with **Supertonic** (in-process ONNX). Text |
| 20 | + always available as a fallback. |
| 21 | +- **Reactions**: the agent can react to your messages instead of replying in text. |
| 22 | +- **Steering**: a message sent mid-turn is injected into the running turn. |
| 23 | +- **Rich inbound handling**: replies/quotes, forwards, edited messages, stickers, |
| 24 | + locations, contacts, polls, dice. |
| 25 | + |
| 26 | +The only bot command is **`/stop`** (abort the current turn). Everything else you |
| 27 | +type (or say, or send) is a prompt. |
| 28 | + |
| 29 | +## Prerequisites |
| 30 | + |
| 31 | +pilegram runs on **[Bun](https://bun.sh)** and shells out to three tools for voice: |
| 32 | + |
| 33 | +| Tool | Why | Provides | |
| 34 | +| --------------- | -------------------------- | ------------------- | |
| 35 | +| **bun** ≥ 1.3 | runtime | — | |
| 36 | +| **ffmpeg** | transcode audio ↔ OGG/Opus | `ffmpeg`, `ffprobe` | |
| 37 | +| **whisper.cpp** | speech-to-text | `whisper-cli` | |
| 38 | + |
| 39 | +TTS (Supertonic) runs in-process via the `onnxruntime-node` npm dependency — no |
| 40 | +extra system package. Speech model weights download automatically on first use. |
| 41 | + |
| 42 | +## Install |
| 43 | + |
| 44 | +### Without Nix |
| 45 | + |
| 46 | +Install the three tools with your package manager, then the app: |
| 47 | + |
| 48 | +```bash |
| 49 | +# macOS (Homebrew) |
| 50 | +brew install oven-sh/bun/bun ffmpeg whisper-cpp |
| 51 | + |
| 52 | +# Debian/Ubuntu: bun via https://bun.sh; ffmpeg via apt; whisper.cpp from source |
| 53 | +# (must expose a `whisper-cli` binary on PATH) |
| 54 | +sudo apt install ffmpeg |
| 55 | + |
| 56 | +git clone <this repo> && cd pilegram |
| 57 | +bun install |
| 58 | +export TELEGRAM_BOT_TOKEN=123456:AA... # the one secret (or put it in .env) |
| 59 | +bun run src/index.ts --allow 111222333 # your Telegram user id(s) |
| 60 | +``` |
| 61 | + |
| 62 | +`whisper-cli`, `ffmpeg`, and `ffprobe` must be on your `PATH`. That's the only |
| 63 | +requirement voice has — everything else is handled by `bun install`. |
| 64 | + |
| 65 | +### With Nix |
| 66 | + |
| 67 | +The flake builds a **hermetic** package — pinned toolchain (bun + ffmpeg + |
| 68 | +whisper.cpp) _and_ pinned `node_modules` — so it runs from anywhere, not just the |
| 69 | +repo: |
| 70 | + |
| 71 | +```bash |
| 72 | +# one-shot: builds the package and runs it |
| 73 | +TELEGRAM_BOT_TOKEN=… nix run github:you/pilegram -- --allow 111222333 |
| 74 | + |
| 75 | +# or install it onto your PATH |
| 76 | +nix profile install github:you/pilegram |
| 77 | +TELEGRAM_BOT_TOKEN=… pilegram --allow 111222333 |
| 78 | + |
| 79 | +# or a dev shell (bun, ffmpeg, whisper-cli), to run from source |
| 80 | +nix develop |
| 81 | +bun install |
| 82 | +bun run src/index.ts --allow 111222333 |
| 83 | +``` |
| 84 | + |
| 85 | +`node_modules` is a fixed-output derivation: `bun install --frozen-lockfile` |
| 86 | +whose result is pinned by content hash (this keeps the native `onnxruntime-node` |
| 87 | +dylib intact — a real node_modules layout, unlike `bun build --compile`). **When |
| 88 | +you change dependencies**, bump that hash: run `nix build .#node-modules`, copy |
| 89 | +the `got: sha256-…` it prints into `outputHash` in `flake.nix`. |
| 90 | + |
| 91 | +## Telegram setup (BotFather) |
| 92 | + |
| 93 | +1. Create a bot with [@BotFather](https://t.me/BotFather) → copy the **token**. |
| 94 | +2. **Enable topics**: BotFather → `/mybots` → your bot → _Bot Settings_ → turn on |
| 95 | + **Threaded Mode**. (Without this, pilegram runs a single-session DM.) |
| 96 | +3. Find **your numeric user id** (e.g. via [@userinfobot](https://t.me/userinfobot)). |
| 97 | + |
| 98 | +## Configuration |
| 99 | + |
| 100 | +The one **secret** is `TELEGRAM_BOT_TOKEN` (from the environment / `.env`, never a |
| 101 | +flag — argv is visible in `ps`). Everything else is a **CLI flag** (`--help`): |
| 102 | + |
| 103 | +| Flag | Required | Default | Notes | |
| 104 | +| ------------------------ | -------- | ------------------------------------------------------- | --------------------------------------------------------------------------- | |
| 105 | +| `--allow <ids>` | ✅ | — | comma-separated Telegram user ids; everyone else is dropped silently | |
| 106 | +| `--state-dir <path>` | | `$XDG_CONFIG_HOME/pilegram` (else `~/.config/pilegram`) | SQLite db | |
| 107 | +| `--models-dir <path>` | | `$XDG_CACHE_HOME/pilegram` (else `~/.cache/pilegram`) | downloaded speech models (~2 GB cache) | |
| 108 | +| `--db-path <path>` | | `<state-dir>/pilegram.db` | override the db path | |
| 109 | +| `--whisper-model <name>` | | `large-v3-turbo` | whisper.cpp ggml model (e.g. `base.en` for a fast/small English-only start) | |
| 110 | +| `--voice <id>` | | `M1` | Supertonic voice: `M1`–`M5`, `F1`–`F5` | |
| 111 | +| `--tz <zone>` | | `Europe/Stockholm` | local time shown to the agent | |
| 112 | +| `--poll-timeout <sec>` | | `30` | long-poll seconds | |
| 113 | +| `--log-level <level>` | | `info` | `debug`\|`info`\|`warn`\|`error` | |
| 114 | + |
| 115 | +## Trust model |
| 116 | + |
| 117 | +pilegram is single-user by design. Only the Telegram user ids in `--allow` are |
| 118 | +served; every other update is logged and dropped. |
| 119 | + |
| 120 | +The agent runs with **full trust and no approval gate** — it runs shell commands, |
| 121 | +reads and writes files, and sends messages on your behalf without asking. It runs |
| 122 | +as _your_ user, with the same filesystem and network access you have: its working |
| 123 | +directory is your home directory, **not a sandbox**, and tools such as |
| 124 | +`tg_send_document` accept absolute paths. Only `--allow` ids you |
| 125 | +trust to drive an unsandboxed agent, and run pilegram as a dedicated, |
| 126 | +least-privileged user (or in a container) if that reach concerns you. |
0 commit comments