@omarestrella/panes 0.0.0-stage → 0.1.1

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 (3) hide show
  1. package/README.md +20 -2
  2. package/package.json +26 -4
  3. package/panes.js +232 -0
package/README.md CHANGED
@@ -1,3 +1,21 @@
1
- # Temporary Holding Version
1
+ # @omarestrella/panes
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Runs a [Rex](https://www.superlogical.com/rex/) server for [Panes](https://github.com/omarestrella/panes), the extension that syncs tab groups between browsers.
4
+
5
+ ```sh
6
+ npx @omarestrella/panes
7
+ ```
8
+
9
+ `bunx` and `pnpx` work too. You need Rex 1.0.1+ on your `PATH`, and Node 20+ or Bun.
10
+
11
+ This server is separate from any other Rex server on the machine. Its sessions are your shared tab groups, and it only listens on your tailnet, as a device called `panes`. The first time it runs, it prints a Tailscale link to approve it. Then it prints its address. Enter that address in the Panes popup (the cog) on each computer. They all need to be on the same tailnet.
12
+
13
+ | Option | |
14
+ | --- | --- |
15
+ | `--hostname NAME` | the device name on your tailnet (default `panes`) |
16
+ | `--state-dir DIR` | where it keeps its sessions and Tailscale identity. Defaults to `~/Library/Application Support/Panes/server` on macOS and `~/.local/state/panes/server` elsewhere. |
17
+ | `--extension-id ID` | allow another extension ID. Can be repeated. |
18
+
19
+ It runs in the foreground. Ctrl-C stops it, and your groups are still there next time.
20
+
21
+ MIT licensed. Panes isn't affiliated with Superlogical, who make Rex.
package/package.json CHANGED
@@ -1,6 +1,28 @@
1
1
  {
2
2
  "name": "@omarestrella/panes",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "Runs a Rex server for the Panes browser extension, reachable over your tailnet.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "bin": {
8
+ "panes": "panes.js"
9
+ },
10
+ "files": [
11
+ "panes.js",
12
+ "README.md"
13
+ ],
14
+ "engines": {
15
+ "node": ">=20"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/omarestrella/panes.git"
20
+ },
21
+ "homepage": "https://github.com/omarestrella/panes",
22
+ "keywords": [
23
+ "rex",
24
+ "tab-groups",
25
+ "browser-sync",
26
+ "tailscale"
27
+ ]
28
+ }
package/panes.js ADDED
@@ -0,0 +1,232 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/server/cli.ts
4
+ import { spawn, spawnSync } from "node:child_process";
5
+ import fs from "node:fs";
6
+ import os from "node:os";
7
+ import path from "node:path";
8
+ // extension/ids.json
9
+ var ids_default = {
10
+ dev: "pkidibccclnpepdjndefoegohbflekpe",
11
+ store: null
12
+ };
13
+
14
+ // src/product.ts
15
+ var VERSION = "0.1.1";
16
+ var EXTENSION_IDS = [ids_default.dev, ids_default.store].filter((x) => typeof x === "string" && x.length === 32);
17
+
18
+ // src/server/cli.ts
19
+ var HELP = `panes ${VERSION}: run a Rex server for the Panes browser extension
20
+
21
+ Usage: npx @omarestrella/panes [options]
22
+
23
+ --hostname NAME the server's device name on your tailnet (default: panes)
24
+ --state-dir DIR where the server keeps its sessions and Tailscale identity
25
+ (default: ${defaultStateDir("panes")})
26
+ --extension-id ID also allow this extension ID (repeatable)
27
+ -h, --help show this help
28
+ `;
29
+ function defaultStateDir(hostname) {
30
+ const home = os.homedir();
31
+ const base = process.platform === "darwin" ? path.join(home, "Library/Application Support/Panes") : path.join(process.env.XDG_STATE_HOME || path.join(home, ".local/state"), "panes");
32
+ return path.join(base, hostname === "panes" ? "server" : `server-${hostname}`);
33
+ }
34
+ function fail(message) {
35
+ console.error(`panes: ${message}`);
36
+ process.exit(1);
37
+ }
38
+ var args = process.argv.slice(2);
39
+ var HOSTNAME = "panes";
40
+ var STATE = null;
41
+ var ids = [...EXTENSION_IDS];
42
+ for (let i = 0;i < args.length; i++) {
43
+ const a = args[i];
44
+ const value = () => args[++i] ?? fail(`${a} needs a value`);
45
+ if (a === "-h" || a === "--help") {
46
+ process.stdout.write(HELP);
47
+ process.exit(0);
48
+ } else if (a === "--hostname")
49
+ HOSTNAME = value();
50
+ else if (a === "--state-dir")
51
+ STATE = path.resolve(value());
52
+ else if (a === "--extension-id")
53
+ ids.push(value());
54
+ else
55
+ fail(`unknown option ${a} (see --help)`);
56
+ }
57
+ if (!/^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/.test(HOSTNAME))
58
+ fail("--hostname takes a tailnet device name: lowercase letters, digits and dashes");
59
+ for (const id of ids)
60
+ if (!/^[a-p]{32}$/.test(id))
61
+ fail(`${id} isn't an extension ID (32 letters from a to p)`);
62
+ if (process.platform === "win32")
63
+ fail("Windows isn't supported yet");
64
+ var STATE_DIR = STATE ?? defaultStateDir(HOSTNAME);
65
+ var SOCKET = path.join(process.env.XDG_RUNTIME_DIR || os.tmpdir(), `panes-server-${HOSTNAME}.sock`);
66
+ var probe = spawnSync("rex", ["server", "run", "--help"], { encoding: "utf8" });
67
+ if (probe.error)
68
+ fail(probe.error.code === "ENOENT" ? "rex isn't installed, or isn't on your PATH. Install Rex first: https://www.superlogical.com/rex/" : `couldn't run rex: ${probe.error.message}`);
69
+ if (!`${probe.stdout}${probe.stderr}`.includes("--websocket-origin-pattern"))
70
+ fail("this Rex is too old for Panes. Update Rex to 1.0.1 or newer.");
71
+ var tty = process.stdout.isTTY && !process.env.NO_COLOR;
72
+ var out = (s) => process.stdout.write(s);
73
+ var RAINBOW = [196, 202, 208, 214, 220, 226, 190, 154, 118, 82, 46, 48, 50, 51, 45, 39, 33, 27, 57, 93, 129, 165, 201, 199];
74
+ var ART = [
75
+ "╭─────────────╮",
76
+ "│ ● ● ● │",
77
+ "├──────┬──────┤",
78
+ "│░░░░░░│▒▒▒▒▒▒│",
79
+ "│░░░░░░│▒▒▒▒▒▒│",
80
+ "│░░░░░░│▒▒▒▒▒▒│",
81
+ "│░░░░░░│▒▒▒▒▒▒│",
82
+ "╰──────┴──────╯"
83
+ ];
84
+ var BESIDE = ["", "", "", "\x1B[1mPanes\x1B[0m server", "\x1B[2ma Rex server just for Panes\x1B[0m", "", "", ""];
85
+ var dim = (s) => tty ? `\x1B[2m${s}\x1B[0m` : s;
86
+ var bold = (s) => tty ? `\x1B[1m${s}\x1B[0m` : s;
87
+ var plain = (s) => s.replace(/\x1b\[[0-9;]*m/g, "");
88
+ var tick = 0;
89
+ function bannerLine(i) {
90
+ const art = tty ? [...ART[i]].map((ch, x) => `\x1B[38;5;${RAINBOW[(x + i + tick) % RAINBOW.length]}m${ch}`).join("") + "\x1B[0m" : ART[i];
91
+ const beside = tty ? BESIDE[i] : plain(BESIDE[i]);
92
+ return ` ${art}${beside ? ` ${beside}` : ""}`;
93
+ }
94
+ var below = 0;
95
+ var spinning = null;
96
+ var FRAMES = "⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏";
97
+ function line(s = "") {
98
+ if (spinning !== null && tty)
99
+ out("\r\x1B[2K");
100
+ out(`${s}
101
+ `);
102
+ below += 1 + Math.floor(plain(s).length / (process.stdout.columns || 80));
103
+ drawSpinner();
104
+ }
105
+ function drawSpinner() {
106
+ if (spinning === null)
107
+ return;
108
+ if (tty)
109
+ out(`\r\x1B[2K ${`\x1B[38;5;${RAINBOW[tick % RAINBOW.length]}m${FRAMES[tick % FRAMES.length]}\x1B[0m`} ${spinning}`);
110
+ }
111
+ function step(s) {
112
+ if (tty) {
113
+ if (spinning !== null)
114
+ out("\r\x1B[2K");
115
+ spinning = s;
116
+ drawSpinner();
117
+ } else {
118
+ spinning = null;
119
+ line(` … ${s}`);
120
+ }
121
+ }
122
+ function done(s, mark = "✓") {
123
+ if (tty && spinning !== null)
124
+ out("\r\x1B[2K");
125
+ spinning = null;
126
+ line(` ${tty ? `\x1B[32m${mark}\x1B[0m` : mark} ${s}`);
127
+ }
128
+ var animation = tty ? setInterval(() => {
129
+ tick++;
130
+ const up = below + ART.length;
131
+ if (up + 1 < (process.stdout.rows || 24)) {
132
+ out(`\x1B7\x1B[${up}F`);
133
+ for (let i = 0;i < ART.length; i++)
134
+ out(`\x1B[2K${bannerLine(i)}
135
+ `);
136
+ out("\x1B8");
137
+ }
138
+ drawSpinner();
139
+ }, 90) : null;
140
+ out(`
141
+ `);
142
+ for (let i = 0;i < ART.length; i++)
143
+ out(`${bannerLine(i)}
144
+ `);
145
+ line();
146
+ line(` This runs a Rex server just for Panes, apart from any other Rex`);
147
+ line(` server on this machine. It keeps its own sessions, and listens on`);
148
+ line(` nothing but your tailnet, as a device named ${bold(HOSTNAME)}.`);
149
+ line();
150
+ fs.mkdirSync(STATE_DIR, { recursive: true, mode: 448 });
151
+ var rex = spawn("rex", [
152
+ "server",
153
+ "run",
154
+ "--listen",
155
+ `unix://${SOCKET}`,
156
+ "--state-dir",
157
+ STATE_DIR,
158
+ "--tailscale",
159
+ "--tailscale-hostname",
160
+ HOSTNAME,
161
+ ...[...new Set(ids)].flatMap((id) => ["--websocket-origin-pattern", id])
162
+ ], { stdio: ["ignore", "pipe", "pipe"] });
163
+ step("Starting the Rex server…");
164
+ var phase = "starting";
165
+ var finish = () => {
166
+ if (animation)
167
+ clearInterval(animation);
168
+ if (tty && spinning !== null)
169
+ out("\r\x1B[2K");
170
+ spinning = null;
171
+ };
172
+ function onLog(l) {
173
+ const login = l.match(/https:\/\/login\.tailscale\.com\/\S+/);
174
+ const ready = l.match(/tailnet https listener ready.*url=https:\/\/(\S+)/);
175
+ if (phase === "starting" && /Rex server ready/.test(l)) {
176
+ done("Rex server started");
177
+ phase = "joining";
178
+ step(`Joining your tailnet as ${HOSTNAME}…`);
179
+ } else if (login && phase !== "approval" && phase !== "ready") {
180
+ phase = "approval";
181
+ done("Tailscale needs your approval", "!");
182
+ line(` The first time, Tailscale asks you to approve this server as a new`);
183
+ line(` device on your tailnet, as it would for a new computer. Open this`);
184
+ line(` link and sign in:`);
185
+ line();
186
+ line(` ${bold(login[0])}`);
187
+ line();
188
+ step("Waiting for you to approve it…");
189
+ } else if (/requesting tailnet https certificate/.test(l) && phase !== "ready") {
190
+ done(phase === "approval" ? "Approved: the server is on your tailnet" : "On your tailnet");
191
+ phase = "certificate";
192
+ step("Getting an HTTPS certificate (the first time can take a minute)…");
193
+ } else if (ready) {
194
+ phase = "ready";
195
+ done(`Ready at ${bold(ready[1])}`);
196
+ finish();
197
+ line();
198
+ line(` Next, in the Panes extension, open the cog in its popup and enter:`);
199
+ line(` ${bold(ready[1])}`);
200
+ line(` Each computer you use Panes on must be on this tailnet.`);
201
+ line();
202
+ line(dim(` Ctrl-C stops the server. Its groups are kept for next time, in`));
203
+ line(dim(` ${STATE_DIR}`));
204
+ } else if (/\bERROR\b/.test(l)) {
205
+ line(dim(` ${l.replace(/^\S+ \S+ /, "").slice(0, (process.stdout.columns || 80) - 6)}`));
206
+ }
207
+ }
208
+ var buf = "";
209
+ var read = (chunk) => {
210
+ buf += chunk.toString();
211
+ for (let i = buf.indexOf(`
212
+ `);i >= 0; i = buf.indexOf(`
213
+ `)) {
214
+ onLog(buf.slice(0, i));
215
+ buf = buf.slice(i + 1);
216
+ }
217
+ };
218
+ rex.stdout.on("data", read);
219
+ rex.stderr.on("data", read);
220
+ rex.on("error", (e) => {
221
+ finish();
222
+ done(`couldn't start rex: ${e.message}`, "✗");
223
+ process.exit(1);
224
+ });
225
+ rex.on("exit", (code) => {
226
+ finish();
227
+ if (phase !== "ready" || code)
228
+ line(` The Rex server stopped${code ? ` (exit code ${code})` : ""}.`);
229
+ process.exit(code ?? 0);
230
+ });
231
+ for (const sig of ["SIGINT", "SIGTERM"])
232
+ process.on(sig, () => rex.kill("SIGTERM"));