cicy-desktop 2.1.368 → 2.1.370

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.
@@ -39,7 +39,7 @@
39
39
  setTimeout(check, 5000);
40
40
  })();
41
41
  </script>
42
- <script type="module" crossorigin src="./assets/index-gkbJ7Q2a.js"></script>
42
+ <script type="module" crossorigin src="./assets/index-BMeWzitz.js"></script>
43
43
  <link rel="stylesheet" crossorigin href="./assets/index-CVk0uc2g.css">
44
44
  </head>
45
45
  <body>
@@ -116,7 +116,7 @@ async function ensureDockerTeam() {
116
116
  return null;
117
117
  };
118
118
  try {
119
- const r = await cc.registerDockerTeam({ port: APP_PORT });
119
+ const r = await cc.registerDockerTeam({ port: APP_PORT, title: "本机团队" });
120
120
  if (r && r.ok && r.apiKey) {
121
121
  dockerTeamReg = { teamId: r.teamId, title: r.title || `Docker :${APP_PORT}`, apiKey: r.apiKey };
122
122
  try { const store = readDockerTeams(); store[APP_VOLUME] = { ...(store[APP_VOLUME] || {}), teamId: r.teamId, title: dockerTeamReg.title, apiKey: r.apiKey }; writeDockerTeams(store); } catch {}
@@ -552,7 +552,9 @@ function register({ sidecarLogPath } = {}) {
552
552
  const registerAppTeam = async () => {
553
553
  const lt = require("./local-teams");
554
554
  await ensureDockerTeam(); // 确保独立云端 team 存在 + 拿到 teamId/title
555
- const title = (dockerTeamReg && dockerTeamReg.title) || "Docker 团队";
555
+ // 默认名「本机团队」(2026-10-21);云端还是系统缺省名(老的 Docker 团队 / Docker :<port>)时也换成它。
556
+ const t0 = dockerTeamReg && dockerTeamReg.title;
557
+ const title = (!t0 || /^\s*docker\s*(团队|team)?\s*(:\s*\d+)?\s*$/i.test(t0)) ? "本机团队" : t0;
556
558
  // is_docker + cloud_team_id are passed INTO addTeam so they land in the SAME
557
559
  // writeNodes as the node — before addTeam's fire-and-forget syncNameToCloud
558
560
  // runs. That's what stops the freshly-created :8008 node from device-registering
@@ -209,7 +209,7 @@
209
209
  "recreateOk": "确定重建",
210
210
  "runningWslBroken": "运行中 · ⚠ WSL 管理异常(能打开;更新/重启需修复 WSL)",
211
211
  "openFailed": "打开失败",
212
- "openTitle": "打开 Docker 团队",
212
+ "openTitle": "打开本机团队",
213
213
  "repairWsl": "修复 WSL",
214
214
  "wslBrokenRepair": "WSL 管理异常 · 点「修复 WSL」重装",
215
215
  "openWslDir": "打开 WSL 目录",
@@ -219,7 +219,16 @@ function headETag(url, hops = 5) {
219
219
  function imageEtagPath() { return path.join(downloadsDir(), "cicy-code-latest.etag"); }
220
220
  function readLoadedImageEtag() { try { return fs.readFileSync(imageEtagPath(), "utf8").trim(); } catch { return ""; } }
221
221
  function writeLoadedImageEtag(v) { try { fs.writeFileSync(imageEtagPath(), String(v || "")); } catch {} }
222
- async function remoteImageEtag() { return headETag(R2_TARBALL); }
222
+ // 国内网络到 R2 公开域名(*.de5.net)会被重置;dl.cicy-ai.com 是同一个桶经 Cloudflare Worker 的只读镜像
223
+ // (仓库 ~/projects/cicy-dl-mirror,ETag/Range 原样透传)。R2 HEAD 不通时一律改走它。
224
+ const R2_MIRROR_TARBALL = process.env.CICY_DOCKER_MIRROR_URL || "https://dl.cicy-ai.com/images/cicy-code-latest.tar.gz";
225
+ async function remoteImageEtag() { return (await headETag(R2_TARBALL)) || headETag(R2_MIRROR_TARBALL); }
226
+ // 先 HEAD 一下 R2(15s 超时),通就用 R2,不通直接换镜像 —— 别让 curl 在被重置的 R2 上重试 8 轮(每轮几十秒)。
227
+ async function pickTarballSource() {
228
+ if ((await headSize(R2_TARBALL)) > 0) return { url: R2_TARBALL, alt: R2_MIRROR_TARBALL };
229
+ if ((await headSize(R2_MIRROR_TARBALL)) > 0) return { url: R2_MIRROR_TARBALL, alt: null };
230
+ return { url: R2_TARBALL, alt: R2_MIRROR_TARBALL };
231
+ }
223
232
  // Drop the cached tarball so a stale copy on disk can't be reused (downloadImageTarball
224
233
  // skips a complete file by size, which a same-size new image would wrongly satisfy).
225
234
  function clearImageTarball() { try { fs.unlinkSync(imageTarballPath()); } catch {} }
@@ -371,7 +380,9 @@ function curlDownload(url, dest, { emit, phase = "image", label = "下载镜像"
371
380
  // --retry-connrefused (curl 7.52+) covers a not-yet-ready net. On curl 7.71+
372
381
  // also add --retry-all-errors so a transient DNS blip (exit 6, common right
373
382
  // after app start) retries on the fast curl path instead of the slow node one.
374
- const args = ["-sL", "-A", DL_UA, "-C", "-", "--retry", "8", "--retry-delay", "3", "--retry-connrefused"];
383
+ // --connect-timeout + --speed-limit/--speed-time:被墙的源几秒就放弃,传着传着卡死(<10KB/s 持续 2 分钟)
384
+ // 也会退出 —— 否则 curl 永远挂着,bootstrap 和守护循环一起卡住(国内链路上真会发生)。
385
+ const args = ["-sL", "-A", DL_UA, "-C", "-", "--connect-timeout", "20", "--speed-limit", "10240", "--speed-time", "120", "--retry", "8", "--retry-delay", "3", "--retry-connrefused"];
375
386
  if (curlSupportsRetryAllErrors(bin)) args.push("--retry-all-errors");
376
387
  args.push("-o", dest, url);
377
388
  let child;
@@ -403,22 +414,23 @@ function curlDownload(url, dest, { emit, phase = "image", label = "下载镜像"
403
414
  // (much faster here); falls back to the node downloader if curl is unavailable.
404
415
  async function downloadImageTarball({ emit } = {}) {
405
416
  const dest = imageTarballPath();
417
+ const src = await pickTarballSource(); // R2 不通(国内)→ dl.cicy-ai.com 镜像
406
418
  // REUSE a complete tarball already on disk (staged into ~/Downloads, or a prior
407
419
  // run) BEFORE curlDownload touches it — curlDownload doesn't skip a complete file
408
420
  // (and a failed curl truncates it). headSize uses node http so it works even when
409
421
  // curl can't resolve the host. Skips the ~500MB re-download per new user.
410
422
  try {
411
- const expected = await headSize(R2_TARBALL);
423
+ const expected = await headSize(src.url);
412
424
  const have = fs.statSync(dest).size;
413
425
  if (expected > 0 && have === expected) {
414
426
  emit && emit({ phase: "image", status: "skip", message: "镜像:已有完整包,跳过下载", progress: 100, received: have, total: expected });
415
427
  return dest;
416
428
  }
417
429
  } catch {}
418
- try { await curlDownload(R2_TARBALL, dest, { emit, phase: "image", label: "下载镜像" }); }
430
+ try { await curlDownload(src.url, dest, { emit, phase: "image", label: "下载镜像" }); }
419
431
  catch (e) {
420
432
  emit && emit({ phase: "image", status: "running", message: `curl 下载失败(${e.message}),改用内置下载…` });
421
- await ensureDownloaded(R2_TARBALL, dest, null, { emit, phase: "image", label: "下载镜像" });
433
+ await ensureDownloaded(src.url, dest, src.alt, { emit, phase: "image", label: "下载镜像" });
422
434
  }
423
435
  return dest;
424
436
  }
@@ -3,9 +3,10 @@
3
3
 
4
4
  // Windows 上 Docker-版 cicy-code 跑在哪:WSL2(老机器)还是 QEMU(新机器,不再用 WSL)。
5
5
  //
6
- // 规则(2026-10 定):已经装了 WSL 版的老机器不动;其余机器一律 QEMU,端口用 8009 —— 和老机器的
7
- // 8008 用端口区分,一眼看得出走的哪套,也绝不撞车。判定结果写进 ~/cicy-ai/db/linux-backend.json,
8
- // 之后不再变(避免某天装了 WSL 又被切回去)。CICY_LINUX_BACKEND=wsl|qemu 可强制覆盖。
6
+ // 规则:2026-10-21 起新机器走 QEMU、端口 8009;2026-10-22 用户定「所有的机器全部用 QEMU」——
7
+ // 新判定一律 qemu(不再看机器上有没有 WSL)。已经落盘的判定不自动改:老机器的 wsl 由人逐台迁
8
+ // (停 WSL 容器 → 改 linux-backend.json → 重启 desktop),避免一升级就整队断服。
9
+ // 判定结果写进 ~/cicy-ai/db/linux-backend.json。CICY_LINUX_BACKEND=wsl|qemu 可强制覆盖。
9
10
  //
10
11
  // 必须在 main.js 最早处 init():sidecar-ipc 等模块在 require 时就读 CICY_DOCKER_APP_PORT。
11
12
 
@@ -37,8 +38,8 @@ function decide() {
37
38
  const forced = String(process.env.CICY_LINUX_BACKEND || "").toLowerCase();
38
39
  if (forced === "wsl" || forced === "qemu") return forced;
39
40
  try { const j = JSON.parse(fs.readFileSync(FILE, "utf8")); if (j && (j.backend === "wsl" || j.backend === "qemu")) return j.backend; } catch {}
40
- const b = hasWslInstall() ? "wsl" : "qemu";
41
- try { fs.mkdirSync(path.dirname(FILE), { recursive: true }); fs.writeFileSync(FILE, JSON.stringify({ backend: b, decidedAt: new Date().toISOString() }, null, 2)); } catch {}
41
+ const b = "qemu";
42
+ try { fs.mkdirSync(path.dirname(FILE), { recursive: true }); fs.writeFileSync(FILE, JSON.stringify({ backend: b, decidedAt: new Date().toISOString(), hadWsl: hasWslInstall() }, null, 2)); } catch {}
42
43
  return b;
43
44
  }
44
45
 
@@ -88,13 +88,25 @@ function sshConnect() {
88
88
  }
89
89
  // 等价于 wslRun:成功 resolve {stdout, stderr};非零退出 reject(err.stdout/err.stderr/err.code)。
90
90
  // opts.stdin:可读流,灌进命令的 stdin(docker load 用)。opts.onLine:逐行回调(流式进度)。
91
+ // ⚠️ 超时必须从调用开始就算(含建连、开通道):虚拟机慢启动时 sshd 可能接了 TCP 却迟迟不开 exec 通道,
92
+ // 以前计时器只在 exec 回调里才挂上 → 回调永不来 → 这个 promise 永不结束 → status()/守护循环整条卡死
93
+ // (xs-2002 2026-10-22 起卡了一夜,docker-status 一直停在旧时间)。
91
94
  async function vmRun(cmd, { timeout = 60000, stdin, onLine } = {}) {
92
- const c = await sshConnect();
95
+ const t0 = Date.now();
96
+ const c = await Promise.race([sshConnect(), new Promise((_, rej) => setTimeout(() => rej(new Error("ssh connect timeout")), Math.min(timeout, 30000)))]);
93
97
  return new Promise((resolve, reject) => {
94
- c.exec(`sudo -n sh -c ${shQuote(cmd)}`, (err, stream) => {
95
- if (err) { _conn = null; try { c.end(); } catch {} return reject(err); }
96
- let out = "", errOut = "", buf = "";
97
- const timer = setTimeout(() => { try { stream.close(); } catch {} reject(Object.assign(new Error(`vmRun timeout after ${timeout}ms: ${cmd.slice(0, 120)}`), { stdout: out, stderr: errOut })); }, timeout);
98
+ let stream = null, done = false;
99
+ let out = "", errOut = "", buf = "";
100
+ const timer = setTimeout(() => {
101
+ if (done) return; done = true;
102
+ try { stream && stream.close(); } catch {}
103
+ if (!stream) { _conn = null; try { c.end(); } catch {} } // 通道都没开出来:这条连接已不可信,丢掉重连
104
+ reject(Object.assign(new Error(`vmRun timeout after ${timeout}ms: ${cmd.slice(0, 120)}`), { stdout: out, stderr: errOut }));
105
+ }, Math.max(1000, timeout - (Date.now() - t0)));
106
+ c.exec(`sudo -n sh -c ${shQuote(cmd)}`, (err, st) => {
107
+ if (done) { try { st && st.close(); } catch {} return; }
108
+ if (err) { done = true; clearTimeout(timer); _conn = null; try { c.end(); } catch {} return reject(err); }
109
+ stream = st;
98
110
  const line = (chunk) => {
99
111
  if (!onLine) return;
100
112
  buf += chunk;
@@ -104,6 +116,7 @@ async function vmRun(cmd, { timeout = 60000, stdin, onLine } = {}) {
104
116
  stream.stderr.on("data", (d) => { const s = d.toString("utf8"); errOut += s; line(s); });
105
117
  stream.on("close", (code) => {
106
118
  clearTimeout(timer);
119
+ if (done) return; done = true;
107
120
  if (code === 0) resolve({ stdout: out, stderr: errOut });
108
121
  else reject(Object.assign(new Error(`exit ${code}: ${(errOut || out).trim().slice(-300)}`), { code, stdout: out, stderr: errOut }));
109
122
  });
@@ -157,7 +170,7 @@ async function ensureVm({ emit } = {}) {
157
170
  const up = await docker.waitUntil(sshOk, { totalMs: 15 * 60 * 1000, everyMs: 5000, onTick: () => e({ phase: "install-docker", status: "running", message: `等虚拟机开机…(${Math.round((Date.now() - t0) / 1000)}s)` }) });
158
171
  if (up) {
159
172
  s = await vmStatus();
160
- if (s.accel === "tcg") e({ phase: "install-docker", status: "running", message: "⚠️ 这台机器没开 WHPX,虚拟机在软件模拟下运行,Docker 版 cicy-code 会很慢。首页 Debian 卡片菜单里可「开启硬件加速」(需管理员 + 重启)。" });
173
+ if (s.accel === "tcg") e({ phase: "install-docker", status: "running", message: "⚠️ 这台机器没开 WHPX,虚拟机在软件模拟下运行,Docker 版 cicy-code 会很慢。首页「本机团队」卡片 ⋯ 菜单里可「开启硬件加速」(需管理员 + 重启)。" });
161
174
  return { ok: true, accel: s.accel };
162
175
  }
163
176
  // SSH 一直不通:多半是这台虚拟机是首页早先开的(老 provision,没 desktop 公钥)→ 重开机一次。
@@ -1,6 +1,6 @@
1
- // Debian 虚拟机控制脚本 —— 首页「Debian」卡片和 desktop 的 QEMU 版 Docker cicy-code 共用这一份。
2
- // 首页:?raw 打进 bundle,写到 ~/cicy-ai/db/debian-ctl.js,用本机 node(dsh 同款找法 / 便携版)跑;
3
- // desktop:src/sidecar/qemu-docker.js 把它写到 ~/cicy-ai/db/qemu-vm-ctl.js 再跑。
1
+ // Debian 虚拟机控制脚本 —— desktop 的 QEMU 版 Docker cicy-code 用(src/sidecar/qemu-docker.js 把它写到
2
+ // ~/cicy-ai/db/qemu-vm-ctl.js 再跑)。首页的「Debian 13」卡片曾经也用它(写成 debian-ctl.js),
3
+ // 2026-10-21 卡片已下线(和「Docker 团队」是同一台虚拟机,重复了);老首页写过的 debian-ctl.js 可能还在。
4
4
  // node <ctl> <status|install|start|stop|open|accel|fwd <port>...>
5
5
  // 两边版本可能不同步,所以只认同一套磁盘约定(vmDir 下的文件 + 端口),谁先开机谁当 runner。
6
6
  // 只打一行 JSON 到 stdout。不靠 WSL:QEMU 便携版 + Debian 官方云镜像,
@@ -20,9 +20,12 @@ const DEB_IMG = "debian-13-genericcloud-amd64-" + DEB_SERIAL + ".qcow2";
20
20
  // 官方 SHA512SUMS 里的值(CI 转存前也按它校验过)—— 不管从哪个源下,落盘后都按它验。
21
21
  const DEB_SHA512 = "ec584ccabfef7120b4c4f7482adf0e615894d9292cedec446b64194b951ebe5dd97c336b5dcbae458333764b0edd516334506017f33c4f2020ef8d38b569ffe3";
22
22
  const R2 = "https://r2.deepfetch.de5.net/releases";
23
- const QEMU_SRCS = [R2 + "/qemu/" + QEMU_ZIP];
23
+ // 国内网络到 R2 公开域名(*.de5.net)被重置;dl.cicy-ai.com 是同一个桶经 Cloudflare Worker 的只读镜像
24
+ // (仓库 ~/projects/cicy-dl-mirror),国内实测 1~3 MB/s。R2 在前,连不上(--connect-timeout)就换镜像。
25
+ const MIRROR = "https://dl.cicy-ai.com/releases";
26
+ const QEMU_SRCS = [R2 + "/qemu/" + QEMU_ZIP, MIRROR + "/qemu/" + QEMU_ZIP];
24
27
  // R2 上是两片(wrangler 单文件上限 300MiB):数组 = 分片,按序下完拼回;字符串 = 整个文件。
25
- const DEB_SRCS = [[R2 + "/debian/" + DEB_IMG + ".p0", R2 + "/debian/" + DEB_IMG + ".p1"], "https://cloud.debian.org/images/cloud/trixie/" + DEB_SERIAL + "/" + DEB_IMG];
28
+ const DEB_SRCS = [[R2 + "/debian/" + DEB_IMG + ".p0", R2 + "/debian/" + DEB_IMG + ".p1"], [MIRROR + "/debian/" + DEB_IMG + ".p0", MIRROR + "/debian/" + DEB_IMG + ".p1"], "https://cloud.debian.org/images/cloud/trixie/" + DEB_SERIAL + "/" + DEB_IMG];
26
29
  // 宿主侧端口全部只绑 127.0.0.1(hostfwd 写死),外网/局域网碰不到。
27
30
  const TTY_PORT = 17681, QMP_PORT = 17682, SEED_PORT = 17683, SSH_PORT = 17622;
28
31
  // cloud-init 的 instance-id:改 user-data 内容时 +1,已装好的虚拟机下次开机会按新配置重跑一遍
@@ -106,12 +109,12 @@ function hashFile(f, algo) {
106
109
  });
107
110
  }
108
111
  function curlText(url) {
109
- const r = cp.spawnSync(CURL, ["-fsSL", "--max-time", "30", url], { encoding: "utf8", windowsHide: true, timeout: 40000 });
112
+ const r = cp.spawnSync(CURL, ["-fsSL", "--connect-timeout", "10", "--max-time", "30", url], { encoding: "utf8", windowsHide: true, timeout: 40000 });
110
113
  return r.status === 0 ? String(r.stdout || "").trim() : "";
111
114
  }
112
115
  function curlTo(u, dest) {
113
116
  log("download " + u);
114
- const r = cp.spawnSync(CURL, ["-L", "-s", "-S", "-f", "-C", "-", "-o", dest + ".part", "--speed-limit", "100000", "--speed-time", "30", "--retry", "2", u], { encoding: "utf8", windowsHide: true, timeout: 3 * 3600 * 1000 });
117
+ const r = cp.spawnSync(CURL, ["-L", "-s", "-S", "-f", "-C", "-", "-o", dest + ".part", "--connect-timeout", "15", "--speed-limit", "100000", "--speed-time", "30", "--retry", "2", u], { encoding: "utf8", windowsHide: true, timeout: 3 * 3600 * 1000 });
115
118
  log("curl exit=" + r.status + " bytes=" + size(dest + ".part") + " " + String(r.stderr || "").trim().slice(-200));
116
119
  if (r.status === 0) { try { fs.renameSync(dest + ".part", dest); } catch { try { fs.copyFileSync(dest + ".part", dest); fs.unlinkSync(dest + ".part"); } catch {} } return fs.existsSync(dest); }
117
120
  // 33 = 服务器不支持续传 / 416 已下完但不认:清掉,下一个源从头来
@@ -157,7 +160,8 @@ async function installRun() {
157
160
  try {
158
161
  if (!(fs.existsSync(qemuExe) && fs.existsSync(qemuImg) && fs.existsSync(ttydBin))) {
159
162
  prog({ phase: "qemu", file: F.zip, total: 44400000 });
160
- const want = curlText(QEMU_SRCS[0] + ".sha256").split(/\s+/)[0];
163
+ let want = "";
164
+ for (const u of QEMU_SRCS) { want = curlText(u + ".sha256").split(/\s+/)[0]; if (/^[0-9a-f]{64}$/.test(want)) break; want = ""; }
161
165
  if (!(fs.existsSync(F.zip) && want && (await hashFile(F.zip, "sha256")) === want)) {
162
166
  try { fs.unlinkSync(F.zip); } catch {}
163
167
  if (!download(QEMU_SRCS, F.zip, prog)) return prog({ error: "qemu_download" });
@@ -303,8 +307,10 @@ function httpOk(port, p) {
303
307
  function accelOf() {
304
308
  const t = tailOf(F.qemuLog, 32 * 1024);
305
309
  if (!t && !pidAlive(readPid(F.qemuPid))) return "";
306
- // qemu 依次试 -accel:whpx 起不来会打一行 WHPX 报错再退到 tcg
307
- return /whpx/i.test(t) && /(fail|error|no accelerator|not supported|unavailable)/i.test(t) ? "tcg" : "whpx";
310
+ // qemu 依次试 -accel:whpx 起不来会打「failed to initialize whpx: …」再「falling back to tcg」。
311
+ // 只认这两句 —— WHPX 正常时也会打无害的 warning(如「WHPX: Failed to get performance monitoring
312
+ // features」),以前按「whpx + fail」判,把 9 台跑在 WHPX 上的机器误报成软件模拟(2026-10-23)。
313
+ return /falling back to tcg|failed to initialize whpx/i.test(t) ? "tcg" : "whpx";
308
314
  }
309
315
  function whpxFeature() { return WIN && fs.existsSync(path.join(process.env.SystemRoot || "C:\\Windows", "System32", "WinHvPlatform.dll")); }
310
316
  // 串口日志最后一行可读的话 = 开机进度(给卡片「启动中」下面那一行小字)
@@ -31,8 +31,17 @@ test("new Windows machine (no WSL install) → qemu on :8009, and the choice is
31
31
  } finally { restore(); }
32
32
  });
33
33
 
34
- test("old machine with a WSL docker status on :8008 stays on wsl and keeps :8008", () => {
35
- const { lb, restore } = fresh({ files: { "cicy-ai/db/docker-status.json": JSON.stringify({ installed: true, port: 8008 }) } });
34
+ test("a fresh decision is qemu even when the machine has a WSL install (2026-10-22: all machines QEMU)", () => {
35
+ const { lb, home, restore } = fresh({ files: { "cicy-ai/db/docker-status.json": JSON.stringify({ installed: true, port: 8008 }) } });
36
+ try {
37
+ assert.strictEqual(lb.init(), "qemu");
38
+ assert.strictEqual(process.env.CICY_DOCKER_APP_PORT, "8009");
39
+ assert.strictEqual(JSON.parse(fs.readFileSync(path.join(home, "cicy-ai", "db", "linux-backend.json"), "utf8")).hadWsl, true);
40
+ } finally { restore(); }
41
+ });
42
+
43
+ test("an already-persisted wsl decision is kept (old machines are migrated by hand, not on upgrade)", () => {
44
+ const { lb, restore } = fresh({ files: { "cicy-ai/db/linux-backend.json": JSON.stringify({ backend: "wsl" }) } });
36
45
  try {
37
46
  assert.strictEqual(lb.init(), "wsl");
38
47
  assert.strictEqual(process.env.CICY_DOCKER_APP_PORT, undefined);