@peer2peer/cli 0.1.3 → 0.1.5
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 +9 -7
- package/dist/app.d.ts +28 -0
- package/dist/app.js +112 -21
- package/dist/circle-ops.js +2 -1
- package/dist/cli.d.ts +3 -3
- package/dist/cli.js +211 -4
- package/dist/config.d.ts +5 -0
- package/dist/doctor.d.ts +7 -0
- package/dist/doctor.js +73 -2
- package/dist/format.d.ts +3 -1
- package/dist/format.js +12 -0
- package/dist/identity.js +2 -0
- package/dist/keystore.d.ts +223 -0
- package/dist/keystore.js +1021 -0
- package/dist/outbox.d.ts +2 -4
- package/dist/outbox.js +12 -3
- package/dist/procstart.js +11 -3
- package/dist/projects.js +4 -8
- package/dist/relay-client.d.ts +8 -0
- package/dist/relay-client.js +7 -1
- package/dist/rotation-lock.d.ts +17 -0
- package/dist/rotation-lock.js +188 -0
- package/dist/rotation.d.ts +27 -1
- package/dist/rotation.js +141 -15
- package/dist/sandbox.d.ts +195 -0
- package/dist/sandbox.js +763 -0
- package/dist/state.d.ts +8 -0
- package/dist/state.js +12 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -4
package/dist/cli.js
CHANGED
|
@@ -28,8 +28,10 @@ import { receiving } from "./inbound.js";
|
|
|
28
28
|
import * as rotation from "./rotation.js";
|
|
29
29
|
import * as sessions from "./sessions.js";
|
|
30
30
|
import * as projects from "./projects.js";
|
|
31
|
+
import * as keystore from "./keystore.js";
|
|
31
32
|
import { isDid } from "@peer2peer/core/v3";
|
|
32
33
|
import * as ixLocal from "./ix-local.js";
|
|
34
|
+
import * as sandbox from "./sandbox.js";
|
|
33
35
|
import * as history from "./history.js";
|
|
34
36
|
import { confirmOnTty } from "./tty-confirm.js";
|
|
35
37
|
import * as social from "./social.js";
|
|
@@ -39,6 +41,7 @@ import { tuiCommand } from "./tui/command.js";
|
|
|
39
41
|
import { TUI_SESSION } from "./tui/tui.js";
|
|
40
42
|
import * as pretty from "./pretty.js";
|
|
41
43
|
import { VERSION } from "./version.js";
|
|
44
|
+
import { CLI_CAPS, PROTO_MINOR } from "./features.js";
|
|
42
45
|
export { VERSION };
|
|
43
46
|
/** How long a command that ran out of time waits for in-flight sends and writes to settle. */
|
|
44
47
|
export const SETTLE_MS = 5000;
|
|
@@ -106,6 +109,7 @@ const PERSON_ONLY = new Map([
|
|
|
106
109
|
["petname", "changes the names you know people by"],
|
|
107
110
|
["circle leave", "changes your circles"],
|
|
108
111
|
["held decline", "decides a held request for you"],
|
|
112
|
+
["keys backend", "moves your identity and device keys"],
|
|
109
113
|
]);
|
|
110
114
|
/** `identity rotate` options that do something beyond making or showing the plan. */
|
|
111
115
|
const ROTATE_ACTS = ["resume", "cancel", "exclude", "keep", "invite", "keepKeyholders", "backupFile", "contest", "resend", "yes", "branch"];
|
|
@@ -131,6 +135,9 @@ export function personOnlyOf(cmd) {
|
|
|
131
135
|
return args.length > 1 ? { what: args[1] === "on" || args[1] === "off" ? `circle hold <cid> ${args[1]}` : "circle hold", why } : undefined;
|
|
132
136
|
case "ix config":
|
|
133
137
|
return args.length > 0 ? { what: "ix config", why } : undefined;
|
|
138
|
+
// A bare `keys backend` only says where the keys are.
|
|
139
|
+
case "keys backend":
|
|
140
|
+
return args.length > 0 ? { what: `keys backend ${args[0] === "file" || args[0] === "keychain" ? args[0] : "<backend>"}`, why } : undefined;
|
|
134
141
|
// Restore runs only on a fresh home and needs the phrase itself, typed or piped: that is the
|
|
135
142
|
// person's proof outside an agent's session (a fresh home has no person token yet, and a
|
|
136
143
|
// headless restore must keep working). Inside an agent's session it is refused, as `link join`.
|
|
@@ -203,6 +210,13 @@ export function buildProgram(deps) {
|
|
|
203
210
|
.enablePositionalOptions()
|
|
204
211
|
.exitOverride()
|
|
205
212
|
.configureOutput({ writeOut: (s) => io.out(s.replace(/\n$/, "")), writeErr: (s) => io.err(s.replace(/\n$/, "")) });
|
|
213
|
+
program.command("version")
|
|
214
|
+
.description("Show CLI, protocol and runtime versions without opening an identity")
|
|
215
|
+
.option("--json", "JSON output")
|
|
216
|
+
.action((o) => {
|
|
217
|
+
const info = { version: VERSION, protocol: "p2p/v3", protoMinor: PROTO_MINOR, caps: [...CLI_CAPS], node: process.version };
|
|
218
|
+
io.out(o.json ? safeJson(info) : `p2p ${VERSION} · protocol 3.${PROTO_MINOR} · node ${process.version}\n${CLI_CAPS.join(", ")}`);
|
|
219
|
+
});
|
|
206
220
|
/** Runs one command: JSON or human output, exit code 1 on failure. */
|
|
207
221
|
const run = (fn, opts = {}) => async (...args) => {
|
|
208
222
|
const cmd = args[args.length - 1];
|
|
@@ -328,6 +342,16 @@ export function buildProgram(deps) {
|
|
|
328
342
|
const a = (await io.prompt(`${q} [y/N] `)).trim().toLowerCase();
|
|
329
343
|
return a === "y" || a === "yes";
|
|
330
344
|
};
|
|
345
|
+
/** A question whose answer defaults to Yes (Enter): only ever for what tightens, such as the sandbox offer. */
|
|
346
|
+
/**
|
|
347
|
+
* The sandbox offer (sandbox.ts): every installed agent whose sandbox doesn't deny P2P_HOME and
|
|
348
|
+
* that the person hasn't said no for, each asked on its own with exactly what would be written.
|
|
349
|
+
* The caller has checked that the person is here (sandbox.assertPersonOutsideAgents) and can be asked.
|
|
350
|
+
*/
|
|
351
|
+
const offerSandbox = async (env, home, reoffer = false) => {
|
|
352
|
+
const plans = sandbox.offerablePlans(env).filter((f) => reoffer || !sandbox.declinedHere(env, f.front));
|
|
353
|
+
return (await askEachAgent(io, env, home, plans, { from: "setup" })).lines;
|
|
354
|
+
};
|
|
331
355
|
/** The command whose options `o` are (commander passes the same object it keeps). */
|
|
332
356
|
const cmdOf = (o) => ({ opts: () => o });
|
|
333
357
|
// ── pickers (prompt/): only with io.select, never with --json or --yes ──
|
|
@@ -517,6 +541,7 @@ export function buildProgram(deps) {
|
|
|
517
541
|
.option("--print-backup", "Print the backup phrase (in --json, as backup.phrase)")
|
|
518
542
|
.option("--no-backup", "Don't save or print the backup phrase now")
|
|
519
543
|
.option("--ix", "Offer Ix again after an earlier no (optional; Peer2Peer never installs it), and with Ix installed, offer to turn on the Ix extension")
|
|
544
|
+
.option("--sandbox", "Offer again to deny P2P_HOME to your agents' sandboxes (Claude Code, Codex) after an earlier no")
|
|
520
545
|
.option("--allow-private-relay", "Linking or joining: accept a code whose relay is a loopback, link-local or private address (your own relay on your network; also P2P_ALLOW_PRIVATE_RELAY=1)")
|
|
521
546
|
.option("--json", "JSON output")
|
|
522
547
|
.action(run(async (app, o) => {
|
|
@@ -634,11 +659,87 @@ export function buildProgram(deps) {
|
|
|
634
659
|
lines.push(" ix not installing Ix. You won't be asked again; `p2p setup --ix` offers it again");
|
|
635
660
|
}
|
|
636
661
|
}
|
|
662
|
+
// The agents' sandboxes keep them out of P2P_HOME (sandbox.ts): offered once to the person at a
|
|
663
|
+
// terminal (default Yes), showing exactly what is written. Never with --json, in CI, without a
|
|
664
|
+
// terminal, from a front end, or inside an agent's session; a "no" is remembered.
|
|
665
|
+
const sandboxHere = (() => {
|
|
666
|
+
try {
|
|
667
|
+
sandbox.assertPersonOutsideAgents(app, "setup");
|
|
668
|
+
return true;
|
|
669
|
+
}
|
|
670
|
+
catch {
|
|
671
|
+
return false;
|
|
672
|
+
}
|
|
673
|
+
})();
|
|
674
|
+
if (!o.json && Boolean(io.prompt || io.select) && !ixLocal.ciEnv(app.env) && sandboxHere) {
|
|
675
|
+
io.out(lines.join("\n"));
|
|
676
|
+
lines.length = 0;
|
|
677
|
+
lines.push(...(await offerSandbox(app.env, app.home, o.sandbox === true)));
|
|
678
|
+
}
|
|
637
679
|
lines.push("", "Invite someone: p2p invite <their name> Join with a code: p2p join <code>");
|
|
638
680
|
return { json: r, human: lines.join("\n") };
|
|
639
681
|
},
|
|
640
682
|
// review L1: never cut short half-way through creating an identity (each step is still bounded).
|
|
641
683
|
{ requireIdentity: false, noDeadline: true }));
|
|
684
|
+
const sb = program
|
|
685
|
+
.command("sandbox")
|
|
686
|
+
.description("Whether your agents' sandboxes (Claude Code, Codex) keep them out of P2P_HOME; `sandbox enable` adds the deny to their config")
|
|
687
|
+
.option("--json", "JSON output")
|
|
688
|
+
.action(run(async (app) => {
|
|
689
|
+
const r = sandbox.sandboxReport(app.env);
|
|
690
|
+
return { json: r, human: sandbox.sandboxHuman(r, projects.personHere(app)) };
|
|
691
|
+
}, { requireIdentity: false, readOnly: true }));
|
|
692
|
+
sb.command("enable")
|
|
693
|
+
.description("Add the deny on P2P_HOME to your Claude Code settings and Codex config.toml (shows the changes and asks first; backs each file up)")
|
|
694
|
+
.option("--claude", "Only Claude Code (~/.claude/settings.json, or $CLAUDE_CONFIG_DIR), even if it isn't set up yet")
|
|
695
|
+
.option("--codex", "Only Codex (config.toml in CODEX_HOME, else ~/.codex), even if it isn't set up yet")
|
|
696
|
+
.option("--yes", "Don't ask (in your own terminal or a script of yours; never inside an agent's session)")
|
|
697
|
+
.option("--json", "JSON output (needs --yes)")
|
|
698
|
+
.action(run(async (app, o) => {
|
|
699
|
+
sandbox.assertPersonOutsideAgents(app, "sandbox enable");
|
|
700
|
+
const only = o.claude || o.codex ? [...(o.claude ? ["claude"] : []), ...(o.codex ? ["codex"] : [])] : undefined;
|
|
701
|
+
const planOpts = o.codexBase ? { codexBase: o.codexBase === "workspace" ? ":workspace" : ":read-only" } : {};
|
|
702
|
+
const fronts = (only ?? ["claude", "codex"]).map((f) => sandbox.planFront(f, app.env, planOpts)).filter((f) => only !== undefined || f.present);
|
|
703
|
+
const name = (f) => (f.front === "claude" ? "Claude Code" : "Codex");
|
|
704
|
+
const lines = [];
|
|
705
|
+
if (fronts.length === 0) {
|
|
706
|
+
lines.push(`Neither Claude Code (${sandbox.claudeSettingsPath(app.env)}) nor Codex (${sandbox.codexConfigPath(app.env)}) is set up here: nothing to change. --claude or --codex writes the config anyway.`);
|
|
707
|
+
}
|
|
708
|
+
for (const f of fronts) {
|
|
709
|
+
if (f.plan.kind === "already")
|
|
710
|
+
lines.push(`${name(f)}: already denies P2P_HOME (${f.path})`);
|
|
711
|
+
else if (f.plan.kind === "unavailable")
|
|
712
|
+
lines.push(`${name(f)}: ${f.status.detail}`);
|
|
713
|
+
else if (f.plan.kind === "manual")
|
|
714
|
+
lines.push(`${name(f)}: not changed: ${f.plan.reason}.${f.plan.snippet ? ` Add this to ${f.path} yourself:\n\n${f.plan.snippet}\n` : ""}`);
|
|
715
|
+
}
|
|
716
|
+
const edits = fronts.filter((f) => f.plan.kind === "edit");
|
|
717
|
+
let written = [];
|
|
718
|
+
if (edits.length > 0) {
|
|
719
|
+
// Windows has no process-tree check (agent detection fails open there): the person's answer at a terminal is required.
|
|
720
|
+
if (o.yes && process.platform === "win32")
|
|
721
|
+
throw new CliError("usage", "nothing was changed: on Windows, run `p2p sandbox enable` at your terminal without --yes and answer the question");
|
|
722
|
+
if (!o.yes && (o.json || !(io.prompt || io.select))) {
|
|
723
|
+
throw new CliError("usage", "nothing was changed: run `p2p sandbox enable` at your terminal to see the changes and be asked, or add --yes");
|
|
724
|
+
}
|
|
725
|
+
const res = await askEachAgent(io, app.env, app.home, edits, { yes: o.yes === true, from: "enable" });
|
|
726
|
+
written = res.written;
|
|
727
|
+
lines.push(...res.lines);
|
|
728
|
+
}
|
|
729
|
+
return {
|
|
730
|
+
json: { written, fronts: fronts.map((f) => ({ front: f.front, path: f.path, plan: f.plan.kind, ...(f.plan.kind === "manual" ? { reason: f.plan.reason } : {}) })) },
|
|
731
|
+
human: lines.join("\n"),
|
|
732
|
+
};
|
|
733
|
+
}, { requireIdentity: false, noDeadline: true }));
|
|
734
|
+
sb.commands.find((c) => c.name() === "enable")?.addOption(new Option("--codex-base <base>", "When your Codex config sets no sandbox: what the new profile extends (read-only, the default, or workspace)").choices(["read-only", "workspace"]));
|
|
735
|
+
sb.command("notice")
|
|
736
|
+
.description("For a front end: the one-time notice for its person when its agent's sandbox doesn't deny P2P_HOME")
|
|
737
|
+
.option("--front <name>", "claude or codex", "claude")
|
|
738
|
+
.option("--json", "JSON output")
|
|
739
|
+
.action(run(async (app, o) => {
|
|
740
|
+
const notice = await sandbox.sandboxNotice(app, o.front === "codex" ? "codex" : "claude").catch(() => undefined);
|
|
741
|
+
return { json: notice ? { notice } : {}, human: notice ?? "" };
|
|
742
|
+
}, { requireIdentity: false }));
|
|
642
743
|
program
|
|
643
744
|
.command("whoami")
|
|
644
745
|
.description("Your address, fingerprint, devices, relays and document expiry")
|
|
@@ -647,6 +748,44 @@ export function buildProgram(deps) {
|
|
|
647
748
|
const r = await ops.whoami(app);
|
|
648
749
|
return { json: r, human: fmt.formatWhoami(r) };
|
|
649
750
|
}));
|
|
751
|
+
const keys = program.command("keys").description("Where this device's secret keys are kept: files in P2P_HOME (the default) or the OS keychain");
|
|
752
|
+
keys
|
|
753
|
+
.command("backend [backend]")
|
|
754
|
+
.description("Show where this device's keys are kept; `keychain` moves them into the OS keychain, `file` back into P2P_HOME (only you, never an agent)")
|
|
755
|
+
.option("--json", "JSON output")
|
|
756
|
+
.addHelpText("after", [
|
|
757
|
+
"",
|
|
758
|
+
"keychain: the macOS Keychain, the Windows Credential Manager, or the Secret Service keyring (libsecret's",
|
|
759
|
+
"secret-tool) on Linux. The keys are stored, read back and compared before keys.json loses them; a move that",
|
|
760
|
+
"was interrupted finishes when run again. If the keychain can't be read later (locked, its tool missing),",
|
|
761
|
+
"commands that need the keys stop with an error: p2p never makes new keys in their place.",
|
|
762
|
+
].join("\n"))
|
|
763
|
+
.action(run(async (app, backend) => {
|
|
764
|
+
if (backend !== undefined && backend !== "keychain" && backend !== "file")
|
|
765
|
+
throw new CliError("usage", "p2p keys backend [keychain|file]");
|
|
766
|
+
const say = (s) => {
|
|
767
|
+
const where = s.keys === "keychain" ? `${s.keychain.label} (item ${s.item?.service}, account ${s.item?.account})` : s.keys === "file" ? `${app.home}/cli/keys.json (0600)` : "nowhere yet (no identity here)";
|
|
768
|
+
const lines = [`Keys: ${where}${s.keys !== "none" ? (s.readable ? ", readable" : ", NOT readable") : ""}.`, `New keys go to: ${s.configured === "keychain" ? s.keychain.label : "files in P2P_HOME"}.`];
|
|
769
|
+
if (s.problem)
|
|
770
|
+
lines.push(`Problem: ${s.problem}`);
|
|
771
|
+
if (s.configured === "file")
|
|
772
|
+
lines.push(s.keychain.available ? `To keep them in ${s.keychain.label}: \`p2p keys backend keychain\`.` : `${s.keychain.label} isn't available here: ${s.keychain.why}.`);
|
|
773
|
+
return lines.join("\n");
|
|
774
|
+
};
|
|
775
|
+
if (backend === undefined) {
|
|
776
|
+
const s = keystore.keyStoreStatus(app.home);
|
|
777
|
+
return { json: s, human: say(s) };
|
|
778
|
+
}
|
|
779
|
+
const r = backend === "keychain" ? await keystore.moveKeysToKeychain(app.state.keyStore) : await keystore.moveKeysToFiles(app.state.keyStore);
|
|
780
|
+
for (const w of r.warnings)
|
|
781
|
+
app.warn(w);
|
|
782
|
+
const s = keystore.keyStoreStatus(app.home);
|
|
783
|
+
const head = r.moved ? `Moved this device's keys to ${r.where}.` : `Keys are kept in ${r.where}.`;
|
|
784
|
+
const note = backend === "keychain"
|
|
785
|
+
? "\nNote: an agent sandbox that denies P2P_HOME doesn't cover the keychain. Anything running as you (an agent too) can ask it for the keys, and can delete or overwrite the item: on a key holder that can destroy the only copy of your identity key, and only your backup phrase brings it back. Have it saved first (`p2p backup show`). See docs/security/threat-model.md, \"Keys in the OS keychain\"."
|
|
786
|
+
: "";
|
|
787
|
+
return { json: { ...r, status: s }, human: `${head}\n${say(s)}${note}` };
|
|
788
|
+
}, { requireIdentity: false }));
|
|
650
789
|
const backup = program.command("backup").description("The 24-word backup phrase of your identity key (§2.7)");
|
|
651
790
|
backup
|
|
652
791
|
.command("show")
|
|
@@ -1918,6 +2057,54 @@ export function buildProgram(deps) {
|
|
|
1918
2057
|
codexCommands(program, deps, io);
|
|
1919
2058
|
return program;
|
|
1920
2059
|
}
|
|
2060
|
+
/**
|
|
2061
|
+
* Asks about each agent's sandbox edit on its own (sandbox.ts frontPreview: what changes, how to
|
|
2062
|
+
* undo it, and exactly what is written), default Yes; `yes` skips the questions. A no is remembered
|
|
2063
|
+
* for that agent. A file that changed after it was shown isn't written (sandbox.applyPlans).
|
|
2064
|
+
*/
|
|
2065
|
+
async function askEachAgent(io, env, home, plans, o) {
|
|
2066
|
+
const lines = [];
|
|
2067
|
+
const written = [];
|
|
2068
|
+
const pre = o.from === "setup" ? " sandbox " : "";
|
|
2069
|
+
for (const f of plans) {
|
|
2070
|
+
if (f.plan.kind !== "edit")
|
|
2071
|
+
continue;
|
|
2072
|
+
if (!o.yes)
|
|
2073
|
+
io.out(`\n${sandbox.frontPreview(f, home, sandbox.userHomeOf(env))}`);
|
|
2074
|
+
const yes = o.yes === true || (await askDefaultYes(io, sandbox.frontQuestion(f)));
|
|
2075
|
+
if (!yes) {
|
|
2076
|
+
sandbox.setSandboxDeclined(home, f.front, true);
|
|
2077
|
+
lines.push(`${pre}${sandbox.AGENT_NAME[f.front]}: not changed. ${o.from === "enable" ? "`p2p setup` won't offer it again" : "You won't be asked again"}; \`p2p sandbox enable\` adds it any time`);
|
|
2078
|
+
continue;
|
|
2079
|
+
}
|
|
2080
|
+
try {
|
|
2081
|
+
for (const w of sandbox.applyPlans([f])) {
|
|
2082
|
+
written.push(w);
|
|
2083
|
+
lines.push(`${pre}Wrote ${w.path}${w.backup ? ` (backup: ${w.backup})` : ""}`);
|
|
2084
|
+
}
|
|
2085
|
+
}
|
|
2086
|
+
catch (e) {
|
|
2087
|
+
lines.push(`${pre}${sandbox.AGENT_NAME[f.front]}: not changed: ${e instanceof Error ? e.message : String(e)}`);
|
|
2088
|
+
continue;
|
|
2089
|
+
}
|
|
2090
|
+
if (sandbox.declinedHere(env, f.front))
|
|
2091
|
+
sandbox.setSandboxDeclined(home, f.front, false);
|
|
2092
|
+
lines.push(f.front === "codex" ? `${pre}Codex reads config.toml when it starts: restart open Codex sessions.` : `${pre}Claude Code applies settings changes to open sessions at their next command.`);
|
|
2093
|
+
}
|
|
2094
|
+
return { lines, written };
|
|
2095
|
+
}
|
|
2096
|
+
/** A question whose answer defaults to Yes (Enter): only ever for what tightens, such as the sandbox offer. */
|
|
2097
|
+
async function askDefaultYes(io, q) {
|
|
2098
|
+
if (io.select) {
|
|
2099
|
+
const lines = q.split("\n");
|
|
2100
|
+
const r = await io.select({ intro: lines.slice(0, -1), message: lines[lines.length - 1] || "Continue?", choices: [{ value: "yes", label: "Yes" }, { value: "no", label: "No" }], initial: "yes" });
|
|
2101
|
+
return r?.[0] === "yes";
|
|
2102
|
+
}
|
|
2103
|
+
if (!io.prompt)
|
|
2104
|
+
return false;
|
|
2105
|
+
const a = (await io.prompt(`${q} [Y/n] `)).trim().toLowerCase();
|
|
2106
|
+
return a === "" || a === "y" || a === "yes";
|
|
2107
|
+
}
|
|
1921
2108
|
/** The running `p2p` script (the bundled p2p.mjs, or dist/bin.js), for Codex to start. */
|
|
1922
2109
|
function selfScript(deps) {
|
|
1923
2110
|
const p = deps.scriptPath ?? process.argv[1] ?? "";
|
|
@@ -1960,6 +2147,23 @@ function codexCommands(program, deps, io) {
|
|
|
1960
2147
|
try {
|
|
1961
2148
|
const script = selfScript(deps);
|
|
1962
2149
|
out(Boolean(o.json), codex.installCommand({ env: deps.env, node: deps.nodeCommand ?? process.execPath, script, ...(o.codexHome ? { codexHome: resolve(o.codexHome) } : {}), write: o.write, remove: o.remove }));
|
|
2150
|
+
// Then the sandbox offer for Codex (sandbox.ts), once, to the person at a terminal (default Yes).
|
|
2151
|
+
if (o.write && !o.remove && !o.json && (io.prompt || io.select) && !ixLocal.ciEnv(deps.env)) {
|
|
2152
|
+
const env = o.codexHome ? { ...deps.env, CODEX_HOME: resolve(o.codexHome) } : deps.env;
|
|
2153
|
+
let here = true;
|
|
2154
|
+
try {
|
|
2155
|
+
sandbox.assertPersonOutsideAgents({ env }, "codex install --write");
|
|
2156
|
+
}
|
|
2157
|
+
catch {
|
|
2158
|
+
here = false;
|
|
2159
|
+
}
|
|
2160
|
+
const plans = here && !sandbox.declinedHere(env, "codex") ? sandbox.offerablePlans(env, ["codex"]) : [];
|
|
2161
|
+
if (plans.length > 0) {
|
|
2162
|
+
const r = await askEachAgent(io, env, resolveHome(env), plans, { from: "codex install" });
|
|
2163
|
+
for (const l of r.lines)
|
|
2164
|
+
io.out(l.trim());
|
|
2165
|
+
}
|
|
2166
|
+
}
|
|
1963
2167
|
}
|
|
1964
2168
|
catch (e) {
|
|
1965
2169
|
fail(Boolean(o.json), e);
|
|
@@ -2090,7 +2294,10 @@ export async function main(argvIn, deps) {
|
|
|
2090
2294
|
front,
|
|
2091
2295
|
env,
|
|
2092
2296
|
...(byToken && deps.front !== true ? { frontToken: token, frontFresh: !projects.identityHere(home) } : {}),
|
|
2093
|
-
|
|
2297
|
+
// A token that couldn't be checked because the keys it derives from are in a keychain that can't
|
|
2298
|
+
// be read now (keystore.ts) isn't stale: the command runs without it, and one that needs the keys
|
|
2299
|
+
// stops with the keychain's own error (`p2p doctor` still diagnoses).
|
|
2300
|
+
...(linked ? { personTokenLinked: true } : given && !front && !keystore.keysUnreadable(home) ? { personTokenStale: true } : {}),
|
|
2094
2301
|
};
|
|
2095
2302
|
}
|
|
2096
2303
|
// `--no-input` anywhere before `--`: no pickers, no questions (as a script would run).
|
|
@@ -2104,10 +2311,10 @@ export async function main(argvIn, deps) {
|
|
|
2104
2311
|
// `p2p` alone on a terminal: the home screen. Piped, it prints the help as before.
|
|
2105
2312
|
if (argv.length === 0 && deps.io.pretty && !deps.noInput)
|
|
2106
2313
|
argv = ["home"];
|
|
2107
|
-
//
|
|
2314
|
+
// Built-in inspections need no extension: loading one records where it came from
|
|
2108
2315
|
// (<home>/extension-locations.json) and runs its code, so it is skipped.
|
|
2109
|
-
const
|
|
2110
|
-
const extensions = deps.extensions ?? (
|
|
2316
|
+
const isInspection = ["doctor", "version"].includes(argv.find((a) => !a.startsWith("-")) ?? "");
|
|
2317
|
+
const extensions = deps.extensions ?? (isInspection ? new ExtensionRegistry() : await loadInstalled(deps));
|
|
2111
2318
|
const program = buildProgram({ ...deps, extensions });
|
|
2112
2319
|
process.exitCode = 0;
|
|
2113
2320
|
try {
|
package/dist/config.d.ts
CHANGED
|
@@ -37,6 +37,11 @@ export interface FileConfig {
|
|
|
37
37
|
* agent hint. `p2p setup --ix` offers it again. Ix is optional; Peer2Peer never installs it.
|
|
38
38
|
*/
|
|
39
39
|
ixDeclined?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* The agents the person said no for when `p2p setup` (or `p2p codex install --write`) offered to deny
|
|
42
|
+
* P2P_HOME to their sandboxes (sandbox.ts; `true`: both): not offered again. `p2p sandbox enable` asks again.
|
|
43
|
+
*/
|
|
44
|
+
sandboxDeclined?: boolean | ("claude" | "codex")[];
|
|
40
45
|
/**
|
|
41
46
|
* Messages from your own agent sessions skip the hold in a session that approves its own tool calls
|
|
42
47
|
* (`p2p own-agents deliver`, person only). Off by default: they are held like a peer's. No variable
|
package/dist/doctor.d.ts
CHANGED
|
@@ -155,6 +155,13 @@ export declare function clockVerdict(skews: readonly {
|
|
|
155
155
|
}[]): Check;
|
|
156
156
|
/** "Where your data goes" for this device (no probes: what the code does, and this device's settings). */
|
|
157
157
|
export declare function dataFlowOf(app: Pick<App, "env" | "home">, ix: Pick<DataFlow, "graphMemory" | "graphs" | "graphsNotListed">): DataFlow;
|
|
158
|
+
/**
|
|
159
|
+
* One line per installed front end: does its agent's sandbox deny its commands read and write
|
|
160
|
+
* access to P2P_HOME? That is the boundary the CLI's own gates rest on (an agent running as you can
|
|
161
|
+
* otherwise read the key files). Read from the person's config files; nothing is written, and
|
|
162
|
+
* nothing of their contents is shown.
|
|
163
|
+
*/
|
|
164
|
+
export declare function sandboxChecks(c: Checks, app: App): void;
|
|
158
165
|
/**
|
|
159
166
|
* The Ix section: the binary and its version, the local backend (reachable at the local endpoint),
|
|
160
167
|
* whether the project here is mapped, and the graph target of the project here and of each project
|
package/dist/doctor.js
CHANGED
|
@@ -41,7 +41,9 @@ import { rosterAudience, sessionRef } from "./sessions.js";
|
|
|
41
41
|
import { EVENT_RETENTION_MS } from "./state.js";
|
|
42
42
|
import { enabledNamespaces } from "./extensions.js";
|
|
43
43
|
import { extIxInstalled, ixBinary, ixDeclined, IX_INSTALL_URL, ixInstallLine, ixMemorySupport, ixVersion, runIx } from "./ix-local.js";
|
|
44
|
-
import { personHere } from "./projects.js";
|
|
44
|
+
import { identityHere, personHere } from "./projects.js";
|
|
45
|
+
import { keyStoreStatus } from "./keystore.js";
|
|
46
|
+
import { sandboxFix, sandboxReport } from "./sandbox.js";
|
|
45
47
|
import { graphMemoryReport } from "./graph-memory.js";
|
|
46
48
|
import { graphMemoryEnabled } from "./config.js";
|
|
47
49
|
import { historySettings } from "./history.js";
|
|
@@ -554,6 +556,7 @@ async function deviceChecks(c, app, o, ms, reports) {
|
|
|
554
556
|
if (dropped > 0) {
|
|
555
557
|
c.add("inbound", "unknown", "incoming envelopes", `${dropped} couldn't be applied and ${dropped === 1 ? "was" : "were"} dropped after failing for good (or every attempt)`, "if messages from someone seem missing, ask them to send again; P2P_DEBUG=1 on `p2p ls` shows why one fails");
|
|
556
558
|
}
|
|
559
|
+
sandboxChecks(c, app);
|
|
557
560
|
const ix = await ixChecks(c, app, ms);
|
|
558
561
|
await versionCheck(c, app, o, ms);
|
|
559
562
|
return dataFlowOf(app, ix);
|
|
@@ -569,6 +572,39 @@ export function dataFlowOf(app, ix) {
|
|
|
569
572
|
};
|
|
570
573
|
}
|
|
571
574
|
// ---------------------------------------------------------------------------
|
|
575
|
+
// The agents' sandboxes (sandbox.ts): whether Claude Code's and Codex's deny P2P_HOME
|
|
576
|
+
/**
|
|
577
|
+
* One line per installed front end: does its agent's sandbox deny its commands read and write
|
|
578
|
+
* access to P2P_HOME? That is the boundary the CLI's own gates rest on (an agent running as you can
|
|
579
|
+
* otherwise read the key files). Read from the person's config files; nothing is written, and
|
|
580
|
+
* nothing of their contents is shown.
|
|
581
|
+
*/
|
|
582
|
+
export function sandboxChecks(c, app) {
|
|
583
|
+
let r;
|
|
584
|
+
try {
|
|
585
|
+
r = sandboxReport(app.env);
|
|
586
|
+
}
|
|
587
|
+
catch {
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
const fix = sandboxFix(personHere(app));
|
|
591
|
+
const rows = [
|
|
592
|
+
["sandbox-claude", "Claude Code sandbox", r.claude],
|
|
593
|
+
["sandbox-codex", "Codex sandbox", r.codex],
|
|
594
|
+
];
|
|
595
|
+
for (const [id, title, s] of rows) {
|
|
596
|
+
if (!s.present && s.state !== "on")
|
|
597
|
+
continue;
|
|
598
|
+
const notes = s.notes.length > 0 ? ` (${s.notes.join("; ")})` : "";
|
|
599
|
+
if (s.state === "on")
|
|
600
|
+
c.add(id, s.notes.length > 0 ? "unknown" : "ok", title, `${s.detail}${notes}`, s.notes.length > 0 ? "see the note: it lets some commands past the deny" : undefined);
|
|
601
|
+
else if (s.state === "off")
|
|
602
|
+
c.add(id, "fail", title, `${s.detail}${notes}`, `${fix}${r.declined ? " (you said no when `p2p setup` offered it)" : ""}`);
|
|
603
|
+
else
|
|
604
|
+
c.add(id, "unknown", title, `${s.detail}${notes}`, s.state === "unavailable" ? "run your agent where its sandbox works (macOS, Linux, WSL2)" : `check ${s.settings}, then \`p2p sandbox\``);
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
// ---------------------------------------------------------------------------
|
|
572
608
|
// Ix (epic #41): the local CLI, its backend, this checkout's map, and each project's graph target
|
|
573
609
|
/** At most this many projects' graph targets are listed. */
|
|
574
610
|
const MAX_GRAPH_ROWS = 10;
|
|
@@ -896,6 +932,23 @@ async function userChecks(c, app, userId, ms, mine) {
|
|
|
896
932
|
}
|
|
897
933
|
}
|
|
898
934
|
// ---------------------------------------------------------------------------
|
|
935
|
+
/** Where this device's keys are kept (`p2p keys backend`), and whether they could be read. Never a secret. */
|
|
936
|
+
function keyStorageCheck(c, ks) {
|
|
937
|
+
const store = ks.keys === "keychain" ? `${ks.keychain.label} (item ${ks.item?.service})` : "files in P2P_HOME (cli/keys.json, 0600)";
|
|
938
|
+
if (ks.keys === "none") {
|
|
939
|
+
c.add("key-storage", "ok", "key storage", `no keys here yet; new ones go to ${ks.configured === "keychain" ? ks.keychain.label : "files in P2P_HOME"}`);
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
942
|
+
if (!ks.readable) {
|
|
943
|
+
c.add("key-storage", "fail", "key storage", `${store}: the keys can't be read${ks.problem ? ` (${errText(ks.problem)})` : ""}`, ks.keys === "keychain" ? "unlock the keychain (or install its tool) and run the command again; nothing makes new keys in their place" : "check cli/keys.json in P2P_HOME");
|
|
944
|
+
return;
|
|
945
|
+
}
|
|
946
|
+
if (ks.problem) {
|
|
947
|
+
c.add("key-storage", "unknown", "key storage", `${store}, readable; ${errText(ks.problem)}`, ks.leftovers?.length && !/hasn't finished|stay in the keychain/.test(ks.problem) ? "run any p2p command that isn't read-only (`p2p whoami`): it removes them" : "run `p2p keys backend keychain` (or `p2p keys backend file`) in your own terminal");
|
|
948
|
+
return;
|
|
949
|
+
}
|
|
950
|
+
c.add("key-storage", "ok", "key storage", `${store}, readable${ks.keys === "file" && ks.keychain.available ? `; \`p2p keys backend keychain\` moves them into ${ks.keychain.label}` : ""}`);
|
|
951
|
+
}
|
|
899
952
|
export function summarize(checks) {
|
|
900
953
|
return {
|
|
901
954
|
ok: checks.filter((x) => x.status === "ok").length,
|
|
@@ -922,7 +975,23 @@ export async function doctor(app, o) {
|
|
|
922
975
|
app.tun.requestTimeoutMs = ms;
|
|
923
976
|
const c = new Checks();
|
|
924
977
|
const scope = o.user !== undefined ? "user" : "device";
|
|
925
|
-
|
|
978
|
+
let loadError;
|
|
979
|
+
const hasIdentity = await app.load(false).catch((e) => {
|
|
980
|
+
loadError = e;
|
|
981
|
+
return false;
|
|
982
|
+
});
|
|
983
|
+
// Where the keys are kept, and whether they could be read (keystore.ts): first, since nothing else works without them.
|
|
984
|
+
const ks = keyStoreStatus(app.home);
|
|
985
|
+
// About another user only when they can't be read (nothing about them can be checked then).
|
|
986
|
+
if (scope === "device" || (ks.keys !== "none" && !ks.readable))
|
|
987
|
+
keyStorageCheck(c, ks);
|
|
988
|
+
if (!hasIdentity && ks.keys !== "none" && identityHere(app.home)) {
|
|
989
|
+
c.add("identity", "fail", "identity", `this device holds an identity, but it couldn't be loaded: ${errText(loadError ?? ks.problem)}`, ks.keys === "keychain" ? "unlock the keychain (or install its tool), then run `p2p doctor` again; p2p never makes new keys in their place" : `check ${app.home}/cli/keys.json`);
|
|
990
|
+
await versionCheck(c, app, o, ms);
|
|
991
|
+
if (scope === "device")
|
|
992
|
+
sandboxChecks(c, app);
|
|
993
|
+
return { scope, version: o.version, ...(o.user !== undefined ? { user: { input: o.user } } : {}), checks: c.list, summary: summarize(c.list) };
|
|
994
|
+
}
|
|
926
995
|
if (!hasIdentity) {
|
|
927
996
|
c.add("identity", "fail", "identity", "this device has no Peer2Peer identity yet", "run `/peers setup` in Claude Code (or `p2p setup`), then `/peers join <code>` with a code from a friend");
|
|
928
997
|
let relays;
|
|
@@ -937,6 +1006,8 @@ export async function doctor(app, o) {
|
|
|
937
1006
|
else
|
|
938
1007
|
relayChecks(c, app, await probeRelays(app, relays, ms, false), undefined);
|
|
939
1008
|
await versionCheck(c, app, o, ms);
|
|
1009
|
+
if (scope === "device")
|
|
1010
|
+
sandboxChecks(c, app);
|
|
940
1011
|
return { scope, version: o.version, ...(o.user !== undefined ? { user: { input: o.user } } : {}), checks: c.list, summary: summarize(c.list) };
|
|
941
1012
|
}
|
|
942
1013
|
const reports = await probeRelays(app, app.relays, ms, true, app.userId);
|
package/dist/format.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { CodeRow } from "./codes.js";
|
|
|
4
4
|
import type { DeviceRow, WhoamiResult } from "./identity.js";
|
|
5
5
|
import type { PeerRow, RosterView } from "./sessions.js";
|
|
6
6
|
import type { FriendRow } from "./social.js";
|
|
7
|
-
import type { RotateResult, RotationPlan } from "./rotation.js";
|
|
7
|
+
import type { BranchSummary, RotateResult, RotationPlan } from "./rotation.js";
|
|
8
8
|
export declare function formatAge(sec: number): string;
|
|
9
9
|
export declare function formatDate(sec: number): string;
|
|
10
10
|
export declare function plural(n: number, one: string, many?: string): string;
|
|
@@ -39,6 +39,8 @@ export declare function formatMembers(r: {
|
|
|
39
39
|
}): string;
|
|
40
40
|
export declare function formatRoster(r: RosterView): string;
|
|
41
41
|
export declare function formatJoin(r: JoinResult): string;
|
|
42
|
+
/** One branch summary as text: `<hash> (ver N, published by ...; relays ...)`. */
|
|
43
|
+
export declare function branchLine(b: BranchSummary): string;
|
|
42
44
|
export declare function formatRotationPlan(p: RotationPlan): string;
|
|
43
45
|
export declare function formatRotation(r: RotateResult): string;
|
|
44
46
|
/**
|
package/dist/format.js
CHANGED
|
@@ -187,12 +187,24 @@ export function formatJoin(r) {
|
|
|
187
187
|
return `Not joined "${r.name}" (${r.cid}): ${r.refused}.`;
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
|
+
/** One branch summary as text: `<hash> (ver N, published by ...; relays ...)`. */
|
|
191
|
+
export function branchLine(b) {
|
|
192
|
+
return `${b.hash} (ver ${b.ver}, published by ${b.by.join(", ") || "?"}; relays ${b.relays.join(", ") || "?"})`;
|
|
193
|
+
}
|
|
190
194
|
export function formatRotationPlan(p) {
|
|
191
195
|
// A label from a version this device didn't publish is shown as such (pre-release re-review N2), and so is why a device is dropped.
|
|
192
196
|
const dev = (d) => ` ${d.did}${d.label ? ` (${d.labelTrusted === false ? "unverified label: " : ""}${sanitizePeerText(d.label, 64)})` : ""}${d.keyholder ? ", key holder" : ""}${d.why ? `: DROPPED, ${d.why} (keep it with --keep ${d.did})` : ""}`;
|
|
193
197
|
return [
|
|
194
198
|
`${p.contest ? "Contesting a rotation you didn't publish: moving" : "Rotating"} ${p.address} to a new identity key ${p.newFingerprint} (§2.8).`,
|
|
195
199
|
...(p.backup ? [`Its backup phrase is in ${p.backup.file}.`] : []),
|
|
200
|
+
// #91: a branch picked by provenance among others that still list this device is never picked silently.
|
|
201
|
+
...(p.branch && p.otherBranches?.length
|
|
202
|
+
? [
|
|
203
|
+
`Your identity is forked: this plan builds on the branch ${p.branch} as yours (its versions come from your devices). Other branches still list this device:\n${p.otherBranches
|
|
204
|
+
.map((b) => ` ${branchLine(b)}`)
|
|
205
|
+
.join("\n")}\nIf ${p.branch} isn't yours, drop this plan (--cancel) and choose with --plan --branch <hash>.`,
|
|
206
|
+
]
|
|
207
|
+
: []),
|
|
196
208
|
p.follow.length ? `These devices get the rotation to follow (each follows only when you accept it there):\n${p.follow.map(dev).join("\n")}` : "No other device follows.",
|
|
197
209
|
...(p.excluded.length ? [`These devices do NOT follow (excluded):\n${p.excluded.map(dev).join("\n")}`] : []),
|
|
198
210
|
`${plural(p.friends, "friend")} get a fresh invite (they approve it); ${plural(p.owned, "circle")} you own move to the new key; in ${plural(p.memberOf, "other circle")} the owner swaps you in.`,
|
package/dist/identity.js
CHANGED
|
@@ -16,6 +16,7 @@ import { receiving } from "./inbound.js";
|
|
|
16
16
|
import { recordJoin, resignJoin } from "./circle-ops.js";
|
|
17
17
|
import { setupIx } from "./ix-local.js";
|
|
18
18
|
import { renewPersonToken } from "./projects.js";
|
|
19
|
+
import { forgetKeychainItem } from "./keystore.js";
|
|
19
20
|
/** The `p2p` command as the person types it here (Windows PowerShell blocks npm's p2p.ps1 shim; p2p.cmd works everywhere on Windows). */
|
|
20
21
|
export function p2pCommand(platform = process.platform) {
|
|
21
22
|
return platform === "win32" ? "p2p.cmd" : "p2p";
|
|
@@ -560,6 +561,7 @@ export async function backupRestore(app, phrase, opts) {
|
|
|
560
561
|
// review N-H1: nothing is committed unless a relay took the new version. The home was fresh
|
|
561
562
|
// (checked above), and no relay can hold the new version (every publish was refused outright or
|
|
562
563
|
// never reached a relay), so its state directories go; config.json stays.
|
|
564
|
+
forgetKeychainItem(app.home, app.keys?.did);
|
|
563
565
|
await rm(join(app.home, "cli"), { recursive: true, force: true });
|
|
564
566
|
await rm(join(app.home, "v3"), { recursive: true, force: true });
|
|
565
567
|
throw e;
|