haoyuan 0.0.5 → 0.0.6

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.
@@ -6,7 +6,7 @@ from pathlib import Path
6
6
  from configs.models import auto_default
7
7
 
8
8
  APP_NAME = "HaoYuan"
9
- APP_VERSION = "0.0.5"
9
+ APP_VERSION = "0.0.6"
10
10
  SERVER_HOST = os.getenv("HAOYUAN_HOST", "127.0.0.1")
11
11
  SERVER_PORT = int(os.getenv("HAOYUAN_PORT", "8030"))
12
12
  prefix = "/api"
package/bin/haoyuan.js CHANGED
@@ -98,10 +98,11 @@ function shellQuote(s) {
98
98
  function run(cmd, args, opts = {}) {
99
99
  const lenient = opts.lenient === true;
100
100
  const useShell = IS_WIN && /\.(cmd|bat)$/i.test(cmd);
101
+ const cwd = opts.cwd || ROOT;
101
102
  log(`${cmd} ${args.join(" ")}`);
102
103
  const r = useShell
103
- ? spawnSync([cmd, ...args.map(shellQuote)].join(" "), { stdio: "inherit", cwd: ROOT, shell: true })
104
- : spawnSync(cmd, args, { stdio: "inherit", cwd: ROOT });
104
+ ? spawnSync([cmd, ...args.map(shellQuote)].join(" "), { stdio: "inherit", cwd, shell: true })
105
+ : spawnSync(cmd, args, { stdio: "inherit", cwd });
105
106
  if (r.error) {
106
107
  if (lenient) {
107
108
  warn(`跳过(${r.error.message})`);
@@ -258,6 +259,37 @@ async function healthyPort(port) {
258
259
  }
259
260
  }
260
261
 
262
+ function stopLocalServer(port) {
263
+ if (!port) return false;
264
+ try {
265
+ if (IS_WIN) {
266
+ const r = spawnSync("netstat", ["-ano", "-p", "TCP"], { encoding: "utf8" });
267
+ const pids = new Set();
268
+ for (const line of (r.stdout || "").split(/\r?\n/)) {
269
+ if (!/LISTENING/i.test(line)) continue;
270
+ const cols = line.trim().split(/\s+/);
271
+ if (!cols[1] || !cols[1].endsWith(`:${port}`)) continue;
272
+ const pid = cols[cols.length - 1];
273
+ if (/^\d+$/.test(pid) && pid !== "0") pids.add(pid);
274
+ }
275
+ for (const pid of pids) {
276
+ log(`停止正在运行的豪源服务(端口 ${port},PID ${pid})...`);
277
+ spawnSync("taskkill", ["/PID", pid, "/F"], { stdio: "ignore" });
278
+ }
279
+ return pids.size > 0;
280
+ }
281
+ const r = spawnSync("lsof", ["-ti", `tcp:${port}`], { encoding: "utf8" });
282
+ const pids = (r.stdout || "").split(/\s+/).filter((pid) => /^\d+$/.test(pid));
283
+ for (const pid of pids) {
284
+ log(`停止正在运行的豪源服务(端口 ${port},PID ${pid})...`);
285
+ spawnSync("kill", ["-TERM", pid], { stdio: "ignore" });
286
+ }
287
+ return pids.length > 0;
288
+ } catch {
289
+ return false;
290
+ }
291
+ }
292
+
261
293
  async function waitUntilHealthy(timeoutMs = 180000) {
262
294
  const deadline = Date.now() + timeoutMs;
263
295
  while (Date.now() < deadline) {
@@ -1141,10 +1173,24 @@ async function upgradeCommand() {
1141
1173
  return;
1142
1174
  }
1143
1175
 
1176
+ // Windows 下 npm 会重命名当前包目录;若服务正在运行或 cwd 在包内会 EBUSY,先停服务并在用户目录执行
1177
+ const port = readApiPort();
1178
+ if (port && (await healthyPort(port))) {
1179
+ stopLocalServer(port);
1180
+ await new Promise((resolve) => setTimeout(resolve, 800));
1181
+ }
1182
+
1144
1183
  log(`开始升级 v${VERSION} → v${latest} ...`);
1145
- const ok = run(NPM, ["install", "-g", `haoyuan@${latest}`, ...npmRegistryArgs()], { lenient: true });
1184
+ const installArgs = ["install", "-g", `haoyuan@${latest}`, ...npmRegistryArgs()];
1185
+ let ok = run(NPM, installArgs, { lenient: true, cwd: os.homedir() });
1186
+ if (!ok && IS_WIN) {
1187
+ await new Promise((resolve) => setTimeout(resolve, 1500));
1188
+ ok = run(NPM, installArgs, { lenient: true, cwd: os.homedir() });
1189
+ }
1146
1190
  if (!ok) {
1147
- fail("升级失败。若提示权限不足,请用管理员权限运行,或手动执行: npm install -g haoyuan@latest");
1191
+ fail(
1192
+ "升级失败:请完全退出正在运行的豪源(关闭所有 haoyuan 窗口/服务),在用户目录(如 C:\\Users\\你的用户名)下执行 npm install -g haoyuan@latest;权限不足请用管理员终端。"
1193
+ );
1148
1194
  }
1149
1195
  log(`升级完成:v${VERSION} → v${latest}`);
1150
1196
  log("请重新运行 haoyuan 以使用新版本。");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "haoyuan",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "豪源 · HaoYuan — 个人指挥 AI 实现多个 AI 员工异步并行工作的 AI 工作室",
5
5
  "bin": {
6
6
  "haoyuan": "bin/haoyuan.js"
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "haoyuan-web",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "haoyuan-web",
9
- "version": "0.0.5",
9
+ "version": "0.0.6",
10
10
  "dependencies": {
11
11
  "dompurify": "^3.2.4",
12
12
  "marked": "^15.0.7",
package/web/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "haoyuan-web",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "scripts": {