@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.
Files changed (105) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +366 -2
  3. package/dist/ancestry.d.ts +13 -0
  4. package/dist/ancestry.js +71 -0
  5. package/dist/app.d.ts +363 -0
  6. package/dist/app.js +1177 -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 +611 -0
  12. package/dist/cli.js +1650 -0
  13. package/dist/codes.d.ts +231 -0
  14. package/dist/codes.js +998 -0
  15. package/dist/config.d.ts +112 -0
  16. package/dist/config.js +243 -0
  17. package/dist/doctor.d.ts +99 -0
  18. package/dist/doctor.js +817 -0
  19. package/dist/errors.d.ts +8 -0
  20. package/dist/errors.js +29 -0
  21. package/dist/ext-host.d.ts +32 -0
  22. package/dist/ext-host.js +259 -0
  23. package/dist/extensions.d.ts +386 -0
  24. package/dist/extensions.js +395 -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/identity.d.ts +236 -0
  30. package/dist/identity.js +751 -0
  31. package/dist/inbound.d.ts +32 -0
  32. package/dist/inbound.js +258 -0
  33. package/dist/index.d.ts +8 -0
  34. package/dist/index.js +14 -0
  35. package/dist/join-answers.d.ts +49 -0
  36. package/dist/join-answers.js +149 -0
  37. package/dist/outbox.d.ts +109 -0
  38. package/dist/outbox.js +337 -0
  39. package/dist/pretty.d.ts +100 -0
  40. package/dist/pretty.js +256 -0
  41. package/dist/procstart.d.ts +1 -0
  42. package/dist/procstart.js +66 -0
  43. package/dist/progress.d.ts +30 -0
  44. package/dist/progress.js +78 -0
  45. package/dist/projects.d.ts +240 -0
  46. package/dist/projects.js +699 -0
  47. package/dist/prompt/picker.d.ts +64 -0
  48. package/dist/prompt/picker.js +152 -0
  49. package/dist/prompt/tty.d.ts +29 -0
  50. package/dist/prompt/tty.js +122 -0
  51. package/dist/readonly.d.ts +20 -0
  52. package/dist/readonly.js +50 -0
  53. package/dist/receipts.d.ts +99 -0
  54. package/dist/receipts.js +180 -0
  55. package/dist/relay-client.d.ts +277 -0
  56. package/dist/relay-client.js +873 -0
  57. package/dist/relay-info.d.ts +24 -0
  58. package/dist/relay-info.js +53 -0
  59. package/dist/rotation.d.ts +402 -0
  60. package/dist/rotation.js +2054 -0
  61. package/dist/running.d.ts +5 -0
  62. package/dist/running.js +74 -0
  63. package/dist/sessions.d.ts +340 -0
  64. package/dist/sessions.js +1152 -0
  65. package/dist/shortcode.d.ts +149 -0
  66. package/dist/shortcode.js +465 -0
  67. package/dist/social.d.ts +139 -0
  68. package/dist/social.js +485 -0
  69. package/dist/state.d.ts +483 -0
  70. package/dist/state.js +217 -0
  71. package/dist/stdin.d.ts +17 -0
  72. package/dist/stdin.js +46 -0
  73. package/dist/sync.d.ts +77 -0
  74. package/dist/sync.js +375 -0
  75. package/dist/transient.d.ts +1 -0
  76. package/dist/transient.js +28 -0
  77. package/dist/trust.d.ts +37 -0
  78. package/dist/trust.js +134 -0
  79. package/dist/tty-confirm.d.ts +2 -0
  80. package/dist/tty-confirm.js +53 -0
  81. package/dist/tui/command.d.ts +20 -0
  82. package/dist/tui/command.js +70 -0
  83. package/dist/tui/frame.d.ts +43 -0
  84. package/dist/tui/frame.js +111 -0
  85. package/dist/tui/model.d.ts +215 -0
  86. package/dist/tui/model.js +255 -0
  87. package/dist/tui/sanitize.d.ts +13 -0
  88. package/dist/tui/sanitize.js +151 -0
  89. package/dist/tui/terminal.d.ts +88 -0
  90. package/dist/tui/terminal.js +354 -0
  91. package/dist/tui/tui.d.ts +71 -0
  92. package/dist/tui/tui.js +571 -0
  93. package/dist/tui/view.d.ts +4 -0
  94. package/dist/tui/view.js +356 -0
  95. package/dist/unknown-kinds.d.ts +12 -0
  96. package/dist/unknown-kinds.js +66 -0
  97. package/dist/version.d.ts +1 -0
  98. package/dist/version.js +5 -0
  99. package/dist/want-pow.d.ts +12 -0
  100. package/dist/want-pow.js +46 -0
  101. package/dist/watch.d.ts +35 -0
  102. package/dist/watch.js +325 -0
  103. package/dist/xstate.d.ts +125 -0
  104. package/dist/xstate.js +422 -0
  105. package/package.json +60 -4
@@ -0,0 +1,386 @@
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
+ /** Its §8.1 namespace: the package must be `@peer2peer/ext-<ns>`. */
76
+ ns: string;
77
+ name: string;
78
+ version: string;
79
+ /** One-line description for `p2p <ns> --help`. */
80
+ description?: string;
81
+ receive?(input: ExtReceiveInput): ExtReceived;
82
+ commands?: ExtCommand[];
83
+ /**
84
+ * Its state kinds (§4.3 "Extension state kinds"), by kind (of its own
85
+ * namespace): sent with ExtContext.publish, kept latest-wins for `ttl`
86
+ * seconds (10-3600, default 600), never logged as events. `p2p status`
87
+ * advertises `<kind>.v1` for each.
88
+ */
89
+ state?: Record<string, ExtStateKind>;
90
+ }
91
+ export interface ExtStateKind {
92
+ /** Seconds a value stays valid (EXT_STATE_TTL_MIN-MAX); default EXT_STATE_TTL_DEFAULT. */
93
+ ttl?: number;
94
+ }
95
+ /** A received extension event, as ExtContext.events() returns it. */
96
+ export interface ExtEvent {
97
+ id: string;
98
+ at: number;
99
+ kind: string;
100
+ from: {
101
+ userId: string;
102
+ address: string;
103
+ self: boolean;
104
+ };
105
+ own?: string;
106
+ sid?: string;
107
+ ref?: string;
108
+ fallback: string;
109
+ rendered?: Record<string, unknown>;
110
+ /** The `keep` value `receive` returned (validated body), when it fit. */
111
+ kept?: {
112
+ v: number;
113
+ body: unknown;
114
+ };
115
+ extError?: string;
116
+ }
117
+ export interface ExtSendOptions {
118
+ fromSession: string;
119
+ /** name@fingerprint, userId or petname, optionally "[ref]" or /sid (as `p2p send --to`). */
120
+ to: string;
121
+ kind: ExtensionKind;
122
+ v: number;
123
+ body: unknown;
124
+ /** ≤200 characters of plain text (§4.3). */
125
+ fallback: string;
126
+ }
127
+ export interface ExtSendResult {
128
+ /** The folders it was given are bound for good (sessions.ts). */
129
+ bound?: true;
130
+ delivered: boolean;
131
+ to: {
132
+ userId: string;
133
+ address: string;
134
+ own: string;
135
+ sid: string;
136
+ ref: string;
137
+ };
138
+ relays: number;
139
+ devices: number;
140
+ kind: string;
141
+ bytes: number;
142
+ }
143
+ export interface ExtPublishOptions {
144
+ fromSession: string;
145
+ /** A state kind this extension declares. */
146
+ kind: ExtensionKind;
147
+ v: number;
148
+ body: unknown;
149
+ /** ≤200 characters of plain text: what a state-aware client without the extension shows in `ls`. */
150
+ fallback: string;
151
+ /** Seconds; default the kind's declared ttl. */
152
+ ttl?: number;
153
+ }
154
+ export interface ExtPublishResult {
155
+ kind: string;
156
+ bytes: number;
157
+ ttl: number;
158
+ delivered: {
159
+ userId: string;
160
+ address: string;
161
+ relays: number;
162
+ devices: number;
163
+ }[];
164
+ skipped: {
165
+ userId: string;
166
+ address: string;
167
+ reason: string;
168
+ }[];
169
+ failed: {
170
+ userId: string;
171
+ address: string;
172
+ error: string;
173
+ }[];
174
+ }
175
+ /** A session's stored value of one state kind. */
176
+ export interface ExtStateValue {
177
+ v: number;
178
+ /** The body this extension's `receive` validated and kept (absent when it refused or kept nothing). */
179
+ body?: unknown;
180
+ /** The sanitized fallback line. */
181
+ fallback: string;
182
+ /** The sender's ts (ms). */
183
+ at: number;
184
+ expiresAt: number;
185
+ extError?: string;
186
+ }
187
+ /** One live session's value of a state kind (ExtContext.peerState). */
188
+ export interface ExtPeerState extends ExtStateValue {
189
+ own: string;
190
+ sid: string;
191
+ ref: string;
192
+ address: string;
193
+ self: boolean;
194
+ thisDevice: boolean;
195
+ kind: string;
196
+ }
197
+ export interface ExtPeer {
198
+ own: string;
199
+ sid: string;
200
+ ref: string;
201
+ address: string;
202
+ self: boolean;
203
+ thisDevice: boolean;
204
+ live: boolean;
205
+ state: "busy" | "idle";
206
+ label: string;
207
+ repo?: string;
208
+ branch?: string;
209
+ files: string[];
210
+ /** What the session's client understands (§4.3 "Status caps"); absent from older clients. */
211
+ caps?: string[];
212
+ /** Its subagents (§4.3 "Status agents"), validated and sanitized; only from a session that sent them to this user. */
213
+ agents?: StatusAgent[];
214
+ /** Its stored values of this extension's state kinds (§4.3 "Extension state kinds"), by kind: live sessions, within the ttl. */
215
+ xstate?: Record<string, ExtStateValue>;
216
+ }
217
+ /** ExtContext.audience: who a session's status reaches. */
218
+ export interface ExtAudience {
219
+ vis: "circle" | "private";
220
+ circle?: string;
221
+ /** The circle's policy is open: anyone its owner admits sees the session. */
222
+ open?: true;
223
+ /** Other people the roster lets see the session now. */
224
+ people: number;
225
+ /** Their userIds (this user's own devices see it too, and aren't listed). */
226
+ members?: string[];
227
+ /** Distinct verified organisations among them (a trust provider's labels); absent when unknown. */
228
+ orgs?: number;
229
+ }
230
+ /** What a command gets from `p2p`: no keys, no store, only these. */
231
+ export interface ExtContext {
232
+ env: Env;
233
+ /** The user's working directory: P2P_WORKDIR (an existing absolute directory), else the process's. */
234
+ cwd: string;
235
+ /** stdout lines are for `--json`-less output only; use the returned `human`. */
236
+ io: {
237
+ err(s: string): void;
238
+ readStdin?: () => Promise<string>;
239
+ };
240
+ /** Whether --json was given (no prompts then). */
241
+ json: boolean;
242
+ /** A person at a terminal: prompts can be answered and what is printed is read (not --json, a TTY). */
243
+ interactive: boolean;
244
+ /** A small JSON store of this extension's own (<home>/ext/<ns>.json, 0600; at most 64 KiB). */
245
+ kv: {
246
+ get(key: string): Promise<unknown>;
247
+ set(key: string, value: unknown): Promise<void>;
248
+ };
249
+ /** Asks the user (y/N). False when there is no terminal, unless `yes`. */
250
+ confirm(question: string, yes?: boolean): Promise<boolean>;
251
+ self(): Promise<{
252
+ userId: string;
253
+ address: string;
254
+ }>;
255
+ /** Sends an `x:<ns>.*` envelope of this extension's namespace (§4.2-authorised, like `p2p send`). Not for state kinds: see publish. */
256
+ send(opts: ExtSendOptions): Promise<ExtSendResult>;
257
+ /**
258
+ * Publishes the session's latest value of one of this extension's state
259
+ * kinds to the session's status audience, to recipients that advertise
260
+ * xstate.v1 only (§4.3 "Extension state kinds"). At most once every 5 s per
261
+ * kind and session (`rate_limited`), at most 16 KiB.
262
+ */
263
+ publish(opts: ExtPublishOptions): Promise<ExtPublishResult>;
264
+ /** Live sessions' stored values of one of this extension's state kinds (this user's own included). */
265
+ peerState(kind: string): Promise<ExtPeerState[]>;
266
+ /** Received events of this extension's kinds, newest last. */
267
+ events(filter?: {
268
+ id?: string;
269
+ kind?: string;
270
+ }): Promise<ExtEvent[]>;
271
+ /** Peer sessions from the local status table (receives what's queued first). */
272
+ peers(opts?: {
273
+ all?: boolean;
274
+ }): Promise<ExtPeer[]>;
275
+ /**
276
+ * Who an own session's status (and so its state kinds) reaches: the roster's visibility,
277
+ * its circle and whether that circle is open, and how many other people it lets see the
278
+ * session. Undefined for a session with no roster yet, or whose circle can't be loaded. `orgs`, the number of distinct
279
+ * verified organisations among them, is set only once a trust provider supplies org labels.
280
+ */
281
+ audience?(sid: string): Promise<ExtAudience | undefined>;
282
+ /**
283
+ * A MAC over `data` keyed by this device's secret (never shown to the extension): base64url
284
+ * HMAC-SHA256 under a key derived from the device signing key and the extension's namespace.
285
+ * For settings an extension keeps in its own store that must come from the person running
286
+ * `p2p` rather than from anything that can write files in P2P_HOME without the keys (a model's
287
+ * file tools): store the MAC with the setting and honour the setting only when it verifies.
288
+ */
289
+ localMac?(data: string): string;
290
+ /** Own sessions' last posted statuses on this device. */
291
+ ownStatus(sid: string): Promise<{
292
+ repo?: string;
293
+ files: string[];
294
+ caps?: string[];
295
+ agents?: StatusAgent[];
296
+ } | undefined>;
297
+ }
298
+ export interface LoadedExtension {
299
+ ext: P2PExtension;
300
+ /** Where it was loaded from (a file path). */
301
+ from: string;
302
+ }
303
+ export declare class ExtensionRegistry {
304
+ private readonly byNs;
305
+ constructor(list?: readonly LoadedExtension[]);
306
+ get(ns: string): P2PExtension | undefined;
307
+ forKind(kind: string): P2PExtension | undefined;
308
+ list(): LoadedExtension[];
309
+ }
310
+ export interface LoadOptions {
311
+ env: Env;
312
+ /** P2P_HOME: where config.json (`extensions`) and the record of load locations live. */
313
+ home?: string;
314
+ /** config.json as read (its `extensions` list enables namespaces). */
315
+ config?: {
316
+ extensions?: unknown;
317
+ };
318
+ /** Always shown (stderr): enabled-but-missing, a bad base, the first load from a new location. */
319
+ warn?: (msg: string) => void;
320
+ /** Debug output (P2P_DEBUG=1). */
321
+ log?: (msg: string) => void;
322
+ /** Overrides where this CLI is installed (tests). */
323
+ selfUrl?: string;
324
+ }
325
+ /** Validates what a module exports; undefined (with a reason) when it isn't a usable extension. */
326
+ export declare function checkExtension(mod: unknown, ns: string): {
327
+ ext?: P2PExtension;
328
+ why?: string;
329
+ };
330
+ /**
331
+ * The namespaces the user enabled (opt-in): P2P_EXTENSIONS when set ("none"
332
+ * or "" = none; "config" = defer to config.json), else `extensions` in
333
+ * config.json, else none. Only
334
+ * namespaces registered in protocol §8.3 count; others are ignored (`ignored`).
335
+ */
336
+ export declare function enabledNamespaces(env: Env, config?: {
337
+ extensions?: unknown;
338
+ }): {
339
+ enabled: string[];
340
+ ignored: string[];
341
+ };
342
+ /**
343
+ * The CLI's own sibling node_modules, when it is installed as a package
344
+ * (`…/node_modules/@peer2peer/cli/dist/extensions.js` → `…/node_modules`):
345
+ * where a global `npm i -g @peer2peer/cli @peer2peer/ext-ix` puts both.
346
+ * Nothing for a checkout or the bundled single file.
347
+ */
348
+ export declare function siblingNodeModules(selfFile: string): string | undefined;
349
+ /** Whether `p` is `dir` or inside it, comparing real paths (a symlink can't hide where it points). */
350
+ export declare function isInside(p: string, dir: string): boolean;
351
+ /**
352
+ * The node_modules directories searched, in order: P2P_EXTENSION_PATH's, then the CLI's sibling one.
353
+ * P2P_EXTENSION_EXCLUDE (path-delimiter separated) drops entries inside those directories, by real
354
+ * path: a client passes the session's repository, so a cloned repo can't supply an extension.
355
+ */
356
+ export declare function extensionDirs(env: Env, selfUrl: string): string[];
357
+ export declare class ExtResolveError extends Error {
358
+ }
359
+ /**
360
+ * Resolves `name` inside one node_modules directory only: no walk-up, no
361
+ * NODE_PATH, no global folders. The package's entry (exports "." import /
362
+ * default, else main, else index.js) must be a file inside the package.
363
+ * Undefined when the package isn't there; ExtResolveError when it is but is
364
+ * malformed.
365
+ */
366
+ export declare function resolveIn(nodeModules: string, name: string): string | undefined;
367
+ /**
368
+ * Loads the extensions the user enabled, from the explicit directories only.
369
+ * Never throws: an enabled one that isn't found, a bad directory, or a broken
370
+ * package is a warning, and the rest still load.
371
+ */
372
+ export declare function loadExtensions(opts: LoadOptions): Promise<ExtensionRegistry>;
373
+ /** `p2p extensions enable|disable <ns>`: edits `extensions` in <home>/config.json. */
374
+ export declare function setExtensionEnabled(home: string, ns: string, on: boolean): string[];
375
+ /** Every string sanitized and capped; depth- and size-bounded; non-JSON values dropped. */
376
+ export declare function sanitizeRendered(v: unknown, depth?: number): unknown;
377
+ export interface RenderOutcome {
378
+ rendered?: Record<string, unknown>;
379
+ kept?: {
380
+ v: number;
381
+ body: unknown;
382
+ };
383
+ extError?: string;
384
+ }
385
+ /** Runs the extension's `receive` defensively. Without one, nothing (the fallback stands). */
386
+ export declare function renderExtension(reg: ExtensionRegistry | undefined, input: ExtReceiveInput): RenderOutcome;