relay-companion 0.1.599 → 0.1.601

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.
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+
3
+ // How macOS names Relay's launch agents.
4
+ //
5
+ // Background Task Management (Login Items & Extensions, and the "App
6
+ // Background Activity" notice it posts when an agent first appears) names a
7
+ // legacy launch agent after the code at ProgramArguments[0]:
8
+ //
9
+ // - When the plist's AssociatedBundleIdentifiers names an installed app
10
+ // signed by the SAME Team ID as that code, the item shows as that app.
11
+ // - Otherwise a Developer ID signed executable shows as its developer.
12
+ // - An ad-hoc signed executable (no Team ID) shows as the executable's own
13
+ // file name.
14
+ //
15
+ // Relay's daemon and recovery agents run the Node that ships inside
16
+ // /Applications/Relay.app (or a byte-identical copy), signed with the same
17
+ // Developer ID team as the app, so associating them with the app shows them as
18
+ // "Relay". The pill runs the runtime's ad-hoc signed Electron, which has no Team
19
+ // ID, so the association cannot apply to it; its main executable is therefore
20
+ // named "Relay" in the runtime artifact. MacOS/Electron stays as a link to it:
21
+ // installers, updaters and recovery engines already in the field locate the
22
+ // runtime by that path and must keep accepting new runtimes.
23
+
24
+ const fs = require("node:fs");
25
+ const path = require("node:path");
26
+ const { APPLICATION_ID } = require("./application-owner.cjs");
27
+
28
+ const RELAY_MAC_ASSOCIATED_BUNDLE_IDENTIFIERS = Object.freeze([APPLICATION_ID]);
29
+ const RELAY_MAC_EXECUTABLE_NAME = "Relay";
30
+ const LEGACY_MAC_EXECUTABLE_NAME = "Electron";
31
+
32
+ function xmlEscape(value) {
33
+ return String(value)
34
+ .replaceAll("&", "&")
35
+ .replaceAll("<", "&lt;")
36
+ .replaceAll(">", "&gt;")
37
+ .replaceAll('"', "&quot;")
38
+ .replaceAll("'", "&apos;");
39
+ }
40
+
41
+ /** The launchd plist fragment that files an agent under Relay.app in Login Items. */
42
+ function associatedBundleIdentifiersPlist(indent = "") {
43
+ const values = RELAY_MAC_ASSOCIATED_BUNDLE_IDENTIFIERS.map((id) => `<string>${xmlEscape(id)}</string>`).join("");
44
+ return `${indent}<key>AssociatedBundleIdentifiers</key><array>${values}</array>`;
45
+ }
46
+
47
+ /**
48
+ * The executable a macOS launch agent should name for an Electron runtime.
49
+ * A Relay-built runtime's bundle executable is MacOS/Relay; MacOS/Electron is
50
+ * only its compatibility link. Stock or older runtimes have MacOS/Electron
51
+ * alone and keep it. Anything that is not a bundle main executable is
52
+ * returned unchanged.
53
+ */
54
+ function preferredMacElectronExecutable(electronPath, { existsSync = fs.existsSync, statSync = fs.statSync } = {}) {
55
+ const value = String(electronPath || "");
56
+ if (!value || path.posix.basename(value) !== LEGACY_MAC_EXECUTABLE_NAME) return electronPath;
57
+ const directory = path.posix.dirname(value);
58
+ if (path.posix.basename(directory) !== "MacOS" || path.posix.basename(path.posix.dirname(directory)) !== "Contents") return electronPath;
59
+ const branded = path.posix.join(directory, RELAY_MAC_EXECUTABLE_NAME);
60
+ try {
61
+ if (existsSync(branded) && statSync(branded).isFile()) return branded;
62
+ } catch {}
63
+ return electronPath;
64
+ }
65
+
66
+ module.exports = {
67
+ LEGACY_MAC_EXECUTABLE_NAME,
68
+ RELAY_MAC_ASSOCIATED_BUNDLE_IDENTIFIERS,
69
+ RELAY_MAC_EXECUTABLE_NAME,
70
+ associatedBundleIdentifiersPlist,
71
+ preferredMacElectronExecutable,
72
+ };
@@ -6,6 +6,7 @@ const crypto = require("node:crypto");
6
6
  const { spawnSync } = require("node:child_process");
7
7
  const { relayOwnedNodePath } = require("./owned-node-runtime.cjs");
8
8
  const { atomicFile } = require("./mac-registration-transaction.cjs");
9
+ const { associatedBundleIdentifiersPlist } = require("./mac-background-identity.cjs");
9
10
  const { read, write, compare } = require("./recovery-runner.cjs");
10
11
  const LABEL = "work.relay.companion.recovery";
11
12
  const TASK = "Relay Companion Recovery";
@@ -185,7 +186,7 @@ function installRecovery({ packageRoot, node = process.execPath, homeDir = os.ho
185
186
  const plist = path.join(homeDir, "Library", "LaunchAgents", `${LABEL}.plist`);
186
187
  fs.mkdirSync(path.dirname(plist), { recursive: true });
187
188
  const priorSchedule = fs.existsSync(plist) ? fs.readFileSync(plist) : null;
188
- const nextSchedule = `<?xml version="1.0"?><plist version="1.0"><dict><key>Label</key><string>${LABEL}</string><key>ProgramArguments</key><array><string>${xml(launcherNode)}</string><string>${xml(launcher)}</string></array><key>EnvironmentVariables</key><dict><key>HOME</key><string>${xml(homeDir)}</string></dict><key>StartInterval</key><integer>60</integer><key>RunAtLoad</key><true/><key>ProcessType</key><string>Background</string><key>StandardOutPath</key><string>${xml(log)}</string><key>StandardErrorPath</key><string>${xml(log)}</string></dict></plist>`;
189
+ const nextSchedule = `<?xml version="1.0"?><plist version="1.0"><dict><key>Label</key><string>${LABEL}</string><key>ProgramArguments</key><array><string>${xml(launcherNode)}</string><string>${xml(launcher)}</string></array><key>EnvironmentVariables</key><dict><key>HOME</key><string>${xml(homeDir)}</string></dict><key>StartInterval</key><integer>60</integer><key>RunAtLoad</key><true/><key>ProcessType</key><string>Background</string>${associatedBundleIdentifiersPlist()}<key>StandardOutPath</key><string>${xml(log)}</string><key>StandardErrorPath</key><string>${xml(log)}</string></dict></plist>`;
189
190
  atomicFile(plist, nextSchedule);
190
191
  // The job dispatches through the stable host. Do not unload it on update.
191
192
  const observed = runCommand("launchctl", ["print", `gui/${userId}/${LABEL}`]);
@@ -2,6 +2,7 @@
2
2
 
3
3
  const fs = require("node:fs");
4
4
  const path = require("node:path");
5
+ const { LEGACY_MAC_EXECUTABLE_NAME, RELAY_MAC_EXECUTABLE_NAME } = require("./mac-background-identity.cjs");
5
6
 
6
7
  const MAC_HELPER_EXECUTABLES = [
7
8
  ["Electron Helper.app", "Electron Helper"],
@@ -18,6 +19,21 @@ function pathsFor(platform) {
18
19
  return platformName(platform) === "win32" ? path.win32 : path.posix;
19
20
  }
20
21
 
22
+ // Electron's main executable inside its npm package, most preferred first.
23
+ // Relay-built macOS runtimes name the bundle executable MacOS/Relay so macOS
24
+ // shows the pill's launch agent as "Relay" (see mac-background-identity.cjs);
25
+ // stock and older runtimes have only MacOS/Electron.
26
+ function electronMainCandidates(platform = process.platform) {
27
+ const name = platformName(platform);
28
+ const api = pathsFor(name);
29
+ if (name === "win32") return [api.join("dist", "electron.exe")];
30
+ if (name === "darwin") {
31
+ return [RELAY_MAC_EXECUTABLE_NAME, LEGACY_MAC_EXECUTABLE_NAME]
32
+ .map((executable) => api.join("dist", "Electron.app", "Contents", "MacOS", executable));
33
+ }
34
+ return [api.join("dist", "electron")];
35
+ }
36
+
21
37
  function runtimeExecutableInventory(packageRoot, {
22
38
  platform = process.platform,
23
39
  existsSync = fs.existsSync,
@@ -25,14 +41,14 @@ function runtimeExecutableInventory(packageRoot, {
25
41
  const name = platformName(platform);
26
42
  const api = pathsFor(name);
27
43
  const roots = [api.join(packageRoot, "node_modules", "electron"), api.join(api.dirname(packageRoot), "electron")];
28
- const mainRelative = name === "win32"
29
- ? api.join("dist", "electron.exe")
30
- : name === "darwin"
31
- ? api.join("dist", "Electron.app", "Contents", "MacOS", "Electron")
32
- : api.join("dist", "electron");
33
- const electronRoot = roots.find((root) => {
34
- try { return existsSync(api.join(root, mainRelative)); } catch { return false; }
35
- });
44
+ let electronRoot = null;
45
+ let mainRelative = null;
46
+ for (const root of roots) {
47
+ mainRelative = electronMainCandidates(name).find((relative) => {
48
+ try { return existsSync(api.join(root, relative)); } catch { return false; }
49
+ }) || null;
50
+ if (mainRelative) { electronRoot = root; break; }
51
+ }
36
52
  if (!electronRoot) return { ok: false, reason: "candidate-electron-missing", paths: [] };
37
53
 
38
54
  const entries = [{ role: "electron", path: api.join(electronRoot, mainRelative) }];
@@ -130,6 +146,7 @@ function repairRuntimeExecutablePermissions(packageRoot, {
130
146
 
131
147
  module.exports = {
132
148
  MAC_HELPER_EXECUTABLES,
149
+ electronMainCandidates,
133
150
  repairRuntimeExecutablePermissions,
134
151
  runtimeExecutableInventory,
135
152
  verifyRuntimeExecutables,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "relay-companion",
3
- "version": "0.1.599",
3
+ "version": "0.1.601",
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": {