haoyuan 0.0.3 → 0.0.4

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.3"
9
+ APP_VERSION = "0.0.4"
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
@@ -1070,6 +1070,77 @@ function printVersion() {
1070
1070
  process.stdout.write(`${VERSION}\n`);
1071
1071
  }
1072
1072
 
1073
+ function npmRegistryArgs() {
1074
+ const registry = (process.env.HAOYUAN_NPM_REGISTRY || "").trim();
1075
+ return registry ? ["--registry", registry] : [];
1076
+ }
1077
+
1078
+ function parseVersion(value) {
1079
+ return String(value || "")
1080
+ .trim()
1081
+ .replace(/^v/i, "")
1082
+ .split("-")[0]
1083
+ .split(".")
1084
+ .map((part) => {
1085
+ const n = Number.parseInt(part, 10);
1086
+ return Number.isFinite(n) ? n : 0;
1087
+ });
1088
+ }
1089
+
1090
+ function compareVersions(a, b) {
1091
+ const pa = parseVersion(a);
1092
+ const pb = parseVersion(b);
1093
+ const len = Math.max(pa.length, pb.length);
1094
+ for (let i = 0; i < len; i += 1) {
1095
+ const x = pa[i] || 0;
1096
+ const y = pb[i] || 0;
1097
+ if (x !== y) return x < y ? -1 : 1;
1098
+ }
1099
+ return 0;
1100
+ }
1101
+
1102
+ function npmCapture(args) {
1103
+ const full = [...args, ...npmRegistryArgs()];
1104
+ const useShell = IS_WIN && /\.(cmd|bat)$/i.test(NPM);
1105
+ const r = spawnSync(NPM, useShell ? full.map(shellQuote) : full, {
1106
+ cwd: ROOT,
1107
+ encoding: "utf8",
1108
+ shell: useShell,
1109
+ });
1110
+ if (r.error) return { ok: false, error: r.error.message };
1111
+ if (r.status !== 0) {
1112
+ const detail = (r.stderr || r.stdout || "").trim();
1113
+ return { ok: false, error: detail || `npm 退出码 ${r.status}` };
1114
+ }
1115
+ return { ok: true, out: (r.stdout || "").trim() };
1116
+ }
1117
+
1118
+ async function upgradeCommand() {
1119
+ log(`当前版本 v${VERSION}`);
1120
+ log("检查 npm 最新版本 ...");
1121
+ const result = npmCapture(["view", "haoyuan", "version"]);
1122
+ if (!result.ok) {
1123
+ fail(`检查最新版本失败: ${result.error}(可用 HAOYUAN_NPM_REGISTRY 指定 npm 源)`);
1124
+ }
1125
+ const latest = (result.out || "").split(/\s+/).filter(Boolean).pop() || "";
1126
+ if (!/^\d+\.\d+\.\d+/.test(latest)) {
1127
+ fail(`无法解析最新版本号: ${result.out || "(空)"}`);
1128
+ }
1129
+ log(`最新版本 v${latest}`);
1130
+ if (compareVersions(VERSION, latest) >= 0) {
1131
+ log("已是最新版本,无需升级。");
1132
+ return;
1133
+ }
1134
+
1135
+ log(`开始升级 v${VERSION} → v${latest} ...`);
1136
+ const ok = run(NPM, ["install", "-g", `haoyuan@${latest}`, ...npmRegistryArgs()], { lenient: true });
1137
+ if (!ok) {
1138
+ fail("升级失败。若提示权限不足,请用管理员权限运行,或手动执行: npm install -g haoyuan@latest");
1139
+ }
1140
+ log(`升级完成:v${VERSION} → v${latest}`);
1141
+ log("请重新运行 haoyuan 以使用新版本。");
1142
+ }
1143
+
1073
1144
  function printHelp() {
1074
1145
  process.stdout.write(
1075
1146
  [
@@ -1086,6 +1157,7 @@ function printHelp() {
1086
1157
  " haoyuan logout 清除本地登录令牌",
1087
1158
  " haoyuan setup 安装后端/前端依赖",
1088
1159
  " haoyuan build 仅构建前端",
1160
+ " haoyuan upgrade 升级到 npm 最新版本",
1089
1161
  " haoyuan help 显示帮助",
1090
1162
  "",
1091
1163
  "选项:",
@@ -1152,6 +1224,10 @@ async function main() {
1152
1224
  buildFrontend();
1153
1225
  return;
1154
1226
  }
1227
+ if (command === "upgrade" || command === "update") {
1228
+ await upgradeCommand();
1229
+ return;
1230
+ }
1155
1231
  if (command === "postinstall") {
1156
1232
  postinstall();
1157
1233
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "haoyuan",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
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.3",
3
+ "version": "0.0.4",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "haoyuan-web",
9
- "version": "0.0.3",
9
+ "version": "0.0.4",
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.3",
3
+ "version": "0.0.4",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "scripts": {