mateooo93-cortex 0.25.42 → 0.25.43

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/lib/download.js CHANGED
@@ -81,4 +81,4 @@ async function downloadBinary({ releaseBase, version, asset, destPath }) {
81
81
  }
82
82
  }
83
83
 
84
- module.exports = { downloadBinary, parseSha256Sums };
84
+ module.exports = { downloadBinary, fetchText, parseSha256Sums };
package/lib/install.js CHANGED
@@ -1,14 +1,60 @@
1
1
  "use strict";
2
2
 
3
3
  const fs = require("fs");
4
- const path = require("path");
5
4
 
6
- const { downloadBinary } = require("./download");
5
+ const { downloadBinary, fetchText } = require("./download");
7
6
  const { warnIfShadowed } = require("./path-check");
8
7
  const { resolveAsset } = require("./platform");
9
- const { cacheDir, readPackageVersion, releaseBase } = require("./paths");
8
+ const {
9
+ cacheDir,
10
+ currentBinaryPath,
11
+ readPackageVersion,
12
+ releaseBase,
13
+ releaseRepo,
14
+ } = require("./paths");
10
15
  const { updateCurrentSymlink } = require("./symlink");
11
- const { readBinaryVersion, versionsMatch } = require("./version");
16
+ const {
17
+ isNewerVersion,
18
+ normalizeVersion,
19
+ readBinaryVersion,
20
+ versionsMatch,
21
+ } = require("./version");
22
+
23
+ async function findNewerCurrentBinary(binaryName, pkgVersion) {
24
+ const currentPath = currentBinaryPath(binaryName);
25
+ if (!fs.existsSync(currentPath)) {
26
+ return null;
27
+ }
28
+ const currentVersion = await readBinaryVersion(currentPath);
29
+ if (isNewerVersion(currentVersion, pkgVersion)) {
30
+ return currentPath;
31
+ }
32
+ return null;
33
+ }
34
+
35
+ async function fetchLatestReleaseVersion(fetchTextFn = fetchText) {
36
+ const data = JSON.parse(
37
+ await fetchTextFn(`https://api.github.com/repos/${releaseRepo()}/releases/latest`)
38
+ );
39
+ const version = normalizeVersion(data.tag_name);
40
+ return version || null;
41
+ }
42
+
43
+ async function resolveInstallVersion(pkgVersion, fetchTextFn = fetchText) {
44
+ if (process.env.CORTEX_NPM_PIN_PACKAGE === "1") {
45
+ return pkgVersion;
46
+ }
47
+ try {
48
+ const latestVersion = await fetchLatestReleaseVersion(fetchTextFn);
49
+ if (isNewerVersion(latestVersion, pkgVersion)) {
50
+ return latestVersion;
51
+ }
52
+ } catch {
53
+ // GitHub Releases is the native-binary source of truth, but launch should
54
+ // still work offline or when the API is temporarily unavailable.
55
+ }
56
+ return pkgVersion;
57
+ }
12
58
 
13
59
  async function ensureBinary() {
14
60
  if (process.env.CORTEX_SKIP_POSTINSTALL === "1") {
@@ -16,18 +62,27 @@ async function ensureBinary() {
16
62
  }
17
63
 
18
64
  const pkgVersion = readPackageVersion();
19
- const version = `v${pkgVersion}`;
20
65
  const { asset, binaryName } = resolveAsset();
21
- const destPath = cacheDir(pkgVersion, asset);
66
+
67
+ if (process.env.CORTEX_FORCE_REINSTALL !== "1") {
68
+ const selfUpdatedPath = await findNewerCurrentBinary(binaryName, pkgVersion);
69
+ if (selfUpdatedPath) {
70
+ return selfUpdatedPath;
71
+ }
72
+ }
73
+
74
+ const installVersion = await resolveInstallVersion(pkgVersion);
75
+ const version = `v${installVersion}`;
76
+ const destPath = cacheDir(installVersion, asset);
22
77
 
23
78
  let needsDownload =
24
79
  process.env.CORTEX_FORCE_REINSTALL === "1" || !fs.existsSync(destPath);
25
80
 
26
81
  if (!needsDownload) {
27
82
  const binaryVersion = await readBinaryVersion(destPath);
28
- if (!versionsMatch(binaryVersion, pkgVersion)) {
83
+ if (!versionsMatch(binaryVersion, installVersion)) {
29
84
  console.warn(
30
- `cortex-cli: cached binary is ${binaryVersion || "unknown"}, package requires ${pkgVersion}; re-downloading…`
85
+ `cortex-cli: cached binary is ${binaryVersion || "unknown"}, expected ${installVersion}; re-downloading…`
31
86
  );
32
87
  needsDownload = true;
33
88
  }
@@ -71,4 +126,9 @@ if (require.main === module) {
71
126
  main();
72
127
  }
73
128
 
74
- module.exports = { ensureBinary };
129
+ module.exports = {
130
+ ensureBinary,
131
+ fetchLatestReleaseVersion,
132
+ findNewerCurrentBinary,
133
+ resolveInstallVersion,
134
+ };
package/lib/paths.js CHANGED
@@ -29,10 +29,15 @@ function cacheDir(version, asset) {
29
29
  return path.join(os.homedir(), ".cortex", "npm", version, asset);
30
30
  }
31
31
 
32
+ function currentBinaryPath(binaryName) {
33
+ return path.join(os.homedir(), ".cortex", "npm", "current", binaryName);
34
+ }
35
+
32
36
  module.exports = {
33
37
  packageRoot,
34
38
  readPackageVersion,
35
39
  releaseRepo,
36
40
  releaseBase,
37
41
  cacheDir,
38
- };
42
+ currentBinaryPath,
43
+ };
package/lib/symlink.js CHANGED
@@ -3,10 +3,12 @@
3
3
  const fs = require("fs");
4
4
  const path = require("path");
5
5
 
6
+ const { currentBinaryPath } = require("./paths");
7
+
6
8
  async function updateCurrentSymlink(destPath, binaryName) {
7
- const currentDir = path.join(path.dirname(path.dirname(destPath)), "current");
9
+ const linkPath = currentBinaryPath(binaryName);
10
+ const currentDir = path.dirname(linkPath);
8
11
  await fs.promises.mkdir(currentDir, { recursive: true });
9
- const linkPath = path.join(currentDir, binaryName);
10
12
  try {
11
13
  await fs.promises.unlink(linkPath);
12
14
  } catch (err) {
@@ -19,4 +21,4 @@ async function updateCurrentSymlink(destPath, binaryName) {
19
21
  }
20
22
  }
21
23
 
22
- module.exports = { updateCurrentSymlink };
24
+ module.exports = { updateCurrentSymlink };
package/lib/version.js CHANGED
@@ -14,6 +14,55 @@ function versionsMatch(binaryVersion, packageVersion) {
14
14
  return normalizeVersion(binaryVersion) === normalizeVersion(packageVersion);
15
15
  }
16
16
 
17
+ function splitVersion(v) {
18
+ const normalized = normalizeVersion(v).split("+", 1)[0];
19
+ const [core, prerelease = ""] = normalized.split("-", 2);
20
+ const nums = core.split(".").map((part) => {
21
+ const n = Number.parseInt(part, 10);
22
+ return Number.isFinite(n) ? n : 0;
23
+ });
24
+ while (nums.length < 3) nums.push(0);
25
+ return { nums, prerelease };
26
+ }
27
+
28
+ function comparePrerelease(a, b) {
29
+ if (a === b) return 0;
30
+ if (!a) return 1;
31
+ if (!b) return -1;
32
+
33
+ const left = a.split(".");
34
+ const right = b.split(".");
35
+ const len = Math.max(left.length, right.length);
36
+ for (let i = 0; i < len; i += 1) {
37
+ if (left[i] === undefined) return -1;
38
+ if (right[i] === undefined) return 1;
39
+ if (left[i] === right[i]) continue;
40
+
41
+ const ln = /^\d+$/.test(left[i]) ? Number.parseInt(left[i], 10) : null;
42
+ const rn = /^\d+$/.test(right[i]) ? Number.parseInt(right[i], 10) : null;
43
+ if (ln !== null && rn !== null) return Math.sign(ln - rn);
44
+ if (ln !== null) return -1;
45
+ if (rn !== null) return 1;
46
+ return left[i] < right[i] ? -1 : 1;
47
+ }
48
+ return 0;
49
+ }
50
+
51
+ function compareVersions(a, b) {
52
+ const left = splitVersion(a);
53
+ const right = splitVersion(b);
54
+ for (let i = 0; i < Math.max(left.nums.length, right.nums.length); i += 1) {
55
+ const diff = (left.nums[i] || 0) - (right.nums[i] || 0);
56
+ if (diff !== 0) return Math.sign(diff);
57
+ }
58
+ return comparePrerelease(left.prerelease, right.prerelease);
59
+ }
60
+
61
+ function isNewerVersion(candidateVersion, baseVersion) {
62
+ if (!candidateVersion || !baseVersion) return false;
63
+ return compareVersions(candidateVersion, baseVersion) > 0;
64
+ }
65
+
17
66
  async function readBinaryVersion(binaryPath) {
18
67
  try {
19
68
  const { stdout } = await execFileAsync(binaryPath, ["--version"], {
@@ -28,4 +77,10 @@ async function readBinaryVersion(binaryPath) {
28
77
  }
29
78
  }
30
79
 
31
- module.exports = { normalizeVersion, versionsMatch, readBinaryVersion };
80
+ module.exports = {
81
+ normalizeVersion,
82
+ versionsMatch,
83
+ compareVersions,
84
+ isNewerVersion,
85
+ readBinaryVersion,
86
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mateooo93-cortex",
3
- "version": "0.25.42",
3
+ "version": "0.25.43",
4
4
  "description": "Fast AI coding agent with a polished terminal UI (npm wrapper — downloads the native binary for your OS)",
5
5
  "license": "AGPL-3.0-or-later",
6
6
  "repository": {