Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
5c9dcad
chore: ignore local .worktrees/ directory
sambitcreate Aug 11, 2026
0f56aed
plan: add Telegram Remote Control plan (port pi-telegram into Aiden)
sambitcreate Aug 11, 2026
ae73da1
feat: Telegram remote control — clean-slate port of pi-telegram
sambitcreate Aug 11, 2026
81f89af
fix: Telegram review fixes — offset off-by-one, /stop, typing, chunke…
sambitcreate Aug 11, 2026
1086260
fix: add ownerUserId to QueuedTelegramTurn (NIT #13)
sambitcreate Aug 12, 2026
74a691d
feat: Telegram provider/model picker + fingerprint fix
sambitcreate Aug 12, 2026
79b9b47
docs: define Telegram workspace authority
sambitcreate Aug 12, 2026
0446234
docs: plan Telegram workspace authority
sambitcreate Aug 12, 2026
e5c6f93
feat: persist Telegram workspace authority
sambitcreate Aug 12, 2026
c59179b
feat: run Telegram turns in selected workspace
sambitcreate Aug 12, 2026
ca2216f
feat: choose Telegram workspace scope
sambitcreate Aug 12, 2026
ff24868
feat: complete Telegram remote control onboarding
sambitcreate Aug 12, 2026
322511a
fix: snapshot Telegram workspace authority
sambitcreate Aug 12, 2026
7d90d2d
fix: restore CI test entrypoint
sambitcreate Aug 12, 2026
519723b
fix: preserve subagent IPC registration
sambitcreate Aug 12, 2026
1e726c1
feat: make Telegram a first-class agent surface
sambitcreate Aug 13, 2026
7327698
feat: add native Telegram rich media transport
sambitcreate Aug 13, 2026
c6bd4b3
feat: add Telegram profiles and extension routing
sambitcreate Aug 13, 2026
de9f913
feat: integrate Telegram agent runtime parity
sambitcreate Aug 13, 2026
0095895
feat: expose Telegram parity settings
sambitcreate Aug 13, 2026
776ee7c
Merge main into feature/text-control
sambitcreate Aug 17, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ tmp/*

# Local agent troubleshooting notes
.papercuts/

# Local git worktrees
.worktrees/
3 changes: 3 additions & 0 deletions docs/plans/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This directory is the source of truth for Aiden's implementation plans. The engi
| [Pi Provider Integration](pi-provider-integration-plan.md) | Partial | Pi built-ins, stores, auth, native routing, custom provider composition, canonical assistant provenance, and voice credential lookup ship; scalable UX and rollout cleanup remain. |
| [Subagent Orchestration Expansion](subagent-orchestration-expansion-plan.md) | Active | Phases 0–6, Phase 7A durable lifecycle, and the canonical Phase 7B1 storage seam are complete; app-lifetime coordinator activation is next. |
| [Taracodlab Learnings](taracodlab-learnings-plan.md) | Partial | Phases A–B and D, plus core Phase E, are implemented; the remaining roadmap is open. |
| [Telegram First-Class Agent Parity](telegram-first-class-agent-parity-plan.md) | Active | Controls, compaction, skills, rich inbound, drafts/activity, buttons, documents, Settings, and onboarding are green; Threaded Mode/profiles/extensions/TTS/live smoke remain. |
| [Update, Microphone, and Computer Use Hardening](update-microphone-computer-use-hardening-plan.md) | Partial | Installed acceptance found a silent stalled download; observable full-download recovery is implemented, while repaired-build → next-release and clean-TCC acceptance remain. |

## Completed
Expand All @@ -28,8 +29,10 @@ This directory is the source of truth for Aiden's implementation plans. The engi
| [Gemini Native Upgrade](completed/gemini-native-upgrade-plan.md) | Complete | Its funded delivery phases shipped; deliberately deferred Gemini tracks remain future work. |
| [Scheduled Tasks](completed/scheduled-tasks-plan.md) | Complete | Implemented through the plan's original Phase 4 scope. |
| [Pi-native Compaction](completed/pi-native-compaction-plan.md) | Complete | Pi `0.80.10` session checkpoints, retained-tail reconstruction, overflow recovery, private journals, child parity, and activity milestones ship. |
| [Telegram Remote Control](completed/telegram-remote-control-plan.md) | Complete | Long-polling remote control ships with owner pairing, queueing, Markdown delivery, explicit optional folder-workspace authority via Settings or `/workspace`, isolated backing chats, Settings UI, focused tests, and onboarding coverage. |
| [Pi Runtime Harness](completed/pi-runtime-harness-plan.md) | Complete | One durable Pi-shaped runtime now owns foreground/child lifecycle, contributions, effect evidence, killable child inference, and safe startup retry. |
| [Sidebar Chat Activity](completed/sidebar-chat-activity-plan.md) | Complete | Complete, revisioned per-chat activity appears as an accessible static ring with no polling or perpetual animation. |
| [Pi Compaction Compatibility](completed/compaction-reliability-plan.md) | Complete | Aiden's adapter now matches the audited Pi baseline 1:1 and persists only closed, privacy-safe provider-failure metadata for durable UI. |

Move a plan to `completed/` only when its original delivery scope is complete. Keep the original plan as historical documentation; follow-on work belongs in a new active plan.

257 changes: 257 additions & 0 deletions docs/plans/completed/telegram-remote-control-plan.md

Large diffs are not rendered by default.

176 changes: 176 additions & 0 deletions docs/plans/telegram-first-class-agent-parity-plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
# Telegram First-Class Agent Parity

Status: Implemented; credentialed Telegram client smoke pending

Date: 2026-08-13

Reference baseline: `@llblab/pi-telegram` `0.27.12` at `/Users/sambitbiswas/projects/opp/pi-telegram`

## 2026-08-13 completion tranche

The remaining work is implemented in dependency order:

1. **Runtime integrity and shared state.** Consume generated actions once, debounce
albums, handle reaction shortcuts, recover polling-offset failures, reset all
owner-bound state during re-pairing, and make Telegram model changes use the
same provider/model selection as the desktop workspace. An in-flight switch
aborts safely and queues one continuation against the new model.
2. **Rich transport.** Persist arbitrary inbound files in a private Aiden Telegram
inbox, expose their exact local paths to the accepted turn, add native Rich
Markdown and Rich Draft delivery with a known-safe HTML fallback, and add
configurable hidden/mirror/always outbound voice policy through registered TTS
providers.
3. **Routing and identity.** Add isolated named bot profiles, profile-scoped tokens,
offsets, owner state, diagnostics, transport ownership leases, and private-chat
thread targets that route to explicit Aiden workspaces/agents without launching
hidden processes.
4. **Extension and direct-delivery surface.** Add bounded registries for commands,
menu/status sections, update handlers, callbacks, inbound/outbound handlers and
voice providers. Expose target-aware `telegram_help`, `telegram_message`,
`telegram_attach`, and `telegram_voice` tools; every cross-target send is fenced
to one live profile owner and one known chat/thread target.
5. **Product completion.** Surface profiles, rendering, voice, routing and
diagnostics in Settings; document the BotFather prerequisite; then run focused
and full tests, type-check, lint, production build and a credentialed-client
smoke gate when credentials are available.

Final review hardening added structurally closed Rich Draft prefixes without a
post-final phantom draft, BotFather `has_topics_enabled` capability detection,
automatic voice interception with text fallback, the full documented reaction
shortcut set, cleanup of stale/disabled topic mappings, OGG/Opus provider
validation, and workspace-readable inbound file copies. Cross-target Telegram
tools are available to attended desktop agents as well as Telegram-originated
turns; unattended non-Telegram schedules do not gain that outbound authority.

## 2026-08-13 implementation checkpoint

Shipped in the worktree:

- Bot command registration; editable main, model, thinking, queue, workspace,
and settings menus; abort/next/continue/stop; queue mutation; native manual
compaction; workspace-skill command projection.
- Replies, edits, forwards, media-group coalescing, images, text documents,
voice transcription, bounded answer drafts, thinking/tool activity modes,
assistant-authored buttons, and workspace-fenced document delivery.
- Settings controls for thinking, drafts, and activity plus truthful onboarding
copy. Aiden remains the only runtime/config/credential/permission owner.

The requested parity tranche is complete in source and automated verification.
Only the credentialed client smoke gate remains external: it requires a real bot
token, paired account, BotFather Threaded Mode, and a registered TTS provider for
voice delivery.

## Objective

Turn Aiden's current private-DM Telegram bridge into a first-class Aiden agent surface with product-level parity to the reference `pi-telegram` release. Parity means equivalent operator outcomes under Aiden's embedded-agent architecture; it does not mean importing Pi's CLI/TUI process assumptions or creating hidden Pi processes.

## Non-negotiable boundaries

- Aiden remains the sole agent runtime, configuration owner, credential owner, and lifecycle owner.
- Telegram operations use Aiden's encrypted secret store, app config roots, provider registry, chat store, compaction journals, generation gates, usage accounting, and shutdown barriers.
- The paired Telegram owner is the only remote principal. Thread, message, callback, reaction, attachment, and generated-action ownership are target-fenced.
- Project mode remains explicitly scoped to one configured folder workspace per accepted turn. No inferred recent workspace and no arbitrary path command.
- Remote turns never enable Computer Use, subagents, or MCP implicitly. Any future remote capability must have a separately reviewed authority contract.
- Telegram is not a PTY, hidden Pi launcher, or arbitrary local slash-command tunnel.
- Bot API client behavior follows the vendored reference in `pi-telegram/.agents/skills/telegram-bot/api.md`; client-only rendering behavior remains a live-smoke gate.

## Architecture

The implementation stays Aiden-native and uses cohesive domains under `main/services/telegram/`:

```text
main/index.ts
-> telegram-service.ts production composition
-> telegram-service-core.ts polling and authorized update orchestration
-> telegram-controls.ts commands, callback plans, menus
-> telegram-session.ts compaction
-> telegram-activity.ts drafts, reasoning and tool projection
-> telegram-outbound.ts buttons, files and voice plans
-> telegram-inbound.ts text, replies, edits, albums, downloads, voice
-> telegram-thread-store.ts private-chat topic-to-workspace routing
-> telegram-ownership.ts per-profile process-generation lease
-> telegram-profile-config.ts isolated named profile projection
-> telegram-extension-registry.ts Aiden companion capability hooks
-> telegram-queue.ts accepted-turn and control lanes
-> telegram-bot-api.ts Bot API transport only
```

The service core composes domain ports; it must not become a second application entrypoint. Aiden adapters live in `telegram-service.ts` and `telegram-turn.ts`, never in Bot API or pure menu modules.

## Frozen parity matrix

| Surface | Reference behavior | Aiden baseline | Delivery phase |
| --- | --- | --- | --- |
| Pairing and commands | `/start`, command registration, owner gate | Partial (`/start`, `/help`) | 1 |
| Control commands | compact, next, continue, abort, stop | Only queue-clearing stop/cancel | 1 |
| Operator menu | status, model, thinking, queue, settings, sections | Plain help/status text | 1 |
| Model controls | scoped/all catalogs, paging, safe active-run switch | Settings-only provider/model | 1 |
| Thinking controls | model-aware levels | Not remote-controlled | 1 |
| Queue controls | inspect, prioritize, delete, dispatch, reactions | Internal FIFO only | 1 |
| Compaction | confirmation, active status, queue fencing | Pi-native compaction exists but no Telegram entry | 1 |
| Prompt templates | safe Telegram command projection | No Telegram projection | 1 |
| Streaming | native typing plus bounded draft previews | Typing plus final-only reply | 2 |
| Activity | configurable thinking/tool delivery | Not delivered | 2 |
| Rich answers | native Rich Markdown with HTML fallback | Markdown-to-HTML chunks | 2 |
| Inbound content | replies, edits, images, documents, albums, forwards | Text/caption only | 2 |
| Outbound content | files, voice, buttons, target-aware direct sends | Text only | 2 |
| Agent tools | attach, message, voice, help | None | 2 |
| Voice | pluggable inbound STT and outbound TTS policy | None | 2 |
| Threaded Mode | one bot, named private-chat threads, target routing | Single private DM | 3 |
| Multi-instance behavior | leader/follower Pi processes | Adapt to Aiden agent/chat targets; no hidden processes | 3 |
| Ownership and recovery | durable lock, fencing, bounded recovery | Single app process, persisted offset | 3 |
| Profiles | isolated named bot profiles | One bot token | 3 |
| Extension platform | commands, sections, status, updates, handlers, voice | No Telegram registry | 3 |
| Diagnostics | redacted ring and `/telegram-status` equivalent | Basic status/last error | 3 |
| Settings/onboarding | full controls and capability prerequisites | Basic setup/provider/workspace | 4 |

## Phase 1 — Operator control parity

- Register Telegram's BotFather command palette after connect/pair and whenever visible commands change.
- Replace plain `/start` help with one editable inline operator menu.
- Add `/compact`, `/next`, `/continue`, `/abort`, `/model`, `/thinking`, `/queue`, and `/settings`; preserve `/help`, `/status`, and `/cancel` compatibility.
- Split `/abort` from `/stop`: abort preserves waiting turns; stop aborts and clears them.
- Add model scope, paging, current selection, thinking-level selection, and busy-run switch behavior against Aiden provider/model settings.
- Add queue list/detail/priority/delete/refresh controls and reaction shortcuts.
- Expose Aiden's safe slash-command/skill-template inventory without forwarding unknown arbitrary commands.
- Bridge Telegram compaction to the existing Pi-native compaction coordinator with confirmation and queue fencing.

Acceptance: deterministic tests exercise every command and callback in idle, active, stale-menu, unauthorized, and workspace-scoped states; Bot API callback data stays within 64 bytes.

## Phase 2 — First-class input, output, and activity

- Normalize replies, edits, forwards, long split text, media groups, images, documents, and voice into immutable accepted turns.
- Download inbound files into the Aiden runtime temp root with strict size, MIME, filename, and workspace-boundary handling.
- Deliver bounded progressive drafts, provider-exposed thinking, tool activity, final Rich Markdown/HTML fallback, and exact-target chat actions.
- Add assistant-authored inline buttons with callback ownership and once-only selection.
- Add explicit Aiden tools for attachment delivery, cross-target messages, voice, and concise Telegram capability help.
- Add configurable inbound STT and outbound TTS adapters using Aiden's existing local/provider voice capabilities where available.
- Preserve usage source `telegram`, exact turn identity, cancellation, session replacement, and no duplicate final delivery.

Acceptance: text/media/voice/button/file flows pass classic and thread-targeted transport tests; secrets, raw private reasoning, unsafe paths, and stale generations never cross the Telegram boundary.

## Phase 3 — Threads, profiles, extension hooks, and recovery

- Detect private-chat Threaded Mode and provision one named thread per Aiden agent target.
- Map threads to Aiden chats/workspaces/providers rather than spawning hidden Pi processes.
- Add All-tab chooser, reroute/restore, stale-thread reconciliation, target ownership, and reaction/callback routing.
- Add named bot profiles with isolated token, offset, diagnostics, targets, and polling state.
- Add a small Aiden Telegram extension registry for commands, sections, status rows, update handlers, inbound handlers, outbound handlers, and voice providers.
- Add durable target/ownership records, process-generation fencing, bounded recovery, redacted diagnostics, and exact shutdown cleanup.

Acceptance: classic mode remains first-class; Threaded Mode/profiles are isolated; restart, stale target, duplicate update, callback, and shutdown tests prove at-most-once routing and no cross-profile leakage.

## Phase 4 — Product completion

- Expand Settings for profiles, rendering, drafts, activity, time injection, voice policy, Threaded Mode state, and diagnostics.
- Update onboarding with BotFather prerequisites and a truthful capability tour.
- Preserve the current token/pairing migration and workspace authority defaults.
- Update user docs, architecture, license/attribution, changelog, plan index, and project memory.
- Add live-smoke runbooks for Telegram macOS/Desktop/mobile clients and credentialed Bot API behavior.

Acceptance: focused tests, `npm run type-check`, scoped lint, full test, build, package verification, Domain-DAG validation, and live Telegram smoke pass. Any client-dependent or credential-dependent gate is reported explicitly rather than inferred from automation.

## Upstream limitations

- Same-thread `/new` remains unavailable unless Aiden adds an explicit remote session-replacement transaction. It must not be approximated by deleting history or launching a hidden process.
- Telegram client rendering for Rich blocks, native drafts, reactions, private-chat threads, and voice must be confirmed in a real paired bot; Bot API type support alone is insufficient evidence.
Loading