@roam-agent/roam-computer-use 0.0.0-stage → 0.5.2
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/LICENSE +21 -0
- package/README.md +80 -2
- package/assets/reference/img.jpg +0 -0
- package/docs/README.md +45 -0
- package/docs/content/docs/explanation/action-pipeline.mdx +36 -0
- package/docs/content/docs/explanation/architecture.mdx +161 -0
- package/docs/content/docs/explanation/index.mdx +19 -0
- package/docs/content/docs/explanation/meta.json +5 -0
- package/docs/content/docs/explanation/observation-pipeline.mdx +37 -0
- package/docs/content/docs/explanation/platform-boundary.mdx +37 -0
- package/docs/content/docs/explanation/state-and-scheduling.mdx +35 -0
- package/docs/content/docs/how-to-guides/develop-and-validate.mdx +112 -0
- package/docs/content/docs/how-to-guides/index.mdx +12 -0
- package/docs/content/docs/how-to-guides/linux.mdx +68 -0
- package/docs/content/docs/how-to-guides/meta.json +1 -0
- package/docs/content/docs/how-to-guides/troubleshooting.mdx +126 -0
- package/docs/content/docs/index.mdx +67 -0
- package/docs/content/docs/meta.json +5 -0
- package/docs/content/docs/reference/agent/contract.mdx +162 -0
- package/docs/content/docs/reference/agent/index.mdx +8 -0
- package/docs/content/docs/reference/agent/meta.json +8 -0
- package/docs/content/docs/reference/agent/tools.mdx +221 -0
- package/docs/content/docs/reference/codebase.mdx +139 -0
- package/docs/content/docs/reference/configuration.mdx +113 -0
- package/docs/content/docs/reference/index.mdx +28 -0
- package/docs/content/docs/reference/meta.json +10 -0
- package/docs/content/docs/reference/platforms/index.mdx +18 -0
- package/docs/content/docs/reference/platforms/macos/accessibility.mdx +61 -0
- package/docs/content/docs/reference/platforms/macos/actions.mdx +63 -0
- package/docs/content/docs/reference/platforms/macos/capture.mdx +58 -0
- package/docs/content/docs/reference/platforms/macos/implementation.mdx +98 -0
- package/docs/content/docs/reference/platforms/macos/index.mdx +16 -0
- package/docs/content/docs/reference/platforms/macos/meta.json +10 -0
- package/docs/content/docs/reference/platforms/macos/root-targeting.mdx +47 -0
- package/docs/content/docs/reference/platforms/meta.json +8 -0
- package/docs/content/docs/reference/platforms/windows.mdx +75 -0
- package/docs/content/docs/tutorials/getting-started.mdx +46 -0
- package/docs/content/docs/tutorials/index.mdx +10 -0
- package/docs/content/docs/tutorials/meta.json +1 -0
- package/extensions/computer-use.ts +235 -0
- package/native/linux/bridge-rs/Cargo.lock +1204 -0
- package/native/linux/bridge-rs/Cargo.toml +21 -0
- package/native/linux/bridge-rs/src/atspi.rs +670 -0
- package/native/linux/bridge-rs/src/error.rs +65 -0
- package/native/linux/bridge-rs/src/lib.rs +11 -0
- package/native/linux/bridge-rs/src/main.rs +1110 -0
- package/native/linux/bridge-rs/src/protocol.rs +49 -0
- package/native/linux/bridge-rs/src/state.rs +293 -0
- package/native/linux/bridge-rs/src/wayland.rs +89 -0
- package/native/linux/bridge-rs/src/x11.rs +909 -0
- package/native/linux/bridge-rs/tests/protocol_tests.rs +73 -0
- package/native/macos/activity_glow.swift +169 -0
- package/native/macos/bridge.swift +3968 -0
- package/native/windows/bridge-rs/Cargo.lock +396 -0
- package/native/windows/bridge-rs/Cargo.toml +30 -0
- package/native/windows/bridge-rs/src/capture.rs +561 -0
- package/native/windows/bridge-rs/src/error.rs +81 -0
- package/native/windows/bridge-rs/src/input.rs +501 -0
- package/native/windows/bridge-rs/src/lib.rs +85 -0
- package/native/windows/bridge-rs/src/main.rs +1683 -0
- package/native/windows/bridge-rs/src/protocol.rs +53 -0
- package/native/windows/bridge-rs/src/refs.rs +237 -0
- package/native/windows/bridge-rs/src/state.rs +55 -0
- package/native/windows/bridge-rs/src/uia.rs +1252 -0
- package/native/windows/bridge-rs/src/window.rs +718 -0
- package/native/windows/bridge-rs/tests/protocol_tests.rs +252 -0
- package/native/windows/bridge-rs/tests/refs_tests.rs +86 -0
- package/native/windows/bridge-rs/tests/state_tests.rs +33 -0
- package/package.json +105 -5
- package/prebuilt/macos/arm64/bridge +0 -0
- package/prebuilt/macos/x64/bridge +0 -0
- package/roam/README.md +52 -0
- package/roam/bridge/macos/arm64/bridge +0 -0
- package/roam/bridge/macos/x64/bridge +0 -0
- package/roam/bridge/manifest.json +20 -0
- package/roam/helper-path.d.mts +9 -0
- package/roam/helper-path.mjs +36 -0
- package/roam/identity.d.mts +16 -0
- package/roam/identity.mjs +64 -0
- package/roam/index.ts +51 -0
- package/roam/redirect.ts +51 -0
- package/roam/repair.ts +120 -0
- package/scripts/build-native.mjs +286 -0
- package/scripts/lib/roam-bridge.mjs +98 -0
- package/scripts/setup-helper.mjs +635 -0
- package/src/actions.ts +130 -0
- package/src/bridge.ts +2594 -0
- package/src/cdp.ts +658 -0
- package/src/config.ts +226 -0
- package/src/contract.ts +107 -0
- package/src/extension/index.ts +9 -0
- package/src/find-params.ts +21 -0
- package/src/note.ts +195 -0
- package/src/outline.ts +702 -0
- package/src/output.ts +134 -0
- package/src/permissions.ts +111 -0
- package/src/platform/architecture.ts +23 -0
- package/src/platform/coerce.ts +16 -0
- package/src/platform/index.ts +61 -0
- package/src/platform/linux/backend.ts +186 -0
- package/src/platform/linux/helper.ts +238 -0
- package/src/platform/macos/backend.ts +147 -0
- package/src/platform/macos/browser.ts +110 -0
- package/src/platform/macos/helper.ts +369 -0
- package/src/platform/macos/permissions.ts +146 -0
- package/src/platform/types.ts +229 -0
- package/src/platform/windows/backend.ts +142 -0
- package/src/platform/windows/helper.ts +140 -0
- package/src/root-selection.ts +25 -0
- package/src/runtime.ts +129 -0
- package/src/state.ts +146 -0
- package/src/view.ts +147 -0
|
@@ -0,0 +1,635 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { spawn, execFile as execFileCallback } from "node:child_process";
|
|
5
|
+
import { constants as fsConstants, createWriteStream, existsSync, realpathSync } from "node:fs";
|
|
6
|
+
import { pipeline } from "node:stream/promises";
|
|
7
|
+
import { promisify } from "node:util";
|
|
8
|
+
import fs from "node:fs/promises";
|
|
9
|
+
import os from "node:os";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import { fileURLToPath } from "node:url";
|
|
12
|
+
import { resolveMacosHelperAppPath } from "../roam/helper-path.mjs";
|
|
13
|
+
import { roamBridgePathForArch } from "./lib/roam-bridge.mjs";
|
|
14
|
+
import {
|
|
15
|
+
ROAM_APP_BUNDLE_NAME,
|
|
16
|
+
ROAM_APP_NAME,
|
|
17
|
+
ROAM_BUNDLE_ID,
|
|
18
|
+
ROAM_LOCAL_SIGNING_COMMON_NAME,
|
|
19
|
+
ROAM_LOG_PREFIX,
|
|
20
|
+
ROAM_RELEASE_ASSET,
|
|
21
|
+
ROAM_REPO_SLUG,
|
|
22
|
+
} from "../roam/identity.mjs";
|
|
23
|
+
|
|
24
|
+
const execFile = promisify(execFileCallback);
|
|
25
|
+
const rootDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
26
|
+
const helperAppPath = resolveMacosHelperAppPath();
|
|
27
|
+
const helperAppExecutablePath = path.join(helperAppPath, "Contents", "MacOS", "bridge");
|
|
28
|
+
const helperSourceHashPath = path.join(helperAppPath, "Contents", "Resources", "source.sha256");
|
|
29
|
+
const helperBundleId = ROAM_BUNDLE_ID;
|
|
30
|
+
const windowsCrateDir = path.join(rootDir, "native", "windows", "bridge-rs");
|
|
31
|
+
const windowsHelperDestPath = process.env.PI_COMPUTER_USE_WINDOWS_HELPER_PATH || path.join(os.homedir(), ".pi", "agent", "helpers", "pi-computer-use", "windows-bridge.exe");
|
|
32
|
+
const linuxCrateDir = path.join(rootDir, "native", "linux", "bridge-rs");
|
|
33
|
+
const linuxHelperDestPath = process.env.PI_COMPUTER_USE_LINUX_HELPER_PATH || path.join(os.homedir(), ".pi", "agent", "helpers", "pi-computer-use", "linux-bridge");
|
|
34
|
+
const helperSourcePaths = ["activity_glow.swift", "agent_cursor.swift", "agent_cursor_motion.swift", "bridge.swift"]
|
|
35
|
+
.map((file) => path.join(rootDir, "native", "macos", file));
|
|
36
|
+
const packageJsonPath = path.join(rootDir, "package.json");
|
|
37
|
+
const releaseRepo = ROAM_REPO_SLUG;
|
|
38
|
+
// X.509 commonName is capped at 64 characters, so the identity names the app and
|
|
39
|
+
// its organization rather than repeating the full bundle id.
|
|
40
|
+
const localCodeSignCommonName = ROAM_LOCAL_SIGNING_COMMON_NAME;
|
|
41
|
+
const localSigningLockPath = path.join(os.tmpdir(), `${ROAM_APP_NAME}-local-signing-${typeof process.getuid === "function" ? process.getuid() : "user"}.lock`);
|
|
42
|
+
|
|
43
|
+
const args = new Set(process.argv.slice(2));
|
|
44
|
+
const isPostinstall = args.has("--postinstall");
|
|
45
|
+
const allowBuildFallback = args.has("--allow-build") || args.has("--runtime") || process.env.PI_COMPUTER_USE_ALLOW_BUILD === "1";
|
|
46
|
+
const allowLinuxBuildFallback = args.has("--allow-build") || process.env.PI_COMPUTER_USE_ALLOW_BUILD === "1";
|
|
47
|
+
const allowAdhocUpdate = args.has("--allow-adhoc-update") || process.env.PI_COMPUTER_USE_ALLOW_ADHOC_UPDATE === "1";
|
|
48
|
+
|
|
49
|
+
function getArg(name) {
|
|
50
|
+
const index = process.argv.indexOf(name);
|
|
51
|
+
if (index >= 0 && index + 1 < process.argv.length) return process.argv[index + 1];
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
const archTriples = {
|
|
55
|
+
arm64: "arm64-apple-macosx",
|
|
56
|
+
x64: "x86_64-apple-macosx",
|
|
57
|
+
};
|
|
58
|
+
const deploymentTarget = "14.0";
|
|
59
|
+
const frameworks = ["ApplicationServices", "AppKit", "ScreenCaptureKit", "Foundation", "SwiftUI"];
|
|
60
|
+
const defaultCodeSignIdentifier = ROAM_BUNDLE_ID;
|
|
61
|
+
|
|
62
|
+
function normalizeArch(arch) {
|
|
63
|
+
if (arch === "arm64" || arch === "x64") return arch;
|
|
64
|
+
throw new Error(`Unsupported architecture '${arch}'. Supported: arm64, x64.`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// The fork ships its own set in roam/bridge so an upstream prebuilt sync cannot
|
|
68
|
+
// silently reinstate upstream artifacts; prebuilt/ stays the fallback.
|
|
69
|
+
export function bridgeSourcePathForArch(arch) {
|
|
70
|
+
const forkBridge = roamBridgePathForArch(arch);
|
|
71
|
+
if (existsSync(forkBridge)) return forkBridge;
|
|
72
|
+
return path.join(rootDir, "prebuilt", "macos", arch, "bridge");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function prebuiltAppPathForArch(arch) {
|
|
76
|
+
return path.join(rootDir, "prebuilt", "macos", arch, ROAM_APP_BUNDLE_NAME);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const releaseAssetName = ROAM_RELEASE_ASSET;
|
|
80
|
+
|
|
81
|
+
async function packageVersion() {
|
|
82
|
+
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, "utf8"));
|
|
83
|
+
if (typeof packageJson.version !== "string" || packageJson.version.length === 0) {
|
|
84
|
+
throw new Error(`Could not read package version from ${packageJsonPath}.`);
|
|
85
|
+
}
|
|
86
|
+
return packageJson.version;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function githubReleaseUrl(tag, assetName) {
|
|
90
|
+
return `https://github.com/${releaseRepo}/releases/download/${tag}/${assetName}`;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function exists(filePath) {
|
|
94
|
+
try {
|
|
95
|
+
await fs.access(filePath, fsConstants.F_OK);
|
|
96
|
+
return true;
|
|
97
|
+
} catch {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async function hashFile(filePath) {
|
|
103
|
+
const data = await fs.readFile(filePath);
|
|
104
|
+
return createHash("sha256").update(data).digest("hex");
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async function copyIfChanged(sourcePath, destinationPath) {
|
|
108
|
+
const destinationExists = await exists(destinationPath);
|
|
109
|
+
if (destinationExists) {
|
|
110
|
+
const [sourceHash, destinationHash] = await Promise.all([hashFile(sourcePath), hashFile(destinationPath)]);
|
|
111
|
+
if (sourceHash === destinationHash) {
|
|
112
|
+
await fs.chmod(destinationPath, 0o755);
|
|
113
|
+
return { changed: false };
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
await fs.mkdir(path.dirname(destinationPath), { recursive: true });
|
|
118
|
+
const tempPath = `${destinationPath}.tmp-${process.pid}-${Date.now()}`;
|
|
119
|
+
await fs.copyFile(sourcePath, tempPath);
|
|
120
|
+
await fs.chmod(tempPath, 0o755);
|
|
121
|
+
try {
|
|
122
|
+
await fs.rename(tempPath, destinationPath);
|
|
123
|
+
} catch (err) {
|
|
124
|
+
await fs.rm(tempPath, { force: true }).catch(() => {});
|
|
125
|
+
if (err.code === "EPERM") {
|
|
126
|
+
throw new Error(`Cannot update helper at ${destinationPath} — the existing helper process is still running. Close the helper process and re-run this script.`);
|
|
127
|
+
}
|
|
128
|
+
throw err;
|
|
129
|
+
}
|
|
130
|
+
return { changed: true };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async function run(command, commandArgs) {
|
|
134
|
+
await new Promise((resolve, reject) => {
|
|
135
|
+
const child = spawn(command, commandArgs, { stdio: "inherit" });
|
|
136
|
+
child.on("error", reject);
|
|
137
|
+
child.on("close", (code) => {
|
|
138
|
+
if (code === 0) {
|
|
139
|
+
resolve();
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
reject(new Error(`Command failed (${code}): ${command} ${commandArgs.join(" ")}`));
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function moduleCachePath(arch) {
|
|
148
|
+
return path.join(os.tmpdir(), `${ROAM_APP_NAME}-swift-module-cache-${arch}`);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async function commandOutput(command, commandArgs) {
|
|
152
|
+
const { stdout } = await execFile(command, commandArgs, { encoding: "utf8" });
|
|
153
|
+
return stdout;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const DOWNLOAD_TIMEOUT_MS = 120_000;
|
|
157
|
+
|
|
158
|
+
async function downloadFile(url, outputPath) {
|
|
159
|
+
const response = await fetch(url, { signal: AbortSignal.timeout(DOWNLOAD_TIMEOUT_MS) });
|
|
160
|
+
if (!response.ok) {
|
|
161
|
+
throw new Error(`HTTP ${response.status} ${response.statusText}`);
|
|
162
|
+
}
|
|
163
|
+
if (!response.body) {
|
|
164
|
+
throw new Error("empty response body");
|
|
165
|
+
}
|
|
166
|
+
await pipeline(response.body, createWriteStream(outputPath));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async function releaseChecksums(tag) {
|
|
170
|
+
const response = await fetch(githubReleaseUrl(tag, "SHA256SUMS"), { signal: AbortSignal.timeout(DOWNLOAD_TIMEOUT_MS) });
|
|
171
|
+
if (!response.ok) return new Map();
|
|
172
|
+
const text = await response.text();
|
|
173
|
+
const checksums = new Map();
|
|
174
|
+
for (const line of text.split("\n")) {
|
|
175
|
+
const match = line.trim().match(/^([a-fA-F0-9]{64})\s+\*?(.+)$/);
|
|
176
|
+
if (match) checksums.set(path.basename(match[2]), match[1].toLowerCase());
|
|
177
|
+
}
|
|
178
|
+
return checksums;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
async function verifySha256(filePath, expected) {
|
|
182
|
+
const file = await fs.readFile(filePath);
|
|
183
|
+
const actual = createHash("sha256").update(file).digest("hex");
|
|
184
|
+
if (actual !== expected.toLowerCase()) {
|
|
185
|
+
throw new Error(`SHA256 mismatch for ${path.basename(filePath)}: expected ${expected}, got ${actual}`);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
async function findExtractedHelperApp(extractDir) {
|
|
190
|
+
const direct = path.join(extractDir, ROAM_APP_BUNDLE_NAME);
|
|
191
|
+
if (await exists(direct)) return direct;
|
|
192
|
+
const entries = await fs.readdir(extractDir, { withFileTypes: true });
|
|
193
|
+
for (const entry of entries) {
|
|
194
|
+
if (!entry.isDirectory()) continue;
|
|
195
|
+
const entryPath = path.join(extractDir, entry.name);
|
|
196
|
+
if (entry.name === ROAM_APP_BUNDLE_NAME) return entryPath;
|
|
197
|
+
const nested = await findExtractedHelperApp(entryPath);
|
|
198
|
+
if (nested) return nested;
|
|
199
|
+
}
|
|
200
|
+
return undefined;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
async function downloadReleaseHelperApp() {
|
|
204
|
+
const version = await packageVersion();
|
|
205
|
+
const tag = `v${version}`;
|
|
206
|
+
const checksums = await releaseChecksums(tag).catch(() => new Map());
|
|
207
|
+
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), `${ROAM_APP_NAME}-release-helper-`));
|
|
208
|
+
try {
|
|
209
|
+
const zipPath = path.join(tempDir, releaseAssetName);
|
|
210
|
+
await downloadFile(githubReleaseUrl(tag, releaseAssetName), zipPath);
|
|
211
|
+
const expectedSha = checksums.get(releaseAssetName);
|
|
212
|
+
if (expectedSha) await verifySha256(zipPath, expectedSha);
|
|
213
|
+
const extractDir = path.join(tempDir, "extract");
|
|
214
|
+
await fs.mkdir(extractDir, { recursive: true });
|
|
215
|
+
await run("/usr/bin/ditto", ["-x", "-k", zipPath, extractDir]);
|
|
216
|
+
const appPath = await findExtractedHelperApp(extractDir);
|
|
217
|
+
if (!appPath) throw new Error(`missing ${ROAM_APP_BUNDLE_NAME} in ${releaseAssetName}`);
|
|
218
|
+
return { appPath, tempDir, assetName: releaseAssetName, tag };
|
|
219
|
+
} catch (error) {
|
|
220
|
+
await fs.rm(tempDir, { force: true, recursive: true }).catch(() => {});
|
|
221
|
+
throw new Error(`No signed helper release asset found for ${tag}: ${error instanceof Error ? error.message : String(error)}`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
async function findDeveloperIdIdentity() {
|
|
226
|
+
const output = await commandOutput("security", ["find-identity", "-p", "codesigning", "-v"]).catch(() => "");
|
|
227
|
+
const line = output.split("\n").find((item) => item.includes("Developer ID Application"));
|
|
228
|
+
return line?.trim().split(/\s+/)[1];
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export function parseCodeSigningIdentities(output, commonName = localCodeSignCommonName) {
|
|
232
|
+
return output.split("\n")
|
|
233
|
+
.map((line) => line.match(/^\s*\d+\)\s+([0-9A-F]{40})\s+"([^"]+)"/i))
|
|
234
|
+
.filter((match) => match?.[2] === commonName)
|
|
235
|
+
.map((match) => match[1].toUpperCase());
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
async function findLocalSigningIdentity() {
|
|
239
|
+
// Self-signed local identities appear as CSSMERR_TP_NOT_TRUSTED and are
|
|
240
|
+
// omitted by `-v`, but remain valid inputs to codesign. Match the identity
|
|
241
|
+
// list directly and return its fingerprint rather than its display name.
|
|
242
|
+
const output = await commandOutput("security", ["find-identity", "-p", "codesigning"]).catch(() => "");
|
|
243
|
+
return parseCodeSigningIdentities(output)[0];
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function delay(ms) {
|
|
247
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export async function withDirectoryLock(lockPath, callback, { waitMs = 15_000, staleMs = 300_000, retryMs = 50 } = {}) {
|
|
251
|
+
const deadline = Date.now() + waitMs;
|
|
252
|
+
while (true) {
|
|
253
|
+
try {
|
|
254
|
+
await fs.mkdir(lockPath);
|
|
255
|
+
break;
|
|
256
|
+
} catch (error) {
|
|
257
|
+
if (error?.code !== "EEXIST") throw error;
|
|
258
|
+
const stat = await fs.stat(lockPath).catch(() => undefined);
|
|
259
|
+
if (stat && Date.now() - stat.mtimeMs > staleMs) {
|
|
260
|
+
await fs.rm(lockPath, { force: true, recursive: true }).catch(() => undefined);
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
if (Date.now() >= deadline) throw new Error(`Timed out waiting for local signing identity lock at ${lockPath}.`);
|
|
264
|
+
await delay(retryMs);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
try {
|
|
268
|
+
return await callback();
|
|
269
|
+
} finally {
|
|
270
|
+
await fs.rm(lockPath, { force: true, recursive: true }).catch(() => undefined);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export async function ensureIdentityOnce(findIdentity, createIdentity, withLock) {
|
|
275
|
+
return (await findIdentity()) ?? await withLock(async () => (await findIdentity()) ?? await createIdentity());
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
async function loginKeychainPath() {
|
|
279
|
+
for (const candidate of [
|
|
280
|
+
path.join(os.homedir(), "Library", "Keychains", "login.keychain-db"),
|
|
281
|
+
path.join(os.homedir(), "Library", "Keychains", "login.keychain"),
|
|
282
|
+
]) {
|
|
283
|
+
if (await exists(candidate)) return candidate;
|
|
284
|
+
}
|
|
285
|
+
return undefined;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
async function ensureLocalSigningIdentity() {
|
|
289
|
+
if (process.platform !== "darwin") return undefined;
|
|
290
|
+
if (!(await commandOutput("which", ["codesign"]).catch(() => ""))) return undefined;
|
|
291
|
+
const existingIdentity = await findLocalSigningIdentity();
|
|
292
|
+
if (existingIdentity) return existingIdentity;
|
|
293
|
+
if (!(await commandOutput("which", ["openssl"]).catch(() => ""))) return undefined;
|
|
294
|
+
const keychain = await loginKeychainPath();
|
|
295
|
+
if (!keychain) return undefined;
|
|
296
|
+
|
|
297
|
+
return await ensureIdentityOnce(findLocalSigningIdentity, createLocalSigningIdentity, (callback) => withDirectoryLock(localSigningLockPath, callback));
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
async function createLocalSigningIdentity() {
|
|
301
|
+
const keychain = await loginKeychainPath();
|
|
302
|
+
if (!keychain) return undefined;
|
|
303
|
+
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), `${ROAM_APP_NAME}-signing-`));
|
|
304
|
+
const password = `${ROAM_APP_NAME}-local-${process.pid}-${Date.now()}`;
|
|
305
|
+
try {
|
|
306
|
+
const configPath = path.join(tempDir, "req.cnf");
|
|
307
|
+
await fs.writeFile(configPath, [
|
|
308
|
+
"[req]",
|
|
309
|
+
"distinguished_name=dn",
|
|
310
|
+
"x509_extensions=ext",
|
|
311
|
+
"prompt=no",
|
|
312
|
+
"[dn]",
|
|
313
|
+
`CN=${localCodeSignCommonName}`,
|
|
314
|
+
"[ext]",
|
|
315
|
+
"basicConstraints=critical,CA:FALSE",
|
|
316
|
+
"keyUsage=critical,digitalSignature",
|
|
317
|
+
"extendedKeyUsage=critical,codeSigning",
|
|
318
|
+
"",
|
|
319
|
+
].join("\n"));
|
|
320
|
+
const keyPath = path.join(tempDir, "key.pem");
|
|
321
|
+
const certPath = path.join(tempDir, "cert.pem");
|
|
322
|
+
const p12Path = path.join(tempDir, "id.p12");
|
|
323
|
+
await execFile("openssl", ["req", "-x509", "-newkey", "rsa:2048", "-keyout", keyPath, "-out", certPath, "-days", "3650", "-nodes", "-config", configPath]);
|
|
324
|
+
await execFile("openssl", ["pkcs12", "-export", "-legacy", "-inkey", keyPath, "-in", certPath, "-out", p12Path, "-passout", `pass:${password}`, "-name", localCodeSignCommonName])
|
|
325
|
+
.catch(async () => {
|
|
326
|
+
await execFile("openssl", ["pkcs12", "-export", "-inkey", keyPath, "-in", certPath, "-out", p12Path, "-passout", `pass:${password}`, "-name", localCodeSignCommonName]);
|
|
327
|
+
});
|
|
328
|
+
await execFile("security", ["import", p12Path, "-k", keychain, "-P", password, "-A", "-T", "/usr/bin/codesign"]);
|
|
329
|
+
const identity = await findLocalSigningIdentity();
|
|
330
|
+
if (!identity) throw new Error("Imported local signing certificate is not a valid code-signing identity.");
|
|
331
|
+
return identity;
|
|
332
|
+
} catch (error) {
|
|
333
|
+
console.warn(`${ROAM_LOG_PREFIX} could not create a valid local signing identity: ${error instanceof Error ? error.message : String(error)}`);
|
|
334
|
+
return undefined;
|
|
335
|
+
} finally {
|
|
336
|
+
await fs.rm(tempDir, { force: true, recursive: true }).catch(() => {});
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
async function resolveCodeSignIdentity() {
|
|
341
|
+
if (process.env.PI_COMPUTER_USE_CODESIGN_IDENTITY) return process.env.PI_COMPUTER_USE_CODESIGN_IDENTITY;
|
|
342
|
+
return (await findDeveloperIdIdentity()) ?? (await ensureLocalSigningIdentity()) ?? "-";
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
async function signHelper(outputPath, identifier = defaultCodeSignIdentifier) {
|
|
346
|
+
if (process.env.PI_COMPUTER_USE_NO_SIGN === "1") {
|
|
347
|
+
return "unsigned";
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
const identity = await resolveCodeSignIdentity();
|
|
351
|
+
const commandArgs = ["--force", "--deep", "-i", identifier, "--timestamp=none", "--sign", identity, outputPath];
|
|
352
|
+
await run("codesign", commandArgs);
|
|
353
|
+
if (identity === "-") {
|
|
354
|
+
console.warn(`${ROAM_LOG_PREFIX} warning: signed helper ad-hoc; macOS may require permission review after native helper changes. Release installs should use a Developer ID-signed helper app.`);
|
|
355
|
+
} else if (identity === await findLocalSigningIdentity()) {
|
|
356
|
+
console.log(`${ROAM_LOG_PREFIX} signed ${outputPath} with local identity '${localCodeSignCommonName}'. macOS may still require permission review after local rebuilds.`);
|
|
357
|
+
}
|
|
358
|
+
return identity;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
async function helperHasAdhocSignature() {
|
|
362
|
+
const output = await execFile("codesign", ["-dv", "--verbose=4", helperAppPath], { encoding: "utf8" }).then(
|
|
363
|
+
(result) => `${result.stdout ?? ""}\n${result.stderr ?? ""}`,
|
|
364
|
+
(error) => `${error.stdout ?? ""}\n${error.stderr ?? ""}`,
|
|
365
|
+
);
|
|
366
|
+
return /Signature=adhoc/i.test(output);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
async function registerHelperApp() {
|
|
370
|
+
const lsregister = "/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister";
|
|
371
|
+
if (!(await exists(lsregister))) return;
|
|
372
|
+
await run(lsregister, ["-f", helperAppPath]).catch(() => {});
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
async function ensureHelperParentDirectory() {
|
|
376
|
+
const parentPath = path.dirname(helperAppPath);
|
|
377
|
+
await fs.mkdir(parentPath, { recursive: true });
|
|
378
|
+
await fs.access(parentPath, fsConstants.W_OK);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
async function installPrebuiltHelperApp(sourceAppPath) {
|
|
382
|
+
await ensureHelperParentDirectory();
|
|
383
|
+
const sourceExecutablePath = path.join(sourceAppPath, "Contents", "MacOS", "bridge");
|
|
384
|
+
const sourceInfoPath = path.join(sourceAppPath, "Contents", "Info.plist");
|
|
385
|
+
const existingExecutable = await fs.readFile(helperAppExecutablePath).catch(() => undefined);
|
|
386
|
+
const sourceExecutable = await fs.readFile(sourceExecutablePath);
|
|
387
|
+
const existingInfo = await fs.readFile(path.join(helperAppPath, "Contents", "Info.plist"), "utf8").catch(() => undefined);
|
|
388
|
+
const sourceInfo = await fs.readFile(sourceInfoPath, "utf8");
|
|
389
|
+
if (existingExecutable?.equals(sourceExecutable) && existingInfo === sourceInfo) {
|
|
390
|
+
await registerHelperApp();
|
|
391
|
+
return false;
|
|
392
|
+
}
|
|
393
|
+
// The sealed bundle must arrive intact — a broken signature would burn
|
|
394
|
+
// the user's TCC grants on an identity that can never validate.
|
|
395
|
+
await run("codesign", ["--verify", "--strict", sourceAppPath]);
|
|
396
|
+
await fs.rm(helperAppPath, { force: true, recursive: true });
|
|
397
|
+
// ditto preserves the bundle byte-for-byte (signature + stapled
|
|
398
|
+
// notarization ticket). The sealed app is NEVER re-signed here: its
|
|
399
|
+
// Developer ID designated requirement (identifier + team) is exactly
|
|
400
|
+
// what gives release builds their best chance of retaining TCC grants.
|
|
401
|
+
await run("/usr/bin/ditto", [sourceAppPath, helperAppPath]);
|
|
402
|
+
await registerHelperApp();
|
|
403
|
+
return true;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
async function installHelperApp(sourcePath) {
|
|
407
|
+
await ensureHelperParentDirectory();
|
|
408
|
+
const version = await packageVersion();
|
|
409
|
+
const infoPlistPath = path.join(helperAppPath, "Contents", "Info.plist");
|
|
410
|
+
const infoPlist = `<?xml version="1.0" encoding="UTF-8"?>
|
|
411
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
412
|
+
<plist version="1.0"><dict>
|
|
413
|
+
<key>CFBundleIdentifier</key><string>${helperBundleId}</string>
|
|
414
|
+
<key>CFBundleName</key><string>${ROAM_APP_NAME}</string>
|
|
415
|
+
<key>CFBundleDisplayName</key><string>${ROAM_APP_NAME}</string>
|
|
416
|
+
<key>CFBundleExecutable</key><string>bridge</string>
|
|
417
|
+
<key>CFBundlePackageType</key><string>APPL</string>
|
|
418
|
+
<key>CFBundleShortVersionString</key><string>${version}</string>
|
|
419
|
+
<key>CFBundleVersion</key><string>${version}</string>
|
|
420
|
+
<key>LSMinimumSystemVersion</key><string>14.0</string>
|
|
421
|
+
<key>LSUIElement</key><true/>
|
|
422
|
+
</dict></plist>\n`;
|
|
423
|
+
|
|
424
|
+
const sourceExecutable = await fs.readFile(sourcePath);
|
|
425
|
+
const sourceHash = createHash("sha256").update(sourceExecutable).digest("hex");
|
|
426
|
+
const existingSourceHash = await fs.readFile(helperSourceHashPath, "utf8").catch(() => undefined);
|
|
427
|
+
const existingInfoPlist = await fs.readFile(infoPlistPath, "utf8").catch(() => undefined);
|
|
428
|
+
if (existingSourceHash?.trim() === sourceHash && existingInfoPlist === infoPlist) {
|
|
429
|
+
// If a real signing identity is available, upgrade older ad-hoc installs
|
|
430
|
+
// in place so local builds have a consistent identity. macOS may still
|
|
431
|
+
// require permission review after native code changes.
|
|
432
|
+
const signingIdentity = process.env.PI_COMPUTER_USE_NO_SIGN === "1" ? "-" : await resolveCodeSignIdentity();
|
|
433
|
+
if (signingIdentity !== "-" && await helperHasAdhocSignature()) {
|
|
434
|
+
await signHelper(helperAppPath, helperBundleId);
|
|
435
|
+
await registerHelperApp();
|
|
436
|
+
return true;
|
|
437
|
+
}
|
|
438
|
+
await registerHelperApp();
|
|
439
|
+
return false;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
const signingIdentity = process.env.PI_COMPUTER_USE_NO_SIGN === "1" ? "-" : await resolveCodeSignIdentity();
|
|
443
|
+
if (signingIdentity === "-" && existingSourceHash !== undefined && !allowAdhocUpdate) {
|
|
444
|
+
throw new Error("Refusing to replace an installed helper with an ad-hoc signed rebuild because macOS may reset Accessibility/Screen Recording grants. Use a pre-signed helper app, install a Developer ID identity, or set PI_COMPUTER_USE_ALLOW_ADHOC_UPDATE=1 for local development.");
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
await fs.mkdir(path.dirname(helperAppExecutablePath), { recursive: true });
|
|
448
|
+
await fs.mkdir(path.dirname(helperSourceHashPath), { recursive: true });
|
|
449
|
+
await fs.copyFile(sourcePath, helperAppExecutablePath);
|
|
450
|
+
await fs.chmod(helperAppExecutablePath, 0o755);
|
|
451
|
+
await fs.writeFile(infoPlistPath, infoPlist);
|
|
452
|
+
await fs.writeFile(helperSourceHashPath, `${sourceHash}\n`);
|
|
453
|
+
await signHelper(helperAppPath, helperBundleId);
|
|
454
|
+
await registerHelperApp();
|
|
455
|
+
return true;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
async function buildHelper(arch, outputPath) {
|
|
459
|
+
for (const sourcePath of helperSourcePaths) {
|
|
460
|
+
if (!(await exists(sourcePath))) throw new Error(`Native helper source not found at ${sourcePath}`);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
await fs.mkdir(path.dirname(outputPath), { recursive: true });
|
|
464
|
+
const swiftArgs = [
|
|
465
|
+
"swiftc",
|
|
466
|
+
"-target",
|
|
467
|
+
`${archTriples[arch]}${deploymentTarget}`,
|
|
468
|
+
"-module-cache-path",
|
|
469
|
+
moduleCachePath(arch),
|
|
470
|
+
"-O",
|
|
471
|
+
];
|
|
472
|
+
for (const framework of frameworks) swiftArgs.push("-framework", framework);
|
|
473
|
+
swiftArgs.push(...helperSourcePaths, "-o", outputPath);
|
|
474
|
+
|
|
475
|
+
await run("xcrun", swiftArgs);
|
|
476
|
+
await fs.chmod(outputPath, 0o755);
|
|
477
|
+
await signHelper(outputPath);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
function windowsBinaryPath() {
|
|
481
|
+
const releaseDir = path.join(windowsCrateDir, "target", "release");
|
|
482
|
+
return {
|
|
483
|
+
exePath: path.join(releaseDir, "windows-bridge.exe"),
|
|
484
|
+
binPath: path.join(releaseDir, "windows-bridge"),
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
async function setupWindowsHelper() {
|
|
489
|
+
const prebuiltPath = path.join(rootDir, "prebuilt", "windows", "windows-bridge.exe");
|
|
490
|
+
if (await exists(prebuiltPath)) {
|
|
491
|
+
const { changed } = await copyIfChanged(prebuiltPath, windowsHelperDestPath);
|
|
492
|
+
console.log(changed
|
|
493
|
+
? `${ROAM_LOG_PREFIX} installed Windows helper from prebuilt to ${windowsHelperDestPath}`
|
|
494
|
+
: `${ROAM_LOG_PREFIX} Windows helper already up to date at ${windowsHelperDestPath}`);
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
if (allowBuildFallback) {
|
|
499
|
+
console.log(`${ROAM_LOG_PREFIX} Windows prebuilt helper missing; attempting source build with cargo...`);
|
|
500
|
+
await run("cargo", ["build", "--release", "--manifest-path", path.join(windowsCrateDir, "Cargo.toml")]);
|
|
501
|
+
const { exePath, binPath } = windowsBinaryPath();
|
|
502
|
+
const cargoOutput = (await exists(exePath)) ? exePath : (await exists(binPath)) ? binPath : exePath;
|
|
503
|
+
const { changed } = await copyIfChanged(cargoOutput, windowsHelperDestPath);
|
|
504
|
+
console.log(changed
|
|
505
|
+
? `${ROAM_LOG_PREFIX} built and installed Windows helper at ${windowsHelperDestPath}`
|
|
506
|
+
: `${ROAM_LOG_PREFIX} Windows helper already up to date at ${windowsHelperDestPath}`);
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
throw new Error(
|
|
511
|
+
`No Windows prebuilt helper found at ${prebuiltPath}. ` +
|
|
512
|
+
"Run 'node scripts/build-native.mjs --platform windows' to build, or set PI_COMPUTER_USE_ALLOW_BUILD=1 to build at install time.",
|
|
513
|
+
);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
async function setupLinuxHelper() {
|
|
517
|
+
const arch = normalizeArch(process.arch);
|
|
518
|
+
const prebuiltPath = path.join(rootDir, "prebuilt", "linux", arch, "linux-bridge");
|
|
519
|
+
if (await exists(prebuiltPath)) {
|
|
520
|
+
const { changed } = await copyIfChanged(prebuiltPath, linuxHelperDestPath);
|
|
521
|
+
console.log(changed ? `${ROAM_LOG_PREFIX} installed Linux helper (${arch}) from prebuilt to ${linuxHelperDestPath}` : `${ROAM_LOG_PREFIX} Linux helper already up to date at ${linuxHelperDestPath}`);
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
if (allowLinuxBuildFallback) {
|
|
525
|
+
if (process.platform !== "linux") throw new Error("The Linux helper source fallback must be built on Linux.");
|
|
526
|
+
console.log(`${ROAM_LOG_PREFIX} Linux prebuilt helper missing; attempting source build with cargo...`);
|
|
527
|
+
await run("cargo", ["build", "--release", "--manifest-path", path.join(linuxCrateDir, "Cargo.toml")]);
|
|
528
|
+
const cargoOutput = path.join(linuxCrateDir, "target", "release", "linux-bridge");
|
|
529
|
+
const { changed } = await copyIfChanged(cargoOutput, linuxHelperDestPath);
|
|
530
|
+
console.log(changed ? `${ROAM_LOG_PREFIX} built and installed Linux helper at ${linuxHelperDestPath}` : `${ROAM_LOG_PREFIX} Linux helper already up to date at ${linuxHelperDestPath}`);
|
|
531
|
+
return;
|
|
532
|
+
}
|
|
533
|
+
throw new Error(`No Linux prebuilt helper found for ${arch} at ${prebuiltPath}. Run node scripts/build-native.mjs --platform linux to build, or set PI_COMPUTER_USE_ALLOW_BUILD=1 to build at install time.`);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
async function setup() {
|
|
537
|
+
const explicitPlatform = getArg("--platform");
|
|
538
|
+
if (explicitPlatform === "windows" || (!explicitPlatform && process.platform === "win32")) {
|
|
539
|
+
await setupWindowsHelper();
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
if (explicitPlatform === "linux" || (!explicitPlatform && process.platform === "linux")) {
|
|
543
|
+
await setupLinuxHelper();
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
if (process.platform !== "darwin") {
|
|
548
|
+
if (isPostinstall) {
|
|
549
|
+
console.warn(`${ROAM_LOG_PREFIX} skipping helper setup: platform is not macOS.`);
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
throw new Error(`${ROAM_APP_NAME} helper is supported on macOS, Windows, and Linux. Use the matching --platform option.`);
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
const arch = normalizeArch(process.arch);
|
|
556
|
+
// Prefer the release-signed universal bundle (one artifact for both
|
|
557
|
+
// arches, produced by .github/workflows/release.yml) over
|
|
558
|
+
// per-arch bundles, over loose binaries (dev fallback).
|
|
559
|
+
const universalAppPath = prebuiltAppPathForArch("universal");
|
|
560
|
+
const prebuiltAppPath = (await exists(universalAppPath))
|
|
561
|
+
? universalAppPath
|
|
562
|
+
: prebuiltAppPathForArch(arch);
|
|
563
|
+
const prebuiltPath = bridgeSourcePathForArch(arch);
|
|
564
|
+
const prebuiltAppExists = await exists(prebuiltAppPath);
|
|
565
|
+
const prebuiltExists = await exists(prebuiltPath);
|
|
566
|
+
|
|
567
|
+
if (prebuiltAppExists) {
|
|
568
|
+
const installed = await installPrebuiltHelperApp(prebuiltAppPath);
|
|
569
|
+
console.log(
|
|
570
|
+
installed
|
|
571
|
+
? `${ROAM_LOG_PREFIX} installed pre-signed helper app (${arch}) at ${helperAppPath}`
|
|
572
|
+
: `${ROAM_LOG_PREFIX} pre-signed helper app (${arch}) already current at ${helperAppPath}`,
|
|
573
|
+
);
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
if (prebuiltExists) {
|
|
578
|
+
const installed = await installHelperApp(prebuiltPath);
|
|
579
|
+
console.log(
|
|
580
|
+
installed
|
|
581
|
+
? `${ROAM_LOG_PREFIX} installed helper app (${arch}) at ${helperAppPath}`
|
|
582
|
+
: `${ROAM_LOG_PREFIX} helper app (${arch}) already current at ${helperAppPath}`,
|
|
583
|
+
);
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
try {
|
|
588
|
+
const releaseHelper = await downloadReleaseHelperApp();
|
|
589
|
+
try {
|
|
590
|
+
const installed = await installPrebuiltHelperApp(releaseHelper.appPath);
|
|
591
|
+
console.log(
|
|
592
|
+
installed
|
|
593
|
+
? `${ROAM_LOG_PREFIX} installed signed helper app from GitHub Release ${releaseHelper.tag} (${releaseHelper.assetName}) at ${helperAppPath}`
|
|
594
|
+
: `${ROAM_LOG_PREFIX} signed helper app from GitHub Release ${releaseHelper.tag} (${releaseHelper.assetName}) already current at ${helperAppPath}`,
|
|
595
|
+
);
|
|
596
|
+
} finally {
|
|
597
|
+
await fs.rm(releaseHelper.tempDir, { force: true, recursive: true }).catch(() => {});
|
|
598
|
+
}
|
|
599
|
+
return;
|
|
600
|
+
} catch (error) {
|
|
601
|
+
console.warn(`${ROAM_LOG_PREFIX} signed helper release download unavailable: ${error instanceof Error ? error.message : String(error)}`);
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
if (allowBuildFallback) {
|
|
605
|
+
const tempPath = path.join(os.tmpdir(), `${ROAM_APP_NAME}-bridge-${process.pid}-${Date.now()}`);
|
|
606
|
+
try {
|
|
607
|
+
console.log(`${ROAM_LOG_PREFIX} prebuilt helper missing; attempting source build with xcrun swiftc...`);
|
|
608
|
+
await buildHelper(arch, tempPath);
|
|
609
|
+
const installed = await installHelperApp(tempPath);
|
|
610
|
+
console.log(
|
|
611
|
+
installed
|
|
612
|
+
? `${ROAM_LOG_PREFIX} built helper app at ${helperAppPath}`
|
|
613
|
+
: `${ROAM_LOG_PREFIX} built helper app; installed app already current at ${helperAppPath}`,
|
|
614
|
+
);
|
|
615
|
+
} finally {
|
|
616
|
+
await fs.rm(tempPath, { force: true }).catch(() => {});
|
|
617
|
+
}
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
throw new Error(
|
|
622
|
+
`No prebuilt helper found for ${arch} at ${prebuiltPath}. Run 'npm run build:native' to build locally.`,
|
|
623
|
+
);
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
const isMain = process.argv[1] && realpathSync(path.resolve(process.argv[1])) === realpathSync(fileURLToPath(import.meta.url));
|
|
627
|
+
if (isMain) setup().catch((error) => {
|
|
628
|
+
if (isPostinstall) {
|
|
629
|
+
console.warn(`${ROAM_LOG_PREFIX} postinstall helper setup skipped: ${error instanceof Error ? error.message : String(error)}`);
|
|
630
|
+
process.exit(0);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
634
|
+
process.exit(1);
|
|
635
|
+
});
|