memorix 0.6.3 → 0.6.4
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/dist/cli/index.js +85 -4
- package/dist/cli/index.js.map +1 -1
- package/dist/index.js +73 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -52,6 +52,9 @@ function sanitizeProjectId(projectId) {
|
|
|
52
52
|
return projectId.replace(/\//g, "--").replace(/[<>:"|?*\\]/g, "_");
|
|
53
53
|
}
|
|
54
54
|
async function getProjectDataDir(projectId, baseDir) {
|
|
55
|
+
if (projectId === "__invalid__") {
|
|
56
|
+
throw new Error("Cannot create data directory for invalid project");
|
|
57
|
+
}
|
|
55
58
|
const base = baseDir ?? DEFAULT_DATA_DIR;
|
|
56
59
|
const dirName = sanitizeProjectId(projectId);
|
|
57
60
|
const dataDir = path2.join(base, dirName);
|
|
@@ -1223,6 +1226,7 @@ __export(detector_exports, {
|
|
|
1223
1226
|
});
|
|
1224
1227
|
import { execSync } from "child_process";
|
|
1225
1228
|
import { existsSync } from "fs";
|
|
1229
|
+
import os2 from "os";
|
|
1226
1230
|
import path3 from "path";
|
|
1227
1231
|
function detectProject(cwd) {
|
|
1228
1232
|
const basePath = cwd ?? process.cwd();
|
|
@@ -1233,11 +1237,77 @@ function detectProject(cwd) {
|
|
|
1233
1237
|
const name2 = id2.split("/").pop() ?? path3.basename(rootPath);
|
|
1234
1238
|
return { id: id2, name: name2, gitRemote, rootPath };
|
|
1235
1239
|
}
|
|
1240
|
+
if (!isValidProjectRoot(rootPath)) {
|
|
1241
|
+
console.error(`[memorix] Skipped invalid project root: ${rootPath}`);
|
|
1242
|
+
return { id: "__invalid__", name: "unknown", rootPath };
|
|
1243
|
+
}
|
|
1236
1244
|
const name = path3.basename(rootPath);
|
|
1237
1245
|
const id = `local/${name}`;
|
|
1238
1246
|
console.error(`[memorix] Warning: no git remote found at ${rootPath}, using fallback projectId: ${id}`);
|
|
1239
1247
|
return { id, name, rootPath };
|
|
1240
1248
|
}
|
|
1249
|
+
function isValidProjectRoot(dirPath) {
|
|
1250
|
+
const resolved = path3.resolve(dirPath);
|
|
1251
|
+
const home = path3.resolve(os2.homedir());
|
|
1252
|
+
if (resolved === home) return false;
|
|
1253
|
+
if (resolved === path3.parse(resolved).root) return false;
|
|
1254
|
+
const basename2 = path3.basename(resolved).toLowerCase();
|
|
1255
|
+
const knownNonProjectDirs = /* @__PURE__ */ new Set([
|
|
1256
|
+
// IDE / editor config dirs
|
|
1257
|
+
".vscode",
|
|
1258
|
+
".cursor",
|
|
1259
|
+
".windsurf",
|
|
1260
|
+
".kiro",
|
|
1261
|
+
".codex",
|
|
1262
|
+
".gemini",
|
|
1263
|
+
".claude",
|
|
1264
|
+
".github",
|
|
1265
|
+
".git",
|
|
1266
|
+
// OS / system dirs
|
|
1267
|
+
"desktop",
|
|
1268
|
+
"documents",
|
|
1269
|
+
"downloads",
|
|
1270
|
+
"pictures",
|
|
1271
|
+
"videos",
|
|
1272
|
+
"music",
|
|
1273
|
+
"appdata",
|
|
1274
|
+
"application data",
|
|
1275
|
+
"library",
|
|
1276
|
+
// Package manager / tool dirs
|
|
1277
|
+
"node_modules",
|
|
1278
|
+
".npm",
|
|
1279
|
+
".yarn",
|
|
1280
|
+
".pnpm-store",
|
|
1281
|
+
".config",
|
|
1282
|
+
".local",
|
|
1283
|
+
".cache",
|
|
1284
|
+
".ssh",
|
|
1285
|
+
".memorix"
|
|
1286
|
+
]);
|
|
1287
|
+
if (knownNonProjectDirs.has(basename2)) {
|
|
1288
|
+
const parent = path3.resolve(path3.dirname(resolved));
|
|
1289
|
+
if (parent === home || parent === path3.parse(parent).root) {
|
|
1290
|
+
return false;
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
const projectIndicators = [
|
|
1294
|
+
"package.json",
|
|
1295
|
+
"Cargo.toml",
|
|
1296
|
+
"go.mod",
|
|
1297
|
+
"pyproject.toml",
|
|
1298
|
+
"setup.py",
|
|
1299
|
+
"pom.xml",
|
|
1300
|
+
"build.gradle",
|
|
1301
|
+
"Makefile",
|
|
1302
|
+
"CMakeLists.txt",
|
|
1303
|
+
"composer.json",
|
|
1304
|
+
"Gemfile",
|
|
1305
|
+
".git",
|
|
1306
|
+
"README.md",
|
|
1307
|
+
"README"
|
|
1308
|
+
];
|
|
1309
|
+
return projectIndicators.some((f) => existsSync(path3.join(resolved, f)));
|
|
1310
|
+
}
|
|
1241
1311
|
function findPackageRoot(cwd) {
|
|
1242
1312
|
let dir = path3.resolve(cwd);
|
|
1243
1313
|
const root = path3.parse(dir).root;
|
|
@@ -3164,7 +3234,7 @@ __export(installers_exports, {
|
|
|
3164
3234
|
});
|
|
3165
3235
|
import * as fs3 from "fs/promises";
|
|
3166
3236
|
import * as path5 from "path";
|
|
3167
|
-
import * as
|
|
3237
|
+
import * as os3 from "os";
|
|
3168
3238
|
import { createRequire } from "module";
|
|
3169
3239
|
function resolveHookCommand() {
|
|
3170
3240
|
if (process.platform === "win32") {
|
|
@@ -3269,7 +3339,7 @@ function getProjectConfigPath(agent, projectRoot) {
|
|
|
3269
3339
|
}
|
|
3270
3340
|
}
|
|
3271
3341
|
function getGlobalConfigPath(agent) {
|
|
3272
|
-
const home =
|
|
3342
|
+
const home = os3.homedir();
|
|
3273
3343
|
switch (agent) {
|
|
3274
3344
|
case "claude":
|
|
3275
3345
|
case "copilot":
|
|
@@ -3284,7 +3354,7 @@ function getGlobalConfigPath(agent) {
|
|
|
3284
3354
|
}
|
|
3285
3355
|
async function detectInstalledAgents() {
|
|
3286
3356
|
const agents = [];
|
|
3287
|
-
const home =
|
|
3357
|
+
const home = os3.homedir();
|
|
3288
3358
|
const claudeDir = path5.join(home, ".claude");
|
|
3289
3359
|
try {
|
|
3290
3360
|
await fs3.access(claudeDir);
|
|
@@ -5029,9 +5099,10 @@ function normalizeCursor(payload, event) {
|
|
|
5029
5099
|
return result;
|
|
5030
5100
|
}
|
|
5031
5101
|
function normalizeHookInput(payload) {
|
|
5102
|
+
const directEvent = typeof payload.event === "string" ? EVENT_MAP[payload.event] : void 0;
|
|
5032
5103
|
const agent = detectAgent(payload);
|
|
5033
5104
|
const rawEventName = extractEventName(payload, agent);
|
|
5034
|
-
const event = EVENT_MAP[rawEventName] ?? "post_tool";
|
|
5105
|
+
const event = directEvent ?? EVENT_MAP[rawEventName] ?? "post_tool";
|
|
5035
5106
|
const timestamp = payload.timestamp ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
5036
5107
|
let agentSpecific = {};
|
|
5037
5108
|
switch (agent) {
|
|
@@ -5064,6 +5135,16 @@ var init_normalizer = __esm({
|
|
|
5064
5135
|
"use strict";
|
|
5065
5136
|
init_esm_shims();
|
|
5066
5137
|
EVENT_MAP = {
|
|
5138
|
+
// Identity mappings — already-normalized event names
|
|
5139
|
+
// This allows direct payloads like { event: 'session_start' } to work
|
|
5140
|
+
session_start: "session_start",
|
|
5141
|
+
user_prompt: "user_prompt",
|
|
5142
|
+
post_edit: "post_edit",
|
|
5143
|
+
post_command: "post_command",
|
|
5144
|
+
post_tool: "post_tool",
|
|
5145
|
+
pre_compact: "pre_compact",
|
|
5146
|
+
session_end: "session_end",
|
|
5147
|
+
post_response: "post_response",
|
|
5067
5148
|
// Claude Code / VS Code Copilot
|
|
5068
5149
|
SessionStart: "session_start",
|
|
5069
5150
|
UserPromptSubmit: "user_prompt",
|