pinggy 0.6.10 → 0.7.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/ARCHITECTURE.md +36 -21
- package/CLAUDE.md +8 -5
- package/README.md +32 -4
- package/dist/{chunk-AYU3GM4D.js → chunk-2IPBK3RG.js} +173 -133
- package/dist/{chunk-3IPMFCEF.js → chunk-QUVQ7ODD.js} +1 -0
- package/dist/{chunk-G3NF35JY.js → chunk-ZSED6OIR.js} +3050 -266
- package/dist/{configStore-6LCHFPQX.js → configStore-VDPOPFLJ.js} +1 -1
- package/dist/{daemonChild-4ZZ3YQDL.js → daemonChild-5HZFQLQR.js} +3 -3
- package/dist/index.cjs +3417 -459
- package/dist/index.js +4 -4
- package/dist/{main-3D7R75PR.js → main-M4BTDE2A.js} +3 -3
- package/dist/{updateChild-ZOC3VGJL.js → updateChild-CEVYCBED.js} +1 -1
- package/package.json +2 -1
- package/scripts/install/install.ps1 +12 -10
- package/scripts/install/install.sh +21 -14
package/ARCHITECTURE.md
CHANGED
|
@@ -11,7 +11,7 @@ The `pinggy` binary has three execution modes, dispatched in `src/main.ts`:
|
|
|
11
11
|
| Mode | Trigger | Entry | Purpose |
|
|
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
|
-
| 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`,
|
|
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`, `devices`, which prints the new spelling, `update`, and `autostart`. |
|
|
15
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. |
|
|
16
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:...`. |
|
|
17
17
|
|
|
@@ -290,7 +290,7 @@ A restore can be cut short by the next crash, and a host that restarts the daemo
|
|
|
290
290
|
|
|
291
291
|
Auto-start tunnels are independent of crash recovery. They come from saved configs marked `autoStart: true` (`getAutoStartConfigs()`), not from the state file. `runDaemonChild({ skipAutoStart: true })` leaves them out: a host sets it when it restarts a daemon after a crash, so an auto-start tunnel the user had stopped stays stopped.
|
|
292
292
|
|
|
293
|
-
The background device agent is not in this file either. `deviceAgent` (`{startedAt, startedBy}`) in `daemon-config.json` survives a clean shutdown, so every daemon start runs the agent: after a crash, a `pinggy daemon stop`, or a reboot with `pinggy
|
|
293
|
+
The background device agent is not in this file either. `deviceAgent` (`{startedAt, startedBy}`) in `daemon-config.json` survives a clean shutdown, so every daemon start runs the agent: after a crash, a `pinggy daemon stop`, or a reboot with `pinggy autostart on`. See section 17.
|
|
294
294
|
|
|
295
295
|
## 9. Tunnel lifecycle end-to-end
|
|
296
296
|
|
|
@@ -369,7 +369,7 @@ src/
|
|
|
369
369
|
│ ├── buildAndStartTunnel.ts Legacy single-tunnel path
|
|
370
370
|
│ ├── buildConfig.ts CLI flags + positionals → FinalConfig
|
|
371
371
|
│ ├── configStore.ts Persisted saved-config CRUD
|
|
372
|
-
│ ├── daemonCommands.ts `pinggy daemon start|stop|status
|
|
372
|
+
│ ├── daemonCommands.ts `pinggy daemon start|stop|status`, and the old service verbs
|
|
373
373
|
│ ├── attachCommand.ts `pinggy attach`
|
|
374
374
|
│ ├── psCommand.ts `pinggy ps`
|
|
375
375
|
│ ├── stopCommand.ts `pinggy stop`
|
|
@@ -490,15 +490,25 @@ CLI logs (the short-lived foreground process) go to stdout by default. The daemo
|
|
|
490
490
|
|
|
491
491
|
Same code path as user-typed subcommands: the daemon does not know or care that the request came from remote management.
|
|
492
492
|
|
|
493
|
-
## 16. Service installation
|
|
493
|
+
## 16. Service installation (`pinggy autostart`)
|
|
494
494
|
|
|
495
|
-
`pinggy
|
|
495
|
+
`pinggy autostart on` writes a platform-specific boot entry and enables it. `pinggy autostart off` removes it and stops nothing. `pinggy device remove` removes it too. Code: `src/daemon/lifecycle/serviceInstaller.ts` (the entry), `src/devices/autostart.ts` (the command). `pinggy daemon service-install` and `service-uninstall`, the old names, print the new command and exit 1 (`renamedDaemonVerbMessage()`).
|
|
496
496
|
|
|
497
|
-
|
|
498
|
-
- macOS: launchd `LaunchAgent` at `~/Library/LaunchAgents/io.pinggy.agent.plist`. `launchctl load`.
|
|
499
|
-
- Windows: Task Scheduler task `PinggyDaemon`, created with `schtasks /Create` and no admin rights. A logon trigger for the current user runs `<binary> daemon start`. `daemon start` spawns `--_daemon-child` detached with `windowsHide`, then exits. The task does not run `--_daemon-child` directly: `pinggy.exe` is a console program, so Task Scheduler opens a console window for it, and closing that window kills the daemon. The `daemon start` window shows for about 1s. The task ends once the daemon is up, so uninstall stops the daemon over IPC. It deletes the task first, so a failed delete leaves the daemon running. With no task, it stops nothing. A task created from an Administrator terminal keeps admin-only permissions, so a normal terminal cannot replace or delete it. When `schtasks` fails, the task exists, and `whoami /groups` shows no High or System integrity SID, pinggy tells the user to run the command from an Administrator terminal. It checks the SID, not the "Access is denied" text, because `schtasks` prints that text in the Windows language.
|
|
497
|
+
A restart brings the device back only when the boot entry and the saved agent (`deviceAgent` in `daemon-config.json`, section 17) both exist. `isAutostartOn()` checks both, for `autostart status` and the `Autostart` row of `pinggy device status`. `on` runs in this order, and a failed step writes no entry:
|
|
500
498
|
|
|
501
|
-
|
|
499
|
+
1. No `device.json`: refuse, naming `pinggy device login`.
|
|
500
|
+
2. `serviceInstallRefusal()`: the npm copy, or a binary that is not the installed one.
|
|
501
|
+
3. No saved agent: refuse while a `--foreground` agent runs. With no terminal, refuse and name `pinggy device start`. Otherwise ask "Start it now, and each time this computer starts? [Y/n]". Yes runs the `pinggy device start` path, which saves the agent.
|
|
502
|
+
4. An entry that already runs `serviceProgramPath()`: print "already on" and change nothing. `bootEntryProgram()` reads the program back from the unit, the plist or `schtasks /Query /XML`.
|
|
503
|
+
5. Write the entry and start it.
|
|
504
|
+
|
|
505
|
+
`off` never stops the daemon. Run from the dashboard's browser terminal, a stop would end that terminal and take the device offline. The device stays online until the next restart, and `pinggy device stop` takes it offline now.
|
|
506
|
+
|
|
507
|
+
- Linux: systemd user unit at `~/.config/systemd/user/pinggy.service`. `Type=simple`, runs `<binary> --_daemon-child` directly (no fork). `systemctl --user enable`, then `start`, which leaves a running unit alone. A user unit starts at sign-in, so `on` then runs `loginctl enable-linger <user>`, unless `loginctl show-user` reports `Linger=yes`. Lingering starts the user's units at boot, with nobody signed in. When the command fails, as on a system that wants an admin password for it, `on` prints the command and still exits 0. `off` runs `disable`, deletes the unit and runs `daemon-reload`, with no `stop`: systemd keeps a running unit whose file is gone until it exits. `off` leaves lingering on, because it belongs to the user and other units may need it.
|
|
508
|
+
- macOS: launchd `LaunchAgent` at `~/Library/LaunchAgents/io.pinggy.agent.plist`. Starts at sign-in. `on` runs `launchctl bootstrap gui/<uid>`, or `kickstart` without `-k` when the job is still loaded after an `off`, and never `bootout`, which would stop the job's daemon. `off` deletes the plist only: launchd keeps the job loaded until sign-out, and the next sign-in finds no plist.
|
|
509
|
+
- Windows: Task Scheduler task `PinggyDaemon`, created with `schtasks /Create` and no admin rights. Starts at sign-in. A logon trigger for the current user runs `<binary> daemon start`. `daemon start` spawns `--_daemon-child` detached with `windowsHide`, then exits. The task does not run `--_daemon-child` directly: `pinggy.exe` is a console program, so Task Scheduler opens a console window for it, and closing that window kills the daemon. The `daemon start` window shows for about 1s. `off` deletes the task and leaves the daemon running. A task created from an Administrator terminal keeps admin-only permissions, so a normal terminal cannot replace or delete it. When `schtasks` fails, the task exists, and `whoami /groups` shows no High or System integrity SID, pinggy tells the user to run the command from an Administrator terminal. It checks the SID, not the "Access is denied" text, because `schtasks` prints that text in the Windows language.
|
|
510
|
+
|
|
511
|
+
The entry stores the full path of the binary (`process.execPath`). If the user moves or deletes that file, the entry fails at login with no message. So `on` writes it only from the path the install scripts write: `%LOCALAPPDATA%\Pinggy\bin\pinggy.exe` on Windows, `~/.pinggy/bin/pinggy` on Linux and macOS (`installerBinaryPath()`). The scripts update the binary in place, so the stored path stays valid. From any other path it prints the install script command and exits 1. From an npm install it prints `npm uninstall -g pinggy` first, because the install script updates an npm copy with npm. The message names no paths, except when the installed copy exists: then it names that copy and the command to run with it, because a downloaded binary can install itself and then run `autostart on` in the same process. `PINGGY_SERVICE_ANY_LOCATION=1` skips the path check, for development and CI. It does not allow npm installs. `off` runs from any path. On Linux and macOS, `on` starts the service at once, and the service runs `--_daemon-child`. When a daemon already runs, for example after `pinggy device login`, the service's daemon finds `daemon.lock` held and exits 0, so 1 daemon and 1 device agent stay. On Windows the task runs `daemon start`, which finds the running daemon and exits. Changing the install directory in either script means changing `installerBinaryPath()` in the same commit.
|
|
502
512
|
|
|
503
513
|
A system service gives restart-on-failure and start-at-login. The plain daemon mode does not.
|
|
504
514
|
|
|
@@ -510,13 +520,13 @@ The one long-lived surface that is not a tunnel. `pinggy device connect` enrols
|
|
|
510
520
|
|
|
511
521
|
**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.
|
|
512
522
|
|
|
513
|
-
**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 the version to install from `https://pinggy.io/cli/version.json`, never from GitHub's `/releases/latest`. The website builds that file from `data/cli_releases.yaml`, and the release PR changes that list and both scripts in 1 commit, so the script and the binary come from 1 release. When pinggy.io does not answer, or the file has no `x.y.z` in its `version` field, the scripts exit 1 with a message that names the URL and `PINGGY_VERSION`. `PINGGY_VERSION` skips the request. The binary still downloads from the GitHub release. `install.sh` reads the field with `sed`, so the key stays `version` with a quoted value. 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
|
|
523
|
+
**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 the version to install from `https://pinggy.io/cli/version.json`, never from GitHub's `/releases/latest`. The website builds that file from `data/cli_releases.yaml`, and the release PR changes that list and both scripts in 1 commit, so the script and the binary come from 1 release. When pinggy.io does not answer, or the file has no `x.y.z` in its `version` field, the scripts exit 1 with a message that names the URL and `PINGGY_VERSION`. `PINGGY_VERSION` skips the request. The binary still downloads from the GitHub release. `install.sh` reads the field with `sed`, so the key stays `version` with a quoted value. 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 autostart on`. A script run with `PINGGY_VERSION` set to a release before `pinggy autostart` gets "Could not turn on autostart" there, and the install still succeeds. The question says "starts" for users. On macOS and Windows the service starts pinggy after the user signs in, not at boot. On Linux it starts at boot, because `on` turns on lingering. 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 `on` replaces it. `install.sh` also skips it on Linux with no systemd user manager. With no terminal, they print the `pinggy autostart on` 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. Before each request the user waits on, both scripts print what it does: `Checking the latest version of Pinggy...` before `version.json`, and `Checking the latest version of pinggy on npm...` before `npm view`. Each request has a stall check and no limit on its total time. curl gets `--speed-limit 1 --speed-time 60`: it gives up when less than 1 byte per second arrives for 60 s. wget gets `--read-timeout=60 --tries=2`. The OS still ends a connection attempt with no answer, and curl a stalled TLS handshake after 5 min. Windows PowerShell 5.1 has no stall check, so `install.ps1` gives the version request `-TimeoutSec 60` and the binary download no limit. `install.sh` prints `Downloading pinggy <version> for <os>-<cpu>` and runs the download in the background. With a terminal on stderr, it rewrites 1 line each second, ` 23.4 MB of 61.5 MB (38%)`. The total comes from the `Content-Length` of the 2xx response in the file curl writes with `-D`, since GitHub's redirect sends `Content-Length: 0` first. curl's own `--progress-bar` drew an unknown-size animation during that redirect, and drew 79 columns under `curl | sh`, which gives curl no terminal width. curl's errors go to a file and print after the line ends. wget shows the size with no total. `install.ps1` downloads with no progress line. After the install, before the sign-in, both scripts offer a daemon restart. They read `pid`, `host` and `cliVersion` from `daemon.json`. When the pid runs `--_daemon-child`, `host` is not `app`, and `cliVersion` differs from what the copy they sign in with prints, they ask "Restart it with <version>? [Y/n]". Yes restarts the daemon the way `serviceRestartInstruction()` names: `launchctl kickstart -k gui/<uid>/io.pinggy.agent` when launchd's process is the daemon, `systemctl --user restart pinggy` when systemd's is. Otherwise, and always on Windows, they run `pinggy daemon stop`, wait up to 10 s for the pid to end, and run `pinggy daemon start`. The restart runs without `DEVICE_AGENT_TOKEN`, because a daemon copies the environment of the command that starts it. Then they read `daemon.json` again and print `The pinggy daemon now runs <version>.` or the restart command. No, or no terminal, restarts nothing and prints the restart command. Tunnels started with `-b` or from the dashboard stop with the old daemon, because a clean stop deletes `daemon-state.json`. Auto-start tunnels and the device agent start again. `PINGGY_INSTALL_ONLY=1` skips the question. Lint with `shellcheck -s sh` and `PSScriptAnalyzer`.
|
|
514
524
|
|
|
515
|
-
**Which copy the scripts update.** Both scripts update the copy that the `pinggy` command runs in that terminal: `command -v pinggy` with every link resolved in `install.sh` (a `readlink` loop and `cd -P`, since macOS before 13 has no `realpath`), and the first `Get-Command pinggy` in `install.ps1`. No copy, or the scripts' own binary, gets the binary flow above. An npm copy is a real path under `<prefix>/lib/node_modules/pinggy/`, or on Windows a launcher folder that holds `node_modules\pinggy\package.json` and no junction there. The scripts update it with `npm install -g --prefix <prefix> pinggy@<version>`, with the version from `npm view pinggy version`, because npm publishes in a separate job. `--prefix` updates that copy even when the `npm` on PATH uses another global folder. The npm flow writes no binary and no PATH, signs in with npm's copy by full path (`pinggy.cmd` on Windows, since an execution policy can block `pinggy.ps1`), and skips the login service question with no message, because `
|
|
525
|
+
**Which copy the scripts update.** Both scripts update the copy that the `pinggy` command runs in that terminal: `command -v pinggy` with every link resolved in `install.sh` (a `readlink` loop and `cd -P`, since macOS before 13 has no `realpath`), and the first `Get-Command pinggy` in `install.ps1`. No copy, or the scripts' own binary, gets the binary flow above. An npm copy is a real path under `<prefix>/lib/node_modules/pinggy/`, or on Windows a launcher folder that holds `node_modules\pinggy\package.json` and no junction there. The scripts update it with `npm install -g --prefix <prefix> pinggy@<version>`, with the version from `npm view pinggy version`, because npm publishes in a separate job. `--prefix` updates that copy even when the `npm` on PATH uses another global folder. The npm flow writes no binary and no PATH, signs in with npm's copy by full path (`pinggy.cmd` on Windows, since an execution policy can block `pinggy.ps1`), and skips the login service question with no message, because `pinggy autostart on` refuses the npm version. A broken npm copy, one that prints no `Pinggy CLI version:` line, gets "Reinstall it with npm? [Y/n]". On macOS and Linux, a folder the user cannot write stops the script with the `sudo npm install -g --prefix` command. On Windows, when the update fails while `%APPDATA%\pinggy\daemon.json` names a live process, `install.ps1` asks "pinggy is running. Stop it and all its tunnels, then retry? [Y/n]". With no terminal that answer is no. A program file the scripts did not install, such as a binary downloaded by hand, gets "Install the latest pinggy, <version>, to ~/.pinggy/bin/pinggy? [Y/n]". No signs in with that file and skips the login service question. A script file, one that starts with `#!` (`npm link`, pnpm, yarn, bun), stops the script with exit 1 and names the command's path. bun's Windows launcher is a `pinggy.exe` beside a `pinggy.bunx`, and counts as a script. `PINGGY_BINARY_URL` skips the check and installs that file.
|
|
516
526
|
|
|
517
527
|
**A downloaded binary installs itself.** `offerSelfInstall()` in `src/install/selfInstall.ts` runs in `main.ts` before the background update. A packaged binary that is not the installed copy (`UnixLayout` or `UnixPlainFile`, or on Windows any file in `%LOCALAPPDATA%\Pinggy\bin`) asks 1 question when stdin and stdout are terminals. With nothing installed, or when `pinggy` runs a copy it cannot remove (`npm link`, pnpm, yarn, bun, another binary): "Install this pinggy, X, to ~/.pinggy/bin/pinggy? [Y/n]". With the scripts' binary installed, whatever its version: "pinggy X is installed in ~/.pinggy/bin/pinggy. Replace it with this pinggy, Y? [Y/n]". When `pinggy` runs an npm copy, whatever its version: "pinggy X is installed with npm. Remove it, and install this pinggy, Y, to ~/.pinggy/bin/pinggy? [Y/n]". The versions are printed and never compared, so an older file can replace a newer install, and the same version asks again. `src/install/pinggyOnPath.ts` finds the copy with the scripts' npm rules and never counts the current folder. No question for `--version`, `--help` or `pinggy update`, under sudo, in a container, while `update.lock` is held, when `update.json` cannot be written, or for a file and version the user said `n` to (`declinedInstallPath`, `declinedInstallVersion`). Yes copies the install script the binary carries in `pkg.assets` to a private temp folder and runs it with `PINGGY_BINARY_URL` naming this file and `PINGGY_INSTALL_ONLY=1`, which ends the script after the install, with no sign-in and no PATH warning. So the files match the scripts' layout exactly. `install.ps1` runs through `iex`, so an execution policy that blocks script files does not block it. For an npm copy the binary installs first, then runs `npm uninstall -g --prefix <prefix> pinggy`, and prints the `sudo` command for a folder it cannot write. It prints the PATH warning itself, then runs the user's command in the same process. A daemon that command starts runs from the installed copy (`startDaemonFromInstalledBinary()`). The installed binary's version comes from its link target, with no process. A plain file's or the Windows binary's `--version` output is kept in `update.json` with the file's size and modified time. Ctrl+D answers nothing, and a failed install counts as `n`. A double-clicked `pinggy.exe` ends with "Press Enter to close.", and the Windows updater moves a remembered `n` to the new version when it replaces that file in place. In the scripts' own case 7, after `n`, sign-in runs the user's binary, which can ask its own question once.
|
|
518
528
|
|
|
519
|
-
**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 still ask every update question, 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/
|
|
529
|
+
**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 still ask every update question, 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/tty` as stdin when it has a terminal, so `connect` can ask the file access question (`device.json` below), and `/dev/null` otherwise. Never its own stdin, which under `curl | sh` holds the rest of the script. `install.ps1` leaves `connect` the console. `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. A pinggy older than 0.6.2 ignores the variable, so a user who keeps one at the update question gets no connection.
|
|
520
530
|
|
|
521
531
|
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.
|
|
522
532
|
|
|
@@ -526,7 +536,7 @@ The design lives in the `pinggy_backend` repo under `docs/pinggy-devices/`: `cli
|
|
|
526
536
|
|
|
527
537
|
### Background mode
|
|
528
538
|
|
|
529
|
-
`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
|
|
539
|
+
`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, the boot entry `pinggy autostart on` writes, or the Pinggy app, whose in-process daemon runs the same `runDaemonChild()`. The app reaches it through `TunnelClient.getDeviceAgentStatus()`, `startDeviceAgent()` and `stopDeviceAgent()`.
|
|
530
540
|
|
|
531
541
|
**The token never goes over IPC.** `device.json` is the hand-off: the CLI writes it, the daemon reads it. The 3 `/device` routes (section 5) read no request field. A target that differs from `device.json` (another token, or another server) is checked first in the CLI with `startDeviceAgent(..., { verifyOnly: true })`: 1 attempt, ended at `welcome`, which writes `device.json` as the foreground agent does. A token the dashboard refuses never reaches the file or the daemon.
|
|
532
542
|
|
|
@@ -541,11 +551,11 @@ The design lives in the `pinggy_backend` repo under `docs/pinggy-devices/`: `cli
|
|
|
541
551
|
|
|
542
552
|
`login` signs in as the foreground does, then runs steps 3 to 6 in place of `runAgent`. After a new sign-in, `runAgent` gets `signInShown`, and step 6 leaves out the email and the device link, which the sign-in already printed. `device stop` calls `POST /device/stop`. `device status` prints a `State` line first (`describeDeviceState()`). It reads `GET /device` once, and `device-agent.json`: `running` plus the daemon agent's connection state, `running, with --foreground in another terminal`, `stopped` when no agent runs or no daemon runs, or `unknown` when `daemon.json` names a daemon that `GET /device` cannot read (another IPC version, an older daemon, no answer). It adds a `Background` line from the same reading. `device remove` stops a running background agent before it deletes `device.json`. A `--foreground` `connect` or `login` refuses while `GET /device` reports a run: 2 agents on 1 credential refuse each other with `already_connected`.
|
|
543
553
|
|
|
544
|
-
**The foreground record** (`src/devices/foregroundAgent.ts`). The daemon cannot see an agent started with `--foreground`, so `runDeviceAgent()` writes `device-agent.json` (`{pid, started_at, boot_id}`) beside `device.json` while it runs, and deletes it on exit if it still names its own PID. The agent checks once a second that the file exists. `device remove` (`src/devices/removeDevice.ts`) first prints the device id, the background agent's state and the foreground record's PID, and asks "Remove this device from this machine? [y/N]". Only `y` or `yes` goes on. `-f`, the existing `cliOptions.force`, skips the question. With no TTY and no `-f`, it exits 1 and changes nothing. Then it deletes the file, waits up to 10 s for the PID to exit, and deletes `device.json`. An agent still running after that fails the remove with exit 1 and leaves `device.json` in place. No signal goes to the PID: a record left by a crash can name an unrelated process. `readForegroundAgent()` deletes a record whose PID is dead or that comes from an earlier boot (section 3, "The boot check"). `connect` and `login` refuse while a live record names another process, both in the default background start and with `--foreground`. The background start writes no record: the daemon's `GET /device` already reports it. `device status` adds a `Foreground` line.
|
|
554
|
+
**The foreground record** (`src/devices/foregroundAgent.ts`). The daemon cannot see an agent started with `--foreground`, so `runDeviceAgent()` writes `device-agent.json` (`{pid, started_at, boot_id}`) beside `device.json` while it runs, and deletes it on exit if it still names its own PID. The agent checks once a second that the file exists. `device remove` (`src/devices/removeDevice.ts`) first prints the device id, the background agent's state and the foreground record's PID, and asks "Remove this device from this machine? [y/N]". Only `y` or `yes` goes on. `-f`, the existing `cliOptions.force`, skips the question. With no TTY and no `-f`, it exits 1 and changes nothing. Then it deletes the file, waits up to 10 s for the PID to exit, and deletes `device.json`. Last it removes the boot entry (section 16), which the question names when one exists. An agent still running after that fails the remove with exit 1 and leaves `device.json` in place. No signal goes to the PID: a record left by a crash can name an unrelated process. `readForegroundAgent()` deletes a record whose PID is dead or that comes from an earlier boot (section 3, "The boot check"). `connect` and `login` refuse while a live record names another process, both in the default background start and with `--foreground`. The background start writes no record: the daemon's `GET /device` already reports it. `device status` adds a `Foreground` line.
|
|
545
555
|
|
|
546
556
|
**`DeviceAgentHost`** (`src/daemon/deviceAgentHost.ts`) holds at most 1 run, built in `runDaemonChild()` once the IPC port is known. `start(origin)` reads `device.json`: none answers `DEVICE_NOT_ENROLLED`, a run on the same token and server is left alone, and a run on another is stopped before the new one starts. Start and stop run 1 at a time through 1 promise chain. A run that ends on its own (401, revoked, deleted, replaced) keeps why in `lastError`. The host saves the run in `daemon-config.json` through `saveDeviceAgent()`, and forgets it through `forgetDeviceAgent()` on a terminal outcome. A stop keeps it saved: `device stop` ends the current run only. `close()` on shutdown records nothing, so the run stays saved.
|
|
547
557
|
|
|
548
|
-
**Start with the daemon.** After the auto-start tunnels, `startSavedDeviceAgent()` in `runDaemonChild()` starts the saved agent with its `startedBy`. This runs on every daemon start, the way auto-start tunnels do, so the Pinggy app's in-process daemon starts it too. It skips the start while `device-agent.json` names a live foreground agent: 2 agents on 1 credential refuse each other with `already_connected`. The record stays for the next start. With no `device.json`, the start fails with `DEVICE_NOT_ENROLLED` and the record is deleted. Only `pinggy device remove` deletes the record from the CLI, before it deletes `device.json`. `pinggy device status` prints `Autostart on` while the record
|
|
558
|
+
**Start with the daemon.** After the auto-start tunnels, `startSavedDeviceAgent()` in `runDaemonChild()` starts the saved agent with its `startedBy`. This runs on every daemon start, the way auto-start tunnels do, so the Pinggy app's in-process daemon starts it too. It skips the start while `device-agent.json` names a live foreground agent: 2 agents on 1 credential refuse each other with `already_connected`. The record stays for the next start. With no `device.json`, the start fails with `DEVICE_NOT_ENROLLED` and the record is deleted. Only `pinggy device remove` deletes the record from the CLI, before it deletes `device.json`. `pinggy device status` prints `Autostart on` only while the record and the boot entry (section 16) both exist: the record alone starts nothing after a reboot. A `--foreground` agent never writes it.
|
|
549
559
|
|
|
550
560
|
The daemon's run differs from the foreground one in 3 dependencies, passed through `DeviceAgentOptions`:
|
|
551
561
|
|
|
@@ -558,7 +568,7 @@ The daemon's run differs from the foreground one in 3 dependencies, passed throu
|
|
|
558
568
|
| The CLI that ran `connect` exits, or its terminal closes | Keeps running. The daemon is detached |
|
|
559
569
|
| Daemon crash | Starts again with the next daemon |
|
|
560
570
|
| `pinggy daemon stop`, or the Pinggy app quits | Stops. The socket closes with 1000 and every shell ends. Starts again with the next daemon |
|
|
561
|
-
| Reboot | Starts again when the daemon starts, at sign-in with `pinggy
|
|
571
|
+
| Reboot | Starts again when the daemon starts: at boot on Linux, at sign-in on macOS and Windows, with `pinggy autostart on` |
|
|
562
572
|
| `pinggy device stop` | Stops. Starts again with the next daemon |
|
|
563
573
|
| `pinggy device remove` | Stops, and the daemon never starts it again |
|
|
564
574
|
| A terminal outcome | Stops, with `lastError`, and stays stopped until the next `connect` or `login` |
|
|
@@ -573,7 +583,8 @@ The daemon's run differs from the foreground one in 3 dependencies, passed throu
|
|
|
573
583
|
| --- | --- |
|
|
574
584
|
| `src/devices/envelope.ts` | The versioned frame wrapper. `request()`, `event()`, `parseEnvelope()`, channel and op constants |
|
|
575
585
|
| `src/devices/device_schema.ts` | Zod schemas for `welcome`, error, and `disconnect` payloads. Types for `hello`, `heartbeat`, `device/info`, `device/metrics`, and `device/tunnels` |
|
|
576
|
-
| `src/devices/deviceIdentity.ts` | `device.json` read, write, clear, and token masking |
|
|
586
|
+
| `src/devices/deviceIdentity.ts` | `device.json` read, write, clear, and token masking. A write with no `file_manager` keeps the stored one for the same token |
|
|
587
|
+
| `src/devices/fileAccess.ts` | The file access question, `--files`, `fileAccessAllowed()` for the file handler, and the `Files` line of `device status` |
|
|
577
588
|
| `src/devices/deviceAgent.ts` | URL build, connect loop, frame dispatch, heartbeat and metrics timers. `startDeviceAgent()` returns a run with `stop()` and `done`; `runDeviceAgent()` is the foreground entry with the SIGINT handler |
|
|
578
589
|
| `src/devices/deviceAgentReporter.ts` | `DeviceAgentReporter`, the run's events. `printingReporter`: the foreground's terminal output. `printConnected()` |
|
|
579
590
|
| `src/devices/backgroundAgent.ts` | The CLI's half of the background agent: verify a new target, print the manage commands, start the daemon's agent, wait for `connected`. `device stop`, the `status` line, the stop before `remove`, the foreground refusal |
|
|
@@ -592,10 +603,10 @@ The daemon's run differs from the foreground one in 3 dependencies, passed throu
|
|
|
592
603
|
| `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 |
|
|
593
604
|
| `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, into a directory named by the addon's hash. `hasExecutableSpawnHelper()`, true off macOS |
|
|
594
605
|
| `src/devices/terminal/shellAllowlist.ts` | `resolveShell()`: exact match against `/etc/shells`, or `powershell.exe` and `cmd.exe` on Windows |
|
|
595
|
-
| `src/cli/subcommand/handlers/deviceCommand.ts` | The `login`, `connect`, `stop`, `status`, `remove` verbs, and `--
|
|
596
|
-
| `src/utils/helpMessages.ts` | `printDeviceHelp()` |
|
|
606
|
+
| `src/cli/subcommand/handlers/deviceCommand.ts` | The `login`, `connect`, `stop`, `status`, `remove` verbs, `--foreground` and `--files`. `refuseDevicesSpelling()` for the old spelling. `handleAutostart()` for `pinggy autostart` |
|
|
607
|
+
| `src/utils/helpMessages.ts` | `printDeviceHelp()`, `printAutostartHelp()` |
|
|
597
608
|
|
|
598
|
-
`Subcommand.Device` in `src/cli/configStore.ts` puts `device` in `SUBCOMMANDS` and `RESERVED_NAMES`, so no new saved tunnel config can be named `device`. `Subcommand.Devices` keeps the old spelling in both. `pinggy devices` prints `"pinggy devices" is now "pinggy device". Run: pinggy device <verb>` and exits 1. It names the verb only when it is 1 of the 5, else `--help`, and never repeats the other arguments, which can hold a token. Without it, `devices` would fall to legacy tunnel mode, where `--token` is the tunnel token, and a device token would reach the tunnel server.
|
|
609
|
+
`Subcommand.Device` in `src/cli/configStore.ts` puts `device` in `SUBCOMMANDS` and `RESERVED_NAMES`, so no new saved tunnel config can be named `device`. `Subcommand.Autostart` does the same for `autostart`. `Subcommand.Devices` keeps the old spelling in both. `pinggy devices` prints `"pinggy devices" is now "pinggy device". Run: pinggy device <verb>` and exits 1. It names the verb only when it is 1 of the 5, else `--help`, and never repeats the other arguments, which can hold a token. Without it, `devices` would fall to legacy tunnel mode, where `--token` is the tunnel token, and a device token would reach the tunnel server.
|
|
599
610
|
|
|
600
611
|
### The envelope
|
|
601
612
|
|
|
@@ -792,9 +803,13 @@ Retry sleeps an exponential backoff with full jitter: 1 s doubling to a 60 s cap
|
|
|
792
803
|
|
|
793
804
|
```json
|
|
794
805
|
{"device_agent_id": "0a7d3f6c-2b41-4e8a-9c5d-1e2f3a4b5c6d", "token": "...",
|
|
795
|
-
"server": "dashboard.pinggy.io", "enrolled_at": "2026-09-05T09:22:10Z"}
|
|
806
|
+
"server": "dashboard.pinggy.io", "enrolled_at": "2026-09-05T09:22:10Z", "file_manager": true}
|
|
796
807
|
```
|
|
797
808
|
|
|
809
|
+
**`file_manager` is the answer to the file access question**, "Allow file access from the Pinggy dashboard? Your account can browse, copy, move and delete this machine's files from the browser. [Y/n]" (`src/devices/fileAccess.ts`). `connect`, `start` and `login` ask it once per device token, in a terminal, before the agent starts. Only an answer that starts with `n` means no. `--files on|off` answers it with no question, and any other value exits 1. With no terminal, nothing is asked or saved, and absent counts as allowed, so the next run in a terminal asks. For the token `device.json` holds, the answer is written at once. A new token's answer rides on the run (`DeviceAgentOptions.fileManager`): the verify of a background `connect`, or the foreground run, writes it with the token at `welcome`. Ctrl+C at the question changes nothing in `connect`. In `login`, after the sign-in, it keeps the new credential with no answer and runs no agent. `device status` prints `Files on`, `Files off` or `Files on, not asked yet`.
|
|
810
|
+
|
|
811
|
+
The file handler reads the answer on every request (`fileAccessAllowed()`) and refuses with `file_access_off` while it is no, after the `file_manager_disabled` check. `file_manager` stays in `hello`'s capabilities, and the dashboard passes the agent's code and message to the tab. A new answer applies to the next request with no restart, so open terminals stay open. A run copies `device.json` at start and rewrites it on every `welcome`: `identityForRun()` drops the stored `file_manager` from that copy, and `writeDeviceIdentity()` keeps the one on disk for the same token when the identity it writes has none. Without both, a `--files off` given while the agent runs turns back on at the next reconnect.
|
|
812
|
+
|
|
798
813
|
`getDeviceConfigPath()` puts it beside `tunnels/`, not inside it: a device is not a tunnel config. `device_agent_id` is minted by the dashboard and read from `welcome`; the agent never invents one. A token from `--token` or `DEVICE_AGENT_TOKEN` always beats the stored value. When it differs from the stored token, `identityForRun()` starts a new identity, with no old `device_agent_id` and no old `enrolled_at`. At the 1st `welcome`, and not before, the run reports "This machine was device <old id>. That device stays in the dashboard, offline." A token the dashboard refuses replaces nothing, so it reports nothing.
|
|
799
814
|
|
|
800
815
|
**Written 0600, then chmodded again on every rewrite**, because `writeFileSync` applies `mode` only when it creates the file. This diverges from `configStore.ts`, which writes tunnel tokens at 0644 under a normal umask. Do not copy that pattern into anything new.
|
package/CLAUDE.md
CHANGED
|
@@ -28,7 +28,7 @@ node test/e2e/run.cjs out/pinggy-<platform>
|
|
|
28
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`, `update`). Routes to `handleSubcommand()` in `src/cli/subcommands.ts`.
|
|
31
|
+
2. **Subcommand** (`config`, `start`, `stop`, `ps`, `attach`, `daemon`, `d`, `device`, `devices`, `update`, `autostart`). 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
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.
|
|
34
34
|
|
|
@@ -57,7 +57,7 @@ Single daemon per user. State lives under `~/.config/pinggy/` on Linux/macOS or
|
|
|
57
57
|
- `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.
|
|
58
58
|
- `daemon.log`: SDK + daemon logs. CLI logs stay separate.
|
|
59
59
|
- `tunnels/<name>_<configId>.json`: saved tunnel configs from `pinggy config save`.
|
|
60
|
-
- `device.json`: device agent id and token from `pinggy device connect` (`src/devices/deviceIdentity.ts`). Written 0600, unlike the tunnel configs beside it.
|
|
60
|
+
- `device.json`: device agent id and token from `pinggy device connect` (`src/devices/deviceIdentity.ts`), and `file_manager`, the answer to the file access question. Written 0600, unlike the tunnel configs beside it.
|
|
61
61
|
- `device-agent.json`: `{pid, started_at, boot_id}` of a device agent started with `--foreground`, while it runs (`src/devices/foregroundAgent.ts`). `pinggy device remove` deletes it, and the agent stops within 1 s. No credential.
|
|
62
62
|
|
|
63
63
|
### Foreground vs detached tunnels
|
|
@@ -77,11 +77,13 @@ Single daemon per user. State lives under `~/.config/pinggy/` on Linux/macOS or
|
|
|
77
77
|
|
|
78
78
|
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.
|
|
79
79
|
|
|
80
|
+
`connect`, `start` and `login` ask once per device token, in a terminal, "Allow file access from the Pinggy dashboard?" (`src/devices/fileAccess.ts`). `--files on|off` answers it with no question. `device.json` holds the answer as `file_manager`. With no terminal nothing is asked or saved, and file access stays on. The file handler reads the answer on every request and refuses with `file_access_off` while it is no, so a new answer applies with no restart. A run rewrites `device.json` on every `welcome` from what it read at start, so `identityForRun()` drops the stored answer and `writeDeviceIdentity()` keeps the one on disk for the same token. Any new writer of `device.json` keeps that rule, or a `--files off` given while the agent runs turns back on at the next reconnect.
|
|
81
|
+
|
|
80
82
|
`pinggy device connect` and `login` run the agent in the daemon, as `pinggy start -b` runs a tunnel there, so it outlives the terminal. `pinggy device start` is the same verb as `connect`. `--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`, `start`, `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.
|
|
81
83
|
|
|
82
84
|
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`.
|
|
83
85
|
|
|
84
|
-
`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. The scripts read the version to install from `https://pinggy.io/cli/version.json`, which the website builds from the `data/cli_releases.yaml` that the same PR updates, and they exit 1 when it does not answer. They download the binary from the GitHub release. The updater in `src/update/` still reads GitHub's `/releases/latest`. Copies of the scripts stay in use, so that URL and its `version` field never change. 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 still gets every update question, then 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. Both scripts update the copy the `pinggy` command runs: an npm copy with `npm install -g --prefix`, the binary otherwise. A copy from `npm link`, pnpm, yarn or bun stops them, and a binary they did not install gets a question first (ARCHITECTURE.md, "Which copy the scripts update"). They tell an npm copy by the `lib/node_modules/pinggy/` path that npm writes. A packaged binary run from anywhere else offers to install itself by running the script it carries, with `PINGGY_BINARY_URL` and `PINGGY_INSTALL_ONLY=1` (`src/install/selfInstall.ts`). It finds the copy `pinggy` runs in `src/install/pinggyOnPath.ts`, so a change to how either script tells an npm copy changes that file in the same commit. `pinggy
|
|
86
|
+
`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. The scripts read the version to install from `https://pinggy.io/cli/version.json`, which the website builds from the `data/cli_releases.yaml` that the same PR updates, and they exit 1 when it does not answer. They download the binary from the GitHub release. The updater in `src/update/` still reads GitHub's `/releases/latest`. Copies of the scripts stay in use, so that URL and its `version` field never change. 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 still gets every update question, then runs `pinggy device connect -b` instead, with the token in the environment, never on a command line. `install.sh` gives `connect` `/dev/tty` as stdin when it has a terminal, so `connect` can ask the file access question, and `/dev/null` otherwise; never its own stdin, which under `curl | sh` holds the rest of the script. `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. Both scripts update the copy the `pinggy` command runs: an npm copy with `npm install -g --prefix`, the binary otherwise. A copy from `npm link`, pnpm, yarn or bun stops them, and a binary they did not install gets a question first (ARCHITECTURE.md, "Which copy the scripts update"). They tell an npm copy by the `lib/node_modules/pinggy/` path that npm writes. A packaged binary run from anywhere else offers to install itself by running the script it carries, with `PINGGY_BINARY_URL` and `PINGGY_INSTALL_ONLY=1` (`src/install/selfInstall.ts`). It finds the copy `pinggy` runs in `src/install/pinggyOnPath.ts`, so a change to how either script tells an npm copy changes that file in the same commit. `pinggy autostart on` writes the boot entry 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 autostart on` unless the boot entry exists. A script run with `PINGGY_VERSION` set to a release before `pinggy autostart` fails that question, and the install still succeeds. 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. Before the sign-in, both scripts offer to restart a daemon that runs another version (ARCHITECTURE.md section 17, "Install scripts."). They read `pid`, `host` and `cliVersion` from `daemon.json`, look for `--_daemon-child` in the daemon's command line, and `install.sh` restarts through the launchd label or the systemd unit as `serviceRestartInstruction()` does. Renaming any of those fields, the flag, the label or the unit changes both scripts in the same commit.
|
|
85
87
|
|
|
86
88
|
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/`.
|
|
87
89
|
|
|
@@ -96,9 +98,10 @@ Section 17 of `ARCHITECTURE.md` has the protocol, the retry and terminal outcome
|
|
|
96
98
|
| `pinggy stop <name\|id>` | Stop running tunnel(s) by name or ID prefix |
|
|
97
99
|
| `pinggy ps` | Table of running tunnels (ID, name, status, local, URL) |
|
|
98
100
|
| `pinggy attach <name\|id>` | Re-attach TUI to a running tunnel |
|
|
99
|
-
| `pinggy daemon start \| stop \| status
|
|
101
|
+
| `pinggy daemon start \| stop \| status` (alias `d`) | Daemon lifecycle. `service-install` and `service-uninstall` print their `pinggy autostart` replacement and exit 1 |
|
|
100
102
|
| `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 |
|
|
101
|
-
| `pinggy device login \| connect \| start [--foreground] \| stop \| status \| remove [-f]` | Sign this machine in by email, or enrol it with a token, as a Pinggy device (`start` is the same as `connect`); the agent runs in the daemon, or in this terminal with `--foreground`, and `stop` stops the daemon's; show whether the agent runs, 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) |
|
|
103
|
+
| `pinggy device login \| connect \| start [--foreground] [--files on\|off] \| stop \| status \| remove [-f]` | Sign this machine in by email, or enrol it with a token, as a Pinggy device (`start` is the same as `connect`); the agent runs in the daemon, or in this terminal with `--foreground`, and `stop` stops the daemon's; `--files` answers the file access question, which a terminal run otherwise asks once; show whether the agent runs, the enrolment and the background agent; show the device and its connection, ask, then stop every agent and forget the credential and the boot entry (`-f` skips the question) |
|
|
104
|
+
| `pinggy autostart [on \| off \| status]` | Bring this device online each time this computer starts. `on` writes the boot entry (systemd unit, launchd plist, Windows task), and first asks to start the agent when `daemon-config.json` saves none. `off` removes the boot entry and leaves the running agent alone. No word means `status` |
|
|
102
105
|
|
|
103
106
|
### Auto-update
|
|
104
107
|
|
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ Create secure, shareable tunnels to your localhost and manage them from the comm
|
|
|
12
12
|
- Foreground (live TUI) and detached (`-b`) tunnel modes
|
|
13
13
|
- Lifecycle commands: `ps`, `start`, `stop`, `restart`, `attach`
|
|
14
14
|
- Per-tunnel and per-daemon log files with `pinggy logs` (tail, follow, rotation-safe)
|
|
15
|
-
-
|
|
15
|
+
- Device autostart with `pinggy autostart on` (systemd, launchd, Task Scheduler)
|
|
16
16
|
- Remote management via secure WebSocket connection (works with Pinggy Dashboard)
|
|
17
17
|
- Pinggy Devices: enrol the machine with `pinggy device` and keep it visible in the dashboard
|
|
18
18
|
- Save and load configuration files
|
|
@@ -265,6 +265,18 @@ pinggy device connect --token <TOKEN> --manage dashboard.pinggy.io
|
|
|
265
265
|
|
|
266
266
|
`--token` here is the device token, not the tunnel token of the same flag name in [Options](#options). The 2 credentials are unrelated and the device agent never reads the tunnel one.
|
|
267
267
|
|
|
268
|
+
### Allow or refuse file access
|
|
269
|
+
|
|
270
|
+
The first `pinggy device connect`, `start` or `login` in a terminal asks "Allow file access from the Pinggy dashboard? Your account can browse, copy, move and delete this machine's files from the browser. [Y/n]". Enter allows it. The answer is saved, so later runs do not ask. With no terminal, nothing is asked and file access stays on.
|
|
271
|
+
|
|
272
|
+
Change the answer at any time. A running agent applies it to the next file request:
|
|
273
|
+
```bash
|
|
274
|
+
pinggy device connect --files off
|
|
275
|
+
pinggy device connect --files on
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
While file access is off, the dashboard's file manager shows "File access is off on this device." `pinggy device status` prints the answer on its `Files` line. The browser terminal does not read this answer.
|
|
279
|
+
|
|
268
280
|
### Show the device and whether it runs
|
|
269
281
|
```bash
|
|
270
282
|
pinggy device status
|
|
@@ -287,7 +299,23 @@ Then it prints the device id, server, masked token, and enrolment time from the
|
|
|
287
299
|
pinggy device remove
|
|
288
300
|
```
|
|
289
301
|
|
|
290
|
-
Prints the device id and whether the device is connected now, in the background or with `--foreground` in another terminal, then asks "Remove this device from this machine? [y/N]". Only `y` removes it: the command stops the device agent, then deletes the local credential. With no terminal, it refuses unless you add `-f`, which removes without asking. The device still exists in the dashboard. Delete it there to revoke it, because a machine that has lost its credential cannot authenticate the delete.
|
|
302
|
+
Prints the device id and whether the device is connected now, in the background or with `--foreground` in another terminal, then asks "Remove this device from this machine? [y/N]". Only `y` removes it: the command stops the device agent, then deletes the local credential. With no terminal, it refuses unless you add `-f`, which removes without asking. The device still exists in the dashboard. Delete it there to revoke it, because a machine that has lost its credential cannot authenticate the delete. When autostart is on, remove turns it off too.
|
|
303
|
+
|
|
304
|
+
### Start on boot
|
|
305
|
+
|
|
306
|
+
```bash
|
|
307
|
+
pinggy autostart on # Bring this device online each time this computer starts
|
|
308
|
+
pinggy autostart off # Stop that. The device stays online until the next restart
|
|
309
|
+
pinggy autostart status # Show whether it is on. `pinggy autostart` alone does the same
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
`on` writes a boot entry that starts the daemon: a systemd user service on Linux, a launchd agent on macOS, a Task Scheduler task on Windows. On Linux it also turns on lingering, so the device comes online at boot with nobody signed in. On macOS and Windows it comes online when you sign in. Only the copy the Pinggy installer put in place may write the entry, so the npm version and a downloaded binary are refused with the command to run instead.
|
|
313
|
+
|
|
314
|
+
A restart brings the device back only when the daemon also runs its agent, which `login`, `connect` and `start` set up and `--foreground` does not. So `on` checks that first. With no background agent, it asks "Start it now, and each time this computer starts? [Y/n]" before it starts one. With no terminal it asks nothing and names `pinggy device start`. On a machine that is not signed in, it refuses and names `pinggy device login`.
|
|
315
|
+
|
|
316
|
+
`off` removes the boot entry and stops nothing, so it is safe to run from the dashboard's browser terminal. To take the device offline now, run `pinggy device stop`.
|
|
317
|
+
|
|
318
|
+
`pinggy daemon service-install` and `pinggy daemon service-uninstall` were the old names. They now print the new command and exit 1.
|
|
291
319
|
|
|
292
320
|
### Reconnect and stop conditions
|
|
293
321
|
|
|
@@ -327,11 +355,11 @@ It enrols, learns its device id and heartbeat interval from the dashboard, and s
|
|
|
327
355
|
|
|
328
356
|
### Devices, tunnels, and the daemon
|
|
329
357
|
|
|
330
|
-
- By default the daemon runs the agent. `pinggy device connect` and `login` start a daemon when none runs. `pinggy daemon stop` stops the agent with every tunnel, and so does a reboot. Every daemon start runs it again, until `pinggy device remove`. `pinggy device stop` stops it until the daemon starts again. With `pinggy
|
|
358
|
+
- By default the daemon runs the agent. `pinggy device connect` and `login` start a daemon when none runs. `pinggy daemon stop` stops the agent with every tunnel, and so does a reboot. Every daemon start runs it again, until `pinggy device remove`. `pinggy device stop` stops it until the daemon starts again. With `pinggy autostart on`, the daemon starts with the computer, so the device comes back online after a reboot. `pinggy device start` or `pinggy device connect` starts it again after a stop.
|
|
331
359
|
- With `--foreground` the agent is its own process. It never starts the daemon, `pinggy daemon stop` leaves it running, and Ctrl+C on it leaves every tunnel running.
|
|
332
360
|
- 1 enrolment per machine. The newest successful connect overwrites `device.json`, and a `--token` on the command line beats the stored one.
|
|
333
361
|
- 1 agent per machine. `connect` and `login` refuse while another terminal runs a `--foreground` agent. `--foreground` is refused while the daemon runs an agent. Stop that one first with `pinggy device stop`.
|
|
334
|
-
- `pinggy device remove` stops a running agent, in the background or with `--foreground` in another terminal, before it deletes the credential file.
|
|
362
|
+
- `pinggy device remove` stops a running agent, in the background or with `--foreground` in another terminal, before it deletes the credential file. Then it removes the boot entry, when there is one.
|
|
335
363
|
|
|
336
364
|
|
|
337
365
|
## Usage
|