mateooo93-cortex 0.25.25 → 0.25.29

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
@@ -6,8 +6,16 @@ npm wrapper that downloads the native `cortex` binary for your OS on `postinstal
6
6
 
7
7
  ## Install
8
8
 
9
+ **Recommended when npm auth fails:** use the install script (downloads the native binary, no registry token):
10
+
11
+ ```bash
12
+ curl -fsSL https://raw.githubusercontent.com/Mateooo93/cortex-cli/main/script/install.sh | bash
13
+ ```
14
+
15
+ **npm** (GitHub Packages):
16
+
9
17
  ```bash
10
- npm install -g @mateooo93/cortex --registry=https://npm.pkg.github.com
18
+ npm install -g @mateooo93/cortex@latest --registry=https://npm.pkg.github.com
11
19
  ```
12
20
 
13
21
  Or set the scope once in `~/.npmrc`:
@@ -19,7 +27,13 @@ Or set the scope once in `~/.npmrc`:
19
27
  Then:
20
28
 
21
29
  ```bash
22
- npm install -g @mateooo93/cortex
30
+ npm install -g @mateooo93/cortex@latest
31
+ ```
32
+
33
+ If you see `E401 Unauthorized`, the package may still be private — use the install script, or add a GitHub token with `read:packages`:
34
+
35
+ ```
36
+ //npm.pkg.github.com/:_authToken=YOUR_GITHUB_TOKEN
23
37
  ```
24
38
 
25
39
  The global `cortex` command must point at `.../node_modules/@mateooo93/cortex/shims/cortex.js` (or your package manager's global bin shim).
@@ -29,13 +43,13 @@ The global `cortex` command must point at `.../node_modules/@mateooo93/cortex/sh
29
43
  **GitHub Packages** (default — uses `GITHUB_TOKEN` in Actions):
30
44
 
31
45
  ```bash
32
- ./script/publish-npm.sh v0.25.19 --yes
46
+ ./script/publish-npm.sh v0.25.25 --yes
33
47
  ```
34
48
 
35
49
  **npmjs.org** (optional legacy `mateooo93-cortex` — requires npm Automation token):
36
50
 
37
51
  ```bash
38
- ./script/publish-npm.sh v0.25.19 --yes --registry npmjs
52
+ ./script/publish-npm.sh v0.25.25 --yes --registry npmjs
39
53
  ```
40
54
 
41
55
  After the first GitHub Packages publish, set the package visibility to **Public** under the repo's **Packages** tab so anyone can install without a token.
package/lib/install.js CHANGED
@@ -7,42 +7,46 @@ const { downloadBinary } = require("./download");
7
7
  const { warnIfShadowed } = require("./path-check");
8
8
  const { resolveAsset } = require("./platform");
9
9
  const { cacheDir, readPackageVersion, releaseBase } = require("./paths");
10
+ const { updateCurrentSymlink } = require("./symlink");
11
+ const { readBinaryVersion, versionsMatch } = require("./version");
10
12
 
11
13
  async function ensureBinary() {
12
14
  if (process.env.CORTEX_SKIP_POSTINSTALL === "1") {
13
15
  return null;
14
16
  }
15
17
 
16
- const version = `v${readPackageVersion()}`;
18
+ const pkgVersion = readPackageVersion();
19
+ const version = `v${pkgVersion}`;
17
20
  const { asset, binaryName } = resolveAsset();
18
- const destPath = cacheDir(version.slice(1), asset);
21
+ const destPath = cacheDir(pkgVersion, asset);
19
22
 
20
- if (fs.existsSync(destPath)) {
21
- return destPath;
22
- }
23
-
24
- await downloadBinary({
25
- releaseBase: releaseBase(),
26
- version,
27
- asset,
28
- destPath,
29
- });
23
+ let needsDownload =
24
+ process.env.CORTEX_FORCE_REINSTALL === "1" || !fs.existsSync(destPath);
30
25
 
31
- // Convenience symlink: ~/.cortex/npm/current/<binaryName>
32
- const currentDir = path.join(path.dirname(path.dirname(destPath)), "current");
33
- await fs.promises.mkdir(currentDir, { recursive: true });
34
- const linkPath = path.join(currentDir, binaryName);
35
- try {
36
- await fs.promises.unlink(linkPath);
37
- } catch (err) {
38
- if (err.code !== "ENOENT") throw err;
26
+ if (!needsDownload) {
27
+ const binaryVersion = await readBinaryVersion(destPath);
28
+ if (!versionsMatch(binaryVersion, pkgVersion)) {
29
+ console.warn(
30
+ `cortex-cli: cached binary is ${binaryVersion || "unknown"}, package requires ${pkgVersion}; re-downloading…`
31
+ );
32
+ needsDownload = true;
33
+ }
39
34
  }
40
- try {
41
- await fs.promises.symlink(destPath, linkPath);
42
- } catch {
43
- // Windows may require elevated symlink rights; ignore.
35
+
36
+ if (needsDownload) {
37
+ if (fs.existsSync(destPath)) {
38
+ await fs.promises.unlink(destPath);
39
+ }
40
+ await downloadBinary({
41
+ releaseBase: releaseBase(),
42
+ version,
43
+ asset,
44
+ destPath,
45
+ });
44
46
  }
45
47
 
48
+ await updateCurrentSymlink(destPath, binaryName);
49
+
46
50
  return destPath;
47
51
  }
48
52
 
@@ -50,7 +54,11 @@ async function main() {
50
54
  try {
51
55
  const dest = await ensureBinary();
52
56
  if (dest) {
53
- console.log(`cortex-cli: installed native binary to ${dest}`);
57
+ const binaryVersion = await readBinaryVersion(dest);
58
+ console.log(
59
+ `cortex-cli: installed native binary to ${dest}` +
60
+ (binaryVersion ? ` (${binaryVersion})` : "")
61
+ );
54
62
  }
55
63
  warnIfShadowed();
56
64
  } catch (err) {
package/lib/path-check.js CHANGED
@@ -45,29 +45,36 @@ function resolveCortexOnPath() {
45
45
  return null;
46
46
  }
47
47
 
48
- function looksLikeCognitiveScale(target) {
48
+ function isOurInstall(target) {
49
49
  if (!target) {
50
50
  return false;
51
51
  }
52
52
  const normalized = target.replace(/\\/g, "/");
53
- if (CONFLICT_MARKERS.some((marker) => normalized.includes(marker))) {
54
- return true;
55
- }
56
53
  if (normalized.endsWith("/shims/cortex.js")) {
57
- return false;
54
+ return true;
58
55
  }
59
56
  if (normalized.includes("/mateooo93-cortex/") || normalized.includes("/@mateooo93/cortex/")) {
60
- return false;
57
+ return true;
61
58
  }
62
59
  if (normalized.includes("/.cortex/npm/")) {
60
+ return true;
61
+ }
62
+ return false;
63
+ }
64
+
65
+ function looksLikeCognitiveScale(target) {
66
+ if (!target) {
67
+ return false;
68
+ }
69
+ const normalized = target.replace(/\\/g, "/");
70
+ if (CONFLICT_MARKERS.some((marker) => normalized.includes(marker))) {
71
+ return true;
72
+ }
73
+ if (isOurInstall(target)) {
63
74
  return false;
64
75
  }
65
76
  // Heuristic: CognitiveScale ships a cortex.js launcher, not our shim layout.
66
- if (
67
- normalized.endsWith("/cortex.js") &&
68
- !normalized.includes("mateooo93-cortex") &&
69
- !normalized.includes("@mateooo93/cortex")
70
- ) {
77
+ if (normalized.endsWith("/cortex.js")) {
71
78
  return true;
72
79
  }
73
80
  return false;
@@ -88,7 +95,7 @@ function warnIfShadowed() {
88
95
  same = shimPath === firstOnPath;
89
96
  }
90
97
 
91
- if (same || !looksLikeCognitiveScale(firstOnPath)) {
98
+ if (same || isOurInstall(firstOnPath)) {
92
99
  return;
93
100
  }
94
101
 
@@ -97,9 +104,14 @@ function warnIfShadowed() {
97
104
  console.warn(` ${firstOnPath}`);
98
105
  console.warn(`@mateooo93/cortex shim: ${shimPath}`);
99
106
  console.warn("");
100
- console.warn("Remove the conflicting CognitiveScale CLI, then open a new terminal:");
101
- console.warn(" npm uninstall -g cortex-cli");
102
- console.warn(" bun remove -g cortex-cli # if installed via bun");
107
+ if (looksLikeCognitiveScale(firstOnPath)) {
108
+ console.warn("Remove the conflicting CognitiveScale CLI, then open a new terminal:");
109
+ console.warn(" npm uninstall -g cortex-cli");
110
+ console.warn(" bun remove -g cortex-cli # if installed via bun");
111
+ } else {
112
+ console.warn("Remove or move the other binary (often ~/.local/bin/cortex from a prior /update),");
113
+ console.warn("ensure the npm global bin directory is before ~/.local/bin on PATH, then open a new shell.");
114
+ }
103
115
  console.warn("");
104
116
  console.warn("Or run this package directly until PATH is fixed:");
105
117
  console.warn(` ${shimPath}`);
package/lib/symlink.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+
6
+ async function updateCurrentSymlink(destPath, binaryName) {
7
+ const currentDir = path.join(path.dirname(path.dirname(destPath)), "current");
8
+ await fs.promises.mkdir(currentDir, { recursive: true });
9
+ const linkPath = path.join(currentDir, binaryName);
10
+ try {
11
+ await fs.promises.unlink(linkPath);
12
+ } catch (err) {
13
+ if (err.code !== "ENOENT") throw err;
14
+ }
15
+ try {
16
+ await fs.promises.symlink(destPath, linkPath);
17
+ } catch {
18
+ // Windows may require elevated symlink rights; ignore.
19
+ }
20
+ }
21
+
22
+ module.exports = { updateCurrentSymlink };
package/lib/version.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ const { execFile } = require("child_process");
4
+ const { promisify } = require("util");
5
+
6
+ const execFileAsync = promisify(execFile);
7
+
8
+ function normalizeVersion(v) {
9
+ if (!v) return "";
10
+ return String(v).trim().replace(/^v/i, "");
11
+ }
12
+
13
+ function versionsMatch(binaryVersion, packageVersion) {
14
+ return normalizeVersion(binaryVersion) === normalizeVersion(packageVersion);
15
+ }
16
+
17
+ async function readBinaryVersion(binaryPath) {
18
+ try {
19
+ const { stdout } = await execFileAsync(binaryPath, ["--version"], {
20
+ timeout: 15_000,
21
+ windowsHide: true,
22
+ });
23
+ const line = String(stdout).trim().split(/\r?\n/)[0] || "";
24
+ const match = line.match(/\bv?(\d+\.\d+\.\d+(?:[-+][\w.-]+)?)\b/i);
25
+ return match ? match[1] : null;
26
+ } catch {
27
+ return null;
28
+ }
29
+ }
30
+
31
+ module.exports = { normalizeVersion, versionsMatch, readBinaryVersion };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mateooo93-cortex",
3
- "version": "0.25.25",
3
+ "version": "0.25.29",
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": {
@@ -37,7 +37,8 @@
37
37
  "files": [
38
38
  "shims",
39
39
  "lib",
40
- "README.md"
40
+ "README.md",
41
+ ".npmrc"
41
42
  ],
42
43
  "scripts": {
43
44
  "postinstall": "node lib/install.js"