getzopu 0.5.0 → 0.5.3

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 +32 -3
  2. package/dist/getzopu.mjs +171 -19
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -57,6 +57,34 @@ needs no `--package`; it provides the `getzopu` and `zopu` executables. Install
57
57
  with `npm publish --access public`; it takes `NPM_TOKEN` from the environment. Nothing is published
58
58
  from a tree that is not green on `master`.
59
59
 
60
+ ### Without the registry: get.zopu.live
61
+
62
+ The same program also goes to Zopu's own distribution origin, `https://get.zopu.live` — the public
63
+ face of the `zopu-dist` bucket — for a computer that cannot or should not wait on npm, whose review
64
+ of each publish can take a while. `scripts/publish-dist.sh` builds, packs and puts there:
65
+
66
+ - the program as **one file**, per version: `getzopu/<version>/getzopu.mjs`, with its `.sha256`;
67
+ - the npm tarball, per version: `tarballs/getzopu-<version>.tgz`;
68
+ - a manifest per version: `versions/<version>.json` (version, build, both addresses and hashes);
69
+ - the channel's pointers: `latest/manifest.json` and `getzopu/latest/getzopu.mjs`, never cached.
70
+
71
+ A version's files are immutable — the script refuses to replace one with a different program; bump
72
+ the version. A release version moves `latest`; a prerelease (`0.6.0-beta.1`) gets its own channel
73
+ (`latest-beta`). It needs `rclone` and the bucket's key (`ALL_CLOUDFLARE_R2_*` in the root `.env`),
74
+ runs only from a tree with no tracked edits, and downloads every address again before it reports.
75
+
76
+ To connect a computer with nothing but the runtime (Node 24+):
77
+
78
+ ```sh
79
+ curl -fsSL -o getzopu.mjs https://get.zopu.live/getzopu/latest/getzopu.mjs
80
+ node getzopu.mjs machines connect
81
+ ```
82
+
83
+ On Windows, in PowerShell: `curl.exe -fsSL -o getzopu.mjs <the same address>`, then
84
+ `node .\getzopu.mjs machines connect`. The service keeps its own copy of the file, so the download
85
+ may sit in any folder. For a `getzopu` command on the PATH instead:
86
+ `npm install -g https://get.zopu.live/tarballs/getzopu-<version>.tgz`.
87
+
60
88
  ### Machines
61
89
 
62
90
  `getzopu machines connect [--name <name>] [--url <url>] [--foreground]` pairs the computer when
@@ -64,8 +92,9 @@ it has no credential — a page to sign in to, a six-digit code to type there
64
92
  in `~/.config/zopu/machine/credential.json` (mode `0600`), and then installs the satellite as a
65
93
  service of your account and starts it, so the computer stays reachable with every window closed
66
94
  and after a restart: a launch agent on macOS (`~/Library/LaunchAgents/zopu-machines-<hash>.plist`),
67
- a systemd user unit on Linux (`~/.config/systemd/user/`, with `loginctl enable-linger` asked for).
68
- No root. The service runs a copy of this program kept under `~/.config/zopu/machine/`, with the
95
+ a systemd user unit on Linux (`~/.config/systemd/user/`, with `loginctl enable-linger` asked for),
96
+ a scheduled task on Windows (a hidden launcher hosts the program; it runs while you are signed in).
97
+ No administrator rights. The service runs a copy of this program kept under `~/.config/zopu/machine/`, with the
69
98
  runtime that ran `connect`, and writes to `satellite.log` there; it is restarted only when it
70
99
  crashes — a revoked or deliberately stopped satellite stays stopped. The service's name carries a
71
100
  hash of the machine's home, so a second Zopu on one computer never displaces the first. The shape
@@ -76,7 +105,7 @@ The satellite (`packages/machines/src/satellite/`) dials out to `/ws/machines` w
76
105
  as a bearer, comes back by itself after a drop (at once the first time, then on a ladder from 1 s
77
106
  to 30 s), and keeps a journal of every command it ran (`~/.config/zopu/machine/journal/`), so a
78
107
  command that outlives a drop is picked up where it was. Commands run as the user, in a process
79
- group of their own; nothing is scoped. `getzopu machines status` says whether the link is up, how
108
+ group of their own; nothing is scoped. On Windows the command runs in cmd.exe with no console window, and a stop ends its whole process tree. `getzopu machines status` says whether the link is up, how
80
109
  the service is, and the last lines of its log; `getzopu machines disconnect` stops and removes the
81
110
  service, revokes the computer on the server, and forgets the credential.
82
111
 
package/dist/getzopu.mjs CHANGED
@@ -362,7 +362,7 @@ var exports_machine = {};
362
362
  __export(exports_machine, {
363
363
  runMachine: () => runMachine
364
364
  });
365
- import { spawn as spawn3, spawnSync } from "node:child_process";
365
+ import { spawn as spawn3, spawnSync as spawnSync2 } from "node:child_process";
366
366
  import {
367
367
  chmodSync,
368
368
  lstatSync,
@@ -413,7 +413,7 @@ var SSHD_PATH = "/usr/sbin/sshd", AUTHORIZED_KEY_ENV = "SSH_AUTHORIZED_KEY", SSH
413
413
  chmodSync(authorizedKeys, 384);
414
414
  prepareCacheTree();
415
415
  mkdirSync("/run/sshd", { recursive: true });
416
- const hostKeys = spawnSync("ssh-keygen", ["-A"], { stdio: "inherit" });
416
+ const hostKeys = spawnSync2("ssh-keygen", ["-A"], { stdio: "inherit" });
417
417
  if (hostKeys.error !== undefined) {
418
418
  throw new BootstrapError(`cannot run ssh-keygen: ${hostKeys.error.message}`);
419
419
  }
@@ -751,7 +751,7 @@ Commands:
751
751
  });
752
752
 
753
753
  // src/cli.ts
754
- import { chmod as chmod2, lstat as lstat2, mkdir as mkdir5, readFile as readFile4, rename as rename2, rm as rm2, writeFile as writeFile5 } from "node:fs/promises";
754
+ import { chmod as chmod2, lstat as lstat2, mkdir as mkdir5, readFile as readFile4, rename as rename3, rm as rm2, writeFile as writeFile5 } from "node:fs/promises";
755
755
  import { homedir as homedir7 } from "node:os";
756
756
  import path6 from "node:path";
757
757
  import { parseArgs } from "node:util";
@@ -26411,7 +26411,8 @@ ${result3.text.slice(0, 4000)}` : "";
26411
26411
 
26412
26412
  // src/machines.ts
26413
26413
  import { spawn as spawn2 } from "node:child_process";
26414
- import { copyFile, mkdir as mkdir4, readFile as readFile3, stat as stat3, writeFile as writeFile4 } from "node:fs/promises";
26414
+ import { appendFileSync as appendFileSync2 } from "node:fs";
26415
+ import { copyFile, mkdir as mkdir4, readFile as readFile3, rename as rename2, stat as stat3, writeFile as writeFile4 } from "node:fs/promises";
26415
26416
  import { hostname as hostname2, platform as platform2 } from "node:os";
26416
26417
  import path4 from "node:path";
26417
26418
  import { setTimeout as pause } from "node:timers/promises";
@@ -26831,6 +26832,7 @@ var servicePath = (runtime, installerPath) => [
26831
26832
  ].filter((directory) => directory !== ""))
26832
26833
  ].join(path2.delimiter);
26833
26834
  var systemctl = (args2) => ask("systemctl", ["--user", ...args2]);
26835
+ var schtasks = (args2) => ask("schtasks", args2);
26834
26836
  var execute = (command, args2) => () => new Promise((resolve3, reject) => {
26835
26837
  execFile(command, [...args2], { encoding: "utf-8", timeout: 20000 }, (error, stdout, stderr) => {
26836
26838
  if (error) {
@@ -26995,6 +26997,118 @@ var systemd = (plan) => {
26995
26997
  ]
26996
26998
  };
26997
26999
  };
27000
+ var writeUtf16 = (file, text) => exports_Effect.tryPromise({
27001
+ catch: (cause) => new ServiceCommandError({ code: null, command: `write ${file}`, stderr: String(cause) }),
27002
+ try: async () => {
27003
+ await fs.mkdir(path2.dirname(file), { recursive: true });
27004
+ await fs.writeFile(file, Buffer.concat([Buffer.from([255, 254]), Buffer.from(text, "utf16le")]));
27005
+ }
27006
+ });
27007
+ var vbs = (value4) => value4.replaceAll('"', '""');
27008
+ var renderLauncher = (plan, options) => [
27009
+ "' Zopu machines: the satellite, hidden. Written by `getzopu machines connect`; edited by nothing.",
27010
+ 'Set sh = CreateObject("WScript.Shell")',
27011
+ 'Set env = sh.Environment("PROCESS")',
27012
+ `env("PATH") = "${vbs(plan.path)}"`,
27013
+ `env("ZOPU_MACHINE_LOG") = "${vbs(options.logFile)}"`,
27014
+ ...Object.entries(plan.env).map(([key, value4]) => `env("${vbs(key)}") = "${vbs(value4)}"`),
27015
+ `code = sh.Run("${vbs(plan.program.map((word) => `"${word}"`).join(" "))}", 0, True)`,
27016
+ "WScript.Quit code",
27017
+ ""
27018
+ ].join(`\r
27019
+ `);
27020
+ var renderTask = (options) => {
27021
+ const wscript = `${process.env.SystemRoot ?? "C:\\Windows"}\\System32\\wscript.exe`;
27022
+ return [
27023
+ '<?xml version="1.0" encoding="UTF-16"?>',
27024
+ '<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">',
27025
+ " <RegistrationInfo>",
27026
+ " <Description>Zopu machines — this computer, reachable by your threads</Description>",
27027
+ " </RegistrationInfo>",
27028
+ " <Triggers>",
27029
+ " <LogonTrigger>",
27030
+ " <Enabled>true</Enabled>",
27031
+ ` <UserId>${xml2(options.user)}</UserId>`,
27032
+ " </LogonTrigger>",
27033
+ " </Triggers>",
27034
+ " <Principals>",
27035
+ ' <Principal id="Author">',
27036
+ ` <UserId>${xml2(options.user)}</UserId>`,
27037
+ " <LogonType>InteractiveToken</LogonType>",
27038
+ " <RunLevel>LeastPrivilege</RunLevel>",
27039
+ " </Principal>",
27040
+ " </Principals>",
27041
+ " <Settings>",
27042
+ " <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>",
27043
+ " <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>",
27044
+ " <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>",
27045
+ " <AllowHardTerminate>true</AllowHardTerminate>",
27046
+ " <StartWhenAvailable>true</StartWhenAvailable>",
27047
+ " <Hidden>true</Hidden>",
27048
+ " <Enabled>true</Enabled>",
27049
+ " <ExecutionTimeLimit>PT0S</ExecutionTimeLimit>",
27050
+ " <RestartOnFailure>",
27051
+ " <Interval>PT1M</Interval>",
27052
+ " <Count>999</Count>",
27053
+ " </RestartOnFailure>",
27054
+ " </Settings>",
27055
+ ' <Actions Context="Author">',
27056
+ " <Exec>",
27057
+ ` <Command>${xml2(wscript)}</Command>`,
27058
+ ` <Arguments>//B &quot;${xml2(options.launcher)}&quot;</Arguments>`,
27059
+ " </Exec>",
27060
+ " </Actions>",
27061
+ "</Task>",
27062
+ ""
27063
+ ].join(`\r
27064
+ `);
27065
+ };
27066
+ var satellitePid = (home) => exports_Effect.gen(function* pid() {
27067
+ const text = yield* exports_Effect.result(exports_Effect.tryPromise({
27068
+ catch: (cause) => cause,
27069
+ try: () => fs.readFile(path2.join(home, "state.json"), "utf-8")
27070
+ }));
27071
+ if (exports_Result.isFailure(text)) {
27072
+ return null;
27073
+ }
27074
+ const parsed = yield* exports_Effect.result(exports_Effect.try(() => JSON.parse(text.success).pid));
27075
+ return exports_Result.isSuccess(parsed) && typeof parsed.success === "number" ? parsed.success : null;
27076
+ });
27077
+ var windows = (plan) => {
27078
+ const name = plan.label;
27079
+ const taskFile = path2.join(plan.home, "zopu-machines.task.xml");
27080
+ const launcher = path2.join(plan.home, "zopu-machines.vbs");
27081
+ const state = () => ask("powershell", [
27082
+ "-NoProfile",
27083
+ "-NonInteractive",
27084
+ "-Command",
27085
+ `(Get-ScheduledTask -TaskName '${name.replaceAll("'", "''")}' -ErrorAction SilentlyContinue).State`
27086
+ ]);
27087
+ const user = process.env.USERDOMAIN ? `${process.env.USERDOMAIN}\\${process.env.USERNAME ?? userInfo().username}` : process.env.USERNAME ?? userInfo().username;
27088
+ return {
27089
+ file: taskFile,
27090
+ install: [
27091
+ writeUtf16(launcher, renderLauncher(plan, { logFile: plan.logFile })),
27092
+ writeUtf16(taskFile, renderTask({ launcher, user })),
27093
+ attempt("schtasks", ["/End", "/TN", name]),
27094
+ schtasks(["/Create", "/TN", name, "/XML", taskFile, "/F"]),
27095
+ schtasks(["/Run", "/TN", name])
27096
+ ],
27097
+ status: exports_Effect.gen(function* status() {
27098
+ const installed = yield* fileExists(taskFile);
27099
+ const shown = yield* exports_Effect.result(state());
27100
+ const running = !exports_Result.isFailure(shown) && /\bRunning\b/u.test(shown.success);
27101
+ const written = yield* satellitePid(plan.home);
27102
+ return { installed, linger: "yes", pid: running ? written : null, running };
27103
+ }),
27104
+ uninstall: [
27105
+ attempt("schtasks", ["/End", "/TN", name]),
27106
+ attempt("schtasks", ["/Delete", "/TN", name, "/F"]),
27107
+ exports_Effect.asVoid(removeFile(taskFile)),
27108
+ exports_Effect.asVoid(removeFile(launcher))
27109
+ ]
27110
+ };
27111
+ };
26998
27112
  var serviceManager = (plan, platform = process.platform) => {
26999
27113
  if (platform === "darwin") {
27000
27114
  return exports_Effect.succeed(launchd(plan));
@@ -27002,10 +27116,13 @@ var serviceManager = (plan, platform = process.platform) => {
27002
27116
  if (platform === "linux") {
27003
27117
  return exports_Effect.succeed(systemd(plan));
27004
27118
  }
27119
+ if (platform === "win32") {
27120
+ return exports_Effect.succeed(windows(plan));
27121
+ }
27005
27122
  return exports_Effect.fail(new ServiceCommandError({
27006
27123
  code: null,
27007
27124
  command: "install the background service",
27008
- stderr: "The background service is available on macOS and Linux; on other systems run connect with --foreground."
27125
+ stderr: "The background service is available on macOS, Linux and Windows; on other systems run connect with --foreground."
27009
27126
  }));
27010
27127
  };
27011
27128
  var installService = (plan, platform) => exports_Effect.gen(function* install() {
@@ -27029,7 +27146,7 @@ var serviceStatus = (plan, platform) => exports_Effect.gen(function* status() {
27029
27146
  return yield* manager.success.status;
27030
27147
  });
27031
27148
  // ../../packages/machines/src/satellite/commands.ts
27032
- import { spawn } from "node:child_process";
27149
+ import { spawn, spawnSync } from "node:child_process";
27033
27150
  import { homedir as homedir3 } from "node:os";
27034
27151
  import { StringDecoder } from "node:string_decoder";
27035
27152
  var BATCH_MS = 50;
@@ -27074,10 +27191,19 @@ var flushAllOutput = (command, writer) => {
27074
27191
  }
27075
27192
  };
27076
27193
  var signalCommand = (child, signal) => {
27077
- const group = child.pid === undefined ? undefined : child.pid * -1;
27078
- if (group === undefined) {
27194
+ if (child.pid === undefined) {
27195
+ return;
27196
+ }
27197
+ if (process.platform === "win32") {
27198
+ try {
27199
+ spawnSync("taskkill", ["/PID", String(child.pid), "/T", "/F"], {
27200
+ stdio: "ignore",
27201
+ windowsHide: true
27202
+ });
27203
+ } catch {}
27079
27204
  return;
27080
27205
  }
27206
+ const group = child.pid * -1;
27081
27207
  try {
27082
27208
  process.kill(group, signal);
27083
27209
  } catch {}
@@ -27167,7 +27293,8 @@ class Commands {
27167
27293
  detached: true,
27168
27294
  env: { ...process.env, ...request3.env },
27169
27295
  shell: true,
27170
- stdio: ["ignore", "pipe", "pipe"]
27296
+ stdio: ["ignore", "pipe", "pipe"],
27297
+ windowsHide: true
27171
27298
  });
27172
27299
  } catch (error) {
27173
27300
  const message = error instanceof Error ? error.message : "Could not start.";
@@ -27425,7 +27552,7 @@ var expand = (target) => {
27425
27552
  if (target === "~") {
27426
27553
  return homedir4();
27427
27554
  }
27428
- if (target.startsWith("~/")) {
27555
+ if (target.startsWith("~/") || target.startsWith("~\\")) {
27429
27556
  return nodePath.join(homedir4(), target.slice(2));
27430
27557
  }
27431
27558
  return target;
@@ -27825,9 +27952,24 @@ var serverUrl = (override) => {
27825
27952
  return parsed.origin;
27826
27953
  };
27827
27954
  var openBrowser = (url) => {
27828
- const [command, args2] = platform2() === "darwin" ? ["open", [url]] : ["xdg-open", [url]];
27955
+ const here = platform2();
27956
+ let command = "xdg-open";
27957
+ let args2 = [url];
27958
+ if (here === "darwin") {
27959
+ command = "open";
27960
+ }
27961
+ if (here === "win32") {
27962
+ command = "rundll32";
27963
+ args2 = ["url.dll,FileProtocolHandler", url];
27964
+ }
27829
27965
  try {
27830
- spawn2(command, args2, { detached: true, stdio: "ignore" }).unref();
27966
+ const opened = spawn2(command, args2, {
27967
+ detached: true,
27968
+ stdio: "ignore",
27969
+ windowsHide: true
27970
+ });
27971
+ opened.on("error", () => null);
27972
+ opened.unref();
27831
27973
  } catch {}
27832
27974
  };
27833
27975
  var refusal = (reason, url) => {
@@ -27895,8 +28037,18 @@ var STATE_FILE = path4.join(HOME, "state.json");
27895
28037
  var PLAN_FILE = path4.join(HOME, "service.json");
27896
28038
  var writeState = async (link2) => {
27897
28039
  await mkdir4(HOME, { recursive: true });
27898
- const state = { at: Date.now(), link: link2 };
27899
- await writeFile4(STATE_FILE, JSON.stringify(state));
28040
+ const state = { at: Date.now(), link: link2, pid: process.pid };
28041
+ const temporary = `${STATE_FILE}.${process.pid}.tmp`;
28042
+ await writeFile4(temporary, JSON.stringify(state));
28043
+ await rename2(temporary, STATE_FILE);
28044
+ };
28045
+ var SERVICE_LOG = process.env.ZOPU_MACHINE_LOG;
28046
+ var say = (line2) => {
28047
+ console.log(line2);
28048
+ if (SERVICE_LOG) {
28049
+ appendFileSync2(SERVICE_LOG, `${line2}
28050
+ `);
28051
+ }
27900
28052
  };
27901
28053
  var readState = async () => {
27902
28054
  try {
@@ -27935,7 +28087,7 @@ var run2 = async () => {
27935
28087
  const end2 = await exports_Effect.runPromise(runSatellite({
27936
28088
  credential: credential2.credential,
27937
28089
  journalDir: journalDir(),
27938
- log: (line2) => console.log(line2),
28090
+ log: say,
27939
28091
  name: credential2.name || `${hostname2()} (${platform2()})`,
27940
28092
  serverUrl: credential2.serverUrl,
27941
28093
  signal: controller.signal,
@@ -27956,8 +28108,8 @@ var run2 = async () => {
27956
28108
  };
27957
28109
  var bundlePath = async () => {
27958
28110
  const file = import.meta.filename ?? "";
27959
- if (!file.endsWith("/dist/getzopu.mjs")) {
27960
- throw new Error("The background service needs the published program (npx getzopu …). Run with --foreground from a source checkout.");
28111
+ if (path4.basename(file) !== "getzopu.mjs") {
28112
+ throw new Error("The background service needs the published program, the one file named getzopu.mjs (npx getzopu …, or the file from get.zopu.live). Run with --foreground from a source checkout.");
27961
28113
  }
27962
28114
  await stat3(file);
27963
28115
  return file;
@@ -27984,7 +28136,7 @@ var planService = async () => {
27984
28136
  };
27985
28137
  var describe = (service4) => {
27986
28138
  if (service4.running) {
27987
- return `The service is running (process ${String(service4.pid)}).`;
28139
+ return service4.pid === null ? "The service is running." : `The service is running (process ${String(service4.pid)}).`;
27988
28140
  }
27989
28141
  if (service4.installed) {
27990
28142
  return "The service is installed, not running.";
@@ -28310,7 +28462,7 @@ var main = async () => {
28310
28462
  mode: 384
28311
28463
  });
28312
28464
  await chmod2(temporary, 384);
28313
- await rename2(temporary, configFile);
28465
+ await rename3(temporary, configFile);
28314
28466
  console.log("Signed in. Token saved privately.");
28315
28467
  return;
28316
28468
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "getzopu",
3
- "version": "0.5.0",
3
+ "version": "0.5.3",
4
4
  "description": "Zopu CLI: projects, threads, and connecting your own computer to Zopu.",
5
5
  "license": "UNLICENSED",
6
6
  "bin": {