@xqli02/mneme 0.1.4 → 0.1.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xqli02/mneme",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Three-layer memory architecture for AI coding agents (Ledger + Beads + OpenCode)",
5
5
  "type": "module",
6
6
  "bin": {
@@ -251,11 +251,37 @@ function ensureDoltServer() {
251
251
  mkdirSync(DOLT_DATA_DIR, { recursive: true });
252
252
  }
253
253
 
254
- // Check if a dolt server is already running and reachable
255
- const test = run("bd list --status=open 2>&1");
256
- if (test !== null && !test.includes("unreachable") && !test.includes("connection refused")) {
257
- log.ok(`dolt server already running ${color.dim(`(port ${DOLT_PORT})`)}`);
258
- return true;
254
+ // Check if port is already in use (bash /dev/tcp returns 0 if open, 1 if refused)
255
+ const portInUse = run(`bash -c 'echo > /dev/tcp/127.0.0.1/${DOLT_PORT}' 2>&1`) !== null;
256
+
257
+ if (portInUse) {
258
+ // Port is occupied — check if it's our dolt server with the right data-dir
259
+ const psOutput = run(`ps aux 2>/dev/null`) ?? "";
260
+ const doltLines = psOutput.split("\n").filter((line) =>
261
+ line.includes("dolt") && line.includes("sql-server") && line.includes(`${DOLT_PORT}`)
262
+ && !line.includes("grep")
263
+ );
264
+ // Prefer the actual dolt binary process over a bash wrapper
265
+ const doltProc = doltLines.find((l) => !l.includes("bash -c") && /\bdolt\s+sql-server\b/.test(l)) || doltLines[0];
266
+
267
+ if (doltProc && doltProc.includes(DOLT_DATA_DIR)) {
268
+ // Same data-dir, already running — nothing to do
269
+ log.ok(`dolt server already running ${color.dim(`(port ${DOLT_PORT}, data-dir ${DOLT_DATA_DIR})`)}`);
270
+ return true;
271
+ }
272
+
273
+ if (doltProc) {
274
+ // Dolt running but with a different data-dir — kill and restart
275
+ log.warn(`dolt server on port ${DOLT_PORT} uses a different data-dir, restarting...`);
276
+ // Extract PID from ps aux output (second column)
277
+ const pid = doltProc.trim().split(/\s+/)[1];
278
+ if (pid) run(`kill ${pid} 2>/dev/null`);
279
+ run("sleep 1");
280
+ } else {
281
+ // Port occupied by something else entirely
282
+ log.fail(`Port ${DOLT_PORT} is in use by a non-dolt process. Set MNEME_DOLT_PORT to use a different port.`);
283
+ return false;
284
+ }
259
285
  }
260
286
 
261
287
  log.info(`Starting dolt server (port ${DOLT_PORT}, data-dir ${DOLT_DATA_DIR})...`);
@@ -269,8 +295,8 @@ function ensureDoltServer() {
269
295
  // Wait for server to be ready (up to 10s)
270
296
  for (let i = 0; i < 10; i++) {
271
297
  run("sleep 1");
272
- const check = run("bd list --status=open 2>&1");
273
- if (check !== null && !check.includes("unreachable") && !check.includes("connection refused")) {
298
+ const alive = run(`bash -c 'echo > /dev/tcp/127.0.0.1/${DOLT_PORT}' 2>&1`) !== null;
299
+ if (alive) {
274
300
  log.ok(`dolt server started ${color.dim(`(port ${DOLT_PORT})`)}`);
275
301
  return true;
276
302
  }