@reason-machines/cli 0.2.368 → 0.2.369

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
@@ -10,7 +10,13 @@ reason login
10
10
 
11
11
  Requires Node.js 18 or newer for npm installation. Both reason and the compatibility alias ara are installed.
12
12
 
13
- Platforms: macOS Apple Silicon and Intel; Linux ARM64 and x64 with glibc or musl.
13
+ Platforms: macOS Apple Silicon and Intel; Linux ARM64 and x64 with glibc or musl. On Windows, install it inside WSL.
14
+
15
+ The package runs an install script that places the native binary for your platform. If your package manager skips
16
+ optional dependencies, the script downloads the same archive from reasonmachines.com and checks its SHA-256.
17
+ With Bun, trust the script: bun install -g --trust @reason-machines/cli
18
+
19
+ Without Node.js: curl -fsSL https://reasonmachines.com/install.sh | bash
14
20
 
15
21
  ## Use
16
22
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reason-machines/cli",
3
- "version": "0.2.368",
3
+ "version": "0.2.369",
4
4
  "description": "Reason CLI for sessions, coding agents, and optional local device work",
5
5
  "type": "module",
6
6
  "bin": {
@@ -20,13 +20,21 @@
20
20
  "engines": {
21
21
  "node": ">=18"
22
22
  },
23
+ "os": [
24
+ "darwin",
25
+ "linux"
26
+ ],
27
+ "cpu": [
28
+ "arm64",
29
+ "x64"
30
+ ],
23
31
  "optionalDependencies": {
24
- "@reason-machines/cli-darwin-arm64": "0.2.368",
25
- "@reason-machines/cli-darwin-x64": "0.2.368",
26
- "@reason-machines/cli-linux-arm64": "0.2.368",
27
- "@reason-machines/cli-linux-arm64-musl": "0.2.368",
28
- "@reason-machines/cli-linux-x64": "0.2.368",
29
- "@reason-machines/cli-linux-x64-musl": "0.2.368"
32
+ "@reason-machines/cli-darwin-arm64": "0.2.369",
33
+ "@reason-machines/cli-darwin-x64": "0.2.369",
34
+ "@reason-machines/cli-linux-arm64": "0.2.369",
35
+ "@reason-machines/cli-linux-arm64-musl": "0.2.369",
36
+ "@reason-machines/cli-linux-x64": "0.2.369",
37
+ "@reason-machines/cli-linux-x64-musl": "0.2.369"
30
38
  },
31
39
  "publishConfig": {
32
40
  "access": "public",
package/postinstall.mjs CHANGED
@@ -1,5 +1,8 @@
1
- import { chmodSync, copyFileSync, cpSync } from "node:fs";
1
+ import { chmodSync, copyFileSync, cpSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2
+ import { execFileSync } from "node:child_process";
3
+ import { createHash } from "node:crypto";
2
4
  import { createRequire } from "node:module";
5
+ import { tmpdir } from "node:os";
3
6
  import { fileURLToPath } from "node:url";
4
7
  import { dirname, join } from "node:path";
5
8
 
@@ -13,50 +16,100 @@ function linuxLibc() {
13
16
  }
14
17
 
15
18
  if (process.platform === "win32") {
16
- process.stderr.write("Reason runs on macOS and Linux.\n");
19
+ process.stderr.write("Reason runs on macOS and Linux. On Windows, install it inside WSL: npm install -g @reason-machines/cli\n");
17
20
  process.exit(1);
18
21
  }
19
22
 
20
23
  const suffix = `${process.platform}-${process.arch}${linuxLibc()}`;
21
24
  const credentialLibraryName = "libara_device_keychain.dylib";
22
-
23
25
  const packageName = `@reason-machines/cli-${suffix}`;
26
+ const { version } = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8"));
27
+ // install.sh's REASON_RELEASE_ORIGIN: the same release storage and SHA256SUMS the curl installer reads.
28
+ const releaseOrigin = process.env.REASON_RELEASE_ORIGIN || "https://reasonmachines.com/cli/releases";
29
+
30
+ /** The platform package npm installed, or null when it skipped it (not yet served, --omit=optional). */
31
+ function installedPackageDirectory() {
32
+ try {
33
+ return dirname(dirname(require.resolve(`${packageName}/bin/ara`)));
34
+ } catch (error) {
35
+ if (error?.code === "MODULE_NOT_FOUND") return null;
36
+ throw error;
37
+ }
38
+ }
24
39
 
40
+ async function fetchOk(url) {
41
+ let lastError;
42
+ for (let attempt = 1; attempt <= 3; attempt++) {
43
+ try {
44
+ const response = await fetch(url);
45
+ if (response.ok) return response;
46
+ lastError = new Error(`${url} returned HTTP ${response.status}`);
47
+ if (response.status === 404) break;
48
+ } catch (error) {
49
+ lastError = error;
50
+ }
51
+ }
52
+ throw lastError;
53
+ }
54
+
55
+ /**
56
+ * npm accepts every platform package before the wrapper, but can take minutes to hours to serve the large
57
+ * Linux ones, and it silently skips an optional dependency it cannot resolve. The release archive npm packs
58
+ * is the one the curl installer downloads (same bytes), so fetch it from release storage and check it
59
+ * against the release's SHA256SUMS.
60
+ */
61
+ async function downloadedPackageDirectory(scratch) {
62
+ const archiveName = `reason-machines-cli-${suffix}-${version}.tgz`;
63
+ const base = `${releaseOrigin}/download/cli-v${version}`;
64
+ const sums = await (await fetchOk(`${base}/SHA256SUMS`)).text();
65
+ const expected = sums.split("\n").map(line => line.trim().split(/\s+/)).find(([, name]) => name === archiveName)?.[0];
66
+ if (!/^[0-9a-f]{64}$/.test(expected ?? "")) throw new Error(`release ${version} lists no checksum for ${archiveName}`);
67
+ const bytes = Buffer.from(await (await fetchOk(`${base}/${archiveName}`)).arrayBuffer());
68
+ if (createHash("sha256").update(bytes).digest("hex") !== expected) throw new Error(`${archiveName} failed its SHA-256 check`);
69
+ const archive = join(scratch, archiveName);
70
+ writeFileSync(archive, bytes);
71
+ execFileSync("tar", ["-xzf", archive, "-C", scratch], { stdio: ["ignore", "ignore", "inherit"] });
72
+ return join(scratch, "package");
73
+ }
74
+
75
+ /**
76
+ * Replace, never merge: a file left from an earlier install inside a signed bundle fails
77
+ * `codesign --verify --strict`. Symlinks are copied as they are, not resolved to absolute paths.
78
+ */
79
+ function replaceTree(source, destination) {
80
+ rmSync(destination, { recursive: true, force: true });
81
+ cpSync(source, destination, { recursive: true, verbatimSymlinks: true });
82
+ }
83
+
84
+ let scratch;
25
85
  try {
26
- const source = require.resolve(`${packageName}/bin/ara`);
27
- const credentialLibrarySource = process.platform === "darwin"
28
- ? require.resolve(`${packageName}/bin/${credentialLibraryName}`)
29
- : null;
86
+ let packageDirectory = installedPackageDirectory();
87
+ if (!packageDirectory) {
88
+ process.stderr.write(`${packageName}@${version} was not installed by the package manager; downloading it from ${releaseOrigin}\n`);
89
+ scratch = mkdtempSync(join(tmpdir(), "reason-cli-"));
90
+ packageDirectory = await downloadedPackageDirectory(scratch);
91
+ }
92
+ const binDirectory = join(packageDirectory, "bin");
30
93
  // npm links bin/reason.exe on every platform; the name is only the bin target.
31
94
  const destination = fileURLToPath(new URL("./bin/reason.exe", import.meta.url));
32
- copyFileSync(source, destination);
95
+ copyFileSync(join(binDirectory, "ara"), destination);
33
96
  chmodSync(destination, 0o755);
34
- cpSync(join(dirname(source), "runtime", "srt"), join(dirname(destination), "runtime", "srt"), {
35
- recursive: true,
36
- force: true,
37
- });
38
- if (credentialLibrarySource) {
39
- const credentialLibraryDestination = fileURLToPath(
40
- new URL(`./bin/${credentialLibraryName}`, import.meta.url),
41
- );
42
- copyFileSync(credentialLibrarySource, credentialLibraryDestination);
97
+ replaceTree(join(binDirectory, "runtime", "srt"), join(dirname(destination), "runtime", "srt"));
98
+ if (process.platform === "darwin") {
99
+ const credentialLibraryDestination = fileURLToPath(new URL(`./bin/${credentialLibraryName}`, import.meta.url));
100
+ copyFileSync(join(binDirectory, credentialLibraryName), credentialLibraryDestination);
43
101
  chmodSync(credentialLibraryDestination, 0o755);
44
102
  // MACOS_BACKGROUND_IDENTITY_PACKAGE_PATH (cli/macos-background-identity.ts).
45
103
  // This script ships with the platform package of its own version.
46
- const identityInfo = require.resolve(
47
- `${packageName}/bin/Background/Reason.app/Contents/Info.plist`,
48
- );
49
- const identitySource = dirname(dirname(identityInfo));
50
- const identityDestination = fileURLToPath(
51
- new URL("./bin/Background/Reason.app", import.meta.url),
104
+ replaceTree(
105
+ join(binDirectory, "Background", "Reason.app"),
106
+ fileURLToPath(new URL("./bin/Background/Reason.app", import.meta.url)),
52
107
  );
53
- cpSync(identitySource, identityDestination, {
54
- recursive: true,
55
- force: true,
56
- });
57
108
  }
58
109
  } catch (error) {
59
110
  const detail = error instanceof Error ? error.message : String(error);
60
111
  process.stderr.write(`Reason could not install its ${suffix} binary: ${detail}\n`);
61
- process.exit(1);
112
+ process.exitCode = 1;
113
+ } finally {
114
+ if (scratch) rmSync(scratch, { recursive: true, force: true });
62
115
  }