pinggy 0.6.9 → 0.6.11
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 +21 -8
- package/CLAUDE.md +7 -3
- package/README.md +12 -0
- package/dist/{chunk-MHQ3CVEB.js → chunk-P54K7NPF.js} +5 -1
- package/dist/chunk-RYO5T2JT.js +1947 -0
- package/dist/{chunk-LF6WMFWT.js → chunk-W47AYOH2.js} +6800 -2025
- package/dist/{daemonChild-WTZ7X6SZ.js → daemonChild-GGG34AOT.js} +7 -5
- package/dist/index.cjs +3234 -432
- package/dist/index.d.cts +75 -2
- package/dist/index.d.ts +75 -2
- package/dist/index.js +21 -5
- package/dist/{ipcClient-IZ5R6TPN.js → ipcClient-6QESURCH.js} +1 -1
- package/dist/{main-INPCUGAN.js → main-FCIOVX5I.js} +5 -8
- package/dist/{updateChild-BPWBQ3WR.js → updateChild-RNCLN24C.js} +12 -14
- package/package.json +1 -1
- package/scripts/install/install.ps1 +3 -2
- package/scripts/install/install.sh +13 -7
- package/dist/chunk-HJECJ7LC.js +0 -889
- package/dist/chunk-OQVFQ5VG.js +0 -1041
- package/dist/chunk-Q5RYSWFK.js +0 -2204
package/ARCHITECTURE.md
CHANGED
|
@@ -90,6 +90,7 @@ The spawn path is deliberately one-way. The CLI fires off a detached child with
|
|
|
90
90
|
│ Unix: spawn(execPath, [argv[1], "--_daemon-child"], {detached, stdio: pipe-stderr})
|
|
91
91
|
│ Windows: same + windowsHide:true
|
|
92
92
|
│ Electron: calls ensuredaemon() which internally starts the daemon server if no daemon is there
|
|
93
|
+
│ Host with setDaemonLauncher(): the launcher starts the daemon, then daemon.json is polled
|
|
93
94
|
│
|
|
94
95
|
├─ child.unref()
|
|
95
96
|
│
|
|
@@ -102,6 +103,8 @@ The spawn path is deliberately one-way. The CLI fires off a detached child with
|
|
|
102
103
|
|
|
103
104
|
Implementation: `src/daemon/daemonManager.ts`.
|
|
104
105
|
|
|
106
|
+
**A host can start the daemon itself.** `setDaemonLauncher(fn)` replaces both the detached spawn and the Electron in-process start: `ensureDaemonRunning()` awaits `fn`, then reads `daemon.json`. The Pinggy app uses it to run the daemon in a child process it supervises (`runDaemonChild({ host: DaemonHost.APP })` in an Electron utility process), so a crash or `exit(1)` in the native library ends that child and not the app. The app starts a new child, which restores the tunnels (section 8). `daemon.json` still says `host: "app"`, so the CLI treats it as before: `pinggy daemon stop` is refused, and a version mismatch points at the app. With no launcher set, an Electron host still gets the in-process daemon. After its child exits, the host calls `removeDeadDaemonFiles(pid)`: `daemon.json` and `daemon.lock` would otherwise name a dead PID until the next daemon starts.
|
|
107
|
+
|
|
105
108
|
The `daemon.json` check only stops the CLI from spawning a child. 2 CLIs started at the same moment can both find no `daemon.json` and both spawn one, and systemd and launchd run `--_daemon-child` with no check at all. So the daemon itself takes `daemon.lock` (`src/daemon/lifecycle/daemonLock.ts`) before it opens its IPC port. The file is created with the `wx` flag, so only 1 process creates it. A daemon that finds a live holder exits 0, or throws when the app hosts it in-process. Exit code 0 keeps systemd's `Restart=on-failure` from starting it again. The spawning CLI keeps polling after a child exits 0, and gets the winner's `daemon.json`. A lock is stale when its PID is dead (`process.kill(pid, 0)` throws `ESRCH`), when it comes from an earlier boot (the PID may name another process now, see "The boot check" in section 3), or when it is unreadable and older than 10s (a crash between create and write). The next daemon deletes a stale lock and creates its own. 2 daemons that find the same stale lock at the same moment can both take it. `EPERM` counts as alive: the service task runs without admin rights, and gets `EPERM` for a daemon started from an Administrator shell. Treating that as dead started a 2nd daemon on Windows. The daemon deletes `daemon.lock` and `daemon.json` on exit only when they hold its own PID.
|
|
106
109
|
|
|
107
110
|
The CLI keeps its `daemon.json` check. It reads the port from that file anyway, and it skips a process start when a daemon already runs.
|
|
@@ -119,12 +122,13 @@ The CLI keeps its `daemon.json` check. It reads the port from that file anyway,
|
|
|
119
122
|
3. Create TunnelManager singleton
|
|
120
123
|
4. Create IPCServer (HTTP + WS, port not yet bound)
|
|
121
124
|
5. Create SessionTracker, wire onSessionDisconnect
|
|
122
|
-
6. Register signal handlers: SIGTERM, SIGINT,
|
|
125
|
+
6. Register signal handlers: SIGTERM, SIGINT, uncaughtException
|
|
123
126
|
7. ipcServer.listen() → returns OS-assigned port
|
|
124
127
|
8. Write daemon.json atomically (write to .tmp, rename)
|
|
125
|
-
9. restoreCrashedTunnels() — replay detached tunnels from daemon-state.json
|
|
126
|
-
10. Start auto-start tunnels (getAutoStartConfigs())
|
|
128
|
+
9. restoreCrashedTunnels() — replay detached tunnels from daemon-state.json, all at the same time
|
|
129
|
+
10. Start auto-start tunnels (getAutoStartConfigs()) at the same time, unless the host passed skipAutoStart
|
|
127
130
|
10a. startSavedDeviceAgent(): the background device agent saved in daemon-config.json
|
|
131
|
+
10b. Register the exit handler. A start that failed must not run cleanup(): it would delete the crash state
|
|
128
132
|
11. Log "Daemon ready"
|
|
129
133
|
|
|
130
134
|
|
|
@@ -280,7 +284,11 @@ Two lifecycle paths:
|
|
|
280
284
|
- **Clean shutdown** (`/shutdown` or signal): `clearDaemonState()` deletes the file. Next daemon start sees nothing to recover.
|
|
281
285
|
- **Crash** (SIGKILL, OOM, panic): the file remains. Next daemon start calls `restoreCrashedTunnels()`, which restarts each `mode === "detached"` tunnel using the persisted config and stable `tunnelId` (so log files stay continuous). Foreground tunnels are not restored: there is no CLI to attach.
|
|
282
286
|
|
|
283
|
-
|
|
287
|
+
The tunnels are restored at the same time, not one after another. A start is about 2 s of waiting for the server, each tunnel has its own worker thread, and the daemon is not ready until the restore is done, so a serial restore cost 2 s of downtime per tunnel. Auto-start tunnels start at the same time for the same reason. Three things keep that safe: the state file can hold 2 entries for 1 config (a tunnel that exited by itself stays in it), so only the newest per config is restored; a tunnel that a stop request stopped while it was starting is not tracked again; and each tunnel handles its own failure.
|
|
288
|
+
|
|
289
|
+
A restore can be cut short by the next crash, and a host that restarts the daemon makes that likely. So `restoreCrashedTunnels()` first rewrites the file with every tunnel it will try, and a tunnel leaves the file only when its start fails or it is stopped. A crash during the restore leaves all of them for the next daemon. A tunnel that crashes the daemon every time it starts therefore crashes each new daemon; the host has to stop restarting (the Pinggy app gives up after 5 crashes in 10 minutes, and clears the file when it quits). `restorableTunnelCount()` tells a host whether a daemon that is gone crashed (tunnels left in the file) or was stopped (no file).
|
|
290
|
+
|
|
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.
|
|
284
292
|
|
|
285
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 daemon service-install`. See section 17.
|
|
286
294
|
|
|
@@ -508,7 +516,7 @@ The one long-lived surface that is not a tunnel. `pinggy device connect` enrols
|
|
|
508
516
|
|
|
509
517
|
**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.
|
|
510
518
|
|
|
511
|
-
**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/
|
|
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/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.
|
|
512
520
|
|
|
513
521
|
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.
|
|
514
522
|
|
|
@@ -565,7 +573,8 @@ The daemon's run differs from the foreground one in 3 dependencies, passed throu
|
|
|
565
573
|
| --- | --- |
|
|
566
574
|
| `src/devices/envelope.ts` | The versioned frame wrapper. `request()`, `event()`, `parseEnvelope()`, channel and op constants |
|
|
567
575
|
| `src/devices/device_schema.ts` | Zod schemas for `welcome`, error, and `disconnect` payloads. Types for `hello`, `heartbeat`, `device/info`, `device/metrics`, and `device/tunnels` |
|
|
568
|
-
| `src/devices/deviceIdentity.ts` | `device.json` read, write, clear, and token masking |
|
|
576
|
+
| `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 |
|
|
577
|
+
| `src/devices/fileAccess.ts` | The file access question, `--files`, `fileAccessAllowed()` for the file handler, and the `Files` line of `device status` |
|
|
569
578
|
| `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 |
|
|
570
579
|
| `src/devices/deviceAgentReporter.ts` | `DeviceAgentReporter`, the run's events. `printingReporter`: the foreground's terminal output. `printConnected()` |
|
|
571
580
|
| `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 |
|
|
@@ -584,7 +593,7 @@ The daemon's run differs from the foreground one in 3 dependencies, passed throu
|
|
|
584
593
|
| `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 |
|
|
585
594
|
| `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 |
|
|
586
595
|
| `src/devices/terminal/shellAllowlist.ts` | `resolveShell()`: exact match against `/etc/shells`, or `powershell.exe` and `cmd.exe` on Windows |
|
|
587
|
-
| `src/cli/subcommand/handlers/deviceCommand.ts` | The `login`, `connect`, `stop`, `status`, `remove` verbs, and `--
|
|
596
|
+
| `src/cli/subcommand/handlers/deviceCommand.ts` | The `login`, `connect`, `stop`, `status`, `remove` verbs, `--foreground` and `--files`. `refuseDevicesSpelling()` for the old spelling |
|
|
588
597
|
| `src/utils/helpMessages.ts` | `printDeviceHelp()` |
|
|
589
598
|
|
|
590
599
|
`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.
|
|
@@ -784,9 +793,13 @@ Retry sleeps an exponential backoff with full jitter: 1 s doubling to a 60 s cap
|
|
|
784
793
|
|
|
785
794
|
```json
|
|
786
795
|
{"device_agent_id": "0a7d3f6c-2b41-4e8a-9c5d-1e2f3a4b5c6d", "token": "...",
|
|
787
|
-
"server": "dashboard.pinggy.io", "enrolled_at": "2026-09-05T09:22:10Z"}
|
|
796
|
+
"server": "dashboard.pinggy.io", "enrolled_at": "2026-09-05T09:22:10Z", "file_manager": true}
|
|
788
797
|
```
|
|
789
798
|
|
|
799
|
+
**`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`.
|
|
800
|
+
|
|
801
|
+
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.
|
|
802
|
+
|
|
790
803
|
`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.
|
|
791
804
|
|
|
792
805
|
**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
|
@@ -47,6 +47,8 @@ CLI code calls `TunnelClient` (`src/daemon/tunnelClient.ts`), the public facade
|
|
|
47
47
|
|
|
48
48
|
`getDaemonInfo()` in `src/daemon/lifecycle/daemonManager.ts` reads `daemon.json`, validates the PID with `process.kill(pid, 0)`, deletes the file if stale (dead PID, or written in an earlier boot), and returns `null` if no live daemon is found. `startedInEarlierBoot()` in `src/daemon/lifecycle/bootId.ts` decides "earlier boot" for `daemon.json`, `daemon.lock` and `device-agent.json`: it compares the OS boot ID each record saves with this boot's. A record with no boot ID, from an older version or on Windows, falls back to comparing its start time with `Date.now() - os.uptime()`. A forward clock step moves that boot time later, so never decide "earlier boot" from the clock where a boot ID exists: the CLI would delete a running daemon's `daemon.json` (ARCHITECTURE.md section 3). `startDaemon()` spawns a detached daemon child and polls `daemon.json` for up to 8s.
|
|
49
49
|
|
|
50
|
+
A host can start the daemon its own way with `setDaemonLauncher()` (`daemonManager.ts`). The Pinggy app runs `runDaemonChild({ host: DaemonHost.APP })` in a child process and starts it again when it exits; `daemon.json` still says `host: "app"`. With no launcher, an Electron host runs the daemon in its own process.
|
|
51
|
+
|
|
50
52
|
Single daemon per user. State lives under `~/.config/pinggy/` on Linux/macOS or `%APPDATA%/pinggy/` on Windows (helper: `src/utils/configDir.ts`):
|
|
51
53
|
|
|
52
54
|
- `daemon.json`: `{pid, port, startedAt, host, ipcVersion, cliVersion, bootId}`. `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.
|
|
@@ -55,7 +57,7 @@ Single daemon per user. State lives under `~/.config/pinggy/` on Linux/macOS or
|
|
|
55
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.
|
|
56
58
|
- `daemon.log`: SDK + daemon logs. CLI logs stay separate.
|
|
57
59
|
- `tunnels/<name>_<configId>.json`: saved tunnel configs from `pinggy config save`.
|
|
58
|
-
- `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.
|
|
59
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.
|
|
60
62
|
|
|
61
63
|
### Foreground vs detached tunnels
|
|
@@ -75,11 +77,13 @@ Single daemon per user. State lives under `~/.config/pinggy/` on Linux/macOS or
|
|
|
75
77
|
|
|
76
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.
|
|
77
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
|
+
|
|
78
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.
|
|
79
83
|
|
|
80
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`.
|
|
81
85
|
|
|
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. 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 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. 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.
|
|
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 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. 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.
|
|
83
87
|
|
|
84
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/`.
|
|
85
89
|
|
|
@@ -96,7 +100,7 @@ Section 17 of `ARCHITECTURE.md` has the protocol, the retry and terminal outcome
|
|
|
96
100
|
| `pinggy attach <name\|id>` | Re-attach TUI to a running tunnel |
|
|
97
101
|
| `pinggy daemon start \| stop \| status \| service-install \| service-uninstall` (alias `d`) | Daemon lifecycle and system-service installation |
|
|
98
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 |
|
|
99
|
-
| `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 (`-f` skips the question) |
|
|
100
104
|
|
|
101
105
|
### Auto-update
|
|
102
106
|
|
package/README.md
CHANGED
|
@@ -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
|
|
@@ -120,7 +120,11 @@ var IPCClient = class {
|
|
|
120
120
|
path,
|
|
121
121
|
method,
|
|
122
122
|
headers,
|
|
123
|
-
timeout: timeoutMs ?? REQUEST_TIMEOUT_MS
|
|
123
|
+
timeout: timeoutMs ?? REQUEST_TIMEOUT_MS,
|
|
124
|
+
// A new connection per request. The shared agent keeps a socket for reuse, and the
|
|
125
|
+
// daemon closes an idle one after 5 s, which is also the heartbeat interval: a ping
|
|
126
|
+
// written to a socket the daemon is closing fails with ECONNRESET.
|
|
127
|
+
agent: false
|
|
124
128
|
},
|
|
125
129
|
(res) => {
|
|
126
130
|
const chunks = [];
|