@memrosetta/cli 0.4.7 → 0.5.0

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 (43) hide show
  1. package/dist/chunk-2MO65JLK.js +139 -0
  2. package/dist/chunk-5PH2RDAS.js +750 -0
  3. package/dist/chunk-IKIJVRHU.js +16 -0
  4. package/dist/chunk-PMQKXYS6.js +752 -0
  5. package/dist/chunk-SYPVELIW.js +64 -0
  6. package/dist/chunk-TSA67QME.js +56 -0
  7. package/dist/chunk-UKGD7QXV.js +81 -0
  8. package/dist/chunk-UOT33X3Q.js +750 -0
  9. package/dist/chunk-VR3TRSC7.js +148 -0
  10. package/dist/clear-HNVVALWL.js +39 -0
  11. package/dist/compress-VZJHSVJK.js +33 -0
  12. package/dist/count-WRCFIWWS.js +24 -0
  13. package/dist/enforce-PHO4L7C2.js +381 -0
  14. package/dist/feedback-JXSKOFRS.js +51 -0
  15. package/dist/feedback-O6NKG46O.js +51 -0
  16. package/dist/hooks/enforce-claude-code.js +119 -0
  17. package/dist/hooks/on-prompt.js +9 -5
  18. package/dist/hooks/on-stop.js +8 -4
  19. package/dist/index.js +22 -16
  20. package/dist/ingest-JWLBIFEI.js +97 -0
  21. package/dist/init-ARU2CIOH.js +205 -0
  22. package/dist/init-C2MCDVWL.js +205 -0
  23. package/dist/init-LIWL7Y3H.js +205 -0
  24. package/dist/init-VUJX3RRW.js +205 -0
  25. package/dist/invalidate-QPOV2E5U.js +40 -0
  26. package/dist/invalidate-VUHHNZUX.js +40 -0
  27. package/dist/maintain-UUZ76QET.js +37 -0
  28. package/dist/relate-MIOQYWTI.js +57 -0
  29. package/dist/relate-TEZ3GIIY.js +57 -0
  30. package/dist/reset-HQFOMYVP.js +129 -0
  31. package/dist/reset-OVU4A575.js +129 -0
  32. package/dist/reset-T6DPQCWI.js +129 -0
  33. package/dist/reset-WMDSMCAR.js +129 -0
  34. package/dist/search-IXV43G2C.js +48 -0
  35. package/dist/status-BLHKHB34.js +184 -0
  36. package/dist/status-CNGR7YDV.js +184 -0
  37. package/dist/status-IHYARQXU.js +184 -0
  38. package/dist/store-DTN3PTFQ.js +101 -0
  39. package/dist/store-V7I5RJ6Y.js +101 -0
  40. package/dist/sync-EHYMBZHE.js +542 -0
  41. package/dist/sync-UJBD7575.js +542 -0
  42. package/dist/working-memory-CH524PJA.js +53 -0
  43. package/package.json +6 -5
@@ -0,0 +1,64 @@
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
+ "enforce"
21
+ ]);
22
+ function findFlag(args, flag) {
23
+ return args.includes(flag);
24
+ }
25
+ function findOption(args, flag) {
26
+ const idx = args.indexOf(flag);
27
+ if (idx === -1 || idx + 1 >= args.length) return void 0;
28
+ return args[idx + 1];
29
+ }
30
+ function parseGlobalArgs(args) {
31
+ const command = args.find((a) => !a.startsWith("-") && COMMANDS.has(a));
32
+ const db = findOption(args, "--db");
33
+ const formatRaw = findOption(args, "--format");
34
+ const format = formatRaw === "json" ? "json" : "text";
35
+ const noEmbeddings = findFlag(args, "--no-embeddings");
36
+ const help = findFlag(args, "--help") || findFlag(args, "-h");
37
+ const version = findFlag(args, "--version") || findFlag(args, "-v");
38
+ const rest = args.filter((a) => a !== command);
39
+ return {
40
+ command,
41
+ global: { db, format, noEmbeddings, help, version },
42
+ rest
43
+ };
44
+ }
45
+ function requireOption(args, flag, name) {
46
+ const value = findOption(args, flag);
47
+ if (!value) {
48
+ throw new Error(`Missing required option: ${name} (${flag})`);
49
+ }
50
+ return value;
51
+ }
52
+ function optionalOption(args, flag) {
53
+ return findOption(args, flag);
54
+ }
55
+ function hasFlag(args, flag) {
56
+ return findFlag(args, flag);
57
+ }
58
+
59
+ export {
60
+ parseGlobalArgs,
61
+ requireOption,
62
+ optionalOption,
63
+ hasFlag
64
+ };
@@ -0,0 +1,56 @@
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((resolve) => {
45
+ timer = setTimeout(() => resolve(null), timeoutMs);
46
+ });
47
+ const result = await Promise.race([enginePromise, timeoutPromise]);
48
+ clearTimeout(timer);
49
+ return result;
50
+ }
51
+
52
+ export {
53
+ getEngine,
54
+ closeEngine,
55
+ getEngineWithTimeout
56
+ };
@@ -0,0 +1,81 @@
1
+ // src/hooks/transcript-parser.ts
2
+ import { readFileSync } from "fs";
3
+ function stripSystemReminders(text) {
4
+ let result = text;
5
+ while (result.includes("<system-reminder>") && result.includes("</system-reminder>")) {
6
+ const start = result.indexOf("<system-reminder>");
7
+ const end = result.indexOf("</system-reminder>") + "</system-reminder>".length;
8
+ result = result.slice(0, start) + result.slice(end);
9
+ }
10
+ return result.trim();
11
+ }
12
+ function extractAssistantText(content) {
13
+ if (typeof content === "string") {
14
+ return content.trim();
15
+ }
16
+ if (Array.isArray(content)) {
17
+ return content.filter(
18
+ (block) => block !== null && typeof block === "object" && block.type === "text" && typeof block.text === "string"
19
+ ).map((block) => block.text).join("\n").trim();
20
+ }
21
+ return "";
22
+ }
23
+ function deduplicateTurns(turns) {
24
+ const result = [];
25
+ for (const turn of turns) {
26
+ if (result.length === 0 || result[result.length - 1].content !== turn.content) {
27
+ result.push(turn);
28
+ }
29
+ }
30
+ return result;
31
+ }
32
+ function parseTranscript(transcriptPath) {
33
+ const content = readFileSync(transcriptPath, "utf-8");
34
+ return parseTranscriptContent(content);
35
+ }
36
+ function parseTranscriptContent(content) {
37
+ const lines = content.split("\n").filter((l) => l.trim());
38
+ let cwd = "";
39
+ let sessionId = "";
40
+ const turns = [];
41
+ for (const line of lines) {
42
+ let entry;
43
+ try {
44
+ entry = JSON.parse(line);
45
+ } catch {
46
+ continue;
47
+ }
48
+ if (!cwd && entry.cwd) {
49
+ cwd = entry.cwd;
50
+ }
51
+ if (!sessionId && entry.sessionId) {
52
+ sessionId = entry.sessionId;
53
+ }
54
+ const msg = entry.message;
55
+ if (!msg || !msg.role) continue;
56
+ if (msg.role === "user" && typeof msg.content === "string") {
57
+ const clean = stripSystemReminders(msg.content);
58
+ if (clean && clean.length > 5) {
59
+ turns.push({ role: "user", content: clean });
60
+ }
61
+ } else if (msg.role === "assistant" && msg.content !== void 0) {
62
+ const text = extractAssistantText(
63
+ msg.content
64
+ );
65
+ if (text && text.length > 10) {
66
+ turns.push({ role: "assistant", content: text });
67
+ }
68
+ }
69
+ }
70
+ return {
71
+ turns: deduplicateTurns(turns),
72
+ cwd,
73
+ sessionId
74
+ };
75
+ }
76
+
77
+ export {
78
+ stripSystemReminders,
79
+ parseTranscript,
80
+ parseTranscriptContent
81
+ };