@ccjr1120/memory-one 0.1.1 → 0.1.2

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/README.md CHANGED
@@ -171,14 +171,14 @@ Memory One 只会替换自己管理的 `memory-one:codex` 标记区块,保留
171
171
 
172
172
  ```bash
173
173
  npm install -g @ccjr1120/memory-one
174
- memory-one start
175
- memory-one status
176
- memory-one open
177
- memory-one update
178
- memory-one stop
174
+ memoryone start
175
+ memoryone status
176
+ memoryone open
177
+ memoryone update
178
+ memoryone stop
179
179
  ```
180
180
 
181
- 服务默认运行在 <http://127.0.0.1:23888/>,MCP 地址为 <http://127.0.0.1:23888/mcp/>。数据库、PID 和日志保存在 `~/.local/share/memory-one`,不会写入 npm 包目录。执行 `memory-one update` 会更新全局 CLI,并在服务运行时自动重启服务。
181
+ 服务默认运行在 <http://127.0.0.1:23888/>,MCP 地址为 <http://127.0.0.1:23888/mcp/>。数据库、PID 和日志保存在 `~/.local/share/memory-one`,不会写入 npm 包目录。执行 `memoryone update` 会更新全局 CLI,并在服务运行时自动重启服务。若启动时端口 `23888` 已被占用,CLI 会询问是否终止占用进程。
182
182
 
183
183
  从源码 checkout 安装并启动:
184
184
 
@@ -222,7 +222,7 @@ git push origin main
222
222
  本地全局安装后,使用下面的命令检查并更新到 npm 上的最新版本;如果服务正在运行,更新完成后会自动重启:
223
223
 
224
224
  ```bash
225
- memory-one update
225
+ memoryone update
226
226
  ```
227
227
 
228
228
  打开记忆工作台时,前端会检查当前版本和 npm 最新版本;发现新版本时会在顶部显示 3 秒通知条。
@@ -1,9 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { spawn, spawnSync } from "node:child_process";
3
+ import { execFileSync, spawn, spawnSync } from "node:child_process";
4
4
  import { closeSync, existsSync, mkdirSync, openSync, readFileSync, rmSync, writeFileSync } from "node:fs";
5
5
  import { homedir, platform } from "node:os";
6
6
  import { dirname, join } from "node:path";
7
+ import { createInterface } from "node:readline/promises";
7
8
  import { fileURLToPath } from "node:url";
8
9
 
9
10
  const packageRoot = dirname(dirname(fileURLToPath(import.meta.url)));
@@ -39,12 +40,45 @@ function currentPid() {
39
40
 
40
41
  const wait = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds));
41
42
 
43
+ function listeningPids() {
44
+ if (platform() === "win32") return [];
45
+ try {
46
+ return execFileSync("lsof", [`-tiTCP:${port}`, "-sTCP:LISTEN"], {
47
+ encoding: "utf8",
48
+ stdio: ["ignore", "pipe", "ignore"],
49
+ }).split(/\s+/).filter(Boolean).map(Number);
50
+ } catch {
51
+ return [];
52
+ }
53
+ }
54
+
55
+ async function releaseOccupiedPort() {
56
+ const pids = listeningPids();
57
+ if (!pids.length) return true;
58
+ const prompt = createInterface({ input: process.stdin, output: process.stdout });
59
+ const answer = await prompt.question(`端口 ${port} 已被进程 ${pids.join(", ")} 占用,是否终止占用进程?[y/N] `);
60
+ prompt.close();
61
+ if (!/^(y|yes|是)$/i.test(answer.trim())) {
62
+ console.log("已取消启动。");
63
+ return false;
64
+ }
65
+ for (const pid of pids) {
66
+ try { process.kill(pid, "SIGTERM"); } catch {}
67
+ }
68
+ await wait(500);
69
+ for (const pid of listeningPids()) {
70
+ try { process.kill(pid, "SIGKILL"); } catch {}
71
+ }
72
+ return true;
73
+ }
74
+
42
75
  async function start() {
43
76
  const runningPid = currentPid();
44
77
  if (runningPid) {
45
78
  console.log(`Memory One 已在运行(PID ${runningPid}):${url}`);
46
79
  return;
47
80
  }
81
+ if (!await releaseOccupiedPort()) return;
48
82
  mkdirSync(dataDir, { recursive: true });
49
83
  const logFd = openSync(logFile, "a");
50
84
  const child = spawn(process.execPath, [join(packageRoot, "dist", "server.js")], {
@@ -118,7 +152,7 @@ function openApp() {
118
152
  }
119
153
 
120
154
  function help() {
121
- console.log(`Memory One\n\n用法:\n memory-one start 启动本地服务\n memory-one stop 停止本地服务\n memory-one status 查看运行状态\n memory-one open 打开工作台\n memory-one update 更新到最新版本`);
155
+ console.log(`Memory One\n\n用法:\n memoryone start 启动本地服务\n memoryone stop 停止本地服务\n memoryone status 查看运行状态\n memoryone open 打开工作台\n memoryone update 更新到最新版本`);
122
156
  }
123
157
 
124
158
  const command = process.argv[2];
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@ccjr1120/memory-one",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "A local HTTP MCP service for personal agent memory",
5
5
  "type": "module",
6
6
  "bin": {
7
- "memory-one": "bin/memory-one.mjs"
7
+ "memoryone": "bin/memory-one.mjs"
8
8
  },
9
9
  "files": [
10
10
  "bin",