@guanzhu.me/xbot-cli 0.7.1 → 0.7.3
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.md +3 -1
- package/bin/xbot-cli.cjs +120 -15
- package/native/win32-x64/xbot-cli.exe +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -56,7 +56,9 @@ xbot-cli install --skills --global --json
|
|
|
56
56
|
|
|
57
57
|
请使用支持 `.agents/skills` 的 Agent,或明确让 Agent 阅读生成的 `SKILL.md`。不支持自动加载 Skill 的工具也可以直接阅读下方指令。已有 Skill 内容不同时,CLI 会返回冲突;先查看差异,确认覆盖后再追加 `--yes`。
|
|
58
58
|
|
|
59
|
-
Skill
|
|
59
|
+
随包提供的 Skill v9 包含 14 个文件,覆盖探索、开发、验收和维护模式,并提供业务任务、定位资产与验收证据模板。网页流程优先使用经过验证的 XPath;元素失效修复同时考虑有效的新旧定位和共存歧义。元素库名称采用“平台名_业务含义_按钮/输入框/标志”,流程按配置、业务、测试及根级主流程组织,编码变量优先使用英文 `snake_case`。
|
|
60
|
+
|
|
61
|
+
风险分级、等待与状态确认、最小修复和回归要求属于 Agent 工作规范。当前浏览器接口仍共享活动页上下文,不提供独立多会话隔离;描述模板也不是自动执行器。新规范通过安装后的 `references/` 和 `templates/` 按需读取,`guide` 继续提供其已列出的内置主题。工作区的 `AGENTS.md` 和用户当前授权仍需遵守。
|
|
60
62
|
|
|
61
63
|
### 可复制的 Agent 指令
|
|
62
64
|
|
package/bin/xbot-cli.cjs
CHANGED
|
@@ -2,22 +2,127 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
const { spawnSync } = require('node:child_process');
|
|
5
|
-
const { join } = require('node:path');
|
|
5
|
+
const { dirname, join } = require('node:path');
|
|
6
|
+
const { tmpdir } = require('node:os');
|
|
7
|
+
const { mkdirSync, readFileSync, writeFileSync } = require('node:fs');
|
|
8
|
+
const pkg = require('../package.json');
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
const UPDATE_TTL_MS = 24 * 60 * 60 * 1000;
|
|
11
|
+
const UPDATE_FAILURE_TTL_MS = 60 * 60 * 1000;
|
|
12
|
+
const UPDATE_TIMEOUT_MS = 1000;
|
|
13
|
+
|
|
14
|
+
// 数字段比较,忽略预发布后缀;返回正数表示 a 比 b 新。
|
|
15
|
+
function compareVersions(a, b) {
|
|
16
|
+
const pick = (v) => String(v).split('-')[0].split('.').map((n) => parseInt(n, 10) || 0);
|
|
17
|
+
const pa = pick(a);
|
|
18
|
+
const pb = pick(b);
|
|
19
|
+
for (let i = 0; i < 3; i += 1) {
|
|
20
|
+
if (pa[i] !== pb[i]) return (pa[i] || 0) - (pb[i] || 0);
|
|
21
|
+
}
|
|
22
|
+
return 0;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function notifierEnabled() {
|
|
26
|
+
if (process.env.XBOT_NO_UPDATE_NOTIFIER) return false;
|
|
27
|
+
if (process.env.XBOT_UPDATE_NOTIFIER === '1') return true;
|
|
28
|
+
if (process.env.CI) return false;
|
|
29
|
+
return Boolean(process.stderr.isTTY);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function cacheFile() {
|
|
33
|
+
const dir = process.env.XBOT_UPDATE_CACHE_DIR
|
|
34
|
+
|| join(process.env.LOCALAPPDATA || tmpdir(), 'xbot-cli');
|
|
35
|
+
return join(dir, 'update-check.json');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function readCache() {
|
|
39
|
+
try {
|
|
40
|
+
return JSON.parse(readFileSync(cacheFile(), 'utf8'));
|
|
41
|
+
} catch {
|
|
42
|
+
return {};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function writeCache(cache) {
|
|
47
|
+
try {
|
|
48
|
+
mkdirSync(dirname(cacheFile()), { recursive: true });
|
|
49
|
+
writeFileSync(cacheFile(), JSON.stringify(cache));
|
|
50
|
+
} catch {
|
|
51
|
+
// 缓存写失败不影响 CLI 本身。
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function fetchLatest() {
|
|
56
|
+
const base = (process.env.XBOT_UPDATE_REGISTRY || 'https://registry.npmjs.org').replace(/\/+$/, '');
|
|
57
|
+
const name = pkg.name.startsWith('@') ? `@${pkg.name.slice(1).replace('/', '%2F')}` : pkg.name;
|
|
58
|
+
const response = await fetch(`${base}/${name}/latest`, {
|
|
59
|
+
signal: AbortSignal.timeout(UPDATE_TIMEOUT_MS),
|
|
60
|
+
});
|
|
61
|
+
if (!response.ok) throw new Error(`registry ${response.status}`);
|
|
62
|
+
const body = await response.json();
|
|
63
|
+
if (!body || typeof body.version !== 'string') throw new Error('registry bad payload');
|
|
64
|
+
return body.version;
|
|
10
65
|
}
|
|
11
66
|
|
|
12
|
-
//
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
|
|
67
|
+
// 命中缓存就直接用;过期则联网刷新,失败退避 1 小时,任何失败都不抛错。
|
|
68
|
+
async function resolveLatest(cache, now) {
|
|
69
|
+
if (cache.expiresAt && cache.expiresAt > now && cache.latest) return cache.latest;
|
|
70
|
+
try {
|
|
71
|
+
cache.latest = await fetchLatest();
|
|
72
|
+
cache.expiresAt = now + UPDATE_TTL_MS;
|
|
73
|
+
} catch {
|
|
74
|
+
if (!cache.latest) cache.expiresAt = now + UPDATE_FAILURE_TTL_MS;
|
|
75
|
+
}
|
|
76
|
+
writeCache(cache);
|
|
77
|
+
return cache.latest;
|
|
22
78
|
}
|
|
23
|
-
|
|
79
|
+
|
|
80
|
+
function formatNotice(latest) {
|
|
81
|
+
const text = `新版本 xbot-cli ${latest} 可用(当前 ${pkg.version})。运行 npm i -g ${pkg.name} 更新。`;
|
|
82
|
+
if (process.stderr.isTTY) return `\u001b[33m${text}\u001b[0m\n`;
|
|
83
|
+
return `${text}\n`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// 返回要写到 stderr 的提醒文本;不需要提醒时返回空串。
|
|
87
|
+
async function updateNotice() {
|
|
88
|
+
if (!notifierEnabled()) return '';
|
|
89
|
+
const now = Date.now();
|
|
90
|
+
const cache = readCache();
|
|
91
|
+
const latest = await resolveLatest(cache, now);
|
|
92
|
+
if (!latest || compareVersions(latest, pkg.version) <= 0) return '';
|
|
93
|
+
if (cache.notifiedFor === latest) return '';
|
|
94
|
+
cache.notifiedFor = latest;
|
|
95
|
+
writeCache(cache);
|
|
96
|
+
return formatNotice(latest);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async function main() {
|
|
100
|
+
if (process.platform !== 'win32' || process.arch !== 'x64') {
|
|
101
|
+
process.stderr.write('xbot-cli currently supports Windows x64 with ShadowBot installed.\n');
|
|
102
|
+
process.exit(1);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// 与原生进程并行发起,最多拖慢退出约 1 秒,失败静默。
|
|
106
|
+
const noticePromise = updateNotice().catch(() => '');
|
|
107
|
+
|
|
108
|
+
// Preserve stdin, terminal detection, output streams, cwd and argument boundaries.
|
|
109
|
+
const executable = join(__dirname, '..', 'native', 'win32-x64', 'xbot-cli.exe');
|
|
110
|
+
const result = spawnSync(executable, process.argv.slice(2), {
|
|
111
|
+
stdio: 'inherit',
|
|
112
|
+
shell: false,
|
|
113
|
+
windowsHide: true,
|
|
114
|
+
});
|
|
115
|
+
if (result.error) {
|
|
116
|
+
process.stderr.write(`Unable to start xbot-cli (${result.error.code}). Reinstall the npm package.\n`);
|
|
117
|
+
process.exit(1);
|
|
118
|
+
}
|
|
119
|
+
const notice = await noticePromise;
|
|
120
|
+
if (notice) process.stderr.write(notice);
|
|
121
|
+
process.exit(result.status ?? (result.signal === 'SIGINT' ? 130 : 1));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (require.main === module) {
|
|
125
|
+
main();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
module.exports = { compareVersions, notifierEnabled, updateNotice, formatNotice };
|
|
Binary file
|