@zatsepin/klava 0.0.0-stage → 0.3.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 (4) hide show
  1. package/README.md +57 -2
  2. package/klava +48 -0
  3. package/package.json +45 -4
  4. package/postinstall.js +106 -0
package/README.md CHANGED
@@ -1,3 +1,58 @@
1
- # Temporary Holding Version
1
+ # @zatsepin/klava — run code agents against any provider
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Installs the `klava` binary: launch Claude Code, OpenCode, Pi or Codex against
4
+ any OpenAI-compatible provider (OpenRouter, Qwen, Cloud.ru, local LLMs) with a
5
+ local proxy in between, and keep API keys and other secrets out of what the
6
+ agent can read.
7
+
8
+ Node ≥ 18 is needed once, at install time, to pick the platform package — the
9
+ installed `klava` is a standalone binary with no Node runtime.
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ npm install --global @zatsepin/klava
15
+ klava --help
16
+ ```
17
+
18
+ One-off, no install:
19
+
20
+ ```bash
21
+ npx @zatsepin/klava --help
22
+ ```
23
+
24
+ The binary comes from an optional dependency matched to your OS and CPU —
25
+ `@zatsepin/klava-linux-x64-gnu`, `@zatsepin/klava-linux-arm64-gnu`,
26
+ `@zatsepin/klava-darwin` (universal2: Apple Silicon + Intel) or
27
+ `@zatsepin/klava-win32-x64-msvc` — installed automatically, never a source
28
+ build. Alpine/musl and other platforms are not packaged: use
29
+ `cargo install klava` there.
30
+
31
+ ## Quick start
32
+
33
+ ```bash
34
+ klava launch # pick an agent and a model, start the proxy, launch it
35
+ klava launch claude # Claude Code against your configured model
36
+ klava launch claude --provider ~deepseek/deepseek-flash-latest
37
+ klava serve # proxy only, on :8085
38
+ ```
39
+
40
+ The first `launch` walks you through picking a provider and a model, stores it
41
+ in the config, and from then on the agent talks to `klava`, which translates
42
+ between the agent's wire format (Anthropic or OpenAI) and your provider's.
43
+
44
+ ## Secrets filtering
45
+
46
+ `klava` inspects the files the agent is about to send and redacts leaked
47
+ credentials — API keys, private keys, tokens — before the request leaves your
48
+ machine. Every request and response is optionally logged (`--verbose`).
49
+
50
+ ## Platforms
51
+
52
+ | OS | Package | Notes |
53
+ |----|---------|-------|
54
+ | Linux x64 / arm64 | `klava-linux-*-gnu` | glibc ≥ 2.17, no build tools needed |
55
+ | macOS (Intel + Apple Silicon) | `klava-darwin` | one universal2 binary |
56
+ | Windows x64 | `klava-win32-x64-msvc` | |
57
+
58
+ Source, Rust crates and the pip package: https://github.com/Partysun/klava
package/klava ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env node
2
+
3
+ // Fallback shim. On Unix, `postinstall` replaces this file with the native
4
+ // binary. On Windows, npm-generated global wrappers call this JS bin target
5
+ // through node, so it must stay in place and spawn the `.exe`.
6
+
7
+ const { spawn } = require("node:child_process");
8
+ const { resolveBinaryPath } = require("./postinstall");
9
+
10
+ if (process.platform !== "win32") {
11
+ console.error(
12
+ "[warn] postinstall script did not run; falling back to runtime binary resolution.",
13
+ );
14
+ console.error("Enable postinstall to avoid the per-invocation overhead.");
15
+ }
16
+
17
+ const binaryPath = resolveBinaryPath();
18
+ if (!binaryPath) {
19
+ console.error(
20
+ "[klava] Failed to locate the native binary. " +
21
+ "Ensure optional dependencies are installed (do not pass --no-optional).",
22
+ );
23
+ process.exit(1);
24
+ }
25
+
26
+ const child = spawn(binaryPath, process.argv.slice(2), { stdio: "inherit" });
27
+
28
+ child.on("error", (error) => {
29
+ console.error("[klava] Failed to execute native binary:", error);
30
+ process.exit(1);
31
+ });
32
+
33
+ const signals = ["SIGINT", "SIGTERM", "SIGHUP"];
34
+ const handlers = signals.map((signal) => {
35
+ const handler = () => {
36
+ if (!child.killed) {
37
+ try { child.kill(signal); } catch (_) {}
38
+ }
39
+ };
40
+ process.on(signal, handler);
41
+ return [signal, handler];
42
+ });
43
+
44
+ child.on("exit", (code, signal) => {
45
+ for (const [s, h] of handlers) process.removeListener(s, h);
46
+ if (signal) process.kill(process.pid, signal);
47
+ else process.exit(code == null ? 1 : code);
48
+ });
package/package.json CHANGED
@@ -1,6 +1,47 @@
1
1
  {
2
2
  "name": "@zatsepin/klava",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.3.0",
4
+ "description": "Klava CLI — run code agents (Claude Code, OpenCode, Pi, Codex) against any OpenAI-compatible provider, with secrets filtered out of your filesystem first.",
5
+ "homepage": "https://github.com/Partysun/klava",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/Partysun/klava.git"
9
+ },
10
+ "license": "Apache-2.0",
11
+ "keywords": [
12
+ "claude",
13
+ "claude-code",
14
+ "codex",
15
+ "opencode",
16
+ "anthropic",
17
+ "openai",
18
+ "proxy",
19
+ "cli"
20
+ ],
21
+ "engines": {
22
+ "node": ">= 18.0.0"
23
+ },
24
+ "files": [
25
+ "klava",
26
+ "postinstall.js"
27
+ ],
28
+ "scripts": {
29
+ "postinstall": "node postinstall.js"
30
+ },
31
+ "optionalDependencies": {
32
+ "@zatsepin/klava-darwin": "0.3.0",
33
+ "@zatsepin/klava-linux-arm64-gnu": "0.3.0",
34
+ "@zatsepin/klava-linux-x64-gnu": "0.3.0",
35
+ "@zatsepin/klava-win32-x64-msvc": "0.3.0"
36
+ },
37
+ "bin": {
38
+ "klava": "klava"
39
+ },
40
+ "publishConfig": {
41
+ "registry": "https://registry.npmjs.org/",
42
+ "access": "public"
43
+ },
44
+ "bugs": {
45
+ "url": "https://github.com/Partysun/klava/issues"
46
+ }
47
+ }
package/postinstall.js ADDED
@@ -0,0 +1,106 @@
1
+ // Port of jigor's @zatsepin/jigor postinstall: locate the native `klava`
2
+ // binary for the current platform (a platform package installed as an
3
+ // optional dependency, or a local `target/release|debug/klava` dev build)
4
+ // and hard-link it over the JS shim next to this file.
5
+ const fs = require("fs");
6
+ const path = require("path");
7
+
8
+ const binaryName = process.platform === "win32" ? "klava.exe" : "klava";
9
+
10
+ // musl and everything else are not packaged yet: klava links the system
11
+ // libc (no static musl build), so an Alpine container must install it with
12
+ // cargo or pip-from-source instead of npm.
13
+ function isMusl() {
14
+ if (process.platform !== "linux") return false;
15
+ try {
16
+ // glibc systems report a runtime version here, musl systems do not.
17
+ const report = process.report && process.report.getReport();
18
+ return !(report && report.header && report.header.glibcVersionRuntime);
19
+ } catch (_) {
20
+ return false;
21
+ }
22
+ }
23
+
24
+ function detectPackageName() {
25
+ const { platform, arch } = process;
26
+ switch (platform) {
27
+ case "darwin":
28
+ // one universal2 fat binary covers Intel (x64) and Apple Silicon (arm64)
29
+ if (arch === "x64" || arch === "arm64") return "@zatsepin/klava-darwin";
30
+ break;
31
+ case "linux":
32
+ if (isMusl()) return null;
33
+ if (arch === "arm64") return "@zatsepin/klava-linux-arm64-gnu";
34
+ if (arch === "x64") return "@zatsepin/klava-linux-x64-gnu";
35
+ break;
36
+ case "win32":
37
+ if (arch === "x64") return "@zatsepin/klava-win32-x64-msvc";
38
+ break;
39
+ }
40
+ return null;
41
+ }
42
+
43
+ function resolveBinaryDir() {
44
+ const pkgName = detectPackageName();
45
+ if (pkgName) {
46
+ try {
47
+ const dir = path.dirname(
48
+ require.resolve(`${pkgName}/package.json`, { paths: [__dirname] }),
49
+ );
50
+ if (fs.existsSync(path.join(dir, binaryName))) return dir;
51
+ } catch (_) {
52
+ // fall through to local dev paths
53
+ }
54
+ }
55
+ for (const profile of ["release", "debug"]) {
56
+ const dir = path.join(__dirname, "..", "target", profile);
57
+ if (fs.existsSync(path.join(dir, binaryName))) return dir;
58
+ }
59
+ return null;
60
+ }
61
+
62
+ function resolveBinaryPath() {
63
+ const dir = resolveBinaryDir();
64
+ return dir ? path.join(dir, binaryName) : null;
65
+ }
66
+
67
+ function installBinary(src, dest) {
68
+ try {
69
+ fs.linkSync(src, dest);
70
+ } catch (_) {
71
+ fs.copyFileSync(src, dest);
72
+ }
73
+ }
74
+
75
+ function main() {
76
+ const sourceDir = resolveBinaryDir();
77
+ if (!sourceDir) {
78
+ console.error(
79
+ "[klava] No native binary found for " +
80
+ `${process.platform ?? "?"}/${process.arch ?? "?"}. ` +
81
+ "Supported: linux x64/arm64 (glibc), macos (universal2: Intel + Apple Silicon), windows x64. " +
82
+ "Musl and other platforms are not packaged yet — use `cargo install klava` there.",
83
+ );
84
+ process.exit(1);
85
+ }
86
+
87
+ const src = path.join(sourceDir, binaryName);
88
+ const destBin = path.join(__dirname, binaryName);
89
+ try {
90
+ installBinary(src, destBin);
91
+ } catch (_) {
92
+ console.error("[klava] Failed to move the native binary into place.");
93
+ process.exit(1);
94
+ }
95
+ }
96
+
97
+ module.exports = {
98
+ binaryName,
99
+ detectPackageName,
100
+ resolveBinaryDir,
101
+ resolveBinaryPath,
102
+ };
103
+
104
+ if (require.main === module) {
105
+ main();
106
+ }