zot/internal/agent
patriceckhart 098a79743d feat(tui): /telegram connect | disconnect | status
The Telegram bridge can now mirror into the running TUI session.
Runs inside the zot process (no daemon needed); DMs from the
paired user become prompts in the current agent, and the
assistant's final text is sent back to Telegram. You see the full
conversation in the TUI in real time and on your phone.

UI:
  - /telegram or /tg with no arg opens a picker (connect /
    disconnect / status) that reflects current state.
  - /telegram connect  starts the bridge. Refuses if bot.json
    has no token (tells you to run `zot telegram-bot setup`) or
    if the background daemon is already polling.
  - /telegram disconnect  stops the bridge cleanly.
  - /telegram status  one-liner: "connected as @botname, paired
    with user X" / "background daemon running (pid N)" /
    "not configured" / "disconnected".
  - Status bar gets a "· tg · ~/cwd" tag while the bridge is
    active, next to the "· jailed ·" tag if that's also on.

How it's wired:

  internal/agent/modes/telegram/bridge.go (new)
    A slim Bridge type that owns the long-poll loop + typing
    indicator + reply sender but delegates the agent side to a
    Host interface. Not an agent itself - just a courier that
    pushes inbound DMs at a host and relays outbound text.

  internal/agent/modes/telegram_dialog.go (new)
    Picker with connect / disconnect / status rows. Shape
    mirrors the logout dialog: arrow keys, enter, esc.

  internal/agent/modes/interactive.go
    - New SubmitOrQueue(text, images) that runs if idle or
      queues if busy. Telegram Host calls this so DMs use the
      same queuing semantics as the user's editor submit.
    - New CancelTurn() for when Telegram sends /stop.
    - telegramHost adapter wires the Interactive to the
      bridge without a cyclic import (bridge lives in
      modes/telegram, interactive in modes; the adapter is
      in modes so it's fine).
    - EvAssistantMessage handler now also forwards the final
      visible text to the bridge when active (goroutine, so
      the network call doesn't hold the event-loop lock).
    - Bridge is stopped on zot exit via a defer in Run().

  internal/tui/view.go
    StatusBarParams gains Telegram bool; the cwd line builds a
    composite "· jailed · tg · ~/cwd" when both tags apply.

  internal/agent/modes/slash_suggest.go
    /telegram added to the slash catalog.

Collision safety:
  /telegram connect refuses when the background daemon
  (telegram.IsRunning via bot.pid) is alive. Two concurrent
  long-poll consumers of the same bot always race and one
  drops half the updates; refusing up-front beats half-working
  silently. Message tells the user exactly what to do.

Attachments:
  Image attachments arriving in Telegram are downloaded and
  queued as user-prompt images (same code path as drag-drop).
  Non-image attachments are ignored for now.

Pairing:
  First Telegram user to DM /start claims the bridge; the id
  is persisted to bot.json so subsequent connects are already
  paired. Anyone else DMing the bot gets "this bot is paired
  with a different user."

README: /telegram row added to the slash-commands table.
2026-04-20 09:18:04 +02:00
..
extensions feat(ext): phase 4 - full-event interception, arg rewrites, /reload-ext 2026-04-19 17:02:04 +02:00
modes feat(tui): /telegram connect | disconnect | status 2026-04-20 09:18:04 +02:00
tools feat(tui,bash): shell-log style bash results 2026-04-20 09:03:24 +02:00
args.go fix(no-yolo): don't auto-refuse tool calls in non-interactive modes 2026-04-19 19:17:05 +02:00
botcmd.go fix ci on windows: split detach helper into posix/windows variants 2026-04-18 10:58:10 +02:00
botcmd_unix.go fix ci on windows: split detach helper into posix/windows variants 2026-04-18 10:58:10 +02:00
botcmd_windows.go fix ci on windows: split detach helper into posix/windows variants 2026-04-18 10:58:10 +02:00
build.go rename: /lock -> /jail, /unlock -> /unjail 2026-04-20 08:57:40 +02:00
changelog.go feat(tui): show github release notes once after upgrading 2026-04-19 16:12:13 +02:00
cli.go fix(cli): load extensions in print and json modes too 2026-04-19 20:00:36 +02:00
config.go feat(tui): show github release notes once after upgrading 2026-04-19 16:12:13 +02:00
extcmd.go feat: extension system (subprocess + json-rpc, any language) 2026-04-19 14:09:43 +02:00
modelsync.go initial commit 2026-04-17 20:36:38 +02:00
rpc.go fix(no-yolo): don't auto-refuse tool calls in non-interactive modes 2026-04-19 19:17:05 +02:00
systemprompt.go feat(auth,tui): dark login pages + /logout picker 2026-04-19 20:14:22 +02:00
update.go tui: show 'update available' banner at top of chat 2026-04-18 11:49:22 +02:00