ai-otel-setup 1.0.7 → 1.0.8
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/cli.js +31 -4
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -28,16 +28,43 @@ 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
|
+
|
|
31
53
|
// 安装时这台机器的 node 绝对路径,给 hook 命令做兜底(见 buildHookCommand)。
|
|
32
|
-
|
|
54
|
+
// Windows 上立刻转 8.3 短路径,规避 PowerShell 解析空格切 token 的问题。
|
|
55
|
+
const NODE_BIN = toWindowsShortPath(process.execPath);
|
|
33
56
|
|
|
34
|
-
// 跨平台 hook 命令:固定形式 `<NODE_BIN> <launcher> <hook
|
|
35
|
-
//
|
|
57
|
+
// 跨平台 hook 命令:固定形式 `<NODE_BIN> <launcher> <hook>`,三段都是绝对路径。
|
|
58
|
+
// 三段均做 8.3 短路径转换(仅 Windows 生效,POSIX 直接透传):node 在 Program Files、
|
|
59
|
+
// 或者用户名/目录里有空格(如 "C:\Users\张 三\.codex\...")都靠这步消歧义。
|
|
36
60
|
// "PATH 上 node 优先 → 否则用 baked 绝对路径" 的兜底逻辑放在 launch-hook.js 里做,
|
|
37
61
|
// 不再依赖 shell `||` 操作符——PS 5.1 不支持 `||`,cc/gemini 在 Windows 上默认就
|
|
38
62
|
// 是 PS,会被坑。
|
|
39
63
|
function buildHookCommand(launcherPath, scriptPath) {
|
|
40
|
-
|
|
64
|
+
const node = NODE_BIN;
|
|
65
|
+
const launcher = toWindowsShortPath(launcherPath);
|
|
66
|
+
const script = toWindowsShortPath(scriptPath);
|
|
67
|
+
return `"${node}" "${launcher}" "${script}"`;
|
|
41
68
|
}
|
|
42
69
|
|
|
43
70
|
// 把 launcher 模板拷到 hook 同目录,返回 launcher 的绝对路径
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai-otel-setup",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
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",
|