@peer2peer/cli 0.1.4 → 0.1.5
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/README.md +7 -6
- package/dist/app.d.ts +8 -0
- package/dist/app.js +35 -9
- package/dist/circle-ops.js +2 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +11 -3
- package/dist/outbox.d.ts +2 -4
- package/dist/outbox.js +12 -3
- package/dist/relay-client.d.ts +8 -0
- package/dist/relay-client.js +7 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# p2p: the Peer2Peer CLI
|
|
2
2
|
|
|
3
|
-
`@peer2peer/cli` is the standalone `p2p` command for [Peer2Peer v3](https://github.com/ix-infrastructure/Peer2Peer/blob/v0.1.
|
|
3
|
+
`@peer2peer/cli` is the standalone `p2p` command for [Peer2Peer v3](https://github.com/ix-infrastructure/Peer2Peer/blob/v0.1.5/docs/protocol.md). It gives you an identity with no account, friends and circles, end-to-end encrypted messages between agent sessions, and live session status. Everything goes over open relays that anyone can run.
|
|
4
4
|
|
|
5
5
|
It is core software: it never imports Ix or an extension (`node scripts/check-boundaries.mjs`).
|
|
6
6
|
|
|
7
7
|
## Two friends in two minutes
|
|
8
8
|
|
|
9
|
-
You need a relay. Run your own (`npx @peer2peer/relay`, see [run-a-relay.md](https://github.com/ix-infrastructure/Peer2Peer/blob/v0.1.
|
|
9
|
+
You need a relay. Run your own (`npx @peer2peer/relay`, see [run-a-relay.md](https://github.com/ix-infrastructure/Peer2Peer/blob/v0.1.5/docs/run-a-relay.md)), or use one your community runs. No relay is built in yet. Tell `p2p` about it once:
|
|
10
10
|
|
|
11
11
|
```sh
|
|
12
12
|
export P2P_DEFAULT_RELAYS=wss://relay.example.org/v3 # 1–5, comma separated
|
|
@@ -29,7 +29,7 @@ p2p join relay.example.org/K7QM-3XPD-9TWA-HF2N-6RJC # you and ann@k7f2-qx9a-3m
|
|
|
29
29
|
|
|
30
30
|
If Ann has a default circle (`p2p circle default <cid>`) that she owns or administers, the code joins Ben to it as well, and it becomes his default circle. Ann's client adds him the next time it runs (at once, when a `watch` is running), and tells her `ben@… joined via your code K7QM… ("ben")`. If that isn't who she meant, `p2p remove <userId>` undoes it. The code works once and lives 7 days at most. The long-link form (`p2p invite --link` / `p2p accept <link>`) still works.
|
|
31
31
|
|
|
32
|
-
**Share a project and talk.** A session is shared with nobody until you share the project it works in (a git repository, or a folder): see [projects](https://github.com/ix-infrastructure/Peer2Peer/blob/v0.1.
|
|
32
|
+
**Share a project and talk.** A session is shared with nobody until you share the project it works in (a git repository, or a folder): see [projects](https://github.com/ix-infrastructure/Peer2Peer/blob/v0.1.5/docs/concepts.md#projects-project-boundaries).
|
|
33
33
|
|
|
34
34
|
```sh
|
|
35
35
|
# Ben, in his repository (and Ann, in hers: `p2p project share --person ben`):
|
|
@@ -61,6 +61,7 @@ On a terminal, `p2p` alone and `p2p relays` connect to your own relays (bounded)
|
|
|
61
61
|
|
|
62
62
|
| Command | What it does |
|
|
63
63
|
|---|---|
|
|
64
|
+
| `version [--json]` | CLI version, protocol minor, advertised capabilities and Node.js version. Works offline without an identity. `--version` still prints only the package version. |
|
|
64
65
|
| `setup [--name n] [--relay url]… [--backup-file [path] \| --print-backup \| --no-backup] [--ix] [--sandbox]` | The friendly `init`: the name defaults to your OS user name, and relays come from the defaults. Interactively it offers to save the backup phrase to a 0600 file (default `<home>/backup-phrase.txt`, never overwritten) or print it. It is idempotent: on a home that already has an identity it changes nothing and reports `created: false`. **Ix is optional and recommended; Peer2Peer never installs it for you.** Without the Ix CLI, setup at your terminal says what Ix adds and asks `Install Ix? [y/N]` (default No): a yes prints the install command for you to run yourself, a no is remembered (`"ixDeclined": true` in config.json) and not asked again; `--ix` asks again. It never offers Ix with `--json`, with `CI` set, without a terminal, or inside an agent's session; `--json` reports `ix.installed`, `ix.recommended` and `ix.install` (the command) instead. With Ix and `@peer2peer/ext-ix` both installed, a new install (or `--ix`) asks you on your terminal (or takes the Claude mod's typed `/peers setup`) before enabling the `ix` extension; never from inside an agent's session. An existing install is never changed silently: it gets a one-time notice at a terminal instead. |
|
|
65
66
|
| `sandbox` / `sandbox enable [--claude] [--codex] [--yes] [--codex-base read-only\|workspace]` | Whether your agents' sandboxes (Claude Code, Codex) deny their commands read and write access to `P2P_HOME`, and the fix (`sandbox`, read-only; `doctor` shows the same, with the session's project settings and, on Linux, bubblewrap). `sandbox enable` adds the deny to your own config, asking about each agent on its own (what changes, how to undo it, exactly what is written; default Yes): Claude Code's user `settings.json` (`sandbox.enabled`, `autoAllowBashIfSandboxed: false` unless you set it, `allowUnsandboxedCommands: false`, `filesystem.denyRead`/`denyWrite`, and `Read`/`Edit` deny rules) and Codex's `config.toml` (a permissions profile, never broader than your current sandbox, that denies `P2P_HOME`; with no sandbox configured it extends `:read-only` unless `--codex-base workspace`). Each file is backed up beside itself (`<file>.p2p-backup-<time>`, 0600), nothing is written if it changed after it was shown, everything else is kept, and a second run changes nothing. `setup` at your terminal, and `codex install --write`, offer it once; a no is remembered per agent (`"sandboxDeclined"` in config.json) and `setup --sandbox` (or `sandbox enable`) asks again. Only you run it, in your own terminal: refused inside an agent's session, when p2p can't read its process tree, from a front end even with its token, and with `--yes` on Windows. See docs/security/threat-model.md. |
|
|
66
67
|
| `init [--name n] [--relay url]… [--yes]` | Creates the identity key and the first device (a key holder), and publishes document v1. It strongly prompts for a backup or a second key holder (§2.5). `--yes` skips the prompt but still warns. |
|
|
@@ -94,7 +95,7 @@ On a terminal, `p2p` alone and `p2p relays` connect to your own relays (bounded)
|
|
|
94
95
|
| `history [--session <sid>\|--inbox] [--peer <user>] [--circle <cid>] [--since 30m\|12h\|7d\|<date>] [--limit n] [--clear]` | Messages this device sent and received, oldest first (the newest `--limit`, default 50): message text in and out, and extension kinds as their one-line fallback (never the body). Kept only on this device, sealed with ChaCha20-Poly1305 under a key of its own (`cli/history.key`, 0600), for `history.retentionDays` (default 30) and at most `history.maxBytes` (default 8 MiB) in config.json, pruned on every write; `"enabled": false` or `P2P_HISTORY=0` keeps nothing new, and `--clear` deletes it all with its key, and the messages still in `events.json` (the event log `watch` reads). Past the cap the oldest go first, whoever sent them. A record's `at` is when it arrived here (`sentAt`: the sender's time). Writes are copy-on-write and reads take the state lock, so a crash loses at most what was being written; an older segment put back is never taken back in (the index names each with its hash and the next unused number, and keeps a copy, `history-mark.json`). A file that can't be opened is set aside (`history.bad-*`, said on stderr) at the next write, never shown; the text output caps each record at 4,000 characters. Nothing goes to a relay or a peer. With no `--session` (everything) or with `--inbox` (messages to you: session `tui`, or no session), it is the person's: their front end's token, or their `yes` typed on the controlling terminal, and refused inside an agent's session. `--session <sid>` is that session's own history: its front end reads it for a session a front end registered, and only what it recorded since that binding began, in projects the session is still bound to (a record kept with no binding is the person's only); without the token only the person at their terminal can. Message text is the sender's data: one line each, sanitized for the terminal. |
|
|
95
96
|
| `receipts [on\|off]` | Whether this user sends delivery receipts (on by default; `"receipts": false` in config.json, `P2P_RECEIPTS=0` overrides). On by default, which is a presence signal: statuses advertise `receipts.v1` to everyone who sees them, and a `shown` tells a sender when the message reached the session's model. Off, no receipt goes out and statuses stop advertising `receipts.v1`, so senders see what an older client looks like. |
|
|
96
97
|
| `status --session <sid> --state busy\|idle [--summary] [--file]… [--label] [--repo] [--branch] [--mode] [--cap]… [--agents-json <json\|->] [--project-dir d]…` | `--project-dir` (and `P2P_PROJECT_DIRS`, `P2P_WORKDIR`): folders the session works in; each binds it to that project, which only narrows who sees it (a device file such as `/dev/null` binds nothing). `--project-dirs-over[=unresolved,folders,front]` (and `P2P_PROJECT_DIRS_OVER`): the front end couldn't resolve a path, dropped folders past its cap, or lost track; the session is private, and the refusal names the cause (a bare flag or an unknown word is `front`). `P2P_SESSION_SCRATCH` (JSON `{sid, tmp, config, job}`, read only from a front end with the person token): Claude Code's own folders for this session (`<tmp>/claude-<uid>/<project>/<sid>`, `<config>/projects/<project>/<sid>`, its job folder); a path there binds no project, checked on real paths by the exact id, and a symlink there binds its target (docs/concepts.md). A private session sends no summary. Sends a `status` envelope to everyone the roster allows. Safe to run every 60 s. A status carries the CLI's own caps (`status.tolerant.v1`, `agents.v1`, `xstate.v1`, `proto.3.1`) and `--cap` adds what the calling client understands. `--agents-json` (a JSON array, `-` reads it from stdin) is the session's subagents (§4.3 "Status agents"): normalized (at most 8, each at most 10 repo-relative files, an 80-character task), sent as `agents` only to users whose live sessions all advertise `agents.v1`, and as a `(+N agents)` summary to everyone else (`delivered[].agents` says which). `P2P_STATUS_CAPS=0` (or `"statusCaps": false` in config.json) opts out, for peers on clients older than the §4.3 "Status caps" amendment: the status then carries only the original fields, and `--cap` is left out with a warning, never an error. `ls --json` rows and watch lines carry each session's `caps` and `agents`. |
|
|
97
|
-
| `project share [<circle>…] [--person u]… [--add] [--subfolders] [--dir d]`, `project private`, `project ls`, `project show` | Who sees sessions working in a project (a git repository, or a folder): private until shared (see [projects](https://github.com/ix-infrastructure/Peer2Peer/blob/v0.1.
|
|
98
|
+
| `project share [<circle>…] [--person u]… [--add] [--subfolders] [--dir d]`, `project private`, `project ls`, `project show` | Who sees sessions working in a project (a git repository, or a folder): private until shared (see [projects](https://github.com/ix-infrastructure/Peer2Peer/blob/v0.1.5/docs/concepts.md#projects-project-boundaries)). `share` with nothing named: a picker on a terminal, else your default circle. `--subfolders` (a folder outside git): the share covers its subfolders too, never past a repository, a `.p2p-private` or a folder with its own policy. It is refused for `/`, a home folder, a temporary or a system folder, and it warns about the repositories and `.p2p-private` folders below. Without it the share is for that folder alone (`--add` keeps what the share had). A committed `.p2p-private` makes a repository private; nothing in a repository can share it |
|
|
98
99
|
| `session show <sid>` | Read only: the session's bound projects, each one's policy (a folder project lists the subfolders it covered), who the session reaches, and every reason it is private with what helps (a share, or a new session when the cause lasts until it ends: a cap, an unresolved path, a dropped front end, `.p2p-private`). Yours only: refused inside an agent's session without the front end's token, so no agent reads another session's bindings. |
|
|
99
100
|
| `session roster <sid> [--circle cid\|--private] [--add u]… [--remove u]…` | Who may see and message a session, within what its project shares (`not_shared` past it). Until changed here, a session follows its project's policy (§6), also when that changes after the session started; a running session never moves into an open circle by itself (it stays private, with a warning). |
|
|
100
101
|
| `watch --session <sid> --jsonl` | One JSON line per accepted event. Stays connected and reconnects silently. |
|
|
@@ -159,7 +160,7 @@ The cursor (`<home>/cursors/<sid>.cursor`) advances only after a line reaches st
|
|
|
159
160
|
| `P2P_DEVICE_INFO` / `deviceInfo` in config.json | Off by default. On, a key-holding device keeps its caps and version in your identity document (`dinfo`), on relays that list `identity.lenient`. Clients from before protocol 3.1 refuse a document with it, so it stays off until the previous two releases are 3.1 (docs/compatibility.md, step 2). |
|
|
160
161
|
| `P2P_DRAIN_QUIET_MS`, `P2P_DRAIN_MAX_MS`, `P2P_DOC_REFRESH_SEC`, `P2P_LINK_POLL_MS` | Timing knobs, mostly for tests. |
|
|
161
162
|
|
|
162
|
-
**Keys.**
|
|
163
|
+
**Keys.** By default, device keys and the identity key on key holders are kept in a 0600 file in `<home>/cli`. Run `p2p keys backend keychain` in your own terminal to move them into the OS keychain, or `p2p keys backend file` to move them back. Save your backup phrase first; see the [OS keychain guide](https://github.com/ix-infrastructure/Peer2Peer/blob/v0.1.5/docs/keychain.md) and [threat model](https://github.com/ix-infrastructure/Peer2Peer/blob/v0.1.5/docs/security/threat-model.md#keys-in-the-os-keychain).
|
|
163
164
|
|
|
164
165
|
**Forks.** When two key holders publish at once, your document forks (§2.5). The next version this CLI publishes first merges the tips, pairwise for three or more, with the intersection of devices and key holders, `by` this device or else the lowest common key holder. It then re-adds any device a merge dropped that wasn't revoked, so a device linked during a fork isn't lost. It re-adds a device only when this device holds each branch's history back to their common ancestor; otherwise it warns you to link that device again rather than guess. A merge's `by` is nominal (a common key holder): the device that wrote it records it as its own, and a merge adds nothing, so no device's "versions I didn't publish" check alerts on it. If the branches share no key holder, it refuses and recommends rotation.
|
|
165
166
|
|
|
@@ -332,7 +333,7 @@ Without a user, it checks this device:
|
|
|
332
333
|
- Ix: the `ix` binary and its version, whether the Ix extension is enabled, the local backend (`<endpoint>/v1/health` reachable), whether the project here is mapped (`ix status`), and the **graph target** of the project here and of each project with a policy: `local only` today (see the threat model's "Graph targets"). Without Ix nothing here is a failure. `ix` runs by absolute path with an allowlisted environment and the local endpoint pinned (Ix's default, or a loopback `ixEndpoint` in config.json; never `IX_ENDPOINT`/`IX_PAT` from the environment);
|
|
333
334
|
- the CLI's version against the one the Claude mod bundles (found from `P2P_MOD_ROOT`, which the mod sets, or the plugin folder around a bundled `p2p.mjs`).
|
|
334
335
|
|
|
335
|
-
After the checks, **Where your data goes** says, for this device, what travels end-to-end encrypted (messages, statuses, receipts) and some of what a relay still sees (metadata, including who may reach whom, which mailboxes, sizes, timing, kind and session id, IPs, your identity document, and a circle's chain on a members-only relay that admits it; the threat model has all of it); that message history stays on this device, encrypted at rest with its key beside it, and that the event log keeps recent messages in the clear; whether graph memory is on; and each project's graph target (the same rule and wording as `p2p project show`), with the reminder that the local Ix backend keeps what it gets in plaintext. See [What is encrypted, what isn't](https://github.com/ix-infrastructure/Peer2Peer/blob/v0.1.
|
|
336
|
+
After the checks, **Where your data goes** says, for this device, what travels end-to-end encrypted (messages, statuses, receipts) and some of what a relay still sees (metadata, including who may reach whom, which mailboxes, sizes, timing, kind and session id, IPs, your identity document, and a circle's chain on a members-only relay that admits it; the threat model has all of it); that message history stays on this device, encrypted at rest with its key beside it, and that the event log keeps recent messages in the clear; whether graph memory is on; and each project's graph target (the same rule and wording as `p2p project show`), with the reminder that the local Ix backend keeps what it gets in plaintext. See [What is encrypted, what isn't](https://github.com/ix-infrastructure/Peer2Peer/blob/v0.1.5/docs/security/encryption.md). In `--json` it is `dataFlow`: `wire`, `history`, `graphMemory {on: true | false | "unknown", detail}` ("unknown" when Ix didn't answer in time: `p2p watch` may still be writing), `graphs[] {id, name, here, target, line, plaintext}`, `graphsNotListed`, `anyShared` and `doc`.
|
|
336
337
|
|
|
337
338
|
With `<user>` (an address, petname, name or userId), it checks whether you can see them: friendship or the circles you both stand in; their identity document, fetched now and fresh; the relays they list and whether you share one you reach; whether you hold a capability for their relays and they hold one from you for yours (as far as this device's records tell); when anything last arrived from them; whether they're blocked, suspended (a contested key move) or held; and whether the sessions they shared include you, and are live. It then lists each of their devices with its protocol minor (and exact client version only when the device publishes one in `dinfo`) and the caps it advertises (from its identity document entry, else its latest status), and the features unavailable between you, in words, never as a failure (docs/compatibility.md); `--json` adds `devices` and `unavailable`.
|
|
338
339
|
|
package/dist/app.d.ts
CHANGED
|
@@ -82,6 +82,8 @@ export interface Delivery {
|
|
|
82
82
|
codes: string[];
|
|
83
83
|
}[];
|
|
84
84
|
}
|
|
85
|
+
/** At most this many other caps ride along with a send target (relay-client.ts SendTarget.fallback). */
|
|
86
|
+
export declare const MAX_FALLBACK_CAPS = 3;
|
|
85
87
|
export declare class App {
|
|
86
88
|
/** The person's front end vouched for this command (P2P_PERSON_TOKEN, checked once and removed: projects.ts). */
|
|
87
89
|
front: boolean;
|
|
@@ -408,6 +410,12 @@ export declare class App {
|
|
|
408
410
|
selfCap(): string;
|
|
409
411
|
/** Caps we hold that let us reach `to` with `kind`, by relay (best first). */
|
|
410
412
|
capsFor(to: string, kind: string, extra?: readonly string[]): Promise<Map<string, string>>;
|
|
413
|
+
/**
|
|
414
|
+
* Every cap we hold that lets us reach `to` with `kind`, by relay, best first. The best one can be
|
|
415
|
+
* dead at the relay while a later one works: a friend cap revoked by a block (an unblock issues no
|
|
416
|
+
* new one) next to a co-member's join cap, and the order between them is only their expiry (#127).
|
|
417
|
+
*/
|
|
418
|
+
capChoicesFor(to: string, kind: string, extra?: readonly string[]): Promise<Map<string, string[]>>;
|
|
411
419
|
/** Records a cap this device issued, so it can be revoked later (§5.3). */
|
|
412
420
|
recordIssued(capJws: string): Promise<StoredCapV3>;
|
|
413
421
|
/** Sends `revoke` for each cap to every relay it names. */
|
package/dist/app.js
CHANGED
|
@@ -42,6 +42,10 @@ export const CLOSE_GRACE_MS = 3000;
|
|
|
42
42
|
const FETCHED_SLACK_MS = 5000;
|
|
43
43
|
export const REPUBLISH_DOC_WITHIN_SEC = 7 * 86_400;
|
|
44
44
|
const CAP_PRIORITY = (c) => (c.kinds[0] === "*" ? 0 : 1);
|
|
45
|
+
/** At most this many other caps ride along with a send target (relay-client.ts SendTarget.fallback). */
|
|
46
|
+
export const MAX_FALLBACK_CAPS = 3;
|
|
47
|
+
/** Send targets as stored and reported (the outbox, `unsent`): each relay's best cap, without the fallbacks. */
|
|
48
|
+
const firstCaps = (targets) => targets.map((t) => ({ relay: t.relay, ...(t.cap !== undefined ? { cap: t.cap } : {}) }));
|
|
45
49
|
export class App {
|
|
46
50
|
/** The person's front end vouched for this command (P2P_PERSON_TOKEN, checked once and removed: projects.ts). */
|
|
47
51
|
front = false;
|
|
@@ -1149,6 +1153,14 @@ export class App {
|
|
|
1149
1153
|
}
|
|
1150
1154
|
/** Caps we hold that let us reach `to` with `kind`, by relay (best first). */
|
|
1151
1155
|
async capsFor(to, kind, extra = []) {
|
|
1156
|
+
return new Map([...(await this.capChoicesFor(to, kind, extra))].map(([r, caps]) => [r, caps[0]]));
|
|
1157
|
+
}
|
|
1158
|
+
/**
|
|
1159
|
+
* Every cap we hold that lets us reach `to` with `kind`, by relay, best first. The best one can be
|
|
1160
|
+
* dead at the relay while a later one works: a friend cap revoked by a block (an unblock issues no
|
|
1161
|
+
* new one) next to a co-member's join cap, and the order between them is only their expiry (#127).
|
|
1162
|
+
*/
|
|
1163
|
+
async capChoicesFor(to, kind, extra = []) {
|
|
1152
1164
|
const now = nowSec();
|
|
1153
1165
|
const cands = [];
|
|
1154
1166
|
if (to === this.userId) {
|
|
@@ -1177,12 +1189,20 @@ export class App {
|
|
|
1177
1189
|
cands.push({ jws: j, relays: p.relays, kinds: p.kinds, exp: p.exp });
|
|
1178
1190
|
}
|
|
1179
1191
|
const usable = cands.filter((c) => c.exp > now + 60 && capAllowsKind(c.kinds, kind)).sort((a, b) => CAP_PRIORITY(a) - CAP_PRIORITY(b) || b.exp - a.exp);
|
|
1192
|
+
// One entry per cap id: the same cap held twice (say, as held and as a join cap) is no fallback.
|
|
1180
1193
|
const out = new Map();
|
|
1181
|
-
for (const c of usable)
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1194
|
+
for (const c of usable) {
|
|
1195
|
+
const id = capPeek(c.jws)?.capid ?? c.jws;
|
|
1196
|
+
for (const r of c.relays) {
|
|
1197
|
+
const e = out.get(r) ?? { jws: [], ids: new Set() };
|
|
1198
|
+
if (e.ids.has(id))
|
|
1199
|
+
continue;
|
|
1200
|
+
e.ids.add(id);
|
|
1201
|
+
e.jws.push(c.jws);
|
|
1202
|
+
out.set(r, e);
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
return new Map([...out].map(([r, e]) => [r, e.jws]));
|
|
1186
1206
|
}
|
|
1187
1207
|
/** Records a cap this device issued, so it can be revoked later (§5.3). */
|
|
1188
1208
|
async recordIssued(capJws) {
|
|
@@ -1221,7 +1241,7 @@ export class App {
|
|
|
1221
1241
|
for (const e of res.errors)
|
|
1222
1242
|
errors.push({ did: outgoing[i].d, relay: e.relay, code: e.code, ...(e.written ? { written: true } : {}) });
|
|
1223
1243
|
if (res.sent.length === 0)
|
|
1224
|
-
unsent.push({ did: outgoing[i].d, env: outgoing[i].env, targets, codes: res.errors.map((e) => e.code) });
|
|
1244
|
+
unsent.push({ did: outgoing[i].d, env: outgoing[i].env, targets: firstCaps(targets), codes: res.errors.map((e) => e.code) });
|
|
1225
1245
|
}
|
|
1226
1246
|
return { userId: to, devices: sealed, relays: [...sentVia], ...(errors.length > 0 ? { errors } : {}), ...(unsent.length > 0 ? { unsent } : {}) };
|
|
1227
1247
|
}
|
|
@@ -1231,7 +1251,7 @@ export class App {
|
|
|
1231
1251
|
*/
|
|
1232
1252
|
async seal(to, kind, session, plaintext, opts = {}) {
|
|
1233
1253
|
const { targets, outgoing } = await this.sealCopies(to, kind, session, plaintext, opts);
|
|
1234
|
-
return outgoing.map(({ d, env }) => ({ did: d, env, targets }));
|
|
1254
|
+
return outgoing.map(({ d, env }) => ({ did: d, env, targets: firstCaps(targets) }));
|
|
1235
1255
|
}
|
|
1236
1256
|
async sealCopies(to, kind, session, plaintext, opts) {
|
|
1237
1257
|
const view = to === this.userId ? await this.ownView() : await this.viewFor(to, { refresh: opts.refresh, hint: opts.hint });
|
|
@@ -1241,7 +1261,7 @@ export class App {
|
|
|
1241
1261
|
// receipt for one): sealed to itself and sent through a relay like any other copy.
|
|
1242
1262
|
const devices = view.devices.filter((d) => (to !== this.userId || d !== this.did || opts.onlyDevices?.includes(d) === true) && (!opts.onlyDevices || opts.onlyDevices.includes(d)));
|
|
1243
1263
|
const relays = orderRelays(view.head.relays, view.relays).slice(0, 3);
|
|
1244
|
-
const caps = await this.
|
|
1264
|
+
const caps = await this.capChoicesFor(to, kind, opts.extraCaps);
|
|
1245
1265
|
const resolveCert = storeCertResolver(this.store);
|
|
1246
1266
|
const errors = [];
|
|
1247
1267
|
// Certificates first (each verified, as before), then one seq block for every copy, then the
|
|
@@ -1263,7 +1283,13 @@ export class App {
|
|
|
1263
1283
|
const seqs = ready.length > 0 ? await this.state.nextSeqs(session.own, session.sid, ready.length) : [];
|
|
1264
1284
|
if (opts.beforeSend && ready.length > 0)
|
|
1265
1285
|
await opts.beforeSend(ready.map((r, i) => ({ did: r.d, seq: seqs[i] })));
|
|
1266
|
-
const targets = relays
|
|
1286
|
+
const targets = relays
|
|
1287
|
+
.map((r) => {
|
|
1288
|
+
const [cap, ...rest] = caps.get(r) ?? [];
|
|
1289
|
+
const fallback = rest.slice(0, MAX_FALLBACK_CAPS);
|
|
1290
|
+
return { relay: r, cap, ...(fallback.length > 0 ? { fallback } : {}) };
|
|
1291
|
+
})
|
|
1292
|
+
.filter((t) => t.cap !== undefined || kind === "contact");
|
|
1267
1293
|
const outgoing = [];
|
|
1268
1294
|
for (const [i, { d, kpk }] of ready.entries()) {
|
|
1269
1295
|
const env = sealEnvelopeV3({
|
package/dist/circle-ops.js
CHANGED
|
@@ -730,7 +730,8 @@ export async function joinCircle(app, input, opts = {}) {
|
|
|
730
730
|
if (exp)
|
|
731
731
|
await sendSync(app, { circles: [exp] });
|
|
732
732
|
if (!delivered.some((d) => d.relays.length > 0) && targets.length > 0) {
|
|
733
|
-
|
|
733
|
+
const codes = [...new Set(delivered.flatMap((d) => (d.errors ?? []).map((e) => e.code)))];
|
|
734
|
+
throw new CliError("undelivered", `joined locally, but the join was delivered via 0 relays${codes.length ? ` (${codes.join(", ")})` : ""}: the owner doesn't know yet`, { cid });
|
|
734
735
|
}
|
|
735
736
|
return {
|
|
736
737
|
...base,
|
package/dist/cli.d.ts
CHANGED
|
@@ -257,7 +257,7 @@ export declare const realOps: {
|
|
|
257
257
|
}>;
|
|
258
258
|
removeUser(app: App, who: string): Promise<codes.RemoveResult>;
|
|
259
259
|
CODE_LABEL_MAX: 64;
|
|
260
|
-
codeHint: (code: string
|
|
260
|
+
codeHint: (code: string) => string;
|
|
261
261
|
PLUGIN_INSTALL: string[];
|
|
262
262
|
CODEX_INSTALL_URL: "https://github.com/ix-infrastructure/Peer2Peer/blob/main/packages/codex-bridge/README.md#install";
|
|
263
263
|
CodePreviewReady: typeof codes.CodePreviewReady;
|
package/dist/cli.js
CHANGED
|
@@ -41,6 +41,7 @@ import { tuiCommand } from "./tui/command.js";
|
|
|
41
41
|
import { TUI_SESSION } from "./tui/tui.js";
|
|
42
42
|
import * as pretty from "./pretty.js";
|
|
43
43
|
import { VERSION } from "./version.js";
|
|
44
|
+
import { CLI_CAPS, PROTO_MINOR } from "./features.js";
|
|
44
45
|
export { VERSION };
|
|
45
46
|
/** How long a command that ran out of time waits for in-flight sends and writes to settle. */
|
|
46
47
|
export const SETTLE_MS = 5000;
|
|
@@ -209,6 +210,13 @@ export function buildProgram(deps) {
|
|
|
209
210
|
.enablePositionalOptions()
|
|
210
211
|
.exitOverride()
|
|
211
212
|
.configureOutput({ writeOut: (s) => io.out(s.replace(/\n$/, "")), writeErr: (s) => io.err(s.replace(/\n$/, "")) });
|
|
213
|
+
program.command("version")
|
|
214
|
+
.description("Show CLI, protocol and runtime versions without opening an identity")
|
|
215
|
+
.option("--json", "JSON output")
|
|
216
|
+
.action((o) => {
|
|
217
|
+
const info = { version: VERSION, protocol: "p2p/v3", protoMinor: PROTO_MINOR, caps: [...CLI_CAPS], node: process.version };
|
|
218
|
+
io.out(o.json ? safeJson(info) : `p2p ${VERSION} · protocol 3.${PROTO_MINOR} · node ${process.version}\n${CLI_CAPS.join(", ")}`);
|
|
219
|
+
});
|
|
212
220
|
/** Runs one command: JSON or human output, exit code 1 on failure. */
|
|
213
221
|
const run = (fn, opts = {}) => async (...args) => {
|
|
214
222
|
const cmd = args[args.length - 1];
|
|
@@ -2303,10 +2311,10 @@ export async function main(argvIn, deps) {
|
|
|
2303
2311
|
// `p2p` alone on a terminal: the home screen. Piped, it prints the help as before.
|
|
2304
2312
|
if (argv.length === 0 && deps.io.pretty && !deps.noInput)
|
|
2305
2313
|
argv = ["home"];
|
|
2306
|
-
//
|
|
2314
|
+
// Built-in inspections need no extension: loading one records where it came from
|
|
2307
2315
|
// (<home>/extension-locations.json) and runs its code, so it is skipped.
|
|
2308
|
-
const
|
|
2309
|
-
const extensions = deps.extensions ?? (
|
|
2316
|
+
const isInspection = ["doctor", "version"].includes(argv.find((a) => !a.startsWith("-")) ?? "");
|
|
2317
|
+
const extensions = deps.extensions ?? (isInspection ? new ExtensionRegistry() : await loadInstalled(deps));
|
|
2310
2318
|
const program = buildProgram({ ...deps, extensions });
|
|
2311
2319
|
process.exitCode = 0;
|
|
2312
2320
|
try {
|
package/dist/outbox.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type App } from "./app.js";
|
|
2
|
+
import type { SendTarget } from "./relay-client.js";
|
|
2
3
|
export declare const OUTBOX_TTL_MS: number;
|
|
3
4
|
export declare const OUTBOX_PER_RECIPIENT = 10;
|
|
4
5
|
export declare const OUTBOX_MAX = 200;
|
|
@@ -102,8 +103,5 @@ export type RoundViews = Map<string, Promise<{
|
|
|
102
103
|
* ones it was sealed for, each with a cap of this moment.
|
|
103
104
|
*/
|
|
104
105
|
export declare function stillAllowed(app: App, item: OutboxItem, views?: RoundViews): Promise<{
|
|
105
|
-
targets:
|
|
106
|
-
relay: string;
|
|
107
|
-
cap?: string;
|
|
108
|
-
}[];
|
|
106
|
+
targets: SendTarget[];
|
|
109
107
|
} | "refused" | "later">;
|
package/dist/outbox.js
CHANGED
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
// while this device's own relays answered are expired early: their relays answer but refuse.
|
|
33
33
|
import { createHash } from "node:crypto";
|
|
34
34
|
import { CircleChain, decodeEnvelopeV3, liveFriendshipsV3, REPLAY_WINDOW } from "@peer2peer/core/v3";
|
|
35
|
-
import { orderRelays } from "./app.js";
|
|
35
|
+
import { MAX_FALLBACK_CAPS, orderRelays } from "./app.js";
|
|
36
36
|
import { CliError } from "./errors.js";
|
|
37
37
|
import { makeEvent } from "./inbound.js";
|
|
38
38
|
import { sessKey } from "./state.js";
|
|
@@ -330,8 +330,17 @@ export async function stillAllowed(app, item, views = new Map()) {
|
|
|
330
330
|
return "refused";
|
|
331
331
|
relays = orderRelays(own.head.relays, own.relays).slice(0, 3);
|
|
332
332
|
}
|
|
333
|
-
|
|
333
|
+
// Every cap of this moment, each relay's best first and the others as fallbacks: a queued copy
|
|
334
|
+
// whose best cap was revoked meanwhile (a block and an unblock) still goes on a live one (#127).
|
|
335
|
+
const caps = await app.capChoicesFor(to, item.kind);
|
|
334
336
|
const candidates = [...new Set([...relays, ...item.targets.map((t) => t.relay)])];
|
|
335
|
-
const targets = candidates
|
|
337
|
+
const targets = candidates
|
|
338
|
+
.filter((r) => (caps.get(r)?.length ?? 0) > 0)
|
|
339
|
+
.slice(0, 3)
|
|
340
|
+
.map((r) => {
|
|
341
|
+
const [cap, ...rest] = caps.get(r);
|
|
342
|
+
const fallback = rest.slice(0, MAX_FALLBACK_CAPS);
|
|
343
|
+
return { relay: r, cap, ...(fallback.length > 0 ? { fallback } : {}) };
|
|
344
|
+
});
|
|
336
345
|
return targets.length > 0 ? { targets } : "refused";
|
|
337
346
|
}
|
package/dist/relay-client.d.ts
CHANGED
|
@@ -86,6 +86,14 @@ export interface SendTarget {
|
|
|
86
86
|
relay: string;
|
|
87
87
|
/** The recipient's cap naming this relay; without one only `contact` goes, with PoW. */
|
|
88
88
|
cap?: string;
|
|
89
|
+
/**
|
|
90
|
+
* Other caps we hold for this relay (each a different cap id), next best first. When the relay
|
|
91
|
+
* refuses `cap` with `undeliverable` (also what a revoked cap gets), the first of them is tried
|
|
92
|
+
* once, so one dead cap doesn't lose a send a live one would carry (#127). A second refusal
|
|
93
|
+
* means the cause isn't the cap (an unknown mailbox, a full store, a recipient not admitted),
|
|
94
|
+
* and every retry spends the relay's send budgets again: no further cap is tried.
|
|
95
|
+
*/
|
|
96
|
+
fallback?: readonly string[];
|
|
89
97
|
}
|
|
90
98
|
export interface SendResult {
|
|
91
99
|
/** Relays that answered `sent`. */
|
package/dist/relay-client.js
CHANGED
|
@@ -607,7 +607,13 @@ export class RelayPool {
|
|
|
607
607
|
}
|
|
608
608
|
// From here the frame goes onto an open connection (request refuses a closed one first).
|
|
609
609
|
written = conn.isOpen;
|
|
610
|
-
|
|
610
|
+
let r = await conn.request(frame);
|
|
611
|
+
// A refused cap stored nothing: one other cap we hold for this relay may still work.
|
|
612
|
+
const next = t.fallback?.find((c) => c !== frame.cap);
|
|
613
|
+
if (r.t !== "sent" && relayCode(r.code ?? r.t) === "undeliverable" && next !== undefined) {
|
|
614
|
+
frame.cap = next;
|
|
615
|
+
r = await conn.request(frame);
|
|
616
|
+
}
|
|
611
617
|
if (r.t === "sent")
|
|
612
618
|
res.sent.push(t.relay);
|
|
613
619
|
else
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.1.
|
|
1
|
+
export declare const VERSION = "0.1.5";
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peer2peer/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "The standalone Peer2Peer v3 CLI (`p2p`): an account-free identity, friends, circles, end-to-end encrypted session messaging and status over open relays",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"peer2peer",
|
|
@@ -53,11 +53,11 @@
|
|
|
53
53
|
"registry": "https://registry.npmjs.org/"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@peer2peer/codex-bridge": "0.1.
|
|
57
|
-
"@peer2peer/core": "0.1.
|
|
56
|
+
"@peer2peer/codex-bridge": "0.1.5",
|
|
57
|
+
"@peer2peer/core": "0.1.5",
|
|
58
58
|
"commander": "15.0.0",
|
|
59
59
|
"uqr": "0.1.3",
|
|
60
|
-
"ws": "8.
|
|
60
|
+
"ws": "8.23.0"
|
|
61
61
|
},
|
|
62
62
|
"overrides": {
|
|
63
63
|
"minimatch": "^11.0.8"
|