@geminilight/mindos 0.6.6 → 0.6.7
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.
|
@@ -42,21 +42,34 @@ function killByPort(port: number) {
|
|
|
42
42
|
*
|
|
43
43
|
* Unlike /api/restart which restarts the entire MindOS (Web + MCP),
|
|
44
44
|
* this endpoint only restarts the MCP server. The Web UI stays up.
|
|
45
|
+
*
|
|
46
|
+
* When running under Desktop's ProcessManager, the crash handler
|
|
47
|
+
* auto-respawns MCP when it exits. We wait for the port to free,
|
|
48
|
+
* then spawn only if nothing re-bound (i.e. CLI mode with no crash
|
|
49
|
+
* handler). This avoids spawning a duplicate that races for the port.
|
|
45
50
|
*/
|
|
46
51
|
export async function POST() {
|
|
47
52
|
try {
|
|
48
53
|
const cfg = readConfig();
|
|
49
|
-
const mcpPort = (cfg.mcpPort
|
|
54
|
+
const mcpPort = Number(process.env.MINDOS_MCP_PORT) || Number(cfg.mcpPort) || 8781;
|
|
50
55
|
const webPort = process.env.MINDOS_WEB_PORT || '3456';
|
|
51
|
-
const authToken = cfg.authToken as string | undefined;
|
|
56
|
+
const authToken = process.env.AUTH_TOKEN || (cfg.authToken as string | undefined);
|
|
57
|
+
const managed = process.env.MINDOS_MANAGED === '1';
|
|
52
58
|
|
|
53
59
|
// Step 1: Kill process on MCP port
|
|
54
60
|
killByPort(mcpPort);
|
|
55
61
|
|
|
56
|
-
|
|
57
|
-
|
|
62
|
+
if (managed) {
|
|
63
|
+
// Desktop ProcessManager will auto-respawn MCP via its crash handler.
|
|
64
|
+
return NextResponse.json({ ok: true, port: mcpPort, note: 'ProcessManager will respawn' });
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Step 2 (CLI mode only): Wait for port to free, then spawn a new MCP
|
|
68
|
+
const portFree = await waitForPortFree(mcpPort, 5000);
|
|
69
|
+
if (!portFree) {
|
|
70
|
+
return NextResponse.json({ error: `MCP port ${mcpPort} still in use after kill` }, { status: 500 });
|
|
71
|
+
}
|
|
58
72
|
|
|
59
|
-
// Step 3: Spawn new MCP server
|
|
60
73
|
const root = process.env.MINDOS_PROJECT_ROOT || resolve(process.cwd(), '..');
|
|
61
74
|
const mcpDir = resolve(root, 'mcp');
|
|
62
75
|
|
|
@@ -88,3 +101,22 @@ export async function POST() {
|
|
|
88
101
|
return NextResponse.json({ error: message }, { status: 500 });
|
|
89
102
|
}
|
|
90
103
|
}
|
|
104
|
+
|
|
105
|
+
function isPortInUse(port: number): Promise<boolean> {
|
|
106
|
+
return new Promise((res) => {
|
|
107
|
+
const net = require('net');
|
|
108
|
+
const server = net.createServer();
|
|
109
|
+
server.once('error', () => res(true));
|
|
110
|
+
server.once('listening', () => { server.close(); res(false); });
|
|
111
|
+
server.listen(port, '127.0.0.1');
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async function waitForPortFree(port: number, timeoutMs: number): Promise<boolean> {
|
|
116
|
+
const start = Date.now();
|
|
117
|
+
while (Date.now() - start < timeoutMs) {
|
|
118
|
+
if (!(await isPortInUse(port))) return true;
|
|
119
|
+
await new Promise(r => setTimeout(r, 300));
|
|
120
|
+
}
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
@@ -63,7 +63,7 @@ export async function GET() {
|
|
|
63
63
|
const kbStats = getCachedKbStats(mindRoot);
|
|
64
64
|
|
|
65
65
|
// Detect MCP status from environment / config
|
|
66
|
-
const mcpPort = Number(process.env.MCP_PORT) ||
|
|
66
|
+
const mcpPort = Number(process.env.MINDOS_MCP_PORT) || Number(process.env.MCP_PORT) || 8781;
|
|
67
67
|
|
|
68
68
|
return NextResponse.json({
|
|
69
69
|
system: {
|
package/bin/lib/stop.js
CHANGED
|
@@ -111,7 +111,7 @@ export function stopMindos(opts = {}) {
|
|
|
111
111
|
if (!pids.length && portKilled === 0) {
|
|
112
112
|
// Last resort: pattern match (for envs without lsof)
|
|
113
113
|
try { execSync('pkill -f "next start|next dev" 2>/dev/null || true', { stdio: ['ignore', 'inherit', 'inherit'] }); } catch {}
|
|
114
|
-
try { execSync('pkill -f "mcp/src/index"
|
|
114
|
+
try { execSync('pkill -f "mcp/(src/index|dist/index)" 2>/dev/null || true', { stdio: ['ignore', 'inherit', 'inherit'] }); } catch {}
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
if (!pids.length) console.log(green('\u2714 Done'));
|
package/package.json
CHANGED