@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.
- package/LICENSE +201 -0
- package/README.md +370 -2
- package/dist/ancestry.d.ts +13 -0
- package/dist/ancestry.js +71 -0
- package/dist/app.d.ts +368 -0
- package/dist/app.js +1181 -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 +660 -0
- package/dist/cli.js +1787 -0
- package/dist/codes.d.ts +231 -0
- package/dist/codes.js +998 -0
- package/dist/config.d.ts +159 -0
- package/dist/config.js +294 -0
- package/dist/doctor.d.ts +113 -0
- package/dist/doctor.js +930 -0
- package/dist/errors.d.ts +8 -0
- package/dist/errors.js +29 -0
- package/dist/ext-host.d.ts +38 -0
- package/dist/ext-host.js +293 -0
- package/dist/extensions.d.ts +487 -0
- package/dist/extensions.js +406 -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/graph-memory.d.ts +107 -0
- package/dist/graph-memory.js +393 -0
- package/dist/history.d.ts +155 -0
- package/dist/history.js +697 -0
- package/dist/identity.d.ts +239 -0
- package/dist/identity.js +759 -0
- package/dist/inbound.d.ts +32 -0
- package/dist/inbound.js +261 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +14 -0
- package/dist/ix-local.d.ts +76 -0
- package/dist/ix-local.js +203 -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 +491 -0
- package/dist/projects.js +1383 -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 +182 -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 +355 -0
- package/dist/sessions.js +1247 -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 +509 -0
- package/dist/state.js +220 -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 +221 -0
- package/dist/tui/model.js +259 -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 +78 -0
- package/dist/tui/tui.js +612 -0
- package/dist/tui/view.d.ts +4 -0
- package/dist/tui/view.js +358 -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 +331 -0
- package/dist/xstate.d.ts +125 -0
- package/dist/xstate.js +422 -0
- package/package.json +60 -4
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
import { type ExtensionKind, type StatusAgent } from "@peer2peer/core/v3";
|
|
2
|
+
import type { Env } from "./config.js";
|
|
3
|
+
/** The seam's version; an extension declares the one it was built against. */
|
|
4
|
+
export declare const EXTENSION_API = 1;
|
|
5
|
+
/** Namespaces registered in docs/protocol.md §8.3: the only ones that can be enabled. */
|
|
6
|
+
export declare const KNOWN_EXTENSIONS: readonly string[];
|
|
7
|
+
/** Cap on the JSON a `receive` digest may add to an event. */
|
|
8
|
+
export declare const MAX_RENDERED_BYTES: number;
|
|
9
|
+
/** Cap on the validated body kept with an event (for user-initiated actions later). */
|
|
10
|
+
export declare const MAX_KEPT_BYTES: number;
|
|
11
|
+
/** Each string in a digest passes the peer-text sanitizer with this cap. */
|
|
12
|
+
export declare const MAX_RENDERED_STRING = 4000;
|
|
13
|
+
export declare function extensionPackageName(ns: string): string;
|
|
14
|
+
/** The namespace of an `x:<ns>.<type>` kind. */
|
|
15
|
+
export declare function kindNamespace(kind: string): string | undefined;
|
|
16
|
+
export interface ExtReceiveInput {
|
|
17
|
+
kind: ExtensionKind;
|
|
18
|
+
/** `ext.v` as sent. */
|
|
19
|
+
v: number;
|
|
20
|
+
/** `ext.body` as sent: untrusted peer data of any JSON shape. */
|
|
21
|
+
body: unknown;
|
|
22
|
+
/** The core-sanitized fallback line, already prefixed with the sender's address. */
|
|
23
|
+
fallback: string;
|
|
24
|
+
from: {
|
|
25
|
+
userId: string;
|
|
26
|
+
address: string;
|
|
27
|
+
self: boolean;
|
|
28
|
+
};
|
|
29
|
+
session: {
|
|
30
|
+
own: string;
|
|
31
|
+
sid: string;
|
|
32
|
+
ref: string;
|
|
33
|
+
};
|
|
34
|
+
/** Set for a state kind (§4.3 "Extension state kinds"): what `keep` returns is stored as the session's latest value. */
|
|
35
|
+
state?: {
|
|
36
|
+
ttl: number;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export type ExtReceived =
|
|
40
|
+
/** `rendered` is printed with the event; `keep` is stored (not printed) for a later user-initiated action. */
|
|
41
|
+
{
|
|
42
|
+
ok: true;
|
|
43
|
+
rendered: Record<string, unknown>;
|
|
44
|
+
keep?: unknown;
|
|
45
|
+
}
|
|
46
|
+
/** Invalid or unsupported: the event shows the fallback, with `extError: reason`. */
|
|
47
|
+
| {
|
|
48
|
+
ok: false;
|
|
49
|
+
reason: string;
|
|
50
|
+
};
|
|
51
|
+
export interface ExtOption {
|
|
52
|
+
/** Commander flags, e.g. "--tag <tag>" or "--yes". */
|
|
53
|
+
flags: string;
|
|
54
|
+
description: string;
|
|
55
|
+
/** May be given more than once (the value is then a string array). */
|
|
56
|
+
repeatable?: boolean;
|
|
57
|
+
default?: string | boolean;
|
|
58
|
+
}
|
|
59
|
+
export interface ExtCommand {
|
|
60
|
+
/** The subcommand name: `p2p <ns> <name>`. */
|
|
61
|
+
name: string;
|
|
62
|
+
/** Commander argument syntax, e.g. "<event>" or "[text...]". */
|
|
63
|
+
args?: string;
|
|
64
|
+
description: string;
|
|
65
|
+
options?: ExtOption[];
|
|
66
|
+
/** Commands that only read local files and run no network step (default: false). */
|
|
67
|
+
offline?: boolean;
|
|
68
|
+
run(ctx: ExtContext, args: unknown[], opts: Record<string, unknown>): Promise<{
|
|
69
|
+
json: unknown;
|
|
70
|
+
human: string;
|
|
71
|
+
}>;
|
|
72
|
+
}
|
|
73
|
+
export interface P2PExtension {
|
|
74
|
+
api: number;
|
|
75
|
+
/**
|
|
76
|
+
* The graph-target contract this extension implements (1: every Ix call takes its endpoint only from
|
|
77
|
+
* ExtContext.graphTarget). Required of the `ix` namespace (REQUIRED_GRAPH_TARGETS): an ext-ix from
|
|
78
|
+
* before it would run Ix with the caller's environment and config, which Ix Pro routes to the cloud.
|
|
79
|
+
*/
|
|
80
|
+
graphTargets?: number;
|
|
81
|
+
/** Its §8.1 namespace: the package must be `@peer2peer/ext-<ns>`. */
|
|
82
|
+
ns: string;
|
|
83
|
+
name: string;
|
|
84
|
+
version: string;
|
|
85
|
+
/** One-line description for `p2p <ns> --help`. */
|
|
86
|
+
description?: string;
|
|
87
|
+
receive?(input: ExtReceiveInput): ExtReceived;
|
|
88
|
+
commands?: ExtCommand[];
|
|
89
|
+
/**
|
|
90
|
+
* Its state kinds (§4.3 "Extension state kinds"), by kind (of its own
|
|
91
|
+
* namespace): sent with ExtContext.publish, kept latest-wins for `ttl`
|
|
92
|
+
* seconds (10-3600, default 600), never logged as events. `p2p status`
|
|
93
|
+
* advertises `<kind>.v1` for each.
|
|
94
|
+
*/
|
|
95
|
+
state?: Record<string, ExtStateKind>;
|
|
96
|
+
/**
|
|
97
|
+
* Graph memory (epic #41 piece 2): writes this device's own sessions' context (their record, status
|
|
98
|
+
* one-liners, the files they edit) into the person's local graph. `p2p watch` gathers it from the
|
|
99
|
+
* statuses this device posted, queues it (bounded) and hands it over in batches, off the hook path.
|
|
100
|
+
* Optional: an extension without it (an older ext-ix) is simply never asked. Each batch is for one
|
|
101
|
+
* session and has already been checked local by graphTarget; the extension checks again.
|
|
102
|
+
*/
|
|
103
|
+
memory?: ExtMemory;
|
|
104
|
+
}
|
|
105
|
+
/** One thing to remember about a session (graph-memory.ts). Every string is local, the person's own. */
|
|
106
|
+
export interface ExtMemoryItem {
|
|
107
|
+
kind: "start" | "status" | "files" | "end";
|
|
108
|
+
/** When it happened (ms). */
|
|
109
|
+
at: number;
|
|
110
|
+
/** start: the session's label, repository and branch. */
|
|
111
|
+
label?: string;
|
|
112
|
+
repo?: string;
|
|
113
|
+
branch?: string;
|
|
114
|
+
/** status: the one-line status. */
|
|
115
|
+
summary?: string;
|
|
116
|
+
/** files: repo-relative files edited since the last batch. */
|
|
117
|
+
files?: string[];
|
|
118
|
+
}
|
|
119
|
+
/** Why memory can't be written now; `message` says what the person can do. */
|
|
120
|
+
export interface ExtMemoryUnavailable {
|
|
121
|
+
ok: false;
|
|
122
|
+
/** e.g. `ix_missing`, `ix_upgrade` (no local `ix note`), `ix_pro` (Ix Pro answers: cloud). */
|
|
123
|
+
reason: string;
|
|
124
|
+
message: string;
|
|
125
|
+
}
|
|
126
|
+
export interface ExtMemoryResult {
|
|
127
|
+
written: number;
|
|
128
|
+
/** Items not written, by reason (counted as dropped). */
|
|
129
|
+
failed?: {
|
|
130
|
+
reason: string;
|
|
131
|
+
n: number;
|
|
132
|
+
message?: string;
|
|
133
|
+
}[];
|
|
134
|
+
/** Stop asking for now (the same as available() turning false). */
|
|
135
|
+
unavailable?: ExtMemoryUnavailable;
|
|
136
|
+
}
|
|
137
|
+
export interface ExtMemory {
|
|
138
|
+
v: 1;
|
|
139
|
+
/** Whether the writes can go to the local graph at all (asked before anything is gathered). */
|
|
140
|
+
available(ctx: ExtContext): Promise<{
|
|
141
|
+
ok: true;
|
|
142
|
+
} | ExtMemoryUnavailable>;
|
|
143
|
+
/**
|
|
144
|
+
* Writes one session's items. `signal` aborts when the host's time for the batch is up: the writer
|
|
145
|
+
* must check it before every write and write nothing after it fires (the host waits for it to settle).
|
|
146
|
+
*/
|
|
147
|
+
write(ctx: ExtContext, batch: {
|
|
148
|
+
sid: string;
|
|
149
|
+
items: ExtMemoryItem[];
|
|
150
|
+
signal?: AbortSignal;
|
|
151
|
+
}): Promise<ExtMemoryResult>;
|
|
152
|
+
}
|
|
153
|
+
/** `ext.memory` when it is a usable v1 memory writer; undefined otherwise (absent or malformed: never asked). */
|
|
154
|
+
export declare function memoryOf(ext: P2PExtension | undefined): ExtMemory | undefined;
|
|
155
|
+
export interface ExtStateKind {
|
|
156
|
+
/** Seconds a value stays valid (EXT_STATE_TTL_MIN-MAX); default EXT_STATE_TTL_DEFAULT. */
|
|
157
|
+
ttl?: number;
|
|
158
|
+
}
|
|
159
|
+
/** A received extension event, as ExtContext.events() returns it. */
|
|
160
|
+
export interface ExtEvent {
|
|
161
|
+
id: string;
|
|
162
|
+
at: number;
|
|
163
|
+
kind: string;
|
|
164
|
+
from: {
|
|
165
|
+
userId: string;
|
|
166
|
+
address: string;
|
|
167
|
+
self: boolean;
|
|
168
|
+
};
|
|
169
|
+
own?: string;
|
|
170
|
+
sid?: string;
|
|
171
|
+
ref?: string;
|
|
172
|
+
fallback: string;
|
|
173
|
+
rendered?: Record<string, unknown>;
|
|
174
|
+
/** The `keep` value `receive` returned (validated body), when it fit. */
|
|
175
|
+
kept?: {
|
|
176
|
+
v: number;
|
|
177
|
+
body: unknown;
|
|
178
|
+
};
|
|
179
|
+
extError?: string;
|
|
180
|
+
}
|
|
181
|
+
export interface ExtSendOptions {
|
|
182
|
+
fromSession: string;
|
|
183
|
+
/** name@fingerprint, userId or petname, optionally "[ref]" or /sid (as `p2p send --to`). */
|
|
184
|
+
to: string;
|
|
185
|
+
kind: ExtensionKind;
|
|
186
|
+
v: number;
|
|
187
|
+
body: unknown;
|
|
188
|
+
/** ≤200 characters of plain text (§4.3). */
|
|
189
|
+
fallback: string;
|
|
190
|
+
}
|
|
191
|
+
export interface ExtSendResult {
|
|
192
|
+
/** The folders it was given are bound for good (sessions.ts). */
|
|
193
|
+
bound?: true;
|
|
194
|
+
delivered: boolean;
|
|
195
|
+
to: {
|
|
196
|
+
userId: string;
|
|
197
|
+
address: string;
|
|
198
|
+
own: string;
|
|
199
|
+
sid: string;
|
|
200
|
+
ref: string;
|
|
201
|
+
};
|
|
202
|
+
relays: number;
|
|
203
|
+
devices: number;
|
|
204
|
+
kind: string;
|
|
205
|
+
bytes: number;
|
|
206
|
+
}
|
|
207
|
+
export interface ExtPublishOptions {
|
|
208
|
+
fromSession: string;
|
|
209
|
+
/** A state kind this extension declares. */
|
|
210
|
+
kind: ExtensionKind;
|
|
211
|
+
v: number;
|
|
212
|
+
body: unknown;
|
|
213
|
+
/** ≤200 characters of plain text: what a state-aware client without the extension shows in `ls`. */
|
|
214
|
+
fallback: string;
|
|
215
|
+
/** Seconds; default the kind's declared ttl. */
|
|
216
|
+
ttl?: number;
|
|
217
|
+
}
|
|
218
|
+
export interface ExtPublishResult {
|
|
219
|
+
kind: string;
|
|
220
|
+
bytes: number;
|
|
221
|
+
ttl: number;
|
|
222
|
+
delivered: {
|
|
223
|
+
userId: string;
|
|
224
|
+
address: string;
|
|
225
|
+
relays: number;
|
|
226
|
+
devices: number;
|
|
227
|
+
}[];
|
|
228
|
+
skipped: {
|
|
229
|
+
userId: string;
|
|
230
|
+
address: string;
|
|
231
|
+
reason: string;
|
|
232
|
+
}[];
|
|
233
|
+
failed: {
|
|
234
|
+
userId: string;
|
|
235
|
+
address: string;
|
|
236
|
+
error: string;
|
|
237
|
+
}[];
|
|
238
|
+
}
|
|
239
|
+
/** A session's stored value of one state kind. */
|
|
240
|
+
export interface ExtStateValue {
|
|
241
|
+
v: number;
|
|
242
|
+
/** The body this extension's `receive` validated and kept (absent when it refused or kept nothing). */
|
|
243
|
+
body?: unknown;
|
|
244
|
+
/** The sanitized fallback line. */
|
|
245
|
+
fallback: string;
|
|
246
|
+
/** The sender's ts (ms). */
|
|
247
|
+
at: number;
|
|
248
|
+
expiresAt: number;
|
|
249
|
+
extError?: string;
|
|
250
|
+
}
|
|
251
|
+
/** One live session's value of a state kind (ExtContext.peerState). */
|
|
252
|
+
export interface ExtPeerState extends ExtStateValue {
|
|
253
|
+
own: string;
|
|
254
|
+
sid: string;
|
|
255
|
+
ref: string;
|
|
256
|
+
address: string;
|
|
257
|
+
self: boolean;
|
|
258
|
+
thisDevice: boolean;
|
|
259
|
+
kind: string;
|
|
260
|
+
}
|
|
261
|
+
export interface ExtPeer {
|
|
262
|
+
own: string;
|
|
263
|
+
sid: string;
|
|
264
|
+
ref: string;
|
|
265
|
+
address: string;
|
|
266
|
+
self: boolean;
|
|
267
|
+
thisDevice: boolean;
|
|
268
|
+
live: boolean;
|
|
269
|
+
state: "busy" | "idle";
|
|
270
|
+
label: string;
|
|
271
|
+
repo?: string;
|
|
272
|
+
branch?: string;
|
|
273
|
+
files: string[];
|
|
274
|
+
/** What the session's client understands (§4.3 "Status caps"); absent from older clients. */
|
|
275
|
+
caps?: string[];
|
|
276
|
+
/** Its subagents (§4.3 "Status agents"), validated and sanitized; only from a session that sent them to this user. */
|
|
277
|
+
agents?: StatusAgent[];
|
|
278
|
+
/** Its stored values of this extension's state kinds (§4.3 "Extension state kinds"), by kind: live sessions, within the ttl. */
|
|
279
|
+
xstate?: Record<string, ExtStateValue>;
|
|
280
|
+
}
|
|
281
|
+
/** ExtContext.audience: who a session's status reaches. */
|
|
282
|
+
export interface ExtAudience {
|
|
283
|
+
vis: "circle" | "private";
|
|
284
|
+
circle?: string;
|
|
285
|
+
/** The circle's policy is open: anyone its owner admits sees the session. */
|
|
286
|
+
open?: true;
|
|
287
|
+
/** Other people the roster lets see the session now. */
|
|
288
|
+
people: number;
|
|
289
|
+
/** Their userIds (this user's own devices see it too, and aren't listed). */
|
|
290
|
+
members?: string[];
|
|
291
|
+
/** Distinct verified organisations among them (a trust provider's labels); absent when unknown. */
|
|
292
|
+
orgs?: number;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Which Ix graph a call may reach (projects.ts graphTarget, the chokepoint): this machine's backend,
|
|
296
|
+
* or one circle's shared graph. An extension that runs Ix takes the endpoint (and any token) only
|
|
297
|
+
* from here, never from its environment.
|
|
298
|
+
*/
|
|
299
|
+
export type ExtGraphTarget =
|
|
300
|
+
/** `trustRootListener`: the person set `ixTrustRootListener: true` in config.json (a root-owned listener on the port, Docker's proxy on Linux, is theirs). */
|
|
301
|
+
{
|
|
302
|
+
kind: "local";
|
|
303
|
+
endpoint: string;
|
|
304
|
+
why: string;
|
|
305
|
+
trustRootListener?: true;
|
|
306
|
+
} | {
|
|
307
|
+
kind: "shared";
|
|
308
|
+
circle: string;
|
|
309
|
+
endpoint: string;
|
|
310
|
+
token?: string;
|
|
311
|
+
};
|
|
312
|
+
/** What a command gets from `p2p`: no keys, no store, only these. */
|
|
313
|
+
export interface ExtContext {
|
|
314
|
+
env: Env;
|
|
315
|
+
/** The user's working directory: P2P_WORKDIR (an existing absolute directory), else the process's. */
|
|
316
|
+
cwd: string;
|
|
317
|
+
/**
|
|
318
|
+
* The graph target for a call made for session `sid` (when given), working in this context's folders
|
|
319
|
+
* (P2P_WORKDIR, P2P_PROJECT_DIRS and the process's cwd) and naming `paths` (absolute: the call's
|
|
320
|
+
* targets, `--path`, `--changed`, the child's cwd; every one is intersected in): projects.ts
|
|
321
|
+
* graphTarget. Absent on clients from before graph targets: an extension then treats every call as local.
|
|
322
|
+
*/
|
|
323
|
+
graphTarget?(opts?: {
|
|
324
|
+
sid?: string;
|
|
325
|
+
paths?: readonly string[];
|
|
326
|
+
}): Promise<ExtGraphTarget>;
|
|
327
|
+
/** stdout lines are for `--json`-less output only; use the returned `human`. */
|
|
328
|
+
io: {
|
|
329
|
+
err(s: string): void;
|
|
330
|
+
readStdin?: () => Promise<string>;
|
|
331
|
+
};
|
|
332
|
+
/** Whether --json was given (no prompts then). */
|
|
333
|
+
json: boolean;
|
|
334
|
+
/** A person at a terminal: prompts can be answered and what is printed is read (not --json, a TTY). */
|
|
335
|
+
interactive: boolean;
|
|
336
|
+
/** A small JSON store of this extension's own (<home>/ext/<ns>.json, 0600; at most 64 KiB). */
|
|
337
|
+
kv: {
|
|
338
|
+
get(key: string): Promise<unknown>;
|
|
339
|
+
set(key: string, value: unknown): Promise<void>;
|
|
340
|
+
};
|
|
341
|
+
/** Asks the user (y/N). False when there is no terminal, unless `yes`. */
|
|
342
|
+
confirm(question: string, yes?: boolean): Promise<boolean>;
|
|
343
|
+
self(): Promise<{
|
|
344
|
+
userId: string;
|
|
345
|
+
address: string;
|
|
346
|
+
}>;
|
|
347
|
+
/** Sends an `x:<ns>.*` envelope of this extension's namespace (§4.2-authorised, like `p2p send`). Not for state kinds: see publish. */
|
|
348
|
+
send(opts: ExtSendOptions): Promise<ExtSendResult>;
|
|
349
|
+
/**
|
|
350
|
+
* Publishes the session's latest value of one of this extension's state
|
|
351
|
+
* kinds to the session's status audience, to recipients that advertise
|
|
352
|
+
* xstate.v1 only (§4.3 "Extension state kinds"). At most once every 5 s per
|
|
353
|
+
* kind and session (`rate_limited`), at most 16 KiB.
|
|
354
|
+
*/
|
|
355
|
+
publish(opts: ExtPublishOptions): Promise<ExtPublishResult>;
|
|
356
|
+
/** Live sessions' stored values of one of this extension's state kinds (this user's own included). */
|
|
357
|
+
peerState(kind: string): Promise<ExtPeerState[]>;
|
|
358
|
+
/** Received events of this extension's kinds, newest last. */
|
|
359
|
+
events(filter?: {
|
|
360
|
+
id?: string;
|
|
361
|
+
kind?: string;
|
|
362
|
+
}): Promise<ExtEvent[]>;
|
|
363
|
+
/** Peer sessions from the local status table (receives what's queued first). */
|
|
364
|
+
peers(opts?: {
|
|
365
|
+
all?: boolean;
|
|
366
|
+
}): Promise<ExtPeer[]>;
|
|
367
|
+
/**
|
|
368
|
+
* Who an own session's status (and so its state kinds) reaches: the roster's visibility,
|
|
369
|
+
* its circle and whether that circle is open, and how many other people it lets see the
|
|
370
|
+
* session. Undefined for a session with no roster yet, or whose circle can't be loaded. `orgs`, the number of distinct
|
|
371
|
+
* verified organisations among them, is set only once a trust provider supplies org labels.
|
|
372
|
+
*/
|
|
373
|
+
audience?(sid: string): Promise<ExtAudience | undefined>;
|
|
374
|
+
/**
|
|
375
|
+
* A MAC over `data` keyed by this device's secret (never shown to the extension): base64url
|
|
376
|
+
* HMAC-SHA256 under a key derived from the device signing key and the extension's namespace.
|
|
377
|
+
* For settings an extension keeps in its own store that must come from the person running
|
|
378
|
+
* `p2p` rather than from anything that can write files in P2P_HOME without the keys (a model's
|
|
379
|
+
* file tools): store the MAC with the setting and honour the setting only when it verifies.
|
|
380
|
+
*/
|
|
381
|
+
localMac?(data: string): string;
|
|
382
|
+
/**
|
|
383
|
+
* Whether session `fromSid` may pass on context recorded for session `ofSid` (graph memory's
|
|
384
|
+
* records, ExtMemory): the same session, or both bound to projects whose ceilings are shared, with
|
|
385
|
+
* `fromSid`'s audience within `ofSid`'s and the same graph target. Absent on older clients: a
|
|
386
|
+
* caller then refuses anything but the same session.
|
|
387
|
+
*/
|
|
388
|
+
mayShareSessionContext?(ofSid: string, fromSid: string): Promise<boolean>;
|
|
389
|
+
/** Own sessions' last posted statuses on this device. */
|
|
390
|
+
ownStatus(sid: string): Promise<{
|
|
391
|
+
repo?: string;
|
|
392
|
+
files: string[];
|
|
393
|
+
caps?: string[];
|
|
394
|
+
agents?: StatusAgent[];
|
|
395
|
+
} | undefined>;
|
|
396
|
+
}
|
|
397
|
+
export interface LoadedExtension {
|
|
398
|
+
ext: P2PExtension;
|
|
399
|
+
/** Where it was loaded from (a file path). */
|
|
400
|
+
from: string;
|
|
401
|
+
}
|
|
402
|
+
export declare class ExtensionRegistry {
|
|
403
|
+
private readonly byNs;
|
|
404
|
+
constructor(list?: readonly LoadedExtension[]);
|
|
405
|
+
get(ns: string): P2PExtension | undefined;
|
|
406
|
+
forKind(kind: string): P2PExtension | undefined;
|
|
407
|
+
list(): LoadedExtension[];
|
|
408
|
+
}
|
|
409
|
+
export interface LoadOptions {
|
|
410
|
+
env: Env;
|
|
411
|
+
/** P2P_HOME: where config.json (`extensions`) and the record of load locations live. */
|
|
412
|
+
home?: string;
|
|
413
|
+
/** config.json as read (its `extensions` list enables namespaces). */
|
|
414
|
+
config?: {
|
|
415
|
+
extensions?: unknown;
|
|
416
|
+
};
|
|
417
|
+
/** Always shown (stderr): enabled-but-missing, a bad base, the first load from a new location. */
|
|
418
|
+
warn?: (msg: string) => void;
|
|
419
|
+
/** Debug output (P2P_DEBUG=1). */
|
|
420
|
+
log?: (msg: string) => void;
|
|
421
|
+
/** Overrides where this CLI is installed (tests). */
|
|
422
|
+
selfUrl?: string;
|
|
423
|
+
}
|
|
424
|
+
/** Namespaces that run Ix, and the graph-target contract version each must declare to load. */
|
|
425
|
+
export declare const REQUIRED_GRAPH_TARGETS: Readonly<Record<string, number>>;
|
|
426
|
+
/** Validates what a module exports; undefined (with a reason) when it isn't a usable extension. */
|
|
427
|
+
export declare function checkExtension(mod: unknown, ns: string): {
|
|
428
|
+
ext?: P2PExtension;
|
|
429
|
+
why?: string;
|
|
430
|
+
};
|
|
431
|
+
/**
|
|
432
|
+
* The namespaces the user enabled (opt-in): P2P_EXTENSIONS when set ("none"
|
|
433
|
+
* or "" = none; "config" = defer to config.json), else `extensions` in
|
|
434
|
+
* config.json, else none. Only
|
|
435
|
+
* namespaces registered in protocol §8.3 count; others are ignored (`ignored`).
|
|
436
|
+
*/
|
|
437
|
+
export declare function enabledNamespaces(env: Env, config?: {
|
|
438
|
+
extensions?: unknown;
|
|
439
|
+
}): {
|
|
440
|
+
enabled: string[];
|
|
441
|
+
ignored: string[];
|
|
442
|
+
};
|
|
443
|
+
/**
|
|
444
|
+
* The CLI's own sibling node_modules, when it is installed as a package
|
|
445
|
+
* (`…/node_modules/@peer2peer/cli/dist/extensions.js` → `…/node_modules`):
|
|
446
|
+
* where a global `npm i -g @peer2peer/cli @peer2peer/ext-ix` puts both.
|
|
447
|
+
* Nothing for a checkout or the bundled single file.
|
|
448
|
+
*/
|
|
449
|
+
export declare function siblingNodeModules(selfFile: string): string | undefined;
|
|
450
|
+
/** Whether `p` is `dir` or inside it, comparing real paths (a symlink can't hide where it points). */
|
|
451
|
+
export declare function isInside(p: string, dir: string): boolean;
|
|
452
|
+
/**
|
|
453
|
+
* The node_modules directories searched, in order: P2P_EXTENSION_PATH's, then the CLI's sibling one.
|
|
454
|
+
* P2P_EXTENSION_EXCLUDE (path-delimiter separated) drops entries inside those directories, by real
|
|
455
|
+
* path: a client passes the session's repository, so a cloned repo can't supply an extension.
|
|
456
|
+
*/
|
|
457
|
+
export declare function extensionDirs(env: Env, selfUrl: string): string[];
|
|
458
|
+
export declare class ExtResolveError extends Error {
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Resolves `name` inside one node_modules directory only: no walk-up, no
|
|
462
|
+
* NODE_PATH, no global folders. The package's entry (exports "." import /
|
|
463
|
+
* default, else main, else index.js) must be a file inside the package.
|
|
464
|
+
* Undefined when the package isn't there; ExtResolveError when it is but is
|
|
465
|
+
* malformed.
|
|
466
|
+
*/
|
|
467
|
+
export declare function resolveIn(nodeModules: string, name: string): string | undefined;
|
|
468
|
+
/**
|
|
469
|
+
* Loads the extensions the user enabled, from the explicit directories only.
|
|
470
|
+
* Never throws: an enabled one that isn't found, a bad directory, or a broken
|
|
471
|
+
* package is a warning, and the rest still load.
|
|
472
|
+
*/
|
|
473
|
+
export declare function loadExtensions(opts: LoadOptions): Promise<ExtensionRegistry>;
|
|
474
|
+
/** `p2p extensions enable|disable <ns>`: edits `extensions` in <home>/config.json. */
|
|
475
|
+
export declare function setExtensionEnabled(home: string, ns: string, on: boolean): string[];
|
|
476
|
+
/** Every string sanitized and capped; depth- and size-bounded; non-JSON values dropped. */
|
|
477
|
+
export declare function sanitizeRendered(v: unknown, depth?: number): unknown;
|
|
478
|
+
export interface RenderOutcome {
|
|
479
|
+
rendered?: Record<string, unknown>;
|
|
480
|
+
kept?: {
|
|
481
|
+
v: number;
|
|
482
|
+
body: unknown;
|
|
483
|
+
};
|
|
484
|
+
extError?: string;
|
|
485
|
+
}
|
|
486
|
+
/** Runs the extension's `receive` defensively. Without one, nothing (the fallback stands). */
|
|
487
|
+
export declare function renderExtension(reg: ExtensionRegistry | undefined, input: ExtReceiveInput): RenderOutcome;
|