anon-pi 0.3.0 → 0.5.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.
package/dist/anon-pi.d.ts CHANGED
@@ -1,11 +1,36 @@
1
- /** The container path the workdir is mounted at (pi's cwd). */
2
- export declare const CONTAINER_WORKDIR = "/work";
1
+ /**
2
+ * The jail cwd root for the projects-root launch: the projects root is mounted
3
+ * here and a project `<name>` is `/projects/<name>` (pi keys a conversation by
4
+ * its launch cwd, so `/projects/<name>` is the conversation key). This is the
5
+ * machines + projects mount (distinct from `--mount`'s /work).
6
+ */
7
+ export declare const CONTAINER_PROJECTS_ROOT = "/projects";
8
+ /**
9
+ * The jail cwd root for a `--mount <parent>` launch: the HOST parent is mounted
10
+ * here (kept DISTINCT from /projects so the two roots never collide), and a
11
+ * project `<name>` is `/work/<name>`. See ADR-0001 (`--mount` keeps `/work`).
12
+ */
13
+ export declare const CONTAINER_MOUNT_ROOT = "/work";
14
+ /**
15
+ * The jail cwd root for a machine (its persistent home, bind-mounted at /root).
16
+ * A machine root has no named subfolders: only the root token `.` (a scratch pi
17
+ * / shell at `~`) is valid. Written as `~` so it reads as "the machine home".
18
+ */
19
+ export declare const CONTAINER_MACHINE_HOME = "~";
20
+ /**
21
+ * The REAL container path the machine home is bind-mounted at (the source is
22
+ * the host `machineHomeDir`). This is what a shell-at-`~` launch actually cwds
23
+ * into (`-w /root`), distinct from CONTAINER_MACHINE_HOME (`~`), which is the
24
+ * human-readable menu token. It is the parent of CONTAINER_AGENT_DIR
25
+ * (`/root/.pi/agent`); the seed-if-fresh promotes the image's `/root` defaults +
26
+ * pi staging into the mounted home here.
27
+ */
28
+ export declare const CONTAINER_HOME_ROOT = "/root";
3
29
  /**
4
30
  * The container path pi uses as its config+state home. anon-pi mounts a
5
31
  * PERSISTENT host dir here (Model B), so everything pi writes, sessions,
6
32
  * history, settings (your model choice), `pi install`ed extensions, downloaded
7
- * bin/fd, survives across launches. Statefulness is the default; --ephemeral
8
- * mounts a throwaway dir here instead.
33
+ * bin/fd, survives across launches. Statefulness is the default.
9
34
  */
10
35
  export declare const CONTAINER_AGENT_DIR = "/root/.pi/agent";
11
36
  /**
@@ -44,10 +69,14 @@ export interface AnonPiEnv {
44
69
  home: string;
45
70
  /** socks5h proxy URL. REQUIRED (no default: the proxy is what anonymizes). */
46
71
  proxy?: string;
47
- /** The anon-pi home dir. Default $XDG_CONFIG_HOME/anon-pi or ~/.config/anon-pi. */
72
+ /** The anon-pi home dir. Default ~/.anon-pi (NOT under ~/.config). */
48
73
  anonPiHome?: string;
49
- /** Override the canonical seed dir. Default <anonPiHome>/agent. */
50
- configSeed?: string;
74
+ /**
75
+ * Projects-root override from env (ANON_PI_PROJECTS). Sits above
76
+ * machine.json/config.json in the projects-root chain, below the later
77
+ * --mount CLI override. See resolveProjectsRoot.
78
+ */
79
+ projects?: string;
51
80
  /** The container image that has `pi` on PATH. REQUIRED. */
52
81
  image?: string;
53
82
  /** The RFC1918/link-local IP[:port] of the local model. REQUIRED. */
@@ -66,43 +95,585 @@ export interface AnonPiEnv {
66
95
  * + SearXNG), used to make the missing-image error mention the fuller build.
67
96
  */
68
97
  webveilDockerfilePath?: string;
69
- /** `import` source models.json override (ANON_PI_SOURCE_MODELS). */
70
- sourceModels?: string;
71
- /** The host pi agent dir override (PI_CODING_AGENT_DIR), used to find models.json. */
72
- piAgentDir?: string;
73
- /** When true, use a throwaway state home (no persistence). Default false. */
74
- ephemeral?: boolean;
75
98
  /** The seed version anon-pi stamps into a fresh home. Default SEED_VERSION. */
76
99
  seedVersion?: string;
77
100
  }
78
- /** The fully-resolved run plan cli.ts executes. */
79
- export interface RunPlan {
80
- /** Absolute workdir on the host (mounted at /work). */
81
- workdir: string;
101
+ /** A user-facing error whose message is meant to be printed verbatim (no stack). */
102
+ export declare class AnonPiError extends Error {
103
+ }
104
+ /**
105
+ * The verbatim guidance printed when no proxy is supplied. Kept as a single
106
+ * source so the fail-closed path (resolveProxy) emits byte-identical
107
+ * copy-pasteable guidance. The proxy is REQUIRED and never guessed: it is what
108
+ * anonymizes egress (fail-closed is the anonymity invariant).
109
+ */
110
+ export declare const PROXY_REQUIRED_MESSAGE: string;
111
+ /**
112
+ * Resolve the anon-pi home dir: the dedicated, browsable workspace folder
113
+ * (`~/.anon-pi/`, NOT under `~/.config`), holding config.json, machines/<M>/,
114
+ * and the default global projects root. Overridable via ANON_PI_HOME.
115
+ */
116
+ export declare function resolveAnonPiHome(env: AnonPiEnv): string;
117
+ /** A machine's directory: <home>/machines/<name> (holds machine.json + home/). */
118
+ export declare function machineDir(env: AnonPiEnv, name: string): string;
119
+ /** A machine's persistent HOST home: <home>/machines/<name>/home (bind-mounted at /root). */
120
+ export declare function machineHomeDir(env: AnonPiEnv, name: string): string;
121
+ /** A machine's machine.json path: <home>/machines/<name>/machine.json. */
122
+ export declare function machineJsonPath(env: AnonPiEnv, name: string): string;
123
+ /** The sessions dirname pi keeps its per-cwd conversation dirs under (in the agent dir). */
124
+ export declare const SESSIONS_DIRNAME = "sessions";
125
+ /**
126
+ * A machine's HOST pi agent dir: the host side of the container's
127
+ * CONTAINER_AGENT_DIR (`/root/.pi/agent`, since the home is bind-mounted at
128
+ * /root). i.e. <machineHome>/.pi/agent. Where pi's config + sessions live.
129
+ */
130
+ export declare function machineAgentDir(env: AnonPiEnv, name: string): string;
131
+ /**
132
+ * A machine's HOST pi sessions dir: <machineAgentDir>/sessions. Each per-cwd
133
+ * conversation is a slug-named subdir here (projectSessionSlug for a project).
134
+ */
135
+ export declare function machineSessionsDir(env: AnonPiEnv, name: string): string;
136
+ /**
137
+ * The HOST session dir a given project's conversation occupies in a given
138
+ * machine's home: <machineSessionsDir>/<projectSessionSlug>. Because the slug is
139
+ * MACHINE-INVARIANT (pi keys by the `/projects/<name>` cwd, identical on every
140
+ * machine), the SAME shared project has this dir in each machine that used it.
141
+ * Validates the project name (rejecting traversal) via projectSessionSlug.
142
+ */
143
+ export declare function machineProjectSessionDir(env: AnonPiEnv, machine: string, project: string): string;
144
+ /** The built-in default global projects root: <home>/projects. */
145
+ export declare function builtinProjectsRoot(env: AnonPiEnv): string;
146
+ /** The affected-path plan for `--delete-home <machine>`. */
147
+ export interface DeleteHomePlan {
148
+ /** The machine whose home is dropped. */
149
+ machine: string;
82
150
  /**
83
- * The PERSISTENT per-workdir state dir on the host, mounted at the container's
84
- * ~/.pi/agent. Everything pi writes here survives. For --ephemeral this is a
85
- * throwaway path cli.ts creates + discards.
151
+ * The single dir removed: the machine's persistent HOST home
152
+ * (machineHomeDir). The machine dir's machine.json (its image pin) is KEPT, so
153
+ * the machine can be relaunched to seed a FRESH home.
86
154
  */
87
- stateDir: string;
88
- /** The canonical host models.json (from `import`) mounted read-only for the seed, or '' if absent. */
89
- configSeed: string;
90
- /** True when this workdir has no state yet (fresh home; the seed will run). */
155
+ home: string;
156
+ }
157
+ /**
158
+ * PURE: resolve the affected path for `--delete-home <machine>`: the machine's
159
+ * HOME dir only (config + convos + shell env), NOT the whole machine dir, so the
160
+ * image pin (machine.json) survives a re-seed. Validates the machine name
161
+ * (rejecting traversal) via machineHomeDir's join being under a validated name;
162
+ * we validate explicitly here so the plan itself is a safe single segment.
163
+ */
164
+ export declare function resolveDeleteHome(env: AnonPiEnv, machine: string): DeleteHomePlan;
165
+ /** The affected-path plan for `--delete-project <project>`. */
166
+ export interface DeleteProjectPlan {
167
+ /** The project whose files + per-machine sessions are dropped. */
168
+ project: string;
169
+ /** The project's files: <projectsRoot>/<project> (the host folder). */
170
+ folder: string;
171
+ /**
172
+ * The per-machine session dirs for this project's (machine-invariant) slug,
173
+ * ONE per supplied machine, in the SUPPLIED order. The homes themselves are
174
+ * kept; only these slug dirs are dropped. The CLI supplies the machine names
175
+ * (readdir of machines/) and skips any that do not exist on disk.
176
+ */
177
+ sessions: string[];
178
+ }
179
+ /**
180
+ * PURE: resolve the affected paths for `--delete-project <project>`: the
181
+ * project's files under the RESOLVED projects root, plus that project's session
182
+ * dir in each SUPPLIED machine home (the machine-invariant slug). Validates the
183
+ * project name (rejecting traversal) so both the folder join and every session
184
+ * join stay inside their roots. The homes are NOT targeted (only the per-project
185
+ * slug dir inside each), matching the prd behaviour table.
186
+ */
187
+ export declare function resolveDeleteProject(args: {
188
+ env: AnonPiEnv;
189
+ project: string;
190
+ /** The resolved projects root (host dir mounted at /projects). */
191
+ projectsRoot: string;
192
+ /** The machine names whose homes may hold this project's session dir. */
193
+ machines: readonly string[];
194
+ }): DeleteProjectPlan;
195
+ /**
196
+ * The project token meaning "the root itself": cwd `/projects` (projects root),
197
+ * `/work` (`--mount`), or `~` (a machine home). It is NOT a valid machine or
198
+ * project name (validateName rejects it) so a folder can never shadow it.
199
+ */
200
+ export declare const ROOT_TOKEN = ".";
201
+ /**
202
+ * Reserved names that a machine/project may NOT take (case-sensitive). Kept
203
+ * DELIBERATELY minimal: only the two structural path tokens. `.` is the root
204
+ * token (see ROOT_TOKEN); `..` is parent-traversal. Both are also rejected by
205
+ * the leading-dot / `..` structural checks below, but are listed here so the
206
+ * reserved-name concept is explicit and extendable. `--mount`'s `/work` is a
207
+ * CONTAINER path, not a name in this namespace, so it needs no reservation.
208
+ */
209
+ export declare const RESERVED_NAMES: readonly string[];
210
+ /** What a name names, for a clear validation error. */
211
+ export type NameKind = 'machine' | 'project';
212
+ /**
213
+ * PURE: validate a machine or project name as a safe single path segment, and
214
+ * return it unchanged on success. Rejects (with AnonPiError):
215
+ * - empty
216
+ * - a path separator `/` or `\`, or a colon `:`
217
+ * - the traversal token `..` (and any leading dot, incl. `.`)
218
+ * - any whitespace
219
+ * - a reserved name (RESERVED_NAMES)
220
+ * A valid name is thus a single folder segment safe to join under the projects
221
+ * root or the machines dir with no traversal or drive/scheme surprises.
222
+ */
223
+ export declare function validateName(name: string, kind: NameKind): string;
224
+ /**
225
+ * PURE: map a validated project `<name>` to its host folder under the resolved
226
+ * projects root (the parent from resolveProjectsRoot / a `--mount` parent).
227
+ * Validates the name (rejecting traversal) so the join stays inside the root.
228
+ */
229
+ export declare function projectHostDir(projectsRoot: string, name: string): string;
230
+ /**
231
+ * PURE: the jail cwd for a validated project `<name>`: `/projects/<name>`. This
232
+ * is pi's conversation key (pi keys a session by its launch cwd). Validates the
233
+ * name. For the `--mount` root use resolveCwd('mount', name) (=> /work/<name>).
234
+ */
235
+ export declare function projectContainerCwd(name: string): string;
236
+ /** Which mounted root a launch cwds into (see the CONTAINER_* root constants). */
237
+ export type RootKind = 'projects' | 'mount' | 'machine';
238
+ /** True iff `token` is exactly the root token `.` ("the root itself"). */
239
+ export declare function isRootToken(token: string | undefined): boolean;
240
+ /** PURE: the jail cwd of a root itself: /projects, /work (mount), or ~ (machine). */
241
+ export declare function rootCwd(kind: RootKind): string;
242
+ /**
243
+ * PURE: resolve a launch's jail cwd UNIFORMLY from a `token` and its root kind.
244
+ * The root token `.` means "the root itself" (rootCwd) in every context; any
245
+ * other token is a project name resolved to `<root>/<name>` (validated). A
246
+ * machine root has no named subfolders (projects live at /projects or /work,
247
+ * never under the machine home), so a non-`.` token for a machine is rejected.
248
+ * This is the one seam so `anon-pi --mount <p> .` and a menu "here" entry agree.
249
+ */
250
+ export declare function resolveCwd(kind: RootKind, token: string): string;
251
+ /** Parsed shape of config.json. All fields optional (a hand-edited file may omit any). */
252
+ export interface AnonPiConfig {
253
+ /** socks5h proxy URL. */
254
+ proxy?: string;
255
+ /** The local-model direct target (host[:port]). */
256
+ llm?: string;
257
+ /** The machine bare `anon-pi` launches by default. */
258
+ defaultMachine?: string;
259
+ /** Override the projects root (host dir mounted at /projects). */
260
+ projects?: string;
261
+ }
262
+ /** Parsed shape of a per-machine machine.json. All fields optional. */
263
+ export interface MachineConfig {
264
+ /** The container image with `pi` on PATH for this machine. */
265
+ image?: string;
266
+ /** Per-machine projects-root override (above config, below env/--mount). */
267
+ projects?: string;
268
+ }
269
+ /**
270
+ * PURE: parse an already-JSON-decoded config.json value into an AnonPiConfig,
271
+ * keeping only the known string fields (defensive against a hand-edited file).
272
+ * Tolerates undefined/null/partial input (an absent config is `{}`).
273
+ */
274
+ export declare function parseConfigJson(raw: unknown): AnonPiConfig;
275
+ /**
276
+ * PURE: parse an already-JSON-decoded machine.json value into a MachineConfig.
277
+ * Tolerates undefined/null/partial input (an absent machine.json is `{}`).
278
+ */
279
+ export declare function parseMachineJson(raw: unknown): MachineConfig;
280
+ /**
281
+ * PURE: resolve the projects root (the host dir mounted at /projects) with the
282
+ * decided precedence, highest first:
283
+ * --mount (CLI) > env ANON_PI_PROJECTS > machine.json.projects >
284
+ * config.json.projects > built-in <home>/projects
285
+ * This task delivers the config/env/machine layers; `mountParent` is the
286
+ * documented top slot the later --mount CLI task threads in (pass the resolved
287
+ * host parent). A relative override is resolved to an absolute path.
288
+ */
289
+ export declare function resolveProjectsRoot(args: {
290
+ env: AnonPiEnv;
291
+ config?: AnonPiConfig;
292
+ machine?: MachineConfig;
293
+ /** The later --mount CLI override (a HOST parent path); top of the chain. */
294
+ mountParent?: string;
295
+ }): string;
296
+ /**
297
+ * PURE: resolve the proxy with env-over-config precedence, REQUIRED /
298
+ * fail-closed. Throws AnonPiError with the verbatim PROXY_REQUIRED_MESSAGE when
299
+ * neither env nor config supplies a non-empty proxy (never a guessed default:
300
+ * fail-closed is the anonymity invariant).
301
+ */
302
+ export declare function resolveProxy(args: {
303
+ config?: AnonPiConfig;
304
+ env: {
305
+ proxy?: string;
306
+ };
307
+ }): string;
308
+ /**
309
+ * PURE: resolve the local-model direct target with env-over-config precedence.
310
+ * Unlike the proxy this is NOT fail-closed here (a launch with no local model
311
+ * is a later decision); returns undefined when neither supplies one.
312
+ */
313
+ export declare function resolveLlm(args: {
314
+ config?: AnonPiConfig;
315
+ env: {
316
+ llmDirect?: string;
317
+ };
318
+ }): string | undefined;
319
+ /** A resolved machine: its host home (bind-mounted at /root) + its image. */
320
+ export interface Machine {
321
+ /** The machine's name (already validated by validateName elsewhere). */
322
+ name: string;
323
+ /** The persistent HOST home dir (machineHomeDir), bind-mounted at /root. */
324
+ home: string;
325
+ /** The container image with `pi` on PATH for this machine. */
326
+ image: string;
327
+ }
328
+ /**
329
+ * What a launch runs. `menu` is the BARE launch: no target is chosen yet, so no
330
+ * netcage argv is composed (the host-side TUI picks a project/shell, THEN a
331
+ * fresh intent is resolved into a launch plan). `pi` runs pi (optionally with
332
+ * forwarded args); `shell` runs bash (the project-hopper, since pi cannot cd).
333
+ */
334
+ export type LaunchMode = 'menu' | 'pi' | 'shell';
335
+ /**
336
+ * A parsed launch intent, injected so the resolver stays pure. The proxy + the
337
+ * direct-hole llm are threaded in RESOLVED (via resolveProxy/resolveLlm); the
338
+ * resolver re-asserts them non-empty so a plan can NEVER be produced without the
339
+ * forced-egress flags (fail-closed is the anonymity invariant).
340
+ */
341
+ export interface LaunchIntent {
342
+ /** The machine to launch on (home + image). */
343
+ machine: Machine;
344
+ /** menu (bare) | pi | shell. */
345
+ mode: LaunchMode;
346
+ /**
347
+ * The resolved HOST projects root, bind-mounted at /projects. One of the two
348
+ * invariant mounts, present on every launch regardless of --mount.
349
+ */
350
+ projectsRoot: string;
351
+ /**
352
+ * The project token: a validated project name, the root token `.`, or
353
+ * undefined (shell-at-home / menu). Resolves the cwd via resolveCwd.
354
+ */
355
+ project?: string;
356
+ /**
357
+ * `--mount <parent>`: a resolved HOST parent path. When set it adds EXACTLY
358
+ * one mount (<parent>:/work) and re-roots the cwd there (/work[/<project>]);
359
+ * it changes nothing else (the two invariant mounts stay). Sidesteps podman
360
+ * mount immutability (we never remount a running box).
361
+ */
362
+ mountParent?: string;
363
+ /** Extra args forwarded to `pi` (headless/one-shot). Ignored for shell. */
364
+ piArgs?: string[];
365
+ /**
366
+ * `--keep`: omit `--rm` so the container is left KEPT (its filesystem
367
+ * survives the apt-install/re-enter flow). Default (false) => `--rm`
368
+ * (throwaway); the machine home persists regardless (it is a host mount).
369
+ */
370
+ keep?: boolean;
371
+ /** The resolved socks5h proxy (REQUIRED; the resolver fails closed without it). */
372
+ proxy: string;
373
+ /** The resolved local-model direct target (REQUIRED: the one --allow-direct hole). */
374
+ llmDirect: string;
375
+ /**
376
+ * The host models.json to mount read-only for the first-launch seed, keyed to
377
+ * THIS machine (e.g. <machine-dir>/models.json). Omitted => no seed mount (pi
378
+ * starts with no models; you add them in-session).
379
+ */
380
+ modelsSeed?: string;
381
+ /** The seed version stamped into a fresh home's marker. Default SEED_VERSION. */
382
+ seedVersion?: string;
383
+ }
384
+ /**
385
+ * The resolved launch plan. A discriminated union so the BARE `menu` mode is a
386
+ * distinct, argv-less marker (the host-side TUI runs first) while every real
387
+ * launch carries a composed netcage argv. The forced-egress invariant is
388
+ * asserted on the `launch` variant's netcageArgs by construction.
389
+ */
390
+ export type LaunchPlan = {
391
+ /** Bare launch: run the host-side menu, then re-resolve into a launch. */
392
+ kind: 'menu';
393
+ machine: Machine;
394
+ } | {
395
+ kind: 'launch';
396
+ machine: Machine;
397
+ /** The jail cwd (`-w`): /projects[/<p>], /work[/<p>] (--mount), or /root (shell ~). */
398
+ cwd: string;
399
+ /** True when the machine home is fresh (informational; the seed is marker-guarded). */
91
400
  fresh: boolean;
92
401
  /** The argv passed to `netcage` (after the `netcage` program name). */
93
402
  netcageArgs: string[];
403
+ };
404
+ /** The machine bare `anon-pi` launches when no `-m` and no config default. */
405
+ export declare const DEFAULT_MACHINE = "default";
406
+ /**
407
+ * A parsed grammar-A launch. `mode` is `menu` when no project/shell target was
408
+ * chosen (bare `anon-pi`, or `-m <machine>` / `--mount <parent>` with no
409
+ * project): the CLI runs the host-side menu. `pi`/`shell` carry the chosen
410
+ * target. `project` is a validated project name, the `.` root token, or
411
+ * undefined (menu / shell-at-home). `mountParent` is the `--mount` HOST parent
412
+ * (a path, NOT a name-namespaced token). `keep` is `--keep` (default false =>
413
+ * throwaway `--rm`). `piArgs` are the trailing tokens forwarded to pi (pi mode
414
+ * only; undefined otherwise).
415
+ */
416
+ export interface ParsedLaunch {
417
+ mode: LaunchMode;
418
+ machine: string;
419
+ /**
420
+ * True iff `-m`/`--machine` was given explicitly (so the CLI can let an
421
+ * explicit `-m default` win over `config.defaultMachine`, rather than treat
422
+ * the DEFAULT_MACHINE value as "unset").
423
+ */
424
+ machineExplicit: boolean;
425
+ project?: string;
426
+ mountParent?: string;
427
+ keep: boolean;
428
+ piArgs?: string[];
94
429
  }
95
- /** A user-facing error whose message is meant to be printed verbatim (no stack). */
96
- export declare class AnonPiError extends Error {
430
+ /**
431
+ * PURE: parse grammar A into a ParsedLaunch. Consumes the anon-pi flags
432
+ * (`-m <machine>`, `--shell`, `--mount <parent>`, `--keep`/`--rm`) LEFT of the
433
+ * project positional; the FIRST bare positional is the project (`.` allowed as
434
+ * the root token). In pi mode every token AFTER the project is forwarded to pi
435
+ * verbatim (so `anon-pi recon -p '...'` works) — anon-pi flags must come before
436
+ * the project. In shell/menu mode a stray extra positional is an error (bash has
437
+ * no forwarded-args grammar; the menu takes no project).
438
+ *
439
+ * Validates the project name and the `-m` machine name via validateName (the
440
+ * reserved-name guard); `--mount <parent>` is a HOST path in its own namespace,
441
+ * distinct from the project-name namespace (NAME vs `--mount` exclusivity), so
442
+ * it is NOT name-validated here. Throws AnonPiError for an unknown option, a
443
+ * missing `-m`/`--mount` argument, a contradictory `--keep --rm`, or a bad name.
444
+ */
445
+ export declare function parseLaunchArgs(args: readonly string[]): ParsedLaunch;
446
+ /**
447
+ * PURE: resolve a LaunchIntent into a LaunchPlan, composing the netcage argv for
448
+ * every mode. Never spawns, never touches the filesystem: `homeFresh` reports
449
+ * whether the machine home has been seeded (so `fresh` is known) and is the only
450
+ * capability injected.
451
+ *
452
+ * Invariants held on EVERY composed argv:
453
+ * - the two mounts <home>:/root and <projectsRoot>:/projects, always;
454
+ * - --mount adds EXACTLY <parent>:/work and re-roots cwd, nothing else;
455
+ * - --proxy <p> + exactly one --allow-direct <llm> (forced egress, fail-closed);
456
+ * - --rm by default, omitted only under --keep.
457
+ *
458
+ * Throws AnonPiError (a plan is NEVER produced) when the image, the machine
459
+ * home, the proxy, or the direct-hole llm is missing.
460
+ */
461
+ export declare function resolveRunPlan(intent: LaunchIntent, homeFresh: (machineHome: string) => boolean): LaunchPlan;
462
+ /**
463
+ * A kept `netcage.managed` container, as the CLI's netcage query surfaces it to
464
+ * the pure decision. Only the two fields the DECISION needs are typed:
465
+ * - `key`: the anon-pi launch-identity key (keptContainerKey) the CLI stamped
466
+ * onto the container at `run` time (a netcage label / container name) and
467
+ * reads back from the label; this is what a launch matches against.
468
+ * - `ref`: how to address the container for `netcage start` (its id or name).
469
+ * The CLI is free to carry more; the pure rule reads only these.
470
+ */
471
+ export interface KeptContainer {
472
+ /** The anon-pi launch-identity key stamped on the container (keptContainerKey). */
473
+ key: string;
474
+ /** The container ref (id or name) to pass to `netcage start`. */
475
+ ref: string;
476
+ }
477
+ /**
478
+ * The run-vs-start decision. `run` = `netcage run` a fresh container (WITHOUT
479
+ * `--rm` under `--keep`, so it is left kept; the run argv itself is
480
+ * resolveRunPlan's job). `start` = `netcage start <ref>` an existing kept
481
+ * container whose identity matches this launch.
482
+ */
483
+ export type RunVsStart = {
484
+ action: 'run';
485
+ } | {
486
+ action: 'start';
487
+ ref: string;
488
+ };
489
+ /**
490
+ * PURE: the launch-identity match key for a kept container, derived ENTIRELY
491
+ * from the (machine, projects-root, project) identity (ADR-0002). It is what
492
+ * decides whether an existing kept `netcage.managed` container IS the one a
493
+ * `--keep` launch should resume.
494
+ *
495
+ * The fields, and why each is load-bearing:
496
+ * - `machine.name`: a kept container mounts THIS machine's home at /root; a
497
+ * same-project container on another machine is a different environment.
498
+ * - `projectsRoot`: the host dir mounted at /projects; two launches with the
499
+ * same project name but different roots are different working trees.
500
+ * - `mountParent` (or '' when absent): `--mount` re-roots into a DIFFERENT
501
+ * host parent at /work, so a `--mount` launch is a distinct identity from
502
+ * the projects-root launch of the same name.
503
+ * - the resolved container `cwd`: this already encodes the project token
504
+ * (`/projects/<p>`, `/work/<p>`, `.` -> a root, or /root for a bare shell)
505
+ * AND which root it sits under, so it is pi's conversation key too. Using
506
+ * the cwd keeps the container identity aligned with the conversation the
507
+ * kept container hosts.
508
+ *
509
+ * DELIBERATELY EXCLUDED (not part of identity): `--keep`/`--rm` (the throwaway
510
+ * choice for THIS run), the proxy + the direct-hole llm (forced-egress inputs),
511
+ * forwarded pi args, and the seed. Two launches that differ only in those must
512
+ * resolve to the SAME kept container.
513
+ *
514
+ * The key is a single opaque string (a `\n`-joined, field-tagged record) so the
515
+ * CLI can stamp it verbatim onto a netcage label and match on string equality;
516
+ * its internal shape is not a contract (compare only keys this function makes).
517
+ */
518
+ export declare function keptContainerKey(intent: LaunchIntent): string;
519
+ /**
520
+ * PURE: decide run-vs-start for a launch given a SUPPLIED listing of kept
521
+ * `netcage.managed` containers (the CLI's netcage query result).
522
+ *
523
+ * - `--rm` (throwaway, `intent.keep !== true`): ALWAYS a fresh `run`. The
524
+ * listing is NOT consulted (a throwaway launch never resumes a kept box).
525
+ * - `--keep`: a kept container whose `key` equals this launch's
526
+ * keptContainerKey is present -> `start` it (by its `ref`); else -> `run`
527
+ * (resolveRunPlan leaves it kept because `--keep` omits `--rm`).
528
+ *
529
+ * Never spawns, never queries netcage: the listing is injected, so the whole
530
+ * decision is a pure function of (intent, listing).
531
+ */
532
+ export declare function resolveRunVsStart(intent: LaunchIntent, kept: readonly KeptContainer[]): RunVsStart;
533
+ /**
534
+ * PURE: the pi session-dir slug for a project, i.e. pathSlug of its jail cwd
535
+ * `/projects/<name>`. Because the cwd is the SAME on every machine (files are
536
+ * global, the projects root is mounted at /projects everywhere), this slug is
537
+ * MACHINE-INVARIANT: the same shared project is recognised in each machine's
538
+ * sessions dir. Validates the name (rejecting traversal) as projectContainerCwd
539
+ * does. e.g. `alpha` -> `--projects-alpha--`.
540
+ */
541
+ export declare function projectSessionSlug(name: string): string;
542
+ /**
543
+ * The pure choice-list the bare-launch menu renders. `projects` are the
544
+ * folder-safe project names (sorted, case-insensitive) offered as pi launches;
545
+ * `here` is the `.` root token (a scratch pi at the root itself); `canNew` /
546
+ * `canShell` gate the `+ new project…` and `shell` affordances. It carries NO
547
+ * usage annotation (that is deriveProjectUsage, keyed by project name), so a
548
+ * caller can render the list alone or joined with usage.
549
+ */
550
+ export interface MenuChoiceList {
551
+ /** The folder-safe project names, sorted case-insensitively for a stable menu. */
552
+ projects: string[];
553
+ /** The `.` "here" entry: a scratch pi at the root itself (ROOT_TOKEN). */
554
+ here: string;
555
+ /** Whether the `+ new project…` affordance is offered (always true today). */
556
+ canNew: boolean;
557
+ /** Whether the `shell` affordance is offered (always true today). */
558
+ canShell: boolean;
559
+ }
560
+ /**
561
+ * PURE: build the menu choice-list from a SUPPLIED projects-root listing (the
562
+ * CLI's real `readdir` of the projects root). Entries that are not folder-safe
563
+ * project names (dotfiles like `.git`, `..`, path-separator names, whitespace,
564
+ * reserved tokens) are DROPPED silently: they can never be a valid project
565
+ * launch (validateName would reject them), and the `.` root is the separate
566
+ * `here` entry, not a listed project. The surviving names are sorted
567
+ * case-insensitively so the menu order is stable regardless of dir-read order.
568
+ *
569
+ * `canNew` / `canShell` default TRUE (both affordances are always offered
570
+ * today); they are fields so a later policy can gate them without a signature
571
+ * change. An empty projects root still offers here / new / shell.
572
+ */
573
+ export declare function buildMenuChoiceList(args: {
574
+ projects: readonly string[];
575
+ canNew?: boolean;
576
+ canShell?: boolean;
577
+ }): MenuChoiceList;
578
+ /**
579
+ * A per-machine session-dir listing: for each machine name, the slugs present
580
+ * under machines/<M>/home/.pi/agent/sessions/. The CLI derives this by reading
581
+ * each machine home's sessions dir; the pure derivation takes it as input. Only
582
+ * the project session slugs (projectSessionSlug) are matched; any other slug
583
+ * (e.g. a `.`/`~`/`--mount` scratch session) is simply not a project so it does
584
+ * not appear in the usage record.
585
+ */
586
+ export type SessionDirListing = Record<string, readonly string[]>;
587
+ /** The usage record for ONE project: which machines used it + a current-new flag. */
588
+ export interface ProjectUsage {
589
+ /** The project name (as supplied; validated). */
590
+ project: string;
591
+ /**
592
+ * The machine names whose home contains this project's session dir, sorted
593
+ * (a stable, machine-invariant "used on" list derived from session presence).
594
+ */
595
+ machines: string[];
596
+ /**
597
+ * True when the CURRENT machine has NO session dir for this project yet (it is
598
+ * new for this machine, even if other machines have used the shared files).
599
+ */
600
+ currentMachineIsNew: boolean;
97
601
  }
98
- /** Resolve the anon-pi home dir (holds the seed). */
99
- export declare function resolveAnonPiHome(env: AnonPiEnv): string;
100
602
  /**
101
- * The CANONICAL host seed dir holding models.json (written by `anon-pi import`).
102
- * Mounted read-only so the first-launch seed can copy models.json into a fresh
103
- * persistent home. Workdir-independent (import does not need a workdir).
603
+ * PURE: derive the per-machine project-usage record from SUPPLIED session-dir
604
+ * presence (no marker file). For each supplied project, in the SUPPLIED order,
605
+ * it reports which machines' homes contain that project's (machine-invariant)
606
+ * session slug, and whether the CURRENT machine is new for it.
607
+ *
608
+ * The project ORDER is preserved (the caller orders the menu, e.g. via
609
+ * buildMenuChoiceList); only the per-project `machines` list is sorted, so the
610
+ * "used on" annotation is stable. Validates each project name (rejecting
611
+ * traversal) via projectSessionSlug.
104
612
  */
105
- export declare function resolveConfigSeed(env: AnonPiEnv): string;
613
+ export declare function deriveProjectUsage(args: {
614
+ projects: readonly string[];
615
+ currentMachine: string;
616
+ sessions: SessionDirListing;
617
+ }): ProjectUsage[];
618
+ /**
619
+ * What ONE selectable menu row launches, so the CLI can dispatch a chosen entry
620
+ * without re-deriving anything:
621
+ * - `project` -> pi in `/projects/<project>` (the `anon-pi <project>` launch);
622
+ * - `here` -> a scratch pi at the root itself (the `.` root token launch);
623
+ * - `new` -> prompt+validate a new project name, then launch it as pi;
624
+ * - `shell` -> the `--shell` jailed-bash launch.
625
+ */
626
+ export type MenuEntryKind = 'project' | 'here' | 'new' | 'shell';
627
+ /** One rendered, selectable menu row: what it launches + its human label. */
628
+ export interface MenuEntry {
629
+ /** Which launch this row dispatches to (project | here | new | shell). */
630
+ kind: MenuEntryKind;
631
+ /**
632
+ * The project token this row launches: a validated project name (`project`),
633
+ * the root token `.` (`here`), or undefined (`new` prompts for it, `shell`
634
+ * takes none). This is exactly the `project` field a launch dispatch feeds
635
+ * back into the grammar, so no re-parsing is needed.
636
+ */
637
+ project?: string;
638
+ /**
639
+ * The rendered row text the selector prints: the project name plus its
640
+ * used-on / new-here annotation (project rows), or the fixed affordance label
641
+ * (here / new / shell). The annotation is the ONLY place the usage record
642
+ * surfaces to the user, so the wording lives here (pure) not in the TUI.
643
+ */
644
+ label: string;
645
+ }
646
+ /** The fixed labels for the non-project affordances (one source, so the TUI + its test agree). */
647
+ export declare const MENU_HERE_LABEL = ". (here: a scratch pi at the root)";
648
+ export declare const MENU_NEW_LABEL = "+ new project\u2026";
649
+ export declare const MENU_SHELL_LABEL = "shell (a jailed bash on this machine)";
650
+ /**
651
+ * PURE: render ONE project row's annotation from its usage record. Files are
652
+ * global but conversations are per-machine, so the row tells the user where a
653
+ * conversation for this project already lives (`used on: <machines>`) and
654
+ * whether the CURRENT machine has none yet (`new here`). An unused project on a
655
+ * fresh machine is just `new here` (no machine list). This is the whole
656
+ * user-visible surface of the derived usage record, kept pure + testable.
657
+ */
658
+ export declare function formatProjectAnnotation(usage: ProjectUsage): string;
659
+ /**
660
+ * PURE: assemble the ordered, labelled, selectable menu rows from the choice-
661
+ * list + the per-project usage record. The order is: the projects (in the
662
+ * choice-list's stable sorted order), then the `.` "here" scratch entry, then
663
+ * `+ new project\u2026` (when `canNew`), then `shell` (when `canShell`). Each
664
+ * project row's label carries its used-on / new-here annotation
665
+ * (formatProjectAnnotation). This holds ALL the menu's logic (order + wording)
666
+ * so the raw-mode selector only renders these rows and dispatches the picked
667
+ * one by its `kind`/`project`.
668
+ *
669
+ * The `usage` list is expected to be keyed to `choiceList.projects` (same order,
670
+ * as deriveProjectUsage produces from the choice-list's projects); a project
671
+ * with no matching usage entry gets a bare, unannotated row rather than erroring.
672
+ */
673
+ export declare function buildMenuEntries(args: {
674
+ choiceList: MenuChoiceList;
675
+ usage: readonly ProjectUsage[];
676
+ }): MenuEntry[];
106
677
  /**
107
678
  * Encode an absolute path into a directory name using pi's OWN convention (see
108
679
  * pi coding-agent session-manager: `--${cwd without leading slash, / \ : -> -}--`),
@@ -110,18 +681,48 @@ export declare function resolveConfigSeed(env: AnonPiEnv): string;
110
681
  * hash). e.g. /home/u/dev/x -> --home-u-dev-x--
111
682
  */
112
683
  export declare function pathSlug(absPath: string): string;
113
- /**
114
- * The persistent per-workdir state dir on the host (mounted at the container's
115
- * ~/.pi/agent). Keyed by the workdir via pi's path-slug convention:
116
- * <anonPiHome>/state/<slug>/agent
117
- */
118
- export declare function stateAgentDir(env: AnonPiEnv, absWorkdir: string): string;
119
684
  /**
120
685
  * Normalise a proxy-less host:port key from an ANON_PI_LLM value or a provider
121
686
  * baseUrl, so `192.168.1.150:8080` matches `http://192.168.1.150:8080/v1`.
122
687
  * Returns `host` (no port) or `host:port`, lowercased, scheme/path stripped.
123
688
  */
124
689
  export declare function hostPortKey(value: string): string;
690
+ /**
691
+ * The provider key anon-pi gives the single local provider it generates. A
692
+ * neutral, host-agnostic name (matches the CONTEXT glossary's "local model"):
693
+ * it carries NO host identity, unlike the old `import` path which kept the
694
+ * host's own provider key.
695
+ */
696
+ export declare const LOCAL_PROVIDER_NAME = "local";
697
+ /**
698
+ * The pi `api` dialect the generated local provider speaks. Local model servers
699
+ * (llama.cpp, ollama, LM Studio, vLLM, ...) are overwhelmingly OpenAI-compatible
700
+ * and serve the completions API under `/v1`, so this is the safe default for an
701
+ * endpoint captured by `init` (there is no host models.json to copy a dialect
702
+ * from anymore). See the ## Decisions note in the done record.
703
+ */
704
+ export declare const LOCAL_PROVIDER_API = "openai-completions";
705
+ /**
706
+ * A benign, non-secret apiKey for the local provider (a LAN model rarely needs a
707
+ * real key). It is one of the values pi never flags as a real secret.
708
+ */
709
+ export declare const LOCAL_PROVIDER_API_KEY = "none";
710
+ /**
711
+ * PURE: synthesize a barebones pi `models.json` from a single `llm` endpoint
712
+ * (a URL, `ip:port`, or bare ip). It normalises the endpoint with `hostPortKey`
713
+ * (drops scheme/path/user:pass@, lowercases) and returns a models.json carrying
714
+ * exactly ONE local provider pointed at that endpoint.
715
+ *
716
+ * This REPLACES the old `import`-from-host-models.json flow: it reads NO host pi
717
+ * config, so no other provider, no paid API key, no session identity can leak
718
+ * into the seed. Endpoint in -> object out; `init` / seed-if-fresh write the
719
+ * result into the machine home.
720
+ *
721
+ * The baseUrl is `http://<host[:port]>/v1` (the OpenAI-compatible convention the
722
+ * completions api uses); the api dialect + benign apiKey are the LOCAL_PROVIDER_*
723
+ * constants.
724
+ */
725
+ export declare function generateModelsJson(llmEndpoint: string): PiModelsFile;
125
726
  /**
126
727
  * A pi provider entry (as it appears under models.json `providers[name]`). Only
127
728
  * the fields anon-pi reads are typed; the rest is preserved verbatim.
@@ -138,51 +739,170 @@ export interface PiModelsFile {
138
739
  providers?: Record<string, PiProvider>;
139
740
  [k: string]: unknown;
140
741
  }
141
- /** The result of picking the ANON_PI_LLM provider out of a host models.json. */
142
- export interface ImportResult {
143
- /** The provider key (e.g. "llamacpp-router"). */
144
- name: string;
145
- /** The barebones models.json to write (just the matched provider). */
146
- models: PiModelsFile;
147
- /** True if the matched provider's apiKey looks like a REAL secret (warn). */
148
- apiKeyLooksReal: boolean;
149
- }
150
742
  /**
151
- * PURE: given a parsed host models.json and the ANON_PI_LLM value, select the
152
- * provider whose baseUrl points at that host:port and return a barebones
153
- * models.json carrying ONLY that provider (verbatim, with its models). Throws
154
- * AnonPiError if nothing matches. Carries no other provider (so etherplay /
155
- * google / paid API keys never enter the seed).
743
+ * The default SOCKS ports `init` probes, each with a WEAK, structural hint (the
744
+ * conventional tool that DEFAULTS to that port). The hint names a local tool a
745
+ * port is CONVENTIONALLY used by, NOT the exit provider: `9050`/`9150` are Tor's
746
+ * own listeners (Tor IS the tool, so naming it is honest), `1080` is the generic
747
+ * SOCKS default (wireproxy / `ssh -D` / other), which is why its hint stays
748
+ * provider-agnostic ("wireproxy / ssh -D / generic"): behind a `1080` wireproxy
749
+ * could be ANY WireGuard VPN, and we never guess which. See the ADR / Decisions.
156
750
  */
157
- export declare function pickProviderForLlm(hostModels: PiModelsFile, llmDirect: string): ImportResult;
751
+ export declare const DEFAULT_SOCKS_PROBE_PORTS: readonly {
752
+ port: number;
753
+ hint: string;
754
+ }[];
158
755
  /**
159
- * The default host models.json path `import` reads FROM. Overridable via
160
- * ANON_PI_SOURCE_MODELS; defaults to the real pi config (~/.pi/agent/models.json
161
- * under the container-less host HOME, or PI_CODING_AGENT_DIR if the user set it).
756
+ * The SOCKS5 method-selection greeting `init` sends to CONFIRM a port really
757
+ * speaks SOCKS5 (RFC 1928 §3): version 5, one method offered, `0x00`
758
+ * (no-authentication). A real SOCKS5 server replies with two bytes
759
+ * `[0x05, <method>]`; anything else is not SOCKS5. Exposed as a constant so the
760
+ * probe I/O and the handshake test send byte-identical bytes.
162
761
  */
163
- export declare function resolveSourceModelsPath(env: AnonPiEnv): string;
762
+ export declare const SOCKS5_METHOD_SELECTOR: readonly number[];
763
+ /** How a SOCKS5 handshake probe against a port came out (the pure verdict). */
764
+ export type SocksHandshake = {
765
+ /** The server replied with a well-formed SOCKS5 method-selection reply. */
766
+ socks5: true;
767
+ /** The selected method byte the server chose (informational). */
768
+ method: number;
769
+ } | {
770
+ /** The reply was absent, too short, or not a SOCKS5 version-5 reply. */
771
+ socks5: false;
772
+ /** A terse, provider-agnostic reason (for the findings line). */
773
+ reason: string;
774
+ };
164
775
  /**
165
- * Build the run plan from the environment + the (optional) workdir arg. PURE: it
166
- * resolves paths and composes the netcage argv, performing NO filesystem writes
167
- * or spawns. It THROWS AnonPiError for the required inputs (image, llm, proxy).
776
+ * PURE: interpret a SOCKS5 method-selection REPLY (the bytes read back after
777
+ * sending SOCKS5_METHOD_SELECTOR). A valid reply is EXACTLY the two bytes
778
+ * `[0x05, <method>]` where `<method> != 0xff` (0xff = "no acceptable methods",
779
+ * i.e. the server IS SOCKS5 but rejected no-auth; that is still a SOCKS5 server,
780
+ * but for a bare no-auth probe we treat it as a soft failure so the finding does
781
+ * not imply the port is usable no-auth). Any non-5 first byte, a short reply, or
782
+ * an empty reply is NOT SOCKS5.
168
783
  *
169
- * Statefulness (Model B): a persistent per-workdir host dir is mounted at the
170
- * container's ~/.pi/agent, so pi's sessions/history/settings/extensions persist.
171
- * First-launch seed (Model C): when that home is FRESH, the container run
172
- * command promotes the image's staged defaults + the imported models.json into
173
- * it and stamps a marker; thereafter pi OWNS the home and nothing is clobbered.
784
+ * Reply in -> verdict out; the socket read is cli.ts's job. The reason strings
785
+ * are deliberately structural ("no reply", "not SOCKS5") and NEVER name a
786
+ * provider.
787
+ */
788
+ export declare function interpretSocks5Handshake(reply: readonly number[] | Uint8Array | Buffer): SocksHandshake;
789
+ /**
790
+ * A weak process hint: a LOCAL tool whose presence SUGGESTS what a port is
791
+ * (e.g. a `tor` process -> likely Tor). It is a hint about the LOCAL software
792
+ * only, never a claim about the EXIT provider. cli.ts supplies the observed
793
+ * process name (e.g. from `ps`/`/proc`); the pure mapping stays testable.
794
+ */
795
+ export interface ProcessHint {
796
+ /** The observed local process name (as cli.ts read it). */
797
+ process: string;
798
+ /** The weak, hedged hint text ("a `tor` process is running -> likely Tor"). */
799
+ hint: string;
800
+ }
801
+ /**
802
+ * PURE: map an observed local process name to a WEAK, hedged hint, or undefined
803
+ * when we have nothing honest to say. The ONLY confident mapping is `tor` ->
804
+ * "likely Tor", because Tor is a LOCAL tool that runs its OWN SOCKS listener (so
805
+ * seeing `tor` is real evidence the port is Tor). We do NOT map anything to an
806
+ * EXIT provider (Mullvad/Proton/...): a `wireproxy` process only tells us the
807
+ * SOCKS front-end, never which VPN sits behind it, so its hint stays
808
+ * provider-agnostic. Every returned hint is HEDGED ("likely", "-> a SOCKS
809
+ * front-end") and never states the exit provider.
810
+ */
811
+ export declare function processHint(processName: string): ProcessHint | undefined;
812
+ /**
813
+ * One probed SOCKS candidate, as `init` gathers it for the findings display. All
814
+ * fields are EVIDENCE the probe actually observed; there is DELIBERATELY no
815
+ * "provider" field, so the type itself cannot carry a provider label.
816
+ */
817
+ export interface ProxyFinding {
818
+ /** The host that was probed (usually 127.0.0.1). */
819
+ host: string;
820
+ /** The port that was probed. */
821
+ port: number;
822
+ /** Whether the TCP port was open (a connection succeeded). */
823
+ open: boolean;
824
+ /** The SOCKS5 handshake verdict (only meaningful when `open`). */
825
+ handshake?: SocksHandshake;
826
+ /** The port's structural hint (DEFAULT_SOCKS_PROBE_PORTS), if any. */
827
+ portHint?: string;
828
+ /** Any weak LOCAL process hint (processHint), if one was observed. */
829
+ processHint?: string;
830
+ }
831
+ /**
832
+ * The set of substrings a findings line must NEVER contain: known exit-provider
833
+ * / VPN brand names. This is the machine-checkable half of the never-label rule
834
+ * (a test asserts formatProxyFindings' output contains NONE of these for any
835
+ * input). It is not exhaustive of every brand, but it pins the obvious ones so a
836
+ * regression that starts labelling providers is caught. `tor` is NOT here: Tor
837
+ * is the LOCAL tool we legitimately hint at, not an opaque exit provider.
838
+ */
839
+ export declare const FORBIDDEN_PROVIDER_LABELS: readonly string[];
840
+ /**
841
+ * PURE: format the probe findings into the human-readable block `init` shows
842
+ * before asking the user to CHOOSE a proxy. It renders EVIDENCE ONLY: for each
843
+ * candidate, the `host:port`, whether it is open, the SOCKS5 handshake verdict,
844
+ * and the structural PORT hint. It NEVER emits an exit-provider label (a SOCKS
845
+ * proxy does not announce its provider; a false label is a dangerous lie). The
846
+ * `## Decisions` note + a test assert the output never contains a
847
+ * FORBIDDEN_PROVIDER_LABELS substring for any input.
174
848
  *
175
- * `modelsSeedExists` reports whether the canonical import models.json exists (so
176
- * it is mounted for the seed); `stateExists` reports whether this workdir's
177
- * state home already exists (so `fresh` is known).
849
+ * `processNote` is the HOST-WIDE weak process hint (a running `tor`/`wireproxy`
850
+ * LOCAL process), shown ONCE as a general note rather than glued onto every port
851
+ * line: the observation is host-wide, not per-port, so repeating it on each
852
+ * candidate (including closed ports the process is unrelated to) reads as noise.
853
+ * A per-finding `processHint`, if still set, is also honoured inline for
854
+ * backward compatibility, but `init` now passes the host-wide note instead.
178
855
  *
179
- * --ephemeral mounts NO writable state: pi writes to the container's own
180
- * filesystem, which netcage runs with `--rm`, so it is destroyed when the
181
- * container exits. Nothing writable ever touches a host path; there is no
182
- * cleanup and no leftover-on-crash. (The read-only models.json seed is still
183
- * mounted; it is a single file anon-pi never writes to.)
856
+ * Findings in -> display string out; the socket probes are cli.ts's job.
857
+ */
858
+ export declare function formatProxyFindings(findings: readonly ProxyFinding[], processNote?: string): string;
859
+ /**
860
+ * PURE: the `socks5h://<host:port>` URL `init` hands to `netcage verify` and
861
+ * writes into config.json. Only socks5h:// is accepted downstream (plain
862
+ * socks5:// resolves DNS locally and leaks), so `init` always emits socks5h.
863
+ * A value that already carries a scheme is normalised to its host:port first
864
+ * (via hostPortKey) so `socks5h://socks5h://...` can never be produced.
865
+ */
866
+ export declare function socks5hUrl(hostPort: string): string;
867
+ /**
868
+ * PURE: extract the exit IP `netcage verify` reported from its combined output.
869
+ * `netcage verify` prints the jail's forced-egress exit IP (an IPv4/IPv6 line)
870
+ * as PROOF the egress leaves via the proxy (not the host IP). We scan the output
871
+ * for the first plausible IP literal and return it; undefined if none is found
872
+ * (the caller then shows the raw output and lets the user judge). This is a
873
+ * best-effort PARSE of another tool's text, kept pure + tested so a format tweak
874
+ * is caught by a unit test, not only in the field.
875
+ */
876
+ export declare function parseVerifyExitIp(output: string): string | undefined;
877
+ /**
878
+ * The image-menu choices `init` offers for the default machine's image. `[1]`
879
+ * and `[2]` build a SHIPPED Dockerfile via `podman build`; `[3]` takes an
880
+ * existing image ref verbatim; `[4]` skips (the machine is created imageless and
881
+ * pinned later). The pure list keeps the menu wording testable; cli.ts renders
882
+ * it, runs `podman build`, and writes the machine.
883
+ */
884
+ export type InitImageChoice = 'basic' | 'webveil' | 'existing' | 'skip';
885
+ /** One rendered image-menu entry: its choice tag + the human label. */
886
+ export interface InitImageMenuEntry {
887
+ choice: InitImageChoice;
888
+ label: string;
889
+ }
890
+ /**
891
+ * PURE: the ordered image-menu entries `init` shows. `[1]` basic pi
892
+ * (Dockerfile.pi), `[2]` pi + webveil/SearXNG (examples/Dockerfile.pi-webveil),
893
+ * `[3]` an existing image ref, `[4]` skip. A single source so the prompt and its
894
+ * test agree on the order + wording.
895
+ */
896
+ export declare function initImageMenu(): InitImageMenuEntry[];
897
+ /**
898
+ * PURE: build the `config.json` body `init` writes, keeping only the non-empty
899
+ * fields (a skipped image / llm is simply omitted, never written as ""). Emits
900
+ * pretty-printed JSON (tab indent, trailing newline) matching
901
+ * serializeMachineJson, so a browsed ~/.anon-pi/config.json reads cleanly. The
902
+ * proxy is REQUIRED (init only reaches here after a verified proxy), so it is
903
+ * always present; llm / defaultMachine / projects are included when set.
184
904
  */
185
- export declare function buildRunPlan(env: AnonPiEnv, workdirArg: string | undefined, modelsSeedExists: (modelsJsonPath: string) => boolean, stateExists: (stateDir: string) => boolean): RunPlan;
905
+ export declare function serializeConfigJson(config: AnonPiConfig): string;
186
906
  /**
187
907
  * Absolute path to the Dockerfile.pi that ships with anon-pi, resolved from this
188
908
  * module's location (package root, one level up from dist/anon-pi.js), or
@@ -195,8 +915,62 @@ export declare function shippedDockerfilePath(): string | undefined;
195
915
  * anon-pi (examples/Dockerfile.pi-webveil), or undefined if not found.
196
916
  */
197
917
  export declare function shippedWebveilDockerfilePath(): string | undefined;
918
+ /**
919
+ * A parsed `machine <verb> …` command. A discriminated union so the CLI
920
+ * dispatches on `verb` with the already-validated fields:
921
+ * - `create <name> [--image <ref>]`: name validated; image optional here (the
922
+ * CLI prompts for it when absent, on a TTY).
923
+ * - `list`: no args.
924
+ * - `set-image <name> <ref>`: name validated; the new image ref (non-empty).
925
+ * - `rm <name> [--yes]`: name validated; `yes` skips the confirm (the CLI
926
+ * still enforces the non-TTY abort when `yes` is false).
927
+ */
928
+ export type MachineCommand = {
929
+ verb: 'create';
930
+ name: string;
931
+ image?: string;
932
+ } | {
933
+ verb: 'list';
934
+ } | {
935
+ verb: 'set-image';
936
+ name: string;
937
+ image: string;
938
+ } | {
939
+ verb: 'rm';
940
+ name: string;
941
+ yes: boolean;
942
+ };
943
+ /**
944
+ * PURE: parse the tokens AFTER `machine` into a MachineCommand. Validates the
945
+ * machine name via validateName (the reserved-name / traversal guard) so the CLI
946
+ * only ever joins a safe segment under the machines dir. Throws AnonPiError
947
+ * (printed verbatim, exit 1) for an unknown/missing verb, a missing or extra
948
+ * positional, an unknown flag, or a bad name.
949
+ *
950
+ * The grammar is deliberately small and flag-light (mirrors the launch grammar's
951
+ * `--yes` / `--image` shape): `--image <ref>` on create, `--yes` on rm; no other
952
+ * flags. This keeps `machine` a thin, predictable dispatch surface.
953
+ */
954
+ export declare function parseMachineArgs(args: readonly string[]): MachineCommand;
955
+ /**
956
+ * PURE: the JSON body a machine.json carries, given the pinned image (and an
957
+ * optional per-machine projects override, preserved on a re-pin). A single
958
+ * source so create + set-image write byte-identical, pretty-printed JSON (tab
959
+ * indent, trailing newline) that reads cleanly when the user browses
960
+ * ~/.anon-pi/machines/<M>/machine.json.
961
+ */
962
+ export declare function serializeMachineJson(config: MachineConfig): string;
963
+ /**
964
+ * PURE: the compatibility WARNING `machine set-image` prints after re-pinning
965
+ * the image. Re-pinning does NOT reseed or touch the home: the home's pi
966
+ * extensions / downloaded bin were built against the OLD image, so a mismatched
967
+ * new image may misbehave. The message tells the user the two remedies (re-run
968
+ * `pi install` inside the machine, or delete the home to reseed) WITHOUT doing
969
+ * either automatically. See the ## Decisions note (set-image warning wording).
970
+ */
971
+ export declare function setImageWarning(name: string, oldImage: string | undefined, newImage: string): string;
198
972
  /** Read the AnonPiEnv from a process env map (kept separate so tests inject one). */
199
973
  export declare function envFromProcess(penv: Record<string, string | undefined>): AnonPiEnv;
200
974
  /** The --help text (kept here so it is covered by the same module). */
201
- export declare const HELP = "anon-pi - launch pi inside a netcage (anonymized egress + one direct local model)\n\nUSAGE\n anon-pi [WORKDIR] launch pi jailed, working in WORKDIR (default: cwd)\n anon-pi import seed models.json from your local model\n\n WORKDIR the host folder pi works in (mounted at /work; pi's cwd). Files pi\n writes there land on the host.\n\nWHAT IT DOES\n Runs pi inside netcage with all web/DNS egress forced through the socks5h\n proxy (fail-closed) and ONE direct hole to your local model (ANON_PI_LLM).\n\n STATEFUL by default: a persistent per-workdir home\n (<ANON_PI_HOME>/state/<workdir>/agent) is mounted at the container's\n ~/.pi/agent, so your conversations, history, settings (model choice), and any\n extensions you `pi install` persist across launches. Re-running in the same\n folder resumes it. On a FRESH home, the image's staged defaults (extensions,\n trust) and your imported models.json are seeded in once; after that pi owns the\n home and nothing is overwritten. Requires `netcage`.\n\n --ephemeral (or ANON_PI_EPHEMERAL=1): mount NO writable state; pi writes to the\n container's own --rm layer, gone on exit. Nothing writable touches the host,\n no cleanup, no leftover-on-crash.\n\nimport\n Reads your host ~/.pi/agent/models.json, picks the provider whose baseUrl\n serves ANON_PI_LLM, and writes JUST that provider to the canonical seed\n (<ANON_PI_CONFIG>/models.json). No other provider's API keys, no sessions, no\n identity. It SEEDS a fresh home; models you later add inside pi persist and are\n never clobbered. Re-run with --force to overwrite the canonical seed.\n\nENVIRONMENT\n ANON_PI_IMAGE (required for run) image with `pi` on PATH. No image yet?\n Running anon-pi without it prints a ready-to-build\n Dockerfile.pi recipe; see the README (Providing a pi image).\n ANON_PI_LLM (required) RFC1918/link-local IP[:port] of the local model\n ANON_PI_PROXY (required) socks5h URL of your proxy (Tor/wireproxy/ssh -D).\n No default: the proxy is what anonymizes, so it is never guessed.\n ANON_PI_EPHEMERAL set to 1 for a throwaway (non-persistent) session\n ANON_PI_HOME anon-pi home (default $XDG_CONFIG_HOME/anon-pi or ~/.config/anon-pi)\n ANON_PI_CONFIG canonical seed dir holding models.json (default <ANON_PI_HOME>/agent)\n ANON_PI_SOURCE_MODELS (import) host models.json to read (default ~/.pi/agent/models.json)\n\nRESET A SESSION\n Delete its state home to start fresh (re-seeds next launch):\n rm -rf <ANON_PI_HOME>/state/<workdir-slug>/agent\n\nPLATFORM\n Linux only (via netcage's netns/nft jail). On macOS/Windows it works only\n inside a Linux VM, where --allow-direct to a LAN model is VM-boundary-sensitive.\n";
975
+ export declare const HELP = "anon-pi - run pi on anonymized, jailed machines (netcage: forced egress + one direct local model)\n\nUSAGE\n anon-pi MENU: pick a project (pi), a shell, or a new project\n anon-pi <project> pi in the project (/projects/<project>); exit pi -> host\n anon-pi <project> <pi-args\u2026> forward args to pi (headless/one-shot; no TTY needed)\n anon-pi --shell [<project>] a jailed bash (at ~, or cd'd into <project>) - the project-hopper\n anon-pi -m <machine> [<p>] the same, on <machine> (its own image + home + conversations)\n anon-pi --mount <parent> [<p>] root at a HOST parent folder instead of the projects root\n anon-pi init onboard: verify your proxy, capture your local model, pick an image\n anon-pi machine \u2026 manage machines (create / list / set-image / rm)\n anon-pi --delete-home [<m>] delete a machine's home (config + convos); keep its image pin + files\n anon-pi --delete-project <p> delete a project's files + its per-machine sessions; keep the homes\n\n <project> a folder under the projects root (mounted at /projects; pi's cwd). `.` means\n the root itself (a scratch pi at /projects, /work for --mount, or ~).\n\n [--rm] throwaway container this run (the DEFAULT; deleted on exit).\n [--keep] leave the container KEPT so its filesystem survives (apt install,\n quit, re-enter). anon-pi finds it by netcage's managed label and\n `netcage start`s it on re-entry.\n\nWHAT IT DOES\n Runs pi inside netcage with all web/DNS egress forced through the socks5h proxy\n (fail-closed) and ONE direct hole to your local model (ANON_PI_LLM). A MACHINE\n is an image + a persistent HOST home (bind-mounted at /root) holding your pi\n config, extensions, and conversations; the container is disposable, so `--rm`\n loses nothing. Files (projects) are global by default; conversations are\n per-machine. On a FRESH machine home the image's staged defaults + your\n models.json are seeded in once; after that pi owns the home. Requires `netcage`.\n\nENVIRONMENT\n ANON_PI_PROXY (required) socks5h URL of your proxy (Tor/wireproxy/ssh -D).\n No default: the proxy is what anonymizes, so it is never guessed.\n ANON_PI_LLM (required) RFC1918/link-local IP[:port] of the local model\n ANON_PI_IMAGE image with `pi` on PATH, used when a machine has no image set.\n No image yet? See the README (Providing a pi image).\n ANON_PI_HOME anon-pi workspace dir (default ~/.anon-pi; NOT under ~/.config)\n ANON_PI_PROJECTS projects root override (host dir mounted at /projects)\n\nPLATFORM\n Linux only (via netcage's netns/nft jail). On macOS/Windows it works only\n inside a Linux VM, where --allow-direct to a LAN model is VM-boundary-sensitive.\n";
202
976
  //# sourceMappingURL=anon-pi.d.ts.map