@peer2peer/cli 0.1.0 → 0.1.2

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.
@@ -62,6 +62,10 @@ export interface MessageRow {
62
62
  lastSeen?: number;
63
63
  receiptId?: string;
64
64
  note?: string;
65
+ /** From the message history (history.ts): kept past this run, up to its retention. */
66
+ fromHistory?: true;
67
+ /** The person's own inbox (this TUI's session, or no session) rather than one of their agent sessions'. */
68
+ inbox?: boolean;
65
69
  }
66
70
  export interface RelayRow {
67
71
  url: string;
@@ -153,6 +157,8 @@ export interface Ui {
153
157
  error?: boolean;
154
158
  };
155
159
  busy?: string;
160
+ /** Messages screen: only your inbox (this TUI's session, or none), not your agent sessions' too. */
161
+ inboxOnly?: boolean;
156
162
  }
157
163
  export type Effect = {
158
164
  kind: "quit";
@@ -206,7 +212,7 @@ export type PeopleItem = {
206
212
  export declare function peopleItems(d: Data): PeopleItem[];
207
213
  /** Send targets: live sessions first (not this TUI's own), then each person (their one session, or our session). */
208
214
  export declare function sendTargets(d: Data): SendTarget[];
209
- export declare function messagesSorted(d: Data): MessageRow[];
215
+ export declare function messagesSorted(d: Data, ui?: Pick<Ui, "inboxOnly">): MessageRow[];
210
216
  export declare function clampSel(ui: Ui, d: Data): Ui;
211
217
  /** One key press. Returns the next ui and, at most, one effect. */
212
218
  export declare function onKey(ui0: Ui, d: Data, key: Key, page?: number): {
package/dist/tui/model.js CHANGED
@@ -34,8 +34,8 @@ export function sendTargets(d) {
34
34
  }
35
35
  return [...sessions, ...people];
36
36
  }
37
- export function messagesSorted(d) {
38
- return [...d.messages].sort((a, b) => b.at - a.at);
37
+ export function messagesSorted(d, ui) {
38
+ return d.messages.filter((m) => !ui?.inboxOnly || m.inbox !== false).sort((a, b) => b.at - a.at);
39
39
  }
40
40
  function count(ui, d) {
41
41
  switch (ui.screen) {
@@ -44,7 +44,7 @@ function count(ui, d) {
44
44
  case "held":
45
45
  return d.held.length;
46
46
  case "messages":
47
- return d.messages.length;
47
+ return messagesSorted(d, ui).length;
48
48
  case "send":
49
49
  return sendTargets(d).length;
50
50
  case "health":
@@ -227,7 +227,11 @@ export function onKey(ui0, d, key, page = 10) {
227
227
  return { ui };
228
228
  }
229
229
  case "messages": {
230
- const msg = messagesSorted(d)[sel];
230
+ if (key.ch === "h") {
231
+ const next = clampSel({ ...ui, inboxOnly: !ui.inboxOnly }, d);
232
+ return { ui: flash(next, next.inboxOnly ? "Your inbox only: messages to you and this window's session." : "Every session on this device: your inbox and your agent sessions' messages.") };
233
+ }
234
+ const msg = messagesSorted(d, ui)[sel];
231
235
  if (!msg)
232
236
  return { ui };
233
237
  if (key.name === "return" || key.name === "space") {
package/dist/tui/tui.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { App } from "../app.js";
2
- import { onKey, type Data, type Effect, type Ui } from "./model.js";
2
+ import { type HistoryRec } from "../history.js";
3
+ import { onKey, type Data, type Effect, type MessageRow, type Ui } from "./model.js";
3
4
  import type { Terminal } from "./terminal.js";
4
5
  export declare const TUI_SESSION = "tui";
5
6
  /** A relay's `/.well-known/p2p-relay.json` read at most this far (it is a few hundred bytes). */
@@ -51,7 +52,11 @@ export declare class Tui {
51
52
  loadAll(): Promise<void>;
52
53
  loadPeople(): Promise<void>;
53
54
  loadHeld(): Promise<void>;
54
- /** Received messages from the event log, and sent ones: this run's, receipts asked for, the outbox. */
55
+ /**
56
+ * Received messages from the event log, and sent ones: this run's, receipts asked for, the outbox;
57
+ * then the message history (history.ts) for what is older or was sent elsewhere. The TUI runs
58
+ * only on the person's own terminal (command.ts tuiRefusal), so it reads the person's view.
59
+ */
55
60
  loadMessages(): Promise<void>;
56
61
  /** Keeps the newest MESSAGES_MAX messages (this run's sends are capped the same way). */
57
62
  private capMessages;
@@ -69,3 +74,5 @@ export declare class Tui {
69
74
  /** For tests: resolves once the TUI stopped. */
70
75
  done(): Promise<void>;
71
76
  }
77
+ /** A message history record as a row of the Messages screen (peer text cleaned for the terminal). */
78
+ export declare function historyRow(r: HistoryRec, session: string): MessageRow;
package/dist/tui/tui.js CHANGED
@@ -22,7 +22,8 @@ import { RECEIPT_OUTCOMES } from "@peer2peer/core/v3";
22
22
  import { approveJoinRequest, circleMembers, joinFromHeld, listCircles } from "../circle-ops.js";
23
23
  import { doctor } from "../doctor.js";
24
24
  import { CliError, toErrorJson } from "../errors.js";
25
- import { listPeers, sendSharing } from "../sessions.js";
25
+ import { listPeers, sendSharing, tuiTaintNote } from "../sessions.js";
26
+ import { isPersonRecord, readHistory } from "../history.js";
26
27
  import { sessionWorkdir, showProject } from "../projects.js";
27
28
  import { accept, dropHeld, friends, getHeld, listHeld } from "../social.js";
28
29
  import { trustAdd } from "../trust.js";
@@ -225,6 +226,7 @@ export class Tui {
225
226
  ...(typeof e.sid === "string" ? { sid: e.sid } : {}),
226
227
  ...(typeof e.ref === "string" ? { ref: e.ref } : {}),
227
228
  text: clean(e.text),
229
+ inbox: forUs,
228
230
  ...(!forUs && typeof e.toSession === "string" ? { note: `for your session ${clean(e.toSession)}` } : {}),
229
231
  };
230
232
  }
@@ -306,7 +308,11 @@ export class Tui {
306
308
  this.data.held = rows;
307
309
  this.draw();
308
310
  }
309
- /** Received messages from the event log, and sent ones: this run's, receipts asked for, the outbox. */
311
+ /**
312
+ * Received messages from the event log, and sent ones: this run's, receipts asked for, the outbox;
313
+ * then the message history (history.ts) for what is older or was sent elsewhere. The TUI runs
314
+ * only on the person's own terminal (command.ts tuiRefusal), so it reads the person's view.
315
+ */
310
316
  async loadMessages() {
311
317
  const app = this.app;
312
318
  const cutoff = this.now() - 7 * 86_400_000;
@@ -328,10 +334,26 @@ export class Tui {
328
334
  for (const [id, w] of Object.entries(receipts)) {
329
335
  if (w.at < cutoff || out.some((m) => m.receiptId === id))
330
336
  continue;
331
- out.push({ id: `r:${id}`, dir: "out", at: w.at, who: await app.addressOf(w.to), userId: w.to, own: w.own, ref: w.ref, text: `(sent from session ${w.fromSession}; text not kept)`, state: "sent", receiptId: id, outcomes: w.outcomes.map((x) => x.outcome) });
337
+ out.push({ id: `r:${id}`, dir: "out", at: w.at, who: await app.addressOf(w.to), userId: w.to, own: w.own, ref: w.ref, text: `(sent from session ${w.fromSession}; text not kept)`, state: "sent", receiptId: id, outcomes: w.outcomes.map((x) => x.outcome), inbox: w.fromSession === this.data.session, ...(w.fromSession !== this.data.session ? { note: `from your session ${clean(w.fromSession)}` } : {}) });
332
338
  }
333
339
  for (const i of outbox) {
334
- out.push({ id: `o:${i.id}`, dir: "out", at: i.queuedAt, who: i.dest.address, userId: i.dest.userId, own: i.dest.own, ref: i.dest.ref, text: `(sealed in the outbox, from session ${i.fromSession})`, state: "outbox" });
340
+ out.push({ id: `o:${i.id}`, dir: "out", at: i.queuedAt, who: i.dest.address, userId: i.dest.userId, own: i.dest.own, ref: i.dest.ref, text: `(sealed in the outbox, from session ${i.fromSession})`, state: "outbox", inbox: i.fromSession === this.data.session });
341
+ }
342
+ const hist = await readHistory(app, { person: true }, { limit: MESSAGES_MAX }, this.now()).catch(() => undefined);
343
+ for (const r of hist?.messages ?? []) {
344
+ if (r.dir === "in") {
345
+ if (!received.some((m) => m.id === r.id))
346
+ received.push(historyRow(r, this.data.session));
347
+ continue;
348
+ }
349
+ // A send already listed (this run's, a receipt's, the outbox's): the history fills in its text.
350
+ const same = out.find((m) => m.userId === r.peer.userId && Math.abs(m.at - r.at) < 60_000 && (m.text === r.text || m.text.startsWith("(")));
351
+ if (same) {
352
+ if (same.text.startsWith("("))
353
+ same.text = clean(r.text);
354
+ continue;
355
+ }
356
+ out.push(historyRow(r, this.data.session));
335
357
  }
336
358
  this.data.messages = [...received, ...out];
337
359
  this.capMessages();
@@ -528,7 +550,7 @@ export class Tui {
528
550
  case "send":
529
551
  await this.busy("sending", async () => {
530
552
  const at = this.now();
531
- const row = { id: `s:${at}:${this.sent.length}`, dir: "out", at, who: e.label, text: e.text, state: "sent" };
553
+ const row = { id: `s:${at}:${this.sent.length}`, dir: "out", at, who: e.label, text: e.text, state: "sent", inbox: true };
532
554
  try {
533
555
  // As `p2p send` on a terminal: someone this session isn't shared with is added with the send
534
556
  // (undone if it fails), so it lands and their replies come here; and it says so.
@@ -547,7 +569,8 @@ export class Tui {
547
569
  // Your own send crosses no project boundary; it says which one this folder has (projects.ts).
548
570
  const here = await showProject(this.app, sessionWorkdir(this.app.env)).catch(() => undefined);
549
571
  const boundary = here ? ` Project ${clean(here.name)} here is ${here.policy}: this send was yours.` : "";
550
- this.flash(`${r.queued ? `Queued for ${clean(r.to.address)} [${r.to.ref}]: it goes out or waits until they're back.` : `Sent to ${clean(r.to.address)} [${r.to.ref}].`}${note}${boundary}`);
572
+ const taint = await tuiTaintNote(this.app, r.to.userId).catch(() => undefined);
573
+ this.flash(`${r.queued ? `Queued for ${clean(r.to.address)} [${r.to.ref}]: it goes out or waits until they're back.` : `Sent to ${clean(r.to.address)} [${r.to.ref}].`}${note}${boundary}${taint ? ` Note: ${taint}.` : ""}`);
551
574
  }
552
575
  catch (err) {
553
576
  Object.assign(row, { state: "failed", note: clean(toErrorJson(err).reason) });
@@ -569,3 +592,21 @@ export class Tui {
569
592
  return (this.closed ??= new Promise((r) => (this.stop.signal.aborted ? r() : this.stop.signal.addEventListener("abort", () => r()))));
570
593
  }
571
594
  }
595
+ /** A message history record as a row of the Messages screen (peer text cleaned for the terminal). */
596
+ export function historyRow(r, session) {
597
+ const mine = isPersonRecord(r) || r.session === session;
598
+ const where = r.session === undefined ? "" : clean(r.session);
599
+ return {
600
+ id: r.id,
601
+ dir: r.dir,
602
+ at: r.at,
603
+ who: clean(r.peer.address) || "?",
604
+ userId: r.peer.userId,
605
+ ...(r.peerSession ? { own: r.peerSession.own, sid: r.peerSession.sid, ref: r.peerSession.ref } : {}),
606
+ text: clean(r.type === "ext" ? `${r.ext ?? "extension"}: ${r.text}` : r.text),
607
+ ...(r.dir === "out" ? { state: r.state === "outbox" ? "outbox" : r.state === "offline" ? "offline" : "sent" } : {}),
608
+ fromHistory: true,
609
+ inbox: mine,
610
+ ...(!mine ? { note: r.dir === "in" ? `for your session ${where}` : `from your session ${where}` } : {}),
611
+ };
612
+ }
package/dist/tui/view.js CHANGED
@@ -23,7 +23,7 @@ export function ago(sec) {
23
23
  const HELP = {
24
24
  people: "↑↓ move · m message · d doctor · 1-5 screens · ? help · q quit",
25
25
  held: "↑↓ move · a accept/deliver · x decline · t always deliver · ? help · q quit",
26
- messages: "↑↓ move · Enter open · r reply · 1-5 screens · ? help · q quit",
26
+ messages: "↑↓ move · Enter open · r reply · h inbox/all · 1-5 screens · ? help · q quit",
27
27
  send: "↑↓ pick · Enter write · then Enter send, Esc cancel, Ctrl-U clear · q quit",
28
28
  health: "r run doctor · d on People: one person · 1-5 screens · ? help · q quit",
29
29
  };
@@ -190,9 +190,9 @@ function outcomeText(m, now) {
190
190
  return { text: m.receiptId ? "sent, no receipt yet" : "sent", style: DIM };
191
191
  }
192
192
  function messages(ui, d, cols, h, out, now) {
193
- const list = messagesSorted(d);
193
+ const list = messagesSorted(d, ui);
194
194
  if (list.length === 0) {
195
- out.push(new Line(cols).add("No messages yet. Messages to this TUI's session, replies and your sends appear here.", DIM));
195
+ out.push(new Line(cols).add(ui.inboxOnly ? "Nothing in your inbox yet (h shows every session's messages)." : "No messages yet. Messages to this TUI's session, replies and your sends appear here.", DIM));
196
196
  return;
197
197
  }
198
198
  const [a, b] = window(list.length, ui.sel.messages, Math.floor(h / 2));
@@ -208,6 +208,8 @@ function messages(ui, d, cols, h, out, now) {
208
208
  if (m.dir === "out") {
209
209
  const o = outcomeText(m, now);
210
210
  l.add(o.text, o.style);
211
+ if (m.note)
212
+ l.gap(2).add(m.note, DIM);
211
213
  }
212
214
  else {
213
215
  if (m.note)
@@ -297,7 +299,7 @@ function overlay(f, ui, cols, rows) {
297
299
  "↑/↓ or j/k move, PgUp/PgDn, g/G first/last",
298
300
  "People: m or Enter message a person or session; d doctor for them",
299
301
  "Held: a accept (invites, joins) or deliver (held messages); x decline; t always deliver from the sender (asks first)",
300
- "Messages: Enter opens one; r replies (this window sends no read receipts)",
302
+ "Messages: Enter opens one; r replies (this window sends no read receipts); h your inbox only or every session (history: kept encrypted on this device, 30 days by default)",
301
303
  "Send: pick, write, Enter sends; Esc cancels",
302
304
  "Health: r runs the doctor again",
303
305
  "q or Ctrl-C quits. Nothing is accepted, sent or trusted except on your key press.",
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.1.0";
1
+ export declare const VERSION = "0.1.2";
package/dist/version.js CHANGED
@@ -2,4 +2,4 @@
2
2
  //
3
3
  // This CLI's version (scripts/set-version.mjs writes it), on its own so the status and identity
4
4
  // code can advertise it (features.ts) without importing the command line.
5
- export const VERSION = "0.1.0";
5
+ export const VERSION = "0.1.2";
package/dist/watch.js CHANGED
@@ -30,6 +30,7 @@ import { safeJson } from "./format.js";
30
30
  import { alertForeignRotations, noteDocRotations, retryRotationJoins } from "./rotation.js";
31
31
  import { flushOutbox, OUTBOX_RETRY_MS } from "./outbox.js";
32
32
  import { markRunning, unmarkRunning } from "./running.js";
33
+ import { graphMemoryLoop, graphMemoryTickMs } from "./graph-memory.js";
33
34
  function cursorPath(app, sid) {
34
35
  return join(app.home, "cursors", `${sid}.cursor`);
35
36
  }
@@ -163,6 +164,11 @@ export async function watch(app, opts) {
163
164
  await renewOpenJoinCaps(app);
164
165
  });
165
166
  every(3600_000, () => maintain(app));
167
+ // Graph memory (graph-memory.ts): this device's sessions' context into the local Ix graph, gathered
168
+ // from the statuses they posted and written in the background, a batch at a time. Off without the
169
+ // Ix extension, without Ix, or when the person turned it off; never on the hook path.
170
+ const memory = graphMemoryLoop(app, { log: opts.log });
171
+ every(graphMemoryTickMs(app.env), () => memory.tick());
166
172
  void maintain(app).catch(() => { });
167
173
  const pollMs = opts.pollMs ?? 300;
168
174
  const startedAs = app.userId;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peer2peer/cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
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,10 +53,13 @@
53
53
  "registry": "https://registry.npmjs.org/"
54
54
  },
55
55
  "dependencies": {
56
- "@peer2peer/codex-bridge": "0.1.0",
57
- "@peer2peer/core": "0.1.0",
56
+ "@peer2peer/codex-bridge": "0.1.2",
57
+ "@peer2peer/core": "0.1.2",
58
58
  "commander": "15.0.0",
59
59
  "uqr": "0.1.3",
60
60
  "ws": "8.22.0"
61
+ },
62
+ "overrides": {
63
+ "minimatch": "^11.0.8"
61
64
  }
62
65
  }