Skip to content

feat: add simple pay and receive commands#40

Merged
rolznz merged 6 commits into
masterfrom
feat/simple-pay-receive
May 29, 2026
Merged

feat: add simple pay and receive commands#40
rolznz merged 6 commits into
masterfrom
feat/simple-pay-receive

Conversation

@rolznz
Copy link
Copy Markdown
Member

@rolznz rolznz commented May 29, 2026

Closes #30

Makes it easier for AI - less likely to make mistakes and not have to handle invoices when paying to lightning addresses.

Also added a receive command - an easy way for the agent to know how it can receive money via lightning address or invoice.

Summary by CodeRabbit

  • New Features

    • Added pay command with auto-detection for BOLT-11 invoices, lightning addresses, keysend pubkeys, and EVM addresses.
    • Added receive command to generate BOLT-11 invoices or retrieve lightning address.
  • Breaking Changes

    • pay-crypto command now requires explicit --currency and --network flags; defaults removed.
  • Documentation

    • Updated README with new command descriptions and usage examples.
    • Added agent workflow documentation.
  • Tests

    • Added comprehensive test coverage for new pay and receive commands.
    • Extended pay-crypto validation tests.

Review Change Stack

@rolznz rolznz requested review from bumi and reneaaron May 29, 2026 07:27
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 29, 2026

Warning

Review limit reached

@rolznz, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 29 minutes and 41 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fc4a00e3-e0e6-402d-aa45-892acbdcf1dc

📥 Commits

Reviewing files that changed from the base of the PR and between 1f627ca and bdc5fa5.

📒 Files selected for processing (5)
  • CLAUDE.md
  • README.md
  • src/commands/pay-crypto.ts
  • src/commands/pay.ts
  • src/test/pay-command.test.ts
📝 Walkthrough

Walkthrough

This PR introduces a unified pay command with destination-type auto-detection, a new receive command for generating invoices or returning lightning addresses, makes pay-crypto options required, and wires both commands into the CLI with comprehensive validation tests and documentation.

Changes

Unified Payment Commands

Layer / File(s) Summary
Destination type detection and validation logic
src/commands/pay.ts (1–60)
Regex patterns and helper functions detect destination type (BOLT-11, lightning address, keysend pubkey, EVM address) and validate that user-provided CLI options match the detected type; rejects mismatched options.
Unified pay command with multi-destination routing
src/commands/pay.ts (61–253), src/test/pay-command.test.ts
Implements pay CLI command that routes validated payments to payInvoice, requestInvoiceFromLightningAddress, payKeysend (with optional TLVs), or payCrypto (with EVM validation). Includes destination detection unit tests, validation error cases, and live integration tests for invoice, lightning address, and keysend flows.
Receive command for lightning address or invoice generation
src/commands/receive.ts, src/test/receive-command.test.ts
Implements receive CLI command that returns wallet lightning address (default) or generates BOLT-11 invoice (when --amount provided). Validates mutual dependencies and positive amounts. Includes validation and live integration tests confirming address/invoice generation with correct sats amounts.
Pay-crypto required options enforcement
src/commands/pay-crypto.ts, src/test/pay-crypto.test.ts
Changes --currency and --network from optional to required options. Updates tests to include complete required options in validation checks and adds tests verifying rejection when required options are missing.
CLI command registration and help text updates
src/index.ts
Imports and registers pay and receive commands with the CLI program and updates top-level help/usage examples to show new command invocations.
Documentation and agent workflow guidance
AGENTS.md, README.md
Adds AGENTS.md with instructions to use package.json scripts. Updates README to replace pay-invoice example with unified pay, documents new receive command behavior, expands pay documentation for destination-type auto-detection and per-type flags.

Sequence Diagram

sequenceDiagram
  participant User as CLI User
  participant Pay as pay command
  participant Detect as detectDestinationType
  participant Validate as rejectUnusedOpts
  participant Router as destination router
  participant PayInvoice as payInvoice
  participant RequestInvoice as requestInvoiceFromLightningAddress
  participant PayKeysend as payKeysend
  participant PayCrypto as payCrypto

  User->>Pay: pay <destination> [--amount] [--currency] [--network] ...
  Pay->>Detect: analyze destination string
  Detect-->>Pay: type: invoice|lightning-address|keysend|crypto
  Pay->>Validate: check that provided flags match type
  alt options valid
    Validate-->>Pay: options approved
    Pay->>Router: route by destination type
    alt type is BOLT-11 invoice
      Router->>PayInvoice: payInvoice(invoice, amount?)
      PayInvoice-->>Pay: success, preimage
    else type is lightning-address
      Router->>RequestInvoice: requestInvoiceFromLightningAddress(address, amount, metadata)
      RequestInvoice-->>Router: fetched invoice
      Router->>PayInvoice: payInvoice(invoice, metadata)
      PayInvoice-->>Pay: success, preimage
    else type is keysend pubkey
      Router->>PayKeysend: payKeysend(pubkey, amount, tlv_records?)
      PayKeysend-->>Pay: success
    else type is EVM address
      Router->>PayCrypto: payCrypto(address, amount, currency, network, callback)
      PayCrypto-->>Pay: swap_id, status, target
    end
  else options invalid
    Validate-->>Pay: error: rejected option
    Pay-->>User: exit with error
  end
  Pay-->>User: output result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • getAlby/cli#39: Implements the pay-crypto atomic-swap command that this PR integrates with via the unified pay command and updates to make --currency and --network required options.

Suggested reviewers

  • bumi
  • reneaaron

Poem

🐰 With paws on the keyboard, I write with delight,
A unified pay command that routes payment just right!
Auto-detect destinations, from invoices to swaps,
And receive brings addresses—no missing the stops!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: add simple pay and receive commands' directly and clearly summarizes the main changes: two new CLI commands (pay and receive) are introduced, which aligns with the primary objective of simplifying payments and receiving funds.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/simple-pay-receive

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/commands/pay.ts (1)

22-28: ⚡ Quick win

Invoice detection is intentionally limited to lnbc...

pay only auto-detects BOLT-11 invoices when the destination starts with lnbc (/^lnbc/i), and the help text/tests/docs also explicitly state “BOLT-11 invoice (starts with lnbc)”, so non-lnbc prefixes (e.g., lntb.../lntbs...) will be treated as “Could not detect destination type”. If supporting those networks is a desired enhancement, broaden the prefix match (e.g., include lntb/lntbs) as an optional follow-up.

🔧 Optional broadening
-  if (/^lnbc/i.test(destination)) return "invoice";
+  if (/^ln(bc|tb|tbs|bcrt)/i.test(destination)) return "invoice";
🤖 Prompt for 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.

In `@src/commands/pay.ts` around lines 22 - 28, The invoice detection in
detectDestinationType currently only matches /^lnbc/i and so misses other
BOLT‑11 prefixes like lntb/lntbs; to support those, broaden the invoice regex
used in detectDestinationType (the branch that currently tests /^lnbc/i) to also
match lntb and lntbs (e.g., a single combined pattern matching ln(bc|tb|tbs)
case-insensitively) and update related help/tests/docs that state “starts with
lnbc” to reflect the additional accepted prefixes if you want this behavior
enabled.
🤖 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 `@README.md`:
- Around line 127-128: The README EVM pay example and description are incorrect:
for EVM destinations the CLI requires both --currency and --network (see
src/commands/pay.ts), so update the sentence and the example to mark --currency
and --network as required and show a full command using them (e.g., npx
`@getalby/cli` pay 0xabc... --amount 10 --currency USDC --network arbitrum);
ensure the wording explicitly states these flags are mandatory for EVM addresses
and aligns with the validation in the pay command implementation.

In `@src/commands/pay.ts`:
- Around line 133-150: The "invoice" case in the switch allows non-positive
integers because it only validates Number.isInteger(options.amount); update the
validation in the "invoice" branch (inside the case "invoice" block that calls
getClient(...) and payInvoice(...)) to also require options.amount > 0 (mirror
the positivity guard used in the "lightning-address" and "keysend" branches),
and throw the same Invalid --amount error when the amount is missing or <= 0
before calling payInvoice.

---

Nitpick comments:
In `@src/commands/pay.ts`:
- Around line 22-28: The invoice detection in detectDestinationType currently
only matches /^lnbc/i and so misses other BOLT‑11 prefixes like lntb/lntbs; to
support those, broaden the invoice regex used in detectDestinationType (the
branch that currently tests /^lnbc/i) to also match lntb and lntbs (e.g., a
single combined pattern matching ln(bc|tb|tbs) case-insensitively) and update
related help/tests/docs that state “starts with lnbc” to reflect the additional
accepted prefixes if you want this behavior enabled.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: c8caa03c-0839-4079-a78e-0c2cd7749c44

📥 Commits

Reviewing files that changed from the base of the PR and between 3084f84 and 1f627ca.

📒 Files selected for processing (9)
  • AGENTS.md
  • README.md
  • src/commands/pay-crypto.ts
  • src/commands/pay.ts
  • src/commands/receive.ts
  • src/index.ts
  • src/test/pay-command.test.ts
  • src/test/pay-crypto.test.ts
  • src/test/receive-command.test.ts

Comment thread README.md Outdated
Comment thread src/commands/pay.ts
Copy link
Copy Markdown
Contributor

@bumi bumi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice. looks good.

Comment thread src/commands/pay.ts Outdated
@rolznz rolznz merged commit fba5232 into master May 29, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add generic pay command

2 participants