@peer2peer/cli 0.1.3 → 0.1.4
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 +7 -6
- package/dist/app.d.ts +20 -0
- package/dist/app.js +77 -12
- package/dist/cli.d.ts +4 -4
- package/dist/cli.js +200 -1
- 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/procstart.js +11 -3
- package/dist/projects.js +4 -8
- 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 +3 -3
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import * as codex from "@peer2peer/codex-bridge";
|
|
2
|
+
import { type Env, type FileConfig } from "./config.js";
|
|
3
|
+
import type { App } from "./app.js";
|
|
4
|
+
/** The person's home folder, as the agents expand `~` (HOME, USERPROFILE on Windows). */
|
|
5
|
+
export declare function userHomeOf(env: Env): string;
|
|
6
|
+
/** P2P_HOME, absolute, and its real path when that differs (a symbolic link on the way). */
|
|
7
|
+
export declare function p2pHomePaths(env: Env): {
|
|
8
|
+
home: string;
|
|
9
|
+
real?: string;
|
|
10
|
+
};
|
|
11
|
+
/** Claude Code's user settings file: `$CLAUDE_CONFIG_DIR/settings.json`, else `~/.claude/settings.json`. */
|
|
12
|
+
export declare function claudeSettingsPath(env: Env): string;
|
|
13
|
+
/** Managed settings (what an organization deploys): read for the status only, never written. */
|
|
14
|
+
export declare function claudeManagedPath(platform?: NodeJS.Platform): string | undefined;
|
|
15
|
+
/** What Claude Code's settings should hold for P2P_HOME: the sandbox paths, and the file tools' rules. */
|
|
16
|
+
export declare function claudeWanted(paths: {
|
|
17
|
+
home: string;
|
|
18
|
+
real?: string;
|
|
19
|
+
}, userHome: string): {
|
|
20
|
+
sandbox: string[];
|
|
21
|
+
read: string[];
|
|
22
|
+
edit: string[];
|
|
23
|
+
};
|
|
24
|
+
export interface ClaudeSandboxStatus {
|
|
25
|
+
/** on: every piece is in place; off: something is missing; unknown: settings couldn't be read; unavailable: no sandbox on this platform. */
|
|
26
|
+
state: "on" | "off" | "unknown" | "unavailable";
|
|
27
|
+
detail: string;
|
|
28
|
+
/** What is missing (each a settings key or rule). */
|
|
29
|
+
missing: string[];
|
|
30
|
+
/** Things that weaken it. */
|
|
31
|
+
notes: string[];
|
|
32
|
+
settings: string;
|
|
33
|
+
}
|
|
34
|
+
/** The most a config file read here may hold: anything bigger is treated as unreadable. */
|
|
35
|
+
export declare const MAX_CONFIG_BYTES: number;
|
|
36
|
+
/**
|
|
37
|
+
* Reads a config file safely, whoever put it there (a cloned repository's `.claude` or `.codex`):
|
|
38
|
+
* opened non-blocking (a FIFO can't hang the read), it must be a regular file once a symbolic link
|
|
39
|
+
* is followed (not a FIFO, a device such as /dev/zero, or a folder), and at most MAX_CONFIG_BYTES.
|
|
40
|
+
* null when it doesn't exist; throws a CliError when it can't be read that way.
|
|
41
|
+
*/
|
|
42
|
+
export declare function readConfigFile(path: string): string | null;
|
|
43
|
+
/** The folders whose `.claude` settings a session here loads: its working directory and, in a git repository, the repository root. */
|
|
44
|
+
export declare function projectRoots(workdir: string): string[];
|
|
45
|
+
/**
|
|
46
|
+
* Whether Claude Code's sandbox denies its commands (and its file tools) P2P_HOME: from the user,
|
|
47
|
+
* managed and this folder's project settings (`.claude/settings.json` and `.claude/settings.local.json`
|
|
48
|
+
* in the session's folder and its repository root), and, on Linux, whether bubblewrap is there.
|
|
49
|
+
*/
|
|
50
|
+
export declare function claudeSandboxStatus(env: Env, o?: {
|
|
51
|
+
platform?: NodeJS.Platform;
|
|
52
|
+
managedPath?: string | null;
|
|
53
|
+
workdir?: string;
|
|
54
|
+
}): ClaudeSandboxStatus;
|
|
55
|
+
/** One change to settings.json, for the preview. */
|
|
56
|
+
export type JsonEdit = {
|
|
57
|
+
key: string;
|
|
58
|
+
value: unknown;
|
|
59
|
+
was?: unknown;
|
|
60
|
+
append?: boolean;
|
|
61
|
+
};
|
|
62
|
+
export type ClaudeSandboxPlan = {
|
|
63
|
+
kind: "already";
|
|
64
|
+
} | {
|
|
65
|
+
kind: "edit";
|
|
66
|
+
after: string;
|
|
67
|
+
edits: JsonEdit[];
|
|
68
|
+
} | {
|
|
69
|
+
kind: "manual";
|
|
70
|
+
reason: string;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* The edit to Claude Code's user settings (`text`, null when the file doesn't exist) that denies
|
|
74
|
+
* P2P_HOME to its sandboxed commands and file tools, keeping every other key and the file's
|
|
75
|
+
* indentation. Idempotent: entries already there (or a folder above P2P_HOME) aren't added again.
|
|
76
|
+
*/
|
|
77
|
+
export declare function planClaudeSandbox(text: string | null, env: Env): ClaudeSandboxPlan;
|
|
78
|
+
export interface FrontPlan {
|
|
79
|
+
front: "claude" | "codex";
|
|
80
|
+
/** The file the edit writes. */
|
|
81
|
+
path: string;
|
|
82
|
+
/** Whether the agent looks installed (its config folder exists). */
|
|
83
|
+
present: boolean;
|
|
84
|
+
status: {
|
|
85
|
+
state: string;
|
|
86
|
+
detail: string;
|
|
87
|
+
notes: string[];
|
|
88
|
+
};
|
|
89
|
+
plan: {
|
|
90
|
+
kind: "already";
|
|
91
|
+
} | {
|
|
92
|
+
kind: "edit";
|
|
93
|
+
before: string | null;
|
|
94
|
+
after: string;
|
|
95
|
+
preview: string[]; /** Codex: what the new profile extends. */
|
|
96
|
+
base?: string; /** Codex: the config set no sandbox, so the base was chosen. */
|
|
97
|
+
assumed?: true;
|
|
98
|
+
} | {
|
|
99
|
+
kind: "manual";
|
|
100
|
+
reason: string;
|
|
101
|
+
snippet?: string;
|
|
102
|
+
} | {
|
|
103
|
+
kind: "unavailable";
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/** The Codex home (CODEX_HOME, else ~/.codex) and its config.toml. */
|
|
107
|
+
export declare function codexConfigPath(env: Env): string;
|
|
108
|
+
/** The deny paths for Codex's config (`~/…` under the home folder). */
|
|
109
|
+
export declare function codexDenyPathsOf(env: Env): string[];
|
|
110
|
+
/**
|
|
111
|
+
* Why P2P_HOME can't be denied safely, or undefined: a path with rule or glob characters (it would
|
|
112
|
+
* match something else, or break the rule), or the home folder itself, `/` or a folder above the home
|
|
113
|
+
* folder (denying it would lock the agents out of everything).
|
|
114
|
+
*/
|
|
115
|
+
export declare function p2pHomeProblem(env: Env): string | undefined;
|
|
116
|
+
export declare function codexStatus(env: Env, o?: {
|
|
117
|
+
workdir?: string;
|
|
118
|
+
}): codex.CodexSandboxStatus & {
|
|
119
|
+
settings: string;
|
|
120
|
+
};
|
|
121
|
+
export interface PlanOptions {
|
|
122
|
+
platform?: NodeJS.Platform;
|
|
123
|
+
managedPath?: string | null;
|
|
124
|
+
workdir?: string;
|
|
125
|
+
/** For a Codex config that sets no sandbox at all: what the new profile extends (default :read-only). */
|
|
126
|
+
codexBase?: ":read-only" | ":workspace";
|
|
127
|
+
}
|
|
128
|
+
/** What `enable` would do for one front end (computed, nothing written). */
|
|
129
|
+
export declare function planFront(front: "claude" | "codex", env: Env, o?: PlanOptions): FrontPlan;
|
|
130
|
+
/** The name the person knows each front end's agent by. */
|
|
131
|
+
export declare const AGENT_NAME: Record<"claude" | "codex", string>;
|
|
132
|
+
/** What one agent's edit does, in full, then the exact lines: asked about on its own. */
|
|
133
|
+
export declare function frontPreview(f: FrontPlan, p2pHome: string, userHome: string): string;
|
|
134
|
+
/** The question for one agent. */
|
|
135
|
+
export declare function frontQuestion(f: FrontPlan): string;
|
|
136
|
+
/**
|
|
137
|
+
* Writes the planned edits. Each file must still hold what the preview was made from (else nothing
|
|
138
|
+
* is written). The backup sits next to the path as named (a symbolic link's own folder, not its
|
|
139
|
+
* target's), 0600, created exclusively; the new content is written atomically to the link's target,
|
|
140
|
+
* keeping its mode.
|
|
141
|
+
*/
|
|
142
|
+
export declare function applyPlans(plans: readonly FrontPlan[], now?: Date): {
|
|
143
|
+
path: string;
|
|
144
|
+
backup?: string;
|
|
145
|
+
}[];
|
|
146
|
+
/**
|
|
147
|
+
* Only the person changes an agent's sandbox, at their own terminal, outside every agent's session:
|
|
148
|
+
* never with a front end's token (that would be an agent's front end changing its own sandbox), and
|
|
149
|
+
* never when the process tree can't be read (fail closed).
|
|
150
|
+
*/
|
|
151
|
+
export declare function assertPersonOutsideAgents(app: {
|
|
152
|
+
env: Env;
|
|
153
|
+
front?: boolean;
|
|
154
|
+
}, what: string): void;
|
|
155
|
+
type Front = "claude" | "codex";
|
|
156
|
+
/** Which agents the person said no for (FileConfig.sandboxDeclined: `true` for both, as an older answer, or a list). */
|
|
157
|
+
export declare function sandboxDeclined(file: Pick<FileConfig, "sandboxDeclined">, front?: Front): boolean;
|
|
158
|
+
/** Records the person's answer for one agent. */
|
|
159
|
+
export declare function setSandboxDeclined(home: string, front: Front, declined: boolean): void;
|
|
160
|
+
/** The front ends worth offering: installed here (their config folder exists), with an edit to make. */
|
|
161
|
+
export declare function offerablePlans(env: Env, only?: readonly Front[], o?: PlanOptions): FrontPlan[];
|
|
162
|
+
/** Whether the person said no before, for `front` (any, without one); config.json unreadable counts as no answer. */
|
|
163
|
+
export declare function declinedHere(env: Env, front?: Front): boolean;
|
|
164
|
+
/** Whether a front end's config folder is here at all. */
|
|
165
|
+
export declare function frontPresent(front: "claude" | "codex", env: Env): boolean;
|
|
166
|
+
/**
|
|
167
|
+
* The one-time notice a front end shows its person (never its model) when its agent's sandbox
|
|
168
|
+
* doesn't deny P2P_HOME: the command to run in their own terminal. Undefined when the sandbox
|
|
169
|
+
* already does, the person said no before, it was shown already (once per device and front end),
|
|
170
|
+
* or the caller is neither the person's front end nor the person. An agent's shell without the token
|
|
171
|
+
* can't use it up; one that already reads P2P_HOME (no sandbox yet) can take the token and can.
|
|
172
|
+
*/
|
|
173
|
+
export declare function sandboxNotice(app: App, front: "claude" | "codex"): Promise<string | undefined>;
|
|
174
|
+
export interface SandboxReport {
|
|
175
|
+
p2pHome: string;
|
|
176
|
+
/** The person said no to the offer before. */
|
|
177
|
+
declined: boolean;
|
|
178
|
+
claude: ClaudeSandboxStatus & {
|
|
179
|
+
present: boolean;
|
|
180
|
+
};
|
|
181
|
+
codex: codex.CodexSandboxStatus & {
|
|
182
|
+
settings: string;
|
|
183
|
+
present: boolean;
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/** Both front ends' sandbox status (read-only; whoever asks). */
|
|
187
|
+
export declare function sandboxReport(env: Env, o?: {
|
|
188
|
+
platform?: NodeJS.Platform;
|
|
189
|
+
managedPath?: string | null;
|
|
190
|
+
workdir?: string;
|
|
191
|
+
}): SandboxReport;
|
|
192
|
+
/** The fix, said to the person, or to an agent (which never runs it). */
|
|
193
|
+
export declare function sandboxFix(person: boolean): string;
|
|
194
|
+
export declare function sandboxHuman(r: SandboxReport, person: boolean): string;
|
|
195
|
+
export {};
|