zcode-pro 1.6.1 → 1.7.0
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.en.md +31 -21
- package/README.md +20 -12
- package/dist/inject.js +10431 -8836
- package/package.json +2 -1
- package/src/host/cdp.mjs +13 -3
- package/src/host/helper.mjs +1287 -488
- package/src/host/main.mjs +368 -30
- package/src/host/paths.mjs +17 -9
- package/src/host/pickFolder.mjs +11 -4
- package/src/host/settings.mjs +15 -2
- package/src/host/setup.mjs +54 -15
- package/src/host/skill-stats.mjs +6 -1
- package/src/host/taskIndex.mjs +464 -66
- package/src/host/taskOrder.mjs +128 -57
- package/src/host/version.mjs +15 -7
- package/src/host/wallpaper.mjs +76 -59
- package/src/host/webdav.mjs +66 -10
- package/src/inject/core.js +228 -103
- package/src/inject/features/alias-migration.js +5 -1
- package/src/inject/features/auto-rename.js +166 -0
- package/src/inject/features/file-menu.js +6 -2
- package/src/inject/features/idle-reclaim.js +31 -8
- package/src/inject/features/newtab-panels.js +11 -1
- package/src/inject/features/pinned-collapse.js +11 -3
- package/src/inject/features/plugin-card-retry.js +18 -8
- package/src/inject/features/plugin-updates.js +58 -0
- package/src/inject/features/sandbox-reclaim.js +17 -1
- package/src/inject/features/session-link.js +202 -0
- package/src/inject/features/session-switch.js +67 -30
- package/src/inject/features/settings-dialog.js +323 -124
- package/src/inject/features/status-bar.js +150 -28
- package/src/inject/features/subagent-icon.js +473 -0
- package/src/inject/features/table-copy.js +18 -2
- package/src/inject/features/task-order.js +47 -13
- package/src/inject/features/theme.js +88 -31
- package/src/inject/features/title-gen.js +5 -4
- package/src/inject/features/title-lock.js +13 -8
- package/src/inject/features/turn-usage.js +99 -47
- package/src/inject/features/ws-running.js +28 -13
- package/src/inject/index.js +7 -0
- package/src/inject/provider-fields.js +2 -2
- package/src/inject/ui.js +14 -0
package/src/host/settings.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// 读用于 helper 的 /projects 端点;写仅用于“切换文件夹”后的路径引用同步,
|
|
3
3
|
// 采用原子写并保留备份。
|
|
4
4
|
|
|
5
|
-
import { copyFileSync, existsSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
5
|
+
import { copyFileSync, existsSync, readFileSync, renameSync, statSync, writeFileSync } from 'node:fs';
|
|
6
6
|
import { join } from 'node:path';
|
|
7
7
|
|
|
8
8
|
export function readSettings(settingsFile) {
|
|
@@ -24,11 +24,24 @@ export function writeSettingsAtomic(settingsFile, next) {
|
|
|
24
24
|
if (existsSync(settingsFile)) {
|
|
25
25
|
try { copyFileSync(settingsFile, backup); } catch { /* 备份失败不阻塞 */ }
|
|
26
26
|
}
|
|
27
|
-
const tmp = settingsFile
|
|
27
|
+
const tmp = `${settingsFile}.${process.pid}.${Date.now().toString(36)}.tmp`; // 防多写者共用同一 .tmp 撕裂
|
|
28
28
|
writeFileSync(tmp, JSON.stringify(next, null, 2), 'utf8');
|
|
29
29
|
renameSync(tmp, settingsFile);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
// 读改写 setting.json 的路径引用同步:应用本体也在写这个文件,写回前核对文件
|
|
33
|
+
// mtime,期间被写过就重读重算再写(最多重算一次),别用旧快照覆盖应用刚写的条目
|
|
34
|
+
export function remapSettingsPathsAtomic(settingsFile, oldPath, newPath) {
|
|
35
|
+
const mtimeOf = () => { try { return statSync(settingsFile).mtimeMs; } catch { return 0; } };
|
|
36
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
37
|
+
const stamp = mtimeOf();
|
|
38
|
+
const next = remapSettingsPaths(readSettings(settingsFile), oldPath, newPath);
|
|
39
|
+
if (attempt === 0 && mtimeOf() !== stamp) continue; // 期间被写过:重读重算再写
|
|
40
|
+
writeSettingsAtomic(settingsFile, next);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
32
45
|
// 将 setting.json 中所有引用旧路径的字段映射到新路径,返回新 settings 对象。
|
|
33
46
|
// 替换时保留原值的尾分隔符风格(ZCode 自身多写带 / 的路径),减少与宿主写入的差异。
|
|
34
47
|
export function remapSettingsPaths(settings, oldPath, newPath) {
|
package/src/host/setup.mjs
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
// 文件编码,避开代码页问题;
|
|
16
16
|
// - 仓库内 PowerShell 脚本(install.ps1 等)必须保存为带 BOM 的 UTF-8。
|
|
17
17
|
import { execFileSync } from 'node:child_process';
|
|
18
|
-
import { accessSync, chmodSync, constants as fsConstants, copyFileSync, existsSync, mkdirSync, readFileSync, realpathSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
|
|
18
|
+
import { accessSync, chmodSync, constants as fsConstants, copyFileSync, existsSync, lstatSync, mkdirSync, readFileSync, readlinkSync, realpathSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
|
|
19
19
|
import { basename, dirname, join, sep } from 'node:path';
|
|
20
20
|
import { homedir, platform } from 'node:os';
|
|
21
21
|
import { fileURLToPath } from 'node:url';
|
|
@@ -144,6 +144,13 @@ function lnkIsOurs(lnkPath) {
|
|
|
144
144
|
|
|
145
145
|
const psQuote = (s) => String(s).replace(/'/g, "''"); // PowerShell 单引号字面量转义
|
|
146
146
|
|
|
147
|
+
// 降级快捷方式的起始位置:命令所在目录;剥不出绝对路径(PATH 里的裸命令名)就
|
|
148
|
+
// 交给调用方走回退(USERPROFILE 等),别把文件名当目录
|
|
149
|
+
const cmdWorkDir = (cmd) => {
|
|
150
|
+
const d = String(cmd).replace(/[\\/][^\\/]*$/, '');
|
|
151
|
+
return /^[A-Za-z]:[\\/]/.test(d) || /^[\\/]{2}/.test(d) ? d : '';
|
|
152
|
+
};
|
|
153
|
+
|
|
147
154
|
// 快捷方式计划(导出仅供测试审查,不执行)。desktop 为真时同时创建桌面快捷方式,
|
|
148
155
|
// 桌面目录由 PowerShell 的 GetFolderPath 解析(正确跟随 OneDrive 重定向等)。
|
|
149
156
|
// wshOk 为假(WSH 异常的机器)时降级:.lnk 直接经 cmd 最小化启动,不再依赖
|
|
@@ -159,7 +166,9 @@ export function windowsShortcutPlan(cmd, desktop = false, wshOk = true, menuLnk
|
|
|
159
166
|
' Dim parts()',
|
|
160
167
|
' ReDim parts(WScript.Arguments.Count - 1)',
|
|
161
168
|
' For i = 0 To WScript.Arguments.Count - 1',
|
|
162
|
-
'
|
|
169
|
+
" ' strip double quotes from each arg (Windows filenames never contain them)",
|
|
170
|
+
" ' an embedded quote would close the quoting and let the rest run as a command",
|
|
171
|
+
' parts(i) = """" & Replace(WScript.Arguments(i), """", "") & """"',
|
|
163
172
|
' Next',
|
|
164
173
|
' cmd = cmd & " " & Join(parts, " ")',
|
|
165
174
|
'End If',
|
|
@@ -182,8 +191,12 @@ export function windowsShortcutPlan(cmd, desktop = false, wshOk = true, menuLnk
|
|
|
182
191
|
] : [
|
|
183
192
|
'function setProps($l) {',
|
|
184
193
|
' $l.TargetPath = "$env:SystemRoot\\System32\\cmd.exe"',
|
|
194
|
+
// cmd.exe 会展开参数里的 %VAR%:cmd 路径本身含 % 的安装位置会被展开成别的
|
|
195
|
+
// 文件。命令行参数没有可靠转义方式,暂不处理(vbs 主路径不受影响)
|
|
185
196
|
` $l.Arguments = '/c start "ZCodePro-Setup" /min "${psQuote(cmd)}"'`,
|
|
186
|
-
|
|
197
|
+
// 降级分支不建 vbsDir(目录可能不存在,快捷方式会报“起始位置无效”):
|
|
198
|
+
// 起始位置改用命令所在目录
|
|
199
|
+
` $l.WorkingDirectory = '${psQuote(cmdWorkDir(cmd) || process.env.USERPROFILE || process.env.HOME || paths.vbsDir)}'`,
|
|
187
200
|
" $l.Description = 'ZCode 桌面版增强启动器(壁纸引擎、皮肤主题等,不修改客户端文件)'",
|
|
188
201
|
iconLine,
|
|
189
202
|
' $l.WindowStyle = 7',
|
|
@@ -215,7 +228,7 @@ export function windowsShortcutPlan(cmd, desktop = false, wshOk = true, menuLnk
|
|
|
215
228
|
// PowerShell 的 GetFolderPath,正确跟随 OneDrive 重定向)。OneDrive 桌面重定向时
|
|
216
229
|
// 桌面在 %OneDrive%\Desktop,未重定向时在用户主目录
|
|
217
230
|
export function desktopLnkPathApprox() {
|
|
218
|
-
for (const od of [process.env.OneDrive, process.env.OneDriveConsumer]) {
|
|
231
|
+
for (const od of [process.env.OneDrive, process.env.OneDriveConsumer, process.env.OneDriveCommercial]) {
|
|
219
232
|
if (od && existsSync(join(od, 'Desktop'))) return join(od, 'Desktop', 'ZCode Pro.lnk');
|
|
220
233
|
}
|
|
221
234
|
return join(homedir(), 'Desktop', 'ZCode Pro.lnk');
|
|
@@ -325,7 +338,10 @@ const shortcutItem = {
|
|
|
325
338
|
// 早期版本写过 0644 的条目:即使内容无需重写也补上执行位(原因见 writeDesktopEntry)
|
|
326
339
|
chmodSync(target, 0o755);
|
|
327
340
|
const exec = (cur.match(/^Exec=(.+)$/m) || [])[1] || '';
|
|
328
|
-
|
|
341
|
+
// 去掉引号后全等比较:子串判断会把指向旧命令(如 zcode-pro-old)的条目
|
|
342
|
+
// 误当成已指向当前命令而跳过更新
|
|
343
|
+
const execCmd = exec.trim().replace(/^"(.*)"$/, '$1');
|
|
344
|
+
if (execCmd === cmd) {
|
|
329
345
|
parts.push('app-menu entry already exists and points to the current command, nothing to do');
|
|
330
346
|
} else {
|
|
331
347
|
writeDesktopEntry(target, cmd);
|
|
@@ -394,6 +410,10 @@ const shortcutItem = {
|
|
|
394
410
|
if (existsSync(app) && !existsSync(marker)) {
|
|
395
411
|
return { skipped: `${app} exists and was not created by setup, not overwritten` };
|
|
396
412
|
}
|
|
413
|
+
// 归属标记先于内容写入:中途失败(复制图标、写启动器等)留下的残包仍带标记,
|
|
414
|
+
// 下次重装直接覆盖重建;反过来(标记最后写)会留下装不进也卸不掉的半成品
|
|
415
|
+
mkdirSync(contents, { recursive: true });
|
|
416
|
+
writeFileSync(marker, '');
|
|
397
417
|
let iconCopied = false;
|
|
398
418
|
for (const src of [join('/', 'Applications', 'ZCode.app', 'Contents', 'Resources', 'app.icns'),
|
|
399
419
|
join(homedir(), 'Applications', 'ZCode.app', 'Contents', 'Resources', 'app.icns')]) {
|
|
@@ -407,20 +427,28 @@ const shortcutItem = {
|
|
|
407
427
|
}
|
|
408
428
|
mkdirSync(join(contents, 'MacOS'), { recursive: true });
|
|
409
429
|
const launcher = join(contents, 'MacOS', 'zcode-pro');
|
|
410
|
-
|
|
430
|
+
// 路径里的 " ` $ \ 按 shell 双引号规则转义:不转义时路径含这些字符会破坏
|
|
431
|
+
// 生成的启动器甚至被当命令替换求值
|
|
432
|
+
writeFileSync(launcher, `#!/bin/sh\nexec "${String(cmd).replace(/([\\"`$])/g, '\\$1')}" "$@"\n`);
|
|
411
433
|
chmodSync(launcher, 0o755);
|
|
412
434
|
writeFileSync(join(contents, 'Info.plist'), plistContent(iconCopied));
|
|
413
|
-
writeFileSync(marker, '');
|
|
414
435
|
let detail = `created ${app} (launcher -> ${cmd}${iconCopied ? ', icon copied' : ''})`;
|
|
415
436
|
if (opts.desktop) {
|
|
416
437
|
const link = macDesktopLink();
|
|
417
|
-
|
|
438
|
+
// 断链符号链接 existsSync 也返回假,会被误判成不存在,symlinkSync 反而报
|
|
439
|
+
// EEXIST 被空 catch 吞掉、桌面入口静默建不出:存在性改用 lstat 判断
|
|
440
|
+
let linkExists = true;
|
|
441
|
+
try { lstatSync(link); } catch { linkExists = false; }
|
|
442
|
+
if (linkExists) {
|
|
418
443
|
detail += '; desktop entry with the same name exists, not overwritten';
|
|
419
444
|
} else {
|
|
420
445
|
try {
|
|
421
446
|
symlinkSync(app, link);
|
|
422
447
|
detail += `; desktop ${link}`;
|
|
423
|
-
} catch {
|
|
448
|
+
} catch (err) {
|
|
449
|
+
// EEXIST(判断与创建之间被抢先建出)按“已存在不覆盖”汇报;其余失败只省略桌面入口
|
|
450
|
+
if (err?.code === 'EEXIST') detail += '; desktop entry with the same name exists, not overwritten';
|
|
451
|
+
}
|
|
424
452
|
}
|
|
425
453
|
}
|
|
426
454
|
return { detail };
|
|
@@ -454,7 +482,10 @@ const shortcutItem = {
|
|
|
454
482
|
const paths = windowsPaths();
|
|
455
483
|
const hadVbs = existsSync(paths.vbsPath);
|
|
456
484
|
const hadLnk = existsSync(paths.lnkPath);
|
|
457
|
-
|
|
485
|
+
// 桌面 .lnk 可能是唯一残留(开始菜单与 vbs 已被清掉):提前返回前一并判断,
|
|
486
|
+
// 否则桌面快捷方式漏删
|
|
487
|
+
const hadDesk = existsSync(desktopLnkPathApprox());
|
|
488
|
+
if (!hadVbs && !hadLnk && !hadDesk) return { skipped: 'no setup-created shortcuts found' };
|
|
458
489
|
// .lnk 可能已被 install.ps1 等重建并指向它自己:只有 Arguments 带本功能归属
|
|
459
490
|
// 标记才删;校验失败也保留 .lnk(宁可漏删不误删)
|
|
460
491
|
let lnkRemoved = false;
|
|
@@ -473,7 +504,7 @@ const shortcutItem = {
|
|
|
473
504
|
'}',
|
|
474
505
|
].join('\r\n'));
|
|
475
506
|
verified = true;
|
|
476
|
-
lnkRemoved = !existsSync(paths.lnkPath);
|
|
507
|
+
lnkRemoved = !existsSync(paths.lnkPath) && !existsSync(desktopLnkPathApprox());
|
|
477
508
|
} catch { /* 校验失败则不动 .lnk */ }
|
|
478
509
|
let vbsCleaned = !hadVbs;
|
|
479
510
|
if (hadVbs) {
|
|
@@ -493,7 +524,7 @@ const shortcutItem = {
|
|
|
493
524
|
}
|
|
494
525
|
}
|
|
495
526
|
const parts = [];
|
|
496
|
-
if (hadLnk) {
|
|
527
|
+
if (hadLnk || hadDesk) {
|
|
497
528
|
parts.push(lnkRemoved ? 'start-menu/desktop shortcut' : verified ? 'shortcut not created by setup, kept' : 'shortcut ownership check failed, .lnk kept');
|
|
498
529
|
}
|
|
499
530
|
if (hadVbs) parts.push(vbsCleaned ? 'generated launcher script' : 'launcher script (delete failed)');
|
|
@@ -506,9 +537,17 @@ const shortcutItem = {
|
|
|
506
537
|
if (!existsSync(marker)) return { skipped: 'no setup-created app bundle found' };
|
|
507
538
|
// setup --desktop 建的桌面入口一并清理(只删指向本应用包的链接)
|
|
508
539
|
const link = macDesktopLink();
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
} catch { /*
|
|
540
|
+
// 断链符号链接 existsSync 返回假、realpath 抛错,都会漏删:存在性用 lstat 判断
|
|
541
|
+
let linkInfo = null;
|
|
542
|
+
try { linkInfo = lstatSync(link); } catch { /* 无桌面入口 */ }
|
|
543
|
+
if (linkInfo) {
|
|
544
|
+
// 目标比较先用链接记录的文本(本功能建链时写的就是应用包路径,断链也读得出),
|
|
545
|
+
// 再退回解析后的真实路径(目标经其他符号链接中转的情形)
|
|
546
|
+
let ours = false;
|
|
547
|
+
try { ours = linkInfo.isSymbolicLink() && readlinkSync(link) === app; } catch { /* 读不出目标 */ }
|
|
548
|
+
if (!ours) { try { ours = realpathSync(link) === realpathSync(app); } catch { /* 断链且目标文本不同 */ } }
|
|
549
|
+
if (ours) rmSync(link);
|
|
550
|
+
}
|
|
512
551
|
rmSync(app, { recursive: true, force: true });
|
|
513
552
|
return { detail: `removed ${app}` };
|
|
514
553
|
},
|
package/src/host/skill-stats.mjs
CHANGED
|
@@ -37,7 +37,12 @@ function parseFrontmatter(text) {
|
|
|
37
37
|
function loadSkill(dir) {
|
|
38
38
|
const path = join(dir, 'SKILL.md');
|
|
39
39
|
if (!existsSync(path)) return null;
|
|
40
|
-
|
|
40
|
+
let fm;
|
|
41
|
+
try {
|
|
42
|
+
fm = parseFrontmatter(readFileSync(path, 'utf8'));
|
|
43
|
+
} catch {
|
|
44
|
+
return null; // 断链、无权限等坏条目跳过,别砸掉整个统计
|
|
45
|
+
}
|
|
41
46
|
let name;
|
|
42
47
|
let description = '';
|
|
43
48
|
let whenToUse = '';
|