@peer2peer/cli 0.0.0-stage → 0.1.1

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.
Files changed (111) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +370 -2
  3. package/dist/ancestry.d.ts +13 -0
  4. package/dist/ancestry.js +71 -0
  5. package/dist/app.d.ts +368 -0
  6. package/dist/app.js +1181 -0
  7. package/dist/bin.d.ts +2 -0
  8. package/dist/bin.js +56 -0
  9. package/dist/circle-ops.d.ts +402 -0
  10. package/dist/circle-ops.js +1725 -0
  11. package/dist/cli.d.ts +660 -0
  12. package/dist/cli.js +1787 -0
  13. package/dist/codes.d.ts +231 -0
  14. package/dist/codes.js +998 -0
  15. package/dist/config.d.ts +159 -0
  16. package/dist/config.js +294 -0
  17. package/dist/doctor.d.ts +113 -0
  18. package/dist/doctor.js +930 -0
  19. package/dist/errors.d.ts +8 -0
  20. package/dist/errors.js +29 -0
  21. package/dist/ext-host.d.ts +38 -0
  22. package/dist/ext-host.js +293 -0
  23. package/dist/extensions.d.ts +487 -0
  24. package/dist/extensions.js +406 -0
  25. package/dist/features.d.ts +91 -0
  26. package/dist/features.js +164 -0
  27. package/dist/format.d.ts +57 -0
  28. package/dist/format.js +248 -0
  29. package/dist/graph-memory.d.ts +107 -0
  30. package/dist/graph-memory.js +393 -0
  31. package/dist/history.d.ts +155 -0
  32. package/dist/history.js +697 -0
  33. package/dist/identity.d.ts +239 -0
  34. package/dist/identity.js +759 -0
  35. package/dist/inbound.d.ts +32 -0
  36. package/dist/inbound.js +261 -0
  37. package/dist/index.d.ts +8 -0
  38. package/dist/index.js +14 -0
  39. package/dist/ix-local.d.ts +76 -0
  40. package/dist/ix-local.js +203 -0
  41. package/dist/join-answers.d.ts +49 -0
  42. package/dist/join-answers.js +149 -0
  43. package/dist/outbox.d.ts +109 -0
  44. package/dist/outbox.js +337 -0
  45. package/dist/pretty.d.ts +100 -0
  46. package/dist/pretty.js +256 -0
  47. package/dist/procstart.d.ts +1 -0
  48. package/dist/procstart.js +66 -0
  49. package/dist/progress.d.ts +30 -0
  50. package/dist/progress.js +78 -0
  51. package/dist/projects.d.ts +491 -0
  52. package/dist/projects.js +1383 -0
  53. package/dist/prompt/picker.d.ts +64 -0
  54. package/dist/prompt/picker.js +152 -0
  55. package/dist/prompt/tty.d.ts +29 -0
  56. package/dist/prompt/tty.js +122 -0
  57. package/dist/readonly.d.ts +20 -0
  58. package/dist/readonly.js +50 -0
  59. package/dist/receipts.d.ts +99 -0
  60. package/dist/receipts.js +182 -0
  61. package/dist/relay-client.d.ts +277 -0
  62. package/dist/relay-client.js +873 -0
  63. package/dist/relay-info.d.ts +24 -0
  64. package/dist/relay-info.js +53 -0
  65. package/dist/rotation.d.ts +402 -0
  66. package/dist/rotation.js +2054 -0
  67. package/dist/running.d.ts +5 -0
  68. package/dist/running.js +74 -0
  69. package/dist/sessions.d.ts +355 -0
  70. package/dist/sessions.js +1247 -0
  71. package/dist/shortcode.d.ts +149 -0
  72. package/dist/shortcode.js +465 -0
  73. package/dist/social.d.ts +139 -0
  74. package/dist/social.js +485 -0
  75. package/dist/state.d.ts +509 -0
  76. package/dist/state.js +220 -0
  77. package/dist/stdin.d.ts +17 -0
  78. package/dist/stdin.js +46 -0
  79. package/dist/sync.d.ts +77 -0
  80. package/dist/sync.js +375 -0
  81. package/dist/transient.d.ts +1 -0
  82. package/dist/transient.js +28 -0
  83. package/dist/trust.d.ts +37 -0
  84. package/dist/trust.js +134 -0
  85. package/dist/tty-confirm.d.ts +2 -0
  86. package/dist/tty-confirm.js +53 -0
  87. package/dist/tui/command.d.ts +20 -0
  88. package/dist/tui/command.js +70 -0
  89. package/dist/tui/frame.d.ts +43 -0
  90. package/dist/tui/frame.js +111 -0
  91. package/dist/tui/model.d.ts +221 -0
  92. package/dist/tui/model.js +259 -0
  93. package/dist/tui/sanitize.d.ts +13 -0
  94. package/dist/tui/sanitize.js +151 -0
  95. package/dist/tui/terminal.d.ts +88 -0
  96. package/dist/tui/terminal.js +354 -0
  97. package/dist/tui/tui.d.ts +78 -0
  98. package/dist/tui/tui.js +612 -0
  99. package/dist/tui/view.d.ts +4 -0
  100. package/dist/tui/view.js +358 -0
  101. package/dist/unknown-kinds.d.ts +12 -0
  102. package/dist/unknown-kinds.js +66 -0
  103. package/dist/version.d.ts +1 -0
  104. package/dist/version.js +5 -0
  105. package/dist/want-pow.d.ts +12 -0
  106. package/dist/want-pow.js +46 -0
  107. package/dist/watch.d.ts +35 -0
  108. package/dist/watch.js +331 -0
  109. package/dist/xstate.d.ts +125 -0
  110. package/dist/xstate.js +422 -0
  111. package/package.json +60 -4
@@ -0,0 +1,5 @@
1
+ import type { App } from "./app.js";
2
+ export declare function markRunning(app: App, sid: string): Promise<void>;
3
+ export declare function unmarkRunning(app: App, sid: string): Promise<void>;
4
+ /** Did session `sid` of this device run under a watch that is gone now? */
5
+ export declare function sessionEnded(app: App, sid: string): boolean;
@@ -0,0 +1,74 @@
1
+ // Copyright 2026 Ix Infrastructure Inc.
2
+ //
3
+ // Which of this device's sessions ran under a `p2p watch` and has ended. A watch writes
4
+ // `<home>/cursors/<sid>.watch` ({pid, started}) when it starts and marks it `ended` when it stops;
5
+ // a session whose watch was killed instead is ended once that process is gone (or a later process
6
+ // has its pid). A laptop asleep keeps its watches: not ended. A session that never ran a watch
7
+ // (only short commands, as in scripts) has no marker and is never called ended.
8
+ //
9
+ // Used when a message arrives for one of this device's sessions: if that session has ended (with
10
+ // `/exit`, or `/clear` started a new one), the message is also logged as one addressed to no
11
+ // session, so the user's current session holds it for Deliver (onSessionEnvelope).
12
+ import { readFileSync } from "node:fs";
13
+ import { mkdir, writeFile } from "node:fs/promises";
14
+ import { join } from "node:path";
15
+ import { processStartMs } from "./procstart.js";
16
+ import { SID_RE } from "./sessions.js";
17
+ const STARTED = Math.round(Date.now() - process.uptime() * 1000);
18
+ /** Start times compare to the second (ps), with room for clock rounding. */
19
+ const START_SLACK_MS = 2500;
20
+ /** Only a valid session id names a file here (pre-release review O4): never a path. */
21
+ const markerPath = (app, sid) => {
22
+ if (!SID_RE.test(sid) || sid === "." || sid === "..")
23
+ throw new Error(`not a session id: ${JSON.stringify(sid.slice(0, 40))}`);
24
+ return join(app.home, "cursors", `${sid}.watch`);
25
+ };
26
+ export async function markRunning(app, sid) {
27
+ await mkdir(join(app.home, "cursors"), { recursive: true, mode: 0o700 });
28
+ await writeFile(markerPath(app, sid), JSON.stringify({ pid: process.pid, started: STARTED }), { mode: 0o600 });
29
+ }
30
+ export async function unmarkRunning(app, sid) {
31
+ try {
32
+ const m = JSON.parse(readFileSync(markerPath(app, sid), "utf8"));
33
+ if (m.pid === process.pid)
34
+ await writeFile(markerPath(app, sid), JSON.stringify({ ...m, ended: Date.now() }), { mode: 0o600 });
35
+ }
36
+ catch {
37
+ // none
38
+ }
39
+ }
40
+ function alive(pid) {
41
+ try {
42
+ process.kill(pid, 0);
43
+ return true;
44
+ }
45
+ catch (e) {
46
+ return e.code === "EPERM";
47
+ }
48
+ }
49
+ /** Did session `sid` of this device run under a watch that is gone now? */
50
+ export function sessionEnded(app, sid) {
51
+ if (!SID_RE.test(sid) || sid === "." || sid === "..")
52
+ return false;
53
+ if (app.watching === sid)
54
+ return false;
55
+ let m;
56
+ try {
57
+ m = JSON.parse(readFileSync(markerPath(app, sid), "utf8"));
58
+ }
59
+ catch {
60
+ return false; // never ran a watch here
61
+ }
62
+ if (typeof m.ended === "number")
63
+ return true;
64
+ if (typeof m.pid !== "number" || !Number.isSafeInteger(m.pid) || m.pid <= 0)
65
+ return false;
66
+ if (m.pid === process.pid)
67
+ return false;
68
+ if (!alive(m.pid))
69
+ return true;
70
+ if (typeof m.started !== "number")
71
+ return false;
72
+ const started = processStartMs(m.pid);
73
+ return started !== undefined && Math.abs(started - m.started) >= START_SLACK_MS;
74
+ }
@@ -0,0 +1,355 @@
1
+ import { type AcceptedMessageV3, type ProjectBound, type StatusAgent, type StatusBody } from "@peer2peer/core/v3";
2
+ import type { App, Delivery } from "./app.js";
3
+ import { type OverWhy, type SessionProjectView } from "./projects.js";
4
+ import { type ExtSendResult } from "./extensions.js";
5
+ import { type NewEvent } from "./inbound.js";
6
+ import { type PeerStatusRec, type SessionDoc } from "./state.js";
7
+ import { type StateSummary } from "./xstate.js";
8
+ /** Session ids: what Claude Code and Codex use (UUIDs and the like). */
9
+ export declare const SID_RE: RegExp;
10
+ export declare const MAX_TEXT_BYTES: number;
11
+ export declare const MAX_FILES = 25;
12
+ export declare const IDLE_SUB_TTL_MS = 3600000;
13
+ /**
14
+ * What this CLI itself understands (§4.3 "Status caps"): the tolerant status
15
+ * parser, `status.agents` (it parses, stores and lists them), and extension
16
+ * state kinds (xstate.v1: it keeps them latest-wins and never logs them as
17
+ * events; xstate.ts). `p2p status` adds `<kind>.v1` for each state kind a
18
+ * loaded extension declares. A caller
19
+ * (the mod, the Codex bridge) adds its own with `--cap`.
20
+ *
21
+ * Two-step rollout, step 2 (footprint P1): statuses carry `caps` by default.
22
+ * Clients older than the amendment reject a status that carries `caps`, so a
23
+ * user whose peers still run one opts out with `P2P_STATUS_CAPS=0` or
24
+ * `"statusCaps": false` in config.json (see statusCapsEnabled).
25
+ */
26
+ export declare const CLI_STATUS_CAPS: readonly string[];
27
+ /** §4.3 "Status agents": at most this many distinct paths across `files` and every agent's. */
28
+ export declare const MAX_STATUS_PATHS = 60;
29
+ /** §4.3: a sender keeps a status plaintext under 8 KiB; agents are trimmed (oldest first) to fit. */
30
+ export declare const STATUS_SOFT_MAX_BYTES: number;
31
+ export declare function checkSid(sid: string | undefined, flag?: string): string;
32
+ /** First 6 hex characters of sha256(own + "/" + sid): a short session reference. */
33
+ export declare function sessionRef(own: string, sid: string): string;
34
+ /**
35
+ * A stored roster of our own as a session doc: its signed payload read back
36
+ * (it is ours, verified when stored). Only a roster this device signed is
37
+ * adopted (pre-release review low); one signed by another device of ours, or one this
38
+ * client can't read, fails closed: nothing is written. Its provenance is
39
+ * unknown, so it counts as set explicitly (no auto-follow), unless it is
40
+ * exactly the default roster this device would sign now (`want`, no
41
+ * participants): then it keeps following the default.
42
+ */
43
+ export declare function docFromStored(sid: string, r: {
44
+ ver: number;
45
+ jws: string;
46
+ }, did: string, want?: {
47
+ vis: "circle" | "private";
48
+ circle?: string;
49
+ }): SessionDoc;
50
+ /**
51
+ * Whether a session's roster is still the default one, never set explicitly.
52
+ * A doc from before `auto` existed counts when it is the first version with
53
+ * no participants: every explicit change (`session roster`) bumps the version.
54
+ */
55
+ export declare function isAutoRoster(d: SessionDoc): boolean;
56
+ export declare const OPEN_CIRCLE_SHARED = "is shared with an open circle (its policy is open now): anyone its owner admits can see it; `p2p session roster <sid> --private` (or /peers private) stops that";
57
+ /** Kept for clients that match these notes (older mods); this CLI no longer says them: sessions follow their project. */
58
+ export declare const CODE_JOIN_NO_FOLLOW = "kept as it was: a code you redeemed set your default circle, and a session already running doesn't move into a circle by itself; share it with `p2p session roster <sid> --circle <cid>` (or /peers circle <cid>). New sessions start in it";
59
+ export declare const OPEN_CIRCLE_NO_FOLLOW = "kept private: your default circle is open (anyone its owner admits can see what's shared there), so a session already running doesn't move into it by itself; share it with `p2p session roster <sid> --circle <cid>` (or /peers circle <cid>)";
60
+ /**
61
+ * The session's roster, made on first use, and kept within its project ceiling (projects.ts):
62
+ * one nobody set by hand follows its projects' policies (private until the person shares the
63
+ * project); one set by hand is cut down to the ceiling when the ceiling narrows (a session that
64
+ * worked in a private project stays private until it ends). The person's own session, and one
65
+ * no project is bound to yet, have no ceiling: their roster is private until set by hand.
66
+ */
67
+ export declare function getSession(app: App, sid: string, notes?: string[]): Promise<SessionDoc>;
68
+ export interface RosterView {
69
+ sid: string;
70
+ ref: string;
71
+ ver: number;
72
+ vis: "circle" | "private";
73
+ circle?: string;
74
+ circleName?: string;
75
+ parts: {
76
+ userId: string;
77
+ address: string;
78
+ }[];
79
+ openCircle?: boolean;
80
+ }
81
+ export declare function roster(app: App, sid: string, opts: {
82
+ circle?: string;
83
+ private?: boolean;
84
+ add?: string[];
85
+ remove?: string[];
86
+ }): Promise<RosterView>;
87
+ /**
88
+ * Who a session's status reaches, as an extension may know it (ExtContext.audience): its
89
+ * roster's visibility, the circle and whether that circle is open, and how many people the
90
+ * roster lets see it besides this user. Read only: a session with no roster yet, or whose circle
91
+ * can't be loaded, is undefined (nothing is created). `orgs` (distinct verified organisations) is absent until a trust
92
+ * provider supplies org labels (§8.2).
93
+ */
94
+ export declare function sessionAudience(app: App, sid: string): Promise<{
95
+ vis: "circle" | "private";
96
+ circle?: string;
97
+ open?: true;
98
+ people: number;
99
+ members: string[];
100
+ } | undefined>;
101
+ /** Who the roster lets see this session, besides us (§4.2, the core rule). */
102
+ export declare function rosterAudience(app: App, s: SessionDoc): Promise<string[]>;
103
+ export interface StatusOpts {
104
+ session: string;
105
+ state: string;
106
+ summary?: string;
107
+ files?: string[];
108
+ label?: string;
109
+ repo?: string;
110
+ branch?: string;
111
+ mode?: string;
112
+ cwd?: string;
113
+ /** Caps the caller's client understands, added to {@link CLI_STATUS_CAPS}. Ignored when `emitCaps` is off. */
114
+ caps?: string[];
115
+ /** Whether this status carries `caps` (and `agents`) at all (statusCapsEnabled); on by default. */
116
+ emitCaps?: boolean;
117
+ /**
118
+ * Directories the session works in besides its working directory (P2P_WORKDIR, else the
119
+ * process's): a folder it moved to, files it touched elsewhere. Each binds the session to that
120
+ * project for the rest of its life (projects.ts), which can only narrow who sees it.
121
+ */
122
+ projectDirs?: string[];
123
+ /**
124
+ * The front end dropped folders past its cap, or couldn't resolve a path (`--project-dirs-over`):
125
+ * private. A list says why (projects.ts OverWhy: `--project-dirs-over=unresolved,folders`); `true`
126
+ * is an older front end's bare flag.
127
+ */
128
+ projectDirsOver?: boolean | string[];
129
+ /**
130
+ * The session's subagents (`--agents-json`), as the caller has them: entries
131
+ * are normalized (sanitized, capped, ordered, trimmed), never trusted as is.
132
+ */
133
+ agents?: unknown;
134
+ }
135
+ export interface StatusResult {
136
+ status: StatusBody;
137
+ roster: RosterView;
138
+ /** `agents`: whether that recipient got `status.agents` (its live sessions all advertise agents.v1). */
139
+ delivered: (Delivery & {
140
+ address: string;
141
+ agents: boolean;
142
+ })[];
143
+ failed: {
144
+ userId: string;
145
+ address: string;
146
+ error: string;
147
+ }[];
148
+ /** What was left out rather than failing the post (review L3): caller caps that were off, invalid or over the limit. */
149
+ warnings?: string[];
150
+ /** The projects this session works in and what they allow (projects.ts). */
151
+ project?: SessionProjectView;
152
+ /** The folders it was given are bound for good (a front end may stop passing them). */
153
+ bound?: true;
154
+ }
155
+ /**
156
+ * The status this session posts. Never fails over what a caller adds on top
157
+ * of the original fields (review L3): with status caps off (the opt-out),
158
+ * caller caps and agents are left out (agents still count in the summary); an
159
+ * invalid or surplus cap is dropped. Each is noted in `warnings`.
160
+ */
161
+ export declare function buildStatus(o: StatusOpts, prev?: StatusBody, warnings?: string[]): StatusBody;
162
+ /** A summary without the ` (+N agents)` summaryWithAgents() appends (or the whole of one that is only that). */
163
+ export declare function withoutAgentCount(summary: string): string;
164
+ /**
165
+ * `--agents-json` as a valid §4.3 `agents` list: each entry's fields
166
+ * sanitized or dropped, at most 10 files each (never under `.claude/worktrees/`
167
+ * or `.git/`), ordered (at work first, then most recent), at most 8, nesting
168
+ * flattened to depth 2. Not an array is a usage error.
169
+ */
170
+ export declare function normalizeAgents(raw: unknown, mainFiles?: readonly string[]): StatusAgent[];
171
+ /**
172
+ * The status a recipient without agents.v1 gets: no `agents` (a client from
173
+ * before P1 would drop it, one from before the amendment would reject the
174
+ * status), and the agents at work counted in the summary instead.
175
+ */
176
+ export declare function statusWithoutAgents(s: StatusBody): StatusBody;
177
+ /**
178
+ * Whether user `u` gets `status.agents`: every live session of theirs we
179
+ * know of (other than this device's own) advertises agents.v1, and there is
180
+ * at least one. Status goes to a user, one plaintext for all their devices,
181
+ * so one session from an older client (or none at all) means the summary
182
+ * fallback for that user.
183
+ */
184
+ export declare function understandsAgents(peers: Record<string, PeerStatusRec>, u: string, self: {
185
+ userId: string;
186
+ did: string;
187
+ }, now?: number): boolean;
188
+ /** How many recipients a status goes to at once. */
189
+ export declare const STATUS_FANOUT = 8;
190
+ /** `fn` over `items`, at most `limit` at a time; results in input order. */
191
+ export declare function mapLimit<T, R>(items: readonly T[], limit: number, fn: (item: T) => Promise<R>): Promise<R[]>;
192
+ export declare function sendStatus(app: App, o: StatusOpts): Promise<StatusResult>;
193
+ export interface PeerRow {
194
+ own: string;
195
+ sid: string;
196
+ ref: string;
197
+ address: string;
198
+ self: boolean;
199
+ thisDevice: boolean;
200
+ live: boolean;
201
+ ageSec: number;
202
+ state: "busy" | "idle";
203
+ label: string;
204
+ repo?: string;
205
+ branch?: string;
206
+ mode?: string;
207
+ summary?: string;
208
+ summaryAt?: number;
209
+ files: string[];
210
+ /** What the session's client understands (§4.3 "Status caps"); absent from older clients. */
211
+ caps?: string[];
212
+ /** The device it runs on, and its client's protocol minor (docs/compatibility.md; from its caps). */
213
+ did?: string;
214
+ proto?: number;
215
+ /** Its subagents (§4.3 "Status agents"), validated; only from a session that sent them to this user. */
216
+ agents?: StatusAgent[];
217
+ /** Its extension state (§4.3 "Extension state kinds"): a bounded summary (kind, times, fallback, size), never a body. */
218
+ xstate?: StateSummary[];
219
+ /** How this user is authorised for the session (§4.2): "owner" for our own sessions. */
220
+ rule?: string;
221
+ viewerRule?: string;
222
+ /** How the session's sender was authorised (the owner, for statuses). */
223
+ senderRule?: string;
224
+ /** The circle that gives standing, when the session is shared through one. */
225
+ circle?: string;
226
+ }
227
+ export declare function listPeers(app: App, opts?: {
228
+ all?: boolean;
229
+ }): Promise<PeerRow[]>;
230
+ export interface SendOpts {
231
+ fromSession: string;
232
+ to: string;
233
+ text: string;
234
+ notifyWhenIdle?: boolean;
235
+ /** Directories the sending session works in besides its working directory (see StatusOpts.projectDirs). */
236
+ projectDirs?: string[];
237
+ /** See StatusOpts.projectDirsOver. */
238
+ projectDirsOver?: boolean | string[];
239
+ /**
240
+ * The person at their own terminal (`p2p send` typed with no --from-session, `p2p tui`): their
241
+ * session is theirs, never bound to a project. Set only by those two paths, never from a flag.
242
+ */
243
+ person?: boolean;
244
+ }
245
+ export interface SendResult {
246
+ delivered: boolean;
247
+ to: {
248
+ userId: string;
249
+ address: string;
250
+ own: string;
251
+ sid: string;
252
+ ref: string;
253
+ };
254
+ relays: number;
255
+ devices: number;
256
+ messageId?: string;
257
+ notifyWhenIdle?: boolean;
258
+ /**
259
+ * Held for later delivery instead of reaching a live session. `state`: "offline" when the
260
+ * relays took it for a session that isn't live (it gets it when it reconnects; `lastSeen` is
261
+ * when its last status was, which the sender's `ls` shows anyway), "outbox" when no relay took
262
+ * it and this device keeps it (outbox.ts) until one does. Either way it expires at `expiresAt`.
263
+ */
264
+ queued?: true;
265
+ state?: "offline" | "outbox";
266
+ lastSeen?: number;
267
+ expiresAt?: number;
268
+ /**
269
+ * Delivery receipts (§4.3): "requested" when the session advertises receipts.v1 and the message
270
+ * asked for them (`receiptId` names it in the `p2p.receipt` events that come back); "unsupported"
271
+ * when it doesn't (an older client, or one with receipts off: the two look the same).
272
+ */
273
+ receipts?: "requested" | "unsupported";
274
+ receiptId?: string;
275
+ /** The folders it was given are bound for good (see StatusResult.bound). */
276
+ bound?: true;
277
+ }
278
+ /** `user`, `user [ref]`, `user/ref` or `user/sid`. */
279
+ export declare function parseTarget(to: string): {
280
+ user: string;
281
+ pick?: string;
282
+ };
283
+ /**
284
+ * How recently a session must have been seen (its last status) for a message to be held for it
285
+ * while it is offline. Relays keep an envelope for 7 days, and a recipient accepts one whose ts is
286
+ * at most 7 days old; but a session silent for a day has most likely ended (`/exit`, `/clear`),
287
+ * and a message for it would only reach its user as an unclaimed notice. A day covers a laptop
288
+ * asleep overnight or a dropped connection, which is what this is for; older sessions are
289
+ * refused as before (not_found), so a sender never queues into one long gone.
290
+ */
291
+ export declare const OFFLINE_TARGET_MS: number;
292
+ /** How long a same-device send's record (Docs.localSends) is kept: as long as a relay keeps the envelope. */
293
+ export declare const LOCAL_SEND_TTL_MS: number;
294
+ /** At most this many same-device send records; the oldest go first. */
295
+ export declare const LOCAL_SENDS_MAX = 4096;
296
+ /** How long after a bounded session's text reached `tui` a send from there to someone else is warned about. */
297
+ export declare const TUI_TAINT_MS: number;
298
+ /**
299
+ * A warning (never a refusal) for the person sending from their own session `tui` to someone else
300
+ * after a message from a bounded session of theirs reached it: they may be passing its text on.
301
+ */
302
+ export declare function tuiTaintNote(app: App, toUserId: string, now?: number): Promise<string | undefined>;
303
+ /**
304
+ * A send by a person at a terminal (the `tui` session: `p2p send` with no --from-session, or `p2p tui`):
305
+ * a recipient who isn't in the session's audience is added to its roster first, so the message can
306
+ * land there and their replies reach it, and the add is undone if the send fails. `shared` names whom
307
+ * it shared with. Never used for --from-session or off a terminal: there a missing share is refused.
308
+ */
309
+ export declare function sendSharing(app: App, o: SendOpts): Promise<{
310
+ result: SendResult;
311
+ shared?: {
312
+ userId: string;
313
+ address: string;
314
+ };
315
+ }>;
316
+ export declare function sendMessage(app: App, o: SendOpts): Promise<SendResult>;
317
+ export interface SendExtOpts {
318
+ fromSession: string;
319
+ to: string;
320
+ kind: string;
321
+ v: number;
322
+ body: unknown;
323
+ fallback: string;
324
+ /** Directories the sending session works in besides its working directory (see StatusOpts.projectDirs). */
325
+ projectDirs?: string[];
326
+ }
327
+ /**
328
+ * The budget for `{v, body}`: the same as a message's text, which leaves room in the 64 KiB
329
+ * envelope (§4.1) for the roster, the certificate and two layers of base64.
330
+ */
331
+ export declare const MAX_EXT_PLAINTEXT_BYTES: number;
332
+ export declare function sendExtension(app: App, o: SendExtOpts): Promise<ExtSendResult>;
333
+ export declare function onSessionEnvelope(app: App, env: string, r: AcceptedMessageV3): Promise<NewEvent[]>;
334
+ /**
335
+ * Binds `sid` to the folders its front end reports (projects.ts sessionDirs: P2P_WORKDIR,
336
+ * P2P_PROJECT_DIRS, past its cap private) and any more the caller names.
337
+ */
338
+ export declare function bindFromEnv(app: App, sid: string, extra?: readonly string[], o?: {
339
+ person?: boolean;
340
+ over?: OverWhy[];
341
+ }): Promise<void>;
342
+ /** This device's live sessions already within a bound (and the person's own terminal session): who may hold an own-session message that carries it. */
343
+ export declare function sessionsWithin(app: App, b: ProjectBound, now?: number): Promise<string[]>;
344
+ /** `p2p session bound`: a front end binds the session that took an own-session message to that message's bound (sticky). */
345
+ export declare function bindBound(app: App, sid: string, bound: unknown): Promise<SessionProjectView>;
346
+ /** Whether a session of ours may reach `user` (projects.ts): the same rule its sends follow. */
347
+ export declare function mayReach(app: App, sid: string, user: string): Promise<boolean>;
348
+ /**
349
+ * The local sessions a message for no session may be held in: this device's live sessions whose
350
+ * projects reach the sender, and the person's own terminal session. Every other session's watch
351
+ * never shows it (watch.ts eventFor), and the mod picks its holder among these.
352
+ */
353
+ export declare function routableSessions(app: App, sender: string, now?: number): Promise<string[]>;
354
+ /** Subscriptions older than an hour end with `p2p.idle {reason: "expired"}` (v1 semantics). */
355
+ export declare function expireSubs(app: App, now?: number): Promise<void>;