zcode-pro 1.5.0 → 1.6.1
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 +4 -2
- package/README.md +5 -3
- package/dist/inject.js +1372 -313
- package/package.json +2 -2
- package/src/host/helper.mjs +705 -96
- package/src/host/main.mjs +53 -5
- package/src/host/setup.mjs +3 -3
- package/src/host/skill-stats.mjs +158 -0
- package/src/host/taskIndex.mjs +11 -7
- package/src/host/wallpaper.mjs +311 -0
- package/src/inject/core.js +148 -46
- package/src/inject/features/alias-migration.js +3 -3
- package/src/inject/features/alias.js +2 -2
- package/src/inject/features/composer-provider.js +82 -63
- package/src/inject/features/copy-path.js +1 -1
- package/src/inject/features/file-menu.js +3 -1
- package/src/inject/features/image-menu.js +2 -2
- package/src/inject/features/newtab-panels.js +5 -3
- package/src/inject/features/project-menu.js +1 -1
- package/src/inject/features/relocate-dialog.js +2 -1
- package/src/inject/features/session-switch.js +94 -32
- package/src/inject/features/settings-dialog.js +344 -91
- package/src/inject/features/task-order.js +1 -1
- package/src/inject/features/theme.js +586 -98
- package/src/inject/features/title-gen.js +3 -2
- package/src/inject/features/title-lock.js +3 -2
- package/src/inject/features/ws-running.js +61 -8
- package/src/inject/index.js +13 -1
- package/src/inject/ui.js +85 -17
package/src/host/main.mjs
CHANGED
|
@@ -14,6 +14,7 @@ import { readZcodeVersion } from './version.mjs';
|
|
|
14
14
|
import { CdpConnection, fetchBrowserWsUrl } from './cdp.mjs';
|
|
15
15
|
import { startHelper } from './helper.mjs';
|
|
16
16
|
import { runSetup } from './setup.mjs';
|
|
17
|
+
import { runWallpaperCli, installWallpaperDocs, removeWallpaperDocs } from './wallpaper.mjs';
|
|
17
18
|
|
|
18
19
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
19
20
|
const INJECT_BUNDLE = resolve(here, '..', '..', 'dist', 'inject.js');
|
|
@@ -34,7 +35,7 @@ if (process.platform === 'win32' && (process.stdout.isTTY || process.stdin.isTTY
|
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
function usage() {
|
|
37
|
-
return `ZCode Pro — ZCode
|
|
38
|
+
return `ZCode Pro — ZCode 桌面版增强启动器(壁纸引擎与界面增强)
|
|
38
39
|
|
|
39
40
|
用法: zcode-pro [选项]
|
|
40
41
|
|
|
@@ -50,6 +51,7 @@ function usage() {
|
|
|
50
51
|
setup 安装本机集成(快捷方式:Linux 应用菜单 / Windows 开始菜单 / macOS 应用)
|
|
51
52
|
setup --desktop 同时在桌面创建快捷方式
|
|
52
53
|
setup --uninstall 移除由 setup 安装的集成(含桌面)
|
|
54
|
+
wallpaper <操作> 壁纸引擎控制:list/set/rotate/params/upload/delete(wallpaper -h 详览)
|
|
53
55
|
|
|
54
56
|
环境变量:
|
|
55
57
|
ZCODEPRO_ZCODE_PATH ZCode 可执行文件路径(同 --zcode-path)
|
|
@@ -155,16 +157,35 @@ async function waitForCdp(port, timeoutMs) {
|
|
|
155
157
|
return false;
|
|
156
158
|
}
|
|
157
159
|
|
|
160
|
+
// 沙箱透明样式:插件卡片(zcode-sandbox 壳/插件页)注入的唯一内容。
|
|
161
|
+
// 不含 token、不碰宿主接口,只是把页面自带的实色 body 背景顶成透明,
|
|
162
|
+
// 让壁纸从卡片透出(与注入层的 webview.insertCSS 双保险)
|
|
163
|
+
const SANDBOX_STYLE_SCRIPT = `(() => {
|
|
164
|
+
const s = document.createElement('style');
|
|
165
|
+
s.textContent = 'html,body{background:transparent !important}';
|
|
166
|
+
(document.head || document.documentElement).append(s);
|
|
167
|
+
})();`;
|
|
168
|
+
|
|
158
169
|
async function buildInjectSource(token, helperPort, features, zcodeVersion) {
|
|
159
170
|
if (!existsSync(INJECT_BUNDLE)) {
|
|
160
171
|
throw new Error('缺少注入脚本 dist/inject.js,请先运行 npm run build');
|
|
161
172
|
}
|
|
162
173
|
const bundle = readFileSync(INJECT_BUNDLE, 'utf8');
|
|
163
174
|
const bootstrap = `window.__ZCODEPRO__={helperUrl:'http://127.0.0.1:${helperPort}',token:${JSON.stringify(token)},features:${JSON.stringify(features)},zcodeVersion:${JSON.stringify(zcodeVersion || '')}};`;
|
|
164
|
-
|
|
175
|
+
// token 护栏做成运行时自检:attach 时判定 URL 挡不住“空白初页 → 导航去沙箱/外网”
|
|
176
|
+
// 的目标(引导脚本会随 addScript 落进该会话之后的每个文档)。每文档执行时看真实
|
|
177
|
+
// href,沙箱/外链页面整段跳过,token 不出应用页;空白文档也跳过(真应用文档会
|
|
178
|
+
// 以自己的 URL 再触发一次钩子)
|
|
179
|
+
const guard = 'if (!/^(zcode-sandbox|about|data|blob|view-source):/i.test(location.href) && !(/^https?:\\/\\//i.test(location.href) && !/^https?:\\/\\/(127\\.0\\.0\\.1|localhost)(:\\d+)?(\\/|$|\\?|#)/i.test(location.href))) {';
|
|
180
|
+
return guard + bootstrap + '\n' + bundle + '\n}';
|
|
165
181
|
}
|
|
166
182
|
|
|
167
183
|
export async function run(argv) {
|
|
184
|
+
// wallpaper 子命令只碰壁纸配置/图库,不启动 ZCode,先于其余参数解析处理
|
|
185
|
+
if (argv[0] === 'wallpaper') {
|
|
186
|
+
process.exitCode = await runWallpaperCli(argv.slice(1), resolveDataRootDir());
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
168
189
|
const args = parseArgs(argv);
|
|
169
190
|
if (args.help) { console.log(usage()); return; }
|
|
170
191
|
// setup 不依赖 ZCode 运行(装快捷方式等本机集成),先于 ZCode 定位处理
|
|
@@ -175,6 +196,7 @@ export async function run(argv) {
|
|
|
175
196
|
return;
|
|
176
197
|
}
|
|
177
198
|
await runSetup({ uninstall: args.setupUninstall, desktop: args.setupDesktop });
|
|
199
|
+
if (args.setupUninstall) { try { removeWallpaperDocs(resolveDataRootDir()); } catch { /* ignore */ } }
|
|
178
200
|
return;
|
|
179
201
|
}
|
|
180
202
|
const log = (...a) => { if (args.verbose) console.log('[zcodepro]', ...a); };
|
|
@@ -193,6 +215,7 @@ export async function run(argv) {
|
|
|
193
215
|
const zcodeVersion = readZcodeVersion(exe);
|
|
194
216
|
if (args.verbose) console.log(`[zcodepro] ZCode 版本: ${zcodeVersion || '未知(app.asar 读取失败)'}`);
|
|
195
217
|
const dataRoot = resolveDataRootDir();
|
|
218
|
+
try { installWallpaperDocs(dataRoot); } catch { /* 命令/技能文件写入失败不挡启动 */ }
|
|
196
219
|
const token = randomBytes(16).toString('hex');
|
|
197
220
|
const state = { injectedPages: 0 };
|
|
198
221
|
|
|
@@ -248,13 +271,38 @@ export async function run(argv) {
|
|
|
248
271
|
|
|
249
272
|
const handleAttach = async (sessionId, targetInfo) => {
|
|
250
273
|
const targetId = targetInfo?.targetId;
|
|
251
|
-
if (!targetId
|
|
274
|
+
if (!targetId) return;
|
|
275
|
+
const pageUrl = String(targetInfo?.url || '');
|
|
276
|
+
// 插件卡片(zcode-sandbox 壳 + 插件页 iframe):只注入透明背景样式,不带
|
|
277
|
+
// 引导脚本——沙箱页面拿不到 token,下面的护栏不受影响。背景透明后壁纸能
|
|
278
|
+
// 从卡片透出(插件页自带的实色 body 背景被这条 !important 顶掉)
|
|
279
|
+
if (/^zcode-sandbox:\/\//i.test(pageUrl)) {
|
|
280
|
+
// 每步独立容错:iframe 会话上 addScript 若被拒,立即执行那步不能跟着一起死,
|
|
281
|
+
// 否则样式永远进不去(白底卡片的根因)
|
|
282
|
+
let ok = false;
|
|
283
|
+
try {
|
|
284
|
+
await conn.send('Page.enable', {}, sessionId);
|
|
285
|
+
await conn.send('Page.addScriptToEvaluateOnNewDocument', { source: SANDBOX_STYLE_SCRIPT, runImmediately: true }, sessionId);
|
|
286
|
+
ok = true;
|
|
287
|
+
} catch (err) {
|
|
288
|
+
log('沙箱新文档钩子注册失败(继续立即执行): ' + err.message);
|
|
289
|
+
}
|
|
290
|
+
try {
|
|
291
|
+
await conn.send('Runtime.evaluate', { expression: SANDBOX_STYLE_SCRIPT, silent: true }, sessionId);
|
|
292
|
+
ok = true;
|
|
293
|
+
} catch (err) {
|
|
294
|
+
log('沙箱立即注入失败: ' + err.message);
|
|
295
|
+
}
|
|
296
|
+
if (ok) log('已注入沙箱透明样式: ' + pageUrl.slice(0, 60));
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
if (targetInfo?.type !== 'page') return;
|
|
252
300
|
// 安全护栏:引导脚本内含 helper 鉴权 token,只能注入 ZCode 应用自身的页面。
|
|
253
301
|
// 外部网站若以内嵌浏览器/网页形式成为 page target,拿到 token 即可调用本地
|
|
254
302
|
// helper(改写增强配置/别名表等)。规则:放行非 http(s)(file://、应用自有协议)与
|
|
255
303
|
// 本机回环地址,拦截其余外部网页。代价是 http(s) 非 localhost 的自有页面不注入。
|
|
256
|
-
const
|
|
257
|
-
|
|
304
|
+
const isExternalWeb = (/^https?:\/\//i.test(pageUrl) && !/^https?:\/\/(127\.0\.0\.1|localhost)(:\d+)?(\/|$|\?|#)/i.test(pageUrl))
|
|
305
|
+
|| /^(data|blob|view-source|about):/i.test(pageUrl); // 非 http 协议的子文档也能拿 token,一并跳过
|
|
258
306
|
if (isExternalWeb) {
|
|
259
307
|
log('跳过外部页面注入(防止 token 泄露): ' + pageUrl.slice(0, 120));
|
|
260
308
|
return;
|
package/src/host/setup.mjs
CHANGED
|
@@ -176,7 +176,7 @@ export function windowsShortcutPlan(cmd, desktop = false, wshOk = true, menuLnk
|
|
|
176
176
|
' $l.TargetPath = "$env:SystemRoot\\System32\\wscript.exe"',
|
|
177
177
|
` $l.Arguments = '${psQuote(`"${paths.vbsPath}"`)}'`,
|
|
178
178
|
` $l.WorkingDirectory = '${psQuote(paths.vbsDir)}'`,
|
|
179
|
-
" $l.Description = 'ZCode
|
|
179
|
+
" $l.Description = 'ZCode 桌面版增强启动器(壁纸引擎、皮肤主题等,不修改客户端文件)'",
|
|
180
180
|
iconLine,
|
|
181
181
|
'}',
|
|
182
182
|
] : [
|
|
@@ -184,7 +184,7 @@ export function windowsShortcutPlan(cmd, desktop = false, wshOk = true, menuLnk
|
|
|
184
184
|
' $l.TargetPath = "$env:SystemRoot\\System32\\cmd.exe"',
|
|
185
185
|
` $l.Arguments = '/c start "ZCodePro-Setup" /min "${psQuote(cmd)}"'`,
|
|
186
186
|
` $l.WorkingDirectory = '${psQuote(paths.vbsDir)}'`,
|
|
187
|
-
" $l.Description = 'ZCode
|
|
187
|
+
" $l.Description = 'ZCode 桌面版增强启动器(壁纸引擎、皮肤主题等,不修改客户端文件)'",
|
|
188
188
|
iconLine,
|
|
189
189
|
' $l.WindowStyle = 7',
|
|
190
190
|
'}',
|
|
@@ -233,7 +233,7 @@ function desktopEntry(execCmd) {
|
|
|
233
233
|
'[Desktop Entry]',
|
|
234
234
|
'Type=Application',
|
|
235
235
|
'Name=ZCode Pro',
|
|
236
|
-
'Comment=ZCode
|
|
236
|
+
'Comment=ZCode 桌面版增强启动器(壁纸引擎、皮肤主题等,不修改客户端文件)',
|
|
237
237
|
`Exec=${exec}`,
|
|
238
238
|
'Icon=zcode',
|
|
239
239
|
'Terminal=false',
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// 技能清单检查:扫描本地与插件技能,按 ZCode 注入清单的条目格式拼出完整清单,
|
|
2
|
+
// 统计字符数是否超出 skills.metadataBudget(超预算时 ZCode 会把清单降级成仅名称)。
|
|
3
|
+
// 条目格式、描述 250 字符截断、默认预算 20000 均于 2026-10-28 反查 ZCode 程序
|
|
4
|
+
// (resources/glm/zcode.cjs 的 buildSkillsContent/formatSkillLine)核对,升级后需复核。
|
|
5
|
+
// 估算只要够判断超没超预算即可,不要求与程序逐字符一致(frontmatter 续行的
|
|
6
|
+
// 折叠方式等按常规处理)。
|
|
7
|
+
import { readdirSync, readFileSync, existsSync } from 'node:fs';
|
|
8
|
+
import { join, dirname, basename } from 'node:path';
|
|
9
|
+
|
|
10
|
+
export const DEFAULT_METADATA_BUDGET = 20000;
|
|
11
|
+
const DESC_LIMIT = 250; // description - when_to_use 合并后截断到 250 字符
|
|
12
|
+
const DESC_LOAD_LIMIT = 1024; // description 超 1024 字符的技能加载失败(丢弃)
|
|
13
|
+
const HEADER = 'The following skills are available for use with the Skill tool:\n\n';
|
|
14
|
+
|
|
15
|
+
// SKILL.md frontmatter:只取顶层 key: value(缩进行忽略,>/| 折叠续行);
|
|
16
|
+
// 没有 frontmatter 返回 null
|
|
17
|
+
function parseFrontmatter(text) {
|
|
18
|
+
const m = /^---[ \t]*\r?\n([\s\S]*?)\r?\n---[ \t]*(\r?\n|$)/.exec(text);
|
|
19
|
+
if (!m) return null;
|
|
20
|
+
const out = {};
|
|
21
|
+
let cur = null;
|
|
22
|
+
for (const line of m[1].split(/\r?\n/)) {
|
|
23
|
+
const kv = /^([A-Za-z_][\w-]*):[ \t]*(.*)$/.exec(line);
|
|
24
|
+
if (kv) {
|
|
25
|
+
cur = kv[1];
|
|
26
|
+
out[cur] = /^[>|][+-]?$/.test(kv[2]) ? '' : kv[2].trim();
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (cur && /^\s+\S/.test(line)) out[cur] = (out[cur] ? out[cur] + ' ' : '') + line.trim();
|
|
30
|
+
}
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// 一个技能目录 → 清单条目;按 ZCode 的两级失败模型处理:
|
|
35
|
+
// 无 frontmatter 用目录名(可加载但描述为空);有 frontmatter 而缺
|
|
36
|
+
// name/description 或 description 超长则加载失败(不进清单)
|
|
37
|
+
function loadSkill(dir) {
|
|
38
|
+
const path = join(dir, 'SKILL.md');
|
|
39
|
+
if (!existsSync(path)) return null;
|
|
40
|
+
const fm = parseFrontmatter(readFileSync(path, 'utf8'));
|
|
41
|
+
let name;
|
|
42
|
+
let description = '';
|
|
43
|
+
let whenToUse = '';
|
|
44
|
+
if (fm) {
|
|
45
|
+
name = (fm.name || '').trim();
|
|
46
|
+
description = (fm.description || '').trim();
|
|
47
|
+
whenToUse = (fm.when_to_use || '').trim();
|
|
48
|
+
if (!name || !description || description.length > DESC_LOAD_LIMIT) return null;
|
|
49
|
+
} else {
|
|
50
|
+
name = basename(dir);
|
|
51
|
+
}
|
|
52
|
+
return { name, description, whenToUse, path };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const listDirs = (dir) => {
|
|
56
|
+
try {
|
|
57
|
+
return readdirSync(dir, { withFileTypes: true })
|
|
58
|
+
.filter((d) => d.isDirectory() && (!d.name.startsWith('.') || d.name === '.system') && d.name !== 'node_modules')
|
|
59
|
+
.map((d) => join(dir, d.name));
|
|
60
|
+
} catch {
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// 扫一个技能根目录:每个直接子目录里有 SKILL.md 即一个技能
|
|
66
|
+
function scanRoot(root, pluginId) {
|
|
67
|
+
const out = [];
|
|
68
|
+
for (const dir of listDirs(root)) {
|
|
69
|
+
const entry = loadSkill(dir);
|
|
70
|
+
if (entry) {
|
|
71
|
+
// 插件技能的限定名形如 插件名:技能名,与裸名不同还附“也可以用裸名加载”
|
|
72
|
+
if (pluginId) entry.qualifiedName = `${pluginId}:${entry.name}`;
|
|
73
|
+
out.push(entry);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// 插件缓存目录按 <市场>/<插件>/<版本>/skills 布局,同一插件只取最高版本
|
|
80
|
+
function pluginVersionDirs(cacheDir) {
|
|
81
|
+
const byPlugin = new Map();
|
|
82
|
+
for (const marketDir of listDirs(cacheDir)) {
|
|
83
|
+
const market = basename(marketDir);
|
|
84
|
+
for (const pluginDir of listDirs(marketDir)) {
|
|
85
|
+
const plugin = basename(pluginDir);
|
|
86
|
+
const key = `${market}/${plugin}`;
|
|
87
|
+
const versions = listDirs(pluginDir).map((v) => basename(v));
|
|
88
|
+
if (!versions.length) continue;
|
|
89
|
+
versions.sort((a, b) => {
|
|
90
|
+
const pa = a.split('.').map((n) => parseInt(n, 10) || 0);
|
|
91
|
+
const pb = b.split('.').map((n) => parseInt(n, 10) || 0);
|
|
92
|
+
for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
|
|
93
|
+
if ((pa[i] || 0) !== (pb[i] || 0)) return (pa[i] || 0) - (pb[i] || 0);
|
|
94
|
+
}
|
|
95
|
+
return 0;
|
|
96
|
+
});
|
|
97
|
+
byPlugin.set(key, { market, plugin, versionDir: join(pluginDir, versions[versions.length - 1]) });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return [...byPlugin.values()];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// 发现顺序(与 ZCode 一致):显式配置的目录 → ~/.zcode/skills → ~/.agents/skills
|
|
104
|
+
// → 启用中的插件(最低优先级)。同一技能名出现在多个路径时清单里都算(条目身份
|
|
105
|
+
// 是文件路径),这里不做同名去重。项目内的 .zcode/.agents 技能随项目而变,不计入。
|
|
106
|
+
export function scanSkills({ dataRoot, roots = [], pluginsEnabled = true, enabledPlugins = {}, suppressedBuiltins = [] }) {
|
|
107
|
+
const userRoots = [
|
|
108
|
+
...roots,
|
|
109
|
+
join(dataRoot, 'skills'),
|
|
110
|
+
join(dirname(dataRoot), '.agents', 'skills'),
|
|
111
|
+
];
|
|
112
|
+
const entries = [];
|
|
113
|
+
for (const root of userRoots) entries.push(...scanRoot(root));
|
|
114
|
+
const pluginEntries = [];
|
|
115
|
+
if (pluginsEnabled) {
|
|
116
|
+
for (const { market, plugin, versionDir } of pluginVersionDirs(join(dataRoot, 'cli', 'plugins', 'cache'))) {
|
|
117
|
+
const id = `${plugin}@${market}`;
|
|
118
|
+
if (enabledPlugins[id] === false || suppressedBuiltins.includes(plugin) || suppressedBuiltins.includes(id)) continue;
|
|
119
|
+
pluginEntries.push(...scanRoot(join(versionDir, 'skills'), plugin));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return { entries, pluginEntries };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// 清单条目行(ZCode formatSkillLine)
|
|
126
|
+
function formatLine(e) {
|
|
127
|
+
const display = e.qualifiedName ?? e.name;
|
|
128
|
+
const alias = e.qualifiedName && e.qualifiedName !== e.name ? ` (also loadable as ${e.name})` : '';
|
|
129
|
+
const desc = e.whenToUse ? `${e.description} - ${e.whenToUse}` : e.description;
|
|
130
|
+
const cut = desc.length > DESC_LIMIT ? `${desc.slice(0, DESC_LIMIT - 1)}...` : desc;
|
|
131
|
+
return `- ${display}: ${cut}${alias} (file: ${e.path})`;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// 完整清单字符数(含表头)——ZCode 拿这个长度和预算比,超了就降级成仅名称
|
|
135
|
+
function fullContentChars(entries) {
|
|
136
|
+
const lines = [...entries]
|
|
137
|
+
.sort((a, b) => (a.qualifiedName ?? a.name).localeCompare(b.qualifiedName ?? b.name))
|
|
138
|
+
.map(formatLine);
|
|
139
|
+
return (HEADER + lines.join('\n')).length;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function skillStats(opts) {
|
|
143
|
+
const { entries, pluginEntries } = scanSkills(opts);
|
|
144
|
+
const all = [...entries, ...pluginEntries];
|
|
145
|
+
const fullChars = fullContentChars(all);
|
|
146
|
+
const budget = Number.isFinite(opts.budget) && opts.budget >= 0 ? opts.budget : DEFAULT_METADATA_BUDGET;
|
|
147
|
+
return {
|
|
148
|
+
total: all.length,
|
|
149
|
+
userCount: entries.length,
|
|
150
|
+
pluginCount: pluginEntries.length,
|
|
151
|
+
fullChars,
|
|
152
|
+
budget,
|
|
153
|
+
defaultBudget: DEFAULT_METADATA_BUDGET,
|
|
154
|
+
degraded: fullChars > budget,
|
|
155
|
+
// 建议预算:完整清单加 20% 余量,向上取整到千
|
|
156
|
+
suggested: Math.ceil((fullChars * 1.2) / 1000) * 1000,
|
|
157
|
+
};
|
|
158
|
+
}
|
package/src/host/taskIndex.mjs
CHANGED
|
@@ -241,8 +241,9 @@ export async function listVirtualProjects(dataRoot) {
|
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
243
|
|
|
244
|
-
// 批量查会话终态:task_id →
|
|
245
|
-
// 卡滞的报告(会话已完成但内存态仍报活跃时,任务行 loader
|
|
244
|
+
// 批量查会话终态:task_id → { status, updatedAt, title }。分区头运行判定用它
|
|
245
|
+
// 剔除官方 syncer 卡滞的报告(会话已完成但内存态仍报活跃时,任务行 loader 会
|
|
246
|
+
// 一直卡转);title 供 alt+r 弹窗显示折叠项目(行不在场)会话的标题。
|
|
246
247
|
// 读不到(库缺失/无驱动)返回 null,调用方按未确认处理
|
|
247
248
|
export async function listTaskStatuses(dataRoot, ids) {
|
|
248
249
|
const out = {};
|
|
@@ -252,17 +253,19 @@ export async function listTaskStatuses(dataRoot, ids) {
|
|
|
252
253
|
if (!driver) return null;
|
|
253
254
|
const esc = (v) => "'" + String(v).replace(/'/g, "''") + "'";
|
|
254
255
|
const inList = ids.map((id) => esc(id)).join(', ');
|
|
255
|
-
const sql = `SELECT task_id, task_status, updated_at FROM tasks WHERE task_id IN (${inList})`;
|
|
256
|
+
const sql = `SELECT task_id, task_status, updated_at, title FROM tasks WHERE task_id IN (${inList})`;
|
|
256
257
|
try {
|
|
257
258
|
let rows;
|
|
258
259
|
if (driver.kind === 'node') {
|
|
259
260
|
const db = new driver.DatabaseSync(dbFile, { readOnly: true });
|
|
260
261
|
try { rows = db.prepare(sql).all(); } finally { db.close(); }
|
|
261
262
|
} else {
|
|
262
|
-
|
|
263
|
-
|
|
263
|
+
// 标题可含任意字符(含分隔符),CLI 路径走 JSON 聚合,不做分隔符切分
|
|
264
|
+
const agg = runCli(dbFile,
|
|
265
|
+
`SELECT coalesce(json_group_array(json_object('task_id', task_id, 'task_status', task_status, 'updated_at', updated_at, 'title', title)), '[]') FROM tasks WHERE task_id IN (${inList});`);
|
|
266
|
+
rows = JSON.parse(agg.stdout.trim() || '[]');
|
|
264
267
|
}
|
|
265
|
-
for (const r of rows) out[String(r.task_id)] = { status: String(r.task_status || ''), updatedAt: Number(r.updated_at) || 0 };
|
|
268
|
+
for (const r of rows) out[String(r.task_id)] = { status: String(r.task_status || ''), updatedAt: Number(r.updated_at) || 0, title: String(r.title || '') };
|
|
266
269
|
return out;
|
|
267
270
|
} catch {
|
|
268
271
|
return null;
|
|
@@ -535,7 +538,8 @@ export async function reconcileCustomTitles(dataRoot, writtenMap) {
|
|
|
535
538
|
};
|
|
536
539
|
|
|
537
540
|
for (const [sessId, rec] of Object.entries(writtenMap)) {
|
|
538
|
-
|
|
541
|
+
// 会话 id 有 sess_ 与 session_ 两种前缀(新版应用为 session_),两种都认
|
|
542
|
+
if (!/^(?:sess|session)_[A-Za-z0-9._-]+$/.test(sessId) || !rec || typeof rec.title !== 'string') continue;
|
|
539
543
|
let cli;
|
|
540
544
|
try { cli = await readCli(sessId); } catch { continue; }
|
|
541
545
|
// CLI 已不是我们所写的 custom 标题:别人改过(手动改名/官方),不碰
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
// zcode-pro wallpaper 子命令:壁纸引擎的命令行控制面(/wallpaper 命令与
|
|
2
|
+
// wallpaper 技能把模型引导到这里,经 Bash 调用)。校验与取值表(扩展名/大小/
|
|
3
|
+
// 数量/魔数/参数键与范围)复用 helper 的一份实现(bgMagicOk、mergeThemeConfig、
|
|
4
|
+
// BG_* 常量、BG_PARAM_KEYS);提示文案里的数字与清单只是说明文字,不是第二处校验。
|
|
5
|
+
// 写入 zcodepro.json 后约 5 秒内生效(运行中的界面轮询配置)。
|
|
6
|
+
import { copyFileSync, existsSync, mkdirSync, openSync, closeSync, readSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
7
|
+
import { basename, isAbsolute, join } from 'node:path';
|
|
8
|
+
import {
|
|
9
|
+
loadConfig, saveConfig, mergeThemeConfig, configFileUnreadable,
|
|
10
|
+
backgroundsDir, transcodeDir, listBgFiles, sanitizeBgName, bgMagicOk, cleanupBgTranscode,
|
|
11
|
+
BG_EXT, VIDEO_EXT, BG_MAX_BYTES, VIDEO_MAX_BYTES, BG_MAX_COUNT,
|
|
12
|
+
BG_MODES, BG_PARAM_KEYS, unlinkOrDefer, renameOrReplace, sweepDeferredBg,
|
|
13
|
+
} from './helper.mjs';
|
|
14
|
+
|
|
15
|
+
function usage() {
|
|
16
|
+
return `zcode-pro wallpaper — 壁纸引擎命令行控制
|
|
17
|
+
|
|
18
|
+
用法:
|
|
19
|
+
wallpaper list 查看当前配置与图库文件
|
|
20
|
+
wallpaper set none 关闭壁纸
|
|
21
|
+
wallpaper set library <图库文件名> 用图库里的某个文件
|
|
22
|
+
wallpaper set folder <目录绝对路径> 用文件夹(原地读取,配合 rotate 轮换)
|
|
23
|
+
wallpaper set url <http(s)地址> 图片网址
|
|
24
|
+
wallpaper set web <http(s)地址> 网页壁纸
|
|
25
|
+
wallpaper rotate <分钟> [--random|--sequential]
|
|
26
|
+
定时轮换(0 = 不轮换,顺序或随机)
|
|
27
|
+
wallpaper params <键=值>... 调画面/播放参数,可一次多项:
|
|
28
|
+
maskOpacity=0.8 遮罩不透明度 0-0.99 blurPx=0 画面模糊 0-24
|
|
29
|
+
panelOpacity=0.3 面板不透明度 0-1 fit=cover cover/contain/fill/tile
|
|
30
|
+
transition=fade cut/fade 换壁纸转场 fpsCap=0 视频帧率上限 0/15/30/60
|
|
31
|
+
videoVolume=0 视频音量 0-1 playbackRate=1 视频倍速 0.5-2
|
|
32
|
+
pauseOnHidden=true 窗口最小化暂停 pauseOnBlur=false 窗口失焦暂停
|
|
33
|
+
pauseOnBattery=false 电池供电暂停
|
|
34
|
+
wallpaper upload [--select] <文件路径>... 把本机图片/视频复制进图库(--select 顺手设为壁纸)
|
|
35
|
+
wallpaper delete <图库文件名> 从图库删除
|
|
36
|
+
`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function ensureWritableConfig(file) {
|
|
40
|
+
// 损坏判定与 helper 的 loadConfig/saveConfig 同一份(configFileUnreadable):
|
|
41
|
+
// 文件损坏时 loadConfig 只回默认值、saveConfig 会静默拒写,这里转成明确报错
|
|
42
|
+
loadConfig(file);
|
|
43
|
+
if (configFileUnreadable()) throw new Error('zcodepro.json 已损坏,拒绝写回以免清空配置;请先修复该文件');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function bgOf(cfg) {
|
|
47
|
+
if (!cfg.theme || typeof cfg.theme !== 'object') cfg.theme = {};
|
|
48
|
+
if (!cfg.theme.bg || typeof cfg.theme.bg !== 'object') cfg.theme.bg = {};
|
|
49
|
+
return cfg.theme.bg;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 类型检查挡明显打错(打错一个键不该把旋钮静默重置回默认),取值范围由
|
|
53
|
+
// mergeThemeConfig 统一校验(clamp + 默认值)
|
|
54
|
+
function applyParams(bg, pairs) {
|
|
55
|
+
for (const [k, v] of pairs) {
|
|
56
|
+
const kind = BG_PARAM_KEYS[k];
|
|
57
|
+
if (!kind) throw new Error(`未知参数 ${k},可用:${Object.keys(BG_PARAM_KEYS).join(', ')}`);
|
|
58
|
+
if (v === '') throw new Error(`${k} 需要值,收到空值`);
|
|
59
|
+
if (kind === 'number') {
|
|
60
|
+
if (!Number.isFinite(Number(v))) throw new Error(`${k} 需要数值,收到: ${v}`);
|
|
61
|
+
bg[k] = Number(v);
|
|
62
|
+
} else if (kind === 'boolean') {
|
|
63
|
+
if (v !== 'true' && v !== 'false') throw new Error(`${k} 需要 true/false,收到: ${v}`);
|
|
64
|
+
bg[k] = v === 'true';
|
|
65
|
+
} else {
|
|
66
|
+
// Set = 枚举成员集:fpsCap 成员是数字(先试原值再试数值),fit/transition 是字符串
|
|
67
|
+
const val = kind.has(v) ? v : Number(v);
|
|
68
|
+
if (!kind.has(val)) throw new Error(`${k} 只支持 ${[...kind].join('/')}`);
|
|
69
|
+
bg[k] = val;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function head16(file) {
|
|
75
|
+
const fd = openSync(file, 'r');
|
|
76
|
+
const head = Buffer.alloc(16);
|
|
77
|
+
try { readSync(fd, head, 0, 16, 0); } finally { closeSync(fd); }
|
|
78
|
+
return head;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export async function runWallpaperCli(argv, dataRoot) {
|
|
82
|
+
const configFile = join(dataRoot, 'zcodepro.json');
|
|
83
|
+
const op = argv[0];
|
|
84
|
+
try {
|
|
85
|
+
if (!op || op === '-h' || op === '--help') { console.log(usage()); return op ? 0 : 1; }
|
|
86
|
+
|
|
87
|
+
if (op === 'list') {
|
|
88
|
+
if (argv.length > 1) throw new Error('list 不接受参数');
|
|
89
|
+
const cfg = loadConfig(configFile);
|
|
90
|
+
console.log(JSON.stringify({ bg: bgOf(cfg), library: listBgFiles(dataRoot) }, null, 2));
|
|
91
|
+
return 0;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (op === 'set') {
|
|
95
|
+
const mode = argv[1];
|
|
96
|
+
if (!BG_MODES.has(mode)) throw new Error(`set 用法: wallpaper set none|library <文件>|folder <目录>|url <地址>|web <地址>(mode 收到: ${mode ?? '(空)'})`);
|
|
97
|
+
if (mode === 'none' ? argv.length > 2 : argv.length !== 3) throw new Error(`${mode} 模式用法: wallpaper set ${mode}${mode === 'none' ? '' : ' <值>'}`);
|
|
98
|
+
ensureWritableConfig(configFile);
|
|
99
|
+
const cfg = loadConfig(configFile);
|
|
100
|
+
const bg = bgOf(cfg);
|
|
101
|
+
bg.mode = mode;
|
|
102
|
+
if (mode === 'library') {
|
|
103
|
+
const file = sanitizeBgName(argv[2] || '');
|
|
104
|
+
if (!file) throw new Error('library 模式需要图库文件名(可用 wallpaper list 查看)');
|
|
105
|
+
if (!listBgFiles(dataRoot).some((f) => f.name === file)) throw new Error(`图库里没有 ${file}`);
|
|
106
|
+
bg.file = file;
|
|
107
|
+
} else if (mode === 'folder') {
|
|
108
|
+
const folder = String(argv[2] || '').trim();
|
|
109
|
+
if (!folder || !isAbsolute(folder) || !existsSync(folder) || !statSync(folder).isDirectory()) throw new Error('folder 需要已存在的目录绝对路径');
|
|
110
|
+
bg.folder = folder;
|
|
111
|
+
} else if (mode === 'url' || mode === 'web') {
|
|
112
|
+
const url = String(argv[2] || '').trim();
|
|
113
|
+
if (!/^https?:\/\/\S+$/i.test(url) || /[<>"'\\]/.test(url)) throw new Error(`${mode} 需以 http(s):// 开头且不含引号尖括号`);
|
|
114
|
+
bg.url = url;
|
|
115
|
+
}
|
|
116
|
+
cfg.theme = mergeThemeConfig({ ...cfg.theme, bg });
|
|
117
|
+
saveConfig(configFile, cfg);
|
|
118
|
+
console.log(`已切换:mode=${mode},约 5 秒后生效。当前配置:${JSON.stringify(cfg.theme.bg)}`);
|
|
119
|
+
return 0;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (op === 'rotate') {
|
|
123
|
+
const raw = argv[1];
|
|
124
|
+
const iv = Number(raw);
|
|
125
|
+
if (raw === undefined || raw === '' || !Number.isFinite(iv) || iv < 0) throw new Error('rotate 用法: wallpaper rotate <分钟> [--random|--sequential](0 = 不轮换,上限 1440,超出自动收敛)');
|
|
126
|
+
const flags = argv.slice(2);
|
|
127
|
+
const unknown = flags.filter((f) => f !== '--random' && f !== '--sequential');
|
|
128
|
+
if (unknown.length) throw new Error(`rotate 不认识 ${unknown.join(' ')},只支持 --random/--sequential`);
|
|
129
|
+
if (flags.includes('--random') && flags.includes('--sequential')) throw new Error('--random 与 --sequential 只能选一个');
|
|
130
|
+
ensureWritableConfig(configFile);
|
|
131
|
+
const cfg = loadConfig(configFile);
|
|
132
|
+
const bg = bgOf(cfg);
|
|
133
|
+
bg.intervalMin = Math.round(iv);
|
|
134
|
+
if (flags.includes('--random')) bg.folderRandom = true;
|
|
135
|
+
if (flags.includes('--sequential')) bg.folderRandom = false;
|
|
136
|
+
cfg.theme = mergeThemeConfig({ ...cfg.theme, bg });
|
|
137
|
+
saveConfig(configFile, cfg);
|
|
138
|
+
const out = cfg.theme.bg;
|
|
139
|
+
console.log(`轮换已设置:间隔 ${out.intervalMin} 分钟(${out.intervalMin === 0 ? '不轮换' : '生效中'}),顺序 ${out.folderRandom === false ? '按列表' : '随机'}`);
|
|
140
|
+
return 0;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (op === 'params') {
|
|
144
|
+
const pairs = argv.slice(1).map((s) => {
|
|
145
|
+
const i = s.indexOf('=');
|
|
146
|
+
if (i <= 0) throw new Error(`params 用法: wallpaper params <键=值>...(收到: ${s})`);
|
|
147
|
+
return [s.slice(0, i).trim(), s.slice(i + 1).trim()];
|
|
148
|
+
});
|
|
149
|
+
if (!pairs.length) throw new Error('params 至少要一个 键=值(可用键见 wallpaper -h)');
|
|
150
|
+
ensureWritableConfig(configFile);
|
|
151
|
+
const cfg = loadConfig(configFile);
|
|
152
|
+
const bg = bgOf(cfg);
|
|
153
|
+
applyParams(bg, pairs);
|
|
154
|
+
cfg.theme = mergeThemeConfig({ ...cfg.theme, bg });
|
|
155
|
+
saveConfig(configFile, cfg);
|
|
156
|
+
console.log(`参数已更新,约 5 秒后生效:${JSON.stringify(cfg.theme.bg)}`);
|
|
157
|
+
return 0;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (op === 'upload') {
|
|
161
|
+
const flags = argv.slice(1).filter((s) => s.startsWith('--'));
|
|
162
|
+
const paths = argv.slice(1).filter((s) => !s.startsWith('--'));
|
|
163
|
+
if (flags.some((f) => f !== '--select')) throw new Error(`upload 只支持 --select,收到: ${flags.join(' ')}`);
|
|
164
|
+
if (!paths.length) throw new Error('upload 用法: wallpaper upload [--select] <文件路径>...');
|
|
165
|
+
// --select 要写配置:在复制前先确认配置可写,免得文件入库了才报“拒绝写回”
|
|
166
|
+
if (flags.includes('--select')) ensureWritableConfig(configFile);
|
|
167
|
+
// 先全量校验再复制:中途报错不留半批文件在图库里
|
|
168
|
+
const plan = [];
|
|
169
|
+
const seen = new Set();
|
|
170
|
+
for (const src of paths) {
|
|
171
|
+
const name = sanitizeBgName(basename(src));
|
|
172
|
+
if (!name) throw new Error(`不支持的文件类型:${src}(图片 ${[...BG_EXT].map((e) => e.slice(1)).join('/')},视频 ${[...VIDEO_EXT].map((e) => e.slice(1)).join('/')})`);
|
|
173
|
+
if (seen.has(name)) throw new Error(`同批出现重复文件名 ${name},请改名或分批上传(避免后一个静默覆盖前一个)`);
|
|
174
|
+
seen.add(name);
|
|
175
|
+
if (!isAbsolute(src)) throw new Error(`需要绝对路径:${src}`);
|
|
176
|
+
if (!existsSync(src) || !statSync(src).isFile()) throw new Error(`文件不存在:${src}`);
|
|
177
|
+
const size = statSync(src).size;
|
|
178
|
+
const isVideo = VIDEO_EXT.has(name.slice(name.lastIndexOf('.')).toLowerCase());
|
|
179
|
+
if (size > (isVideo ? VIDEO_MAX_BYTES : BG_MAX_BYTES)) throw new Error(`${name} 超出大小限制(${isVideo ? `视频 ${VIDEO_MAX_BYTES / 1048576}MB` : `图片 ${BG_MAX_BYTES / 1048576}MB`})`);
|
|
180
|
+
if (!size || !bgMagicOk(name, head16(src))) throw new Error(`${name} 内容与扩展名不符(防止改名绕过检查)`);
|
|
181
|
+
plan.push({ src, name });
|
|
182
|
+
}
|
|
183
|
+
const dir = backgroundsDir(dataRoot);
|
|
184
|
+
mkdirSync(dir, { recursive: true });
|
|
185
|
+
const existing = new Set(listBgFiles(dataRoot).map((f) => f.name));
|
|
186
|
+
let added = 0;
|
|
187
|
+
for (const { name } of plan) { if (!existing.has(name)) added += 1; }
|
|
188
|
+
if (existing.size + added > BG_MAX_COUNT) throw new Error(`图库最多 ${BG_MAX_COUNT} 个文件,请先删除一些再上传`);
|
|
189
|
+
const done = [];
|
|
190
|
+
for (const { src, name } of plan) {
|
|
191
|
+
// 临时名+改名:复制中断不留半截文件,读方也不会看到混合字节
|
|
192
|
+
const tmp = join(dir, `${name}.${Date.now().toString(36)}.tmp`);
|
|
193
|
+
try {
|
|
194
|
+
copyFileSync(src, tmp);
|
|
195
|
+
renameOrReplace(tmp, join(dir, name));
|
|
196
|
+
} catch (e) {
|
|
197
|
+
unlinkOrDefer(tmp);
|
|
198
|
+
throw e;
|
|
199
|
+
}
|
|
200
|
+
done.push(name);
|
|
201
|
+
}
|
|
202
|
+
sweepDeferredBg(dir);
|
|
203
|
+
let selected = '';
|
|
204
|
+
if (flags.includes('--select') && done.length) {
|
|
205
|
+
const cfg = loadConfig(configFile);
|
|
206
|
+
if (configFileUnreadable()) throw new Error(`文件已入库(${done.join(', ')})但配置在上传期间变为不可读,未设为壁纸;修复配置后跑 wallpaper set library ${done[0]}`);
|
|
207
|
+
const bg = bgOf(cfg);
|
|
208
|
+
bg.mode = 'library';
|
|
209
|
+
bg.file = done[0];
|
|
210
|
+
cfg.theme = mergeThemeConfig({ ...cfg.theme, bg });
|
|
211
|
+
saveConfig(configFile, cfg);
|
|
212
|
+
selected = ',并已设为当前壁纸';
|
|
213
|
+
}
|
|
214
|
+
console.log(`已上传 ${done.length} 个文件${selected}:${done.join(', ')}`);
|
|
215
|
+
return 0;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (op === 'delete') {
|
|
219
|
+
if (argv.length !== 2) throw new Error('delete 用法: wallpaper delete <图库文件名>');
|
|
220
|
+
const name = sanitizeBgName(argv[1] || '');
|
|
221
|
+
if (!name) throw new Error('delete 用法: wallpaper delete <图库文件名>');
|
|
222
|
+
const dir = backgroundsDir(dataRoot);
|
|
223
|
+
const file = join(dir, name);
|
|
224
|
+
if (!existsSync(file)) throw new Error(`图库里没有 ${name}(可用 wallpaper list 查看)`);
|
|
225
|
+
cleanupBgTranscode(dataRoot, file);
|
|
226
|
+
unlinkOrDefer(file);
|
|
227
|
+
sweepDeferredBg(dir);
|
|
228
|
+
sweepDeferredBg(transcodeDir(dataRoot));
|
|
229
|
+
console.log(`已删除 ${name}(如正在使用,约 5 秒后自动停用)`);
|
|
230
|
+
return 0;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
console.error(`未知操作: ${op}\n`);
|
|
234
|
+
console.log(usage());
|
|
235
|
+
return 1;
|
|
236
|
+
} catch (err) {
|
|
237
|
+
console.error(`wallpaper ${op ?? ''} 失败: ${err?.message || err}`);
|
|
238
|
+
return 1;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// —— /wallpaper 命令与 wallpaper 技能:写到 ZCode 用户目录(每次启动覆盖,随
|
|
243
|
+
// zcode-pro 版本更新);setup --uninstall 移除 ————————————————————————
|
|
244
|
+
const COMMAND_MD = `---
|
|
245
|
+
description: 管理 zcode-pro 壁纸:换壁纸、开/关定时轮换、设文件夹或网页壁纸、调画面与播放参数、传删图库。示例:/wallpaper 换成海边那张
|
|
246
|
+
argument-hint: [壁纸需求]
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
按 wallpaper 技能(skills/wallpaper/SKILL.md)处理壁纸需求:$ARGUMENTS
|
|
250
|
+
|
|
251
|
+
用 Bash 执行 \`zcode-pro wallpaper ...\` 子命令完成操作(list / set / rotate / params / upload / delete,用法见技能)。改完报告改了哪些值。
|
|
252
|
+
`;
|
|
253
|
+
|
|
254
|
+
const SKILL_MD = `---
|
|
255
|
+
name: wallpaper
|
|
256
|
+
description: 控制 zcode-pro 的壁纸引擎:换壁纸、开/关定时轮换、设文件夹或网页壁纸、调画面(遮罩/模糊/缩放)与播放(音量/倍速/帧率/暂停)参数。当用户提到壁纸、换壁纸、背景图、轮换、视频壁纸、网页壁纸这类需求时使用。
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
# zcode-pro 壁纸控制
|
|
260
|
+
|
|
261
|
+
zcode-pro(ZCode 桌面版增强工具)内置壁纸引擎:图片、视频、网页铺在 ZCode 界面后方,带定时轮换、切换转场、暂停条件和画面调参。控制入口是 \`zcode-pro wallpaper\` 子命令,经 Bash 执行,写入后约 5 秒内自动生效。
|
|
262
|
+
|
|
263
|
+
## 子命令
|
|
264
|
+
|
|
265
|
+
| 命令 | 用途 |
|
|
266
|
+
|---|---|
|
|
267
|
+
| \`zcode-pro wallpaper list\` | 看当前配置和图库文件 |
|
|
268
|
+
| \`zcode-pro wallpaper set none\\|library <文件>\\|folder <目录>\\|url <地址>\\|web <地址>\` | 切换壁纸来源 |
|
|
269
|
+
| \`zcode-pro wallpaper rotate <分钟> [--random\\|--sequential]\` | 定时轮换(0 = 不轮换) |
|
|
270
|
+
| \`zcode-pro wallpaper params <键=值>...\` | 调画面(遮罩/模糊/面板/缩放)、转场、播放(音量/倍速/帧率)、暂停条件 |
|
|
271
|
+
| \`zcode-pro wallpaper upload [--select] <文件路径>...\` | 把本机图片/视频复制进图库(--select 顺手设为当前壁纸) |
|
|
272
|
+
| \`zcode-pro wallpaper delete <图库文件名>\` | 从图库删文件 |
|
|
273
|
+
|
|
274
|
+
\`zcode-pro wallpaper -h\` 查看 params 全部键与取值。上传限制:图片 ${BG_MAX_BYTES / 1048576}MB(${[...BG_EXT].map((e) => e.slice(1)).join('/')}),视频 ${VIDEO_MAX_BYTES / 1048576}MB(${[...VIDEO_EXT].map((e) => e.slice(1)).join('/')}),图库共 ${BG_MAX_COUNT} 个以内。
|
|
275
|
+
|
|
276
|
+
## 前置检查
|
|
277
|
+
|
|
278
|
+
- \`zcode-pro\` 不在 PATH 时,提示用户先跑一次 \`zcode-pro setup\`(或用绝对路径调用),然后停下。
|
|
279
|
+
- \`~/.zcode/zcodepro.json\`(Windows 即 \`%USERPROFILE%\\\\.zcode\\\\zcodepro.json\`)不存在时,说明这台机器没装 zcode-pro,告知用户先安装并用它启动 ZCode,然后停下。
|
|
280
|
+
|
|
281
|
+
## 配置字段(手动读改时参考;正常操作用上面的子命令)
|
|
282
|
+
|
|
283
|
+
配置 JSON 的 \`theme.bg\` 节(手动改时保留文件里其余所有内容):
|
|
284
|
+
|
|
285
|
+
| 字段 | 含义 | 取值 |
|
|
286
|
+
|---|---|---|
|
|
287
|
+
| mode | 壁纸来源 | none / library / folder / url / web |
|
|
288
|
+
| file | 图库模式的当前文件名 | 图库里的文件名 |
|
|
289
|
+
| folder | 文件夹模式的目录 | 绝对路径 |
|
|
290
|
+
| folderRandom | 轮换顺序 | true 随机 / false 按列表 |
|
|
291
|
+
| intervalMin | 轮换间隔(分钟) | 0-1440,0 = 不轮换 |
|
|
292
|
+
| url | url/web 模式的地址 | http(s):// 开头 |
|
|
293
|
+
| maskOpacity / blurPx / panelOpacity | 遮罩 0-0.99 / 模糊 0-24 / 面板 0-1 | 数值 |
|
|
294
|
+
| fit / transition / fpsCap | 缩放 cover/contain/fill/tile / 转场 cut/fade / 帧率 0/15/30/60 | 枚举 |
|
|
295
|
+
| videoVolume / playbackRate | 音量 0-1 / 倍速 0.5-2 | 数值 |
|
|
296
|
+
| pauseOnHidden / pauseOnBlur / pauseOnBattery | 最小化/失焦/电池暂停 | true/false |
|
|
297
|
+
`;
|
|
298
|
+
|
|
299
|
+
export function installWallpaperDocs(dataRoot) {
|
|
300
|
+
const cmdDir = join(dataRoot, 'commands');
|
|
301
|
+
mkdirSync(cmdDir, { recursive: true });
|
|
302
|
+
writeFileSync(join(cmdDir, 'wallpaper.md'), COMMAND_MD, 'utf8');
|
|
303
|
+
const skillDir = join(dataRoot, 'skills', 'wallpaper');
|
|
304
|
+
mkdirSync(skillDir, { recursive: true });
|
|
305
|
+
writeFileSync(join(skillDir, 'SKILL.md'), SKILL_MD, 'utf8');
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export function removeWallpaperDocs(dataRoot) {
|
|
309
|
+
try { rmSync(join(dataRoot, 'commands', 'wallpaper.md'), { force: true }); } catch { /* ignore */ }
|
|
310
|
+
try { rmSync(join(dataRoot, 'skills', 'wallpaper'), { recursive: true, force: true }); } catch { /* ignore */ }
|
|
311
|
+
}
|