mateooo93-cortex 0.25.20

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 ADDED
@@ -0,0 +1,13 @@
1
+ # mateooo93-cortex (npm)
2
+
3
+ Cross-platform npm wrapper for the [Mateooo93 cortex-cli](https://github.com/Mateooo93/cortex-cli) AI coding agent. On install it downloads the matching native binary from GitHub Releases.
4
+
5
+ > **Note:** The npm package `cortex-cli` is a different product (CognitiveScale). Use `mateooo93-cortex`.
6
+
7
+ ```bash
8
+ npm uninstall -g cortex-cli
9
+ npm install -g mateooo93-cortex
10
+ cortex
11
+ ```
12
+
13
+ Set `CORTEX_SKIP_POSTINSTALL=1` to skip the binary download (for CI or offline mirrors).
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+
3
+ const crypto = require("crypto");
4
+ const fs = require("fs");
5
+ const https = require("https");
6
+ const path = require("path");
7
+
8
+ function get(url) {
9
+ return new Promise((resolve, reject) => {
10
+ const req = https.get(url, { headers: { "User-Agent": "cortex-cli-npm" } }, (res) => {
11
+ if (res.statusCode && res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
12
+ get(res.headers.location).then(resolve, reject);
13
+ return;
14
+ }
15
+ if (res.statusCode !== 200) {
16
+ reject(new Error(`HTTP ${res.statusCode} for ${url}`));
17
+ res.resume();
18
+ return;
19
+ }
20
+ const chunks = [];
21
+ res.on("data", (c) => chunks.push(c));
22
+ res.on("end", () => resolve(Buffer.concat(chunks)));
23
+ res.on("error", reject);
24
+ });
25
+ req.on("error", reject);
26
+ });
27
+ }
28
+
29
+ async function fetchText(url) {
30
+ const buf = await get(url);
31
+ return buf.toString("utf8");
32
+ }
33
+
34
+ async function sha256OfFile(filePath) {
35
+ return new Promise((resolve, reject) => {
36
+ const hash = crypto.createHash("sha256");
37
+ const stream = fs.createReadStream(filePath);
38
+ stream.on("data", (chunk) => hash.update(chunk));
39
+ stream.on("end", () => resolve(hash.digest("hex")));
40
+ stream.on("error", reject);
41
+ });
42
+ }
43
+
44
+ function parseSha256Sums(text, assetName) {
45
+ for (const line of text.split(/\r?\n/)) {
46
+ const trimmed = line.trim();
47
+ if (!trimmed) continue;
48
+ const match = trimmed.match(/^([a-f0-9]{64})\s{2}(.+)$/i);
49
+ if (!match) continue;
50
+ if (match[2] === assetName) {
51
+ return match[1].toLowerCase();
52
+ }
53
+ }
54
+ return null;
55
+ }
56
+
57
+ async function downloadBinary({ releaseBase, version, asset, destPath }) {
58
+ const sumsURL = `${releaseBase}/download/${version}/SHA256SUMS`;
59
+ const assetURL = `${releaseBase}/download/${version}/${asset}`;
60
+
61
+ const sumsText = await fetchText(sumsURL);
62
+ const expected = parseSha256Sums(sumsText, asset);
63
+ if (!expected) {
64
+ throw new Error(`SHA256SUMS missing entry for ${asset} (${sumsURL})`);
65
+ }
66
+
67
+ await fs.promises.mkdir(path.dirname(destPath), { recursive: true });
68
+ const tmpPath = `${destPath}.download`;
69
+ const data = await get(assetURL);
70
+ await fs.promises.writeFile(tmpPath, data);
71
+
72
+ const got = await sha256OfFile(tmpPath);
73
+ if (got !== expected) {
74
+ await fs.promises.unlink(tmpPath).catch(() => {});
75
+ throw new Error(`checksum mismatch for ${asset}: expected ${expected}, got ${got}`);
76
+ }
77
+
78
+ await fs.promises.rename(tmpPath, destPath);
79
+ if (process.platform !== "win32") {
80
+ await fs.promises.chmod(destPath, 0o755);
81
+ }
82
+ }
83
+
84
+ module.exports = { downloadBinary, parseSha256Sums };
package/lib/install.js ADDED
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+
6
+ const { downloadBinary } = require("./download");
7
+ const { resolveAsset } = require("./platform");
8
+ const { cacheDir, readPackageVersion, releaseBase } = require("./paths");
9
+
10
+ async function ensureBinary() {
11
+ if (process.env.CORTEX_SKIP_POSTINSTALL === "1") {
12
+ return null;
13
+ }
14
+
15
+ const version = `v${readPackageVersion()}`;
16
+ const { asset, binaryName } = resolveAsset();
17
+ const destPath = cacheDir(version.slice(1), asset);
18
+
19
+ if (fs.existsSync(destPath)) {
20
+ return destPath;
21
+ }
22
+
23
+ await downloadBinary({
24
+ releaseBase: releaseBase(),
25
+ version,
26
+ asset,
27
+ destPath,
28
+ });
29
+
30
+ // Convenience symlink: ~/.cortex/npm/current/<binaryName>
31
+ const currentDir = path.join(path.dirname(path.dirname(destPath)), "current");
32
+ await fs.promises.mkdir(currentDir, { recursive: true });
33
+ const linkPath = path.join(currentDir, binaryName);
34
+ try {
35
+ await fs.promises.unlink(linkPath);
36
+ } catch (err) {
37
+ if (err.code !== "ENOENT") throw err;
38
+ }
39
+ try {
40
+ await fs.promises.symlink(destPath, linkPath);
41
+ } catch {
42
+ // Windows may require elevated symlink rights; ignore.
43
+ }
44
+
45
+ return destPath;
46
+ }
47
+
48
+ async function main() {
49
+ try {
50
+ const dest = await ensureBinary();
51
+ if (dest) {
52
+ console.log(`cortex-cli: installed native binary to ${dest}`);
53
+ }
54
+ } catch (err) {
55
+ console.error(`cortex-cli: postinstall failed: ${err.message}`);
56
+ process.exit(1);
57
+ }
58
+ }
59
+
60
+ if (require.main === module) {
61
+ main();
62
+ }
63
+
64
+ module.exports = { ensureBinary };
package/lib/paths.js ADDED
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ const fs = require("fs");
4
+ const os = require("os");
5
+ const path = require("path");
6
+
7
+ function packageRoot() {
8
+ return path.join(__dirname, "..");
9
+ }
10
+
11
+ function readPackageVersion() {
12
+ const pkgPath = path.join(packageRoot(), "package.json");
13
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
14
+ if (!pkg.version || pkg.version === "0.0.0-dev") {
15
+ throw new Error("cortex-cli npm package has no pinned release version");
16
+ }
17
+ return pkg.version;
18
+ }
19
+
20
+ function releaseRepo() {
21
+ return process.env.CORTEX_CLI_REPO || "Mateooo93/cortex-cli";
22
+ }
23
+
24
+ function releaseBase() {
25
+ return `https://github.com/${releaseRepo()}/releases`;
26
+ }
27
+
28
+ function cacheDir(version, asset) {
29
+ return path.join(os.homedir(), ".cortex", "npm", version, asset);
30
+ }
31
+
32
+ module.exports = {
33
+ packageRoot,
34
+ readPackageVersion,
35
+ releaseRepo,
36
+ releaseBase,
37
+ cacheDir,
38
+ };
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ const os = require("os");
4
+
5
+ /**
6
+ * Map Node platform/arch to the cortex release asset basename.
7
+ * Returns { asset, binaryName } where asset is the GitHub release filename.
8
+ */
9
+ function resolveAsset() {
10
+ const platform = os.platform();
11
+ const arch = os.arch();
12
+
13
+ if (platform === "darwin") {
14
+ if (arch === "arm64") {
15
+ return { asset: "cortex-darwin-arm64", binaryName: "cortex" };
16
+ }
17
+ throw unsupported(platform, arch, "macOS builds are Apple Silicon (arm64) only");
18
+ }
19
+
20
+ if (platform === "linux") {
21
+ if (arch === "x64") {
22
+ return { asset: "cortex-linux-amd64", binaryName: "cortex" };
23
+ }
24
+ if (arch === "arm64") {
25
+ return { asset: "cortex-linux-arm64", binaryName: "cortex" };
26
+ }
27
+ throw unsupported(platform, arch);
28
+ }
29
+
30
+ if (platform === "win32") {
31
+ if (arch === "x64") {
32
+ return { asset: "cortex-windows-amd64.exe", binaryName: "cortex.exe" };
33
+ }
34
+ if (arch === "arm64") {
35
+ return { asset: "cortex-windows-arm64.exe", binaryName: "cortex.exe" };
36
+ }
37
+ throw unsupported(platform, arch);
38
+ }
39
+
40
+ throw unsupported(platform, arch);
41
+ }
42
+
43
+ function unsupported(platform, arch, hint) {
44
+ const msg =
45
+ `cortex-cli: unsupported platform ${platform}/${arch}.` +
46
+ (hint ? ` ${hint}` : "") +
47
+ " Install a binary from https://github.com/Mateooo93/cortex-cli/releases";
48
+ const err = new Error(msg);
49
+ err.code = "UNSUPPORTED_PLATFORM";
50
+ return err;
51
+ }
52
+
53
+ module.exports = { resolveAsset };
package/lib/run.js ADDED
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ const { spawn } = require("child_process");
4
+ const fs = require("fs");
5
+
6
+ const { ensureBinary } = require("./install");
7
+
8
+ async function main() {
9
+ let binaryPath;
10
+ try {
11
+ binaryPath = await ensureBinary();
12
+ } catch (err) {
13
+ console.error(err.message || err);
14
+ process.exit(1);
15
+ }
16
+
17
+ if (!binaryPath || !fs.existsSync(binaryPath)) {
18
+ console.error(
19
+ "cortex-cli: native binary not installed. Re-run: npm install -g mateooo93-cortex"
20
+ );
21
+ process.exit(1);
22
+ }
23
+
24
+ const env = {
25
+ ...process.env,
26
+ CORTEX_NPM_PACKAGE: "mateooo93-cortex",
27
+ CORTEX_NPM_SHIM: __filename,
28
+ };
29
+
30
+ const child = spawn(binaryPath, process.argv.slice(2), {
31
+ stdio: "inherit",
32
+ windowsHide: false,
33
+ env,
34
+ });
35
+
36
+ child.on("error", (err) => {
37
+ console.error(`cortex-cli: failed to launch ${binaryPath}: ${err.message}`);
38
+ process.exit(1);
39
+ });
40
+
41
+ child.on("exit", (code, signal) => {
42
+ if (signal) {
43
+ process.kill(process.pid, signal);
44
+ return;
45
+ }
46
+ process.exit(code ?? 1);
47
+ });
48
+ }
49
+
50
+ main();
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "mateooo93-cortex",
3
+ "version": "0.25.20",
4
+ "description": "Fast AI coding agent with a polished terminal UI (npm wrapper — downloads the native binary for your OS)",
5
+ "license": "AGPL-3.0-or-later",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/Mateooo93/cortex-cli.git"
9
+ },
10
+ "homepage": "https://github.com/Mateooo93/cortex-cli#readme",
11
+ "bugs": {
12
+ "url": "https://github.com/Mateooo93/cortex-cli/issues"
13
+ },
14
+ "keywords": [
15
+ "cortex",
16
+ "ai",
17
+ "coding-agent",
18
+ "cli",
19
+ "tui",
20
+ "terminal"
21
+ ],
22
+ "engines": {
23
+ "node": ">=18"
24
+ },
25
+ "os": [
26
+ "darwin",
27
+ "linux",
28
+ "win32"
29
+ ],
30
+ "cpu": [
31
+ "x64",
32
+ "arm64"
33
+ ],
34
+ "bin": {
35
+ "cortex": "shims/cortex.js"
36
+ },
37
+ "files": [
38
+ "shims",
39
+ "lib",
40
+ "README.md"
41
+ ],
42
+ "scripts": {
43
+ "postinstall": "node lib/install.js"
44
+ }
45
+ }
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ require("../lib/run");