@peer2peer/cli 0.0.0-stage → 0.1.0
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/LICENSE +201 -0
- package/README.md +366 -2
- package/dist/ancestry.d.ts +13 -0
- package/dist/ancestry.js +71 -0
- package/dist/app.d.ts +363 -0
- package/dist/app.js +1177 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +56 -0
- package/dist/circle-ops.d.ts +402 -0
- package/dist/circle-ops.js +1725 -0
- package/dist/cli.d.ts +611 -0
- package/dist/cli.js +1650 -0
- package/dist/codes.d.ts +231 -0
- package/dist/codes.js +998 -0
- package/dist/config.d.ts +112 -0
- package/dist/config.js +243 -0
- package/dist/doctor.d.ts +99 -0
- package/dist/doctor.js +817 -0
- package/dist/errors.d.ts +8 -0
- package/dist/errors.js +29 -0
- package/dist/ext-host.d.ts +32 -0
- package/dist/ext-host.js +259 -0
- package/dist/extensions.d.ts +386 -0
- package/dist/extensions.js +395 -0
- package/dist/features.d.ts +91 -0
- package/dist/features.js +164 -0
- package/dist/format.d.ts +57 -0
- package/dist/format.js +248 -0
- package/dist/identity.d.ts +236 -0
- package/dist/identity.js +751 -0
- package/dist/inbound.d.ts +32 -0
- package/dist/inbound.js +258 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +14 -0
- package/dist/join-answers.d.ts +49 -0
- package/dist/join-answers.js +149 -0
- package/dist/outbox.d.ts +109 -0
- package/dist/outbox.js +337 -0
- package/dist/pretty.d.ts +100 -0
- package/dist/pretty.js +256 -0
- package/dist/procstart.d.ts +1 -0
- package/dist/procstart.js +66 -0
- package/dist/progress.d.ts +30 -0
- package/dist/progress.js +78 -0
- package/dist/projects.d.ts +240 -0
- package/dist/projects.js +699 -0
- package/dist/prompt/picker.d.ts +64 -0
- package/dist/prompt/picker.js +152 -0
- package/dist/prompt/tty.d.ts +29 -0
- package/dist/prompt/tty.js +122 -0
- package/dist/readonly.d.ts +20 -0
- package/dist/readonly.js +50 -0
- package/dist/receipts.d.ts +99 -0
- package/dist/receipts.js +180 -0
- package/dist/relay-client.d.ts +277 -0
- package/dist/relay-client.js +873 -0
- package/dist/relay-info.d.ts +24 -0
- package/dist/relay-info.js +53 -0
- package/dist/rotation.d.ts +402 -0
- package/dist/rotation.js +2054 -0
- package/dist/running.d.ts +5 -0
- package/dist/running.js +74 -0
- package/dist/sessions.d.ts +340 -0
- package/dist/sessions.js +1152 -0
- package/dist/shortcode.d.ts +149 -0
- package/dist/shortcode.js +465 -0
- package/dist/social.d.ts +139 -0
- package/dist/social.js +485 -0
- package/dist/state.d.ts +483 -0
- package/dist/state.js +217 -0
- package/dist/stdin.d.ts +17 -0
- package/dist/stdin.js +46 -0
- package/dist/sync.d.ts +77 -0
- package/dist/sync.js +375 -0
- package/dist/transient.d.ts +1 -0
- package/dist/transient.js +28 -0
- package/dist/trust.d.ts +37 -0
- package/dist/trust.js +134 -0
- package/dist/tty-confirm.d.ts +2 -0
- package/dist/tty-confirm.js +53 -0
- package/dist/tui/command.d.ts +20 -0
- package/dist/tui/command.js +70 -0
- package/dist/tui/frame.d.ts +43 -0
- package/dist/tui/frame.js +111 -0
- package/dist/tui/model.d.ts +215 -0
- package/dist/tui/model.js +255 -0
- package/dist/tui/sanitize.d.ts +13 -0
- package/dist/tui/sanitize.js +151 -0
- package/dist/tui/terminal.d.ts +88 -0
- package/dist/tui/terminal.js +354 -0
- package/dist/tui/tui.d.ts +71 -0
- package/dist/tui/tui.js +571 -0
- package/dist/tui/view.d.ts +4 -0
- package/dist/tui/view.js +356 -0
- package/dist/unknown-kinds.d.ts +12 -0
- package/dist/unknown-kinds.js +66 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +5 -0
- package/dist/want-pow.d.ts +12 -0
- package/dist/want-pow.js +46 -0
- package/dist/watch.d.ts +35 -0
- package/dist/watch.js +325 -0
- package/dist/xstate.d.ts +125 -0
- package/dist/xstate.js +422 -0
- package/package.json +60 -4
package/dist/state.d.ts
ADDED
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
import type { OutboxDoc } from "./outbox.js";
|
|
2
|
+
import type { ReceiptsDoc } from "./receipts.js";
|
|
3
|
+
import type { RelayInfoRec } from "./relay-info.js";
|
|
4
|
+
import type { ProjectsDoc, SessionProjectsDoc } from "./projects.js";
|
|
5
|
+
import { type LockOptions } from "@peer2peer/core/v3/node";
|
|
6
|
+
import type { DocBackend, RotationStatement, StatusBody } from "@peer2peer/core/v3";
|
|
7
|
+
import { type Progress } from "./progress.js";
|
|
8
|
+
export interface KeysDoc {
|
|
9
|
+
v: 1;
|
|
10
|
+
userId: string;
|
|
11
|
+
did: string;
|
|
12
|
+
/** b64u Ed25519 seed of the device signing key. */
|
|
13
|
+
spk: string;
|
|
14
|
+
/** b64u X25519 secret of the device agreement key. */
|
|
15
|
+
kpk: string;
|
|
16
|
+
/** This device's current certificate. */
|
|
17
|
+
cert: string;
|
|
18
|
+
/** b64u identity seed, on key-holding devices only (§2.2). */
|
|
19
|
+
ik?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface SelfDoc {
|
|
22
|
+
name: string;
|
|
23
|
+
relays: string[];
|
|
24
|
+
createdAt: number;
|
|
25
|
+
defaultCircle?: string;
|
|
26
|
+
/**
|
|
27
|
+
* The default circle was set by a code join (there was none): sessions already running when it was set
|
|
28
|
+
* don't move into it by themselves; new ones start in it. Cleared when the user sets a default.
|
|
29
|
+
*/
|
|
30
|
+
defaultFromJoin?: string;
|
|
31
|
+
/** Relays that have not yet confirmed the current document. */
|
|
32
|
+
unpublished?: string[];
|
|
33
|
+
/** Relays that refused a publish outright (not a transient failure), with when (ms): retried at most hourly. */
|
|
34
|
+
refusedPublish?: Record<string, number>;
|
|
35
|
+
backupShown?: boolean;
|
|
36
|
+
/** When this device last published its identity document to bring its `dinfo` entry current (ms; app.ts refreshDeviceInfo). */
|
|
37
|
+
deviceInfoAt?: number;
|
|
38
|
+
}
|
|
39
|
+
export interface SessionDoc {
|
|
40
|
+
sid: string;
|
|
41
|
+
ver: number;
|
|
42
|
+
vis: "circle" | "private";
|
|
43
|
+
circle?: string;
|
|
44
|
+
parts: string[];
|
|
45
|
+
jws: string;
|
|
46
|
+
/**
|
|
47
|
+
* The roster is the default one (§6: the default circle, else private),
|
|
48
|
+
* never set explicitly: it follows the default circle as that changes.
|
|
49
|
+
* Absent on docs written before this field; isAutoRoster() reads those.
|
|
50
|
+
*/
|
|
51
|
+
auto?: boolean;
|
|
52
|
+
/** The open circle this session was last warned about being shared with (warned once per circle). */
|
|
53
|
+
openNoted?: string;
|
|
54
|
+
}
|
|
55
|
+
/** One stored extension state value (xstate.ts): never an event. */
|
|
56
|
+
export interface XStateRec {
|
|
57
|
+
own: string;
|
|
58
|
+
sid: string;
|
|
59
|
+
/** The sending device. */
|
|
60
|
+
did: string;
|
|
61
|
+
kind: string;
|
|
62
|
+
/** The envelope `ts` (ms): latest wins by it. */
|
|
63
|
+
ts: number;
|
|
64
|
+
/** When it arrived here (ms). */
|
|
65
|
+
at: number;
|
|
66
|
+
/** Seconds it stays valid. */
|
|
67
|
+
ttl: number;
|
|
68
|
+
/** `ext.v` as sent. */
|
|
69
|
+
v: number;
|
|
70
|
+
/** The sanitized fallback line (no address prefix). */
|
|
71
|
+
fallback: string;
|
|
72
|
+
/** Bytes of `{v, body}` as sent. */
|
|
73
|
+
bytes: number;
|
|
74
|
+
/** The body the extension validated and kept; absent without the extension. */
|
|
75
|
+
body?: unknown;
|
|
76
|
+
extError?: string;
|
|
77
|
+
/** This user's own session (this device, or another of ours). */
|
|
78
|
+
self?: true;
|
|
79
|
+
}
|
|
80
|
+
/** `xstate`: the small index of senders whose state is held, with their totals (xstate.ts). */
|
|
81
|
+
export interface XStateIndex {
|
|
82
|
+
v: 2;
|
|
83
|
+
users: Record<string, {
|
|
84
|
+
doc: string;
|
|
85
|
+
n: number;
|
|
86
|
+
cost: number;
|
|
87
|
+
}>;
|
|
88
|
+
}
|
|
89
|
+
/** `xstate-<hash>`: one sender's values, by `<sid>|<kind>`, and their per-session rate windows. */
|
|
90
|
+
export interface XStateSenderDoc {
|
|
91
|
+
own: string;
|
|
92
|
+
recs: Record<string, XStateRec>;
|
|
93
|
+
/** Per session id: the current one-minute window of accepted updates (at most 128, the newest). */
|
|
94
|
+
rate: Record<string, {
|
|
95
|
+
start: number;
|
|
96
|
+
n: number;
|
|
97
|
+
}>;
|
|
98
|
+
/** The sender's one-minute window across all their sessions. */
|
|
99
|
+
all?: {
|
|
100
|
+
start: number;
|
|
101
|
+
n: number;
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
export interface PeerStatusRec {
|
|
105
|
+
own: string;
|
|
106
|
+
sid: string;
|
|
107
|
+
/** The sending device. */
|
|
108
|
+
did: string;
|
|
109
|
+
/** The envelope `ts` (ms): liveness is judged by it (§4.3). */
|
|
110
|
+
ts: number;
|
|
111
|
+
status: StatusBody;
|
|
112
|
+
rule?: string;
|
|
113
|
+
viewerRule?: string;
|
|
114
|
+
self?: boolean;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* `rotation`: a friend's new identity, "<friend> moved to a new key" (§2.8).
|
|
118
|
+
* `rotation-join`: the owner side, a rotated member's join to swap in.
|
|
119
|
+
*/
|
|
120
|
+
/** `rotation-dispute`: an approved rotation is now contested by another one (keep one, or neither). */
|
|
121
|
+
export type HeldType = "invite" | "circle-invite" | "circle-join" | "rotation" | "rotation-join" | "rotation-follow" | "rotation-dispute";
|
|
122
|
+
export interface HeldItem {
|
|
123
|
+
id: string;
|
|
124
|
+
type: HeldType;
|
|
125
|
+
from: string;
|
|
126
|
+
at: number;
|
|
127
|
+
/** invite: the invite JWS. */
|
|
128
|
+
invite?: string;
|
|
129
|
+
/** circle-invite: the offered head and the chain that came with it. */
|
|
130
|
+
head?: string;
|
|
131
|
+
chain?: string[];
|
|
132
|
+
joins?: string[];
|
|
133
|
+
cid?: string;
|
|
134
|
+
/** circle-join, rotation-join: the joiner's statement (owner side). */
|
|
135
|
+
join?: string;
|
|
136
|
+
reason?: string;
|
|
137
|
+
/** rotation, rotation-join: the two-part statement (`invite` is the new identity's invite). */
|
|
138
|
+
rotation?: RotationStatement;
|
|
139
|
+
/** rotation, rotation-join: the old userId. */
|
|
140
|
+
old?: string;
|
|
141
|
+
/** rotation-dispute: the new identities that claim `old` (one of them approved here before). */
|
|
142
|
+
candidates?: string[];
|
|
143
|
+
/** rotation-follow: the key-holding device that sent it, its label, and the new identity's fingerprint. */
|
|
144
|
+
device?: string;
|
|
145
|
+
deviceLabel?: string;
|
|
146
|
+
newFingerprint?: string;
|
|
147
|
+
}
|
|
148
|
+
export interface RotationApproval {
|
|
149
|
+
to: string;
|
|
150
|
+
kind: "friend" | "circle";
|
|
151
|
+
cid?: string;
|
|
152
|
+
at: number;
|
|
153
|
+
}
|
|
154
|
+
export interface RotationDispute {
|
|
155
|
+
candidates: string[];
|
|
156
|
+
/** Identities this client suspended (blocked) for it; `wasBlocked` ones it leaves blocked. */
|
|
157
|
+
suspended: {
|
|
158
|
+
userId: string;
|
|
159
|
+
wasBlocked: boolean;
|
|
160
|
+
}[];
|
|
161
|
+
/** review M3: members this owner's key holder took out of its circles when the dispute began (re-added if kept). */
|
|
162
|
+
removedFrom?: {
|
|
163
|
+
cid: string;
|
|
164
|
+
userId: string;
|
|
165
|
+
admin: boolean;
|
|
166
|
+
}[];
|
|
167
|
+
heldId: string;
|
|
168
|
+
at: number;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* A rotation of our own identity a key holder sent (§2.8 step 4), held until
|
|
172
|
+
* the user follows it (`p2p identity follow <id>`): never followed by itself.
|
|
173
|
+
* The link code is a secret, so it is kept here, never in the held item.
|
|
174
|
+
*/
|
|
175
|
+
export interface FollowRec {
|
|
176
|
+
statement: RotationStatement;
|
|
177
|
+
/** The one-time link code the new identity minted for this device (a secret). */
|
|
178
|
+
link: string;
|
|
179
|
+
fromDid: string;
|
|
180
|
+
at: number;
|
|
181
|
+
}
|
|
182
|
+
export interface EventRec {
|
|
183
|
+
n: number;
|
|
184
|
+
id: string;
|
|
185
|
+
at: number;
|
|
186
|
+
kind: string;
|
|
187
|
+
/** Session events: the local session it is for, when known. */
|
|
188
|
+
toSession?: string;
|
|
189
|
+
/** Session events: the session it belongs to. */
|
|
190
|
+
own?: string;
|
|
191
|
+
sid?: string;
|
|
192
|
+
data: Record<string, unknown>;
|
|
193
|
+
}
|
|
194
|
+
export interface EventsDoc {
|
|
195
|
+
next: number;
|
|
196
|
+
items: EventRec[];
|
|
197
|
+
}
|
|
198
|
+
export interface IdleSub {
|
|
199
|
+
own: string;
|
|
200
|
+
sid: string;
|
|
201
|
+
toSession: string;
|
|
202
|
+
at: number;
|
|
203
|
+
}
|
|
204
|
+
export interface AnswerPartsRec {
|
|
205
|
+
n: number;
|
|
206
|
+
got: number[];
|
|
207
|
+
top: number;
|
|
208
|
+
/** When the first part of this answer arrived (ms). */
|
|
209
|
+
at?: number;
|
|
210
|
+
}
|
|
211
|
+
export interface PendingJoin {
|
|
212
|
+
cid: string;
|
|
213
|
+
head: string;
|
|
214
|
+
inviter?: string;
|
|
215
|
+
/** Owner hint from a CLI circle link: its identity document and join statement. */
|
|
216
|
+
hint?: {
|
|
217
|
+
doc?: string;
|
|
218
|
+
join?: string;
|
|
219
|
+
};
|
|
220
|
+
/** Older clients kept answers here; now each confirmer's answer is a document of its own (join-answers.ts). */
|
|
221
|
+
answers?: Record<string, string[]>;
|
|
222
|
+
/** Who has an answer document for this join (written once per confirmer, not per part). */
|
|
223
|
+
answerFrom?: string[];
|
|
224
|
+
/** The answer caps this join issued (capids), revoked when it completes or is refused. */
|
|
225
|
+
answerCaps?: string[];
|
|
226
|
+
/** Membership statements that came with the answers. */
|
|
227
|
+
joins: string[];
|
|
228
|
+
asked: string[];
|
|
229
|
+
askedAt: number;
|
|
230
|
+
/** When each confirmer was last asked (ms); askedAt for ones asked before this field. */
|
|
231
|
+
askedAtBy?: Record<string, number>;
|
|
232
|
+
}
|
|
233
|
+
/** A short-code invite this user issued (P4). */
|
|
234
|
+
export interface CodeRecord {
|
|
235
|
+
lid: string;
|
|
236
|
+
/** The grouped code, `K7QM-3XPD-9TWA-HF2N-6RJC` (this user's own secret, kept like the keys). */
|
|
237
|
+
code: string;
|
|
238
|
+
/** `<relay part>/<code>`. */
|
|
239
|
+
short: string;
|
|
240
|
+
relay: string;
|
|
241
|
+
/** The hash of the invite JWS inside (what the accept names). */
|
|
242
|
+
inv: string;
|
|
243
|
+
/** The contact cap inside, so a revoke can revoke it too. */
|
|
244
|
+
capid?: string;
|
|
245
|
+
capRelays?: string[];
|
|
246
|
+
aud: string;
|
|
247
|
+
/** Local only: shown on the join notice. */
|
|
248
|
+
label?: string;
|
|
249
|
+
/** The (first) circle the code joins: what clients before multi-circle codes read. */
|
|
250
|
+
cid?: string;
|
|
251
|
+
/** Every circle the code joins, `cid` first (multi-circle codes). */
|
|
252
|
+
cids?: string[];
|
|
253
|
+
/** The circles the redemption put the redeemer in (added, or proposed to the owner): what `p2p remove` undoes. */
|
|
254
|
+
added?: string[];
|
|
255
|
+
/** Seconds. */
|
|
256
|
+
createdAt: number;
|
|
257
|
+
exp: number;
|
|
258
|
+
status: "open" | "redeemed" | "revoked";
|
|
259
|
+
redeemedBy?: string;
|
|
260
|
+
redeemedAt?: number;
|
|
261
|
+
removedAt?: number;
|
|
262
|
+
}
|
|
263
|
+
export interface RedeemedCode {
|
|
264
|
+
lid: string;
|
|
265
|
+
relay: string;
|
|
266
|
+
blob: string;
|
|
267
|
+
at: number;
|
|
268
|
+
/** The accept reached no relay: a retry resends it. */
|
|
269
|
+
undelivered?: boolean;
|
|
270
|
+
}
|
|
271
|
+
export interface CodeJoin {
|
|
272
|
+
cid: string;
|
|
273
|
+
inviter: string;
|
|
274
|
+
lid: string;
|
|
275
|
+
head: string;
|
|
276
|
+
at: number;
|
|
277
|
+
/** Set once a join was tried and needs the user's say (held item id). */
|
|
278
|
+
needsApproval?: string;
|
|
279
|
+
/** The code's first circle (the only one that may become the default circle); false for the others. */
|
|
280
|
+
first?: boolean;
|
|
281
|
+
/** What the person saw in the preview and said yes to: the circle that arrives must match it to be joined. */
|
|
282
|
+
confirmed?: {
|
|
283
|
+
name: string;
|
|
284
|
+
policy: "invite" | "open";
|
|
285
|
+
owner: string;
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
type Docs = {
|
|
289
|
+
keys: KeysDoc;
|
|
290
|
+
self: SelfDoc;
|
|
291
|
+
sessions: Record<string, SessionDoc>;
|
|
292
|
+
seq: Record<string, number>;
|
|
293
|
+
peers: Record<string, PeerStatusRec>;
|
|
294
|
+
held: HeldItem[];
|
|
295
|
+
events: EventsDoc;
|
|
296
|
+
spoke: Record<string, string>;
|
|
297
|
+
subs: IdleSub[];
|
|
298
|
+
joins: Record<string, PendingJoin>;
|
|
299
|
+
transfers: Record<string, Record<string, string>>;
|
|
300
|
+
fetched: Record<string, number>;
|
|
301
|
+
codes: Record<string, CodeRecord>;
|
|
302
|
+
redeemed: Record<string, RedeemedCode>;
|
|
303
|
+
codeJoins: Record<string, CodeJoin>;
|
|
304
|
+
/** Members-only relays: admission keys from redeemed codes, by relay, until a relay admits us with one. */
|
|
305
|
+
admits: Record<string, {
|
|
306
|
+
key: string;
|
|
307
|
+
at: number;
|
|
308
|
+
}>;
|
|
309
|
+
rotations: Record<string, RotationStatement[]>;
|
|
310
|
+
follows: Record<string, FollowRec>;
|
|
311
|
+
rotationAlerts: string[];
|
|
312
|
+
/** What this client carried over through a rotation, by old userId (friendships, circle swaps). */
|
|
313
|
+
rotationApprovals: Record<string, RotationApproval[]>;
|
|
314
|
+
/** Contested carry-overs waiting for the user: who was suspended, by old userId. */
|
|
315
|
+
disputes: Record<string, RotationDispute>;
|
|
316
|
+
/** How the user settled a contest, by old userId: the identity kept (or none) and the rejected ones. */
|
|
317
|
+
rotationResolved: Record<string, {
|
|
318
|
+
keep: string | null;
|
|
319
|
+
rejected: string[];
|
|
320
|
+
at: number;
|
|
321
|
+
}>;
|
|
322
|
+
circleHold: Record<string, boolean>;
|
|
323
|
+
/** Slices of a synced circle too large for one envelope, waiting for the rest (sync.ts importCircle), by cid. */
|
|
324
|
+
syncCircles: Record<string, {
|
|
325
|
+
versions: string[];
|
|
326
|
+
statements: string[];
|
|
327
|
+
at: number;
|
|
328
|
+
}>;
|
|
329
|
+
/** Answers to `want`s in the last hour (circle-ops chargeAnswer): per asker, bytes per asker and to non-members, and what was sent. */
|
|
330
|
+
wantAnswers: {
|
|
331
|
+
by: Record<string, number[]>;
|
|
332
|
+
bytes: Record<string, {
|
|
333
|
+
at: number;
|
|
334
|
+
bytes: number;
|
|
335
|
+
}[]>;
|
|
336
|
+
sent: {
|
|
337
|
+
at: number;
|
|
338
|
+
bytes: number;
|
|
339
|
+
pool?: "reserve" | "open" | "link";
|
|
340
|
+
}[];
|
|
341
|
+
last: Record<string, {
|
|
342
|
+
ver: number;
|
|
343
|
+
at: number;
|
|
344
|
+
resent?: boolean;
|
|
345
|
+
}>;
|
|
346
|
+
members?: Record<string, {
|
|
347
|
+
at: number;
|
|
348
|
+
bytes: number;
|
|
349
|
+
}[]>;
|
|
350
|
+
pows?: {
|
|
351
|
+
id: string;
|
|
352
|
+
at: number;
|
|
353
|
+
}[];
|
|
354
|
+
refused?: Record<string, number>;
|
|
355
|
+
};
|
|
356
|
+
/** Wants this device answers only if no device of ours has by `due` (circle-ops DeferredWant, re-review N6). */
|
|
357
|
+
deferredWants: {
|
|
358
|
+
from: string;
|
|
359
|
+
fdid: string;
|
|
360
|
+
want: {
|
|
361
|
+
cid: string;
|
|
362
|
+
fromVer: number;
|
|
363
|
+
};
|
|
364
|
+
relay: string;
|
|
365
|
+
cap?: string;
|
|
366
|
+
pow?: {
|
|
367
|
+
at: number;
|
|
368
|
+
nonce: string;
|
|
369
|
+
};
|
|
370
|
+
at: number;
|
|
371
|
+
due: number;
|
|
372
|
+
}[];
|
|
373
|
+
/** Envelopes dropped unapplied (failed for good, or given up after every attempt): a count only. */
|
|
374
|
+
inbound: {
|
|
375
|
+
gaveUp: number;
|
|
376
|
+
at?: number;
|
|
377
|
+
tooOld?: number;
|
|
378
|
+
};
|
|
379
|
+
xstate: XStateIndex;
|
|
380
|
+
xstateSent: Record<string, number>;
|
|
381
|
+
/** Sealed messages no relay accepted yet, retried by `watch` (outbox.ts). */
|
|
382
|
+
outbox: OutboxDoc;
|
|
383
|
+
/** Delivery receipts (receipts.ts, §4.3). */
|
|
384
|
+
receipts: ReceiptsDoc;
|
|
385
|
+
/** When each (sender, kind) of an envelope this version doesn't know was last noticed (unknown-kinds.ts). */
|
|
386
|
+
unknownKinds: Record<string, number>;
|
|
387
|
+
/** Relays' /.well-known/p2p-relay.json, as last fetched (relay-info.ts), by canonical URL. */
|
|
388
|
+
relayInfo: Record<string, RelayInfoRec>;
|
|
389
|
+
/** Project policies (projects.ts): this device's own, keyed by project id. Never synced, never read from a repository. */
|
|
390
|
+
projects: ProjectsDoc;
|
|
391
|
+
/** Which projects each session has worked in (projects.ts), by sid: sticky until the session ends. */
|
|
392
|
+
sessionProjects: SessionProjectsDoc;
|
|
393
|
+
};
|
|
394
|
+
export declare const sessKey: (own: string, sid: string) => string;
|
|
395
|
+
/** Events older than this, or beyond the count cap, are pruned. */
|
|
396
|
+
export declare const EVENT_RETENTION_MS: number;
|
|
397
|
+
export declare const EVENT_MAX = 2000;
|
|
398
|
+
/** What CliState needs from its backend: documents and a lock (the file backend's, or an in-memory one). */
|
|
399
|
+
export type CliBackend = DocBackend & {
|
|
400
|
+
withLock<T>(fn: () => Promise<T>): Promise<T>;
|
|
401
|
+
};
|
|
402
|
+
/** Back-to-back state updates from one process before it leaves other processes a gap. */
|
|
403
|
+
export declare const STATE_BURST = 8;
|
|
404
|
+
/** The gap: longer than FileDocBackend's longest wait between lock attempts (50 ms). */
|
|
405
|
+
export declare const STATE_YIELD_MS = 60;
|
|
406
|
+
export declare class CliState {
|
|
407
|
+
readonly dir: string;
|
|
408
|
+
private readonly progress?;
|
|
409
|
+
readonly backend: CliBackend;
|
|
410
|
+
private readonly eventListeners;
|
|
411
|
+
/**
|
|
412
|
+
* In-process queue in front of the cross-process lock: concurrent updates from this process
|
|
413
|
+
* (a status going to several recipients at once) wait their turn here instead of polling the
|
|
414
|
+
* lock file with backoff. The lock itself is still taken for every update.
|
|
415
|
+
*/
|
|
416
|
+
private queue;
|
|
417
|
+
/** Updates queued here and not yet done. */
|
|
418
|
+
private queued;
|
|
419
|
+
/** Updates run back to back with more waiting (the lock went straight from one to the next). */
|
|
420
|
+
private streak;
|
|
421
|
+
private locked;
|
|
422
|
+
constructor(dir: string, progress?: Progress | undefined,
|
|
423
|
+
/** `p2p doctor`: an in-memory overlay (readonly.ts), so nothing is written to `dir`. */
|
|
424
|
+
backend?: CliBackend, lockOpts?: Partial<LockOptions>);
|
|
425
|
+
get<K extends keyof Docs>(name: K): Promise<Docs[K] | undefined>;
|
|
426
|
+
/** Read-modify-write under the cross-process lock. Return `undefined` as `next` to leave it. */
|
|
427
|
+
/**
|
|
428
|
+
* Runs `fn` under the state lock (the same one every update takes), for a read-modify-write of a
|
|
429
|
+
* file outside the state documents: config.json (config.ts updateFileConfigField).
|
|
430
|
+
*/
|
|
431
|
+
withLock<R>(fn: () => Promise<R>): Promise<R>;
|
|
432
|
+
update<K extends keyof Docs, R>(name: K, fn: (cur: Docs[K] | undefined) => {
|
|
433
|
+
next?: Docs[K];
|
|
434
|
+
result: R;
|
|
435
|
+
}): Promise<R>;
|
|
436
|
+
/**
|
|
437
|
+
* update() for a decision that must await something while holding the lock
|
|
438
|
+
* (rosters: the trust store's putRoster, whose own lock is another file's
|
|
439
|
+
* and never takes this one). `fn` must not call back into this state.
|
|
440
|
+
*/
|
|
441
|
+
updateAsync<K extends keyof Docs, R>(name: K, fn: (cur: Docs[K] | undefined) => Promise<{
|
|
442
|
+
next?: Docs[K];
|
|
443
|
+
result: R;
|
|
444
|
+
}>): Promise<R>;
|
|
445
|
+
/** A document outside the fixed set (one per key, e.g. a join answer per confirmer), read without the lock. */
|
|
446
|
+
getDoc<T>(name: string): Promise<T | undefined>;
|
|
447
|
+
/** update() for a document outside the fixed set: only that document is rewritten. */
|
|
448
|
+
updateDoc<T, R>(name: string, fn: (cur: T | undefined) => {
|
|
449
|
+
next?: T;
|
|
450
|
+
result: R;
|
|
451
|
+
}): Promise<R>;
|
|
452
|
+
removeDoc(name: string): Promise<void>;
|
|
453
|
+
put<K extends keyof Docs>(name: K, value: Docs[K]): Promise<void>;
|
|
454
|
+
/** The next envelope seq for (own, sid) on this device. */
|
|
455
|
+
nextSeq(own: string, sid: string): Promise<number>;
|
|
456
|
+
/**
|
|
457
|
+
* `count` consecutive envelope seqs for (own, sid) on this device, in one write.
|
|
458
|
+
*
|
|
459
|
+
* A missing counter starts at the clock in ms (as on main, so it lands above every window a
|
|
460
|
+
* receiver already holds for the session, and a lost or never-written seq.json heals); after
|
|
461
|
+
* that it counts up by one (review M1, third round). Jumping to the clock on every send put two
|
|
462
|
+
* sends a second apart ~1000 seqs apart, so an earlier envelope applied after a later one (a
|
|
463
|
+
* crash, a transient failure, another relay's late copy) was dropped as seq-too-old.
|
|
464
|
+
*
|
|
465
|
+
* Residual: a counter restored from a backup taken after the session's first send is behind
|
|
466
|
+
* seqs it already spent. Until it passes them, receivers drop its envelopes: as replays while
|
|
467
|
+
* within their 512-seq window, and as late envelopes (counted in `p2p doctor`) below it.
|
|
468
|
+
*
|
|
469
|
+
* One counter serves every recipient device of a send (a status fan-out takes one seq per
|
|
470
|
+
* device), so a receiver sees gaps of up to the number of other copies: its 512-seq window
|
|
471
|
+
* tolerates about 512 / (devices per send) sends of reordering, ~36 statuses at 14 copies.
|
|
472
|
+
*/
|
|
473
|
+
nextSeqs(own: string, sid: string, count: number): Promise<number[]>;
|
|
474
|
+
/**
|
|
475
|
+
* Calls `fn` whenever this process has appended events, so `watch` prints them at once instead
|
|
476
|
+
* of at its next poll. Returns the unsubscribe.
|
|
477
|
+
*/
|
|
478
|
+
onEventsAdded(fn: () => void): () => void;
|
|
479
|
+
/** Appends events; returns them with their log positions. Duplicate ids are dropped. */
|
|
480
|
+
addEvents(events: Omit<EventRec, "n">[], now?: number): Promise<EventRec[]>;
|
|
481
|
+
private appendEvents;
|
|
482
|
+
}
|
|
483
|
+
export {};
|