chatccc 0.2.111 → 0.2.112

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chatccc",
3
- "version": "0.2.111",
3
+ "version": "0.2.112",
4
4
  "description": "Feishu bot bridge for Claude Code",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -8,8 +8,9 @@
8
8
  import { spawn, type ChildProcess } from "node:child_process";
9
9
  import { createInterface } from "node:readline";
10
10
  import { existsSync, readFileSync } from "node:fs";
11
- import { join } from "node:path";
11
+ import { join, dirname } from "node:path";
12
12
  import { homedir } from "node:os";
13
+ import { createRequire } from "node:module";
13
14
 
14
15
  import type {
15
16
  ToolAdapter,
@@ -19,7 +20,6 @@ import type {
19
20
  SessionInfo,
20
21
  ToolPromptOptions,
21
22
  } from "./adapter-interface.ts";
22
- import { PROJECT_ROOT } from "../config.ts";
23
23
  import { killProcessTree } from "./proc-tree-kill.ts";
24
24
  import {
25
25
  defaultClaudeSessionMetaStore,
@@ -30,13 +30,48 @@ import {
30
30
  // 常量
31
31
  // ---------------------------------------------------------------------------
32
32
 
33
- const CLAUDE_EXE = join(
34
- PROJECT_ROOT,
35
- "node_modules",
36
- "@anthropic-ai",
37
- "claude-agent-sdk-win32-x64",
38
- "claude.exe",
39
- );
33
+ /** 根据当前平台动态解析 claude-agent-sdk 二进制路径 */
34
+ function resolveClaudeBinary(): string {
35
+ const platform = process.platform; // 'win32', 'linux', 'darwin'
36
+ const arch = process.arch; // 'x64', 'arm64'
37
+
38
+ // 通过 Node 模块解析找到 SDK 主包目录,确保测试和生产环境一致
39
+ const _require = createRequire(import.meta.url);
40
+ const sdkMainDir = dirname(_require.resolve("@anthropic-ai/claude-agent-sdk"));
41
+
42
+ // 读取 manifest.json 获取各平台二进制文件名
43
+ let platforms: Record<string, { binary: string }> | null = null;
44
+ try {
45
+ const manifest = JSON.parse(
46
+ readFileSync(join(sdkMainDir, "manifest.json"), "utf-8"),
47
+ ) as { platforms?: Record<string, { binary: string }> };
48
+ platforms = manifest.platforms ?? null;
49
+ } catch { /* manifest 缺失时用默认规则推断 */ }
50
+
51
+ // Linux 上需区分 musl / glibc,先检测 musl 变体
52
+ const candidates: string[] = [];
53
+ if (platform === "linux") {
54
+ candidates.push(`${platform}-${arch}-musl`, `${platform}-${arch}`);
55
+ } else {
56
+ candidates.push(`${platform}-${arch}`);
57
+ }
58
+
59
+ for (const triple of candidates) {
60
+ const binaryName = platforms?.[triple]?.binary
61
+ ?? (platform === "win32" ? "claude.exe" : "claude");
62
+ const pkgDir = join(sdkMainDir, "..", `claude-agent-sdk-${triple}`);
63
+ if (!existsSync(pkgDir)) continue;
64
+ const exePath = join(pkgDir, binaryName);
65
+ if (existsSync(exePath)) return exePath;
66
+ }
67
+
68
+ throw new Error(
69
+ `No Claude CLI binary found for platform ${platform}-${arch}. ` +
70
+ `Tried: ${candidates.map((c) => `@anthropic-ai/claude-agent-sdk-${c}`).join(", ")}`,
71
+ );
72
+ }
73
+
74
+ const CLAUDE_EXE = resolveClaudeBinary();
40
75
 
41
76
  // ---------------------------------------------------------------------------
42
77
  // 类型别名(CLI JSONL 消息格式,与旧 SDK 消息格式兼容)