@peer2peer/cli 0.0.0-stage → 0.1.1

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 (111) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +370 -2
  3. package/dist/ancestry.d.ts +13 -0
  4. package/dist/ancestry.js +71 -0
  5. package/dist/app.d.ts +368 -0
  6. package/dist/app.js +1181 -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 +660 -0
  12. package/dist/cli.js +1787 -0
  13. package/dist/codes.d.ts +231 -0
  14. package/dist/codes.js +998 -0
  15. package/dist/config.d.ts +159 -0
  16. package/dist/config.js +294 -0
  17. package/dist/doctor.d.ts +113 -0
  18. package/dist/doctor.js +930 -0
  19. package/dist/errors.d.ts +8 -0
  20. package/dist/errors.js +29 -0
  21. package/dist/ext-host.d.ts +38 -0
  22. package/dist/ext-host.js +293 -0
  23. package/dist/extensions.d.ts +487 -0
  24. package/dist/extensions.js +406 -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/graph-memory.d.ts +107 -0
  30. package/dist/graph-memory.js +393 -0
  31. package/dist/history.d.ts +155 -0
  32. package/dist/history.js +697 -0
  33. package/dist/identity.d.ts +239 -0
  34. package/dist/identity.js +759 -0
  35. package/dist/inbound.d.ts +32 -0
  36. package/dist/inbound.js +261 -0
  37. package/dist/index.d.ts +8 -0
  38. package/dist/index.js +14 -0
  39. package/dist/ix-local.d.ts +76 -0
  40. package/dist/ix-local.js +203 -0
  41. package/dist/join-answers.d.ts +49 -0
  42. package/dist/join-answers.js +149 -0
  43. package/dist/outbox.d.ts +109 -0
  44. package/dist/outbox.js +337 -0
  45. package/dist/pretty.d.ts +100 -0
  46. package/dist/pretty.js +256 -0
  47. package/dist/procstart.d.ts +1 -0
  48. package/dist/procstart.js +66 -0
  49. package/dist/progress.d.ts +30 -0
  50. package/dist/progress.js +78 -0
  51. package/dist/projects.d.ts +491 -0
  52. package/dist/projects.js +1383 -0
  53. package/dist/prompt/picker.d.ts +64 -0
  54. package/dist/prompt/picker.js +152 -0
  55. package/dist/prompt/tty.d.ts +29 -0
  56. package/dist/prompt/tty.js +122 -0
  57. package/dist/readonly.d.ts +20 -0
  58. package/dist/readonly.js +50 -0
  59. package/dist/receipts.d.ts +99 -0
  60. package/dist/receipts.js +182 -0
  61. package/dist/relay-client.d.ts +277 -0
  62. package/dist/relay-client.js +873 -0
  63. package/dist/relay-info.d.ts +24 -0
  64. package/dist/relay-info.js +53 -0
  65. package/dist/rotation.d.ts +402 -0
  66. package/dist/rotation.js +2054 -0
  67. package/dist/running.d.ts +5 -0
  68. package/dist/running.js +74 -0
  69. package/dist/sessions.d.ts +355 -0
  70. package/dist/sessions.js +1247 -0
  71. package/dist/shortcode.d.ts +149 -0
  72. package/dist/shortcode.js +465 -0
  73. package/dist/social.d.ts +139 -0
  74. package/dist/social.js +485 -0
  75. package/dist/state.d.ts +509 -0
  76. package/dist/state.js +220 -0
  77. package/dist/stdin.d.ts +17 -0
  78. package/dist/stdin.js +46 -0
  79. package/dist/sync.d.ts +77 -0
  80. package/dist/sync.js +375 -0
  81. package/dist/transient.d.ts +1 -0
  82. package/dist/transient.js +28 -0
  83. package/dist/trust.d.ts +37 -0
  84. package/dist/trust.js +134 -0
  85. package/dist/tty-confirm.d.ts +2 -0
  86. package/dist/tty-confirm.js +53 -0
  87. package/dist/tui/command.d.ts +20 -0
  88. package/dist/tui/command.js +70 -0
  89. package/dist/tui/frame.d.ts +43 -0
  90. package/dist/tui/frame.js +111 -0
  91. package/dist/tui/model.d.ts +221 -0
  92. package/dist/tui/model.js +259 -0
  93. package/dist/tui/sanitize.d.ts +13 -0
  94. package/dist/tui/sanitize.js +151 -0
  95. package/dist/tui/terminal.d.ts +88 -0
  96. package/dist/tui/terminal.js +354 -0
  97. package/dist/tui/tui.d.ts +78 -0
  98. package/dist/tui/tui.js +612 -0
  99. package/dist/tui/view.d.ts +4 -0
  100. package/dist/tui/view.js +358 -0
  101. package/dist/unknown-kinds.d.ts +12 -0
  102. package/dist/unknown-kinds.js +66 -0
  103. package/dist/version.d.ts +1 -0
  104. package/dist/version.js +5 -0
  105. package/dist/want-pow.d.ts +12 -0
  106. package/dist/want-pow.js +46 -0
  107. package/dist/watch.d.ts +35 -0
  108. package/dist/watch.js +331 -0
  109. package/dist/xstate.d.ts +125 -0
  110. package/dist/xstate.js +422 -0
  111. package/package.json +60 -4
@@ -0,0 +1,491 @@
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
+ why: OverWhy[];
22
+ };
23
+ /**
24
+ * Why a session went private for good, past a cap or a gap in what its front end saw:
25
+ * - `projects`: more than MAX_SESSION_PROJECTS projects;
26
+ * - `folders`: more folders than a front end or the CLI keeps (MAX_SESSION_DIRS per call);
27
+ * - `unresolved`: a path its front end couldn't resolve (a variable or `$(…)` it doesn't know, in the path's first segment);
28
+ * - `front`: its front end lost track (a forked conversation, a record it couldn't read; an older front end's bare "over");
29
+ * - `constraints`: more than MAX_SESSION_CONSTRAINTS bounds from own-session messages.
30
+ */
31
+ export type OverWhy = "projects" | "folders" | "unresolved" | "front" | "constraints";
32
+ /** A front end's over reasons (`unresolved,folders`, an array, or `1`/`true` from an older one): an unknown word counts as `front`, never as nothing. */
33
+ export declare function overWhys(v: unknown): OverWhy[];
34
+ /** At most this many folders a front end passes per call; past it the session is private. */
35
+ export declare const MAX_SESSION_DIRS = 512;
36
+ /** At most this many projects per session; past it the session is private. */
37
+ export declare const MAX_SESSION_PROJECTS = 16;
38
+ /** Bindings of sessions not seen for this long are dropped. */
39
+ export declare const SESSION_BINDING_TTL_MS: number;
40
+ /** At most this many circles and people in one project's policy. */
41
+ export declare const MAX_PROJECT_SHARES = 32;
42
+ export interface ProjectRef {
43
+ /** `pj_` + 24 hex: a hash, so state never holds a remote URL's credentials or a path as a key. */
44
+ id: string;
45
+ /** A short display name (the repository or folder name). */
46
+ name: string;
47
+ kind: "git" | "dir";
48
+ /** The working tree's top level (git) or the folder (dir), real path. */
49
+ root: string;
50
+ /** The normalised remote URL (no credentials), when the repository has one. */
51
+ remote?: string;
52
+ /** The repository asks to stay private (a committed PRIVATE_MARKER at `root`). */
53
+ repoPrivate?: true;
54
+ }
55
+ export type ProjectShare = "private" | {
56
+ circles: string[];
57
+ people: string[];
58
+ };
59
+ export interface ProjectPolicyRec {
60
+ name: string;
61
+ root: string;
62
+ remote?: string;
63
+ share: ProjectShare;
64
+ /**
65
+ * A folder project's share covers its subfolders too (`p2p project share --subfolders`). Without
66
+ * it (every policy from before it), the policy is for that folder alone.
67
+ */
68
+ covers?: true;
69
+ at: number;
70
+ }
71
+ export interface ProjectsDoc {
72
+ v: 1;
73
+ projects: Record<string, ProjectPolicyRec>;
74
+ /** When this device showed the one-time notice that sessions no longer follow the default circle. */
75
+ noticeAt?: number;
76
+ }
77
+ export interface SessionBinding {
78
+ projects: Record<string, BoundProject>;
79
+ /** Past a cap, or a path its front end couldn't resolve: private (overWhy says which; absent in bindings from before it). */
80
+ over?: true;
81
+ overWhy?: OverWhy[];
82
+ /**
83
+ * What other sessions of this user that sent to this one could reach (own-device messages carry
84
+ * their sender's ceiling): intersected in, sticky, so a private session can't launder through a
85
+ * shared one of yours.
86
+ */
87
+ constraints?: ProjectShare[];
88
+ /** First used by an agent (agentContext) with no front end vouching for it: private until registered. */
89
+ unregistered?: true;
90
+ /** A front end holding the person token (personTokenOk) has used it. */
91
+ registered?: true;
92
+ /** When this binding began (ms): a session id bound anew (its old binding expired) starts again here (history.ts). */
93
+ since?: number;
94
+ at: number;
95
+ }
96
+ /** At most this many constraints a session keeps; past it, private. */
97
+ export declare const MAX_SESSION_CONSTRAINTS = 16;
98
+ export type SessionProjectsDoc = Record<string, SessionBinding>;
99
+ export interface BoundProject {
100
+ name: string;
101
+ /** Its folder (git: the working tree it was first seen in), for `p2p session show`. */
102
+ root?: string;
103
+ repoPrivate?: true;
104
+ /**
105
+ * Folders below `root` that a shared folder covered (dir projects only, at most MAX_UNDER): a
106
+ * policy given to one of them later still narrows this session. `underOver`: more than that,
107
+ * so any policy below `root` does.
108
+ */
109
+ under?: string[];
110
+ underOver?: true;
111
+ }
112
+ /** At most this many covered subfolders a bound folder project remembers; past it, every policy below it counts. */
113
+ export declare const MAX_UNDER = 64;
114
+ /** What a session may reach. `none`: the person's own session, or one not bound yet. */
115
+ export type Ceiling = {
116
+ kind: "none";
117
+ } | {
118
+ kind: "private";
119
+ why: string;
120
+ causes: PrivateCause[];
121
+ blocking?: string[];
122
+ } | {
123
+ kind: "shared";
124
+ circles: string[];
125
+ people: string[];
126
+ };
127
+ /**
128
+ * Why a session is private: an over reason (OverWhy), `unregistered` (an agent named it, no front
129
+ * end registered it), `repo-private` (`.p2p-private`), `private` (a project made private),
130
+ * `unshared` (a project never shared), `sent-private` (a private session of yours sent it a
131
+ * message), `disjoint` (its projects share nobody in common, or nobody you can reach).
132
+ */
133
+ export type PrivateCause = OverWhy | "legacy-over" | "unregistered" | "repo-private" | "private" | "unshared" | "sent-private" | "disjoint";
134
+ /**
135
+ * Whether `p` is a device or pseudo file (`/dev/null`, `/dev/tty`, `/proc/self/status`), never a
136
+ * project: it exists, isn't a folder, and its real path stays under /dev (and isn't a regular
137
+ * file there, like one in /dev/shm), /proc or /sys. A path through /proc to a real file
138
+ * (`/proc/self/cwd/x`, `/proc/<pid>/root/…`) resolves out of it and binds as usual; one that
139
+ * doesn't exist binds its nearest existing parent as every path does.
140
+ */
141
+ export declare function pseudoPath(p: string): boolean;
142
+ /**
143
+ * Whether a path component holds a brace expansion with a choice: a `{`, then `,` or `..` with no
144
+ * brace between, then `}` (`{.git,x}`, `{a..z}`). One pass, so it stays linear on any input.
145
+ */
146
+ export declare function braceChoice(c: string): boolean;
147
+ /** A folder project's id: its real path, hashed. */
148
+ export declare function dirProjectId(root: string): string;
149
+ /**
150
+ * A remote URL as one canonical string: scheme, credentials, port-less ssh form, trailing `.git`
151
+ * and slashes dropped, host lower-cased. `https://u:t@GitHub.com/a/b.git` and `git@github.com:a/b`
152
+ * are both `github.com/a/b`. A local path stays a path.
153
+ */
154
+ export declare function normalizeRemote(url: string): string | undefined;
155
+ /**
156
+ * The project `dir` belongs to, read from the files alone (git is never run: no hook, fsmonitor
157
+ * or config of the repository's can execute). A `.git` directory or `gitdir:` file up the tree
158
+ * marks a working tree; its common dir (`commondir` for a linked worktree) identifies the clone.
159
+ * A bare repository (isBareRepo) is a git project too, and a `.git` that can't be read as one is
160
+ * a folder project of its own.
161
+ *
162
+ * Outside git, a folder project. With `doc` (the policies), the nearest folder at or above `dir`
163
+ * that has a policy of its own is the project when that is `dir`'s own folder, or when its share
164
+ * covers subfolders (`covers`, given with `p2p project share --subfolders`; a policy without it
165
+ * is for that folder alone, as before). The walk stops at the first folder with a policy (the
166
+ * nearest one wins, so a private subfolder stays private; one that doesn't cover leaves `dir`'s
167
+ * own folder as the project), and it never crosses:
168
+ * - a git repository (found first: a nested repository is always its own project);
169
+ * - a `.p2p-private` (at or above `dir`: the folder project is private, whatever covers it);
170
+ * - a folder whose `.git` or `.p2p-private` the path itself names (namedStop: a command that may
171
+ * have just removed it);
172
+ * - the nearest existing folder, when `dir` itself isn't there (deleted or moved since the
173
+ * session named it, or not made yet): that folder is the project unless it has a policy, so a
174
+ * repository removed after a session read it is never covered from above.
175
+ * Without `doc` (sharing, `project show`): the folder itself.
176
+ */
177
+ export declare function projectOf(dir: string, doc?: ProjectsDoc): ProjectRef;
178
+ export declare function projectsDoc(app: App): Promise<ProjectsDoc>;
179
+ /** A project's share as stored, or `private` (no policy: private by default). */
180
+ export declare function shareOf(doc: ProjectsDoc, id: string): ProjectShare;
181
+ export interface ProjectView {
182
+ id: string;
183
+ name: string;
184
+ kind: "git" | "dir";
185
+ root: string;
186
+ remote?: string;
187
+ /** Who it is shared with (`private`: only your own devices). */
188
+ policy: "private" | "shared";
189
+ circles: {
190
+ cid: string;
191
+ name?: string;
192
+ open?: true;
193
+ joined: boolean;
194
+ }[];
195
+ people: {
196
+ userId: string;
197
+ address: string;
198
+ }[];
199
+ /** Why it is private although a policy shares it, or `unmapped` when none does. */
200
+ why?: string;
201
+ repoPrivate?: true;
202
+ /** A folder whose share covers its subfolders (`p2p project share --subfolders`). */
203
+ covers?: true;
204
+ /** Which Ix graph its work may reach (graphTarget): `local` (only this machine's) today. */
205
+ graph: GraphTarget;
206
+ }
207
+ export declare function projectView(app: App, ref: Pick<ProjectRef, "id" | "name" | "kind" | "root" | "remote" | "repoPrivate">, doc?: ProjectsDoc): Promise<ProjectView>;
208
+ /**
209
+ * Why `root` may not cover its subfolders (a share for it alone is still allowed), or undefined:
210
+ * the file system's root, a home folder or a folder above one (`$HOME`, `/Users`, `/home/<u>`),
211
+ * the temporary folders (`/tmp`, `/private/tmp`, `/var/folders/…`, os.tmpdir() and above it), and
212
+ * the system's top folders. Everything below them would be one project.
213
+ */
214
+ export declare function broadRoot(root: string, env?: Record<string, string | undefined>): string | undefined;
215
+ /** At most this deep and this many entries `nestedBoundaries` looks through below a covering share. */
216
+ export declare const NESTED_SCAN_DEPTH = 4;
217
+ export declare const NESTED_SCAN_ENTRIES = 2000;
218
+ /**
219
+ * The nested git repositories (a `.git`, or a bare repository) and `.p2p-private` folders below
220
+ * `root`, for the warning a covering share prints: each stays its own project, but only while its
221
+ * marker is there. Bounded (NESTED_SCAN_DEPTH, NESTED_SCAN_ENTRIES: `capped` past it); symlinks
222
+ * are never followed.
223
+ */
224
+ export declare function nestedBoundaries(root: string): {
225
+ repos: string[];
226
+ private: string[];
227
+ capped: boolean;
228
+ };
229
+ /**
230
+ * `p2p project share`: share the project at `dir` with circles you joined and friends. Replaces the
231
+ * project's shares with exactly these (`add` keeps the ones it has). Only ever the person's
232
+ * command: no session or file can run it for them (the mod and the Codex bridge refuse it from a
233
+ * model).
234
+ */
235
+ export declare function shareProject(app: App, dir: string, targets: {
236
+ circles?: string[];
237
+ people?: string[];
238
+ add?: boolean;
239
+ subfolders?: boolean;
240
+ }): Promise<{
241
+ project: ProjectView;
242
+ warnings: string[];
243
+ }>;
244
+ /** `p2p project private`: only your own devices see the project's sessions (the default). */
245
+ export declare function makeProjectPrivate(app: App, dir: string): Promise<ProjectView>;
246
+ /** `p2p project ls`: every project with a policy on this device. */
247
+ export declare function listProjects(app: App): Promise<ProjectView[]>;
248
+ /** `p2p project show`: the project at `dir` (a shared folder above it covers it), its policy and why. */
249
+ export declare function showProject(app: App, dir: string): Promise<ProjectView>;
250
+ /**
251
+ * Binds a session to the projects of `dirs` (sticky: a session's projects only ever grow until it
252
+ * ends), plus a constraint an own-device message carried. The person's own session is never
253
+ * bound; another caller naming it is refused. A session an agent names (agentContext) that no
254
+ * front end of this user has registered (personTokenOk) starts private.
255
+ */
256
+ export declare function bindSession(app: App, sid: string, dirs: readonly string[], o?: {
257
+ person?: boolean;
258
+ over?: boolean | readonly OverWhy[];
259
+ constraint?: ProjectShare;
260
+ inbound?: boolean;
261
+ }): Promise<SessionBinding | undefined>;
262
+ /**
263
+ * The variables Claude Code and Codex set in the commands their agents run (an allow-list, from
264
+ * their documentation and source: docs/security/threat-model.md "Project boundaries"). Variables a
265
+ * person sets in their own shell (CODEX_HOME, CODEX_API_KEY, CODEX_PROFILE) never count.
266
+ */
267
+ export declare const AGENT_ENV_VARS: readonly string[];
268
+ /** Whether the environment says this runs inside an agent's tool call. */
269
+ export declare function agentEnv(env: Record<string, string | undefined> | undefined): boolean;
270
+ /** Whether this call runs on an agent's behalf: its environment, or a Claude Code or Codex ancestor (ancestry.ts). */
271
+ export declare function agentContext(env: Record<string, string | undefined> | undefined): boolean;
272
+ export { isAgentProcess };
273
+ /** `<home>/cli/person.key`: a random secret the person's front ends (the Claude mod, the Codex bridge) pass back as P2P_PERSON_TOKEN. */
274
+ export declare function personTokenFile(home: string): string;
275
+ /** The person token, made once (exclusively, 0600, in the CLI's own folder, which the mod's guards keep from the model). */
276
+ export declare function personToken(home: string): string;
277
+ /** Whether P2P_PERSON_TOKEN is this home's person token (read only: a missing file is no match). */
278
+ export declare function personTokenOk(env: Record<string, string | undefined> | undefined, home: string | undefined): boolean;
279
+ /**
280
+ * Checks the person token once, at the start of a command, and takes it out of the environment
281
+ * (this object and the process's), so no child (git, ix, an extension's tool) ever inherits it.
282
+ */
283
+ export declare function takePersonToken(env: Record<string, string | undefined>, home: string | undefined): boolean;
284
+ /** The person's confirmation on their own terminal (tty-confirm.ts), or a test's stand-in. */
285
+ export type ConfirmTty = (question: string) => Promise<boolean>;
286
+ /**
287
+ * Lets a command that widens who reaches this user (sharing a project, a session, a default
288
+ * circle, invites, joins, trust, friends) run only for the person: their front end's token; or,
289
+ * outside any agent's session, their "yes" typed on the controlling terminal (never stdin, never a
290
+ * flag: a process detached from every terminal can't give it). Reads are never asked, except for
291
+ * the person's own messages (history.ts), which pass their own `why`.
292
+ */
293
+ export declare function assertPersonForWidening(app: Pick<App, "env"> & {
294
+ front?: boolean;
295
+ }, what: string, confirm: ConfirmTty, why?: string): Promise<void>;
296
+ /**
297
+ * For an act on a session that binds nothing (a delivery receipt): the session's front end (its
298
+ * token); or, outside any agent's session, a caller acting for a session no front end registered.
299
+ * An agent's own shell never may, as for statuses and sends (bindSession).
300
+ */
301
+ export declare function assertSpeaksFor(app: App, sid: string): Promise<void>;
302
+ /** 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). */
303
+ export declare function personHere(app: Pick<App, "env"> & {
304
+ front?: boolean;
305
+ }): boolean;
306
+ export declare function sessionBinding(app: App, sid: string): Promise<SessionBinding | undefined>;
307
+ /** One reason a session is private, as said to the person (and to a model that reads a refusal). */
308
+ export interface PrivateReason {
309
+ cause: PrivateCause;
310
+ why: string;
311
+ /** The project it is about, when it is one project's policy. */
312
+ project?: string;
313
+ }
314
+ /** Why a binding is private, every cause (no network: `disjoint` needs the store, see sessionCeiling). */
315
+ export declare function privateReasons(doc: ProjectsDoc, b: SessionBinding): PrivateReason[];
316
+ /**
317
+ * What the person can do about a private session, for an error a model may read: a share only
318
+ * when a share can lift it, never the "share each project" hint for a cause that lasts until the
319
+ * session ends (a cap, an unresolved path, a dropped front end, `.p2p-private`, a private
320
+ * session's message).
321
+ */
322
+ export declare function privateRemedy(causes: readonly PrivateCause[], names: string[]): string;
323
+ /** Whether a ceiling's privacy can only end with the session (privateRemedy says to start a new one). */
324
+ export declare function stickyPrivate(c: Ceiling): boolean;
325
+ /**
326
+ * The most a session may reach: the intersection of every bound project's policy. Unmapped,
327
+ * private and repository-private projects make it private, and so does an empty intersection.
328
+ */
329
+ export declare function sessionCeiling(app: App, sid: string, binding?: SessionBinding | null): Promise<Ceiling>;
330
+ /** Everyone a ceiling lets in (besides this user): members of its circles who stand in them, and its people. */
331
+ export declare function ceilingAudience(app: App, c: Ceiling): Promise<Set<string> | undefined>;
332
+ /** How to tell the person to share, for an error a model may read: the person's command, never a flag for the caller. */
333
+ export declare function shareHint(names: string[]): string;
334
+ /**
335
+ * The exfiltration barrier: may session `sid` send to `userId`? Your own devices always; the
336
+ * person's own session always; anyone else only within the session's project ceiling.
337
+ */
338
+ export declare function assertMayReach(app: App, sid: string, userId: string, o?: {
339
+ person?: boolean;
340
+ address?: string;
341
+ }): Promise<void>;
342
+ /** Friends of this user (live friendships), for the roster's named parts. */
343
+ export declare function friendIds(app: App): Promise<Set<string>>;
344
+ /** What `p2p status`, `ls` and the mod show about a session's projects. */
345
+ export interface SessionProjectView {
346
+ projects: {
347
+ id: string;
348
+ name: string;
349
+ repoPrivate?: true;
350
+ }[];
351
+ /** `private`: only your own devices see it; `shared`: the circles and people below (all its projects share them). */
352
+ policy: "private" | "shared" | "none";
353
+ why?: string;
354
+ /** Why it is private, as codes (PrivateCause). */
355
+ causes?: PrivateCause[];
356
+ circles?: string[];
357
+ people?: string[];
358
+ }
359
+ export declare function sessionProjectView(app: App, sid: string): Promise<SessionProjectView>;
360
+ /** `p2p session show`: one session's bound projects, each one's policy, and every reason it is private. */
361
+ export interface SessionShow {
362
+ sid: string;
363
+ policy: "private" | "shared" | "none";
364
+ /** Every reason it is private (empty when it isn't). */
365
+ reasons: PrivateReason[];
366
+ /** What the person can do about it (privateRemedy). */
367
+ remedy?: string;
368
+ /** Who it reaches, when shared: circle ids and userIds. */
369
+ circles?: string[];
370
+ people?: string[];
371
+ projects: (ProjectView & {
372
+ under?: string[];
373
+ underOver?: true;
374
+ })[];
375
+ /** Bounds own-session messages carried in (projects.v1). */
376
+ constraints: number;
377
+ }
378
+ /**
379
+ * `p2p session show <sid>`: read only, and the person's: their front end (the person token) or
380
+ * their own terminal outside any agent's session. An agent's shell is refused, so no session reads
381
+ * another's bindings (or its own: the model has the not_shared reason already).
382
+ */
383
+ export declare function showSession(app: App, sid: string): Promise<SessionShow>;
384
+ /**
385
+ * The one-time notice for a user who relied on the default circle: shown once per device, the
386
+ * first time a session of theirs is private only because its project was never shared.
387
+ */
388
+ export declare function defaultCircleNotice(app: App, sid: string): Promise<string | undefined>;
389
+ /** The text of the one-time notice starts so (the mod and the Codex bridge match it). */
390
+ export declare const PROJECT_NOTICE_PREFIX = "project boundaries:";
391
+ /**
392
+ * Where Ix calls made for a project (or a session) may go. `local`: this machine's own Ix backend,
393
+ * the only target today. `shared`: the shared graph of exactly one circle the project is shared
394
+ * with (Ix-memory, through Ix Pro), once one exists: a later PR adds the registry of shared
395
+ * graphs, and until then nothing resolves to it.
396
+ */
397
+ export type GraphTarget = {
398
+ kind: "local";
399
+ endpoint: string;
400
+ why: string;
401
+ } | {
402
+ kind: "shared";
403
+ circle: string;
404
+ endpoint: string;
405
+ };
406
+ /** What `p2p doctor` and `p2p project show` print for a local target. */
407
+ export declare const GRAPH_LOCAL_ONLY = "local only";
408
+ /** Ix's own default backend (ix-cli config.ts DEFAULT_ENDPOINT): `ix docker` runs it on this machine. */
409
+ export declare const DEFAULT_IX_ENDPOINT = "http://localhost:8090";
410
+ /**
411
+ * Whether `url` is an Ix backend on this machine: http(s) to localhost, 127.0.0.0/8 or ::1, with no
412
+ * credentials, query or fragment. Anything else (a cloud URL, a LAN host, `localhost.example.com`,
413
+ * `http://127.0.0.1@evil.example`) is not.
414
+ */
415
+ export declare function isLoopbackEndpoint(url: unknown): url is string;
416
+ /** A loopback endpoint as one canonical string: `origin + pathname`, trailing slashes dropped. Undefined when it isn't one. */
417
+ export declare function normalizeLoopbackEndpoint(url: unknown): string | undefined;
418
+ /**
419
+ * The local Ix endpoint every `local` target names: `ixEndpoint` in config.json (the person's own
420
+ * file) when it is a loopback URL, else Ix's default. Never from the environment (an agent or a
421
+ * project config can set that), and never a non-loopback URL. On a shared machine another user can
422
+ * listen on a loopback port first (threat model, "Graph targets").
423
+ */
424
+ export declare function localGraphEndpoint(_env: Record<string, string | undefined>, file?: {
425
+ ixEndpoint?: unknown;
426
+ }): string;
427
+ /**
428
+ * The circles that have a shared graph, and its endpoint. None yet: the shared cloud graph (epic #41
429
+ * piece 3) comes in a later PR, which fills this from settled, person-made state. Nothing in the
430
+ * environment, config.json, a repository or a peer's message can add to it.
431
+ */
432
+ export declare const SHARED_GRAPHS: ReadonlyMap<string, string>;
433
+ /** One input to a graph target: a bound project's (or a constraint's) share, as the ceiling sees it. */
434
+ export interface GraphShareInput {
435
+ name: string;
436
+ share: ProjectShare;
437
+ repoPrivate?: true;
438
+ }
439
+ /**
440
+ * The graph target of a set of projects (pure: graphTarget gathers the inputs). Intersection, like
441
+ * the session ceiling: any private, repository-private or unmapped project makes it local, and so
442
+ * does an empty set. A shared target needs every input shared with the same circle, and exactly one
443
+ * such circle with a shared graph (an https endpoint); people-only shares, no common circle, or a
444
+ * choice of several circles all stay local.
445
+ */
446
+ export declare function graphTargetOf(inputs: readonly GraphShareInput[], o: {
447
+ local: string;
448
+ sharedGraphs?: ReadonlyMap<string, string>;
449
+ }): GraphTarget;
450
+ /** A shared graph's endpoint as `origin + pathname` (https, off this machine, no credentials, query or fragment), else undefined. */
451
+ export declare function normalizeSharedEndpoint(url: unknown): string | undefined;
452
+ /**
453
+ * The chokepoint for every Ix call Peer2Peer makes or lets an extension make (ext-ix takes its
454
+ * endpoint only from here, ExtContext.graphTarget): the graph a session, the folders it works in,
455
+ * or both may reach. A session bound to a private project, or one whose ceiling is private for any
456
+ * reason (an unregistered agent session, too many projects, a private session's message), is local.
457
+ * The folders' own projects are intersected in, so a session can't name a shared sibling to widen
458
+ * a private repository it works in. The process's own cwd and every path the call names (`paths`:
459
+ * its targets, `--path`, `--changed`, the child's cwd) are intersected in as well. A named session
460
+ * that isn't bound yet is local, and a `shared` result needs a session a front end registered (its
461
+ * person token). Read only: binds nothing.
462
+ */
463
+ export declare function graphTarget(app: App, o?: {
464
+ sid?: string;
465
+ dirs?: readonly string[];
466
+ paths?: readonly string[];
467
+ over?: boolean;
468
+ }, sharedGraphs?: ReadonlyMap<string, string>): Promise<GraphTarget>;
469
+ /** At most this many paths one Ix call may name for its graph target; past it, local. */
470
+ export declare const MAX_GRAPH_PATHS = 64;
471
+ /** One project's graph target (`p2p project show`, `p2p doctor`). */
472
+ export declare function projectGraphTarget(app: Pick<App, "env" | "file">, ref: Pick<ProjectRef, "id" | "name" | "repoPrivate">, doc: ProjectsDoc): GraphTarget;
473
+ /** How a target reads in one line: `local only (http://localhost:8090)`, or the circle's shared graph. */
474
+ export declare function describeGraphTarget(t: GraphTarget): string;
475
+ /**
476
+ * The Ix variables that could send an `ix` call somewhere other than its graph target, or carry a
477
+ * cloud credential: Ix Pro's PAT mode (IX_PAT, IX_ORG, its endpoint override), the cloud push and
478
+ * ingestion knobs, the OAuth secret, auto-map routing to the cloud. Every IX_* variable outside
479
+ * IX_KEEP is dropped as well; these are named so tests and docs can point at them.
480
+ */
481
+ export declare const IX_CLOUD_ENV: readonly string[];
482
+ /** IX_* variables an `ix` call keeps: which binary (read by ext-ix, not ix), where Ix keeps its local state, and the local backend's token (Ix sends it to a loopback endpoint only). */
483
+ export declare const IX_KEEP: readonly string[];
484
+ /**
485
+ * The environment an extension gets (ExtContext.env), with the target pinned: every IX_* variable
486
+ * outside IX_KEEP set to undefined (so a `{...process.env, ...ctx.env}` merge drops it too: an older
487
+ * ext-ix spreads it), IX_ENDPOINT set to the target's endpoint, and readers kept from starting a
488
+ * background `ix map` (Ix Pro routes a map to the cloud when an org session is active, whatever
489
+ * IX_ENDPOINT says). Defence in depth: ext-ix builds its own allowlisted env from the target.
490
+ */
491
+ export declare function graphPinnedEnv(env: Record<string, string | undefined>, target: GraphTarget, base?: Record<string, string | undefined>): Record<string, string | undefined>;