@peer2peer/cli 0.1.1 → 0.1.3

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/dist/doctor.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { App } from "./app.js";
2
2
  import { type PeerDevice } from "./features.js";
3
+ import { type GraphMemoryDoc } from "./graph-memory.js";
4
+ import { type GraphTarget } from "./projects.js";
3
5
  export type CheckStatus = "ok" | "fail" | "unknown";
4
6
  export interface Check {
5
7
  id: string;
@@ -30,6 +32,61 @@ export interface DoctorResult {
30
32
  theyLack: string[];
31
33
  weLack: string[];
32
34
  };
35
+ /** This device: where each kind of data goes ("Where your data goes"). */
36
+ dataFlow?: DataFlow;
37
+ }
38
+ /** The threat model, which lists everything a relay sees. */
39
+ export declare const THREAT_MODEL_DOC = "docs/security/threat-model.md";
40
+ /** What is encrypted and what isn't, on one page. */
41
+ export declare const ENCRYPTION_DOC = "docs/security/encryption.md";
42
+ /**
43
+ * Some of what a relay sees besides an envelope's ciphertext (the threat model, "What each party can
44
+ * see", has the full list): never read as complete.
45
+ */
46
+ export declare const RELAY_METADATA: readonly string[];
47
+ /**
48
+ * Where each kind of data goes, as `p2p doctor` says it for this device. Facts, not checks: the
49
+ * graph targets come from projects.ts (graphTarget's rule, the same as `p2p project show`).
50
+ */
51
+ export interface DataFlow {
52
+ /** Messages, statuses, receipts, rosters and Ix items shared with peers: end-to-end encrypted envelopes. */
53
+ wire: {
54
+ encryption: "end-to-end";
55
+ relaysSee: "ciphertext and metadata"; /** Some of it, not all: `doc` has the full list. */
56
+ metadata: readonly string[];
57
+ doc: string;
58
+ };
59
+ /** Message history (history.ts): never leaves this device; sealed at rest, with its key beside it. */
60
+ history: {
61
+ where: "this device only";
62
+ recording: boolean;
63
+ encryptedAtRest: true;
64
+ keyBesideIt: true;
65
+ eventLogPlaintextDays: number;
66
+ };
67
+ /**
68
+ * Graph memory (graph-memory.ts): on only with Ix, the Ix extension, and an Ix with a local `ix note`.
69
+ * `on` is "unknown" when the doctor couldn't tell (`ix --help` didn't answer in time): `p2p watch`
70
+ * may still be writing, and `detail` says what it wrote and queued so far.
71
+ */
72
+ graphMemory: {
73
+ on: boolean | "unknown";
74
+ detail: string;
75
+ };
76
+ /** Each project's graph target (the project here first), at most MAX_GRAPH_ROWS of them. */
77
+ graphs: {
78
+ id: string;
79
+ name: string;
80
+ here: boolean;
81
+ target: GraphTarget;
82
+ line: string;
83
+ plaintext: string;
84
+ }[];
85
+ /** Projects not listed past MAX_GRAPH_ROWS. */
86
+ graphsNotListed: number;
87
+ /** Whether any listed project's target is a shared (cloud) graph. None today: every target is local. */
88
+ anyShared: boolean;
89
+ doc: string;
33
90
  }
34
91
  export interface DoctorOptions {
35
92
  /** The CLI's own version (cli.ts VERSION). */
@@ -96,6 +153,8 @@ export declare function clockVerdict(skews: readonly {
96
153
  relay: string;
97
154
  sec: number;
98
155
  }[]): Check;
156
+ /** "Where your data goes" for this device (no probes: what the code does, and this device's settings). */
157
+ export declare function dataFlowOf(app: Pick<App, "env" | "home">, ix: Pick<DataFlow, "graphMemory" | "graphs" | "graphsNotListed">): DataFlow;
99
158
  /**
100
159
  * The Ix section: the binary and its version, the local backend (reachable at the local endpoint),
101
160
  * whether the project here is mapped, and the graph target of the project here and of each project
@@ -103,11 +162,21 @@ export declare function clockVerdict(skews: readonly {
103
162
  * `ix` runs as ext-ix runs it (ix-local.ts): absolute path, allowlisted environment, the local
104
163
  * endpoint pinned, read-only commands, bounded.
105
164
  */
106
- export declare function ixChecks(c: Checks, app: App, ms: number): Promise<void>;
165
+ export declare function ixChecks(c: Checks, app: App, ms: number): Promise<Pick<DataFlow, "graphMemory" | "graphs" | "graphsNotListed">>;
166
+ /**
167
+ * Graph memory's state for "Where your data goes", from what Ix answered (`support`: undefined when it
168
+ * didn't in time) and what `p2p watch` recorded. Not knowing is "unknown", never "off": the watch
169
+ * asks Ix itself and may be writing.
170
+ */
171
+ export declare function graphMemoryState(support: "oss" | "pro" | "none" | undefined, doc: Pick<GraphMemoryDoc, "written" | "queue"> | undefined, endpoint: string): DataFlow["graphMemory"];
107
172
  export declare function summarize(checks: readonly Check[]): DoctorResult["summary"];
108
173
  /** The doctor's per-step bound: P2P_DOCTOR_TIMEOUT_MS (default 5 s), never more than the connect timeout. */
109
174
  export declare function doctorTimeoutMs(app: App, override?: number): number;
110
175
  export declare function doctor(app: App, o: DoctorOptions): Promise<DoctorResult>;
111
- /** Human output: one line per check (✓ ✗ ?), with its fix indented below. */
176
+ /** The heading of the data-flow section (pretty.ts styles it). */
177
+ export declare const DATA_FLOW_HEADING = "Where your data goes";
178
+ /** "Where your data goes", in plain words: one line per kind of data, then one per project's graph. */
179
+ export declare function formatDataFlow(d: DataFlow): string[];
180
+ /** Human output: one line per check (✓ ✗ ?), with its fix indented below, then where data goes. */
112
181
  export declare function formatDoctor(r: DoctorResult): string;
113
182
  export {};
package/dist/doctor.js CHANGED
@@ -21,11 +21,16 @@
21
21
  // bounded (P2P_DOCTOR_TIMEOUT_MS, default 5 s, never more than the connect
22
22
  // timeout), and so is every local step, so the command can't hang. Nothing
23
23
  // secret is ever in the output: no keys, caps, invite or link codes, envelopes.
24
+ //
25
+ // For this device it ends with "Where your data goes" (dataFlow): what travels end-to-end
26
+ // encrypted and what a relay still sees, where message history is kept, and per project the graph
27
+ // target (projects.ts graphTarget's rule, as `p2p project show` prints it) and that Ix keeps what it
28
+ // gets in plaintext.
24
29
  import { readdirSync, statSync } from "node:fs";
25
30
  import { readFile, stat } from "node:fs/promises";
26
31
  import { dirname, join } from "node:path";
27
32
  import { fileURLToPath } from "node:url";
28
- import { capAllowsKind, daysPastExp, decodeTyped, DEFAULT_SKEW_SEC, displayAddress, identityFreshness, isLive, isUserId, liveFriendshipsV3, nowSec, peekIdentityDoc, sanitizePeerText, TYP3, unfriendApplies, refreshIdentity as coreRefreshIdentity, } from "@peer2peer/core/v3";
33
+ import { capAllowsKind, daysPastExp, decodeTyped, DEFAULT_SKEW_SEC, displayAddress, identityFreshness, isLive, isUserId, liveFriendshipsV3, nowSec, peekIdentityDoc, sanitizePeerText, TYP3, unfriendApplies, pendingHeadSenders, refreshIdentity as coreRefreshIdentity, } from "@peer2peer/core/v3";
29
34
  import { App, capPeek, joinCapOf, orderRelays, REPUBLISH_DOC_WITHIN_SEC } from "./app.js";
30
35
  import { CAP_PROJECTS, CLI_CAPS, KNOWN_FEATURES, peerDevices, unavailableBetween } from "./features.js";
31
36
  import { circleMembers, listCircles } from "./circle-ops.js";
@@ -33,11 +38,32 @@ import { defaultRelays } from "./config.js";
33
38
  import { CliError } from "./errors.js";
34
39
  import { readCapped, RelayConnection } from "./relay-client.js";
35
40
  import { rosterAudience, sessionRef } from "./sessions.js";
41
+ import { EVENT_RETENTION_MS } from "./state.js";
36
42
  import { enabledNamespaces } from "./extensions.js";
37
- import { extIxInstalled, ixBinary, IX_INSTALL_URL, ixMemorySupport, ixVersion, runIx } from "./ix-local.js";
43
+ import { extIxInstalled, ixBinary, ixDeclined, IX_INSTALL_URL, ixInstallLine, ixMemorySupport, ixVersion, runIx } from "./ix-local.js";
44
+ import { personHere } from "./projects.js";
38
45
  import { graphMemoryReport } from "./graph-memory.js";
39
46
  import { graphMemoryEnabled } from "./config.js";
40
- import { describeGraphTarget, listProjects, localGraphEndpoint, projectOf, projectsDoc, projectGraphTarget, sessionWorkdir } from "./projects.js";
47
+ import { historySettings } from "./history.js";
48
+ import { graphPlaintextNote, graphTargetLine, listProjects, localGraphEndpoint, projectOf, projectsDoc, projectGraphTarget, sessionWorkdir } from "./projects.js";
49
+ /** The threat model, which lists everything a relay sees. */
50
+ export const THREAT_MODEL_DOC = "docs/security/threat-model.md";
51
+ /** What is encrypted and what isn't, on one page. */
52
+ export const ENCRYPTION_DOC = "docs/security/encryption.md";
53
+ /**
54
+ * Some of what a relay sees besides an envelope's ciphertext (the threat model, "What each party can
55
+ * see", has the full list): never read as complete.
56
+ */
57
+ export const RELAY_METADATA = [
58
+ "who may reach whom (capabilities)",
59
+ "which mailboxes send to which",
60
+ "sizes",
61
+ "timing",
62
+ "each envelope's kind and session id",
63
+ "IP addresses",
64
+ "your public identity document",
65
+ "on a members-only relay that admits a circle's members, that circle's signed chain (its name, owner, admins and members)",
66
+ ];
41
67
  /**
42
68
  * Clock skew. Signed objects (device certificates, documents, caps, invites, statements) are
43
69
  * refused when their `iat` is more than DEFAULT_SKEW_SEC (300 s) ahead of the verifier's clock,
@@ -390,6 +416,33 @@ async function versionCheck(c, app, o, ms) {
390
416
  async function circlesOf(app, ms) {
391
417
  return (await bounded(listCircles(app), ms)).value ?? [];
392
418
  }
419
+ /**
420
+ * #78: newer versions of our own identity this device holds as pending heads, with the listed relays that
421
+ * sent them. While one of those relays doesn't answer, edits and the key holder's renewal are refused
422
+ * (App.ownPendingGuard), so the document can lapse: name the relays this probe couldn't reach, and the fix.
423
+ * Local data only (no refresh).
424
+ */
425
+ async function pendingHeadsCheck(c, app, view, reports, ms) {
426
+ const stored = (await bounded(app.store.getIdentity(app.userId), ms)).value;
427
+ if (!stored)
428
+ return;
429
+ const above = pendingHeadSenders(stored).filter((p) => p.ver > view.head.ver && p.relays.some((r) => view.relays.includes(r)));
430
+ if (above.length === 0)
431
+ return;
432
+ const newest = Math.max(...above.map((p) => p.ver));
433
+ const senders = [...new Set(above.flatMap((p) => p.relays.filter((r) => view.relays.includes(r))))];
434
+ const down = senders.filter((r) => reports.find((x) => x.relay === r)?.reachable === false);
435
+ const what = `this device holds version ${newest} of your identity, newer than its head (version ${view.head.ver}), from ${senders.join(", ")}`;
436
+ if (down.length === 0 && senders.some((r) => !reports.some((x) => x.relay === r))) {
437
+ c.add("pending-heads", "unknown", "newer versions of your identity", `${what}; not probed here`, "run `p2p doctor` again; if one of them stays unreachable, edits and renewals are refused until it answers or you remove it (`p2p relays remove <url>`)");
438
+ return;
439
+ }
440
+ if (down.length === 0) {
441
+ c.add("pending-heads", "ok", "newer versions of your identity", `${what}; ${senders.length === 1 ? "it answers" : "they answer"}, so your next edit or renewal fetches it`);
442
+ return;
443
+ }
444
+ c.add("pending-heads", "fail", "newer versions of your identity", `${what}; ${down.join(", ")} ${down.length === 1 ? "doesn't" : "don't"} answer, so edits and renewing your identity document are refused until ${down.length === 1 ? "it answers" : "they answer"}`, `wait for ${down.length === 1 ? "it" : "them"} to come back; if ${down.length === 1 ? "it is" : "they are"} gone for good, or no device of yours published that version: \`p2p relays remove ${down.join(" ")}\``);
445
+ }
393
446
  async function deviceChecks(c, app, o, ms, reports) {
394
447
  const view = (await bounded(app.view(app.userId), ms)).value;
395
448
  const name = view?.head.name ?? app.self?.name ?? "?";
@@ -414,6 +467,7 @@ async function deviceChecks(c, app, o, ms, reports) {
414
467
  c.add("document-fork", "fail", "identity document history", "forked (two versions claim the same place)", "run `p2p identity republish` on a key holder: it merges the branches");
415
468
  if (view.rotations.length > 0)
416
469
  c.add("document-rotated", "fail", "identity", "this identity moved to a new key", "follow it: `p2p held` shows the move (approve it there), or re-link with `p2p link join <code> --rotated`");
470
+ await pendingHeadsCheck(c, app, view, reports, ms);
417
471
  }
418
472
  relayChecks(c, app, reports, view ? { hash: view.head.hash, ver: view.head.ver } : undefined);
419
473
  clockCheck(c, reports);
@@ -500,8 +554,19 @@ async function deviceChecks(c, app, o, ms, reports) {
500
554
  if (dropped > 0) {
501
555
  c.add("inbound", "unknown", "incoming envelopes", `${dropped} couldn't be applied and ${dropped === 1 ? "was" : "were"} dropped after failing for good (or every attempt)`, "if messages from someone seem missing, ask them to send again; P2P_DEBUG=1 on `p2p ls` shows why one fails");
502
556
  }
503
- await ixChecks(c, app, ms);
557
+ const ix = await ixChecks(c, app, ms);
504
558
  await versionCheck(c, app, o, ms);
559
+ return dataFlowOf(app, ix);
560
+ }
561
+ /** "Where your data goes" for this device (no probes: what the code does, and this device's settings). */
562
+ export function dataFlowOf(app, ix) {
563
+ return {
564
+ wire: { encryption: "end-to-end", relaysSee: "ciphertext and metadata", metadata: RELAY_METADATA, doc: THREAT_MODEL_DOC },
565
+ history: { where: "this device only", recording: historySettings(app).enabled, encryptedAtRest: true, keyBesideIt: true, eventLogPlaintextDays: Math.round(EVENT_RETENTION_MS / 86_400_000) },
566
+ ...ix,
567
+ anyShared: ix.graphs.some((g) => g.target.kind === "shared"),
568
+ doc: ENCRYPTION_DOC,
569
+ };
505
570
  }
506
571
  // ---------------------------------------------------------------------------
507
572
  // Ix (epic #41): the local CLI, its backend, this checkout's map, and each project's graph target
@@ -519,8 +584,12 @@ export async function ixChecks(c, app, ms) {
519
584
  const target = { endpoint: local };
520
585
  const bin = ixBinary(app.env);
521
586
  const on = enabledNamespaces(app.env, app.file).enabled.includes("ix");
587
+ let memory;
522
588
  if (!bin) {
523
- c.add("ix", "unknown", "Ix", "the Ix CLI isn't installed (Peer2Peer works without it; peers' Ix items show as plain text)", `install Ix (${IX_INSTALL_URL}), then \`p2p extensions enable ix\``);
589
+ memory = { on: false, detail: "off: Ix isn't installed" };
590
+ c.add("ix", "unknown", "Ix", `the Ix CLI isn't installed: it is optional (Peer2Peer works without it; peers' Ix items show as plain text)${ixDeclined(app.file) ? ", and you said no to it at setup" : ""}`, personHere(app)
591
+ ? `optional and recommended; Peer2Peer never installs it. To add it, run \`${ixInstallLine()}\` yourself (${IX_INSTALL_URL}), then \`p2p setup --ix\``
592
+ : `optional and recommended; installing it is your user's decision, never yours: ask your user whether they want it; they run \`${ixInstallLine()}\` in their own terminal, then \`p2p setup --ix\``);
524
593
  }
525
594
  else {
526
595
  const v = (await bounded(ixVersion(bin, app.env, target, ms), ms + 500)).value;
@@ -532,8 +601,7 @@ export async function ixChecks(c, app, ms) {
532
601
  c.add("ix-extension", "ok", "Ix extension", "enabled: sessions can share Ix context");
533
602
  else
534
603
  c.add("ix-extension", "unknown", "Ix extension", "not enabled", extIxInstalled(app.env) ? "`p2p extensions enable ix`" : "`npm i -g @peer2peer/ext-ix`, then `p2p extensions enable ix`");
535
- if (on)
536
- await graphMemoryChecks(c, app, bin, target, ms);
604
+ memory = on ? await graphMemoryChecks(c, app, bin, target, ms) : { on: false, detail: "off: the Ix extension isn't enabled" };
537
605
  // Never followed elsewhere: a loopback listener that redirects is not the local backend.
538
606
  const h = await httpProbe(`${local}/v1/health`, ms, { noRedirect: true });
539
607
  if (h.ok && h.status !== undefined && h.status < 500)
@@ -567,12 +635,17 @@ export async function ixChecks(c, app, ms) {
567
635
  for (const p of all)
568
636
  if (!rows.some((r) => r.id === p.id))
569
637
  rows.push({ id: p.id, name: p.name });
638
+ const graphs = [];
570
639
  for (const r of rows.slice(0, MAX_GRAPH_ROWS)) {
571
640
  const t = projectGraphTarget(app, r, doc);
572
- c.add(`graph:${r.id}`, "ok", `graph of project ${peer(r.name)}${r.id === here.id ? " (here)" : ""}`, `${describeGraphTarget(t)}${t.kind === "local" ? `: ${t.why}` : ""}`);
641
+ const line = graphTargetLine(t);
642
+ graphs.push({ id: r.id, name: peer(r.name), here: r.id === here.id, target: t, line, plaintext: graphPlaintextNote(t) });
643
+ c.add(`graph:${r.id}`, "ok", `graph of project ${peer(r.name)}${r.id === here.id ? " (here)" : ""}`, line);
573
644
  }
574
- if (rows.length > MAX_GRAPH_ROWS)
575
- c.add("graph:more", "ok", "graphs of other projects", `${rows.length - MAX_GRAPH_ROWS} more not listed (run \`p2p project show\` in each)`);
645
+ const more = Math.max(0, rows.length - MAX_GRAPH_ROWS);
646
+ if (more > 0)
647
+ c.add("graph:more", "ok", "graphs of other projects", `${more} more not listed (run \`p2p project show\` in each)`);
648
+ return { graphMemory: memory, graphs, graphsNotListed: more };
576
649
  }
577
650
  /**
578
651
  * Graph memory (graph-memory.ts): whether this Ix has the OSS `ix note` (local) or Ix Pro's (cloud,
@@ -582,7 +655,7 @@ export async function ixChecks(c, app, ms) {
582
655
  async function graphMemoryChecks(c, app, bin, target, ms) {
583
656
  if (!graphMemoryEnabled(app.env, app.home)) {
584
657
  c.add("ix-memory", "ok", "Ix graph memory", 'off ("ixMemory": false in config.json, or P2P_IX_MEMORY=0)');
585
- return;
658
+ return { on: false, detail: 'off ("ixMemory": false in config.json, or P2P_IX_MEMORY=0)' };
586
659
  }
587
660
  const support = (await bounded(ixMemorySupport(bin, app.env, target, ms), ms + 500)).value;
588
661
  const doc = (await bounded(graphMemoryReport(app), ms)).value;
@@ -609,6 +682,22 @@ async function graphMemoryChecks(c, app, bin, target, ms) {
609
682
  }
610
683
  if (app.file.ixTrustRootListener === true)
611
684
  c.add("ix-memory-root", "ok", "Ix graph memory", 'a root-owned listener on the local port counts as yours ("ixTrustRootListener": true in config.json)');
685
+ return graphMemoryState(support, doc, target.endpoint);
686
+ }
687
+ /**
688
+ * Graph memory's state for "Where your data goes", from what Ix answered (`support`: undefined when it
689
+ * didn't in time) and what `p2p watch` recorded. Not knowing is "unknown", never "off": the watch
690
+ * asks Ix itself and may be writing.
691
+ */
692
+ export function graphMemoryState(support, doc, endpoint) {
693
+ if (support === "oss")
694
+ return { on: true, detail: `on: your sessions in shared projects are recorded in the local graph only (${endpoint})` };
695
+ if (support === "pro")
696
+ return { on: false, detail: "off: Ix Pro is installed (its `ix note` writes to the cloud), so nothing is written" };
697
+ if (support === "none")
698
+ return { on: false, detail: "off: this Ix has no local `ix note`" };
699
+ const counts = doc ? `${doc.written} written, ${doc.queue.length} queued` : "nothing written yet";
700
+ return { on: "unknown", detail: `unknown: couldn't tell whether this Ix has a local \`ix note\`; ${counts} (to the local graph only, ${endpoint})` };
612
701
  }
613
702
  // ---------------------------------------------------------------------------
614
703
  // About another user
@@ -852,8 +941,8 @@ export async function doctor(app, o) {
852
941
  }
853
942
  const reports = await probeRelays(app, app.relays, ms, true, app.userId);
854
943
  if (scope === "device") {
855
- await deviceChecks(c, app, o, ms, reports);
856
- return { scope, version: o.version, checks: c.list, summary: summarize(c.list) };
944
+ const dataFlow = await deviceChecks(c, app, o, ms, reports);
945
+ return { scope, version: o.version, checks: c.list, summary: summarize(c.list), dataFlow };
857
946
  }
858
947
  // About a user: who they are first (a userId needn't be known yet).
859
948
  const input = o.user.trim();
@@ -867,8 +956,8 @@ export async function doctor(app, o) {
867
956
  return { scope, version: o.version, user: { input }, checks: c.list, summary: summarize(c.list) };
868
957
  }
869
958
  if (userId === app.userId) {
870
- await deviceChecks(c, app, o, ms, reports);
871
- return { scope: "device", version: o.version, user: { input, userId, address: await app.addressOf(userId) }, checks: c.list, summary: summarize(c.list) };
959
+ const dataFlow = await deviceChecks(c, app, o, ms, reports);
960
+ return { scope: "device", version: o.version, user: { input, userId, address: await app.addressOf(userId) }, checks: c.list, summary: summarize(c.list), dataFlow };
872
961
  }
873
962
  // This device first, in one line (its details are `p2p doctor` with no user).
874
963
  const dev = new Checks();
@@ -916,7 +1005,23 @@ async function versionChecks(c, app, userId) {
916
1005
  }
917
1006
  return { devices, unavailable };
918
1007
  }
919
- /** Human output: one line per check (✓ ✗ ?), with its fix indented below. */
1008
+ /** The heading of the data-flow section (pretty.ts styles it). */
1009
+ export const DATA_FLOW_HEADING = "Where your data goes";
1010
+ /** "Where your data goes", in plain words: one line per kind of data, then one per project's graph. */
1011
+ export function formatDataFlow(d) {
1012
+ const lines = [`${DATA_FLOW_HEADING} (${d.doc})`];
1013
+ lines.push(` messages, statuses, receipts: end-to-end encrypted; relays can't read their content, but see metadata, including ${d.wire.metadata.join(", ")} (all of it: ${d.wire.doc})`);
1014
+ lines.push(` message history: ${d.history.recording ? "on this device only" : "not recording (history.enabled is false, or P2P_HISTORY=0); what was kept stays on this device only"}, encrypted at rest, but its key sits beside it in P2P_HOME; the event log keeps up to ${d.history.eventLogPlaintextDays} days of recent messages in the clear`);
1015
+ lines.push(` graph memory: ${d.graphMemory.detail}`);
1016
+ for (const g of d.graphs)
1017
+ lines.push(` graph of project ${g.name}${g.here ? " (here)" : ""}: ${g.line} (${g.plaintext})`);
1018
+ if (d.graphsNotListed > 0)
1019
+ lines.push(` ${d.graphsNotListed} more project${d.graphsNotListed === 1 ? "" : "s"} not listed: run \`p2p project show\` in each`);
1020
+ if (!d.anyShared)
1021
+ lines.push(` cloud graph: none; no ${d.graphsNotListed > 0 ? "listed " : ""}project writes to one (a shared team graph is planned: opt-in per circle, and its operator can read what it holds)`);
1022
+ return lines;
1023
+ }
1024
+ /** Human output: one line per check (✓ ✗ ?), with its fix indented below, then where data goes. */
920
1025
  export function formatDoctor(r) {
921
1026
  const head = r.scope === "user" && r.user ? `p2p doctor: can you see ${r.user.address ?? r.user.input}?` : "p2p doctor: this device";
922
1027
  const lines = [head, ""];
@@ -925,6 +1030,8 @@ export function formatDoctor(r) {
925
1030
  if (x.fix)
926
1031
  lines.push(` ${x.status === "unknown" ? "to tell" : "fix"}: ${x.fix}`);
927
1032
  }
1033
+ if (r.dataFlow)
1034
+ lines.push("", ...formatDataFlow(r.dataFlow));
928
1035
  lines.push("", `${r.summary.ok} ✓ ${r.summary.fail} ✗ ${r.summary.unknown} ?`);
929
1036
  return lines.join("\n");
930
1037
  }
package/dist/ext-host.js CHANGED
@@ -12,6 +12,7 @@ import { join } from "node:path";
12
12
  import { displayStatus, sanitizePeerText } from "@peer2peer/core/v3";
13
13
  import { CliError } from "./errors.js";
14
14
  import { enabledNamespaces, extensionPackageName, kindNamespace, KNOWN_EXTENSIONS, setExtensionEnabled, } from "./extensions.js";
15
+ import { ixAdvice } from "./ix-local.js";
15
16
  import { ceilingAudience, graphPinnedEnv, graphTarget, localGraphEndpoint, PERSON_SESSION, sessionCeiling, sessionDirs, sessionWorkdir } from "./projects.js";
16
17
  import { listPeers, sendExtension, sessionAudience, sessionRef } from "./sessions.js";
17
18
  import { sessKey } from "./state.js";
@@ -266,12 +267,15 @@ export function registerExtensionCommands(program, reg, deps) {
266
267
  const loaded = reg.list().map((l) => ({ ns: l.ext.ns, name: l.ext.name, version: l.ext.version, from: l.from, commands: (l.ext.commands ?? []).map((c) => c.name) }));
267
268
  const { enabled, ignored } = enabledNamespaces(app.env, app.file);
268
269
  const missing = KNOWN_EXTENSIONS.filter((ns) => !reg.get(ns)).map(extensionPackageName);
270
+ // Ix is optional and recommended (never installed for the person): front ends read this to
271
+ // tell their agent it may suggest Ix once, and never install it itself.
272
+ const ix = ixAdvice(app.env, app.file);
269
273
  const human = [
270
274
  ...(loaded.length ? loaded.map((l) => `${l.name} ${l.version} (x:${l.ns}.*): ${l.from}`) : ["no extensions loaded"]),
271
275
  `enabled: ${enabled.length ? enabled.join(", ") : "none"}${app.env.P2P_EXTENSIONS !== undefined ? " (from P2P_EXTENSIONS)" : ""}`,
272
276
  ...(ignored.length ? [`ignored (not registered): ${ignored.join(", ")}`] : []),
273
277
  ].join("\n");
274
- return { json: { extensions: loaded, enabled, missing, ...(ignored.length ? { ignored } : {}) }, human };
278
+ return { json: { extensions: loaded, enabled, missing, ...(ignored.length ? { ignored } : {}), ix }, human };
275
279
  }, { requireIdentity: false }));
276
280
  for (const on of [true, false]) {
277
281
  group
@@ -12,7 +12,7 @@
12
12
  // can reach (the home directory, the identity and device keys). ExtContext
13
13
  // is the API it is meant to use, not a sandbox. So loading is opt-in:
14
14
  // - Which: only namespaces registered in protocol §8.3 (KNOWN_EXTENSIONS)
15
- // that the user enabled: P2P_EXTENSIONS ("ix,kartr"; "none" = none), else
15
+ // that the user enabled: P2P_EXTENSIONS ("ix"; "none" = none), else
16
16
  // `extensions` in <home>/config.json (`p2p extensions enable ix`). Nothing
17
17
  // enabled, nothing loaded.
18
18
  // - Where: only explicit node_modules directories: each P2P_EXTENSION_PATH
@@ -44,7 +44,7 @@ import { extensionKindCap, isExtensionKind, isExtStateTtl, sanitizePeerText } fr
44
44
  /** The seam's version; an extension declares the one it was built against. */
45
45
  export const EXTENSION_API = 1;
46
46
  /** Namespaces registered in docs/protocol.md §8.3: the only ones that can be enabled. */
47
- export const KNOWN_EXTENSIONS = ["ix", "kartr"];
47
+ export const KNOWN_EXTENSIONS = ["ix"];
48
48
  /** Cap on the JSON a `receive` digest may add to an event. */
49
49
  export const MAX_RENDERED_BYTES = 16 * 1024;
50
50
  /** Cap on the validated body kept with an event (for user-initiated actions later). */
package/dist/format.d.ts CHANGED
@@ -9,6 +9,8 @@ export declare function formatAge(sec: number): string;
9
9
  export declare function formatDate(sec: number): string;
10
10
  export declare function plural(n: number, one: string, many?: string): string;
11
11
  export declare function formatCodes(rows: CodeRow[]): string;
12
+ /** A code cut to its first four characters (after any link prefix): what the listing shows of a code that no longer lets anyone in. */
13
+ export declare function shortCode(code: string): string;
12
14
  /** "delivered via 2 relays (1 device)". */
13
15
  export declare function formatDelivery(d: Pick<Delivery, "relays" | "devices">): string;
14
16
  /** A terminal QR code of `text`; empty when it can't be rendered. */
package/dist/format.js CHANGED
@@ -47,11 +47,15 @@ export function formatCodes(rows) {
47
47
  default:
48
48
  st = r.status;
49
49
  }
50
- const shown = r.status === "open" || r.status === "taken" ? r.code : r.code.replace(/[^/]*$/, (c) => `${c.slice(0, 4)}…`);
50
+ const shown = (r.status === "open" || r.status === "taken") && !r.redacted ? r.code : shortCode(r.code);
51
51
  return `${shown}${who}${circle}${to}: ${st}`;
52
52
  })
53
53
  .join("\n");
54
54
  }
55
+ /** A code cut to its first four characters (after any link prefix): what the listing shows of a code that no longer lets anyone in. */
56
+ export function shortCode(code) {
57
+ return code.endsWith("…") ? code : code.replace(/[^/]*$/, (c) => `${c.slice(0, 4)}…`);
58
+ }
55
59
  /** "delivered via 2 relays (1 device)". */
56
60
  export function formatDelivery(d) {
57
61
  return `delivered via ${plural(d.relays.length, "relay")} (${plural(d.devices, "device")})`;
@@ -13,6 +13,13 @@ export interface InitResult {
13
13
  code: string;
14
14
  }[];
15
15
  }
16
+ /** The `p2p` command as the person types it here (Windows PowerShell blocks npm's p2p.ps1 shim; p2p.cmd works everywhere on Windows). */
17
+ export declare function p2pCommand(platform?: NodeJS.Platform): string;
18
+ /**
19
+ * Why a new identity can't be made here (no relay anywhere), naming the three ways in. There is
20
+ * no default relay, by design (bring your own relay).
21
+ */
22
+ export declare function noRelaysReason(home: string, platform?: NodeJS.Platform): string;
16
23
  export declare function init(app: App, opts: {
17
24
  name?: string;
18
25
  relays?: string[];
@@ -35,15 +42,21 @@ export interface SetupResult {
35
42
  file?: string;
36
43
  phrase?: string;
37
44
  };
38
- /** Ix on by default (ix-local.ts setupIx): found, enabled, and what to do when it isn't. */
45
+ /** Ix, optional and recommended (ix-local.ts setupIx): found, enabled, recommended (with the command for the person to run), and what to do when it isn't on. Never installed for them. */
39
46
  ix?: SetupIx;
47
+ /** This device is the only key holder and the backup phrase was never shown or saved (`p2p backup show`). */
48
+ backupNeeded?: true;
40
49
  }
41
50
  export declare const BACKUP_FILE_NAME = "backup-phrase.txt";
51
+ export type BackupMode = "file" | "print" | "none";
42
52
  export declare function setup(app: App, opts: {
43
53
  name?: string;
44
54
  relays?: string[];
45
- backup?: "file" | "print" | "none";
55
+ backup?: BackupMode;
46
56
  backupFile?: string;
57
+ ix?: boolean;
58
+ /** Asked only once an identity was created here (never before its key exists), when `backup` isn't given. */
59
+ chooseBackup?: (created: InitResult) => Promise<BackupMode>;
47
60
  }): Promise<SetupResult>;
48
61
  export declare function relaysList(app: App): Promise<{
49
62
  relays: string[];
@@ -76,8 +89,12 @@ export declare function reissueForRelays(app: App): Promise<{
76
89
  }>;
77
90
  /** Adds a relay to your identity document (the next version, published to old and new relays). */
78
91
  export declare function relaysAdd(app: App, url: string): Promise<RelaysChange>;
79
- /** Removes a relay (at least one must stay). The removed relay gets the new version too, so it stops admitting removed state. */
80
- export declare function relaysRemove(app: App, url: string): Promise<RelaysChange>;
92
+ /**
93
+ * Removes relays (at least one must stay), in one new version. The removed relays get it too, so they stop
94
+ * admitting removed state. Several at once (#78 review): two relays that both went silent while holding a
95
+ * newer version each hold up removing the other one alone (App.ownPendingGuard).
96
+ */
97
+ export declare function relaysRemove(app: App, urls: string | readonly string[]): Promise<RelaysChange>;
81
98
  export interface DeviceRow {
82
99
  did: string;
83
100
  label: string;
@@ -143,10 +160,22 @@ export declare function linkStart(app: App, opts?: {
143
160
  keyholder?: boolean;
144
161
  relay?: string;
145
162
  }): Promise<LinkStart>;
163
+ /** The identity a link code would make this device part of, shown before anything is kept (LinkJoin.wait). */
164
+ export interface LinkIdentity {
165
+ userId: string;
166
+ address: string;
167
+ fingerprint: string;
168
+ /** This device would get the identity key. */
169
+ keyholder: boolean;
170
+ }
146
171
  export interface LinkJoin {
147
172
  compareCode: string;
148
173
  did: string;
149
- wait(): Promise<{
174
+ /**
175
+ * Waits for the other device, then, with `confirm`, shows which identity this device would
176
+ * become and keeps nothing unless it says yes (a code from someone else makes this device theirs).
177
+ */
178
+ wait(confirm?: (who: LinkIdentity) => Promise<boolean>): Promise<{
150
179
  userId: string;
151
180
  address: string;
152
181
  did: string;
@@ -156,6 +185,7 @@ export interface LinkJoin {
156
185
  export declare function linkJoin(app: App, code: string, opts?: {
157
186
  label?: string;
158
187
  maxWaitMs?: number;
188
+ allowPrivateRelay?: boolean;
159
189
  }): Promise<LinkJoin>;
160
190
  export declare function backupShow(app: App): Promise<{
161
191
  phrase: string;