@frumu/tandem 0.3.6 → 0.3.13

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
@@ -31,12 +31,6 @@ Start the engine server:
31
31
  tandem-engine serve --hostname 127.0.0.1 --port 39731
32
32
  ```
33
33
 
34
- In a second terminal, you can start the TUI:
35
-
36
- ```bash
37
- tandem-tui
38
- ```
39
-
40
34
  ## Commands
41
35
 
42
36
  ### Serve
@@ -1,17 +1,102 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const path = require("path");
4
+ const https = require("https");
4
5
  const { spawnSync } = require("child_process");
5
6
 
6
7
  const binaryName = process.platform === "win32" ? "tandem-engine.exe" : "tandem-engine";
7
8
  const binaryPath = path.join(__dirname, "native", binaryName);
8
9
 
9
- const child = spawnSync(binaryPath, process.argv.slice(2), { stdio: "inherit" });
10
+ const packageInfo = require("../package.json");
11
+ const UPDATE_CHECK_TIMEOUT_MS = 1200;
10
12
 
11
- if (child.error) {
12
- console.error("tandem-engine binary is missing. Reinstall with: npm i -g @frumu/tandem");
13
- console.error(child.error.message);
14
- process.exit(1);
13
+ function parseVersion(version) {
14
+ const core = String(version || "").split("-")[0];
15
+ return core.split(".").map((part) => {
16
+ const value = Number.parseInt(part, 10);
17
+ return Number.isFinite(value) ? value : 0;
18
+ });
15
19
  }
16
20
 
17
- process.exit(child.status ?? 1);
21
+ function isNewerVersion(latest, current) {
22
+ const a = parseVersion(latest);
23
+ const b = parseVersion(current);
24
+ const length = Math.max(a.length, b.length);
25
+
26
+ for (let i = 0; i < length; i += 1) {
27
+ const left = a[i] || 0;
28
+ const right = b[i] || 0;
29
+ if (left > right) return true;
30
+ if (left < right) return false;
31
+ }
32
+
33
+ return false;
34
+ }
35
+
36
+ function fetchLatestVersion(packageName, timeoutMs) {
37
+ return new Promise((resolve) => {
38
+ const encodedName = encodeURIComponent(packageName);
39
+ const url = `https://registry.npmjs.org/${encodedName}/latest`;
40
+ const request = https.get(url, { headers: { Accept: "application/json" } }, (response) => {
41
+ if (response.statusCode !== 200) {
42
+ response.resume();
43
+ resolve(null);
44
+ return;
45
+ }
46
+
47
+ let body = "";
48
+ response.setEncoding("utf8");
49
+ response.on("data", (chunk) => {
50
+ body += chunk;
51
+ });
52
+ response.on("end", () => {
53
+ try {
54
+ const parsed = JSON.parse(body);
55
+ resolve(typeof parsed.version === "string" ? parsed.version : null);
56
+ } catch {
57
+ resolve(null);
58
+ }
59
+ });
60
+ });
61
+
62
+ request.on("error", () => resolve(null));
63
+ request.setTimeout(timeoutMs, () => {
64
+ request.destroy();
65
+ resolve(null);
66
+ });
67
+ });
68
+ }
69
+
70
+ async function notifyIfUpdateAvailable() {
71
+ const latestVersion = await fetchLatestVersion(packageInfo.name, UPDATE_CHECK_TIMEOUT_MS);
72
+ if (!latestVersion || !isNewerVersion(latestVersion, packageInfo.version)) {
73
+ return;
74
+ }
75
+
76
+ console.error(`[${packageInfo.name}] Update available: ${packageInfo.version} -> ${latestVersion}`);
77
+ console.error(`Run: npm i -g ${packageInfo.name}`);
78
+ }
79
+
80
+ async function main() {
81
+ await notifyIfUpdateAvailable();
82
+
83
+ const child = spawnSync(binaryPath, process.argv.slice(2), { stdio: "inherit" });
84
+
85
+ if (child.error) {
86
+ console.error("tandem-engine binary is missing. Reinstall with: npm i -g @frumu/tandem");
87
+ console.error(child.error.message);
88
+ process.exit(1);
89
+ }
90
+
91
+ process.exit(child.status ?? 1);
92
+ }
93
+
94
+ main().catch(() => {
95
+ const child = spawnSync(binaryPath, process.argv.slice(2), { stdio: "inherit" });
96
+ if (child.error) {
97
+ console.error("tandem-engine binary is missing. Reinstall with: npm i -g @frumu/tandem");
98
+ console.error(child.error.message);
99
+ process.exit(1);
100
+ }
101
+ process.exit(child.status ?? 1);
102
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frumu/tandem",
3
- "version": "0.3.6",
3
+ "version": "0.3.13",
4
4
  "description": "Tandem Engine binary distribution",
5
5
  "homepage": "https://tandem.frumu.ai",
6
6
  "bin": {