diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cd2609..e079ffb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ GitHub release vX.Y.Z. ### Added +- **Linux server.** God Mode runs on a Linux Paseo daemon: Address → Connect finds a packaged or + Linuxbrew `cloudflared`, or downloads Cloudflare's Linux build (amd64, arm64, arm, 386) instead of + the macOS archive, which could not run there. The sign-in link opens on the device you pressed the + button on, so a server without a desktop needs nothing more. The voice buttons stay Mac and iPhone only. - **Claude voice button.** A second voice button, off until **Claude voice in Paseo** is turned on: one tap brings the Claude desktop app forward and presses its voice mode button through Accessibility, opening a new chat first when Claude is elsewhere. It finds the button by several signals, not only diff --git a/README.md b/README.md index 20b9273..8baf0a8 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ your phone, your car or a walk, while your Mac does the work. [![Licence](https://img.shields.io/github/license/devXpro/paseo-god-mode-plugin?style=flat-square&color=111111&labelColor=111111&label=licence)](LICENSE) [![Status](https://img.shields.io/badge/status-building%20in%20public-ffb020?style=flat-square&labelColor=111111)](#status) -🎙️ **Voice or chat, in Claude or ChatGPT** · 🧠 **Every agent, every project** · 🧩 **Your Paseo plugins too** · 🔘 **Three buttons, no terminal** · 🔐 **Your own tunnel and sign-in** · ⚡ **Straight to Paseo on your Mac or Windows** +🎙️ **Voice or chat, in Claude or ChatGPT** · 🧠 **Every agent, every project** · 🧩 **Your Paseo plugins too** · 🔘 **Three buttons, no terminal** · 🔐 **Your own tunnel and sign-in** · ⚡ **Straight to Paseo on your Mac, Windows or Linux server** @@ -36,7 +36,8 @@ The same works in ChatGPT, typed or in its voice mode. ## Quick start You need: -- a Mac running **Paseo 0.15.4** or newer, awake and online while you use God Mode; +- a Mac, a Windows PC or a Linux server running **Paseo 0.15.4** or newer, awake and online while you + use God Mode (on Linux everything but the voice buttons); - a domain in your own **Cloudflare** account (the free plan is enough): God Mode puts its address there, for example `gm.example.com`; - **Claude** (custom connectors; voice mode in the phone app), **ChatGPT** Plus or Pro (custom MCP diff --git a/docs/configuration.md b/docs/configuration.md index 37ba587..563f188 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -5,8 +5,9 @@ button on its screen does, what it needs, and what God Mode keeps on the Mac. ## What you need -- A Mac running **Paseo 0.15.4** or newer with plugins on. The Mac has to be awake and online while - Claude or ChatGPT uses God Mode. +- A Mac, a Windows PC or a Linux server running **Paseo 0.15.4** or newer with plugins on. It has to + be awake and online while Claude or ChatGPT uses God Mode. On a Linux server everything but the voice + buttons works: the address, Claude and ChatGPT, and every tool; see [Linux server](#linux-server). - A domain in your own **Cloudflare** account. The free plan is enough; Cloudflare Registrar sells domains at cost. Keep that account to yourself and protect it with two-factor sign-in: whoever can edit its DNS or tunnels controls the address (see [security](security.md#the-tunnel-and-cloudflare)). @@ -20,9 +21,10 @@ button on its screen does, what it needs, and what God Mode keeps on the Mac. **Address → Connect** on God Mode's screen: -1. God Mode looks for `cloudflared` (Homebrew's, or its own copy in `~/.paseo/god-mode/bin/`). If it - is missing, it installs it with `brew install cloudflared`, or without Homebrew (and always on - Windows) downloads Cloudflare's release build. +1. God Mode looks for `cloudflared` (Homebrew's, on Linux also a package's in `/usr/local/bin` or + `/usr/bin`, or its own copy in `~/.paseo/god-mode/bin/`). If it is missing, it installs it with + `brew install cloudflared`, or without Homebrew (and always on Windows) downloads Cloudflare's + release build for the system: `cloudflared-linux-amd64` or `-arm64` on Linux. 2. Cloudflare's sign-in page opens on the device where you pressed the button. Sign in, pick the domain, press **Authorize**. The link is good for about ten minutes; press Connect again for a new one. 3. God Mode creates a tunnel named `god-mode`, points `gm.` at it, deletes the sign-in @@ -62,6 +64,14 @@ ChatGPT's voice mode uses the plugins of your account, God Mode included. connected again with a new code. Removing the connector in Claude or ChatGPT does not sign it out on the Mac; use Disconnect for that. +## Linux server + +God Mode runs the same on a Linux server with the Paseo daemon, for example a VPS kept apart from your +own computer. Nothing opens a browser on the server: press **Address → Connect** in Paseo on your Mac +or phone, and Cloudflare's sign-in link opens there. God Mode downloads `cloudflared` into its data +directory unless one is already installed (a `.deb`/`.rpm` from Cloudflare, or Linuxbrew). The voice +buttons need a Mac or an iPhone, so on a Linux daemon they report that they are not supported. + ## What God Mode keeps on the Mac Everything is in `~/.paseo/god-mode/` (under `PASEO_HOME` if Paseo uses another home), readable only by diff --git a/server/tunnel/cloudflared.test.ts b/server/tunnel/cloudflared.test.ts index fd2b4b3..9e38efb 100644 --- a/server/tunnel/cloudflared.test.ts +++ b/server/tunnel/cloudflared.test.ts @@ -1,6 +1,22 @@ import assert from "node:assert/strict"; import { test } from "node:test"; -import { configText, routedHostname } from "./cloudflared.ts"; +import { cloudflaredPaths, configText, releaseAsset, routedHostname } from "./cloudflared.ts"; + +test("each system downloads its own cloudflared build, packed only on macOS", () => { + assert.deepEqual(releaseAsset("darwin", "arm64"), { name: "cloudflared-darwin-arm64.tgz", packed: true }); + assert.deepEqual(releaseAsset("darwin", "x64"), { name: "cloudflared-darwin-amd64.tgz", packed: true }); + assert.deepEqual(releaseAsset("win32", "arm64"), { name: "cloudflared-windows-amd64.exe", packed: false }); + assert.deepEqual(releaseAsset("linux", "x64"), { name: "cloudflared-linux-amd64", packed: false }); + assert.deepEqual(releaseAsset("linux", "arm64"), { name: "cloudflared-linux-arm64", packed: false }); + assert.deepEqual(releaseAsset("linux", "arm"), { name: "cloudflared-linux-arm", packed: false }); + assert.throws(() => releaseAsset("linux", "riscv64"), /no cloudflared build for Linux on riscv64/); +}); + +test("Linux finds a packaged or Linuxbrew cloudflared before downloading one; macOS looks where it did", () => { + const own = "/home/me/.paseo/god-mode/bin/cloudflared"; + assert.deepEqual(cloudflaredPaths("linux", own), ["/usr/local/bin/cloudflared", "/usr/bin/cloudflared", "/home/linuxbrew/.linuxbrew/bin/cloudflared", own]); + assert.deepEqual(cloudflaredPaths("darwin", own), ["/opt/homebrew/bin/cloudflared", "/usr/local/bin/cloudflared", own]); +}); test("the hostname comes out of what `tunnel route dns` says, new or already there", () => { assert.equal(routedHostname("2026-11-16T13:24:33Z INF Added CNAME gm.devxpro.net which will route to this tunnel tunnelID=5f54"), "gm.devxpro.net"); diff --git a/server/tunnel/cloudflared.ts b/server/tunnel/cloudflared.ts index c8824ff..adbdab7 100644 --- a/server/tunnel/cloudflared.ts +++ b/server/tunnel/cloudflared.ts @@ -34,7 +34,8 @@ export interface TunnelStatus { const LOGIN_WAIT_MS = 10 * 60_000; const WINDOWS = process.platform === "win32"; -const BREW = ["/opt/homebrew/bin/brew", "/usr/local/bin/brew"]; +const LINUXBREW = "/home/linuxbrew/.linuxbrew/bin"; +const BREW = ["/opt/homebrew/bin/brew", "/usr/local/bin/brew", `${LINUXBREW}/brew`]; const tunnelDir = () => join(dataDir(), "tunnel"); const recordFile = () => join(dataDir(), "tunnel.json"); const configFile = () => join(tunnelDir(), "config.yml"); @@ -44,20 +45,41 @@ const pidFile = () => join(tunnelDir(), "cloudflared.pid"); const originCert = () => join(homedir(), ".cloudflared", "cert.pem"); const ownBinary = () => join(dataDir(), "bin", WINDOWS ? "cloudflared.exe" : "cloudflared"); -/** Where cloudflared is: Homebrew's, or the copy God Mode downloaded. */ +/** Where cloudflared may be, in order: Homebrew's, a Linux package's, then the copy God Mode downloaded. */ +export function cloudflaredPaths(platform: NodeJS.Platform, own: string): string[] { + if (platform === "linux") return ["/usr/local/bin/cloudflared", "/usr/bin/cloudflared", `${LINUXBREW}/cloudflared`, own]; + return ["/opt/homebrew/bin/cloudflared", "/usr/local/bin/cloudflared", own]; +} + +/** Where cloudflared is: Homebrew's, a Linux package's, or the copy God Mode downloaded. */ export function findCloudflared(): string | null { - return ["/opt/homebrew/bin/cloudflared", "/usr/local/bin/cloudflared", ownBinary()].find((path) => existsSync(path)) ?? null; + return cloudflaredPaths(process.platform, ownBinary()).find((path) => existsSync(path)) ?? null; } +/** Cloudflare's release build for this system, and whether it comes packed in a .tgz. Windows has no + * arm64 build, and the amd64 one runs under emulation; Linux and Windows builds are the binary itself. */ +export function releaseAsset(platform: NodeJS.Platform, cpu: string): { name: string; packed: boolean } { + if (platform === "win32") return { name: "cloudflared-windows-amd64.exe", packed: false }; + if (platform === "linux") { + const builds: Record = { x64: "amd64", arm64: "arm64", arm: "arm", ia32: "386" }; + const build = builds[cpu]; + if (!build) throw new Error(`Cloudflare has no cloudflared build for Linux on ${cpu}. Install cloudflared yourself, then press Connect again.`); + return { name: `cloudflared-linux-${build}`, packed: false }; + } + return { name: `cloudflared-darwin-${cpu === "arm64" ? "arm64" : "amd64"}.tgz`, packed: true }; +} + +/** `ps` is in /bin on macOS and on most Linux systems, and only in /usr/bin on some. */ +const psBinary = () => ["/bin/ps", "/usr/bin/ps"].find((path) => existsSync(path)) ?? "/bin/ps"; + async function install(): Promise { const brew = BREW.find((path) => existsSync(path)); if (brew) { const result = await run(brew, ["install", "cloudflared"], { timeoutMs: 10 * 60_000 }); if (!result.ok) throw new Error(`brew install cloudflared failed:\n${tail(result)}`); } else { - // Without Homebrew: Cloudflare's own release build, in God Mode's data directory. On Windows it is - // the .exe itself; there is no arm64 build, and the amd64 one runs under emulation. - const asset = WINDOWS ? "cloudflared-windows-amd64.exe" : `cloudflared-darwin-${arch() === "arm64" ? "arm64" : "amd64"}.tgz`; + // Without Homebrew: Cloudflare's own release build, in God Mode's data directory. + const { name: asset, packed } = releaseAsset(process.platform, arch()); const response = await fetch(`https://github.com/cloudflare/cloudflared/releases/latest/download/${asset}`); if (!response.ok) throw new Error(`Downloading ${asset} failed: HTTP ${response.status}`); const dir = join(dataDir(), "bin"); @@ -65,6 +87,9 @@ async function install(): Promise { const body = Buffer.from(await response.arrayBuffer()); if (WINDOWS) { await writeFile(ownBinary(), body); + } else if (!packed) { + await writeFile(ownBinary(), body, { mode: 0o755 }); + await chmod(ownBinary(), 0o755); } else { const archive = join(dir, asset); await writeFile(archive, body, { mode: 0o600 }); @@ -166,7 +191,8 @@ export class Tunnel { private signIn(binary: string): Promise<{ loginUrl: string; done: Promise }> { return new Promise((resolveLink, rejectLink) => { // A PATH without /usr/bin keeps cloudflared from opening a browser here: the link goes to the - // device the user pressed the button on. Windows ignores the case of variable names: Node keeps + // device the user pressed the button on (on Linux it keeps xdg-open out of reach the same way, so a + // server without a desktop just prints the link). Windows ignores the case of variable names: Node keeps // this PATH and drops the inherited Path, so cloudflared does not find cmd to open one either. const login = spawn(binary, ["tunnel", "login"], { env: { ...process.env, PATH: "/opt/homebrew/bin" }, stdio: ["ignore", "pipe", "pipe"] }); this.login = login; @@ -270,7 +296,7 @@ export class Tunnel { private async stopStray(): Promise { const pid = Number((await readFile(pidFile(), "utf8").catch(() => "")).trim()); if (!pid) return; - const command = await run("/bin/ps", ["-o", "command=", "-p", String(pid)]); + const command = await run(psBinary(), ["-o", "command=", "-p", String(pid)]); if (command.ok && command.stdout.includes("cloudflared") && command.stdout.includes(configFile())) { try { process.kill(pid);