relay-companion 0.1.618 → 0.1.619

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.
@@ -1,4 +1,6 @@
1
1
  "use strict";
2
+ // First: started as an Electron app instead of Node, re-run as Node and quit.
3
+ require("./electron-as-node.cjs");
2
4
  const fs = require("node:fs"), path = require("node:path"), os = require("node:os");
3
5
  const { verifyReleaseEnvelope } = require("./release-signature.cjs");
4
6
  const trust = require("./trust.json");
@@ -1,4 +1,6 @@
1
1
  "use strict";
2
+ // First: started as an Electron app instead of Node, re-run as Node and quit.
3
+ require("./electron-as-node.cjs");
2
4
  // Independently scheduled, upload-only capability; never reads a device token.
3
5
  const fs = require("node:fs"), path = require("node:path"), os = require("node:os");
4
6
  const d = require("./diagnostics.cjs");
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+
3
+ // "A bunch of the electron icons on my dash" (ao1, 2026-10-08). Relay's
4
+ // runtime ships an Electron binary, and anyone handed that binary to run one of
5
+ // Relay's Node scripts (an agent given an old prompt, a launcher that forgot
6
+ // ELECTRON_RUN_AS_NODE, a stale descriptor) starts an Electron APP, not Node:
7
+ // the script runs, prints, and the app never quits. Before the runtime bundle
8
+ // was LSUIElement every such run left a generic atom in the Dock; after it,
9
+ // an invisible process that lives forever.
10
+ //
11
+ // Every script Relay can be asked to run requires this first. Started as an
12
+ // Electron app, the script re-runs itself as plain Node with the same
13
+ // arguments, stdin and stdout, and the app exits with its status. Required by
14
+ // the pill (or anything else) it does nothing: only the entry script itself is
15
+ // ever re-run.
16
+ const fs = require("node:fs");
17
+ const path = require("node:path");
18
+
19
+ const RELAUNCHED = "RELAY_ELECTRON_AS_NODE_RELAUNCHED";
20
+ const PACKAGE_ROOT = path.resolve(__dirname, "..");
21
+ const ENTRY_SCRIPTS = Object.freeze([
22
+ "bin/relay.js",
23
+ "bin/relay-hook.js",
24
+ "bootstrap/application-update.cjs",
25
+ "bootstrap/diagnostics-reporter.cjs",
26
+ "bootstrap/recovery-runner.cjs",
27
+ "bootstrap/recovery-schedule-handover.cjs",
28
+ "bootstrap/relay-background-install.cjs",
29
+ "bootstrap/relay-setup.cjs",
30
+ "bootstrap/update-watchdog.cjs",
31
+ "src/mcp-bridge.js",
32
+ "src/mcp-broker-entry.js",
33
+ "src/recovery-maintenance.js",
34
+ ]);
35
+
36
+ // Runnable, but copied on their own into the agent protocol bundle
37
+ // (tools/relay-application/prepare-protocol.mjs) where no sibling exists, so
38
+ // they cannot load this guard. Both run under Relay's Node; a stray Electron
39
+ // launch of either is still quit by the pill (src/stray-electron.cjs).
40
+ const STANDALONE_SCRIPTS = Object.freeze([
41
+ "bootstrap/recovery-launcher.cjs",
42
+ "bootstrap/relay-skill.cjs",
43
+ ]);
44
+
45
+ function realpath(file, realpathSync = fs.realpathSync) {
46
+ try { return realpathSync(path.resolve(String(file || ""))); } catch { return path.resolve(String(file || "")); }
47
+ }
48
+
49
+ // True when this process is Electron running a script as its app (the main,
50
+ // "browser", process). Under ELECTRON_RUN_AS_NODE Electron is plain Node and
51
+ // process.type is undefined.
52
+ function runningAsElectronApp({ versions = process.versions, type = process.type } = {}) {
53
+ return Boolean(versions && versions.electron) && type === "browser";
54
+ }
55
+
56
+ function isRelayEntryScript(script, { packageRoot = PACKAGE_ROOT, realpathSync = fs.realpathSync } = {}) {
57
+ if (!script) return false;
58
+ const target = realpath(script, realpathSync);
59
+ return ENTRY_SCRIPTS.some((relative) => realpath(path.join(packageRoot, relative), realpathSync) === target);
60
+ }
61
+
62
+ function relaunchAsNodeIfElectronApp({
63
+ versions = process.versions,
64
+ type = process.type,
65
+ argv = process.argv,
66
+ env = process.env,
67
+ execPath = process.execPath,
68
+ packageRoot = PACKAGE_ROOT,
69
+ realpathSync = fs.realpathSync,
70
+ spawnSync = require("node:child_process").spawnSync,
71
+ hideDock = () => { try { require("electron").app?.dock?.hide?.(); } catch {} },
72
+ exit = (code) => process.exit(code),
73
+ } = {}) {
74
+ if (!runningAsElectronApp({ versions, type })) return { relaunched: false, reason: "not-electron-app" };
75
+ if (!isRelayEntryScript(argv[1], { packageRoot, realpathSync })) return { relaunched: false, reason: "not-entry" };
76
+ hideDock();
77
+ // ELECTRON_RUN_AS_NODE was honoured once already and Electron is still an
78
+ // app: the RunAsNode fuse is off. Say so and stop rather than loop.
79
+ if (env[RELAUNCHED] === "1") {
80
+ try { process.stderr.write("Relay: this Electron cannot run scripts as Node; run it with Node instead.\n"); } catch {}
81
+ exit(1);
82
+ return { relaunched: false, reason: "run-as-node-unavailable" };
83
+ }
84
+ const result = spawnSync(execPath, argv.slice(1), {
85
+ stdio: "inherit",
86
+ windowsHide: true,
87
+ env: { ...env, ELECTRON_RUN_AS_NODE: "1", [RELAUNCHED]: "1" },
88
+ });
89
+ const code = Number.isInteger(result.status) ? result.status : 1;
90
+ exit(code);
91
+ return { relaunched: true, code };
92
+ }
93
+
94
+ module.exports = {
95
+ ENTRY_SCRIPTS,
96
+ STANDALONE_SCRIPTS,
97
+ RELAUNCHED,
98
+ isRelayEntryScript,
99
+ relaunchAsNodeIfElectronApp,
100
+ runningAsElectronApp,
101
+ };
102
+
103
+ relaunchAsNodeIfElectronApp();
@@ -1,4 +1,6 @@
1
1
  "use strict";
2
+ // First: started as an Electron app instead of Node, re-run as Node and quit.
3
+ require("./electron-as-node.cjs");
2
4
 
3
5
  // This file and its bootstrap dependencies live outside the application tree.
4
6
  // No application imports, npm, credentials, or messaging API are needed to heal it.
@@ -1,4 +1,6 @@
1
1
  "use strict";
2
+ // First: started as an Electron app instead of Node, re-run as Node and quit.
3
+ require("./electron-as-node.cjs");
2
4
  // launchctl submit is KeepAlive, including after exit 0. Re-entry must reconcile
3
5
  // the loaded schedule, not replay bootout/bootstrap. Keep the independent job
4
6
  // until a schedule is confirmed: the daemon may also be unavailable.
@@ -1,4 +1,6 @@
1
1
  "use strict";
2
+ // First: started as an Electron app instead of Node, re-run as Node and quit.
3
+ require("./electron-as-node.cjs");
2
4
 
3
5
  const fs = require("node:fs");
4
6
  const os = require("node:os");
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  "use strict";
4
+ // First: started as an Electron app instead of Node, re-run as Node and quit.
5
+ require("./electron-as-node.cjs");
4
6
 
5
7
  // Deliberately stdlib-only. This is every byte npm executes before the person
6
8
  // has reviewed Relay: no package dependencies and no npm lifecycle scripts.
@@ -1,4 +1,6 @@
1
1
  "use strict";
2
+ // First: started as an Electron app instead of Node, re-run as Node and quit.
3
+ require("./electron-as-node.cjs");
2
4
  // The guardian does not load the application's module graph. A broken import or
3
5
  // blocked worker event loop cannot disable its deadline.
4
6
  const fs = require("node:fs");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "relay-companion",
3
- "version": "0.1.618",
3
+ "version": "0.1.619",
4
4
  "description": "Install Relay for Claude Code, Cowork, and Codex, then sign in from the Relay pill.",
5
5
  "homepage": "https://sendrelays.com/get-started",
6
6
  "repository": {