@digitalex99/unison 0.0.0-stage → 0.1.1

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Alexander Mossin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/bin/unison.js ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ const { main } = require("../lib/install.js");
5
+
6
+ main(process.argv.slice(2)).catch((err) => {
7
+ console.error(`unison-cli: ${err.message}`);
8
+ process.exit(1);
9
+ });
package/checksums.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "unison-darwin-amd64.gz": "4ec8cbf3cd0416dfa7fb119c26401f2843d75ee4da67d58b8b815faed2d473f3",
3
+ "unison-darwin-arm64.gz": "7c904c5aee1d2d574ed37427427c91ddc85bc2be72105d2e0e00681f193a1cc1",
4
+ "unison-linux-amd64.gz": "f872387bd24134911e38067763f4486f13f3671fe7a106b302f145ac496d5a35",
5
+ "unison-linux-arm64.gz": "45e8c3d88692275f1164350afffff9202569e097e636dbb04b14b7a4c225780d",
6
+ "unison-windows-amd64.exe.gz": "d735e36ab270bfc86be0c8275472217f5b1deb4a68095f07809e9a492ba0808e"
7
+ }
package/lib/install.js ADDED
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+
3
+ // The npm package holds no binary: on first run it downloads the one for this
4
+ // platform from the GitHub release of the same version, checks it against the
5
+ // checksums published in the package, caches it, and from then on just runs it.
6
+ // Stdout belongs to the binary (agents parse --json), so progress goes to stderr.
7
+
8
+ const { spawn } = require("node:child_process");
9
+ const crypto = require("node:crypto");
10
+ const fs = require("node:fs");
11
+ const os = require("node:os");
12
+ const path = require("node:path");
13
+ const zlib = require("node:zlib");
14
+
15
+ const RELEASES = "https://github.com/digitalex/unison/releases/download";
16
+ const OSES = { darwin: "darwin", linux: "linux", win32: "windows" };
17
+ const ARCHES = { arm64: "arm64", x64: "amd64" };
18
+ const DOWNLOAD_TIMEOUT_MS = 120_000;
19
+
20
+ // assetName is the release file for a platform, as release.yml names it.
21
+ function assetName(platform, arch) {
22
+ const goos = OSES[platform];
23
+ const goarch = ARCHES[arch];
24
+ if (!goos || !goarch || (goos === "windows" && goarch !== "amd64")) {
25
+ throw new Error(`no prebuilt binary for ${platform}/${arch}; build from source with Go: https://github.com/digitalex/unison`);
26
+ }
27
+ return `unison-${goos}-${goarch}${goos === "windows" ? ".exe" : ""}.gz`;
28
+ }
29
+
30
+ function cacheDir(env, platform) {
31
+ if (platform === "win32" && env.LOCALAPPDATA) return path.join(env.LOCALAPPDATA, "unison-cli");
32
+ return path.join(env.XDG_CACHE_HOME || path.join(os.homedir(), ".cache"), "unison-cli");
33
+ }
34
+
35
+ // ensureBinary returns the path of the cached binary, downloading it if needed.
36
+ async function ensureBinary({ version, checksums, platform, arch, env, baseURL = RELEASES }) {
37
+ const asset = assetName(platform, arch);
38
+ const want = checksums[asset];
39
+ if (!want) throw new Error(`this package has no checksum for ${asset}`);
40
+
41
+ const dir = path.join(cacheDir(env, platform), version);
42
+ const bin = path.join(dir, platform === "win32" ? "unison.exe" : "unison");
43
+ if (fs.existsSync(bin)) return bin;
44
+
45
+ const url = `${baseURL}/v${version}/${asset}`;
46
+ console.error(`unison-cli: downloading ${asset} (v${version})...`);
47
+ const resp = await fetch(url, { signal: AbortSignal.timeout(DOWNLOAD_TIMEOUT_MS) });
48
+ if (!resp.ok) throw new Error(`downloading ${url} failed: HTTP ${resp.status}`);
49
+ const gz = Buffer.from(await resp.arrayBuffer());
50
+ const got = crypto.createHash("sha256").update(gz).digest("hex");
51
+ if (got !== want) throw new Error(`checksum mismatch for ${asset}: refusing to run it`);
52
+
53
+ // Rename into place, so a concurrent or interrupted run never sees half a binary.
54
+ fs.mkdirSync(dir, { recursive: true });
55
+ const tmp = `${bin}.${process.pid}.tmp`;
56
+ fs.writeFileSync(tmp, zlib.gunzipSync(gz), { mode: 0o755 });
57
+ fs.renameSync(tmp, bin);
58
+ return bin;
59
+ }
60
+
61
+ // runBinary runs bin to completion, passing on its exit code: the protocol
62
+ // depends on them (`unison wait` exits 2 on a timeout, 4 when logged out).
63
+ function runBinary(bin, args) {
64
+ return new Promise((resolve, reject) => {
65
+ const child = spawn(bin, args, { stdio: "inherit" });
66
+ const forward = (sig) => child.kill(sig);
67
+ process.on("SIGINT", forward);
68
+ process.on("SIGTERM", forward);
69
+ child.on("error", reject);
70
+ child.on("exit", (code, signal) => {
71
+ process.off("SIGINT", forward);
72
+ process.off("SIGTERM", forward);
73
+ resolve({ code, signal });
74
+ });
75
+ });
76
+ }
77
+
78
+ async function main(args) {
79
+ const { version } = require("../package.json");
80
+ let checksums;
81
+ try {
82
+ checksums = require("../checksums.json");
83
+ } catch {
84
+ throw new Error("this copy has no checksums.json: only published packages can download a binary");
85
+ }
86
+ const bin = await ensureBinary({ version, checksums, platform: process.platform, arch: process.arch, env: process.env });
87
+ const { code, signal } = await runBinary(bin, args);
88
+ if (signal) process.kill(process.pid, signal);
89
+ else process.exit(code);
90
+ }
91
+
92
+ module.exports = { assetName, ensureBinary, main, runBinary };
package/package.json CHANGED
@@ -1,6 +1,26 @@
1
1
  {
2
2
  "name": "@digitalex99/unison",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "The Unison CLI: a real-time project workspace where humans and agents build together.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/digitalex/unison.git",
9
+ "directory": "npm"
10
+ },
11
+ "homepage": "https://unison.cloud.run",
12
+ "bin": {
13
+ "unison": "bin/unison.js"
14
+ },
15
+ "files": [
16
+ "bin",
17
+ "lib",
18
+ "checksums.json"
19
+ ],
20
+ "engines": {
21
+ "node": ">=18"
22
+ },
23
+ "scripts": {
24
+ "test": "node --test test/install.test.js"
25
+ }
26
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.