monomind 1.17.0 → 1.17.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.
- package/.claude/agents/engineering/engineering-security-engineer.md +1 -1
- package/.claude/commands/mastermind/_repeat.md +4 -0
- package/.claude/commands/mastermind/master.md +52 -1
- package/.claude/scheduled_tasks.lock +1 -1
- package/.claude/skills/mastermind/_repeat.md +2 -0
- package/package.json +1 -1
- package/packages/@monomind/cli/.claude/agents/engineering/engineering-security-engineer.md +1 -1
- package/packages/@monomind/cli/.claude/commands/mastermind/_repeat.md +4 -0
- package/packages/@monomind/cli/.claude/commands/mastermind/master.md +52 -1
- package/packages/@monomind/cli/.claude/skills/mastermind/_repeat.md +2 -0
- package/packages/@monomind/cli/dist/src/__tests__/browse-analyzer.test.js +42 -59
- package/packages/@monomind/cli/dist/src/browser/dashboard/server.js +18 -0
- package/packages/@monomind/cli/dist/src/browser/dashboard/ui.html +37 -125
- package/packages/@monomind/cli/dist/src/commands/agent-lifecycle.d.ts +17 -0
- package/packages/@monomind/cli/dist/src/commands/agent-lifecycle.js +320 -0
- package/packages/@monomind/cli/dist/src/commands/agent-ops.d.ts +9 -0
- package/packages/@monomind/cli/dist/src/commands/agent-ops.js +329 -0
- package/packages/@monomind/cli/dist/src/commands/agent.js +5 -907
- package/packages/@monomind/cli/dist/src/commands/analyze-ast.d.ts +26 -0
- package/packages/@monomind/cli/dist/src/commands/analyze-ast.js +284 -0
- package/packages/@monomind/cli/dist/src/commands/analyze-boundaries.d.ts +14 -0
- package/packages/@monomind/cli/dist/src/commands/analyze-boundaries.js +295 -0
- package/packages/@monomind/cli/dist/src/commands/analyze-diff.d.ts +8 -0
- package/packages/@monomind/cli/dist/src/commands/analyze-diff.js +395 -0
- package/packages/@monomind/cli/dist/src/commands/analyze-graph.d.ts +14 -0
- package/packages/@monomind/cli/dist/src/commands/analyze-graph.js +304 -0
- package/packages/@monomind/cli/dist/src/commands/analyze-imports.d.ts +11 -0
- package/packages/@monomind/cli/dist/src/commands/analyze-imports.js +287 -0
- package/packages/@monomind/cli/dist/src/commands/analyze-symbols.d.ts +14 -0
- package/packages/@monomind/cli/dist/src/commands/analyze-symbols.js +302 -0
- package/packages/@monomind/cli/dist/src/commands/analyze.d.ts +38 -0
- package/packages/@monomind/cli/dist/src/commands/analyze.js +12 -1827
- package/packages/@monomind/cli/dist/src/commands/doctor-env-checks.d.ts +26 -0
- package/packages/@monomind/cli/dist/src/commands/doctor-env-checks.js +189 -0
- package/packages/@monomind/cli/dist/src/commands/doctor-project-checks.d.ts +19 -0
- package/packages/@monomind/cli/dist/src/commands/doctor-project-checks.js +388 -0
- package/packages/@monomind/cli/dist/src/commands/doctor.js +51 -942
- package/packages/@monomind/cli/dist/src/commands/hive-mind-comms.d.ts +11 -0
- package/packages/@monomind/cli/dist/src/commands/hive-mind-comms.js +242 -0
- package/packages/@monomind/cli/dist/src/commands/hive-mind-helpers.d.ts +35 -0
- package/packages/@monomind/cli/dist/src/commands/hive-mind-helpers.js +203 -0
- package/packages/@monomind/cli/dist/src/commands/hive-mind-ops.d.ts +8 -0
- package/packages/@monomind/cli/dist/src/commands/hive-mind-ops.js +233 -0
- package/packages/@monomind/cli/dist/src/commands/hive-mind-spawn.d.ts +12 -0
- package/packages/@monomind/cli/dist/src/commands/hive-mind-spawn.js +274 -0
- package/packages/@monomind/cli/dist/src/commands/hive-mind.js +10 -1129
- package/packages/@monomind/cli/dist/src/commands/hooks-coverage-commands.d.ts +4 -4
- package/packages/@monomind/cli/dist/src/commands/hooks-coverage-commands.js +19 -819
- package/packages/@monomind/cli/dist/src/commands/hooks-coverage-gaps.d.ts +7 -0
- package/packages/@monomind/cli/dist/src/commands/hooks-coverage-gaps.js +334 -0
- package/packages/@monomind/cli/dist/src/commands/hooks-coverage-routing.d.ts +7 -0
- package/packages/@monomind/cli/dist/src/commands/hooks-coverage-routing.js +399 -0
- package/packages/@monomind/cli/dist/src/commands/init-subcommands.d.ts +8 -0
- package/packages/@monomind/cli/dist/src/commands/init-subcommands.js +156 -0
- package/packages/@monomind/cli/dist/src/commands/init-upgrade.d.ts +6 -0
- package/packages/@monomind/cli/dist/src/commands/init-upgrade.js +203 -0
- package/packages/@monomind/cli/dist/src/commands/init-wizard.d.ts +6 -0
- package/packages/@monomind/cli/dist/src/commands/init-wizard.js +246 -0
- package/packages/@monomind/cli/dist/src/commands/init.js +6 -623
- package/packages/@monomind/cli/dist/src/commands/memory-admin.d.ts +10 -0
- package/packages/@monomind/cli/dist/src/commands/memory-admin.js +433 -0
- package/packages/@monomind/cli/dist/src/commands/memory-crud.d.ts +9 -0
- package/packages/@monomind/cli/dist/src/commands/memory-crud.js +342 -0
- package/packages/@monomind/cli/dist/src/commands/memory-list.d.ts +10 -0
- package/packages/@monomind/cli/dist/src/commands/memory-list.js +321 -0
- package/packages/@monomind/cli/dist/src/commands/memory-transfer.d.ts +9 -0
- package/packages/@monomind/cli/dist/src/commands/memory-transfer.js +372 -0
- package/packages/@monomind/cli/dist/src/commands/memory.d.ts +6 -0
- package/packages/@monomind/cli/dist/src/commands/memory.js +10 -1441
- package/packages/@monomind/cli/dist/src/commands/neural-core.d.ts +8 -0
- package/packages/@monomind/cli/dist/src/commands/neural-core.js +274 -0
- package/packages/@monomind/cli/dist/src/commands/neural-optimize.d.ts +7 -0
- package/packages/@monomind/cli/dist/src/commands/neural-optimize.js +332 -0
- package/packages/@monomind/cli/dist/src/commands/neural-registry.d.ts +7 -0
- package/packages/@monomind/cli/dist/src/commands/neural-registry.js +290 -0
- package/packages/@monomind/cli/dist/src/commands/neural.js +3 -974
- package/packages/@monomind/cli/dist/src/commands/platforms.js +327 -7
- package/packages/@monomind/cli/dist/src/commands/security-cve.d.ts +6 -0
- package/packages/@monomind/cli/dist/src/commands/security-cve.js +310 -0
- package/packages/@monomind/cli/dist/src/commands/security-misc.d.ts +9 -0
- package/packages/@monomind/cli/dist/src/commands/security-misc.js +293 -0
- package/packages/@monomind/cli/dist/src/commands/security-scan.d.ts +18 -0
- package/packages/@monomind/cli/dist/src/commands/security-scan.js +328 -0
- package/packages/@monomind/cli/dist/src/commands/security.js +3 -958
- package/packages/@monomind/cli/dist/src/commands/session.js +1 -1
- package/packages/@monomind/cli/dist/src/commands/swarm.js +23 -17
- package/packages/@monomind/cli/dist/src/mcp-tools/swarm-tools.js +77 -0
- package/packages/@monomind/cli/dist/src/parser.js +11 -6
- package/packages/@monomind/cli/dist/src/routing/llm-caller.js +1 -2
- package/packages/@monomind/cli/package.json +2 -3
- package/packages/@monomind/cli/scripts/understand-analyze.mjs +1 -1
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory Transfer Commands
|
|
3
|
+
* compressCommand, exportCommand, importCommand
|
|
4
|
+
*/
|
|
5
|
+
import { output } from '../output.js';
|
|
6
|
+
import { callMCPTool, MCPClientError } from '../mcp-client.js';
|
|
7
|
+
// Compress command
|
|
8
|
+
export const compressCommand = {
|
|
9
|
+
name: 'compress',
|
|
10
|
+
description: 'Compress and optimize memory storage',
|
|
11
|
+
options: [
|
|
12
|
+
{
|
|
13
|
+
name: 'level',
|
|
14
|
+
short: 'l',
|
|
15
|
+
description: 'Compression level (fast, balanced, max)',
|
|
16
|
+
type: 'string',
|
|
17
|
+
choices: ['fast', 'balanced', 'max'],
|
|
18
|
+
default: 'balanced'
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: 'target',
|
|
22
|
+
short: 't',
|
|
23
|
+
description: 'Target (vectors, text, patterns, all)',
|
|
24
|
+
type: 'string',
|
|
25
|
+
choices: ['vectors', 'text', 'patterns', 'all'],
|
|
26
|
+
default: 'all'
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: 'quantize',
|
|
30
|
+
short: 'z',
|
|
31
|
+
description: 'Enable vector quantization (reduces memory 4-32x)',
|
|
32
|
+
type: 'boolean',
|
|
33
|
+
default: false
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: 'bits',
|
|
37
|
+
description: 'Quantization bits (4, 8, 16)',
|
|
38
|
+
type: 'number',
|
|
39
|
+
default: 8
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: 'rebuild-index',
|
|
43
|
+
short: 'r',
|
|
44
|
+
description: 'Rebuild HNSW index after compression',
|
|
45
|
+
type: 'boolean',
|
|
46
|
+
default: true
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
examples: [
|
|
50
|
+
{ command: 'monomind memory compress', description: 'Balanced compression' },
|
|
51
|
+
{ command: 'monomind memory compress --quantize --bits 4', description: '4-bit quantization (32x reduction)' },
|
|
52
|
+
{ command: 'monomind memory compress -l max -t vectors', description: 'Max compression on vectors' }
|
|
53
|
+
],
|
|
54
|
+
action: async (ctx) => {
|
|
55
|
+
const level = ctx.flags.level || 'balanced';
|
|
56
|
+
const target = ctx.flags.target || 'all';
|
|
57
|
+
const quantize = ctx.flags.quantize;
|
|
58
|
+
const bits = ctx.flags.bits || 8;
|
|
59
|
+
const rebuildIndex = ctx.flags.rebuildIndex ?? true;
|
|
60
|
+
output.writeln();
|
|
61
|
+
output.writeln(output.bold('Memory Compression'));
|
|
62
|
+
output.writeln(output.dim(`Level: ${level}, Target: ${target}, Quantize: ${quantize ? `${bits}-bit` : 'no'}`));
|
|
63
|
+
output.writeln();
|
|
64
|
+
const spinner = output.createSpinner({ text: 'Analyzing current storage...', spinner: 'dots' });
|
|
65
|
+
spinner.start();
|
|
66
|
+
try {
|
|
67
|
+
const result = await callMCPTool('memory_compress', {
|
|
68
|
+
level,
|
|
69
|
+
target,
|
|
70
|
+
quantize,
|
|
71
|
+
bits,
|
|
72
|
+
rebuildIndex,
|
|
73
|
+
});
|
|
74
|
+
spinner.succeed('Compression complete');
|
|
75
|
+
if (ctx.flags.format === 'json') {
|
|
76
|
+
output.printJson(result);
|
|
77
|
+
return { success: true, data: result };
|
|
78
|
+
}
|
|
79
|
+
output.writeln();
|
|
80
|
+
output.writeln(output.bold('Storage Comparison'));
|
|
81
|
+
output.printTable({
|
|
82
|
+
columns: [
|
|
83
|
+
{ key: 'category', header: 'Category', width: 15 },
|
|
84
|
+
{ key: 'before', header: 'Before', width: 12, align: 'right' },
|
|
85
|
+
{ key: 'after', header: 'After', width: 12, align: 'right' },
|
|
86
|
+
{ key: 'saved', header: 'Saved', width: 12, align: 'right' }
|
|
87
|
+
],
|
|
88
|
+
data: [
|
|
89
|
+
{ category: 'Vectors', before: result.before.vectorsSize, after: result.after.vectorsSize, saved: '-' },
|
|
90
|
+
{ category: 'Text', before: result.before.textSize, after: result.after.textSize, saved: '-' },
|
|
91
|
+
{ category: 'Patterns', before: result.before.patternsSize, after: result.after.patternsSize, saved: '-' },
|
|
92
|
+
{ category: 'Index', before: result.before.indexSize, after: result.after.indexSize, saved: '-' },
|
|
93
|
+
{ category: output.bold('Total'), before: result.before.totalSize, after: result.after.totalSize, saved: output.success(result.compression.formattedSaved) }
|
|
94
|
+
]
|
|
95
|
+
});
|
|
96
|
+
output.writeln();
|
|
97
|
+
output.printBox([
|
|
98
|
+
`Compression Ratio: ${result.compression.ratio.toFixed(2)}x`,
|
|
99
|
+
`Space Saved: ${result.compression.formattedSaved}`,
|
|
100
|
+
`Quantization: ${result.compression.quantizationApplied ? `Yes (${bits}-bit)` : 'No'}`,
|
|
101
|
+
`Index Rebuilt: ${result.compression.indexRebuilt ? 'Yes' : 'No'}`,
|
|
102
|
+
`Duration: ${(result.duration / 1000).toFixed(1)}s`
|
|
103
|
+
].join('\n'), 'Results');
|
|
104
|
+
if (result.performance) {
|
|
105
|
+
output.writeln();
|
|
106
|
+
output.writeln(output.bold('Performance Impact'));
|
|
107
|
+
output.printList([
|
|
108
|
+
`Search latency: ${result.performance.searchLatencyBefore.toFixed(2)}ms → ${result.performance.searchLatencyAfter.toFixed(2)}ms`,
|
|
109
|
+
`Speedup: ${output.success(result.performance.searchSpeedup)}`
|
|
110
|
+
]);
|
|
111
|
+
}
|
|
112
|
+
return { success: true, data: result };
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
spinner.fail('Compression failed');
|
|
116
|
+
if (error instanceof MCPClientError) {
|
|
117
|
+
output.printError(`Compression error: ${error.message}`);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
output.printError(`Unexpected error: ${String(error)}`);
|
|
121
|
+
}
|
|
122
|
+
return { success: false, exitCode: 1 };
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
// Export command
|
|
127
|
+
export const exportCommand = {
|
|
128
|
+
name: 'export',
|
|
129
|
+
description: 'Export memory to file',
|
|
130
|
+
options: [
|
|
131
|
+
{
|
|
132
|
+
name: 'output',
|
|
133
|
+
short: 'o',
|
|
134
|
+
description: 'Output file path',
|
|
135
|
+
type: 'string',
|
|
136
|
+
required: true
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
name: 'format',
|
|
140
|
+
short: 'f',
|
|
141
|
+
description: 'Export format (json, csv, binary, okf)',
|
|
142
|
+
type: 'string',
|
|
143
|
+
choices: ['json', 'csv', 'binary', 'okf'],
|
|
144
|
+
default: 'json'
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
name: 'namespace',
|
|
148
|
+
short: 'n',
|
|
149
|
+
description: 'Export specific namespace',
|
|
150
|
+
type: 'string'
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
name: 'include-vectors',
|
|
154
|
+
description: 'Include vector embeddings',
|
|
155
|
+
type: 'boolean',
|
|
156
|
+
default: true
|
|
157
|
+
}
|
|
158
|
+
],
|
|
159
|
+
examples: [
|
|
160
|
+
{ command: 'monomind memory export -o ./backup.json', description: 'Export all to JSON' },
|
|
161
|
+
{ command: 'monomind memory export -o ./data.csv -f csv', description: 'Export to CSV' },
|
|
162
|
+
{ command: 'monomind memory export -o ./knowledge -f okf', description: 'Export as OKF bundle (directory of .md files)' }
|
|
163
|
+
],
|
|
164
|
+
action: async (ctx) => {
|
|
165
|
+
const outputPath = ctx.flags.output;
|
|
166
|
+
const format = ctx.flags.format || 'json';
|
|
167
|
+
if (!outputPath) {
|
|
168
|
+
output.printError('Output path is required. Use --output or -o');
|
|
169
|
+
return { success: false, exitCode: 1 };
|
|
170
|
+
}
|
|
171
|
+
output.printInfo(`Exporting memory to ${outputPath}...`);
|
|
172
|
+
// OKF bundle: native export — directory of .md files with YAML frontmatter
|
|
173
|
+
if (format === 'okf') {
|
|
174
|
+
try {
|
|
175
|
+
const fs = await import('fs');
|
|
176
|
+
const path = await import('path');
|
|
177
|
+
const { listEntries, getEntry } = await import('../memory/memory-initializer.js');
|
|
178
|
+
const namespace = ctx.flags.namespace;
|
|
179
|
+
const listed = await listEntries({ namespace, limit: 10000 });
|
|
180
|
+
if (!listed.success) {
|
|
181
|
+
output.printError(`Failed to list entries: ${listed.error}`);
|
|
182
|
+
return { success: false, exitCode: 1 };
|
|
183
|
+
}
|
|
184
|
+
let written = 0;
|
|
185
|
+
for (const entry of listed.entries) {
|
|
186
|
+
const got = await getEntry({ key: entry.key, namespace: entry.namespace });
|
|
187
|
+
if (!got.found || !got.entry)
|
|
188
|
+
continue;
|
|
189
|
+
const { key, namespace: ns, content, tags, createdAt } = got.entry;
|
|
190
|
+
const safeKey = key.replace(/[/\\:*?"<>|]/g, '-');
|
|
191
|
+
const dir = path.join(outputPath, ns);
|
|
192
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
193
|
+
const yamlEscape = (s) => s.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
194
|
+
const tagsLine = tags.length > 0 ? `tags: [${tags.join(', ')}]\n` : '';
|
|
195
|
+
const md = `---\ntype: Memory\nkey: "${yamlEscape(key)}"\nnamespace: "${yamlEscape(ns)}"\n${tagsLine}timestamp: ${createdAt}\n---\n\n${content}`;
|
|
196
|
+
fs.writeFileSync(path.join(dir, `${safeKey}.md`), md, 'utf-8');
|
|
197
|
+
written++;
|
|
198
|
+
}
|
|
199
|
+
output.printSuccess(`Exported ${written} entries to ${outputPath}`);
|
|
200
|
+
if (listed.total > 10000) {
|
|
201
|
+
output.printInfo(`Note: only first 10000 of ${listed.total} entries exported`);
|
|
202
|
+
}
|
|
203
|
+
return { success: true, data: { written, outputPath } };
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
output.printError(`OKF export error: ${String(error)}`);
|
|
207
|
+
return { success: false, exitCode: 1 };
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
try {
|
|
211
|
+
const result = await callMCPTool('memory_export', {
|
|
212
|
+
outputPath,
|
|
213
|
+
format,
|
|
214
|
+
namespace: ctx.flags.namespace,
|
|
215
|
+
includeVectors: ctx.flags.includeVectors ?? true,
|
|
216
|
+
});
|
|
217
|
+
output.printSuccess(`Exported to ${result.outputPath}`);
|
|
218
|
+
output.printList([
|
|
219
|
+
`Entries: ${result.exported.entries}`,
|
|
220
|
+
`Vectors: ${result.exported.vectors}`,
|
|
221
|
+
`Patterns: ${result.exported.patterns}`,
|
|
222
|
+
`File size: ${result.fileSize}`
|
|
223
|
+
]);
|
|
224
|
+
return { success: true, data: result };
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
if (error instanceof MCPClientError) {
|
|
228
|
+
output.printError(`Export error: ${error.message}`);
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
output.printError(`Unexpected error: ${String(error)}`);
|
|
232
|
+
}
|
|
233
|
+
return { success: false, exitCode: 1 };
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
// Import command
|
|
238
|
+
export const importCommand = {
|
|
239
|
+
name: 'import',
|
|
240
|
+
description: 'Import memory from file',
|
|
241
|
+
options: [
|
|
242
|
+
{
|
|
243
|
+
name: 'input',
|
|
244
|
+
short: 'i',
|
|
245
|
+
description: 'Input file path',
|
|
246
|
+
type: 'string',
|
|
247
|
+
required: true
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
name: 'merge',
|
|
251
|
+
short: 'm',
|
|
252
|
+
description: 'Merge with existing (skip duplicates)',
|
|
253
|
+
type: 'boolean',
|
|
254
|
+
default: true
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
name: 'namespace',
|
|
258
|
+
short: 'n',
|
|
259
|
+
description: 'Import into specific namespace',
|
|
260
|
+
type: 'string'
|
|
261
|
+
}
|
|
262
|
+
],
|
|
263
|
+
examples: [
|
|
264
|
+
{ command: 'monomind memory import -i ./backup.json', description: 'Import from file' },
|
|
265
|
+
{ command: 'monomind memory import -i ./data.json -n archive', description: 'Import to namespace' }
|
|
266
|
+
],
|
|
267
|
+
action: async (ctx) => {
|
|
268
|
+
const inputPath = ctx.flags.input || ctx.args[0];
|
|
269
|
+
if (!inputPath) {
|
|
270
|
+
output.printError('Input path is required. Use --input or -i');
|
|
271
|
+
return { success: false, exitCode: 1 };
|
|
272
|
+
}
|
|
273
|
+
output.printInfo(`Importing memory from ${inputPath}...`);
|
|
274
|
+
// OKF bundle: native import — detect directory of .md files with YAML frontmatter
|
|
275
|
+
const fsCheck = await import('fs');
|
|
276
|
+
const isDir = fsCheck.existsSync(inputPath) && fsCheck.statSync(inputPath).isDirectory();
|
|
277
|
+
if (isDir) {
|
|
278
|
+
try {
|
|
279
|
+
const fs = await import('fs');
|
|
280
|
+
const path = await import('path');
|
|
281
|
+
const { storeEntry } = await import('../memory/memory-initializer.js');
|
|
282
|
+
function parseOkfFrontmatter(raw) {
|
|
283
|
+
if (!raw.startsWith('---\n'))
|
|
284
|
+
return { meta: {}, body: raw };
|
|
285
|
+
const end = raw.indexOf('\n---\n', 4);
|
|
286
|
+
if (end === -1)
|
|
287
|
+
return { meta: {}, body: raw };
|
|
288
|
+
const meta = {};
|
|
289
|
+
for (const line of raw.slice(4, end).split('\n')) {
|
|
290
|
+
const colon = line.indexOf(':');
|
|
291
|
+
if (colon <= 0)
|
|
292
|
+
continue;
|
|
293
|
+
const k = line.slice(0, colon).trim();
|
|
294
|
+
const rawV = line.slice(colon + 1).trim();
|
|
295
|
+
const isQuoted = rawV.startsWith('"') && rawV.endsWith('"') && rawV.length >= 2;
|
|
296
|
+
const v = isQuoted ? rawV.slice(1, -1).replace(/\\(["\\])/g, '$1') : rawV;
|
|
297
|
+
if (v.startsWith('[') && v.endsWith(']')) {
|
|
298
|
+
meta[k] = v.slice(1, -1).split(',').map(s => s.trim()).filter(Boolean);
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
meta[k] = v;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return { meta, body: raw.slice(end + 5) };
|
|
305
|
+
}
|
|
306
|
+
function findMdFiles(dir) {
|
|
307
|
+
const results = [];
|
|
308
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
309
|
+
const full = path.join(dir, entry.name);
|
|
310
|
+
if (entry.isDirectory())
|
|
311
|
+
results.push(...findMdFiles(full));
|
|
312
|
+
else if (entry.name.endsWith('.md'))
|
|
313
|
+
results.push(full);
|
|
314
|
+
}
|
|
315
|
+
return results;
|
|
316
|
+
}
|
|
317
|
+
const overrideNs = ctx.flags.namespace;
|
|
318
|
+
const merge = ctx.flags.merge ?? true;
|
|
319
|
+
const files = findMdFiles(inputPath);
|
|
320
|
+
let imported = 0, skipped = 0;
|
|
321
|
+
const start = Date.now();
|
|
322
|
+
for (const file of files) {
|
|
323
|
+
const raw = fs.readFileSync(file, 'utf-8');
|
|
324
|
+
const { meta, body } = parseOkfFrontmatter(raw);
|
|
325
|
+
const key = meta['key'] || path.basename(file, '.md');
|
|
326
|
+
const ns = overrideNs || meta['namespace'] || path.basename(path.dirname(file));
|
|
327
|
+
const tags = Array.isArray(meta['tags']) ? meta['tags'] : meta['tags'] ? [meta['tags']] : [];
|
|
328
|
+
const result = await storeEntry({ key, value: body.trim(), namespace: ns, tags, upsert: !merge });
|
|
329
|
+
if (result.success)
|
|
330
|
+
imported++;
|
|
331
|
+
else
|
|
332
|
+
skipped++;
|
|
333
|
+
}
|
|
334
|
+
output.printSuccess(`Imported ${imported} entries from ${inputPath}`);
|
|
335
|
+
if (skipped > 0)
|
|
336
|
+
output.printInfo(`Skipped ${skipped} entries (duplicates or errors)`);
|
|
337
|
+
output.printInfo(`Duration: ${Date.now() - start}ms`);
|
|
338
|
+
return { success: true, data: { imported, skipped } };
|
|
339
|
+
}
|
|
340
|
+
catch (error) {
|
|
341
|
+
output.printError(`OKF import error: ${String(error)}`);
|
|
342
|
+
return { success: false, exitCode: 1 };
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
try {
|
|
346
|
+
const result = await callMCPTool('memory_import', {
|
|
347
|
+
inputPath,
|
|
348
|
+
merge: ctx.flags.merge ?? true,
|
|
349
|
+
namespace: ctx.flags.namespace,
|
|
350
|
+
});
|
|
351
|
+
output.printSuccess(`Imported from ${result.inputPath}`);
|
|
352
|
+
output.printList([
|
|
353
|
+
`Entries: ${result.imported.entries}`,
|
|
354
|
+
`Vectors: ${result.imported.vectors}`,
|
|
355
|
+
`Patterns: ${result.imported.patterns}`,
|
|
356
|
+
`Skipped (duplicates): ${result.skipped}`,
|
|
357
|
+
`Duration: ${result.duration}ms`
|
|
358
|
+
]);
|
|
359
|
+
return { success: true, data: result };
|
|
360
|
+
}
|
|
361
|
+
catch (error) {
|
|
362
|
+
if (error instanceof MCPClientError) {
|
|
363
|
+
output.printError(`Import error: ${error.message}`);
|
|
364
|
+
}
|
|
365
|
+
else {
|
|
366
|
+
output.printError(`Unexpected error: ${String(error)}`);
|
|
367
|
+
}
|
|
368
|
+
return { success: false, exitCode: 1 };
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
//# sourceMappingURL=memory-transfer.js.map
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* CLI Memory Command
|
|
3
3
|
* Memory operations for LanceDB integration
|
|
4
|
+
*
|
|
5
|
+
* Split into sub-modules:
|
|
6
|
+
* memory-crud.ts — store, retrieve, search
|
|
7
|
+
* memory-list.ts — list, edit, templates
|
|
8
|
+
* memory-admin.ts — delete, stats, configure, cleanup
|
|
9
|
+
* memory-transfer.ts — compress, export, import
|
|
4
10
|
*/
|
|
5
11
|
import type { Command } from '../types.js';
|
|
6
12
|
export declare const memoryCommand: Command;
|