@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,240 @@
1
+ import { isAgentProcess } from "./ancestry.js";
2
+ import type { App } from "./app.js";
3
+ /** The person's own terminal session (`p2p tui`, `p2p send` with no --from-session). */
4
+ export declare const PERSON_SESSION = "tui";
5
+ /** The committed file a repository may carry to ask for privacy (it can never widen anything). */
6
+ export declare const PRIVATE_MARKER = ".p2p-private";
7
+ /**
8
+ * The directory a session works in, as the CLI sees it: P2P_WORKDIR when it names an existing
9
+ * absolute directory (the Claude mod and the Codex bridge run p2p from elsewhere and pass the
10
+ * session's folder there), else the process's own.
11
+ */
12
+ export declare function sessionWorkdir(env: Record<string, string | undefined>): string;
13
+ /**
14
+ * Every folder a session works in, as its front end tells the CLI: its working directory
15
+ * (sessionWorkdir) and P2P_PROJECT_DIRS (path-delimited: folders it moved to, files it touched
16
+ * elsewhere). Anyone may add to these: a binding only ever narrows who the session reaches.
17
+ */
18
+ export declare function sessionDirs(env: Record<string, string | undefined>): {
19
+ dirs: string[];
20
+ over: boolean;
21
+ };
22
+ /** At most this many folders a front end passes per call; past it the session is private. */
23
+ export declare const MAX_SESSION_DIRS = 512;
24
+ /** At most this many projects per session; past it the session is private. */
25
+ export declare const MAX_SESSION_PROJECTS = 16;
26
+ /** Bindings of sessions not seen for this long are dropped. */
27
+ export declare const SESSION_BINDING_TTL_MS: number;
28
+ /** At most this many circles and people in one project's policy. */
29
+ export declare const MAX_PROJECT_SHARES = 32;
30
+ export interface ProjectRef {
31
+ /** `pj_` + 24 hex: a hash, so state never holds a remote URL's credentials or a path as a key. */
32
+ id: string;
33
+ /** A short display name (the repository or folder name). */
34
+ name: string;
35
+ kind: "git" | "dir";
36
+ /** The working tree's top level (git) or the folder (dir), real path. */
37
+ root: string;
38
+ /** The normalised remote URL (no credentials), when the repository has one. */
39
+ remote?: string;
40
+ /** The repository asks to stay private (a committed PRIVATE_MARKER at `root`). */
41
+ repoPrivate?: true;
42
+ }
43
+ export type ProjectShare = "private" | {
44
+ circles: string[];
45
+ people: string[];
46
+ };
47
+ export interface ProjectPolicyRec {
48
+ name: string;
49
+ root: string;
50
+ remote?: string;
51
+ share: ProjectShare;
52
+ at: number;
53
+ }
54
+ export interface ProjectsDoc {
55
+ v: 1;
56
+ projects: Record<string, ProjectPolicyRec>;
57
+ /** When this device showed the one-time notice that sessions no longer follow the default circle. */
58
+ noticeAt?: number;
59
+ }
60
+ export interface SessionBinding {
61
+ projects: Record<string, {
62
+ name: string;
63
+ repoPrivate?: true;
64
+ }>;
65
+ /** More than MAX_SESSION_PROJECTS projects or MAX_SESSION_DIRS folders: private. */
66
+ over?: true;
67
+ /**
68
+ * What other sessions of this user that sent to this one could reach (own-device messages carry
69
+ * their sender's ceiling): intersected in, sticky, so a private session can't launder through a
70
+ * shared one of yours.
71
+ */
72
+ constraints?: ProjectShare[];
73
+ /** First used by an agent (agentContext) with no front end vouching for it: private until registered. */
74
+ unregistered?: true;
75
+ /** A front end holding the person token (personTokenOk) has used it. */
76
+ registered?: true;
77
+ at: number;
78
+ }
79
+ /** At most this many constraints a session keeps; past it, private. */
80
+ export declare const MAX_SESSION_CONSTRAINTS = 16;
81
+ export type SessionProjectsDoc = Record<string, SessionBinding>;
82
+ /** What a session may reach. `none`: the person's own session, or one not bound yet. */
83
+ export type Ceiling = {
84
+ kind: "none";
85
+ } | {
86
+ kind: "private";
87
+ why: string;
88
+ } | {
89
+ kind: "shared";
90
+ circles: string[];
91
+ people: string[];
92
+ };
93
+ /**
94
+ * A remote URL as one canonical string: scheme, credentials, port-less ssh form, trailing `.git`
95
+ * and slashes dropped, host lower-cased. `https://u:t@GitHub.com/a/b.git` and `git@github.com:a/b`
96
+ * are both `github.com/a/b`. A local path stays a path.
97
+ */
98
+ export declare function normalizeRemote(url: string): string | undefined;
99
+ /**
100
+ * The project `dir` belongs to, read from the files alone (git is never run: no hook, fsmonitor
101
+ * or config of the repository's can execute). A `.git` directory or `gitdir:` file up the tree
102
+ * marks a working tree; its common dir (`commondir` for a linked worktree) identifies the clone.
103
+ */
104
+ export declare function projectOf(dir: string): ProjectRef;
105
+ export declare function projectsDoc(app: App): Promise<ProjectsDoc>;
106
+ /** A project's share as stored, or `private` (no policy: private by default). */
107
+ export declare function shareOf(doc: ProjectsDoc, id: string): ProjectShare;
108
+ export interface ProjectView {
109
+ id: string;
110
+ name: string;
111
+ kind: "git" | "dir";
112
+ root: string;
113
+ remote?: string;
114
+ /** Who it is shared with (`private`: only your own devices). */
115
+ policy: "private" | "shared";
116
+ circles: {
117
+ cid: string;
118
+ name?: string;
119
+ open?: true;
120
+ joined: boolean;
121
+ }[];
122
+ people: {
123
+ userId: string;
124
+ address: string;
125
+ }[];
126
+ /** Why it is private although a policy shares it, or `unmapped` when none does. */
127
+ why?: string;
128
+ repoPrivate?: true;
129
+ }
130
+ export declare function projectView(app: App, ref: Pick<ProjectRef, "id" | "name" | "kind" | "root" | "remote" | "repoPrivate">, doc?: ProjectsDoc): Promise<ProjectView>;
131
+ /**
132
+ * `p2p project share`: share the project at `dir` with circles you joined and friends. Replaces the
133
+ * project's shares with exactly these (`add` keeps the ones it has). Only ever the person's
134
+ * command: no session or file can run it for them (the mod and the Codex bridge refuse it from a
135
+ * model).
136
+ */
137
+ export declare function shareProject(app: App, dir: string, targets: {
138
+ circles?: string[];
139
+ people?: string[];
140
+ add?: boolean;
141
+ }): Promise<{
142
+ project: ProjectView;
143
+ warnings: string[];
144
+ }>;
145
+ /** `p2p project private`: only your own devices see the project's sessions (the default). */
146
+ export declare function makeProjectPrivate(app: App, dir: string): Promise<ProjectView>;
147
+ /** `p2p project ls`: every project with a policy on this device. */
148
+ export declare function listProjects(app: App): Promise<ProjectView[]>;
149
+ /** `p2p project show`: the project at `dir`, its policy and why. */
150
+ export declare function showProject(app: App, dir: string): Promise<ProjectView>;
151
+ /**
152
+ * Binds a session to the projects of `dirs` (sticky: a session's projects only ever grow until it
153
+ * ends), plus a constraint an own-device message carried. The person's own session is never
154
+ * bound; another caller naming it is refused. A session an agent names (agentContext) that no
155
+ * front end of this user has registered (personTokenOk) starts private.
156
+ */
157
+ export declare function bindSession(app: App, sid: string, dirs: readonly string[], o?: {
158
+ person?: boolean;
159
+ over?: boolean;
160
+ constraint?: ProjectShare;
161
+ inbound?: boolean;
162
+ }): Promise<SessionBinding | undefined>;
163
+ /**
164
+ * The variables Claude Code and Codex set in the commands their agents run (an allow-list, from
165
+ * their documentation and source: docs/security/threat-model.md "Project boundaries"). Variables a
166
+ * person sets in their own shell (CODEX_HOME, CODEX_API_KEY, CODEX_PROFILE) never count.
167
+ */
168
+ export declare const AGENT_ENV_VARS: readonly string[];
169
+ /** Whether the environment says this runs inside an agent's tool call. */
170
+ export declare function agentEnv(env: Record<string, string | undefined> | undefined): boolean;
171
+ /** Whether this call runs on an agent's behalf: its environment, or a Claude Code or Codex ancestor (ancestry.ts). */
172
+ export declare function agentContext(env: Record<string, string | undefined> | undefined): boolean;
173
+ export { isAgentProcess };
174
+ /** `<home>/cli/person.key`: a random secret the person's front ends (the Claude mod, the Codex bridge) pass back as P2P_PERSON_TOKEN. */
175
+ export declare function personTokenFile(home: string): string;
176
+ /** The person token, made once (exclusively, 0600, in the CLI's own folder, which the mod's guards keep from the model). */
177
+ export declare function personToken(home: string): string;
178
+ /** Whether P2P_PERSON_TOKEN is this home's person token (read only: a missing file is no match). */
179
+ export declare function personTokenOk(env: Record<string, string | undefined> | undefined, home: string | undefined): boolean;
180
+ /**
181
+ * Checks the person token once, at the start of a command, and takes it out of the environment
182
+ * (this object and the process's), so no child (git, ix, an extension's tool) ever inherits it.
183
+ */
184
+ export declare function takePersonToken(env: Record<string, string | undefined>, home: string | undefined): boolean;
185
+ /** The person's confirmation on their own terminal (tty-confirm.ts), or a test's stand-in. */
186
+ export type ConfirmTty = (question: string) => Promise<boolean>;
187
+ /**
188
+ * Lets a command that widens who reaches this user (sharing a project, a session, a default
189
+ * circle, invites, joins, trust, friends) run only for the person: their front end's token; or,
190
+ * outside any agent's session, their "yes" typed on the controlling terminal (never stdin, never a
191
+ * flag: a process detached from every terminal can't give it). Reads are never asked.
192
+ */
193
+ export declare function assertPersonForWidening(app: Pick<App, "env"> & {
194
+ front?: boolean;
195
+ }, what: string, confirm: ConfirmTty): Promise<void>;
196
+ /** Whether a person-only path (session `tui`) may run here: the person's front end, or no agent in sight (then a terminal "yes" too). */
197
+ export declare function personHere(app: Pick<App, "env"> & {
198
+ front?: boolean;
199
+ }): boolean;
200
+ export declare function sessionBinding(app: App, sid: string): Promise<SessionBinding | undefined>;
201
+ /**
202
+ * The most a session may reach: the intersection of every bound project's policy. Unmapped,
203
+ * private and repository-private projects make it private, and so does an empty intersection.
204
+ */
205
+ export declare function sessionCeiling(app: App, sid: string, binding?: SessionBinding | null): Promise<Ceiling>;
206
+ /** Everyone a ceiling lets in (besides this user): members of its circles who stand in them, and its people. */
207
+ export declare function ceilingAudience(app: App, c: Ceiling): Promise<Set<string> | undefined>;
208
+ /** How to tell the person to share, for an error a model may read: the person's command, never a flag for the caller. */
209
+ export declare function shareHint(names: string[]): string;
210
+ /**
211
+ * The exfiltration barrier: may session `sid` send to `userId`? Your own devices always; the
212
+ * person's own session always; anyone else only within the session's project ceiling.
213
+ */
214
+ export declare function assertMayReach(app: App, sid: string, userId: string, o?: {
215
+ person?: boolean;
216
+ address?: string;
217
+ }): Promise<void>;
218
+ /** Friends of this user (live friendships), for the roster's named parts. */
219
+ export declare function friendIds(app: App): Promise<Set<string>>;
220
+ /** What `p2p status`, `ls` and the mod show about a session's projects. */
221
+ export interface SessionProjectView {
222
+ projects: {
223
+ id: string;
224
+ name: string;
225
+ repoPrivate?: true;
226
+ }[];
227
+ /** `private`: only your own devices see it; `shared`: the circles and people below (all its projects share them). */
228
+ policy: "private" | "shared" | "none";
229
+ why?: string;
230
+ circles?: string[];
231
+ people?: string[];
232
+ }
233
+ export declare function sessionProjectView(app: App, sid: string): Promise<SessionProjectView>;
234
+ /**
235
+ * The one-time notice for a user who relied on the default circle: shown once per device, the
236
+ * first time a session of theirs is private only because its project was never shared.
237
+ */
238
+ export declare function defaultCircleNotice(app: App, sid: string): Promise<string | undefined>;
239
+ /** The text of the one-time notice starts so (the mod and the Codex bridge match it). */
240
+ export declare const PROJECT_NOTICE_PREFIX = "project boundaries:";