shellx-cli 0.0.22 → 0.0.23

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/bundle/shellx.js CHANGED
@@ -233003,7 +233003,7 @@ async function createContentGenerator(config, gcConfig, sessionId2) {
233003
233003
  if (gcConfig.fakeResponses) {
233004
233004
  return FakeContentGenerator.fromFile(gcConfig.fakeResponses);
233005
233005
  }
233006
- const version3 = "0.0.22";
233006
+ const version3 = "0.0.23";
233007
233007
  const userAgent = `GeminiCLI/${version3} (${process.platform}; ${process.arch})`;
233008
233008
  const baseHeaders = {
233009
233009
  "User-Agent": userAgent
@@ -302330,7 +302330,7 @@ async function getClientMetadata() {
302330
302330
  if (!clientMetadataPromise) {
302331
302331
  clientMetadataPromise = (async () => ({
302332
302332
  ideName: "GEMINI_CLI",
302333
- ideVersion: "0.0.22",
302333
+ ideVersion: "0.0.23",
302334
302334
  platform: getPlatform(),
302335
302335
  updateChannel: await getReleaseChannel(__dirname3)
302336
302336
  }))();
@@ -429061,7 +429061,7 @@ var __filename3 = fileURLToPath10(import.meta.url);
429061
429061
  var __dirname7 = path59.dirname(__filename3);
429062
429062
  async function getCliVersion() {
429063
429063
  const pkgJson = await getPackageJson(__dirname7);
429064
- return "0.0.22";
429064
+ return "0.0.23";
429065
429065
  }
429066
429066
 
429067
429067
  // packages/cli/src/ui/commands/aboutCommand.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shellx-cli",
3
- "version": "0.0.22",
3
+ "version": "0.0.23",
4
4
  "engines": {
5
5
  "node": ">=20.0.0"
6
6
  },
@@ -75,6 +75,7 @@
75
75
  },
76
76
  "files": [
77
77
  "bundle/",
78
+ "scripts/install-shellx-files.js",
78
79
  "README.md",
79
80
  "LICENSE"
80
81
  ],
@@ -0,0 +1,222 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * install-shellx-files.js
4
+ *
5
+ * @功能简介(ENGLISH below):
6
+ * -------------------------------------------
7
+ * 本脚本用于在安装 shellx-cli 时,根据当前操作系统 (platform) 和架构 (arch),
8
+ * 自动从 npm registry 安装对应的 shellx-files 二进制文件包(比如模拟器或者驱动所需的二进制文件)。
9
+ * 另外,如果不是 Android 沙箱环境,还会自动保证 shellx-platform-tools 工具包的可用性。
10
+ * 最后,会安装必需的 eval 包,这个包是必须的,不像平台特定包那样可选。
11
+ *
12
+ * 用于提升 shellx-cli 的自动安装体验和平台兼容性。
13
+ * 失败不会导致整体安装中断,仅会打印告警信息。
14
+ * 支持通过环境变量指定包版本,如 SHELLX_SHELLX_FILES_WIN32_X64_VERSION=1.0.0 或 SHELLX_EVAL_VERSION=1.0.0
15
+ * -------------------------------------------
16
+ *
17
+ * @Function Overview (ENGLISH):
18
+ * -------------------------------------------
19
+ * This script auto-installs platform-specific shellx-files binaries from npm registry during shellx-cli installation.
20
+ * If not running for 'android' sandbox, it ensures shellx-platform-tools package is also available.
21
+ * Finally, it installs the required 'eval' package, which is mandatory unlike the optional platform-specific packages.
22
+ * Any install failure is non-fatal and only triggers a warning, not breaking the main install process.
23
+ * Version can be specified via environment variables like SHELLX_SHELLX_FILES_WIN32_X64_VERSION=1.0.0 or SHELLX_EVAL_VERSION=1.0.0
24
+ * -------------------------------------------
25
+ *
26
+ * 详细流程说明:
27
+ * 1. 检测当前 OS 与 架构,选出可能的 shellx-files 包名候选。
28
+ * 2. 如果有多个候选包,显示交互式选择菜单让用户选择;如果只有一个则自动选择。
29
+ * 3. 检查环境变量中是否有指定版本(格式:SHELLX_{包名大写并下划线替换横线}_VERSION),默认使用 latest。
30
+ * 4. 直接从 npm registry 安装选中的包。
31
+ * 5. 如果未能安装到任何 shellx-files 包,会给出强烈提示,但不会报错退出。
32
+ * 6. 如果当前不是 SANDBOX=android 环境,从 registry 安装 shellx-platform-tools 工具包。
33
+ * 7. 安装必需的 eval 包,直接从 registry 安装,支持版本指定。
34
+ * 8. 打印最后的完成提示。
35
+ *
36
+ * 适用环境: 仅限 node >= v14, shellx-cli 根目录(通过 npm scripts/preinstall 或直接运行)。
37
+ * 可安全多次运行,支持开发与 CI 场景。
38
+ */
39
+
40
+ import { execSync } from 'node:child_process';
41
+ import readline from 'node:readline';
42
+
43
+ /**
44
+ * 封装执行 shell 命令工具,显示日志,出错返回 false 不 throw
45
+ * @param {string} cmd
46
+ * @returns {boolean} 是否执行成功
47
+ */
48
+ function run(cmd) {
49
+ try {
50
+ execSync(cmd, { stdio: 'inherit' });
51
+ return true;
52
+ } catch (e) {
53
+ console.warn(`Command failed: ${cmd}`);
54
+ return false;
55
+ }
56
+ }
57
+
58
+ /**
59
+ * 交互式选择函数,让用户从候选列表中选择要安装的包和版本
60
+ * @param {string[]} candidates 候选包名数组
61
+ * @returns {Promise<{package: string, version: string}|null>} 用户选择的包信息,包含包名和版本,如果取消则返回 null
62
+ */
63
+ function selectPackage(candidates) {
64
+ return new Promise((resolve) => {
65
+ if (candidates.length === 0) {
66
+ resolve(null);
67
+ return;
68
+ }
69
+
70
+ if (candidates.length === 1) {
71
+ // 只有一个选项,直接返回,默认使用最新版本
72
+ const selectedPkg = candidates[0];
73
+ const version = process.env[`SHELLX_${selectedPkg.toUpperCase().replace(/-/g, '_')}_VERSION`] || 'latest';
74
+ console.log(`[shellx-files] Only one candidate available: ${selectedPkg}@${version}`);
75
+ resolve({ package: selectedPkg, version });
76
+ return;
77
+ }
78
+
79
+ const rl = readline.createInterface({
80
+ input: process.stdin,
81
+ output: process.stdout
82
+ });
83
+
84
+ console.log('\n[shellx-files] Multiple platform candidates available:');
85
+ candidates.forEach((pkg, index) => {
86
+ const envVersion = process.env[`SHELLX_${pkg.toUpperCase().replace(/-/g, '_')}_VERSION`];
87
+ const versionHint = envVersion ? `@${envVersion}` : '@latest';
88
+ console.log(` ${index + 1}. ${pkg}${versionHint}`);
89
+ });
90
+ console.log(' 0. Skip installation');
91
+
92
+ rl.question('\nSelect a package to install (number) or press Enter to auto-select first available: ', (answer) => {
93
+ rl.close();
94
+
95
+ const choice = parseInt(answer.trim(), 10);
96
+
97
+ if (isNaN(choice) || choice === '' || choice === undefined) {
98
+ // 按Enter键或无效输入,使用第一个可用的
99
+ const selectedPkg = candidates[0];
100
+ const version = process.env[`SHELLX_${selectedPkg.toUpperCase().replace(/-/g, '_')}_VERSION`] || 'latest';
101
+ console.log(`[shellx-files] Auto-selecting first available package: ${selectedPkg}@${version}`);
102
+ resolve({ package: selectedPkg, version });
103
+ } else if (choice === 0) {
104
+ // 跳过安装
105
+ console.log('[shellx-files] Skipping shellx-files installation.');
106
+ resolve(null);
107
+ } else if (choice >= 1 && choice <= candidates.length) {
108
+ // 选择指定包
109
+ const selectedPkg = candidates[choice - 1];
110
+ const version = process.env[`SHELLX_${selectedPkg.toUpperCase().replace(/-/g, '_')}_VERSION`] || 'latest';
111
+ console.log(`[shellx-files] Selected: ${selectedPkg}@${version}`);
112
+ resolve({ package: selectedPkg, version });
113
+ } else {
114
+ // 无效选择,使用第一个可用的
115
+ const selectedPkg = candidates[0];
116
+ const version = process.env[`SHELLX_${selectedPkg.toUpperCase().replace(/-/g, '_')}_VERSION`] || 'latest';
117
+ console.log(`[shellx-files] Invalid choice, auto-selecting first available package: ${selectedPkg}@${version}`);
118
+ resolve({ package: selectedPkg, version });
119
+ }
120
+ });
121
+ });
122
+ }
123
+
124
+ // platform 值: 'darwin' | 'linux' | 'win32',但 Node.js process.platform 实际上不包含 'android'
125
+ // 如果在 Android Termux、Node.js 环境,这里会取到 'linux'
126
+ const platform = process.platform;
127
+ // arch 值: 'x64' | 'arm64' | 其他,在 Android 设备常为 'arm64'
128
+ const arch = process.arch;
129
+
130
+ /**
131
+ * 不同平台和架构对应的 shellx-files 包候选矩阵,优先级从前到后。
132
+ * 可根据实际支持覆盖扩展。
133
+ */
134
+ const candidateMap = {
135
+ darwin: {
136
+ arm64: ['shellx-files-arm64'],
137
+ x64: ['shellx-files-arm64'],
138
+ },
139
+ linux: {
140
+ arm64: ['shellx-files-arm64'],
141
+ x64: ['shellx-files-linux-x64', 'shellx-files-arm64'],
142
+ },
143
+ win32: {
144
+ arm64: ['shellx-files-win32-arm64', 'shellx-files-arm64'],
145
+ x64: ['shellx-files-win32-x64'],
146
+ },
147
+ };
148
+
149
+ /**
150
+ * 决定候选架构 key(只区分最主流的两种;特殊架构可自行补充)
151
+ */
152
+ const archKey = arch === 'x64' ? 'x64' : arch === 'arm64' ? 'arm64' : arch;
153
+
154
+ // 主函数包装,使脚本支持 async/await
155
+ async function main() {
156
+ // 检测当前 OS 与 架构,选出可能的 shellx-files 包名候选。
157
+ const archKey = arch === 'x64' ? 'x64' : arch === 'arm64' ? 'arm64' : arch;
158
+ const platformCandidates = ['shellx-files-arm64'];
159
+ // (candidateMap[platform] && candidateMap[platform][archKey]) || ['shellx-files-arm64'];
160
+
161
+ /**
162
+ * 安装过程核心:
163
+ * 让用户选择要安装的包和版本,然后尝试安装选中的包。
164
+ */
165
+ let installed = false;
166
+ const selectedPkgInfo = await selectPackage(platformCandidates);
167
+ if (selectedPkgInfo) {
168
+ const { package: selectedPkg, version } = selectedPkgInfo;
169
+ // 直接从 registry 安装,非致命
170
+ const installCmd = version === 'latest'
171
+ ? `npm install --no-audit --no-fund ${selectedPkg}`
172
+ : `npm install --no-audit --no-fund ${selectedPkg}@${version}`;
173
+ console.log(`[shellx-files] Attempting to install registry package ${selectedPkg}@${version}`);
174
+ installed = run(installCmd);
175
+ }
176
+
177
+ /**
178
+ * 如果所有候选都没装上,告警但不 throw
179
+ */
180
+ if (!installed && selectedPkgInfo) {
181
+ const { package: selectedPkg, version } = selectedPkgInfo;
182
+ console.warn(
183
+ `[shellx-files] Failed to install selected package ${selectedPkg}@${version} for ${platform}-${arch}.` +
184
+ ' If you need platform binaries, please publish the appropriate package or add it to the workspace.'
185
+ );
186
+ }
187
+
188
+ /**
189
+ * 检查 shellx-platform-tools 工具包,如果不是 Android 沙箱都要自动装好,直接从 registry 安装。
190
+ */
191
+ const sandbox = process.env['SANDBOX'];
192
+ if (sandbox !== 'android') {
193
+ // 直接从 registry 安装,不存在也不会中断
194
+ console.log('[shellx-files] Attempting to install shellx-platform-tools from registry (if available)');
195
+ run('npm install --no-audit --no-fund shellx-platform-tools || true');
196
+ }
197
+
198
+ /**
199
+ * 安装必须的 eval 包,直接从 registry 安装。
200
+ * 这个包是必需的,不像平台特定包那样可选。
201
+ */
202
+ const evalPkg = 'eval';
203
+ const evalVersion = process.env['SHELLX_EVAL_VERSION'] || 'latest';
204
+ // 直接从 registry 安装
205
+ const evalInstallCmd = evalVersion === 'latest'
206
+ ? `npm install --no-audit --no-fund ${evalPkg}`
207
+ : `npm install --no-audit --no-fund ${evalPkg}@${evalVersion}`;
208
+ console.log(`[shellx-files] Attempting to install eval package from registry (${evalVersion})`);
209
+ const evalInstalled = run(evalInstallCmd);
210
+ if (!evalInstalled) {
211
+ console.warn(`[shellx-files] Failed to install required eval package. This may affect functionality.`);
212
+ }
213
+
214
+ console.log('[shellx-files] install-shellx-files finished (non-fatal failures are allowed).');
215
+ }
216
+
217
+ // 运行主函数
218
+ main().catch((error) => {
219
+ console.error('[shellx-files] Unexpected error:', error);
220
+ process.exit(1);
221
+ });
222
+