getzopu 0.5.1 → 0.5.4

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 +29 -1
  2. package/dist/getzopu.mjs +138 -26
  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
@@ -77,7 +105,7 @@ The satellite (`packages/machines/src/satellite/`) dials out to `/ws/machines` w
77
105
  as a bearer, comes back by itself after a drop (at once the first time, then on a ladder from 1 s
78
106
  to 30 s), and keeps a journal of every command it ran (`~/.config/zopu/machine/journal/`), so a
79
107
  command that outlives a drop is picked up where it was. Commands run as the user, in a process
80
- 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
108
+ group of their own; nothing is scoped. A command runs in the computer's default shell — `sh` on macOS and Linux, PowerShell on Windows (`pwsh` when installed, else Windows PowerShell; `cmd` with `shell: "cmd"`) — under one hidden console, so no window opens; on Windows a stop ends its whole process tree. The connection program says which shells it has, its default first. Its output is kept from the end, as the thread's own shell keeps it. `getzopu machines status` says whether the link is up, how
81
109
  the service is, and the last lines of its log; `getzopu machines disconnect` stops and removes the
82
110
  service, revokes the computer on the server, and forgets the credential.
83
111
 
package/dist/getzopu.mjs CHANGED
@@ -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";
@@ -26412,7 +26412,7 @@ ${result3.text.slice(0, 4000)}` : "";
26412
26412
  // src/machines.ts
26413
26413
  import { spawn as spawn2 } from "node:child_process";
26414
26414
  import { appendFileSync as appendFileSync2 } from "node:fs";
26415
- import { copyFile, mkdir as mkdir4, readFile as readFile3, stat as stat3, writeFile as writeFile4 } from "node:fs/promises";
26415
+ import { copyFile, mkdir as mkdir4, readFile as readFile3, rename as rename2, stat as stat3, writeFile as writeFile4 } from "node:fs/promises";
26416
26416
  import { hostname as hostname2, platform as platform2 } from "node:os";
26417
26417
  import path4 from "node:path";
26418
26418
  import { setTimeout as pause } from "node:timers/promises";
@@ -26514,6 +26514,7 @@ var MACHINE_OUTPUT_MAX_BYTES = 1024 * 1024;
26514
26514
  var MACHINE_READ_MAX_BYTES = 8 * 1024 * 1024;
26515
26515
  var MACHINE_FRAME_MAX_BYTES = 12000000;
26516
26516
  var MACHINE_OUTPUT_CHUNK_BYTES = 64 * 1024;
26517
+ var MACHINE_SHELLS = ["sh", "bash", "zsh", "powershell", "pwsh", "cmd"];
26517
26518
  var MACHINE_SOCKET_PATH = "/ws/machines";
26518
26519
  var MACHINE_PAIR_START_PATH = "/api/machines/pair/start";
26519
26520
  var MACHINE_PAIR_POLL_PATH = "/api/machines/pair/poll";
@@ -26529,12 +26530,14 @@ var MACHINE_CLOSE_CODES = {
26529
26530
  var Id = exports_Schema.String.check(exports_Schema.isMinLength(1), exports_Schema.isMaxLength(128));
26530
26531
  var Path2 = exports_Schema.String.check(exports_Schema.isMinLength(1), exports_Schema.isMaxLength(4096));
26531
26532
  var TimeoutMs = exports_Schema.optional(exports_Schema.Number.check(exports_Schema.isInt(), exports_Schema.isBetween({ maximum: MACHINE_EXEC_MAX_MS, minimum: 1 })));
26533
+ var Shell = exports_Schema.optional(exports_Schema.Literals(MACHINE_SHELLS));
26532
26534
  var ExecRequest = exports_Schema.Struct({
26533
26535
  command: exports_Schema.String.check(exports_Schema.isMinLength(1)),
26534
26536
  cwd: exports_Schema.optional(Path2),
26535
26537
  env: exports_Schema.optional(exports_Schema.Record(exports_Schema.String, exports_Schema.String)),
26536
26538
  id: Id,
26537
26539
  op: exports_Schema.Literal("exec"),
26540
+ shell: Shell,
26538
26541
  timeoutMs: TimeoutMs,
26539
26542
  type: exports_Schema.Literal("request")
26540
26543
  });
@@ -26606,6 +26609,7 @@ var SatelliteHelloFrame = exports_Schema.Struct({
26606
26609
  home: Path2,
26607
26610
  hostname: exports_Schema.String,
26608
26611
  platform: exports_Schema.String,
26612
+ shells: exports_Schema.optional(exports_Schema.Array(exports_Schema.String)),
26609
26613
  version: exports_Schema.String
26610
26614
  }),
26611
26615
  type: exports_Schema.Literal("hello")
@@ -26678,7 +26682,12 @@ var MachineStatus = exports_Schema.Struct({
26678
26682
  home: exports_Schema.NullOr(exports_Schema.String),
26679
26683
  hostname: exports_Schema.NullOr(exports_Schema.String),
26680
26684
  machineId: exports_Schema.String,
26681
- platform: exports_Schema.NullOr(exports_Schema.String)
26685
+ platform: exports_Schema.NullOr(exports_Schema.String),
26686
+ shells: exports_Schema.NullOr(exports_Schema.Array(exports_Schema.String))
26687
+ });
26688
+ var MachineExecStarted = exports_Schema.Struct({
26689
+ id: exports_Schema.String,
26690
+ started: exports_Schema.Literal(true)
26682
26691
  });
26683
26692
  var MachinePairStartInput = exports_Schema.Struct({
26684
26693
  name: exports_Schema.String.check(exports_Schema.isMinLength(1), exports_Schema.isMaxLength(100))
@@ -27063,6 +27072,17 @@ var renderTask = (options) => {
27063
27072
  ].join(`\r
27064
27073
  `);
27065
27074
  };
27075
+ var satellitePid = (home) => exports_Effect.gen(function* pid() {
27076
+ const text = yield* exports_Effect.result(exports_Effect.tryPromise({
27077
+ catch: (cause) => cause,
27078
+ try: () => fs.readFile(path2.join(home, "state.json"), "utf-8")
27079
+ }));
27080
+ if (exports_Result.isFailure(text)) {
27081
+ return null;
27082
+ }
27083
+ const parsed = yield* exports_Effect.result(exports_Effect.try(() => JSON.parse(text.success).pid));
27084
+ return exports_Result.isSuccess(parsed) && typeof parsed.success === "number" ? parsed.success : null;
27085
+ });
27066
27086
  var windows = (plan) => {
27067
27087
  const name = plan.label;
27068
27088
  const taskFile = path2.join(plan.home, "zopu-machines.task.xml");
@@ -27077,8 +27097,9 @@ var windows = (plan) => {
27077
27097
  return {
27078
27098
  file: taskFile,
27079
27099
  install: [
27080
- writeFile2(launcher, renderLauncher(plan, { logFile: plan.logFile })),
27100
+ writeUtf16(launcher, renderLauncher(plan, { logFile: plan.logFile })),
27081
27101
  writeUtf16(taskFile, renderTask({ launcher, user })),
27102
+ attempt("schtasks", ["/End", "/TN", name]),
27082
27103
  schtasks(["/Create", "/TN", name, "/XML", taskFile, "/F"]),
27083
27104
  schtasks(["/Run", "/TN", name])
27084
27105
  ],
@@ -27086,15 +27107,8 @@ var windows = (plan) => {
27086
27107
  const installed = yield* fileExists(taskFile);
27087
27108
  const shown = yield* exports_Effect.result(state());
27088
27109
  const running = !exports_Result.isFailure(shown) && /\bRunning\b/u.test(shown.success);
27089
- let pid = null;
27090
- if (running) {
27091
- const held = yield* exports_Effect.result(exports_Effect.promise(() => fs.readFile(path2.join(plan.home, "state.json"), "utf-8")));
27092
- if (!exports_Result.isFailure(held)) {
27093
- const parsed = JSON.parse(held.success);
27094
- pid = typeof parsed.pid === "number" ? parsed.pid : null;
27095
- }
27096
- }
27097
- return { installed, linger: "yes", pid, running };
27110
+ const written = yield* satellitePid(plan.home);
27111
+ return { installed, linger: "yes", pid: running ? written : null, running };
27098
27112
  }),
27099
27113
  uninstall: [
27100
27114
  attempt("schtasks", ["/End", "/TN", name]),
@@ -27154,6 +27168,80 @@ var NO_END = {
27154
27168
  };
27155
27169
  var KILL_GRACE_MS = 5000;
27156
27170
  var KEEP_ENDED = 50;
27171
+ var STDIO = ["ignore", "pipe", "pipe"];
27172
+ var POWERSHELL_UTF8 = [
27173
+ "try { [Console]::OutputEncoding=[System.Text.Encoding]::UTF8 } catch {}",
27174
+ "try { $ErrorView = 'ConciseView' } catch {}",
27175
+ "$ProgressPreference = 'SilentlyContinue'"
27176
+ ].join("; ");
27177
+ var POWERSHELL_EXIT = "if ($null -ne $LASTEXITCODE) { exit $LASTEXITCODE }";
27178
+ var POWERSHELL_ARGS = [
27179
+ "-NoProfile",
27180
+ "-NonInteractive",
27181
+ "-ExecutionPolicy",
27182
+ "Bypass",
27183
+ "-EncodedCommand"
27184
+ ];
27185
+ var encoded = (script) => Buffer.from(script, "utf16le").toString("base64");
27186
+ var has4 = (shell) => spawnSync("/bin/sh", ["-c", `command -v ${shell}`], { stdio: "ignore" }).status === 0;
27187
+ var known = null;
27188
+ var shellsAvailable = () => {
27189
+ if (known !== null) {
27190
+ return known;
27191
+ }
27192
+ if (process.platform === "win32") {
27193
+ const seven = spawnSync("where.exe", ["pwsh.exe"], { stdio: "ignore", windowsHide: true });
27194
+ known = seven.status === 0 ? ["pwsh", "powershell", "cmd"] : ["powershell", "cmd"];
27195
+ } else {
27196
+ const found = ["sh"];
27197
+ if (has4("bash")) {
27198
+ found.push("bash");
27199
+ }
27200
+ if (has4("zsh")) {
27201
+ found.push("zsh");
27202
+ }
27203
+ known = found;
27204
+ }
27205
+ return known;
27206
+ };
27207
+ var formOf = (shell, command, env) => {
27208
+ const options = {
27209
+ detached: process.platform !== "win32",
27210
+ env,
27211
+ stdio: STDIO,
27212
+ windowsHide: true
27213
+ };
27214
+ const kind = shell ?? shellsAvailable()[0] ?? "sh";
27215
+ if (kind === "cmd") {
27216
+ return {
27217
+ args: ["/d", "/s", "/c", `"chcp 65001>nul & ${command}"`],
27218
+ options: { ...options, windowsVerbatimArguments: true },
27219
+ program: process.env.ComSpec ?? "cmd.exe"
27220
+ };
27221
+ }
27222
+ if (kind === "pwsh" || kind === "powershell") {
27223
+ const script = `${POWERSHELL_UTF8}
27224
+ ${command}
27225
+ ${POWERSHELL_EXIT}`;
27226
+ return {
27227
+ args: [...POWERSHELL_ARGS, encoded(script)],
27228
+ options,
27229
+ program: kind === "pwsh" ? "pwsh.exe" : "powershell.exe"
27230
+ };
27231
+ }
27232
+ return { args: ["-c", command], options, program: kind };
27233
+ };
27234
+ var CLIXML = /^#< CLIXML\r?\n?/u;
27235
+ var unescaped = (text) => text.replaceAll("_x000D_", "\r").replaceAll("_x000A_", `
27236
+ `).replaceAll("_x0009_", "\t").replaceAll("&lt;", "<").replaceAll("&gt;", ">").replaceAll("&quot;", '"').replaceAll("&apos;", "'").replaceAll("&amp;", "&");
27237
+ var messagesOf = (raw) => {
27238
+ const body = raw.replace(CLIXML, "");
27239
+ const held = [
27240
+ ...body.matchAll(/<S S="(?:Error|Warning|Message|Verbose|Debug)"[^>]*>(?<message>[\s\S]*?)<\/S>/gu)
27241
+ ].map((found) => unescaped(found.groups?.message ?? ""));
27242
+ const after = body.slice(body.lastIndexOf("</Objs>") + 7);
27243
+ return `${held.length > 0 ? held.join("") : unescaped(body.replaceAll(/<[^>]+>/gu, ""))}${after}`;
27244
+ };
27157
27245
  var errorFrame = (id2, code, message) => ({
27158
27246
  error: { code, message },
27159
27247
  id: id2,
@@ -27178,10 +27266,27 @@ var clearTimers = (command) => {
27178
27266
  command.timers.timeout = null;
27179
27267
  }
27180
27268
  };
27269
+ var readable = (command, stream2, text) => {
27270
+ if (process.platform !== "win32") {
27271
+ return text;
27272
+ }
27273
+ const whole = `${command.carried[stream2] ? "\r" : ""}${text}`;
27274
+ const endsInReturn = whole.endsWith("\r");
27275
+ command.carried[stream2] = endsInReturn;
27276
+ return (endsInReturn ? whole.slice(0, -1) : whole).replaceAll(`\r
27277
+ `, `
27278
+ `);
27279
+ };
27181
27280
  var flushAllOutput = (command, writer) => {
27182
27281
  clearTimers(command);
27282
+ if (command.clixml !== null) {
27283
+ command.pending.stderr += messagesOf(command.clixml);
27284
+ command.clixml = null;
27285
+ }
27183
27286
  for (const stream2 of ["stderr", "stdout"]) {
27184
27287
  command.pending[stream2] += command.decoders[stream2].end();
27288
+ command.pending[stream2] += command.carried[stream2] ? "\r" : "";
27289
+ command.carried[stream2] = false;
27185
27290
  flushOutput(command, writer, stream2);
27186
27291
  }
27187
27292
  };
@@ -27259,7 +27364,9 @@ class Commands {
27259
27364
  return;
27260
27365
  }
27261
27366
  const command = {
27367
+ carried: { stderr: false, stdout: false },
27262
27368
  child: null,
27369
+ clixml: null,
27263
27370
  decoders: { stderr: new StringDecoder("utf-8"), stdout: new StringDecoder("utf-8") },
27264
27371
  history: [],
27265
27372
  historyBytes: 0,
@@ -27283,13 +27390,10 @@ class Commands {
27283
27390
  command.listeners.add(listener);
27284
27391
  let child;
27285
27392
  try {
27286
- child = spawn(request3.command, {
27287
- cwd: request3.cwd ?? homedir3(),
27288
- detached: true,
27289
- env: { ...process.env, ...request3.env },
27290
- shell: true,
27291
- stdio: ["ignore", "pipe", "pipe"],
27292
- windowsHide: true
27393
+ const form = formOf(request3.shell, request3.command, { ...process.env, ...request3.env });
27394
+ child = spawn(form.program, [...form.args], {
27395
+ ...form.options,
27396
+ cwd: request3.cwd ?? homedir3()
27293
27397
  });
27294
27398
  } catch (error) {
27295
27399
  const message = error instanceof Error ? error.message : "Could not start.";
@@ -27301,7 +27405,12 @@ class Commands {
27301
27405
  }
27302
27406
  command.child = child;
27303
27407
  const onData = (stream2) => (chunk) => {
27304
- command.pending[stream2] += command.decoders[stream2].write(chunk);
27408
+ const text = readable(command, stream2, command.decoders[stream2].write(chunk));
27409
+ if (stream2 === "stderr" && (command.clixml !== null || CLIXML.test(text))) {
27410
+ command.clixml = `${command.clixml ?? ""}${text}`;
27411
+ return;
27412
+ }
27413
+ command.pending[stream2] += text;
27305
27414
  if (command.pending[stream2].length >= MACHINE_OUTPUT_CHUNK_BYTES) {
27306
27415
  flushOutput(command, writer, stream2);
27307
27416
  } else if (command.timers.flush[stream2] === null) {
@@ -27605,6 +27714,7 @@ var hello = () => ({
27605
27714
  home: homedir5(),
27606
27715
  hostname: hostname(),
27607
27716
  platform: platform(),
27717
+ shells: [...shellsAvailable()],
27608
27718
  version: SATELLITE_VERSION
27609
27719
  },
27610
27720
  type: "hello"
@@ -28033,7 +28143,9 @@ var PLAN_FILE = path4.join(HOME, "service.json");
28033
28143
  var writeState = async (link2) => {
28034
28144
  await mkdir4(HOME, { recursive: true });
28035
28145
  const state = { at: Date.now(), link: link2, pid: process.pid };
28036
- await writeFile4(STATE_FILE, JSON.stringify(state));
28146
+ const temporary = `${STATE_FILE}.${process.pid}.tmp`;
28147
+ await writeFile4(temporary, JSON.stringify(state));
28148
+ await rename2(temporary, STATE_FILE);
28037
28149
  };
28038
28150
  var SERVICE_LOG = process.env.ZOPU_MACHINE_LOG;
28039
28151
  var say = (line2) => {
@@ -28101,8 +28213,8 @@ var run2 = async () => {
28101
28213
  };
28102
28214
  var bundlePath = async () => {
28103
28215
  const file = import.meta.filename ?? "";
28104
- if (path4.basename(file) !== "getzopu.mjs" || path4.basename(path4.dirname(file)) !== "dist") {
28105
- throw new Error("The background service needs the published program (npx getzopu …). Run with --foreground from a source checkout.");
28216
+ if (path4.basename(file) !== "getzopu.mjs") {
28217
+ 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.");
28106
28218
  }
28107
28219
  await stat3(file);
28108
28220
  return file;
@@ -28129,7 +28241,7 @@ var planService = async () => {
28129
28241
  };
28130
28242
  var describe = (service4) => {
28131
28243
  if (service4.running) {
28132
- return `The service is running (process ${String(service4.pid)}).`;
28244
+ return service4.pid === null ? "The service is running." : `The service is running (process ${String(service4.pid)}).`;
28133
28245
  }
28134
28246
  if (service4.installed) {
28135
28247
  return "The service is installed, not running.";
@@ -28455,7 +28567,7 @@ var main = async () => {
28455
28567
  mode: 384
28456
28568
  });
28457
28569
  await chmod2(temporary, 384);
28458
- await rename2(temporary, configFile);
28570
+ await rename3(temporary, configFile);
28459
28571
  console.log("Signed in. Token saved privately.");
28460
28572
  return;
28461
28573
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "getzopu",
3
- "version": "0.5.1",
3
+ "version": "0.5.4",
4
4
  "description": "Zopu CLI: projects, threads, and connecting your own computer to Zopu.",
5
5
  "license": "UNLICENSED",
6
6
  "bin": {