kratos-memory 1.5.0 → 1.5.1
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/kratos-cli +3 -0
- package/package.json +3 -2
- package/scripts/ensure-better-sqlite3.mjs +115 -0
package/bin/kratos-cli
CHANGED
|
@@ -3,5 +3,8 @@ import { fileURLToPath } from 'url';
|
|
|
3
3
|
import { dirname, join, resolve } from 'path';
|
|
4
4
|
const __filename = fileURLToPath(import.meta.url);
|
|
5
5
|
const __dirname = dirname(__filename);
|
|
6
|
+
const ensureNativeModulePath = resolve(join(__dirname, '..', 'scripts', 'ensure-better-sqlite3.mjs'));
|
|
7
|
+
const { ensureBetterSqlite3 } = await import(ensureNativeModulePath);
|
|
8
|
+
ensureBetterSqlite3();
|
|
6
9
|
const cliPath = resolve(join(__dirname, '..', 'dist', 'cli', 'index.js'));
|
|
7
10
|
await import(cliPath);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kratos-memory",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "Persistent memory for AI coding agents — CLI-first, local, zero network calls",
|
|
5
5
|
"main": "dist/cli/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"dev": "tsx src/cli/index.ts",
|
|
18
18
|
"start": "node dist/cli/index.js",
|
|
19
19
|
"test": "npm run build && node --test tests/*.test.mjs",
|
|
20
|
-
"postinstall": "
|
|
20
|
+
"postinstall": "node ./scripts/ensure-better-sqlite3.mjs",
|
|
21
21
|
"prepublishOnly": "npm run build"
|
|
22
22
|
},
|
|
23
23
|
"keywords": [
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
"files": [
|
|
54
54
|
"dist/**/*",
|
|
55
55
|
"bin/**/*",
|
|
56
|
+
"scripts/**/*",
|
|
56
57
|
"README.md",
|
|
57
58
|
"LICENSE",
|
|
58
59
|
"AGENTS.md"
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { existsSync, rmSync } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { createRequire } from 'node:module';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname = path.dirname(__filename);
|
|
9
|
+
const packageRoot = path.resolve(__dirname, '..');
|
|
10
|
+
const requireFromPackage = createRequire(path.join(packageRoot, 'package.json'));
|
|
11
|
+
|
|
12
|
+
function resolveBetterSqlite3Dir() {
|
|
13
|
+
const pkgPath = requireFromPackage.resolve('better-sqlite3/package.json');
|
|
14
|
+
return path.dirname(pkgPath);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function getBinaryPath(moduleDir) {
|
|
18
|
+
return path.join(moduleDir, 'build', 'Release', 'better_sqlite3.node');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function canLoadBetterSqlite3(moduleDir) {
|
|
22
|
+
if (!existsSync(getBinaryPath(moduleDir))) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const script = `
|
|
27
|
+
const { createRequire } = require('node:module');
|
|
28
|
+
const req = createRequire(${JSON.stringify(path.join(packageRoot, 'package.json'))});
|
|
29
|
+
req('better-sqlite3');
|
|
30
|
+
`;
|
|
31
|
+
|
|
32
|
+
const result = spawnSync(process.execPath, ['-e', script], {
|
|
33
|
+
cwd: packageRoot,
|
|
34
|
+
env: process.env,
|
|
35
|
+
encoding: 'utf8',
|
|
36
|
+
stdio: 'pipe',
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return result.status === 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function runCommand(command, args, cwd) {
|
|
43
|
+
return spawnSync(command, args, {
|
|
44
|
+
cwd,
|
|
45
|
+
env: {
|
|
46
|
+
...process.env,
|
|
47
|
+
npm_config_loglevel: process.env.npm_config_loglevel || 'error',
|
|
48
|
+
},
|
|
49
|
+
encoding: 'utf8',
|
|
50
|
+
stdio: 'pipe',
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function findNpmCommand() {
|
|
55
|
+
if (process.env.npm_execpath) {
|
|
56
|
+
return {
|
|
57
|
+
command: process.execPath,
|
|
58
|
+
argsPrefix: [process.env.npm_execpath],
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
command: process.platform === 'win32' ? 'npm.cmd' : 'npm',
|
|
64
|
+
argsPrefix: [],
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function formatOutput(result) {
|
|
69
|
+
const chunks = [result.stdout?.trim(), result.stderr?.trim()].filter(Boolean);
|
|
70
|
+
return chunks.join('\n');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function ensureBetterSqlite3() {
|
|
74
|
+
let moduleDir;
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
moduleDir = resolveBetterSqlite3Dir();
|
|
78
|
+
} catch (error) {
|
|
79
|
+
console.warn('[kratos-memory] better-sqlite3 is not installed yet:', error.message);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (canLoadBetterSqlite3(moduleDir)) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const binaryPath = getBinaryPath(moduleDir);
|
|
88
|
+
console.warn(`[kratos-memory] better-sqlite3 binary missing or unloadable at ${binaryPath}`);
|
|
89
|
+
console.warn('[kratos-memory] rebuilding better-sqlite3 from source...');
|
|
90
|
+
|
|
91
|
+
rmSync(path.join(moduleDir, 'build'), { recursive: true, force: true });
|
|
92
|
+
|
|
93
|
+
const npm = findNpmCommand();
|
|
94
|
+
const rebuild = runCommand(
|
|
95
|
+
npm.command,
|
|
96
|
+
[...npm.argsPrefix, 'run', 'build-release', '--foreground-scripts'],
|
|
97
|
+
moduleDir
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
if (canLoadBetterSqlite3(moduleDir)) {
|
|
101
|
+
console.warn('[kratos-memory] better-sqlite3 rebuild succeeded.');
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const detail = formatOutput(rebuild);
|
|
106
|
+
throw new Error(
|
|
107
|
+
detail
|
|
108
|
+
? `Failed to build better-sqlite3.\n${detail}`
|
|
109
|
+
: 'Failed to build better-sqlite3.'
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (process.argv[1] === __filename) {
|
|
114
|
+
ensureBetterSqlite3();
|
|
115
|
+
}
|