ambivalence 0.1.0 → 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.
Files changed (3) hide show
  1. package/cli.cjs +12 -8
  2. package/install.cjs +17 -9
  3. package/package.json +36 -9
package/cli.cjs CHANGED
@@ -1,11 +1,15 @@
1
1
  #!/usr/bin/env node
2
- // Runs the binary install.cjs downloaded, passing arguments, stdio and exit code through.
3
- const path = require("path");
2
+ // Runs the platform binary, fetching it first if postinstall did not run (ignore-scripts).
3
+ const fs = require("fs");
4
4
  const { spawnSync } = require("child_process");
5
- const bin = path.join(__dirname, "bin", process.platform === "win32" ? "ambivalence.exe" : "ambivalence");
6
- const r = spawnSync(bin, process.argv.slice(2), { stdio: "inherit" });
7
- if (r.error) {
8
- console.error("ambivalence: binary missing, reinstall the package (" + r.error.message + ")");
5
+ const { install, dest } = require("./install.cjs");
6
+
7
+ (async () => {
8
+ if (!fs.existsSync(dest)) await install();
9
+ const r = spawnSync(dest, process.argv.slice(2), { stdio: "inherit" });
10
+ if (r.error) throw r.error;
11
+ process.exit(r.status === null ? 1 : r.status);
12
+ })().catch((e) => {
13
+ console.error("ambivalence: " + e.message);
9
14
  process.exit(1);
10
- }
11
- process.exit(r.status === null ? 1 : r.status);
15
+ });
package/install.cjs CHANGED
@@ -1,11 +1,12 @@
1
- // Downloads the ambivalence binary for this platform from the GitHub release matching this
2
- // package version and checks it against the release's checksums.txt.
1
+ // Downloads the ambivalence binary for this platform from the GitHub release named by
2
+ // binaryVersion and checks it against the release's checksums.txt. Runs at postinstall and,
3
+ // when install scripts are disabled, on the first `ambivalence` run (see cli.cjs).
3
4
  const fs = require("fs");
4
5
  const path = require("path");
5
6
  const crypto = require("crypto");
6
7
  const https = require("https");
7
8
 
8
- const version = require("./package.json").version;
9
+ const version = require("./package.json").binaryVersion;
9
10
  const os = { linux: "linux", darwin: "darwin", win32: "windows" }[process.platform];
10
11
  const arch = { x64: "amd64", arm64: "arm64" }[process.arch];
11
12
  if (!os || !arch) throw new Error(`ambivalence has no binary for ${process.platform}/${process.arch}`);
@@ -28,7 +29,7 @@ function get(url, redirects = 5) {
28
29
  });
29
30
  }
30
31
 
31
- (async () => {
32
+ async function install() {
32
33
  const sums = (await get(base + "checksums.txt")).toString();
33
34
  const line = sums.split("\n").find((l) => l.trim().endsWith(" " + asset));
34
35
  if (!line) throw new Error(`${asset} is not listed in checksums.txt`);
@@ -36,8 +37,15 @@ function get(url, redirects = 5) {
36
37
  const got = crypto.createHash("sha256").update(bin).digest("hex");
37
38
  if (got !== line.split(/\s+/)[0]) throw new Error(`checksum mismatch for ${asset}`);
38
39
  fs.mkdirSync(path.dirname(dest), { recursive: true });
39
- fs.writeFileSync(dest, bin, { mode: 0o755 });
40
- })().catch((e) => {
41
- console.error("ambivalence: install failed: " + e.message);
42
- process.exit(1);
43
- });
40
+ fs.writeFileSync(dest + ".tmp", bin, { mode: 0o755 });
41
+ fs.renameSync(dest + ".tmp", dest); // never leave a half-written binary behind
42
+ }
43
+
44
+ module.exports = { install, dest };
45
+
46
+ if (require.main === module) {
47
+ install().catch((e) => {
48
+ console.error("ambivalence: install failed: " + e.message);
49
+ process.exit(1);
50
+ });
51
+ }
package/package.json CHANGED
@@ -1,15 +1,42 @@
1
1
  {
2
2
  "name": "ambivalence",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "give your coding agent a camera: your phone. pair once over mcp or cli, found on your wi-fi, end-to-end encrypted",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/Microck/ambivalence",
7
- "repository": { "type": "git", "url": "git+https://github.com/Microck/ambivalence.git" },
8
- "keywords": ["mcp", "model-context-protocol", "ai-agents", "camera", "phone", "cli"],
9
- "bin": { "ambivalence": "cli.cjs" },
10
- "scripts": { "postinstall": "node install.cjs" },
11
- "files": ["cli.cjs", "install.cjs"],
12
- "engines": { "node": ">=18" },
13
- "os": ["linux", "darwin", "win32"],
14
- "cpu": ["x64", "arm64"]
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/Microck/ambivalence.git"
10
+ },
11
+ "keywords": [
12
+ "mcp",
13
+ "model-context-protocol",
14
+ "ai-agents",
15
+ "camera",
16
+ "phone",
17
+ "cli"
18
+ ],
19
+ "bin": {
20
+ "ambivalence": "cli.cjs"
21
+ },
22
+ "scripts": {
23
+ "postinstall": "node install.cjs"
24
+ },
25
+ "files": [
26
+ "cli.cjs",
27
+ "install.cjs"
28
+ ],
29
+ "engines": {
30
+ "node": ">=18"
31
+ },
32
+ "os": [
33
+ "linux",
34
+ "darwin",
35
+ "win32"
36
+ ],
37
+ "cpu": [
38
+ "x64",
39
+ "arm64"
40
+ ],
41
+ "binaryVersion": "0.1.0"
15
42
  }