ai-otel-setup 1.0.8 → 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 +31 -35
  2. package/package.json +1 -1
package/cli.js CHANGED
@@ -28,43 +28,39 @@ const { execFileSync } = require("child_process");
28
28
 
29
29
  const PKG_VERSION = require("./package.json").version;
30
30
 
31
- // Windows 8.3 短路径:把 "C:\Program Files\nodejs\node.exe" 这种带空格的长路径
32
- // 转成 "C:\Progra~1\nodejs\node.exe" 形式。**必要性**:codex Windows 下走
33
- // PowerShell 解析 hooks command,PS 把外层引号脱掉之后会按空白拆 token,导致
34
- // "C:\Program Files\..." 被切成 "C:\Program" + "Files\...",hook 进程起不来,
35
- // exit code 1。用 8.3 短路径就根本没空格,cmd.exe 和 PowerShell 都能正确解析。
36
- // 拿不到短路径(NTFS 卷禁用了 8.3 名)就回退原路径——比起死掉,至少 cmd.exe 还能跑。
37
- function toWindowsShortPath(p) {
38
- if (process.platform !== "win32" || !p) return p;
39
- try {
40
- const out = execFileSync(
41
- "cmd.exe",
42
- ["/c", `for %A in ("${p}") do @echo %~sA`],
43
- { encoding: "utf8", windowsHide: true, timeout: 3000 },
44
- );
45
- const short = out.trim();
46
- if (short && short.length > 0) return short;
47
- } catch (_) {
48
- /* 卷禁用了 8.3 / cmd.exe 不可用:吞掉,回退原路径 */
49
- }
50
- return p;
51
- }
52
-
53
- // 安装时这台机器的 node 绝对路径,给 hook 命令做兜底(见 buildHookCommand)。
54
- // Windows 上立刻转 8.3 短路径,规避 PowerShell 解析空格切 token 的问题。
55
- const NODE_BIN = toWindowsShortPath(process.execPath);
31
+ // 安装时这台机器的 node 绝对路径,POSIX 上拿来构造 hook command 用。
32
+ // Windows 上不再写 node 绝对路径(见 buildHookCommand 注释)。
33
+ const NODE_BIN = process.execPath;
56
34
 
57
- // 跨平台 hook 命令:固定形式 `<NODE_BIN> <launcher> <hook>`,三段都是绝对路径。
58
- // 三段均做 8.3 短路径转换(仅 Windows 生效,POSIX 直接透传):node 在 Program Files、
59
- // 或者用户名/目录里有空格(如 "C:\Users\张 三\.codex\...")都靠这步消歧义。
60
- // "PATH node 优先 否则用 baked 绝对路径" 的兜底逻辑放在 launch-hook.js 里做,
61
- // 不再依赖 shell `||` 操作符——PS 5.1 不支持 `||`,cc/gemini 在 Windows 上默认就
62
- // 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.1cc/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 行为统一,路径有空格也安全。
63
59
  function buildHookCommand(launcherPath, scriptPath) {
64
- const node = NODE_BIN;
65
- const launcher = toWindowsShortPath(launcherPath);
66
- const script = toWindowsShortPath(scriptPath);
67
- return `"${node}" "${launcher}" "${script}"`;
60
+ if (process.platform === "win32") {
61
+ return `node ${launcherPath} ${scriptPath}`;
62
+ }
63
+ return `"${NODE_BIN}" "${launcherPath}" "${scriptPath}"`;
68
64
  }
69
65
 
70
66
  // 把 launcher 模板拷到 hook 同目录,返回 launcher 的绝对路径
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-otel-setup",
3
- "version": "1.0.8",
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",