@guanzhu.me/xbot-cli 0.8.1 → 0.8.2

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 CHANGED
@@ -18,7 +18,7 @@ xbot-cli 通过影刀客户端内置通道管理应用、编辑流程、运行
18
18
  - **Agent 优先的输出契约。** 裸调用逐层返回帮助,`schema <path>` 给出机器可读的参数定义;成功写 stdout、失败写 stderr,配合明确的退出码与 `ok/data/error` JSON 信封。
19
19
  - **应用与流程全生命周期。** `app` 创建、打开、保存、同步、发布;`flow` 读取、静态检查、运行与等待;`task` 运行已发布应用。
20
20
  - **安全的写入边界。** `--dry-run` 离线预览,`--expect-app` 断言当前应用,高风险操作必须显式 `--yes`。
21
- - **浏览器自动化。** `xbot web` 提供“打开页面 → 快照 → 操作元素”的短命令循环,无需手写 JSON。
21
+ - **浏览器自动化。** `xbot-cli web` 提供“打开页面 → 快照 → 操作元素”的短命令循环,无需手写 JSON。
22
22
  - **开放平台 Open API。** `oapi` 一条命令保存 AccessKey,token 自动刷新;应用、机器人、调度、日志、队列、企业账号全覆盖。
23
23
  - **内置 Agent Skill。** `xbot-cli install --skills` 安装开发规范、Web/Windows 修复辅助和排障指南。
24
24
 
@@ -28,10 +28,10 @@ xbot-cli 通过影刀客户端内置通道管理应用、编辑流程、运行
28
28
 
29
29
  ```powershell
30
30
  npm install -g '@guanzhu.me/xbot-cli'
31
- xbot version
31
+ xbot-cli version
32
32
  ```
33
33
 
34
- 安装后 `xbot` 与 `xbot-cli` 调用同一程序。升级直接运行:
34
+ 安装后通过 `xbot-cli` 调用(0.8.2 起仅保留此入口;安装时会自动清理旧版遗留的 `xbot` shim 和 PATH 中的旧程序)。升级直接运行:
35
35
 
36
36
  ```powershell
37
37
  xbot-cli update # 升级到最新版本;--check 只检查不升级
@@ -51,9 +51,9 @@ xbot-cli task run <app-id> --json # 运行已发布应用
51
51
  浏览器交互:
52
52
 
53
53
  ```powershell
54
- xbot web open baidu.com
55
- xbot web fill e4 "影刀 RPA"
56
- xbot web click e7
54
+ xbot-cli web open baidu.com
55
+ xbot-cli web fill e4 "影刀 RPA"
56
+ xbot-cli web click e7
57
57
  ```
58
58
 
59
59
  裸调用 `xbot-cli` 或任意分组(如 `xbot-cli flow`)会返回该层级的帮助和示例;`xbot-cli help <path>` 查看详细帮助。
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guanzhu.me/xbot-cli",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "description": "Agent-friendly CLI for ShadowBot RPA applications, flows, tasks and browser automation",
5
5
  "license": "MIT",
6
6
  "author": "wn0x00",
@@ -21,12 +21,12 @@
21
21
  "automation"
22
22
  ],
23
23
  "bin": {
24
- "xbot": "bin/xbot-cli.cjs",
25
24
  "xbot-cli": "bin/xbot-cli.cjs"
26
25
  },
27
26
  "files": [
28
27
  "bin/xbot-cli.cjs",
29
- "native/win32-x64/xbot-cli.exe"
28
+ "native/win32-x64/xbot-cli.exe",
29
+ "scripts/preinstall.cjs"
30
30
  ],
31
31
  "os": [
32
32
  "win32"
@@ -40,6 +40,7 @@
40
40
  "scripts": {
41
41
  "build": "node scripts/build.cjs",
42
42
  "check": "cargo fmt --check && cargo clippy --locked --all-targets -- -D warnings",
43
+ "preinstall": "node scripts/preinstall.cjs",
43
44
  "pretest": "npm run build",
44
45
  "test": "cargo test --locked && npm run test:npm && npm run test:skill",
45
46
  "test:npm": "node --test tests/npm/*.test.cjs",
@@ -0,0 +1,99 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ // 安装前清理环境,保证 xbot-cli 命令指向本次安装:
5
+ // 1. 移除本包历史版本遗留的 xbot shim(0.8.2 起仅保留 xbot-cli 入口);
6
+ // 2. PATH 中位于 npm 目录之外的同名 xbot-cli 程序(手工放置的旧版)会截获命令,
7
+ // 移为 .bak 而不是删除,可由用户自行恢复或清理。
8
+ // 任何失败都不阻断安装;XBOT_CLI_SKIP_CLEANUP=1 完全跳过。
9
+ // XBOT_CLEANUP_NPM_BIN / XBOT_CLEANUP_PATH 是测试注入点,正常环境不设置。
10
+
11
+ const fs = require('node:fs');
12
+ const path = require('node:path');
13
+
14
+ function log(message) {
15
+ console.log(`[xbot-cli cleanup] ${message}`);
16
+ }
17
+
18
+ function binDir() {
19
+ return process.env.XBOT_CLEANUP_NPM_BIN || process.env.npm_config_prefix || null;
20
+ }
21
+
22
+ function referencesPackage(file) {
23
+ try {
24
+ return fs.readFileSync(file, 'utf8').includes('xbot-cli');
25
+ } catch {
26
+ return false;
27
+ }
28
+ }
29
+
30
+ function removeLegacyShims(dir) {
31
+ let removed = 0;
32
+ for (const name of ['xbot', 'xbot.cmd', 'xbot.ps1']) {
33
+ const file = path.join(dir, name);
34
+ // 只处理指向本包的 shim;不相干的同名文件保持原样。
35
+ if (!fs.existsSync(file) || !referencesPackage(file)) continue;
36
+ try {
37
+ fs.rmSync(file, { force: true });
38
+ removed += 1;
39
+ log(`removed legacy shim ${file}`);
40
+ } catch (error) {
41
+ log(`cannot remove ${file}: ${error.message}`);
42
+ }
43
+ }
44
+ return removed;
45
+ }
46
+
47
+ function quarantine(file) {
48
+ let target = `${file}.bak`;
49
+ if (fs.existsSync(target)) target = `${file}.bak-${Date.now()}`;
50
+ fs.renameSync(file, target);
51
+ log(`moved conflicting program ${file} -> ${target}`);
52
+ }
53
+
54
+ function quarantineForeign(dirs, ownDir) {
55
+ let moved = 0;
56
+ const own = ownDir && fs.realpathSync.native(ownDir);
57
+ for (const dir of dirs) {
58
+ if (!dir || !fs.existsSync(dir)) continue;
59
+ let real;
60
+ try {
61
+ real = fs.realpathSync.native(dir);
62
+ } catch {
63
+ continue;
64
+ }
65
+ if (own && real === own) continue;
66
+ for (const name of ['xbot-cli.exe', 'xbot-cli.cmd', 'xbot-cli.ps1', 'xbot-cli']) {
67
+ const file = path.join(dir, name);
68
+ if (!fs.existsSync(file)) continue;
69
+ // 脚本类 shim 要求内容指向本包;.exe 按文件名即视为旧版原生程序。
70
+ if (!name.endsWith('.exe') && !referencesPackage(file)) continue;
71
+ try {
72
+ quarantine(file);
73
+ moved += 1;
74
+ } catch (error) {
75
+ log(`cannot move ${file}: ${error.message}`);
76
+ }
77
+ }
78
+ }
79
+ return moved;
80
+ }
81
+
82
+ function main() {
83
+ if (process.env.XBOT_CLI_SKIP_CLEANUP === '1') return;
84
+ if (process.platform !== 'win32') return;
85
+ const dir = binDir();
86
+ if (!dir) return;
87
+ const dirs = (process.env.XBOT_CLEANUP_PATH || process.env.PATH || '').split(path.delimiter);
88
+ const moved = quarantineForeign(dirs, dir);
89
+ const removed = removeLegacyShims(dir);
90
+ if (moved + removed > 0) {
91
+ log(`done: ${moved} conflicting program(s) quarantined, ${removed} legacy shim(s) removed`);
92
+ }
93
+ }
94
+
95
+ try {
96
+ main();
97
+ } catch (error) {
98
+ log(`skipped after error: ${error.message}`);
99
+ }