khive 0.0.1 → 0.2.5

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,50 @@
1
+ # khive
2
+
3
+ A research knowledge graph runtime — 63 verbs, 7 packs, one MCP tool.
4
+
5
+ [![GitHub](https://img.shields.io/github/stars/ohdearquant/khive?style=flat)](https://github.com/ohdearquant/khive)
6
+ [![crates.io](https://img.shields.io/crates/v/khive-mcp.svg)](https://crates.io/crates/khive-mcp)
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ npm install -g khive
12
+ ```
13
+
14
+ ## Configure
15
+
16
+ Add to `.mcp.json` (project-level or `~/.claude/mcp.json` for global):
17
+
18
+ ```json
19
+ { "mcpServers": { "khive": { "command": "khive", "args": ["mcp"] } } }
20
+ ```
21
+
22
+ All 7 packs load by default. A background daemon auto-spawns to keep the runtime warm.
23
+
24
+ ## What you get
25
+
26
+ | Pack | Verbs | What it does |
27
+ | ------------- | ----- | ------------------------------------------------ |
28
+ | **kg** | 16 | Entities, edges, notes, graph queries, proposals |
29
+ | **gtd** | 5 | Task lifecycle (inbox → next → active → done) |
30
+ | **memory** | 2 | Salience-weighted remember / decay-ranked recall |
31
+ | **brain** | 13 | Bayesian user profiles + feedback loop |
32
+ | **comm** | 5 | Threaded messaging |
33
+ | **schedule** | 4 | Reminders and scheduled verb execution |
34
+ | **knowledge** | 18 | Atom-based KB with embedding rerank search |
35
+
36
+ ## Usage
37
+
38
+ ```text
39
+ khive mcp # Start MCP server (used by Claude Code)
40
+ khive kg init # Initialize .khive/kg/ in a git repo
41
+ khive kg validate # Check NDJSON files against schema
42
+ khive kg commit -m "msg" # Validate + stage + git commit
43
+ ```
44
+
45
+ ## Documentation
46
+
47
+ - [GitHub](https://github.com/ohdearquant/khive)
48
+ - [AGENTS.md](https://github.com/ohdearquant/khive/blob/main/AGENTS.md) — full verb reference
49
+ - [Marketplace plugins](https://github.com/ohdearquant/khive/tree/main/marketplace) — Claude Code
50
+ skills
package/bin/khive CHANGED
@@ -1,3 +1,200 @@
1
1
  #!/usr/bin/env node
2
- console.log("khive CLI — coming soon. Visit https://khive.ai for early access.");
3
- process.exit(0);
2
+
3
+ // khive — per-platform binary shim (ADR-026)
4
+ //
5
+ // Resolves the host platform to the matching @khive-ai/kernel-{platform}
6
+ // optional dependency and execs the kkernel binary from its bin/ directory.
7
+ // Falls back to a local cargo build directory for monorepo development.
8
+ //
9
+ // NOTE: npm/bin/khive-mcp is a sibling shim that resolves khive-mcp using
10
+ // the same logic. Both shims share `resolveBinaryPath()` — keep them in sync.
11
+
12
+ "use strict";
13
+
14
+ const { execFileSync } = require("child_process");
15
+ const path = require("path");
16
+ const fs = require("fs");
17
+ const os = require("os");
18
+
19
+ // Map os.platform()+os.arch() → @khive-ai/kernel-{platform} package name suffix.
20
+ // Follows the naming established in ADR-026.
21
+ //
22
+ // NOTE: linux-arm64 is glibc-only in v1. Musl arm64 is not yet in the matrix.
23
+ // If musl is detected on arm64, `detectLinuxVariant` returns null and we error
24
+ // with a clear "unsupported" message — see getBinaryPath() below.
25
+ const PLATFORM_MAP = {
26
+ "darwin-arm64": "darwin-arm64",
27
+ "darwin-x64": "darwin-x64",
28
+ "linux-arm64": null, // resolved dynamically: glibc=linux-arm64, musl=unsupported
29
+ "linux-x64": null, // resolved dynamically by detectLinuxVariant()
30
+ "win32-x64": "win32-x64",
31
+ };
32
+
33
+ /**
34
+ * Detect whether the Linux runtime links against glibc or musl.
35
+ * Detection order (most-reliable first):
36
+ * 1. `ldd --version` — invokes the actual system linker
37
+ * 2. `/lib/ld-musl-*` glob — fast filesystem check
38
+ * Returns "gnu" or "musl". Defaults to "gnu" if detection is inconclusive.
39
+ *
40
+ * NOTE: cli/lib/kernel.ts uses the same ordered detection. Keep them in sync.
41
+ */
42
+ function detectLibc() {
43
+ try {
44
+ const ldd = require("child_process")
45
+ .execFileSync("ldd", ["--version"], { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] })
46
+ .toLowerCase();
47
+ if (ldd.includes("musl")) return "musl";
48
+ return "gnu";
49
+ } catch (_) {
50
+ // ldd not available or returned non-zero — check /lib/ld-musl-* presence
51
+ try {
52
+ const libs = fs.readdirSync("/lib");
53
+ if (libs.some((f) => f.startsWith("ld-musl-"))) return "musl";
54
+ } catch (_) {}
55
+ return "gnu";
56
+ }
57
+ }
58
+
59
+ const SUPPORTED_PLATFORMS = [
60
+ "darwin-arm64",
61
+ "darwin-x64",
62
+ "linux-x64-gnu",
63
+ "linux-x64-musl",
64
+ "linux-arm64",
65
+ "win32-x64",
66
+ ];
67
+
68
+ function getPlatformKey() {
69
+ return `${os.platform()}-${os.arch()}`;
70
+ }
71
+
72
+ /**
73
+ * Resolve the platform suffix for the @khive-ai/kernel-{platform} subpackage.
74
+ * Returns null if the platform is recognized but unsupported (musl arm64).
75
+ * Returns undefined if the platform is entirely unknown.
76
+ */
77
+ function resolvePlatformSuffix() {
78
+ const platformKey = getPlatformKey();
79
+ if (platformKey === "linux-x64") {
80
+ const libc = detectLibc();
81
+ return libc === "musl" ? "linux-x64-musl" : "linux-x64-gnu";
82
+ }
83
+ if (platformKey === "linux-arm64") {
84
+ const libc = detectLibc();
85
+ if (libc === "musl") {
86
+ // musl arm64 is not in the v1 matrix — emit a clear error instead of
87
+ // silently falling back to the glibc arm64 binary (which will fail with
88
+ // a cryptic ENOENT when the glibc loader is absent).
89
+ return null; // caller treats null as "unsupported but recognized"
90
+ }
91
+ return "linux-arm64";
92
+ }
93
+ return PLATFORM_MAP[platformKey]; // darwin-arm64, darwin-x64, win32-x64
94
+ }
95
+
96
+ /**
97
+ * Locate the named binary using the platform subpackage resolution strategy:
98
+ * 1. KKERNEL_BINARY env var override (development / CI)
99
+ * 2. Package-manager-agnostic resolution via require.resolve (works with
100
+ * npm, yarn, and pnpm including isolated-store layouts)
101
+ * 3. Dev fallback: cargo build directory inside the monorepo
102
+ *
103
+ * `binaryName` is "kkernel" or "khive-mcp" (without .exe; added for Windows).
104
+ */
105
+ function getBinaryPath(binaryName) {
106
+ const isWindows = os.platform() === "win32";
107
+ const exe = isWindows ? `${binaryName}.exe` : binaryName;
108
+
109
+ // 1. Explicit override env var. For kkernel the conventional var is
110
+ // KKERNEL_BINARY; for khive-mcp we accept KHIVE_MCP_BINARY.
111
+ const envVar = binaryName === "kkernel" ? "KKERNEL_BINARY" : "KHIVE_MCP_BINARY";
112
+ const override = process.env[envVar];
113
+ if (override && fs.existsSync(override)) return override;
114
+
115
+ const platformSuffix = resolvePlatformSuffix();
116
+
117
+ // null means recognized-but-unsupported platform (musl arm64)
118
+ if (platformSuffix === null) {
119
+ const platformKey = getPlatformKey();
120
+ const libc = detectLibc();
121
+ console.error(`khive: unsupported platform: ${platformKey} (libc: ${libc})`);
122
+ console.error("linux-arm64 with musl is not in the v1 release matrix.");
123
+ console.error("Supported: " + SUPPORTED_PLATFORMS.join(", "));
124
+ console.error(
125
+ "File an issue at https://github.com/ohdearquant/khive/issues if you need this target.",
126
+ );
127
+ process.exit(1);
128
+ }
129
+
130
+ // undefined means completely unknown platform
131
+ if (platformSuffix === undefined) {
132
+ const platformKey = getPlatformKey();
133
+ console.error(`khive: unsupported platform: ${platformKey}`);
134
+ console.error("Supported: " + SUPPORTED_PLATFORMS.join(", "));
135
+ console.error(
136
+ "File an issue at https://github.com/ohdearquant/khive/issues if you need this target.",
137
+ );
138
+ process.exit(1);
139
+ }
140
+
141
+ const pkgName = `@khive-ai/kernel-${platformSuffix}`;
142
+
143
+ // 2. Package-manager-agnostic resolution. `require.resolve` honours npm,
144
+ // yarn, AND pnpm's isolated-store layout (node_modules/.pnpm/...).
145
+ // Walk-up approaches break under pnpm's default shamefully-hoist=false.
146
+ try {
147
+ const pkgJsonPath = require.resolve(`${pkgName}/package.json`);
148
+ const pkgDir = path.dirname(pkgJsonPath);
149
+ const candidate = path.join(pkgDir, "bin", exe);
150
+ if (fs.existsSync(candidate)) return candidate;
151
+ } catch (_) {
152
+ // Package not installed — fall through to dev fallback.
153
+ }
154
+
155
+ // 3. Dev fallback: look for a cargo build in typical monorepo locations.
156
+ const devCandidates = [];
157
+ let search = path.join(__dirname, "..");
158
+ for (let i = 0; i < 8; i++) {
159
+ const cratesDir = path.join(search, "crates");
160
+ if (fs.existsSync(cratesDir)) {
161
+ devCandidates.push(path.join(cratesDir, "target", "release", exe));
162
+ devCandidates.push(path.join(cratesDir, "target", "debug", exe));
163
+ break;
164
+ }
165
+ const parent = path.dirname(search);
166
+ if (parent === search) break;
167
+ search = parent;
168
+ }
169
+ for (const c of devCandidates) {
170
+ if (fs.existsSync(c)) return c;
171
+ }
172
+
173
+ console.error(`khive: ${pkgName} not installed or ${binaryName} binary not found.`);
174
+ console.error(`Expected: ${pkgName}/bin/${exe}`);
175
+ console.error(
176
+ "Run 'npm install -g khive' to install platform binaries, or set " +
177
+ `${envVar} to point to a local build.`,
178
+ );
179
+ process.exit(1);
180
+ }
181
+
182
+ // `khive mcp [args]` dispatches to the khive-mcp binary (MCP stdio server).
183
+ // All other subcommands dispatch to kkernel (admin CLI).
184
+ const subcommand = process.argv[2];
185
+ const isMcp = subcommand === "mcp";
186
+ const binaryName = isMcp ? "khive-mcp" : "kkernel";
187
+ const args = isMcp ? process.argv.slice(3) : process.argv.slice(2);
188
+
189
+ try {
190
+ const binary = getBinaryPath(binaryName);
191
+ execFileSync(binary, args, {
192
+ stdio: "inherit",
193
+ env: process.env,
194
+ });
195
+ } catch (err) {
196
+ if (err.status !== undefined) {
197
+ process.exit(err.status);
198
+ }
199
+ throw err;
200
+ }
package/bin/khive-mcp ADDED
@@ -0,0 +1,161 @@
1
+ #!/usr/bin/env node
2
+
3
+ // khive-mcp — per-platform binary shim for the MCP stdio server (ADR-026)
4
+ //
5
+ // Resolves the host platform to the matching @khive-ai/kernel-{platform}
6
+ // optional dependency and execs the khive-mcp binary from its bin/ directory.
7
+ // Falls back to a local cargo build directory for monorepo development.
8
+ //
9
+ // This shim is the companion to npm/bin/khive. Both use the same
10
+ // `getBinaryPath()` logic — see npm/bin/khive for comments and rationale.
11
+ // Keep detection order and platform mapping in sync between the two shims.
12
+ //
13
+ // Users configure this binary in Claude Code's MCP config:
14
+ // {"mcpServers": {"khive": {"command": "khive-mcp"}}}
15
+
16
+ "use strict";
17
+
18
+ const { execFileSync } = require("child_process");
19
+ const path = require("path");
20
+ const fs = require("fs");
21
+ const os = require("os");
22
+
23
+ /**
24
+ * Detect whether the Linux runtime links against glibc or musl.
25
+ * Detection order (most-reliable first):
26
+ * 1. `ldd --version` — invokes the actual system linker
27
+ * 2. `/lib/ld-musl-*` glob — fast filesystem check
28
+ * Returns "gnu" or "musl". Defaults to "gnu" if detection is inconclusive.
29
+ *
30
+ * NOTE: npm/bin/khive and cli/lib/kernel.ts use the same detection order.
31
+ * Keep all three in sync.
32
+ */
33
+ function detectLibc() {
34
+ try {
35
+ const ldd = require("child_process")
36
+ .execFileSync("ldd", ["--version"], { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] })
37
+ .toLowerCase();
38
+ if (ldd.includes("musl")) return "musl";
39
+ return "gnu";
40
+ } catch (_) {
41
+ try {
42
+ const libs = fs.readdirSync("/lib");
43
+ if (libs.some((f) => f.startsWith("ld-musl-"))) return "musl";
44
+ } catch (_) {}
45
+ return "gnu";
46
+ }
47
+ }
48
+
49
+ const SUPPORTED_PLATFORMS = [
50
+ "darwin-arm64",
51
+ "darwin-x64",
52
+ "linux-x64-gnu",
53
+ "linux-x64-musl",
54
+ "linux-arm64",
55
+ "win32-x64",
56
+ ];
57
+
58
+ function getPlatformKey() {
59
+ return `${os.platform()}-${os.arch()}`;
60
+ }
61
+
62
+ function resolvePlatformSuffix() {
63
+ const platformKey = getPlatformKey();
64
+ if (platformKey === "linux-x64") {
65
+ const libc = detectLibc();
66
+ return libc === "musl" ? "linux-x64-musl" : "linux-x64-gnu";
67
+ }
68
+ if (platformKey === "linux-arm64") {
69
+ const libc = detectLibc();
70
+ if (libc === "musl") return null; // unsupported, caller emits clear error
71
+ return "linux-arm64";
72
+ }
73
+ const PLATFORM_MAP = {
74
+ "darwin-arm64": "darwin-arm64",
75
+ "darwin-x64": "darwin-x64",
76
+ "win32-x64": "win32-x64",
77
+ };
78
+ return PLATFORM_MAP[platformKey];
79
+ }
80
+
81
+ function getBinaryPath(binaryName) {
82
+ const isWindows = os.platform() === "win32";
83
+ const exe = isWindows ? `${binaryName}.exe` : binaryName;
84
+
85
+ const envVar = binaryName === "kkernel" ? "KKERNEL_BINARY" : "KHIVE_MCP_BINARY";
86
+ const override = process.env[envVar];
87
+ if (override && fs.existsSync(override)) return override;
88
+
89
+ const platformSuffix = resolvePlatformSuffix();
90
+
91
+ if (platformSuffix === null) {
92
+ const platformKey = getPlatformKey();
93
+ const libc = detectLibc();
94
+ console.error(`khive-mcp: unsupported platform: ${platformKey} (libc: ${libc})`);
95
+ console.error("linux-arm64 with musl is not in the v1 release matrix.");
96
+ console.error("Supported: " + SUPPORTED_PLATFORMS.join(", "));
97
+ console.error(
98
+ "File an issue at https://github.com/ohdearquant/khive/issues if you need this target.",
99
+ );
100
+ process.exit(1);
101
+ }
102
+
103
+ if (platformSuffix === undefined) {
104
+ const platformKey = getPlatformKey();
105
+ console.error(`khive-mcp: unsupported platform: ${platformKey}`);
106
+ console.error("Supported: " + SUPPORTED_PLATFORMS.join(", "));
107
+ console.error(
108
+ "File an issue at https://github.com/ohdearquant/khive/issues if you need this target.",
109
+ );
110
+ process.exit(1);
111
+ }
112
+
113
+ const pkgName = `@khive-ai/kernel-${platformSuffix}`;
114
+
115
+ // Package-manager-agnostic resolution (npm, yarn, pnpm isolated-store).
116
+ try {
117
+ const pkgJsonPath = require.resolve(`${pkgName}/package.json`);
118
+ const pkgDir = path.dirname(pkgJsonPath);
119
+ const candidate = path.join(pkgDir, "bin", exe);
120
+ if (fs.existsSync(candidate)) return candidate;
121
+ } catch (_) {}
122
+
123
+ // Dev fallback: cargo build directory inside the monorepo.
124
+ const devCandidates = [];
125
+ let search = path.join(__dirname, "..");
126
+ for (let i = 0; i < 8; i++) {
127
+ const cratesDir = path.join(search, "crates");
128
+ if (fs.existsSync(cratesDir)) {
129
+ devCandidates.push(path.join(cratesDir, "target", "release", exe));
130
+ devCandidates.push(path.join(cratesDir, "target", "debug", exe));
131
+ break;
132
+ }
133
+ const parent = path.dirname(search);
134
+ if (parent === search) break;
135
+ search = parent;
136
+ }
137
+ for (const c of devCandidates) {
138
+ if (fs.existsSync(c)) return c;
139
+ }
140
+
141
+ console.error(`khive-mcp: ${pkgName} not installed or ${binaryName} binary not found.`);
142
+ console.error(`Expected: ${pkgName}/bin/${exe}`);
143
+ console.error(
144
+ "Run 'npm install -g khive' to install platform binaries, or set " +
145
+ `${envVar} to point to a local build.`,
146
+ );
147
+ process.exit(1);
148
+ }
149
+
150
+ try {
151
+ const binary = getBinaryPath("khive-mcp");
152
+ execFileSync(binary, process.argv.slice(2), {
153
+ stdio: "inherit",
154
+ env: process.env,
155
+ });
156
+ } catch (err) {
157
+ if (err.status !== undefined) {
158
+ process.exit(err.status);
159
+ }
160
+ throw err;
161
+ }
package/package.json CHANGED
@@ -1,16 +1,46 @@
1
1
  {
2
2
  "name": "khive",
3
- "version": "0.0.1",
4
- "description": "khive — AI agent infrastructure. Memory, knowledge, tasks, and MCP tools for your AI workflows.",
5
- "keywords": ["ai", "agents", "mcp", "memory", "knowledge-graph", "cli"],
6
- "author": "Ocean HaiyangLi <ocean@khive.ai>",
7
- "license": "UNLICENSED",
3
+ "version": "0.2.5",
4
+ "description": "Research knowledge graph CLI git-native KG versioning",
5
+ "license": "Apache-2.0",
8
6
  "repository": {
9
7
  "type": "git",
10
8
  "url": "https://github.com/ohdearquant/khive"
11
9
  },
12
- "homepage": "https://khive.ai",
10
+ "homepage": "https://github.com/ohdearquant",
11
+ "keywords": [
12
+ "knowledge-graph",
13
+ "research",
14
+ "git",
15
+ "ndjson",
16
+ "cli"
17
+ ],
13
18
  "bin": {
14
- "khive": "./bin/khive"
19
+ "khive": "bin/khive",
20
+ "khive-mcp": "bin/khive-mcp"
21
+ },
22
+ "files": [
23
+ "bin/",
24
+ "README.md"
25
+ ],
26
+ "os": [
27
+ "darwin",
28
+ "linux",
29
+ "win32"
30
+ ],
31
+ "cpu": [
32
+ "arm64",
33
+ "x64"
34
+ ],
35
+ "engines": {
36
+ "node": ">=18"
37
+ },
38
+ "optionalDependencies": {
39
+ "@khive-ai/kernel-darwin-arm64": "0.2.5",
40
+ "@khive-ai/kernel-darwin-x64": "0.2.5",
41
+ "@khive-ai/kernel-linux-x64-gnu": "0.2.5",
42
+ "@khive-ai/kernel-linux-x64-musl": "0.2.5",
43
+ "@khive-ai/kernel-linux-arm64": "0.2.5",
44
+ "@khive-ai/kernel-win32-x64": "0.2.5"
15
45
  }
16
46
  }