From 7a5976481d73d43fa0665ad0329bf814e5784a6b Mon Sep 17 00:00:00 2001 From: Aleksandr Razumov Date: Sat, 13 Jun 2026 00:03:02 +0300 Subject: [PATCH] feat: migrate CLI to cobra and add roadmap Replace urfave/cli/v2 with spf13/cobra for the command surface, giving first-class shell completion and doc generation: - Root command with persistent global flags, command groups, and flag-name normalization preserving old aliases (--staging/--target/--msg/--as). - init/send/upload ported to cobra with rich Short/Long/Example help. - Dynamic completion for --peer (self aliases for now) and enum completion for --type; enum flag reimplemented as a pflag.Value. - Hidden `docs` command generating Markdown/man pages from the tree. - Switch error handling from golang.org/x/xerrors to go-faster/errors (Wrap/Wrapf house style). Also add ROADMAP.md describing the agent-automatable CLI plan. Co-Authored-By: Claude Opus 4.8 --- ROADMAP.md | 238 +++++++++++++++++++++++++++++++++++++++++++ cmd/tg/app.go | 82 +++++++++------ cmd/tg/common.go | 64 ++++++------ cmd/tg/completion.go | 29 ++++++ cmd/tg/docs.go | 47 +++++++++ cmd/tg/enum_flag.go | 41 ++++---- cmd/tg/init.go | 94 ++++++++++------- cmd/tg/main.go | 76 +------------- cmd/tg/root.go | 82 +++++++++++++++ cmd/tg/send.go | 74 +++++++++----- cmd/tg/upload.go | 237 ++++++++++++++++++++++-------------------- go.mod | 9 +- go.sum | 13 +-- 13 files changed, 746 insertions(+), 340 deletions(-) create mode 100644 ROADMAP.md create mode 100644 cmd/tg/completion.go create mode 100644 cmd/tg/docs.go create mode 100644 cmd/tg/root.go diff --git a/ROADMAP.md b/ROADMAP.md new file mode 100644 index 0000000..d0bcc87 --- /dev/null +++ b/ROADMAP.md @@ -0,0 +1,238 @@ +# `tg` Roadmap — Agent-Automatable Telegram CLI + +## Vision + +Turn `tg` into a single static binary that an AI agent (or any script) can drive to +automate everyday Telegram work on a **personal account**: message yourself, list and +triage chats, mark chats as read, reply, upload/download files, search history, and more. + +The goal is a broad capability surface — and strong agent ergonomics — delivered as a +fast, dependency-free Go binary built on [`gotd/td`](https://github.com/gotd/td), exposed +as composable subcommands. New capability should land as `tg` subcommands. + +## The central gap: user-account auth + +`tg` today authenticates **only as a bot** (`Config.BotToken`, `client.Auth().Bot(...)`, +and `app.Before` hard-rejects a config without a bot token). Bots cannot: + +- access **Saved Messages** / "message yourself", +- list **dialogs** (`messages.getDialogs` is unavailable to bots), +- read arbitrary chat history or mark dialogs as read the way a user can, +- see the chat/folder list, contacts, or most account state. + +**Every automation use case in the request requires a user session.** So user login is +Phase 0 and gates everything else. `gotd/td` already supports this: `auth.NewFlow` with a +code-prompt + 2FA handler, and `qrlogin` for QR-based login. + +## Agent-first design principles + +These cut across every feature and matter as much as the features themselves: + +1. **Structured output.** Global `--output json|text` (default `text` for humans, but + agents pass `--output json`). Every command emits a stable, documented JSON object on + stdout. No data on stderr; logs/progress go to stderr only. +2. **Non-interactive by default.** Never block on a TTY prompt in agent mode. Auth codes, + confirmations, and 2FA come from flags / env / a pre-established session. +3. **Stable exit codes.** `0` success, distinct non-zero codes for auth failure, peer not + found, flood-wait exceeded, permission denied — so agents can branch on them. +4. **No decorative output in machine mode.** The upload progress bar and typing-action + updates must be suppressed under `--output json`. +5. **Consistent peer resolution.** One shared `--peer` grammar everywhere: `me`/`self`, + `@username`, numeric ID, phone, `t.me/...` link. Cache resolved access-hashes in the + session dir (StringSession-style sessions have no entity cache — we must keep our own). +6. **Idempotency & safety.** Destructive actions (delete history, leave, ban, delete + account-level state) require `--yes` in agent mode and are clearly marked read-only vs + mutating. +7. **Schema versioning.** Include `"schema": 1` (or similar) in JSON so agents can adapt. +8. **Account selection.** Every command accepts a global `--account