@kernaut/kernaut 0.1.0-linux-x64 → 0.1.0

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 (2) hide show
  1. package/bin/kernaut.js +178 -0
  2. package/package.json +18 -11
package/bin/kernaut.js ADDED
@@ -0,0 +1,178 @@
1
+ #!/usr/bin/env node
2
+ // Unified entry point for the Kernaut CLI.
3
+
4
+ import { spawn } from "node:child_process";
5
+ import { existsSync, realpathSync } from "fs";
6
+ import { createRequire } from "node:module";
7
+ import path from "path";
8
+ import { fileURLToPath } from "url";
9
+
10
+ const __filename = fileURLToPath(import.meta.url);
11
+ const __dirname = path.dirname(__filename);
12
+ const require = createRequire(import.meta.url);
13
+
14
+ const PLATFORM_PACKAGE_BY_TARGET = {
15
+ "x86_64-unknown-linux-musl": "@kernaut/kernaut-linux-x64",
16
+ "aarch64-unknown-linux-musl": "@kernaut/kernaut-linux-arm64",
17
+ "x86_64-apple-darwin": "@kernaut/kernaut-darwin-x64",
18
+ "aarch64-apple-darwin": "@kernaut/kernaut-darwin-arm64",
19
+ "x86_64-pc-windows-msvc": "@kernaut/kernaut-win32-x64",
20
+ "aarch64-pc-windows-msvc": "@kernaut/kernaut-win32-arm64",
21
+ };
22
+
23
+ const { platform, arch } = process;
24
+
25
+ let targetTriple = null;
26
+ switch (platform) {
27
+ case "linux":
28
+ case "android":
29
+ switch (arch) {
30
+ case "x64":
31
+ targetTriple = "x86_64-unknown-linux-musl";
32
+ break;
33
+ case "arm64":
34
+ targetTriple = "aarch64-unknown-linux-musl";
35
+ break;
36
+ default:
37
+ break;
38
+ }
39
+ break;
40
+ case "darwin":
41
+ switch (arch) {
42
+ case "x64":
43
+ targetTriple = "x86_64-apple-darwin";
44
+ break;
45
+ case "arm64":
46
+ targetTriple = "aarch64-apple-darwin";
47
+ break;
48
+ default:
49
+ break;
50
+ }
51
+ break;
52
+ case "win32":
53
+ switch (arch) {
54
+ case "x64":
55
+ targetTriple = "x86_64-pc-windows-msvc";
56
+ break;
57
+ case "arm64":
58
+ targetTriple = "aarch64-pc-windows-msvc";
59
+ break;
60
+ default:
61
+ break;
62
+ }
63
+ break;
64
+ default:
65
+ break;
66
+ }
67
+
68
+ if (!targetTriple) {
69
+ throw new Error(`Unsupported platform: ${platform} (${arch})`);
70
+ }
71
+
72
+ const platformPackage = PLATFORM_PACKAGE_BY_TARGET[targetTriple];
73
+ if (!platformPackage) {
74
+ throw new Error(`Unsupported target triple: ${targetTriple}`);
75
+ }
76
+
77
+ function findKernautExecutable() {
78
+ let vendorRoot;
79
+ try {
80
+ const packageJsonPath = require.resolve(`${platformPackage}/package.json`);
81
+ vendorRoot = path.join(path.dirname(packageJsonPath), "vendor");
82
+ } catch {
83
+ vendorRoot = path.join(__dirname, "..", "vendor");
84
+ }
85
+
86
+ const kernautExecutable = path.join(
87
+ vendorRoot,
88
+ targetTriple,
89
+ "bin",
90
+ process.platform === "win32" ? "kernaut.exe" : "kernaut",
91
+ );
92
+ if (existsSync(kernautExecutable)) {
93
+ return kernautExecutable;
94
+ }
95
+
96
+ const packageManager = detectPackageManager();
97
+ const updateCommand =
98
+ packageManager === "bun"
99
+ ? "bun install -g @kernaut/kernaut@latest"
100
+ : "npm install -g @kernaut/kernaut@latest";
101
+ throw new Error(
102
+ `Missing optional dependency ${platformPackage}. Reinstall Kernaut: ${updateCommand}`,
103
+ );
104
+ }
105
+
106
+ const binaryPath = findKernautExecutable();
107
+
108
+ function detectPackageManager() {
109
+ const userAgent = process.env.npm_config_user_agent || "";
110
+ if (/\bbun\//.test(userAgent)) {
111
+ return "bun";
112
+ }
113
+
114
+ const execPath = process.env.npm_execpath || "";
115
+ if (execPath.includes("bun")) {
116
+ return "bun";
117
+ }
118
+
119
+ if (
120
+ __dirname.includes(".bun/install/global") ||
121
+ __dirname.includes(".bun\\install\\global")
122
+ ) {
123
+ return "bun";
124
+ }
125
+
126
+ return userAgent ? "npm" : null;
127
+ }
128
+
129
+ const packageManagerEnvVar =
130
+ detectPackageManager() === "bun"
131
+ ? "CODEX_MANAGED_BY_BUN"
132
+ : "CODEX_MANAGED_BY_NPM";
133
+ const env = {
134
+ ...process.env,
135
+ [packageManagerEnvVar]: "1",
136
+ CODEX_MANAGED_PACKAGE_ROOT: realpathSync(path.join(__dirname, "..")),
137
+ };
138
+
139
+ const child = spawn(binaryPath, process.argv.slice(2), {
140
+ stdio: "inherit",
141
+ env,
142
+ });
143
+
144
+ child.on("error", (err) => {
145
+ console.error(err);
146
+ process.exit(1);
147
+ });
148
+
149
+ const forwardSignal = (signal) => {
150
+ if (child.killed) {
151
+ return;
152
+ }
153
+ try {
154
+ child.kill(signal);
155
+ } catch {
156
+ /* ignore */
157
+ }
158
+ };
159
+
160
+ ["SIGINT", "SIGTERM", "SIGHUP"].forEach((sig) => {
161
+ process.on(sig, () => forwardSignal(sig));
162
+ });
163
+
164
+ const childResult = await new Promise((resolve) => {
165
+ child.on("exit", (code, signal) => {
166
+ if (signal) {
167
+ resolve({ type: "signal", signal });
168
+ } else {
169
+ resolve({ type: "code", exitCode: code ?? 1 });
170
+ }
171
+ });
172
+ });
173
+
174
+ if (childResult.type === "signal") {
175
+ process.kill(process.pid, childResult.signal);
176
+ } else {
177
+ process.exit(childResult.exitCode);
178
+ }
package/package.json CHANGED
@@ -1,18 +1,25 @@
1
1
  {
2
2
  "name": "@kernaut/kernaut",
3
- "version": "0.1.0-linux-x64",
3
+ "version": "0.1.0",
4
+ "description": "Kernaut CLI is a coding agent for kernel and operator optimization workflows.",
4
5
  "license": "UNLICENSED",
5
- "os": [
6
- "linux"
7
- ],
8
- "cpu": [
9
- "x64"
10
- ],
11
- "files": [
12
- "vendor"
13
- ],
6
+ "bin": {
7
+ "kernaut": "bin/kernaut.js"
8
+ },
9
+ "type": "module",
14
10
  "engines": {
15
11
  "node": ">=16"
16
12
  },
17
- "packageManager": "pnpm@10.33.0+sha512.10568bb4a6afb58c9eb3630da90cc9516417abebd3fabbe6739f0ae795728da1491e9db5a544c76ad8eb7570f5c4bb3d6c637b2cb41bfdcdb47fa823c8649319"
13
+ "files": [
14
+ "bin/kernaut.js"
15
+ ],
16
+ "packageManager": "pnpm@10.33.0+sha512.10568bb4a6afb58c9eb3630da90cc9516417abebd3fabbe6739f0ae795728da1491e9db5a544c76ad8eb7570f5c4bb3d6c637b2cb41bfdcdb47fa823c8649319",
17
+ "optionalDependencies": {
18
+ "@kernaut/kernaut-linux-x64": "npm:@kernaut/kernaut@0.1.0-linux-x64",
19
+ "@kernaut/kernaut-linux-arm64": "npm:@kernaut/kernaut@0.1.0-linux-arm64",
20
+ "@kernaut/kernaut-darwin-x64": "npm:@kernaut/kernaut@0.1.0-darwin-x64",
21
+ "@kernaut/kernaut-darwin-arm64": "npm:@kernaut/kernaut@0.1.0-darwin-arm64",
22
+ "@kernaut/kernaut-win32-x64": "npm:@kernaut/kernaut@0.1.0-win32-x64",
23
+ "@kernaut/kernaut-win32-arm64": "npm:@kernaut/kernaut@0.1.0-win32-arm64"
24
+ }
18
25
  }