kiro-memory 1.1.3 → 1.2.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.
- package/README.md +102 -3
- package/package.json +1 -1
- package/plugin/dist/cli/contextkit.js +267 -7
- package/plugin/dist/hooks/agentSpawn.js +48 -29
- package/plugin/dist/hooks/postToolUse.js +71 -28
- package/plugin/dist/hooks/stop.js +46 -27
- package/plugin/dist/hooks/userPromptSubmit.js +50 -31
- package/plugin/dist/index.js +20 -1
- package/plugin/dist/viewer.html +4 -0
- package/plugin/dist/viewer.js +1 -0
package/README.md
CHANGED
|
@@ -69,7 +69,7 @@ npm run install:kiro
|
|
|
69
69
|
Kiro Memory works as a **custom agent**. You must start Kiro with the `--agent` flag:
|
|
70
70
|
|
|
71
71
|
```bash
|
|
72
|
-
kiro --agent kiro-memory
|
|
72
|
+
kiro-cli --agent kiro-memory
|
|
73
73
|
```
|
|
74
74
|
|
|
75
75
|
> **Why?** Kiro Memory uses hooks (`agentSpawn`, `postToolUse`, `userPromptSubmit`, `stop`) to capture context automatically. Hooks are defined inside the agent configuration, so they only run when the `kiro-memory` agent is active.
|
|
@@ -78,10 +78,10 @@ To avoid typing the flag every time, add an alias to your shell:
|
|
|
78
78
|
|
|
79
79
|
```bash
|
|
80
80
|
# Bash
|
|
81
|
-
echo 'alias kiro="kiro --agent kiro-memory"' >> ~/.bashrc && source ~/.bashrc
|
|
81
|
+
echo 'alias kiro="kiro-cli --agent kiro-memory"' >> ~/.bashrc && source ~/.bashrc
|
|
82
82
|
|
|
83
83
|
# Zsh
|
|
84
|
-
echo 'alias kiro="kiro --agent kiro-memory"' >> ~/.zshrc && source ~/.zshrc
|
|
84
|
+
echo 'alias kiro="kiro-cli --agent kiro-memory"' >> ~/.zshrc && source ~/.zshrc
|
|
85
85
|
```
|
|
86
86
|
|
|
87
87
|
Once running, the worker auto-starts and the web dashboard is available at `http://localhost:3001`.
|
|
@@ -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
|
@@ -900,8 +900,8 @@ var ContextKitSDK = class {
|
|
|
900
900
|
}
|
|
901
901
|
detectProject() {
|
|
902
902
|
try {
|
|
903
|
-
const { execSync } = __require("child_process");
|
|
904
|
-
const gitRoot =
|
|
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,264 @@ 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, copyFileSync } 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 PROJECT_ROOT = dirname2(dirname2(DIST_DIR));
|
|
1095
|
+
function isWSL() {
|
|
1096
|
+
try {
|
|
1097
|
+
const rel = release().toLowerCase();
|
|
1098
|
+
if (rel.includes("microsoft") || rel.includes("wsl")) return true;
|
|
1099
|
+
if (existsSync3("/proc/version")) {
|
|
1100
|
+
const proc = readFileSync2("/proc/version", "utf8").toLowerCase();
|
|
1101
|
+
return proc.includes("microsoft") || proc.includes("wsl");
|
|
1102
|
+
}
|
|
1103
|
+
return false;
|
|
1104
|
+
} catch {
|
|
1105
|
+
return false;
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
function commandExists(cmd) {
|
|
1109
|
+
try {
|
|
1110
|
+
execSync(`which ${cmd}`, { stdio: "ignore" });
|
|
1111
|
+
return true;
|
|
1112
|
+
} catch {
|
|
1113
|
+
return false;
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
function runEnvironmentChecks() {
|
|
1117
|
+
const checks = [];
|
|
1118
|
+
const wsl = isWSL();
|
|
1119
|
+
const os = platform();
|
|
1120
|
+
checks.push({
|
|
1121
|
+
name: "Sistema operativo",
|
|
1122
|
+
ok: os === "linux" || os === "darwin",
|
|
1123
|
+
message: os === "linux" ? wsl ? "Linux (WSL)" : "Linux" : os === "darwin" ? "macOS" : `${os} (non supportato ufficialmente)`
|
|
1124
|
+
});
|
|
1125
|
+
if (wsl) {
|
|
1126
|
+
const nodePath = process.execPath;
|
|
1127
|
+
const nodeOnWindows = nodePath.startsWith("/mnt/c") || nodePath.startsWith("/mnt/d");
|
|
1128
|
+
checks.push({
|
|
1129
|
+
name: "WSL: Node.js nativo",
|
|
1130
|
+
ok: !nodeOnWindows,
|
|
1131
|
+
message: nodeOnWindows ? `Node.js punta a Windows: ${nodePath}` : `Node.js nativo Linux: ${nodePath}`,
|
|
1132
|
+
fix: nodeOnWindows ? "Installa Node.js dentro WSL:\n curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -\n sudo apt-get install -y nodejs\n Oppure usa nvm: https://github.com/nvm-sh/nvm" : void 0
|
|
1133
|
+
});
|
|
1134
|
+
try {
|
|
1135
|
+
const npmPrefix = execSync("npm prefix -g", { encoding: "utf8" }).trim();
|
|
1136
|
+
const prefixOnWindows = npmPrefix.startsWith("/mnt/c") || npmPrefix.startsWith("/mnt/d");
|
|
1137
|
+
checks.push({
|
|
1138
|
+
name: "WSL: npm global prefix",
|
|
1139
|
+
ok: !prefixOnWindows,
|
|
1140
|
+
message: prefixOnWindows ? `npm global prefix punta a Windows: ${npmPrefix}` : `npm global prefix: ${npmPrefix}`,
|
|
1141
|
+
fix: prefixOnWindows ? `Correggi il prefix npm:
|
|
1142
|
+
mkdir -p ~/.npm-global
|
|
1143
|
+
npm config set prefix ~/.npm-global
|
|
1144
|
+
echo 'export PATH="$HOME/.npm-global/bin:$PATH"' >> ~/.bashrc
|
|
1145
|
+
source ~/.bashrc
|
|
1146
|
+
Poi reinstalla: npm install -g kiro-memory` : void 0
|
|
1147
|
+
});
|
|
1148
|
+
} catch {
|
|
1149
|
+
checks.push({
|
|
1150
|
+
name: "WSL: npm global prefix",
|
|
1151
|
+
ok: false,
|
|
1152
|
+
message: "Impossibile determinare npm prefix"
|
|
1153
|
+
});
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
const nodeVersion = parseInt(process.versions.node.split(".")[0]);
|
|
1157
|
+
checks.push({
|
|
1158
|
+
name: "Node.js >= 18",
|
|
1159
|
+
ok: nodeVersion >= 18,
|
|
1160
|
+
message: `Node.js v${process.versions.node}`,
|
|
1161
|
+
fix: nodeVersion < 18 ? "Aggiorna Node.js:\n nvm install 22 && nvm use 22\n Oppure: https://nodejs.org/" : void 0
|
|
1162
|
+
});
|
|
1163
|
+
let sqliteOk = false;
|
|
1164
|
+
let sqliteMsg = "";
|
|
1165
|
+
try {
|
|
1166
|
+
__require("better-sqlite3");
|
|
1167
|
+
sqliteOk = true;
|
|
1168
|
+
sqliteMsg = "Modulo nativo caricato correttamente";
|
|
1169
|
+
} catch (err) {
|
|
1170
|
+
sqliteMsg = err.code === "ERR_DLOPEN_FAILED" ? "Binario nativo incompatibile (ELF header invalido \u2014 probabile mismatch piattaforma)" : `Errore: ${err.message}`;
|
|
1171
|
+
}
|
|
1172
|
+
checks.push({
|
|
1173
|
+
name: "better-sqlite3",
|
|
1174
|
+
ok: sqliteOk,
|
|
1175
|
+
message: sqliteMsg,
|
|
1176
|
+
fix: !sqliteOk ? wsl ? "In WSL, ricompila il modulo nativo:\n npm rebuild better-sqlite3\n Se non funziona, reinstalla:\n npm install -g kiro-memory --build-from-source" : "Reinstalla il modulo nativo:\n npm rebuild better-sqlite3" : void 0
|
|
1177
|
+
});
|
|
1178
|
+
if (os === "linux") {
|
|
1179
|
+
const hasMake = commandExists("make");
|
|
1180
|
+
const hasGcc = commandExists("g++") || commandExists("gcc");
|
|
1181
|
+
const hasPython = commandExists("python3") || commandExists("python");
|
|
1182
|
+
const allPresent = hasMake && hasGcc && hasPython;
|
|
1183
|
+
const missing = [];
|
|
1184
|
+
if (!hasMake || !hasGcc) missing.push("build-essential");
|
|
1185
|
+
if (!hasPython) missing.push("python3");
|
|
1186
|
+
checks.push({
|
|
1187
|
+
name: "Build tools (moduli nativi)",
|
|
1188
|
+
ok: allPresent,
|
|
1189
|
+
message: allPresent ? "make, g++, python3 disponibili" : `Mancanti: ${missing.join(", ")}`,
|
|
1190
|
+
fix: !allPresent ? `Installa i pacchetti richiesti:
|
|
1191
|
+
sudo apt-get update && sudo apt-get install -y ${missing.join(" ")}
|
|
1192
|
+
Poi reinstalla: npm install -g kiro-memory --build-from-source` : void 0
|
|
1193
|
+
});
|
|
1194
|
+
}
|
|
1195
|
+
return checks;
|
|
1196
|
+
}
|
|
1197
|
+
function printChecks(checks) {
|
|
1198
|
+
let hasErrors = false;
|
|
1199
|
+
console.log("");
|
|
1200
|
+
for (const check of checks) {
|
|
1201
|
+
const icon = check.ok ? "\x1B[32m\u2713\x1B[0m" : "\x1B[31m\u2717\x1B[0m";
|
|
1202
|
+
console.log(` ${icon} ${check.name}: ${check.message}`);
|
|
1203
|
+
if (!check.ok && check.fix) {
|
|
1204
|
+
console.log(` \x1B[33m\u2192 Fix:\x1B[0m`);
|
|
1205
|
+
for (const line of check.fix.split("\n")) {
|
|
1206
|
+
console.log(` ${line}`);
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
if (!check.ok) hasErrors = true;
|
|
1210
|
+
}
|
|
1211
|
+
console.log("");
|
|
1212
|
+
return { hasErrors };
|
|
1213
|
+
}
|
|
1214
|
+
async function installKiro() {
|
|
1215
|
+
console.log("\n=== Kiro Memory - Installazione ===\n");
|
|
1216
|
+
console.log("[1/3] Diagnostica ambiente...");
|
|
1217
|
+
const checks = runEnvironmentChecks();
|
|
1218
|
+
const { hasErrors } = printChecks(checks);
|
|
1219
|
+
if (hasErrors) {
|
|
1220
|
+
console.log("\x1B[31mInstallazione annullata.\x1B[0m Risolvi i problemi sopra e riprova.");
|
|
1221
|
+
console.log("Dopo aver risolto, esegui: kiro-memory install\n");
|
|
1222
|
+
process.exit(1);
|
|
1223
|
+
}
|
|
1224
|
+
const distDir = DIST_DIR;
|
|
1225
|
+
const agentTemplatePath = join3(PROJECT_ROOT, "kiro-agent", "contextkit.json");
|
|
1226
|
+
const steeringSourcePath = join3(PROJECT_ROOT, "kiro-agent", "steering.md");
|
|
1227
|
+
if (!existsSync3(agentTemplatePath)) {
|
|
1228
|
+
console.error(`\x1B[31mErrore:\x1B[0m Template agent non trovato: ${agentTemplatePath}`);
|
|
1229
|
+
console.error("Prova a reinstallare: npm install -g kiro-memory");
|
|
1230
|
+
process.exit(1);
|
|
1231
|
+
}
|
|
1232
|
+
const kiroDir = process.env.KIRO_CONFIG_DIR || join3(homedir3(), ".kiro");
|
|
1233
|
+
const agentsDir = join3(kiroDir, "agents");
|
|
1234
|
+
const settingsDir = join3(kiroDir, "settings");
|
|
1235
|
+
const steeringDir = join3(kiroDir, "steering");
|
|
1236
|
+
const dataDir = process.env.CONTEXTKIT_DATA_DIR || join3(homedir3(), ".contextkit");
|
|
1237
|
+
console.log("[2/3] Installazione configurazione Kiro...\n");
|
|
1238
|
+
for (const dir of [agentsDir, settingsDir, steeringDir, dataDir]) {
|
|
1239
|
+
mkdirSync3(dir, { recursive: true });
|
|
1240
|
+
}
|
|
1241
|
+
const agentTemplate = readFileSync2(agentTemplatePath, "utf8");
|
|
1242
|
+
const agentConfig = agentTemplate.replace(/__CONTEXTKIT_DIST__/g, distDir);
|
|
1243
|
+
const agentDestPath = join3(agentsDir, "contextkit.json");
|
|
1244
|
+
writeFileSync(agentDestPath, agentConfig, "utf8");
|
|
1245
|
+
console.log(` \u2192 Agent config: ${agentDestPath}`);
|
|
1246
|
+
const mcpFilePath = join3(settingsDir, "mcp.json");
|
|
1247
|
+
let mcpConfig = { mcpServers: {} };
|
|
1248
|
+
if (existsSync3(mcpFilePath)) {
|
|
1249
|
+
try {
|
|
1250
|
+
mcpConfig = JSON.parse(readFileSync2(mcpFilePath, "utf8"));
|
|
1251
|
+
if (!mcpConfig.mcpServers) mcpConfig.mcpServers = {};
|
|
1252
|
+
} catch {
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
mcpConfig.mcpServers.contextkit = {
|
|
1256
|
+
command: "node",
|
|
1257
|
+
args: [join3(distDir, "servers", "mcp-server.js")]
|
|
1258
|
+
};
|
|
1259
|
+
writeFileSync(mcpFilePath, JSON.stringify(mcpConfig, null, 2), "utf8");
|
|
1260
|
+
console.log(` \u2192 MCP config: ${mcpFilePath}`);
|
|
1261
|
+
const steeringDestPath = join3(steeringDir, "contextkit.md");
|
|
1262
|
+
if (existsSync3(steeringSourcePath)) {
|
|
1263
|
+
copyFileSync(steeringSourcePath, steeringDestPath);
|
|
1264
|
+
console.log(` \u2192 Steering: ${steeringDestPath}`);
|
|
1265
|
+
}
|
|
1266
|
+
console.log(` \u2192 Data dir: ${dataDir}`);
|
|
1267
|
+
console.log("\n[3/3] Installazione completata!\n");
|
|
1268
|
+
console.log("Per usare Kiro con memoria persistente:");
|
|
1269
|
+
console.log(" kiro-cli --agent contextkit-memory\n");
|
|
1270
|
+
console.log("Per creare un alias permanente:");
|
|
1271
|
+
console.log(` echo 'alias kiro="kiro-cli --agent contextkit-memory"' >> ~/.bashrc`);
|
|
1272
|
+
console.log(" source ~/.bashrc\n");
|
|
1273
|
+
console.log("Il worker si avvia automaticamente alla prima sessione.");
|
|
1274
|
+
console.log(`Dashboard web: http://localhost:3001
|
|
1275
|
+
`);
|
|
1276
|
+
}
|
|
1277
|
+
async function runDoctor() {
|
|
1278
|
+
console.log("\n=== Kiro Memory - Diagnostica ===");
|
|
1279
|
+
const checks = runEnvironmentChecks();
|
|
1280
|
+
const kiroDir = process.env.KIRO_CONFIG_DIR || join3(homedir3(), ".kiro");
|
|
1281
|
+
const agentPath = join3(kiroDir, "agents", "contextkit.json");
|
|
1282
|
+
const mcpPath = join3(kiroDir, "settings", "mcp.json");
|
|
1283
|
+
const dataDir = process.env.CONTEXTKIT_DATA_DIR || join3(homedir3(), ".contextkit");
|
|
1284
|
+
checks.push({
|
|
1285
|
+
name: "Agent config Kiro",
|
|
1286
|
+
ok: existsSync3(agentPath),
|
|
1287
|
+
message: existsSync3(agentPath) ? agentPath : "Non trovato",
|
|
1288
|
+
fix: !existsSync3(agentPath) ? "Esegui: kiro-memory install" : void 0
|
|
1289
|
+
});
|
|
1290
|
+
let mcpOk = false;
|
|
1291
|
+
if (existsSync3(mcpPath)) {
|
|
1292
|
+
try {
|
|
1293
|
+
const mcp = JSON.parse(readFileSync2(mcpPath, "utf8"));
|
|
1294
|
+
mcpOk = !!mcp.mcpServers?.contextkit;
|
|
1295
|
+
} catch {
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
checks.push({
|
|
1299
|
+
name: "MCP server configurato",
|
|
1300
|
+
ok: mcpOk,
|
|
1301
|
+
message: mcpOk ? "contextkit registrato in mcp.json" : "Non configurato",
|
|
1302
|
+
fix: !mcpOk ? "Esegui: kiro-memory install" : void 0
|
|
1303
|
+
});
|
|
1304
|
+
checks.push({
|
|
1305
|
+
name: "Data directory",
|
|
1306
|
+
ok: existsSync3(dataDir),
|
|
1307
|
+
message: existsSync3(dataDir) ? dataDir : "Non creata (verr\xE0 creata al primo uso)"
|
|
1308
|
+
});
|
|
1309
|
+
let workerOk = false;
|
|
1310
|
+
try {
|
|
1311
|
+
const port = process.env.KIRO_MEMORY_WORKER_PORT || "3001";
|
|
1312
|
+
execSync(`curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:${port}/api/health`, {
|
|
1313
|
+
timeout: 2e3,
|
|
1314
|
+
encoding: "utf8"
|
|
1315
|
+
});
|
|
1316
|
+
workerOk = true;
|
|
1317
|
+
} catch {
|
|
1318
|
+
}
|
|
1319
|
+
checks.push({
|
|
1320
|
+
name: "Worker service",
|
|
1321
|
+
ok: true,
|
|
1322
|
+
// Non bloccante: si avvia automaticamente
|
|
1323
|
+
message: workerOk ? "Attivo su porta 3001" : "Non in esecuzione (si avvia automaticamente con Kiro)"
|
|
1324
|
+
});
|
|
1325
|
+
const { hasErrors } = printChecks(checks);
|
|
1326
|
+
if (hasErrors) {
|
|
1327
|
+
console.log("Alcuni check sono falliti. Risolvi i problemi indicati sopra.\n");
|
|
1328
|
+
process.exit(1);
|
|
1329
|
+
} else {
|
|
1330
|
+
console.log("Tutto OK! Kiro Memory \xE8 pronto.\n");
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1086
1333
|
async function main() {
|
|
1334
|
+
if (command === "install") {
|
|
1335
|
+
await installKiro();
|
|
1336
|
+
return;
|
|
1337
|
+
}
|
|
1338
|
+
if (command === "doctor") {
|
|
1339
|
+
await runDoctor();
|
|
1340
|
+
return;
|
|
1341
|
+
}
|
|
1087
1342
|
const contextkit = createContextKit();
|
|
1088
1343
|
try {
|
|
1089
1344
|
switch (command) {
|
|
@@ -1238,7 +1493,11 @@ async function addSummary(contextkit, content) {
|
|
|
1238
1493
|
`);
|
|
1239
1494
|
}
|
|
1240
1495
|
function showHelp() {
|
|
1241
|
-
console.log(`Usage:
|
|
1496
|
+
console.log(`Usage: kiro-memory <command> [options]
|
|
1497
|
+
|
|
1498
|
+
Setup:
|
|
1499
|
+
install Install hooks, MCP server, and agent config into Kiro CLI
|
|
1500
|
+
doctor Run environment diagnostics (checks Node, build tools, WSL, etc.)
|
|
1242
1501
|
|
|
1243
1502
|
Commands:
|
|
1244
1503
|
context, ctx Show current project context
|
|
@@ -1250,10 +1509,11 @@ Commands:
|
|
|
1250
1509
|
help Show this help message
|
|
1251
1510
|
|
|
1252
1511
|
Examples:
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1512
|
+
kiro-memory install
|
|
1513
|
+
kiro-memory doctor
|
|
1514
|
+
kiro-memory context
|
|
1515
|
+
kiro-memory search "authentication"
|
|
1516
|
+
kiro-memory observations 20
|
|
1257
1517
|
`);
|
|
1258
1518
|
}
|
|
1259
1519
|
main().catch(console.error);
|
|
@@ -384,6 +384,22 @@ var init_Search = __esm({
|
|
|
384
384
|
});
|
|
385
385
|
|
|
386
386
|
// src/hooks/utils.ts
|
|
387
|
+
import { writeFileSync, mkdirSync, existsSync } from "fs";
|
|
388
|
+
import { join } from "path";
|
|
389
|
+
function debugLog(hookName, label, data) {
|
|
390
|
+
if ((process.env.KIRO_MEMORY_LOG_LEVEL || "").toUpperCase() !== "DEBUG") return;
|
|
391
|
+
try {
|
|
392
|
+
const dataDir = process.env.KIRO_MEMORY_DATA_DIR || join(process.env.HOME || "/tmp", ".kiro-memory");
|
|
393
|
+
const logDir = join(dataDir, "logs");
|
|
394
|
+
if (!existsSync(logDir)) mkdirSync(logDir, { recursive: true });
|
|
395
|
+
const ts = (/* @__PURE__ */ new Date()).toISOString();
|
|
396
|
+
const line = `[${ts}] [${hookName}] ${label}: ${JSON.stringify(data)}
|
|
397
|
+
`;
|
|
398
|
+
const logFile = join(logDir, `hooks-${(/* @__PURE__ */ new Date()).toISOString().split("T")[0]}.log`);
|
|
399
|
+
writeFileSync(logFile, line, { flag: "a" });
|
|
400
|
+
} catch {
|
|
401
|
+
}
|
|
402
|
+
}
|
|
387
403
|
async function readStdin() {
|
|
388
404
|
return new Promise((resolve, reject) => {
|
|
389
405
|
let data = "";
|
|
@@ -457,10 +473,13 @@ function formatContext(data) {
|
|
|
457
473
|
async function runHook(name, handler) {
|
|
458
474
|
try {
|
|
459
475
|
const input = await readStdin();
|
|
476
|
+
debugLog(name, "stdin", input);
|
|
460
477
|
await handler(input);
|
|
478
|
+
debugLog(name, "completato", { success: true });
|
|
461
479
|
process.exit(0);
|
|
462
480
|
} catch (error) {
|
|
463
|
-
|
|
481
|
+
debugLog(name, "errore", { error: String(error) });
|
|
482
|
+
process.stderr.write(`[kiro-memory:${name}] Errore: ${error}
|
|
464
483
|
`);
|
|
465
484
|
process.exit(0);
|
|
466
485
|
}
|
|
@@ -534,14 +553,14 @@ var BunQueryCompat = class {
|
|
|
534
553
|
};
|
|
535
554
|
|
|
536
555
|
// src/shared/paths.ts
|
|
537
|
-
import { join as
|
|
556
|
+
import { join as join3, dirname, basename } from "path";
|
|
538
557
|
import { homedir as homedir2 } from "os";
|
|
539
|
-
import { mkdirSync as
|
|
558
|
+
import { mkdirSync as mkdirSync3 } from "fs";
|
|
540
559
|
import { fileURLToPath } from "url";
|
|
541
560
|
|
|
542
561
|
// src/utils/logger.ts
|
|
543
|
-
import { appendFileSync, existsSync, mkdirSync, readFileSync } from "fs";
|
|
544
|
-
import { join } from "path";
|
|
562
|
+
import { appendFileSync, existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync } from "fs";
|
|
563
|
+
import { join as join2 } from "path";
|
|
545
564
|
import { homedir } from "os";
|
|
546
565
|
var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
547
566
|
LogLevel2[LogLevel2["DEBUG"] = 0] = "DEBUG";
|
|
@@ -551,7 +570,7 @@ var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
|
551
570
|
LogLevel2[LogLevel2["SILENT"] = 4] = "SILENT";
|
|
552
571
|
return LogLevel2;
|
|
553
572
|
})(LogLevel || {});
|
|
554
|
-
var DEFAULT_DATA_DIR =
|
|
573
|
+
var DEFAULT_DATA_DIR = join2(homedir(), ".contextkit");
|
|
555
574
|
var Logger = class {
|
|
556
575
|
level = null;
|
|
557
576
|
useColor;
|
|
@@ -567,12 +586,12 @@ var Logger = class {
|
|
|
567
586
|
if (this.logFileInitialized) return;
|
|
568
587
|
this.logFileInitialized = true;
|
|
569
588
|
try {
|
|
570
|
-
const logsDir =
|
|
571
|
-
if (!
|
|
572
|
-
|
|
589
|
+
const logsDir = join2(DEFAULT_DATA_DIR, "logs");
|
|
590
|
+
if (!existsSync2(logsDir)) {
|
|
591
|
+
mkdirSync2(logsDir, { recursive: true });
|
|
573
592
|
}
|
|
574
593
|
const date = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
575
|
-
this.logFilePath =
|
|
594
|
+
this.logFilePath = join2(logsDir, `contextkit-${date}.log`);
|
|
576
595
|
} catch (error) {
|
|
577
596
|
console.error("[LOGGER] Failed to initialize log file:", error);
|
|
578
597
|
this.logFilePath = null;
|
|
@@ -584,8 +603,8 @@ var Logger = class {
|
|
|
584
603
|
getLevel() {
|
|
585
604
|
if (this.level === null) {
|
|
586
605
|
try {
|
|
587
|
-
const settingsPath =
|
|
588
|
-
if (
|
|
606
|
+
const settingsPath = join2(DEFAULT_DATA_DIR, "settings.json");
|
|
607
|
+
if (existsSync2(settingsPath)) {
|
|
589
608
|
const settingsData = readFileSync(settingsPath, "utf-8");
|
|
590
609
|
const settings = JSON.parse(settingsData);
|
|
591
610
|
const envLevel = (settings.CONTEXTKIT_LOG_LEVEL || "INFO").toUpperCase();
|
|
@@ -766,22 +785,22 @@ function getDirname() {
|
|
|
766
785
|
return dirname(fileURLToPath(import.meta.url));
|
|
767
786
|
}
|
|
768
787
|
var _dirname = getDirname();
|
|
769
|
-
var DATA_DIR = process.env.CONTEXTKIT_DATA_DIR ||
|
|
770
|
-
var KIRO_CONFIG_DIR = process.env.KIRO_CONFIG_DIR ||
|
|
771
|
-
var PLUGIN_ROOT =
|
|
772
|
-
var ARCHIVES_DIR =
|
|
773
|
-
var LOGS_DIR =
|
|
774
|
-
var TRASH_DIR =
|
|
775
|
-
var BACKUPS_DIR =
|
|
776
|
-
var MODES_DIR =
|
|
777
|
-
var USER_SETTINGS_PATH =
|
|
778
|
-
var DB_PATH =
|
|
779
|
-
var VECTOR_DB_DIR =
|
|
780
|
-
var OBSERVER_SESSIONS_DIR =
|
|
781
|
-
var KIRO_SETTINGS_PATH =
|
|
782
|
-
var KIRO_CONTEXT_PATH =
|
|
788
|
+
var DATA_DIR = process.env.CONTEXTKIT_DATA_DIR || join3(homedir2(), ".contextkit");
|
|
789
|
+
var KIRO_CONFIG_DIR = process.env.KIRO_CONFIG_DIR || join3(homedir2(), ".kiro");
|
|
790
|
+
var PLUGIN_ROOT = join3(KIRO_CONFIG_DIR, "plugins", "contextkit");
|
|
791
|
+
var ARCHIVES_DIR = join3(DATA_DIR, "archives");
|
|
792
|
+
var LOGS_DIR = join3(DATA_DIR, "logs");
|
|
793
|
+
var TRASH_DIR = join3(DATA_DIR, "trash");
|
|
794
|
+
var BACKUPS_DIR = join3(DATA_DIR, "backups");
|
|
795
|
+
var MODES_DIR = join3(DATA_DIR, "modes");
|
|
796
|
+
var USER_SETTINGS_PATH = join3(DATA_DIR, "settings.json");
|
|
797
|
+
var DB_PATH = join3(DATA_DIR, "contextkit.db");
|
|
798
|
+
var VECTOR_DB_DIR = join3(DATA_DIR, "vector-db");
|
|
799
|
+
var OBSERVER_SESSIONS_DIR = join3(DATA_DIR, "observer-sessions");
|
|
800
|
+
var KIRO_SETTINGS_PATH = join3(KIRO_CONFIG_DIR, "settings.json");
|
|
801
|
+
var KIRO_CONTEXT_PATH = join3(KIRO_CONFIG_DIR, "context.md");
|
|
783
802
|
function ensureDir(dirPath) {
|
|
784
|
-
|
|
803
|
+
mkdirSync3(dirPath, { recursive: true });
|
|
785
804
|
}
|
|
786
805
|
|
|
787
806
|
// src/services/sqlite/Database.ts
|
|
@@ -1165,7 +1184,7 @@ function createContextKit(config) {
|
|
|
1165
1184
|
|
|
1166
1185
|
// src/hooks/agentSpawn.ts
|
|
1167
1186
|
import { spawn } from "child_process";
|
|
1168
|
-
import { dirname as dirname2, join as
|
|
1187
|
+
import { dirname as dirname2, join as join4 } from "path";
|
|
1169
1188
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
1170
1189
|
var __filename_hook = fileURLToPath2(import.meta.url);
|
|
1171
1190
|
var __dirname_hook = dirname2(__filename_hook);
|
|
@@ -1181,7 +1200,7 @@ async function ensureWorkerRunning() {
|
|
|
1181
1200
|
if (resp.ok) return;
|
|
1182
1201
|
} catch {
|
|
1183
1202
|
}
|
|
1184
|
-
const workerPath =
|
|
1203
|
+
const workerPath = join4(__dirname_hook, "..", "worker-service.js");
|
|
1185
1204
|
const child = spawn("node", [workerPath], {
|
|
1186
1205
|
detached: true,
|
|
1187
1206
|
stdio: "ignore",
|
|
@@ -384,6 +384,22 @@ var init_Search = __esm({
|
|
|
384
384
|
});
|
|
385
385
|
|
|
386
386
|
// src/hooks/utils.ts
|
|
387
|
+
import { writeFileSync, mkdirSync, existsSync } from "fs";
|
|
388
|
+
import { join } from "path";
|
|
389
|
+
function debugLog(hookName, label, data) {
|
|
390
|
+
if ((process.env.KIRO_MEMORY_LOG_LEVEL || "").toUpperCase() !== "DEBUG") return;
|
|
391
|
+
try {
|
|
392
|
+
const dataDir = process.env.KIRO_MEMORY_DATA_DIR || join(process.env.HOME || "/tmp", ".kiro-memory");
|
|
393
|
+
const logDir = join(dataDir, "logs");
|
|
394
|
+
if (!existsSync(logDir)) mkdirSync(logDir, { recursive: true });
|
|
395
|
+
const ts = (/* @__PURE__ */ new Date()).toISOString();
|
|
396
|
+
const line = `[${ts}] [${hookName}] ${label}: ${JSON.stringify(data)}
|
|
397
|
+
`;
|
|
398
|
+
const logFile = join(logDir, `hooks-${(/* @__PURE__ */ new Date()).toISOString().split("T")[0]}.log`);
|
|
399
|
+
writeFileSync(logFile, line, { flag: "a" });
|
|
400
|
+
} catch {
|
|
401
|
+
}
|
|
402
|
+
}
|
|
387
403
|
async function readStdin() {
|
|
388
404
|
return new Promise((resolve, reject) => {
|
|
389
405
|
let data = "";
|
|
@@ -448,10 +464,13 @@ async function notifyWorker(event, data) {
|
|
|
448
464
|
async function runHook(name, handler) {
|
|
449
465
|
try {
|
|
450
466
|
const input = await readStdin();
|
|
467
|
+
debugLog(name, "stdin", input);
|
|
451
468
|
await handler(input);
|
|
469
|
+
debugLog(name, "completato", { success: true });
|
|
452
470
|
process.exit(0);
|
|
453
471
|
} catch (error) {
|
|
454
|
-
|
|
472
|
+
debugLog(name, "errore", { error: String(error) });
|
|
473
|
+
process.stderr.write(`[kiro-memory:${name}] Errore: ${error}
|
|
455
474
|
`);
|
|
456
475
|
process.exit(0);
|
|
457
476
|
}
|
|
@@ -525,14 +544,14 @@ var BunQueryCompat = class {
|
|
|
525
544
|
};
|
|
526
545
|
|
|
527
546
|
// src/shared/paths.ts
|
|
528
|
-
import { join as
|
|
547
|
+
import { join as join3, dirname, basename } from "path";
|
|
529
548
|
import { homedir as homedir2 } from "os";
|
|
530
|
-
import { mkdirSync as
|
|
549
|
+
import { mkdirSync as mkdirSync3 } from "fs";
|
|
531
550
|
import { fileURLToPath } from "url";
|
|
532
551
|
|
|
533
552
|
// src/utils/logger.ts
|
|
534
|
-
import { appendFileSync, existsSync, mkdirSync, readFileSync } from "fs";
|
|
535
|
-
import { join } from "path";
|
|
553
|
+
import { appendFileSync, existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync } from "fs";
|
|
554
|
+
import { join as join2 } from "path";
|
|
536
555
|
import { homedir } from "os";
|
|
537
556
|
var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
538
557
|
LogLevel2[LogLevel2["DEBUG"] = 0] = "DEBUG";
|
|
@@ -542,7 +561,7 @@ var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
|
542
561
|
LogLevel2[LogLevel2["SILENT"] = 4] = "SILENT";
|
|
543
562
|
return LogLevel2;
|
|
544
563
|
})(LogLevel || {});
|
|
545
|
-
var DEFAULT_DATA_DIR =
|
|
564
|
+
var DEFAULT_DATA_DIR = join2(homedir(), ".contextkit");
|
|
546
565
|
var Logger = class {
|
|
547
566
|
level = null;
|
|
548
567
|
useColor;
|
|
@@ -558,12 +577,12 @@ var Logger = class {
|
|
|
558
577
|
if (this.logFileInitialized) return;
|
|
559
578
|
this.logFileInitialized = true;
|
|
560
579
|
try {
|
|
561
|
-
const logsDir =
|
|
562
|
-
if (!
|
|
563
|
-
|
|
580
|
+
const logsDir = join2(DEFAULT_DATA_DIR, "logs");
|
|
581
|
+
if (!existsSync2(logsDir)) {
|
|
582
|
+
mkdirSync2(logsDir, { recursive: true });
|
|
564
583
|
}
|
|
565
584
|
const date = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
566
|
-
this.logFilePath =
|
|
585
|
+
this.logFilePath = join2(logsDir, `contextkit-${date}.log`);
|
|
567
586
|
} catch (error) {
|
|
568
587
|
console.error("[LOGGER] Failed to initialize log file:", error);
|
|
569
588
|
this.logFilePath = null;
|
|
@@ -575,8 +594,8 @@ var Logger = class {
|
|
|
575
594
|
getLevel() {
|
|
576
595
|
if (this.level === null) {
|
|
577
596
|
try {
|
|
578
|
-
const settingsPath =
|
|
579
|
-
if (
|
|
597
|
+
const settingsPath = join2(DEFAULT_DATA_DIR, "settings.json");
|
|
598
|
+
if (existsSync2(settingsPath)) {
|
|
580
599
|
const settingsData = readFileSync(settingsPath, "utf-8");
|
|
581
600
|
const settings = JSON.parse(settingsData);
|
|
582
601
|
const envLevel = (settings.CONTEXTKIT_LOG_LEVEL || "INFO").toUpperCase();
|
|
@@ -757,22 +776,22 @@ function getDirname() {
|
|
|
757
776
|
return dirname(fileURLToPath(import.meta.url));
|
|
758
777
|
}
|
|
759
778
|
var _dirname = getDirname();
|
|
760
|
-
var DATA_DIR = process.env.CONTEXTKIT_DATA_DIR ||
|
|
761
|
-
var KIRO_CONFIG_DIR = process.env.KIRO_CONFIG_DIR ||
|
|
762
|
-
var PLUGIN_ROOT =
|
|
763
|
-
var ARCHIVES_DIR =
|
|
764
|
-
var LOGS_DIR =
|
|
765
|
-
var TRASH_DIR =
|
|
766
|
-
var BACKUPS_DIR =
|
|
767
|
-
var MODES_DIR =
|
|
768
|
-
var USER_SETTINGS_PATH =
|
|
769
|
-
var DB_PATH =
|
|
770
|
-
var VECTOR_DB_DIR =
|
|
771
|
-
var OBSERVER_SESSIONS_DIR =
|
|
772
|
-
var KIRO_SETTINGS_PATH =
|
|
773
|
-
var KIRO_CONTEXT_PATH =
|
|
779
|
+
var DATA_DIR = process.env.CONTEXTKIT_DATA_DIR || join3(homedir2(), ".contextkit");
|
|
780
|
+
var KIRO_CONFIG_DIR = process.env.KIRO_CONFIG_DIR || join3(homedir2(), ".kiro");
|
|
781
|
+
var PLUGIN_ROOT = join3(KIRO_CONFIG_DIR, "plugins", "contextkit");
|
|
782
|
+
var ARCHIVES_DIR = join3(DATA_DIR, "archives");
|
|
783
|
+
var LOGS_DIR = join3(DATA_DIR, "logs");
|
|
784
|
+
var TRASH_DIR = join3(DATA_DIR, "trash");
|
|
785
|
+
var BACKUPS_DIR = join3(DATA_DIR, "backups");
|
|
786
|
+
var MODES_DIR = join3(DATA_DIR, "modes");
|
|
787
|
+
var USER_SETTINGS_PATH = join3(DATA_DIR, "settings.json");
|
|
788
|
+
var DB_PATH = join3(DATA_DIR, "contextkit.db");
|
|
789
|
+
var VECTOR_DB_DIR = join3(DATA_DIR, "vector-db");
|
|
790
|
+
var OBSERVER_SESSIONS_DIR = join3(DATA_DIR, "observer-sessions");
|
|
791
|
+
var KIRO_SETTINGS_PATH = join3(KIRO_CONFIG_DIR, "settings.json");
|
|
792
|
+
var KIRO_CONTEXT_PATH = join3(KIRO_CONFIG_DIR, "context.md");
|
|
774
793
|
function ensureDir(dirPath) {
|
|
775
|
-
|
|
794
|
+
mkdirSync3(dirPath, { recursive: true });
|
|
776
795
|
}
|
|
777
796
|
|
|
778
797
|
// src/services/sqlite/Database.ts
|
|
@@ -1157,8 +1176,28 @@ function createContextKit(config) {
|
|
|
1157
1176
|
// src/hooks/postToolUse.ts
|
|
1158
1177
|
runHook("postToolUse", async (input) => {
|
|
1159
1178
|
if (!input.tool_name) return;
|
|
1160
|
-
const ignoredTools = ["
|
|
1179
|
+
const ignoredTools = ["introspect", "thinking", "todo"];
|
|
1161
1180
|
if (ignoredTools.includes(input.tool_name)) return;
|
|
1181
|
+
const readOnlyTools = ["glob", "grep", "fs_read", "read"];
|
|
1182
|
+
if (readOnlyTools.includes(input.tool_name)) {
|
|
1183
|
+
const project2 = detectProject(input.cwd);
|
|
1184
|
+
const sdk2 = createContextKit({ project: project2 });
|
|
1185
|
+
try {
|
|
1186
|
+
const files = extractFiles(input.tool_input, input.tool_response);
|
|
1187
|
+
const query = input.tool_input?.pattern || input.tool_input?.regex || input.tool_input?.query || "";
|
|
1188
|
+
const title = input.tool_name === "grep" || input.tool_name === "glob" ? `Cercato: ${query}`.substring(0, 100) : `Letto: ${files[0] || input.tool_input?.path || input.tool_input?.file_path || "file"}`;
|
|
1189
|
+
await sdk2.storeObservation({
|
|
1190
|
+
type: "file-read",
|
|
1191
|
+
title,
|
|
1192
|
+
content: files.length > 0 ? `File: ${files.join(", ")}` : `Tool ${input.tool_name} eseguito`,
|
|
1193
|
+
files
|
|
1194
|
+
});
|
|
1195
|
+
await notifyWorker("observation-created", { project: project2, title, type: "file-read" });
|
|
1196
|
+
} finally {
|
|
1197
|
+
sdk2.close();
|
|
1198
|
+
}
|
|
1199
|
+
return;
|
|
1200
|
+
}
|
|
1162
1201
|
const project = detectProject(input.cwd);
|
|
1163
1202
|
const sdk = createContextKit({ project });
|
|
1164
1203
|
try {
|
|
@@ -1214,6 +1253,10 @@ function categorizeToolUse(toolName) {
|
|
|
1214
1253
|
const categories = {
|
|
1215
1254
|
"fs_write": "file-write",
|
|
1216
1255
|
"write": "file-write",
|
|
1256
|
+
"fs_read": "file-read",
|
|
1257
|
+
"read": "file-read",
|
|
1258
|
+
"glob": "file-read",
|
|
1259
|
+
"grep": "file-read",
|
|
1217
1260
|
"execute_bash": "command",
|
|
1218
1261
|
"shell": "command",
|
|
1219
1262
|
"web_search": "research",
|
|
@@ -384,6 +384,22 @@ var init_Search = __esm({
|
|
|
384
384
|
});
|
|
385
385
|
|
|
386
386
|
// src/hooks/utils.ts
|
|
387
|
+
import { writeFileSync, mkdirSync, existsSync } from "fs";
|
|
388
|
+
import { join } from "path";
|
|
389
|
+
function debugLog(hookName, label, data) {
|
|
390
|
+
if ((process.env.KIRO_MEMORY_LOG_LEVEL || "").toUpperCase() !== "DEBUG") return;
|
|
391
|
+
try {
|
|
392
|
+
const dataDir = process.env.KIRO_MEMORY_DATA_DIR || join(process.env.HOME || "/tmp", ".kiro-memory");
|
|
393
|
+
const logDir = join(dataDir, "logs");
|
|
394
|
+
if (!existsSync(logDir)) mkdirSync(logDir, { recursive: true });
|
|
395
|
+
const ts = (/* @__PURE__ */ new Date()).toISOString();
|
|
396
|
+
const line = `[${ts}] [${hookName}] ${label}: ${JSON.stringify(data)}
|
|
397
|
+
`;
|
|
398
|
+
const logFile = join(logDir, `hooks-${(/* @__PURE__ */ new Date()).toISOString().split("T")[0]}.log`);
|
|
399
|
+
writeFileSync(logFile, line, { flag: "a" });
|
|
400
|
+
} catch {
|
|
401
|
+
}
|
|
402
|
+
}
|
|
387
403
|
async function readStdin() {
|
|
388
404
|
return new Promise((resolve, reject) => {
|
|
389
405
|
let data = "";
|
|
@@ -448,10 +464,13 @@ async function notifyWorker(event, data) {
|
|
|
448
464
|
async function runHook(name, handler) {
|
|
449
465
|
try {
|
|
450
466
|
const input = await readStdin();
|
|
467
|
+
debugLog(name, "stdin", input);
|
|
451
468
|
await handler(input);
|
|
469
|
+
debugLog(name, "completato", { success: true });
|
|
452
470
|
process.exit(0);
|
|
453
471
|
} catch (error) {
|
|
454
|
-
|
|
472
|
+
debugLog(name, "errore", { error: String(error) });
|
|
473
|
+
process.stderr.write(`[kiro-memory:${name}] Errore: ${error}
|
|
455
474
|
`);
|
|
456
475
|
process.exit(0);
|
|
457
476
|
}
|
|
@@ -525,14 +544,14 @@ var BunQueryCompat = class {
|
|
|
525
544
|
};
|
|
526
545
|
|
|
527
546
|
// src/shared/paths.ts
|
|
528
|
-
import { join as
|
|
547
|
+
import { join as join3, dirname, basename } from "path";
|
|
529
548
|
import { homedir as homedir2 } from "os";
|
|
530
|
-
import { mkdirSync as
|
|
549
|
+
import { mkdirSync as mkdirSync3 } from "fs";
|
|
531
550
|
import { fileURLToPath } from "url";
|
|
532
551
|
|
|
533
552
|
// src/utils/logger.ts
|
|
534
|
-
import { appendFileSync, existsSync, mkdirSync, readFileSync } from "fs";
|
|
535
|
-
import { join } from "path";
|
|
553
|
+
import { appendFileSync, existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync } from "fs";
|
|
554
|
+
import { join as join2 } from "path";
|
|
536
555
|
import { homedir } from "os";
|
|
537
556
|
var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
538
557
|
LogLevel2[LogLevel2["DEBUG"] = 0] = "DEBUG";
|
|
@@ -542,7 +561,7 @@ var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
|
542
561
|
LogLevel2[LogLevel2["SILENT"] = 4] = "SILENT";
|
|
543
562
|
return LogLevel2;
|
|
544
563
|
})(LogLevel || {});
|
|
545
|
-
var DEFAULT_DATA_DIR =
|
|
564
|
+
var DEFAULT_DATA_DIR = join2(homedir(), ".contextkit");
|
|
546
565
|
var Logger = class {
|
|
547
566
|
level = null;
|
|
548
567
|
useColor;
|
|
@@ -558,12 +577,12 @@ var Logger = class {
|
|
|
558
577
|
if (this.logFileInitialized) return;
|
|
559
578
|
this.logFileInitialized = true;
|
|
560
579
|
try {
|
|
561
|
-
const logsDir =
|
|
562
|
-
if (!
|
|
563
|
-
|
|
580
|
+
const logsDir = join2(DEFAULT_DATA_DIR, "logs");
|
|
581
|
+
if (!existsSync2(logsDir)) {
|
|
582
|
+
mkdirSync2(logsDir, { recursive: true });
|
|
564
583
|
}
|
|
565
584
|
const date = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
566
|
-
this.logFilePath =
|
|
585
|
+
this.logFilePath = join2(logsDir, `contextkit-${date}.log`);
|
|
567
586
|
} catch (error) {
|
|
568
587
|
console.error("[LOGGER] Failed to initialize log file:", error);
|
|
569
588
|
this.logFilePath = null;
|
|
@@ -575,8 +594,8 @@ var Logger = class {
|
|
|
575
594
|
getLevel() {
|
|
576
595
|
if (this.level === null) {
|
|
577
596
|
try {
|
|
578
|
-
const settingsPath =
|
|
579
|
-
if (
|
|
597
|
+
const settingsPath = join2(DEFAULT_DATA_DIR, "settings.json");
|
|
598
|
+
if (existsSync2(settingsPath)) {
|
|
580
599
|
const settingsData = readFileSync(settingsPath, "utf-8");
|
|
581
600
|
const settings = JSON.parse(settingsData);
|
|
582
601
|
const envLevel = (settings.CONTEXTKIT_LOG_LEVEL || "INFO").toUpperCase();
|
|
@@ -757,22 +776,22 @@ function getDirname() {
|
|
|
757
776
|
return dirname(fileURLToPath(import.meta.url));
|
|
758
777
|
}
|
|
759
778
|
var _dirname = getDirname();
|
|
760
|
-
var DATA_DIR = process.env.CONTEXTKIT_DATA_DIR ||
|
|
761
|
-
var KIRO_CONFIG_DIR = process.env.KIRO_CONFIG_DIR ||
|
|
762
|
-
var PLUGIN_ROOT =
|
|
763
|
-
var ARCHIVES_DIR =
|
|
764
|
-
var LOGS_DIR =
|
|
765
|
-
var TRASH_DIR =
|
|
766
|
-
var BACKUPS_DIR =
|
|
767
|
-
var MODES_DIR =
|
|
768
|
-
var USER_SETTINGS_PATH =
|
|
769
|
-
var DB_PATH =
|
|
770
|
-
var VECTOR_DB_DIR =
|
|
771
|
-
var OBSERVER_SESSIONS_DIR =
|
|
772
|
-
var KIRO_SETTINGS_PATH =
|
|
773
|
-
var KIRO_CONTEXT_PATH =
|
|
779
|
+
var DATA_DIR = process.env.CONTEXTKIT_DATA_DIR || join3(homedir2(), ".contextkit");
|
|
780
|
+
var KIRO_CONFIG_DIR = process.env.KIRO_CONFIG_DIR || join3(homedir2(), ".kiro");
|
|
781
|
+
var PLUGIN_ROOT = join3(KIRO_CONFIG_DIR, "plugins", "contextkit");
|
|
782
|
+
var ARCHIVES_DIR = join3(DATA_DIR, "archives");
|
|
783
|
+
var LOGS_DIR = join3(DATA_DIR, "logs");
|
|
784
|
+
var TRASH_DIR = join3(DATA_DIR, "trash");
|
|
785
|
+
var BACKUPS_DIR = join3(DATA_DIR, "backups");
|
|
786
|
+
var MODES_DIR = join3(DATA_DIR, "modes");
|
|
787
|
+
var USER_SETTINGS_PATH = join3(DATA_DIR, "settings.json");
|
|
788
|
+
var DB_PATH = join3(DATA_DIR, "contextkit.db");
|
|
789
|
+
var VECTOR_DB_DIR = join3(DATA_DIR, "vector-db");
|
|
790
|
+
var OBSERVER_SESSIONS_DIR = join3(DATA_DIR, "observer-sessions");
|
|
791
|
+
var KIRO_SETTINGS_PATH = join3(KIRO_CONFIG_DIR, "settings.json");
|
|
792
|
+
var KIRO_CONTEXT_PATH = join3(KIRO_CONFIG_DIR, "context.md");
|
|
774
793
|
function ensureDir(dirPath) {
|
|
775
|
-
|
|
794
|
+
mkdirSync3(dirPath, { recursive: true });
|
|
776
795
|
}
|
|
777
796
|
|
|
778
797
|
// src/services/sqlite/Database.ts
|
|
@@ -384,6 +384,22 @@ var init_Search = __esm({
|
|
|
384
384
|
});
|
|
385
385
|
|
|
386
386
|
// src/hooks/utils.ts
|
|
387
|
+
import { writeFileSync, mkdirSync, existsSync } from "fs";
|
|
388
|
+
import { join } from "path";
|
|
389
|
+
function debugLog(hookName, label, data) {
|
|
390
|
+
if ((process.env.KIRO_MEMORY_LOG_LEVEL || "").toUpperCase() !== "DEBUG") return;
|
|
391
|
+
try {
|
|
392
|
+
const dataDir = process.env.KIRO_MEMORY_DATA_DIR || join(process.env.HOME || "/tmp", ".kiro-memory");
|
|
393
|
+
const logDir = join(dataDir, "logs");
|
|
394
|
+
if (!existsSync(logDir)) mkdirSync(logDir, { recursive: true });
|
|
395
|
+
const ts = (/* @__PURE__ */ new Date()).toISOString();
|
|
396
|
+
const line = `[${ts}] [${hookName}] ${label}: ${JSON.stringify(data)}
|
|
397
|
+
`;
|
|
398
|
+
const logFile = join(logDir, `hooks-${(/* @__PURE__ */ new Date()).toISOString().split("T")[0]}.log`);
|
|
399
|
+
writeFileSync(logFile, line, { flag: "a" });
|
|
400
|
+
} catch {
|
|
401
|
+
}
|
|
402
|
+
}
|
|
387
403
|
async function readStdin() {
|
|
388
404
|
return new Promise((resolve, reject) => {
|
|
389
405
|
let data = "";
|
|
@@ -448,10 +464,13 @@ async function notifyWorker(event, data) {
|
|
|
448
464
|
async function runHook(name, handler) {
|
|
449
465
|
try {
|
|
450
466
|
const input = await readStdin();
|
|
467
|
+
debugLog(name, "stdin", input);
|
|
451
468
|
await handler(input);
|
|
469
|
+
debugLog(name, "completato", { success: true });
|
|
452
470
|
process.exit(0);
|
|
453
471
|
} catch (error) {
|
|
454
|
-
|
|
472
|
+
debugLog(name, "errore", { error: String(error) });
|
|
473
|
+
process.stderr.write(`[kiro-memory:${name}] Errore: ${error}
|
|
455
474
|
`);
|
|
456
475
|
process.exit(0);
|
|
457
476
|
}
|
|
@@ -525,14 +544,14 @@ var BunQueryCompat = class {
|
|
|
525
544
|
};
|
|
526
545
|
|
|
527
546
|
// src/shared/paths.ts
|
|
528
|
-
import { join as
|
|
547
|
+
import { join as join3, dirname, basename } from "path";
|
|
529
548
|
import { homedir as homedir2 } from "os";
|
|
530
|
-
import { mkdirSync as
|
|
549
|
+
import { mkdirSync as mkdirSync3 } from "fs";
|
|
531
550
|
import { fileURLToPath } from "url";
|
|
532
551
|
|
|
533
552
|
// src/utils/logger.ts
|
|
534
|
-
import { appendFileSync, existsSync, mkdirSync, readFileSync } from "fs";
|
|
535
|
-
import { join } from "path";
|
|
553
|
+
import { appendFileSync, existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync } from "fs";
|
|
554
|
+
import { join as join2 } from "path";
|
|
536
555
|
import { homedir } from "os";
|
|
537
556
|
var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
538
557
|
LogLevel2[LogLevel2["DEBUG"] = 0] = "DEBUG";
|
|
@@ -542,7 +561,7 @@ var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
|
542
561
|
LogLevel2[LogLevel2["SILENT"] = 4] = "SILENT";
|
|
543
562
|
return LogLevel2;
|
|
544
563
|
})(LogLevel || {});
|
|
545
|
-
var DEFAULT_DATA_DIR =
|
|
564
|
+
var DEFAULT_DATA_DIR = join2(homedir(), ".contextkit");
|
|
546
565
|
var Logger = class {
|
|
547
566
|
level = null;
|
|
548
567
|
useColor;
|
|
@@ -558,12 +577,12 @@ var Logger = class {
|
|
|
558
577
|
if (this.logFileInitialized) return;
|
|
559
578
|
this.logFileInitialized = true;
|
|
560
579
|
try {
|
|
561
|
-
const logsDir =
|
|
562
|
-
if (!
|
|
563
|
-
|
|
580
|
+
const logsDir = join2(DEFAULT_DATA_DIR, "logs");
|
|
581
|
+
if (!existsSync2(logsDir)) {
|
|
582
|
+
mkdirSync2(logsDir, { recursive: true });
|
|
564
583
|
}
|
|
565
584
|
const date = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
566
|
-
this.logFilePath =
|
|
585
|
+
this.logFilePath = join2(logsDir, `contextkit-${date}.log`);
|
|
567
586
|
} catch (error) {
|
|
568
587
|
console.error("[LOGGER] Failed to initialize log file:", error);
|
|
569
588
|
this.logFilePath = null;
|
|
@@ -575,8 +594,8 @@ var Logger = class {
|
|
|
575
594
|
getLevel() {
|
|
576
595
|
if (this.level === null) {
|
|
577
596
|
try {
|
|
578
|
-
const settingsPath =
|
|
579
|
-
if (
|
|
597
|
+
const settingsPath = join2(DEFAULT_DATA_DIR, "settings.json");
|
|
598
|
+
if (existsSync2(settingsPath)) {
|
|
580
599
|
const settingsData = readFileSync(settingsPath, "utf-8");
|
|
581
600
|
const settings = JSON.parse(settingsData);
|
|
582
601
|
const envLevel = (settings.CONTEXTKIT_LOG_LEVEL || "INFO").toUpperCase();
|
|
@@ -757,22 +776,22 @@ function getDirname() {
|
|
|
757
776
|
return dirname(fileURLToPath(import.meta.url));
|
|
758
777
|
}
|
|
759
778
|
var _dirname = getDirname();
|
|
760
|
-
var DATA_DIR = process.env.CONTEXTKIT_DATA_DIR ||
|
|
761
|
-
var KIRO_CONFIG_DIR = process.env.KIRO_CONFIG_DIR ||
|
|
762
|
-
var PLUGIN_ROOT =
|
|
763
|
-
var ARCHIVES_DIR =
|
|
764
|
-
var LOGS_DIR =
|
|
765
|
-
var TRASH_DIR =
|
|
766
|
-
var BACKUPS_DIR =
|
|
767
|
-
var MODES_DIR =
|
|
768
|
-
var USER_SETTINGS_PATH =
|
|
769
|
-
var DB_PATH =
|
|
770
|
-
var VECTOR_DB_DIR =
|
|
771
|
-
var OBSERVER_SESSIONS_DIR =
|
|
772
|
-
var KIRO_SETTINGS_PATH =
|
|
773
|
-
var KIRO_CONTEXT_PATH =
|
|
779
|
+
var DATA_DIR = process.env.CONTEXTKIT_DATA_DIR || join3(homedir2(), ".contextkit");
|
|
780
|
+
var KIRO_CONFIG_DIR = process.env.KIRO_CONFIG_DIR || join3(homedir2(), ".kiro");
|
|
781
|
+
var PLUGIN_ROOT = join3(KIRO_CONFIG_DIR, "plugins", "contextkit");
|
|
782
|
+
var ARCHIVES_DIR = join3(DATA_DIR, "archives");
|
|
783
|
+
var LOGS_DIR = join3(DATA_DIR, "logs");
|
|
784
|
+
var TRASH_DIR = join3(DATA_DIR, "trash");
|
|
785
|
+
var BACKUPS_DIR = join3(DATA_DIR, "backups");
|
|
786
|
+
var MODES_DIR = join3(DATA_DIR, "modes");
|
|
787
|
+
var USER_SETTINGS_PATH = join3(DATA_DIR, "settings.json");
|
|
788
|
+
var DB_PATH = join3(DATA_DIR, "contextkit.db");
|
|
789
|
+
var VECTOR_DB_DIR = join3(DATA_DIR, "vector-db");
|
|
790
|
+
var OBSERVER_SESSIONS_DIR = join3(DATA_DIR, "observer-sessions");
|
|
791
|
+
var KIRO_SETTINGS_PATH = join3(KIRO_CONFIG_DIR, "settings.json");
|
|
792
|
+
var KIRO_CONTEXT_PATH = join3(KIRO_CONFIG_DIR, "context.md");
|
|
774
793
|
function ensureDir(dirPath) {
|
|
775
|
-
|
|
794
|
+
mkdirSync3(dirPath, { recursive: true });
|
|
776
795
|
}
|
|
777
796
|
|
|
778
797
|
// src/services/sqlite/Database.ts
|
|
@@ -1156,13 +1175,13 @@ function createContextKit(config) {
|
|
|
1156
1175
|
|
|
1157
1176
|
// src/hooks/userPromptSubmit.ts
|
|
1158
1177
|
runHook("userPromptSubmit", async (input) => {
|
|
1178
|
+
const promptText = input.prompt || input.user_prompt || input.tool_input?.prompt || input.tool_input?.content;
|
|
1179
|
+
if (!promptText || typeof promptText !== "string" || promptText.trim().length === 0) return;
|
|
1159
1180
|
const project = detectProject(input.cwd);
|
|
1160
1181
|
const sdk = createContextKit({ project });
|
|
1161
1182
|
try {
|
|
1162
|
-
const
|
|
1163
|
-
|
|
1164
|
-
const sessionId = `kiro-${(/* @__PURE__ */ new Date()).toISOString().split("T")[0]}-${project}`;
|
|
1165
|
-
await sdk.storePrompt(sessionId, Date.now(), promptText);
|
|
1183
|
+
const sessionId = input.session_id || `kiro-${(/* @__PURE__ */ new Date()).toISOString().split("T")[0]}-${project}`;
|
|
1184
|
+
await sdk.storePrompt(sessionId, Date.now(), promptText.trim());
|
|
1166
1185
|
await notifyWorker("prompt-created", { project });
|
|
1167
1186
|
} finally {
|
|
1168
1187
|
sdk.close();
|
package/plugin/dist/index.js
CHANGED
|
@@ -1202,6 +1202,22 @@ function createContextKit(config) {
|
|
|
1202
1202
|
init_Search();
|
|
1203
1203
|
|
|
1204
1204
|
// src/hooks/utils.ts
|
|
1205
|
+
import { writeFileSync, mkdirSync as mkdirSync3, existsSync as existsSync3 } from "fs";
|
|
1206
|
+
import { join as join3 } from "path";
|
|
1207
|
+
function debugLog(hookName, label, data) {
|
|
1208
|
+
if ((process.env.KIRO_MEMORY_LOG_LEVEL || "").toUpperCase() !== "DEBUG") return;
|
|
1209
|
+
try {
|
|
1210
|
+
const dataDir = process.env.KIRO_MEMORY_DATA_DIR || join3(process.env.HOME || "/tmp", ".kiro-memory");
|
|
1211
|
+
const logDir = join3(dataDir, "logs");
|
|
1212
|
+
if (!existsSync3(logDir)) mkdirSync3(logDir, { recursive: true });
|
|
1213
|
+
const ts = (/* @__PURE__ */ new Date()).toISOString();
|
|
1214
|
+
const line = `[${ts}] [${hookName}] ${label}: ${JSON.stringify(data)}
|
|
1215
|
+
`;
|
|
1216
|
+
const logFile = join3(logDir, `hooks-${(/* @__PURE__ */ new Date()).toISOString().split("T")[0]}.log`);
|
|
1217
|
+
writeFileSync(logFile, line, { flag: "a" });
|
|
1218
|
+
} catch {
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1205
1221
|
async function readStdin() {
|
|
1206
1222
|
return new Promise((resolve, reject) => {
|
|
1207
1223
|
let data = "";
|
|
@@ -1275,10 +1291,13 @@ function formatContext(data) {
|
|
|
1275
1291
|
async function runHook(name, handler) {
|
|
1276
1292
|
try {
|
|
1277
1293
|
const input = await readStdin();
|
|
1294
|
+
debugLog(name, "stdin", input);
|
|
1278
1295
|
await handler(input);
|
|
1296
|
+
debugLog(name, "completato", { success: true });
|
|
1279
1297
|
process.exit(0);
|
|
1280
1298
|
} catch (error) {
|
|
1281
|
-
|
|
1299
|
+
debugLog(name, "errore", { error: String(error) });
|
|
1300
|
+
process.stderr.write(`[kiro-memory:${name}] Errore: ${error}
|
|
1282
1301
|
`);
|
|
1283
1302
|
process.exit(0);
|
|
1284
1303
|
}
|
package/plugin/dist/viewer.html
CHANGED
|
@@ -32,6 +32,8 @@
|
|
|
32
32
|
--pink-muted: rgba(244, 114, 182, 0.15);
|
|
33
33
|
--red: #f87171;
|
|
34
34
|
--red-muted: rgba(248, 113, 113, 0.15);
|
|
35
|
+
--teal: #2dd4bf;
|
|
36
|
+
--teal-muted: rgba(45, 212, 191, 0.15);
|
|
35
37
|
--sidebar-width: 260px;
|
|
36
38
|
--header-height: 56px;
|
|
37
39
|
--radius: 8px;
|
|
@@ -415,6 +417,7 @@
|
|
|
415
417
|
.card--summary { border-left-color: var(--violet); }
|
|
416
418
|
.card--prompt { border-left-color: var(--pink); }
|
|
417
419
|
.card--delegation { border-left-color: var(--accent); }
|
|
420
|
+
.card--file-read { border-left-color: var(--teal); }
|
|
418
421
|
.card--tool-use { border-left-color: var(--text-muted); }
|
|
419
422
|
.card--default { border-left-color: var(--text-muted); }
|
|
420
423
|
|
|
@@ -445,6 +448,7 @@
|
|
|
445
448
|
.badge--summary { background: var(--violet-muted); color: var(--violet); }
|
|
446
449
|
.badge--prompt { background: var(--pink-muted); color: var(--pink); }
|
|
447
450
|
.badge--delegation { background: var(--accent-muted); color: var(--accent); }
|
|
451
|
+
.badge--file-read { background: var(--teal-muted); color: var(--teal); }
|
|
448
452
|
.badge--tool-use { background: var(--bg-tertiary); color: var(--text-secondary); }
|
|
449
453
|
.badge--default { background: var(--bg-tertiary); color: var(--text-secondary); }
|
|
450
454
|
|
package/plugin/dist/viewer.js
CHANGED
|
@@ -23597,6 +23597,7 @@ var import_react = __toESM(require_react(), 1);
|
|
|
23597
23597
|
function getBadgeClass(type) {
|
|
23598
23598
|
const map = {
|
|
23599
23599
|
"file-write": "badge--file-write",
|
|
23600
|
+
"file-read": "badge--file-read",
|
|
23600
23601
|
"command": "badge--command",
|
|
23601
23602
|
"research": "badge--research",
|
|
23602
23603
|
"delegation": "badge--delegation",
|