pinggy 0.6.4 → 0.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/ARCHITECTURE.md +126 -57
  2. package/CLAUDE.md +25 -12
  3. package/README.md +5 -5
  4. package/dist/{TunnelManager-NGSUBZYI.js → TunnelManager-JRVEADS4.js} +4 -3
  5. package/dist/{TunnelTui-UCG2YSLX.js → TunnelTui-6H4NPUNF.js} +4 -3
  6. package/dist/{chunk-Y435RMHQ.js → chunk-2GIJXE4K.js} +3 -2
  7. package/dist/{chunk-QNUVQ6KD.js → chunk-3WMTTJHI.js} +11 -299
  8. package/dist/chunk-4XXAHYCJ.js +927 -0
  9. package/dist/{chunk-PD7HXVQ3.js → chunk-CZOKR73F.js} +18 -1
  10. package/dist/chunk-FQ22KFVV.js +882 -0
  11. package/dist/{chunk-UVJYL2ZN.js → chunk-HAFTH5MX.js} +933 -576
  12. package/dist/chunk-HTIWY3O5.js +293 -0
  13. package/dist/{chunk-MV56U3E6.js → chunk-LWCVB42S.js} +2 -2
  14. package/dist/{chunk-AFMTIELL.js → chunk-MAK5R4WQ.js} +20 -0
  15. package/dist/{chunk-7EQKHVQX.js → chunk-MHQ3CVEB.js} +4 -51
  16. package/dist/chunk-MKGD2QAI.js +51 -0
  17. package/dist/{chunk-CIOYQU7F.js → chunk-Q5NCTGNS.js} +49 -233
  18. package/dist/{configStore-RR5ZU4E3.js → configStore-JJUWT2YO.js} +3 -3
  19. package/dist/{daemonChild-WHS676G4.js → daemonChild-Q6WGYKYX.js} +14 -14
  20. package/dist/daemonConfig-VWK4TXVS.js +17 -0
  21. package/dist/index.cjs +3214 -935
  22. package/dist/index.d.cts +150 -129
  23. package/dist/index.d.ts +150 -129
  24. package/dist/index.js +18 -13
  25. package/dist/{ipcClient-XGF2KCQO.js → ipcClient-IZ5R6TPN.js} +2 -1
  26. package/dist/{main-JRVKAIHH.js → main-BI7ACRHS.js} +19 -14
  27. package/dist/updateChild-Z3SIRYO5.js +237 -0
  28. package/dist/workers/file_serve_worker.js +1 -1
  29. package/package.json +2 -1
  30. package/scripts/install/install.ps1 +49 -5
  31. package/scripts/install/install.sh +99 -12
  32. package/dist/daemonConfig-QVXQ47XH.js +0 -9
@@ -1,20 +1,28 @@
1
1
  import {
2
- DaemonHost,
3
- IPCClient,
4
- IPC_VERSION,
5
- SessionMode,
6
- ShutdownStatus
7
- } from "./chunk-7EQKHVQX.js";
2
+ IPCClient
3
+ } from "./chunk-MHQ3CVEB.js";
4
+ import {
5
+ TunnelAlreadyRunningError,
6
+ TunnelManager,
7
+ TunnelRebuildInProgressError
8
+ } from "./chunk-3WMTTJHI.js";
9
+ import {
10
+ ensureDaemonRunning,
11
+ getDaemonInfo,
12
+ getInProcessDaemonHandle,
13
+ ipcMismatchMessage,
14
+ isIpcCompatible,
15
+ printDaemonVersionNoticeOnce
16
+ } from "./chunk-4XXAHYCJ.js";
17
+ import {
18
+ SessionMode
19
+ } from "./chunk-MKGD2QAI.js";
8
20
  import {
9
21
  ErrorCode,
10
22
  NewErrorResponseObject,
11
23
  NewResponseObject,
12
24
  RemoteManagementStatus,
13
- TunnelAlreadyRunningError,
14
- TunnelManager,
15
- TunnelRebuildInProgressError,
16
25
  errorMessage,
17
- getLocalAddress,
18
26
  getVersion,
19
27
  isErrorResponse,
20
28
  isValidPort,
@@ -22,14 +30,10 @@ import {
22
30
  newStats,
23
31
  newStatus,
24
32
  printer_default
25
- } from "./chunk-QNUVQ6KD.js";
33
+ } from "./chunk-HTIWY3O5.js";
26
34
  import {
27
35
  logger
28
- } from "./chunk-MV56U3E6.js";
29
- import {
30
- getDaemonInfoPath,
31
- getDaemonLogPath
32
- } from "./chunk-AFMTIELL.js";
36
+ } from "./chunk-LWCVB42S.js";
33
37
 
34
38
  // src/remote_management/remote_schema.ts
35
39
  import { HaProxyVersion, TunnelType } from "@pinggy/pinggy";
@@ -1500,211 +1504,6 @@ function setRemoteManagementState(state, errorMessage2) {
1500
1504
  };
1501
1505
  }
1502
1506
 
1503
- // src/daemon/lifecycle/daemonManager.ts
1504
- import os from "os";
1505
- import fs from "fs";
1506
- import { spawn } from "child_process";
1507
- var inProcessHandle = null;
1508
- var DAEMON_SPAWN_TIMEOUT_MS = 8e3;
1509
- var DAEMON_POLL_INTERVAL_MS = 200;
1510
- function isProcessAlive(pid) {
1511
- try {
1512
- process.kill(pid, 0);
1513
- return true;
1514
- } catch {
1515
- return false;
1516
- }
1517
- }
1518
- function getDaemonInfo() {
1519
- const infoPath = getDaemonInfoPath();
1520
- if (!fs.existsSync(infoPath)) return null;
1521
- try {
1522
- const data = JSON.parse(fs.readFileSync(infoPath, "utf-8"));
1523
- if (!data.pid || !data.port) return null;
1524
- if (!isProcessAlive(data.pid)) {
1525
- logger.info("Stale daemon.json found, cleaning up", { stalePid: data.pid });
1526
- try {
1527
- fs.unlinkSync(infoPath);
1528
- } catch {
1529
- }
1530
- return null;
1531
- }
1532
- return data;
1533
- } catch {
1534
- return null;
1535
- }
1536
- }
1537
- function isDaemonRunning() {
1538
- return getDaemonInfo() !== null;
1539
- }
1540
- function daemonIpcVersion(info) {
1541
- return info.ipcVersion ?? 0;
1542
- }
1543
- function isIpcCompatible(info) {
1544
- return daemonIpcVersion(info) === IPC_VERSION;
1545
- }
1546
- function ipcMismatchMessage(info) {
1547
- const versions = `daemon IPC v${daemonIpcVersion(info)}, this CLI expects v${IPC_VERSION}`;
1548
- if (info.host === DaemonHost.APP) {
1549
- return `The Pinggy app is running a daemon from a different version (${versions}). Update or restart the Pinggy app.`;
1550
- }
1551
- return `A daemon from a different Pinggy CLI version is running (PID ${info.pid}; ${versions}). Run "pinggy daemon stop" and retry. This stops all running tunnels.`;
1552
- }
1553
- function getDaemonSpawnArgs() {
1554
- return {
1555
- command: process.execPath,
1556
- args: [process.argv[1], "--_daemon-child"],
1557
- env: { ...process.env }
1558
- };
1559
- }
1560
- async function startDaemon() {
1561
- const existing = getDaemonInfo();
1562
- if (existing) {
1563
- return existing;
1564
- }
1565
- const { command, args, env } = getDaemonSpawnArgs();
1566
- logger.info("Spawning daemon child", { command, args });
1567
- let stderrOutput = "";
1568
- let exited = false;
1569
- let exitCode = null;
1570
- const child = spawn(command, args, {
1571
- detached: true,
1572
- stdio: ["ignore", "ignore", "pipe"],
1573
- env,
1574
- ...os.platform() === "win32" ? { windowsHide: true } : {}
1575
- });
1576
- child.stderr?.on("data", (chunk) => {
1577
- stderrOutput += chunk.toString("utf-8");
1578
- });
1579
- child.on("exit", (code) => {
1580
- exited = true;
1581
- exitCode = code;
1582
- });
1583
- child.unref();
1584
- const info = await pollForDaemonInfo(DAEMON_SPAWN_TIMEOUT_MS, () => exited);
1585
- if (!info) {
1586
- const logPath = getDaemonLogPath();
1587
- if (exited) {
1588
- const detail = stderrOutput.trim() || `Check ${logPath} for details.`;
1589
- throw new Error(`Daemon child exited with code ${exitCode}. ${detail}`);
1590
- }
1591
- throw new Error(`Daemon failed to start within timeout. Check ${logPath} for details.`);
1592
- }
1593
- child.stderr?.removeAllListeners();
1594
- child.stderr?.destroy();
1595
- return info;
1596
- }
1597
- async function ensureDaemonRunning() {
1598
- const existing = getDaemonInfo();
1599
- if (existing) {
1600
- if (!isIpcCompatible(existing)) throw new Error(ipcMismatchMessage(existing));
1601
- return existing;
1602
- }
1603
- if (process.versions.electron) {
1604
- const { runDaemonChild } = await import("./daemonChild-WHS676G4.js");
1605
- const handle = await runDaemonChild({
1606
- installSignalHandlers: false,
1607
- exitOnFailure: false,
1608
- host: DaemonHost.APP
1609
- });
1610
- inProcessHandle = handle;
1611
- return getDaemonInfo() ?? {
1612
- pid: handle.pid,
1613
- port: handle.port,
1614
- startedAt: (/* @__PURE__ */ new Date()).toISOString(),
1615
- host: DaemonHost.APP,
1616
- ipcVersion: IPC_VERSION
1617
- };
1618
- }
1619
- return startDaemon();
1620
- }
1621
- function getInProcessDaemonHandle() {
1622
- return inProcessHandle;
1623
- }
1624
- async function getActiveTunnelSummaries(origin = "app") {
1625
- const info = getDaemonInfo();
1626
- if (!info) return [];
1627
- const { IPCClient: IPCClient2 } = await import("./ipcClient-XGF2KCQO.js");
1628
- const client = new IPCClient2(info.port, origin);
1629
- let tunnels;
1630
- try {
1631
- tunnels = await client.listTunnels();
1632
- } catch (err) {
1633
- logger.warn("Failed to list tunnels from daemon", { error: errorMessage(err) });
1634
- return [];
1635
- }
1636
- if (!Array.isArray(tunnels)) return [];
1637
- return tunnels.filter((t) => {
1638
- const state = t?.status?.state;
1639
- return state !== "closed" /* Closed */ && state !== "exited" /* Exited */;
1640
- }).map((t) => ({
1641
- tunnelId: t.tunnelid,
1642
- name: t.tunnelconfig?.name || t.tunnelid.slice(0, 8),
1643
- localAddress: getLocalAddress(t.tunnelconfig),
1644
- urls: t.remoteurls ?? []
1645
- }));
1646
- }
1647
- function pollForDaemonInfo(timeoutMs, hasExited) {
1648
- return new Promise((resolve) => {
1649
- const start = Date.now();
1650
- const check = () => {
1651
- const info = getDaemonInfo();
1652
- if (info) {
1653
- resolve(info);
1654
- return;
1655
- }
1656
- if (hasExited?.()) {
1657
- resolve(null);
1658
- return;
1659
- }
1660
- if (Date.now() - start > timeoutMs) {
1661
- resolve(null);
1662
- return;
1663
- }
1664
- setTimeout(check, DAEMON_POLL_INTERVAL_MS);
1665
- };
1666
- check();
1667
- });
1668
- }
1669
- async function stopDaemon() {
1670
- const info = getDaemonInfo();
1671
- if (!info) return { ok: false, error: "No daemon is running." };
1672
- let daemonErrors = [];
1673
- try {
1674
- const { IPCClient: IPCClient2 } = await import("./ipcClient-XGF2KCQO.js");
1675
- const client = new IPCClient2(info.port);
1676
- const result = await client.shutdown();
1677
- logger.debug("Sent shutdown command to daemon", { result });
1678
- if (result?.status === ShutdownStatus.RefusedInApp) {
1679
- return {
1680
- ok: false,
1681
- reason: DaemonHost.APP,
1682
- error: "The daemon is running inside the Pinggy app."
1683
- };
1684
- }
1685
- if (Array.isArray(result?.errors)) daemonErrors = result.errors;
1686
- } catch (e) {
1687
- return { ok: false, error: `Failed to reach daemon: ${errorMessage(e)}` };
1688
- }
1689
- const exited = await waitForExit(info.pid, 5e3);
1690
- if (!exited) {
1691
- const detail = daemonErrors.length > 0 ? ` Daemon reported: ${daemonErrors.join("; ")}` : "";
1692
- return { ok: false, error: `Daemon PID ${info.pid} did not exit within 5s.${detail}` };
1693
- }
1694
- if (daemonErrors.length > 0) {
1695
- return { ok: false, error: `Daemon exited but reported errors: ${daemonErrors.join("; ")}` };
1696
- }
1697
- return { ok: true };
1698
- }
1699
- async function waitForExit(pid, timeoutMs) {
1700
- const deadline = Date.now() + timeoutMs;
1701
- while (Date.now() < deadline) {
1702
- if (!isProcessAlive(pid)) return true;
1703
- await new Promise((r) => setTimeout(r, 100));
1704
- }
1705
- return !isProcessAlive(pid);
1706
- }
1707
-
1708
1507
  // src/daemon/ws/wsStream.ts
1709
1508
  import { WebSocket as WebSocket2 } from "ws";
1710
1509
  var WS_NORMAL_CLOSE = 1e3;
@@ -2086,15 +1885,42 @@ var TunnelClient = class _TunnelClient {
2086
1885
  this.shimDisconnectListeners = /* @__PURE__ */ new Map();
2087
1886
  this.shimSubscribedTunnels = /* @__PURE__ */ new Set();
2088
1887
  this.shimListenerSeq = 0;
1888
+ this.boundDaemon = null;
2089
1889
  this.origin = options.origin ?? "cli";
1890
+ this.printVersionNotice = options.printVersionNotice ?? printDaemonVersionNoticeOnce;
2090
1891
  this.stream = new WsStream(() => {
2091
1892
  if (!this.ipc) throw new Error("TunnelClient not initialized. Call ensureDaemon() first.");
2092
1893
  return this.ipc.getWsUrl();
2093
1894
  });
2094
1895
  this.health = new DaemonHealth(() => this.ipc, this.stream);
2095
1896
  }
2096
- async ensureDaemon() {
2097
- const info = await ensureDaemonRunning();
1897
+ /**
1898
+ * @param options.holdVersionNotice leaves the "daemon runs an older version" line for `printHeldVersionNotice()`.
1899
+ * A caller with a spinner running uses this, so the line does not land on the spinner.
1900
+ */
1901
+ async ensureDaemon(options = {}) {
1902
+ this.bindDaemon(await ensureDaemonRunning());
1903
+ if (!options.holdVersionNotice) this.printHeldVersionNotice();
1904
+ }
1905
+ printHeldVersionNotice() {
1906
+ if (this.boundDaemon) this.printVersionNotice(this.boundDaemon);
1907
+ }
1908
+ /**
1909
+ * Connects to the daemon that runs now, and never starts one. For commands that only read state.
1910
+ * Throws when that daemon speaks another IPC version, as ensureDaemon() does.
1911
+ *
1912
+ * @returns false when no daemon runs
1913
+ */
1914
+ connectIfRunning() {
1915
+ const info = getDaemonInfo();
1916
+ if (!info) return false;
1917
+ if (!isIpcCompatible(info)) throw new Error(ipcMismatchMessage(info));
1918
+ this.bindDaemon(info);
1919
+ this.printHeldVersionNotice();
1920
+ return true;
1921
+ }
1922
+ bindDaemon(info) {
1923
+ this.boundDaemon = info;
2098
1924
  this.ipc = new IPCClient(info.port, this.origin);
2099
1925
  this.health.bindPid(info.pid);
2100
1926
  this.health.reset();
@@ -2374,15 +2200,5 @@ export {
2374
2200
  closeRemoteManagement,
2375
2201
  startRemoteManagement,
2376
2202
  getRemoteManagementState,
2377
- getDaemonInfo,
2378
- isDaemonRunning,
2379
- daemonIpcVersion,
2380
- isIpcCompatible,
2381
- ipcMismatchMessage,
2382
- startDaemon,
2383
- ensureDaemonRunning,
2384
- getInProcessDaemonHandle,
2385
- getActiveTunnelSummaries,
2386
- stopDaemon,
2387
2203
  TunnelClient
2388
2204
  };
@@ -22,9 +22,9 @@ import {
22
22
  validateName,
23
23
  validateNameForStorage,
24
24
  validateNameStrict
25
- } from "./chunk-Y435RMHQ.js";
26
- import "./chunk-MV56U3E6.js";
27
- import "./chunk-AFMTIELL.js";
25
+ } from "./chunk-2GIJXE4K.js";
26
+ import "./chunk-LWCVB42S.js";
27
+ import "./chunk-MAK5R4WQ.js";
28
28
  export {
29
29
  CONFIG_VERBS,
30
30
  ConfigVerb,
@@ -3,31 +3,31 @@ import {
3
3
  removeDaemonInfo,
4
4
  runDaemonChild,
5
5
  setDaemonSessionTracker,
6
- trackDeviceAgentStart,
7
- trackDeviceAgentStop,
8
6
  trackIPCTunnelStart,
9
7
  trackTunnelStart,
10
8
  trackTunnelStop
11
- } from "./chunk-UVJYL2ZN.js";
12
- import "./chunk-CIOYQU7F.js";
13
- import "./chunk-PD7HXVQ3.js";
14
- import {
15
- DaemonHost
16
- } from "./chunk-7EQKHVQX.js";
17
- import "./chunk-Y435RMHQ.js";
9
+ } from "./chunk-HAFTH5MX.js";
10
+ import "./chunk-Q5NCTGNS.js";
11
+ import "./chunk-CZOKR73F.js";
12
+ import "./chunk-MHQ3CVEB.js";
13
+ import "./chunk-2GIJXE4K.js";
18
14
  import "./chunk-XZ64ZAGO.js";
19
- import "./chunk-QNUVQ6KD.js";
15
+ import "./chunk-3WMTTJHI.js";
20
16
  import "./chunk-UB26QJ4T.js";
21
- import "./chunk-MV56U3E6.js";
22
- import "./chunk-AFMTIELL.js";
17
+ import "./chunk-FQ22KFVV.js";
18
+ import "./chunk-4XXAHYCJ.js";
19
+ import {
20
+ DaemonHost
21
+ } from "./chunk-MKGD2QAI.js";
22
+ import "./chunk-HTIWY3O5.js";
23
+ import "./chunk-LWCVB42S.js";
24
+ import "./chunk-MAK5R4WQ.js";
23
25
  export {
24
26
  DaemonHost,
25
27
  getDaemonHost,
26
28
  removeDaemonInfo,
27
29
  runDaemonChild,
28
30
  setDaemonSessionTracker,
29
- trackDeviceAgentStart,
30
- trackDeviceAgentStop,
31
31
  trackIPCTunnelStart,
32
32
  trackTunnelStart,
33
33
  trackTunnelStop
@@ -0,0 +1,17 @@
1
+ import {
2
+ configuredLogLevel,
3
+ forgetDeviceAgent,
4
+ readDaemonConfig,
5
+ saveDeviceAgent,
6
+ savedDeviceAgent,
7
+ writeDaemonConfig
8
+ } from "./chunk-CZOKR73F.js";
9
+ import "./chunk-MAK5R4WQ.js";
10
+ export {
11
+ configuredLogLevel,
12
+ forgetDeviceAgent,
13
+ readDaemonConfig,
14
+ saveDeviceAgent,
15
+ savedDeviceAgent,
16
+ writeDaemonConfig
17
+ };