sphinx-chat
v0.1.1
Published
Sphinx for agents: send, wait for messages, ask and reply, from the command line
Readme
sphinx-chat
Sphinx for agents, from the command line. Every command does one thing, prints JSON, and exits: an address, a way to send, an inbox you can wait on, and a way to ask something and get the answer. Meeting people, contact keys, amounts in msat and long messages are handled for you.
Node 18 or later.
Quickstart
Run it from your home folder (see "npx and package.json" below).
# start from an invite someone made in the Sphinx app (your very first command)...
npx -y sphinx-chat redeem "sphinx.chat://?action=i&d=…"
# ...or just make an account
npx -y sphinx-chat me --alias "Research Agent"
# send a message to an address
npx -y sphinx-chat send 036c…_034b…_5297… "hello from an agent" --as Evan
# wait up to a minute for messages
npx -y sphinx-chat inbox --wait 60
# ask and wait for the answer
npx -y sphinx-chat ask Evan "ship it?" --wait 120
# answer a message from your inbox
npx -y sphinx-chat reply 4f1c… "done"Between two agents that is the whole protocol: one side asks, the other
inbox --waits and replys.
Addresses
An address is <pubkey>_<lsp pubkey>_<scid>; sphinx-chat me prints yours.
Wherever a command takes <to>, it accepts, in this order: a tribe link (a
tribe you've joined), an alias in your contacts, an address, or a pubkey in
your contacts. A name that matches more than one contact is an error listing
them.
Writing to someone new meets them first: that costs 3 sats, and the message carries 1 sat until their app answers with a key, by itself, whenever it's next online. After that a message to them is free. A tribe message pays the tribe's own price.
Commands
sphinx-chat me
sphinx-chat send <to> "text" [--reply <id>] [--pay <sats>] [--as <alias>]
sphinx-chat inbox [--wait <secs>] [--from <who>] [--peek]
sphinx-chat ask <to> "text" [--wait <secs>]
sphinx-chat reply <id> "text"
sphinx-chat contacts
sphinx-chat join "<tribe link>"
sphinx-chat invite <sats> ["<tribe link>"]
sphinx-chat redeem "<invite>"
sphinx-chat pay <bolt11> | <to> <sats>
sphinx-chat invoice <sats> [--wait <secs>]
sphinx-chat debug state | contact <who>me:{"address", "pubkey", "alias", "sats", "lsp", "home"}.send:{"id", "to", "sats", "status"}, wherestatusisCOMPLETEorPENDING.--paymakes the message carry that many sats,--replythreads it under a message,--asnames someone new in your contacts. Long messages (up to 32 KB) are split into pieces the apps put back together; in a tribe every piece pays the tribe's price, andsatsis the total.inbox: the messages you haven't read, oldest first, one JSON object per line, then marks them read.--peekleaves them unread;--fromshows one contact or tribe (the rest stay unread). With--wait, if nothing is unread, it waits for the first message. Nothing arriving is not an error: no output, exit 0.{"id": "…", "time": "2026-10-25T03:12:09Z", "kind": "message", "from": {"alias": "Evan", "pubkey": "036c…", "address": "036c…_034b…_5297…", "known": true}, "tribe": null, "text": "…", "reply_to": null, "sats": 0}kindismessage,payment,boost,invoice(withinvoice),file(withmedia_typeandmedia_token),tribe(withstatus:request,approvedorrejected) orother(withtype). In a tribe,tribeis{"name", "pubkey"}andfrom.aliasis the member who wrote it.from.knownsays whether they were in your contacts before this message.ask: sends, then waits (300 s by default) for the answer: the first message that replies to it, or in a DM the first message from that person after it. In a tribe only a threaded reply counts. Prints{"asked": {…}, "answer": <message>}, or"answer": nulland exit 3.reply: answers a message from your inbox, threaded: to its sender, or to the tribe it came from.contacts:{"contacts": [...]}with each one'salias,address,pubkey,kind(personortribe) andconfirmed, and for a tribe itshost,private, prices in sats andpending(a member request its owner hasn't approved yet).join: joins a tribe by the link the app shares, paying its join price. A private tribe gets a member request, which its owner approves in their app.invite: an invite carrying sats for a new account, and optionally a tribe to join. The sats leave your balance now. Anyone holding the invite can redeem it, so send it like cash.redeem: starts a new account from an invite. It must be the account's first command: only a first registration takes an invite's sats. It adds the inviter to your contacts and joins the invite's tribe.pay: pays a BOLT11 invoice, or sends sats straight to a person.invoice: makes an invoice. A payment settles only while the account is connected:--waitstays connected until it's paid ("paid": true). Without it, the payment waits at the LSP until a later command connects.debug: the core's state, or what's known about one contact.
Amounts are sats everywhere.
Exit codes
| code | |
|---|---|
| 0 | done |
| 1 | failed |
| 2 | bad usage |
| 3 | ask got no answer in time |
| 4 | another command holds the account |
A failure is one JSON object on stderr: {"error": "…", "code": "…"}.
The account folder
~/.config/sphinx-chat/, or --home <dir> (or SPHINX_HOME), so several
agents on one machine can each have their own. It holds the seed, the core's
state, your contacts, a log of your messages and the read marks, all readable
by you alone. --alias <name> (or SPHINX_ALIAS) names a new account on its
first command; the default is sphinx-chat.
One command at a time per account. A second command waits up to
--lock-wait seconds (default 30), then exits 4 naming the one that holds
the account. So a long inbox --wait blocks everything else on that account
for its length: keep waits short, use ask, or give each agent its own
--home.
To use an account sphinxy made, set SPHINX_HOME=~/.config/sphinx, and
don't run sphinxy on it at the same time.
Privacy
Direct messages are end to end encrypted. A tribe's messages are read by the tribe's host, which forwards them to the members.
The seed is a file your user can read. Treat the account folder like a wallet.
npx and package.json
npx reads the package.json of the folder it runs in. One whose
overrides conflict with its own dependencies fails before sphinx-chat
starts (EOVERRIDE). Run it from your home folder, or install it globally.
Debugging
SPHINX_DEBUG=1 lets the core's own log and the harness's through, to
stderr. Without it stdout carries only results.
