@stage-labs/metro 0.1.0-beta.4 → 0.1.0-beta.6

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.
package/docs/agents.md ADDED
@@ -0,0 +1,168 @@
1
+ # Metro: a guide for coding agents
2
+
3
+ You are running inside a session that has **launched `metro`** in the background. Metro emits a live stream of JSON events from Discord, Telegram, and other agents on its stdout. Your job is to consume that stream and post replies back via subcommands.
4
+
5
+ ## Starting the bridge
6
+
7
+ The launch mechanics differ by runtime — pick the one that matches yours.
8
+
9
+ ### Claude Code
10
+
11
+ ```
12
+ Bash(command: "metro", run_in_background: true)
13
+ ```
14
+
15
+ Then attach `Monitor` to its stdout. Each line is one JSON event you act on.
16
+
17
+ ### Codex
18
+
19
+ ```
20
+ shell(command: "METRO_CODEX_RC=ws://127.0.0.1:8421 metro", run_in_background: true)
21
+ ```
22
+
23
+ Don't watch its stdout — Codex has no Monitor equivalent. Metro pushes each event into your thread via JSON-RPC `turn/start`, so events arrive as user input on your next turn. The user must have a daemon and TUI running for this to work:
24
+
25
+ ```
26
+ codex app-server --listen ws://127.0.0.1:8421 # daemon (terminal 1)
27
+ codex --remote ws://127.0.0.1:8421 # TUI (this session — terminal 2)
28
+ ```
29
+
30
+ Run `metro doctor` if anything seems off.
31
+
32
+ ## Event shape
33
+
34
+ Every event carries `id` (`msg_…`), `ts`, `from` (a universal participant URI), `fromName` (display name), `line` (conversation = `to`), and `messageId` (the platform-side id).
35
+
36
+ ```json
37
+ {"type":"inbound","id":"msg_aB3xY7zP","ts":"2026-05-14T12:00:00Z","station":"telegram","line":"metro://telegram/-100…/247","from":"metro://telegram/user/12345","fromName":"@alice","messageId":"4567","text":"hello","attachmentNames":["[image]"],"mentionsBot":true,"meta":{"isPrivate":false,"inForum":true,"isForumTopic":true},"lineName":"infra"}
38
+ ```
39
+
40
+ ```json
41
+ {"type":"notification","id":"msg_pQ4r5sT0","ts":"…","line":"metro://claude/deploys","from":"metro://codex/ci","text":"deploy succeeded"}
42
+ ```
43
+
44
+ Both `from` and `to` are **participant URIs** (the conversation lives in `line`): `metro://<station>/user/<id>` for a person, `metro://claude/<topic>` / `metro://codex/<topic>` for an agent, `metro://<station>/<channelId>` as a fallback `to` when sending to a group with no single recipient.
45
+
46
+ When **you** call `metro send`/`reply`/`edit`/`react`, metro auto-stamps `from` to your runtime — `metro://claude/agent` (from `$CLAUDECODE`) or `metro://codex/agent` (from `$METRO_CODEX_RC`/`$CODEX_HOME`). Override with `--from=<uri>` or `$METRO_FROM`. When replying/reacting, `to` is auto-set to the original sender (history lookup).
47
+
48
+ - `type: "inbound"` — a human (or another bot) posted on a chat platform.
49
+ - `type: "notification"` — another agent called `metro notify`/`metro send` against your agent line. This is how Codex pings Claude Code and vice versa.
50
+
51
+ `text` may include `[image]` / `[voice]` / `[audio]` / `[file: <name>]` placeholders alongside the real text — non-image attachments are opaque markers, images can be materialized via `metro download`.
52
+
53
+ ## Required flow on every event
54
+
55
+ 1. **Echo the event** to your visible output: `[<line>#<messageId>] <text>`. Both Monitor and Codex collapse tool output, so this echo is the only thing the user sees without expanding cards.
56
+ 2. **Decide and act** using the subcommands below.
57
+
58
+ ## Subcommands
59
+
60
+ | Action | Command |
61
+ |---|---|
62
+ | Quote-reply (threads under original) | `metro reply <line> <messageId> <text>` |
63
+ | Send a fresh message (no reply context) | `metro send <line> <text>` |
64
+ | Edit a message you previously sent | `metro edit <line> <messageId> <text>` |
65
+ | Reaction (empty emoji clears it) | `metro react <line> <messageId> <emoji>` |
66
+ | Download `[image]` attachments | `metro download <line> <messageId> [--out=<dir>]` |
67
+ | Recent-message lookback (Discord only) | `metro fetch <line> [--limit=20]` |
68
+ | Cross-agent ping | `metro notify <line> <text> [--from=<line>]` |
69
+
70
+ `reply` / `send` / `edit` accept multi-line text via stdin (heredoc).
71
+
72
+ ### Rich content flags
73
+
74
+ `send` and `reply` accept these flags; `edit` accepts `--buttons` only.
75
+
76
+ - `--image=<path>` — local image. **Repeatable** for albums: `--image=a.png --image=b.png` (or comma-separated). Up to 10 / message. Text becomes the caption (on the first image for albums).
77
+ - `--document=<path>` — local file (PDF, log, csv, …). Same repeat/comma syntax.
78
+ - `--voice=<path>` — single voice message (`.ogg` Opus or `.mp3`). On Telegram renders as a voice bubble; on Discord uploaded as audio attachment.
79
+ - `--buttons='[[{"text":"…","url":"…"}]]'` — inline URL-button keyboard (2D rows × buttons). Pass `'[]'` to `edit` to clear.
80
+
81
+ ```bash
82
+ metro send <line> "screenshot" --image=/tmp/build.png
83
+ metro send <line> "before/after" --image=/tmp/before.png --image=/tmp/after.png
84
+ metro reply <line> <id> "voice note" --voice=/tmp/note.ogg
85
+ metro send <line> "approve?" --buttons='[[{"text":"Open PR","url":"https://github.com/x/y/pull/1"}]]'
86
+ ```
87
+
88
+ Limits: 20 MB / file. Telegram albums are single-type (photos OR documents per album); mixing kinds still works — metro splits into two messages. Buttons are dropped on multi-attachment Telegram sends. URL buttons only for now.
89
+
90
+ Append `--json` to any command for a single JSON line you can parse.
91
+
92
+ ## When to use `reply` vs `send`
93
+
94
+ - **`reply`** — responding to a specific inbound message. Threads under it. Default when handling an `inbound` event.
95
+ - **`send`** — initiating without a triggering message: a long task you kicked off finished, a follow-up the user asked you to deliver later, or posting to an agent line (`metro://claude/...`, `metro://codex/...`) to notify a peer.
96
+
97
+ ## Universal message IDs
98
+
99
+ The `id` field on every event and `metro history` row is metro's **universal ID** (`msg_<8 chars>`). It works anywhere a `<message_id>` is expected — `metro reply`, `edit`, `react`, `download` — and resolves to the platform's own id via the history file. Use it for chaining commands or referring back across stations.
100
+
101
+ ## `metro history` — read the universal message log
102
+
103
+ Every inbound, outbound, edit, react, and notification is appended to `$METRO_STATE_DIR/history.jsonl` automatically.
104
+
105
+ ```bash
106
+ metro history --limit=20 # recent 20, newest first
107
+ metro history --line=metro://discord/123 # only this conversation
108
+ metro history --kind=inbound --since=2026-05-14 # inbounds since that day
109
+ metro history --station=telegram --text=deploy # all Telegram entries containing "deploy"
110
+ metro history --from='@alice' --json # everything from alice, JSON
111
+ ```
112
+
113
+ Filters: `--limit` (default 50), `--line`, `--station`, `--kind` (`inbound`/`outbound`/`edit`/`react`/`notification`), `--from`, `--text`, `--since` (ISO), `--json`.
114
+
115
+ ## Discovery
116
+
117
+ ### `metro lines`
118
+
119
+ ```
120
+ $ metro lines
121
+ 2m ago metro://discord/1234567890 infra
122
+ 5m ago metro://telegram/-100123/42 design-review
123
+ ```
124
+
125
+ Lines sorted by recency. Use when the user says "the Telegram channel" or "that PR thread."
126
+
127
+ ### `metro stations`
128
+
129
+ ```
130
+ $ metro stations
131
+ ✓ discord chat in: text+image · out: text · features: reply, send, edit, react, download, fetch
132
+ ✓ telegram chat in: text+image · out: text · features: reply, send, edit, react, download, fetch
133
+ · claude agent in: text · out: – · features: notify
134
+ ✓ codex agent in: text · out: – · features: notify
135
+ ```
136
+
137
+ `✓` = ready, `✗` = configured-but-broken, `·` = informational (agent stations have no setup).
138
+
139
+ ## Image attachments
140
+
141
+ When an inbound has an `[image]` tag in `text`:
142
+
143
+ 1. `metro download <line> <messageId>` → prints absolute paths.
144
+ 2. `Read` each path with your `Read` tool — the image enters your context as a vision input.
145
+ 3. Reply normally via `metro reply`.
146
+
147
+ ## Cross-agent notification
148
+
149
+ Both agents can post to each other's "agent line" — a logical channel under `metro://claude/<topic>` or `metro://codex/<topic>`. The daemon re-emits the post on its stdout stream (and pushes via codex-rc if configured), so the peer agent sees it as a notification:
150
+
151
+ ```bash
152
+ metro send metro://claude/deploys "build green, ready to ship"
153
+ # or equivalently:
154
+ metro notify metro://claude/deploys "build green, ready to ship" --from=metro://codex/ci
155
+ ```
156
+
157
+ This requires the metro daemon to be running on the machine. Without a daemon, agent-line sends error with a clear message.
158
+
159
+ ## Don'ts
160
+
161
+ - ❌ Spawning a second metro daemon — there's one per machine (lockfile-enforced).
162
+ - ❌ `metro send` to a line that isn't in `metro lines` unless the user gave it to you explicitly.
163
+ - ❌ Narrating the tool ("I'll now use metro reply to…"). The tool call is already visible.
164
+
165
+ ## Further reading
166
+
167
+ - URI scheme: [`uri-scheme.md`](uri-scheme.md)
168
+ - Source: https://github.com/bonustrack/metro
@@ -0,0 +1,71 @@
1
+ # Metro URI scheme
2
+
3
+ Universal identifier for every conversational scope and notification sink in metro. Lines pass around as opaque strings; only the owning station parses its own paths.
4
+
5
+ ## Grammar
6
+
7
+ ```
8
+ line = "metro://" station "/" path
9
+ station = lowercase identifier (claude | codex | discord | telegram | …)
10
+ path = station-specific, "/"-separated segments
11
+ ```
12
+
13
+ The URI parses cleanly with the WHATWG `URL` parser: `new URL(line)` gives `protocol="metro:"`, `host=<station>`, `pathname="/<path>"`.
14
+
15
+ ## Registered stations
16
+
17
+ | Station | Kind | Pattern | Example |
18
+ |------------|-------|-------------------------------------------|---------------------------------------|
19
+ | `discord` | chat | `metro://discord/<channel-id>` | `metro://discord/1234567890123456789` |
20
+ | `telegram` | chat | `metro://telegram/<chat-id>[/<topic-id>]` | `metro://telegram/-1001234567890/42` |
21
+ | `claude` | agent | `metro://claude/<topic>` | `metro://claude/deploys` |
22
+ | `codex` | agent | `metro://codex/<topic>` | `metro://codex/ci` |
23
+
24
+ ## Participants
25
+
26
+ Every chat station also exposes participant URIs — used as `from` on inbound/outbound events and history rows.
27
+
28
+ | Kind | Pattern | Example |
29
+ |-------|------------------------------------------|----------------------------------|
30
+ | user | `metro://<station>/user/<id>` | `metro://discord/user/87654321` |
31
+ | agent | `metro://{claude,codex}/<topic>` | `metro://claude/agent` |
32
+
33
+ `from` and `to` on history entries are always participant URIs. Discord/Telegram inbounds set `from` to the user URI; the daemon sets `to` to the agent identity (`metro://claude/agent` if `$CLAUDECODE` is detected, `metro://codex/agent` if `$METRO_CODEX_RC`/`$CODEX_HOME` is set, else `metro://agent`). On outbound, `from` = the same agent identity; `to` = the original sender for replies/reacts (looked up from history), or the channel `line` for fresh group sends. A `fromName` field carries the display name (`@alice`, `bonustrack_`).
34
+
35
+ Override with `--from=<uri>` on any write command, or set `$METRO_FROM` to pin a custom identity for the whole session.
36
+
37
+ Chat lines identify a Discord channel / Telegram chat (with optional forum topic). Agent lines are notification sinks — posting to one re-emits the message on the daemon's stdout stream and (if configured) pushes it to the Codex app-server. They have no inherent "messages"; only events.
38
+
39
+ ## Message addressing
40
+
41
+ Messages on chat lines are referenced by **line + message id** (two args), not as part of the URI. So:
42
+
43
+ ```bash
44
+ metro reply metro://discord/123… 4567 "ack"
45
+ metro edit metro://discord/123… 9876 "fixed typo"
46
+ metro react metro://telegram/-100…/42 4567 👍
47
+ ```
48
+
49
+ ## Properties
50
+
51
+ - **Stable**: a Line is valid for the lifetime of the scope.
52
+ - **Self-describing**: the station name is encoded; the dispatcher routes by station prefix.
53
+ - **Persistable**: safe as a JSON key on disk (used by `lines.json`).
54
+ - **Branded**: TypeScript type `Line` prevents mixing with arbitrary strings.
55
+
56
+ ## API
57
+
58
+ ```ts
59
+ import { Line } from './stations/index.js'; // value namespace + type
60
+
61
+ const l: Line = Line.discord('1234567890'); // typed Line
62
+ Line.parse(l); // { station: 'discord', path: ['1234567890'] } | null
63
+ Line.station(l); // 'discord'
64
+ Line.isAgent(Line.claude('deploys')); // true
65
+ ```
66
+
67
+ ## Adding a new station
68
+
69
+ 1. Pick a lowercase station name (`slack`, `matrix`, …).
70
+ 2. Add a `Line.<station>(...)` formatter and a parser that returns your typed payload.
71
+ 3. Document the path grammar in the table above.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stage-labs/metro",
3
- "version": "0.1.0-beta.4",
4
- "description": "Orchestrator daemon that bridges Codex / Claude Code agent sessions with Telegram and Discord. Each chat thread gets its own agent session, with streaming responses and tool-call visibility.",
3
+ "version": "0.1.0-beta.6",
4
+ "description": "Live JSON stream of Telegram + Discord messages for your local Claude Code / Codex session. The agent launches metro; metro emits inbounds on stdout and accepts replies via CLI subcommands.",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -14,10 +14,12 @@
14
14
  "node": ">=22"
15
15
  },
16
16
  "bin": {
17
- "metro": "./dist/cli.js"
17
+ "metro": "./dist/cli/index.js"
18
18
  },
19
19
  "files": [
20
20
  "dist",
21
+ "docs",
22
+ "skills",
21
23
  "README.md",
22
24
  "LICENSE"
23
25
  ],
@@ -34,6 +36,7 @@
34
36
  "dependencies": {
35
37
  "discord.js": "^14.14.0",
36
38
  "pino": "^9.5.0",
39
+ "pino-pretty": "^13.1.3",
37
40
  "ws": "^8.20.0"
38
41
  },
39
42
  "devDependencies": {
@@ -0,0 +1,220 @@
1
+ ---
2
+ name: metro
3
+ description: Run the metro Telegram/Discord bridge in this session — launch `metro` in the background, watch its stdout for inbound JSON events, and act on each. Use when the user asks to start/run/launch metro, when you see JSON lines on stdout shaped `{"type":"inbound","station":...,"line":"metro://...","messageId":...,"text":...}`, or when handling a chat reply/edit/react/send/download/fetch/notify.
4
+ ---
5
+
6
+ # Metro — running the Telegram & Discord bridge
7
+
8
+ Metro is a CLI bridge between this agent session and Telegram/Discord. You launch `metro` once when the user asks, then act on each inbound JSON line via `metro <subcommand>`.
9
+
10
+ ## Starting the bridge
11
+
12
+ When the user asks to run/start/launch metro:
13
+
14
+ ### Claude Code
15
+
16
+ ```
17
+ Bash(command: "metro", run_in_background: true)
18
+ ```
19
+
20
+ Then attach `Monitor` to its stdout. Each line is one JSON event. Stderr is pino logs — don't act on it.
21
+
22
+ ### Codex
23
+
24
+ ```
25
+ shell(command: "METRO_CODEX_RC=ws://127.0.0.1:8421 metro", run_in_background: true)
26
+ ```
27
+
28
+ Codex has no Monitor equivalent. Instead, metro pushes each event into your thread via JSON-RPC `turn/start`, so events arrive as user input on your next turn. The user must have a daemon + TUI running on the **same WebSocket URL**:
29
+
30
+ ```
31
+ codex app-server --listen ws://127.0.0.1:8421 # daemon (terminal 1)
32
+ codex --remote ws://127.0.0.1:8421 # TUI (terminal 2) — type "hi" once to create a live thread
33
+ ```
34
+
35
+ Then metro starts third. If metro exits immediately or you see `thread not found` retries on its stderr, the TUI didn't create a thread yet — tell the user to type something in the TUI.
36
+
37
+ ### Diagnostics
38
+
39
+ If something seems off, run `metro doctor`. Common causes: missing tokens (`metro setup telegram <token>` / `metro setup discord <token>`), Discord Message Content Intent not toggled, stale lockfile, or (Codex) no live thread on the daemon.
40
+
41
+ ## Event shape
42
+
43
+ Every line on stdout is one JSON object. Each event carries:
44
+ - `id` (`msg_…`) — universal message ID minted by metro
45
+ - `ts` — ISO timestamp
46
+ - `from` — universal **participant URI** of the sender (a Line)
47
+ - `fromName` — optional human-readable display name (`@alice`, `bonustrack_`)
48
+ - `line` — the conversation URI (also the implicit `to`)
49
+ - `messageId` — the platform-side id (Discord snowflake, Telegram int, …)
50
+
51
+ ```json
52
+ {"type":"inbound","id":"msg_aB3xY7zP","ts":"2026-05-14T12:00:00Z","station":"telegram","line":"metro://telegram/-100…/247","from":"metro://telegram/user/12345","fromName":"@alice","messageId":"4567","text":"hi","attachmentNames":["[image]"],"mentionsBot":true,"meta":{"isPrivate":false,"inForum":true,"isForumTopic":true},"lineName":"infra"}
53
+ ```
54
+
55
+ ```json
56
+ {"type":"notification","id":"msg_pQ4r5sT0","ts":"…","line":"metro://claude/deploys","from":"metro://codex/ci","text":"deploy green"}
57
+ ```
58
+
59
+ Both `from` and `to` are **participant URIs** (the conversation context lives in `line`):
60
+ - `metro://<station>/user/<id>` — a person on a chat platform
61
+ - `metro://claude/<topic>` / `metro://codex/<topic>` — an agent
62
+ - `metro://<station>/<channelId>` — a channel (used as `to` for fresh sends to a group, where no single recipient)
63
+
64
+ When **you** send via `metro send`/`reply`/`edit`/`react`, metro auto-stamps `from = metro://claude/agent` (from `$CLAUDECODE`) or `metro://codex/agent` (from `$METRO_CODEX_RC` / `$CODEX_HOME`). Override with `--from=<uri>` or `$METRO_FROM`. When replying/reacting, `to` is automatically the original sender (looked up via the universal id).
65
+
66
+ The `id` is the **canonical handle** for that message across all stations — store it if you want to refer back to it later.
67
+
68
+ - `type: "inbound"` — a human (or another bot) posted on a chat platform.
69
+ - `type: "notification"` — another agent called `metro notify` / `metro send` against your agent line. This is how Codex pings Claude Code and vice versa.
70
+
71
+ `text` may contain `[image]`, `[voice]`, `[audio]`, or `[file: <name>]` placeholders alongside the real text — non-image attachments are opaque markers; images can be materialized via `metro download`.
72
+
73
+ ## Required flow on every event
74
+
75
+ 1. **Echo to your visible output**: `[<line>#<messageId>] <text>` on its own line. Both Claude Code's Monitor and Codex collapse tool output, so this echo is the only way the user sees what arrived without expanding cards.
76
+ 2. **Decide and act** using the subcommands below.
77
+
78
+ No server-side auto-reaction — don't expect 👀 to be on the user's message; add one yourself with `metro react` if you want to ack quickly.
79
+
80
+ ## Subcommands
81
+
82
+ All take positional args (no `--to=`/`--text=` flags). Append `--json` to any for a parseable single-line result.
83
+
84
+ | Action | Command |
85
+ |---|---|
86
+ | Quote-reply (threads under original) | `metro reply <line> <messageId> <text>` |
87
+ | Send a fresh message (no reply context) | `metro send <line> <text>` |
88
+ | Edit a message you previously sent | `metro edit <line> <messageId> <text>` |
89
+ | Reaction (empty emoji clears) | `metro react <line> <messageId> <emoji>` |
90
+ | Download `[image]` attachments → paths | `metro download <line> <messageId> [--out=<dir>]` |
91
+ | Recent channel history (Discord only) | `metro fetch <line> [--limit=20]` |
92
+ | Ping another agent (cross-agent line) | `metro send metro://claude/<topic> <text>` or `metro notify <line> <text> [--from=<line>]` |
93
+
94
+ `reply` / `send` / `edit` accept multi-line text via stdin (heredoc).
95
+
96
+ ### Rich content flags
97
+
98
+ `send` and `reply` accept these extra flags; `edit` accepts `--buttons` only.
99
+
100
+ - `--image=<path>` — upload a local image. **Repeatable** for albums: `--image=a.png --image=b.png`. Comma-separated also works: `--image='a.png,b.png'`. Up to 10 / message. Text becomes the caption (on the first image for albums).
101
+ - `--document=<path>` — upload any local file (PDF, log, csv, …). Same repeat/comma syntax.
102
+ - `--voice=<path>` — single voice message (`.ogg` Opus or `.mp3`). On Telegram renders as a voice bubble via `sendVoice`; on Discord uploaded as an audio attachment.
103
+ - `--buttons='[[{"text":"…","url":"https://…"}]]'` — attach an inline URL-button keyboard. 2D array: outer = rows, inner = buttons on that row.
104
+
105
+ ```bash
106
+ metro send <line> "screenshot" --image=/tmp/build.png
107
+ metro send <line> "before/after" --image=/tmp/before.png --image=/tmp/after.png
108
+ metro reply <line> <id> "log + transcript" --document=/tmp/run.log --document=/tmp/transcript.txt
109
+ metro send <line> "have a listen" --voice=/tmp/note.ogg
110
+ metro send <line> "approve?" --buttons='[[{"text":"Open PR","url":"https://github.com/x/y/pull/1"}]]'
111
+ metro edit <line> <id> "still working…" --buttons='[]' # clears buttons
112
+ ```
113
+
114
+ Limits / quirks:
115
+ - 20 MB per file (both platforms).
116
+ - Telegram albums are single-type (all photos OR all documents in one album). Mixing kinds in one send still works — metro splits into two album messages and returns the first id.
117
+ - Telegram drops `--buttons` when multiple attachments are sent (the bot API doesn't allow `reply_markup` on media groups).
118
+ - URL buttons only (no callback / interactive components yet).
119
+
120
+ ## When to use `reply` vs `send`
121
+
122
+ - **`reply`** — responding to a specific inbound message. Threads under it. Default for handling an `inbound` event.
123
+ - **`send`** — initiating without a triggering message: a long task finished, a follow-up the user asked you to deliver later, or posting to an agent line (`metro://claude/...`, `metro://codex/...`) to notify a peer.
124
+
125
+ ## Line URI scheme
126
+
127
+ `metro://<station>/<path>` — see [docs/uri-scheme.md](https://github.com/bonustrack/metro/blob/main/docs/uri-scheme.md) for the full grammar.
128
+
129
+ | Station | Pattern | Example |
130
+ |------------|-------------------------------------------|--------------------------------------|
131
+ | `discord` | `metro://discord/<channel-id>` | `metro://discord/1234567890` |
132
+ | `telegram` | `metro://telegram/<chat-id>[/<topic-id>]` | `metro://telegram/-1001234567890/42` |
133
+ | `claude` | `metro://claude/<topic>` | `metro://claude/deploys` |
134
+ | `codex` | `metro://codex/<topic>` | `metro://codex/ci` |
135
+
136
+ The `messageId` is **not** part of the URI — it's a separate positional arg for `reply` / `edit` / `react` / `download`.
137
+
138
+ ## Image attachments
139
+
140
+ When an event's `text` contains `[image]`:
141
+
142
+ 1. `metro download <line> <messageId>` — writes images to disk and prints absolute paths.
143
+ 2. `Read` each path with your Read tool — the image enters your context as a vision input.
144
+ 3. Reply normally with `metro reply`.
145
+
146
+ ## Opaque attachment markers
147
+
148
+ `[voice]`, `[audio]`, and `[file: <name>]` are opaque — `metro download` only handles images. Acknowledge in text or ask the user to resend as a regular file.
149
+
150
+ ## Cross-agent notification
151
+
152
+ Both agents can post to each other's "agent line":
153
+
154
+ ```bash
155
+ metro send metro://claude/deploys "build green, ready to ship"
156
+ # or
157
+ metro notify metro://codex/ci "build green" --from=metro://claude/deploys
158
+ ```
159
+
160
+ The daemon re-emits the post on its stdout stream (and pushes via codex-rc if configured), so the peer agent sees a `{"type":"notification",...}` event. Requires the metro daemon to be running on the machine — agent-line sends error with `metro daemon is not running` otherwise.
161
+
162
+ ## Discoverability
163
+
164
+ - `metro lines` — list recently-seen conversations (sorted by recency).
165
+ - `metro stations` — list stations + capability matrix.
166
+ - `metro history` — universal message log (every inbound + outbound + notification across all stations). Newest first. Filters:
167
+ - `--limit=N` (default 50)
168
+ - `--line=<metro://…>` — only this conversation
169
+ - `--station=<discord|telegram|claude|codex>`
170
+ - `--kind=<inbound|outbound|edit|react|notification>`
171
+ - `--from=<sender>`
172
+ - `--text=<substring>`
173
+ - `--since=<iso>` — e.g. `--since=2026-05-14T00:00:00Z`
174
+ - `--json` — machine-parseable
175
+
176
+ Every action you take is logged automatically — `metro send`/`reply`/`edit`/`react` append outbound entries, daemon-side inbounds + notifications append on arrival. Stored at `$METRO_STATE_DIR/history.jsonl`.
177
+
178
+ ## Universal message IDs
179
+
180
+ The `id` from `metro history` or an event JSON works **anywhere a `<message_id>` argument is expected**:
181
+
182
+ ```bash
183
+ # Either form works for reply/edit/react/download:
184
+ metro reply <line> 4567 "ack" # platform messageId (Telegram int)
185
+ metro reply <line> msg_aB3xY7zP "ack" # universal — resolves via history
186
+ ```
187
+
188
+ Use universal IDs when chaining commands or referring back to a specific message across stations.
189
+
190
+ ## Exit codes
191
+
192
+ - `0` success
193
+ - `1` usage error (bad args, unknown subcommand)
194
+ - `2` configuration error (no tokens — tell the user to run `metro setup`)
195
+ - `3` upstream error (rate limit, auth, network) — retry once after a few seconds before surfacing
196
+
197
+ `metro doctor` diagnoses tokens, gateways, dispatcher liveness, and codex-rc target.
198
+
199
+ ## --json output
200
+
201
+ Every command supports `--json` for stable parseable output:
202
+
203
+ ```bash
204
+ metro reply <line> <messageId> "ack" --json
205
+ # {"ok":true,"line":"metro://discord/...","replyTo":"...","messageId":"..."}
206
+
207
+ metro fetch metro://discord/1234 --limit=10 --json
208
+ # {"ok":true,"line":"...","messages":[{"messageId":"...","author":"...","text":"...","timestamp":"..."},...]}
209
+
210
+ metro download <line> <messageId> --json
211
+ # {"ok":true,"line":"...","files":[{"path":"/abs/...png","mediaType":"image/png"}]}
212
+ ```
213
+
214
+ Use `--json` when you need to chain calls or capture the new `messageId` for a later edit.
215
+
216
+ ## Don'ts
217
+
218
+ - ❌ Spawning a second metro daemon — there's one per machine (lockfile-enforced).
219
+ - ❌ Posting to a line that isn't in `metro lines` unless the user gave it to you explicitly.
220
+ - ❌ Narrating the tool ("I'll now use metro reply to…"). The tool call is already visible to the user.