feat(transport): Phase 3 — auto-detection + get-dm v2 + docs#178
Conversation
|
Warning Review limit reached
More reviews will be available in 45 minutes and 14 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
WalkthroughPhase 3 of Transport V2 is implemented: ChangesTransport V2 Phase 3: capability auto-detection
Sequence Diagram(s)sequenceDiagram
participant CLI as mostro-cli
participant Net as connect_nostr
participant Events as fetch_protocol_version_with
participant Relay as Nostr Relay
CLI->>Net: connect_nostr(relays)
Net->>Relay: add_relays + connect()
Net->>Relay: wait_for_connection(CONNECT_TIMEOUT)
Relay-->>Net: handshake complete
Net-->>CLI: client (ready)
CLI->>CLI: resolve_transport(client, mostro_pubkey)
alt TRANSPORT env var set
CLI-->>CLI: use explicit transport, return
else no explicit transport
CLI->>Events: fetch_protocol_version_with(client, pubkey)
Events->>Relay: fetch kind-38385 event (INFO_PROBE_TIMEOUT)
Relay-->>Events: info event or timeout
Events-->>CLI: Some(version) or None
alt version == 2
CLI-->>CLI: set TRANSPORT=nip44
else version == 1 / unknown / None
CLI-->>CLI: default to gift-wrap
end
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5e4f4f13a6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Phase 3 of docs/TRANSPORT_V2_SPEC.md — completes the CLI's transport-v2 support. - Auto-detection: `events::fetch_protocol_version_with` reads the node's `protocol_versions` tag (kind-38385 info event) with a short INFO_PROBE_TIMEOUT. `init_context` → `resolve_transport` runs it once at startup when `--transport`/`TRANSPORT` is unset: "2" → TRANSPORT=nip44; "1"/absent/unreachable → leave unset (messaging defaults to gift-wrap). An explicit `--transport` is authoritative and skips the probe. A pre-v2 daemon publishes no tag, so the CLI stays on v1 instead of mis-pairing (backward-compat guard for the version-skew risk Phase 1 flagged). - get-dm listing is transport-aware: `create_filter` for the DirectMessages* kinds now uses `transport.event_kind()` and pins `author = mostro_pubkey` on v2 (new `mostro_pubkey` param threaded through call sites), closing the Phase 2 gap. - Verbose: `resolve_transport` logs the active transport and how it was chosen. - Docs: docs/commands.md gains a Global options section documenting `--transport` + auto-detection; spec marked complete. Tests: deterministic `protocol_versions` tag read/parse. Full suite green; clippy --all-targets --all-features -D warnings and fmt clean. Based on Phase 2 (#177). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
5e4f4f1 to
9906f2c
Compare
connect() only spawns background connection tasks; firing subscribe/ send_dm immediately raced the handshake and dropped Mostro's reply, surfacing as "Timeout waiting for DM". Block on wait_for_connection so auto-detection and the DM round-trip run against a live relay. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/cli.rs`:
- Around line 508-511: The early return condition for the TRANSPORT environment
variable in the if let Ok(explicit) block treats any present value, including
empty strings or whitespace, as explicit and short-circuits auto-detection. This
is inconsistent with how parse_transport_env handles empty values. Modify the
logic to check if the explicit value is empty or contains only whitespace after
retrieving it from std::env::var("TRANSPORT"), and only return early if the
value is non-empty and meaningful. If the value is empty or whitespace-only,
allow the code to continue to auto-detection instead of returning early.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 66d5314b-da6f-4247-8817-08c474833203
📒 Files selected for processing (5)
docs/TRANSPORT_V2_SPEC.mddocs/commands.mdsrc/cli.rssrc/util/events.rssrc/util/net.rs
…rsion
Client and node are compatible only when they run the same protocol
version, so the kind-38385 info tag carries a single value ("1" or "2"),
not a list. Rename the tag everywhere the CLI reads/documents it to match
the daemon and protocol spec.
NOTE: must land together with the matching mostrod + protocol changes;
the daemon still emits the old tag name until then.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
resolve_transport short-circuited on any present TRANSPORT value, but parse_transport_env only honors a non-empty, trimmed value. So `TRANSPORT=""` (e.g. `--transport ""`) skipped auto-detection and left the var empty, silently pairing a v2 node to the gift-wrap default. Only short-circuit on a meaningful value; fall through to auto-detect otherwise. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Phase 3 of
docs/TRANSPORT_V2_SPEC.md— capability auto-detection + UX/docsCompletes the CLI's transport-v2 support: the operator no longer needs
--transport, theget-dmhistorical listing works on v2, and the transport is surfaced/documented.What changed
events::fetch_protocol_version_withreads the node'sprotocol_versionstag from its kind-38385 info event (shortINFO_PROBE_TIMEOUT = 5sso a node without one degrades fast).init_context→resolve_transportruns it once at startup when--transport/TRANSPORTis unset:"2"→ setTRANSPORT=nip44;"1"/ absent / unreachable → leave unset, so the messaging layer keeps the gift-wrap default.--transportis authoritative and skips the probe entirely.protocol_versionstag, so auto-detect leaves the CLI on gift-wrap (v1) rather than silently mis-pairing — this is the version-skew guard Phase 1 flagged.--transportstill forces either side.get-dmlisting is transport-aware.create_filterfor theDirectMessages*kinds now usestransport.event_kind()and, on v2, pinsauthor = mostro_pubkey(newmostro_pubkeyparam threaded through its 6 call sites). Closes the Phase 2 known gap — listing past Mostro DMs works on a v2 node.resolve_transportlogs the active transport and how it was chosen (explicit/auto-detected protocol vN/ default fallback) atinfo(shown with-v).docs/commands.mdgains a Global options section documenting--transport(and the other global flags); the spec is marked complete.Tests
protocol_versionstag read + parse (mirrors the existingpowprobe test). Auto-detect wiring + the v2create_filterauthor-pin are integration-level (live relay/node) and covered by the manual checks below.cargo clippy --all-targets --all-features -D warnings+cargo fmt --checkclean.🧪 Manual testing — step by step
Needs a Mostro daemon on mostro-core 0.13 reachable on a relay.
1. Auto-detect a v2 node (no
--transport)transport = "nip44"in the daemon'ssettings.toml; restart.--transport, verbose:Transport: nip44 (auto-detected protocol v2), and the command works (kind-14 traffic). A fullnewordr → takesell/takebuy → addinvoice → fiatsent → releaseround-trips without ever passing--transport. ✔️2. Auto-detect a v1 node
transport = "gift-wrap"(or use a default node); restart.mostro-cli -v … listorderswithout--transport.Transport: gift-wrap (auto-detected protocol v1)(or the "could not detect … defaulting to gift-wrap" line if the node publishes no info event), and behaviour is identical to today. ✔️3. Explicit override wins (skips the probe)
mostro-cli -v --transport gift-wrap … listorders.Transport: gift-wrap (explicit)— no probe — and (since the node only listens on kind 14) the command times out. Re-run with--transport nip44or no flag → works. Confirms the flag is authoritative. ✔️4.
get-dmlisting on v2mostro-cli --transport nip44 … getdm(or omit--transportto auto-detect).5. Pre-v2 daemon / unreachable node
--transport) at a node that publishes no kind-38385 info event (or an unreachable relay).Could not detect node transport … defaulting to gift-wrap, and the CLI proceeds on v1 — no hang for the full 15s fetch timeout, no mis-pairing. ✔️🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
--transportin most cases.Documentation
--transportauto-detection behavior.