ai-otel-setup 1.0.7 → 1.0.9

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/cli.js +29 -6
  2. package/package.json +1 -1
package/cli.js CHANGED
@@ -28,15 +28,38 @@ const { execFileSync } = require("child_process");
28
28
 
29
29
  const PKG_VERSION = require("./package.json").version;
30
30
 
31
- // 安装时这台机器的 node 绝对路径,给 hook 命令做兜底(见 buildHookCommand)。
31
+ // 安装时这台机器的 node 绝对路径,POSIX 上拿来构造 hook command 用。
32
+ // Windows 上不再写 node 绝对路径(见 buildHookCommand 注释)。
32
33
  const NODE_BIN = process.execPath;
33
34
 
34
- // 跨平台 hook 命令:固定形式 `<NODE_BIN> <launcher> <hook>`,三段都是绝对路径,
35
- // 对 shell 完全透明(POSIX sh / cmd.exe / PowerShell 5.1+ / PowerShell 7+ 全 cover)。
36
- // "PATH node 优先 → 否则用 baked 绝对路径" 的兜底逻辑放在 launch-hook.js 里做,
37
- // 不再依赖 shell `||` 操作符——PS 5.1 不支持 `||`,cc/gemini Windows 上默认就
38
- // PS,会被坑。
35
+ // 跨平台 hook 命令构造。
36
+ //
37
+ // **Windows 上的关键决策(v1.0.9 重构)**:不再写 node 绝对路径,也不再加引号,
38
+ // shell 自己按空白 split + PATH lookup node。原因:
39
+ // - 写绝对路径如 "C:\Program Files\nodejs\node.exe",PowerShell 5.1(cc/gemini
40
+ // 在 Windows 默认 shell)解析时会把外层引号脱掉,按空白把 "C:\Program" 切成
41
+ // 一个 token,"Files\nodejs\..." 切成另一个,hook 进程起不来,exit code 1。
42
+ // - 用 8.3 短路径 (C:\Progra~1\...) 在 NTFS 8dot3name 禁用的卷上失效,
43
+ // 更糟的是 cmd /c for 在某些 locale 下输出会带额外引号,被 installer
44
+ // 二次拼装成 ""\"C:\\\"C:\\Program Files\\nodejs\\node.exe\\\"\"" 这种
45
+ // 非法嵌套,比原 bug 更难修。
46
+ // - 改写 wrapper .cmd / .sh 让用户用别的 shell 接管 → 整体复杂度+30 行,
47
+ // 而且 wrapper 路径本身仍可能带空格,治标不治本。
48
+ //
49
+ // 务实最稳的解:让 shell 自己 PATH 找 node,命令字符串本身不含空格路径段。
50
+ // 假设 ~/.codex/ai-otel/ 这条路径不含空格(取决于用户名):
51
+ // - 99% 用户名是 ASCII 无空格 → 完美工作
52
+ // - 用户名带空格的极少数(如 "John Smith")→ 文档化处理(见
53
+ // docs/codex-windows-troubleshooting.md "用户名含空格" 一节)
54
+ //
55
+ // launch-hook.js 内部还会再做一次 PATH 上探 node、失败时 fallback baked
56
+ // execPath 的兜底,所以 PATH 上 node 临时失踪也能起来。
57
+ //
58
+ // POSIX:保持 quoted 三段格式,shell 行为统一,路径有空格也安全。
39
59
  function buildHookCommand(launcherPath, scriptPath) {
60
+ if (process.platform === "win32") {
61
+ return `node ${launcherPath} ${scriptPath}`;
62
+ }
40
63
  return `"${NODE_BIN}" "${launcherPath}" "${scriptPath}"`;
41
64
  }
42
65
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-otel-setup",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "One-shot installer for AI CLI OpenTelemetry forwarding. Writes Claude Code, Codex CLI, and Gemini CLI telemetry config in a single npx command.",
5
5
  "bin": {
6
6
  "ai-otel-setup": "cli.js",