mindferry 0.0.0-stage → 0.2.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.
- package/LICENSE +21 -0
- package/README.md +182 -2
- package/README.zh-CN.md +165 -0
- package/bin/mindferry.mjs +301 -0
- package/examples/demo-en/chatgpt-conversations.json +72 -0
- package/examples/demo-en/chatgpt-copied.txt +8 -0
- package/examples/demo-en/claude-conversations.json +25 -0
- package/examples/demo-en/claude-memories.json +6 -0
- package/examples/demo-en/deepseek-conversations.json +39 -0
- package/examples/demo-en/gemini-MyActivity.json +18 -0
- package/examples/demo-en/grok-export.json +27 -0
- package/examples/exports/README.md +4 -0
- package/examples/exports/chatgpt-conversations.json +21 -0
- package/examples/exports/claude-conversations.json +13 -0
- package/examples/exports/claude-memories.json +3 -0
- package/examples/exports/deepseek-conversations.json +12 -0
- package/examples/exports/gemini-MyActivity.json +5 -0
- package/examples/exports/grok-export.json +11 -0
- package/examples/exports/open-webui-export.json +13 -0
- package/examples/scheduler/crontab.txt +2 -0
- package/examples/scheduler/io.github.mindferry.sync.plist +18 -0
- package/examples/single-chats/chatgpt-copied.txt +8 -0
- package/examples/single-chats/chatgpt-saved-page.html +4 -0
- package/examples/single-chats/claude-chat.md +7 -0
- package/package.json +55 -4
- package/src/connect.mjs +204 -0
- package/src/core/archive.mjs +144 -0
- package/src/core/card.mjs +64 -0
- package/src/core/classify.mjs +81 -0
- package/src/core/clients.mjs +63 -0
- package/src/core/errors.mjs +146 -0
- package/src/core/export.mjs +53 -0
- package/src/core/extract.mjs +183 -0
- package/src/core/generator.mjs +98 -0
- package/src/core/hub.mjs +637 -0
- package/src/core/llm.mjs +77 -0
- package/src/core/merge.mjs +95 -0
- package/src/core/profile.mjs +175 -0
- package/src/core/rules.mjs +88 -0
- package/src/core/store.mjs +109 -0
- package/src/core/text.mjs +82 -0
- package/src/demo.mjs +30 -0
- package/src/importers/index.mjs +366 -0
- package/src/importers/zip.mjs +48 -0
- package/src/mcp/server.mjs +272 -0
- package/src/remote.mjs +180 -0
- package/src/ui/server.mjs +281 -0
- package/src/ui/static/app.js +1037 -0
- package/src/ui/static/index.html +269 -0
- package/src/ui/static/logo.svg +16 -0
- package/src/ui/static/mascot-busy.svg +35 -0
- package/src/ui/static/mascot-happy.svg +27 -0
- package/src/ui/static/mascot-idle.svg +26 -0
- package/src/ui/static/mascot-oops.svg +26 -0
- package/src/ui/static/style.css +382 -0
- package/src/version.mjs +1 -0
- package/src/watch.mjs +80 -0
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// mindferry — sync what your AIs know about you. Run with no arguments to open the app.
|
|
3
|
+
const major = Number(process.versions.node.split('.')[0]);
|
|
4
|
+
if (major < 22) {
|
|
5
|
+
const zh = /^zh/i.test(process.env.LANG || '');
|
|
6
|
+
console.error(zh
|
|
7
|
+
? `需要 Node.js 22 或更新版本,你现在是 ${process.version}。下一步:到 https://nodejs.org 下载安装「LTS」版本,再重新运行。`
|
|
8
|
+
: `MindFerry needs Node.js 22 or newer; you have ${process.version}. Next step: install the "LTS" version from https://nodejs.org and run it again.`);
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const { resolve, join, basename } = await import('node:path');
|
|
13
|
+
const { mkdtempSync, readFileSync } = await import('node:fs');
|
|
14
|
+
const { tmpdir } = await import('node:os');
|
|
15
|
+
// Accept both "--data dir" and "--data=dir".
|
|
16
|
+
const args = process.argv.slice(2).flatMap((a) => (/^--[a-z-]+=/.test(a) ? [a.slice(0, a.indexOf('=')), a.slice(a.indexOf('=') + 1)] : [a]));
|
|
17
|
+
// "mindferry items | head" closes the pipe early; that is not an error.
|
|
18
|
+
process.stdout.on('error', (e) => { if (e.code === 'EPIPE') process.exit(0); throw e; });
|
|
19
|
+
const KNOWN_FLAGS = new Set(['--port', '--data', '--lang', '--client', '--q', '--source', '--hours', '--no-open', '--yes', '--json', '--help', '--version', '--for-good']);
|
|
20
|
+
const unknownFlag = args.find((a) => a.startsWith('--') && a !== '--' && !KNOWN_FLAGS.has(a));
|
|
21
|
+
if (unknownFlag) {
|
|
22
|
+
const zh = /^zh/i.test(process.env.LANG || '') || args.includes('zh');
|
|
23
|
+
console.error(zh ? `不认识的选项:${unknownFlag}。运行 mindferry help 查看全部选项。` : `Unknown option: ${unknownFlag}. Run mindferry help to see all options.`);
|
|
24
|
+
process.exit(2);
|
|
25
|
+
}
|
|
26
|
+
const flag = (name) => { const i = args.indexOf('--' + name); return i >= 0 ? args[i + 1] : undefined; };
|
|
27
|
+
const has = (name) => args.includes('--' + name);
|
|
28
|
+
const BOOL = new Set(['--no-open', '--yes', '--json', '--help', '--version', '--for-good']);
|
|
29
|
+
const positional = [];
|
|
30
|
+
for (let i = 0; i < args.length; i++) {
|
|
31
|
+
if (args[i].startsWith('--')) { if (!BOOL.has(args[i])) i++; continue; }
|
|
32
|
+
positional.push(args[i]);
|
|
33
|
+
}
|
|
34
|
+
let [cmd, ...rest] = positional;
|
|
35
|
+
if (!cmd) cmd = has('help') || has('version') ? (has('version') ? 'version' : 'help') : 'start';
|
|
36
|
+
|
|
37
|
+
if (flag('data')) process.env.MINDFERRY_DATA_DIR = resolve(flag('data'));
|
|
38
|
+
if (cmd === 'demo') {
|
|
39
|
+
process.env.MINDFERRY_DATA_DIR = mkdtempSync(join(tmpdir(), 'mindferry-demo-'));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const { Hub } = await import('../src/core/hub.mjs');
|
|
43
|
+
const { CLIENTS, CLIENT_IDS } = await import('../src/core/clients.mjs');
|
|
44
|
+
const { toFriendly, SYSTEM_LANG } = await import('../src/core/errors.mjs');
|
|
45
|
+
const { VERSION } = await import('../src/version.mjs');
|
|
46
|
+
// Language: --lang, else the language last chosen in the window, else the system's.
|
|
47
|
+
let storedLang = null;
|
|
48
|
+
// Only read a store that already exists: "mindferry --help" must not create a data folder.
|
|
49
|
+
try {
|
|
50
|
+
const { defaultDataDir } = await import('../src/core/store.mjs');
|
|
51
|
+
const { existsSync } = await import('node:fs');
|
|
52
|
+
if (existsSync(join(defaultDataDir(), 'store.json'))) storedLang = new Hub().read().settings?.uiLang || null;
|
|
53
|
+
} catch {}
|
|
54
|
+
const lang = flag('lang') === 'en' || flag('lang') === 'zh' ? flag('lang') : storedLang || SYSTEM_LANG;
|
|
55
|
+
const t = (z, e) => (lang === 'zh' ? z : e);
|
|
56
|
+
|
|
57
|
+
const HELP = `MindFerry ${VERSION} — ${t('同步一次,各聊各的,过段时间再同步', 'sync once, chat separately, sync again later')}
|
|
58
|
+
|
|
59
|
+
mindferry ${t('打开 MindFerry(浏览器里的本地界面)', 'open MindFerry (a local page in your browser)')}
|
|
60
|
+
mindferry start --port 7799 ${t('换一个端口打开(7788 被占用时)', 'open on another port (if 7788 is taken)')}
|
|
61
|
+
mindferry demo ${t('用虚构人物的示例数据试玩,不碰你的数据', 'try it with a made-up person — your data is untouched')}
|
|
62
|
+
mindferry import <file> ${t('导入导出文件或单个对话(.zip .json .html .md .txt)', 'import an export or a single chat (.zip .json .html .md .txt)')}
|
|
63
|
+
mindferry import - --client chatgpt ${t('从标准输入粘贴一段对话', 'paste a chat from stdin')}
|
|
64
|
+
mindferry sync ${t('执行一次同步', 'run one sync')}
|
|
65
|
+
mindferry status ${t('每个 AI 的上次同步时间和新增条数', 'last sync time and counts per AI')}
|
|
66
|
+
mindferry card <ai> ${t('打印某个 AI 的上下文卡', "print an AI's context card")}
|
|
67
|
+
mindferry profile [ai] ${t('打印「关于我」档案(给某个 AI 时按它的权限删减)', 'print the "About me" profile (trimmed to what an AI may see)')}
|
|
68
|
+
mindferry items [--json] [--q 词] ${t('列出全部信息', 'list all facts')}
|
|
69
|
+
mindferry undo ${t('撤回最近一次同步', 'undo the last sync')}
|
|
70
|
+
mindferry forget <id> [--for-good] ${t('删除一条(进「最近删除」;--for-good 连原句一起彻底删)', 'delete a fact (to "Recently deleted"; --for-good also erases its sentence)')}
|
|
71
|
+
mindferry restore <id> ${t('从「最近删除」找回', 'bring a fact back from "Recently deleted"')}
|
|
72
|
+
mindferry lock|unlock <id> ${t('永不分享 / 恢复分享', 'never share / share again')}
|
|
73
|
+
mindferry pause|resume <ai> ${t('暂停或恢复给某个 AI', 'pause or resume an AI')}
|
|
74
|
+
mindferry rule <ai> summary|everything ${t('设置某个 AI 能看多少', 'set how much an AI may see')}
|
|
75
|
+
mindferry conflicts ${t('列出有新说法的信息', 'list facts that changed')}
|
|
76
|
+
mindferry export <dir|file.md|file.json> ${t('导出全部数据(文件夹 = Obsidian/Logseq 笔记库)', 'export everything (a folder = an Obsidian / Logseq vault)')}
|
|
77
|
+
mindferry connect <ai> ${t('把本地 AI 接到 MindFerry(可撤销)', 'connect a local AI app (reversible)')}
|
|
78
|
+
mindferry disconnect <ai> ${t('撤销接入', 'undo connect')}
|
|
79
|
+
mindferry mcp --client <ai> ${t('MCP 服务(由 AI 应用调用)', 'MCP server (started by your AI app)')}
|
|
80
|
+
|
|
81
|
+
--port <n> --no-open --data <dir> --lang zh|en
|
|
82
|
+
|
|
83
|
+
${t('本地 AI', 'Local AIs')}: ${CLIENTS.filter((c) => c.kind === 'mcp').map((c) => c.id).join(', ')}
|
|
84
|
+
${t('网页 AI', 'Web AIs')}: ${CLIENTS.filter((c) => c.kind === 'web').map((c) => c.id).join(', ')}
|
|
85
|
+
${t('数据目录', 'Data')}: ${process.env.MINDFERRY_DATA_DIR || '~/.mindferry'}
|
|
86
|
+
`;
|
|
87
|
+
|
|
88
|
+
const fmt = (iso) => (iso ? new Date(iso).toLocaleString(lang === 'zh' ? 'zh-CN' : 'en-US') : t('从未', 'never'));
|
|
89
|
+
// Accept "ChatGPT", "claude code", "Claude-Code"…; suggest the closest id on a typo.
|
|
90
|
+
const ALIASES = { claude: 'claude-web', 'claude.ai': 'claude-web', gemini: 'gemini-web', grok: 'grok-web', gpt: 'chatgpt', 'claude-cli': 'claude-code', ollama: 'local-llm', 'open-webui': 'local-llm' };
|
|
91
|
+
const needClient = (raw, kind) => {
|
|
92
|
+
const pool = CLIENTS.filter((c) => !kind || c.kind === kind).map((c) => c.id);
|
|
93
|
+
const eg = kind === 'web' ? 'chatgpt' : 'codex';
|
|
94
|
+
if (!raw) {
|
|
95
|
+
console.error(t(`请写明是哪个 AI,例如:mindferry ${cmd} ${eg}`, `Say which AI, e.g. mindferry ${cmd} ${eg}`));
|
|
96
|
+
console.error(t('可以用:', 'Choose from: ') + pool.join(', '));
|
|
97
|
+
process.exit(2);
|
|
98
|
+
}
|
|
99
|
+
let id = String(raw).trim().toLowerCase().replace(/[\s_]+/g, '-');
|
|
100
|
+
id = ALIASES[id] || id;
|
|
101
|
+
if (pool.includes(id)) return id;
|
|
102
|
+
const dist = (a, b) => { const d = Array.from({ length: b.length + 1 }, (_, i) => i); for (let i = 1; i <= a.length; i++) { let prev = d[0]; d[0] = i; for (let j = 1; j <= b.length; j++) { const tmp = d[j]; d[j] = Math.min(d[j] + 1, d[j - 1] + 1, prev + (a[i - 1] === b[j - 1] ? 0 : 1)); prev = tmp; } } return d[b.length]; };
|
|
103
|
+
// Prefer ids that share the typed start ("gemni" → gemini-web / gemini-cli), then edit distance.
|
|
104
|
+
const head = id.slice(0, 3);
|
|
105
|
+
const best = pool.map((p) => [p, dist(id, p.slice(0, Math.max(id.length, 3))) - (p.startsWith(head) ? 1 : 0)]).sort((a, b) => a[1] - b[1])[0];
|
|
106
|
+
const why = CLIENT_IDS.includes(id) ? t(`「${raw}」是网页 AI,不能这样接入`, `"${raw}" is a web AI and can't be connected this way`) : t(`不认识「${raw}」`, `Unknown AI "${raw}"`);
|
|
107
|
+
console.error('✗ ' + why + (best && best[1] <= 3 ? t(`。你是不是想写:${best[0]}`, `. Did you mean: ${best[0]}`) : ''));
|
|
108
|
+
console.error(t('可以用:', 'Choose from: ') + pool.join(', '));
|
|
109
|
+
process.exit(2);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// Find a fact by its id or the start of it (as printed by `mindferry items`).
|
|
113
|
+
const needItem = (raw, pool) => {
|
|
114
|
+
if (!raw) { console.error(t(`请写上信息的编号,先用 mindferry items 查看。`, `Give the fact's id; see them with mindferry items.`)); process.exit(2); }
|
|
115
|
+
const hits = pool.filter((i) => i.id === raw || i.id.startsWith(raw));
|
|
116
|
+
if (hits.length === 1) return hits[0].id;
|
|
117
|
+
console.error(hits.length ? t('有好几条以它开头,多写几个字符。', 'Several facts start with that; type a few more characters.') : t(`找不到「${raw}」。用 mindferry items 查看编号。`, `No fact "${raw}". See ids with mindferry items.`));
|
|
118
|
+
process.exit(2);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
try {
|
|
122
|
+
const hub = new Hub();
|
|
123
|
+
switch (cmd) {
|
|
124
|
+
case 'help': console.log(HELP); break;
|
|
125
|
+
case 'version': console.log(VERSION); break;
|
|
126
|
+
case 'sync': {
|
|
127
|
+
const r = await hub.sync();
|
|
128
|
+
console.log(t(`同步完成:处理 ${r.processed} 条,新增 ${r.added},更新 ${r.updated},冲突 ${r.conflicts}(以新的为准)`,
|
|
129
|
+
`Sync done: processed ${r.processed}, added ${r.added}, updated ${r.updated}, conflicts ${r.conflicts} (newer wins)`));
|
|
130
|
+
for (const [id, c] of Object.entries(r.perClient)) console.log(` ${id.padEnd(15)} ${t('收到', 'in')} +${c.in} ${t('待发', 'out')} +${c.out}`);
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
case 'status': {
|
|
134
|
+
const s = hub.status();
|
|
135
|
+
if (has('json')) { console.log(JSON.stringify(s, null, 2)); break; }
|
|
136
|
+
console.log(t(`事实 ${s.items} 条 · 对话消息 ${s.archive.messages} 条 · 待同步 ${s.inbox} · 未确认冲突 ${s.conflicts} · 上次同步 ${fmt(s.lastSyncAt)}`,
|
|
137
|
+
`${s.items} facts · ${s.archive.messages} archived messages · ${s.inbox} waiting for sync · ${s.conflicts} open conflicts · last sync ${fmt(s.lastSyncAt)}`));
|
|
138
|
+
for (const c of s.clients) {
|
|
139
|
+
if (!c.enabled) continue;
|
|
140
|
+
console.log(` ${c.paused ? '⏸' : '●'} ${c.id.padEnd(15)} ${fmt(c.lastSyncAt).padEnd(24)} ${t('收到', 'in')} +${c.lastIn} ${t('待发', 'out')} +${c.lastOut} ${t('权限', 'access')}: ${c.rule.preset}`);
|
|
141
|
+
}
|
|
142
|
+
console.log(t(`数据目录:${s.dataDir}`, `Data: ${s.dataDir}`));
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
case 'card': process.stdout.write(hub.card(needClient(rest[0])).text); break;
|
|
146
|
+
case 'profile': {
|
|
147
|
+
const id = rest[0] ? needClient(rest[0]) : null;
|
|
148
|
+
if (id && hub.read().clients[id]?.paused) { console.log(t(`${id} 已暂停:它现在什么都拿不到(mindferry resume ${id} 恢复)。下面是恢复后它会看到的:\n`, `${id} is paused: it gets nothing right now (mindferry resume ${id}). This is what it will see once resumed:\n`)); }
|
|
149
|
+
process.stdout.write(hub.profile(id, { lang }).text);
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
case 'items': {
|
|
153
|
+
const q = (flag('q') || '').toLowerCase();
|
|
154
|
+
const items = hub.read().items.filter((i) => i.status === 'active' && (!q || i.text.toLowerCase().includes(q)));
|
|
155
|
+
if (has('json')) console.log(JSON.stringify(items, null, 2));
|
|
156
|
+
else for (const i of items) console.log(`${i.id} ${i.locked ? '🔒 ' : ''}[${i.category}/${i.sensitivity}] ${i.text}`);
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
case 'undo': {
|
|
160
|
+
const r = await hub.undoSync();
|
|
161
|
+
console.log(t(`已撤回 ${fmt(r.at)} 的同步,移除了 ${r.removed} 条。`, `Undid the sync from ${fmt(r.at)}; removed ${r.removed} fact(s).`));
|
|
162
|
+
for (const f of r.facts || []) console.log(' - ' + f);
|
|
163
|
+
if (r.facts?.length) console.log(t(' 它们在「最近删除」里,还能找回。', ' They are in "Recently deleted" and can be brought back.'));
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
case 'forget':
|
|
167
|
+
case 'restore':
|
|
168
|
+
case 'lock':
|
|
169
|
+
case 'unlock': {
|
|
170
|
+
const trashed = hub.trash();
|
|
171
|
+
const active = hub.read().items.filter((i) => i.status === 'active');
|
|
172
|
+
const pool = cmd === 'restore' ? trashed : cmd === 'forget' && has('for-good') ? [...active, ...trashed] : active;
|
|
173
|
+
const id = needItem(rest[0], pool);
|
|
174
|
+
if (cmd === 'forget' && has('for-good')) {
|
|
175
|
+
await hub.forgetForGood(id);
|
|
176
|
+
console.log(t('已彻底删除,原句也从本机聊天存档里抹掉了。', 'Deleted for good; its sentence was erased from the local chat archive too.'));
|
|
177
|
+
} else if (cmd === 'forget') {
|
|
178
|
+
await hub.updateItem(id, { delete: true });
|
|
179
|
+
console.log(t('已删除,在「最近删除」里还能找回:mindferry restore ' + id, 'Deleted. It is in "Recently deleted": mindferry restore ' + id));
|
|
180
|
+
} else if (cmd === 'restore') {
|
|
181
|
+
await hub.restoreItem(id);
|
|
182
|
+
console.log(t('已找回。', 'Restored.'));
|
|
183
|
+
} else {
|
|
184
|
+
await hub.updateItem(id, { locked: cmd === 'lock' });
|
|
185
|
+
console.log(cmd === 'lock' ? t('已锁定:任何 AI 都拿不到这条。', 'Locked: no AI gets this fact.') : t('已恢复分享(按各 AI 的规则)。', 'Shared again (following each AI\'s rule).'));
|
|
186
|
+
}
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
case 'pause':
|
|
190
|
+
case 'resume': {
|
|
191
|
+
const id = needClient(rest[0]);
|
|
192
|
+
await hub.setPaused(id, cmd === 'pause');
|
|
193
|
+
console.log(cmd === 'pause' ? t(`已暂停:${id} 现在什么都拿不到。`, `Paused: ${id} gets nothing now.`) : t(`已恢复:${id}。`, `Resumed: ${id}.`));
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
case 'rule': {
|
|
197
|
+
const id = needClient(rest[0]);
|
|
198
|
+
const preset = String(rest[1] || '').toLowerCase();
|
|
199
|
+
if (!['summary', 'everything'].includes(preset)) {
|
|
200
|
+
console.error(t('写 summary(默认,只给安全的信息)或 everything(全部,含原始对话搜索)。细调请用界面里的「分享规则」。',
|
|
201
|
+
'Use summary (the default: safe facts only) or everything (all, including searching raw chats). For finer control use "Sharing rules" in the app.'));
|
|
202
|
+
process.exit(2);
|
|
203
|
+
}
|
|
204
|
+
const r = await hub.setRule(id, { preset });
|
|
205
|
+
console.log(t(`${id} 现在:${preset}`, `${id} is now: ${preset}`) + (r?.categories ? ` (${r.categories.join(', ')})` : ''));
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
case 'conflicts': {
|
|
209
|
+
const list = hub.read().items.filter((i) => i.status === 'active' && i.conflict && !i.conflict.acknowledged);
|
|
210
|
+
if (has('json')) { console.log(JSON.stringify(list, null, 2)); break; }
|
|
211
|
+
if (!list.length) console.log(t('没有新说法。', 'Nothing changed.'));
|
|
212
|
+
for (const i of list) console.log(`${i.id} 「${i.conflict.previousText}」 → 「${i.text}」`);
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
case 'export': {
|
|
216
|
+
const { toMarkdown, toFolder } = await import('../src/core/export.mjs');
|
|
217
|
+
const { writeFileSync } = await import('node:fs');
|
|
218
|
+
if (!rest[0]) { console.error(t('请写导出到哪里,例如:mindferry export ~/Desktop/mindferry-export', 'Say where, e.g. mindferry export ~/Desktop/mindferry-export')); process.exit(2); }
|
|
219
|
+
const target = resolve(rest[0]);
|
|
220
|
+
const data = hub.exportAll();
|
|
221
|
+
if (/\.json$/i.test(target)) writeFileSync(target, JSON.stringify(data, null, 2));
|
|
222
|
+
else if (/\.md$/i.test(target)) writeFileSync(target, toMarkdown(data, hub.profile(null, { lang }).text));
|
|
223
|
+
else toFolder(data, target, hub.profile(null, { lang }).text);
|
|
224
|
+
console.log(t(`✓ 已导出 ${data.facts.length} 条信息、${data.conversations.length} 条消息到 ${target}`, `✓ Exported ${data.facts.length} facts and ${data.conversations.length} messages to ${target}`));
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
case 'import': {
|
|
228
|
+
const { importFile, importText } = await import('../src/importers/index.mjs');
|
|
229
|
+
if (!rest[0]) { console.error(HELP); process.exit(2); }
|
|
230
|
+
const { statSync, readdirSync } = await import('node:fs');
|
|
231
|
+
const target = rest[0] === '-' ? null : resolve(rest[0]);
|
|
232
|
+
// A folder: import every file in it that looks like a chat export; skip the rest with a note.
|
|
233
|
+
if (target && statSync(target, { throwIfNoEntry: false })?.isDirectory()) {
|
|
234
|
+
const files = readdirSync(target).filter((f) => !f.startsWith('.')).map((f) => join(target, f)).filter((f) => statSync(f).isFile());
|
|
235
|
+
let ok = 0;
|
|
236
|
+
for (const f of files) {
|
|
237
|
+
try {
|
|
238
|
+
const r = await importFile(hub, f, { client: flag('client') });
|
|
239
|
+
ok++;
|
|
240
|
+
for (const [id, v] of Object.entries(r.imported)) console.log(`${basename(f)} → ${id}: ${t(`${v.messages} 条消息,${v.new} 条新信息`, `${v.messages} message(s), ${v.new} new fact(s)`)}`);
|
|
241
|
+
} catch (e) { console.log(t(`跳过 ${basename(f)}:`, `Skipped ${basename(f)}: `) + (e.message?.[lang] || e.message)); }
|
|
242
|
+
}
|
|
243
|
+
if (!ok) { console.error(t('这个文件夹里没有认得的聊天记录。', 'No chat exports were recognised in this folder.')); process.exit(1); }
|
|
244
|
+
const s2 = await hub.sync();
|
|
245
|
+
console.log(t(`已同步:新增 ${s2.added},更新 ${s2.updated}`, `Synced: ${s2.added} added, ${s2.updated} updated`));
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
const r = rest[0] === '-'
|
|
249
|
+
? await importText(hub, readFileSync(0, 'utf8'), { client: flag('client'), sync: true })
|
|
250
|
+
: await importFile(hub, target, { client: flag('client'), sync: true });
|
|
251
|
+
for (const [id, v] of Object.entries(r.imported)) {
|
|
252
|
+
console.log(t(`${id}:${v.messages} 条消息,提炼出 ${v.new} 条新信息(重复 ${v.duplicates})`, `${id}: ${v.messages} message(s), ${v.new} new fact(s) (${v.duplicates} already known)`));
|
|
253
|
+
}
|
|
254
|
+
if (r.sync) console.log(t(`已同步:新增 ${r.sync.added},更新 ${r.sync.updated}`, `Synced: ${r.sync.added} added, ${r.sync.updated} updated`));
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
case 'connect':
|
|
258
|
+
case 'disconnect': {
|
|
259
|
+
rest[0] = needClient(rest[0], 'mcp');
|
|
260
|
+
const { connect, disconnect } = await import('../src/connect.mjs');
|
|
261
|
+
const r = cmd === 'connect' ? connect(rest[0]) : disconnect(rest[0]);
|
|
262
|
+
await hub.setConnected(rest[0], cmd === 'connect');
|
|
263
|
+
if (cmd === 'connect') {
|
|
264
|
+
console.log(t(`✓ 已接入 ${rest[0]}(${r.how})`, `✓ Connected ${rest[0]} (${r.how})`));
|
|
265
|
+
if (r.backup) console.log(t(` 原配置已备份:${r.backup}`, ` Previous config backed up: ${r.backup}`));
|
|
266
|
+
if (r.restart) console.log(t(' 请重启这个应用,让它加载 MindFerry。', ' Restart that app so it loads MindFerry.'));
|
|
267
|
+
console.log(t(` 撤销:${r.undo}`, ` Undo: ${r.undo}`));
|
|
268
|
+
} else {
|
|
269
|
+
console.log(t(`✓ 已断开 ${rest[0]}`, `✓ Disconnected ${rest[0]}`));
|
|
270
|
+
}
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
case 'mcp': {
|
|
274
|
+
const { runMcp } = await import('../src/mcp/server.mjs');
|
|
275
|
+
if (!flag('client')) {
|
|
276
|
+
console.error(t('请用 --client 写明是哪个 AI 在连接,例如:mindferry mcp --client codex', 'Say which AI is connecting with --client, e.g. mindferry mcp --client codex'));
|
|
277
|
+
process.exit(2);
|
|
278
|
+
}
|
|
279
|
+
await runMcp(hub, needClient(flag('client')));
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
case 'start':
|
|
283
|
+
case 'demo': {
|
|
284
|
+
if (cmd === 'demo') {
|
|
285
|
+
const { loadDemo } = await import('../src/demo.mjs');
|
|
286
|
+
await loadDemo(hub, { lang });
|
|
287
|
+
console.log(t('演示模式:数据是虚构人物「林小雨」的,关掉后自动丢弃。', 'Demo mode: the data belongs to a made-up person ("Alex Moreno") and is thrown away afterwards.'));
|
|
288
|
+
}
|
|
289
|
+
const { startServer } = await import('../src/ui/server.mjs');
|
|
290
|
+
await startServer(hub, { port: Number(flag('port')) || 7788, open: !has('no-open'), lang, demo: cmd === 'demo' });
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
default:
|
|
294
|
+
console.error(t(`不认识的命令「${cmd}」。`, `Unknown command "${cmd}".`));
|
|
295
|
+
console.log(HELP);
|
|
296
|
+
process.exit(2);
|
|
297
|
+
}
|
|
298
|
+
} catch (e) {
|
|
299
|
+
console.error('✗ ' + toFriendly(e).text(lang));
|
|
300
|
+
process.exit(1);
|
|
301
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"title": "Sorting helper",
|
|
4
|
+
"create_time": 1735689600,
|
|
5
|
+
"update_time": 1735689700,
|
|
6
|
+
"mapping": {
|
|
7
|
+
"a": {
|
|
8
|
+
"message": {
|
|
9
|
+
"author": {
|
|
10
|
+
"role": "user"
|
|
11
|
+
},
|
|
12
|
+
"content": {
|
|
13
|
+
"content_type": "text",
|
|
14
|
+
"parts": [
|
|
15
|
+
"Hi, I'm Alex Moreno, a frontend engineer. I live in Austin. Can you write me a quicksort?"
|
|
16
|
+
]
|
|
17
|
+
},
|
|
18
|
+
"create_time": 1735689600
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"b": {
|
|
22
|
+
"message": {
|
|
23
|
+
"author": {
|
|
24
|
+
"role": "assistant"
|
|
25
|
+
},
|
|
26
|
+
"content": {
|
|
27
|
+
"content_type": "text",
|
|
28
|
+
"parts": [
|
|
29
|
+
"Sure! Here's a quicksort in TypeScript…"
|
|
30
|
+
]
|
|
31
|
+
},
|
|
32
|
+
"create_time": 1735689610
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"c": {
|
|
36
|
+
"message": {
|
|
37
|
+
"author": {
|
|
38
|
+
"role": "user"
|
|
39
|
+
},
|
|
40
|
+
"content": {
|
|
41
|
+
"content_type": "text",
|
|
42
|
+
"parts": [
|
|
43
|
+
"I'm allergic to peanuts, suggest some snacks. I love strong coffee."
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
"create_time": 1735689650
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"title": "Budget",
|
|
53
|
+
"create_time": 1736000000,
|
|
54
|
+
"update_time": 1736000100,
|
|
55
|
+
"mapping": {
|
|
56
|
+
"x": {
|
|
57
|
+
"message": {
|
|
58
|
+
"author": {
|
|
59
|
+
"role": "user"
|
|
60
|
+
},
|
|
61
|
+
"content": {
|
|
62
|
+
"content_type": "text",
|
|
63
|
+
"parts": [
|
|
64
|
+
"My salary is $95k and my wife works too. Please keep answers short."
|
|
65
|
+
]
|
|
66
|
+
},
|
|
67
|
+
"create_time": 1736000000
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
]
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"uuid": "00000000-0000-4000-8000-000000000101",
|
|
4
|
+
"name": "Side project",
|
|
5
|
+
"created_at": "2025-03-01T10:00:00Z",
|
|
6
|
+
"updated_at": "2025-03-01T10:30:00Z",
|
|
7
|
+
"chat_messages": [
|
|
8
|
+
{
|
|
9
|
+
"sender": "human",
|
|
10
|
+
"text": "I'm building an open-source notes app called Pebble. I'm good at TypeScript and React.",
|
|
11
|
+
"created_at": "2025-03-01T10:00:00Z"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"sender": "assistant",
|
|
15
|
+
"text": "Love that idea!",
|
|
16
|
+
"created_at": "2025-03-01T10:00:05Z"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"sender": "human",
|
|
20
|
+
"text": "I moved to Denver last month.",
|
|
21
|
+
"created_at": "2025-03-01T10:20:00Z"
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
]
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "ds-1",
|
|
4
|
+
"title": "Spanish",
|
|
5
|
+
"inserted_at": "2025-05-02T12:00:00+08:00",
|
|
6
|
+
"mapping": {
|
|
7
|
+
"root": {
|
|
8
|
+
"id": "root",
|
|
9
|
+
"message": null
|
|
10
|
+
},
|
|
11
|
+
"1": {
|
|
12
|
+
"id": "1",
|
|
13
|
+
"message": {
|
|
14
|
+
"inserted_at": "2025-05-02T12:00:00+08:00",
|
|
15
|
+
"model": "deepseek-chat",
|
|
16
|
+
"fragments": [
|
|
17
|
+
{
|
|
18
|
+
"type": "REQUEST",
|
|
19
|
+
"content": "I'm learning Spanish for a trip to Mexico in June. I practice every morning."
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"2": {
|
|
25
|
+
"id": "2",
|
|
26
|
+
"message": {
|
|
27
|
+
"inserted_at": "2025-05-02T12:00:09+08:00",
|
|
28
|
+
"model": "deepseek-chat",
|
|
29
|
+
"fragments": [
|
|
30
|
+
{
|
|
31
|
+
"type": "RESPONSE",
|
|
32
|
+
"content": "¡Genial! Here is a plan…"
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"header": "Gemini Apps",
|
|
4
|
+
"title": "Prompted I love hiking and go to the hills most weekends. Any trails near Austin?",
|
|
5
|
+
"time": "2025-02-10T08:00:00.000Z",
|
|
6
|
+
"products": [
|
|
7
|
+
"Gemini Apps"
|
|
8
|
+
]
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"header": "Gemini Apps",
|
|
12
|
+
"title": "Prompted My SSN is 078-05-1120, is that format right?",
|
|
13
|
+
"time": "2025-02-11T08:00:00.000Z",
|
|
14
|
+
"products": [
|
|
15
|
+
"Gemini Apps"
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
]
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"conversations": [
|
|
3
|
+
{
|
|
4
|
+
"conversation": {
|
|
5
|
+
"id": "g1",
|
|
6
|
+
"title": "Trip",
|
|
7
|
+
"create_time": "2025-04-01T09:00:00Z"
|
|
8
|
+
},
|
|
9
|
+
"responses": [
|
|
10
|
+
{
|
|
11
|
+
"response": {
|
|
12
|
+
"sender": "human",
|
|
13
|
+
"message": "I'm vegetarian. I take medication for anxiety, so keep plans calm.",
|
|
14
|
+
"create_time": "2025-04-01T09:00:00Z"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"response": {
|
|
19
|
+
"sender": "ASSISTANT",
|
|
20
|
+
"message": "Got it!",
|
|
21
|
+
"create_time": "2025-04-01T09:00:03Z"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"title": "排序函数",
|
|
4
|
+
"create_time": 1735689600,
|
|
5
|
+
"update_time": 1735689700,
|
|
6
|
+
"mapping": {
|
|
7
|
+
"a": { "message": { "author": { "role": "system" }, "content": { "content_type": "text", "parts": [""] }, "create_time": null } },
|
|
8
|
+
"b": { "message": { "author": { "role": "user" }, "content": { "content_type": "text", "parts": ["你好,我叫林小雨,我是一名前端工程师。我住在杭州。帮我写一个快速排序?"] }, "create_time": 1735689600 } },
|
|
9
|
+
"c": { "message": { "author": { "role": "assistant" }, "content": { "content_type": "text", "parts": ["好的,我住在服务器里。这是代码……"] }, "create_time": 1735689610 } },
|
|
10
|
+
"d": { "message": { "author": { "role": "user" }, "content": { "content_type": "text", "parts": ["我对花生过敏,推荐点零食。我喜欢喝咖啡。"] }, "create_time": 1735689650 } }
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"title": "Budget",
|
|
15
|
+
"create_time": 1736000000,
|
|
16
|
+
"update_time": 1736000100,
|
|
17
|
+
"mapping": {
|
|
18
|
+
"x": { "message": { "author": { "role": "user" }, "content": { "content_type": "text", "parts": ["我的月薪是两万,我老婆也在上班。请用中文回答,回答简洁一点。"] }, "create_time": 1736000000 } }
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
]
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"uuid": "00000000-0000-4000-8000-000000000001",
|
|
4
|
+
"name": "Side project",
|
|
5
|
+
"created_at": "2025-03-01T10:00:00Z",
|
|
6
|
+
"updated_at": "2025-03-01T10:30:00Z",
|
|
7
|
+
"chat_messages": [
|
|
8
|
+
{ "sender": "human", "text": "我正在开发一个开源笔记应用,叫 Pebble。我擅长 TypeScript 和 React。", "created_at": "2025-03-01T10:00:00Z" },
|
|
9
|
+
{ "sender": "assistant", "text": "I love that idea!", "created_at": "2025-03-01T10:00:05Z" },
|
|
10
|
+
{ "sender": "human", "text": "", "content": [{ "type": "text", "text": "我现在住在上海了。" }], "created_at": "2025-03-01T10:20:00Z" }
|
|
11
|
+
]
|
|
12
|
+
}
|
|
13
|
+
]
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "ds-0001",
|
|
4
|
+
"title": "学英语",
|
|
5
|
+
"inserted_at": "2025-05-02T12:00:00+08:00",
|
|
6
|
+
"mapping": {
|
|
7
|
+
"root": { "id": "root", "message": null },
|
|
8
|
+
"1": { "id": "1", "message": { "inserted_at": "2025-05-02T12:00:00+08:00", "model": "deepseek-chat", "fragments": [ { "type": "REQUEST", "content": "我在准备雅思,目标 7 分。每天早上背单词。" } ] } },
|
|
9
|
+
"2": { "id": "2", "message": { "inserted_at": "2025-05-02T12:00:09+08:00", "model": "deepseek-chat", "fragments": [ { "type": "THINK", "content": "用户在备考…" }, { "type": "RESPONSE", "content": "好的!我是一个AI助手,这是一份计划……" } ] } }
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
]
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
[
|
|
2
|
+
{ "header": "Gemini Apps", "title": "Prompted 我喜欢徒步,周末常去爬山。推荐杭州周边路线?", "time": "2025-02-10T08:00:00.000Z", "products": ["Gemini Apps"] },
|
|
3
|
+
{ "header": "Gemini Apps", "title": "Prompted 我的身份证号是110101199003071234,帮我看看格式对不对", "time": "2025-02-11T08:00:00.000Z", "products": ["Gemini Apps"] },
|
|
4
|
+
{ "header": "Gemini Apps", "title": "Used an Extension", "time": "2025-02-12T08:00:00.000Z" }
|
|
5
|
+
]
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"conversations": [
|
|
3
|
+
{
|
|
4
|
+
"conversation": { "id": "c1", "title": "Trip", "create_time": "2025-04-01T09:00:00Z" },
|
|
5
|
+
"responses": [
|
|
6
|
+
{ "response": { "sender": "human", "message": "我吃素。我在吃治焦虑的药,所以计划安排得轻松一点。", "create_time": "2025-04-01T09:00:00Z" } },
|
|
7
|
+
{ "response": { "sender": "ASSISTANT", "message": "Got it!", "create_time": "2025-04-01T09:00:03Z" } }
|
|
8
|
+
]
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "owui-1",
|
|
4
|
+
"title": "Homelab",
|
|
5
|
+
"chat": {
|
|
6
|
+
"models": ["llama3.1:8b"],
|
|
7
|
+
"messages": [
|
|
8
|
+
{ "role": "user", "content": "我在家里用 Proxmox 搭了个小服务器,我更喜欢开源工具。", "timestamp": 1746000000 },
|
|
9
|
+
{ "role": "assistant", "content": "Nice! Here are some ideas…", "timestamp": 1746000010 }
|
|
10
|
+
]
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<!-- Runs `mindferry sync` every 6 hours. Replace /path/to/node and /path/to/mindferry.
|
|
4
|
+
Install: cp this file ~/Library/LaunchAgents/ && launchctl load ~/Library/LaunchAgents/com.mindferry.sync.plist
|
|
5
|
+
Remove: launchctl unload ~/Library/LaunchAgents/com.mindferry.sync.plist && rm that file -->
|
|
6
|
+
<plist version="1.0">
|
|
7
|
+
<dict>
|
|
8
|
+
<key>Label</key><string>com.mindferry.sync</string>
|
|
9
|
+
<key>ProgramArguments</key>
|
|
10
|
+
<array>
|
|
11
|
+
<string>/path/to/node</string>
|
|
12
|
+
<string>/path/to/mindferry/bin/mindferry.mjs</string>
|
|
13
|
+
<string>sync</string>
|
|
14
|
+
</array>
|
|
15
|
+
<key>StartInterval</key><integer>21600</integer>
|
|
16
|
+
<key>RunAtLoad</key><false/>
|
|
17
|
+
</dict>
|
|
18
|
+
</plist>
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<!DOCTYPE html><html><head><title>ChatGPT - Tea</title></head><body><main>
|
|
2
|
+
<div data-message-author-role="user"><div class="whitespace-pre-wrap">I drink oolong tea every afternoon.</div></div>
|
|
3
|
+
<div data-message-author-role="assistant"><div class="markdown"><p>Oolong is a lovely choice!</p></div></div>
|
|
4
|
+
</main></body></html>
|