@hasna/mementos 0.4.9 → 0.4.10

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":";AACA;;;GAGG;AAikCH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAoG9C"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":";AACA;;;GAGG;AAkkCH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CA2G9C"}
@@ -1030,6 +1030,97 @@ function loadConfig() {
1030
1030
  }
1031
1031
  return merged;
1032
1032
  }
1033
+ function findFileWalkingUp(filename) {
1034
+ let dir = process.cwd();
1035
+ while (true) {
1036
+ const candidate = join2(dir, filename);
1037
+ if (existsSync2(candidate)) {
1038
+ return candidate;
1039
+ }
1040
+ const parent = dirname2(dir);
1041
+ if (parent === dir) {
1042
+ return null;
1043
+ }
1044
+ dir = parent;
1045
+ }
1046
+ }
1047
+ function findGitRoot2() {
1048
+ let dir = process.cwd();
1049
+ while (true) {
1050
+ if (existsSync2(join2(dir, ".git"))) {
1051
+ return dir;
1052
+ }
1053
+ const parent = dirname2(dir);
1054
+ if (parent === dir) {
1055
+ return null;
1056
+ }
1057
+ dir = parent;
1058
+ }
1059
+ }
1060
+ function profilesDir() {
1061
+ return join2(homedir(), ".mementos", "profiles");
1062
+ }
1063
+ function globalConfigPath() {
1064
+ return join2(homedir(), ".mementos", "config.json");
1065
+ }
1066
+ function readGlobalConfig() {
1067
+ const p = globalConfigPath();
1068
+ if (!existsSync2(p))
1069
+ return {};
1070
+ try {
1071
+ return JSON.parse(readFileSync(p, "utf-8"));
1072
+ } catch {
1073
+ return {};
1074
+ }
1075
+ }
1076
+ function getActiveProfile() {
1077
+ const envProfile = process.env["MEMENTOS_PROFILE"];
1078
+ if (envProfile)
1079
+ return envProfile.trim();
1080
+ const cfg = readGlobalConfig();
1081
+ return cfg["active_profile"] || null;
1082
+ }
1083
+ function listProfiles() {
1084
+ const dir = profilesDir();
1085
+ if (!existsSync2(dir))
1086
+ return [];
1087
+ return readdirSync(dir).filter((f) => f.endsWith(".db")).map((f) => basename(f, ".db")).sort();
1088
+ }
1089
+ function getDbPath2() {
1090
+ const envDbPath = process.env["MEMENTOS_DB_PATH"];
1091
+ if (envDbPath) {
1092
+ const resolved = resolve2(envDbPath);
1093
+ ensureDir2(dirname2(resolved));
1094
+ return resolved;
1095
+ }
1096
+ const profile = getActiveProfile();
1097
+ if (profile) {
1098
+ const profilePath = join2(profilesDir(), `${profile}.db`);
1099
+ ensureDir2(dirname2(profilePath));
1100
+ return profilePath;
1101
+ }
1102
+ const dbScope = process.env["MEMENTOS_DB_SCOPE"];
1103
+ if (dbScope === "project") {
1104
+ const gitRoot = findGitRoot2();
1105
+ if (gitRoot) {
1106
+ const dbPath = join2(gitRoot, ".mementos", "mementos.db");
1107
+ ensureDir2(dirname2(dbPath));
1108
+ return dbPath;
1109
+ }
1110
+ }
1111
+ const found = findFileWalkingUp(join2(".mementos", "mementos.db"));
1112
+ if (found) {
1113
+ return found;
1114
+ }
1115
+ const fallback = join2(homedir(), ".mementos", "mementos.db");
1116
+ ensureDir2(dirname2(fallback));
1117
+ return fallback;
1118
+ }
1119
+ function ensureDir2(dir) {
1120
+ if (!existsSync2(dir)) {
1121
+ mkdirSync2(dir, { recursive: true });
1122
+ }
1123
+ }
1033
1124
 
1034
1125
  // src/db/memories.ts
1035
1126
  function runEntityExtraction(memory, projectId, d) {
@@ -2750,7 +2841,12 @@ function startServer(port) {
2750
2841
  return new Response(null, { status: 204, headers: CORS_HEADERS });
2751
2842
  }
2752
2843
  if (pathname === "/api/health" || pathname === "/health") {
2753
- return json({ status: "ok", version: "0.1.0" });
2844
+ const profile = getActiveProfile();
2845
+ return json({ status: "ok", version: "0.1.0", profile: profile ?? "default", db_path: getDbPath2() });
2846
+ }
2847
+ if (pathname === "/api/profile" && req.method === "GET") {
2848
+ const profile = getActiveProfile();
2849
+ return json({ active: profile ?? null, profiles: listProfiles(), db_path: getDbPath2() });
2754
2850
  }
2755
2851
  if (pathname === "/api/memories/stream" && req.method === "GET") {
2756
2852
  const stream = new ReadableStream({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hasna/mementos",
3
- "version": "0.4.9",
3
+ "version": "0.4.10",
4
4
  "description": "Universal memory system for AI agents - CLI + MCP server + library API",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",