@memrosetta/cli 0.3.2 → 0.4.1

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 (149) hide show
  1. package/dist/chunk-356QK7TK.js +533 -0
  2. package/dist/chunk-3LSITXZ4.js +69 -0
  3. package/dist/chunk-6IOTBMUB.js +570 -0
  4. package/dist/chunk-72IW6TAV.js +59 -0
  5. package/dist/chunk-BGXZ3MDD.js +341 -0
  6. package/dist/chunk-EZVP3OY7.js +52 -0
  7. package/dist/chunk-FCHV2JMZ.js +347 -0
  8. package/dist/{chunk-F7ZMZ6HN.js → chunk-HXZ7MAT6.js} +2 -1
  9. package/dist/chunk-IM6H35RB.js +341 -0
  10. package/dist/chunk-JGE6RXXH.js +48 -0
  11. package/dist/chunk-JPBSMZ26.js +343 -0
  12. package/dist/chunk-KSKRPUZZ.js +43 -0
  13. package/dist/chunk-L6S3TXHR.js +326 -0
  14. package/dist/chunk-MISLIVUL.js +70 -0
  15. package/dist/chunk-NU5ZJJXP.js +63 -0
  16. package/dist/{chunk-326TFH4F.js → chunk-OCCU5YEG.js} +11 -42
  17. package/dist/chunk-PW52BB6L.js +61 -0
  18. package/dist/chunk-RABFL4EN.js +528 -0
  19. package/dist/chunk-RDUU53MG.js +343 -0
  20. package/dist/chunk-RYPYJJ2K.js +70 -0
  21. package/dist/chunk-SEPYQK3J.js +60 -0
  22. package/dist/{chunk-CATBN3ZT.js → chunk-TQOH7ZXN.js} +6 -18
  23. package/dist/chunk-Y6NH6K27.js +209 -0
  24. package/dist/{clear-MTL4CQM3.js → clear-47OFIDME.js} +10 -5
  25. package/dist/clear-4RQW6SYW.js +39 -0
  26. package/dist/clear-5SZVGYBX.js +39 -0
  27. package/dist/clear-BYRCL5ZN.js +39 -0
  28. package/dist/clear-ETQ7XFMV.js +39 -0
  29. package/dist/clear-P6H55OKZ.js +39 -0
  30. package/dist/clear-T3TWJQKL.js +39 -0
  31. package/dist/{compress-Z46R4N4M.js → compress-HDNYPXZ3.js} +10 -5
  32. package/dist/compress-S6MS4QW7.js +33 -0
  33. package/dist/compress-SEFTKZMU.js +33 -0
  34. package/dist/compress-TVWXLW3L.js +33 -0
  35. package/dist/compress-VLYNZ5BQ.js +33 -0
  36. package/dist/compress-YNY6YNFU.js +33 -0
  37. package/dist/compress-ZXWRRGHT.js +33 -0
  38. package/dist/{count-4TZ3C524.js → count-26AGY5XL.js} +10 -5
  39. package/dist/count-AMSEVDWR.js +24 -0
  40. package/dist/count-AVG5ZIRW.js +24 -0
  41. package/dist/count-CJIYYJKN.js +24 -0
  42. package/dist/count-KFFD4ML7.js +24 -0
  43. package/dist/count-UUAD3GEJ.js +24 -0
  44. package/dist/count-Z67KBEMV.js +24 -0
  45. package/dist/feedback-QDOWDWHM.js +40 -0
  46. package/dist/feedback-XGBKFQXC.js +40 -0
  47. package/dist/{get-B6AL75EW.js → get-75MGS4LN.js} +4 -2
  48. package/dist/get-NY5H3MUA.js +30 -0
  49. package/dist/hooks/on-prompt.js +2 -2
  50. package/dist/hooks/on-stop.js +2 -2
  51. package/dist/index.js +35 -18
  52. package/dist/ingest-A3BAI2C4.js +95 -0
  53. package/dist/ingest-E7QDD5NY.js +95 -0
  54. package/dist/ingest-GSJMWDV5.js +95 -0
  55. package/dist/ingest-IGI7RXR4.js +95 -0
  56. package/dist/ingest-JPIHSH7W.js +95 -0
  57. package/dist/ingest-QGXA4Y6C.js +95 -0
  58. package/dist/ingest-TZEVA25F.js +95 -0
  59. package/dist/init-2PRW64KV.js +146 -0
  60. package/dist/init-C3CONL23.js +146 -0
  61. package/dist/init-DAKOWQSW.js +169 -0
  62. package/dist/init-FYPMJDRN.js +146 -0
  63. package/dist/{init-C335O4TX.js → init-GCT4XEI6.js} +2 -2
  64. package/dist/init-GRVRJ6RO.js +205 -0
  65. package/dist/init-HBEIXY3N.js +146 -0
  66. package/dist/init-LK4UQISR.js +205 -0
  67. package/dist/init-MISGIVCC.js +146 -0
  68. package/dist/init-MNM4TXXJ.js +146 -0
  69. package/dist/{init-YAGOXYWG.js → init-OQW3KXTR.js} +2 -2
  70. package/dist/init-SIEKAILM.js +113 -0
  71. package/dist/init-TM7GTHTJ.js +146 -0
  72. package/dist/init-VYWOSISP.js +146 -0
  73. package/dist/init-WCL7FZOJ.js +182 -0
  74. package/dist/init-ZLUDTJAP.js +182 -0
  75. package/dist/invalidate-BY5VNFSE.js +25 -0
  76. package/dist/{invalidate-C54IVIGL.js → invalidate-D2O4VWZU.js} +4 -2
  77. package/dist/{maintain-ZPHG47YY.js → maintain-B65WIMGJ.js} +10 -5
  78. package/dist/maintain-EWOU3DGT.js +37 -0
  79. package/dist/maintain-FELKLG7O.js +37 -0
  80. package/dist/maintain-SGM56XKE.js +37 -0
  81. package/dist/maintain-VX2VWB2L.js +37 -0
  82. package/dist/maintain-WRRDXEG3.js +37 -0
  83. package/dist/maintain-XTCSOQBU.js +37 -0
  84. package/dist/{relate-R6DQUJCQ.js → relate-2QMG5H2I.js} +5 -3
  85. package/dist/relate-C22YYJZT.js +46 -0
  86. package/dist/relate-L5464WV5.js +47 -0
  87. package/dist/relate-SGZLG7JU.js +47 -0
  88. package/dist/relate-V5RYMJJ5.js +47 -0
  89. package/dist/relate-W4BXPFJA.js +46 -0
  90. package/dist/reset-45EUG44R.js +95 -0
  91. package/dist/reset-5NDHFUC3.js +95 -0
  92. package/dist/reset-C7I3LA5M.js +95 -0
  93. package/dist/reset-CYY4KYAB.js +129 -0
  94. package/dist/reset-F6F2R6BR.js +95 -0
  95. package/dist/reset-K3K4K5CT.js +95 -0
  96. package/dist/reset-K4WZJ4WU.js +95 -0
  97. package/dist/{reset-P63V46RN.js → reset-NNQQJN6L.js} +2 -2
  98. package/dist/{reset-GPV46GSD.js → reset-P5FXLI4E.js} +2 -2
  99. package/dist/reset-SORHIEKY.js +112 -0
  100. package/dist/reset-SVJMWYAK.js +95 -0
  101. package/dist/reset-W22RJGYZ.js +112 -0
  102. package/dist/reset-W3QVA632.js +95 -0
  103. package/dist/reset-WYEU6XJQ.js +112 -0
  104. package/dist/{search-YEYKOEXC.js → search-2SU5WQYK.js} +9 -4
  105. package/dist/search-5EE3XB2R.js +48 -0
  106. package/dist/search-BJ2YV5IS.js +48 -0
  107. package/dist/search-L6P3XY47.js +48 -0
  108. package/dist/search-PT4POELX.js +48 -0
  109. package/dist/search-UA7Y55LQ.js +48 -0
  110. package/dist/search-ZKLRJXFT.js +48 -0
  111. package/dist/status-3XVXJF7M.js +170 -0
  112. package/dist/status-4THJLSJL.js +131 -0
  113. package/dist/status-4UYY7TOE.js +131 -0
  114. package/dist/status-7G3RMR6A.js +139 -0
  115. package/dist/status-7M4TJVDH.js +170 -0
  116. package/dist/status-7MEEKEC2.js +131 -0
  117. package/dist/status-BQL4VJ6Y.js +149 -0
  118. package/dist/status-BTEVCZ5K.js +125 -0
  119. package/dist/status-F3NZGGPH.js +131 -0
  120. package/dist/status-GQMXOMRN.js +131 -0
  121. package/dist/status-HJGTMHTD.js +131 -0
  122. package/dist/{status-AMMF6QGI.js → status-IEKR6SSH.js} +35 -6
  123. package/dist/status-JJGVWESB.js +139 -0
  124. package/dist/status-LDVRVYZH.js +131 -0
  125. package/dist/{status-XNQRRFWF.js → status-TATIX3R6.js} +1 -1
  126. package/dist/{status-PYD6U7U7.js → status-TVY32MZD.js} +10 -3
  127. package/dist/{store-ZMERYHI6.js → store-2USP33HQ.js} +12 -7
  128. package/dist/store-6D5OJ2DX.js +91 -0
  129. package/dist/store-I4JNJWAZ.js +91 -0
  130. package/dist/store-R4LXYE57.js +91 -0
  131. package/dist/store-UMR2NOT7.js +91 -0
  132. package/dist/store-XCFYGYBE.js +91 -0
  133. package/dist/store-ZDI5AH4M.js +91 -0
  134. package/dist/sync-643GTA5X.js +319 -0
  135. package/dist/sync-BPVMHW34.js +319 -0
  136. package/dist/sync-OZQLBYT2.js +317 -0
  137. package/dist/sync-WURX2HJZ.js +321 -0
  138. package/dist/update-XJLMXCDZ.js +36 -0
  139. package/dist/{working-memory-2RRQFX4Q.js → working-memory-2U33JHJB.js} +10 -6
  140. package/dist/working-memory-35TMFU3P.js +53 -0
  141. package/dist/working-memory-IBWGIXLW.js +53 -0
  142. package/dist/working-memory-RZE3GYQZ.js +53 -0
  143. package/dist/working-memory-UYVEJJYW.js +53 -0
  144. package/dist/working-memory-VP6L2QV6.js +53 -0
  145. package/dist/working-memory-WGB5DZ3B.js +53 -0
  146. package/package.json +5 -4
  147. package/dist/chunk-MWLPPS7U.js +0 -133
  148. package/dist/ingest-ZOR3XSAE.js +0 -152
  149. package/dist/init-7VFBCA4O.js +0 -26
@@ -0,0 +1,533 @@
1
+ // src/integrations/claude-code.ts
2
+ import { join as join2 } from "path";
3
+ import { homedir } from "os";
4
+ import { existsSync as existsSync2, readFileSync, writeFileSync } from "fs";
5
+
6
+ // src/integrations/resolve-command.ts
7
+ import { execSync } from "child_process";
8
+ import { createRequire } from "module";
9
+ import { join, dirname } from "path";
10
+ import { existsSync } from "fs";
11
+ function isInPath(command) {
12
+ try {
13
+ const cmd = process.platform === "win32" ? `where ${command}` : `command -v ${command}`;
14
+ execSync(cmd, { stdio: "ignore" });
15
+ return true;
16
+ } catch {
17
+ return false;
18
+ }
19
+ }
20
+ function resolveMcpCommand() {
21
+ if (isInPath("memrosetta-mcp")) {
22
+ return { command: "memrosetta-mcp", args: [] };
23
+ }
24
+ try {
25
+ const require2 = createRequire(import.meta.url);
26
+ const mcpPkgPath = dirname(
27
+ require2.resolve("@memrosetta/mcp/package.json")
28
+ );
29
+ const entryPoint = join(mcpPkgPath, "dist", "index.js");
30
+ if (existsSync(entryPoint)) {
31
+ return { command: "node", args: [entryPoint] };
32
+ }
33
+ } catch {
34
+ }
35
+ return { command: "memrosetta-mcp", args: [] };
36
+ }
37
+ function resolveHookCommand(hookName) {
38
+ if (isInPath(hookName)) {
39
+ return hookName;
40
+ }
41
+ try {
42
+ const require2 = createRequire(import.meta.url);
43
+ const hookFile = hookName === "memrosetta-on-stop" ? "hooks/on-stop.js" : "hooks/on-prompt.js";
44
+ const cliPkgPath = dirname(
45
+ require2.resolve("@memrosetta/cli/package.json")
46
+ );
47
+ const entryPoint = join(cliPkgPath, "dist", hookFile);
48
+ if (existsSync(entryPoint)) {
49
+ return `node ${entryPoint}`;
50
+ }
51
+ } catch {
52
+ }
53
+ return hookName;
54
+ }
55
+
56
+ // src/integrations/claude-code.ts
57
+ var CLAUDE_DIR = join2(homedir(), ".claude");
58
+ var CLAUDE_SETTINGS_PATH = join2(CLAUDE_DIR, "settings.json");
59
+ var CLAUDE_MD_PATH = join2(CLAUDE_DIR, "CLAUDE.md");
60
+ function isMemrosettaHook(command) {
61
+ return command.includes("memrosetta") && (command.includes("on-stop") || command.includes("on-prompt"));
62
+ }
63
+ function readClaudeSettings() {
64
+ if (!existsSync2(CLAUDE_SETTINGS_PATH)) return {};
65
+ try {
66
+ return JSON.parse(
67
+ readFileSync(CLAUDE_SETTINGS_PATH, "utf-8")
68
+ );
69
+ } catch {
70
+ return {};
71
+ }
72
+ }
73
+ function writeClaudeSettings(settings) {
74
+ if (!existsSync2(CLAUDE_DIR)) {
75
+ throw new Error(
76
+ "~/.claude directory does not exist. Is Claude Code installed?"
77
+ );
78
+ }
79
+ writeFileSync(
80
+ CLAUDE_SETTINGS_PATH,
81
+ JSON.stringify(settings, null, 2),
82
+ "utf-8"
83
+ );
84
+ }
85
+ function removeMemrosettaHooksFromSettings(settings) {
86
+ if (!settings.hooks) return settings;
87
+ const cleaned = {};
88
+ for (const [eventType, hookConfigs] of Object.entries(settings.hooks)) {
89
+ const filtered = hookConfigs.filter(
90
+ (hc) => !hc.hooks.some((h) => isMemrosettaHook(h.command))
91
+ );
92
+ cleaned[eventType] = filtered;
93
+ }
94
+ return { ...settings, hooks: cleaned };
95
+ }
96
+ function isClaudeCodeInstalled() {
97
+ return existsSync2(CLAUDE_DIR);
98
+ }
99
+ function isClaudeCodeConfigured() {
100
+ const settings = readClaudeSettings();
101
+ const stopHooks = settings.hooks?.["Stop"] || [];
102
+ return stopHooks.some(
103
+ (hc) => hc.hooks.some((h) => isMemrosettaHook(h.command))
104
+ );
105
+ }
106
+ function registerClaudeCodeHooks() {
107
+ if (!isClaudeCodeInstalled()) return false;
108
+ let settings = readClaudeSettings();
109
+ if (!settings.hooks) {
110
+ settings = { ...settings, hooks: {} };
111
+ }
112
+ settings = removeMemrosettaHooksFromSettings(settings);
113
+ const stopHookConfigs = settings.hooks["Stop"] || [];
114
+ settings.hooks["Stop"] = [
115
+ ...stopHookConfigs,
116
+ {
117
+ matcher: "*",
118
+ hooks: [
119
+ {
120
+ type: "command",
121
+ command: resolveHookCommand("memrosetta-on-stop"),
122
+ timeout: 15
123
+ }
124
+ ]
125
+ }
126
+ ];
127
+ writeClaudeSettings(settings);
128
+ return true;
129
+ }
130
+ function removeClaudeCodeHooks() {
131
+ if (!existsSync2(CLAUDE_SETTINGS_PATH)) return false;
132
+ const settings = readClaudeSettings();
133
+ if (!settings.hooks) return false;
134
+ const cleaned = removeMemrosettaHooksFromSettings(settings);
135
+ writeClaudeSettings(cleaned);
136
+ return true;
137
+ }
138
+ function updateClaudeMd() {
139
+ if (!isClaudeCodeInstalled()) return false;
140
+ const marker = "## MemRosetta (Long-term Memory)";
141
+ const existing = existsSync2(CLAUDE_MD_PATH) ? readFileSync(CLAUDE_MD_PATH, "utf-8") : "";
142
+ if (existing.includes(marker)) return false;
143
+ const memorySection = `
144
+
145
+ ${marker}
146
+
147
+ MCP server \`memory-service\` provides long-term memory across sessions.
148
+ userId defaults to the system username -- no need to specify it.
149
+
150
+ ### Search (mcp__memory-service__memrosetta_search)
151
+ When you need information not in the current context, search past memories.
152
+ No need to specify userId -- it defaults to the system username.
153
+
154
+ ### Store (mcp__memory-service__memrosetta_store)
155
+
156
+ **After EVERY response, run this checklist (zero extra cost):**
157
+ 1. Did I encounter a DECISION? (tech choice, approach selection) -> store as "decision"
158
+ 2. Did I learn a new FACT? (config, architecture, project info) -> store as "fact"
159
+ 3. Did the user state a PREFERENCE? (style, tool choice, pattern) -> store as "preference"
160
+ 4. Did we COMPLETE something? (deploy, migration, fix) -> store as "event"
161
+ 5. None of the above? -> skip, do not store.
162
+
163
+ Always include 2-3 keywords. Example:
164
+ content: "Decided to use OAuth2 with PKCE for auth"
165
+ type: "decision"
166
+ keywords: "auth, oauth2, pkce"
167
+
168
+ Do NOT store:
169
+ - Code itself (belongs in git)
170
+ - File operations ("Created file X", "Modified Y")
171
+ - Debugging steps and attempts
172
+ - Simple confirmations or acknowledgments
173
+ - Implementation details (HOW you did it -- only WHAT)
174
+
175
+ This checklist ensures nothing important is lost, including the last response before session ends.
176
+ No need to specify userId -- it defaults to the system username.
177
+ `;
178
+ writeFileSync(CLAUDE_MD_PATH, existing + memorySection, "utf-8");
179
+ return true;
180
+ }
181
+ function removeClaudeMdSection() {
182
+ if (!existsSync2(CLAUDE_MD_PATH)) return false;
183
+ const content = readFileSync(CLAUDE_MD_PATH, "utf-8");
184
+ const marker = "## MemRosetta (Long-term Memory)";
185
+ const markerIdx = content.indexOf(marker);
186
+ if (markerIdx === -1) return false;
187
+ const afterMarker = content.slice(markerIdx + marker.length);
188
+ const nextHeadingMatch = afterMarker.match(/\n## (?!MemRosetta)/);
189
+ const endIdx = nextHeadingMatch ? markerIdx + marker.length + (nextHeadingMatch.index ?? afterMarker.length) : content.length;
190
+ const before = content.slice(0, markerIdx).replace(/\n+$/, "");
191
+ const after = content.slice(endIdx);
192
+ const updated = (before + after).trimEnd() + "\n";
193
+ writeFileSync(CLAUDE_MD_PATH, updated, "utf-8");
194
+ return true;
195
+ }
196
+
197
+ // src/integrations/mcp.ts
198
+ import { join as join3 } from "path";
199
+ import { homedir as homedir2 } from "os";
200
+ import { existsSync as existsSync3, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
201
+ var MCP_CONFIG_PATH = join3(homedir2(), ".mcp.json");
202
+ var SERVER_NAME = "memory-service";
203
+ function readMcpConfig(path) {
204
+ if (!existsSync3(path)) return {};
205
+ try {
206
+ return JSON.parse(readFileSync2(path, "utf-8"));
207
+ } catch {
208
+ return {};
209
+ }
210
+ }
211
+ function writeMcpConfig(path, config) {
212
+ writeFileSync2(path, JSON.stringify(config, null, 2), "utf-8");
213
+ }
214
+ function mcpServerEntry() {
215
+ const { command, args } = resolveMcpCommand();
216
+ return { command, args };
217
+ }
218
+ function isGenericMCPConfigured() {
219
+ const config = readMcpConfig(MCP_CONFIG_PATH);
220
+ return !!config.mcpServers?.[SERVER_NAME];
221
+ }
222
+ function registerGenericMCP() {
223
+ const config = readMcpConfig(MCP_CONFIG_PATH);
224
+ const servers = config.mcpServers ?? {};
225
+ writeMcpConfig(MCP_CONFIG_PATH, {
226
+ ...config,
227
+ mcpServers: { ...servers, [SERVER_NAME]: mcpServerEntry() }
228
+ });
229
+ }
230
+ function removeGenericMCP() {
231
+ if (!existsSync3(MCP_CONFIG_PATH)) return false;
232
+ const config = readMcpConfig(MCP_CONFIG_PATH);
233
+ if (!config.mcpServers?.[SERVER_NAME]) return false;
234
+ const { [SERVER_NAME]: _, ...rest } = config.mcpServers;
235
+ writeMcpConfig(MCP_CONFIG_PATH, { ...config, mcpServers: rest });
236
+ return true;
237
+ }
238
+ function getGenericMCPPath() {
239
+ return MCP_CONFIG_PATH;
240
+ }
241
+
242
+ // src/integrations/cursor.ts
243
+ import { join as join4 } from "path";
244
+ import { homedir as homedir3 } from "os";
245
+ import { existsSync as existsSync4, readFileSync as readFileSync3, writeFileSync as writeFileSync3, mkdirSync } from "fs";
246
+ var SERVER_NAME2 = "memory-service";
247
+ var CURSOR_RULES_PATH_GETTER = () => join4(homedir3(), ".cursorrules");
248
+ var MEMROSETTA_CURSOR_RULES_MARKER = "## MemRosetta (Long-term Memory)";
249
+ var MEMROSETTA_CURSOR_RULES = `
250
+
251
+ ${MEMROSETTA_CURSOR_RULES_MARKER}
252
+
253
+ MCP server \`memory-service\` provides persistent memory across sessions.
254
+ userId defaults to the system username -- no need to specify it.
255
+
256
+ ### When to search (memrosetta_search)
257
+ When you need information not in the current context, search past memories.
258
+ No need to specify userId -- it defaults to the system username.
259
+
260
+ ### When to store (memrosetta_store)
261
+
262
+ **After EVERY response, run this checklist (zero extra cost):**
263
+ 1. Did I encounter a DECISION? (tech choice, approach selection) -> store as "decision"
264
+ 2. Did I learn a new FACT? (config, architecture, project info) -> store as "fact"
265
+ 3. Did the user state a PREFERENCE? (style, tool choice, pattern) -> store as "preference"
266
+ 4. Did we COMPLETE something? (deploy, migration, fix) -> store as "event"
267
+ 5. None of the above? -> skip, do not store.
268
+
269
+ Always include 2-3 keywords. Example:
270
+ content: "Decided to use OAuth2 with PKCE for auth"
271
+ type: "decision"
272
+ keywords: "auth, oauth2, pkce"
273
+
274
+ Do NOT store:
275
+ - Code itself (belongs in git)
276
+ - File operations ("Created file X", "Modified Y")
277
+ - Debugging steps and attempts
278
+ - Simple confirmations or acknowledgments
279
+ - Implementation details (HOW you did it -- only WHAT)
280
+
281
+ This checklist ensures nothing important is lost, including the last response before session ends.
282
+ No need to specify userId -- it defaults to the system username.
283
+
284
+ ### When to relate (memrosetta_relate)
285
+ When new information updates or contradicts existing memories, create a relation.
286
+
287
+ ### Working memory (memrosetta_working_memory)
288
+ Call this at the start of complex tasks to load relevant context.
289
+ No need to specify userId -- it defaults to the system username.
290
+ `;
291
+ function getCursorConfigDir() {
292
+ return join4(homedir3(), ".cursor");
293
+ }
294
+ function getCursorMcpPath() {
295
+ return join4(getCursorConfigDir(), "mcp.json");
296
+ }
297
+ function readCursorConfig(path) {
298
+ if (!existsSync4(path)) return {};
299
+ try {
300
+ return JSON.parse(readFileSync3(path, "utf-8"));
301
+ } catch {
302
+ return {};
303
+ }
304
+ }
305
+ function writeCursorConfig(path, config) {
306
+ const dir = getCursorConfigDir();
307
+ if (!existsSync4(dir)) {
308
+ mkdirSync(dir, { recursive: true });
309
+ }
310
+ writeFileSync3(path, JSON.stringify(config, null, 2), "utf-8");
311
+ }
312
+ function mcpServerEntry2() {
313
+ const { command, args } = resolveMcpCommand();
314
+ return { command, args };
315
+ }
316
+ function isCursorConfigured() {
317
+ const path = getCursorMcpPath();
318
+ const config = readCursorConfig(path);
319
+ return !!config.mcpServers?.[SERVER_NAME2];
320
+ }
321
+ function registerCursorMCP() {
322
+ const path = getCursorMcpPath();
323
+ const config = readCursorConfig(path);
324
+ const servers = config.mcpServers ?? {};
325
+ writeCursorConfig(path, {
326
+ ...config,
327
+ mcpServers: { ...servers, [SERVER_NAME2]: mcpServerEntry2() }
328
+ });
329
+ return updateCursorRules();
330
+ }
331
+ function removeCursorMCP() {
332
+ const path = getCursorMcpPath();
333
+ if (!existsSync4(path)) return false;
334
+ const config = readCursorConfig(path);
335
+ if (!config.mcpServers?.[SERVER_NAME2]) return false;
336
+ const { [SERVER_NAME2]: _, ...rest } = config.mcpServers;
337
+ writeCursorConfig(path, { ...config, mcpServers: rest });
338
+ removeCursorRulesSection();
339
+ return true;
340
+ }
341
+ function getCursorMcpConfigPath() {
342
+ return getCursorMcpPath();
343
+ }
344
+ function getCursorRulesPath() {
345
+ return CURSOR_RULES_PATH_GETTER();
346
+ }
347
+ function updateCursorRules() {
348
+ const rulesPath = CURSOR_RULES_PATH_GETTER();
349
+ const existing = existsSync4(rulesPath) ? readFileSync3(rulesPath, "utf-8") : "";
350
+ if (existing.includes(MEMROSETTA_CURSOR_RULES_MARKER)) return false;
351
+ writeFileSync3(rulesPath, existing + MEMROSETTA_CURSOR_RULES, "utf-8");
352
+ return true;
353
+ }
354
+ function removeCursorRulesSection() {
355
+ const rulesPath = CURSOR_RULES_PATH_GETTER();
356
+ if (!existsSync4(rulesPath)) return false;
357
+ const content = readFileSync3(rulesPath, "utf-8");
358
+ const markerIdx = content.indexOf(MEMROSETTA_CURSOR_RULES_MARKER);
359
+ if (markerIdx === -1) return false;
360
+ const afterMarker = content.slice(
361
+ markerIdx + MEMROSETTA_CURSOR_RULES_MARKER.length
362
+ );
363
+ const nextHeadingMatch = afterMarker.match(/\n## (?!MemRosetta)/);
364
+ const endIdx = nextHeadingMatch ? markerIdx + MEMROSETTA_CURSOR_RULES_MARKER.length + (nextHeadingMatch.index ?? afterMarker.length) : content.length;
365
+ const before = content.slice(0, markerIdx).replace(/\n+$/, "");
366
+ const after = content.slice(endIdx);
367
+ const updated = (before + after).trimEnd() + "\n";
368
+ writeFileSync3(rulesPath, updated, "utf-8");
369
+ return true;
370
+ }
371
+
372
+ // src/integrations/codex.ts
373
+ import { join as join5 } from "path";
374
+ import { homedir as homedir4 } from "os";
375
+ import { existsSync as existsSync5, readFileSync as readFileSync4, writeFileSync as writeFileSync4, mkdirSync as mkdirSync2 } from "fs";
376
+ var SERVER_NAME3 = "memrosetta";
377
+ var CODEX_CONFIG_PATH_GETTER = () => join5(homedir4(), ".codex", "config.toml");
378
+ var AGENTS_MD_MARKER = "## MemRosetta (Long-term Memory)";
379
+ var MEMROSETTA_AGENTS_MD = `
380
+
381
+ ${AGENTS_MD_MARKER}
382
+
383
+ MCP server \`memrosetta\` provides persistent memory across sessions.
384
+ userId defaults to the system username -- no need to specify it.
385
+
386
+ ### When to search (memrosetta_search)
387
+ When you need information not in the current context, search past memories.
388
+
389
+ ### When to store (memrosetta_store)
390
+
391
+ **After EVERY response, run this checklist:**
392
+ 1. Did I encounter a DECISION? (tech choice, approach selection) -> store as "decision"
393
+ 2. Did I learn a new FACT? (config, architecture, project info) -> store as "fact"
394
+ 3. Did the user state a PREFERENCE? (style, tool choice, pattern) -> store as "preference"
395
+ 4. Did we COMPLETE something? (deploy, migration, fix) -> store as "event"
396
+ 5. None of the above? -> skip, do not store.
397
+
398
+ Always include 2-3 keywords. Example:
399
+ content: "Decided to use OAuth2 with PKCE for auth"
400
+ type: "decision"
401
+ keywords: "auth, oauth2, pkce"
402
+
403
+ Do NOT store:
404
+ - Code itself (belongs in git)
405
+ - File operations ("Created file X", "Modified Y")
406
+ - Debugging steps and attempts
407
+ - Simple confirmations or acknowledgments
408
+
409
+ ### When to relate (memrosetta_relate)
410
+ When new information updates or contradicts existing memories, create a relation.
411
+
412
+ ### Working memory (memrosetta_working_memory)
413
+ Call this at the start of complex tasks to load relevant context.
414
+ `;
415
+ function getCodexConfigDir() {
416
+ return join5(homedir4(), ".codex");
417
+ }
418
+ function getCodexConfigPath() {
419
+ return CODEX_CONFIG_PATH_GETTER();
420
+ }
421
+ function readCodexConfig(path) {
422
+ if (!existsSync5(path)) return "";
423
+ try {
424
+ return readFileSync4(path, "utf-8");
425
+ } catch {
426
+ return "";
427
+ }
428
+ }
429
+ function buildMcpServerToml() {
430
+ const { command, args } = resolveMcpCommand();
431
+ const argsLine = args.length > 0 ? `
432
+ args = [${args.map((a) => `"${a}"`).join(", ")}]` : "";
433
+ return `
434
+ [mcp_servers.${SERVER_NAME3}]
435
+ command = "${command}"${argsLine}
436
+ `;
437
+ }
438
+ function hasMcpServer(content) {
439
+ return content.includes(`[mcp_servers.${SERVER_NAME3}]`);
440
+ }
441
+ function isCodexConfigured() {
442
+ const content = readCodexConfig(getCodexConfigPath());
443
+ return hasMcpServer(content);
444
+ }
445
+ function registerCodexMCP() {
446
+ const configPath = getCodexConfigPath();
447
+ const dir = getCodexConfigDir();
448
+ if (!existsSync5(dir)) {
449
+ mkdirSync2(dir, { recursive: true });
450
+ }
451
+ const content = readCodexConfig(configPath);
452
+ if (!hasMcpServer(content)) {
453
+ writeFileSync4(configPath, content + buildMcpServerToml(), "utf-8");
454
+ }
455
+ return updateAgentsMd();
456
+ }
457
+ function removeCodexMCP() {
458
+ const configPath = getCodexConfigPath();
459
+ if (!existsSync5(configPath)) return false;
460
+ const content = readCodexConfig(configPath);
461
+ if (!hasMcpServer(content)) return false;
462
+ const lines = content.split("\n");
463
+ const filtered = [];
464
+ let skipping = false;
465
+ for (const line of lines) {
466
+ if (line.trim() === `[mcp_servers.${SERVER_NAME3}]`) {
467
+ skipping = true;
468
+ continue;
469
+ }
470
+ if (skipping && line.trim().startsWith("[")) {
471
+ skipping = false;
472
+ }
473
+ if (!skipping) {
474
+ filtered.push(line);
475
+ }
476
+ }
477
+ writeFileSync4(configPath, filtered.join("\n").replace(/\n{3,}/g, "\n\n").trimEnd() + "\n", "utf-8");
478
+ removeAgentsMdSection();
479
+ return true;
480
+ }
481
+ function getCodexConfigFilePath() {
482
+ return getCodexConfigPath();
483
+ }
484
+ function getAgentsMdPath() {
485
+ return join5(process.cwd(), "AGENTS.md");
486
+ }
487
+ function updateAgentsMd() {
488
+ const agentsPath = getAgentsMdPath();
489
+ const existing = existsSync5(agentsPath) ? readFileSync4(agentsPath, "utf-8") : "";
490
+ if (existing.includes(AGENTS_MD_MARKER)) return false;
491
+ writeFileSync4(agentsPath, existing + MEMROSETTA_AGENTS_MD, "utf-8");
492
+ return true;
493
+ }
494
+ function removeAgentsMdSection() {
495
+ const agentsPath = getAgentsMdPath();
496
+ if (!existsSync5(agentsPath)) return false;
497
+ const content = readFileSync4(agentsPath, "utf-8");
498
+ const markerIdx = content.indexOf(AGENTS_MD_MARKER);
499
+ if (markerIdx === -1) return false;
500
+ const afterMarker = content.slice(markerIdx + AGENTS_MD_MARKER.length);
501
+ const nextHeadingMatch = afterMarker.match(/\n## (?!MemRosetta)/);
502
+ const endIdx = nextHeadingMatch ? markerIdx + AGENTS_MD_MARKER.length + (nextHeadingMatch.index ?? afterMarker.length) : content.length;
503
+ const before = content.slice(0, markerIdx).replace(/\n+$/, "");
504
+ const after = content.slice(endIdx);
505
+ const updated = (before + after).trimEnd() + "\n";
506
+ writeFileSync4(agentsPath, updated, "utf-8");
507
+ return true;
508
+ }
509
+
510
+ export {
511
+ isClaudeCodeInstalled,
512
+ isClaudeCodeConfigured,
513
+ registerClaudeCodeHooks,
514
+ removeClaudeCodeHooks,
515
+ updateClaudeMd,
516
+ removeClaudeMdSection,
517
+ isGenericMCPConfigured,
518
+ registerGenericMCP,
519
+ removeGenericMCP,
520
+ getGenericMCPPath,
521
+ isCursorConfigured,
522
+ registerCursorMCP,
523
+ removeCursorMCP,
524
+ getCursorMcpConfigPath,
525
+ getCursorRulesPath,
526
+ removeCursorRulesSection,
527
+ isCodexConfigured,
528
+ registerCodexMCP,
529
+ removeCodexMCP,
530
+ getCodexConfigFilePath,
531
+ getAgentsMdPath,
532
+ removeAgentsMdSection
533
+ };
@@ -0,0 +1,69 @@
1
+ import {
2
+ ensureDir,
3
+ getConfig
4
+ } from "./chunk-KSKRPUZZ.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
+ embedder = new HuggingFaceEmbedder();
18
+ await embedder.initialize();
19
+ } catch (err) {
20
+ const message = err instanceof Error ? err.message : String(err);
21
+ process.stderr.write(
22
+ `[memrosetta] Failed to load embeddings, continuing without: ${message}
23
+ `
24
+ );
25
+ }
26
+ }
27
+ engineInstance = new SqliteMemoryEngine({
28
+ dbPath: config.dbPath,
29
+ embedder
30
+ });
31
+ await engineInstance.initialize();
32
+ return engineInstance;
33
+ }
34
+ async function closeEngine() {
35
+ if (engineInstance) {
36
+ await engineInstance.close();
37
+ engineInstance = null;
38
+ }
39
+ }
40
+ async function getEngineWithTimeout(timeoutMs) {
41
+ let timer;
42
+ const enginePromise = getEngine();
43
+ const timeoutPromise = new Promise((resolve2) => {
44
+ timer = setTimeout(() => resolve2(null), timeoutMs);
45
+ });
46
+ const result = await Promise.race([enginePromise, timeoutPromise]);
47
+ clearTimeout(timer);
48
+ return result;
49
+ }
50
+
51
+ // src/hooks/path-validation.ts
52
+ import { resolve } from "path";
53
+ import { homedir } from "os";
54
+ var CLAUDE_DIR = resolve(homedir(), ".claude");
55
+ function isValidTranscriptPath(p) {
56
+ const resolved = resolve(p);
57
+ return resolved.startsWith(CLAUDE_DIR) && resolved.endsWith(".jsonl");
58
+ }
59
+ function sanitizeSessionId(sessionId) {
60
+ return sessionId.replace(/[^a-zA-Z0-9_-]/g, "");
61
+ }
62
+
63
+ export {
64
+ getEngine,
65
+ closeEngine,
66
+ getEngineWithTimeout,
67
+ isValidTranscriptPath,
68
+ sanitizeSessionId
69
+ };