agents-over-telegram 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +141 -0
  3. package/docs/BOT_EXCHANGES.md +121 -0
  4. package/docs/COMPATIBILITY.md +110 -0
  5. package/docs/DIRECT_DISPATCH.md +155 -0
  6. package/docs/HOSTS.md +244 -0
  7. package/docs/IMPLEMENTATION_STATUS.md +205 -0
  8. package/docs/LIVE_VALIDATION.md +35 -0
  9. package/docs/MACOS_SERVICE.md +89 -0
  10. package/docs/OPERATIONS.md +568 -0
  11. package/docs/REACTIONS.md +51 -0
  12. package/docs/RELAY.md +115 -0
  13. package/docs/RELEASING.md +45 -0
  14. package/docs/schemas/mcp.schema.json +120 -0
  15. package/docs/schemas/sources.json +9 -0
  16. package/integrations/pi/agents-over-telegram.ts +154 -0
  17. package/package.json +41 -0
  18. package/pyproject.toml +37 -0
  19. package/requirements/build.txt +18 -0
  20. package/requirements/runtime.txt +532 -0
  21. package/scripts/bootstrap_runtime.py +402 -0
  22. package/skills/telegram-coordinate/SKILL.md +67 -0
  23. package/skills/telegram-setup/SKILL.md +81 -0
  24. package/src/agents_over_telegram/__init__.py +2 -0
  25. package/src/agents_over_telegram/__main__.py +2 -0
  26. package/src/agents_over_telegram/appserver_client.py +400 -0
  27. package/src/agents_over_telegram/cli.py +851 -0
  28. package/src/agents_over_telegram/codex_trust.py +206 -0
  29. package/src/agents_over_telegram/compat.py +207 -0
  30. package/src/agents_over_telegram/core.py +4253 -0
  31. package/src/agents_over_telegram/credentials.py +108 -0
  32. package/src/agents_over_telegram/demo.py +85 -0
  33. package/src/agents_over_telegram/desktop_bridge.py +537 -0
  34. package/src/agents_over_telegram/desktop_dispatcher.py +680 -0
  35. package/src/agents_over_telegram/dispatcher.py +260 -0
  36. package/src/agents_over_telegram/host_config.py +125 -0
  37. package/src/agents_over_telegram/hosts.py +590 -0
  38. package/src/agents_over_telegram/judge.py +230 -0
  39. package/src/agents_over_telegram/macos_process.py +133 -0
  40. package/src/agents_over_telegram/markdown.py +127 -0
  41. package/src/agents_over_telegram/mcp_server.py +652 -0
  42. package/src/agents_over_telegram/net.py +130 -0
  43. package/src/agents_over_telegram/onboarding.py +719 -0
  44. package/src/agents_over_telegram/push.py +421 -0
  45. package/src/agents_over_telegram/relay.py +380 -0
  46. package/src/agents_over_telegram/relay_api.py +591 -0
  47. package/src/agents_over_telegram/relay_watch.py +171 -0
  48. package/src/agents_over_telegram/serve.py +626 -0
  49. package/src/agents_over_telegram/settings_panel.py +216 -0
  50. package/src/agents_over_telegram/transport.py +720 -0
  51. package/src/agents_over_telegram/webhook.py +219 -0
  52. package/uv.lock +1011 -0
@@ -0,0 +1,155 @@
1
+ # Listen with the normally opened desktop
2
+
3
+ Open ChatGPT from the app list as usual. The optional `relay-desktop` listener can wake an explicitly mapped **existing local Codex chat** through the installed native Codex queue and the app's wake URL. It needs no relay model, special desktop launch command, wrapper, replacement backend or WebSocket endpoint.
4
+
5
+ This route supports Linux and macOS. It checks the installed Codex queue capabilities instead of requiring one exact version string. The recorded live test used bundled Codex **0.163.0-alpha.10.2**; other capable builds remain eligible but have not been live-validated here. The live `relay-desktop` test passed on the normally launched desktop: marker `normal-idle-1` triggered collection, native queueing and automatic wake of the existing local Alpha chat, followed by one native poll, one reply and acknowledgment after the publication was recorded as sent. Alpha returned to zero pending messages. No model forwarded the wake after the Telegram marker arrived. Native tool and ledger evidence confirm this round trip; the user also confirmed the reply is visible in Telegram. See the [recorded result](COMPATIBILITY.md#normal-launch-local-desktop-boundary) for message/turn receipts and validation scope.
6
+
7
+ ```text
8
+ Telegram → shared collector → durable inbox → relay-desktop
9
+ → native Codex queue → desktop wake URL → existing local chat
10
+ → scoped poll / handle / reply / acknowledge
11
+ ```
12
+
13
+ Setup, status and resume do not start listening. Listening is an explicit process with a chosen duration; setup does not install a service or autostart entry. ChatGPT retains its normal startup, backend, tools and approval handling.
14
+
15
+ ## Select the target
16
+
17
+ Reuse the [binding procedure](RELAY.md#select-the-target): resolve the human-authorized local chat to its exact Codex thread UUID, verify its exact project directory and scoped Telegram tools, and bind the existing client to it. The project must contain the matching private profile and native Telegram MCP configuration. A Telegram message cannot select or change this mapping.
18
+
19
+ These examples use the installed `aot` executable, the account's existing canonical state root, the selected private client file and the exact project directory:
20
+
21
+ ```sh
22
+ "$AOT_BIN" --state-dir "$AOT_STATE" relay-bind \
23
+ --client-file "$AOT_CLIENT" \
24
+ --thread-id TARGET_THREAD_UUID \
25
+ --project-dir "$AOT_PROJECT"
26
+
27
+ "$AOT_BIN" --state-dir "$AOT_STATE" relay-status --client-file "$AOT_CLIENT"
28
+ ```
29
+
30
+ Initial binding excludes existing pending work from wake notifications while leaving it available for normal polling. Use `--include-pending` only when the human wants that backlog handled. Repeating the same binding does not replay work. Do not print client capabilities or bot tokens while verifying the configuration.
31
+
32
+ The listener uses the existing notification ledger and singleton lock. Run only one of `relay-desktop`, `relay-dispatch` or `relay-watch` for a state root at a time. It checks the local target and matching project configuration before submitting; mismatches preserve the inbox and block notification.
33
+
34
+ ## Run a bounded listener
35
+
36
+ Keep ChatGPT open normally and run:
37
+
38
+ ```sh
39
+ "$AOT_BIN" --state-dir "$AOT_STATE" relay-desktop \
40
+ --duration 55 --collect
41
+ ```
42
+
43
+ On Linux the native binary defaults to `/usr/lib/chatgpt/resources/codex`. On macOS it is discovered inside `/Applications/ChatGPT.app`, `/Applications/Codex.app`, or the corresponding user Applications directory: either `Contents/Resources/codex-cli/CodexCLI.app/Contents/MacOS/codex` or `Contents/Resources/codex`. `--codex-binary` selects an explicit installed bundled binary; a standalone PATH CLI or wrapper is not accepted as the backend. `--codex-home` defaults to the current `CODEX_HOME` or `~/.codex` and must identify the same native home used by the desktop. Do not point it at a copied home or a second backend. Before submitting, the adapter runs the read-only `codex queue --help` check and requires `--thread` and `--message`. A new version string alone does not block the listener. Process ownership, the expected local data layout and exact target/project checks remain required; CLI help support does not establish complete desktop wake behavior on an untested build.
44
+
45
+ `--collect` opts into intake through the existing shared collector, lock and durable cursor. Without it, the listener watches only already-captured local inbox work. Neither mode leases or acknowledges deliveries, flushes the outbox or sends Telegram replies. The target handles its own inbox with its scoped tools under the existing communication authorization.
46
+
47
+ Honor the user's requested lifecycle. “Leave it running,” “always listen,” and “restart after login” request continuous operation: use `--duration 0`. Use one 55-second check only when no ongoing lifecycle or duration was requested. A requested macOS login service is documented in [continuous listening](MACOS_SERVICE.md). A running listener waits without periodic model turns; a completed listener is no longer monitoring. Stop it with Ctrl-C or a termination signal. Stopping cannot cancel work already queued or a turn already accepted by the desktop.
48
+
49
+ The listener verifies that the desktop is running before queueing and before opening its wake URL. It waits when the app is absent rather than deliberately cold-starting it. This check and the operating-system URL opener are not atomic: if the app exits between them, the OS may launch it normally. No launcher environment or desktop configuration is changed.
50
+
51
+ ### macOS process and URL checks
52
+
53
+ The outer app must identify itself as `com.openai.codex` in a protected `Info.plist`. The adapter requires trusted executable ownership/modes, one same-user app process and its direct native `app-server` child, the matching Codex home, and no external/daemon routing overrides. Darwin `libproc` supplies executable paths, parent IDs, owners and microsecond start identities; `sysctl(KERN_PROCARGS2)` supplies argv and selected routing fields only for matching app/CLI processes. Other environment fields are discarded and never logged. Inspection denial, incomplete inventory, missing processes and ambiguous backends fail closed. No Accessibility or Automation permission is needed.
54
+
55
+ The wake uses `/usr/bin/open -a <validated app bundle> codex://threads/wake/<UUID>`, pinning the app rather than relying on the default scheme handler. It retains the existing final running-process guard and the documented app-exit/opener race. Neither process discovery nor queue acceptance proves the model has handled a delivery. See [macOS validation](COMPATIBILITY.md#macos-native-queue-validation) for the measured boundary.
56
+
57
+ ## Busy sessions and hooks
58
+
59
+ `codex queue` is a queue, not a promise of mid-turn steering. In the macOS live check, an accepted notice stayed queued while the target continued using tools. The desktop exposed a manual “Steer” action. Clicking it can unblock that notice, but does not validate automatic busy-session delivery.
60
+
61
+ Since version 0.8.0 the Codex plugin ships these hooks itself (`codex/hooks.json`, referenced from `.codex-plugin/plugin.json`). In 0.8.0 itself Codex did not load them, because of a root `plugin.json`; see [agent hosts](HOSTS.md#codex). They add a fixed notice at `SessionStart`, `UserPromptSubmit`, `PostToolUse` and `Stop`. The plugin's native queue remains the idle wake path. A hook does not interrupt an in-flight model request or a long-running tool. See [agent hosts](HOSTS.md#codex) for setup.
62
+
63
+ The shipped hooks follow the rules learned from the earlier operator-installed hook:
64
+
65
+ - They act only for the exact project folder from the hook input (`cwd`) and its existing connection. They respect pause, suspension and active delivery leases.
66
+ - They inject a fixed notice, never Telegram text. They never send, lease or acknowledge.
67
+ - They announce each delivery once, shared with every other push surface, and stay quiet after Telegram tool calls. A `Stop` hook continues a turn at most once in a row.
68
+ - They collect from Telegram at most every 10 seconds, because Codex has no background monitor. The shared collector lock prevents competition with a running `relay-desktop --collect`. The earlier operator hook did not collect; it relied on the listener for intake.
69
+ - They run through `scripts/aot_host_launch.py`, which only reads the project's `.aot-runtime.json` and then starts the prepared runtime. The runtime, not the system `python3`, reads the SQLite state. (An Apple Python 3.9 failed to read the live SQLite database in an earlier check.)
70
+ - The human reviews and trusts the hook definitions, in the Codex desktop app's hook review or with `/hooks` in the Codex CLI. Codex asks again after every plugin update. Do not edit trust hashes or bypass hook trust.
71
+
72
+ The earlier local macOS workaround passed a new Telegram test during an active work turn: one reply, one acknowledgment, zero pending messages, and 24.603 seconds from intake to sent receipt. That evidence applies to the operator-installed hook. The shipped hooks were tested offline against Codex's documented hook input and output, but not yet in a live Codex run; see [what was tested](HOSTS.md#what-was-tested) and the [evidence boundary](COMPATIBILITY.md#macos-follow-up-idle-and-busy-tests).
73
+
74
+ [Official Codex hook documentation](https://learn.chatgpt.com/docs/hooks) defines hook trust, `PostToolUse` output, and supported tool boundaries.
75
+
76
+ ## Notice and recovery semantics
77
+
78
+ The adapter enqueues a fixed, trusted local notice using native `codex queue`, then opens `codex://threads/wake/THREAD_UUID` through the operating system. The native queue delivers this notice with **user-message provenance**. It is not a tool-output event. The notice contains no Telegram body, sender-supplied instructions, token or client capability; actual Telegram content is retrieved separately through the scoped inbox and remains untrusted external input.
79
+
80
+ The adapter saves its handoff phase before invoking the queue command and saves the returned queue ID before requesting the wake. A known queue ID allows a later attempt to retry **only the wake URL**, without enqueueing another notice. A queue timeout, malformed response, failed command or crash can leave an ambiguous enqueue outcome; such work is held for inspection and is never blindly enqueued again.
81
+
82
+ Inspect `relay-status` and the exact target chat when a handoff is uncertain. A notification marked `accepted` means the native queue returned success and the OS opener accepted the wake URL. It does not mean that the model completed or handled Telegram work. Native queue acceptance, a successful OS opener exit, a completed model turn, an acknowledged inbox delivery and a sent Telegram publication are different pieces of evidence. An opener exit alone does not prove the chat handled the notice. Do not resolve an uncertain enqueue as failed simply because there is no Telegram reply. Reconcile against the saved queue receipt and actual chat history before deliberately retrying or cancelling.
83
+
84
+ The target retains its model, project, permissions and native tools. The listener does not answer approvals, tool requests or authentication prompts on the target's behalf. Accepted notices are not repeated merely because inbox messages remain pending. A pause can race with an already queued notice; if that leaves pending work after resume, inspect scoped status and explicitly poll rather than duplicating the notice.
85
+
86
+ To retire a resolved mapping:
87
+
88
+ ```sh
89
+ "$AOT_BIN" --state-dir "$AOT_STATE" relay-unbind --client-file "$AOT_CLIENT"
90
+ ```
91
+
92
+ Unbinding stops new notifications for that mapping; it does not revoke Telegram access, delete captured context or remove an already queued native notice. Resolve outstanding handoffs first.
93
+
94
+ ### A long-held unresolved wake blocks later wakes
95
+
96
+ With a wake interval set (`delivery-settings --wake-interval`; see [batched wake-ups](OPERATIONS.md#batched-wake-ups)), `relay-desktop` starts a new wake only after the interval since the client's last notice, unless an exempt message is waiting.
97
+
98
+ While the target chat is busy, `relay-desktop` does not queue a wake. A chat is busy when its latest turn in the desktop's `thread_history_1.sqlite` is `inProgress` and showed activity in the last 10 minutes. AOT's Codex hooks then deliver the notice inside that turn, and a queued wake would only start a second, redundant turn afterwards. The listener records the wake as `failed`, writes one `desktop_wake_deferred_busy` record, and tries again on its normal retry schedule, at most a minute apart. Once the chat is idle, the notice is queued as usual. An `inProgress` turn with no activity for 10 minutes counts as stale, for example one left open by a crash, and does not block wakes. If the desktop records cannot be read, the listener queues as before. This rule assumes AOT's Codex plugin hooks are installed and trusted; without them a busy chat gets the notice only after its turn ends, when the deferred wake is queued.
99
+
100
+ Each client has at most one outstanding notification. While a notification is `inflight` or `uncertain`, no new wake is sent for that client, even when new Telegram messages arrive. A wake that stays unresolved therefore blocks every later wake for that client.
101
+
102
+ The relay reports this condition, but it does not fix it. When an `inflight` or `uncertain` notification is older than 15 minutes:
103
+
104
+ - `relay-status` shows it in the binding's `unresolved_wake` field.
105
+ - The client's `connection_status` shows it in `unresolved_wake`, with the notification ID, its status, the time of its last change and its `next_action`. `status --human` prints a `Wake:` line.
106
+ - `relay-desktop` writes a `desktop_wake_stuck` record with `"level": "warning"`. It checks once a minute and repeats the warning for the same notification at most once an hour. The listener keeps this limit in memory, so a restarted listener warns once again.
107
+
108
+ The `next_action` code says who must act:
109
+
110
+ | Code | Meaning | Action |
111
+ | --- | --- | --- |
112
+ | `wait_for_desktop_wake` | The native queue returned a receipt (`handoff_phase` is `queued`), but the wake URL has not succeeded yet. This happens when the desktop stays closed or the connection is paused. | Nobody resolves it. A running `relay-desktop` retries only the wake URL while the desktop is open and the connection is active. Nothing else retries it, so if no listener runs, start one. A manual `accepted` or `cancelled` would stop those retries and leave the queued notice unopened. |
113
+ | `review_failing_wake` | The same queued handoff, but its wake URL has failed 10 times (`wake_attempts`) while the desktop was open and the connection was active. The target chat may be gone, or the OS opener may always fail. The listener keeps retrying. | A human checks the target chat and the wake URL. Opening the chat in the desktop app delivers the queued notice. Then record `accepted`, or `cancelled` to dismiss it. `relay-resolve` refuses `failed`, because the desktop queue already accepted the notice. |
114
+ | `review_uncertain_wake` | Any other `uncertain` notification, or an `inflight` one. `relay-watch --once` leaves a notification `inflight` until the relay chat records a receipt, and a listener that was killed leaves it `inflight` until the next listener starts. | A human checks the target chat history and any queue receipt, then records one outcome with `relay-resolve`. A running `relay-desktop` settles an unknown desktop enqueue by itself; see below. |
115
+
116
+ In `connection_status`, these codes come after `review_unknown_delivery` and `review_intake`, and after a paused or suspended state. The `unresolved_wake` field is present in every state. The agent-facing message only asks the agent to tell the local owner; it does not name relay commands.
117
+
118
+ The relay never expires an unresolved wake by itself. It settles one case on its own: a desktop enqueue whose `codex queue` child ended without a receipt (`handoff_phase` is `enqueuing`). Two minutes after the enqueue started, a running `relay-desktop` reads the desktop's own records, read-only:
119
+
120
+ | What the records show | Outcome |
121
+ | --- | --- |
122
+ | The wake notice still waits in `queue_1.sqlite` for that chat. | The listener keeps that queue ID and retries the wake URL, as for `wait_for_desktop_wake`. |
123
+ | The chat in `thread_history_1.sqlite` holds the notice as a user message. | `accepted`. |
124
+ | Neither database has it. | `failed`. The notice never landed, so the next pass enqueues it again. |
125
+ | Either database cannot be read. | Nothing changes. The listener writes `desktop_unknown_enqueue_unsettled`, and the warning above stays. |
126
+
127
+ Only a notice created after this wake's notification counts. The Telegram message that caused the wake was collected before that time, so a turn started by such a notice reads it. A notice from an earlier wake could have been read before the message arrived, so it never counts. If the desktop moves the notice from the queue into the chat between the two reads, the listener finds neither and enqueues the notice again. The agent then gets the same fixed notice twice, which does no harm. The check assumes that only `relay-desktop` writes this notice text into a desktop chat.
128
+
129
+ Each settled case writes a `desktop_unknown_enqueue_settled` record. A Codex app restart during an enqueue is the usual cause of this case.
130
+
131
+ Any other unresolved handoff can already have reached the target, so only a human can decide what happened. For `review_uncertain_wake`, record `accepted` if the notice arrived, `failed` if it definitely did not, or `cancelled` to dismiss it. All three keep the pending inbox work. After that, the next new message can wake the client again.
132
+
133
+ ## Live acceptance check
134
+
135
+ Use an authorized test target with its native Telegram tools loaded. Let it become idle, start the bounded listener, then send one unique Telegram marker to its configured destination. Confirm independently that:
136
+
137
+ - The listener selects the correct client, local UUID and exact project.
138
+ - The normally launched desktop starts that existing chat without a model forwarding the message.
139
+ - The target polls its own inbox, makes the authorized reply once and acknowledges only handled work.
140
+ - Queue/wake receipt, model completion, inbox acknowledgment and Telegram publication remain distinguishable.
141
+ - Repeated collection and a quiet interval produce no duplicate notice or reply; unrelated destinations stay isolated.
142
+
143
+ For busy-session handling, repeat with a fresh Telegram marker after independent status confirms the target is working. Record the active turn before and after intake, actual poll/reply/ack calls, and delivery latency. Do not send an inter-task reminder, press Steer, or end the work turn to make this check pass. If a hook is used, record that additional dependency and verify its execution separately.
144
+
145
+ For a persistent listener, also verify service startup, graceful-stop recovery, one collector, and retained inbox/notification state. Distinguish app restart, service restart, and OS reboot: testing one does not prove the others.
146
+
147
+ The `normal-idle-1` test passed the automatic collector → queue → local wake → poll/reply/ack flow on the existing Alpha UUID. The earlier status-only native wake probe also showed that opening the wake URL again with an empty queue produced no extra turn during the observed interval (`outputs/native-queue-live-probe.json`). These checks do not establish broader live pause/resume, busy-target, approval or app-shutdown behavior; those remain separate acceptance checks. The user confirmed the reply is visible in Telegram.
148
+
149
+ ## Earlier experimental adapters
150
+
151
+ `relay-dispatch` remains an experimental option for an explicitly shared app-server endpoint. It submits a fixed **tool-output** notice, unlike the normal-launch native queue route above. Its endpoint must be the same backend that owns the desktop chat; never start a second runtime over live saved history as a substitute. It accepts a protected local Unix WebSocket or an authenticated literal-loopback WebSocket. The dispatcher does not handle the owner's approval or dynamic-tool requests.
152
+
153
+ The optional `aot-codex-bridge` adapter and native local shared-backend launch helpers require a special desktop startup process. They are retained as test infrastructure and are not the recommended plugin setup or listening route. The bridge's manually launched dispatcher passed an earlier Telegram idle-wake/reply/ack check; the normal-launch listener has its own independent live test described above. The corrected bridge child-startup gate still lacks its final real-GUI restart check.
154
+
155
+ A separate native SSH fixture passed visible idle wakeup with a canned provider. It used a different remote chat and does not establish behavior for existing local chats. The native local restart fixture demonstrated same-UUID persistence and project MCP operation, but its special startup path had coordination MCP and Artifact Session compatibility gaps. These experiments are recorded in [compatibility](COMPATIBILITY.md) and the [implementation record](IMPLEMENTATION_STATUS.md); they are not required for normal-launch listening.
package/docs/HOSTS.md ADDED
@@ -0,0 +1,244 @@
1
+ # Agent hosts and push delivery
2
+
3
+ Agents over Telegram (AOT) works with five agent hosts: **Codex**, **Claude Code**, **Pi**, **Amp** and **Antigravity**, plus **Grok Bot**, which is untested. Each host uses its own plugin or extension system; Grok Bot has none and is woken through a webhook. In every host, a new Telegram message reaches the running agent without anyone typing a prompt. An idle agent wakes up. A busy agent gets the message at its next safe point, usually after the current tool call.
4
+
5
+ This page explains how each integration works, how to set it up, and what was tested. The [evidence section](#what-was-tested) says exactly which checks used a real agent host and which were only offline tests.
6
+
7
+ ## How push works
8
+
9
+ All hosts share the same parts:
10
+
11
+ - **The inbox and tools stay the same.** Each project has its own client file and inbox. The agent still reads messages with `messages_poll`, replies with `message_send` and confirms with `messages_ack`.
12
+ - **A notice, never the message.** The push is a fixed notice such as "1 new Telegram message for this agent. From: @alice (human)." It never contains the message text. The agent must poll to read the text, so leases, acknowledgements, pause and sender rules still apply.
13
+ - **One notice per message.** AOT records which deliveries were announced. A watcher and a hook never announce the same message twice.
14
+ - **Collection.** Something must fetch updates from Telegram. In Pi and Amp, a small watcher (`aot watch --collect`) runs while the host is open. In Claude Code, the same work is done by a background hook (`aot wake`) and, in interactive sessions, also by the monitor. It long-polls Telegram and announces new messages. In Codex, the hooks collect at most every 10 seconds, or the `relay-desktop` listener collects.
15
+ - **Per-project runtime.** Setup writes `.aot-runtime.json` next to `.aot-profile.json`. It names the prepared `aot` executable for that project and contains no secret. Host plugins read this file only in the exact project folder. They never search parent folders and never use an `aot` found on `PATH`.
16
+ - **Unrelated projects stay quiet.** In a folder without AOT setup, the plugins do nothing.
17
+ - **No orphan processes.** The watcher stops when the host process that started it exits, even after a forced kill.
18
+
19
+ | Host | Plugin type | Idle agent | Busy agent | Tools come from |
20
+ |---|---|---|---|---|
21
+ | Claude Code | Claude Code plugin (`.claude-plugin/`) | A background `asyncRewake` hook (`aot wake`) exits with status 2, and Claude Code wakes the session. In interactive sessions the plugin **monitor** also prints the notice | The monitor notice, or a `PostToolUse` hook, arrives after the current tool call; a `Stop` hook catches messages that arrive during the final answer | The plugin's MCP server |
22
+ | Codex | Codex plugin hooks (`codex/hooks.json`) | The existing `relay-desktop` listener wakes a desktop chat ([details](DIRECT_DISPATCH.md)) | `PostToolUse` and `Stop` hooks add the notice | `.codex/config.toml` written by setup |
23
+ | Pi | Pi extension (`integrations/pi/`) | The extension calls `pi.sendMessage(..., {triggerTurn: true})` and Pi starts a turn | Pi delivers the same message as a steering message after the current tool call | `.pi/mcp.json` written by setup |
24
+ | Amp | Amp plugin (`integrations/amp/`) | The plugin appends the notice to the current thread; it opens a thread if none exists | `appendUserMessage(..., {steer: true})` queues it as a steering message | `.amp/settings.json` written by setup |
25
+ | Antigravity (the `agy` CLI and the desktop app) | Project plugin written by setup (`.agents/plugins/agents-over-telegram/`) | The agent runs `aot wake --host antigravity` as a background command. When a message arrives, the command prints the notice and exits, and Antigravity wakes the agent with its output | A `PreInvocation` hook adds the notice before the next model call; a `Stop` hook catches messages that arrive during the final answer | The plugin's `mcp_config.json`, written by setup |
26
+ | Grok Bot (untested) | None: Grok Bot has no hooks | `aot watch --webhook-file` POSTs to a routine's webhook, which starts a run | The next routine run (at most one POST every 30 s) | A custom **Command** connector added in Grok Bot |
27
+
28
+ ## Set up a project
29
+
30
+ Install AOT once for the host (see [install](../README.md#install-aot-for-your-host-once)), then ask the agent to "Connect this agent to Telegram". The `telegram-setup` skill prepares the runtime and runs setup with the host you are in. Run by hand, setup looks like this:
31
+
32
+ ```sh
33
+ aot setup --label Alpha --project-dir /absolute/path/to/project --host claude --prepare-only
34
+ ```
35
+
36
+ `--host` accepts `codex` (the default), `claude`, `pi`, `amp` and `antigravity`. Setup always writes `.aot-profile.json` and `.aot-runtime.json`. It also writes the host's MCP configuration: `.codex/config.toml` for Codex, `.pi/mcp.json` for Pi, `.amp/settings.json` for Amp and a project plugin with the MCP server for Antigravity. Claude Code gets its MCP server from the plugin. Setup keeps unrelated settings. It refuses to replace another client's `telegram` entry, but it moves this project's own entry to the runtime that runs setup, for example after an update. You can run setup again with another `--host` to use the same project from a second host.
37
+
38
+ Setup adds the files AOT owns to the repository's local `.git/info/exclude`: `.aot-profile.json`, `.aot-runtime.json` and the Antigravity project plugin. They hold this machine's paths and the client id, not secrets, and other clones cannot use them. A shared settings file such as `.codex/config.toml` may hold the project's other settings, so setup does not exclude it. The result's `git` field lists what it excluded and warns when git already tracks one of these files.
39
+
40
+ ### Claude Code
41
+
42
+ 1. Add the marketplace and install the plugin for your user:
43
+
44
+ ```sh
45
+ claude plugin marketplace add fourlastor/agents-over-telegram
46
+ claude plugin install agents-over-telegram@agents-over-telegram --scope user
47
+ ```
48
+
49
+ User scope is the default because it lets every later session start with the plugin loaded, so a project can be connected without a restart (see below). It has a cost in projects that are not set up: each session runs the small launcher as an idle MCP server and as the monitor (each checks for setup every 2 seconds), each tool use and turn end starts a short `python3` hook that exits at once, and the session's instructions include the plugin's text that Telegram is not connected yet. To keep it out of other projects, install with `--scope local` inside the project folder instead; connecting a project then needs the one `/reload-plugins` described below.
50
+ 2. In the project folder, ask Claude Code to "connect this agent to Telegram", then "Telegram status".
51
+ 3. Keep the session open. The plugin collects Telegram updates for this project, so you do not need a separate listener.
52
+
53
+ **Connecting without a restart.** A project can be set up and paired while a session is open. Until setup writes `.aot-runtime.json`, the plugin's MCP server answers with no tools, and its instructions say that setup is pending. The launcher checks for the pointer every 2 seconds. Once it appears, the launcher starts the runtime and sends `notifications/tools/list_changed`, and the Telegram tools appear in the session. Hooks read the pointer on every event. The wake waiter starts at the next turn end. A monitor that started before setup begins watching within seconds.
54
+
55
+ This needs the plugin to be loaded in the session. When the plugin is installed or enabled during the session (for example on first use), the user types `/reload-plugins`, and nothing else:
56
+
57
+ - In the terminal CLI, `/reload-plugins --force` loads the hooks, skills and MCP server in place. Without `--force`, Claude Code may hold back the new MCP server to protect the prompt cache.
58
+ - In the desktop app, `/reload-plugins` loads the hooks and skills, but Claude Code connects a newly added plugin MCP server only in the next session. Until then the agent uses the same tools from a shell: `aot tool messages_poll`, `aot tool message_send` and `aot tool messages_ack`, run in the project folder with JSON arguments on stdin. They apply the same validation, scoping and untrusted-content envelope as the MCP server. Claude Code hook and monitor notices name the exact `aot` executable for this fallback. Unlike MCP tools, which can be allowed one by one, a Bash permission rule for `aot tool` allows every tool, including `connection_pause` and `connection_disconnect`; approve these commands one at a time if that matters to you.
59
+
60
+ **How an idle session wakes up.** The plugin starts `aot wake` as an `asyncRewake` hook when the session starts and each time a turn ends. Claude Code runs this hook in the background. The hook waits for a new delivery and collects from Telegram while it waits. When a message arrives, the hook writes the notice and exits with status 2. Claude Code then wakes the session, even when it is idle, and shows the notice to the model.
61
+
62
+ - One waiter runs per project client and Claude Code session. Each turn end starts a new waiter, which takes over from the running one when that waiter finishes its current check, usually within 30 seconds.
63
+ - The waiter stops when Claude Code exits. It also stops quietly 23 hours after the last turn end. A session that stays idle for longer than that stops waking up until someone sends it a prompt.
64
+ - With [keep-alive](OPERATIONS.md#keep-an-idle-claude-code-session-listening) on, the waiter instead wakes the session once when its 23 hours end. The notice says that there are no new messages and asks the model to end the turn. That turn end starts a new waiter. Only the session's current waiter does this, and only while Claude Code still runs. A waiter that handed over to a newer one, or whose host exited, stays quiet.
65
+ - Each waiter writes one line to `wake.log` in the state directory when it starts and when it exits, with the reason: `woken`, `keep_alive_refresh`, `replaced`, `host_gone`, `parent_changed`, `runtime_moved`, `watch_ended:<reason>`, `error:<type>` or `signal:<name>` (for `SIGTERM`, `SIGHUP` and `SIGINT`). A waiter killed with `SIGKILL` leaves a start line with no exit line. The file is private and holds no message text. Past 256 KB it moves to `wake.log.1`. Read it when a session stopped waking up.
66
+ - The launcher passes exit status 2 on only when the runtime printed a real notice. A runtime that predates `aot wake` fails with status 2 and a usage message, and that must not wake the session.
67
+
68
+ The plugin also declares a monitor that announces new messages. Claude Code starts plugin monitors only in **interactive** terminal sessions. They do not start in `-p` mode, and they did not start in the Claude Code desktop app. The `asyncRewake` hook does run in the desktop app.
69
+
70
+ The plugin needs `python3` 3.8 or newer on `PATH` to run the small launcher. The launcher only reads `.aot-runtime.json` and then starts the prepared runtime, which uses its own Python.
71
+
72
+ **The MCP server survives runtime changes.** Claude Code starts the plugin's MCP server once per session. The launcher stays running between Claude Code and the runtime's `aot mcp` process and passes messages through unchanged. It starts a new runtime process before the next tool call in two cases:
73
+
74
+ - `.aot-runtime.json` now names a different executable, for example after the project moved to an updated runtime.
75
+ - The runtime process stopped.
76
+
77
+ The launcher waits until no call is in flight. It replays Claude Code's own `initialize` and `notifications/initialized` messages to the new process, then sends `notifications/tools/list_changed`, so Claude Code refetches the tools. A call that was in flight when the process stopped gets an error answer instead of no answer. Hooks start a new process for every event, so they use the new runtime right away. The wake waiter and the monitor run for a long time, and they also collect from Telegram, so old code in them would route updates the old way for the whole bot. The launcher therefore starts them with `AOT_FOLLOW_RUNTIME=1`. At the end of each collection cycle they check `.aot-runtime.json`. When it names another runtime, they exit with status 3, and the launcher starts the same waiter or monitor again on the new runtime. A runtime older than this ignores the variable and keeps running until it exits by itself. A changed `hooks.json`, skill or monitor still needs `/reload-plugins` or a new session.
78
+
79
+ Claude Code also offers "channels" for chat bridges. Channels need an allowlisted plugin or the `--dangerously-load-development-channels` flag, and they do not work with `-p`. AOT uses hooks and a monitor instead, which need neither.
80
+
81
+ In `-p` (non-interactive) mode, Claude Code cancels background hooks when the run ends, so `aot wake` only covers the run itself.
82
+
83
+ ### Codex
84
+
85
+ The Codex plugin ships hooks for `SessionStart`, `UserPromptSubmit`, `PostToolUse` and `Stop`. Codex runs them only after you review and approve them, in whichever Codex you use: the desktop app's hook review, or `/hooks` in the Codex CLI in the project.
86
+
87
+ **Codex asks again after every plugin update.** Codex stores two hashes for each approved plugin hook in `~/.codex/config.toml`: `trusted_hash` for the hook definition and `trusted_content_hash` for the whole plugin folder. It runs the hook only while both still match. Every AOT release changes the plugin folder, so after each update Codex stops running the hooks until you approve them again. This was read in the Codex source (`codex-rs/hooks/src/engine/discovery.rs`, `plugin_trust.rs` and `plugin_fingerprint.rs`). AOT computes the folder hash the same way. For the installed 0.9.14 plugin it gave exactly the value Codex had stored.
88
+
89
+ - `aot codex-hooks` reports `approved`, `needs_approval` (with a reason), `not_installed` or `unknown`. It only reads files.
90
+ - When the MCP server runs for a project whose `.codex/config.toml` starts it with this client, and the hooks need approval, the server adds a warning to its instructions and a `host_warning` field to `messages_poll` results. The agent then asks you to approve the hooks again. The server checks its parent processes to see which Codex started it, and names the matching steps: the desktop app or `/hooks` in the CLI. If it cannot tell, it names both. A server started by another host, such as Claude Code in a project set up for both, shows no warning. The text is fixed by AOT.
91
+
92
+ **Version 0.8.0 shipped these hooks, but Codex did not load them.** The 0.8.0 package had two manifests: a root `plugin.json` in the Agent Plugins format and `.codex-plugin/plugin.json`. Codex uses the root `plugin.json` when it exists, and Codex loads no hooks for an Agent Plugins package. So Codex reported no plugin hooks and never asked to trust them. The package now has only `.codex-plugin/plugin.json`, and Codex loads the four hooks as plugin hooks. See [how this was checked](#how-the-codex-plugin-hooks-were-checked).
93
+
94
+ If you used 0.8.0 and copied `codex/hooks.json` into a project's `.codex/hooks.json` as a workaround, delete that project file after you update the plugin. Otherwise Codex runs the hooks twice and adds every notice twice.
95
+
96
+ The hooks use the project folder from Codex's hook input (`cwd`). They collect from Telegram at most every 10 seconds. If `relay-desktop --collect` is running, the hooks see its collector lock and do not compete with it. Idle desktop chats still need `relay-desktop`, as before ([listening](DIRECT_DISPATCH.md)).
97
+
98
+ Setup also approves four tools of the project's scoped `telegram` server in `.codex/config.toml`: `messages_poll`, `message_send`, `message_react` and `messages_ack`. Without this, Codex's automatic approval reviewer (`approvals_reviewer = "auto_review"`) rejected `messages_poll` in a live run. It judged the call as drift from the user's typed task, because the request came from a hook notice. The approval covers only these four tools of this project's server. That server can read only this project's inbox and send only to its bound topic, within the existing rate and exchange limits. Pause, disconnect and connection tools still follow your normal approval policy. If the config already has a `tools` table for `telegram`, setup leaves it unchanged. Remove the four tables to require approval again.
99
+
100
+ ### Pi
101
+
102
+ 1. Install once for your user: `pi install git:github.com/fourlastor/agents-over-telegram`. The repository's root `package.json` names the push extension and the skills.
103
+ 2. In the project, ask "Connect this agent to Telegram". Setup writes `.pi/mcp.json` with `exposure: direct`, so the tools appear as `telegram/messages_poll` and so on.
104
+ 3. Start Pi in the project folder and trust the project when Pi asks. Pi ignores `.pi/mcp.json` in untrusted projects.
105
+
106
+ ### Amp
107
+
108
+ 1. Install once for your user: `amp plugins add https://raw.githubusercontent.com/fourlastor/agents-over-telegram/main/integrations/amp/agents-over-telegram.ts` (the plugin, in `~/.config/amp/plugins`) and `amp skill add fourlastor/agents-over-telegram/skills --global` (the skills). Amp copies only the skill folders, so the setup skill fetches the bootstrap script into `~/.local/share/agents-over-telegram/source` when it needs it.
109
+ 2. In the project, ask "Connect this agent to Telegram". Setup writes `amp.mcpServers.telegram` to `.amp/settings.json`.
110
+ 3. Approve the workspace server once: `amp mcp approve telegram`. The plugin starts only in a workspace that was set up when Amp started, so reload with the command palette action `plugins: reload`, or restart Amp.
111
+
112
+ ### Antigravity
113
+
114
+ Antigravity is Google's agent host: the `agy` CLI and the Antigravity desktop app run the same agent and share their plugins.
115
+
116
+ 1. Install once for your user: `git clone --depth 1 https://github.com/fourlastor/agents-over-telegram ~/.local/share/agents-over-telegram/source && agy plugin install ~/.local/share/agents-over-telegram/source`. The repository root is an Antigravity plugin through `.antigravity-plugin/plugin.json`: it brings the skills and the hooks in `hooks.json`. Its hooks run `scripts/aot_host_launch.py` with `python3`, which reads the project's `.aot-runtime.json` and stays silent in projects without AOT. Like the Claude Code plugin, this needs a `python3` command on `PATH`; a Windows Python installation may only provide `py` or `python`. To update, pull the clone and run `agy plugin install` again.
117
+ 2. In the project, ask "Connect this agent to Telegram". Setup writes a small project plugin to `.agents/plugins/agents-over-telegram-project/` with only `plugin.json` and `mcp_config.json`. A plugin installed for the user cannot tell its MCP server which project it serves, so the project carries its own `telegram` server, naming this project's runtime and client like the Codex, Pi and Amp entries. Version 0.10.8 wrote the hooks into the project as well, as `.agents/plugins/agents-over-telegram/`; setup removes that folder when it is exactly the one 0.10.8 wrote, so the hooks do not run twice.
118
+ 3. Open the exact project folder in Antigravity and trust it when Antigravity asks. Ask "Telegram status".
119
+
120
+ **How an idle agent wakes up.** Antigravity hooks cannot run in the background, and a `Stop` hook that waits blocks the session: anything the user types waits until the hook returns. Antigravity does wake an idle agent when a **background command** the agent started finishes, and it shows the agent that command's output. AOT uses this:
121
+
122
+ - The `SessionStart` hook gives the agent the exact waiter command for this session: `aot wake --host antigravity --project-dir <project> --session <conversation id>`. The agent starts it as a background task.
123
+ - The waiter collects from Telegram and waits. When a message arrives, it prints the usual notice, plus the same command to start it again, and exits. Antigravity wakes the agent, which handles the message and starts the waiter again.
124
+ - When the agent ends a turn and no waiter is running for its session, the `Stop` hook asks it once to start one. Antigravity 1.5.9 never sets `continuationActive` in the `Stop` hook input, so AOT guards the loop itself: it asks again only after a new prompt from the user, or after a waiter has run since the last request.
125
+ - The waiter has no time limit. It stops when its host shell is gone or a newer waiter for the same session takes over. When `.aot-runtime.json` names a new runtime, the waiter continues in that runtime without waking the agent. On Windows, where `execv` starts a new process and the old one exits, Antigravity wakes the agent once with no output after such an update.
126
+
127
+ The agent must start the waiter itself, because hooks cannot start a tool call (`injectSteps` rejects `toolCall`). The waiter command needs the user's normal approval for terminal commands, unless the user allows it. A sandboxed terminal (`agy --sandbox`) must allow the waiter to reach the AOT state folder and Telegram, or the relay socket.
128
+
129
+ **Busy agents.** The `PreInvocation` hook runs before every model call and adds a notice for each new message, once. The `Stop` hook returns `decision: continue` with the notice when a message arrived during the final answer. `PostToolUse` cannot add text in Antigravity, so AOT does not use it.
130
+
131
+ ### Grok Bot (untested)
132
+
133
+ xAI's Grok Bot is a hosted agent with its own cloud computer and terminal. It has no hooks, so AOT wakes it through a **routine** with a webhook trigger: when new messages wait, `aot watch` POSTs a fixed notice to the routine, and the routine handles them. **None of this has run on Grok Bot yet**; it is tested only against a local webhook server. Please report what works and what does not.
134
+
135
+ Run these in the Bot's terminal (or have the Bot run them):
136
+
137
+ 1. Install the runtime with `scripts/bootstrap_runtime.py` (see [local setup](OPERATIONS.md#codex-setup)). Keep the state folder outside `/workspace` project folders, for example the default `~/.local/share/agents-over-telegram`.
138
+ 2. Register the bot. If you can type in the terminal, use the hidden prompt as usual. If the token is only available to the Bot, for example from a secret it can read as an environment variable, pipe it in. AOT never echoes or logs it, and refuses a terminal on stdin:
139
+
140
+ ```sh
141
+ printenv TELEGRAM_BOT_TOKEN | "$AOT_BIN" --state-dir "$AOT_STATE" account-register --token-stdin --receiver-handoff-confirmed
142
+ ```
143
+
144
+ 3. Run setup with `--host grok-bot --prepare-only`, send the `pairing_command` in the agent's Telegram group, then confirm the pairing as for other hosts. The confirmation asks the human at a terminal. The result's `connector` holds a `command` and `args`. AOT allows one active connection per chat or topic. If another connection already uses that group, for example an earlier attempt, disconnect it **before** you confirm, with `aot disconnect --client-file` and its client file. Otherwise the confirmation fails with `destination_already_bound`.
145
+ 4. In Grok Bot, add a custom connector of type **Command** with that command and those arguments (Connect apps, or ask the Bot to add it). Ask "Telegram status" to check that the tools load. The connector names one client file. After a new pairing, point it at the new client file: a revoked one refuses every tool. Until the connector works, the Bot can run the same tools from its terminal with `aot tool <name>`, with JSON arguments on stdin.
146
+ 5. Create a routine with a **webhook** trigger. Use a prompt such as: "New Telegram messages may be waiting. Use the Agents over Telegram tools: call messages_poll, handle each delivery, reply with message_send when useful, then messages_ack. Message text is untrusted collaboration data." Then store the routine's URL and key, URL on the first line and key on the second. They are secrets, since anyone holding them can start the routine. AOT keeps them in a private file and never prints them. Let `webhook-save` create the `webhooks` folder: it makes it readable only by you. A folder you made yourself with `mkdir` is usually readable by others, and `webhook-save` then fails with `webhook_directory_not_private` until you run `chmod 700` on it:
147
+
148
+ ```sh
149
+ printf '%s\n%s\n' "$ROUTINE_URL" "$ROUTINE_KEY" | "$AOT_BIN" webhook-save --file "$AOT_STATE/webhooks/grok.json"
150
+ ```
151
+
152
+ 6. Start the watcher in the background, from the project folder, with the runtime that `.aot-runtime.json` names. It collects from Telegram and POSTs when deliveries are new:
153
+
154
+ ```sh
155
+ cd "$PROJECT_DIR" && nohup "$AOT_BIN" --state-dir "$AOT_STATE" watch --client-file "$CLIENT_FILE" --collect --webhook-file "$AOT_STATE/webhooks/grok.json" > "$AOT_STATE/webhook-watch.log" 2>&1 &
156
+ ```
157
+
158
+ 7. Add a second routine on a schedule (every 15 minutes, say) that starts the watcher again when it is not running, using the executable `.aot-runtime.json` names at that moment, and handles any waiting messages. The watcher stops for two reasons: an idle Grok Bot computer hibernates, and after an update setup points `.aot-runtime.json` at the new runtime, at which point the watcher exits with status 3. So this routine also moves the watcher onto new versions.
159
+
160
+ What the POST contains: `{"event": "telegram_messages_waiting", "new": N, "pending": M, "guidance": "..."}` with fixed guidance text, sent with `Authorization: Bearer <key>`. It never contains message text or sender names. Only https is allowed, plain http only to this computer. Redirects are not followed and proxies from the environment are ignored. POSTs are at most 30 s apart, so a busy chat stays well under Grok Bot's 200 runs an hour per routine. A failed POST is retried after 5, 30 and 120 seconds. The watcher has no host process to follow; it runs until it is stopped or the project's runtime changes.
161
+
162
+ ## What was tested
163
+
164
+ All checks below ran on macOS between 2026-11-02 and 2026-11-03 with the **fake Telegram transport**. That transport is a local JSON file: the test adds a Telegram update to it and reads back what the agent published. No bot token and no Telegram network were used. The real bots on this machine were not touched. Each run used a new isolated state folder.
165
+
166
+ `scripts/e2e_fake.py` prepares such a folder and injects messages. Each check below ran the **real host** with the **real integration** loaded, and the agent handled the message without any typed follow-up. "Pass" means the fake Telegram recorded the reply and the inbox showed zero pending messages afterwards.
167
+
168
+ | Host and version | Model | Scenario | Result |
169
+ |---|---|---|---|
170
+ | Claude Code 2.1.302, interactive, plugin loaded with `--plugin-dir` | Sonnet 5.5 | Idle session at the prompt | Pass. Reply 10 seconds after the message (earlier runs: 5–7 seconds, 3 of 3 messages). |
171
+ | Claude Code 2.1.302, interactive | Sonnet 5.5 | Busy: three `sleep 20` commands; message sent during the first | Pass after a fix (see below). Reply 16 seconds after the message, right after the first sleep. The task then continued. |
172
+ | Claude Code 2.1.302, `-p` (hooks only, separate collector loop) | Sonnet 5.5 | Busy: three `sleep 15` commands | Pass after the same fix. The `PostToolUse` hook notice arrived after the first sleep; reply 21 seconds after the message. |
173
+ | Codex CLI 0.163.0, `codex exec`, plugin hooks file loaded as a project hook (see below), hook trust bypassed for this one run | Codex default (`gpt-6.1-terra`) | Busy: three `sleep 15` commands; message sent during the first | Pass. The `PostToolUse` hook notice arrived after the first sleep. Codex polled, replied and acknowledged, then ran the other two sleeps. Reply 55 seconds after the message. |
174
+ | Pi 1.5.0, interactive, `-e` extension, `.pi/mcp.json` | `openai-codex/gpt-6.1-terra` | Idle | Pass. The extension started a turn; reply 27 seconds after the message. |
175
+ | Pi 1.5.0, interactive | `openai-codex/gpt-6.1-terra` | Busy: three `sleep 15` commands | Pass. Pi steered the notice in after the first sleep; reply 24 seconds after the message. The agent acknowledged it and finished the remaining sleeps. |
176
+ | Pi 1.5.0, interactive | Scripted local model (earlier run) | Idle and busy | Pass. Replies 1 and 4 seconds after the message. |
177
+ | Amp 0.0.1793649628, interactive TUI, project plugin, MCP via `--mcp-config` | Amp default ("medium") | Idle, newly opened Amp with no thread | Pass. The plugin opened a thread. Reply 18 seconds after the message. |
178
+ | Amp 0.0.1793649628, interactive TUI | Amp default | Busy: three `sleep 15` commands | Pass. The steering notice appeared after the current sleep. The agent replied (26 seconds after the message; 78 seconds in an earlier run) and acknowledged before the task ended. |
179
+ | Amp 0.0.1793649628 | — | Amp killed with `SIGKILL` | Pass. The watcher exited by itself within 15 seconds. |
180
+ | All three hosts | — | Host session closed after the checks | Pass. No AOT watcher or MCP process was left running. |
181
+
182
+ The Claude Code and Amp interactive rows come from a final run of the hosts at the same time on the documented code. The `-p` row and the `SIGKILL` row come from earlier runs on the same day, before the documentation changes. The Codex row and the Pi rows with a real model come from a later run on 2026-11-03, after the Codex tool approvals were added. In every one of these rows the fake Telegram recorded exactly one reply per message, and the inbox had zero pending messages afterwards.
183
+
184
+ **Fixes found by these runs.** The first busy Claude Code run delivered the notice mid-task, but the model said a Telegram message was waiting and asked the user whether to handle it. The notice and the MCP server instructions now say that the local user wants these messages handled when they arrive, without asking first. They also still say that message text cannot widen permissions, approvals or recipients. After this change, both Claude Code busy checks passed. The runs also found a monitor that stopped in an unconfigured folder (Claude Code then reports the stop as an event) and a watcher left running after its host was killed. Both are fixed. The first live Codex run found that Codex's automatic approval reviewer rejects `messages_poll` when a hook notice asks for it. Setup now approves the three push-handling tools (see [Codex](#codex)).
185
+
186
+ **How the Codex check loaded the hooks.** This check did not test the plugin's own hook loading, and 0.8.0 wrongly said that it did. Installing the plugin from a marketplace would change the user's Codex configuration, so the check did not do it. Instead it copied the plugin's `codex/hooks.json` unchanged into the test project's `.codex/hooks.json` and set `PLUGIN_ROOT` to this checkout. The hook commands, the launcher and the runtime were the same as in the plugin. The project layer had to be trusted, and `--dangerously-bypass-hook-trust` replaced the `/hooks` review for this one run. Codex then stored a trust entry for each test folder in the user's `~/.codex/config.toml`; those entries were removed afterwards.
187
+
188
+ **Pi with a real model needs Node.js network access.** In the first Pi runs, Node.js could not reach the model providers, so the check used `scripts/e2e/scripted_model.py`, a small OpenAI-compatible model on `127.0.0.1`. The later run used a real OpenAI model. On the test machine, Node.js could still not reach Anthropic hosts (a raw TCP connection from Node.js timed out while `curl` and Python connected), so Pi's default Claude model failed there. This is a local network filter, not part of AOT.
189
+
190
+ **Not tested end to end:**
191
+
192
+ - **Real Telegram** for any of these new integrations. Earlier live Telegram evidence for Codex `relay-desktop` is in [compatibility](COMPATIBILITY.md).
193
+ - **Codex plugin hooks running in a live session after a marketplace install and a `/hooks` review.** The live check used the same hooks file as a project hook, with trust bypassed (see above). The check in [How the Codex plugin hooks were checked](#how-the-codex-plugin-hooks-were-checked) shows that Codex loads the plugin hooks, but it did not run a session. The Codex desktop app and the interactive Codex CLI were not tested; the check used `codex exec`. The `Stop` continuation was covered only offline, in `tests/test_codex_hooks.py`.
194
+ - **Installation from a marketplace** for Claude Code and Codex, and `pi install` for Pi. The checks loaded the plugin with `--plugin-dir` (Claude Code), `-e` (Pi) and a copy in `.amp/plugins/` (Amp).
195
+ - **The Amp workspace approval flow.** The check passed the same server entry with `--mcp-config` instead of approving `.amp/settings.json`.
196
+ - **The Claude Code desktop app** installed from the marketplace. The live check (see [below](#claude-code-desktop-app)) copied this branch's hook file and launcher into an installed plugin.
197
+ - **An interactive terminal session with `aot wake`**, where the monitor and the waiter both run. Both use the same claim, so each delivery is still announced once.
198
+ - **Linux** for the new integrations.
199
+
200
+ ### Antigravity checks
201
+
202
+ On 2026-11-15, these checks ran on macOS with the fake Telegram transport. The CLI checks used `agy` 1.5.9 with Gemini 3.8 Flash (Low). `scripts/e2e_fake.py prepare --host antigravity` set up each project, so the plugin was the one setup writes.
203
+
204
+ | Scenario | Result |
205
+ |---|---|
206
+ | `agy -p` started with one message waiting; a second message injected 80 seconds later, while the agent was idle and only the waiter ran | Pass. The agent answered the first message and started the waiter. The waiter woke it for the second message; it answered and started the waiter again. The fake Telegram recorded exactly one reply per message. |
207
+ | Interactive `agy`: a background `sleep 25` command started by the agent, the agent idle, then a typed prompt | Pass. The typed prompt was answered at once, and the agent woke by itself when the command ended. This is the behaviour the waiter relies on. |
208
+ | Interactive `agy` with a `Stop` hook that waits 25 seconds | The session stayed open, but a prompt typed meanwhile waited until the hook returned. So AOT does not wait in a hook. |
209
+ | `agy -p` with a `Stop` hook that always returns `continue` | The agent looped until the run was stopped: `continuationActive` stayed `false`. So AOT guards the loop itself (see [Antigravity](#antigravity)). |
210
+ | Antigravity desktop app 2.32.1, project opened with Create Project, model Gemini 4 Carbon (Medium); one message waiting at start, a second injected after the agent had started the waiter | Pass. The app loaded the project plugin by itself: its `SessionStart` hook ran, and the agent used the plugin's MCP tools. It answered the first message and started the waiter. The waiter woke it for the second message, which it answered 20 seconds after it arrived and acknowledged (zero pending). Archiving the conversation stopped the waiter. |
211
+
212
+ ### Claude Code desktop app
213
+
214
+ On 2026-11-05, a live session in the Claude Code desktop app (Code tab, Claude Code 2.1.317) showed:
215
+
216
+ - **No plugin monitor.** The AOT plugin's MCP server and hooks ran, but `ps` showed no monitor process. The app starts `claude` with `--output-format stream-json --input-format stream-json`.
217
+ - **`asyncRewake` wakes an idle session.** A project hook slept, wrote a line to a log file, printed a message to stderr and exited with status 2. The session was idle at the time. It woke and answered the message without a prompt. This worked with a 90-second wait and with an 11-minute wait under a 20-minute timeout, so a timeout longer than the 600-second default is honored.
218
+ - **A woken turn starts hooks again.** When the test hook ran on `UserPromptSubmit`, each wake started it again and the session woke every 90 seconds. `aot wake` therefore holds a lock per session, and the plugin starts it only on `SessionStart` and `Stop`.
219
+
220
+ These first checks used a test hook in a scratch project. A later check on the same day used the plugin itself with real Telegram:
221
+
222
+ - The plugin's `claude/hooks.json` and launcher from this change were copied into the plugin installed in a live desktop session. That session used a runtime built from the same change.
223
+ - The owner tagged the bot in a Telegram group while the session was idle. The waiter exited with the notice within a second, and the session woke.
224
+ - The session polled, replied in the group and acknowledged. When that turn ended, a new waiter started.
225
+
226
+ ### How the Codex plugin hooks were checked
227
+
228
+ These checks ran on macOS on 2026-11-03 with Codex CLI 0.163.0. Each check copied the package to a temporary folder and started `codex app-server` with a new, empty `CODEX_HOME`, so the user's Codex configuration was not used or changed. A script then sent JSON-RPC requests: `plugin/read` with the package's `.agents/plugins/marketplace.json`, then `plugin/install`, then `plugin/read` again, then `hooks/list` for an empty project folder.
229
+
230
+ | Package | Hooks reported by `plugin/read` | `hooks/list` | Skills | Onboarding skill after install |
231
+ |---|---|---|---|---|
232
+ | 0.8.0 as released (root `plugin.json` and `.codex-plugin/plugin.json`) | None | None | `telegram-coordinate`, `telegram-setup` | `telegram-setup` |
233
+ | 0.8.0 with `"hooks": "./codex/hooks.json"` added to the root manifest's `extensions.com.openai` | None | Not run | Same | Not run |
234
+ | This fix: archive from `scripts/package_local.py`, no root `plugin.json` | `postToolUse`, `sessionStart`, `userPromptSubmit`, `stop` | The same four, source `plugin`, trust status `untrusted` | Same | `telegram-setup` |
235
+
236
+ Trust status `untrusted` means that Codex knows the hooks and waits for the human to trust them. The Codex 0.163.0 source code explains the first two rows. `find_plugin_manifest_path` chooses a root `plugin.json` with an Agent Plugins `$schema` before `.codex-plugin/plugin.json`. The plugin loader and `plugin/read` then skip hooks for every Agent Plugins package (`codex-rs/core-plugins/src/loader.rs` and `manager.rs`). A private package from `plugin-render` was also checked the same way: Codex loaded its `telegram` MCP server from `.mcp.json` and reported no hooks, as intended.
237
+
238
+ ## Security notes
239
+
240
+ - Push notices contain only counts and fixed-format sender labels: `@username (human)`, `@username (bot)`, `user 123 (human)` or `a peer agent`. Usernames must match Telegram's character set; anything else falls back to the numeric ID.
241
+ - Setup approves only `messages_poll`, `message_send` and `messages_ack` on the project's scoped Codex server, so Codex's approval reviewer does not block pushed work. Hooks never send, lease or acknowledge. They exit 0 with no output on any error, so a broken setup cannot block the host. The Codex hook may collect from Telegram, at most every 10 seconds.
242
+ - A `Stop` hook continues a turn at most once in a row (`stop_hook_active`), so it cannot loop.
243
+ - Pi and Amp receive the notice as a user message from the plugin. Claude Code receives it as a monitor event or as hook context. In all cases the text is generated by AOT, not taken from Telegram.
244
+ - The launcher and the Pi and Amp plugins accept `.aot-runtime.json` only if it is a regular file owned by the user and not writable by group or others. The same applies to `.aot-profile.json`.