pinggy 0.6.5 → 0.6.6
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/ARCHITECTURE.md +90 -36
- package/CLAUDE.md +18 -8
- package/dist/{TunnelManager-DXNXIH5W.js → TunnelManager-JRVEADS4.js} +4 -3
- package/dist/{TunnelTui-K7KESRTQ.js → TunnelTui-6H4NPUNF.js} +4 -3
- package/dist/{chunk-QZJGTQZC.js → chunk-2GIJXE4K.js} +3 -2
- package/dist/{chunk-EMCDDH3B.js → chunk-3WMTTJHI.js} +11 -299
- package/dist/chunk-4XXAHYCJ.js +927 -0
- package/dist/{chunk-X6TZN5CT.js → chunk-CZOKR73F.js} +1 -1
- package/dist/chunk-FQ22KFVV.js +882 -0
- package/dist/{chunk-K5QHR5KU.js → chunk-HAFTH5MX.js} +498 -551
- package/dist/chunk-HTIWY3O5.js +293 -0
- package/dist/{chunk-IRKMUV37.js → chunk-LWCVB42S.js} +2 -2
- package/dist/{chunk-N5WE4DYD.js → chunk-MAK5R4WQ.js} +12 -0
- package/dist/{chunk-7EQKHVQX.js → chunk-MHQ3CVEB.js} +4 -51
- package/dist/chunk-MKGD2QAI.js +51 -0
- package/dist/{chunk-3PTLHLFL.js → chunk-Q5NCTGNS.js} +33 -240
- package/dist/{configStore-DXC6WMYO.js → configStore-JJUWT2YO.js} +3 -3
- package/dist/{daemonChild-HZ27YJKQ.js → daemonChild-Q6WGYKYX.js} +14 -10
- package/dist/{daemonConfig-MCAKZHY2.js → daemonConfig-VWK4TXVS.js} +2 -2
- package/dist/index.cjs +3555 -1791
- package/dist/index.d.cts +142 -129
- package/dist/index.d.ts +142 -129
- package/dist/index.js +18 -13
- package/dist/{ipcClient-XGF2KCQO.js → ipcClient-IZ5R6TPN.js} +2 -1
- package/dist/{main-TDQB5ZB4.js → main-BI7ACRHS.js} +19 -14
- package/dist/updateChild-Z3SIRYO5.js +237 -0
- package/dist/workers/file_serve_worker.js +1 -1
- package/package.json +2 -1
- package/scripts/install/install.ps1 +3 -1
- package/scripts/install/install.sh +34 -6
package/ARCHITECTURE.md
CHANGED
|
@@ -12,11 +12,12 @@ The `pinggy` binary has three execution modes, dispatched in `src/main.ts`:
|
|
|
12
12
|
| -------------------- | -------------------------------- | --------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
|
|
13
13
|
| Daemon child | `--_daemon-child` flag | `runDaemonChild()` in `src/daemon/daemonChild.ts` | Long-running background process. Owns the `TunnelManager` and the SDK. |
|
|
14
14
|
| Subcommand | First arg in `SUBCOMMANDS` set | `handleSubcommand()` in `src/cli/subcommands.ts` | Short-lived CLI invocation:`config`, `start`, `stop`, `ps`, `attach`, `daemon`, `logs`, `log`, `restart`, `device`, and `devices`, which prints the new spelling. |
|
|
15
|
+
| Update child | `--_update-child` flag | `runUpdateChild()` in `src/update/updateChild.ts` | Short-lived detached process. Checks for a release, downloads it, swaps it in. See section 20. |
|
|
15
16
|
| Legacy single-tunnel | No subcommand, has flags | `buildAndStartTunnel()` in `src/cli/buildAndStartTunnel.ts` | Backwards-compatible single-shot tunnel for flags like `-l 3000` or `-R0:...`. |
|
|
16
17
|
|
|
17
18
|
The CLI never opens an SDK tunnel itself. Every tunnel is created inside the daemon. CLI processes talk to the daemon over HTTP + WebSocket on `127.0.0.1`.
|
|
18
19
|
|
|
19
|
-
`pinggy device` is the exception. By default the daemon runs the device agent
|
|
20
|
+
`pinggy device` is the exception. By default the daemon runs the device agent, so it outlives the terminal. With `--foreground` it runs inside the CLI process and talks to the dashboard directly. It reads the daemon's tunnel list, and it stops, restarts and starts tunnels when the dashboard asks. See section 17.
|
|
20
21
|
|
|
21
22
|

|
|
22
23
|
|
|
@@ -43,11 +44,14 @@ Logs live under `getPinggyLogDir()`:
|
|
|
43
44
|
├── daemon-config.json Persisted settings: log level, and the background device agent to start
|
|
44
45
|
├── daemon-state.json Active tunnels, for crash recovery
|
|
45
46
|
├── device.json Device agent identity + token, mode 0600
|
|
47
|
+
├── update.json What the update checks found and which lines printed
|
|
48
|
+
├── update.lock Held by the 1 process replacing the binary: {pid, startedAt}
|
|
46
49
|
└── tunnels/
|
|
47
50
|
└── <name>_<configId>.json Saved tunnel configs (from `pinggy config save`)
|
|
48
51
|
|
|
49
52
|
<logDir>/
|
|
50
53
|
├── daemon.log Daemon process log (rolled)
|
|
54
|
+
├── update.log The last background update, overwritten each run
|
|
51
55
|
└── tunnels/
|
|
52
56
|
└── <origin>__<name>__<tunnelId>.log Per-tunnel logs (rolled 10MB×3)
|
|
53
57
|
```
|
|
@@ -149,7 +153,7 @@ Server: `src/daemon/ipcServer.ts`. Client: `src/daemon/ipcClient.ts`. Public fac
|
|
|
149
153
|
| GET | `/logs/paths` | All tunnel log file paths + running flags |
|
|
150
154
|
| GET | `/logs/resolve?q=` | Resolve a name/id/configId to a log path |
|
|
151
155
|
| POST | `/shutdown` | Graceful shutdown |
|
|
152
|
-
| GET | `/device` | The background device agent's status
|
|
156
|
+
| GET | `/device` | The background device agent's status |
|
|
153
157
|
| POST | `/device/start` | Start the device agent on `device.json` |
|
|
154
158
|
| POST | `/device/stop` | Stop the device agent |
|
|
155
159
|
|
|
@@ -381,8 +385,8 @@ src/
|
|
|
381
385
|
│ ├── envelope.ts Versioned frame wrapper + channel/op constants
|
|
382
386
|
│ ├── device_schema.ts Zod schemas for welcome, error, disconnect payloads
|
|
383
387
|
│ ├── tunnels/tunnelList.ts device/tunnels: daemon poll, whitelist, change detection
|
|
384
|
-
│ ├── tunnels/tunnelActions.ts tunnel/start, stop, restart
|
|
385
|
-
│ └── login/ `pinggy device login
|
|
388
|
+
│ ├── tunnels/tunnelActions.ts tunnel/start, stop, restart, update against the daemon
|
|
389
|
+
│ └── login/ `pinggy device login`: email sign-in over HTTPS, then the agent
|
|
386
390
|
│
|
|
387
391
|
├── remote_management/ Remote control via Pinggy management WS
|
|
388
392
|
│ ├── remoteManagement.ts Connect/disconnect + state machine
|
|
@@ -409,7 +413,7 @@ src/
|
|
|
409
413
|
|
|
410
414
|
## 11. Key types
|
|
411
415
|
|
|
412
|
-
- `TunnelOrigin = "app" | "cli" | "remote" | "device"` (`src/tunnel_manager/TunnelManager.ts`). `device` is the device agent acting for the dashboard's device page
|
|
416
|
+
- `TunnelOrigin = "app" | "cli" | "remote" | "device"` (`src/tunnel_manager/TunnelManager.ts`). `device` is the device agent acting for the dashboard's device page. Set on every tunnel at creation; flows into log filenames.
|
|
413
417
|
- `ClientOrigin = "app" | "cli" | "remote" | "device"` (`src/daemon/ipcClient.ts`). Same values, used in the `X-Pinggy-Origin` header.
|
|
414
418
|
- `TunnelStateType` (`src/types.ts`): `idle | starting | running | live | closed | exited`.
|
|
415
419
|
- `FinalConfig` (`src/types.ts`): the SDK's `TunnelConfigurationV1` plus `conf?` and `saveconf?`. Used by `buildConfig.ts` and threaded through to the daemon.
|
|
@@ -483,23 +487,25 @@ The service stores the full path of the binary (`process.execPath`). If the user
|
|
|
483
487
|
|
|
484
488
|
A system service gives restart-on-failure and start-at-login. The plain daemon mode does not.
|
|
485
489
|
|
|
490
|
+
On macOS and Linux an installed binary sits behind the link `~/.pinggy/bin/pinggy` (section 20), so `serviceProgramPath()` stores the link. A versioned path would pin the service to 1 file that a later prune deletes.
|
|
491
|
+
|
|
486
492
|
## 17. Device agent (`pinggy device`)
|
|
487
493
|
|
|
488
|
-
The one long-lived surface that is not a tunnel. `pinggy device connect` enrols the machine with the Pinggy dashboard and holds 1 WebSocket open so the dashboard can show it as online. By default the daemon runs it (
|
|
494
|
+
The one long-lived surface that is not a tunnel. `pinggy device connect` enrols the machine with the Pinggy dashboard and holds 1 WebSocket open so the dashboard can show it as online. By default the daemon runs it (see Background mode below). With `--foreground` it runs in the CLI process. Code lives in `src/devices/`, entered from `src/cli/subcommand/handlers/deviceCommand.ts`.
|
|
489
495
|
|
|
490
|
-
**Email sign-in
|
|
496
|
+
**Email sign-in.** `pinggy device login` gets the device token without the dashboard: it asks for an email, `POST /backend/api/v1/device-agent/login/start` emails a 6-digit code, and the code prompt races a `poll` every few seconds under 1 `AbortController`. A right code (and the TOTP, with MFA on) answers the token once. The email also carries an Approve link: the CLI prints the `match_code` its page shows as `Device Code: <code>`, then `We have sent a 6-digit code to <email>.` and `Enter the code below or click the approve button in the email.` A poll collects a link's approval, and a typed code answered `pending` stops the prompt so the poll can. The CLI writes `device.json`, prints the device's browser link and its QR code (`createQrCodes`, shared with the TUI): a one-time sign-in link after a typed code, the plain device page after the emailed link. Then it runs the same agent. Code in `src/devices/login/`: `deviceLogin.ts` (the command; every dependency injected, so `src/_tests_/deviceLogin.test.ts` runs it with no dashboard or terminal), `loginApi.ts` (`fetch`, `buildDashboardHttpUrl`, the public client token), `login_schema.ts` (zod), `prompts.ts` (`readline/promises`, 1 interface per question, closed on answer or abort; every question starts with a cyan `→`, and the sign-in result with a green one, through `picocolors`; `askHidden` reads the authenticator code without showing it, since the code still works after it is typed and the open link asks for one). A stdin that is not a TTY stops at once and points at `connect --token`. The token is never printed.
|
|
491
497
|
|
|
492
|
-
**Install scripts
|
|
498
|
+
**Install scripts.** `scripts/install/install.sh` (macOS, Linux, POSIX `sh`) and `scripts/install/install.ps1` (Windows PowerShell 5.1 and 7) install or update the binary, put `pinggy` on PATH with no sudo, then ask "Connect this device to Pinggy? [Y/n]". Enter or `y` runs `pinggy device login -b` by full path. `-b` is the default, and the scripts pass it so an older binary the user kept also runs the agent in its daemon. An answer starting with `n` prints the login command and exits 0, so the CLI is installed with no device. With no terminal, the scripts ask nothing and print the command. `install.sh` writes `~/.pinggy/bin/pinggy` and links `~/.local/bin/pinggy` to it, adding 1 marked block to the shell's rc file when `~/.local/bin` is not on PATH. `install.ps1` writes `%LOCALAPPDATA%\Pinggy\bin\pinggy.exe` and adds that directory to the user PATH. Both read 3 things this repo owns: the release asset names, the `Pinggy CLI version: <x.y.z>` line, and the `--manage` and `-b` flags of `device login` and `connect`. A change to any of them changes both scripts in the same commit. `.github/workflows/website-cli-download-links-pr.yml` copies both, read at the release tag, to the website's `static/`, so pinggy.io serves `/install.sh` and `/install.ps1`. After `device login` or `connect` exits 0, both scripts ask "Start pinggy automatically when this computer starts? [Y/n]" and run `pinggy daemon service-install`. The question says "starts" for users. The service actually starts pinggy after the user signs in, not at boot. They skip the question when the service exists and runs the installed binary: `install.sh` looks for that binary's path in the launchd plist or the systemd unit file, `install.ps1` compares the command of the `PinggyDaemon` task (`Get-ScheduledTask`) with it. A service that runs any other binary gets the question, and `service-install` replaces it. `install.sh` also skips it on Linux with no systemd user manager. With no terminal, they print the `service-install` command. They remove `DEVICE_AGENT_TOKEN` before the question. Renaming the task, the plist or the unit file changes both scripts in the same commit. Lint with `shellcheck -s sh` and `PSScriptAnalyzer`.
|
|
493
499
|
|
|
494
|
-
**The token command
|
|
500
|
+
**The token command.** The dashboard shows `curl -fsSL https://pinggy.io/install.sh | DEVICE_AGENT_TOKEN=<token> sh`, and `$env:DEVICE_AGENT_TOKEN='<token>'; irm https://pinggy.io/install.ps1 | iex` on Windows. With the variable set, both scripts update an older binary without asking, then run `pinggy device connect -b` by full path, with `--manage` when `PINGGY_MANAGE` is set. The token reaches the CLI in its environment, never on a command line, where `ps` would show it. `install.sh` gives `connect` `/dev/null` as stdin, since it reads no key. `install.ps1` removes the variable in a `finally`, because `iex` runs in the user's own window. `handleDevice()` reads `DEVICE_AGENT_TOKEN` and deletes it from `process.env` before any verb runs, so no shell, daemon or other child inherits it (`takeEnvironmentToken()` in `deviceCommand.ts`). `connect` then picks the token from `--token`, else the variable, else `device.json`, and the server from `--manage`, else `dashboard.pinggy.io` for a token from the variable, else the server in `device.json` (`resolveConnectTarget()`). An empty variable counts as unset.
|
|
495
501
|
|
|
496
|
-
The design lives in the `pinggy_backend` repo under `docs/pinggy-devices/`: `cli.md` is the CLI contract
|
|
502
|
+
The design lives in the `pinggy_backend` repo under `docs/pinggy-devices/`: `cli.md` is the CLI contract. The wire format is `src/devices/envelope.ts` and the zod schemas under `src/devices/`. This section records what the CLI implements today.
|
|
497
503
|
|
|
498
|
-
**With `--foreground` it runs in the CLI process.** The agent owns no tunnel.
|
|
504
|
+
**With `--foreground` it runs in the CLI process.** The agent owns no tunnel. It reads the daemon: `getDaemonInfo()` for `daemon.json`, then `IPCClient.listTunnels()` for `GET /tunnels`, every 5 s, and `listSavedConfigs()` for the saved configs. Listing never starts a daemon, and it refuses a daemon whose `ipcVersion` differs, as `ensureDaemonRunning()` does. It also acts on the daemon when the dashboard asks (see Device tunnel actions below); only a start of a config may call `ensureDaemonRunning()`. `TunnelManager` and `TunnelClient` stay off this path. Killing the agent leaves running tunnels alone.
|
|
499
505
|
|
|
500
|
-
**It does not reuse `src/remote_management/`.** Remote management is a dashboard-driven tunnel controller keyed by an API key. A device is the machine itself, keyed by its own token, and the 2 sockets speak different protocols. The duplication is deliberate: the backend `
|
|
506
|
+
**It does not reuse `src/remote_management/`.** Remote management is a dashboard-driven tunnel controller keyed by an API key. A device is the machine itself, keyed by its own token, and the 2 sockets speak different protocols. The duplication is deliberate: the backend's do-not-touch list (`docs/pinggy-devices/must-not-change.txt`) names the remote-management files, and that loop keeps its fixed 5000 ms retry with no cap and no watchdog.
|
|
501
507
|
|
|
502
|
-
### Background mode
|
|
508
|
+
### Background mode
|
|
503
509
|
|
|
504
510
|
`pinggy device connect` and `pinggy device login` hand the agent to the daemon, as `pinggy start -b` hands it a tunnel, and exit once the device connects. This is the default. `--foreground` (`cliOptions.foreground`, hidden) keeps the agent in the CLI process. `-b` (`cliOptions.b`) still parses and changes nothing. `-b` with `--foreground` exits 1 before anything runs. Whoever hosts the daemon hosts the agent: the CLI's detached child, `pinggy daemon service-install`, or the Pinggy app, whose in-process daemon runs the same `runDaemonChild()`. The app reaches it through `TunnelClient.getDeviceAgentStatus()`, `startDeviceAgent()` and `stopDeviceAgent()`.
|
|
505
511
|
|
|
@@ -538,7 +544,7 @@ The daemon's run differs from the foreground one in 3 dependencies, passed throu
|
|
|
538
544
|
| `pinggy device remove` | Stops, and the daemon never starts it again |
|
|
539
545
|
| A terminal outcome | Stops, with `lastError`, and stays stopped until the next `connect` or `login` |
|
|
540
546
|
|
|
541
|
-
**Inside the Pinggy app** `node-pty` resolves inside `app.asar`, where `spawn-helper` is not on real disk, and a spawn without its helper kills the process. `resolveNodePtyRoot()` copies the package out of an `.asar` archive the way it does out of a `pkg` snapshot, and `loadNodePty()` offers a terminal only when `hasExecutableSpawnHelper()` holds.
|
|
547
|
+
**Inside the Pinggy app** `node-pty` resolves inside `app.asar`, where `spawn-helper` is not on real disk, and on macOS a spawn without its helper kills the process. `resolveNodePtyRoot()` copies the package out of an `.asar` archive the way it does out of a `pkg` snapshot, and `loadNodePty()` offers a terminal only when `hasExecutableSpawnHelper()` holds.
|
|
542
548
|
|
|
543
549
|
`IPC_VERSION` stays 1: the routes are additive, and a bump would make every installed app refuse a newer CLI daemon.
|
|
544
550
|
|
|
@@ -564,8 +570,8 @@ The daemon's run differs from the foreground one in 3 dependencies, passed throu
|
|
|
564
570
|
| `src/devices/terminal/frameSplitter.ts` | `FrameSplitter`: bundles pty output into `data` frames at the raw cap derived from `max_frame_bytes`, or after `BUNDLE_MILLIS` |
|
|
565
571
|
| `src/devices/terminal/shellContext.ts` | Each shell's `cwd` and foreground program from the process table: `/proc` on Linux, `ps` and `lsof` on macOS, nothing on Windows. `programName()` keeps the first word, basename only, because a process can write its arguments into its own name. `ShellContextTracker` turns polls into `context` events, only on change |
|
|
566
572
|
| `src/devices/terminal/terminalRegistry.ts` | `TerminalRegistry`: terminal id to pty handle, with the per-device ceiling from `welcome` |
|
|
567
|
-
| `src/devices/terminal/ptySession.ts` | Lazy `node-pty` load, `isTerminalSupported()` (false unless `spawn-helper` can be exec'd), `spawnPty()`, the `spawn-helper` execute-bit repair, `signalForeground()` to the tty's foreground process group |
|
|
568
|
-
| `src/devices/terminal/nodePtyRuntime.ts` | `resolveNodePtyRoot()`: where `node-pty` loads from. Unpacks it onto real disk inside a `pkg` binary or an Electron `.asar` archive. `hasExecutableSpawnHelper()
|
|
573
|
+
| `src/devices/terminal/ptySession.ts` | Lazy `node-pty` load, `isTerminalSupported()` (false unless the addon loads and, on macOS, `spawn-helper` can be exec'd), `spawnPty()`, the `spawn-helper` execute-bit repair, `signalForeground()` to the tty's foreground process group |
|
|
574
|
+
| `src/devices/terminal/nodePtyRuntime.ts` | `resolveNodePtyRoot()`: where `node-pty` loads from. Unpacks it onto real disk inside a `pkg` binary or an Electron `.asar` archive, and replaces a copy with no addon. `hasExecutableSpawnHelper()`, true off macOS |
|
|
569
575
|
| `src/devices/terminal/shellAllowlist.ts` | `resolveShell()`: exact match against `/etc/shells`, or `powershell.exe` and `cmd.exe` on Windows |
|
|
570
576
|
| `src/cli/subcommand/handlers/deviceCommand.ts` | The `login`, `connect`, `stop`, `status`, `remove` verbs, and `--foreground`. `refuseDevicesSpelling()` for the old spelling |
|
|
571
577
|
| `src/utils/helpMessages.ts` | `printDeviceHelp()` |
|
|
@@ -634,7 +640,7 @@ No daemon, or a dead pid in `daemon.json`, sends `daemon_running: false` with th
|
|
|
634
640
|
|
|
635
641
|
### Device tunnel actions
|
|
636
642
|
|
|
637
|
-
`ch: "tunnel"` frames go to `handleTunnelAction()
|
|
643
|
+
`ch: "tunnel"` frames go to `handleTunnelAction()`. The dashboard sends 4 requests, and the agent answers each on its `id` and op with `{tunnel_id, state}`, `{config_id}` for a rewritten saved config, or an error. The agent advertises `tunnel_control` in `hello` for start, stop and restart, `tunnel_update` for update, and `saved_config_update` for an update of a saved config; a dashboard refuses an op to an agent without its capability.
|
|
638
644
|
|
|
639
645
|
| Request | Daemon route | Starts a daemon |
|
|
640
646
|
| --- | --- | --- |
|
|
@@ -655,7 +661,7 @@ Every call goes through an `IPCClient` with origin `device`. With no daemon, a s
|
|
|
655
661
|
|
|
656
662
|
The dashboard answers an unreadable payload with `invalid_payload` on the `device` channel. The agent ignores every non-`system` frame, so that answer is logged at debug and changes nothing.
|
|
657
663
|
|
|
658
|
-
### Terminal (
|
|
664
|
+
### Terminal (open, close, shells that outlive the socket, output, input, screen)
|
|
659
665
|
|
|
660
666
|
`ch: "terminal"` frames go to the run's `TerminalHandler`, never to `handleFrame()`. Output flows up as `data`, and keystrokes flow down as `data`.
|
|
661
667
|
|
|
@@ -681,51 +687,55 @@ The dashboard answers an unreadable payload with `invalid_payload` on the `devic
|
|
|
681
687
|
│ terminal/close event {terminal_id, user_closed} │
|
|
682
688
|
│◀───────────────────────────────────────────────────────┤ only when the shell exits on its own
|
|
683
689
|
│ terminal/snapshot event {terminal_id, snapshot_id} │
|
|
684
|
-
├───────────────────────────────────────────────────────▶│ a tab attached and asks for its screen
|
|
690
|
+
├───────────────────────────────────────────────────────▶│ a tab attached and asks for its screen
|
|
685
691
|
│ terminal/snapshot event {part, last, after_seq, data} │
|
|
686
692
|
│◀───────────────────────────────────────────────────────┤ the screen, to that tab only
|
|
687
693
|
│ terminal/resync event {resync_id, part, after_seq, data}
|
|
688
|
-
│◀───────────────────────────────────────────────────────┤ the latest screen after a skip, to every tab
|
|
694
|
+
│◀───────────────────────────────────────────────────────┤ the latest screen after a skip, to every tab
|
|
689
695
|
│ terminal/activity event {terminal_id, skipped_bytes} │
|
|
690
|
-
│◀───────────────────────────────────────────────────────┤ still busy while skipping, not forwarded
|
|
696
|
+
│◀───────────────────────────────────────────────────────┤ still busy while skipping, not forwarded
|
|
691
697
|
```
|
|
692
698
|
|
|
693
699
|
- **`terminal` is advertised only when `node-pty` loads.** `buildCapabilities(isTerminalSupported())`. The capability is what un-greys the Terminal button, so an agent must never advertise a shell it cannot spawn.
|
|
694
700
|
- **The dashboard validates neither shell nor cwd.** `resolveShell()` is the only check. A requested shell must equal an `/etc/shells` line exactly and exist; no request picks `$SHELL` when it is allowed. A missing cwd falls back to home rather than refusing.
|
|
695
701
|
- **A refusal answers on `opened`** with `{terminal_id, error: {code, message}}`: `invalid_payload`, `terminal_disabled`, `terminal_limit_reached`, `shell_not_allowed`, or `spawn_failed`.
|
|
696
|
-
- **A shell outlives the socket that opened it
|
|
702
|
+
- **A shell outlives the socket that opened it.** `runDeviceAgent()` builds 1 `TerminalHandler` for the whole run. When `connectOnce()` settles, `suspend()` pauses every pty (stops reading its master, so the shell blocks once the kernel buffer fills) and kills none. In skip mode (below) it pauses none. The next `hello` lists them in `terminals`. The dashboard answers `close` with `device_gone` for any it forgot, possibly before `welcome`, and `welcome` calls `resumeAll()`.
|
|
697
703
|
- **Only the agent stopping kills shells.** When the loop ends (interrupted, revoked, refused), `closeAll()` kills them. Killing the agent process reaps them too, through `SIGHUP` when the pty master closes.
|
|
698
704
|
- **A shell that exits while the socket is down sends nothing.** Its `close` has no socket to go to, and the next `hello` simply omits it. The dashboard records that as `device_gone`.
|
|
699
705
|
- **Output is read as raw bytes and sent as base64.** `spawnPty()` passes `encoding: null`, so a read that ends mid-character is not decoded into a replacement character. `FrameSplitter` sends a bundle at the raw cap from `rawBundleBytes(max_frame_bytes)` or after `BUNDLE_MILLIS`, whichever comes first. A frame above `max_frame_bytes` would close the socket, and every other terminal on it.
|
|
700
|
-
- **
|
|
706
|
+
- **Without skip mode, a full window stops the reads, not the sends.** `FlowWindow` counts raw bytes sent minus the browser's cumulative `ack_bytes`, clamped to what was sent. When it reaches the window, the handler pauses the pty and the shell blocks in the kernel. The next `ack` that reopens it resumes reads. Nothing is buffered on the agent.
|
|
701
707
|
- **Ctrl-C is input, not a signal.** It arrives as `data` byte `0x03`, and the pty's line discipline turns it into SIGINT for the foreground process group.
|
|
702
708
|
- **`signal` goes to the foreground process group**, never the shell's pid. `signalForeground()` reads the tty's `tpgid` with `ps` and calls `process.kill(-tpgid)`, falling back to the shell's own group. `node-pty`'s `kill(signal)` signals the pid only, and bash ignores SIGINT while `sleep` holds the terminal. The allowlist is `TERMINAL_SIGNALS`, enforced by the zod schema, so `KILL` and anything else never reach `kill`. Ignored on Windows.
|
|
703
709
|
- **`resize` touches the pty only on an actual change.** Every call is a `TIOCSWINSZ` and a SIGWINCH, and a full-screen program redraws on each.
|
|
704
|
-
- **
|
|
710
|
+
- **Without skip mode, 2 things pause a pty, and neither lifts the other's.** A suspended handler (socket down) and a full window. `resumeAll()` skips a shell whose window is still full, and an `ack` does not resume a shell while the handler is suspended.
|
|
705
711
|
- **The window has no default.** `welcome.terminal_window_bytes` is the only place the number lives. Without it the handler answers every `open` with `terminal_disabled`.
|
|
706
712
|
- **`seq` counts per terminal from 1**, on every `data` frame, for the life of the shell rather than the socket. The dashboard closes a terminal with `sequence_gap` on a hole.
|
|
707
|
-
- **
|
|
708
|
-
- **The window still assumes 1 viewer.**
|
|
709
|
-
- **Every shell keeps its screen
|
|
713
|
+
- **Without skip mode, a bundle cut while the socket is down is held**, not sent into no socket. It takes no `seq` and does not count against the window until `resumeAll()` sends it first. It is at most what was already read when `suspend()` paused the pty.
|
|
714
|
+
- **The window still assumes 1 viewer.** The slowest-viewer rule (the window moves on the slowest viewer's ack) and the 10 s `too_slow` detach are not built. The replay for a late attach is the screen snapshot, below, not a buffer of bytes.
|
|
715
|
+
- **Every shell keeps its screen.** `ScreenMirror` is a headless xterm (`@xterm/headless`, 1000 lines of scrollback) fed each bundle in `sendData`, in the same tick as its `seq`, never when the pty is read: a bundle still being cut would otherwise be in the screen and drawn twice. `snapshot` notes `after_seq` and `after_bytes`, then serialises inside the callback of an empty write queued on the mirror, which xterm runs before it parses anything fed later. The text goes out in parts of the raw bundle size. Parts take no `seq` and never count against the window. Over 1 MB it is serialised again with 200 lines, then with the screen alone, and past that it is not sent. The serialize addon needs `allowProposedApi`.
|
|
710
716
|
- **`terminal_snapshot` is advertised only beside `terminal`**, and only when both xterm packages load. The mirror is memory only, disposed with its shell, never logged and never written to disk.
|
|
711
|
-
- **Output never waits
|
|
712
|
-
- **After `welcome`, a resync at once** for every stream that skipped or had bytes in flight, since frames in flight died with the old socket. A shell that exits while skipping sends 1 last resync, then `exit` and `close`. A
|
|
717
|
+
- **Output never waits.** With `welcome.terminal_resync` and a mirror, `sendOrSkip` replaces the window brake. A bundle cut while the window is closed, the socket is down, or the stream is already skipping is skipped: fed to the mirror, given no `seq`, not sent, not counted against the window. Once every sent byte is acked, and no sooner than `RESYNC_MIN_INTERVAL_MILLIS` (1 s) after the last, the latest screen goes to every tab as `resync` parts, then live `data`. `after_seq` and `after_bytes` are read before the mirror is asked, as for a snapshot. The screen is serialised under the window size, and a screen alone over it still goes, up to 1 MB. The dashboard treats each part as a `seq` barrier.
|
|
718
|
+
- **After `welcome`, a resync at once** for every stream that skipped or had bytes in flight, since frames in flight died with the old socket. A shell that exits while skipping sends 1 last resync, then `exit` and `close`. A snapshot never ends skip mode: it reaches 1 tab.
|
|
713
719
|
- **A bundle cut while a resync is serialised waits** in `resyncHeldBundles`, unfed, and goes out after the parts. Past the window size the held bundles and every later one are skipped, and another resync follows.
|
|
714
720
|
- **The only pause in skip mode is the mirror's.** `ScreenMirror.feed` counts bytes fed and not yet parsed through xterm's write callback. The pty pauses above `MIRROR_HIGH_WATER_BYTES` (1 MB) and resumes under `MIRROR_LOW_WATER_BYTES` (256 KB). That is local CPU, never the network: a loud shell runs at the parse rate, about 22.5 MB/s measured on 2026-11-03.
|
|
715
721
|
- **A skipping shell sends `activity`** with its `skipped_bytes`, at most every `ACTIVITY_REPORT_MILLIS` (60 s), so the dashboard's sweep does not close it as idle. The agent's own idle timer counts every pty read already.
|
|
716
|
-
- **`terminal_resync` is advertised beside `terminal_snapshot`**, on the same condition. A `welcome` without the flag ends skip mode on every shell with no resync, and the shells go back to
|
|
722
|
+
- **`terminal_resync` is advertised beside `terminal_snapshot`**, on the same condition. A `welcome` without the flag ends skip mode on every shell with no resync, and the shells go back to the window brake.
|
|
717
723
|
- **No log line carries a payload.** Ids, pids, and codes only, and an error's class name rather than its message. Input is what a person typed, so it is never logged at any level.
|
|
718
724
|
- `welcome.terminal_enabled` and `welcome.max_terminals_per_device` are optional, so an older dashboard leaves the defaults (enabled, 3).
|
|
719
725
|
|
|
720
726
|
`node-pty` 1.1.0 publishes its macOS `spawn-helper` without the execute bit, and every spawn then fails with `posix_spawnp failed`. `ensureSpawnHelperExecutable()` restores it once, at load.
|
|
721
727
|
|
|
722
|
-
**A packaged binary loads `node-pty` from real disk, not from the snapshot.** `node-pty` does not exec the shell directly. It execs `spawn-helper`, at a path it derives from wherever its own module sits. Inside a `pkg` binary that path is `/snapshot/...`, which only exists in the `fs` module pkg patches, so the kernel cannot exec it and `posix_spawn` fails with `ENOENT`. The throw is fatal inside the addon, so no caller gets to answer for it.
|
|
728
|
+
**A packaged binary loads `node-pty` from real disk, not from the snapshot.** On macOS `node-pty` does not exec the shell directly. It execs `spawn-helper`, at a path it derives from wherever its own module sits. Inside a `pkg` binary that path is `/snapshot/...`, which only exists in the `fs` module pkg patches, so the kernel cannot exec it and `posix_spawn` fails with `ENOENT`. The throw is fatal inside the addon, so no caller gets to answer for it. node-pty builds `spawn-helper` on macOS only: Linux forks the shell with `forkpty()`, and Windows uses ConPTY. `hasExecutableSpawnHelper()` asks for a helper on macOS only.
|
|
723
729
|
|
|
724
730
|
`resolveNodePtyRoot()` copies the package out of the snapshot on first use and returns that path, so every path `node-pty` derives afterwards is a real one. It copies `package.json`, `lib/`, and this platform's native directory only: 41 files and 404 KB. The snapshot carries the native directories of all 4 prebuilt platforms, about 5 MB. The `pkg.ignore` list in `package.json` keeps the package's `.pdb` debug symbols and C++ source, 56 MB, out of the binary. A glob added there must not remove anything else from the 3 copied paths. The copy lands in `~/.config/pinggy/runtime/node-pty-<version>-<platform>-<arch>`, staged under a sibling name and renamed into place, so 2 agents starting at once cannot load a half-written copy. An unpackaged run resolves through `require` as normal and copies nothing.
|
|
725
731
|
|
|
732
|
+
**Linux has no prebuild.** node-pty 1.1.0 ships prebuilds for `darwin-arm64`, `darwin-x64`, `win32-arm64` and `win32-x64`. On Linux `npm ci` compiles `build/Release/pty.node`. node-pty's `files` list leaves `build/` out, and pkg packs only what that list names, so `pkg.assets` names `pty.node`. Linux binaries up to 0.6.5 carried no addon, and their copy holds `package.json` and `lib/` only. `rename(2)` does not replace a directory with files in it, so the unpack deletes a copy with no addon before the rename.
|
|
733
|
+
|
|
734
|
+
The compiled addon needs glibc 2.34 (`forkpty` and `openpty`). The SDK's `libpinggy.so` already needs the system's OpenSSL 3 (`libssl.so.3`), and every distro that ships it has glibc 2.34 or newer, so a build on `ubuntu-latest` narrows nothing. Measured on Debian 10 and 11: the CLI does not start there, because `libssl.so.3` is missing.
|
|
735
|
+
|
|
726
736
|
Not `pkg`'s own cache. `pkg` already unpacks the addon to `~/.cache/pkg/<hash>/` at mode 644, but the hash is undocumented and `node-pty` never looks there.
|
|
727
737
|
|
|
728
|
-
Measured on `macos-arm64` and `macos-x64
|
|
738
|
+
Measured on `macos-arm64` and `macos-x64`, and on `linux-arm64` in Docker (Debian 12 and 13). The `device-agent-terminal` e2e case opens a shell and runs 1 command on all 6 CI platforms.
|
|
729
739
|
|
|
730
740
|
### Outcomes
|
|
731
741
|
|
|
@@ -802,9 +812,9 @@ Without `--foreground` the daemon owns the agent: `ensureDaemonRunning()` may st
|
|
|
802
812
|
|
|
803
813
|
### Not built yet
|
|
804
814
|
|
|
805
|
-
In this repo: terminal input, output, flow control, resize, and signals
|
|
806
|
-
carries `node-pty
|
|
807
|
-
`device/metrics` collectors, and
|
|
815
|
+
In this repo: terminal input, output, flow control, resize, and signals. A `pkg` build that
|
|
816
|
+
carries `node-pty`. The reconnect backoff and pong watchdog, the `device/info` and
|
|
817
|
+
`device/metrics` collectors, and the terminal open and close have all landed. Everything else
|
|
808
818
|
outstanding is dashboard or frontend work.
|
|
809
819
|
|
|
810
820
|
## 18. Reference for AI agents
|
|
@@ -853,7 +863,7 @@ No em-dashes. Short phrases. Present tense. See `CLAUDE.md` § "English Style" b
|
|
|
853
863
|
- The IPC server only listens on `127.0.0.1`. Do not change to `0.0.0.0` without adding authentication. The current design assumes loopback isolation.
|
|
854
864
|
- Every tunnel reconnects without limit. `_createTunnelWithProcessedConfig()` in `TunnelManager.ts` sets `maxReconnectAttempts` to 0 and ignores the value the caller sends. Create, restart and update all pass through it, so the rule covers the CLI, the app, autostart, crash recovery and remote management. libpinggy counts reconnects over the whole tunnel lifetime and does not reset the count after a successful reconnect. Any limit, including the libpinggy default of 20 for an omitted value, stops a long-running tunnel permanently.
|
|
855
865
|
- Do not route `pinggy device --foreground` through the daemon. Without it the daemon runs the agent, and no IPC route takes or returns a token or a server: the daemon reads both from `device.json`. Any local user can reach the IPC port.
|
|
856
|
-
- Do not generalise `src/remote_management/` to serve the device agent. Those files are on the backend
|
|
866
|
+
- Do not generalise `src/remote_management/` to serve the device agent. Those files are on the backend's do-not-touch list (`docs/pinggy-devices/must-not-change.txt`).
|
|
857
867
|
- `device.json` holds a live credential. Any code that writes it goes through `writeDeviceIdentity()`, which keeps the 0600 mode on rewrites.
|
|
858
868
|
|
|
859
869
|
## 19. Quick diagrams
|
|
@@ -948,3 +958,47 @@ No em-dashes. Short phrases. Present tense. See `CLAUDE.md` § "English Style" b
|
|
|
948
958
|
│ Daemon keeps running with t1 still live.
|
|
949
959
|
▼
|
|
950
960
|
```
|
|
961
|
+
|
|
962
|
+
## 20. Auto-update
|
|
963
|
+
|
|
964
|
+
The CLI updates itself from GitHub releases. `pinggy update` does it on request. Every other command can start a detached process, `pinggy --_update-child`, at most once a day. The command never waits for it. Code: `src/update/`.
|
|
965
|
+
|
|
966
|
+
| File | Purpose |
|
|
967
|
+
| --- | --- |
|
|
968
|
+
| `installKind.ts` | How this copy was installed, which decides whether it can replace itself. An unknown location gets a hint and never a write |
|
|
969
|
+
| `updateState.ts` | `update.json`. Every field is optional, and a corrupt file reads as empty |
|
|
970
|
+
| `latestRelease.ts` | The latest tag from the `/releases/latest` redirect, `isReleaseComplete()`, the npm registry, version compare |
|
|
971
|
+
| `binaryUpdater.ts` | `downloadAndVerify()`, `runPinggyBinary()`, `UpdateError` |
|
|
972
|
+
| `updateLock.ts` | `update.lock`. 1 process replaces the binary at a time |
|
|
973
|
+
| `windowsSwap.ts` | Rename swap with retries, the post-swap run, the restore, rollback, cleanup on start |
|
|
974
|
+
| `unixLinkSwap.ts` | Versioned layout, atomic link move, prune, rollback, plain-file conversion |
|
|
975
|
+
| `applyUpdate.ts` | The swap for this install kind, behind 1 interface |
|
|
976
|
+
| `backgroundUpdate.ts` | The gates on every command, the pending notice, starting the detached process |
|
|
977
|
+
| `updateChild.ts` | The detached process |
|
|
978
|
+
|
|
979
|
+
**Layout on macOS and Linux.** `~/.local/bin/pinggy` links to `~/.pinggy/bin/pinggy`, which links to `~/.pinggy/versions/<x.y.z>/pinggy`. The updater moves the 2nd link with a temp link and a rename, because `ln -sf` removes the old link first. No step touches a running binary. A process whose file was pruned keeps its code, and `getDaemonSpawnArgs()` starts any new daemon from the link.
|
|
980
|
+
|
|
981
|
+
**Windows.** A running `.exe` can be renamed but not overwritten. The live file becomes `<live name>.<epochMillis>.old`, the download takes the live name, and `<stem>.prev.exe` holds a copy for rollback. Every file stays in the folder of `execPath`. Each rename retries for 10 seconds, because a scanner can hold a new `.exe` open, and the live path runs once after the swap, because a scanner can remove it.
|
|
982
|
+
|
|
983
|
+
**Verify.** `SHA256SUMS` first, then free space, the download, size, SHA-256, and `--version`. Nothing runs the new file before its hash matches. `runPinggyBinary()` sets `windowsHide` and an empty `PKG_EXECPATH`: pkg adds `PKG_EXECPATH=<execPath>` to every child, and a file at the running binary's own path then reads its first argument as a script.
|
|
984
|
+
|
|
985
|
+
**Background gates, in order.** Not an explicit or print-only command, stdout is a terminal, `PINGGY_AUTO_UPDATE` is not off, not under `sudo` or in a container, the running version parses, not under `_npx`. Any pending notice prints here. Then the last check is over 24 hours old, the last attempt is over 1 hour old, not a dev checkout, no live lock, and `lastAttemptEpochSeconds` is written.
|
|
986
|
+
|
|
987
|
+
**A live daemon.** A daemon keeps the code it started with. The updater reads `--_ipc-version` from the verified file. When a live daemon speaks another IPC version, the background update holds the swap, because the swap would break every daemon command until the user stops all tunnels. This costs 1 download per release.
|
|
988
|
+
|
|
989
|
+
**A release.** `publish-binaries.yml` uploads the 6 binaries, then `SHA256SUMS`. A release with no `SHA256SUMS` is unfinished, and the updater refuses it.
|
|
990
|
+
|
|
991
|
+
**What installed updaters read.** Each installed copy keeps the updater it shipped with, so these never change: the `/releases/latest` redirect, the tag format `vX.Y.Z`, the 6 asset names, `SHA256SUMS` and its format, the `Pinggy CLI version: <x.y.z>` line, the `--_ipc-version` output, and the `update.json` field names.
|
|
992
|
+
|
|
993
|
+
**After a rollback.** Older code reads `daemon-state.json`, `device.json` and saved configs. They carry no version, so they change by adding fields only. A breaking change uses a new file name.
|
|
994
|
+
|
|
995
|
+
**Stopping a bad release.**
|
|
996
|
+
|
|
997
|
+
1. Stop further updates: `gh release delete-asset <bad-tag> SHA256SUMS --repo Pinggy-io/cli-js --yes`.
|
|
998
|
+
2. Send new installs to the last good release: `gh release edit <good-tag> --latest --repo Pinggy-io/cli-js`.
|
|
999
|
+
3. Publish the fix as a higher patch version. Copies on the bad version take it on their next check.
|
|
1000
|
+
4. Tell users on the bad version to run `pinggy update --rollback`.
|
|
1001
|
+
|
|
1002
|
+
Step 3 needs a working updater in the bad build. If the updater is the bug, those users run the install script.
|
|
1003
|
+
|
|
1004
|
+
**Overrides, for dev and tests.** `PINGGY_UPDATE_RELEASES_URL` accepts a loopback `http` URL only.
|
package/CLAUDE.md
CHANGED
|
@@ -25,11 +25,12 @@ node test/e2e/run.cjs out/pinggy-<platform>
|
|
|
25
25
|
|
|
26
26
|
### Two-process model
|
|
27
27
|
|
|
28
|
-
The CLI binary has
|
|
28
|
+
The CLI binary has 4 entry modes, dispatched in `src/main.ts`:
|
|
29
29
|
|
|
30
30
|
1. **Daemon child** (`--_daemon-child` flag). Calls `runDaemonChild()` in `src/daemon/daemonChild.ts`. The CLI re-execs itself with this flag when it needs to spawn a daemon; users never invoke it directly.
|
|
31
|
-
2. **Subcommand** (`config`, `start`, `stop`, `ps`, `attach`, `daemon`, `d`, `device`, `devices`). Routes to `handleSubcommand()` in `src/cli/subcommands.ts`.
|
|
31
|
+
2. **Subcommand** (`config`, `start`, `stop`, `ps`, `attach`, `daemon`, `d`, `device`, `devices`, `update`). Routes to `handleSubcommand()` in `src/cli/subcommands.ts`.
|
|
32
32
|
3. **Legacy single-tunnel** (no subcommand). Routes to `buildAndStartTunnel()` for flags like `-l 3000` or `-R0:localhost:3000`.
|
|
33
|
+
4. **Update child** (`--_update-child` flag). Calls `runUpdateChild()` in `src/update/updateChild.ts`. A command starts it at most once a day, detached, to check for a release and install it.
|
|
33
34
|
|
|
34
35
|
The daemon owns the `TunnelManager` singleton, the `@pinggy/pinggy` SDK, the web debugger server, and any `--serve` file servers. The CLI owns argument parsing, the TUI, the remote-management WebSocket client, and the IPC client to the daemon.
|
|
35
36
|
|
|
@@ -48,7 +49,7 @@ CLI code calls `TunnelClient` (`src/daemon/tunnelClient.ts`), the public facade
|
|
|
48
49
|
|
|
49
50
|
Single daemon per user. State lives under `~/.config/pinggy/` on Linux/macOS or `%APPDATA%/pinggy/` on Windows (helper: `src/utils/configDir.ts`):
|
|
50
51
|
|
|
51
|
-
- `daemon.json`: `{pid, port, startedAt, host, ipcVersion}`. `ipcVersion` is `IPC_VERSION` from `src/daemon/ipc/ipcRoutes.ts`. `ensureDaemonRunning()` refuses a live daemon whose version differs and tells the user to run `pinggy daemon stop`. Bump `IPC_VERSION` on any incompatible IPC or WebSocket change.
|
|
52
|
+
- `daemon.json`: `{pid, port, startedAt, host, ipcVersion, cliVersion}`. `cliVersion` is the version the daemon started with, and never follows the installed binary. `ipcVersion` is `IPC_VERSION` from `src/daemon/ipc/ipcRoutes.ts`. `ensureDaemonRunning()` refuses a live daemon whose version differs and tells the user to run `pinggy daemon stop`. Bump `IPC_VERSION` on any incompatible IPC or WebSocket change. After an update the CLI is newer than the daemon, often for weeks, so a new IPC route or WebSocket frame needs a capability check or an `IPC_VERSION` bump.
|
|
52
53
|
- `daemon.lock`: `{pid, started_at}` of the running daemon (`src/daemon/lifecycle/daemonLock.ts`). Each daemon takes it before it opens its IPC port, and a daemon that finds a live holder exits 0. systemd and launchd run `--_daemon-child` directly, and 2 CLIs can spawn at once, so the CLI's `daemon.json` check alone does not keep 1 daemon.
|
|
53
54
|
- `daemon-state.json`: detached tunnel configs, for crash recovery (`src/daemon/lifecycle/stateStore.ts`). Deleted on clean shutdown; replayed on next start.
|
|
54
55
|
- `daemon-config.json`: settings that survive a clean shutdown (`src/daemon/lifecycle/daemonConfig.ts`): the log level, and `deviceAgent`, set while the background device agent should run. Every daemon start runs that agent. `pinggy device remove` deletes it. `pinggy device stop` keeps it, so the agent starts again with the next daemon.
|
|
@@ -72,15 +73,15 @@ Single daemon per user. State lives under `~/.config/pinggy/` on Linux/macOS or
|
|
|
72
73
|
|
|
73
74
|
`pinggy devices`, the old spelling, stays a subcommand that prints the new one and exits 1 (`refuseDevicesSpelling()`). Do not remove `Subcommand.Devices`: without it `devices` falls to legacy tunnel mode, where `--token` is the tunnel token, so `pinggy devices connect --token pga_...` would send the device token to the tunnel server.
|
|
74
75
|
|
|
75
|
-
It owns no tunnel.
|
|
76
|
+
It owns no tunnel. It reads the daemon's `GET /tunnels` through `IPCClient` and the saved configs, to send `device/tunnels` (`src/devices/tunnels/tunnelList.ts`), and listing never starts a daemon. It stops, restarts and starts tunnels when the dashboard asks (`src/devices/tunnels/tunnelActions.ts`), through `IPCClient` with the `device` origin; only a start of a config may call `ensureDaemonRunning()`. It also applies an updated dashboard config to the tunnel running it, through the daemon's `update-config-v2`, and it rewrites a saved config's file when the dashboard edits it (`upsertConfig()`, no daemon). `pinggy device login` signs the machine in by email over plain HTTPS (`src/devices/login/`), writes `device.json`, then runs the same agent; the sign-in can also be approved from the email's link, and the poll collects it. No `TunnelManager`. It also does not reuse `src/remote_management/`, which is a tunnel controller keyed by an API key rather than the machine keyed by a device token. Frames use a versioned envelope (`src/devices/envelope.ts`) validated with zod (`src/devices/device_schema.ts`); an unknown `ch` or `op` is ignored, never fatal.
|
|
76
77
|
|
|
77
|
-
`pinggy device connect` and `login` run the agent in the daemon, as `pinggy start -b` runs a tunnel there, so it outlives the terminal
|
|
78
|
+
`pinggy device connect` and `login` run the agent in the daemon, as `pinggy start -b` runs a tunnel there, so it outlives the terminal. `--foreground` runs it in the CLI process instead, until Ctrl+C. `-b` still parses and changes nothing; `-b` with `--foreground` exits 1. `--foreground` sits hidden in `cliOptions`, because `main.ts` parses the whole command line with it, strict, before it dispatches. Whoever hosts the daemon, the CLI's child or the Pinggy app, hosts the agent (`src/daemon/deviceAgentHost.ts`, `src/devices/backgroundAgent.ts`). `GET /device`, `POST /device/start` and `POST /device/stop` reach it, and `TunnelClient` exposes them for the app. No IPC route takes or returns a token or a server: the daemon reads both from `device.json`, and a new token is checked in the CLI with 1 handshake before the daemon sees it. Once the daemon starts the agent, the CLI prints the commands that manage it (`status`, `stop`, `connect`, `remove`). `pinggy device stop` stops it. A `--foreground` `connect` or `login` refuses while it runs. The loop prints nothing itself: it calls a `DeviceAgentReporter`, and the foreground's prints the same lines as before.
|
|
78
79
|
|
|
79
80
|
1 invocation runs 1 subcommand: `isSubcommand()` reads `rawArgs[0]` only, so `pinggy device connect start my-tunnel` runs the agent and drops the rest, and tunnel flags on a `device` line parse and are ignored, except `-b` and `--foreground`.
|
|
80
81
|
|
|
81
|
-
|
|
82
|
+
`scripts/install/install.sh` installs into `~/.pinggy/versions/<version>/` and points the link `~/.pinggy/bin/pinggy` at it. `install.sh` and `install.ps1` install or update the binary, put it on PATH, then ask "Connect this device to Pinggy? [Y/n]" and run `pinggy device login -b` unless the answer starts with `n`. `-b` is the default, and the scripts pass it so an older binary the user kept also runs the agent in its daemon. pinggy.io serves copies that `website-cli-download-links-pr.yml` writes at each release tag. Renaming a release asset, changing the `Pinggy CLI version:` line, or changing `device login`'s `--manage` or `-b` flag means changing both scripts in the same commit. `DEVICE_AGENT_TOKEN` on either script updates without asking and runs `pinggy device connect -b` instead, with the token in the environment, never on a command line. `handleDevice()` deletes the variable from `process.env` before any verb runs, so no shell or daemon the agent starts inherits it. Renaming the variable or `connect`'s `--manage` or `-b` flag also changes both scripts in the same commit. `pinggy daemon service-install` runs only from the path the scripts install to (`installerBinaryPath()` in `src/daemon/lifecycle/serviceInstaller.ts`), so changing either script's install directory changes that function in the same commit. Once the device connects, both scripts offer `pinggy daemon service-install` unless the service exists. They look for the task name, plist or unit file that `serviceInstaller.ts` writes, and the installed binary's path in it, so renaming any of them changes both scripts in the same commit.
|
|
82
83
|
|
|
83
|
-
Section 17 of `ARCHITECTURE.md` has the protocol, the retry and terminal outcome table, the `device.json` rules, and the full composition table. The design docs are in the `pinggy_backend` repo under `docs/pinggy-devices/`; read `cli.md`
|
|
84
|
+
Section 17 of `ARCHITECTURE.md` has the protocol, the retry and terminal outcome table, the `device.json` rules, and the full composition table. The design docs are in the `pinggy_backend` repo under `docs/pinggy-devices/`; read `cli.md` there before changing anything in `src/devices/`.
|
|
84
85
|
|
|
85
86
|
**Core types** are in `src/types.ts`: `TunnelStatus`, `Status`, `TunnelStateType` enum (`idle/starting/running/live/closed/exited`), `FinalConfig` (extends SDK's `TunnelConfigurationV1`). Browse `src/daemon/` and `src/cli/` for the rest of the module layout.
|
|
86
87
|
|
|
@@ -94,13 +95,22 @@ Section 17 of `ARCHITECTURE.md` has the protocol, the retry and terminal outcome
|
|
|
94
95
|
| `pinggy ps` | Table of running tunnels (ID, name, status, local, URL) |
|
|
95
96
|
| `pinggy attach <name\|id>` | Re-attach TUI to a running tunnel |
|
|
96
97
|
| `pinggy daemon start \| stop \| status \| service-install \| service-uninstall` (alias `d`) | Daemon lifecycle and system-service installation |
|
|
98
|
+
| `pinggy update [--check \| --rollback]` | Update to the latest release now, print the latest version and change nothing, or go back to the previous version. A background check starts on its own; `PINGGY_AUTO_UPDATE=false` turns it off |
|
|
97
99
|
| `pinggy device login \| connect [--foreground] \| stop \| status \| remove [-f]` | Sign this machine in by email, or enrol it with a token, as a Pinggy device; the agent runs in the daemon, or in this terminal with `--foreground`, and `stop` stops the daemon's; show the enrolment and the background agent; show the device and its connection, ask, then stop every agent and forget the credential (`-f` skips the question) |
|
|
98
100
|
|
|
101
|
+
### Auto-update
|
|
102
|
+
|
|
103
|
+
`src/update/` updates the CLI from GitHub releases. Section 20 of `ARCHITECTURE.md` has the flow. 3 rules hold for every change:
|
|
104
|
+
|
|
105
|
+
- Each installed copy keeps the updater it shipped with, so these never change: the `/releases/latest` redirect, the tag format `vX.Y.Z`, the 6 asset names, `SHA256SUMS` and its format, the `Pinggy CLI version: <x.y.z>` line, the `--_ipc-version` output, and the `update.json` field names.
|
|
106
|
+
- A rollback runs older code against `daemon-state.json`, `device.json` and saved configs, so they change by adding fields only.
|
|
107
|
+
- `SHA256SUMS` is the last upload of a release. A release that has it counts as complete.
|
|
108
|
+
|
|
99
109
|
## Build System
|
|
100
110
|
|
|
101
111
|
tsup bundles to `dist/` (CJS + ESM). tsc type-checks only (`npm run build:tsc`). pkg builds standalone platform binaries (`out/pinggy-<platform>`). ts-jest with the ESM preset for unit tests (`jest.config.cjs`).
|
|
102
112
|
|
|
103
|
-
pkg packs every file in a dependency's `files` list and every package in its `dependencies`, whether the code loads it or not. The `pkg.ignore` list in `package.json` keeps out what the binary never loads: node-pty's `.pdb` debug symbols and C++ source, the SDK's unlinked `libcrypto.dylib` and `libssl.dylib` copies, the SDK's install-time `node-gyp` and `@mapbox/node-pre-gyp`, and zod's `src/` and `v3/`. A new glob must not match node-pty's `package.json`, `lib/`, or any file under `prebuilds/` other than a `.pdb`: `resolveNodePtyRoot()` copies those out of the snapshot at runtime. The `**` in these globs does not match a folder whose name starts with a dot, so a checkout under such a path (`~/.work/cli-js`) ignores nothing and builds the full-size binary. `"compress": "Brotli"` compresses the snapshot: on macOS arm64 the binary drops from 83 MB to 59 MB, and each run starts about 80ms later.
|
|
113
|
+
pkg packs every file in a dependency's `files` list and every package in its `dependencies`, whether the code loads it or not. The `pkg.ignore` list in `package.json` keeps out what the binary never loads: node-pty's `.pdb` debug symbols and C++ source, the SDK's unlinked `libcrypto.dylib` and `libssl.dylib` copies, the SDK's install-time `node-gyp` and `@mapbox/node-pre-gyp`, and zod's `src/` and `v3/`. A new glob must not match node-pty's `package.json`, `lib/`, `build/Release/pty.node`, or any file under `prebuilds/` other than a `.pdb`: `resolveNodePtyRoot()` copies those out of the snapshot at runtime. node-pty has no Linux prebuild, so on Linux `npm ci` compiles `build/Release/pty.node`. Its `files` list leaves `build/` out, so `pkg.assets` names that file. Without it the Linux binary offers no terminal. The `**` in these globs does not match a folder whose name starts with a dot, so a checkout under such a path (`~/.work/cli-js`) ignores nothing and builds the full-size binary. `"compress": "Brotli"` compresses the snapshot: on macOS arm64 the binary drops from 83 MB to 59 MB, and each run starts about 80ms later.
|
|
104
114
|
|
|
105
115
|
## Testing
|
|
106
116
|
|
|
@@ -2,10 +2,11 @@ import {
|
|
|
2
2
|
TunnelAlreadyRunningError,
|
|
3
3
|
TunnelManager,
|
|
4
4
|
TunnelRebuildInProgressError
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-3WMTTJHI.js";
|
|
6
6
|
import "./chunk-UB26QJ4T.js";
|
|
7
|
-
import "./chunk-
|
|
8
|
-
import "./chunk-
|
|
7
|
+
import "./chunk-HTIWY3O5.js";
|
|
8
|
+
import "./chunk-LWCVB42S.js";
|
|
9
|
+
import "./chunk-MAK5R4WQ.js";
|
|
9
10
|
export {
|
|
10
11
|
TunnelAlreadyRunningError,
|
|
11
12
|
TunnelManager,
|
|
@@ -3,12 +3,13 @@ import {
|
|
|
3
3
|
} from "./chunk-XZ64ZAGO.js";
|
|
4
4
|
import {
|
|
5
5
|
TunnelManager
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-3WMTTJHI.js";
|
|
7
7
|
import "./chunk-UB26QJ4T.js";
|
|
8
|
+
import "./chunk-HTIWY3O5.js";
|
|
8
9
|
import {
|
|
9
10
|
logger
|
|
10
|
-
} from "./chunk-
|
|
11
|
-
import "./chunk-
|
|
11
|
+
} from "./chunk-LWCVB42S.js";
|
|
12
|
+
import "./chunk-MAK5R4WQ.js";
|
|
12
13
|
|
|
13
14
|
// src/tui/blessed/TunnelTui.ts
|
|
14
15
|
import blessed3 from "blessed";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
logger
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-LWCVB42S.js";
|
|
4
4
|
import {
|
|
5
5
|
ensureTunnelConfigDir,
|
|
6
6
|
getTunnelConfigDir
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-MAK5R4WQ.js";
|
|
8
8
|
|
|
9
9
|
// src/cli/configStore.ts
|
|
10
10
|
import fs from "fs";
|
|
@@ -36,6 +36,7 @@ var Subcommand = {
|
|
|
36
36
|
Log: "log",
|
|
37
37
|
Restart: "restart",
|
|
38
38
|
Device: "device",
|
|
39
|
+
Update: "update",
|
|
39
40
|
// The old spelling, refused with a hint. As a subcommand it never reaches tunnel mode, where `--token` is the
|
|
40
41
|
// tunnel token and a device token would go to the tunnel server.
|
|
41
42
|
Devices: "devices"
|