@cohaku/cli 0.2.6

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.
@@ -0,0 +1,37 @@
1
+ import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
+ import {
3
+ StdioServerTransport,
4
+ createServer
5
+ } from "./chunk-2MC3FCZP.js";
6
+ import {
7
+ checkForUpdate,
8
+ printBanner
9
+ } from "./chunk-7WYEO45L.js";
10
+ import {
11
+ createEngine
12
+ } from "./chunk-HMH4HWDA.js";
13
+ import "./chunk-2CDNPZUE.js";
14
+
15
+ // src/commands/mcp.ts
16
+ async function mcpCommand() {
17
+ const { engine, dbPath, projectId } = await createEngine();
18
+ const server = createServer(engine);
19
+ const transport = new StdioServerTransport();
20
+ const latestVersion = await checkForUpdate();
21
+ printBanner({
22
+ projectId,
23
+ dbPath,
24
+ transport: "stdio",
25
+ latestVersion
26
+ });
27
+ await server.connect(transport);
28
+ const shutdown = () => {
29
+ engine.close();
30
+ process.exit(0);
31
+ };
32
+ process.on("SIGINT", shutdown);
33
+ process.on("SIGTERM", shutdown);
34
+ }
35
+ export {
36
+ mcpCommand
37
+ };
@@ -0,0 +1,70 @@
1
+ import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
+ import {
3
+ createApi,
4
+ serve
5
+ } from "./chunk-437HAVIY.js";
6
+ import {
7
+ checkForUpdate,
8
+ printBanner
9
+ } from "./chunk-7WYEO45L.js";
10
+ import {
11
+ createEngine
12
+ } from "./chunk-HMH4HWDA.js";
13
+ import "./chunk-2CDNPZUE.js";
14
+
15
+ // src/commands/serve.ts
16
+ import { join, dirname } from "path";
17
+ import { existsSync, readFileSync } from "fs";
18
+ import { fileURLToPath } from "url";
19
+ var DEFAULT_PORT = 24200;
20
+ async function serveCommand(opts) {
21
+ const port = opts.port ?? Number(process.env["COHAKU_DASHBOARD_PORT"] ?? DEFAULT_PORT);
22
+ const { engine, dbPath, projectId } = await createEngine();
23
+ const app = createApi(engine);
24
+ const __dirname = dirname(fileURLToPath(import.meta.url));
25
+ const dashboardDir = join(__dirname, "dashboard");
26
+ if (existsSync(dashboardDir)) {
27
+ const mimeTypes = {
28
+ ".html": "text/html",
29
+ ".js": "application/javascript",
30
+ ".css": "text/css",
31
+ ".json": "application/json",
32
+ ".svg": "image/svg+xml",
33
+ ".png": "image/png",
34
+ ".ico": "image/x-icon"
35
+ };
36
+ app.get("/*", (c) => {
37
+ const urlPath = c.req.path === "/" ? "/index.html" : c.req.path;
38
+ const filePath = join(dashboardDir, urlPath);
39
+ if (!existsSync(filePath)) {
40
+ const indexPath = join(dashboardDir, "index.html");
41
+ if (existsSync(indexPath)) {
42
+ return c.body(readFileSync(indexPath), 200, { "Content-Type": "text/html" });
43
+ }
44
+ return c.notFound();
45
+ }
46
+ const ext = urlPath.slice(urlPath.lastIndexOf("."));
47
+ const contentType = mimeTypes[ext] ?? "application/octet-stream";
48
+ return c.body(readFileSync(filePath), 200, { "Content-Type": contentType });
49
+ });
50
+ }
51
+ const dashboardUrl = `http://localhost:${port}`;
52
+ serve({ fetch: app.fetch, port });
53
+ const latestVersion = await checkForUpdate();
54
+ printBanner({
55
+ projectId,
56
+ dbPath,
57
+ transport: `http (port ${port})`,
58
+ latestVersion,
59
+ dashboardUrl
60
+ });
61
+ const shutdown = () => {
62
+ engine.close();
63
+ process.exit(0);
64
+ };
65
+ process.on("SIGINT", shutdown);
66
+ process.on("SIGTERM", shutdown);
67
+ }
68
+ export {
69
+ serveCommand
70
+ };
@@ -0,0 +1,81 @@
1
+ import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
+ import {
3
+ StdioServerTransport,
4
+ createServer
5
+ } from "./chunk-2MC3FCZP.js";
6
+ import {
7
+ createApi,
8
+ serve
9
+ } from "./chunk-437HAVIY.js";
10
+ import {
11
+ checkForUpdate,
12
+ printBanner
13
+ } from "./chunk-7WYEO45L.js";
14
+ import {
15
+ createEngine
16
+ } from "./chunk-HMH4HWDA.js";
17
+ import "./chunk-2CDNPZUE.js";
18
+
19
+ // src/commands/start.ts
20
+ import { join, dirname } from "path";
21
+ import { existsSync, readFileSync } from "fs";
22
+ import { fileURLToPath } from "url";
23
+ var DEFAULT_PORT = 24200;
24
+ async function startCommand(opts) {
25
+ const port = opts.port ?? Number(process.env["COHAKU_DASHBOARD_PORT"] ?? DEFAULT_PORT);
26
+ const { engine, dbPath, projectId } = await createEngine();
27
+ const mcpServer = createServer(engine);
28
+ const transport = new StdioServerTransport();
29
+ let dashboardUrl;
30
+ const app = createApi(engine);
31
+ const __dirname = dirname(fileURLToPath(import.meta.url));
32
+ const dashboardDir = join(__dirname, "dashboard");
33
+ if (existsSync(dashboardDir)) {
34
+ const mimeTypes = {
35
+ ".html": "text/html",
36
+ ".js": "application/javascript",
37
+ ".css": "text/css",
38
+ ".json": "application/json",
39
+ ".svg": "image/svg+xml",
40
+ ".png": "image/png",
41
+ ".ico": "image/x-icon"
42
+ };
43
+ app.get("/*", (c) => {
44
+ const urlPath = c.req.path === "/" ? "/index.html" : c.req.path;
45
+ const filePath = join(dashboardDir, urlPath);
46
+ if (!existsSync(filePath)) {
47
+ const indexPath = join(dashboardDir, "index.html");
48
+ if (existsSync(indexPath)) {
49
+ return c.body(readFileSync(indexPath), 200, { "Content-Type": "text/html" });
50
+ }
51
+ return c.notFound();
52
+ }
53
+ const ext = urlPath.slice(urlPath.lastIndexOf("."));
54
+ const contentType = mimeTypes[ext] ?? "application/octet-stream";
55
+ return c.body(readFileSync(filePath), 200, { "Content-Type": contentType });
56
+ });
57
+ }
58
+ try {
59
+ serve({ fetch: app.fetch, port });
60
+ dashboardUrl = `http://localhost:${port}`;
61
+ } catch {
62
+ }
63
+ const latestVersion = await checkForUpdate();
64
+ printBanner({
65
+ projectId,
66
+ dbPath,
67
+ transport: "stdio + http",
68
+ latestVersion,
69
+ dashboardUrl
70
+ });
71
+ await mcpServer.connect(transport);
72
+ const shutdown = () => {
73
+ engine.close();
74
+ process.exit(0);
75
+ };
76
+ process.on("SIGINT", shutdown);
77
+ process.on("SIGTERM", shutdown);
78
+ }
79
+ export {
80
+ startCommand
81
+ };
@@ -0,0 +1,76 @@
1
+ import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
+ import {
3
+ createEngine,
4
+ detectProjectId,
5
+ getDbPath
6
+ } from "./chunk-HMH4HWDA.js";
7
+ import {
8
+ VERSION
9
+ } from "./chunk-2CDNPZUE.js";
10
+
11
+ // src/commands/status.ts
12
+ import { existsSync, statSync } from "fs";
13
+ var c = {
14
+ reset: "\x1B[0m",
15
+ bold: "\x1B[1m",
16
+ dim: "\x1B[2m",
17
+ amber: "\x1B[38;5;214m",
18
+ gray: "\x1B[38;5;245m",
19
+ green: "\x1B[38;5;114m",
20
+ red: "\x1B[38;5;203m",
21
+ white: "\x1B[97m"
22
+ };
23
+ function formatBytes(bytes) {
24
+ if (bytes < 1024) return `${bytes} B`;
25
+ if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
26
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
27
+ }
28
+ async function statusCommand() {
29
+ const dbPath = getDbPath();
30
+ const projectId = detectProjectId();
31
+ const dbExists = existsSync(dbPath);
32
+ const lines = [
33
+ "",
34
+ ` ${c.amber}${c.bold}\u25C6 Cohaku AI${c.reset} ${c.dim}v${VERSION}${c.reset}`,
35
+ ""
36
+ ];
37
+ const projectName = projectId ? projectId.split("/").pop() : void 0;
38
+ lines.push(` ${c.gray}Project${c.reset} ${projectName ? `${c.green}${projectName}${c.reset}` : `${c.dim}global${c.reset}`}`);
39
+ const dbDisplay = dbPath.replace(process.env["HOME"] ?? "", "~");
40
+ if (dbExists) {
41
+ const dbSize = formatBytes(statSync(dbPath).size);
42
+ lines.push(` ${c.gray}Database${c.reset} ${c.dim}${dbDisplay}${c.reset} ${c.dim}(${dbSize})${c.reset}`);
43
+ } else {
44
+ lines.push(` ${c.gray}Database${c.reset} ${c.red}not found${c.reset} ${c.dim}${dbDisplay}${c.reset}`);
45
+ lines.push("");
46
+ console.log(lines.join("\n"));
47
+ return;
48
+ }
49
+ try {
50
+ const { engine } = await createEngine();
51
+ const [memories, entities, edges, sessions, episodes] = await Promise.all([
52
+ engine.listMemories({ limit: 1e4 }),
53
+ engine.listEntities({ limit: 1e4 }),
54
+ engine.listEdges({ limit: 1e4 }),
55
+ engine.sessionList(1e4),
56
+ engine.listEpisodes(1e4)
57
+ ]);
58
+ const ruleCount = memories.filter((m) => m.layer === "rule").length;
59
+ const workingCount = memories.filter((m) => m.layer === "working").length;
60
+ const longTermCount = memories.filter((m) => m.layer === "long_term").length;
61
+ lines.push("");
62
+ lines.push(` ${c.white}${c.bold}Memories${c.reset} ${c.green}${memories.length}${c.reset}`);
63
+ lines.push(` ${c.dim} rule: ${ruleCount} working: ${workingCount} long_term: ${longTermCount}${c.reset}`);
64
+ lines.push(` ${c.white}${c.bold}Graph${c.reset} ${c.green}${entities.length}${c.reset} ${c.dim}nodes${c.reset} ${c.green}${edges.length}${c.reset} ${c.dim}edges${c.reset}`);
65
+ lines.push(` ${c.white}${c.bold}Sessions${c.reset} ${c.green}${sessions.length}${c.reset}`);
66
+ lines.push(` ${c.white}${c.bold}Episodes${c.reset} ${c.green}${episodes.length}${c.reset}`);
67
+ engine.close();
68
+ } catch (e) {
69
+ lines.push(` ${c.red}Error reading database${c.reset}`);
70
+ }
71
+ lines.push("");
72
+ console.log(lines.join("\n"));
73
+ }
74
+ export {
75
+ statusCommand
76
+ };
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@cohaku/cli",
3
+ "version": "0.2.6",
4
+ "description": "CLI for Cohaku AI — persistent memory layer for coding agents",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/cohaku-ai/cohaku-ai"
10
+ },
11
+ "keywords": [
12
+ "cohaku",
13
+ "mcp",
14
+ "memory",
15
+ "ai",
16
+ "coding-agent",
17
+ "cli"
18
+ ],
19
+ "main": "./dist/index.js",
20
+ "types": "./dist/index.d.ts",
21
+ "bin": {
22
+ "cohaku": "./dist/index.js"
23
+ },
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "scripts": {
28
+ "build": "tsup && node -e \"const {cpSync,existsSync}=require('fs');const src='../dashboard/dist';if(existsSync(src))cpSync(src,'dist/dashboard',{recursive:true})\"",
29
+ "dev": "tsup --watch",
30
+ "typecheck": "tsc --noEmit",
31
+ "clean": "rm -rf dist"
32
+ },
33
+ "dependencies": {
34
+ "@xenova/transformers": "^2.17.2",
35
+ "better-sqlite3": "^12.6.2",
36
+ "sqlite-vec": "0.1.7-alpha.2"
37
+ },
38
+ "devDependencies": {
39
+ "@cohaku/api": "workspace:*",
40
+ "@cohaku/core": "workspace:*",
41
+ "@cohaku/mcp": "workspace:*",
42
+ "@cohaku/shared": "workspace:*",
43
+ "@hono/node-server": "^1.14.0",
44
+ "@modelcontextprotocol/sdk": "^1.27.1",
45
+ "@types/better-sqlite3": "^7.6.13",
46
+ "@types/node": "^25.3.2",
47
+ "commander": "^14.0.0",
48
+ "hono": "^4.7.0",
49
+ "nanoid": "^5.1.6",
50
+ "tsup": "^8.5.0",
51
+ "typescript": "^5.7.0",
52
+ "zod": "^4.3.6"
53
+ }
54
+ }