@memrosetta/cli 0.4.0 → 0.4.2

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.
Files changed (39) hide show
  1. package/dist/chunk-72IW6TAV.js +59 -0
  2. package/dist/chunk-MISLIVUL.js +70 -0
  3. package/dist/chunk-NU5ZJJXP.js +63 -0
  4. package/dist/chunk-SEPYQK3J.js +60 -0
  5. package/dist/clear-47OFIDME.js +39 -0
  6. package/dist/clear-5SZVGYBX.js +39 -0
  7. package/dist/compress-SEFTKZMU.js +33 -0
  8. package/dist/compress-YNY6YNFU.js +33 -0
  9. package/dist/count-AMSEVDWR.js +24 -0
  10. package/dist/count-Z67KBEMV.js +24 -0
  11. package/dist/feedback-QDOWDWHM.js +40 -0
  12. package/dist/feedback-XGBKFQXC.js +40 -0
  13. package/dist/get-NY5H3MUA.js +30 -0
  14. package/dist/hooks/on-prompt.js +2 -2
  15. package/dist/hooks/on-stop.js +2 -2
  16. package/dist/index.js +35 -18
  17. package/dist/ingest-GSJMWDV5.js +95 -0
  18. package/dist/ingest-TZEVA25F.js +95 -0
  19. package/dist/init-GRVRJ6RO.js +205 -0
  20. package/dist/init-LK4UQISR.js +205 -0
  21. package/dist/invalidate-BY5VNFSE.js +25 -0
  22. package/dist/maintain-SGM56XKE.js +37 -0
  23. package/dist/maintain-VX2VWB2L.js +37 -0
  24. package/dist/relate-L5464WV5.js +47 -0
  25. package/dist/relate-SGZLG7JU.js +47 -0
  26. package/dist/reset-CYY4KYAB.js +129 -0
  27. package/dist/search-BJ2YV5IS.js +48 -0
  28. package/dist/search-PT4POELX.js +48 -0
  29. package/dist/status-TVY32MZD.js +218 -0
  30. package/dist/store-2USP33HQ.js +91 -0
  31. package/dist/store-XCFYGYBE.js +91 -0
  32. package/dist/sync-643GTA5X.js +319 -0
  33. package/dist/sync-7TONPJBY.js +351 -0
  34. package/dist/sync-BPVMHW34.js +319 -0
  35. package/dist/sync-OZQLBYT2.js +317 -0
  36. package/dist/sync-WURX2HJZ.js +321 -0
  37. package/dist/working-memory-UYVEJJYW.js +53 -0
  38. package/dist/working-memory-VP6L2QV6.js +53 -0
  39. package/package.json +5 -4
@@ -0,0 +1,59 @@
1
+ import {
2
+ getConfig
3
+ } from "./chunk-SEPYQK3J.js";
4
+
5
+ // src/engine.ts
6
+ import { join, dirname } from "path";
7
+ import { homedir } from "os";
8
+ import { mkdirSync, existsSync } from "fs";
9
+ var DEFAULT_DB = join(homedir(), ".memrosetta", "memories.db");
10
+ var cachedEngine = null;
11
+ var cachedDbPath = null;
12
+ async function createEngineInstance(options) {
13
+ const config = getConfig();
14
+ const dbPath = options.db ?? config.dbPath ?? DEFAULT_DB;
15
+ const dir = dirname(dbPath);
16
+ if (!existsSync(dir)) {
17
+ mkdirSync(dir, { recursive: true });
18
+ }
19
+ const { SqliteMemoryEngine } = await import("@memrosetta/core");
20
+ let embedder;
21
+ if (!options.noEmbeddings && config.enableEmbeddings !== false) {
22
+ try {
23
+ const { HuggingFaceEmbedder } = await import("@memrosetta/embeddings");
24
+ const preset = options.embeddingPreset ?? config.embeddingPreset ?? "en";
25
+ embedder = new HuggingFaceEmbedder({ preset });
26
+ await embedder.initialize();
27
+ } catch {
28
+ }
29
+ }
30
+ const engine = new SqliteMemoryEngine({ dbPath, embedder });
31
+ await engine.initialize();
32
+ return engine;
33
+ }
34
+ async function getEngine(options) {
35
+ const config = getConfig();
36
+ const dbPath = options.db ?? config.dbPath ?? DEFAULT_DB;
37
+ if (cachedEngine && cachedDbPath === dbPath) {
38
+ return cachedEngine;
39
+ }
40
+ cachedEngine = await createEngineInstance(options);
41
+ cachedDbPath = dbPath;
42
+ return cachedEngine;
43
+ }
44
+ function getDefaultDbPath() {
45
+ return DEFAULT_DB;
46
+ }
47
+ async function closeEngine() {
48
+ if (cachedEngine) {
49
+ await cachedEngine.close();
50
+ cachedEngine = null;
51
+ cachedDbPath = null;
52
+ }
53
+ }
54
+
55
+ export {
56
+ getEngine,
57
+ getDefaultDbPath,
58
+ closeEngine
59
+ };
@@ -0,0 +1,70 @@
1
+ import {
2
+ ensureDir,
3
+ getConfig
4
+ } from "./chunk-SEPYQK3J.js";
5
+
6
+ // src/hooks/engine-manager.ts
7
+ import { SqliteMemoryEngine } from "@memrosetta/core";
8
+ var engineInstance = null;
9
+ async function getEngine() {
10
+ if (engineInstance) return engineInstance;
11
+ const config = getConfig();
12
+ ensureDir();
13
+ let embedder;
14
+ if (config.enableEmbeddings) {
15
+ try {
16
+ const { HuggingFaceEmbedder } = await import("@memrosetta/embeddings");
17
+ const preset = config.embeddingPreset ?? "en";
18
+ embedder = new HuggingFaceEmbedder({ preset });
19
+ await embedder.initialize();
20
+ } catch (err) {
21
+ const message = err instanceof Error ? err.message : String(err);
22
+ process.stderr.write(
23
+ `[memrosetta] Failed to load embeddings, continuing without: ${message}
24
+ `
25
+ );
26
+ }
27
+ }
28
+ engineInstance = new SqliteMemoryEngine({
29
+ dbPath: config.dbPath,
30
+ embedder
31
+ });
32
+ await engineInstance.initialize();
33
+ return engineInstance;
34
+ }
35
+ async function closeEngine() {
36
+ if (engineInstance) {
37
+ await engineInstance.close();
38
+ engineInstance = null;
39
+ }
40
+ }
41
+ async function getEngineWithTimeout(timeoutMs) {
42
+ let timer;
43
+ const enginePromise = getEngine();
44
+ const timeoutPromise = new Promise((resolve2) => {
45
+ timer = setTimeout(() => resolve2(null), timeoutMs);
46
+ });
47
+ const result = await Promise.race([enginePromise, timeoutPromise]);
48
+ clearTimeout(timer);
49
+ return result;
50
+ }
51
+
52
+ // src/hooks/path-validation.ts
53
+ import { resolve } from "path";
54
+ import { homedir } from "os";
55
+ var CLAUDE_DIR = resolve(homedir(), ".claude");
56
+ function isValidTranscriptPath(p) {
57
+ const resolved = resolve(p);
58
+ return resolved.startsWith(CLAUDE_DIR) && resolved.endsWith(".jsonl");
59
+ }
60
+ function sanitizeSessionId(sessionId) {
61
+ return sessionId.replace(/[^a-zA-Z0-9_-]/g, "");
62
+ }
63
+
64
+ export {
65
+ getEngine,
66
+ closeEngine,
67
+ getEngineWithTimeout,
68
+ isValidTranscriptPath,
69
+ sanitizeSessionId
70
+ };
@@ -0,0 +1,63 @@
1
+ // src/parser.ts
2
+ var COMMANDS = /* @__PURE__ */ new Set([
3
+ "store",
4
+ "search",
5
+ "ingest",
6
+ "get",
7
+ "count",
8
+ "clear",
9
+ "relate",
10
+ "invalidate",
11
+ "working-memory",
12
+ "maintain",
13
+ "compress",
14
+ "status",
15
+ "init",
16
+ "reset",
17
+ "update",
18
+ "feedback",
19
+ "sync"
20
+ ]);
21
+ function findFlag(args, flag) {
22
+ return args.includes(flag);
23
+ }
24
+ function findOption(args, flag) {
25
+ const idx = args.indexOf(flag);
26
+ if (idx === -1 || idx + 1 >= args.length) return void 0;
27
+ return args[idx + 1];
28
+ }
29
+ function parseGlobalArgs(args) {
30
+ const command = args.find((a) => !a.startsWith("-") && COMMANDS.has(a));
31
+ const db = findOption(args, "--db");
32
+ const formatRaw = findOption(args, "--format");
33
+ const format = formatRaw === "json" ? "json" : "text";
34
+ const noEmbeddings = findFlag(args, "--no-embeddings");
35
+ const help = findFlag(args, "--help") || findFlag(args, "-h");
36
+ const version = findFlag(args, "--version") || findFlag(args, "-v");
37
+ const rest = args.filter((a) => a !== command);
38
+ return {
39
+ command,
40
+ global: { db, format, noEmbeddings, help, version },
41
+ rest
42
+ };
43
+ }
44
+ function requireOption(args, flag, name) {
45
+ const value = findOption(args, flag);
46
+ if (!value) {
47
+ throw new Error(`Missing required option: ${name} (${flag})`);
48
+ }
49
+ return value;
50
+ }
51
+ function optionalOption(args, flag) {
52
+ return findOption(args, flag);
53
+ }
54
+ function hasFlag(args, flag) {
55
+ return findFlag(args, flag);
56
+ }
57
+
58
+ export {
59
+ parseGlobalArgs,
60
+ requireOption,
61
+ optionalOption,
62
+ hasFlag
63
+ };
@@ -0,0 +1,60 @@
1
+ // src/hooks/config.ts
2
+ import { join } from "path";
3
+ import { homedir, userInfo } from "os";
4
+ import { mkdirSync, readFileSync, writeFileSync, existsSync, chmodSync } from "fs";
5
+ var MEMROSETTA_DIR = join(homedir(), ".memrosetta");
6
+ var CONFIG_PATH = join(MEMROSETTA_DIR, "config.json");
7
+ var DB_PATH = join(MEMROSETTA_DIR, "memories.db");
8
+ var DEFAULT_CONFIG = {
9
+ dbPath: DB_PATH,
10
+ enableEmbeddings: true,
11
+ maxRecallResults: 5,
12
+ minQueryLength: 5,
13
+ maxContextChars: 2e3
14
+ };
15
+ function getDefaultDbPath() {
16
+ return DB_PATH;
17
+ }
18
+ function ensureDir() {
19
+ if (!existsSync(MEMROSETTA_DIR)) {
20
+ mkdirSync(MEMROSETTA_DIR, { recursive: true, mode: 448 });
21
+ }
22
+ try {
23
+ chmodSync(MEMROSETTA_DIR, 448);
24
+ } catch {
25
+ }
26
+ }
27
+ function getConfig() {
28
+ if (!existsSync(CONFIG_PATH)) {
29
+ return DEFAULT_CONFIG;
30
+ }
31
+ try {
32
+ const raw = readFileSync(CONFIG_PATH, "utf-8");
33
+ const parsed = JSON.parse(raw);
34
+ return {
35
+ ...DEFAULT_CONFIG,
36
+ ...parsed
37
+ };
38
+ } catch {
39
+ return DEFAULT_CONFIG;
40
+ }
41
+ }
42
+ function writeConfig(config) {
43
+ ensureDir();
44
+ writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2), "utf-8");
45
+ try {
46
+ chmodSync(CONFIG_PATH, 384);
47
+ } catch {
48
+ }
49
+ }
50
+ function getDefaultUserId() {
51
+ return userInfo().username;
52
+ }
53
+
54
+ export {
55
+ getDefaultDbPath,
56
+ ensureDir,
57
+ getConfig,
58
+ writeConfig,
59
+ getDefaultUserId
60
+ };
@@ -0,0 +1,39 @@
1
+ import {
2
+ hasFlag,
3
+ optionalOption
4
+ } from "./chunk-VZQURGWB.js";
5
+ import {
6
+ getEngine
7
+ } from "./chunk-72IW6TAV.js";
8
+ import {
9
+ output,
10
+ outputError
11
+ } from "./chunk-ET6TNQOJ.js";
12
+ import {
13
+ getDefaultUserId
14
+ } from "./chunk-SEPYQK3J.js";
15
+
16
+ // src/commands/clear.ts
17
+ async function run(options) {
18
+ const { args, format, db, noEmbeddings } = options;
19
+ const userId = optionalOption(args, "--user") ?? getDefaultUserId();
20
+ const confirm = hasFlag(args, "--confirm");
21
+ if (!confirm) {
22
+ outputError(
23
+ "This will delete all memories for the user. Use --confirm to proceed.",
24
+ format
25
+ );
26
+ process.exitCode = 1;
27
+ return;
28
+ }
29
+ const engine = await getEngine({ db, noEmbeddings });
30
+ const countBefore = await engine.count(userId);
31
+ await engine.clear(userId);
32
+ output(
33
+ { userId, cleared: countBefore, message: `Cleared ${countBefore} memories` },
34
+ format
35
+ );
36
+ }
37
+ export {
38
+ run
39
+ };
@@ -0,0 +1,39 @@
1
+ import {
2
+ hasFlag,
3
+ optionalOption
4
+ } from "./chunk-NU5ZJJXP.js";
5
+ import {
6
+ getEngine
7
+ } from "./chunk-72IW6TAV.js";
8
+ import {
9
+ output,
10
+ outputError
11
+ } from "./chunk-ET6TNQOJ.js";
12
+ import {
13
+ getDefaultUserId
14
+ } from "./chunk-SEPYQK3J.js";
15
+
16
+ // src/commands/clear.ts
17
+ async function run(options) {
18
+ const { args, format, db, noEmbeddings } = options;
19
+ const userId = optionalOption(args, "--user") ?? getDefaultUserId();
20
+ const confirm = hasFlag(args, "--confirm");
21
+ if (!confirm) {
22
+ outputError(
23
+ "This will delete all memories for the user. Use --confirm to proceed.",
24
+ format
25
+ );
26
+ process.exitCode = 1;
27
+ return;
28
+ }
29
+ const engine = await getEngine({ db, noEmbeddings });
30
+ const countBefore = await engine.count(userId);
31
+ await engine.clear(userId);
32
+ output(
33
+ { userId, cleared: countBefore, message: `Cleared ${countBefore} memories` },
34
+ format
35
+ );
36
+ }
37
+ export {
38
+ run
39
+ };
@@ -0,0 +1,33 @@
1
+ import {
2
+ optionalOption
3
+ } from "./chunk-VZQURGWB.js";
4
+ import {
5
+ getEngine
6
+ } from "./chunk-72IW6TAV.js";
7
+ import {
8
+ output
9
+ } from "./chunk-ET6TNQOJ.js";
10
+ import {
11
+ getDefaultUserId
12
+ } from "./chunk-SEPYQK3J.js";
13
+
14
+ // src/commands/compress.ts
15
+ async function run(options) {
16
+ const { args, format, db, noEmbeddings } = options;
17
+ const userId = optionalOption(args, "--user") ?? getDefaultUserId();
18
+ const engine = await getEngine({ db, noEmbeddings });
19
+ const result = await engine.compress(userId);
20
+ if (format === "text") {
21
+ process.stdout.write(`Compression completed for user: ${userId}
22
+ `);
23
+ process.stdout.write(` Groups compressed: ${result.compressed}
24
+ `);
25
+ process.stdout.write(` Memories archived: ${result.removed}
26
+ `);
27
+ return;
28
+ }
29
+ output({ userId, ...result }, format);
30
+ }
31
+ export {
32
+ run
33
+ };
@@ -0,0 +1,33 @@
1
+ import {
2
+ optionalOption
3
+ } from "./chunk-NU5ZJJXP.js";
4
+ import {
5
+ getEngine
6
+ } from "./chunk-72IW6TAV.js";
7
+ import {
8
+ output
9
+ } from "./chunk-ET6TNQOJ.js";
10
+ import {
11
+ getDefaultUserId
12
+ } from "./chunk-SEPYQK3J.js";
13
+
14
+ // src/commands/compress.ts
15
+ async function run(options) {
16
+ const { args, format, db, noEmbeddings } = options;
17
+ const userId = optionalOption(args, "--user") ?? getDefaultUserId();
18
+ const engine = await getEngine({ db, noEmbeddings });
19
+ const result = await engine.compress(userId);
20
+ if (format === "text") {
21
+ process.stdout.write(`Compression completed for user: ${userId}
22
+ `);
23
+ process.stdout.write(` Groups compressed: ${result.compressed}
24
+ `);
25
+ process.stdout.write(` Memories archived: ${result.removed}
26
+ `);
27
+ return;
28
+ }
29
+ output({ userId, ...result }, format);
30
+ }
31
+ export {
32
+ run
33
+ };
@@ -0,0 +1,24 @@
1
+ import {
2
+ optionalOption
3
+ } from "./chunk-NU5ZJJXP.js";
4
+ import {
5
+ getEngine
6
+ } from "./chunk-72IW6TAV.js";
7
+ import {
8
+ output
9
+ } from "./chunk-ET6TNQOJ.js";
10
+ import {
11
+ getDefaultUserId
12
+ } from "./chunk-SEPYQK3J.js";
13
+
14
+ // src/commands/count.ts
15
+ async function run(options) {
16
+ const { args, format, db, noEmbeddings } = options;
17
+ const userId = optionalOption(args, "--user") ?? getDefaultUserId();
18
+ const engine = await getEngine({ db, noEmbeddings });
19
+ const count = await engine.count(userId);
20
+ output({ userId, count }, format);
21
+ }
22
+ export {
23
+ run
24
+ };
@@ -0,0 +1,24 @@
1
+ import {
2
+ optionalOption
3
+ } from "./chunk-VZQURGWB.js";
4
+ import {
5
+ getEngine
6
+ } from "./chunk-72IW6TAV.js";
7
+ import {
8
+ output
9
+ } from "./chunk-ET6TNQOJ.js";
10
+ import {
11
+ getDefaultUserId
12
+ } from "./chunk-SEPYQK3J.js";
13
+
14
+ // src/commands/count.ts
15
+ async function run(options) {
16
+ const { args, format, db, noEmbeddings } = options;
17
+ const userId = optionalOption(args, "--user") ?? getDefaultUserId();
18
+ const engine = await getEngine({ db, noEmbeddings });
19
+ const count = await engine.count(userId);
20
+ output({ userId, count }, format);
21
+ }
22
+ export {
23
+ run
24
+ };
@@ -0,0 +1,40 @@
1
+ import {
2
+ hasFlag
3
+ } from "./chunk-VZQURGWB.js";
4
+ import {
5
+ getEngine
6
+ } from "./chunk-72IW6TAV.js";
7
+ import {
8
+ output,
9
+ outputError
10
+ } from "./chunk-ET6TNQOJ.js";
11
+ import "./chunk-SEPYQK3J.js";
12
+
13
+ // src/commands/feedback.ts
14
+ async function run(options) {
15
+ const { args, format, db, noEmbeddings } = options;
16
+ const memoryId = args.find((a) => !a.startsWith("-"));
17
+ if (!memoryId) {
18
+ outputError("Usage: memrosetta feedback <memoryId> --helpful | --not-helpful", format);
19
+ process.exitCode = 1;
20
+ return;
21
+ }
22
+ const helpful = hasFlag(args, "--helpful");
23
+ const notHelpful = hasFlag(args, "--not-helpful");
24
+ if (!helpful && !notHelpful) {
25
+ outputError("Specify --helpful or --not-helpful", format);
26
+ process.exitCode = 1;
27
+ return;
28
+ }
29
+ if (helpful && notHelpful) {
30
+ outputError("Specify either --helpful or --not-helpful, not both", format);
31
+ process.exitCode = 1;
32
+ return;
33
+ }
34
+ const engine = await getEngine({ db, noEmbeddings });
35
+ await engine.feedback(memoryId, helpful);
36
+ output({ memoryId, helpful }, format);
37
+ }
38
+ export {
39
+ run
40
+ };
@@ -0,0 +1,40 @@
1
+ import {
2
+ hasFlag
3
+ } from "./chunk-NU5ZJJXP.js";
4
+ import {
5
+ getEngine
6
+ } from "./chunk-72IW6TAV.js";
7
+ import {
8
+ output,
9
+ outputError
10
+ } from "./chunk-ET6TNQOJ.js";
11
+ import "./chunk-SEPYQK3J.js";
12
+
13
+ // src/commands/feedback.ts
14
+ async function run(options) {
15
+ const { args, format, db, noEmbeddings } = options;
16
+ const memoryId = args.find((a) => !a.startsWith("-"));
17
+ if (!memoryId) {
18
+ outputError("Usage: memrosetta feedback <memoryId> --helpful | --not-helpful", format);
19
+ process.exitCode = 1;
20
+ return;
21
+ }
22
+ const helpful = hasFlag(args, "--helpful");
23
+ const notHelpful = hasFlag(args, "--not-helpful");
24
+ if (!helpful && !notHelpful) {
25
+ outputError("Specify --helpful or --not-helpful", format);
26
+ process.exitCode = 1;
27
+ return;
28
+ }
29
+ if (helpful && notHelpful) {
30
+ outputError("Specify either --helpful or --not-helpful, not both", format);
31
+ process.exitCode = 1;
32
+ return;
33
+ }
34
+ const engine = await getEngine({ db, noEmbeddings });
35
+ await engine.feedback(memoryId, helpful);
36
+ output({ memoryId, helpful }, format);
37
+ }
38
+ export {
39
+ run
40
+ };
@@ -0,0 +1,30 @@
1
+ import {
2
+ getEngine
3
+ } from "./chunk-72IW6TAV.js";
4
+ import {
5
+ output,
6
+ outputError
7
+ } from "./chunk-ET6TNQOJ.js";
8
+ import "./chunk-SEPYQK3J.js";
9
+
10
+ // src/commands/get.ts
11
+ async function run(options) {
12
+ const { args, format, db, noEmbeddings } = options;
13
+ const memoryId = args.find((a) => !a.startsWith("-") && a !== "get");
14
+ if (!memoryId) {
15
+ outputError("Missing memory ID. Usage: memrosetta get <memory-id>", format);
16
+ process.exitCode = 1;
17
+ return;
18
+ }
19
+ const engine = await getEngine({ db, noEmbeddings });
20
+ const memory = await engine.getById(memoryId);
21
+ if (!memory) {
22
+ outputError(`Memory not found: ${memoryId}`, format);
23
+ process.exitCode = 1;
24
+ return;
25
+ }
26
+ output(memory, format);
27
+ }
28
+ export {
29
+ run
30
+ };
@@ -4,7 +4,7 @@ import {
4
4
  getEngineWithTimeout,
5
5
  isValidTranscriptPath,
6
6
  sanitizeSessionId
7
- } from "../chunk-XL6EHACB.js";
7
+ } from "../chunk-MISLIVUL.js";
8
8
  import {
9
9
  extractMemories,
10
10
  parseTranscript,
@@ -13,7 +13,7 @@ import {
13
13
  } from "../chunk-KR63XYFW.js";
14
14
  import {
15
15
  getConfig
16
- } from "../chunk-TU5EHSDE.js";
16
+ } from "../chunk-SEPYQK3J.js";
17
17
 
18
18
  // src/hooks/on-prompt.ts
19
19
  import { existsSync, statSync } from "fs";
@@ -4,7 +4,7 @@ import {
4
4
  getEngine,
5
5
  isValidTranscriptPath,
6
6
  sanitizeSessionId
7
- } from "../chunk-XL6EHACB.js";
7
+ } from "../chunk-MISLIVUL.js";
8
8
  import {
9
9
  extractMemories,
10
10
  parseTranscript,
@@ -12,7 +12,7 @@ import {
12
12
  } from "../chunk-KR63XYFW.js";
13
13
  import {
14
14
  getConfig
15
- } from "../chunk-TU5EHSDE.js";
15
+ } from "../chunk-SEPYQK3J.js";
16
16
 
17
17
  // src/hooks/on-stop.ts
18
18
  import { existsSync } from "fs";