Skip to content
This repository was archived by the owner on Dec 2, 2026. It is now read-only.
codejunkienickPublic archive

About

Superseded by https://github.com/codejunkienick/yardr-tg (Go v2). Archived Python bridge.

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

yardr-telegram

Working in the author's yard (2026-11-26). The bridge is deployed to both of the author's yard bridges (release 73e3d85) and in daily use there, against the installed yardr 1f3e8ecd5357.

Public source, not an installable release (2026-11-14). Basic pack adoption is proved offline on public core 52e22d57. Thread formats (#20) and guarded answers (#17) have merged upstream. The latest release checked, v0.17.0, refuses this pack with thread.formats: unknown key, even without native keys. Installable presentation waits for a compatible public core release and the exact-candidate re-check. The tested main revision is source evidence, not a released install target.

A private Telegram bridge for a yardr yard: one paired chat with the yard's crew, its topics, tap-button asks, pins, reactions, typing and on-host voice transcription. The bridge runs as a service of its own, and the yard reaches it as the declared source tgbridge (yardr/).

yardr's bundled telegram pack uses a webhook with a public HTTPS URL and needs no separate bridge service. This bridge uses long polling and a verified loopback hook, adding its ledger, history, topics, buttons and optional local transcription. It costs a Python 3.11+ service per bot, with its own updates, secrets, state and rollback. Use one integration per bot: the bundled pack's setWebhook conflicts with this bridge's getUpdates polling. See the proposal and evidence.

(Terms such as the paired chat and the ledger: bridge/OPERATIONS.md, "Terms".)

Release history: CHANGELOG.md.

What it does

  • The paired user gets a private chat with the yard's crew (the yardmaster by default) for text in both directions, with Telegram HTML formatting on outbound text. A message the user forwards reaches the yard marked as forwarded, its content quoted as material rather than the user's instruction.
  • The agent gets inbound photos, documents, videos, voice and audio files saved on the host, and can send photos, videos, documents, voice notes and round video notes to the chat.
  • The agent sends several screenshots as one album (--attachment given 2-10 times) under one key, captioned by the body.
  • When transcription is enabled, the yard gets each voice and audio note transcribed on the host with whisper.cpp in the configured language, with no cloud service. With method = "auto", it uses the GPU when one is free. An English-only (.en) model requires language = "en".
  • The yard gets a delivery ledger that stops a retried send from posting twice and reports an unknown outcome instead of resending it, and a message log that yardr thread show reads whole.
  • A crew member sends an update that needs no action silently: it still notifies, but with no sound, so only asks and problems ring.
  • A yard keeps one pinned message per slot at the top of the chat, edited in place (yardr call tgbridge pin), such as a list of what waits on the user.
  • A yard gives the paired chat topics, one per subject beside General, each its own conversation: <root>/bin/telegram-bridge topics creates the topics its settings list ([[topic]]) once and prints the yardr subscribe line that routes each to a crew member.
  • The paired user gets a slash command menu, and a yard adds commands through its own handler programs that answer with text and inline buttons and need no enable flag.
  • The paired user sees a reaction on a message once the yard has it (seen, when the settings turn it on) and another when the work it asked for is done (yardr call tgbridge react reaction=done). Every bot can show πŸ•Š landed, πŸ‘€ read and πŸ‘Œ done for its conversation's crew: set [yardr] home and [reactions] on_accept = true, seen = "πŸ•Š", read = "πŸ‘€". Adding operator and nudge_after = 300 enables verified unread Nudge offers where the core supports them. Set cards = false on non-owner bots.
  • The paired user sees "typing..." after a message the yard has, until the bridge's next send, when the settings turn it on ([typing]).
  • The paired user answers an ask on a text message or on one photo message (the caption is the question) by tapping one of its inline buttons instead of typing: one tap reaches the yard once as one actionable message, and the ask message then shows the choice. When the user answers some other way, the crew member closes the ask with the decision made (yardr call tgbridge ask_close): its buttons go and it shows the decision.
  • Each yard gets its own bot, settings file, bridge process, delivery ledger and installed copy of the code on one host, and the bridges share one whisper.cpp build, its models and the transcription queue.
  • The operator gets setup checks from install.sh and check-install before the bridge runs, and a service for each yard: a systemd user unit on Linux and WSL 2, a launchd agent on macOS.
  • The repository includes skills for Telegram formatting, attachments and voice transcripts; installing/assigning them with skill add/skills= is an aligned-fork-only operator workflow, skipped on public core.
Path What
bridge/bridge.py the bridge: run, probe, send, ask-close, run-ask, ask-card, siding-card, react, pin, topics, set-commands, render-unit, check-install, and the yard API on its loopback port
bridge/OPERATIONS.md the operations guide: settings, launch, delivery recovery, transcription
docs/design/tap-confirmation.md the two-tap gate for weighty Telegram cards
docs/design/depot-pack-approvals.md the depot-pack approval contract, activation watermark and rollback
docs/design/upstream-alignment.md the aligned and plain-upstream call contract, rollout and rollback
bridge/test_*.py sh scripts/test.sh (fake Telegram and whisper-cli, an optional isolated real yardr store, and the pack tests; no external network). Set TEST_PORT_RANGE=LOW-HIGH to bind test servers inside that range. Pick a range that excludes ports the host's own services use.
settings.example.toml every settings key, with example values
install.sh installs one yard's bridge as its own release copy of a clean commit under its root, checks its settings and host, mints the two secrets, renders its service and launchers; --rollback returns to the previous release
yardr/ the yardr pack: the declared source tgbridge (tgbridge.yaml), its normalize and thread commands, and SETUP.md, the steps for a yard
YARDR.md the contract between the bridge and a yard: the inbound body, the yard API, the settings
systemd/telegram-bridge.service.in the Linux unit template; on macOS the agent is rendered by <root>/bin/telegram-bridge render-unit
transcriber/ voice_transcribe.py (whisper.cpp, configured language), adapter.py (the bridge's contract), models.sha256
skills/ the shared skills: telegram-formatting, telegram-attachments, telegram-voice-transcripts; telegram-decisions for coordinators with the relevant call grants

Testing

Run sh scripts/test.sh -v for the offline bridge and pack suites (parallel by default, capped by CPU count; pass --serial to run serially or -j N / TGBRIDGE_TEST_JOBS=N to set worker count, and pass a file path such as sh scripts/test.sh bridge/test_bridge.py to run one file for debugging). The public CI matrix runs without a core: isolated native tests skip explicitly when neither TGBRIDGE_TEST_YARDR nor a yardr executable on PATH is available. The model-switch skip reason names crew_handoff_switch v1. A supplied or discovered core without that capability fails the native switch fixture after isolated home initialization; it does not skip or use an older switch path.

The depot gate and model-switch evidence runs require a compatible core, currently yardr local 6febd1a650fc1930c385ceda3198edfb6273fc91 or later:

TGBRIDGE_TEST_YARDR=/absolute/path/to/yardr nice -n10 sh scripts/test.sh -v

The path must name an executable build with crew_handoff_switch v1 and per-ask tell keys (notify.key). Check the verbose results show every NativeSwitchTests and native ask-tell case ran rather than skipped. These cases use an isolated core server/store, SQLite and fake Telegram through production polling; they do not use a live yard or account. Public CI without that core does not supply the required native feature evidence.

Native cards and review bundles

Native run cards bind the proposed command to its ask and bead. For a weighty change, tap Approve, then Confirm on the same card within 60 seconds. The confirmation names the ask, bead, command and time window.

View the synthetic Approve and Confirm card sequence.

Synthetic offline HTML capture: unarmed Approve, armed Confirm, expired and cancelled cards. These are test fixtures, not a live Telegram chat.

A review bundle arrives as one document with the complete proposal, files and diffs, followed by one compact approval card bound to it.

Native general cards also use run_ask and /decide. The complete document shows each verbatim argv word as an escaped JSON string with rune and UTF-8 byte counts, even when native prose shortens a long word. These commands are unchecked: file operands are not captured or stale-bound, no rollback is shown, and output goes to the asker. Approval requires Approve then Confirm within 60 seconds; the core separately enforces its one-hour expiry. Only the native local-time expiry sentence is public. See general-card operation and recovery. This works on unmodified public 5dc0bfca and 52e22d57; it does not add commands absent from those cores or make v0.17.0 an installable release.

View the synthetic review document and compact approval card.

Synthetic offline HTML capture: one review document and its approval card, using fictional data. Open the image at full size to read the details; this is not a live Telegram chat.

When a harness stops on an error and the core files a nudge card for it (asked by yard), the bridge sends that card to the paired chat without the yardmaster: Approve asks the daemon to type one line into the stuck agent, and the outcome comes back as a reply on the card. A core without that feature files no card, and none is sent. See the yard's nudge cards.

The operator can also nudge with their own words: /nudge <target> [words], or a reply with words to a nudge card, opens a confirm card, and the tap calls core NudgeSession once, with the outcome relayed on the card. Typed-only, never in the menu; a core without the method answers not-supported. See nudging with your own words.

Prerequisites

This is public source for review. The setup steps below require a compatible public core release; v0.17.0 rejects the shipped declaration, including for hook/chat-only setup. Basic adoption on public 52e22d57 is proved in isolation against an earlier pack, before the shipped notify.key mapping. See the public-core gate and capability table for the outstanding contracts and required passing check.

  • Linux with a systemd user session (systemctl --user status). macOS has a launchd renderer (bridge/OPERATIONS.md, "Install and launch"), untested with yardr.
  • Python 3.11 or later (python3 --version), and curl.
  • yardr with source packs, hook verification, thread commands, explicit thread.formats declarations, per-ask tell keys (notify.key) and the yard running (yardr --version); configure a loopback hook listener (yardr settings get hook_addr). Native cards and Markdown need the additional capabilities listed in the compatibility table. Hook-only settings still require a core that accepts the whole pack, notify.key included. A version number alone does not establish those capabilities.
  • The yard-local skill setup, yardr skill add and crew/group skills= are fork-only; skip that section and its skill upgrade/rollback steps on public core. The bridge carries no specific captured skill add card: the fork's skill core lets the operator, users and crew add skills directly. Its optional skill removal and assignment cards are fork-only too; public core reports them unavailable. Basic SETUP steps 1–11 omit native home/operator and native-card grants.
  • Optional native repository edit proposals (depot edit) require a core serving RepoEditCapabilities (v1 capture-only or v2 materialized flow/review/merge-local landing with NativeEditStatus). They are fork-only until upstream accepts those core contracts and an operator installs/activates them; public cores without RepoEditCapabilities refuse repo-edit cards locally without affecting any existing native cards.
  • Optional native cards require the per-build contracts in the capability table. Public 52e22d57 supports the tested group fields (not group-set model=), new source-add and fresh embedded/directory source-pack cards. Source/pack replacements without explicit kept-grants disclosure refuse before send. Review documents contain native carried files and full diffs; no manifest/setup snapshot is invented. Weighty cards require Approve then Confirm on the same card within 60 seconds; typed numbers never approve. See source pack review.
  • Native depot-directory packs require an explicit depot, matching SHA-256 pin, complete input-free plan and recorded native global event watermark. Their document includes every object/change, mapping, file and full diff. Pre-activation, closed and missing-creation-event asks refuse; create a fresh ask after activation. Embedded/bare/URL depot forms, summary and overwrite cards remain unsupported. Limits are 40 Does lines, 256 KiB declarations, 64 KiB aggregate carried/ depot file text and diffs/removals, and a 50 MiB framed document; existing source per-file bounds remain. No review is truncated. See depot bundles and activation.
  • For transcription also git, cmake, make or ninja, a C++ compiler, ffmpeg, sha256sum, and network access to clone whisper.cpp and download the models (transcriber/setup.sh --settings <file>; about 600 MB).

Specific native run cards exclude unsupported depot forms and summary plans, crew add, depot push, the removed specific skill add payload, secret/setup/identity operations and parameter input; use the full native client for those.

Adopt in a yard

yardr/SETUP.md walks one yard through it: the bot, the settings, the install, the yard's hook listener, the pack and its credential, the hook, who writes, who answers, the start, and telling.

To read the ids for the settings before the bridge's first start, without the token in argv or history:

python3 - ~/.config/<yard>-telegram/telegram-bot-token <<'EOF'
import json, sys, urllib.request
token = open(sys.argv[1]).read().strip()
for method in ('getMe', 'getUpdates'):
    with urllib.request.urlopen(f'https://api.telegram.org/bot{token}/{method}', timeout=20) as answer:
        print(method, json.dumps(json.load(answer)['result'], indent=1))
EOF

getMe's id goes to [bot] bot_id, its username to [bot] account_id. In the /start update, message.from.id goes to [bot] user_id, message.chat.id to [bot] chat_id (equal to user_id), and update_id to pairing_update_id.

Each yard's bridge is its own instance: install.sh --settings <file> copies the checkout's committed HEAD (it refuses tracked changes) to <root>/releases/<commit> and points <root>/current at it, with the root ~/.local/share/yardr-telegram/<unit stem> unless --root names another. The unit runs <root>/current/bridge/bridge.py, and <root>/bin/telegram-bridge and <root>/bin/voice-transcribe run the same copy with the settings' python, so the checkout can change, move or go without touching a running yard, and updating, rolling back (install.sh --rollback) or removing one instance changes no other. A release's own Python dependencies, when it has any, are committed under vendor/. Why and how: docs/design/independent-instances.md; moving a bridge whose unit still runs a checkout: yardr/SETUP.md, "Move an existing bridge to its own installation". To move a bot from an existing bridge, disable and stop the old instance first, so it cannot return at login or reboot (two pollers on one bot conflict):

  • Linux and WSL 2: systemctl --user disable --now <old unit>.
  • macOS: launchctl bootout gui/$(id -u)/<old label>, then move ~/Library/LaunchAgents/<old label>.plist out of ~/Library/LaunchAgents and keep it with the retained old installation.

Keep the old settings and installation for rollback. Point state_dir at a copy of its state directory, so the ledger, the offset, the pins and the topics carry over. A new settings path needs a fresh unit and root; install it, then run the printed next: line to enable and start only the new instance. To roll back, disable and stop the new instance the same way (on macOS, also retain its plist outside ~/Library/LaunchAgents), then run systemctl --user enable --now <old unit>, or restore the old plist to ~/Library/LaunchAgents and run launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/<old label>.plist. The settings-move steps spell out both directions.

Uninstall

  1. (shell) systemctl --user disable --now <unit>, then rm ~/.config/systemd/user/<unit> && systemctl --user daemon-reload, then rm -rf <root> (~/.local/share/yardr-telegram/<unit stem> by default): its releases, launchers, packs and service.previous.
  2. (shell) Select this instance's yard home explicitly: yardr --home <this-yard-home> hook rm tgbridge, then yardr --home <this-yard-home> unsubscribe <crew> tgbridge for each subscribed crew member, then yardr --home <this-yard-home> source rm tgbridge.
  3. (shell, optional) Delete the settings file, the token, both secrets and the state directory. That directory holds the ledger and the message log, so keep a private copy if the bridge may return.
  4. (shell) Keep the host's shared pieces while another bridge runs: the queue ~/.local/state/voice-transcribe and the whisper.cpp build and models. ~/.local/bin/voice-transcribe is yours: an install never creates, changes or removes it.
  5. (you, optional) Delete the bot with BotFather.

Skills

The skills are the shared base set, written for any yard and any bot, naming no yard, person or product. On the aligned fork, the operator copies them from its installed release with yardr skill add into that yard's home. Public core lacks skill add and skills=; skip these steps, including skill refresh after upgrades/rollbacks. On the fork's skill core users and crew may add or refresh them too (dropped on November 12/13, restored since); removing one and giving the names to crew or groups stay the operator's, in a terminal or by approving a skill card. See the crew's skills for setup and refresh after an install or rollback. Harness skill folders such as ~/.claude/skills are shared by all yards on the host; keep instance-specific links out of them.

  • A yard adds its own skill in its own pack, never by editing these: for example its menu commands' meaning, who reads the chat, or its message house style. Its skill may point at these ones by name.
  • Promoting a skill into the shared set: when a yard's skill turns out to be true for every yard (a Telegram rule, not a habit of one yard or user), rewrite it without any yard, person, product or path of that yard, move it to skills/<name>/SKILL.md here with a citations table of the pack files it relies on in citations.md beside it (never in SKILL.md), and delete the yard's copy in the same change. Nothing here names a yard, person or company.

Add-ons

An add-on is one [[command]] table in a yard's bridge settings, with no enable flag. Its handler lives outside this repository: a program of your own, or one you install. Add one: install the handler at an absolute path (owner-writable only, executable, owned by this user or root, in a directory owned by this user or root and writable by neither group nor others), add the table (and a handler_write_paths entry if it writes), then run install.sh again and restart the service: on Linux and WSL 2 systemctl --user daemon-reload and restart the unit, on macOS launchctl bootout gui/$(id -u)/<label> 2>/dev/null; launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/<label>.plist, and run set-commands. Remove one: delete the table, delete the handler program if nothing else uses it, drop its handler_write_paths entry if no other handler writes there, run install.sh again, restart the service the same way, then run set-commands. The menu loses the command only then. The handler protocol is in bridge/OPERATIONS.md, "Commands". With [yardr] cards = true (requiring home and operator), /decide and the decide: prefix are the bridge's own (native cards, YARDR.md). Exactly one instance per yard owns these cards; the shared lock_dir fences a second owner at startup. cards is required wherever home and operator are both set. With tell including asks, each new ask to the operator also arrives as a plain pointer ending Tap /decide to answer. (no buttons; /decide answers). Message states, /nudge, quota, model switching and mail do not require card ownership. Three ready add-ons are telegram-quota, which adds a /resets command that spends a Codex reset credit (/quota and /switch_model are native with [yardr.quota] and [yardr.switch_model], bridge/OPERATIONS.md, "Native yard commands"; /switch_model requires core crew_handoff_switch v1; /crew is native with [[yardr.switch_crews]] and switches any configured crew; the add-on keeps /resets), telegram-secret-drop, which adds a one-time form on the local network for handing a secret to an agent without it passing through the chat, and telegram-waiting, which adds a /waiting command that shows the list of what waits on the paired user.

Example

A partial file, with only the keys that differ from settings.example.toml:

yard = "example"
state_dir = "~/.local/state/example-telegram"
port = 8941
[yardr]
hook_url = "http://127.0.0.1:8795/hooks/tgbridge"
hook_secret_file = "~/.config/example-telegram/hook-secret"
[transcribe]
enabled = true
method = "auto"
[[topic]]
name = "homelab"
[[command]]
name = "deploy"
description = "Deploy a branch"
handler = "/absolute/path/to/telegram-deploy"

Explicit Markdown

Ordinary replies may select yardr reply <seq> --format markdown <text>; source/API sends and pins take format=markdown, and the bridge CLI takes --format markdown. Existing auto/plain/HTML defaults stay unchanged. The pinned parser ships offline in each release through the existing installer. See formatting policy and operator handoff.

Local public-readiness review

Public-readiness checks and release handoff covers portable setup, compatibility limits, a location-only committed-tree scan and a local export/manifest for review. It does not publish or rewrite history. Optional transcription downloads have separate third-party notices; the project's MIT LICENSE is unchanged.

About

Superseded by https://github.com/codejunkienick/yardr-tg (Go v2). Archived Python bridge.

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages