@hasna/mementos 0.4.8 → 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.
- package/dist/cli/index.js +143 -11
- package/dist/index.js +5 -5
- package/dist/lib/config.d.ts +4 -0
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/mcp/index.js +4 -4
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +99 -3
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -3059,9 +3059,9 @@ var init_relations = __esm(() => {
|
|
|
3059
3059
|
});
|
|
3060
3060
|
|
|
3061
3061
|
// src/lib/config.ts
|
|
3062
|
-
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync } from "fs";
|
|
3062
|
+
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync, readdirSync, writeFileSync, unlinkSync } from "fs";
|
|
3063
3063
|
import { homedir } from "os";
|
|
3064
|
-
import { dirname as dirname2, join as join2, resolve as resolve2 } from "path";
|
|
3064
|
+
import { basename, dirname as dirname2, join as join2, resolve as resolve2 } from "path";
|
|
3065
3065
|
function deepMerge(target, source) {
|
|
3066
3066
|
const result = { ...target };
|
|
3067
3067
|
for (const key of Object.keys(source)) {
|
|
@@ -3108,6 +3108,63 @@ function loadConfig() {
|
|
|
3108
3108
|
}
|
|
3109
3109
|
return merged;
|
|
3110
3110
|
}
|
|
3111
|
+
function profilesDir() {
|
|
3112
|
+
return join2(homedir(), ".mementos", "profiles");
|
|
3113
|
+
}
|
|
3114
|
+
function globalConfigPath() {
|
|
3115
|
+
return join2(homedir(), ".mementos", "config.json");
|
|
3116
|
+
}
|
|
3117
|
+
function readGlobalConfig() {
|
|
3118
|
+
const p = globalConfigPath();
|
|
3119
|
+
if (!existsSync2(p))
|
|
3120
|
+
return {};
|
|
3121
|
+
try {
|
|
3122
|
+
return JSON.parse(readFileSync(p, "utf-8"));
|
|
3123
|
+
} catch {
|
|
3124
|
+
return {};
|
|
3125
|
+
}
|
|
3126
|
+
}
|
|
3127
|
+
function writeGlobalConfig(data) {
|
|
3128
|
+
const p = globalConfigPath();
|
|
3129
|
+
ensureDir2(dirname2(p));
|
|
3130
|
+
writeFileSync(p, JSON.stringify(data, null, 2), "utf-8");
|
|
3131
|
+
}
|
|
3132
|
+
function getActiveProfile() {
|
|
3133
|
+
const envProfile = process.env["MEMENTOS_PROFILE"];
|
|
3134
|
+
if (envProfile)
|
|
3135
|
+
return envProfile.trim();
|
|
3136
|
+
const cfg = readGlobalConfig();
|
|
3137
|
+
return cfg["active_profile"] || null;
|
|
3138
|
+
}
|
|
3139
|
+
function setActiveProfile(name) {
|
|
3140
|
+
const cfg = readGlobalConfig();
|
|
3141
|
+
if (name === null) {
|
|
3142
|
+
delete cfg["active_profile"];
|
|
3143
|
+
} else {
|
|
3144
|
+
cfg["active_profile"] = name;
|
|
3145
|
+
}
|
|
3146
|
+
writeGlobalConfig(cfg);
|
|
3147
|
+
}
|
|
3148
|
+
function listProfiles() {
|
|
3149
|
+
const dir = profilesDir();
|
|
3150
|
+
if (!existsSync2(dir))
|
|
3151
|
+
return [];
|
|
3152
|
+
return readdirSync(dir).filter((f) => f.endsWith(".db")).map((f) => basename(f, ".db")).sort();
|
|
3153
|
+
}
|
|
3154
|
+
function deleteProfile(name) {
|
|
3155
|
+
const dbPath = join2(profilesDir(), `${name}.db`);
|
|
3156
|
+
if (!existsSync2(dbPath))
|
|
3157
|
+
return false;
|
|
3158
|
+
unlinkSync(dbPath);
|
|
3159
|
+
if (getActiveProfile() === name)
|
|
3160
|
+
setActiveProfile(null);
|
|
3161
|
+
return true;
|
|
3162
|
+
}
|
|
3163
|
+
function ensureDir2(dir) {
|
|
3164
|
+
if (!existsSync2(dir)) {
|
|
3165
|
+
mkdirSync2(dir, { recursive: true });
|
|
3166
|
+
}
|
|
3167
|
+
}
|
|
3111
3168
|
var DEFAULT_CONFIG, VALID_SCOPES, VALID_CATEGORIES;
|
|
3112
3169
|
var init_config = __esm(() => {
|
|
3113
3170
|
DEFAULT_CONFIG = {
|
|
@@ -3707,7 +3764,7 @@ init_memories();
|
|
|
3707
3764
|
init_agents();
|
|
3708
3765
|
init_projects();
|
|
3709
3766
|
import chalk from "chalk";
|
|
3710
|
-
import { readFileSync as readFileSync2, writeFileSync, existsSync as existsSync3, unlinkSync, accessSync, statSync, copyFileSync, mkdirSync as mkdirSync3, readdirSync, constants as fsConstants } from "fs";
|
|
3767
|
+
import { readFileSync as readFileSync2, writeFileSync as writeFileSync2, existsSync as existsSync3, unlinkSync as unlinkSync2, accessSync, statSync, copyFileSync, mkdirSync as mkdirSync3, readdirSync as readdirSync2, constants as fsConstants } from "fs";
|
|
3711
3768
|
import { dirname as dirname3, join as join3, resolve as resolve3 } from "path";
|
|
3712
3769
|
import { homedir as homedir2 } from "os";
|
|
3713
3770
|
import { fileURLToPath } from "url";
|
|
@@ -5599,7 +5656,7 @@ program2.command("history").description("List memories sorted by most recently a
|
|
|
5599
5656
|
}
|
|
5600
5657
|
});
|
|
5601
5658
|
program2.command("mcp").description("Install mementos MCP server into Claude Code, Codex, or Gemini").option("--claude", "Install into Claude Code (~/.claude/.mcp.json)").option("--codex", "Install into Codex (~/.codex/config.toml)").option("--gemini", "Install into Gemini (~/.gemini/settings.json)").option("--all", "Install into all supported agents").option("--uninstall", "Remove mementos MCP from config").action((opts) => {
|
|
5602
|
-
const { readFileSync: readFileSync3, writeFileSync:
|
|
5659
|
+
const { readFileSync: readFileSync3, writeFileSync: writeFileSync3, existsSync: fileExists } = __require("fs");
|
|
5603
5660
|
const { join: pathJoin } = __require("path");
|
|
5604
5661
|
const { homedir: getHome } = __require("os");
|
|
5605
5662
|
const home = getHome();
|
|
@@ -5629,7 +5686,7 @@ program2.command("mcp").description("Install mementos MCP server into Claude Cod
|
|
|
5629
5686
|
servers["mementos"] = { command: mementosCmd, args: [] };
|
|
5630
5687
|
}
|
|
5631
5688
|
config["mcpServers"] = servers;
|
|
5632
|
-
|
|
5689
|
+
writeFileSync3(configPath, JSON.stringify(config, null, 2) + `
|
|
5633
5690
|
`, "utf-8");
|
|
5634
5691
|
console.log(chalk.green(`${opts.uninstall ? "Removed from" : "Installed into"} Claude Code: ${configPath}`));
|
|
5635
5692
|
}
|
|
@@ -5647,7 +5704,7 @@ command = "${mementosCmd}"
|
|
|
5647
5704
|
args = []
|
|
5648
5705
|
`;
|
|
5649
5706
|
}
|
|
5650
|
-
|
|
5707
|
+
writeFileSync3(configPath, content, "utf-8");
|
|
5651
5708
|
console.log(chalk.green(`${opts.uninstall ? "Removed from" : "Installed into"} Codex: ${configPath}`));
|
|
5652
5709
|
} else {
|
|
5653
5710
|
console.log(chalk.yellow(`Codex config not found: ${configPath}`));
|
|
@@ -5666,7 +5723,7 @@ args = []
|
|
|
5666
5723
|
servers["mementos"] = { command: mementosCmd, args: [] };
|
|
5667
5724
|
}
|
|
5668
5725
|
config["mcpServers"] = servers;
|
|
5669
|
-
|
|
5726
|
+
writeFileSync3(configPath, JSON.stringify(config, null, 2) + `
|
|
5670
5727
|
`, "utf-8");
|
|
5671
5728
|
console.log(chalk.green(`${opts.uninstall ? "Removed from" : "Installed into"} Gemini: ${configPath}`));
|
|
5672
5729
|
}
|
|
@@ -5981,7 +6038,7 @@ program2.command("backup [path]").description("Backup the SQLite database to a f
|
|
|
5981
6038
|
console.log(chalk.yellow("No backups directory found."));
|
|
5982
6039
|
return;
|
|
5983
6040
|
}
|
|
5984
|
-
const files =
|
|
6041
|
+
const files = readdirSync2(backupsDir).filter((f) => f.endsWith(".db")).map((f) => {
|
|
5985
6042
|
const filePath = join3(backupsDir, f);
|
|
5986
6043
|
const st2 = statSync(filePath);
|
|
5987
6044
|
return { name: f, path: filePath, size: st2.size, mtime: st2.mtime };
|
|
@@ -6058,7 +6115,7 @@ program2.command("restore [file]").description("Restore the database from a back
|
|
|
6058
6115
|
console.error(chalk.red("No backups directory found."));
|
|
6059
6116
|
process.exit(1);
|
|
6060
6117
|
}
|
|
6061
|
-
const files =
|
|
6118
|
+
const files = readdirSync2(backupsDir).filter((f) => f.endsWith(".db")).map((f) => {
|
|
6062
6119
|
const fp = join3(backupsDir, f);
|
|
6063
6120
|
const st = statSync(fp);
|
|
6064
6121
|
return { path: fp, mtime: st.mtime };
|
|
@@ -6488,7 +6545,7 @@ function writeFileConfig(data) {
|
|
|
6488
6545
|
const dir = dirname3(configPath);
|
|
6489
6546
|
if (!existsSync3(dir))
|
|
6490
6547
|
mkdirSync3(dir, { recursive: true });
|
|
6491
|
-
|
|
6548
|
+
writeFileSync2(configPath, JSON.stringify(data, null, 2) + `
|
|
6492
6549
|
`, "utf-8");
|
|
6493
6550
|
}
|
|
6494
6551
|
program2.command("config [subcommand] [args...]").description("View or modify configuration. Subcommands: get <key>, set <key> <value>, reset [key], path").action((subcommand, args) => {
|
|
@@ -6576,7 +6633,7 @@ program2.command("config [subcommand] [args...]").description("View or modify co
|
|
|
6576
6633
|
} else {
|
|
6577
6634
|
const configPath = getConfigPath();
|
|
6578
6635
|
if (existsSync3(configPath)) {
|
|
6579
|
-
|
|
6636
|
+
unlinkSync2(configPath);
|
|
6580
6637
|
}
|
|
6581
6638
|
if (useJson) {
|
|
6582
6639
|
outputJson({ reset: true, all: true });
|
|
@@ -6994,4 +7051,79 @@ function sendNotification(m) {
|
|
|
6994
7051
|
execSync(`osascript -e 'display notification "${escaped}" with title "${title}"'`, { stdio: "ignore", timeout: 2000 });
|
|
6995
7052
|
} catch {}
|
|
6996
7053
|
}
|
|
7054
|
+
var profileCmd = program2.command("profile").description("Manage memory profiles (isolated DBs per context)");
|
|
7055
|
+
profileCmd.command("list").description("List all available profiles").action(() => {
|
|
7056
|
+
const profiles = listProfiles();
|
|
7057
|
+
const active = getActiveProfile();
|
|
7058
|
+
if (profiles.length === 0) {
|
|
7059
|
+
console.log(chalk.dim("No profiles yet. Create one with: mementos profile set <name>"));
|
|
7060
|
+
return;
|
|
7061
|
+
}
|
|
7062
|
+
console.log(chalk.bold("Profiles:"));
|
|
7063
|
+
for (const p of profiles) {
|
|
7064
|
+
const marker = p === active ? chalk.green(" \u2713 (active)") : "";
|
|
7065
|
+
console.log(` ${p}${marker}`);
|
|
7066
|
+
}
|
|
7067
|
+
if (!active) {
|
|
7068
|
+
console.log(chalk.dim(`
|
|
7069
|
+
(no active profile \u2014 using default DB)`));
|
|
7070
|
+
}
|
|
7071
|
+
});
|
|
7072
|
+
profileCmd.command("get").description("Show the currently active profile").action(() => {
|
|
7073
|
+
const active = getActiveProfile();
|
|
7074
|
+
if (active) {
|
|
7075
|
+
console.log(chalk.green(`Active profile: ${active}`));
|
|
7076
|
+
if (!process.env["MEMENTOS_PROFILE"]) {
|
|
7077
|
+
console.log(chalk.dim("(persisted in ~/.mementos/config.json)"));
|
|
7078
|
+
} else {
|
|
7079
|
+
console.log(chalk.dim("(from MEMENTOS_PROFILE env var)"));
|
|
7080
|
+
}
|
|
7081
|
+
} else {
|
|
7082
|
+
console.log(chalk.dim("No active profile \u2014 using default DB (~/.mementos/mementos.db)"));
|
|
7083
|
+
}
|
|
7084
|
+
});
|
|
7085
|
+
profileCmd.command("set <name>").description("Switch to a named profile (creates the DB on first use)").action((name) => {
|
|
7086
|
+
const clean = name.trim().toLowerCase().replace(/[^a-z0-9_-]/g, "-");
|
|
7087
|
+
if (!clean) {
|
|
7088
|
+
console.error(chalk.red("Invalid profile name. Use letters, numbers, hyphens, underscores."));
|
|
7089
|
+
process.exit(1);
|
|
7090
|
+
}
|
|
7091
|
+
setActiveProfile(clean);
|
|
7092
|
+
console.log(chalk.green(`\u2713 Switched to profile: ${clean}`));
|
|
7093
|
+
console.log(chalk.dim(` DB: ~/.mementos/profiles/${clean}.db (created on first use)`));
|
|
7094
|
+
});
|
|
7095
|
+
profileCmd.command("unset").description("Clear the active profile (revert to default DB)").action(() => {
|
|
7096
|
+
const was = getActiveProfile();
|
|
7097
|
+
setActiveProfile(null);
|
|
7098
|
+
if (was) {
|
|
7099
|
+
console.log(chalk.green(`\u2713 Cleared profile (was: ${was})`));
|
|
7100
|
+
} else {
|
|
7101
|
+
console.log(chalk.dim("No active profile was set."));
|
|
7102
|
+
}
|
|
7103
|
+
console.log(chalk.dim(" Now using default DB: ~/.mementos/mementos.db"));
|
|
7104
|
+
});
|
|
7105
|
+
profileCmd.command("delete <name>").description("Delete a profile and its DB file (irreversible)").option("-y, --yes", "Skip confirmation prompt").action(async (name, opts) => {
|
|
7106
|
+
if (!opts.yes) {
|
|
7107
|
+
const profiles = listProfiles();
|
|
7108
|
+
if (!profiles.includes(name)) {
|
|
7109
|
+
console.error(chalk.red(`Profile not found: ${name}`));
|
|
7110
|
+
process.exit(1);
|
|
7111
|
+
}
|
|
7112
|
+
process.stdout.write(chalk.yellow(`Delete profile "${name}" and its DB? This cannot be undone. [y/N] `));
|
|
7113
|
+
const answer = await new Promise((resolve4) => {
|
|
7114
|
+
process.stdin.once("data", (d) => resolve4(d.toString().trim().toLowerCase()));
|
|
7115
|
+
});
|
|
7116
|
+
if (answer !== "y" && answer !== "yes") {
|
|
7117
|
+
console.log(chalk.dim("Cancelled."));
|
|
7118
|
+
return;
|
|
7119
|
+
}
|
|
7120
|
+
}
|
|
7121
|
+
const deleted = deleteProfile(name);
|
|
7122
|
+
if (deleted) {
|
|
7123
|
+
console.log(chalk.green(`\u2713 Profile "${name}" deleted.`));
|
|
7124
|
+
} else {
|
|
7125
|
+
console.error(chalk.red(`Profile not found: ${name}`));
|
|
7126
|
+
process.exit(1);
|
|
7127
|
+
}
|
|
7128
|
+
});
|
|
6997
7129
|
program2.parse(process.argv);
|
package/dist/index.js
CHANGED
|
@@ -1034,9 +1034,9 @@ function findPath(fromEntityId, toEntityId, maxDepth = 5, db) {
|
|
|
1034
1034
|
}
|
|
1035
1035
|
|
|
1036
1036
|
// src/lib/config.ts
|
|
1037
|
-
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync } from "fs";
|
|
1037
|
+
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync, readdirSync, writeFileSync, unlinkSync } from "fs";
|
|
1038
1038
|
import { homedir } from "os";
|
|
1039
|
-
import { dirname as dirname2, join as join2, resolve as resolve2 } from "path";
|
|
1039
|
+
import { basename, dirname as dirname2, join as join2, resolve as resolve2 } from "path";
|
|
1040
1040
|
var DEFAULT_CONFIG = {
|
|
1041
1041
|
default_scope: "private",
|
|
1042
1042
|
default_category: "knowledge",
|
|
@@ -2241,7 +2241,7 @@ function runCleanup(config, db) {
|
|
|
2241
2241
|
return { expired, evicted, archived, unused_archived, deprioritized };
|
|
2242
2242
|
}
|
|
2243
2243
|
// src/lib/sync.ts
|
|
2244
|
-
import { existsSync as existsSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync2, writeFileSync } from "fs";
|
|
2244
|
+
import { existsSync as existsSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
2245
2245
|
import { homedir as homedir2 } from "os";
|
|
2246
2246
|
import { join as join3 } from "path";
|
|
2247
2247
|
function getAgentSyncDir(agentName) {
|
|
@@ -2253,7 +2253,7 @@ function getAgentSyncDir(agentName) {
|
|
|
2253
2253
|
}
|
|
2254
2254
|
function setHighWaterMark(agentDir, timestamp) {
|
|
2255
2255
|
const markFile = join3(agentDir, ".highwatermark");
|
|
2256
|
-
|
|
2256
|
+
writeFileSync2(markFile, timestamp, "utf-8");
|
|
2257
2257
|
}
|
|
2258
2258
|
function resolveConflict(local, remote, resolution) {
|
|
2259
2259
|
switch (resolution) {
|
|
@@ -2274,7 +2274,7 @@ function pushMemories(agentName, agentId, projectId, db) {
|
|
|
2274
2274
|
limit: 1e4
|
|
2275
2275
|
}, db);
|
|
2276
2276
|
const outFile = join3(agentDir, "memories.json");
|
|
2277
|
-
|
|
2277
|
+
writeFileSync2(outFile, JSON.stringify(memories, null, 2), "utf-8");
|
|
2278
2278
|
if (memories.length > 0) {
|
|
2279
2279
|
const latest = memories.reduce((a, b) => new Date(a.updated_at).getTime() > new Date(b.updated_at).getTime() ? a : b);
|
|
2280
2280
|
setHighWaterMark(agentDir, latest.updated_at);
|
package/dist/lib/config.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type { MementosConfig } from "../types";
|
|
2
2
|
export declare const DEFAULT_CONFIG: MementosConfig;
|
|
3
3
|
export declare function loadConfig(): MementosConfig;
|
|
4
|
+
export declare function getActiveProfile(): string | null;
|
|
5
|
+
export declare function setActiveProfile(name: string | null): void;
|
|
6
|
+
export declare function listProfiles(): string[];
|
|
7
|
+
export declare function deleteProfile(name: string): boolean;
|
|
4
8
|
export declare function getDbPath(): string;
|
|
5
9
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/lib/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAA+B,MAAM,UAAU,CAAC;AAM5E,eAAO,MAAM,cAAc,EAAE,cA2B5B,CAAC;AA4DF,wBAAgB,UAAU,IAAI,cAAc,CAwC3C;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAA+B,MAAM,UAAU,CAAC;AAM5E,eAAO,MAAM,cAAc,EAAE,cA2B5B,CAAC;AA4DF,wBAAgB,UAAU,IAAI,cAAc,CAwC3C;AAwED,wBAAgB,gBAAgB,IAAI,MAAM,GAAG,IAAI,CAMhD;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAQ1D;AAED,wBAAgB,YAAY,IAAI,MAAM,EAAE,CAOvC;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAOnD;AAED,wBAAgB,SAAS,IAAI,MAAM,CAuClC"}
|
package/dist/mcp/index.js
CHANGED
|
@@ -4919,9 +4919,9 @@ function findPath(fromEntityId, toEntityId, maxDepth = 5, db) {
|
|
|
4919
4919
|
}
|
|
4920
4920
|
|
|
4921
4921
|
// src/lib/config.ts
|
|
4922
|
-
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync } from "fs";
|
|
4922
|
+
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync, readdirSync, writeFileSync, unlinkSync } from "fs";
|
|
4923
4923
|
import { homedir } from "os";
|
|
4924
|
-
import { dirname as dirname2, join as join2, resolve as resolve2 } from "path";
|
|
4924
|
+
import { basename, dirname as dirname2, join as join2, resolve as resolve2 } from "path";
|
|
4925
4925
|
var DEFAULT_CONFIG = {
|
|
4926
4926
|
default_scope: "private",
|
|
4927
4927
|
default_category: "knowledge",
|
|
@@ -5914,7 +5914,7 @@ function logSearchQuery(query, resultCount, agentId, projectId, db) {
|
|
|
5914
5914
|
|
|
5915
5915
|
// src/lib/project-detect.ts
|
|
5916
5916
|
import { existsSync as existsSync3 } from "fs";
|
|
5917
|
-
import { basename, dirname as dirname3, join as join3, resolve as resolve3 } from "path";
|
|
5917
|
+
import { basename as basename2, dirname as dirname3, join as join3, resolve as resolve3 } from "path";
|
|
5918
5918
|
function findGitRoot2(startDir) {
|
|
5919
5919
|
let dir = resolve3(startDir);
|
|
5920
5920
|
while (true) {
|
|
@@ -5938,7 +5938,7 @@ function detectProject(db) {
|
|
|
5938
5938
|
_cachedProject = null;
|
|
5939
5939
|
return null;
|
|
5940
5940
|
}
|
|
5941
|
-
const repoName =
|
|
5941
|
+
const repoName = basename2(gitRoot);
|
|
5942
5942
|
const absPath = resolve3(gitRoot);
|
|
5943
5943
|
const existing = getProject(absPath, d);
|
|
5944
5944
|
if (existing) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":";AACA;;;GAGG;
|
|
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"}
|
package/dist/server/index.js
CHANGED
|
@@ -946,9 +946,9 @@ function findPath(fromEntityId, toEntityId, maxDepth = 5, db) {
|
|
|
946
946
|
}
|
|
947
947
|
|
|
948
948
|
// src/lib/config.ts
|
|
949
|
-
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync } from "fs";
|
|
949
|
+
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync, readdirSync, writeFileSync, unlinkSync } from "fs";
|
|
950
950
|
import { homedir } from "os";
|
|
951
|
-
import { dirname as dirname2, join as join2, resolve as resolve2 } from "path";
|
|
951
|
+
import { basename, dirname as dirname2, join as join2, resolve as resolve2 } from "path";
|
|
952
952
|
var DEFAULT_CONFIG = {
|
|
953
953
|
default_scope: "private",
|
|
954
954
|
default_category: "knowledge",
|
|
@@ -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
|
-
|
|
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({
|