@acefelix/jarvis 2.6.2 → 2.6.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.
Files changed (2) hide show
  1. package/install.js +53 -3
  2. package/package.json +3 -2
package/install.js CHANGED
@@ -10,6 +10,7 @@
10
10
  * - 安装成功后根据所选功能提示对应的系统级依赖
11
11
  *
12
12
  * @author aceFelix
13
+ * @updated 2026-11-27 # uv 安装显式绑定已校验的解释器,避免 PATH 中的坏 Python shim 抢先
13
14
  */
14
15
 
15
16
  "use strict";
@@ -167,6 +168,45 @@ function findUv() {
167
168
  }
168
169
  }
169
170
 
171
+ /**
172
+ * 把已通过版本检查的 Python 命令解析成绝对解释器路径。
173
+ *
174
+ * uv 默认会重新扫描 PATH 并选择“第一个 Python”,它可能选中坏的 Chocolatey shim
175
+ * (例如 python3.14.exe 指向不存在的 C:\python314\python.exe),而不是前面
176
+ * findPython() 已经验证过的 python。因此 uv 安装必须显式绑定这个解释器。
177
+ *
178
+ * @param {string} pythonCmd 已验证可用的 Python 命令(python / python3 / py)
179
+ * @param {Function} run 可注入的命令执行器,供单测使用
180
+ * @returns {string} sys.executable 的绝对路径;查询失败时退回原命令
181
+ * @author aceFelix
182
+ * @since 2026-11-27
183
+ */
184
+ function resolvePythonExecutable(pythonCmd, run = execSync) {
185
+ try {
186
+ const out = run(`${pythonCmd} -c "import sys; print(sys.executable)"`, {
187
+ encoding: "utf8",
188
+ timeout: 10000,
189
+ stdio: ["pipe", "pipe", "pipe"],
190
+ });
191
+ const resolved = String(out || "").trim();
192
+ return resolved || pythonCmd;
193
+ } catch {
194
+ return pythonCmd;
195
+ }
196
+ }
197
+
198
+ /**
199
+ * 构造 uv 安装前缀:显式指定解释器,避免 uv 自己重新扫描 PATH。
200
+ *
201
+ * @param {string} pythonPath findPython() 校验通过的解释器绝对路径
202
+ * @returns {string} 可直接与 pip 目标拼接的 uv pip install 前缀
203
+ * @author aceFelix
204
+ * @since 2026-11-27
205
+ */
206
+ function buildUvInstallPrefix(pythonPath) {
207
+ return `uv pip install --python "${pythonPath}"`;
208
+ }
209
+
170
210
  // ─── 交互式选装菜单 ─────────────────────────────────────────────────────────────
171
211
  // 返回选中的 extras 数组;特殊值 "all" 表示安装 [all];空数组表示仅装核心。
172
212
  // 非 TTY 环境(CI / 管道)跳过交互,直接返回 ["all"]。
@@ -303,8 +343,10 @@ async function main() {
303
343
  let installPrefix;
304
344
  const hasUv = findUv();
305
345
  if (hasUv) {
306
- console.log("[jarvis] ✓ 检测到 uv,使用 uv 加速安装(快 5-10x)");
307
- installPrefix = "uv pip install";
346
+ const pythonPath = resolvePythonExecutable(python.cmd);
347
+ console.log(`[jarvis] ✓ 检测到 uv,使用 uv 加速安装(快 5-10x)`);
348
+ console.log(`[jarvis] ✓ 绑定 Python 解释器: ${pythonPath}`);
349
+ installPrefix = buildUvInstallPrefix(pythonPath);
308
350
  } else {
309
351
  const pip = findPip(python.cmd);
310
352
  if (!pip) {
@@ -345,4 +387,12 @@ async function main() {
345
387
  console.log(`\n[jarvis] 运行 "jarvis" 启动贾维斯。\n`);
346
388
  }
347
389
 
348
- main();
390
+ if (require.main === module) {
391
+ main();
392
+ }
393
+
394
+ module.exports = {
395
+ findPython,
396
+ resolvePythonExecutable,
397
+ buildUvInstallPrefix,
398
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acefelix/jarvis",
3
- "version": "2.6.2",
3
+ "version": "2.6.3",
4
4
  "description": "J.A.R.V.I.S — 你的钢铁侠同款桌面 AI 助手。可对话、可操作电脑、可后台常驻、能听会说,内置 70+ 工具(MCP 生态接入后可扩展至 100+)、多模型动态切换。",
5
5
  "keywords": [
6
6
  "ai-agent",
@@ -24,7 +24,8 @@
24
24
  "jarvis": "run.js"
25
25
  },
26
26
  "scripts": {
27
- "postinstall": "node install.js"
27
+ "postinstall": "node install.js",
28
+ "test": "node --test install.test.js"
28
29
  },
29
30
  "files": [
30
31
  "install.js",