@memrosetta/cli 0.4.6 → 0.4.8

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.
@@ -0,0 +1,95 @@
1
+ import {
2
+ classifyTurn,
3
+ parseTranscriptContent
4
+ } from "./chunk-KR63XYFW.js";
5
+ import {
6
+ optionalOption
7
+ } from "./chunk-NU5ZJJXP.js";
8
+ import {
9
+ getEngine
10
+ } from "./chunk-VAVUPQZA.js";
11
+ import {
12
+ output,
13
+ outputError
14
+ } from "./chunk-ET6TNQOJ.js";
15
+ import {
16
+ getDefaultUserId
17
+ } from "./chunk-SEPYQK3J.js";
18
+
19
+ // src/commands/ingest.ts
20
+ import { readFileSync } from "fs";
21
+ function turnsToMemories(turns, userId, namespace, sessionShort) {
22
+ const now = (/* @__PURE__ */ new Date()).toISOString();
23
+ const memories = [];
24
+ for (let i = 0; i < turns.length; i++) {
25
+ const turn = turns[i];
26
+ if (turn.content.length < 20) continue;
27
+ const content = turn.content.length > 500 ? turn.content.slice(0, 497) + "..." : turn.content;
28
+ memories.push({
29
+ userId,
30
+ namespace: namespace ?? `session-${sessionShort}`,
31
+ memoryType: classifyTurn(turn),
32
+ content,
33
+ documentDate: now,
34
+ sourceId: `cc-${sessionShort}-${i}`,
35
+ confidence: turn.role === "user" ? 0.9 : 0.8
36
+ });
37
+ }
38
+ return memories;
39
+ }
40
+ async function readStdin() {
41
+ const chunks = [];
42
+ for await (const chunk of process.stdin) {
43
+ chunks.push(chunk);
44
+ }
45
+ return Buffer.concat(chunks).toString("utf-8").trim();
46
+ }
47
+ async function run(options) {
48
+ const { args, format, db, noEmbeddings } = options;
49
+ const userId = optionalOption(args, "--user") ?? getDefaultUserId();
50
+ const file = optionalOption(args, "--file");
51
+ const namespace = optionalOption(args, "--namespace");
52
+ let content;
53
+ if (file) {
54
+ try {
55
+ content = readFileSync(file, "utf-8");
56
+ } catch (err) {
57
+ const msg = err instanceof Error ? err.message : String(err);
58
+ outputError(`Failed to read file: ${msg}`, format);
59
+ process.exitCode = 1;
60
+ return;
61
+ }
62
+ } else {
63
+ content = await readStdin();
64
+ }
65
+ if (!content) {
66
+ outputError("No transcript content provided", format);
67
+ process.exitCode = 1;
68
+ return;
69
+ }
70
+ const parsed = parseTranscriptContent(content);
71
+ const sessionShort = parsed.sessionId ? parsed.sessionId.slice(0, 8) : "unknown";
72
+ const memories = turnsToMemories(
73
+ parsed.turns,
74
+ userId,
75
+ namespace,
76
+ sessionShort
77
+ );
78
+ if (memories.length === 0) {
79
+ output({ stored: 0, message: "No memories extracted from transcript" }, format);
80
+ return;
81
+ }
82
+ const engine = await getEngine({ db, noEmbeddings });
83
+ const stored = await engine.storeBatch(memories);
84
+ output(
85
+ {
86
+ stored: stored.length,
87
+ sessionId: parsed.sessionId || void 0,
88
+ namespace: namespace ?? `session-${sessionShort}`
89
+ },
90
+ format
91
+ );
92
+ }
93
+ export {
94
+ run
95
+ };
@@ -0,0 +1,205 @@
1
+ import {
2
+ getAgentsMdPath,
3
+ getCodexConfigFilePath,
4
+ getCursorMcpConfigPath,
5
+ getCursorRulesPath,
6
+ getGeminiMdPath,
7
+ getGeminiSettingsFilePath,
8
+ getGenericMCPPath,
9
+ isClaudeCodeInstalled,
10
+ registerClaudeCodeHooks,
11
+ registerCodexMCP,
12
+ registerCursorMCP,
13
+ registerGeminiMCP,
14
+ registerGenericMCP,
15
+ updateClaudeMd
16
+ } from "./chunk-IS4IKWPL.js";
17
+ import {
18
+ hasFlag,
19
+ optionalOption
20
+ } from "./chunk-NU5ZJJXP.js";
21
+ import {
22
+ getDefaultDbPath,
23
+ getEngine
24
+ } from "./chunk-VAVUPQZA.js";
25
+ import {
26
+ output
27
+ } from "./chunk-ET6TNQOJ.js";
28
+ import {
29
+ getConfig,
30
+ writeConfig
31
+ } from "./chunk-SEPYQK3J.js";
32
+
33
+ // src/commands/init.ts
34
+ import { existsSync } from "fs";
35
+ var LANG_FLAG_TO_PRESET = {
36
+ en: "en",
37
+ multi: "multilingual",
38
+ ko: "ko"
39
+ };
40
+ async function run(options) {
41
+ const { args, format, db, noEmbeddings } = options;
42
+ const wantClaudeCode = hasFlag(args, "--claude-code");
43
+ const wantCursor = hasFlag(args, "--cursor");
44
+ const wantCodex = hasFlag(args, "--codex");
45
+ const wantGemini = hasFlag(args, "--gemini");
46
+ const langFlag = optionalOption(args, "--lang");
47
+ const embeddingPreset = langFlag ? LANG_FLAG_TO_PRESET[langFlag] : void 0;
48
+ if (langFlag && !LANG_FLAG_TO_PRESET[langFlag]) {
49
+ process.stderr.write(
50
+ `Unknown --lang value: "${langFlag}". Supported: en, multi, ko
51
+ `
52
+ );
53
+ process.exitCode = 1;
54
+ return;
55
+ }
56
+ {
57
+ const config2 = getConfig();
58
+ const updates = {};
59
+ if (db) {
60
+ updates.dbPath = db;
61
+ }
62
+ if (noEmbeddings) {
63
+ updates.enableEmbeddings = false;
64
+ }
65
+ if (embeddingPreset) {
66
+ updates.embeddingPreset = embeddingPreset;
67
+ }
68
+ if (Object.keys(updates).length > 0) {
69
+ writeConfig({ ...config2, ...updates });
70
+ }
71
+ }
72
+ const config = getConfig();
73
+ const dbPath = db ?? config.dbPath ?? getDefaultDbPath();
74
+ const existed = existsSync(dbPath);
75
+ const engine = await getEngine({ db: dbPath, noEmbeddings });
76
+ await engine.close();
77
+ const result = {
78
+ database: {
79
+ path: dbPath,
80
+ created: !existed
81
+ },
82
+ integrations: {}
83
+ };
84
+ registerGenericMCP();
85
+ result.integrations.mcp = {
86
+ registered: true,
87
+ path: getGenericMCPPath()
88
+ };
89
+ if (wantClaudeCode) {
90
+ const hooksOk = registerClaudeCodeHooks();
91
+ const claudeMdOk = updateClaudeMd();
92
+ result.integrations.claudeCode = {
93
+ hooks: hooksOk,
94
+ mcp: true,
95
+ claudeMd: claudeMdOk
96
+ };
97
+ }
98
+ if (wantCursor) {
99
+ const cursorRulesUpdated = registerCursorMCP();
100
+ result.integrations.cursor = {
101
+ mcp: true,
102
+ path: getCursorMcpConfigPath(),
103
+ cursorRules: cursorRulesUpdated,
104
+ cursorRulesPath: getCursorRulesPath()
105
+ };
106
+ }
107
+ if (wantCodex) {
108
+ const agentsMdUpdated = registerCodexMCP();
109
+ result.integrations.codex = {
110
+ mcp: true,
111
+ path: getCodexConfigFilePath(),
112
+ agentsMd: agentsMdUpdated,
113
+ agentsMdPath: getAgentsMdPath()
114
+ };
115
+ }
116
+ if (wantGemini) {
117
+ const geminiMdUpdated = registerGeminiMCP();
118
+ result.integrations.gemini = {
119
+ mcp: true,
120
+ path: getGeminiSettingsFilePath(),
121
+ geminiMd: geminiMdUpdated,
122
+ geminiMdPath: getGeminiMdPath()
123
+ };
124
+ }
125
+ if (format === "text") {
126
+ printTextOutput(result, wantClaudeCode, wantCursor, wantCodex, wantGemini);
127
+ return;
128
+ }
129
+ output(result, format);
130
+ }
131
+ function printTextOutput(result, claudeCode, cursor, codex = false, gemini = false) {
132
+ const w = (s) => process.stdout.write(s);
133
+ w("\nMemRosetta initialized successfully.\n\n");
134
+ w(" What was set up:\n");
135
+ w(" ----------------------------------------\n");
136
+ w(` Database: ${result.database.path}`);
137
+ w(result.database.created ? " (created)\n" : " (already exists)\n");
138
+ w(` MCP Server: ${result.integrations.mcp.path} (always included)
139
+ `);
140
+ const currentConfig = getConfig();
141
+ if (currentConfig.embeddingPreset && currentConfig.embeddingPreset !== "en") {
142
+ const presetLabels = {
143
+ multilingual: "multilingual (multilingual-e5-small)",
144
+ ko: "Korean (ko-sroberta-multitask)"
145
+ };
146
+ w(` Embeddings: ${presetLabels[currentConfig.embeddingPreset] ?? currentConfig.embeddingPreset}
147
+ `);
148
+ }
149
+ if (claudeCode) {
150
+ const cc = result.integrations.claudeCode;
151
+ if (cc.hooks) {
152
+ w(" Stop Hook: ~/.claude/settings.json (auto-save on session end)\n");
153
+ } else if (!isClaudeCodeInstalled()) {
154
+ w(" Stop Hook: SKIPPED (Claude Code not found at ~/.claude)\n");
155
+ w(' Install Claude Code first, then run "memrosetta init --claude-code" again.\n');
156
+ }
157
+ if (cc.claudeMd) {
158
+ w(" CLAUDE.md: ~/.claude/CLAUDE.md (memory instructions added)\n");
159
+ } else {
160
+ w(" CLAUDE.md: already configured\n");
161
+ }
162
+ }
163
+ if (cursor) {
164
+ w(` Cursor MCP: ${result.integrations.cursor.path}
165
+ `);
166
+ if (result.integrations.cursor.cursorRules) {
167
+ w(` .cursorrules: ${result.integrations.cursor.cursorRulesPath} (memory instructions added)
168
+ `);
169
+ } else {
170
+ w(" .cursorrules: already configured\n");
171
+ }
172
+ }
173
+ if (codex) {
174
+ w(` Codex MCP: ${result.integrations.codex.path}
175
+ `);
176
+ if (result.integrations.codex.agentsMd) {
177
+ w(` AGENTS.md: ${result.integrations.codex.agentsMdPath} (memory instructions added)
178
+ `);
179
+ } else {
180
+ w(" AGENTS.md: already configured\n");
181
+ }
182
+ }
183
+ if (gemini) {
184
+ w(` Gemini MCP: ${result.integrations.gemini.path}
185
+ `);
186
+ if (result.integrations.gemini.geminiMd) {
187
+ w(` GEMINI.md: ${result.integrations.gemini.geminiMdPath} (memory instructions added)
188
+ `);
189
+ } else {
190
+ w(" GEMINI.md: already configured\n");
191
+ }
192
+ }
193
+ w("\n");
194
+ if (!claudeCode && !cursor && !codex && !gemini) {
195
+ w(" MCP is ready. Add --claude-code, --cursor, --codex, or --gemini for tool-specific setup.\n");
196
+ w(" Example: memrosetta init --claude-code\n");
197
+ w("\n");
198
+ }
199
+ if (claudeCode) {
200
+ w(" Restart Claude Code to activate.\n\n");
201
+ }
202
+ }
203
+ export {
204
+ run
205
+ };
@@ -0,0 +1,40 @@
1
+ import {
2
+ buildMemoryInvalidatedOp,
3
+ openCliSyncContext
4
+ } from "./chunk-2MO65JLK.js";
5
+ import {
6
+ optionalOption
7
+ } from "./chunk-NU5ZJJXP.js";
8
+ import {
9
+ getEngine,
10
+ resolveDbPath
11
+ } from "./chunk-VAVUPQZA.js";
12
+ import {
13
+ output,
14
+ outputError
15
+ } from "./chunk-ET6TNQOJ.js";
16
+ import "./chunk-SEPYQK3J.js";
17
+
18
+ // src/commands/invalidate.ts
19
+ async function run(options) {
20
+ const { args, format, db, noEmbeddings } = options;
21
+ const memoryId = args.find((a) => !a.startsWith("-"));
22
+ if (!memoryId) {
23
+ outputError("Usage: memrosetta invalidate <memoryId>", format);
24
+ process.exitCode = 1;
25
+ return;
26
+ }
27
+ const reason = optionalOption(args, "--reason");
28
+ const engine = await getEngine({ db, noEmbeddings });
29
+ const now = (/* @__PURE__ */ new Date()).toISOString();
30
+ await engine.invalidate(memoryId, reason);
31
+ const sync = await openCliSyncContext(resolveDbPath(db));
32
+ if (sync.enabled) {
33
+ sync.enqueue(buildMemoryInvalidatedOp(sync, memoryId, now, reason));
34
+ sync.close();
35
+ }
36
+ output({ memoryId, invalidated: true }, format);
37
+ }
38
+ export {
39
+ run
40
+ };
@@ -0,0 +1,40 @@
1
+ import {
2
+ buildMemoryInvalidatedOp,
3
+ openCliSyncContext
4
+ } from "./chunk-KPASMEV7.js";
5
+ import {
6
+ optionalOption
7
+ } from "./chunk-NU5ZJJXP.js";
8
+ import {
9
+ getEngine,
10
+ resolveDbPath
11
+ } from "./chunk-VAVUPQZA.js";
12
+ import {
13
+ output,
14
+ outputError
15
+ } from "./chunk-ET6TNQOJ.js";
16
+ import "./chunk-SEPYQK3J.js";
17
+
18
+ // src/commands/invalidate.ts
19
+ async function run(options) {
20
+ const { args, format, db, noEmbeddings } = options;
21
+ const memoryId = args.find((a) => !a.startsWith("-"));
22
+ if (!memoryId) {
23
+ outputError("Usage: memrosetta invalidate <memoryId>", format);
24
+ process.exitCode = 1;
25
+ return;
26
+ }
27
+ const reason = optionalOption(args, "--reason");
28
+ const engine = await getEngine({ db, noEmbeddings });
29
+ const now = (/* @__PURE__ */ new Date()).toISOString();
30
+ await engine.invalidate(memoryId, reason);
31
+ const sync = await openCliSyncContext(resolveDbPath(db));
32
+ if (sync.enabled) {
33
+ sync.enqueue(buildMemoryInvalidatedOp(sync, memoryId, now, reason));
34
+ sync.close();
35
+ }
36
+ output({ memoryId, invalidated: true }, format);
37
+ }
38
+ export {
39
+ run
40
+ };
@@ -0,0 +1,37 @@
1
+ import {
2
+ optionalOption
3
+ } from "./chunk-NU5ZJJXP.js";
4
+ import {
5
+ getEngine
6
+ } from "./chunk-VAVUPQZA.js";
7
+ import {
8
+ output
9
+ } from "./chunk-ET6TNQOJ.js";
10
+ import {
11
+ getDefaultUserId
12
+ } from "./chunk-SEPYQK3J.js";
13
+
14
+ // src/commands/maintain.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.maintain(userId);
20
+ if (format === "text") {
21
+ process.stdout.write(`Maintenance completed for user: ${userId}
22
+ `);
23
+ process.stdout.write(` Activation scores updated: ${result.activationUpdated}
24
+ `);
25
+ process.stdout.write(` Tiers updated: ${result.tiersUpdated}
26
+ `);
27
+ process.stdout.write(` Groups compressed: ${result.compressed}
28
+ `);
29
+ process.stdout.write(` Memories archived: ${result.removed}
30
+ `);
31
+ return;
32
+ }
33
+ output({ userId, ...result }, format);
34
+ }
35
+ export {
36
+ run
37
+ };
@@ -0,0 +1,57 @@
1
+ import {
2
+ buildRelationCreatedOp,
3
+ openCliSyncContext
4
+ } from "./chunk-KPASMEV7.js";
5
+ import {
6
+ optionalOption,
7
+ requireOption
8
+ } from "./chunk-NU5ZJJXP.js";
9
+ import {
10
+ getEngine,
11
+ resolveDbPath
12
+ } from "./chunk-VAVUPQZA.js";
13
+ import {
14
+ output,
15
+ outputError
16
+ } from "./chunk-ET6TNQOJ.js";
17
+ import "./chunk-SEPYQK3J.js";
18
+
19
+ // src/commands/relate.ts
20
+ var VALID_RELATION_TYPES = /* @__PURE__ */ new Set([
21
+ "updates",
22
+ "extends",
23
+ "derives",
24
+ "contradicts",
25
+ "supports"
26
+ ]);
27
+ async function run(options) {
28
+ const { args, format, db, noEmbeddings } = options;
29
+ const src = requireOption(args, "--src", "source memory ID");
30
+ const dst = requireOption(args, "--dst", "destination memory ID");
31
+ const relationType = requireOption(args, "--type", "relation type");
32
+ const reason = optionalOption(args, "--reason");
33
+ if (!VALID_RELATION_TYPES.has(relationType)) {
34
+ outputError(
35
+ `Invalid relation type: ${relationType}. Must be one of: updates, extends, derives, contradicts, supports`,
36
+ format
37
+ );
38
+ process.exitCode = 1;
39
+ return;
40
+ }
41
+ const engine = await getEngine({ db, noEmbeddings });
42
+ const relation = await engine.relate(
43
+ src,
44
+ dst,
45
+ relationType,
46
+ reason
47
+ );
48
+ const sync = await openCliSyncContext(resolveDbPath(db));
49
+ if (sync.enabled) {
50
+ sync.enqueue(buildRelationCreatedOp(sync, relation));
51
+ sync.close();
52
+ }
53
+ output(relation, format);
54
+ }
55
+ export {
56
+ run
57
+ };
@@ -0,0 +1,57 @@
1
+ import {
2
+ buildRelationCreatedOp,
3
+ openCliSyncContext
4
+ } from "./chunk-2MO65JLK.js";
5
+ import {
6
+ optionalOption,
7
+ requireOption
8
+ } from "./chunk-NU5ZJJXP.js";
9
+ import {
10
+ getEngine,
11
+ resolveDbPath
12
+ } from "./chunk-VAVUPQZA.js";
13
+ import {
14
+ output,
15
+ outputError
16
+ } from "./chunk-ET6TNQOJ.js";
17
+ import "./chunk-SEPYQK3J.js";
18
+
19
+ // src/commands/relate.ts
20
+ var VALID_RELATION_TYPES = /* @__PURE__ */ new Set([
21
+ "updates",
22
+ "extends",
23
+ "derives",
24
+ "contradicts",
25
+ "supports"
26
+ ]);
27
+ async function run(options) {
28
+ const { args, format, db, noEmbeddings } = options;
29
+ const src = requireOption(args, "--src", "source memory ID");
30
+ const dst = requireOption(args, "--dst", "destination memory ID");
31
+ const relationType = requireOption(args, "--type", "relation type");
32
+ const reason = optionalOption(args, "--reason");
33
+ if (!VALID_RELATION_TYPES.has(relationType)) {
34
+ outputError(
35
+ `Invalid relation type: ${relationType}. Must be one of: updates, extends, derives, contradicts, supports`,
36
+ format
37
+ );
38
+ process.exitCode = 1;
39
+ return;
40
+ }
41
+ const engine = await getEngine({ db, noEmbeddings });
42
+ const relation = await engine.relate(
43
+ src,
44
+ dst,
45
+ relationType,
46
+ reason
47
+ );
48
+ const sync = await openCliSyncContext(resolveDbPath(db));
49
+ if (sync.enabled) {
50
+ sync.enqueue(buildRelationCreatedOp(sync, relation));
51
+ sync.close();
52
+ }
53
+ output(relation, format);
54
+ }
55
+ export {
56
+ run
57
+ };
@@ -0,0 +1,48 @@
1
+ import {
2
+ optionalOption,
3
+ requireOption
4
+ } from "./chunk-NU5ZJJXP.js";
5
+ import {
6
+ getEngine
7
+ } from "./chunk-VAVUPQZA.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/search.ts
17
+ async function run(options) {
18
+ const { args, format, db, noEmbeddings } = options;
19
+ const userId = optionalOption(args, "--user") ?? getDefaultUserId();
20
+ const query = requireOption(args, "--query", "query");
21
+ const limitRaw = optionalOption(args, "--limit");
22
+ const namespace = optionalOption(args, "--namespace");
23
+ const typesRaw = optionalOption(args, "--types");
24
+ const minConfidenceRaw = optionalOption(args, "--min-confidence");
25
+ const limit = limitRaw ? parseInt(limitRaw, 10) : 5;
26
+ if (isNaN(limit) || limit < 1) {
27
+ outputError("Invalid limit value", format);
28
+ process.exitCode = 1;
29
+ return;
30
+ }
31
+ const memoryTypes = typesRaw ? typesRaw.split(",") : void 0;
32
+ const minConfidence = minConfidenceRaw ? parseFloat(minConfidenceRaw) : void 0;
33
+ const engine = await getEngine({ db, noEmbeddings });
34
+ const response = await engine.search({
35
+ userId,
36
+ query,
37
+ namespace,
38
+ limit,
39
+ filters: {
40
+ memoryTypes,
41
+ minConfidence
42
+ }
43
+ });
44
+ output(response, format);
45
+ }
46
+ export {
47
+ run
48
+ };