ozarnik 0.2.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.
- package/bin/ozarnik.js +103 -0
- package/package.json +20 -0
package/bin/ozarnik.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Unified entry point for the Ozarnik CLI.
|
|
3
|
+
// Detects host platform and spawns the platform-specific Ozarnik binary that
|
|
4
|
+
// was installed via the matching optional dependency.
|
|
5
|
+
|
|
6
|
+
import { spawn } from "node:child_process";
|
|
7
|
+
import { existsSync, realpathSync, chmodSync, statSync } from "node:fs";
|
|
8
|
+
import { createRequire } from "node:module";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
|
|
12
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
13
|
+
const __dirname = path.dirname(__filename);
|
|
14
|
+
const require = createRequire(import.meta.url);
|
|
15
|
+
|
|
16
|
+
const PLATFORM_PACKAGE_BY_TARGET = {
|
|
17
|
+
"x86_64-unknown-linux-musl": "ozarnik-linux-x64",
|
|
18
|
+
"aarch64-unknown-linux-musl": "ozarnik-linux-arm64",
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const { platform, arch } = process;
|
|
22
|
+
|
|
23
|
+
let targetTriple = null;
|
|
24
|
+
switch (platform) {
|
|
25
|
+
case "linux":
|
|
26
|
+
case "android":
|
|
27
|
+
if (arch === "x64") targetTriple = "x86_64-unknown-linux-musl";
|
|
28
|
+
else if (arch === "arm64") targetTriple = "aarch64-unknown-linux-musl";
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (!targetTriple) {
|
|
33
|
+
throw new Error(`Unsupported platform: ${platform} (${arch})`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const platformPackage = PLATFORM_PACKAGE_BY_TARGET[targetTriple];
|
|
37
|
+
const binaryName = "ozarnik";
|
|
38
|
+
|
|
39
|
+
function resolveBinary() {
|
|
40
|
+
try {
|
|
41
|
+
const pkgJson = require.resolve(`${platformPackage}/package.json`);
|
|
42
|
+
const pkgRoot = path.dirname(pkgJson);
|
|
43
|
+
const candidate = path.join(pkgRoot, "bin", binaryName);
|
|
44
|
+
if (existsSync(candidate)) return candidate;
|
|
45
|
+
} catch {}
|
|
46
|
+
const localCandidate = path.join(
|
|
47
|
+
__dirname,
|
|
48
|
+
"..",
|
|
49
|
+
"vendor",
|
|
50
|
+
targetTriple,
|
|
51
|
+
"bin",
|
|
52
|
+
binaryName,
|
|
53
|
+
);
|
|
54
|
+
if (existsSync(localCandidate)) return localCandidate;
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const binaryPath = resolveBinary();
|
|
59
|
+
if (!binaryPath) {
|
|
60
|
+
throw new Error(
|
|
61
|
+
`Missing optional dependency ${platformPackage}. Reinstall: npm install -g ozarnik@latest`,
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// chmod fallback in case postinstall did not run (e.g. --ignore-scripts).
|
|
66
|
+
try {
|
|
67
|
+
const mode = statSync(binaryPath).mode & 0o777;
|
|
68
|
+
if ((mode & 0o111) === 0) chmodSync(binaryPath, 0o755);
|
|
69
|
+
} catch {}
|
|
70
|
+
|
|
71
|
+
const env = { ...process.env };
|
|
72
|
+
env.OZARNIK_MANAGED_PACKAGE_ROOT = realpathSync(path.join(__dirname, ".."));
|
|
73
|
+
|
|
74
|
+
const child = spawn(binaryPath, process.argv.slice(2), {
|
|
75
|
+
stdio: "inherit",
|
|
76
|
+
env,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
child.on("error", (err) => {
|
|
80
|
+
console.error(err);
|
|
81
|
+
process.exit(1);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
["SIGINT", "SIGTERM", "SIGHUP"].forEach((sig) => {
|
|
85
|
+
process.on(sig, () => {
|
|
86
|
+
if (!child.killed) {
|
|
87
|
+
try { child.kill(sig); } catch {}
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const result = await new Promise((resolve) => {
|
|
93
|
+
child.on("exit", (code, signal) => {
|
|
94
|
+
if (signal) resolve({ type: "signal", signal });
|
|
95
|
+
else resolve({ type: "code", exitCode: code ?? 1 });
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
if (result.type === "signal") {
|
|
100
|
+
process.kill(process.pid, result.signal);
|
|
101
|
+
} else {
|
|
102
|
+
process.exit(result.exitCode);
|
|
103
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ozarnik",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Ozarnik - coding agent CLI/TUI powered by ozarnik.rf",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"ozarnik": "bin/ozarnik.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"bin"
|
|
12
|
+
],
|
|
13
|
+
"optionalDependencies": {
|
|
14
|
+
"ozarnik-linux-x64": "0.2.0",
|
|
15
|
+
"ozarnik-linux-arm64": "0.2.0"
|
|
16
|
+
},
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=18"
|
|
19
|
+
}
|
|
20
|
+
}
|