@peer2peer/cli 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -15
- package/dist/app.d.ts +83 -0
- package/dist/app.js +155 -40
- package/dist/cli.d.ts +76 -6
- package/dist/cli.js +386 -34
- package/dist/config.d.ts +52 -0
- package/dist/config.js +51 -0
- package/dist/doctor.d.ts +84 -1
- package/dist/doctor.js +198 -6
- package/dist/ext-host.d.ts +6 -0
- package/dist/ext-host.js +41 -3
- package/dist/extensions.d.ts +101 -0
- package/dist/extensions.js +13 -2
- 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 +31 -2
- package/dist/identity.js +80 -10
- package/dist/inbound.js +4 -1
- package/dist/ix-local.d.ts +128 -0
- package/dist/ix-local.js +260 -0
- package/dist/pretty.d.ts +3 -1
- package/dist/pretty.js +9 -2
- package/dist/projects.d.ts +330 -12
- package/dist/projects.js +1044 -74
- package/dist/receipts.js +3 -1
- package/dist/rotation.js +15 -7
- package/dist/sessions.d.ts +28 -5
- package/dist/sessions.js +182 -30
- package/dist/social.js +11 -0
- package/dist/state.d.ts +26 -0
- package/dist/state.js +3 -0
- package/dist/tui/model.d.ts +7 -1
- package/dist/tui/model.js +8 -4
- package/dist/tui/tui.d.ts +9 -2
- package/dist/tui/tui.js +47 -6
- package/dist/tui/view.js +6 -4
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/watch.js +6 -0
- package/package.json +6 -3
package/dist/identity.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type DisplayProfile, type ProofFetchers } from "@peer2peer/core/v3";
|
|
2
2
|
import { type App } from "./app.js";
|
|
3
|
+
import { type SetupIx } from "./ix-local.js";
|
|
3
4
|
export interface InitResult {
|
|
4
5
|
userId: string;
|
|
5
6
|
address: string;
|
|
@@ -12,6 +13,13 @@ export interface InitResult {
|
|
|
12
13
|
code: string;
|
|
13
14
|
}[];
|
|
14
15
|
}
|
|
16
|
+
/** The `p2p` command as the person types it here (Windows PowerShell blocks npm's p2p.ps1 shim; p2p.cmd works everywhere on Windows). */
|
|
17
|
+
export declare function p2pCommand(platform?: NodeJS.Platform): string;
|
|
18
|
+
/**
|
|
19
|
+
* Why a new identity can't be made here (no relay anywhere), naming the three ways in. There is
|
|
20
|
+
* no default relay, by design (bring your own relay).
|
|
21
|
+
*/
|
|
22
|
+
export declare function noRelaysReason(home: string, platform?: NodeJS.Platform): string;
|
|
15
23
|
export declare function init(app: App, opts: {
|
|
16
24
|
name?: string;
|
|
17
25
|
relays?: string[];
|
|
@@ -34,13 +42,21 @@ export interface SetupResult {
|
|
|
34
42
|
file?: string;
|
|
35
43
|
phrase?: string;
|
|
36
44
|
};
|
|
45
|
+
/** Ix, optional and recommended (ix-local.ts setupIx): found, enabled, recommended (with the command for the person to run), and what to do when it isn't on. Never installed for them. */
|
|
46
|
+
ix?: SetupIx;
|
|
47
|
+
/** This device is the only key holder and the backup phrase was never shown or saved (`p2p backup show`). */
|
|
48
|
+
backupNeeded?: true;
|
|
37
49
|
}
|
|
38
50
|
export declare const BACKUP_FILE_NAME = "backup-phrase.txt";
|
|
51
|
+
export type BackupMode = "file" | "print" | "none";
|
|
39
52
|
export declare function setup(app: App, opts: {
|
|
40
53
|
name?: string;
|
|
41
54
|
relays?: string[];
|
|
42
|
-
backup?:
|
|
55
|
+
backup?: BackupMode;
|
|
43
56
|
backupFile?: string;
|
|
57
|
+
ix?: boolean;
|
|
58
|
+
/** Asked only once an identity was created here (never before its key exists), when `backup` isn't given. */
|
|
59
|
+
chooseBackup?: (created: InitResult) => Promise<BackupMode>;
|
|
44
60
|
}): Promise<SetupResult>;
|
|
45
61
|
export declare function relaysList(app: App): Promise<{
|
|
46
62
|
relays: string[];
|
|
@@ -140,10 +156,22 @@ export declare function linkStart(app: App, opts?: {
|
|
|
140
156
|
keyholder?: boolean;
|
|
141
157
|
relay?: string;
|
|
142
158
|
}): Promise<LinkStart>;
|
|
159
|
+
/** The identity a link code would make this device part of, shown before anything is kept (LinkJoin.wait). */
|
|
160
|
+
export interface LinkIdentity {
|
|
161
|
+
userId: string;
|
|
162
|
+
address: string;
|
|
163
|
+
fingerprint: string;
|
|
164
|
+
/** This device would get the identity key. */
|
|
165
|
+
keyholder: boolean;
|
|
166
|
+
}
|
|
143
167
|
export interface LinkJoin {
|
|
144
168
|
compareCode: string;
|
|
145
169
|
did: string;
|
|
146
|
-
|
|
170
|
+
/**
|
|
171
|
+
* Waits for the other device, then, with `confirm`, shows which identity this device would
|
|
172
|
+
* become and keeps nothing unless it says yes (a code from someone else makes this device theirs).
|
|
173
|
+
*/
|
|
174
|
+
wait(confirm?: (who: LinkIdentity) => Promise<boolean>): Promise<{
|
|
147
175
|
userId: string;
|
|
148
176
|
address: string;
|
|
149
177
|
did: string;
|
|
@@ -153,6 +181,7 @@ export interface LinkJoin {
|
|
|
153
181
|
export declare function linkJoin(app: App, code: string, opts?: {
|
|
154
182
|
label?: string;
|
|
155
183
|
maxWaitMs?: number;
|
|
184
|
+
allowPrivateRelay?: boolean;
|
|
156
185
|
}): Promise<LinkJoin>;
|
|
157
186
|
export declare function backupShow(app: App): Promise<{
|
|
158
187
|
phrase: string;
|
package/dist/identity.js
CHANGED
|
@@ -9,17 +9,33 @@ import { addIdentityVersion, b64uEncode, backupPhraseFromSeed, canonicalProofLoc
|
|
|
9
9
|
import { capPeek, certDid, defaultLabel, defaultName, joinCapOf, newKeysDoc } from "./app.js";
|
|
10
10
|
import { defaultRelays, normalizeRelays } from "./config.js";
|
|
11
11
|
import { CliError } from "./errors.js";
|
|
12
|
+
import { isOwnRelay, isPrivateRelayHost, PRIVATE_RESOLVE_MARK, privateGuardLookup, privateRelayMessage } from "./shortcode.js";
|
|
12
13
|
import { fetchTips, linkGet, linkPut, openLinkConnection, relayCode, sleep } from "./relay-client.js";
|
|
13
14
|
import { exportAll, sendSync, verifiedIssuedCap } from "./sync.js";
|
|
14
15
|
import { receiving } from "./inbound.js";
|
|
15
16
|
import { recordJoin, resignJoin } from "./circle-ops.js";
|
|
17
|
+
import { setupIx } from "./ix-local.js";
|
|
18
|
+
import { renewPersonToken } from "./projects.js";
|
|
19
|
+
/** The `p2p` command as the person types it here (Windows PowerShell blocks npm's p2p.ps1 shim; p2p.cmd works everywhere on Windows). */
|
|
20
|
+
export function p2pCommand(platform = process.platform) {
|
|
21
|
+
return platform === "win32" ? "p2p.cmd" : "p2p";
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Why a new identity can't be made here (no relay anywhere), naming the three ways in. There is
|
|
25
|
+
* no default relay, by design (bring your own relay).
|
|
26
|
+
*/
|
|
27
|
+
export function noRelaysReason(home, platform = process.platform) {
|
|
28
|
+
const p = p2pCommand(platform);
|
|
29
|
+
return (`no relays configured. Already use Peer2Peer on another device? Run \`p2p link start\` there, then \`${p} link join <code>\` here (one identity, not a second one). ` +
|
|
30
|
+
`Have an invite? \`${p} join <invite link or code>\`. ` +
|
|
31
|
+
`Starting a new identity? Pass --relay wss://… (1–5, your group's relay), or set P2P_DEFAULT_RELAYS, or "defaultRelays" in ${home}/config.json`);
|
|
32
|
+
}
|
|
16
33
|
export async function init(app, opts) {
|
|
17
34
|
if (await app.load(false))
|
|
18
35
|
throw new CliError("already_initialized", `${app.home} already holds an identity (${app.userId})`);
|
|
19
36
|
const relays = opts.relays && opts.relays.length > 0 ? normalizeRelays(opts.relays) : defaultRelays(app.env, app.file);
|
|
20
|
-
if (relays.length === 0)
|
|
21
|
-
throw new CliError("no_relays",
|
|
22
|
-
}
|
|
37
|
+
if (relays.length === 0)
|
|
38
|
+
throw new CliError("no_relays", noRelaysReason(app.home));
|
|
23
39
|
const name = opts.name ?? defaultName();
|
|
24
40
|
if (!isValidName(name))
|
|
25
41
|
throw new CliError("usage", "--name must match [a-z0-9._-]{1,32}");
|
|
@@ -29,6 +45,9 @@ export async function init(app, opts) {
|
|
|
29
45
|
const doc = createIdentityDoc(ik, { ver: 1, prev: null, name, relays, devices: [device.did], keyholders: [device.did], by: device.did, certs: [cert] });
|
|
30
46
|
const keys = newKeysDoc(ik.userId, device, cert, ik);
|
|
31
47
|
const self = { name, relays, createdAt: Date.now() };
|
|
48
|
+
// A person.key from before this identity existed no longer counts (projects.ts renewPersonToken).
|
|
49
|
+
// Replaced before any key is written: if that fails, no identity is made here.
|
|
50
|
+
renewPersonToken(app.home);
|
|
32
51
|
await app.state.put("keys", keys);
|
|
33
52
|
await app.state.put("self", self);
|
|
34
53
|
app.setKeys(keys, self);
|
|
@@ -48,10 +67,13 @@ export const BACKUP_FILE_NAME = "backup-phrase.txt";
|
|
|
48
67
|
export async function setup(app, opts) {
|
|
49
68
|
let created = false;
|
|
50
69
|
let pub;
|
|
70
|
+
let backupMode = opts.backup;
|
|
51
71
|
if (!(await app.load(false))) {
|
|
52
72
|
const r = await init(app, { name: opts.name, relays: opts.relays });
|
|
53
73
|
created = true;
|
|
54
74
|
pub = { published: r.published, failed: r.failed };
|
|
75
|
+
if (backupMode === undefined && opts.chooseBackup)
|
|
76
|
+
backupMode = await opts.chooseBackup(r);
|
|
55
77
|
}
|
|
56
78
|
const v = await app.ownView();
|
|
57
79
|
const out = {
|
|
@@ -63,7 +85,14 @@ export async function setup(app, opts) {
|
|
|
63
85
|
created,
|
|
64
86
|
...(pub ?? {}),
|
|
65
87
|
};
|
|
66
|
-
|
|
88
|
+
try {
|
|
89
|
+
out.ix = await setupIx(app, created, { reoffer: opts.ix === true });
|
|
90
|
+
}
|
|
91
|
+
catch (e) {
|
|
92
|
+
// Never fails a setup: Ix is optional.
|
|
93
|
+
out.ix = { found: false, installed: false, recommended: false, enabled: false, hint: `couldn't check for Ix: ${sanitizePeerText(e.message, 200)}` };
|
|
94
|
+
}
|
|
95
|
+
if (backupMode === "file") {
|
|
67
96
|
const path = opts.backupFile ?? join(app.home, BACKUP_FILE_NAME);
|
|
68
97
|
const { phrase } = await backupShow(app);
|
|
69
98
|
try {
|
|
@@ -78,9 +107,12 @@ export async function setup(app, opts) {
|
|
|
78
107
|
await chmod(path, 0o600);
|
|
79
108
|
out.backup = { file: path };
|
|
80
109
|
}
|
|
81
|
-
else if (
|
|
110
|
+
else if (backupMode === "print") {
|
|
82
111
|
out.backup = { phrase: (await backupShow(app)).phrase };
|
|
83
112
|
}
|
|
113
|
+
// This device is the only key holder and its phrase was never shown: losing it loses the identity.
|
|
114
|
+
if (!out.backup && app.isKeyholder && v.head.keyholders.length < 2 && !app.self?.backupShown)
|
|
115
|
+
out.backupNeeded = true;
|
|
84
116
|
return out;
|
|
85
117
|
}
|
|
86
118
|
// ---------------------------------------------------------------------------
|
|
@@ -88,12 +120,14 @@ export async function setup(app, opts) {
|
|
|
88
120
|
export async function relaysList(app) {
|
|
89
121
|
return { relays: [...(await app.ownView()).head.relays] };
|
|
90
122
|
}
|
|
91
|
-
async function changeRelays(app, f) {
|
|
123
|
+
async function changeRelays(app, f, removing = []) {
|
|
92
124
|
app.requireKeyholder("Changing your relays");
|
|
93
125
|
await app.connectAndDrain();
|
|
94
126
|
const pub = await app.publishNext((p) => {
|
|
95
127
|
p.relays = f(p.relays);
|
|
96
|
-
}
|
|
128
|
+
},
|
|
129
|
+
// #67: removing a relay must work even while it serves versions that don't connect (App.ownStrictFallback).
|
|
130
|
+
{ removing });
|
|
97
131
|
const re = await reissueForRelays(app);
|
|
98
132
|
return { relays: [...(await app.ownView()).head.relays], ver: pub.ver, published: pub.ok, failed: pub.failed, ...re };
|
|
99
133
|
}
|
|
@@ -171,7 +205,7 @@ export async function relaysRemove(app, url) {
|
|
|
171
205
|
throw new CliError("usage", "that is your only relay: add another first");
|
|
172
206
|
// Caps naming the dropped relay, captured before the re-issue adds new ones.
|
|
173
207
|
const old = (await app.store.listCapsIssued()).filter((c) => c.iss === app.userId && c.relays.includes(r));
|
|
174
|
-
const out = await changeRelays(app, (list) => list.filter((x) => x !== r));
|
|
208
|
+
const out = await changeRelays(app, (list) => list.filter((x) => x !== r), [r]);
|
|
175
209
|
// review L2: revoke them at the dropped relay only (our devices are still in its allowlist). Other
|
|
176
210
|
// relays keep honouring them, so friends who haven't picked up the new caps stay covered.
|
|
177
211
|
// Best effort: the relay may be down.
|
|
@@ -389,12 +423,37 @@ export async function linkJoin(app, code, opts = {}) {
|
|
|
389
423
|
throw new CliError("usage", "that is not a link code (p2p-link:…@relay)");
|
|
390
424
|
}
|
|
391
425
|
const { secret, relay } = parsed;
|
|
426
|
+
// A link code someone else gave connects to its relay before anyone confirms anything: the same
|
|
427
|
+
// private-address rule as an invite code's relay, unless it is one of the person's own relays
|
|
428
|
+
// (P2P_DEFAULT_RELAYS or config.json: no identity here yet) or they opted in.
|
|
429
|
+
const allowPrivate = opts.allowPrivateRelay || app.env.P2P_ALLOW_PRIVATE_RELAY === "1";
|
|
430
|
+
let own = [];
|
|
431
|
+
try {
|
|
432
|
+
own = defaultRelays(app.env, app.file);
|
|
433
|
+
}
|
|
434
|
+
catch {
|
|
435
|
+
// a broken config: no own relays
|
|
436
|
+
}
|
|
437
|
+
const guard = !allowPrivate && !isOwnRelay(relay, own);
|
|
438
|
+
if (guard && isPrivateRelayHost(new URL(relay).hostname)) {
|
|
439
|
+
throw new CliError("private_relay", privateRelayMessage("link code's relay", new URL(relay).hostname));
|
|
440
|
+
}
|
|
392
441
|
const device = generateDeviceKeysV3("p2p:pending");
|
|
393
442
|
const x = generateDeviceKeysV3("p2p:pending");
|
|
394
443
|
const label = (opts.label ?? defaultLabel()).slice(0, 64);
|
|
395
444
|
const req = createLinkRequest(secret, device, x.agreementPublicKey, label);
|
|
396
445
|
const lid = linkId(secret);
|
|
397
|
-
|
|
446
|
+
let conn;
|
|
447
|
+
try {
|
|
448
|
+
conn = await openLinkConnection(relay, app.transport, app.tun.connectTimeoutMs, app.progress, guard ? { lookup: privateGuardLookup() } : {});
|
|
449
|
+
}
|
|
450
|
+
catch (e) {
|
|
451
|
+
if (e.message?.includes(PRIVATE_RESOLVE_MARK)) {
|
|
452
|
+
const at = /\(([^()]+)\)\s*$/.exec(e.message)?.[1];
|
|
453
|
+
throw new CliError("private_relay", privateRelayMessage("link code's relay", new URL(relay).hostname, at ? { detail: `it resolves to ${at}` } : {}));
|
|
454
|
+
}
|
|
455
|
+
throw e;
|
|
456
|
+
}
|
|
398
457
|
try {
|
|
399
458
|
await linkPut(conn, lid, "req", JSON.stringify(req));
|
|
400
459
|
}
|
|
@@ -405,7 +464,7 @@ export async function linkJoin(app, code, opts = {}) {
|
|
|
405
464
|
return {
|
|
406
465
|
compareCode: linkCompareCode(secret, device.did),
|
|
407
466
|
did: device.did,
|
|
408
|
-
wait: async () => {
|
|
467
|
+
wait: async (confirm) => {
|
|
409
468
|
const deadline = Date.now() + Math.min(LINK_TTL_SEC * 1000, opts.maxWaitMs ?? Infinity);
|
|
410
469
|
let frame;
|
|
411
470
|
try {
|
|
@@ -427,8 +486,17 @@ export async function linkJoin(app, code, opts = {}) {
|
|
|
427
486
|
}
|
|
428
487
|
const opened = openLinkResponse(secret, device, x.agreementSecretKey, JSON.parse(frame));
|
|
429
488
|
const userId = opened.doc.iss;
|
|
489
|
+
// Nothing is kept before the person says this is their identity: a code from someone else
|
|
490
|
+
// would make this device theirs.
|
|
491
|
+
if (confirm) {
|
|
492
|
+
const who = { userId, address: displayAddress(userId, opened.doc.name), fingerprint: displayFingerprint(userId), keyholder: !!opened.ik };
|
|
493
|
+
if (!(await confirm(who))) {
|
|
494
|
+
throw new CliError("link_declined", `not linked: nothing was kept on this device. The other device's identity (${who.address}) now lists a device that will never be used: if it is yours after all, remove it there with \`p2p devices revoke ${device.did}\``);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
430
497
|
const keys = newKeysDoc(userId, { ...device, userId }, opened.cert.jws, opened.ik);
|
|
431
498
|
const self = { name: opened.doc.name, relays: opened.doc.relays, createdAt: Date.now() };
|
|
499
|
+
renewPersonToken(app.home);
|
|
432
500
|
await app.state.put("keys", keys);
|
|
433
501
|
await app.state.put("self", self);
|
|
434
502
|
app.setKeys(keys, self);
|
|
@@ -523,6 +591,7 @@ async function restoreInto(app, phrase, opts) {
|
|
|
523
591
|
if (found === 0) {
|
|
524
592
|
const name = opts.name ?? defaultName();
|
|
525
593
|
const doc = createIdentityDoc(ik, { ver: 1, prev: null, name, relays, devices: [device.did], keyholders: [device.did], by: device.did, certs: [cert] });
|
|
594
|
+
renewPersonToken(app.home);
|
|
526
595
|
await app.state.put("keys", keys);
|
|
527
596
|
await app.state.put("self", { ...self, name });
|
|
528
597
|
app.setKeys(keys, { ...self, name });
|
|
@@ -545,6 +614,7 @@ async function restoreInto(app, phrase, opts) {
|
|
|
545
614
|
const existing = await app.refreshIdentity(ik.userId, relays, { force: true, strict: true });
|
|
546
615
|
if (!existing)
|
|
547
616
|
throw new CliError("refresh_failed", "couldn't fit the relays' identity document");
|
|
617
|
+
renewPersonToken(app.home);
|
|
548
618
|
await app.state.put("keys", keys);
|
|
549
619
|
await app.store.putDeviceCert({ userId: ik.userId, did: device.did, exp: verifyDeviceCertV3(cert).exp, jws: cert });
|
|
550
620
|
await app.state.put("self", { ...self, name: existing.head.name, relays: existing.head.relays });
|
package/dist/inbound.js
CHANGED
|
@@ -14,6 +14,7 @@ export { isTransient } from "./transient.js";
|
|
|
14
14
|
import { decodeEnvelopeV3, jwsHash, P2PError, sanitizePeerText, verifyIncomingV3 } from "@peer2peer/core/v3";
|
|
15
15
|
import { answerDeferredWants, onCircleEnvelope } from "./circle-ops.js";
|
|
16
16
|
import { onSessionEnvelope } from "./sessions.js";
|
|
17
|
+
import { recordEvents } from "./history.js";
|
|
17
18
|
import { onReceipt } from "./receipts.js";
|
|
18
19
|
import { onUnknownKind } from "./unknown-kinds.js";
|
|
19
20
|
import { onContact, onUnfriendKind } from "./social.js";
|
|
@@ -174,7 +175,9 @@ async function processClaimed(app, env, relay, token) {
|
|
|
174
175
|
await r.releaseReplay?.({ uncount: true }).catch(() => undefined);
|
|
175
176
|
return "keep";
|
|
176
177
|
}
|
|
177
|
-
await app.state.addEvents(events);
|
|
178
|
+
const added = await app.state.addEvents(events);
|
|
179
|
+
// Message history (history.ts): the messages just logged, once each (a redelivery adds none).
|
|
180
|
+
await recordEvents(app, added);
|
|
178
181
|
}
|
|
179
182
|
catch (e) {
|
|
180
183
|
const what = `applying ${sanitizePeerText(r.envelope.kind, 40)} from ${r.envelope.from} failed: ${sanitizePeerText(e.message, 300)}`;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { App } from "./app.js";
|
|
2
|
+
import { type Env, type FileConfig } from "./config.js";
|
|
3
|
+
import { type GraphTarget } from "./projects.js";
|
|
4
|
+
/** Where to get Ix (and how p2p says it): never installed for the person. */
|
|
5
|
+
export declare const IX_INSTALL_URL = "https://github.com/ix-infrastructure/Ix";
|
|
6
|
+
/**
|
|
7
|
+
* The command(s) that install Ix on this platform, from the Ix README, for the person to run in their
|
|
8
|
+
* own terminal: Peer2Peer prints them and never runs them (it doesn't run a downloaded script). Intel
|
|
9
|
+
* Macs have no pre-built Ix package, so Homebrew builds it.
|
|
10
|
+
*/
|
|
11
|
+
export declare function ixInstallCommands(platform?: NodeJS.Platform, arch?: string): string[];
|
|
12
|
+
/** The install command(s) as one line (`&&` between steps; Windows has one). */
|
|
13
|
+
export declare function ixInstallLine(platform?: NodeJS.Platform, arch?: string): string;
|
|
14
|
+
/** What Ix adds, in a few lines, said when `p2p setup` recommends it. */
|
|
15
|
+
export declare const IX_PITCH: string[];
|
|
16
|
+
/** The person said no to Ix at `p2p setup` (FileConfig.ixDeclined): not asked again until `p2p setup --ix`. */
|
|
17
|
+
export declare function ixDeclined(file: Pick<FileConfig, "ixDeclined">): boolean;
|
|
18
|
+
/** Records the person's answer to the Ix offer (config.json `ixDeclined`); only `p2p setup`, at a terminal, writes it. */
|
|
19
|
+
export declare function setIxDeclined(home: string, declined: boolean): void;
|
|
20
|
+
/** CI set (anything but empty, 0 or false): never a prompt. */
|
|
21
|
+
export declare function ciEnv(env: Env): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Whether p2p recommends Ix here (`p2p setup --json`, `p2p extensions --json`, and the hint the front
|
|
24
|
+
* ends give their agent): the Ix CLI isn't found and the person hasn't said no. `install` is the
|
|
25
|
+
* command for the person to run; nothing is ever installed for them.
|
|
26
|
+
*/
|
|
27
|
+
export interface IxAdvice {
|
|
28
|
+
/** The Ix CLI was found. */
|
|
29
|
+
installed: boolean;
|
|
30
|
+
/** The person said no at `p2p setup` (`p2p setup --ix` asks again). */
|
|
31
|
+
declined: boolean;
|
|
32
|
+
/** Ix isn't installed and the person hasn't said no. */
|
|
33
|
+
recommended: boolean;
|
|
34
|
+
/** The command that installs Ix on this platform, for the person to run themselves. */
|
|
35
|
+
install: string;
|
|
36
|
+
}
|
|
37
|
+
export declare function ixAdvice(env: Env, file: Pick<FileConfig, "ixDeclined">, o?: {
|
|
38
|
+
reoffer?: boolean;
|
|
39
|
+
}): IxAdvice;
|
|
40
|
+
/**
|
|
41
|
+
* `name` resolved to an absolute path through PATH's absolute entries (the same rule as ext-ix's
|
|
42
|
+
* which.ts: on Windows the current directory is searched before PATH, so a cloned repository's
|
|
43
|
+
* `ix.exe` would otherwise run). An absolute name is used as given when it runs.
|
|
44
|
+
*/
|
|
45
|
+
export declare function whichAbsolute(name: string, env?: Record<string, string | undefined>, platform?: NodeJS.Platform): string | undefined;
|
|
46
|
+
/** The Ix CLI: IX_BIN when it is an absolute path that runs (or a bare name found on PATH), else `ix` on PATH. */
|
|
47
|
+
export declare function ixBinary(env: Env): string | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* The environment `ix` runs with: IX_CHILD_ALLOW from `env`, then IX_ENDPOINT from the target
|
|
50
|
+
* (never the caller's), no background `ix map` from a reader (Ix Pro routes a map to the cloud
|
|
51
|
+
* whenever an org session is active), no update check. Names compare case-insensitively, as on
|
|
52
|
+
* Windows. The same rule as ext-ix's ixEnv (ix.ts).
|
|
53
|
+
*/
|
|
54
|
+
export declare function ixChildEnv(env: Record<string, string | undefined>, target: Pick<GraphTarget, "endpoint">): NodeJS.ProcessEnv;
|
|
55
|
+
/** PATH with its relative and empty entries dropped (they mean the current directory: a repository's own `node`). */
|
|
56
|
+
export declare function absolutePath(v: string, platform?: NodeJS.Platform): string;
|
|
57
|
+
export interface IxRun {
|
|
58
|
+
code: number;
|
|
59
|
+
stdout: string;
|
|
60
|
+
stderr: string;
|
|
61
|
+
timedOut?: true;
|
|
62
|
+
}
|
|
63
|
+
/** One bounded `ix` call (argv, no shell, SIGKILL on timeout, output capped). Read-only commands only. */
|
|
64
|
+
export declare function runIx(bin: string, argv: readonly string[], o: {
|
|
65
|
+
env: Record<string, string | undefined>;
|
|
66
|
+
target: Pick<GraphTarget, "endpoint">;
|
|
67
|
+
cwd?: string;
|
|
68
|
+
timeoutMs: number;
|
|
69
|
+
}): Promise<IxRun>;
|
|
70
|
+
/** `ix --version`'s first line, sanitized; undefined when it fails. */
|
|
71
|
+
export declare function ixVersion(bin: string, env: Env, target: Pick<GraphTarget, "endpoint">, timeoutMs: number): Promise<string | undefined>;
|
|
72
|
+
/** Whether @peer2peer/ext-ix is where this p2p loads extensions from (resolved, never imported). */
|
|
73
|
+
export declare function extIxInstalled(env: Env): boolean;
|
|
74
|
+
/** What `p2p setup` did about Ix (SetupResult.ix). */
|
|
75
|
+
export interface SetupIx {
|
|
76
|
+
/** The Ix CLI was found (its absolute path is local only, never sent anywhere). */
|
|
77
|
+
found: boolean;
|
|
78
|
+
/** The same as `found` (IxAdvice's name). */
|
|
79
|
+
installed: boolean;
|
|
80
|
+
/** Ix isn't installed and the person hasn't said no: p2p recommends it (it never installs it). */
|
|
81
|
+
recommended: boolean;
|
|
82
|
+
/** The person said no to Ix at an earlier `p2p setup` (`--ix` asks again). */
|
|
83
|
+
declined?: true;
|
|
84
|
+
/** The command that installs Ix on this platform, for the person to run themselves (when it isn't installed). */
|
|
85
|
+
install?: string;
|
|
86
|
+
/** The `ix` extension is enabled now (by this setup, or already). */
|
|
87
|
+
enabled: boolean;
|
|
88
|
+
/** This setup turned it on (a new install, Ix present, ext-ix installed, the person running it). */
|
|
89
|
+
enabledNow?: true;
|
|
90
|
+
/** What the person can do, when it isn't on. */
|
|
91
|
+
hint?: string;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* What to do about Ix when it isn't installed: the person runs the command themselves; read by an
|
|
95
|
+
* agent (not the person), it says to ask the user instead, since installing is theirs alone.
|
|
96
|
+
*/
|
|
97
|
+
export declare function ixInstallHint(line: string, person: boolean): string;
|
|
98
|
+
/**
|
|
99
|
+
* Ix for `p2p setup`: optional and recommended, never installed. Without the Ix CLI it says what to
|
|
100
|
+
* run (`recommended`, `install`), unless the person said no before (`--ix`, `reoffer`, asks again).
|
|
101
|
+
* With it, a new install (`created`; or any install, with `reoffer`) gets the `ix` extension enabled
|
|
102
|
+
* when ext-ix is there too and the person agrees: their front end's token (the Claude mod's typed
|
|
103
|
+
* `/peers setup`), or, outside any agent's session (its environment or a Claude Code or Codex
|
|
104
|
+
* ancestor), their "yes" typed on the controlling terminal, as for every other person-only action
|
|
105
|
+
* (projects.ts). Otherwise nothing changes: an existing install is never switched silently (it gets
|
|
106
|
+
* the one-time notice, ixNotice), an agent never enables an extension, and P2P_EXTENSIONS, when
|
|
107
|
+
* set, decides alone.
|
|
108
|
+
*/
|
|
109
|
+
export declare function setupIx(app: App, created: boolean, o?: {
|
|
110
|
+
reoffer?: boolean;
|
|
111
|
+
}): Promise<SetupIx>;
|
|
112
|
+
/**
|
|
113
|
+
* The one-time notice for an existing install (shown once per device, to the person at a terminal):
|
|
114
|
+
* new installs offer to turn the Ix extension on when Ix is present; this one wasn't changed.
|
|
115
|
+
* Undefined when it was shown already, Ix isn't installed, the person said no to Ix, or the
|
|
116
|
+
* extension is on (or P2P_EXTENSIONS decides).
|
|
117
|
+
*/
|
|
118
|
+
export declare function ixNotice(app: App): Promise<string | undefined>;
|
|
119
|
+
/**
|
|
120
|
+
* Which `ix note` / `ix session` this Ix has, from `ix --help` (graph memory, graph-memory.ts):
|
|
121
|
+
* "oss" (the local backend: Ix after 0.13.0, ix-infrastructure/Ix#916, with Ix Pro not loaded: its
|
|
122
|
+
* help then lists them under "Memory:"), "pro" (Ix Pro loaded: its "Pro:" section; its note and
|
|
123
|
+
* session go to the cloud org), "none" (neither). The same reading as ext-ix's parseMemorySupport
|
|
124
|
+
* (ix.ts), which decides; this one only reports (`p2p doctor`).
|
|
125
|
+
*/
|
|
126
|
+
export declare function parseIxMemorySupport(help: string): "oss" | "pro" | "none";
|
|
127
|
+
/** `ix --help` read as parseIxMemorySupport; undefined when it doesn't answer. */
|
|
128
|
+
export declare function ixMemorySupport(bin: string, env: Env, target: Pick<GraphTarget, "endpoint">, timeoutMs: number): Promise<"oss" | "pro" | "none" | undefined>;
|