@geminilight/mindos 0.5.10 → 0.5.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +9 -9
  2. package/README_zh.md +9 -9
  3. package/app/README.md +2 -2
  4. package/app/app/api/ask/route.ts +126 -3
  5. package/app/app/api/mcp/install/route.ts +1 -1
  6. package/app/app/api/mcp/status/route.ts +1 -1
  7. package/app/app/api/settings/route.ts +1 -1
  8. package/app/app/api/settings/test-key/route.ts +111 -0
  9. package/app/app/api/setup/route.ts +7 -7
  10. package/app/app/api/sync/route.ts +30 -40
  11. package/app/components/AskModal.tsx +28 -21
  12. package/app/components/ask/MessageList.tsx +62 -3
  13. package/app/components/ask/ToolCallBlock.tsx +89 -0
  14. package/app/components/settings/AiTab.tsx +120 -2
  15. package/app/components/setup/StepReview.tsx +31 -25
  16. package/app/components/setup/index.tsx +6 -3
  17. package/app/instrumentation.ts +19 -0
  18. package/app/lib/agent/prompt.ts +32 -0
  19. package/app/lib/agent/stream-consumer.ts +178 -0
  20. package/app/lib/agent/tools.ts +122 -0
  21. package/app/lib/i18n.ts +18 -0
  22. package/app/lib/types.ts +18 -0
  23. package/app/next-env.d.ts +1 -1
  24. package/app/next.config.ts +1 -1
  25. package/app/package.json +2 -2
  26. package/bin/cli.js +49 -22
  27. package/bin/lib/gateway.js +24 -3
  28. package/bin/lib/mcp-install.js +2 -2
  29. package/bin/lib/mcp-spawn.js +3 -3
  30. package/bin/lib/stop.js +1 -1
  31. package/bin/lib/sync.js +61 -11
  32. package/mcp/README.md +5 -5
  33. package/mcp/src/index.ts +2 -2
  34. package/package.json +4 -2
  35. package/scripts/setup.js +12 -12
  36. package/scripts/upgrade-prompt.md +6 -6
  37. package/assets/images/demo-flow-dark.png +0 -0
  38. package/assets/images/demo-flow-light.png +0 -0
  39. package/assets/images/demo-flow-zh-dark.png +0 -0
  40. package/assets/images/demo-flow-zh-light.png +0 -0
  41. package/assets/images/gui-sync-cv.png +0 -0
  42. package/assets/images/wechat-qr.png +0 -0
  43. package/mcp/package-lock.json +0 -1717
package/bin/lib/stop.js CHANGED
@@ -75,7 +75,7 @@ function killTree(pid) {
75
75
  */
76
76
  export function stopMindos(opts = {}) {
77
77
  // Read ports from config for port-based cleanup
78
- let webPort = '3000', mcpPort = '8787';
78
+ let webPort = '3456', mcpPort = '8781';
79
79
  try {
80
80
  const config = JSON.parse(readFileSync(CONFIG_PATH, 'utf-8'));
81
81
  if (config.port) webPort = String(config.port);
package/bin/lib/sync.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { execSync } from 'node:child_process';
2
2
  import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs';
3
3
  import { resolve } from 'node:path';
4
+ import { homedir } from 'node:os';
4
5
  import { CONFIG_PATH, MINDOS_DIR } from './constants.js';
5
6
  import { bold, dim, cyan, green, red, yellow } from './colors.js';
6
7
 
@@ -129,12 +130,24 @@ function autoPull(mindRoot) {
129
130
  }
130
131
  }
131
132
  }
133
+
134
+ // Retry any pending pushes (handles previous push failures)
135
+ try {
136
+ const unpushed = gitExec('git rev-list --count @{u}..HEAD', mindRoot);
137
+ if (parseInt(unpushed) > 0) {
138
+ execSync('git push', { cwd: mindRoot, stdio: 'pipe' });
139
+ saveSyncState({ ...loadSyncState(), lastSync: new Date().toISOString(), lastError: null });
140
+ }
141
+ } catch {
142
+ // No upstream tracking or push failed — ignore silently, autoCommitAndPush handles primary pushes
143
+ }
132
144
  }
133
145
 
134
146
  // ── Exported API ────────────────────────────────────────────────────────────
135
147
 
136
148
  let activeWatcher = null;
137
149
  let activePullInterval = null;
150
+ let activeShutdownHandler = null;
138
151
 
139
152
  /**
140
153
  * Interactive sync init — configure remote git repo
@@ -187,18 +200,43 @@ export async function initSync(mindRoot, opts = {}) {
187
200
  try { execSync('git checkout -b main', { cwd: mindRoot, stdio: 'pipe' }); } catch {}
188
201
  }
189
202
 
203
+ // 1b. Ensure .gitignore exists
204
+ const gitignorePath = resolve(mindRoot, '.gitignore');
205
+ if (!existsSync(gitignorePath)) {
206
+ writeFileSync(gitignorePath, [
207
+ '# MindOS auto-generated',
208
+ '.DS_Store',
209
+ 'Thumbs.db',
210
+ '*.tmp',
211
+ '*.bak',
212
+ '*.swp',
213
+ '*.sync-conflict',
214
+ 'node_modules/',
215
+ '.obsidian/',
216
+ '',
217
+ ].join('\n'), 'utf-8');
218
+ }
219
+
190
220
  // Handle token for HTTPS
191
221
  if (token && remoteUrl.startsWith('https://')) {
192
222
  const urlObj = new URL(remoteUrl);
193
- urlObj.username = 'oauth2';
194
- urlObj.password = token;
195
- // Configure credential helper
196
- try { execSync(`git config credential.helper store`, { cwd: mindRoot, stdio: 'pipe' }); } catch {}
197
- // Store the credential
223
+ // Choose credential helper by platform
224
+ const platform = process.platform;
225
+ let helper;
226
+ if (platform === 'darwin') helper = 'osxkeychain';
227
+ else if (platform === 'win32') helper = 'manager';
228
+ else helper = 'store';
229
+ try { execSync(`git config credential.helper '${helper}'`, { cwd: mindRoot, stdio: 'pipe' }); } catch {}
230
+ // Store the credential via git credential approve
198
231
  try {
199
232
  const credInput = `protocol=${urlObj.protocol.replace(':', '')}\nhost=${urlObj.host}\nusername=oauth2\npassword=${token}\n\n`;
200
233
  execSync('git credential approve', { cwd: mindRoot, input: credInput, stdio: 'pipe' });
201
234
  } catch {}
235
+ // For 'store' helper, restrict file permissions AFTER credential file is created
236
+ if (helper === 'store') {
237
+ const credFile = resolve(process.env.HOME || homedir(), '.git-credentials');
238
+ try { execSync(`chmod 600 "${credFile}"`, { stdio: 'pipe' }); } catch {}
239
+ }
202
240
  }
203
241
 
204
242
  // 4. Set remote
@@ -257,6 +295,7 @@ export async function initSync(mindRoot, opts = {}) {
257
295
  * Start file watcher + periodic pull
258
296
  */
259
297
  export async function startSyncDaemon(mindRoot) {
298
+ if (activeWatcher) return null; // already running — idempotent guard
260
299
  const config = loadSyncConfig();
261
300
  if (!config.enabled) return null;
262
301
  if (!mindRoot || !isGitRepo(mindRoot)) return null;
@@ -281,10 +320,20 @@ export async function startSyncDaemon(mindRoot) {
281
320
  // Pull on startup
282
321
  autoPull(mindRoot);
283
322
 
323
+ // Graceful shutdown: flush pending changes before exit
324
+ const gracefulShutdown = () => {
325
+ if (commitTimer) { clearTimeout(commitTimer); commitTimer = null; }
326
+ try { autoCommitAndPush(mindRoot); } catch {}
327
+ stopSyncDaemon();
328
+ };
329
+ process.on('SIGTERM', gracefulShutdown);
330
+ process.on('SIGINT', gracefulShutdown);
331
+
284
332
  activeWatcher = watcher;
285
333
  activePullInterval = pullInterval;
334
+ activeShutdownHandler = gracefulShutdown;
286
335
 
287
- return { watcher, pullInterval };
336
+ return { watcher, pullInterval, gracefulShutdown };
288
337
  }
289
338
 
290
339
  /**
@@ -299,6 +348,11 @@ export function stopSyncDaemon() {
299
348
  clearInterval(activePullInterval);
300
349
  activePullInterval = null;
301
350
  }
351
+ if (activeShutdownHandler) {
352
+ process.removeListener('SIGTERM', activeShutdownHandler);
353
+ process.removeListener('SIGINT', activeShutdownHandler);
354
+ activeShutdownHandler = null;
355
+ }
302
356
  }
303
357
 
304
358
  /**
@@ -336,14 +390,10 @@ export function getSyncStatus(mindRoot) {
336
390
  */
337
391
  export function manualSync(mindRoot) {
338
392
  if (!mindRoot || !isGitRepo(mindRoot)) {
339
- console.error(red('Not a git repository. Run `mindos sync init` first.'));
340
- process.exit(1);
393
+ throw new Error('Not a git repository. Run `mindos sync init` first.');
341
394
  }
342
- console.log(dim('Pulling...'));
343
395
  autoPull(mindRoot);
344
- console.log(dim('Committing & pushing...'));
345
396
  autoCommitAndPush(mindRoot);
346
- console.log(green('✔ Sync complete'));
347
397
  }
348
398
 
349
399
  /**
package/mcp/README.md CHANGED
@@ -26,7 +26,7 @@ mindos start # starts app + MCP server together
26
26
  Or run MCP server only:
27
27
 
28
28
  ```bash
29
- mindos mcp # HTTP mode (default, port 8787)
29
+ mindos mcp # HTTP mode (default, port 8781)
30
30
  MCP_TRANSPORT=stdio mindos mcp # stdio mode
31
31
  ```
32
32
 
@@ -34,11 +34,11 @@ MCP_TRANSPORT=stdio mindos mcp # stdio mode
34
34
 
35
35
  | Variable | Default | Description |
36
36
  |----------|---------|-------------|
37
- | `MINDOS_URL` | `http://localhost:3000` | App server base URL |
37
+ | `MINDOS_URL` | `http://localhost:3456` | App server base URL |
38
38
  | `AUTH_TOKEN` | — | Optional: bearer token (must match App's `AUTH_TOKEN`) |
39
39
  | `MCP_TRANSPORT` | `http` | Transport mode: `http` or `stdio` |
40
40
  | `MCP_HOST` | `127.0.0.1` | HTTP bind address (`0.0.0.0` for remote access) |
41
- | `MCP_PORT` | `8787` | HTTP listen port (configurable via `mindos onboard`) |
41
+ | `MCP_PORT` | `8781` | HTTP listen port (configurable via `mindos onboard`) |
42
42
  | `MCP_ENDPOINT` | `/mcp` | HTTP endpoint path |
43
43
 
44
44
  ## MCP Tools (20)
@@ -75,7 +75,7 @@ Add to your Agent's MCP config (field names vary by client):
75
75
  {
76
76
  "mcpServers": {
77
77
  "mindos": {
78
- "url": "http://localhost:8787/mcp",
78
+ "url": "http://localhost:8781/mcp",
79
79
  "headers": { "Authorization": "Bearer your-token" }
80
80
  }
81
81
  }
@@ -101,7 +101,7 @@ Add to your Agent's MCP config (field names vary by client):
101
101
  {
102
102
  "mcpServers": {
103
103
  "mindos": {
104
- "url": "http://<server-ip>:8787/mcp",
104
+ "url": "http://<server-ip>:8781/mcp",
105
105
  "headers": { "Authorization": "Bearer your-token" }
106
106
  }
107
107
  }
package/mcp/src/index.ts CHANGED
@@ -22,11 +22,11 @@ import { z } from "zod";
22
22
 
23
23
  // ─── Config ──────────────────────────────────────────────────────────────────
24
24
 
25
- const BASE_URL = process.env.MINDOS_URL ?? "http://localhost:3000";
25
+ const BASE_URL = process.env.MINDOS_URL ?? "http://localhost:3456";
26
26
  const AUTH_TOKEN = process.env.AUTH_TOKEN;
27
27
  const MCP_TRANSPORT = process.env.MCP_TRANSPORT ?? "http"; // "http" | "stdio"
28
28
  const MCP_HOST = process.env.MCP_HOST ?? "127.0.0.1";
29
- const MCP_PORT = parseInt(process.env.MCP_PORT ?? "8787", 10);
29
+ const MCP_PORT = parseInt(process.env.MCP_PORT ?? "8781", 10);
30
30
  const MCP_ENDPOINT = process.env.MCP_ENDPOINT ?? "/mcp";
31
31
  const CHARACTER_LIMIT = 25_000;
32
32
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geminilight/mindos",
3
- "version": "0.5.10",
3
+ "version": "0.5.12",
4
4
  "description": "MindOS — Human-Agent Collaborative Mind System. Local-first knowledge base that syncs your mind to all AI Agents via MCP.",
5
5
  "keywords": [
6
6
  "mindos",
@@ -54,8 +54,10 @@
54
54
  "!assets/capture-demo.mjs",
55
55
  "!assets/demo-flow.html",
56
56
  "!assets/demo-flow-zh.html",
57
+ "!assets/images",
57
58
  "!mcp/node_modules",
58
- "!mcp/dist"
59
+ "!mcp/dist",
60
+ "!mcp/package-lock.json"
59
61
  ],
60
62
  "scripts": {
61
63
  "setup": "node scripts/setup.js",
package/scripts/setup.js CHANGED
@@ -844,11 +844,11 @@ async function startGuiSetup() {
844
844
  if (isFirstTime) {
845
845
  // First-time onboard: use a temporary port (scan from 9100) so the user's
846
846
  // chosen port in Step 3 can differ without a mid-setup restart.
847
- // 9100 is chosen to avoid conflicts with common services (5000=AirPlay, 3000/8080=dev).
847
+ // 9100 is chosen to avoid conflicts with common services (5000=AirPlay, 3456/8080=dev).
848
848
  usePort = await findFreePort(9100);
849
849
  } else {
850
850
  // Re-onboard: service is already running on config.port — reuse it.
851
- const existingPort = config.port || 3000;
851
+ const existingPort = config.port || 3456;
852
852
  if (await isSelfPort(existingPort)) {
853
853
  // Service already running — just open the setup page, no need to spawn.
854
854
  const url = `http://localhost:${existingPort}/setup`;
@@ -866,7 +866,7 @@ async function startGuiSetup() {
866
866
  // stopMindos() sends SIGTERM synchronously — wait for both web and mcp
867
867
  // ports to free, since `start` will assertPortFree on both.
868
868
  const { waitForPortFree } = await import('../bin/lib/gateway.js');
869
- const mcpPort = config.mcpPort || 8787;
869
+ const mcpPort = config.mcpPort || 8781;
870
870
  const [webFreed, mcpFreed] = await Promise.all([
871
871
  waitForPortFree(existingPort),
872
872
  waitForPortFree(mcpPort),
@@ -941,8 +941,8 @@ async function main() {
941
941
 
942
942
  console.log(c.bold('\nExisting config:'));
943
943
  console.log(row('Knowledge base:', c.cyan(existing.mindRoot || '(not set)')));
944
- console.log(row('Web port:', c.cyan(String(existing.port || '3000'))));
945
- console.log(row('MCP port:', c.cyan(String(existing.mcpPort || '8787'))));
944
+ console.log(row('Web port:', c.cyan(String(existing.port || '3456'))));
945
+ console.log(row('MCP port:', c.cyan(String(existing.mcpPort || '8781'))));
946
946
  console.log(row('Auth token:', existing.authToken ? mask(existing.authToken) : c.dim('(not set)')));
947
947
  console.log(row('Web password:', existing.webPassword ? '••••••••' : c.dim('(none)')));
948
948
  console.log(row('AI provider:', c.cyan(existing.ai?.provider || '(not set)')));
@@ -953,7 +953,7 @@ async function main() {
953
953
  const overwrite = await askYesNo('cfgExists', CONFIG_PATH);
954
954
  if (!overwrite) {
955
955
  const existingMode = existing.startMode || 'start';
956
- const existingMcpPort = existing.mcpPort || 8787;
956
+ const existingMcpPort = existing.mcpPort || 8781;
957
957
  const existingAuth = existing.authToken || '';
958
958
  const existingMindRoot = existing.mindRoot || resolve(homedir(), 'MindOS', 'mind');
959
959
  console.log(`\n${c.green(t('cfgKept'))} ${c.dim(CONFIG_PATH)}`);
@@ -1072,8 +1072,8 @@ async function main() {
1072
1072
  write('\n');
1073
1073
  stepHeader(3);
1074
1074
  const existingCfg = resumeCfg;
1075
- const defaultWebPort = typeof existingCfg.port === 'number' ? existingCfg.port : 3000;
1076
- const defaultMcpPort = typeof existingCfg.mcpPort === 'number' ? existingCfg.mcpPort : (defaultWebPort === 8787 ? 8788 : 8787);
1075
+ const defaultWebPort = typeof existingCfg.port === 'number' ? existingCfg.port : 3456;
1076
+ const defaultMcpPort = typeof existingCfg.mcpPort === 'number' ? existingCfg.mcpPort : (defaultWebPort === 8781 ? 8782 : 8781);
1077
1077
  let webPort, mcpPort;
1078
1078
  while (true) {
1079
1079
  webPort = await askPort('webPortPrompt', defaultWebPort);
@@ -1178,8 +1178,8 @@ async function main() {
1178
1178
 
1179
1179
  const isResuming = Object.keys(resumeCfg).length > 0;
1180
1180
  const needsRestart = isResuming && (
1181
- config.port !== (resumeCfg.port ?? 3000) ||
1182
- config.mcpPort !== (resumeCfg.mcpPort ?? 8787) ||
1181
+ config.port !== (resumeCfg.port ?? 3456) ||
1182
+ config.mcpPort !== (resumeCfg.mcpPort ?? 8781) ||
1183
1183
  config.mindRoot !== (resumeCfg.mindRoot ?? '') ||
1184
1184
  config.authToken !== (resumeCfg.authToken ?? '') ||
1185
1185
  config.webPassword !== (resumeCfg.webPassword ?? '')
@@ -1212,7 +1212,7 @@ async function main() {
1212
1212
  }
1213
1213
 
1214
1214
  const installDaemon = startMode === 'daemon' || process.argv.includes('--install-daemon');
1215
- finish(mindDir, config.startMode, config.mcpPort, config.authToken, installDaemon, needsRestart, resumeCfg.port ?? 3000);
1215
+ finish(mindDir, config.startMode, config.mcpPort, config.authToken, installDaemon, needsRestart, resumeCfg.port ?? 3456);
1216
1216
  }
1217
1217
 
1218
1218
  function getLocalIP() {
@@ -1224,7 +1224,7 @@ function getLocalIP() {
1224
1224
  return null;
1225
1225
  }
1226
1226
 
1227
- async function finish(mindDir, startMode = 'start', mcpPort = 8787, authToken = '', installDaemon = false, needsRestart = false, oldPort = 3000) {
1227
+ async function finish(mindDir, startMode = 'start', mcpPort = 8781, authToken = '', installDaemon = false, needsRestart = false, oldPort = 3456) {
1228
1228
  if (needsRestart) {
1229
1229
  const isRunning = await isSelfPort(oldPort);
1230
1230
  if (isRunning) {
@@ -37,8 +37,8 @@ Help me upgrade my MindOS installation from the old source-based setup to the ne
37
37
  ```json
38
38
  {
39
39
  "mindRoot": "<value of MIND_ROOT>",
40
- "port": 3000,
41
- "mcpPort": 8787,
40
+ "port": 3456,
41
+ "mcpPort": 8781,
42
42
  "authToken": "<value of AUTH_TOKEN or empty string>",
43
43
  "webPassword": "",
44
44
  "ai": {
@@ -69,7 +69,7 @@ Help me upgrade my MindOS installation from the old source-based setup to the ne
69
69
  ```
70
70
  (First run will build automatically — this may take a minute.)
71
71
 
72
- 7. **Confirm** the app is accessible at http://localhost:3000 and MCP is running at http://localhost:8787/mcp.
72
+ 7. **Confirm** the app is accessible at http://localhost:3456 and MCP is running at http://localhost:8781/mcp.
73
73
 
74
74
  Do not delete the old cloned repository — keep it as a backup. The `app/.env.local` file can also be kept as reference.
75
75
  ```
@@ -109,8 +109,8 @@ Do not delete the old cloned repository — keep it as a backup. The `app/.env.l
109
109
  ```json
110
110
  {
111
111
  "mindRoot": "<MIND_ROOT 的值>",
112
- "port": 3000,
113
- "mcpPort": 8787,
112
+ "port": 3456,
113
+ "mcpPort": 8781,
114
114
  "authToken": "<AUTH_TOKEN 的值,没有则留空字符串>",
115
115
  "webPassword": "",
116
116
  "ai": {
@@ -141,7 +141,7 @@ Do not delete the old cloned repository — keep it as a backup. The `app/.env.l
141
141
  ```
142
142
  (首次运行会自动构建,可能需要一两分钟。)
143
143
 
144
- 7. **确认** http://localhost:3000 可以访问,http://localhost:8787/mcp 的 MCP 服务也在运行。
144
+ 7. **确认** http://localhost:3456 可以访问,http://localhost:8781/mcp 的 MCP 服务也在运行。
145
145
 
146
146
  不要删除旧的克隆仓库,保留作为备份。`app/.env.local` 也可以保留作参考。
147
147
  ```
Binary file
Binary file
Binary file
Binary file
Binary file