getzopu 0.5.3 → 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.
package/README.md CHANGED
@@ -105,7 +105,7 @@ The satellite (`packages/machines/src/satellite/`) dials out to `/ws/machines` w
105
105
  as a bearer, comes back by itself after a drop (at once the first time, then on a ladder from 1 s
106
106
  to 30 s), and keeps a journal of every command it ran (`~/.config/zopu/machine/journal/`), so a
107
107
  command that outlives a drop is picked up where it was. Commands run as the user, in a process
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
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
109
109
  the service is, and the last lines of its log; `getzopu machines disconnect` stops and removes the
110
110
  service, revokes the computer on the server, and forgets the credential.
111
111
 
package/dist/getzopu.mjs CHANGED
@@ -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))
@@ -27159,6 +27168,80 @@ var NO_END = {
27159
27168
  };
27160
27169
  var KILL_GRACE_MS = 5000;
27161
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
+ };
27162
27245
  var errorFrame = (id2, code, message) => ({
27163
27246
  error: { code, message },
27164
27247
  id: id2,
@@ -27183,10 +27266,27 @@ var clearTimers = (command) => {
27183
27266
  command.timers.timeout = null;
27184
27267
  }
27185
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
+ };
27186
27280
  var flushAllOutput = (command, writer) => {
27187
27281
  clearTimers(command);
27282
+ if (command.clixml !== null) {
27283
+ command.pending.stderr += messagesOf(command.clixml);
27284
+ command.clixml = null;
27285
+ }
27188
27286
  for (const stream2 of ["stderr", "stdout"]) {
27189
27287
  command.pending[stream2] += command.decoders[stream2].end();
27288
+ command.pending[stream2] += command.carried[stream2] ? "\r" : "";
27289
+ command.carried[stream2] = false;
27190
27290
  flushOutput(command, writer, stream2);
27191
27291
  }
27192
27292
  };
@@ -27264,7 +27364,9 @@ class Commands {
27264
27364
  return;
27265
27365
  }
27266
27366
  const command = {
27367
+ carried: { stderr: false, stdout: false },
27267
27368
  child: null,
27369
+ clixml: null,
27268
27370
  decoders: { stderr: new StringDecoder("utf-8"), stdout: new StringDecoder("utf-8") },
27269
27371
  history: [],
27270
27372
  historyBytes: 0,
@@ -27288,13 +27390,10 @@ class Commands {
27288
27390
  command.listeners.add(listener);
27289
27391
  let child;
27290
27392
  try {
27291
- child = spawn(request3.command, {
27292
- cwd: request3.cwd ?? homedir3(),
27293
- detached: true,
27294
- env: { ...process.env, ...request3.env },
27295
- shell: true,
27296
- stdio: ["ignore", "pipe", "pipe"],
27297
- 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()
27298
27397
  });
27299
27398
  } catch (error) {
27300
27399
  const message = error instanceof Error ? error.message : "Could not start.";
@@ -27306,7 +27405,12 @@ class Commands {
27306
27405
  }
27307
27406
  command.child = child;
27308
27407
  const onData = (stream2) => (chunk) => {
27309
- 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;
27310
27414
  if (command.pending[stream2].length >= MACHINE_OUTPUT_CHUNK_BYTES) {
27311
27415
  flushOutput(command, writer, stream2);
27312
27416
  } else if (command.timers.flush[stream2] === null) {
@@ -27610,6 +27714,7 @@ var hello = () => ({
27610
27714
  home: homedir5(),
27611
27715
  hostname: hostname(),
27612
27716
  platform: platform(),
27717
+ shells: [...shellsAvailable()],
27613
27718
  version: SATELLITE_VERSION
27614
27719
  },
27615
27720
  type: "hello"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "getzopu",
3
- "version": "0.5.3",
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": {