chatccc 0.2.110 → 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/README.md CHANGED
@@ -44,7 +44,100 @@ ChatCCC 把本地 AI 编程工具接入即时通讯软件。你可以在手机
44
44
 
45
45
  ### 1. 安装
46
46
 
47
- #### npm 全局安装(推荐)
47
+ #### Windows 一键安装(零依赖起步)
48
+
49
+ 如果你的电脑没有装任何东西,**复制下面全部内容,打开 PowerShell 粘贴,回车**。脚本会自动检测并安装所有缺失的依赖,最后启动 ChatCCC。全程只需确认一次 UAC 弹窗。
50
+
51
+ ```powershell
52
+ # ============================================================
53
+ # ChatCCC Windows 一键安装脚本
54
+ # 用法: 复制全部内容 → 打开 PowerShell → 粘贴 → 回车
55
+ # 优先用 winget(快),没有则直接下载安装包(零依赖)
56
+ # ============================================================
57
+
58
+ # --- 辅助函数:安装完程序后刷新 PATH,让当前窗口立即可用 ---
59
+ function Refresh-Path {
60
+ $env:Path = [System.Environment]::GetEnvironmentVariable('Path','Machine') + ';' + [System.Environment]::GetEnvironmentVariable('Path','User')
61
+ }
62
+
63
+ # --- 辅助函数:判断一个命令是否已安装 ---
64
+ function Test-Cmd($name) { return [bool](Get-Command $name -ErrorAction SilentlyContinue) }
65
+
66
+ # --- 判断 winget 是否可用 ---
67
+ $useWinget = Test-Cmd winget
68
+
69
+ Write-Host ''
70
+ Write-Host '============================================================' -ForegroundColor Cyan
71
+ Write-Host ' ChatCCC 环境检测与一键安装' -ForegroundColor Cyan
72
+ if ($useWinget) {
73
+ Write-Host ' 安装方式: winget(Windows 包管理器)' -ForegroundColor DarkGray
74
+ } else {
75
+ Write-Host ' 安装方式: 直接下载(无需 winget)' -ForegroundColor DarkGray
76
+ }
77
+ Write-Host '============================================================' -ForegroundColor Cyan
78
+ Write-Host ''
79
+
80
+ # ============================================================
81
+ # [1/2] 安装 Node.js(ChatCCC 运行环境,要求 >= 20)
82
+ # ============================================================
83
+ if (Test-Cmd node) {
84
+ Write-Host "[1/2] Node.js 已安装: $(node --version 2>$null)" -ForegroundColor Green
85
+ } else {
86
+ Write-Host '[1/2] Node.js 未安装,正在安装...' -ForegroundColor Yellow
87
+
88
+ if ($useWinget) {
89
+ # 方式 A:winget 安装(推荐,速度快)
90
+ Write-Host ' (如弹出 UAC 窗口请点击"是")' -ForegroundColor DarkGray
91
+ winget install OpenJS.NodeJS.LTS --accept-source-agreements --accept-package-agreements
92
+ } else {
93
+ # 方式 B:直接请求 Node.js 官网目录页,从页面中提取最新 LTS 安装包链接
94
+ Write-Host ' 正在获取最新 LTS 版本...' -ForegroundColor DarkGray
95
+ # 请求 latest-v22.x 目录页(返回该大版本下最新的小版本列表)
96
+ $dirHtml = (Invoke-WebRequest 'https://nodejs.org/dist/latest-v22.x/' -UseBasicParsing).Content
97
+ # 从 HTML 中匹配 MSI 文件名,如 node-v22.15.0-x64.msi
98
+ $msiFile = [regex]::Match($dirHtml, 'node-v\d+\.\d+\.\d+-x64\.msi').Value
99
+ if (-not $msiFile) {
100
+ Write-Host ' 错误: 未能从页面中提取 MSI 下载链接' -ForegroundColor Red
101
+ exit 1
102
+ }
103
+ Write-Host " 正在下载 $msiFile ..." -ForegroundColor DarkGray
104
+ # 用提取到的文件名拼出完整下载链接
105
+ $nodeMsi = "$env:TEMP\$msiFile"
106
+ Invoke-WebRequest "https://nodejs.org/dist/latest-v22.x/$msiFile" -OutFile $nodeMsi
107
+ Write-Host ' 正在静默安装(请稍候)...' -ForegroundColor DarkGray
108
+ # /quiet 静默安装,/norestart 不自动重启
109
+ Start-Process msiexec.exe -ArgumentList "/i `"$nodeMsi`" /quiet /norestart" -Wait
110
+ Remove-Item $nodeMsi -Force
111
+ }
112
+
113
+ Refresh-Path
114
+ Write-Host "[1/2] Node.js 安装完成: $(node --version 2>$null)" -ForegroundColor Green
115
+ }
116
+
117
+ # ============================================================
118
+ # [2/2] 安装 ChatCCC 本体(npm 全局安装)
119
+ # ============================================================
120
+ Write-Host '[2/2] 正在从 npm 安装 ChatCCC...' -ForegroundColor Yellow
121
+ npm install -g chatccc
122
+ Write-Host '[2/2] ChatCCC 安装完成!' -ForegroundColor Green
123
+
124
+ # ============================================================
125
+ # 启动 ChatCCC(首次启动自动打开浏览器进入配置向导)
126
+ # ============================================================
127
+ Write-Host ''
128
+ Write-Host '============================================================' -ForegroundColor Cyan
129
+ Write-Host ' 环境就绪,正在启动 ChatCCC ...' -ForegroundColor Cyan
130
+ Write-Host ' 浏览器将自动打开 Web 配置页面' -ForegroundColor Cyan
131
+ Write-Host '============================================================' -ForegroundColor Cyan
132
+ Write-Host ''
133
+ chatccc
134
+ ```
135
+
136
+ 如果一切顺利,浏览器会自动打开 `http://127.0.0.1:18080` 的 Web 配置页面。按页面提示填入飞书 App ID / App Secret,点击"保存并启动"即可。
137
+
138
+ > **只想装 ChatCCC 本体?** 如果你已经有 Node.js,直接 `npm install -g chatccc && chatccc` 即可,不需要跑上面的完整脚本。
139
+
140
+ #### 其他安装方式
48
141
 
49
142
  ```bash
50
143
  npm install -g chatccc
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chatccc",
3
- "version": "0.2.110",
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 消息格式兼容)