@hasna/mementos 0.4.9 → 0.4.11

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,CAkH9C"}
@@ -3,7 +3,7 @@
3
3
 
4
4
  // src/server/index.ts
5
5
  import { existsSync as existsSync3 } from "fs";
6
- import { dirname as dirname3, extname, join as join3 } from "path";
6
+ import { dirname as dirname3, extname, join as join3, resolve as resolve3, sep } from "path";
7
7
  import { fileURLToPath } from "url";
8
8
 
9
9
  // src/types/index.ts
@@ -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) {
@@ -2741,8 +2832,10 @@ async function findFreePort(start) {
2741
2832
  return start;
2742
2833
  }
2743
2834
  function startServer(port) {
2835
+ const hostname = process.env["MEMENTOS_HOST"] ?? "127.0.0.1";
2744
2836
  Bun.serve({
2745
2837
  port,
2838
+ hostname,
2746
2839
  async fetch(req) {
2747
2840
  const url = new URL(req.url);
2748
2841
  const { pathname } = url;
@@ -2750,7 +2843,12 @@ function startServer(port) {
2750
2843
  return new Response(null, { status: 204, headers: CORS_HEADERS });
2751
2844
  }
2752
2845
  if (pathname === "/api/health" || pathname === "/health") {
2753
- return json({ status: "ok", version: "0.1.0" });
2846
+ const profile = getActiveProfile();
2847
+ return json({ status: "ok", version: "0.1.0", profile: profile ?? "default", db_path: getDbPath2(), hostname });
2848
+ }
2849
+ if (pathname === "/api/profile" && req.method === "GET") {
2850
+ const profile = getActiveProfile();
2851
+ return json({ active: profile ?? null, profiles: listProfiles(), db_path: getDbPath2() });
2754
2852
  }
2755
2853
  if (pathname === "/api/memories/stream" && req.method === "GET") {
2756
2854
  const stream = new ReadableStream({
@@ -2796,9 +2894,13 @@ function startServer(port) {
2796
2894
  const dashDir = resolveDashboardDir();
2797
2895
  if (existsSync3(dashDir) && (req.method === "GET" || req.method === "HEAD")) {
2798
2896
  if (pathname !== "/") {
2799
- const staticRes = serveStaticFile(join3(dashDir, pathname));
2800
- if (staticRes)
2801
- return staticRes;
2897
+ const resolvedDash = resolve3(dashDir) + sep;
2898
+ const requestedPath = resolve3(join3(dashDir, pathname));
2899
+ if (requestedPath.startsWith(resolvedDash)) {
2900
+ const staticRes = serveStaticFile(requestedPath);
2901
+ if (staticRes)
2902
+ return staticRes;
2903
+ }
2802
2904
  }
2803
2905
  const indexRes = serveStaticFile(join3(dashDir, "index.html"));
2804
2906
  if (indexRes)
@@ -2815,7 +2917,7 @@ function startServer(port) {
2815
2917
  }
2816
2918
  }
2817
2919
  });
2818
- console.log(`Mementos server listening on http://localhost:${port}`);
2920
+ console.log(`Mementos server listening on http://${hostname}:${port}`);
2819
2921
  }
2820
2922
  async function main() {
2821
2923
  const requestedPort = parsePort();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hasna/mementos",
3
- "version": "0.4.9",
3
+ "version": "0.4.11",
4
4
  "description": "Universal memory system for AI agents - CLI + MCP server + library API",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",