kiro-memory 1.1.4 → 1.2.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/README.md CHANGED
@@ -308,6 +308,105 @@ npm run test:context
308
308
  npm run test:server
309
309
  ```
310
310
 
311
+ ## Troubleshooting
312
+
313
+ ### `invalid ELF header` (WSL)
314
+
315
+ ```
316
+ Error: .../better_sqlite3.node: invalid ELF header
317
+ ```
318
+
319
+ This happens when the native module was compiled for Windows but you're running inside WSL (Linux). Common cause: npm installed to the Windows filesystem (`/mnt/c/...`) instead of the Linux one.
320
+
321
+ **Fix:**
322
+
323
+ ```bash
324
+ # Check which node you're using
325
+ which node
326
+ # If it shows /mnt/c/... you're using Windows Node inside WSL
327
+
328
+ # Install Node.js natively in WSL
329
+ curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
330
+ sudo apt-get install -y nodejs
331
+
332
+ # Or use nvm (recommended)
333
+ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
334
+ nvm install 22
335
+
336
+ # Verify
337
+ which node # Should be /home/... or /root/.nvm/...
338
+
339
+ # Reinstall
340
+ npm install -g kiro-memory
341
+ ```
342
+
343
+ ### `npm prefix` pointing to Windows (WSL)
344
+
345
+ If `npm prefix -g` returns a `/mnt/c/...` path, npm installs global packages on the Windows filesystem, causing native module issues.
346
+
347
+ **Fix:**
348
+
349
+ ```bash
350
+ mkdir -p ~/.npm-global
351
+ npm config set prefix ~/.npm-global
352
+ echo 'export PATH="$HOME/.npm-global/bin:$PATH"' >> ~/.bashrc
353
+ source ~/.bashrc
354
+
355
+ # Reinstall
356
+ npm install -g kiro-memory
357
+ ```
358
+
359
+ ### Missing build tools (Linux/WSL)
360
+
361
+ ```
362
+ gyp ERR! find Python
363
+ gyp ERR! stack Error: Could not find any Python installation to use
364
+ ```
365
+
366
+ Native modules like `better-sqlite3` need compilation tools.
367
+
368
+ **Fix:**
369
+
370
+ ```bash
371
+ sudo apt-get update && sudo apt-get install -y build-essential python3
372
+ npm install -g kiro-memory --build-from-source
373
+ ```
374
+
375
+ ### `no agent with name kiro-memory found`
376
+
377
+ The agent configuration was not installed. Run the install command:
378
+
379
+ ```bash
380
+ kiro-memory install
381
+ ```
382
+
383
+ This creates the agent config at `~/.kiro/agents/contextkit.json`. Note: the agent name is `contextkit-memory`, so start Kiro with:
384
+
385
+ ```bash
386
+ kiro-cli --agent contextkit-memory
387
+ ```
388
+
389
+ ### Port 3001 already in use
390
+
391
+ ```bash
392
+ # Find what's using the port
393
+ lsof -i :3001
394
+
395
+ # Kill the process
396
+ kill -9 <PID>
397
+
398
+ # Or use a different port
399
+ export KIRO_MEMORY_WORKER_PORT=3002
400
+ ```
401
+
402
+ ### Quick diagnostics
403
+
404
+ Run the built-in doctor command to check your environment:
405
+
406
+ ```bash
407
+ kiro-memory doctor
408
+ ```
409
+
311
410
  ## Contributing
312
411
 
313
412
  Contributions are welcome. Please open an issue to discuss proposed changes before submitting a pull request. See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kiro-memory",
3
- "version": "1.1.4",
3
+ "version": "1.2.1",
4
4
  "description": "Persistent cross-session memory for Kiro CLI. Automatically tracks context, observations, and summaries across coding sessions.",
5
5
  "keywords": [
6
6
  "kiro",
@@ -900,8 +900,8 @@ var ContextKitSDK = class {
900
900
  }
901
901
  detectProject() {
902
902
  try {
903
- const { execSync } = __require("child_process");
904
- const gitRoot = execSync("git rev-parse --show-toplevel", {
903
+ const { execSync: execSync2 } = __require("child_process");
904
+ const gitRoot = execSync2("git rev-parse --show-toplevel", {
905
905
  cwd: process.cwd(),
906
906
  encoding: "utf8",
907
907
  stdio: ["pipe", "pipe", "ignore"]
@@ -1081,9 +1081,303 @@ function createContextKit(config) {
1081
1081
  }
1082
1082
 
1083
1083
  // src/cli/contextkit.ts
1084
+ import { execSync } from "child_process";
1085
+ import { existsSync as existsSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync2, writeFileSync } from "fs";
1086
+ import { join as join3, dirname as dirname2 } from "path";
1087
+ import { homedir as homedir3, platform, release } from "os";
1088
+ import { fileURLToPath as fileURLToPath2 } from "url";
1084
1089
  var args = process.argv.slice(2);
1085
1090
  var command = args[0];
1091
+ var __filename = fileURLToPath2(import.meta.url);
1092
+ var __dirname2 = dirname2(__filename);
1093
+ var DIST_DIR = dirname2(__dirname2);
1094
+ var AGENT_TEMPLATE = JSON.stringify({
1095
+ name: "contextkit-memory",
1096
+ description: "Agent with persistent cross-session memory. Uses ContextKit to remember context from previous sessions and automatically save what it learns.",
1097
+ model: "claude-sonnet-4",
1098
+ tools: ["read", "write", "shell", "glob", "grep", "web_search", "web_fetch", "@contextkit"],
1099
+ mcpServers: {
1100
+ contextkit: {
1101
+ command: "node",
1102
+ args: ["__DIST_DIR__/servers/mcp-server.js"]
1103
+ }
1104
+ },
1105
+ hooks: {
1106
+ agentSpawn: [{ command: "node __DIST_DIR__/hooks/agentSpawn.js", timeout_ms: 1e4 }],
1107
+ userPromptSubmit: [{ command: "node __DIST_DIR__/hooks/userPromptSubmit.js", timeout_ms: 5e3 }],
1108
+ postToolUse: [{ command: "node __DIST_DIR__/hooks/postToolUse.js", matcher: "*", timeout_ms: 5e3 }],
1109
+ stop: [{ command: "node __DIST_DIR__/hooks/stop.js", timeout_ms: 1e4 }]
1110
+ },
1111
+ resources: ["file://.kiro/steering/contextkit.md"]
1112
+ }, null, 2);
1113
+ var STEERING_CONTENT = `# ContextKit - Persistent Memory
1114
+
1115
+ You have access to ContextKit, a persistent cross-session memory system.
1116
+
1117
+ ## Available MCP Tools
1118
+
1119
+ ### @contextkit/search
1120
+ Search previous session memory. Use when:
1121
+ - The user mentions past work
1122
+ - You need context on previous decisions
1123
+ - You want to check if a problem was already addressed
1124
+
1125
+ ### @contextkit/get_context
1126
+ Retrieve recent context for the current project. Use at the start of complex tasks to understand what was done before.
1127
+
1128
+ ### @contextkit/timeline
1129
+ Show chronological context around an observation. Use to understand the sequence of events.
1130
+
1131
+ ### @contextkit/get_observations
1132
+ Retrieve full details of specific observations. Use after \`search\` to drill down.
1133
+
1134
+ ## Behavior
1135
+
1136
+ - Previous session context is automatically injected at startup
1137
+ - Your actions (files written, commands run) are tracked automatically
1138
+ - A summary is generated at the end of each session
1139
+ - No manual saving needed: the system is fully automatic
1140
+ `;
1141
+ function isWSL() {
1142
+ try {
1143
+ const rel = release().toLowerCase();
1144
+ if (rel.includes("microsoft") || rel.includes("wsl")) return true;
1145
+ if (existsSync3("/proc/version")) {
1146
+ const proc = readFileSync2("/proc/version", "utf8").toLowerCase();
1147
+ return proc.includes("microsoft") || proc.includes("wsl");
1148
+ }
1149
+ return false;
1150
+ } catch {
1151
+ return false;
1152
+ }
1153
+ }
1154
+ function commandExists(cmd) {
1155
+ try {
1156
+ execSync(`which ${cmd}`, { stdio: "ignore" });
1157
+ return true;
1158
+ } catch {
1159
+ return false;
1160
+ }
1161
+ }
1162
+ function isWindowsPath(p) {
1163
+ return p.startsWith("/mnt/c") || p.startsWith("/mnt/d") || /^[A-Za-z]:[\\\/]/.test(p);
1164
+ }
1165
+ function runEnvironmentChecks() {
1166
+ const checks = [];
1167
+ const wsl = isWSL();
1168
+ const os = platform();
1169
+ checks.push({
1170
+ name: "Operating system",
1171
+ ok: os === "linux" || os === "darwin",
1172
+ message: os === "linux" ? wsl ? "Linux (WSL)" : "Linux" : os === "darwin" ? "macOS" : `${os} (not officially supported)`
1173
+ });
1174
+ if (wsl) {
1175
+ const nodePath = process.execPath;
1176
+ const nodeOnWindows = isWindowsPath(nodePath);
1177
+ checks.push({
1178
+ name: "WSL: Native Node.js",
1179
+ ok: !nodeOnWindows,
1180
+ message: nodeOnWindows ? `Node.js points to Windows: ${nodePath}` : `Native Linux Node.js: ${nodePath}`,
1181
+ fix: nodeOnWindows ? "Install Node.js inside WSL:\n curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -\n sudo apt-get install -y nodejs\n Or use nvm: https://github.com/nvm-sh/nvm" : void 0
1182
+ });
1183
+ try {
1184
+ const npmPrefix = execSync("npm prefix -g", { encoding: "utf8" }).trim();
1185
+ const prefixOnWindows = isWindowsPath(npmPrefix);
1186
+ checks.push({
1187
+ name: "WSL: npm global prefix",
1188
+ ok: !prefixOnWindows,
1189
+ message: prefixOnWindows ? `npm global prefix points to Windows: ${npmPrefix}` : `npm global prefix: ${npmPrefix}`,
1190
+ fix: prefixOnWindows ? `Fix npm prefix:
1191
+ mkdir -p ~/.npm-global
1192
+ npm config set prefix ~/.npm-global
1193
+ echo 'export PATH="$HOME/.npm-global/bin:$PATH"' >> ~/.bashrc
1194
+ source ~/.bashrc
1195
+ Then reinstall: npm install -g kiro-memory` : void 0
1196
+ });
1197
+ } catch {
1198
+ checks.push({
1199
+ name: "WSL: npm global prefix",
1200
+ ok: false,
1201
+ message: "Unable to determine npm prefix"
1202
+ });
1203
+ }
1204
+ }
1205
+ const nodeVersion = parseInt(process.versions.node.split(".")[0]);
1206
+ checks.push({
1207
+ name: "Node.js >= 18",
1208
+ ok: nodeVersion >= 18,
1209
+ message: `Node.js v${process.versions.node}`,
1210
+ fix: nodeVersion < 18 ? "Upgrade Node.js:\n nvm install 22 && nvm use 22\n Or visit: https://nodejs.org/" : void 0
1211
+ });
1212
+ let sqliteOk = false;
1213
+ let sqliteMsg = "";
1214
+ try {
1215
+ __require("better-sqlite3");
1216
+ sqliteOk = true;
1217
+ sqliteMsg = "Native module loaded successfully";
1218
+ } catch (err) {
1219
+ sqliteMsg = err.code === "ERR_DLOPEN_FAILED" ? "Incompatible native binary (invalid ELF header \u2014 likely platform mismatch)" : `Error: ${err.message}`;
1220
+ }
1221
+ checks.push({
1222
+ name: "better-sqlite3",
1223
+ ok: sqliteOk,
1224
+ message: sqliteMsg,
1225
+ fix: !sqliteOk ? wsl ? "In WSL, rebuild the native module:\n npm rebuild better-sqlite3\n If that fails, reinstall:\n npm install -g kiro-memory --build-from-source" : "Rebuild the native module:\n npm rebuild better-sqlite3" : void 0
1226
+ });
1227
+ if (os === "linux") {
1228
+ const hasMake = commandExists("make");
1229
+ const hasGcc = commandExists("g++") || commandExists("gcc");
1230
+ const hasPython = commandExists("python3") || commandExists("python");
1231
+ const allPresent = hasMake && hasGcc && hasPython;
1232
+ const missing = [];
1233
+ if (!hasMake || !hasGcc) missing.push("build-essential");
1234
+ if (!hasPython) missing.push("python3");
1235
+ checks.push({
1236
+ name: "Build tools (native modules)",
1237
+ ok: allPresent,
1238
+ message: allPresent ? "make, g++, python3 available" : `Missing: ${missing.join(", ")}`,
1239
+ fix: !allPresent ? `Install required packages:
1240
+ sudo apt-get update && sudo apt-get install -y ${missing.join(" ")}
1241
+ Then reinstall: npm install -g kiro-memory --build-from-source` : void 0
1242
+ });
1243
+ }
1244
+ return checks;
1245
+ }
1246
+ function printChecks(checks) {
1247
+ let hasErrors = false;
1248
+ console.log("");
1249
+ for (const check of checks) {
1250
+ const icon = check.ok ? "\x1B[32m\u2713\x1B[0m" : "\x1B[31m\u2717\x1B[0m";
1251
+ console.log(` ${icon} ${check.name}: ${check.message}`);
1252
+ if (!check.ok && check.fix) {
1253
+ console.log(` \x1B[33m\u2192 Fix:\x1B[0m`);
1254
+ for (const line of check.fix.split("\n")) {
1255
+ console.log(` ${line}`);
1256
+ }
1257
+ }
1258
+ if (!check.ok) hasErrors = true;
1259
+ }
1260
+ console.log("");
1261
+ return { hasErrors };
1262
+ }
1263
+ async function installKiro() {
1264
+ console.log("\n=== Kiro Memory - Installation ===\n");
1265
+ console.log("[1/3] Running environment checks...");
1266
+ const checks = runEnvironmentChecks();
1267
+ const { hasErrors } = printChecks(checks);
1268
+ if (hasErrors) {
1269
+ console.log("\x1B[31mInstallation aborted.\x1B[0m Fix the issues above and retry.");
1270
+ console.log("After fixing, run: kiro-memory install\n");
1271
+ process.exit(1);
1272
+ }
1273
+ const distDir = DIST_DIR;
1274
+ const kiroDir = process.env.KIRO_CONFIG_DIR || join3(homedir3(), ".kiro");
1275
+ const agentsDir = join3(kiroDir, "agents");
1276
+ const settingsDir = join3(kiroDir, "settings");
1277
+ const steeringDir = join3(kiroDir, "steering");
1278
+ const dataDir = process.env.CONTEXTKIT_DATA_DIR || join3(homedir3(), ".contextkit");
1279
+ console.log("[2/3] Installing Kiro configuration...\n");
1280
+ for (const dir of [agentsDir, settingsDir, steeringDir, dataDir]) {
1281
+ mkdirSync3(dir, { recursive: true });
1282
+ }
1283
+ const agentConfig = AGENT_TEMPLATE.replace(/__DIST_DIR__/g, distDir);
1284
+ const agentDestPath = join3(agentsDir, "contextkit.json");
1285
+ writeFileSync(agentDestPath, agentConfig, "utf8");
1286
+ console.log(` \u2192 Agent config: ${agentDestPath}`);
1287
+ const mcpFilePath = join3(settingsDir, "mcp.json");
1288
+ let mcpConfig = { mcpServers: {} };
1289
+ if (existsSync3(mcpFilePath)) {
1290
+ try {
1291
+ mcpConfig = JSON.parse(readFileSync2(mcpFilePath, "utf8"));
1292
+ if (!mcpConfig.mcpServers) mcpConfig.mcpServers = {};
1293
+ } catch {
1294
+ }
1295
+ }
1296
+ mcpConfig.mcpServers.contextkit = {
1297
+ command: "node",
1298
+ args: [join3(distDir, "servers", "mcp-server.js")]
1299
+ };
1300
+ writeFileSync(mcpFilePath, JSON.stringify(mcpConfig, null, 2), "utf8");
1301
+ console.log(` \u2192 MCP config: ${mcpFilePath}`);
1302
+ const steeringDestPath = join3(steeringDir, "contextkit.md");
1303
+ writeFileSync(steeringDestPath, STEERING_CONTENT, "utf8");
1304
+ console.log(` \u2192 Steering: ${steeringDestPath}`);
1305
+ console.log(` \u2192 Data dir: ${dataDir}`);
1306
+ console.log("\n[3/3] Installation complete!\n");
1307
+ console.log("To use Kiro with persistent memory:");
1308
+ console.log(" kiro-cli --agent contextkit-memory\n");
1309
+ console.log("To create a permanent alias:");
1310
+ console.log(` echo 'alias kiro="kiro-cli --agent contextkit-memory"' >> ~/.bashrc`);
1311
+ console.log(" source ~/.bashrc\n");
1312
+ console.log("The worker starts automatically when a Kiro session begins.");
1313
+ console.log(`Web dashboard: http://localhost:3001
1314
+ `);
1315
+ }
1316
+ async function runDoctor() {
1317
+ console.log("\n=== Kiro Memory - Diagnostics ===");
1318
+ const checks = runEnvironmentChecks();
1319
+ const kiroDir = process.env.KIRO_CONFIG_DIR || join3(homedir3(), ".kiro");
1320
+ const agentPath = join3(kiroDir, "agents", "contextkit.json");
1321
+ const mcpPath = join3(kiroDir, "settings", "mcp.json");
1322
+ const dataDir = process.env.CONTEXTKIT_DATA_DIR || join3(homedir3(), ".contextkit");
1323
+ checks.push({
1324
+ name: "Kiro agent config",
1325
+ ok: existsSync3(agentPath),
1326
+ message: existsSync3(agentPath) ? agentPath : "Not found",
1327
+ fix: !existsSync3(agentPath) ? "Run: kiro-memory install" : void 0
1328
+ });
1329
+ let mcpOk = false;
1330
+ if (existsSync3(mcpPath)) {
1331
+ try {
1332
+ const mcp = JSON.parse(readFileSync2(mcpPath, "utf8"));
1333
+ mcpOk = !!mcp.mcpServers?.contextkit;
1334
+ } catch {
1335
+ }
1336
+ }
1337
+ checks.push({
1338
+ name: "MCP server configured",
1339
+ ok: mcpOk,
1340
+ message: mcpOk ? "contextkit registered in mcp.json" : "Not configured",
1341
+ fix: !mcpOk ? "Run: kiro-memory install" : void 0
1342
+ });
1343
+ checks.push({
1344
+ name: "Data directory",
1345
+ ok: existsSync3(dataDir),
1346
+ message: existsSync3(dataDir) ? dataDir : "Not created (will be created on first use)"
1347
+ });
1348
+ let workerOk = false;
1349
+ try {
1350
+ const port = process.env.KIRO_MEMORY_WORKER_PORT || "3001";
1351
+ execSync(`curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:${port}/api/health`, {
1352
+ timeout: 2e3,
1353
+ encoding: "utf8"
1354
+ });
1355
+ workerOk = true;
1356
+ } catch {
1357
+ }
1358
+ checks.push({
1359
+ name: "Worker service",
1360
+ ok: true,
1361
+ // Non-blocking: starts automatically with Kiro
1362
+ message: workerOk ? "Running on port 3001" : "Not running (starts automatically with Kiro)"
1363
+ });
1364
+ const { hasErrors } = printChecks(checks);
1365
+ if (hasErrors) {
1366
+ console.log("Some checks failed. Fix the issues listed above.\n");
1367
+ process.exit(1);
1368
+ } else {
1369
+ console.log("All good! Kiro Memory is ready.\n");
1370
+ }
1371
+ }
1086
1372
  async function main() {
1373
+ if (command === "install") {
1374
+ await installKiro();
1375
+ return;
1376
+ }
1377
+ if (command === "doctor") {
1378
+ await runDoctor();
1379
+ return;
1380
+ }
1087
1381
  const contextkit = createContextKit();
1088
1382
  try {
1089
1383
  switch (command) {
@@ -1238,7 +1532,11 @@ async function addSummary(contextkit, content) {
1238
1532
  `);
1239
1533
  }
1240
1534
  function showHelp() {
1241
- console.log(`Usage: contextkit <command> [options]
1535
+ console.log(`Usage: kiro-memory <command> [options]
1536
+
1537
+ Setup:
1538
+ install Install hooks, MCP server, and agent config into Kiro CLI
1539
+ doctor Run environment diagnostics (checks Node, build tools, WSL, etc.)
1242
1540
 
1243
1541
  Commands:
1244
1542
  context, ctx Show current project context
@@ -1250,10 +1548,11 @@ Commands:
1250
1548
  help Show this help message
1251
1549
 
1252
1550
  Examples:
1253
- contextkit context
1254
- contextkit search "authentication"
1255
- contextkit observations 20
1256
- contextkit add-observation "Bug Fix" "Fixed the login issue"
1551
+ kiro-memory install
1552
+ kiro-memory doctor
1553
+ kiro-memory context
1554
+ kiro-memory search "authentication"
1555
+ kiro-memory observations 20
1257
1556
  `);
1258
1557
  }
1259
1558
  main().catch(console.error);